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