]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettings.java
First draft of vertex size adjusting district network diagram profiles
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / profile / DiagramSettings.java
index 8136b19c257a37f62d47b14e751178a94cb1730e..071489de1b0a8cf2f9b2cad1d16f86b0b791b412 100644 (file)
@@ -3,22 +3,27 @@ package org.simantics.district.network.profile;
 import java.util.Optional;
 
 import org.simantics.db.Resource;
+import org.simantics.scl.runtime.function.Function1;
 
 /**
  * @author Tuukka Lehtonen
  */
 public class DiagramSettings {
 
-       public final Optional<Resource> vertexScalingProperty;
-       public final double vertexScalingScale;
-       public final Optional<Resource> edgeThicknessProperty;
-       public final double edgeThicknessScale;
+       public final Optional<Function1<Resource, Double>> vertexScaleProperty;
+       public final double vertexScaleGain;
+       public final double vertexScaleBias;
+       public final Optional<Function1<Resource, Double>> edgeThicknessProperty;
+       public final double edgeThicknessGain;
+       public final double edgeThicknessBias;
 
-       public DiagramSettings(Resource vertexScalingProperty, double vertexScalingScale, Resource edgeThicknessProperty, double edgeThicknessScale) {
-               this.vertexScalingProperty = Optional.ofNullable(vertexScalingProperty);
-               this.vertexScalingScale = vertexScalingScale;
+       public DiagramSettings(Function1<Resource, Double> vertexScaleProperty, double vertexScaleGain, double vertexScaleBias, Function1<Resource, Double> edgeThicknessProperty, double edgeThicknessGain, double edgeThicknessBias) {
+               this.vertexScaleProperty = Optional.ofNullable(vertexScaleProperty);
+               this.vertexScaleGain = vertexScaleGain;
+               this.vertexScaleBias = vertexScaleBias;
                this.edgeThicknessProperty = Optional.ofNullable(edgeThicknessProperty);
-               this.edgeThicknessScale = edgeThicknessScale;
+               this.edgeThicknessGain = edgeThicknessGain;
+               this.edgeThicknessBias = edgeThicknessBias;
        }
 
        @Override
@@ -27,10 +32,14 @@ public class DiagramSettings {
                int result = 1;
                result = prime * result + edgeThicknessProperty.hashCode();
                long temp;
-               temp = Double.doubleToLongBits(edgeThicknessScale);
+               temp = Double.doubleToLongBits(edgeThicknessGain);
                result = prime * result + (int) (temp ^ (temp >>> 32));
-//             result = prime * result + vertexScalingProperty.hashCode();
-               temp = Double.doubleToLongBits(vertexScalingScale);
+               temp = Double.doubleToLongBits(edgeThicknessBias);
+               result = prime * result + (int) (temp ^ (temp >>> 32));
+               result = prime * result + vertexScaleProperty.hashCode();
+               temp = Double.doubleToLongBits(vertexScaleGain);
+               result = prime * result + (int) (temp ^ (temp >>> 32));
+               temp = Double.doubleToLongBits(vertexScaleBias);
                result = prime * result + (int) (temp ^ (temp >>> 32));
                return result;
        }
@@ -46,14 +55,23 @@ public class DiagramSettings {
                DiagramSettings other = (DiagramSettings) obj;
                if (!edgeThicknessProperty.equals(other.edgeThicknessProperty))
                        return false;
-               if (Double.doubleToLongBits(edgeThicknessScale) != Double.doubleToLongBits(other.edgeThicknessScale))
+               if (Double.doubleToLongBits(edgeThicknessGain) != Double.doubleToLongBits(other.edgeThicknessGain))
+                       return false;
+               if (Double.doubleToLongBits(edgeThicknessBias) != Double.doubleToLongBits(other.edgeThicknessBias))
+                       return false;
+               if (!vertexScaleProperty.equals(other.vertexScaleProperty))
                        return false;
-               if (!vertexScalingProperty.equals(other.vertexScalingProperty))
+               if (Double.doubleToLongBits(vertexScaleGain) != Double.doubleToLongBits(other.vertexScaleGain))
                        return false;
-               if (Double.doubleToLongBits(vertexScalingScale) != Double.doubleToLongBits(other.vertexScalingScale))
+               if (Double.doubleToLongBits(vertexScaleBias) != Double.doubleToLongBits(other.vertexScaleBias))
                        return false;
                return true;
        }
 
-       
+       @Override
+       public String toString() {
+               return String.format("DiagramSettings[%s * %f + %f - %s * %f + %f]", vertexScaleProperty.toString(),
+                               vertexScaleGain, vertexScaleBias, edgeThicknessProperty, edgeThicknessGain, edgeThicknessBias);
+       }
+
 }