44 SCROLL_ZONE = 10 |
44 SCROLL_ZONE = 10 |
45 |
45 |
46 CURSORS = None |
46 CURSORS = None |
47 SFC_Objects = (SFC_Step, SFC_ActionBlock, SFC_Transition, SFC_Divergence, SFC_Jump) |
47 SFC_Objects = (SFC_Step, SFC_ActionBlock, SFC_Transition, SFC_Divergence, SFC_Jump) |
48 |
48 |
|
49 |
49 def ResetCursors(): |
50 def ResetCursors(): |
50 global CURSORS |
51 global CURSORS |
51 if CURSORS == None: |
52 if CURSORS == None: |
52 CURSORS = [wx.NullCursor, |
53 CURSORS = [wx.NullCursor, |
53 wx.StockCursor(wx.CURSOR_HAND), |
54 wx.StockCursor(wx.CURSOR_HAND), |
54 wx.StockCursor(wx.CURSOR_SIZENWSE), |
55 wx.StockCursor(wx.CURSOR_SIZENWSE), |
55 wx.StockCursor(wx.CURSOR_SIZENESW), |
56 wx.StockCursor(wx.CURSOR_SIZENESW), |
56 wx.StockCursor(wx.CURSOR_SIZEWE), |
57 wx.StockCursor(wx.CURSOR_SIZEWE), |
57 wx.StockCursor(wx.CURSOR_SIZENS)] |
58 wx.StockCursor(wx.CURSOR_SIZENS)] |
|
59 |
58 |
60 |
59 def AppendMenu(parent, help, id, kind, text): |
61 def AppendMenu(parent, help, id, kind, text): |
60 if wx.VERSION >= (2, 6, 0): |
62 if wx.VERSION >= (2, 6, 0): |
61 parent.Append(help=help, id=id, kind=kind, text=text) |
63 parent.Append(help=help, id=id, kind=kind, text=text) |
62 else: |
64 else: |
81 MAX_ZOOMIN = 4 |
83 MAX_ZOOMIN = 4 |
82 else: |
84 else: |
83 MAX_ZOOMIN = 7 |
85 MAX_ZOOMIN = 7 |
84 ZOOM_FACTORS = [math.sqrt(2) ** x for x in xrange(-6, MAX_ZOOMIN)] |
86 ZOOM_FACTORS = [math.sqrt(2) ** x for x in xrange(-6, MAX_ZOOMIN)] |
85 |
87 |
|
88 |
86 def GetVariableCreationFunction(variable_type): |
89 def GetVariableCreationFunction(variable_type): |
87 def variableCreationFunction(viewer, id, specific_values): |
90 def variableCreationFunction(viewer, id, specific_values): |
88 return FBD_Variable(viewer, variable_type, |
91 return FBD_Variable(viewer, variable_type, |
89 specific_values.name, |
92 specific_values.name, |
90 specific_values.value_type, |
93 specific_values.value_type, |
91 id, |
94 id, |
92 specific_values.execution_order) |
95 specific_values.execution_order) |
93 return variableCreationFunction |
96 return variableCreationFunction |
94 |
97 |
|
98 |
95 def GetConnectorCreationFunction(connector_type): |
99 def GetConnectorCreationFunction(connector_type): |
96 def connectorCreationFunction(viewer, id, specific_values): |
100 def connectorCreationFunction(viewer, id, specific_values): |
97 return FBD_Connector(viewer, connector_type, |
101 return FBD_Connector(viewer, connector_type, |
98 specific_values.name, id) |
102 specific_values.name, id) |
99 return connectorCreationFunction |
103 return connectorCreationFunction |
100 |
104 |
|
105 |
101 def commentCreationFunction(viewer, id, specific_values): |
106 def commentCreationFunction(viewer, id, specific_values): |
102 return Comment(viewer, specific_values.content, id) |
107 return Comment(viewer, specific_values.content, id) |
|
108 |
103 |
109 |
104 def GetPowerRailCreationFunction(powerrail_type): |
110 def GetPowerRailCreationFunction(powerrail_type): |
105 def powerRailCreationFunction(viewer, id, specific_values): |
111 def powerRailCreationFunction(viewer, id, specific_values): |
106 return LD_PowerRail(viewer, powerrail_type, id, |
112 return LD_PowerRail(viewer, powerrail_type, id, |
107 specific_values.connectors) |
113 specific_values.connectors) |
112 |
118 |
113 CONTACT_TYPES = {(True, "none"): CONTACT_REVERSE, |
119 CONTACT_TYPES = {(True, "none"): CONTACT_REVERSE, |
114 (False, "rising"): CONTACT_RISING, |
120 (False, "rising"): CONTACT_RISING, |
115 (False, "falling"): CONTACT_FALLING} |
121 (False, "falling"): CONTACT_FALLING} |
116 |
122 |
|
123 |
117 def contactCreationFunction(viewer, id, specific_values): |
124 def contactCreationFunction(viewer, id, specific_values): |
118 contact_type = CONTACT_TYPES.get((NEGATED_VALUE(specific_values.negated), |
125 contact_type = CONTACT_TYPES.get((NEGATED_VALUE(specific_values.negated), |
119 MODIFIER_VALUE(specific_values.edge)), |
126 MODIFIER_VALUE(specific_values.edge)), |
120 CONTACT_NORMAL) |
127 CONTACT_NORMAL) |
121 return LD_Contact(viewer, contact_type, specific_values.name, id) |
128 return LD_Contact(viewer, contact_type, specific_values.name, id) |
123 COIL_TYPES = {(True, "none", "none"): COIL_REVERSE, |
130 COIL_TYPES = {(True, "none", "none"): COIL_REVERSE, |
124 (False, "none", "set"): COIL_SET, |
131 (False, "none", "set"): COIL_SET, |
125 (False, "none", "reset"): COIL_RESET, |
132 (False, "none", "reset"): COIL_RESET, |
126 (False, "rising", "none"): COIL_RISING, |
133 (False, "rising", "none"): COIL_RISING, |
127 (False, "falling", "none"): COIL_FALLING} |
134 (False, "falling", "none"): COIL_FALLING} |
|
135 |
128 |
136 |
129 def coilCreationFunction(viewer, id, specific_values): |
137 def coilCreationFunction(viewer, id, specific_values): |
130 coil_type = COIL_TYPES.get((NEGATED_VALUE(specific_values.negated), |
138 coil_type = COIL_TYPES.get((NEGATED_VALUE(specific_values.negated), |
131 MODIFIER_VALUE(specific_values.edge), |
139 MODIFIER_VALUE(specific_values.edge), |
132 MODIFIER_VALUE(specific_values.storage)), |
140 MODIFIER_VALUE(specific_values.storage)), |
133 COIL_NORMAL) |
141 COIL_NORMAL) |
134 return LD_Coil(viewer, coil_type, specific_values.name, id) |
142 return LD_Coil(viewer, coil_type, specific_values.name, id) |
|
143 |
135 |
144 |
136 def stepCreationFunction(viewer, id, specific_values): |
145 def stepCreationFunction(viewer, id, specific_values): |
137 step = SFC_Step(viewer, specific_values.name, |
146 step = SFC_Step(viewer, specific_values.name, |
138 specific_values.initial, id) |
147 specific_values.initial, id) |
139 if specific_values.action is not None: |
148 if specific_values.action is not None: |
140 step.AddAction() |
149 step.AddAction() |
141 connector = step.GetActionConnector() |
150 connector = step.GetActionConnector() |
142 connector.SetPosition(wx.Point(*specific_values.action.position)) |
151 connector.SetPosition(wx.Point(*specific_values.action.position)) |
143 return step |
152 return step |
144 |
153 |
|
154 |
145 def transitionCreationFunction(viewer, id, specific_values): |
155 def transitionCreationFunction(viewer, id, specific_values): |
146 transition = SFC_Transition(viewer, specific_values.condition_type, |
156 transition = SFC_Transition(viewer, specific_values.condition_type, |
147 specific_values.condition, |
157 specific_values.condition, |
148 specific_values.priority, id) |
158 specific_values.priority, id) |
149 return transition |
159 return transition |
150 |
160 |
151 divergence_types = [SELECTION_DIVERGENCE, |
161 divergence_types = [SELECTION_DIVERGENCE, |
152 SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE] |
162 SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE] |
153 |
163 |
|
164 |
154 def GetDivergenceCreationFunction(divergence_type): |
165 def GetDivergenceCreationFunction(divergence_type): |
155 def divergenceCreationFunction(viewer, id, specific_values): |
166 def divergenceCreationFunction(viewer, id, specific_values): |
156 return SFC_Divergence(viewer, divergence_type, |
167 return SFC_Divergence(viewer, divergence_type, |
157 specific_values.connectors, id) |
168 specific_values.connectors, id) |
158 return divergenceCreationFunction |
169 return divergenceCreationFunction |
159 |
170 |
|
171 |
160 def jumpCreationFunction(viewer, id, specific_values): |
172 def jumpCreationFunction(viewer, id, specific_values): |
161 return SFC_Jump(viewer, specific_values.target, id) |
173 return SFC_Jump(viewer, specific_values.target, id) |
|
174 |
162 |
175 |
163 def actionBlockCreationFunction(viewer, id, specific_values): |
176 def actionBlockCreationFunction(viewer, id, specific_values): |
164 return SFC_ActionBlock(viewer, specific_values.actions, id) |
177 return SFC_ActionBlock(viewer, specific_values.actions, id) |
165 |
178 |
166 ElementCreationFunctions = { |
179 ElementCreationFunctions = { |
481 |
495 |
482 text = ")" |
496 text = ")" |
483 dc.DrawText(text, x + tw, y) |
497 dc.DrawText(text, x + tw, y) |
484 dc.SetUserScale(scalex, scaley) |
498 dc.SetUserScale(scalex, scaley) |
485 |
499 |
486 """ |
|
487 Class that implements a Viewer based on a wx.ScrolledWindow for drawing and |
|
488 manipulating graphic elements |
|
489 """ |
|
490 |
500 |
491 class Viewer(EditorPanel, DebugViewer): |
501 class Viewer(EditorPanel, DebugViewer): |
|
502 """ |
|
503 Class that implements a Viewer based on a wx.ScrolledWindow for drawing and |
|
504 manipulating graphic elements |
|
505 """ |
492 |
506 |
493 if wx.VERSION < (2, 6, 0): |
507 if wx.VERSION < (2, 6, 0): |
494 def Bind(self, event, function, id = None): |
508 def Bind(self, event, function, id = None): |
495 if id is not None: |
509 if id is not None: |
496 event(self, id, function) |
510 event(self, id, function) |