org.simantics.db.indexing;bundle-version="1.1.0",
org.simantics.workbench,
org.simantics.annotation.ui;bundle-version="1.0.0",
- org.simantics.annotation.ontology;bundle-version="1.0.0"
+ org.simantics.annotation.ontology;bundle-version="1.0.0",
+ org.simantics.spreadsheet.common;bundle-version="1.1.0"
Bundle-Activator: org.simantics.sysdyn.ui.Activator
Bundle-ActivationPolicy: lazy
Export-Package: org.simantics.sysdyn.ui.browser.nodes
ifEmpty="false"\r
operator="or">\r
<equals\r
- value="org.simantics.sysdyn.ui.basicExperiment">\r
+ value="org.simantics.sysdyn.ui.gameExperiment">\r
+ </equals>\r
+ </iterate>\r
+ </with>\r
+ </visibleWhen>\r
+ </command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.saveHistory"\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/table_save.png"\r
+ id="org.simantics.sysdyn.ui.savehistory.button"\r
+ label="Save History">\r
+ <visibleWhen>\r
+ <with\r
+ variable="activeContexts">\r
+ <iterate\r
+ ifEmpty="false"\r
+ operator="or">\r
+ <equals\r
+ value="org.simantics.sysdyn.ui.gameExperiment">\r
</equals>\r
</iterate>\r
</with>\r
checkEnabled="true">\r
<with\r
variable="selection">\r
+ <or>\r
<test\r
args="http://www.simantics.org/Layer0-0.0/Library"\r
property="org.simantics.graph.resourceType"\r
value="true">\r
</test>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ModelNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </or>\r
</with>\r
</visibleWhen>\r
</command>\r
<command\r
commandId="org.simantics.sysdyn.ui.newModuleNode"\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/bricks.png"\r
id="org.simantics.sysdyn.ui.browser.newModule"\r
label="Module type"\r
style="push">\r
label="Export">\r
<command\r
commandId="org.simantics.sysdyn.ui.exportSharedOntology"\r
- icon="platform:/plugin/com.famfamfam.silk/icons/application_form.png"\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/folder.png"\r
id="org.simantics.sysdyn.ui.exportSharedOntology"\r
label="Shared Library"\r
style="push">\r
variable="selection">\r
<or>\r
<test\r
- args="org.simantics.sysdyn.ui.browser.contributions.SharedOntologyNode"\r
+ args="org.simantics.sysdyn.ui.browser.nodes.SharedOntologyNode"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
</test>\r
</or>\r
id="org.simantics.sysdyn.ui.saveIC"\r
name="Save Initial Condition">\r
</command>\r
+ <command\r
+ defaultHandler="org.simantics.sysdyn.ui.handlers.SaveHistoryHandler"\r
+ id="org.simantics.sysdyn.ui.saveHistory"\r
+ name="Save History">\r
+ </command>\r
<command\r
defaultHandler="org.simantics.sysdyn.ui.handlers.ToggleResultActivation"\r
id="org.simantics.sysdyn.ui.activateResult"\r
<with\r
variable="selection">\r
<or>\r
- <test\r
- args="http://www.simantics.org/Layer0-0.0/Library"\r
- property="org.simantics.graph.resourceType"\r
- value="true">\r
- </test>\r
+ <test\r
+ args="http://www.simantics.org/Layer0-0.0/Library"\r
+ property="org.simantics.graph.resourceType"\r
+ value="true">\r
+ </test>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ModelNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
</or>\r
</with>\r
</activeWhen>\r
variable="selection">\r
<or>\r
<test\r
- args="org.simantics.sysdyn.ui.browser.contributions.SharedOntologyNode"\r
+ args="org.simantics.sysdyn.ui.browser.nodes.SharedOntologyNode"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
</test>\r
</or>\r
preference="2.0">\r
</implementation>\r
<implementation\r
- class="org.simantics.sysdyn.ui.browser.contributions.LibraryContribution"\r
+ class="org.simantics.sysdyn.ui.browser.contributions.AnnotationContribution2"\r
preference="2.0">\r
</implementation>\r
<implementation\r
- class="org.simantics.sysdyn.ui.browser.contributions.SharedOntology"\r
+ class="org.simantics.sysdyn.ui.browser.contributions.LibraryContribution"\r
preference="2.0">\r
</implementation>\r
<implementation\r
else if (node instanceof ModuleTypeNode || node instanceof ModuleNode || node instanceof ConfigurationNode)\r
image = "icons/bricks.png";\r
else if (node instanceof SCLModule)\r
- image = "icons/bullet_gray.png";\r
+ image = "icons/box.png";\r
else if (node instanceof InitialCondition)\r
image = "icons/table.png";\r
else if (node instanceof ExperimentNode) {\r
\r
ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ \r
if(node instanceof ISpecialFolder) return result;\r
\r
- Layer0 L0 = Layer0.getInstance(graph);\r
AnnotationResource ANNO = AnnotationResource.getInstance(graph);\r
if(graph.isInstanceOf(node.data, L0.Library)) {\r
for(Resource anno : graph.syncRequest(new ObjectsWithType(node.data, L0.ConsistsOf, ANNO.AnnotationType))) {\r
import java.util.ArrayList;\r
import java.util.Collection;\r
\r
+import org.simantics.annotation.ontology.AnnotationResource;\r
import org.simantics.browsing.ui.common.node.AbstractNode;\r
import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\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.SCLModulesFolder;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.ui.browser.nodes.AnnotationType;\r
+import org.simantics.sysdyn.ui.browser.nodes.AnnotationValue;\r
\r
-public class SharedOntology extends ViewpointContributor<SharedOntologyNode> {\r
+public class AnnotationContribution2 extends ViewpointContributor<Resource> {\r
\r
@Override\r
- public Collection<?> getContribution(ReadGraph graph, SharedOntologyNode model)\r
- throws DatabaseException {\r
+ public Collection<?> getContribution(ReadGraph graph, Resource res) throws DatabaseException {\r
+ \r
ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
- result.add(new SCLModulesFolder(model.data));\r
+ \r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ \r
+ AnnotationResource ANNO = AnnotationResource.getInstance(graph);\r
+ if(graph.isInstanceOf(res, L0.Library)) {\r
+ for(Resource anno : graph.syncRequest(new ObjectsWithType(res, L0.ConsistsOf, ANNO.AnnotationType))) {\r
+ result.add(new AnnotationType(anno));\r
+ }\r
+ }\r
+ for(Resource anno : graph.syncRequest(new ObjectsWithType(res, L0.ConsistsOf, ANNO.Annotation))) {\r
+ result.add(new AnnotationValue(anno));\r
+ }\r
+ \r
return result;\r
+ \r
}\r
\r
@Override\r
if(node instanceof ISpecialFolder) return result;\r
\r
Layer0 L0 = Layer0.getInstance(graph);\r
- if(graph.isInstanceOf(node.data, L0.Library)) {\r
+ if(!graph.isInstanceOf(node.data, L0.SharedOntology)) {\r
for(Resource lib : graph.syncRequest(new ObjectsWithType(node.data, L0.ConsistsOf, L0.Library))) {\r
result.add(new Library(lib));\r
}\r
import org.simantics.layer0.Layer0;\r
import org.simantics.project.ontology.ProjectResource;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedOntologyNode;\r
\r
public class Project extends ViewpointContributor<Resource> {\r
\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.browser.nodes.SharedOntologyNode;\r
\r
public class SharedOntologyImager extends ImagerContributor<SharedOntologyNode> {\r
\r
\r
import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
import org.simantics.db.ReadGraph;\r
+import org.simantics.db.common.utils.Versions;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedOntologyNode;\r
\r
public class SharedOntologyLabeler extends LabelerContributor<SharedOntologyNode> {\r
\r
@Override\r
public String getLabel(ReadGraph graph, SharedOntologyNode node) throws DatabaseException {\r
- return graph.getURI(node.data);\r
+ return Versions.getStandardNameString(graph, node.data);\r
}\r
\r
@Override\r
+++ /dev/null
-package org.simantics.sysdyn.ui.browser.contributions;\r
-\r
-import org.simantics.browsing.ui.common.node.AbstractNode;\r
-import org.simantics.browsing.ui.common.node.DeleteException;\r
-import org.simantics.browsing.ui.common.node.IDeletableNode;\r
-import org.simantics.browsing.ui.common.node.IModifiableNode;\r
-import org.simantics.browsing.ui.content.Labeler.Modifier;\r
-import org.simantics.db.Resource;\r
-\r
-public class SharedOntologyNode extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode {\r
-\r
- public SharedOntologyNode(Resource data) {\r
- super(data);\r
- }\r
- \r
- @Override\r
- public void delete() throws DeleteException {\r
- }\r
-\r
- @Override\r
- public Modifier getModifier(String columnId) {\r
- return null;\r
- }\r
-\r
-}\r
} catch (DatabaseException e) {\r
ExceptionUtils.logAndShowError(e);\r
} \r
-\r
}\r
\r
@Override\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDeletableNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.CancelTransactionException;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+\r
+public class SharedOntologyNode extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode {\r
+\r
+ public SharedOntologyNode(Resource data) {\r
+ super(data);\r
+ }\r
+ \r
+ @Override\r
+ public void delete() throws DeleteException {\r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
+ RemoverUtil.remove(graph, data);\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ ExceptionUtils.logAndShowError(e);\r
+ } \r
+ }\r
+\r
+ @Override\r
+ public Modifier getModifier(String columnId) {\r
+ return null;\r
+ }\r
+\r
+}\r
import org.eclipse.jface.viewers.ISelection;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
import org.simantics.modeling.ModelingUtils;\r
-import org.simantics.sysdyn.ui.browser.contributions.SharedOntologyNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.SharedOntologyNode;\r
import org.simantics.utils.ui.AdaptionUtils;\r
\r
public class ExportSharedOntologyHandler extends AbstractHandler {\r
ISelection sel = HandlerUtil.getCurrentSelection(event);\r
\r
@SuppressWarnings("unchecked")\r
- AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
- if (node == null)\r
- return null;\r
+ Resource res = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+ if(res == null) {\r
+ AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+ if (node == null)\r
+ return null;\r
+ res = node.data;\r
+ }\r
\r
- final Resource parent = node.data;\r
+ final Resource parent = res;\r
\r
SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
\r
ISelection sel = HandlerUtil.getCurrentSelection(event);\r
\r
@SuppressWarnings("unchecked")\r
- AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
- if (node == null)\r
- return null;\r
+ Resource res = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+ if(res == null) {\r
+ AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+ if (node == null)\r
+ return null;\r
+ res = node.data;\r
+ }\r
\r
- final Resource parent = node.data;\r
+ final Resource parent = res;\r
try {\r
Resource model = Simantics.getSession().syncRequest(new PossibleIndexRoot(parent));\r
if(model == null) return null;\r
ISelection sel = HandlerUtil.getCurrentSelection(event);\r
\r
@SuppressWarnings("unchecked")\r
- AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
- if (node == null)\r
- return null;\r
+ Resource res = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+ if(res == null) {\r
+ AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+ if (node == null)\r
+ return null;\r
+ res = node.data;\r
+ }\r
\r
- final Resource parent = node.data;\r
+ final Resource parent = res;\r
\r
SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * 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
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import java.util.Map;\r
+\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.jface.dialogs.IDialogSettings;\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.jface.viewers.StructuredSelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.ModifyEvent;\r
+import org.eclipse.swt.events.ModifyListener;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.annotation.ui.Activator;\r
+import org.simantics.modelica.data.DataSet;\r
+import org.simantics.spreadsheet.util.SpreadsheetUtils;\r
+import org.simantics.ui.workbench.dialogs.ResourceSelectionDialog3;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+public class SaveHistoryDialog extends ResourceSelectionDialog3<DataSet> {\r
+\r
+ private String sheetName;\r
+ private String sheetLocation;\r
+\r
+ public SaveHistoryDialog(Shell shell,\r
+ Map<DataSet, Pair<String, ImageDescriptor>> parameter, String title) {\r
+ super(shell, parameter, title);\r
+ this.sheetName = "";\r
+ this.sheetLocation = "";\r
+ }\r
+\r
+ @Override\r
+ protected IDialogSettings getBaseDialogSettings() {\r
+ return Activator.getDefault().getDialogSettings();\r
+ }\r
+ \r
+ @Override\r
+ protected void setSelectionResult(Object[] newResult) {\r
+ super.setSelectionResult(newResult);\r
+ validatePage();\r
+ }\r
+\r
+ @Override\r
+ protected Control createExtendedContentArea(Composite parent_) {\r
+\r
+ Composite parent = new Composite(parent_, SWT.NONE);\r
+ GridLayoutFactory.swtDefaults().numColumns(2).applyTo(parent);\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(parent);\r
+\r
+ Label l = new Label(parent, SWT.NONE); \r
+ l.setText("Select a sheet:");\r
+ GridDataFactory.fillDefaults().grab(false, false).applyTo(l);\r
+ final Text t = new Text(parent,SWT.BORDER);\r
+ t.addModifyListener(new ModifyListener() {\r
+ @Override\r
+ public void modifyText(ModifyEvent e) {\r
+ sheetName = t.getText();\r
+ validatePage();\r
+ }\r
+ });\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(t);\r
+ Label l2 = new Label(parent, SWT.NONE); \r
+ l2.setText("Select cell in sheet:");\r
+ GridDataFactory.fillDefaults().grab(false, false).applyTo(l2);\r
+ final Text t2 = new Text(parent,SWT.BORDER);\r
+ t2.addModifyListener(new ModifyListener() {\r
+ @Override\r
+ public void modifyText(ModifyEvent e) {\r
+ sheetLocation = t2.getText();\r
+ validatePage();\r
+ }\r
+ });\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(t2);\r
+ validatePage();\r
+ return super.createExtendedContentArea(parent);\r
+ }\r
+\r
+ @Override\r
+ protected void handleSelected(StructuredSelection selection) {\r
+ super.handleSelected(selection);\r
+ validatePage(); \r
+ }\r
+\r
+ protected void validatePage() {\r
+ \r
+ if(getSelectedItems().size() == 0) {\r
+ updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, "Please select some variable(s)"));\r
+ return;\r
+ }\r
+ \r
+ String error = validateSheet(sheetName);\r
+ if (error != null) {\r
+ updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, error));\r
+ return;\r
+ }\r
+\r
+ error = validateLocation(sheetLocation);\r
+ if (error != null) {\r
+ updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, error));\r
+ return;\r
+ }\r
+ \r
+ updateStatus(new Status(Status.OK, Activator.PLUGIN_ID, ""));\r
+ \r
+ }\r
+\r
+ protected String validateSheet(String name) {\r
+ if (name.trim().isEmpty())\r
+ return "Sheet name cannot be empty";\r
+ return null;\r
+ }\r
+\r
+ protected String validateLocation(String location) {\r
+ try {\r
+ if(location.isEmpty())\r
+ return "Empty location";\r
+ SpreadsheetUtils.decodeCellAbsolute(location);\r
+ return null;\r
+ } catch (Exception e) {\r
+ return e.getMessage();\r
+ }\r
+ }\r
+\r
+ public String getSheetName() {\r
+ return sheetName;\r
+ }\r
+\r
+ public String getSheetLocation() {\r
+ return sheetLocation;\r
+ }\r
+ \r
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * 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
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\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.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.jface.window.Window;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.Simantics;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.request.PossibleModel;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modelica.data.DataSet;\r
+import org.simantics.modelica.data.SimulationResult;\r
+import org.simantics.modeling.ModelingUtils;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.spreadsheet.Range;\r
+import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
+import org.simantics.spreadsheet.util.SpreadsheetUtils;\r
+import org.simantics.sysdyn.manager.MemoryResult;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
+import org.simantics.sysdyn.manager.SysdynResult;\r
+import org.simantics.sysdyn.ui.utils.HandlerUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.datastructures.Pair;\r
+ \r
+public class SaveHistoryHandler extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ HandlerUtils.saveBeforeExperimentRun(event);\r
+ \r
+ IExperimentManager manager = \r
+ SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+ IExperiment experiment = manager.getActiveExperiment();\r
+ if(experiment instanceof SysdynGameExperimentBase) {\r
+ final SysdynGameExperimentBase exp = (SysdynGameExperimentBase)experiment;\r
+ try {\r
+ \r
+ Map<DataSet, Pair<String,ImageDescriptor>> map = new HashMap<DataSet, Pair<String,ImageDescriptor>>();\r
+\r
+ SysdynResult r = exp.getCurrentResult(); \r
+ if(r instanceof MemoryResult) {\r
+ MemoryResult gr = (MemoryResult)r;\r
+ SimulationResult sr = gr.getSimulationResult();\r
+ for(DataSet ds : sr.getVariableDataSets()) {\r
+ map.put(ds, new Pair<String,ImageDescriptor>(ds.name, null));\r
+ }\r
+ }\r
+ \r
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();\r
+ SaveHistoryDialog dialog = new SaveHistoryDialog(shell, map, "Select variables");\r
+ if (dialog.open() == Window.OK) {\r
+ final Object[] result = dialog.getResult();\r
+ final String sheetName = dialog.getSheetName();\r
+ final String sheetLocation = dialog.getSheetLocation();\r
+ Simantics.getSession().syncRequest(new WriteRequest() {\r
+\r
+ public void writeCell(WriteGraph graph, Variable sheet, String cellName, String value) throws DatabaseException {\r
+ SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);\r
+ Variable child = sheet.getPossibleChild(graph, cellName);\r
+ if(child != null) {\r
+ child.setPropertyValue(graph, SHEET.Cell_content, Variant.ofInstance(value), Bindings.VARIANT);\r
+ } else {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ Resource container = sheet.getRepresents(graph);\r
+ Resource cell = graph.newResource();\r
+ graph.claim(cell, L0.InstanceOf, null, SHEET.TextCell);\r
+ graph.addLiteral(cell, L0.HasName, L0.NameOf, L0.String, cellName, Bindings.STRING);\r
+ graph.addLiteral(cell, SHEET.Cell_content, SHEET.Cell_content_Inverse, L0.Variant, Variant.ofInstance(value), Bindings.VARIANT);\r
+ graph.claim(cell, L0.PartOf, container);\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ \r
+ SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);\r
+ Resource modelResource = graph.syncRequest(new PossibleModel(exp.getResource()));\r
+ if(modelResource == null) return;\r
+ List<Resource> sheets = ModelingUtils.searchByTypeAndName(graph, modelResource, SHEET.Spreadsheet, sheetName);\r
+ if(sheets.size() != 1) return;\r
+ Variable sheet = Variables.getVariable(graph, sheets.get(0));\r
+ \r
+ Range base = SpreadsheetUtils.decodeCellAbsolute(sheetLocation);\r
+ \r
+ DataSet first = (DataSet)result[0];\r
+ writeCell(graph, sheet, sheetLocation, "times");\r
+ for(int i=0;i<first.times.length;i++) {\r
+ String loc = SpreadsheetUtils.cellName(base.startRow+1+i, base.startColumn);\r
+ writeCell(graph, sheet, loc, "" + first.times[i]); \r
+ }\r
+ \r
+ for(int j=0;j<result.length;j++) {\r
+\r
+ first = (DataSet)result[j];\r
+ writeCell(graph, sheet, SpreadsheetUtils.cellName(base.startRow, base.startColumn+1+j), first.name);\r
+ for(int i=0;i<first.values.length;i++) {\r
+ String loc = SpreadsheetUtils.cellName(base.startRow+1+i, base.startColumn+1+j);\r
+ writeCell(graph, sheet, loc, "" + first.values[i]); \r
+ }\r
+\r
+ }\r
+ \r
+ }\r
+\r
+ });\r
+ }\r
+ \r
+ \r
+ } catch (Throwable e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+}\r
import org.simantics.simulation.experiment.IExperiment;\r
import org.simantics.simulation.project.IExperimentManager;\r
import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
import org.simantics.sysdyn.ui.handlers.RunBasicExperiment;\r
import org.simantics.ui.SimanticsUI;\r
\r
\r
@Override\r
public Object execute(ExecutionEvent event) throws ExecutionException {\r
- SysdynGameExperiment game = getGameExperiment();\r
+ SysdynGameExperimentBase game = getGameExperiment();\r
if(game != null)\r
game.simulate(true);\r
return null;\r
* Find currently active game experiment\r
* @return Currently active game experiment or null if game experiment not active\r
*/\r
- private SysdynGameExperiment getGameExperiment() {\r
+ private SysdynGameExperimentBase getGameExperiment() {\r
// Find active experiment\r
IProject project = SimanticsUI.peekProject();\r
if (project == null)\r
IExperimentManager manager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
\r
IExperiment active = manager.getActiveExperiment();\r
- if (!(active instanceof SysdynGameExperiment))\r
+ if (!(active instanceof SysdynGameExperimentBase))\r
return null;\r
\r
- return (SysdynGameExperiment) active;\r
+ return (SysdynGameExperimentBase) active;\r
}\r
\r
@SuppressWarnings("rawtypes")\r
\r
\r
// Change tooltip according to the current status\r
- SysdynGameExperiment game = getGameExperiment(); \r
+ SysdynGameExperimentBase game = getGameExperiment(); \r
\r
if(game == null) {\r
started = false;\r
import org.simantics.simulation.experiment.ExperimentState;\r
import org.simantics.simulation.experiment.IExperiment;\r
import org.simantics.simulation.project.IExperimentManager;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
import org.simantics.sysdyn.ui.utils.HandlerUtils;\r
import org.simantics.ui.SimanticsUI;\r
\r
private boolean initialized = false;\r
private boolean running = false; \r
\r
- private SysdynGameExperiment getGameExperiment() {\r
+ private SysdynGameExperimentBase getGameExperiment() {\r
// Find active experiment\r
IProject project = SimanticsUI.peekProject();\r
if (project == null)\r
IExperimentManager manager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
\r
IExperiment active = manager.getActiveExperiment();\r
- if (!(active instanceof SysdynGameExperiment))\r
+ if (!(active instanceof SysdynGameExperimentBase))\r
return null;\r
\r
- return (SysdynGameExperiment) active;\r
+ return (SysdynGameExperimentBase) active;\r
}\r
\r
@Override\r
public Object execute(ExecutionEvent event) throws ExecutionException {\r
HandlerUtils.saveBeforeExperimentRun(event);\r
\r
- SysdynGameExperiment game = getGameExperiment();\r
+ SysdynGameExperimentBase game = getGameExperiment();\r
if(game != null)\r
game.simulateDuration(game.getStepDuration());\r
return null;\r
public void updateElement(UIElement element, Map parameters) {\r
\r
// Disable button when model has not been initialized and change tooltip accordingly\r
- SysdynGameExperiment game = getGameExperiment(); \r
+ SysdynGameExperimentBase game = getGameExperiment(); \r
\r
if(game == null) {\r
started = false;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
\r
/**\r
* Handler for creating a new Game Experiment\r
*/\r
protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
- graph.claimLiteral(experiment, sr.GameExperiment_stepDuration, SysdynGameExperiment.DEFAULT_STEP_DURATION);\r
- graph.claimLiteral(experiment, sr.GameExperiment_stepLength, SysdynGameExperiment.DEFAULT_STEP_LENGTH);\r
+ graph.claimLiteral(experiment, sr.GameExperiment_stepDuration, SysdynGameExperimentBase.DEFAULT_STEP_DURATION);\r
+ graph.claimLiteral(experiment, sr.GameExperiment_stepLength, SysdynGameExperimentBase.DEFAULT_STEP_LENGTH);\r
}\r
\r
protected String getNameSuggestion() {\r
import org.simantics.simulation.project.IExperimentManager;\r
import org.simantics.simulation.project.IExperimentManagerListener;\r
import org.simantics.sysdyn.manager.SysdynExperiment;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
import org.simantics.sysdyn.manager.SysdynPlaybackExperiment;\r
import org.simantics.sysdyn.manager.SysdynSensitivityAnalysisExperiment;\r
\r
if(experiment instanceof SysdynPlaybackExperiment) {\r
contextActivations.add(contextService.activateContext(PLAYBACK_EXPERIMENT_CONTEXT));\r
experiment.addListener(new SysdynPlaybackExperimentListener((SysdynPlaybackExperiment)experiment));\r
- } else if(experiment instanceof SysdynGameExperiment) {\r
+ } else if(experiment instanceof SysdynGameExperimentBase) {\r
contextActivations.add(contextService.activateContext(GAME_EXPERIMENT_CONTEXT));\r
// TODO: some listener?\r
} else if(experiment instanceof SysdynSensitivityAnalysisExperiment) {\r
import org.simantics.simulation.experiment.IExperiment;\r
import org.simantics.simulation.project.IExperimentManager;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
import org.simantics.sysdyn.ui.properties.SysdynBasicColorProvider;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
IExperimentManager manager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
\r
IExperiment active = manager.getActiveExperiment();\r
- if (!(active instanceof SysdynGameExperiment))\r
+ if (!(active instanceof SysdynGameExperimentBase))\r
return;\r
\r
- final SysdynGameExperiment game = (SysdynGameExperiment) active;\r
+ final SysdynGameExperimentBase game = (SysdynGameExperimentBase) active;\r
\r
// Create the text\r
\r
import org.simantics.simulation.experiment.IExperiment;\r
import org.simantics.simulation.project.IExperimentManager;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
import org.simantics.sysdyn.ui.utils.ExpressionUtils;\r
import org.simantics.ui.SimanticsUI;\r
\r
public void readData(final Resource expression, Map<String, Object> data) {\r
IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
IExperiment experiment = manager.getActiveExperiment();\r
- if(experiment == null || !(experiment instanceof SysdynGameExperiment)) {\r
+ if(experiment == null || !(experiment instanceof SysdynGameExperimentBase)) {\r
super.readData(expression, data);\r
} else {\r
Double value;\r
- ExperimentState state = ((SysdynGameExperiment)experiment).getSysdynExperimentState();\r
+ ExperimentState state = ((SysdynGameExperimentBase)experiment).getSysdynExperimentState();\r
if(ExperimentState.RUNNING.equals(state) || ExperimentState.STOPPED.equals(state)) {\r
try {\r
value = SimanticsUI.getSession().syncRequest(new Read<Double>() {\r
\r
IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
IExperiment experiment = manager.getActiveExperiment();\r
- if(experiment != null && experiment instanceof SysdynGameExperiment) {\r
+ if(experiment != null && experiment instanceof SysdynGameExperimentBase) {\r
final String currentText = this.expression.getExpression();\r
final String oldEquation = (String)data.get("equation");\r
if(oldEquation == null || \r
if(ExpressionUtils.isParameter(currentText)) {\r
Boolean savedIntoFMU = false;\r
\r
- ExperimentState state = ((SysdynGameExperiment)experiment).getSysdynExperimentState();\r
+ ExperimentState state = ((SysdynGameExperimentBase)experiment).getSysdynExperimentState();\r
// Set value to control only if the simulation is running or stopped, not before initialization\r
if(ExperimentState.RUNNING.equals(state) || ExperimentState.STOPPED.equals(state)) {\r
try {\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
import org.simantics.sysdyn.manager.SysdynPlaybackExperiment;\r
\r
public class TimeIndexVariable extends IndexVariable<Double> {\r
public Double getValue() {\r
if(experiment != null && experiment instanceof SysdynPlaybackExperiment)\r
return ((SysdynPlaybackExperiment)experiment).getTime();\r
- if(experiment != null && experiment instanceof SysdynGameExperiment)\r
- return ((SysdynGameExperiment)experiment).getTime();\r
+ if(experiment != null && experiment instanceof SysdynGameExperimentBase)\r
+ return ((SysdynGameExperimentBase)experiment).getSolver().getTime();\r
return null;\r
}\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.Logger;\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.fmu.FMUControlJNI;\r
-import org.simantics.fmu.FMUJNIException;\r
import org.simantics.simulation.experiment.ExperimentState;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.manager.SysdynDataSet;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
import org.simantics.sysdyn.manager.SysdynResult;\r
+import org.simantics.sysdyn.solver.ISolver;\r
\r
abstract public class ValueIndexVariableBase<T> extends IndexVariable<T> {\r
\r
double[] result = new double[variableNames.size()];\r
for(int i = 0; i < variableNames.size(); i++) {\r
for(SysdynResult r : results) { \r
- if(experiment instanceof SysdynGameExperiment) {\r
- Double d = ((SysdynGameExperiment)experiment).getCurrentValue(variableNames.get(i)); \r
+ if(experiment instanceof SysdynGameExperimentBase) {\r
+ Double d = ((SysdynGameExperimentBase)experiment).getCurrentValue(variableNames.get(i)); \r
result[i] = d != null ? d : 0;\r
} else {\r
SysdynDataSet ds = r.getDataSet(variableNames.get(i));\r
\r
double[] values = (double[]) value;\r
\r
- FMUControlJNI control = null;\r
- if(experiment instanceof SysdynGameExperiment) { // Support only game experiments for now..\r
+// FMUControlJNI control = null;\r
+ if(experiment instanceof SysdynGameExperimentBase) { // Support only game experiments for now..\r
\r
- SysdynGameExperiment exp = (SysdynGameExperiment)experiment;\r
+ SysdynGameExperimentBase exp = (SysdynGameExperimentBase)experiment;\r
ExperimentState state = exp.getSysdynExperimentState();\r
// Set value to control only if the simulation is running or stopped, not before initialization\r
if(!(ExperimentState.RUNNING.equals(state) || ExperimentState.STOPPED.equals(state)))\r
return;\r
\r
- control = ((SysdynGameExperiment)this.experiment).getFMUControl();\r
- if(control == null) \r
- return;\r
+// control = ((SysdynGameExperimentBase)this.experiment).getFMUControl();\r
+// if(control == null) \r
+// return;\r
\r
+ ISolver solver = exp.getSolver();\r
+\r
+ try {\r
\r
+ ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
+ for(int i = 0; i < variableNames.size() && i < values.length; i++) {\r
+\r
+ if(values[i] == Double.NaN)\r
+ continue;\r
\r
- ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
- for(int i = 0; i < variableNames.size() && i < values.length; i++) {\r
- if(values[i] == Double.NaN)\r
- continue;\r
- \r
- try {\r
String name = variableNames.get(i);\r
- control.setRealValue(name, values[i]);\r
- \r
+ solver.setRealValue(name, values[i]);\r
+\r
// Set value for all referred variables in modules\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
for(Resource dependency : graph.getObjects(resource, sr.Variable_isTailOf)) {\r
if(name.indexOf(".") > 0)\r
module = name.substring(0, name.lastIndexOf(".") + 1);\r
String refName = module + NameUtils.getSafeName(graph, head) + "." + NameUtils.getSafeName(graph, ref);\r
- control.setRealValue(refName, values[i]);\r
+ solver.setRealValue(refName, values[i]);\r
} \r
}\r
- } catch (FMUJNIException e) {\r
+\r
}\r
+ exp.updateSubscriptions();\r
+ \r
+ } catch (Exception e) {\r
+ \r
+ Logger.defaultLogError(e);\r
+ \r
}\r
- exp.updateSubscriptions();\r
+ \r
}\r
}\r
\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.sysdyn.manager.SysdynDataSet;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
import org.simantics.sysdyn.manager.SysdynResult;\r
\r
public class ValuesIndexVariable extends IndexVariable<double[][]> {\r
* get the last value from experiment. It might be different from the result\r
* file, if it has been modified in current time step \r
*/\r
- if(experiment instanceof SysdynGameExperiment && ds.result == null) {\r
- double d = ((SysdynGameExperiment)experiment).getCurrentValue(variableNames.get(i));\r
+ if(experiment instanceof SysdynGameExperimentBase && ds.result == null) {\r
+ double d = ((SysdynGameExperimentBase)experiment).getCurrentValue(variableNames.get(i));\r
result[i][ds.values.length - 1] = d;\r
}\r
break; // Show the first result found. (i.e. do not show history datasets)\r
--- /dev/null
+package org.simantics.sysdyn.manager;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.simantics.modelica.data.DataSet;\r
+import org.simantics.modelica.data.SimulationResult;\r
+\r
+/**\r
+ * Game results\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class GameResult extends SimulationResult {\r
+ \r
+ private final SysdynGameExperimentBase base;\r
+\r
+ public GameResult(SysdynGameExperimentBase sysdynGameExperiment, HashMap<String, ArrayList<Double>> results, String[] subscription) {\r
+ \r
+ base = sysdynGameExperiment;\r
+ // Get times\r
+ ArrayList<Double> timeList = results.get("time");\r
+ double[] times = new double[timeList.size()];\r
+ for(int i = 0; i < timeList.size(); i++) {\r
+ times[i] = timeList.get(i);\r
+ }\r
+ \r
+ String name;\r
+ double[] values;\r
+ ArrayList<Double> valueList;\r
+ for(int k = 0; k < subscription.length; k++) {\r
+ name = subscription[k];\r
+ values = new double[timeList.size()];\r
+ valueList = results.get(name);\r
+ if(valueList.size() == timeList.size()) {\r
+ for(int i = 0; i < valueList.size(); i++) {\r
+ values[i] = valueList.get(i);\r
+ }\r
+ this.variables.add(new DataSet(name, times, values));\r
+ } else {\r
+ System.err.println("wrong amount of values " + name);\r
+ }\r
+ }\r
+ }\r
+}
\ No newline at end of file
addAllInitialValues(result); // For legacy reasons\r
}\r
\r
- private SimulationResult getSimulationResult() {\r
+ public SimulationResult getSimulationResult() {\r
return this.simulationResult;\r
}\r
\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.Logger;\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.service.VirtualGraphSupport;\r
for(IExperimentListener listener : listeners.getListeners())\r
listener.stateChanged(state);\r
\r
- session.asyncRequest(new ReadRequest() {\r
-\r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- final Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
- sysdynModel = SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
- toggleActivation(graph, true);\r
- }\r
- });\r
+ try {\r
+ g.syncRequest(new ReadRequest() {\r
+\r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ final Resource configuration = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
+ sysdynModel = SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
+ toggleActivation(graph, true);\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ Logger.defaultLogError(e);\r
+ }\r
\r
setSysdynExperimentState(ExperimentState.INITIALIZING);\r
}\r
--- /dev/null
+package org.simantics.sysdyn.manager;\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.simulation.experiment.ExperimentState;\r
+import org.simantics.sysdyn.solver.ISolver;\r
+\r
+class SimulateDurationJob extends Job {\r
+\r
+ private boolean canceled = false;\r
+ private double duration;\r
+ private final SysdynGameExperimentBase base;\r
+ private final ISolver solver;\r
+ \r
+ public SimulateDurationJob(SysdynGameExperimentBase base, String name, double duration) {\r
+ super(name);\r
+ this.base = base;\r
+ this.solver = base.getSolver();\r
+ this.duration = duration;\r
+ }\r
+\r
+ @Override\r
+ protected void canceling() {\r
+ canceled = true;\r
+ }\r
+\r
+ @Override\r
+ protected IStatus run(IProgressMonitor monitor) {\r
+ if(base == null || base.getState() != ExperimentState.STOPPED)\r
+ return Status.OK_STATUS;\r
+\r
+ base.changeState(ExperimentState.RUNNING);\r
+ int nSteps = (int)(duration / base.stepLength); \r
+ int work = 1 + nSteps * 3 + 2; // initialization + number of steps * number of phases per step + set result + call result listeners \r
+\r
+ monitor.beginTask("Simulating " + duration + " time steps", work);\r
+ monitor.subTask("Initialize step simulation");\r
+\r
+ if(base.subscription == null || base.results == null)\r
+ return Status.OK_STATUS;\r
+\r
+ if(duration <= 0.0)\r
+ duration = base.stepDuration;\r
+\r
+\r
+ try {\r
+\r
+ solver.prepareToStep();\r
+\r
+ double time = solver.getTime();\r
+ double eTime = time + duration;\r
+\r
+ monitor.worked(1);\r
+\r
+ base.setSubscribedResults(monitor, time);\r
+\r
+ int stepNumber = 1;\r
+ while(time < eTime && !canceled) {\r
+ \r
+ if(eTime - time < base.stepLength)\r
+ solver.setStepLength(eTime - time);\r
+\r
+ monitor.subTask("Simulate step (time = " + time + ")");\r
+ solver.simulateStep();\r
+ monitor.worked(1);\r
+\r
+ time = solver.getTime();\r
+\r
+ if(stepNumber % base.savePer == 0) {\r
+ base.setSubscribedResults(monitor, time);\r
+ } else {\r
+ monitor.worked(1);\r
+ }\r
+ stepNumber++;\r
+ monitor.worked(1);\r
+\r
+ }\r
+\r
+ monitor.subTask("Display results");\r
+ ((MemoryResult)base.getCurrentResult()).setResult(new GameResult(base, base.results, base.subscription));\r
+ monitor.worked(1);\r
+\r
+ base.resultsChanged(true);\r
+ monitor.worked(1);\r
+ base.changeState(ExperimentState.STOPPED);\r
+\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ System.err.println("SysdynGameExperiment simulateDuration failed: \n\t" + e.getMessage());\r
+ }\r
+ return Status.OK_STATUS;\r
+ \r
+ }\r
+}
\ No newline at end of file
import java.util.HashMap;\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.eclipse.core.runtime.NullProgressMonitor;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.db.AsyncReadGraph;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Session;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.Logger;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.util.Layer0Utils;\r
import org.simantics.db.layer0.util.Simantics;\r
import org.simantics.modelica.IModelicaMonitor;\r
import org.simantics.modelica.ModelicaManager;\r
import org.simantics.modelica.SimulationLocation;\r
-import org.simantics.modelica.data.DataSet;\r
-import org.simantics.modelica.data.SimulationResult;\r
import org.simantics.modeling.PartialIC;\r
import org.simantics.simulation.experiment.ExperimentState;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.simulation.SimulationJob.HeadlessModelicaMonitor;\r
+import org.simantics.sysdyn.solver.ISolver;\r
+import org.simantics.sysdyn.solver.ModelicaSolver;\r
import org.simantics.utils.datastructures.Quad;\r
\r
/**\r
* @author Teemu Lempinen\r
*\r
*/\r
-public class SysdynGameExperiment extends OldSysdynExperiment {\r
-\r
- private FMUControlJNI control;\r
- private String[] subscription;\r
- private HashMap<String, Integer> subscriptionIndexes;\r
- private HashMap<String, ArrayList<Double>> results;\r
- private double stepLength = DEFAULT_STEP_LENGTH;\r
- private double startTime = DEFAULT_START_TIME;\r
- private double stepDuration = DEFAULT_STEP_DURATION;\r
- private int savePer = 1;\r
- private static boolean fortranLibrariesLoaded = false;\r
+public class SysdynGameExperiment extends SysdynGameExperimentBase {\r
+\r
+ private ModelicaSolver solver;\r
+ public FMUControlJNI control;\r
+ private boolean loaded = false;\r
\r
- public static double DEFAULT_STEP_DURATION = 1.0;\r
- public static double DEFAULT_STEP_LENGTH = 0.1;\r
- public static double DEFAULT_START_TIME = 0.0;\r
- public static int DEFAULT_OUTPUT_INTERVAL = 1;\r
+ private static boolean fortranLibrariesLoaded = false;\r
\r
- double[] currentValues; // Current values from FMU. Updated with updateSubscriptions\r
-\r
public SysdynGameExperiment(Resource experiment, Resource model) {\r
super(experiment, model);\r
+ this.solver = new ModelicaSolver(this);\r
}\r
-\r
- public double getStepDuration() {\r
- return stepDuration;\r
- }\r
- \r
- public void setStepDuration(double duration) {\r
- this.stepDuration = duration;\r
- }\r
- \r
- public double getStepLength() {\r
- return stepLength;\r
- }\r
- \r
- public void setStepLength(double stepLength) {\r
- this.stepLength = stepLength;\r
- }\r
- \r
- public void setStartTime(double startTime) {\r
- this.startTime = startTime;\r
- }\r
-\r
- public void setOutputInterval(int interval) {\r
- this.savePer = interval;\r
- }\r
-\r
\r
public FMUControlJNI getFMUControl() {\r
return control;\r
}\r
\r
- public double getTime() {\r
- if(control != null) {\r
- try {\r
- return control.getTime();\r
- } catch (FMUJNIException e) {\r
- }\r
- }\r
- return 0.0;\r
- }\r
- \r
-\r
@Override\r
public void init(ReadGraph g) {\r
super.init(g);\r
if(control!=null) {\r
try {\r
control.unloadFMU();\r
+ loaded = false;\r
} catch (FMUJNIException e) {\r
e.printStackTrace();\r
}\r
}\r
\r
control.loadFMUFile(simulationLocation.executableFile.getAbsolutePath()); // unzip and load fmu\r
+ loaded = true;\r
instantiate();\r
\r
} catch (FMUJNIException e) {\r
\r
\r
@Override\r
- public void simulateDuration(double duration) {\r
- Job job = new simulateDurationJob("Simulate steps", this, duration);\r
- // Start the Job\r
- job.schedule();\r
- }\r
- \r
- private double lastResultTime = Double.NaN;\r
-\r
- public void setSubscribedResults(IProgressMonitor monitor, double time) throws FMUJNIException {\r
-\r
-// System.err.println("setSubscribedResults " + time);\r
- \r
- monitor.subTask("Get results (time = " + time + ")");\r
- currentValues = control.getSubscribedResults(currentValues);\r
- monitor.worked(1);\r
-\r
- monitor.subTask("Save results (time = " + time + ")");\r
- for(int k = 0; k < subscription.length; k++) {\r
- setResults(time, subscription[k], currentValues[k]);\r
- }\r
- \r
- lastResultTime = time;\r
- \r
- }\r
- \r
- public void setResults(double time, String key, Double value) {\r
- ArrayList<Double> list = results.get(key);\r
- if(list == null) {\r
- list = new ArrayList<Double>();\r
- results.put(key, list);\r
- }\r
- if(time == lastResultTime) {\r
- list.set(list.size()-1, value);\r
- } else {\r
- list.add(value);\r
- }\r
-// System.err.println("setResults " + time + " " + key + " = " + list);\r
- }\r
- \r
- public void clearResults() {\r
- lastResultTime = Double.NaN;\r
- results.clear();\r
- }\r
- \r
- private class simulateDurationJob extends Job {\r
-\r
- private boolean canceled = false;\r
- private double duration;\r
- private final SysdynGameExperiment experiment;\r
- public simulateDurationJob(String name, SysdynGameExperiment experiment, double duration) {\r
- super(name);\r
- this.duration = duration;\r
- this.experiment = experiment;\r
- }\r
- \r
- @Override\r
- protected void canceling() {\r
- canceled = true;\r
- }\r
-\r
- @Override\r
- protected IStatus run(IProgressMonitor monitor) {\r
- if(experiment == null || experiment.getState() != ExperimentState.STOPPED)\r
- return Status.OK_STATUS;\r
- \r
- changeState(ExperimentState.RUNNING);\r
- int nSteps = (int)(duration / stepLength); \r
- int work = 1 + nSteps * 3 + 2; // initialization + number of steps * number of phases per step + set result + call result listeners \r
- \r
- monitor.beginTask("Simulating " + duration + " time steps", work);\r
- monitor.subTask("Initialize step simulation");\r
-\r
- if(subscription == null || SysdynGameExperiment.this.results == null || control == null)\r
- return Status.OK_STATUS;\r
- \r
- if(duration <= 0.0)\r
- duration = stepDuration;\r
- \r
- \r
- try {\r
-\r
- // initialize if not initialized\r
- if(!control.isInitialized()) {\r
- control.setTime(startTime);\r
- control.initializeSimulation();\r
- clearResults();\r
-// getInitialResultValues();\r
- }\r
- \r
- control.setStepLength(stepLength); // Set step length each time in case there has been changes\r
-\r
- double time = control.getTime();\r
- double eTime = time + duration;\r
- \r
- monitor.worked(1);\r
-\r
- setSubscribedResults(monitor, time);\r
-\r
- int stepNumber = 1;\r
- while(time < eTime && !canceled) {\r
- if(eTime - time < stepLength)\r
- control.setStepLength(eTime - time);\r
- \r
- monitor.subTask("Simulate step (time = " + time + ")");\r
- control.simulateStep();\r
- monitor.worked(1);\r
-\r
- time = control.getTime();\r
-\r
- if(stepNumber % savePer == 0) {\r
- setSubscribedResults(monitor, time);\r
- } else {\r
- monitor.worked(1);\r
- }\r
- stepNumber++;\r
- monitor.worked(1);\r
- \r
- }\r
- \r
- monitor.subTask("Display results");\r
- ((MemoryResult)getCurrentResult()).setResult(new GameResult(SysdynGameExperiment.this.results, SysdynGameExperiment.this.subscription));\r
- monitor.worked(1);\r
- \r
- resultsChanged(true);\r
- monitor.worked(1);\r
- changeState(ExperimentState.STOPPED);\r
- \r
- } catch (FMUJNIException e) {\r
- System.err.println("SysdynGameExperiment simulateDuration failed: \n\t" + e.getMessage());\r
- }\r
- return Status.OK_STATUS;\r
- }\r
- }\r
- \r
- /**\r
- * Game results\r
- * @author Teemu Lempinen\r
- *\r
- */\r
- public class GameResult extends SimulationResult {\r
- \r
- public GameResult(HashMap<String, ArrayList<Double>> results, String[] subscription) {\r
- \r
- // Get times\r
- ArrayList<Double> timeList = results.get("time");\r
- double[] times = new double[timeList.size()];\r
- for(int i = 0; i < timeList.size(); i++) {\r
- times[i] = timeList.get(i);\r
- }\r
- \r
- String name;\r
- double[] values;\r
- ArrayList<Double> valueList;\r
- for(int k = 0; k < subscription.length; k++) {\r
- name = subscription[k];\r
- values = new double[timeList.size()];\r
- valueList = results.get(name);\r
- for(int i = 0; i < valueList.size(); i++) {\r
- values[i] = valueList.get(i);\r
- }\r
- this.variables.add(new DataSet(name, times, values));\r
- }\r
- }\r
- }\r
- \r
- @Override\r
public void rewindTo(double time) {\r
+ \r
if(control == null)\r
return;\r
\r
if(time >-0.001 && time < 0.001) {\r
- instantiate();\r
+ try {\r
+ simulate(new HeadlessModelicaMonitor(), new NullProgressMonitor(), sysdynModel.getConfiguration().getLabel());\r
+ //instantiate();\r
+ } catch (IOException e) {\r
+ Logger.defaultLogError(e);\r
+ }\r
} else {\r
System.out.println("rewindTo");\r
}\r
control.setStepLength(stepLength); // FIXME: fixed step lenghth\r
control.setTime(startTime);\r
control.instantiateSimulation(); // instantiate simulation\r
- \r
- if(!control.isInitialized()) {\r
+\r
+ if(!control.isInitialized()) {\r
control.initializeSimulation();\r
}\r
- \r
+\r
if(inits.get("variableFilter") == null || inits.get("variableFilter").equals(".*"))\r
subscription = control.getAllVariables();\r
else\r
\r
@Override\r
public void updateSubscriptions() {\r
+ \r
+ if(!loaded) return;\r
+ \r
try {\r
if(control.isInitialized())\r
currentValues = control.getSubscribedResults(currentValues);\r
}\r
super.updateSubscriptions();\r
}\r
+\r
+ @Override\r
+ public ISolver getSolver() {\r
+ return solver;\r
+ }\r
\r
- public Double getCurrentValue(String name) {\r
- if(subscriptionIndexes != null && name != null) {\r
- Integer index = subscriptionIndexes.get(name);\r
- if(index != null) {\r
- return currentValues[index];\r
- }\r
- }\r
- return null;\r
- }\r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
+ * 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
+package org.simantics.sysdyn.manager;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.jobs.Job;\r
+import org.simantics.db.Resource;\r
+import org.simantics.fmu.FMUJNIException;\r
+import org.simantics.sysdyn.solver.ISolver;\r
+\r
+/**\r
+ * Game experiment\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+abstract public class SysdynGameExperimentBase extends OldSysdynExperiment {\r
+\r
+ public double stepLength = DEFAULT_STEP_LENGTH;\r
+ public double startTime = DEFAULT_START_TIME;\r
+ protected double stepDuration = DEFAULT_STEP_DURATION;\r
+ protected int savePer = 1;\r
+\r
+ protected HashMap<String, Integer> subscriptionIndexes;\r
+ protected double[] currentValues; // Current values from FMU. Updated with updateSubscriptions\r
+ \r
+ HashMap<String, ArrayList<Double>> results;\r
+\r
+ protected String[] subscription;\r
+ \r
+ public static double DEFAULT_STEP_DURATION = 1.0;\r
+ public static double DEFAULT_STEP_LENGTH = 0.1;\r
+ public static double DEFAULT_START_TIME = 0.0;\r
+ public static int DEFAULT_OUTPUT_INTERVAL = 1;\r
+ \r
+ public SysdynGameExperimentBase(Resource experiment, Resource model) {\r
+ super(experiment, model);\r
+ }\r
+\r
+ public double getStepDuration() {\r
+ return stepDuration;\r
+ }\r
+ \r
+ public void setStepDuration(double duration) {\r
+ this.stepDuration = duration;\r
+ }\r
+ \r
+ public double getStepLength() {\r
+ return stepLength;\r
+ }\r
+ \r
+ public void setStepLength(double stepLength) {\r
+ this.stepLength = stepLength;\r
+ }\r
+ \r
+ public void setStartTime(double startTime) {\r
+ this.startTime = startTime;\r
+ }\r
+\r
+ public void setOutputInterval(int interval) {\r
+ this.savePer = interval;\r
+ }\r
+ \r
+ public Double getCurrentValue(String name) {\r
+ if(subscriptionIndexes != null && name != null) {\r
+ Integer index = subscriptionIndexes.get(name);\r
+ if(index != null) {\r
+ return currentValues[index];\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+ public void setSubscribedResults(IProgressMonitor monitor, double time) throws FMUJNIException {\r
+\r
+// System.err.println("setSubscribedResults " + time);\r
+ \r
+ monitor.subTask("Get results (time = " + time + ")");\r
+ currentValues = getSolver().getSubscribedResults(currentValues);\r
+ monitor.worked(1);\r
+\r
+ monitor.subTask("Save results (time = " + time + ")");\r
+ for(int k = 0; k < subscription.length; k++) {\r
+ setResults(time, subscription[k], currentValues[k]);\r
+ }\r
+ \r
+ lastResultTime = time;\r
+ \r
+ }\r
+ \r
+ private double lastResultTime = Double.NaN;\r
+\r
+ public void setResults(double time, String key, Double value) {\r
+ ArrayList<Double> list = results.get(key);\r
+ if(list == null) {\r
+ list = new ArrayList<Double>();\r
+ results.put(key, list);\r
+ }\r
+ if(time == lastResultTime) {\r
+ list.set(list.size()-1, value);\r
+ } else {\r
+ list.add(value);\r
+ }\r
+// System.err.println("setResults " + time + " " + key + " = " + list);\r
+ }\r
+ \r
+ public void clearResults() {\r
+ lastResultTime = Double.NaN;\r
+ results.clear();\r
+ }\r
+ \r
+ @Override\r
+ public void simulateDuration(double duration) {\r
+ Job job = new SimulateDurationJob(this, "Simulate steps", duration);\r
+ // Start the Job\r
+ job.schedule();\r
+ }\r
+ \r
+ public abstract ISolver getSolver();\r
+ \r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
+ * 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
+package org.simantics.sysdyn.manager;\r
+\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.NullProgressMonitor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.Logger;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
+import org.simantics.db.layer0.util.Simantics;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.modelica.IModelicaMonitor;\r
+import org.simantics.modeling.PartialIC;\r
+import org.simantics.simulation.experiment.ExperimentState;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.simulation.SimulationJob.HeadlessModelicaMonitor;\r
+import org.simantics.sysdyn.solver.ISolver;\r
+import org.simantics.sysdyn.solver.ISolverMonitor;\r
+import org.simantics.sysdyn.solver.InternalSolver;\r
+\r
+\r
+public class SysdynGameExperimentInternal extends SysdynGameExperimentBase {\r
+\r
+ public InternalSolver solver;\r
+ \r
+ public SysdynGameExperimentInternal(Resource experiment, Resource model) {\r
+ super(experiment, model);\r
+ }\r
+\r
+ @Override\r
+ public ISolver getSolver() {\r
+ return solver;\r
+ }\r
+ \r
+ @Override\r
+ public void init(ReadGraph g) {\r
+ \r
+ super.init(g);\r
+ \r
+ results = new HashMap<String, ArrayList<Double>>();\r
+\r
+ solver = new InternalSolver(this, sysdynModel, true, new ISolverMonitor() {\r
+ \r
+ @Override\r
+ public void showConsole() {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+ \r
+ @Override\r
+ public void message(String message) {\r
+ System.err.println("Internal solver:" + message);\r
+ }\r
+ \r
+ @Override\r
+ public void clearConsole() {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+ });\r
+\r
+ }\r
+\r
+ @Override\r
+ public synchronized void simulate(final IModelicaMonitor monitor, final IProgressMonitor progressMonitor, String modelName) throws IOException {\r
+ \r
+ new Exception().printStackTrace();\r
+ \r
+ try {\r
+\r
+ solver.initialize();\r
+ solver.buildModel();\r
+\r
+ solver.setStepLength(stepLength); // FIXME: fixed step length\r
+\r
+ //solver.setTime(startTime);\r
+\r
+ subscription = solver.solver.keys();\r
+ \r
+ // Initialize subscription indexes map for fast result reading in getValue()\r
+ if(subscriptionIndexes == null)\r
+ subscriptionIndexes = new HashMap<String, Integer>();\r
+ \r
+ subscriptionIndexes.clear();\r
+ for(int i = 0; i < subscription.length; i++) {\r
+ subscriptionIndexes.put(subscription[i], i);\r
+ }\r
+\r
+ // Initialize container for current simulation results\r
+ currentValues = new double[subscription.length];\r
+ \r
+ // subscribe all variables\r
+ //solver.subscribe(subscription); \r
+\r
+ clearResults();\r
+ //getInitialResultValues();\r
+ \r
+ Simantics.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+\r
+ Resource run = Layer0Utils.getPossibleChild(graph, SysdynGameExperimentInternal.this.experiment, getIdentifier());\r
+ if(run == null) {\r
+ System.err.println("No run");\r
+ return;\r
+ }\r
+ \r
+ Variable base = Variables.getVariable(graph, run);\r
+ \r
+ SysdynResource SYSDYN = SysdynResource.getInstance(graph);\r
+ \r
+ Resource ic = graph.getPossibleObject(SysdynGameExperimentInternal.this.experiment, SYSDYN.Experiment_ic);\r
+ if(ic == null) return;\r
+ \r
+ PartialIC data = graph.getPossibleRelatedValue(ic, SYSDYN.InitialCondition_HasInitialValues, PartialIC.BINDING);\r
+ data.apply(graph, base);\r
+ \r
+ }\r
+ \r
+ });\r
+ \r
+ \r
+ setSubscribedResults(new NullProgressMonitor(), solver.getTime());\r
+\r
+ ((MemoryResult)getCurrentResult()).setResult(new GameResult(this, this.results, this.subscription));\r
+\r
+ resultsChanged(true);\r
+ \r
+ changeState(ExperimentState.STOPPED);\r
+ \r
+ } catch (Exception e) {\r
+ Logger.defaultLogError(e);\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public void rewindTo(double time) {\r
+ \r
+ if(time >-0.001 && time < 0.001) {\r
+ try {\r
+ simulate(new HeadlessModelicaMonitor(), new NullProgressMonitor(), sysdynModel.getConfiguration().getLabel());\r
+ //instantiate();\r
+ } catch (IOException e) {\r
+ Logger.defaultLogError(e);\r
+ }\r
+ } else {\r
+ System.out.println("rewindTo");\r
+ }\r
+ }\r
+\r
+ }\r
if(g.isInstanceOf(experiment, sr.PlaybackExperiment)) {\r
exp = new SysdynPlaybackExperiment(experiment, modelResource);\r
} else if(g.isInstanceOf(experiment, sr.GameExperiment)) {\r
- exp = new SysdynGameExperiment(experiment, modelResource);\r
+ if (SolverType.INTERNAL.equals(SolverSettings.getSelectedSolverType())) {\r
+ exp = new SysdynGameExperimentInternal(experiment, modelResource);\r
+ }\r
+ else {\r
+ exp = new SysdynGameExperiment(experiment, modelResource);\r
+ }\r
} else if(g.isInstanceOf(experiment, sr.SensitivityAnalysisExperiment)) {\r
exp = new SysdynSensitivityAnalysisExperiment(experiment, modelResource);\r
} else if(g.isInstanceOf(experiment, sr.BasicExperiment)) {\r
import org.simantics.simulation.project.IExperimentManager;\r
import org.simantics.sysdyn.expressionParser.ExpressionParser;\r
import org.simantics.sysdyn.expressionParser.ParseException;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.IElement;\r
import org.simantics.sysdyn.representation.IndependentVariable;\r
IExperimentManager manager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
\r
IExperiment active = manager.getActiveExperiment();\r
- if (active instanceof SysdynGameExperiment)\r
+ if (active instanceof SysdynGameExperimentBase)\r
return true;\r
else\r
return false;\r
return "SimulationJob".equals(family);\r
}\r
\r
- private class HeadlessModelicaMonitor implements IModelicaMonitor {\r
+ public static class HeadlessModelicaMonitor implements IModelicaMonitor {\r
public HeadlessModelicaMonitor() {\r
}\r
\r
public void updateResults() throws Exception;\r
public SolverType getType();\r
\r
+ public double[] getSubscribedResults(double[] array);\r
+ \r
+ public void prepareToStep() throws Exception;\r
+ public void simulateStep() throws Exception ;\r
+ \r
+ public void setStepLength(double length) throws Exception ;\r
+ public double getTime();\r
+ \r
+ public void setRealValue(String name, double value) throws Exception ;\r
+\r
}\r
private SysdynExperiment experiment;\r
private SysdynModel model;\r
private ISolverMonitor monitor;\r
- private Solver solver;\r
+ public Solver solver;\r
\r
private double start;\r
private double stop;\r
private double step;\r
private double interval;\r
\r
+ private final boolean isGame;\r
+ \r
private SimulationLocation location;\r
\r
private HashMap<String, SysdynDataSet> results;\r
\r
- public InternalSolver(SysdynExperiment experiment, SysdynModel model, ISolverMonitor monitor) {\r
+ public InternalSolver(SysdynExperiment experiment, SysdynModel model, boolean isGame, ISolverMonitor monitor) {\r
this.experiment = experiment;\r
this.model = model;\r
this.monitor = monitor;\r
+ this.isGame = isGame;\r
\r
solver = new Solver();\r
\r
stop = representation.getStopTime();\r
\r
// String omVersion = ModelicaManager.getDefaultOMVersion();\r
- String modelContent = ModelicaWriter.write(model.getModules(), start, false, "1.9");\r
+ String modelContent = ModelicaWriter.write(model.getModules(), start, isGame, "1.9");\r
\r
// update some stuff\r
FunctionUtils.updateFunctionFilesForExperiment(experiment);\r
public SolverType getType() {\r
return SolverType.INTERNAL;\r
}\r
+ \r
+ @Override\r
+ public double[] getSubscribedResults(double[] array) {\r
+ return solver.values();\r
+ }\r
+ \r
+ @Override\r
+ public double getTime() {\r
+ return solver.getTime();\r
+ }\r
+ \r
+ @Override\r
+ public void prepareToStep() throws Exception {\r
+ }\r
+ \r
+ @Override\r
+ public void setRealValue(String name, double value) throws Exception {\r
+ solver.setValue(name, value);\r
+ }\r
+\r
+ @Override\r
+ public void simulateStep() throws Exception {\r
+ solver.step();\r
+ }\r
+\r
+ @Override\r
+ public void setStepLength(double length) throws Exception {\r
+ solver.setStep(length);\r
+ }\r
\r
}\r
--- /dev/null
+package org.simantics.sysdyn.solver;\r
+\r
+import org.simantics.fmu.FMUJNIException;\r
+import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.solver.SolverSettings.SolverType;\r
+\r
+public class ModelicaSolver implements ISolver {\r
+ \r
+ SysdynGameExperiment exp;\r
+ \r
+ public ModelicaSolver(SysdynGameExperiment exp) {\r
+ this.exp = exp;\r
+ }\r
+ \r
+ @Override\r
+ public void initialize() throws Exception {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void buildModel() throws Exception {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void runSolver() throws Exception {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void updateResults() throws Exception {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+ @Override\r
+ public SolverType getType() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public double[] getSubscribedResults(double[] array) {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public void prepareToStep() throws Exception {\r
+\r
+ // initialize if not initialized\r
+ if(!exp.control.isInitialized()) {\r
+ exp.control.setTime(exp.startTime);\r
+ exp.control.initializeSimulation();\r
+ exp.clearResults();\r
+ // getInitialResultValues();\r
+ }\r
+\r
+ exp.control.setStepLength(exp.stepLength); // Set step length each time in case there has been changes\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void simulateStep() throws Exception {\r
+ exp.control.simulateStep();\r
+ }\r
+\r
+ @Override\r
+ public void setStepLength(double length) throws Exception {\r
+ exp.control.setStepLength(length);\r
+ }\r
+\r
+ @Override\r
+ public double getTime() {\r
+ if(exp.control != null) {\r
+ try {\r
+ return exp.control.getTime();\r
+ } catch (FMUJNIException e) {\r
+ }\r
+ }\r
+ return 0.0;\r
+ }\r
+\r
+ @Override\r
+ public void setRealValue(String name, double value) throws Exception {\r
+ exp.control.setRealValue(name, value);\r
+ }\r
+\r
+ \r
+}\r
// has changed, a new solver must be created\r
if (solver == null || !solver.getType().equals(type)) {\r
if (SolverType.INTERNAL.equals(type)) {\r
- solver = new InternalSolver(experiment, experiment.sysdynModel, solverMonitor);\r
+ solver = new InternalSolver(experiment, experiment.sysdynModel, false, solverMonitor);\r
}\r
else if (SolverType.OPENMODELICA.equals(type)) {\r
return new Status(Status.ERROR, pluginId, "The experiment should be reloaded");\r