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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
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-04-16 17:03:39 -07:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
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 HalfCylinderObject3D : PrimitiveObject3D, IObject3DControlsProvider
|
2018-02-07 15:57:27 -08:00
|
|
|
|
{
|
2018-04-27 10:13:45 -07:00
|
|
|
|
public HalfCylinderObject3D()
|
2018-02-07 15:57:27 -08:00
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
Name = "Half Cylinder".Localize();
|
2018-06-07 14:20:39 -07:00
|
|
|
|
Color = Operations.Object3DExtensions.PrimitiveColors["HalfCylinder"];
|
2018-02-07 15:57:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-28 08:00:35 -07:00
|
|
|
|
public override string ThumbnailName => "Half Cylinder";
|
|
|
|
|
|
|
2019-03-04 14:00:52 -08:00
|
|
|
|
public static async Task<HalfCylinderObject3D> Create()
|
2018-02-07 15:57:27 -08:00
|
|
|
|
{
|
2018-04-27 10:13:45 -07:00
|
|
|
|
var item = new HalfCylinderObject3D();
|
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(3, 360, Easing.EaseType.Quadratic, snapDistance: 1)]
|
2021-06-05 11:12:26 -07:00
|
|
|
|
public IntOrExpression Sides { get; set; } = 20;
|
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();
|
|
|
|
|
|
}
|
2023-03-10 17:15:55 -08:00
|
|
|
|
else if (Expressions.NeedRebuild(this, invalidateArgs))
|
2018-06-20 17:16:38 -07:00
|
|
|
|
{
|
2019-02-12 15:56:28 -08:00
|
|
|
|
await Rebuild();
|
|
|
|
|
|
}
|
|
|
|
|
|
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");
|
2019-02-03 10:05:01 -08:00
|
|
|
|
bool valuesChanged = false;
|
2019-02-12 15:56:28 -08:00
|
|
|
|
|
2018-06-20 08:09:35 -07:00
|
|
|
|
using (RebuildLock())
|
|
|
|
|
|
{
|
2021-06-05 11:12:26 -07:00
|
|
|
|
var sides = Sides.ClampIfNotCalculated(this, 3, 180, ref valuesChanged);
|
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();
|
2021-05-31 16:12:07 -07:00
|
|
|
|
path.MoveTo(Width.Value(this) / 2, 0);
|
2019-01-29 15:13:16 -08:00
|
|
|
|
|
2021-06-05 11:12:26 -07:00
|
|
|
|
for (int i = 1; i < sides; i++)
|
2019-01-29 15:13:16 -08:00
|
|
|
|
{
|
2021-06-05 11:12:26 -07:00
|
|
|
|
var angle = MathHelper.Tau * i / 2 / (sides - 1);
|
2021-05-31 16:12:07 -07:00
|
|
|
|
path.LineTo(Math.Cos(angle) * Width.Value(this) / 2, Math.Sin(angle) * Width.Value(this) / 2);
|
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
|
|
|
|
|
2021-10-01 12:28:06 -07:00
|
|
|
|
Invalidate(InvalidateType.DisplayValues);
|
2019-01-29 15:37:06 -08:00
|
|
|
|
|
2021-12-05 22:01:50 -08:00
|
|
|
|
this.CancelAllParentBuilding();
|
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-04-16 17:03:39 -07:00
|
|
|
|
|
|
|
|
|
|
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
|
|
|
|
|
|
{
|
2021-05-31 16:12:07 -07:00
|
|
|
|
var controls = object3DControlsLayer.Object3DControls;
|
|
|
|
|
|
|
2021-06-02 10:22:13 -07:00
|
|
|
|
object3DControlsLayer.AddWidthDepthControls(this, Width, Depth, null);
|
2021-05-31 16:12:07 -07:00
|
|
|
|
|
2021-04-17 22:35:53 -07:00
|
|
|
|
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
|
|
|
|
|
|
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
|
2021-04-16 17:03:39 -07:00
|
|
|
|
}
|
2018-02-07 15:57:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|