279 var_class = INPUT |
279 var_class = INPUT |
280 if values[2] is not None: |
280 if values[2] is not None: |
281 var_type = values[2] |
281 var_type = values[2] |
282 else: |
282 else: |
283 var_type = LOCATIONDATATYPES.get(values[0][2], ["BOOL"])[0] |
283 var_type = LOCATIONDATATYPES.get(values[0][2], ["BOOL"])[0] |
284 id = self.ParentWindow.GetNewId() |
|
285 variable = FBD_Variable(self.ParentWindow, var_class, var_name, var_type, id) |
|
286 width, height = variable.GetMinSize() |
|
287 if scaling is not None: |
|
288 x = round(float(x) / float(scaling[0])) * scaling[0] |
|
289 y = round(float(y) / float(scaling[1])) * scaling[1] |
|
290 width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
|
291 height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
|
292 variable.SetPosition(x, y) |
|
293 variable.SetSize(width, height) |
|
294 self.ParentWindow.AddBlock(variable) |
|
295 if not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: |
284 if not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: |
296 self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, values[0], values[4]) |
285 self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, values[0], values[4]) |
297 self.ParentWindow.Controler.AddEditedElementVariable(tagname, id, var_class) |
286 self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type) |
298 self.ParentWindow.RefreshVariableModel(variable) |
|
299 self.ParentWindow.RefreshBuffer() |
|
300 self.ParentWindow.RefreshScrollBars() |
|
301 self.ParentWindow.RefreshVisibleElements() |
|
302 self.ParentWindow.ParentWindow.RefreshVariablePanel(tagname) |
|
303 self.ParentWindow.Refresh(False) |
|
304 elif values[3] == tagname: |
287 elif values[3] == tagname: |
305 if values[1] == "Output": |
288 if values[1] == "Output": |
306 var_class = OUTPUT |
289 var_class = OUTPUT |
307 elif values[1] == "InOut": |
290 elif values[1] == "InOut": |
308 var_class = INPUT |
291 var_class = INPUT |
313 if len(tree[0]) > 0: |
296 if len(tree[0]) > 0: |
314 menu = wx.Menu(title='') |
297 menu = wx.Menu(title='') |
315 self.GenerateTreeMenu(x, y, scaling, menu, "", var_class, [(values[0], values[2], tree)]) |
298 self.GenerateTreeMenu(x, y, scaling, menu, "", var_class, [(values[0], values[2], tree)]) |
316 self.ParentWindow.PopupMenuXY(menu) |
299 self.ParentWindow.PopupMenuXY(menu) |
317 else: |
300 else: |
318 self.AddParentVariableBlock(x, y, scaling, var_class, values[0], values[2]) |
301 self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, values[0], values[2]) |
319 else: |
302 else: |
320 message = _("Unknown variable \"%s\" for this POU!") % values[0] |
303 message = _("Unknown variable \"%s\" for this POU!") % values[0] |
321 else: |
304 else: |
322 message = _("Variable don't belong to this POU!") |
305 message = _("Variable don't belong to this POU!") |
323 if message is not None: |
306 if message is not None: |
341 self.GenerateTreeMenu(x, y, scaling, child_menu, child_path, var_class, child_tree) |
324 self.GenerateTreeMenu(x, y, scaling, child_menu, child_path, var_class, child_tree) |
342 menu.AppendMenu(new_id, "%s." % child_name, child_menu) |
325 menu.AppendMenu(new_id, "%s." % child_name, child_menu) |
343 |
326 |
344 def GetAddVariableBlockFunction(self, x, y, scaling, var_class, var_name, var_type): |
327 def GetAddVariableBlockFunction(self, x, y, scaling, var_class, var_name, var_type): |
345 def AddVariableFunction(event): |
328 def AddVariableFunction(event): |
346 self.AddParentVariableBlock(x, y, scaling, var_class, var_name, var_type) |
329 self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type) |
347 return AddVariableFunction |
330 return AddVariableFunction |
348 |
|
349 def AddParentVariableBlock(self, x, y, scaling, var_class, var_name, var_type): |
|
350 id = self.ParentWindow.GetNewId() |
|
351 variable = FBD_Variable(self.ParentWindow, var_class, var_name, var_type, id) |
|
352 width, height = variable.GetMinSize() |
|
353 if scaling is not None: |
|
354 x = round(float(x) / float(scaling[0])) * scaling[0] |
|
355 y = round(float(y) / float(scaling[1])) * scaling[1] |
|
356 width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
|
357 height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
|
358 variable.SetPosition(x, y) |
|
359 variable.SetSize(width, height) |
|
360 self.ParentWindow.AddBlock(variable) |
|
361 self.ParentWindow.Controler.AddEditedElementVariable(self.ParentWindow.GetTagName(), id, var_class) |
|
362 self.ParentWindow.RefreshVariableModel(variable) |
|
363 self.ParentWindow.RefreshBuffer() |
|
364 self.ParentWindow.RefreshScrollBars() |
|
365 self.ParentWindow.RefreshVisibleElements() |
|
366 self.ParentWindow.Refresh(False) |
|
367 |
331 |
368 def ShowMessage(self, message): |
332 def ShowMessage(self, message): |
369 message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR) |
333 message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR) |
370 message.ShowModal() |
334 message.ShowModal() |
371 message.Destroy() |
335 message.Destroy() |
1759 event.Skip() |
1723 event.Skip() |
1760 else: |
1724 else: |
1761 event.Skip() |
1725 event.Skip() |
1762 |
1726 |
1763 #------------------------------------------------------------------------------- |
1727 #------------------------------------------------------------------------------- |
|
1728 # Model adding functions from Drop Target |
|
1729 #------------------------------------------------------------------------------- |
|
1730 |
|
1731 def AddVariableBlock(self, x, y, scaling, var_class, var_name, var_type): |
|
1732 id = self.GetNewId() |
|
1733 variable = FBD_Variable(self, var_class, var_name, var_type, id) |
|
1734 width, height = variable.GetMinSize() |
|
1735 if scaling is not None: |
|
1736 x = round(float(x) / float(scaling[0])) * scaling[0] |
|
1737 y = round(float(y) / float(scaling[1])) * scaling[1] |
|
1738 width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
|
1739 height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
|
1740 variable.SetPosition(x, y) |
|
1741 variable.SetSize(width, height) |
|
1742 self.AddBlock(variable) |
|
1743 self.Controler.AddEditedElementVariable(self.GetTagName(), id, var_class) |
|
1744 self.RefreshVariableModel(variable) |
|
1745 self.RefreshBuffer() |
|
1746 self.RefreshScrollBars() |
|
1747 self.RefreshVisibleElements() |
|
1748 self.Refresh(False) |
|
1749 |
|
1750 #------------------------------------------------------------------------------- |
1764 # Model adding functions |
1751 # Model adding functions |
1765 #------------------------------------------------------------------------------- |
1752 #------------------------------------------------------------------------------- |
1766 |
1753 |
1767 def GetScaledSize(self, width, height): |
1754 def GetScaledSize(self, width, height): |
1768 if self.Scaling is not None: |
1755 if self.Scaling is not None: |