SYSDYN.Experiment <T SIMU.Experiment
>-- SYSDYN.Experiment.result --> SYSDYN.Result <R L0.IsComposedOf
-
+ >-- SYSDYN.Experiment.resultSet --> SYSDYN.ResultSet <R L0.IsComposedOf
+
SYSDYN.BasicExperiment <T SYSDYN.Experiment
SYSDYN.GameExperiment <T SYSDYN.Experiment
@L0.symmetric
>-- SYSDYN.Result.time --> L0.Long <R L0.HasProperty : L0.FunctionalRelation
-
SYSDYN.HistoryDataset <T SYSDYN.Result
@L0.singleProperty L0.HasName
@L0.singleProperty L0.HasLabel
>-- SYSDYN.HistoryDataset.columns --> L0.Boolean <R L0.HasProperty // Is the data in columns. If false, data is in rows
>-- SYSDYN.HistoryDataset.sheet --> SHEET.Spreadsheet <R L0.IsRelatedTo : L0.FunctionalRelation
+SYSDYN.ResultSet <T L0.Entity
+ >-- SYSDYN.Experiment.result --> SYSDYN.Result <R L0.IsComposedOf
//#####################################################################
//#####################################################################
public final Resource Experiment_Run_time;\r
public final Resource Experiment_Run_time_Inverse;\r
public final Resource Experiment_result;\r
+ public final Resource Experiment_resultSet;\r
+ public final Resource Experiment_resultSet_Inverse;\r
public final Resource Experiment_result_Inverse;\r
public final Resource ExportModuleTree;\r
public final Resource Expression;\r
public final Resource Redeclaration_replacingEnumeration;\r
public final Resource Redeclaration_replacingEnumeration_Inverse;\r
public final Resource Result;\r
+ public final Resource ResultSet;\r
public final Resource Result_parameterFile;\r
public final Resource Result_parameterFile_Inverse;\r
public final Resource Result_resultFile;\r
public static final String Experiment_Run_time = "http://www.simantics.org/Sysdyn-1.1/Experiment/Run/time";\r
public static final String Experiment_Run_time_Inverse = "http://www.simantics.org/Sysdyn-1.1/Experiment/Run/time/Inverse";\r
public static final String Experiment_result = "http://www.simantics.org/Sysdyn-1.1/Experiment/result";\r
+ public static final String Experiment_resultSet = "http://www.simantics.org/Sysdyn-1.1/Experiment/resultSet";\r
+ public static final String Experiment_resultSet_Inverse = "http://www.simantics.org/Sysdyn-1.1/Experiment/resultSet/Inverse";\r
public static final String Experiment_result_Inverse = "http://www.simantics.org/Sysdyn-1.1/Experiment/result/Inverse";\r
public static final String ExportModuleTree = "http://www.simantics.org/Sysdyn-1.1/ExportModuleTree";\r
public static final String Expression = "http://www.simantics.org/Sysdyn-1.1/Expression";\r
public static final String Redeclaration_replacingEnumeration = "http://www.simantics.org/Sysdyn-1.1/Redeclaration/replacingEnumeration";\r
public static final String Redeclaration_replacingEnumeration_Inverse = "http://www.simantics.org/Sysdyn-1.1/Redeclaration/replacingEnumeration/Inverse";\r
public static final String Result = "http://www.simantics.org/Sysdyn-1.1/Result";\r
+ public static final String ResultSet = "http://www.simantics.org/Sysdyn-1.1/ResultSet";\r
public static final String Result_parameterFile = "http://www.simantics.org/Sysdyn-1.1/Result/parameterFile";\r
public static final String Result_parameterFile_Inverse = "http://www.simantics.org/Sysdyn-1.1/Result/parameterFile/Inverse";\r
public static final String Result_resultFile = "http://www.simantics.org/Sysdyn-1.1/Result/resultFile";\r
Experiment_Run_time = getResourceOrNull(graph, URIs.Experiment_Run_time);\r
Experiment_Run_time_Inverse = getResourceOrNull(graph, URIs.Experiment_Run_time_Inverse);\r
Experiment_result = getResourceOrNull(graph, URIs.Experiment_result);\r
+ Experiment_resultSet = getResourceOrNull(graph, URIs.Experiment_resultSet);\r
+ Experiment_resultSet_Inverse = getResourceOrNull(graph, URIs.Experiment_resultSet_Inverse);\r
Experiment_result_Inverse = getResourceOrNull(graph, URIs.Experiment_result_Inverse);\r
ExportModuleTree = getResourceOrNull(graph, URIs.ExportModuleTree);\r
Expression = getResourceOrNull(graph, URIs.Expression);\r
Redeclaration_replacingEnumeration = getResourceOrNull(graph, URIs.Redeclaration_replacingEnumeration);\r
Redeclaration_replacingEnumeration_Inverse = getResourceOrNull(graph, URIs.Redeclaration_replacingEnumeration_Inverse);\r
Result = getResourceOrNull(graph, URIs.Result);\r
+ ResultSet = getResourceOrNull(graph, URIs.ResultSet);\r
Result_parameterFile = getResourceOrNull(graph, URIs.Result_parameterFile);\r
Result_parameterFile_Inverse = getResourceOrNull(graph, URIs.Result_parameterFile_Inverse);\r
Result_resultFile = getResourceOrNull(graph, URIs.Result_resultFile);\r
</command>\r
<command\r
commandId="org.simantics.sysdyn.ui.newSensitivityAnalysisExperiment"\r
- icon="platform:/plugin/com.famfamfam.silk/icons/rainbow.png"\r
+ icon="icons/time_rainbow.png"\r
id="org.simantics.sysdyn.ui.browser.newSensitivityAnalysisExperiment"\r
label="Sensitivity Analysis Experiment"\r
style="push">\r
</with>\r
</visibleWhen>\r
</command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.activateResultSet"\r
+ id="org.simantics.sysdyn.ui.browser.activateResultSet"\r
+ label="Show in charts"\r
+ style="push">\r
+ <visibleWhen\r
+ checkEnabled="true">\r
+ <with\r
+ variable="selection">\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.SimulationResultSetNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </with>\r
+ </visibleWhen>\r
+ </command>\r
<command\r
commandId="org.simantics.sysdyn.ui.renameNode"\r
icon="platform:/plugin/com.famfamfam.silk/icons/textfield_rename.png"\r
id="org.simantics.sysdyn.ui.activateResult"\r
name="Show in charts">\r
</command>\r
+ <command\r
+ defaultHandler="org.simantics.sysdyn.ui.handlers.ToggleResultSetActivation"\r
+ id="org.simantics.sysdyn.ui.activateResultSet"\r
+ name="Show in charts">\r
+ </command>\r
<command\r
defaultHandler="org.simantics.sysdyn.ui.handlers.newComponents.NewExperimentNodeHandler"\r
id="org.simantics.sysdyn.ui.newExperiment"\r
args="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
</test>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.SimulationResultSetNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
<test\r
args="org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
args="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
</test>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.SimulationResultSetNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
<test\r
args="org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
class="org.simantics.sysdyn.ui.browser.contributions.SimulationResult"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultSet"\r
+ preference="2.0">\r
+ </implementation>\r
<implementation\r
class="org.simantics.sysdyn.ui.browser.contributions.Configuration"\r
preference="2.0">\r
class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultLabeler"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultSetLabeler"\r
+ preference="2.0">\r
+ </implementation>\r
<implementation\r
class="org.simantics.sysdyn.ui.browser.contributions.ModuleLabeler"\r
preference="2.0">\r
class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultImager"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultSetImager"\r
+ preference="2.0">\r
+ </implementation>\r
<implementation\r
class="org.simantics.sysdyn.ui.browser.contributions.ChartImager"\r
preference="2.0">\r
class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultDecorator"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultSetDecorator"\r
+ preference="2.0">\r
+ </implementation>\r
<implementation\r
class="org.simantics.sysdyn.ui.browser.contributions.ExperimentLabelDecorator"\r
preference="2.0">\r
name="Activate result in charts"\r
priority="250.0">\r
</doubleClickAction> \r
+ <doubleClickAction\r
+ class="org.simantics.sysdyn.ui.browser.actions.ActivateResultSetDatasetAction"\r
+ name="Activate result in charts"\r
+ priority="240.0">\r
+ </doubleClickAction> \r
<doubleClickAction\r
class="org.simantics.sysdyn.ui.browser.actions.OpenSheetAction"\r
name="Open Spreadsheet"\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.ui.browser.actions;\r
+\r
+import java.util.Collection;\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.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.DoubleClickEvent;\r
+import org.simantics.ui.IDoubleClickAction;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+\r
+/**\r
+ * Activates the result datasets of a result set to be shown in charts and other result visualizations\r
+ * \r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class ActivateResultSetDatasetAction implements IDoubleClickAction {\r
+\r
+ @Override\r
+ public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException {\r
+ final Resource resultSet = ResourceAdaptionUtils.toSingleResource(e.getResource());\r
+ if (resultSet == null)\r
+ return;\r
+\r
+ ReadGraph graph = e.getGraph();\r
+\r
+ if(graph.isInstanceOf(resultSet, SysdynResource.getInstance(graph).ResultSet)) {\r
+\r
+ graph.getSession().asyncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ if(graph.isInstanceOf(resultSet, sr.ResultSet)) {\r
+ // If there is at least one result which shown, clear them all.\r
+ // If not one result is shown, show them all.\r
+ boolean resultShown = false;\r
+ Collection<Resource> results = graph.getObjects(resultSet, sr.Experiment_result); \r
+ for (Resource result : results) {\r
+ if (graph.hasStatement(result, sr.Result_showResult)) {\r
+ resultShown = true;\r
+ break;\r
+ }\r
+ }\r
+ for (Resource result : results) {\r
+ if (resultShown) { \r
+ graph.denyStatement(result, sr.Result_showResult, result);\r
+ } else {\r
+ graph.claim(result, sr.Result_showResult, result);\r
+ }\r
+ }\r
+ } \r
+ }\r
+ });\r
+ e.consume();\r
+ }\r
+\r
+ }\r
+\r
+}\r
else if(graph.isInstanceOf(node.data, sr.GameExperiment))\r
image = "icons/time_go.png";\r
else if(graph.isInstanceOf(node.data, sr.SensitivityAnalysisExperiment))\r
- image = "icons/rainbow.png";\r
+ image = "icons/time_rainbow.png";\r
else\r
image = "icons/time.png";\r
} else if (node instanceof InputNode)\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode;\r
import org.simantics.sysdyn.ui.browser.nodes.HistoryDataNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.SimulationResultSetNode;\r
\r
-public class SimulationResult extends ViewpointContributor<ExperimentNode> {\r
+public class SimulationResult extends ViewpointContributor<AbstractNode<Resource>> {\r
\r
- @SuppressWarnings("unchecked")\r
@Override\r
- public Collection<?> getContribution(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
+ public Collection<?> getContribution(ReadGraph graph, AbstractNode<Resource> node) throws DatabaseException {\r
ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
- for(final Resource r : graph.syncRequest(new ObjectsWithType(experiment.data, sr.Experiment_result, sr.Result))) {\r
+ if (!(node instanceof ExperimentNode || node instanceof SimulationResultSetNode))\r
+ return result;\r
+ for(final Resource r : graph.syncRequest(new ObjectsWithType(node.data, sr.Experiment_result, sr.Result))) {\r
if(graph.isInstanceOf(r, sr.HistoryDataset)) {\r
- result.add(graph.adapt(r, AbstractNode.class));\r
- } else {\r
result.add(new HistoryDataNode(r));\r
+ } else {\r
+ result.add(new SimulationResultNode<Resource>(r));\r
\r
String resultPath = (String)graph.getPossibleRelatedValue(r, sr.Result_resultFile);\r
File file = new File(resultPath);\r
}\r
};\r
}\r
- return null;\r
+ return new LabelDecorator.Stub() {\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public <F> F decorateFont(F font, String column, int itemIndex) {\r
+ return (F) ((FontDescriptor) font).withStyle(SWT.NORMAL);\r
+ }\r
+ };\r
}\r
\r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010, 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.ui.browser.contributions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.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.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.SimulationResultSetNode;\r
+\r
+public class SimulationResultSet extends ViewpointContributor<ExperimentNode> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
+ ArrayList<SimulationResultSetNode> results = new ArrayList<SimulationResultSetNode>();\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ for(final Resource r : graph.syncRequest(new ObjectsWithType(experiment.data, sr.Experiment_resultSet, sr.ResultSet))) {\r
+ results.add(new SimulationResultSetNode(r));\r
+ }\r
+ return results;\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010, 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.ui.browser.contributions;\r
+\r
+import org.eclipse.jface.resource.FontDescriptor;\r
+import org.eclipse.swt.SWT;\r
+import org.simantics.browsing.ui.content.LabelDecorator;\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelDecoratorContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.SimulationResultSetNode;\r
+\r
+public class SimulationResultSetDecorator extends LabelDecoratorContributor<SimulationResultSetNode>{\r
+\r
+ @Override\r
+ public LabelDecorator getDecorator(ReadGraph graph, SimulationResultSetNode resultSet) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ for (Resource result : graph.getObjects(resultSet.data, sr.Experiment_result)) {\r
+ if (graph.hasStatement(result, sr.Result_showResult)) {\r
+ return new LabelDecorator.Stub() {\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public <F> F decorateFont(F font, String column, int itemIndex) {\r
+ return (F) ((FontDescriptor) font).withStyle(SWT.BOLD);\r
+ }\r
+ };\r
+ }\r
+ }\r
+ return new LabelDecorator.Stub() {\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public <F> F decorateFont(F font, String column, int itemIndex) {\r
+ return (F) ((FontDescriptor) font).withStyle(SWT.NORMAL);\r
+ }\r
+ };\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010, 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.ui.browser.contributions;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.simantics.browsing.ui.swt.ImagerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.sysdyn.ui.browser.nodes.SimulationResultSetNode;\r
+\r
+public class SimulationResultSetImager extends ImagerContributor<SimulationResultSetNode>{\r
+\r
+ @Override\r
+ public ImageDescriptor getDescriptor(ReadGraph graph, SimulationResultSetNode resultSet) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ for (Resource result : graph.getObjects(resultSet.data, sr.Experiment_result)) {\r
+ if (graph.hasStatement(result, sr.Result_showResult)) {\r
+ return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar_3.png"));\r
+ }\r
+ }\r
+ return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar_3_blackAndWhite.png"));\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010, 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.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.ui.browser.nodes.SimulationResultSetNode;\r
+\r
+public class SimulationResultSetLabeler extends LabelerContributor<SimulationResultSetNode>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, SimulationResultSetNode resultSet) throws DatabaseException {\r
+ String name = graph.getPossibleRelatedValue(resultSet.data, Layer0.getInstance(graph).HasLabel);\r
+ return name == null ? "Experiment (no name)" : name;\r
+ }\r
+\r
+}\r
if(results != null)\r
for(Resource result : results) \r
SimulationResultNode.unlinkResult(graph, result);\r
+ Collection<Resource> resultSets = graph.getObjects(data, SysdynResource.getInstance(graph).Experiment_resultSet);\r
+ if(resultSets != null)\r
+ for(Resource resultSet : resultSets) \r
+ SimulationResultSetNode.unlinkResultSet(graph, resultSet);\r
RemoverUtil.remove(graph, data);\r
}\r
});\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010, 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.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.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.db.WriteGraph;\r
+import org.simantics.db.common.request.ObjectsWithType;\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.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.handlers.ToggleResultSetActivation;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+\r
+public class SimulationResultSetNode extends AbstractNode<Resource> implements IDoubleClickableNode, IDeletableNode, IModifiableNode {\r
+\r
+ public SimulationResultSetNode(Resource resource) {\r
+ super(resource);\r
+ }\r
+ \r
+ \r
+ @Override\r
+ public Modifier getModifier(String columnId) {\r
+ LabelModifier modifier = new LabelModifier(SimanticsUI.getSession(), data) {\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
+ @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
+ unlinkResultSet(graph, data);\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ ExceptionUtils.logAndShowError(e);\r
+ }\r
+ \r
+ }\r
+ \r
+ \r
+ public static void unlinkResultSet(WriteGraph graph, Resource resultSet) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ for (Resource result : graph.syncRequest(new ObjectsWithType(resultSet, sr.Experiment_result, sr.Result))) {\r
+ SimulationResultNode.unlinkResult(graph, result);\r
+ }\r
+ RemoverUtil.remove(graph, resultSet);\r
+ }\r
+\r
+ @Override\r
+ public boolean handleDoubleClick() {\r
+ Resource[] resources = {data};\r
+ ToggleResultSetActivation.toggleActivation(resources);\r
+ return true;\r
+ }\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010, 2011 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.Collection;\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.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 ToggleResultSetActivation 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
+ public static 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
+ for(Resource r : resources) {\r
+ // If there is at least one result which shown, clear them all.\r
+ // If not one result is shown, show them all.\r
+ boolean resultShown = false;\r
+ Collection<Resource> results = graph.getObjects(r, sr.Experiment_result); \r
+ for (Resource result : results) {\r
+ if (graph.hasStatement(result, sr.Result_showResult)) {\r
+ resultShown = true;\r
+ break;\r
+ }\r
+ }\r
+ for (Resource result : results) {\r
+ if (resultShown) { \r
+ graph.denyStatement(result, sr.Result_showResult, result);\r
+ } else {\r
+ graph.claim(result, sr.Result_showResult, result);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ });\r
+ } catch (DatabaseException e) {\r
+\r
+ }\r
+ }\r
+}\r
if(result != null) resultPaths.put(resultFile, result);\r
}\r
}\r
+ for(Resource resultSet : graph.getObjects(experiment, sr.Experiment_resultSet)) {\r
+ for(Resource result : graph.getObjects(resultSet, sr.Experiment_result)) {\r
+ if(!graph.isInstanceOf(result, sr.HistoryDataset)) {\r
+ String resultFile = (String)graph.getPossibleRelatedValue(result, sr.Result_resultFile);\r
+ if(result != null) resultPaths.put(resultFile, result);\r
+ }\r
+ }\r
+ }\r
}\r
}\r
}\r
result.add(r);\r
}\r
}\r
+ Collection<Resource> experimentResultSets = graph.getObjects(experiment, SR.Experiment_resultSet);\r
+ for(Resource resultSet : experimentResultSets) {\r
+ experimentResults = graph.getObjects(resultSet, SR.Experiment_result);\r
+ for(Resource r : experimentResults) {\r
+ if(graph.hasStatement(r, SR.Result_showResult)) {\r
+ result.add(r);\r
+ }\r
+ }\r
+ }\r
}\r
\r
return result;\r
protected IStatus run(IProgressMonitor monitor) {\r
this.monitor = monitor;\r
int resultItemsNumber = sysdynResult.numberOfVariables();\r
- monitor.beginTask("Save result", resultItemsNumber * 2); \r
+ monitor.beginTask("Save result", resultItemsNumber * 2 + 1); \r
try {\r
// Create result file\r
file = session.syncRequest(new Read<File>() {\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010, 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
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.manager;\r
+\r
+import java.io.File;\r
+import java.util.ArrayList;\r
+import java.util.UUID;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.core.runtime.jobs.Job;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\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.request.WriteResultRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+/**\r
+ * Class for saving simulation result sets.\r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class SaveResultSetJob extends Job {\r
+\r
+ private final ArrayList<MemoryResult> sysdynResults;\r
+ private final SysdynExperiment experiment;\r
+ private final Session session;\r
+ private IProgressMonitor monitor;\r
+ private File file;\r
+\r
+ public SaveResultSetJob(final SysdynExperiment experiment, Session session, final ArrayList<MemoryResult> results) {\r
+ super("Save Results");\r
+ this.experiment = experiment;\r
+ this.sysdynResults = results;\r
+ this.session = session;\r
+ }\r
+\r
+ @Override\r
+ protected IStatus run(IProgressMonitor monitor) {\r
+ this.monitor = monitor;\r
+ if (sysdynResults == null || sysdynResults.size() == 0)\r
+ return Status.CANCEL_STATUS;\r
+ int resultItemsNumber = sysdynResults.get(0).numberOfVariables() * sysdynResults.size();\r
+ monitor.beginTask("Save results", resultItemsNumber * 2 + 2); \r
+ \r
+ try {\r
+ // Create a ResultSet, under which the individual results are stored, and\r
+ // add it under the experiment within the model browser. \r
+\r
+ final Resource resultSetResource = session.syncRequest(new WriteResultRequest<Resource>() {\r
+\r
+ @Override\r
+ public Resource perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource model = graph.getSingleObject(experiment.getResource(), l0.PartOf);\r
+ String name = NameUtils.findFreshName(graph, "ResultSet", model, l0.ConsistsOf, "%s%d");\r
+\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource res = GraphUtils.create2(graph, sr.ResultSet,\r
+ l0.HasLabel, name,\r
+ l0.HasName, name,\r
+ l0.PartOf, model,\r
+ sr.Result_time, System.currentTimeMillis());\r
+ graph.claim(experiment.getResource(), sr.Experiment_resultSet, res);\r
+ return res;\r
+ }\r
+ });\r
+ monitor.worked(1);\r
+ \r
+ // Save the individual results\r
+ for (int i = 0; i < sysdynResults.size(); ++i) {\r
+ MemoryResult result = sysdynResults.get(i);\r
+ final String name = new Integer(i+1).toString();\r
+ // Create result file\r
+ file = session.syncRequest(new Read<File>() {\r
+\r
+ @Override\r
+ public File perform(ReadGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ Resource model = graph.getSingleObject(experiment.getResource(), l0.PartOf);\r
+ Resource project = graph.getSingleObject(model, l0.PartOf);\r
+ String projectName = graph.getPossibleRelatedValue(project, l0.HasName);\r
+ File root = new File(Platform.getLocation().toOSString(), "www.simantics.org");\r
+ if(!root.isDirectory()) root.mkdir();\r
+ File projectRoot = new File(root, projectName);\r
+ if(!projectRoot.isDirectory()) projectRoot.mkdir();\r
+ File file = new File( projectRoot, UUID.randomUUID().toString() + ".dbb");\r
+ return file;\r
+ }\r
+ });\r
+\r
+ // Start the saving operation\r
+ Thread saveThread = experiment.getSaveThread(result, file, SaveResultSetJob.this.monitor);\r
+ saveThread.run();\r
+\r
+ // Add the result under the ResultSet within the model browser. \r
+ session.syncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ String resultSetName = graph.getRelatedValue(resultSetResource, l0.HasName);\r
+ \r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource res = GraphUtils.create2(graph, sr.Result,\r
+ l0.HasLabel, name,\r
+ l0.HasName, resultSetName + "#" + name,\r
+ sr.Result_resultFile, file.getAbsolutePath(),\r
+ sr.Result_time, System.currentTimeMillis());\r
+ graph.claim(resultSetResource, sr.Experiment_result, res);\r
+ }\r
+ });\r
+\r
+ }\r
+\r
+ } catch (DatabaseException e1) {\r
+ // TODO Auto-generated catch block\r
+ e1.printStackTrace();\r
+ }\r
+\r
+ monitor.done(); \r
+ return Status.OK_STATUS;\r
+ }\r
+\r
+ @Override\r
+ public boolean belongsTo(Object family) {\r
+ return "SaveResultSetJob".equals(family);\r
+ }\r
+\r
+ @Override\r
+ protected void canceling() {\r
+\r
+ }\r
+\r
+}\r
public void saveState() {\r
if(results == null || !(results instanceof ArrayList<?>)) \r
return;\r
- //SaveResultJob saveResultJob = new SaveResultJob(SysdynSensitivityAnalysisExperiment.this, session, results);\r
- //saveResultJob.schedule();\r
+ SaveResultSetJob saveResultSetJob = new SaveResultSetJob((SysdynExperiment)this, session, results);\r
+ saveResultSetJob.schedule();\r
}\r
\r
@Override\r