diff --git a/MatterControl.csproj b/MatterControl.csproj index f5f766ebd..1ae17662f 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -208,7 +208,6 @@ - @@ -219,7 +218,6 @@ - diff --git a/PartPreviewWindow/View3D/SideBar/MirrorControls.cs b/PartPreviewWindow/View3D/SideBar/MirrorControls.cs index 432a510e3..43ce0b6bc 100644 --- a/PartPreviewWindow/View3D/SideBar/MirrorControls.cs +++ b/PartPreviewWindow/View3D/SideBar/MirrorControls.cs @@ -32,7 +32,16 @@ using MatterHackers.Agg.UI; namespace MatterHackers.MatterControl.PartPreviewWindow { - public partial class MirrorControls : PopupActionPanel + public class PopupActionPanel : FlowLayoutWidget, IIgnoredPopupChild + { + public PopupActionPanel() : base(FlowDirection.TopToBottom) + { + this.Padding = 15; + this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; + } + } + + public class MirrorControls : PopupActionPanel { private View3DWidget view3DWidget; diff --git a/PartPreviewWindow/View3D/SideBar/RotateControls.cs b/PartPreviewWindow/View3D/SideBar/RotateControls.cs deleted file mode 100644 index bc21a290f..000000000 --- a/PartPreviewWindow/View3D/SideBar/RotateControls.cs +++ /dev/null @@ -1,165 +0,0 @@ -/* -Copyright (c) 2017, Lars Brubaker, John Lewin -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -The views and conclusions contained in the software and documentation are those -of the authors and should not be interpreted as representing official policies, -either expressed or implied, of the FreeBSD Project. -*/ - -using System.Collections.Generic; -using MatterHackers.Agg; -using MatterHackers.Agg.Image; -using MatterHackers.Agg.PlatformAbstract; -using MatterHackers.Agg.UI; -using MatterHackers.Localizations; -using MatterHackers.MatterControl.CustomWidgets; -using MatterHackers.VectorMath; - -namespace MatterHackers.MatterControl.PartPreviewWindow -{ - public class RotateControls : PopupActionPanel - { - private View3DWidget view3DWidget; - - public RotateControls(View3DWidget view3DWidget, TextImageButtonFactory buttonFactory, TextImageButtonFactory smallMarginButtonFactory) - { - this.view3DWidget = view3DWidget; - this.HAnchor = HAnchor.FitToChildren; - - var degreesContainer = new FlowLayoutWidget(FlowDirection.LeftToRight); - degreesContainer.HAnchor = HAnchor.ParentLeftRight; - degreesContainer.Padding = new BorderDouble(5); - - var degreesLabel = new TextWidget("Degrees".Localize() + ":", textColor: ActiveTheme.Instance.PrimaryTextColor); - degreesContainer.AddChild(degreesLabel); - degreesContainer.AddChild(new HorizontalSpacer()); - - var degreesControl = new MHNumberEdit(45, pixelWidth: 40, allowNegatives: true, allowDecimals: true, increment: 5, minValue: -360, maxValue: 360); - degreesControl.VAnchor = Agg.UI.VAnchor.ParentTop; - degreesContainer.AddChild(degreesControl); - - this.AddChild(degreesContainer); - - var rotateButtonContainer = new FlowLayoutWidget(FlowDirection.LeftToRight) - { - HAnchor = HAnchor.FitToChildren - }; - - // Reused on each button below - var rotateIcon = StaticData.Instance.LoadIcon("icon_rotate_32x32.png", 32, 32); - - var initialMargin = smallMarginButtonFactory.Margin; - - smallMarginButtonFactory.Margin = 0; - - //smallMarginButtonFactory.Margin = 0; - - Button rotateXButton = CreateAxisButton("X", smallMarginButtonFactory.Generate("", rotateIcon)); - rotateXButton.Click += (s, e) => - { - var scene = view3DWidget.Scene; - if (scene.HasSelection) - { - double radians = MathHelper.DegreesToRadians(degreesControl.ActuallNumberEdit.Value); - Matrix4X4 rotation = Matrix4X4.CreateRotationX(radians); - Matrix4X4 undoTransform = scene.SelectedItem.Matrix; - scene.SelectedItem.Matrix = PlatingHelper.ApplyAtCenter(scene.SelectedItem, rotation); - view3DWidget.UndoBuffer.Add(new TransformUndoCommand(view3DWidget, scene.SelectedItem, undoTransform, scene.SelectedItem.Matrix)); - view3DWidget.PartHasBeenChanged(); - Invalidate(); - } - }; - rotateButtonContainer.AddChild(rotateXButton); - - Button rotateYButton = CreateAxisButton("Y", smallMarginButtonFactory.Generate("", rotateIcon)); - rotateYButton.Click += (s, e) => - { - var scene = view3DWidget.Scene; - if (scene.HasSelection) - { - double radians = MathHelper.DegreesToRadians(degreesControl.ActuallNumberEdit.Value); - Matrix4X4 rotation = Matrix4X4.CreateRotationY(radians); - Matrix4X4 undoTransform = scene.SelectedItem.Matrix; - scene.SelectedItem.Matrix = PlatingHelper.ApplyAtCenter(scene.SelectedItem, rotation); - view3DWidget.UndoBuffer.Add(new TransformUndoCommand(view3DWidget, scene.SelectedItem, undoTransform, scene.SelectedItem.Matrix)); - view3DWidget.PartHasBeenChanged(); - Invalidate(); - } - }; - rotateButtonContainer.AddChild(rotateYButton); - - Button rotateZButton = CreateAxisButton("Z", smallMarginButtonFactory.Generate("", rotateIcon)); - rotateZButton.Click += (s, e) => - { - var scene = view3DWidget.Scene; - if (scene.HasSelection) - { - double radians = MathHelper.DegreesToRadians(degreesControl.ActuallNumberEdit.Value); - Matrix4X4 rotation = Matrix4X4.CreateRotationZ(radians); - Matrix4X4 undoTransform = scene.SelectedItem.Matrix; - scene.SelectedItem.Matrix = PlatingHelper.ApplyAtCenter(scene.SelectedItem, rotation); - view3DWidget.UndoBuffer.Add(new TransformUndoCommand(view3DWidget, scene.SelectedItem, undoTransform, scene.SelectedItem.Matrix)); - view3DWidget.PartHasBeenChanged(); - Invalidate(); - } - }; - rotateButtonContainer.AddChild(rotateZButton); - - this.AddChild(rotateButtonContainer); - - Button layFlatButton = buttonFactory.Generate("Align to Bed".Localize(), centerText: true); - layFlatButton.HAnchor = HAnchor.ParentCenter; - layFlatButton.Margin = new BorderDouble(0, 0, 0, 8); - layFlatButton.Cursor = Cursors.Hand; - layFlatButton.Click += (s, e) => - { - var scene = view3DWidget.Scene; - - if (scene.HasSelection) - { - Matrix4X4 undoTransform = scene.SelectedItem.Matrix; - view3DWidget.MakeLowestFaceFlat(scene.SelectedItem); - view3DWidget.UndoBuffer.Add(new TransformUndoCommand(view3DWidget, scene.SelectedItem, undoTransform, scene.SelectedItem.Matrix)); - view3DWidget.PartHasBeenChanged(); - Invalidate(); - } - }; - this.AddChild(layFlatButton); - - smallMarginButtonFactory.Margin = initialMargin; - } - - private static Button CreateAxisButton(string axis, Button button) - { - var textWidget = new TextWidget(axis, pointSize: 10, textColor: ActiveTheme.Instance.PrimaryTextColor); - textWidget.Margin = new BorderDouble(3, 0, 0, 0); - textWidget.AnchorCenter(); - - button.Margin = new BorderDouble(0, 0, 12, 0); - button.AddChild(textWidget); - - return button; - } - } -} \ No newline at end of file diff --git a/PartPreviewWindow/View3D/SideBar/ScaleControls.cs b/PartPreviewWindow/View3D/SideBar/ScaleControls.cs deleted file mode 100644 index 3fbe4064a..000000000 --- a/PartPreviewWindow/View3D/SideBar/ScaleControls.cs +++ /dev/null @@ -1,329 +0,0 @@ -/* -Copyright (c) 2017, Lars Brubaker, John Lewin -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -The views and conclusions contained in the software and documentation are those -of the authors and should not be interpreted as representing official policies, -either expressed or implied, of the FreeBSD Project. -*/ - -using System; -using System.Collections.Generic; -using MatterHackers.Agg; -using MatterHackers.Agg.UI; -using MatterHackers.Localizations; -using MatterHackers.MatterControl.CustomWidgets; -using MatterHackers.VectorMath; - -namespace MatterHackers.MatterControl.PartPreviewWindow -{ - public class PopupActionPanel : FlowLayoutWidget, IIgnoredPopupChild - { - public PopupActionPanel() : base(FlowDirection.TopToBottom) - { - this.Padding = 15; - this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; - } - } - - public class ScaleControls : PopupActionPanel - { - private Button applyScaleButton; - private MHNumberEdit scaleRatioControl; - private EditableNumberDisplay[] sizeDisplay = new EditableNumberDisplay[3]; - private CheckBox uniformScale; - private View3DWidget view3DWidget; - - public ScaleControls(View3DWidget view3DWidget, TextImageButtonFactory buttonFactory) - { - this.view3DWidget = view3DWidget; - - List scaleControls = new List(); - - // Put in the scale ratio edit field - { - var scaleRatioContainer = new FlowLayoutWidget(FlowDirection.LeftToRight); - scaleRatioContainer.HAnchor = HAnchor.ParentLeftRight; - scaleRatioContainer.Padding = new BorderDouble(5); - - var scaleRatioLabel = new TextWidget("Ratio".Localize() + ":", textColor: ActiveTheme.Instance.PrimaryTextColor); - scaleRatioLabel.Margin = new BorderDouble(0, 0, 3, 0); - scaleRatioLabel.VAnchor = VAnchor.ParentCenter; - scaleRatioContainer.AddChild(scaleRatioLabel); - - scaleRatioContainer.AddChild(new HorizontalSpacer()); - - scaleRatioControl = new MHNumberEdit(1, pixelWidth: 50 * GuiWidget.DeviceScale, allowDecimals: true, increment: .05); - scaleRatioControl.SelectAllOnFocus = true; - scaleRatioControl.VAnchor = VAnchor.ParentCenter; - scaleRatioContainer.AddChild(scaleRatioControl); - scaleRatioControl.ActuallNumberEdit.KeyPressed += (sender, e) => - { - OnSelectedTransformChanged(this, null); - }; - - scaleRatioControl.ActuallNumberEdit.KeyDown += (sender, e) => - { - OnSelectedTransformChanged(this, null); - }; - - scaleRatioControl.ActuallNumberEdit.EnterPressed += (object sender, KeyEventArgs keyEvent) => - { - ApplyScaleFromEditField(); - }; - - scaleRatioContainer.AddChild(CreateScaleDropDownMenu()); - - this.AddChild(scaleRatioContainer); - - scaleControls.Add(scaleRatioControl); - } - - applyScaleButton = buttonFactory.Generate("Apply Scale".Localize(), centerText: true); - applyScaleButton.Cursor = Cursors.Hand; - this.AddChild(applyScaleButton); - - scaleControls.Add(applyScaleButton); - applyScaleButton.Click += (s, e) => - { - ApplyScaleFromEditField(); - }; - - // add in the dimensions - { - this.AddChild(CreateAxisScalingControl("x".ToUpper(), 0, buttonFactory)); - this.AddChild(CreateAxisScalingControl("y".ToUpper(), 1, buttonFactory)); - this.AddChild(CreateAxisScalingControl("z".ToUpper(), 2, buttonFactory)); - - uniformScale = new CheckBox("Lock Ratio".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor); - uniformScale.Checked = true; - - FlowLayoutWidget leftToRight = new FlowLayoutWidget(); - leftToRight.Padding = new BorderDouble(5, 3); - - leftToRight.AddChild(uniformScale); - this.AddChild(leftToRight); - } - - view3DWidget.SelectedTransformChanged += OnSelectedTransformChanged; - } - - private void ApplyScaleFromEditField() - { - if (view3DWidget.Scene.HasSelection) - { - Matrix4X4 startingTransform = view3DWidget.Scene.SelectedItem.Matrix; - Vector3 currentScale = view3DWidget.Scene.SelectedItem.ExtraData.CurrentScale; - - double scale = scaleRatioControl.ActuallNumberEdit.Value; - if (scale > 0) - { - ScaleAxis(scale, 0); - - view3DWidget.Scene.SelectedItem.ExtraData.CurrentScale.y = currentScale.y; - view3DWidget.Scene.SelectedItem.ExtraData.CurrentScale.z = currentScale.z; - ScaleAxis(scale, 1); - - view3DWidget.Scene.SelectedItem.ExtraData.CurrentScale.z = currentScale.z; - ScaleAxis(scale, 2); - } - - view3DWidget.AddUndoForSelectedMeshGroupTransform(startingTransform); - } - } - - private GuiWidget CreateAxisScalingControl(string axis, int axisIndex, TextImageButtonFactory buttonFactory) - { - var leftToRight = new FlowLayoutWidget() - { - Padding = new BorderDouble(5, 3) - }; - - var sizeDescription = new TextWidget("{0}:".FormatWith(axis), textColor: ActiveTheme.Instance.PrimaryTextColor); - sizeDescription.VAnchor = VAnchor.ParentCenter; - leftToRight.AddChild(sizeDescription); - - sizeDisplay[axisIndex] = new EditableNumberDisplay(buttonFactory, "100", "1000.00"); - sizeDisplay[axisIndex].EditComplete += (sender, e) => - { - if (view3DWidget.Scene.HasSelection) - { - Matrix4X4 startingTransform = view3DWidget.Scene.SelectedItem.Matrix; - SetNewModelSize(sizeDisplay[axisIndex].GetValue(), axisIndex); - sizeDisplay[axisIndex].SetDisplayString("{0:0.00}".FormatWith(view3DWidget.Scene.SelectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity).Size[axisIndex])); - OnSelectedTransformChanged(null, null); - view3DWidget.AddUndoForSelectedMeshGroupTransform(startingTransform); - } - else - { - sizeDisplay[axisIndex].SetDisplayString("---"); - } - }; - - leftToRight.AddChild(sizeDisplay[axisIndex]); - - return leftToRight; - } - - private DropDownMenu CreateScaleDropDownMenu() - { - var presetScaleMenu = new DropDownMenu("", Direction.Down) - { - NormalArrowColor = ActiveTheme.Instance.PrimaryTextColor, - HoverArrowColor = ActiveTheme.Instance.PrimaryTextColor, - MenuAsWideAsItems = false, - AlignToRightEdge = true, - //presetScaleMenu.OpenOffset = new Vector2(-50, 0); - HAnchor = HAnchor.AbsolutePosition, - VAnchor = VAnchor.AbsolutePosition, - Width = 25, - Height = scaleRatioControl.Height + 2 - }; - - presetScaleMenu.AddItem("mm to in (.0393)"); - presetScaleMenu.AddItem("in to mm (25.4)"); - presetScaleMenu.AddItem("mm to cm (.1)"); - presetScaleMenu.AddItem("cm to mm (10)"); - presetScaleMenu.AddItem("none".Localize() + " (1)"); - - presetScaleMenu.SelectionChanged += (sender, e) => - { - double scale = 1; - switch (presetScaleMenu.SelectedIndex) - { - case 0: - scale = 1.0 / 25.4; - break; - - case 1: - scale = 25.4; - break; - - case 2: - scale = .1; - break; - - case 3: - scale = 10; - break; - - case 4: - scale = 1; - break; - } - - scaleRatioControl.ActuallNumberEdit.Value = scale; - }; - - return presetScaleMenu; - } - - private void ScaleAxis(double scaleIn, int axis) - { - var selectedItem = view3DWidget.Scene.SelectedItem; - AxisAlignedBoundingBox originalMeshBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity); - - AxisAlignedBoundingBox scaledBounds = selectedItem.GetAxisAlignedBoundingBox(selectedItem.Matrix); - - // first we remove any scale we have applied and then scale to the new value - Vector3 axisRemoveScalings = Vector3.One; - if(originalMeshBounds.XSize > 0 && scaledBounds.XSize > 0) axisRemoveScalings.x = originalMeshBounds.XSize / scaledBounds.XSize; - if (originalMeshBounds.YSize > 0 && scaledBounds.YSize > 0) axisRemoveScalings.y = originalMeshBounds.YSize / scaledBounds.YSize; - if (originalMeshBounds.ZSize > 0 && scaledBounds.ZSize > 0) axisRemoveScalings.z = originalMeshBounds.ZSize / scaledBounds.ZSize; - - Matrix4X4 removeScaleMatrix = Matrix4X4.CreateScale(axisRemoveScalings); - - Vector3 newScale = selectedItem.ExtraData.CurrentScale; - newScale[axis] = scaleIn; - Matrix4X4 totalScale = Matrix4X4.CreateScale(newScale); - - selectedItem.Matrix = PlatingHelper.ApplyAtCenter(selectedItem, totalScale); - - PlatingHelper.PlaceMeshAtHeight(selectedItem, originalMeshBounds.minXYZ.z); - - view3DWidget.PartHasBeenChanged(); - Invalidate(); - view3DWidget.Scene.SelectedItem.ExtraData.CurrentScale[axis] = scaleIn; - OnSelectedTransformChanged(this, null); - } - - private void SetNewModelSize(double sizeInMm, int axis) - { - if (view3DWidget.Scene.HasSelection) - { - // because we remove any current scale before we change to a new one we only get the size of the base mesh data - AxisAlignedBoundingBox originalMeshBounds = view3DWidget.Scene.SelectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity); - - double currentSize = originalMeshBounds.Size[axis]; - double desiredSize = sizeDisplay[axis].GetValue(); - double scaleFactor = 1; - if (currentSize != 0) - { - scaleFactor = desiredSize / currentSize; - } - - if (uniformScale.Checked) - { - scaleRatioControl.ActuallNumberEdit.Value = scaleFactor; - ApplyScaleFromEditField(); - } - else - { - ScaleAxis(scaleFactor, axis); - } - } - } - - private void OnSelectedTransformChanged(object sender, EventArgs e) - { - if (sizeDisplay[0] != null - && view3DWidget.Scene.HasSelection) - { - var selectedItem = view3DWidget.Scene.SelectedItem; - - // TODO: jlewin - could be this simple but how do we call old/new transform values from this context given they've likely been updated and we track one value - // AxisAlignedBoundingBox bounds = view3DWidget.SelectedObject3D.GetAxisAlignedBoundingBox(); - AxisAlignedBoundingBox bounds = selectedItem.GetAxisAlignedBoundingBox(selectedItem.Matrix); - sizeDisplay[0].SetDisplayString("{0:0.00}".FormatWith(bounds.Size[0])); - sizeDisplay[1].SetDisplayString("{0:0.00}".FormatWith(bounds.Size[1])); - sizeDisplay[2].SetDisplayString("{0:0.00}".FormatWith(bounds.Size[2])); - - // set the scaling to be this new size - AxisAlignedBoundingBox originalMeshBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity); - AxisAlignedBoundingBox scaledBounds = selectedItem.GetAxisAlignedBoundingBox(selectedItem.Matrix); - Vector3 currentScale = new Vector3(); - currentScale.x = scaledBounds.XSize / originalMeshBounds.XSize; - currentScale.y = scaledBounds.YSize / originalMeshBounds.YSize; - currentScale.z = scaledBounds.ZSize / originalMeshBounds.ZSize; - - selectedItem.ExtraData.CurrentScale = currentScale; - } - else - { - sizeDisplay[0].SetDisplayString("---"); - sizeDisplay[1].SetDisplayString("---"); - sizeDisplay[2].SetDisplayString("---"); - } - } - } -} \ No newline at end of file diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index 495d900fb..13abbd40a 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -423,20 +423,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // Normal margin factory var normalMarginButtonFactory = ApplicationController.Instance.Theme.BreadCrumbButtonFactory; - var rotateButton = new PopupButton(smallMarginButtonFactory.Generate("Rotate".Localize())) - { - PopDirection = Direction.Up, - PopupContent = new RotateControls(this, normalMarginButtonFactory, smallMarginButtonFactory) - }; - doEdittingButtonsContainer.AddChild(rotateButton); - - var scaleButton = new PopupButton(smallMarginButtonFactory.Generate("Scale".Localize())) - { - PopDirection = Direction.Up, - PopupContent = new ScaleControls(this, normalMarginButtonFactory) - }; - doEdittingButtonsContainer.AddChild(scaleButton); - var mirrorButton = new PopupButton(smallMarginButtonFactory.Generate("Mirror".Localize())) { PopDirection = Direction.Up,