PLCGenerator.py
author lbessard
Thu, 16 Aug 2007 10:40:27 +0200
changeset 72 73212220ad22
parent 71 0578bc212c20
child 78 049f2e7090a2
permissions -rw-r--r--
Adding support for generating FBD with connectors and continuations
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     3
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     5
#based on the plcopen standard. 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     6
#
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     8
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     9
#See COPYING file for copyrights details.
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    10
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5
f8652b073e84 GPL->LGPL
etisserant
parents: 4
diff changeset
    12
#modify it under the terms of the GNU General Public
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    15
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    19
#General Public License for more details.
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    20
#
5
f8652b073e84 GPL->LGPL
etisserant
parents: 4
diff changeset
    21
#You should have received a copy of the GNU General Public
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    24
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    25
from plcopen import plcopen
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    26
from plcopen.structures import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    27
from types import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    28
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    29
varTypeNames = {"localVars" : "VAR", "tempVars" : "VAR_TEMP", "inputVars" : "VAR_INPUT", 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    30
                "outputVars" : "VAR_OUTPUT", "inOutVars" : "VAR_IN_OUT", "externalVars" : "VAR_EXTERNAL",
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    31
                "globalVars" : "VAR_GLOBAL", "accessVars" : "VAR_ACCESS"}
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    32
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
    33
pouTypeNames = {"function" : "FUNCTION", "functionBlock" : "FUNCTION_BLOCK", "program" : "PROGRAM"}
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
    34
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
    35
currentProject = None
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
    36
currentProgram = ""
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
    37
pouComputed = {}
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
    38
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    39
def ReIndentText(text, nb_spaces):
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    40
    compute = ""
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    41
    lines = text.splitlines()
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    42
    if len(lines) > 0:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    43
        spaces = 0
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    44
        while lines[0][spaces] == " ":
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    45
            spaces += 1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    46
        indent = ""
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    47
        for i in xrange(spaces, nb_spaces):
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    48
            indent += " "
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    49
        for line in lines:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    50
            if line != "":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    51
                compute += "%s%s\n"%(indent, line)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    52
            else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    53
                compute += "\n"
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    54
    return compute
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    55
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    56
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    57
Module implementing methods for generating PLC programs in ST or IL
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    58
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    59
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    60
class PouProgram:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    61
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    62
    def __init__(self, name, type):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    63
        self.Name = name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    64
        self.Type = type
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    65
        self.ReturnType = None
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    66
        self.Interface = []
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    67
        self.InitialSteps = []
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
    68
        self.ComputedBlocks = {}
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
    69
        self.ComputedConnectors = {}
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    70
        self.SFCNetworks = {"Steps":{}, "Transitions":{}, "Actions":{}}
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
    71
        self.SFCComputedBlocks = ""
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 37
diff changeset
    72
        self.ActionNumber = 0
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    73
        self.Program = ""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    74
    
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 37
diff changeset
    75
    def GetActionNumber(self):
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 37
diff changeset
    76
        self.ActionNumber += 1
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 37
diff changeset
    77
        return self.ActionNumber
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 37
diff changeset
    78
    
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    79
    def IsAlreadyDefined(self, name):
33
0dd4a876392f Bugs on ST generation fixed
lbessard
parents: 31
diff changeset
    80
        for list_type, retain, constant, located, vars in self.Interface:
30
768cf2a6b0b1 Bug on ressource generation fixed
lbessard
parents: 29
diff changeset
    81
            for var_type, var_name, var_address, var_initial in vars:
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    82
                if name == var_name:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    83
                    return True
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    84
        return False
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    85
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    86
    def GenerateInterface(self, interface):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    87
        if self.Type == "FUNCTION":
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    88
            self.ReturnType = interface.getReturnType().getValue()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    89
        for varlist in interface.getContent():
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
    90
            variables = []
33
0dd4a876392f Bugs on ST generation fixed
lbessard
parents: 31
diff changeset
    91
            located = False
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    92
            for var in varlist["value"].getVariable():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    93
                type = var.getType().getValue()
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 66
diff changeset
    94
                if not isinstance(type, (StringType, UnicodeType)):
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 66
diff changeset
    95
                    type = type.getName()
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
    96
                    GeneratePouProgram(type)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 6
diff changeset
    97
                initial = var.getInitialValue()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 6
diff changeset
    98
                if initial:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 6
diff changeset
    99
                    initial_value = initial.getValue()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 6
diff changeset
   100
                else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 6
diff changeset
   101
                    initial_value = None
30
768cf2a6b0b1 Bug on ressource generation fixed
lbessard
parents: 29
diff changeset
   102
                address = var.getAddress()
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 66
diff changeset
   103
                if address:
