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