Put in undo for Description and Measure tools.
issue: MatterHackers/MCCentral#6397 Need undo for description and measure tool moves
This commit is contained in:
parent
e8d07222c2
commit
3425b63f98
5 changed files with 82 additions and 19 deletions
|
|
@ -158,7 +158,9 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
{
|
||||
tracedPositionControl = new TracedPositionObject3DControl(object3DControlsLayer,
|
||||
this,
|
||||
// get position function
|
||||
() => worldPosition,
|
||||
// set position function
|
||||
(position) =>
|
||||
{
|
||||
if (!PositionHasBeenSet)
|
||||
|
|
@ -171,7 +173,10 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
worldPosition = position;
|
||||
UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues));
|
||||
}
|
||||
});
|
||||
},
|
||||
// edit complete function
|
||||
(undoPosition) => SetUndoData(undoPosition)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -370,9 +375,27 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
if (mouseDownOnWidget)
|
||||
{
|
||||
mouseDownOnWidget = false;
|
||||
|
||||
SetUndoData(mouseDownPosition);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetUndoData(Vector3 undoPosition)
|
||||
{
|
||||
var doPosition = worldPosition;
|
||||
|
||||
controlLayer.Scene.UndoBuffer.Add(new UndoRedoActions(() =>
|
||||
{
|
||||
worldPosition = undoPosition;
|
||||
this.Invalidate(InvalidateType.Matrix);
|
||||
},
|
||||
() =>
|
||||
{
|
||||
worldPosition = doPosition;
|
||||
this.Invalidate(InvalidateType.Matrix);
|
||||
}));
|
||||
}
|
||||
|
||||
private void GuiSurface_AfterDraw(object sender, DrawEventArgs e)
|
||||
{
|
||||
if (!controlLayer.Scene.Contains(this))
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ 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 System.ComponentModel;
|
||||
using System.IO;
|
||||
|
|
@ -130,34 +131,46 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
{
|
||||
editorControls = new List<IObject3DControl>
|
||||
{
|
||||
// Start Position Object
|
||||
new TracedPositionObject3DControl(object3DControlsLayer,
|
||||
this,
|
||||
// get position function
|
||||
() => worldStartPosition,
|
||||
// set position function
|
||||
(position) =>
|
||||
{
|
||||
if (!PositionsHaveBeenSet)
|
||||
{
|
||||
PositionsHaveBeenSet = true;
|
||||
}
|
||||
if (!PositionsHaveBeenSet)
|
||||
{
|
||||
PositionsHaveBeenSet = true;
|
||||
}
|
||||
|
||||
worldStartPosition = position;
|
||||
Distance = (worldStartPosition - worldEndPosition).Length;
|
||||
UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues));
|
||||
}),
|
||||
Distance = (worldStartPosition - worldEndPosition).Length;
|
||||
UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues));
|
||||
},
|
||||
// edit complete function
|
||||
(undoPosition) => SetUndoData(undoPosition, worldEndPosition)
|
||||
),
|
||||
// End Position Object
|
||||
new TracedPositionObject3DControl(object3DControlsLayer,
|
||||
this,
|
||||
// get position function
|
||||
() => worldEndPosition,
|
||||
// set position function
|
||||
(position) =>
|
||||
{
|
||||
if (!PositionsHaveBeenSet)
|
||||
{
|
||||
PositionsHaveBeenSet = true;
|
||||
}
|
||||
if (!PositionsHaveBeenSet)
|
||||
{
|
||||
PositionsHaveBeenSet = true;
|
||||
}
|
||||
|
||||
worldEndPosition = position;
|
||||
Distance = (worldStartPosition - worldEndPosition).Length;
|
||||
UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues));
|
||||
}),
|
||||
Distance = (worldStartPosition - worldEndPosition).Length;
|
||||
UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues));
|
||||
},
|
||||
// edit complete function
|
||||
(undoPosition) => SetUndoData(worldStartPosition, undoPosition)
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -167,6 +180,25 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
});
|
||||
}
|
||||
|
||||
private void SetUndoData(Vector3 undoStartPosition, Vector3 undoEndPosition)
|
||||
{
|
||||
var doStartPosition = worldStartPosition;
|
||||
var doEndPosition = worldEndPosition;
|
||||
|
||||
controlLayer.Scene.UndoBuffer.Add(new UndoRedoActions(() =>
|
||||
{
|
||||
worldStartPosition = undoStartPosition;
|
||||
worldEndPosition = undoEndPosition;
|
||||
this.Invalidate(InvalidateType.Matrix);
|
||||
},
|
||||
() =>
|
||||
{
|
||||
worldStartPosition = doStartPosition;
|
||||
worldEndPosition = doEndPosition;
|
||||
this.Invalidate(InvalidateType.Matrix);
|
||||
}));
|
||||
}
|
||||
|
||||
public override async void OnInvalidate(InvalidateArgs invalidateType)
|
||||
{
|
||||
if (invalidateType.InvalidateType.HasFlag(InvalidateType.Properties)
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
private IObject3D owner;
|
||||
|
||||
private Action<Vector3> setPosition;
|
||||
|
||||
private Action<Vector3> editComplete;
|
||||
|
||||
private Mesh shape;
|
||||
private bool mouseOver;
|
||||
|
|
@ -68,7 +70,8 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
public TracedPositionObject3DControl(IObject3DControlContext object3DControlContext,
|
||||
IObject3D owner,
|
||||
Func<Vector3> getPosition,
|
||||
Action<Vector3> setPosition)
|
||||
Action<Vector3> setPosition,
|
||||
Action<Vector3> editComplete)
|
||||
{
|
||||
this.Object3DControlContext = object3DControlContext;
|
||||
|
||||
|
|
@ -76,6 +79,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
this.context = object3DControlContext;
|
||||
this.getPosition = getPosition;
|
||||
this.setPosition = setPosition;
|
||||
this.editComplete = editComplete;
|
||||
this.shape = PlatonicSolids.CreateCube();
|
||||
this.shape = SphereObject3D.CreateSphere(1, 15, 10);
|
||||
collisionVolume = shape.CreateBVHData();
|
||||
|
|
@ -216,7 +220,11 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
public void OnMouseUp(Mouse3DEventArgs mouseEvent3D)
|
||||
{
|
||||
DownOnControl = false;
|
||||
if (DownOnControl)
|
||||
{
|
||||
DownOnControl = false;
|
||||
editComplete(mouseDownPosition);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo)
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ namespace MatterHackers.MatterControl.Plugins
|
|||
|
||||
public double PixelsPerMM => inchesPerMm * SheetDpi;
|
||||
|
||||
public BorderDouble PageMarginMM { get; } = new BorderDouble(10, 40, 10, 0);
|
||||
public BorderDouble PageMarginMM { get; } = new BorderDouble(10, 25, 10, 5);
|
||||
|
||||
public BorderDouble PageMarginPixels => PageMarginMM * PixelsPerMM;
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit cba77af8b9a07c6cdce1a41de93c1a0c58d2c36d
|
||||
Subproject commit 92fcf1854bd5538016b8b71295679a07b2f0c9cb
|
||||
Loading…
Add table
Add a link
Reference in a new issue