Made a new scale transform control that has width depth height
This commit is contained in:
parent
e5b290e06a
commit
8bd06fe3da
7 changed files with 117 additions and 134 deletions
|
|
@ -42,9 +42,14 @@ using Newtonsoft.Json;
|
|||
|
||||
namespace MatterHackers.MatterControl.DesignTools.Operations
|
||||
{
|
||||
public class ScaleObject3D_2 : TransformWrapperObject3D, IObjectWithHeight, IObjectWithWidthAndDepth, ISelectedEditorDraw, IPropertyGridModifier
|
||||
public interface IScaleLocker
|
||||
{
|
||||
public enum ScaleType
|
||||
bool ScaleLocked { get; }
|
||||
}
|
||||
|
||||
public class ScaleObject3D_2 : TransformWrapperObject3D, IObjectWithHeight, IObjectWithWidthAndDepth, IPropertyGridModifier, IScaleLocker
|
||||
{
|
||||
public enum ScaleTypes
|
||||
{
|
||||
Custom,
|
||||
Inches_to_mm,
|
||||
|
|
@ -98,102 +103,126 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
// this is the size we actually serialize
|
||||
public Vector3 ScaleRatio = Vector3.One;
|
||||
|
||||
public ScaleType Operation { get; set; } = ScaleType.Custom;
|
||||
public ScaleTypes ScaleType { get; set; } = ScaleTypes.Custom;
|
||||
|
||||
public enum ScaleMethods
|
||||
{
|
||||
Direct,
|
||||
Percentage,
|
||||
}
|
||||
|
||||
[EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Tabs)]
|
||||
public ScaleMethods ScaleMethod { get; set; } = ScaleMethods.Direct;
|
||||
|
||||
[Description("Ensure that the part maintains its proportions.")]
|
||||
public bool LockProportions { get; set; } = true;
|
||||
|
||||
|
||||
[MaxDecimalPlaces(3)]
|
||||
[JsonIgnore]
|
||||
public double Width
|
||||
{
|
||||
get
|
||||
{
|
||||
if (UsePercentage)
|
||||
{
|
||||
return ScaleRatio.X * 100;
|
||||
}
|
||||
|
||||
return ScaleRatio.X * UntransformedChildren.GetAxisAlignedBoundingBox().XSize;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (UsePercentage)
|
||||
{
|
||||
ScaleRatio.X = value / 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
ScaleRatio.X = value / UntransformedChildren.GetAxisAlignedBoundingBox().XSize;
|
||||
}
|
||||
ScaleRatio.X = value / UntransformedChildren.GetAxisAlignedBoundingBox().XSize;
|
||||
FixIfLockedProportions(0);
|
||||
}
|
||||
}
|
||||
|
||||
[MaxDecimalPlaces(3)]
|
||||
[JsonIgnore]
|
||||
public double Depth
|
||||
{
|
||||
get
|
||||
{
|
||||
if (UsePercentage)
|
||||
{
|
||||
return ScaleRatio.Y * 100;
|
||||
}
|
||||
|
||||
return ScaleRatio.Y * UntransformedChildren.GetAxisAlignedBoundingBox().YSize;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (UsePercentage)
|
||||
{
|
||||
ScaleRatio.Y = value / 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
ScaleRatio.Y = value / UntransformedChildren.GetAxisAlignedBoundingBox().YSize;
|
||||
}
|
||||
ScaleRatio.Y = value / UntransformedChildren.GetAxisAlignedBoundingBox().YSize;
|
||||
FixIfLockedProportions(1);
|
||||
}
|
||||
}
|
||||
|
||||
[MaxDecimalPlaces(3)]
|
||||
[JsonIgnore]
|
||||
public double Height
|
||||
{
|
||||
get
|
||||
{
|
||||
if (UsePercentage)
|
||||
{
|
||||
return ScaleRatio.Z * 100;
|
||||
}
|
||||
|
||||
return ScaleRatio.Z * UntransformedChildren.GetAxisAlignedBoundingBox().ZSize;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (UsePercentage)
|
||||
{
|
||||
ScaleRatio.Z = value / 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
ScaleRatio.Z = value / UntransformedChildren.GetAxisAlignedBoundingBox().ZSize;
|
||||
}
|
||||
ScaleRatio.Z = value / UntransformedChildren.GetAxisAlignedBoundingBox().ZSize;
|
||||
FixIfLockedProportions(2);
|
||||
}
|
||||
}
|
||||
|
||||
[Description("Ensure that the part maintains its proportions.")]
|
||||
[DisplayName("Maintain Proportions")]
|
||||
public bool MaitainProportions { get; set; } = true;
|
||||
|
||||
[Description("Toggle between specifying the size or the percentage to scale.")]
|
||||
public bool UsePercentage { get; set; }
|
||||
|
||||
[Description("This is the position to perform the scale about.")]
|
||||
public Vector3 ScaleAbout { get; set; }
|
||||
|
||||
public void DrawEditor(Object3DControlsLayer layer, List<Object3DView> transparentMeshes, DrawEventArgs e)
|
||||
[MaxDecimalPlaces(2)]
|
||||
[JsonIgnore]
|
||||
public double WidthPercent
|
||||
{
|
||||
if (layer.Scene.SelectedItem != null
|
||||
&& layer.Scene.SelectedItem.DescendantsAndSelf().Where((i) => i == this).Any())
|
||||
get
|
||||
{
|
||||
layer.World.RenderAxis(ScaleAbout, this.WorldMatrix(), 30, 1);
|
||||
return ScaleRatio.X * 100;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ScaleRatio.X = value / 100;
|
||||
FixIfLockedProportions(0);
|
||||
}
|
||||
}
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
[JsonIgnore]
|
||||
public double DepthPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
return ScaleRatio.Y * 100;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ScaleRatio.Y = value / 100;
|
||||
FixIfLockedProportions(1);
|
||||
}
|
||||
}
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
[JsonIgnore]
|
||||
public double HeightPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
return ScaleRatio.Z * 100;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ScaleRatio.Z = value / 100;
|
||||
FixIfLockedProportions(2);
|
||||
}
|
||||
}
|
||||
|
||||
public bool ScaleLocked => LockProportions;
|
||||
|
||||
private void FixIfLockedProportions(int index)
|
||||
{
|
||||
if (LockProportions)
|
||||
{
|
||||
ScaleRatio[(index + 1) % 3] = ScaleRatio[index];
|
||||
ScaleRatio[(index + 2) % 3] = ScaleRatio[index];
|
||||
Invalidate(new InvalidateArgs(null, InvalidateType.DisplayValues));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -228,9 +257,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
{
|
||||
// set the matrix for the transform object
|
||||
ItemWithTransform.Matrix = Matrix4X4.Identity;
|
||||
ItemWithTransform.Matrix *= Matrix4X4.CreateTranslation(-ScaleAbout);
|
||||
ItemWithTransform.Matrix *= Matrix4X4.CreateScale(ScaleRatio);
|
||||
ItemWithTransform.Matrix *= Matrix4X4.CreateTranslation(ScaleAbout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -241,29 +268,30 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
|
||||
public void UpdateControls(PublicPropertyChange change)
|
||||
{
|
||||
change.SetRowVisible(nameof(Width), () => Operation == ScaleType.Custom);
|
||||
change.SetRowVisible(nameof(Depth), () => Operation == ScaleType.Custom);
|
||||
change.SetRowVisible(nameof(Height), () => Operation == ScaleType.Custom);
|
||||
change.SetRowVisible(nameof(MaitainProportions), () => Operation == ScaleType.Custom);
|
||||
change.SetRowVisible(nameof(UsePercentage), () => Operation == ScaleType.Custom);
|
||||
change.SetRowVisible(nameof(ScaleAbout), () => Operation == ScaleType.Custom);
|
||||
change.SetRowVisible(nameof(Width), () => ScaleType == ScaleTypes.Custom && ScaleMethod == ScaleMethods.Direct);
|
||||
change.SetRowVisible(nameof(Depth), () => ScaleType == ScaleTypes.Custom && ScaleMethod == ScaleMethods.Direct);
|
||||
change.SetRowVisible(nameof(Height), () => ScaleType == ScaleTypes.Custom && ScaleMethod == ScaleMethods.Direct);
|
||||
change.SetRowVisible(nameof(WidthPercent), () => ScaleType == ScaleTypes.Custom && ScaleMethod == ScaleMethods.Percentage);
|
||||
change.SetRowVisible(nameof(DepthPercent), () => ScaleType == ScaleTypes.Custom && ScaleMethod == ScaleMethods.Percentage);
|
||||
change.SetRowVisible(nameof(HeightPercent), () => ScaleType == ScaleTypes.Custom && ScaleMethod == ScaleMethods.Percentage);
|
||||
change.SetRowVisible(nameof(LockProportions), () => ScaleType == ScaleTypes.Custom);
|
||||
|
||||
if (change.Changed == nameof(Operation))
|
||||
if (change.Changed == nameof(ScaleType))
|
||||
{
|
||||
// recalculate the scaling
|
||||
double scale = 1;
|
||||
switch (Operation)
|
||||
switch (ScaleType)
|
||||
{
|
||||
case ScaleType.Inches_to_mm:
|
||||
case ScaleTypes.Inches_to_mm:
|
||||
scale = 25.4;
|
||||
break;
|
||||
case ScaleType.mm_to_Inches:
|
||||
case ScaleTypes.mm_to_Inches:
|
||||
scale = .0393;
|
||||
break;
|
||||
case ScaleType.mm_to_cm:
|
||||
case ScaleTypes.mm_to_cm:
|
||||
scale = .1;
|
||||
break;
|
||||
case ScaleType.cm_to_mm:
|
||||
case ScaleTypes.cm_to_mm:
|
||||
scale = 10;
|
||||
break;
|
||||
}
|
||||
|
|
@ -271,14 +299,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
ScaleRatio = new Vector3(scale, scale, scale);
|
||||
Rebuild();
|
||||
}
|
||||
else if (change.Changed == nameof(UsePercentage))
|
||||
else if (change.Changed == nameof(LockProportions))
|
||||
{
|
||||
// make sure we update the controls on screen to reflect the different data type
|
||||
Invalidate(new InvalidateArgs(null, InvalidateType.DisplayValues));
|
||||
}
|
||||
else if (change.Changed == nameof(MaitainProportions))
|
||||
{
|
||||
if (MaitainProportions)
|
||||
if (LockProportions)
|
||||
{
|
||||
var maxScale = Math.Max(ScaleRatio.X, Math.Max(ScaleRatio.Y, ScaleRatio.Z));
|
||||
ScaleRatio = new Vector3(maxScale, maxScale, maxScale);
|
||||
|
|
@ -287,48 +310,6 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
Invalidate(new InvalidateArgs(null, InvalidateType.DisplayValues));
|
||||
}
|
||||
}
|
||||
else if (change.Changed == nameof(Width))
|
||||
{
|
||||
if (MaitainProportions)
|
||||
{
|
||||
// scale y and z to match
|
||||
ScaleRatio[1] = ScaleRatio[0];
|
||||
ScaleRatio[2] = ScaleRatio[0];
|
||||
Rebuild();
|
||||
// and invalidate the other properties
|
||||
Invalidate(new InvalidateArgs(this, InvalidateType.Properties));
|
||||
// then update the display values
|
||||
Invalidate(new InvalidateArgs(null, InvalidateType.DisplayValues));
|
||||
}
|
||||
}
|
||||
else if (change.Changed == nameof(Depth))
|
||||
{
|
||||
if (MaitainProportions)
|
||||
{
|
||||
// scale y and z to match
|
||||
ScaleRatio[0] = ScaleRatio[1];
|
||||
ScaleRatio[2] = ScaleRatio[1];
|
||||
Rebuild();
|
||||
// and invalidate the other properties
|
||||
Invalidate(new InvalidateArgs(this, InvalidateType.Properties));
|
||||
// then update the display values
|
||||
Invalidate(new InvalidateArgs(null, InvalidateType.DisplayValues));
|
||||
}
|
||||
}
|
||||
else if (change.Changed == nameof(Height))
|
||||
{
|
||||
if (MaitainProportions)
|
||||
{
|
||||
// scale y and z to match
|
||||
ScaleRatio[0] = ScaleRatio[2];
|
||||
ScaleRatio[1] = ScaleRatio[2];
|
||||
Rebuild();
|
||||
// and invalidate the other properties
|
||||
Invalidate(new InvalidateArgs(this, InvalidateType.Properties));
|
||||
// then update the display values
|
||||
Invalidate(new InvalidateArgs(null, InvalidateType.DisplayValues));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue