Working to add variables in the form of a sheet
This commit is contained in:
parent
4f3a241e86
commit
703dadafad
8 changed files with 253 additions and 50 deletions
|
|
@ -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<double>(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<T>(IObject3D owner, string expresion)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class CubeObject3D : PrimitiveObject3D, IObject3DControlsProvider
|
||||
{
|
||||
public CubeObject3D()
|
||||
|
|
|
|||
|
|
@ -84,7 +84,6 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
set => base.Mesh = value;
|
||||
}
|
||||
|
||||
|
||||
public static async Task<DescriptionObject3D> Create()
|
||||
{
|
||||
var item = new DescriptionObject3D();
|
||||
|
|
|
|||
70
MatterControlLib/DesignTools/Primitives/DoubleExpresion.cs
Normal file
70
MatterControlLib/DesignTools/Primitives/DoubleExpresion.cs
Normal file
|
|
@ -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<double>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
145
MatterControlLib/DesignTools/Primitives/VariableSheetObject3D.cs
Normal file
145
MatterControlLib/DesignTools/Primitives/VariableSheetObject3D.cs
Normal file
|
|
@ -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<List<RowData>>(height);
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
Table.Add(new List<RowData>(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
|
||||
{
|
||||
/// <summary>
|
||||
/// The user override name for this cell
|
||||
/// </summary>
|
||||
public string Name;
|
||||
|
||||
public string Data;
|
||||
|
||||
public CellFormat Format;
|
||||
}
|
||||
|
||||
public class RowData
|
||||
{
|
||||
public List<CellData> RowItems;
|
||||
}
|
||||
|
||||
public List<List<RowData>> 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<VariableSheetObject3D> Create()
|
||||
{
|
||||
var item = new VariableSheetObject3D();
|
||||
await item.Rebuild();
|
||||
return item;
|
||||
}
|
||||
|
||||
public static T FindTableAndValue<T>(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -689,6 +689,27 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
var spacer = rowContainer.Children.OfType<HorizontalSpacer>().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<MaxDecimalPlacesAttribute>().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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<GuiWidget>();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue