From: lempinen Date: Mon, 7 Jun 2010 07:32:19 +0000 (+0000) Subject: Simulation run to GE and better toggle simulation handling X-Git-Tag: simantics-1.2.0~227 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=b5f9f0a577ea5c7d9eec05c45c1c6c2bb697be2c;p=simantics%2Fsysdyn.git Simulation run to GE and better toggle simulation handling git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16054 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/adapters.xml b/org.simantics.sysdyn.ui/adapters.xml index 49125c61..7518623b 100644 --- a/org.simantics.sysdyn.ui/adapters.xml +++ b/org.simantics.sysdyn.ui/adapters.xml @@ -25,5 +25,5 @@ - + \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index bb6143f7..e7a97cbd 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -469,6 +469,10 @@ class="org.simantics.sysdyn.ui.browser.contributions.Experiment" preference="1.0"> + + + + + + { + + @Override + public Collection getContribution(ReadGraph graph, ExperimentNode experiment) throws DatabaseException { + ArrayList result = new ArrayList(); + Builtins b = graph.getBuiltins(); + for(Resource r : graph.syncRequest(new ObjectsWithType(experiment.resource, b.ConsistsOf, b.Run))) { + try { + result.add(graph.adapt(r, AbstractNode.class)); + } catch(DatabaseException e) { + e.printStackTrace(); + } + } + return result; + } + + @Override + public String getViewpointId() { + return "Standard"; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java new file mode 100644 index 00000000..1aef4422 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java @@ -0,0 +1,17 @@ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.swt.ImagerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode; + +public class SimulationResultImager extends ImagerContributor{ + + @Override + public ImageDescriptor getDescriptor(ReadGraph graph, SimulationResultNode input) throws DatabaseException { + return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar.png")); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultLabeler.java new file mode 100644 index 00000000..cf5b808c --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultLabeler.java @@ -0,0 +1,16 @@ +package org.simantics.sysdyn.ui.browser.contributions; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode; + +public class SimulationResultLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, SimulationResultNode result) throws DatabaseException { + String name = graph.getPossibleRelatedValue(result.resource, graph.getBuiltins().HasName); + return name == null ? "Experiment (no name)" : name; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java new file mode 100644 index 00000000..28be114c --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java @@ -0,0 +1,12 @@ +package org.simantics.sysdyn.ui.browser.nodes; + +import org.simantics.browsing.ui.common.node.IDeletable; +import org.simantics.db.Resource; + +public class SimulationResultNode extends AbstractNode implements IDeletable { + + public SimulationResultNode(Resource resource) { + super(resource); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java index 0d4047a5..bc71e8e7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java @@ -61,7 +61,12 @@ public class NewModelHandler extends AbstractHandler { Resource report = GraphUtils.create2(g, mu.b.Report, mu.b.HasDocumentation, "===Report==="); Resource experiment = GraphUtils.create2(g, mu.b.Experiment, - mu.b.HasName, "Experiment", + mu.b.HasName, "Experiment 1", + mu.b.HasReportFactory, report, + mu.b.PartOf, model); + + experiment = GraphUtils.create2(g, mu.b.Experiment, + mu.b.HasName, "Experiment 2", mu.b.HasReportFactory, report, mu.b.PartOf, model); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java index 4b681603..85823f83 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java @@ -41,7 +41,13 @@ public class SysdynExperimentActivator { String experimentName = getName(processor, experiment); if (experimentName != null) jobName += " '" + experimentName + "'"; - + /* + // Shut down the previous active experiment + IExperiment activeExperiment = experimentManager.getActiveExperiment(); + if (experiment != null) + activeExperiment.shutdown(); + */ + // Activate a new experiment scheduleActivation(jobName, project, experimentManager, experiment); } @@ -85,6 +91,10 @@ public class SysdynExperimentActivator { monitor.beginTask("Activating experiment", IProgressMonitor.UNKNOWN); try { SysdynExperimentManagerListener.listenManager(manager); + IExperiment experiment = manager.getActiveExperiment(); + if(experiment != null) { + experiment.shutdown(); + } final Semaphore activated = new Semaphore(0); final DataContainer problem = new DataContainer(); manager.startExperiment(experimentResource, new IExperimentActivationListener() { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java index 3ccec206..bc58ec64 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java @@ -114,6 +114,11 @@ public class SysdynProject extends AbstractProjectFeature { mu.b.HasReportFactory, report, mu.b.PartOf, model); + experiment = GraphUtils.create2(g, mu.b.Experiment, + mu.b.HasName, "Experiment 2", + mu.b.HasReportFactory, report, + mu.b.PartOf, model); + callback.run(model); } catch(Exception e) { errorCallback.run(e); diff --git a/org.simantics.sysdyn/META-INF/MANIFEST.MF b/org.simantics.sysdyn/META-INF/MANIFEST.MF index d10349c0..47301654 100644 --- a/org.simantics.sysdyn/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn/META-INF/MANIFEST.MF @@ -12,7 +12,8 @@ Require-Bundle: org.simantics.objmap;bundle-version="0.1.0", 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, diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java index 5a1a29f9..1297dba9 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java @@ -5,6 +5,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.db.request.Read; import org.simantics.simulation.experiment.Experiment; import org.simantics.simulation.experiment.ExperimentState; import org.simantics.simulation.experiment.IDynamicExperiment; @@ -17,6 +18,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment { public SysdynExperiment(Resource model) { super(model); + System.out.println(this.getIdentifier()); // TODO Auto-generated constructor stub } @@ -40,58 +42,57 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment { System.out.println("simulate"); if(enabled) { changeState(ExperimentState.STOPPED); - session.asyncRequest(new ReadRequest() { + startSimulation(); + } + } + + + private SysdynModel startSimulation() { + try { + return session.syncRequest(new Read() { @Override - public void run(ReadGraph graph) throws DatabaseException { + public SysdynModel perform(ReadGraph graph) throws DatabaseException { final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration); SysdynModel sysdynmodel = SysdynModelManager.getInstance(session).getModel(graph, configuration); SimulationScheduler.start(sysdynmodel); + return sysdynmodel; } }); + } catch (DatabaseException e) { + e.printStackTrace(); } - + return null; } public void toggleSimulation(boolean enabled) { if(enabled) { changeState(ExperimentState.RUNNING); if(modificationListener == null) { - try { - session.syncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph graph) throws DatabaseException { - final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration); - SysdynModel sysdynmodel = - SysdynModelManager.getInstance(session).getModel(graph, configuration); - SimulationScheduler.start(sysdynmodel); - - modificationListener = new Runnable() { - - @Override - public void run() { - session.asyncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph graph) throws DatabaseException { - if(getState() == ExperimentState.RUNNING) { - SysdynModel sysdynmodel = - SysdynModelManager.getInstance(session).getModel(graph, configuration); - SimulationScheduler.start(sysdynmodel); - } - - } - }); - - }; - }; - sysdynmodel.addModificationListener(modificationListener); - }}); - } catch (DatabaseException e) { - e.printStackTrace(); - } + SysdynModel sysdynModel = startSimulation(); + + modificationListener = new Runnable() { + + @Override + public void run() { + session.asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + if(getState() == ExperimentState.RUNNING) { + Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration); + SysdynModel sysdynmodel = + SysdynModelManager.getInstance(session).getModel(graph, configuration); + SimulationScheduler.start(sysdynmodel); + } + + } + }); + + }; + }; + sysdynModel.addModificationListener(modificationListener); } } else { @@ -117,14 +118,14 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment { changeState(ExperimentState.STOPPED); this.session = g.getSession(); } - + @Override protected void localStateChange() { ExperimentState state = getState(); switch(state) { case DISPOSED: session.asyncRequest(new ReadRequest() { - + @Override public void run(ReadGraph graph) throws DatabaseException { final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration); @@ -132,11 +133,11 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment { SysdynModelManager.getInstance(session).getModel(graph, configuration); sysdynmodel.removeModificationListener(modificationListener); modificationListener = null; - + } }); break; - } + } }