]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
renderSVG fails if a SingleElementNode does not contain a resource 36/1236/2
authorAntti Villberg <antti.villberg@semantum.fi>
Sat, 18 Nov 2017 19:24:12 +0000 (21:24 +0200)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Sat, 18 Nov 2017 20:33:00 +0000 (23:33 +0300)
refs #7625

Change-Id: I5c0eee38a060207c2a31078586a4c4c85b2c902f

bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java

index c7f3fe4ec97431874529627aee3a09404748b4bc..e0c198388e41f20a0f6848c22b2e70ae34b0ea2f 100644 (file)
@@ -759,10 +759,14 @@ public class SCLScenegraph {
 
         private String getKey(SingleElementNode node) {
             String key;
-            if (mappings.containsKey(node.getKey()))
-                key = mappings.get(node.getKey()).toString();
-            else
-                key = node.getKey().toString();
+               if(node.getKey() != null) {
+                if (mappings.containsKey(node.getKey()))
+                    key = mappings.get(node.getKey()).toString();
+                else
+                    key = node.getKey().toString();
+               } else {
+                       key = Long.toString(node.getId());
+               }
             return key;
         }
 
@@ -813,7 +817,7 @@ public class SCLScenegraph {
                 
                 SelectionNode n = (SelectionNode)node;
                 SingleElementNode parentSEN = (SingleElementNode)NodeUtil.getNearestParentOfType(node, SingleElementNode.class);
-                if(parentSEN != null && parentSEN.getKey() != null) {
+                if(parentSEN != null) {
                     
                        RenderSVGContext parentBuilder2 = getParentBuilder(parentSEN);
                     
@@ -844,15 +848,13 @@ public class SCLScenegraph {
                 AffineTransform at = node.getTransform();
                 if(node instanceof SingleElementNode) {
                     SingleElementNode sen = (SingleElementNode)node;
-                    if(sen.getKey() != null) {
-                        String key = getKey(sen);
-                        String typeClass = sen.getTypeClass();
-                        String clazz = "definedElement";
-                        if(typeClass != null && !typeClass.isEmpty())
-                               clazz = clazz + " " + typeClass;
-                        
-                        parentBuilder.append(MAIN_SECTION, "\n<g class=\""+clazz+"\" id=\"" + key + "\">");
-                    }
+                    String key = getKey(sen);
+                    String typeClass = sen.getTypeClass();
+                    String clazz = "definedElement";
+                    if(typeClass != null && !typeClass.isEmpty())
+                       clazz = clazz + " " + typeClass;
+
+                    parentBuilder.append(MAIN_SECTION, "\n<g class=\""+clazz+"\" id=\"" + key + "\">");
                     senBuilders.put(sen, new RenderSVGContext());
                 }
                 if(!at.isIdentity()) {
@@ -898,16 +900,12 @@ public class SCLScenegraph {
                        RenderSVGContext b = senBuilders.get(sen);
                        String content = b.get(MAIN_SECTION);
                        if(content.isEmpty()) {
-                               if(sen.getKey() != null) {
-
-                                       for(SelectionNode n : NodeUtil.collectNodes(node, SelectionNode.class)) {
-                                               n.setIgnore(true);
-                                       }
-
-                                       Element doc = renderSVGNode((IG2DNode)node);
-                                       String svg = printSVGDocument(doc);
-                                       parentBuilder.append(MAIN_SECTION, svg);
+                               for(SelectionNode n : NodeUtil.collectNodes(node, SelectionNode.class)) {
+                                       n.setIgnore(true);
                                }
+                               Element doc = renderSVGNode((IG2DNode)node);
+                               String svg = printSVGDocument(doc);
+                               parentBuilder.append(MAIN_SECTION, svg);
                        } else {
                                parentBuilder.append(b);
                        }
@@ -919,9 +917,9 @@ public class SCLScenegraph {
                 }
                 if(node instanceof SingleElementNode) {
                     SingleElementNode sen = (SingleElementNode)node;
-                    if(sen.getKey() != null) {
+                    //if(sen.getKey() != null) {
                         parentBuilder.append(MAIN_SECTION, "</g>");
-                    }
+                    //}
                 }
             }
             indent --;