From 0af2a72a5091a7273840568f1bf00422304a32aa Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 23 Feb 2010 13:34:35 +0000 Subject: [PATCH] Sysdyn modelica simulation console git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14351 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../simantics/modelica/ModelicaManager.java | 8 +- org.simantics.sysdyn.ui/META-INF/MANIFEST.MF | 3 +- org.simantics.sysdyn.ui/plugin.xml | 79 +++++++++---------- .../ui/project/SysdynPerspectiveFactory.java | 2 + .../sysdyn/ui/simulation/SimulationJob.java | 43 +++++++++- .../simantics/sysdyn/manager/SysdynModel.java | 8 +- 6 files changed, 95 insertions(+), 48 deletions(-) diff --git a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java index b61f37e7..0244e434 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java +++ b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java @@ -43,11 +43,17 @@ public class ModelicaManager { protected static void printProcessOutput(Process process, IModelicaMonitor monitor) throws IOException { InputStream stream = process.getInputStream(); + StringBuilder b = new StringBuilder(); while(true) { int c = stream.read(); if(c <= 0) break; - monitor.message(new String(new char[] {(char)c})); + if((char)c != '\n') + b.append((char)c); + else { + monitor.message(b.toString()); + b.delete(0, b.length()); + } } } diff --git a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF index 6df3ec2d..cb322707 100644 --- a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF @@ -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 diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index a8811207..2aa1e029 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -78,6 +78,43 @@ tooltip="Pins the trend so that it does not react to selection changes"> + + + + + + + + + + + + + + + + + + @@ -121,45 +158,5 @@ class="org.simantics.sysdyn.ui.trend.PinTrend" commandId="org.simantics.sysdyn.ui.trend.view.pin"> - - - - - - - - - - - - - - - - - - - - - + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java index 3ad32a21..6a4611c9 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java @@ -3,6 +3,7 @@ package org.simantics.sysdyn.ui.project; import org.eclipse.ui.IFolderLayout; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; +import org.eclipse.ui.console.IConsoleConstants; public class SysdynPerspectiveFactory implements IPerspectiveFactory { @@ -14,6 +15,7 @@ public class SysdynPerspectiveFactory implements IPerspectiveFactory { IFolderLayout bottom1 = layout.createFolder("bottom1", IPageLayout.BOTTOM, 0.75f, editorArea); IFolderLayout bottom2 = layout.createFolder("bottom2", IPageLayout.LEFT, 0.4f, "bottom1"); bottom1.addView("org.simantics.sysdyn.ui.equation.view"); + bottom1.addView(IConsoleConstants.ID_CONSOLE_VIEW); bottom2.addView("org.simantics.sysdyn.ui.trend.view"); IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, 0.25f, editorArea); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationJob.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationJob.java index bcf8dfa4..3a80ebab 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationJob.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationJob.java @@ -4,22 +4,31 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; +import org.simantics.modelica.IModelicaMonitor; import org.simantics.sysdyn.manager.SysdynModel; public class SimulationJob extends Job { SysdynModel model; - + ModelicaMonitor monitor; + public SimulationJob(SysdynModel model) { super("Simulate " + model.getConfiguration().name); this.model = model; + this.monitor = new ModelicaMonitor(); } @Override protected IStatus run(IProgressMonitor monitor) { + this.monitor.clearConsole(); try { model.update(); - model.simulate(); + model.simulate(this.monitor); } catch (Exception e) { e.printStackTrace(); return new Status( @@ -30,4 +39,34 @@ public class SimulationJob extends Job { return Status.OK_STATUS; } + private class ModelicaMonitor implements IModelicaMonitor { + + MessageConsole console; + + public ModelicaMonitor() { + ConsolePlugin plugin = ConsolePlugin.getDefault(); + IConsoleManager conMan = plugin.getConsoleManager(); + IConsole[] existing = conMan.getConsoles(); + for (int i = 0; i < existing.length; i++) + if (existing[i].getName().equals("Simulation")) + console = (MessageConsole) existing[i]; + if(console == null) { + MessageConsole myConsole = new MessageConsole("Simulation", null); + conMan.addConsoles(new IConsole[]{myConsole}); + console = myConsole; + } + } + + @Override + public void message(String message) { + MessageConsoleStream out = this.console.newMessageStream(); + out.println(message); + } + + public void clearConsole() { + this.console.clearConsole(); + } + + } + } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java index e1eca430..6e1de23d 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java @@ -10,6 +10,7 @@ import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.modelica.IModelicaMonitor; import org.simantics.modelica.ModelicaManager; import org.simantics.modelica.data.SimulationResult; import org.simantics.objmap.IMapping; @@ -63,14 +64,15 @@ public class SysdynModel implements IMappingListener { } } - public synchronized void simulate() throws IOException { + public synchronized void simulate(IModelicaMonitor monitor) throws IOException { try { ModelicaWriter writer = new ModelicaWriter(); writer.write(configuration); result = ModelicaManager.runModelica( configuration.name, - writer.toString(), + writer.toString(), + monitor, configuration.startTime, configuration.stopTime); } catch(Exception e) { @@ -156,5 +158,5 @@ public class SysdynModel implements IMappingListener { services.put(clazz, service); } } - + } -- 2.47.1