private void markPoint(double x, double y, String label, Color fg, Color bg, GC gc) { gc.setForeground(black); gc.setBackground(bg); gc.fillOval((int) x - 3, (int) y - 3, 7, 7); gc.drawOval((int) x - 3, (int) y - 3, 6, 6); gc.setForeground(fg); gc.setBackground(white); if (y > 0) { gc.drawText(label, (int) x + 8, (int) y + 4, true); } else { gc.drawText(label, (int) x + 10, (int) y - 10, true); } }
/* * (non-Javadoc) * * @see sak.orbit.ui.AbstractOrbitAnimator#drawAdditionalObjects(int, int, * org.eclipse.swt.graphics.GC) */ @Override protected void drawAdditionalObjects(final int x0, final int y0, final GC gc) { final Point p1 = new Point(controller.getSxRelativeToEarth(), controller.getSyRelativeToEarth()); final Point p2 = new Point( controller.getSxRelativeToTargetSatellite(), controller.getSyRelativeToTargetSatellite()); final Point other = Utils.magGetOthersPosition(p1, p2); // the target satellite final int xAbsTarget = x0 + new Double(other.x / getCurrentScale()).intValue(); final int yAbsTarget = y0 + new Double(other.y / getCurrentScale()).intValue(); drawImage(gc, IMAGE_NAME_SPUTNIK, xAbsTarget, yAbsTarget, 0.5); if (showOrbit) { gc.setForeground(display.getSystemColor(SWT.COLOR_GRAY)); final double distance = Math.hypot(other.x, other.y); final int distRadius = new Double(distance / getCurrentScale()).intValue(); gc.drawOval(x0 - distRadius, y0 - distRadius, distRadius * 2, distRadius * 2); } }
public void drawOval(int x, int y, int width, int height) { _gc.drawOval(x, y, width, height); }
private void drawGraph(PaintEvent e) { GC gc = e.gc; Point size = canvasCurve.getSize(); int gridSize = 50 - sliderZoom.getSelection(); Color black = new Color(canvasCurve.getDisplay(), 0, 0, 0); Color grey = new Color(canvasCurve.getDisplay(), 235, 235, 235); // first, draw the grid gc.setForeground(grey); for (int i = 0; i < size.x / 2; i += gridSize) { gc.drawLine(size.x / 2 - i, 0, size.x / 2 - i, size.y); gc.drawLine(size.x / 2 + i, 0, size.x / 2 + i, size.y); } for (int i = 0; i < size.y / 2; i += gridSize) { gc.drawLine(0, size.y / 2 - i, size.x, size.y / 2 - i); gc.drawLine(0, size.y / 2 + i, size.x, size.y / 2 + i); } // Draw the axis gc.setForeground(black); // Black gc.drawLine(size.x / 2, 0, size.x / 2, size.y); gc.drawLine(0, size.y / 2, size.x, size.y / 2); int labeljumps = 5; int scale = (size.x / 2 / gridSize) - ((size.x / 2 / gridSize) % labeljumps); if (scale > 50) labeljumps = 10; for (int i = 0; i < size.x / 2; i += gridSize) { if ((i / gridSize) % labeljumps == 0) { gc.drawLine(size.x / 2 + i, size.y / 2 - 8, size.x / 2 + i, size.y / 2 + 8); gc.drawLine(size.x / 2 - i, size.y / 2 - 8, size.x / 2 - i, size.y / 2 + 8); gc.drawLine(size.x / 2 - 8, size.y / 2 + i, size.x / 2 + 8, size.y / 2 + i); gc.drawLine(size.x / 2 - 8, size.y / 2 - i, size.x / 2 + 8, size.y / 2 - i); int label = i / gridSize; if (label < 10) { if (label != 0) { gc.drawText(label + "", size.x / 2 + i - 2, size.y / 2 + 10, true); // $NON-NLS-1$ gc.drawText(-label + "", size.x / 2 - i - 5, size.y / 2 + 10, true); // $NON-NLS-1$ gc.drawText(label + "", size.x / 2 + 13, size.y / 2 - i - 7, true); // $NON-NLS-1$ gc.drawText(-label + "", size.x / 2 + 13, size.y / 2 + i - 7, true); // $NON-NLS-1$ } else { gc.drawText(label + "", size.x / 2 + i + 13, size.y / 2 + 10, true); // $NON-NLS-1$ } } else { gc.drawText(label + "", size.x / 2 + i - 6, size.y / 2 + 10, true); // $NON-NLS-1$ gc.drawText(-label + "", size.x / 2 - i - 10, size.y / 2 + 10, true); // $NON-NLS-1$ gc.drawText(label + "", size.x / 2 + 13, size.y / 2 - i - 7, true); // $NON-NLS-1$ gc.drawText(-label + "", size.x / 2 + 13, size.y / 2 + i - 7, true); // $NON-NLS-1$ } } else { gc.drawLine(size.x / 2 + i, size.y / 2 - 2, size.x / 2 + i, size.y / 2 + 2); gc.drawLine(size.x / 2 - i, size.y / 2 - 2, size.x / 2 - i, size.y / 2 + 2); gc.drawLine(size.x / 2 - 2, size.y / 2 + i, size.x / 2 + 2, size.y / 2 + i); gc.drawLine(size.x / 2 - 2, size.y / 2 - i, size.x / 2 + 2, size.y / 2 - i); } } if (points != null) { gc.setForeground(blue); double step = Math.pow((double) gridSize, -1); double x1, y1, x2, y2; for (int i = 2; i < points.length; i++) { if (points[i - 2].y == 0) { if (points[i - 1] != null && points[i - 1].y != 0) { x1 = (double) points[i - 2].x / 100 / step + size.x / 2; y1 = -(double) points[i - 2].y / 100 / step + size.y / 2; x2 = (double) points[i - 1].x / 100 / step + size.x / 2; y2 = -(double) points[i - 1].y / 100 / step + size.y / 2; gc.drawLine((int) x1, (int) y1, (int) x2, (int) y2); gc.drawLine((int) x1, (int) y1 + 1, (int) x2, (int) y2 + 1); x1 = (double) points[i - 2].x / 100 / step + size.x / 2; y1 = -(double) points[i - 2].y / 100 / step + size.y / 2; x2 = (double) points[i].x / 100 / step + size.x / 2; y2 = -(double) points[i].y / 100 / step + size.y / 2; gc.drawLine((int) x1, (int) y1, (int) x2, (int) y2); gc.drawLine((int) x1, (int) y1 + 1, (int) x2, (int) y2 + 1); } else { x1 = (double) points[i - 2].x / 100 / step + size.x / 2; y1 = -(double) points[i - 2].y / 100 / step + size.y / 2; x2 = (double) points[i - 3].x / 100 / step + size.x / 2; y2 = -(double) points[i - 3].y / 100 / step + size.y / 2; gc.drawLine((int) x1, (int) y1, (int) x2, (int) y2); gc.drawLine((int) x1, (int) y1 + 1, (int) x2, (int) y2 + 1); x1 = (double) points[i - 2].x / 100 / step + size.x / 2; y1 = -(double) points[i - 2].y / 100 / step + size.y / 2; x2 = (double) points[i - 4].x / 100 / step + size.x / 2; y2 = -(double) points[i - 4].y / 100 / step + size.y / 2; gc.drawLine((int) x1, (int) y1, (int) x2, (int) y2); gc.drawLine((int) x1, (int) y1 + 1, (int) x2, (int) y2 + 1); } } else { x1 = (double) points[i - 2].x / 100 / step + size.x / 2; y1 = -(double) points[i - 2].y / 100 / step + size.y / 2; x2 = (double) points[i].x / 100 / step + size.x / 2; y2 = -(double) points[i].y / 100 / step + size.y / 2; if ((int) Math.signum(points[i - 2].y + 0.0) == (int) Math.signum(points[i].y + 0.0)) { gc.drawLine((int) x1, (int) y1, (int) x2, (int) y2); gc.drawLine((int) x1, (int) y1 + 1, (int) x2, (int) y2 + 1); } } if (points[points.length - 1].y == 0) { x1 = (double) points[points.length - 1].x / 100 / step + size.x / 2; y1 = -(double) points[points.length - 1].y / 100 / step + size.y / 2; x2 = (double) points[points.length - 2].x / 100 / step + size.x / 2; y2 = -(double) points[points.length - 2].y / 100 / step + size.y / 2; gc.drawLine((int) x1, (int) y1, (int) x2, (int) y2); gc.drawLine((int) x1, (int) y1 + 1, (int) x2, (int) y2 + 1); x1 = (double) points[points.length - 1].x / 100 / step + size.x / 2; y1 = -(double) points[points.length - 1].y / 100 / step + size.y / 2; x2 = (double) points[points.length - 3].x / 100 / step + size.x / 2; y2 = -(double) points[points.length - 3].y / 100 / step + size.y / 2; gc.drawLine((int) x1, (int) y1, (int) x2, (int) y2); gc.drawLine((int) x1, (int) y1 + 1, (int) x2, (int) y2 + 1); } } if (pointR != null && !pointR.isInfinite()) { int rX; int rY; int lX; int lY; FpPoint p = pointP; FpPoint q = pointQ; FpPoint r = pointR; if (q != null) { if (p.x < q.x && p.x < r.x) { // if pointP is the most left point lX = (int) ((double) p.x / 100 / step + size.x / 2); lY = (int) ((double) -p.y / 100 / step + size.y / 2); } else if (q.x < r.x) { // if pointQ is the most left point lX = (int) ((double) q.x / 100 / step + size.x / 2); lY = (int) ((double) -q.y / 100 / step + size.y / 2); } else { // if pointR is the most left point lX = (int) ((double) r.x / 100 / step + size.x / 2); lY = (int) ((double) r.y / 100 / step + size.y / 2); } if (p.x > q.x && p.x > r.x) { // if pointP is the most right point rX = (int) ((double) p.x / 100 / step + size.x / 2); rY = (int) ((double) -p.y / 100 / step + size.y / 2); } else if (q.x > r.x) { // if pointQ is the most right point rX = (int) ((double) q.x / 100 / step + size.x / 2); rY = (int) ((double) -q.y / 100 / step + size.y / 2); } else { // if pointR is the most left point rX = (int) ((double) r.x / 100 / step + size.x / 2); rY = (int) ((double) r.y / 100 / step + size.y / 2); } } else { if (p.x < r.x) { // if pointP is the most left point lX = (int) ((double) p.x / 100 / step + size.x / 2); lY = (int) ((double) -p.y / 100 / step + size.y / 2); rX = (int) ((double) r.x / 100 / step + size.x / 2); rY = (int) ((double) r.y / 100 / step + size.y / 2); } else { // if pointR is the most left point lX = (int) ((double) r.x / 100 / step + size.x / 2); lY = (int) ((double) r.y / 100 / step + size.y / 2); rX = (int) ((double) p.x / 100 / step + size.x / 2); rY = (int) ((double) -p.y / 100 / step + size.y / 2); } } int startX; int endX; int startY; int endY; if ((rX > lX ? rX - lX : lX - rX) > (rY > lY ? rY - lY : lY - rY)) { double alfa = (double) (rY - lY) / (double) (rX - lX); startX = lX - 30; endX = rX + 30; startY = lY - (int) (alfa * 30); endY = rY + (int) (alfa * 30); } else { double alfa = (double) (rX - lX) / (double) (rY - lY); startX = lX + (lY > rY ? (int) (alfa * 30) : -(int) (alfa * 30)); endX = rX + (lY > rY ? -(int) (alfa * 30) : (int) (alfa * 30)); ; startY = lY + (lY > rY ? 30 : -30); endY = rY + (lY > rY ? -30 : 30); } if (startY < 0) { double alfa = (double) (rX - lX) / (double) (rY - lY); startX += (double) (-startY) * alfa; startY = 0; } else if (startY > size.y) { double alfa = (double) (rX - lX) / (double) (rY - lY); startX += -(double) (startY - size.y) * alfa; startY = size.y; } if (endY < 0) { double alfa = (double) (rX - lX) / (double) (rY - lY); endX += (double) (-endY - 1) * alfa; endY = -1; } else if (endY > size.y) { double alfa = (double) (rX - lX) / (double) (rY - lY); endX -= (double) (endY - size.y) * alfa + 0.5; endY = size.y; } gc.setForeground(darkPurple); gc.setLineWidth(2); gc.drawLine(startX, startY, endX, endY); startX = (int) ((double) pointR.x / 100 / step + size.x / 2); endX = startX; if (pointR.y > 0) { startY = (int) ((double) pointR.y / 100 / step + size.y / 2) + 30; endY = (int) ((double) -pointR.y / 100 / step + size.y / 2) - 30; } else { startY = (int) ((double) pointR.y / 100 / step + size.y / 2) - 30; endY = (int) ((double) -pointR.y / 100 / step + size.y / 2) + 30; } gc.setForeground(purple); gc.drawLine(startX, startY, endX, endY); gc.setLineWidth(1); double x = (double) pointR.x / 100 / step + size.x / 2; double y = (double) pointR.y / 100 / step + size.y / 2; gc.setForeground(black); gc.setBackground(darkPurple); gc.fillOval((int) x - 3, (int) y - 3, 7, 7); gc.drawOval((int) x - 3, (int) y - 3, 6, 6); gc.setForeground(darkPurple); gc.setBackground(white); if (y < size.x / 2) { gc.drawText("-R", (int) x + 8, (int) y + 4, true); // $NON-NLS-1$ } else { gc.drawText("-R", (int) x + 8, (int) y - 10, true); // $NON-NLS-1$ } } else if (pointP != null) { gc.setForeground(darkPurple); gc.setLineWidth(2); int x = (int) ((double) pointP.x / 100 / step + size.x / 2); gc.drawLine(x, 0, x, size.y); gc.setLineWidth(1); } if (pointSelect != null) { double x = (double) pointSelect.x / 100 / step + size.x / 2; double y = -(double) pointSelect.y / 100 / step + size.y / 2; String caption = "Q"; // $NON-NLS-1$ if (pointP == null) caption = "P"; // $NON-NLS-1$ markPoint(x, y, caption, black, lightBlue, gc); } if (pointP != null) { double x = (double) pointP.x / 100 / step + size.x / 2; double y = -(double) pointP.y / 100 / step + size.y / 2; String caption = "P"; // $NON-NLS-1$ if (pointP.equals(pointQ)) caption = "P=Q"; // $NON-NLS-1$ if (pointP.equals(pointR)) caption = "P=R"; // $NON-NLS-1$ markPoint(x, y, caption, red, red, gc); } if (pointQ != null && !pointQ.equals(pointP)) { double x = (double) pointQ.x / 100 / step + size.x / 2; double y = -(double) pointQ.y / 100 / step + size.y / 2; if (!pointQ.equals(pointP)) markPoint(x, y, "Q", red, red, gc); // $NON-NLS-1$ } if (pointR != null && !pointR.isInfinite()) { double x = (double) pointR.x / 100 / step + size.x / 2; double y = -(double) pointR.y / 100 / step + size.y / 2; markPoint(x, y, "R", purple, purple, gc); // $NON-NLS-1$ } } }