134 |
134 |
135 def GetTagName(self): |
135 def GetTagName(self): |
136 return self.TagName |
136 return self.TagName |
137 |
137 |
138 def ConfigTagName(self, context, *args): |
138 def ConfigTagName(self, context, *args): |
139 self.TagName = self.Controller.ComputeConfigurationName(args[0][0]) |
139 self.TagName = ComputeConfigurationName(args[0][0]) |
140 |
140 |
141 def ResourceTagName(self, context, *args): |
141 def ResourceTagName(self, context, *args): |
142 self.TagName = self.Controller.ComputeConfigurationResourceName(args[0][0], args[1][0]) |
142 self.TagName = ComputeConfigurationResourceName(args[0][0], args[1][0]) |
143 |
143 |
144 def PouTagName(self, context, *args): |
144 def PouTagName(self, context, *args): |
145 self.TagName = self.Controller.ComputePouName(args[0][0]) |
145 self.TagName = ComputePouName(args[0][0]) |
146 |
146 |
147 def ActionTagName(self, context, *args): |
147 def ActionTagName(self, context, *args): |
148 self.TagName = self.Controller.ComputePouActionName(args[0][0], args[0][1]) |
148 self.TagName = ComputePouActionName(args[0][0], args[0][1]) |
149 |
149 |
150 def TransitionTagName(self, context, *args): |
150 def TransitionTagName(self, context, *args): |
151 self.TagName = self.Controller.ComputePouTransitionName(args[0][0], args[0][1]) |
151 self.TagName = ComputePouTransitionName(args[0][0], args[0][1]) |
152 |
152 |
153 |
153 |
154 # ------------------------------------------------------------------------------- |
154 # ------------------------------------------------------------------------------- |
155 # Helpers object for generating pou block instances list |
155 # Helpers object for generating pou block instances list |
156 # ------------------------------------------------------------------------------- |
156 # ------------------------------------------------------------------------------- |
557 datatypes = {"name": DATA_TYPES, "type": ITEM_DATATYPES, "values": []} |
557 datatypes = {"name": DATA_TYPES, "type": ITEM_DATATYPES, "values": []} |
558 for datatype in project.getdataTypes(): |
558 for datatype in project.getdataTypes(): |
559 datatypes["values"].append({ |
559 datatypes["values"].append({ |
560 "name": datatype.getname(), |
560 "name": datatype.getname(), |
561 "type": ITEM_DATATYPE, |
561 "type": ITEM_DATATYPE, |
562 "tagname": self.ComputeDataTypeName(datatype.getname()), |
562 "tagname": ComputeDataTypeName(datatype.getname()), |
563 "values": []}) |
563 "values": []}) |
564 pou_types = { |
564 pou_types = { |
565 "function": { |
565 "function": { |
566 "name": FUNCTIONS, |
566 "name": FUNCTIONS, |
567 "type": ITEM_FUNCTION, |
567 "type": ITEM_FUNCTION, |
579 } |
579 } |
580 } |
580 } |
581 for pou in project.getpous(): |
581 for pou in project.getpous(): |
582 pou_type = pou.getpouType() |
582 pou_type = pou.getpouType() |
583 pou_infos = {"name": pou.getname(), "type": ITEM_POU, |
583 pou_infos = {"name": pou.getname(), "type": ITEM_POU, |
584 "tagname": self.ComputePouName(pou.getname())} |
584 "tagname": ComputePouName(pou.getname())} |
585 pou_values = [] |
585 pou_values = [] |
586 if pou.getbodyType() == "SFC": |
586 if pou.getbodyType() == "SFC": |
587 transitions = [] |
587 transitions = [] |
588 for transition in pou.gettransitionList(): |
588 for transition in pou.gettransitionList(): |
589 transitions.append({ |
589 transitions.append({ |
590 "name": transition.getname(), |
590 "name": transition.getname(), |
591 "type": ITEM_TRANSITION, |
591 "type": ITEM_TRANSITION, |
592 "tagname": self.ComputePouTransitionName(pou.getname(), transition.getname()), |
592 "tagname": ComputePouTransitionName(pou.getname(), transition.getname()), |
593 "values": []}) |
593 "values": []}) |
594 pou_values.append({"name": TRANSITIONS, "type": ITEM_TRANSITIONS, "values": transitions}) |
594 pou_values.append({"name": TRANSITIONS, "type": ITEM_TRANSITIONS, "values": transitions}) |
595 actions = [] |
595 actions = [] |
596 for action in pou.getactionList(): |
596 for action in pou.getactionList(): |
597 actions.append({ |
597 actions.append({ |
598 "name": action.getname(), |
598 "name": action.getname(), |
599 "type": ITEM_ACTION, |
599 "type": ITEM_ACTION, |
600 "tagname": self.ComputePouActionName(pou.getname(), action.getname()), |
600 "tagname": ComputePouActionName(pou.getname(), action.getname()), |
601 "values": []}) |
601 "values": []}) |
602 pou_values.append({"name": ACTIONS, "type": ITEM_ACTIONS, "values": actions}) |
602 pou_values.append({"name": ACTIONS, "type": ITEM_ACTIONS, "values": actions}) |
603 if pou_type in pou_types: |
603 if pou_type in pou_types: |
604 pou_infos["values"] = pou_values |
604 pou_infos["values"] = pou_values |
605 pou_types[pou_type]["values"].append(pou_infos) |
605 pou_types[pou_type]["values"].append(pou_infos) |
607 for config in project.getconfigurations(): |
607 for config in project.getconfigurations(): |
608 config_name = config.getname() |
608 config_name = config.getname() |
609 config_infos = { |
609 config_infos = { |
610 "name": config_name, |
610 "name": config_name, |
611 "type": ITEM_CONFIGURATION, |
611 "type": ITEM_CONFIGURATION, |
612 "tagname": self.ComputeConfigurationName(config.getname()), |
612 "tagname": ComputeConfigurationName(config.getname()), |
613 "values": []} |
613 "values": []} |
614 resources = {"name": RESOURCES, "type": ITEM_RESOURCES, "values": []} |
614 resources = {"name": RESOURCES, "type": ITEM_RESOURCES, "values": []} |
615 for resource in config.getresource(): |
615 for resource in config.getresource(): |
616 resource_name = resource.getname() |
616 resource_name = resource.getname() |
617 resource_infos = { |
617 resource_infos = { |
618 "name": resource_name, |
618 "name": resource_name, |
619 "type": ITEM_RESOURCE, |
619 "type": ITEM_RESOURCE, |
620 "tagname": self.ComputeConfigurationResourceName(config.getname(), resource.getname()), |
620 "tagname": ComputeConfigurationResourceName(config.getname(), resource.getname()), |
621 "values": []} |
621 "values": []} |
622 resources["values"].append(resource_infos) |
622 resources["values"].append(resource_infos) |
623 config_infos["values"] = [resources] |
623 config_infos["values"] = [resources] |
624 configurations["values"].append(config_infos) |
624 configurations["values"].append(config_infos) |
625 infos["values"] = [datatypes, pou_types["function"], pou_types["functionBlock"], |
625 infos["values"] = [datatypes, pou_types["function"], pou_types["functionBlock"], |
655 elif words[0] == 'R': |
655 elif words[0] == 'R': |
656 return ["%s.%s" % (words[1], words[2])] |
656 return ["%s.%s" % (words[1], words[2])] |
657 elif words[0] in ['T', 'A']: |
657 elif words[0] in ['T', 'A']: |
658 return ["%s.%s" % (instance, words[2]) |
658 return ["%s.%s" % (instance, words[2]) |
659 for instance in self.SearchPouInstances( |
659 for instance in self.SearchPouInstances( |
660 self.ComputePouName(words[1]), debug)] |
660 ComputePouName(words[1]), debug)] |
661 return [] |
661 return [] |
662 |
662 |
663 def GetPouInstanceTagName(self, instance_path, debug=False): |
663 def GetPouInstanceTagName(self, instance_path, debug=False): |
664 project = self.GetProject(debug) |
664 project = self.GetProject(debug) |
665 factory = InstanceTagName(self) |
665 factory = InstanceTagName(self) |
778 if datatype_name is None: |
778 if datatype_name is None: |
779 datatype_name = self.GenerateNewName(None, None, "datatype%d") |
779 datatype_name = self.GenerateNewName(None, None, "datatype%d") |
780 # Add the datatype to project |
780 # Add the datatype to project |
781 self.Project.appenddataType(datatype_name) |
781 self.Project.appenddataType(datatype_name) |
782 self.BufferProject() |
782 self.BufferProject() |
783 return self.ComputeDataTypeName(datatype_name) |
783 return ComputeDataTypeName(datatype_name) |
784 return None |
784 return None |
785 |
785 |
786 # Remove a Data Type from project |
786 # Remove a Data Type from project |
787 def ProjectRemoveDataType(self, datatype_name): |
787 def ProjectRemoveDataType(self, datatype_name): |
788 if self.Project is not None: |
788 if self.Project is not None: |
795 # Add the pou to project |
795 # Add the pou to project |
796 self.Project.appendpou(pou_name, pou_type, body_type) |
796 self.Project.appendpou(pou_name, pou_type, body_type) |
797 if pou_type == "function": |
797 if pou_type == "function": |
798 self.SetPouInterfaceReturnType(pou_name, "BOOL") |
798 self.SetPouInterfaceReturnType(pou_name, "BOOL") |
799 self.BufferProject() |
799 self.BufferProject() |
800 return self.ComputePouName(pou_name) |
800 return ComputePouName(pou_name) |
801 return None |
801 return None |
802 |
802 |
803 def ProjectChangePouType(self, name, pou_type): |
803 def ProjectChangePouType(self, name, pou_type): |
804 if self.Project is not None: |
804 if self.Project is not None: |
805 pou = self.Project.getpou(name) |
805 pou = self.Project.getpou(name) |
853 new_pou.setpouType(pou_type) |
853 new_pou.setpouType(pou_type) |
854 |
854 |
855 self.Project.insertpou(0, new_pou) |
855 self.Project.insertpou(0, new_pou) |
856 self.BufferProject() |
856 self.BufferProject() |
857 |
857 |
858 return self.ComputePouName(new_name), |
858 return ComputePouName(new_name), |
859 |
859 |
860 # Remove a Pou from project |
860 # Remove a Pou from project |
861 def ProjectRemovePou(self, pou_name): |
861 def ProjectRemovePou(self, pou_name): |
862 if self.Project is not None: |
862 if self.Project is not None: |
863 self.Project.removepou(pou_name) |
863 self.Project.removepou(pou_name) |
877 if self.Project is not None: |
877 if self.Project is not None: |
878 if config_name is None: |
878 if config_name is None: |
879 config_name = self.GenerateNewName(None, None, "configuration%d") |
879 config_name = self.GenerateNewName(None, None, "configuration%d") |
880 self.Project.addconfiguration(config_name) |
880 self.Project.addconfiguration(config_name) |
881 self.BufferProject() |
881 self.BufferProject() |
882 return self.ComputeConfigurationName(config_name) |
882 return ComputeConfigurationName(config_name) |
883 return None |
883 return None |
884 |
884 |
885 # Remove a configuration from project |
885 # Remove a configuration from project |
886 def ProjectRemoveConfiguration(self, config_name): |
886 def ProjectRemoveConfiguration(self, config_name): |
887 if self.Project is not None: |
887 if self.Project is not None: |
893 if self.Project is not None: |
893 if self.Project is not None: |
894 if resource_name is None: |
894 if resource_name is None: |
895 resource_name = self.GenerateNewName(None, None, "resource%d") |
895 resource_name = self.GenerateNewName(None, None, "resource%d") |
896 self.Project.addconfigurationResource(config_name, resource_name) |
896 self.Project.addconfigurationResource(config_name, resource_name) |
897 self.BufferProject() |
897 self.BufferProject() |
898 return self.ComputeConfigurationResourceName(config_name, resource_name) |
898 return ComputeConfigurationResourceName(config_name, resource_name) |
899 return None |
899 return None |
900 |
900 |
901 # Remove a resource from a configuration of the project |
901 # Remove a resource from a configuration of the project |
902 def ProjectRemoveConfigurationResource(self, config_name, resource_name): |
902 def ProjectRemoveConfigurationResource(self, config_name, resource_name): |
903 if self.Project is not None: |
903 if self.Project is not None: |
909 if self.Project is not None: |
909 if self.Project is not None: |
910 pou = self.Project.getpou(pou_name) |
910 pou = self.Project.getpou(pou_name) |
911 if pou is not None: |
911 if pou is not None: |
912 pou.addtransition(transition_name, transition_type) |
912 pou.addtransition(transition_name, transition_type) |
913 self.BufferProject() |
913 self.BufferProject() |
914 return self.ComputePouTransitionName(pou_name, transition_name) |
914 return ComputePouTransitionName(pou_name, transition_name) |
915 return None |
915 return None |
916 |
916 |
917 # Remove a Transition from a Project Pou |
917 # Remove a Transition from a Project Pou |
918 def ProjectRemovePouTransition(self, pou_name, transition_name): |
918 def ProjectRemovePouTransition(self, pou_name, transition_name): |
919 # Search if the pou removed is currently opened |
919 # Search if the pou removed is currently opened |
928 if self.Project is not None: |
928 if self.Project is not None: |
929 pou = self.Project.getpou(pou_name) |
929 pou = self.Project.getpou(pou_name) |
930 if pou is not None: |
930 if pou is not None: |
931 pou.addaction(action_name, action_type) |
931 pou.addaction(action_name, action_type) |
932 self.BufferProject() |
932 self.BufferProject() |
933 return self.ComputePouActionName(pou_name, action_name) |
933 return ComputePouActionName(pou_name, action_name) |
934 return None |
934 return None |
935 |
935 |
936 # Remove an Action from a Project Pou |
936 # Remove an Action from a Project Pou |
937 def ProjectRemovePouAction(self, pou_name, action_name): |
937 def ProjectRemovePouAction(self, pou_name, action_name): |
938 # Search if the pou removed is currently opened |
938 # Search if the pou removed is currently opened |
1758 if project is not None: |
1758 if project is not None: |
1759 values.extend(project.GetEnumeratedDataTypeValues()) |
1759 values.extend(project.GetEnumeratedDataTypeValues()) |
1760 for confnodetype in self.ConfNodeTypes: |
1760 for confnodetype in self.ConfNodeTypes: |
1761 values.extend(confnodetype["types"].GetEnumeratedDataTypeValues()) |
1761 values.extend(confnodetype["types"].GetEnumeratedDataTypeValues()) |
1762 return values |
1762 return values |
1763 |
|
1764 # ------------------------------------------------------------------------------- |
|
1765 # Project Element tag name computation functions |
|
1766 # ------------------------------------------------------------------------------- |
|
1767 |
|
1768 # Compute a data type name |
|
1769 def ComputeDataTypeName(self, datatype): |
|
1770 return "D::%s" % datatype |
|
1771 |
|
1772 # Compute a pou name |
|
1773 def ComputePouName(self, pou): |
|
1774 return "P::%s" % pou |
|
1775 |
|
1776 # Compute a pou transition name |
|
1777 def ComputePouTransitionName(self, pou, transition): |
|
1778 return "T::%s::%s" % (pou, transition) |
|
1779 |
|
1780 # Compute a pou action name |
|
1781 def ComputePouActionName(self, pou, action): |
|
1782 return "A::%s::%s" % (pou, action) |
|
1783 |
|
1784 # Compute a pou name |
|
1785 def ComputeConfigurationName(self, config): |
|
1786 return "C::%s" % config |
|
1787 |
|
1788 # Compute a pou name |
|
1789 def ComputeConfigurationResourceName(self, config, resource): |
|
1790 return "R::%s::%s" % (config, resource) |
|
1791 |
|
1792 def GetElementType(self, tagname): |
|
1793 words = tagname.split("::") |
|
1794 return { |
|
1795 "D": ITEM_DATATYPE, |
|
1796 "P": ITEM_POU, |
|
1797 "T": ITEM_TRANSITION, |
|
1798 "A": ITEM_ACTION, |
|
1799 "C": ITEM_CONFIGURATION, |
|
1800 "R": ITEM_RESOURCE |
|
1801 }[words[0]] |
|
1802 |
1763 |
1803 # ------------------------------------------------------------------------------- |
1764 # ------------------------------------------------------------------------------- |
1804 # Project opened Data types management functions |
1765 # Project opened Data types management functions |
1805 # ------------------------------------------------------------------------------- |
1766 # ------------------------------------------------------------------------------- |
1806 |
1767 |