PLCGenerator.py
author Laurent Bessard
Tue, 10 Sep 2013 10:35:18 +0200
changeset 1310 3d7fa2257b24
parent 1298 f034fb2b1aab
child 1315 ff14a66bbd12
permissions -rw-r--r--
Removed obsolete process for customizing block code generated in extensions
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
    25
from plcopen import PLCOpenParser
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
from plcopen.structures import *
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
from types import *
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
import re
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
# Dictionary associating PLCOpen variable categories to the corresponding 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
# IEC 61131-3 variable categories
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
varTypeNames = {"localVars" : "VAR", "tempVars" : "VAR_TEMP", "inputVars" : "VAR_INPUT", 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
                "outputVars" : "VAR_OUTPUT", "inOutVars" : "VAR_IN_OUT", "externalVars" : "VAR_EXTERNAL",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
                "globalVars" : "VAR_GLOBAL", "accessVars" : "VAR_ACCESS"}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
# Dictionary associating PLCOpen POU categories to the corresponding 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
# IEC 61131-3 POU categories
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
pouTypeNames = {"function" : "FUNCTION", "functionBlock" : "FUNCTION_BLOCK", "program" : "PROGRAM"}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
errorVarTypes = {
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
    "VAR_INPUT": "var_input",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
    "VAR_OUTPUT": "var_output",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
    "VAR_INOUT": "var_inout",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
# Helper function for reindenting text
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
def ReIndentText(text, nb_spaces):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
    compute = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
    lines = text.splitlines()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
    if len(lines) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
        line_num = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
        while line_num < len(lines) and len(lines[line_num].strip()) == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
            line_num += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
        if line_num < len(lines):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
            spaces = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
            while lines[line_num][spaces] == " ":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
                spaces += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
            indent = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
            for i in xrange(spaces, nb_spaces):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
                indent += " "
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
            for line in lines:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
                if line != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
                    compute += "%s%s\n"%(indent, line)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
                    compute += "\n"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
    return compute
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
def SortInstances(a, b):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
    ax, ay = int(a.getx()), int(a.gety())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
    bx, by = int(b.getx()), int(b.gety())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
    if abs(ay - by) < 10:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
        return cmp(ax, bx)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
        return cmp(ay, by)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
1310
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
    78
# Helper for emulate join on element list
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
    79
def JoinList(separator, mylist):
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
    80
    if len(mylist) > 0 :
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
    81
        return reduce(lambda x, y: x + separator + y, mylist)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
    82
    else :
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
    83
        return mylist
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
    84
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
#                  Specific exception for PLC generating errors
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
class PLCGenException(Exception):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
    pass
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
#                           Generator of PLC program
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
class ProgramGenerator:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
    # Create a new PCL program generator
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
    def __init__(self, controler, project, errors, warnings):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
        # Keep reference of the controler and project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        self.Controler = controler
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
        self.Project = project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        # Reset the internal variables used to generate PLC programs
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
        self.Program = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
        self.DatatypeComputed = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
        self.PouComputed = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
        self.Errors = errors
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
        self.Warnings = warnings
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
    # Compute value according to type given
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
    def ComputeValue(self, value, var_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
        base_type = self.Controler.GetBaseType(var_type)
1032
c4989e53f9c3 Fix bug defining string initial value using quotes
Laurent Bessard
parents: 893
diff changeset
   116
        if base_type == "STRING" and not value.startswith("'") and not value.endswith("'"):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
            return "'%s'"%value
1032
c4989e53f9c3 Fix bug defining string initial value using quotes
Laurent Bessard
parents: 893
diff changeset
   118
        elif base_type == "WSTRING" and not value.startswith('"') and not value.endswith('"'):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
            return "\"%s\""%value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
        return value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
    # Generate a data type from its name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
    def GenerateDataType(self, datatype_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
        # Verify that data type hasn't been generated yet
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
        if not self.DatatypeComputed.get(datatype_name, True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
            # If not mark data type as computed
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
            self.DatatypeComputed[datatype_name] = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
            # Getting datatype model from project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
            datatype = self.Project.getdataType(datatype_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
            tagname = self.Controler.ComputeDataTypeName(datatype.getname())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   132
            datatype_def = [("  ", ()), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
                            (datatype.getname(), (tagname, "name")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
                            (" : ", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
            basetype_content = datatype.baseType.getcontent()
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   136
            basetype_content_type = basetype_content.getLocalTag()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
            # Data type derived directly from a user defined type 
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   138
            if basetype_content_type == "derived":
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   139
                basetype_name = basetype_content.getname()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
                self.GenerateDataType(basetype_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
                datatype_def += [(basetype_name, (tagname, "base"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
            # Data type is a subrange
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   143
            elif basetype_content_type in ["subrangeSigned", "subrangeUnsigned"]:
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   144
                base_type = basetype_content.baseType.getcontent()
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   145
                base_type_type = base_type.getLocalTag()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
                # Subrange derived directly from a user defined type 
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   147
                if base_type_type == "derived":
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   148
                    basetype_name = base_type_type.getname()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
                    self.GenerateDataType(basetype_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
                # Subrange derived directly from an elementary type 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
                else:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   152
                    basetype_name = base_type_type
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   153
                min_value = basetype_content.range.getlower()
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   154
                max_value = basetype_content.range.getupper()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
                datatype_def += [(basetype_name, (tagname, "base")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
                                 (" (", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
                                 ("%s"%min_value, (tagname, "lower")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
                                 ("..", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
                                 ("%s"%max_value, (tagname, "upper")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
                                 (")",())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
            # Data type is an enumerated type
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   162
            elif basetype_content_type == "enum":
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
                values = [[(value.getname(), (tagname, "value", i))]
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   164
                          for i, value in enumerate(
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   165
                              basetype_content.xpath("ppx:values/ppx:value", 
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   166
                                  namespaces=PLCOpenParser.NSMAP))]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
                datatype_def += [("(", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
                datatype_def += JoinList([(", ", ())], values)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
                datatype_def += [(")", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
            # Data type is an array
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   171
            elif basetype_content_type == "array":
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   172
                base_type = basetype_content.baseType.getcontent()
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   173
                base_type_type = base_type.getLocalTag()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
                # Array derived directly from a user defined type 
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   175
                if base_type_type == "derived":
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   176
                    basetype_name = base_type.getname()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
                    self.GenerateDataType(basetype_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
                # Array derived directly from an elementary type 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
                else:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   180
                    basetype_name = base_type_type.upper()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
                dimensions = [[("%s"%dimension.getlower(), (tagname, "range", i, "lower")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
                               ("..", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
                               ("%s"%dimension.getupper(), (tagname, "range", i, "upper"))] 
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   184
                              for i, dimension in enumerate(basetype_content.getdimension())]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
                datatype_def += [("ARRAY [", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
                datatype_def += JoinList([(",", ())], dimensions)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
                datatype_def += [("] OF " , ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
                                 (basetype_name, (tagname, "base"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
            # Data type is a structure
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   190
            elif basetype_content_type == "struct":
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
                elements = []
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   192
                for i, element in enumerate(basetype_content.getvariable()):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
                    element_type = element.type.getcontent()
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   194
                    element_type_type = element_type.getLocalTag()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
                    # Structure element derived directly from a user defined type 
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   196
                    if element_type_type == "derived":
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   197
                        elementtype_name = element_type.getname()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
                        self.GenerateDataType(elementtype_name)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   199
                    elif element_type_type == "array":
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   200
                        base_type = element_type.baseType.getcontent()
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   201
                        base_type_type = base_type.getLocalTag()
864
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 854
diff changeset
   202
                        # Array derived directly from a user defined type 
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   203
                        if base_type_type == "derived":
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   204
                            basetype_name = base_type.getname()
864
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 854
diff changeset
   205
                            self.GenerateDataType(basetype_name)
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 854
diff changeset
   206
                        # Array derived directly from an elementary type 
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 854
diff changeset
   207
                        else:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   208
                            basetype_name = base_type_type.upper()
864
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 854
diff changeset
   209
                        dimensions = ["%s..%s" % (dimension.getlower(), dimension.getupper())
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   210
                                      for dimension in element_type.getdimension()]
864
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 854
diff changeset
   211
                        elementtype_name = "ARRAY [%s] OF %s" % (",".join(dimensions), basetype_name)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   212
                    # Structure element derived directly from an elementary type 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
                    else:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   214
                        elementtype_name = element_type_type.upper()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
                    element_text = [("\n    ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   216
                                    (element.getname(), (tagname, "struct", i, "name")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   217
                                    (" : ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
                                    (elementtype_name, (tagname, "struct", i, "type"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
                    if element.initialValue is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
                        element_text.extend([(" := ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
                                             (self.ComputeValue(element.initialValue.getvalue(), elementtype_name), (tagname, "struct", i, "initial value"))])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   222
                    element_text.append((";", ()))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   223
                    elements.append(element_text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   224
                datatype_def += [("STRUCT", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   225
                datatype_def += JoinList([("", ())], elements)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   226
                datatype_def += [("\n  END_STRUCT", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   227
            # Data type derived directly from a elementary type 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
            else:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   229
                datatype_def += [(basetype_content_type.upper(), (tagname, "base"))]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
            # Data type has an initial value
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
            if datatype.initialValue is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
                datatype_def += [(" := ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
                                 (self.ComputeValue(datatype.initialValue.getvalue(), datatype_name), (tagname, "initial value"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
            datatype_def += [(";\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
            self.Program += datatype_def
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   236
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
    # Generate a POU from its name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
    def GeneratePouProgram(self, pou_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
        # Verify that POU hasn't been generated yet
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
        if not self.PouComputed.get(pou_name, True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
            # If not mark POU as computed
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
            self.PouComputed[pou_name] = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
            # Getting POU model from project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
            pou = self.Project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
            pou_type = pou.getpouType()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
            # Verify that POU type exists
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
            if pouTypeNames.has_key(pou_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
                # Create a POU program generator
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
                pou_program = PouProgramGenerator(self, pou.getname(), pouTypeNames[pou_type], self.Errors, self.Warnings)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
                program = pou_program.GenerateProgram(pou)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
                self.Program += program
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
                raise PLCGenException, _("Undefined pou type \"%s\"")%pou_type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
    # Generate a POU defined and used in text
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
    def GeneratePouProgramInText(self, text):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
        for pou_name in self.PouComputed.keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
            model = re.compile("(?:^|[^0-9^A-Z])%s(?:$|[^0-9^A-Z])"%pou_name.upper())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   260
            if model.search(text) is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
                self.GeneratePouProgram(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   262
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   263
    # Generate a configuration from its model
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   264
    def GenerateConfiguration(self, configuration):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   265
        tagname = self.Controler.ComputeConfigurationName(configuration.getname())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
        config = [("\nCONFIGURATION ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   267
                  (configuration.getname(), (tagname, "name")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
                  ("\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   269
        var_number = 0
883
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   270
        
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   271
        varlists = [(varlist, varlist.getvariable()[:]) for varlist in configuration.getglobalVars()]
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   272
        
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   273
        extra_variables = self.Controler.GetConfigurationExtraVariables()
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   274
        if len(extra_variables) > 0:
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   275
            if len(varlists) == 0:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   276
                varlists = [(PLCOpenParser.CreateElement("globalVars", "interface"), [])]
883
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   277
            varlists[-1][1].extend(extra_variables)
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   278
            
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
        # Generate any global variable in configuration
883
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   280
        for varlist, varlist_variables in varlists:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   281
            variable_type = errorVarTypes.get("VAR_GLOBAL", "var_local")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
            # Generate variable block with modifier
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   283
            config += [("  VAR_GLOBAL", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
            if varlist.getconstant():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   285
                config += [(" CONSTANT", (tagname, variable_type, (var_number, var_number + len(varlist.getvariable())), "constant"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
            elif varlist.getretain():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   287
                config += [(" RETAIN", (tagname, variable_type, (var_number, var_number + len(varlist.getvariable())), "retain"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
            elif varlist.getnonretain():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
                config += [(" NON_RETAIN", (tagname, variable_type, (var_number, var_number + len(varlist.getvariable())), "non_retain"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
            config += [("\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
            # Generate any variable of this block
883
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   292
            for var in varlist_variables:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
                vartype_content = var.gettype().getcontent()
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   294
                if vartype_content.getLocalTag() == "derived":
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   295
                    var_type = vartype_content.getname()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
                    self.GenerateDataType(var_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
                    var_type = var.gettypeAsText()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
                config += [("    ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
                           (var.getname(), (tagname, variable_type, var_number, "name")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
                           (" ", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
                # Generate variable address if exists
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
                address = var.getaddress()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
                if address:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
                    config += [("AT ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   307
                               (address, (tagname, variable_type, var_number, "location")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   308
                               (" ", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
                config += [(": ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
                           (var.gettypeAsText(), (tagname, variable_type, var_number, "type"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
                # Generate variable initial value if exists
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
                initial = var.getinitialValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
                if initial:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
                    config += [(" := ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
                               (self.ComputeValue(initial.getvalue(), var_type), (tagname, variable_type, var_number, "initial value"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
                config += [(";\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   317
                var_number += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
            config += [("  END_VAR\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
        # Generate any resource in the configuration
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   320
        for resource in configuration.getresource():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
            config += self.GenerateResource(resource, configuration.getname())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
        config += [("END_CONFIGURATION\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   323
        return config
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   325
    # Generate a resource from its model
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
    def GenerateResource(self, resource, config_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
        tagname = self.Controler.ComputeConfigurationResourceName(config_name, resource.getname())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
        resrce = [("\n  RESOURCE ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
                  (resource.getname(), (tagname, "name")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
                  (" ON PLC\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   331
        var_number = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   332
        # Generate any global variable in configuration
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   333
        for varlist in resource.getglobalVars():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   334
            variable_type = errorVarTypes.get("VAR_GLOBAL", "var_local")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   335
            # Generate variable block with modifier
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
            resrce += [("    VAR_GLOBAL", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   337
            if varlist.getconstant():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
                resrce += [(" CONSTANT", (tagname, variable_type, (var_number, var_number + len(varlist.getvariable())), "constant"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   339
            elif varlist.getretain():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   340
                resrce += [(" RETAIN", (tagname, variable_type, (var_number, var_number + len(varlist.getvariable())), "retain"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   341
            elif varlist.getnonretain():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   342
                resrce += [(" NON_RETAIN", (tagname, variable_type, (var_number, var_number + len(varlist.getvariable())), "non_retain"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   343
            resrce += [("\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   344
            # Generate any variable of this block
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   345
            for var in varlist.getvariable():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   346
                vartype_content = var.gettype().getcontent()
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   347
                if vartype_content.getLocalTag() == "derived":
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   348
                    var_type = vartype_content.getname()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
                    self.GenerateDataType(var_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   350
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   351
                    var_type = var.gettypeAsText()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   352
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   353
                resrce += [("      ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   354
                           (var.getname(), (tagname, variable_type, var_number, "name")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   355
                           (" ", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   356
                address = var.getaddress()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   357
                # Generate variable address if exists
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   358
                if address:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   359
                    resrce += [("AT ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   360
                               (address, (tagname, variable_type, var_number, "location")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   361
                               (" ", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   362
                resrce += [(": ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
                           (var.gettypeAsText(), (tagname, variable_type, var_number, "type"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   364
                # Generate variable initial value if exists
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   365
                initial = var.getinitialValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   366
                if initial:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   367
                    resrce += [(" := ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   368
                               (self.ComputeValue(initial.getvalue(), var_type), (tagname, variable_type, var_number, "initial value"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   369
                resrce += [(";\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   370
                var_number += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   371
            resrce += [("    END_VAR\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   372
        # Generate any task in the resource
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   373
        tasks = resource.gettask()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   374
        task_number = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   375
        for task in tasks:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   376
            # Task declaration
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   377
            resrce += [("    TASK ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   378
                       (task.getname(), (tagname, "task", task_number, "name")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   379
                       ("(", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   380
            args = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   381
            single = task.getsingle()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   382
            # Single argument if exists
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   383
            if single:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   384
                resrce += [("SINGLE := ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   385
                           (single, (tagname, "task", task_number, "single")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   386
                           (",", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   387
            # Interval argument if exists
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   388
            interval = task.getinterval()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   389
            if interval:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   390
                resrce += [("INTERVAL := ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   391
                           (interval, (tagname, "task", task_number, "interval")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
                           (",", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   393
##                resrce += [("INTERVAL := t#", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
##                if interval.hour != 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   395
##                    resrce += [("%dh"%interval.hour, (tagname, "task", task_number, "interval", "hour"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   396
##                if interval.minute != 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   397
##                    resrce += [("%dm"%interval.minute, (tagname, "task", task_number, "interval", "minute"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   398
##                if interval.second != 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   399
##                    resrce += [("%ds"%interval.second, (tagname, "task", task_number, "interval", "second"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   400
##                if interval.microsecond != 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   401
##                    resrce += [("%dms"%(interval.microsecond / 1000), (tagname, "task", task_number, "interval", "millisecond"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   402
##                resrce += [(",", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   403
            # Priority argument
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   404
            resrce += [("PRIORITY := ", ()), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   405
                       ("%d"%task.getpriority(), (tagname, "task", task_number, "priority")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   406
                       (");\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   407
            task_number += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   408
        instance_number = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   409
        # Generate any program assign to each task
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   410
        for task in tasks:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   411
            for instance in task.getpouInstance():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   412
                resrce += [("    PROGRAM ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   413
                           (instance.getname(), (tagname, "instance", instance_number, "name")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   414
                           (" WITH ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   415
                           (task.getname(), (tagname, "instance", instance_number, "task")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   416
                           (" : ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   417
                           (instance.gettypeName(), (tagname, "instance", instance_number, "type")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   418
                           (";\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   419
                instance_number += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   420
        # Generate any program assign to no task
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   421
        for instance in resource.getpouInstance():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   422
            resrce += [("    PROGRAM ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   423
                           (instance.getname(), (tagname, "instance", instance_number, "name")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   424
                           (" : ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   425
                           (instance.gettypeName(), (tagname, "instance", instance_number, "type")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   426
                           (";\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   427
            instance_number += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   428
        resrce += [("  END_RESOURCE\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   429
        return resrce
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   430
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   431
    # Generate the entire program for current project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   432
    def GenerateProgram(self):        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   433
        # Find all data types defined
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   434
        for datatype in self.Project.getdataTypes():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   435
            self.DatatypeComputed[datatype.getname()] = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   436
        # Find all data types defined
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   437
        for pou in self.Project.getpous():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   438
            self.PouComputed[pou.getname()] = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   439
        # Generate data type declaration structure if there is at least one data 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   440
        # type defined
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   441
        if len(self.DatatypeComputed) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   442
            self.Program += [("TYPE\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   443
            # Generate every data types defined
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   444
            for datatype_name in self.DatatypeComputed.keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   445
                self.GenerateDataType(datatype_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   446
            self.Program += [("END_TYPE\n\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   447
        # Generate every POUs defined
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   448
        for pou_name in self.PouComputed.keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   449
            self.GeneratePouProgram(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   450
        # Generate every configurations defined
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   451
        for config in self.Project.getconfigurations():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   452
            self.Program += self.GenerateConfiguration(config)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   453
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   454
    # Return generated program
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   455
    def GetGeneratedProgram(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   456
        return self.Program
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   457
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   458
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   459
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   460
#                           Generator of POU programs
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   461
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   462
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   463
[ConnectorClass, ContinuationClass, ActionBlockClass] = [
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   464
    PLCOpenParser.GetElementClass(instance_name, "commonObjects")
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   465
    for instance_name in ["connector", "continuation", "actionBlock"]]
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   466
[InVariableClass, InOutVariableClass, OutVariableClass, BlockClass] = [
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   467
    PLCOpenParser.GetElementClass(instance_name, "fbdObjects")
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   468
    for instance_name in ["inVariable", "inOutVariable", "outVariable", "block"]]
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   469
[ContactClass, CoilClass, LeftPowerRailClass, RightPowerRailClass] = [
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   470
    PLCOpenParser.GetElementClass(instance_name, "ldObjects")
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   471
    for instance_name in ["contact", "coil", "leftPowerRail", "rightPowerRail"]]
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   472
[StepClass, TransitionClass, JumpStepClass, 
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   473
 SelectionConvergenceClass, SelectionDivergenceClass,
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   474
 SimultaneousConvergenceClass, SimultaneousDivergenceClass] = [
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   475
    PLCOpenParser.GetElementClass(instance_name, "sfcObjects")
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   476
    for instance_name in ["step", "transition", "jumpStep", 
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   477
        "selectionConvergence", "selectionDivergence",
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   478
        "simultaneousConvergence", "simultaneousDivergence"]]
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   479
TransitionObjClass = PLCOpenParser.GetElementClass("transition", "transitions")
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   480
ActionObjClass = PLCOpenParser.GetElementClass("action", "actions")
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   481
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   482
class PouProgramGenerator:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   483
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   484
    # Create a new POU program generator
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   485
    def __init__(self, parent, name, type, errors, warnings):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   486
        # Keep Reference to the parent generator
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   487
        self.ParentGenerator = parent
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   488
        self.Name = name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   489
        self.Type = type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   490
        self.TagName = self.ParentGenerator.Controler.ComputePouName(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   491
        self.CurrentIndent = "  "
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   492
        self.ReturnType = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   493
        self.Interface = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   494
        self.InitialSteps = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   495
        self.ComputedBlocks = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   496
        self.ComputedConnectors = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   497
        self.ConnectionTypes = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   498
        self.RelatedConnections = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   499
        self.SFCNetworks = {"Steps":{}, "Transitions":{}, "Actions":{}}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   500
        self.SFCComputedBlocks = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   501
        self.ActionNumber = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   502
        self.Program = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   503
        self.Errors = errors
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   504
        self.Warnings = warnings
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   505
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   506
    def GetBlockType(self, type, inputs=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   507
        return self.ParentGenerator.Controler.GetBlockType(type, inputs)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   508
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   509
    def IndentLeft(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   510
        if len(self.CurrentIndent) >= 2:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   511
            self.CurrentIndent = self.CurrentIndent[:-2]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   512
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   513
    def IndentRight(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   514
        self.CurrentIndent += "  "
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   515
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   516
    # Generator of unique ID for inline actions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   517
    def GetActionNumber(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   518
        self.ActionNumber += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   519
        return self.ActionNumber
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   520
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   521
    # Test if a variable has already been defined
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   522
    def IsAlreadyDefined(self, name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   523
        for list_type, option, located, vars in self.Interface:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   524
            for var_type, var_name, var_address, var_initial in vars:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   525
                if name == var_name:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   526
                    return True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   527
        return False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   528
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   529
    # Return the type of a variable defined in interface
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   530
    def GetVariableType(self, name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   531
        parts = name.split('.')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   532
        current_type = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   533
        if len(parts) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   534
            name = parts.pop(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   535
            for list_type, option, located, vars in self.Interface:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   536
                for var_type, var_name, var_address, var_initial in vars:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   537
                    if name == var_name:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   538
                        current_type = var_type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   539
                        break
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   540
            while current_type is not None and len(parts) > 0:
883
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   541
                blocktype = self.ParentGenerator.Controler.GetBlockType(current_type)
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   542
                if blocktype is not None:
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   543
                    name = parts.pop(0)
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   544
                    current_type = None
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   545
                    for var_name, var_type, var_modifier in blocktype["inputs"] + blocktype["outputs"]:
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   546
                        if var_name == name:
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   547
                            current_type = var_type
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   548
                            break
883
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   549
                else:
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   550
                    tagname = self.ParentGenerator.Controler.ComputeDataTypeName(current_type)
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   551
                    infos = self.ParentGenerator.Controler.GetDataTypeInfos(tagname)
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   552
                    if infos is not None and infos["type"] == "Structure":
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   553
                        name = parts.pop(0)
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   554
                        current_type = None
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   555
                        for element in infos["elements"]:
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   556
                            if element["Name"] == name:
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   557
                                current_type = element["Type"]
235a9ec83b95 Adding support for defining specific global variables for ConfTreeNodes
Laurent Bessard
parents: 864
diff changeset
   558
                                break
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   559
        return current_type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   560
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   561
    # Return connectors linked by a connection to the given connector
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   562
    def GetConnectedConnector(self, connector, body):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   563
        links = connector.getconnections()
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   564
        if links is not None and len(links) == 1:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   565
            return self.GetLinkedConnector(links[0], body)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   566
        return None        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   567
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   568
    def GetLinkedConnector(self, link, body):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   569
        parameter = link.getformalParameter()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   570
        instance = body.getcontentInstance(link.getrefLocalId())
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   571
        if isinstance(instance, (InVariableClass, InOutVariableClass, 
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   572
             ContinuationClass, ContactClass, CoilClass)):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   573
            return instance.connectionPointOut
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   574
        elif isinstance(instance, BlockClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   575
            outputvariables = instance.outputVariables.getvariable()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   576
            if len(outputvariables) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   577
                return outputvariables[0].connectionPointOut
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   578
            elif parameter:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   579
                for variable in outputvariables:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   580
                    if variable.getformalParameter() == parameter:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   581
                        return variable.connectionPointOut
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   582
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   583
                point = link.getposition()[-1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   584
                for variable in outputvariables:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   585
                    relposition = variable.connectionPointOut.getrelPositionXY()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   586
                    blockposition = instance.getposition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   587
                    if point.x == blockposition.x + relposition[0] and point.y == blockposition.y + relposition[1]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   588
                        return variable.connectionPointOut
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   589
        elif isinstance(instance, LeftPowerRailClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   590
            outputconnections = instance.getconnectionPointOut()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   591
            if len(outputconnections) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   592
                return outputconnections[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   593
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   594
                point = link.getposition()[-1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   595
                for outputconnection in outputconnections:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   596
                    relposition = outputconnection.getrelPositionXY()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   597
                    powerrailposition = instance.getposition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   598
                    if point.x == powerrailposition.x + relposition[0] and point.y == powerrailposition.y + relposition[1]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   599
                        return outputconnection
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   600
        return None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   601
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   602
    def ExtractRelatedConnections(self, connection):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   603
        for i, related in enumerate(self.RelatedConnections):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   604
            if connection in related:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   605
                return self.RelatedConnections.pop(i)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   606
        return [connection]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   607
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   608
    def ComputeInterface(self, pou):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   609
        interface = pou.getinterface()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   610
        if interface is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   611
            body = pou.getbody()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   612
            if isinstance(body, ListType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   613
                body = body[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   614
            body_content = body.getcontent()
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   615
            body_type = body_content.getLocalTag()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   616
            if self.Type == "FUNCTION":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   617
                returntype_content = interface.getreturnType().getcontent()
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   618
                returntype_content_type = returntype_content.getLocalTag()
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   619
                if returntype_content_type == "derived":
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   620
                    self.ReturnType = returntype_content.getname()
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   621
                else:
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   622
                    self.ReturnType = returntype_content_type.upper()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   623
            for varlist in interface.getcontent():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   624
                variables = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   625
                located = []
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   626
                varlist_type = varlist.getLocalTag()
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   627
                for var in varlist.getvariable():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   628
                    vartype_content = var.gettype().getcontent()
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   629
                    if vartype_content.getLocalTag() == "derived":
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   630
                        var_type = vartype_content.getname()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   631
                        blocktype = self.GetBlockType(var_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   632
                        if blocktype is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   633
                            self.ParentGenerator.GeneratePouProgram(var_type)
1310
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   634
                            variables.append((var_type, var.getname(), None, None))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   635
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   636
                            self.ParentGenerator.GenerateDataType(var_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   637
                            initial = var.getinitialValue()
1310
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   638
                            if initial is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   639
                                initial_value = initial.getvalue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   640
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   641
                                initial_value = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   642
                            address = var.getaddress()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   643
                            if address is not None:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   644
                                located.append((vartype_content.getname(), var.getname(), address, initial_value))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   645
                            else:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   646
                                variables.append((vartype_content.getname(), var.getname(), None, initial_value))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   647
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   648
                        var_type = var.gettypeAsText()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   649
                        initial = var.getinitialValue()
1310
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   650
                        if initial is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   651
                            initial_value = initial.getvalue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   652
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   653
                            initial_value = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   654
                        address = var.getaddress()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   655
                        if address is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   656
                            located.append((var_type, var.getname(), address, initial_value))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   657
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   658
                            variables.append((var_type, var.getname(), None, initial_value))
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   659
                if varlist.getconstant():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   660
                    option = "CONSTANT"
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   661
                elif varlist.getretain():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   662
                    option = "RETAIN"
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   663
                elif varlist.getnonretain():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   664
                    option = "NON_RETAIN"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   665
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   666
                    option = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   667
                if len(variables) > 0:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   668
                    self.Interface.append((varTypeNames[varlist_type], option, False, variables))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   669
                if len(located) > 0:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   670
                    self.Interface.append((varTypeNames[varlist_type], option, True, located))
1181
21e6db77eb29 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1134
diff changeset
   671
    
21e6db77eb29 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1134
diff changeset
   672
    LITERAL_TYPES = {
21e6db77eb29 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1134
diff changeset
   673
        "T": "TIME",
21e6db77eb29 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1134
diff changeset
   674
        "D": "DATE",
21e6db77eb29 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1134
diff changeset
   675
        "TOD": "TIME_OF_DAY",
21e6db77eb29 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1134
diff changeset
   676
        "DT": "DATE_AND_TIME",
1183
a01618805821 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1181
diff changeset
   677
        "2": None,
a01618805821 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1181
diff changeset
   678
        "8": None,
a01618805821 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1181
diff changeset
   679
        "16": None,
1181
21e6db77eb29 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1134
diff changeset
   680
    }
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   681
    def ComputeConnectionTypes(self, pou):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   682
        body = pou.getbody()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   683
        if isinstance(body, ListType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   684
            body = body[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   685
        body_content = body.getcontent()
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   686
        body_type = body_content.getLocalTag()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   687
        if body_type in ["FBD", "LD", "SFC"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   688
            undefined_blocks = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   689
            for instance in body.getcontentInstances():
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   690
                if isinstance(instance, (InVariableClass, OutVariableClass, 
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   691
                                         InOutVariableClass)):
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   692
                    expression = instance.getexpression().text
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   693
                    var_type = self.GetVariableType(expression)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   694
                    if (isinstance(pou, TransitionObjClass) 
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   695
                        and expression == pou.getname()):
822
050045c32d98 Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents: 814
diff changeset
   696
                        var_type = "BOOL"
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   697
                    elif (not isinstance(pou, (TransitionObjClass, ActionObjClass)) and
822
050045c32d98 Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents: 814
diff changeset
   698
                          pou.getpouType() == "function" and expression == pou.getname()):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   699
                        returntype_content = pou.interface.getreturnType().getcontent()
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   700
                        returntype_content_type = returntype_content.getLocalTag()
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   701
                        if returntype_content_type == "derived":
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   702
                            var_type = returntype_content.getname()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   703
                        else:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   704
                            var_type = returntype_content_type.upper()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   705
                    elif var_type is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   706
                        parts = expression.split("#")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   707
                        if len(parts) > 1:
1181
21e6db77eb29 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1134
diff changeset
   708
                            literal_prefix = parts[0].upper()
21e6db77eb29 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1134
diff changeset
   709
                            var_type = self.LITERAL_TYPES.get(literal_prefix, 
21e6db77eb29 Fixed bug in PLC code generated with binary, octal and hexadecimal literals
Laurent Bessard
parents: 1134
diff changeset
   710
                                                              literal_prefix)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   711
                        elif expression.startswith("'"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   712
                            var_type = "STRING"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   713
                        elif expression.startswith('"'):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   714
                            var_type = "WSTRING"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   715
                    if var_type is not None:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   716
                        if isinstance(instance, (InVariableClass, InOutVariableClass)):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   717
                            for connection in self.ExtractRelatedConnections(instance.connectionPointOut):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   718
                                self.ConnectionTypes[connection] = var_type
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   719
                        if isinstance(instance, (OutVariableClass, InOutVariableClass)):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   720
                            self.ConnectionTypes[instance.connectionPointIn] = var_type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   721
                            connected = self.GetConnectedConnector(instance.connectionPointIn, body)
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   722
                            if connected is not None and not self.ConnectionTypes.has_key(connected):
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   723
                                for related in self.ExtractRelatedConnections(connected):
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   724
                                    self.ConnectionTypes[related] = var_type
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   725
                elif isinstance(instance, (ContactClass, CoilClass)):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   726
                    for connection in self.ExtractRelatedConnections(instance.connectionPointOut):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   727
                        self.ConnectionTypes[connection] = "BOOL"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   728
                    self.ConnectionTypes[instance.connectionPointIn] = "BOOL"
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   729
                    for link in instance.connectionPointIn.getconnections():
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   730
                        connected = self.GetLinkedConnector(link, body)
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   731
                        if connected is not None and not self.ConnectionTypes.has_key(connected):
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   732
                            for related in self.ExtractRelatedConnections(connected):
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   733
                                self.ConnectionTypes[related] = "BOOL"
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   734
                elif isinstance(instance, LeftPowerRailClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   735
                    for connection in instance.getconnectionPointOut():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   736
                        for related in self.ExtractRelatedConnections(connection):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   737
                            self.ConnectionTypes[related] = "BOOL"
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   738
                elif isinstance(instance, RightPowerRailClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   739
                    for connection in instance.getconnectionPointIn():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   740
                        self.ConnectionTypes[connection] = "BOOL"
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   741
                        for link in connection.getconnections():
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   742
                            connected = self.GetLinkedConnector(link, body)
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   743
                            if connected is not None and not self.ConnectionTypes.has_key(connected):
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   744
                                for related in self.ExtractRelatedConnections(connected):
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   745
                                    self.ConnectionTypes[related] = "BOOL"
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   746
                elif isinstance(instance, TransitionClass):
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   747
                    content = instance.getconditionContent()
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   748
                    if content["type"] == "connection":
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   749
                        self.ConnectionTypes[content["value"]] = "BOOL"
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   750
                        for link in content["value"].getconnections():
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   751
                            connected = self.GetLinkedConnector(link, body)
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   752
                            if connected is not None and not self.ConnectionTypes.has_key(connected):
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   753
                                for related in self.ExtractRelatedConnections(connected):
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   754
                                    self.ConnectionTypes[related] = "BOOL"
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   755
                elif isinstance(instance, ContinuationClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   756
                    name = instance.getname()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   757
                    connector = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   758
                    var_type = "ANY"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   759
                    for element in body.getcontentInstances():
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   760
                        if isinstance(element, ConnectorClass) and element.getname() == name:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   761
                            if connector is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   762
                                raise PLCGenException, _("More than one connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   763
                            connector = element
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   764
                    if connector is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   765
                        undefined = [instance.connectionPointOut, connector.connectionPointIn]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   766
                        connected = self.GetConnectedConnector(connector.connectionPointIn, body)
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   767
                        if connected is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   768
                            undefined.append(connected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   769
                        related = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   770
                        for connection in undefined:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   771
                            if self.ConnectionTypes.has_key(connection):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   772
                                var_type = self.ConnectionTypes[connection]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   773
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   774
                                related.extend(self.ExtractRelatedConnections(connection))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   775
                        if var_type.startswith("ANY") and len(related) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   776
                            self.RelatedConnections.append(related)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   777
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   778
                            for connection in related:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   779
                                self.ConnectionTypes[connection] = var_type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   780
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   781
                        raise PLCGenException, _("No connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   782
                elif isinstance(instance, BlockClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   783
                    block_infos = self.GetBlockType(instance.gettypeName(), "undefined")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   784
                    if block_infos is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   785
                        self.ComputeBlockInputTypes(instance, block_infos, body)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   786
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   787
                        for variable in instance.inputVariables.getvariable():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   788
                            connected = self.GetConnectedConnector(variable.connectionPointIn, body)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   789
                            if connected is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   790
                                var_type = self.ConnectionTypes.get(connected, None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   791
                                if var_type is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   792
                                    self.ConnectionTypes[variable.connectionPointIn] = var_type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   793
                                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   794
                                    related = self.ExtractRelatedConnections(connected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   795
                                    related.append(variable.connectionPointIn)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   796
                                    self.RelatedConnections.append(related)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   797
                        undefined_blocks.append(instance)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   798
            for instance in undefined_blocks:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   799
                block_infos = self.GetBlockType(instance.gettypeName(), tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in instance.inputVariables.getvariable() if variable.getformalParameter() != "EN"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   800
                if block_infos is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   801
                    self.ComputeBlockInputTypes(instance, block_infos, body)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   802
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   803
                    raise PLCGenException, _("No informations found for \"%s\" block")%(instance.gettypeName())
822
050045c32d98 Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents: 814
diff changeset
   804
            if body_type == "SFC":
050045c32d98 Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents: 814
diff changeset
   805
                previous_tagname = self.TagName
050045c32d98 Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents: 814
diff changeset
   806
                for action in pou.getactionList():
050045c32d98 Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents: 814
diff changeset
   807
                    self.TagName = self.ParentGenerator.Controler.ComputePouActionName(self.Name, action.getname())
050045c32d98 Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents: 814
diff changeset
   808
                    self.ComputeConnectionTypes(action)
050045c32d98 Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents: 814
diff changeset
   809
                for transition in pou.gettransitionList():
050045c32d98 Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents: 814
diff changeset
   810
                    self.TagName = self.ParentGenerator.Controler.ComputePouTransitionName(self.Name, transition.getname())
050045c32d98 Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents: 814
diff changeset
   811
                    self.ComputeConnectionTypes(transition)
050045c32d98 Fix bug in PLCGenerator connection types not computed for SFC actions and transitions body
laurent
parents: 814
diff changeset
   812
                self.TagName = previous_tagname
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   813
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   814
    def ComputeBlockInputTypes(self, instance, block_infos, body):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   815
        undefined = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   816
        for variable in instance.outputVariables.getvariable():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   817
            output_name = variable.getformalParameter()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   818
            if output_name == "ENO":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   819
                for connection in self.ExtractRelatedConnections(variable.connectionPointOut):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   820
                    self.ConnectionTypes[connection] = "BOOL"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   821
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   822
                for oname, otype, oqualifier in block_infos["outputs"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   823
                    if output_name == oname:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   824
                        if otype.startswith("ANY"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   825
                            if not undefined.has_key(otype):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   826
                                undefined[otype] = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   827
                            undefined[otype].append(variable.connectionPointOut)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   828
                        elif not self.ConnectionTypes.has_key(variable.connectionPointOut):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   829
                            for connection in self.ExtractRelatedConnections(variable.connectionPointOut):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   830
                                self.ConnectionTypes[connection] = otype
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   831
        for variable in instance.inputVariables.getvariable():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   832
            input_name = variable.getformalParameter()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   833
            if input_name == "EN":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   834
                for connection in self.ExtractRelatedConnections(variable.connectionPointIn):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   835
                    self.ConnectionTypes[connection] = "BOOL"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   836
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   837
                for iname, itype, iqualifier in block_infos["inputs"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   838
                    if input_name == iname:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   839
                        connected = self.GetConnectedConnector(variable.connectionPointIn, body)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   840
                        if itype.startswith("ANY"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   841
                            if not undefined.has_key(itype):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   842
                                undefined[itype] = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   843
                            undefined[itype].append(variable.connectionPointIn)
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   844
                            if connected is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   845
                                undefined[itype].append(connected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   846
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   847
                            self.ConnectionTypes[variable.connectionPointIn] = itype
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   848
                            if connected is not None and not self.ConnectionTypes.has_key(connected):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   849
                                for connection in self.ExtractRelatedConnections(connected):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   850
                                    self.ConnectionTypes[connection] = itype
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   851
        for var_type, connections in undefined.items():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   852
            related = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   853
            for connection in connections:
854
c10f2092c43a Fixing bug in PLCGenerator with user defined functions and standard overloaded function
Laurent Bessard
parents: 822
diff changeset
   854
                connection_type = self.ConnectionTypes.get(connection)
c10f2092c43a Fixing bug in PLCGenerator with user defined functions and standard overloaded function
Laurent Bessard
parents: 822
diff changeset
   855
                if connection_type and not connection_type.startswith("ANY"):
c10f2092c43a Fixing bug in PLCGenerator with user defined functions and standard overloaded function
Laurent Bessard
parents: 822
diff changeset
   856
                    var_type = connection_type
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   857
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   858
                    related.extend(self.ExtractRelatedConnections(connection))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   859
            if var_type.startswith("ANY") and len(related) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   860
                self.RelatedConnections.append(related)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   861
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   862
                for connection in related:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   863
                    self.ConnectionTypes[connection] = var_type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   864
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   865
    def ComputeProgram(self, pou):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   866
        body = pou.getbody()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   867
        if isinstance(body, ListType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   868
            body = body[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   869
        body_content = body.getcontent()
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   870
        body_type = body_content.getLocalTag()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   871
        if body_type in ["IL","ST"]:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   872
            text = body_content.getanyText()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   873
            self.ParentGenerator.GeneratePouProgramInText(text.upper())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   874
            self.Program = [(ReIndentText(text, len(self.CurrentIndent)), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   875
                            (self.TagName, "body", len(self.CurrentIndent)))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   876
        elif body_type == "SFC":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   877
            self.IndentRight()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   878
            for instance in body.getcontentInstances():
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   879
                if isinstance(instance, StepClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   880
                    self.GenerateSFCStep(instance, pou)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   881
                elif isinstance(instance, ActionBlockClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   882
                    self.GenerateSFCStepActions(instance, pou)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   883
                elif isinstance(instance, TransitionClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   884
                    self.GenerateSFCTransition(instance, pou)
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   885
                elif isinstance(instance, JumpStepClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   886
                    self.GenerateSFCJump(instance, pou)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   887
            if len(self.InitialSteps) > 0 and len(self.SFCComputedBlocks) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   888
                action_name = "COMPUTE_FUNCTION_BLOCKS"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   889
                action_infos = {"qualifier" : "S", "content" : action_name}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   890
                self.SFCNetworks["Steps"][self.InitialSteps[0]]["actions"].append(action_infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   891
                self.SFCNetworks["Actions"][action_name] = (self.SFCComputedBlocks, ())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   892
                self.Program = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   893
            self.IndentLeft()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   894
            for initialstep in self.InitialSteps:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   895
                self.ComputeSFCStep(initialstep)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   896
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   897
            otherInstances = {"outVariables&coils" : [], "blocks" : [], "connectors" : []}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   898
            orderedInstances = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   899
            for instance in body.getcontentInstances():
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   900
                if isinstance(instance, (OutVariableClass, InOutVariableClass, BlockClass)):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   901
                    executionOrderId = instance.getexecutionOrderId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   902
                    if executionOrderId > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   903
                        orderedInstances.append((executionOrderId, instance))
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   904
                    elif isinstance(instance, (OutVariableClass, InOutVariableClass)):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   905
                        otherInstances["outVariables&coils"].append(instance)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   906
                    elif isinstance(instance, BlockClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   907
                        otherInstances["blocks"].append(instance)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   908
                elif isinstance(instance, ConnectorClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   909
                    otherInstances["connectors"].append(instance)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   910
                elif isinstance(instance, CoilClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   911
                    otherInstances["outVariables&coils"].append(instance)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   912
            orderedInstances.sort()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   913
            otherInstances["outVariables&coils"].sort(SortInstances)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   914
            otherInstances["blocks"].sort(SortInstances)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   915
            instances = [instance for (executionOrderId, instance) in orderedInstances]
1048
b450202605ab Fixed bug in program elements computation order in PLCGenerator
Laurent Bessard
parents: 1032
diff changeset
   916
            instances.extend(otherInstances["outVariables&coils"] + otherInstances["blocks"] + otherInstances["connectors"])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   917
            for instance in instances:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   918
                if isinstance(instance, (OutVariableClass, InOutVariableClass)):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   919
                    connections = instance.connectionPointIn.getconnections()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   920
                    if connections is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   921
                        expression = self.ComputeExpression(body, connections)
1239
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   922
                        if expression is not None:
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   923
                            self.Program += [(self.CurrentIndent, ()),
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   924
                                             (instance.getexpression().text, (self.TagName, "io_variable", instance.getlocalId(), "expression")),
1239
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   925
                                             (" := ", ())]
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   926
                            self.Program += expression
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   927
                            self.Program += [(";\n", ())]
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   928
                elif isinstance(instance, BlockClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   929
                    block_type = instance.gettypeName()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   930
                    self.ParentGenerator.GeneratePouProgram(block_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   931
                    block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in instance.inputVariables.getvariable() if variable.getformalParameter() != "EN"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   932
                    if block_infos is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   933
                        block_infos = self.GetBlockType(block_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   934
                    if block_infos is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   935
                        raise PLCGenException, _("Undefined block type \"%s\" in \"%s\" POU")%(block_type, self.Name)
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 1048
diff changeset
   936
                    try:
1310
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   937
                        self.GenerateBlock(instance, block_infos, body, None)
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 1048
diff changeset
   938
                    except ValueError, e:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 1048
diff changeset
   939
                        raise PLCGenException, e.message
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   940
                elif isinstance(instance, ConnectorClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   941
                    connector = instance.getname()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   942
                    if self.ComputedConnectors.get(connector, None):
1239
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   943
                        continue
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   944
                    expression = self.ComputeExpression(body, instance.connectionPointIn.getconnections())
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   945
                    if expression is not None:
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   946
                        self.ComputedConnectors[connector] = expression
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   947
                elif isinstance(instance, CoilClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   948
                    connections = instance.connectionPointIn.getconnections()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   949
                    if connections is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   950
                        coil_info = (self.TagName, "coil", instance.getlocalId())
1239
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   951
                        expression = self.ComputeExpression(body, connections)
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   952
                        if expression is not None:
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   953
                            expression = self.ExtractModifier(instance, expression, coil_info)
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   954
                            self.Program += [(self.CurrentIndent, ())]
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
   955
                            self.Program += [(instance.getvariable().text, coil_info + ("reference",))]
1239
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
   956
                            self.Program += [(" := ", ())] + expression + [(";\n", ())]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   957
                        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   958
    def FactorizePaths(self, paths):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   959
        same_paths = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   960
        uncomputed_index = range(len(paths))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   961
        factorized_paths = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   962
        for num, path in enumerate(paths):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   963
            if type(path) == ListType:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   964
                if len(path) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   965
                    str_path = str(path[-1:])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   966
                    same_paths.setdefault(str_path, [])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   967
                    same_paths[str_path].append((path[:-1], num))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   968
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   969
                factorized_paths.append(path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   970
                uncomputed_index.remove(num)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   971
        for same_path, elements in same_paths.items():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   972
            if len(elements) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   973
                elements_paths = self.FactorizePaths([path for path, num in elements])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   974
                if len(elements_paths) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   975
                    factorized_paths.append([tuple(elements_paths)] + eval(same_path))        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   976
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   977
                    factorized_paths.append(elements_paths + eval(same_path))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   978
                for path, num in elements:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   979
                    uncomputed_index.remove(num)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   980
        for num in uncomputed_index:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   981
            factorized_paths.append(paths[num])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   982
        factorized_paths.sort()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   983
        return factorized_paths
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   984
1310
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   985
    def GenerateBlock(self, block, block_infos, body, link, order=False, to_inout=False):
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   986
        body_type = body.getcontent().getLocalTag()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   987
        name = block.getinstanceName()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   988
        type = block.gettypeName()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   989
        executionOrderId = block.getexecutionOrderId()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   990
        input_variables = block.inputVariables.getvariable()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   991
        output_variables = block.outputVariables.getvariable()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   992
        inout_variables = {}
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   993
        for input_variable in input_variables:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   994
            for output_variable in output_variables:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   995
                if input_variable.getformalParameter() == output_variable.getformalParameter():
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   996
                    inout_variables[input_variable.getformalParameter()] = ""
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   997
        input_names = [input[0] for input in block_infos["inputs"]]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   998
        output_names = [output[0] for output in block_infos["outputs"]]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
   999
        if block_infos["type"] == "function":
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1000
            if not self.ComputedBlocks.get(block, False) and not order:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1001
                self.ComputedBlocks[block] = True
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1002
                connected_vars = []
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1003
                if not block_infos["extensible"]:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1004
                    input_connected = dict([("EN", None)] + 
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1005
                                           [(input_name, None) for input_name in input_names])
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1006
                    for variable in input_variables:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1007
                        parameter = variable.getformalParameter()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1008
                        if input_connected.has_key(parameter):
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1009
                            input_connected[parameter] = variable
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1010
                    if input_connected["EN"] is None:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1011
                        input_connected.pop("EN")
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1012
                        input_parameters = input_names
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1013
                    else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1014
                        input_parameters = ["EN"] + input_names
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1015
                else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1016
                    input_connected = dict([(variable.getformalParameter(), variable)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1017
                                            for variable in input_variables])
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1018
                    input_parameters = [variable.getformalParameter()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1019
                                        for variable in input_variables]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1020
                one_input_connected = False
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1021
                all_input_connected = True
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1022
                for i, parameter in enumerate(input_parameters):
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1023
                    variable = input_connected.get(parameter)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1024
                    if variable is not None:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1025
                        input_info = (self.TagName, "block", block.getlocalId(), "input", i)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1026
                        connections = variable.connectionPointIn.getconnections()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1027
                        if connections is not None:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1028
                            if parameter != "EN":
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1029
                                one_input_connected = True
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1030
                            if inout_variables.has_key(parameter):
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1031
                                expression = self.ComputeExpression(body, connections, executionOrderId > 0, True)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1032
                                if expression is not None:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1033
                                    inout_variables[parameter] = value
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1034
                            else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1035
                                expression = self.ComputeExpression(body, connections, executionOrderId > 0)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1036
                            if expression is not None:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1037
                                connected_vars.append(([(parameter, input_info), (" := ", ())],
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1038
                                                       self.ExtractModifier(variable, expression, input_info)))
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1039
                        else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1040
                            all_input_connected = False
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1041
                    else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1042
                        all_input_connected = False
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1043
                if len(output_variables) > 1 or not all_input_connected:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1044
                    vars = [name + value for name, value in connected_vars]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1045
                else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1046
                    vars = [value for name, value in connected_vars]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1047
                if one_input_connected:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1048
                    for i, variable in enumerate(output_variables):
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1049
                        parameter = variable.getformalParameter()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1050
                        if not inout_variables.has_key(parameter) and parameter in output_names + ["", "ENO"]:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1051
                            if variable.getformalParameter() == "":
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1052
                                variable_name = "%s%d"%(type, block.getlocalId())
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1053
                            else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1054
                                variable_name = "%s%d_%s"%(type, block.getlocalId(), parameter)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1055
                            if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] is not None or self.Interface[-1][2]:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1056
                                self.Interface.append(("VAR", None, False, []))
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1057
                            if variable.connectionPointOut in self.ConnectionTypes:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1058
                                self.Interface[-1][3].append((self.ConnectionTypes[variable.connectionPointOut], variable_name, None, None))
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1059
                            else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1060
                                self.Interface[-1][3].append(("ANY", variable_name, None, None))
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1061
                            if len(output_variables) > 1 and parameter not in ["", "OUT"]:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1062
                                vars.append([(parameter, (self.TagName, "block", block.getlocalId(), "output", i)), 
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1063
                                             (" => %s"%variable_name, ())])
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1064
                            else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1065
                                output_info = (self.TagName, "block", block.getlocalId(), "output", i)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1066
                                output_name = variable_name
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1067
                    self.Program += [(self.CurrentIndent, ()),
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1068
                                     (output_name, output_info),
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1069
                                     (" := ", ()),
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1070
                                     (type, (self.TagName, "block", block.getlocalId(), "type")),
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1071
                                     ("(", ())]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1072
                    self.Program += JoinList([(", ", ())], vars)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1073
                    self.Program += [(");\n", ())]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1074
                else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1075
                    self.Warnings.append(_("\"%s\" function cancelled in \"%s\" POU: No input connected")%(type, self.TagName.split("::")[-1]))
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1076
        elif block_infos["type"] == "functionBlock":
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1077
            if not self.ComputedBlocks.get(block, False) and not order:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1078
                self.ComputedBlocks[block] = True
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1079
                vars = []
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1080
                offset_idx = 0
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1081
                for variable in input_variables:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1082
                    parameter = variable.getformalParameter()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1083
                    if parameter in input_names or parameter == "EN":
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1084
                        if parameter == "EN":
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1085
                            input_idx = 0
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1086
                            offset_idx = 1
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1087
                        else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1088
                            input_idx = offset_idx + input_names.index(parameter)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1089
                        input_info = (self.TagName, "block", block.getlocalId(), "input", input_idx)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1090
                        connections = variable.connectionPointIn.getconnections()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1091
                        if connections is not None:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1092
                            expression = self.ComputeExpression(body, connections, executionOrderId > 0, inout_variables.has_key(parameter))
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1093
                            if expression is not None:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1094
                                vars.append([(parameter, input_info),
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1095
                                             (" := ", ())] + self.ExtractModifier(variable, expression, input_info))
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1096
                self.Program += [(self.CurrentIndent, ()), 
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1097
                                 (name, (self.TagName, "block", block.getlocalId(), "name")),
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1098
                                 ("(", ())]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1099
                self.Program += JoinList([(", ", ())], vars)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1100
                self.Program += [(");\n", ())]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1101
        
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1102
        if link is not None:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1103
            connectionPoint = link.getposition()[-1]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1104
            output_parameter = link.getformalParameter()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1105
        else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1106
            connectionPoint = None
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1107
            output_parameter = None
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1108
        
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1109
        output_variable = None
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1110
        output_idx = 0
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1111
        if output_parameter is not None:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1112
            if output_parameter in output_names or output_parameter == "ENO":
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1113
                for variable in output_variables:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1114
                    if variable.getformalParameter() == output_parameter:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1115
                        output_variable = variable
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1116
                        if output_parameter != "ENO":
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1117
                            output_idx = output_names.index(output_parameter)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1118
        else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1119
            for i, variable in enumerate(output_variables):
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1120
                blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1121
                if (connectionPoint is None or 
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1122
                    block.getx() + blockPointx == connectionPoint.getx() and 
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1123
                    block.gety() + blockPointy == connectionPoint.gety()):
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1124
                    output_variable = variable
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1125
                    output_parameter = variable.getformalParameter()
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1126
                    output_idx = i
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1127
        
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1128
        if output_variable is not None:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1129
            if block_infos["type"] == "function":
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1130
                output_info = (self.TagName, "block", block.getlocalId(), "output", output_idx)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1131
                if inout_variables.has_key(output_parameter):
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1132
                    output_value = inout_variables[output_parameter]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1133
                else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1134
                    if output_parameter == "":
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1135
                        output_name = "%s%d"%(type, block.getlocalId())
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1136
                    else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1137
                        output_name = "%s%d_%s"%(type, block.getlocalId(), output_parameter)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1138
                    output_value = [(output_name, output_info)]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1139
                return self.ExtractModifier(output_variable, output_value, output_info)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1140
            
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1141
            if block_infos["type"] == "functionBlock":
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1142
                output_info = (self.TagName, "block", block.getlocalId(), "output", output_idx)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1143
                output_name = self.ExtractModifier(output_variable, [("%s.%s"%(name, output_parameter), output_info)], output_info)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1144
                if to_inout:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1145
                    variable_name = "%s_%s"%(name, output_parameter)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1146
                    if not self.IsAlreadyDefined(variable_name):
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1147
                        if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] is not None or self.Interface[-1][2]:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1148
                            self.Interface.append(("VAR", None, False, []))
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1149
                        if variable.connectionPointOut in self.ConnectionTypes:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1150
                            self.Interface[-1][3].append(
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1151
                                (self.ConnectionTypes[output_variable.connectionPointOut], variable_name, None, None))
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1152
                        else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1153
                            self.Interface[-1][3].append(("ANY", variable_name, None, None))
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1154
                        self.Program += [(self.CurrentIndent, ()),
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1155
                                         ("%s := "%variable_name, ())]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1156
                        self.Program += output_name
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1157
                        self.Program += [(";\n", ())]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1158
                    return [(variable_name, ())]
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1159
                return output_name 
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1160
        if link is not None:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1161
            if output_parameter is None:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1162
                output_parameter = ""
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1163
            if name:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1164
                blockname = "%s(%s)" % (name, type)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1165
            else:
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1166
                blockname = type
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1167
            raise ValueError, _("No output %s variable found in block %s in POU %s. Connection must be broken")  % \
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1168
                              (output_parameter, blockname, self.Name)
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1169
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1170
    def GeneratePaths(self, connections, body, order = False, to_inout = False):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1171
        paths = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1172
        for connection in connections:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1173
            localId = connection.getrefLocalId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1174
            next = body.getcontentInstance(localId)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1175
            if isinstance(next, LeftPowerRailClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1176
                paths.append(None)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1177
            elif isinstance(next, (InVariableClass, InOutVariableClass)):
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1178
                paths.append(str([(next.getexpression().text, (self.TagName, "io_variable", localId, "expression"))]))
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1179
            elif isinstance(next, BlockClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1180
                block_type = next.gettypeName()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1181
                self.ParentGenerator.GeneratePouProgram(block_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1182
                block_infos = self.GetBlockType(block_type, tuple([self.ConnectionTypes.get(variable.connectionPointIn, "ANY") for variable in next.inputVariables.getvariable() if variable.getformalParameter() != "EN"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1183
                if block_infos is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1184
                    block_infos = self.GetBlockType(block_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1185
                if block_infos is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1186
                    raise PLCGenException, _("Undefined block type \"%s\" in \"%s\" POU")%(block_type, self.Name)
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 1048
diff changeset
  1187
                try:
1310
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1188
                    paths.append(str(self.GenerateBlock(next, block_infos, body, connection, order, to_inout)))
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 1048
diff changeset
  1189
                except ValueError, e:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 1048
diff changeset
  1190
                    raise PLCGenException, e.message
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1191
            elif isinstance(next, ContinuationClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1192
                name = next.getname()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1193
                computed_value = self.ComputedConnectors.get(name, None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1194
                if computed_value != None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1195
                    paths.append(str(computed_value))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1196
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1197
                    connector = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1198
                    for instance in body.getcontentInstances():
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1199
                        if isinstance(instance, ConnectorClass) and instance.getname() == name:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1200
                            if connector is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1201
                                raise PLCGenException, _("More than one connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1202
                            connector = instance
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1203
                    if connector is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1204
                        connections = connector.connectionPointIn.getconnections()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1205
                        if connections is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1206
                            expression = self.ComputeExpression(body, connections, order)
1239
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1207
                            if expression is not None:
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1208
                                self.ComputedConnectors[name] = expression
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1209
                                paths.append(str(expression))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1210
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1211
                        raise PLCGenException, _("No connector found corresponding to \"%s\" continuation in \"%s\" POU")%(name, self.Name)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1212
            elif isinstance(next, ContactClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1213
                contact_info = (self.TagName, "contact", next.getlocalId())
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1214
                variable = str(self.ExtractModifier(next, [(next.getvariable().text, contact_info + ("reference",))], contact_info))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1215
                result = self.GeneratePaths(next.connectionPointIn.getconnections(), body, order)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1216
                if len(result) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1217
                    factorized_paths = self.FactorizePaths(result)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1218
                    if len(factorized_paths) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1219
                        paths.append([variable, tuple(factorized_paths)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1220
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1221
                        paths.append([variable] + factorized_paths)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1222
                elif type(result[0]) == ListType:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1223
                    paths.append([variable] + result[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1224
                elif result[0] is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1225
                    paths.append([variable, result[0]])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1226
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1227
                    paths.append(variable)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1228
            elif isinstance(next, CoilClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1229
                paths.append(str(self.GeneratePaths(next.connectionPointIn.getconnections(), body, order)))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1230
        return paths
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1231
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1232
    def ComputePaths(self, paths, first = False):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1233
        if type(paths) == TupleType:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1234
            if None in paths:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1235
                return [("TRUE", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1236
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1237
                vars = [self.ComputePaths(path) for path in paths]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1238
                if first:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1239
                    return JoinList([(" OR ", ())], vars)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1240
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1241
                    return [("(", ())] + JoinList([(" OR ", ())], vars) + [(")", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1242
        elif type(paths) == ListType:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1243
            vars = [self.ComputePaths(path) for path in paths]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1244
            return JoinList([(" AND ", ())], vars)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1245
        elif paths is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1246
            return [("TRUE", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1247
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1248
            return eval(paths)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1249
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1250
    def ComputeExpression(self, body, connections, order = False, to_inout = False):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1251
        paths = self.GeneratePaths(connections, body, order, to_inout)
1239
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1252
        if len(paths) == 0:
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1253
            return None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1254
        if len(paths) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1255
            factorized_paths = self.FactorizePaths(paths)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1256
            if len(factorized_paths) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1257
                paths = tuple(factorized_paths)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1258
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1259
                paths = factorized_paths[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1260
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1261
            paths = paths[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1262
        return self.ComputePaths(paths, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1263
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1264
    def ExtractModifier(self, variable, expression, var_info):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1265
        if variable.getnegated():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1266
            return [("NOT(", var_info + ("negated",))] + expression + [(")", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1267
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1268
            storage = variable.getstorage()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1269
            if storage in ["set", "reset"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1270
                self.Program += [(self.CurrentIndent + "IF ", var_info + (storage,))] + expression
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1271
                self.Program += [(" THEN\n  ", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1272
                if storage == "set":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1273
                    return [("TRUE; (*set*)\n" + self.CurrentIndent + "END_IF", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1274
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1275
                    return [("FALSE; (*reset*)\n" + self.CurrentIndent + "END_IF", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1276
            edge = variable.getedge()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1277
            if edge == "rising":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1278
                return self.AddTrigger("R_TRIG", expression, var_info + ("rising",))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1279
            elif edge == "falling":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1280
                return self.AddTrigger("F_TRIG", expression, var_info + ("falling",))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1281
        return expression
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1282
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1283
    def AddTrigger(self, edge, expression, var_info):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1284
        if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] is not None or self.Interface[-1][2]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1285
            self.Interface.append(("VAR", None, False, []))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1286
        i = 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1287
        name = "%s%d"%(edge, i)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1288
        while self.IsAlreadyDefined(name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1289
            i += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1290
            name = "%s%d"%(edge, i)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1291
        self.Interface[-1][3].append((edge, name, None, None))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1292
        self.Program += [(self.CurrentIndent, ()), (name, var_info), ("(CLK := ", ())] 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1293
        self.Program += expression
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1294
        self.Program += [(");\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1295
        return [("%s.Q"%name, var_info)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1296
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1297
    def ExtractDivergenceInput(self, divergence, pou):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1298
        connectionPointIn = divergence.getconnectionPointIn()
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1299
        if connectionPointIn is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1300
            connections = connectionPointIn.getconnections()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1301
            if connections is not None and len(connections) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1302
                instanceLocalId = connections[0].getrefLocalId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1303
                body = pou.getbody()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1304
                if isinstance(body, ListType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1305
                    body = body[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1306
                return body.getcontentInstance(instanceLocalId)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1307
        return None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1308
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1309
    def ExtractConvergenceInputs(self, convergence, pou):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1310
        instances = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1311
        for connectionPointIn in convergence.getconnectionPointIn():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1312
            connections = connectionPointIn.getconnections()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1313
            if connections is not None and len(connections) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1314
                instanceLocalId = connections[0].getrefLocalId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1315
                body = pou.getbody()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1316
                if isinstance(body, ListType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1317
                    body = body[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1318
                instances.append(body.getcontentInstance(instanceLocalId))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1319
        return instances
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1320
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1321
    def GenerateSFCStep(self, step, pou):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1322
        step_name = step.getname()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1323
        if step_name not in self.SFCNetworks["Steps"].keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1324
            if step.getinitialStep():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1325
                self.InitialSteps.append(step_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1326
            step_infos = {"id" : step.getlocalId(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1327
                          "initial" : step.getinitialStep(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1328
                          "transitions" : [], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1329
                          "actions" : []}
889
ac18acb6917f Fix bug when using feedback loop in SFC program instead of jump
Laurent Bessard
parents: 883
diff changeset
  1330
            self.SFCNetworks["Steps"][step_name] = step_infos
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1331
            if step.connectionPointIn is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1332
                instances = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1333
                connections = step.connectionPointIn.getconnections()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1334
                if connections is not None and len(connections) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1335
                    instanceLocalId = connections[0].getrefLocalId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1336
                    body = pou.getbody()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1337
                    if isinstance(body, ListType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1338
                        body = body[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1339
                    instance = body.getcontentInstance(instanceLocalId)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1340
                    if isinstance(instance, TransitionClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1341
                        instances.append(instance)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1342
                    elif isinstance(instance, SelectionConvergenceClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1343
                        instances.extend(self.ExtractConvergenceInputs(instance, pou))
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1344
                    elif isinstance(instance, SimultaneousDivergenceClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1345
                        transition = self.ExtractDivergenceInput(instance, pou)
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1346
                        if transition is not None:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1347
                            if isinstance(transition, TransitionClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1348
                                instances.append(transition)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1349
                            elif isinstance(transition, SelectionConvergenceClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1350
                                instances.extend(self.ExtractConvergenceInputs(transition, pou))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1351
                for instance in instances:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1352
                    self.GenerateSFCTransition(instance, pou)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1353
                    if instance in self.SFCNetworks["Transitions"].keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1354
                        target_info = (self.TagName, "transition", instance.getlocalId(), "to", step_infos["id"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1355
                        self.SFCNetworks["Transitions"][instance]["to"].append([(step_name, target_info)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1356
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1357
    def GenerateSFCJump(self, jump, pou):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1358
        jump_target = jump.gettargetName()
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1359
        if jump.connectionPointIn is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1360
            instances = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1361
            connections = jump.connectionPointIn.getconnections()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1362
            if connections is not None and len(connections) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1363
                instanceLocalId = connections[0].getrefLocalId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1364
                body = pou.getbody()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1365
                if isinstance(body, ListType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1366
                    body = body[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1367
                instance = body.getcontentInstance(instanceLocalId)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1368
                if isinstance(instance, TransitionClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1369
                    instances.append(instance)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1370
                elif isinstance(instance, SelectionConvergenceClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1371
                    instances.extend(self.ExtractConvergenceInputs(instance, pou))
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1372
                elif isinstance(instance, SimultaneousDivergenceClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1373
                    transition = self.ExtractDivergenceInput(instance, pou)
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1374
                    if transition is not None:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1375
                        if isinstance(transition, TransitionClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1376
                            instances.append(transition)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1377
                        elif isinstance(transition, SelectionConvergenceClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1378
                            instances.extend(self.ExtractConvergenceInputs(transition, pou))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1379
            for instance in instances:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1380
                self.GenerateSFCTransition(instance, pou)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1381
                if instance in self.SFCNetworks["Transitions"].keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1382
                    target_info = (self.TagName, "jump", jump.getlocalId(), "target")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1383
                    self.SFCNetworks["Transitions"][instance]["to"].append([(jump_target, target_info)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1384
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1385
    def GenerateSFCStepActions(self, actionBlock, pou):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1386
        connections = actionBlock.connectionPointIn.getconnections()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1387
        if connections is not None and len(connections) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1388
            stepLocalId = connections[0].getrefLocalId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1389
            body = pou.getbody()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1390
            if isinstance(body, ListType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1391
                body = body[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1392
            step = body.getcontentInstance(stepLocalId)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1393
            self.GenerateSFCStep(step, pou)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1394
            step_name = step.getname()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1395
            if step_name in self.SFCNetworks["Steps"].keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1396
                actions = actionBlock.getactions()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1397
                for i, action in enumerate(actions):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1398
                    action_infos = {"id" : actionBlock.getlocalId(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1399
                                    "qualifier" : action["qualifier"], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1400
                                    "content" : action["value"],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1401
                                    "num" : i}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1402
                    if "duration" in action:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1403
                        action_infos["duration"] = action["duration"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1404
                    if "indicator" in action:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1405
                        action_infos["indicator"] = action["indicator"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1406
                    if action["type"] == "reference":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1407
                        self.GenerateSFCAction(action["value"], pou)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1408
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1409
                        action_name = "%s_INLINE%d"%(step_name.upper(), self.GetActionNumber())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1410
                        self.SFCNetworks["Actions"][action_name] = ([(self.CurrentIndent, ()), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1411
                            (action["value"], (self.TagName, "action_block", action_infos["id"], "action", i, "inline")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1412
                            ("\n", ())], ())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1413
                        action_infos["content"] = action_name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1414
                    self.SFCNetworks["Steps"][step_name]["actions"].append(action_infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1415
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1416
    def GenerateSFCAction(self, action_name, pou):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1417
        if action_name not in self.SFCNetworks["Actions"].keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1418
            actionContent = pou.getaction(action_name)
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1419
            if actionContent is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1420
                previous_tagname = self.TagName
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1421
                self.TagName = self.ParentGenerator.Controler.ComputePouActionName(self.Name, action_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1422
                self.ComputeProgram(actionContent)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1423
                self.SFCNetworks["Actions"][action_name] = (self.Program, (self.TagName, "name"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1424
                self.Program = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1425
                self.TagName = previous_tagname
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1426
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1427
    def GenerateSFCTransition(self, transition, pou):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1428
        if transition not in self.SFCNetworks["Transitions"].keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1429
            steps = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1430
            connections = transition.connectionPointIn.getconnections()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1431
            if connections is not None and len(connections) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1432
                instanceLocalId = connections[0].getrefLocalId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1433
                body = pou.getbody()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1434
                if isinstance(body, ListType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1435
                    body = body[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1436
                instance = body.getcontentInstance(instanceLocalId)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1437
                if isinstance(instance, StepClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1438
                    steps.append(instance)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1439
                elif isinstance(instance, SelectionDivergenceClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1440
                    step = self.ExtractDivergenceInput(instance, pou)
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1441
                    if step is not None:
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1442
                        if isinstance(step, StepClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1443
                            steps.append(step)
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1444
                        elif isinstance(step, SimultaneousConvergenceClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1445
                            steps.extend(self.ExtractConvergenceInputs(step, pou))
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1446
                elif isinstance(instance, SimultaneousConvergenceClass):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1447
                    steps.extend(self.ExtractConvergenceInputs(instance, pou))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1448
            transition_infos = {"id" : transition.getlocalId(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1449
                                "priority": transition.getpriority(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1450
                                "from": [], 
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1451
                                "to" : [],
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1452
                                "content": []}
889
ac18acb6917f Fix bug when using feedback loop in SFC program instead of jump
Laurent Bessard
parents: 883
diff changeset
  1453
            self.SFCNetworks["Transitions"][transition] = transition_infos
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1454
            transitionValues = transition.getconditionContent()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1455
            if transitionValues["type"] == "inline":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1456
                transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1457
                                               (transitionValues["value"], (self.TagName, "transition", transition.getlocalId(), "inline")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1458
                                               (";\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1459
            elif transitionValues["type"] == "reference":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1460
                transitionContent = pou.gettransition(transitionValues["value"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1461
                transitionType = transitionContent.getbodyType()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1462
                transitionBody = transitionContent.getbody()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1463
                previous_tagname = self.TagName
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1464
                self.TagName = self.ParentGenerator.Controler.ComputePouTransitionName(self.Name, transitionValues["value"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1465
                if transitionType == "IL":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1466
                    transition_infos["content"] = [(":\n", ()),
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1467
                                                   (ReIndentText(transitionBody.getanyText(), len(self.CurrentIndent)), (self.TagName, "body", len(self.CurrentIndent)))]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1468
                elif transitionType == "ST":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1469
                    transition_infos["content"] = [("\n", ()),
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1470
                                                   (ReIndentText(transitionBody.getanyText(), len(self.CurrentIndent)), (self.TagName, "body", len(self.CurrentIndent)))]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1471
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1472
                    for instance in transitionBody.getcontentInstances():
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1473
                        if isinstance(instance, OutVariableClass) and instance.getexpression().text == transitionValues["value"]\
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1239
diff changeset
  1474
                            or isinstance(instance, CoilClass) and instance.getvariable().text == transitionValues["value"]:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1475
                            connections = instance.connectionPointIn.getconnections()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1476
                            if connections is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1477
                                expression = self.ComputeExpression(transitionBody, connections)
1239
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1478
                                if expression is not None:
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1479
                                    transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())]
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1480
                                    self.SFCComputedBlocks += self.Program
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1481
                                    self.Program = []
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1482
                    if not transition_infos.has_key("content"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1483
                        raise PLCGenException, _("Transition \"%s\" body must contain an output variable or coil referring to its name") % transitionValues["value"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1484
                self.TagName = previous_tagname
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1485
            elif transitionValues["type"] == "connection":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1486
                body = pou.getbody()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1487
                if isinstance(body, ListType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1488
                    body = body[0]
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1489
                connections = transitionValues["value"].getconnections()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1490
                if connections is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1491
                    expression = self.ComputeExpression(body, connections)
1239
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1492
                    if expression is not None:
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1493
                        transition_infos["content"] = [("\n%s:= "%self.CurrentIndent, ())] + expression + [(";\n", ())]
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1494
                        self.SFCComputedBlocks += self.Program
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1183
diff changeset
  1495
                        self.Program = []
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1496
            for step in steps:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1497
                self.GenerateSFCStep(step, pou)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1498
                step_name = step.getname()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1499
                if step_name in self.SFCNetworks["Steps"].keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1500
                    transition_infos["from"].append([(step_name, (self.TagName, "transition", transition.getlocalId(), "from", step.getlocalId()))])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1501
                    self.SFCNetworks["Steps"][step_name]["transitions"].append(transition)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1502
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1503
    def ComputeSFCStep(self, step_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1504
        if step_name in self.SFCNetworks["Steps"].keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1505
            step_infos = self.SFCNetworks["Steps"].pop(step_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1506
            self.Program += [(self.CurrentIndent, ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1507
            if step_infos["initial"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1508
                self.Program += [("INITIAL_", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1509
            self.Program += [("STEP ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1510
                             (step_name, (self.TagName, "step", step_infos["id"], "name")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1511
                             (":\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1512
            actions = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1513
            self.IndentRight()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1514
            for action_infos in step_infos["actions"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1515
                if action_infos.get("id", None) is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1516
                    action_info = (self.TagName, "action_block", action_infos["id"], "action", action_infos["num"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1517
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1518
                    action_info = ()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1519
                actions.append(action_infos["content"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1520
                self.Program += [(self.CurrentIndent, ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1521
                                 (action_infos["content"], action_info + ("reference",)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1522
                                 ("(", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1523
                                 (action_infos["qualifier"], action_info + ("qualifier",))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1524
                if "duration" in action_infos:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1525
                    self.Program += [(", ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1526
                                     (action_infos["duration"], action_info + ("duration",))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1527
                if "indicator" in action_infos:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1528
                    self.Program += [(", ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1529
                                     (action_infos["indicator"], action_info + ("indicator",))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1530
                self.Program += [(");\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1531
            self.IndentLeft()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1532
            self.Program += [("%sEND_STEP\n\n"%self.CurrentIndent, ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1533
            for action in actions:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1534
                self.ComputeSFCAction(action)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1535
            for transition in step_infos["transitions"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1536
                self.ComputeSFCTransition(transition)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1537
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1538
    def ComputeSFCAction(self, action_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1539
        if action_name in self.SFCNetworks["Actions"].keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1540
            action_content, action_info = self.SFCNetworks["Actions"].pop(action_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1541
            self.Program += [("%sACTION "%self.CurrentIndent, ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1542
                             (action_name, action_info),
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1543
                             (":\n", ())]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1544
            self.Program += action_content
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1545
            self.Program += [("%sEND_ACTION\n\n"%self.CurrentIndent, ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1546
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1547
    def ComputeSFCTransition(self, transition):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1548
        if transition in self.SFCNetworks["Transitions"].keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1549
            transition_infos = self.SFCNetworks["Transitions"].pop(transition)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1550
            self.Program += [("%sTRANSITION"%self.CurrentIndent, ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1551
            if transition_infos["priority"] != None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1552
                self.Program += [(" (PRIORITY := ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1553
                                 ("%d"%transition_infos["priority"], (self.TagName, "transition", transition_infos["id"], "priority")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1554
                                 (")", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1555
            self.Program += [(" FROM ", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1556
            if len(transition_infos["from"]) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1557
                self.Program += [("(", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1558
                self.Program += JoinList([(", ", ())], transition_infos["from"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1559
                self.Program += [(")", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1560
            elif len(transition_infos["from"]) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1561
                self.Program += transition_infos["from"][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1562
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1563
                raise PLCGenException, _("Transition with content \"%s\" not connected to a previous step in \"%s\" POU")%(transition_infos["content"], self.Name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1564
            self.Program += [(" TO ", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1565
            if len(transition_infos["to"]) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1566
                self.Program += [("(", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1567
                self.Program += JoinList([(", ", ())], transition_infos["to"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1568
                self.Program += [(")", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1569
            elif len(transition_infos["to"]) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1570
                self.Program += transition_infos["to"][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1571
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1572
                raise PLCGenException, _("Transition with content \"%s\" not connected to a next step in \"%s\" POU")%(transition_infos["content"], self.Name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1573
            self.Program += transition_infos["content"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1574
            self.Program += [("%sEND_TRANSITION\n\n"%self.CurrentIndent, ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1575
            for [(step_name, step_infos)] in transition_infos["to"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1576
                self.ComputeSFCStep(step_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1577
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1578
    def GenerateProgram(self, pou):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1579
        self.ComputeInterface(pou)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1580
        self.ComputeConnectionTypes(pou)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1581
        self.ComputeProgram(pou)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1582
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1583
        program = [("%s "%self.Type, ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1584
                   (self.Name, (self.TagName, "name"))]
1310
3d7fa2257b24 Removed obsolete process for customizing block code generated in extensions
Laurent Bessard
parents: 1298
diff changeset
  1585
        if self.ReturnType is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1586
            program += [(" : ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1587
                        (self.ReturnType, (self.TagName, "return"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1588
        program += [("\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1589
        if len(self.Interface) == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1590
            raise PLCGenException, _("No variable defined in \"%s\" POU")%self.Name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1591
        if len(self.Program) == 0 :
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1592
            raise PLCGenException, _("No body defined in \"%s\" POU")%self.Name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1593
        var_number = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1594
        for list_type, option, located, variables in self.Interface:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1595
            variable_type = errorVarTypes.get(list_type, "var_local")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1596
            program += [("  %s"%list_type, ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1597
            if option is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1598
                program += [(" %s"%option, (self.TagName, variable_type, (var_number, var_number + len(variables)), option.lower()))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1599
            program += [("\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1600
            for var_type, var_name, var_address, var_initial in variables:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1601
                program += [("    ", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1602
                if var_name:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1603
                    program += [(var_name, (self.TagName, variable_type, var_number, "name")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1604
                                (" ", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1605
                if var_address != None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1606
                    program += [("AT ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1607
                                (var_address, (self.TagName, variable_type, var_number, "location")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1608
                                (" ", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1609
                program += [(": ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1610
                            (var_type, (self.TagName, variable_type, var_number, "type"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1611
                if var_initial != None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1612
                    program += [(" := ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1613
                                (self.ParentGenerator.ComputeValue(var_initial, var_type), (self.TagName, variable_type, var_number, "initial value"))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1614
                program += [(";\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1615
                var_number += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1616
            program += [("  END_VAR\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1617
        program += [("\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1618
        program += self.Program
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1619
        program += [("END_%s\n\n"%self.Type, ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1620
        return program
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1621
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1622
def GenerateCurrentProgram(controler, project, errors, warnings):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1623
    generator = ProgramGenerator(controler, project, errors, warnings)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1624
    generator.GenerateProgram()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1625
    return generator.GetGeneratedProgram()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1626