Improvements to operation source object
This commit is contained in:
parent
530f3d2638
commit
57b94fd7a4
5 changed files with 221 additions and 194 deletions
|
|
@ -34,10 +34,11 @@ using MatterHackers.MatterControl.DesignTools.EditableTypes;
|
|||
using MatterHackers.VectorMath;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||
{
|
||||
public class ArrayLinearObject3D : Object3D
|
||||
public class ArrayLinearObject3D : OperationSourceContainerObject3D
|
||||
{
|
||||
public ArrayLinearObject3D()
|
||||
{
|
||||
|
|
@ -49,14 +50,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
public DirectionVector Direction { get; set; } = new DirectionVector { Normal = new Vector3(1, 0, 0) };
|
||||
public double Distance { get; set; } = 30;
|
||||
|
||||
public override void Flatten(UndoBuffer undoBuffer)
|
||||
{
|
||||
OperationSourceObject3D.Flatten(this);
|
||||
|
||||
base.Flatten(undoBuffer);
|
||||
}
|
||||
|
||||
public override void OnInvalidate(InvalidateArgs invalidateType)
|
||||
public override async void OnInvalidate(InvalidateArgs invalidateType)
|
||||
{
|
||||
if ((invalidateType.InvalidateType == InvalidateType.Content
|
||||
|| invalidateType.InvalidateType == InvalidateType.Matrix
|
||||
|
|
@ -64,12 +58,14 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
&& invalidateType.Source != this
|
||||
&& !RebuildLocked)
|
||||
{
|
||||
Rebuild(null);
|
||||
await Rebuild();
|
||||
base.OnInvalidate(new InvalidateArgs(this, InvalidateType.Content, invalidateType.UndoBuffer));
|
||||
}
|
||||
else if (invalidateType.InvalidateType == InvalidateType.Properties
|
||||
&& invalidateType.Source == this)
|
||||
{
|
||||
Rebuild(null);
|
||||
await Rebuild();
|
||||
base.OnInvalidate(new InvalidateArgs(this, InvalidateType.Content, invalidateType.UndoBuffer));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -77,39 +73,41 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
}
|
||||
}
|
||||
|
||||
private void Rebuild(UndoBuffer undoBuffer)
|
||||
public override async Task Rebuild()
|
||||
{
|
||||
using (this.RebuildLock())
|
||||
{
|
||||
this.DebugDepth("Rebuild");
|
||||
//let the Operation Source base rebuild first
|
||||
await base.Rebuild();
|
||||
|
||||
var sourceContainer = OperationSourceObject3D.GetOrCreateSourceContainer(this);
|
||||
var rebuildLock = this.RebuildLock();
|
||||
|
||||
this.Children.Modify(list =>
|
||||
await ApplicationController.Instance.Tasks.Execute(
|
||||
"Linear Array".Localize(),
|
||||
null,
|
||||
(reporter, cancellationToken) =>
|
||||
{
|
||||
list.Clear();
|
||||
// add back in the sourceContainer
|
||||
list.Add(sourceContainer);
|
||||
// get the source item
|
||||
var sourceItem = sourceContainer.Children.First();
|
||||
this.DebugDepth("Rebuild");
|
||||
|
||||
for (int i = 0; i < Math.Max(Count, 1); i++)
|
||||
var sourceContainer = SourceContainer;
|
||||
|
||||
this.Children.Modify(list =>
|
||||
{
|
||||
var next = sourceItem.Clone();
|
||||
next.Matrix = sourceItem.Matrix * Matrix4X4.CreateTranslation(Direction.Normal.GetNormal() * Distance * i);
|
||||
list.Add(next);
|
||||
}
|
||||
list.Clear();
|
||||
// add back in the sourceContainer
|
||||
list.Add(sourceContainer);
|
||||
// get the source item
|
||||
var sourceItem = sourceContainer.Children.First();
|
||||
|
||||
for (int i = 0; i < Math.Max(Count, 1); i++)
|
||||
{
|
||||
var next = sourceItem.Clone();
|
||||
next.Matrix = sourceItem.Matrix * Matrix4X4.CreateTranslation(Direction.Normal.GetNormal() * Distance * i);
|
||||
list.Add(next);
|
||||
}
|
||||
});
|
||||
|
||||
rebuildLock.Dispose();
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
}
|
||||
|
||||
this.Invalidate(new InvalidateArgs(this, InvalidateType.Content));
|
||||
}
|
||||
|
||||
public override void Remove(UndoBuffer undoBuffer)
|
||||
{
|
||||
OperationSourceObject3D.Remove(this);
|
||||
|
||||
base.Remove(undoBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue