diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleController.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleController.cs
index da6895559..12f61851a 100644
--- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleController.cs
+++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleController.cs
@@ -90,8 +90,8 @@ namespace MatterHackers.Plugins.EditorTools
{
get
{
- if (getWidth != null
- && (getWidth() != InitialState.Width || getDepth() != InitialState.Depth))
+ if ((getWidth != null && getWidth() != InitialState.Width)
+ || (getDepth != null && getDepth() != InitialState.Depth))
{
return true;
}
@@ -200,7 +200,11 @@ namespace MatterHackers.Plugins.EditorTools
if (getWidth != null)
{
InitialState.Width = getWidth();
- InitialState.Depth = getDepth();
+ }
+
+ if (getDepth != null)
+ {
+ InitialState.Depth = getDepth.Invoke();
}
if (getHeight != null)
diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs
index fa191a57f..32af77d2d 100644
--- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs
+++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs
@@ -327,8 +327,8 @@ namespace MatterHackers.Plugins.EditorTools
{
if (hadClickOnControl)
{
- if (getWidth() != scaleController.InitialState.Width
- || getDepth() != scaleController.InitialState.Depth)
+ if ((getWidth != null && getWidth() != scaleController.InitialState.Width)
+ || (getDepth != null && getDepth() != scaleController.InitialState.Depth))
{
scaleController.EditComplete();
}
diff --git a/MatterControlLib/DesignTools/Operations/ScaleObject3D_2.cs b/MatterControlLib/DesignTools/Operations/ScaleObject3D_2.cs
index 9802d65ee..bb0889b4b 100644
--- a/MatterControlLib/DesignTools/Operations/ScaleObject3D_2.cs
+++ b/MatterControlLib/DesignTools/Operations/ScaleObject3D_2.cs
@@ -370,12 +370,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
(depth) => Depth = depth,
() => Height,
(height) => Height = height));
- object3DControlsLayer.AddWidthDepthControls(() => Width,
- (width) => Width = width,
- () => Depth,
- (depth) => Depth = depth,
- () => Height,
- (height) => Height = height);
+ object3DControlsLayer.AddWidthDepthControls(this, Width, Depth, Height);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
diff --git a/MatterControlLib/DesignTools/Operations/ScaleObject3D_3.cs b/MatterControlLib/DesignTools/Operations/ScaleObject3D_3.cs
index f19e1735e..1161ed934 100644
--- a/MatterControlLib/DesignTools/Operations/ScaleObject3D_3.cs
+++ b/MatterControlLib/DesignTools/Operations/ScaleObject3D_3.cs
@@ -470,12 +470,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height));
- object3DControlsLayer.AddWidthDepthControls(() => Width.Value(this),
- (width) => Width = width,
- () => Depth.Value(this),
- (depth) => Depth = depth,
- () => Height.Value(this),
- (height) => Height = height);
+ object3DControlsLayer.AddWidthDepthControls(this, Width, Depth, Height);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
diff --git a/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs b/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs
index a003b3afc..8d4fad6a3 100644
--- a/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs
+++ b/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs
@@ -89,12 +89,7 @@ namespace MatterHackers.MatterControl.DesignTools
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height));
- object3DControlsLayer.AddWidthDepthControls(() => Width.Value(this),
- (width) => Width = width,
- () => Depth.Value(this),
- (depth) => Depth = depth,
- () => Height.Value(this),
- (height) => Height = height);
+ object3DControlsLayer.AddWidthDepthControls(this, Width, Depth, Height);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
diff --git a/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs b/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs
index 4cfad7378..06c8dba31 100644
--- a/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs
+++ b/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs
@@ -126,7 +126,7 @@ namespace MatterHackers.MatterControl.DesignTools
public DoubleOrExpression Height { get; set; } = 20;
[Description("The number of segments around the perimeter.")]
- public int Sides { get; set; } = 40;
+ public IntOrExpression Sides { get; set; } = 40;
public bool Advanced { get; set; } = false;
@@ -161,14 +161,12 @@ namespace MatterHackers.MatterControl.DesignTools
this.DebugDepth("Rebuild");
bool valuesChanged = false;
- var height = Height.Value(this);
- var diameter = Diameter.Value(this);
- var diameterTop = DiameterTop.Value(this);
- Sides = agg_basics.Clamp(Sides, 3, 360, ref valuesChanged);
- height = agg_basics.Clamp(height, .01, 1000000, ref valuesChanged);
- diameter = agg_basics.Clamp(diameter, .01, 1000000, ref valuesChanged);
- var startingAngle = agg_basics.Clamp(StartingAngle.Value(this), 0, 360 - .01, ref valuesChanged);
- var endingAngle = agg_basics.Clamp(EndingAngle.Value(this), StartingAngle.Value(this) + .01, 360, ref valuesChanged);
+ double height = Height.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
+ var diameter = Diameter.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
+ var diameterTop = DiameterTop.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
+ var sides = Sides.ClampIfNotCalculated(this, 3, 360, ref valuesChanged);
+ var startingAngle = StartingAngle.ClampIfNotCalculated(this, 0, 360 - .01, ref valuesChanged);
+ var endingAngle = EndingAngle.ClampIfNotCalculated(this, StartingAngle.Value(this) + .01, 360, ref valuesChanged);
if (valuesChanged)
{
@@ -187,7 +185,7 @@ namespace MatterHackers.MatterControl.DesignTools
path.LineTo(diameter / 2, height / 2);
path.LineTo(0, height / 2);
- Mesh = VertexSourceToMesh.Revolve(path, Sides);
+ Mesh = VertexSourceToMesh.Revolve(path, sides);
}
else
{
@@ -197,7 +195,7 @@ namespace MatterHackers.MatterControl.DesignTools
path.LineTo(diameterTop / 2, height / 2);
path.LineTo(0, height / 2);
- Mesh = VertexSourceToMesh.Revolve(path, Sides, MathHelper.DegreesToRadians(startingAngle), MathHelper.DegreesToRadians(endingAngle));
+ Mesh = VertexSourceToMesh.Revolve(path, sides, MathHelper.DegreesToRadians(startingAngle), MathHelper.DegreesToRadians(endingAngle));
}
}
}
diff --git a/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs b/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs
index 8b96296cc..978bebe33 100644
--- a/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs
+++ b/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs
@@ -116,12 +116,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
var controls = object3DControlsLayer.Object3DControls;
- object3DControlsLayer.AddWidthDepthControls(() => Width.Value(this),
- (width) => Width = width,
- () => Depth.Value(this),
- (depth) => Depth = depth,
- null,
- null);
+ object3DControlsLayer.AddWidthDepthControls(this, Width, Depth, null);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
diff --git a/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs b/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs
index 420cf9bbe..f0d82a0dd 100644
--- a/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs
+++ b/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs
@@ -110,12 +110,7 @@ namespace MatterHackers.MatterControl.DesignTools
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height));
- object3DControlsLayer.AddWidthDepthControls(() => Width.Value(this),
- (width) => Width = width,
- () => Depth.Value(this),
- (depth) => Depth = depth,
- () => Height.Value(this),
- (height) => Height = height);
+ object3DControlsLayer.AddWidthDepthControls(this, Width, Depth, Height);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
diff --git a/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs b/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs
index 2e6a4b928..1ca1dae41 100644
--- a/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs
+++ b/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs
@@ -111,12 +111,7 @@ namespace MatterHackers.MatterControl.DesignTools
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height));
- object3DControlsLayer.AddWidthDepthControls(() => Width.Value(this),
- (width) => Width = width,
- () => Depth.Value(this),
- (depth) => Depth = depth,
- () => Height.Value(this),
- (height) => Height = height);
+ object3DControlsLayer.AddWidthDepthControls(this, Width, Depth, Height);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
diff --git a/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs b/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs
index 70d6ec2af..22600e30d 100644
--- a/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs
+++ b/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs
@@ -146,12 +146,7 @@ namespace MatterHackers.MatterControl.DesignTools
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height));
- object3DControlsLayer.AddWidthDepthControls(() => Width.Value(this),
- (width) => Width = width,
- () => Depth.Value(this),
- (depth) => Depth = depth,
- () => Height.Value(this),
- (height) => Height = height);
+ object3DControlsLayer.AddWidthDepthControls(this, Width, Depth, Height);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
diff --git a/MatterControlLib/DesignTools/Sheets/DoubleOrExpression.cs b/MatterControlLib/DesignTools/Sheets/DoubleOrExpression.cs
index 0cd3609f9..cec1cdc50 100644
--- a/MatterControlLib/DesignTools/Sheets/DoubleOrExpression.cs
+++ b/MatterControlLib/DesignTools/Sheets/DoubleOrExpression.cs
@@ -27,7 +27,9 @@ 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 MatterHackers.Agg;
using MatterHackers.DataConverters3D;
namespace MatterHackers.MatterControl.DesignTools
@@ -35,15 +37,15 @@ namespace MatterHackers.MatterControl.DesignTools
[TypeConverter(typeof(DoubleOrExpression))]
public class DoubleOrExpression
{
+ ///
+ /// 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 double Value(IObject3D owner)
{
- if (double.TryParse(Expression, out double result))
- {
- return result;
- }
-
return SheetObject3D.EvaluateExpression(owner, Expression);
}
@@ -66,5 +68,26 @@ namespace MatterHackers.MatterControl.DesignTools
{
return new DoubleOrExpression(expression);
}
+
+ ///
+ /// Evaluate the expression clap the result and return the clamped value.
+ /// If the expression as not an equation, modify it to be the clamped value.
+ ///
+ /// The Object to find the table relative to
+ /// The min value to clamp to
+ /// The max value to clamp to
+ /// Did the value actual get changed (clamped).
+ ///
+ public double ClampIfNotCalculated(IObject3D item, double min, double max, ref bool valuesChanged)
+ {
+ var value = agg_basics.Clamp(this.Value(item), min, max, ref valuesChanged);
+ if (!this.IsEquation)
+ {
+ // clamp the actual expression as it is not an equation
+ Expression = value.ToString();
+ }
+
+ return value;
+ }
}
}
\ No newline at end of file
diff --git a/MatterControlLib/DesignTools/Sheets/IntOrExpression.cs b/MatterControlLib/DesignTools/Sheets/IntOrExpression.cs
index 39135ae23..6b8483233 100644
--- a/MatterControlLib/DesignTools/Sheets/IntOrExpression.cs
+++ b/MatterControlLib/DesignTools/Sheets/IntOrExpression.cs
@@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
*/
using System.ComponentModel;
+using MatterHackers.Agg;
using MatterHackers.DataConverters3D;
namespace MatterHackers.MatterControl.DesignTools
@@ -37,13 +38,13 @@ namespace MatterHackers.MatterControl.DesignTools
{
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)
{
- if (int.TryParse(Expression, out int result))
- {
- return result;
- }
-
return SheetObject3D.EvaluateExpression(owner, Expression);
}
@@ -52,6 +53,11 @@ namespace MatterHackers.MatterControl.DesignTools
Expression = value.ToString();
}
+ public IntOrExpression(double value)
+ {
+ Expression = ((int)value).ToString();
+ }
+
public IntOrExpression(string expression)
{
Expression = expression;
@@ -62,9 +68,35 @@ namespace MatterHackers.MatterControl.DesignTools
return new IntOrExpression(value);
}
+ public static implicit operator IntOrExpression(double value)
+ {
+ return new IntOrExpression(value);
+ }
+
public static implicit operator IntOrExpression(string expression)
{
return new IntOrExpression(expression);
}
+
+ ///
+ /// Evaluate the expression clap the result and return the clamped value.
+ /// If the expression as not an equation, modify it to be the clamped value.
+ ///
+ /// The Object to find the table relative to
+ /// The min value to clamp to
+ /// The max value to clamp to
+ /// Did the value actual get changed (clamped).
+ ///
+ public int ClampIfNotCalculated(IObject3D item, int min, int max, ref bool valuesChanged)
+ {
+ var value = agg_basics.Clamp(this.Value(item), min, max, ref valuesChanged);
+ if (!this.IsEquation)
+ {
+ // clamp the actual expression as it is not an equation
+ Expression = value.ToString();
+ }
+
+ return value;
+ }
}
}
\ No newline at end of file
diff --git a/MatterControlLib/DesignTools/Sheets/SheetData.cs b/MatterControlLib/DesignTools/Sheets/SheetData.cs
index 102e697ab..5129b6a75 100644
--- a/MatterControlLib/DesignTools/Sheets/SheetData.cs
+++ b/MatterControlLib/DesignTools/Sheets/SheetData.cs
@@ -36,6 +36,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
public class SheetData
{
+ private object locker = new object();
public SheetData()
{
}
@@ -51,33 +52,49 @@ namespace MatterHackers.MatterControl.DesignTools
public string EvaluateExpression(string expression)
{
- if (!tabelCalculated)
+ lock (locker)
{
- Recalculate();
+ if (!tabelCalculated)
+ {
+ Recalculate();
+ }
+
+ if(expression.StartsWith("="))
+ {
+ expression = expression.Substring(1);
+ }
+ var evaluator = new Expression(expression);
+ AddConstants(evaluator);
+ var value = evaluator.calculate();
+
+ return value.ToString();
}
-
- var evaluator = new Expression(expression);
- AddConstants(evaluator);
- var value = evaluator.calculate();
-
- return value.ToString();
}
public string CellId(int x, int y)
{
- return $"{(char)('A' + x)}{y + 1}";
+ lock (locker)
+ {
+ return $"{(char)('A' + x)}{y + 1}";
+ }
}
public TableCell this[int x, int y]
{
get
{
- return this[CellId(x, y)];
+ lock (locker)
+ {
+ return this[CellId(x, y)];
+ }
}
set
{
- this[CellId(x, y)] = value;
+ lock (locker)
+ {
+ this[CellId(x, y)] = value;
+ }
}
}
@@ -85,46 +102,52 @@ namespace MatterHackers.MatterControl.DesignTools
{
get
{
- if (cellId.Length == 2)
+ lock (locker)
{
- var x = cellId.Substring(0, 1).ToUpper()[0] - 'A';
- var y = cellId.Substring(1, 1)[0] - '1';
- return Rows[y].Cells[x];
- }
- else
- {
- foreach (var row in Rows)
+ if (cellId.Length == 2)
{
- foreach(var cell in row.Cells)
+ var x = cellId.Substring(0, 1).ToUpper()[0] - 'A';
+ var y = cellId.Substring(1, 1)[0] - '1';
+ return Rows[y].Cells[x];
+ }
+ else
+ {
+ foreach (var row in Rows)
{
- if (cell.Name == cellId)
+ foreach (var cell in row.Cells)
{
- return cell;
+ if (cell.Name == cellId)
+ {
+ return cell;
+ }
}
}
}
- }
- return null;
+ return null;
+ }
}
set
{
- if (cellId.Length == 2)
+ lock (locker)
{
- var x = cellId.Substring(0, 1).ToUpper()[0] - 'A';
- var y = cellId.Substring(1, 1)[0] - '1';
- Rows[y].Cells[x] = value;
- }
- else
- {
- foreach (var row in Rows)
+ if (cellId.Length == 2)
{
- for (int i = 0; i < row.Cells.Count; i++)
+ var x = cellId.Substring(0, 1).ToUpper()[0] - 'A';
+ var y = cellId.Substring(1, 1)[0] - '1';
+ Rows[y].Cells[x] = value;
+ }
+ else
+ {
+ foreach (var row in Rows)
{
- if (row.Cells[i].Name == cellId)
+ for (int i = 0; i < row.Cells.Count; i++)
{
- row.Cells[i] = value;
+ if (row.Cells[i].Name == cellId)
+ {
+ row.Cells[i] = value;
+ }
}
}
}
@@ -202,56 +225,65 @@ namespace MatterHackers.MatterControl.DesignTools
private IEnumerable<(int x, int y, TableCell cell)> EnumerateCells()
{
- for (int y = 0; y < Rows.Count; y++)
+ lock (locker)
{
- for (int x = 0; x < Rows[y].Cells.Count; x++)
+ for (int y = 0; y < Rows.Count; y++)
{
- yield return (x, y, this[x, y]);
+ for (int x = 0; x < Rows[y].Cells.Count; x++)
+ {
+ yield return (x, y, this[x, y]);
+ }
}
}
}
public void Recalculate()
{
- constants.Clear();
-
- // WIP: sort the cell by reference (needs to be DAG)
- var list = EnumerateCells().OrderByDescending(i => i.cell.Expression).ToList();
- foreach (var xyc in list)
+ lock (locker)
{
- var expression = xyc.cell.Expression;
- if (expression.StartsWith("="))
+ constants.Clear();
+
+ // WIP: sort the cell by reference (needs to be DAG)
+ var list = EnumerateCells().OrderByDescending(i => i.cell.Expression).ToList();
+ foreach (var xyc in list)
{
- expression = expression.Substring(1);
- }
- if (expression.StartsWith("."))
- {
- expression = "0" + expression;
- }
- var evaluator = new Expression(expression);
- AddConstants(evaluator);
- var value = evaluator.calculate();
- if (double.IsNaN(value)
- || double.IsInfinity(value))
- {
- value = 0;
+ var expression = xyc.cell.Expression;
+ if (expression.StartsWith("="))
+ {
+ expression = expression.Substring(1);
+ }
+ if (expression.StartsWith("."))
+ {
+ expression = "0" + expression;
+ }
+ var evaluator = new Expression(expression);
+ AddConstants(evaluator);
+ var value = evaluator.calculate();
+ if (double.IsNaN(value)
+ || double.IsInfinity(value))
+ {
+ value = 0;
+ }
+
+ constants.Add(CellId(xyc.x, xyc.y), value);
+ if (!string.IsNullOrEmpty(xyc.cell.Name))
+ {
+ constants.Add(xyc.cell.Name, value);
+ }
}
- constants.Add(CellId(xyc.x, xyc.y), value);
- if (!string.IsNullOrEmpty(xyc.cell.Name))
- {
- constants.Add(xyc.cell.Name, value);
- }
+ tabelCalculated = true;
}
-
- tabelCalculated = true;
}
private void AddConstants(Expression evaluator)
{
- foreach(var kvp in constants)
+ lock (locker)
{
- evaluator.defineConstant(kvp.Key, kvp.Value);
+ foreach (var kvp in constants)
+ {
+ evaluator.defineConstant(kvp.Key, kvp.Value);
+ }
}
}
}
diff --git a/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs b/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs
index 1475eee3e..7b3c2a92e 100644
--- a/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs
+++ b/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs
@@ -116,6 +116,34 @@ namespace MatterHackers.MatterControl.DesignTools
public static T EvaluateExpression(IObject3D owner, string inputExpression)
{
+ // check if the expression is not an equation (does not start with "=")
+ if (inputExpression.Length > 0 && inputExpression[0] != '=')
+ {
+ // not an equation so try to parse it directly
+ if (double.TryParse(inputExpression, out var result))
+ {
+ if (typeof(T) == typeof(double))
+ {
+ return (T)(object)result;
+ }
+ if (typeof(T) == typeof(int))
+ {
+ return (T)(object)(int)Math.Round(result);
+ }
+ }
+ else
+ {
+ if (typeof(T) == typeof(double))
+ {
+ return (T)(object)0.0;
+ }
+ if (typeof(T) == typeof(int))
+ {
+ return (T)(object)0;
+ }
+ }
+ }
+
// look through all the parents
foreach (var parent in owner.Parents())
{
diff --git a/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs b/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs
index a1a21c547..82ef7fc42 100644
--- a/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs
+++ b/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs
@@ -207,17 +207,43 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
base.OnDraw(graphics2D);
}
- public void AddWidthDepthControls(Func getWidth,
- Action setWidth,
- Func getDepth,
- Action setDepth,
- Func getHeight,
- Action setHeight)
+ public void AddWidthDepthControls(IObject3D item, DoubleOrExpression width, DoubleOrExpression depth, DoubleOrExpression height)
{
- for (int i = 0; i < 4; i++)
+ Func getWidth = () => width.Value(item);
+ Action setWidth = (newWidth) => width.Expression = newWidth.ToString();
+ Func getDepth = () => depth.Value(item);
+ Action setDepth = (newDepth) => depth.Expression = newDepth.ToString();
+ Func getHeight = () => height.Value(item);
+ Action setHeight = (newHeight) => height.Expression = newHeight.ToString();
+
+ if (width != null
+ && !width.IsEquation
+ && depth != null
+ && !depth.IsEquation)
{
- Object3DControls.Add(new ScaleWidthDepthCornerControl(this, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, i));
- Object3DControls.Add(new ScaleWidthDepthEdgeControl(this, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, i));
+ for (int i = 0; i < 4; i++)
+ {
+ Object3DControls.Add(new ScaleWidthDepthCornerControl(this, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, i));
+ Object3DControls.Add(new ScaleWidthDepthEdgeControl(this, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, i));
+ }
+ }
+ else
+ {
+ // if the width is set and a constant
+ if (width != null && !width.IsEquation)
+ {
+ // add width side controls
+ Object3DControls.Add(new ScaleWidthDepthEdgeControl(this, getWidth, setWidth, null, null, getHeight, setHeight, 1));
+ Object3DControls.Add(new ScaleWidthDepthEdgeControl(this, getWidth, setWidth, null, null, getHeight, setHeight, 3));
+ }
+
+ // if the depth is set and a constant
+ if (depth != null && !depth.IsEquation)
+ {
+ // add depth side controls
+ Object3DControls.Add(new ScaleWidthDepthEdgeControl(this, null, null, getDepth, setDepth, getHeight, setHeight, 0));
+ Object3DControls.Add(new ScaleWidthDepthEdgeControl(this, null, null, getDepth, setDepth, getHeight, setHeight, 2));
+ }
}
}