diff --git a/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs b/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs index 4e1c65497..6d5505f6f 100644 --- a/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs @@ -27,8 +27,6 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ -using System; -using System.ComponentModel; using System.Text.Json.Serialization; using System.Threading.Tasks; using MatterHackers.DataConverters3D; @@ -39,50 +37,6 @@ using MatterHackers.PolygonMesh; namespace MatterHackers.MatterControl.DesignTools { - [TypeConverter(typeof(DoubleExpresion))] - public class DoubleExpresion - { - public string Expresion { get; set; } - - public double Value(IObject3D owner) - { - if (double.TryParse(Expresion, out double result)) - { - return result; - } - - return SheetObject3D.FindTableAndValue(owner, Expresion); - } - - public DoubleExpresion(double value) - { - Expresion = value.ToString(); - } - - public DoubleExpresion(string value) - { - Expresion = value; - } - - public static implicit operator DoubleExpresion(double value) - { - return new DoubleExpresion(value); - } - - public static implicit operator DoubleExpresion(string value) - { - return new DoubleExpresion(value); - } - } - - public class SheetObject3D : Object3D - { - public static T FindTableAndValue(IObject3D owner, string expresion) - { - throw new NotImplementedException(); - } - } - public class CubeObject3D : PrimitiveObject3D, IObject3DControlsProvider { public CubeObject3D() diff --git a/MatterControlLib/DesignTools/Primitives/DescriptionObject3D.cs b/MatterControlLib/DesignTools/Primitives/DescriptionObject3D.cs index d8d47960e..32d360fad 100644 --- a/MatterControlLib/DesignTools/Primitives/DescriptionObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/DescriptionObject3D.cs @@ -84,7 +84,6 @@ namespace MatterHackers.MatterControl.DesignTools set => base.Mesh = value; } - public static async Task Create() { var item = new DescriptionObject3D(); diff --git a/MatterControlLib/DesignTools/Primitives/DoubleExpresion.cs b/MatterControlLib/DesignTools/Primitives/DoubleExpresion.cs new file mode 100644 index 000000000..2c231a16b --- /dev/null +++ b/MatterControlLib/DesignTools/Primitives/DoubleExpresion.cs @@ -0,0 +1,70 @@ +/* +Copyright (c) 2019, 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.ComponentModel; +using MatterHackers.DataConverters3D; + +namespace MatterHackers.MatterControl.DesignTools +{ + [TypeConverter(typeof(DoubleExpresion))] + public class DoubleExpresion + { + public string Expresion { get; set; } + + public double Value(IObject3D owner) + { + if (double.TryParse(Expresion, out double result)) + { + return result; + } + + return VariableSheetObject3D.FindTableAndValue(owner, Expresion); + } + + public DoubleExpresion(double value) + { + Expresion = value.ToString(); + } + + public DoubleExpresion(string value) + { + Expresion = value; + } + + public static implicit operator DoubleExpresion(double value) + { + return new DoubleExpresion(value); + } + + public static implicit operator DoubleExpresion(string value) + { + return new DoubleExpresion(value); + } + } +} \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Primitives/VariableSheetObject3D.cs b/MatterControlLib/DesignTools/Primitives/VariableSheetObject3D.cs new file mode 100644 index 000000000..057ac0ba2 --- /dev/null +++ b/MatterControlLib/DesignTools/Primitives/VariableSheetObject3D.cs @@ -0,0 +1,145 @@ +/* +Copyright (c) 2019, 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; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MatterHackers.Agg.Platform; +using MatterHackers.DataConverters3D; +using MatterHackers.PolygonMesh; +using Newtonsoft.Json; + +namespace MatterHackers.MatterControl.DesignTools +{ + public class SheetData + { + public SheetData(int width, int height) + { + this.Table = new List>(height); + for (int i = 0; i < height; i++) + { + Table.Add(new List(width)); + for (int j = 0; j < width; j++) + { + Table[i].Add(new RowData()); + } + } + } + + [JsonIgnore] + public int Width => Table.Count; + + [JsonIgnore] + public int Height => Table[0].Count; + + public class CellFormat + { + public enum DataTypes + { + String, + Number, + Curency, + DateTime, + } + + public int DecimalPlaces = 10; + public DataTypes DataType; + public Agg.Font.Justification Justification; + public bool Bold; + } + + public class CellData + { + /// + /// The user override name for this cell + /// + public string Name; + + public string Data; + + public CellFormat Format; + } + + public class RowData + { + public List RowItems; + } + + public List> Table; + } + + public class VariableSheetObject3D : Object3D + { + public SheetData SheetData { get; set; } = new SheetData(5, 5); + + public override Mesh Mesh + { + get + { + if (!this.Children.Where(i => i.VisibleMeshes().Count() > 0).Any()) + { + // add the amf content + using (Stream measureAmfStream = StaticData.Instance.OpenStream(Path.Combine("Stls", "description_tool.amf"))) + { + Children.Modify((list) => + { + list.Clear(); + list.Add(AmfDocument.Load(measureAmfStream, CancellationToken.None)); + }); + } + } + + return base.Mesh; + } + + set => base.Mesh = value; + } + + public static async Task Create() + { + var item = new VariableSheetObject3D(); + await item.Rebuild(); + return item; + } + + public static T FindTableAndValue(IObject3D owner, string expresion) + { + if (typeof(T) == typeof(double)) + { + // this way we can use the common pattern without error + return (T)(object)5.5; + } + + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/MatterControlLib/DesignTools/PublicPropertyEditor.cs b/MatterControlLib/DesignTools/PublicPropertyEditor.cs index 5697f7ad3..bb51626e2 100644 --- a/MatterControlLib/DesignTools/PublicPropertyEditor.cs +++ b/MatterControlLib/DesignTools/PublicPropertyEditor.cs @@ -689,6 +689,27 @@ namespace MatterHackers.MatterControl.DesignTools var spacer = rowContainer.Children.OfType().FirstOrDefault(); spacer.HAnchor = HAnchor.Absolute; spacer.Width = Math.Max(0, 100 - label.Width); + + void RefreshField(object s, InvalidateArgs e) + { + if (e.InvalidateType.HasFlag(InvalidateType.DisplayValues)) + { + DoubleExpresion newValue = (DoubleExpresion)property.Value; + if (newValue.Expresion != field.Value) + { + var format = "0." + new string('#', 5); + if (property.PropertyInfo.GetCustomAttributes(true).OfType().FirstOrDefault() is MaxDecimalPlacesAttribute decimalPlaces) + { + format = "0." + new string('#', Math.Min(10, decimalPlaces.Number)); + } + + field.TextValue = newValue.Value(object3D).ToString(format); + } + } + } + + object3D.Invalidated += RefreshField; + field.Content.Closed += (s, e) => object3D.Invalidated -= RefreshField; } else if (propertyValue is string stringValue) { diff --git a/MatterControlLib/Library/Providers/MatterControl/PrimitivesContainer.cs b/MatterControlLib/Library/Providers/MatterControl/PrimitivesContainer.cs index 1ab538dea..f60d856ab 100644 --- a/MatterControlLib/Library/Providers/MatterControl/PrimitivesContainer.cs +++ b/MatterControlLib/Library/Providers/MatterControl/PrimitivesContainer.cs @@ -147,6 +147,10 @@ namespace MatterHackers.MatterControl.Library () => "Description".Localize(), async () => await DescriptionObject3D.Create()) { DateCreated = new System.DateTime(index++) }, + new GeneratorItem( + () => "Variable Sheet".Localize(), + async () => await VariableSheetObject3D.Create()) + { DateCreated = new System.DateTime(index++) }, }; string title = "Primitive Shapes".Localize(); diff --git a/MatterControlLib/PartPreviewWindow/View3D/GridOptionsPanel.cs b/MatterControlLib/PartPreviewWindow/View3D/GridOptionsPanel.cs index 99edb6a80..ab752c76e 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/GridOptionsPanel.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/GridOptionsPanel.cs @@ -29,9 +29,7 @@ either expressed or implied, of the FreeBSD Project. using System; using System.Collections.Generic; using MatterHackers.Agg; -using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; -using MatterHackers.ImageProcessing; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; @@ -104,7 +102,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme) { HAnchor = HAnchor.Absolute, - Width = 80 + Width = 80 * GuiWidget.DeviceScale }; var siblingList = new List(); diff --git a/MatterControlLib/SlicerConfiguration/UIFields/TextField.cs b/MatterControlLib/SlicerConfiguration/UIFields/TextField.cs index 363e44733..09be78c81 100644 --- a/MatterControlLib/SlicerConfiguration/UIFields/TextField.cs +++ b/MatterControlLib/SlicerConfiguration/UIFields/TextField.cs @@ -41,6 +41,18 @@ namespace MatterHackers.MatterControl.SlicerConfiguration this.theme = theme; } + public string TextValue + { + get { return textEditWidget.Text; } + set + { + if (textEditWidget.Text != value) + { + textEditWidget.Text = value; + } + } + } + public override void Initialize(int tabIndex) { textEditWidget = new MHTextEditWidget("", theme, pixelWidth: ControlWidth, tabIndex: tabIndex)