]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Work around one active experiment per model limitation for FMI studio. 04/104/4
authorjsimomaa <jani.simomaa@gmail.com>
Tue, 27 Sep 2016 10:59:37 +0000 (13:59 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 27 Sep 2016 12:27:21 +0000 (15:27 +0300)
refs #6711

Change-Id: I78a98ca08b81828a728f8bd0ab4c338a064a04fd

bundles/org.simantics.charts/src/org/simantics/charts/Charts.java
bundles/org.simantics.charts/src/org/simantics/charts/ITrendSupport.java

index dd7ae02a08bf809c4b5aaa607a7681e89af5520b..1358c402333b40a42d425e66acaef6faf339af42 100644 (file)
@@ -1,77 +1,75 @@
-package org.simantics.charts;\r
-\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import org.simantics.Simantics;\r
-import org.simantics.charts.editor.ChartData;\r
-import org.simantics.charts.editor.ChartKeys;\r
-import org.simantics.databoard.binding.error.BindingException;\r
-import org.simantics.databoard.util.Bean;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.PossibleIndexRoot;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.history.HistoryException;\r
-import org.simantics.history.HistorySamplerItem;\r
-import org.simantics.history.ItemManager;\r
-import org.simantics.history.util.subscription.SamplingFormat;\r
-import org.simantics.modeling.subscription.SubscriptionItem;\r
-import org.simantics.modeling.subscription.SubscriptionItemQuery;\r
-import org.simantics.project.IProject;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
-\r
-/**\r
- * Main facade for externally dealing with the trending system.\r
- * \r
- * @author Tuukka Lehtonen\r
- * @author Antti Villberg\r
- * \r
- */\r
-public final class Charts {\r
-\r
-    public static void resetChartEditorData(IProject project, Resource model, ChartData editorData) {\r
-        if (editorData != null) {\r
-            project.setHint(ChartKeys.chartSourceKey(model), editorData);\r
-        } else {\r
-            project.removeHint(ChartKeys.chartSourceKey(model));\r
-        }\r
-    }\r
-\r
-       public static HistorySamplerItem createHistorySamplerItem(ReadGraph graph, Resource subscriptionItem) throws DatabaseException {\r
-               \r
-               try {\r
-\r
-                       Resource model = graph.syncRequest(new PossibleIndexRoot(subscriptionItem));\r
-                       if ( model == null ) {\r
-                               throw new DatabaseException("There is no model for " + subscriptionItem);\r
-                       }\r
-\r
-                       Key chartDataKey = ChartKeys.chartSourceKey(model);\r
-\r
-                       final ChartData data = Simantics.getProject().getHint(chartDataKey);\r
-                       if ( data == null ) {\r
-                               throw new DatabaseException("There is no chart data for " + model);\r
-                       }\r
-\r
-                       ItemManager im = new ItemManager( data.history.getItems() );\r
-\r
-                       SubscriptionItem i = graph.syncRequest(new SubscriptionItemQuery(subscriptionItem));\r
-\r
-                       List<Bean> items = im.search("variableId", i.variableId);\r
-                       Collections.sort(items, SamplingFormat.INTERVAL_COMPARATOR);\r
-                       if (items.isEmpty()) new DatabaseException("There is history item for " + i.variableId);\r
-                       Bean config = items.get(0);\r
-                       String historyId = (String) config.getFieldUnchecked("id");\r
-\r
-                       return new HistorySamplerItem(data.collector, data.history, historyId, System.identityHashCode(data));\r
-\r
-               } catch (HistoryException e) {\r
-                       throw new DatabaseException(e);\r
-               } catch (BindingException e) {\r
-                       throw new DatabaseException(e);\r
-               }\r
-       \r
-       }\r
-\r
-}\r
+package org.simantics.charts;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.simantics.charts.editor.ChartData;
+import org.simantics.charts.editor.ChartKeys;
+import org.simantics.databoard.binding.error.BindingException;
+import org.simantics.databoard.util.Bean;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.PossibleIndexRoot;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.history.HistoryException;
+import org.simantics.history.HistorySamplerItem;
+import org.simantics.history.ItemManager;
+import org.simantics.history.util.subscription.SamplingFormat;
+import org.simantics.modeling.subscription.SubscriptionItem;
+import org.simantics.modeling.subscription.SubscriptionItemQuery;
+import org.simantics.project.IProject;
+import org.simantics.simulation.experiment.IExperiment;
+
+/**
+ * Main facade for externally dealing with the trending system.
+ * 
+ * @author Tuukka Lehtonen
+ * @author Antti Villberg
+ * 
+ */
+public final class Charts {
+
+    public static void resetChartEditorData(IProject project, Resource model, ChartData editorData) {
+        if (editorData != null) {
+            project.setHint(ChartKeys.chartSourceKey(model), editorData);
+        } else {
+            project.removeHint(ChartKeys.chartSourceKey(model));
+        }
+    }
+
+       public static HistorySamplerItem createHistorySamplerItem(ReadGraph graph, Variable run, Resource subscriptionItem) throws DatabaseException {
+                       IExperiment exp = (IExperiment) run.getPropertyValue(graph, "iExperiment");
+                       ITrendSupport support = exp.getService(ITrendSupport.class);
+                       ChartData data = support.getChartData();
+                       return createHistorySamplerItem(graph, subscriptionItem, data);
+       }
+
+    public static HistorySamplerItem createHistorySamplerItem(ReadGraph graph, Resource subscriptionItem, ChartData data) throws DatabaseException {
+
+        try {
+            Resource model = graph.syncRequest(new PossibleIndexRoot(subscriptionItem));
+            if (model == null) {
+                throw new DatabaseException("There is no model for " + subscriptionItem);
+            }
+
+            ItemManager im = new ItemManager(data.history.getItems());
+
+            SubscriptionItem i = graph.syncRequest(new SubscriptionItemQuery(subscriptionItem));
+
+            List<Bean> items = im.search("variableId", i.variableId);
+            Collections.sort(items, SamplingFormat.INTERVAL_COMPARATOR);
+            if (items.isEmpty())
+                new DatabaseException("There is history item for " + i.variableId);
+            Bean config = items.get(0);
+            String historyId = (String) config.getFieldUnchecked("id");
+
+            return new HistorySamplerItem(data.collector, data.history, historyId, System.identityHashCode(data));
+        } catch (HistoryException e) {
+            throw new DatabaseException(e);
+        } catch (BindingException e) {
+            throw new DatabaseException(e);
+        }
+    }
+
+}
index c7a1f84a286c64ff3ff428240cd686ee629d2673..d1c374e60b94c41ae650060863a426ceb906ffe2 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.charts;\r
 \r
+import org.simantics.charts.editor.ChartData;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.exception.DatabaseException;\r
 \r
@@ -7,4 +8,6 @@ public interface ITrendSupport {
 \r
        void setChartData(ReadGraph graph) throws DatabaseException;\r
        \r
+       ChartData getChartData();\r
+       \r
 }\r