Making better names for collection items (combine, align, subtract, intersect)
This commit is contained in:
parent
5e898a0650
commit
39af203e95
15 changed files with 121 additions and 100 deletions
|
|
@ -938,7 +938,7 @@ namespace MatterHackers.MatterControl
|
|||
new EditContext()
|
||||
{
|
||||
ContentStore = historyContainer,
|
||||
SourceItem = historyContainer.NewPlatingItem(onlyPrinter.Bed.Scene)
|
||||
SourceItem = historyContainer.NewBedPlate(onlyPrinter.Bed)
|
||||
});
|
||||
|
||||
UiThread.RunOnIdle(() =>
|
||||
|
|
@ -1568,7 +1568,7 @@ namespace MatterHackers.MatterControl
|
|||
await workspace.SceneContext.LoadContent(new EditContext()
|
||||
{
|
||||
ContentStore = history,
|
||||
SourceItem = history.NewPlatingItem(workspace.SceneContext.Scene)
|
||||
SourceItem = history.NewBedPlate(workspace.Printer.Bed)
|
||||
});
|
||||
|
||||
this.OpenWorkspace(workspace);
|
||||
|
|
|
|||
|
|
@ -189,15 +189,23 @@ namespace MatterHackers.MatterControl
|
|||
if (this.Printer != null)
|
||||
{
|
||||
this.Printer.ViewState.ViewMode = PartViewMode.Model;
|
||||
}
|
||||
|
||||
// Load
|
||||
this.LoadEmptyContent(
|
||||
new EditContext()
|
||||
{
|
||||
ContentStore = historyContainer,
|
||||
SourceItem = historyContainer.NewPlatingItem(this.Scene)
|
||||
});
|
||||
this.LoadEmptyContent(
|
||||
new EditContext()
|
||||
{
|
||||
ContentStore = historyContainer,
|
||||
SourceItem = historyContainer.NewBedPlate(this)
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.LoadEmptyContent(
|
||||
new EditContext()
|
||||
{
|
||||
ContentStore = historyContainer,
|
||||
SourceItem = historyContainer.NewDesign()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public InsertionGroupObject3D AddToPlate(IEnumerable<ILibraryItem> itemsToAdd)
|
||||
|
|
|
|||
|
|
@ -690,6 +690,8 @@ namespace MatterHackers.MatterControl
|
|||
var selectedItem = scene.SelectedItem;
|
||||
var align = new AlignObject3D();
|
||||
align.AddSelectionAsChildren(scene, selectedItem);
|
||||
align.Name = align.NameFromChildren();
|
||||
align.NameOverriden = false;
|
||||
},
|
||||
Icon = (theme) => StaticData.Instance.LoadIcon("align_left_dark.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
|
||||
HelpTextGetter = () => "At least 2 parts must be selected".Localize().Stars(),
|
||||
|
|
|
|||
|
|
@ -217,23 +217,6 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
|
||||
public override bool CanApply => true;
|
||||
|
||||
private List<Aabb> CurrentChildrenBounds
|
||||
{
|
||||
get
|
||||
{
|
||||
var currentChildrenBounds = new List<Aabb>();
|
||||
this.Children.Modify(list =>
|
||||
{
|
||||
foreach (var child in list)
|
||||
{
|
||||
currentChildrenBounds.Add(child.GetAxisAlignedBoundingBox());
|
||||
}
|
||||
});
|
||||
|
||||
return currentChildrenBounds;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
private Aabb AnchorBounds
|
||||
{
|
||||
|
|
@ -330,6 +313,12 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
{
|
||||
await Rebuild();
|
||||
}
|
||||
else if (invalidateArgs.InvalidateType.HasFlag(InvalidateType.Name)
|
||||
&& !NameOverriden)
|
||||
{
|
||||
Name = NameFromChildren();
|
||||
NameOverriden = false;
|
||||
}
|
||||
else if (SheetObject3D.NeedsRebuild(this, invalidateArgs))
|
||||
{
|
||||
await Rebuild();
|
||||
|
|
@ -384,6 +373,12 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
AlignAxis(2, ZAlign, GetAlignToOffset(anchorBounds, 2, (!Advanced || ZAlignTo == Align.None) ? ZAlign : ZAlignTo), ZOffset.Value(this), child);
|
||||
}
|
||||
});
|
||||
|
||||
if (!NameOverriden)
|
||||
{
|
||||
Name = NameFromChildren();
|
||||
NameOverriden = false;
|
||||
}
|
||||
}
|
||||
|
||||
this.CancelAllParentBuilding();
|
||||
|
|
@ -482,5 +477,10 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public string NameFromChildren()
|
||||
{
|
||||
return CalculateName(this.Children, ", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -419,23 +419,11 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
{
|
||||
using (selectedItem.Parent.RebuildLock())
|
||||
{
|
||||
var newName = "";
|
||||
foreach (var item in selectedItems)
|
||||
{
|
||||
if (newName == "")
|
||||
{
|
||||
newName = item.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
newName += $" & {item.Name}";
|
||||
}
|
||||
|
||||
newParent.Children.Add(item.Clone());
|
||||
}
|
||||
|
||||
newParent.Name = newName;
|
||||
|
||||
newParent.MakeNameNonColliding();
|
||||
|
||||
scene.UndoBuffer.AddAndDo(
|
||||
|
|
|
|||
|
|
@ -205,12 +205,23 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
{
|
||||
await Rebuild();
|
||||
}
|
||||
else if (invalidateArgs.InvalidateType.HasFlag(InvalidateType.Name)
|
||||
&& !NameOverriden)
|
||||
{
|
||||
Name = NameFromChildren();
|
||||
NameOverriden = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
base.OnInvalidate(invalidateArgs);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string NameFromChildren()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public override void Cancel(UndoBuffer undoBuffer)
|
||||
{
|
||||
using (RebuildLock())
|
||||
|
|
@ -286,6 +297,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
new List<IObject3D> { this }));
|
||||
|
||||
await this.Rebuild();
|
||||
|
||||
Name = NameFromChildren();
|
||||
NameOverriden = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
|
|||
using MatterHackers.Agg;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MatterHackers.MatterControl.Library
|
||||
{
|
||||
|
|
@ -97,29 +98,35 @@ namespace MatterHackers.MatterControl.Library
|
|||
string sourceFile = this.FilePath;
|
||||
if (File.Exists(sourceFile))
|
||||
{
|
||||
string extension = Path.GetExtension(sourceFile);
|
||||
string destFile = Path.Combine(Path.GetDirectoryName(sourceFile), value);
|
||||
destFile = Path.ChangeExtension(destFile, extension);
|
||||
var extension = Path.GetExtension(sourceFile);
|
||||
var fileNameNumberMatch = new Regex("\\s*\\(\\d+\\)" + extension, RegexOptions.Compiled);
|
||||
|
||||
var directory = Path.GetDirectoryName(sourceFile);
|
||||
var destName = value;
|
||||
var destPathAndName = Path.Combine(directory, Path.ChangeExtension(destName, extension));
|
||||
|
||||
var uniqueFileIncrement = 0;
|
||||
while(File.Exists(destFile))
|
||||
while(File.Exists(destPathAndName))
|
||||
{
|
||||
uniqueFileIncrement++;
|
||||
destFile = Path.Combine(Path.GetDirectoryName(sourceFile), value + $" ({uniqueFileIncrement})");
|
||||
destFile = Path.ChangeExtension(destFile, extension);
|
||||
// remove any number
|
||||
destName = fileNameNumberMatch.Replace(sourceFile, "");
|
||||
// add the new number
|
||||
destName += $" ({++uniqueFileIncrement})";
|
||||
destName = Path.ChangeExtension(destName, extension);
|
||||
destPathAndName = Path.Combine(directory, Path.ChangeExtension(destName, extension));
|
||||
|
||||
if (sourceFile == destFile)
|
||||
if (sourceFile == destPathAndName)
|
||||
{
|
||||
// we have gotten back to the name we currently have (don't change it)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceFile != destFile)
|
||||
if (sourceFile != destPathAndName)
|
||||
{
|
||||
File.Move(sourceFile, destFile);
|
||||
File.Move(sourceFile, destPathAndName);
|
||||
|
||||
this.FilePath = destFile;
|
||||
this.FilePath = destPathAndName;
|
||||
|
||||
NameChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ using MatterHackers.Agg.Image;
|
|||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
|
||||
namespace MatterHackers.MatterControl.Library
|
||||
{
|
||||
|
|
@ -79,9 +80,26 @@ namespace MatterHackers.MatterControl.Library
|
|||
}
|
||||
}
|
||||
|
||||
internal ILibraryItem NewPlatingItem(InteractiveScene scene)
|
||||
internal ILibraryItem NewBedPlate(BedConfig bedConfig)
|
||||
{
|
||||
var name = bedConfig.Printer.Settings.GetValue(SettingsKey.printer_name);
|
||||
string now = DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss");
|
||||
var filename = ApplicationController.Instance.SanitizeFileName($"{name} - {now}.mcx");
|
||||
string mcxPath = Path.Combine(this.FullPath, filename);
|
||||
|
||||
File.WriteAllText(mcxPath, new Object3D().ToJson());
|
||||
|
||||
return new FileSystemFileItem(mcxPath);
|
||||
}
|
||||
|
||||
internal ILibraryItem NewDesign()
|
||||
{
|
||||
string mcxPath = Path.Combine(this.FullPath, "New Design.mcx");
|
||||
var count = 0;
|
||||
while(File.Exists(mcxPath))
|
||||
{
|
||||
mcxPath = Path.Combine(this.FullPath, $"New Design ({++count}).mcx");
|
||||
}
|
||||
|
||||
File.WriteAllText(mcxPath, new Object3D().ToJson());
|
||||
|
||||
|
|
|
|||
|
|
@ -846,7 +846,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
new EditContext()
|
||||
{
|
||||
ContentStore = ApplicationController.Instance.Library.PlatingHistory,
|
||||
SourceItem = history.NewPlatingItem(workspace.SceneContext.Scene)
|
||||
SourceItem = history.NewDesign()
|
||||
});
|
||||
|
||||
ApplicationController.Instance.Workspaces.Add(workspace);
|
||||
|
|
|
|||
|
|
@ -94,6 +94,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
{
|
||||
}
|
||||
|
||||
if (!NameOverriden)
|
||||
{
|
||||
Name = NameFromChildren();
|
||||
NameOverriden = false;
|
||||
}
|
||||
|
||||
this.cancellationToken = null;
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
|
|
@ -110,6 +116,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
Combine(CancellationToken.None, null);
|
||||
}
|
||||
|
||||
public override string NameFromChildren()
|
||||
{
|
||||
return CalculateName(SourceContainer.Children, " + ");
|
||||
}
|
||||
|
||||
private void Combine(CancellationToken cancellationToken, IProgress<ProgressStatus> reporter)
|
||||
{
|
||||
SourceContainer.Visible = true;
|
||||
|
|
|
|||
|
|
@ -104,6 +104,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
{
|
||||
}
|
||||
|
||||
if (!NameOverriden)
|
||||
{
|
||||
Name = NameFromChildren();
|
||||
NameOverriden = false;
|
||||
}
|
||||
|
||||
this.cancellationToken = null;
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
|
|
@ -116,6 +122,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
});
|
||||
}
|
||||
|
||||
public override string NameFromChildren()
|
||||
{
|
||||
return CalculateName(SourceContainer.Children, " & ");
|
||||
}
|
||||
|
||||
public void Intersect()
|
||||
{
|
||||
Intersect(CancellationToken.None, null);
|
||||
|
|
|
|||
|
|
@ -102,13 +102,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
}
|
||||
}
|
||||
|
||||
public override void WrapSelectedItemAndSelect(InteractiveScene scene)
|
||||
public override async void WrapSelectedItemAndSelect(InteractiveScene scene)
|
||||
{
|
||||
base.WrapSelectedItemAndSelect(scene);
|
||||
|
||||
if (SelectedChildren.Count == 0)
|
||||
{
|
||||
SelectedChildren.Add(SourceContainer.DescendantsAndSelfMultipleChildrenFirstOrSelf().Children.Last().ID);
|
||||
await this.Rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -376,54 +377,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
change.SetRowVisible(nameof(InputResolution), () => Processing != ProcessingModes.Polygons && MeshAnalysis == IplicitSurfaceMethod.Grid);
|
||||
}
|
||||
|
||||
private string NameFromChildren()
|
||||
public override string NameFromChildren()
|
||||
{
|
||||
var (keepItems, removeItems) = GetSubtractItems();
|
||||
|
||||
var name = "";
|
||||
if (keepItems != null)
|
||||
{
|
||||
foreach (var item in keepItems)
|
||||
{
|
||||
if (name == "")
|
||||
{
|
||||
name = item.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
name += ", " + item.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (removeItems != null)
|
||||
{
|
||||
var firstRemove = true;
|
||||
foreach (var item in removeItems)
|
||||
{
|
||||
if (name == "")
|
||||
{
|
||||
name = item.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (firstRemove)
|
||||
{
|
||||
name += " - ";
|
||||
}
|
||||
else
|
||||
{
|
||||
name += ", ";
|
||||
}
|
||||
|
||||
name += item.Name;
|
||||
}
|
||||
|
||||
firstRemove = false;
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
return CalculateName(keepItems, ", ", " - ", removeItems, ", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -300,6 +300,8 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
var application = ApplicationController.Instance;
|
||||
|
||||
await ApplicationController.Instance.PersistUserWorkspaceTabs(true);
|
||||
|
||||
application.ApplicationExiting = true;
|
||||
|
||||
// Make sure we tell the Application Controller to shut down. This will release the slicing thread if running.
|
||||
|
|
|
|||
|
|
@ -955,6 +955,9 @@ Translated:Edit Selected Setting
|
|||
English:Email
|
||||
Translated:Email
|
||||
|
||||
English:Empty
|
||||
Translated:Empty
|
||||
|
||||
English:Empty Bed
|
||||
Translated:Empty Bed
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit e123dc76700b6e041069f5ad0e9f189dfeea3311
|
||||
Subproject commit 940c157f73bb807176c08e799bf0bb55ba08f2df
|
||||
Loading…
Add table
Add a link
Reference in a new issue