1 #!/usr/bin/env python |
1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- |
2 # -*- coding: utf-8 -*- |
3 |
3 |
4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
4 # This file is part of Beremiz, a Integrated Development Environment for |
5 #based on the plcopen standard. |
5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
6 # |
6 # |
7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
8 # |
8 # |
9 #See COPYING file for copyrights details. |
9 # See COPYING file for copyrights details. |
10 # |
10 # |
11 #This library is free software; you can redistribute it and/or |
11 # This program is free software; you can redistribute it and/or |
12 #modify it under the terms of the GNU General Public |
12 # modify it under the terms of the GNU General Public License |
13 #License as published by the Free Software Foundation; either |
13 # as published by the Free Software Foundation; either version 2 |
14 #version 2.1 of the License, or (at your option) any later version. |
14 # of the License, or (at your option) any later version. |
15 # |
15 # |
16 #This library is distributed in the hope that it will be useful, |
16 # This program is distributed in the hope that it will be useful, |
17 #but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 #General Public License for more details. |
19 # GNU General Public License for more details. |
20 # |
20 # |
21 #You should have received a copy of the GNU General Public |
21 # You should have received a copy of the GNU General Public License |
22 #License along with this library; if not, write to the Free Software |
22 # along with this program; if not, write to the Free Software |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 from types import * |
25 from types import * |
26 |
26 |
27 import wx |
27 import wx |
28 |
28 |
29 from Viewer import * |
29 from Viewer import * |
|
30 from graphics.SFC_Objects import * |
|
31 from graphics.GraphicCommons import SELECTION_DIVERGENCE, \ |
|
32 SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE, EAST, NORTH, WEST, SOUTH |
|
33 |
|
34 SFC_Objects = (SFC_Step, SFC_ActionBlock, SFC_Transition, SFC_Divergence, SFC_Jump) |
|
35 |
30 |
36 |
31 class SFC_Viewer(Viewer): |
37 class SFC_Viewer(Viewer): |
32 |
38 |
|
39 SFC_StandardRules = { |
|
40 # The key of this dict is a block that user try to connect, |
|
41 # and the value is a list of blocks, that can be connected with the current block |
|
42 # and with directions of connection |
|
43 "SFC_Step": [("SFC_ActionBlock", EAST), |
|
44 ("SFC_Transition", SOUTH), |
|
45 (SELECTION_DIVERGENCE, SOUTH), |
|
46 (SIMULTANEOUS_CONVERGENCE, SOUTH)], |
|
47 |
|
48 "SFC_ActionBlock": [("SFC_Step", EAST)], |
|
49 |
|
50 "SFC_Transition": [("SFC_Step", SOUTH), |
|
51 (SELECTION_CONVERGENCE, SOUTH), |
|
52 (SIMULTANEOUS_DIVERGENCE, SOUTH), |
|
53 ("SFC_Jump", SOUTH), |
|
54 ("FBD_Block", EAST), |
|
55 ("FBD_Variable", EAST), |
|
56 ("FBD_Connector", EAST), |
|
57 ("LD_Contact", EAST), |
|
58 ("LD_PowerRail", EAST), |
|
59 ("LD_Coil", EAST)], |
|
60 |
|
61 SELECTION_DIVERGENCE: [("SFC_Transition", SOUTH)], |
|
62 |
|
63 SELECTION_CONVERGENCE: [("SFC_Step", SOUTH), |
|
64 ("SFC_Jump", SOUTH)], |
|
65 |
|
66 SIMULTANEOUS_DIVERGENCE: [("SFC_Step", SOUTH)], |
|
67 |
|
68 SIMULTANEOUS_CONVERGENCE: [("SFC_Transition", SOUTH)], |
|
69 |
|
70 "SFC_Jump": [], |
|
71 |
|
72 "FBD_Block": [("SFC_Transition", WEST)], |
|
73 |
|
74 "FBD_Variable": [("SFC_Transition", WEST)], |
|
75 |
|
76 "FBD_Connector": [("SFC_Transition", WEST)], |
|
77 |
|
78 "LD_Contact": [("SFC_Transition", WEST)], |
|
79 |
|
80 "LD_PowerRail": [("SFC_Transition", WEST)], |
|
81 |
|
82 "LD_Coil": [("SFC_Transition", WEST)] |
|
83 } |
|
84 |
33 def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
85 def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
34 Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath) |
86 Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath) |
35 self.CurrentLanguage = "SFC" |
87 self.CurrentLanguage = "SFC" |
36 |
88 |
37 def ConnectConnectors(self, start, end): |
89 def ConnectConnectors(self, start, end): |
279 self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
331 self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
280 self.SelectedElement.GeneratePoints() |
332 self.SelectedElement.GeneratePoints() |
281 self.SelectedElement.Refresh() |
333 self.SelectedElement.Refresh() |
282 self.UpdateScrollPos(event) |
334 self.UpdateScrollPos(event) |
283 event.Skip() |
335 event.Skip() |
|
336 |
|
337 def GetBlockName(self, block): |
|
338 blockName = block.__class__.__name__ |
|
339 if blockName == "SFC_Divergence": |
|
340 blockName = block.Type |
|
341 return blockName |
|
342 |
|
343 # This method check the IEC 61131-3 compatibility between two SFC blocks |
|
344 def BlockCompatibility(self,startblock = None, endblock = None, direction = None): |
|
345 if startblock!= None and endblock != None and (isinstance(startblock,SFC_Objects)\ |
|
346 or isinstance(endblock,SFC_Objects)): |
|
347 # Full "SFC_StandardRules" table would be symmetrical and |
|
348 # to avoid duplicate records and minimize the table only upper part is defined. |
|
349 if (direction == SOUTH or direction == EAST): |
|
350 startblock, endblock = endblock, startblock |
|
351 start = self.GetBlockName(startblock) |
|
352 end = self.GetBlockName(endblock) |
|
353 for val in self.SFC_StandardRules[start]: |
|
354 if end in val: |
|
355 return True |
|
356 return False |
|
357 return True |
284 |
358 |
285 #------------------------------------------------------------------------------- |
359 #------------------------------------------------------------------------------- |
286 # Keyboard event functions |
360 # Keyboard event functions |
287 #------------------------------------------------------------------------------- |
361 #------------------------------------------------------------------------------- |
288 |
362 |