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