X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fcontributions%2FPasteDistrictVertexHandler.java;h=7fadac3fd32743aac2800e79017027463c22fd2a;hb=a1fb6a041444504a126b01ad1137e14a4994fa30;hp=c9aa0f3cfc4c04c95cc9b1faebbf2c9fa03d31f4;hpb=d047c535b73df03168c11bb798a8c349f7bec732;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/PasteDistrictVertexHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/PasteDistrictVertexHandler.java index c9aa0f3c..7fadac3f 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/PasteDistrictVertexHandler.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/PasteDistrictVertexHandler.java @@ -137,53 +137,14 @@ public class PasteDistrictVertexHandler { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); Resource sourceMappedElement = graph.getPossibleObject(sourceElement, DN.MappedComponent); - sourceCopyAttributes.putAll(copyAttributes(graph, sourceMappedElement)); + sourceCopyAttributes.putAll(copyAttributes(graph, sourceElement, sourceMappedElement)); Resource targetMappedElement = graph.getPossibleObject(targetElement, DN.MappedComponent); - targetCopyAttributes.putAll(copyAttributes(graph, targetMappedElement)); + targetCopyAttributes.putAll(copyAttributes(graph, targetElement, targetMappedElement)); if (sourceMappedElement != null && cut) RemoverUtil.remove(graph, sourceMappedElement); if (targetMappedElement != null) RemoverUtil.remove(graph, targetMappedElement); } - - private Map copyAttributes(WriteGraph graph, Resource mappedElement) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - - Resource mapping = graph.getSingleObject(sourceElement, DN.HasMapping); - Collection statements = graph.getStatements(mapping, L0.HasProperty); - Collection mappingAttributeStatements = statements.stream().filter(stm -> { - try { - Resource predicate = stm.getPredicate(); - Resource hasDomain = graph.getPossibleObject(predicate, L0.HasDomain); - if (hasDomain != null && hasDomain.equals(DN.Mapping_VertexMapping)) { - // filter out x and y and z - Resource vertexAttribute = attributeMappingToVertexAttribute(graph, DN, predicate); - return vertexAttribute != null; - } - } catch (Exception e) { - e.printStackTrace(); - } - return false; - }).collect(Collectors.toList()); - Resource component = graph.getPossibleObject(mappedElement, ModelingResources.getInstance(graph).ElementToComponent); - Variable variable = Variables.getVariable(graph, component); - Map predValues = new HashMap<>(); - for (Statement stm : mappingAttributeStatements) { - String propertyName = graph.getPossibleValue(stm.getObject()); - if (propertyName != null) { - Object propertyValue = variable.getPossiblePropertyValue(graph, propertyName); - if (propertyValue != null) { - predValues.put(attributeMappingToVertexAttribute(graph, DN, stm.getPredicate()), propertyValue); - } else { - System.err.println("no property value for " + variable.getURI(graph) + " and property " + propertyName); - } - } else { - System.err.println("stm.getObject() is not string " + stm.getObject()); - } - } - return predValues; - } }); ThreadUtils.getNonBlockingWorkExecutor().schedule(() -> { try { @@ -273,6 +234,45 @@ public class PasteDistrictVertexHandler { } + private static Map copyAttributes(WriteGraph graph, Resource sourceElement, Resource mappedElement) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + + Resource mapping = graph.getSingleObject(sourceElement, DN.HasMapping); + Collection statements = graph.getStatements(mapping, L0.HasProperty); + Collection mappingAttributeStatements = statements.stream().filter(stm -> { + try { + Resource predicate = stm.getPredicate(); + Resource hasDomain = graph.getPossibleObject(predicate, L0.HasDomain); + if (hasDomain != null && hasDomain.equals(DN.Mapping_VertexMapping)) { + // filter out x and y and z + Resource vertexAttribute = attributeMappingToVertexAttribute(graph, DN, predicate); + return vertexAttribute != null; + } + } catch (Exception e) { + e.printStackTrace(); + } + return false; + }).collect(Collectors.toList()); + Resource component = graph.getPossibleObject(mappedElement, ModelingResources.getInstance(graph).ElementToComponent); + Variable variable = Variables.getVariable(graph, component); + Map predValues = new HashMap<>(); + for (Statement stm : mappingAttributeStatements) { + String propertyName = graph.getPossibleValue(stm.getObject()); + if (propertyName != null) { + Object propertyValue = variable.getPossiblePropertyValue(graph, propertyName); + if (propertyValue != null) { + predValues.put(attributeMappingToVertexAttribute(graph, DN, stm.getPredicate()), propertyValue); + } else { + System.err.println("no property value for " + variable.getURI(graph) + " and property " + propertyName); + } + } else { + System.err.println("stm.getObject() is not string " + stm.getObject()); + } + } + return predValues; + } + private static Resource attributeMappingToVertexAttribute(ReadGraph graph, DistrictNetworkResource DN, Resource attribute) throws DatabaseException { Resource attr = null; if (attribute.equals(DN.Mapping_VertexMapping_ElevationAttribute)) @@ -321,6 +321,40 @@ public class PasteDistrictVertexHandler { attr = DN.Vertex_HasVelocity; else if (attribute.equals(DN.Mapping_VertexMapping_VolFlowAttribute)) attr = DN.Vertex_HasVolFlow; + else if (attribute.equals(DN.Mapping_VertexMapping_PumpInReturnLineAttribute)) + attr = DN.Vertex_HasPumpInReturnLine; + else if (attribute.equals(DN.Mapping_VertexMapping_HeadPumpMaximumAttribute)) + attr = DN.Vertex_HasHeadPumpMaximum; + else if (attribute.equals(DN.Mapping_VertexMapping_HeadPumpNominalAttribute)) + attr = DN.Vertex_HasHeadPumpNominal; + else if (attribute.equals(DN.Mapping_VertexMapping_FrequencyConverterControlledAttribute)) + attr = DN.Vertex_HasFrequencyConverterControlled; + else if (attribute.equals(DN.Mapping_VertexMapping_InternalValveMeasurementAttribute)) + attr = DN.Vertex_HasInternalValveMeasurement; + else if (attribute.equals(DN.Mapping_VertexMapping_PumpMassFlowNominalAttribute)) + attr = DN.Vertex_HasPumpMassFlowNominal; + else if (attribute.equals(DN.Mapping_VertexMapping_PumpMeMaxAttribute)) + attr = DN.Vertex_HasPumpMeMax; + else if (attribute.equals(DN.Mapping_VertexMapping_PumpMeMinAttribute)) + attr = DN.Vertex_HasPumpMeMin; + else if (attribute.equals(DN.Mapping_VertexMapping_PumpSpeedMaxAttribute)) + attr = DN.Vertex_HasPumpSpeedMax; + else if (attribute.equals(DN.Mapping_VertexMapping_PumpSpeedMinAttribute)) + attr = DN.Vertex_HasPumpSpeedMin; + else if (attribute.equals(DN.Mapping_VertexMapping_ValveReturnLineAttribute)) + attr = DN.Vertex_HasValveReturnLine; + else if (attribute.equals(DN.Mapping_VertexMapping_ValveMeMaxAttribute)) + attr = DN.Vertex_HasValveMeMax; + else if (attribute.equals(DN.Mapping_VertexMapping_ValveMeMinAttribute)) + attr = DN.Vertex_HasValveMeMin; + else if (attribute.equals(DN.Mapping_VertexMapping_ValveMinPositionAttribute)) + attr = DN.Vertex_HasValveMinPosition; + else if (attribute.equals(DN.Mapping_VertexMapping_ValveOutletModeAttribute)) + attr = DN.Vertex_HasValveOutletMode; + else if (attribute.equals(DN.Mapping_VertexMapping_ValvePressLossNominalAttribute)) + attr = DN.Vertex_HasValvePressLossNominal; + else if (attribute.equals(DN.Mapping_VertexMapping_OpeningTimeAttribute)) + attr = DN.Vertex_HasOpeningTime; else if (attribute.equals(DN.Mapping_VertexMapping_XAttribute)) attr = null; // ignore this! else if (attribute.equals(DN.Mapping_VertexMapping_YAttribute))