From 95543966d3531bc35f08884acf6c62bf3dc3f1b9 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sat, 12 Sep 2020 11:34:18 -0700 Subject: [PATCH] Making array names better --- .../ApplicationView/ApplicationController.cs | 3 + .../Operations/ArrayAdvancedObject3D.cs | 4 +- .../Operations/ArrayLinearObject3D.cs | 23 ++++-- .../Operations/ArrayRadialObject3D.cs | 4 +- .../PartPreviewWindow/Object3DTreeBuilder.cs | 80 ++++++++++--------- .../PartPreviewWindow/View3D/SceneActions.cs | 10 ++- Submodules/agg-sharp | 2 +- 7 files changed, 73 insertions(+), 53 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 33f95c8e0..8a44ace88 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -773,6 +773,7 @@ namespace MatterHackers.MatterControl Action = (sceneContext) => { var array = new ArrayLinearObject3D(); + array.Name = ""; // this will get the default behavior of showing the child's name + a count array.AddSelectionAsChildren(sceneContext.Scene, sceneContext.Scene.SelectedItem); }, Icon = (invertIcon) => AggContext.StaticData.LoadIcon("array_linear.png", 16, 16).SetPreMultiply(), @@ -786,6 +787,7 @@ namespace MatterHackers.MatterControl Action = (sceneContext) => { var array = new ArrayRadialObject3D(); + array.Name = ""; // this will get the default behavior of showing the child's name + a count array.AddSelectionAsChildren(sceneContext.Scene, sceneContext.Scene.SelectedItem); }, Icon = (invertIcon) => AggContext.StaticData.LoadIcon("array_radial.png", 16, 16).SetPreMultiply(), @@ -799,6 +801,7 @@ namespace MatterHackers.MatterControl Action = (sceneContext) => { var array = new ArrayAdvancedObject3D(); + array.Name = ""; // this will get the default behavior of showing the child's name + a count array.AddSelectionAsChildren(sceneContext.Scene, sceneContext.Scene.SelectedItem); }, Icon = (invertIcon) => AggContext.StaticData.LoadIcon("array_advanced.png", 16, 16).SetPreMultiply(), diff --git a/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs index 0ddb45c88..ada6d2889 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs @@ -36,7 +36,7 @@ using System.Threading.Tasks; namespace MatterHackers.MatterControl.DesignTools.Operations { - public class ArrayAdvancedObject3D : OperationSourceContainerObject3D + public class ArrayAdvancedObject3D : ArrayObject3D { public ArrayAdvancedObject3D() { @@ -45,7 +45,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations public override bool CanFlatten => true; - public int Count { get; set; } = 3; + public override int Count { get; set; } = 3; public Vector3 Offset { get; set; } = new Vector3(30, 0, 0); diff --git a/MatterControlLib/DesignTools/Operations/ArrayLinearObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayLinearObject3D.cs index f92152948..b695668ce 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayLinearObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayLinearObject3D.cs @@ -27,18 +27,23 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ -using MatterHackers.DataConverters3D; -using MatterHackers.Localizations; -using MatterHackers.MatterControl.DesignTools.EditableTypes; -using MatterHackers.VectorMath; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using MatterHackers.DataConverters3D; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.DesignTools.EditableTypes; +using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.DesignTools.Operations { - public class ArrayLinearObject3D : OperationSourceContainerObject3D + public abstract class ArrayObject3D : OperationSourceContainerObject3D + { + public abstract int Count { get; set; } + } + + public class ArrayLinearObject3D : ArrayObject3D { public ArrayLinearObject3D() { @@ -46,10 +51,13 @@ namespace MatterHackers.MatterControl.DesignTools.Operations } public override bool CanFlatten => true; - public int Count { get; set; } = 3; + + public override int Count { get; set; } = 3; + public DirectionVector Direction { get; set; } = new DirectionVector { Normal = new Vector3(1, 0, 0) }; + public double Distance { get; set; } = 30; - + public override async Task Rebuild() { var rebuildLock = this.RebuildLock(); @@ -84,6 +92,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations list.AddRange(newChildren); }); } + SourceContainer.Visible = false; rebuildLock.Dispose(); Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); diff --git a/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs index 57a54bf87..985d71413 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs @@ -42,7 +42,7 @@ using System.Threading.Tasks; namespace MatterHackers.MatterControl.DesignTools.Operations { - public class ArrayRadialObject3D : OperationSourceContainerObject3D, IEditorDraw + public class ArrayRadialObject3D : ArrayObject3D, IEditorDraw { public ArrayRadialObject3D() { @@ -54,7 +54,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations public override bool CanFlatten => true; - public int Count { get; set; } = 3; + public override int Count { get; set; } = 3; [Description("Rotate the part to the same angle as the array.")] public bool RotatePart { get; set; } = true; diff --git a/MatterControlLib/PartPreviewWindow/Object3DTreeBuilder.cs b/MatterControlLib/PartPreviewWindow/Object3DTreeBuilder.cs index 1d3234c22..565e57410 100644 --- a/MatterControlLib/PartPreviewWindow/Object3DTreeBuilder.cs +++ b/MatterControlLib/PartPreviewWindow/Object3DTreeBuilder.cs @@ -139,51 +139,55 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private static ObjectView BuildItemView(IObject3D item) { - switch (item) + string GetArrayName(ArrayObject3D arrayItem) { - case TransformWrapperObject3D transformWrapperObject3D: - return new ObjectView() + if (string.IsNullOrWhiteSpace(item.Name) + && arrayItem?.SourceContainer?.Children?.Any() == true) + { + var childName = arrayItem.SourceContainer.Children.First().Name; + if (childName.Length > 20) { - Children = transformWrapperObject3D.UntransformedChildren, - Name = item.Name, - Source = item - }; + childName = childName.Substring(0, 20) + "..."; + } - case ArrayLinearObject3D arrayLinear3D: - return new ObjectView() - { - Children = item.Children.OfType().ToList(), - Name = $"{arrayLinear3D.Name} ({arrayLinear3D.Count})", - Source = item - }; + return $"{childName} - x{arrayItem.Count}"; + } - case ArrayAdvancedObject3D arrayAdvanced3D: - return new ObjectView() - { - Children = item.Children.OfType().ToList(), - Name = $"{arrayAdvanced3D.Name} ({arrayAdvanced3D.Count})", - Source = item - }; + return arrayItem.Name; + } - // TODO: array operations should only expose OperationSource - case ArrayRadialObject3D arrayRadial3D: - return new ObjectView() - { - Children = item.Children.OfType().ToList(), - Name = $"{arrayRadial3D.Name} ({arrayRadial3D.Count})", - Source = item - }; + if (item is ArrayObject3D array) + { + return new ObjectView() + { + Children = item.Children.OfType().ToList(), + Name = GetArrayName(array), + Source = item + }; + } + else + { + switch (item) + { + case TransformWrapperObject3D transformWrapperObject3D: + return new ObjectView() + { + Children = transformWrapperObject3D.UntransformedChildren, + Name = item.Name, + Source = item + }; - case OperationSourceContainerObject3D operationSourceContainerObject3D: - return new ObjectView() - { - Children = item.Children.OfType().ToList(), - Name = operationSourceContainerObject3D.Name, - Source = item - }; + case OperationSourceContainerObject3D operationSourceContainerObject3D: + return new ObjectView() + { + Children = item.Children.OfType().ToList(), + Name = operationSourceContainerObject3D.Name, + Source = item + }; - default: - return new ObjectView(item); + default: + return new ObjectView(item); + } } } diff --git a/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs b/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs index f9dfe3fb6..635958550 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs @@ -261,9 +261,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var clonedItem = sourceItem.Clone(); clonedItem.Translate(xOffset); - // make the name unique - var newName = agg_basics.GetNonCollidingName(sourceItem.Name, scene.DescendantsAndSelf().Select((d) => d.Name)); - clonedItem.Name = newName; + // an empty string is used do denote special name processing for some container types + if (!string.IsNullOrWhiteSpace(sourceItem.Name)) + { + // make the name unique + var newName = agg_basics.GetNonCollidingName(sourceItem.Name, scene.DescendantsAndSelf().Select((d) => d.Name)); + clonedItem.Name = newName; + } // More useful if it creates the part in the exact position and then the user can move it. // Consistent with other software as well. LBB 2017-12-02 diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 63001c23d..67e40e4f7 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 63001c23de74c62477522796d4ec04360dc2f7db +Subproject commit 67e40e4f7b7109e258eebf8642ea45cf39e051ba