use of com.archimatetool.editor.diagram.figures.PolarPoint in project archi by archimatetool.
the class RoundedPolylineConnection method addSegment.
@SuppressWarnings({ "rawtypes" })
private void addSegment(Graphics g, Point start, Point end, ArrayList connections, PointList linepoints) {
// List of crossing points
ArrayList<Point> crosspoints = new ArrayList<Point>();
//
int radius = (int) JUMP_MAX_RADIUS;
// Add start point to the list
linepoints.addPoint(start);
// If line-jumps are enabled, draw them using half circles
if (ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.USE_LINE_JUMPS)) {
// Compute angle between line segment and horizontal line
PolarPoint end_p = new PolarPoint(start, end);
double angle = end_p.theta % Math.PI;
boolean reverse = (end_p.theta != angle);
// If yes, add it to the list
for (Iterator I = connections.iterator(); I.hasNext(); ) {
RoundedPolylineConnection conn = (RoundedPolylineConnection) I.next();
PointList bendpoints = conn.getPoints();
// Iterate on connection segments
for (int j = 0; j < bendpoints.size() - 1; j++) {
Point bp = bendpoints.getPoint(j);
Point next = bendpoints.getPoint(j + 1);
Point crosspoint = lineIntersect(start, end, bp, next);
// Check if crossing point found and not too close from ends
if (crosspoint != null && (new PolarPoint(crosspoint, start)).r > JUMP_MAX_RADIUS && (new PolarPoint(crosspoint, end)).r > JUMP_MAX_RADIUS && (new PolarPoint(crosspoint, bp)).r > JUMP_MAX_RADIUS && (new PolarPoint(crosspoint, next)).r > JUMP_MAX_RADIUS) {
double con_angle = ((new PolarPoint(bp, next)).theta % Math.PI);
if (angle > con_angle && !crosspoints.contains(crosspoint))
crosspoints.add(crosspoint);
}
}
}
// If crossing points found, render them using a half circle
if (crosspoints.size() != 0) {
// Sort crosspoints from start to end
crosspoints.add(start);
Collections.sort(crosspoints, new PointCompare());
if (crosspoints.get(0) != start)
Collections.reverse(crosspoints);
// Do not add start point to the list a second time, so start at i=1
for (int i = 1; i < crosspoints.size(); i++) {
for (double a = 0; a <= MAX_ITER; a++) {
if (reverse)
linepoints.addPoint((new PolarPoint(radius, angle - a * Math.PI / MAX_ITER)).toAbsolutePoint(crosspoints.get(i)));
else
linepoints.addPoint((new PolarPoint(radius, angle - Math.PI + a * Math.PI / MAX_ITER)).toAbsolutePoint(crosspoints.get(i)));
}
}
}
}
// Add end point to the list
linepoints.addPoint(end);
}
use of com.archimatetool.editor.diagram.figures.PolarPoint in project archi by archimatetool.
the class RoundedPolylineConnection method outlineShape.
@Override
@SuppressWarnings("rawtypes")
protected void outlineShape(Graphics g) {
// Original list of bendpoints
PointList bendpoints = getPoints();
// List of bendpoints and points added to draw line-curves and line-jumps
PointList linepoints = new PointList();
// List of all connections on current diagram
ArrayList connections = getAllConnections();
if (bendpoints.size() == 0) {
return;
}
// Start point is the first "previous" point
Point prev = bendpoints.getPoint(0);
// Main loop: check all bendpoints and add curve is needed
for (int i = 1; i < bendpoints.size(); i++) {
// Current bendpoint
Point bp = bendpoints.getPoint(i);
// and then draw polyline
if (i == bendpoints.size() - 1) {
addSegment(g, prev, bp, connections, linepoints);
continue;
}
// Next bendpoint
Point next = bendpoints.getPoint(i + 1);
// If line-curves are enabled draw bendpoints using ellipse approximation
if (ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.USE_LINE_CURVES)) {
// Switch to polar coordinates
PolarPoint prev_p = new PolarPoint(bp, prev);
PolarPoint next_p = new PolarPoint(bp, next);
// Compute arc angle between source and target
// and be sure that arc angle is positive and less than PI
double arc = next_p.theta - prev_p.theta;
arc = (arc + PI2) % (PI2);
// Do we have to go from previous to next or the opposite
boolean prev2next = arc < Math.PI ? true : false;
arc = prev2next ? arc : PI2 - arc;
// Check bendpoint radius against source and target
double bp_radius = CURVE_MAX_RADIUS;
bp_radius = Math.min(bp_radius, prev_p.r / 2.0);
bp_radius = Math.min(bp_radius, next_p.r / 2.0);
// Find center of bendpoint arc
PolarPoint center_p = new PolarPoint(bp_radius, (prev2next ? prev_p.theta : next_p.theta) + arc / 2.0);
Point center = center_p.toAbsolutePoint(bp);
// Compute source and target of bendpoint arc
double arc_radius = bp_radius * Math.sin(arc / 2.0);
double start_angle = (Math.PI + arc) / 2.0 + center_p.theta;
double full_angle = Math.PI - arc;
Point bpprev;
Point bpnext;
if (!prev2next) {
bpprev = new PolarPoint(arc_radius, start_angle).toAbsolutePoint(center);
bpnext = new PolarPoint(arc_radius, start_angle + full_angle).toAbsolutePoint(center);
} else {
bpprev = new PolarPoint(arc_radius, start_angle + full_angle).toAbsolutePoint(center);
bpnext = new PolarPoint(arc_radius, start_angle).toAbsolutePoint(center);
}
// Now that bendpoint position has been refined we can add line segment
addSegment(g, prev, bpprev, connections, linepoints);
// Create circle approximation
for (double a = 1; a < MAX_ITER; a++) {
if (prev2next)
linepoints.addPoint(new PolarPoint(arc_radius, start_angle + full_angle * (1 - a / MAX_ITER)).toAbsolutePoint(center));
else
linepoints.addPoint(new PolarPoint(arc_radius, start_angle + full_angle * a / MAX_ITER).toAbsolutePoint(center));
}
// Prepare next iteration
prev = bpnext;
} else {
// Add line segment
addSegment(g, prev, bp, connections, linepoints);
// Prepare next iteration
prev = bp;
}
}
// Finally draw the polyLine
g.drawPolyline(linepoints);
}
use of com.archimatetool.editor.diagram.figures.PolarPoint in project archi by archimatetool.
the class EquipmentFigure method drawIconCog.
/**
* Draw a Cog with choosen number of "segments"
*/
private void drawIconCog(Graphics graphics, Point center, int segments, int r1, int r2, int r3) {
// Draw outer Cog
PointList outer = new PointList();
final double halfSeg = Math.PI / (2 * segments);
final double delta = halfSeg / 4;
for (int i = 0; i < segments; i++) {
outer.addPoint(new PolarPoint(r2, 2 * Math.PI * i / segments - halfSeg).toAbsolutePoint(center));
outer.addPoint(new PolarPoint(r3, 2 * Math.PI * i / segments - halfSeg + delta).toAbsolutePoint(center));
outer.addPoint(new PolarPoint(r3, 2 * Math.PI * i / segments + halfSeg - delta).toAbsolutePoint(center));
outer.addPoint(new PolarPoint(r2, 2 * Math.PI * i / segments + halfSeg).toAbsolutePoint(center));
}
graphics.drawPolygon(outer);
// Draw inner circle
Path path = new Path(null);
path.addArc(center.x - r1, center.y - r1, 2 * r1, 2 * r1, 0, 360);
graphics.drawPath(path);
path.dispose();
}
use of com.archimatetool.editor.diagram.figures.PolarPoint in project archi by archimatetool.
the class EquipmentFigure method drawCog.
/**
* Draw a Cog with choosen number of "segments"
*/
protected void drawCog(Graphics graphics, Point center, int segments, int r1, int r2, int r3) {
// Draw outer Cog
PointList outer = new PointList();
final double halfSeg = Math.PI / (2 * segments);
final double delta = halfSeg / 4;
for (int i = 0; i < segments; i++) {
outer.addPoint(new PolarPoint(r2, 2 * Math.PI * i / segments - halfSeg).toAbsolutePoint(center));
outer.addPoint(new PolarPoint(r3, 2 * Math.PI * i / segments - halfSeg + delta).toAbsolutePoint(center));
outer.addPoint(new PolarPoint(r3, 2 * Math.PI * i / segments + halfSeg - delta).toAbsolutePoint(center));
outer.addPoint(new PolarPoint(r2, 2 * Math.PI * i / segments + halfSeg).toAbsolutePoint(center));
}
graphics.drawPolygon(outer);
// Draw inner circle
Path path = new Path(null);
path.addArc(center.x - r1, center.y - r1, 2 * r1, 2 * r1, 0, 360);
graphics.drawPath(path);
path.dispose();
}
Aggregations