/**
   * straightenPoints This is a simpler version of the.
   *
   * @see updateIfNotRectilinear that simply ensures that the lines are horizontal or vertical
   *     without any intelligence in terms of shortest distance around a rectangle.
   * @param newLine PointList to check for rectilinear qualities and change if necessary.
   * @param tolerance int tolerance value by which points will be straightened in HiMetrics
   */
  protected static void straightenPoints(final PointList newLine, final int tolerance) {
    for (int i = 0; i < newLine.size() - 1; i++) {
      final Point ptCurrent = newLine.getPoint(i);
      final Point ptNext = newLine.getPoint(i + 1);

      final int xDelta = Math.abs(ptNext.x - ptCurrent.x);
      final int yDelta = Math.abs(ptNext.y - ptCurrent.y);

      if (xDelta < yDelta) {
        if (xDelta > tolerance) {
          return;
        }
        if (i == newLine.size() - 2) {
          // The last point is more important than the other (not
          // change the end of the line)
          ptCurrent.x = ptNext.x;
        } else {
          ptNext.x = ptCurrent.x;
        }
      } else {
        if (yDelta > tolerance) {
          return;
        }
        if (i == newLine.size() - 2) {
          // The last point is more important than the other (not
          // change the end of the line)
          ptCurrent.y = ptNext.y;
        } else {
          ptNext.y = ptCurrent.y;
        }
      }

      newLine.setPoint(ptNext, i + 1);
    }
  }
  private boolean trunkVertexEqual(final Connection connMaster, final Connection connSlave) {
    final PointList cmPts = connMaster.getPoints();
    final PointList csPts = connSlave.getPoints();
    if (cmPts.size() > 2 && csPts.size() > 2) {
      return cmPts.getPoint(2).equals(csPts.getPoint(2));
    }

    return false;
  }
  @Override
  protected List<?> createSelectionHandles() {
    List<BendpointHandle> list = new ArrayList<BendpointHandle>();
    ConnectionEditPart connEP = (ConnectionEditPart) getHost();
    PointList points = getConnection().getPoints();
    List<?> bendPoints = (List<?>) getConnection().getRoutingConstraint();
    int bendPointIndex = 0;
    Point currBendPoint = null;

    if (bendPoints == null) bendPoints = NULL_CONSTRAINT;
    else if (!bendPoints.isEmpty()) currBendPoint = ((Bendpoint) bendPoints.get(0)).getLocation();

    for (int i = 0; i < points.size() - 1; i++) {
      // Put a create handle on the middle of every segment
      list.add(new SnappingBendpointCreationHandle(connEP, bendPointIndex, i));

      // If the current user bendpoint matches a bend location, show a
      // move handle
      if (i < points.size() - 1
          && bendPointIndex < bendPoints.size()
          && currentBendPointMatches(currBendPoint, points.getPoint(i + 1))) {
        list.add(new SnappingBendpointMoveHandle(connEP, bendPointIndex, i + 1));

        // Go to the next user bendpoint
        bendPointIndex++;
        if (bendPointIndex < bendPoints.size())
          currBendPoint = ((Bendpoint) bendPoints.get(bendPointIndex)).getLocation();
      }
    }
    return list;
  }
 protected List<BezierPoint> getBezierPoints(PointList points, double zoom) {
   List<BezierPoint> ret = new ArrayList<BezierPoint>(points.size());
   for (int i = 0; i < points.size(); i++) {
     int bezierDistance = (int) (getGeneralBezierDistance() * zoom);
     Point point = points.getPoint(i);
     ret.add(new BezierPoint(point.x, point.y, bezierDistance, bezierDistance));
   }
   return ret;
 }
  /** @param newConstraint */
  private void validateConstraint(List newConstraint) {
    getTreeRouter().setConstraint(getConnection1(), newConstraint);
    PointList ptl1 = getTreeRouter().getPointsFromConstraint(getConnection1());

    getTreeRouter().route(getConnection2());
    getTreeRouter().route(getConnection1());

    assertTrue(
        "Connection1 points aren't orthogonal", //$NON-NLS-1$
        getTreeRouter().isOrthogonalTreeBranch(getConnection1(), ptl1));

    PointList c1Pts = getConnection1().getPoints();
    PointList c2Pts = getConnection2().getPoints();
    assertTrue(
        "Connection2 points aren't orthogonal", //$NON-NLS-1$
        getTreeRouter().isOrthogonalTreeBranch(getConnection2(), c2Pts));
    assertTrue(
        "Trunk values don't match after tree routing", //$NON-NLS-1$
        c1Pts.getPoint(2).equals(c2Pts.getPoint(2)));
  }
  public void testMoveShape() {
    List newConstraint = initializeConstraint(test1, test1Start, test1End, test1Other);

    getTreeRouter().setConstraint(getConnection1(), newConstraint);
    getTreeRouter().route(getConnection2());
    getTreeRouter().route(getConnection1());

    Rectangle newBounds = new Rectangle(test1Start);
    newBounds.translate(4000, 4000);
    getConnection1().getSourceAnchor().getOwner().setBounds(newBounds);
    getTreeRouter().route(getConnection1());

    getConnection2().validate();

    PointList c1Pts = getConnection1().getPoints();
    PointList c2Pts = getConnection2().getPoints();
    assertTrue(
        "Trunk values don't match after tree routing", //$NON-NLS-1$
        c1Pts.getPoint(2).equals(c2Pts.getPoint(2)));
  }
 @Override
 public boolean test() throws Exception {
   boolean location = false;
   PointList points = ((PolylineConnectionEx) connectionEditPart.getFigure()).getPoints();
   if (checkFirstBendpoint) {
     location = !initialLocation.equals(points.getFirstPoint());
   } else if (checkLastBendpoint) {
     location = !initialLocation.equals(points.getLastPoint());
   } else if (bendpointPosition >= 0 || bendpointPosition < points.size()) {
     location = !initialLocation.equals(points.getPoint(bendpointPosition));
   }
   return location;
 }
  @Override
  public void route(Connection conn) {
    if (isDirty) {
      ignoreInvalidate = true;
      processStaleConnections();
      isDirty = false;
      List<?> updated = algorithm.solve();
      Connection current;
      for (int i = 0; i < updated.size(); i++) {
        Path path = (Path) updated.get(i);
        current = (Connection) path.data;
        current.revalidate();

        PointList points = path.getPoints().getCopy();
        Point ref1;
        Point ref2;
        Point start;
        Point end;
        ref1 = new PrecisionPoint(points.getPoint(1));
        ref2 = new PrecisionPoint(points.getPoint(points.size() - 2));
        current.translateToAbsolute(ref1);
        current.translateToAbsolute(ref2);

        start = current.getSourceAnchor().getLocation(ref1).getCopy();
        end = current.getTargetAnchor().getLocation(ref2).getCopy();

        current.translateToRelative(start);
        current.translateToRelative(end);
        points.setPoint(start, 0);
        points.setPoint(end, points.size() - 1);

        current.setPoints(points);
      }
      ignoreInvalidate = false;
    }
  }
  /**
   * UpdateConstraint Updates the constraint value for the connection based on the tree vertex.
   *
   * @param conn Connection whose constraint is to be updated.
   */
  protected void updateConstraint(final Connection conn) {
    boolean update =
        conn != null && conn.getSourceAnchor() != null && conn.getTargetAnchor() != null;
    update =
        update
            && conn.getSourceAnchor().getOwner() != null
            && conn.getTargetAnchor().getOwner() != null;
    if (update) {
      if (isUpdatingPeers()) {
        return;
      }

      List bendpoints = (List) conn.getRoutingConstraint();
      if (bendpoints == null) {
        bendpoints = new ArrayList(conn.getPoints().size());
      }

      final Point sourceRefPoint = conn.getSourceAnchor().getReferencePoint();
      conn.translateToRelative(sourceRefPoint);

      final Point targetRefPoint = conn.getTargetAnchor().getReferencePoint();
      conn.translateToRelative(targetRefPoint);

      final Point ptTrunk = getTrunkLocation(conn);
      final Point ptSource = getBranchRouter().getSourceLocation(conn, ptTrunk);

      bendpoints.clear();
      final PointList pts = getBranchRouter().recreateBranch(conn, ptSource, ptTrunk);
      for (int i = 0; i < pts.size(); i++) {
        final Bendpoint bp = new AbsoluteBendpoint(pts.getPoint(i));
        bendpoints.add(bp);
      }

      setUpdatingPeers(true);

      try {
        setConstraint(conn, bendpoints);
        conn.invalidate();
        conn.validate();
      } finally {
        setUpdatingPeers(false);
      }
    }
  }
  /**
   * Utility method to determine if the given set of points conforms to the constraints of being an
   * orthogonal connection tree-branch. 1. Points size must be 4. 2. Source point resides with-in
   * boundary of source shape based on orientation 3. Target point resides with-in boundary of
   * target shape based on orientation 4. Middle line is perpendicular to the 2 end lines.
   *
   * @param conn the <code>Connection</code> to test
   * @param points <code>PointList</code> to test constraints against
   * @return <code>boolean</code> <code>true</code> if points represent valid orthogaonl tree
   *     branch, <code>false</code> otherwise.
   */
  public boolean isOrthogonalTreeBranch(final Connection conn, final PointList points) {
    boolean result = false;
    if (isTreeBranch(conn, points)) {
      final LineSeg branch = new LineSeg(points.getPoint(0), points.getPoint(1));
      final LineSeg trunkShoulder = new LineSeg(points.getPoint(1), points.getPoint(2));
      final LineSeg trunk = new LineSeg(points.getPoint(2), points.getPoint(3));

      if (isTopDown(conn)) {
        result = branch.isVertical() && trunkShoulder.isHorizontal() && trunk.isVertical();
      } else {
        result = branch.isHorizontal() && trunkShoulder.isVertical() && trunk.isHorizontal();
      }
    }

    return result;
  }
  /**
   * Utility method to determine if the given set of points conforms to the constraints of being a
   * connection tree-branch. 1. Points size must be 4. 2. Source point resides with-in boundary of
   * source shape based on orientation 3. Target point resides with-in boundary of target shape
   * based on orientation
   *
   * @param conn the <code>Connection</code> to test
   * @param points the <code>PointList</code> to test constraints against
   * @return <code>boolean</code> <code>true</code> if points represent valid tree branch, <code>
   *     false</code> otherwise.
   */
  public boolean isTreeBranch(final Connection conn, final PointList points) {
    boolean result = false;
    if (points.size() == 4) {
      // just check if ends are with-in the owner bounding box
      final Rectangle targetBounds = getTargetAnchorRelativeBounds(conn);
      final Rectangle sourceBounds = getSourceAnchorRelativeBounds(conn);

      if (isTopDown(conn)) {
        result =
            (points.getPoint(0).x > sourceBounds.x
                    && points.getPoint(0).x < sourceBounds.x + sourceBounds.width)
                && (points.getPoint(3).x > targetBounds.x
                    && points.getPoint(3).x < targetBounds.x + targetBounds.width);
      } else {
        result =
            (points.getPoint(0).y > sourceBounds.y
                    && points.getPoint(0).y < sourceBounds.y + sourceBounds.height)
                && (points.getPoint(3).y > targetBounds.y
                    && points.getPoint(3).y < targetBounds.y + targetBounds.height);
      }
    }

    return result;
  }
