PLCControler.py
author lbessard
Thu, 06 Dec 2007 18:05:29 +0100
changeset 125 394d9f168258
parent 121 40b91ba978db
child 128 d16a8df4d322
permissions -rw-r--r--
Adding support for execution order in PLCGenerator
Adding support for derived data types (struct not supported yet)
Fixed refresh bug with windows on Viewers
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: 57
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: 57
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 minixsv import pyxsval
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
    26
from xml.dom import minidom
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
    27
from types import StringType, UnicodeType
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    28
import cPickle
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    29
import os,sys,re
24
364320323b4d Adding support for date and time data types
lbessard
parents: 13
diff changeset
    30
from datetime import *
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    31
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    32
from plcopen import plcopen
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    33
from plcopen.structures import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    34
from graphics.GraphicCommons import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    35
from PLCGenerator import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    36
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 35
diff changeset
    37
duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:.[0-9]*)?)ms)?")
24
364320323b4d Adding support for date and time data types
lbessard
parents: 13
diff changeset
    38
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    39
[ITEM_UNEDITABLE, ITEM_PROJECT, ITEM_POU, ITEM_CLASS, ITEM_VARIABLE,
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
    40
 ITEM_TRANSITION, ITEM_ACTION, ITEM_CONFIGURATION, ITEM_RESOURCE, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
    41
 ITEM_DATATYPE] = range(10)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
    42
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
    43
