Spliting multiple points

This commit is contained in:
Jindra Petřík
2022-12-31 20:32:21 +01:00
parent 88a77d448d
commit f0bc22f6de
3 changed files with 76 additions and 89 deletions

View File

@@ -281,8 +281,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
private List<Integer> pointsUnderCursor = new ArrayList<>();
private List<Integer> selectedPoints = new ArrayList<>();
private Integer pathPointUnderCursor = null;
private Double pathPointPosition = null;
private List<DistanceItem> pathPointsUnderCursor = new ArrayList<>();
private DisplayPoint closestPoint = null;
@@ -336,18 +335,18 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
}
}
private boolean fireEdgeSplit(List<DisplayPoint> points, int position, double splitPoint) {
private boolean fireEdgeSplit(int position, double splitPoint) {
boolean result = true;
for (PointUpdateListener listener : pointUpdateListeners) {
result = result && listener.edgeSplit(points, position, splitPoint);
result = result && listener.edgeSplit(position, splitPoint);
}
return result;
}
private boolean firePointRemoved(List<DisplayPoint> points, int position) {
private boolean firePointRemoved(int position) {
boolean result = true;
for (PointUpdateListener listener : pointUpdateListeners) {
result = result && listener.pointRemoved(points, position);
result = result && listener.pointRemoved(position);
}
return result;
}
@@ -1028,7 +1027,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
}
});
for (int i : selectedPointsDesc) {
firePointRemoved(hilightedPoints, i);
firePointRemoved(i);
}
selectedPoints.clear();
repaint();
@@ -1156,12 +1155,20 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
calculatePointsXY();
}
if (ctrlDown && pathPointUnderCursor != null) {
fireEdgeSplit(hilightedPoints, pathPointUnderCursor, pathPointPosition);
if (ctrlDown && !pathPointsUnderCursor.isEmpty()) {
/*List<Integer> positions = new ArrayList<>();
List<Double> splitPositions = new ArrayList<>();
for(DistanceItem di:pathPointsUnderCursor) {
positions.add(di.pathPoint);
splitPositions.add(di.pathPosition);
}*/
for (DistanceItem di:pathPointsUnderCursor) {
fireEdgeSplit(di.pathPoint, di.pathPosition);
}
selectedPoints.clear();
pointsUnderCursor.clear();
pathPointUnderCursor = null;
pathPointPosition = 0.0;
pathPointsUnderCursor.clear();
repaint();
}
updateScrollBarMinMax();
@@ -1732,23 +1739,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
repaint();
}
}
}
class DistanceItem {
public double distance;
public int pathPoint;
public double pathPosition;
public DisplayPoint closestPoint;
public DistanceItem(double distance, int pathPoint, double pathPosition, DisplayPoint closestPoint) {
this.distance = distance;
this.pathPoint = pathPoint;
this.pathPosition = pathPosition;
this.closestPoint = closestPoint;
}
}
}
@Override
public void mouseMoved(MouseEvent e) {
@@ -1833,11 +1824,11 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
distanceList.sort(new Comparator<DistanceItem>() {
@Override
public int compare(DistanceItem o1, DistanceItem o2) {
return Double.compare(o1.distance, o2.distance);
return o2.pathPoint - o1.pathPoint; //Double.compare(o1.distance, o2.distance);
}
});
if (dragStart == null) {
if (!distanceList.isEmpty()) {
/*if (!distanceList.isEmpty()) {
DistanceItem di = distanceList.get(0);
pathPointUnderCursor = di.pathPoint;
pathPointPosition = di.pathPosition;
@@ -1846,7 +1837,8 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
pathPointUnderCursor = null;
pathPointPosition = null;
closestPoint = null;
}
}*/
pathPointsUnderCursor = distanceList;
pointsUnderCursor = newPointsUnderCursor;
}
return;
@@ -3426,7 +3418,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
Cursor newCursor;
if (!pointsUnderCursor.isEmpty()) {
newCursor = movePointCursor;
} else if (pathPointUnderCursor != null) {
} else if (!pathPointsUnderCursor.isEmpty()) {
if (iconPanel.isCtrlDown()) {
newCursor = addPointCursor;
} else {
@@ -3970,3 +3962,20 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
return null;
}
}
class DistanceItem {
public double distance;
public int pathPoint;
public double pathPosition;
public DisplayPoint closestPoint;
public DistanceItem(double distance, int pathPoint, double pathPosition, DisplayPoint closestPoint) {
this.distance = distance;
this.pathPoint = pathPoint;
this.pathPosition = pathPosition;
this.closestPoint = closestPoint;
}
}

View File

@@ -25,7 +25,7 @@ import java.util.List;
public interface PointUpdateListener {
public void pointsUpdated(List<DisplayPoint> points);
public boolean edgeSplit(List<DisplayPoint> points, int position, double splitPoint);
public boolean edgeSplit(int position, double splitPoint);
public boolean pointRemoved(List<DisplayPoint> points, int position);
public boolean pointRemoved(int position);
}

View File

@@ -837,7 +837,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
}
@Override
public boolean edgeSplit(List<DisplayPoint> points, int position, double splitPoint) {
public boolean edgeSplit(int position, double splitPoint) {
List<SHAPERECORD> selectedRecords = new ArrayList<>();
List<SHAPERECORD> otherRecords = null;
@@ -860,7 +860,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
Reference<Integer> importantRecordPosRef = new Reference<>(0);
if (splitRecords(importantRecordPosRef, points, selectedRecords, position, splitPoint) && otherRecords != null) {
if (splitRecords(importantRecordPosRef, selectedRecords, position, splitPoint) && otherRecords != null) {
int importantRecordPos = importantRecordPosRef.getVal();
int otherPosition = 0;
int otherImportantRecordPos = 0;
@@ -886,15 +886,15 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
break;
}
}
splitRecords(importantRecordPosRef, null, otherRecords, otherPosition, splitPoint);
splitRecords(importantRecordPosRef, otherRecords, otherPosition, splitPoint);
}
refreshHilightedPoints();
clearCache();
displayEditImagePanel.repaint();
return false;
}
private boolean splitRecords(Reference<Integer> importantRecordPosRef, List<DisplayPoint> points, List<SHAPERECORD> selectedRecords, int position, double splitPoint) {
private boolean splitRecords(Reference<Integer> importantRecordPosRef, List<SHAPERECORD> selectedRecords, int position, double splitPoint) {
int pointsPos = 0;
int x = 0;
int y = 0;
@@ -920,10 +920,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
ser.deltaX -= newSer.deltaX;
ser.deltaY -= newSer.deltaY;
ser.simplify();
selectedRecords.add(i + 1, newSer);
if (points != null) {
points.add(position, new DisplayPoint(new Point2D.Double(x + ser.deltaX, y + ser.deltaY)));
}
selectedRecords.add(i + 1, newSer);
importantRecordPosRef.setVal(importantRecordPos);
return true;
}
@@ -956,12 +953,6 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
newCer.anchorDeltaX = (int) Math.round(right.get(2).getX() - right.get(1).getX());
newCer.anchorDeltaY = (int) Math.round(right.get(2).getY() - right.get(1).getY());
selectedRecords.add(i + 1, newCer);
if (points != null) {
points.remove(position);
points.add(position, new DisplayPoint(new Point2D.Double(left.get(1).getX(), left.get(1).getY()), false));
points.add(position + 1, new DisplayPoint(new Point2D.Double(left.get(2).getX(), left.get(2).getY())));
points.add(position + 2, new DisplayPoint(new Point2D.Double(right.get(1).getX(), right.get(1).getY()), false));
}
importantRecordPosRef.setVal(importantRecordPos);
return true;
}
@@ -983,7 +974,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
}
@Override
public boolean pointRemoved(List<DisplayPoint> points, int position) {
public boolean pointRemoved(int position) {
List<SHAPERECORD> selectedRecords = new ArrayList<>();
List<SHAPERECORD> otherRecords = null;
@@ -1005,7 +996,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
}
Reference<Integer> importantRecordPosRef = new Reference<>(0);
if (removePoint(importantRecordPosRef, points, selectedRecords, position) && otherRecords != null) {
if (removePoint(importantRecordPosRef, selectedRecords, position) && otherRecords != null) {
int importantRecordPos = importantRecordPosRef.getVal();
int otherPosition = 0;
int otherImportantRecordPos = 0;
@@ -1031,15 +1022,15 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
break;
}
}
removePoint(importantRecordPosRef, null, otherRecords, otherPosition);
removePoint(importantRecordPosRef, otherRecords, otherPosition);
}
refreshHilightedPoints();
clearCache();
displayEditImagePanel.repaint();
return true;
}
private boolean removePoint(Reference<Integer> importantRecordPosRef, List<DisplayPoint> points, List<SHAPERECORD> selectedRecords, int position) {
private boolean removePoint(Reference<Integer> importantRecordPosRef,List<SHAPERECORD> selectedRecords, int position) {
int pointsPos = 0;
int importantRecordPos = 0;
int x = 0;
@@ -1065,11 +1056,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
nextSer.generalLineFlag = true;
nextSer.deltaX += ser.deltaX;
nextSer.deltaY += ser.deltaY;
selectedRecords.remove(i);
if (points != null) {
points.remove(position);
}
selectedRecords.remove(i);
importantRecordPosRef.setVal(importantRecordPos);
return true;
@@ -1078,11 +1065,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
CurvedEdgeRecord cer = (CurvedEdgeRecord) nextRec;
ser.generalLineFlag = true;
ser.deltaX += cer.controlDeltaX + cer.anchorDeltaX;
ser.deltaY += cer.controlDeltaY + cer.anchorDeltaY;
if (points != null) {
points.remove(position + 1);
points.remove(position);
}
ser.deltaY += cer.controlDeltaY + cer.anchorDeltaY;
selectedRecords.remove(i + 1);
importantRecordPosRef.setVal(importantRecordPos);
return true;
@@ -1101,10 +1084,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
ser.deltaX = cer.controlDeltaX + cer.anchorDeltaX;
ser.deltaY = cer.controlDeltaY + cer.anchorDeltaY;
ser.simplify();
selectedRecords.set(i, ser);
if (points != null) {
points.remove(position);
}
selectedRecords.set(i, ser);
//No need to update otherRecords
importantRecordPosRef.setVal(importantRecordPos);
return false;
@@ -1118,12 +1098,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
ser.deltaY = cer.controlDeltaY + cer.anchorDeltaY + nextCer.controlDeltaY + nextCer.anchorDeltaY;
ser.simplify();
selectedRecords.set(i, ser);
selectedRecords.remove(i + 1);
if (points != null) {
points.remove(pointsPos + 2);
points.remove(pointsPos + 1);
points.remove(pointsPos);
}
selectedRecords.remove(i + 1);
importantRecordPosRef.setVal(importantRecordPos);
return true;
}
@@ -1133,11 +1108,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
nextSer.deltaX += cer.controlDeltaX + cer.anchorDeltaX;
nextSer.deltaY += cer.controlDeltaY + cer.anchorDeltaY;
nextSer.simplify();
selectedRecords.remove(i);
if (points != null) {
points.remove(pointsPos + 1);
points.remove(pointsPos);
}
selectedRecords.remove(i);
importantRecordPosRef.setVal(importantRecordPos);
return true;
}
@@ -2258,8 +2229,6 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
displayEditShowEndButton.setVisible(false);
morphShowSpace.setVisible(false);
List<SHAPERECORD> selectedRecords = new ArrayList<>();
if (displayEditTag instanceof ShapeTag) {
ShapeTag shape = (ShapeTag) displayEditTag;
@@ -2268,9 +2237,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
if (shape instanceof DefineShape4Tag) {
DefineShape4Tag shape4 = (DefineShape4Tag) shape;
oldShapeEdgeBounds = shape4.edgeBounds;
}
selectedRecords = shape.shapes.shapeRecords;
}
}
if (displayEditTag instanceof MorphShapeTag) {
MorphShapeTag morphShape = (MorphShapeTag) displayEditTag;
@@ -2282,14 +2249,27 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
DefineMorphShape2Tag morphShape2 = (DefineMorphShape2Tag) morphShape;
oldShapeEdgeBounds = morphShape2.startEdgeBounds;
oldEndShapeEdgeBounds = morphShape2.endEdgeBounds;
}
}
}
refreshHilightedPoints();
mainPanel.setEditingStatus();
}
private void refreshHilightedPoints() {
List<SHAPERECORD> selectedRecords = new ArrayList<>();
if (displayEditTag instanceof ShapeTag) {
ShapeTag shape = (ShapeTag) displayEditTag;
selectedRecords = shape.shapes.shapeRecords;
}
if (displayEditTag instanceof MorphShapeTag) {
MorphShapeTag morphShape = (MorphShapeTag) displayEditTag;
if (morphDisplayMode == MORPH_START) {
selectedRecords = morphShape.startEdges.shapeRecords;
}
if (morphDisplayMode == MORPH_END) {
selectedRecords = morphShape.endEdges.shapeRecords;
}
}
}
int x = 0;
int y = 0;
@@ -2320,8 +2300,6 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
y = rec.changeY(y);
}
displayEditImagePanel.setHilightedPoints(points);
mainPanel.setEditingStatus();
}
private void transformDisplayEditTagButtonActionPerformed(ActionEvent evt) {