array tools are rebuilding correctly

This commit is contained in:
Lars Brubaker 2018-05-31 16:24:09 -07:00
parent 6cf694dc7b
commit 9f98291014
5 changed files with 79 additions and 42 deletions

View file

@ -27,11 +27,11 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.Linq;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.VectorMath;
using System.Linq;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
@ -57,7 +57,14 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public bool ScaleOffset { get; set; } = true;
public void Rebuild(UndoBuffer undoBuffer)
public override void Apply(UndoBuffer undoBuffer)
{
OperationSource.Apply(this);
base.Apply(undoBuffer);
}
public override void Rebuild(UndoBuffer undoBuffer)
{
this.DebugDepth("Rebuild");
this.Children.Modify(list =>
@ -92,12 +99,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public override void Remove(UndoBuffer undoBuffer)
{
this.Children.Modify(list =>
{
IObject3D firstChild = list.First();
list.Clear();
list.Add(firstChild);
});
OperationSource.Remove(this);
base.Remove(undoBuffer);
}

View file

@ -51,11 +51,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public override void Apply(UndoBuffer undoBuffer)
{
this.Children.Modify(list =>
{
var sourceItem = list.First(c => c is OperationSource);
list.Remove(sourceItem);
});
OperationSource.Apply(this);
base.Apply(undoBuffer);
}
@ -86,11 +82,10 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
this.Children.Modify(list =>
{
list.Clear();
var sourceItem = sourceContainer.Children.First();
// 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++)
{
@ -101,17 +96,13 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
});
this.ResumeRebuild();
this.Invalidate(new InvalidateArgs(this, InvalidateType.Content));
}
public override void Remove(UndoBuffer undoBuffer)
{
this.Children.Modify(list =>
{
var sourceItem = list.First(c => c is OperationSource).Children.First();
list.Clear();
list.Add(sourceItem);
});
OperationSource.Remove(this);
base.Remove(undoBuffer);
}

View file

@ -31,6 +31,7 @@ using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.VectorMath;
using System;
using System.ComponentModel;
using System.Linq;
@ -64,11 +65,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public override void Apply(UndoBuffer undoBuffer)
{
this.Children.Modify(list =>
{
var sourceItem = list.First(c => c is OperationSource);
list.Remove(sourceItem);
});
OperationSource.Apply(this);
base.Apply(undoBuffer);
}
@ -94,22 +91,27 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
this.SuspendRebuild();
this.DebugDepth("Rebuild");
// check if we have initialized the Axis
if (Axis.Origin.X == double.NegativeInfinity)
{
// make it something reasonable (just to the left of the aabb of the object)
var aabb = this.GetAxisAlignedBoundingBox();
Axis.Origin = aabb.Center - new Vector3(30, 0, 0);
}
var sourceContainer = OperationSource.GetOrCreateSourceContainer(this);
this.Children.Modify(list =>
{
IObject3D first = list.First();
list.Clear();
list.Add(first);
// add back in the sourceContainer
list.Add(sourceContainer);
// get the source item
var sourceItem = sourceContainer.Children.First();
var offset = Vector3.Zero;
for (int i = 1; i < Count; i++)
for (int i = 0; i < Math.Max(Count, 1); i++)
{
var next = first.Clone();
var next = sourceItem.Clone();
var normal = Axis.Normal.GetNormal();
var angleRadians = MathHelper.DegreesToRadians(Angle) / Count * i;
@ -124,17 +126,15 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
list.Add(next);
}
});
this.ResumeRebuild();
this.Invalidate(new InvalidateArgs(this, InvalidateType.Content));
}
public override void Remove(UndoBuffer undoBuffer)
{
this.Children.Modify(list =>
{
IObject3D firstChild = list.First();
list.Clear();
list.Add(firstChild);
});
OperationSource.Remove(this);
base.Remove(undoBuffer);
}

View file

@ -27,10 +27,10 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Linq;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using System;
using System.Linq;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
@ -54,6 +54,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
/// <returns>The existing or created OperationSource</returns>
public static IObject3D GetOrCreateSourceContainer(IObject3D parent)
{
parent.SuspendRebuild();
var sourceContainer = parent.Children.FirstOrDefault(c => c is OperationSource);
if (sourceContainer == null)
{
@ -64,8 +65,51 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
parent.Children.Remove(firstChild);
sourceContainer.Children.Add(firstChild);
}
parent.ResumeRebuild();
return sourceContainer;
}
/// <summary>
/// Do the work of apply for a parent that has a source Operation in it
/// </summary>
/// <param name="parent"></param>
public static void Apply(IObject3D parent)
{
parent.SuspendRebuild();
// The idea is we leave everything but the source and that is the applied operation
parent.Children.Modify(list =>
{
var sourceItem = list.FirstOrDefault(c => c is OperationSource);
if (sourceItem != null)
{
list.Remove(sourceItem);
}
});
parent.ResumeRebuild();
}
internal static void Remove(IObject3D parent)
{
parent.SuspendRebuild();
parent.Children.Modify(list =>
{
var sourceItem = list.FirstOrDefault(c => c is OperationSource);
if (sourceItem != null)
{
IObject3D firstChild = sourceItem.Children.First();
if (firstChild != null)
{
list.Clear();
list.Add(firstChild);
}
}
});
parent.ResumeRebuild();
}
}
}