217 if values is not None: |
219 if values is not None: |
218 if values[1] == "debug": |
220 if values[1] == "debug": |
219 pass |
221 pass |
220 elif values[1] == "program": |
222 elif values[1] == "program": |
221 message = _("Programs can't be used by other POUs!") |
223 message = _("Programs can't be used by other POUs!") |
222 elif values[1] in ["function", "functionBlock", "program"]: |
224 elif values[1] in ["function", "functionBlock"]: |
223 name, type = self.ParentWindow.Controler.GetEditedElementType(self.ParentWindow.GetTagName(), self.ParentWindow.Debug) |
225 words = tagname.split("::") |
224 words = self.ParentWindow.TagName.split("::") |
226 if pou_name == values[0]: |
225 if name == values[0]: |
227 message = _("\"%s\" can't use itself!")%pou_name |
226 message = _("\"%s\" can't use itself!")%name |
228 elif pou_type == "function" and values[1] != "function": |
227 elif type == "function" and values[1] != "function": |
|
228 message = _("Function Blocks can't be used in Functions!") |
229 message = _("Function Blocks can't be used in Functions!") |
229 elif words[0] == "T" and values[1] != "function": |
230 elif words[0] == "T" and values[1] != "function": |
230 message = _("Function Blocks can't be used in Transitions!") |
231 message = _("Function Blocks can't be used in Transitions!") |
231 elif self.ParentWindow.Controler.PouIsUsedBy(name, values[0], self.ParentWindow.Debug): |
232 elif self.ParentWindow.Controler.PouIsUsedBy(pou_name, values[0], self.ParentWindow.Debug): |
232 message = _("\"%s\" is already used by \"%s\"!")%(name, values[0]) |
233 message = _("\"%s\" is already used by \"%s\"!")%(pou_name, values[0]) |
233 else: |
234 else: |
234 blockname = values[2] |
235 blockname = values[2] |
235 if len(values) > 3: |
236 if len(values) > 3: |
236 blockinputs = values[3] |
237 blockinputs = values[3] |
237 else: |
238 else: |
257 width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
258 width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
258 height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
259 height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
259 block.SetPosition(x, y) |
260 block.SetPosition(x, y) |
260 block.SetSize(width, height) |
261 block.SetSize(width, height) |
261 self.ParentWindow.AddBlock(block) |
262 self.ParentWindow.AddBlock(block) |
262 self.ParentWindow.Controler.AddEditedElementBlock(self.ParentWindow.GetTagName(), id, values[0], blockname) |
263 self.ParentWindow.Controler.AddEditedElementBlock(tagname, id, values[0], blockname) |
263 self.ParentWindow.RefreshBlockModel(block) |
264 self.ParentWindow.RefreshBlockModel(block) |
264 self.ParentWindow.RefreshBuffer() |
265 self.ParentWindow.RefreshBuffer() |
265 self.ParentWindow.RefreshScrollBars() |
266 self.ParentWindow.RefreshScrollBars() |
266 self.ParentWindow.RefreshVisibleElements() |
267 self.ParentWindow.RefreshVisibleElements() |
267 self.ParentWindow.ParentWindow.RefreshVariablePanel(self.ParentWindow.GetTagName()) |
268 self.ParentWindow.ParentWindow.RefreshVariablePanel(tagname) |
268 self.ParentWindow.Refresh(False) |
269 self.ParentWindow.Refresh(False) |
269 elif values[1] != "location": |
270 elif values[1] == "location": |
270 tagname = self.ParentWindow.GetTagName() |
271 if len(values) > 2 and pou_type == "program": |
271 if values[3] == tagname: |
272 var_name = values[3] |
272 if values[1] == "Output": |
273 if var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]: |
273 var_class = OUTPUT |
274 message = _("\"%s\" pou already exists!")%blockname |
274 elif values[1] == "InOut": |
275 elif var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: |
275 var_class = INPUT |
276 message = _("\"%s\" element for this pou already exists!")%blockname |
276 else: |
277 else: |
277 var_class = INPUT |
278 if values[0][1] == "Q": |
278 tree = dict([(var["Name"], var["Tree"]) for var in self.ParentWindow.Controler.GetEditedElementInterfaceVars(tagname, self.ParentWindow.Debug)]).get(values[0], None) |
279 var_class = OUTPUT |
279 if tree is not None: |
|
280 if len(tree[0]) > 0: |
|
281 menu = wx.Menu(title='') |
|
282 self.GenerateTreeMenu(x, y, scaling, menu, "", var_class, [(values[0], values[2], tree)]) |
|
283 self.ParentWindow.PopupMenuXY(menu) |
|
284 else: |
280 else: |
285 self.AddParentVariableBlock(x, y, scaling, var_class, values[0], values[2]) |
281 var_class = INPUT |
|
282 if values[2] is not None: |
|
283 var_type = values[2] |
|
284 else: |
|
285 var_type = LOCATIONDATATYPES.get(values[0][2], ["BOOL"])[0] |
|
286 id = self.ParentWindow.GetNewId() |
|
287 variable = FBD_Variable(self.ParentWindow, var_class, var_name, var_type, id) |
|
288 width, height = variable.GetMinSize() |
|
289 if scaling is not None: |
|
290 x = round(float(x) / float(scaling[0])) * scaling[0] |
|
291 y = round(float(y) / float(scaling[1])) * scaling[1] |
|
292 width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
|
293 height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
|
294 variable.SetPosition(x, y) |
|
295 variable.SetSize(width, height) |
|
296 self.ParentWindow.AddBlock(variable) |
|
297 self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, values[0], values[4]) |
|
298 self.ParentWindow.Controler.AddEditedElementVariable(tagname, id, var_class) |
|
299 self.ParentWindow.RefreshVariableModel(variable) |
|
300 self.ParentWindow.RefreshBuffer() |
|
301 self.ParentWindow.RefreshScrollBars() |
|
302 self.ParentWindow.RefreshVisibleElements() |
|
303 self.ParentWindow.ParentWindow.RefreshVariablePanel(tagname) |
|
304 self.ParentWindow.Refresh(False) |
|
305 elif values[3] == tagname: |
|
306 if values[1] == "Output": |
|
307 var_class = OUTPUT |
|
308 elif values[1] == "InOut": |
|
309 var_class = INPUT |
|
310 else: |
|
311 var_class = INPUT |
|
312 tree = dict([(var["Name"], var["Tree"]) for var in self.ParentWindow.Controler.GetEditedElementInterfaceVars(tagname, self.ParentWindow.Debug)]).get(values[0], None) |
|
313 if tree is not None: |
|
314 if len(tree[0]) > 0: |
|
315 menu = wx.Menu(title='') |
|
316 self.GenerateTreeMenu(x, y, scaling, menu, "", var_class, [(values[0], values[2], tree)]) |
|
317 self.ParentWindow.PopupMenuXY(menu) |
286 else: |
318 else: |
287 message = _("Unknown variable \"%s\" for this POU!") % values[0] |
319 self.AddParentVariableBlock(x, y, scaling, var_class, values[0], values[2]) |
288 else: |
320 else: |
289 message = _("Variable don't belong to this POU!") |
321 message = _("Unknown variable \"%s\" for this POU!") % values[0] |
|
322 else: |
|
323 message = _("Variable don't belong to this POU!") |
290 if message is not None: |
324 if message is not None: |
291 wx.CallAfter(self.ShowMessage, message) |
325 wx.CallAfter(self.ShowMessage, message) |
292 |
326 |
293 def GenerateTreeMenu(self, x, y, scaling, menu, base_path, var_class, tree): |
327 def GenerateTreeMenu(self, x, y, scaling, menu, base_path, var_class, tree): |
294 for child_name, child_type, (child_tree, child_dimensions) in tree: |
328 for child_name, child_type, (child_tree, child_dimensions) in tree: |