import org.simantics.scenegraph.g2d.nodes.UnboundedNode;
import org.simantics.scenegraph.g2d.nodes.spatial.RTreeNode;
import org.simantics.scenegraph.utils.ColorUtil;
+import org.simantics.scenegraph.utils.GeometryUtils;
import org.simantics.scenegraph.utils.NodeUtil;
import org.simantics.utils.datastructures.collections.CollectionUtils;
import org.simantics.utils.datastructures.hints.HintListenerAdapter;
Shape shape = ElementUtils.getElementShapeOrBounds(e);
Rectangle2D bounds = shape.getBounds2D();
//System.out.println("selection bounds: "+bounds);
- final double marginX = 1 / selectionTransform.getScaleX();
- final double marginY = 1 / selectionTransform.getScaleY();
+
+ Point2D scale = GeometryUtils.getScale2D(selectionTransform);
+ final double marginX = Math.abs(scale.getX()) > 1e-10 ? 1 / scale.getX() : 1;
+ final double marginY = Math.abs(scale.getY()) > 1e-10 ? 1 / scale.getY() : 1;
+
bounds.setFrame(bounds.getMinX() - marginX, bounds.getMinY() - marginY, bounds.getWidth() + 2*marginX, bounds.getHeight() + 2*marginY);
List<SelectionSpecification> ss = e.getElementClass().getItemsByClass(SelectionSpecification.class);
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);
}
- 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\">");
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) {