Ejemplo n.º 1
0
  /*
   * (non-Javadoc)
   *
   * @see br.org.archimedes.factories.SelectionPointVectorFactory#drawVisualHelper(br.org.archimedes.model.writers.Writer,
   *      java.util.Set, br.org.archimedes.model.Point,
   *      br.org.archimedes.model.Vector)
   */
  @Override
  protected void drawVisualHelper(Set<Element> selection, Point reference, Vector vector) {

    OpenGLWrapper opengl = br.org.archimedes.Utils.getOpenGLWrapper();
    for (Element element : selection) {
      Element copied = element.clone();
      try {
        Point start = reference;
        Point end = start.addVector(vector);

        List<Point> points = new LinkedList<Point>();
        points.add(start);
        points.add(end);
        opengl.drawFromModel(points);

        copied.mirror(start, end);
        copied.draw(opengl);
      } catch (NullArgumentException e) {
        // Should not happen
        e.printStackTrace();
      } catch (Exception e) {
        // Might happen, just ignore
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * @param selection The selection with the elements that should be considered
   * @return The collection of points or null if null was passsed.
   */
  private Map<Element, Collection<Point>> getPoints(Selection selection) {

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

    Map<Element, Collection<Point>> pointsToMove = new HashMap<Element, Collection<Point>>();
    for (Element element : selection.getSelectedElements()) {
      pointsToMove.put(element, element.getPoints());
    }

    return pointsToMove;
  }
  public Collection<Element> trim(Element element, Collection<Point> cutPoints, Point click)
      throws NullArgumentException {

    if (element == null || cutPoints == null) {
      throw new NullArgumentException();
    }

    InfiniteLine line = (InfiniteLine) element;
    Collection<Element> trimResult = new ArrayList<Element>();

    SortedSet<ComparablePoint> sortedPointSet =
        getSortedPointSet(line, line.getInitialPoint(), cutPoints);

    Vector direction = new Vector(line.getInitialPoint(), line.getEndingPoint());

    Vector clickVector = new Vector(line.getInitialPoint(), click);
    double key = direction.dotProduct(clickVector);
    ComparablePoint clickPoint = null;
    try {
      clickPoint = new ComparablePoint(click, new DoubleKey(key));
    } catch (NullArgumentException e) {
      // Should never reach
      e.printStackTrace();
    }

    SortedSet<ComparablePoint> headSet = sortedPointSet.headSet(clickPoint);
    SortedSet<ComparablePoint> tailSet = sortedPointSet.tailSet(clickPoint);

    try {

      if (tailSet.size() > 0 && tailSet.first().getPoint().equals(clickPoint.getPoint())) {

        Point initialPoint = tailSet.first().getPoint();

        if (line.getInitialPoint().compareTo(line.getEndingPoint()) < 0) {
          direction = new Vector(line.getInitialPoint(), line.getEndingPoint());
        } else {
          direction = new Vector(line.getEndingPoint(), line.getInitialPoint());
        }

        clickPoint.getPoint().setX(clickPoint.getPoint().getX() + direction.getX());
        clickPoint.getPoint().setY(clickPoint.getPoint().getY() + direction.getY());

        Element trimmedLine = generateSemiline(clickPoint, initialPoint);
        trimmedLine.setLayer(line.getLayer());
        trimResult.add(trimmedLine);

      } else if (headSet.size() == 0 && tailSet.size() > 0) {
        Point initialPoint = tailSet.first().getPoint();
        Element trimmedLine = generateSemiline(clickPoint, initialPoint);
        trimmedLine.setLayer(line.getLayer());
        trimResult.add(trimmedLine);

      } else if (tailSet.size() == 0 && headSet.size() > 0) {
        Point initialPoint = headSet.last().getPoint();
        Element trimmedLine = generateSemiline(clickPoint, initialPoint);
        trimmedLine.setLayer(line.getLayer());
        trimResult.add(trimmedLine);

      } else if (headSet.size() > 0 && tailSet.size() > 0) {

        Point initialPoint = headSet.last().getPoint();
        Element trimmedLine = generateSemiline(clickPoint, initialPoint);
        trimmedLine.setLayer(line.getLayer());
        trimResult.add(trimmedLine);

        initialPoint = tailSet.first().getPoint();
        trimmedLine = generateSemiline(clickPoint, initialPoint);
        trimmedLine.setLayer(line.getLayer());
        trimResult.add(trimmedLine);
      }
    } catch (Exception e) {
      // Should not catch any exception
      e.printStackTrace();
    }

    return trimResult;
  }