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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2020-09-12 13:09:17 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
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-14 19:56:46 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
2018-06-01 17:44:46 -07:00
|
|
|
|
using MatterHackers.MatterControl.DesignTools.EditableTypes;
|
2018-07-01 20:53:42 -07:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
|
|
|
|
|
using MatterHackers.MeshVisualizer;
|
2018-02-12 15:28:26 -08:00
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.DesignTools.Operations
|
|
|
|
|
|
{
|
2021-11-19 15:44:00 -08:00
|
|
|
|
public class ArrayRadialObject3D : ArrayObject3D, IEditorDraw
|
2018-02-12 15:28:26 -08:00
|
|
|
|
{
|
2018-06-21 21:02:37 -07:00
|
|
|
|
public ArrayRadialObject3D()
|
2018-02-12 15:28:26 -08:00
|
|
|
|
{
|
2018-02-16 17:51:05 -08:00
|
|
|
|
Name = "Radial Array".Localize();
|
2018-02-12 15:28:26 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-31 15:10:46 -07:00
|
|
|
|
[DisplayName("Rotate About")]
|
|
|
|
|
|
public DirectionAxis Axis { get; set; } = new DirectionAxis() { Origin = Vector3.NegativeInfinity, Normal = Vector3.UnitZ };
|
|
|
|
|
|
|
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-12 15:28:26 -08:00
|
|
|
|
|
|
|
|
|
|
[Description("Rotate the part to the same angle as the array.")]
|
|
|
|
|
|
public bool RotatePart { get; set; } = true;
|
|
|
|
|
|
|
2019-01-25 13:25:02 -08:00
|
|
|
|
public override async Task Rebuild()
|
2018-05-31 15:10:46 -07:00
|
|
|
|
{
|
2019-01-25 13:25:02 -08:00
|
|
|
|
// check if we have initialized the Axis
|
|
|
|
|
|
if (Axis.Origin.X == double.NegativeInfinity)
|
2018-02-12 15:28:26 -08:00
|
|
|
|
{
|
2019-01-25 13:25:02 -08:00
|
|
|
|
// make it something reasonable (just to the left of the aabb of the object)
|
|
|
|
|
|
Axis.Origin = this.GetAxisAlignedBoundingBox().Center - new Vector3(-30, 0, 0);
|
|
|
|
|
|
}
|
2018-05-31 16:24:09 -07: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-06-20 08:09:35 -07:00
|
|
|
|
|
2019-01-25 13:25:02 -08:00
|
|
|
|
await ApplicationController.Instance.Tasks.Execute(
|
|
|
|
|
|
"Radial Array".Localize(),
|
|
|
|
|
|
null,
|
|
|
|
|
|
(reporter, cancellationToken) =>
|
2018-06-20 08:09:35 -07:00
|
|
|
|
{
|
2019-01-25 13:25:02 -08:00
|
|
|
|
this.DebugDepth("Rebuild");
|
|
|
|
|
|
var aabb = this.GetAxisAlignedBoundingBox();
|
2018-05-31 16:24:09 -07:00
|
|
|
|
|
2022-01-31 17:01:37 -08:00
|
|
|
|
var firstBuild = this.Children.Count == 1;
|
|
|
|
|
|
|
2019-01-25 13:25:02 -08:00
|
|
|
|
var sourceContainer = SourceContainer;
|
|
|
|
|
|
this.Children.Modify(list =>
|
|
|
|
|
|
{
|
|
|
|
|
|
list.Clear();
|
|
|
|
|
|
// add back in the sourceContainer
|
|
|
|
|
|
list.Add(sourceContainer);
|
|
|
|
|
|
// get the source item
|
|
|
|
|
|
var sourceItem = sourceContainer.Children.First();
|
|
|
|
|
|
|
|
|
|
|
|
var offset = Vector3.Zero;
|
2021-06-14 08:00:14 -07:00
|
|
|
|
var count = Count.Value(this);
|
|
|
|
|
|
for (int i = 0; i < Math.Max(count, 1); i++)
|
2019-01-25 13:25:02 -08:00
|
|
|
|
{
|
|
|
|
|
|
var next = sourceItem.Clone();
|
2018-02-17 08:57:56 -08:00
|
|
|
|
|
2019-01-25 13:25:02 -08:00
|
|
|
|
var normal = Axis.Normal.GetNormal();
|
2022-01-30 11:08:02 -08:00
|
|
|
|
var angleRadians = MathHelper.Tau / count * i;
|
2019-01-25 13:25:02 -08:00
|
|
|
|
next.Rotate(Axis.Origin, normal, angleRadians);
|
|
|
|
|
|
|
|
|
|
|
|
if (!RotatePart)
|
|
|
|
|
|
{
|
|
|
|
|
|
var nextAabb = next.GetAxisAlignedBoundingBox();
|
|
|
|
|
|
next.Rotate(nextAabb.Center, normal, -angleRadians);
|
|
|
|
|
|
}
|
2018-02-17 08:57:56 -08:00
|
|
|
|
|
2022-01-31 17:01:37 -08:00
|
|
|
|
next.Matrix *= Matrix4X4.CreateTranslation(-Axis.Origin);
|
|
|
|
|
|
|
2019-01-25 13:25:02 -08:00
|
|
|
|
list.Add(next);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2021-11-23 10:11:25 -08:00
|
|
|
|
|
2022-01-31 17:01:37 -08:00
|
|
|
|
if (firstBuild)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Matrix *= Matrix4X4.CreateTranslation(Axis.Origin);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-07-01 20:53:42 -07:00
|
|
|
|
|
2021-11-19 15:44:00 -08:00
|
|
|
|
public void DrawEditor(Object3DControlsLayer layer, DrawEventArgs e)
|
2018-07-01 20:53:42 -07:00
|
|
|
|
{
|
2022-01-31 17:01:37 -08:00
|
|
|
|
layer.World.RenderDirectionAxis(new DirectionAxis() { Normal = Axis.Normal, Origin = Vector3.Zero }, this.WorldMatrix(), 30);
|
2018-07-01 20:53:42 -07:00
|
|
|
|
}
|
2018-02-12 15:28:26 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|