]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Sysdyn modelica simulation console
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 23 Feb 2010 13:34:35 +0000 (13:34 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 23 Feb 2010 13:34:35 +0000 (13:34 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14351 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java
org.simantics.sysdyn.ui/META-INF/MANIFEST.MF
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationJob.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java

index b61f37e753c504d78cde0acc45f81f7da14b004e..0244e434959181f4c1186d02ca4113158b6f99a8 100644 (file)
@@ -43,11 +43,17 @@ public class ModelicaManager {
     \r
     protected static void printProcessOutput(Process process, IModelicaMonitor monitor) throws IOException {\r
         InputStream stream = process.getInputStream();\r
+        StringBuilder b = new StringBuilder();\r
         while(true) {\r
             int c = stream.read();\r
             if(c <= 0)\r
                 break;\r
-            monitor.message(new String(new char[] {(char)c}));\r
+            if((char)c != '\n')\r
+                b.append((char)c);\r
+            else {\r
+                monitor.message(b.toString());\r
+                b.delete(0, b.length());\r
+            }\r
         }\r
     }\r
     \r
index 6df3ec2da00af17b2ec030661a02a06ed5937533..cb32270707413d7bff0187a7d383091785a48a3d 100644 (file)
@@ -23,6 +23,7 @@ Require-Bundle: org.simantics.h2d;bundle-version="1.0.0",
  org.simantics.modelica;bundle-version="1.0.0",
  org.simantics.browsing.ui;bundle-version="0.9.0",
  org.simantics.browsing.ui.common;bundle-version="0.9.0",
- org.apache.log4j;bundle-version="1.2.15"
+ org.apache.log4j;bundle-version="1.2.15",
+ org.eclipse.ui.console;bundle-version="3.4.0"
 Bundle-Activator: org.simantics.sysdyn.ui.Activator
 Bundle-ActivationPolicy: lazy
index a88112075d1ed17ef793eb7004ed4916b6064be8..2aa1e0290989d052471eaa27c662ab1167c12240 100644 (file)
                tooltip="Pins the trend so that it does not react to selection changes">\r
          </command>\r
       </menuContribution>\r
+      <menuContribution\r
+            locationURI="popup:#SysdynDiagramPopup?after=wbStart">\r
+         <menu\r
+               label="New...">\r
+            <command\r
+                  commandId="org.simantics.sysdyn.ui.createAuxiliary"\r
+                  label="Auxiliary"\r
+                  style="push">\r
+            </command>\r
+            <command\r
+                  commandId="org.simantics.sysdyn.ui.createStock"\r
+                  label="Stock"\r
+                  style="push">\r
+            </command>\r
+            <command\r
+                  commandId="org.simantics.sysdyn.ui.createCloud"\r
+                  label="Cloud"\r
+                  style="push">\r
+            </command>\r
+         </menu>\r
+         <command\r
+               commandId="org.simantics.sysdyn.ui.rename"\r
+               label="Rename"\r
+               style="push">\r
+            <visibleWhen\r
+                  checkEnabled="true">\r
+            </visibleWhen>\r
+         </command>\r
+         <command\r
+               commandId="org.simantics.sysdyn.ui.remove"\r
+               label="Remove"\r
+               style="push">\r
+            <visibleWhen\r
+                  checkEnabled="true">\r
+            </visibleWhen>\r
+         </command>\r
+      </menuContribution>\r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.commands">\r
             class="org.simantics.sysdyn.ui.trend.PinTrend"\r
             commandId="org.simantics.sysdyn.ui.trend.view.pin">\r
       </handler>\r
-   </extension>\r
-   <extension\r
-         point="org.eclipse.ui.menus">\r
-      <menuContribution\r
-            locationURI="popup:#SysdynDiagramPopup?after=wbStart">\r
-         <menu\r
-               label="New...">\r
-            <command\r
-                  commandId="org.simantics.sysdyn.ui.createAuxiliary"\r
-                  label="Auxiliary"\r
-                  style="push">\r
-            </command>\r
-            <command\r
-                  commandId="org.simantics.sysdyn.ui.createStock"\r
-                  label="Stock"\r
-                  style="push">\r
-            </command>\r
-            <command\r
-                  commandId="org.simantics.sysdyn.ui.createCloud"\r
-                  label="Cloud"\r
-                  style="push">\r
-            </command>\r
-         </menu>\r
-         <command\r
-               commandId="org.simantics.sysdyn.ui.rename"\r
-               label="Rename"\r
-               style="push">\r
-            <visibleWhen\r
-                  checkEnabled="true">\r
-            </visibleWhen>\r
-         </command>\r
-         <command\r
-               commandId="org.simantics.sysdyn.ui.remove"\r
-               label="Remove"\r
-               style="push">\r
-            <visibleWhen\r
-                  checkEnabled="true">\r
-            </visibleWhen>\r
-         </command>\r
-      </menuContribution>\r
-   </extension>\r
+   </extension>
 </plugin>\r
index 3ad32a21f45796c38971dc8c395ed5e9b073130f..6a4611c9b54494d8f8d7f6a3675e9db4ad6c9040 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.sysdyn.ui.project;
 import org.eclipse.ui.IFolderLayout;\r
 import org.eclipse.ui.IPageLayout;\r
 import org.eclipse.ui.IPerspectiveFactory;\r
+import org.eclipse.ui.console.IConsoleConstants;\r
 \r
 public class SysdynPerspectiveFactory implements IPerspectiveFactory {\r
 \r
@@ -14,6 +15,7 @@ public class SysdynPerspectiveFactory implements IPerspectiveFactory {
         IFolderLayout bottom1 = layout.createFolder("bottom1", IPageLayout.BOTTOM, 0.75f, editorArea);\r
         IFolderLayout bottom2 = layout.createFolder("bottom2", IPageLayout.LEFT, 0.4f, "bottom1");        \r
         bottom1.addView("org.simantics.sysdyn.ui.equation.view");\r
+        bottom1.addView(IConsoleConstants.ID_CONSOLE_VIEW);\r
         bottom2.addView("org.simantics.sysdyn.ui.trend.view");\r
         \r
         IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, 0.25f, editorArea);\r
index bcf8dfa4c98c309abdf089fbfa7fd6c8c08b27e0..3a80ebab55cf788e00896442147cef775049b6d3 100644 (file)
@@ -4,22 +4,31 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;\r
 import org.eclipse.core.runtime.Status;\r
 import org.eclipse.core.runtime.jobs.Job;\r
+import org.eclipse.ui.console.IConsole;\r
+import org.eclipse.ui.console.ConsolePlugin;\r
+import org.eclipse.ui.console.IConsoleManager;\r
+import org.eclipse.ui.console.MessageConsole;\r
+import org.eclipse.ui.console.MessageConsoleStream;\r
+import org.simantics.modelica.IModelicaMonitor;\r
 import org.simantics.sysdyn.manager.SysdynModel;\r
 \r
 public class SimulationJob extends Job {\r
 \r
     SysdynModel model;\r
-    \r
+    ModelicaMonitor monitor;\r
+\r
     public SimulationJob(SysdynModel model) {\r
         super("Simulate " + model.getConfiguration().name);\r
         this.model = model;\r
+        this.monitor = new ModelicaMonitor();\r
     }\r
 \r
     @Override\r
     protected IStatus run(IProgressMonitor monitor) {\r
+        this.monitor.clearConsole();\r
         try {\r
             model.update();\r
-            model.simulate();\r
+            model.simulate(this.monitor);\r
         } catch (Exception e) {\r
             e.printStackTrace();\r
             return new Status(\r
@@ -30,4 +39,34 @@ public class SimulationJob extends Job {
         return Status.OK_STATUS;\r
     }\r
 \r
+    private class ModelicaMonitor implements IModelicaMonitor {\r
+\r
+        MessageConsole console;\r
+\r
+        public ModelicaMonitor() {\r
+            ConsolePlugin plugin = ConsolePlugin.getDefault();\r
+            IConsoleManager conMan = plugin.getConsoleManager();\r
+            IConsole[] existing = conMan.getConsoles();\r
+            for (int i = 0; i < existing.length; i++)\r
+                if (existing[i].getName().equals("Simulation"))\r
+                    console =  (MessageConsole) existing[i];\r
+            if(console == null) {\r
+                MessageConsole myConsole = new MessageConsole("Simulation", null);\r
+                conMan.addConsoles(new IConsole[]{myConsole});\r
+                console = myConsole;\r
+            }\r
+        }\r
+\r
+        @Override\r
+        public void message(String message) {\r
+            MessageConsoleStream out = this.console.newMessageStream();\r
+            out.println(message);\r
+        }\r
+        \r
+        public void clearConsole() {\r
+            this.console.clearConsole();\r
+        }\r
+\r
+    }\r
+\r
 }\r
index e1eca4306b2515ee13183f3fdbe88c22e0d982dc..6e1de23dee44320febd617230e2899e6e0b5ff0c 100644 (file)
@@ -10,6 +10,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.Session;\r
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.modelica.IModelicaMonitor;\r
 import org.simantics.modelica.ModelicaManager;\r
 import org.simantics.modelica.data.SimulationResult;\r
 import org.simantics.objmap.IMapping;\r
@@ -63,14 +64,15 @@ public class SysdynModel implements IMappingListener {
         }\r
     }\r
     \r
-    public synchronized void simulate() throws IOException {\r
+    public synchronized void simulate(IModelicaMonitor monitor) throws IOException {\r
         try {\r
             ModelicaWriter writer = new ModelicaWriter();\r
             writer.write(configuration);\r
             \r
             result = ModelicaManager.runModelica(\r
                     configuration.name,\r
-                    writer.toString(),\r
+                    writer.toString(), \r
+                    monitor,\r
                     configuration.startTime,\r
                     configuration.stopTime);            \r
         } catch(Exception e) {\r
@@ -156,5 +158,5 @@ public class SysdynModel implements IMappingListener {
             services.put(clazz, service);\r
         }\r
     }\r
-\r
+   \r
 }\r