From 91d2a4c9212ecbb89656acaf5a01fb86a0aa5898 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 17 Oct 2019 01:57:08 +0300 Subject: [PATCH] Introduced G2DRenderingHints.KEY_TRANSFORM_UNDER_SPATIAL_ROOT gitlab #398 (cherry picked from commit ceff53434e48f94c5d84ce12f3b1e21cabda457b) --- .../diagram/handler/impl/PickContextImpl.java | 2 +- .../src/org/simantics/scenegraph/ParentNode.java | 2 +- .../scenegraph/g2d/G2DRenderingHints.java | 16 ++++++++++++++++ .../scenegraph/g2d/nodes/spatial/RTreeNode.java | 4 ++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/impl/PickContextImpl.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/impl/PickContextImpl.java index f6fd5fe6d..6a77af9b8 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/impl/PickContextImpl.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/impl/PickContextImpl.java @@ -91,7 +91,7 @@ public class PickContextImpl implements PickContext { if (PERF) { long endTime = System.nanoTime(); - LOGGER.info("[picked " + result.size() + " elements @ " + request.pickArea + "] total pick time : " + ((endTime - startTime)*1e-6)); + LOGGER.info("[picked {} elements @ {}] total pick time {} ms", result.size(), request.pickArea, ((endTime - startTime)*1e-6)); } if (!result.isEmpty()) { diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/ParentNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/ParentNode.java index 866e8d36c..f599fd05e 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/ParentNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/ParentNode.java @@ -244,7 +244,7 @@ public abstract class ParentNode extends Node { * @return the collection of this node's children in an unspecified order */ public Collection getNodes() { - return children.values(); + return children.isEmpty() ? Collections.emptyList() : (Collection) children.values(); } public int getNodeCount() { diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DRenderingHints.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DRenderingHints.java index ff68dac5a..992213c45 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DRenderingHints.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DRenderingHints.java @@ -12,6 +12,7 @@ package org.simantics.scenegraph.g2d; import java.awt.Component; +import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.util.Map; @@ -105,4 +106,19 @@ public final class G2DRenderingHints { } }; + /** + * The current Graphics2D AffineTransform for all nodes under the special + * spatialRoot : RTreeNode. + * + * This can be used to optimize the creation and of new AffineTransforms by + * not having to use Graphics2D.getTransform to retrieve the current + * transformation which always creates new instances. + */ + public static final Key KEY_TRANSFORM_UNDER_SPATIAL_ROOT = new Key(2006) { + @Override + public boolean isCompatibleValue(Object val) { + return val instanceof AffineTransform || val == null; + } + }; + } \ No newline at end of file diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/spatial/RTreeNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/spatial/RTreeNode.java index 52403edd0..1d3ee9740 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/spatial/RTreeNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/spatial/RTreeNode.java @@ -24,6 +24,7 @@ import java.util.Properties; import java.util.Set; import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.G2DRenderingHints; import org.simantics.scenegraph.g2d.IG2DNode; import org.simantics.scenegraph.g2d.events.Event; import org.simantics.scenegraph.g2d.events.EventTypes; @@ -127,6 +128,8 @@ public class RTreeNode extends G2DParentNode implements INodeEventHandlerProvide g.transform(transform); } + g.setRenderingHint(G2DRenderingHints.KEY_TRANSFORM_UNDER_SPATIAL_ROOT, g.getTransform()); + try { // Get transformed clip bounds Shape clipShape = g.getClip(); @@ -235,6 +238,7 @@ public class RTreeNode extends G2DParentNode implements INodeEventHandlerProvide // drawTree(g, tree.rtree); } finally { + g.setRenderingHint(G2DRenderingHints.KEY_TRANSFORM_UNDER_SPATIAL_ROOT, null); if (ot != null) g.setTransform(ot); } -- 2.47.1