diff --git a/DataStorage/Models.cs b/DataStorage/Models.cs index 615687bcc..5285edf4d 100644 --- a/DataStorage/Models.cs +++ b/DataStorage/Models.cs @@ -199,6 +199,8 @@ namespace MatterHackers.MatterControl.DataStorage public string Name { get; set; } + public string LibraryProviderBreadCrumbs { get; set; } + public string FileLocation { get; set; } public DateTime DateAdded { get; set; } @@ -210,10 +212,11 @@ namespace MatterHackers.MatterControl.DataStorage { } - public PrintItem(string name, string fileLocation) + public PrintItem(string name, string fileLocation, string libraryProviderBreadCrumbs = "") { this.Name = name; this.FileLocation = fileLocation; + this.LibraryProviderBreadCrumbs = libraryProviderBreadCrumbs; DateAdded = DateTime.Now; PrintCount = 0; diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index a8dbdd5b5..c3bc27459 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -36,6 +36,7 @@ using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrinterCommunication; using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.PrintLibrary.Provider; using MatterHackers.MatterControl.PrintQueue; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.MeshVisualizer; @@ -1871,6 +1872,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } saveSucceded = true; + //LibraryProvider.Instance.SaveToCollection(printItemWrapper.PrintItem.LibraryProviderBreadCrumbs LibrarySQLiteData.SaveToLibraryFolder(printItemWrapper, asynchMeshGroups, true); } catch (System.UnauthorizedAccessException) diff --git a/PrintLibrary/LibraryDataView.cs b/PrintLibrary/LibraryDataView.cs index 1c6056748..eaa7a036d 100644 --- a/PrintLibrary/LibraryDataView.cs +++ b/PrintLibrary/LibraryDataView.cs @@ -28,12 +28,12 @@ either expressed or implied, of the FreeBSD Project. */ using MatterHackers.Agg; -using MatterHackers.MatterControl.PrintLibrary.Provider; using MatterHackers.Agg.UI; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.PrintLibrary.Provider; using MatterHackers.MatterControl.PrintQueue; using MatterHackers.VectorMath; using System; -using MatterHackers.MatterControl.DataStorage; namespace MatterHackers.MatterControl.PrintLibrary { @@ -232,7 +232,6 @@ namespace MatterHackers.MatterControl.PrintLibrary AddAllItems(); } - public override void OnClosed(EventArgs e) { if (unregisterEvents != null) diff --git a/PrintLibrary/PrintLibraryWidget.cs b/PrintLibrary/PrintLibraryWidget.cs index 4ec9aba26..34caf3e2d 100644 --- a/PrintLibrary/PrintLibraryWidget.cs +++ b/PrintLibrary/PrintLibraryWidget.cs @@ -38,6 +38,7 @@ using MatterHackers.VectorMath; using System; using System.Collections.Generic; using System.IO; +using System.Text; namespace MatterHackers.MatterControl.PrintLibrary { @@ -46,6 +47,7 @@ namespace MatterHackers.MatterControl.PrintLibrary private TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory(); private TextImageButtonFactory editButtonFactory = new TextImageButtonFactory(); private TextWidget navigationLabel; + private TextWidget breadCrumbDisplay; private FlowLayoutWidget itemOperationButtons; private List editOperationMultiCapable = new List(); @@ -150,8 +152,12 @@ namespace MatterHackers.MatterControl.PrintLibrary CreateEditBarButtons(); + breadCrumbDisplay = new TextWidget(""); + breadCrumbDisplay.AutoExpandBoundsToText = true; + //allControls.AddChild(navigationPanel); allControls.AddChild(searchPanel); + allControls.AddChild(breadCrumbDisplay); allControls.AddChild(itemOperationButtons); libraryDataView = new LibraryDataView(); allControls.AddChild(libraryDataView); @@ -200,10 +206,47 @@ namespace MatterHackers.MatterControl.PrintLibrary editButtonFactory.FixedWidth = oldWidth; } + private event EventHandler unregisterEvents; private void AddHandlers() { libraryDataView.SelectedItems.OnAdd += onLibraryItemsSelected; libraryDataView.SelectedItems.OnRemove += onLibraryItemsSelected; + LibraryProvider.CollectionChanged.RegisterEvent(CollectionChanged, ref unregisterEvents); + } + + private void CollectionChanged(object sender, EventArgs e) + { + string breadCrumbs = LibraryProvider.Instance.GetBreadCrumbs(); + StringBuilder path = new StringBuilder(); + string[] splitOnBar = breadCrumbs.Split('|'); + if (splitOnBar.Length > 1) + { + bool first = true; + foreach (string split in splitOnBar) + { + if (!first) + { + path.Append("->"); + } + string[] splitOnComma = split.Split(','); + if (splitOnComma.Length > 1 + && splitOnComma[1] != "..") + { + path.Append(splitOnComma[1]); + first = false; + } + } + } + breadCrumbDisplay.Text = path.ToString(); + } + + public override void OnClosed(EventArgs e) + { + if (unregisterEvents != null) + { + unregisterEvents(this, null); + } + base.OnClosed(e); } private void searchInputKeyUp(object sender, KeyEventArgs keyEvent) diff --git a/PrintLibrary/Provider/LibraryProvider.cs b/PrintLibrary/Provider/LibraryProvider.cs index ed81107ac..fd244ea39 100644 --- a/PrintLibrary/Provider/LibraryProvider.cs +++ b/PrintLibrary/Provider/LibraryProvider.cs @@ -38,6 +38,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider { public abstract class LibraryProvider { + public static RootedObjectEventHandler CollectionChanged = new RootedObjectEventHandler(); public static RootedObjectEventHandler DataReloaded = new RootedObjectEventHandler(); public static RootedObjectEventHandler ItemAdded = new RootedObjectEventHandler(); public static RootedObjectEventHandler ItemRemoved = new RootedObjectEventHandler(); @@ -50,7 +51,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider { if (instance == null) { - //instance = new LibraryProviderSQLite(null); instance = new LibraryProviderSelector(); } @@ -60,22 +60,25 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider #region Abstract Methods - public abstract bool HasParent { get; } - - public abstract string ProviderTypeKey { get; } - - public abstract string Name { get; } - public abstract int CollectionCount { get; } + public abstract bool HasParent { get; } + public abstract int ItemCount { get; } public abstract string KeywordFilter { get; set; } + public abstract string Name { get; } + + public abstract string ProviderKey { get; } + public abstract void AddCollectionToLibrary(string collectionName); public abstract void AddFilesToLibrary(IList files, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null); + // A key,value list that threads into the current collection looks like "key0,displayName0|key1,displayName1|key2,displayName2|...|keyN,displayNameN". + public abstract string GetBreadCrumbs(); + public abstract PrintItemCollection GetCollectionItem(int collectionIndex); public abstract PrintItemCollection GetParentCollectionItem(); @@ -107,11 +110,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider ItemRemoved.CallEvents(Instance, eventArgs); } - public static void SetCurrent(LibraryProvider current) - { - LibraryProvider.instance = current; - } - #endregion Static Methods } } \ No newline at end of file diff --git a/PrintLibrary/Provider/LibraryProviderFileSystem.cs b/PrintLibrary/Provider/LibraryProviderFileSystem.cs index e432462da..5cdb9ee26 100644 --- a/PrintLibrary/Provider/LibraryProviderFileSystem.cs +++ b/PrintLibrary/Provider/LibraryProviderFileSystem.cs @@ -49,8 +49,9 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider private string parentKey = null; private string rootPath; - public LibraryProviderFileSystem(string rootPath, string description) + public LibraryProviderFileSystem(string rootPath, string description, string parentKeyKey) { + this.parentKey = parentKeyKey; this.description = description; this.rootPath = rootPath; @@ -59,17 +60,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider GetFilesInCurrentDirectory(); } - public LibraryProviderFileSystem(PrintItemCollection collectionBase, string description, string parentKey) - { - this.parentKey = parentKey; - this.description = description; - this.rootPath = collectionBase.Key; - key = keyCount.ToString(); - keyCount++; - - GetFilesInCurrentDirectory(); - } - public override int CollectionCount { get @@ -99,14 +89,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public override string ProviderTypeKey - { - get - { - return "LibraryProvider_" + key.ToString() + "_Key"; - } - } - public override string KeywordFilter { get @@ -127,6 +109,14 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public override string Name { get { return description; } } + public override string ProviderKey + { + get + { + return "FileSystem_" + key.ToString() + "_Key"; + } + } + public override void AddCollectionToLibrary(string collectionName) { throw new NotImplementedException(); @@ -137,6 +127,35 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider throw new NotImplementedException(); } + public override string GetBreadCrumbs() + { + throw new NotImplementedException(); + + // append all of the collection keys with names + string addDirectory = currentDirectory; + List collectionKeys = new List(); + while (addDirectory != ".") + { + collectionKeys.Add(addDirectory); + addDirectory = Path.GetDirectoryName(addDirectory); + } + + string total = ""; + bool first = true; + for(int i = collectionKeys.Count-1; i>=0; i--) + { + string key = collectionKeys[i]; + if (!first) + { + total += "|"; + } + total += key + "," + Path.GetFileName(key); + first = false; + } + + return total; + } + public override PrintItemCollection GetCollectionItem(int collectionIndex) { string directoryName = currentDirectoryDirectories[collectionIndex]; @@ -166,7 +185,8 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public override PrintItemWrapper GetPrintItemWrapper(int itemIndex) { string fileName = currentDirectoryFiles[itemIndex]; - return new PrintItemWrapper(new DataStorage.PrintItem(Path.GetFileNameWithoutExtension(fileName), fileName)); + string breadCrumbs = LibraryProvider.Instance.GetBreadCrumbs(); + return new PrintItemWrapper(new DataStorage.PrintItem(Path.GetFileNameWithoutExtension(fileName), fileName, breadCrumbs)); } public override void RemoveCollection(string collectionName) @@ -200,7 +220,8 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider if (keywordFilter.Trim() == string.Empty || Path.GetFileNameWithoutExtension(directoryName).Contains(keywordFilter)) { - currentDirectoryDirectories.Add(directoryName); + string subPath = directoryName.Substring(rootPath.Length + 1); + currentDirectoryDirectories.Add(subPath); } } diff --git a/PrintLibrary/Provider/LibraryProviderSelector.cs b/PrintLibrary/Provider/LibraryProviderSelector.cs index 928ed8b62..a31a472f9 100644 --- a/PrintLibrary/Provider/LibraryProviderSelector.cs +++ b/PrintLibrary/Provider/LibraryProviderSelector.cs @@ -34,37 +34,41 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; +using System.Text; namespace MatterHackers.MatterControl.PrintLibrary.Provider { public class LibraryProviderSelector : LibraryProvider { private List libraryProviders = new List(); - int selectedLibraryProvider = -1; + private int selectedLibraryProvider = -1; public LibraryProviderSelector() { // put in the sqlite provider - LibraryProviderSQLite localStore = new LibraryProviderSQLite(this.ProviderTypeKey); + LibraryProviderSQLite localStore = new LibraryProviderSQLite(this.ProviderKey); libraryProviders.Add(localStore); // and any directory providers (sd card provider, etc...) - PrintItemCollection downloadsCollection = new PrintItemCollection("Downloads", Path.Combine("C:\\", "Users", "LarsBrubaker", "Downloads")); - //libraryProviders.Add(new LibraryProviderFileSystem(downloadsCollection, "Downloads", this.ProviderTypeKey)); + libraryProviders.Add(new LibraryProviderFileSystem(Path.Combine("C:\\", "Users", "LarsBrubaker", "Downloads"), "Downloads", this.ProviderKey)); PrintItemCollection libraryCollection = new PrintItemCollection("Library Folder1", Path.Combine("C:\\", "Users", "LarsBrubaker", "AppData", "Local", "MatterControl", "Library")); - //libraryProviders.Add(new LibraryProviderFileSystem(libraryCollection, "Library Folder2", this.ProviderTypeKey)); + //libraryProviders.Add(new LibraryProviderFileSystem(libraryCollection, "Library Folder2", this.ProviderKey)); // Check for LibraryProvider factories and put them in the list too. PluginFinder libraryFactories = new PluginFinder(); foreach (LibraryProviderFactory factory in libraryFactories.Plugins) { - libraryProviders.Add(factory.CreateProvider(this.ProviderTypeKey)); + libraryProviders.Add(factory.CreateProvider(this.ProviderKey)); } + + breadCrumbStack.Add(new PrintItemCollection("..", ProviderKey)); } #region Overriden Abstract Methods + private List breadCrumbStack = new List(); + public override int CollectionCount { get @@ -80,6 +84,21 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } + public override bool HasParent + { + get + { + if (selectedLibraryProvider == -1) + { + return false; + } + else + { + return libraryProviders[selectedLibraryProvider].HasParent; + } + } + } + public override int ItemCount { get @@ -121,6 +140,22 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } + public override string Name + { + get + { + return "Never visible"; + } + } + + public override string ProviderKey + { + get + { + return "ProviderSelectorKey"; + } + } + public override void AddCollectionToLibrary(string collectionName) { if (selectedLibraryProvider == -1) @@ -145,12 +180,42 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } + // A key,value list that threads into the current collection loos like "key0,displayName0|key1,displayName1|key2,displayName2|...|keyN,displayNameN". + public override string GetBreadCrumbs() + { + if (selectedLibraryProvider == -1) + { + return ""; + } + else + { + StringBuilder breadCrumbString = new StringBuilder(); + bool first = true; + + for(int i=0; i 2 + && collectionBase.Key == breadCrumbStack[breadCrumbStack.Count - 2].Key) + || (breadCrumbStack.Count > 1 + && selectedLibraryProvider != -1 + && collectionBase.Key == libraryProviders[selectedLibraryProvider].GetParentCollectionItem().Key) + ) { - selectedLibraryProvider = -1; - return; + breadCrumbStack.RemoveAt(breadCrumbStack.Count-1); + } + else + { + breadCrumbStack.Add(collectionBase); } - bool wasSet = false; - for (int i = 0; i < libraryProviders.Count; i++) + if (collectionBase.Key == this.ProviderKey) { - if (libraryProviders[i].ProviderTypeKey == collectionBase.Key) + selectedLibraryProvider = -1; + } + else + { + bool wasSet = false; + for (int i = 0; i < libraryProviders.Count; i++) { - selectedLibraryProvider = i; - wasSet = true; - break; + if (libraryProviders[i].ProviderKey == collectionBase.Key) + { + selectedLibraryProvider = i; + wasSet = true; + break; + } + } + + if (!wasSet) + { + libraryProviders[selectedLibraryProvider].SetCollectionBase(collectionBase); } } - if (!wasSet) - { - libraryProviders[selectedLibraryProvider].SetCollectionBase(collectionBase); - } + CollectionChanged.CallEvents(this, null); } #endregion Overriden Abstract Methods diff --git a/PrintLibrary/Provider/LibraryProviderSqlite.cs b/PrintLibrary/Provider/LibraryProviderSqlite.cs index 21a7545f9..dccb68692 100644 --- a/PrintLibrary/Provider/LibraryProviderSqlite.cs +++ b/PrintLibrary/Provider/LibraryProviderSqlite.cs @@ -74,14 +74,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public override string ProviderTypeKey - { - get - { - return "LibraryProviderSqliteKey"; - } - } - public override string KeywordFilter { get @@ -103,6 +95,14 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } + public override string ProviderKey + { + get + { + return "LibraryProviderSqliteKey"; + } + } + public override void AddCollectionToLibrary(string collectionName) { throw new NotImplementedException(); @@ -113,6 +113,11 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider LibrarySQLiteData.Instance.LoadFilesIntoLibrary(files, reportProgress, callback); } + public override string GetBreadCrumbs() + { + throw new NotImplementedException(); + } + public override PrintItemCollection GetCollectionItem(int collectionIndex) { throw new NotImplementedException(); diff --git a/SlicerConfiguration/SlicerMapping/MappingClasses.cs b/SlicerConfiguration/SlicerMapping/MappingClasses.cs index 1a0ef10fa..e05a77926 100644 --- a/SlicerConfiguration/SlicerMapping/MappingClasses.cs +++ b/SlicerConfiguration/SlicerMapping/MappingClasses.cs @@ -192,16 +192,16 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } // Start heating all the extruder that we are going to use. - for (int extruderIndex = 0; extruderIndex < numberOfHeatedExtruders; extruderIndex++) + for (int extruderIndex0Based = 0; extruderIndex0Based < numberOfHeatedExtruders; extruderIndex0Based++) { - if (extrudersUsed.Count > extruderIndex - && extrudersUsed[extruderIndex]) + if (extrudersUsed.Count > extruderIndex0Based + && extrudersUsed[extruderIndex0Based]) { - string materialTemperature = ActiveSliceSettings.Instance.GetMaterialValue("temperature", extruderIndex); + string materialTemperature = ActiveSliceSettings.Instance.GetMaterialValue("temperature", extruderIndex0Based + 1); if (materialTemperature != "0") { - string setTempString = "M104 T{0} S{1}".FormatWith(extruderIndex, materialTemperature); - AddDefaultIfNotPresent(preStartGCode, setTempString, preStartGCodeLines, string.Format("start heating extruder {0}", extruderIndex)); + string setTempString = "M104 T{0} S{1}".FormatWith(extruderIndex0Based, materialTemperature); + AddDefaultIfNotPresent(preStartGCode, setTempString, preStartGCodeLines, string.Format("start heating extruder {0}", extruderIndex0Based + 1)); } } } @@ -209,16 +209,16 @@ namespace MatterHackers.MatterControl.SlicerConfiguration // If we need to wait for the heaters to heat up before homing then set them to M109 (heat and wait). if (ActiveSliceSettings.Instance.GetActiveValue("heat_extruder_before_homing") == "1") { - for (int extruderIndex = 0; extruderIndex < numberOfHeatedExtruders; extruderIndex++) + for (int extruderIndex0Based = 0; extruderIndex0Based < numberOfHeatedExtruders; extruderIndex0Based++) { - if (extrudersUsed.Count > extruderIndex - && extrudersUsed[extruderIndex]) + if (extrudersUsed.Count > extruderIndex0Based + && extrudersUsed[extruderIndex0Based]) { - string materialTemperature = ActiveSliceSettings.Instance.GetMaterialValue("temperature", extruderIndex); + string materialTemperature = ActiveSliceSettings.Instance.GetMaterialValue("temperature", extruderIndex0Based + 1); if (materialTemperature != "0") { - string setTempString = "M109 T{0} S{1}".FormatWith(extruderIndex, materialTemperature); - AddDefaultIfNotPresent(preStartGCode, setTempString, preStartGCodeLines, string.Format("wait for extruder {0}", extruderIndex)); + string setTempString = "M109 T{0} S{1}".FormatWith(extruderIndex0Based, materialTemperature); + AddDefaultIfNotPresent(preStartGCode, setTempString, preStartGCodeLines, string.Format("wait for extruder {0}", extruderIndex0Based)); } } } @@ -261,16 +261,16 @@ namespace MatterHackers.MatterControl.SlicerConfiguration // don't set the extrudes to heating if we alread waited for them to reach temp if (ActiveSliceSettings.Instance.GetActiveValue("heat_extruder_before_homing") != "1") { - for (int extruderIndex = 0; extruderIndex < numberOfHeatedExtruders; extruderIndex++) + for (int extruderIndex0Based = 0; extruderIndex0Based < numberOfHeatedExtruders; extruderIndex0Based++) { - if (extrudersUsed.Count > extruderIndex - && extrudersUsed[extruderIndex]) + if (extrudersUsed.Count > extruderIndex0Based + && extrudersUsed[extruderIndex0Based]) { - string materialTemperature = ActiveSliceSettings.Instance.GetMaterialValue("temperature", extruderIndex + 1); + string materialTemperature = ActiveSliceSettings.Instance.GetMaterialValue("temperature", extruderIndex0Based + 1); if (materialTemperature != "0") { - string setTempString = "M109 T{0} S{1}".FormatWith(extruderIndex, materialTemperature); - AddDefaultIfNotPresent(postStartGCode, setTempString, postStartGCodeLines, string.Format("wait for extruder {0} to reach temperature", extruderIndex)); + string setTempString = "M109 T{0} S{1}".FormatWith(extruderIndex0Based, materialTemperature); + AddDefaultIfNotPresent(postStartGCode, setTempString, postStartGCodeLines, string.Format("wait for extruder {0} to reach temperature", extruderIndex0Based)); } } }