# HG changeset patch # User greg # Date 1228927041 -3600 # Node ID 8628f3dd0979e2d2837ab18ac534100e9223de02 # Parent d15a20eb2b8b3683b9c209b35620bd69628a75a8 Adding support for defining plugin library as a plcopen xml file in plugin folder diff -r d15a20eb2b8b -r 8628f3dd0979 plugger.py --- a/plugger.py Wed Nov 26 09:05:04 2008 +0100 +++ b/plugger.py Wed Dec 10 17:37:21 2008 +0100 @@ -18,6 +18,8 @@ from xmlclass import GenerateClassesFromXSDstring from wxPopen import ProcessLogger +from PLCControler import PLCControler + _BaseParamsClass = GenerateClassesFromXSDstring(""" @@ -83,6 +85,7 @@ PlugChildsTypes = [] PlugMaxCount = None PluginMethods = [] + LibraryControler = None def _AddParamsMembers(self): self.PlugParams = None @@ -110,6 +113,9 @@ def PluginXmlFilePath(self, PlugName=None): return os.path.join(self.PlugPath(PlugName), "plugin.xml") + def PluginLibraryFilePath(self, PlugName=None): + return os.path.join(os.path.join(os.path.split(__file__)[0], "plugins", self.PlugType, "pous.xml")) + def PlugPath(self,PlugName=None): if not PlugName: PlugName = self.BaseParams.getName() @@ -264,9 +270,13 @@ return LocationCFilesAndCFLAGS, LDFLAGS, extra_files def BlockTypesFactory(self): + if self.LibraryControler is not None: + return [{"name" : "%s POUs" % self.PlugType, "list": self.LibraryControler.Project.GetCustomBlockTypes()}] return [] def STLibraryFactory(self): + if self.LibraryControler is not None: + return self.LibraryControler.GenerateProgram() return "" def IterChilds(self): @@ -528,7 +538,13 @@ methode_name = os.path.join(self.PlugPath(PlugName), "methods.py") if os.path.isfile(methode_name): execfile(methode_name) - + + # Get library blocks if plcopen library exist + library_path = self.PluginLibraryFilePath(PlugName) + if os.path.isfile(library_path): + self.LibraryControler = PLCControler() + self.LibraryControler.OpenXMLFile(library_path) + # Get the base xml tree if self.MandatoryParams: try: @@ -604,7 +620,6 @@ from time import localtime from datetime import datetime # import necessary stuff from PLCOpenEditor -from PLCControler import PLCControler from PLCOpenEditor import PLCOpenEditor, ProjectDialog from TextViewer import TextViewer from plcopen.structures import IEC_KEYWORDS, TypeHierarchy_list @@ -688,6 +703,9 @@ # copy PluginMethods so that it can be later customized self.PluginMethods = [dic.copy() for dic in self.PluginMethods] + def PluginLibraryFilePath(self, PlugName=None): + return os.path.join(os.path.join(os.path.split(__file__)[0], "pous.xml")) + def PlugTestModified(self): return self.ChangesToSave or not self.ProjectIsSaved() @@ -875,6 +893,13 @@ self.logger.write_error("Error in ST/IL/SFC code generator :\n%s\n"%result) return False plc_file = open(self._getIECcodepath(), "w") + if getattr(self, "PluggedChilds", None) is not None: + # Add ST Library from plugins + plc_file.write(self.STLibraryFactory()) + plc_file.write("\n") + for child in self.IterChilds(): + plc_file.write(child.STLibraryFactory()) + plc_file.write("\n") if os.path.isfile(self._getIECrawcodepath()): plc_file.write(open(self._getIECrawcodepath(), "r").read()) plc_file.write("\n")