Java Code Examples for org.eclipse.draw2d.geometry.PointList#getPoint()

The following examples show how to use org.eclipse.draw2d.geometry.PointList#getPoint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PointsUtil.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**Scale the geometry size of a pointlist.
 * @param points points to be scaled.
 * @param widthRatio width scale ratio.
 * @param heightRatio height scale ratio.
 */
public static final void scalePoints(PointList points,
		double widthRatio, double heightRatio){
	Point p0 = points.getBounds().getLocation();
	for(int i=0; i<points.size(); i++){
		Point p=points.getPoint(i);
		p.x=(int) ((p.x-p0.x)*widthRatio) + p0.x;
		p.y=(int) ((p.y-p0.y)*heightRatio) + p0.y;
		points.setPoint(p,i);
	}	
}
 
Example 2
Source File: ConnData.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void printVisualPoints() {
	System.out.println("Visual Points for " + conn);
	PointList pointList = conn.getPoints();
	for (int i = 0; i < pointList.size(); i++) {
		Point p = pointList.getPoint(i);
		System.out.println("- " + p);
	}
}
 
Example 3
Source File: BPMNShapeFactory.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public BPMNEdge createBPMNEdge(final String bpmnFlowId, EObject bonitaElement) {
    Edge bonitaEdge = modelExporter.getElementNotationEdge(bonitaElement);
    if (bonitaEdge != null) {
        final BPMNEdge edge = DiFactory.eINSTANCE.createBPMNEdge();
        edge.setBpmnElement(QName.valueOf(bpmnFlowId));
        edge.setId(modelExporter.getEObjectID(bonitaEdge));

        PolylineConnection conn = createConnectorFigure(bonitaEdge);
        PointList points = conn.getPoints();
        for (int i = 0; i < points.size(); i++) {
            final org.omg.spec.dd.dc.Point sourcePoint = DcFactory.eINSTANCE.createPoint();
            Point point = points.getPoint(i);
            sourcePoint.setX(point.x);
            sourcePoint.setY(point.y);
            edge.getWaypoint().add(sourcePoint);
        }

        if (bonitaElement instanceof SequenceFlow) {
            bonitaEdge.getPersistedChildren().stream()
                    .filter(DecorationNode.class::isInstance)
                    .findFirst()
                    .ifPresent(decorationNode -> attachEdgeLabel((DecorationNode) decorationNode, edge,
                            ((SequenceFlow) bonitaElement).getName(), bonitaEdge));
        }
        return edge;
    }
    return null;
}
 
Example 4
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Rectilinear polyline is invalid if:
 * 1. First bend point is within the source
 * 2. Last bend point is within the target
 * 3. First bend point and source anchor are on different sides of the source shape
 * 4. Last bend point and target anchor are on different sides of the target shape
 * 
 * @param conn connection
 * @param line rectilinear polyline
 * @return <code>true</code> if the line is valid
 */
private boolean isValidRectilinearLine(Connection conn, PointList line) {
    if (!(conn.getSourceAnchor().getOwner() instanceof Connection)) {
        Rectangle source = new PrecisionRectangle(
                getAnchorableFigureBounds(conn.getSourceAnchor().getOwner()));
        conn.getSourceAnchor().getOwner().translateToAbsolute(source);
        conn.translateToRelative(source);
        if (source.contains(line.getPoint(1))) {
            return false;
        }
        int firstSegmentOrientation = line.getFirstPoint().x == line.getPoint(1).x ? PositionConstants.VERTICAL
                : PositionConstants.HORIZONTAL;
        if (getOutisePointOffRectanglePosition(line.getPoint(1), source) != getAnchorLocationBasedOnSegmentOrientation(
                line.getFirstPoint(), source, firstSegmentOrientation)) {
            return false;
        }
    }
    if (!(conn.getTargetAnchor().getOwner() instanceof Connection)) {
        Rectangle target = new PrecisionRectangle(
                getAnchorableFigureBounds(conn.getTargetAnchor().getOwner()));
        conn.getTargetAnchor().getOwner().translateToAbsolute(target);
        conn.translateToRelative(target);
        if (target.contains(line.getPoint(line.size() - 2))) {
            return false;
        }
        int lastSegmentOrientation = line.getLastPoint().x == line.getPoint(line.size() - 2).x
                ? PositionConstants.VERTICAL : PositionConstants.HORIZONTAL;
        if (getOutisePointOffRectanglePosition(line.getPoint(line.size() - 2),
                target) != getAnchorLocationBasedOnSegmentOrientation(line.getLastPoint(), target,
                        lastSegmentOrientation)) {
            return false;
        }
    }
    return true;
}
 
Example 5
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Goes through line segments of a polyline and makes strict straight segments
 * from nearly straight segments.
 * 
 * @param line polyline
 * @param tolerance tolerance value specifying nearly straight lines.
 */
