21 #You should have received a copy of the GNU General Public |
21 #You should have received a copy of the GNU General Public |
22 #License along with this library; if not, write to the Free Software |
22 #License along with this library; if not, write to the Free Software |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
24 |
25 from xmlclass import * |
25 from xmlclass import * |
26 from structures import * |
|
27 from types import * |
26 from types import * |
28 import os, re |
27 import os, re |
29 from lxml import etree |
28 from lxml import etree |
30 """ |
29 """ |
31 Dictionary that makes the relation between var names in plcopen and displayed values |
30 Dictionary that makes the relation between var names in plcopen and displayed values |
294 setattr(cls, "getcontentHeader", getcontentHeader) |
293 setattr(cls, "getcontentHeader", getcontentHeader) |
295 |
294 |
296 def setcontentHeader(self, contentheader): |
295 def setcontentHeader(self, contentheader): |
297 contentheader_obj = self.contentHeader |
296 contentheader_obj = self.contentHeader |
298 for attr, value in contentheader.iteritems(): |
297 for attr, value in contentheader.iteritems(): |
299 if attr == "projectName": |
298 func = {"projectName": contentheader_obj.setname, |
300 contentheader_obj.setname(value) |
299 "projectVersion": contentheader_obj.setversion, |
301 elif attr == "projectVersion": |
300 "authorName": contentheader_obj.setauthor, |
302 contentheader_obj.setversion(value) |
301 "pageSize": lambda v: contentheader_obj.setpageSize(*v), |
303 elif attr == "authorName": |
302 "scaling": contentheader_obj.setscaling}.get(attr) |
304 contentheader_obj.setauthor(value) |
303 if func is not None: |
305 elif attr == "pageSize": |
304 func(value) |
306 contentheader_obj.setpageSize(*contentheader["pageSize"]) |
|
307 elif attr == "scaling": |
|
308 contentheader_obj.setscaling(contentheader["scaling"]) |
|
309 elif attr in ["modificationDateTime", "organization", "language"]: |
305 elif attr in ["modificationDateTime", "organization", "language"]: |
310 setattr(contentheader_obj, attr, value) |
306 setattr(contentheader_obj, attr, value) |
311 setattr(cls, "setcontentHeader", setcontentHeader) |
307 setattr(cls, "setcontentHeader", setcontentHeader) |
312 |
308 |
313 def gettypeElementFunc(element_type): |
309 def gettypeElementFunc(element_type): |
605 globalvars = self.getglobalVars() |
601 globalvars = self.getglobalVars() |
606 if len(globalvars) == 0: |
602 if len(globalvars) == 0: |
607 globalvars.append(PLCOpenParser.CreateElement("varList")) |
603 globalvars.append(PLCOpenParser.CreateElement("varList")) |
608 var = PLCOpenParser.CreateElement("variable", "varListPlain") |
604 var = PLCOpenParser.CreateElement("variable", "varListPlain") |
609 var.setname(name) |
605 var.setname(name) |
610 var_type_obj = PLCOpenParser.CreateElement("dataType") |
606 var.settype(var_type) |
611 if not var_type.startswith("ANY") and TypeHierarchy.get(var_type): |
|
612 var_type_obj.setcontent(PLCOpenParser.CreateElement( |
|
613 var_type.lower() if var_type in ["STRING", "WSTRING"] |
|
614 else vartype, "dataType")) |
|
615 else: |
|
616 derived_type = PLCOpenParser.CreateElement("derived", "dataType") |
|
617 derived_type.setname(var_type) |
|
618 var_type_obj.setcontent(derived_type) |
|
619 var.settype(var_type_obj) |
|
620 if location != "": |
607 if location != "": |
621 var.setaddress(location) |
608 var.setaddress(location) |
622 if description != "": |
609 if description != "": |
623 ft = PLCOpenParser.CreateElement("documentation", "variable") |
610 ft = PLCOpenParser.CreateElement("documentation", "variable") |
624 ft.setanyText(description) |
611 ft.setanyText(description) |
1162 if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
1149 if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
1163 varlist = PLCOpenParser.CreateElement(var_class, "interface") |
1150 varlist = PLCOpenParser.CreateElement(var_class, "interface") |
1164 content[-1].addnext(varlist) |
1151 content[-1].addnext(varlist) |
1165 var = PLCOpenParser.CreateElement("variable", "varListPlain") |
1152 var = PLCOpenParser.CreateElement("variable", "varListPlain") |
1166 var.setname(name) |
1153 var.setname(name) |
1167 var_type_obj = PLCOpenParser.CreateElement("type", "variable") |
1154 var.settype(var_type) |
1168 if not var_type.startswith("ANY") and TypeHierarchy.get(var_type): |
|
1169 var_type_obj.setcontent(PLCOpenParser.CreateElement( |
|
1170 var_type.lower() if var_type in ["STRING", "WSTRING"] |
|
1171 else var_type, "dataType")) |
|
1172 else: |
|
1173 derived_type = PLCOpenParser.CreateElement("derived", "dataType") |
|
1174 derived_type.setname(var_type) |
|
1175 var_type_obj.setcontent(derived_type) |
|
1176 var.settype(var_type_obj) |
|
1177 if location != "": |
1155 if location != "": |
1178 var.setaddress(location) |
1156 var.setaddress(location) |
1179 if description != "": |
1157 if description != "": |
1180 ft = PLCOpenParser.CreateElement("documentation", "variable") |
1158 ft = PLCOpenParser.CreateElement("documentation", "variable") |
1181 ft.setanyText(description) |
1159 ft.setanyText(description) |