X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FSCLScenegraph.java;h=675c4e52581eb81995e4888246011f59b0e30b74;hb=49a09c66d060cfd2e22e15f648d62b0a34c13e45;hp=559469d4a21ce908aff65f9574355363a989d2f3;hpb=643690b7f2f2a6e7a2eef723fffb5bef0d5fcb34;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java index 559469d4a..675c4e525 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java @@ -31,6 +31,7 @@ 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.apache.batik.svggen.SVGIDGenerator; import org.simantics.Simantics; import org.simantics.datatypes.literal.GUID; import org.simantics.db.ReadGraph; @@ -46,6 +47,7 @@ import org.simantics.diagram.elements.DiagramNodeUtil; import org.simantics.diagram.elements.TextGridNode; import org.simantics.diagram.elements.TextNode; import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.diagram.ui.DiagramModelHints; import org.simantics.g2d.canvas.Hints; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.diagram.DiagramHints; @@ -399,6 +401,22 @@ public class SCLScenegraph { return true; } + + static class UniqueIDGenerator extends SVGIDGenerator{ + + String overallId; + public UniqueIDGenerator(String overallId) { + super(); + this.overallId = overallId; + } + + @Override + public String generateID(String prefix) { + return super.generateID(overallId+prefix); + } + + } + static class Generator extends SVGGraphics2D { int elemLevel = 0; @@ -412,9 +430,14 @@ public class SCLScenegraph { } public Generator(Document document) { + this(document,null); + } + public Generator(Document document, String id) { super(document); // prevent batik comment in each g-element getGeneratorContext().setComment(null); + if (id != null) + getGeneratorContext().setIDGenerator(new UniqueIDGenerator(id)); } @Override @@ -640,6 +663,8 @@ public class SCLScenegraph { } + + private static String renderSVG0(double width, double height, ICanvasContext ctx, Function1, Map> mappingFunction) { // Get a DOMImplementation. @@ -650,7 +675,13 @@ public class SCLScenegraph { Document document = domImpl.createDocument(svgNS, "svg", null); // Create an instance of the SVG Generator. - SVGGraphics2D svgGenerator = new Generator(document); + IDiagram d = ctx.getDefaultHintContext().getHint(DiagramHints.KEY_DIAGRAM); + Resource r = d.getHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE); + SVGGraphics2D svgGenerator; + if (r != null) + svgGenerator = new Generator(document,r.toString()); + else + svgGenerator = new Generator(document); RenderSVGContext result = new RenderSVGContext(); @@ -661,8 +692,7 @@ public class SCLScenegraph { if (selection != null) { // This prevents workbench selection from being left over. // Also prevents scene graph crap from being left on the screen. - IDiagram d = ctx.getDefaultHintContext().getHint(DiagramHints.KEY_DIAGRAM); - selection.setSelection(0, d.getElements()); + selection.setSelection(0, d.getElements()); } G2DSceneGraph sg = ctx.getSceneGraph(); @@ -863,7 +893,8 @@ public class SCLScenegraph { parentBuilder.append(SELECTION_MASK_SECTION, "\n"); parentBuilder.append(SELECTION_SECTION, "\n"); - parentBuilder.append(MAIN_SECTION, "\n"); + senBuilders.put((ConnectionNode)node, new RenderSVGContext()); + } else if (isSelection0(node)) { @@ -1067,8 +1098,28 @@ public class SCLScenegraph { @Override public void leave(IG2DNode node) { - if(node instanceof ConnectionNode || node instanceof SVGNode) { + if( node instanceof SVGNode) { // We are done + } else if (node instanceof ConnectionNode) { + RenderSVGContext parentBuilder = getParentBuilder(node); + SingleElementNode sen = (SingleElementNode)node; + RenderSVGContext b = senBuilders.get(sen); + String content = b.get(MAIN_SECTION); + if(content.isEmpty()) { + if(sen.getKey() != null) { + + for(SelectionNode n : NodeUtil.collectNodes(node, SelectionNode.class)) { + n.setIgnore(true); + } + + Element doc = renderSVGNode(svgGenerator, (IG2DNode)node); + String svg = printSVGDocument(doc); + parentBuilder.append(MAIN_SECTION, svg); + } + } else { + parentBuilder.append(b); + } + parentBuilder.append(MAIN_SECTION, "\n"); } else if (node instanceof G2DParentNode) { RenderSVGContext parentBuilder = getParentBuilder(node);