Merge pull request #5363 from larsbrubaker/main
Working to make make expressions check before recalculate
This commit is contained in:
commit
66ab823720
13 changed files with 154 additions and 79 deletions
|
|
@ -212,7 +212,7 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
if (selectedItem is IRightClickMenuProvider menuProvider)
|
||||
{
|
||||
menuProvider.AddRightClickMenuItemsItems(popupMenu);
|
||||
menuProvider.AddRightClickMenuItemsItems(popupMenu, menuTheme);
|
||||
}
|
||||
|
||||
var parent = selectedItem.Parent;
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
/// </summary>
|
||||
public interface IRightClickMenuProvider
|
||||
{
|
||||
void AddRightClickMenuItemsItems(PopupMenu popupMenu);
|
||||
void AddRightClickMenuItemsItems(PopupMenu popupMenu, ThemeConfig theme);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -316,10 +316,5 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void AddRightClickMenuItemsItems(PopupMenu popupMenu)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<ScrollableWidget>().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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
/// <summary>
|
||||
/// Is the expression referencing a cell in the table or an equation. If not it is simply a constant
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Is the expression referencing a cell in the table or an equation. If not it is simply a constant
|
||||
/// </summary>
|
||||
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<double>(owner, Expression);
|
||||
}
|
||||
var value = SheetObject3D.EvaluateExpression<double>(owner, GetExpression(owner.RebuildLocked));
|
||||
if (owner.RebuildLocked)
|
||||
{
|
||||
ExpressionValueAtLastRebuild = value.ToString();
|
||||
}
|
||||
|
||||
public string ValueString(IObject3D owner)
|
||||
{
|
||||
return SheetObject3D.EvaluateExpression<string>(owner, Expression);
|
||||
return value;
|
||||
}
|
||||
|
||||
public DoubleOrExpression(double value)
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the expression referencing a cell in the table or an equation. If not it is simply a constant
|
||||
/// </summary>
|
||||
public bool IsEquation { get => Expression.Length > 0 && Expression[0] == '='; }
|
||||
|
||||
public int Value(IObject3D owner)
|
||||
{
|
||||
return SheetObject3D.EvaluateExpression<int>(owner, Expression);
|
||||
}
|
||||
var rebuilding = owner.RebuildLocked;
|
||||
var value = SheetObject3D.EvaluateExpression<int>(owner, GetExpression(rebuilding));
|
||||
if (rebuilding)
|
||||
{
|
||||
ExpressionValueAtLastRebuild = value.ToString();
|
||||
}
|
||||
|
||||
public string ValueString(IObject3D owner)
|
||||
{
|
||||
return SheetObject3D.EvaluateExpression<string>(owner, Expression);
|
||||
return value;
|
||||
}
|
||||
|
||||
public IntOrExpression(int value)
|
||||
|
|
|
|||
|
|
@ -253,6 +253,41 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
return runningInterval;
|
||||
}
|
||||
|
||||
private static readonly Type[] ExpressionTypes =
|
||||
{
|
||||
typeof(StringOrExpression),
|
||||
typeof(DoubleOrExpression),
|
||||
typeof(IntOrExpression),
|
||||
|
||||
};
|
||||
|
||||
|
||||
public static IEnumerable<EditableProperty> 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<string>(item, propertyValue.ToString()).ToString();
|
||||
// inExpression = inExpression.Replace("[" + constant + "]", value);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
private static void AddItemsRequiringUpdateToDictionary(IObject3D inItem,
|
||||
Dictionary<IObject3D, UpdateItem> updatedItems,
|
||||
int inDepth,
|
||||
|
|
@ -551,17 +586,17 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
return false;
|
||||
}
|
||||
|
||||
public static IEnumerable<IDirectOrExpression> GetActiveExpressions(IObject3D item, string checkForString, bool startsWith)
|
||||
public static IEnumerable<DirectOrExpression> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Is the expression referencing a cell in the table or an equation. If not it is simply a constant
|
||||
/// </summary>
|
||||
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<string>(owner, Expression);
|
||||
}
|
||||
var rebuilding = owner.RebuildLocked;
|
||||
var value = SheetObject3D.EvaluateExpression<string>(owner, GetExpression(rebuilding));
|
||||
if (rebuilding)
|
||||
{
|
||||
ExpressionValueAtLastRebuild = value.ToString();
|
||||
}
|
||||
|
||||
public string ValueString(IObject3D owner)
|
||||
{
|
||||
return SheetObject3D.EvaluateExpression<string>(owner, Expression);
|
||||
return value;
|
||||
}
|
||||
|
||||
public StringOrExpression(string expression)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit ad2d82da3826dd2f64b4b1ab6d696a7c758539d7
|
||||
Subproject commit c4f8114e2006faa32e6792f1a4d007ab2bbaed9a
|
||||
Loading…
Add table
Add a link
Reference in a new issue