]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network/src/org/simantics/district/network/profile/VertexSizeStyle.java
Support showing ticks in DynamicVisualisations
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / profile / VertexSizeStyle.java
1 package org.simantics.district.network.profile;
2
3 import org.simantics.Simantics;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.scenegraph.INode;
9 import org.simantics.scenegraph.g2d.G2DSceneGraph;
10 import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
11 import org.simantics.scenegraph.profile.EvaluationContext;
12 import org.simantics.scenegraph.profile.common.ProfileVariables;
13
14 public class VertexSizeStyle extends ThrottledStyleBase<Double> {
15
16         private static final Double PENDING = Double.NaN;
17         private static final Double ONE = 1.0;
18
19         @Override
20         public Double calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
21                 DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
22                 Double scaling = ONE;
23                 // Prevent PendingVariableExceptions from coming through
24                 boolean wasSynchronous = graph.setSynchronous(true);
25                 try {
26                         if (ds.vertexScaleProperty.isPresent()) {
27                                 scaling = Simantics.applySCLRead(graph, ds.vertexScaleProperty.get(), groupItem);
28                                 if (scaling == null) {
29                                         scaling = ONE;
30                                 } else {
31         //                              System.out.println("read vertex scaling: " + scaling + " : " + ds.vertexScaleProperty);
32                                         scaling = scaling * ds.vertexScaleGain + ds.vertexScaleBias;
33         //                              System.out.println("RESULT: " + scaling);
34                                 }
35                         }
36                         return scaling;
37                 }
38                 finally {
39                         graph.setSynchronous(wasSynchronous);
40                 }
41         }
42
43         @Override
44         public void applyThrottledStyleForNode(EvaluationContext observer, INode node, Double value) {
45                 //System.out.println("apply: " + node + " : " + value);
46                 SingleElementNode n = (SingleElementNode) node;
47                 if (value == PENDING) {
48                         ((G2DSceneGraph)node.getRootNode()).setPending(node);
49                 } else {
50                         ((G2DSceneGraph)node.getRootNode()).clearPending(node);
51                 }
52                 if (value == null)
53                         value = ONE;
54                 for (INode nn : n.getNodes())
55                         ProfileVariables.claimNodeProperty(nn, "size", value, observer);
56         }
57
58         @Override
59         protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
60                 ((G2DSceneGraph)node.getRootNode()).clearPending(node);
61                 SingleElementNode n = (SingleElementNode) node;
62                 for (INode nn : n.getNodes())
63                         ProfileVariables.claimNodeProperty(nn, "size", ONE, evaluationContext);
64         }
65
66 }