Making sliders have option to do non-linear scalling

This commit is contained in:
LarsBrubaker 2021-08-30 08:47:11 -07:00
parent 82adc982d8
commit 627abbef9e
18 changed files with 52 additions and 30 deletions

View file

@ -322,6 +322,7 @@ namespace MatterHackers.MatterControl
"$.Children<BaseObject3D>.Children<LinearExtrudeObject3D>.Children<SmoothPathObject3D>.Children<ImageToPathObject3D_2>.AnalysisType", "$.Children<BaseObject3D>.Children<LinearExtrudeObject3D>.Children<SmoothPathObject3D>.Children<ImageToPathObject3D_2>.AnalysisType",
"$.Children<BaseObject3D>.Children<LinearExtrudeObject3D>.Children<SmoothPathObject3D>.Children<ImageToPathObject3D_2>.TransparencyMessage", "$.Children<BaseObject3D>.Children<LinearExtrudeObject3D>.Children<SmoothPathObject3D>.Children<ImageToPathObject3D_2>.TransparencyMessage",
"$.Children<BaseObject3D>.Children<LinearExtrudeObject3D>.Children<SmoothPathObject3D>.Children<ImageToPathObject3D_2>.Histogram", "$.Children<BaseObject3D>.Children<LinearExtrudeObject3D>.Children<SmoothPathObject3D>.Children<ImageToPathObject3D_2>.Histogram",
"$.Children<BaseObject3D>.Children<LinearExtrudeObject3D>.Children<SmoothPathObject3D>.Children<ImageToPathObject3D_2>.MinSurfaceArea",
"$.Children<BaseObject3D>", "$.Children<BaseObject3D>",
} }
}; };

View file

@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project. either expressed or implied, of the FreeBSD Project.
*/ */
using MatterHackers.VectorMath;
using System; using System;
namespace MatterHackers.MatterControl.DesignTools namespace MatterHackers.MatterControl.DesignTools
@ -34,15 +35,17 @@ namespace MatterHackers.MatterControl.DesignTools
[AttributeUsage(AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Property)]
public class SliderAttribute : Attribute public class SliderAttribute : Attribute
{ {
public SliderAttribute(double min, double max, double increment) public SliderAttribute(double min, double max, Easing.EaseType easingType = Easing.EaseType.Linear, Easing.EaseOption easeOption = Easing.EaseOption.Out)
{ {
this.Min = min; this.Min = min;
this.Max = max; this.Max = max;
this.Incement = increment; this.EasingType = easingType;
this.EaseOption = easeOption;
} }
public double Min { get; set; } public double Min { get; set; }
public double Max { get; set; } public double Max { get; set; }
public double Incement { get; set; } public Easing.EaseType EasingType { get; set; }
public Easing.EaseOption EaseOption { get; }
} }
} }

View file

@ -57,7 +57,7 @@ namespace MatterHackers.MatterControl.Plugins.Lithophane
[DisplayName("Pixels Per mm"), Range(0.5, 3, ErrorMessage = "Value for {0} must be between {1} and {2}.")] [DisplayName("Pixels Per mm"), Range(0.5, 3, ErrorMessage = "Value for {0} must be between {1} and {2}.")]
public double PixelsPerMM { get; set; } = 1.5; public double PixelsPerMM { get; set; } = 1.5;
[Slider(0.5, 3, .2)] [Slider(0.5, 3)]
public double Height { get; set; } = 2.5; public double Height { get; set; } = 2.5;
public int Width { get; set; } = 150; public int Width { get; set; } = 150;

View file

