41 if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "CFile": |
41 if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "CFile": |
42 self.CFile.loadXMLTree(child, ["xmlns", "xmlns:xsi", "xsi:schemaLocation"]) |
42 self.CFile.loadXMLTree(child, ["xmlns", "xmlns:xsi", "xsi:schemaLocation"]) |
43 self.CreateCFileBuffer(True) |
43 self.CreateCFileBuffer(True) |
44 else: |
44 else: |
45 self.CreateCFileBuffer(False) |
45 self.CreateCFileBuffer(False) |
46 self.OnPlugSave() |
46 self.OnCTNSave() |
47 |
47 |
48 def CFileName(self): |
48 def CFileName(self): |
49 return os.path.join(self.PlugPath(), "cfile.xml") |
49 return os.path.join(self.CTNPath(), "cfile.xml") |
50 |
50 |
51 def GetBaseTypes(self): |
51 def GetBaseTypes(self): |
52 return self.GetPlugRoot().GetBaseTypes() |
52 return self.GetCTRoot().GetBaseTypes() |
53 |
53 |
54 def GetDataTypes(self, basetypes = False, only_locatables = False): |
54 def GetDataTypes(self, basetypes = False, only_locatables = False): |
55 return self.GetPlugRoot().GetDataTypes(basetypes=basetypes, only_locatables=only_locatables) |
55 return self.GetCTRoot().GetDataTypes(basetypes=basetypes, only_locatables=only_locatables) |
56 |
56 |
57 def GetSizeOfType(self, type): |
57 def GetSizeOfType(self, type): |
58 return TYPECONVERSION.get(self.GetPlugRoot().GetBaseType(type), None) |
58 return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None) |
59 |
59 |
60 def SetVariables(self, variables): |
60 def SetVariables(self, variables): |
61 self.CFile.variables.setvariable([]) |
61 self.CFile.variables.setvariable([]) |
62 for var in variables: |
62 for var in variables: |
63 variable = CFileClasses["variables_variable"]() |
63 variable = CFileClasses["variables_variable"]() |
145 "name" : _("Edit C File"), |
145 "name" : _("Edit C File"), |
146 "tooltip" : _("Edit C File"), |
146 "tooltip" : _("Edit C File"), |
147 "method" : "_OpenView"}, |
147 "method" : "_OpenView"}, |
148 ] |
148 ] |
149 |
149 |
150 def PlugTestModified(self): |
150 def CTNTestModified(self): |
151 return self.ChangesToSave or not self.CFileIsSaved() |
151 return self.ChangesToSave or not self.CFileIsSaved() |
152 |
152 |
153 def OnPlugSave(self): |
153 def OnCTNSave(self): |
154 filepath = self.CFileName() |
154 filepath = self.CFileName() |
155 |
155 |
156 text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" |
156 text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" |
157 extras = {"xmlns":"http://www.w3.org/2001/XMLSchema", |
157 extras = {"xmlns":"http://www.w3.org/2001/XMLSchema", |
158 "xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance", |
158 "xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance", |
164 xmlfile.close() |
164 xmlfile.close() |
165 |
165 |
166 self.MarkCFileAsSaved() |
166 self.MarkCFileAsSaved() |
167 return True |
167 return True |
168 |
168 |
169 def PlugGenerate_C(self, buildpath, locations): |
169 def CTNGenerate_C(self, buildpath, locations): |
170 """ |
170 """ |
171 Generate C code |
171 Generate C code |
172 @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
172 @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
173 @param locations: List of complete variables locations \ |
173 @param locations: List of complete variables locations \ |
174 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
174 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
213 else: |
213 else: |
214 var["location"] = "__Q%s%s_%d"%(self.GetSizeOfType(var["Type"]), location_str, outputs) |
214 var["location"] = "__Q%s%s_%d"%(self.GetSizeOfType(var["Type"]), location_str, outputs) |
215 outputs += 1 |
215 outputs += 1 |
216 vars.append(var) |
216 vars.append(var) |
217 text += "/* Beremiz c_ext confnode user variables definition */\n" |
217 text += "/* Beremiz c_ext confnode user variables definition */\n" |
218 base_types = self.GetPlugRoot().GetBaseTypes() |
218 base_types = self.GetCTRoot().GetBaseTypes() |
219 for var in vars: |
219 for var in vars: |
220 if var["Type"] in base_types: |
220 if var["Type"] in base_types: |
221 prefix = "IEC_" |
221 prefix = "IEC_" |
222 else: |
222 else: |
223 prefix = "" |
223 prefix = "" |
254 Gen_Cfile_path = os.path.join(buildpath, "CFile_%s.c"%location_str) |
254 Gen_Cfile_path = os.path.join(buildpath, "CFile_%s.c"%location_str) |
255 cfile = open(Gen_Cfile_path,'w') |
255 cfile = open(Gen_Cfile_path,'w') |
256 cfile.write(text) |
256 cfile.write(text) |
257 cfile.close() |
257 cfile.close() |
258 |
258 |
259 matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()) |
259 matiec_flags = '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()) |
260 |
260 |
261 return [(Gen_Cfile_path, str(self.CExtension.getCFLAGS() + matiec_flags))],str(self.CExtension.getLDFLAGS()),True |
261 return [(Gen_Cfile_path, str(self.CExtension.getCFLAGS() + matiec_flags))],str(self.CExtension.getLDFLAGS()),True |
262 |
262 |
263 |
263 |
264 #------------------------------------------------------------------------------- |
264 #------------------------------------------------------------------------------- |
305 last = self.CFileBuffer.IsLast() |
305 last = self.CFileBuffer.IsLast() |
306 return not first, not last |
306 return not first, not last |
307 |
307 |
308 class RootClass: |
308 class RootClass: |
309 |
309 |
310 PlugChildsTypes = [("C_File",_Cfile, "C file")] |
310 CTNChildrenTypes = [("C_File",_Cfile, "C file")] |
311 |
311 |
312 def PlugGenerate_C(self, buildpath, locations): |
312 def CTNGenerate_C(self, buildpath, locations): |
313 return [],"",False |
313 return [],"",False |
314 |
314 |
315 |
315 |