예제 #1
0
    /**
     * Constructor.
     *
     * @param drawingTools the {@link DrawingTools} of the canvas where the ruler will be drawn.
     * @param rulerModel the {@link RulerModel} of the drawn ruler.
     */
    public synchronized RulerDrawingResult drawWithResults(
        DrawingTools drawingTools, RulerModel rulerModel) {
      this.rulerModel = rulerModel;
      subTicksValue = new LinkedList<Double>();
      ticksValue = new LinkedList<Double>();
      spritesList = new LinkedList<PositionedSprite>();
      canvasProjection = drawingTools.getTransformationManager().getCanvasProjection();

      Vector3d windowTicksDirection =
          canvasProjection.projectDirection(rulerModel.getTicksDirection());
      windowTicksDirection = windowTicksDirection.setZ(0);

      Vector3d normalizedProjectedTicksDirection = windowTicksDirection.getNormalized();
      windowSubTicksDelta = normalizedProjectedTicksDirection.times(rulerModel.getSubTicksLength());
      windowTicksDelta = normalizedProjectedTicksDirection.times(rulerModel.getTicksLength());

      DecimalFormat format;
      if (rulerModel.isAutoTicks()) {
        format = computeAutoGraduation();
      } else {
        format = computeUserGraduation();
      }
      computeTicksData();

      draw(drawingTools);

      double distRatio = computeTicksDistanceRatio(windowTicksDirection.getNorm());

      return new RulerDrawingResult(
          format, ticksValue, subTicksValue, density, distRatio, normalizedProjectedTicksDirection);
    }
예제 #2
0
    /**
     * Compute different parameters on a ruler
     *
     * @param drawingTools the {@link DrawingTools} of the canvas where the ruler will be drawn.
     * @param rulerModel the {@link RulerModel} of the drawn ruler.
     * @param canvasProjection the canvas projection.
     */
    public synchronized RulerDrawingResult computeRuler(
        DrawingTools drawingTools, RulerModel rulerModel, Transformation canvasProjection) {
      // Same code as drawWithResults (without drawing)
      // Historically, computations were made when drawing and they are made before drawing.
      // TODO: remove drawWithResults ??
      this.canvasProjection = canvasProjection;
      this.rulerModel = rulerModel;
      subTicksValue = new LinkedList<Double>();
      ticksValue = new LinkedList<Double>();
      spritesList = new LinkedList<PositionedSprite>();

      Vector3d windowTicksDirection =
          canvasProjection.projectDirection(rulerModel.getTicksDirection());
      windowTicksDirection = windowTicksDirection.setZ(0);

      Vector3d normalizedProjectedTicksDirection = windowTicksDirection.getNormalized();
      windowSubTicksDelta = normalizedProjectedTicksDirection.times(rulerModel.getSubTicksLength());
      windowTicksDelta = normalizedProjectedTicksDirection.times(rulerModel.getTicksLength());

      DecimalFormat format;
      if (rulerModel.isAutoTicks()) {
        format = computeAutoGraduation();
      } else {
        format = computeUserGraduation();
      }
      computeTicksData();

      double distRatio = computeTicksDistanceRatio(windowTicksDirection.getNorm());

      return new RulerDrawingResult(
          format, ticksValue, subTicksValue, density, distRatio, normalizedProjectedTicksDirection);
    }