diff --git a/MatterControlLib/CustomWidgets/CalibrationTabWidget.cs b/MatterControlLib/CustomWidgets/CalibrationTabWidget.cs index 91c7b62c7..a774dc32a 100644 --- a/MatterControlLib/CustomWidgets/CalibrationTabWidget.cs +++ b/MatterControlLib/CustomWidgets/CalibrationTabWidget.cs @@ -90,8 +90,8 @@ namespace MatterHackers.MatterControl tabShape2.Add(a.X, a.Y, FlagsAndCommand.MoveTo); // A tabShape2.LineTo(b); // A - B - tabShape2.curve3(r.X, r.Y, m.X, m.Y); // B -> C - tabShape2.curve3(c.X, c.Y); + tabShape2.Curve3(r.X, r.Y, m.X, m.Y); // B -> C + tabShape2.Curve3(c.X, c.Y); tabShape2.LineTo(d); // C -> D tabShape2.LineTo(e); // D -> E diff --git a/MatterControlLib/DesignTools/EditorTools/RotateControls/PathControl.cs b/MatterControlLib/DesignTools/EditorTools/RotateControls/PathControl.cs index f0d91cd23..3262d9285 100644 --- a/MatterControlLib/DesignTools/EditorTools/RotateControls/PathControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/RotateControls/PathControl.cs @@ -208,9 +208,9 @@ namespace MatterHackers.Plugins.EditorTools 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) { @@ -224,12 +224,12 @@ namespace MatterHackers.Plugins.EditorTools context.GuiSurface.AddChild(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); context.GuiSurface.AddChild(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) { ControlPoint = controlPoint2, @@ -395,7 +395,7 @@ namespace MatterHackers.Plugins.EditorTools if (vertexStorage?.Count >= index) { - vertexStorage.modify_vertex(index, _point.X, _point.Y); + vertexStorage.ModifyVertex(index, _point.X, _point.Y); } this.Invalidate(); diff --git a/MatterControlLib/DesignTools/Operations/Image/Histogram.cs b/MatterControlLib/DesignTools/Operations/Image/Histogram.cs index bfedff2d3..2f73ecf27 100644 --- a/MatterControlLib/DesignTools/Operations/Image/Histogram.cs +++ b/MatterControlLib/DesignTools/Operations/Image/Histogram.cs @@ -387,11 +387,11 @@ namespace MatterHackers.MatterControl.DesignTools g.Line(w * e, 0, w * e, h, theme.TextColor); var leftEdge = new VertexStorage(); leftEdge.MoveTo(w * e, h * .80); - leftEdge.curve3(w * e, h * .70, w * .5, h * .70); - leftEdge.curve3(w * s, h * .60); + leftEdge.Curve3(w * e, h * .70, w * .5, h * .70); + leftEdge.Curve3(w * s, h * .60); leftEdge.LineTo(w * s, h * .40); - leftEdge.curve3(w * s, h * .30, w * .5, h * .30); - leftEdge.curve3(w * e, h * .20); + leftEdge.Curve3(w * s, h * .30, w * .5, h * .30); + leftEdge.Curve3(w * e, h * .20); g.Render(new FlattenCurves(leftEdge), theme.PrimaryAccentColor); g.Line(w * .35, h * .6, w * .35, h * .4, theme.BackgroundColor); g.Line(w * .65, h * .6, w * .65, h * .4, theme.BackgroundColor); diff --git a/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs b/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs index a63b616cb..658a75ab1 100644 --- a/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs @@ -276,7 +276,7 @@ namespace MatterHackers.MatterControl.DesignTools var affine = Affine.NewScaling(1.0 / pixelsToIntPointsScale * xScale); affine *= Affine.NewTranslation(-aabb.XSize / 2, -aabb.YSize / 2); - rawVectorShape.transform(affine); + rawVectorShape.Transform(affine); this.VertexStorage = rawVectorShape; progressReporter?.Invoke(1, null); diff --git a/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D_2.cs b/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D_2.cs index 86bfb9443..3e322f2be 100644 --- a/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D_2.cs +++ b/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D_2.cs @@ -260,7 +260,7 @@ namespace MatterHackers.MatterControl.DesignTools var affine = Affine.NewScaling(1.0 / pixelsToIntPointsScale * xScale); affine *= Affine.NewTranslation(-aabb.XSize / 2, -aabb.YSize / 2); - rawVectorShape.transform(affine); + rawVectorShape.Transform(affine); this.VertexStorage = rawVectorShape; progressReporter?.Invoke(1, null); diff --git a/MatterControlLib/DesignTools/Operations/RadialPinchObject3D.cs b/MatterControlLib/DesignTools/Operations/RadialPinchObject3D.cs index 787f10a09..b498f6f5c 100644 --- a/MatterControlLib/DesignTools/Operations/RadialPinchObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/RadialPinchObject3D.cs @@ -34,6 +34,8 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using MatterHackers.Agg; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.Transform; using MatterHackers.Agg.UI; using MatterHackers.Agg.VertexSource; using MatterHackers.DataConverters3D; @@ -47,44 +49,51 @@ using MatterHackers.VectorMath; 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; - - public double TopControlRatio { get; set; } - - public double BottomControlRatio { get; set; } - } - - public List ControlPoints { get; set; } = new List() - { - 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 (property.Value is VertexStorage vertexStorage) { - if (i == 0) + var container = new GuiWidget() { - vertexStorage.MoveTo(radius * ControlPoints[0].WidthRatio, 0); - } - else + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Stretch, + BackgroundOutlineWidth = 1, + BackgroundColor = Color.White, + BorderColor = Color.Black, + Margin = 1, + }; + + var imageWidget = new ImageWidget(100, 200) { - var curPoint = ControlPoints[i]; - var x = radius * curPoint.WidthRatio; - var y = i * segmentHeight; - vertexStorage.curve4(x, y - curPoint.BottomControlRatio * segmentHeight, x, y - curPoint.TopControlRatio * segmentHeight, x, y); + AutoResize = true, + HAnchor = HAnchor.Center, + VAnchor = VAnchor.Center, + }; + 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() { + PropertyEditor.RegisterEditor(typeof(VertexStorage), new PathEditor()); + 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.")] [Slider(0, 50, snapDistance: 1)] @@ -179,8 +190,8 @@ namespace MatterHackers.MatterControl.DesignTools var size = sourceAabb.ZSize; if (Advanced) { - top -= sourceAabb.ZSize * endHeightPercent / 100.0; - bottom += sourceAabb.ZSize * startHeightPercent / 100.0; + top = sourceAabb.ZSize * endHeightPercent / 100.0; + bottom = sourceAabb.ZSize * startHeightPercent / 100.0; size = top - bottom; } @@ -199,7 +210,22 @@ namespace MatterHackers.MatterControl.DesignTools var rotationCenter = enclosingCircle.Center + RotationOffset; 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); @@ -238,8 +264,8 @@ namespace MatterHackers.MatterControl.DesignTools var fromLine = true; if (fromLine) { - //positionXy *= horizontalOffset.GetXAtY(position.Z) / maxRadius; - positionXy *= xAtYInterpolator.Get(position.Z) / maxRadius; + positionXy *= horizontalOffset.GetXAtY(position.Z * 10) / (maxRadius * 10); + //positionXy *= xAtYInterpolator.Get(position.Z * 10) / maxRadius; } else { diff --git a/MatterControlLib/PartPreviewWindow/HorizontalTag.cs b/MatterControlLib/PartPreviewWindow/HorizontalTag.cs index 7627e03e4..a1a32508a 100644 --- a/MatterControlLib/PartPreviewWindow/HorizontalTag.cs +++ b/MatterControlLib/PartPreviewWindow/HorizontalTag.cs @@ -54,9 +54,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var radius = 3.0; var tabShape2 = new VertexStorage(); 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.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, centerY); tabShape2.LineTo(rect.Right - 8, rect.Bottom); diff --git a/MatterControlLib/PartPreviewWindow/Popover.cs b/MatterControlLib/PartPreviewWindow/Popover.cs index 03459e69a..0554d05bc 100644 --- a/MatterControlLib/PartPreviewWindow/Popover.cs +++ b/MatterControlLib/PartPreviewWindow/Popover.cs @@ -200,7 +200,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow int notchX = (int)(p2 - notchSize); 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) { @@ -218,7 +218,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow 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) { @@ -236,7 +236,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow 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) { @@ -254,7 +254,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow 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) { diff --git a/MatterControlLib/PartPreviewWindow/RoundedRectShape.cs b/MatterControlLib/PartPreviewWindow/RoundedRectShape.cs index 25e71e315..8c57da46f 100644 --- a/MatterControlLib/PartPreviewWindow/RoundedRectShape.cs +++ b/MatterControlLib/PartPreviewWindow/RoundedRectShape.cs @@ -59,7 +59,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow tabShape2.MoveTo(rect.Left + radius, rect.Bottom); 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 @@ -67,7 +67,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow tabShape2.LineTo(rect.Left, rect.Top - radius); 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 @@ -75,7 +75,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow tabShape2.LineTo(rect.Right - radius, rect.Top); 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 @@ -83,7 +83,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow tabShape2.LineTo(rect.Right, rect.Bottom + radius); 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 diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index d7786240e..997d76189 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit d7786240ef49ae59929da73363e8a17311941aef +Subproject commit 997d761896c03f40be9b7db8bd5ababd97a7c5ef