From: jsimomaa Date: Mon, 3 Jul 2017 18:46:33 +0000 (+0300) Subject: Add hashcodes from URI's as id if no component is found for SVG print X-Git-Tag: v1.31.0~279^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F74%2F674%2F5;p=simantics%2Fplatform.git Add hashcodes from URI's as id if no component is found for SVG print Change-Id: If278ef81d6006aff9ac487e2d34f014e0b671f28 --- diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java index bfab7fc6c..6345a1329 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java @@ -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) {