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