Skip to content
Snippets Groups Projects
Commit f29e3c81 authored by Vincent Aravantinos's avatar Vincent Aravantinos
Browse files

Temptative fix

refs 2021
parent 9348296c
No related branches found
No related tags found
No related merge requests found
......@@ -27,14 +27,15 @@ import static org.fortiss.tooling.base.ui.utils.LayoutDataUtils.setConnectorOffs
import static org.fortiss.tooling.base.ui.utils.RectangleLayoutUtils.calculateRectangleBorderOrientation;
import static org.fortiss.tooling.base.ui.utils.RectangleLayoutUtils.clampRectangularShapeSize;
import static org.fortiss.tooling.base.ui.utils.SnapToGridUtils.snapToGrid;
import static org.fortiss.tooling.base.ui.utils.ZoomUtils.determineZoom;
import static org.fortiss.tooling.base.ui.utils.ZoomUtils.internalToScreenPoint;
import static org.fortiss.tooling.base.ui.utils.ZoomUtils.screenToInternalPoint;
import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createDimension;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Viewport;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.editparts.ScalableRootEditPart;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.OffsetOrientation;
......@@ -52,7 +53,7 @@ import org.fortiss.tooling.base.ui.editpart.StickyConnectorEditPartBase;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 0CE64ACB8F262EFB9BCA06665C7E4AA7
* @ConQAT.Rating YELLOW Hash: 554E256E48502ACEF16407FF74D3D28B
*/
public class RectangleGridLayoutDiagramConfiguration extends DiagramLayoutConfigurationBase {
......@@ -100,27 +101,22 @@ public class RectangleGridLayoutDiagramConfiguration extends DiagramLayoutConfig
public void alterStickyConnectorMoveFeedbackRequest(ChangeBoundsRequest request,
StickyConnectorEditPartBase<? extends ILayoutedModelElement> connectorEditPart,
IFigure connectorFigure) {
double zoom = determineZoom(connectorEditPart.getRoot());
Point moveDelta = screenToInternalPoint(request.getMoveDelta(), zoom);
// get the bounds of the parent
Rectangle containerBounds = getContainerBounds(connectorEditPart);
// get the child position relative to the parent
Point childPos =
connectorFigure.getBounds().getLocation()
.getTranslated(containerBounds.getLocation().getNegated());
// get the current mouse position
Point mousePos = request.getLocation();
// fix offset in mouse position because of possibly scrolled editing
// window
Point clientAreaOffset =
new Point(((Viewport)((ScalableRootEditPart)connectorEditPart.getParentEditPart()
.getRoot()).getFigure()).getClientArea().getLocation());
mousePos.translate(clientAreaOffset);
// get the mouse position relative to the parent
Point relativePos = mousePos.getTranslated(containerBounds.getLocation().getNegated());
Point relativePos = childPos.getTranslated(moveDelta);
// do border clamping
OffsetOrientation orient =
calculateRectangleBorderOrientation(relativePos, containerBounds.getSize(),
DEFAULT_SHAPE_INSETS);
// snap to grid
orient.setOffset(snapToGrid(orient.getOffset()));
// use the calculated value for positioning
......@@ -136,7 +132,7 @@ public class RectangleGridLayoutDiagramConfiguration extends DiagramLayoutConfig
// MoveDelta needs positions relative to the child
relativePos.translate(childPos.getNegated());
request.setMoveDelta(relativePos);
request.setMoveDelta(internalToScreenPoint(relativePos, zoom));
}
/**
......
......@@ -17,6 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.utils;
import static java.lang.Math.min;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_CONNECTOR_SIZE;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_INSETS;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_MINIMUM_HEIGHT;
......@@ -34,8 +35,6 @@ import static org.fortiss.tooling.base.ui.utils.LayoutDataUtils.setNodePosition;
import static org.fortiss.tooling.base.ui.utils.SnapToGridUtils.snapToGrid;
import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createOffsetOrientation;
import java.awt.Polygon;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
......@@ -52,7 +51,7 @@ import org.fortiss.tooling.base.ui.dnd.gef.ElementDropContext;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 4AC211E8ED3669B184AEB530916A8A5C
* @ConQAT.Rating YELLOW Hash: 118735F6573C95F19DDFBB5B6CFAE4A1
*/
public class RectangleLayoutUtils {
......@@ -76,34 +75,24 @@ public class RectangleLayoutUtils {
// The figure bounds
Rectangle bounds = new Rectangle(0, 0, rectangleSize.width, rectangleSize.height);
// Divide the rectangle into four diagonal sectors
Polygon northSector =
new Polygon(new int[] {bounds.getCenter().x, bounds.x, bounds.width}, new int[] {
bounds.getCenter().y, bounds.y, bounds.y}, 3);
Polygon eastSector =
new Polygon(new int[] {bounds.getCenter().x, bounds.width, bounds.width},
new int[] {bounds.getCenter().y, bounds.y, bounds.height}, 3);
Polygon southSector =
new Polygon(new int[] {bounds.getCenter().x, bounds.width, bounds.x}, new int[] {
bounds.getCenter().y, bounds.height, bounds.height}, 3);
Polygon westSector =
new Polygon(new int[] {bounds.getCenter().x, bounds.x, bounds.x}, new int[] {
bounds.getCenter().y, bounds.height, bounds.y}, 3);
int distanceToNorth = source.y;
int distanceToSouth = bounds.height - source.y;
int distanceToWest = source.x;
int distanceToEast = bounds.width - source.x;
int minDistance =
min(min(min(distanceToEast, distanceToNorth), distanceToWest), distanceToSouth);
// Determine in which sector we are and clamp the position accordingly
if(northSector.contains(source.x, source.y)) {
if(minDistance == distanceToNorth) {
orientation = NORTH;
offset = (int)(source.x * (1 - (2 * inset) / (double)bounds.width));
}
if(westSector.contains(source.x, source.y)) {
} else if(minDistance == distanceToWest) {
orientation = WEST;
offset = (int)(source.y * (1 - (2 * inset) / (double)bounds.height));
}
if(southSector.contains(source.x, source.y)) {
} else if(minDistance == distanceToSouth) {
orientation = SOUTH;
offset = (int)(source.x * (1 - (2 * inset) / (double)bounds.width));
}
if(eastSector.contains(source.x, source.y)) {
} else {
orientation = EAST;
offset = (int)(source.y * (1 - (2 * inset) / (double)bounds.height));
}
......
......@@ -17,6 +17,8 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.utils;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.RootEditPart;
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
import org.eclipse.gef.editparts.ScalableRootEditPart;
......@@ -28,7 +30,7 @@ import org.eclipse.gef.requests.ChangeBoundsRequest;
* @author hummel
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 57E5F4C587CD015E3B85AC0666F7BA44
* @ConQAT.Rating YELLOW Hash: 7629EF7289BEE454E9279494EB3A7413
*/
public class ZoomUtils {
......@@ -51,7 +53,39 @@ public class ZoomUtils {
if(zoom <= 0 || zoom == 1) {
return;
}
request.getMoveDelta().scale(1 / zoom);
request.getSizeDelta().scale(1 / zoom);
request.setMoveDelta(screenToInternalPoint(request.getMoveDelta(), zoom));
request.setSizeDelta(screenToInternalDimension(request.getSizeDelta(), zoom));
}
/**
* Converts a point expressed in screen coordinates, into a point in internal coordinates,
* taking the zoom into account.
*/
public static Point screenToInternalPoint(Point pos, double zoom) {
return pos.scale(1 / zoom);
}
/**
* Converts a point expressed in internal coordinates, into a point in screen coordinates,
* taking the zoom into account.
*/
public static Point internalToScreenPoint(Point pos, double zoom) {
return pos.scale(zoom);
}
/**
* Converts a point expressed in screen coordinates, into a point in internal coordinates,
* taking the zoom into account.
*/
public static Dimension screenToInternalDimension(Dimension dim, double zoom) {
return dim.scale(1 / zoom);
}
/**
* Converts a point expressed in internal coordinates, into a point in screen coordinates,
* taking the zoom into account.
*/
public static Dimension internalToScreenDimension(Dimension dim, double zoom) {
return dim.scale(zoom);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment