]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettings.java
Arrow length indicators for flow magnitude
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / profile / DiagramSettings.java
1 package org.simantics.district.network.profile;
2
3 import java.util.Optional;
4
5 import org.simantics.db.Resource;
6 import org.simantics.scl.runtime.function.Function1;
7
8 /**
9  * @author Tuukka Lehtonen
10  */
11 public class DiagramSettings {
12
13         public final Optional<Function1<Resource, Double>> vertexScaleProperty;
14         public final double vertexScaleGain;
15         public final double vertexScaleBias;
16         public final Optional<Function1<Resource, Double>> edgeThicknessProperty;
17         public final double edgeThicknessGain;
18         public final double edgeThicknessBias;
19         public final Optional<Function1<Resource, Double>> arrowLengthProperty;
20         public final double arrowLengthGain;
21         public final double arrowLengthBias;
22         public final Optional<Function1<Resource, Double>> elementColoringFunction;
23         public final float elementColoringGradientHue;
24         public final float elementColoringGradientSaturation;
25         public final transient ColorGradient coloringGradient;
26
27         public DiagramSettings(
28                         Function1<Resource, Double> vertexScaleProperty, double vertexScaleGain, double vertexScaleBias,
29                         Function1<Resource, Double> edgeThicknessProperty, double edgeThicknessGain, double edgeThicknessBias,
30                         Function1<Resource, Double> arrowLengthProperty, double arrowLengthGain, double arrowLengthBias,
31                         Function1<Resource, Double> elementColoringFunction,
32                         float elementColoringGradientHue,
33                         float elementColoringGradientSaturation
34                         ) {
35                 this.vertexScaleProperty = Optional.ofNullable(vertexScaleProperty);
36                 this.vertexScaleGain = vertexScaleGain;
37                 this.vertexScaleBias = vertexScaleBias;
38                 this.edgeThicknessProperty = Optional.ofNullable(edgeThicknessProperty);
39                 this.edgeThicknessGain = edgeThicknessGain;
40                 this.edgeThicknessBias = edgeThicknessBias;
41                 this.arrowLengthProperty = Optional.ofNullable(arrowLengthProperty);
42                 this.arrowLengthGain = arrowLengthGain;
43                 this.arrowLengthBias = arrowLengthBias;
44                 this.elementColoringFunction = Optional.ofNullable(elementColoringFunction);
45                 this.elementColoringGradientHue = elementColoringGradientHue;
46                 this.elementColoringGradientSaturation = elementColoringGradientSaturation;
47                 this.coloringGradient = Colors.cached(
48                                 Colors.hsvGradient(
49                                                 elementColoringGradientHue,
50                                                 elementColoringGradientSaturation)
51                                 );
52         }
53
54         @Override
55         public int hashCode() {
56                 final int prime = 31;
57                 int result = 1;
58                 result = prime * result + edgeThicknessProperty.hashCode();
59                 result = prime * result + arrowLengthProperty.hashCode();
60                 long temp;
61                 temp = Double.doubleToLongBits(edgeThicknessGain);
62                 result = prime * result + (int) (temp ^ (temp >>> 32));
63                 temp = Double.doubleToLongBits(edgeThicknessBias);
64                 result = prime * result + (int) (temp ^ (temp >>> 32));
65                 temp = Double.doubleToLongBits(arrowLengthGain);
66                 result = prime * result + (int) (temp ^ (temp >>> 32));
67                 temp = Double.doubleToLongBits(arrowLengthBias);
68                 result = prime * result + (int) (temp ^ (temp >>> 32));
69                 result = prime * result + vertexScaleProperty.hashCode();
70                 temp = Double.doubleToLongBits(vertexScaleGain);
71                 result = prime * result + (int) (temp ^ (temp >>> 32));
72                 temp = Double.doubleToLongBits(vertexScaleBias);
73                 result = prime * result + (int) (temp ^ (temp >>> 32));
74                 result = prime * result + elementColoringFunction.hashCode();
75                 result = prime * result + Float.floatToIntBits(elementColoringGradientHue);
76                 result = prime * result + Float.floatToIntBits(elementColoringGradientSaturation);
77                 return result;
78         }
79
80         @Override
81         public boolean equals(Object obj) {
82                 if (this == obj)
83                         return true;
84                 if (obj == null)
85                         return false;
86                 if (getClass() != obj.getClass())
87                         return false;
88                 DiagramSettings other = (DiagramSettings) obj;
89                 if (!edgeThicknessProperty.equals(other.edgeThicknessProperty))
90                         return false;
91                 if (Double.doubleToLongBits(edgeThicknessGain) != Double.doubleToLongBits(other.edgeThicknessGain))
92                         return false;
93                 if (Double.doubleToLongBits(edgeThicknessBias) != Double.doubleToLongBits(other.edgeThicknessBias))
94                         return false;
95                 if (!arrowLengthProperty.equals(other.arrowLengthProperty))
96                         return false;
97                 if (Double.doubleToLongBits(arrowLengthGain) != Double.doubleToLongBits(other.arrowLengthGain))
98                         return false;
99                 if (Double.doubleToLongBits(arrowLengthBias) != Double.doubleToLongBits(other.arrowLengthBias))
100                         return false;
101                 if (!vertexScaleProperty.equals(other.vertexScaleProperty))
102                         return false;
103                 if (Double.doubleToLongBits(vertexScaleGain) != Double.doubleToLongBits(other.vertexScaleGain))
104                         return false;
105                 if (Double.doubleToLongBits(vertexScaleBias) != Double.doubleToLongBits(other.vertexScaleBias))
106                         return false;
107                 if (!elementColoringFunction.equals(other.elementColoringFunction))
108                         return false;
109                 if (Float.floatToIntBits(elementColoringGradientHue) != Float.floatToIntBits(other.elementColoringGradientHue))
110                         return false;
111                 if (Float.floatToIntBits(elementColoringGradientSaturation) != Float.floatToIntBits(other.elementColoringGradientSaturation))
112                         return false;
113                 return true;
114         }
115
116         @Override
117         public String toString() {
118                 return String.format("DiagramSettings[%s * %f + %f - %s * %f + %f - %s * %f + %f - coloringFunction: %s, hue: %f, saturation: %f]",
119                                 vertexScaleProperty.toString(), vertexScaleGain, vertexScaleBias,
120                                 edgeThicknessProperty, edgeThicknessGain, edgeThicknessBias,
121                                 arrowLengthProperty, arrowLengthGain, arrowLengthBias,
122                                 elementColoringFunction.toString(),
123                                 elementColoringGradientHue, elementColoringGradientSaturation
124                                 );
125         }
126
127 }