Search in sources :

Example 1 with AbstractDiagramModelObjectFigure

use of com.archimatetool.editor.diagram.figures.AbstractDiagramModelObjectFigure in project archi by archimatetool.

the class ResetAspectRatioAction method createCommand.

private Command createCommand(List<?> objects) {
    CompoundCommand result = new CompoundCommand();
    for (Object object : objects) {
        if (object instanceof AbstractConnectedEditPart) {
            AbstractConnectedEditPart editPart = (AbstractConnectedEditPart) object;
            AbstractDiagramModelObjectFigure figure = (AbstractDiagramModelObjectFigure) editPart.getFigure();
            IDiagramModelObject dmo = editPart.getModel();
            // Diagram Image object with image or Iconic type with image and Fill setting
            if (!isDiagramObjectWithImage(dmo) && !isIconicWithImageFill(dmo, figure)) {
                continue;
            }
            // Locked
            if (dmo instanceof ILockable && ((ILockable) dmo).isLocked()) {
                continue;
            }
            IBounds modelBounds = dmo.getBounds().getCopy();
            int currentHeight = modelBounds.getHeight();
            int currentWidth = modelBounds.getWidth();
            // Sanity check
            if (currentHeight < 1 || currentWidth < 1) {
                continue;
            }
            float currentRatio = ((float) currentHeight / (float) currentWidth);
            float otherRatio = 0;
            // Image object type
            if (dmo instanceof IDiagramModelImage) {
                // This will return the image's proper size (unsized) if there is an image, else the object's size
                Dimension size = figure.getDefaultSize();
                if (size.height == 0 || size.width == 0) {
                    continue;
                }
                otherRatio = ((float) size.height / (float) size.width);
            } else // Iconic and fill type is fill and has an image
            {
                Rectangle imageBounds = figure.getIconicDelegate().getImage().getBounds();
                otherRatio = ((float) imageBounds.height / (float) imageBounds.width);
            }
            // If the ratio is different (within tolerance)
            if (otherRatio != 0 && Math.abs(otherRatio - currentRatio) > 0.01) {
                if (currentWidth < currentHeight) {
                    currentWidth = (int) (currentHeight / otherRatio);
                } else {
                    currentHeight = (int) (currentWidth * otherRatio);
                }
                modelBounds.setWidth(currentWidth);
                modelBounds.setHeight(currentHeight);
                Command cmd = new SetConstraintObjectCommand(dmo, modelBounds);
                result.add(cmd);
            }
        }
    }
    return result.unwrap();
}
Also used : AbstractDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.AbstractDiagramModelObjectFigure) AbstractConnectedEditPart(com.archimatetool.editor.diagram.editparts.AbstractConnectedEditPart) IBounds(com.archimatetool.model.IBounds) Rectangle(org.eclipse.swt.graphics.Rectangle) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Dimension(org.eclipse.draw2d.geometry.Dimension) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) IDiagramModelImage(com.archimatetool.model.IDiagramModelImage) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) ILockable(com.archimatetool.model.ILockable)

Example 2 with AbstractDiagramModelObjectFigure

use of com.archimatetool.editor.diagram.figures.AbstractDiagramModelObjectFigure in project archi by archimatetool.

the class RoundedRectangleAnchor method getLocation.

/**
 * Calculates the position with ChopboxAnchor#getLocation() and if the
 * anchor is not at the rounded corners, the result is returned. If the
 * anchor point should be at a corner, the rectangle for the ellipse is
 * determined and ellipseAnchorGetLocation returns the two intersection
 * points between the line from calculated anchor point and the center of
 * the rounded rectangle.
 *
 * @return The anchor location
 */
