]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Introduced G2DRenderingHints.KEY_TRANSFORM_UNDER_SPATIAL_ROOT
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 16 Oct 2019 22:57:08 +0000 (01:57 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 17 Oct 2019 09:53:51 +0000 (12:53 +0300)
gitlab #398
(cherry picked from commit ceff53434e48f94c5d84ce12f3b1e21cabda457b)

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 866e8d36cba6718fe20b5eebb926fe9698228e2a..f599fd05efda23dd517aa677be780ee309067963 100644 (file)
@@ -244,7 +244,7 @@ public abstract class ParentNode<T extends INode> extends Node {
      * @return the collection of this node's children in an unspecified order
      */
     public Collection<T> getNodes() {
-        return 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 52403edd02ea251522270f43ec9904614cda8c0b..1d3ee97409fe6aae0efbc41231cf6ad0a859ab9e 100644 (file)
@@ -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);
         }