]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java
Fix SCL SceneGraph is omitting graphical elements
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / SCLScenegraph.java
index d3fd1cca9b9314cf4933c78d331fe22f349d85be..40a5265852fa79083df1781db24a563df95d4532 100644 (file)
@@ -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, "<g class=\"symbols\">");
@@ -906,6 +913,18 @@ public class SCLScenegraph {
                         parentBuilder.append(ALL_SECTIONS, "\n<g transform=\"" + m + "\">");
                     }
                 }
+            } 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, "<g>");
+                       parentBuilder.append(MAIN_SECTION, svg);
+                       parentBuilder.append(MAIN_SECTION, "\n</g>");
+               } 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());