X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=inline;f=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fprofile%2FVertexSizeStyle.java;fp=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fprofile%2FVertexSizeStyle.java;h=b33cd1c0851f1b1d786e001cf0567a8a2d96def5;hb=3354c578fb8e65421d0fdb123310232ccdc597cf;hp=0000000000000000000000000000000000000000;hpb=437c54d4e0501d31b5476e12a041a23a6905bffa;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSizeStyle.java b/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSizeStyle.java new file mode 100644 index 00000000..b33cd1c0 --- /dev/null +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSizeStyle.java @@ -0,0 +1,60 @@ +package org.simantics.district.network.profile; + +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.profile.StyleBase; +import org.simantics.scenegraph.INode; +import org.simantics.scenegraph.g2d.G2DSceneGraph; +import org.simantics.scenegraph.g2d.nodes.SingleElementNode; +import org.simantics.scenegraph.profile.EvaluationContext; +import org.simantics.scenegraph.profile.common.ProfileVariables; + +public class VertexSizeStyle extends StyleBase { + + private static final Double PENDING = Double.NaN; + private static final Double ONE = 1.0; + + @Override + public Double calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException { + DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance()); + Double scaling = ONE; + if (ds.vertexScaleProperty.isPresent()) { + scaling = Simantics.applySCLRead(graph, ds.vertexScaleProperty.get(), groupItem); + if (scaling == null) { + scaling = ONE; + } else { +// System.out.println("read vertex scaling: " + scaling + " : " + ds.vertexScaleProperty); + scaling = scaling * ds.vertexScaleGain + ds.vertexScaleBias; +// System.out.println("RESULT: " + scaling); + } + } + return scaling; + } + + @Override + public void applyStyleForNode(EvaluationContext observer, INode node, Double value) { + //System.out.println("apply: " + node + " : " + value); + SingleElementNode n = (SingleElementNode) node; + if (value == PENDING) { + ((G2DSceneGraph)node.getRootNode()).setPending(node); + } else { + ((G2DSceneGraph)node.getRootNode()).clearPending(node); + } + if (value == null) + value = ONE; + for (INode nn : n.getNodes()) + ProfileVariables.claimNodeProperty(nn, "size", value, observer); + } + + @Override + protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) { + ((G2DSceneGraph)node.getRootNode()).clearPending(node); + SingleElementNode n = (SingleElementNode) node; + for (INode nn : n.getNodes()) + ProfileVariables.claimNodeProperty(nn, "size", ONE, evaluationContext); + } + +}