private MapScalingTransform() {
}
public static final double scale = 256.0d / 360.0d;
- public static final AffineTransform INSTANCE = new AffineTransform(scale, 0, 0, scale, 0, 0);
+ public static final AffineTransform INSTANCE = AffineTransform.getScaleInstance(scale, scale);
+ public static final AffineTransform INVERSE = AffineTransform.getScaleInstance(1/scale, 1/scale);
public static double getScaleX() {
return INSTANCE.getScaleX();
public class NetworkDrawingParticipant extends AbstractDiagramParticipant {
- @Dependency
+ public static final String NETWORK_DRAWING_NODE = "networkDrawingNode";
+
+ @Dependency
PickContext pick;
/**
@SGInit
public void initSG(G2DParentNode parent) {
- node = parent.addNode("networkDrawingNode", NetworkDrawingNode.class);
+ node = parent.addNode(NETWORK_DRAWING_NODE, NetworkDrawingNode.class);
node.setTransform(transform);
node.setNetworkDrawingParticipant(this);
}
// snap.removeAll(pickables);
boolean changed = false;
- changed = hoverVertexNodes(snap, false, isConnectionTool, changed);
- changed = hoverEdgeNodes(snap, false, isConnectionTool, changed);
- changed = hoverVertexNodes(pickables, true, isConnectionTool, changed);
- changed = hoverEdgeNodes(pickables, true, isConnectionTool, changed);
+ changed = hoverVertexNodes(snap, false, isConnectionTool, changed, currentMousePos);
+ changed = hoverEdgeNodes(snap, false, isConnectionTool, changed, currentMousePos);
+ changed = hoverVertexNodes(pickables, true, isConnectionTool, changed, currentMousePos);
+ changed = hoverEdgeNodes(pickables, true, isConnectionTool, changed, currentMousePos);
return changed;
}
- private boolean hoverVertexNodes(List<IElement> elements, boolean hover, boolean isConnectionTool, boolean changed) {
+ private boolean hoverVertexNodes(List<IElement> elements, boolean hover, boolean isConnectionTool, boolean changed, Point2D p) {
for (IElement elem : elements) {
Node node = elem.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
if (node instanceof DistrictNetworkVertexNode) {
changed = ((DistrictNetworkVertexNode) node).hover(hover, isConnectionTool) || changed;
+ if (hover)
+ ((DistrictNetworkVertexNode) node).setMousePosition(p);
}
}
return changed;
}
- private boolean hoverEdgeNodes(List<IElement> elements, boolean hover, boolean isConnectionTool, boolean changed) {
+ private boolean hoverEdgeNodes(List<IElement> elements, boolean hover, boolean isConnectionTool, boolean changed, Point2D p) {
for (IElement elem : elements) {
Node node = elem.getHint(DistrictNetworkEdgeElement.KEY_DN_EDGE_NODE);
if (node instanceof DistrictNetworkEdgeNode) {
for (IG2DNode n : ((DistrictNetworkEdgeNode) node).getNodes()) {
if (n instanceof HoverSensitiveNode) {
changed = ((HoverSensitiveNode)n).hover(hover, isConnectionTool) || changed;
+ if (hover)
+ ((HoverSensitiveNode)n).setMousePosition(p);
}
}
}
--- /dev/null
+package org.simantics.district.network.ui.nodes;
+
+import java.awt.Graphics2D;
+
+public interface DeferredNode {
+ void renderDeferred(Graphics2D g);
+}
--- /dev/null
+package org.simantics.district.network.ui.nodes;
+
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.simantics.scenegraph.g2d.G2DNode;
+import org.simantics.utils.datastructures.Pair;
+
+public class DeferredRenderingNode extends G2DNode {
+
+ private static final long serialVersionUID = 1L;
+
+ List<Pair<AffineTransform, DeferredNode>> queue = new LinkedList<>();
+
+ @Override
+ public void render(Graphics2D g2d) {
+ AffineTransform currentTransform = g2d.getTransform();
+
+ ListIterator<Pair<AffineTransform, DeferredNode>> listIterator = queue.listIterator();
+ while (listIterator.hasNext()) {
+ Pair<AffineTransform, DeferredNode> node = listIterator.next();
+ listIterator.remove();
+
+ g2d.setTransform(node.first);
+ node.second.renderDeferred(g2d);
+ }
+
+ g2d.setTransform(currentTransform);
+ }
+
+ @Override
+ public Rectangle2D getBoundsInLocal() {
+ return null;
+ }
+
+ public void deferNode(AffineTransform transform, DeferredNode node) {
+ queue.add(new Pair<>(transform, node));
+ }
+}
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
+import org.simantics.district.network.ui.styles.DistrictNetworkHoverInfoStyle;
import org.simantics.maps.MapScalingTransform;
+import org.simantics.scenegraph.ParentNode;
import org.simantics.scenegraph.g2d.G2DNode;
+import org.simantics.scenegraph.g2d.nodes.spatial.RTreeNode;
import org.simantics.scenegraph.utils.DPIUtil;
+import org.simantics.scenegraph.utils.NodeUtil;
import org.simantics.scl.runtime.Lists;
import org.simantics.scl.runtime.tuple.Tuple3;
-public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensitiveNode {
+public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensitiveNode, DeferredNode {
private static final Font FONT = new Font("Tahoma", Font.PLAIN, (int)(DPIUtil.upscale(9) * MapScalingTransform.getScaleY() + 0.5));
private List<Tuple3> labels;
+ @SuppressWarnings("unused")
private Point2D origin;
private boolean hover = false;
+
+ private Point2D mousePosition;
private static AtomicReference<DistrictNetworkHoverInfoNode> activeNode = new AtomicReference<>();
if (!hover || activeNode.get() != this)
return;
+ ParentNode<?> root = (ParentNode<?>) NodeUtil.getNearestParentOfType(this, RTreeNode.class);
+ DeferredRenderingNode deferred = root != null ? (DeferredRenderingNode) root.getNode(DistrictNetworkHoverInfoStyle.HOVER_INFO_DEFERRED) : null;
+ if (deferred != null)
+ deferred.deferNode(g.getTransform(), this);
+ else
+ renderDeferred(g);
+ }
+
+ @Override
+ public void renderDeferred(Graphics2D g) {
AffineTransform ot = g.getTransform();
Font of = g.getFont();
doRender(g);
}
private void doRender(Graphics2D g) {
- g.translate(origin.getX(), origin.getY());
+ g.transform(MapScalingTransform.INVERSE);
+ g.translate(mousePosition.getX(), mousePosition.getY());
+ //g.translate(origin.getX(), origin.getY());
double scale = 1.5 / g.getTransform().getScaleX();
g.scale(scale, scale);
return changed;
}
+ @Override
+ public void setMousePosition(Point2D p) {
+ mousePosition = p;
+ }
+
@Override
public void delete() {
super.delete();
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
-import org.simantics.district.network.DistrictNetworkUtil;
-import org.simantics.district.network.ui.DistrictNetworkUIUtil;
+import org.simantics.district.network.ui.styles.DistrictNetworkStaticInfoStyle;
import org.simantics.maps.MapScalingTransform;
+import org.simantics.scenegraph.ParentNode;
import org.simantics.scenegraph.g2d.G2DNode;
import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.g2d.nodes.spatial.RTreeNode;
import org.simantics.scenegraph.utils.DPIUtil;
+import org.simantics.scenegraph.utils.NodeUtil;
-public class DistrictNetworkStaticInfoNode extends G2DNode {
+public class DistrictNetworkStaticInfoNode extends G2DNode implements DeferredNode {
private static final Font FONT = new Font("Tahoma", Font.PLAIN, (int)(DPIUtil.upscale(9) * MapScalingTransform.getScaleY() + 0.5));
@Override
public void render(Graphics2D g) {
+ ParentNode<?> root = (ParentNode<?>) NodeUtil.getNearestParentOfType(this, RTreeNode.class);
+ DeferredRenderingNode deferred = root != null ? (DeferredRenderingNode) root.getNode(DistrictNetworkStaticInfoStyle.STATIC_INFO_DEFERRED) : null;
+ if (deferred != null)
+ deferred.deferNode(g.getTransform(), this);
+ else
+ renderDeferred(g);
+ }
+
+ @Override
+ public void renderDeferred(Graphics2D g) {
if (info == null || "".equals(info))
return;
double scale = 1.5 / g.getTransform().getScaleX();
g.scale(scale, scale);
- int width1 = g.getFontMetrics().stringWidth(info);
- int height = g.getFontMetrics().getHeight();
-
- g.setColor(Color.WHITE);
- g.fillRect(-width1/2 - 5, -2, width1, height);
-
g.setFont(FONT);
- g.setColor(Color.BLACK);
+ int width1 = g.getFontMetrics().stringWidth(info);
+// int height = g.getFontMetrics().getHeight();
g.transform(AffineTransform.getRotateInstance(direction.getX(), direction.getY()));
g.translate(0, 10);
+// g.setColor(Color.WHITE);
+// g.fillRect(-width1/2 - 5, -height-2, width1+10, height+4);
+
+ g.setColor(Color.BLACK);
+
g.drawString(info, -width1/2, 0);
}
symbolTransform = DistrictNetworkNodeUtils.getTransformToRectangle(toDraw, symbolTransform);
g2dNode.setTransform(symbolTransform);
}
+
g2dNode.render(g2d);
}
return changed;
}
+
+ @Override
+ public void setMousePosition(Point2D p) {
+ for (IG2DNode child : getNodes()) {
+ if (child instanceof HoverSensitiveNode)
+ ((HoverSensitiveNode) child).setMousePosition(p);
+ }
+ }
public void setColor(Color color) {
this.color = color;
package org.simantics.district.network.ui.nodes;
+import java.awt.geom.Point2D;
+
public interface HoverSensitiveNode {
boolean hover(boolean hover, boolean isConnectionTool);
+ default void setMousePosition(Point2D p) {};
}
import org.simantics.diagram.stubs.DiagramResource;
import org.simantics.district.network.DistrictNetworkUtil;
import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.ui.nodes.DeferredRenderingNode;
import org.simantics.district.network.ui.nodes.DistrictNetworkHoverInfoNode;
import org.simantics.district.network.ui.nodes.DistrictNetworkNodeUtils;
import org.simantics.layer0.Layer0;
import org.simantics.modeling.ModelingResources;
import org.simantics.scenegraph.INode;
+import org.simantics.scenegraph.ParentNode;
+import org.simantics.scenegraph.g2d.nodes.spatial.RTreeNode;
import org.simantics.scenegraph.profile.EvaluationContext;
import org.simantics.scenegraph.profile.common.ProfileVariables;
+import org.simantics.scenegraph.utils.NodeUtil;
import org.simantics.scl.compiler.top.ValueNotFound;
import org.simantics.scl.osgi.SCLOsgi;
import org.simantics.scl.runtime.SCLContext;
public class DistrictNetworkHoverInfoStyle extends StyleBase<DistrictNetworkHoverInfoStyle.StyleResult> {
- private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkHoverInfoStyle.class);
+ public static final String HOVER_INFO_DEFERRED = "hoverInfo";
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkHoverInfoStyle.class);
private static final String ACTIONS_MODULE = "Actions";
private static final String HOVER_CONTRIBUTION = "hoverContribution";
if (node == null)
return;
+ ParentNode<?> root = (ParentNode<?>) NodeUtil.getNearestParentOfType(parent, RTreeNode.class);
+ if (root != null) {
+ DeferredRenderingNode deferred = ProfileVariables.claimChild(root, "", HOVER_INFO_DEFERRED, DeferredRenderingNode.class, observer);
+ deferred.setZIndex(Integer.MAX_VALUE);
+ }
+
node.setLabels(results.getLabels());
node.setOrigin(results.getOrigin());
}
import org.simantics.district.network.DistrictNetworkUtil;
import org.simantics.district.network.ontology.DistrictNetworkResource;
import org.simantics.district.network.profile.MidBranchEdgeSetRequest;
+import org.simantics.district.network.ui.nodes.DeferredRenderingNode;
import org.simantics.district.network.ui.nodes.DistrictNetworkNodeUtils;
import org.simantics.district.network.ui.nodes.DistrictNetworkStaticInfoNode;
import org.simantics.layer0.Layer0;
import org.simantics.scenegraph.INode;
+import org.simantics.scenegraph.ParentNode;
+import org.simantics.scenegraph.g2d.nodes.spatial.RTreeNode;
import org.simantics.scenegraph.profile.EvaluationContext;
import org.simantics.scenegraph.profile.common.ProfileVariables;
+import org.simantics.scenegraph.utils.NodeUtil;
import org.simantics.scl.compiler.top.ValueNotFound;
import org.simantics.scl.osgi.SCLOsgi;
import org.simantics.scl.runtime.SCLContext;
private static final String ACTIONS_MODULE = "Actions";
private static final String PIPELINE_INFO = "pipelineInfo";
+
+ public static final String STATIC_INFO_DEFERRED = "staticInfo";
public static class StyleResult {
public StyleResult(Point2D p1, Point2D p2, String info) {
return;
}
+ ParentNode<?> root = (ParentNode<?>) NodeUtil.getNearestParentOfType(parent, RTreeNode.class);
+ if (root != null) {
+ DeferredRenderingNode deferred = ProfileVariables.claimChild(root, "", STATIC_INFO_DEFERRED, DeferredRenderingNode.class, evaluationContext);
+ deferred.setZIndex(Integer.MAX_VALUE-1);
+ }
+
DistrictNetworkStaticInfoNode node = ProfileVariables.claimChild(parent, "*", DistrictNetworkStaticInfoNode.NODE_KEY, DistrictNetworkStaticInfoNode.class, evaluationContext);
if (node == null)
return;