# HG changeset patch # User Laurent Bessard # Date 1340877792 -7200 # Node ID 86a2d17866842e7adbcbc38d46edbc1a7cdee773 # Parent 2681a6da58d6eeb78e106faecc070ed8d08e2ae6 Fix bug variable and connection size not updated when name or expression is too long diff -r 2681a6da58d6 -r 86a2d1786684 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