1 package org.simantics.district.network.profile;
5 import org.simantics.Simantics;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.layer0.Layer0;
11 import org.simantics.scenegraph.INode;
12 import org.simantics.scenegraph.g2d.G2DSceneGraph;
13 import org.simantics.scenegraph.g2d.nodes.ConnectionNode;
14 import org.simantics.scenegraph.profile.EvaluationContext;
15 import org.simantics.scenegraph.profile.common.ProfileVariables;
17 public class ArrowLengthStyle extends ThrottledStyleBase<Double> {
19 private static final Double PENDING = Double.NaN;
22 public Double calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
23 Resource diagram = graph.getSingleObject(groupItem, Layer0.getInstance(graph).PartOf);
24 Set<Resource> edgesToUse = graph.syncRequest(new MidBranchEdgeSetRequest(diagram), TransientCacheListener.instance());
25 if (!edgesToUse.contains(groupItem))
28 DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheListener.instance());
29 // Prevent PendingVariableExceptions from coming through
30 boolean wasSynchronous = graph.setSynchronous(true);
32 if (ds.arrowLengthProperty.isPresent()) {
33 Double length = Simantics.applySCLRead(graph, ds.arrowLengthProperty.get(), groupItem);
34 return length != null ? length * ds.arrowLengthGain + ds.arrowLengthBias : null;
41 graph.setSynchronous(wasSynchronous);
46 public void applyThrottledStyleForNode(EvaluationContext observer, INode node, Double value) {
47 // System.out.println("apply: " + node + " : " + value);
48 ConnectionNode n = (ConnectionNode) node;
49 if (value == PENDING) {
50 ((G2DSceneGraph)node.getRootNode()).setPending(node);
52 ((G2DSceneGraph)node.getRootNode()).clearPending(node);
54 for (INode nn : n.getNodes())
55 ProfileVariables.claimNodeProperty(nn, "arrowLength", value, observer);
59 protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
60 ((G2DSceneGraph)node.getRootNode()).clearPending(node);
61 ConnectionNode n = (ConnectionNode) node;
62 for (INode nn : n.getNodes())
63 ProfileVariables.claimNodeProperty(nn, "arrowLength", null, evaluationContext);