示例#12
0
    public void layout(IFigure container) {
      Rectangle area = container.getClientArea();
      // calculate a virtual area

      if (scale != null && scale.isDirty())
        M =
            Math.max(
                    FigureUtilities.getTextWidth(
                        scale.format(scale.getRange().getLower()), scale.getFont()),
                    FigureUtilities.getTextWidth(
                        scale.format(scale.getRange().getUpper()), scale.getFont()))
                / 2;

      int h = area.height;
      int w = area.width;
      if (h > HW_RATIO * (w - 2 * M)) h = (int) (HW_RATIO * (w - 2 * M));
      // else if (w > h/HW_RATIO + 2*M)
      //	w = (int) (h/HW_RATIO + 2*M);
      double r = h / (1 - Math.sin(ALPHA) / 2);
      int x = (int) (area.x - r * (1.0 - Math.cos(ALPHA)) + M);
      int y = area.y;

      area = new Rectangle(x, y, (int) (2 * r), (int) (2 * r));
      Point center = area.getCenter();

      if (scale != null) {
        scale.setBounds(area);
      }

      if (ramp != null && ramp.isVisible()) {
        Rectangle rampBounds = area.getCopy();
        ramp.setBounds(
            rampBounds.shrink(
                area.width / 4 - ramp.getRampWidth(), area.height / 4 - ramp.getRampWidth()));
      }

      if (valueLabel != null) {
        Dimension labelSize = valueLabel.getPreferredSize();
        valueLabel.setBounds(
            new Rectangle(
                area.x + area.width / 2 - labelSize.width / 2,
                area.y
                    + area.height / 2
                    - area.height / 4
                    - (scale.getInnerRadius() - area.height / 4) / 2
                    - labelSize.height / 2,
                labelSize.width,
                labelSize.height));
      }

      if (needle != null && scale != null) {
        needlePoints.setPoint(
            new Point(center.x + area.width / 4, center.y - NEEDLE_WIDTH / 2 + 3), 0);
        scale.getScaleTickMarks();
        needlePoints.setPoint(
            new Point(center.x + scale.getInnerRadius() - GAP_BTW_NEEDLE_SCALE, center.y), 1);
        needlePoints.setPoint(
            new Point(center.x + area.width / 4, center.y + NEEDLE_WIDTH / 2 - 3), 2);

        double valuePosition = 360 - scale.getValuePosition(getCoercedValue(), false);
        if (maximum > minimum) {
          if (value > maximum) valuePosition += 8;
          else if (value < minimum) valuePosition -= 8;
        } else {
          if (value > minimum) valuePosition -= 8;
          else if (value < maximum) valuePosition += 8;
        }
        needlePoints.setPoint(
            PointsUtil.rotate(needlePoints.getPoint(0), valuePosition, center), 0);
        needlePoints.setPoint(
            PointsUtil.rotate(needlePoints.getPoint(1), valuePosition, center), 1);
        needlePoints.setPoint(
            PointsUtil.rotate(needlePoints.getPoint(2), valuePosition, center), 2);
        needle.setPoints(needlePoints);
      }

      //			if(needleCenter != null){
      //				needleCenter.setBounds(new Rectangle(center.x - area.width/4,
      //						center.y - area.height/4,
      //						area.width/2, area.height/2));
      //			}

    }
