]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java
Handle SelectionOutline interface implementation in SCLScenegraph
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / SCLScenegraph.java
index fad803ce41a4a84bdb11991a06f73e0bdc3a3451..82115ef0e0825e2c9b8b2c69793f6bffd015344b 100644 (file)
@@ -51,6 +51,7 @@ import org.simantics.g2d.canvas.ICanvasContext;
 import org.simantics.g2d.diagram.DiagramHints;
 import org.simantics.g2d.diagram.IDiagram;
 import org.simantics.g2d.diagram.handler.DataElementMap;
+import org.simantics.g2d.diagram.participant.ElementPainter.SelectionShapeNode;
 import org.simantics.g2d.diagram.participant.Selection;
 import org.simantics.g2d.element.IElement;
 import org.simantics.g2d.scenegraph.ICanvasSceneGraphProvider;
@@ -914,6 +915,39 @@ public class SCLScenegraph {
                         parentBuilder.append(ALL_SECTIONS, "\n<g transform=\"" + m + "\">");
                     }
                 }
+            } else if (node instanceof TextNode) {
+                TextNode text = (TextNode)node;
+                               
+                 SingleElementNode parentSEN = (SingleElementNode)NodeUtil.getNearestParentOfType(node, SingleElementNode.class);
+                 if(parentSEN != null) {
+                        
+                        text.setShowSelection(false);
+                        Element doc = renderSVGNode(svgGenerator, (IG2DNode)node);
+                     String svg = printSVGDocument(doc);
+                     parentBuilder.append(MAIN_SECTION, svg);
+                     
+                        RenderSVGContext parentBuilder2 = getParentBuilder(parentSEN);
+                     
+                     String key = getKey(parentSEN);
+                     text.setShowSelection(true);
+                     doc = renderSVGNode(svgGenerator, (IG2DNode)node);
+                     svg = printSVGDocument(doc);
+                     
+                     parentBuilder2.append(SELECTION_SECTION, "\n<g style=\"visibility:hidden\" class=\"selection\" id=\"" + key + "\">");
+                     parentBuilder2.append(SELECTION_SECTION, svg);
+                     parentBuilder2.append(SELECTION_SECTION, "\n</g>");
+                     parentBuilder2.append(SELECTION_MASK_SECTION, "\n<g class=\"selectionMask\" id=\"" + key /*+ "\" transform=\"" + matrixString + "\"*/+ "\">");
+                     Rectangle2D rect = text.getBounds();
+                     // NaN
+                     if(rect.getHeight() == rect.getHeight() && rect.getWidth() == rect.getWidth()) {
+                           parentBuilder2.append(SELECTION_MASK_SECTION,"<rect style=\"fill:#fff\" opacity=\"" + OPACITY + "\"");
+                           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 RouteGraphNode) && !(node instanceof LinkNode)){
                try {
                        Element doc = renderSVGNode(svgGenerator, (IG2DNode)node);
@@ -931,9 +965,31 @@ public class SCLScenegraph {
                        if (!hasContent)
                            return;
                        String svg = printSVGDocument(doc);
-                       parentBuilder.append(MAIN_SECTION, "<g class=\"" +node.getSimpleClassName() +"\">");
-                       parentBuilder.append(MAIN_SECTION, svg);
-                       parentBuilder.append(MAIN_SECTION, "\n</g>");
+                       if (node instanceof SelectionShapeNode) {
+                               SingleElementNode parentSEN = (SingleElementNode)NodeUtil.getNearestParentOfType(node, SingleElementNode.class);
+                        if(parentSEN != null) {
+                                String key = getKey(parentSEN);
+                                RenderSVGContext parentBuilder2 = getParentBuilder(parentSEN);
+                                parentBuilder2.append(SELECTION_SECTION, "\n<g style=\"visibility:hidden\" class=\"selection\" id=\"" + key + "\">");
+                             parentBuilder2.append(SELECTION_SECTION, svg);
+                             parentBuilder2.append(SELECTION_SECTION, "\n</g>");
+                             
+                             parentBuilder2.append(SELECTION_MASK_SECTION, "\n<g class=\"selectionMask\" id=\"" + key /*+ "\" transform=\"" + matrixString + "\"*/+ "\">");
+                             Rectangle2D rect = node.getBounds();
+                             // NaN
+                             if(rect.getHeight() == rect.getHeight() && rect.getWidth() == rect.getWidth()) {
+                                   parentBuilder2.append(SELECTION_MASK_SECTION,"<rect style=\"fill:#fff\" opacity=\"" + OPACITY + "\"");
+                                   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 {
+                               parentBuilder.append(MAIN_SECTION, "<g class=\"" +node.getSimpleClassName() +"\">");
+                               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.
                }