diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 19088f5e5..4e3a71b52 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -212,7 +212,7 @@ namespace MatterHackers.MatterControl if (selectedItem is IRightClickMenuProvider menuProvider) { - menuProvider.AddRightClickMenuItemsItems(popupMenu); + menuProvider.AddRightClickMenuItemsItems(popupMenu, menuTheme); } var parent = selectedItem.Parent; diff --git a/MatterControlLib/DesignTools/Interfaces/EditorButtonData.cs b/MatterControlLib/DesignTools/Interfaces/EditorButtonData.cs index 2efed0c79..9b795ae36 100644 --- a/MatterControlLib/DesignTools/Interfaces/EditorButtonData.cs +++ b/MatterControlLib/DesignTools/Interfaces/EditorButtonData.cs @@ -61,7 +61,7 @@ namespace MatterHackers.MatterControl.DesignTools /// public interface IRightClickMenuProvider { - void AddRightClickMenuItemsItems(PopupMenu popupMenu); + void AddRightClickMenuItemsItems(PopupMenu popupMenu, ThemeConfig theme); } /// diff --git a/MatterControlLib/DesignTools/Operations/ArrayObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayObject3D.cs index 3e807d75e..62dbeebc0 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayObject3D.cs @@ -53,7 +53,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations { foreach (var expression in SheetObject3D.GetActiveExpressions(item, expansion.key, false)) { - expression.Expression = expression.Expression.Replace(expansion.key, SheetObject3D.RetrieveArrayIndex(item, expansion.index).ToString()); + var expressionValue = expression.GetExpression(this.RebuildLocked); + expression.Expression = expressionValue.Replace(expansion.key, SheetObject3D.RetrieveArrayIndex(item, expansion.index).ToString()); } // Also convert index expressions in ComponentObjects to their constants diff --git a/MatterControlLib/DesignTools/Primitives/ComponentObject3D.cs b/MatterControlLib/DesignTools/Primitives/ComponentObject3D.cs index c39011d9b..1744ea2a0 100644 --- a/MatterControlLib/DesignTools/Primitives/ComponentObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/ComponentObject3D.cs @@ -316,10 +316,5 @@ namespace MatterHackers.MatterControl.DesignTools } }; } - - public void AddRightClickMenuItemsItems(PopupMenu popupMenu) - { - throw new System.NotImplementedException(); - } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Primitives/TextObject3D.cs b/MatterControlLib/DesignTools/Primitives/TextObject3D.cs index 7b5d3a30a..b20f51709 100644 --- a/MatterControlLib/DesignTools/Primitives/TextObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/TextObject3D.cs @@ -182,7 +182,9 @@ namespace MatterHackers.MatterControl.DesignTools { bool valuesChanged = false; var height = Height.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged); - var nameToWrite = MultiLine ? MultiLineText.Value(this).Replace("\\n", "\n").Replace("\r", "\n").Replace("\n\n", "\n") : NameToWrite.Value(this); + var nameToWrite = MultiLine + ? MultiLineText.Value(this).Replace("\\n", "\n").Replace("\r", "\n").Replace("\n\n", "\n") + : NameToWrite.Value(this); if (string.IsNullOrWhiteSpace(nameToWrite)) { Mesh = PlatonicSolids.CreateCube(20, 10, height); diff --git a/MatterControlLib/DesignTools/PublicPropertyEditor.cs b/MatterControlLib/DesignTools/PublicPropertyEditor.cs index 940976a27..f416c4e76 100644 --- a/MatterControlLib/DesignTools/PublicPropertyEditor.cs +++ b/MatterControlLib/DesignTools/PublicPropertyEditor.cs @@ -321,7 +321,15 @@ namespace MatterHackers.MatterControl.DesignTools field.ValueChanged += (s, e) => { var newValue = field.Value; - var oldValue = property.Value.ToString(); + var oldValue = ""; + if (property.Value is DirectOrExpression directOrExpression) + { + oldValue = directOrExpression.GetExpression(false); + } + else + { + oldValue = property.Value.ToString(); + } if (newValue == oldValue) { return; @@ -831,9 +839,9 @@ namespace MatterHackers.MatterControl.DesignTools Name = property.DisplayName + " Field" }; field.Initialize(0); - if (doubleExpresion.Expression.Contains("=")) + if (doubleExpresion.GetExpression(false).Contains("=")) { - field.SetValue(doubleExpresion.Expression, false); + field.SetValue(doubleExpresion.GetExpression(false), false); } else // make sure it is formatted { @@ -855,7 +863,7 @@ namespace MatterHackers.MatterControl.DesignTools }, (value) => { - return ((DoubleOrExpression)value).Expression; + return ((DoubleOrExpression)value).GetExpression(false); }); rowContainer = CreateSettingsRow(property, @@ -876,9 +884,9 @@ namespace MatterHackers.MatterControl.DesignTools // if (newValue.Expression != field.Value) { // we should never be in the situation where there is an '=' as the in scene controls should be disabled - if (newValue.Expression.StartsWith("=")) + if (newValue.GetExpression(false).StartsWith("=")) { - field.TextValue = newValue.Expression; + field.TextValue = newValue.GetExpression(false); } else { @@ -906,9 +914,9 @@ namespace MatterHackers.MatterControl.DesignTools Name = property.DisplayName + " Field" }; field.Initialize(0); - if (intExpresion.Expression.Contains("=")) + if (intExpresion.GetExpression(false).Contains("=")) { - field.SetValue(intExpresion.Expression, false); + field.SetValue(intExpresion.GetExpression(false), false); } else // make sure it is formatted { @@ -930,7 +938,7 @@ namespace MatterHackers.MatterControl.DesignTools }, (value) => { - return ((IntOrExpression)value).Expression; + return ((IntOrExpression)value).GetExpression(false); }); rowContainer = CreateSettingsRow(property, @@ -951,9 +959,9 @@ namespace MatterHackers.MatterControl.DesignTools // if (newValue.Expression != field.Value) { // we should never be in the situation where there is an '=' as the in scene controls should be disabled - if (newValue.Expression.StartsWith("=")) + if (newValue.GetExpression(false).StartsWith("=")) { - field.TextValue = newValue.Expression; + field.TextValue = newValue.GetExpression(false); } else { @@ -1098,7 +1106,7 @@ namespace MatterHackers.MatterControl.DesignTools // create a a multi-line string editor var field = new MultilineStringField(theme); field.Initialize(0); - field.SetValue(stringOrExpression.Expression, false); + field.SetValue(stringOrExpression.GetExpression(false), false); field.ClearUndoHistory(); field.Content.HAnchor = HAnchor.Stretch; field.Content.Descendants().FirstOrDefault().MaximumSize = new Vector2(double.MaxValue, 200); @@ -1109,7 +1117,7 @@ namespace MatterHackers.MatterControl.DesignTools (valueString) => new StringOrExpression(valueString), (value) => { - return ((StringOrExpression)value).Expression; + return ((StringOrExpression)value).GetExpression(false); }); rowContainer = CreateSettingsColumn(property, field, fullWidth: true); } @@ -1118,14 +1126,14 @@ namespace MatterHackers.MatterControl.DesignTools // create a string editor var field = new TextField(theme); field.Initialize(0); - field.SetValue(stringOrExpression.Expression, false); + field.SetValue(stringOrExpression.GetExpression(false), false); field.ClearUndoHistory(); field.Content.HAnchor = HAnchor.Stretch; RegisterValueChanged(field, (valueString) => new StringOrExpression(valueString), (value) => { - return ((StringOrExpression)value).Expression; + return ((StringOrExpression)value).GetExpression(false); }); rowContainer = CreateSettingsColumn(property, field, fullWidth: true); } diff --git a/MatterControlLib/DesignTools/Sheets/IDirectOrExpression.cs b/MatterControlLib/DesignTools/Sheets/DirectOrExpression.cs similarity index 57% rename from MatterControlLib/DesignTools/Sheets/IDirectOrExpression.cs rename to MatterControlLib/DesignTools/Sheets/DirectOrExpression.cs index 3d349d11c..b25b53035 100644 --- a/MatterControlLib/DesignTools/Sheets/IDirectOrExpression.cs +++ b/MatterControlLib/DesignTools/Sheets/DirectOrExpression.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2019, Lars Brubaker, John Lewin +Copyright (c) 2022, Lars Brubaker, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -28,13 +28,64 @@ either expressed or implied, of the FreeBSD Project. */ using MatterHackers.DataConverters3D; +using System; namespace MatterHackers.MatterControl.DesignTools { - public interface IDirectOrExpression + public class DirectOrExpression { - string Expression { get; set; } + /// + /// Is the expression referencing a cell in the table or an equation. If not it is simply a constant + /// + public bool IsEquation + { + get + { + internalGet = true; + var value = Expression.Length > 0 && Expression[0] == '='; + internalGet = false; + return value; + } + } - string ValueString(IObject3D owner); + public string ExpressionValueAtLastRebuild { get; set; } = ""; + + private bool internalGet = false; + private string _expression; + + public string Expression + { + private get + { + if (!internalGet) + { + throw new Exception("All get accessing should run through GetExpression rather than direct"); + } + return _expression; + } + + set => _expression = value; + } + + public override string ToString() => Expression; + + public string GetExpression(bool rebuilding) + { + internalGet = true; + var expression = ""; + try + { + if (rebuilding) + { + ExpressionValueAtLastRebuild = Expression; + } + + expression = Expression; + } + catch { } + + internalGet = false; + return expression; + } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Sheets/DoubleOrExpression.cs b/MatterControlLib/DesignTools/Sheets/DoubleOrExpression.cs index c2ca0329a..d9ea44366 100644 --- a/MatterControlLib/DesignTools/Sheets/DoubleOrExpression.cs +++ b/MatterControlLib/DesignTools/Sheets/DoubleOrExpression.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2019, Lars Brubaker, John Lewin +Copyright (c) 2022, Lars Brubaker, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -36,25 +36,17 @@ namespace MatterHackers.MatterControl.DesignTools { [TypeConverter(typeof(DoubleOrExpression))] - public class DoubleOrExpression : IDirectOrExpression + public class DoubleOrExpression : DirectOrExpression { - /// - /// Is the expression referencing a cell in the table or an equation. If not it is simply a constant - /// - public bool IsEquation { get => Expression.Length > 0 && Expression[0] == '='; } - - public string Expression { get; set; } - - public override string ToString() => Expression; - public double Value(IObject3D owner) { - return SheetObject3D.EvaluateExpression(owner, Expression); - } + var value = SheetObject3D.EvaluateExpression(owner, GetExpression(owner.RebuildLocked)); + if (owner.RebuildLocked) + { + ExpressionValueAtLastRebuild = value.ToString(); + } - public string ValueString(IObject3D owner) - { - return SheetObject3D.EvaluateExpression(owner, Expression); + return value; } public DoubleOrExpression(double value) diff --git a/MatterControlLib/DesignTools/Sheets/IntOrExpression.cs b/MatterControlLib/DesignTools/Sheets/IntOrExpression.cs index 4aaef4aba..93152f7a7 100644 --- a/MatterControlLib/DesignTools/Sheets/IntOrExpression.cs +++ b/MatterControlLib/DesignTools/Sheets/IntOrExpression.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2019, Lars Brubaker, John Lewin +Copyright (c) 2022, Lars Brubaker, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -34,23 +34,18 @@ using MatterHackers.DataConverters3D; namespace MatterHackers.MatterControl.DesignTools { [TypeConverter(typeof(IntOrExpression))] - public class IntOrExpression : IDirectOrExpression + public class IntOrExpression : DirectOrExpression { - public string Expression { get; set; } - - /// - /// Is the expression referencing a cell in the table or an equation. If not it is simply a constant - /// - public bool IsEquation { get => Expression.Length > 0 && Expression[0] == '='; } - public int Value(IObject3D owner) { - return SheetObject3D.EvaluateExpression(owner, Expression); - } + var rebuilding = owner.RebuildLocked; + var value = SheetObject3D.EvaluateExpression(owner, GetExpression(rebuilding)); + if (rebuilding) + { + ExpressionValueAtLastRebuild = value.ToString(); + } - public string ValueString(IObject3D owner) - { - return SheetObject3D.EvaluateExpression(owner, Expression); + return value; } public IntOrExpression(int value) diff --git a/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs b/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs index 716bc6b3e..36678926e 100644 --- a/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs +++ b/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs @@ -253,6 +253,41 @@ namespace MatterHackers.MatterControl.DesignTools return runningInterval; } + private static readonly Type[] ExpressionTypes = + { + typeof(StringOrExpression), + typeof(DoubleOrExpression), + typeof(IntOrExpression), + + }; + + + public static IEnumerable GetExpressionPropreties(IObject3D item) + { + return item.GetType().GetProperties(OwnedPropertiesOnly) + .Where(pi => ExpressionTypes.Contains(pi.PropertyType) + && pi.GetGetMethod() != null + && pi.GetSetMethod() != null) + .Select(p => new EditableProperty(p, item)); + } + + //private static bool HasValuesThatWillChange(IObject3D item) + // { + // // enumerate public properties on child + // foreach (var property in GetExpressionPropreties(item)) + // { + // var propertyValue = property.Value; + + // if (propertyValue is IDirectOrExpression expression) + // { + // // return the value + // var currentValue = item.GetType().GetProperty(property.Name).GetValue(child, null).ToString(); + // var newValue = EvaluateExpression(item, propertyValue.ToString()).ToString(); + // inExpression = inExpression.Replace("[" + constant + "]", value); + // } + // } + //} + private static void AddItemsRequiringUpdateToDictionary(IObject3D inItem, Dictionary updatedItems, int inDepth, @@ -551,17 +586,17 @@ namespace MatterHackers.MatterControl.DesignTools return false; } - public static IEnumerable GetActiveExpressions(IObject3D item, string checkForString, bool startsWith) + public static IEnumerable GetActiveExpressions(IObject3D item, string checkForString, bool startsWith) { foreach (var property in PublicPropertyEditor.GetEditablePropreties(item)) { var propertyValue = property.Value; - if (propertyValue is IDirectOrExpression directOrExpression) + if (propertyValue is DirectOrExpression directOrExpression) { if (startsWith) { - if (directOrExpression.Expression.StartsWith(checkForString)) + if (directOrExpression.GetExpression(false).StartsWith(checkForString)) { // WIP: check if the value has actually changed, this will update every object on any cell change yield return directOrExpression; @@ -569,7 +604,7 @@ namespace MatterHackers.MatterControl.DesignTools } else { - if(directOrExpression.Expression.Contains(checkForString)) + if(directOrExpression.GetExpression(false).Contains(checkForString)) { yield return directOrExpression; } diff --git a/MatterControlLib/DesignTools/Sheets/StringOrExpression.cs b/MatterControlLib/DesignTools/Sheets/StringOrExpression.cs index 96372d70b..334451fd1 100644 --- a/MatterControlLib/DesignTools/Sheets/StringOrExpression.cs +++ b/MatterControlLib/DesignTools/Sheets/StringOrExpression.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2019, Lars Brubaker, John Lewin +Copyright (c) 2022, Lars Brubaker, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -33,25 +33,18 @@ using MatterHackers.DataConverters3D; namespace MatterHackers.MatterControl.DesignTools { [TypeConverter(typeof(StringOrExpression))] - public class StringOrExpression : IDirectOrExpression + public class StringOrExpression : DirectOrExpression { - /// - /// Is the expression referencing a cell in the table or an equation. If not it is simply a constant - /// - public bool IsEquation { get => Expression.Length > 0 && Expression[0] == '='; } - - public string Expression { get; set; } - - public override string ToString() => Expression; - public string Value(IObject3D owner) { - return SheetObject3D.EvaluateExpression(owner, Expression); - } + var rebuilding = owner.RebuildLocked; + var value = SheetObject3D.EvaluateExpression(owner, GetExpression(rebuilding)); + if (rebuilding) + { + ExpressionValueAtLastRebuild = value.ToString(); + } - public string ValueString(IObject3D owner) - { - return SheetObject3D.EvaluateExpression(owner, Expression); + return value; } public StringOrExpression(string expression) diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 5514ac9c1..23124256d 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -607,6 +607,9 @@ Translated:Below you can find a list of each setting that has changed. English:Bend Direction Translated:Bend Direction +English:Bend Up +Translated:Bend Up + English:Beta Translated:Beta diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index ad2d82da3..c4f8114e2 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit ad2d82da3826dd2f64b4b1ab6d696a7c758539d7 +Subproject commit c4f8114e2006faa32e6792f1a4d007ab2bbaed9a