plugger.py
changeset 274 8628f3dd0979
parent 273 d15a20eb2b8b
child 275 ff7c8eb3f362
equal deleted inserted replaced
273:d15a20eb2b8b 274:8628f3dd0979
    15 sys.path.append(os.path.join(base_folder, "docutils"))
    15 sys.path.append(os.path.join(base_folder, "docutils"))
    16 
    16 
    17 from docpdf import *
    17 from docpdf import *
    18 from xmlclass import GenerateClassesFromXSDstring
    18 from xmlclass import GenerateClassesFromXSDstring
    19 from wxPopen import ProcessLogger
    19 from wxPopen import ProcessLogger
       
    20 
       
    21 from PLCControler import PLCControler
    20 
    22 
    21 _BaseParamsClass = GenerateClassesFromXSDstring("""<?xml version="1.0" encoding="ISO-8859-1" ?>
    23 _BaseParamsClass = GenerateClassesFromXSDstring("""<?xml version="1.0" encoding="ISO-8859-1" ?>
    22         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    24         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    23           <xsd:element name="BaseParams">
    25           <xsd:element name="BaseParams">
    24             <xsd:complexType>
    26             <xsd:complexType>
    81 
    83 
    82     XSD = None
    84     XSD = None
    83     PlugChildsTypes = []
    85     PlugChildsTypes = []
    84     PlugMaxCount = None
    86     PlugMaxCount = None
    85     PluginMethods = []
    87     PluginMethods = []
       
    88     LibraryControler = None
    86 
    89 
    87     def _AddParamsMembers(self):
    90     def _AddParamsMembers(self):
    88         self.PlugParams = None
    91         self.PlugParams = None
    89         if self.XSD:
    92         if self.XSD:
    90             Classes = GenerateClassesFromXSDstring(self.XSD)
    93             Classes = GenerateClassesFromXSDstring(self.XSD)
   107     def PluginBaseXmlFilePath(self, PlugName=None):
   110     def PluginBaseXmlFilePath(self, PlugName=None):
   108         return os.path.join(self.PlugPath(PlugName), "baseplugin.xml")
   111         return os.path.join(self.PlugPath(PlugName), "baseplugin.xml")
   109     
   112     
   110     def PluginXmlFilePath(self, PlugName=None):
   113     def PluginXmlFilePath(self, PlugName=None):
   111         return os.path.join(self.PlugPath(PlugName), "plugin.xml")
   114         return os.path.join(self.PlugPath(PlugName), "plugin.xml")
       
   115 
       
   116     def PluginLibraryFilePath(self, PlugName=None):
       
   117         return os.path.join(os.path.join(os.path.split(__file__)[0], "plugins", self.PlugType, "pous.xml"))
   112 
   118 
   113     def PlugPath(self,PlugName=None):
   119     def PlugPath(self,PlugName=None):
   114         if not PlugName:
   120         if not PlugName:
   115             PlugName = self.BaseParams.getName()
   121             PlugName = self.BaseParams.getName()
   116         return os.path.join(self.PlugParent.PlugPath(),
   122         return os.path.join(self.PlugParent.PlugPath(),
   262             extra_files += _extra_files
   268             extra_files += _extra_files
   263         
   269         
   264         return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
   270         return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
   265 
   271 
   266     def BlockTypesFactory(self):
   272     def BlockTypesFactory(self):
       
   273         if self.LibraryControler is not None:
       
   274             return [{"name" : "%s POUs" % self.PlugType, "list": self.LibraryControler.Project.GetCustomBlockTypes()}]
   267         return []
   275         return []
   268 
   276 
   269     def STLibraryFactory(self):
   277     def STLibraryFactory(self):
       
   278         if self.LibraryControler is not None:
       
   279             return self.LibraryControler.GenerateProgram()
   270         return ""
   280         return ""
   271 
   281 
   272     def IterChilds(self):
   282     def IterChilds(self):
   273         for PlugType, PluggedChilds in self.PluggedChilds.items():
   283         for PlugType, PluggedChilds in self.PluggedChilds.items():
   274             for PlugInstance in PluggedChilds:
   284             for PlugInstance in PluggedChilds:
   526 
   536 
   527     def LoadXMLParams(self, PlugName = None):
   537     def LoadXMLParams(self, PlugName = None):
   528         methode_name = os.path.join(self.PlugPath(PlugName), "methods.py")
   538         methode_name = os.path.join(self.PlugPath(PlugName), "methods.py")
   529         if os.path.isfile(methode_name):
   539         if os.path.isfile(methode_name):
   530             execfile(methode_name)
   540             execfile(methode_name)
   531 
   541         
       
   542         # Get library blocks if plcopen library exist
       
   543         library_path = self.PluginLibraryFilePath(PlugName)
       
   544         if os.path.isfile(library_path):
       
   545             self.LibraryControler = PLCControler()
       
   546             self.LibraryControler.OpenXMLFile(library_path)
       
   547         
   532         # Get the base xml tree
   548         # Get the base xml tree
   533         if self.MandatoryParams:
   549         if self.MandatoryParams:
   534             try:
   550             try:
   535                 basexmlfile = open(self.PluginBaseXmlFilePath(PlugName), 'r')
   551                 basexmlfile = open(self.PluginBaseXmlFilePath(PlugName), 'r')
   536                 basetree = minidom.parse(basexmlfile)
   552                 basetree = minidom.parse(basexmlfile)
   602 # import for project creation timestamping
   618 # import for project creation timestamping
   603 from threading import Timer, Lock, Thread, Semaphore
   619 from threading import Timer, Lock, Thread, Semaphore
   604 from time import localtime
   620 from time import localtime
   605 from datetime import datetime
   621 from datetime import datetime
   606 # import necessary stuff from PLCOpenEditor
   622 # import necessary stuff from PLCOpenEditor
   607 from PLCControler import PLCControler
       
   608 from PLCOpenEditor import PLCOpenEditor, ProjectDialog
   623 from PLCOpenEditor import PLCOpenEditor, ProjectDialog
   609 from TextViewer import TextViewer
   624 from TextViewer import TextViewer
   610 from plcopen.structures import IEC_KEYWORDS, TypeHierarchy_list
   625 from plcopen.structures import IEC_KEYWORDS, TypeHierarchy_list
   611 
   626 
   612 # Construct debugger natively supported types
   627 # Construct debugger natively supported types
   685         self.BuildPath = None
   700         self.BuildPath = None
   686         self.PLCEditor = None
   701         self.PLCEditor = None
   687         self.PLCDebug = None
   702         self.PLCDebug = None
   688         # copy PluginMethods so that it can be later customized
   703         # copy PluginMethods so that it can be later customized
   689         self.PluginMethods = [dic.copy() for dic in self.PluginMethods]
   704         self.PluginMethods = [dic.copy() for dic in self.PluginMethods]
       
   705 
       
   706     def PluginLibraryFilePath(self, PlugName=None):
       
   707         return os.path.join(os.path.join(os.path.split(__file__)[0], "pous.xml"))
   690 
   708 
   691     def PlugTestModified(self):
   709     def PlugTestModified(self):
   692          return self.ChangesToSave or not self.ProjectIsSaved()
   710          return self.ChangesToSave or not self.ProjectIsSaved()
   693 
   711 
   694     def GetPlugRoot(self):
   712     def GetPlugRoot(self):
   873         if result is not None:
   891         if result is not None:
   874             # Failed !
   892             # Failed !
   875             self.logger.write_error("Error in ST/IL/SFC code generator :\n%s\n"%result)
   893             self.logger.write_error("Error in ST/IL/SFC code generator :\n%s\n"%result)
   876             return False
   894             return False
   877         plc_file = open(self._getIECcodepath(), "w")
   895         plc_file = open(self._getIECcodepath(), "w")
       
   896         if getattr(self, "PluggedChilds", None) is not None:
       
   897             # Add ST Library from plugins
       
   898             plc_file.write(self.STLibraryFactory())
       
   899             plc_file.write("\n")
       
   900             for child in self.IterChilds():
       
   901                 plc_file.write(child.STLibraryFactory())
       
   902                 plc_file.write("\n")
   878         if os.path.isfile(self._getIECrawcodepath()):
   903         if os.path.isfile(self._getIECrawcodepath()):
   879             plc_file.write(open(self._getIECrawcodepath(), "r").read())
   904             plc_file.write(open(self._getIECrawcodepath(), "r").read())
   880             plc_file.write("\n")
   905             plc_file.write("\n")
   881         plc_file.write(open(self._getIECgeneratedcodepath(), "r").read())
   906         plc_file.write(open(self._getIECgeneratedcodepath(), "r").read())
   882         plc_file.close()
   907         plc_file.close()