From e67eb887cf46dea8f8d5606a583a2a55b34c6d8e Mon Sep 17 00:00:00 2001 From: rondlh <77279634+rondlh@users.noreply.github.com> Date: Fri, 5 Dec 2025 08:29:39 +0800 Subject: [PATCH 1/3] Use threading to download assets to speedup startup Use threading to download assets to speedup startup --- .../java/com/commonwealthrobotics/Main.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/commonwealthrobotics/Main.java b/src/main/java/com/commonwealthrobotics/Main.java index fcb92a3..241fe89 100644 --- a/src/main/java/com/commonwealthrobotics/Main.java +++ b/src/main/java/com/commonwealthrobotics/Main.java @@ -292,15 +292,18 @@ public void uncaughtException(Thread t, Throwable e) { // Auto-generated catch block com.neuronrobotics.sdk.common.Log.error(e); } - if(PasswordManager.hasNetwork()) { - try { - ensureGitAssetsArePresent(); - }catch(Throwable t) { - com.neuronrobotics.sdk.common.Log.error(t); + + new Thread(() -> { + if (PasswordManager.hasNetwork()) { + try { + ensureGitAssetsArePresent(); + } catch (Throwable t) { + com.neuronrobotics.sdk.common.Log.error(t); + } + } else { + com.neuronrobotics.sdk.common.Log.error("No Network"); } - }else { - SplashManager.renderSplashFrame(2, "No Network"); - } + }, "cadoodle-assets-loader").start(); // com.neuronrobotics.sdk.common.Log.enableErrorPrint(); FontSizeManager.setFontSize(12); From 87198d2a63a9f42cb1682c97b43e21e3dc63c5d4 Mon Sep 17 00:00:00 2001 From: rondlh <77279634+rondlh@users.noreply.github.com> Date: Sat, 6 Dec 2025 22:15:46 +0800 Subject: [PATCH 2/3] Implement uniform scaling with the corner handles Implement uniform scaling with the corner handles --- .../controls/ResizeSessionManager.java | 285 +++++++++++++----- 1 file changed, 211 insertions(+), 74 deletions(-) diff --git a/src/main/java/com/commonwealthrobotics/controls/ResizeSessionManager.java b/src/main/java/com/commonwealthrobotics/controls/ResizeSessionManager.java index eb29cdd..ed597a4 100644 --- a/src/main/java/com/commonwealthrobotics/controls/ResizeSessionManager.java +++ b/src/main/java/com/commonwealthrobotics/controls/ResizeSessionManager.java @@ -36,6 +36,7 @@ public class ResizeSessionManager { private boolean locked; private boolean resizeAllowed; private boolean moveLock; + private Bounds originalBounds = null; public ResizeSessionManager(BowlerStudio3dEngine engine, Affine selection, Runnable updateLines, ActiveProject ap, SelectionSession s, Affine workplaneOffset, MoveUpArrow up) { @@ -62,120 +63,255 @@ public ResizeSessionManager(BowlerStudio3dEngine engine, Affine selection, Runna updateLines, onReset); rightFront.manipulator.addEventListener(ev -> { - if (scalingFlag) - return; - - scalingFlag = false; if (beingUpdated == null) beingUpdated = rightFront; - if (beingUpdated != rightFront) { - // com.neuronrobotics.sdk.common.Log.error("Motion from "+beingUpdated+" - // rejected by "+rightFront); + if (beingUpdated != rightFront) + return; + if (scalingFlag) { // cancel one recursive call + scalingFlag = false; return; } - double x = rightRear.manipulator.getCurrentPose().getX(); - double y = rightFront.manipulator.getCurrentPose().getY(); - double z = rightRear.manipulator.getCurrentPose().getZ(); - // com.neuronrobotics.sdk.common.Log.error("rightRear Move x" + x + " y" + y + " - // z" + z); - rightRear.manipulator.setInReferenceFrame(x, y, z); - x = rightFront.manipulator.getCurrentPose().getX(); - y = leftFront.manipulator.getCurrentPose().getY(); - leftFront.manipulator.setInReferenceFrame(x, y, z); + + // Uniform scaling with shift key + if (ev != null && ev.isShiftDown()) { + if (originalBounds == null) + originalBounds = getBounds(); + + double original_x = originalBounds.getTotalX(); + double original_y = originalBounds.getTotalY(); + double original_diagonal = Math.hypot(original_x, original_y); + + // Mouse offset from manipulator + double mouseX = rightFront.getCurrentInReferenceFrame().getX() - originalBounds.getMaxX(); // Front + double mouseY = - rightFront.getCurrentInReferenceFrame().getY() + originalBounds.getMinY(); // Right + double scale = (mouseX * original_x + mouseY * original_y) / (original_diagonal * original_diagonal); + + double rawNewX = original_x * (1.0 + scale); // Snap X-dimension to grid + double gridNewX = Math.round(rawNewX / size) * size; + double difference_x = Math.abs(rawNewX - gridNewX); + + double rawNewY = original_y * (1.0 + scale); // Snap Y-dimension to grid + double gridNewY = Math.round(rawNewY / size) * size; + double difference_y = Math.abs(rawNewY - gridNewY); + double gridScale; + + if (difference_x < difference_y) + gridScale = (gridNewX / original_x) - 1.0; + else + gridScale = (gridNewY / original_y) - 1.0; + + scalingFlag = true; + rightFront.manipulator.setInReferenceFrame(original_x * gridScale, -original_y * gridScale, 0); + rightRear.manipulator.setInReferenceFrame (0, -original_y * gridScale, 0); + leftFront.manipulator.setInReferenceFrame (original_x * gridScale, 0 , 0); + topCenter.setInReferenceFrame (0, 0, originalBounds.getMinZ() + originalBounds.getTotalZ() * (gridScale + 1)); + + } else { + // Unconstraint resizing path + double x = rightRear.manipulator.getCurrentPose().getX(); + double y = rightFront.manipulator.getCurrentPose().getY(); + double z = rightRear.manipulator.getCurrentPose().getZ(); + rightRear.manipulator.setInReferenceFrame(x, y, z); + x = rightFront.manipulator.getCurrentPose().getX(); + y = leftFront.manipulator.getCurrentPose().getY(); + leftFront.manipulator.setInReferenceFrame(x, y, z); + } + BowlerStudio.runLater(() -> update()); - // com.neuronrobotics.sdk.common.Log.error("rightFront"); }); - rightRear.manipulator.addEventListener(ev -> { - if (scalingFlag) - return; - - scalingFlag = false; + rightRear.manipulator.addEventListener(ev -> { if (beingUpdated == null) beingUpdated = rightRear; - if (beingUpdated != rightRear) { - // com.neuronrobotics.sdk.common.Log.error("Motion from "+beingUpdated+" - // rejected by "+rightRear); + if (beingUpdated != rightRear) + return; + if (scalingFlag) { + scalingFlag = false; return; } - double x = rightFront.manipulator.getCurrentPose().getX(); - double y = rightRear.manipulator.getCurrentPose().getY(); - double z = rightFront.manipulator.getCurrentPose().getZ(); - rightFront.manipulator.setInReferenceFrame(x, y, z); - x = rightRear.manipulator.getCurrentPose().getX(); - y = leftRear.manipulator.getCurrentPose().getY(); - leftRear.manipulator.setInReferenceFrame(x, y, z); + + if (ev != null && ev.isShiftDown()) { + // Uniform scaling + if (originalBounds == null) + originalBounds = getBounds(); + + double original_x = originalBounds.getTotalX(); + double original_y = originalBounds.getTotalY(); + double original_diagonal = Math.hypot(original_x, original_y); + + // Mouse offset from manipulator + double mouseX = -rightRear.getCurrentInReferenceFrame().getX() + originalBounds.getMinX(); // Rear + double mouseY = -rightRear.getCurrentInReferenceFrame().getY() + originalBounds.getMinY(); // Right + double scale = (mouseX * original_x + mouseY * original_y) / (original_diagonal * original_diagonal); + + double rawNewX = original_x * (1.0 + scale); // Snap X-dimension to grid + double gridNewX = Math.round(rawNewX / size) * size; + double difference_x = Math.abs(rawNewX - gridNewX); + + double rawNewY = original_y * (1.0 + scale); // Snap Y-dimension to grid + double gridNewY = Math.round(rawNewY / size) * size; + double difference_y = Math.abs(rawNewY - gridNewY); + double gridScale; + + if (difference_x < difference_y) + gridScale = (gridNewX / original_x) - 1.0; + else + gridScale = (gridNewY / original_y) - 1.0; + + scalingFlag = true; // Set to true to prevent recursive call + rightRear.manipulator.setInReferenceFrame(-original_x * gridScale, -original_y * gridScale, 0); + rightFront.manipulator.setInReferenceFrame(0, -original_y * gridScale, 0); + leftRear.manipulator.setInReferenceFrame (-original_x * gridScale, 0 , 0); + topCenter.setInReferenceFrame (0, 0, originalBounds.getMinZ() + originalBounds.getTotalZ() * (gridScale + 1)); + } else { + double x = rightFront.manipulator.getCurrentPose().getX(); + double y = rightRear.manipulator.getCurrentPose().getY(); + double z = rightFront.manipulator.getCurrentPose().getZ(); + rightFront.manipulator.setInReferenceFrame(x, y, z); + x = rightRear.manipulator.getCurrentPose().getX(); + y = leftRear.manipulator.getCurrentPose().getY(); + leftRear.manipulator.setInReferenceFrame(x, y, z); + } + BowlerStudio.runLater(() -> update()); - // com.neuronrobotics.sdk.common.Log.error("rightRear"); }); - leftFront.manipulator.addEventListener(ev -> { - if (scalingFlag) - return; - - scalingFlag = false; + leftFront.manipulator.addEventListener(ev -> { if (beingUpdated == null) beingUpdated = leftFront; - if (beingUpdated != leftFront) { - // com.neuronrobotics.sdk.common.Log.error("Motion from "+beingUpdated+" - // rejected by "+leftFront); + if (beingUpdated != leftFront) return; + if (scalingFlag) { + scalingFlag = false; + return; + } + + if (ev != null && ev.isShiftDown()) { + // Uniform scaling + if (originalBounds == null) + originalBounds = getBounds(); + + double original_x = originalBounds.getTotalX(); + double original_y = originalBounds.getTotalY(); + double original_diagonal = Math.hypot(original_x, original_y); + + // Mouse offset from manipulator + double mouseX = leftFront.getCurrentInReferenceFrame().getX() - originalBounds.getMaxX(); // Front + double mouseY = leftFront.getCurrentInReferenceFrame().getY() - originalBounds.getMaxY(); // Left + double scale = (mouseX * original_x + mouseY * original_y) / (original_diagonal * original_diagonal); + + double rawNewX = original_x * (1.0 + scale); // Snap X-dimension to grid + double gridNewX = Math.round(rawNewX / size) * size; + double difference_x = Math.abs(rawNewX - gridNewX); + + double rawNewY = original_y * (1.0 + scale); // Snap Y-dimension to grid + double gridNewY = Math.round(rawNewY / size) * size; + double difference_y = Math.abs(rawNewY - gridNewY); + double gridScale; + + if (difference_x < difference_y) + gridScale = (gridNewX / original_x) - 1.0; + else + gridScale = (gridNewY / original_y) - 1.0; + + scalingFlag = true; // Set to true to prevent recursive call + leftFront.manipulator.setInReferenceFrame (original_x * gridScale, original_y * gridScale, 0); + rightFront.manipulator.setInReferenceFrame(original_x * gridScale, 0, 0); + leftRear.manipulator.setInReferenceFrame (0, original_y * gridScale, 0); + topCenter.setInReferenceFrame(0, 0, originalBounds.getMinZ() + originalBounds.getTotalZ() * (gridScale + 1)); + } else { + double x = leftRear.manipulator.getCurrentPose().getX(); + double y = leftFront.manipulator.getCurrentPose().getY(); + double z = leftFront.manipulator.getCurrentPose().getZ(); + leftRear.manipulator.setInReferenceFrame(x, y, z); + x = leftFront.manipulator.getCurrentPose().getX(); + y = rightFront.manipulator.getCurrentPose().getY(); + rightFront.manipulator.setInReferenceFrame(x, y, z); } - double x = leftRear.manipulator.getCurrentPose().getX(); - double y = leftFront.manipulator.getCurrentPose().getY(); - double z = leftFront.manipulator.getCurrentPose().getZ(); - leftRear.manipulator.setInReferenceFrame(x, y, z); - x = leftFront.manipulator.getCurrentPose().getX(); - y = rightFront.manipulator.getCurrentPose().getY(); - rightFront.manipulator.setInReferenceFrame(x, y, z); - BowlerStudio.runLater(() -> update()); // com.neuronrobotics.sdk.common.Log.error("leftFront"); + + BowlerStudio.runLater(() -> update()); }); - leftRear.manipulator.addEventListener(ev -> { - if (scalingFlag) - return; - scalingFlag = false; + leftRear.manipulator.addEventListener(ev -> { if (beingUpdated == null) beingUpdated = leftRear; - if (beingUpdated != leftRear) { - // com.neuronrobotics.sdk.common.Log.error("Motion from "+beingUpdated+" - // rejected by "+leftRear); + if (beingUpdated != leftRear) return; + if (scalingFlag) { + scalingFlag = false; + return; + } + + if (ev != null && ev.isShiftDown()) { + // Uniform scaling + if (originalBounds == null) + originalBounds = getBounds(); + + double original_x = originalBounds.getTotalX(); + double original_y = originalBounds.getTotalY(); + double original_diagonal = Math.hypot(original_x, original_y); + + // Mouse offset from manipulator + double mouseX = -leftRear.getCurrentInReferenceFrame().getX() + originalBounds.getMinX(); // Rear + double mouseY = leftRear.getCurrentInReferenceFrame().getY() - originalBounds.getMaxY(); // Left + double scale = (mouseX * original_x + mouseY * original_y) / (original_diagonal * original_diagonal); + + double rawNewX = original_x * (1.0 + scale); // Snap X-dimension to grid + double gridNewX = Math.round(rawNewX / size) * size; + double difference_x = Math.abs(rawNewX - gridNewX); + + double rawNewY = original_y * (1.0 + scale); // Snap Y-dimension to grid + double gridNewY = Math.round(rawNewY / size) * size; + double difference_y = Math.abs(rawNewY - gridNewY); + double gridScale; + + if (difference_x < difference_y) + gridScale = (gridNewX / original_x) - 1.0; + else + gridScale = (gridNewY / original_y) - 1.0; + + scalingFlag = true; // Set to true to prevent recursive call + leftRear.manipulator.setInReferenceFrame (-original_x * gridScale, original_y * gridScale, 0); + leftFront.manipulator.setInReferenceFrame(0, original_y * gridScale, 0); + rightRear.manipulator.setInReferenceFrame(-original_x * gridScale, 0 , 0); + topCenter.setInReferenceFrame(0, 0, originalBounds.getMinZ() + originalBounds.getTotalZ() * (gridScale + 1)); + } else { + double x = leftFront.manipulator.getCurrentPose().getX(); + double y = leftRear.manipulator.getCurrentPose().getY(); + double z = leftRear.manipulator.getCurrentPose().getZ(); + leftFront.manipulator.setInReferenceFrame(x, y, z); + x = leftRear.manipulator.getCurrentPose().getX(); + y = rightRear.manipulator.getCurrentPose().getY(); + rightRear.manipulator.setInReferenceFrame(x, y, z); } - double x = leftFront.manipulator.getCurrentPose().getX(); - double y = leftRear.manipulator.getCurrentPose().getY(); - double z = leftRear.manipulator.getCurrentPose().getZ(); - leftFront.manipulator.setInReferenceFrame(x, y, z); - x = leftRear.manipulator.getCurrentPose().getX(); - y = rightRear.manipulator.getCurrentPose().getY(); - rightRear.manipulator.setInReferenceFrame(x, y, z); - BowlerStudio.runLater(() -> update()); // com.neuronrobotics.sdk.common.Log.error("leftRear"); + BowlerStudio.runLater(() -> update()); }); - topCenter.manipulator.addEventListener(ev -> { - scalingFlag = false; + topCenter.manipulator.addEventListener(ev -> { if (beingUpdated == null) beingUpdated = topCenter; - if (beingUpdated != topCenter) { - // com.neuronrobotics.sdk.common.Log.error("Motion from "+beingUpdated+" - // rejected by "+topCenter); + if (beingUpdated != topCenter) + return; + if (scalingFlag) { + scalingFlag = false; return; } + if (ev != null) if (ev.isShiftDown()) { TransformNR tcC = topCenter.getCurrentInReferenceFrame(); uniformScalingZ(tcC); - // com.neuronrobotics.sdk.common.Log.debug("RE-Scaling whole object! "+scale); } BowlerStudio.runLater(() -> update()); - - // com.neuronrobotics.sdk.common.Log.error("topCenter"); }); + controls = Arrays.asList(topCenter, rightFront, rightRear, leftFront, leftRear); for (ResizingHandle c : controls) { c.manipulator.setFrameOfReference(() -> ap.get().getWorkplane()); c.manipulator.addSaveListener(() -> { + if (beingUpdated != c) + return; try { Thread.sleep(32); } catch (InterruptedException e) { @@ -196,7 +332,6 @@ public ResizeSessionManager(BowlerStudio3dEngine engine, Affine selection, Runna for (ResizingHandle ctrl : controls) { ctrl.manipulator.set(0, 0, 0); } - beingUpdated = null; // if (Math.abs(lfC.getZ() - rrC.getZ()) > 0.00001) { // throw new RuntimeException("The control points of the corners must be at the same Z value \n" // + lfC.toSimpleString() + "\n" + rrC.toSimpleString()); @@ -214,6 +349,7 @@ public ResizeSessionManager(BowlerStudio3dEngine engine, Affine selection, Runna com.neuronrobotics.sdk.common.Log.error(e); } } + beingUpdated = null; BowlerStudio.runLater(() -> threeDTarget()); }); } @@ -227,7 +363,6 @@ public void setResizeAllowed(boolean resizeAllowed, boolean moveLock) { } private void uniformScalingZ(TransformNR tcC) { - scalingFlag = true; double startZ = bounds.getTotalZ(); double startX = bounds.getTotalX(); double startY = bounds.getTotalY(); @@ -250,6 +385,7 @@ private void uniformScalingZ(TransformNR tcC) { double newY = -newYComp; double newX2 = +newXComp; double newY2 = +newYComp; + scalingFlag = true; rightRear.manipulator.setInReferenceFrame(newX, newY, z); leftFront.manipulator.setInReferenceFrame(newX2, newY2, z); rightFront.manipulator.setInReferenceFrame(newX2, newY, z); @@ -346,6 +482,7 @@ public void setSnapGrid(double size) { } public void resetSelected() { + originalBounds = null; // reset var that exists to help maintain aspect ratios for (ResizingHandle c : controls) { c.resetSelected(); } From bc277018f9ce1a21656ee17188f641beefb3c1ba Mon Sep 17 00:00:00 2001 From: rondlh <77279634+rondlh@users.noreply.github.com> Date: Sat, 6 Dec 2025 22:43:34 +0800 Subject: [PATCH 3/3] Revert "Implement uniform scaling with the corner handles" This reverts commit 87198d2a63a9f42cb1682c97b43e21e3dc63c5d4. --- .../controls/ResizeSessionManager.java | 285 +++++------------- 1 file changed, 74 insertions(+), 211 deletions(-) diff --git a/src/main/java/com/commonwealthrobotics/controls/ResizeSessionManager.java b/src/main/java/com/commonwealthrobotics/controls/ResizeSessionManager.java index ed597a4..eb29cdd 100644 --- a/src/main/java/com/commonwealthrobotics/controls/ResizeSessionManager.java +++ b/src/main/java/com/commonwealthrobotics/controls/ResizeSessionManager.java @@ -36,7 +36,6 @@ public class ResizeSessionManager { private boolean locked; private boolean resizeAllowed; private boolean moveLock; - private Bounds originalBounds = null; public ResizeSessionManager(BowlerStudio3dEngine engine, Affine selection, Runnable updateLines, ActiveProject ap, SelectionSession s, Affine workplaneOffset, MoveUpArrow up) { @@ -63,255 +62,120 @@ public ResizeSessionManager(BowlerStudio3dEngine engine, Affine selection, Runna updateLines, onReset); rightFront.manipulator.addEventListener(ev -> { + if (scalingFlag) + return; + + scalingFlag = false; if (beingUpdated == null) beingUpdated = rightFront; - if (beingUpdated != rightFront) - return; - if (scalingFlag) { // cancel one recursive call - scalingFlag = false; + if (beingUpdated != rightFront) { + // com.neuronrobotics.sdk.common.Log.error("Motion from "+beingUpdated+" + // rejected by "+rightFront); return; } - - // Uniform scaling with shift key - if (ev != null && ev.isShiftDown()) { - if (originalBounds == null) - originalBounds = getBounds(); - - double original_x = originalBounds.getTotalX(); - double original_y = originalBounds.getTotalY(); - double original_diagonal = Math.hypot(original_x, original_y); - - // Mouse offset from manipulator - double mouseX = rightFront.getCurrentInReferenceFrame().getX() - originalBounds.getMaxX(); // Front - double mouseY = - rightFront.getCurrentInReferenceFrame().getY() + originalBounds.getMinY(); // Right - double scale = (mouseX * original_x + mouseY * original_y) / (original_diagonal * original_diagonal); - - double rawNewX = original_x * (1.0 + scale); // Snap X-dimension to grid - double gridNewX = Math.round(rawNewX / size) * size; - double difference_x = Math.abs(rawNewX - gridNewX); - - double rawNewY = original_y * (1.0 + scale); // Snap Y-dimension to grid - double gridNewY = Math.round(rawNewY / size) * size; - double difference_y = Math.abs(rawNewY - gridNewY); - double gridScale; - - if (difference_x < difference_y) - gridScale = (gridNewX / original_x) - 1.0; - else - gridScale = (gridNewY / original_y) - 1.0; - - scalingFlag = true; - rightFront.manipulator.setInReferenceFrame(original_x * gridScale, -original_y * gridScale, 0); - rightRear.manipulator.setInReferenceFrame (0, -original_y * gridScale, 0); - leftFront.manipulator.setInReferenceFrame (original_x * gridScale, 0 , 0); - topCenter.setInReferenceFrame (0, 0, originalBounds.getMinZ() + originalBounds.getTotalZ() * (gridScale + 1)); - - } else { - // Unconstraint resizing path - double x = rightRear.manipulator.getCurrentPose().getX(); - double y = rightFront.manipulator.getCurrentPose().getY(); - double z = rightRear.manipulator.getCurrentPose().getZ(); - rightRear.manipulator.setInReferenceFrame(x, y, z); - x = rightFront.manipulator.getCurrentPose().getX(); - y = leftFront.manipulator.getCurrentPose().getY(); - leftFront.manipulator.setInReferenceFrame(x, y, z); - } - + double x = rightRear.manipulator.getCurrentPose().getX(); + double y = rightFront.manipulator.getCurrentPose().getY(); + double z = rightRear.manipulator.getCurrentPose().getZ(); + // com.neuronrobotics.sdk.common.Log.error("rightRear Move x" + x + " y" + y + " + // z" + z); + rightRear.manipulator.setInReferenceFrame(x, y, z); + x = rightFront.manipulator.getCurrentPose().getX(); + y = leftFront.manipulator.getCurrentPose().getY(); + leftFront.manipulator.setInReferenceFrame(x, y, z); BowlerStudio.runLater(() -> update()); + // com.neuronrobotics.sdk.common.Log.error("rightFront"); }); - rightRear.manipulator.addEventListener(ev -> { + if (scalingFlag) + return; + + scalingFlag = false; + if (beingUpdated == null) beingUpdated = rightRear; - if (beingUpdated != rightRear) - return; - if (scalingFlag) { - scalingFlag = false; + if (beingUpdated != rightRear) { + // com.neuronrobotics.sdk.common.Log.error("Motion from "+beingUpdated+" + // rejected by "+rightRear); return; } - - if (ev != null && ev.isShiftDown()) { - // Uniform scaling - if (originalBounds == null) - originalBounds = getBounds(); - - double original_x = originalBounds.getTotalX(); - double original_y = originalBounds.getTotalY(); - double original_diagonal = Math.hypot(original_x, original_y); - - // Mouse offset from manipulator - double mouseX = -rightRear.getCurrentInReferenceFrame().getX() + originalBounds.getMinX(); // Rear - double mouseY = -rightRear.getCurrentInReferenceFrame().getY() + originalBounds.getMinY(); // Right - double scale = (mouseX * original_x + mouseY * original_y) / (original_diagonal * original_diagonal); - - double rawNewX = original_x * (1.0 + scale); // Snap X-dimension to grid - double gridNewX = Math.round(rawNewX / size) * size; - double difference_x = Math.abs(rawNewX - gridNewX); - - double rawNewY = original_y * (1.0 + scale); // Snap Y-dimension to grid - double gridNewY = Math.round(rawNewY / size) * size; - double difference_y = Math.abs(rawNewY - gridNewY); - double gridScale; - - if (difference_x < difference_y) - gridScale = (gridNewX / original_x) - 1.0; - else - gridScale = (gridNewY / original_y) - 1.0; - - scalingFlag = true; // Set to true to prevent recursive call - rightRear.manipulator.setInReferenceFrame(-original_x * gridScale, -original_y * gridScale, 0); - rightFront.manipulator.setInReferenceFrame(0, -original_y * gridScale, 0); - leftRear.manipulator.setInReferenceFrame (-original_x * gridScale, 0 , 0); - topCenter.setInReferenceFrame (0, 0, originalBounds.getMinZ() + originalBounds.getTotalZ() * (gridScale + 1)); - } else { - double x = rightFront.manipulator.getCurrentPose().getX(); - double y = rightRear.manipulator.getCurrentPose().getY(); - double z = rightFront.manipulator.getCurrentPose().getZ(); - rightFront.manipulator.setInReferenceFrame(x, y, z); - x = rightRear.manipulator.getCurrentPose().getX(); - y = leftRear.manipulator.getCurrentPose().getY(); - leftRear.manipulator.setInReferenceFrame(x, y, z); - } - + double x = rightFront.manipulator.getCurrentPose().getX(); + double y = rightRear.manipulator.getCurrentPose().getY(); + double z = rightFront.manipulator.getCurrentPose().getZ(); + rightFront.manipulator.setInReferenceFrame(x, y, z); + x = rightRear.manipulator.getCurrentPose().getX(); + y = leftRear.manipulator.getCurrentPose().getY(); + leftRear.manipulator.setInReferenceFrame(x, y, z); BowlerStudio.runLater(() -> update()); + // com.neuronrobotics.sdk.common.Log.error("rightRear"); }); - leftFront.manipulator.addEventListener(ev -> { + if (scalingFlag) + return; + + scalingFlag = false; + if (beingUpdated == null) beingUpdated = leftFront; - if (beingUpdated != leftFront) + if (beingUpdated != leftFront) { + // com.neuronrobotics.sdk.common.Log.error("Motion from "+beingUpdated+" + // rejected by "+leftFront); return; - if (scalingFlag) { - scalingFlag = false; - return; - } - - if (ev != null && ev.isShiftDown()) { - // Uniform scaling - if (originalBounds == null) - originalBounds = getBounds(); - - double original_x = originalBounds.getTotalX(); - double original_y = originalBounds.getTotalY(); - double original_diagonal = Math.hypot(original_x, original_y); - - // Mouse offset from manipulator - double mouseX = leftFront.getCurrentInReferenceFrame().getX() - originalBounds.getMaxX(); // Front - double mouseY = leftFront.getCurrentInReferenceFrame().getY() - originalBounds.getMaxY(); // Left - double scale = (mouseX * original_x + mouseY * original_y) / (original_diagonal * original_diagonal); - - double rawNewX = original_x * (1.0 + scale); // Snap X-dimension to grid - double gridNewX = Math.round(rawNewX / size) * size; - double difference_x = Math.abs(rawNewX - gridNewX); - - double rawNewY = original_y * (1.0 + scale); // Snap Y-dimension to grid - double gridNewY = Math.round(rawNewY / size) * size; - double difference_y = Math.abs(rawNewY - gridNewY); - double gridScale; - - if (difference_x < difference_y) - gridScale = (gridNewX / original_x) - 1.0; - else - gridScale = (gridNewY / original_y) - 1.0; - - scalingFlag = true; // Set to true to prevent recursive call - leftFront.manipulator.setInReferenceFrame (original_x * gridScale, original_y * gridScale, 0); - rightFront.manipulator.setInReferenceFrame(original_x * gridScale, 0, 0); - leftRear.manipulator.setInReferenceFrame (0, original_y * gridScale, 0); - topCenter.setInReferenceFrame(0, 0, originalBounds.getMinZ() + originalBounds.getTotalZ() * (gridScale + 1)); - } else { - double x = leftRear.manipulator.getCurrentPose().getX(); - double y = leftFront.manipulator.getCurrentPose().getY(); - double z = leftFront.manipulator.getCurrentPose().getZ(); - leftRear.manipulator.setInReferenceFrame(x, y, z); - x = leftFront.manipulator.getCurrentPose().getX(); - y = rightFront.manipulator.getCurrentPose().getY(); - rightFront.manipulator.setInReferenceFrame(x, y, z); } - - BowlerStudio.runLater(() -> update()); + double x = leftRear.manipulator.getCurrentPose().getX(); + double y = leftFront.manipulator.getCurrentPose().getY(); + double z = leftFront.manipulator.getCurrentPose().getZ(); + leftRear.manipulator.setInReferenceFrame(x, y, z); + x = leftFront.manipulator.getCurrentPose().getX(); + y = rightFront.manipulator.getCurrentPose().getY(); + rightFront.manipulator.setInReferenceFrame(x, y, z); + BowlerStudio.runLater(() -> update()); // com.neuronrobotics.sdk.common.Log.error("leftFront"); }); - leftRear.manipulator.addEventListener(ev -> { + if (scalingFlag) + return; + scalingFlag = false; + if (beingUpdated == null) beingUpdated = leftRear; - if (beingUpdated != leftRear) + if (beingUpdated != leftRear) { + // com.neuronrobotics.sdk.common.Log.error("Motion from "+beingUpdated+" + // rejected by "+leftRear); return; - if (scalingFlag) { - scalingFlag = false; - return; - } - - if (ev != null && ev.isShiftDown()) { - // Uniform scaling - if (originalBounds == null) - originalBounds = getBounds(); - - double original_x = originalBounds.getTotalX(); - double original_y = originalBounds.getTotalY(); - double original_diagonal = Math.hypot(original_x, original_y); - - // Mouse offset from manipulator - double mouseX = -leftRear.getCurrentInReferenceFrame().getX() + originalBounds.getMinX(); // Rear - double mouseY = leftRear.getCurrentInReferenceFrame().getY() - originalBounds.getMaxY(); // Left - double scale = (mouseX * original_x + mouseY * original_y) / (original_diagonal * original_diagonal); - - double rawNewX = original_x * (1.0 + scale); // Snap X-dimension to grid - double gridNewX = Math.round(rawNewX / size) * size; - double difference_x = Math.abs(rawNewX - gridNewX); - - double rawNewY = original_y * (1.0 + scale); // Snap Y-dimension to grid - double gridNewY = Math.round(rawNewY / size) * size; - double difference_y = Math.abs(rawNewY - gridNewY); - double gridScale; - - if (difference_x < difference_y) - gridScale = (gridNewX / original_x) - 1.0; - else - gridScale = (gridNewY / original_y) - 1.0; - - scalingFlag = true; // Set to true to prevent recursive call - leftRear.manipulator.setInReferenceFrame (-original_x * gridScale, original_y * gridScale, 0); - leftFront.manipulator.setInReferenceFrame(0, original_y * gridScale, 0); - rightRear.manipulator.setInReferenceFrame(-original_x * gridScale, 0 , 0); - topCenter.setInReferenceFrame(0, 0, originalBounds.getMinZ() + originalBounds.getTotalZ() * (gridScale + 1)); - } else { - double x = leftFront.manipulator.getCurrentPose().getX(); - double y = leftRear.manipulator.getCurrentPose().getY(); - double z = leftRear.manipulator.getCurrentPose().getZ(); - leftFront.manipulator.setInReferenceFrame(x, y, z); - x = leftRear.manipulator.getCurrentPose().getX(); - y = rightRear.manipulator.getCurrentPose().getY(); - rightRear.manipulator.setInReferenceFrame(x, y, z); } - BowlerStudio.runLater(() -> update()); + double x = leftFront.manipulator.getCurrentPose().getX(); + double y = leftRear.manipulator.getCurrentPose().getY(); + double z = leftRear.manipulator.getCurrentPose().getZ(); + leftFront.manipulator.setInReferenceFrame(x, y, z); + x = leftRear.manipulator.getCurrentPose().getX(); + y = rightRear.manipulator.getCurrentPose().getY(); + rightRear.manipulator.setInReferenceFrame(x, y, z); + BowlerStudio.runLater(() -> update()); // com.neuronrobotics.sdk.common.Log.error("leftRear"); }); - topCenter.manipulator.addEventListener(ev -> { + scalingFlag = false; + if (beingUpdated == null) beingUpdated = topCenter; - if (beingUpdated != topCenter) - return; - if (scalingFlag) { - scalingFlag = false; + if (beingUpdated != topCenter) { + // com.neuronrobotics.sdk.common.Log.error("Motion from "+beingUpdated+" + // rejected by "+topCenter); return; } - if (ev != null) if (ev.isShiftDown()) { TransformNR tcC = topCenter.getCurrentInReferenceFrame(); uniformScalingZ(tcC); + // com.neuronrobotics.sdk.common.Log.debug("RE-Scaling whole object! "+scale); } BowlerStudio.runLater(() -> update()); - }); + // com.neuronrobotics.sdk.common.Log.error("topCenter"); + }); controls = Arrays.asList(topCenter, rightFront, rightRear, leftFront, leftRear); for (ResizingHandle c : controls) { c.manipulator.setFrameOfReference(() -> ap.get().getWorkplane()); c.manipulator.addSaveListener(() -> { - if (beingUpdated != c) - return; try { Thread.sleep(32); } catch (InterruptedException e) { @@ -332,6 +196,7 @@ public ResizeSessionManager(BowlerStudio3dEngine engine, Affine selection, Runna for (ResizingHandle ctrl : controls) { ctrl.manipulator.set(0, 0, 0); } + beingUpdated = null; // if (Math.abs(lfC.getZ() - rrC.getZ()) > 0.00001) { // throw new RuntimeException("The control points of the corners must be at the same Z value \n" // + lfC.toSimpleString() + "\n" + rrC.toSimpleString()); @@ -349,7 +214,6 @@ public ResizeSessionManager(BowlerStudio3dEngine engine, Affine selection, Runna com.neuronrobotics.sdk.common.Log.error(e); } } - beingUpdated = null; BowlerStudio.runLater(() -> threeDTarget()); }); } @@ -363,6 +227,7 @@ public void setResizeAllowed(boolean resizeAllowed, boolean moveLock) { } private void uniformScalingZ(TransformNR tcC) { + scalingFlag = true; double startZ = bounds.getTotalZ(); double startX = bounds.getTotalX(); double startY = bounds.getTotalY(); @@ -385,7 +250,6 @@ private void uniformScalingZ(TransformNR tcC) { double newY = -newYComp; double newX2 = +newXComp; double newY2 = +newYComp; - scalingFlag = true; rightRear.manipulator.setInReferenceFrame(newX, newY, z); leftFront.manipulator.setInReferenceFrame(newX2, newY2, z); rightFront.manipulator.setInReferenceFrame(newX2, newY, z); @@ -482,7 +346,6 @@ public void setSnapGrid(double size) { } public void resetSelected() { - originalBounds = null; // reset var that exists to help maintain aspect ratios for (ResizingHandle c : controls) { c.resetSelected(); }