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