예제 #1
0
    /**
     * Actually perform the ruler drawing.
     *
     * @param drawingTools {@link DrawingTools} used to perform the ruler drawing.
     */
    private synchronized void draw(DrawingTools drawingTools) {
      BuffersManager bufferManager = drawingTools.getCanvas().getBuffersManager();
      ElementsBuffer vertices = bufferManager.createElementsBuffer();
      fillVertices(vertices, rulerModel, ticksValue, subTicksValue, canvasProjection);
      DefaultGeometry geometry = new DefaultGeometry();
      geometry.setFillDrawingMode(Geometry.FillDrawingMode.NONE);
      geometry.setLineDrawingMode(Geometry.LineDrawingMode.SEGMENTS);
      geometry.setVertices(vertices);

      Appearance appearance = new Appearance();
      appearance.setLineColor(rulerModel.getColor());
      appearance.setLineWidth((float) rulerModel.getLineWidth());

      drawingTools.getTransformationManager().useWindowCoordinate();
      try {
        for (PositionedSprite positionedSprite : spritesList) {
          drawingTools.draw(
              positionedSprite.getSprite(),
              AnchorPosition.CENTER,
              positionedSprite.getWindowPosition());
        }
        drawingTools.draw(geometry, appearance);
      } catch (SciRendererException ignored) {
      }
      drawingTools.getTransformationManager().useSceneCoordinate();
      bufferManager.dispose(vertices);
    }
예제 #2
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);
    }