Search in sources :

Example 31 with PointList

use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.

the class PointsUtil method scalePointsBySize.

/**
 *Scale the bound size of a point list.
 * @param points the points to be scaled.
 * @param width the new width.
 * @param height the new height
 * @return the points after scaled. If no scale is needed, return the input points.
 */
public static PointList scalePointsBySize(final PointList points, final int width, final int height) {
    int targetW = Math.max(1, width);
    int targetH = Math.max(1, height);
    double oldW = points.getBounds().width;
    double oldH = points.getBounds().height;
    double topLeftX = points.getBounds().x;
    double topLeftY = points.getBounds().y;
    if (oldW != targetW || oldH != targetH) {
        PointList newPoints = new PointList();
        for (int i = 0; i < points.size(); i++) {
            int x = points.getPoint(i).x;
            int y = points.getPoint(i).y;
            Point newPoint = new Point(x, y);
            if (oldW > 0 && oldH > 0) {
                double oldRelX = (x - topLeftX) / oldW;
                double oldRelY = (y - topLeftY) / oldH;
                double newX = topLeftX + (oldRelX * targetW);
                double newY = topLeftY + (oldRelY * targetH);
                int roundedX = (int) Math.round(newX);
                int roundedY = (int) Math.round(newY);
                newPoint = new Point(roundedX, roundedY);
            }
            newPoints.addPoint(newPoint);
        }
        return newPoints;
    }
    return points;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 32 with PointList

use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.

the class PointsUtil method rotatePoints.

/**
 * Rotates all points.
 *
 * @param points The PoinList, which points should be rotated
 * @param angle
 *            The angle to rotate
 * @return The rotated PointList
 */
public static final PointList rotatePoints(final PointList points, final double angle) {
    Rectangle pointBounds = points.getBounds();
    Point rotationPoint = pointBounds.getCenter();
    PointList newPoints = rotatePoints(points, angle, rotationPoint);
    Rectangle newPointBounds = newPoints.getBounds();
    if (!rotationPoint.equals(newPointBounds.getCenter())) {
        Dimension difference = rotationPoint.getCopy().getDifference(newPointBounds.getCenter());
        newPoints.translate(difference.width, difference.height);
    }
    return newPoints;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 33 with PointList

use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.

the class WidgetCreateCommand method execute.

@Override
public void execute() {
    oldBounds = newWidget.getBounds();
    generateNewWUID(newWidget);
    // If the new created widget has connections on it, remove their points.
    for (ConnectionModel conn : newWidget.getSourceConnections()) {
        conn.setPoints(new PointList());
    }
    redo();
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel)

Example 34 with PointList

use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.

the class AbstractPolyEditPart method registerPropertyChangeHandlers.

/**
 * {@inheritDoc}
 */
@Override
protected void registerPropertyChangeHandlers() {
    super.registerPropertyChangeHandlers();
    // points
    IWidgetPropertyChangeHandler pointsHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            Polyline polyline = (Polyline) refreshableFigure;
            PointList points = (PointList) newValue;
            if (points.size() != polyline.getPoints().size()) {
                anchorMap = null;
                // delete connections on deleted points
                if (points.size() < polyline.getPoints().size()) {
                    for (ConnectionModel conn : getWidgetModel().getSourceConnections()) {
                        if (Integer.parseInt(conn.getSourceTerminal()) >= points.size()) {
                            conn.disconnect();
                        }
                    }
                    for (ConnectionModel conn : getWidgetModel().getTargetConnections()) {
                        if (Integer.parseInt(conn.getTargetTerminal()) >= points.size()) {
                            conn.disconnect();
                        }
                    }
                }
            }
            // deselect the widget (this refreshes the polypoint drag
            // handles)
            int selectionState = getSelected();
            setSelected(EditPart.SELECTED_NONE);
            polyline.setPoints(points);
            doRefreshVisuals(polyline);
            // restore the selection state
            setSelected(selectionState);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPolyModel.PROP_POINTS, pointsHandler);
    IWidgetPropertyChangeHandler rotationHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            getWidgetModel().setPoints(PointsUtil.rotatePoints(getWidgetModel().getOriginalPoints().getCopy(), (Double) newValue), false);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPolyModel.PROP_ROTATION, rotationHandler);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) Polyline(org.eclipse.draw2d.Polyline) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) IFigure(org.eclipse.draw2d.IFigure)

Example 35 with PointList

use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.

the class GeometryUtil method getChildrenRange.

/**
 *Get the range of children widgets.
 * @param container editpart of the container widget.
 * @return the range (minX, minY, maxX-minX, maxY-minY) relative to the container.
 */
public static Rectangle getChildrenRange(AbstractContainerEditpart container) {
    PointList pointList = new PointList(container.getChildren().size());
    for (Object child : container.getChildren()) {
        AbstractWidgetModel childModel = ((AbstractBaseEditPart) child).getWidgetModel();
        pointList.addPoint(childModel.getLocation());
        pointList.addPoint(childModel.getX() + childModel.getWidth(), childModel.getY() + childModel.getHeight());
    }
    return pointList.getBounds();
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart)

Aggregations

PointList (org.eclipse.draw2d.geometry.PointList)80 Point (org.eclipse.draw2d.geometry.Point)49 Rectangle (org.eclipse.draw2d.geometry.Rectangle)15 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)10 ArrayList (java.util.ArrayList)9 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)8 Polyline (org.eclipse.draw2d.Polyline)7 List (java.util.List)6 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)6 AbstractPolyModel (org.csstudio.opibuilder.widgets.model.AbstractPolyModel)5 Dimension (org.eclipse.draw2d.geometry.Dimension)5 Bendpoint (org.eclipse.draw2d.Bendpoint)4 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)4 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)3 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)3 PolarPoint (org.csstudio.swt.widgets.figureparts.PolarPoint)3 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 ConnectionReconnectCommand (org.csstudio.opibuilder.commands.ConnectionReconnectCommand)2