From: Tuukka Lehtonen Date: Wed, 16 Oct 2019 22:57:08 +0000 (+0300) Subject: Introduced G2DRenderingHints.KEY_TRANSFORM_UNDER_SPATIAL_ROOT X-Git-Tag: v1.43.0~136^2~54 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=ceff53434e48f94c5d84ce12f3b1e21cabda457b;p=simantics%2Fplatform.git Introduced G2DRenderingHints.KEY_TRANSFORM_UNDER_SPATIAL_ROOT gitlab #398 Change-Id: I505af1d0ef38a001c6bbb4fc900e62091099fafd --- 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 976857afe..510bbabb0 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/ParentNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/ParentNode.java @@ -241,7 +241,7 @@ public abstract class ParentNode extends Node { */ @SuppressWarnings("unchecked") public Collection getNodes() { - return (Collection) 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 56b6be302..04bad53c0 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 @@ -26,6 +26,7 @@ import java.util.Set; import org.simantics.scenegraph.INode; 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; @@ -134,6 +135,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(); @@ -242,6 +245,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); }