Fix bug variable and connection size not updated when name or expression is too long
authorLaurent Bessard
Thu, 28 Jun 2012 12:03:12 +0200
changeset 717 86a2d1786684
parent 716 2681a6da58d6
child 718 0183a66eddf9
Fix bug variable and connection size not updated when name or expression is too long
graphics/FBD_Objects.py
--- a/graphics/FBD_Objects.py	Thu Jun 28 12:00:45 2012 +0200
+++ b/graphics/FBD_Objects.py	Thu Jun 28 12:03:12 2012 +0200
@@ -161,7 +161,7 @@
             position = BLOCK_LINE_SIZE + linesize / 2
             for i in xrange(lines):
                 if scaling is not None:
-                    ypos = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y
+                    ypos = round_scaling(self.Pos.y + position, scaling[1]) - self.Pos.y
                 else:
                     ypos = position
                 if i < len(self.Inputs):
@@ -590,7 +590,7 @@
     def RefreshConnectors(self):
         scaling = self.Parent.GetScaling()
         if scaling is not None:
-            position = round(float(self.Pos.y + self.Size[1] / 2) / float(scaling[1])) * scaling[1] - self.Pos.y
+            position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y
         else:
             position = self.Size[1] / 2
         if self.Input:
@@ -690,6 +690,34 @@
     def GetExecutionOrder(self):
         return self.ExecutionOrder
     
+    # Changes the element size
+    def SetSize(self, width, height):
+        scaling = self.Parent.GetScaling()
+        min_width, min_height = self.GetMinSize()
+        if width < min_width:
+            if self.Type == INPUT:
+                posx = max(0, self.Pos.x + width - min_width)
+                if scaling is not None:
+                    posx = round_scaling(posx, scaling[0])
+                self.Pos.x = posx
+            elif self.Type == OUTPUT:
+                posy = max(0, self.Pos.x + (width - min_width) / 2)
+                if scaling is not None:
+                    posx = round_scaling(posx, scaling[0])
+                self.Pos.x = posx
+            width = min_width
+            if scaling is not None:
+                width = round_scaling(width, scaling[0], 1)
+        if height < min_height:
+            posy = max(0, self.Pos.y + (height - min_height) / 2)
+            if scaling is not None:
+                posy = round_scaling(posy, scaling[1])
+            self.Pos.y = posy
+            height = min_height
+            if scaling is not None:
+                height = round_scaling(height, scaling[1], 1)
+        Graphic_Element.SetSize(self, width, height)
+    
     # Returns the variable minimum size
     def GetMinSize(self):
         return self.NameSize[0] + 10, self.NameSize[1] + 10
@@ -837,7 +865,7 @@
     def RefreshConnectors(self):
         scaling = self.Parent.GetScaling()
         if scaling is not None:
-            position = round(float(self.Pos.y + self.Size[1] / 2) / float(scaling[1])) * scaling[1] - self.Pos.y
+            position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y
         else:
             position = self.Size[1] / 2
         if self.Type == CONNECTOR:
@@ -902,6 +930,29 @@
     def GetName(self):
         return self.Name
     
+    # Changes the element size
+    def SetSize(self, width, height):
+        scaling = self.Parent.GetScaling()
+        min_width, min_height = self.GetMinSize()
+        if width < min_width:
+            if self.Type == CONTINUATION:
+                posx = max(0, self.Pos.x + width - min_width)
+                if scaling is not None:
+                    posx = round_scaling(posx, scaling[0])
+                self.Pos.x = posx
+            width = min_width
+            if scaling is not None:
+                width = round_scaling(width, scaling[0], 1)
+        if height < min_height:
+            posy = max(0, self.Pos.y + (height - min_height) / 2)
+            if scaling is not None:
+                posy = round_scaling(posy, scaling[1])
+            self.Pos.y = posy
+            height = min_height
+            if scaling is not None:
+                height = round_scaling(height, scaling[1], 1)
+        Graphic_Element.SetSize(self, width, height)
+    
     # Returns the connection minimum size
     def GetMinSize(self):
         text_width, text_height = self.NameSize