示例#13
0
    public void layout(IFigure container) {
      Rectangle area = container.getClientArea();

      area.width = Math.min(area.width, area.height);
      area.height = area.width;
      area.shrink(BORDER_WIDTH, BORDER_WIDTH);

      Point center = area.getCenter();

      if (scale != null) {
        scale.setBounds(area);
      }

      if (ramp != null && ramp.isVisible()) {
        Rectangle rampBounds = area.getCopy();
        ramp.setBounds(rampBounds.shrink(area.width / 4, area.height / 4));
      }

      if (valueLabel != null) {
        Dimension labelSize = valueLabel.getPreferredSize();
        valueLabel.setBounds(
            new Rectangle(
                area.x + area.width / 2 - labelSize.width / 2,
                area.y + area.height * 7 / 8 - labelSize.height / 2,
                labelSize.width,
                labelSize.height));
      }

      if (needle != null && scale != null) {
        needlePoints.setPoint(new Point(center.x, center.y - NeedleCenter.DIAMETER / 2 + 3), 0);
        scale.getScaleTickMarks();
        needlePoints.setPoint(
            new Point(
                center.x
                    + area.width / 2
                    - RoundScaleTickMarks.MAJOR_TICK_LENGTH
                    - GAP_BTW_NEEDLE_SCALE,
                center.y),
            1);
        needlePoints.setPoint(new Point(center.x, center.y + NeedleCenter.DIAMETER / 2 - 3), 2);

        double valuePosition = 360 - scale.getValuePosition(getCoercedValue(), false);
        if (maximum > minimum) {
          if (value > maximum) valuePosition += 10;
          else if (value < minimum) valuePosition -= 10;
        } else {
          if (value > minimum) valuePosition -= 10;
          else if (value < maximum) valuePosition += 10;
        }
        needlePoints.setPoint(
            PointsUtil.rotate(needlePoints.getPoint(0), valuePosition, center), 0);
        needlePoints.setPoint(
            PointsUtil.rotate(needlePoints.getPoint(1), valuePosition, center), 1);
        needlePoints.setPoint(
            PointsUtil.rotate(needlePoints.getPoint(2), valuePosition, center), 2);
        needle.setPoints(needlePoints);
      }

      if (needleCenter != null) {
        needleCenter.setBounds(
            new Rectangle(
                center.x - NeedleCenter.DIAMETER / 2,
                center.y - NeedleCenter.DIAMETER / 2,
                NeedleCenter.DIAMETER,
                NeedleCenter.DIAMETER));
      }
    }
