Viewer.py
author lbessard
Thu, 19 Jul 2007 15:04:41 +0200
changeset 46 4379e98a30aa
parent 45 42637f721b5b
child 47 2b2f8d88e6d3
permissions -rw-r--r--
Bug on SFC generation fixed
Adding Action and Transition remove functions
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
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     7
#Copyright (C): Edouard TISSERANT and Laurent BESSARD
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
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    19
#Lesser General Public License for more details.
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
from wxPython.wx import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    26
import wx
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    27
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    28
from plcopen.structures import *
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    29
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    30
from Dialogs import *
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    31
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    32
SCROLLBAR_UNIT = 10
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    33
WINDOW_BORDER = 10
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    34
SCROLL_ZONE = 10
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    35
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    36
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    37
#                       Graphic elements Viewer base class
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    38
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    39
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    40
# ID Constants for menu items
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    41
[wxID_FBDVIEWERCONTEXTUALMENUITEMS0, wxID_FBDVIEWERCONTEXTUALMENUITEMS1,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    42
 wxID_FBDVIEWERCONTEXTUALMENUITEMS2, wxID_FBDVIEWERCONTEXTUALMENUITEMS3,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    43
 wxID_FBDVIEWERCONTEXTUALMENUITEMS5, wxID_FBDVIEWERCONTEXTUALMENUITEMS6,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    44
 wxID_FBDVIEWERCONTEXTUALMENUITEMS8, wxID_FBDVIEWERCONTEXTUALMENUITEMS9,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    45
 wxID_FBDVIEWERCONTEXTUALMENUITEMS11,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    46
] = [wx.NewId() for _init_coll_ContextualMenu_Items in range(9)]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    47
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    48
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    49
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    50
Class that implements a Viewer based on a wxScrolledWindow for drawing and 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    51
manipulating graphic elements
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    52
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    53
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    54
class Viewer(wx.ScrolledWindow):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    55
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    56
    # Create Contextual Menu items
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    57
    def _init_coll_ContextualMenu_Items(self, parent):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    58
        # Create menu items
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    59
        parent.Append(help='', id=wxID_FBDVIEWERCONTEXTUALMENUITEMS0,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    60
              kind=wx.ITEM_RADIO, text=u'No Modifier')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    61
        parent.Append(help='', id=wxID_FBDVIEWERCONTEXTUALMENUITEMS1,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    62
              kind=wx.ITEM_RADIO, text=u'Negated')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    63
        parent.Append(help='', id=wxID_FBDVIEWERCONTEXTUALMENUITEMS2,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    64
              kind=wx.ITEM_RADIO, text=u'Rising Edge')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    65
        parent.Append(help='', id=wxID_FBDVIEWERCONTEXTUALMENUITEMS3,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    66
              kind=wx.ITEM_RADIO, text=u'Falling Edge')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    67
        parent.AppendSeparator()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    68
        parent.Append(help='', id=wxID_FBDVIEWERCONTEXTUALMENUITEMS5,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    69
              kind=wx.ITEM_NORMAL, text=u'Add Wire Segment')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    70
        parent.Append(help='', id=wxID_FBDVIEWERCONTEXTUALMENUITEMS6,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    71
              kind=wx.ITEM_NORMAL, text=u'Delete Wire Segment')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    72
        parent.AppendSeparator()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    73
        parent.Append(help='', id=wxID_FBDVIEWERCONTEXTUALMENUITEMS8,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    74
              kind=wx.ITEM_NORMAL, text=u'Add Divergence Branch')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    75
        parent.Append(help='', id=wxID_FBDVIEWERCONTEXTUALMENUITEMS9,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    76
              kind=wx.ITEM_NORMAL, text=u'Delete Divergence Branch')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    77
        parent.AppendSeparator()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    78
        parent.Append(help='', id=wxID_FBDVIEWERCONTEXTUALMENUITEMS11,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    79
              kind=wx.ITEM_NORMAL, text=u'Delete')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    80
        # Link menu event to corresponding called functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    81
        self.Bind(wx.EVT_MENU, self.OnNoModifierMenu,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    82
              id=wxID_FBDVIEWERCONTEXTUALMENUITEMS0)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    83
        self.Bind(wx.EVT_MENU, self.OnNegatedMenu,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    84
              id=wxID_FBDVIEWERCONTEXTUALMENUITEMS1)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    85
        self.Bind(wx.EVT_MENU, self.OnRisingEdgeMenu,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    86
              id=wxID_FBDVIEWERCONTEXTUALMENUITEMS2)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    87
        self.Bind(wx.EVT_MENU, self.OnFallingEdgeMenu,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    88
              id=wxID_FBDVIEWERCONTEXTUALMENUITEMS3)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    89
        self.Bind(wx.EVT_MENU, self.OnAddSegmentMenu,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    90
              id=wxID_FBDVIEWERCONTEXTUALMENUITEMS5)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    91
        self.Bind(wx.EVT_MENU, self.OnDeleteSegmentMenu,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    92
              id=wxID_FBDVIEWERCONTEXTUALMENUITEMS6)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    93
        self.Bind(wx.EVT_MENU, self.OnAddBranchMenu,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    94
              id=wxID_FBDVIEWERCONTEXTUALMENUITEMS8)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    95
        self.Bind(wx.EVT_MENU, self.OnDeleteBranchMenu,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    96
              id=wxID_FBDVIEWERCONTEXTUALMENUITEMS9)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    97
        self.Bind(wx.EVT_MENU, self.OnDeleteMenu,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    98
              id=wxID_FBDVIEWERCONTEXTUALMENUITEMS11)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    99
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   100
    # Create and initialize Contextual Menu
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   101
    def _init_menus(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   102
        self.ContextualMenu = wx.Menu(title='')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   103
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   104
        self._init_coll_ContextualMenu_Items(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   105
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   106
    # Create a new Viewer
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   107
    def __init__(self, parent, window, controler):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   108
        wx.ScrolledWindow.__init__(self, parent, style=wx.SUNKEN_BORDER | wx.HSCROLL | wx.VSCROLL)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   109
        self._init_menus()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   110
        # Adding a rubberband to Viewer
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   111
        self.rubberBand = RubberBand(drawingSurface=self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   112
        self.SetBackgroundColour(wxColour(255,255,255))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   113
        self.ResetView()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   114
        self.Scaling = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   115
        #self.Scaling = (8, 8)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   116
        self.DrawGrid = True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   117
        self.current_id = 0    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   118
        
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   119
        # Initialize Block, Wire and Comment numbers
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   120
        self.block_id = self.wire_id = self.comment_id = 0
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   121
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   122
        # Initialize Viewer mode to Selection mode
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   123
        self.Mode = MODE_SELECTION
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   124
        self.SavedMode = False
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   125
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   126
        self.Parent = window
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   127
        self.Controler = controler
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   128
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   129
        # Link Viewer event to corresponding methods
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   130
        EVT_PAINT(self, self.OnPaint)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   131
        EVT_LEFT_DOWN(self, self.OnViewerLeftDown)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   132
        EVT_LEFT_UP(self, self.OnViewerLeftUp)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   133
        EVT_LEFT_DCLICK(self, self.OnViewerLeftDClick)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   134
        EVT_RIGHT_UP(self, self.OnViewerRightUp)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   135
        EVT_MOTION(self, self.OnViewerMotion)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   136
        EVT_CHAR(self, self.OnChar)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   137
        EVT_SCROLLWIN(self, self.OnMoveWindow)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   138
        EVT_SIZE(self, self.OnMoveWindow)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   139
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   140
    # Returns a new id
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   141
    def GetNewId(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   142
        self.current_id += 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   143
        return self.current_id
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   144
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   145
    # Destructor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   146
    def __del__(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   147
        self.ResetView()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   148
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   149
    def GetLogicalDC(self):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   150
        dc = wxClientDC(self)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   151
        self.DoPrepareDC(dc)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   152
        return dc
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   153
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   154
#-------------------------------------------------------------------------------
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   155
#                         Element management functions
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   156
#-------------------------------------------------------------------------------
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   157
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   158
    def AddBlock(self, block):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   159
        self.block_id += 1
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   160
        self.Blocks[block] = self.block_id
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   161
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   162
    def AddWire(self, wire):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   163
        self.wire_id += 1
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   164
        self.Wires[wire] = self.wire_id
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   165
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   166
    def AddComment(self, comment):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   167
        self.comment_id += 1
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   168
        self.Comments[comment] = self.comment_id
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   169
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   170
    def IsBlock(self, block):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   171
        return self.Blocks.get(block, False)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   172
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   173
    def IsWire(self, wire):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   174
        return self.Wires.get(wire, False)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   175
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   176
    def IsComment(self, comment):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   177
        return self.Comments.get(comment, False)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   178
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   179
    def RemoveBlock(self, block):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   180
        self.Blocks.pop(block)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   181
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   182
    def RemoveWire(self, wire):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   183
        self.Wires.pop(wire)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   184
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   185
    def RemoveComment(self, comment):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   186
        self.Comments.pop(comment)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   187
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   188
    def GetElements(self, sort_blocks=False, sort_wires=False, sort_comments=False):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   189
        blocks = self.Blocks.keys()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   190
        wires = self.Wires.keys()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   191
        comments = self.Comments.keys()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   192
        if sort_blocks:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   193
            blocks.sort(lambda x,y:self.Blocks[x].__cmp__(self.Blocks[y]))
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   194
        if sort_wires:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   195
            wires.sort(lambda x,y:self.Wires[x].__cmp__(self.Wires[y]))
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   196
        if sort_comments:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   197
            comments.sort(lambda x,y:self.Comments[x].__cmp__(self.Comments[y]))
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   198
        return blocks + wires + comments
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   199
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   200
#-------------------------------------------------------------------------------
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   201
#                              Reset functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   202
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   203
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   204
    # Resets Viewer lists
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   205
    def ResetView(self):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   206
        self.Blocks = {}
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   207
        self.Wires = {}
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   208
        self.Comments = {}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   209
        self.SelectedElement = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   210
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   211
    # Changes Viewer mode
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   212
    def SetMode(self, mode):
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   213
        if self.Mode != mode or mode == MODE_SELECTION:
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   214
            self.Mode = mode
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   215
            self.SavedMode = False
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   216
        else:
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   217
            self.SavedMode = True
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   218
        # Reset selection
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   219
        if self.Mode != MODE_SELECTION and self.SelectedElement:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   220
            self.SelectedElement.SetSelected(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   221
            self.SelectedElement = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   222
            self.Refresh()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   223
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   224
    # Return current drawing mode
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   225
    def GetDrawingMode(self):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   226
        return self.Parent.GetDrawingMode()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   227
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   228
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   229
#                          Refresh functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   230
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   231
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   232
    # Refresh Viewer elements
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   233
    def RefreshView(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   234
        self.current_id = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   235
        # Start by reseting Viewer
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   236
        self.ResetView()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   237
        instance = True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   238
        # List of ids of already loaded blocks
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   239
        ids = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   240
        # Load Blocks until they are all loaded
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   241
        while instance:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   242
            instance = self.Controler.GetCurrentElementEditingInstanceInfos(exclude=ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   243
            if instance:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   244
                self.loadInstance(instance, ids)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   245
        self.RefreshScrollBars()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   246
        self.Refresh()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   247
    
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   248
    def RefreshScrollBars(self):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   249
        xstart, ystart = self.GetViewStart()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   250
        window_size = self.GetClientSize()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   251
        maxx = maxy = 0
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   252
        for element in self.GetElements():
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   253
            posx, posy = element.GetPosition()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   254
            width, height = element.GetSize()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   255
            maxx = max(maxx, posx + width)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   256
            maxy = max(maxy, posy + height)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   257
        maxx = max(maxx + WINDOW_BORDER, xstart * SCROLLBAR_UNIT + window_size[0])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   258
        maxy = max(maxy + WINDOW_BORDER, ystart * SCROLLBAR_UNIT + window_size[1])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   259
        if self.rubberBand.IsShown():
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   260
            extent = self.rubberBand.GetCurrentExtent()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   261
            maxx = max(maxx, extent.x + extent.width)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   262
            maxy = max(maxy, extent.y + extent.height)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   263
        self.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   264
            maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, xstart, ystart)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   265
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   266
    # Load instance from given informations
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   267
    def loadInstance(self, instance, ids):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   268
        ids.append(instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   269
        self.current_id = max(self.current_id, instance["id"]) 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   270
        if instance["type"] == "input":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   271
            variable = FBD_Variable(self, INPUT, instance["name"], instance["value_type"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   272
            variable.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   273
            variable.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   274
            self.AddBlock(variable)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   275
            connectors = variable.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   276
            connectors["output"].SetPosition(wxPoint(*instance["connector"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   277
            if instance["connector"]["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   278
                connectors["output"].SetNegated(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   279
            if instance["connector"]["edge"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   280
                connectors["output"].SetEdge(instance["connector"]["edge"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   281
        elif instance["type"] == "output":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   282
            variable = FBD_Variable(self, OUTPUT, instance["name"], instance["value_type"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   283
            variable.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   284
            variable.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   285
            self.AddBlock(variable)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   286
            connectors = variable.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   287
            connectors["input"].SetPosition(wxPoint(*instance["connector"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   288
            if instance["connector"]["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   289
                connectors["input"].SetNegated(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   290
            if instance["connector"]["edge"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   291
                connectors["input"].SetEdge(instance["connector"]["edge"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   292
            self.CreateWires(connectors["input"], instance["connector"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   293
        elif instance["type"] == "inout":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   294
            variable = FBD_Variable(self, INOUT, instance["name"], instance["value_type"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   295
            variable.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   296
            variable.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   297
            self.AddBlock(variable)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   298
            connectors = variable.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   299
            connectors["output"].SetPosition(wxPoint(*instance["connectors"]["output"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   300
            connectors["input"].SetPosition(wxPoint(*instance["connectors"]["input"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   301
            if instance["connectors"]["output"]["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   302
                connectors["output"].SetNegated(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   303
            if instance["connectors"]["output"]["edge"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   304
                connectors["output"].SetEdge(instance["connectors"]["output"]["edge"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   305
            if instance["connectors"]["input"]["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   306
                connectors["input"].SetNegated(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   307
            if instance["connectors"]["input"]["edge"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   308
                connectors["input"].SetEdge(instance["connectors"]["input"]["edge"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   309
            self.CreateWires(connectors["input"], instance["connectors"]["input"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   310
        elif instance["type"] == "continuation":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   311
            connection = FBD_Connector(self, CONTINUATION, instance["name"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   312
            connection.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   313
            connection.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   314
            self.AddBlock(connection)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   315
            connector = connection.GetConnector()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   316
            connector.SetPosition(wxPoint(*instance["connector"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   317
        elif instance["type"] == "connection":
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   318
            connection = FBD_Connector(self, CONNECTOR, instance["name"], instance["id"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   319
            connection.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   320
            connection.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   321
            self.AddBlock(connection)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   322
            connector = connection.GetConnector()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   323
            connector.SetPosition(wxPoint(*instance["connector"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   324
            self.CreateWires(connector, instance["connector"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   325
        elif instance["type"] == "comment":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   326
            comment = Comment(self, instance["content"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   327
            comment.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   328
            comment.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   329
            self.AddComment(comment)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   330
        elif instance["type"] == "leftPowerRail":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   331
            leftpowerrail = LD_PowerRail(self, LEFTRAIL, instance["id"], [True for i in range(len(instance["connectors"]))])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   332
            leftpowerrail.SetPosition(instance["x"], instance["y"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   333
            self.AddBlock(leftpowerrail)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   334
            connectors = leftpowerrail.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   335
            for i, connector in enumerate(instance["connectors"]):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   336
                connectors[i].SetPosition(wxPoint(*connector["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   337
        elif instance["type"] == "rightPowerRail":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   338
            rightpowerrail = LD_PowerRail(self, RIGHTRAIL, instance["id"], [True for i in range(len(instance["connectors"]))])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   339
            rightpowerrail.SetPosition(instance["x"], instance["y"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   340
            self.AddBlock(rightpowerrail)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   341
            connectors = rightpowerrail.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   342
            for i, connector in enumerate(instance["connectors"]):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   343
                connectors[i].SetPosition(wxPoint(*connector["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   344
                self.CreateWires(connectors[i], connector["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   345
        elif instance["type"] == "contact":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   346
            if instance["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   347
                negated = instance["negated"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   348
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   349
                negated = False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   350
            if instance["edge"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   351
                edge = instance["edge"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   352
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   353
                edge = "none"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   354
            if negated and edge == "none":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   355
                contact_type = CONTACT_REVERSE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   356
            elif not negated and edge == "rising":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   357
                contact_type = CONTACT_RISING
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   358
            elif not negated and edge == "falling":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   359
                contact_type = CONTACT_FALLING
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   360
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   361
                contact_type = CONTACT_NORMAL
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   362
            contact = LD_Contact(self, contact_type, instance["name"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   363
            contact.SetPosition(instance["x"], instance["y"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   364
            self.AddBlock(contact)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   365
            connectors = contact.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   366
            connectors["input"].SetPosition(wxPoint(*instance["connectors"]["input"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   367
            self.CreateWires(connectors["input"], instance["connectors"]["input"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   368
            connectors["output"].SetPosition(wxPoint(*instance["connectors"]["output"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   369
        elif instance["type"] == "coil":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   370
            if instance["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   371
                negated = instance["negated"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   372
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   373
                negated = False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   374
            if instance["storage"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   375
                storage = instance["storage"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   376
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   377
                storage = "none"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   378
            if negated and storage == "none":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   379
                coil_type = COIL_REVERSE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   380
            elif not negated and storage == "set":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   381
                coil_type = COIL_SET
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   382
            elif not negated and storage == "reset":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   383
                coil_type = COIL_RESET
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   384
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   385
                coil_type = COIL_NORMAL
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   386
            coil = LD_Coil(self, coil_type, instance["name"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   387
            coil.SetPosition(instance["x"], instance["y"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   388
            self.AddBlock(coil)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   389
            connectors = coil.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   390
            connectors["input"].SetPosition(wxPoint(*instance["connectors"]["input"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   391
            self.CreateWires(connectors["input"], instance["connectors"]["input"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   392
            connectors["output"].SetPosition(wxPoint(*instance["connectors"]["output"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   393
        elif instance["type"] == "step":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   394
            if instance["initial"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   395
                initial = instance["initial"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   396
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   397
                initial = False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   398
            step = SFC_Step(self, instance["name"], initial, instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   399
            step.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   400
            step.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   401
            self.AddBlock(step)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   402
            if "output" in instance["connectors"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   403
                step.AddOutput()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   404
            if "action" in instance["connectors"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   405
                step.AddAction()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   406
            connectors = step.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   407
            if connectors["input"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   408
                connectors["input"].SetPosition(wxPoint(*instance["connectors"]["input"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   409
                self.CreateWires(connectors["input"], instance["connectors"]["input"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   410
            if connectors["output"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   411
                connectors["output"].SetPosition(wxPoint(*instance["connectors"]["output"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   412
            if connectors["action"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   413
                connectors["action"].SetPosition(wxPoint(*instance["connectors"]["action"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   414
        elif instance["type"] == "transition":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   415
            transition = SFC_Transition(self, instance["condition_type"], instance["condition"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   416
            transition.SetPosition(instance["x"], instance["y"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   417
            self.AddBlock(transition)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   418
            connectors = transition.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   419
            connectors["input"].SetPosition(wxPoint(*instance["connectors"]["input"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   420
            self.CreateWires(connectors["input"], instance["connectors"]["input"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   421
            connectors["output"].SetPosition(wxPoint(*instance["connectors"]["output"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   422
        elif instance["type"] in ["selectionDivergence", "selectionConvergence", "simultaneousDivergence", "simultaneousConvergence"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   423
            if instance["type"] == "selectionDivergence":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   424
                divergence = SFC_Divergence(self, SELECTION_DIVERGENCE, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   425
                    len(instance["connectors"]["outputs"]), instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   426
            elif instance["type"] == "selectionConvergence":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   427
                divergence = SFC_Divergence(self, SELECTION_CONVERGENCE, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   428
                    len(instance["connectors"]["inputs"]), instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   429
            elif instance["type"] == "simultaneousDivergence":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   430
                divergence = SFC_Divergence(self, SIMULTANEOUS_DIVERGENCE, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   431
                    len(instance["connectors"]["outputs"]), instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   432
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   433
                divergence = SFC_Divergence(self, SIMULTANEOUS_CONVERGENCE, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   434
                    len(instance["connectors"]["inputs"]), instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   435
            divergence.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   436
            divergence.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   437
            self.AddBlock(divergence)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   438
            connectors = divergence.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   439
            for i, input_connector in enumerate(instance["connectors"]["inputs"]):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   440
                connector = connectors["inputs"][i]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   441
                connector.SetPosition(wxPoint(*input_connector["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   442
                self.CreateWires(connector, input_connector["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   443
            for i, output_connector in enumerate(instance["connectors"]["outputs"]):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   444
                connector = connectors["outputs"][i]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   445
                connector.SetPosition(wxPoint(*output_connector["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   446
        elif instance["type"] == "jump":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   447
            jump = SFC_Jump(self, instance["target"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   448
            jump.SetPosition(instance["x"], instance["y"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   449
            self.AddBlock(jump)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   450
            connector = jump.GetConnector()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   451
            connector.SetPosition(wxPoint(*instance["connector"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   452
            self.CreateWires(connector, instance["connector"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   453
        elif instance["type"] == "actionBlock":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   454
            actionBlock = SFC_ActionBlock(self, instance["actions"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   455
            actionBlock.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   456
            actionBlock.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   457
            self.AddBlock(actionBlock)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   458
            connector = actionBlock.GetConnector()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   459
            connector.SetPosition(wxPoint(*instance["connector"]["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   460
            self.CreateWires(connector, instance["connector"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   461
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   462
            if instance["name"] != None:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   463
                block = FBD_Block(self, instance["type"], instance["name"], instance["id"], len(instance["connectors"]["inputs"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   464
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   465
                block = FBD_Block(self, instance["type"], "", instance["id"], len(instance["connectors"]["inputs"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   466
            block.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   467
            block.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   468
            self.AddBlock(block)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   469
            connectors = block.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   470
            for i, input_connector in enumerate(instance["connectors"]["inputs"]):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   471
                connector = connectors["inputs"][i]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   472
                connector.SetPosition(wxPoint(*input_connector["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   473
                if input_connector["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   474
                    connector.SetNegated(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   475
                if input_connector["edge"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   476
                    connector.SetEdge(input_connector["edge"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   477
                self.CreateWires(connector, input_connector["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   478
            for i, output_connector in enumerate(instance["connectors"]["outputs"]):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   479
                connector = connectors["outputs"][i]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   480
                if output_connector["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   481
                    connector.SetNegated(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   482
                if output_connector["edge"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   483
                    connector.SetEdge(output_connector["edge"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   484
                connector.SetPosition(wxPoint(*output_connector["position"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   485
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   486
    def CreateWires(self, start_connector, links, ids):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   487
        for link in links:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   488
            refLocalId = link["refLocalId"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   489
            if refLocalId != None:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   490
                if refLocalId not in ids:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   491
                    new_instance = self.Controler.GetCurrentElementEditingInstanceInfos(refLocalId)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   492
                    if new_instance:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   493
                        self.loadInstance(new_instance, ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   494
                connected = self.FindElementById(refLocalId)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   495
                if connected:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   496
                    points = link["points"]
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   497
                    end_connector = connected.GetConnector(wxPoint(points[-1][0], points[-1][1]), link["formalParameter"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   498
                    if end_connector:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   499
                        wire = Wire(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   500
                        wire.SetPoints(points)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   501
                        start_connector.Connect((wire, 0), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   502
                        end_connector.Connect((wire, -1), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   503
                        wire.ConnectStartPoint(None, start_connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   504
                        wire.ConnectEndPoint(None, end_connector)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   505
                        self.AddWire(wire)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   506
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   507
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   508
#                          Search Element functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   509
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   510
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   511
    def FindBlock(self, pos):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   512
        for block in self.Blocks:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   513
            if block.HitTest(pos) or block.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   514
                return block
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   515
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   516
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   517
    def FindWire(self, pos):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   518
        for wire in self.Wires:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   519
            if wire.HitTest(pos) or wire.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   520
                return wire
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   521
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   522
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   523
    def FindElement(self, pos, exclude_group = False):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   524
        if self.SelectedElement and not (exclude_group and isinstance(self.SelectedElement, Graphic_Group)):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   525
            if self.SelectedElement.HitTest(pos) or self.SelectedElement.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   526
                return self.SelectedElement
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   527
        for element in self.GetElements():
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   528
            if element.HitTest(pos) or element.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   529
                return element
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   530
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   531
    
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   532
    def FindBlockConnector(self, pos, exclude = True):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   533
        for block in self.Blocks:
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   534
            result = block.TestConnector(pos, exclude)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   535
            if result:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   536
                return result
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   537
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   538
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   539
    def FindElementById(self, id):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   540
        for element in self.Blocks:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   541
            if element.GetId() == id:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   542
                return element
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   543
        for element in self.Comments:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   544
            if element.GetId() == id:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   545
                return element
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   546
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   547
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   548
    def SearchElements(self, bbox):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   549
        elements = []
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   550
        for element in self.GetElements():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   551
            if element.IsInSelection(bbox):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   552
                elements.append(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   553
        return elements
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   554
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   555
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   556
#                           Popup menu functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   557
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   558
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   559
    def PopupBlockMenu(self, connector = None):
13
69075340d6a9 Adding support for forbidding insertion of function block into function
lbessard
parents: 10
diff changeset
   560
        type = self.Controler.GetCurrentElementEditingType()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   561
        self.ContextualMenu.FindItemByPosition(0).Enable(connector != None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   562
        self.ContextualMenu.FindItemByPosition(1).Enable(connector != None)
13
69075340d6a9 Adding support for forbidding insertion of function block into function
lbessard
parents: 10
diff changeset
   563
        self.ContextualMenu.FindItemByPosition(2).Enable(connector != None and type != "function")
69075340d6a9 Adding support for forbidding insertion of function block into function
lbessard
parents: 10
diff changeset
   564
        self.ContextualMenu.FindItemByPosition(3).Enable(connector != None and type != "function")
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   565
        self.ContextualMenu.FindItemByPosition(5).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   566
        self.ContextualMenu.FindItemByPosition(6).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   567
        self.ContextualMenu.FindItemByPosition(8).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   568
        self.ContextualMenu.FindItemByPosition(9).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   569
        if connector:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   570
            if connector.IsNegated():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   571
                self.ContextualMenu.FindItemByPosition(1).Check(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   572
            elif connector.GetEdge() == "rising":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   573
                self.ContextualMenu.FindItemByPosition(2).Check(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   574
            elif connector.GetEdge() == "falling":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   575
                self.ContextualMenu.FindItemByPosition(3).Check(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   576
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   577
                self.ContextualMenu.FindItemByPosition(0).Check(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   578
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   579
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   580
    def PopupVariableMenu(self, connector = None):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   581
        self.ContextualMenu.FindItemByPosition(0).Enable(connector != None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   582
        self.ContextualMenu.FindItemByPosition(1).Enable(connector != None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   583
        self.ContextualMenu.FindItemByPosition(2).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   584
        self.ContextualMenu.FindItemByPosition(3).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   585
        self.ContextualMenu.FindItemByPosition(5).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   586
        self.ContextualMenu.FindItemByPosition(6).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   587
        self.ContextualMenu.FindItemByPosition(8).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   588
        self.ContextualMenu.FindItemByPosition(9).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   589
        if connector:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   590
            if connector.IsNegated():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   591
                self.ContextualMenu.FindItemByPosition(1).Check(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   592
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   593
                self.ContextualMenu.FindItemByPosition(0).Check(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   594
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   595
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   596
    def PopupWireMenu(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   597
        self.ContextualMenu.FindItemByPosition(0).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   598
        self.ContextualMenu.FindItemByPosition(1).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   599
        self.ContextualMenu.FindItemByPosition(2).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   600
        self.ContextualMenu.FindItemByPosition(3).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   601
        self.ContextualMenu.FindItemByPosition(5).Enable(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   602
        self.ContextualMenu.FindItemByPosition(6).Enable(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   603
        self.ContextualMenu.FindItemByPosition(8).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   604
        self.ContextualMenu.FindItemByPosition(9).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   605
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   606
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   607
    def PopupDivergenceMenu(self, connector):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   608
        self.ContextualMenu.FindItemByPosition(0).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   609
        self.ContextualMenu.FindItemByPosition(1).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   610
        self.ContextualMenu.FindItemByPosition(2).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   611
        self.ContextualMenu.FindItemByPosition(3).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   612
        self.ContextualMenu.FindItemByPosition(5).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   613
        self.ContextualMenu.FindItemByPosition(6).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   614
        self.ContextualMenu.FindItemByPosition(8).Enable(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   615
        self.ContextualMenu.FindItemByPosition(9).Enable(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   616
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   617
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   618
    def PopupDefaultMenu(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   619
        self.ContextualMenu.FindItemByPosition(0).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   620
        self.ContextualMenu.FindItemByPosition(1).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   621
        self.ContextualMenu.FindItemByPosition(2).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   622
        self.ContextualMenu.FindItemByPosition(3).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   623
        self.ContextualMenu.FindItemByPosition(5).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   624
        self.ContextualMenu.FindItemByPosition(6).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   625
        self.ContextualMenu.FindItemByPosition(8).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   626
        self.ContextualMenu.FindItemByPosition(9).Enable(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   627
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   628
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   629
    def EditCommentContent(self, comment):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   630
        dialog = wxTextEntryDialog(self.Parent, "Edit comment", "Please enter comment text", comment.GetContent(), wxOK|wxCANCEL|wxTE_MULTILINE)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   631
        if dialog.ShowModal() == wxID_OK:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   632
            value = dialog.GetValue()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   633
            comment.SetContent(value)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   634
            infos = {"content" : value}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   635
            infos["width"], infos["height"] = comment.GetSize()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   636
            self.Controler.SetCurrentElementEditingCommentInfos(comment.GetId(), infos)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   637
            self.Refresh()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   638
        dialog.Destroy()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   639
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   640
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   641
#                            Menu items functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   642
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   643
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   644
    def OnNoModifierMenu(self, event):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   645
        if self.SelectedElement and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   646
            self.SelectedElement.SetConnectorNegated(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   647
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   648
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   649
    def OnNegatedMenu(self, event):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   650
        if self.SelectedElement and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   651
            self.SelectedElement.SetConnectorNegated(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   652
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   653
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   654
    def OnRisingEdgeMenu(self, event):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   655
        if self.SelectedElement and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   656
            self.SelectedElement.SetConnectorEdge("rising")
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   657
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   658
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   659
    def OnFallingEdgeMenu(self, event):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   660
        if self.SelectedElement and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   661
            self.SelectedElement.SetConnectorEdge("falling")
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   662
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   663
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   664
    def OnAddSegmentMenu(self, event):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   665
        if self.SelectedElement and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   666
            self.SelectedElement.AddSegment()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   667
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   668
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   669
    def OnDeleteSegmentMenu(self, event):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   670
        if self.SelectedElement and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   671
            self.SelectedElement.DeleteSegment()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   672
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   673
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   674
    def OnAddBranchMenu(self, event):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   675
        if self.SelectedElement and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   676
            self.AddDivergenceBranch(self.SelectedElement)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   677
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   678
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   679
    def OnDeleteBranchMenu(self, event):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   680
        if self.SelectedElement and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   681
            self.RemoveDivergenceBranch(self.SelectedElement)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   682
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   683
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   684
    def OnDeleteMenu(self, event):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   685
        if self.SelectedElement:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   686
            self.SelectedElement.Delete()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   687
            self.SelectedElement = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   688
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   689
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   690
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   691
#                          Mouse event functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   692
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   693
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   694
    def OnViewerLeftDown(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   695
        if self.Mode == MODE_SELECTION:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   696
            dc = self.GetLogicalDC()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   697
            pos = event.GetLogicalPosition(dc)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   698
            if event.ControlDown() and self.SelectedElement:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   699
                element = self.FindElement(pos, True)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   700
                if element:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   701
                    if isinstance(self.SelectedElement, Graphic_Group):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   702
                        self.SelectedElement.SetSelected(False)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   703
                        self.SelectedElement.SelectElement(element)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   704
                    elif self.SelectedElement:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   705
                        group = Graphic_Group(self)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   706
                        group.SelectElement(self.SelectedElement)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   707
                        group.SelectElement(element)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   708
                        self.SelectedElement = group
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   709
                    elements = self.SelectedElement.GetElements()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   710
                    if len(elements) == 0:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   711
                        self.SelectedElement = element
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   712
                    elif len(elements) == 1:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   713
                        self.SelectedElement = elements[0]
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   714
                    self.SelectedElement.SetSelected(True)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   715
            else:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   716
                element = self.FindElement(pos)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   717
                if self.SelectedElement and self.SelectedElement != element:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   718
                    self.SelectedElement.SetSelected(False)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   719
                    self.SelectedElement = None
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   720
                    self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   721
                if element:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   722
                    self.SelectedElement = element
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   723
                    self.SelectedElement.OnLeftDown(event, dc, self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   724
                    self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   725
                else:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   726
                    self.rubberBand.Reset()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   727
                    self.rubberBand.OnLeftDown(event, dc, self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   728
        elif self.Mode in [MODE_BLOCK, MODE_VARIABLE, MODE_CONNECTION, MODE_COMMENT, 
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   729
                           MODE_CONTACT, MODE_COIL, MODE_POWERRAIL, MODE_INITIALSTEP, 
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   730
                           MODE_STEP, MODE_TRANSITION, MODE_DIVERGENCE, MODE_JUMP, MODE_ACTION]:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   731
            self.rubberBand.Reset()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   732
            self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   733
        elif self.Mode == MODE_WIRE:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   734
            pos = GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   735
            connector = self.FindBlockConnector(pos)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   736
            if connector:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   737
                if (connector.GetDirection() == EAST):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   738
                    wire = Wire(self, [wxPoint(pos.x, pos.y), EAST], [wxPoint(pos.x, pos.y), WEST])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   739
                else:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   740
                    wire = Wire(self, [wxPoint(pos.x, pos.y), WEST], [wxPoint(pos.x, pos.y), EAST])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   741
                wire.oldPos = pos
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   742
                wire.Handle = (HANDLE_POINT, 0)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   743
                wire.ProcessDragging(0, 0)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   744
                wire.Handle = (HANDLE_POINT, 1)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   745
                self.AddWire(wire)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   746
                if self.SelectedElement:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   747
                    self.SelectedElement.SetSelected(False)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   748
                self.SelectedElement = wire
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   749
            elif self.SelectedElement:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   750
                self.SelectedElement.SetSelected(False)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   751
                self.SelectedElement = None
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   752
            self.Refresh()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   753
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   754
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   755
    def OnViewerLeftUp(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   756
        if self.rubberBand.IsShown():
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   757
            if self.Mode == MODE_SELECTION:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   758
                elements = self.SearchElements(self.rubberBand.GetCurrentExtent())
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   759
                self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   760
                if len(elements) > 0:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   761
                    self.SelectedElement = Graphic_Group(self)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   762
                    self.SelectedElement.SetElements(elements)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   763
                    self.SelectedElement.SetSelected(True)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   764
                    self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   765
            else:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   766
                bbox = self.rubberBand.GetCurrentExtent()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   767
                self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)                
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   768
                if self.Mode == MODE_BLOCK:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   769
                    wxCallAfter(self.AddNewBlock, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   770
                elif self.Mode == MODE_VARIABLE:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   771
                    wxCallAfter(self.AddNewVariable, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   772
                elif self.Mode == MODE_CONNECTION:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   773
                    wxCallAfter(self.AddNewConnection, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   774
                elif self.Mode == MODE_COMMENT:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   775
                    wxCallAfter(self.AddNewComment, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   776
                elif self.Mode == MODE_CONTACT:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   777
                    wxCallAfter(self.AddNewContact, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   778
                elif self.Mode == MODE_COIL:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   779
                    wxCallAfter(self.AddNewContact, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   780
                elif self.Mode == MODE_POWERRAIL:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   781
                    wxCallAfter(self.AddNewPowerRail, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   782
                elif self.Mode == MODE_INITIALSTEP:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   783
                    wxCallAfter(self.AddNewInitialStep, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   784
                elif self.Mode == MODE_STEP:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   785
                    wxCallAfter(self.AddNewStep, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   786
                elif self.Mode == MODE_TRANSITION:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   787
                    wxCallAfter(self.AddNewTransition, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   788
                elif self.Mode == MODE_DIVERGENCE:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   789
                    wxCallAfter(self.AddNewDivergence, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   790
                elif self.Mode == MODE_JUMP:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   791
                    wxCallAfter(self.AddNewJump, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   792
                elif self.Mode == MODE_ACTION:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   793
                    wxCallAfter(self.AddNewActionBlock, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   794
        elif self.Mode == MODE_SELECTION and self.SelectedElement:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   795
            self.SelectedElement.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   796
            wxCallAfter(self.SetCursor, wxNullCursor)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   797
            self.ReleaseMouse()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   798
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   799
        elif self.Mode == MODE_WIRE and self.SelectedElement:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   800
            if self.SelectedElement.EndConnected != None:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   801
                self.SelectedElement.ResetPoints()
45
42637f721b5b Bugs fixed
lbessard
parents: 42
diff changeset
   802
                self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   803
                self.SelectedElement.GeneratePoints()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   804
                self.SelectedElement.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   805
                self.SelectedElement.SetSelected(True)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   806
            else:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   807
                self.SelectedElement.Delete()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   808
                self.SelectedElement = None
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   809
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   810
        if not self.SavedMode:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   811
            wxCallAfter(self.Parent.ResetCurrentMode)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   812
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   813
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   814
    def OnViewerRightUp(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   815
        pos = event.GetPosition()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   816
        element = self.FindElement(pos)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   817
        if element:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   818
            if self.SelectedElement and self.SelectedElement != element:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   819
                self.SelectedElement.SetSelected(False)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   820
            self.SelectedElement = element
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   821
            self.SelectedElement.SetSelected(True)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   822
            self.SelectedElement.OnRightUp(event, self.GetLogicalDC(), self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   823
            wxCallAfter(self.SetCursor, wxNullCursor)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   824
            self.ReleaseMouse()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   825
            self.Refresh()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   826
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   827
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   828
    def OnViewerLeftDClick(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   829
        if self.Mode == MODE_SELECTION and self.SelectedElement:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   830
            self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   831
            self.Refresh()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   832
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   833
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   834
    def OnViewerMotion(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   835
        if self.rubberBand.IsShown():
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   836
            self.rubberBand.OnMotion(event, self.GetLogicalDC(), self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   837
        elif self.Mode == MODE_SELECTION and self.SelectedElement:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   838
            self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   839
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   840
        elif self.Mode == MODE_WIRE and self.SelectedElement:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   841
            dc = self.GetLogicalDC()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   842
            pos = GetScaledEventPosition(event, dc, self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   843
            connector = self.FindBlockConnector(pos, False)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   844
            if not connector or self.SelectedElement.EndConnected == None:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   845
                self.SelectedElement.ResetPoints()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   846
                self.SelectedElement.OnMotion(event, dc, self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   847
                self.SelectedElement.GeneratePoints()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   848
                self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   849
        if (event.Dragging() and self.SelectedElement) or self.rubberBand.IsShown():
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   850
            position = event.GetPosition()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   851
            move_window = wxPoint()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   852
            window_size = self.GetClientSize()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   853
            xstart, ystart = self.GetViewStart()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   854
            if position.x < SCROLL_ZONE and xstart > 0:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   855
                move_window.x = -1
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   856
            elif position.x > window_size[0] - SCROLL_ZONE:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   857
                move_window.x = 1
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   858
            if position.y < SCROLL_ZONE and ystart > 0:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   859
                move_window.y = -1
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   860
            elif position.y > window_size[1] - SCROLL_ZONE:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   861
                move_window.y = 1
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   862
            if move_window.x != 0 or move_window.y != 0:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   863
                self.Scroll(xstart + move_window.x, ystart + move_window.y)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   864
            self.RefreshScrollBars()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   865
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   866
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   867
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   868
#                          Keyboard event functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   869
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   870
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   871
    def OnChar(self, event):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   872
        xpos, ypos = self.GetScrollPos(wxHORIZONTAL), self.GetScrollPos(wxVERTICAL)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   873
        xmax = self.GetScrollRange(wxHORIZONTAL) - self.GetScrollThumb(wxHORIZONTAL)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   874
        ymax = self.GetScrollRange(wxVERTICAL) - self.GetScrollThumb(wxVERTICAL)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   875
        keycode = event.GetKeyCode()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   876
        if self.Scaling:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   877
            scaling = self.Scaling
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   878
        else:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   879
            scaling = (8, 8)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   880
        if keycode == WXK_DELETE and self.SelectedElement:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   881
            self.SelectedElement.Clean()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   882
            self.SelectedElement.Delete()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   883
            self.SelectedElement = None
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   884
        elif keycode == WXK_LEFT:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   885
            if event.ControlDown() and event.ShiftDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   886
                self.Scroll(0, ypos)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   887
            elif event.ControlDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   888
                self.Scroll(max(0, xpos - 1), ypos)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   889
            elif self.SelectedElement:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   890
                self.SelectedElement.Move(-scaling[0], 0)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   891
        elif keycode == WXK_RIGHT:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   892
            if event.ControlDown() and event.ShiftDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   893
                self.Scroll(xmax, ypos)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   894
            elif event.ControlDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   895
                self.Scroll(min(xpos + 1, xmax), ypos)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   896
            elif self.SelectedElement:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   897
                self.SelectedElement.Move(scaling[0], 0)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   898
        elif keycode == WXK_UP:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   899
            if event.ControlDown() and event.ShiftDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   900
                self.Scroll(xpos, 0)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   901
            elif event.ControlDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   902
                self.Scroll(xpos, max(0, ypos - 1))
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   903
            elif self.SelectedElement:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   904
                self.SelectedElement.Move(0, -scaling[1])
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   905
        elif keycode == WXK_DOWN:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   906
            if event.ControlDown() and event.ShiftDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   907
                self.Scroll(xpos, ymax)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   908
            elif event.ControlDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   909
                self.Scroll(xpos, min(ypos + 1, ymax))
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   910
            elif self.SelectedElement:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   911
                self.SelectedElement.Move(0, scaling[1])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   912
        self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   913
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   914
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   915
#                          Model adding functions
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   916
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   917
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   918
    def AddNewBlock(self, bbox):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   919
        dialog = BlockPropertiesDialog(self.Parent)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   920
        dialog.SetBlockList(self.Controler.GetBlockTypes())
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   921
        dialog.SetMinBlockSize((bbox.width, bbox.height))
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   922
        if dialog.ShowModal() == wxID_OK:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   923
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   924
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   925
            if "name" in values:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   926
                block = FBD_Block(self, values["type"], values["name"], id, values["extension"], values["inputs"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   927
            else:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   928
                block = FBD_Block(self, values["type"], "", id, values["extension"], values["inputs"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   929
            block.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   930
            block.SetSize(values["width"], values["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   931
            self.AddBlock(block)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   932
            self.Controler.AddCurrentElementEditingBlock(id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   933
            self.RefreshBlockModel(block)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   934
            self.RefreshScrollBars()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   935
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   936
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   937
    
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   938
    def AddNewVariable(self, bbox):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   939
        dialog = VariablePropertiesDialog(self.Parent)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   940
        dialog.SetMinVariableSize((bbox.width, bbox.height))
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   941
        varlist = []
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   942
        vars = self.Controler.GetCurrentElementEditingInterfaceVars()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   943
        if vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   944
            for var in vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   945
                varlist.append((var["Name"], var["Class"], var["Type"]))
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   946
        returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   947
        if returntype:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   948
            varlist.append((self.Controler.GetCurrentElementEditingName(), "Output", returntype))
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   949
        dialog.SetVariables(varlist)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   950
        if dialog.ShowModal() == wxID_OK:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   951
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   952
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   953
            variable = FBD_Variable(self, values["type"], values["name"], values["value_type"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   954
            variable.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   955
            variable.SetSize(values["width"], values["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   956
            self.AddBlock(variable)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   957
            self.Controler.AddCurrentElementEditingVariable(id, values["type"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   958
            self.RefreshVariableModel(variable)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   959
            self.RefreshScrollBars()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   960
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   961
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   962
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   963
    def AddNewConnection(self, bbox):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   964
        dialog = ConnectionPropertiesDialog(self.Parent)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   965
        dialog.SetMinConnectionSize((bbox.width, bbox.height))
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   966
        if dialog.ShowModal() == wxID_OK:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   967
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   968
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   969
            connection = FBD_Connector(self, values["type"], values["name"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   970
            connection.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   971
            connection.SetSize(values["width"], values["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   972
            self.AddBlock(connection)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   973
            self.Controler.AddCurrentElementEditingConnection(id, values["type"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   974
            self.RefreshConnectionModel(connection)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   975
            self.RefreshScrollBars()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   976
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   977
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   978
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   979
    def AddNewComment(self, bbox):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   980
        dialog = wxTextEntryDialog(self.Parent, "Add a new comment", "Please enter comment text", "", wxOK|wxCANCEL|wxTE_MULTILINE)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   981
        if dialog.ShowModal() == wxID_OK:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   982
            value = dialog.GetValue()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   983
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   984
            comment = Comment(self, value, id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   985
            comment.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   986
            min_width, min_height = comment.GetMinSize()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   987
            comment.SetSize(max(min_width,bbox.width),max(min_height,bbox.height))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   988
            self.AddComment(comment)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   989
            self.Controler.AddCurrentElementEditingComment(id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   990
            self.RefreshCommentModel(comment)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   991
            self.RefreshScrollBars()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   992
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   993
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   994
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   995
    def AddNewContact(self, bbox):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   996
        dialog = LDElementDialog(self.Parent, "contact")
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   997
        varlist = []
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   998
        vars = self.Controler.GetCurrentElementEditingInterfaceVars()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   999
        if vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1000
            for var in vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1001
                if var["Class"] != "Output" and var["Type"] == "BOOL":
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1002
                    varlist.append(var["Name"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1003
        dialog.SetVariables(varlist)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1004
        dialog.SetValues({"name":"","type":CONTACT_NORMAL})
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1005
        dialog.SetElementSize((bbox.width, bbox.height))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1006
        if dialog.ShowModal() == wxID_OK:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1007
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1008
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1009
            contact = LD_Contact(self, values["type"], values["name"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1010
            contact.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1011
            contact.SetSize(values["width"], values["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1012
            self.AddBlock(contact)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1013
            self.Controler.AddCurrentElementEditingContact(id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1014
            self.RefreshContactModel(contact)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1015
            self.RefreshScrollBars()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1016
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1017
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1018
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1019
    def AddNewCoil(self, bbox):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1020
        dialog = LDElementDialog(self.Parent, "coil")
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1021
        varlist = []
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1022
        vars = self.Controler.GetCurrentElementEditingInterfaceVars()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1023
        if vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1024
            for var in vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1025
                if var["Class"] != "Input" and var["Type"] == "BOOL":
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1026
                    varlist.append(var["Name"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1027
        returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1028
        if returntype == "BOOL":
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1029
            varlist.append(self.Controler.GetCurrentElementEditingName())
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1030
        dialog.SetVariables(varlist)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1031
        dialog.SetValues({"name":"","type":COIL_NORMAL})
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1032
        dialog.SetElementSize((bbox.width, bbox.height))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1033
        if dialog.ShowModal() == wxID_OK:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1034
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1035
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1036
            coil = LD_Coil(self, values["type"], values["name"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1037
            coil.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1038
            coil.SetSize(values["width"], values["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1039
            self.AddBlock(coil)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1040
            self.Controler.AddCurrentElementEditingCoil(id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1041
            self.RefreshCoilModel(contact)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1042
            self.RefreshScrollBars()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1043
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1044
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1045
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1046
    def AddNewPowerRail(self, bbox):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1047
        dialog = LDPowerRailDialog(self.Parent)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1048
        dialog.SetMinSize((bbox.width, bbox.height))
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1049
        if dialog.ShowModal() == wxID_OK:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1050
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1051
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1052
            powerrail = LD_PowerRail(self, values["type"], id, [True for i in xrange(values["number"])])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1053
            powerrail.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1054
            powerrail.SetSize(values["width"], values["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1055
            self.AddBlock(powerrail)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1056
            self.Controler.AddCurrentElementEditingPowerRail(id, values["type"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1057
            self.RefreshPowerRailModel(powerrail)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1058
            self.RefreshScrollBars()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1059
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1060
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1061
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1062
    def AddNewTransition(self, bbox):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1063
        dialog = TransitionContentDialog(self.Parent)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1064
        dialog.SetTransitions(self.Controler.GetCurrentElementEditingTransitions())
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1065
        if dialog.ShowModal() == wxID_OK:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1066
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1067
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1068
            transition = SFC_Transition(self, values["type"], values["value"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1069
            transition.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1070
            min_width, min_height = transition.GetMinSize()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1071
            transition.SetSize(max(bbox.width, min_width), max(bbox.height, min_height))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1072
            self.AddBlock(transition)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1073
            self.Controler.AddCurrentElementEditingTransition(id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1074
            self.RefreshTransitionModel(transition)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1075
            self.RefreshScrollBars()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1076
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1077
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1078
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1079
    def AddNewDivergence(self, bbox):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1080
        dialog = DivergenceCreateDialog(self.Parent)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1081
        dialog.SetMinSize((bbox.width, bbox.height))
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1082
        if dialog.ShowModal() == wxID_OK:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1083
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1084
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1085
            divergence = SFC_Divergence(self, values["type"], values["number"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1086
            divergence.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1087
            min_width, min_height = divergence.GetMinSize()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1088
            divergence.SetSize(max(bbox.width, min_width), max(bbox.height, min_height))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1089
            self.AddBlock(divergence)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1090
            self.Controler.AddCurrentElementEditingDivergence(id, values["type"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1091
            self.RefreshDivergenceModel(divergence)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1092
            self.RefreshScrollBars()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1093
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1094
        dialog.Destroy()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1095
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1096
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1097
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1098
#                          Edit element content functions
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1099
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1100
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1101
    def EditBlockContent(self, block):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1102
        dialog = BlockPropertiesDialog(self.Parent)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1103
        dialog.SetBlockList(self.Controler.GetBlockTypes())
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1104
        dialog.SetMinBlockSize(block.GetSize())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1105
        values = {"name" : block.GetName(), "type" : block.GetType(), "inputs" : block.GetInputTypes()}
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1106
        values["extension"] = block.GetExtension()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1107
        dialog.SetValues(values)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1108
        if dialog.ShowModal() == wxID_OK:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1109
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1110
            if "name" in values:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1111
                block.SetName(values["name"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1112
            block.SetSize(values["width"], values["height"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1113
            block.SetType(values["type"], values["extension"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1114
            self.RefreshBlockModel(block)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1115
            self.RefreshScrollBars()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1116
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1117
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1118
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1119
    def EditVariableContent(self, variable):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1120
        dialog = VariablePropertiesDialog(self.Parent)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1121
        dialog.SetMinVariableSize(variable.GetSize())
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1122
        varlist = []
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1123
        vars = self.Controler.GetCurrentElementEditingInterfaceVars()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1124
        if vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1125
            for var in vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1126
                varlist.append((var["Name"], var["Class"], var["Type"]))
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1127
        returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1128
        if returntype:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1129
            varlist.append((self.Controler.GetCurrentElementEditingName(), "Output", returntype))
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1130
        dialog.SetVariables(varlist)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1131
        values = {"name" : variable.GetName(), "type" : variable.GetType()}
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1132
        dialog.SetValues(values)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1133
        if dialog.ShowModal() == wxID_OK:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1134
            old_type = variable.GetType()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1135
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1136
            variable.SetName(values["name"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1137
            variable.SetType(values["type"], values["value_type"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1138
            variable.SetSize(values["width"], values["height"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1139
            if old_type != values["type"]:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1140
                id = variable.GetId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1141
                self.Controler.RemoveCurrentElementEditingInstance(id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1142
                self.Controler.AddCurrentElementEditingVariable(id, values["type"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1143
            self.RefreshVariableModel(variable)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1144
            self.RefreshScrollBars()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1145
            self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1146
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1147
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1148
    def EditConnectionContent(self, connection):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1149
        dialog = ConnectionPropertiesDialog(self.Parent)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1150
        dialog.SetMinConnectionSize(connection.GetSize())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1151
        values = {"name" : connection.GetName(), "type" : connection.GetType()}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1152
        dialog.SetValues(values)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1153
        if dialog.ShowModal() == wxID_OK:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1154
            old_type = connection.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1155
            values = dialog.GetValues()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1156
            connection.SetName(values["name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1157
            connection.SetType(values["type"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1158
            connection.SetSize(values["width"], values["height"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1159
            if old_type != values["type"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1160
                id = connection.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1161
                self.Controler.RemoveCurrentElementEditingInstance(id)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1162
                self.Controler.AddCurrentElementEditingConnection(id, values["type"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1163
            self.RefreshConnectionModel(connection)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1164
            self.RefreshScrollBars()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1165
            self.Refresh()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1166
        dialog.Destroy()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1167
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1168
    def EditContactContent(self, contact):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1169
        dialog = LDElementDialog(self.Parent, "contact")
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1170
        varlist = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1171
        vars = self.Controler.GetCurrentElementEditingInterfaceVars()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1172
        if vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1173
            for var in vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1174
                if var["Class"] != "Output" and var["Type"] == "BOOL":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1175
                    varlist.append(var["Name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1176
        dialog.SetVariables(varlist)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1177
        values = {"name" : contact.GetName(), "type" : contact.GetType()}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1178
        dialog.SetValues(values)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1179
        dialog.SetElementSize(contact.GetSize())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1180
        if dialog.ShowModal() == wxID_OK:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1181
            values = dialog.GetValues()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1182
            contact.SetName(values["name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1183
            contact.SetType(values["type"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1184
            contact.SetSize(values["width"], values["height"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1185
            self.RefreshContactModel(contact)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1186
            self.RefreshScrollBars()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1187
            self.Refresh()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1188
        dialog.Destroy()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1189
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1190
    def EditCoilContent(self, coil):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1191
        dialog = LDElementDialog(self.Parent, "coil")
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1192
        varlist = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1193
        vars = self.Controler.GetCurrentElementEditingInterfaceVars()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1194
        if vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1195
            for var in vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1196
                if var["Class"] != "Input" and var["Type"] == "BOOL":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1197
                    varlist.append(var["Name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1198
        returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1199
        if returntype == "BOOL":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1200
            varlist.append(self.Controler.GetCurrentElementEditingName())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1201
        dialog.SetVariables(varlist)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1202
        values = {"name" : coil.GetName(), "type" : coil.GetType()}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1203
        dialog.SetValues(values)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1204
        dialog.SetElementSize(contact.GetSize())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1205
        if dialog.ShowModal() == wxID_OK:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1206
            values = dialog.GetValues()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1207
            coil.SetName(values["name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1208
            coil.SetType(values["type"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1209
            coil.SetSize(values["width"], values["height"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1210
            self.RefreshContactModel(coil)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1211
            self.RefreshScrollBars()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1212
            self.Refresh()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1213
        dialog.Destroy()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1214
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1215
    def EditPowerRailContent(self, powerrail):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1216
        dialog = LDPowerRailDialog(self.Parent, powerrail.GetType(), len(powerrail.GetConnectors()))
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1217
        dialog.SetMinSize(powerrail.GetSize())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1218
        if dialog.ShowModal() == wxID_OK:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1219
            old_type = powerrail.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1220
            values = dialog.GetValues()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1221
            powerrail.SetType(values["type"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1222
            powerrail.SetSize(values["width"], values["height"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1223
            if old_type != values["type"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1224
                id = powerrail.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1225
                self.Controler.RemoveCurrentElementEditingInstance(id)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1226
                self.Controler.AddCurrentElementEditingPowerRail(id, values["type"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1227
            self.RefreshPowerRailModel(powerrail)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1228
            self.RefreshScrollBars()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1229
            self.Refresh()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1230
        dialog.Destroy()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1231
##
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1232
##
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1233
##    def AddNewTransition(self, bbox):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1234
##        dialog = TransitionContentDialog(self.Parent)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1235
##        dialog.SetTransitions(self.Controler.GetCurrentElementEditingTransitions())
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1236
##        if dialog.ShowModal() == wxID_OK:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1237
##            id = self.GetNewId()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1238
##            values = dialog.GetValues()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1239
##            transition = SFC_Transition(self, values["type"], values["value"], id)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1240
##            transition.SetPosition(bbox.x, bbox.y)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1241
##            min_width, min_height = transition.GetMinSize()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1242
##            transition.SetSize(max(bbox.width, min_width), max(bbox.height, min_height))
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1243
##            self.Blocks.append(transition)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1244
##            self.Elements.append(transition)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1245
##            self.Controler.AddCurrentElementEditingTransition(id)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1246
##            self.RefreshTransitionModel(transition)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1247
##            self.RefreshScrollBars()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1248
##            self.Refresh()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1249
##        dialog.Destroy()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1250
##
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1251
##    def AddNewDivergence(self, bbox):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1252
##        dialog = DivergenceCreateDialog(self.Parent)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1253
##        dialog.SetMinSize((bbox.width, bbox.height))
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1254
##        if dialog.ShowModal() == wxID_OK:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1255
##            id = self.GetNewId()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1256
##            values = dialog.GetValues()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1257
##            divergence = SFC_Divergence(self, values["type"], values["number"], id)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1258
##            divergence.SetPosition(bbox.x, bbox.y)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1259
##            min_width, min_height = divergence.GetMinSize()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1260
##            divergence.SetSize(max(bbox.width, min_width), max(bbox.height, min_height))
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1261
##            self.Blocks.append(divergence)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1262
##            self.Elements.append(divergence)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1263
##            self.Controler.AddCurrentElementEditingDivergence(id, values["type"])
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1264
##            self.RefreshDivergenceModel(divergence)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1265
##            self.RefreshScrollBars()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1266
##            self.Refresh()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1267
##        dialog.Destroy()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1268
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1269
#-------------------------------------------------------------------------------
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1270
#                          Model update functions
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1271
#-------------------------------------------------------------------------------
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1272
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1273
    def RefreshBlockModel(self, block):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1274
        blockid = block.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1275
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1276
        infos["type"] = block.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1277
        infos["name"] = block.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1278
        infos["x"], infos["y"] = block.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1279
        infos["width"], infos["height"] = block.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1280
        infos["connectors"] = block.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1281
        self.Controler.SetCurrentElementEditingBlockInfos(blockid, infos)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1282
    
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1283
    def RefreshVariableModel(self, variable):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1284
        variableid = variable.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1285
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1286
        infos["name"] = variable.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1287
        infos["x"], infos["y"] = variable.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1288
        infos["width"], infos["height"] = variable.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1289
        infos["connectors"] = variable.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1290
        self.Controler.SetCurrentElementEditingVariableInfos(variableid, infos)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1291
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1292
    def RefreshConnectionModel(self, connection):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1293
        connectionid = connection.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1294
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1295
        infos["name"] = connection.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1296
        infos["x"], infos["y"] = connection.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1297
        infos["width"], infos["height"] = connection.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1298
        infos["connector"] = connection.GetConnector()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1299
        self.Controler.SetCurrentElementEditingConnectionInfos(connectionid, infos)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1300
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1301
    def RefreshCommentModel(self, comment):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1302
        commentid = comment.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1303
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1304
        infos["content"] = comment.GetContent()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1305
        infos["x"], infos["y"] = comment.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1306
        infos["width"], infos["height"] = comment.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1307
        self.Controler.SetCurrentElementEditingCommentInfos(commentid, infos)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1308
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1309
    def RefreshPowerRailModel(self, powerrail):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1310
        powerrailid = powerrail.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1311
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1312
        infos["x"], infos["y"] = powerrail.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1313
        infos["width"], infos["height"] = powerrail.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1314
        infos["connectors"] = powerrail.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1315
        self.Controler.SetCurrentElementEditingPowerRailInfos(powerrailid, infos)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1316
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1317
    def RefreshContactModel(self, contact):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1318
        contactid = contact.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1319
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1320
        infos["name"] = contact.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1321
        infos["type"] = contact.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1322
        infos["x"], infos["y"] = contact.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1323
        infos["width"], infos["height"] = contact.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1324
        infos["connectors"] = contact.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1325
        self.Controler.SetCurrentElementEditingContactInfos(contactid, infos)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1326
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1327
    def RefreshCoilModel(self, coil):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1328
        coilid = coil.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1329
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1330
        infos["name"] = coil.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1331
        infos["type"] = coil.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1332
        infos["x"], infos["y"] = coil.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1333
        infos["width"], infos["height"] = coil.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1334
        infos["connectors"] = coil.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1335
        self.Controler.SetCurrentElementEditingCoilInfos(coilid, infos)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1336
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1337
    def RefreshStepModel(self, step):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1338
        stepid = step.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1339
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1340
        infos["name"] = step.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1341
        infos["initial"] = step.GetInitial()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1342
        infos["x"], infos["y"] = step.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1343
        infos["width"], infos["height"] = step.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1344
        infos["connectors"] = step.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1345
        self.Controler.SetCurrentElementEditingStepInfos(stepid, infos)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1346
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1347
    def RefreshTransitionModel(self, transition):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1348
        transitionid = transition.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1349
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1350
        infos["type"] = transition.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1351
        infos["condition"] = transition.GetCondition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1352
        infos["x"], infos["y"] = transition.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1353
        infos["width"], infos["height"] = transition.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1354
        infos["connectors"] = transition.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1355
        self.Controler.SetCurrentElementEditingTransitionInfos(transitionid, infos)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1356
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1357
    def RefreshDivergenceModel(self, divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1358
        divergenceid = divergence.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1359
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1360
        infos["x"], infos["y"] = divergence.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1361
        infos["width"], infos["height"] = divergence.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1362
        infos["connectors"] = divergence.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1363
        self.Controler.SetCurrentElementEditingDivergenceInfos(divergenceid, infos)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1364
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1365
    def RefreshJumpModel(self, jump):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1366
        jumpid = jump.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1367
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1368
        infos["target"] = jump.GetTarget()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1369
        infos["x"], infos["y"] = jump.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1370
        infos["width"], infos["height"] = jump.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1371
        infos["connector"] = jump.GetConnector()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1372
        self.Controler.SetCurrentElementEditingJumpInfos(jumpid, infos)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1373
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1374
    def RefreshActionBlockModel(self, actionblock):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1375
        actionblockid = actionblock.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1376
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1377
        infos["actions"] = actionblock.GetActions()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1378
        infos["x"], infos["y"] = actionblock.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1379
        infos["width"], infos["height"] = actionblock.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1380
        infos["connector"] = actionblock.GetConnector()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1381
        self.Controler.SetCurrentElementEditingActionBlockInfos(actionblockid, infos)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1382
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1383
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1384
#-------------------------------------------------------------------------------
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1385
#                          Model delete functions
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1386
#-------------------------------------------------------------------------------
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1387
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1388
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1389
    def DeleteBlock(self, block):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1390
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1391
        for output in block.GetConnectors()["outputs"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1392
            for element in output.GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1393
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1394
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1395
        block.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1396
        self.RemoveBlock(block)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1397
        self.Controler.RemoveCurrentElementEditingInstance(block.GetId())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1398
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1399
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1400
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1401
    def DeleteVariable(self, variable):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1402
        connectors = variable.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1403
        if connectors["output"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1404
            elements = connectors["output"].GetConnectedBlocks()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1405
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1406
            elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1407
        variable.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1408
        self.RemoveBlock(variable)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1409
        self.Controler.RemoveCurrentElementEditingInstance(variable.GetId())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1410
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1411
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1412
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1413
    def DeleteConnection(self, connection):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1414
        if connection.GetType() == CONTINUATION:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1415
            elements = connection.GetConnector().GetConnectedBlocks()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1416
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1417
            elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1418
        connection.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1419
        self.RemoveBlock(connection)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1420
        self.Controler.RemoveCurrentElementEditingInstance(connection.GetId())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1421
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1422
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1423
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1424
    def DeleteComment(self, comment):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1425
        self.RemoveComment(comment)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1426
        self.Controler.RemoveCurrentElementEditingInstance(comment.GetId())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1427
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1428
    def DeleteWire(self, wire):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1429
        if wire in self.Wires:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1430
            connected = wire.GetConnected()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1431
            wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1432
            self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1433
            for connector in connected:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1434
                connector.RefreshParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1435
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1436
    def DeleteContact(self, contact):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1437
        connectors = contact.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1438
        elements = connectors["output"].GetConnectedBlocks()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1439
        contact.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1440
        self.RemoveBlock(contact)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1441
        self.Controler.RemoveCurrentElementEditingInstance(contact.GetId())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1442
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1443
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1444
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1445
    def DeleteCoil(self, coil):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1446
        connectors = coil.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1447
        elements = connectors["output"].GetConnectedBlocks()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1448
        coil.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1449
        self.RemoveBlock(coil)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1450
        self.Controler.RemoveCurrentElementEditingInstance(coil.GetId())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1451
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1452
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1453
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1454
    def DeletePowerRail(self, powerrail):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1455
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1456
        if powerrail.GetType() == LEFTRAIL:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1457
            for connector in powerrail.GetConnectors():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1458
                for element in connector.GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1459
                    if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1460
                        elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1461
        powerrrail.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1462
        self.RemoveBlock(powerrrail)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1463
        self.Controler.RemoveCurrentElementEditingInstance(powerrrail.GetId())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1464
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1465
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1466
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1467
    def DeleteStep(self, step):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1468
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1469
        connectors = step.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1470
        if connectors["output"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1471
            for element in connectors["output"].GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1472
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1473
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1474
        if connectors["action"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1475
            for element in connectors["action"].GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1476
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1477
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1478
        step.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1479
        self.RemoveBlock(step)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1480
        self.Controler.RemoveCurrentElementEditingInstance(step.GetId())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1481
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1482
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1483
            
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1484
    def DeleteTransition(self, transition):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1485
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1486
        connectors = transition.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1487
        if connectors["output"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1488
            for element in connectors["output"].GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1489
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1490
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1491
        transition.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1492
        self.RemoveBlock(transition)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1493
        self.Controler.RemoveCurrentElementEditingInstance(transition.GetId())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1494
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1495
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1496
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1497
    def DeleteDivergence(self, divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1498
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1499
        connectors = divergence.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1500
        for output in connectors["outputs"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1501
            for element in output.GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1502
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1503
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1504
        divergence.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1505
        self.RemoveBlock(divergence)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1506
        self.Controler.RemoveCurrentElementEditingInstance(divergence.GetId())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1507
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1508
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1509
    
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1510
    def DeleteJump(self, jump):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1511
        jump.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1512
        self.RemoveBlock(jump)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1513
        self.Controler.RemoveCurrentElementEditingInstance(jump.GetId())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1514
    
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1515
    def DeleteActionBlock(self, actionblock):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1516
        actionblock.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1517
        self.RemoveBlock(actionblock)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1518
        self.Controler.RemoveCurrentElementEditingInstance(actionblock.GetId())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1519
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1520
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1521
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1522
#                            Editing functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1523
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1524
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1525
    def Cut(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1526
        pass
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1527
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1528
    def Copy(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1529
        pass
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1530
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1531
    def Paste(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1532
        pass
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1533
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1534
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1535
#                            Drawing functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1536
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1537
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1538
    def OnMoveWindow(self, event):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1539
        self.RefreshScrollBars()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1540
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1541
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1542
    def OnPaint(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1543
        dc = self.GetLogicalDC()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1544
        dc.Clear()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1545
        dc.SetPen(wxPen(wxColour(230, 230, 230)))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1546
        if self.Scaling and self.DrawGrid:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1547
            width, height = dc.GetSize()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1548
            for i in xrange(1, width / self.Scaling[0] + 1):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1549
                dc.DrawLine(i * self.Scaling[0], 0, i * self.Scaling[0], height)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1550
            for i in xrange(1, height / self.Scaling[1] + 1):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1551
                dc.DrawLine(0, i * self.Scaling[1], width, i * self.Scaling[1])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1552
        for comment in self.Comments:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1553
            if comment != self.SelectedElement:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1554
                comment.Draw(dc)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1555
        for wire in self.Wires:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1556
            if wire != self.SelectedElement:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1557
                wire.Draw(dc)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1558
        for block in self.Blocks:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1559
            if block != self.SelectedElement:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1560
                block.Draw(dc)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1561
        if self.SelectedElement:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1562
            self.SelectedElement.Draw(dc)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1563
        if self.rubberBand.IsShown():
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1564
            self.rubberBand.Draw()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1565
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1566
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1567