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