@ -66,13 +66,14 @@ namespace MatterHackers.MatterControl.DesignTools
[DisplayName("Bend Up")] [DisplayName("Bend Up")]
public bool BendCcw { get; set; } = true; public bool BendCcw { get; set; } = true;
[Slider(1, 400, Easing.EaseType.Quadratic)]
public double Diameter { get; set; } = double.MinValue; public double Diameter { get; set; } = double.MinValue;
[Slider(3, 360, 1)] [Slider(3, 360)]
[Description("Ensures the rotated part has a minimum number of sides per complete rotation")] [Description("Ensures the rotated part has a minimum number of sides per complete rotation")]
public double MinSidesPerRotation { get; set; } = 3; public double MinSidesPerRotation { get; set; } = 3;
[Slider(0, 100, 1)] [Slider(0, 100)]
[Description("Where to start the bend as a percent of the width of the part")] [Description("Where to start the bend as a percent of the width of the part")]
public double StartPercent { get; set; } = 50; public double StartPercent { get; set; } = 50;

View file

@ -96,7 +96,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
{ {
if(SheetObject3D.HasParametersWithActiveFunctions(child)) if(SheetObject3D.HasParametersWithActiveFunctions(child))
{ {
child.Invalidate(new InvalidateArgs(child, InvalidateType.Properties)); // This really needs to be 'Has Perameters With index at this level'
// And is not the source object (only the copies should try to re-build (that might fix the recursion bug without the extra filtering)
//child.Invalidate(new InvalidateArgs(child, InvalidateType.Properties));
} }
} }

View file

@ -64,11 +64,11 @@ namespace MatterHackers.MatterControl.DesignTools
public double Diameter { get; set; } = double.MaxValue; public double Diameter { get; set; } = double.MaxValue;
[Slider(3, 360, 1)] [Slider(3, 360)]
[Description("Ensures the rotated part has a minimum number of sides per complete rotation")] [Description("Ensures the rotated part has a minimum number of sides per complete rotation")]
public double MinSidesPerRotation { get; set; } = 30; public double MinSidesPerRotation { get; set; } = 30;
[Slider(0, 100, 1)] [Slider(0, 100)]
[Description("Where to start the bend as a percent of the width of the part")] [Description("Where to start the bend as a percent of the width of the part")]
public double StartPercent { get; set; } = 50; public double StartPercent { get; set; } = 50;

View file

@ -86,7 +86,7 @@ namespace MatterHackers.MatterControl.DesignTools
[DescriptionImage("https://lh3.googleusercontent.com/h-s2FyBKO5etYDr_9YSLtGmGmQTcmSGMu4p0mRqX4_7Z62Ndn2QRLoFICC6X9scbhr1EP29RiYRj4EmhLMUwiNTAG-PIiFbzI_jAses")] [DescriptionImage("https://lh3.googleusercontent.com/h-s2FyBKO5etYDr_9YSLtGmGmQTcmSGMu4p0mRqX4_7Z62Ndn2QRLoFICC6X9scbhr1EP29RiYRj4EmhLMUwiNTAG-PIiFbzI_jAses")]
public BendDirections BendDirection { get; set; } = BendDirections.Bend_Up; public BendDirections BendDirection { get; set; } = BendDirections.Bend_Up;
[Slider(0, 100, 1)] [Slider(0, 100)]
[Description("Where to start the bend as a percent from the left side")] [Description("Where to start the bend as a percent from the left side")]
[DescriptionImage("https://lh3.googleusercontent.com/eOeWjr98uz_E924PnNaXrasepv15nWEuvhqH-jbaQyvrOVdX5MHXF00HdZQGC8NLpJc9ok1sToMtyPx1wnnDgFwTTGA5MjoMFu612AY1")] [DescriptionImage("https://lh3.googleusercontent.com/eOeWjr98uz_E924PnNaXrasepv15nWEuvhqH-jbaQyvrOVdX5MHXF00HdZQGC8NLpJc9ok1sToMtyPx1wnnDgFwTTGA5MjoMFu612AY1")]
public double StartPercent { get; set; } = 50; public double StartPercent { get; set; } = 50;
@ -95,7 +95,7 @@ namespace MatterHackers.MatterControl.DesignTools
[Description("Split the mesh so it has enough geometry to create a smooth curve")] [Description("Split the mesh so it has enough geometry to create a smooth curve")]
public bool SplitMesh { get; set; } = true; public bool SplitMesh { get; set; } = true;
[Slider(3, 360, 1)] [Slider(3, 360)]
[Description("Ensures the rotated part has a minimum number of sides per complete rotation")] [Description("Ensures the rotated part has a minimum number of sides per complete rotation")]
[DescriptionImage("https://lh3.googleusercontent.com/p9MyKu3AFP55PnobUKZQPqf6iAx11GzXyX-25f1ddrUnfCt8KFGd1YtHOR5HqfO0mhlX2ZVciZV4Yn0Kzfm43SErOS_xzgsESTu9scux")] [DescriptionImage("https://lh3.googleusercontent.com/p9MyKu3AFP55PnobUKZQPqf6iAx11GzXyX-25f1ddrUnfCt8KFGd1YtHOR5HqfO0mhlX2ZVciZV4Yn0Kzfm43SErOS_xzgsESTu9scux")]
public double MinSidesPerRotation { get; set; } = 30; public double MinSidesPerRotation { get; set; } = 30;

