\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
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
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
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
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
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
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
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
}\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
services.put(clazz, service);\r
}\r
}\r
-\r
+ \r
}\r