]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Add hashcodes from URI's as id if no component is found for SVG print 74/674/5
authorjsimomaa <jani.simomaa@gmail.com>
Mon, 3 Jul 2017 18:46:33 +0000 (21:46 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Mon, 3 Jul 2017 19:24:11 +0000 (22:24 +0300)
Change-Id: If278ef81d6006aff9ac487e2d34f014e0b671f28

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

index bfab7fc6c0f7f8472a4c4158f547a0cf6acce68e..6345a132985c875bdf5b02cf5b2bc73e6d06f9a3 100644 (file)
@@ -30,6 +30,7 @@ import org.apache.batik.dom.GenericDOMImplementation;
 import org.apache.batik.svggen.SVGGeneratorContext;
 import org.apache.batik.svggen.SVGGraphics2D;
 import org.simantics.Simantics;
+import org.simantics.datatypes.literal.GUID;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.UnaryRead;
@@ -498,29 +499,27 @@ public class SCLScenegraph {
                                 try {
                                     if (p instanceof Resource) {
                                         Resource element = (Resource) p;
-                                        if (graph.isInstanceOf(element, DIA.Connection) || graph.isInstanceOf(element, DIA.Terminal)) {
-                                            // Ok, lets create a hashcode for connections and terminals as they do not have identifiers 
-                                            return graph.getURI(element).hashCode();
-                                        } else if (graph.isInstanceOf(element, DIA.Element)) {
+                                        if (graph.isInstanceOf(element, DIA.Element)) {
                                             Resource component = graph.getPossibleObject(element, MOD.ElementToComponent);
                                             if (component != null) {
-                                                Object relatedValue = graph.getPossibleRelatedValue(component, L0.identifier);
-                                                if (relatedValue != null) {
-                                                    if (relatedValue instanceof Object[]) {
-                                                        // OK, found guid, lets generate new based on URI
-                                                        return Arrays.toString(createURIBasedL0Identifier(graph, component));
-                                                    } else {
-                                                        System.err.println("Component " + component + " identifeir is not normal: " + relatedValue);
-                                                    }
+                                                GUID identifier = graph.getPossibleRelatedValue(component, L0.identifier, GUID.BINDING);
+                                                if (identifier != null) {
+                                                    return Arrays.toString(createURIBasedL0Identifier(graph, component));
                                                 } else {
-                                                    System.err.println("Compoennt " + component + " dooes not have identifier");
+                                                    LOGGER.error("Component {} does not have GUID identifier!", component);
                                                 }
+                                            } else if (graph.isInstanceOf(element, DIA.Connection) || graph.isInstanceOf(element, DIA.Terminal)) {
+                                                // Ok, lets create a hashcode for connections and terminals as they do not have identifiers 
+                                                return graph.getURI(element).hashCode();
                                             } else {
-                                                System.err.println("Element " + element + " does not have component");
+                                                // Ok, lets create a hashcode or either return empty string in cases where no ID is required
+                                                if (graph.hasStatement(element, L0.HasName))
+                                                    return graph.getURI(element).hashCode();
+                                                return "";
                                             }
                                         }
                                     } else {
-                                        System.err.println("p is not resource but is " + p);
+                                        LOGGER.error("Parameter p {} is not resource but it is {}", p, p.getClass());
                                     }
                                     return p;
                                 } catch (DatabaseException e) {