PLCGenerator.py
branchpython3
changeset 3759 f713566d5d01
parent 3752 9f6f46dbe3ae
child 3769 f5124b39ae56
equal deleted inserted replaced
3758:bc71b19b45ff 3759:f713566d5d01
    21 # You should have received a copy of the GNU General Public License
    21 # You should have received a copy of the GNU General Public License
    22 # along with this program; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 
    25 
       
    26 from functools import cmp_to_key
       
    27 from operator import eq
    26 import re
    28 import re
    27 from functools import reduce
    29 from functools import reduce
    28 
    30 
    29 from plcopen import PLCOpenParser
    31 from plcopen import PLCOpenParser
    30 from plcopen.structures import *
    32 from plcopen.structures import *
    75 
    77 
    76 def SortInstances(a, b):
    78 def SortInstances(a, b):
    77     ax, ay = int(a.getx()), int(a.gety())
    79     ax, ay = int(a.getx()), int(a.gety())
    78     bx, by = int(b.getx()), int(b.gety())
    80     bx, by = int(b.getx()), int(b.gety())
    79     if abs(ay - by) < 10:
    81     if abs(ay - by) < 10:
    80         return cmp(ax, bx)
    82         return eq(ax, bx)
    81     else:
    83     else:
    82         return cmp(ay, by)
    84         return eq(ay, by)
    83 
    85 
    84 
    86 
    85 def JoinList(separator, mylist):
    87 def JoinList(separator, mylist):
    86     """ Helper for emulate join on element list """
    88     """ Helper for emulate join on element list """
    87     if len(mylist) > 0:
    89     if len(mylist) > 0:
   991                         otherInstances["blocks"].append(instance)
   993                         otherInstances["blocks"].append(instance)
   992                 elif isinstance(instance, ConnectorClass):
   994                 elif isinstance(instance, ConnectorClass):
   993                     otherInstances["connectors"].append(instance)
   995                     otherInstances["connectors"].append(instance)
   994                 elif isinstance(instance, CoilClass):
   996                 elif isinstance(instance, CoilClass):
   995                     otherInstances["outVariables&coils"].append(instance)
   997                     otherInstances["outVariables&coils"].append(instance)
   996             orderedInstances.sort()
   998             orderedInstances.sort(key=lambda n: n[0])
   997             otherInstances["outVariables&coils"].sort(SortInstances)
   999             otherInstances["outVariables&coils"].sort(key=cmp_to_key(SortInstances))
   998             otherInstances["blocks"].sort(SortInstances)
  1000             otherInstances["blocks"].sort(key=cmp_to_key(SortInstances))
   999             instances = [instance for (executionOrderId, instance) in orderedInstances]
  1001             instances = [instance for (executionOrderId, instance) in orderedInstances]
  1000             instances.extend(otherInstances["outVariables&coils"] + otherInstances["blocks"] + otherInstances["connectors"])
  1002             instances.extend(otherInstances["outVariables&coils"] + otherInstances["blocks"] + otherInstances["connectors"])
  1001             for instance in instances:
  1003             for instance in instances:
  1002                 if isinstance(instance, (OutVariableClass, InOutVariableClass)):
  1004                 if isinstance(instance, (OutVariableClass, InOutVariableClass)):
  1003                     connections = instance.connectionPointIn.getconnections()
  1005                     connections = instance.connectionPointIn.getconnections()