]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network/src/org/simantics/district/network/profile/EdgeThicknessStyle.java
First draft of vertex size adjusting district network diagram profiles
[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.diagram.profile.StyleBase;
9 import org.simantics.scenegraph.INode;
10 import org.simantics.scenegraph.g2d.G2DSceneGraph;
11 import org.simantics.scenegraph.g2d.nodes.ConnectionNode;
12 import org.simantics.scenegraph.profile.EvaluationContext;
13 import org.simantics.scenegraph.profile.common.ProfileVariables;
14
15 public class EdgeThicknessStyle extends StyleBase<Double> {
16
17         private static final Double PENDING = Double.NaN;
18         private static final Double ONE = 1.0;
19
20         @Override
21         public Double calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
22                 DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
23                 Double thickness = ONE;
24                 if (ds.edgeThicknessProperty.isPresent()) {
25                         thickness = Simantics.applySCLRead(graph, ds.edgeThicknessProperty.get(), groupItem);
26 //                      System.out.println("read thickness: " + thickness + " : " + ds.edgeThicknessProperty);
27                         if (thickness == null) {
28                                 thickness = ONE;
29                         } else {
30                                 thickness = thickness * ds.edgeThicknessGain + ds.edgeThicknessBias;
31                         }
32                 }
33                 return thickness;
34         }
35
36         @Override
37         public void applyStyleForNode(EvaluationContext observer, INode node, Double value) {
38 //              System.out.println("apply: " + node + " : " + value);
39                 ConnectionNode n = (ConnectionNode) 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, "stroke", value, observer);
49         }
50
51         @Override
52         protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
53                 ((G2DSceneGraph)node.getRootNode()).clearPending(node);
54                 ConnectionNode n = (ConnectionNode) node;
55                 for (INode nn : n.getNodes())
56                         ProfileVariables.claimNodeProperty(nn, "stroke", ONE, evaluationContext);
57         }
58
59 }