Making 2D Paths a more natural part of the system
This commit is contained in:
parent
19d46d6afd
commit
a9b1081bed
20 changed files with 122 additions and 142 deletions
|
|
@ -50,9 +50,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
Sharp,
|
||||
}
|
||||
|
||||
public class InflatePathObject3D : Object3D, IPathObject, IEditorDraw, IObject3DControlsProvider
|
||||
public class InflatePathObject3D : Object3D, IEditorDraw, IObject3DControlsProvider
|
||||
{
|
||||
public IVertexSource VertexSource { get; set; } = new VertexStorage();
|
||||
public override IVertexSource VertexSource { get; set; } = new VertexStorage();
|
||||
|
||||
public InflatePathObject3D()
|
||||
{
|
||||
|
|
@ -111,7 +111,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
|
||||
private void InsetPath()
|
||||
{
|
||||
var path = this.Children.OfType<IPathObject>()?.FirstOrDefault();
|
||||
var path = this.Children.Where(c => c.VertexSource != null).FirstOrDefault();
|
||||
if (path == null)
|
||||
{
|
||||
// clear our existing data
|
||||
|
|
|
|||
|
|
@ -75,19 +75,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
|
||||
public override bool CanApply => true;
|
||||
|
||||
[JsonIgnore]
|
||||
private IVertexSource VertexSource
|
||||
public override IVertexSource GetVertexSource()
|
||||
{
|
||||
get
|
||||
{
|
||||
var item = this.Descendants().Where((d) => d is IPathObject).FirstOrDefault();
|
||||
if (item is IPathObject pathItem)
|
||||
{
|
||||
return pathItem.VertexSource;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return this.CombinedVisibleChildrenPaths();
|
||||
}
|
||||
|
||||
public override void Apply(UndoBuffer undoBuffer)
|
||||
|
|
@ -162,7 +152,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
null,
|
||||
(reporter, cancellationToken) =>
|
||||
{
|
||||
var vertexSource = this.VertexSource;
|
||||
var vertexSource = this.GetVertexSource();
|
||||
List<(double height, double inset)> bevel = null;
|
||||
#if DEBUG
|
||||
if (BevelTop)
|
||||
|
|
@ -178,12 +168,18 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Mesh = VertexSourceToMesh.Extrude(this.VertexSource, height, bevel);
|
||||
if (Mesh.Vertices.Count == 0)
|
||||
if (this.GetVertexSource() != null)
|
||||
{
|
||||
Mesh = null;
|
||||
Mesh = VertexSourceToMesh.Extrude(this.GetVertexSource(), height, bevel);
|
||||
if (Mesh.Vertices.Count == 0)
|
||||
{
|
||||
Mesh = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Mesh = null;
|
||||
}
|
||||
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ using MatterHackers.VectorMath;
|
|||
|
||||
namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||
{
|
||||
public class MergePathObject3D : OperationSourceContainerObject3D, IPathObject, IEditorDraw, IObject3DControlsProvider
|
||||
public class MergePathObject3D : OperationSourceContainerObject3D, IEditorDraw, IObject3DControlsProvider
|
||||
{
|
||||
private ClipperLib.ClipType clipType;
|
||||
private string operationName;
|
||||
|
|
@ -55,7 +55,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
Name = name;
|
||||
}
|
||||
|
||||
public IVertexSource VertexSource { get; set; } = new VertexStorage();
|
||||
public override IVertexSource VertexSource { get; set; } = new VertexStorage();
|
||||
|
||||
public void DrawEditor(Object3DControlsLayer layer, DrawEventArgs e)
|
||||
{
|
||||
|
|
@ -135,7 +135,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
}
|
||||
|
||||
var first = participants.First();
|
||||
var resultsVertexSource = (first as IPathObject).VertexSource.Transform(first.Matrix);
|
||||
var resultsVertexSource = first.VertexSource.Transform(first.Matrix);
|
||||
|
||||
var totalOperations = participants.Count() - 1;
|
||||
double amountPerOperation = 1.0 / totalOperations;
|
||||
|
|
@ -145,9 +145,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
foreach (var item in participants)
|
||||
{
|
||||
if (item != first
|
||||
&& item is IPathObject pathItem)
|
||||
&& item.VertexSource != null)
|
||||
{
|
||||
var itemVertexSource = pathItem.VertexSource.Transform(item.Matrix);
|
||||
var itemVertexSource = item.VertexSource.Transform(item.Matrix);
|
||||
|
||||
resultsVertexSource = resultsVertexSource.MergePaths(itemVertexSource, clipType);
|
||||
|
||||
|
|
|
|||
|
|
@ -45,10 +45,8 @@ using MatterHackers.VectorMath;
|
|||
|
||||
namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||
{
|
||||
public class OutlinePathObject3D : Object3D, IPathObject, IEditorDraw, IObject3DControlsProvider
|
||||
public class OutlinePathObject3D : Object3D, IEditorDraw, IObject3DControlsProvider
|
||||
{
|
||||
public IVertexSource VertexSource { get; set; } = new VertexStorage();
|
||||
|
||||
public OutlinePathObject3D()
|
||||
{
|
||||
Name = "Outline Path".Localize();
|
||||
|
|
@ -57,7 +55,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
[Description("The with of the outline.")]
|
||||
public DoubleOrExpression OutlineWidth { get; set; } = 3;
|
||||
|
||||
public DoubleOrExpression Ratio { get; set; } = .5;
|
||||
[Description("The offset of the outside of the outline as a ratio of the width.")]
|
||||
public DoubleOrExpression Offset { get; set; } = .5;
|
||||
|
||||
[EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Buttons)]
|
||||
public ExpandStyles InnerStyle { get; set; } = ExpandStyles.Sharp;
|
||||
|
|
@ -110,7 +109,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
{
|
||||
InsetPath();
|
||||
// set the mesh to show the path
|
||||
this.Mesh = this.VertexSource.Extrude(Constants.PathPolygonsHeight);
|
||||
this.Mesh = VertexStorage.Extrude(Constants.PathPolygonsHeight);
|
||||
}
|
||||
|
||||
Invalidate(InvalidateType.DisplayValues);
|
||||
|
|
@ -122,20 +121,20 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
|
||||
private void InsetPath()
|
||||
{
|
||||
var path = this.Children.OfType<IPathObject>().FirstOrDefault();
|
||||
var path = this.CombinedVisibleChildrenPaths();
|
||||
if (path == null)
|
||||
{
|
||||
// clear our existing data
|
||||
VertexSource = new VertexStorage();
|
||||
VertexStorage = new VertexStorage();
|
||||
return;
|
||||
}
|
||||
|
||||
var aPolys = path.VertexSource.CreatePolygons();
|
||||
var aPolys = path.CreatePolygons();
|
||||
|
||||
var offseter = new ClipperOffset();
|
||||
|
||||
var outlineWidth = OutlineWidth.Value(this);
|
||||
var ratio = Ratio.Value(this);
|
||||
var ratio = Offset.Value(this);
|
||||
|
||||
offseter.AddPaths(aPolys, InflatePathObject3D.GetJoinType(OuterStyle), EndType.etClosedPolygon);
|
||||
var outerLoops = new List<List<IntPoint>>();
|
||||
|
|
@ -150,9 +149,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
var allLoops = outerLoops;
|
||||
allLoops.AddRange(innerLoops);
|
||||
|
||||
VertexSource = allLoops.CreateVertexStorage();
|
||||
VertexStorage = allLoops.CreateVertexStorage();
|
||||
|
||||
(VertexSource as VertexStorage).Add(0, 0, ShapePath.FlagsAndCommand.Stop);
|
||||
VertexStorage.Add(0, 0, ShapePath.FlagsAndCommand.Stop);
|
||||
}
|
||||
|
||||
public void DrawEditor(Object3DControlsLayer layer, DrawEventArgs e)
|
||||
|
|
|
|||
|
|
@ -70,10 +70,10 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
{
|
||||
get
|
||||
{
|
||||
var item = this.Descendants().Where((d) => d is IPathObject).FirstOrDefault();
|
||||
if (item is IPathObject pathItem)
|
||||
var item = this.Descendants().Where(c => c.VertexSource != null).FirstOrDefault();
|
||||
if (item != null)
|
||||
{
|
||||
return pathItem.VertexSource;
|
||||
return item.VertexSource;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
@ -131,7 +131,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
}
|
||||
}
|
||||
|
||||
(Vector3, Vector3) GetStartEnd(IPathObject pathObject)
|
||||
(Vector3, Vector3) GetStartEnd(IObject3D pathObject)
|
||||
{
|
||||
// draw the line that is the rotation point
|
||||
var aabb = this.GetAxisAlignedBoundingBox();
|
||||
|
|
@ -147,9 +147,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
public void DrawEditor(Object3DControlsLayer layer, DrawEventArgs e)
|
||||
{
|
||||
var child = this.Children.FirstOrDefault();
|
||||
if (child is IPathObject pathObject)
|
||||
if (child?.VertexSource != null)
|
||||
{
|
||||
var (start, end) = GetStartEnd(pathObject);
|
||||
var (start, end) = GetStartEnd(child);
|
||||
layer.World.Render3DLine(start, end, Color.Red, true);
|
||||
layer.World.Render3DLine(start, end, Color.Red.WithAlpha(20), false);
|
||||
}
|
||||
|
|
@ -158,9 +158,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
public AxisAlignedBoundingBox GetEditorWorldspaceAABB(Object3DControlsLayer layer)
|
||||
{
|
||||
var child = this.Children.FirstOrDefault();
|
||||
if (child is IPathObject pathObject)
|
||||
if (child.VertexSource != null)
|
||||
{
|
||||
var (start, end) = GetStartEnd(pathObject);
|
||||
var (start, end) = GetStartEnd(child);
|
||||
return new AxisAlignedBoundingBox(new Vector3[] { start, end });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ using Polygons = System.Collections.Generic.List<System.Collections.Generic.List
|
|||
|
||||
namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||
{
|
||||
public class SmoothPathObject3D : Object3D, IPathObject, IEditorDraw, IObject3DControlsProvider
|
||||
public class SmoothPathObject3D : Object3D, IEditorDraw, IObject3DControlsProvider
|
||||
{
|
||||
public IVertexSource VertexSource { get; set; } = new VertexStorage();
|
||||
public override IVertexSource VertexSource { get; set; } = new VertexStorage();
|
||||
|
||||
public SmoothPathObject3D()
|
||||
{
|
||||
|
|
@ -121,7 +121,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
private void DoSmoothing(long maxDist, int interations)
|
||||
{
|
||||
bool closedPath = true;
|
||||
var path = this.Children.OfType<IPathObject>().FirstOrDefault();
|
||||
var path = this.Children.Where(c => c.VertexSource != null).FirstOrDefault();
|
||||
if (path == null)
|
||||
{
|
||||
// clear our existing data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue