Fix bug when copying transition and the connected FBD or LD diagram
authorLaurent Bessard
Mon, 03 Dec 2012 12:33:21 +0100
changeset 891 39f355a535d8
parent 890 b3cafb73c5e9
child 892 771581a6b0be
Fix bug when copying transition and the connected FBD or LD diagram
editors/Viewer.py
plcopen/plcopen.py
--- a/editors/Viewer.py	Mon Dec 03 12:31:27 2012 +0100
+++ b/editors/Viewer.py	Mon Dec 03 12:33:21 2012 +0100
@@ -3093,16 +3093,16 @@
         return isinstance(element, FBD_Block) and element.GetName() != "" or isinstance(element, SFC_Step)
 
     def CopyBlock(self, element, pos):
-        id = self.GetNewId()
         if isinstance(element, Graphic_Group):
             block = element.Clone(self, pos=pos)
         else:
+            new_id = self.GetNewId()
             if self.IsNamedElement(element):
                 name = self.GenerateNewName(element)
-                block = element.Clone(self, id, name, pos)
+                block = element.Clone(self, new_id, name, pos)
             else:
                 name = None
-                block = element.Clone(self, id, pos=pos)
+                block = element.Clone(self, new_id, pos=pos)
             self.AddBlockInModel(block)
         return block
     
--- a/plcopen/plcopen.py	Mon Dec 03 12:31:27 2012 +0100
+++ b/plcopen/plcopen.py	Mon Dec 03 12:33:21 2012 +0100
@@ -2330,7 +2330,7 @@
             tree.childNodes = [node]
     setattr(cls, "compatibility", compatibility)
 
-cls = _initElementClass("transition", "sfcObjects_transition", "single")
+cls = _initElementClass("transition", "sfcObjects_transition")
 if cls:
     def getinfos(self):
         infos = _getelementinfos(self)
@@ -2382,6 +2382,46 @@
         return ""
     setattr(cls, "getconditionContent", getconditionContent)
 
+    def getconditionConnection(self):
+        if self.condition:
+            content = self.condition.getcontent()
+            if content["name"] == "connectionPointIn":
+                return content["value"]
+        return None
+    setattr(cls, "getconditionConnection", getconditionConnection)
+
+    def getBoundingBox(self):
+        bbox = _getBoundingBoxSingle(self)
+        condition_connection = self.getconditionConnection()
+        if condition_connection:
+            bbox.union(_getConnectionsBoundingBox(condition_connection))
+        return bbox
+    setattr(cls, "getBoundingBox", getBoundingBox)
+    
+    def translate(self, dx, dy):
+        _translateSingle(self, dx, dy)
+        condition_connection = self.getconditionConnection()
+        if condition_connection:
+            _translateConnections(condition_connection, dx, dy)
+    setattr(cls, "translate", translate)
+    
+    def filterConnections(self, connections):
+        _filterConnectionsSingle(self, connections)
+        condition_connection = self.getconditionConnection()
+        if condition_connection:
+            _filterConnections(condition_connection, self.localId, connections)
+    setattr(cls, "filterConnections", filterConnections)
+    
+    def updateConnectionsId(self, translation):
+        connections_end = []
+        if self.connectionPointIn is not None:
+            connections_end = _updateConnectionsId(self.connectionPointIn, translation)
+        condition_connection = self.getconditionConnection()
+        if condition_connection:
+            connections_end.extend(_updateConnectionsId(condition_connection, translation))
+        return _getconnectionsdefinition(self, connections_end)
+    setattr(cls, "updateConnectionsId", updateConnectionsId)
+
     def updateElementName(self, old_name, new_name):
         if self.condition:
             content = self.condition.getcontent()
@@ -2402,10 +2442,10 @@
     setattr(cls, "updateElementAddress", updateElementAddress)
 
     def getconnections(self):
-        if self.condition:
-            content = self.condition.getcontent()
-            if content["name"] == "connectionPointIn":
-                return content["value"].getconnections()
+        condition_connection = self.getconditionConnection()
+        if condition_connection:
+            return condition_connection.getconnections()
+        return None
     setattr(cls, "getconnections", getconnections)
     
     def Search(self, criteria, parent_infos=[]):