graphics/FBD_Objects.py
author lbessard
Sun, 07 Sep 2008 19:21:39 +0200
changeset 254 27abdcf9a460
parent 249 d8425712acef
child 269 34eff05909b0
permissions -rw-r--r--
Bug with PowerRail resize 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 *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    29
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    30
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    31
#                         Function Block Diagram Block
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    32
#-------------------------------------------------------------------------------
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
Class that implements the graphic representation of a function block
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    36
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    37
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    38
class FBD_Block(Graphic_Element):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    39
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    40
    # Create a new block
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
    41
    def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}, executionOrder = 0):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    42
        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
    43
        self.Type = None
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
    44
        self.Extension = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    45
        self.Id = id
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
    46
        self.SetName(name)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
    47
        self.SetExecutionOrder(executionOrder)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    48
        self.Inputs = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    49
        self.Outputs = []
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
    50
        self.Colour = wx.BLACK
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
    51
        self.Pen = wx.BLACK_PEN
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
    52
        self.SetType(type, extension, inputs, connectors)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
    53
        self.Errors = {}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    54
    
112
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
    55
    # Make a clone of this FBD_Block
162
e746ff4aa8be Bug on Element Paste fixed
lbessard
parents: 145
diff changeset
    56
    def Clone(self, parent, id = None, name = "", pos = None):
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    57
        if self.Name != "" and name == "":
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    58
            name = self.Name
162
e746ff4aa8be Bug on Element Paste fixed
lbessard
parents: 145
diff changeset
    59
        block = FBD_Block(parent, self.Type, name, id, self.Extension)
112
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
    60
        block.SetSize(self.Size[0], self.Size[1])
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
    61
        if pos is not None:
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
    62
            block.SetPosition(pos.x, pos.y)
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
    63
        block.Inputs = [input.Clone(block) for input in self.Inputs]
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
    64
        block.Outputs = [output.Clone(block) for output in self.Outputs]
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
    65
        return block
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
    66
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
    67
    def Flush(self):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
    68
        for input in self.Inputs:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
    69
            input.Flush()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    70
        self.Inputs = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
    71
        for output in self.Outputs:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
    72
            output.Flush()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    73
        self.Outputs = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    74
    
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    75
    # Returns the RedrawRect
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    76
    def GetRedrawRect(self, movex = 0, movey = 0):
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    77
        rect = Graphic_Element.GetRedrawRect(self, movex, movey)
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    78
        if movex != 0 or movey != 0:
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    79
            for input in self.Inputs:
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    80
                if input.IsConnected():
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    81
                    rect = rect.Union(input.GetConnectedRedrawRect(movex, movey))
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    82
            for output in self.Outputs:
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    83
                if output.IsConnected():
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    84
                    rect = rect.Union(output.GetConnectedRedrawRect(movex, movey))
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    85
        return rect
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
    86
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    87
    # Delete this block by calling the appropriate method
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    88
    def Delete(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    89
        self.Parent.DeleteBlock(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    90
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    91
    # Unconnect all inputs and outputs
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    92
    def Clean(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    93
        for input in self.Inputs:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    94
            input.UnConnect(delete = True)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    95
        for output in self.Outputs:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
    96
            output.UnConnect(delete = True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    97
    
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
    98
    # Refresh the size of text for name
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
    99
    def RefreshNameSize(self):
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   100
        self.NameSize = self.Parent.GetTextExtent(self.Name)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   101
    
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   102
    # Refresh the size of text for execution order
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   103
    def RefreshExecutionOrderSize(self):
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   104
        self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder))
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   105
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   106
    # Refresh the block bounding box
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   107
    def RefreshBoundingBox(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   108
        # Calculate the size of the name outside the block
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   109
        text_width, text_height = self.NameSize
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   110
        # Calculate the bounding box size
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   111
        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
   112
        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
   113
        if self.Name != "":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   114
            bbx_y = self.Pos.y - (text_height + 2)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   115
            bbx_height = self.Size[1] + (text_height + 2)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   116
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   117
            bbx_y = self.Pos.y
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   118
            bbx_height = self.Size[1]
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   119
        if self.ExecutionOrder != 0:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   120
            bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0])
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   121
            bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0])
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   122
            bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   123
        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
   124
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   125
    # Refresh the positions of the block connectors
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   126
    def RefreshConnectors(self):
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   127
        scaling = self.Parent.GetScaling()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   128
        # Calculate the size for the connector lines
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   129
        lines = max(len(self.Inputs), len(self.Outputs))
103
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
   130
        if lines > 0:
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
   131
            linesize = max((self.Size[1] - BLOCK_LINE_SIZE) / lines, BLOCK_LINE_SIZE)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   132
            # Update inputs and outputs positions
103
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
   133
            position = BLOCK_LINE_SIZE + linesize / 2
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   134
            for i in xrange(lines):
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   135
                if scaling is not None:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   136
                    ypos = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   137
                else:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   138
                    ypos = position
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   139
                if i < len(self.Inputs):
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   140
                    self.Inputs[i].SetPosition(wx.Point(0, ypos))
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   141
                if i < len(self.Outputs):
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   142
                    self.Outputs[i].SetPosition(wx.Point(self.Size[0], ypos))
103
26c10e28ee3a Bug on block without input or output fixed
lbessard
parents: 102
diff changeset
   143
                position += linesize
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   144
        self.RefreshConnected()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   145
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   146
    # Refresh the positions of wires connected to inputs and outputs
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   147
    def RefreshConnected(self, exclude = []):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   148
        for input in self.Inputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   149
            input.MoveConnected(exclude)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   150
        for output in self.Outputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   151
            output.MoveConnected(exclude)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   152
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   153
    # Returns the block connector that starts with the point given if it exists 
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   154
    def GetConnector(self, position, name = None):
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   155
        # if a name is given
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   156
        if name:
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   157
            # Test each input and output connector
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   158
            for input in self.Inputs:
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   159
                if name == input.GetName():
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   160
                    return input
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   161
            for output in self.Outputs:
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   162
                if name == output.GetName():
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   163
                    return output
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   164
        # Test each input connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   165
        for input in self.Inputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   166
            input_pos = input.GetRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   167
            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
   168
                return input
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   169
        # Test each output connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   170
        for output in self.Outputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   171
            output_pos = output.GetRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   172
            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
   173
                return output
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   174
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   175
    
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   176
    def GetInputTypes(self):
112
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   177
        return tuple([input.GetType(True) for input in self.Inputs])
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   178
    
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   179
    def SetOutputValues(self, values):
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   180
        for output in self.Outputs:
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   181
            output.SetValue(values.get(ouput.getName(), None))
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   182
    
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   183
    def GetConnectionResultType(self, connector, connectortype):
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   184
        resulttype = connectortype
99
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   185
        for input in self.Inputs:
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   186
            name = input.GetName()
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   187
            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
   188
                inputtype = input.GetConnectedType()
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   189
                if resulttype is None or inputtype is not None and self.IsOfType(inputtype, resulttype):
99
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   190
                    resulttype = inputtype
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   191
        for output in self.Outputs:
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   192
            name = output.GetName()
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   193
            if output != connector and name == "OUT" and not self.IsEndType(output.GetType()):
99
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   194
                outputtype = output.GetConnectedType()
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   195
                if resulttype is None or outputtype is not None and self.IsOfType(outputtype, resulttype):
