2018-02-12 15:28:26 -08:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2018, 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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2018-03-08 17:23:03 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2018-02-12 15:28:26 -08:00
|
|
|
|
using MatterHackers.DataConverters3D;
|
2018-02-16 17:51:05 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
2018-02-12 15:28:26 -08:00
|
|
|
|
using MatterHackers.VectorMath;
|
2018-05-31 16:24:09 -07:00
|
|
|
|
using System.Linq;
|
2019-01-25 13:25:02 -08:00
|
|
|
|
using System.Threading.Tasks;
|
2018-02-12 15:28:26 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.DesignTools.Operations
|
|
|
|
|
|
{
|
2020-09-12 11:34:18 -07:00
|
|
|
|
public class ArrayAdvancedObject3D : ArrayObject3D
|
2018-02-12 15:28:26 -08:00
|
|
|
|
{
|
2018-06-21 21:02:37 -07:00
|
|
|
|
public ArrayAdvancedObject3D()
|
2018-02-12 15:28:26 -08:00
|
|
|
|
{
|
2018-02-16 17:51:05 -08:00
|
|
|
|
Name = "Advanced Array".Localize();
|
2018-02-12 15:28:26 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-22 15:43:50 -08:00
|
|
|
|
public override bool CanApply => true;
|
2018-02-17 08:57:56 -08:00
|
|
|
|
|
2021-06-14 08:00:14 -07:00
|
|
|
|
public override IntOrExpression Count { get; set; } = 3;
|
2018-02-17 08:57:56 -08:00
|
|
|
|
|
2018-02-12 17:45:57 -08:00
|
|
|
|
public Vector3 Offset { get; set; } = new Vector3(30, 0, 0);
|
2018-02-17 08:57:56 -08:00
|
|
|
|
|
2021-06-14 08:00:14 -07:00
|
|
|
|
public DoubleOrExpression Rotate { get; set; } = -15;
|
2018-02-17 08:57:56 -08:00
|
|
|
|
|
2018-02-12 17:45:57 -08:00
|
|
|
|
public bool RotatePart { get; set; } = true;
|
2018-02-17 08:57:56 -08:00
|
|
|
|
|
2021-06-14 08:00:14 -07:00
|
|
|
|
public DoubleOrExpression Scale { get; set; } = .9;
|
2018-02-17 08:57:56 -08:00
|
|
|
|
|
2018-02-12 17:45:57 -08:00
|
|
|
|
public bool ScaleOffset { get; set; } = true;
|
2018-02-12 15:28:26 -08:00
|
|
|
|
|
2019-01-25 13:25:02 -08:00
|
|
|
|
public override async Task Rebuild()
|
2018-02-12 15:28:26 -08:00
|
|
|
|
{
|
2019-01-25 13:25:02 -08:00
|
|
|
|
var rebuildLock = this.RebuildLock();
|
2019-01-25 16:46:23 -08:00
|
|
|
|
SourceContainer.Visible = true;
|
2018-02-12 15:28:26 -08:00
|
|
|
|
|
2019-01-25 13:25:02 -08:00
|
|
|
|
await ApplicationController.Instance.Tasks.Execute(
|
|
|
|
|
|
"Advanced Array".Localize(),
|
|
|
|
|
|
null,
|
|
|
|
|
|
(reporter, cancellationToken) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
this.DebugDepth("Rebuild");
|
|
|
|
|
|
var sourceContainer = SourceContainer;
|
|
|
|
|
|
this.Children.Modify(list =>
|
2018-02-12 15:28:26 -08:00
|
|
|
|
{
|
2019-01-25 13:25:02 -08:00
|
|
|
|
list.Clear();
|
|
|
|
|
|
list.Add(sourceContainer);
|
|
|
|
|
|
var lastChild = sourceContainer.Children.First();
|
|
|
|
|
|
list.Add(lastChild.Clone());
|
|
|
|
|
|
var offset = Offset;
|
2021-06-14 08:00:14 -07:00
|
|
|
|
var count = Count.Value(this);
|
|
|
|
|
|
var rotate = Rotate.Value(this);
|
|
|
|
|
|
var scale = Scale.Value(this);
|
|
|
|
|
|
for (int i = 1; i < count; i++)
|
2019-01-25 13:25:02 -08:00
|
|
|
|
{
|
2021-06-14 08:00:14 -07:00
|
|
|
|
var rotateRadians = MathHelper.DegreesToRadians(rotate);
|
2019-01-25 13:25:02 -08:00
|
|
|
|
if (ScaleOffset)
|
|
|
|
|
|
{
|
2021-06-14 08:00:14 -07:00
|
|
|
|
offset *= scale;
|
2019-01-25 13:25:02 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var next = lastChild.Clone();
|
|
|
|
|
|
offset = Vector3Ex.Transform(offset, Matrix4X4.CreateRotationZ(rotateRadians));
|
|
|
|
|
|
next.Matrix *= Matrix4X4.CreateTranslation(offset);
|
|
|
|
|
|
|
|
|
|
|
|
if (RotatePart)
|
|
|
|
|
|
{
|
|
|
|
|
|
next.Matrix = next.ApplyAtBoundsCenter(Matrix4X4.CreateRotationZ(rotateRadians));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-14 08:00:14 -07:00
|
|
|
|
next.Matrix = next.ApplyAtBoundsCenter(Matrix4X4.CreateScale(scale));
|
2019-01-25 13:25:02 -08:00
|
|
|
|
list.Add(next);
|
|
|
|
|
|
lastChild = next;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2021-11-23 10:11:25 -08:00
|
|
|
|
|
|
|
|
|
|
ProcessIndexExpressions();
|
|
|
|
|
|
|
2019-01-25 16:46:23 -08:00
|
|
|
|
SourceContainer.Visible = false;
|
2021-05-03 17:58:03 -07:00
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
rebuildLock.Dispose();
|
2021-12-05 22:01:50 -08:00
|
|
|
|
this.CancelAllParentBuilding();
|
2021-05-03 17:58:03 -07:00
|
|
|
|
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
|
|
|
|
|
|
});
|
2019-01-25 13:25:02 -08:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
});
|
2018-02-17 08:57:56 -08:00
|
|
|
|
}
|
2018-02-12 15:28:26 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|