diff --git a/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs b/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs index 33d4c05d4..d2a479792 100644 --- a/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs +++ b/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs @@ -63,6 +63,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public MoveInZControl(IInteractionVolumeContext context) : base(context) { + Name = "MoveInZControl"; zHeightDisplayInfo = new ValueDisplayInfo() { ForceHide = () => diff --git a/PartPreviewWindow/View3D/InteractionVolume.cs b/PartPreviewWindow/View3D/InteractionVolume.cs index 3c879f041..3ad1ceaa3 100644 --- a/PartPreviewWindow/View3D/InteractionVolume.cs +++ b/PartPreviewWindow/View3D/InteractionVolume.cs @@ -48,6 +48,8 @@ namespace MatterHackers.MeshVisualizer public bool MouseDownOnControl; public Matrix4X4 TotalTransform = Matrix4X4.Identity; + public string Name { get; set; } + private bool mouseOver = false; public InteractionVolume(IInteractionVolumeContext meshViewerToDrawWith) diff --git a/PartPreviewWindow/View3D/MeshViewerWidget.cs b/PartPreviewWindow/View3D/MeshViewerWidget.cs index 945a7da63..a22e02936 100644 --- a/PartPreviewWindow/View3D/MeshViewerWidget.cs +++ b/PartPreviewWindow/View3D/MeshViewerWidget.cs @@ -162,6 +162,51 @@ namespace MatterHackers.MeshVisualizer public override void FindNamedChildrenRecursive(string nameToSearchFor, List foundChildren, RectangleDouble touchingBounds, SearchType seachType, bool allowInvalidItems = true) { + foreach (InteractionVolume child in interactionLayer.InteractionVolumes) + { + string object3DName = child.Name; + + bool nameFound = false; + + if (seachType == SearchType.Exact) + { + if (object3DName == nameToSearchFor) + { + nameFound = true; + } + } + else + { + if (nameToSearchFor == "" + || object3DName.Contains(nameToSearchFor)) + { + nameFound = true; + } + } + + if (nameFound) + { + AxisAlignedBoundingBox bounds = child.CollisionVolume.GetAxisAlignedBoundingBox(); + bounds = bounds.NewTransformed(child.TotalTransform); + + RectangleDouble screenBoundsOfObject3D = RectangleDouble.ZeroIntersection; + for (int i = 0; i < 4; i++) + { + screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetTopCorner(i))); + screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetBottomCorner(i))); + } + + if (touchingBounds.IsTouching(screenBoundsOfObject3D)) + { + Vector3 renderPosition = bounds.Center; + Vector2 objectCenterScreenSpace = this.World.GetScreenPosition(renderPosition); + Point2D screenPositionOfObject3D = new Point2D((int)objectCenterScreenSpace.x, (int)objectCenterScreenSpace.y); + + foundChildren.Add(new WidgetAndPosition(this, screenPositionOfObject3D, object3DName)); + } + } + } + foreach (var child in scene.Children) { string object3DName = child.Name; diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 97b5ea15d..c0e756961 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 97b5ea15d8c467718a4eedaa79142101ce1ab30b +Subproject commit c0e756961265b558607b0dab418dab1e372e8c09 diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 9040a33c4..db24fd8c6 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 9040a33c4af85d8ff9bde011d9043b381b1ca183 +Subproject commit db24fd8c66bbf2034b0f6162e5c35c00282c4a46 diff --git a/Tests/MatterControl.AutomationTests/PartPreviewTests.cs b/Tests/MatterControl.AutomationTests/PartPreviewTests.cs index a2945c4a0..eb0975d7c 100644 --- a/Tests/MatterControl.AutomationTests/PartPreviewTests.cs +++ b/Tests/MatterControl.AutomationTests/PartPreviewTests.cs @@ -233,7 +233,7 @@ namespace MatterHackers.MatterControl.Tests.Automation } [Test] - public async Task MirrorUndoDo() + public async Task ValidateDoUndoOnSceneOperations() { await MatterControlUtilities.RunTest((testRunner) => { @@ -243,55 +243,27 @@ namespace MatterHackers.MatterControl.Tests.Automation var view3D = testRunner.GetWidgetByName("View3DWidget", out _) as View3DWidget; var scene1 = view3D.InteractionLayer.Scene; + testRunner.AddDefaultFileToBedplate(partName: "Row Item MatterControl - Coin.stl"); + + // test z translation RunDoUndoTest(testRunner, scene1, (scene) => { - testRunner.AddDefaultFileToBedplate(partName: "Row Item MatterControl - Coin.stl"); - // TODO: assert the part is centered on the bed - - testRunner.ClickByName("MatterControl - Coin.stl"); - Assert.IsNotNull(scene.SelectedItem); + AddCoinToBed(testRunner, scene); }, (scene) => { - testRunner.ClickByName("Mirror Button"); - testRunner.ClickByName("Mirror Button X"); + testRunner.DragDropByName("MoveInZControl", "MoveInZControl", offsetDrop: new Point2D(0, 40)); }); + // test mirror operations + TestMirrorDoUndo(testRunner, scene1, "Mirror Button X"); + TestMirrorDoUndo(testRunner, scene1, "Mirror Button Y"); + TestMirrorDoUndo(testRunner, scene1, "Mirror Button Z"); + + // test drag x y translation RunDoUndoTest(testRunner, scene1, (scene) => { - testRunner.AddSelectedItemToBedplate(); - testRunner.Delay(.1); - - testRunner.ClickByName("MatterControl - Coin.stl"); - Assert.IsNotNull(scene.SelectedItem); - }, - (scene) => - { - testRunner.ClickByName("Mirror Button"); - testRunner.ClickByName("Mirror Button Y"); - }); - - RunDoUndoTest(testRunner, scene1, (scene) => - { - testRunner.AddSelectedItemToBedplate(); - testRunner.Delay(.1); - - testRunner.ClickByName("MatterControl - Coin.stl"); - Assert.IsNotNull(scene.SelectedItem); - }, - (scene) => - { - testRunner.ClickByName("Mirror Button"); - testRunner.ClickByName("Mirror Button Z"); - }); - - RunDoUndoTest(testRunner, scene1, (scene) => - { - testRunner.AddSelectedItemToBedplate(); - testRunner.Delay(.1); - - testRunner.ClickByName("MatterControl - Coin.stl"); - Assert.IsNotNull(scene.SelectedItem); + AddCoinToBed(testRunner, scene); }, (scene) => { @@ -305,6 +277,29 @@ namespace MatterHackers.MatterControl.Tests.Automation }, overrideWidth: 1300, maxTimeToRun: 200); } + private static void AddCoinToBed(AutomationRunner testRunner, InteractiveScene scene) + { + testRunner.AddSelectedItemToBedplate(); + testRunner.Delay(.1); + // TODO: assert the part is centered on the bed + + testRunner.ClickByName("MatterControl - Coin.stl"); + Assert.IsNotNull(scene.SelectedItem); + } + + private void TestMirrorDoUndo(AutomationRunner testRunner, InteractiveScene scene1, string mirrorButtonName) + { + RunDoUndoTest(testRunner, scene1, (scene) => + { + AddCoinToBed(testRunner, scene); + }, + (scene) => + { + testRunner.ClickByName("Mirror Button"); + testRunner.ClickByName(mirrorButtonName); + }); + } + private void RunDoUndoTest(AutomationRunner testRunner, InteractiveScene scene, Action InitializeTest,