org.simantics.modeling;bundle-version="1.0.0",
org.simantics.mapping;bundle-version="1.0.0",
org.simantics.structural.stubs;bundle-version="1.0.0",
- gnu.trove2;bundle-version="2.0.4"
+ gnu.trove2;bundle-version="2.0.4",
+ org.simantics.simulation;bundle-version="1.0.0",
+ org.simantics.data;bundle-version="0.6.3",
+ org.simantics.message;bundle-version="0.9.0"
Bundle-Activator: org.simantics.sysdyn.ui.Activator
Bundle-ActivationPolicy: lazy
<resource\r
uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r
class="org.simantics.sysdyn.ui.project.SysdynProject" />\r
- <resource\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynSymbols"\r class="org.simantics.sysdyn.ui.editor.SymbolsFeature" />\r </target>\r \r
+ <resource\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynSymbols"\r class="org.simantics.sysdyn.ui.editor.SymbolsFeature" />\r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModelManager"\r class="org.simantics.sysdyn.ui.project.SysdynProject" />\r </target>\r \r <target interface="org.simantics.project.IProjectLifeCycle">\r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r class="org.simantics.sysdyn.ui.project.SysdynProjectLifeCycle" />\r </target>\r \r
<target\r
interface="org.simantics.scenegraph.adapters.ISceneGraphProvider">\r
<type\r
<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 </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 </target>\r \r
</adapters>
\ No newline at end of file
<extension\r
point="org.eclipse.ui.menus">\r
<menuContribution\r
- locationURI="toolbar:org.simantics.sysdyn.ui.trend.view">\r
- <command\r
- commandId="org.simantics.sysdyn.ui.trend.view.pin"\r
- icon="icons/table_multiple_pinned.png"\r
- label="Pin Trend"\r
- style="toggle"\r
- tooltip="Pins the trend so that it does not react to selection changes">\r
- </command>\r
- </menuContribution>\r
- <menuContribution\r
- locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">\r
+ locationURI="toolbar:org.eclipse.ui.main.toolbar">\r
<toolbar\r
- id="org.simantics.sysdyn.ui.sysdynToolbar">\r
+ id="org.simantics.sysdyn.ui.experimentControlToolbar">\r
<command\r
- commandId="org.simantics.sysdyn.ui.simulate"\r
+ commandId="org.simantics.sysdyn.ui.run"\r
+ hoverIcon="icons/control_play_blue.png"\r
icon="icons/control_play.png"\r
+ id="org.simantics.sysdyn.ui.run.button"\r
label="Simulate"\r
+ style="push">\r
+ <visibleWhen>\r
+ <with\r
+ variable="activeContexts">\r
+ <iterate\r
+ ifEmpty="false"\r
+ operator="or">\r
+ <equals\r
+ value="org.simantics.sysdyn.ui.basicExperiment">\r
+ </equals>\r
+ </iterate>\r
+ </with>\r
+ </visibleWhen>\r
+ </command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.toggleSimulation"\r
+ hoverIcon="icons/control_repeat_blue.png"\r
+ icon="icons/control_repeat.png"\r
+ label="Simulate On Change"\r
style="toggle"\r
- tooltip="Toggle simulation">\r
- <visibleWhen\r
- checkEnabled="true">\r
+ tooltip="Simulate On Change">\r
+ <visibleWhen>\r
+ <with\r
+ variable="activeContexts">\r
+ <iterate\r
+ ifEmpty="false"\r
+ operator="or">\r
+ <equals\r
+ value="org.simantics.sysdyn.ui.basicExperiment">\r
+ </equals>\r
+ </iterate>\r
+ </with>\r
+ </visibleWhen>\r
+ </command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.dispose"\r
+ hoverIcon="icons/control_eject_blue.png"\r
+ icon="icons/control_eject.png"\r
+ id="org.simantics.sysdyn.ui.dispose.button"\r
+ label="Quit Experiment">\r
+ <visibleWhen>\r
<with\r
- variable="activeWorkbenchWindow.activePerspective">\r
- <equals\r
- value="org.simantics.sysdyn.ui.perspective">\r
- </equals>\r
+ variable="activeContexts">\r
+ <iterate\r
+ ifEmpty="false"\r
+ operator="or">\r
+ <equals\r
+ value="org.simantics.sysdyn.ui.basicExperiment">\r
+ </equals>\r
+ </iterate>\r
+ </with>\r
+ </visibleWhen>\r
+ </command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.saveResults"\r
+ icon="icons/disk.png"\r
+ id="org.simantics.sysdyn.ui.save.button">\r
+ <visibleWhen>\r
+ <with\r
+ variable="activeContexts">\r
+ <iterate\r
+ ifEmpty="false"\r
+ operator="or">\r
+ <equals\r
+ value="org.simantics.sysdyn.ui.basicExperiment">\r
+ </equals>\r
+ </iterate>\r
</with>\r
</visibleWhen>\r
</command>\r
</toolbar>\r
</menuContribution>\r
+ <menuContribution\r
+ locationURI="toolbar:org.simantics.sysdyn.ui.trend.view">\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.trend.view.pin"\r
+ icon="icons/table_multiple_pinned.png"\r
+ label="Pin Trend"\r
+ style="toggle"\r
+ tooltip="Pins the trend so that it does not react to selection changes">\r
+ </command>\r
+ </menuContribution>\r
<menuContribution\r
locationURI="popup:#SysdynBrowserPopup?after=wbStart">\r
<dynamic\r
</command>\r
<command\r
defaultHandler="org.simantics.sysdyn.ui.actions.ToggleSimulation"\r
- id="org.simantics.sysdyn.ui.simulate"\r
+ id="org.simantics.sysdyn.ui.toggleSimulation"\r
name="Toggle Simulate">\r
<state\r
class="org.eclipse.jface.commands.ToggleState"\r
- id="org.simantics.sysdyn.ui.simulate.state">\r
+ id="org.simantics.sysdyn.ui.toggleSimulation.state">\r
</state>\r
</command>\r
<command\r
id="org.simantics.sysdyn.ui.newModel"\r
name="New Model">\r
</command>\r
+ <command\r
+ id="org.simantics.sysdyn.ui.activateExperiment"\r
+ name="Activate Experiment">\r
+ </command>\r
+ <command\r
+ defaultHandler="org.simantics.sysdyn.ui.handlers.RunBasicExperiment"\r
+ id="org.simantics.sysdyn.ui.run"\r
+ name="Run Basic Simulation">\r
+ </command>\r
+ <command\r
+ defaultHandler="org.simantics.sysdyn.ui.handlers.DisposeExperiment"\r
+ id="org.simantics.sysdyn.ui.dispose"\r
+ name="Quit Experiment">\r
+ </command>\r
+ <command\r
+ defaultHandler="org.simantics.sysdyn.ui.handlers.SaveResultsHandler"\r
+ id="org.simantics.sysdyn.ui.saveResults"\r
+ name="Save Results">\r
+ </command>\r
</extension>\r
<extension\r
point="org.eclipse.ui.handlers">\r
class="org.simantics.sysdyn.ui.browser.contributions.ModelChildren"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.Experiment"\r
+ preference="1.0">\r
+ </implementation>\r
</binding>\r
</extension>\r
<extension\r
class="org.simantics.sysdyn.ui.browser.contributions.OperatingInterfacesLabeler"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.ExperimentLabeler"\r
+ preference="2.0">\r
+ </implementation>\r
</binding>\r
</extension>\r
<extension\r
class="org.simantics.sysdyn.ui.browser.contributions.VariableImager"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.ExperimentImager"\r
+ preference="2.0">\r
+ </implementation>\r
</binding>\r
</extension>\r
<extension\r
properties="nodeClass"\r
type="org.eclipse.jface.viewers.IStructuredSelection">\r
</propertyTester>\r
+ </extension>\r
+ <extension\r
+ point="org.eclipse.ui.contexts">\r
+ <context\r
+ id="org.simantics.sysdyn.ui.basicExperiment"\r
+ name="Basic Experiment">\r
+ </context>\r
</extension>
</plugin>\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.actions;\r
\r
+\r
+import java.util.Map;\r
+\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.Command;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.eclipse.core.commands.ExecutionException;\r
import org.eclipse.core.commands.State;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.IEditorPart;\r
import org.eclipse.ui.PlatformUI;\r
import org.eclipse.ui.commands.ICommandService;\r
-import org.simantics.sysdyn.manager.SysdynModel;\r
-import org.simantics.sysdyn.manager.SysdynModelManager;\r
-import org.simantics.sysdyn.ui.editor.SysdynDiagramEditor;\r
+import org.eclipse.ui.commands.IElementUpdater;\r
+import org.eclipse.ui.menus.UIElement;\r
+import org.simantics.simulation.experiment.IDynamicExperiment;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.sysdyn.manager.SysdynExperiment;\r
+import org.simantics.sysdyn.ui.handlers.RunBasicExperiment;\r
import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.workbench.ResourceEditorInput;\r
\r
-public class ToggleSimulation extends AbstractHandler {\r
+public class ToggleSimulation extends AbstractHandler implements IElementUpdater {\r
\r
- public static final String COMMAND = "org.simantics.sysdyn.ui.simulate";\r
- public static final String STATE = "org.simantics.sysdyn.ui.simulate.state";\r
+ public static final String COMMAND = "org.simantics.sysdyn.ui.toggleSimulation";\r
+ public static final String STATE = "org.simantics.sysdyn.ui.toggleSimulation.state";\r
\r
@Override\r
public Object execute(ExecutionEvent event) throws ExecutionException {\r
Boolean value = (Boolean) state.getValue();\r
value = !value;\r
state.setValue(value);\r
- // If turned back on, simulate to apply any changes\r
- if(value) {\r
- IEditorPart editor =\r
- PlatformUI.getWorkbench()\r
- .getActiveWorkbenchWindow().getActivePage().getActiveEditor();\r
- if (editor instanceof SysdynDiagramEditor) {\r
- IEditorInput input = editor.getEditorInput();\r
- ResourceEditorInput rei = (ResourceEditorInput) input;\r
- SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession());\r
- SysdynModel model = sdm.getModel(rei.getResource());\r
- model.domainModified();\r
+ service.refreshElements(RunBasicExperiment.COMMAND, null);\r
+ \r
+ IExperimentManager manager = \r
+ SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+ IExperiment experiment = manager.getActiveExperiment();\r
+ if(experiment instanceof SysdynExperiment) {\r
+ if(getState()) {\r
+ ((SysdynExperiment)experiment).toggleSimulation(true);\r
+ } else {\r
+ ((SysdynExperiment)experiment).toggleSimulation(false);\r
}\r
}\r
+ \r
+ \r
return null;\r
}\r
\r
return (Boolean)state.getValue();\r
}\r
\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public void updateElement(UIElement element, Map parameters) {\r
+ ICommandService commandService =\r
+ (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
+ Command command = commandService.getCommand(COMMAND);\r
+ boolean checked = (Boolean) command.getState(STATE).getValue();\r
+ element.setChecked(checked);\r
+ }\r
}\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.browser.contributions;\r
\r
+import java.util.ArrayList;\r
import java.util.Collection;\r
-import java.util.Collections;\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.ExperimentsFolder;\r
\r
public class Experiment extends ViewpointContributor<ExperimentsFolder> {\r
\r
@Override\r
- public Collection<?> getContribution(ReadGraph graph, ExperimentsFolder input) throws DatabaseException {\r
- // hasExperiment or something\r
- return Collections.EMPTY_LIST;\r
+ public Collection<?> getContribution(ReadGraph graph, ExperimentsFolder experimentsFolder) throws DatabaseException {\r
+ ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
+ Builtins b = graph.getBuiltins();\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(experimentsFolder.resource, b.ConsistsOf, b.Experiment))) {\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
--- /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.ExperimentNode;\r
+\r
+public class ExperimentImager extends ImagerContributor<ExperimentNode> {\r
+ \r
+ @Override\r
+ public ImageDescriptor getDescriptor(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
+ return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/time.png"));\r
+ }\r
+\r
+}\r
public class ExperimentLabeler extends LabelerContributor<ExperimentNode>{\r
\r
@Override\r
- public String getLabel(ReadGraph graph, ExperimentNode input) throws DatabaseException {\r
- // TODO Auto-generated method stub\r
- return null;\r
+ public String getLabel(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
+ String name = graph.getPossibleRelatedValue(experiment.resource, graph.getBuiltins().HasName);\r
+ return name == null ? "Experiment (no name)" : name;\r
}\r
\r
}\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.browser.nodes;\r
\r
+import org.simantics.browsing.ui.common.node.IDoubleClickableNode;\r
import org.simantics.db.Resource;\r
+import org.simantics.project.IProject;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.sysdyn.ui.handlers.SysdynExperimentActivator;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ErrorLogger;\r
\r
-public class ExperimentNode extends AbstractNode {\r
+public class ExperimentNode extends AbstractNode implements IDoubleClickableNode{\r
\r
public ExperimentNode(Resource resource) {\r
super(resource);\r
}\r
\r
+ @Override\r
+ public boolean handleDoubleClick() {\r
+ if (resource == null)\r
+ return false;\r
+ IProject project = SimanticsUI.getProject();\r
+ IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+ if (experimentManager == null) {\r
+ ErrorLogger.defaultLogWarning("Experiment manager not available.", new Exception());\r
+ return false;\r
+ }\r
+ SysdynExperimentActivator.scheduleActivation(SimanticsUI.getSession(), project, experimentManager, resource);\r
+ return true;\r
+ }\r
+\r
}\r
variable = resource;\r
a.configuration = graph.getPossibleObject(variable, b.PartOf);\r
a.name = graph.getPossibleRelatedValue(resource, b.HasName);\r
- a.isVariable = graph.isInstanceOf(variable, sr.Auxiliary) ||\r
- graph.isInstanceOf(variable, sr.Stock) ||\r
- graph.isInstanceOf(variable, sr.Valve);\r
+ a.isVariable = graph.isInstanceOf(variable, sr.IndependentVariable);\r
if(a.name == null)\r
a.name = "";\r
return a;\r
unitSelector.clear(); // empty units\r
shortcutTabs.updateTables(variable);\r
expressionController.setExpressionTypes(null); \r
- nameComposite.setName(result.name);\r
+ nameComposite.setName("");\r
expressionComposite.resetExpressionView(variable);\r
}\r
}\r
--- /dev/null
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.simantics.project.IExperimentDescriptor;\r
+import org.simantics.project.IProject;\r
+import org.simantics.project.ProjectKeys;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class DisposeExperiment extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ IProject project = SimanticsUI.getProject();\r
+ IExperimentManager manager = \r
+ project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+ IExperiment experiment = manager.getActiveExperiment();\r
+ if (experiment != null)\r
+ experiment.shutdown();\r
+\r
+ /*\r
+ // Keep the UI happy.\r
+ IExperimentDescriptor ed = project.getHint(ProjectKeys.KEY_SELECTED_UI_EXPERIMENT);\r
+ if (ed != null) {\r
+ ed.getParent().removeHint(ProjectKeys.KEY_SELECTED_EXPERIMENT);\r
+ project.removeHint(ProjectKeys.KEY_SELECTED_UI_EXPERIMENT);\r
+ }\r
+ */\r
+ return null;\r
+ }\r
+\r
+}\r
SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
\r
@Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
+ public void perform(WriteGraph g) throws DatabaseException {\r
// Same as in SysdynProject.java. Should use the same code, not copy.\r
- Builtins b = graph.getBuiltins();\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
- ModelingUtils mu = new ModelingUtils(graph);\r
+ Builtins b = g.getBuiltins();\r
+ SysdynResource sr = SysdynResource.getInstance(g);\r
+ ModelingResources mr = ModelingResources.getInstance(g);\r
+ ModelingUtils mu = new ModelingUtils(g);\r
\r
- Resource model = graph.newResource();\r
- graph.claimValue(model, b.HasName, "Model1");\r
- graph.claimValue(model, b.HasLabel, "Model1");\r
- graph.claim(model, b.InstanceOf, sr.SysdynModel);\r
- graph.claim(model, b.PartOf, SimanticsUI.getProject().get());\r
+ Resource model = g.newResource();\r
+ g.claimValue(model, b.HasName, "Model1");\r
+ g.claimValue(model, b.HasLabel, "Model1");\r
+ g.claim(model, b.InstanceOf, sr.SysdynModel);\r
+ g.claim(model, b.PartOf, SimanticsUI.getProject().get());\r
\r
\r
- Resource diagram = OrderedSetUtils.create(graph, sr.ConfigurationDiagram);\r
- GraphLayer l = new GraphLayerUtil(graph).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
- graph.claim(diagram, mu.dr.HasLayer, l.getLayer());\r
- graph.claimValue(diagram, b.HasName, "Diagrammi", StringJavaBinding.INSTANCE);\r
+ Resource diagram = OrderedSetUtils.create(g, sr.ConfigurationDiagram);\r
+ GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
+ g.claim(diagram, mu.dr.HasLayer, l.getLayer());\r
+ g.claimValue(diagram, b.HasName, "Diagrammi", StringJavaBinding.INSTANCE);\r
\r
- Resource conf = GraphUtils.create2(graph, \r
+ Resource conf = GraphUtils.create2(g, \r
sr.Configuration,\r
b.HasName, "Configuration",\r
sr.HasStartTime, 0.0,\r
sr.HasStopTime, 10.0);\r
\r
- graph.claim(conf, mr.CompositeToDiagram, diagram);\r
- graph.claim(model, b.HasConfiguration, conf);\r
+ g.claim(conf, mr.CompositeToDiagram, diagram);\r
+ g.claim(model, b.HasConfiguration, conf);\r
\r
- Resource mapping = graph.newResource();\r
- graph.claim(mapping, b.InstanceOf, null, sr.DiagramToCompositeMapping);\r
- graph.claim(diagram, b.HasTrigger, mapping);\r
+ Resource mapping = g.newResource();\r
+ g.claim(mapping, b.InstanceOf, null, sr.DiagramToCompositeMapping);\r
+ g.claim(diagram, b.HasTrigger, mapping);\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.HasReportFactory, report,\r
+ mu.b.PartOf, model);\r
}\r
});\r
return null;\r
--- /dev/null
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+\r
+import java.util.Map;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.Command;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.commands.ICommandService;\r
+import org.eclipse.ui.commands.IElementUpdater;\r
+import org.eclipse.ui.menus.UIElement;\r
+import org.simantics.simulation.experiment.IDynamicExperiment;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.sysdyn.ui.actions.ToggleSimulation;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class RunBasicExperiment extends AbstractHandler implements IElementUpdater {\r
+ \r
+ public static final String COMMAND = "org.simantics.sysdyn.ui.run";\r
+ \r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ IExperimentManager manager = \r
+ SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+ IExperiment experiment = manager.getActiveExperiment();\r
+ if(experiment instanceof IDynamicExperiment)\r
+ ((IDynamicExperiment)experiment).simulate(true);\r
+ return null;\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public void updateElement(UIElement element, Map parameters) {\r
+ ICommandService commandService =\r
+ (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
+ Command command = commandService.getCommand(ToggleSimulation.COMMAND);\r
+ boolean checked = (Boolean) command.getState(ToggleSimulation.STATE).getValue();\r
+ if(checked)\r
+ this.setBaseEnabled(false);\r
+ else\r
+ this.setBaseEnabled(true);\r
+\r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.simantics.simulation.experiment.IDynamicExperiment;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class SaveResultsHandler extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ IExperimentManager manager = \r
+ SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+ IExperiment experiment = manager.getActiveExperiment();\r
+ if(experiment instanceof IDynamicExperiment) {\r
+ ((IDynamicExperiment)experiment).saveState();\r
+ }\r
+ return null;\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import java.util.concurrent.Semaphore;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\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.simantics.db.ReadGraph;\r
+import org.simantics.db.RequestProcessor;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.AdaptionException;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.message.MessageService;\r
+import org.simantics.project.IExperimentDescriptor;\r
+import org.simantics.project.IModelDescriptor;\r
+import org.simantics.project.IProject;\r
+import org.simantics.project.IProjectElement;\r
+import org.simantics.project.ProjectKeys;\r
+import org.simantics.project.exception.ProjectException;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.model.ExperimentLoadingFailed;\r
+import org.simantics.simulation.project.IExperimentActivationListener;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.sysdyn.ui.listeners.SysdynExperimentManagerListener;\r
+import org.simantics.utils.DataContainer;\r
+import org.simantics.utils.ui.ErrorLogger;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+import org.simantics.utils.ui.dialogs.ShowMessage;\r
+\r
+public class SysdynExperimentActivator {\r
+ /**\r
+ * @param project\r
+ * @param experimentManager\r
+ * @param experiment\r
+ */\r
+ public static void scheduleActivation(RequestProcessor processor, final IProject project, final IExperimentManager experimentManager, final Resource experiment) {\r
+ String jobName = "Activate Experiment";\r
+ String experimentName = getName(processor, experiment);\r
+ if (experimentName != null)\r
+ jobName += " '" + experimentName + "'";\r
+\r
+ scheduleActivation(jobName, project, experimentManager, experiment);\r
+ }\r
+\r
+ /**\r
+ * @param project\r
+ * @param experimentManager\r
+ * @param experiment\r
+ */\r
+ public static void scheduleActivation(String jobName, final IProject project, final IExperimentManager experimentManager, final Resource experiment) {\r
+ new Job(jobName) {\r
+ @Override\r
+ protected IStatus run(final IProgressMonitor monitor) {\r
+ return SysdynExperimentActivator.activate(monitor, project, experimentManager, experiment);\r
+ }\r
+ }.schedule();\r
+ }\r
+\r
+ public static IStatus activate(IProgressMonitor monitor, IProject project, IExperimentManager experimentManager, Resource experiment) {\r
+ return new SysdynExperimentActivator().activateExperiment(monitor, project, experimentManager, experiment);\r
+ }\r
+\r
+ private static String getName(RequestProcessor processor, final Resource resource) {\r
+ try {\r
+ return processor.syncRequest(new Read<String>() {\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ try {\r
+ return graph.adapt(resource, String.class);\r
+ } catch (AdaptionException e) {\r
+ return GraphUtils.getReadableName(graph, resource);\r
+ }\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ ErrorLogger.defaultLogWarning(e);\r
+ return null;\r
+ }\r
+ }\r
+\r
+ private IStatus activateExperiment(final IProgressMonitor monitor, final IProject project, final IExperimentManager manager, final Resource experimentResource) {\r
+ monitor.beginTask("Activating experiment", IProgressMonitor.UNKNOWN);\r
+ try {\r
+ SysdynExperimentManagerListener.listenManager(manager);\r
+ final Semaphore activated = new Semaphore(0);\r
+ final DataContainer<Throwable> problem = new DataContainer<Throwable>();\r
+ manager.startExperiment(experimentResource, new IExperimentActivationListener() {\r
+ \r
+ @Override\r
+ public void onExperimentActivated(final IExperiment experiment) {\r
+\r
+ MessageService.defaultLog(new org.eclipse.core.runtime.Status(IStatus.INFO, "org.simantics.simulation.ui", 0, "Activated experiment " + experiment.getIdentifier() , null));\r
+ \r
+ \r
+ activated.release();\r
+ // Set the selected experiment into the the model descriptor.\r
+ new Thread("Set Selected Experiment") {\r
+ @Override\r
+ public void run() {\r
+ setSelectedExperiment(project, experimentResource);\r
+ }\r
+ }.start();\r
+ }\r
+ @Override\r
+ public void onFailure(Throwable e) {\r
+ problem.set(e);\r
+ activated.release();\r
+ }\r
+ @Override\r
+ public void onMessage(IStatus message) {\r
+ MessageService.getDefault().log(message);\r
+ /*ILogger logger = MessageService.getDefault();\r
+ MultiStatus init = new MultiStatus(Activator.PLUGIN_ID, 0, "Activating experiment", null);\r
+ for (String msg : messages) {\r
+ init.add(new Status(IStatus.INFO, Activator.PLUGIN_ID, msg));\r
+ }\r
+ logger.log(init);*/\r
+ }\r
+ }, true);\r
+ try {\r
+ activated.acquire();\r
+ Throwable t = problem.get();\r
+ if (t != null) {\r
+ if (t instanceof ExperimentLoadingFailed) {\r
+ ErrorLogger.defaultLogError(t);\r
+ ShowMessage.showError("Experiment Activation Failed", t.getMessage());\r
+ } else {\r
+ ExceptionUtils.logAndShowError(t);\r
+ }\r
+ }\r
+ \r
+ return Status.OK_STATUS;\r
+ //return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Experiment activation failed, see exception for details.", problem.get());\r
+ } catch (InterruptedException e) {\r
+ return Status.CANCEL_STATUS;\r
+ }\r
+ } finally {\r
+ monitor.done();\r
+ }\r
+ }\r
+\r
+ private void setSelectedExperiment(IProject project, Resource experiment) {\r
+ try {\r
+ for (IProjectElement model : project.members()) {\r
+ if (model instanceof IModelDescriptor) {\r
+ for (IProjectElement member : ((IModelDescriptor) model).members()) {\r
+ if (member instanceof IExperimentDescriptor && experiment.equals(member.get())) {\r
+ model.setHint(ProjectKeys.KEY_SELECTED_EXPERIMENT, member);\r
+ project.setHint(ProjectKeys.KEY_SELECTED_UI_EXPERIMENT, member);\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ } catch (ProjectException e) {\r
+ ErrorLogger.defaultLogError(e);\r
+ }\r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.listeners;\r
+\r
+import org.eclipse.core.commands.Command;\r
+import org.eclipse.core.commands.State;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.commands.ICommandService;\r
+import org.eclipse.ui.contexts.IContextActivation;\r
+import org.simantics.simulation.experiment.ExperimentState;\r
+import org.simantics.simulation.experiment.IExperimentListener;\r
+import org.simantics.sysdyn.ui.actions.ToggleSimulation;\r
+import org.simantics.sysdyn.ui.handlers.RunBasicExperiment;\r
+\r
+public class SysdynExperimentListener implements IExperimentListener {\r
+\r
+ IContextActivation contextActivation;\r
+\r
+ @Override\r
+ public void stateChanged(final ExperimentState state) {\r
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ ICommandService commandService =\r
+ (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
+ Command command = commandService.getCommand(ToggleSimulation.COMMAND);\r
+ State buttonState = command.getState(ToggleSimulation.STATE);\r
+ \r
+ switch(state) {\r
+ case DISPOSED:\r
+ buttonState.setValue(false); \r
+ break;\r
+ }\r
+ commandService.refreshElements(command.getId(), null); \r
+ commandService.refreshElements(RunBasicExperiment.COMMAND, null);\r
+ }\r
+ \r
+ });\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.listeners;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import org.eclipse.ui.IWorkbench;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.contexts.IContextActivation;\r
+import org.eclipse.ui.contexts.IContextService;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.simulation.project.IExperimentManagerListener;\r
+\r
+public class SysdynExperimentManagerListener implements IExperimentManagerListener{\r
+\r
+ public static final String BASIC_EXPERIMENT_CONTEXT = "org.simantics.sysdyn.ui.basicExperiment";\r
+ \r
+ static Set<IExperimentManager> managers = \r
+ new HashSet<IExperimentManager>();\r
+ \r
+ IExperimentManager manager;\r
+ \r
+ Collection<IContextActivation> contextActivations = \r
+ new ArrayList<IContextActivation>();\r
+ \r
+ public SysdynExperimentManagerListener(IExperimentManager manager) {\r
+ this.manager = manager;\r
+ }\r
+\r
+ public static void listenManager(IExperimentManager manager) {\r
+ synchronized(managers) {\r
+ if(managers.contains(manager))\r
+ return;\r
+ SysdynExperimentManagerListener listener = \r
+ new SysdynExperimentManagerListener(manager);\r
+ manager.addListener(listener);\r
+ managers.add(manager);\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public void activeExperimentLoaded(final IExperiment experiment) { \r
+ experiment.addListener(new SysdynExperimentListener());\r
+\r
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ IContextService contextService =\r
+ (IContextService)PlatformUI.getWorkbench()\r
+ .getActiveWorkbenchWindow().getService(IContextService.class);\r
+ synchronized(contextActivations) {\r
+ contextActivations.add(contextService.activateContext(BASIC_EXPERIMENT_CONTEXT));\r
+ }\r
+ }\r
+ \r
+ });\r
+ }\r
+\r
+ @Override\r
+ public void activeExperimentUnloaded() {\r
+ \r
+ synchronized(contextActivations) {\r
+ final Collection<IContextActivation> oldContextActivations = \r
+ contextActivations;\r
+ \r
+ contextActivations = new ArrayList<IContextActivation>();\r
+ \r
+ final IWorkbench workbench = PlatformUI.getWorkbench();\r
+ workbench.getDisplay().asyncExec(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ if (workbench.isClosing())\r
+ return;\r
+ \r
+ IContextService contextService =\r
+ (IContextService)workbench.getActiveWorkbenchWindow().getService(IContextService.class);\r
+ contextService.deactivateContexts(oldContextActivations); \r
+ }\r
+ \r
+ });\r
+ }\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void managerDisposed() {\r
+ synchronized(managers) {\r
+ managers.remove(manager);\r
+ }\r
+ }\r
+\r
+}\r
import org.simantics.diagram.DiagramConstants;\r
import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.modeling.ModelingUtils;\r
import org.simantics.project.ProjectElementType;\r
Resource mapping = g.newResource();\r
g.claim(mapping, b.InstanceOf, null, mr.DiagramToCompositeMapping);\r
g.claim(diagram, b.HasTrigger, mapping);\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.HasReportFactory, report,\r
+ mu.b.PartOf, model);\r
+ \r
callback.run(model);\r
} catch(Exception e) {\r
errorCallback.run(e);\r
--- /dev/null
+package org.simantics.sysdyn.ui.project;\r
+\r
+import java.util.Timer;\r
+\r
+import org.simantics.databoard.accessor.Accessor;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.RequestProcessor;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.VirtualGraph;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.procedure.single.SingleSetListener;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.ActivationManager;\r
+import org.simantics.db.layer0.adapter.RuntimeValuations;\r
+import org.simantics.db.layer0.adapter.TrendVariable;\r
+import org.simantics.db.layer0.adapter.ValuationVirtualGraph;\r
+import org.simantics.db.layer0.util.Simantics;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.db.service.VirtualGraphSupport;\r
+import org.simantics.project.IProject;\r
+import org.simantics.project.IProjectLifeCycle;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
+\r
+public class SysdynProjectLifeCycle implements IProjectLifeCycle{\r
+\r
+ public static final Key INITIALIZED = new KeyOf(Boolean.class, "SYSDYN_LIFECYCLE_INITIALIZED");\r
+\r
+ static Timer timer = new Timer();\r
+\r
+ @Override\r
+ public void onCreate(WriteGraph g, Resource project) {\r
+// System.out.println("onCreate Apros Project: " + GraphUtils.getReadableName(g, project));\r
+ }\r
+\r
+ @Override\r
+ public void onDestroy(WriteGraph g, Resource project) {\r
+// System.out.println("onDestroy Apros Project: " + GraphUtils.getReadableName(g, project));\r
+ }\r
+\r
+ @Override\r
+ public void onActivated(RequestProcessor processor, final IProject project) {\r
+\r
+// System.out.println("onActivated DEVS Project");\r
+\r
+ ISessionContext context = SimanticsUI.getSessionContext();\r
+ if (context.getHint(INITIALIZED) == null) {\r
+\r
+ try {\r
+\r
+ Resource projectResource = project.get();\r
+\r
+ final Session session = context.getSession();\r
+\r
+ session.registerService(RuntimeValuations.class, new RuntimeValuations() {\r
+\r
+ @Override\r
+ public boolean supports(String valuation) {\r
+\r
+ IExperimentManager expMan = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+ IExperiment experiment = expMan.getExperiment(valuation);\r
+\r
+ return experiment != null;\r
+\r
+ }\r
+\r
+ @Override\r
+ public Accessor getAccessor(String variableIdentityPrefix, String valuation, String suffix) {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public TrendVariable getVariable(String variableIdentityPrefix, String valuation, String suffix) {\r
+\r
+ return null;\r
+\r
+ }\r
+\r
+ });\r
+\r
+\r
+// System.out.println("A1");\r
+\r
+ Builtins b = session.getBuiltins();\r
+ ActivationManager activationManager = session.getService(ActivationManager.class);\r
+ if (activationManager != null) {\r
+ activationManager.activate(processor, projectResource);\r
+ }\r
+\r
+// System.out.println("A2");\r
+\r
+ VirtualGraphSupport support = session.getService(VirtualGraphSupport.class);\r
+ final VirtualGraph graph = support.create();\r
+ session.registerService(VirtualGraph.class, graph);\r
+\r
+// System.out.println("A3");\r
+\r
+ session.asyncRequest(new ObjectsWithType(projectResource, b.ConsistsOf, b.Model), new SingleSetListener<Resource>() {\r
+\r
+ @Override\r
+ public void add(final Resource model) {\r
+ // FIXME:\r
+// System.out.println("A4");\r
+ Simantics.async(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ try {\r
+// System.out.println("A5 " + model);\r
+ graph.register(new ValuationVirtualGraph(session, model));\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public void exception(Throwable t) {\r
+ t.printStackTrace();\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return false;\r
+ }\r
+\r
+ });\r
+\r
+ support.resume("experiments");\r
+\r
+ } catch (DatabaseException e) {\r
+\r
+ e.printStackTrace();\r
+\r
+ }\r
+\r
+\r
+\r
+ context.setHint(INITIALIZED, Boolean.TRUE);\r
+\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public void onDeactivated(IProject project) {\r
+// System.out.println("onDeactivated Apros Project: " + project.getName());\r
+ }\r
+}\r
import org.simantics.sysdyn.manager.SysdynModelManager;\r
import org.simantics.sysdyn.representation.IElement;\r
import org.simantics.sysdyn.representation.Variable;\r
-import org.simantics.sysdyn.ui.simulation.SimulationScheduler;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.ui.ISelectionUtils;\r
import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
if(model == null) {\r
model = \r
SysdynModelManager.getInstance(g.getSession()).getModel(g, configuration);\r
- SimulationScheduler.start(model);\r
+ // SimulationScheduler.start(model); Don't want this to operate simulation\r
model.addResultListener(updater);\r
models.put(configuration, model);\r
}\r
Resource configuration = g.getPossibleObject(resource, b.PartOf);\r
if(g.isInstanceOf(configuration, sr.Configuration)) {\r
SysdynModel model = getModel(g, configuration);\r
+ if(model == null)\r
+ return null;\r
IElement element = model.getElement(resource);\r
if(element instanceof Variable) {\r
Variable var = (Variable)element; \r
Require-Bundle: org.simantics.objmap;bundle-version="0.1.0",
org.simantics.db;bundle-version="0.6.2",
org.simantics.modelica;bundle-version="1.0.0",
- org.simantics.db.common;bundle-version="0.8.0"
+ org.simantics.db.common;bundle-version="0.8.0",
+ org.simantics.simulation;bundle-version="1.0.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"
Export-Package: org.simantics.sysdyn,
org.simantics.sysdyn.expressionParser,
org.simantics.sysdyn.manager,
org.simantics.sysdyn.modelica,
org.simantics.sysdyn.representation,
org.simantics.sysdyn.representation.visitors,
+ org.simantics.sysdyn.simulation,
org.simantics.sysdyn.tableParser
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!--\r
+ Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ in Industry THTH ry.\r
+ All rights reserved. This program and the accompanying materials\r
+ are made available under the terms of the Eclipse Public License v1.0\r
+ which accompanies this distribution, and is available at\r
+ http://www.eclipse.org/legal/epl-v10.html\r
+ \r
+ Contributors:\r
+ VTT Technical Research Centre of Finland - initial API and implementation\r
+ -->\r
+\r
+<adapters> \r
+ <target\r
+ interface="org.simantics.simulation.model.IModel">\r
+ <type\r
+ uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r
+ class="org.simantics.sysdyn.manager.SysdynModel">\r
+ <this />\r
+ </type>\r
+ </target>\r
+</adapters>
\ No newline at end of file
\r
public final Resource Auxiliary;\r
public final Resource AuxiliarySymbol;\r
+ public final Resource BasicExperiment;\r
public final Resource Cloud;\r
public final Resource Configuration;\r
public final Resource ConfigurationDiagram;\r
public final Resource DelayExpression;\r
public final Resource Dependency;\r
public final Resource DiagramToCompositeMapping;\r
+ public final Resource Experiment;\r
public final Resource Expression;\r
public final Resource Flow;\r
+ public final Resource GameExperiment;\r
public final Resource HasAngle;\r
public final Resource HasEquation;\r
public final Resource HasExpression;\r
public final Resource ParameterExpression;\r
public final Resource PhantomTerminal;\r
public final Resource RefersTo;\r
+ public final Resource SimulateOnChangeExperiment;\r
public final Resource Stock;\r
public final Resource StockExpression;\r
public final Resource StockSymbol;\r
public final Resource SysdynConnectionType;\r
public final Resource SysdynModel;\r
+ public final Resource SysdynModelManager;\r
public final Resource SysdynProject;\r
public final Resource SysdynSymbols;\r
public final Resource Terminal;\r
public static class URIs {\r
public static final String Auxiliary = "http://www.simantics.org/Sysdyn-1.0/Auxiliary";\r
public static final String AuxiliarySymbol = "http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol";\r
+ public static final String BasicExperiment = "http://www.simantics.org/Sysdyn-1.0/BasicExperiment";\r
public static final String Cloud = "http://www.simantics.org/Sysdyn-1.0/Cloud";\r
public static final String Configuration = "http://www.simantics.org/Sysdyn-1.0/Configuration";\r
public static final String ConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagram";\r
public static final String DelayExpression = "http://www.simantics.org/Sysdyn-1.0/DelayExpression";\r
public static final String Dependency = "http://www.simantics.org/Sysdyn-1.0/Dependency";\r
public static final String DiagramToCompositeMapping = "http://www.simantics.org/Sysdyn-1.0/DiagramToCompositeMapping";\r
+ public static final String Experiment = "http://www.simantics.org/Sysdyn-1.0/Experiment";\r
public static final String Expression = "http://www.simantics.org/Sysdyn-1.0/Expression";\r
public static final String Flow = "http://www.simantics.org/Sysdyn-1.0/Flow";\r
+ public static final String GameExperiment = "http://www.simantics.org/Sysdyn-1.0/GameExperiment";\r
public static final String HasAngle = "http://www.simantics.org/Sysdyn-1.0/HasAngle";\r
public static final String HasEquation = "http://www.simantics.org/Sysdyn-1.0/HasEquation";\r
public static final String HasExpression = "http://www.simantics.org/Sysdyn-1.0/HasExpression";\r
public static final String ParameterExpression = "http://www.simantics.org/Sysdyn-1.0/ParameterExpression";\r
public static final String PhantomTerminal = "http://www.simantics.org/Sysdyn-1.0/PhantomTerminal";\r
public static final String RefersTo = "http://www.simantics.org/Sysdyn-1.0/RefersTo";\r
+ public static final String SimulateOnChangeExperiment = "http://www.simantics.org/Sysdyn-1.0/SimulateOnChangeExperiment";\r
public static final String Stock = "http://www.simantics.org/Sysdyn-1.0/Stock";\r
public static final String StockExpression = "http://www.simantics.org/Sysdyn-1.0/StockExpression";\r
public static final String StockSymbol = "http://www.simantics.org/Sysdyn-1.0/StockSymbol";\r
public static final String SysdynConnectionType = "http://www.simantics.org/Sysdyn-1.0/SysdynConnectionType";\r
public static final String SysdynModel = "http://www.simantics.org/Sysdyn-1.0/SysdynModel";\r
+ public static final String SysdynModelManager = "http://www.simantics.org/Sysdyn-1.0/SysdynModelManager";\r
public static final String SysdynProject = "http://www.simantics.org/Sysdyn-1.0/SysdynProject";\r
public static final String SysdynSymbols = "http://www.simantics.org/Sysdyn-1.0/SysdynSymbols";\r
public static final String Terminal = "http://www.simantics.org/Sysdyn-1.0/Terminal";\r
public SysdynResource(ReadGraph graph) {\r
Auxiliary = getResourceOrNull(graph, URIs.Auxiliary);\r
AuxiliarySymbol = getResourceOrNull(graph, URIs.AuxiliarySymbol);\r
+ BasicExperiment = getResourceOrNull(graph, URIs.BasicExperiment);\r
Cloud = getResourceOrNull(graph, URIs.Cloud);\r
Configuration = getResourceOrNull(graph, URIs.Configuration);\r
ConfigurationDiagram = getResourceOrNull(graph, URIs.ConfigurationDiagram);\r
DelayExpression = getResourceOrNull(graph, URIs.DelayExpression);\r
Dependency = getResourceOrNull(graph, URIs.Dependency);\r
DiagramToCompositeMapping = getResourceOrNull(graph, URIs.DiagramToCompositeMapping);\r
+ Experiment = getResourceOrNull(graph, URIs.Experiment);\r
Expression = getResourceOrNull(graph, URIs.Expression);\r
Flow = getResourceOrNull(graph, URIs.Flow);\r
+ GameExperiment = getResourceOrNull(graph, URIs.GameExperiment);\r
HasAngle = getResourceOrNull(graph, URIs.HasAngle);\r
HasEquation = getResourceOrNull(graph, URIs.HasEquation);\r
HasExpression = getResourceOrNull(graph, URIs.HasExpression);\r
ParameterExpression = getResourceOrNull(graph, URIs.ParameterExpression);\r
PhantomTerminal = getResourceOrNull(graph, URIs.PhantomTerminal);\r
RefersTo = getResourceOrNull(graph, URIs.RefersTo);\r
+ SimulateOnChangeExperiment = getResourceOrNull(graph, URIs.SimulateOnChangeExperiment);\r
Stock = getResourceOrNull(graph, URIs.Stock);\r
StockExpression = getResourceOrNull(graph, URIs.StockExpression);\r
StockSymbol = getResourceOrNull(graph, URIs.StockSymbol);\r
SysdynConnectionType = getResourceOrNull(graph, URIs.SysdynConnectionType);\r
SysdynModel = getResourceOrNull(graph, URIs.SysdynModel);\r
+ SysdynModelManager = getResourceOrNull(graph, URIs.SysdynModelManager);\r
SysdynProject = getResourceOrNull(graph, URIs.SysdynProject);\r
SysdynSymbols = getResourceOrNull(graph, URIs.SysdynSymbols);\r
Terminal = getResourceOrNull(graph, URIs.Terminal);\r
--- /dev/null
+package org.simantics.sysdyn.manager;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\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.simulation.experiment.Experiment;\r
+import org.simantics.simulation.experiment.ExperimentState;\r
+import org.simantics.simulation.experiment.IDynamicExperiment;\r
+import org.simantics.sysdyn.simulation.SimulationScheduler;\r
+\r
+public class SysdynExperiment extends Experiment implements IDynamicExperiment {\r
+\r
+ Session session;\r
+ Runnable modificationListener;\r
+\r
+ public SysdynExperiment(Resource model) {\r
+ super(model);\r
+ // TODO Auto-generated constructor stub\r
+ }\r
+\r
+ @Override\r
+ public void rewindTo(double time) {\r
+ // TODO Auto-generated method stub\r
+ System.out.println("rewindTo");\r
+ }\r
+\r
+ @Override\r
+ public void saveState() {\r
+ // TODO Auto-generated method stub\r
+ System.out.println("saveState");\r
+ }\r
+\r
+ /**\r
+ * enabled: is simulate on change enabled\r
+ */\r
+ @Override\r
+ public void simulate(boolean enabled) {\r
+ System.out.println("simulate");\r
+ if(enabled) {\r
+ changeState(ExperimentState.STOPPED);\r
+ session.asyncRequest(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
+ });\r
+ }\r
+\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
+ } \r
+ }\r
+ else {\r
+ changeState(ExperimentState.STOPPED); \r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public void simulateDuration(double duration) {\r
+ // TODO Auto-generated method stub\r
+ System.out.println("simulateDuartion");\r
+ }\r
+\r
+ @Override\r
+ public void refresh(Session session) {\r
+ // TODO Auto-generated method stub\r
+ System.out.println("refresh");\r
+ }\r
+\r
+ public void init(ReadGraph g) {\r
+ System.out.println("init");\r
+ changeState(ExperimentState.STOPPED);\r
+ this.session = g.getSession();\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
+ @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
+ sysdynmodel.removeModificationListener(modificationListener);\r
+ modificationListener = null;\r
+ \r
+ }\r
+ });\r
+ break;\r
+ }\r
+ }\r
+\r
+\r
+}\r
import org.simantics.objmap.IMapping;\r
import org.simantics.objmap.IMappingListener;\r
import org.simantics.objmap.Mappings;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.model.IModel;\r
+import org.simantics.simulation.project.IExperimentActivationListener;\r
import org.simantics.sysdyn.modelica.ModelicaWriter;\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.IElement;\r
* Maintains a Java representation of system dynamic model.\r
* @author Hannu Niemistö\r
*/\r
-public class SysdynModel implements IMappingListener {\r
+public class SysdynModel implements IMappingListener, IModel {\r
\r
Session session;\r
Resource configurationResource; \r
e.printStackTrace();\r
}\r
}\r
+ \r
+ \r
+ /*\r
+ * some dummy(?) stuff for experiments\r
+ */\r
+ public SysdynModel(Resource configurationResource) {\r
+ this.configurationResource = configurationResource; \r
+ }\r
\r
public synchronized void simulate(IModelicaMonitor monitor) throws IOException {\r
try {\r
}\r
}\r
\r
+ @Override\r
+ public IExperiment loadExperiment(ReadGraph g, Resource experiment, IExperimentActivationListener listener) {\r
+ SysdynExperiment exp = new SysdynExperiment(configurationResource);\r
+ try {\r
+ exp.init(g);\r
+ listener.onExperimentActivated(exp);\r
+ return exp;\r
+ } catch(Exception e) {\r
+ listener.onFailure(e);\r
+ return null;\r
+ }\r
+ } \r
}\r
* Contributors:\r
* VTT Technical Research Centre of Finland - initial API and implementation\r
*******************************************************************************/\r
-package org.simantics.sysdyn.ui.simulation;\r
+package org.simantics.sysdyn.simulation;\r
\r
import org.eclipse.core.runtime.IProgressMonitor;\r
import org.eclipse.core.runtime.IStatus;\r
import org.eclipse.ui.console.MessageConsoleStream;\r
import org.simantics.modelica.IModelicaMonitor;\r
import org.simantics.sysdyn.manager.SysdynModel;\r
-import org.simantics.sysdyn.ui.actions.ToggleSimulation;\r
\r
public class SimulationJob extends Job {\r
\r
this.monitor.clearConsole();\r
try {\r
model.update();\r
- if(ToggleSimulation.getState())\r
- model.simulate(this.monitor);\r
+ model.simulate(this.monitor);\r
} catch (Exception e) {\r
e.printStackTrace();\r
return new Status(\r
* Contributors:\r
* VTT Technical Research Centre of Finland - initial API and implementation\r
*******************************************************************************/\r
-package org.simantics.sysdyn.ui.simulation;\r
+package org.simantics.sysdyn.simulation;\r
\r
import org.simantics.sysdyn.manager.SysdynModel;\r
\r
\r
private void start() {\r
job.schedule();\r
+ /*\r
+ * Don't want this behavior. Use this in simulate on change or somewhere\r
model.addModificationListener(new Runnable() {\r
\r
@Override\r
}\r
\r
});\r
+ */\r
}\r
\r
public static synchronized SimulationScheduler start(SysdynModel model) {\r
scheduler = new SimulationScheduler(model);\r
model.addService(SimulationScheduler.class, scheduler);\r
scheduler.start();\r
+ } else {\r
+ scheduler.start();\r
}\r
return scheduler;\r
}\r
Symbols : L0.Library\r
\r
SysdynProject : PROJ.Feature\r
+ PROJ.LifecycleFeature\r
+ SysdynProject\r
L0.HasLabel "System Dynamics Project" : L0.String\r
L0.HasDescription """System dynamics modelling project. Create system dynamics models and simulate them with OpenModelica.""" : L0.String\r
L0.PartOf Sysdyn\r
PROJ.RequiresNamespace\r
"http://www.simantics.org/Sysdyn-1.0" : L0.URI\r
SysdynSymbols\r
+ PROJ.ExperimentControl\r
+ SysdynModelManager : PROJ.Feature\r
+ L0.PartOf Sysdyn\r
+ L0.HasLabel "Sysdyn Model Manager" : L0.String\r
+ L0.HasDescription "Sysdyn Model Manager." : L0.String\r
+ PROJ.RequiresFeature MOD.ModelingProject\r
+ PROJ.RequiresFeature PROJ.ExperimentControl\r
\r
SysdynSymbols : PROJ.Feature\r
L0.PartOf Sysdyn\r
[HasMaxY card "1"]\r
\r
\r
+######################################################################\r
+# Experiments\r
+######################################################################\r
+ \r
+Experiment <T L0.Entity\r
+\r
+BasicExperiment <T Experiment\r
+\r
+GameExperiment <T Experiment\r
+\r
+SimulateOnChangeExperiment <T Experiment\r
+\r
######################################################################\r
# Symbols\r
######################################################################\r