Search in sources :

Example 1 with IDiagramModelObject

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

the class ReconnectDiagramConnectionCommand method createBendPointsCommand.

/**
 * Adding a circular connection requires some bendpoints
 */
protected Command createBendPointsCommand() {
    // Only works for IDiagramModelObject as source and target objects not for connections
    if (!(fConnection.getSource() instanceof IDiagramModelObject) && !(fConnection.getTarget() instanceof IDiagramModelObject)) {
        return null;
    }
    IDiagramModelObject source = (IDiagramModelObject) fConnection.getSource();
    IDiagramModelObject target = (IDiagramModelObject) fConnection.getTarget();
    int width = source.getBounds().getWidth();
    if (width == -1) {
        width = 100;
    }
    int height = target.getBounds().getHeight();
    if (height == -1) {
        height = 60;
    }
    width = (int) Math.max(100, width * 0.6);
    height = (int) Math.max(60, height * 0.6);
    CompoundCommand result = new CompoundCommand();
    CreateBendpointCommand cmd = new CreateBendpointCommand();
    cmd.setDiagramModelConnection(fConnection);
    cmd.setRelativeDimensions(new Dimension(width, 0), new Dimension(width, 0));
    result.add(cmd);
    cmd = new CreateBendpointCommand();
    cmd.setDiagramModelConnection(fConnection);
    cmd.setRelativeDimensions(new Dimension(width, height), new Dimension(width, height));
    result.add(cmd);
    cmd = new CreateBendpointCommand();
    cmd.setDiagramModelConnection(fConnection);
    cmd.setRelativeDimensions(new Dimension(0, height), new Dimension(0, height));
    result.add(cmd);
    return result;
}
Also used : IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Dimension(org.eclipse.draw2d.geometry.Dimension) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 2 with IDiagramModelObject

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

the class AbstractBaseEditPart method refreshBounds.

/**
 * Refresh the Bounds
 */
protected void refreshBounds() {
    /*
         * We need to set the bounds in the LayoutManager.
         * Tells the parent part that this part and its figure are to be constrained to the given rectangle.
         */
    GraphicalEditPart parentEditPart = (GraphicalEditPart) getParent();
    IDiagramModelObject object = getModel();
    Rectangle bounds = new Rectangle(object.getBounds().getX(), object.getBounds().getY(), object.getBounds().getWidth(), object.getBounds().getHeight());
    if (parentEditPart.getFigure().getLayoutManager() instanceof XYLayout) {
        parentEditPart.setLayoutConstraint(this, getFigure(), bounds);
    } else // Content Pane Figure needs laying out
    if (parentEditPart.getContentPane().getLayoutManager() instanceof XYLayout) {
        parentEditPart.getContentPane().setConstraint(getFigure(), bounds);
    }
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) XYLayout(org.eclipse.draw2d.XYLayout) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart)

Example 3 with IDiagramModelObject

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

the class CreateMapViewCheatSheetActionTests method testNewMapViewCommand.

@Test
public void testNewMapViewCommand() throws IOException {
    // Load ArchiMate model
    ArchimateTestModel tm = new ArchimateTestModel(TestData.TEST_MODEL_FILE_ARCHISURANCE);
    IArchimateModel model = tm.loadModel();
    // Has 17 diagrams
    assertEquals(17, model.getDiagramModels().size());
    NewMapViewCommand cmd = new NewMapViewCommand(model);
    cmd.execute();
    assertNotNull(cmd.diagramModel);
    assertNotNull(cmd.diagramModel.eContainer());
    // Model now has 18 diagrams
    assertEquals(18, model.getDiagramModels().size());
    // New diagram has 17 children...
    assertEquals(17, cmd.diagramModel.getChildren().size());
    // ...all of which are IDiagramModelReference types with IDs
    for (IDiagramModelObject dmo : cmd.diagramModel.getChildren()) {
        assertTrue(dmo instanceof IDiagramModelReference);
        assertNotNull(dmo.getId());
    }
    // Undo
    cmd.undo();
    assertEquals(17, model.getDiagramModels().size());
    assertNull(cmd.diagramModel.eContainer());
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) NewMapViewCommand(com.archimatetool.help.cheatsheets.CreateMapViewCheatSheetAction.NewMapViewCommand) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Example 4 with IDiagramModelObject

use of com.archimatetool.model.IDiagramModelObject 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 5 with IDiagramModelObject

use of com.archimatetool.model.IDiagramModelObject 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)

Aggregations

IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)51 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)12 IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)12 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)10 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)10 Test (org.junit.Test)10 IArchimateElement (com.archimatetool.model.IArchimateElement)9 Dimension (org.eclipse.draw2d.geometry.Dimension)9 IDiagramModel (com.archimatetool.model.IDiagramModel)8 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)7 IBounds (com.archimatetool.model.IBounds)6 Command (org.eclipse.gef.commands.Command)6 ILockable (com.archimatetool.model.ILockable)5 ArrayList (java.util.ArrayList)5 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)4 EObject (org.eclipse.emf.ecore.EObject)4 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)4 IArchimateModel (com.archimatetool.model.IArchimateModel)3 IDiagramModelGroup (com.archimatetool.model.IDiagramModelGroup)3 ILineObject (com.archimatetool.model.ILineObject)3