From: Marko Luukkainen Date: Fri, 29 Mar 2019 10:47:11 +0000 (+0200) Subject: Fix SCL SceneGraph is omitting graphical elements X-Git-Tag: v1.43.0~136^2~167^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=2bd26538bb54ec285c01ba1a170f2486086c96a4;ds=sidebyside Fix SCL SceneGraph is omitting graphical elements gitlab #283 Change-Id: I660a9344ebdcb9aef8adecd712025bd2a623de8d --- 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 d3fd1cca9..40a526585 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java @@ -68,6 +68,7 @@ import org.simantics.scenegraph.g2d.nodes.BackgroundNode; import org.simantics.scenegraph.g2d.nodes.BoundsNode; import org.simantics.scenegraph.g2d.nodes.ConnectionNode; import org.simantics.scenegraph.g2d.nodes.DataNode; +import org.simantics.scenegraph.g2d.nodes.LinkNode; import org.simantics.scenegraph.g2d.nodes.NavigationNode; import org.simantics.scenegraph.g2d.nodes.SVGNode; import org.simantics.scenegraph.g2d.nodes.SelectionNode; @@ -673,22 +674,28 @@ public class SCLScenegraph { // get the bounds of the content Rectangle2D content = rtreeBounds; - // To account for dynamic padding of selection rectangles (5 units + stroke width) - int offset = 6; - double scale = width < 0 || height < 0 ? 1.0 : Math.min((width - 2*offset) / content.getWidth(), (height - 2*offset) / content.getHeight()); - - AffineTransform tr = new AffineTransform(); - tr.translate(offset, offset); - tr.scale(scale, scale); - tr.translate(-content.getX(), -content.getY()); - tr.getMatrix(matrix); + if (content != null) { + // To account for dynamic padding of selection rectangles (5 units + stroke width) + int offset = 6; + + double scale = width < 0 || height < 0 ? 1.0 : Math.min((width - 2*offset) / content.getWidth(), (height - 2*offset) / content.getHeight()); + + AffineTransform tr = new AffineTransform(); + tr.translate(offset, offset); + tr.scale(scale, scale); + tr.translate(-content.getX(), -content.getY()); + tr.getMatrix(matrix); + svgGenerator.setSVGCanvasSize(new Dimension((int)Math.ceil(scale * content.getWidth()) + 2*offset, (int)Math.ceil(scale * content.getHeight()) + 2*offset)); + } else { + svgGenerator.setSVGCanvasSize(new Dimension(100, 100)); + } //svgGenerator.translate(offset, offset); //svgGenerator.scale(scale, scale); // translate svgGenerator to the x and y coordinates of current content //svgGenerator.translate(-content.getX(), -content.getY()); - svgGenerator.setSVGCanvasSize(new Dimension((int)Math.ceil(scale * content.getWidth()) + 2*offset, (int)Math.ceil(scale * content.getHeight()) + 2*offset)); + //svgGenerator.setClip(content); result.append(MAIN_SECTION, ""); @@ -906,6 +913,18 @@ public class SCLScenegraph { parentBuilder.append(ALL_SECTIONS, "\n"); } } + } else if (!(node instanceof RouteGraphNode) && !(node instanceof LinkNode)){ + try { + Element doc = renderSVGNode(svgGenerator, (IG2DNode)node); + if (doc.getElementsByTagName("g").getLength() == 0) + return; + String svg = printSVGDocument(doc); + parentBuilder.append(MAIN_SECTION, ""); + parentBuilder.append(MAIN_SECTION, svg); + parentBuilder.append(MAIN_SECTION, "\n"); + } catch (Exception e) { + // TODO: There are nodes that do not behave well when rendered to SVG. For backwards compatibility, we don't handle the exceptions. + } } //enters.put(node, b.length()); diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/BackgroundNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/BackgroundNode.java index 46804e656..00c18879b 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/BackgroundNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/BackgroundNode.java @@ -47,7 +47,10 @@ public class BackgroundNode extends G2DNode { public void render(Graphics2D g) { Rectangle2D drawBounds = bounds; if(drawBounds == null) { - drawBounds = (Rectangle2D)g.getClipBounds().clone(); // Fill whole clip area if bounds is not defined + if (g.getClipBounds() != null) + drawBounds = (Rectangle2D)g.getClipBounds().clone(); // Fill whole clip area if bounds is not defined + else + return; } if (color!=null) {