99
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   196
                    resulttype = outputtype
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   197
        return resulttype
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 90
diff changeset
   198
    
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   199
    # Returns all the block connectors
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   200
    def GetConnectors(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   201
        return {"inputs" : self.Inputs, "outputs" : self.Outputs}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   202
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   203
    # Test if point given is on one of the block connectors
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 231
diff changeset
   204
    def TestConnector(self, pt, direction = None, exclude = True):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   205
        # Test each input connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   206
        for input in self.Inputs:
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 231
diff changeset
   207
            if input.TestPoint(pt, direction, exclude):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   208
                return input
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   209
        # Test each output connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   210
        for output in self.Outputs:
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 231
diff changeset
   211
            if output.TestPoint(pt, direction, exclude):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   212
                return output
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   213
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   214
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   215
    # Changes the block type
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   216
    def SetType(self, type, extension, inputs = None, connectors = {}):
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   217
        if type != self.Type or self.Extension != extension: 
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   218
            if type != self.Type:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   219
                self.Type = type
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   220
                self.TypeSize = self.Parent.GetTextExtent(self.Type)
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   221
            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
   222
            # 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
   223
            # inputs and outputs
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   224
            blocktype = self.Parent.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
   225
            if blocktype:
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   226
                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
   227
                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
   228
                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
   229
                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
   230
                    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
   231
                    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
   232
                        start += 1
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   233
                        inputs.append(("IN%d"%start, inputs[-1][1], inputs[-1][2]))
16
20dcc0dce64b Bug on block properties dialog corrected
lbessard
parents: 5
diff changeset
   234
            else:
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   235
                self.Colour = wx.RED
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   236
                if "inputs" in connectors:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   237
                    inputs = connectors["inputs"]
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   238
                else:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   239
                    inputs = []
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   240
                if "outputs" in connectors:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   241
                    outputs = connectors["outputs"]
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   242
                else:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   243
                    outputs = []
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   244
            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
   245
            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
   246
            # 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
   247
            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
   248
            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
   249
                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
   250
                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
   251
                    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
   252
                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
   253
                    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
   254
                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
   255
            # 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
   256
            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
   257
            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
   258
                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
   259
                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
   260
                    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
   261
                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
   262
                    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
   263
                self.Outputs.append(connector)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   264
            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
   265
            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
   266
            self.RefreshBoundingBox()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   267
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   268
    # Returns the block type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   269
    def GetType(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   270
        return self.Type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   271
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   272
    # Changes the block name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   273
    def SetName(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   274
        self.Name = name
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   275
        self.RefreshNameSize()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   276
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   277
    # Returs the block name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   278
    def GetName(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   279
        return self.Name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   280
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   281
    # Changes the extension name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   282
    def SetExtension(self, extension):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   283
        self.Extension = extension
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   284
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   285
    # Returs the extension name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   286
    def GetExtension(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   287
        return self.Extension
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   288
    
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   289
    # Changes the execution order
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   290
    def SetExecutionOrder(self, executionOrder):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   291
        self.ExecutionOrder = executionOrder
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   292
        self.RefreshExecutionOrderSize()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   293
    
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   294
    # Returs the execution order
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   295
    def GetExecutionOrder(self):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   296
        return self.ExecutionOrder
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   297
    
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   298
    # Refresh the block minimum size
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   299
    def RefreshMinSize(self):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   300
        # Calculate the inputs maximum width
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   301
        max_input = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   302
        for input in self.Inputs:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   303
            w, h = input.GetNameSize()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   304
            max_input = max(max_input, w)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   305
        # Calculate the outputs maximum width
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   306
        max_output = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   307
        for output in self.Outputs:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   308
            w, h = output.GetNameSize()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   309
            max_output = max(max_output, w)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   310
        width = max(self.TypeSize[0] + 10, max_input + max_output + 15)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   311
        height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   312
        self.MinSize = width, height
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   313
    
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   314
    # Returns the block minimum size
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   315
    def GetMinSize(self):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   316
        return self.MinSize
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   317
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   318
    # Changes the negated property of the connector handled
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   319
    def SetConnectorNegated(self, negated):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   320
        handle_type, handle = self.Handle
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   321
        if handle_type == HANDLE_CONNECTOR:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   322
            handle.SetNegated(negated)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   323
            self.RefreshModel(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   324
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   325
    # Changes the edge property of the connector handled
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   326
    def SetConnectorEdge(self, edge):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   327
        handle_type, handle = self.Handle
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   328
        if handle_type == HANDLE_CONNECTOR:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   329
            handle.SetEdge(edge)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   330
            self.RefreshModel(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   331
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   332
    # Method called when a LeftDClick event have been generated
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   333
    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
   334
        # Edit the block properties
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   335
        self.Parent.EditBlockContent(self)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 0
diff changeset
   336
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   337
    # Method called when a RightUp event have been generated
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   338
    def OnRightUp(self, event, dc, scaling):
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   339
        pos = GetScaledEventPosition(event, dc, scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   340
        # Popup the menu with special items for a block and a connector if one is handled
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 231
diff changeset
   341
        connector = self.TestConnector(pos, exclude=False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   342
        if connector:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   343
            self.Handle = (HANDLE_CONNECTOR, connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   344
            self.Parent.PopupBlockMenu(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   345
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   346
            self.Parent.PopupBlockMenu()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   347
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   348
    # Refreshes the block model
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   349
    def RefreshModel(self, move=True):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   350
        self.Parent.RefreshBlockModel(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   351
        # If block has moved, refresh the model of wires connected to outputs
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   352
        if move:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   353
            for output in self.Outputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   354
                output.RefreshWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   355
    
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   356
    def AddError(self, infos, start, end):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   357
        if infos[0] in ["type", "name"] and start[0] == 0 and end[0] == 0:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   358
            self.Errors[infos[0]] = (start, end)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   359
        elif infos[0] == "input" and infos[1] < len(self.Inputs):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   360
            self.Inputs[infos[1]].AddError(infos[2:], start, end)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   361
        elif infos[0] == "output" and infos[1] < len(self.Outputs):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   362
            self.Outputs[infos[1]].AddError(infos[2:], start, end)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   363
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   364
    # Draws block
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   365
    def Draw(self, dc):
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   366
        Graphic_Element.Draw(self, dc)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   367
        dc.SetPen(self.Pen)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   368
        dc.SetBrush(wx.WHITE_BRUSH)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 64
diff changeset
   369
        dc.SetTextForeground(self.Colour)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   370
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   371
        if getattr(dc, "printing", False):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   372
            name_size = dc.GetTextExtent(self.Name)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   373
            type_size = dc.GetTextExtent(self.Type)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   374
            executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder))
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   375
        else:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   376
            name_size = self.NameSize
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   377
            type_size = self.TypeSize
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   378
            executionorder_size = self.ExecutionOrderSize
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   379
            
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   380
        # Draw a rectangle with the block size
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   381
        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
   382
        # Draw block name and block type
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   383
        name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   384
                    self.Pos.y - (name_size[1] + 2))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   385
        type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2,
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   386
                    self.Pos.y + 5)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   387
        dc.DrawText(self.Name, name_pos[0], name_pos[1])
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   388
        dc.DrawText(self.Type, type_pos[0], type_pos[1])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   389
        # Draw inputs and outputs connectors
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   390
        for input in self.Inputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   391
            input.Draw(dc)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   392
        for output in self.Outputs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   393
            output.Draw(dc)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   394
        if self.ExecutionOrder != 0:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   395
            # Draw block execution order
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   396
            dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0],
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   397
                    self.Pos.y + self.Size[1] + 2)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   398
        if "name" in self.Errors:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   399
            HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1])
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   400
        if "type" in self.Errors:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   401
            HighlightErrorZone(dc, type_pos[0], type_pos[1], type_size[0], type_size[1])    
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 118
diff changeset
   402
        dc.SetTextForeground(wx.BLACK)
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 118
diff changeset
   403
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   404
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   405
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   406
#                        Function Block Diagram Variable
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   407
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   408
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   409
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   410
Class that implements the graphic representation of a variable
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   411
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   412
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   413
class FBD_Variable(Graphic_Element):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   414
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   415
    # Create a new variable
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   416
    def __init__(self, parent, type, name, value_type, id = None, executionOrder = 0):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   417
        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
   418
        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
   419
        self.ValueType = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   420
        self.Id = id
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   421
        self.SetName(name)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   422
        self.SetExecutionOrder(executionOrder)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   423
        self.Input = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   424
        self.Output = None
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   425
        self.SetType(type, value_type)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   426
        self.Errors = []
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   427
    
112
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   428
    # Make a clone of this FBD_Variable
162
e746ff4aa8be Bug on Element Paste fixed
lbessard
parents: 145
diff changeset
   429
    def Clone(self, parent, id = None, pos = None):
e746ff4aa8be Bug on Element Paste fixed
lbessard
parents: 145
diff changeset
   430
        variable = FBD_Variable(parent, self.Type, self.Name, self.ValueType, id)
112
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   431
        variable.SetSize(self.Size[0], self.Size[1])
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   432
        if pos is not None:
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   433
            variable.SetPosition(pos.x, pos.y)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   434
        if self.Input:
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   435
            variable.Input = self.Input.Clone(variable)
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   436
        if self.Output:
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   437
            variable.Output = self.Output.Clone(variable)
112
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   438
        return variable
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   439
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   440
    def Flush(self):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   441
        if self.Input is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   442
            self.Input.Flush()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   443
            self.Input = None
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   444
        if self.Output is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   445
            self.Output.Flush()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   446
            self.Output = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   447
    
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   448
    # Returns the RedrawRect
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   449
    def GetRedrawRect(self, movex = 0, movey = 0):
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   450
        rect = Graphic_Element.GetRedrawRect(self, movex, movey)
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   451
        if movex != 0 or movey != 0:
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   452
            if self.Input and self.Input.IsConnected():
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   453
                rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey))
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   454
            if self.Output and self.Output.IsConnected():
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   455
                rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey))
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   456
        return rect
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   457
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   458
    # Unconnect connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   459
    def Clean(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   460
        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
   461
            self.Input.UnConnect(delete = True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   462
        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
   463
            self.Output.UnConnect(delete = True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   464
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   465
    # Delete this variable by calling the appropriate method
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   466
    def Delete(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   467
        self.Parent.DeleteVariable(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   468
    
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   469
    # Refresh the size of text for name
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   470
    def RefreshNameSize(self):
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   471
        self.NameSize = self.Parent.GetTextExtent(self.Name)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   472
    
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   473
    # Refresh the size of text for execution order
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   474
    def RefreshExecutionOrderSize(self):
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   475
        self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder))
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   476
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   477
    # Refresh the variable bounding box
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   478
    def RefreshBoundingBox(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   479
        if self.Type in (OUTPUT, INOUT):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   480
            bbx_x = self.Pos.x - CONNECTOR_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   481
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   482
            bbx_x = self.Pos.x
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   483
        if self.Type == INOUT:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   484
            bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   485
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   486
            bbx_width = self.Size[0] + CONNECTOR_SIZE
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   487
        bbx_height = self.Size[1]
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   488
        if self.ExecutionOrder != 0:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   489
            bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0])
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   490
            bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0])
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   491
            bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   492
        self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, bbx_height + 1)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   493
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   494
    # Refresh the position of the variable connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   495
    def RefreshConnectors(self):
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   496
        scaling = self.Parent.GetScaling()
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   497
        if scaling is not None:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   498
            position = round(float(self.Pos.y + self.Size[1] / 2) / float(scaling[1])) * scaling[1] - self.Pos.y
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   499
        else:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   500
            position = self.Size[1] / 2
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   501
        if self.Input:
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   502
            self.Input.SetPosition(wx.Point(0, position))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   503
        if self.Output:
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   504
            self.Output.SetPosition(wx.Point(self.Size[0], position))
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   505
        self.RefreshConnected()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   506
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   507
    # Refresh the position of wires connected to connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   508
    def RefreshConnected(self, exclude = []):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   509
        if self.Input:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   510
            self.Input.MoveConnected(exclude)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   511
        if self.Output:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   512
            self.Output.MoveConnected(exclude)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   513
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   514
    # Test if point given is on the variable connector
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 231
diff changeset
   515
    def TestConnector(self, pt, direction = None, exclude=True):
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 231
diff changeset
   516
        if self.Input and self.Input.TestPoint(pt, direction, exclude):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   517
            return self.Input
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 231
diff changeset
   518
        if self.Output and self.Output.TestPoint(pt, direction, exclude):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   519
            return self.Output
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   520
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   521
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   522
    # Returns the block connector that starts with the point given if it exists 
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   523
    def GetConnector(self, position, name = None):
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   524
        # if a name is given
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   525
        if name:
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   526
            # Test input and output connector if they exists
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   527
            if self.Input and name == self.Input.GetName():
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   528
                return self.Input
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   529
            if self.Output and name == self.Output.GetName():
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   530
                return self.Output
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   531
        # Test input connector if it exists
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   532
        if self.Input:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   533
            input_pos = self.Input.GetRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   534
            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
   535
                return self.Input
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   536
        # Test output connector if it exists
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   537
        if self.Output:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   538
            output_pos = self.Output.GetRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   539
            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
   540
                return self.Output
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   541
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   542
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   543
    # Returns all the block connectors 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   544
    def GetConnectors(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   545
        return {"input" : self.Input, "output" : self.Output}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   546
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   547
    # Changes the negated property of the variable connector if handled
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   548
    def SetConnectorNegated(self, negated):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   549
        handle_type, handle = self.Handle
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   550
        if handle_type == HANDLE_CONNECTOR:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   551
            handle.SetNegated(negated)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   552
            self.RefreshModel(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   553
    
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   554
    # 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
   555
    def SetType(self, type, value_type):
32
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   556
        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
   557
            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
   558
            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
   559
            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
   560
            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
   561
            # 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
   562
            if self.Type != INPUT:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   563
                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
   564
            if self.Type != OUTPUT:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   565
                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
   566
            self.RefreshConnectors()
32
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   567
        elif value_type != self.ValueType:
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   568
            if self.Input:
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   569
                self.Input.SetType(value_type)
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   570
            if self.Output:
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   571
                self.Output.SetType(value_type)            
cf9efccff009 FBD_Variable don't remove wire when just expression changed
lbessard
parents: 28
diff changeset
   572
        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
   573
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   574
    # Returns the variable type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   575
    def GetType(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   576
        return self.Type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   577
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   578
    # Changes the variable name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   579
    def SetName(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   580
        self.Name = name
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   581
        self.RefreshNameSize()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   582
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   583
    # Returns the variable name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   584
    def GetName(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   585
        return self.Name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   586
    
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   587
    # Changes the execution order
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   588
    def SetExecutionOrder(self, executionOrder):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   589
        self.ExecutionOrder = executionOrder
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   590
        self.RefreshExecutionOrderSize()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   591
    
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   592
    # Returs the execution order
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   593
    def GetExecutionOrder(self):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   594
        return self.ExecutionOrder
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   595
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   596
    # Returns the variable minimum size
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   597
    def GetMinSize(self):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   598
        return self.NameSize[0] + 10, self.NameSize[1] + 10
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   599
    
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   600
    # Method called when a LeftDClick event have been generated
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   601
    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
   602
        # 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
   603
        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
   604
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   605
    # Method called when a RightUp event have been generated
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   606
    def OnRightUp(self, event, dc, scaling):
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 99
diff changeset
   607
        self.Parent.PopupDefaultMenu()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   608
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   609
    # Refreshes the variable model
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   610
    def RefreshModel(self, move=True):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   611
        self.Parent.RefreshVariableModel(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   612
        # 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
   613
        # of wires connected to output connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   614
        if move and self.Type != OUTPUT:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   615
            if self.Output:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   616
                self.Output.RefreshWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   617
    
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   618
    def AddError(self, infos, start, end):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   619
        if infos[0] == "expression" and start[0] == 0 and end[0] == 0:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   620
            self.Errors.append((start[1], end[1]))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   621
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   622
    # Draws variable
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   623
    def Draw(self, dc):
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   624
        Graphic_Element.Draw(self, dc)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   625
        dc.SetPen(wx.BLACK_PEN)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   626
        dc.SetBrush(wx.WHITE_BRUSH)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   627
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   628
        if getattr(dc, "printing", False):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   629
            name_size = dc.GetTextExtent(self.Name)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   630
            executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder))
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   631
        else:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   632
            name_size = self.NameSize
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   633
            executionorder_size = self.ExecutionOrderSize
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   634
        
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   635
        text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, 
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   636
                    self.Pos.y + (self.Size[1] - name_size[1]) / 2)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   637
        # Draw a rectangle with the variable size
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   638
        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
   639
        # Draw variable name
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   640
        dc.DrawText(self.Name, text_pos[0], text_pos[1])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   641
        # Draw connectors
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   642
        if self.Input:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   643
            self.Input.Draw(dc)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   644
        if self.Output:    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   645
            self.Output.Draw(dc)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   646
        if self.ExecutionOrder != 0:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   647
            # Draw variable execution order
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   648
            dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0],
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   649
                    self.Pos.y + self.Size[1] + 2)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   650
        for start, end in self.Errors:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   651
            offset = dc.GetTextExtent(self.Name[:start])
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   652
            size = dc.GetTextExtent(self.Name[start:end + 1])
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 213
diff changeset
   653
            HighlightErrorZone(dc, text_pos[0] + offset[0], text_pos[1], size[0], size[1])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   654
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   655
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   656
#                        Function Block Diagram Connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   657
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   658
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   659
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   660
Class that implements the graphic representation of a connection
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   661
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   662
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   663
class FBD_Connector(Graphic_Element):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   664
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   665
    # Create a new connection
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   666
    def __init__(self, parent, type, name, id = None):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   667
        Graphic_Element.__init__(self, parent)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   668
        self.Type = type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   669
        self.Id = id
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   670
        self.SetName(name)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   671
        self.Pos = wx.Point(0, 0)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   672
        self.Size = wx.Size(0, 0)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   673
        # Create an input or output connector according to connection type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   674
        if self.Type == CONNECTOR:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   675
            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
   676
        else:
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   677
            self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   678
        self.RefreshConnectors()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   679
        self.RefreshNameSize()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   680
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   681
    def Flush(self):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   682
        if self.Connector:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   683
            self.Connector.Flush()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   684
            self.Connector = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   685
    
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   686
    # Returns the RedrawRect
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   687
    def GetRedrawRect(self, movex = 0, movey = 0):
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   688
        rect = Graphic_Element.GetRedrawRect(self, movex, movey)
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   689
        if movex != 0 or movey != 0:
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   690
            if self.Connector and self.Connector.IsConnected():
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   691
                rect = rect.Union(self.Connector.GetConnectedRedrawRect(movex, movey))
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   692
        return rect
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   693
    
112
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   694
    # Make a clone of this FBD_Connector
162
e746ff4aa8be Bug on Element Paste fixed
lbessard
parents: 145
diff changeset
   695
    def Clone(self, parent, id = None, pos = None):
e746ff4aa8be Bug on Element Paste fixed
lbessard
parents: 145
diff changeset
   696
        connection = FBD_Connector(parent, self.Type, self.Name, id)
112
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   697
        connection.SetSize(self.Size[0], self.Size[1])
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   698
        if pos is not None:
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   699
            connection.SetPosition(pos.x, pos.y)
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   700
        connection.Connector = self.Connector.Clone(connection)
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   701
        return connection
317148fc1225 Adding support for block copy
lbessard
parents: 103
diff changeset
   702
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   703
    # Unconnect connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   704
    def Clean(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   705
        if self.Connector:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   706
            self.Connector.UnConnect(delete = True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   707
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   708
    # Delete this connection by calling the appropriate method
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   709
    def Delete(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   710
        self.Parent.DeleteConnection(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   711
    
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   712
    # Refresh the size of text for name
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   713
    def RefreshNameSize(self):
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   714
        self.NameSize = self.Parent.GetTextExtent(self.Name)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   715
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   716
    # Refresh the connection bounding box
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   717
    def RefreshBoundingBox(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   718
        if self.Type == CONNECTOR:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   719
            bbx_x = self.Pos.x - CONNECTOR_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   720
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   721
            bbx_x = self.Pos.x
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   722
        bbx_width = self.Size[0] + CONNECTOR_SIZE
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   723
        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
   724
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   725
    # Refresh the position of the connection connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   726
    def RefreshConnectors(self):
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   727
        scaling = self.Parent.GetScaling()
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   728
        if scaling is not None:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   729
            position = round(float(self.Pos.y + self.Size[1] / 2) / float(scaling[1])) * scaling[1] - self.Pos.y
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   730
        else:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   731
            position = self.Size[1] / 2
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   732
        if self.Type == CONNECTOR:
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   733
            self.Connector.SetPosition(wx.Point(0, position))
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   734
        else:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   735
            self.Connector.SetPosition(wx.Point(self.Size[0], position))
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   736
        self.RefreshConnected()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   737
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   738
    # Refresh the position of wires connected to connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   739
    def RefreshConnected(self, exclude = []):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   740
        if self.Connector:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   741
            self.Connector.MoveConnected(exclude)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   742
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   743
    # Test if point given is on the connection connector
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 231
diff changeset
   744
    def TestConnector(self, pt, direction = None, exclude=True):
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 231
diff changeset
   745
        if self.Connector and self.Connector.TestPoint(pt, direction, exclude):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   746
            return self.Connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   747
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   748
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   749
    # Returns the connection connector
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   750
    def GetConnector(self, position = None, name = None):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   751
        return self.Connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   752
    
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   753
    # Changes the variable type
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   754
    def SetType(self, type):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   755
        if type != self.Type:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   756
            self.Type = type
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   757
            self.Clean()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   758
            # Create an input or output connector according to connection type
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   759
            if self.Type == CONNECTOR:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   760
                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
   761
            else:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   762
                self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   763
            self.RefreshConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   764
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   765
    # Returns the connection type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   766
    def GetType(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   767
        return self.Type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   768
    
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   769
    def GetConnectionResultType(self, connector, connectortype):
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   770
        return connectortype
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   771
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   772
    # Changes the connection name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   773
    def SetName(self, name):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   774
        self.Name = name
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   775
        self.RefreshNameSize()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   776
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   777
    # Returns the connection name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   778
    def GetName(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   779
        return self.Name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   780
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   781
    # Returns the connection minimum size
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   782
    def GetMinSize(self):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 32
diff changeset
   783
        text_width, text_height = self.NameSize
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   784
        if text_height % 2 == 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   785
            text_height += 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   786
        return text_width + text_height + 20, text_height + 10
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   787
    
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   788
    # Method called when a LeftDClick event have been generated
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   789
    def OnLeftDClick(self, event, dc, scaling):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   790
        # Edit the connection properties
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   791
        self.Parent.EditConnectionContent(self)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   792
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   793
    # Method called when a RightUp event have been generated
27
dae55dd9ee14 Current developping version
lbessard
parents: 16
diff changeset
   794
    def OnRightUp(self, event, dc, scaling):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   795
        # Popup the default menu
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   796
        self.Parent.PopupDefaultMenu()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   797
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   798
    # Refreshes the connection model
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   799
    def RefreshModel(self, move=True):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   800
        self.Parent.RefreshConnectionModel(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   801
        # If connection has moved and connection is of type CONTINUATION, refresh
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   802
        # the model of wires connected to connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   803
        if move and self.Type == CONTINUATION:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   804
            if self.Connector:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   805
                self.Connector.RefreshWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   806
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   807
    # Draws connection
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   808
    def Draw(self, dc):
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   809
        Graphic_Element.Draw(self, dc)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   810
        dc.SetPen(wx.BLACK_PEN)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   811
        dc.SetBrush(wx.WHITE_BRUSH)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   812
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   813
        if getattr(dc, "printing", False):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   814
            name_size = dc.GetTextExtent(self.Name)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   815
        else:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   816
            name_size = self.NameSize
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   817
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   818
        # Draw a rectangle with the connection size with arrows in 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   819
        dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   820
        arrowsize = min(self.Size[1] / 2, (self.Size[0] - name_size[0] - 10) / 2)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   821
        dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   822
                self.Pos.y + self.Size[1] / 2)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   823
        dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   824
                self.Pos.x, self.Pos.y + self.Size[1])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   825
        dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   826
                self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   827
        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
   828
                self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1])
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 112
diff changeset
   829
        # Draw connection name
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   830
        dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - name_size[0]) / 2,
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 165
diff changeset
   831
                self.Pos.y + (self.Size[1] - name_size[1]) / 2)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   832
        # Draw connector
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   833
        if self.Connector:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   834
            self.Connector.Draw(dc)
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 118
diff changeset
   835