Bug on block modification fixed
authorlbessard
Mon, 17 Sep 2007 17:51:05 +0200
changeset 94 e7f5a251f251
parent 93 c3c24b979a4d
child 95 ee66a9a1748b
Bug on block modification fixed
PLCControler.py
Viewer.py
plcopen/plcopen.py
--- a/PLCControler.py	Mon Sep 17 17:50:41 2007 +0200
+++ b/PLCControler.py	Mon Sep 17 17:51:05 2007 +0200
@@ -1498,6 +1498,12 @@
     
     def SetCurrentElementEditingBlockInfos(self, id, infos):
         block = self.GetCurrentElementEditing().getInstance(id)
+        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.GetCurrentElementEditing().changePouVar(old_type, old_name, new_type, new_name)
         for param, value in infos.items():
             if param == "name":
                 block.setInstanceName(value)
@@ -1975,9 +1981,7 @@
                 if self.CurrentElementEditing != None:
                     name = self.ElementsOpened[self.CurrentElementEditing]
                     words = name.split("::")
-                    if len(words) == 1:
-                        element.removePouVar(blocktype, instance.getInstanceName())
-                    elif words[0] in ['T', 'A']:
+                    if words[0] in ["P","T","A"]:
                         pou = self.Project.getPou(words[1])
                         pou.removePouVar(blocktype, instance.getInstanceName())    
         element.removeInstance(id)
--- a/Viewer.py	Mon Sep 17 17:50:41 2007 +0200
+++ b/Viewer.py	Mon Sep 17 17:51:05 2007 +0200
@@ -1262,6 +1262,7 @@
             self.RefreshBlockModel(block)
             self.RefreshBuffer()
             self.RefreshScrollBars()
+            self.ParentWindow.RefreshEditor()
             self.Refresh(False)
         dialog.Destroy()
 
--- a/plcopen/plcopen.py	Mon Sep 17 17:50:41 2007 +0200
+++ b/plcopen/plcopen.py	Mon Sep 17 17:51:05 2007 +0200
@@ -422,6 +422,19 @@
         content[-1]["value"].appendVariable(var)
     setattr(cls, "addPouVar", addPouVar)
     
+    def changePouVar(self, old_type, old_name, new_type, new_name):
+        content = self.interface.getContent()
+        for varlist in content:
+            variables = varlist["value"].getVariable()
+            for var in variables:
+                if var.getName() == old_name:
+                    var_type = var.getType().getValue()
+                    if isinstance(var_type, PLCOpenClasses["derived"]) and var_type.getName() == old_type:
+                        var.setName(new_name)
+                        var.getType().getValue().setName(new_type)
+                        return
+    setattr(cls, "changePouVar", changePouVar)
+    
     def removePouVar(self, type, name):
         content = self.interface.getContent()
         for varlist in content: