X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fadapter%2FCompositeImage.java;h=d4e20230185f18ae59c94824132ed88b401a772f;hp=1c6e4df404c0403683b68a9ef18b35c96b6d5b3e;hb=HEAD;hpb=060886da1e94e4a6bb1e09d56e96a6ad289ba7d0 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..d4e202301 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,18 @@ 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()) { + // #7663: prevent the code from removing other element graphics from directly under another element + if (!(n instanceof SingleElementNode)) + 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; + } }