381 |
381 |
382 #------------------------------------------------------------------------------- |
382 #------------------------------------------------------------------------------- |
383 # Project Pous management functions |
383 # Project Pous management functions |
384 #------------------------------------------------------------------------------- |
384 #------------------------------------------------------------------------------- |
385 |
385 |
|
386 def RemoveElementEditing(self, index): |
|
387 self.ElementsOpened.pop(index) |
|
388 if self.CurrentElementEditing > index: |
|
389 self.CurrentElementEditing -= 1 |
|
390 if len(self.ElementsOpened) > 0: |
|
391 self.CurrentElementEditing = max(0, min(self.CurrentElementEditing, len(self.ElementsOpened) - 1)) |
|
392 else: |
|
393 self.CurrentElementEditing = None |
|
394 |
386 # Add a Pou to Project |
395 # Add a Pou to Project |
387 def ProjectAddPou(self, name, pou_type, body_type): |
396 def ProjectAddPou(self, pou_name, pou_type, body_type): |
388 # Add the pou to project |
397 # Add the pou to project |
389 self.Project.appendPou(name, pou_type, body_type) |
398 self.Project.appendPou(pou_name, pou_type, body_type) |
390 self.SetPouInterfaceReturnType(name, "BOOL") |
399 if pou_type == "function": |
|
400 self.SetPouInterfaceReturnType(pou_name, "BOOL") |
391 self.RefreshPouUsingTree() |
401 self.RefreshPouUsingTree() |
392 self.RefreshBlockTypes() |
402 self.RefreshBlockTypes() |
393 self.BufferProject() |
403 self.BufferProject() |
394 |
404 |
395 # Remove a pou from project |
405 # Remove a pou from project |
396 def ProjectRemovePou(self, name): |
406 def ProjectRemovePou(self, pou_name): |
397 removed = None |
|
398 # Search if the pou removed is currently opened |
407 # Search if the pou removed is currently opened |
399 for i, pou in enumerate(self.ElementsOpened): |
408 for i, element in enumerate(self.ElementsOpened): |
400 if pou == name: |
409 words = element.split("::") |
401 removed = i |
410 if words[0] == "P" and words[1] == pou_name: |
402 # If found, remove pou from list of opened pous and actualize current edited |
411 self.RemoveElementEditing(i) |
403 if removed != None: |
|
404 self.ElementsOpened.pop(removed) |
|
405 if self.CurrentElementEditing > removed: |
|
406 self.CurrentElementEditing -= 1 |
|
407 if len(self.ElementsOpened) > 0: |
|
408 self.CurrentElementEditing = max(0, min(self.CurrentElementEditing, len(self.ElementsOpened) - 1)) |
|
409 else: |
|
410 self.CurrentElementEditing = None |
|
411 # Remove pou from project |
412 # Remove pou from project |
412 self.Project.removePou(name) |
413 self.Project.removePou(pou_name) |
413 self.RefreshPouUsingTree() |
414 self.RefreshPouUsingTree() |
414 self.RefreshBlockTypes() |
415 self.RefreshBlockTypes() |
415 self.BufferProject() |
416 self.BufferProject() |
416 |
417 |
417 # Add a configuration to Project |
418 # Add a configuration to Project |
418 def ProjectAddConfiguration(self, name): |
419 def ProjectAddConfiguration(self, config_name): |
419 self.Project.addConfiguration(name) |
420 self.Project.addConfiguration(config_name) |
420 self.RefreshPouUsingTree() |
421 self.RefreshPouUsingTree() |
421 self.RefreshBlockTypes() |
422 self.RefreshBlockTypes() |
422 self.BufferProject() |
423 self.BufferProject() |
423 |
424 |
424 # Remove a configuration from project |
425 # Remove a configuration from project |
425 def ProjectRemoveConfiguration(self, name): |
426 def ProjectRemoveConfiguration(self, config_name): |
426 self.Project.removeConfiguration(name) |
427 # Search if the pou removed is currently opened |
|
428 for i, element in enumerate(self.ElementsOpened): |
|
429 words = element.split("::") |
|
430 if words[0] == "C" and words[1] == config_name: |
|
431 self.RemoveElementEditing(i) |
|
432 self.Project.removeConfiguration(config_name) |
|
433 self.BufferProject() |
|
434 |
|
435 # Add a resource to a configuration of the Project |
|
436 def ProjectAddConfigurationResource(self, config_name, resource_name): |
|
437 self.Project.addConfigurationResource(config_name, resource_name) |
427 self.RefreshPouUsingTree() |
438 self.RefreshPouUsingTree() |
428 self.RefreshBlockTypes() |
439 self.RefreshBlockTypes() |
429 self.BufferProject() |
440 self.BufferProject() |
430 |
441 |
431 # Add a resource to a configuration of the Project |
|
432 def ProjectAddConfigurationResource(self, config, name): |
|
433 self.Project.addConfigurationResource(config, name) |
|
434 self.RefreshPouUsingTree() |
|
435 self.RefreshBlockTypes() |
|
436 self.BufferProject() |
|
437 |
|
438 # Remove a resource from a configuration of the project |
442 # Remove a resource from a configuration of the project |
439 def ProjectRemoveConfigurationResource(self, config, name): |
443 def ProjectRemoveConfigurationResource(self, config_name, resource_name): |
440 self.Project.removeConfigurationResource(config, name) |
444 # Search if the pou removed is currently opened |
441 self.RefreshPouUsingTree() |
445 for i, element in enumerate(self.ElementsOpened): |
442 self.RefreshBlockTypes() |
446 words = element.split("::") |
|
447 if words[0] == "R" and words[1] == config_name and words[2] == resource_name: |
|
448 self.RemoveElementEditing(i) |
|
449 self.Project.removeConfigurationResource(config_name, resource_name) |
443 self.BufferProject() |
450 self.BufferProject() |
444 |
451 |
445 # Add a Transition to a Project Pou |
452 # Add a Transition to a Project Pou |
446 def ProjectAddPouTransition(self, pou_name, transition_name, transition_type): |
453 def ProjectAddPouTransition(self, pou_name, transition_name, transition_type): |
447 pou = self.Project.getPou(pou_name) |
454 pou = self.Project.getPou(pou_name) |
448 pou.addTransition(transition_name, transition_type) |
455 pou.addTransition(transition_name, transition_type) |
449 self.BufferProject() |
456 self.BufferProject() |
450 |
457 |
451 # Add a Transition to a Project Pou |
458 # Remove a Transition from a Project Pou |
|
459 def ProjectRemovePouTransition(self, pou_name, transition_name): |
|
460 # Search if the pou removed is currently opened |
|
461 for i, element in enumerate(self.ElementsOpened): |
|
462 words = element.split("::") |
|
463 if words[0] == "T" and words[1] == pou_name and words[2] == transition_name: |
|
464 self.RemoveElementEditing(i) |
|
465 pou = self.Project.getPou(pou_name) |
|
466 pou.removeTransition(transition_name) |
|
467 self.BufferProject() |
|
468 |
|
469 # Add an Action to a Project Pou |
452 def ProjectAddPouAction(self, pou_name, action_name, action_type): |
470 def ProjectAddPouAction(self, pou_name, action_name, action_type): |
453 pou = self.Project.getPou(pou_name) |
471 pou = self.Project.getPou(pou_name) |
454 pou.addAction(action_name, action_type) |
472 pou.addAction(action_name, action_type) |
|
473 self.BufferProject() |
|
474 |
|
475 # Remove an Action from a Project Pou |
|
476 def ProjectRemovePouAction(self, pou_name, action_name): |
|
477 # Search if the pou removed is currently opened |
|
478 for i, element in enumerate(self.ElementsOpened): |
|
479 words = element.split("::") |
|
480 if words[0] == "A" and words[1] == pou_name and words[2] == action_name: |
|
481 self.RemoveElementEditing(i) |
|
482 pou = self.Project.getPou(pou_name) |
|
483 pou.removeAction(action_name) |
455 self.BufferProject() |
484 self.BufferProject() |
456 |
485 |
457 # Change the name of a pou |
486 # Change the name of a pou |
458 def ChangePouName(self, old_name, new_name): |
487 def ChangePouName(self, old_name, new_name): |
459 # Found the pou corresponding to old name and change its name to new name |
488 # Found the pou corresponding to old name and change its name to new name |