use of org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg in project statecharts by Yakindu.
the class EdgeLabelQuery method getRotatedVector.
/**
* Get the rotated vector according to the segment orientation.
*
* @param vector
* vector to be rotated
* @param segment
* reference segment
* @param inverseRotation
* if true, inverse rotation
* @return the rotated Vector
*/
private static Vector getRotatedVector(Vector vector, LineSeg segment, boolean inverseRotation) {
Vector result = new Vector(vector.x, vector.y);
if (vector.x != 0 || vector.y != 0) {
double angle = angleBetween2Lines(new LineSeg(new Point(0, 0), new Point(1, 0)), segment) * (inverseRotation ? -1 : 1);
Transform rotateTransform = new Transform();
rotateTransform.setRotation(angle);
Point rotatedPoint = rotateTransform.getTransformed(vector.toPoint());
result.x = rotatedPoint.x;
result.y = rotatedPoint.y;
}
return result;
}
use of org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg in project statecharts by Yakindu.
the class EdgeLabelQuery method getVectorForSegmentMoveCase.
/**
* Check if we are in case of a rectilinear segment move: there is a new segment
* at the same index as old nearest segment and with the same axis. Return the
* corresponding vector from old to new center in this case, null otherwise.
*
* @param oldNearestSeg
* The segment that is the nearest from the center of the label in
* the old points list.
* @return the corresponding vector from old to new center in case of
* rectilinear segment move, null otherwise.
*/
private Vector getVectorForSegmentMoveCase(LineSeg oldNearestSeg, Point oldNearestPoint, Point oldCenterLabel) {
Vector fromOldToNewCenterVector = null;
if (newEdgeSegments.size() == oldEdgeSegments.size()) {
int index = oldEdgeSegments.indexOf(oldNearestSeg);
LineSeg newNearestSegment = newEdgeSegments.get(index);
if (oldNearestSeg.isHorizontal() == newNearestSegment.isHorizontal()) {
Vector oldVector = new Vector(oldNearestSeg.getTerminus().x - oldNearestSeg.getOrigin().x, oldNearestSeg.getTerminus().y - oldNearestSeg.getOrigin().y);
Vector newVector = new Vector(newNearestSegment.getTerminus().x - newNearestSegment.getOrigin().x, newNearestSegment.getTerminus().y - newNearestSegment.getOrigin().y);
fromOldToNewCenterVector = applyOldRatioOnNewSegment(oldNearestSeg, oldNearestPoint, oldCenterLabel, newNearestSegment, oldVector.getAngle(newVector) == 180, false);
}
}
return fromOldToNewCenterVector;
}
use of org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg in project statecharts by Yakindu.
the class EdgeLabelQuery method getVectorFromOldToNewForSegmentsOnSameLine.
private Optional<Vector> getVectorFromOldToNewForSegmentsOnSameLine(LineSeg oldRefSeg, Point oldRefPoint, Point oldCenterLabel) {
Optional<Vector> result = Optional.empty();
LineSeg newSegmentOnSameLineWithSameDirection = null;
LineSeg newSegmentOnSameLineWithOppositeDirection = null;
// Firstly, for points lists with same nb of segments, search if the
// vector, at
// the same index, is on the same line
int sameLineStatus = NOT_ON_SAME_LINE;
if (newEdgeSegments.size() == oldEdgeSegments.size()) {
LineSeg newSegAtSameIndex = newEdgeSegments.get(oldEdgeSegments.indexOf(oldRefSeg));
sameLineStatus = getSameLineStatus(oldRefSeg, newSegAtSameIndex);
if (ON_SAME_LINE_SAME_DIRECTION == sameLineStatus) {
newSegmentOnSameLineWithSameDirection = newSegAtSameIndex;
} else if (ON_SAME_LINE_OPPOSITE_DIRECTION == sameLineStatus) {
newSegmentOnSameLineWithOppositeDirection = newSegAtSameIndex;
}
}
if (NOT_ON_SAME_LINE == sameLineStatus) {
// If this is not the case search on all new segments.
for (LineSeg newSeg : newEdgeSegments) {
sameLineStatus = getSameLineStatus(oldRefSeg, newSeg);
if (ON_SAME_LINE_SAME_DIRECTION == sameLineStatus) {
newSegmentOnSameLineWithSameDirection = newSeg;
break;
} else if (ON_SAME_LINE_OPPOSITE_DIRECTION == sameLineStatus) {
newSegmentOnSameLineWithOppositeDirection = newSeg;
// Continue to search a potential segment in the same
// direction.
}
}
}
LineSeg newRefSeg = newSegmentOnSameLineWithSameDirection;
if (newRefSeg == null) {
newRefSeg = newSegmentOnSameLineWithOppositeDirection;
}
if (newRefSeg != null) {
result = Optional.of(applyOldRatioOnNewSegment(oldRefSeg, oldRefPoint, oldCenterLabel, newRefSeg, newSegmentOnSameLineWithOppositeDirection != null, true));
}
return result;
}
use of org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg in project statecharts by Yakindu.
the class EdgeLabelQuery method relativeCenterCoordinateFromOffset.
/**
* Calculates the relative coordinate that is equivalent to the offset from the
* reference point, that can be used to set the label center location. <BR>
*
* This is another implementation of
* {@link org.eclipse.gmf.runtime.diagram.ui.internal.figures.LabelHelper#relativeCoordinateFromOffset(org.eclipse.draw2d.IFigure, Point, Point)}
* . See bugzilla 476305 for more detail.
*
* @param points
* the <code>PointList</code> of the edge that contains the label.
* The label offset is relative to this <code>PointList</code>.
* @param ref
* a <code>Point</code> located on the parent which the offset value
* is relative to.
* @param offset
* a <code>Point</code> which represents a value offset from the
* <code>ref</code> point oriented based on the nearest line segment.
* @return a <code>Point</code> that is the relative coordinate of the label
* that can be used to set it's center location.
*/
public static Point relativeCenterCoordinateFromOffset(PointList points, Point ref, Point offset) {
Vector fromAnchorToLabelCenterPointVector = new Vector(offset.x, offset.y);
@SuppressWarnings("rawtypes") List lineSegments = PointListUtilities.getLineSegments(points);
LineSeg segmentContainingLabelAnchor = PointListUtilities.getNearestSegment(lineSegments, ref.x, ref.y);
Vector rotatedVector = getRotatedVector(fromAnchorToLabelCenterPointVector, segmentContainingLabelAnchor, true);
return new PrecisionPoint(ref.x + rotatedVector.x, ref.y + rotatedVector.y);
}
use of org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg in project statecharts by Yakindu.
the class EdgeLabelQuery method offsetFromRelativeCoordinate.
/**
* Calculates the label offset from the reference point given the label center
* and a points list.<BR>
* {@link org.eclipse.gmf.runtime.diagram.ui.internal.figures.LabelHelper#offsetFromRelativeCoordinate(org.eclipse.draw2d.IFigure, org.eclipse.draw2d.geometry.Rectangle, Point)}
*
* @param labelCenter
* the label center for the <code>IFigure</code> to calculate the
* offset for
* @param points
* the <code>PointList</code> of the edge that contains the label.
* The label offset is relative to this <code>PointList</code>.
* @param ref
* the <code>Point</code> that is the reference point that the offset
* is based on.
* @return a <code>Point</code> which represents a value offset from the
* <code>ref</code> point oriented based on the nearest line segment.
*/
public static Point offsetFromRelativeCoordinate(Point labelCenter, PointList points, Point ref) {
Vector fromAnchorToLabelCenterPointVector = new Vector(labelCenter.x - ref.x, labelCenter.y - ref.y);
@SuppressWarnings("rawtypes") List lineSegments = PointListUtilities.getLineSegments(points);
LineSeg segmentContainingLabelAnchor = PointListUtilities.getNearestSegment(lineSegments, ref.x, ref.y);
Vector rotatedVector = getRotatedVector(fromAnchorToLabelCenterPointVector, segmentContainingLabelAnchor, false);
return new PrecisionPoint(rotatedVector.x, rotatedVector.y);
}
Aggregations