From: Antti Villberg Date: Mon, 2 Oct 2017 06:13:12 +0000 (+0300) Subject: Update diagram element graphics when symbol graphics change X-Git-Tag: v1.31.0~157 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F63%2F1063%2F5;p=simantics%2Fplatform.git Update diagram element graphics when symbol graphics change refs #7523 Change-Id: Ia600c55dbf607a657dee4ad1adb8a02c488205c0 --- 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; + } } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementFactory.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementFactory.java index 9f02393c7..10855496b 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementFactory.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementFactory.java @@ -20,6 +20,8 @@ import java.util.concurrent.atomic.AtomicInteger; import org.simantics.databoard.Bindings; import org.simantics.db.AsyncReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.primitiverequest.PossibleAdapter; +import org.simantics.db.common.procedure.adapter.AsyncProcedureAdapter; import org.simantics.db.common.procedure.adapter.ProcedureAdapter; import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper; @@ -44,9 +46,7 @@ import org.simantics.g2d.element.handler.impl.SimpleElementLayers; import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer; import org.simantics.g2d.element.handler.impl.StaticSymbolImpl; -import org.simantics.g2d.element.handler.impl.Terminals; import org.simantics.g2d.element.handler.impl.TextImpl; -import org.simantics.g2d.elementclass.ImageClass; import org.simantics.g2d.elementclass.PlainElementPropertySetter; import org.simantics.g2d.tooltip.TerminalTooltipProvider; import org.simantics.g2d.tooltip.TooltipParticipant; @@ -259,6 +259,15 @@ public class DefinedElementFactory extends ElementFactoryAdapter { // This is needed for terminal tooltips. e.setHint(TooltipParticipant.TOOLTIP_KEY, TerminalTooltipProvider.INSTANCE); + graph.asyncRequest(new PossibleAdapter(element, ElementFactory.class), new AsyncProcedureAdapter() { + @Override + public void execute(AsyncReadGraph graph, ElementFactory factory) { + if (factory != null) { + graph.asyncRequest(new GetElementClassRequest(factory, element, canvas, diagram)); + } + } + }); + ElementFactoryUtil.readParameters(graph, element, e); GuardedAsyncProcedureWrapper guard = new GuardedAsyncProcedureWrapper(procedure, 1);