]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Loading fortran and msvc libraries for Sysdyn (needed by OpenModelica), also in game...
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 16 May 2014 10:51:17 +0000 (10:51 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 16 May 2014 10:51:17 +0000 (10:51 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29502 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.fmu.me.win32/libraries/FMUSimulator.dll
org.simantics.fmu.me.win32/libraries/miniunz.dll
org.simantics.fmu.me.win32/libraries/zlibwapi.dll
org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java
org.simantics.sysdyn.feature/rootfiles/msvcr100.dll [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java

index cee79fe9085caaca854c13a4d439ccdb40ea3961..6db0c3f5c9d68da6989b8685de6f44283d03291f 100644 (file)
Binary files a/org.simantics.fmu.me.win32/libraries/FMUSimulator.dll and b/org.simantics.fmu.me.win32/libraries/FMUSimulator.dll differ
index a218a76bddac44614729d394af7a0b4cae489b74..312a60bb2c90b14fcde201917b321489b3e74c95 100644 (file)
Binary files a/org.simantics.fmu.me.win32/libraries/miniunz.dll and b/org.simantics.fmu.me.win32/libraries/miniunz.dll differ
index bd6d8276ee0bba214bfe79a4476c9835340b091d..fa494119f916f6dbbf3a2e06b84f3639bb7726b1 100644 (file)
Binary files a/org.simantics.fmu.me.win32/libraries/zlibwapi.dll and b/org.simantics.fmu.me.win32/libraries/zlibwapi.dll differ
index 7908c7f93cf55d6e6a58048c9b78d65c436de913..ae40d665e7a25ca922a3148b16d87047cc40e8ab 100644 (file)
@@ -127,10 +127,15 @@ public class ModelicaManager {
                \r
                File mbin = new File(mingw, "bin");\r
                File mlib = new File(mingw, "lib");\r
-               env.put("PATH", env.get("PATH") + File.pathSeparator + bin.getAbsolutePath()\r
-                                                       + File.pathSeparator + mbin.getAbsolutePath()\r
-                                                       + File.pathSeparator + mlib.getAbsolutePath());\r
-               \r
+               String path_allcaps = env.get("PATH") == null ? "" : env.get("PATH") + File.pathSeparator;\r
+               env.put("PATH", path_allcaps + bin.getAbsolutePath()\r
+                                + File.pathSeparator + mbin.getAbsolutePath()\r
+                    + File.pathSeparator + mlib.getAbsolutePath());\r
+               String path = env.get("Path") == null ? "" : env.get("Path") + File.pathSeparator;\r
+               env.put("Path", path + bin.getAbsolutePath()\r
+                                + File.pathSeparator + mbin.getAbsolutePath()\r
+                    + File.pathSeparator + mlib.getAbsolutePath());\r
+\r
                env.put("MODELICAUSERCFLAGS", "-O0");\r
                \r
                // run the process\r
diff --git a/org.simantics.sysdyn.feature/rootfiles/msvcr100.dll b/org.simantics.sysdyn.feature/rootfiles/msvcr100.dll
new file mode 100644 (file)
index 0000000..3e82b1a
Binary files /dev/null and b/org.simantics.sysdyn.feature/rootfiles/msvcr100.dll differ
index 36b13025d3711c9b03c4774ede9e1ac4f401afa7..ced8ad76f115788c4effedb47dc93ff51a78eee3 100644 (file)
@@ -16,6 +16,7 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;\r
 import java.io.FileOutputStream;\r
 import java.io.IOException;\r
+import java.lang.reflect.Field;\r
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
 \r
@@ -64,6 +65,7 @@ public class SysdynGameExperiment extends OldSysdynExperiment {
        private double startTime = DEFAULT_START_TIME;\r
        private double stepDuration = DEFAULT_STEP_DURATION;\r
        private int savePer = 1;\r
+       private static boolean fortranLibrariesLoaded = false;\r
        \r
        public static double DEFAULT_STEP_DURATION = 1.0;\r
        public static double DEFAULT_STEP_LENGTH        = 0.1;\r
@@ -243,11 +245,45 @@ public class SysdynGameExperiment extends OldSysdynExperiment {
                if(simulationLocation != null && !canceled) {\r
                        // Load fmu and initialize it for simulation\r
                        try {\r
+                               if (!fortranLibrariesLoaded) {\r
+                                       File omDir = ModelicaManager.getOMHome();\r
+                                       File mingw = new File(omDir, "MinGW");\r
+                                       File mbin = new File(mingw, "bin");\r
+                                       \r
+                                       // Add MinGW path to java.library.path. This is a bit of a hack because \r
+                                       // java.library.path isn't intended to be set programmatically.\r
+                                       String newLibPath = System.getProperty("java.library.path") + File.pathSeparator + mbin.getAbsolutePath();\r
+                                       System.setProperty("java.library.path", newLibPath);\r
+                                       Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");\r
+                                       fieldSysPath.setAccessible(true);\r
+                                       if (fieldSysPath != null) {\r
+                                               fieldSysPath.set(System.class.getClassLoader(), null);\r
+                                       }\r
+                                       \r
+                                       System.loadLibrary("libgfortran-3");\r
+                                       System.out.println("Loaded libgfortran-3.dll");\r
+                                       System.loadLibrary("pthreadGC2");\r
+                                       System.out.println("Loaded pthreadGC2.dll");\r
+                                       fortranLibrariesLoaded = true;\r
+                               }\r
+                \r
                                control.loadFMUFile(simulationLocation.executableFile.getAbsolutePath()); // unzip and load fmu\r
                                instantiate();\r
                                \r
                        } catch (FMUJNIException e) {\r
                                System.err.println("SysdynGameExperiment initialization failed:\n\t" + e.getMessage());\r
+                       } catch (SecurityException e) {\r
+                               // TODO Auto-generated catch block\r
+                               e.printStackTrace();\r
+                       } catch (NoSuchFieldException e) {\r
+                               // TODO Auto-generated catch block\r
+                               e.printStackTrace();\r
+                       } catch (IllegalArgumentException e) {\r
+                               // TODO Auto-generated catch block\r
+                               e.printStackTrace();\r
+                       } catch (IllegalAccessException e) {\r
+                               // TODO Auto-generated catch block\r
+                               e.printStackTrace();\r
                        }\r
 \r
                }\r