2018-01-29 13:50:55 -08:00
|
|
|
|
/*
|
2019-05-18 08:48:23 -07:00
|
|
|
|
Copyright (c) 2019, Lars Brubaker, John Lewin
|
2018-01-29 13:50:55 -08:00
|
|
|
|
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-26 18:44:04 -08:00
|
|
|
|
using System.Threading.Tasks;
|
2018-01-29 13:50:55 -08:00
|
|
|
|
using MatterHackers.DataConverters3D;
|
2018-05-02 10:59:08 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2021-05-29 22:21:50 -07:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
2018-01-29 13:50:55 -08:00
|
|
|
|
using MatterHackers.PolygonMesh;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.DesignTools
|
|
|
|
|
|
{
|
2021-05-29 22:21:50 -07:00
|
|
|
|
public class CubeObject3D : PrimitiveObject3D, IObject3DControlsProvider
|
2018-01-29 13:50:55 -08:00
|
|
|
|
{
|
2018-02-23 18:05:13 -08:00
|
|
|
|
public CubeObject3D()
|
2018-01-29 13:50:55 -08:00
|
|
|
|
{
|
2018-05-04 13:47:16 -07:00
|
|
|
|
Name = "Cube".Localize();
|
2018-06-07 14:20:39 -07:00
|
|
|
|
Color = Operations.Object3DExtensions.PrimitiveColors["Cube"];
|
2018-01-29 13:50:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-28 08:00:35 -07:00
|
|
|
|
public override string ThumbnailName => "Cube";
|
|
|
|
|
|
|
2021-05-29 22:21:50 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This is the actual serialized with that can use expressions
|
|
|
|
|
|
/// </summary>
|
2021-04-16 17:03:39 -07:00
|
|
|
|
[MaxDecimalPlaces(2)]
|
2021-08-30 08:47:11 -07:00
|
|
|
|
[Slider(1, 100)]
|
2021-05-31 18:44:00 -07:00
|
|
|
|
public DoubleOrExpression Width { get; set; } = 20;
|
2019-05-18 08:48:23 -07:00
|
|
|
|
|
2021-04-16 17:03:39 -07:00
|
|
|
|
[MaxDecimalPlaces(2)]
|
2021-05-31 18:44:00 -07:00
|
|
|
|
public DoubleOrExpression Depth { get; set; } = 20;
|
2019-05-18 08:48:23 -07:00
|
|
|
|
|
2021-04-16 17:03:39 -07:00
|
|
|
|
[MaxDecimalPlaces(2)]
|
2021-05-31 18:44:00 -07:00
|
|
|
|
public DoubleOrExpression Height { get; set; } = 20;
|
2018-01-29 13:50:55 -08:00
|
|
|
|
|
2019-03-04 14:00:52 -08:00
|
|
|
|
public static async Task<CubeObject3D> Create()
|
2018-01-29 15:32:01 -08:00
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
var item = new CubeObject3D();
|
2019-03-04 14:00:52 -08:00
|
|
|
|
await item.Rebuild();
|
2018-01-29 15:32:01 -08:00
|
|
|
|
return item;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-04 14:00:52 -08:00
|
|
|
|
public static async Task<CubeObject3D> Create(double x, double y, double z)
|
2018-01-29 15:32:01 -08:00
|
|
|
|
{
|
|
|
|
|
|
var item = new CubeObject3D()
|
|
|
|
|
|
{
|
|
|
|
|
|
Width = x,
|
|
|
|
|
|
Depth = y,
|
|
|
|
|
|
Height = z,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-03-04 14:00:52 -08:00
|
|
|
|
await item.Rebuild();
|
2018-01-29 15:32:01 -08:00
|
|
|
|
return item;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-29 22:21:50 -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);
|
2021-05-29 22:21:50 -07: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();
|
|
|
|
|
|
}
|
|
|
|
|
|
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-01-26 18:44:04 -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");
|
2019-02-03 08:09:41 -08:00
|
|
|
|
|
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
|
|
|
|
{
|
2021-05-29 22:21:50 -07:00
|
|
|
|
Mesh = PlatonicSolids.CreateCube(Width.Value(this), Depth.Value(this), Height.Value(this));
|
2018-06-20 08:09:35 -07:00
|
|
|
|
}
|
2018-01-29 17:05:55 -08:00
|
|
|
|
}
|
2019-01-26 18:44:04 -08:00
|
|
|
|
|
2019-02-12 15:56:28 -08:00
|
|
|
|
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
|
2019-01-26 18:44:04 -08:00
|
|
|
|
return Task.CompletedTask;
|
2018-01-29 13:50:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|