Merge pull request #2741 from larsbrubaker/design_tools

Unify to single GetNonCollidingName
This commit is contained in:
johnlewin 2017-12-06 16:56:16 -08:00 committed by GitHub
commit bdb1e2386d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 78 additions and 87 deletions

View file

@ -280,16 +280,21 @@ namespace MatterHackers.MatterControl
() => "Subtract".Localize(),
(scene) =>
{
var difference = new MeshWrapperOperation(scene.SelectedItem.Children)
var children = scene.SelectedItem.Children;
scene.SelectedItem = null;
var difference = new MeshWrapperOperation(new List<IObject3D> (children.Select((i) => i.Clone())))
{
ActiveEditor = nameof(SubtractEditor),
Name = "Subtract",
};
scene.SelectedItem.Children.Modify((list) =>
{
list.Clear();
});
scene.Children.Add(difference);
scene.UndoBuffer.AddAndDo(
new ReplaceCommand(
new List<IObject3D>(children),
new List<IObject3D> { difference }));
difference.MakeNameNonColliding();
scene.SelectedItem = difference;
}
},
@ -297,17 +302,21 @@ namespace MatterHackers.MatterControl
() => "Intersect".Localize(),
(scene) =>
{
var intersection = new MeshWrapperOperation(scene.SelectedItem.Children)
var selectedItems = scene.SelectedItem.Children;
scene.SelectedItem = null;
var intersection = new MeshWrapperOperation(new List<IObject3D> (selectedItems.Select((i) => i.Clone())))
{
ActiveEditor = nameof(IntersectionEditor),
Name = "Intersect",
};
scene.SelectedItem.Children.Modify((list) =>
{
list.Clear();
});
scene.Children.Add(intersection);
scene.UndoBuffer.AddAndDo(
new ReplaceCommand(
new List<IObject3D>(selectedItems),
new List<IObject3D> { intersection }));
intersection.MakeNameNonColliding();
scene.SelectedItem = intersection;
}
},
@ -316,16 +325,21 @@ namespace MatterHackers.MatterControl
() => "Paint Material".Localize(),
(scene) =>
{
var materialPaint = new MeshWrapperOperation(scene.SelectedItem.Children)
var selectedItems = scene.SelectedItem.Children;
scene.SelectedItem = null;
var materialPaint = new MeshWrapperOperation(new List<IObject3D> (selectedItems.Select((i) => i.Clone())))
{
ActiveEditor = nameof(PaintMaterialEditor),
Name = "Material Paint",
};
scene.SelectedItem.Children.Modify((list) =>
{
list.Clear();
});
scene.Children.Add(materialPaint);
scene.UndoBuffer.AddAndDo(
new ReplaceCommand(
new List<IObject3D>(selectedItems),
new List<IObject3D> { materialPaint }));
materialPaint.MakeNameNonColliding();
scene.SelectedItem = materialPaint;
}
},

View file

