mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
allow curve shape control points to overlap
This commit is contained in:
+5
@@ -35,6 +35,11 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canControlPointOverlap(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
+6
@@ -107,6 +107,12 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.WHEN_SELECTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canControlPointOverlap(int index) {
|
||||
// Only shape control points may overlap.
|
||||
return index == 1 || index == 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
|
||||
+15
-2
@@ -80,9 +80,22 @@ public interface IDIYComponent<T> extends Serializable {
|
||||
* @param index
|
||||
*/
|
||||
void setControlPoint(Point point, int index);
|
||||
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @return true, if the specified control point may stick to control points
|
||||
* of other components.
|
||||
*/
|
||||
boolean isControlPointSticky(int index);
|
||||
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @return true, if the specified control point may overlap with other
|
||||
* control points <b>of the same component</b>. The other control
|
||||
* point must be able to overlap too.
|
||||
*/
|
||||
boolean canControlPointOverlap(int index);
|
||||
|
||||
VisibilityPolicy getControlPointVisibilityPolicy(int index);
|
||||
|
||||
/**
|
||||
|
||||
+40
-40
@@ -480,11 +480,6 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
}
|
||||
// // If CTRL is pressed, we only care about the top most
|
||||
// component.
|
||||
// if (altDown && components.size() > 0) {
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,7 +655,6 @@ public class Presenter implements IPlugInPort {
|
||||
return false;
|
||||
}
|
||||
Point scaledPoint = scalePoint(point);
|
||||
boolean repaint = false;
|
||||
if (!controlPointMap.isEmpty()) {
|
||||
// We're dragging control point(s).
|
||||
int dx = (scaledPoint.x - previousDragPoint.x);
|
||||
@@ -670,24 +664,46 @@ public class Presenter implements IPlugInPort {
|
||||
int actualDx = 0;
|
||||
int actualDy = 0;
|
||||
|
||||
// Do a simulation of the move to see if any of them will
|
||||
// collide.
|
||||
// For each component, do a simulation of the move to see if any of
|
||||
// them will
|
||||
// overlap.
|
||||
boolean isFirst = true;
|
||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||
IDIYComponent<?> c = entry.getKey();
|
||||
Point[] controlPoints = new Point[c.getControlPointCount()];
|
||||
for (int i = 0; i < controlPoints.length; i++) {
|
||||
controlPoints[i] = new Point(c.getControlPoint(i));
|
||||
if (entry.getValue().contains(i)) {
|
||||
controlPoints[i].translate(dx, dy);
|
||||
if (snapToGrid) {
|
||||
CalcUtils.snapPointToGrid(controlPoints[i], currentProject
|
||||
.getGridSpacing());
|
||||
IDIYComponent<?> component = entry.getKey();
|
||||
Point[] controlPoints = new Point[component.getControlPointCount()];
|
||||
for (int index = 0; index < component.getControlPointCount(); index++) {
|
||||
controlPoints[index] = new Point(component.getControlPoint(index));
|
||||
// When the first point is moved, calculate how much it
|
||||
// actually moved after snapping.
|
||||
if (entry.getValue().contains(index)) {
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
controlPoints[index].translate(dx, dy);
|
||||
if (snapToGrid) {
|
||||
CalcUtils.snapPointToGrid(controlPoints[index], currentProject
|
||||
.getGridSpacing());
|
||||
}
|
||||
actualDx = controlPoints[index].x - component.getControlPoint(index).x;
|
||||
actualDy = controlPoints[index].y - component.getControlPoint(index).y;
|
||||
if (actualDx == 0 && actualDy == 0) {
|
||||
// Nothing to move.
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
controlPoints[index].translate(actualDx, actualDy);
|
||||
}
|
||||
}
|
||||
// For control points that may overlap, just write null,
|
||||
// we'll ignore them later.
|
||||
if (component.canControlPointOverlap(index)) {
|
||||
controlPoints[index] = null;
|
||||
}
|
||||
}
|
||||
System.out.println(Arrays.deepToString(controlPoints));
|
||||
for (int i = 0; i < controlPoints.length - 1; i++) {
|
||||
for (int j = i + 1; j < controlPoints.length; j++) {
|
||||
if (controlPoints[i].equals(controlPoints[j])) {
|
||||
if (controlPoints[i] != null && controlPoints[j] != null
|
||||
&& controlPoints[i].equals(controlPoints[j])) {
|
||||
LOG.error("Control points collision detected, cannot make this move.");
|
||||
return true;
|
||||
}
|
||||
@@ -696,32 +712,16 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
// Update all points.
|
||||
boolean isFirst = true;
|
||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||
IDIYComponent<?> c = entry.getKey();
|
||||
drawingManager.invalidateComponent(c);
|
||||
for (Integer index : entry.getValue()) {
|
||||
Point p = new Point(c.getControlPoint(index));
|
||||
// When the first point is moved, calculate how much it
|
||||
// actually moved after snapping.
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
p.translate(dx, dy);
|
||||
if (snapToGrid) {
|
||||
CalcUtils.snapPointToGrid(p, currentProject.getGridSpacing());
|
||||
}
|
||||
actualDx = p.x - c.getControlPoint(index).x;
|
||||
actualDy = p.y - c.getControlPoint(index).y;
|
||||
} else {
|
||||
p.translate(actualDx, actualDy);
|
||||
}
|
||||
p.translate(actualDx, actualDy);
|
||||
c.setControlPoint(p, index);
|
||||
}
|
||||
}
|
||||
if (actualDx != 0 || actualDy != 0) {
|
||||
previousDragPoint.translate(actualDx, actualDy);
|
||||
repaint = true;
|
||||
}
|
||||
previousDragPoint.translate(actualDx, actualDy);
|
||||
} else if (selectedComponents.isEmpty()
|
||||
&& instantiationManager.getComponentTypeSlot() == null) {
|
||||
// If there's no selection, the only thing to do is update the
|
||||
@@ -729,13 +729,13 @@ public class Presenter implements IPlugInPort {
|
||||
Rectangle oldSelectionRect = selectionRect == null ? null
|
||||
: new Rectangle(selectionRect);
|
||||
this.selectionRect = Utils.createRectangle(scaledPoint, previousDragPoint);
|
||||
repaint = !selectionRect.equals(oldSelectionRect);
|
||||
if (selectionRect.equals(oldSelectionRect)) {
|
||||
return true;
|
||||
}
|
||||
// messageDispatcher.dispatchMessage(EventType.SELECTION_RECT_CHANGED,
|
||||
// selectionRect);
|
||||
}
|
||||
if (repaint) {
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -45,6 +45,11 @@ public class MockDIYComponent implements IDIYComponent<Capacitance> {
|
||||
public MockDIYComponent() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canControlPointOverlap(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getName() {
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user