]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Update diagram element graphics when symbol graphics change 63/1063/5
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 2 Oct 2017 06:13:12 +0000 (09:13 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 2 Oct 2017 09:33:57 +0000 (12:33 +0300)
refs #7523

Change-Id: Ia600c55dbf607a657dee4ad1adb8a02c488205c0

bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/CompositeImage.java
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementFactory.java

index 1c6e4df404c0403683b68a9ef18b35c96b6d5b3e..b8a5daa2681f7b739fcf42efc9414f918b32f761 100644 (file)
@@ -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<SceneGraph> 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> 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<Key, Object> getHints() {
-//            throw new UnsupportedOperationException();
-//        }
-//        @Override
-//        public <E extends Key> Map<E, Object> getHintsOfClass(Class<E> 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;
+    }
 
 }
index 9f02393c7dd90cc30b2ec1d73757329c862b4d15..10855496becc36fce003acafba8e0cac4fb3489a 100644 (file)
@@ -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<ElementFactory>(element, ElementFactory.class), new AsyncProcedureAdapter<ElementFactory>() {
+            @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<IElement> guard = new GuardedAsyncProcedureWrapper<IElement>(procedure, 1);