111 |
111 |
112 # Refresh the size of text for execution order |
112 # Refresh the size of text for execution order |
113 def RefreshExecutionOrderSize(self): |
113 def RefreshExecutionOrderSize(self): |
114 self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) |
114 self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) |
115 |
115 |
116 # Refresh the block bounding box |
116 # Returns if the point given is in the bounding box |
117 def RefreshBoundingBox(self): |
117 def HitTest(self, pt, connectors=True): |
|
118 if self.Name != "": |
|
119 test_text = self.GetTextBoundingBox().InsideXY(pt.x, pt.y) |
|
120 else: |
|
121 test_text = False |
|
122 test_block = self.GetBlockBoundingBox(connectors).InsideXY(pt.x, pt.y) |
|
123 return test_text or test_block |
|
124 |
|
125 # Returns the bounding box of the name outside the block |
|
126 def GetTextBoundingBox(self): |
118 # Calculate the size of the name outside the block |
127 # Calculate the size of the name outside the block |
119 text_width, text_height = self.NameSize |
128 text_width, text_height = self.NameSize |
120 # Calculate the bounding box size |
129 return wx.Rect(self.Pos.x + (self.Size[0] - text_width) / 2, |
121 bbx_x = self.Pos.x - max(min(1, len(self.Inputs)) * CONNECTOR_SIZE, (text_width - self.Size[0]) / 2) |
130 self.Pos.y - (text_height + 2), |
122 bbx_width = max(self.Size[0] + 1 + (min(1, len(self.Inputs)) + min(1, len(self.Outputs))) * CONNECTOR_SIZE, text_width) |
131 text_width, |
123 if self.Name != "": |
132 text_height) |
124 bbx_y = self.Pos.y - (text_height + 2) |
133 |
125 bbx_height = self.Size[1] + (text_height + 2) |
134 # Returns the bounding box of function block without name outside |
126 else: |
135 def GetBlockBoundingBox(self, connectors=True): |
127 bbx_y = self.Pos.y |
136 bbx_x, bbx_y = self.Pos.x, self.Pos.y |
128 bbx_height = self.Size[1] |
137 bbx_width, bbx_height = self.Size |
|
138 if connectors: |
|
139 bbx_x -= min(1, len(self.Inputs)) * CONNECTOR_SIZE |
|
140 bbx_width += (min(1, len(self.Inputs)) + min(1, len(self.Outputs))) * CONNECTOR_SIZE |
129 if self.ExecutionOrder != 0: |
141 if self.ExecutionOrder != 0: |
130 bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0]) |
142 bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0]) |
131 bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0]) |
143 bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0]) |
132 bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2) |
144 bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2) |
133 self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
145 return wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
|
146 |
|
147 # Refresh the block bounding box |
|
148 def RefreshBoundingBox(self): |
|
149 self.BoundingBox = self.GetBlockBoundingBox() |
|
150 if self.Name != "": |
|
151 self.BoundingBox.Union(self.GetTextBoundingBox()) |
134 |
152 |
135 # Refresh the positions of the block connectors |
153 # Refresh the positions of the block connectors |
136 def RefreshConnectors(self): |
154 def RefreshConnectors(self): |
137 scaling = self.Parent.GetScaling() |
155 scaling = self.Parent.GetScaling() |
138 # Calculate the size for the connector lines |
156 # Calculate the size for the connector lines |