From 7977ea8081aed5396b820c26bcaf354ca878db21 Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Mon, 11 Mar 2019 11:11:39 +0200 Subject: [PATCH] Arrow length indicators for flow magnitude gitlab #39 Change-Id: I0fa73f0025f02e115a49199ef41c82885a1bf4ca (cherry picked from commit 0864cdbfa9df392bceb26ef3431034ebfc995bcb) --- .../DistrictNetworkDiagramSettings.pgraph | 40 ++++++++++++ .../graph/DistrictNetworkProfiles.pgraph | 1 + .../ontology/DistrictNetworkResource.java | 60 +++++++++++++++++ .../network/ui/function/Functions.java | 15 ++++- .../ui/nodes/DistrictNetworkEdgeNode.java | 57 +++++++++++++++-- org.simantics.district.network/adapters.xml | 3 + .../network/profile/ArrowLengthStyle.java | 64 +++++++++++++++++++ .../network/profile/DiagramSettings.java | 21 +++++- .../profile/DiagramSettingsRequest.java | 20 ++++++ 9 files changed, 272 insertions(+), 9 deletions(-) create mode 100644 org.simantics.district.network/src/org/simantics/district/network/profile/ArrowLengthStyle.java diff --git a/org.simantics.district.network.ontology/graph/DistrictNetworkDiagramSettings.pgraph b/org.simantics.district.network.ontology/graph/DistrictNetworkDiagramSettings.pgraph index 8abc05de..69cb2807 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetworkDiagramSettings.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetworkDiagramSettings.pgraph @@ -19,6 +19,12 @@ DN.EdgeThicknessPropertyParameterType -- DN.Edge.ArrowLengthProperty.value ==> "Resource -> Maybe Double" -- DN.Edge.ArrowLengthProperty.gain --> L0.Double -- DN.Edge.ArrowLengthProperty.bias --> L0.Double -- DN.Vertex.ScaleProperty.value ==> "Resource -> Maybe Double" -- DN.Diagram.edgeThicknessProperty --> DN.Edge.ThicknessProperty -- DN.Diagram.arrowLengthGain ==> "Double" -- DN.Diagram.arrowLengthBias ==> "Double" -- DN.Diagram.arrowLengthProperty --> DN.Edge.ArrowLengthProperty -- DN.Diagram.nodeScaleGain ==> "Double" -- DN.Diagram.nodeScaleBias ==> "Double" Maybe Double" +DN.Functions.hasNominalMassFlowValue : L0.Function + L0.HasValueType "Resource -> Maybe Double" + DN.Edge.ThicknessProperty.OnlyGainAndBias: DN.Edge.ThicknessProperty L0.HasLabel "Only Gain and Bias" DN.Edge.ThicknessProperty.value @@ -120,6 +149,17 @@ DN.Edge.ThicknessProperty.Diameter : DN.Edge.ThicknessProperty L0.HasValueType "Resource -> Maybe Double" DN.Edge.ThicknessProperty.gain 0.001 +DN.Edge.ThicknessProperty.FlowRate : DN.Edge.ThicknessProperty + L0.HasLabel "Nominal Mass Flow" + DN.Edge.ThicknessProperty.value + DN.Functions.hasNominalMassFlowValue + DN.Edge.ThicknessProperty.gain 0.1 + +DN.Edge.ArrowLengthProperty.FlowRate : DN.Edge.ArrowLengthProperty + L0.HasLabel "Nominal Mass Flow" + DN.Edge.ArrowLengthProperty.value + DN.Functions.hasNominalMassFlowValue + DN.Edge.ArrowLengthProperty.gain 1.0 DN.Vertex.ScaleProperty.OnlyGainAndBias: DN.Vertex.ScaleProperty L0.HasLabel "Only Gain and Bias" diff --git a/org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph b/org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph index 54700829..a853d85e 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph @@ -22,6 +22,7 @@ DN.Groups.EdgeGroup : DIA.TypeGroup DN.ElementColoringStyle : DIA.Style DN.VertexSizeStyle : DIA.Style DN.EdgeThicknessStyle : DIA.Style +DN.ArrowLengthStyle : DIA.Style DN.HideStyle : DIA.Style DN.VertexSymbolStyle : DIA.Style DN.ConnectionLineStyle : DIA.Style diff --git a/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java b/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java index 178dbc28..a48137cf 100644 --- a/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java +++ b/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java @@ -15,6 +15,8 @@ public class DistrictNetworkResource { public final Resource Actions; public final Resource Actions_NewDNDiagram; public final Resource AddLayerToDNDiagramTemplate; + public final Resource ArrowLengthPropertyParameterType; + public final Resource ArrowLengthStyle; public final Resource BrowseContext; public final Resource Composite; public final Resource Connection; @@ -22,6 +24,12 @@ public class DistrictNetworkResource { public final Resource Diagram; public final Resource Diagram_MappedDiagram; public final Resource Diagram_MappedFromDiagram; + public final Resource Diagram_arrowLengthBias; + public final Resource Diagram_arrowLengthBias_Inverse; + public final Resource Diagram_arrowLengthGain; + public final Resource Diagram_arrowLengthGain_Inverse; + public final Resource Diagram_arrowLengthProperty; + public final Resource Diagram_arrowLengthProperty_Inverse; public final Resource Diagram_backgroundColor; public final Resource Diagram_backgroundColor_Inverse; public final Resource Diagram_drawMapEnabled; @@ -60,6 +68,14 @@ public class DistrictNetworkResource { public final Resource EdgeMappingParameterType; public final Resource EdgeThicknessPropertyParameterType; public final Resource EdgeThicknessStyle; + public final Resource Edge_ArrowLengthProperty; + public final Resource Edge_ArrowLengthProperty_FlowRate; + public final Resource Edge_ArrowLengthProperty_bias; + public final Resource Edge_ArrowLengthProperty_bias_Inverse; + public final Resource Edge_ArrowLengthProperty_gain; + public final Resource Edge_ArrowLengthProperty_gain_Inverse; + public final Resource Edge_ArrowLengthProperty_value; + public final Resource Edge_ArrowLengthProperty_value_Inverse; public final Resource Edge_HasDiameter; public final Resource Edge_HasDiameter_Inverse; public final Resource Edge_HasElevation; @@ -82,6 +98,7 @@ public class DistrictNetworkResource { public final Resource Edge_HasTGround_Inverse; public final Resource Edge_ThicknessProperty; public final Resource Edge_ThicknessProperty_Diameter; + public final Resource Edge_ThicknessProperty_FlowRate; public final Resource Edge_ThicknessProperty_OnlyGainAndBias; public final Resource Edge_ThicknessProperty_bias; public final Resource Edge_ThicknessProperty_bias_Inverse; @@ -92,6 +109,8 @@ public class DistrictNetworkResource { public final Resource Element; public final Resource ElementColoringStyle; public final Resource Functions; + public final Resource Functions_arrowLengthPropertyEnumerationValues; + public final Resource Functions_arrowLengthPropertyModifier; public final Resource Functions_brightnessValidator; public final Resource Functions_compositeInstantiator; public final Resource Functions_constantOne; @@ -103,6 +122,7 @@ public class DistrictNetworkResource { public final Resource Functions_enumerationValues; public final Resource Functions_hasDiameterValue; public final Resource Functions_hasElevation; + public final Resource Functions_hasNominalMassFlowValue; public final Resource Functions_hasNominalSupplyPressure; public final Resource Functions_hueValidator; public final Resource Functions_mappingModifier; @@ -294,6 +314,8 @@ public class DistrictNetworkResource { public static final String Actions = "http://www.simantics.org/DistrictNetwork-1.0/Actions"; public static final String Actions_NewDNDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Actions/NewDNDiagram"; public static final String AddLayerToDNDiagramTemplate = "http://www.simantics.org/DistrictNetwork-1.0/AddLayerToDNDiagramTemplate"; + public static final String ArrowLengthPropertyParameterType = "http://www.simantics.org/DistrictNetwork-1.0/ArrowLengthPropertyParameterType"; + public static final String ArrowLengthStyle = "http://www.simantics.org/DistrictNetwork-1.0/ArrowLengthStyle"; public static final String BrowseContext = "http://www.simantics.org/DistrictNetwork-1.0/BrowseContext"; public static final String Composite = "http://www.simantics.org/DistrictNetwork-1.0/Composite"; public static final String Connection = "http://www.simantics.org/DistrictNetwork-1.0/Connection"; @@ -301,6 +323,12 @@ public class DistrictNetworkResource { public static final String Diagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram"; public static final String Diagram_MappedDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/MappedDiagram"; public static final String Diagram_MappedFromDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/MappedFromDiagram"; + public static final String Diagram_arrowLengthBias = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/arrowLengthBias"; + public static final String Diagram_arrowLengthBias_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/arrowLengthBias/Inverse"; + public static final String Diagram_arrowLengthGain = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/arrowLengthGain"; + public static final String Diagram_arrowLengthGain_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/arrowLengthGain/Inverse"; + public static final String Diagram_arrowLengthProperty = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/arrowLengthProperty"; + public static final String Diagram_arrowLengthProperty_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/arrowLengthProperty/Inverse"; public static final String Diagram_backgroundColor = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/backgroundColor"; public static final String Diagram_backgroundColor_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/backgroundColor/Inverse"; public static final String Diagram_drawMapEnabled = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/drawMapEnabled"; @@ -339,6 +367,14 @@ public class DistrictNetworkResource { public static final String EdgeMappingParameterType = "http://www.simantics.org/DistrictNetwork-1.0/EdgeMappingParameterType"; public static final String EdgeThicknessPropertyParameterType = "http://www.simantics.org/DistrictNetwork-1.0/EdgeThicknessPropertyParameterType"; public static final String EdgeThicknessStyle = "http://www.simantics.org/DistrictNetwork-1.0/EdgeThicknessStyle"; + public static final String Edge_ArrowLengthProperty = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ArrowLengthProperty"; + public static final String Edge_ArrowLengthProperty_FlowRate = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ArrowLengthProperty/FlowRate"; + public static final String Edge_ArrowLengthProperty_bias = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ArrowLengthProperty/bias"; + public static final String Edge_ArrowLengthProperty_bias_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ArrowLengthProperty/bias/Inverse"; + public static final String Edge_ArrowLengthProperty_gain = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ArrowLengthProperty/gain"; + public static final String Edge_ArrowLengthProperty_gain_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ArrowLengthProperty/gain/Inverse"; + public static final String Edge_ArrowLengthProperty_value = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ArrowLengthProperty/value"; + public static final String Edge_ArrowLengthProperty_value_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ArrowLengthProperty/value/Inverse"; public static final String Edge_HasDiameter = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter"; public static final String Edge_HasDiameter_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter/Inverse"; public static final String Edge_HasElevation = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasElevation"; @@ -361,6 +397,7 @@ public class DistrictNetworkResource { public static final String Edge_HasTGround_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasTGround/Inverse"; public static final String Edge_ThicknessProperty = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ThicknessProperty"; public static final String Edge_ThicknessProperty_Diameter = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ThicknessProperty/Diameter"; + public static final String Edge_ThicknessProperty_FlowRate = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ThicknessProperty/FlowRate"; public static final String Edge_ThicknessProperty_OnlyGainAndBias = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ThicknessProperty/OnlyGainAndBias"; public static final String Edge_ThicknessProperty_bias = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ThicknessProperty/bias"; public static final String Edge_ThicknessProperty_bias_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ThicknessProperty/bias/Inverse"; @@ -371,6 +408,8 @@ public class DistrictNetworkResource { public static final String Element = "http://www.simantics.org/DistrictNetwork-1.0/Element"; public static final String ElementColoringStyle = "http://www.simantics.org/DistrictNetwork-1.0/ElementColoringStyle"; public static final String Functions = "http://www.simantics.org/DistrictNetwork-1.0/Functions"; + public static final String Functions_arrowLengthPropertyEnumerationValues = "http://www.simantics.org/DistrictNetwork-1.0/Functions/arrowLengthPropertyEnumerationValues"; + public static final String Functions_arrowLengthPropertyModifier = "http://www.simantics.org/DistrictNetwork-1.0/Functions/arrowLengthPropertyModifier"; public static final String Functions_brightnessValidator = "http://www.simantics.org/DistrictNetwork-1.0/Functions/brightnessValidator"; public static final String Functions_compositeInstantiator = "http://www.simantics.org/DistrictNetwork-1.0/Functions/compositeInstantiator"; public static final String Functions_constantOne = "http://www.simantics.org/DistrictNetwork-1.0/Functions/constantOne"; @@ -382,6 +421,7 @@ public class DistrictNetworkResource { public static final String Functions_enumerationValues = "http://www.simantics.org/DistrictNetwork-1.0/Functions/enumerationValues"; public static final String Functions_hasDiameterValue = "http://www.simantics.org/DistrictNetwork-1.0/Functions/hasDiameterValue"; public static final String Functions_hasElevation = "http://www.simantics.org/DistrictNetwork-1.0/Functions/hasElevation"; + public static final String Functions_hasNominalMassFlowValue = "http://www.simantics.org/DistrictNetwork-1.0/Functions/hasNominalMassFlowValue"; public static final String Functions_hasNominalSupplyPressure = "http://www.simantics.org/DistrictNetwork-1.0/Functions/hasNominalSupplyPressure"; public static final String Functions_hueValidator = "http://www.simantics.org/DistrictNetwork-1.0/Functions/hueValidator"; public static final String Functions_mappingModifier = "http://www.simantics.org/DistrictNetwork-1.0/Functions/mappingModifier"; @@ -583,6 +623,8 @@ public class DistrictNetworkResource { Actions = getResourceOrNull(graph, URIs.Actions); Actions_NewDNDiagram = getResourceOrNull(graph, URIs.Actions_NewDNDiagram); AddLayerToDNDiagramTemplate = getResourceOrNull(graph, URIs.AddLayerToDNDiagramTemplate); + ArrowLengthPropertyParameterType = getResourceOrNull(graph, URIs.ArrowLengthPropertyParameterType); + ArrowLengthStyle = getResourceOrNull(graph, URIs.ArrowLengthStyle); BrowseContext = getResourceOrNull(graph, URIs.BrowseContext); Composite = getResourceOrNull(graph, URIs.Composite); Connection = getResourceOrNull(graph, URIs.Connection); @@ -590,6 +632,12 @@ public class DistrictNetworkResource { Diagram = getResourceOrNull(graph, URIs.Diagram); Diagram_MappedDiagram = getResourceOrNull(graph, URIs.Diagram_MappedDiagram); Diagram_MappedFromDiagram = getResourceOrNull(graph, URIs.Diagram_MappedFromDiagram); + Diagram_arrowLengthBias = getResourceOrNull(graph, URIs.Diagram_arrowLengthBias); + Diagram_arrowLengthBias_Inverse = getResourceOrNull(graph, URIs.Diagram_arrowLengthBias_Inverse); + Diagram_arrowLengthGain = getResourceOrNull(graph, URIs.Diagram_arrowLengthGain); + Diagram_arrowLengthGain_Inverse = getResourceOrNull(graph, URIs.Diagram_arrowLengthGain_Inverse); + Diagram_arrowLengthProperty = getResourceOrNull(graph, URIs.Diagram_arrowLengthProperty); + Diagram_arrowLengthProperty_Inverse = getResourceOrNull(graph, URIs.Diagram_arrowLengthProperty_Inverse); Diagram_backgroundColor = getResourceOrNull(graph, URIs.Diagram_backgroundColor); Diagram_backgroundColor_Inverse = getResourceOrNull(graph, URIs.Diagram_backgroundColor_Inverse); Diagram_drawMapEnabled = getResourceOrNull(graph, URIs.Diagram_drawMapEnabled); @@ -628,6 +676,14 @@ public class DistrictNetworkResource { EdgeMappingParameterType = getResourceOrNull(graph, URIs.EdgeMappingParameterType); EdgeThicknessPropertyParameterType = getResourceOrNull(graph, URIs.EdgeThicknessPropertyParameterType); EdgeThicknessStyle = getResourceOrNull(graph, URIs.EdgeThicknessStyle); + Edge_ArrowLengthProperty = getResourceOrNull(graph, URIs.Edge_ArrowLengthProperty); + Edge_ArrowLengthProperty_FlowRate = getResourceOrNull(graph, URIs.Edge_ArrowLengthProperty_FlowRate); + Edge_ArrowLengthProperty_bias = getResourceOrNull(graph, URIs.Edge_ArrowLengthProperty_bias); + Edge_ArrowLengthProperty_bias_Inverse = getResourceOrNull(graph, URIs.Edge_ArrowLengthProperty_bias_Inverse); + Edge_ArrowLengthProperty_gain = getResourceOrNull(graph, URIs.Edge_ArrowLengthProperty_gain); + Edge_ArrowLengthProperty_gain_Inverse = getResourceOrNull(graph, URIs.Edge_ArrowLengthProperty_gain_Inverse); + Edge_ArrowLengthProperty_value = getResourceOrNull(graph, URIs.Edge_ArrowLengthProperty_value); + Edge_ArrowLengthProperty_value_Inverse = getResourceOrNull(graph, URIs.Edge_ArrowLengthProperty_value_Inverse); Edge_HasDiameter = getResourceOrNull(graph, URIs.Edge_HasDiameter); Edge_HasDiameter_Inverse = getResourceOrNull(graph, URIs.Edge_HasDiameter_Inverse); Edge_HasElevation = getResourceOrNull(graph, URIs.Edge_HasElevation); @@ -650,6 +706,7 @@ public class DistrictNetworkResource { Edge_HasTGround_Inverse = getResourceOrNull(graph, URIs.Edge_HasTGround_Inverse); Edge_ThicknessProperty = getResourceOrNull(graph, URIs.Edge_ThicknessProperty); Edge_ThicknessProperty_Diameter = getResourceOrNull(graph, URIs.Edge_ThicknessProperty_Diameter); + Edge_ThicknessProperty_FlowRate = getResourceOrNull(graph, URIs.Edge_ThicknessProperty_FlowRate); Edge_ThicknessProperty_OnlyGainAndBias = getResourceOrNull(graph, URIs.Edge_ThicknessProperty_OnlyGainAndBias); Edge_ThicknessProperty_bias = getResourceOrNull(graph, URIs.Edge_ThicknessProperty_bias); Edge_ThicknessProperty_bias_Inverse = getResourceOrNull(graph, URIs.Edge_ThicknessProperty_bias_Inverse); @@ -660,6 +717,8 @@ public class DistrictNetworkResource { Element = getResourceOrNull(graph, URIs.Element); ElementColoringStyle = getResourceOrNull(graph, URIs.ElementColoringStyle); Functions = getResourceOrNull(graph, URIs.Functions); + Functions_arrowLengthPropertyEnumerationValues = getResourceOrNull(graph, URIs.Functions_arrowLengthPropertyEnumerationValues); + Functions_arrowLengthPropertyModifier = getResourceOrNull(graph, URIs.Functions_arrowLengthPropertyModifier); Functions_brightnessValidator = getResourceOrNull(graph, URIs.Functions_brightnessValidator); Functions_compositeInstantiator = getResourceOrNull(graph, URIs.Functions_compositeInstantiator); Functions_constantOne = getResourceOrNull(graph, URIs.Functions_constantOne); @@ -671,6 +730,7 @@ public class DistrictNetworkResource { Functions_enumerationValues = getResourceOrNull(graph, URIs.Functions_enumerationValues); Functions_hasDiameterValue = getResourceOrNull(graph, URIs.Functions_hasDiameterValue); Functions_hasElevation = getResourceOrNull(graph, URIs.Functions_hasElevation); + Functions_hasNominalMassFlowValue = getResourceOrNull(graph, URIs.Functions_hasNominalMassFlowValue); Functions_hasNominalSupplyPressure = getResourceOrNull(graph, URIs.Functions_hasNominalSupplyPressure); Functions_hueValidator = getResourceOrNull(graph, URIs.Functions_hueValidator); Functions_mappingModifier = getResourceOrNull(graph, URIs.Functions_mappingModifier); diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java index 627561a1..60dd3e22 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java @@ -483,7 +483,13 @@ public class Functions { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); return listInstanceNames(graph, context, DN.Edge_ThicknessProperty); } - + + @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 nodeScalePropertyEnumerationValues(ReadGraph graph, Resource resource, Variable context) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); @@ -497,6 +503,13 @@ public class Functions { return baseMappingModifier(graph, diagram, DN.Diagram_edgeThicknessProperty, DN.Edge_ThicknessProperty, context); } + @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 Object nodeScalePropertyModifier(ReadGraph graph, Resource resource, Variable context) throws DatabaseException { Resource diagram = resolveElement(graph, context); diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java index a4f348eb..21f3d741 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java @@ -5,6 +5,7 @@ import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; +import java.awt.geom.Line2D; import java.awt.geom.Path2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; @@ -44,11 +45,18 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection private static final double height = 0.5; private static final Rectangle2D NORMAL = new Rectangle2D.Double(left, top, width, height); - + private transient Point2D centerPoint; private transient Rectangle2D symbolRect; private transient AffineTransform symbolTransform; - + + private Double arrowLength; + + private static double startX; + private static double startY; + private static double endX; + private static double endY; + @Override public void init() { } @@ -90,6 +98,37 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection g2d.setStroke(bs); g2d.draw(path); + // Draw arrow + if (arrowLength != null) { + g2d.setColor(Color.BLACK); + g2d.setStroke(new BasicStroke(bs.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + + double l = arrowLength; + double w = 2 * (double) bs.getLineWidth() * Math.signum(l); + if (Math.abs(w) > Math.abs(l)) w = l; + double offset = 2 * (double) bs.getLineWidth(); + + double centerX = (startX + endX) / 2, centerY = (startY + endY) / 2; + double deltaX = endX - startX, deltaY = endY - startY; + double length = Math.sqrt(deltaX * deltaX + deltaY * deltaY); + deltaX /= length; + deltaY /= length; + + double x0 = centerX - l/2 * deltaX + offset * deltaY; + double y0 = centerY - l/2 * deltaY - offset * deltaX; + double x1 = centerX + (l/2 - w) * deltaX + offset * deltaY; + double y1 = centerY + (l/2 - w) * deltaY - offset * deltaX; + + g2d.draw(new Line2D.Double(x0, y0, x1, y1)); + + Path2D path = new Path2D.Double(); + path.moveTo(x1 + w * deltaX, y1 + w * deltaY); + path.lineTo(x1 + w * deltaY, y1 - w * deltaX); + path.lineTo(x1 - w * deltaY, y1 + w * deltaX); + path.closePath(); + g2d.fill(path); + } + // Reset g2d.setStroke(oldStroke); g2d.setColor(oldColor); @@ -141,11 +180,10 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection // } public static Path2D calculatePath(DistrictNetworkEdge edge, Path2D result, boolean detailed) { - // Convert to screen coordinates - double startX = ModelledCRS.longitudeToX(edge.getStartPoint().getX()); - double startY = ModelledCRS.latitudeToY(-edge.getStartPoint().getY()); // Invert for Simantics - double endX = ModelledCRS.longitudeToX(edge.getEndPoint().getX()); - double endY = ModelledCRS.latitudeToY(-edge.getEndPoint().getY());// Invert for Simantics + startX = ModelledCRS.longitudeToX(edge.getStartPoint().getX()); + startY = ModelledCRS.latitudeToY(-edge.getStartPoint().getY()); + endX = ModelledCRS.longitudeToX(edge.getEndPoint().getX()); + endY = ModelledCRS.latitudeToY(-edge.getEndPoint().getY()); if (result == null) { result = new Path2D.Double(); @@ -211,6 +249,11 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection public void setDynamicColor(Color color) { this.dynamicColor = color; } + + @PropertySetter(value = "arrowLength") + public void setArroLength(Double length) { + arrowLength = length; + } @PropertySetter(value = "SVG") public void setSVG(String value) { diff --git a/org.simantics.district.network/adapters.xml b/org.simantics.district.network/adapters.xml index 8cec4400..fddb3b74 100644 --- a/org.simantics.district.network/adapters.xml +++ b/org.simantics.district.network/adapters.xml @@ -18,6 +18,9 @@ + + diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/ArrowLengthStyle.java b/org.simantics.district.network/src/org/simantics/district/network/profile/ArrowLengthStyle.java new file mode 100644 index 00000000..3b0524d4 --- /dev/null +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/ArrowLengthStyle.java @@ -0,0 +1,64 @@ +package org.simantics.district.network.profile; + +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; +import org.simantics.db.exception.DatabaseException; +import org.simantics.scenegraph.INode; +import org.simantics.scenegraph.g2d.G2DSceneGraph; +import org.simantics.scenegraph.g2d.nodes.ConnectionNode; +import org.simantics.scenegraph.profile.EvaluationContext; +import org.simantics.scenegraph.profile.common.ProfileVariables; + +public class ArrowLengthStyle extends ThrottledStyleBase { + + private static final Double PENDING = Double.NaN; + private static final Double ONE = 1.0; + + @Override + public Double calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException { + DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance()); + // Prevent PendingVariableExceptions from coming through + boolean wasSynchronous = graph.setSynchronous(true); + try { + Double length = ONE; + if (ds.arrowLengthProperty.isPresent()) { + length = Simantics.applySCLRead(graph, ds.arrowLengthProperty.get(), groupItem); + // System.out.println("read thickness: " + thickness + " : " + ds.arrowLengthProperty); + if (length == null) { + length = ONE; + } else { + length = length * ds.arrowLengthGain + ds.arrowLengthBias; + } + } + + return length; + } + finally { + graph.setSynchronous(wasSynchronous); + } + } + + @Override + public void applyThrottledStyleForNode(EvaluationContext observer, INode node, Double value) { +// System.out.println("apply: " + node + " : " + value); + ConnectionNode n = (ConnectionNode) node; + if (value == PENDING) { + ((G2DSceneGraph)node.getRootNode()).setPending(node); + } else { + ((G2DSceneGraph)node.getRootNode()).clearPending(node); + } + for (INode nn : n.getNodes()) + ProfileVariables.claimNodeProperty(nn, "arrowLength", value, observer); + } + + @Override + protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) { + ((G2DSceneGraph)node.getRootNode()).clearPending(node); + ConnectionNode n = (ConnectionNode) node; + for (INode nn : n.getNodes()) + ProfileVariables.claimNodeProperty(nn, "arrowLength", null, evaluationContext); + } + +} diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettings.java b/org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettings.java index 13c38bed..a0dcd40f 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettings.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettings.java @@ -16,6 +16,9 @@ public class DiagramSettings { public final Optional> edgeThicknessProperty; public final double edgeThicknessGain; public final double edgeThicknessBias; + public final Optional> arrowLengthProperty; + public final double arrowLengthGain; + public final double arrowLengthBias; public final Optional> elementColoringFunction; public final float elementColoringGradientHue; public final float elementColoringGradientSaturation; @@ -24,6 +27,7 @@ public class DiagramSettings { public DiagramSettings( Function1 vertexScaleProperty, double vertexScaleGain, double vertexScaleBias, Function1 edgeThicknessProperty, double edgeThicknessGain, double edgeThicknessBias, + Function1 arrowLengthProperty, double arrowLengthGain, double arrowLengthBias, Function1 elementColoringFunction, float elementColoringGradientHue, float elementColoringGradientSaturation @@ -34,6 +38,9 @@ public class DiagramSettings { this.edgeThicknessProperty = Optional.ofNullable(edgeThicknessProperty); this.edgeThicknessGain = edgeThicknessGain; this.edgeThicknessBias = edgeThicknessBias; + this.arrowLengthProperty = Optional.ofNullable(arrowLengthProperty); + this.arrowLengthGain = arrowLengthGain; + this.arrowLengthBias = arrowLengthBias; this.elementColoringFunction = Optional.ofNullable(elementColoringFunction); this.elementColoringGradientHue = elementColoringGradientHue; this.elementColoringGradientSaturation = elementColoringGradientSaturation; @@ -49,11 +56,16 @@ public class DiagramSettings { final int prime = 31; int result = 1; result = prime * result + edgeThicknessProperty.hashCode(); + result = prime * result + arrowLengthProperty.hashCode(); long temp; temp = Double.doubleToLongBits(edgeThicknessGain); result = prime * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(edgeThicknessBias); result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(arrowLengthGain); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(arrowLengthBias); + result = prime * result + (int) (temp ^ (temp >>> 32)); result = prime * result + vertexScaleProperty.hashCode(); temp = Double.doubleToLongBits(vertexScaleGain); result = prime * result + (int) (temp ^ (temp >>> 32)); @@ -80,6 +92,12 @@ public class DiagramSettings { return false; if (Double.doubleToLongBits(edgeThicknessBias) != Double.doubleToLongBits(other.edgeThicknessBias)) return false; + if (!arrowLengthProperty.equals(other.arrowLengthProperty)) + return false; + if (Double.doubleToLongBits(arrowLengthGain) != Double.doubleToLongBits(other.arrowLengthGain)) + return false; + if (Double.doubleToLongBits(arrowLengthBias) != Double.doubleToLongBits(other.arrowLengthBias)) + return false; if (!vertexScaleProperty.equals(other.vertexScaleProperty)) return false; if (Double.doubleToLongBits(vertexScaleGain) != Double.doubleToLongBits(other.vertexScaleGain)) @@ -97,9 +115,10 @@ public class DiagramSettings { @Override public String toString() { - return String.format("DiagramSettings[%s * %f + %f - %s * %f + %f - coloringFunction: %s, hue: %f, saturation: %f]", + return String.format("DiagramSettings[%s * %f + %f - %s * %f + %f - %s * %f + %f - coloringFunction: %s, hue: %f, saturation: %f]", vertexScaleProperty.toString(), vertexScaleGain, vertexScaleBias, edgeThicknessProperty, edgeThicknessGain, edgeThicknessBias, + arrowLengthProperty, arrowLengthGain, arrowLengthBias, elementColoringFunction.toString(), elementColoringGradientHue, elementColoringGradientSaturation ); diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettingsRequest.java b/org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettingsRequest.java index a17464d8..2254b305 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettingsRequest.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettingsRequest.java @@ -30,9 +30,12 @@ public class DiagramSettingsRequest extends ResourceRead { float elementColoringGradientHue = 0; float elementColoringGradientSaturation = 1; Function1 edgeThicknessProperty = null; + Function1 arrowLengthProperty = null; Function1 nodeScaleProperty = null; double edgeThicknessGain = 1; double edgeThicknessBias = 0; + double arrowLengthGain = 1; + double arrowLengthBias = 0; double nodeScaleGain = 1; double nodeScaleBias = 0; @@ -68,6 +71,22 @@ public class DiagramSettingsRequest extends ResourceRead { safeDoubleProperty(graph, etp, DN.Edge_ThicknessProperty_bias, 0) + safeDoubleProperty(graph, diagram, DN.Diagram_edgeThicknessBias, 0); } + Resource alp = graph.getPossibleObject(diagram, DN.Diagram_arrowLengthProperty); + //System.out.println("alp: " + NameUtils.getURIOrSafeNameInternal(graph, alp)); + if (alp != null) { + Variable alpv = Variables.getPossibleVariable(graph, alp); + if (alpv != null) { + //System.out.println("alpv: " + alpv.getURI(graph)); + arrowLengthProperty = alpv.getPropertyValue(graph, DN.Edge_ArrowLengthProperty_value); + } + + arrowLengthGain = + safeDoubleProperty(graph, alp, DN.Edge_ArrowLengthProperty_gain, 1) + * safeDoubleProperty(graph, diagram, DN.Diagram_arrowLengthGain, 1); + arrowLengthBias = + safeDoubleProperty(graph, alp, DN.Edge_ArrowLengthProperty_bias, 0) + + safeDoubleProperty(graph, diagram, DN.Diagram_arrowLengthBias, 0); + } Resource nsp = graph.getPossibleObject(diagram, DN.Diagram_nodeScaleProperty); if (nsp != null) { Variable nspv = Variables.getPossibleVariable(graph, nsp); @@ -88,6 +107,7 @@ public class DiagramSettingsRequest extends ResourceRead { DiagramSettings ds = new DiagramSettings( nodeScaleProperty, nodeScaleGain, nodeScaleBias, edgeThicknessProperty, edgeThicknessGain, edgeThicknessBias, + arrowLengthProperty, arrowLengthGain, arrowLengthBias, elementColoringFunction, elementColoringGradientHue, elementColoringGradientSaturation); -- 2.45.2