Ejemplo n.º 1
0
  public void processPolygonSpline(boolean shiftDown) {
    mCurrPC.setBatchModeOn();
    if (!shiftDown) mCurrPC.unselectAll();

    // loop on spline pts to construct a Polygon
    Polygon srcArea = new Polygon();
    for (int s = 0; s < mSplinePoints.size(); s++) {
      Point p = (Point) mSplinePoints.elementAt(s);
      int x = p.x - mLeft - 5;
      int y = p.y - mTop - 5;

      srcArea.addPoint(x, y);
    }

    mSplinePoints.removeAllElements();

    // search for matches
    byte[] currFilterResults = fdm.getResults();
    double[] yArray1 = getYArray1();
    double[] xArray1 = getXArray1();
    double[] yArray2 = getYArray2();
    double[] xArray2 = getXArray2();
    Point p1 = new Point();
    Point p2 = new Point();

    for (int i = 0; i < mCurrPC.getSize(); i++) {
      if (!mIgnoreFilter
          && (mCurrPC.isDeleted(i) || currFilterResults[i] != 4 || !mCurrPC.isSelectedLayer(i)))
        continue;
      double yi = yArray1[i];
      double xi = xArray1[i];
      double xi2 = Float.NaN;
      double yi2 = Float.NaN;
      double xx2 = Float.NaN;
      double yy2 = Float.NaN;

      // correct the X value if necessary
      xi = correctX(xi);

      double xx1 = (xi - winXOrigin) * winXScale;
      double yy1 = (yi - winYOrigin) * winYScale;

      // correct the Y coordinate if necessary
      yy1 = correctY(yy1);

      if (!isYAxisScaler()) {
        yi2 = yArray2[i];
        yy2 = (yi2 - winYOrigin) * winYScale;
        ;
        yy2 = correctY(yy2);
      } else yy2 = yy1;

      if (!isXAxisScaler()) {
        xi2 = xArray2[i];
        xi2 = correctX(xi2);
        xx2 = (xi2 - winXOrigin) * winXScale;
      } else xx2 = xx1;

      p1.setLocation((int) xx1, (int) yy1);
      p2.setLocation((int) xx2, (int) yy2);

      if (srcArea.contains(p1) || srcArea.contains(p2)) {
        mCurrPC.select(i);
      }
    }
    mViewManager.invalidateAllViews();
    mCurrPC.setBatchModeOff();
  }
