X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fadapter%2FCompositeImage.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fadapter%2FCompositeImage.java;h=b8a5daa2681f7b739fcf42efc9414f918b32f761;hb=fb51fd7b6e8999e90c7769757ef4151c5f22243d;hp=1c6e4df404c0403683b68a9ef18b35c96b6d5b3e;hpb=de6ca001c169e87055e8e66f450baf4f6119110e;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/CompositeImage.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/CompositeImage.java index 1c6e4df40..b8a5daa26 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/CompositeImage.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/CompositeImage.java @@ -24,6 +24,7 @@ import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.SceneGraphNodeKey; import org.simantics.g2d.element.handler.SceneGraph; import org.simantics.g2d.image.Image; +import org.simantics.scenegraph.INode; import org.simantics.scenegraph.Node; import org.simantics.scenegraph.g2d.G2DParentNode; import org.simantics.scenegraph.g2d.nodes.SingleElementNode; @@ -103,7 +104,7 @@ public class CompositeImage implements Image { // } // Rendering is single-threaded, this is used while rendering. - Rectangle2D tempBounds = new Rectangle2D.Double(0, 0, 0, 0); + //Rectangle2D tempBounds = new Rectangle2D.Double(0, 0, 0, 0); @Override public Node init(G2DParentNode parent) { @@ -111,7 +112,7 @@ public class CompositeImage implements Image { // Optimization for 0..1 element composites for (IElement e : elements) { ElementClass ec = e.getElementClass(); - G2DParentNode node = parent.getOrCreateNode("composite_image_"+this.hashCode(), G2DParentNode.class); + G2DParentNode node = getOrCreateParentNode(parent); List nodeHandlers = ec.getItemsByClass(SceneGraph.class); for (SceneGraph n : nodeHandlers) { // n.init(e, parent); @@ -123,9 +124,7 @@ public class CompositeImage implements Image { // For N element composites - // Removed this grouping node as unnecessary, just use the given parent node - G2DParentNode node = parent.getOrCreateNode("composite_image_"+this.hashCode(), G2DParentNode.class); - + G2DParentNode node = getOrCreateParentNode(parent); // Rectangle2D bounds = tempBounds; int zIndex = 0; @@ -153,38 +152,15 @@ public class CompositeImage implements Image { return node; // Valid node must be returned because transform is set afterwards } -// public static class TypeProxyElement extends ProxyElement { -// IHintContext instanceHints; -// public TypeProxyElement(IElement orig, IHintContext instanceHints) { -// super(orig); -// this.instanceHints = instanceHints; -// } -// @Override -// public E getHint(Key key) { -// // TODO: need some mechanism to tell whether it is allowed to look for this key in the instance hints or not -// // This version is broken because some hints MUST come from the original element. -// E e = null; -// if (instanceHints != null) -// e = instanceHints.getHint(key); -// if (e == null) -// e = orig.getHint(key); -// return e; -// } -// @Override -// public Map getHints() { -// throw new UnsupportedOperationException(); -// } -// @Override -// public Map getHintsOfClass(Class clazz) { -// throw new UnsupportedOperationException(); -// } -// @Override -// public void setHint(Key key, Object value) { -// if (instanceHints != null) -// instanceHints.setHint(key, value); -// else -// orig.setHint(key, value); -// } -// } + private G2DParentNode getOrCreateParentNode(G2DParentNode parent) { + G2DParentNode node = (G2DParentNode)parent.getNode("composite_image_"+this.hashCode()); + if (node == null) { + for (INode n : parent.getNodes()) + n.remove(); + // Removed this grouping node as unnecessary, just use the given parent node + node = parent.getOrCreateNode("composite_image_"+this.hashCode(), G2DParentNode.class); + } + return node; + } }