- Simantics.getSession().asyncRequest(
- NewCompositeActionFactory.createCompositeRequest(target, defaultName, compositeType),
- new Procedure<Resource>() {
- @Override
- public void execute(Resource composite) {
- Simantics.getSession().asyncRequest(new WriteRequest() {
-
- @Override
- public void perform(WriteGraph graph) throws DatabaseException {
- DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
- Resource diagram = graph.getSingleObject(composite, ModelingResources.getInstance(graph).CompositeToDiagram);
- graph.claim(diagram, DN.EdgeDefaultMapping, dialog.getDefaultEdgeMapping());
- graph.claim(diagram, DN.VertexDefaultMapping, dialog.getDefaultVertexMapping());
- graph.claim(diagram, DN.HasSpatialRefSystem, dialog.getCRS());
- }
- });
- DefaultActions.asyncPerformDefaultAction(Simantics.getSession(), composite, false, false, true);
- procedure.execute(composite);
- }
-
- @Override
- public void exception(Throwable t) {
- LOGGER.error("Failed to create composite, see exception for details.", t);
- procedure.exception(t);
- }
- });
+ Simantics.getSession().asyncRequest(new WriteResultRequest<Resource>() {
+
+ @Override
+ public Resource perform(WriteGraph graph) throws DatabaseException {
+ return DistrictNetworkUtil.createNetworkDiagram(graph, target, compositeType, defaultName,
+ dialog.getDefaultEdgeMapping(),
+ dialog.getDefaultVertexMapping(),
+ dialog.getRightClickVertexMapping(),
+ dialog.getLeftClickVertexMapping(),
+ dialog.getCRS()
+ );
+ }
+
+
+ }, new Procedure<Resource>() {
+
+ @Override
+ public void execute(Resource composite) {
+ DefaultActions.asyncPerformDefaultAction(Simantics.getSession(), composite, false, false, true);
+ procedure.execute(composite);
+ }
+
+ @Override
+ public void exception(Throwable t) {
+ LOGGER.error("Failed to create composite, see exception for details.", t);
+ procedure.exception(t);
+ }
+ });
+ }
+
+ public static Collection<Resource> getDistrictDiagrams(ReadGraph graph) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ Collection<Resource> indexRoots = graph.sync(new ObjectsWithType(Simantics.getProjectResource(), L0.ConsistsOf, L0.IndexRoot));
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ Set<Resource> results = new HashSet<>();
+ for (Resource indexRoot : indexRoots) {
+ Collection<Resource> diagrams = QueryIndexUtils.searchByType(graph, indexRoot, DN.Diagram);
+ results.addAll(diagrams);
+ }
+ return results;
+ }
+
+ private static List<String> listInstanceNames(ReadGraph graph, Variable context, Resource type) throws DatabaseException {
+ Resource indexRoot = Variables.getIndexRoot(graph, context);
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ List<Resource> properties = Collections.emptyList();//QueryIndexUtils.searchByType(graph, indexRoot, DN.Vertex_ScaleProperty);
+ return properties.stream()
+ .map(m -> createEnumeratedValue(graph, m))
+ .map(EnumeratedValue::getName)
+ .collect(Collectors.toList());
+ }
+
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+ public static Object arrowLengthPropertyEnumerationValues(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ return listInstanceNames(graph, context, DN.Edge_ArrowLengthProperty);
+ }
+
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+ public static Object arrowLengthPropertyModifier(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
+ Resource diagram = resolveElement(graph, context);
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ return baseMappingModifier(graph, diagram, DN.Diagram_arrowLengthProperty, DN.Edge_ArrowLengthProperty, context);
+ }
+
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+ public static Function1<Resource, Double> hasDiameterValue(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
+ return directPropertyValueFunction(DistrictNetworkResource.getInstance(graph).Edge_HasDiameter, 0);
+ }
+
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+ public static Function1<Resource, Double> hasNominalMassFlowValue(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
+ return directPropertyValueFunction(DistrictNetworkResource.getInstance(graph).Edge_HasNominalMassFlow, 0);
+ }
+
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+ public static Function1<Resource, Double> hasNominalSupplyPressure(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
+ return directPropertyValueFunction(DistrictNetworkResource.getInstance(graph).Vertex_HasSupplyPressure, 0);
+ }
+
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+ public static Function1<Resource, Double> hasElevation(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
+ return directPropertyValueFunction(DistrictNetworkResource.getInstance(graph).Vertex_HasElevation, 0);
+ }
+
+ private static final Function1<Resource, Double> ONE = new FunctionImpl1<Resource, Double>() {
+ private final Double ONE = 1.0;
+ @Override
+ public Double apply(Resource edge) {
+ return ONE;
+ }
+ @Override
+ public String toString() {
+ return "1";
+ }
+ };
+
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+ public static Function1<Resource, Double> constantOne(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
+ return ONE;