# HG changeset patch # User laurent # Date 1326046618 -3600 # Node ID 8a60ffcfd70bdb2aeccc49a7012062d4d7748fdc # Parent 8baeb9dff775460e8ff9ec3c4f6cf681a62463bf Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables Adding support for drag'n dropping located variables from topology panel to configurations and resources variable panel for declaring global located variables diff -r 8baeb9dff775 -r 8a60ffcfd70b LDViewer.py --- a/LDViewer.py Sun Jan 08 18:23:55 2012 +0100 +++ b/LDViewer.py Sun Jan 08 19:16:58 2012 +0100 @@ -897,7 +897,6 @@ if self.GetDrawingMode() == FREEDRAWING_MODE: Viewer.DeleteContact(self, contact) else: - print "Delete" rungindex = self.FindRung(contact) rung = self.Rungs[rungindex] old_bbox = rung.GetBoundingBox() diff -r 8baeb9dff775 -r 8a60ffcfd70b PLCControler.py --- a/PLCControler.py Sun Jan 08 18:23:55 2012 +0100 +++ b/PLCControler.py Sun Jan 08 19:16:58 2012 +0100 @@ -1950,9 +1950,15 @@ if words[0] in ['P', 'T', 'A']: pou = self.Project.getpou(words[1]) if pou is not None: - if pou.interface is None: - pou.interface = plcopen.pou_interface() - pou.addpouVar(type, name, location, description) + pou.addpouLocalVar(type, name, location, description) + + def AddEditedElementPouExternalVar(self, tagname, type, name): + if self.Project is not None: + words = tagname.split("::") + if words[0] in ['P', 'T', 'A']: + pou = self.Project.getpou(words[1]) + if pou is not None: + pou.addpouExternalVar(type, name) def ChangeEditedElementPouVar(self, tagname, old_type, old_name, new_type, new_name): if self.Project is not None: diff -r 8baeb9dff775 -r 8a60ffcfd70b TextViewer.py --- a/TextViewer.py Sun Jan 08 18:23:55 2012 +0100 +++ b/TextViewer.py Sun Jan 08 19:16:58 2012 +0100 @@ -319,6 +319,16 @@ event.SetDragText(var_name) else: event.SetDragText("") + elif values[1] == "Global": + var_name = values[0] + if var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: + message = _("\"%s\" pou already exists!")%var_name + else: + if not var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: + self.Controler.AddEditedElementPouExternalVar(self.TagName, values[2], var_name) + self.RefreshVariablePanel() + self.RefreshVariableTree() + event.SetDragText(var_name) elif values[3] == self.TagName: self.ResetBuffer() event.SetDragText(values[0]) diff -r 8baeb9dff775 -r 8a60ffcfd70b Viewer.py --- a/Viewer.py Sun Jan 08 18:23:55 2012 +0100 +++ b/Viewer.py Sun Jan 08 19:16:58 2012 +0100 @@ -279,8 +279,17 @@ var_type = LOCATIONDATATYPES.get(values[0][2], ["BOOL"])[0] if not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, values[0], values[4]) + self.ParentWindow.RefreshVariablePanel() + self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type) + elif values[1] == "Global": + var_name = values[0] + if var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]: + message = _("\"%s\" pou already exists!")%var_name + else: + if not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: + self.ParentWindow.Controler.AddEditedElementPouExternalVar(tagname, values[2], var_name) self.ParentWindow.RefreshVariablePanel() - self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type) + self.ParentWindow.AddVariableBlock(x, y, scaling, INPUT, var_name, values[2]) elif values[3] == tagname: if values[1] == "Output": var_class = OUTPUT diff -r 8baeb9dff775 -r 8a60ffcfd70b controls/VariablePanel.py --- a/controls/VariablePanel.py Sun Jan 08 18:23:55 2012 +0100 +++ b/controls/VariablePanel.py Sun Jan 08 19:16:58 2012 +0100 @@ -220,28 +220,28 @@ x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y) col = self.ParentWindow.VariablesGrid.XToCol(x) row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize()) - if col != wx.NOT_FOUND and row != wx.NOT_FOUND: - if self.ParentWindow.Table.GetColLabelValue(col, False) != "Location": - return - message = None - if not self.ParentWindow.Table.GetValueByName(row, "Edit"): - message = _("Can't give a location to a function block instance") - elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]: - message = _("Can only give a location to local or global variables") - else: - try: - values = eval(data) - except: - message = _("Invalid value \"%s\" for location")%data - values = None - if not isinstance(values, TupleType): - message = _("Invalid value \"%s\" for location")%data - values = None - if values is not None and values[1] == "location": + message = None + element_type = self.ParentWindow.ElementType + try: + values = eval(data) + except: + message = _("Invalid value \"%s\" for variable grid element")%data + values = None + if not isinstance(values, TupleType): + message = _("Invalid value \"%s\" for variable grid element")%data + values = None + if values is not None: + if col != wx.NOT_FOUND and row != wx.NOT_FOUND: + if self.ParentWindow.Table.GetColLabelValue(col, False) != "Location": + return + if not self.ParentWindow.Table.GetValueByName(row, "Edit"): + message = _("Can't give a location to a function block instance") + elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]: + message = _("Can only give a location to local or global variables") + elif values is not None and values[1] == "location": location = values[0] variable_type = self.ParentWindow.Table.GetValueByName(row, "Type") base_type = self.ParentWindow.Controler.GetBaseType(variable_type) - message = None if location.startswith("%"): if base_type != values[2]: message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type) @@ -270,9 +270,33 @@ self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid) self.ParentWindow.SaveValues() dialog.Destroy() - if message is not None: - wx.CallAfter(self.ShowMessage, message) + elif (element_type not in ["config", "resource"] and values[1] == "Global" and self.ParentWindow.Filter in ["All", "Interface", "External"] or + element_type in ["config", "resource"] and values[1] == "location"): + if values[1] == "location": + var_name = values[3] + else: + var_name = values[0] + tagname = self.ParentWindow.GetTagName() + if var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]: + message = _("\"%s\" pou already exists!")%var_name + elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: + var_infos = self.ParentWindow.DefaultValue.copy() + var_infos["Name"] = var_name + var_infos["Type"] = values[2] + if values[1] == "location": + var_infos["Class"] = "Global" + var_infos["Location"] = values[0] + else: + var_infos["Class"] = "External" + var_infos["Number"] = len(self.ParentWindow.Values) + self.ParentWindow.Values.append(var_infos) + self.ParentWindow.SaveValues() + self.ParentWindow.RefreshValues() + + if message is not None: + wx.CallAfter(self.ShowMessage, message) + def ShowMessage(self, message): message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR) message.ShowModal() @@ -537,6 +561,9 @@ def SetTagName(self, tagname): self.TagName = tagname + def GetTagName(self): + return self.TagName + def IsFunctionBlockType(self, name): bodytype = self.Controler.GetEditedElementBodyType(self.TagName) pouname, poutype = self.Controler.GetEditedElementType(self.TagName) diff -r 8baeb9dff775 -r 8a60ffcfd70b plcopen/plcopen.py --- a/plcopen/plcopen.py Sun Jan 08 18:23:55 2012 +0100 +++ b/plcopen/plcopen.py Sun Jan 08 19:16:58 2012 +0100 @@ -1288,17 +1288,25 @@ self.interface.appendcontent({"name" : VarTypes[vartype], "value" : varlist}) setattr(cls, "setvars", setvars) - def addpouVar(self, type, name, location="", description=""): + def addpouLocalVar(self, type, name, location="", description=""): + self.addpouVar(type, name, location=location, description=description) + setattr(cls, "addpouLocalVar", addpouLocalVar) + + def addpouExternalVar(self, type, name): + self.addpouVar(type, name, "externalVars") + setattr(cls, "addpouExternalVar", addpouExternalVar) + + def addpouVar(self, type, name, var_class="localVars", location="", description=""): if self.interface is None: self.interface = PLCOpenClasses["pou_interface"]() content = self.interface.getcontent() - if len(content) == 0 or content[-1]["name"] != "localVars": - content.append({"name" : "localVars", "value" : PLCOpenClasses["interface_localVars"]()}) + if len(content) == 0 or content[-1]["name"] != var_class: + content.append({"name" : var_class, "value" : PLCOpenClasses["interface_%s" % var_class]()}) else: varlist = content[-1]["value"] variables = varlist.getvariable() if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): - content.append({"name" : "localVars", "value" : PLCOpenClasses["interface_localVars"]()}) + content.append({"name" : var_class, "value" : PLCOpenClasses["interface_%s" % var_class]()}) var = PLCOpenClasses["varListPlain_variable"]() var.setname(name) var_type = PLCOpenClasses["dataType"]() diff -r 8baeb9dff775 -r 8a60ffcfd70b xmlclass/xmlclass.py --- a/xmlclass/xmlclass.py Sun Jan 08 18:23:55 2012 +0100 +++ b/xmlclass/xmlclass.py Sun Jan 08 19:16:58 2012 +0100 @@ -1408,7 +1408,6 @@ structure_model = re.compile("(%s)$" % structure_pattern) result = structure_model.match(children_structure) if not result: - print children_structure, structure_model.pattern raise ValueError("Invalid structure for \"%s\" children!." % tree.nodeName) required_attributes = dict([(attr["name"], True) for attr in classinfos["attributes"] if attr["use"] == "required"]) if classinfos.has_key("base"):