ProjectController.py
changeset 1630 f0030c3cd6ab
parent 1606 99a02c6161b6
child 1634 299a1dde6baa
equal deleted inserted replaced
1629:80eee3c5a057 1630:f0030c3cd6ab
    81         menu_items.append((n, d, h, children))
    81         menu_items.append((n, d, h, children))
    82     return menu_items
    82     return menu_items
    83 
    83 
    84 def GetAddMenuItems():
    84 def GetAddMenuItems():
    85     return ExtractMenuItemsFromCatalog(features.catalog)
    85     return ExtractMenuItemsFromCatalog(features.catalog)
       
    86 
       
    87 class Iec2CSettings():
       
    88     def __init__(self):
       
    89         self.iec2c = os.path.join(base_folder, "matiec", "iec2c"+(".exe" if wx.Platform == '__WXMSW__' else ""))
       
    90         self.iec2c_buildopts = None
       
    91         self.ieclib_path   = os.path.join(base_folder, "matiec", "lib")
       
    92         self.ieclib_c_path = None
       
    93 
       
    94     def findLibCPath(self):
       
    95         path=""
       
    96         paths=[
       
    97             os.path.join(base_folder, "matiec", "lib", "C"),
       
    98             os.path.join(base_folder, "matiec", "lib") ]
       
    99         for p in paths:
       
   100             filename=os.path.join(p, "iec_types.h")
       
   101             if (os.path.isfile(filename)):
       
   102                 path = p
       
   103                 break
       
   104         return path
       
   105 
       
   106     def findSupportedOptions(self):
       
   107         buildcmd = "\"%s\" -h"%(self.iec2c)
       
   108         options =["-f", "-l", "-p"]
       
   109 
       
   110         buildopt = ""
       
   111         try:
       
   112             # Invoke compiler. Output files are listed to stdout, errors to stderr
       
   113             status, result, err_result = ProcessLogger(self.logger, buildcmd,
       
   114                 no_stdout=True, no_stderr=True).spin()
       
   115         except Exception,e:
       
   116             return buildopt
       
   117 
       
   118         for opt in options:
       
   119             if opt in result:
       
   120                 buildopt = buildopt + " " + opt
       
   121         return buildopt
       
   122 
       
   123     def getCmd(self):
       
   124         return self.iec2c
       
   125 
       
   126     def getOptions(self):
       
   127         if self.iec2c_buildopts is None:
       
   128             self.iec2c_buildopts = self.findSupportedOptions()
       
   129         return self.iec2c_buildopts
       
   130 
       
   131     def getLibPath(self):
       
   132         return self.ieclib_path
       
   133 
       
   134     def getLibCPath(self):
       
   135         if self.ieclib_c_path is None:
       
   136             self.ieclib_c_path = self.findLibCPath()
       
   137         return self.ieclib_c_path
       
   138 
       
   139 iec2c_cfg = Iec2CSettings()
    86 
   140 
    87 class ProjectController(ConfigTreeNode, PLCControler):
   141 class ProjectController(ConfigTreeNode, PLCControler):
    88     """
   142     """
    89     This class define Root object of the confnode tree.
   143     This class define Root object of the confnode tree.
    90     It is responsible of :
   144     It is responsible of :
   137         self.DispatchDebugValuesTimer = None
   191         self.DispatchDebugValuesTimer = None
   138         self.DebugValuesBuffers = []
   192         self.DebugValuesBuffers = []
   139         self.DebugTicks = []
   193         self.DebugTicks = []
   140         self.SetAppFrame(frame, logger)
   194         self.SetAppFrame(frame, logger)
   141 
   195 
   142         self.iec2c_path = os.path.join(base_folder, "matiec", "iec2c"+(".exe" if wx.Platform == '__WXMSW__' else ""))
       
   143         self.ieclib_path = os.path.join(base_folder, "matiec", "lib")
       
   144         self.ieclib_c_path = self._getMatIecCPath()
       
   145 
       
   146         # Setup debug information
   196         # Setup debug information
   147         self.IECdebug_datas = {}
   197         self.IECdebug_datas = {}
   148         self.IECdebug_lock = Lock()
   198         self.IECdebug_lock = Lock()
   149 
   199 
   150         self.DebugTimer=None
   200         self.DebugTimer=None
   226 
   276 
   227     def GetCTRoot(self):
   277     def GetCTRoot(self):
   228         return self
   278         return self
   229 
   279 
   230     def GetIECLibPath(self):
   280     def GetIECLibPath(self):
   231         return self.ieclib_c_path
   281         return iec2c_cfg.getLibCPath()
   232 
   282 
   233     def GetIEC2cPath(self):
   283     def GetIEC2cPath(self):
   234         return self.iec2c_path
   284         return iec2c_cfg.getCmd()
   235 
   285 
   236     def GetCurrentLocation(self):
   286     def GetCurrentLocation(self):
   237         return ()
   287         return ()
   238 
   288 
   239     def GetCurrentName(self):
   289     def GetCurrentName(self):
   636         plc_file.write(open(self._getIECgeneratedcodepath(), "r").read())
   686         plc_file.write(open(self._getIECgeneratedcodepath(), "r").read())
   637         plc_file.close()
   687         plc_file.close()
   638         return True
   688         return True
   639 
   689 
   640 
   690 
   641     def _getMatIecCPath(self):
       
   642         path=''
       
   643         paths=[
       
   644             os.path.join(base_folder, "matiec", "lib", "C"),
       
   645             os.path.join(base_folder, "matiec", "lib") ]
       
   646         for p in paths:
       
   647             filename=os.path.join(p, "iec_types.h")
       
   648             if (os.path.isfile(filename)):
       
   649                 path = p
       
   650                 break
       
   651         return path
       
   652 
       
   653     def _getMatIecOptions(self):
       
   654         buildpath = self._getBuildPath()
       
   655         buildcmd = "\"%s\" -h"%(self.iec2c_path)
       
   656         options =["-f", "-l", "-p"]
       
   657 
       
   658         buildopt = ""
       
   659         try:
       
   660             # Invoke compiler. Output files are listed to stdout, errors to stderr
       
   661             status, result, err_result = ProcessLogger(self.logger, buildcmd,
       
   662                 no_stdout=True, no_stderr=True).spin()
       
   663         except Exception,e:
       
   664             return buildopt
       
   665 
       
   666         for opt in options:
       
   667             if opt in result:
       
   668                 buildopt = buildopt + " " + opt
       
   669         return buildopt
       
   670 
   691 
   671     def _Compile_ST_to_SoftPLC(self):
   692     def _Compile_ST_to_SoftPLC(self):
   672         self.logger.write(_("Compiling IEC Program into C code...\n"))
   693         self.logger.write(_("Compiling IEC Program into C code...\n"))
   673         buildpath = self._getBuildPath()
   694         buildpath = self._getBuildPath()
   674         buildcmd = "\"%s\" %s -I \"%s\" -T \"%s\" \"%s\""%(
   695         buildcmd = "\"%s\" %s -I \"%s\" -T \"%s\" \"%s\""%(
   675                          self.iec2c_path,
   696                          iec2c_cfg.getCmd(),
   676                          self._getMatIecOptions(),
   697                          iec2c_cfg.getOptions(),
   677                          self.ieclib_path,
   698                          iec2c_cfg.getLibPath(),
   678                          buildpath,
   699                          buildpath,
   679                          self._getIECcodepath())
   700                          self._getIECcodepath())
   680 
   701 
   681         try:
   702         try:
   682             # Invoke compiler. Output files are listed to stdout, errors to stderr
   703             # Invoke compiler. Output files are listed to stdout, errors to stderr
   741         # Keep track of generated located variables for later use by self._Generate_C
   762         # Keep track of generated located variables for later use by self._Generate_C
   742         self.PLCGeneratedLocatedVars = self.GetLocations()
   763         self.PLCGeneratedLocatedVars = self.GetLocations()
   743         # Keep track of generated C files for later use by self.CTNGenerate_C
   764         # Keep track of generated C files for later use by self.CTNGenerate_C
   744         self.PLCGeneratedCFiles = C_files
   765         self.PLCGeneratedCFiles = C_files
   745         # compute CFLAGS for plc
   766         # compute CFLAGS for plc
   746         self.plcCFLAGS = '"-I%s" -Wno-unused-function'%self.ieclib_c_path
   767         self.plcCFLAGS = '"-I%s" -Wno-unused-function'%iec2c_cfg.getLibCPath()
   747         return True
   768         return True
   748 
   769 
   749     def GetBuilder(self):
   770     def GetBuilder(self):
   750         """
   771         """
   751         Return a Builder (compile C code into machine code)
   772         Return a Builder (compile C code into machine code)