]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java
Diagram to SVG was rendering removed elements
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / SCLScenegraph.java
index 5f375095fb239db428f53a07040bc58e7b10b21d..2591dc7d85dfd79ffa05dd208667d1b9caf5aa65 100644 (file)
@@ -36,6 +36,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.request.UnaryRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.RuntimeDatabaseException;
+import org.simantics.diagram.elements.DecorationSVGNode;
 import org.simantics.diagram.elements.DiagramNodeUtil;
 import org.simantics.diagram.elements.TextGridNode;
 import org.simantics.diagram.elements.TextNode;
@@ -61,7 +62,6 @@ 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.DecorationSVGNode;
 import org.simantics.scenegraph.g2d.nodes.NavigationNode;
 import org.simantics.scenegraph.g2d.nodes.SVGNode;
 import org.simantics.scenegraph.g2d.nodes.SelectionNode;
@@ -599,6 +599,7 @@ public class SCLScenegraph {
             }
 
                        G2DSceneGraph sg = ctx.getSceneGraph();
+                       sg.performCleanup();
                        G2DParentNode root = (G2DParentNode) sg.getRootNode();
 
                        // rtree is the actual content of the diagram
@@ -632,15 +633,20 @@ public class SCLScenegraph {
                        double trX = -1 * content.getX();
                        double trY = -1 * content.getY();
                        
-                       result.append(MAIN_SECTION, "<g transform=\"translate(");
-                       result.append(MAIN_SECTION, "" + trX);
-                       result.append(MAIN_SECTION, " ");
-                       result.append(MAIN_SECTION, "" + trY);
-                       result.append(MAIN_SECTION, "\">");
-
-                       result.append(SELECTION_SECTION, "<g class=\"selections\">");
+                       // NaNs
+                       if(!Double.isFinite(trX)) trX = 0;
+                       if(!Double.isFinite(trY)) trY = 0;
                        
+                       result.append(MAIN_SECTION, "<g class=\"symbols\">");
+                       result.append(SELECTION_SECTION, "<g class=\"selections\">");
                        result.append(SELECTION_MASK_SECTION, "<g class=\"selectionMasks\">");
+
+                       result.append(ALL_SECTIONS, "<g transform=\"translate(");
+                       result.append(ALL_SECTIONS, "" + trX);
+                       result.append(ALL_SECTIONS, ", ");
+                       result.append(ALL_SECTIONS, "" + trY);
+                       result.append(ALL_SECTIONS, ")\">");
+
                        
                        KeyVisitor keyVisitor = new KeyVisitor();
                        sg.accept(keyVisitor);
@@ -658,9 +664,7 @@ public class SCLScenegraph {
                }
 
 
-               result.append(SELECTION_SECTION, "</g>");
-               result.append(SELECTION_MASK_SECTION, "</g>");
-               result.append(MAIN_SECTION, "</g>");
+               result.append(ALL_SECTIONS, "</g></g>");
 
                StringBuilder res = new StringBuilder();
                res.append("<svg width=\"100%\" height=\"100%\" stroke=\"black\">");
@@ -785,10 +789,13 @@ public class SCLScenegraph {
                     parentBuilder2.append(SELECTION_SECTION, "\n</g>");
                     parentBuilder2.append(SELECTION_MASK_SECTION, "\n<g class=\"selectionMask\" id=\"" + key + "\">");
                     Rectangle2D rect = n.getRect();
-                    parentBuilder2.append(SELECTION_MASK_SECTION,"<rect style=\"fill:#fff\" opacity=\"0.001\"");
-                    parentBuilder2.append(SELECTION_MASK_SECTION," x=\"" + rect.getX() + "\" y=\"" + rect.getY() + "\"");
-                    parentBuilder2.append(SELECTION_MASK_SECTION," width=\"" + rect.getWidth() + "\" height=\"" + rect.getHeight() + "\"");
-                    parentBuilder2.append(SELECTION_MASK_SECTION,"></rect>");
+                    // NaN
+                    if(rect.getHeight() == rect.getHeight() && rect.getWidth() == rect.getWidth()) {
+                           parentBuilder2.append(SELECTION_MASK_SECTION,"<rect style=\"fill:#fff\" opacity=\"0.001\"");
+                           parentBuilder2.append(SELECTION_MASK_SECTION," x=\"" + rect.getX() + "\" y=\"" + rect.getY() + "\"");
+                           parentBuilder2.append(SELECTION_MASK_SECTION," width=\"" + rect.getWidth() + "\" height=\"" + rect.getHeight() + "\"");
+                           parentBuilder2.append(SELECTION_MASK_SECTION,"></rect>");
+                    }
                     parentBuilder2.append(SELECTION_MASK_SECTION,"\n</g>");
                 }
             } else if (node instanceof SVGNode) {