Search in sources :

Example 1 with IBounds

use of com.archimatetool.model.IBounds in project archi by archimatetool.

the class DiagramModelObjectTests method testGetBounds.

@Test
public void testGetBounds() {
    assertNull(object.getBounds());
    IBounds bounds = IArchimateFactory.eINSTANCE.createBounds();
    object.setBounds(bounds);
    assertSame(bounds, object.getBounds());
}
Also used : IBounds(com.archimatetool.model.IBounds) Test(org.junit.Test)

Example 2 with IBounds

use of com.archimatetool.model.IBounds in project archi by archimatetool.

the class FixDefaultSizesHandler method getDefaultSize.

Dimension getDefaultSize(IDiagramModelObject dmo) {
    IBounds bounds = dmo.getBounds();
    if (bounds.getWidth() != -1 && bounds.getHeight() != -1) {
        return new Dimension(bounds.getWidth(), bounds.getHeight());
    }
    // Legacy size of ArchiMate figure
    if (dmo instanceof IDiagramModelArchimateObject) {
        if (!(((IDiagramModelArchimateObject) dmo).getArchimateElement() instanceof IJunction)) {
            return new Dimension(120, 55);
        }
    }
    IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider) ObjectUIFactory.INSTANCE.getProvider(dmo);
    return provider != null ? provider.getUserDefaultSize() : new Dimension(120, 55);
}
Also used : IBounds(com.archimatetool.model.IBounds) IGraphicalObjectUIProvider(com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider) Dimension(org.eclipse.draw2d.geometry.Dimension) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IJunction(com.archimatetool.model.IJunction)

Example 3 with IBounds

use of com.archimatetool.model.IBounds in project archi by archimatetool.

the class FixDefaultSizesHandler method fixMissingWidthAndHeight.

/**
 * Fix missing width and height values
 */
void fixMissingWidthAndHeight(IArchimateModel model) {
    for (Iterator<EObject> iter = model.eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        // However, here, Images with -1, -1 would be converted to a default box size of 200, 150. So ignore it.
        if (eObject instanceof IDiagramModelImage) {
            continue;
        }
        if (eObject instanceof IDiagramModelObject) {
            IDiagramModelObject dmo = (IDiagramModelObject) eObject;
            Dimension d = getNewSize(dmo);
            IBounds bounds = dmo.getBounds();
            bounds.setWidth(d.width);
            bounds.setHeight(d.height);
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IBounds(com.archimatetool.model.IBounds) IDiagramModelImage(com.archimatetool.model.IDiagramModelImage) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 4 with IBounds

use of com.archimatetool.model.IBounds in project archi by archimatetool.

the class FixDefaultSizesHandler method getNewSize.

/**
 * Get a new size for a diagram object if width or height are not set
 * Child figures will affect the size.
 */
Dimension getNewSize(IDiagramModelObject dmo) {
    IBounds bounds = dmo.getBounds().getCopy();
    if (bounds.getWidth() != -1 && bounds.getHeight() != -1) {
        return new Dimension(bounds.getWidth(), bounds.getHeight());
    }
    // Calculate default size based on children
    if (dmo instanceof IDiagramModelContainer && ((IDiagramModelContainer) dmo).getChildren().size() > 0) {
        IDiagramModelContainer container = (IDiagramModelContainer) dmo;
        // Start with zero and build up from that...
        Dimension childrenSize = new Dimension();
        for (IDiagramModelObject child : container.getChildren()) {
            IBounds childbounds = child.getBounds().getCopy();
            Dimension size = getNewSize(child);
            childrenSize.width = Math.max(childbounds.getX() + size.width() + 10, childrenSize.width);
            childrenSize.height = Math.max(childbounds.getY() + size.height() + 10, childrenSize.height);
        }
        Dimension defaultSize = getDefaultSize(dmo);
        Dimension newSize = childrenSize.union(defaultSize);
        return newSize;
    }
    // No children...
    return getDefaultSize(dmo);
}
Also used : IBounds(com.archimatetool.model.IBounds) Dimension(org.eclipse.draw2d.geometry.Dimension) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 5 with IBounds

use of com.archimatetool.model.IBounds 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 DiagramImageEditPart) {
            DiagramImageEditPart part = (DiagramImageEditPart) object;
            IDiagramModelObject model = part.getModel();
            // Locked
            if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                continue;
            }
            IBounds modelBounds = model.getBounds().getCopy();
            int currentHeight = modelBounds.getHeight();
            int currentWidth = modelBounds.getWidth();
            // Already set to default height and width
            if (currentHeight == -1 && currentWidth == -1) {
                continue;
            }
            // Get original default size
            DiagramImageFigure figure = part.getFigure();
            Dimension size = figure.getDefaultSize();
            if (size.height == 0 || size.width == 0) {
                continue;
            }
            float originalRatio = ((float) size.height / (float) size.width);
            float currentRatio = ((float) currentHeight / (float) currentWidth);
            // If the ratio is different within tolerance
            if (Math.abs(originalRatio - currentRatio) > 0.01) {
                int width = currentWidth;
                int height = currentHeight;
                if (currentWidth < currentHeight) {
                    width = (int) (currentHeight / originalRatio);
                } else {
                    height = (int) (currentWidth * originalRatio);
                }
                modelBounds.setWidth(width);
                modelBounds.setHeight(height);
                Command cmd = new SetConstraintObjectCommand(model, modelBounds);
                result.add(cmd);
            }
        }
    }
    return result.unwrap();
}
Also used : SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) DiagramImageFigure(com.archimatetool.editor.diagram.figures.diagram.DiagramImageFigure) SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) IBounds(com.archimatetool.model.IBounds) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) DiagramImageEditPart(com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Dimension(org.eclipse.draw2d.geometry.Dimension) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ILockable(com.archimatetool.model.ILockable)

Aggregations

IBounds (com.archimatetool.model.IBounds)13 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)6 Dimension (org.eclipse.draw2d.geometry.Dimension)6 Test (org.junit.Test)4 SetConstraintObjectCommand (com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand)2 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)2 IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)2 IDiagramModelImage (com.archimatetool.model.IDiagramModelImage)2 ILockable (com.archimatetool.model.ILockable)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 DiagramImageEditPart (com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart)1 IDiagramModelObjectFigure (com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure)1 DiagramImageFigure (com.archimatetool.editor.diagram.figures.diagram.DiagramImageFigure)1 IGraphicalObjectUIProvider (com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider)1 IArchimateElement (com.archimatetool.model.IArchimateElement)1 IDiagramModel (com.archimatetool.model.IDiagramModel)1 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)1 IJunction (com.archimatetool.model.IJunction)1 File (java.io.File)1