graphics/FBD_Objects.py
author lbessard
Fri, 19 Oct 2007 17:08:46 +0200
changeset 111 0ec40799ba11
parent 103 26c10e28ee3a
child 112 317148fc1225
permissions -rw-r--r--
Bug on divergence creation with null size fixed
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     3
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     5
#based on the plcopen standard. 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     6
#
58
39cd981ff242 Changing file headers
lbessard
parents: 42
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: 3
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: 42
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: 3
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
import wx
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    26
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    27
from GraphicCommons import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    28
from plcopen.structures import *
99
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
    29
from plcopen.structures import IsOfType
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    30
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    31
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    32
#                         Function Block Diagram Block
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    33
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    34
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    35
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    36
Class that implements the graphic representation of a function block
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    37
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    38
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    39
class FBD_Block(Graphic_Element):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    40
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    41
    # Create a new block
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
    42
    def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    43
        Graphic_Element.__init__(self, parent)
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
    44
        self.Type = None
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
    45
        self.Extension = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    46
        self.Name = name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    47
        self.Id = id
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    48
        self.Inputs = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    49
        self.Outputs = []
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
    50
        self.RefreshNameSize()
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
    51
        self.Colour = wx.BLACK
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
    52
        self.Pen = wx.BLACK_PEN
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
    53
        self.SetType(type, extension, inputs, connectors)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    54
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    55
    # Destructor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    56
    def __del__(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    57
        self.Inputs = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    58
        self.Outputs = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    59
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    60
    # Delete this block by calling the appropriate method
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    61
    def Delete(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    62
        self.Parent.DeleteBlock(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    63
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    64
    # Unconnect all inputs and outputs
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    65
    def Clean(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    66
        for input in self.Inputs:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    67
            input.UnConnect(delete = True)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    68
        for output in self.Outputs:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    69
            output.UnConnect(delete = True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    70
    
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
    71
    # Refresh the size of text for name
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
    72
    def RefreshNameSize(self):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
    73
        dc = wx.ClientDC(self.Parent)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
    74
        self.NameSize = dc.GetTextExtent(self.Name)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
    75
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    76
    # Refresh the block bounding box
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    77
    def RefreshBoundingBox(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    78
        # Calculate the size of the name outside the block
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
    79
        text_width, text_height = self.NameSize
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    80
        # Calculate the bounding box size
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    81
        bbx_x = self.Pos.x - max(min(1, len(self.Inputs)) * CONNECTOR_SIZE, (text_width - self.Size[0]) / 2)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    82
        bbx_width = self.Size[0] + 1 + (min(1, len(self.Inputs)) + min(1, len(self.Outputs))) * CONNECTOR_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    83
        if self.Name != "":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    84
            bbx_y = self.Pos.y - (text_height + 2)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    85
            bbx_height = self.Size[1] + (text_height + 2)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    86
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    87
            bbx_y = self.Pos.y
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    88
            bbx_height = self.Size[1]
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
    89
        self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    90
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    91
    # Refresh the positions of the block connectors
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    92
    def RefreshConnectors(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    93
        # Calculate the size for the connector lines
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    94
        lines = max(len(self.Inputs), len(self.Outputs))
103
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
    95
        if lines > 0:
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
    96
            linesize = max((self.Size[1] - BLOCK_LINE_SIZE) / lines, BLOCK_LINE_SIZE)
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
    97
            # Update inputs positions
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
    98
            position = BLOCK_LINE_SIZE + linesize / 2
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
    99
            for input in self.Inputs:
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
   100
                input.SetPosition(wx.Point(0, position))
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
   101
                position += linesize
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
   102
            # Update outputs positions
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
   103
            position = BLOCK_LINE_SIZE + linesize / 2
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
   104
            for output in self.Outputs:
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
   105
                output.SetPosition(wx.Point(self.Size[0], position))
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
   106
                position += linesize
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   107
        self.RefreshConnected()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   108
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   109
    # Refresh the positions of wires connected to inputs and outputs
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   110
    def RefreshConnected(self, exclude = []):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   111
        for input in self.Inputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   112
            input.MoveConnected(exclude)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   113
        for output in self.Outputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   114
            output.MoveConnected(exclude)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   115
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   116
    # Returns the block connector that starts with the point given if it exists 
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   117
    def GetConnector(self, position, name = None):
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   118
        # if a name is given
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   119
        if name:
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   120
            # Test each input and output connector
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   121
            for input in self.Inputs:
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   122
                if name == input.GetName():
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   123
                    return input
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   124
            for output in self.Outputs:
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   125
                if name == output.GetName():
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   126
                    return output
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   127
        # Test each input connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   128
        for input in self.Inputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   129
            input_pos = input.GetRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   130
            if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   131
                return input
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   132
        # Test each output connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   133
        for output in self.Outputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   134
            output_pos = output.GetRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   135
            if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   136
                return output
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   137
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   138
    
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   139
    def GetInputTypes(self):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   140
        return tuple([input.GetType() for input in self.Inputs])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   141
    
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   142
    def SetOutputValues(self, values):
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   143
        for output in self.Outputs:
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   144
            output.SetValue(values.get(ouput.getName(), None))
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   145
    
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   146
    def GetConnectionResultType(self, connector, connectortype):
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   147
        resulttype = connectortype
99
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   148
        for input in self.Inputs:
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   149
            name = input.GetName()
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   150
            if input != connector and (name.startswith("IN") or name in ["MN", "MX"]):
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   151
                inputtype = input.GetConnectedType()
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   152
                if resulttype is None or inputtype is not None and IsOfType(inputtype, resulttype):
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   153
                    resulttype = inputtype
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   154
        for output in self.Outputs:
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   155
            name = output.GetName()
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   156
            if output != connector and name == "OUT":
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   157
                outputtype = output.GetConnectedType()
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   158
                if resulttype is None or outputtype is not None and IsOfType(outputtype, resulttype):
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   159
                    resulttype = outputtype
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   160
        return resulttype
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   161
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   162
    # Returns all the block connectors 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   163
    def GetConnectors(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   164
        return {"inputs" : self.Inputs, "outputs" : self.Outputs}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   165
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   166
    # Test if point given is on one of the block connectors
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   167
    def TestConnector(self, pt, exclude = True):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   168
        # Test each input connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   169
        for input in self.Inputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   170
            if input.TestPoint(pt, exclude):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   171
                return input
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   172
        # Test each output connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   173
        for output in self.Outputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   174
            if output.TestPoint(pt, exclude):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   175
                return output
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   176
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   177
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   178
    # Changes the block type
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   179
    def SetType(self, type, extension, inputs = None, connectors = {}):
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   180
        if type != self.Type or self.Extension != extension: 
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   181
            if type != self.Type:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   182
                self.Type = type
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   183
                dc = wx.ClientDC(self.Parent)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   184
                self.TypeSize = dc.GetTextExtent(self.Type)
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   185
            self.Extension = extension
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   186
            # Find the block definition from type given and create the corresponding
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   187
            # inputs and outputs
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   188
            blocktype = GetBlockType(type, inputs)
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   189
            if blocktype:
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   190
                self.Colour = wx.BLACK
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   191
                inputs = [input for input in blocktype["inputs"]]
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   192
                outputs = [output for output in blocktype["outputs"]]
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   193
                if blocktype["extensible"]:
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   194
                    start = int(inputs[-1][0].replace("IN", ""))
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   195
                    for i in xrange(self.Extension - len(blocktype["inputs"])):
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   196
                        start += 1
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   197
                        inputs.append(("IN%d"%start, inputs[-1][1], inputs[-1][2]))
16
20dcc0dce64b Bug on block properties dialog corrected
lbessard
parents: 5
diff changeset
   198
            else:
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   199
                self.Colour = wx.RED
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   200
                if "inputs" in connectors:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   201
                    inputs = connectors["inputs"]
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   202
                else:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   203
                    inputs = []
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   204
                if "outputs" in connectors:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   205
                    outputs = connectors["outputs"]
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   206
                else:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   207
                    outputs = []
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   208
            self.Pen = wx.Pen(self.Colour)
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   209
            self.Clean()
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   210
            # Extract the inputs properties and create the corresponding connector
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   211
            self.Inputs = []
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   212
            for input_name, input_type, input_modifier in inputs:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   213
                connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone = True)
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   214
                if input_modifier == "negated":
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   215
                    connector.SetNegated(True)
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   216
                elif input_modifier != "none":
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   217
                    connector.SetEdge(input_modifier)
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   218
                self.Inputs.append(connector)
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   219
            # Extract the outputs properties and create the corresponding connector
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   220
            self.Outputs = []
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   221
            for output_name, output_type, output_modifier in outputs:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   222
                connector = Connector(self, output_name, output_type, wx.Point(0, 0), EAST)
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   223
                if output_modifier == "negated":
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   224
                    connector.SetNegated(True)
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   225
                elif output_modifier != "none":
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   226
                    connector.SetEdge(output_modifier)
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   227
                self.Outputs.append(connector)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   228
            self.RefreshMinSize()
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   229
            self.RefreshConnectors()
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   230
            self.RefreshBoundingBox()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   231
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   232
    # Returns the block type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   233
    def GetType(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   234
        return self.Type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   235
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   236
    # Changes the block name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   237
    def SetName(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   238
        self.Name = name
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   239
        self.RefreshNameSize()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   240
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   241
    # Returs the block name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   242
    def GetName(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   243
        return self.Name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   244
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   245
    # Changes the extension name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   246
    def SetExtension(self, extension):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   247
        self.Extension = extension
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   248
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   249
    # Returs the extension name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   250
    def GetExtension(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   251
        return self.Extension
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   252
    
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   253
    # Refresh the block minimum size
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   254
    def RefreshMinSize(self):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   255
        # Calculate the inputs maximum width
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   256
        max_input = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   257
        for input in self.Inputs:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   258
            w, h = input.GetNameSize()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   259
            max_input = max(max_input, w)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   260
        # Calculate the outputs maximum width
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   261
        max_output = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   262
        for output in self.Outputs:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   263
            w, h = output.GetNameSize()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   264
            max_output = max(max_output, w)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   265
        width = max(self.TypeSize[0] + 10, max_input + max_output + 15)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   266
        height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   267
        self.MinSize = width, height
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   268
    
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   269
    # Returns the block minimum size
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   270
    def GetMinSize(self):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   271
        return self.MinSize
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   272
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   273
    # Changes the negated property of the connector handled
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   274
    def SetConnectorNegated(self, negated):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   275
        handle_type, handle = self.Handle
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   276
        if handle_type == HANDLE_CONNECTOR:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   277
            handle.SetNegated(negated)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   278
            self.RefreshModel(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   279
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   280
    # Changes the edge property of the connector handled
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   281
    def SetConnectorEdge(self, edge):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   282
        handle_type, handle = self.Handle
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   283
        if handle_type == HANDLE_CONNECTOR:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   284
            handle.SetEdge(edge)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   285
            self.RefreshModel(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   286
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   287
    # Method called when a LeftDClick event have been generated
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   288
    def OnLeftDClick(self, event, dc, scaling):
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   289
        # Edit the block properties
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   290
        self.Parent.EditBlockContent(self)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   291
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   292
    # Method called when a RightUp event have been generated
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   293
    def OnRightUp(self, event, dc, scaling):
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   294
        pos = GetScaledEventPosition(event, dc, scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   295
        # Popup the menu with special items for a block and a connector if one is handled
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   296
        connector = self.TestConnector(pos, False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   297
        if connector:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   298
            self.Handle = (HANDLE_CONNECTOR, connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   299
            self.Parent.PopupBlockMenu(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   300
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   301
            self.Parent.PopupBlockMenu()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   302
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   303
    # Refreshes the block model
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   304
    def RefreshModel(self, move=True):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   305
        self.Parent.RefreshBlockModel(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   306
        # If block has moved, refresh the model of wires connected to outputs
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   307
        if move:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   308
            for output in self.Outputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   309
                output.RefreshWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   310
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   311
    # Draws block
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   312
    def Draw(self, dc):
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   313
        dc.SetPen(self.Pen)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   314
        dc.SetBrush(wx.WHITE_BRUSH)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   315
        dc.SetTextForeground(self.Colour)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   316
        # Draw a rectangle with the block size
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   317
        dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   318
        # Draw block name and block type
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   319
        dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2,
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   320
                self.Pos.y - (self.NameSize[1] + 2))
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   321
        dc.DrawText(self.Type, self.Pos.x + (self.Size[0] - self.TypeSize[0]) / 2,
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   322
                self.Pos.y + 5)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   323
        # Draw inputs and outputs connectors
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   324
        for input in self.Inputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   325
            input.Draw(dc)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   326
        for output in self.Outputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   327
            output.Draw(dc)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   328
        Graphic_Element.Draw(self, dc)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   329
        dc.SetTextForeground(wx.BLACK)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   330
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   331
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   332
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   333
#                        Function Block Diagram Variable
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   334
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   335
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   336
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   337
Class that implements the graphic representation of a variable
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   338
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   339
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   340
class FBD_Variable(Graphic_Element):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   341
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   342
    # Create a new variable
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   343
    def __init__(self, parent, type, name, value_type, id = None):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   344
        Graphic_Element.__init__(self, parent)
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   345
        self.Type = None
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   346
        self.ValueType = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   347
        self.Name = name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   348
        self.Id = id
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   349
        self.Input = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   350
        self.Output = None
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   351
        self.RefreshNameSize()
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   352
        self.SetType(type, value_type)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   353
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   354
    # Destructor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   355
    def __del__(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   356
        self.Input = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   357
        self.Output = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   358
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   359
    # Unconnect connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   360
    def Clean(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   361
        if self.Input:
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   362
            self.Input.UnConnect(delete = True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   363
        if self.Output:
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   364
            self.Output.UnConnect(delete = True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   365
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   366
    # Delete this variable by calling the appropriate method
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   367
    def Delete(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   368
        self.Parent.DeleteVariable(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   369
    
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   370
    # Refresh the size of text for name
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   371
    def RefreshNameSize(self):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   372
        dc = wx.ClientDC(self.Parent)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   373
        self.NameSize = dc.GetTextExtent(self.Name)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   374
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   375
    # Refresh the variable bounding box
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   376
    def RefreshBoundingBox(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   377
        if self.Type in (OUTPUT, INOUT):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   378
            bbx_x = self.Pos.x - CONNECTOR_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   379
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   380
            bbx_x = self.Pos.x
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   381
        if self.Type == INOUT:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   382
            bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   383
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   384
            bbx_width = self.Size[0] + CONNECTOR_SIZE
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   385
        self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, self.Size[1] + 1)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   386
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   387
    # Refresh the position of the variable connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   388
    def RefreshConnectors(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   389
        if self.Input:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   390
            self.Input.SetPosition(wx.Point(0, self.Size[1] / 2))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   391
        if self.Output:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   392
            self.Output.SetPosition(wx.Point(self.Size[0], self.Size[1] / 2))
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   393
        self.RefreshConnected()
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
    # Refresh the position of wires connected to connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   396
    def RefreshConnected(self, exclude = []):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   397
        if self.Input:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   398
            self.Input.MoveConnected(exclude)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   399
        if self.Output:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   400
            self.Output.MoveConnected(exclude)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   401
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   402
    # Test if point given is on the variable connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   403
    def TestConnector(self, pt, exclude=True):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   404
        if self.Input and self.Input.TestPoint(pt, exclude):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   405
            return self.Input
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   406
        if self.Output and self.Output.TestPoint(pt, exclude):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   407
            return self.Output
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   408
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   409
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   410
    # Returns the block connector that starts with the point given if it exists 
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   411
    def GetConnector(self, position, name = None):
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   412
        # if a name is given
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   413
        if name:
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   414
            # Test input and output connector if they exists
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   415
            if self.Input and name == self.Input.GetName():
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   416
                return self.Input
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   417
            if self.Output and name == self.Output.GetName():
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   418
                return self.Output
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   419
        # Test input connector if it exists
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   420
        if self.Input:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   421
            input_pos = self.Input.GetRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   422
            if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   423
                return self.Input
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   424
        # Test output connector if it exists
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   425
        if self.Output:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   426
            output_pos = self.Output.GetRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   427
            if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   428
                return self.Output
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   429
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   430
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   431
    # Returns all the block connectors 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   432
    def GetConnectors(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   433
        return {"input" : self.Input, "output" : self.Output}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   434
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   435
    # Changes the negated property of the variable connector if handled
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   436
    def SetConnectorNegated(self, negated):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   437
        handle_type, handle = self.Handle
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   438
        if handle_type == HANDLE_CONNECTOR:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   439
            handle.SetNegated(negated)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   440
            self.RefreshModel(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   441
    
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   442
    # Changes the variable type
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   443
    def SetType(self, type, value_type):
32
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   444
        if type != self.Type:
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   445
            self.Type = type
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   446
            self.Clean()
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   447
            self.Input = None
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   448
            self.Output = None
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   449
            # Create an input or output connector according to variable type
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   450
            if self.Type != INPUT:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   451
                self.Input = Connector(self, "", value_type, wx.Point(0, 0), WEST, onlyone = True)
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   452
            if self.Type != OUTPUT:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   453
                self.Output = Connector(self, "", value_type, wx.Point(0, 0), EAST)
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   454
            self.RefreshConnectors()
32
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   455
        elif value_type != self.ValueType:
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   456
            if self.Input:
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   457
                self.Input.SetType(value_type)
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   458
            if self.Output:
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   459
                self.Output.SetType(value_type)            
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   460
        self.RefreshConnectors()
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   461
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   462
    # Returns the variable type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   463
    def GetType(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   464
        return self.Type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   465
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   466
    # Changes the variable name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   467
    def SetName(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   468
        self.Name = name
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   469
        self.RefreshNameSize()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   470
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   471
    # Returns the variable name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   472
    def GetName(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   473
        return self.Name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   474
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   475
    # Returns the variable minimum size
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   476
    def GetMinSize(self):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   477
        return self.NameSize[0] + 10, self.NameSize[1] + 10
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   478
    
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   479
    # Method called when a LeftDClick event have been generated
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   480
    def OnLeftDClick(self, event, dc, scaling):
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   481
        # Edit the variable properties
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   482
        self.Parent.EditVariableContent(self)
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   483
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   484
    # Method called when a RightUp event have been generated
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   485
    def OnRightUp(self, event, dc, scaling):
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   486
        self.Parent.PopupDefaultMenu()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   487
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   488
    # Refreshes the variable model
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   489
    def RefreshModel(self, move=True):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   490
        self.Parent.RefreshVariableModel(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   491
        # If variable has moved and variable is not of type OUTPUT, refresh the model
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   492
        # of wires connected to output connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   493
        if move and self.Type != OUTPUT:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   494
            if self.Output:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   495
                self.Output.RefreshWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   496
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   497
    # Draws variable
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   498
    def Draw(self, dc):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   499
        dc.SetPen(wx.BLACK_PEN)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   500
        dc.SetBrush(wx.WHITE_BRUSH)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   501
        # Draw a rectangle with the variable size
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   502
        dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   503
        # Draw variable name
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   504
        dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2,
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   505
                self.Pos.y + (self.Size[1] - self.NameSize[1]) / 2)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   506
        # Draw connectors
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   507
        if self.Input:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   508
            self.Input.Draw(dc)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   509
        if self.Output:    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   510
            self.Output.Draw(dc)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   511
        Graphic_Element.Draw(self, dc)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   512
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   513
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   514
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   515
#                        Function Block Diagram Connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   516
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   517
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   518
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   519
Class that implements the graphic representation of a connection
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   520
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   521
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   522
class FBD_Connector(Graphic_Element):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   523
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   524
    # Create a new connection
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   525
    def __init__(self, parent, type, name, id = None):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   526
        Graphic_Element.__init__(self, parent)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   527
        self.Type = type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   528
        self.Name = name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   529
        self.Id = id
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   530
        self.Pos = wx.Point(0, 0)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   531
        self.Size = wx.Size(0, 0)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   532
        # Create an input or output connector according to connection type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   533
        if self.Type == CONNECTOR:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   534
            self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   535
        else:
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   536
            self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   537
        self.RefreshConnectors()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   538
        self.RefreshNameSize()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   539
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   540
    # Destructor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   541
    def __del__(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   542
        self.Connector = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   543
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   544
    # Unconnect connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   545
    def Clean(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   546
        if self.Connector:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   547
            self.Connector.UnConnect(delete = True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   548
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   549
    # Delete this connection by calling the appropriate method
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   550
    def Delete(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   551
        self.Parent.DeleteConnection(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   552
    
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   553
    # Refresh the size of text for name
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   554
    def RefreshNameSize(self):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   555
        dc = wx.ClientDC(self.Parent)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   556
        self.NameSize = dc.GetTextExtent(self.Name)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   557
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   558
    # Refresh the connection bounding box
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   559
    def RefreshBoundingBox(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   560
        if self.Type == CONNECTOR:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   561
            bbx_x = self.Pos.x - CONNECTOR_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   562
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   563
            bbx_x = self.Pos.x
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   564
        bbx_width = self.Size[0] + CONNECTOR_SIZE
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   565
        self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   566
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   567
    # Refresh the position of the connection connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   568
    def RefreshConnectors(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   569
        if self.Type == CONNECTOR:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   570
            self.Connector.SetPosition(wx.Point(0, self.Size[1] / 2))
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   571
        else:
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   572
            self.Connector.SetPosition(wx.Point(self.Size[0], self.Size[1] / 2))
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   573
        self.RefreshConnected()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   574
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   575
    # Refresh the position of wires connected to connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   576
    def RefreshConnected(self, exclude = []):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   577
        if self.Connector:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   578
            self.Connector.MoveConnected(exclude)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   579
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   580
    # Test if point given is on the connection connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   581
    def TestConnector(self, pt, exclude=True):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   582
        if self.Connector and self.Connector.TestPoint(pt, exclude):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   583
            return self.Connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   584
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   585
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   586
    # Returns the connection connector
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   587
    def GetConnector(self, position = None, name = None):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   588
        return self.Connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   589
    
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   590
    # Changes the variable type
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   591
    def SetType(self, type):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   592
        if type != self.Type:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   593
            self.Type = type
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   594
            self.Clean()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   595
            # Create an input or output connector according to connection type
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   596
            if self.Type == CONNECTOR:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   597
                self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   598
            else:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   599
                self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   600
            self.RefreshConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   601
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   602
    # Returns the connection type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   603
    def GetType(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   604
        return self.Type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   605
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   606
    # Changes the connection name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   607
    def SetName(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   608
        self.Name = name
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   609
        self.RefreshNameSize()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   610
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   611
    # Returns the connection name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   612
    def GetName(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   613
        return self.Name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   614
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   615
    # Returns the connection minimum size
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   616
    def GetMinSize(self):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   617
        text_width, text_height = self.NameSize
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   618
        if text_height % 2 == 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   619
            text_height += 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   620
        return text_width + text_height + 20, text_height + 10
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   621
    
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   622
    # Method called when a LeftDClick event have been generated
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   623
    def OnLeftDClick(self, event, dc, scaling):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   624
        # Edit the connection properties
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   625
        self.Parent.EditConnectionContent(self)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   626
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   627
    # Method called when a RightUp event have been generated
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   628
    def OnRightUp(self, event, dc, scaling):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   629
        # Popup the default menu
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   630
        self.Parent.PopupDefaultMenu()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   631
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   632
    # Refreshes the connection model
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   633
    def RefreshModel(self, move=True):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   634
        self.Parent.RefreshConnectionModel(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   635
        # If connection has moved and connection is of type CONTINUATION, refresh
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   636
        # the model of wires connected to connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   637
        if move and self.Type == CONTINUATION:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   638
            if self.Connector:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   639
                self.Connector.RefreshWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   640
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   641
    # Draws connection
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   642
    def Draw(self, dc):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   643
        dc.SetPen(wx.BLACK_PEN)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   644
        dc.SetBrush(wx.WHITE_BRUSH)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   645
        # Draw a rectangle with the connection size with arrows in 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   646
        dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   647
        arrowsize = min(self.Size[1] / 2, (self.Size[0] - self.NameSize[0] - 10) / 2)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   648
        dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   649
                self.Pos.y + self.Size[1] / 2)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   650
        dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   651
                self.Pos.x, self.Pos.y + self.Size[1])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   652
        dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   653
                self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   654
        dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   655
                self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   656
        # Draw variable name
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   657
        dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2,
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   658
                self.Pos.y + (self.Size[1] - self.NameSize[1]) / 2)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   659
        # Draw connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   660
        if self.Connector:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   661
            self.Connector.Draw(dc)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   662
        Graphic_Element.Draw(self, dc)