448 #------------------------------------------------------------------------------- |
424 #------------------------------------------------------------------------------- |
449 |
425 |
450 # Add a Data Type to Project |
426 # Add a Data Type to Project |
451 def ProjectAddDataType(self, datatype_name): |
427 def ProjectAddDataType(self, datatype_name): |
452 # Add the pou to project |
428 # Add the pou to project |
453 self.Project.appendDataType(datatype_name) |
429 self.Project.appenddataType(datatype_name) |
454 self.RefreshDataTypeUsingTree() |
430 self.RefreshDataTypeUsingTree() |
455 self.RefreshDataTypes() |
431 self.RefreshDataTypes() |
456 self.BufferProject() |
432 self.BufferProject() |
457 |
433 |
458 # Remove a Data Type from project |
434 # Remove a Data Type from project |
459 def ProjectRemoveDataType(self, datatype_name): |
435 def ProjectRemoveDataType(self, datatype_name): |
460 self.Project.removeDataType(datatype_name) |
436 self.Project.removedataType(datatype_name) |
461 self.RefreshDataTypeUsingTree() |
437 self.RefreshDataTypeUsingTree() |
462 self.RefreshDataTypes() |
438 self.RefreshDataTypes() |
463 self.BufferProject() |
439 self.BufferProject() |
464 |
440 |
465 # Add a Pou to Project |
441 # Add a Pou to Project |
466 def ProjectAddPou(self, pou_name, pou_type, body_type): |
442 def ProjectAddPou(self, pou_name, pou_type, body_type): |
467 # Add the pou to project |
443 # Add the pou to project |
468 self.Project.appendPou(pou_name, pou_type, body_type) |
444 self.Project.appendpou(pou_name, pou_type, body_type) |
469 if pou_type == "function": |
445 if pou_type == "function": |
470 self.SetPouInterfaceReturnType(pou_name, "BOOL") |
446 self.SetPouInterfaceReturnType(pou_name, "BOOL") |
471 self.RefreshPouUsingTree() |
447 self.RefreshPouUsingTree() |
472 self.RefreshBlockTypes() |
448 self.RefreshBlockTypes() |
473 self.BufferProject() |
449 self.BufferProject() |
474 |
450 |
475 # Remove a Pou from project |
451 # Remove a Pou from project |
476 def ProjectRemovePou(self, pou_name): |
452 def ProjectRemovePou(self, pou_name): |
477 self.Project.removePou(pou_name) |
453 self.Project.removepou(pou_name) |
478 self.RefreshPouUsingTree() |
454 self.RefreshPouUsingTree() |
479 self.RefreshBlockTypes() |
455 self.RefreshBlockTypes() |
480 self.BufferProject() |
456 self.BufferProject() |
481 |
457 |
482 # Add a configuration to Project |
458 # Add a configuration to Project |
483 def ProjectAddConfiguration(self, config_name): |
459 def ProjectAddConfiguration(self, config_name): |
484 self.Project.addConfiguration(config_name) |
460 self.Project.addconfiguration(config_name) |
485 self.BufferProject() |
461 self.BufferProject() |
486 |
462 |
487 # Remove a configuration from project |
463 # Remove a configuration from project |
488 def ProjectRemoveConfiguration(self, config_name): |
464 def ProjectRemoveConfiguration(self, config_name): |
489 self.Project.removeConfiguration(config_name) |
465 self.Project.removeconfiguration(config_name) |
490 self.BufferProject() |
466 self.BufferProject() |
491 |
467 |
492 # Add a resource to a configuration of the Project |
468 # Add a resource to a configuration of the Project |
493 def ProjectAddConfigurationResource(self, config_name, resource_name): |
469 def ProjectAddConfigurationResource(self, config_name, resource_name): |
494 self.Project.addConfigurationResource(config_name, resource_name) |
470 self.Project.addconfigurationResource(config_name, resource_name) |
495 self.BufferProject() |
471 self.BufferProject() |
496 |
472 |
497 # Remove a resource from a configuration of the project |
473 # Remove a resource from a configuration of the project |
498 def ProjectRemoveConfigurationResource(self, config_name, resource_name): |
474 def ProjectRemoveConfigurationResource(self, config_name, resource_name): |
499 self.Project.removeConfigurationResource(config_name, resource_name) |
475 self.Project.removeconfigurationResource(config_name, resource_name) |
500 self.BufferProject() |
476 self.BufferProject() |
501 |
477 |
502 # Add a Transition to a Project Pou |
478 # Add a Transition to a Project Pou |
503 def ProjectAddPouTransition(self, pou_name, transition_name, transition_type): |
479 def ProjectAddPouTransition(self, pou_name, transition_name, transition_type): |
504 pou = self.Project.getPou(pou_name) |
480 pou = self.Project.getpou(pou_name) |
505 pou.addTransition(transition_name, transition_type) |
481 pou.addtransition(transition_name, transition_type) |
506 self.BufferProject() |
482 self.BufferProject() |
507 |
483 |
508 # Remove a Transition from a Project Pou |
484 # Remove a Transition from a Project Pou |
509 def ProjectRemovePouTransition(self, pou_name, transition_name): |
485 def ProjectRemovePouTransition(self, pou_name, transition_name): |
510 pou = self.Project.getPou(pou_name) |
486 pou = self.Project.getpou(pou_name) |
511 pou.removeTransition(transition_name) |
487 pou.removetransition(transition_name) |
512 self.BufferProject() |
488 self.BufferProject() |
513 |
489 |
514 # Add an Action to a Project Pou |
490 # Add an Action to a Project Pou |
515 def ProjectAddPouAction(self, pou_name, action_name, action_type): |
491 def ProjectAddPouAction(self, pou_name, action_name, action_type): |
516 pou = self.Project.getPou(pou_name) |
492 pou = self.Project.getpou(pou_name) |
517 pou.addAction(action_name, action_type) |
493 pou.addaction(action_name, action_type) |
518 self.BufferProject() |
494 self.BufferProject() |
519 |
495 |
520 # Remove an Action from a Project Pou |
496 # Remove an Action from a Project Pou |
521 def ProjectRemovePouAction(self, pou_name, action_name): |
497 def ProjectRemovePouAction(self, pou_name, action_name): |
522 # Search if the pou removed is currently opened |
498 # Search if the pou removed is currently opened |
523 for i, element in enumerate(self.ElementsOpened): |
499 for i, element in enumerate(self.ElementsOpened): |
524 words = element.split("::") |
500 words = element.split("::") |
525 if words[0] == "A" and words[1] == pou_name and words[2] == action_name: |
501 if words[0] == "A" and words[1] == pou_name and words[2] == action_name: |
526 self.RemoveElementEditing(i) |
502 self.RemoveElementEditing(i) |
527 pou = self.Project.getPou(pou_name) |
503 pou = self.Project.getpou(pou_name) |
528 pou.removeAction(action_name) |
504 pou.removeaction(action_name) |
529 self.BufferProject() |
505 self.BufferProject() |
530 |
506 |
531 # Change the name of a pou |
507 # Change the name of a pou |
532 def ChangeDataTypeName(self, old_name, new_name): |
508 def ChangeDataTypeName(self, old_name, new_name): |
533 # Found the pou corresponding to old name and change its name to new name |
509 # Found the pou corresponding to old name and change its name to new name |
534 datatype = self.Project.getDataType(old_name) |
510 datatype = self.Project.getdataType(old_name) |
535 datatype.setName(new_name) |
511 datatype.setname(new_name) |
536 self.Project.updateElementName(old_name, new_name) |
512 self.Project.updateElementName(old_name, new_name) |
537 self.BufferProject() |
513 self.BufferProject() |
538 |
514 |
539 # Change the name of a pou |
515 # Change the name of a pou |
540 def ChangePouName(self, old_name, new_name): |
516 def ChangePouName(self, old_name, new_name): |
541 # Found the pou corresponding to old name and change its name to new name |
517 # Found the pou corresponding to old name and change its name to new name |
542 pou = self.Project.getPou(old_name) |
518 pou = self.Project.getpou(old_name) |
543 pou.setName(new_name) |
519 pou.setname(new_name) |
544 self.Project.updateElementName(old_name, new_name) |
520 self.Project.updateElementName(old_name, new_name) |
545 self.RefreshPouUsingTree() |
521 self.RefreshPouUsingTree() |
546 self.RefreshBlockTypes() |
522 self.RefreshBlockTypes() |
547 self.BufferProject() |
523 self.BufferProject() |
548 |
524 |
549 # Change the name of a pou transition |
525 # Change the name of a pou transition |
550 def ChangePouTransitionName(self, pou_name, old_name, new_name): |
526 def ChangePouTransitionName(self, pou_name, old_name, new_name): |
551 # Found the pou transition corresponding to old name and change its name to new name |
527 # Found the pou transition corresponding to old name and change its name to new name |
552 pou = self.Project.getPou(pou_name) |
528 pou = self.Project.getpou(pou_name) |
553 transition = pou.getTransition(old_name) |
529 transition = pou.gettransition(old_name) |
554 transition.setName(new_name) |
530 transition.setname(new_name) |
555 pou.updateElementName(old_name, new_name) |
531 pou.updateElementName(old_name, new_name) |
556 self.BufferProject() |
532 self.BufferProject() |
557 |
533 |
558 # Change the name of a pou action |
534 # Change the name of a pou action |
559 def ChangePouActionName(self, pou_name, old_name, new_name): |
535 def ChangePouActionName(self, pou_name, old_name, new_name): |
560 # Found the pou action corresponding to old name and change its name to new name |
536 # Found the pou action corresponding to old name and change its name to new name |
561 pou = self.Project.getPou(pou_name) |
537 pou = self.Project.getpou(pou_name) |
562 action = pou.getAction(old_name) |
538 action = pou.getaction(old_name) |
563 action.setName(new_name) |
539 action.setname(new_name) |
564 pou.updateElementName(old_name, new_name) |
540 pou.updateElementName(old_name, new_name) |
565 self.BufferProject() |
541 self.BufferProject() |
566 |
542 |
567 # Change the name of a pou variable |
543 # Change the name of a pou variable |
568 def ChangePouVariableName(self, pou_name, old_name, new_name): |
544 def ChangePouVariableName(self, pou_name, old_name, new_name): |
569 # Found the pou action corresponding to old name and change its name to new name |
545 # Found the pou action corresponding to old name and change its name to new name |
570 pou = self.Project.getPou(pou_name) |
546 pou = self.Project.getpou(pou_name) |
571 for type, varlist in pou.getVars(): |
547 for type, varlist in pou.getvars(): |
572 for var in varlist.getVariable(): |
548 for var in varlist.getvariable(): |
573 if var.getName() == old_name: |
549 if var.getname() == old_name: |
574 var.setName(new_name) |
550 var.setname(new_name) |
575 self.RefreshBlockTypes() |
551 self.RefreshBlockTypes() |
576 self.BufferProject() |
552 self.BufferProject() |
577 |
553 |
578 # Change the name of a configuration |
554 # Change the name of a configuration |
579 def ChangeConfigurationName(self, old_name, new_name): |
555 def ChangeConfigurationName(self, old_name, new_name): |
580 # Found the configuration corresponding to old name and change its name to new name |
556 # Found the configuration corresponding to old name and change its name to new name |
581 configuration = self.Project.getConfiguration(old_name) |
557 configuration = self.Project.getconfiguration(old_name) |
582 configuration.setName(new_name) |
558 configuration.setname(new_name) |
583 self.BufferProject() |
559 self.BufferProject() |
584 |
560 |
585 # Change the name of a configuration resource |
561 # Change the name of a configuration resource |
586 def ChangeConfigurationResourceName(self, config_name, old_name, new_name): |
562 def ChangeConfigurationResourceName(self, config_name, old_name, new_name): |
587 # Found the resource corresponding to old name and change its name to new name |
563 # Found the resource corresponding to old name and change its name to new name |
588 resource = self.Project.getConfigurationResource(config_name) |
564 resource = self.Project.getconfigurationResource(config_name) |
589 resource.setName(new_name) |
565 resource.setName(new_name) |
590 self.BufferProject() |
566 self.BufferProject() |
591 |
567 |
592 # Return the type of the pou given by its name |
568 # Return the type of the pou given by its name |
593 def GetPouType(self, name): |
569 def GetPouType(self, name): |
594 # Found the pou correponding to name and return its type |
570 # Found the pou correponding to name and return its type |
595 pou = self.Project.getPou(name) |
571 pou = self.Project.getpou(name) |
596 return pou.pouType.getValue() |
572 return pou.getpouType() |
597 |
573 |
598 # Return pous with SFC language |
574 # Return pous with SFC language |
599 def GetSFCPous(self): |
575 def GetSFCPous(self): |
600 list = [] |
576 list = [] |
601 if self.Project: |
577 if self.Project: |
602 for pou in self.Project.getPous(): |
578 for pou in self.Project.getpous(): |
603 if pou.getBodyType() == "SFC": |
579 if pou.getBodyType() == "SFC": |
604 list.append(pou.getName()) |
580 list.append(pou.getname()) |
605 return list |
581 return list |
606 |
582 |
607 # Return the body language of the pou given by its name |
583 # Return the body language of the pou given by its name |
608 def GetPouBodyType(self, name): |
584 def GetPouBodyType(self, name): |
609 # Found the pou correponding to name and return its body language |
585 # Found the pou correponding to name and return its body language |
610 pou = self.Project.getPou(name) |
586 pou = self.Project.getpou(name) |
611 return pou.getBodyType() |
587 return pou.getbodyType() |
612 |
588 |
613 # Return the actions of a pou |
589 # Return the actions of a pou |
614 def GetPouTransitions(self, pou_name): |
590 def GetPouTransitions(self, pou_name): |
615 transitions = [] |
591 transitions = [] |
616 pou = self.Project.getPou(pou_name) |
592 pou = self.Project.getpou(pou_name) |
617 if pou.getBodyType() == "SFC": |
593 if pou.getbodyType() == "SFC": |
618 for transition in pou.getTransitionList(): |
594 for transition in pou.gettransitionList(): |
619 transitions.append(transition.getName()) |
595 transitions.append(transition.getname()) |
620 return transitions |
596 return transitions |
621 |
597 |
622 # Return the body language of the transition given by its name |
598 # Return the body language of the transition given by its name |
623 def GetTransitionBodyType(self, pou_name, pou_transition): |
599 def GetTransitionBodyType(self, pou_name, pou_transition): |
624 # Found the pou correponding to name and return its body language |
600 # Found the pou correponding to name and return its body language |
625 pou = self.Project.getPou(pou_name) |
601 pou = self.Project.getpou(pou_name) |
626 transition = pou.getTransition(pou_transition) |
602 transition = pou.gettransition(pou_transition) |
627 return transition.getBodyType() |
603 return transition.getbodyType() |
628 |
604 |
629 # Return the actions of a pou |
605 # Return the actions of a pou |
630 def GetPouActions(self, pou_name): |
606 def GetPouActions(self, pou_name): |
631 actions = [] |
607 actions = [] |
632 pou = self.Project.getPou(pou_name) |
608 pou = self.Project.getpou(pou_name) |
633 if pou.getBodyType() == "SFC": |
609 if pou.getbodyType() == "SFC": |
634 for action in pou.getActionList(): |
610 for action in pou.getactionList(): |
635 actions.append(action.getName()) |
611 actions.append(action.getname()) |
636 return actions |
612 return actions |
637 |
613 |
638 # Return the body language of the pou given by its name |
614 # Return the body language of the pou given by its name |
639 def GetActionBodyType(self, pou_name, pou_action): |
615 def GetActionBodyType(self, pou_name, pou_action): |
640 # Found the pou correponding to name and return its body language |
616 # Found the pou correponding to name and return its body language |
641 pou = self.Project.getPou(pou_name) |
617 pou = self.Project.getpou(pou_name) |
642 action = pou.getAction(pou_action) |
618 action = pou.getaction(pou_action) |
643 return action.getBodyType() |
619 return action.getbodyType() |
644 |
620 |
645 # Extract varlists from a list of vars |
621 # Extract varlists from a list of vars |
646 def ExtractVarLists(self, vars): |
622 def ExtractVarLists(self, vars): |
647 varlist_list = [] |
623 varlist_list = [] |
648 current_varlist = None |
624 current_varlist = None |
649 current_type = None |
625 current_type = None |
650 for var in vars: |
626 for var in vars: |
651 if current_type != (var["Class"], var["Retain"], var["Constant"], var["Location"] in ["", None]): |
627 if current_type != (var["Class"], var["Retain"], var["Constant"], var["Location"] in ["", None]): |
652 current_type = (var["Class"], var["Retain"], var["Constant"], var["Location"] in ["", None]) |
628 current_type = (var["Class"], var["Retain"], var["Constant"], var["Location"] in ["", None]) |
653 current_varlist = plcopen.varList() |
629 if var["Class"] == "Local": |
|
630 current_varlist = plcopen.interface_localVars() |
|
631 elif var["Class"] == "Global": |
|
632 current_varlist = plcopen.interface_globalVars() |
|
633 elif var["Class"] == "External": |
|
634 current_varlist = plcopen.interface_externalVars() |
|
635 elif var["Class"] == "Temp": |
|
636 current_varlist = plcopen.interface_tempVars() |
|
637 elif var["Class"] == "Input": |
|
638 current_varlist = plcopen.interface_inputVars() |
|
639 elif var["Class"] == "Output": |
|
640 current_varlist = plcopen.interface_outputVars() |
|
641 elif var["Class"] == "InOut": |
|
642 current_varlist = plcopen.interface_inOutVars() |
|
643 else: |
|
644 current_varlist = plcopen.varList() |
654 varlist_list.append((var["Class"], current_varlist)) |
645 varlist_list.append((var["Class"], current_varlist)) |
655 if var["Retain"] == "Yes": |
646 if var["Retain"] == "Yes": |
656 varlist.setRetain(True) |
647 current_varlist.setretain(True) |
657 if var["Constant"] == "Yes": |
648 if var["Constant"] == "Yes": |
658 varlist.setConstant(True) |
649 current_varlist.setconstant(True) |
659 # Create variable and change its properties |
650 # Create variable and change its properties |
660 tempvar = plcopen.varListPlain_variable() |
651 tempvar = plcopen.varListPlain_variable() |
661 tempvar.setName(var["Name"]) |
652 tempvar.setname(var["Name"]) |
662 var_type = plcopen.dataType() |
653 var_type = plcopen.dataType() |
663 if var["Type"] not in var_type.getChoices(): |
654 if var["Type"] in self.GetBaseTypes(): |
664 if var["Type"] == "STRING": |
655 if var["Type"] == "STRING": |
665 var_type.setContent("string", plcopen.string()) |
656 var_type.setcontent({"name" : "string", "value" : plcopen.elementaryTypes_string()}) |
666 elif var["Type"] == "WSTRING": |
657 elif var["Type"] == "WSTRING": |
667 var_type.setContent("wstring", plcopen.wstring()) |
658 var_type.setcontent({"name" : "wstring", "value" : plcopen.elementaryTypes_wstring()}) |
668 else: |
659 else: |
669 derived_type = plcopen.derived() |
660 var_type.setcontent({"name" : var["Type"], "value" : None}) |
670 derived_type.setName(var["Type"]) |
|
671 var_type.setContent("derived", derived_type) |
|
672 else: |
661 else: |
673 var_type.setContent(var["Type"], None) |
662 derived_type = plcopen.derivedTypes_derived() |
674 tempvar.setType(var_type) |
663 derived_type.setname(var["Type"]) |
|
664 var_type.setcontent({"name" : "derived", "value" : derived_type}) |
|
665 tempvar.settype(var_type) |
675 if var["Initial Value"] != "": |
666 if var["Initial Value"] != "": |
676 value = plcopen.value() |
667 value = plcopen.value() |
677 value.setValue(var["Initial Value"]) |
668 value.setvalue(var["Initial Value"]) |
678 tempvar.setInitialValue(value) |
669 tempvar.setinitialValue(value) |
679 if var["Location"] != "": |
670 if var["Location"] != "": |
680 tempvar.setAddress(var["Location"]) |
671 tempvar.setaddress(var["Location"]) |
681 else: |
672 else: |
682 tempvar.setAddress(None) |
673 tempvar.setaddress(None) |
683 # Add variable to varList |
674 # Add variable to varList |
684 current_varlist.appendVariable(tempvar) |
675 current_varlist.appendvariable(tempvar) |
685 return varlist_list |
676 return varlist_list |
686 |
677 |
687 # Replace the configuration globalvars by those given |
678 # Replace the configuration globalvars by those given |
688 def SetConfigurationGlobalVars(self, name, vars): |
679 def SetConfigurationGlobalVars(self, name, vars): |
689 # Found the configuration corresponding to name |
680 # Found the configuration corresponding to name |
690 configuration = self.Project.getConfiguration(name) |
681 configuration = self.Project.getconfiguration(name) |
691 if configuration: |
682 if configuration: |
692 # Set configuration global vars |
683 # Set configuration global vars |
693 configuration.setGlobalVars([]) |
684 configuration.setglobalVars([]) |
694 for vartype, varlist in self.ExtractVarLists(vars): |
685 for vartype, varlist in self.ExtractVarLists(vars): |
695 configuration.globalVars.append(varlist) |
686 configuration.globalVars.append(varlist) |
696 self.RefreshBlockTypes() |
687 self.RefreshBlockTypes() |
697 |
688 |
698 # Return the configuration globalvars |
689 # Return the configuration globalvars |
699 def GetConfigurationGlobalVars(self, name): |
690 def GetConfigurationGlobalVars(self, name): |
700 vars = [] |
691 vars = [] |
701 # Found the configuration corresponding to name |
692 # Found the configuration corresponding to name |
702 configuration = self.Project.getConfiguration(name) |
693 configuration = self.Project.getconfiguration(name) |
703 if configuration: |
694 if configuration: |
704 # Extract variables from every varLists |
695 # Extract variables from every varLists |
705 for varlist in configuration.getGlobalVars(): |
696 for varlist in configuration.getglobalVars(): |
706 for var in varlist.getVariable(): |
697 for var in varlist.getvariable(): |
707 tempvar = {"Name":var.getName(),"Class":"Global"} |
698 tempvar = {"Name" : var.getname(), "Class" : "Global"} |
708 vartype_content = var.getType().getContent() |
699 vartype_content = var.gettype().getcontent() |
709 if vartype_content["name"] == "derived": |
700 if vartype_content["name"] == "derived": |
710 tempvar["Type"] = vartype_content["value"].getName() |
701 tempvar["Type"] = vartype_content["value"].getname() |
711 elif vartype_content["name"] in ["string", "wstring"]: |
702 elif vartype_content["name"] in ["string", "wstring"]: |
712 tempvar["Type"] = vartype_content["name"].upper() |
703 tempvar["Type"] = vartype_content["name"].upper() |
713 else: |
704 else: |
714 tempvar["Type"] = vartype_content["name"] |
705 tempvar["Type"] = vartype_content["name"] |
715 tempvar["Edit"] = True |
706 tempvar["Edit"] = True |
716 initial = var.getInitialValue() |
707 initial = var.getinitialValue() |
717 if initial: |
708 if initial: |
718 tempvar["Initial Value"] = initial.getValue() |
709 tempvar["Initial Value"] = initial.getvalue() |
719 else: |
710 else: |
720 tempvar["Initial Value"] = "" |
711 tempvar["Initial Value"] = "" |
721 address = var.getAddress() |
712 address = var.getaddress() |
722 if address: |
713 if address: |
723 tempvar["Location"] = address |
714 tempvar["Location"] = address |
724 else: |
715 else: |
725 tempvar["Location"] = "" |
716 tempvar["Location"] = "" |
726 if varlist.getRetain(): |
717 if varlist.getretain(): |
727 tempvar["Retain"] = "Yes" |
718 tempvar["Retain"] = "Yes" |
728 else: |
719 else: |
729 tempvar["Retain"] = "No" |
720 tempvar["Retain"] = "No" |
730 if varlist.getConstant(): |
721 if varlist.getconstant(): |
731 tempvar["Constant"] = "Yes" |
722 tempvar["Constant"] = "Yes" |
732 else: |
723 else: |
733 tempvar["Constant"] = "No" |
724 tempvar["Constant"] = "No" |
734 vars.append(tempvar) |
725 vars.append(tempvar) |
735 return vars |
726 return vars |
736 |
727 |
737 # Replace the resource globalvars by those given |
728 # Replace the resource globalvars by those given |
738 def SetConfigurationResourceGlobalVars(self, config_name, name, vars): |
729 def SetConfigurationResourceGlobalVars(self, config_name, name, vars): |
739 # Found the resource corresponding to name |
730 # Found the resource corresponding to name |
740 resource = self.Project.getConfigurationResource(config_name, name) |
731 resource = self.Project.getconfigurationResource(config_name, name) |
741 # Set resource global vars |
732 # Set resource global vars |
742 if resource: |
733 if resource: |
743 resource.setGlobalVars([]) |
734 resource.setglobalVars([]) |
744 for vartype, varlist in self.ExtractVarLists(vars): |
735 for vartype, varlist in self.ExtractVarLists(vars): |
745 resource.globalVars.append(varlist) |
736 resource.globalVars.append(varlist) |
746 self.RefreshBlockTypes() |
737 self.RefreshBlockTypes() |
747 |
738 |
748 # Return the resource globalvars |
739 # Return the resource globalvars |
749 def GetConfigurationResourceGlobalVars(self, config_name, name): |
740 def GetConfigurationResourceGlobalVars(self, config_name, name): |
750 vars = [] |
741 vars = [] |
751 # Found the resource corresponding to name |
742 # Found the resource corresponding to name |
752 resource = self.Project.getConfigurationResource(config_name, name) |
743 resource = self.Project.getconfigurationResource(config_name, name) |
753 if resource: |
744 if resource: |
754 # Extract variables from every varLists |
745 # Extract variables from every varLists |
755 for varlist in resource.getGlobalVars(): |
746 for varlist in resource.getglobalVars(): |
756 for var in varlist.getVariable(): |
747 for var in varlist.getvariable(): |
757 tempvar = {"Name":var.getName(),"Class":"Global"} |
748 tempvar = {"Name" : var.getname(), "Class" : "Global"} |
758 vartype_content = var.getType().getContent() |
749 vartype_content = var.gettype().getcontent() |
759 if vartype_content["name"] == "derived": |
750 if vartype_content["name"] == "derived": |
760 tempvar["Type"] = vartype_content["value"].getName() |
751 tempvar["Type"] = vartype_content["value"].getname() |
761 elif vartype_content["name"] in ["string", "wstring"]: |
752 elif vartype_content["name"] in ["string", "wstring"]: |
762 tempvar["Type"] = vartype_content["name"].upper() |
753 tempvar["Type"] = vartype_content["name"].upper() |
763 else: |
754 else: |
764 tempvar["Type"] = vartype_content["name"] |
755 tempvar["Type"] = vartype_content["name"] |
765 tempvar["Edit"] = True |
756 tempvar["Edit"] = True |
766 initial = var.getInitialValue() |
757 initial = var.getinitialValue() |
767 if initial: |
758 if initial: |
768 tempvar["Initial Value"] = initial.getValue() |
759 tempvar["Initial Value"] = initial.getvalue() |
769 else: |
760 else: |
770 tempvar["Initial Value"] = "" |
761 tempvar["Initial Value"] = "" |
771 address = var.getAddress() |
762 address = var.getaddress() |
772 if address: |
763 if address: |
773 tempvar["Location"] = address |
764 tempvar["Location"] = address |
774 else: |
765 else: |
775 tempvar["Location"] = "" |
766 tempvar["Location"] = "" |
776 if varlist.getRetain(): |
767 if varlist.getretain(): |
777 tempvar["Retain"] = "Yes" |
768 tempvar["Retain"] = "Yes" |
778 else: |
769 else: |
779 tempvar["Retain"] = "No" |
770 tempvar["Retain"] = "No" |
780 if varlist.getConstant(): |
771 if varlist.getconstant(): |
781 tempvar["Constant"] = "Yes" |
772 tempvar["Constant"] = "Yes" |
782 else: |
773 else: |
783 tempvar["Constant"] = "No" |
774 tempvar["Constant"] = "No" |
784 vars.append(tempvar) |
775 vars.append(tempvar) |
785 return vars |
776 return vars |
786 |
777 |
787 # Return the interface of the pou given by its name |
778 # Return the interface of the pou given by its name |
788 def GetPouInterfaceVarsByName(self, name): |
779 def GetPouInterfaceVarsByName(self, name): |
789 # Found the pou correponding to name and return the interface |
780 # Found the pou correponding to name and return the interface |
790 return self.GetPouInterfaceVars(self.Project.getPou(name)) |
781 return self.GetPouInterfaceVars(self.Project.getpou(name)) |
791 |
782 |
792 # Return the interface for the given pou |
783 # Return the interface for the given pou |
793 def GetPouInterfaceVars(self, pou): |
784 def GetPouInterfaceVars(self, pou): |
794 vars = [] |
785 vars = [] |
795 # Verify that the pou has an interface |
786 # Verify that the pou has an interface |
796 if pou.interface: |
787 if pou.interface: |
797 # Extract variables from every varLists |
788 # Extract variables from every varLists |
798 for type, varlist in pou.getVars(): |
789 for type, varlist in pou.getvars(): |
799 for var in varlist.getVariable(): |
790 for var in varlist.getvariable(): |
800 tempvar = {"Name":var.getName(),"Class":type} |
791 tempvar = {"Name" : var.getname(), "Class" : type} |
801 vartype_content = var.getType().getContent() |
792 vartype_content = var.gettype().getcontent() |
802 if vartype_content["name"] == "derived": |
793 if vartype_content["name"] == "derived": |
803 tempvar["Type"] = vartype_content["value"].getName() |
794 tempvar["Type"] = vartype_content["value"].getname() |
804 tempvar["Edit"] = not pou.hasBlock(tempvar["Name"]) |
795 tempvar["Edit"] = not pou.hasblock(tempvar["Name"]) |
805 else: |
796 else: |
806 if vartype_content["name"] in ["string", "wstring"]: |
797 if vartype_content["name"] in ["string", "wstring"]: |
807 tempvar["Type"] = vartype_content["name"].upper() |
798 tempvar["Type"] = vartype_content["name"].upper() |
808 else: |
799 else: |
809 tempvar["Type"] = vartype_content["name"] |
800 tempvar["Type"] = vartype_content["name"] |
810 tempvar["Edit"] = True |
801 tempvar["Edit"] = True |
811 initial = var.getInitialValue() |
802 initial = var.getinitialValue() |
812 if initial: |
803 if initial: |
813 tempvar["Initial Value"] = initial.getValue() |
804 tempvar["Initial Value"] = initial.getvalue() |
814 else: |
805 else: |
815 tempvar["Initial Value"] = "" |
806 tempvar["Initial Value"] = "" |
816 address = var.getAddress() |
807 address = var.getaddress() |
817 if address: |
808 if address: |
818 tempvar["Location"] = address |
809 tempvar["Location"] = address |
819 else: |
810 else: |
820 tempvar["Location"] = "" |
811 tempvar["Location"] = "" |
821 if varlist.getRetain(): |
812 if varlist.getretain(): |
822 tempvar["Retain"] = "Yes" |
813 tempvar["Retain"] = "Yes" |
823 else: |
814 else: |
824 tempvar["Retain"] = "No" |
815 tempvar["Retain"] = "No" |
825 if varlist.getConstant(): |
816 if varlist.getconstant(): |
826 tempvar["Constant"] = "Yes" |
817 tempvar["Constant"] = "Yes" |
827 else: |
818 else: |
828 tempvar["Constant"] = "No" |
819 tempvar["Constant"] = "No" |
829 vars.append(tempvar) |
820 vars.append(tempvar) |
830 return vars |
821 return vars |
831 |
822 |
832 # Replace the Pou interface by the one given |
823 # Replace the Pou interface by the one given |
833 def SetPouInterfaceVars(self, name, vars): |
824 def SetPouInterfaceVars(self, name, vars): |
834 # Found the pou corresponding to name and add interface if there isn't one yet |
825 # Found the pou corresponding to name and add interface if there isn't one yet |
835 pou = self.Project.getPou(name) |
826 pou = self.Project.getpou(name) |
836 if not pou.interface: |
827 if not pou.interface: |
837 pou.interface = plcopen.pou_interface() |
828 pou.interface = plcopen.pou_interface() |
838 # Set Pou interface |
829 # Set Pou interface |
839 pou.setVars(self.ExtractVarLists(vars)) |
830 pou.setvars(self.ExtractVarLists(vars)) |
840 self.RefreshPouUsingTree() |
831 self.RefreshPouUsingTree() |
841 self.RefreshBlockTypes() |
832 self.RefreshBlockTypes() |
842 |
833 |
843 # Replace the return type of the pou given by its name (only for functions) |
834 # Replace the return type of the pou given by its name (only for functions) |
844 def SetPouInterfaceReturnType(self, name, type): |
835 def SetPouInterfaceReturnType(self, name, type): |
845 pou = self.Project.getPou(name) |
836 pou = self.Project.getpou(name) |
846 if not pou.interface: |
837 if not pou.interface: |
847 pou.interface = plcopen.pou_interface() |
838 pou.interface = plcopen.pou_interface() |
848 # If there isn't any return type yet, add it |
839 # If there isn't any return type yet, add it |
849 return_type = pou.interface.getReturnType() |
840 return_type = pou.interface.getreturnType() |
850 if not return_type: |
841 if not return_type: |
851 return_type = plcopen.dataType() |
842 return_type = plcopen.dataType() |
852 pou.interface.setReturnType(return_type) |
843 pou.interface.setreturnType(return_type) |
853 # Change return type |
844 # Change return type |
854 if type in self.GetBaseTypes(): |
845 if type in self.GetBaseTypes(): |
855 return_type.setContent(type, None) |
846 if type == "STRING": |
|
847 return_type.setcontent({"name" : "string", "value" : plcopen.elementaryTypes_string()}) |
|
848 elif type == "WSTRING": |
|
849 return_type.setcontent({"name" : "wstring", "value" : plcopen.elementaryTypes_wstring()}) |
|
850 else: |
|
851 return_type.setcontent({"name" : type, "value" : None}) |
856 else: |
852 else: |
857 derived_type = plcopen.derived() |
853 derived_type = plcopen.derivedTypes_derived() |
858 derived_type.setName(type) |
854 derived_type.setname(type) |
859 return_type.setContent("derived", derived_type) |
855 return_type.setcontent({"name" : "derived", "value" : derived_type}) |
860 self.RefreshBlockTypes() |
856 self.RefreshBlockTypes() |
861 |
857 |
862 def UpdateProjectUsedPous(self, old_name, new_name): |
858 def UpdateProjectUsedPous(self, old_name, new_name): |
863 if self.Project: |
859 if self.Project: |
864 self.Project.updateElementName(old_name, new_name) |
860 self.Project.updateElementName(old_name, new_name) |
1325 instance = None |
1324 instance = None |
1326 element = self.GetEditedElement(tagname) |
1325 element = self.GetEditedElement(tagname) |
1327 if element is not None: |
1326 if element is not None: |
1328 # if id is defined |
1327 # if id is defined |
1329 if id is not None: |
1328 if id is not None: |
1330 instance = element.getInstance(id) |
1329 instance = element.getinstance(id) |
1331 else: |
1330 else: |
1332 instance = element.getRandomInstance(exclude) |
1331 instance = element.getrandomInstance(exclude) |
1333 if instance is not None: |
1332 if instance is not None: |
1334 if id is not None: |
1333 if id is not None: |
1335 infos["id"] = id |
1334 infos["id"] = id |
1336 else: |
1335 else: |
1337 infos["id"] = instance.getLocalId() |
1336 infos["id"] = instance.getlocalId() |
1338 infos["x"] = instance.getX() |
1337 infos["x"] = instance.getx() |
1339 infos["y"] = instance.getY() |
1338 infos["y"] = instance.gety() |
1340 infos["height"] = instance.getHeight() |
1339 infos["height"] = instance.getheight() |
1341 infos["width"] = instance.getWidth() |
1340 infos["width"] = instance.getwidth() |
1342 if isinstance(instance, plcopen.block): |
1341 if isinstance(instance, plcopen.fbdObjects_block): |
1343 infos["name"] = instance.getInstanceName() |
1342 infos["name"] = instance.getinstanceName() |
1344 infos["type"] = instance.getTypeName() |
1343 infos["type"] = instance.gettypeName() |
1345 executionOrder = instance.getExecutionOrderId() |
1344 executionOrder = instance.getexecutionOrderId() |
1346 if executionOrder is not None: |
1345 if executionOrder is not None: |
1347 infos["executionOrder"] = executionOrder |
1346 infos["executionOrder"] = executionOrder |
1348 else: |
1347 else: |
1349 infos["executionOrder"] = 0 |
1348 infos["executionOrder"] = 0 |
1350 infos["connectors"] = {"inputs":[],"outputs":[]} |
1349 infos["connectors"] = {"inputs":[],"outputs":[]} |
1351 for variable in instance.inputVariables.getVariable(): |
1350 for variable in instance.inputVariables.getvariable(): |
1352 connector = {} |
1351 connector = {} |
1353 connector["name"] = variable.getFormalParameter() |
1352 connector["name"] = variable.getformalParameter() |
1354 connector["position"] = variable.connectionPointIn.getRelPosition() |
1353 connector["position"] = variable.connectionPointIn.getrelPositionXY() |
1355 connector["negated"] = variable.getNegated() |
1354 connector["negated"] = variable.getnegated() |
1356 connector["edge"] = variable.getConnectorEdge() |
1355 connector["edge"] = variable.getedge() |
1357 connector["links"] = [] |
1356 connector["links"] = [] |
1358 connections = variable.connectionPointIn.getConnections() |
1357 connections = variable.connectionPointIn.getconnections() |
1359 if connections: |
1358 if connections: |
1360 for link in connections: |
1359 for link in connections: |
1361 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1360 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1362 connector["links"].append(dic) |
1361 connector["links"].append(dic) |
1363 infos["connectors"]["inputs"].append(connector) |
1362 infos["connectors"]["inputs"].append(connector) |
1364 for variable in instance.outputVariables.getVariable(): |
1363 for variable in instance.outputVariables.getvariable(): |
1365 connector = {} |
1364 connector = {} |
1366 connector["name"] = variable.getFormalParameter() |
1365 connector["name"] = variable.getformalParameter() |
1367 connector["position"] = variable.connectionPointOut.getRelPosition() |
1366 connector["position"] = variable.connectionPointOut.getrelPositionXY() |
1368 connector["negated"] = variable.getNegated() |
1367 connector["negated"] = variable.getnegated() |
1369 connector["edge"] = variable.getConnectorEdge() |
1368 connector["edge"] = variable.getedge() |
1370 infos["connectors"]["outputs"].append(connector) |
1369 infos["connectors"]["outputs"].append(connector) |
1371 elif isinstance(instance, plcopen.inVariable): |
1370 elif isinstance(instance, plcopen.fbdObjects_inVariable): |
1372 infos["name"] = instance.getExpression() |
1371 infos["name"] = instance.getexpression() |
1373 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"]) |
1372 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"]) |
1374 infos["type"] = "input" |
1373 infos["type"] = "input" |
1375 executionOrder = instance.getExecutionOrderId() |
1374 executionOrder = instance.getexecutionOrderId() |
1376 if executionOrder is not None: |
1375 if executionOrder is not None: |
1377 infos["executionOrder"] = executionOrder |
1376 infos["executionOrder"] = executionOrder |
1378 else: |
1377 else: |
1379 infos["executionOrder"] = 0 |
1378 infos["executionOrder"] = 0 |
1380 infos["connector"] = {} |
1379 infos["connector"] = {} |
1381 infos["connector"]["position"] = instance.connectionPointOut.getRelPosition() |
1380 infos["connector"]["position"] = instance.connectionPointOut.getrelPositionXY() |
1382 infos["connector"]["negated"] = instance.getNegated() |
1381 infos["connector"]["negated"] = instance.getnegated() |
1383 infos["connector"]["edge"] = instance.getConnectorEdge() |
1382 infos["connector"]["edge"] = instance.getedge() |
1384 elif isinstance(instance, plcopen.outVariable): |
1383 elif isinstance(instance, plcopen.fbdObjects_outVariable): |
1385 infos["name"] = instance.getExpression() |
1384 infos["name"] = instance.getexpression() |
1386 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"]) |
1385 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"]) |
1387 infos["type"] = "output" |
1386 infos["type"] = "output" |
1388 executionOrder = instance.getExecutionOrderId() |
1387 executionOrder = instance.getexecutionOrderId() |
1389 if executionOrder is not None: |
1388 if executionOrder is not None: |
1390 infos["executionOrder"] = executionOrder |
1389 infos["executionOrder"] = executionOrder |
1391 else: |
1390 else: |
1392 infos["executionOrder"] = 0 |
1391 infos["executionOrder"] = 0 |
1393 infos["connector"] = {} |
1392 infos["connector"] = {} |
1394 infos["connector"]["position"] = instance.connectionPointIn.getRelPosition() |
1393 infos["connector"]["position"] = instance.connectionPointIn.getrelPositionXY() |
1395 infos["connector"]["negated"] = instance.getNegated() |
1394 infos["connector"]["negated"] = instance.getnegated() |
1396 infos["connector"]["edge"] = instance.getConnectorEdge() |
1395 infos["connector"]["edge"] = instance.getedge() |
1397 infos["connector"]["links"] = [] |
1396 infos["connector"]["links"] = [] |
1398 connections = instance.connectionPointIn.getConnections() |
1397 connections = instance.connectionPointIn.getconnections() |
1399 if connections: |
1398 if connections: |
1400 for link in connections: |
1399 for link in connections: |
1401 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1400 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1402 infos["connector"]["links"].append(dic) |
1401 infos["connector"]["links"].append(dic) |
1403 elif isinstance(instance, plcopen.inOutVariable): |
1402 elif isinstance(instance, plcopen.fbdObjects_inOutVariable): |
1404 infos["name"] = instance.getExpression() |
1403 infos["name"] = instance.getexpression() |
1405 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"]) |
1404 infos["value_type"] = self.GetEditedElementVarValueType(tagname, infos["name"]) |
1406 infos["type"] = "inout" |
1405 infos["type"] = "inout" |
1407 executionOrder = instance.getExecutionOrderId() |
1406 executionOrder = instance.getexecutionOrderId() |
1408 if executionOrder is not None: |
1407 if executionOrder is not None: |
1409 infos["executionOrder"] = executionOrder |
1408 infos["executionOrder"] = executionOrder |
1410 else: |
1409 else: |
1411 infos["executionOrder"] = 0 |
1410 infos["executionOrder"] = 0 |
1412 infos["connectors"] = {"input":{},"output":{}} |
1411 infos["connectors"] = {"input":{},"output":{}} |
1413 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition() |
1412 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getrelPositionXY() |
1414 infos["connectors"]["output"]["negated"] = instance.getNegatedOut() |
1413 infos["connectors"]["output"]["negated"] = instance.getnegatedOut() |
1415 infos["connectors"]["output"]["edge"] = instance.getOutputEdge() |
1414 infos["connectors"]["output"]["edge"] = instance.getedgeOut() |
1416 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
1415 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getrelPositionXY() |
1417 infos["connectors"]["input"]["negated"] = instance.getNegatedIn() |
1416 infos["connectors"]["input"]["negated"] = instance.getnegatedIn() |
1418 infos["connectors"]["input"]["edge"] = instance.getInputEdge() |
1417 infos["connectors"]["input"]["edge"] = instance.getedgeIn() |
1419 infos["connectors"]["input"]["links"] = [] |
1418 infos["connectors"]["input"]["links"] = [] |
1420 connections = instance.connectionPointIn.getConnections() |
1419 connections = instance.connectionPointIn.getconnections() |
1421 if connections: |
1420 if connections: |
1422 for link in connections: |
1421 for link in connections: |
1423 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1422 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1424 infos["connectors"]["input"]["links"].append(dic) |
1423 infos["connectors"]["input"]["links"].append(dic) |
1425 elif isinstance(instance, plcopen.continuation): |
1424 elif isinstance(instance, plcopen.commonObjects_continuation): |
1426 infos["name"] = instance.getName() |
1425 infos["name"] = instance.getname() |
1427 infos["type"] = "continuation" |
1426 infos["type"] = "continuation" |
1428 infos["connector"] = {} |
1427 infos["connector"] = {} |
1429 infos["connector"]["position"] = instance.connectionPointOut.getRelPosition() |
1428 infos["connector"]["position"] = instance.connectionPointOut.getrelPositionXY() |
1430 elif isinstance(instance, plcopen.connector): |
1429 elif isinstance(instance, plcopen.commonObjects_connector): |
1431 infos["name"] = instance.getName() |
1430 infos["name"] = instance.getName() |
1432 infos["type"] = "connection" |
1431 infos["type"] = "connection" |
1433 infos["connector"] = {} |
1432 infos["connector"] = {} |
1434 infos["connector"]["position"] = instance.connectionPointIn.getRelPosition() |
1433 infos["connector"]["position"] = instance.connectionPointIn.getrelPositionXY() |
1435 infos["connector"]["links"] = [] |
1434 infos["connector"]["links"] = [] |
1436 connections = instance.connectionPointIn.getConnections() |
1435 connections = instance.connectionPointIn.getconnections() |
1437 if connections: |
1436 if connections: |
1438 for link in connections: |
1437 for link in connections: |
1439 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1438 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1440 infos["connector"]["links"].append(dic) |
1439 infos["connector"]["links"].append(dic) |
1441 elif isinstance(instance, plcopen.comment): |
1440 elif isinstance(instance, plcopen.commonObjects_comment): |
1442 infos["type"] = "comment" |
1441 infos["type"] = "comment" |
1443 infos["content"] = instance.getContentText() |
1442 infos["content"] = instance.getcontentText() |
1444 elif isinstance(instance, plcopen.leftPowerRail): |
1443 elif isinstance(instance, plcopen.ldObjects_leftPowerRail): |
1445 infos["type"] = "leftPowerRail" |
1444 infos["type"] = "leftPowerRail" |
1446 infos["connectors"] = [] |
1445 infos["connectors"] = [] |
1447 for connection in instance.getConnectionPointOut(): |
1446 for connection in instance.getconnectionPointOut(): |
1448 connector = {} |
1447 connector = {} |
1449 connector["position"] = connection.getRelPosition() |
1448 connector["position"] = connection.getrelPositionXY() |
1450 infos["connectors"].append(connector) |
1449 infos["connectors"].append(connector) |
1451 elif isinstance(instance, plcopen.rightPowerRail): |
1450 elif isinstance(instance, plcopen.ldObjects_rightPowerRail): |
1452 infos["type"] = "rightPowerRail" |
1451 infos["type"] = "rightPowerRail" |
1453 infos["connectors"] = [] |
1452 infos["connectors"] = [] |
1454 for connection in instance.getConnectionPointIn(): |
1453 for connection in instance.getconnectionPointIn(): |
1455 connector = {} |
1454 connector = {} |
1456 connector["position"] = connection.getRelPosition() |
1455 connector["position"] = connection.getrelPositionXY() |
1457 connector["links"] = [] |
1456 connector["links"] = [] |
1458 connections = connection.getConnections() |
1457 connections = connection.getconnections() |
1459 if connections: |
1458 if connections: |
1460 for link in connection.getConnections(): |
1459 for link in connection.getconnections(): |
1461 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1460 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1462 connector["links"].append(dic) |
1461 connector["links"].append(dic) |
1463 infos["connectors"].append(connector) |
1462 infos["connectors"].append(connector) |
1464 elif isinstance(instance, plcopen.contact): |
1463 elif isinstance(instance, plcopen.ldObjects_contact): |
1465 infos["name"] = instance.getVariable() |
1464 infos["name"] = instance.getvariable() |
1466 infos["type"] = "contact" |
1465 infos["type"] = "contact" |
1467 executionOrder = instance.getExecutionOrderId() |
1466 executionOrder = instance.getexecutionOrderId() |
1468 if executionOrder is not None: |
1467 if executionOrder is not None: |
1469 infos["executionOrder"] = executionOrder |
1468 infos["executionOrder"] = executionOrder |
1470 else: |
1469 else: |
1471 infos["executionOrder"] = 0 |
1470 infos["executionOrder"] = 0 |
1472 infos["negated"] = instance.getNegated() |
1471 infos["negated"] = instance.getnegated() |
1473 infos["edge"] = instance.getContactEdge() |
1472 infos["edge"] = instance.getedge() |
1474 infos["connectors"] = {"input":{},"output":{}} |
1473 infos["connectors"] = {"input":{},"output":{}} |
1475 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
1474 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getrelPositionXY() |
1476 infos["connectors"]["input"]["links"] = [] |
1475 infos["connectors"]["input"]["links"] = [] |
1477 connections = instance.connectionPointIn.getConnections() |
1476 connections = instance.connectionPointIn.getconnections() |
1478 if connections: |
1477 if connections: |
1479 for link in connections: |
1478 for link in connections: |
1480 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1479 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1481 infos["connectors"]["input"]["links"].append(dic) |
1480 infos["connectors"]["input"]["links"].append(dic) |
1482 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition() |
1481 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getrelPositionXY() |
1483 elif isinstance(instance, plcopen.coil): |
1482 elif isinstance(instance, plcopen.ldObjects_coil): |
1484 infos["name"] = instance.getVariable() |
1483 infos["name"] = instance.getvariable() |
1485 infos["type"] = "coil" |
1484 infos["type"] = "coil" |
1486 executionOrder = instance.getExecutionOrderId() |
1485 executionOrder = instance.getexecutionOrderId() |
1487 if executionOrder is not None: |
1486 if executionOrder is not None: |
1488 infos["executionOrder"] = executionOrder |
1487 infos["executionOrder"] = executionOrder |
1489 else: |
1488 else: |
1490 infos["executionOrder"] = 0 |
1489 infos["executionOrder"] = 0 |
1491 infos["negated"] = instance.getNegated() |
1490 infos["negated"] = instance.getnegated() |
1492 infos["storage"] = instance.getCoilStorage() |
1491 infos["storage"] = instance.getstorage() |
1493 infos["connectors"] = {"input":{},"output":{}} |
1492 infos["connectors"] = {"input":{},"output":{}} |
1494 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
1493 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getrelPositionXY() |
1495 infos["connectors"]["input"]["links"] = [] |
1494 infos["connectors"]["input"]["links"] = [] |
1496 connections = instance.connectionPointIn.getConnections() |
1495 connections = instance.connectionPointIn.getconnections() |
1497 if connections: |
1496 if connections: |
1498 for link in connections: |
1497 for link in connections: |
1499 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1498 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1500 infos["connectors"]["input"]["links"].append(dic) |
1499 infos["connectors"]["input"]["links"].append(dic) |
1501 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition() |
1500 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getrelPositionXY() |
1502 elif isinstance(instance, plcopen.step): |
1501 elif isinstance(instance, plcopen.sfcObjects_step): |
1503 infos["name"] = instance.getName() |
1502 infos["name"] = instance.getname() |
1504 infos["type"] = "step" |
1503 infos["type"] = "step" |
1505 infos["initial"] = instance.getInitialStep() |
1504 infos["initial"] = instance.getinitialStep() |
1506 infos["connectors"] = {} |
1505 infos["connectors"] = {} |
1507 if instance.connectionPointIn: |
1506 if instance.connectionPointIn: |
1508 infos["connectors"]["input"] = {} |
1507 infos["connectors"]["input"] = {} |
1509 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
1508 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getrelPositionXY() |
1510 infos["connectors"]["input"]["links"] = [] |
1509 infos["connectors"]["input"]["links"] = [] |
1511 connections = instance.connectionPointIn.getConnections() |
1510 connections = instance.connectionPointIn.getconnections() |
1512 if connections: |
1511 if connections: |
1513 for link in connections: |
1512 for link in connections: |
1514 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1513 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1515 infos["connectors"]["input"]["links"].append(dic) |
1514 infos["connectors"]["input"]["links"].append(dic) |
1516 if instance.connectionPointOut: |
1515 if instance.connectionPointOut: |
1517 infos["connectors"]["output"] = {"position" : instance.connectionPointOut.getRelPosition()} |
1516 infos["connectors"]["output"] = {"position" : instance.connectionPointOut.getrelPositionXY()} |
1518 if instance.connectionPointOutAction: |
1517 if instance.connectionPointOutAction: |
1519 infos["connectors"]["action"] = {"position" : instance.connectionPointOutAction.getRelPosition()} |
1518 infos["connectors"]["action"] = {"position" : instance.connectionPointOutAction.getrelPositionXY()} |
1520 elif isinstance(instance, plcopen.transition): |
1519 elif isinstance(instance, plcopen.sfcObjects_transition): |
1521 infos["type"] = "transition" |
1520 infos["type"] = "transition" |
1522 condition = instance.getConditionContent() |
1521 condition = instance.getconditionContent() |
1523 priority = instance.getPriority() |
1522 priority = instance.getpriority() |
1524 if priority == None: |
1523 if priority == None: |
1525 infos["priority"] = 0 |
1524 infos["priority"] = 0 |
1526 else: |
1525 else: |
1527 infos["priority"] = priority |
1526 infos["priority"] = priority |
1528 infos["condition_type"] = condition["type"] |
1527 infos["condition_type"] = condition["type"] |
1529 infos["connectors"] = {"input":{},"output":{}} |
1528 infos["connectors"] = {"input":{},"output":{}} |
1530 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getRelPosition() |
1529 infos["connectors"]["input"]["position"] = instance.connectionPointIn.getrelPositionXY() |
1531 infos["connectors"]["input"]["links"] = [] |
1530 infos["connectors"]["input"]["links"] = [] |
1532 connections = instance.connectionPointIn.getConnections() |
1531 connections = instance.connectionPointIn.getconnections() |
1533 if connections: |
1532 if connections: |
1534 for link in connections: |
1533 for link in connections: |
1535 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1534 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1536 infos["connectors"]["input"]["links"].append(dic) |
1535 infos["connectors"]["input"]["links"].append(dic) |
1537 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition() |
1536 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getrelPositionXY() |
1538 if infos["condition_type"] == "connection": |
1537 if infos["condition_type"] == "connection": |
1539 infos["connectors"]["connection"] = {} |
1538 infos["connectors"]["connection"] = {} |
1540 infos["connectors"]["connection"]["links"] = [] |
1539 infos["connectors"]["connection"]["links"] = [] |
1541 connections = instance.getConnections() |
1540 connections = instance.getconnections() |
1542 if connections: |
1541 if connections: |
1543 for link in connections: |
1542 for link in connections: |
1544 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1543 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1545 infos["connectors"]["connection"]["links"].append(dic) |
1544 infos["connectors"]["connection"]["links"].append(dic) |
1546 infos["condition"] = None |
1545 infos["condition"] = None |
1547 else: |
1546 else: |
1548 infos["condition"] = condition["value"] |
1547 infos["condition"] = condition["value"] |
1549 elif isinstance(instance, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)): |
1548 elif isinstance(instance, (plcopen.sfcObjects_selectionDivergence, plcopen.sfcObjects_simultaneousDivergence)): |
1550 if isinstance(instance, plcopen.selectionDivergence): |
1549 if isinstance(instance, plcopen.sfcObjects_selectionDivergence): |
1551 infos["type"] = "selectionDivergence" |
1550 infos["type"] = "selectionDivergence" |
1552 else: |
1551 else: |
1553 infos["type"] = "simultaneousDivergence" |
1552 infos["type"] = "simultaneousDivergence" |
1554 infos["connectors"] = {"inputs":[],"outputs":[]} |
1553 infos["connectors"] = {"inputs":[],"outputs":[]} |
1555 connector = {} |
1554 connector = {} |
1556 connector["position"] = instance.connectionPointIn.getRelPosition() |
1555 connector["position"] = instance.connectionPointIn.getrelPositionXY() |
1557 connector["links"] = [] |
1556 connector["links"] = [] |
1558 connections = instance.connectionPointIn.getConnections() |
1557 connections = instance.connectionPointIn.getconnections() |
1559 if connections: |
1558 if connections: |
1560 for link in connections: |
1559 for link in connections: |
1561 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1560 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1562 connector["links"].append(dic) |
1561 connector["links"].append(dic) |
1563 infos["connectors"]["inputs"].append(connector) |
1562 infos["connectors"]["inputs"].append(connector) |
1564 for sequence in instance.getConnectionPointOut(): |
1563 for sequence in instance.getconnectionPointOut(): |
1565 connector = {} |
1564 connector = {} |
1566 connector["position"] = sequence.getRelPosition() |
1565 connector["position"] = sequence.getrelPositionXY() |
1567 infos["connectors"]["outputs"].append(connector) |
1566 infos["connectors"]["outputs"].append(connector) |
1568 elif isinstance(instance, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)): |
1567 elif isinstance(instance, (plcopen.sfcObjects_selectionConvergence, plcopen.sfcObjects_simultaneousConvergence)): |
1569 if isinstance(instance, plcopen.selectionConvergence): |
1568 if isinstance(instance, plcopen.sfcObjects_selectionConvergence): |
1570 infos["type"] = "selectionConvergence" |
1569 infos["type"] = "selectionConvergence" |
1571 else: |
1570 else: |
1572 infos["type"] = "simultaneousConvergence" |
1571 infos["type"] = "simultaneousConvergence" |
1573 infos["connectors"] = {"inputs":[],"outputs":[]} |
1572 infos["connectors"] = {"inputs":[],"outputs":[]} |
1574 for sequence in instance.getConnectionPointIn(): |
1573 for sequence in instance.getconnectionPointIn(): |
1575 connector = {} |
1574 connector = {} |
1576 connector["position"] = sequence.getRelPosition() |
1575 connector["position"] = sequence.getrelPositionXY() |
1577 connector["links"] = [] |
1576 connector["links"] = [] |
1578 connections = sequence.getConnections() |
1577 connections = sequence.getconnections() |
1579 if connections: |
1578 if connections: |
1580 for link in connections: |
1579 for link in connections: |
1581 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1580 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1582 connector["links"].append(dic) |
1581 connector["links"].append(dic) |
1583 infos["connectors"]["inputs"].append(connector) |
1582 infos["connectors"]["inputs"].append(connector) |
1584 connector = {} |
1583 connector = {} |
1585 connector["position"] = instance.connectionPointOut.getRelPosition() |
1584 connector["position"] = instance.connectionPointOut.getrelPositionXY() |
1586 infos["connectors"]["outputs"].append(connector) |
1585 infos["connectors"]["outputs"].append(connector) |
1587 elif isinstance(instance, plcopen.jumpStep): |
1586 elif isinstance(instance, plcopen.sfcObjects_jumpStep): |
1588 infos["type"] = "jump" |
1587 infos["type"] = "jump" |
1589 infos["target"] = instance.getTargetName() |
1588 infos["target"] = instance.gettargetName() |
1590 infos["connector"] = {} |
1589 infos["connector"] = {} |
1591 infos["connector"]["position"] = instance.connectionPointIn.getRelPosition() |
1590 infos["connector"]["position"] = instance.connectionPointIn.getrelPositionXY() |
1592 infos["connector"]["links"] = [] |
1591 infos["connector"]["links"] = [] |
1593 connections = instance.connectionPointIn.getConnections() |
1592 connections = instance.connectionPointIn.getconnections() |
1594 if connections: |
1593 if connections: |
1595 for link in connections: |
1594 for link in connections: |
1596 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1595 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1597 infos["connector"]["links"].append(dic) |
1596 infos["connector"]["links"].append(dic) |
1598 elif isinstance(instance, plcopen.actionBlock): |
1597 elif isinstance(instance, plcopen.commonObjects_actionBlock): |
1599 infos["type"] = "actionBlock" |
1598 infos["type"] = "actionBlock" |
1600 infos["actions"] = instance.getActions() |
1599 infos["actions"] = instance.getactions() |
1601 infos["connector"] = {} |
1600 infos["connector"] = {} |
1602 infos["connector"]["position"] = instance.connectionPointIn.getRelPosition() |
1601 infos["connector"]["position"] = instance.connectionPointIn.getrelPositionXY() |
1603 infos["connector"]["links"] = [] |
1602 infos["connector"]["links"] = [] |
1604 connections = instance.connectionPointIn.getConnections() |
1603 connections = instance.connectionPointIn.getconnections() |
1605 if connections: |
1604 if connections: |
1606 for link in connections: |
1605 for link in connections: |
1607 dic = {"refLocalId":link.getRefLocalId(),"points":link.getPoints(),"formalParameter":link.getFormalParameter()} |
1606 dic = {"refLocalId":link.getrefLocalId(),"points":link.getpoints(),"formalParameter":link.getformalParameter()} |
1608 infos["connector"]["links"].append(dic) |
1607 infos["connector"]["links"].append(dic) |
1609 return infos |
1608 return infos |
1610 return False |
1609 return False |
1611 |
1610 |
1612 def ClearEditedElementExecutionOrder(self, tagname): |
1611 def ClearEditedElementExecutionOrder(self, tagname): |
1613 element = self.GetEditedElement(tagname) |
1612 element = self.GetEditedElement(tagname) |
1614 if element is not None: |
1613 if element is not None: |
1615 element.resetExecutionOrder() |
1614 element.resetexecutionOrder() |
1616 |
1615 |
1617 def ResetEditedElementExecutionOrder(self, tagname): |
1616 def ResetEditedElementExecutionOrder(self, tagname): |
1618 element = self.GetEditedElement(tagname) |
1617 element = self.GetEditedElement(tagname) |
1619 if element is not None: |
1618 if element is not None: |
1620 element.compileExecutionOrder() |
1619 element.compileexecutionOrder() |
1621 |
1620 |
1622 # Return the variable type of the given pou |
1621 # Return the variable type of the given pou |
1623 def GetEditedElementVarValueType(self, tagname, varname): |
1622 def GetEditedElementVarValueType(self, tagname, varname): |
1624 words = tagname.split("::") |
1623 words = tagname.split("::") |
1625 if words[0] in ["P","T","A"]: |
1624 if words[0] in ["P","T","A"]: |
1626 pou = self.Project.getPou(words[1]) |
1625 pou = self.Project.getpou(words[1]) |
1627 for type, varlist in pou.getVars(): |
1626 for type, varlist in pou.getvars(): |
1628 for var in varlist.getVariable(): |
1627 for var in varlist.getvariable(): |
1629 if var.getName() == varname: |
1628 if var.getname() == varname: |
1630 vartype_content = var.getType().getContent() |
1629 vartype_content = var.gettype().getcontent() |
1631 if vartype_content["name"] == "derived": |
1630 if vartype_content["name"] == "derived": |
1632 return vartype_content["value"].getName() |
1631 return vartype_content["value"].getname() |
1633 elif vartype_content["name"] in ["string", "wstring"]: |
1632 elif vartype_content["name"] in ["string", "wstring"]: |
1634 return vartype_content["name"].upper() |
1633 return vartype_content["name"].upper() |
1635 else: |
1634 else: |
1636 return vartype_content["name"] |
1635 return vartype_content["name"] |
1637 return None |
1636 return None |
1645 result = wire.GetConnectedInfos(-1) |
1644 result = wire.GetConnectedInfos(-1) |
1646 else: |
1645 else: |
1647 result = wire.GetConnectedInfos(0) |
1646 result = wire.GetConnectedInfos(0) |
1648 if result != None: |
1647 if result != None: |
1649 refLocalId, formalParameter = result |
1648 refLocalId, formalParameter = result |
1650 connection.addConnection() |
1649 connection.addconnection() |
1651 connection.setConnectionId(idx, refLocalId) |
1650 connection.setconnectionId(idx, refLocalId) |
1652 connection.setConnectionPoints(idx, points) |
1651 connection.setconnectionPoints(idx, points) |
1653 if formalParameter != "": |
1652 if formalParameter != "": |
1654 connection.setConnectionParameter(idx, formalParameter) |
1653 connection.setconnectionParameter(idx, formalParameter) |
1655 else: |
1654 else: |
1656 connection.setConnectionParameter(idx, None) |
1655 connection.setconnectionParameter(idx, None) |
1657 idx += 1 |
1656 idx += 1 |
1658 |
1657 |
1659 def AddEditedElementPouVar(self, tagname, type, name): |
1658 def AddEditedElementPouVar(self, tagname, type, name): |
1660 words = tagname.split("::") |
1659 words = tagname.split("::") |
1661 if words[0] in ['P', 'T', 'A']: |
1660 if words[0] in ['P', 'T', 'A']: |
1662 pou = self.Project.getPou(words[1]) |
1661 pou = self.Project.getpou(words[1]) |
1663 pou.addPouVar(type, name) |
1662 pou.addpouVar(type, name) |
1664 |
1663 |
1665 def ChangeEditedElementPouVar(self, tagname, old_type, old_name, new_type, new_name): |
1664 def ChangeEditedElementPouVar(self, tagname, old_type, old_name, new_type, new_name): |
1666 words = tagname.split("::") |
1665 words = tagname.split("::") |
1667 if words[0] in ['P', 'T', 'A']: |
1666 if words[0] in ['P', 'T', 'A']: |
1668 pou = self.Project.getPou(words[1]) |
1667 pou = self.Project.getpou(words[1]) |
1669 pou.changePouVar(old_type, old_name, new_type, new_name) |
1668 pou.changepouVar(old_type, old_name, new_type, new_name) |
1670 |
1669 |
1671 def AddEditedElementBlock(self, tagname, id, blocktype, blockname = None): |
1670 def AddEditedElementBlock(self, tagname, id, blocktype, blockname = None): |
1672 element = self.GetEditedElement(tagname) |
1671 element = self.GetEditedElement(tagname) |
1673 if element is not None: |
1672 if element is not None: |
1674 block = plcopen.block() |
1673 block = plcopen.fbdObjects_block() |
1675 block.setLocalId(id) |
1674 block.setlocalId(id) |
1676 block.setTypeName(blocktype) |
1675 block.settypeName(blocktype) |
1677 blocktype_infos = GetBlockType(blocktype) |
1676 blocktype_infos = GetBlockType(blocktype) |
1678 if blocktype_infos["type"] != "function" and blockname is not None: |
1677 if blocktype_infos["type"] != "function" and blockname is not None: |
1679 block.setInstanceName(blockname) |
1678 block.setinstanceName(blockname) |
1680 self.AddEditedElementPouVar(tagname, blocktype, blockname) |
1679 self.AddEditedElementPouVar(tagname, blocktype, blockname) |
1681 element.addInstance("block", block) |
1680 element.addinstance("block", block) |
1682 self.RefreshPouUsingTree() |
1681 self.RefreshPouUsingTree() |
1683 |
1682 |
1684 def SetEditedElementBlockInfos(self, tagname, id, infos): |
1683 def SetEditedElementBlockInfos(self, tagname, id, infos): |
1685 element = self.GetEditedElement(tagname) |
1684 element = self.GetEditedElement(tagname) |
1686 if element is not None: |
1685 if element is not None: |
1687 block = element.getInstance(id) |
1686 block = element.getinstance(id) |
1688 blocktype = infos.get("type", block.getTypeName()) |
1687 blocktype = infos.get("type", block.gettypeName()) |
1689 blocktype_infos = GetBlockType(blocktype) |
1688 blocktype_infos = GetBlockType(blocktype) |
1690 if blocktype_infos["type"] != "function": |
1689 if blocktype_infos["type"] != "function": |
1691 if "name" in infos or "type" in infos: |
1690 if "name" in infos or "type" in infos: |
1692 old_name = block.getInstanceName() |
1691 old_name = block.getinstanceName() |
1693 old_type = block.getTypeName() |
1692 old_type = block.gettypeName() |
1694 new_name = infos.get("name", old_name) |
1693 new_name = infos.get("name", old_name) |
1695 new_type = infos.get("type", old_type) |
1694 new_type = infos.get("type", old_type) |
1696 self.ChangeEditedElementPouVar(tagname, old_type, old_name, new_type, new_name) |
1695 self.ChangeEditedElementPouVar(tagname, old_type, old_name, new_type, new_name) |
1697 for param, value in infos.items(): |
1696 for param, value in infos.items(): |
1698 if param == "name": |
1697 if param == "name": |
1699 block.setInstanceName(value) |
1698 block.setinstanceName(value) |
1700 elif param == "type": |
1699 elif param == "type": |
1701 block.setTypeName(value) |
1700 block.settypeName(value) |
1702 elif param == "executionOrder" and block.getExecutionOrderId() != value: |
1701 elif param == "executionOrder" and block.getexecutionOrderId() != value: |
1703 self.GetEditedElement(tagname).setElementExecutionOrder(block, value) |
1702 self.GetEditedElement(tagname).setelementExecutionOrder(block, value) |
1704 elif param == "height": |
1703 elif param == "height": |
1705 block.setHeight(value) |
1704 block.setheight(value) |
1706 elif param == "width": |
1705 elif param == "width": |
1707 block.setWidth(value) |
1706 block.setwidth(value) |
1708 elif param == "x": |
1707 elif param == "x": |
1709 block.setX(value) |
1708 block.setx(value) |
1710 elif param == "y": |
1709 elif param == "y": |
1711 block.setY(value) |
1710 block.sety(value) |
1712 elif param == "connectors": |
1711 elif param == "connectors": |
1713 block.inputVariables.setVariable([]) |
1712 block.inputVariables.setvariable([]) |
1714 block.outputVariables.setVariable([]) |
1713 block.outputVariables.setvariable([]) |
1715 for connector in value["inputs"]: |
1714 for connector in value["inputs"]: |
1716 variable = plcopen.inputVariables_variable() |
1715 variable = plcopen.inputVariables_variable() |
1717 variable.setFormalParameter(connector.GetName()) |
1716 variable.setformalParameter(connector.GetName()) |
1718 if connector.IsNegated(): |
1717 if connector.IsNegated(): |
1719 variable.setNegated(True) |
1718 variable.setnegated(True) |
1720 if connector.GetEdge() != "none": |
1719 if connector.GetEdge() != "none": |
1721 variable.setConnectorEdge(connector.GetEdge()) |
1720 variable.setedge(connector.GetEdge()) |
1722 position = connector.GetRelPosition() |
1721 position = connector.GetRelPosition() |
1723 variable.connectionPointIn.setRelPosition(position.x, position.y) |
1722 variable.connectionPointIn.setrelPositionXY(position.x, position.y) |
1724 self.SetConnectionWires(variable.connectionPointIn, connector) |
1723 self.SetConnectionWires(variable.connectionPointIn, connector) |
1725 block.inputVariables.appendVariable(variable) |
1724 block.inputVariables.appendvariable(variable) |
1726 for connector in value["outputs"]: |
1725 for connector in value["outputs"]: |
1727 variable = plcopen.outputVariables_variable() |
1726 variable = plcopen.outputVariables_variable() |
1728 variable.setFormalParameter(connector.GetName()) |
1727 variable.setformalParameter(connector.GetName()) |
1729 if connector.IsNegated(): |
1728 if connector.IsNegated(): |
1730 variable.setNegated(True) |
1729 variable.setnegated(True) |
1731 if connector.GetEdge() != "none": |
1730 if connector.GetEdge() != "none": |
1732 variable.setConnectorEdge(connector.GetEdge()) |
1731 variable.setedge(connector.GetEdge()) |
1733 position = connector.GetRelPosition() |
1732 position = connector.GetRelPosition() |
1734 variable.addConnectionPointOut() |
1733 variable.addconnectionPointOut() |
1735 variable.connectionPointOut.setRelPosition(position.x, position.y) |
1734 variable.connectionPointOut.setrelPositionXY(position.x, position.y) |
1736 block.outputVariables.appendVariable(variable) |
1735 block.outputVariables.appendvariable(variable) |
1737 self.RefreshPouUsingTree() |
1736 self.RefreshPouUsingTree() |
1738 |
1737 |
1739 def AddEditedElementVariable(self, tagname, id, type): |
1738 def AddEditedElementVariable(self, tagname, id, type): |
1740 element = self.GetEditedElement(tagname) |
1739 element = self.GetEditedElement(tagname) |
1741 if element is not None: |
1740 if element is not None: |
1742 if type == INPUT: |
1741 if type == INPUT: |
1743 name = "inVariable" |
1742 name = "inVariable" |
1744 variable = plcopen.inVariable() |
1743 variable = plcopen.fbdObjects_inVariable() |
1745 elif type == OUTPUT: |
1744 elif type == OUTPUT: |
1746 name = "outVariable" |
1745 name = "outVariable" |
1747 variable = plcopen.outVariable() |
1746 variable = plcopen.fbdObjects_outVariable() |
1748 elif type == INOUT: |
1747 elif type == INOUT: |
1749 name = "inOutVariable" |
1748 name = "inOutVariable" |
1750 variable = plcopen.inOutVariable() |
1749 variable = plcopen.fbdObjects_inOutVariable() |
1751 variable.setLocalId(id) |
1750 variable.setlocalId(id) |
1752 element.addInstance(name, variable) |
1751 element.addinstance(name, variable) |
1753 |
1752 |
1754 def SetEditedElementVariableInfos(self, tagname, id, infos): |
1753 def SetEditedElementVariableInfos(self, tagname, id, infos): |
1755 element = self.GetEditedElement(tagname) |
1754 element = self.GetEditedElement(tagname) |
1756 if element is not None: |
1755 if element is not None: |
1757 variable = element.getInstance(id) |
1756 variable = element.getinstance(id) |
1758 for param, value in infos.items(): |
1757 for param, value in infos.items(): |
1759 if param == "name": |
1758 if param == "name": |
1760 variable.setExpression(value) |
1759 variable.setexpression(value) |
1761 elif param == "executionOrder" and variable.getExecutionOrderId() != value: |
1760 elif param == "executionOrder" and variable.getexecutionOrderId() != value: |
1762 self.GetEditedElement(tagname).setElementExecutionOrder(variable, value) |
1761 self.GetEditedElement(tagname).setelementExecutionOrder(variable, value) |
1763 elif param == "height": |
1762 elif param == "height": |
1764 variable.setHeight(value) |
1763 variable.setheight(value) |
1765 elif param == "width": |
1764 elif param == "width": |
1766 variable.setWidth(value) |
1765 variable.setwidth(value) |
1767 elif param == "x": |
1766 elif param == "x": |
1768 variable.setX(value) |
1767 variable.setx(value) |
1769 elif param == "y": |
1768 elif param == "y": |
1770 variable.setY(value) |
1769 variable.sety(value) |
1771 elif param == "connectors": |
1770 elif param == "connectors": |
1772 if isinstance(variable, plcopen.inVariable): |
1771 if isinstance(variable, plcopen.fbdObjects_inVariable): |
1773 if value["output"].IsNegated(): |
1772 if value["output"].IsNegated(): |
1774 variable.setNegated(True) |
1773 variable.setnegated(True) |
1775 if value["output"].GetEdge() != "none": |
1774 if value["output"].GetEdge() != "none": |
1776 variable.setConnectorEdge(value["output"].GetEdge()) |
1775 variable.setedge(value["output"].GetEdge()) |
1777 position = value["output"].GetRelPosition() |
1776 position = value["output"].GetRelPosition() |
1778 variable.addConnectionPointOut() |
1777 variable.addconnectionPointOut() |
1779 variable.connectionPointOut.setRelPosition(position.x, position.y) |
1778 variable.connectionPointOut.setrelPositionXY(position.x, position.y) |
1780 elif isinstance(variable, plcopen.outVariable): |
1779 elif isinstance(variable, plcopen.fbdObjects_outVariable): |
1781 if value["input"].IsNegated(): |
1780 if value["input"].IsNegated(): |
1782 variable.setNegated(True) |
1781 variable.setnegated(True) |
1783 if value["input"].GetEdge() != "none": |
1782 if value["input"].GetEdge() != "none": |
1784 variable.setConnectorEdge(value["input"].GetEdge()) |
1783 variable.setedge(value["input"].GetEdge()) |
1785 position = value["input"].GetRelPosition() |
1784 position = value["input"].GetRelPosition() |
1786 variable.addConnectionPointIn() |
1785 variable.addconnectionPointIn() |
1787 variable.connectionPointIn.setRelPosition(position.x, position.y) |
1786 variable.connectionPointIn.setrelPositionXY(position.x, position.y) |
1788 self.SetConnectionWires(variable.connectionPointIn, value["input"]) |
1787 self.SetConnectionWires(variable.connectionPointIn, value["input"]) |
1789 elif isinstance(variable, plcopen.inOutVariable): |
1788 elif isinstance(variable, plcopen.fbdObjects_inOutVariable): |
1790 if value["input"].IsNegated(): |
1789 if value["input"].IsNegated(): |
1791 variable.setNegatedIn(True) |
1790 variable.setnegatedIn(True) |
1792 if value["input"].GetEdge() != "none": |
1791 if value["input"].GetEdge() != "none": |
1793 variable.setInputEdge(value["input"].GetEdge()) |
1792 variable.setedgeIn(value["input"].GetEdge()) |
1794 if value["output"].IsNegated(): |
1793 if value["output"].IsNegated(): |
1795 variable.setNegatedOut(True) |
1794 variable.setnegatedOut(True) |
1796 if value["output"].GetEdge() != "none": |
1795 if value["output"].GetEdge() != "none": |
1797 variable.setOutputEdge(value["output"].GetEdge()) |
1796 variable.setedgeOut(value["output"].GetEdge()) |
1798 position = value["output"].GetRelPosition() |
1797 position = value["output"].GetRelPosition() |
1799 variable.addConnectionPointOut() |
1798 variable.addconnectionPointOut() |
1800 variable.connectionPointOut.setRelPosition(position.x, position.y) |
1799 variable.connectionPointOut.setrelPositionXY(position.x, position.y) |
1801 position = value["input"].GetRelPosition() |
1800 position = value["input"].GetRelPosition() |
1802 variable.addConnectionPointIn() |
1801 variable.addconnectionPointIn() |
1803 variable.connectionPointIn.setRelPosition(position.x, position.y) |
1802 variable.connectionPointIn.setrelPositionXY(position.x, position.y) |
1804 self.SetConnectionWires(variable.connectionPointIn, value["input"]) |
1803 self.SetConnectionWires(variable.connectionPointIn, value["input"]) |
1805 |
1804 |
1806 def AddEditedElementConnection(self, tagname, id, type): |
1805 def AddEditedElementConnection(self, tagname, id, type): |
1807 element = self.GetEditedElement(tagname) |
1806 element = self.GetEditedElement(tagname) |
1808 if element is not None: |
1807 if element is not None: |
1809 if type == CONNECTOR: |
1808 if type == CONNECTOR: |
1810 name = "connector" |
1809 name = "connector" |
1811 connection = plcopen.connector() |
1810 connection = plcopen.commonObjects_connector() |
1812 elif type == CONTINUATION: |
1811 elif type == CONTINUATION: |
1813 name = "continuation" |
1812 name = "continuation" |
1814 connection = plcopen.continuation() |
1813 connection = plcopen.commonObjects_continuation() |
1815 connection.setLocalId(id) |
1814 connection.setlocalId(id) |
1816 element.addInstance(name, connection) |
1815 element.addinstance(name, connection) |
1817 |
1816 |
1818 def SetEditedElementConnectionInfos(self, tagname, id, infos): |
1817 def SetEditedElementConnectionInfos(self, tagname, id, infos): |
1819 element = self.GetEditedElement(tagname) |
1818 element = self.GetEditedElement(tagname) |
1820 if element is not None: |
1819 if element is not None: |
1821 connection = element.getInstance(id) |
1820 connection = element.getinstance(id) |
1822 for param, value in infos.items(): |
1821 for param, value in infos.items(): |
1823 if param == "name": |
1822 if param == "name": |
1824 connection.setName(value) |
1823 connection.setname(value) |
1825 elif param == "height": |
1824 elif param == "height": |
1826 connection.setHeight(value) |
1825 connection.setheight(value) |
1827 elif param == "width": |
1826 elif param == "width": |
1828 connection.setWidth(value) |
1827 connection.setwidth(value) |
1829 elif param == "x": |
1828 elif param == "x": |
1830 connection.setX(value) |
1829 connection.setx(value) |
1831 elif param == "y": |
1830 elif param == "y": |
1832 connection.setY(value) |
1831 connection.sety(value) |
1833 elif param == "connector": |
1832 elif param == "connector": |
1834 position = value.GetRelPosition() |
1833 position = value.GetRelPosition() |
1835 if isinstance(connection, plcopen.continuation): |
1834 if isinstance(connection, plcopen.commonObjects_continuation): |
1836 connection.addConnectionPointOut() |
1835 connection.addconnectionPointOut() |
1837 connection.connectionPointOut.setRelPosition(position.x, position.y) |
1836 connection.connectionPointOut.setrelPositionXY(position.x, position.y) |
1838 elif isinstance(connection, plcopen.connector): |
1837 elif isinstance(connection, plcopen.commonObjects_connector): |
1839 connection.addConnectionPointIn() |
1838 connection.addconnectionPointIn() |
1840 connection.connectionPointIn.setRelPosition(position.x, position.y) |
1839 connection.connectionPointIn.setrelPositionXY(position.x, position.y) |
1841 self.SetConnectionWires(connection.connectionPointIn, value) |
1840 self.SetConnectionWires(connection.connectionPointIn, value) |
1842 |
1841 |
1843 def AddEditedElementComment(self, tagname, id): |
1842 def AddEditedElementComment(self, tagname, id): |
1844 element = self.GetEditedElement(tagname) |
1843 element = self.GetEditedElement(tagname) |
1845 if element is not None: |
1844 if element is not None: |
1846 comment = plcopen.comment() |
1845 comment = plcopen.commonObjects_comment() |
1847 comment.setLocalId(id) |
1846 comment.setlocalId(id) |
1848 element.addInstance("comment", comment) |
1847 element.addinstance("comment", comment) |
1849 |
1848 |
1850 def SetEditedElementCommentInfos(self, tagname, id, infos): |
1849 def SetEditedElementCommentInfos(self, tagname, id, infos): |
1851 element = self.GetEditedElement(tagname) |
1850 element = self.GetEditedElement(tagname) |
1852 if element is not None: |
1851 if element is not None: |
1853 comment = element.getInstance(id) |
1852 comment = element.getinstance(id) |
1854 for param, value in infos.items(): |
1853 for param, value in infos.items(): |
1855 if param == "content": |
1854 if param == "content": |
1856 comment.setContentText(value) |
1855 comment.setcontentText(value) |
1857 elif param == "height": |
1856 elif param == "height": |
1858 comment.setHeight(value) |
1857 comment.setheight(value) |
1859 elif param == "width": |
1858 elif param == "width": |
1860 comment.setWidth(value) |
1859 comment.setwidth(value) |
1861 elif param == "x": |
1860 elif param == "x": |
1862 comment.setX(value) |
1861 comment.setx(value) |
1863 elif param == "y": |
1862 elif param == "y": |
1864 comment.setY(value) |
1863 comment.sety(value) |
1865 |
1864 |
1866 def AddEditedElementPowerRail(self, tagname, id, type): |
1865 def AddEditedElementPowerRail(self, tagname, id, type): |
1867 element = self.GetEditedElement(tagname) |
1866 element = self.GetEditedElement(tagname) |
1868 if element is not None: |
1867 if element is not None: |
1869 if type == LEFTRAIL: |
1868 if type == LEFTRAIL: |
1870 name = "leftPowerRail" |
1869 name = "leftPowerRail" |
1871 powerrail = plcopen.leftPowerRail() |
1870 powerrail = plcopen.ldObjects_leftPowerRail() |
1872 elif type == RIGHTRAIL: |
1871 elif type == RIGHTRAIL: |
1873 name = "rightPowerRail" |
1872 name = "rightPowerRail" |
1874 powerrail = plcopen.rightPowerRail() |
1873 powerrail = plcopen.ldObjects_rightPowerRail() |
1875 powerrail.setLocalId(id) |
1874 powerrail.setlocalId(id) |
1876 element.addInstance(name, powerrail) |
1875 element.addinstance(name, powerrail) |
1877 |
1876 |
1878 def SetEditedElementPowerRailInfos(self, tagname, id, infos): |
1877 def SetEditedElementPowerRailInfos(self, tagname, id, infos): |
1879 element = self.GetEditedElement(tagname) |
1878 element = self.GetEditedElement(tagname) |
1880 if element is not None: |
1879 if element is not None: |
1881 powerrail = element.getInstance(id) |
1880 powerrail = element.getinstance(id) |
1882 for param, value in infos.items(): |
1881 for param, value in infos.items(): |
1883 if param == "height": |
1882 if param == "height": |
1884 powerrail.setHeight(value) |
1883 powerrail.setheight(value) |
1885 elif param == "width": |
1884 elif param == "width": |
1886 powerrail.setWidth(value) |
1885 powerrail.setwidth(value) |
1887 elif param == "x": |
1886 elif param == "x": |
1888 powerrail.setX(value) |
1887 powerrail.setx(value) |
1889 elif param == "y": |
1888 elif param == "y": |
1890 powerrail.setY(value) |
1889 powerrail.sety(value) |
1891 elif param == "connectors": |
1890 elif param == "connectors": |
1892 if isinstance(powerrail, plcopen.leftPowerRail): |
1891 if isinstance(powerrail, plcopen.ldObjects_leftPowerRail): |
1893 powerrail.setConnectionPointOut([]) |
1892 powerrail.setconnectionPointOut([]) |
1894 for connector in value: |
1893 for connector in value: |
1895 position = connector.GetRelPosition() |
1894 position = connector.GetRelPosition() |
1896 connection = plcopen.leftPowerRail_connectionPointOut() |
1895 connection = plcopen.leftPowerRail_connectionPointOut() |
1897 connection.setRelPosition(position.x, position.y) |
1896 connection.setrelPositionXY(position.x, position.y) |
1898 powerrail.connectionPointOut.append(connection) |
1897 powerrail.connectionPointOut.append(connection) |
1899 elif isinstance(powerrail, plcopen.rightPowerRail): |
1898 elif isinstance(powerrail, plcopen.ldObjects_rightPowerRail): |
1900 powerrail.setConnectionPointIn([]) |
1899 powerrail.setconnectionPointIn([]) |
1901 for connector in value: |
1900 for connector in value: |
1902 position = connector.GetRelPosition() |
1901 position = connector.GetRelPosition() |
1903 connection = plcopen.connectionPointIn() |
1902 connection = plcopen.connectionPointIn() |
1904 connection.setRelPosition(position.x, position.y) |
1903 connection.setrelPositionXY(position.x, position.y) |
1905 self.SetConnectionWires(connection, connector) |
1904 self.SetConnectionWires(connection, connector) |
1906 powerrail.connectionPointIn.append(connection) |
1905 powerrail.connectionPointIn.append(connection) |
1907 |
1906 |
1908 def AddEditedElementContact(self, tagname, id): |
1907 def AddEditedElementContact(self, tagname, id): |
1909 element = self.GetEditedElement(tagname) |
1908 element = self.GetEditedElement(tagname) |
1910 if element is not None: |
1909 if element is not None: |
1911 contact = plcopen.contact() |
1910 contact = plcopen.ldObjects_contact() |
1912 contact.setLocalId(id) |
1911 contact.setlocalId(id) |
1913 element.addInstance("contact", contact) |
1912 element.addinstance("contact", contact) |
1914 |
1913 |
1915 def SetEditedElementContactInfos(self, tagname, id, infos): |
1914 def SetEditedElementContactInfos(self, tagname, id, infos): |
1916 element = self.GetEditedElement(tagname) |
1915 element = self.GetEditedElement(tagname) |
1917 if element is not None: |
1916 if element is not None: |
1918 contact = element.getInstance(id) |
1917 contact = element.getinstance(id) |
1919 for param, value in infos.items(): |
1918 for param, value in infos.items(): |
1920 if param == "name": |
1919 if param == "name": |
1921 contact.setVariable(value) |
1920 contact.setvariable(value) |
1922 elif param == "type": |
1921 elif param == "type": |
1923 if value == CONTACT_NORMAL: |
1922 if value == CONTACT_NORMAL: |
1924 contact.setNegated(False) |
1923 contact.setnegated(False) |
1925 contact.setContactEdge("none") |
1924 contact.setedge("none") |
1926 elif value == CONTACT_REVERSE: |
1925 elif value == CONTACT_REVERSE: |
1927 contact.setNegated(True) |
1926 contact.setnegated(True) |
1928 contact.setContactEdge("none") |
1927 contact.setedge("none") |
1929 elif value == CONTACT_RISING: |
1928 elif value == CONTACT_RISING: |
1930 contact.setNegated(False) |
1929 contact.setnegated(False) |
1931 contact.setContactEdge("rising") |
1930 contact.setedge("rising") |
1932 elif value == CONTACT_FALLING: |
1931 elif value == CONTACT_FALLING: |
1933 contact.setNegated(False) |
1932 contact.setnegated(False) |
1934 contact.setContactEdge("falling") |
1933 contact.setedge("falling") |
1935 elif param == "height": |
1934 elif param == "height": |
1936 contact.setHeight(value) |
1935 contact.setheight(value) |
1937 elif param == "width": |
1936 elif param == "width": |
1938 contact.setWidth(value) |
1937 contact.setwidth(value) |
1939 elif param == "x": |
1938 elif param == "x": |
1940 contact.setX(value) |
1939 contact.setx(value) |
1941 elif param == "y": |
1940 elif param == "y": |
1942 contact.setY(value) |
1941 contact.sety(value) |
1943 elif param == "connectors": |
1942 elif param == "connectors": |
1944 input_connector = value["input"] |
1943 input_connector = value["input"] |
1945 position = input_connector.GetRelPosition() |
1944 position = input_connector.GetRelPosition() |
1946 contact.addConnectionPointIn() |
1945 contact.addconnectionPointIn() |
1947 contact.connectionPointIn.setRelPosition(position.x, position.y) |
1946 contact.connectionPointIn.setrelPositionXY(position.x, position.y) |
1948 self.SetConnectionWires(contact.connectionPointIn, input_connector) |
1947 self.SetConnectionWires(contact.connectionPointIn, input_connector) |
1949 output_connector = value["output"] |
1948 output_connector = value["output"] |
1950 position = output_connector.GetRelPosition() |
1949 position = output_connector.GetRelPosition() |
1951 contact.addConnectionPointOut() |
1950 contact.addconnectionPointOut() |
1952 contact.connectionPointOut.setRelPosition(position.x, position.y) |
1951 contact.connectionPointOut.setrelPositionXY(position.x, position.y) |
1953 |
1952 |
1954 def AddEditedElementCoil(self, tagname, id): |
1953 def AddEditedElementCoil(self, tagname, id): |
1955 element = self.GetEditedElement(tagname) |
1954 element = self.GetEditedElement(tagname) |
1956 if element is not None: |
1955 if element is not None: |
1957 coil = plcopen.coil() |
1956 coil = plcopen.ldObjects_coil() |
1958 coil.setLocalId(id) |
1957 coil.setlocalId(id) |
1959 element.addInstance("coil", coil) |
1958 element.addinstance("coil", coil) |
1960 |
1959 |
1961 def SetEditedElementCoilInfos(self, tagname, id, infos): |
1960 def SetEditedElementCoilInfos(self, tagname, id, infos): |
1962 element = self.GetEditedElement(tagname) |
1961 element = self.GetEditedElement(tagname) |
1963 if element is not None: |
1962 if element is not None: |
1964 coil = element.getInstance(id) |
1963 coil = element.getinstance(id) |
1965 for param, value in infos.items(): |
1964 for param, value in infos.items(): |
1966 if param == "name": |
1965 if param == "name": |
1967 coil.setVariable(value) |
1966 coil.setvariable(value) |
1968 elif param == "type": |
1967 elif param == "type": |
1969 if value == COIL_NORMAL: |
1968 if value == COIL_NORMAL: |
1970 coil.setNegated(False) |
1969 coil.setnegated(False) |
1971 coil.setCoilStorage("none") |
1970 coil.setstorage("none") |
1972 elif value == COIL_REVERSE: |
1971 elif value == COIL_REVERSE: |
1973 coil.setNegated(True) |
1972 coil.setnegated(True) |
1974 coil.setCoilStorage("none") |
1973 coil.setstorage("none") |
1975 elif value == COIL_SET: |
1974 elif value == COIL_SET: |
1976 coil.setNegated(False) |
1975 coil.setnegated(False) |
1977 coil.setCoilStorage("set") |
1976 coil.setstorage("set") |
1978 elif value == COIL_RESET: |
1977 elif value == COIL_RESET: |
1979 coil.setNegated(False) |
1978 coil.setnegated(False) |
1980 coil.setCoilStorage("reset") |
1979 coil.setstorage("reset") |
1981 elif param == "height": |
1980 elif param == "height": |
1982 coil.setHeight(value) |
1981 coil.setheight(value) |
1983 elif param == "width": |
1982 elif param == "width": |
1984 coil.setWidth(value) |
1983 coil.setwidth(value) |
1985 elif param == "x": |
1984 elif param == "x": |
1986 coil.setX(value) |
1985 coil.setx(value) |
1987 elif param == "y": |
1986 elif param == "y": |
1988 coil.setY(value) |
1987 coil.sety(value) |
1989 elif param == "connectors": |
1988 elif param == "connectors": |
1990 input_connector = value["input"] |
1989 input_connector = value["input"] |
1991 position = input_connector.GetRelPosition() |
1990 position = input_connector.GetRelPosition() |
1992 coil.addConnectionPointIn() |
1991 coil.addconnectionPointIn() |
1993 coil.connectionPointIn.setRelPosition(position.x, position.y) |
1992 coil.connectionPointIn.setrelPositionXY(position.x, position.y) |
1994 self.SetConnectionWires(coil.connectionPointIn, input_connector) |
1993 self.SetConnectionWires(coil.connectionPointIn, input_connector) |
1995 output_connector = value["output"] |
1994 output_connector = value["output"] |
1996 position = output_connector.GetRelPosition() |
1995 position = output_connector.GetRelPosition() |
1997 coil.addConnectionPointOut() |
1996 coil.addconnectionPointOut() |
1998 coil.connectionPointOut.setRelPosition(position.x, position.y) |
1997 coil.connectionPointOut.setrelPositionXY(position.x, position.y) |
1999 |
1998 |
2000 def AddEditedElementStep(self, tagname, id): |
1999 def AddEditedElementStep(self, tagname, id): |
2001 element = self.GetEditedElement(tagname) |
2000 element = self.GetEditedElement(tagname) |
2002 if element is not None: |
2001 if element is not None: |
2003 step = plcopen.step() |
2002 step = plcopen.sfcObjects_step() |
2004 step.setLocalId(id) |
2003 step.setlocalId(id) |
2005 element.addInstance("step", step) |
2004 element.addinstance("step", step) |
2006 |
2005 |
2007 def SetEditedElementStepInfos(self, tagname, id, infos): |
2006 def SetEditedElementStepInfos(self, tagname, id, infos): |
2008 element = self.GetEditedElement(tagname) |
2007 element = self.GetEditedElement(tagname) |
2009 if element is not None: |
2008 if element is not None: |
2010 step = element.getInstance(id) |
2009 step = element.getinstance(id) |
2011 for param, value in infos.items(): |
2010 for param, value in infos.items(): |
2012 if param == "name": |
2011 if param == "name": |
2013 step.setName(value) |
2012 step.setname(value) |
2014 elif param == "initial": |
2013 elif param == "initial": |
2015 step.setInitialStep(value) |
2014 step.setinitialStep(value) |
2016 elif param == "height": |
2015 elif param == "height": |
2017 step.setHeight(value) |
2016 step.setheight(value) |
2018 elif param == "width": |
2017 elif param == "width": |
2019 step.setWidth(value) |
2018 step.setwidth(value) |
2020 elif param == "x": |
2019 elif param == "x": |
2021 step.setX(value) |
2020 step.setx(value) |
2022 elif param == "y": |
2021 elif param == "y": |
2023 step.setY(value) |
2022 step.sety(value) |
2024 elif param == "connectors": |
2023 elif param == "connectors": |
2025 input_connector = value["input"] |
2024 input_connector = value["input"] |
2026 if input_connector: |
2025 if input_connector: |
2027 position = input_connector.GetRelPosition() |
2026 position = input_connector.GetRelPosition() |
2028 step.addConnectionPointIn() |
2027 step.addconnectionPointIn() |
2029 step.connectionPointIn.setRelPosition(position.x, position.y) |
2028 step.connectionPointIn.setrelPositionXY(position.x, position.y) |
2030 self.SetConnectionWires(step.connectionPointIn, input_connector) |
2029 self.SetConnectionWires(step.connectionPointIn, input_connector) |
2031 else: |
2030 else: |
2032 step.deleteConnectionPointIn() |
2031 step.deleteconnectionPointIn() |
2033 output_connector = value["output"] |
2032 output_connector = value["output"] |
2034 if output_connector: |
2033 if output_connector: |
2035 position = output_connector.GetRelPosition() |
2034 position = output_connector.GetRelPosition() |
2036 step.addConnectionPointOut() |
2035 step.addconnectionPointOut() |
2037 step.connectionPointOut.setRelPosition(position.x, position.y) |
2036 step.connectionPointOut.setrelPositionXY(position.x, position.y) |
2038 else: |
2037 else: |
2039 step.deleteConnectionPointOut() |
2038 step.deleteconnectionPointOut() |
2040 action_connector = value["action"] |
2039 action_connector = value["action"] |
2041 if action_connector: |
2040 if action_connector: |
2042 position = action_connector.GetRelPosition() |
2041 position = action_connector.GetRelPosition() |
2043 step.addConnectionPointOutAction() |
2042 step.addconnectionPointOutAction() |
2044 step.connectionPointOutAction.setRelPosition(position.x, position.y) |
2043 step.connectionPointOutAction.setrelPositionXY(position.x, position.y) |
2045 else: |
2044 else: |
2046 step.deleteConnectionPointOutAction() |
2045 step.deleteconnectionPointOutAction() |
2047 |
2046 |
2048 def AddEditedElementTransition(self, tagname, id): |
2047 def AddEditedElementTransition(self, tagname, id): |
2049 element = self.GetEditedElement(tagname) |
2048 element = self.GetEditedElement(tagname) |
2050 if element is not None: |
2049 if element is not None: |
2051 transition = plcopen.transition() |
2050 transition = plcopen.sfcObjects_transition() |
2052 transition.setLocalId(id) |
2051 transition.setlocalId(id) |
2053 element.addInstance("transition", transition) |
2052 element.addinstance("transition", transition) |
2054 |
2053 |
2055 def SetEditedElementTransitionInfos(self, tagname, id, infos): |
2054 def SetEditedElementTransitionInfos(self, tagname, id, infos): |
2056 element = self.GetEditedElement(tagname) |
2055 element = self.GetEditedElement(tagname) |
2057 if element is not None: |
2056 if element is not None: |
2058 transition = element.getInstance(id) |
2057 transition = element.getinstance(id) |
2059 for param, value in infos.items(): |
2058 for param, value in infos.items(): |
2060 if param == "type" and value != "connection": |
2059 if param == "type" and value != "connection": |
2061 transition.setConditionContent(value, infos["condition"]) |
2060 transition.setconditionContent(value, infos["condition"]) |
2062 elif param == "height": |
2061 elif param == "height": |
2063 transition.setHeight(value) |
2062 transition.setheight(value) |
2064 elif param == "width": |
2063 elif param == "width": |
2065 transition.setWidth(value) |
2064 transition.setwidth(value) |
2066 elif param == "x": |
2065 elif param == "x": |
2067 transition.setX(value) |
2066 transition.setx(value) |
2068 elif param == "y": |
2067 elif param == "y": |
2069 transition.setY(value) |
2068 transition.sety(value) |
2070 elif param == "priority": |
2069 elif param == "priority": |
2071 if value != 0: |
2070 if value != 0: |
2072 transition.setPriority(value) |
2071 transition.setpriority(value) |
2073 else: |
2072 else: |
2074 transition.setPriority(None) |
2073 transition.setpriority(None) |
2075 elif param == "connectors": |
2074 elif param == "connectors": |
2076 input_connector = value["input"] |
2075 input_connector = value["input"] |
2077 position = input_connector.GetRelPosition() |
2076 position = input_connector.GetRelPosition() |
2078 transition.addConnectionPointIn() |
2077 transition.addconnectionPointIn() |
2079 transition.connectionPointIn.setRelPosition(position.x, position.y) |
2078 transition.connectionPointIn.setrelPositionXY(position.x, position.y) |
2080 self.SetConnectionWires(transition.connectionPointIn, input_connector) |
2079 self.SetConnectionWires(transition.connectionPointIn, input_connector) |
2081 output_connector = value["output"] |
2080 output_connector = value["output"] |
2082 position = output_connector.GetRelPosition() |
2081 position = output_connector.GetRelPosition() |
2083 transition.addConnectionPointOut() |
2082 transition.addconnectionPointOut() |
2084 transition.connectionPointOut.setRelPosition(position.x, position.y) |
2083 transition.connectionPointOut.setrelPositionXY(position.x, position.y) |
2085 if infos.get("type", None) == "connection": |
2084 if infos.get("type", None) == "connection": |
2086 transition.setConditionContent("connection", None) |
2085 transition.setconditionContent("connection", None) |
2087 connection_connector = value["connection"] |
2086 connection_connector = value["connection"] |
2088 self.SetConnectionWires(transition, connection_connector) |
2087 self.SetConnectionWires(transition, connection_connector) |
2089 |
2088 |
2090 def AddEditedElementDivergence(self, tagname, id, type): |
2089 def AddEditedElementDivergence(self, tagname, id, type): |
2091 element = self.GetEditedElement(tagname) |
2090 element = self.GetEditedElement(tagname) |
2092 if element is not None: |
2091 if element is not None: |
2093 if type == SELECTION_DIVERGENCE: |
2092 if type == SELECTION_DIVERGENCE: |
2094 name = "selectionDivergence" |
2093 name = "selectionDivergence" |
2095 divergence = plcopen.selectionDivergence() |
2094 divergence = plcopen.sfcObjects_selectionDivergence() |
2096 elif type == SELECTION_CONVERGENCE: |
2095 elif type == SELECTION_CONVERGENCE: |
2097 name = "selectionConvergence" |
2096 name = "selectionConvergence" |
2098 divergence = plcopen.selectionConvergence() |
2097 divergence = plcopen.sfcObjects_selectionConvergence() |
2099 elif type == SIMULTANEOUS_DIVERGENCE: |
2098 elif type == SIMULTANEOUS_DIVERGENCE: |
2100 name = "simultaneousDivergence" |
2099 name = "simultaneousDivergence" |
2101 divergence = plcopen.simultaneousDivergence() |
2100 divergence = plcopen.sfcObjects_simultaneousDivergence() |
2102 elif type == SIMULTANEOUS_CONVERGENCE: |
2101 elif type == SIMULTANEOUS_CONVERGENCE: |
2103 name = "simultaneousConvergence" |
2102 name = "simultaneousConvergence" |
2104 divergence = plcopen.simultaneousConvergence() |
2103 divergence = plcopen.sfcObjects_simultaneousConvergence() |
2105 divergence.setLocalId(id) |
2104 divergence.setlocalId(id) |
2106 element.addInstance(name, divergence) |
2105 element.addinstance(name, divergence) |
2107 |
2106 |
2108 def SetEditedElementDivergenceInfos(self, tagname, id, infos): |
2107 def SetEditedElementDivergenceInfos(self, tagname, id, infos): |
2109 element = self.GetEditedElement(tagname) |
2108 element = self.GetEditedElement(tagname) |
2110 if element is not None: |
2109 if element is not None: |
2111 divergence = element.getInstance(id) |
2110 divergence = element.getinstance(id) |
2112 for param, value in infos.items(): |
2111 for param, value in infos.items(): |
2113 if param == "height": |
2112 if param == "height": |
2114 divergence.setHeight(value) |
2113 divergence.setheight(value) |
2115 elif param == "width": |
2114 elif param == "width": |
2116 divergence.setWidth(value) |
2115 divergence.setwidth(value) |
2117 elif param == "x": |
2116 elif param == "x": |
2118 divergence.setX(value) |
2117 divergence.setx(value) |
2119 elif param == "y": |
2118 elif param == "y": |
2120 divergence.setY(value) |
2119 divergence.sety(value) |
2121 elif param == "connectors": |
2120 elif param == "connectors": |
2122 input_connectors = value["inputs"] |
2121 input_connectors = value["inputs"] |
2123 if isinstance(divergence, (plcopen.selectionDivergence, plcopen.simultaneousDivergence)): |
2122 if isinstance(divergence, (plcopen.sfcObjects_selectionDivergence, plcopen.sfcObjects_simultaneousDivergence)): |
2124 position = input_connectors[0].GetRelPosition() |
2123 position = input_connectors[0].GetRelPosition() |
2125 divergence.addConnectionPointIn() |
2124 divergence.addconnectionPointIn() |
2126 divergence.connectionPointIn.setRelPosition(position.x, position.y) |
2125 divergence.connectionPointIn.setrelPositionXY(position.x, position.y) |
2127 self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0]) |
2126 self.SetConnectionWires(divergence.connectionPointIn, input_connectors[0]) |
2128 else: |
2127 else: |
2129 divergence.setConnectionPointIn([]) |
2128 divergence.setconnectionPointIn([]) |
2130 for input_connector in input_connectors: |
2129 for input_connector in input_connectors: |
2131 position = input_connector.GetRelPosition() |
2130 position = input_connector.GetRelPosition() |
2132 if isinstance(divergence, plcopen.selectionConvergence): |
2131 if isinstance(divergence, plcopen.sfcObjects_selectionConvergence): |
2133 connection = plcopen.selectionConvergence_connectionPointIn() |
2132 connection = plcopen.selectionConvergence_connectionPointIn() |
2134 else: |
2133 else: |
2135 connection = plcopen.connectionPointIn() |
2134 connection = plcopen.connectionPointIn() |
2136 connection.setRelPosition(position.x, position.y) |
2135 connection.setrelPositionXY(position.x, position.y) |
2137 self.SetConnectionWires(connection, input_connector) |
2136 self.SetConnectionWires(connection, input_connector) |
2138 divergence.appendConnectionPointIn(connection) |
2137 divergence.appendconnectionPointIn(connection) |
2139 output_connectors = value["outputs"] |
2138 output_connectors = value["outputs"] |
2140 if isinstance(divergence, (plcopen.selectionConvergence, plcopen.simultaneousConvergence)): |
2139 if isinstance(divergence, (plcopen.sfcObjects_selectionConvergence, plcopen.sfcObjects_simultaneousConvergence)): |
2141 position = output_connectors[0].GetRelPosition() |
2140 position = output_connectors[0].GetRelPosition() |
2142 divergence.addConnectionPointOut() |
2141 divergence.addconnectionPointOut() |
2143 divergence.connectionPointOut.setRelPosition(position.x, position.y) |
2142 divergence.connectionPointOut.setrelPositionXY(position.x, position.y) |
2144 else: |
2143 else: |
2145 divergence.setConnectionPointOut([]) |
2144 divergence.setconnectionPointOut([]) |
2146 for output_connector in output_connectors: |
2145 for output_connector in output_connectors: |
2147 position = output_connector.GetRelPosition() |
2146 position = output_connector.GetRelPosition() |
2148 if isinstance(divergence, plcopen.selectionDivergence): |
2147 if isinstance(divergence, plcopen.sfcObjects_selectionDivergence): |
2149 connection = plcopen.selectionDivergence_connectionPointOut() |
2148 connection = plcopen.selectionDivergence_connectionPointOut() |
2150 else: |
2149 else: |
2151 connection = plcopen.simultaneousDivergence_connectionPointOut() |
2150 connection = plcopen.simultaneousDivergence_connectionPointOut() |
2152 connection.setRelPosition(position.x, position.y) |
2151 connection.setrelPositionXY(position.x, position.y) |
2153 divergence.appendConnectionPointOut(connection) |
2152 divergence.appendconnectionPointOut(connection) |
2154 |
2153 |
2155 def AddEditedElementJump(self, tagname, id): |
2154 def AddEditedElementJump(self, tagname, id): |
2156 element = self.GetEditedElement(tagname) |
2155 element = self.GetEditedElement(tagname) |
2157 if element is not None: |
2156 if element is not None: |
2158 jump = plcopen.jumpStep() |
2157 jump = plcopen.sfcObjects_jumpStep() |
2159 jump.setLocalId(id) |
2158 jump.setlocalId(id) |
2160 element.addInstance("jumpStep", jump) |
2159 element.addinstance("jumpStep", jump) |
2161 |
2160 |
2162 def SetEditedElementJumpInfos(self, tagname, id, infos): |
2161 def SetEditedElementJumpInfos(self, tagname, id, infos): |
2163 element = self.GetEditedElement(tagname) |
2162 element = self.GetEditedElement(tagname) |
2164 if element is not None: |
2163 if element is not None: |
2165 jump = element.getInstance(id) |
2164 jump = element.getinstance(id) |
2166 for param, value in infos.items(): |
2165 for param, value in infos.items(): |
2167 if param == "target": |
2166 if param == "target": |
2168 jump.setTargetName(value) |
2167 jump.settargetName(value) |
2169 elif param == "height": |
2168 elif param == "height": |
2170 jump.setHeight(value) |
2169 jump.setheight(value) |
2171 elif param == "width": |
2170 elif param == "width": |
2172 jump.setWidth(value) |
2171 jump.setwidth(value) |
2173 elif param == "x": |
2172 elif param == "x": |
2174 jump.setX(value) |
2173 jump.setx(value) |
2175 elif param == "y": |
2174 elif param == "y": |
2176 jump.setY(value) |
2175 jump.sety(value) |
2177 elif param == "connector": |
2176 elif param == "connector": |
2178 position = value.GetRelPosition() |
2177 position = value.GetRelPosition() |
2179 jump.addConnectionPointIn() |
2178 jump.addconnectionPointIn() |
2180 jump.connectionPointIn.setRelPosition(position.x, position.y) |
2179 jump.connectionPointIn.setrelPositionXY(position.x, position.y) |
2181 self.SetConnectionWires(jump.connectionPointIn, value) |
2180 self.SetConnectionWires(jump.connectionPointIn, value) |
2182 |
2181 |
2183 def AddEditedElementActionBlock(self, tagname, id): |
2182 def AddEditedElementActionBlock(self, tagname, id): |
2184 element = self.GetEditedElement(tagname) |
2183 element = self.GetEditedElement(tagname) |
2185 if element is not None: |
2184 if element is not None: |
2186 actionBlock = plcopen.actionBlock() |
2185 actionBlock = plcopen.commonObjects_actionBlock() |
2187 actionBlock.setLocalId(id) |
2186 actionBlock.setlocalId(id) |
2188 element.addInstance("actionBlock", actionBlock) |
2187 element.addinstance("actionBlock", actionBlock) |
2189 |
2188 |
2190 def SetEditedElementActionBlockInfos(self, tagname, id, infos): |
2189 def SetEditedElementActionBlockInfos(self, tagname, id, infos): |
2191 element = self.GetEditedElement(tagname) |
2190 element = self.GetEditedElement(tagname) |
2192 if element is not None: |
2191 if element is not None: |
2193 actionBlock = element.getInstance(id) |
2192 actionBlock = element.getinstance(id) |
2194 for param, value in infos.items(): |
2193 for param, value in infos.items(): |
2195 if param == "actions": |
2194 if param == "actions": |
2196 actionBlock.setActions(value) |
2195 actionBlock.setactions(value) |
2197 elif param == "height": |
2196 elif param == "height": |
2198 actionBlock.setHeight(value) |
2197 actionBlock.setheight(value) |
2199 elif param == "width": |
2198 elif param == "width": |
2200 actionBlock.setWidth(value) |
2199 actionBlock.setwidth(value) |
2201 elif param == "x": |
2200 elif param == "x": |
2202 actionBlock.setX(value) |
2201 actionBlock.setx(value) |
2203 elif param == "y": |
2202 elif param == "y": |
2204 actionBlock.setY(value) |
2203 actionBlock.sety(value) |
2205 elif param == "connector": |
2204 elif param == "connector": |
2206 position = value.GetRelPosition() |
2205 position = value.GetRelPosition() |
2207 actionBlock.addConnectionPointIn() |
2206 actionBlock.addconnectionPointIn() |
2208 actionBlock.connectionPointIn.setRelPosition(position.x, position.y) |
2207 actionBlock.connectionPointIn.setrelPositionXY(position.x, position.y) |
2209 self.SetConnectionWires(actionBlock.connectionPointIn, value) |
2208 self.SetConnectionWires(actionBlock.connectionPointIn, value) |
2210 |
2209 |
2211 def RemoveEditedElementInstance(self, tagname, id): |
2210 def RemoveEditedElementInstance(self, tagname, id): |
2212 element = self.GetEditedElement(tagname) |
2211 element = self.GetEditedElement(tagname) |
2213 if element is not None: |
2212 if element is not None: |
2214 instance = element.getInstance(id) |
2213 instance = element.getinstance(id) |
2215 if isinstance(instance, plcopen.block): |
2214 if isinstance(instance, plcopen.fbdObjects_block): |
2216 blocktype = instance.getTypeName() |
2215 blocktype = instance.gettypeName() |
2217 element.removePouVar(blocktype, instance.getInstanceName()) |
2216 element.removepouVar(blocktype, instance.getinstanceName()) |
2218 element.removeInstance(id) |
2217 element.removeinstance(id) |
2219 self.RefreshPouUsingTree() |
2218 self.RefreshPouUsingTree() |
2220 |
2219 |
2221 def GetEditedResourceVariables(self, tagname): |
2220 def GetEditedResourceVariables(self, tagname): |
2222 varlist = [] |
2221 varlist = [] |
2223 words = tagname.split("::") |
2222 words = tagname.split("::") |