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