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;
}
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);
}
}
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());
}
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);
}
}
}
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);
}
Aggregations