@ -34,6 +34,7 @@ using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
@ -49,8 +50,6 @@ namespace MatterHackers.MatterControl.Library
private bool isActiveContainer;
private bool isDirty;
private static Regex fileNameNumberMatch = new Regex("\\(\\d+\\)", RegexOptions.Compiled);
public FileSystemContainer(string path)
{
this.fullPath = path;
@ -205,29 +204,14 @@ namespace MatterHackers.MatterControl.Library
private string GetNonCollidingName(string fileName)
{
string incrementedFilePath;
string fileExtension = Path.GetExtension(fileName);
// Switching from .stl, .obj or similar to AMF. Save the file and update the
// the filename with an incremented (n) value to reflect the extension change in the UI
fileName = Path.GetFileNameWithoutExtension(fileName);
var similarFileNames = Directory.GetFiles(this.fullPath, $"{Path.GetFileNameWithoutExtension(fileName)}.*");
// Drop bracketed number sections from our source filename to ensure we don't generate something like "file (1) (1).amf"
if (fileName.Contains("("))
{
fileName = fileNameNumberMatch.Replace(fileName, "").Trim();
}
// ;
var validName = agg_basics.GetNonCollidingName(fileName, (testName) => !File.Exists(testName));
// Generate and search for an incremented file name until no match is found at the target directory
int foundCount = 1;
do
{
incrementedFilePath = Path.Combine(this.fullPath, $"{fileName} ({foundCount++}){fileExtension}");
// Continue incrementing while any matching file exists
} while (File.Exists(incrementedFilePath));
return incrementedFilePath;
return validName;
}
public async override void Add(IEnumerable<ILibraryItem> items)

View file

@ -121,6 +121,8 @@ namespace MatterHackers.MatterControl.PrintLibrary
this.Children.Add(loadedItem);
loadedItem.MakeNameNonColliding();
// Wait for content to load
// Adjust next item position

View file

@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.Collections.Generic;
using System.Linq;
using MatterHackers.DataConverters3D;
using MatterHackers.PolygonMesh;
@ -39,7 +40,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
}
public MeshWrapperOperation(SafeList<IObject3D> children)
public MeshWrapperOperation(List<IObject3D> children)
{
Children.Modify((list) =>
{

View file

@ -153,26 +153,23 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
{
foreach (var keep in keepObjects)
{
if (paint.MaterialIndex != keep.MaterialIndex)
{
var transformedPaint = Mesh.Copy(paint.Mesh, CancellationToken.None);
transformedPaint.Transform(paint.WorldMatrix());
var transformedPaint = Mesh.Copy(paint.Mesh, CancellationToken.None);
transformedPaint.Transform(paint.WorldMatrix());
var transformedKeep = Mesh.Copy(keep.Mesh, CancellationToken.None);
transformedKeep.Transform(keep.WorldMatrix());
var transformedKeep = Mesh.Copy(keep.Mesh, CancellationToken.None);
transformedKeep.Transform(keep.WorldMatrix());
// remove the paint from the original
var intersectAndSubtract = PolygonMesh.Csg.CsgOperations.IntersectAndSubtract(transformedKeep, transformedPaint);
var inverseKeep = keep.WorldMatrix();
inverseKeep.Invert();
intersectAndSubtract.subtract.Transform(inverseKeep);
keep.Mesh = intersectAndSubtract.subtract;
// remove the paint from the original
var intersectAndSubtract = PolygonMesh.Csg.CsgOperations.IntersectAndSubtract(transformedKeep, transformedPaint);
var inverseKeep = keep.WorldMatrix();
inverseKeep.Invert();
intersectAndSubtract.subtract.Transform(inverseKeep);
keep.Mesh = intersectAndSubtract.subtract;
var inverseRemove = paint.WorldMatrix();
inverseRemove.Invert();
intersectAndSubtract.intersect.Transform(inverseRemove);
paint.Mesh = intersectAndSubtract.intersect;
}
var inverseRemove = paint.WorldMatrix();
inverseRemove.Invert();
intersectAndSubtract.intersect.Transform(inverseRemove);
paint.Mesh = intersectAndSubtract.intersect;
}
// now set it to the new solid color

View file

@ -32,10 +32,12 @@ using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MeshVisualizer;
using MatterHackers.PolygonMesh;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow
@ -157,14 +159,24 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// Copy selected item
IObject3D newItem = await Task.Run(() =>
{
// new item can be null by the time this task kicks off
var clonedItem = Scene.SelectedItem?.Clone();
var originalItem = Scene.SelectedItem;
if (originalItem != null)
{
// new item can be null by the time this task kicks off
var clonedItem = originalItem.Clone();
// More usefull if it creates the part in the exact positon and then the user can move it.
// Consistent with othre software as well. LBB 2017-12-02
//PlatingHelper.MoveToOpenPositionRelativeGroup(clonedItem, Scene.Children);
// make the name unique
var newName = agg_basics.GetNonCollidingName(originalItem.Name, Scene.Descendants().Select((d) => d.Name));
clonedItem.Name = newName;
return clonedItem;
// More usefull if it creates the part in the exact positon and then the user can move it.
// Consistent with othre software as well. LBB 2017-12-02
//PlatingHelper.MoveToOpenPositionRelativeGroup(clonedItem, Scene.Children);
return clonedItem;
}
return null;
});
if (view3DWidget.HasBeenClosed)

View file

@ -316,6 +316,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
var button = new TextButton(namedAction.Title, theme)
{
Name = namedAction.Title + " Button",
VAnchor = VAnchor.Center,
Margin = theme.ButtonSpacing,
BackgroundColor = theme.MinimalShade

View file

@ -259,7 +259,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
string mappedMakeText = printerManufacturerSelector.SelectedLabel;
var existingPrinterNames = ProfileManager.Instance.ActiveProfiles.Select(p => p.Name);
printerNameInput.Text = agg_basics.GetNonCollidingName(existingPrinterNames, $"{mappedMakeText} {activeModel}");
printerNameInput.Text = agg_basics.GetNonCollidingName($"{mappedMakeText} {activeModel}", existingPrinterNames);
}
});
}

View file

@ -350,7 +350,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
var printerInfo = new PrinterInfo
{
Name = agg_basics.GetNonCollidingName(existingPrinterNames, fileName),
Name = agg_basics.GetNonCollidingName(fileName, existingPrinterNames),
ID = Guid.NewGuid().ToString(),
Make = "Other",
Model = "Other",

View file

@ -161,26 +161,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
};
}
private string GetNonCollidingName(string profileName, IEnumerable<string> existingNames)
{
if (!existingNames.Contains(profileName))
{
return profileName;
}
else
{
int currentIndex = 1;
string possiblePrinterName;
do
{
possiblePrinterName = String.Format("{0} ({1})", profileName, currentIndex++);
} while (existingNames.Contains(possiblePrinterName));
return possiblePrinterName;
}
}
private FlowLayoutWidget GetBottomRow(TextImageButtonFactory buttonFactory)
{
var container = new FlowLayoutWidget()
@ -195,7 +175,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
UiThread.RunOnIdle(() =>
{
string sanitizedName = numberMatch.Replace(presetNameInput.Text, "").Trim();
string newProfileName = GetNonCollidingName(sanitizedName, presetsContext.PresetLayers.Select(preset => preset.ValueOrDefault(SettingsKey.layer_name)));
string newProfileName = agg_basics.GetNonCollidingName(sanitizedName, presetsContext.PresetLayers.Select(preset => preset.ValueOrDefault(SettingsKey.layer_name)));
var clonedLayer = presetsContext.PersistenceLayer.Clone();
clonedLayer.Name = newProfileName;

@ -1 +1 @@
Subproject commit 207215ac28662e4e370a6f71c114a28904974686
Subproject commit 612f60db00c94d3338ec44389f5643ef09b7316f