36 if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "Python": |
36 if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "Python": |
37 self.PythonCode.loadXMLTree(child, ["xmlns", "xmlns:xsi", "xsi:schemaLocation"]) |
37 self.PythonCode.loadXMLTree(child, ["xmlns", "xmlns:xsi", "xsi:schemaLocation"]) |
38 self.CreatePythonBuffer(True) |
38 self.CreatePythonBuffer(True) |
39 else: |
39 else: |
40 self.CreatePythonBuffer(False) |
40 self.CreatePythonBuffer(False) |
41 self.OnPlugSave() |
41 self.OnCTNSave() |
42 |
42 |
43 def ConfNodePath(self): |
43 def ConfNodePath(self): |
44 return os.path.join(self.PlugParent.ConfNodePath(), "modules", self.PlugType) |
44 return os.path.join(self.CTNParent.ConfNodePath(), "modules", self.CTNType) |
45 |
45 |
46 def PythonFileName(self): |
46 def PythonFileName(self): |
47 return os.path.join(self.PlugPath(), "python.xml") |
47 return os.path.join(self.CTNPath(), "python.xml") |
48 |
48 |
49 def GetFilename(self): |
49 def GetFilename(self): |
50 if self.PythonBuffer.IsCurrentSaved(): |
50 if self.PythonBuffer.IsCurrentSaved(): |
51 return "python" |
51 return "python" |
52 else: |
52 else: |
56 self.PythonCode.settext(text) |
56 self.PythonCode.settext(text) |
57 |
57 |
58 def GetPythonCode(self): |
58 def GetPythonCode(self): |
59 return self.PythonCode.gettext() |
59 return self.PythonCode.gettext() |
60 |
60 |
61 def PlugTestModified(self): |
61 def CTNTestModified(self): |
62 return self.ChangesToSave or not self.PythonIsSaved() |
62 return self.ChangesToSave or not self.PythonIsSaved() |
63 |
63 |
64 def OnPlugSave(self): |
64 def OnCTNSave(self): |
65 filepath = self.PythonFileName() |
65 filepath = self.PythonFileName() |
66 |
66 |
67 text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" |
67 text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" |
68 extras = {"xmlns":"http://www.w3.org/2001/XMLSchema", |
68 extras = {"xmlns":"http://www.w3.org/2001/XMLSchema", |
69 "xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance", |
69 "xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance", |
127 return getattr(modules, name).RootClass |
127 return getattr(modules, name).RootClass |
128 return GetRootClass |
128 return GetRootClass |
129 |
129 |
130 class RootClass(PythonCodeTemplate): |
130 class RootClass(PythonCodeTemplate): |
131 |
131 |
132 # For root object, available Childs Types are modules of the modules packages. |
132 # For root object, available Children Types are modules of the modules packages. |
133 PlugChildsTypes = [(name, _GetClassFunction(name), help) for name, help in zip(modules.__all__,modules.helps)] |
133 CTNChildrenTypes = [(name, _GetClassFunction(name), help) for name, help in zip(modules.__all__,modules.helps)] |
134 |
134 |
135 def ConfNodePath(self): |
135 def ConfNodePath(self): |
136 return os.path.join(self.PlugParent.ConfNodePath(), self.PlugType) |
136 return os.path.join(self.CTNParent.ConfNodePath(), self.CTNType) |
137 |
137 |
138 def PlugGenerate_C(self, buildpath, locations): |
138 def CTNGenerate_C(self, buildpath, locations): |
139 """ |
139 """ |
140 Generate C code |
140 Generate C code |
141 @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
141 @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
142 @param locations: List of complete variables locations \ |
142 @param locations: List of complete variables locations \ |
143 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
143 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
150 """ |
150 """ |
151 current_location = self.GetCurrentLocation() |
151 current_location = self.GetCurrentLocation() |
152 # define a unique name for the generated C file |
152 # define a unique name for the generated C file |
153 location_str = "_".join(map(lambda x:str(x), current_location)) |
153 location_str = "_".join(map(lambda x:str(x), current_location)) |
154 |
154 |
155 ctr = self.GetPlugRoot() |
155 ctr = self.GetCTRoot() |
156 ctr.GetIECProgramsAndVariables() |
156 ctr.GetIECProgramsAndVariables() |
157 |
157 |
158 plc_python_filepath = os.path.join(os.path.split(__file__)[0], "plc_python.c") |
158 plc_python_filepath = os.path.join(os.path.split(__file__)[0], "plc_python.c") |
159 plc_python_file = open(plc_python_filepath, 'r') |
159 plc_python_file = open(plc_python_filepath, 'r') |
160 plc_python_code = plc_python_file.read() |
160 plc_python_code = plc_python_file.read() |
178 runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) |
178 runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) |
179 runtimefile = open(runtimefile_path, 'w') |
179 runtimefile = open(runtimefile_path, 'w') |
180 runtimefile.write(self.GetPythonCode()) |
180 runtimefile.write(self.GetPythonCode()) |
181 runtimefile.close() |
181 runtimefile.close() |
182 |
182 |
183 matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()) |
183 matiec_flags = '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()) |
184 |
184 |
185 return [(Gen_Pythonfile_path, matiec_flags)], "", True, ("runtime_%s.py"%location_str, file(runtimefile_path,"rb")) |
185 return [(Gen_Pythonfile_path, matiec_flags)], "", True, ("runtime_%s.py"%location_str, file(runtimefile_path,"rb")) |