Support SVG generation from scenegraph 94/394/4
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 3 Apr 2017 07:25:30 +0000 (10:25 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 3 Apr 2017 14:17:26 +0000 (17:17 +0300)
refs #7054

Change-Id: Ide69219fee786bd19ccf447c227c2424d9cabdc2

14 files changed:
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/CompositeImage.java
bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java
bundles/org.simantics.modeling/META-INF/MANIFEST.MF
bundles/org.simantics.modeling/scl/Simantics/Scenegraph.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DParentNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DRenderingHints.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNodeVisitor.java [new file with mode: 0644]
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ConnectionNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SVGNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SingleElementNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/UnboundedNode.java

index 93957f0698fc0643691d0676039ce676e78f4b3c..98f229b91324b75a913be0df238676f52813cbec 100644 (file)
@@ -18,6 +18,7 @@ import java.util.EnumSet;
 import java.util.List;
 
 import org.simantics.g2d.element.ElementClass;
+import org.simantics.g2d.element.ElementHints;
 import org.simantics.g2d.element.ElementUtils;
 import org.simantics.g2d.element.IElement;
 import org.simantics.g2d.element.SceneGraphNodeKey;
@@ -140,6 +141,7 @@ public class CompositeImage implements Image {
             SingleElementNode holder = node.getOrCreateNode(ElementUtils.generateNodeId(e), SingleElementNode.class);
             //SingleElementNode holder = parent.getOrCreateNode(ElementUtils.generateNodeId(e), SingleElementNode.class);
             holder.setZIndex(++zIndex);
+            holder.setKey(e.getHint(ElementHints.KEY_OBJECT));
 
             List<SceneGraph> nodeHandlers = ec.getItemsByClass(SceneGraph.class);
             for(SceneGraph n : nodeHandlers) {
index 1eb15f61c2132ece167643ee6af6638ef4cb6e9b..d69ef69c69fadec257a3e07e2fc31a600cd5ed15 100644 (file)
@@ -557,6 +557,7 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos
             ConnectionNode holder = e.getHint(sgKey);
             if (holder == null) {
                 holder = parentNode.addNode(ElementUtils.generateNodeId(e), ConnectionNode.class);
+                holder.setKey(e.getHint(ElementHints.KEY_OBJECT));
                 holder.setTransferableProvider(new ElementTransferableProvider(getContext(), e));
                 e.setHint(sgKey, holder);
                 holder.setZIndex(parentNode.getNodeCount() + 1);
@@ -567,6 +568,7 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos
             SingleElementNode holder = e.getHint(sgKey);
             if (holder == null) {
                 holder = parentNode.addNode(ElementUtils.generateNodeId(e), SingleElementNode.class);
+                holder.setKey(e.getHint(ElementHints.KEY_OBJECT));
                 holder.setTransferableProvider(new ElementTransferableProvider(getContext(), e));
                 e.setHint(sgKey, holder);
                 holder.setZIndex(parentNode.getNodeCount() + 1);
index 5245ed47e7665fb1abe384033ad087367844f446..7f81e56f2300bc0511473436e2494932e4b8af15 100644 (file)
@@ -37,7 +37,8 @@ Require-Bundle: org.simantics.simulation;bundle-version="1.0.0",
  org.simantics.scl.db;bundle-version="0.1.3",
  org.simantics.selectionview.ontology;bundle-version="1.2.0",
  org.simantics.scl.ui;bundle-version="0.5.0",
- org.slf4j.api
+ org.slf4j.api,
+ org.apache.batik
 Export-Package: org.simantics.modeling,
  org.simantics.modeling.actions,
  org.simantics.modeling.adapters,
index fa1d2193fde51181ade6b5dc66bd79e256ff2cc4..5e0e830752c5a3869655a6c3101b4311e4c182cf 100644 (file)
@@ -51,12 +51,14 @@ importJava "org.simantics.modeling.SCLScenegraph" where
     editNodeText :: ICanvasContext -> String -> String -> String -> <Proc> String
     
     copyPaste :: ICanvasContext -> ICanvasContext -> [Resource] -> <Proc> Boolean
+    
+    renderSVG :: ICanvasContext -> <Proc> String
 
 getSceneGraphProvider :: Diagram -> <Proc> ICanvasSceneGraphProvider
 getSceneGraphProvider diagram = do
     diagramName = syncRead(\() -> getSafeName diagram)
     diagramRVI = "/" + diagramName
-    model = syncRead(\() -> getPossibleModel diagram)
+    model = syncRead(\() -> fromJust $ possibleIndexRoot diagram)
     composite = syncRead(\() -> compositeToDiagram' diagram)
     getICanvasSceneGraphProvider model composite diagramRVI
 
index 33d7f06290e109e69fdc4ceff7afb00c8b7cd00a..358d50fb4b4c9ac6f5f673ac3836bddf6f5ee383 100644 (file)
@@ -1,10 +1,28 @@
 package org.simantics.modeling;
 
+import java.awt.Dimension;
+import java.awt.RenderingHints;
+import java.awt.RenderingHints.Key;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStreamWriter;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Set;
+import java.util.UUID;
 
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.batik.dom.GenericDOMImplementation;
+import org.apache.batik.svggen.SVGGeneratorContext;
+import org.apache.batik.svggen.SVGGraphics2D;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.diagram.elements.DiagramNodeUtil;
@@ -20,7 +38,10 @@ import org.simantics.g2d.scenegraph.ICanvasSceneGraphProvider;
 import org.simantics.g2d.utils.CanvasUtils;
 import org.simantics.scenegraph.ParentNode;
 import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.g2d.G2DRenderingHints;
 import org.simantics.scenegraph.g2d.G2DSceneGraph;
+import org.simantics.scenegraph.g2d.IG2DNode;
+import org.simantics.scenegraph.g2d.IG2DNodeVisitor;
 import org.simantics.scenegraph.g2d.events.command.Commands;
 import org.simantics.scenegraph.g2d.nodes.BackgroundNode;
 import org.simantics.scenegraph.g2d.nodes.BoundsNode;
@@ -28,13 +49,23 @@ import org.simantics.scenegraph.g2d.nodes.ConnectionNode;
 import org.simantics.scenegraph.g2d.nodes.DataNode;
 import org.simantics.scenegraph.g2d.nodes.DecorationSVGNode;
 import org.simantics.scenegraph.g2d.nodes.NavigationNode;
+import org.simantics.scenegraph.g2d.nodes.SVGNode;
 import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
+import org.simantics.scenegraph.g2d.nodes.spatial.RTreeNode;
 import org.simantics.scenegraph.utils.NodeUtil;
 import org.simantics.trend.impl.ItemNode;
 import org.simantics.utils.threads.ThreadUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 public class SCLScenegraph {
-       
+
+       private static final Logger LOGGER = LoggerFactory.getLogger(SCLScenegraph.class);
+
        public static ICanvasSceneGraphProvider getICanvasSceneGraphProvider(Resource model, Resource diagram, String diagramRVI) throws DatabaseException, InterruptedException {
                ICanvasSceneGraphProvider provider = DiagramNodeUtil.loadSceneGraphProvider(model, diagram, diagramRVI);
                return provider;
@@ -44,13 +75,6 @@ public class SCLScenegraph {
                provider.dispose();
        }
        
-       //public static Resource getDiagramRuntime(Resource ) 
-       
-       
-//     public static String getNodeTransform(ICanvasContext ctx, String name) throws DatabaseException, InterruptedException {
-//             return getNodeTransform(ctx, name);
-//     }
-       
        public static String getNodeTransform(ICanvasContext ctx, String name) {
                
                Set<TextNode> texts = NodeUtil.collectNodes(ctx.getSceneGraph(), TextNode.class);
@@ -234,7 +258,7 @@ public class SCLScenegraph {
         }
     }
     
-     public static boolean copyPaste (final ICanvasContext source_ctx, final ICanvasContext target_ctx, List<Resource> modules) throws DatabaseException {
+    public static boolean copyPaste (final ICanvasContext source_ctx, final ICanvasContext target_ctx, List<Resource> modules) throws DatabaseException {
        
        IDiagram idiagram = source_ctx.getDefaultHintContext().getHint(DiagramHints.KEY_DIAGRAM);
 
@@ -286,5 +310,259 @@ public class SCLScenegraph {
                return true;
     }
 
+       static class Generator extends SVGGraphics2D {
+
+               int elemLevel = 0;
+               String newElementId = null;
+               ArrayList<Element> elements = new ArrayList<Element>();
+
+               public static final String svgNS = "http://www.w3.org/2000/svg";
+
+               public Generator(SVGGeneratorContext ctx, boolean joku) {
+                       super(ctx, joku);
+               }
+
+               public Generator(Document document) {
+                       super(document);
+               }
+
+               @Override
+               public Element getRoot() {
+                       Element root = super.getRoot();
+                       for(Element e : elements) {
+                               root.appendChild(e);
+                       }
+                       return root;
+               }
+
+               @Override
+               public void setRenderingHint(Key arg0, Object arg1) {
+                       if(G2DRenderingHints.KEY_BEGIN_ELEMENT == arg0) {
+                               elemLevel++;
+                       }
+                       if(G2DRenderingHints.KEY_ELEMENT_ID == arg0) {
+                               if(arg1 != null)
+                                       newElementId = arg1.toString();
+                               else
+                                       newElementId = UUID.randomUUID().toString();
+                       }
+                       if(G2DRenderingHints.KEY_END_ELEMENT == arg0) {
+                               elemLevel--;
+                               if(elemLevel == 0) {
+                                       Element group = getDOMFactory().createElement(SVG_G_TAG);
+                                       //Element group = getDOMFactory().createElementNS(SVG_NAMESPACE_URI, SVG_G_TAG);
+                                       group.setAttributeNS(null, "id", newElementId);
+                                       group.setAttributeNS(null, "class", arg1.toString());
+                                       getRoot(group);
+                                       elements.add(group);
+                               }
+                       }
+                       super.setRenderingHint(arg0, arg1);
+               }
+
+       }
+
+       public static Element renderSVGNode(IG2DNode node) {
+
+               // Get a DOMImplementation.
+               DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
+
+               // Create an instance of org.w3c.dom.Document.
+               String svgNS = "http://www.w3.org/2000/svg";
+               Document document = domImpl.createDocument(svgNS, "svg", null);
+
+               SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
+               ctx.setComment(null);
+
+               // Create an instance of the SVG Generator.
+               SVGGraphics2D svgGenerator = new Generator(ctx, false);
+
+               try {
+
+                       svgGenerator.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+                       svgGenerator.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+                       svgGenerator.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+
+                       node.render(svgGenerator);
+
+               } catch (Throwable t) {
+                       LOGGER.error("Problems rendering scene graph to SVG", t);
+               }
+
+               return svgGenerator.getRoot();
+       }
+
+       public static String printSVGDocument(Element doce) {
+
+               StringBuilder result = new StringBuilder();
+
+               NodeList nl =  doce.getChildNodes();
+
+               for(int i=0;i<nl.getLength();i++) {
+
+                       ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+                       try {
+
+                               TransformerFactory tf = TransformerFactory.newInstance();
+                               Transformer transformer = tf.newTransformer();
+                               transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+                               transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
+                               transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+                               transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+                               transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+                               transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
+
+                               transformer.transform(new DOMSource(nl.item(i)), 
+                                               new StreamResult(new OutputStreamWriter(os, "UTF-8")));
+
+                               os.flush();
+                               os.close();
+
+                       } catch (Throwable t) {
+                               LOGGER.error("Problems formatting SVGDocument to text.", t);
+                       }
+
+                       result.append(new String(os.toByteArray()));
+
+               }
+
+               return result.toString();
+
+       }
+
+       public static String renderSVG(ICanvasContext ctx) {
+
+               // Get a DOMImplementation.
+               DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
+
+               // Create an instance of org.w3c.dom.Document.
+               String svgNS = "http://www.w3.org/2000/svg";
+               Document document = domImpl.createDocument(svgNS, "svg", null);
+
+               // Create an instance of the SVG Generator.
+               SVGGraphics2D svgGenerator = new Generator(document);
+
+               StringBuilder b = new StringBuilder();
+
+               try {
+
+                       G2DSceneGraph sg = ctx.getSceneGraph();
+                       G2DParentNode root = (G2DParentNode) sg.getRootNode();
+
+                       // rtree is the actual content of the diagram
+                       RTreeNode rtree = NodeUtil.getNearestChildByClass(root, RTreeNode.class);
+                       Rectangle2D rtreeBounds = NodeUtil.getLocalBounds(rtree);
+
+                       // nav is a node that has zooming functionalities
+                       NavigationNode nav = NodeUtil.getNearestChildByClass(root, NavigationNode.class);
+                       nav.setZoomEnabled(true);
+
+                       // fit view with the contents of rtreeBounds
+                       nav.zoomTo(rtreeBounds);
+
+                       // get the bounds of the content
+                       Rectangle2D content = NodeUtil.getLocalBounds(nav);
+
+                       svgGenerator.scale(3,3);
+
+                       // translate svgGenerator to the x and y coordinates of current content
+                       svgGenerator.translate(-1 * content.getX(), (-1 * content.getY()));
+
+                       Rectangle2D destination = new Rectangle2D.Double(0,0,1000,1000);
+                       double sx = destination.getWidth() / content.getWidth();
+                       double sy = destination.getHeight() / content.getHeight();
+                       double scale = sx < sy ? sx : sy;
+
+                       // Set svgCanvasSize to the given size parameters
+                       svgGenerator.setSVGCanvasSize(new Dimension((int)(scale * content.getWidth()), (int)(scale * content.getHeight())));
+                       svgGenerator.setClip(content);
+
+                       double trX = -1 * content.getX();
+                       double trY = -1 * content.getY();
+
+                       b.append("<svg width=\"100%\" height=\"100%\" stroke=\"black\"><g transform=\"translate(").append(trX).append(' ').append(trY).append(")\">");
+
+                       IG2DNodeVisitor visitor = new IG2DNodeVisitor() {
+
+                               int indent = 0;
+
+                               HashMap<IG2DNode,Integer> enters = new HashMap<>();
+
+                               @Override
+                               public void enter(IG2DNode node) {
+                                       indent++;
+                                       if(node instanceof ConnectionNode) {
+                                               Element doc = renderSVGNode((IG2DNode)node);
+                                               String svg = printSVGDocument(doc);
+                                               b.append(svg);
+                                       } else if (node instanceof SVGNode) {
+                                               SVGNode svg = (SVGNode)node;
+                                               b.append(svg.getSVGText());
+                                       } else if (node instanceof G2DParentNode) {
+                                               AffineTransform at = node.getTransform();
+                                               if(node instanceof SingleElementNode) {
+                                                       SingleElementNode sen = (SingleElementNode)node;
+                                                       if(sen.getKey() != null) {
+                                                               String key = sen.getKey().toString();
+                                                               b.append("\n<g class=\"definedElement\" id=\"" + key + "\">");
+                                                       }
+                                               }
+                                               if(!at.isIdentity()) {
+                                                       if(at.getScaleX() == 1.0 && at.getScaleY() == 1.0 && at.getShearX() == 0.0 && at.getShearY() == 0.0) {
+                                                               String m = "translate(" + at.getTranslateX() + " " + at.getTranslateY() + ")";
+                                                               b.append("\n<g transform=\"" + m + "\">");
+                                                       } else {
+                                                               double[] ds = new double[6];
+                                                               at.getMatrix(ds);
+                                                               String m = "matrix(" + ds[0] + " " + ds[1] + " " + ds[2] + " " + ds[3] + " " + ds[4] + " " + ds[5] + ")";
+                                                               b.append("\n<g transform=\"" + m + "\">");
+                                                       }
+                                               }
+                                       }
+
+                                       enters.put(node, b.length());
+
+                               }
+
+                               @Override
+                               public void leave(IG2DNode node) {
+                                       if(node instanceof ConnectionNode || node instanceof SVGNode) {
+                                               // We are done
+                                       } else if (node instanceof G2DParentNode) {
+                                               AffineTransform at = node.getTransform();
+                                               if(!at.isIdentity()) {
+                                                       b.append("</g>");
+                                               }
+                                               if(node instanceof SingleElementNode) {
+                                                       SingleElementNode sen = (SingleElementNode)node;
+                                                       if(sen.getKey() != null) {
+                                                               int enterLength = enters.get(node);
+                                                               if(b.length() == enterLength) {
+                                                                       Element doc = renderSVGNode((IG2DNode)node);
+                                                                       String svg = printSVGDocument(doc);
+                                                                       b.append(svg);
+                                                               }
+                                                               b.append("</g>");
+                                                       }
+                                               }
+                                       }
+                                       indent --;
+                               }
+
+                       };
+                       sg.accept(visitor);
+
+               } catch (Throwable t) {
+                       LOGGER.error("Problems rendering canvas context to SVG", t);
+               }
+
+               b.append("</g></svg>");
+               //System.err.println(" == FINAL RESULT == ");
+               //System.err.println(b);
+               return b.toString();
+
+       }
+
 
 }
\ No newline at end of file
index cf4fe0b308e1d246ea719a06fc9fb30dea749076..b39d7a0582167f7b6222a550b44c4d5954769ca9 100644 (file)
@@ -395,5 +395,10 @@ public abstract class G2DNode extends Node implements IG2DNode {
         if (rootPane != null)
             rootPane.setCursor(cursor);
     }
+    
+    public void accept(IG2DNodeVisitor visitor) {
+        visitor.enter(this);
+        visitor.leave(this);
+    }
 
 }
index 231b616e2a0a1a8f09497ce12941a6a562782a4c..838eb893e52b392b78a8796adf4e6e10e17fd7cc 100644 (file)
@@ -122,6 +122,17 @@ public class G2DParentNode extends ParentNode<IG2DNode> implements IG2DNode, Ini
             g2d.setTransform(ot);
     }
 
+    @Override
+    public void accept(IG2DNodeVisitor visitor) {
+        visitor.enter(this);
+        for (IG2DNode node : getSortedNodes()) {
+            if (node.validate()) {
+                node.accept(visitor);
+            }
+        }
+        visitor.leave(this);
+    }
+
     /**
      * Return the IDs of the children of this node in ascending Z order. This
      * method will always allocate a new result list and sort it. To get the IDs
index 00c7a6d0c8c516ead3e619f6edc8b8bb0070c9db..0f1803e2d64ee6d27d74695cab015a62fa658b54 100644 (file)
@@ -12,8 +12,8 @@
 package org.simantics.scenegraph.g2d;
 
 import java.awt.Component;
-import java.awt.RenderingHints.Key;
 import java.awt.geom.Rectangle2D;
+import java.util.Map;
 
 /**
  * @author Tuukka Lehtonen
@@ -21,6 +21,32 @@ import java.awt.geom.Rectangle2D;
  */
 public final class G2DRenderingHints {
 
+    public static final Key KEY_BEGIN_ELEMENT = new G2DRenderingHints.Key(0);
+    public static final Key KEY_END_ELEMENT = new G2DRenderingHints.Key(1);
+    public static final Key KEY_ELEMENT_ID = new G2DRenderingHints.Key(2);
+
+    public static class Key extends java.awt.RenderingHints.Key {
+
+        public Key(int privateKey) {
+            super(privateKey);    
+        }
+    
+        @Override
+        public boolean isCompatibleValue(Object val) {
+            switch (intKey()) {
+                case 0:
+                    return val == null || val instanceof String 
+                            || val instanceof Map;
+                case 1:
+                    return val == null || val instanceof Object;
+                case 2:
+                    return val == null || val instanceof Object;
+                default:
+                    throw new RuntimeException("Not possible!");
+            }
+        }
+    }
+       
     /**
      * A rendering hint for storing the boundaries of the control area within a
      * Graphics2D instance.
index 0afebc2db387857a305a8458001755c28766e973..e181d59ff02d45305da28dbbac3cb7802be5b002 100644 (file)
@@ -71,6 +71,14 @@ public interface IG2DNode extends INode, IEventHandler {
      */
     public void render(Graphics2D g2d);
 
+    /**
+     * Visit the IG2DNode substructure of this node using the provided visitor.
+     * 
+     * @param visitor the visitor to use
+     * @since 1.29.0
+     */
+    public void accept(IG2DNodeVisitor visitor);
+
     /**
      * Mark the scene graph to be repainted in its current rendering context (UI
      * component) as soon as is appropriate for the backend system.
diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNodeVisitor.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/IG2DNodeVisitor.java
new file mode 100644 (file)
index 0000000..2f52117
--- /dev/null
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.scenegraph.g2d;
+
+/**
+ * @author Antti Villberg
+ * @since 1.29.0
+ */
+public interface IG2DNodeVisitor {
+
+       public void enter(IG2DNode node);
+       public void leave(IG2DNode node);
+
+}
index a83ca52647719d4dd3d4001605f9a3086336bdb9..d4543c6d110546c08cf8709f94f3af81d9501810 100644 (file)
@@ -13,11 +13,13 @@ package org.simantics.scenegraph.g2d.nodes;
 
 import java.awt.Color;
 import java.awt.Composite;
+import java.awt.Graphics2D;
 import java.awt.Stroke;
 import java.awt.geom.Point2D;
 
 import org.simantics.diagram.connection.RouteGraph;
 import org.simantics.scenegraph.INode;
+import org.simantics.scenegraph.g2d.G2DRenderingHints;
 import org.simantics.scenegraph.g2d.IG2DNode;
 import org.simantics.scenegraph.g2d.events.MouseEvent;
 import org.simantics.scenegraph.g2d.nodes.connection.RouteGraphNode;
@@ -150,4 +152,14 @@ public class ConnectionNode extends SingleElementNode implements InitValueSuppor
         return false;
     }
 
+    @Override
+    public void beforeRender(Graphics2D g) {
+        g.setRenderingHint(G2DRenderingHints.KEY_BEGIN_ELEMENT, "connection");
+    }
+    
+    @Override
+    public void afterRender(Graphics2D g) {
+        g.setRenderingHint(G2DRenderingHints.KEY_END_ELEMENT, "connection");
+    }
+    
 }
index d50c65056af7c6fe1e028cac2a8a3afefe9cb97d..cdd6a26458f578d4b30fbe3e5b8099a6191f6550 100644 (file)
@@ -478,4 +478,11 @@ public class SVGNode extends G2DNode implements InitValueSupport, LoaderNode {
                this.setTransform(new AffineTransform(data));
        }
        
+       public String getSVGText() {
+               String ret = data.replace("<svg", "<g").replaceAll("svg>", "g>");
+               //return diagramCache.toString();
+               //return data.replace("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"><svg xmlns=\"http://www.w3.org/2000/svg\" overflow=\"visible\" version=\"1.1\"", "<g").replaceAll("svg>", "/g>");
+               return ret;
+       }
+       
 }
index 00ca6b8663f59c984097508f9cc9a5dba1491fc5..beee2538a534092c9f32c79577d9559b3851e3d9 100644 (file)
@@ -17,6 +17,7 @@ import java.awt.Graphics2D;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 
+import org.simantics.scenegraph.g2d.G2DRenderingHints;
 import org.simantics.scenegraph.g2d.IG2DNode;
 import org.simantics.scenegraph.g2d.events.EventTypes;
 import org.simantics.scenegraph.g2d.events.MouseEvent;
@@ -32,6 +33,15 @@ public class SingleElementNode extends TransformNode implements InitValueSupport
     protected Composite composite;
     protected Boolean visible = Boolean.TRUE;
     protected Boolean hidden = Boolean.FALSE;
+    private transient Object key;
+
+    public void setKey(Object key) {
+        this.key = key;
+    }
+
+    public Object getKey() {
+        return key;
+    }
 
     public void setTransferableProvider(TransferableProvider transferableProvider) {
         if (transferableProvider != this.transferableProvider) {
@@ -169,4 +179,12 @@ public class SingleElementNode extends TransformNode implements InitValueSupport
         return EventTypes.MouseDragBeginMask;
     }
 
+    public void beforeRender(Graphics2D g) {
+        g.setRenderingHint(G2DRenderingHints.KEY_BEGIN_ELEMENT, "definedElement");
+    }
+
+    public void afterRender(Graphics2D g) {
+        g.setRenderingHint(G2DRenderingHints.KEY_END_ELEMENT, "definedElement");
+    }
+
 }
index 4cacc70f99bb2c23859095d7fa7df8889d9c1a9e..b5071941f4297e9641b44ac3b0ecc533797912df 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/
 package org.simantics.scenegraph.g2d.nodes;
 
+import java.awt.Graphics2D;
 import java.awt.geom.Rectangle2D;
 
 public class UnboundedNode extends SingleElementNode {
@@ -22,4 +23,12 @@ public class UnboundedNode extends SingleElementNode {
         return null;
     }
 
+    @Override
+    public void beforeRender(Graphics2D g) {
+    }
+
+    @Override
+    public void afterRender(Graphics2D g) {
+    }
+
 }