2018-02-07 15:57:27 -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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2019-01-29 15:37:06 -08:00
|
|
|
|
using System.Threading.Tasks;
|
2018-02-07 15:57:27 -08:00
|
|
|
|
using MatterHackers.Agg.VertexSource;
|
|
|
|
|
|
using MatterHackers.DataConverters3D;
|
2018-05-02 10:59:08 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2021-05-31 16:12:07 -07:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
|
|
|
|
|
using MatterHackers.Plugins.EditorTools;
|
2021-11-26 12:49:42 -08:00
|
|
|
|
using MatterHackers.PolygonMesh.Processors;
|
2018-02-07 15:57:27 -08:00
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.DesignTools
|
|
|
|
|
|
{
|
2021-05-31 16:12:07 -07:00
|
|
|
|
public class HalfWedgeObject3D : PrimitiveObject3D, IObject3DControlsProvider
|
2018-02-07 15:57:27 -08:00
|
|
|
|
{
|
2018-04-27 10:13:45 -07:00
|
|
|
|
public HalfWedgeObject3D()
|
2018-02-07 15:57:27 -08:00
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
Name = "Half Wedge".Localize();
|
2018-06-07 14:20:39 -07:00
|
|
|
|
Color = Operations.Object3DExtensions.PrimitiveColors["HalfWedge"];
|
2018-02-07 15:57:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-28 08:00:35 -07:00
|
|
|
|
public override string ThumbnailName => "Half Wedge";
|
|
|
|
|
|
|
2019-03-04 14:00:52 -08:00
|
|
|
|
public static async Task<HalfWedgeObject3D> Create()
|
2018-02-07 15:57:27 -08:00
|
|
|
|
{
|
2018-04-27 10:13:45 -07:00
|
|
|
|
var item = new HalfWedgeObject3D();
|
2018-02-07 15:57:27 -08:00
|
|
|
|
|
2019-03-04 14:00:52 -08:00
|
|
|
|
await item.Rebuild();
|
2018-02-07 15:57:27 -08:00
|
|
|
|
return item;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-16 17:03:39 -07:00
|
|
|
|
[MaxDecimalPlaces(2)]
|
2021-09-12 20:23:40 -07:00
|
|
|
|
[Slider(1, 400, Easing.EaseType.Quadratic, snapDistance: 1)]
|
2021-05-31 18:44:00 -07:00
|
|
|
|
public DoubleOrExpression Width { get; set; } = 20;
|
2021-04-16 17:03:39 -07:00
|
|
|
|
|
|
|
|
|
|
[MaxDecimalPlaces(2)]
|
2021-09-12 20:23:40 -07:00
|
|
|
|
[Slider(1, 400, Easing.EaseType.Quadratic, snapDistance: 1)]
|
2021-05-31 18:44:00 -07:00
|
|
|
|
public DoubleOrExpression Depth { get; set; } = 20;
|
2021-04-16 17:03:39 -07:00
|
|
|
|
|
|
|
|
|
|
[MaxDecimalPlaces(2)]
|
2021-09-12 20:23:40 -07:00
|
|
|
|
[Slider(1, 400, VectorMath.Easing.EaseType.Quadratic, useSnappingGrid: true)]
|
2021-05-31 18:44:00 -07:00
|
|
|
|
public DoubleOrExpression Height { get; set; } = 10;
|
2018-02-07 15:57:27 -08:00
|
|
|
|
|
2021-06-19 21:28:16 -07:00
|
|
|
|
public override async void OnInvalidate(InvalidateArgs invalidateArgs)
|
2018-06-20 17:16:38 -07:00
|
|
|
|
{
|
2021-06-19 21:28:16 -07:00
|
|
|
|
if ((invalidateArgs.InvalidateType.HasFlag(InvalidateType.Properties) && invalidateArgs.Source == this))
|
|
|
|
|
|
{
|
|
|
|
|
|
await Rebuild();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (SheetObject3D.NeedsRebuild(this, invalidateArgs))
|
2018-06-20 17:16:38 -07:00
|
|
|
|
{
|
2019-02-12 15:56:28 -08:00
|
|
|
|
await Rebuild();
|
2018-06-20 17:16:38 -07:00
|
|
|
|
}
|
2018-06-21 08:01:44 -07:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-06-19 21:28:16 -07:00
|
|
|
|
base.OnInvalidate(invalidateArgs);
|
2018-06-21 08:01:44 -07:00
|
|
|
|
}
|
2018-06-20 17:16:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-01 18:19:16 -08:00
|
|
|
|
public override Task Rebuild()
|
2018-02-07 15:57:27 -08:00
|
|
|
|
{
|
2018-05-29 17:46:59 -07:00
|
|
|
|
this.DebugDepth("Rebuild");
|
2018-06-20 08:09:35 -07:00
|
|
|
|
using (RebuildLock())
|
|
|
|
|
|
{
|
2019-04-19 09:52:49 -07:00
|
|
|
|
using (new CenterAndHeightMaintainer(this))
|
2018-06-20 08:09:35 -07:00
|
|
|
|
{
|
2019-01-29 15:13:16 -08:00
|
|
|
|
var path = new VertexStorage();
|
|
|
|
|
|
path.MoveTo(0, 0);
|
2021-05-31 16:12:07 -07:00
|
|
|
|
path.LineTo(Width.Value(this), 0);
|
|
|
|
|
|
path.LineTo(Width.Value(this) / 2, Height.Value(this));
|
2019-01-29 15:13:16 -08:00
|
|
|
|
|
2021-05-31 16:12:07 -07:00
|
|
|
|
var mesh = VertexSourceToMesh.Extrude(path, Depth.Value(this));
|
2019-01-29 15:13:16 -08:00
|
|
|
|
mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
|
|
|
|
|
|
Mesh = mesh;
|
2018-06-20 08:09:35 -07:00
|
|
|
|
}
|
2018-02-07 15:57:27 -08:00
|
|
|
|
}
|
2018-05-27 19:38:53 -07:00
|
|
|
|
|
2019-02-12 15:56:28 -08:00
|
|
|
|
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
|
2019-01-29 15:37:06 -08:00
|
|
|
|
return Task.CompletedTask;
|
2018-02-07 15:57:27 -08:00
|
|
|
|
}
|
2021-05-31 16:12:07 -07:00
|
|
|
|
|
|
|
|
|
|
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
|
|
|
|
|
|
{
|
2021-06-02 17:58:43 -07:00
|
|
|
|
object3DControlsLayer.AddHeightControl(this, Width, Depth, Height);
|
2021-06-02 10:22:13 -07:00
|
|
|
|
object3DControlsLayer.AddWidthDepthControls(this, Width, Depth, Height);
|
2021-05-31 16:12:07 -07:00
|
|
|
|
|
|
|
|
|
|
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
|
|
|
|
|
|
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
|
|
|
|
|
|
}
|
2018-02-07 15:57:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|