2018-08-08 07:49:39 -07: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.Collections.Generic;
|
2020-05-23 22:54:41 -07:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2018-08-08 07:49:39 -07:00
|
|
|
|
using ClipperLib;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
2020-05-23 22:54:41 -07:00
|
|
|
|
using MatterHackers.Agg.VertexSource;
|
2020-06-23 08:28:21 -07:00
|
|
|
|
using MatterHackers.DataConverters2D;
|
2018-08-08 07:49:39 -07:00
|
|
|
|
using MatterHackers.DataConverters3D;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2020-05-23 22:54:41 -07:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
2021-11-26 12:49:42 -08:00
|
|
|
|
using MatterHackers.PolygonMesh.Processors;
|
2022-03-02 00:52:04 +00:00
|
|
|
|
using MatterHackers.VectorMath;
|
2018-08-08 07:49:39 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.DesignTools.Operations
|
|
|
|
|
|
{
|
2020-05-23 22:54:41 -07:00
|
|
|
|
public enum ExpandStyles
|
|
|
|
|
|
{
|
|
|
|
|
|
Flat,
|
|
|
|
|
|
Round,
|
|
|
|
|
|
Sharp,
|
|
|
|
|
|
}
|
2018-08-08 07:49:39 -07:00
|
|
|
|
|
2023-03-11 10:56:32 -08:00
|
|
|
|
public class InflatePathObject3D : PathObject3D, IEditorDraw, IObject3DControlsProvider
|
|
|
|
|
|
{
|
2018-08-08 07:49:39 -07:00
|
|
|
|
public InflatePathObject3D()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Inflate Path".Localize();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-23 22:54:41 -07:00
|
|
|
|
[Description("The amount to expand the path lines.")]
|
2022-08-11 18:37:06 -07:00
|
|
|
|
public DoubleOrExpression Inflate { get; set; } = .2;
|
2018-08-08 07:49:39 -07:00
|
|
|
|
|
2020-05-23 22:54:41 -07:00
|
|
|
|
[EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Buttons)]
|
|
|
|
|
|
public ExpandStyles Style { get; set; } = ExpandStyles.Sharp;
|
|
|
|
|
|
|
2023-11-28 18:16:20 -08:00
|
|
|
|
public override bool MeshIsSolidObject => false;
|
|
|
|
|
|
|
2020-10-11 14:53:46 -07:00
|
|
|
|
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
|
|
|
|
|
|
{
|
|
|
|
|
|
object3DControlsLayer.AddControls(ControlTypes.Standard2D);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-19 21:28:16 -07:00
|
|
|
|
public override async void OnInvalidate(InvalidateArgs invalidateArgs)
|
2018-08-08 07:49:39 -07:00
|
|
|
|
{
|
2021-06-19 21:28:16 -07:00
|
|
|
|
if ((invalidateArgs.InvalidateType.HasFlag(InvalidateType.Children)
|
|
|
|
|
|
|| invalidateArgs.InvalidateType.HasFlag(InvalidateType.Matrix)
|
|
|
|
|
|
|| invalidateArgs.InvalidateType.HasFlag(InvalidateType.Path))
|
|
|
|
|
|
&& invalidateArgs.Source != this
|
2018-08-08 07:49:39 -07:00
|
|
|
|
&& !RebuildLocked)
|
|
|
|
|
|
{
|
2019-02-13 15:45:33 -08:00
|
|
|
|
await Rebuild();
|
2018-08-08 07:49:39 -07:00
|
|
|
|
}
|
2021-06-19 21:28:16 -07:00
|
|
|
|
else 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-08-08 07:49:39 -07:00
|
|
|
|
{
|
2019-02-13 15:45:33 -08:00
|
|
|
|
await Rebuild();
|
2018-08-08 07:49:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-06-19 21:28:16 -07:00
|
|
|
|
base.OnInvalidate(invalidateArgs);
|
2018-08-08 07:49:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-01 18:19:16 -08:00
|
|
|
|
public override Task Rebuild()
|
2018-08-08 07:49:39 -07:00
|
|
|
|
{
|
|
|
|
|
|
this.DebugDepth("Rebuild");
|
|
|
|
|
|
using (RebuildLock())
|
|
|
|
|
|
{
|
|
|
|
|
|
InsetPath();
|
2020-10-16 16:25:11 -07:00
|
|
|
|
// set the mesh to show the path
|
2022-08-09 16:21:39 -07:00
|
|
|
|
this.Mesh = VertexStorage.Extrude(Constants.PathPolygonsHeight);
|
2018-08-08 07:49:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-05 22:01:50 -08:00
|
|
|
|
this.CancelAllParentBuilding();
|
2019-02-13 15:45:33 -08:00
|
|
|
|
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Path));
|
2019-01-29 15:37:06 -08:00
|
|
|
|
return Task.CompletedTask;
|
2018-08-08 07:49:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void InsetPath()
|
|
|
|
|
|
{
|
2022-08-09 16:21:39 -07:00
|
|
|
|
var path = this.CombinedVisibleChildrenPaths();
|
2020-05-23 22:54:41 -07:00
|
|
|
|
if (path == null)
|
2018-08-08 07:49:39 -07:00
|
|
|
|
{
|
2018-11-29 13:41:24 -08:00
|
|
|
|
// clear our existing data
|
2022-08-09 16:21:39 -07:00
|
|
|
|
VertexStorage = new VertexStorage();
|
2018-08-08 07:49:39 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-09 16:21:39 -07:00
|
|
|
|
VertexStorage = path.Offset(Inflate.Value(this), GetJoinType(Style));
|
2020-05-23 22:54:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-14 21:30:40 -07:00
|
|
|
|
public static JoinType GetJoinType(ExpandStyles style)
|
2020-05-23 22:54:41 -07:00
|
|
|
|
{
|
2022-08-14 21:30:40 -07:00
|
|
|
|
ClipperLib.JoinType joinType = JoinType.jtMiter;
|
2020-05-23 22:54:41 -07:00
|
|
|
|
switch (style)
|
|
|
|
|
|
{
|
|
|
|
|
|
case ExpandStyles.Flat:
|
2022-08-14 21:30:40 -07:00
|
|
|
|
joinType = JoinType.jtSquare;
|
2020-05-23 22:54:41 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case ExpandStyles.Round:
|
2022-08-14 21:30:40 -07:00
|
|
|
|
joinType = JoinType.jtRound;
|
2020-05-23 22:54:41 -07:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return joinType;
|
2018-08-08 07:49:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|