1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.charts.query;
\r
14 import java.util.UUID;
\r
16 import org.simantics.charts.ontology.ChartResource;
\r
17 import org.simantics.databoard.Bindings;
\r
18 import org.simantics.db.ReadGraph;
\r
19 import org.simantics.db.Resource;
\r
20 import org.simantics.db.common.request.BinaryRead;
\r
21 import org.simantics.db.common.request.ObjectsWithType;
\r
22 import org.simantics.db.exception.DatabaseException;
\r
23 import org.simantics.layer0.Layer0;
\r
24 import org.simantics.trend.configuration.TrendItem;
\r
25 import org.simantics.trend.configuration.TrendSpec;
\r
26 import org.simantics.trend.configuration.ViewProfile;
\r
27 import org.simantics.trend.configuration.YAxisMode;
\r
30 * This query reads trend configuration (Resource) and returns TrendSpec.
\r
32 * @author Tuukka Lehtonen
\r
34 public class TrendSpecQuery extends BinaryRead<UUID, Resource, TrendSpec> {
\r
36 public TrendSpecQuery(UUID id, Resource resource) {
\r
37 super(id, resource);
\r
41 public TrendSpec perform(ReadGraph graph) throws DatabaseException {
\r
42 Resource chart = parameter2;
\r
44 ChartResource CHART = ChartResource.getInstance(graph);
\r
45 Layer0 L0 = Layer0.getInstance(graph);
\r
47 TrendSpec spec = new TrendSpec();
\r
49 if ( !graph.hasStatement(chart) ) return spec;
\r
50 spec.name = graph.getPossibleRelatedValue(chart, L0.HasName, Bindings.STRING);
\r
51 if (spec.name == null)
\r
52 spec.name = "Unnamed Chart";
\r
54 spec.axisMode = YAxisMode.MultiAxis;
\r
55 Resource axisMode = graph.getPossibleObject(chart, CHART.Chart_YAxisMode);
\r
56 if (CHART.YAxisMode_SingleAxis.equals(axisMode))
\r
57 spec.axisMode = YAxisMode.SingleAxis;
\r
58 else if (CHART.YAxisMode_MultiAxis.equals(axisMode))
\r
59 spec.axisMode = YAxisMode.MultiAxis;
\r
61 readProfile(graph, chart, spec.viewProfile);
\r
63 for (Resource plot : graph.syncRequest(new ObjectsWithType(chart, L0.ConsistsOf, CHART.Chart_Item))) {
\r
64 TrendItem item = graph.sync( new TrendItemQuery(plot) );
\r
65 // if ( item.subscriptionId.equals("") ) continue;
\r
66 spec.items.add( item );
\r
73 private void readProfile(ReadGraph graph, Resource profile, ViewProfile viewProfile) throws DatabaseException {
\r
74 viewProfile.profileName = "Custom Profile";
\r
75 viewProfile.showMilestones = false;
\r
76 // viewProfile.timeWindow.timeWindowStart = 0.0;
\r
77 // viewProfile.timeWindow.timeWindowLength = 60.0;
\r
78 viewProfile.timeWindow.timeWindowIncrement = 50.0;
\r
80 if (profile != null) {
\r
81 Layer0 L0 = Layer0.getInstance(graph);
\r
82 ChartResource CHART = ChartResource.getInstance(graph);
\r
83 String pn = graph.getPossibleRelatedValue(profile, L0.HasName);
\r
85 viewProfile.profileName = pn;
\r
87 viewProfile.showMilestones = Boolean.TRUE.equals( graph.getPossibleRelatedValue(profile, CHART.Chart_ShowMilestones, Bindings.BOOLEAN) );
\r
88 viewProfile.showGrid = Boolean.TRUE.equals( graph.getPossibleRelatedValue(profile, CHART.Chart_showGrid, Bindings.BOOLEAN) );
\r
90 Double windowStart = graph.getPossibleRelatedAdapter(profile, CHART.Chart_TimeWindowStart, Double.class);
\r
91 if (windowStart != null && !Double.isNaN(windowStart))
\r
92 viewProfile.timeWindow.timeWindowStart = windowStart;
\r
93 Double windowLength = graph.getPossibleRelatedAdapter(profile, CHART.Chart_TimeWindowLength, Double.class);
\r
94 if (windowLength != null)
\r
95 viewProfile.timeWindow.timeWindowLength = windowLength;
\r
96 Double windowIncrement = graph.getPossibleRelatedAdapter(profile, CHART.Chart_TimeWindowIncrement, Double.class);
\r
97 if (windowIncrement != null)
\r
98 viewProfile.timeWindow.timeWindowIncrement = windowIncrement;
\r
100 Boolean trackExperimentTime = graph.getPossibleRelatedValue(profile, CHART.Chart_trackExperimentTime, Bindings.BOOLEAN);
\r
101 if (trackExperimentTime != null)
\r
102 viewProfile.trackExperimentTime = trackExperimentTime;
\r
103 double[] valueViewPosition = graph.getPossibleRelatedValue(profile, CHART.Chart_valueViewPosition, Bindings.DOUBLE_ARRAY);
\r
104 if (valueViewPosition != null && valueViewPosition.length >= 2) {
\r
105 viewProfile.valueViewPositionX = valueViewPosition[0];
\r
106 viewProfile.valueViewPositionY = valueViewPosition[1];
\r
109 float[] bgColor = graph.getPossibleRelatedValue(profile, CHART.Chart_backgroundColor, Bindings.FLOAT_ARRAY);
\r
110 if (bgColor != null && bgColor.length >= 3) {
\r
111 viewProfile.backgroundColor = bgColor;
\r
114 float[] gridColor = graph.getPossibleRelatedValue(profile, CHART.Chart_gridColor, Bindings.FLOAT_ARRAY);
\r
115 if (gridColor != null && gridColor.length >= 3) {
\r
116 viewProfile.gridColor = gridColor;
\r