]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettings.java
First prototype of HSV color space based dynamic DN element coloring
[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>> elementColoringFunction;
20         public final float elementColoringGradientHue;
21         public final float elementColoringGradientSaturation;
22         public final transient ColorGradient coloringGradient;
23
24         public DiagramSettings(
25                         Function1<Resource, Double> vertexScaleProperty, double vertexScaleGain, double vertexScaleBias,
26                         Function1<Resource, Double> edgeThicknessProperty, double edgeThicknessGain, double edgeThicknessBias,
27                         Function1<Resource, Double> elementColoringFunction,
28                         float elementColoringGradientHue,
29                         float elementColoringGradientSaturation
30                         ) {
31                 this.vertexScaleProperty = Optional.ofNullable(vertexScaleProperty);
32                 this.vertexScaleGain = vertexScaleGain;
33                 this.vertexScaleBias = vertexScaleBias;
34                 this.edgeThicknessProperty = Optional.ofNullable(edgeThicknessProperty);
35                 this.edgeThicknessGain = edgeThicknessGain;
36                 this.edgeThicknessBias = edgeThicknessBias;
37                 this.elementColoringFunction = Optional.ofNullable(elementColoringFunction);
38                 this.elementColoringGradientHue = elementColoringGradientHue;
39                 this.elementColoringGradientSaturation = elementColoringGradientSaturation;
40                 this.coloringGradient = Colors.cached(
41                                 Colors.hsvGradient(
42                                                 elementColoringGradientHue,
43                                                 elementColoringGradientSaturation)
44                                 );
45         }
46
47         @Override
48         public int hashCode() {
49                 final int prime = 31;
50                 int result = 1;
51                 result = prime * result + edgeThicknessProperty.hashCode();
52                 long temp;
53                 temp = Double.doubleToLongBits(edgeThicknessGain);
54                 result = prime * result + (int) (temp ^ (temp >>> 32));
55                 temp = Double.doubleToLongBits(edgeThicknessBias);
56                 result = prime * result + (int) (temp ^ (temp >>> 32));
57                 result = prime * result + vertexScaleProperty.hashCode();
58                 temp = Double.doubleToLongBits(vertexScaleGain);
59                 result = prime * result + (int) (temp ^ (temp >>> 32));
60                 temp = Double.doubleToLongBits(vertexScaleBias);
61                 result = prime * result + (int) (temp ^ (temp >>> 32));
62                 result = prime * result + elementColoringFunction.hashCode();
63                 result = prime * result + Float.floatToIntBits(elementColoringGradientHue);
64                 result = prime * result + Float.floatToIntBits(elementColoringGradientSaturation);
65                 return result;
66         }
67
68         @Override
69         public boolean equals(Object obj) {
70                 if (this == obj)
71                         return true;
72                 if (obj == null)
73                         return false;
74                 if (getClass() != obj.getClass())
75                         return false;
76                 DiagramSettings other = (DiagramSettings) obj;
77                 if (!edgeThicknessProperty.equals(other.edgeThicknessProperty))
78                         return false;
79                 if (Double.doubleToLongBits(edgeThicknessGain) != Double.doubleToLongBits(other.edgeThicknessGain))
80                         return false;
81                 if (Double.doubleToLongBits(edgeThicknessBias) != Double.doubleToLongBits(other.edgeThicknessBias))
82                         return false;
83                 if (!vertexScaleProperty.equals(other.vertexScaleProperty))
84                         return false;
85                 if (Double.doubleToLongBits(vertexScaleGain) != Double.doubleToLongBits(other.vertexScaleGain))
86                         return false;
87                 if (Double.doubleToLongBits(vertexScaleBias) != Double.doubleToLongBits(other.vertexScaleBias))
88                         return false;
89                 if (!elementColoringFunction.equals(other.elementColoringFunction))
90                         return false;
91                 if (Float.floatToIntBits(elementColoringGradientHue) != Float.floatToIntBits(other.elementColoringGradientHue))
92                         return false;
93                 if (Float.floatToIntBits(elementColoringGradientSaturation) != Float.floatToIntBits(other.elementColoringGradientSaturation))
94                         return false;
95                 return true;
96         }
97
98         @Override
99         public String toString() {
100                 return String.format("DiagramSettings[%s * %f + %f - %s * %f + %f - coloringFunction: %s, hue: %f, saturation: %f]",
101                                 vertexScaleProperty.toString(), vertexScaleGain, vertexScaleBias,
102                                 edgeThicknessProperty, edgeThicknessGain, edgeThicknessBias,
103                                 elementColoringFunction.toString(),
104                                 elementColoringGradientHue, elementColoringGradientSaturation
105                                 );
106         }
107
108 }