View file

@ -335,7 +335,10 @@ namespace MatterHackers.MatterControl.DesignTools
graphShape.MoveTo(0, bottom); graphShape.MoveTo(0, bottom);
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
{ {
graphShape.LineTo(i, bottom + counts[i] * graphHeight / max ); graphShape.LineTo(i, bottom + Easing.Exponential.Out(counts[i] / max) * graphHeight);
// graphShape.LineTo(i, bottom + Easing.Cubic.Out(counts[i] / max) * graphHeight);
// graphShape.LineTo(i, bottom + Easing.Exponential.Out(counts[i] / max) * graphHeight);
// graphShape.LineTo(i, bottom + counts[i] / max * graphHeight);
} }
graphShape.LineTo(256, bottom); graphShape.LineTo(256, bottom);
graphShape.LineTo(0, bottom); graphShape.LineTo(0, bottom);

View file

@ -173,10 +173,10 @@ namespace MatterHackers.MatterControl.DesignTools
[JsonIgnore] [JsonIgnore]
private ImageBuffer Image => this.Descendants<ImageObject3D>().FirstOrDefault()?.Image; private ImageBuffer Image => this.Descendants<ImageObject3D>().FirstOrDefault()?.Image;
[Slider(0, 1, .05)] [Slider(0, 1)]
public DoubleOrExpression RangeStart { get; set; } = .1; public DoubleOrExpression RangeStart { get; set; } = .1;
[Slider(0, 1, .05)] [Slider(0, 1)]
public DoubleOrExpression RangeEnd { get; set; } = 1; public DoubleOrExpression RangeEnd { get; set; } = 1;
public IVertexSource VertexSource { get; set; } = new VertexStorage(); public IVertexSource VertexSource { get; set; } = new VertexStorage();

View file

