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.diagram.profile.StyleBase;
9 import org.simantics.scenegraph.INode;
10 import org.simantics.scenegraph.g2d.G2DSceneGraph;
11 import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
12 import org.simantics.scenegraph.profile.EvaluationContext;
13 import org.simantics.scenegraph.profile.common.ProfileVariables;
15 public class VertexSizeStyle extends StyleBase<Double> {
17 private static final Double PENDING = Double.NaN;
18 private static final Double ONE = 1.0;
21 public Double calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
22 DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
24 if (ds.vertexScaleProperty.isPresent()) {
25 scaling = Simantics.applySCLRead(graph, ds.vertexScaleProperty.get(), groupItem);
26 if (scaling == null) {
29 // System.out.println("read vertex scaling: " + scaling + " : " + ds.vertexScaleProperty);
30 scaling = scaling * ds.vertexScaleGain + ds.vertexScaleBias;
31 // System.out.println("RESULT: " + scaling);
38 public void applyStyleForNode(EvaluationContext observer, INode node, Double value) {
39 //System.out.println("apply: " + node + " : " + value);
40 SingleElementNode n = (SingleElementNode) node;
41 if (value == PENDING) {
42 ((G2DSceneGraph)node.getRootNode()).setPending(node);
44 ((G2DSceneGraph)node.getRootNode()).clearPending(node);
48 for (INode nn : n.getNodes())
49 ProfileVariables.claimNodeProperty(nn, "size", value, observer);
53 protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
54 ((G2DSceneGraph)node.getRootNode()).clearPending(node);
55 SingleElementNode n = (SingleElementNode) node;
56 for (INode nn : n.getNodes())
57 ProfileVariables.claimNodeProperty(nn, "size", ONE, evaluationContext);