private void normalizeToStraightLineTolerance(PointList line, int tolerance) {
    for (int i = 0; i < line.size() - 1; i++) {
        Point pt1 = line.getPoint(i);
        Point pt2 = line.getPoint(i + 1);
        if (Math.abs(pt1.x - pt2.x) < tolerance) {
            line.setPoint(new Point(pt1.x, pt2.y), i + 1);
        } else if (Math.abs(pt1.y - pt2.y) < tolerance) {
            line.setPoint(new Point(pt2.x, pt1.y), i + 1);
        }
    }
}
 
Example 6
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Iterates through points of a polyline and does the following:
 * if 3 points lie on the same line the middle point is removed
 * 
 * @param line polyline's points
 */
private boolean removeRedundantPoints(PointList line) {
    int initialNumberOfPoints = line.size();
    if (line.size() > 2) {
        PointList newLine = new PointList(line.size());
        newLine.addPoint(line.removePoint(0));
        while (line.size() >= 2) {
            Point p0 = newLine.getLastPoint();
            Point p1 = line.getPoint(0);
            Point p2 = line.getPoint(1);
            if (p0.x == p1.x && p0.x == p2.x) {
                // Have two vertical segments in a row
                // get rid of the point between
                line.removePoint(0);
            } else if (p0.y == p1.y && p0.y == p2.y) {
                // Have two horizontal segments in a row
                // get rid of the point between
                line.removePoint(0);
            } else {
                newLine.addPoint(line.removePoint(0));
            }
        }
        while (line.size() > 0) {
            newLine.addPoint(line.removePoint(0));
        }
        line.removeAllPoints();
        line.addAll(newLine);
    }
    return line.size() != initialNumberOfPoints;
}
 
Example 7
Source File: Animation.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
static boolean playbackState(Connection conn) {
	if (!PLAYBACK) {
		return false;
	}

	PointList list1 = (PointList) initialStates.get(conn);
	PointList list2 = (PointList) finalStates.get(conn);
	if (list1 == null) {
		conn.setVisible(false);
		return true;
	}
	if (list1.size() == list2.size()) {
		Point pt1 = new Point(), pt2 = new Point();
		PointList points = conn.getPoints();
		points.removeAllPoints();
		for (int i = 0; i < list1.size(); i++) {
			list1.getPoint(pt2, i);
			list2.getPoint(pt1, i);
			pt1.x = (int) Math.round(pt1.x * progress + (1 - progress)
					* pt2.x);
			pt1.y = (int) Math.round(pt1.y * progress + (1 - progress)
					* pt2.y);
			points.addPoint(pt1);
		}
		conn.setPoints(points);
	}
	return true;
}
 
Example 8
Source File: Animation.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
static void recordFinalState(Connection conn) {
	PointList points1 = (PointList) initialStates.get(conn);
	PointList points2 = conn.getPoints().getCopy();

	if (points1 != null && points1.size() != points2.size()) {
		Point p = new Point(), q = new Point();

		int size1 = points1.size() - 1;
		int size2 = points2.size() - 1;

		int i1 = size1;
		int i2 = size2;

		double current1 = 1.0;
		double current2 = 1.0;

		double prev1 = 1.0;
		double prev2 = 1.0;

		while (i1 > 0 || i2 > 0) {
			if (Math.abs(current1 - current2) < 0.1 && i1 > 0 && i2 > 0) {
				// Both points are the same, use them and go on;
				prev1 = current1;
				prev2 = current2;
				i1--;
				i2--;
				current1 = (double) i1 / size1;
				current2 = (double) i2 / size2;
			} else if (current1 < current2) {
				// 2 needs to catch up
				// current1 < current2 < prev1
				points1.getPoint(p, i1);
				points1.getPoint(q, i1 + 1);

				p.x = (int) ((q.x * (current2 - current1) + p.x
						* (prev1 - current2)) / (prev1 - current1));
				p.y = (int) ((q.y * (current2 - current1) + p.y
						* (prev1 - current2)) / (prev1 - current1));

				points1.insertPoint(p, i1 + 1);

				prev1 = prev2 = current2;
				i2--;
				current2 = (double) i2 / size2;

			} else {
				// 1 needs to catch up
				// current2< current1 < prev2

				points2.getPoint(p, i2);
				points2.getPoint(q, i2 + 1);

				p.x = (int) ((q.x * (current1 - current2) + p.x
						* (prev2 - current1)) / (prev2 - current2));
				p.y = (int) ((q.y * (current1 - current2) + p.y
						* (prev2 - current1)) / (prev2 - current2));

				points2.insertPoint(p, i2 + 1);

				prev2 = prev1 = current1;
				i1--;
				current1 = (double) i1 / size1;
			}
		}
	}
	finalStates.put(conn, points2);
}