]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SVGNode.java
Dynamic terminals and connections
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / nodes / SVGNode.java
index 2fc37b7d59ab6bc9179943ab80b60246118e08e3..ec85fd75c86e7893a8b7341bcfde6641e380d244 100644 (file)
@@ -27,6 +27,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.WeakHashMap;
 
 import org.simantics.scenegraph.ExportableWidget.RasterOutputWidget;
@@ -172,32 +173,55 @@ public class SVGNode extends G2DNode implements InitValueSupport, LoaderNode {
                     diagramCache = null;
                 }
 
-                // NOTE: hard-coded to assume all SVG data is encoded in UTF-8
-                byte[] dataBytes = data.getBytes("UTF-8");
+                
+                // Lets check for rootAssignment that contributes the whole SVG 
+                SVGNodeAssignment rootAssignment = null;
+                if (!assignments.isEmpty()) {
+                    for (SVGNodeAssignment ass : assignments) {
+                        if (ass.attributeNameOrId.equals("$root")) {
+                            rootAssignment = ass;
+                            break;
+                        }
+                    }
+                }
+                byte[] dataBytes;
+                if (rootAssignment != null) {
+                    dataBytes = rootAssignment.value.getBytes("UTF-8");
+                } else {
+                    // NOTE: hard-coded to assume all SVG data is encoded in UTF-8
+                    dataBytes = data.getBytes("UTF-8");
+                }
                 dataHash = digest(dataBytes, assignments);
                 URI uri = univ.loadSVG(new ByteArrayInputStream(dataBytes), dataHash);
                 diagramCache = univ.getDiagram(uri, false);
 
                 if (diagramCache != null) {
                     univ.incRefCount(diagramCache.getXMLBase());
-
-                    if (diagramCache.getRoot() == null) {
+                    SVGRoot root = diagramCache.getRoot();
+                    if (root == null) {
                         univ.decRefCount(diagramCache.getXMLBase());
                         diagramCache = univ.getDiagram(univ.loadSVG(BROKEN_SVG_DATA), false);
                         dataHash = "broken";
                         univ.incRefCount(diagramCache.getXMLBase());
                         bbox = (Rectangle2D) diagramCache.getRoot().getBoundingBox().clone();
                     } else {
-                        bbox = diagramCache.getRoot().getBoundingBox();
+                        bbox = root.getBoundingBox();
                         if (bbox.isEmpty()) {
-                            univ.decRefCount(diagramCache.getXMLBase());
-                            diagramCache = univ.getDiagram(univ.loadSVG(EMPTY_SVG_DATA), false);
-                            dataHash = "empty";
-                            univ.incRefCount(diagramCache.getXMLBase());
-                            bbox = (Rectangle2D) diagramCache.getRoot().getBoundingBox().clone();
+                            // Lets check if this should be visible or not
+                            Set presentationAttributes = root.getPresentationAttributes();
+                            if (!presentationAttributes.contains("display")) {
+                                // TODO: fix this - How can one read values of attributes in SVG salamander???
+                                univ.decRefCount(diagramCache.getXMLBase());
+                                diagramCache = univ.getDiagram(univ.loadSVG(EMPTY_SVG_DATA), false);
+                                dataHash = "empty";
+                                univ.incRefCount(diagramCache.getXMLBase());
+                                bbox = (Rectangle2D) root.getBoundingBox().clone();
+                            } else {
+                                bbox = new Rectangle2D.Double(0, 0, 0, 0);
+                            }
                         } else {
                             if (applyAssignments(diagramCache, assignments)) {
-                                bbox = (Rectangle2D) diagramCache.getRoot().getBoundingBox().clone();
+                                bbox = (Rectangle2D) root.getBoundingBox().clone();
                             } else {
                                 bbox = (Rectangle2D) bbox.clone();
                             }
@@ -227,6 +251,9 @@ public class SVGNode extends G2DNode implements InitValueSupport, LoaderNode {
             return false;
         boolean changed = false;
         for (SVGNodeAssignment ass : assignments) {
+//             System.err.println("assign: " + ass.elementId + " " + ass.attributeNameOrId + " " + ass.value);
+//             if("opacity".equals(ass.attributeNameOrId))
+//                     System.err.println("faaf");
             SVGElement e = diagram.getElement(ass.elementId);
             if (e != null) {
                 if ("$text".equals(ass.attributeNameOrId)) {