Exemplo n.º 1
0
 protected boolean validStartEnd(double x, double y) {
   try {
     IFeatureIterator iterator;
     for (IGeometry geom : geometries) {
       if (geom.contains(x, y)) {
         return true;
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return false;
 }
  /*
   * (non-Javadoc)
   *
   * @see com.iver.cit.gvsig.gui.cad.snapping.ISnapper#getSnapPoint(Point2D
   * point, IGeometry geom,double tolerance, Point2D lastPointEntered)
   */
  public Point2D getSnapPoint(
      Point2D point, IGeometry geom, double tolerance, Point2D lastPointEntered) {
    if (geom.getInternalShape() instanceof FCircle2D
        || geom.getInternalShape() instanceof FArc2D
        || geom.getInternalShape() instanceof FEllipse2D
        || geom.getInternalShape() instanceof FSpline2D) {
      return null;
    }

    Point2D resul = null;
    Coordinate c = new Coordinate(point.getX(), point.getY());

    PathIterator theIterator =
        geom.getPathIterator(null, FConverter.FLATNESS); // polyLine.getPathIterator(null,
    // flatness);
    double[] theData = new double[6];
    double minDist = tolerance;
    Coordinate from = null;
    Coordinate first = null;

    while (!theIterator.isDone()) {
      // while not done
      int theType = theIterator.currentSegment(theData);

      switch (theType) {
        case PathIterator.SEG_MOVETO:
          from = new Coordinate(theData[0], theData[1]);
          first = from;

          break;

        case PathIterator.SEG_LINETO:
          Coordinate to = new Coordinate(theData[0], theData[1]);
          Coordinate mediumPoint = new Coordinate((to.x + from.x) / 2, (to.y + from.y) / 2);
          double dist = c.distance(mediumPoint);

          if ((dist < minDist)) {
            resul = new Point2D.Double(mediumPoint.x, mediumPoint.y);
            minDist = dist;
          }

          from = to;

          break;

        case PathIterator.SEG_CLOSE:
          mediumPoint = new Coordinate((first.x + from.x) / 2, (first.y + from.y) / 2);
          dist = c.distance(mediumPoint);

          if ((dist < minDist)) {
            resul = new Point2D.Double(mediumPoint.x, mediumPoint.y);
            minDist = dist;
          }

          from = first;

          break;
      } // end switch

      theIterator.next();
    }

    return resul;
  }
  /*
   * (non-Javadoc)
   *
   * @see com.iver.cit.gvsig.gui.cad.snapping.ISnapper#getSnapPoint(Point2D
   * point, IGeometry geom,double tolerance, Point2D lastPointEntered)
   */
  public Point2D getSnapPoint(
      Point2D point, IGeometry geom, double tolerance, Point2D lastPointEntered) {
    Point2D resul = null;
    Coordinate c = new Coordinate(point.getX(), point.getY());

    if (lastPointEntered == null) {
      return null;
    }

    Coordinate cLastPoint = new Coordinate(lastPointEntered.getX(), lastPointEntered.getY());
    PathIterator theIterator =
        geom.getPathIterator(null, FConverter.FLATNESS); // polyLine.getPathIterator(null,
    // flatness);
    double[] theData = new double[6];
    double minDist = tolerance;
    Coordinate from = null;
    Coordinate first = null;

    while (!theIterator.isDone()) {
      // while not done
      int theType = theIterator.currentSegment(theData);

      switch (theType) {
        case PathIterator.SEG_MOVETO:
          from = new Coordinate(theData[0], theData[1]);
          first = from;

          break;

        case PathIterator.SEG_LINETO:

          // System.out.println("SEG_LINETO");
          Coordinate to = new Coordinate(theData[0], theData[1]);
          LineSegment line = new LineSegment(from, to);
          Coordinate closestPoint = line.closestPoint(cLastPoint);
          double dist = c.distance(closestPoint);

          if (!(line.getCoordinate(0).equals2D(closestPoint)
              || line.getCoordinate(1).equals2D(closestPoint))) {
            if ((dist < minDist)) {
              resul = new Point2D.Double(closestPoint.x, closestPoint.y);
              minDist = dist;
            }
          }

          from = to;

          break;

        case PathIterator.SEG_CLOSE:
          line = new LineSegment(from, first);
          closestPoint = line.closestPoint(cLastPoint);
          dist = c.distance(closestPoint);

          if (!(line.getCoordinate(0).equals2D(closestPoint)
              || line.getCoordinate(1).equals2D(closestPoint))) {
            if ((dist < minDist)) {
              resul = new Point2D.Double(closestPoint.x, closestPoint.y);
              minDist = dist;
            }
          }

          from = first;

          break;
      } // end switch

      theIterator.next();
    }

    return resul;
  }
Exemplo n.º 4
0
 /**
  * Defines the default logic of drawing a graphic symbol.
  *
  * <p>Using the rendering defined in <code>g</code>, if <code>theSymbol</code> is visible, that
  * symbol will be drawn in <code>viewPort</code>.
  *
  * @param g for rendering 2-dimensional shapes, text and images on the Java(tm) platform
  * @param viewPort information for drawing this graphic item
  * @param theSymbol the symbol that will be drawn
  */
 public void draw(Graphics2D g, ViewPort viewPort, ISymbol theSymbol) {
   if (theSymbol.isShapeVisible()) {
     IGeometry cloneGeom = geom.cloneGeometry();
     cloneGeom.draw(g, viewPort, theSymbol, null);
   }
 }