@Override
public Point getLocation(final Point ref) {
    Dimension corner = new Dimension(0, 0);
    if (getOwner() instanceof IRoundedRectangleFigure) {
        corner = ((IRoundedRectangleFigure) getOwner()).getArc();
    } else if (getOwner() instanceof RoundedRectangle) {
        corner = ((RoundedRectangle) getOwner()).getCornerDimensions();
    } else if (getOwner() instanceof AbstractDiagramModelObjectFigure) {
        IFigureDelegate figureDelegate = ((AbstractDiagramModelObjectFigure) getOwner()).getFigureDelegate();
        if (figureDelegate instanceof IRoundedRectangleFigure) {
            corner = ((IRoundedRectangleFigure) figureDelegate).getArc();
        }
    }
    corner = corner.scale(FigureUtils.getFigureScale(getOwner()));
    final Point location = super.getLocation(ref);
    final Rectangle r = Rectangle.SINGLETON;
    r.setBounds(getOwner().getBounds());
    r.translate(-1, -1);
    r.resize(1, 1);
    getOwner().translateToAbsolute(r);
    final int yTop = r.y + corner.height / 2;
    final int yBottom = r.y + r.height - corner.height / 2;
    final int xLeft = r.x + corner.width / 2;
    final int xRight = r.x + r.width - corner.width / 2;
    int pos = 0;
    if (location.x < xLeft) {
        pos = LEFT;
    } else if (location.x > xRight) {
        pos = RIGHT;
    } else {
        pos = MIDDLE;
    }
    if (location.y < yTop) {
        pos |= TOP;
    } else if (location.y > yBottom) {
        pos |= BOTTOM;
    } else {
        pos += CENTER;
    }
    switch(pos) {
        case TOP | MIDDLE:
        case CENTER | LEFT:
        case CENTER | RIGHT:
        case BOTTOM | MIDDLE:
            return new Point(location.x, location.y);
        case TOP | LEFT:
            return ellipseAnchorGetLocation(location, new Rectangle(r.x, r.y, corner.width, corner.height), // getOwner().getBounds().getCenter() // Jaiguru fix
            r.getCenter())[0];
        case TOP | RIGHT:
            return ellipseAnchorGetLocation(location, new Rectangle(r.x + r.width - corner.width, r.y, corner.width, corner.height), // getOwner().getBounds().getCenter() // Jaiguru fix
            r.getCenter())[1];
        case CENTER | MIDDLE:
            // default for reference inside Figure
            return new Point(r.x, r.y + r.height / 2);
        case BOTTOM | LEFT:
            return ellipseAnchorGetLocation(location, new Rectangle(r.x, r.y + r.height - corner.height, corner.width, corner.height), // getOwner().getBounds().getCenter() // Jaiguru fix
            r.getCenter())[0];
        case BOTTOM | RIGHT:
            return ellipseAnchorGetLocation(location, new Rectangle(r.x + r.width - corner.width, r.y + r.height - corner.height, corner.width, corner.height), // getOwner().getBounds().getCenter() // Jaiguru fix
            r.getCenter())[1];
        default:
            throw new IllegalStateException(// $NON-NLS-1$
            "Calculation of RoundedRectangleAnchor missed. Rect: " + r + " Point: " + // $NON-NLS-1$
            location);
    }
}
Also used : AbstractDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.AbstractDiagramModelObjectFigure) IFigureDelegate(com.archimatetool.editor.diagram.figures.IFigureDelegate) IRoundedRectangleFigure(com.archimatetool.editor.diagram.figures.IRoundedRectangleFigure) Rectangle(org.eclipse.draw2d.geometry.Rectangle) RoundedRectangle(org.eclipse.draw2d.RoundedRectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) RoundedRectangle(org.eclipse.draw2d.RoundedRectangle)

Example 3 with AbstractDiagramModelObjectFigure

use of com.archimatetool.editor.diagram.figures.AbstractDiagramModelObjectFigure in project archi by archimatetool.

the class DefaultEditPartSizeAction method createDefaultSizeCommand.

private Command createDefaultSizeCommand(List<?> objects) {
    CompoundCommand command = new CompoundCommand();
    for (Object object : objects) {
        if (object instanceof AbstractConnectedEditPart) {
            AbstractConnectedEditPart editPart = (AbstractConnectedEditPart) object;
            IDiagramModelObject model = editPart.getModel();
            // Locked
            if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                continue;
            }
            AbstractDiagramModelObjectFigure figure = (AbstractDiagramModelObjectFigure) editPart.getFigure();
            IBounds bounds = model.getBounds().getCopy();
            // If the object has an icon image and set to image fill and isn't a container with childrem
            if (model instanceof IIconic && ((IIconic) model).getImagePosition() == IIconic.ICON_POSITION_FILL && figure.hasIconImage() && !(model instanceof IDiagramModelContainer && !((IDiagramModelContainer) model).getChildren().isEmpty())) {
                Rectangle imageBounds = figure.getIconicDelegate().getImage().getBounds();
                bounds.setWidth(imageBounds.width);
                bounds.setHeight(imageBounds.height);
            } else {
                Dimension defaultSize = ((IDiagramModelObjectFigure) figure).getDefaultSize();
                bounds.setWidth(defaultSize.width);
                bounds.setHeight(defaultSize.height);
            }
            if (bounds.getWidth() != model.getBounds().getWidth() || bounds.getHeight() != model.getBounds().getHeight()) {
                Command cmd = new SetConstraintObjectCommand(model, bounds);
                command.add(cmd);
            }
        }
    }
    return command.unwrap();
}
Also used : IIconic(com.archimatetool.model.IIconic) AbstractDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.AbstractDiagramModelObjectFigure) AbstractConnectedEditPart(com.archimatetool.editor.diagram.editparts.AbstractConnectedEditPart) IBounds(com.archimatetool.model.IBounds) Rectangle(org.eclipse.swt.graphics.Rectangle) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Dimension(org.eclipse.draw2d.geometry.Dimension) IDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) ILockable(com.archimatetool.model.ILockable)

Aggregations

AbstractDiagramModelObjectFigure (com.archimatetool.editor.diagram.figures.AbstractDiagramModelObjectFigure)3 Dimension (org.eclipse.draw2d.geometry.Dimension)3 SetConstraintObjectCommand (com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand)2 AbstractConnectedEditPart (com.archimatetool.editor.diagram.editparts.AbstractConnectedEditPart)2 IBounds (com.archimatetool.model.IBounds)2 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)2 ILockable (com.archimatetool.model.ILockable)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 IDiagramModelObjectFigure (com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure)1 IFigureDelegate (com.archimatetool.editor.diagram.figures.IFigureDelegate)1 IRoundedRectangleFigure (com.archimatetool.editor.diagram.figures.IRoundedRectangleFigure)1 IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)1 IDiagramModelImage (com.archimatetool.model.IDiagramModelImage)1 IIconic (com.archimatetool.model.IIconic)1 RoundedRectangle (org.eclipse.draw2d.RoundedRectangle)1 Point (org.eclipse.draw2d.geometry.Point)1 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1