Skip to content
Snippets Groups Projects
Commit add4d922 authored by Tiziano Munaro's avatar Tiziano Munaro
Browse files

Update visuals of Bezier curves while dragging bend points

parent bea3430f
No related branches found
No related tags found
1 merge request!88[3873] Ellipses and Bezier curves
......@@ -6,7 +6,7 @@ EObjectRectangularResizableContentControllerBase.java 787a540213f29e8daaecd9afe9
KernelServiceBasedModelChangeProviderBase.java 18e48f17ea8dfba90de024a8959fc5a4b0d05d45 GREEN
LayoutModelChangeProvider.java b5449d02eaf39086909720c43e21bd061005fc9e GREEN
LayoutedContentAnchorageController.java 3794b41d76e9ce14ead0bd812cde5c1a6d348d5c GREEN
LayoutedCurveLinkBendPointController.java c426c300e6147a1ed0394e2f75f57a3b1061f959 RED
LayoutedCurveLinkBendPointController.java e47215864706953fac8e7059376d5898684f1816 RED
LayoutedDiagramAnchorageController.java 1e1ac7c5fa26c632736f5023e90f05d09bc0710d GREEN
LayoutedEllipticResizableContentController.java b2c9c48190b9ff69a175bbe5f89761c1b08621ab YELLOW
LayoutedLineLinkBendPointController.java e2dac36334191c39d54b4f95fa8482a6392ce82c RED
......
......@@ -17,6 +17,7 @@ package org.fortiss.tooling.base.ui.editor.fx.controller;
import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;
import static org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.FeedbackChange.locationFeedbackChange;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.addConnectionPoint;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getConnectionPoints;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.removeConnectionPoint;
......@@ -28,15 +29,19 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramCoordinate;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewer;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerFeatures;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.FeedbackChange;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.IController;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.controller.base.LinkControllerBase;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.IModelChangeProvider;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.ILinkVisual;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.Point;
import org.fortiss.tooling.kernel.service.IConnectionCompositorService;
import javafx.geometry.Point2D;
/**
* {@link IController} for {@link ILayoutedModelElement}s representing curved links and connections
* in a {@link DiagramViewer}.
......@@ -120,31 +125,54 @@ public class LayoutedCurveLinkBendPointController<T extends ILayoutedModelElemen
/** {@inheritDoc} */
@Override
protected void updateModelAfterBendPointMove(int bpIndex, double dx, double dy) {
movePoint(bpIndex, dx, dy);
if(bpIndex % 3 == 2) {
movePoint(bpIndex - 1, dx, dy);
movePoint(bpIndex + 1, dx, dy);
} else if(bpIndex > 0 && bpIndex < getBendPointList(getModelElement()).size() - 1) {
if(bpIndex % 3 == 1) {
movePoint(bpIndex + 2, -dx, -dy);
} else {
movePoint(bpIndex - 2, -dx, -dy);
}
protected final void moveBendPointVisually(int bpIndex, Point2D delta) {
super.moveBendPointVisually(bpIndex, delta);
if(bpIndex <= 0 || bpIndex >= getNumerOfBendPoints() - 1) {
// first and last bend-point move unconnected
return;
}
ILinkVisual linkVisual = getLinkVisual();
FeedbackChange centerPointChange = getMoveDeltaFeedback(bpIndex, delta);
int indexMod3 = bpIndex % 3;
if(indexMod3 == 2) {
// bend-points between curve segments also drag the previous and next point
linkVisual.setFeedbackChangeForBendPoint(bpIndex - 1, centerPointChange);
linkVisual.setFeedbackChangeForBendPoint(bpIndex + 1, centerPointChange);
} else {
// otherwise the connected bend-point is moved in the opposite direction
FeedbackChange inv = locationFeedbackChange(-centerPointChange.getDeltaX(),
-centerPointChange.getDeltaY());
int otherIndex = (indexMod3 == 1) ? bpIndex + 2 : bpIndex - 2;
linkVisual.setFeedbackChangeForBendPoint(otherIndex, inv);
}
// linkVisual.update();
return;
}
/** Updates the coordinates of a point. */
private void movePoint(int bpIndex, double dx, double dy) {
List<Point> oldPoints = getBendPointList(getModelElement());
Point point = oldPoints.get(bpIndex);
int oldX = point.getX();
int oldY = point.getY();
int newX = oldX + (int)dx;
int newY = oldY + (int)dy;
point.setX(newX);
point.setY(newY);
/** {@inheritDoc} */
@Override
protected final void moveBendPointInModel(int bpIndex, Point2D delta) {
FeedbackChange chg = getMoveDeltaFeedback(bpIndex, delta);
getLinkVisual().setFeedbackChangeForBendPoint(bpIndex, null);
updateModelAfterBendPointMove(bpIndex, chg.getDeltaX(), chg.getDeltaY());
if(bpIndex <= 0 || bpIndex >= getNumerOfBendPoints() - 1) {
// first and last bend-point move unconnected
return;
}
ILinkVisual linkVisual = getLinkVisual();
int indexMod3 = bpIndex % 3;
if(indexMod3 == 2) {
// bend-points between curve segments also drag the previous and next point
linkVisual.setFeedbackChangeForBendPoint(bpIndex - 1, null);
updateModelAfterBendPointMove(bpIndex - 1, chg.getDeltaX(), chg.getDeltaY());
linkVisual.setFeedbackChangeForBendPoint(bpIndex + 1, null);
updateModelAfterBendPointMove(bpIndex + 1, chg.getDeltaX(), chg.getDeltaY());
} else {
// otherwise the connected bend-point is moved in the opposite direction
int otherIndex = (indexMod3 == 1) ? bpIndex + 2 : bpIndex - 2;
linkVisual.setFeedbackChangeForBendPoint(otherIndex, null);
updateModelAfterBendPointMove(otherIndex, -chg.getDeltaX(), -chg.getDeltaY());
}
}
/** {@inheritDoc} */
......@@ -171,4 +199,17 @@ public class LayoutedCurveLinkBendPointController<T extends ILayoutedModelElemen
public void delete() {
deleteLink();
}
/** {@inheritDoc} */
@Override
protected void updateModelAfterBendPointMove(int bpIndex, double dx, double dy) {
List<Point> oldPoints = getBendPointList(getModelElement());
Point point = oldPoints.get(bpIndex);
int oldX = point.getX();
int oldY = point.getY();
int newX = oldX + (int)dx;
int newY = oldY + (int)dy;
point.setX(newX);
point.setY(newY);
}
}
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