33
0dd4a876392f Bugs on ST generation fixed
lbessard
parents: 31
diff changeset
   104
                    located = True
30
768cf2a6b0b1 Bug on ressource generation fixed
lbessard
parents: 29
diff changeset
   105
                variables.append((type, var.getName(), address, initial_value))
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   106
            self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getRetain(), 
33
0dd4a876392f Bugs on ST generation fixed
lbessard
parents: 31
diff changeset
   107
                            varlist["value"].getConstant(), located, variables))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   108
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   109
    def GenerateProgram(self, pou):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   110
        body = pou.getBody()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   111
        body_content = body.getContent()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   112
        body_type = body_content["name"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   113
        if body_type in ["IL","ST"]:
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   114
            self.Program = ReIndentText(body_content["value"].getText(), 2)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   115
        elif body_type == "FBD":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   116
            for instance in body.getContentInstances():
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   117
                if isinstance(instance, (plcopen.outVariable, plcopen.inOutVariable)):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   118
                    var = instance.getExpression()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   119
                    connections = instance.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   120
                    if connections and len(connections) == 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   121
                        expression = self.ComputeFBDExpression(body, connections[0])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   122
                        self.Program += "  %s := %s;\n"%(var, expression)
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   123
                if isinstance(instance, plcopen.connector):
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   124
                    connector = instance.getName()
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   125
                    if self.ComputedConnectors.get(connector, None):
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   126
                        continue 
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   127
                    connections = instance.connectionPointIn.getConnections()
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   128
                    if connections and len(connections) == 1:
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   129
                        self.ComputedConnectors[connector] = self.ComputeFBDExpression(body, connections[0])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   130
        elif body_type == "LD":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   131
            for instance in body.getContentInstances():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   132
                if isinstance(instance, plcopen.coil):
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   133
                    paths = self.GenerateLDPaths(instance.connectionPointIn.getConnections(), body)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   134
                    variable = self.ExtractModifier(instance, instance.getVariable())
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   135
                    expression = self.ComputeLDExpression(paths, True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   136
                    self.Program += "  %s := %s;\n"%(variable, expression)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   137
        elif body_type == "SFC":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   138
            for instance in body.getContentInstances():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   139
                if isinstance(instance, plcopen.step):
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   140
                    self.GenerateSFCStep(instance, pou)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   141
                elif isinstance(instance, plcopen.actionBlock):
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   142
                    self.GenerateSFCStepActions(instance, pou)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   143
                elif isinstance(instance, plcopen.transition):
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   144
                    self.GenerateSFCTransition(instance, pou)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   145
                elif isinstance(instance, plcopen.jumpStep):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   146
                    self.GenerateSFCJump(instance, pou)
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   147
            if len(self.InitialSteps) > 0 and self.SFCComputedBlocks != "":
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   148
                action_name = "COMPUTE_FUNCTION_BLOCKS"
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   149
                action_infos = {"qualifier" : "S", "content" : action_name}
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   150
                self.SFCNetworks["Steps"][self.InitialSteps[0]]["actions"].append(action_infos)
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   151
                self.SFCNetworks["Actions"][action_name] = ReIndentText(self.SFCComputedBlocks, 4)
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   152
                self.Program = ""
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   153
            else:
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   154
                raise Exception
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   155
            for initialstep in self.InitialSteps:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   156
                self.ComputeSFCStep(initialstep)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   157
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   158
    def ComputeFBDExpression(self, body, link):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   159
        localid = link.getRefLocalId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   160
        instance = body.getContentInstance(localid)
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   161
        if isinstance(instance, (plcopen.inVariable, plcopen.inOutVariable)):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   162
            return instance.getExpression()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   163
        elif isinstance(instance, plcopen.block):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   164
            name = instance.getInstanceName()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   165
            type = instance.getTypeName()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   166
            block_infos = GetBlockType(type)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   167
            if block_infos["type"] == "function":
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   168
                GeneratePouProgram(type)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   169
                vars = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   170
                for variable in instance.inputVariables.getVariable():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   171
                    connections = variable.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   172
                    if connections and len(connections) == 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   173
                        value = self.ComputeFBDExpression(body, connections[0])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   174
                        vars.append(self.ExtractModifier(variable, value))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   175
                variable = instance.outputVariables.getVariable()[0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   176
                return self.ExtractModifier(variable, "%s(%s)"%(type, ", ".join(vars)))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   177
            elif block_infos["type"] == "functionBlock":
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   178
                if not self.ComputedBlocks.get(name, False):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   179
                    vars = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   180
                    for variable in instance.inputVariables.getVariable():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   181
                        connections = variable.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   182
                        if connections and len(connections) == 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   183
                            parameter = variable.getFormalParameter()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   184
                            value = self.ComputeFBDExpression(body, connections[0])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   185
                            vars.append(self.ExtractModifier(variable, "%s := %s"%(parameter, value)))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   186
                    self.Program += "  %s(%s);\n"%(name, ", ".join(vars))
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   187
                    self.ComputedBlocks[name] = True
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   188
                connectionPoint = link.getPosition()[-1]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   189
                for variable in instance.outputVariables.getVariable():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   190
                    blockPointx, blockPointy = variable.connectionPointOut.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   191
                    if instance.getX() + blockPointx == connectionPoint.getX() and instance.getY() + blockPointy == connectionPoint.getY():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   192
                        return self.ExtractModifier(variable, "%s.%s"%(name, variable.getFormalParameter()))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   193
                raise ValueError, "No output variable found"
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   194
        elif isinstance(instance, plcopen.continuation):
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   195
            name = instance.getName()
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   196
            computed_value = self.ComputedConnectors.get(name, None)
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   197
            if computed_value != None:
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   198
                return computed_value
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   199
            for tmp_instance in body.getContentInstances():
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   200
                if isinstance(tmp_instance, plcopen.connector):
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   201
                    if tmp_instance.getName() == name:
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   202
                        connections = tmp_instance.connectionPointIn.getConnections()
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   203
                        if connections and len(connections) == 1:
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   204
                            expression = self.ComputeFBDExpression(body, connections[0])
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   205
                            self.ComputedConnectors[name] = expression
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   206
                            return expression
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   207
            raise ValueError, "No connector found"
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   208
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   209
    def GenerateLDPaths(self, connections, body):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   210
        paths = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   211
        for connection in connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   212
            localId = connection.getRefLocalId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   213
            next = body.getContentInstance(localId)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   214
            if isinstance(next, plcopen.leftPowerRail):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   215
                paths.append(None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   216
            else:
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   217
                variable = self.ExtractModifier(next, next.getVariable())
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   218
                result = self.GenerateLDPaths(next.connectionPointIn.getConnections(), body)
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   219
                if len(result) > 1:
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   220
                    paths.append([variable, tuple(result)])
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   221
                elif type(result[0]) == ListType:
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   222
                    paths.append([variable] + result[0])
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   223
                elif result[0]:
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   224
                    paths.append([variable, result[0]])
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   225
                else:
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   226
                    paths.append(variable)
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   227
        return paths
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   228
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   229
    def GetNetworkType(self, connections, body):
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   230
        network_type = "FBD"
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   231
        for connection in connections:
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   232
            localId = connection.getRefLocalId()
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   233
            next = body.getContentInstance(localId)
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   234
            if isinstance(next, plcopen.leftPowerRail) or isinstance(next, plcopen.contact):
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   235
                return "LD"
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   236
            elif isinstance(next, plcopen.block):
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   237
                 for variable in next.inputVariables.getVariable():
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   238
                     result = self.GetNetworkType(variable.connectionPointIn.getConnections(), body)
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   239
                     if result != "FBD":
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   240
                         return result
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   241
            elif isinstance(next, plcopen.inVariable):
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   242
                return "FBD"
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   243
            elif isinstance(next, plcopen.inOutVariable):
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   244
                return self.GetNetworkType(next.connectionPointIn.getConnections(), body)
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   245
            else:
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   246
                return None
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   247
        return "FBD"
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   248
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   249
    def ExtractDivergenceInput(self, divergence, pou):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   250
        connectionPointIn = divergence.getConnectionPointIn()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   251
        if connectionPointIn:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   252
            connections = connectionPointIn.getConnections()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   253
            if len(connections) == 1:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   254
                instanceLocalId = connections[0].getRefLocalId()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   255
                return pou.body.getContentInstance(instanceLocalId)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   256
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   257
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   258
    def ExtractConvergenceInputs(self, convergence, pou):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   259
        instances = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   260
        for connectionPointIn in convergence.getConnectionPointIn():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   261
            connections = connectionPointIn.getConnections()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   262
            if len(connections) == 1:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   263
                instanceLocalId = connections[0].getRefLocalId()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   264
                instances.append(pou.body.getContentInstance(instanceLocalId))
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   265
        return instances
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   266
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   267
    def GenerateSFCStep(self, step, pou):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   268
        step_name = step.getName()
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   269
        if step_name not in self.SFCNetworks["Steps"].keys():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   270
            if step.getInitialStep():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   271
                self.InitialSteps.append(step_name)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   272
            step_infos = {"initial" : step.getInitialStep(), "transitions" : [], "actions" : []}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   273
            if step.connectionPointIn:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   274
                instances = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   275
                connections = step.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   276
                if len(connections) == 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   277
                    instanceLocalId = connections[0].getRefLocalId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   278
                    instance = pou.body.getContentInstance(instanceLocalId)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   279
                    if isinstance(instance, plcopen.transition):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   280
                        instances.append(instance)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   281
                    elif isinstance(instance, plcopen.selectionConvergence):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   282
                        instances.extend(self.ExtractConvergenceInputs(instance, pou))
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   283
                    elif isinstance(instance, plcopen.simultaneousDivergence):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   284
                        transition = self.ExtractDivergenceInput(instance, pou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   285
                        if transition:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   286
                            if isinstance(transition, plcopen.transition):
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   287
                                instances.append(transition)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   288
                            elif isinstance(transition, plcopen.selectionConvergence):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   289
                                instances.extend(self.ExtractConvergenceInputs(transition, pou))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   290
                for instance in instances:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   291
                    self.GenerateSFCTransition(instance, pou)
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   292
                    if instance in self.SFCNetworks["Transitions"].keys():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   293
                        self.SFCNetworks["Transitions"][instance]["to"].append(step_name)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   294
            self.SFCNetworks["Steps"][step_name] = step_infos
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   295
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   296
    def GenerateSFCJump(self, jump, pou):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   297
        jump_target = jump.getTargetName()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   298
        if jump.connectionPointIn:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   299
            instances = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   300
            connections = jump.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   301
            if len(connections) == 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   302
                instanceLocalId = connections[0].getRefLocalId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   303
                instance = pou.body.getContentInstance(instanceLocalId)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   304
                if isinstance(instance, plcopen.transition):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   305
                    instances.append(instance)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   306
                elif isinstance(instance, plcopen.selectionConvergence):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   307
                    instances.extend(self.ExtractConvergenceInputs(instance, pou))
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   308
                elif isinstance(instance, plcopen.simultaneousDivergence):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   309
                    transition = self.ExtractDivergenceInput(instance, pou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   310
                    if transition:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   311
                        if isinstance(transition, plcopen.transition):
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   312
                            instances.append(transition)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   313
                        elif isinstance(transition, plcopen.selectionConvergence):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   314
                            instances.extend(self.ExtractConvergenceInputs(transition, pou))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   315
            for instance in instances:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   316
                self.GenerateSFCTransition(instance, pou)
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   317
                if instance in self.SFCNetworks["Transitions"].keys():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   318
                    self.SFCNetworks["Transitions"][instance]["to"].append(jump_target)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   319
    
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   320
    def GenerateSFCStepActions(self, actionBlock, pou):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   321
        connections = actionBlock.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   322
        if len(connections) == 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   323
            stepLocalId = connections[0].getRefLocalId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   324
            step = pou.body.getContentInstance(stepLocalId)
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   325
            self.GenerateSFCStep(step, pou)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   326
            step_name = step.getName()
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   327
            if step_name in self.SFCNetworks["Steps"].keys():
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   328
                actions = actionBlock.getActions()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   329
                for action in actions:
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   330
                    action_infos = {"qualifier" : action["qualifier"], "content" : action["value"]}
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   331
                    if "duration" in action:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   332
                        action_infos["duration"] = action["duration"]
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   333
                    if "indicator" in action:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   334
                        action_infos["indicator"] = action["indicator"]
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   335
                    if action["type"] == "reference":
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   336
                        self.GenerateSFCAction(action["value"], pou)
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 37
diff changeset
   337
                    else:
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 37
diff changeset
   338
                        action_name = "INLINE%d"%self.GetActionNumber()
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 37
diff changeset
   339
                        self.SFCNetworks["Actions"][action_name] = "    %s\n"%action["value"]
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 37
diff changeset
   340
                        action_infos["content"] = action_name
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   341
                    self.SFCNetworks["Steps"][step_name]["actions"].append(action_infos)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   342
    
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   343
    def GenerateSFCAction(self, action_name, pou):
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   344
        if action_name not in self.SFCNetworks["Actions"].keys():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   345
            actionContent = pou.getAction(action_name)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   346
            if actionContent:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   347
                actionType = actionContent.getBodyType()
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   348
                actionBody = actionContent.getBody()
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   349
                if actionType in ["ST", "IL"]:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   350
                    self.SFCNetworks["Actions"][action_name] = ReIndentText(actionContent.getText(), 4)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   351
                elif actionType == "FBD":
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   352
                    for instance in actionBody.getContentInstances():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   353
                        if isinstance(instance, plcopen.outVariable):
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   354
                            var = instance.getExpression()
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   355
                            connections = instance.connectionPointIn.getConnections()
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   356
                            if connections and len(connections) == 1:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   357
                                expression = self.ComputeFBDExpression(actionBody, connections[0])
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   358
                                action_content = self.Program + "  %s := %s;\n"%(var, expression)
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   359
                                self.Program = ""
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   360
                                self.SFCNetworks["Actions"][action_name] = ReIndentText(action_content, 4)
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   361
                elif actionType == "LD":
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   362
                    for instance in actionbody.getContentInstances():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   363
                        if isinstance(instance, plcopen.coil):
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   364
                            paths = self.GenerateLDPaths(instance.connectionPointIn.getConnections(), actionBody)
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   365
                            variable = self.ExtractModifier(instance, instance.getVariable())
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   366
                            expression = self.ComputeLDExpression(paths, True)
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   367
                            action_content = self.Program + "  %s := %s;\n"%(variable, expression)
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   368
                            self.Program = ""
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   369
                            self.SFCNetworks["Actions"][action_name] = ReIndentText(action_content, 4)
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   370
    
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   371
    def GenerateSFCTransition(self, transition, pou):
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   372
        if transition not in self.SFCNetworks["Transitions"].keys():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   373
            steps = []
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   374
            connections = transition.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   375
            if len(connections) == 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   376
                instanceLocalId = connections[0].getRefLocalId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   377
                instance = pou.body.getContentInstance(instanceLocalId)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   378
                if isinstance(instance, plcopen.step):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   379
                    steps.append(instance)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   380
                elif isinstance(instance, plcopen.selectionDivergence):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   381
                    step = self.ExtractDivergenceInput(instance, pou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   382
                    if step:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   383
                        if isinstance(step, plcopen.step):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   384
                            steps.append(step)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   385
                        elif isinstance(step, plcopen.simultaneousConvergence):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   386
                            steps.extend(self.ExtractConvergenceInputs(step, pou))
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   387
                elif isinstance(instance, plcopen.simultaneousConvergence):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   388
                    steps.extend(self.ExtractConvergenceInputs(instance, pou))
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   389
            transition_infos = {"from": [], "to" : []}
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   390
            transitionValues = transition.getConditionContent()
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   391
            if transitionValues["type"] == "inline":
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   392
                transition_infos["content"] = "\n    := %s;\n"%transitionValues["value"]
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   393
            elif transitionValues["type"] == "reference":
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   394
                transitionContent = pou.getTransition(transitionValues["value"])
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   395
                transitionType = transitionContent.getBodyType()
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   396
                transitionBody = transitionContent.getBody()
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   397
                if transitionType == "IL":
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   398
                    transition_infos["content"] = ":\n%s"%ReIndentText(transitionBody.getText(), 4)
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   399
                elif transitionType == "ST":
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   400
                    transition_infos["content"] = "\n%s"%ReIndentText(transitionBody.getText(), 4)
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   401
                elif transitionType == "FBD":
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   402
                    for instance in transitionBody.getContentInstances():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   403
                        if isinstance(instance, plcopen.outVariable):
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   404
                            connections = instance.connectionPointIn.getConnections()
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   405
                            if connections and len(connections) == 1:
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   406
                                expression = self.ComputeFBDExpression(transitionBody, connections[0])
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   407
                                transition_infos["content"] = "\n    := %s;\n"%expression
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   408
                                self.SFCComputedBlocks += self.Program
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   409
                                self.Program = ""
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   410
                elif transitionType == "LD":
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   411
                    for instance in transitionBody.getContentInstances():
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   412
                        if isinstance(instance, plcopen.coil):
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   413
                            paths = self.GenerateLDPaths(instance.connectionPointIn.getConnections(), transitionBody)
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   414
                            expression = self.ComputeLDExpression(paths, True)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   415
                            transition_infos["content"] = "\n    := %s;\n"%expression
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   416
                            self.SFCComputedBlocks += self.Program
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   417
                            self.Program = ""
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   418
            elif transitionValues["type"] == "connection":
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   419
                body = pou.getBody()
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   420
                connections = transition.getConnections()
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   421
                network_type = self.GetNetworkType(connections, body)
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   422
                if network_type == None:
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   423
                    raise Exception
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   424
                if len(connections) > 1 or network_type == "LD":
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   425
                    paths = self.GenerateLDPaths(connections, body)
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   426
                    expression = self.ComputeLDExpression(paths, True)
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   427
                    transition_infos["content"] = "\n    := %s;\n"%expression
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   428
                    self.SFCComputedBlocks += self.Program
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   429
                    self.Program = ""
66
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   430
                else:
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   431
                    expression = self.ComputeFBDExpression(body, connections[0])
fd138fc77510 Adding support for generating network and rung connected to transitions into SFC
lbessard
parents: 58
diff changeset
   432
                    transition_infos["content"] = "\n    := %s;\n"%expression
72
73212220ad22 Adding support for generating FBD with connectors and continuations
lbessard
parents: 71
diff changeset
   433
                    self.SFCComputedBlocks += self.Program
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   434
                    self.Program = ""
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   435
            for step in steps:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   436
                self.GenerateSFCStep(step, pou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   437
                step_name = step.getName()
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   438
                if step_name in self.SFCNetworks["Steps"].keys():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   439
                    transition_infos["from"].append(step_name)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   440
                    self.SFCNetworks["Steps"][step_name]["transitions"].append(transition)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   441
            self.SFCNetworks["Transitions"][transition] = transition_infos
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   442
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   443
    def ComputeSFCStep(self, step_name):
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   444
        if step_name in self.SFCNetworks["Steps"].keys():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   445
            step_infos = self.SFCNetworks["Steps"].pop(step_name)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   446
            if step_infos["initial"]:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   447
                self.Program += "  INITIAL_STEP %s:\n"%step_name
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   448
            else:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   449
                self.Program += "  STEP %s:\n"%step_name
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   450
            actions = []
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   451
            for action_infos in step_infos["actions"]:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   452
                actions.append(action_infos["content"])
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   453
                self.Program += "    %(content)s(%(qualifier)s"%action_infos
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   454
                if "duration" in action_infos:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   455
                    self.Program += ", %(duration)s"%action_infos
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   456
                if "indicator" in action_infos:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   457
                    self.Program += ", %(indicator)s"%action_infos
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   458
                self.Program += ");\n"
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   459
            self.Program += "  END_STEP\n\n"
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   460
            for action in actions:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   461
                self.ComputeSFCAction(action)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   462
            for transition in step_infos["transitions"]:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   463
                self.ComputeSFCTransition(transition)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   464
                
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   465
    def ComputeSFCAction(self, action_name):
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   466
        if action_name in self.SFCNetworks["Actions"].keys():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   467
            action_content = self.SFCNetworks["Actions"].pop(action_name)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   468
            self.Program += "  ACTION %s:\n%s  END_ACTION\n\n"%(action_name, action_content)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   469
    
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   470
    def ComputeSFCTransition(self, transition):
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   471
        if transition in self.SFCNetworks["Transitions"].keys():
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   472
            transition_infos = self.SFCNetworks["Transitions"].pop(transition)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   473
            self.Program += "  TRANSITION FROM "
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   474
            if len(transition_infos["from"]) > 1:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   475
                self.Program += "(%s)"%", ".join(transition_infos["from"])
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   476
            else:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   477
                self.Program += "%s"%transition_infos["from"][0]
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   478
            self.Program += " TO "
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   479
            if len(transition_infos["to"]) > 1:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   480
                self.Program += "(%s)"%", ".join(transition_infos["to"])
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   481
            else:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   482
                self.Program += "%s"%transition_infos["to"][0]
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   483
            self.Program += transition_infos["content"]
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   484
            self.Program += "  END_TRANSITION\n\n"
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   485
            for step_name in transition_infos["to"]:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   486
                self.ComputeSFCStep(step_name)
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   487
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   488
    def ComputeLDExpression(self, paths, first = False):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   489
        if type(paths) == TupleType:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   490
            if None in paths:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   491
                return "TRUE"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   492
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   493
                var = [self.ComputeLDExpression(path) for path in paths]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   494
                if first:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   495
                    return " OR ".join(var)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   496
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   497
                    return "(%s)"%" OR ".join(var)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   498
        elif type(paths) == ListType:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   499
            var = [self.ComputeLDExpression(path) for path in paths]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   500
            return " AND ".join(var)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   501
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   502
            return paths
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   503
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   504
    def ExtractModifier(self, variable, text):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   505
        if variable.getNegated():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   506
            return "NOT(%s)"%text
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   507
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   508
            edge = variable.getEdge()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   509
            if edge:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   510
                if edge.getValue() == "rising":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   511
                    return self.AddTrigger("R_TRIG", text)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   512
                elif edge.getValue() == "falling":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   513
                    return self.AddTrigger("F_TRIG", text)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   514
        return text
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   515
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   516
    def AddTrigger(self, edge, text):
33
0dd4a876392f Bugs on ST generation fixed
lbessard
parents: 31
diff changeset
   517
        if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] or self.Interface[-1][2] or self.Interface[-1][3]:
0dd4a876392f Bugs on ST generation fixed
lbessard
parents: 31
diff changeset
   518
            self.Interface.append(("VAR", False, False, False, []))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   519
        i = 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   520
        name = "%s%d"%(edge, i)
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   521
        while self.IsAlreadyDefined(name):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   522
            i += 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   523
            name = "%s%d"%(edge, i)
33
0dd4a876392f Bugs on ST generation fixed
lbessard
parents: 31
diff changeset
   524
        self.Interface[-1][4].append((edge, name, None, None))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   525
        self.Program += "  %s(CLK := %s);\n"%(name, text)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   526
        return "%s.Q"%name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   527
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   528
    def GenerateSTProgram(self):
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   529
        if self.ReturnType:
29
3b7e23a323a6 Adding support for configuration generation
lbessard
parents: 28
diff changeset
   530
            program = "%s %s : %s\n"%(self.Type, self.Name, self.ReturnType)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   531
        else:
29
3b7e23a323a6 Adding support for configuration generation
lbessard
parents: 28
diff changeset
   532
            program = "%s %s\n"%(self.Type, self.Name)
33
0dd4a876392f Bugs on ST generation fixed
lbessard
parents: 31
diff changeset
   533
        for list_type, retain, constant, located, variables in self.Interface:
1
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   534
            program += "  %s"%list_type
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   535
            if retain:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   536
                program += " RETAIN"
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   537
            if constant:
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   538
                program += " CONSTANT"
e9d01d824086 SFC textual programs generation completed
lbessard
parents: 0
diff changeset
   539
            program += "\n"
30
768cf2a6b0b1 Bug on ressource generation fixed
lbessard
parents: 29
diff changeset
   540
            for var_type, var_name, var_address, var_initial in variables:
768cf2a6b0b1 Bug on ressource generation fixed
lbessard
parents: 29
diff changeset
   541
                program += "    %s "%var_name
768cf2a6b0b1 Bug on ressource generation fixed
lbessard
parents: 29
diff changeset
   542
                if var_address != None:
31
d833bf7567b1 Bug on variable location fixed
lbessard
parents: 30
diff changeset
   543
                    program += "AT %s "%var_address
30
768cf2a6b0b1 Bug on ressource generation fixed
lbessard
parents: 29
diff changeset
   544
                program += ": %s"%var_type
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 6
diff changeset
   545
                if var_initial != None:
33
0dd4a876392f Bugs on ST generation fixed
lbessard
parents: 31
diff changeset
   546
                    value = {"TRUE":"0","FALSE":"1"}.get(str(var_initial).upper(), str(var_initial))
37
256eedd275d0 Adding support for disable interface variable change if a POU is used
lbessard
parents: 33
diff changeset
   547
                    if var_type == "STRING":
256eedd275d0 Adding support for disable interface variable change if a POU is used
lbessard
parents: 33
diff changeset
   548
                        program += " := '%s'"%value
256eedd275d0 Adding support for disable interface variable change if a POU is used
lbessard
parents: 33
diff changeset
   549
                    elif var_type == "WSTRING":
33
0dd4a876392f Bugs on ST generation fixed
lbessard
parents: 31
diff changeset
   550
                        program += " := \"%s\""%value
0dd4a876392f Bugs on ST generation fixed
lbessard
parents: 31
diff changeset
   551
                    else:
0dd4a876392f Bugs on ST generation fixed
lbessard
parents: 31
diff changeset
   552
                        program += " := %s"%value
30
768cf2a6b0b1 Bug on ressource generation fixed
lbessard
parents: 29
diff changeset
   553
                program += ";\n"
4
2de7fd952fdd Adding File Dialog for choosing path to generated program
lbessard
parents: 2
diff changeset
   554
            program += "  END_VAR\n"
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   555
        program += "\n"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   556
        program += self.Program
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   557
        program += "END_%s\n\n"%self.Type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   558
        return program
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   559
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   560
def GeneratePouProgram(pou_name):
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   561
    if not pouComputed.get(pou_name, True):
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   562
        pouComputed[pou_name] = True
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   563
        global currentProject, currentProgram
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   564
        pou = currentProject.getPou(pou_name)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   565
        pou_type = pou.getPouType().getValue()
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   566
        if pou_type in pouTypeNames:
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   567
            pou_program = PouProgram(pou.getName(), pouTypeNames[pou_type])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   568
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   569
            raise ValueError, "Undefined pou type"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   570
        pou_program.GenerateInterface(pou.getInterface())
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   571
        pou_program.GenerateProgram(pou)
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   572
        currentProgram += pou_program.GenerateSTProgram()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   573
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   574
def GenerateConfiguration(configuration):
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   575
    config = "\nCONFIGURATION %s\n"%configuration.getName()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   576
    for varlist in configuration.getGlobalVars():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   577
        config += "  VAR_GLOBAL"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   578
        if varlist.getRetain():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   579
            config += " RETAIN"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   580
        if varlist.getConstant():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   581
            config += " CONSTANT"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   582
        config += "\n"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   583
        for var in varlist.getVariable():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   584
            var_type = var.getType().getValue()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   585
            config += "    %s "%var.getName()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   586
            address = var.getAddress()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   587
            if address:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   588
                config += "AT %s "%address
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   589
            config += ": %s"%var_type
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   590
            initial = var.getInitialValue()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   591
            if initial:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   592
                value = str(initial.getValue())
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   593
                value = {"TRUE":"0","FALSE":"1"}.get(value.upper(), value)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   594
                if var_type == "STRING":
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   595
                    config += " := '%s'"%value
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   596
                elif var_type == "WSTRING":
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   597
                    config += " := \"%s\""%value
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   598
                else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   599
                    config += " := %s"%value
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   600
            config += ";\n"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   601
        config += "  END_VAR\n"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   602
    for resource in configuration.getResource():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   603
        config += GenerateResource(resource)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   604
    config += "END_CONFIGURATION\n"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   605
    return config
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   606
    
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   607
def GenerateResource(resource):
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   608
    resrce = "\n  RESOURCE %s ON BEREMIZ\n"%resource.getName()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   609
    for varlist in resource.getGlobalVars():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   610
        resrce += "    VAR_GLOBAL"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   611
        if varlist.getRetain():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   612
            resrce += " RETAIN"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   613
        if varlist.getConstant():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   614
            resrce += " CONSTANT"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   615
        resrce += "\n"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   616
        for var in varlist.getVariable():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   617
            var_type = var.getType().getValue()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   618
            resrce += "      %s "%var.getName()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   619
            address = var.getAddress()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   620
            if address:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   621
                resrce += "AT %s "%address
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   622
            resrce += ": %s"%var.getType().getValue()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   623
            initial = var.getInitialValue()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   624
            if initial:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   625
                value = str(initial.getValue())
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   626
                value = {"TRUE":"0","FALSE":"1"}.get(value.upper(), value)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   627
                if var_type == "STRING":
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   628
                    resrce += " := '%s'"%value
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   629
                elif var_type == "WSTRING":
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   630
                    resrce += " := \"%s\""%value
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   631
                else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   632
                    resrce += " := %s"%value
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   633
            resrce += ";\n"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   634
        resrce += "    END_VAR\n"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   635
    tasks = resource.getTask()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   636
    for task in tasks:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   637
        resrce += "    TASK %s("%task.getName()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   638
        args = []
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   639
        single = task.getSingle()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   640
        if single:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   641
            args.append("SINGLE := %s"%single)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   642
        interval = task.getInterval()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   643
        if interval:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   644
            text = "t#"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   645
            if interval.hour != 0:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   646
                text += "%dh"%interval.hour
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   647
            if interval.minute != 0:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   648
                text += "%dm"%interval.minute
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   649
            if interval.second != 0:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   650
                text += "%ds"%interval.second
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   651
            if interval.microsecond != 0:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   652
                text += "%dms"%(interval.microsecond / 1000)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   653
            args.append("INTERVAL := %s"%text)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   654
        args.append("PRIORITY := %s"%str(task.priority.getValue()))
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   655
        resrce += ",".join(args) + ");\n"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   656
    for task in tasks:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   657
        for instance in task.getPouInstance():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   658
            resrce += "    PROGRAM %s WITH %s : %s;\n"%(instance.getName(), task.getName(), instance.getType())
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   659
    for instance in resource.getPouInstance():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   660
        resrce += "    PROGRAM %s : %s;\n"%(instance.getName(), instance.getType())
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   661
    resrce += "  END_RESOURCE\n"
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   662
    return resrce
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   663
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   664
def GenerateCurrentProgram(project):
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   665
    global currentProject, currentProgram
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   666
    currentProject = project
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   667
    currentProgram = ""
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   668
    for pou in project.getPous():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   669
        pouComputed[pou.getName()] = False
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   670
    for pou_name in pouComputed.keys():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   671
        GeneratePouProgram(pou_name)
29
3b7e23a323a6 Adding support for configuration generation
lbessard
parents: 28
diff changeset
   672
    for config in project.getConfigurations():
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   673
        currentProgram += GenerateConfiguration(config)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   674
    return currentProgram
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   675