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 type = [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE] |
|
35 divergence = dict(zip(type,["SELECTION_DIVERGENCE", "SELECTION_CONVERGENCE",\ |
|
36 "SIMULTANEOUS_DIVERGENCE", "SIMULTANEOUS_CONVERGENCE"])) |
|
37 SFC_Objects = (SFC_Step, SFC_ActionBlock, SFC_Transition, SFC_Divergence, SFC_Jump) |
|
38 |
|
39 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 "SFC_Step" : ["SFC_ActionBlock", |
|
43 "SFC_Transition", |
|
44 "SELECTION_DIVERGENCE", |
|
45 "SIMULTANEOUS_CONVERGENCE"], |
|
46 |
|
47 "SFC_ActionBlock" : ["SFC_Step"], |
|
48 |
|
49 "SFC_Transition" : ["SFC_Step", |
|
50 "SELECTION_CONVERGENCE", |
|
51 "SIMULTANEOUS_DIVERGENCE", |
|
52 "SFC_Jump", |
|
53 "FBD_Block", |
|
54 "FBD_Variable" |
|
55 "LD_Contact", |
|
56 "LD_PowerRail", |
|
57 "LD_Coil"], |
|
58 |
|
59 "SELECTION_DIVERGENCE" : ["SFC_Transition"], |
|
60 |
|
61 "SELECTION_CONVERGENCE" : ["SFC_Step", |
|
62 "SFC_Jump"], |
|
63 |
|
64 "SIMULTANEOUS_DIVERGENCE" : ["SFC_Step"], |
|
65 |
|
66 "SIMULTANEOUS_CONVERGENCE" : ["SFC_Transition"], |
|
67 |
|
68 "SFC_Jump" : [], |
|
69 |
|
70 "FBD_Block" : ["SFC_Transition"], |
|
71 |
|
72 "FBD_Variable" : ["SFC_Transition"], |
|
73 |
|
74 "LD_Contact" : ["SFC_Transition"], |
|
75 |
|
76 "LD_PowerRail" : ["SFC_Transition"], |
|
77 |
|
78 "LD_Coil" : ["SFC_Transition"] |
|
79 } |
30 |
80 |
31 class SFC_Viewer(Viewer): |
81 class SFC_Viewer(Viewer): |
32 |
82 |
33 def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
83 def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
34 Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath) |
84 Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath) |
279 self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
329 self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
280 self.SelectedElement.GeneratePoints() |
330 self.SelectedElement.GeneratePoints() |
281 self.SelectedElement.Refresh() |
331 self.SelectedElement.Refresh() |
282 self.UpdateScrollPos(event) |
332 self.UpdateScrollPos(event) |
283 event.Skip() |
333 event.Skip() |
|
334 |
|
335 def GetBlockName(self, block): |
|
336 blockName = block.__class__.__name__ |
|
337 if blockName == "SFC_Divergence": |
|
338 blockName = divergence[block.Type] |
|
339 return blockName |
|
340 |
|
341 # This method check the IEC 61131-3 compatibility between two SFC blocks |
|
342 def BlockCompatibility(self,startblock = None, endblock = None, direction = None): |
|
343 if startblock!= None and endblock != None and (isinstance(startblock,SFC_Objects)\ |
|
344 or isinstance(endblock,SFC_Objects)): |
|
345 # Full "StandardRules" table would be simmetrical and |
|
346 # to avoid duplicate records and minimize the table only upper part is defined. |
|
347 if (direction == SOUTH or direction == EAST): |
|
348 startblock, endblock = endblock, startblock |
|
349 start = self.GetBlockName(startblock) |
|
350 end = self.GetBlockName(endblock) |
|
351 return end in StandardRules[start] |
|
352 return True |
284 |
353 |
285 #------------------------------------------------------------------------------- |
354 #------------------------------------------------------------------------------- |
286 # Keyboard event functions |
355 # Keyboard event functions |
287 #------------------------------------------------------------------------------- |
356 #------------------------------------------------------------------------------- |
288 |
357 |