示例#14
0
 @Override
 public void execute() {
   // configure the request
   EditPart source = request.getSourceEditPart();
   EditPart target = request.getTargetEditPart();
   PointList list = feedback.getPoints();
   DiagramEditPart diagramEditPart = null;
   if (source.getParent() instanceof DiagramEditPart) {
     diagramEditPart = (DiagramEditPart) source.getParent();
   } else if (source instanceof DiagramEditPart) {
     diagramEditPart = (DiagramEditPart) source;
   } else {
     if (source.getParent().getParent() instanceof DiagramEditPart) {
       diagramEditPart = (DiagramEditPart) source.getParent().getParent();
     }
   }
   if (diagramEditPart == null) {
     return;
   }
   if (!(source instanceof DiagramEditPart || target instanceof DiagramEditPart)) {
     // one must be whitespace, we make it the target
     request.setTargetEditPart(diagramEditPart);
     // additionally we must cut the drawn connection
     // in half to share room with the element that will
     // be auto-created
     PointList newList = new PointList();
     newList.addPoint(list.getFirstPoint());
     if (list.size() == 4) {
       // rectilinear routing will have a three points
       newList.addPoint(list.getPoint(1));
     }
     newList.addPoint(list.getMidpoint());
     feedback.setPoints(newList);
   }
   // create the active tool's element first
   CreateConnectionCommand command = new CreateConnectionCommand(request, feedback);
   command.execute();
   Connector_c newConnector = command.result;
   if (newConnector == null) {
     return;
   }
   // we need to now refresh the diagram to get the new edit part
   source.refresh();
   source.getParent().refresh();
   GraphicalEditPart newPart =
       (GraphicalEditPart) source.getViewer().getEditPartRegistry().get(newConnector);
   // transfer the feedback connection points to the newly created
   // edit part
   ((Connection) newPart.getFigure()).setPoints(feedback.getPoints().getCopy());
   // now adjust the request for the new element to be created for each
   // terminal specification that requires auto-creation
   createElementForTerminalSpec(
       autoStartSpec,
       ((NonRootModelElement) diagramEditPart.getModel()).getModelRoot(),
       list,
       newPart,
       target,
       diagramEditPart);
   createElementForTerminalSpec(
       autoEndSpec,
       ((NonRootModelElement) diagramEditPart.getModel()).getModelRoot(),
       list,
       newPart,
       target,
       diagramEditPart);
 }