@ -168,7 +168,7 @@ namespace MatterHackers.MatterControl.DesignTools
[DisplayName("Select Range")] [DisplayName("Select Range")]
public Histogram Histogram { get; set; } = new Histogram(); public Histogram Histogram { get; set; } = new Histogram();
[Slider(0, 10, 1)] [Slider(0, 150, Easing.EaseType.Quadratic)]
[Description("The minimum area each loop needs to be for inclusion")] [Description("The minimum area each loop needs to be for inclusion")]
public double MinSurfaceArea {get; set; } = 1; public double MinSurfaceArea {get; set; } = 1;
@ -186,6 +186,9 @@ namespace MatterHackers.MatterControl.DesignTools
public override bool CanFlatten => true; public override bool CanFlatten => true;
[HideFromEditor]
public int NumLineLoops { get; set; }
public override void Flatten(UndoBuffer undoBuffer) public override void Flatten(UndoBuffer undoBuffer)
{ {
this.FlattenToPathObject(undoBuffer); this.FlattenToPathObject(undoBuffer);
@ -210,7 +213,9 @@ namespace MatterHackers.MatterControl.DesignTools
int pixelsToIntPointsScale = 1000; int pixelsToIntPointsScale = 1000;
var lineLoops = marchingSquaresData.CreateLineLoops(pixelsToIntPointsScale); var lineLoops = marchingSquaresData.CreateLineLoops(pixelsToIntPointsScale);
if (MinSurfaceArea > 0) NumLineLoops = lineLoops.Count;
if (NumLineLoops > 1 && MinSurfaceArea > 0)
{ {
var minimumSurfaceArea = Math.Pow(MinSurfaceArea * 1000, 2); var minimumSurfaceArea = Math.Pow(MinSurfaceArea * 1000, 2);
@ -429,6 +434,7 @@ namespace MatterHackers.MatterControl.DesignTools
change.SetRowVisible(nameof(Histogram), () => AnalysisType != AnalysisTypes.Transparency); change.SetRowVisible(nameof(Histogram), () => AnalysisType != AnalysisTypes.Transparency);
change.SetRowVisible(nameof(MinSurfaceArea), () => AnalysisType != AnalysisTypes.Transparency); change.SetRowVisible(nameof(MinSurfaceArea), () => AnalysisType != AnalysisTypes.Transparency);
change.SetRowVisible(nameof(TransparencyMessage), () => AnalysisType == AnalysisTypes.Transparency); change.SetRowVisible(nameof(TransparencyMessage), () => AnalysisType == AnalysisTypes.Transparency);
change.SetRowVisible(nameof(MinSurfaceArea), () => NumLineLoops > 1);
} }
} }
} }

View file

