コード例 #1
0
 private Point getPointForEnd(PointList points) {
   Point point = null;
   if (end == End_c.Middle) {
     point = points.getMidpoint();
   } else if (end == End_c.Start) {
     point = points.getFirstPoint();
   } else if (end == End_c.End) {
     point = points.getLastPoint();
   }
   return point;
 }
コード例 #2
0
 @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;
 }
コード例 #3
0
 private Point getAbsoluteEdgeExtremity(
     ConnectionNodeEditPart editPart, boolean isStart, Float[] preferPosition) {
   if (editPart == null) {
     return null;
   }
   PointList points = editPart.getConnectionFigure().getPoints().getCopy();
   if (points.size() == 2
       && new Point(0, 0).equals(points.getFirstPoint())
       && new Point(100, 100).equals(points.getLastPoint())) {
     // not display yet.
     if (preferPosition != null) {
       if (isStart && preferPosition[0] != null) {
         return new Point(0, preferPosition[0].intValue());
       } else if (!isStart && preferPosition[1] != null) {
         return new Point(0, preferPosition[1].intValue());
       }
     }
     return SequenceUtil.getAbsoluteEdgeExtremity(editPart, isStart, false);
   }
   return SequenceUtil.getAbsoluteEdgeExtremity(editPart, isStart, true);
 }
コード例 #4
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
  }
  /**
   * Computes clipping rectangle(s) for a given connection. Will consider all enclosing viewports,
   * excluding the root viewport.
   */
  protected Rectangle[] getEdgeClippingRectangle(Connection connection) {
    // start with clipping the connection at its original bounds
    Rectangle clipRect = getAbsoluteBoundsAsCopy(connection);

    // in case we cannot infer source and target of the connection (e.g.
    // if XYAnchors are used), returning the bounds is all we can do
    ConnectionAnchor sourceAnchor = connection.getSourceAnchor();
    ConnectionAnchor targetAnchor = connection.getTargetAnchor();
    if (sourceAnchor == null
        || sourceAnchor.getOwner() == null
        || targetAnchor == null
        || targetAnchor.getOwner() == null) {
      return new Rectangle[] {clipRect};
    }

    // source and target figure are known, see if there is common
    // viewport
    // the connection has to be clipped at.
    IFigure sourceFigure = sourceAnchor.getOwner();
    IFigure targetFigure = targetAnchor.getOwner();
    Viewport nearestEnclosingCommonViewport =
        ViewportUtilities.getNearestCommonViewport(sourceFigure, targetFigure);
    if (nearestEnclosingCommonViewport == null) {
      return new Rectangle[] {clipRect};
    }

    // if the nearest common viewport is not the root viewport, we may
    // start with clipping the connection at this viewport.
    if (nearestEnclosingCommonViewport != getRootViewport()) {
      clipRect.intersect(getNodeClippingRectangle(nearestEnclosingCommonViewport));
    }

    // if the nearest common viewport of source and target is not
    // simultaneously
    // the nearest enclosing viewport of source and target respectively, the
    // connection has to be further clipped (the connection may even not be
    // visible at all)
    Viewport nearestEnclosingSourceViewport =
        ViewportUtilities.getNearestEnclosingViewport(sourceFigure);
    Viewport nearestEnclosingTargetViewport =
        ViewportUtilities.getNearestEnclosingViewport(targetFigure);
    if (nearestEnclosingSourceViewport != nearestEnclosingTargetViewport) {
      // compute if source and target anchor are visible
      // within the nearest common enclosing viewport (which may
      // itself be nested in other viewports).
      Rectangle sourceClipRect = getAbsoluteBoundsAsCopy(connection);
      if (nearestEnclosingSourceViewport != nearestEnclosingCommonViewport) {
        clipAtViewports(
            sourceClipRect,
            ViewportUtilities.getViewportsPath(
                nearestEnclosingSourceViewport, nearestEnclosingCommonViewport, false));
      }
      Rectangle targetClipRect = getAbsoluteBoundsAsCopy(connection);
      if (nearestEnclosingTargetViewport != nearestEnclosingCommonViewport) {
        clipAtViewports(
            targetClipRect,
            ViewportUtilities.getViewportsPath(
                nearestEnclosingTargetViewport, nearestEnclosingCommonViewport, false));
      }
      PointList absolutePointsAsCopy = getAbsolutePointsAsCopy(connection);
      boolean sourceAnchorVisible =
          sourceClipRect.getExpanded(PRIVATE_INSETS).contains(absolutePointsAsCopy.getFirstPoint());
      boolean targetAnchorVisible =
          targetClipRect.getExpanded(PRIVATE_INSETS).contains(absolutePointsAsCopy.getLastPoint());

      if (!sourceAnchorVisible || !targetAnchorVisible) {
        // one (or both) of source or target anchor is invisible
        // within the nearest common viewport, so up to now
        // we regard the edge as invisible.
        return new Rectangle[] {};
        // TODO: We could come up with a more decent strategy here,
        // which also computes clipping fragments in those cases
        // where source/target are not visible but the edge
        // intersects with the enclosing source/target viewport's
        // parents bounds.

      } else {
        // both ends are visible, so just return what we have
        // computed before
        // (clipping at nearest enclosing viewport)
        return new Rectangle[] {clipRect};
      }
    } else {
      // source and target share the same enclosing viewport, so just
      // return what we have computed before (clipping at nearest
      // enclosing viewport)
      return new Rectangle[] {clipRect};
    }
  }