Reverting expression caching changes.

The caching should happen in the sheet object not the property
This commit is contained in:
Lars Brubaker 2022-09-15 13:26:28 -07:00
parent c1f7817eb3
commit abb56a5c76
8 changed files with 39 additions and 58 deletions

View file

@ -53,7 +53,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
{
foreach (var expression in SheetObject3D.GetActiveExpressions(item, expansion.key, false))
{
var expressionValue = expression.GetExpression(this.RebuildLocked);
var expressionValue = expression.Expression;
expression.Expression = expressionValue.Replace(expansion.key, SheetObject3D.RetrieveArrayIndex(item, expansion.index).ToString());
}

View file

@ -324,7 +324,7 @@ namespace MatterHackers.MatterControl.DesignTools
var oldValue = "";
if (property.Value is DirectOrExpression directOrExpression)
{
oldValue = directOrExpression.GetExpression(false);
oldValue = directOrExpression.Expression;
}
else
{
@ -839,9 +839,9 @@ namespace MatterHackers.MatterControl.DesignTools
Name = property.DisplayName + " Field"
};
field.Initialize(0);
if (doubleExpresion.GetExpression(false).Contains("="))
if (doubleExpresion.Expression.Contains("="))
{
field.SetValue(doubleExpresion.GetExpression(false), false);
field.SetValue(doubleExpresion.Expression, false);
}
else // make sure it is formatted
{
@ -863,7 +863,7 @@ namespace MatterHackers.MatterControl.DesignTools
},
(value) =>
{
return ((DoubleOrExpression)value).GetExpression(false);
return ((DoubleOrExpression)value).Expression;
});
rowContainer = CreateSettingsRow(property,
@ -884,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.GetExpression(false).StartsWith("="))
if (newValue.Expression.StartsWith("="))
{
field.TextValue = newValue.GetExpression(false);
field.TextValue = newValue.Expression;
}
else
{
@ -914,9 +914,9 @@ namespace MatterHackers.MatterControl.DesignTools
Name = property.DisplayName + " Field"
};
field.Initialize(0);
if (intExpresion.GetExpression(false).Contains("="))
if (intExpresion.Expression.Contains("="))
{
field.SetValue(intExpresion.GetExpression(false), false);
field.SetValue(intExpresion.Expression, false);
}
else // make sure it is formatted
{
@ -938,7 +938,7 @@ namespace MatterHackers.MatterControl.DesignTools
},
(value) =>
{
return ((IntOrExpression)value).GetExpression(false);
return ((IntOrExpression)value).Expression;
});
rowContainer = CreateSettingsRow(property,
@ -959,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.GetExpression(false).StartsWith("="))
if (newValue.Expression.StartsWith("="))
{
field.TextValue = newValue.GetExpression(false);
field.TextValue = newValue.Expression;
}
else
{
@ -1106,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.GetExpression(false), false);
field.SetValue(stringOrExpression.Expression, false);
field.ClearUndoHistory();
field.Content.HAnchor = HAnchor.Stretch;
field.Content.Descendants<ScrollableWidget>().FirstOrDefault().MaximumSize = new Vector2(double.MaxValue, 200);
@ -1117,7 +1117,7 @@ namespace MatterHackers.MatterControl.DesignTools
(valueString) => new StringOrExpression(valueString),
(value) =>
{
return ((StringOrExpression)value).GetExpression(false);
return ((StringOrExpression)value).Expression;
});
rowContainer = CreateSettingsColumn(property, field, fullWidth: true);
}
@ -1126,14 +1126,14 @@ namespace MatterHackers.MatterControl.DesignTools
// create a string editor
var field = new TextField(theme);
field.Initialize(0);
field.SetValue(stringOrExpression.GetExpression(false), false);
field.SetValue(stringOrExpression.Expression, false);
field.ClearUndoHistory();
field.Content.HAnchor = HAnchor.Stretch;
RegisterValueChanged(field,
(valueString) => new StringOrExpression(valueString),
(value) =>
{
return ((StringOrExpression)value).GetExpression(false);
return ((StringOrExpression)value).Expression;
});
rowContainer = CreateSettingsColumn(property, field, fullWidth: true);
}

View file

@ -41,51 +41,15 @@ namespace MatterHackers.MatterControl.DesignTools
{
get
{
internalGet = true;
var value = Expression.Length > 0 && Expression[0] == '=';
internalGet = false;
return value;
}
}
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 string Expression { get; set; }
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;
}
}
}

View file

@ -40,7 +40,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public double Value(IObject3D owner)
{
var value = SheetObject3D.EvaluateExpression<double>(owner, GetExpression(owner.RebuildLocked));
var value = SheetObject3D.EvaluateExpression<double>(owner, Expression);
if (owner.RebuildLocked)
{
ExpressionValueAtLastRebuild = value.ToString();

View file

@ -39,7 +39,7 @@ namespace MatterHackers.MatterControl.DesignTools
public int Value(IObject3D owner)
{
var rebuilding = owner.RebuildLocked;
var value = SheetObject3D.EvaluateExpression<int>(owner, GetExpression(rebuilding));
var value = SheetObject3D.EvaluateExpression<int>(owner, Expression);
if (rebuilding)
{
ExpressionValueAtLastRebuild = value.ToString();

View file

@ -596,7 +596,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
if (startsWith)
{
if (directOrExpression.GetExpression(false).StartsWith(checkForString))
if (directOrExpression.Expression.StartsWith(checkForString))
{
// WIP: check if the value has actually changed, this will update every object on any cell change
yield return directOrExpression;
@ -604,7 +604,7 @@ namespace MatterHackers.MatterControl.DesignTools
}
else
{
if(directOrExpression.GetExpression(false).Contains(checkForString))
if(directOrExpression.Expression.Contains(checkForString))
{
yield return directOrExpression;
}

View file

@ -38,7 +38,7 @@ namespace MatterHackers.MatterControl.DesignTools
public string Value(IObject3D owner)
{
var rebuilding = owner.RebuildLocked;
var value = SheetObject3D.EvaluateExpression<string>(owner, GetExpression(rebuilding));
var value = SheetObject3D.EvaluateExpression<string>(owner, Expression);
if (rebuilding)
{
ExpressionValueAtLastRebuild = value.ToString();

View file

@ -40,6 +40,7 @@ using MatterHackers.PolygonMesh;
using MatterHackers.PolygonMesh.Processors;
using MatterHackers.VectorMath;
using NUnit.Framework;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -381,6 +382,22 @@ namespace MatterControl.Tests.MatterControl
}
}
[Test, Category("InteractiveScene")]
public async Task CopyObjectTests()
{
StartupMC();
// Copying an object copies the internal state correctly
{
var cubeA1 = await CubeObject3D.Create(10, 20, 20);
var copy = cubeA1.Clone() as CubeObject3D;
Assert.AreEqual(10, copy.Width.Expression, "10");
Assert.AreEqual(10, copy.GetAxisAlignedBoundingBox().XSize, .001);
}
}
[Test, Category("InteractiveScene")]
public async Task AabbCalculatedCorrectlyForPinchedFitObjects()
{