1 package org.simantics.district.network.profile;
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;
14 public class ArrowLengthStyle extends ThrottledStyleBase<Double> {
16 private static final Double PENDING = Double.NaN;
17 private static final Double ONE = 1.0;
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 // Prevent PendingVariableExceptions from coming through
23 boolean wasSynchronous = graph.setSynchronous(true);
26 if (ds.arrowLengthProperty.isPresent()) {
27 length = Simantics.applySCLRead(graph, ds.arrowLengthProperty.get(), groupItem);
28 // System.out.println("read thickness: " + thickness + " : " + ds.arrowLengthProperty);
32 length = length * ds.arrowLengthGain + ds.arrowLengthBias;
39 graph.setSynchronous(wasSynchronous);
44 public void applyThrottledStyleForNode(EvaluationContext observer, INode node, Double value) {
45 // System.out.println("apply: " + node + " : " + value);
46 ConnectionNode n = (ConnectionNode) node;
47 if (value == PENDING) {
48 ((G2DSceneGraph)node.getRootNode()).setPending(node);
50 ((G2DSceneGraph)node.getRootNode()).clearPending(node);
52 for (INode nn : n.getNodes())
53 ProfileVariables.claimNodeProperty(nn, "arrowLength", value, observer);
57 protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
58 ((G2DSceneGraph)node.getRootNode()).clearPending(node);
59 ConnectionNode n = (ConnectionNode) node;
60 for (INode nn : n.getNodes())
61 ProfileVariables.claimNodeProperty(nn, "arrowLength", null, evaluationContext);