PLCControler.py
changeset 154 203c4acdaf27
parent 151 aaa80b48bead
child 162 e746ff4aa8be
--- a/PLCControler.py	Wed Jan 23 18:25:57 2008 +0100
+++ b/PLCControler.py	Wed Jan 23 18:26:49 2008 +0100
@@ -1427,7 +1427,7 @@
                 infos["connector"] = {}
                 infos["connector"]["position"] = instance.connectionPointOut.getrelPositionXY()
             elif isinstance(instance, plcopen.commonObjects_connector):
-                infos["name"] = instance.getName()
+                infos["name"] = instance.getname()
                 infos["type"] = "connection"
                 infos["connector"] = {}
                 infos["connector"]["position"] = instance.connectionPointIn.getrelPositionXY()
@@ -1667,6 +1667,12 @@
             pou = self.Project.getpou(words[1])
             pou.changepouVar(old_type, old_name, new_type, new_name)
     
+    def RemoveEditedElementPouVar(self, tagname, type, name):
+        words = tagname.split("::")
+        if words[0] in ['P', 'T', 'A']:
+            pou = self.Project.getpou(words[1])
+            pou.removepouVar(type, name)
+    
     def AddEditedElementBlock(self, tagname, id, blocktype, blockname = None):
         element = self.GetEditedElement(tagname)
         if element is not None:
@@ -1684,15 +1690,19 @@
         element = self.GetEditedElement(tagname)
         if element is not None:
             block = element.getinstance(id)
-            blocktype = infos.get("type", block.gettypeName())
-            blocktype_infos = GetBlockType(blocktype)
-            if blocktype_infos["type"] != "function":
-                if "name" in infos or "type" in infos:
-                    old_name = block.getinstanceName()
-                    old_type = block.gettypeName()
-                    new_name = infos.get("name", old_name)
-                    new_type = infos.get("type", old_type)
-                    self.ChangeEditedElementPouVar(tagname, old_type, old_name, new_type, new_name)
+            old_name = block.getinstanceName()
+            old_type = block.gettypeName()
+            new_name = infos.get("name", old_name)
+            new_type = infos.get("type", old_type)
+            old_typeinfos = GetBlockType(old_type)
+            new_typeinfos = GetBlockType(new_type)
+            if new_typeinfos["type"] != old_typeinfos["type"]:
+                if new_typeinfos["type"] == "function":
+                    self.RemoveEditedElementPouVar(tagname, old_type, old_name)
+                else:
+                    self.AddEditedElementPouVar(tagname, new_type, new_name)
+            elif new_typeinfos["type"] != "function" and old_name != new_name:
+                self.ChangeEditedElementPouVar(tagname, old_type, old_name, new_type, new_name)
             for param, value in infos.items():
                 if param == "name":
                     block.setinstanceName(value)
@@ -2212,8 +2222,7 @@
         if element is not None:
             instance = element.getinstance(id)
             if isinstance(instance, plcopen.fbdObjects_block):
-                blocktype = instance.gettypeName()
-                element.removepouVar(blocktype, instance.getinstanceName())    
+                self.RemoveEditedElementPouVar(tagname, instance.gettypeName(), instance.getinstanceName())
             element.removeinstance(id)
             self.RefreshPouUsingTree()