snap rigid components back to the grid

This commit is contained in:
bancika
2020-12-12 11:39:01 +01:00
parent a1e43be273
commit 7dd63ba2d8
3 changed files with 11 additions and 3 deletions
@@ -1321,19 +1321,23 @@ public class Presenter implements IPlugInPort {
Dimension d = drawingManager.getCanvasDimensions(currentProject, 1d, useExtraSpace);
double extraSpace = useExtraSpace ? drawingManager.getExtraSpace(currentProject) : 0;
boolean isRigid = true;
List<Point2D> points = new ArrayList<Point2D>();
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
for (Integer i : entry.getValue())
{
Point2D p = entry.getKey().getControlPoint(i);
if (entry.getKey().canPointMoveFreely(i))
isRigid = false;
points.add(p);
}
}
Point2D firstPoint = points.iterator().next();
if (points.size() == 1 || points.stream().allMatch((x) -> x.equals(firstPoint))) {
double avgX = points.stream().mapToDouble((x) -> x.getX()).average().getAsDouble();
double avgY = points.stream().mapToDouble((x) -> x.getY()).average().getAsDouble();
if (points.size() == 1 || points.stream().allMatch((x) -> x.equals(firstPoint)) || (controlPointMap.size() == 1 && isRigid)) {
double avgX = firstPoint.getX();//points.stream().mapToDouble((x) -> x.getX()).average().getAsDouble();
double avgY = firstPoint.getY();//points.stream().mapToDouble((x) -> x.getY()).average().getAsDouble();
Point2D testPoint = new Point2D.Double(avgX + dx, avgY + dy);
if (snapToGrid) {
@@ -3297,6 +3297,10 @@
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>In cases when there's already a component in the selection that is reduced to nothing, allow moving the selection to avoid getting stuck</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Moving a rigid component (e.g. tube/transistor symbol) which is not snapped to grid makes it snap back to the grid when 'Snap to Grid' is switched on</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>