Bundle-SymbolicName: org.simantics.modelica
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Require-Bundle: gnu.trove2;bundle-version="2.0.4"
+Require-Bundle: gnu.trove2;bundle-version="2.0.4",
+ org.simantics.databoard;bundle-version="0.5.2"
Export-Package: org.simantics.modelica,
org.simantics.modelica.data
*/\r
public class SimulationResult { \r
\r
- List<DataSet> dataSets = new ArrayList<DataSet>();\r
+ List<DataSet> variables = new ArrayList<DataSet>();\r
+ List<DataSet> initials = new ArrayList<DataSet>();\r
\r
static String getLine(InputStream stream) {\r
if(stream == null)\r
\r
for(String key : mappedInitials.keySet()) {\r
double[] values = {mappedInitials.get(key), mappedInitials.get(key)};\r
- dataSets.add(new DataSet(key, times , values));\r
+ initials.add(new DataSet(key, times , values));\r
}\r
}\r
\r
values.add(Double.parseDouble(nn[1]));\r
}\r
\r
- dataSets.add(new DataSet(name, times.toNativeArray(), values.toNativeArray()));\r
+ variables.add(new DataSet(name, times.toNativeArray(), values.toNativeArray()));\r
}\r
}\r
\r
public void filter() {\r
- ArrayList<DataSet> newDataSets = new ArrayList<DataSet>();\r
- for(DataSet dataSet : dataSets) {\r
- if(!dataSet.name.equals("time") && !dataSet.name.contains("$") && !dataSet.name.contains("der("))\r
- newDataSets.add(dataSet);\r
+ ArrayList<DataSet> newVariables = new ArrayList<DataSet>();\r
+ for(DataSet dataSet : variables) {\r
+ if(!dataSet.name.contains("$") && !dataSet.name.contains("der("))\r
+ newVariables.add(dataSet);\r
}\r
- dataSets = newDataSets;\r
+ variables = newVariables;\r
}\r
\r
- public List<DataSet> getDataSets() {\r
- return dataSets;\r
+ public List<DataSet> getVariableDataSets() {\r
+ return variables;\r
}\r
\r
+ /**\r
+ * Gets DataSet for variable. Loops first the variables and then initials. \r
+ * @param name the name of the variable\r
+ * @return DataSet for the variable or null if DataSet not found\r
+ */\r
public DataSet getDataSet(String name) {\r
- for(DataSet set : dataSets)\r
+ for(DataSet set : variables)\r
+ if(set.name.equals(name))\r
+ return set;\r
+ for(DataSet set : initials)\r
if(set.name.equals(name))\r
return set;\r
return null;\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 \r <type\r uri="http://www.simantics.org/Simulation-1.0/Types/Experiment"\r class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Simulation-1.0/Types/Run"\r class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r <this />\r </type>\r </target>\r \r
+ </target>\r \r <target\r interface="org.simantics.sysdyn.ui.browser.nodes.AbstractNode">\r <type\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/IndependentVariable"\r class="org.simantics.sysdyn.ui.browser.nodes.VariableNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Simulation-1.0/Types/Experiment"\r class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Result"\r class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r <this />\r </type>\r </target>\r \r
</adapters>
\ No newline at end of file
</menuContribution>\r
<menuContribution\r
locationURI="popup:#SysdynBrowserPopup?after=wbStart">\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.activateResult"\r
+ id="org.simantics.sysdyn.ui.browser.activateResult"\r
+ label="Activate"\r
+ style="push">\r
+ <visibleWhen\r
+ checkEnabled="true">\r
+ <with\r
+ variable="selection">\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </with>\r
+ </visibleWhen>\r
+ </command>\r
<dynamic\r
class="org.simantics.ui.contribution.OpenWithMenuContribution"\r
id="org.simantics.sysdyn.ui.browser.openWithMenu">\r
id="org.simantics.sysdyn.ui.saveResults"\r
name="Save Results">\r
</command>\r
+ <command\r
+ defaultHandler="org.simantics.sysdyn.ui.handlers.ToggleResultActivation"\r
+ id="org.simantics.sysdyn.ui.activateResult"\r
+ name="Activate Result">\r
+ </command>\r
</extension>\r
<extension\r
point="org.eclipse.ui.handlers">\r
</implementation>\r
</binding>\r
</extension>\r
+ <extension\r
+ point="org.simantics.browsing.ui.common.labelDecoratorBinding">\r
+ <binding\r
+ browseContext="http://www.simantics.org/Sysdyn-1.0/Browser">\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultDecorator"\r
+ preference="2.0">\r
+ </implementation>\r
+ </binding>\r
+ </extension>\r
<extension\r
point="org.eclipse.core.expressions.propertyTesters">\r
<propertyTester\r
\r
@Override\r
public String getLabel(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
- String name = graph.getPossibleRelatedValue(experiment.resource, graph.getBuiltins().HasName);\r
+ String name = graph.getPossibleRelatedValue(experiment.resource, graph.getBuiltins().HasLabel);\r
return name == null ? "Experiment (no name)" : name;\r
}\r
\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.SysdynResource;\r
import org.simantics.sysdyn.ui.browser.nodes.AbstractNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode;\r
\r
public Collection<?> getContribution(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
Builtins b = graph.getBuiltins();\r
- for(Resource r : graph.syncRequest(new ObjectsWithType(experiment.resource, b.ConsistsOf, b.Run))) {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(experiment.resource, sr.HasResult, sr.Result))) {\r
try {\r
result.add(graph.adapt(r, AbstractNode.class));\r
} catch(DatabaseException e) {\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.content.LabelDecorator;\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelDecoratorContributor;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode;\r
+\r
+public class SimulationResultDecorator extends LabelDecoratorContributor<SimulationResultNode>{\r
+\r
+ @Override\r
+ public LabelDecorator getDecorator(ReadGraph graph, SimulationResultNode result) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ if (graph.hasStatement(result.resource, b.IsActive)) {\r
+ return new LabelDecorator.Stub() {\r
+ @Override\r
+ public String decorateLabel(String label, String column, int itemIndex) {\r
+ return label + " [ACTIVE]";\r
+ }\r
+ };\r
+ }\r
+ return null;\r
+ }\r
+\r
+}\r
\r
@Override\r
public String getLabel(ReadGraph graph, SimulationResultNode result) throws DatabaseException {\r
- String name = graph.getPossibleRelatedValue(result.resource, graph.getBuiltins().HasName);\r
+ String name = graph.getPossibleRelatedValue(result.resource, graph.getBuiltins().HasLabel);\r
return name == null ? "Experiment (no name)" : name;\r
}\r
\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.browser.nodes;\r
\r
+import org.simantics.browsing.ui.common.node.IDeletable;\r
import org.simantics.browsing.ui.common.node.IDoubleClickableNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.browsing.ui.graph.impl.LabelModifier;\r
import org.simantics.db.Resource;\r
import org.simantics.project.IProject;\r
import org.simantics.simulation.project.IExperimentManager;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.ui.ErrorLogger;\r
\r
-public class ExperimentNode extends AbstractNode implements IDoubleClickableNode{\r
+public class ExperimentNode extends AbstractNode implements IDoubleClickableNode, IDeletable, IModifiableNode{\r
\r
public ExperimentNode(Resource resource) {\r
super(resource);\r
SysdynExperimentActivator.scheduleActivation(SimanticsUI.getSession(), project, experimentManager, resource);\r
return true;\r
}\r
+ \r
+ @Override\r
+ public Modifier getModifier(String columnId) {\r
+ LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), resource) {\r
+ @Override\r
+ public String isValid(String label) {\r
+ if (label.isEmpty())\r
+ return "Empty label not allowed";\r
+ return null;\r
+ }\r
+ };\r
+ return modifier;\r
+ }\r
\r
}\r
package org.simantics.sysdyn.ui.browser.nodes;\r
\r
import org.simantics.browsing.ui.common.node.IDeletable;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.browsing.ui.graph.impl.LabelModifier;\r
import org.simantics.db.Resource;\r
+import org.simantics.ui.SimanticsUI;\r
\r
-public class SimulationResultNode extends AbstractNode implements IDeletable {\r
+public class SimulationResultNode extends AbstractNode implements IDeletable, IModifiableNode {\r
\r
public SimulationResultNode(Resource resource) {\r
super(resource);\r
}\r
\r
+ \r
+ @Override\r
+ public Modifier getModifier(String columnId) {\r
+ LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), resource) {\r
+ @Override\r
+ public String isValid(String label) {\r
+ if (label.isEmpty())\r
+ return "Empty label not allowed";\r
+ return null;\r
+ }\r
+ };\r
+ return modifier;\r
+ }\r
}\r
Resource report = GraphUtils.create2(g, mu.b.Report, mu.b.HasDocumentation, "===Report===");\r
\r
Resource experiment = GraphUtils.create2(g, mu.b.Experiment,\r
- mu.b.HasName, "Experiment 1",\r
- mu.b.HasReportFactory, report,\r
- mu.b.PartOf, model);\r
- \r
- experiment = GraphUtils.create2(g, mu.b.Experiment,\r
- mu.b.HasName, "Experiment 2",\r
+ mu.b.HasName, "Experiment",\r
+ mu.b.HasLabel, "Experiment",\r
mu.b.HasReportFactory, report,\r
mu.b.PartOf, model);\r
}\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
+ System.out.println("MOIOI" + member);\r
project.setHint(ProjectKeys.KEY_SELECTED_UI_EXPERIMENT, member);\r
break;\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.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.db.Builtins;\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.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+\r
+public class ToggleResultActivation extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ Resource[] resources = ResourceAdaptionUtils.toResources(sel);\r
+ if (resources.length == 0)\r
+ return null;\r
+ \r
+ toggleActivation(resources);\r
+ \r
+ return null;\r
+ }\r
+\r
+ private void toggleActivation(final Resource[] resources) {\r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Builtins b = graph.getBuiltins();\r
+ for(Resource r : resources) {\r
+ if(graph.isInstanceOf(r, sr.Result)) {\r
+ if (graph.hasStatement(r, b.IsActive)) {\r
+ graph.deny(r, b.IsActive, r);\r
+ } else {\r
+ graph.claim(r, b.IsActive, r);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ });\r
+ } catch (DatabaseException e) {\r
+ \r
+ }\r
+ }\r
+}\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
- experiment = GraphUtils.create2(g, mu.b.Experiment,\r
- mu.b.HasName, "Experiment 2",\r
+ mu.b.HasLabel, "Experiment",\r
mu.b.HasReportFactory, report,\r
mu.b.PartOf, model);\r
\r
package org.simantics.sysdyn.ui.trend;\r
\r
import java.awt.Frame;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
import java.util.HashMap;\r
import java.util.Set;\r
\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.modelica.data.DataSet;\r
-import org.simantics.modelica.data.SimulationResult;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynDataSet;\r
import org.simantics.sysdyn.manager.SysdynModel;\r
import org.simantics.sysdyn.manager.SysdynModelManager;\r
+import org.simantics.sysdyn.manager.SysdynResult;\r
import org.simantics.sysdyn.representation.IElement;\r
import org.simantics.sysdyn.representation.Variable;\r
import org.simantics.ui.SimanticsUI;\r
\r
Frame frame;\r
ChartPanel panel;\r
- SysdynDataset sysdynDataset = new SysdynDataset();\r
- \r
+ SysdynDatasets sysdynDatasets = new SysdynDatasets();\r
+\r
+\r
@SuppressWarnings("serial")\r
- class SysdynDataset extends AbstractXYDataset {\r
+ class SysdynDatasets extends AbstractXYDataset {\r
+\r
+ SysdynDataSet[] sets = new SysdynDataSet[0];\r
\r
- DataSet[] sets = new DataSet[0];\r
- \r
- public void setDatasets(DataSet[] sets) {\r
+ public void setDatasets(SysdynDataSet[] sets) {\r
this.sets = sets;\r
fireDatasetChanged();\r
}\r
- \r
+\r
@Override\r
public Number getY(int series, int item) {\r
return sets[series].values[item];\r
}\r
- \r
+\r
@Override\r
public Number getX(int series, int item) {\r
return sets[series].times[item];\r
}\r
- \r
+\r
@Override\r
public int getItemCount(int series) {\r
return sets[series].times.length;\r
}\r
- \r
+\r
@SuppressWarnings("unchecked")\r
@Override\r
- public Comparable getSeriesKey(int series) {\r
- return sets[series].name;\r
+ public Comparable getSeriesKey(int series) { \r
+ SysdynDataSet sds = sets[series];\r
+ if(sds.result == null)\r
+ return sds.name;\r
+ else\r
+ return sds.name + " : " + sds.result;\r
}\r
- \r
+\r
@Override\r
public int getSeriesCount() { \r
return sets.length;\r
}\r
- \r
+\r
}\r
- \r
+\r
@Override\r
public void createPartControl(Composite parent) { \r
final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider();\r
getSite().setSelectionProvider(selectionProvider);\r
- \r
+\r
final Composite composite = new Composite(parent, \r
SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
frame = SWT_AWT.new_Frame(composite);\r
- \r
+\r
SwingUtilities.invokeLater(new Runnable() {\r
\r
@Override\r
public void run() { \r
XYPlot plot = new XYPlot(\r
- sysdynDataset,\r
+ sysdynDatasets,\r
new NumberAxis("time"),\r
new NumberAxis("x"),\r
new XYLineAndShapeRenderer(true, false)\r
- );\r
- \r
+ );\r
+\r
JFreeChart chart = new JFreeChart(plot);\r
panel = new ChartPanel(chart);\r
frame.add(panel);\r
- \r
+\r
panel.requestFocus();\r
}\r
- \r
+\r
});\r
- \r
+\r
getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(new ISelectionListener() {\r
- \r
+\r
@Override\r
public void selectionChanged(IWorkbenchPart part, ISelection selection) {\r
if(selection.isEmpty() || Boolean.TRUE.equals(PinTrend.getState()))\r
return;\r
if(selection instanceof IStructuredSelection) {\r
- Set<Resource> ress = ISelectionUtils.filterSetSelection(selection, Resource.class);\r
+ Set<Resource> ress = ISelectionUtils.filterSetSelection(selection, Resource.class);\r
// Object[] els = ((IStructuredSelection) selection).toArray();\r
// Resource[] resources = new Resource[els.length];\r
// for(int i=0;i<els.length;++i) {\r
} \r
}\r
});\r
- \r
- /*composite.getDisplay().asyncExec(new Runnable() {\r
+\r
+ /*composite.getDisplay().asyncExec(new Runnable() {\r
\r
@Override\r
public void run() {\r
// Do something\r
}\r
- \r
+\r
});*/ \r
}\r
- \r
+\r
Resource[] resources;\r
- \r
+\r
protected void setSelection(Resource[] resources) {\r
this.resources = resources;\r
updateView();\r
}\r
- \r
+\r
public void updateView() {\r
Session session = SimanticsUI.peekSession();\r
if (session == null)\r
session.asyncRequest(new ReadRequest() {\r
@Override\r
public void run(ReadGraph g) throws DatabaseException {\r
- \r
- final DataSet[] sets = new DataSet[resources.length];\r
- for(int i=0;i<resources.length;++i) {\r
- try {\r
- sets[i] = load(g, resources[i]);\r
- } catch(Exception e) {\r
- e.printStackTrace();\r
- return;\r
- }\r
- if(sets[i] == null)\r
- return;\r
- }\r
- \r
+\r
+ final ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
+ for(Resource resource : resources) {\r
+ Collection<SysdynDataSet> set = load(g, resource);\r
+ if(set == null) return;\r
+ datasets.addAll(load(g, resource));\r
+ }
+\r
SwingUtilities.invokeLater(new Runnable() {\r
\r
@Override\r
public void run() { \r
- sysdynDataset.setDatasets(sets);\r
+ sysdynDatasets.setDatasets(datasets.toArray(new SysdynDataSet[datasets.size()]));\r
}\r
- \r
+\r
});\r
- \r
+\r
}\r
});\r
}\r
- \r
+\r
Runnable updater = new Runnable() {\r
@Override\r
public void run() {\r
updateView();\r
} \r
};\r
- \r
+\r
HashMap<Resource, SysdynModel> models = new HashMap<Resource, SysdynModel>(); \r
protected SysdynModel getModel(ReadGraph g, Resource configuration) {\r
synchronized(models) {\r
return model;\r
}\r
}\r
- \r
- protected DataSet load(ReadGraph g, Resource resource) throws DatabaseException {\r
+\r
+ protected Collection<SysdynDataSet> load(ReadGraph g, Resource resource) throws DatabaseException {\r
Builtins b = g.getBuiltins();\r
SysdynResource sr = SysdynResource.getInstance(g);\r
- \r
+\r
ModelingResources mr = ModelingResources.getInstance(g);\r
Resource map = g.getPossibleObject(resource, mr.ElementToComponent);\r
if(map != null) resource = map;\r
- \r
+\r
if(g.isInstanceOf(resource, sr.Variable)) {\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
+\r
IElement element = model.getElement(resource);\r
if(element instanceof Variable) {\r
- Variable var = (Variable)element; \r
- SimulationResult result = model.getResult();\r
- if(result == null)\r
- return null;\r
- return result.getDataSet(var.getName());\r
+ Variable var = (Variable)element; \r
+\r
+ Collection<SysdynResult> activeResults = model.getActiveResults(g);\r
+ ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
+ for(SysdynResult r : activeResults) {\r
+ datasets.add(r.getDataSet(var.getName()));\r
+ }\r
+ return datasets;\r
} \r
\r
}\r
org.eclipse.ui.console;bundle-version="3.4.0",
org.eclipse.core.runtime;bundle-version="3.5.0",
org.eclipse.jface;bundle-version="3.5.2",
- org.simantics.project;bundle-version="1.0.0"
+ org.simantics.project;bundle-version="1.0.0",
+ org.simantics.layer0.utils;bundle-version="0.8.0"
Export-Package: org.simantics.sysdyn,
org.simantics.sysdyn.expressionParser,
org.simantics.sysdyn.manager,
public final Resource HasMaxY;\r
public final Resource HasMinX;\r
public final Resource HasMinY;\r
+ public final Resource HasParameterFile;\r
+ public final Resource HasResult;\r
+ public final Resource HasResultFile;\r
public final Resource HasStartTime;\r
public final Resource HasStopTime;\r
public final Resource HasTail;\r
public final Resource ParameterExpression;\r
public final Resource PhantomTerminal;\r
public final Resource RefersTo;\r
+ public final Resource Result;\r
public final Resource SimulateOnChangeExperiment;\r
public final Resource Stock;\r
public final Resource StockExpression;\r
public static final String HasMaxY = "http://www.simantics.org/Sysdyn-1.0/HasMaxY";\r
public static final String HasMinX = "http://www.simantics.org/Sysdyn-1.0/HasMinX";\r
public static final String HasMinY = "http://www.simantics.org/Sysdyn-1.0/HasMinY";\r
+ public static final String HasParameterFile = "http://www.simantics.org/Sysdyn-1.0/HasParameterFile";\r
+ public static final String HasResult = "http://www.simantics.org/Sysdyn-1.0/HasResult";\r
+ public static final String HasResultFile = "http://www.simantics.org/Sysdyn-1.0/HasResultFile";\r
public static final String HasStartTime = "http://www.simantics.org/Sysdyn-1.0/HasStartTime";\r
public static final String HasStopTime = "http://www.simantics.org/Sysdyn-1.0/HasStopTime";\r
public static final String HasTail = "http://www.simantics.org/Sysdyn-1.0/HasTail";\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 Result = "http://www.simantics.org/Sysdyn-1.0/Result";\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
HasMaxY = getResourceOrNull(graph, URIs.HasMaxY);\r
HasMinX = getResourceOrNull(graph, URIs.HasMinX);\r
HasMinY = getResourceOrNull(graph, URIs.HasMinY);\r
+ HasParameterFile = getResourceOrNull(graph, URIs.HasParameterFile);\r
+ HasResult = getResourceOrNull(graph, URIs.HasResult);\r
+ HasResultFile = getResourceOrNull(graph, URIs.HasResultFile);\r
HasStartTime = getResourceOrNull(graph, URIs.HasStartTime);\r
HasStopTime = getResourceOrNull(graph, URIs.HasStopTime);\r
HasTail = getResourceOrNull(graph, URIs.HasTail);\r
ParameterExpression = getResourceOrNull(graph, URIs.ParameterExpression);\r
PhantomTerminal = getResourceOrNull(graph, URIs.PhantomTerminal);\r
RefersTo = getResourceOrNull(graph, URIs.RefersTo);\r
+ Result = getResourceOrNull(graph, URIs.Result);\r
SimulateOnChangeExperiment = getResourceOrNull(graph, URIs.SimulateOnChangeExperiment);\r
Stock = getResourceOrNull(graph, URIs.Stock);\r
StockExpression = getResourceOrNull(graph, URIs.StockExpression);\r
--- /dev/null
+package org.simantics.sysdyn.manager;\r
+\r
+import org.simantics.modelica.data.DataSet;\r
+\r
+public class SysdynDataSet extends DataSet {\r
+\r
+ public String result;\r
+\r
+ public SysdynDataSet(String name, String result, double[] times, double[] values) {\r
+ super(name, times, values);\r
+ this.result = result;\r
+ }\r
+\r
+}\r
package org.simantics.sysdyn.manager;\r
\r
+import java.io.File;\r
+import java.util.ArrayList;\r
+import java.util.TreeMap;\r
+import java.util.UUID;\r
+\r
+import org.eclipse.core.runtime.Platform;\r
+import org.simantics.databoard.annotations.Optional;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.db.Builtins;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.Session;\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.exception.DatabaseException;\r
-import org.simantics.db.request.Read;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\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.SysdynResource;\r
import org.simantics.sysdyn.simulation.SimulationScheduler;\r
\r
public class SysdynExperiment extends Experiment implements IDynamicExperiment {\r
\r
Session session;\r
Runnable modificationListener;\r
+ Resource experiment;\r
+ SysdynModel sysdynModel;\r
+ SysdynResult result;\r
\r
- public SysdynExperiment(Resource model) {\r
+ public SysdynExperiment(Resource experiment, Resource model) {\r
super(model);\r
- System.out.println(this.getIdentifier());\r
+ this.experiment = experiment;\r
// TODO Auto-generated constructor stub\r
}\r
\r
public void saveState() {\r
// TODO Auto-generated method stub\r
System.out.println("saveState");\r
+\r
+ try {\r
+ session.syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ File root = new File(Platform.getLocation().toOSString(), "www.simantics.org");\r
+ if(!root.isDirectory())\r
+ root.mkdir();\r
+ File file = new File( root, UUID.randomUUID().toString() + ".dbb");\r
+ Builtins b = graph.getBuiltins();\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource res = GraphUtils.create2(graph, sr.Result,\r
+ b.HasLabel, "Result x",\r
+ b.HasName, "Result x",\r
+ sr.HasResultFile, file.getAbsolutePath());\r
+ graph.claim(experiment, sr.HasResult, res);\r
+ result.saveToFile(file);\r
+\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
}\r
\r
- /**\r
- * enabled: is simulate on change enabled\r
- */\r
+\r
@Override\r
public void simulate(boolean enabled) {\r
System.out.println("simulate");\r
}\r
\r
\r
- private SysdynModel startSimulation() {\r
+ private void startSimulation() {\r
try {\r
- return session.syncRequest(new Read<SysdynModel>() {\r
+ session.syncRequest(new ReadRequest() {\r
\r
@Override\r
- public SysdynModel perform(ReadGraph graph) throws DatabaseException {\r
- final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
- SysdynModel sysdynmodel = \r
- SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
- SimulationScheduler.start(sysdynmodel);\r
- return sysdynmodel;\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ SimulationScheduler.start(sysdynModel);\r
}\r
});\r
} catch (DatabaseException e) {\r
e.printStackTrace();\r
}\r
- return null;\r
}\r
\r
public void toggleSimulation(boolean enabled) {\r
if(enabled) {\r
changeState(ExperimentState.RUNNING);\r
- if(modificationListener == null) { \r
- SysdynModel sysdynModel = startSimulation();\r
-\r
+ if(modificationListener == null) { \r
+ \r
modificationListener = new Runnable() {\r
\r
@Override\r
@Override\r
public void run(ReadGraph graph) throws DatabaseException {\r
if(getState() == ExperimentState.RUNNING) {\r
- Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
- SysdynModel sysdynmodel = \r
- SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
- SimulationScheduler.start(sysdynmodel);\r
+ SimulationScheduler.start(sysdynModel);\r
}\r
\r
}\r
System.out.println("init");\r
changeState(ExperimentState.STOPPED);\r
this.session = g.getSession();\r
+ result = new SysdynResult();\r
+ \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 = SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
+ sysdynModel.addResultListener(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ result.setResult(sysdynModel.getSimulationResult());\r
+ }\r
+ });\r
+ }\r
+ });\r
+ \r
+ \r
}\r
\r
@Override\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
+ sysdynModel.removeModificationListener(modificationListener);\r
modificationListener = null;\r
\r
}\r
break;\r
}\r
}\r
+ \r
+ public static class Sample {\r
+ public double value;\r
+ \r
+ @Override\r
+ public String toString() {\r
+ return ""+value;\r
+ }\r
+ }\r
+ \r
+ public static class Segment {\r
+ public int startTime, endTime;\r
+ public ArrayList<Sample> samples;\r
+ \r
+ @Override\r
+ public String toString() {\r
+ return "[startTime="+startTime+", endTime="+endTime+", samples="+samples+"]";\r
+ }\r
+ \r
+ }\r
+\r
+ public static class Recording {\r
+ public String id;\r
+ public TreeMap<String, String> labels;\r
+ public ArrayList<Segment> segments;\r
+ \r
+ @Override\r
+ public String toString() {\r
+ return "id="+id+", labels="+labels+", segments="+segments;\r
+ }\r
+ \r
+ }\r
+\r
+ public static class RecordingSession {\r
+ public @Optional Variant datasource;\r
+ public Variant timeVarialbeId;\r
+ public TreeMap<Variant, Variant> recordings;\r
+ \r
+ @Override\r
+ public String toString() {\r
+ return recordings.toString();\r
+ }\r
+ }\r
+ \r
+ public static class NodeId {\r
+ public String nodeId;\r
+ }\r
\r
\r
}\r
+\r
package org.simantics.sysdyn.manager;\r
\r
import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
import java.util.HashMap;\r
import java.util.Map;\r
import java.util.concurrent.CopyOnWriteArrayList;\r
\r
+import org.simantics.db.Builtins;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.Session;\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.SysdynResource;\r
import org.simantics.sysdyn.modelica.ModelicaWriter;\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.IElement;\r
e.printStackTrace();\r
}\r
}\r
- \r
- \r
+\r
+\r
/*\r
* some dummy(?) stuff for experiments\r
*/\r
return false;\r
}\r
\r
- public SimulationResult getResult() {\r
+ public SimulationResult getSimulationResult() {\r
return result;\r
}\r
\r
\r
@Override\r
public IExperiment loadExperiment(ReadGraph g, Resource experiment, IExperimentActivationListener listener) {\r
- SysdynExperiment exp = new SysdynExperiment(configurationResource);\r
+ SysdynExperiment exp = new SysdynExperiment(experiment, configurationResource);\r
try {\r
exp.init(g);\r
listener.onExperimentActivated(exp);\r
return null;\r
}\r
} \r
+\r
+ public Collection<SysdynResult> getActiveResults(ReadGraph graph) {\r
+ ArrayList<SysdynResult> results = new ArrayList<SysdynResult>();\r
+\r
+ try {\r
+ Builtins b = graph.getBuiltins();\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource model = graph.getSingleObject(configurationResource, b.IsConfigurationOf);\r
+ Collection<Resource> experiments = graph.getObjects(model, b.ConsistsOf);\r
+ for(Resource experiment : experiments) {\r
+ Collection<Resource> experimentResults = graph.getObjects(experiment, sr.HasResult);\r
+ for(Resource result : experimentResults) {\r
+ if(graph.hasStatement(result, b.IsActive)) {\r
+ SysdynResult sysdynResult = new SysdynResult(\r
+ (String) graph.getPossibleRelatedValue(result, b.HasLabel),\r
+ (String) graph.getPossibleRelatedValue(result, sr.HasResultFile));\r
+ results.add(sysdynResult);\r
+ }\r
+ }\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ if(getSimulationResult() != null)\r
+ results.add(0, new SysdynResult(getSimulationResult()));\r
+\r
+\r
+\r
+ return results;\r
+ }\r
+\r
}\r
--- /dev/null
+package org.simantics.sysdyn.manager;\r
+\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.TreeMap;\r
+\r
+import org.simantics.databoard.Accessors;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.accessor.Accessor;\r
+import org.simantics.databoard.accessor.MapAccessor;\r
+import org.simantics.databoard.accessor.RecordAccessor;\r
+import org.simantics.databoard.accessor.VariantAccessor;\r
+import org.simantics.databoard.accessor.binary.BinaryRecord;\r
+import org.simantics.databoard.accessor.binary.BinaryVariant;\r
+import org.simantics.databoard.accessor.error.AccessorConstructionException;\r
+import org.simantics.databoard.accessor.error.AccessorException;\r
+import org.simantics.databoard.accessor.java.JavaRecord;\r
+import org.simantics.databoard.annotations.Optional;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.binding.error.BindingConstructionException;\r
+import org.simantics.databoard.binding.error.BindingException;\r
+import org.simantics.databoard.binding.java.StringJavaBinding;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.databoard.binding.mutable.VariantContainerBinding;\r
+import org.simantics.databoard.serialization.SerializationException;\r
+import org.simantics.modelica.data.DataSet;\r
+import org.simantics.modelica.data.SimulationResult;\r
+\r
+public class SysdynResult {\r
+ \r
+ RecordingSession recordingSession;\r
+ RecordAccessor accessor;\r
+ String resultName;\r
+\r
+ public SysdynResult() {\r
+\r
+ }\r
+\r
+ public SysdynResult(SimulationResult result) {\r
+ if(result != null)\r
+ setResult(result);\r
+ }\r
+\r
+ public SysdynResult(String result, String path) {\r
+ this.resultName = result;\r
+ File file = new File(path);\r
+ try {\r
+ BinaryVariant bv = (BinaryVariant)Accessors.openFile(file);\r
+ BinaryRecord br = bv.getValueAccessor();\r
+ accessor = br;\r
+ } catch (AccessorConstructionException e) {\r
+ e.printStackTrace();\r
+ } \r
+ }\r
+\r
+ public Accessor getAccessor() {\r
+ try {\r
+ return Accessors.getAccessor(recordingSession);\r
+ } catch (AccessorConstructionException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return null;\r
+ }\r
+\r
+ public void setResult(SimulationResult result) {\r
+ try { \r
+ Binding stringBinding = StringJavaBinding.INSTANCE;\r
+ Binding recordBinding = Bindings.getBinding( Recording.class );\r
+ \r
+ recordingSession = new RecordingSession();\r
+ recordingSession.recordings = new TreeMap<Variant, Variant>();\r
+ Variant timeVariableId = new Variant();\r
+ timeVariableId.setValue(stringBinding, "timeVariableId");\r
+ recordingSession.timeVariableId = timeVariableId;\r
+ \r
+\r
+\r
+ for(DataSet ds : result.getVariableDataSets()){\r
+ Recording rec = new Recording();\r
+ rec.labels = new TreeMap<String, String>();\r
+ String name = ds.name;\r
+ rec.id = name;\r
+ rec.labels.put("en", name); \r
+ rec.segments = new ArrayList<Segment>(); \r
+\r
+ Segment seg = new Segment();\r
+ seg.startTime = 0;\r
+ seg.endTime = ds.values.length;\r
+ seg.samples = new ArrayList<Sample>();\r
+ for(double value : ds.values) {\r
+ Sample samp = new Sample();\r
+ samp.value = value;\r
+ seg.samples.add(samp); \r
+ }\r
+\r
+ rec.segments.add(seg);\r
+\r
+ Variant tmpVariant = new Variant();\r
+ Variant tmpVariant2 = new Variant();\r
+ tmpVariant.setValue(recordBinding, rec);\r
+ tmpVariant2.setValue(stringBinding, name);\r
+ recordingSession.recordings.put(tmpVariant2, tmpVariant);\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ } \r
+ }\r
+\r
+ public void saveToFile(File file) {\r
+ try {\r
+ Binding binding = Bindings.getBinding( recordingSession.getClass() );\r
+ Accessors.createFile(file, binding, recordingSession);\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ } catch (BindingConstructionException e) {\r
+ e.printStackTrace();\r
+ } catch (SerializationException e) {\r
+ e.printStackTrace();\r
+ } catch (BindingException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ }\r
+\r
+\r
+ public static class Sample {\r
+ public double value;\r
+\r
+ @Override\r
+ public String toString() {\r
+ return ""+value;\r
+ }\r
+ }\r
+\r
+ public static class Segment {\r
+ public int startTime, endTime;\r
+ public ArrayList<Sample> samples;\r
+\r
+ @Override\r
+ public String toString() {\r
+ return "[startTime="+startTime+", endTime="+endTime+", samples="+samples+"]";\r
+ }\r
+\r
+ }\r
+\r
+ public static class Recording {\r
+ public String id;\r
+ public TreeMap<String, String> labels;\r
+ public ArrayList<Segment> segments;\r
+\r
+ @Override\r
+ public String toString() {\r
+ return "id="+id+", labels="+labels+", segments="+segments;\r
+ }\r
+\r
+ }\r
+\r
+ public static class RecordingSession {\r
+ public @Optional Variant datasource;\r
+ public Variant timeVariableId;\r
+ public TreeMap<Variant, Variant> recordings;\r
+\r
+ @Override\r
+ public String toString() {\r
+ return recordings.toString();\r
+ }\r
+ }\r
+\r
+ public static class NodeId {\r
+ public String nodeId;\r
+ }\r
+ \r
+ public SysdynDataSet getDataSet(String variable) {\r
+ if(accessor == null && recordingSession != null) {\r
+ try {\r
+ Binding recordBinding = Bindings.getBinding( RecordingSession.class );\r
+ accessor = (JavaRecord)Accessors.getAccessor(recordBinding, recordingSession);\r
+ } catch (AccessorConstructionException e) {\r
+ e.printStackTrace();\r
+ } catch (BindingConstructionException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ if(accessor != null) {\r
+ MapAccessor ma;\r
+ try {\r
+ ma = accessor.getFieldAccessor("recordings");\r
+ } catch (AccessorConstructionException e1) {\r
+ e1.printStackTrace();\r
+ return null;\r
+ }\r
+ Binding stringBinding = StringJavaBinding.INSTANCE;\r
+ Variant tmpVariant = new Variant();\r
+ tmpVariant.setValue(stringBinding, variable);\r
+ Variant tmpVariant2 = new Variant();\r
+ tmpVariant2.setValue(stringBinding, "time");\r
+ Recording rec;\r
+ Recording time;\r
+ try {\r
+ VariantAccessor va = ma.getValueAccessor( VariantContainerBinding.INSTANCE, tmpVariant);\r
+ Accessor valueAccessor = va.getValueAccessor();\r
+ rec = (Recording)valueAccessor.getValue( Bindings.getBinding(Recording.class));\r
+ \r
+ va = ma.getValueAccessor( VariantContainerBinding.INSTANCE, tmpVariant2);\r
+ valueAccessor = va.getValueAccessor();\r
+ time = (Recording)valueAccessor.getValue( Bindings.getBinding(Recording.class));\r
+ if( rec == null || time == null) return null;\r
+ } catch (AccessorException e) {\r
+ e.printStackTrace();\r
+ return null;\r
+ } catch (BindingConstructionException e) {\r
+ e.printStackTrace();\r
+ return null;\r
+ } catch (AccessorConstructionException e) {\r
+ e.printStackTrace();\r
+ return null;\r
+ }\r
+ ArrayList<Sample> samples = rec.segments.get(0).samples;\r
+ double[] values = new double[samples.size()];\r
+ ArrayList<Sample> timeSamples = time.segments.get(0).samples;\r
+ double[] times = new double[samples.size()];\r
+ for(int i = 0; i < samples.size(); i++) {\r
+ values[i] = samples.get(i).value;\r
+ times[i] = timeSamples.get(i).value;\r
+ }\r
+ return new SysdynDataSet(variable, resultName, times, values);\r
+ }\r
+ return null;\r
+ }\r
+}\r
L0.Asserts _ : L0.Assertion\r
L0.HasPredicate $pred\r
L0.HasObject $obj\r
+ \r
+%define tag($pred)\r
+ $subject\r
+ $pred $subject\r
\r
######################################################################\r
# Defines ontology and attaches it to SimanticsDomain\r
Symbols : L0.Library\r
\r
SysdynProject : PROJ.Feature\r
- PROJ.LifecycleFeature\r
- SysdynProject\r
+ tag(PROJ.LifecycleFeature)\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
L0.HasRange L0.String\r
\r
IndependentVariable <T Variable\r
- [L0.HasName card "1"]\r
+ \r
[HasType card "1"]\r
[HasUnit card "0..1"]\r
[HasExpression card "0..1"] \r
######################################################################\r
\r
Experiment <T L0.Entity\r
+ [HasResult]\r
+\r
\r
BasicExperiment <T Experiment\r
\r
\r
SimulateOnChangeExperiment <T Experiment\r
\r
+HasResult <R L0.IsRelatedTo\r
+ L0.HasRange [Result]\r
+\r
+######################################################################\r
+# Results\r
+######################################################################\r
+\r
+Result <T L0.Entity\r
+ SIMU.IsActive\r
+ [L0.HasName card "1"]\r
+ [HasParameterFile card "0..1"]\r
+ [HasResultFile card "0..1"]\r
+\r
+HasParameterFile <R L0.HasProperty\r
+ L0.HasRange L0.String \r
+\r
+HasResultFile <R L0.HasProperty\r
+ L0.HasRange L0.String\r
+\r
+ \r
######################################################################\r
# Symbols\r
######################################################################\r