X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fprofile%2FEdgeStyle.java;fp=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fprofile%2FEdgeStyle.java;h=4ee26ad4f7b00f1014668d78feeeed2d8443e0eb;hb=a3b6137601545ac6e3484995d0ec6d39224bbf3f;hp=0000000000000000000000000000000000000000;hpb=1e6f4461465fc45d71b30535d02bbe1cd7672d4a;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/EdgeStyle.java b/org.simantics.district.network/src/org/simantics/district/network/profile/EdgeStyle.java new file mode 100644 index 00000000..4ee26ad4 --- /dev/null +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/EdgeStyle.java @@ -0,0 +1,59 @@ +package org.simantics.district.network.profile; + +import org.simantics.databoard.Bindings; +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.ConnectionNode; +import org.simantics.scenegraph.profile.EvaluationContext; +import org.simantics.scenegraph.profile.common.ProfileVariables; + +public class EdgeStyle 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 thickness = ONE; + if (ds.edgeThicknessProperty.isPresent()) { + thickness = graph.getPossibleRelatedValue2(groupItem, ds.edgeThicknessProperty.get(), Bindings.DOUBLE); + //System.out.println("read thickness: " + thickness + " : " + ds.edgeThicknessProperty); + if (thickness == null) { + thickness = ONE; + } else { + thickness = thickness * ds.edgeThicknessScale; + } + } + return thickness; + } + + @Override + public void applyStyleForNode(EvaluationContext observer, INode node, Double value) { + //System.out.println("apply: " + node + " : " + value); + ConnectionNode n = (ConnectionNode) 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, "stroke", value, observer); + } + + @Override + protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) { + ((G2DSceneGraph)node.getRootNode()).clearPending(node); + ConnectionNode n = (ConnectionNode) node; + for (INode nn : n.getNodes()) + ProfileVariables.claimNodeProperty(nn, "stroke", ONE, evaluationContext); + } + +}