]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Introduced G2DRenderingHints.KEY_TRANSFORM_UNDER_SPATIAL_ROOT 50/3350/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 16 Oct 2019 22:57:08 +0000 (01:57 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 16 Oct 2019 22:57:08 +0000 (01:57 +0300)
gitlab #398

Change-Id: I505af1d0ef38a001c6bbb4fc900e62091099fafd

bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/impl/PickContextImpl.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/ParentNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DRenderingHints.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/spatial/RTreeNode.java

index f6fd5fe6ddab9067960d168a1c487161b1065e4c..6a77af9b80e0cb0463abe78f5d8e0962f9b66c2a 100644 (file)
@@ -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()) {
index 976857afe1fbc85349a1bcb3e5869782ff5f9b48..510bbabb096ff7534f32ad56cfd37b5549058e4b 100644 (file)
@@ -241,7 +241,7 @@ public abstract class ParentNode<T extends INode> extends Node {
      */
     @SuppressWarnings("unchecked")
     public Collection<T> getNodes() {
-        return (Collection<T>) children.values();
+        return children.isEmpty() ? Collections.emptyList() : (Collection<T>) children.values();
     }
 
     public int getNodeCount() {
index ff68dac5a692829ad157dc4180091dd9a3abb31a..992213c4595f8dfa5f375af72b00750e00ce71bf 100644 (file)
@@ -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
index 56b6be302e44910e22fb62f47310406ba2c419e8..04bad53c01ae93167509add0004949a2ae1e44c5 100644 (file)
@@ -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);
         }