113 |
113 |
114 def PluginXmlFilePath(self, PlugName=None): |
114 def PluginXmlFilePath(self, PlugName=None): |
115 return os.path.join(self.PlugPath(PlugName), "plugin.xml") |
115 return os.path.join(self.PlugPath(PlugName), "plugin.xml") |
116 |
116 |
117 def PluginLibraryFilePath(self): |
117 def PluginLibraryFilePath(self): |
118 return os.path.join(os.path.join(os.path.split(__file__)[0], "plugins", self.PlugType, "pous.xml")) |
118 return os.path.join(self.PluginPath(), "pous.xml") |
|
119 |
|
120 def PluginPath(self): |
|
121 return os.path.join(self.PlugParent.PluginPath(), self.PlugType) |
119 |
122 |
120 def PlugPath(self,PlugName=None): |
123 def PlugPath(self,PlugName=None): |
121 if not PlugName: |
124 if not PlugName: |
122 PlugName = self.BaseParams.getName() |
125 PlugName = self.BaseParams.getName() |
123 return os.path.join(self.PlugParent.PlugPath(), |
126 return os.path.join(self.PlugParent.PlugPath(), |
273 def BlockTypesFactory(self): |
276 def BlockTypesFactory(self): |
274 if self.LibraryControler is not None: |
277 if self.LibraryControler is not None: |
275 return [{"name" : "%s POUs" % self.PlugType, "list": self.LibraryControler.Project.GetCustomBlockTypes()}] |
278 return [{"name" : "%s POUs" % self.PlugType, "list": self.LibraryControler.Project.GetCustomBlockTypes()}] |
276 return [] |
279 return [] |
277 |
280 |
|
281 def ParentsBlockTypesFactory(self): |
|
282 return self.PlugParent.ParentsBlockTypesFactory() + self.BlockTypesFactory() |
|
283 |
|
284 def PluginsBlockTypesFactory(self): |
|
285 list = self.BlockTypesFactory() |
|
286 for PlugChild in self.IterChilds(): |
|
287 list += PlugChild.PluginsBlockTypesFactory() |
|
288 return list |
|
289 |
278 def STLibraryFactory(self): |
290 def STLibraryFactory(self): |
279 if self.LibraryControler is not None: |
291 if self.LibraryControler is not None: |
280 program, errors, warnings = self.LibraryControler.GenerateProgram() |
292 program, errors, warnings = self.LibraryControler.GenerateProgram() |
281 return program |
293 return program + "\n" |
282 return "" |
294 return "" |
283 |
295 |
|
296 def PluginsSTLibraryFactory(self): |
|
297 program = self.STLibraryFactory() |
|
298 for PlugChild in self.IECSortedChilds(): |
|
299 program += PlugChild.PluginsSTLibraryFactory() |
|
300 return program |
|
301 |
284 def IterChilds(self): |
302 def IterChilds(self): |
285 for PlugType, PluggedChilds in self.PluggedChilds.items(): |
303 for PlugType, PluggedChilds in self.PluggedChilds.items(): |
286 for PlugInstance in PluggedChilds: |
304 for PlugInstance in PluggedChilds: |
287 yield PlugInstance |
305 yield PlugInstance |
288 |
306 |
539 # Get library blocks if plcopen library exist |
557 # Get library blocks if plcopen library exist |
540 library_path = self.PluginLibraryFilePath() |
558 library_path = self.PluginLibraryFilePath() |
541 if os.path.isfile(library_path): |
559 if os.path.isfile(library_path): |
542 self.LibraryControler = PLCControler() |
560 self.LibraryControler = PLCControler() |
543 self.LibraryControler.OpenXMLFile(library_path) |
561 self.LibraryControler.OpenXMLFile(library_path) |
|
562 self.LibraryControler.ClearPluginTypes() |
|
563 self.LibraryControler.AddPluginBlockList(self.ParentsBlockTypesFactory()) |
544 |
564 |
545 def LoadXMLParams(self, PlugName = None): |
565 def LoadXMLParams(self, PlugName = None): |
546 methode_name = os.path.join(self.PlugPath(PlugName), "methods.py") |
566 methode_name = os.path.join(self.PlugPath(PlugName), "methods.py") |
547 if os.path.isfile(methode_name): |
567 if os.path.isfile(methode_name): |
548 execfile(methode_name) |
568 execfile(methode_name) |
852 |
872 |
853 # Update PLCOpenEditor Plugin Block types from loaded plugins |
873 # Update PLCOpenEditor Plugin Block types from loaded plugins |
854 def RefreshPluginsBlockLists(self): |
874 def RefreshPluginsBlockLists(self): |
855 if getattr(self, "PluggedChilds", None) is not None: |
875 if getattr(self, "PluggedChilds", None) is not None: |
856 self.ClearPluginTypes() |
876 self.ClearPluginTypes() |
857 self.AddPluginBlockList(self.BlockTypesFactory()) |
877 self.AddPluginBlockList(self.PluginsBlockTypesFactory()) |
858 for child in self.IterChilds(): |
|
859 self.AddPluginBlockList(child.BlockTypesFactory()) |
|
860 if self.PLCEditor is not None: |
878 if self.PLCEditor is not None: |
861 self.PLCEditor.RefreshEditor() |
879 self.PLCEditor.RefreshEditor() |
862 |
880 |
|
881 def PluginPath(self): |
|
882 return os.path.join(os.path.split(__file__)[0], "plugins") |
|
883 |
863 def PlugPath(self, PlugName=None): |
884 def PlugPath(self, PlugName=None): |
864 return self.ProjectPath |
885 return self.ProjectPath |
865 |
886 |
866 def PluginXmlFilePath(self, PlugName=None): |
887 def PluginXmlFilePath(self, PlugName=None): |
867 return os.path.join(self.PlugPath(PlugName), "beremiz.xml") |
888 return os.path.join(self.PlugPath(PlugName), "beremiz.xml") |
|
889 |
|
890 def ParentsBlockTypesFactory(self): |
|
891 return self.BlockTypesFactory() |
868 |
892 |
869 def _getBuildPath(self): |
893 def _getBuildPath(self): |
870 if self.BuildPath is None: |
894 if self.BuildPath is None: |
871 return os.path.join(self.ProjectPath, "build") |
895 return os.path.join(self.ProjectPath, "build") |
872 return self.BuildPath |
896 return self.BuildPath |
939 if len(errors) > 0: |
963 if len(errors) > 0: |
940 # Failed ! |
964 # Failed ! |
941 self.logger.write_error(_("Error in ST/IL/SFC code generator :\n%s\n")%errors[0]) |
965 self.logger.write_error(_("Error in ST/IL/SFC code generator :\n%s\n")%errors[0]) |
942 return False |
966 return False |
943 plc_file = open(self._getIECcodepath(), "w") |
967 plc_file = open(self._getIECcodepath(), "w") |
944 if getattr(self, "PluggedChilds", None) is not None: |
968 # Add ST Library from plugins |
945 # Add ST Library from plugins |
969 plc_file.write(self.PluginsSTLibraryFactory()) |
946 plc_file.write(self.STLibraryFactory()) |
|
947 plc_file.write("\n") |
|
948 for child in self.IterChilds(): |
|
949 plc_file.write(child.STLibraryFactory()) |
|
950 plc_file.write("\n") |
|
951 if os.path.isfile(self._getIECrawcodepath()): |
970 if os.path.isfile(self._getIECrawcodepath()): |
952 plc_file.write(open(self._getIECrawcodepath(), "r").read()) |
971 plc_file.write(open(self._getIECrawcodepath(), "r").read()) |
953 plc_file.write("\n") |
972 plc_file.write("\n") |
954 plc_file.close() |
973 plc_file.close() |
955 plc_file = open(self._getIECcodepath(), "r") |
974 plc_file = open(self._getIECcodepath(), "r") |