150 self.ParentWindow.RefreshScrollBars() |
150 self.ParentWindow.RefreshScrollBars() |
151 self.ParentWindow.RefreshVisibleElements() |
151 self.ParentWindow.RefreshVisibleElements() |
152 self.ParentWindow.ParentWindow.RefreshVariablePanel(self.ParentWindow.GetTagName()) |
152 self.ParentWindow.ParentWindow.RefreshVariablePanel(self.ParentWindow.GetTagName()) |
153 self.ParentWindow.Refresh(False) |
153 self.ParentWindow.Refresh(False) |
154 elif values[1] != "location": |
154 elif values[1] != "location": |
155 if values[3] == self.ParentWindow.GetTagName(): |
155 tagname = self.ParentWindow.GetTagName() |
156 id = self.ParentWindow.GetNewId() |
156 if values[3] == tagname: |
157 if values[1] == "Output": |
157 if values[1] == "Output": |
158 var_type = OUTPUT |
158 var_class = OUTPUT |
159 elif values[1] == "InOut": |
159 elif values[1] == "InOut": |
160 var_type = INPUT |
160 var_class = INPUT |
161 else: |
161 else: |
162 var_type = INPUT |
162 var_class = INPUT |
163 variable = FBD_Variable(self.ParentWindow, var_type, values[0], values[2], id) |
163 tree = dict([(var["Name"], var["Tree"]) for var in self.ParentWindow.Controler.GetEditedElementInterfaceVars(tagname, self.ParentWindow.Debug)]).get(values[0], None) |
164 width, height = variable.GetMinSize() |
164 if tree is not None: |
165 if scaling is not None: |
165 if len(tree) > 0: |
166 x = round(float(x) / float(scaling[0])) * scaling[0] |
166 menu = wx.Menu(title='') |
167 y = round(float(y) / float(scaling[1])) * scaling[1] |
167 self.GenerateTreeMenu(x, y, scaling, menu, "", var_class, [(values[0], values[2], tree)]) |
168 width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
168 self.ParentWindow.PopupMenuXY(menu) |
169 height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
169 else: |
170 variable.SetPosition(x, y) |
170 self.AddParentVariableBlock(x, y, scaling, var_class, values[0], values[2]) |
171 variable.SetSize(width, height) |
171 else: |
172 self.ParentWindow.AddBlock(variable) |
172 message = "Unknown variable \"%s\" this POU!" % values[0] |
173 self.ParentWindow.Controler.AddEditedElementVariable(self.ParentWindow.GetTagName(), id, var_type) |
|
174 self.ParentWindow.RefreshVariableModel(variable) |
|
175 self.ParentWindow.RefreshBuffer() |
|
176 self.ParentWindow.RefreshScrollBars() |
|
177 self.ParentWindow.RefreshVisibleElements() |
|
178 self.ParentWindow.Refresh(False) |
|
179 else: |
173 else: |
180 message = "Variable don't belong to this POU!" |
174 message = "Variable don't belong to this POU!" |
181 if message is not None: |
175 if message is not None: |
182 wx.CallAfter(self.ShowMessage, message) |
176 wx.CallAfter(self.ShowMessage, message) |
183 |
177 |
|
178 def GenerateTreeMenu(self, x, y, scaling, menu, base_path, var_class, tree): |
|
179 for child_name, child_type, child_tree in tree: |
|
180 if base_path: |
|
181 child_path = "%s.%s" % (base_path, child_name) |
|
182 else: |
|
183 child_path = child_name |
|
184 if len(child_tree) == 1 and isinstance(child_tree[0], ListType): |
|
185 child_path += "[0]" |
|
186 child_name += "[]" |
|
187 child_tree = child_tree[0] |
|
188 new_id = wx.NewId() |
|
189 AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=child_name) |
|
190 self.ParentWindow.Bind(wx.EVT_MENU, self.GetAddVariableBlockFunction(x, y, scaling, var_class, child_path, child_type), id=new_id) |
|
191 if len(child_tree) > 0: |
|
192 new_id = wx.NewId() |
|
193 child_menu = wx.Menu(title='') |
|
194 self.GenerateTreeMenu(x, y, scaling, child_menu, child_path, var_class, child_tree) |
|
195 menu.AppendMenu(new_id, "%s." % child_name, child_menu) |
|
196 |
|
197 def GetAddVariableBlockFunction(self, x, y, scaling, var_class, var_name, var_type): |
|
198 def AddVariableFunction(event): |
|
199 self.AddParentVariableBlock(x, y, scaling, var_class, var_name, var_type) |
|
200 return AddVariableFunction |
|
201 |
|
202 def AddParentVariableBlock(self, x, y, scaling, var_class, var_name, var_type): |
|
203 id = self.ParentWindow.GetNewId() |
|
204 variable = FBD_Variable(self.ParentWindow, var_class, var_name, var_type, id) |
|
205 width, height = variable.GetMinSize() |
|
206 if scaling is not None: |
|
207 x = round(float(x) / float(scaling[0])) * scaling[0] |
|
208 y = round(float(y) / float(scaling[1])) * scaling[1] |
|
209 width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
|
210 height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
|
211 variable.SetPosition(x, y) |
|
212 variable.SetSize(width, height) |
|
213 self.ParentWindow.AddBlock(variable) |
|
214 self.ParentWindow.Controler.AddEditedElementVariable(self.ParentWindow.GetTagName(), id, var_class) |
|
215 self.ParentWindow.RefreshVariableModel(variable) |
|
216 self.ParentWindow.RefreshBuffer() |
|
217 self.ParentWindow.RefreshScrollBars() |
|
218 self.ParentWindow.RefreshVisibleElements() |
|
219 self.ParentWindow.Refresh(False) |
|
220 |
184 def ShowMessage(self, message): |
221 def ShowMessage(self, message): |
185 message = wx.MessageDialog(self.ParentWindow, message, "Error", wx.OK|wx.ICON_ERROR) |
222 message = wx.MessageDialog(self.ParentWindow, message, "Error", wx.OK|wx.ICON_ERROR) |
186 message.ShowModal() |
223 message.ShowModal() |
187 message.Destroy() |
224 message.Destroy() |
188 |
225 |