Ejemplo n.º 2
0
  public void rubberbandEnded(Rubberband rb, boolean shiftDown) {
    // get the limits and zoom the plot
    if (mCurrPC == null) return;
    Rectangle rbRect = rb.getBounds();
    if (rbRect.width == 0 || rbRect.height == 0) {
      // click selection
      if (toolMode == Constants.SELECT_MODE) {
        // find any matches at the mouseclick location
        int x = rbRect.x - mLeft - 5;
        int y = rbRect.y - mTop - 5;

        // construct a search region;
        int[] xpoints = {x - 1, x + 1, x + 1, x - 1, x - 1};
        int[] ypoints = {y - 1, y - 1, y + 1, y + 1, y - 1};
        Polygon sr = new Polygon(xpoints, ypoints, 5);

        if (!shiftDown) mCurrPC.unselectAll();

        mCurrPC.setBatchModeOn();

        byte[] currFilterResults = fdm.getResults();
        double[] yArray1 = getYArray1();
        double[] xArray1 = getXArray1();
        double[] yArray2 = getYArray2();
        double[] xArray2 = getXArray2();

        for (int i = 0; i < mCurrPC.getSize(); i++) {
          if (!mIgnoreFilter && (mCurrPC.isDeleted(i) || currFilterResults[i] != 4)
              || !mCurrPC.isSelectedLayer(i)) continue;

          // search for matches
          double yi = yArray1[i];
          double xi = xArray1[i];
          double xi2 = Float.NaN;
          double yi2 = Float.NaN;
          double x2 = Float.NaN;
          double y2 = Float.NaN;

          // correct the X value if necessary
          xi = correctX(xi);

          double x1 = (xi - winXOrigin) * winXScale;
          double y1 = (yi - winYOrigin) * winYScale;

          // correct the Y coordinate if necessary
          y1 = correctY(y1);

          if (!isYAxisScaler()) {
            yi2 = yArray2[i];
            y2 = (yi2 - winYOrigin) * winYScale;
            y2 = correctY(y2);
          } else y2 = y1;

          if (!isXAxisScaler()) {
            xi2 = xArray2[i];
            xi2 = correctX(xi2);
            x2 = (xi2 - winXOrigin) * winXScale;
          } else x2 = x1;

          if (sr.contains(new Point((int) x1, (int) y1))
              || sr.contains(new Point((int) x2, (int) y2))) {
            mCurrPC.select(i);
          }
        }
        mViewManager.invalidateAllViews();
        mCurrPC.setBatchModeOff();
      } else if (toolMode == Constants.ZOOM_MODE) {
        if (!shiftDown) {
          doZoomIn(rbRect);
        } else {
          // zoom out
          double xInc = getXZoomIncrement();
          double yInc = getYZoomIncrement();
          double[] oldYs = {getMaxYVal(), getMinYVal()};
          double[] newYs = {
            getMinYVal() < 0 ? getMinYVal() - yInc : getMinYVal() + yInc,
            getMaxYVal() < 0 ? getMaxYVal() - yInc : getMaxYVal() + yInc
          };
          double[] oldXs = {getMinXVal(), getMaxXVal()};
          double[] newXs = {
            getMinXVal() < 0 ? getMinXVal() - xInc : getMinXVal() + xInc,
            getMaxXVal() < 0 ? getMaxXVal() - xInc : getMaxXVal() + xInc
          };
          this.zoomDomain(oldYs, newYs, oldXs, newXs);
        }
        mViewManager.invalidateAllViews();
      }
    } else {
      // region selected
      int x = rbRect.x - mLeft - 5;
      int y = rbRect.y - mTop - 5;
      int x2 = x + rbRect.width;
      int y2 = y + rbRect.height;
      Point p1 = new Point();
      Point p2 = new Point();

      if (toolMode == Constants.SELECT_MODE) {
        if (!shiftDown) mCurrPC.unselectAll();

        // construct a search region;
        int[] xpoints = {x, x2, x2, x, x};
        int[] ypoints = {y, y, y2, y2, y};
        Polygon sr = new Polygon(xpoints, ypoints, 5);

        // search for matches
        byte[] currFilterResults = fdm.getResults();
        double[] yArray1 = getYArray1();
        double[] xArray1 = getXArray1();
        double[] yArray2 = getYArray2();
        double[] xArray2 = getXArray2();

        mCurrPC.setBatchModeOn();
        for (int i = 0; i < mCurrPC.getSize(); i++) {
          if (!mIgnoreFilter
              && (mCurrPC.isDeleted(i) || currFilterResults[i] != 4 || !mCurrPC.isSelectedLayer(i)))
            continue;

          double yi = yArray1[i];
          double xi = xArray1[i];
          double xi2 = Float.NaN;
          double yi2 = Float.NaN;
          double xx2 = Float.NaN;
          double yy2 = Float.NaN;

          // correct the X value if necessary
          xi = correctX(xi);

          double xx1 = (xi - winXOrigin) * winXScale;
          double yy1 = (yi - winYOrigin) * winYScale;

          // correct the Y coordinate if necessary
          yy1 = correctY(yy1);

          if (!isYAxisScaler()) {
            yi2 = yArray2[i];
            yy2 = (yi2 - winYOrigin) * winYScale;
            yy2 = correctY(yy2);
          } else yy2 = yy1;

          if (!isXAxisScaler()) {
            xi2 = xArray2[i];
            xi2 = correctX(xi2);
            xx2 = (xi2 - winXOrigin) * winXScale;
          } else xx2 = xx1;

          p1.setLocation((int) xx1, (int) yy1);
          p2.setLocation((int) xx2, (int) yy2);

          if (sr.contains(p1) || sr.contains(p2)) {
            mCurrPC.select(i);
          }
        }
        mViewManager.invalidateAllViews();
        mCurrPC.setBatchModeOff();
      } else if (toolMode == Constants.ZOOM_MODE) {
        // correct the x value if necessary
        double xx = correctX((double) x);
        double xx2 = correctX((double) x2);

        // correct the Y coordinate if necessary
        double yy = correctY((double) y);
        double yy2 = correctY((double) y2);

        double newX = (xx / winXScale) + winXOrigin;
        double newX2 = (xx2 / winXScale) + winXOrigin;
        double newY = (yy / winYScale) + winYOrigin;
        double newY2 = (yy2 / winYScale) + winYOrigin;

        double[] oldYs = {getMaxYVal(), getMinYVal()};
        if (this.toString().indexOf("Depth") >= 0) {
          double temp = newY2;
          newY2 = newY;
          newY = temp;
        }
        double[] newYs = {newY2, newY};

        double[] oldXs = {getMinXVal(), getMaxXVal()};
        double[] newXs = {newX, newX2};
        this.zoomDomain(oldYs, newYs, oldXs, newXs);
        mViewManager.invalidateAllViews();
      }
    }
  }