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