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 ...@@ -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.calculateRectangleBorderOrientation;
import static org.fortiss.tooling.base.ui.utils.RectangleLayoutUtils.clampRectangularShapeSize; 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.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 static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createDimension;
import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Viewport;
import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.editparts.ScalableRootEditPart;
import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement; import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.OffsetOrientation; import org.fortiss.tooling.base.model.layout.OffsetOrientation;
...@@ -52,7 +53,7 @@ import org.fortiss.tooling.base.ui.editpart.StickyConnectorEditPartBase; ...@@ -52,7 +53,7 @@ import org.fortiss.tooling.base.ui.editpart.StickyConnectorEditPartBase;
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating GREEN Hash: 0CE64ACB8F262EFB9BCA06665C7E4AA7 * @ConQAT.Rating YELLOW Hash: 554E256E48502ACEF16407FF74D3D28B
*/ */
public class RectangleGridLayoutDiagramConfiguration extends DiagramLayoutConfigurationBase { public class RectangleGridLayoutDiagramConfiguration extends DiagramLayoutConfigurationBase {
...@@ -100,27 +101,22 @@ public class RectangleGridLayoutDiagramConfiguration extends DiagramLayoutConfig ...@@ -100,27 +101,22 @@ public class RectangleGridLayoutDiagramConfiguration extends DiagramLayoutConfig
public void alterStickyConnectorMoveFeedbackRequest(ChangeBoundsRequest request, public void alterStickyConnectorMoveFeedbackRequest(ChangeBoundsRequest request,
StickyConnectorEditPartBase<? extends ILayoutedModelElement> connectorEditPart, StickyConnectorEditPartBase<? extends ILayoutedModelElement> connectorEditPart,
IFigure connectorFigure) { IFigure connectorFigure) {
double zoom = determineZoom(connectorEditPart.getRoot());
Point moveDelta = screenToInternalPoint(request.getMoveDelta(), zoom);
// get the bounds of the parent // get the bounds of the parent
Rectangle containerBounds = getContainerBounds(connectorEditPart); Rectangle containerBounds = getContainerBounds(connectorEditPart);
// get the child position relative to the parent // get the child position relative to the parent
Point childPos = Point childPos =
connectorFigure.getBounds().getLocation() connectorFigure.getBounds().getLocation()
.getTranslated(containerBounds.getLocation().getNegated()); .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 // do border clamping
OffsetOrientation orient = OffsetOrientation orient =
calculateRectangleBorderOrientation(relativePos, containerBounds.getSize(), calculateRectangleBorderOrientation(relativePos, containerBounds.getSize(),
DEFAULT_SHAPE_INSETS); DEFAULT_SHAPE_INSETS);
// snap to grid // snap to grid
orient.setOffset(snapToGrid(orient.getOffset())); orient.setOffset(snapToGrid(orient.getOffset()));
// use the calculated value for positioning // use the calculated value for positioning
...@@ -136,7 +132,7 @@ public class RectangleGridLayoutDiagramConfiguration extends DiagramLayoutConfig ...@@ -136,7 +132,7 @@ public class RectangleGridLayoutDiagramConfiguration extends DiagramLayoutConfig
// MoveDelta needs positions relative to the child // MoveDelta needs positions relative to the child
relativePos.translate(childPos.getNegated()); relativePos.translate(childPos.getNegated());
request.setMoveDelta(relativePos); request.setMoveDelta(internalToScreenPoint(relativePos, zoom));
} }
/** /**
......
...@@ -17,6 +17,7 @@ $Id$ ...@@ -17,6 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.utils; 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_CONNECTOR_SIZE;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_INSETS; import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_INSETS;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_MINIMUM_HEIGHT; 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; ...@@ -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.ui.utils.SnapToGridUtils.snapToGrid;
import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createOffsetOrientation; import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createOffsetOrientation;
import java.awt.Polygon;
import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.draw2d.geometry.Rectangle;
...@@ -52,7 +51,7 @@ import org.fortiss.tooling.base.ui.dnd.gef.ElementDropContext; ...@@ -52,7 +51,7 @@ import org.fortiss.tooling.base.ui.dnd.gef.ElementDropContext;
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating GREEN Hash: 4AC211E8ED3669B184AEB530916A8A5C * @ConQAT.Rating YELLOW Hash: 118735F6573C95F19DDFBB5B6CFAE4A1
*/ */
public class RectangleLayoutUtils { public class RectangleLayoutUtils {
...@@ -76,34 +75,24 @@ public class RectangleLayoutUtils { ...@@ -76,34 +75,24 @@ public class RectangleLayoutUtils {
// The figure bounds // The figure bounds
Rectangle bounds = new Rectangle(0, 0, rectangleSize.width, rectangleSize.height); Rectangle bounds = new Rectangle(0, 0, rectangleSize.width, rectangleSize.height);
// Divide the rectangle into four diagonal sectors int distanceToNorth = source.y;
Polygon northSector = int distanceToSouth = bounds.height - source.y;
new Polygon(new int[] {bounds.getCenter().x, bounds.x, bounds.width}, new int[] { int distanceToWest = source.x;
bounds.getCenter().y, bounds.y, bounds.y}, 3); int distanceToEast = bounds.width - source.x;
Polygon eastSector = int minDistance =
new Polygon(new int[] {bounds.getCenter().x, bounds.width, bounds.width}, min(min(min(distanceToEast, distanceToNorth), distanceToWest), distanceToSouth);
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);
// Determine in which sector we are and clamp the position accordingly // Determine in which sector we are and clamp the position accordingly
if(northSector.contains(source.x, source.y)) { if(minDistance == distanceToNorth) {
orientation = NORTH; orientation = NORTH;
offset = (int)(source.x * (1 - (2 * inset) / (double)bounds.width)); offset = (int)(source.x * (1 - (2 * inset) / (double)bounds.width));
} } else if(minDistance == distanceToWest) {
if(westSector.contains(source.x, source.y)) {
orientation = WEST; orientation = WEST;
offset = (int)(source.y * (1 - (2 * inset) / (double)bounds.height)); offset = (int)(source.y * (1 - (2 * inset) / (double)bounds.height));
} } else if(minDistance == distanceToSouth) {
if(southSector.contains(source.x, source.y)) {
orientation = SOUTH; orientation = SOUTH;
offset = (int)(source.x * (1 - (2 * inset) / (double)bounds.width)); offset = (int)(source.x * (1 - (2 * inset) / (double)bounds.width));
} } else {
if(eastSector.contains(source.x, source.y)) {
orientation = EAST; orientation = EAST;
offset = (int)(source.y * (1 - (2 * inset) / (double)bounds.height)); offset = (int)(source.y * (1 - (2 * inset) / (double)bounds.height));
} }
......
...@@ -17,6 +17,8 @@ $Id$ ...@@ -17,6 +17,8 @@ $Id$
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.utils; 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.RootEditPart;
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
import org.eclipse.gef.editparts.ScalableRootEditPart; import org.eclipse.gef.editparts.ScalableRootEditPart;
...@@ -28,7 +30,7 @@ import org.eclipse.gef.requests.ChangeBoundsRequest; ...@@ -28,7 +30,7 @@ import org.eclipse.gef.requests.ChangeBoundsRequest;
* @author hummel * @author hummel
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating GREEN Hash: 57E5F4C587CD015E3B85AC0666F7BA44 * @ConQAT.Rating YELLOW Hash: 7629EF7289BEE454E9279494EB3A7413
*/ */
public class ZoomUtils { public class ZoomUtils {
...@@ -51,7 +53,39 @@ public class ZoomUtils { ...@@ -51,7 +53,39 @@ public class ZoomUtils {
if(zoom <= 0 || zoom == 1) { if(zoom <= 0 || zoom == 1) {
return; return;
} }
request.getMoveDelta().scale(1 / zoom); request.setMoveDelta(screenToInternalPoint(request.getMoveDelta(), zoom));
request.getSizeDelta().scale(1 / 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