<graph />\r
<this />\r
</type>\r
- </target>\r \r <target\r interface="org.simantics.sysdyn.ui.browser.nodes.AbstractNode">\r <type\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/IndependentVariable"\r class="org.simantics.sysdyn.ui.browser.nodes.VariableNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Simulation-1.0/Types/Experiment"\r class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r <this />\r </type>\r </target>\r \r
+ </target>\r \r <target\r interface="org.simantics.sysdyn.ui.browser.nodes.AbstractNode">\r <type\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/IndependentVariable"\r class="org.simantics.sysdyn.ui.browser.nodes.VariableNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Simulation-1.0/Types/Experiment"\r class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Simulation-1.0/Types/Run"\r class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r <this />\r </type>\r </target>\r \r
</adapters>
\ No newline at end of file
class="org.simantics.sysdyn.ui.browser.contributions.Experiment"\r
preference="1.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SimulationResult"\r
+ preference="2.0">\r
+ </implementation>\r
</binding>\r
</extension>\r
<extension\r
class="org.simantics.sysdyn.ui.browser.contributions.ExperimentLabeler"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultLabeler"\r
+ preference="2.0">\r
+ </implementation>\r
</binding>\r
</extension>\r
<extension\r
class="org.simantics.sysdyn.ui.browser.contributions.ExperimentImager"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultImager"\r
+ preference="2.0">\r
+ </implementation>\r
</binding>\r
</extension>\r
<extension\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.AbstractNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode;\r
+\r
+public class SimulationResult extends ViewpointContributor<ExperimentNode> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
+ ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
+ Builtins b = graph.getBuiltins();\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(experiment.resource, b.ConsistsOf, b.Run))) {\r
+ try {\r
+ result.add(graph.adapt(r, AbstractNode.class));\r
+ } catch(DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.simantics.browsing.ui.swt.ImagerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode;\r
+\r
+public class SimulationResultImager extends ImagerContributor<SimulationResultNode>{\r
+\r
+ @Override\r
+ public ImageDescriptor getDescriptor(ReadGraph graph, SimulationResultNode input) throws DatabaseException {\r
+ return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar.png"));\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode;\r
+\r
+public class SimulationResultLabeler extends LabelerContributor<SimulationResultNode>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, SimulationResultNode result) throws DatabaseException {\r
+ String name = graph.getPossibleRelatedValue(result.resource, graph.getBuiltins().HasName);\r
+ return name == null ? "Experiment (no name)" : name;\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import org.simantics.browsing.ui.common.node.IDeletable;\r
+import org.simantics.db.Resource;\r
+\r
+public class SimulationResultNode extends AbstractNode implements IDeletable {\r
+\r
+ public SimulationResultNode(Resource resource) {\r
+ super(resource);\r
+ }\r
+ \r
+}\r
Resource report = GraphUtils.create2(g, mu.b.Report, mu.b.HasDocumentation, "===Report===");\r
\r
Resource experiment = GraphUtils.create2(g, mu.b.Experiment,\r
- mu.b.HasName, "Experiment",\r
+ mu.b.HasName, "Experiment 1",\r
+ mu.b.HasReportFactory, report,\r
+ mu.b.PartOf, model);\r
+ \r
+ experiment = GraphUtils.create2(g, mu.b.Experiment,\r
+ mu.b.HasName, "Experiment 2",\r
mu.b.HasReportFactory, report,\r
mu.b.PartOf, model);\r
}\r
String experimentName = getName(processor, experiment);\r
if (experimentName != null)\r
jobName += " '" + experimentName + "'";\r
-\r
+ /*\r
+ // Shut down the previous active experiment\r
+ IExperiment activeExperiment = experimentManager.getActiveExperiment();\r
+ if (experiment != null)\r
+ activeExperiment.shutdown();\r
+ */\r
+ // Activate a new experiment\r
scheduleActivation(jobName, project, experimentManager, experiment);\r
}\r
\r
monitor.beginTask("Activating experiment", IProgressMonitor.UNKNOWN);\r
try {\r
SysdynExperimentManagerListener.listenManager(manager);\r
+ IExperiment experiment = manager.getActiveExperiment();\r
+ if(experiment != null) {\r
+ experiment.shutdown();\r
+ }\r
final Semaphore activated = new Semaphore(0);\r
final DataContainer<Throwable> problem = new DataContainer<Throwable>();\r
manager.startExperiment(experimentResource, new IExperimentActivationListener() {\r
mu.b.HasReportFactory, report,\r
mu.b.PartOf, model);\r
\r
+ experiment = GraphUtils.create2(g, mu.b.Experiment,\r
+ mu.b.HasName, "Experiment 2",\r
+ mu.b.HasReportFactory, report,\r
+ mu.b.PartOf, model);\r
+ \r
callback.run(model);\r
} catch(Exception e) {\r
errorCallback.run(e);\r
org.simantics.data;bundle-version="0.6.3",
org.eclipse.ui.console;bundle-version="3.4.0",
org.eclipse.core.runtime;bundle-version="3.5.0",
- org.eclipse.jface;bundle-version="3.5.2"
+ org.eclipse.jface;bundle-version="3.5.2",
+ org.simantics.project;bundle-version="1.0.0"
Export-Package: org.simantics.sysdyn,
org.simantics.sysdyn.expressionParser,
org.simantics.sysdyn.manager,
import org.simantics.db.Session;\r
import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
import org.simantics.simulation.experiment.Experiment;\r
import org.simantics.simulation.experiment.ExperimentState;\r
import org.simantics.simulation.experiment.IDynamicExperiment;\r
\r
public SysdynExperiment(Resource model) {\r
super(model);\r
+ System.out.println(this.getIdentifier());\r
// TODO Auto-generated constructor stub\r
}\r
\r
System.out.println("simulate");\r
if(enabled) {\r
changeState(ExperimentState.STOPPED);\r
- session.asyncRequest(new ReadRequest() {\r
+ startSimulation();\r
+ }\r
+ }\r
+\r
+\r
+ private SysdynModel startSimulation() {\r
+ try {\r
+ return session.syncRequest(new Read<SysdynModel>() {\r
\r
@Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
+ public SysdynModel perform(ReadGraph graph) throws DatabaseException {\r
final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
SysdynModel sysdynmodel = \r
SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
SimulationScheduler.start(sysdynmodel);\r
+ return sysdynmodel;\r
}\r
});\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
}\r
-\r
+ return null;\r
}\r
\r
public void toggleSimulation(boolean enabled) {\r
if(enabled) {\r
changeState(ExperimentState.RUNNING);\r
if(modificationListener == null) { \r
- try {\r
- session.syncRequest(new ReadRequest() {\r
-\r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
- SysdynModel sysdynmodel = \r
- SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
- SimulationScheduler.start(sysdynmodel);\r
-\r
- modificationListener = new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- session.asyncRequest(new ReadRequest() {\r
-\r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- if(getState() == ExperimentState.RUNNING) {\r
- SysdynModel sysdynmodel = \r
- SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
- SimulationScheduler.start(sysdynmodel);\r
- }\r
-\r
- }\r
- });\r
-\r
- };\r
- };\r
- sysdynmodel.addModificationListener(modificationListener);\r
- }});\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
+ SysdynModel sysdynModel = startSimulation();\r
+\r
+ modificationListener = new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ session.asyncRequest(new ReadRequest() {\r
+\r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ if(getState() == ExperimentState.RUNNING) {\r
+ Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
+ SysdynModel sysdynmodel = \r
+ SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
+ SimulationScheduler.start(sysdynmodel);\r
+ }\r
+\r
+ }\r
+ });\r
+\r
+ };\r
+ };\r
+ sysdynModel.addModificationListener(modificationListener);\r
} \r
}\r
else {\r
changeState(ExperimentState.STOPPED);\r
this.session = g.getSession();\r
}\r
- \r
+\r
@Override\r
protected void localStateChange() {\r
ExperimentState state = getState();\r
switch(state) {\r
case DISPOSED:\r
session.asyncRequest(new ReadRequest() {\r
- \r
+\r
@Override\r
public void run(ReadGraph graph) throws DatabaseException {\r
final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
sysdynmodel.removeModificationListener(modificationListener);\r
modificationListener = null;\r
- \r
+\r
}\r
});\r
break;\r
- }\r
+ }\r
}\r
\r
\r