ScriptDirectory = os.path.split(os.path.realpath(__file__))[0]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    44
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    45
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    46
pyxsval is not complete and the parts that are not supported print some error
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    47
reports. This class is used for not displaying them
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    48
"""
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    49
class HolePseudoFile:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    50
    """ Base class for file like objects to facilitate StdOut for the Shell."""
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    51
    def __init__(self, output = None):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    52
        if output is None: output = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    53
        self.output = output
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    54
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    55
    def writelines(self, l):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    56
        map(self.write, l)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    57
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    58
    def write(self, s):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    59
        pass
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    60
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    61
    def flush(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    62
        pass
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    63
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    64
    def isatty(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    65
        return false
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    66
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    67
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    68
#                         Undo Buffer for PLCOpenEditor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    69
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    70
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    71
# Length of the buffer
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    72
UNDO_BUFFER_LENGTH = 20
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    73
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    74
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    75
Class implementing a buffer of changes made on the current editing Object Dictionary
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    76
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    77
class UndoBuffer:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    78
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    79
    # Constructor initialising buffer
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    80
    def __init__(self, currentstate, issaved = False):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    81
        self.Buffer = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    82
        self.CurrentIndex = -1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    83
        self.MinIndex = -1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    84
        self.MaxIndex = -1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    85
        # if current state is defined
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    86
        if currentstate:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    87
            self.CurrentIndex = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    88
            self.MinIndex = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    89
            self.MaxIndex = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    90
        # Initialising buffer with currentstate at the first place
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    91
        for i in xrange(UNDO_BUFFER_LENGTH):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    92
            if i == 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    93
                self.Buffer.append(currentstate)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    94
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    95
                self.Buffer.append(None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    96
        # Initialising index of state saved
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    97
        if issaved:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    98
            self.LastSave = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    99
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   100
            self.LastSave = -1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   101
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   102
    # Add a new state in buffer
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   103
    def Buffering(self, currentstate):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   104
        self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   105
        self.Buffer[self.CurrentIndex] = currentstate
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   106
        # Actualising buffer limits
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   107
        self.MaxIndex = self.CurrentIndex
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   108
        if self.MinIndex == self.CurrentIndex:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   109
            # If the removed state was the state saved, there is no state saved in the buffer
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   110
            if self.LastSave == self.MinIndex:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   111
                self.LastSave = -1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   112
            self.MinIndex = (self.MinIndex + 1) % UNDO_BUFFER_LENGTH
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   113
        self.MinIndex = max(self.MinIndex, 0)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   114
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   115
    # Return current state of buffer
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   116
    def Current(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   117
        return self.Buffer[self.CurrentIndex]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   118
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   119
    # Change current state to previous in buffer and return new current state
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   120
    def Previous(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   121
        if self.CurrentIndex != self.MinIndex:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   122
            self.CurrentIndex = (self.CurrentIndex - 1) % UNDO_BUFFER_LENGTH
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   123
            return self.Buffer[self.CurrentIndex]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   124
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   125
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   126
    # Change current state to next in buffer and return new current state
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   127
    def Next(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   128
        if self.CurrentIndex != self.MaxIndex:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   129
            self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   130
            return self.Buffer[self.CurrentIndex]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   131
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   132
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   133
    # Return True if current state is the first in buffer
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   134
    def IsFirst(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   135
        return self.CurrentIndex == self.MinIndex
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   136
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   137
    # Return True if current state is the last in buffer
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   138
    def IsLast(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   139
        return self.CurrentIndex == self.MaxIndex
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   140
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   141
    # Note that current state is saved
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   142
    def CurrentSaved(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   143
        self.LastSave = self.CurrentIndex
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   144
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   145
    # Return True if current state is saved
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   146
    def IsCurrentSaved(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   147
        return self.LastSave == self.CurrentIndex
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   148
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   149
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   150
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   151
#                           Controler for PLCOpenEditor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   152
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   153
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   154
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   155
Class which controls the operations made on the plcopen model and answers to view requests
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   156
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   157
class PLCControler:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   158
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   159
    # Create a new PLCControler
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   160
    def __init__(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   161
        self.LastNewIndex = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   162
        self.Reset()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   163
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   164
    # Reset PLCControler internal variables
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   165
    def Reset(self):
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
   166
        self.VerifyXML = False
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   167
        self.Project = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   168
        self.ProjectBuffer = None
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   169
        self.Buffering = False
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   170
        self.FilePath = ""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   171
        self.FileName = ""
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 35
diff changeset
   172
        self.ProgramFilePath = ""
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   173
        self.RefreshDataTypeUsingTree()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   174
        self.RefreshDataTypes()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   175
        self.RefreshPouUsingTree()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   176
        self.RefreshBlockTypes()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   177
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   178
    def GetQualifierTypes(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   179
        return plcopen.QualifierList
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   180
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   181
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   182
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   183
#                         Project management functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   184
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   185
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   186
    # Return if a project is opened
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   187
    def HasOpenedProject(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   188
        return self.Project != None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   189
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   190
    # Create a new project by replacing the current one
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   191
    def CreateNewProject(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   192
        # Create the project
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   193
        self.Project = plcopen.project()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   194
        self.Project.setName(name)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   195
        self.SetFilePath("")
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   196
        # Initialize the project buffer
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   197
        self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), False)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   198
        self.Buffering = False
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   199
    
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   200
    # Return project data type names
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   201
    def GetProjectDataTypeNames(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   202
        if self.Project:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   203
            return [datatype.getName() for datatype in self.Project.getDataTypes()]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   204
        return []
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   205
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   206
    # Return project pou names
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   207
    def GetProjectPouNames(self):
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   208
        if self.Project:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   209
            return [pou.getName() for pou in self.Project.getPous()]
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   210
        return []
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   211
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   212
    # Return project pou names
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   213
    def GetProjectConfigNames(self):
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   214
        if self.Project:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   215
            return [config.getName() for config in self.Project.getConfigurations()]
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   216
        return []
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   217
    
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   218
    # Return project pou variables
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   219
    def GetProjectPouVariables(self, pou_name=None):
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   220
        variables = []
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   221
        for pou in self.Project.getPous():
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   222
            if not pou_name or pou_name == pou.getName():
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   223
                variables.extend([var["Name"] for var in self.GetPouInterfaceVars(pou)])
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   224
                for transition in pou.getTransitionList():
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   225
                    variables.append(transition.getName())
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   226
                for action in pou.getActionList():
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 68
diff changeset
   227
                    variables.append(action.getName())
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   228
        return variables
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   229
    
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   230
    # Return if project is saved
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   231
    def ProjectIsSaved(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   232
        return self.ProjectBuffer.IsCurrentSaved()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   233
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   234
    # Return file path if project is an open file
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   235
    def GetFilePath(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   236
        return self.FilePath
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   237
    
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 35
diff changeset
   238
    # Return file path if project is an open file
4a8400732001 Adding optimization on redrawing
lbessard
parents: 35
diff changeset
   239
    def GetProgramFilePath(self):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 35
diff changeset
   240
        return self.ProgramFilePath
4a8400732001 Adding optimization on redrawing
lbessard
parents: 35
diff changeset
   241
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   242
    # Return file name and point out if file is up to date
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   243
    def GetFilename(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   244
        if self.ProjectBuffer.IsCurrentSaved():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   245
            return self.FileName
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   246
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   247
            return "~%s~"%self.FileName
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   248
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   249
    # Change file path and save file name or create a default one if file path not defined
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   250
    def SetFilePath(self, filepath):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   251
        self.FilePath = filepath
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   252
        if filepath == "":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   253
            self.LastNewIndex += 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   254
            self.FileName = "Unnamed%d"%self.LastNewIndex
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   255
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   256
            self.FileName = os.path.splitext(os.path.basename(filepath))[0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   257
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   258
    # Change project properties
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   259
    def SetProjectProperties(self, name = None, properties = None):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   260
        if name != None:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   261
            self.Project.setName(name)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   262
        if properties != None:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   263
            self.Project.setFileHeader(properties)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   264
        if name != None or properties != None:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   265
            self.BufferProject()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   266
            
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   267
    # Return project properties
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   268
    def GetProjectProperties(self):
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   269
        properties = self.Project.getFileHeader()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   270
        properties["projectName"] = self.Project.getName()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   271
        return properties
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   272
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   273
    # Return project informations
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   274
    def GetProjectInfos(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   275
        if self.Project:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   276
            infos = {"name": self.Project.getName(), "type": ITEM_PROJECT}
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   277
            datatypes = {"name": "Data Types", "type": ITEM_UNEDITABLE, "values":[]}
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   278
            for datatype in self.Project.getDataTypes():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   279
                datatypes["values"].append({"name": datatype.getName(), "type": ITEM_DATATYPE, "values": []})
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   280
            pou_types = {"function": {"name": "Functions", "type": ITEM_UNEDITABLE, "values":[]},
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   281
                         "functionBlock": {"name": "Function Blocks", "type": ITEM_UNEDITABLE, "values":[]},
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   282
                         "program": {"name": "Programs", "type": ITEM_UNEDITABLE, "values":[]}}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   283
            for pou in self.Project.getPous():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   284
                pou_type = pou.getPouType().getValue()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   285
                pou_infos = {"name": pou.getName(), "type": ITEM_POU}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   286
                pou_values = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   287
                if pou.getBodyType() == "SFC":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   288
                    transitions = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   289
                    for transition in pou.getTransitionList():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   290
                        transitions.append({"name": transition.getName(), "type": ITEM_TRANSITION, "values": []})
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   291
                    pou_values.append({"name": "Transitions", "type": ITEM_UNEDITABLE, "values": transitions})
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   292
                    actions = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   293
                    for action in pou.getActionList():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   294
                        actions.append({"name": action.getName(), "type": ITEM_ACTION, "values": []})
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   295
                    pou_values.append({"name": "Actions", "type": ITEM_UNEDITABLE, "values": actions})
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   296
                if pou_type in pou_types:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   297
                    pou_infos["values"] = pou_values
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   298
                    pou_types[pou_type]["values"].append(pou_infos)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   299
            configurations = {"name": "Configurations", "type": ITEM_UNEDITABLE, "values": []}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   300
            for config in self.Project.getConfigurations():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   301
                config_name = config.getName()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   302
                config_infos = {"name": config_name, "type": ITEM_CONFIGURATION, "values": []}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   303
                resources = {"name": "Resources", "type": ITEM_UNEDITABLE, "values": []}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   304
                for resource in config.getResource():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   305
                    resource_name = resource.getName()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   306
                    resource_infos = {"name": resource_name, "type": ITEM_RESOURCE, "values": []}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   307
                    resources["values"].append(resource_infos)
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 46
diff changeset
   308
                config_infos["values"] = [resources]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   309
                configurations["values"].append(config_infos)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   310
            infos["values"] = [{"name": "Properties", "type": ITEM_UNEDITABLE, "values": []},
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   311
                               datatypes, pou_types["function"], pou_types["functionBlock"], 
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   312
                               pou_types["program"], configurations]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   313
            return infos
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   314
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   315
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   316
    # Refresh the tree of user-defined data type cross-use
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   317
    def RefreshDataTypeUsingTree(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   318
        # Reset the tree of user-defined pou cross-use
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   319
        self.DataTypeUsingTree = {}
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   320
        if self.Project:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   321
            datatypes = self.Project.getDataTypes()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   322
            # Reference all the user-defined data type names and initialize the tree of 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   323
            # user-defined data type cross-use
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   324
            datatypenames = [datatype.getName() for datatype in datatypes]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   325
            for name in datatypenames:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   326
                self.DataTypeUsingTree[name] = []
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   327
            # Analyze each data type
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   328
            for datatype in datatypes:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   329
                name = datatype.getName()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   330
                basetype_content = datatype.getBaseType().getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   331
                if basetype_content["value"] is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   332
                    if basetype_content["name"] == "derived":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   333
                        basetype_name = basetype_content["value"].getName()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   334
                        if basetype_name in datatypenames and name not in self.DataTypeUsingTree[basetype_name]:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   335
                            self.DataTypeUsingTree[basetype_name].append(name)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   336
                    elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned", "array"]:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   337
                        base_type = basetype_content["value"].baseType.getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   338
                        if base_type["value"] is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   339
                            basetype_name = base_type["value"].getName()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   340
                            if basetype_name in datatypenames and name not in self.DataTypeUsingTree[basetype_name]:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   341
                                self.DataTypeUsingTree[basetype_name].append(name)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   342
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   343
    # Refresh the tree of user-defined pou cross-use
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   344
    def RefreshPouUsingTree(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   345
        # Reset the tree of user-defined pou cross-use
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   346
        self.PouUsingTree = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   347
        if self.Project:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   348
            pous = self.Project.getPous()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   349
            # Reference all the user-defined pou names and initialize the tree of 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   350
            # user-defined pou cross-use
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   351
            pounames = [pou.getName() for pou in pous]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   352
            for name in pounames:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   353
                self.PouUsingTree[name] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   354
            # Analyze each pou 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   355
            for pou in pous:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   356
                name = pou.getName()
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   357
                if pou.interface:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   358
                    # Extract variables from every varLists
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   359
                    for type, varlist in pou.getVars():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   360
                        for var in varlist.getVariable():
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   361
                            vartype_content = var.getType().getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   362
                            if vartype_content["value"] is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   363
                                typename = vartype_content["value"].getName()
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   364
                                if typename in pounames and name not in self.PouUsingTree[typename]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   365
                                    self.PouUsingTree[typename].append(name)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   366
                bodytype = pou.getBodyType()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   367
                # If pou is written in a graphical language
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   368
                if bodytype in ["FBD","LD","SFC"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   369
                    # Analyze each instance of the pou
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   370
                    for instance in pou.getInstances():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   371
                        if isinstance(instance, plcopen.block):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   372
                            typename = instance.getTypeName()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   373
                            # Update tree if there is a cross-use
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   374
                            if typename in pounames and name not in self.PouUsingTree[typename]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   375
                                 self.PouUsingTree[typename].append(name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   376
                # If pou is written in a textual language
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   377
                elif bodytype in ["IL", "ST"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   378
                    text = pou.getText()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   379
                    # Search if each pou is mentioned in the pou text
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   380
                    for typename in pounames:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   381
                        typename_model = re.compile("[ \t\n]%s[ \t\n]"%typename)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   382
                        # Update tree if there is a cross-use
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   383
                        if typename != name and typename_model.search(text):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   384
                            self.PouUsingTree[typename].append(name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   385
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   386
    # Return if data type given by name is used by another data type or pou
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   387
    def DataTypeIsUsed(self, name):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   388
        if name in self.DataTypeUsingTree:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   389
            return len(self.DataTypeUsingTree[name]) > 0
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   390
        return False
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   391
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   392
    # Return if pou given by name is used by another pou
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   393
    def PouIsUsed(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   394
        if name in self.PouUsingTree:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   395
            return len(self.PouUsingTree[name]) > 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   396
        return False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   397
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   398
    # Return if data type given by name is directly or undirectly used by the reference data type
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   399
    def DataTypeIsUsedBy(self, name, reference):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   400
        if name in self.DataTypeUsingTree:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   401
            list = self.DataTypeUsingTree[name]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   402
            # Test if data type is directly used by reference
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   403
            if reference in list:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   404
                return True
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   405
            else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   406
                # Test if data type is undirectly used by reference, by testing if data types 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   407
                # that directly use data type is directly or undirectly used by reference
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   408
                used = False
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   409
                for element in list:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   410
                    used |= self.DataTypeIsUsedBy(element, reference)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   411
                return used
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   412
        return False
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   413
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   414
    # Return if pou given by name is directly or undirectly used by the reference pou
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   415
    def PouIsUsedBy(self, name, reference):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   416
        if name in self.PouUsingTree:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   417
            list = self.PouUsingTree[name]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   418
            # Test if pou is directly used by reference
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   419
            if reference in list:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   420
                return True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   421
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   422
                # Test if pou is undirectly used by reference, by testing if pous 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   423
                # that directly use pou is directly or undirectly used by reference
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   424
                used = False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   425
                for element in list:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   426
                    used |= self.PouIsUsedBy(element, reference)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   427
                return used
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   428
        return False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   429
4
2de7fd952fdd Adding File Dialog for choosing path to generated program
lbessard
parents: 2
diff changeset
   430
    def GenerateProgram(self, filepath):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   431
        if self.Project:
97
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 94
diff changeset
   432
            try:
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 94
diff changeset
   433
                program = GenerateCurrentProgram(self.Project)
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 94
diff changeset
   434
                programfile = open(filepath, "w")
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 94
diff changeset
   435
                programfile.write(program)
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 94
diff changeset
   436
                programfile.close()
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 94
diff changeset
   437
                self.ProgramFilePath = filepath
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 94
diff changeset
   438
                return True
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 94
diff changeset
   439
            except:
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 94
diff changeset
   440
                pass
4
2de7fd952fdd Adding File Dialog for choosing path to generated program
lbessard
parents: 2
diff changeset
   441
        return False
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   442
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   443
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   444
#                        Project Pous management functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   445
#-------------------------------------------------------------------------------
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   446
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   447
    # Add a Data Type to Project
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   448
    def ProjectAddDataType(self, datatype_name):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   449
        # Add the pou to project
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   450
        self.Project.appendDataType(datatype_name)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   451
        self.RefreshDataTypeUsingTree()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   452
        self.RefreshDataTypes()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   453
        self.BufferProject()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   454
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   455
    # Remove a Data Type from project
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   456
    def ProjectRemoveDataType(self, datatype_name):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   457
        self.Project.removeDataType(datatype_name)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   458
        self.RefreshDataTypeUsingTree()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   459
        self.RefreshDataTypes()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   460
        self.BufferProject()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   461
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   462
    # Add a Pou to Project
107
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   463
    def ProjectAddPou(self, pou_name, pou_type, body_type):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   464
        # Add the pou to project
107
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   465
        self.Project.appendPou(pou_name, pou_type, body_type)
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   466
        if pou_type == "function":
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   467
            self.SetPouInterfaceReturnType(pou_name, "BOOL")
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   468
        self.RefreshPouUsingTree()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   469
        self.RefreshBlockTypes()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   470
        self.BufferProject()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   471
    
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   472
    # Remove a Pou from project
107
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   473
    def ProjectRemovePou(self, pou_name):
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   474
        self.Project.removePou(pou_name)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   475
        self.RefreshPouUsingTree()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   476
        self.RefreshBlockTypes()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   477
        self.BufferProject()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   478
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   479
    # Add a configuration to Project
107
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   480
    def ProjectAddConfiguration(self, config_name):
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   481
        self.Project.addConfiguration(config_name)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   482
        self.BufferProject()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   483
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   484
    # Remove a configuration from project
107
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   485
    def ProjectRemoveConfiguration(self, config_name):
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   486
        self.Project.removeConfiguration(config_name)
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   487
        self.BufferProject()
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   488
    
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   489
    # Add a resource to a configuration of the Project
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   490
    def ProjectAddConfigurationResource(self, config_name, resource_name):
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   491
        self.Project.addConfigurationResource(config_name, resource_name)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   492
        self.BufferProject()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   493
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   494
    # Remove a resource from a configuration of the project
107
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   495
    def ProjectRemoveConfigurationResource(self, config_name, resource_name):
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   496
        self.Project.removeConfigurationResource(config_name, resource_name)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   497
        self.BufferProject()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   498
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   499
    # Add a Transition to a Project Pou
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   500
    def ProjectAddPouTransition(self, pou_name, transition_name, transition_type):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   501
        pou = self.Project.getPou(pou_name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   502
        pou.addTransition(transition_name, transition_type)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   503
        self.BufferProject()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   504
    
107
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   505
    # Remove a Transition from a Project Pou
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   506
    def ProjectRemovePouTransition(self, pou_name, transition_name):
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   507
        pou = self.Project.getPou(pou_name)
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   508
        pou.removeTransition(transition_name)
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   509
        self.BufferProject()
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   510
    
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   511
    # Add an Action to a Project Pou
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   512
    def ProjectAddPouAction(self, pou_name, action_name, action_type):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   513
        pou = self.Project.getPou(pou_name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   514
        pou.addAction(action_name, action_type)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   515
        self.BufferProject()
107
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   516
    
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   517
    # Remove an Action from a Project Pou
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   518
    def ProjectRemovePouAction(self, pou_name, action_name):
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   519
        # Search if the pou removed is currently opened
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   520
        for i, element in enumerate(self.ElementsOpened):
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   521
            words = element.split("::")
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   522
            if words[0] == "A" and words[1] == pou_name and words[2] == action_name:
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   523
                self.RemoveElementEditing(i)
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   524
        pou = self.Project.getPou(pou_name)
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   525
        pou.removeAction(action_name)
255eada20688 Lots of bug fixed
lbessard
parents: 101
diff changeset
   526
        self.BufferProject()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   527
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   528
    # Change the name of a pou
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   529
    def ChangeDataTypeName(self, old_name, new_name):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   530
        # Found the pou corresponding to old name and change its name to new name
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   531
        datatype = self.Project.getDataType(old_name)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   532
        datatype.setName(new_name)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   533
        self.Project.updateElementName(old_name, new_name)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   534
        self.BufferProject()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   535
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   536
    # Change the name of a pou
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   537
    def ChangePouName(self, old_name, new_name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   538
        # Found the pou corresponding to old name and change its name to new name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   539
        pou = self.Project.getPou(old_name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   540
        pou.setName(new_name)
58
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
   541
        self.Project.updateElementName(old_name, new_name)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   542
        self.RefreshPouUsingTree()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   543
        self.RefreshBlockTypes()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   544
        self.BufferProject()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   545
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   546
    # Change the name of a pou transition
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   547
    def ChangePouTransitionName(self, pou_name, old_name, new_name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   548
        # Found the pou transition corresponding to old name and change its name to new name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   549
        pou = self.Project.getPou(pou_name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   550
        transition = pou.getTransition(old_name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   551
        transition.setName(new_name)
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 107
diff changeset
   552
        pou.updateElementName(old_name, new_name)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   553
        self.BufferProject()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   554
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   555
    # Change the name of a pou action
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   556
    def ChangePouActionName(self, pou_name, old_name, new_name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   557
        # Found the pou action corresponding to old name and change its name to new name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   558
        pou = self.Project.getPou(pou_name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   559
        action = pou.getAction(old_name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   560
        action.setName(new_name)
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 107
diff changeset
   561
        pou.updateElementName(old_name, new_name)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   562
        self.BufferProject()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   563
    
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   564
    # Change the name of a pou variable
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   565
    def ChangePouVariableName(self, pou_name, old_name, new_name):
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   566
        # Found the pou action corresponding to old name and change its name to new name
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   567
        pou = self.Project.getPou(pou_name)
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   568
        for type, varlist in pou.getVars():
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   569
            for var in varlist.getVariable():
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   570
                if var.getName() == old_name:
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   571
                    var.setName(new_name)
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   572
        self.RefreshBlockTypes()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   573
        self.BufferProject()
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   574
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   575
    # Change the name of a configuration
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   576
    def ChangeConfigurationName(self, old_name, new_name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   577
        # Found the configuration corresponding to old name and change its name to new name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   578
        configuration = self.Project.getConfiguration(old_name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   579
        configuration.setName(new_name)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   580
        self.BufferProject()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   581
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   582
    # Change the name of a configuration resource
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   583
    def ChangeConfigurationResourceName(self, config_name, old_name, new_name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   584
        # Found the resource corresponding to old name and change its name to new name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   585
        resource = self.Project.getConfigurationResource(config_name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   586
        resource.setName(new_name)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   587
        self.BufferProject()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   588
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   589
    # Return the type of the pou given by its name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   590
    def GetPouType(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   591
        # Found the pou correponding to name and return its type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   592
        pou = self.Project.getPou(name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   593
        return pou.pouType.getValue()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   594
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   595
    # Return pous with SFC language
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   596
    def GetSFCPous(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   597
        list = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   598
        if self.Project:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   599
            for pou in self.Project.getPous():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   600
                if pou.getBodyType() == "SFC":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   601
                    list.append(pou.getName())
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   602
        return list
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   603
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   604
    # Return the body language of the pou given by its name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   605
    def GetPouBodyType(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   606
        # Found the pou correponding to name and return its body language
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   607
        pou = self.Project.getPou(name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   608
        return pou.getBodyType()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   609
    
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   610
    # Return the actions of a pou
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   611
    def GetPouTransitions(self, pou_name):
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   612
        transitions = []
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   613
        pou = self.Project.getPou(pou_name)
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   614
        if pou.getBodyType() == "SFC":
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   615
            for transition in pou.getTransitionList():
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   616
                transitions.append(transition.getName())
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   617
        return transitions
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   618
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   619
    # Return the body language of the transition given by its name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   620
    def GetTransitionBodyType(self, pou_name, pou_transition):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   621
        # Found the pou correponding to name and return its body language
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   622
        pou = self.Project.getPou(pou_name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   623
        transition = pou.getTransition(pou_transition)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   624
        return transition.getBodyType()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   625
    
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   626
    # Return the actions of a pou
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   627
    def GetPouActions(self, pou_name):
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   628
        actions = []
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   629
        pou = self.Project.getPou(pou_name)
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   630
        if pou.getBodyType() == "SFC":
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   631
            for action in pou.getActionList():
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   632
                actions.append(action.getName())
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   633
        return actions
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 45
diff changeset
   634
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   635
    # Return the body language of the pou given by its name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   636
    def GetActionBodyType(self, pou_name, pou_action):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   637
        # Found the pou correponding to name and return its body language
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   638
        pou = self.Project.getPou(pou_name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   639
        action = pou.getAction(pou_action)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   640
        return action.getBodyType()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   641
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   642
    # Extract varlists from a list of vars
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   643
    def ExtractVarLists(self, vars):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   644
        varlist_list = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   645
        current_varlist = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   646
        current_type = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   647
        for var in vars:
34
ad3fa2752106 Bugs on ST generation fixed
lbessard
parents: 33
diff changeset
   648
            if current_type != (var["Class"], var["Retain"], var["Constant"], var["Location"] in ["", None]):
ad3fa2752106 Bugs on ST generation fixed
lbessard
parents: 33
diff changeset
   649
                current_type = (var["Class"], var["Retain"], var["Constant"], var["Location"] in ["", None])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   650
                current_varlist = plcopen.varList()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   651
                varlist_list.append((var["Class"], current_varlist))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   652
                if var["Retain"] == "Yes":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   653
                    varlist.setRetain(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   654
                if var["Constant"] == "Yes":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   655
                    varlist.setConstant(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   656
            # Create variable and change its properties
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   657
            tempvar = plcopen.varListPlain_variable()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   658
            tempvar.setName(var["Name"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   659
            var_type = plcopen.dataType()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   660
            if var["Type"] not in var_type.getChoices():
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   661
                derived_type = plcopen.derived()
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   662
                derived_type.setName(var["Type"])
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   663
                var_type.setContent("derived", derived_type)
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   664
            else:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   665
                var_type.setContent(var["Type"], None)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   666
            tempvar.setType(var_type)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   667
            if var["Initial Value"] != "":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   668
                value = plcopen.value()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   669
                value.setValue(var["Initial Value"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   670
                tempvar.setInitialValue(value)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   671
            if var["Location"] != "":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   672
                tempvar.setAddress(var["Location"])
53
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   673
            else:
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   674
                tempvar.setAddress(None)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   675
            # Add variable to varList
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   676
            current_varlist.appendVariable(tempvar)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   677
        return varlist_list
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   678
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   679
    # Replace the configuration globalvars by those given
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   680
    def SetConfigurationGlobalVars(self, name, vars):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   681
        # Found the configuration corresponding to name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   682
        configuration = self.Project.getConfiguration(name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   683
        if configuration:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   684
            # Set configuration global vars
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   685
            configuration.setGlobalVars([])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   686
            for vartype, varlist in self.ExtractVarLists(vars):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   687
                configuration.globalVars.append(varlist)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   688
        self.RefreshBlockTypes()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   689
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   690
    # Return the configuration globalvars
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   691
    def GetConfigurationGlobalVars(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   692
        vars = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   693
        # Found the configuration corresponding to name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   694
        configuration = self.Project.getConfiguration(name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   695
        if configuration:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   696
            # Extract variables from every varLists
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   697
            for varlist in configuration.getGlobalVars():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   698
                for var in varlist.getVariable():
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   699
                    tempvar = {"Name":var.getName(),"Class":"Global"}
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   700
                    vartype_content = var.getType().getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   701
                    if vartype_content["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   702
                        tempvar["Type"] = vartype_content["name"]
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   703
                    else:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   704
                        tempvar["Type"] = vartype_content["value"].getName()
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   705
                    tempvar["Edit"] = True
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   706
                    initial = var.getInitialValue()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   707
                    if initial:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   708
                        tempvar["Initial Value"] = initial.getValue()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   709
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   710
                        tempvar["Initial Value"] = ""
53
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   711
                    address = var.getAddress()
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   712
                    if address:
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   713
                        tempvar["Location"] = address
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   714
                    else:
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   715
                        tempvar["Location"] = ""
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   716
                    if varlist.getRetain():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   717
                        tempvar["Retain"] = "Yes"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   718
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   719
                        tempvar["Retain"] = "No"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   720
                    if varlist.getConstant():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   721
                        tempvar["Constant"] = "Yes"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   722
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   723
                        tempvar["Constant"] = "No"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   724
                    vars.append(tempvar)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   725
        return vars
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   726
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   727
    # Replace the resource globalvars by those given
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   728
    def SetConfigurationResourceGlobalVars(self, config_name, name, vars):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   729
        # Found the resource corresponding to name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   730
        resource = self.Project.getConfigurationResource(config_name, name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   731
        # Set resource global vars
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   732
        if resource:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   733
            resource.setGlobalVars([])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   734
            for vartype, varlist in self.ExtractVarLists(vars):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   735
                resource.globalVars.append(varlist)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   736
        self.RefreshBlockTypes()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   737
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   738
    # Return the resource globalvars
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   739
    def GetConfigurationResourceGlobalVars(self, config_name, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   740
        vars = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   741
        # Found the resource corresponding to name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   742
        resource = self.Project.getConfigurationResource(config_name, name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   743
        if resource:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   744
            # Extract variables from every varLists
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   745
            for varlist in resource.getGlobalVars():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   746
                for var in varlist.getVariable():
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   747
                    tempvar = {"Name":var.getName(),"Class":"Global"}
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   748
                    vartype_content = var.getType().getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   749
                    if vartype_content["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   750
                        tempvar["Type"] = vartype_content["name"]
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   751
                    else:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   752
                        tempvar["Type"] = vartype_content["value"].getName()
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   753
                    tempvar["Edit"] = True
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   754
                    initial = var.getInitialValue()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   755
                    if initial:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   756
                        tempvar["Initial Value"] = initial.getValue()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   757
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   758
                        tempvar["Initial Value"] = ""
53
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   759
                    address = var.getAddress()
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   760
                    if address:
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   761
                        tempvar["Location"] = address
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   762
                    else:
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   763
                        tempvar["Location"] = ""
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   764
                    if varlist.getRetain():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   765
                        tempvar["Retain"] = "Yes"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   766
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   767
                        tempvar["Retain"] = "No"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   768
                    if varlist.getConstant():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   769
                        tempvar["Constant"] = "Yes"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   770
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   771
                        tempvar["Constant"] = "No"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   772
                    vars.append(tempvar)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   773
        return vars
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   774
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   775
    # Return the interface of the pou given by its name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   776
    def GetPouInterfaceVarsByName(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   777
        # Found the pou correponding to name and return the interface
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   778
        return self.GetPouInterfaceVars(self.Project.getPou(name))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   779
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   780
    # Return the interface for the given pou
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   781
    def GetPouInterfaceVars(self, pou):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   782
        vars = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   783
        # Verify that the pou has an interface
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   784
        if pou.interface:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   785
            # Extract variables from every varLists
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   786
            for type, varlist in pou.getVars():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   787
                for var in varlist.getVariable():
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   788
                    tempvar = {"Name":var.getName(),"Class":type}
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   789
                    vartype_content = var.getType().getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   790
                    if vartype_content["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   791
                        tempvar["Type"] = vartype_content["name"]
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   792
                        tempvar["Edit"] = True
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   793
                    else:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   794
                        tempvar["Type"] = vartype_content["value"].getName()
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   795
                        tempvar["Edit"] = not pou.hasBlock(tempvar["Name"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   796
                    initial = var.getInitialValue()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   797
                    if initial:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   798
                        tempvar["Initial Value"] = initial.getValue()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   799
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   800
                        tempvar["Initial Value"] = ""
53
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   801
                    address = var.getAddress()
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   802
                    if address:
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   803
                        tempvar["Location"] = address
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   804
                    else:
4988262d03e3 *** empty log message ***
lbessard
parents: 47
diff changeset
   805
                        tempvar["Location"] = ""
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   806
                    if varlist.getRetain():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   807
                        tempvar["Retain"] = "Yes"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   808
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   809
                        tempvar["Retain"] = "No"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   810
                    if varlist.getConstant():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   811
                        tempvar["Constant"] = "Yes"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   812
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   813
                        tempvar["Constant"] = "No"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   814
                    vars.append(tempvar)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   815
        return vars
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   816
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   817
    # Replace the Pou interface by the one given
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   818
    def SetPouInterfaceVars(self, name, vars):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   819
        # Found the pou corresponding to name and add interface if there isn't one yet
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   820
        pou = self.Project.getPou(name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   821
        if not pou.interface:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   822
            pou.interface = plcopen.pou_interface()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   823
        # Set Pou interface
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   824
        pou.setVars(self.ExtractVarLists(vars))
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
   825
        self.RefreshPouUsingTree()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   826
        self.RefreshBlockTypes()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
   827
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   828
    # Replace the return type of the pou given by its name (only for functions)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   829
    def SetPouInterfaceReturnType(self, name, type):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   830
        pou = self.Project.getPou(name)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   831
        if not pou.interface:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   832
            pou.interface = plcopen.pou_interface()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   833
        # If there isn't any return type yet, add it
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   834
        return_type = pou.interface.getReturnType()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   835
        if not return_type:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   836
            return_type = plcopen.dataType()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   837
            pou.interface.setReturnType(return_type)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   838
        # Change return type
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   839
        if type in self.GetBaseTypes():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   840
            return_type.setContent(type, None)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   841
        else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   842
            derived_type = plcopen.derived()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   843
            derived_type.setName(type)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   844
            return_type.setContent("derived", derived_type)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   845
        self.RefreshBlockTypes()
58
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
   846
    
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
   847
    def UpdateProjectUsedPous(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
   848
        if self.Project:
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
   849
            self.Project.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
   850
    
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   851
    def UpdateEditedElementUsedVariable(self, tagname, old_name, new_name):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   852
        pou = self.GetEditedElement(tagname)
58
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
   853
        if pou:
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
   854
            pou.updateElementName(old_name, new_name)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   855
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   856
    # Return the return type of the pou given by its name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   857
    def GetPouInterfaceReturnTypeByName(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   858
        # Found the pou correponding to name and return the return type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   859
        return self.GetPouInterfaceReturnType(self.Project.getPou(name))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   860
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   861
    # Return the return type of the given pou
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   862
    def GetPouInterfaceReturnType(self, pou):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   863
        # Verify that the pou has an interface
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   864
        if pou.interface:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   865
            # Return the return type if there is one
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   866
            return_type = pou.interface.getReturnType()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   867
            if return_type:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   868
                returntype_content = return_type.getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   869
                if returntype_content["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   870
                    return returntype_content["name"]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   871
                else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   872
                    return returntype_content["value"].getName()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   873
        return None
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   874
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   875
    # Update data types with user-defined data types added
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   876
    def RefreshDataTypes(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   877
        ResetTypeHierarchy()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   878
        ResetEnumeratedDataValues()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   879
        if self.Project:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   880
            for datatype in self.Project.getDataTypes():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   881
                name = datatype.getName()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   882
                basetype_content = datatype.getBaseType().getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   883
                if basetype_content["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   884
                    AddDataTypeHierarchy(name, basetype_content["name"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   885
                elif basetype_content["name"] == "derived":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   886
                    AddDataTypeHierarchy(name, basetype_content["value"].getName())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   887
                elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   888
                    base_type = basetype_content["value"].baseType.getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   889
                    if base_type["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   890
                        AddDataTypeHierarchy(name, base_type["name"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   891
                    else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   892
                        AddDataTypeHierarchy(name, base_type["value"].getName())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   893
                else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   894
                    if basetype_content["name"] == "enum":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   895
                        values = []
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   896
                        for value in basetype_content["value"].values.getValue():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   897
                            values.append(value.getName())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   898
                        AddEnumeratedDataValues(values)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   899
                    AddDataTypeHierarchy(name, "ANY_DERIVED")
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   900
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   901
    # Update Block types with user-defined pou added
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   902
    def RefreshBlockTypes(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   903
        if BlockTypes[-1]["name"] == "User-defined POUs":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   904
            BlockTypes[-1]["list"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   905
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   906
            BlockTypes.append({"name" : "User-defined POUs", "list": []})
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   907
        if self.Project:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   908
            for pou in self.Project.getPous():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   909
                pou_name = pou.getName()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   910
                pou_type = pou.pouType.getValue()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   911
                if pou_type != "program":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   912
                    block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False,
81
11ca9ad9e3c3 Fixed ST generation bug with custom FB
etisserant
parents: 80
diff changeset
   913
                                   "inputs" : [], "outputs" : [], "comment" : "",
100
4e3f5b320bc3 fixed code gen crash when using own FB/F in FBD
etisserant
parents: 99
diff changeset
   914
                                   "generate" : generate_block, "initialise" : initialise_block }
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   915
                    if pou.getInterface():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   916
                        for type, varlist in pou.getVars():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   917
                            if type == "InOut":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   918
                                for var in varlist.getVariable():
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   919
                                    var_type = var.type.getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   920
                                    if var_type["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   921
                                        block_infos["inputs"].append((var.getName(),var_type["name"],"none"))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   922
                                        block_infos["outputs"].append((var.getName(),var_type["name"],"none"))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   923
                                    else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   924
                                        block_infos["inputs"].append((var.getName(),var_type["value"].getName(),"none"))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   925
                                        block_infos["outputs"].append((var.getName(),var_type["value"].getName(),"none"))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   926
                            elif type == "Input":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   927
                                for var in varlist.getVariable():
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   928
                                    var_type = var.type.getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   929
                                    if var_type["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   930
                                        block_infos["inputs"].append((var.getName(),var_type["name"],"none"))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   931
                                    else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   932
                                        block_infos["inputs"].append((var.getName(),var_type["value"].getName(),"none"))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   933
                            elif type == "Output":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   934
                                for var in varlist.getVariable():
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   935
                                    var_type = var.type.getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   936
                                    if var_type["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   937
                                        block_infos["outputs"].append((var.getName(),var_type["name"],"none"))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   938
                                    else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   939
                                        block_infos["outputs"].append((var.getName(),var_type["value"].getName(),"none"))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   940
                        return_type = pou.interface.getReturnType()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   941
                        if return_type:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   942
                            var_type = return_type.getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   943
                            if var_type["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   944
                                block_infos["outputs"].append(("",var_type["name"],"none"))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   945
                            else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   946
                                block_infos["outputs"].append(("",var_type["value"].getName(),"none"))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   947
                    if pou.getBodyType() in ["FBD","LD","SFC"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   948
                        for instance in pou.getInstances():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   949
                            if isinstance(instance, plcopen.comment):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   950
                                block_infos["comment"] = instance.getContentText()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   951
                    BlockTypes[-1]["list"].append(block_infos)
92
76d5001393df Adding support for refreshing PLCOpenEditor block list
lbessard
parents: 90
diff changeset
   952
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   953
    # Return Block types checking for recursion
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   954
    def GetBlockTypes(self, tagname = ""):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   955
        name = ""
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   956
        type = None
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   957
        if self.Project:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   958
            words = tagname.split("::")
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   959
            if words[0] in ["P","T","A"]:
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   960
                name = words[1]
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   961
                type = self.GetPouType(name)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   962
        if type == "function":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   963
            blocktypes = []
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   964
            for category in BlockTypes[:-1] + PluginTypes:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   965
                cat = {"name" : category["name"], "list" : []}
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   966
                for block in category["list"]:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   967
                    if block["type"] == "function":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   968
                        cat["list"].append(block)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   969
                if len(cat["list"]) > 0:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   970
                    blocktypes.append(cat)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   971
        else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   972
            blocktypes = [category for category in BlockTypes[:-1] + PluginTypes]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   973
        if self.Project:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   974
            blocktypes.append({"name" : "User-defined POUs", "list": []})
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   975
            for blocktype in BlockTypes[-1]["list"]:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   976
                if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   977
                    blocktypes[-1]["list"].append(blocktype)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   978
        return blocktypes
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   979
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   980
    # Return Function Block types checking for recursion
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   981
    def GetFunctionBlockTypes(self, tagname = ""):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   982
        name = ""
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   983
        type = None
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   984
        if self.Project:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   985
            words = tagname.split("::")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   986
            if words[0] in ["P","T","A"]:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
   987
                name = words[1]
13
69075340d6a9 Adding support for forbidding insertion of function block into function
lbessard
parents: 6
diff changeset
   988
                type = self.GetPouType(name)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   989
        blocktypes = []
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   990
        for category in BlockTypes[:-1]:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   991
            for block in category["list"]:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   992
                if block["type"] != "function":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   993
                    blocktypes.append(block["name"])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   994
        if self.Project:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   995
            for blocktype in BlockTypes[-1]["list"]:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   996
                if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   997
                    blocktypes.append(blocktype["name"])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   998
        return blocktypes
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   999
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1000
    # Return Block types checking for recursion
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1001
    def GetBlockResource(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1002
        blocktypes = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1003
        for category in BlockTypes[:-1]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1004
            for blocktype in category["list"]:
29
3b7e23a323a6 Adding support for configuration generation
lbessard
parents: 28
diff changeset
  1005
                if blocktype["type"] == "program":
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1006
                    blocktypes.append(blocktype["name"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1007
        if self.Project:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1008
            for pou in self.Project.getPous():
29
3b7e23a323a6 Adding support for configuration generation
lbessard
parents: 28
diff changeset
  1009
                if pou.pouType.getValue() == "program":
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1010
                    blocktypes.append(pou.getName())
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1011
        return blocktypes
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1012
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1013
    # Return Data Types checking for recursion
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1014
    def GetDataTypes(self, tagname = "", basetypes = True):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1015
        if basetypes:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1016
            datatypes = self.GetBaseTypes()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1017
        else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1018
            datatypes = []
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1019
        if self.Project:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1020
            words = tagname.split("::")
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1021
            if words[0] in ["D"]:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1022
                name = words[1]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1023
            else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1024
                name = ""
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1025
            for datatype in self.Project.getDataTypes():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1026
                datatype_name = datatype.getName()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1027
                if datatype_name != name and not self.DataTypeIsUsedBy(name, datatype_name):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1028
                    datatypes.append(datatype_name)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1029
        return datatypes
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1030
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1031
    # Return Base Types
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1032
    def GetBaseTypes(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1033
        return [value for value, parent in TypeHierarchy_list if not value.startswith("ANY")]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1034
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1035
    # Return Subrange types
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1036
    def GetSubrangeTypes(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1037
        return [value for value, range in DataTypeRange_list]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1038
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1039
    # Return Enumerated Values
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1040
    def GetEnumeratedDataValues(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1041
        return EnumeratedDataValues
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1042
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1043
#-------------------------------------------------------------------------------
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1044
#                   Project Element tag name computation functions
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1045
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1046
    
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1047
    # Compute a data type name
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1048
    def ComputeDataTypeName(self, datatype):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1049
        return "D::%s" % datatype
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1050
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1051
    # Compute a pou name
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1052
    def ComputePouName(self, pou):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1053
        return "P::%s" % pou
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1054
    
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1055
    # Compute a pou transition name
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1056
    def ComputePouTransitionName(self, pou, transition):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1057
        return "T::%s::%s" % (pou, transition)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1058
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1059
    # Compute a pou action name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1060
    def ComputePouActionName(self, pou, action):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1061
        return "A::%s::%s" % (pou, action)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1062
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1063
    # Compute a pou  name
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 46
diff changeset
  1064
    def ComputeConfigurationName(self, config):
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 46
diff changeset
  1065
        return "C::%s" % config
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 46
diff changeset
  1066
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 46
diff changeset
  1067
    # Compute a pou  name
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1068
    def ComputeConfigurationResourceName(self, config, resource):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1069
        return "R::%s::%s" % (config, resource)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1070
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1071
#-------------------------------------------------------------------------------
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1072
#                    Project opened Data types management functions
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1073
#-------------------------------------------------------------------------------
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1074
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1075
    # Return the data type informations
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1076
    def GetDataTypeInfos(self, tagname):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1077
        words = tagname.split("::")
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1078
        if words[0] == "D":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1079
            infos = {}
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1080
            datatype = self.Project.getDataType(words[1])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1081
            basetype_content = datatype.baseType.getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1082
            if basetype_content["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1083
                infos["type"] = "Directly"
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1084
                infos["base_type"] = basetype_content["name"]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1085
            elif basetype_content["name"] == "derived":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1086
                infos["type"] = "Directly"
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1087
                infos["base_type"] = basetype_content["value"].getName()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1088
            elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1089
                infos["type"] = "Subrange"
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1090
                infos["min"] = basetype_content["value"].range.getLower()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1091
                infos["max"] = basetype_content["value"].range.getUpper()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1092
                base_type = basetype_content["value"].baseType.getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1093
                if base_type["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1094
                    infos["base_type"] = base_type["name"]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1095
                else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1096
                    infos["base_type"] = base_type["value"].getName()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1097
            elif basetype_content["name"] == "enum":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1098
                infos["type"] = "Enumerated"
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1099
                infos["values"] = []
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1100
                for value in basetype_content["value"].values.getValue():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1101
                    infos["values"].append(value.getName())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1102
            elif basetype_content["name"] == "array":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1103
                infos["type"] = "Array"
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1104
                infos["dimensions"] = []
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1105
                for dimension in basetype_content["value"].getDimension():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1106
                    infos["dimensions"].append(str(dimension.getUpper()))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1107
                base_type = basetype_content["value"].baseType.getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1108
                if base_type["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1109
                    infos["base_type"] = base_type["name"]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1110
                else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1111
                    infos["base_type"] = base_type["value"].getName()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1112
            if datatype.initialValue is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1113
                infos["initial"] = str(datatype.initialValue.getValue())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1114
            else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1115
                infos["initial"] = ""
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1116
            return infos
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1117
        return None
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1118
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1119
    # Change the data type informations
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1120
    def SetDataTypeInfos(self, tagname, infos):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1121
        words = tagname.split("::")
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1122
        if words[0] == "D":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1123
            datatype = self.Project.getDataType(words[1])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1124
            if infos["type"] == "Directly":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1125
                if infos["base_type"] in self.GetBaseTypes():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1126
                    datatype.baseType.setContent(infos["base_type"], None)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1127
                else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1128
                    derived_datatype = plcopen.derived()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1129
                    derived_datatype.setName(infos["base_type"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1130
                    datatype.baseType.setContent("derived", derived_datatype)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1131
            elif infos["type"] == "Subrange":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1132
                if infos["base_type"] in GetSubTypes("ANY_UINT"):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1133
                    subrange = plcopen.subrangeUnsigned()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1134
                    datatype.baseType.setContent("subrangeUnsigned", subrange)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1135
                else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1136
                    subrange = plcopen.subrangeSigned()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1137
                    datatype.baseType.setContent("subrangeSigned", subrange)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1138
                subrange.range.setLower(infos["min"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1139
                subrange.range.setUpper(infos["max"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1140
                if infos["base_type"] in self.GetBaseTypes():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1141
                    subrange.baseType.setContent(infos["base_type"], None)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1142
                else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1143
                    derived_datatype = plcopen.derived()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1144
                    derived_datatype.setName(infos["base_type"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1145
                    subrange.baseType.setContent("derived", derived_datatype)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1146
            elif infos["type"] == "Enumerated":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1147
                enumerated = plcopen.enum()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1148
                for enum_value in infos["values"]:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1149
                    value = plcopen.values_value()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1150
                    value.setName(enum_value)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1151
                    enumerated.values.appendValue(value)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1152
                datatype.baseType.setContent("enum", enumerated)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1153
            elif infos["type"] == "Array":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1154
                array = plcopen.array()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1155
                for dimension in infos["dimensions"]:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1156
                    dimension_range = plcopen.rangeSigned()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1157
                    dimension_range.setLower(1)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1158
                    dimension_range.setUpper(int(dimension))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1159
                    array.appendDimension(dimension_range)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1160
                if infos["base_type"] in self.GetBaseTypes():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1161
                    array.baseType.setContent(infos["base_type"], None)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1162
                else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1163
                    derived_datatype = plcopen.derived()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1164
                    derived_datatype.setName(infos["base_type"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1165
                    array.baseType.setContent("derived", derived_datatype)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1166
                datatype.baseType.setContent("array", array)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1167
            if infos["initial"] != "":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1168
                if datatype.initialValue is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1169
                    datatype.initialValue = plcopen.value()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1170
                datatype.initialValue.setValue(infos["initial"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1171
            else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1172
                datatype.initialValue = None
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1173
            self.RefreshDataTypeUsingTree()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1174
            self.RefreshDataTypes()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1175
            self.BufferProject()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1176
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1177
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1178
#                       Project opened Pous management functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1179
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1180
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1181
    # Return edited element
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1182
    def GetEditedElement(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1183
        words = tagname.split("::")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1184
        if words[0] == "P":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1185
            return self.Project.getPou(words[1])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1186
        if words[0] in ['T', 'A']:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1187
            pou = self.Project.getPou(words[1])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1188
            if words[0] == 'T':
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1189
                return pou.getTransition(words[2])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1190
            elif words[0] == 'A':
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1191
                return pou.getAction(words[2])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1192
        elif words[0] == 'C':
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1193
            return self.Project.getConfiguration(words[1])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1194
        elif words[0] == 'R':
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1195
            return self.Project.getConfigurationResource(words[1], words[2])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1196
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1197
    
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1198
    # Return edited element name
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1199
    def GetEditedElementName(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1200
        words = tagname.split("::")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1201
        if words[0] in ["P","C"]:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1202
            return words[1]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1203
        else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1204
            return words[2]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1205
        return None
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1206
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1207
    # Return edited element name and type
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1208
    def GetEditedElementType(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1209
        words = tagname.split("::")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1210
        if words[0] in ["P","T","A"]:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1211
            return words[1], self.GetPouType(words[1])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1212
        return None, None
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1213
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1214
    # Return language in which edited element is written
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1215
    def GetEditedElementBodyType(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1216
        words = tagname.split("::")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1217
        if words[0] == "P":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1218
            return self.GetPouBodyType(words[1])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1219
        elif words[0] == 'T':
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1220
            return self.GetTransitionBodyType(words[1], words[2])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1221
        elif words[0] == 'A':
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1222
            return self.GetActionBodyType(words[1], words[2])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1223
        return None
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1224
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1225
    # Return the edited element variables
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1226
    def GetEditedElementInterfaceVars(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1227
        words = tagname.split("::")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1228
        if words[0] in ["P","T","A"]:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1229
            pou = self.Project.getPou(words[1])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1230
            return self.GetPouInterfaceVars(pou)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1231
        return []
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1232
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1233
    # Return the edited element return type
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1234
    def GetEditedElementInterfaceReturnType(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1235
        words = tagname.split("::")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1236
        if words[0] == "P":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1237
            pou = self.Project.getPou(words[1])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1238
            return self.GetPouInterfaceReturnType(pou)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1239
        elif words[0] == 'T':
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1240
            return "BOOL"
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1241
        return None
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1242
    
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1243
    # Change the edited element text
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1244
    def SetEditedElementText(self, tagname, text):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1245
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1246
        if element != None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1247
            element.setText(text)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1248
            self.RefreshPouUsingTree()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1249
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1250
    # Return the edited element text
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1251
    def GetEditedElementText(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1252
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1253
        if element != None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1254
            return element.getText()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1255
        return ""
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1256
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1257
    # Return the edited element transitions
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1258
    def GetEditedElementTransitions(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1259
        pou = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1260
        if pou != None and pou.getBodyType() == "SFC":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1261
            transitions = []
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1262
            for transition in pou.getTransitionList():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1263
                transitions.append(transition.getName())
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1264
            return transitions
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1265
        return []
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1266
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1267
    # Return edited element transitions
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1268
    def GetEditedElementActions(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1269
        pou = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1270
        if pou != None and pou.getBodyType() == "SFC":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1271
            actions = []
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1272
            for action in pou.getActionList():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1273
                actions.append(action.getName())
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1274
            return actions
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1275
        return []
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1276
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1277
    # Return the names of the pou elements
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1278
    def GetEditedElementVariables(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1279
        words = tagname.split("::")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1280
        if words[0] in ["P","T","A"]:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1281
            return self.GetProjectPouVariables(words[1])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1282
        return []
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1283
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1284
    # Return the current pou editing informations
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1285
    def GetEditedElementInstanceInfos(self, tagname, id = None, exclude = []):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1286
        infos = {}
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1287
        instance = None
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1288
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1289
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1290
            # if id is defined
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1291
            if id is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1292
                instance = element.getInstance(id)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1293
            else:
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1294
                instance = element.getRandomInstance(exclude)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1295
        if instance is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1296
            if id is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1297
                infos["id"] = id
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1298
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1299
                infos["id"] = instance.getLocalId() 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1300
            infos["x"] = instance.getX()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1301
            infos["y"] = instance.getY()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1302
            infos["height"] = instance.getHeight()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1303
            infos["width"] = instance.getWidth()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1304
            if isinstance(instance, plcopen.block):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1305
                infos["name"] = instance.getInstanceName()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1306
                infos["type"] = instance.getTypeName()
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1307
                executionOrder = instance.getExecutionOrderId()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1308
                if executionOrder is not None:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1309
                    infos["executionOrder"] = executionOrder
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1310
                else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1311
                    infos["executionOrder"] = 0
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1312
                infos["connectors"] = {"inputs":[],"outputs":[]}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1313
                for variable in instance.inputVariables.getVariable():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1314
                    connector = {}
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 81
diff changeset
  1315
                    connector["name"] = variable.getFormalParameter()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1316
                    connector["position"] = variable.connectionPointIn.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1317
                    connector["negated"] = variable.getNegated()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1318
                    connector["edge"] = variable.getConnectorEdge()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1319
                    connector["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1320
                    connections = variable.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1321
                    if connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1322
                        for link in connections:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1323
                            dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1324
                            connector["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1325
                    infos["connectors"]["inputs"].append(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1326
                for variable in instance.outputVariables.getVariable():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1327
                    connector = {}
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 81
diff changeset
  1328
                    connector["name"] = variable.getFormalParameter()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1329
                    connector["position"] = variable.connectionPointOut.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1330
                    connector["negated"] = variable.getNegated()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1331
                    connector["edge"] = variable.getConnectorEdge()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1332
                    infos["connectors"]["outputs"].append(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1333
            elif isinstance(instance, plcopen.inVariable):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1334
                infos["name"] = instance.getExpression()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1335
                infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1336
                infos["type"] = "input"
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1337
                executionOrder = instance.getExecutionOrderId()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1338
                if executionOrder is not None:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1339
                    infos["executionOrder"] = executionOrder
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1340
                else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1341
                    infos["executionOrder"] = 0
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1342
                infos["connector"] = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1343
                infos["connector"]["position"] = instance.connectionPointOut.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1344
                infos["connector"]["negated"] = instance.getNegated()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1345
                infos["connector"]["edge"] = instance.getConnectorEdge()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1346
            elif isinstance(instance, plcopen.outVariable):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1347
                infos["name"] = instance.getExpression()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1348
                infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1349
                infos["type"] = "output"
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1350
                executionOrder = instance.getExecutionOrderId()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1351
                if executionOrder is not None:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1352
                    infos["executionOrder"] = executionOrder
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1353
                else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1354
                    infos["executionOrder"] = 0
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1355
                infos["connector"] = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1356
                infos["connector"]["position"] = instance.connectionPointIn.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1357
                infos["connector"]["negated"] = instance.getNegated()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1358
                infos["connector"]["edge"] = instance.getConnectorEdge()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1359
                infos["connector"]["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1360
                connections = instance.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1361
                if connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1362
                    for link in connections:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1363
                        dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1364
                        infos["connector"]["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1365
            elif isinstance(instance, plcopen.inOutVariable):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1366
                infos["name"] = instance.getExpression()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1367
                infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1368
                infos["type"] = "inout"
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1369
                executionOrder = instance.getExecutionOrderId()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1370
                if executionOrder is not None:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1371
                    infos["executionOrder"] = executionOrder
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1372
                else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1373
                    infos["executionOrder"] = 0
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1374
                infos["connectors"] = {"input":{},"output":{}}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1375
                infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1376
                infos["connectors"]["output"]["negated"] = instance.getNegatedOut()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1377
                infos["connectors"]["output"]["edge"] = instance.getOutputEdge()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1378
                infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1379
                infos["connectors"]["input"]["negated"] = instance.getNegatedIn()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1380
                infos["connectors"]["input"]["edge"] = instance.getInputEdge()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1381
                infos["connectors"]["input"]["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1382
                connections = instance.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1383
                if connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1384
                    for link in connections:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1385
                        dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1386
                        infos["connectors"]["input"]["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1387
            elif isinstance(instance, plcopen.continuation):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1388
                infos["name"] = instance.getName()
45
42637f721b5b Bugs fixed
lbessard
parents: 42
diff changeset
  1389
                infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1390
                infos["type"] = "continuation"
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1391
                executionOrder = instance.getExecutionOrderId()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1392
                if executionOrder is not None:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1393
                    infos["executionOrder"] = executionOrder
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1394
                else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1395
                    infos["executionOrder"] = 0
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1396
                infos["connector"] = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1397
                infos["connector"]["position"] = instance.connectionPointOut.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1398
            elif isinstance(instance, plcopen.connector):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1399
                infos["name"] = instance.getName()
45
42637f721b5b Bugs fixed
lbessard
parents: 42
diff changeset
  1400
                infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1401
                infos["type"] = "connection"
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1402
                executionOrder = instance.getExecutionOrderId()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1403
                if executionOrder is not None:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1404
                    infos["executionOrder"] = executionOrder
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1405
                else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1406
                    infos["executionOrder"] = 0
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1407
                infos["connector"] = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1408
                infos["connector"]["position"] = instance.connectionPointIn.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1409
                infos["connector"]["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1410
                connections = instance.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1411
                if connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1412
                    for link in connections:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1413
                        dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1414
                        infos["connector"]["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1415
            elif isinstance(instance, plcopen.comment):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1416
                infos["type"] = "comment"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1417
                infos["content"] = instance.getContentText()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1418
            elif isinstance(instance, plcopen.leftPowerRail):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1419
                infos["type"] = "leftPowerRail"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1420
                infos["connectors"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1421
                for connection in instance.getConnectionPointOut():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1422
                    connector = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1423
                    connector["position"] = connection.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1424
                    infos["connectors"].append(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1425
            elif isinstance(instance, plcopen.rightPowerRail):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1426
                infos["type"] = "rightPowerRail"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1427
                infos["connectors"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1428
                for connection in instance.getConnectionPointIn():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1429
                    connector = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1430
                    connector["position"] = connection.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1431
                    connector["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1432
                    for link in connection.getConnections():
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1433
                        dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1434
                        connector["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1435
                    infos["connectors"].append(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1436
            elif isinstance(instance, plcopen.contact):
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1437
                infos["name"] = instance.getVariable()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1438
                infos["type"] = "contact"
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1439
                executionOrder = instance.getExecutionOrderId()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1440
                if executionOrder is not None:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1441
                    infos["executionOrder"] = executionOrder
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1442
                else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1443
                    infos["executionOrder"] = 0
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1444
                infos["negated"] = instance.getNegated()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1445
                infos["edge"] = instance.getContactEdge()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1446
                infos["connectors"] = {"input":{},"output":{}}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1447
                infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1448
                infos["connectors"]["input"]["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1449
                connections = instance.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1450
                if connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1451
                    for link in connections:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1452
                        dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1453
                        infos["connectors"]["input"]["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1454
                infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1455
            elif isinstance(instance, plcopen.coil):
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1456
                infos["name"] = instance.getVariable()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1457
                infos["type"] = "coil"
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1458
                executionOrder = instance.getExecutionOrderId()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1459
                if executionOrder is not None:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1460
                    infos["executionOrder"] = executionOrder
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1461
                else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1462
                    infos["executionOrder"] = 0
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1463
                infos["negated"] = instance.getNegated()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1464
                infos["storage"] = instance.getCoilStorage()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1465
                infos["connectors"] = {"input":{},"output":{}}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1466
                infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1467
                infos["connectors"]["input"]["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1468
                connections = instance.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1469
                if connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1470
                    for link in connections:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1471
                        dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1472
                        infos["connectors"]["input"]["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1473
                infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1474
            elif isinstance(instance, plcopen.step):
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1475
                infos["name"] = instance.getName()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1476
                infos["type"] = "step"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1477
                infos["initial"] = instance.getInitialStep()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1478
                infos["connectors"] = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1479
                if instance.connectionPointIn:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1480
                    infos["connectors"]["input"] = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1481
                    infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1482
                    infos["connectors"]["input"]["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1483
                    connections = instance.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1484
                    if connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1485
                        for link in connections:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1486
                            dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1487
                            infos["connectors"]["input"]["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1488
                if instance.connectionPointOut:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1489
                    infos["connectors"]["output"] = {"position" : instance.connectionPointOut.getRelPosition()}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1490
                if instance.connectionPointOutAction:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1491
                    infos["connectors"]["action"] = {"position" : instance.connectionPointOutAction.getRelPosition()}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1492
            elif isinstance(instance, plcopen.transition):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1493
                infos["type"] = "transition"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1494
                condition = instance.getConditionContent()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1495
                priority = instance.getPriority()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1496
                if priority == None:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1497
                    infos["priority"] = 0
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1498
                else:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1499
                    infos["priority"] = priority
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1500
                infos["condition_type"] = condition["type"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1501
                infos["connectors"] = {"input":{},"output":{}}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1502
                infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1503
                infos["connectors"]["input"]["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1504
                connections = instance.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1505
                if connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1506
                    for link in connections:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1507
                        dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1508
                        infos["connectors"]["input"]["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1509
                infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 62
diff changeset
  1510
                if infos["condition_type"] == "connection":
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 62
diff changeset
  1511
                    infos["connectors"]["connection"] = {}
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 62
diff changeset
  1512
                    infos["connectors"]["connection"]["links"] = []
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 62
diff changeset
  1513
                    connections = instance.getConnections()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 62
diff changeset
  1514
                    if connections:
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 62
diff changeset
  1515
                        for link in connections:
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 62
diff changeset
  1516
                            dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 62
diff changeset
  1517
                            infos["connectors"]["connection"]["links"].append(dic)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 62
diff changeset
  1518
                    infos["condition"] = None
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 62
diff changeset
  1519
                else:
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 62
diff changeset
  1520
                    infos["condition"] = condition["value"]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1521
            elif isinstance(instance, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1522
                if isinstance(instance, plcopen.selectionDivergence):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1523
                    infos["type"] = "selectionDivergence"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1524
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1525
                    infos["type"] = "simultaneousDivergence"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1526
                infos["connectors"] = {"inputs":[],"outputs":[]}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1527
                connector = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1528
                connector["position"] = instance.connectionPointIn.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1529
                connector["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1530
                connections = instance.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1531
                if connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1532
                    for link in connections:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1533
                        dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1534
                        connector["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1535
                infos["connectors"]["inputs"].append(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1536
                for sequence in instance.getConnectionPointOut():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1537
                    connector = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1538
                    connector["position"] = sequence.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1539
                    infos["connectors"]["outputs"].append(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1540
            elif isinstance(instance, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1541
                if isinstance(instance, plcopen.selectionConvergence):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1542
                    infos["type"] = "selectionConvergence"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1543
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1544
                    infos["type"] = "simultaneousConvergence"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1545
                infos["connectors"] = {"inputs":[],"outputs":[]}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1546
                for sequence in instance.getConnectionPointIn():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1547
                    connector = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1548
                    connector["position"] = sequence.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1549
                    connector["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1550
                    connections = sequence.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1551
                    if connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1552
                        for link in connections:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1553
                            dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1554
                            connector["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1555
                    infos["connectors"]["inputs"].append(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1556
                connector = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1557
                connector["position"] = instance.connectionPointOut.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1558
                infos["connectors"]["outputs"].append(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1559
            elif isinstance(instance, plcopen.jumpStep):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1560
                infos["type"] = "jump"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1561
                infos["target"] = instance.getTargetName()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1562
                infos["connector"] = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1563
                infos["connector"]["position"] = instance.connectionPointIn.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1564
                infos["connector"]["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1565
                connections = instance.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1566
                if connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1567
                    for link in connections:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1568
                        dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1569
                        infos["connector"]["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1570
            elif isinstance(instance, plcopen.actionBlock):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1571
                infos["type"] = "actionBlock"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1572
                infos["actions"] = instance.getActions()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1573
                infos["connector"] = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1574
                infos["connector"]["position"] = instance.connectionPointIn.getRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1575
                infos["connector"]["links"] = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1576
                connections = instance.connectionPointIn.getConnections()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1577
                if connections:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1578
                    for link in connections:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1579
                        dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1580
                        infos["connector"]["links"].append(dic)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1581
            return infos
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1582
        return False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1583
    
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1584
    def ClearEditedElementExecutionOrder(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1585
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1586
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1587
            element.resetExecutionOrder()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1588
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1589
    def ResetEditedElementExecutionOrder(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1590
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1591
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1592
            element.compileExecutionOrder()
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 117
diff changeset
  1593
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1594
    # Return the variable type of the given pou
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1595
    def GetEditedElementVarValueType(self, tagname, varname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1596
        words = tagname.split("::")
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1597
        if words[0] in ["P","T","A"]:
45
42637f721b5b Bugs fixed
lbessard
parents: 42
diff changeset
  1598
            pou = self.Project.getPou(words[1])
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1599
            for type, varlist in pou.getVars():
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1600
                for var in varlist.getVariable():
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1601
                    if var.getName() == varname:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1602
                        vartype_content = var.getType().getContent()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1603
                        if vartype_content["value"] is None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1604
                            return vartype_content["name"]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1605
                        else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  1606
                            return vartype_content["value"].getName()
101
3f06a178b960 Fixed crash while draging connector from pins with undefined types
etisserant
parents: 100
diff changeset
  1607
        return None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1608
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1609
    def SetConnectionWires(self, connection, connector):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1610
        wires = connector.GetWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1611
        idx = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1612
        for wire, handle in wires:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1613
            points = wire.GetPoints(handle != 0)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1614
            if handle == 0:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1615
                result = wire.GetConnectedInfos(-1)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1616
            else:
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1617
                result = wire.GetConnectedInfos(0)
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1618
            if result != None:
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1619
                refLocalId, formalParameter = result
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1620
                connection.addConnection()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1621
                connection.setConnectionId(idx, refLocalId)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1622
                connection.setConnectionPoints(idx, points)
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1623
                if formalParameter != "":
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1624
                    connection.setConnectionParameter(idx, formalParameter)
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1625
                else:
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  1626
                    connection.setConnectionParameter(idx, None)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1627
                idx += 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1628
    
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1629
    def AddEditedElementBlock(self, tagname, id, blocktype, blockname = None):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1630
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1631
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1632
            block = plcopen.block()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1633
            block.setLocalId(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1634
            block.setTypeName(blocktype)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1635
            blocktype_infos = GetBlockType(blocktype)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1636
            if blocktype_infos["type"] != "function" and blockname is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1637
                block.setInstanceName(blockname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1638
                element.addPouVar(blocktype, blockname)    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1639
            element.addInstance("block", block)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1640
            self.RefreshPouUsingTree()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1641
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1642
    def SetEditedElementBlockInfos(self, tagname, id, infos):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1643
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1644
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1645
            block = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1646
            if "name" in infos or "type" in infos:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1647
                old_name = block.getInstanceName()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1648
                old_type = block.getTypeName()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1649
                new_name = infos.get("name", old_name)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1650
                new_type = infos.get("type", old_type)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1651
                self.GetEditedElement(tagname).changePouVar(old_type, old_name, new_type, new_name)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1652
            for param, value in infos.items():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1653
                if param == "name":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1654
                    block.setInstanceName(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1655
                elif param == "type":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1656
                    block.setTypeName(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1657
                elif param == "executionOrder" and block.getExecutionOrderId() != value:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1658
                    self.GetEditedElement(tagname).setElementExecutionOrder(block, value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1659
                elif param == "height":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1660
                    block.setHeight(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1661
                elif param == "width":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1662
                    block.setWidth(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1663
                elif param == "x":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1664
                    block.setX(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1665
                elif param == "y":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1666
                    block.setY(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1667
                elif param == "connectors":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1668
                    block.inputVariables.setVariable([])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1669
                    block.outputVariables.setVariable([])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1670
                    for connector in value["inputs"]:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1671
                        variable = plcopen.inputVariables_variable()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1672
                        variable.setFormalParameter(connector.GetName())
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1673
                        if connector.IsNegated():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1674
                            variable.setNegated(True)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1675
                        if connector.GetEdge() != "none":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1676
                            variable.setConnectorEdge(connector.GetEdge())
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1677
                        position = connector.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1678
                        variable.connectionPointIn.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1679
                        self.SetConnectionWires(variable.connectionPointIn, connector)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1680
                        block.inputVariables.appendVariable(variable)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1681
                    for connector in value["outputs"]:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1682
                        variable = plcopen.outputVariables_variable()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1683
                        variable.setFormalParameter(connector.GetName())
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1684
                        if connector.IsNegated():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1685
                            variable.setNegated(True)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1686
                        if connector.GetEdge() != "none":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1687
                            variable.setConnectorEdge(connector.GetEdge())
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1688
                        position = connector.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1689
                        variable.addConnectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1690
                        variable.connectionPointOut.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1691
                        block.outputVariables.appendVariable(variable)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1692
            self.RefreshPouUsingTree()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1693
        
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1694
    def AddEditedElementVariable(self, tagname, id, type):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1695
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1696
        if element is not None:            
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1697
            if type == INPUT:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1698
                name = "inVariable"
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1699
                variable = plcopen.inVariable()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1700
            elif type == OUTPUT:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1701
                name = "outVariable"
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1702
                variable = plcopen.outVariable()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1703
            elif type == INOUT:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1704
                name = "inOutVariable"
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1705
                variable = plcopen.inOutVariable()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1706
            variable.setLocalId(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1707
            element.addInstance(name, variable)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1708
        
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1709
    def SetEditedElementVariableInfos(self, tagname, id, infos):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1710
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1711
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1712
            variable = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1713
            for param, value in infos.items():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1714
                if param == "name":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1715
                    variable.setExpression(value)    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1716
                elif param == "executionOrder" and variable.getExecutionOrderId() != value:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1717
                    self.GetEditedElement(tagname).setElementExecutionOrder(variable, value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1718
                elif param == "height":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1719
                    variable.setHeight(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1720
                elif param == "width":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1721
                    variable.setWidth(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1722
                elif param == "x":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1723
                    variable.setX(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1724
                elif param == "y":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1725
                    variable.setY(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1726
                elif param == "connectors":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1727
                    if isinstance(variable, plcopen.inVariable):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1728
                        if value["output"].IsNegated():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1729
                            variable.setNegated(True)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1730
                        if value["output"].GetEdge() != "none":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1731
                            variable.setConnectorEdge(value["output"].GetEdge())
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1732
                        position = value["output"].GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1733
                        variable.addConnectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1734
                        variable.connectionPointOut.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1735
                    elif isinstance(variable, plcopen.outVariable):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1736
                        if value["input"].IsNegated():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1737
                            variable.setNegated(True)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1738
                        if value["input"].GetEdge() != "none":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1739
                            variable.setConnectorEdge(value["input"].GetEdge())
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1740
                        position = value["input"].GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1741
                        variable.addConnectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1742
                        variable.connectionPointIn.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1743
                        self.SetConnectionWires(variable.connectionPointIn, value["input"])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1744
                    elif isinstance(variable, plcopen.inOutVariable):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1745
                        if value["input"].IsNegated():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1746
                            variable.setNegatedIn(True)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1747
                        if value["input"].GetEdge() != "none":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1748
                            variable.setInputEdge(value["input"].GetEdge())
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1749
                        if value["output"].IsNegated():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1750
                            variable.setNegatedOut(True)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1751
                        if value["output"].GetEdge() != "none":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1752
                            variable.setOutputEdge(value["output"].GetEdge())
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1753
                        position = value["output"].GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1754
                        variable.addConnectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1755
                        variable.connectionPointOut.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1756
                        position = value["input"].GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1757
                        variable.addConnectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1758
                        variable.connectionPointIn.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1759
                        self.SetConnectionWires(variable.connectionPointIn, value["input"])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1760
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1761
    def AddEditedElementConnection(self, tagname, id, type):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1762
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1763
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1764
            if type == CONNECTOR:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1765
                name = "connector"
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1766
                connection = plcopen.connector()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1767
            elif type == CONTINUATION:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1768
                name = "continuation"
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1769
                connection = plcopen.continuation()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1770
            connection.setLocalId(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1771
            element.addInstance(name, connection)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1772
        
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1773
    def SetEditedElementConnectionInfos(self, tagname, id, infos):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1774
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1775
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1776
            connection = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1777
            for param, value in infos.items():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1778
                if param == "name":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1779
                    connection.setName(value)    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1780
                elif param == "height":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1781
                    connection.setHeight(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1782
                elif param == "width":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1783
                    connection.setWidth(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1784
                elif param == "x":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1785
                    connection.setX(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1786
                elif param == "y":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1787
                    connection.setY(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1788
                elif param == "connector":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1789
                    position = value.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1790
                    if isinstance(connection, plcopen.continuation):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1791
                        connection.addConnectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1792
                        connection.connectionPointOut.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1793
                    elif isinstance(connection, plcopen.connector):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1794
                        connection.addConnectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1795
                        connection.connectionPointIn.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1796
                        self.SetConnectionWires(connection.connectionPointIn, value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1797
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1798
    def AddEditedElementComment(self, tagname, id):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1799
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1800
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1801
            comment = plcopen.comment()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1802
            comment.setLocalId(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1803
            element.addInstance("comment", comment)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1804
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1805
    def SetEditedElementCommentInfos(self, tagname, id, infos):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1806
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1807
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1808
            comment = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1809
            for param, value in infos.items():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1810
                if param == "content":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1811
                    comment.setContentText(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1812
                elif param == "height":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1813
                    comment.setHeight(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1814
                elif param == "width":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1815
                    comment.setWidth(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1816
                elif param == "x":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1817
                    comment.setX(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1818
                elif param == "y":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1819
                    comment.setY(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1820
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1821
    def AddEditedElementPowerRail(self, tagname, id, type):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1822
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1823
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1824
            if type == LEFTRAIL:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1825
                name = "leftPowerRail"
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1826
                powerrail = plcopen.leftPowerRail()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1827
            elif type == RIGHTRAIL:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1828
                name = "rightPowerRail"
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1829
                powerrail = plcopen.rightPowerRail()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1830
            powerrail.setLocalId(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1831
            element.addInstance(name, powerrail)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1832
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1833
    def SetEditedElementPowerRailInfos(self, tagname, id, infos):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1834
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1835
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1836
            powerrail = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1837
            for param, value in infos.items():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1838
                if param == "height":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1839
                    powerrail.setHeight(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1840
                elif param == "width":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1841
                    powerrail.setWidth(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1842
                elif param == "x":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1843
                    powerrail.setX(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1844
                elif param == "y":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1845
                    powerrail.setY(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1846
                elif param == "connectors":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1847
                    if isinstance(powerrail, plcopen.leftPowerRail):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1848
                        powerrail.setConnectionPointOut([])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1849
                        for connector in value:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1850
                            position = connector.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1851
                            connection = plcopen.leftPowerRail_connectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1852
                            connection.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1853
                            powerrail.connectionPointOut.append(connection)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1854
                    elif isinstance(powerrail, plcopen.rightPowerRail):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1855
                        powerrail.setConnectionPointIn([])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1856
                        for connector in value:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1857
                            position = connector.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1858
                            connection = plcopen.connectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1859
                            connection.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1860
                            self.SetConnectionWires(connection, connector)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1861
                            powerrail.connectionPointIn.append(connection)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1862
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1863
    def AddEditedElementEditingContact(self, tagname, id):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1864
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1865
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1866
            contact = plcopen.contact()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1867
            contact.setLocalId(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1868
            element.addInstance("contact", contact)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1869
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1870
    def SetEditedElementContactInfos(self, tagname, id, infos):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1871
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1872
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1873
            contact = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1874
            for param, value in infos.items():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1875
                if param == "name":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1876
                    contact.setVariable(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1877
                elif param == "type":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1878
                    if value == CONTACT_NORMAL:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1879
                        contact.setNegated(False)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1880
                        contact.setContactEdge("none")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1881
                    elif value == CONTACT_REVERSE:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1882
                        contact.setNegated(True)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1883
                        contact.setContactEdge("none")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1884
                    elif value == CONTACT_RISING:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1885
                        contact.setNegated(False)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1886
                        contact.setContactEdge("rising")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1887
                    elif value == CONTACT_FALLING:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1888
                        contact.setNegated(False)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1889
                        contact.setContactEdge("falling")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1890
                elif param == "height":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1891
                    contact.setHeight(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1892
                elif param == "width":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1893
                    contact.setWidth(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1894
                elif param == "x":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1895
                    contact.setX(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1896
                elif param == "y":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1897
                    contact.setY(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1898
                elif param == "connectors":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1899
                    input_connector = value["input"]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1900
                    position = input_connector.GetRelPosition()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1901
                    contact.addConnectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1902
                    contact.connectionPointIn.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1903
                    self.SetConnectionWires(contact.connectionPointIn, input_connector)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1904
                    output_connector = value["output"]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1905
                    position = output_connector.GetRelPosition()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1906
                    contact.addConnectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1907
                    contact.connectionPointOut.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1908
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1909
    def AddEditedElementCoil(self, tagname, id):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1910
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1911
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1912
            coil = plcopen.coil()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1913
            coil.setLocalId(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1914
            element.addInstance("coil", coil)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1915
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1916
    def SetEditedElementCoilInfos(self, tagname, id, infos):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1917
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1918
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1919
            coil = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1920
            for param, value in infos.items():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1921
                if param == "name":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1922
                    coil.setVariable(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1923
                elif param == "type":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1924
                    if value == COIL_NORMAL:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1925
                        coil.setNegated(False)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1926
                        coil.setCoilStorage("none")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1927
                    elif value == COIL_REVERSE:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1928
                        coil.setNegated(True)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1929
                        coil.setCoilStorage("none")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1930
                    elif value == COIL_SET:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1931
                        coil.setNegated(False)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1932
                        coil.setCoilStorage("set")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1933
                    elif value == COIL_RESET:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1934
                        coil.setNegated(False)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1935
                        coil.setCoilStorage("reset")
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1936
                elif param == "height":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1937
                    coil.setHeight(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1938
                elif param == "width":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1939
                    coil.setWidth(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1940
                elif param == "x":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1941
                    coil.setX(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1942
                elif param == "y":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1943
                    coil.setY(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1944
                elif param == "connectors":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1945
                    input_connector = value["input"]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1946
                    position = input_connector.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1947
                    coil.addConnectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1948
                    coil.connectionPointIn.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1949
                    self.SetConnectionWires(coil.connectionPointIn, input_connector)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1950
                    output_connector = value["output"]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1951
                    position = output_connector.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1952
                    coil.addConnectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1953
                    coil.connectionPointOut.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1954
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1955
    def AddEditedElementStep(self, tagname, id):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1956
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1957
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1958
            step = plcopen.step()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1959
            step.setLocalId(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1960
            element.addInstance("step", step)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1961
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1962
    def SetEditedElementStepInfos(self, tagname, id, infos):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1963
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1964
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1965
            step = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1966
            for param, value in infos.items():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1967
                if param == "name":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1968
                    step.setName(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1969
                elif param == "initial":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1970
                    step.setInitialStep(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1971
                elif param == "height":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1972
                    step.setHeight(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1973
                elif param == "width":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1974
                    step.setWidth(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1975
                elif param == "x":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1976
                    step.setX(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1977
                elif param == "y":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1978
                    step.setY(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1979
                elif param == "connectors":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1980
                    input_connector = value["input"]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1981
                    if input_connector:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1982
                        position = input_connector.GetRelPosition()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1983
                        step.addConnectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1984
                        step.connectionPointIn.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1985
                        self.SetConnectionWires(step.connectionPointIn, input_connector)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1986
                    else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1987
                        step.deleteConnectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1988
                    output_connector = value["output"]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1989
                    if output_connector:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1990
                        position = output_connector.GetRelPosition()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1991
                        step.addConnectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1992
                        step.connectionPointOut.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1993
                    else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1994
                        step.deleteConnectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1995
                    action_connector = value["action"]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1996
                    if action_connector:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1997
                        position = action_connector.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1998
                        step.addConnectionPointOutAction()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1999
                        step.connectionPointOutAction.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2000
                    else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2001
                        step.deleteConnectionPointOutAction()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2002
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2003
    def AddEditedElementTransition(self, tagname, id):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2004
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2005
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2006
            transition = plcopen.transition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2007
            transition.setLocalId(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2008
            element.addInstance("transition", transition)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2009
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2010
    def SetEditedElementTransitionInfos(self, tagname, id, infos):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2011
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2012
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2013
            transition = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2014
            for param, value in infos.items():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2015
                if param == "type" and value != "connection":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2016
                    transition.setConditionContent(value, infos["condition"])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2017
                elif param == "height":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2018
                    transition.setHeight(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2019
                elif param == "width":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2020
                    transition.setWidth(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2021
                elif param == "x":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2022
                    transition.setX(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2023
                elif param == "y":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2024
                    transition.setY(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2025
                elif param == "priority":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2026
                    if value != 0:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2027
                        transition.setPriority(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2028
                    else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2029
                        transition.setPriority(None)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2030
                elif param == "connectors":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2031
                    input_connector = value["input"]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2032
                    position = input_connector.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2033
                    transition.addConnectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2034
                    transition.connectionPointIn.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2035
                    self.SetConnectionWires(transition.connectionPointIn, input_connector)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2036
                    output_connector = value["output"]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2037
                    position = output_connector.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2038
                    transition.addConnectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2039
                    transition.connectionPointOut.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2040
                    if infos.get("type", None) == "connection":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2041
                        transition.setConditionContent("connection", None)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2042
                        connection_connector = value["connection"]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2043
                        self.SetConnectionWires(transition, connection_connector)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2044
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2045
    def AddEditedElementDivergence(self, tagname, id, type):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2046
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2047
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2048
            if type == SELECTION_DIVERGENCE:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2049
                name = "selectionDivergence"
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2050
                divergence = plcopen.selectionDivergence()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2051
            elif type == SELECTION_CONVERGENCE:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2052
                name = "selectionConvergence"
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2053
                divergence = plcopen.selectionConvergence()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2054
            elif type == SIMULTANEOUS_DIVERGENCE:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2055
                name = "simultaneousDivergence"
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2056
                divergence = plcopen.simultaneousDivergence()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2057
            elif type == SIMULTANEOUS_CONVERGENCE:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2058
                name = "simultaneousConvergence"
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2059
                divergence = plcopen.simultaneousConvergence()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2060
            divergence.setLocalId(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2061
            element.addInstance(name, divergence)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2062
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2063
    def SetEditedElementDivergenceInfos(self, tagname, id, infos):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2064
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2065
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2066
            divergence = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2067
            for param, value in infos.items():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2068
                if param == "height":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2069
                    divergence.setHeight(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2070
                elif param == "width":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2071
                    divergence.setWidth(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2072
                elif param == "x":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2073
                    divergence.setX(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2074
                elif param == "y":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2075
                    divergence.setY(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2076
                elif param == "connectors":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2077
                    input_connectors = value["inputs"]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2078
                    if isinstance(divergence, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2079
                        position = input_connectors[0].GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2080
                        divergence.addConnectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2081
                        divergence.connectionPointIn.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2082
                        self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2083
                    else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2084
                        divergence.setConnectionPointIn([])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2085
                        for input_connector in input_connectors:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2086
                            position = input_connector.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2087
                            if isinstance(divergence, plcopen.selectionConvergence):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2088
                                connection = plcopen.selectionConvergence_connectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2089
                            else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2090
                                connection = plcopen.connectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2091
                            connection.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2092
                            self.SetConnectionWires(connection, input_connector)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2093
                            divergence.appendConnectionPointIn(connection)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2094
                    output_connectors = value["outputs"]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2095
                    if isinstance(divergence, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2096
                        position = output_connectors[0].GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2097
                        divergence.addConnectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2098
                        divergence.connectionPointOut.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2099
                    else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2100
                        divergence.setConnectionPointOut([])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2101
                        for output_connector in output_connectors:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2102
                            position = output_connector.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2103
                            if isinstance(divergence, plcopen.selectionDivergence):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2104
                                connection = plcopen.selectionDivergence_connectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2105
                            else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2106
                                connection = plcopen.simultaneousDivergence_connectionPointOut()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2107
                            connection.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2108
                            divergence.appendConnectionPointOut(connection)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2109
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2110
    def AddEditedElementJump(self, tagname, id):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2111
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2112
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2113
            jump = plcopen.jumpStep()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2114
            jump.setLocalId(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2115
            element.addInstance("jumpStep", jump)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2116
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2117
    def SetEditedElementJumpInfos(self, tagname, id, infos):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2118
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2119
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2120
            jump = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2121
            for param, value in infos.items():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2122
                if param == "target":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2123
                    jump.setTargetName(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2124
                elif param == "height":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2125
                    jump.setHeight(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2126
                elif param == "width":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2127
                    jump.setWidth(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2128
                elif param == "x":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2129
                    jump.setX(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2130
                elif param == "y":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2131
                    jump.setY(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2132
                elif param == "connector":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2133
                    position = value.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2134
                    jump.addConnectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2135
                    jump.connectionPointIn.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2136
                    self.SetConnectionWires(jump.connectionPointIn, value)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2137
 
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2138
    def AddEditedElementActionBlock(self, tagname, id):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2139
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2140
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2141
            actionBlock = plcopen.actionBlock()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2142
            actionBlock.setLocalId(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2143
            element.addInstance("actionBlock", actionBlock)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2144
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2145
    def SetEditedElementActionBlockInfos(self, tagname, id, infos):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2146
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2147
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2148
            actionBlock = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2149
            for param, value in infos.items():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2150
                if param == "actions":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2151
                    actionBlock.setActions(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2152
                elif param == "height":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2153
                    actionBlock.setHeight(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2154
                elif param == "width":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2155
                    actionBlock.setWidth(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2156
                elif param == "x":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2157
                    actionBlock.setX(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2158
                elif param == "y":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2159
                    actionBlock.setY(value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2160
                elif param == "connector":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2161
                    position = value.GetRelPosition()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2162
                    actionBlock.addConnectionPointIn()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2163
                    actionBlock.connectionPointIn.setRelPosition(position.x, position.y)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2164
                    self.SetConnectionWires(actionBlock.connectionPointIn, value)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2165
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2166
    def RemoveEditedElementInstance(self, tagname, id):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2167
        element = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2168
        if element is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2169
            instance = element.getInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2170
            if isinstance(instance, plcopen.block):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2171
                blocktype = instance.getTypeName()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2172
                element.removePouVar(blocktype, instance.getInstanceName())    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2173
            element.removeInstance(id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2174
            self.RefreshPouUsingTree()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2175
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2176
    def GetEditedResourceVariables(self, tagname):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2177
        varlist = []
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2178
        words = tagname.split("::")
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2179
        for var in self.GetConfigurationGlobalVars(words[1]):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2180
            if var["Type"] == "BOOL":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2181
                varlist.append(var["Name"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2182
        for var in self.GetConfigurationResourceGlobalVars(words[1], words[2]):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2183
            if var["Type"] == "BOOL":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2184
                varlist.append(var["Name"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2185
        return varlist
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2186
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2187
    def SetEditedResourceInfos(self, tasks, instances):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2188
        resource = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2189
        if resource is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2190
            resource.setTask([])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2191
            resource.setPouInstance([])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2192
            task_list = {}
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2193
            for task in tasks:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2194
                new_task = plcopen.resource_task()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2195
                new_task.setName(task["Name"])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2196
                if task["Single"] != "":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2197
                    new_task.setSingle(task["Single"])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2198
                result = duration_model.match(task["Interval"]).groups()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2199
                if reduce(lambda x, y: x or y != None, result):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2200
                    values = []
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2201
                    for value in result[:-1]:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2202
                        if value != None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2203
                            values.append(int(value))
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2204
                        else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2205
                            values.append(0)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2206
                    values.append(int(float(result[-1]) * 1000))
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2207
                    new_task.setInterval(time(*values))
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2208
                new_task.priority.setValue(int(task["Priority"]))
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2209
                if task["Name"] != "":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2210
                    task_list[task["Name"]] = new_task
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2211
                resource.appendTask(new_task)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2212
            for instance in instances:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2213
                new_instance = plcopen.pouInstance()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2214
                new_instance.setName(instance["Name"])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2215
                new_instance.setType(instance["Type"])
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2216
                if instance["Task"] != "":
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2217
                    task_list[instance["Task"]].appendPouInstance(new_instance)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2218
                else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2219
                    resource.appendPouInstance(new_instance)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2220
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2221
    def GetEditedResourceInfos(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2222
        resource = self.GetEditedElement(tagname)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2223
        if resource is not None:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2224
            tasks = resource.getTask()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2225
            instances = resource.getPouInstance()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2226
            tasks_data = []
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2227
            instances_data = []
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2228
            for task in tasks:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2229
                new_task = {}
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2230
                new_task["Name"] = task.getName()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2231
                single = task.getSingle()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2232
                if single:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2233
                    new_task["Single"] = single
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2234
                else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2235
                    new_task["Single"] = ""
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2236
                interval = task.getInterval()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2237
                if interval:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2238
                    text = ""
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2239
                    if interval.hour != 0:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2240
                        text += "%dh"%interval.hour
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2241
                    if interval.minute != 0:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2242
                        text += "%dm"%interval.minute
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2243
                    if interval.second != 0:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2244
                        text += "%ds"%interval.second
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2245
                    if interval.microsecond != 0:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2246
                        if interval.microsecond % 1000 != 0:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2247
                            text += "%.3fms"%(float(interval.microsecond) / 1000)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2248
                        else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2249
                            text += "%dms"%(interval.microsecond / 1000)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2250
                    new_task["Interval"] = text
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2251
                else:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2252
                    new_task["Interval"] = ""
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2253
                new_task["Priority"] = str(task.priority.getValue())
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2254
                tasks_data.append(new_task)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2255
                for instance in task.getPouInstance():
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2256
                    new_instance = {}
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2257
                    new_instance["Name"] = instance.getName()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2258
                    new_instance["Type"] = instance.getType()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2259
                    new_instance["Task"] = task.getName()
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2260
                    instances_data.append(new_instance)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2261
            for instance in instances:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2262
                new_instance = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2263
                new_instance["Name"] = instance.getName()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2264
                new_instance["Type"] = instance.getType()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2265
                new_instance["Task"] = ""
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2266
                instances_data.append(new_instance)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2267
            return tasks_data, instances_data
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2268
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2269
    def OpenXMLFile(self, filepath):
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2270
        if self.VerifyXML:
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2271
            if sys:
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2272
                sys.stdout = HolePseudoFile()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  2273
            result = pyxsval.parseAndValidate(filepath, os.path.join(ScriptDirectory, "plcopen", "TC6_XML_V10_B.xsd"))
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2274
            if sys:
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2275
                sys.stdout = sys.__stdout__
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2276
            tree = result.getTree()
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2277
        else:
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2278
            xmlfile = open(filepath, 'r')
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2279
            tree = minidom.parse(xmlfile)
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2280
            xmlfile.close()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2281
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2282
        self.Project = plcopen.project()
116
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 108
diff changeset
  2283
        for child in tree.childNodes:
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 108
diff changeset
  2284
            if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "project":
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 108
diff changeset
  2285
                self.Project.loadXMLTree(child)
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 108
diff changeset
  2286
                self.SetFilePath(filepath)
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 108
diff changeset
  2287
                self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), True)
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 108
diff changeset
  2288
                self.Buffering = False
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 108
diff changeset
  2289
                self.ElementsOpened = []
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 108
diff changeset
  2290
                self.CurrentElementEditing = None
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  2291
                self.RefreshDataTypeUsingTree()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  2292
                self.RefreshDataTypes()
116
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 108
diff changeset
  2293
                self.RefreshPouUsingTree()
58b9b84e385f Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents: 108
diff changeset
  2294
                self.RefreshBlockTypes()
117
bbe0697cf1ea Bug on Open Project fixed
lbessard
parents: 116
diff changeset
  2295
                return None
bbe0697cf1ea Bug on Open Project fixed
lbessard
parents: 116
diff changeset
  2296
        return "No PLC project found"
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2297
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2298
    def SaveXMLFile(self, filepath = None):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2299
        if not filepath and self.FilePath == "":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2300
            return False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2301
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2302
            text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2303
            extras = {"xmlns" : "http://www.plcopen.org/xml/tc6.xsd",
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2304
                      "xmlns:xhtml" : "http://www.w3.org/1999/xhtml",
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2305
                      "xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance",
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2306
                      "xsi:schemaLocation" : "http://www.plcopen.org/xml/tc6.xsd http://www.plcopen.org/xml/tc6.xsd"}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2307
            text += self.Project.generateXMLText("project", 0, extras)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  2308
            
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2309
            if self.VerifyXML:
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2310
                if sys:
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2311
                    sys.stdout = HolePseudoFile()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 121
diff changeset
  2312
                pyxsval.parseAndValidateString(text, open(os.path.join(ScriptDirectory, "plcopen", "TC6_XML_V10_B.xsd"),"r").read())
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2313
                if sys:
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2314
                    sys.stdout = sys.__stdout__
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2315
            
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2316
            if filepath:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2317
                xmlfile = open(filepath,"w")
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2318
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2319
                xmlfile = open(self.FilePath,"w")
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2320
            xmlfile.write(text)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2321
            xmlfile.close()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
  2322
            self.ProjectBuffer.CurrentSaved()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2323
            if filepath:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2324
                self.SetFilePath(filepath)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2325
            return True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2326
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2327
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2328
#                      Current Buffering Management Functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2329
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2330
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2331
    """
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2332
    Return a copy of the project
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2333
    """
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2334
    def Copy(self, model):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2335
        return cPickle.loads(cPickle.dumps(model))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2336
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2337
    def BufferProject(self):
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
  2338
        self.ProjectBuffer.Buffering(self.Copy(self.Project))
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
  2339
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
  2340
    def StartBuffering(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
  2341
        self.ProjectBuffer.Buffering(self.Project)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
  2342
        self.Buffering = True
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
  2343
        
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
  2344
    def EndBuffering(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
  2345
        if self.Buffering:
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
  2346
            self.Project = self.Copy(self.Project)
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 53
diff changeset
  2347
            self.Buffering = False
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2348
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2349
    def ProjectIsSaved(self):
58
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
  2350
        if self.ProjectBuffer:
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
  2351
            return self.ProjectBuffer.IsCurrentSaved()
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
  2352
        else:
62
1908c45f21ef Adding sizer on some Dialogs for making them resizable
lbessard
parents: 58
diff changeset
  2353
            return True
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2354
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2355
    def LoadPrevious(self):
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2356
        self.Project = self.Copy(self.ProjectBuffer.Previous())
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2357
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2358
    def LoadNext(self):
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2359
        self.Project = self.Copy(self.ProjectBuffer.Next())
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2360
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2361
    def GetBufferState(self):
27
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2362
        first = self.ProjectBuffer.IsFirst()
dae55dd9ee14 Current developping version
lbessard
parents: 24
diff changeset
  2363
        last = self.ProjectBuffer.IsLast()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2364
        return not first, not last