Пример #1
0
  /** update values for ticks and labels */
  public void updateDecorations() {

    // update decorations
    GeoAxis3D axis = (GeoAxis3D) getGeoElement();

    // gets the direction vector of the axis as it is drawn on screen
    /*
    Coords v = axis.getCoordSys().getVx().copyVector();
    getView3D().toScreenCoords3D(v);
    */
    Coords v = getView3D().getToScreenMatrix().mul(axis.getCoordSys().getVx());
    v.set(3, 0); // set z-coord to 0
    // double vScale = v.norm(); //axis scale, used for ticks distance
    double vScale = getView3D().getScale(); // TODO use different scales for x/y/z
    // Application.debug("vScale="+vScale);

    // calc orthogonal offsets
    int vx = (int) (v.get(1) * 1.5 * axis.getTickSize() / vScale);
    int vy = (int) (v.get(2) * 1.5 * axis.getTickSize() / vScale);
    int xOffset = -vy;
    int yOffset = vx;

    if (yOffset > 0) {
      xOffset = -xOffset;
      yOffset = -yOffset;
    }

    // interval between two ticks
    // Application.debug("vscale : "+vScale);
    double maxPix = 100; // only one tick is allowed per maxPix pixels
    double units = maxPix / vScale;

    NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
    // TODO see EuclidianView::setAxesIntervals	and Kernel::axisNumberDistance
    double distance = getView3D().getKernel().axisNumberDistance(units, numberFormat);

    axis.updateDecorations(
        distance, numberFormat, xOffset, yOffset, -vx - 2 * xOffset, -vy - 2 * yOffset);
  }
Пример #2
0
  protected void updateLabel() {

    // draw numbers
    GeoAxis3D axis = (GeoAxis3D) getGeoElement();

    NumberFormat numberFormat = axis.getNumberFormat();
    double distance = axis.getNumbersDistance();

    // Application.debug("drawMinMax="+getDrawMin()+","+getDrawMax());
    double[] minmax = getDrawMinMax();

    int iMin = (int) (minmax[0] / distance);
    int iMax = (int) (minmax[1] / distance);
    int nb = iMax - iMin + 1;

    // Application.debug("iMinMax="+iMin+","+iMax);

    if (nb < 1) {
      Application.debug("nb=" + nb);
      // labels = null;
      return;
    }

    // sets all already existing labels not visible
    for (DrawLabel3D label : labels.values()) label.setIsVisible(false);

    for (int i = iMin; i <= iMax; i++) {
      double val = i * distance;
      Coords origin = ((GeoCoordSys1D) getGeoElement()).getPoint(val);

      // draw numbers
      String strNum = getView3D().getKernel().formatPiE(val, numberFormat);

      // check if the label already exists
      DrawLabel3D label = labels.get(strNum);
      if (label != null) {
        // sets the label visible
        label.setIsVisible(true);
        label.update(
            strNum,
            10,
            getGeoElement().getObjectColor(),
            origin.copyVector(),
            axis.getNumbersXOffset(),
            axis.getNumbersYOffset());
        // TODO optimize this
      } else {
        // creates new label
        label = new DrawLabel3D(getView3D());
        label.setAnchor(true);
        label.update(
            strNum,
            10,
            getGeoElement().getObjectColor(),
            origin.copyVector(),
            axis.getNumbersXOffset(),
            axis.getNumbersYOffset());
        labels.put(strNum, label);
      }
    }

    // update end of axis label
    label.update(
        ((GeoAxis3D) getGeoElement()).getAxisLabel(),
        10,
        getGeoElement().getObjectColor(),
        ((GeoCoordSys1D) getGeoElement()).getPoint(minmax[1]),
        axis.labelOffsetX - 4,
        axis.labelOffsetY - 6);
  }