Put in some transform undoing in 3D view (much better)
This commit is contained in:
parent
0f178bfb0d
commit
79dd8a966e
3 changed files with 103 additions and 49 deletions
|
|
@ -185,6 +185,7 @@
|
|||
<Compile Include="PartPreviewWindow\View3D\Gui3D\SnapingIndicator.cs" />
|
||||
<Compile Include="PartPreviewWindow\View3D\Gui3D\SelectionShadow.cs" />
|
||||
<Compile Include="PartPreviewWindow\View3D\Gui3D\UpArrow3D.cs" />
|
||||
<Compile Include="PartPreviewWindow\View3D\TransformUndoCommand.cs" />
|
||||
<Compile Include="PartPreviewWindow\View3D\View3DCreateSelectionData.cs" />
|
||||
<Compile Include="PartPreviewWindow\View3D\View3DAlign.cs" />
|
||||
<Compile Include="PartPreviewWindow\View3D\View3DAutoArange.cs" />
|
||||
|
|
|
|||
32
PartPreviewWindow/View3D/TransformUndoCommand.cs
Normal file
32
PartPreviewWindow/View3D/TransformUndoCommand.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||
{
|
||||
internal class TransformUndoCommand : IUndoRedoCommand
|
||||
{
|
||||
private int meshGroupIndex;
|
||||
private Matrix4X4 redoTransform;
|
||||
private Matrix4X4 undoTransform;
|
||||
private View3DWidget view3DWidget;
|
||||
|
||||
public TransformUndoCommand(View3DWidget view3DWidget, MeshGroup selectedMeshGroup, Matrix4X4 undoTransform, Matrix4X4 redoTransform)
|
||||
{
|
||||
this.view3DWidget = view3DWidget;
|
||||
meshGroupIndex = view3DWidget.MeshGroups.IndexOf(selectedMeshGroup);
|
||||
this.undoTransform = undoTransform;
|
||||
this.redoTransform = redoTransform;
|
||||
}
|
||||
|
||||
public void Do()
|
||||
{
|
||||
view3DWidget.MeshGroupTransforms[meshGroupIndex] = redoTransform;
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
view3DWidget.MeshGroupTransforms[meshGroupIndex] = undoTransform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -74,6 +74,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
public partial class View3DWidget : PartPreview3DWidget
|
||||
{
|
||||
private UndoBuffer undoBuffer = new UndoBuffer();
|
||||
public readonly int EditButtonHeight = 44;
|
||||
private Action afterSaveCallback = null;
|
||||
private Button applyScaleButton;
|
||||
|
|
@ -344,30 +345,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
AddSaveAndSaveAs(doEdittingButtonsContainer);
|
||||
}
|
||||
|
||||
KeyDown += (sender, e) =>
|
||||
{
|
||||
KeyEventArgs keyEvent = e as KeyEventArgs;
|
||||
if (keyEvent != null && !keyEvent.Handled)
|
||||
{
|
||||
if (keyEvent.KeyCode == Keys.Delete || keyEvent.KeyCode == Keys.Back)
|
||||
{
|
||||
DeleteSelectedMesh();
|
||||
}
|
||||
|
||||
if (keyEvent.KeyCode == Keys.Escape)
|
||||
{
|
||||
if (CurrentSelectInfo.DownOnPart)
|
||||
{
|
||||
CurrentSelectInfo.DownOnPart = false;
|
||||
|
||||
SelectedMeshGroupTransform = transformOnMouseDown;
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
editToolBar.AddChild(doEdittingButtonsContainer);
|
||||
buttonBottomPanel.AddChild(editToolBar);
|
||||
}
|
||||
|
|
@ -449,7 +426,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
meshViewerWidget.interactionVolumes.Add(new SnappingIndicators(this));
|
||||
|
||||
PluginFinder<InteractionVolumePlugin> InteractionVolumePlugins = new PluginFinder<InteractionVolumePlugin>();
|
||||
foreach(InteractionVolumePlugin plugin in InteractionVolumePlugins.Plugins)
|
||||
foreach (InteractionVolumePlugin plugin in InteractionVolumePlugins.Plugins)
|
||||
{
|
||||
meshViewerWidget.interactionVolumes.Add(plugin.CreateLibraryProvider(this));
|
||||
}
|
||||
|
|
@ -471,6 +448,64 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
#endif
|
||||
}
|
||||
|
||||
public override void OnKeyDown(KeyEventArgs keyEvent)
|
||||
{
|
||||
if (activeButtonBeforeKeyOverride == null)
|
||||
{
|
||||
activeButtonBeforeKeyOverride = viewControls3D.ActiveButton;
|
||||
|
||||
if (keyEvent.Alt)
|
||||
{
|
||||
viewControls3D.ActiveButton = ViewControls3DButtons.Rotate;
|
||||
}
|
||||
else if (keyEvent.Shift)
|
||||
{
|
||||
viewControls3D.ActiveButton = ViewControls3DButtons.Translate;
|
||||
}
|
||||
else if (keyEvent.Control)
|
||||
{
|
||||
viewControls3D.ActiveButton = ViewControls3DButtons.Scale;
|
||||
}
|
||||
}
|
||||
|
||||
switch (keyEvent.KeyCode)
|
||||
{
|
||||
case Keys.Z:
|
||||
if (keyEvent.Control)
|
||||
{
|
||||
undoBuffer.Undo();
|
||||
keyEvent.Handled = true;
|
||||
keyEvent.SuppressKeyPress = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Keys.Y:
|
||||
if (keyEvent.Control)
|
||||
{
|
||||
undoBuffer.Redo();
|
||||
keyEvent.Handled = true;
|
||||
keyEvent.SuppressKeyPress = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Keys.Delete:
|
||||
case Keys.Back:
|
||||
DeleteSelectedMesh();
|
||||
break;
|
||||
|
||||
case Keys.Escape:
|
||||
if (CurrentSelectInfo.DownOnPart)
|
||||
{
|
||||
CurrentSelectInfo.DownOnPart = false;
|
||||
|
||||
SelectedMeshGroupTransform = transformOnMouseDown;
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DragingPart
|
||||
{
|
||||
get { return CurrentSelectInfo.DownOnPart; }
|
||||
|
|
@ -737,29 +772,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
private ViewControls3DButtons? activeButtonBeforeMouseOverride = null;
|
||||
private ViewControls3DButtons? activeButtonBeforeKeyOverride = null;
|
||||
|
||||
public override void OnKeyDown(KeyEventArgs keyEvent)
|
||||
{
|
||||
if (activeButtonBeforeKeyOverride == null)
|
||||
{
|
||||
activeButtonBeforeKeyOverride = viewControls3D.ActiveButton;
|
||||
|
||||
if (keyEvent.Alt)
|
||||
{
|
||||
viewControls3D.ActiveButton = ViewControls3DButtons.Rotate;
|
||||
}
|
||||
else if (keyEvent.Shift)
|
||||
{
|
||||
viewControls3D.ActiveButton = ViewControls3DButtons.Translate;
|
||||
}
|
||||
else if (keyEvent.Control)
|
||||
{
|
||||
viewControls3D.ActiveButton = ViewControls3DButtons.Scale;
|
||||
}
|
||||
}
|
||||
|
||||
base.OnKeyDown(keyEvent);
|
||||
}
|
||||
|
||||
public override void OnKeyUp(KeyEventArgs keyEvent)
|
||||
{
|
||||
if (activeButtonBeforeKeyOverride != null)
|
||||
|
|
@ -915,13 +927,22 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
base.OnMouseMove(mouseEvent);
|
||||
}
|
||||
|
||||
public void AddUndoForSelectedMeshGroupTransform(Matrix4X4 undoTransform)
|
||||
{
|
||||
undoBuffer.Add(new TransformUndoCommand(this, SelectedMeshGroup, transformOnMouseDown, SelectedMeshGroupTransform));
|
||||
}
|
||||
|
||||
public override void OnMouseUp(MouseEventArgs mouseEvent)
|
||||
{
|
||||
if (meshViewerWidget.TrackballTumbleWidget.TransformState == TrackBallController.MouseDownType.None
|
||||
&& CurrentSelectInfo.DownOnPart
|
||||
&& CurrentSelectInfo.LastMoveDelta != Vector3.Zero)
|
||||
{
|
||||
PartHasBeenChanged();
|
||||
if (SelectedMeshGroupTransform != transformOnMouseDown)
|
||||
{
|
||||
AddUndoForSelectedMeshGroupTransform(transformOnMouseDown);
|
||||
PartHasBeenChanged();
|
||||
}
|
||||
}
|
||||
|
||||
CurrentSelectInfo.DownOnPart = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue