]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network/src/org/simantics/district/network/profile/VertexSizeStyle.java
First version of throttled profile results - configure via proeprty view
[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                 if (ds.vertexScaleProperty.isPresent()) {
24                         scaling = Simantics.applySCLRead(graph, ds.vertexScaleProperty.get(), groupItem);
25                         if (scaling == null) {
26                                 scaling = ONE;
27                         } else {
28 //                              System.out.println("read vertex scaling: " + scaling + " : " + ds.vertexScaleProperty);
29                                 scaling = scaling * ds.vertexScaleGain + ds.vertexScaleBias;
30 //                              System.out.println("RESULT: " + scaling);
31                         }
32                 }
33                 return scaling;
34         }
35
36         @Override
37         public void applyThrottledStyleForNode(EvaluationContext observer, INode node, Double value) {
38                 //System.out.println("apply: " + node + " : " + value);
39                 SingleElementNode n = (SingleElementNode) node;
40                 if (value == PENDING) {
41                         ((G2DSceneGraph)node.getRootNode()).setPending(node);
42                 } else {
43                         ((G2DSceneGraph)node.getRootNode()).clearPending(node);
44                 }
45                 if (value == null)
46                         value = ONE;
47                 for (INode nn : n.getNodes())
48                         ProfileVariables.claimNodeProperty(nn, "size", value, observer);
49         }
50
51         @Override
52         protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
53                 ((G2DSceneGraph)node.getRootNode()).clearPending(node);
54                 SingleElementNode n = (SingleElementNode) node;
55                 for (INode nn : n.getNodes())
56                         ProfileVariables.claimNodeProperty(nn, "size", ONE, evaluationContext);
57         }
58
59 }