--- /dev/null
+package org.simantics.sysdyn.manager;\r
+\r
+import java.text.SimpleDateFormat;\r
+import java.util.Calendar;\r
+\r
+import org.eclipse.jface.text.BadLocationException;\r
+import org.eclipse.ui.PartInitException;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.console.ConsolePlugin;\r
+import org.eclipse.ui.console.IConsole;\r
+import org.eclipse.ui.console.IConsoleManager;\r
+import org.eclipse.ui.console.IHyperlink;\r
+import org.eclipse.ui.console.IPatternMatchListener;\r
+import org.eclipse.ui.console.MessageConsole;\r
+import org.eclipse.ui.console.MessageConsoleStream;\r
+import org.eclipse.ui.console.PatternMatchEvent;\r
+import org.eclipse.ui.console.TextConsole;\r
+import org.simantics.modelica.IModelicaMonitor;\r
+\r
+public class SysdynConsole implements IModelicaMonitor {\r
+\r
+ private static String SYSDYN_CONSOLE = "Sysyn modelica console";\r
+ private MessageConsole console;\r
+\r
+ public static SysdynConsole INSTANCE = new SysdynConsole();\r
+ \r
+ public SysdynConsole() {\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(SYSDYN_CONSOLE))\r
+ console = (MessageConsole) existing[i];\r
+ if(console == null) {\r
+ MessageConsole myConsole = new MessageConsole(SYSDYN_CONSOLE, null);\r
+ conMan.addConsoles(new IConsole[]{myConsole});\r
+ console = myConsole;\r
+ console.addPatternMatchListener(new IPatternMatchListener() {\r
+\r
+ @Override\r
+ public void matchFound(PatternMatchEvent event) {\r
+ try {\r
+ console.addHyperlink(new IssueLink(), event.getOffset(), event.getLength());\r
+ } catch (BadLocationException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void disconnect() {\r
+ }\r
+\r
+ @Override\r
+ public void connect(TextConsole console) {\r
+ }\r
+\r
+ @Override\r
+ public String getPattern() {\r
+ \r
+ return "Issues view";\r
+ }\r
+\r
+ @Override\r
+ public String getLineQualifier() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public int getCompilerFlags() {\r
+ return 0;\r
+ }\r
+ });\r
+ \r
+ /* Link to the modelica document: to be opened to a modelica code viewer.\r
+ console.addPatternMatchListener(new IPatternMatchListener() {\r
+\r
+ @Override\r
+ public void matchFound(PatternMatchEvent event) {\r
+ try {\r
+ if(event.getSource() instanceof MessageConsole) {\r
+ MessageConsole console = (MessageConsole) event.getSource();\r
+ IDocument document = console.getDocument();\r
+ String s = document.get(event.getOffset(), event.getLength());\r
+ s = s.substring(s.indexOf(":") + 1, s.lastIndexOf(":"));\r
+ String[] split = s.split(":|-");\r
+ \r
+ //TODO: Find the modelica document and its locations\r
+ int startOffset = modelicaDocument.getLineOffset(Integer.parseInt(split[0])) + Integer.parseInt(split[1]);\r
+ int endOffset = modelicaDocument.getLineOffset(Integer.parseInt(split[2])) + Integer.parseInt(split[3]);\r
+ System.out.println("Open modelica editor for model at: " + startOffset + ", " + (endOffset - startOffset));\r
+ \r
+ }\r
+ \r
+ console.addHyperlink(new ModelicaLink(), event.getOffset(), event.getLength());\r
+ } catch (BadLocationException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void disconnect() {\r
+ }\r
+\r
+ @Override\r
+ public void connect(TextConsole console) {\r
+ }\r
+\r
+ @Override\r
+ public String getPattern() {\r
+ return "\\[[^\\[]*:[\\d]*:[\\d]*\\-[\\d]*:[\\d]*:writable\\]";\r
+\r
+ }\r
+\r
+ @Override\r
+ public String getLineQualifier() {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public int getCompilerFlags() {\r
+ return 0;\r
+ }\r
+ });\r
+ */\r
+\r
+\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void message(String message) {\r
+ message(message, "hh:mm:ss");\r
+ }\r
+\r
+ /**\r
+ * Print message to a console with a specified time stamp format\r
+ * \r
+ * @param message the message to be printed\r
+ * @param timeStampFormat simpledateformat timestamp format. null if no timestamp wanted\r
+ */\r
+ public void message(String message, String timeStampFormat) {\r
+ Calendar cal = Calendar.getInstance();\r
+ SimpleDateFormat sdf = new SimpleDateFormat(timeStampFormat);\r
+ String time = sdf.format(cal.getTime());\r
+\r
+ MessageConsoleStream out = this.console.newMessageStream();\r
+ if(message.length() > 1)\r
+ out.println("[" + time +"] " + message);\r
+\r
+\r
+\r
+ if(message.contains("Error")) {\r
+ showConsole();\r
+ out.println("See Issues view");\r
+ }\r
+ }\r
+\r
+ public void clearConsole() {\r
+ this.console.clearConsole();\r
+ }\r
+\r
+ public void showConsole() {\r
+ ConsolePlugin plugin = ConsolePlugin.getDefault();\r
+ IConsoleManager conMan = plugin.getConsoleManager();\r
+ conMan.showConsoleView(console);\r
+ }\r
+ \r
+\r
+ class IssueLink implements IHyperlink {\r
+\r
+ @Override\r
+ public void linkEntered() {\r
+ }\r
+\r
+ @Override\r
+ public void linkExited() {\r
+ }\r
+\r
+ @Override\r
+ public void linkActivated() {\r
+ try {\r
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.simantics.issues.ui.issueview");\r
+ } catch (PartInitException e) {\r
+ e.printStackTrace();\r
+ } \r
+ }\r
+ }\r
+ \r
+ class ModelicaLink implements IHyperlink {\r
+\r
+ @Override\r
+ public void linkEntered() {\r
+ }\r
+\r
+ @Override\r
+ public void linkExited() {\r
+ }\r
+\r
+ @Override\r
+ public void linkActivated() {\r
+ System.out.println("MODELICA LINK"); \r
+ }\r
+\r
+ }\r
+\r
+}\r
import org.simantics.layer0.Layer0;\r
import org.simantics.objmap.IMapping;\r
import org.simantics.objmap.IMappingListener;\r
+import org.simantics.objmap.MappingException;\r
import org.simantics.objmap.Mappings;\r
import org.simantics.project.IProject;\r
import org.simantics.simulation.experiment.IDynamicExperiment;\r
SysdynSchema schema = new SysdynSchema(g);\r
mapping = Mappings.createWithListening(schema);\r
mapping.addMappingListener(SysdynModel.this);\r
- configuration = (Configuration)mapping.map(g, configurationResource);\r
+ try {\r
+ configuration = (Configuration)mapping.map(g, configurationResource); \r
+ } catch (MappingException e) {\r
+ SysdynConsole.INSTANCE.message(\r
+ "Error: Mapping is broken! Find the problem, " +\r
+ "fix it and restart the program." +\r
+ "\nJava error message:\n" + \r
+ e.getMessage());\r
+ throw e;\r
+ }\r
for(Resource config : readModules(g, configurationResource)) {\r
modules.add((Configuration)mapping.map(g, config));\r
}\r
*/\r
public synchronized boolean update(ReadGraph graph) throws DatabaseException {\r
if(mapping.isDomainModified()) {\r
- mapping.updateRange(graph);\r
+ \r
+ try {\r
+ mapping.updateRange(graph);\r
+ } catch (MappingException e) {\r
+ SysdynConsole.INSTANCE.message(\r
+ "Error: Mapping is broken! Find the problem, " +\r
+ "fix it and restart the program." +\r
+ "\nJava error message:\n" + \r
+ e.getMessage());\r
+ throw e;\r
+ }\r
\r
// Remove all unnecessary module configurations from modules \r
Set<Resource> configs = readModules(graph, configurationResource); \r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.request.Read;\r
import org.simantics.objmap.IMapping;\r
+import org.simantics.objmap.MappingException;\r
import org.simantics.objmap.Mappings;\r
+import org.simantics.sysdyn.manager.SysdynConsole;\r
\r
public class LoadRepresentation {\r
\r
throws DatabaseException {\r
SysdynSchema schema = new SysdynSchema(graph);\r
IMapping mapping = Mappings.createWithoutListening(schema);\r
- mapping.map(graph, configuration);\r
+ \r
+ try {\r
+ mapping.map(graph, configuration);\r
+ } catch (MappingException e) {\r
+ SysdynConsole.INSTANCE.message(\r
+ "Error: Mapping is broken! Find the problem, " +\r
+ "fix it and restart the program." +\r
+ "\nJava error message:\n" + \r
+ e.getMessage());\r
+ throw e;\r
+ }\r
+ \r
return mapping;\r
}\r
\r
throws DatabaseException {\r
SysdynSchema schema = new SysdynSchema(graph);\r
IMapping mapping = Mappings.createWithoutListening(schema);\r
- return (Configuration)mapping.map(graph, configuration); \r
+ \r
+ try {\r
+ return (Configuration)mapping.map(graph, configuration); \r
+ } catch (MappingException e) {\r
+ SysdynConsole.INSTANCE.message(\r
+ "Error: Mapping is broken! Find the problem, " +\r
+ "fix it and restart the program." +\r
+ "\nJava error message:\n" + \r
+ e.getMessage());\r
+ throw e;\r
+ }\r
+ \r
}\r
\r
});\r
throws DatabaseException {\r
SysdynSchema schema = new SysdynSchema(graph);\r
IMapping mapping = Mappings.createWithoutListening(schema);\r
- return (IElement)mapping.map(graph, element); \r
+ \r
+ try {\r
+ return (IElement)mapping.map(graph, element); \r
+ } catch (MappingException e) {\r
+ SysdynConsole.INSTANCE.message(\r
+ "Error: Mapping is broken! Find the problem, " +\r
+ "fix it and restart the program." +\r
+ "\nJava error message:\n" + \r
+ e.getMessage());\r
+ throw e;\r
+ }\r
+ \r
}\r
\r
});\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.jface.text.BadLocationException;\r
-import org.eclipse.ui.PartInitException;\r
import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.console.ConsolePlugin;\r
-import org.eclipse.ui.console.IConsole;\r
-import org.eclipse.ui.console.IConsoleManager;\r
-import org.eclipse.ui.console.IHyperlink;\r
-import org.eclipse.ui.console.IPatternMatchListener;\r
-import org.eclipse.ui.console.MessageConsole;\r
-import org.eclipse.ui.console.MessageConsoleStream;\r
-import org.eclipse.ui.console.PatternMatchEvent;\r
-import org.eclipse.ui.console.TextConsole;\r
import org.simantics.modelica.IModelicaMonitor;\r
import org.simantics.simulation.experiment.Experiment;\r
+import org.simantics.sysdyn.manager.SysdynConsole;\r
import org.simantics.sysdyn.manager.SysdynExperiment;\r
import org.simantics.sysdyn.manager.SysdynModel;\r
\r
public class SimulationJob extends Job {\r
\r
- SysdynModel model;\r
- Experiment experiment;\r
- IModelicaMonitor monitor;\r
-\r
+ private SysdynModel model;\r
+ private Experiment experiment;\r
+ private IModelicaMonitor monitor;\r
+ \r
public SimulationJob(SysdynModel model, Experiment experiment) {\r
super("Simulate " + model.getConfiguration().getLabel());\r
this.model = model;\r
this.experiment = experiment;\r
if(PlatformUI.isWorkbenchRunning()) {\r
- this.monitor = new ModelicaMonitor();\r
+ this.monitor = SysdynConsole.INSTANCE;\r
} else {\r
// Fallback to headless\r
this.monitor = new HeadlessModelicaMonitor();\r
public void showConsole() {\r
}\r
\r
- }\r
- //org.simantics.sysdyn.ui.modelicaEditor\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
- console.addPatternMatchListener(new IPatternMatchListener() {\r
-\r
- @Override\r
- public void matchFound(PatternMatchEvent event) {\r
- try {\r
- console.addHyperlink(new IssueLink(), event.getOffset(), event.getLength());\r
- } catch (BadLocationException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- @Override\r
- public void disconnect() {\r
- }\r
-\r
- @Override\r
- public void connect(TextConsole console) {\r
- }\r
-\r
- @Override\r
- public String getPattern() {\r
- \r
- return "Issues view";\r
- }\r
-\r
- @Override\r
- public String getLineQualifier() {\r
- return null;\r
- }\r
-\r
- @Override\r
- public int getCompilerFlags() {\r
- return 0;\r
- }\r
- });\r
- \r
- /* Link to the modelica document: to be opened to a modelica code viewer.\r
- console.addPatternMatchListener(new IPatternMatchListener() {\r
-\r
- @Override\r
- public void matchFound(PatternMatchEvent event) {\r
- try {\r
- if(event.getSource() instanceof MessageConsole) {\r
- MessageConsole console = (MessageConsole) event.getSource();\r
- IDocument document = console.getDocument();\r
- String s = document.get(event.getOffset(), event.getLength());\r
- s = s.substring(s.indexOf(":") + 1, s.lastIndexOf(":"));\r
- String[] split = s.split(":|-");\r
- \r
- //TODO: Find the modelica document and its locations\r
- int startOffset = modelicaDocument.getLineOffset(Integer.parseInt(split[0])) + Integer.parseInt(split[1]);\r
- int endOffset = modelicaDocument.getLineOffset(Integer.parseInt(split[2])) + Integer.parseInt(split[3]);\r
- System.out.println("Open modelica editor for model at: " + startOffset + ", " + (endOffset - startOffset));\r
- \r
- }\r
- \r
- console.addHyperlink(new ModelicaLink(), event.getOffset(), event.getLength());\r
- } catch (BadLocationException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- @Override\r
- public void disconnect() {\r
- }\r
-\r
- @Override\r
- public void connect(TextConsole console) {\r
- }\r
-\r
- @Override\r
- public String getPattern() {\r
- return "\\[[^\\[]*:[\\d]*:[\\d]*\\-[\\d]*:[\\d]*:writable\\]";\r
-\r
- }\r
-\r
- @Override\r
- public String getLineQualifier() {\r
- return null;\r
- }\r
-\r
- @Override\r
- public int getCompilerFlags() {\r
- return 0;\r
- }\r
- });\r
- */\r
-\r
-\r
- }\r
- }\r
-\r
- @Override\r
- public void message(String message) {\r
- message(message, "hh:mm:ss");\r
- }\r
-\r
- /**\r
- * Print message to a console with a specified time stamp format\r
- * \r
- * @param message the message to be printed\r
- * @param timeStampFormat simpledateformat timestamp format. null if no timestamp wanted\r
- */\r
- public void message(String message, String timeStampFormat) {\r
- Calendar cal = Calendar.getInstance();\r
- SimpleDateFormat sdf = new SimpleDateFormat(timeStampFormat);\r
- String time = sdf.format(cal.getTime());\r
-\r
- MessageConsoleStream out = this.console.newMessageStream();\r
- if(message.length() > 1)\r
- out.println("[" + time +"] " + message);\r
-\r
-\r
-\r
- if(message.contains("Error")) {\r
- showConsole();\r
- out.println("See Issues view");\r
- }\r
- }\r
-\r
- public void clearConsole() {\r
- this.console.clearConsole();\r
- }\r
-\r
- public void showConsole() {\r
- ConsolePlugin plugin = ConsolePlugin.getDefault();\r
- IConsoleManager conMan = plugin.getConsoleManager();\r
- conMan.showConsoleView(console);\r
- }\r
-\r
}\r
\r
@Override\r
\r
}\r
\r
-\r
- class IssueLink implements IHyperlink {\r
-\r
- @Override\r
- public void linkEntered() {\r
- }\r
-\r
- @Override\r
- public void linkExited() {\r
- }\r
-\r
- @Override\r
- public void linkActivated() {\r
- try {\r
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.simantics.issues.ui.issueview");\r
- } catch (PartInitException e) {\r
- e.printStackTrace();\r
- } \r
- }\r
- }\r
- \r
- class ModelicaLink implements IHyperlink {\r
-\r
- @Override\r
- public void linkEntered() {\r
- }\r
-\r
- @Override\r
- public void linkExited() {\r
- }\r
-\r
- @Override\r
- public void linkActivated() {\r
- System.out.println("MODELICA LINK"); \r
- }\r
-\r
- }\r
-\r
}\r