X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fvisualisations%2FDynamicVisualisationsContributions.java;h=e3ede04fb970053c87d17962f2fbf398ab140e98;hb=2de54d0f65ace8c56d27a5a1191e4420b96e22c2;hp=45e52fb55c48c99519f4a17ca7525efec3b4d9d9;hpb=dab24824da1b284b8a4734a069cfba72fb1f05de;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisationsContributions.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisationsContributions.java index 45e52fb5..e3ede04f 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisationsContributions.java +++ b/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisationsContributions.java @@ -17,6 +17,7 @@ import org.simantics.db.common.NamedResource; import org.simantics.db.common.request.ObjectsWithSupertype; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.util.Layer0Utils; +import org.simantics.district.network.visualisations.model.DynamicArrowContribution; import org.simantics.district.network.visualisations.model.DynamicColorContribution; import org.simantics.district.network.visualisations.model.DynamicColorMap; import org.simantics.district.network.visualisations.model.DynamicSizeContribution; @@ -41,6 +42,7 @@ public class DynamicVisualisationsContributions { private static final String DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE = "DynamicVisualisationsContribution"; private static final String COLOR_CONTRIBUTION = "colorContribution"; private static final String SIZE_CONTRIBUTION = "sizeContribution"; + private static final String ARROW_CONTRIBUTION = "arrowContribution"; public static Map dynamicColorMaps(ReadGraph graph) throws DatabaseException { List sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE); @@ -62,7 +64,8 @@ public class DynamicVisualisationsContributions { results.put(colorMap.getLabel(), colorMap); } } catch (ValueNotFound e) { - e.printStackTrace(); + // ignore + LOGGER.debug("Dynamic color maps not found for {}", sclModule, e); } finally { SCLContext.getCurrent().put("graph", oldGraph); } @@ -91,7 +94,8 @@ public class DynamicVisualisationsContributions { results.put(sizeMap.getLabel(), sizeMap); } } catch (ValueNotFound e) { - e.printStackTrace(); + // ignore + LOGGER.debug("Dynamic size maps not found for {}", sclModule, e); } finally { SCLContext.getCurrent().put("graph", oldGraph); } @@ -143,73 +147,86 @@ public class DynamicVisualisationsContributions { Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE); if (sclModule != null) { String moduleURI = graph.getURI(sclModule); - return new DynamicColoringObject(moduleType, getDynamicColorContributionSupplier(moduleURI, COLOR_CONTRIBUTION)); + return new DynamicColoringObject(moduleType, getContributionSupplier(moduleURI, COLOR_CONTRIBUTION)); } return null; } - -// private static DynamicColoringMap dynamicColoringMap(ReadGraph graph, NamedResource moduleType) throws DatabaseException { -// Layer0 L0 = Layer0.getInstance(graph); -// Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE); -// if (sclModule != null) { -// String moduleURI = graph.getURI(sclModule); -// return new DynamicColoringMap(moduleType, getDynamicColoringMapSupplier(moduleURI, COLOR_CONTRIBUTION)); -// } -// return null; -// } - + private static DynamicSizingObject dynamicSizingObject(ReadGraph graph, NamedResource moduleType) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE); if (sclModule != null) { String moduleURI = graph.getURI(sclModule); - return new DynamicSizingObject(moduleType, getDynamicSizeContributionSupplier(moduleURI, SIZE_CONTRIBUTION)); + return new DynamicSizingObject(moduleType, getContributionSupplier(moduleURI, SIZE_CONTRIBUTION)); } return null; } - private static Supplier> getDynamicColorMapSupplier(String uri, String expressionText) { - return () -> { - try { - @SuppressWarnings("unchecked") - List result = (List) SCLOsgi.MODULE_REPOSITORY.getValue(uri, expressionText); - return result.stream();//result.stream().map(DynamicColorContribution::fromTuple9); - } catch (ValueNotFound e) { - LOGGER.error("Could not find contributions", e); - //throw new RuntimeException(e); - return Stream.empty(); + public static Collection dynamicEdgeArrowObjects(ReadGraph graph) throws DatabaseException { + + List sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE); + + List results = new ArrayList<>(); + + for (Resource sharedOntology : sharedOntologies) { + Collection findByType = graph.syncRequest(new ObjectsWithSupertype(sharedOntology, Layer0.getInstance(graph).ConsistsOf, StructuralResource2.getInstance(graph).Component)); + //Collection findByType = QueryIndexUtils.searchByType(graph, sharedOntology, ); + for (Resource find : findByType) { + NamedResource moduleType = new NamedResource(NameLabelUtil.modalName(graph, find), find); + DynamicArrowObject dynamicarrowObject = dynamicEdgeArrowObject(graph, moduleType); + if (dynamicarrowObject != null) + results.add(dynamicarrowObject); } - }; + } + return results; } - - private static Supplier> getDynamicColorContributionSupplier(String uri, String expressionText) { - return () -> { - try { - @SuppressWarnings("unchecked") - List result = (List) SCLOsgi.MODULE_REPOSITORY.getValue(uri, expressionText); - return result.stream();//result.stream().map(DynamicColorContribution::fromTuple9); - } catch (ValueNotFound e) { - LOGGER.error("Could not find contributions", e); - //throw new RuntimeException(e); - return Stream.empty(); - } - }; + + private static DynamicArrowObject dynamicEdgeArrowObject(ReadGraph graph, NamedResource moduleType) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE); + if (sclModule != null) { + String moduleURI = graph.getURI(sclModule); + return new DynamicArrowObject(moduleType, getContributionSupplier(moduleURI, ARROW_CONTRIBUTION)); + } + return null; } - private static Supplier> getDynamicSizeContributionSupplier(String uri, String expressionText) { + private static Supplier> getContributionSupplier(String uri, String expressionText) { return () -> { try { @SuppressWarnings("unchecked") - List result = (List) SCLOsgi.MODULE_REPOSITORY.getValue(uri, expressionText); + List result = (List) SCLOsgi.MODULE_REPOSITORY.getValue(uri, expressionText); return result.stream();//result.stream().map(DynamicColorContribution::fromTuple9); } catch (ValueNotFound e) { - LOGGER.error("Could not find contributions", e); + LOGGER.trace("Could not find contributions for module {} and expression {}", uri, expressionText, e); //throw new RuntimeException(e); return Stream.empty(); } }; } + + public static class DynamicArrowObject { + + private final NamedResource arrowObject; + private final Supplier> arrowContributionSupplier; + private Map arrowContributions; + + public DynamicArrowObject(NamedResource coloringObject, Supplier> arrowContributionSupplier) { + this.arrowObject = coloringObject; + this.arrowContributionSupplier = arrowContributionSupplier; + } + + public NamedResource getArrowObject() { + return arrowObject; + } + public Map getArrowContributions() { + if (arrowContributions == null) + arrowContributions = arrowContributionSupplier.get().collect(Collectors.toMap(c -> c.getLabel(), c -> c)); + return arrowContributions; + } + } + public static class DynamicColoringObject { private final NamedResource coloringObject;