More refactoring
This commit is contained in:
parent
7b65b02d92
commit
962007c3ed
10 changed files with 86 additions and 60 deletions
|
|
@ -90,8 +90,8 @@ namespace MatterHackers.MatterControl
|
||||||
tabShape2.Add(a.X, a.Y, FlagsAndCommand.MoveTo); // A
|
tabShape2.Add(a.X, a.Y, FlagsAndCommand.MoveTo); // A
|
||||||
tabShape2.LineTo(b); // A - B
|
tabShape2.LineTo(b); // A - B
|
||||||
|
|
||||||
tabShape2.curve3(r.X, r.Y, m.X, m.Y); // B -> C
|
tabShape2.Curve3(r.X, r.Y, m.X, m.Y); // B -> C
|
||||||
tabShape2.curve3(c.X, c.Y);
|
tabShape2.Curve3(c.X, c.Y);
|
||||||
|
|
||||||
tabShape2.LineTo(d); // C -> D
|
tabShape2.LineTo(d); // C -> D
|
||||||
tabShape2.LineTo(e); // D -> E
|
tabShape2.LineTo(e); // D -> E
|
||||||
|
|
|
||||||
|
|
@ -208,9 +208,9 @@ namespace MatterHackers.Plugins.EditorTools
|
||||||
|
|
||||||
for (var i = 0; i < vertexStorage.Count; i++)
|
for (var i = 0; i < vertexStorage.Count; i++)
|
||||||
{
|
{
|
||||||
var command = vertexStorage.vertex(i, out double x, out double y);
|
var command = vertexStorage.Vertex(i, out double x, out double y);
|
||||||
|
|
||||||
if (ShapePath.is_vertex(command))
|
if (ShapePath.IsVertex(command))
|
||||||
{
|
{
|
||||||
if (command == ShapePath.FlagsAndCommand.Curve4)
|
if (command == ShapePath.FlagsAndCommand.Curve4)
|
||||||
{
|
{
|
||||||
|
|
@ -224,12 +224,12 @@ namespace MatterHackers.Plugins.EditorTools
|
||||||
context.GuiSurface.AddChild(controlPoint1);
|
context.GuiSurface.AddChild(controlPoint1);
|
||||||
targets.Add(controlPoint1);
|
targets.Add(controlPoint1);
|
||||||
|
|
||||||
command = vertexStorage.vertex(i + 1, out x, out y);
|
command = vertexStorage.Vertex(i + 1, out x, out y);
|
||||||
var controlPoint2 = new CurveControlPoint(context, this, vertexStorage, new Vector3(x, y, 0), command, i + 1);
|
var controlPoint2 = new CurveControlPoint(context, this, vertexStorage, new Vector3(x, y, 0), command, i + 1);
|
||||||
context.GuiSurface.AddChild(controlPoint2);
|
context.GuiSurface.AddChild(controlPoint2);
|
||||||
targets.Add(controlPoint2);
|
targets.Add(controlPoint2);
|
||||||
|
|
||||||
command = vertexStorage.vertex(i + 2, out x, out y);
|
command = vertexStorage.Vertex(i + 2, out x, out y);
|
||||||
var curveWidget = new Curve4AnchorWidget(context, this, vertexStorage, new Vector3(x, y, 0), command, i + 2)
|
var curveWidget = new Curve4AnchorWidget(context, this, vertexStorage, new Vector3(x, y, 0), command, i + 2)
|
||||||
{
|
{
|
||||||
ControlPoint = controlPoint2,
|
ControlPoint = controlPoint2,
|
||||||
|
|
@ -395,7 +395,7 @@ namespace MatterHackers.Plugins.EditorTools
|
||||||
|
|
||||||
if (vertexStorage?.Count >= index)
|
if (vertexStorage?.Count >= index)
|
||||||
{
|
{
|
||||||
vertexStorage.modify_vertex(index, _point.X, _point.Y);
|
vertexStorage.ModifyVertex(index, _point.X, _point.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Invalidate();
|
this.Invalidate();
|
||||||
|
|
|
||||||
|
|
@ -387,11 +387,11 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
g.Line(w * e, 0, w * e, h, theme.TextColor);
|
g.Line(w * e, 0, w * e, h, theme.TextColor);
|
||||||
var leftEdge = new VertexStorage();
|
var leftEdge = new VertexStorage();
|
||||||
leftEdge.MoveTo(w * e, h * .80);
|
leftEdge.MoveTo(w * e, h * .80);
|
||||||
leftEdge.curve3(w * e, h * .70, w * .5, h * .70);
|
leftEdge.Curve3(w * e, h * .70, w * .5, h * .70);
|
||||||
leftEdge.curve3(w * s, h * .60);
|
leftEdge.Curve3(w * s, h * .60);
|
||||||
leftEdge.LineTo(w * s, h * .40);
|
leftEdge.LineTo(w * s, h * .40);
|
||||||
leftEdge.curve3(w * s, h * .30, w * .5, h * .30);
|
leftEdge.Curve3(w * s, h * .30, w * .5, h * .30);
|
||||||
leftEdge.curve3(w * e, h * .20);
|
leftEdge.Curve3(w * e, h * .20);
|
||||||
g.Render(new FlattenCurves(leftEdge), theme.PrimaryAccentColor);
|
g.Render(new FlattenCurves(leftEdge), theme.PrimaryAccentColor);
|
||||||
g.Line(w * .35, h * .6, w * .35, h * .4, theme.BackgroundColor);
|
g.Line(w * .35, h * .6, w * .35, h * .4, theme.BackgroundColor);
|
||||||
g.Line(w * .65, h * .6, w * .65, h * .4, theme.BackgroundColor);
|
g.Line(w * .65, h * .6, w * .65, h * .4, theme.BackgroundColor);
|
||||||
|
|
|
||||||
|
|
@ -276,7 +276,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
var affine = Affine.NewScaling(1.0 / pixelsToIntPointsScale * xScale);
|
var affine = Affine.NewScaling(1.0 / pixelsToIntPointsScale * xScale);
|
||||||
affine *= Affine.NewTranslation(-aabb.XSize / 2, -aabb.YSize / 2);
|
affine *= Affine.NewTranslation(-aabb.XSize / 2, -aabb.YSize / 2);
|
||||||
|
|
||||||
rawVectorShape.transform(affine);
|
rawVectorShape.Transform(affine);
|
||||||
this.VertexStorage = rawVectorShape;
|
this.VertexStorage = rawVectorShape;
|
||||||
|
|
||||||
progressReporter?.Invoke(1, null);
|
progressReporter?.Invoke(1, null);
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
var affine = Affine.NewScaling(1.0 / pixelsToIntPointsScale * xScale);
|
var affine = Affine.NewScaling(1.0 / pixelsToIntPointsScale * xScale);
|
||||||
affine *= Affine.NewTranslation(-aabb.XSize / 2, -aabb.YSize / 2);
|
affine *= Affine.NewTranslation(-aabb.XSize / 2, -aabb.YSize / 2);
|
||||||
|
|
||||||
rawVectorShape.transform(affine);
|
rawVectorShape.Transform(affine);
|
||||||
this.VertexStorage = rawVectorShape;
|
this.VertexStorage = rawVectorShape;
|
||||||
|
|
||||||
progressReporter?.Invoke(1, null);
|
progressReporter?.Invoke(1, null);
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MatterHackers.Agg;
|
using MatterHackers.Agg;
|
||||||
|
using MatterHackers.Agg.Image;
|
||||||
|
using MatterHackers.Agg.Transform;
|
||||||
using MatterHackers.Agg.UI;
|
using MatterHackers.Agg.UI;
|
||||||
using MatterHackers.Agg.VertexSource;
|
using MatterHackers.Agg.VertexSource;
|
||||||
using MatterHackers.DataConverters3D;
|
using MatterHackers.DataConverters3D;
|
||||||
|
|
@ -47,44 +49,51 @@ using MatterHackers.VectorMath;
|
||||||
|
|
||||||
namespace MatterHackers.MatterControl.DesignTools
|
namespace MatterHackers.MatterControl.DesignTools
|
||||||
{
|
{
|
||||||
public class HorizontalOffset2D
|
public class PathEditor : IPropertyEditorFactory
|
||||||
{
|
{
|
||||||
public class ControlPoint
|
public GuiWidget CreateEditor(PropertyEditor propertyEditor, EditableProperty property, EditorContext context)
|
||||||
{
|
{
|
||||||
public double WidthRatio { get; set; } = 1.0;
|
if (property.Value is VertexStorage vertexStorage)
|
||||||
|
|
||||||
public double TopControlRatio { get; set; }
|
|
||||||
|
|
||||||
public double BottomControlRatio { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ControlPoint> ControlPoints { get; set; } = new List<ControlPoint>()
|
|
||||||
{
|
|
||||||
new ControlPoint() { WidthRatio = 1.0, TopControlRatio = .5, BottomControlRatio = 0 },
|
|
||||||
new ControlPoint() { WidthRatio = 1.5, TopControlRatio = .5, BottomControlRatio = .5 },
|
|
||||||
new ControlPoint() { WidthRatio = 1.0, TopControlRatio = 0, BottomControlRatio = .5 },
|
|
||||||
};
|
|
||||||
|
|
||||||
public VertexStorage GetOffsetPath(double radius, double totalHeight)
|
|
||||||
{
|
|
||||||
double segmentHeight = totalHeight / (ControlPoints.Count - 1);
|
|
||||||
var vertexStorage = new VertexStorage();
|
|
||||||
for (int i = 0; i < ControlPoints.Count; i++)
|
|
||||||
{
|
{
|
||||||
if (i == 0)
|
var container = new GuiWidget()
|
||||||
{
|
{
|
||||||
vertexStorage.MoveTo(radius * ControlPoints[0].WidthRatio, 0);
|
HAnchor = HAnchor.Stretch,
|
||||||
}
|
VAnchor = VAnchor.Stretch,
|
||||||
else
|
BackgroundOutlineWidth = 1,
|
||||||
|
BackgroundColor = Color.White,
|
||||||
|
BorderColor = Color.Black,
|
||||||
|
Margin = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
var imageWidget = new ImageWidget(100, 200)
|
||||||
{
|
{
|
||||||
var curPoint = ControlPoints[i];
|
AutoResize = true,
|
||||||
var x = radius * curPoint.WidthRatio;
|
HAnchor = HAnchor.Center,
|
||||||
var y = i * segmentHeight;
|
VAnchor = VAnchor.Center,
|
||||||
vertexStorage.curve4(x, y - curPoint.BottomControlRatio * segmentHeight, x, y - curPoint.TopControlRatio * segmentHeight, x, y);
|
};
|
||||||
|
container.AddChild(imageWidget);
|
||||||
|
|
||||||
|
void RebuildImage(object item, EventArgs e)
|
||||||
|
{
|
||||||
|
imageWidget.Width = container.Width;
|
||||||
|
imageWidget.Height = container.Height;
|
||||||
|
imageWidget.Image.Allocate((int)container.Width, (int)container.Height, 32, new BlenderBGRA());
|
||||||
|
|
||||||
|
var graphics2D = imageWidget.Image.NewGraphics2D();
|
||||||
|
|
||||||
|
var bounds = imageWidget.Image.GetBounds();
|
||||||
|
bounds.Inflate(-1);
|
||||||
|
graphics2D.Rectangle(bounds, Color.Red);
|
||||||
|
|
||||||
|
vertexStorage.RenderCurve(graphics2D, Color.Black, 2, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
container.SizeChanged += RebuildImage;
|
||||||
|
|
||||||
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
return vertexStorage;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,10 +101,12 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
{
|
{
|
||||||
public RadialPinchObject3D()
|
public RadialPinchObject3D()
|
||||||
{
|
{
|
||||||
|
PropertyEditor.RegisterEditor(typeof(VertexStorage), new PathEditor());
|
||||||
|
|
||||||
Name = "Radial Pinch".Localize();
|
Name = "Radial Pinch".Localize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HorizontalOffset2D LinearHorizontalOffset { get; set; } = new HorizontalOffset2D();
|
public VertexStorage PathForHorizontalOffsets { get; set; } = new VertexStorage();
|
||||||
|
|
||||||
[Description("Specifies the number of vertical cuts required to ensure the part can be pinched well.")]
|
[Description("Specifies the number of vertical cuts required to ensure the part can be pinched well.")]
|
||||||
[Slider(0, 50, snapDistance: 1)]
|
[Slider(0, 50, snapDistance: 1)]
|
||||||
|
|
@ -179,8 +190,8 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
var size = sourceAabb.ZSize;
|
var size = sourceAabb.ZSize;
|
||||||
if (Advanced)
|
if (Advanced)
|
||||||
{
|
{
|
||||||
top -= sourceAabb.ZSize * endHeightPercent / 100.0;
|
top = sourceAabb.ZSize * endHeightPercent / 100.0;
|
||||||
bottom += sourceAabb.ZSize * startHeightPercent / 100.0;
|
bottom = sourceAabb.ZSize * startHeightPercent / 100.0;
|
||||||
size = top - bottom;
|
size = top - bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,7 +210,22 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
var rotationCenter = enclosingCircle.Center + RotationOffset;
|
var rotationCenter = enclosingCircle.Center + RotationOffset;
|
||||||
|
|
||||||
var maxRadius = enclosingCircle.Radius + RotationOffset.Length;
|
var maxRadius = enclosingCircle.Radius + RotationOffset.Length;
|
||||||
var horizontalOffset = new FlattenCurves(LinearHorizontalOffset.GetOffsetPath(maxRadius, size));
|
|
||||||
|
//if (PathForHorizontalOffsets.Count == 0)
|
||||||
|
{
|
||||||
|
var bottomPoint = new Vector2(maxRadius, bottom * 10);
|
||||||
|
var topPoint = new Vector2(maxRadius, top * 10);
|
||||||
|
var middlePoint = (bottomPoint + topPoint) / 2;
|
||||||
|
middlePoint.X *= 2;
|
||||||
|
|
||||||
|
PathForHorizontalOffsets.Clear();
|
||||||
|
PathForHorizontalOffsets.MoveTo(bottomPoint);
|
||||||
|
PathForHorizontalOffsets.Curve4(bottomPoint, bottomPoint + new Vector2(.5, .5), middlePoint);
|
||||||
|
PathForHorizontalOffsets.Curve4(middlePoint - new Vector2(0, -1), middlePoint + new Vector2(0, 1), topPoint);
|
||||||
|
PathForHorizontalOffsets.Curve4(topPoint - new Vector2(.5, .5), topPoint, topPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
var horizontalOffset = new FlattenCurves(new VertexSourceApplyTransform(PathForHorizontalOffsets, Affine.NewScaling(10)));
|
||||||
|
|
||||||
var xAtYInterpolator = new XAtYInterpolator(horizontalOffset);
|
var xAtYInterpolator = new XAtYInterpolator(horizontalOffset);
|
||||||
|
|
||||||
|
|
@ -238,8 +264,8 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
var fromLine = true;
|
var fromLine = true;
|
||||||
if (fromLine)
|
if (fromLine)
|
||||||
{
|
{
|
||||||
//positionXy *= horizontalOffset.GetXAtY(position.Z) / maxRadius;
|
positionXy *= horizontalOffset.GetXAtY(position.Z * 10) / (maxRadius * 10);
|
||||||
positionXy *= xAtYInterpolator.Get(position.Z) / maxRadius;
|
//positionXy *= xAtYInterpolator.Get(position.Z * 10) / maxRadius;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
var radius = 3.0;
|
var radius = 3.0;
|
||||||
var tabShape2 = new VertexStorage();
|
var tabShape2 = new VertexStorage();
|
||||||
tabShape2.MoveTo(rect.Left + radius, rect.Bottom);
|
tabShape2.MoveTo(rect.Left + radius, rect.Bottom);
|
||||||
tabShape2.curve3(rect.Left, rect.Bottom, rect.Left, rect.Bottom + radius);
|
tabShape2.Curve3(rect.Left, rect.Bottom, rect.Left, rect.Bottom + radius);
|
||||||
tabShape2.LineTo(rect.Left, rect.Top - radius);
|
tabShape2.LineTo(rect.Left, rect.Top - radius);
|
||||||
tabShape2.curve3(rect.Left, rect.Top, rect.Left + radius, rect.Top);
|
tabShape2.Curve3(rect.Left, rect.Top, rect.Left + radius, rect.Top);
|
||||||
tabShape2.LineTo(rect.Right - 8, rect.Top);
|
tabShape2.LineTo(rect.Right - 8, rect.Top);
|
||||||
tabShape2.LineTo(rect.Right, centerY);
|
tabShape2.LineTo(rect.Right, centerY);
|
||||||
tabShape2.LineTo(rect.Right - 8, rect.Bottom);
|
tabShape2.LineTo(rect.Right - 8, rect.Bottom);
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
int notchX = (int)(p2 - notchSize);
|
int notchX = (int)(p2 - notchSize);
|
||||||
|
|
||||||
tabShape.MoveTo(x2, y4); // A
|
tabShape.MoveTo(x2, y4); // A
|
||||||
tabShape.curve3(x1, y4, x1, y3); // A -> B
|
tabShape.Curve3(x1, y4, x1, y3); // A -> B
|
||||||
|
|
||||||
if (arrowDirection != ArrowDirection.Left)
|
if (arrowDirection != ArrowDirection.Left)
|
||||||
{
|
{
|
||||||
|
|
@ -218,7 +218,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
tabShape.LineTo(x1, y2); // P3 -> P4
|
tabShape.LineTo(x1, y2); // P3 -> P4
|
||||||
}
|
}
|
||||||
|
|
||||||
tabShape.curve3(x1, y1, x2, y1); // C -> D
|
tabShape.Curve3(x1, y1, x2, y1); // C -> D
|
||||||
|
|
||||||
if (arrowDirection != ArrowDirection.Up)
|
if (arrowDirection != ArrowDirection.Up)
|
||||||
{
|
{
|
||||||
|
|
@ -236,7 +236,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
tabShape.LineTo(x3, y1); // P3 -> E
|
tabShape.LineTo(x3, y1); // P3 -> E
|
||||||
}
|
}
|
||||||
|
|
||||||
tabShape.curve3(x4, y1, x4, y2); // E -> F
|
tabShape.Curve3(x4, y1, x4, y2); // E -> F
|
||||||
|
|
||||||
if (arrowDirection != ArrowDirection.Right)
|
if (arrowDirection != ArrowDirection.Right)
|
||||||
{
|
{
|
||||||
|
|
@ -254,7 +254,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
tabShape.LineTo(x4, y3); // P3 -> G
|
tabShape.LineTo(x4, y3); // P3 -> G
|
||||||
}
|
}
|
||||||
|
|
||||||
tabShape.curve3(x4, y4, x3, y4); // G -> H
|
tabShape.Curve3(x4, y4, x3, y4); // G -> H
|
||||||
|
|
||||||
if (arrowDirection != ArrowDirection.Down)
|
if (arrowDirection != ArrowDirection.Down)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
tabShape2.MoveTo(rect.Left + radius, rect.Bottom);
|
tabShape2.MoveTo(rect.Left + radius, rect.Bottom);
|
||||||
if (radius > 0)
|
if (radius > 0)
|
||||||
{
|
{
|
||||||
tabShape2.curve3(rect.Left, rect.Bottom, rect.Left, rect.Bottom + radius);
|
tabShape2.Curve3(rect.Left, rect.Bottom, rect.Left, rect.Bottom + radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
// C -> D
|
// C -> D
|
||||||
|
|
@ -67,7 +67,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
tabShape2.LineTo(rect.Left, rect.Top - radius);
|
tabShape2.LineTo(rect.Left, rect.Top - radius);
|
||||||
if (radius > 0)
|
if (radius > 0)
|
||||||
{
|
{
|
||||||
tabShape2.curve3(rect.Left, rect.Top, rect.Left + radius, rect.Top);
|
tabShape2.Curve3(rect.Left, rect.Top, rect.Left + radius, rect.Top);
|
||||||
}
|
}
|
||||||
|
|
||||||
// E -> F
|
// E -> F
|
||||||
|
|
@ -75,7 +75,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
tabShape2.LineTo(rect.Right - radius, rect.Top);
|
tabShape2.LineTo(rect.Right - radius, rect.Top);
|
||||||
if (radius > 0)
|
if (radius > 0)
|
||||||
{
|
{
|
||||||
tabShape2.curve3(rect.Right, rect.Top, rect.Right, rect.Top - radius);
|
tabShape2.Curve3(rect.Right, rect.Top, rect.Right, rect.Top - radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
// G -> H
|
// G -> H
|
||||||
|
|
@ -83,7 +83,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
tabShape2.LineTo(rect.Right, rect.Bottom + radius);
|
tabShape2.LineTo(rect.Right, rect.Bottom + radius);
|
||||||
if (radius > 0)
|
if (radius > 0)
|
||||||
{
|
{
|
||||||
tabShape2.curve3(rect.Right, rect.Bottom, rect.Right - radius, rect.Bottom);
|
tabShape2.Curve3(rect.Right, rect.Bottom, rect.Right - radius, rect.Bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
// H -> A
|
// H -> A
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit d7786240ef49ae59929da73363e8a17311941aef
|
Subproject commit 997d761896c03f40be9b7db8bd5ababd97a7c5ef
|
||||||
Loading…
Add table
Add a link
Reference in a new issue