--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.charts.query;\r
+\r
+import java.util.UUID;\r
+\r
+import org.simantics.charts.ontology.ChartResource;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.BinaryRead;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.trend.configuration.TrendItem;\r
+import org.simantics.trend.configuration.TrendSpec;\r
+import org.simantics.trend.configuration.ViewProfile;\r
+import org.simantics.trend.configuration.YAxisMode;\r
+\r
+/**\r
+ * This query reads trend configuration (Resource) and returns TrendSpec.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class TrendSpecQuery extends BinaryRead<UUID, Resource, TrendSpec> {\r
+\r
+ public TrendSpecQuery(UUID id, Resource resource) {\r
+ super(id, resource);\r
+ }\r
+\r
+ @Override\r
+ public TrendSpec perform(ReadGraph graph) throws DatabaseException {\r
+ Resource chart = parameter2;\r
+\r
+ ChartResource CHART = ChartResource.getInstance(graph);\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ \r
+ TrendSpec spec = new TrendSpec();\r
+ spec.init();\r
+ if ( !graph.hasStatement(chart) ) return spec;\r
+ spec.name = graph.getPossibleRelatedValue(chart, L0.HasName, Bindings.STRING);\r
+ if (spec.name == null)\r
+ spec.name = "Unnamed Chart";\r
+\r
+ spec.axisMode = YAxisMode.MultiAxis;\r
+ Resource axisMode = graph.getPossibleObject(chart, CHART.Chart_YAxisMode);\r
+ if (CHART.YAxisMode_SingleAxis.equals(axisMode))\r
+ spec.axisMode = YAxisMode.SingleAxis;\r
+ else if (CHART.YAxisMode_MultiAxis.equals(axisMode))\r
+ spec.axisMode = YAxisMode.MultiAxis;\r
+ \r
+ readProfile(graph, chart, spec.viewProfile);\r
+\r
+ for (Resource plot : graph.syncRequest(new ObjectsWithType(chart, L0.ConsistsOf, CHART.Chart_Item))) {\r
+ TrendItem item = graph.sync( new TrendItemQuery(plot) );\r
+// if ( item.subscriptionId.equals("") ) continue;\r
+ spec.items.add( item );\r
+ }\r
+\r
+ spec.sortItems();\r
+ return spec;\r
+ }\r
+\r
+ private void readProfile(ReadGraph graph, Resource profile, ViewProfile viewProfile) throws DatabaseException {\r
+ viewProfile.profileName = "Custom Profile";\r
+ viewProfile.showMilestones = false;\r
+// viewProfile.timeWindow.timeWindowStart = 0.0;\r
+// viewProfile.timeWindow.timeWindowLength = 60.0;\r
+ viewProfile.timeWindow.timeWindowIncrement = 50.0;\r
+\r
+ if (profile != null) {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ ChartResource CHART = ChartResource.getInstance(graph);\r
+ String pn = graph.getPossibleRelatedValue(profile, L0.HasName);\r
+ if (pn != null)\r
+ viewProfile.profileName = pn;\r
+\r
+ viewProfile.showMilestones = Boolean.TRUE.equals( graph.getPossibleRelatedValue(profile, CHART.Chart_ShowMilestones, Bindings.BOOLEAN) );\r
+ viewProfile.showGrid = Boolean.TRUE.equals( graph.getPossibleRelatedValue(profile, CHART.Chart_showGrid, Bindings.BOOLEAN) );\r
+\r
+ Double windowStart = graph.getPossibleRelatedAdapter(profile, CHART.Chart_TimeWindowStart, Double.class);\r
+ if (windowStart != null && !Double.isNaN(windowStart))\r
+ viewProfile.timeWindow.timeWindowStart = windowStart;\r
+ Double windowLength = graph.getPossibleRelatedAdapter(profile, CHART.Chart_TimeWindowLength, Double.class);\r
+ if (windowLength != null)\r
+ viewProfile.timeWindow.timeWindowLength = windowLength;\r
+ Double windowIncrement = graph.getPossibleRelatedAdapter(profile, CHART.Chart_TimeWindowIncrement, Double.class);\r
+ if (windowIncrement != null)\r
+ viewProfile.timeWindow.timeWindowIncrement = windowIncrement;\r
+\r
+ Boolean trackExperimentTime = graph.getPossibleRelatedValue(profile, CHART.Chart_trackExperimentTime, Bindings.BOOLEAN);\r
+ if (trackExperimentTime != null)\r
+ viewProfile.trackExperimentTime = trackExperimentTime;\r
+ double[] valueViewPosition = graph.getPossibleRelatedValue(profile, CHART.Chart_valueViewPosition, Bindings.DOUBLE_ARRAY);\r
+ if (valueViewPosition != null && valueViewPosition.length >= 2) {\r
+ viewProfile.valueViewPositionX = valueViewPosition[0];\r
+ viewProfile.valueViewPositionY = valueViewPosition[1];\r
+ }\r
+\r
+ float[] bgColor = graph.getPossibleRelatedValue(profile, CHART.Chart_backgroundColor, Bindings.FLOAT_ARRAY);\r
+ if (bgColor != null && bgColor.length >= 3) {\r
+ viewProfile.backgroundColor = bgColor;\r
+ }\r
+\r
+ float[] gridColor = graph.getPossibleRelatedValue(profile, CHART.Chart_gridColor, Bindings.FLOAT_ARRAY);\r
+ if (gridColor != null && gridColor.length >= 3) {\r
+ viewProfile.gridColor = gridColor;\r
+ }\r
+ }\r
+ }\r
+\r
+}
\ No newline at end of file