示例#15
0
  private void createElementForTerminalSpec(
      TerminalSpecification_c autoCreationSpec,
      ModelRoot modelRoot,
      PointList line,
      EditPart newPart,
      EditPart targetPart,
      final DiagramEditPart diagramEditPart) {
    ElementSpecification_c specification =
        ElementSpecification_c.getOneGD_ESOnR209(autoCreationSpec);
    if (specification != null && request instanceof GraphicsConnectionCreateRequest) {
      // deactivate the current tool
      ModelTool_c activeTool =
          ModelTool_c.ModelToolInstance(
              modelRoot,
              new ClassQueryInterface_c() {

                @Override
                public boolean evaluate(Object candidate) {
                  return ((ModelTool_c) candidate).getActive();
                }
              });
      activeTool.setActive(false);
      // find the new tool and activate it
      ModelTool_c newTool =
          ModelTool_c.getOneCT_MTLOnR103(
              specification,
              new ClassQueryInterface_c() {

                @Override
                public boolean evaluate(Object candidate) {
                  ModelTool_c tool = (ModelTool_c) candidate;
                  return Model_c.getOneGD_MDOnR100(tool) == diagramEditPart.getModel();
                }
              });
      newTool.setActive(true);
      // create the new element
      if (specification.getSymboltype().equals("connector")) { // $NON-NLS-1$
        // creating a connector
        // we want to create the new connector from the
        // midpoint of the drawn line to the end of the
        // drawn line
        PointList newLine = new PointList();
        newLine.addPoint(line.getLastPoint());
        if (line.size() == 4) {
          // rectilinear routing will have a three points
          newLine.addPoint(line.getPoint(2));
        }
        newLine.addPoint(line.getMidpoint());
        feedback.setPoints(newLine);
        // we also need to adjust the request's source and
        // target edit part, we swap the original target as the
        // source as if the new connection was drawn from
        // the original destination element
        request.setTargetEditPart(newPart);
        request.setSourceEditPart(targetPart);
        // need to update the location in the request for
        // those connectors that end on whitespace
        request.setLocation(line.getMidpoint());
        // we need to configure the proper tool id in the
        // request
        GraphicsConnectionCreateRequest gRequest = (GraphicsConnectionCreateRequest) request;
        gRequest.setToolId(newTool.getTool_id());
        CreateConnectionCommand command = new CreateConnectionCommand(request, feedback);
        command.disableCropping();
        command.execute();
        // reset the active tool states
        newTool.setActive(false);
        activeTool.setActive(true);
      } else if (specification.getSymboltype().equals("shape")) { // $NON-NLS-1$
        // TODO: support shape auto creation
      }
    }
    // otherwise this is not an auto create specification
  }