ProjectController.py
changeset 1789 492e2cd6157e
parent 1782 5b6ad7a7fd9d
child 1793 c2f48d791d9f
--- a/ProjectController.py	Tue Aug 22 14:15:49 2017 +0000
+++ b/ProjectController.py	Fri Aug 25 11:22:08 2017 +0300
@@ -131,10 +131,13 @@
 
     def findLibCPath(self):
         path = None
-        paths = [
-            os.path.join(self.ieclib_path, "C"),
-            self.ieclib_path]
-        path = self.findObject(paths, lambda p: os.path.isfile(os.path.join(p, "iec_types.h")))
+        if self.ieclib_path is not None:
+            paths = [
+                os.path.join(self.ieclib_path, "C"),
+                self.ieclib_path]
+            path = self.findObject(
+                paths,
+                lambda p: os.path.isfile(os.path.join(p, "iec_types.h")))
         return path
 
     def findSupportedOptions(self):
@@ -174,9 +177,6 @@
         return self.ieclib_c_path
 
 
-iec2c_cfg = Iec2CSettings()
-
-
 class ProjectController(ConfigTreeNode, PLCControler):
     """
     This class define Root object of the confnode tree.
@@ -220,10 +220,14 @@
     </xsd:schema>
     """
     EditorType = ProjectNodeEditor
+    iec2c_cfg = None
 
     def __init__(self, frame, logger):
         PLCControler.__init__(self)
 
+        if ProjectController.iec2c_cfg is None:
+            ProjectController.iec2c_cfg = Iec2CSettings()
+
         self.MandatoryParams = None
         self._builder = None
         self._connector = None
@@ -319,10 +323,10 @@
         return self
 
     def GetIECLibPath(self):
-        return iec2c_cfg.getLibCPath()
+        return self.iec2c_cfg.getLibCPath()
 
     def GetIEC2cPath(self):
-        return iec2c_cfg.getCmd()
+        return self.iec2c_cfg.getCmd()
 
     def GetCurrentLocation(self):
         return ()
@@ -742,12 +746,17 @@
         return True
 
     def _Compile_ST_to_SoftPLC(self):
+        iec2c_libpath = self.iec2c_cfg.getLibPath()
+        if iec2c_libpath is None:
+            self.logger.write_error(_("matiec installation is not found\n"))
+            return False
+
         self.logger.write(_("Compiling IEC Program into C code...\n"))
         buildpath = self._getBuildPath()
         buildcmd = "\"%s\" %s -I \"%s\" -T \"%s\" \"%s\"" % (
-                         iec2c_cfg.getCmd(),
-                         iec2c_cfg.getOptions(),
-                         iec2c_cfg.getLibPath(),
+                         self.iec2c_cfg.getCmd(),
+                         self.iec2c_cfg.getOptions(),
+                         iec2c_libpath,
                          buildpath,
                          self._getIECcodepath())
 
@@ -818,7 +827,7 @@
         # Keep track of generated C files for later use by self.CTNGenerate_C
         self.PLCGeneratedCFiles = C_files
         # compute CFLAGS for plc
-        self.plcCFLAGS = '"-I%s" -Wno-unused-function' % iec2c_cfg.getLibCPath()
+        self.plcCFLAGS = '"-I%s" -Wno-unused-function' % self.iec2c_cfg.getLibCPath()
         return True
 
     def GetBuilder(self):