2018-01-29 13:50:55 -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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2021-05-03 13:56:42 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2019-01-29 07:45:23 -08:00
|
|
|
|
using System.Threading.Tasks;
|
2018-04-26 14:58:38 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2018-01-29 13:50:55 -08:00
|
|
|
|
using MatterHackers.Agg.VertexSource;
|
|
|
|
|
|
using MatterHackers.DataConverters3D;
|
2018-05-02 10:59:08 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2021-05-01 22:14:28 -07:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
|
|
|
|
|
using MatterHackers.Plugins.EditorTools;
|
2021-11-26 12:49:42 -08:00
|
|
|
|
using MatterHackers.PolygonMesh.Processors;
|
2021-09-12 20:23:40 -07:00
|
|
|
|
using MatterHackers.VectorMath;
|
2018-01-29 13:50:55 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.DesignTools
|
|
|
|
|
|
{
|
2021-05-29 22:21:50 -07:00
|
|
|
|
public class ConeObject3D : PrimitiveObject3D, IObject3DControlsProvider
|
2018-01-29 13:50:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
public ConeObject3D()
|
|
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
Name = "Cone".Localize();
|
2018-06-07 14:20:39 -07:00
|
|
|
|
Color = Operations.Object3DExtensions.PrimitiveColors["Cone"];
|
2018-01-29 15:32:01 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-28 08:00:35 -07:00
|
|
|
|
public override string ThumbnailName => "Cone";
|
|
|
|
|
|
|
2019-01-29 07:45:23 -08:00
|
|
|
|
public static async Task<ConeObject3D> Create()
|
2018-01-29 15:32:01 -08:00
|
|
|
|
{
|
|
|
|
|
|
var item = new ConeObject3D();
|
2019-01-31 10:24:06 -08:00
|
|
|
|
await item.Rebuild();
|
|
|
|
|
|
|
2018-01-29 15:32:01 -08:00
|
|
|
|
return item;
|
2018-01-29 13:50:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-12 20:23:40 -07:00
|
|
|
|
[Slider(1, 400, VectorMath.Easing.EaseType.Quadratic, useSnappingGrid: true)]
|
2021-06-05 11:12:26 -07:00
|
|
|
|
public DoubleOrExpression Diameter { 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-06-05 11:12:26 -07:00
|
|
|
|
public DoubleOrExpression Height { get; set; } = 20;
|
2021-04-16 17:03:39 -07:00
|
|
|
|
|
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; } = 40;
|
2018-01-29 13:50:55 -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-01-29 07:45:23 -08:00
|
|
|
|
await Rebuild();
|
2018-06-21 08:01:44 -07:00
|
|
|
|
}
|
2019-02-12 15:56:28 -08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-06-19 21:28:16 -07:00
|
|
|
|
base.OnInvalidate(invalidateArgs);
|
2019-02-12 15:56:28 -08:00
|
|
|
|
}
|
2018-06-20 17:16:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-12 15:56:28 -08:00
|
|
|
|
public override Task Rebuild()
|
2018-01-29 13:50:55 -08:00
|
|
|
|
{
|
2018-05-29 17:46:59 -07:00
|
|
|
|
this.DebugDepth("Rebuild");
|
2018-07-08 13:57:45 -07:00
|
|
|
|
bool changed = false;
|
2018-01-29 17:05:55 -08:00
|
|
|
|
|
2019-02-12 15:56:28 -08:00
|
|
|
|
using (RebuildLock())
|
|
|
|
|
|
{
|
2021-06-05 11:12:26 -07:00
|
|
|
|
var sides = Sides.ClampIfNotCalculated(this, 3, 360, ref changed);
|
2021-06-07 07:45:18 -07:00
|
|
|
|
var diameter = Diameter.ClampIfNotCalculated(this, .01, 1000000, ref changed);
|
|
|
|
|
|
var height = Height.ClampIfNotCalculated(this, .01, 1000000, ref changed);
|
2019-04-19 09:52:49 -07:00
|
|
|
|
using (new CenterAndHeightMaintainer(this))
|
2018-06-20 08:09:35 -07:00
|
|
|
|
{
|
2018-05-27 19:38:53 -07:00
|
|
|
|
|
2019-02-12 15:56:28 -08:00
|
|
|
|
var path = new VertexStorage();
|
|
|
|
|
|
path.MoveTo(0, 0);
|
2021-06-07 07:45:18 -07:00
|
|
|
|
path.LineTo(diameter / 2, 0);
|
|
|
|
|
|
path.LineTo(0, height);
|
2019-02-12 15:56:28 -08:00
|
|
|
|
|
2021-06-05 11:12:26 -07:00
|
|
|
|
Mesh = VertexSourceToMesh.Revolve(path, sides);
|
2019-02-12 15:56:28 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-01-29 07:45:23 -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.Children));
|
|
|
|
|
|
return Task.CompletedTask;
|
2018-01-29 13:50:55 -08:00
|
|
|
|
}
|
2021-05-01 22:14:28 -07:00
|
|
|
|
|
|
|
|
|
|
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
|
|
|
|
|
|
{
|
2021-06-05 11:12:26 -07:00
|
|
|
|
double getHeight() => Height.Value(this);
|
2021-05-29 22:21:50 -07:00
|
|
|
|
void setHeight(double height) => Height = height;
|
2021-06-05 11:12:26 -07:00
|
|
|
|
var getDiameters = new List<Func<double>>() { () => Diameter.Value(this) };
|
2021-05-03 13:56:42 -07:00
|
|
|
|
var setDiameters = new List<Action<double>>() { (diameter) => Diameter = diameter };
|
2021-05-01 22:14:28 -07:00
|
|
|
|
object3DControlsLayer.Object3DControls.Add(new ScaleDiameterControl(object3DControlsLayer,
|
2021-05-29 22:21:50 -07:00
|
|
|
|
getHeight,
|
|
|
|
|
|
setHeight,
|
2021-05-03 13:56:42 -07:00
|
|
|
|
getDiameters,
|
|
|
|
|
|
setDiameters,
|
|
|
|
|
|
0));
|
2021-05-01 22:14:28 -07:00
|
|
|
|
object3DControlsLayer.Object3DControls.Add(new ScaleHeightControl(object3DControlsLayer,
|
2021-05-31 16:12:07 -07:00
|
|
|
|
null,
|
|
|
|
|
|
null,
|
|
|
|
|
|
null,
|
|
|
|
|
|
null,
|
2021-05-29 22:21:50 -07:00
|
|
|
|
getHeight,
|
|
|
|
|
|
setHeight,
|
2021-05-03 13:56:42 -07:00
|
|
|
|
getDiameters,
|
|
|
|
|
|
setDiameters));
|
2021-05-01 22:14:28 -07:00
|
|
|
|
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
|
|
|
|
|
|
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
|
|
|
|
|
|
}
|
2018-01-29 13:50:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|