92 LOCATION_VAR_OUTPUT, |
92 LOCATION_VAR_OUTPUT, |
93 LOCATION_VAR_MEMORY] = range(6) |
93 LOCATION_VAR_MEMORY] = range(6) |
94 |
94 |
95 ScriptDirectory = paths.AbsDir(__file__) |
95 ScriptDirectory = paths.AbsDir(__file__) |
96 |
96 |
|
97 |
97 def GetUneditableNames(): |
98 def GetUneditableNames(): |
98 _ = lambda x:x |
99 _ = lambda x:x |
99 return [_("User-defined POUs"), _("Functions"), _("Function Blocks"), |
100 return [_("User-defined POUs"), _("Functions"), _("Function Blocks"), |
100 _("Programs"), _("Data Types"), _("Transitions"), _("Actions"), |
101 _("Programs"), _("Data Types"), _("Transitions"), _("Actions"), |
101 _("Configurations"), _("Resources"), _("Properties")] |
102 _("Configurations"), _("Resources"), _("Properties")] |
105 RESOURCES, PROPERTIES] = UNEDITABLE_NAMES |
106 RESOURCES, PROPERTIES] = UNEDITABLE_NAMES |
106 |
107 |
107 #------------------------------------------------------------------------------- |
108 #------------------------------------------------------------------------------- |
108 # Helper object for loading library in xslt stylesheets |
109 # Helper object for loading library in xslt stylesheets |
109 #------------------------------------------------------------------------------- |
110 #------------------------------------------------------------------------------- |
|
111 |
110 |
112 |
111 class LibraryResolver(etree.Resolver): |
113 class LibraryResolver(etree.Resolver): |
112 |
114 |
113 def __init__(self, controller, debug=False): |
115 def __init__(self, controller, debug=False): |
114 self.Controller = controller |
116 self.Controller = controller |
134 #------------------------------------------------------------------------------- |
136 #------------------------------------------------------------------------------- |
135 |
137 |
136 _StringValue = lambda x: x |
138 _StringValue = lambda x: x |
137 _BoolValue = lambda x: x in ["true", "0"] |
139 _BoolValue = lambda x: x in ["true", "0"] |
138 |
140 |
|
141 |
139 def _translate_args(translations, args): |
142 def _translate_args(translations, args): |
140 return [translate(arg[0]) if len(arg) > 0 else None |
143 return [translate(arg[0]) if len(arg) > 0 else None |
141 for translate, arg in |
144 for translate, arg in |
142 zip(translations, args)] |
145 zip(translations, args)] |
143 |
146 |
144 #------------------------------------------------------------------------------- |
147 #------------------------------------------------------------------------------- |
145 # Helpers object for generating pou var list |
148 # Helpers object for generating pou var list |
146 #------------------------------------------------------------------------------- |
149 #------------------------------------------------------------------------------- |
|
150 |
147 |
151 |
148 class _VariableInfos(object): |
152 class _VariableInfos(object): |
149 __slots__ = ["Name", "Class", "Option", "Location", "InitialValue", |
153 __slots__ = ["Name", "Class", "Option", "Location", "InitialValue", |
150 "Edit", "Documentation", "Type", "Tree", "Number"] |
154 "Edit", "Documentation", "Type", "Tree", "Number"] |
151 def __init__(self, *args): |
155 def __init__(self, *args): |
152 for attr, value in zip(self.__slots__, args): |
156 for attr, value in zip(self.__slots__, args): |
153 setattr(self, attr, value if value is not None else "") |
157 setattr(self, attr, value if value is not None else "") |
154 def copy(self): |
158 def copy(self): |
155 return _VariableInfos(*[getattr(self, attr) for attr in self.__slots__]) |
159 return _VariableInfos(*[getattr(self, attr) for attr in self.__slots__]) |
156 |
160 |
|
161 |
157 class VariablesInfosFactory: |
162 class VariablesInfosFactory: |
158 |
163 |
159 def __init__(self, variables): |
164 def __init__(self, variables): |
160 self.Variables = variables |
165 self.Variables = variables |
161 self.TreeStack = [] |
166 self.TreeStack = [] |
191 [self.GetType(), self.GetTree()]))) |
196 [self.GetType(), self.GetTree()]))) |
192 |
197 |
193 #------------------------------------------------------------------------------- |
198 #------------------------------------------------------------------------------- |
194 # Helpers object for generating pou variable instance list |
199 # Helpers object for generating pou variable instance list |
195 #------------------------------------------------------------------------------- |
200 #------------------------------------------------------------------------------- |
|
201 |
196 |
202 |
197 def class_extraction(value): |
203 def class_extraction(value): |
198 class_type = { |
204 class_type = { |
199 "configuration": ITEM_CONFIGURATION, |
205 "configuration": ITEM_CONFIGURATION, |
200 "resource": ITEM_RESOURCE, |
206 "resource": ITEM_RESOURCE, |
212 if var_type is not None: |
218 if var_type is not None: |
213 return var_type[1] |
219 return var_type[1] |
214 |
220 |
215 return None |
221 return None |
216 |
222 |
|
223 |
217 class _VariablesTreeItemInfos(object): |
224 class _VariablesTreeItemInfos(object): |
218 __slots__ = ["name", "var_class", "type", "edit", "debug", "variables"] |
225 __slots__ = ["name", "var_class", "type", "edit", "debug", "variables"] |
219 def __init__(self, *args): |
226 def __init__(self, *args): |
220 for attr, value in zip(self.__slots__, args): |
227 for attr, value in zip(self.__slots__, args): |
221 setattr(self, attr, value if value is not None else "") |
228 setattr(self, attr, value if value is not None else "") |
222 def copy(self): |
229 def copy(self): |
223 return _VariableTreeItem(*[getattr(self, attr) for attr in self.__slots__]) |
230 return _VariableTreeItem(*[getattr(self, attr) for attr in self.__slots__]) |
224 |
231 |
|
232 |
225 class VariablesTreeInfosFactory: |
233 class VariablesTreeInfosFactory: |
226 |
234 |
227 def __init__(self): |
235 def __init__(self): |
228 self.Root = None |
236 self.Root = None |
229 |
237 |
245 |
253 |
246 #------------------------------------------------------------------------------- |
254 #------------------------------------------------------------------------------- |
247 # Helpers object for generating instances path list |
255 # Helpers object for generating instances path list |
248 #------------------------------------------------------------------------------- |
256 #------------------------------------------------------------------------------- |
249 |
257 |
|
258 |
250 class InstancesPathFactory: |
259 class InstancesPathFactory: |
251 |
260 |
252 def __init__(self, instances): |
261 def __init__(self, instances): |
253 self.Instances = instances |
262 self.Instances = instances |
254 |
263 |
256 self.Instances.append(args[0][0]) |
265 self.Instances.append(args[0][0]) |
257 |
266 |
258 #------------------------------------------------------------------------------- |
267 #------------------------------------------------------------------------------- |
259 # Helpers object for generating instance tagname |
268 # Helpers object for generating instance tagname |
260 #------------------------------------------------------------------------------- |
269 #------------------------------------------------------------------------------- |
|
270 |
261 |
271 |
262 class InstanceTagName: |
272 class InstanceTagName: |
263 |
273 |
264 def __init__(self, controller): |
274 def __init__(self, controller): |
265 self.Controller = controller |
275 self.Controller = controller |
353 ["name", "negated", "edge", "position", "links"]) |
363 ["name", "negated", "edge", "position", "links"]) |
354 |
364 |
355 _ConnectionLinkInfos = namedtuple("ConnectionLinkInfos", |
365 _ConnectionLinkInfos = namedtuple("ConnectionLinkInfos", |
356 ["refLocalId", "formalParameter", "points"]) |
366 ["refLocalId", "formalParameter", "points"]) |
357 |
367 |
|
368 |
358 class _ActionInfos(object): |
369 class _ActionInfos(object): |
359 __slots__ = ["qualifier", "type", "value", "duration", "indicator"] |
370 __slots__ = ["qualifier", "type", "value", "duration", "indicator"] |
360 def __init__(self, *args): |
371 def __init__(self, *args): |
361 for attr, value in zip(self.__slots__, args): |
372 for attr, value in zip(self.__slots__, args): |
362 setattr(self, attr, value if value is not None else "") |
373 setattr(self, attr, value if value is not None else "") |
363 def copy(self): |
374 def copy(self): |
364 return _ActionInfos(*[getattr(self, attr) for attr in self.__slots__]) |
375 return _ActionInfos(*[getattr(self, attr) for attr in self.__slots__]) |
|
376 |
365 |
377 |
366 class BlockInstanceFactory: |
378 class BlockInstanceFactory: |
367 |
379 |
368 def __init__(self, block_instances): |
380 def __init__(self, block_instances): |
369 self.BlockInstances = block_instances |
381 self.BlockInstances = block_instances |
436 #------------------------------------------------------------------------------- |
448 #------------------------------------------------------------------------------- |
437 |
449 |
438 # Length of the buffer |
450 # Length of the buffer |
439 UNDO_BUFFER_LENGTH = 20 |
451 UNDO_BUFFER_LENGTH = 20 |
440 |
452 |
441 """ |
453 |
442 Class implementing a buffer of changes made on the current editing model |
|
443 """ |
|
444 class UndoBuffer: |
454 class UndoBuffer: |
445 |
455 """ |
446 # Constructor initialising buffer |
456 Class implementing a buffer of changes made on the current editing model |
|
457 """ |
|
458 |
447 def __init__(self, currentstate, issaved = False): |
459 def __init__(self, currentstate, issaved = False): |
|
460 """ |
|
461 Constructor initialising buffer |
|
462 """ |
448 self.Buffer = [] |
463 self.Buffer = [] |
449 self.CurrentIndex = -1 |
464 self.CurrentIndex = -1 |
450 self.MinIndex = -1 |
465 self.MinIndex = -1 |
451 self.MaxIndex = -1 |
466 self.MaxIndex = -1 |
452 # if current state is defined |
467 # if current state is defined |
464 if issaved: |
479 if issaved: |
465 self.LastSave = 0 |
480 self.LastSave = 0 |
466 else: |
481 else: |
467 self.LastSave = -1 |
482 self.LastSave = -1 |
468 |
483 |
469 # Add a new state in buffer |
484 |
470 def Buffering(self, currentstate): |
485 def Buffering(self, currentstate): |
|
486 """ |
|
487 Add a new state in buffer |
|
488 """ |
471 self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH |
489 self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH |
472 self.Buffer[self.CurrentIndex] = currentstate |
490 self.Buffer[self.CurrentIndex] = currentstate |
473 # Actualising buffer limits |
491 # Actualising buffer limits |
474 self.MaxIndex = self.CurrentIndex |
492 self.MaxIndex = self.CurrentIndex |
475 if self.MinIndex == self.CurrentIndex: |
493 if self.MinIndex == self.CurrentIndex: |
477 if self.LastSave == self.MinIndex: |
495 if self.LastSave == self.MinIndex: |
478 self.LastSave = -1 |
496 self.LastSave = -1 |
479 self.MinIndex = (self.MinIndex + 1) % UNDO_BUFFER_LENGTH |
497 self.MinIndex = (self.MinIndex + 1) % UNDO_BUFFER_LENGTH |
480 self.MinIndex = max(self.MinIndex, 0) |
498 self.MinIndex = max(self.MinIndex, 0) |
481 |
499 |
482 # Return current state of buffer |
500 |
483 def Current(self): |
501 def Current(self): |
|
502 """ |
|
503 Return current state of buffer |
|
504 """ |
484 return self.Buffer[self.CurrentIndex] |
505 return self.Buffer[self.CurrentIndex] |
485 |
506 |
486 # Change current state to previous in buffer and return new current state |
507 # Change current state to previous in buffer and return new current state |
487 def Previous(self): |
508 def Previous(self): |
488 if self.CurrentIndex != self.MinIndex: |
509 if self.CurrentIndex != self.MinIndex: |
516 |
537 |
517 #------------------------------------------------------------------------------- |
538 #------------------------------------------------------------------------------- |
518 # Controler for PLCOpenEditor |
539 # Controler for PLCOpenEditor |
519 #------------------------------------------------------------------------------- |
540 #------------------------------------------------------------------------------- |
520 |
541 |
521 """ |
542 |
522 Class which controls the operations made on the plcopen model and answers to view requests |
|
523 """ |
|
524 class PLCControler: |
543 class PLCControler: |
|
544 """ |
|
545 Class which controls the operations made on the plcopen model and answers to view requests |
|
546 """ |
525 |
547 |
526 # Create a new PLCControler |
548 # Create a new PLCControler |
527 def __init__(self): |
549 def __init__(self): |
528 self.LastNewIndex = 0 |
550 self.LastNewIndex = 0 |
529 self.Reset() |
551 self.Reset() |