@ -212,7 +212,7 @@ namespace MatterHackers.MatterControl.DesignTools
// look for an x value that equals the goal // look for an x value that equals the goal
for (int j = 0; j < 64; j++) for (int j = 0; j < 64; j++)
{ {
var xAtY = Easing.Specify(EasingType, EasingOption, current); var xAtY = Easing.Calculate(EasingType, EasingOption, current);
if (xAtY < goal) if (xAtY < goal)
{ {
current += next; current += next;
@ -275,7 +275,7 @@ namespace MatterHackers.MatterControl.DesignTools
else else
{ {
ratio = (position.Z - bottom) / size; ratio = (position.Z - bottom) / size;
ratio = Easing.Specify(EasingType, EasingOption, ratio); ratio = Easing.Calculate(EasingType, EasingOption, ratio);
} }
} }

View file

@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.DesignTools
/// This is the actual serialized with that can use expressions /// This is the actual serialized with that can use expressions
/// </summary> /// </summary>
[MaxDecimalPlaces(2)] [MaxDecimalPlaces(2)]
[Slider(1, 100, 1)] [Slider(1, 100)]
public DoubleOrExpression Width { get; set; } = 20; public DoubleOrExpression Width { get; set; } = 20;
[MaxDecimalPlaces(2)] [MaxDecimalPlaces(2)]

View file

@ -76,7 +76,7 @@ namespace MatterHackers.MatterControl.DesignTools
}; };
public const BindingFlags OwnedPropertiesOnly = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly; public const BindingFlags OwnedPropertiesOnly = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
private List<SettingsRow> rows = new List<SettingsRow>(); private SafeList<SettingsRow> rows = new SafeList<SettingsRow>();
public GuiWidget Create(IObject3D item, UndoBuffer undoBuffer, ThemeConfig theme) public GuiWidget Create(IObject3D item, UndoBuffer undoBuffer, ThemeConfig theme)
{ {
@ -211,7 +211,7 @@ namespace MatterHackers.MatterControl.DesignTools
} }
} }
private static SettingsRow CreateSettingsRow(EditableProperty property, GuiWidget content, ThemeConfig theme, List<SettingsRow> rows = null) private static SettingsRow CreateSettingsRow(EditableProperty property, GuiWidget content, ThemeConfig theme, SafeList<SettingsRow> rows = null)
{ {
var row = new SettingsRow(property.DisplayName.Localize(), property.Description, content, theme); var row = new SettingsRow(property.DisplayName.Localize(), property.Description, content, theme);
if (rows != null) if (rows != null)
@ -307,20 +307,26 @@ namespace MatterHackers.MatterControl.DesignTools
if (field is DoubleField doubleField) if (field is DoubleField doubleField)
{ {
slider.Value = doubleField.DoubleValue; slider.Value = Easing.CalculateInverse(sliderAttribute.EasingType,
sliderAttribute.EaseOption,
doubleField.DoubleValue);
var changeDueToSlider = false; var changeDueToSlider = false;
doubleField.ValueChanged += (s, e) => doubleField.ValueChanged += (s, e) =>
{ {
if (!changeDueToSlider) if (!changeDueToSlider)
{ {
slider.Value = doubleField.DoubleValue; slider.Value = Easing.CalculateInverse(sliderAttribute.EasingType,
sliderAttribute.EaseOption,
doubleField.DoubleValue); ;
} }
}; };
slider.ValueChanged += (s, e) => slider.ValueChanged += (s, e) =>
{ {
changeDueToSlider = true; changeDueToSlider = true;
doubleField.SetValue(slider.Value.ToString(), true); doubleField.SetValue(Easing.Calculate(sliderAttribute.EasingType,
sliderAttribute.EaseOption,
slider.Value).ToString(), true);
changeDueToSlider = false; changeDueToSlider = false;
}; };
@ -344,7 +350,7 @@ namespace MatterHackers.MatterControl.DesignTools
return field.Content; return field.Content;
} }
public static GuiWidget CreatePropertyEditor(List<SettingsRow> rows, EditableProperty property, UndoBuffer undoBuffer, PPEContext context, ThemeConfig theme) public static GuiWidget CreatePropertyEditor(SafeList<SettingsRow> rows, EditableProperty property, UndoBuffer undoBuffer, PPEContext context, ThemeConfig theme)
{ {
var localItem = context.item; var localItem = context.item;
var object3D = property.Item; var object3D = property.Item;

View file

@ -58,7 +58,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// Add an editor field for the SupportGenerator.SupportType // Add an editor field for the SupportGenerator.SupportType
PropertyInfo propertyInfo = typeof(SupportGenerator).GetProperty(nameof(SupportGenerator.SupportType)); PropertyInfo propertyInfo = typeof(SupportGenerator).GetProperty(nameof(SupportGenerator.SupportType));
var rows = new List<SettingsRow>(); var rows = new SafeList<SettingsRow>();
var editor = PublicPropertyEditor.CreatePropertyEditor( var editor = PublicPropertyEditor.CreatePropertyEditor(
rows, rows,

View file

@ -299,7 +299,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
new SettingsRow("Material".Localize(), null, materialField.Content, theme)); new SettingsRow("Material".Localize(), null, materialField.Content, theme));
} }
var rows = new List<SettingsRow>(); var rows = new SafeList<SettingsRow>();
// put in the normal editor // put in the normal editor
if (selectedItem is ComponentObject3D componentObject if (selectedItem is ComponentObject3D componentObject

View file

@ -117,7 +117,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
this.PerformLayout(); this.PerformLayout();
} }
public SettingsRow SetTextRightMargin(List<SettingsRow> rows) public SettingsRow SetTextRightMargin(SafeList<SettingsRow> rows)
{ {
var spacing = 11 * GuiWidget.DeviceScale; var spacing = 11 * GuiWidget.DeviceScale;
var maxTextWidth = 0.0; var maxTextWidth = 0.0;

@ -1 +1 @@
Subproject commit 9352d21185adb4d111970d985c48d1c93f716d82 Subproject commit 75f6c6920ada5316768e890fc221f141393fd9cd

@ -1 +1 @@
Subproject commit 0cc956c6ccb27e52962662c73f27d82a16e00cbd Subproject commit c4d395b08e2185e20f72990354aa133fc73eacdf