Making array names better

This commit is contained in:
LarsBrubaker 2020-09-12 11:34:18 -07:00
parent 49447fa38f
commit 95543966d3
7 changed files with 73 additions and 53 deletions

View file

@ -773,6 +773,7 @@ namespace MatterHackers.MatterControl
Action = (sceneContext) => Action = (sceneContext) =>
{ {
var array = new ArrayLinearObject3D(); 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); array.AddSelectionAsChildren(sceneContext.Scene, sceneContext.Scene.SelectedItem);
}, },
Icon = (invertIcon) => AggContext.StaticData.LoadIcon("array_linear.png", 16, 16).SetPreMultiply(), Icon = (invertIcon) => AggContext.StaticData.LoadIcon("array_linear.png", 16, 16).SetPreMultiply(),
@ -786,6 +787,7 @@ namespace MatterHackers.MatterControl
Action = (sceneContext) => Action = (sceneContext) =>
{ {
var array = new ArrayRadialObject3D(); 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); array.AddSelectionAsChildren(sceneContext.Scene, sceneContext.Scene.SelectedItem);
}, },
Icon = (invertIcon) => AggContext.StaticData.LoadIcon("array_radial.png", 16, 16).SetPreMultiply(), Icon = (invertIcon) => AggContext.StaticData.LoadIcon("array_radial.png", 16, 16).SetPreMultiply(),
@ -799,6 +801,7 @@ namespace MatterHackers.MatterControl
Action = (sceneContext) => Action = (sceneContext) =>
{ {
var array = new ArrayAdvancedObject3D(); 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); array.AddSelectionAsChildren(sceneContext.Scene, sceneContext.Scene.SelectedItem);
}, },
Icon = (invertIcon) => AggContext.StaticData.LoadIcon("array_advanced.png", 16, 16).SetPreMultiply(), Icon = (invertIcon) => AggContext.StaticData.LoadIcon("array_advanced.png", 16, 16).SetPreMultiply(),

View file

@ -36,7 +36,7 @@ using System.Threading.Tasks;
namespace MatterHackers.MatterControl.DesignTools.Operations namespace MatterHackers.MatterControl.DesignTools.Operations
{ {
public class ArrayAdvancedObject3D : OperationSourceContainerObject3D public class ArrayAdvancedObject3D : ArrayObject3D
{ {
public ArrayAdvancedObject3D() public ArrayAdvancedObject3D()
{ {
@ -45,7 +45,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public override bool CanFlatten => true; 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); public Vector3 Offset { get; set; } = new Vector3(30, 0, 0);

View file

@ -27,18 +27,23 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project. 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.EditableTypes;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools.Operations 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() public ArrayLinearObject3D()
{ {
@ -46,10 +51,13 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
} }
public override bool CanFlatten => true; 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 DirectionVector Direction { get; set; } = new DirectionVector { Normal = new Vector3(1, 0, 0) };
public double Distance { get; set; } = 30; public double Distance { get; set; } = 30;
public override async Task Rebuild() public override async Task Rebuild()
{ {
var rebuildLock = this.RebuildLock(); var rebuildLock = this.RebuildLock();
@ -84,6 +92,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
list.AddRange(newChildren); list.AddRange(newChildren);
}); });
} }
SourceContainer.Visible = false; SourceContainer.Visible = false;
rebuildLock.Dispose(); rebuildLock.Dispose();
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));

View file

@ -42,7 +42,7 @@ using System.Threading.Tasks;
namespace MatterHackers.MatterControl.DesignTools.Operations namespace MatterHackers.MatterControl.DesignTools.Operations
{ {
public class ArrayRadialObject3D : OperationSourceContainerObject3D, IEditorDraw public class ArrayRadialObject3D : ArrayObject3D, IEditorDraw
{ {
public ArrayRadialObject3D() public ArrayRadialObject3D()
{ {
@ -54,7 +54,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public override bool CanFlatten => true; 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.")] [Description("Rotate the part to the same angle as the array.")]
public bool RotatePart { get; set; } = true; public bool RotatePart { get; set; } = true;

View file

@ -139,51 +139,55 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private static ObjectView BuildItemView(IObject3D item) private static ObjectView BuildItemView(IObject3D item)
{ {
switch (item) string GetArrayName(ArrayObject3D arrayItem)
{ {
case TransformWrapperObject3D transformWrapperObject3D: if (string.IsNullOrWhiteSpace(item.Name)
return new ObjectView() && arrayItem?.SourceContainer?.Children?.Any() == true)
{
var childName = arrayItem.SourceContainer.Children.First().Name;
if (childName.Length > 20)
{ {
Children = transformWrapperObject3D.UntransformedChildren, childName = childName.Substring(0, 20) + "...";
Name = item.Name, }
Source = item
};
case ArrayLinearObject3D arrayLinear3D: return $"{childName} - x{arrayItem.Count}";
return new ObjectView() }
{
Children = item.Children.OfType<OperationSourceObject3D>().ToList(),
Name = $"{arrayLinear3D.Name} ({arrayLinear3D.Count})",
Source = item
};
case ArrayAdvancedObject3D arrayAdvanced3D: return arrayItem.Name;
return new ObjectView() }
{
Children = item.Children.OfType<OperationSourceObject3D>().ToList(),
Name = $"{arrayAdvanced3D.Name} ({arrayAdvanced3D.Count})",
Source = item
};
// TODO: array operations should only expose OperationSource if (item is ArrayObject3D array)
case ArrayRadialObject3D arrayRadial3D: {
return new ObjectView() return new ObjectView()
{ {
Children = item.Children.OfType<OperationSourceObject3D>().ToList(), Children = item.Children.OfType<OperationSourceObject3D>().ToList(),
Name = $"{arrayRadial3D.Name} ({arrayRadial3D.Count})", Name = GetArrayName(array),
Source = item Source = item
}; };
}
else
{
switch (item)
{
case TransformWrapperObject3D transformWrapperObject3D:
return new ObjectView()
{
Children = transformWrapperObject3D.UntransformedChildren,
Name = item.Name,
Source = item
};
case OperationSourceContainerObject3D operationSourceContainerObject3D: case OperationSourceContainerObject3D operationSourceContainerObject3D:
return new ObjectView() return new ObjectView()
{ {
Children = item.Children.OfType<OperationSourceObject3D>().ToList(), Children = item.Children.OfType<OperationSourceObject3D>().ToList(),
Name = operationSourceContainerObject3D.Name, Name = operationSourceContainerObject3D.Name,
Source = item Source = item
}; };
default: default:
return new ObjectView(item); return new ObjectView(item);
}
} }
} }

View file

@ -261,9 +261,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
var clonedItem = sourceItem.Clone(); var clonedItem = sourceItem.Clone();
clonedItem.Translate(xOffset); clonedItem.Translate(xOffset);
// make the name unique // an empty string is used do denote special name processing for some container types
var newName = agg_basics.GetNonCollidingName(sourceItem.Name, scene.DescendantsAndSelf().Select((d) => d.Name)); if (!string.IsNullOrWhiteSpace(sourceItem.Name))
clonedItem.Name = newName; {
// 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. // 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 // Consistent with other software as well. LBB 2017-12-02

@ -1 +1 @@
Subproject commit 63001c23de74c62477522796d4ec04360dc2f7db Subproject commit 67e40e4f7b7109e258eebf8642ea45cf39e051ba