From 185fdfc5b63d8c1798117fa36723d83fb22f042a Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Mon, 22 Jun 2015 18:21:56 -0700 Subject: [PATCH] Working on a Provider SaveToLibrary function. Some refactoring --- PartPreviewWindow/View3D/View3DWidget.cs | 2 +- PrintLibrary/LibraryRowItemPart.cs | 377 +++++++++--------- PrintLibrary/Provider/LibraryProvider.cs | 33 +- .../Provider/LibraryProviderFileSystem.cs | 68 ++-- .../Provider/LibraryProviderSelector.cs | 140 ++++--- .../Provider/LibraryProviderSqlite.cs | 40 +- PrintLibrary/Provider/LibrarySQLiteData.cs | 4 +- Submodules/MatterSlice | 2 +- 8 files changed, 359 insertions(+), 307 deletions(-) diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index ef57b8122..d83c385f2 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -1873,7 +1873,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow saveSucceded = true; //LibraryProvider.Instance.SaveToCollection(printItemWrapper.PrintItem.LibraryProviderLocator - LibrarySQLiteData.SaveToLibraryFolder(printItemWrapper, asynchMeshGroups, true); + LibraryProvider.Instance.SaveToLibrary(printItemWrapper, asynchMeshGroups); } catch (System.UnauthorizedAccessException) { diff --git a/PrintLibrary/LibraryRowItemPart.cs b/PrintLibrary/LibraryRowItemPart.cs index 83eb9aa7f..36379cba7 100644 --- a/PrintLibrary/LibraryRowItemPart.cs +++ b/PrintLibrary/LibraryRowItemPart.cs @@ -34,21 +34,19 @@ using MatterHackers.Localizations; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.PrintLibrary.Provider; using MatterHackers.MatterControl.PrintQueue; -using MatterHackers.VectorMath; +using MatterHackers.PolygonMesh; using System; -using System.Globalization; +using System.Collections.Generic; using System.IO; namespace MatterHackers.MatterControl.PrintLibrary { public class LibraryRowItemPart : LibraryRowItem { + public bool isActivePrint = false; public PrintItemWrapper printItemWrapper; private ExportPrintItemWindow exportingWindow; - - public bool isActivePrint = false; - private PartPreviewMainWindow viewingWindow; public LibraryRowItemPart(PrintItemWrapper printItem, LibraryDataView libraryDataView) @@ -58,6 +56,95 @@ namespace MatterHackers.MatterControl.PrintLibrary CreateGuiElements(); } + public override void AddToQueue() + { + QueueData.Instance.AddItem(printItemWrapper); + } + + public override void Edit() + { + OpenPartViewWindow(PartPreviewWindow.View3DWidget.OpenMode.Editing); + } + + public override void Export() + { + OpenExportWindow(printItemWrapper); + } + + public override void OnDraw(Graphics2D graphics2D) + { + if (this.libraryDataView.EditMode) + { + selectionCheckBoxContainer.Visible = true; + rightButtonOverlay.Visible = false; + } + else + { + selectionCheckBoxContainer.Visible = false; + } + + base.OnDraw(graphics2D); + + if (this.isSelectedItem) + { + this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; + this.partLabel.TextColor = RGBA_Bytes.White; + this.selectionCheckBox.TextColor = RGBA_Bytes.White; + } + else if (this.IsHoverItem) + { + RectangleDouble Bounds = LocalBounds; + RoundedRect rectBorder = new RoundedRect(Bounds, 0); + + this.BackgroundColor = RGBA_Bytes.White; + this.partLabel.TextColor = RGBA_Bytes.Black; + this.selectionCheckBox.TextColor = RGBA_Bytes.Black; + + graphics2D.Render(new Stroke(rectBorder, 3), ActiveTheme.Instance.SecondaryAccentColor); + } + else + { + this.BackgroundColor = new RGBA_Bytes(255, 255, 255, 255); + this.partLabel.TextColor = RGBA_Bytes.Black; + this.selectionCheckBox.TextColor = RGBA_Bytes.Black; + } + } + + public override void OnMouseDown(MouseEventArgs mouseEvent) + { + if (mouseEvent.Clicks == 2) + { + UiThread.RunOnIdle(() => + { + openPartView(View3DWidget.OpenMode.Viewing); + }); + } + base.OnMouseDown(mouseEvent); + } + + public void OpenPartViewWindow(View3DWidget.OpenMode openMode = View3DWidget.OpenMode.Viewing) + { + if (viewingWindow == null) + { + viewingWindow = new PartPreviewMainWindow(this.printItemWrapper, View3DWidget.AutoRotate.Enabled, openMode); + viewingWindow.Closed += new EventHandler(PartPreviewMainWindow_Closed); + } + else + { + viewingWindow.BringToFront(); + } + } + + public override void RemoveFromCollection() + { + LibraryProvider.Instance.RemoveItem(printItemWrapper); + } + + public override void RemoveFromParentCollection() + { + LibraryProvider.Instance.RemoveItem(printItemWrapper); + } + protected override SlideWidget GetItemActionButtons() { SlideWidget buttonContainer = new SlideWidget(); @@ -111,11 +198,90 @@ namespace MatterHackers.MatterControl.PrintLibrary return buttonContainer; } + protected override string GetItemName() + { + return printItemWrapper.Name; + } + + protected override GuiWidget GetThumbnailWidget() + { + PartThumbnailWidget thumbnailWidget = new PartThumbnailWidget(printItemWrapper, "part_icon_transparent_40x40.png", "building_thumbnail_40x40.png", PartThumbnailWidget.ImageSizes.Size50x50); + return thumbnailWidget; + } + + protected override void RemoveThisFromPrintLibrary() + { + LibraryProvider.Instance.RemoveItem(this.printItemWrapper); + } + private void ExportQueueItemWindow_Closed(object sender, EventArgs e) { exportingWindow = null; } + private void onAddLinkClick(object sender, EventArgs e) + { + } + + private void onConfirmRemove(bool messageBoxResponse) + { + if (messageBoxResponse) + { + libraryDataView.RemoveChild(this); + } + } + + private void onLibraryItemClick(object sender, EventArgs e) + { + if (this.libraryDataView.EditMode == false) + { + //UiThread.RunOnIdle((state) => + //{ + // openPartView(state); + //}); + } + else + { + if (this.isSelectedItem == false) + { + this.isSelectedItem = true; + this.selectionCheckBox.Checked = true; + libraryDataView.SelectedItems.Add(this); + } + else + { + this.isSelectedItem = false; + this.selectionCheckBox.Checked = false; + libraryDataView.SelectedItems.Remove(this); + } + } + } + + private void onOpenPartViewClick(object sender, EventArgs e) + { + UiThread.RunOnIdle(() => openPartView()); + } + + private void onRemoveLinkClick(object sender, EventArgs e) + { + UiThread.RunOnIdle(RemoveThisFromPrintLibrary); + } + + private void onThemeChanged(object sender, EventArgs e) + { + //Set background and text color to new theme + this.Invalidate(); + } + + private void onViewPartClick(object sender, EventArgs e) + { + UiThread.RunOnIdle(() => + { + this.rightButtonOverlay.SlideOut(); + openPartView(View3DWidget.OpenMode.Viewing); + }); + } + private void OpenExportWindow() { if (exportingWindow == null) @@ -144,72 +310,23 @@ namespace MatterHackers.MatterControl.PrintLibrary } } - private void SetDisplayAttributes() + private void openPartView(View3DWidget.OpenMode openMode = View3DWidget.OpenMode.Viewing) { - //this.VAnchor = Agg.UI.VAnchor.FitToChildren; - this.HAnchor = Agg.UI.HAnchor.ParentLeftRight; - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + string pathAndFile = this.printItemWrapper.FileLocation; + if (File.Exists(pathAndFile)) { - this.Height = 65; + OpenPartViewWindow(openMode); } else { - this.Height = 50; + string message = String.Format("Cannot find\n'{0}'.\nWould you like to remove it from the library?", pathAndFile); + StyledMessageBox.ShowMessageBox(null, message, "Item not found", StyledMessageBox.MessageType.YES_NO); } - - this.Padding = new BorderDouble(0); - this.Margin = new BorderDouble(6, 0, 6, 6); } - public override void RemoveFromParentCollection() + private void PartPreviewMainWindow_Closed(object sender, EventArgs e) { - LibraryProvider.Instance.RemoveItem(printItemWrapper); - } - - public override void Export() - { - OpenExportWindow(printItemWrapper); - } - - public override void Edit() - { - OpenPartViewWindow(PartPreviewWindow.View3DWidget.OpenMode.Editing); - } - - public override void RemoveFromCollection() - { - LibraryProvider.Instance.RemoveItem(printItemWrapper); - } - - public override void AddToQueue() - { - QueueData.Instance.AddItem(printItemWrapper); - } - - private void onLibraryItemClick(object sender, EventArgs e) - { - if (this.libraryDataView.EditMode == false) - { - //UiThread.RunOnIdle((state) => - //{ - // openPartView(state); - //}); - } - else - { - if (this.isSelectedItem == false) - { - this.isSelectedItem = true; - this.selectionCheckBox.Checked = true; - libraryDataView.SelectedItems.Add(this); - } - else - { - this.isSelectedItem = false; - this.selectionCheckBox.Checked = false; - libraryDataView.SelectedItems.Remove(this); - } - } + viewingWindow = null; } private void selectionCheckBox_CheckedStateChanged(object sender, EventArgs e) @@ -226,141 +343,21 @@ namespace MatterHackers.MatterControl.PrintLibrary } } - private void onAddLinkClick(object sender, EventArgs e) + private void SetDisplayAttributes() { - } - - protected override GuiWidget GetThumbnailWidget() - { - PartThumbnailWidget thumbnailWidget = new PartThumbnailWidget(printItemWrapper, "part_icon_transparent_40x40.png", "building_thumbnail_40x40.png", PartThumbnailWidget.ImageSizes.Size50x50); - return thumbnailWidget; - } - - protected override string GetItemName() - { - return printItemWrapper.Name; - } - - protected override void RemoveThisFromPrintLibrary() - { - LibraryProvider.Instance.RemoveItem(this.printItemWrapper); - } - - private void onRemoveLinkClick(object sender, EventArgs e) - { - UiThread.RunOnIdle(RemoveThisFromPrintLibrary); - } - - private void onOpenPartViewClick(object sender, EventArgs e) - { - UiThread.RunOnIdle(() => openPartView()); - } - - public override void OnMouseDown(MouseEventArgs mouseEvent) - { - if (mouseEvent.Clicks == 2) + //this.VAnchor = Agg.UI.VAnchor.FitToChildren; + this.HAnchor = Agg.UI.HAnchor.ParentLeftRight; + if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) { - UiThread.RunOnIdle(() => - { - openPartView(View3DWidget.OpenMode.Viewing); - }); - } - base.OnMouseDown(mouseEvent); - } - - - private void onViewPartClick(object sender, EventArgs e) - { - UiThread.RunOnIdle(() => - { - this.rightButtonOverlay.SlideOut(); - openPartView(View3DWidget.OpenMode.Viewing); - }); - } - - public void OpenPartViewWindow(View3DWidget.OpenMode openMode = View3DWidget.OpenMode.Viewing) - { - if (viewingWindow == null) - { - viewingWindow = new PartPreviewMainWindow(this.printItemWrapper, View3DWidget.AutoRotate.Enabled, openMode); - viewingWindow.Closed += new EventHandler(PartPreviewMainWindow_Closed); + this.Height = 65; } else { - viewingWindow.BringToFront(); - } - } - - private void PartPreviewMainWindow_Closed(object sender, EventArgs e) - { - viewingWindow = null; - } - - private void openPartView(View3DWidget.OpenMode openMode = View3DWidget.OpenMode.Viewing) - { - string pathAndFile = this.printItemWrapper.FileLocation; - if (File.Exists(pathAndFile)) - { - OpenPartViewWindow(openMode); - } - else - { - string message = String.Format("Cannot find\n'{0}'.\nWould you like to remove it from the library?", pathAndFile); - StyledMessageBox.ShowMessageBox(null, message, "Item not found", StyledMessageBox.MessageType.YES_NO); - } - } - - private void onConfirmRemove(bool messageBoxResponse) - { - if (messageBoxResponse) - { - libraryDataView.RemoveChild(this); - } - } - - private void onThemeChanged(object sender, EventArgs e) - { - //Set background and text color to new theme - this.Invalidate(); - } - - public override void OnDraw(Graphics2D graphics2D) - { - if (this.libraryDataView.EditMode) - { - selectionCheckBoxContainer.Visible = true; - rightButtonOverlay.Visible = false; - } - else - { - selectionCheckBoxContainer.Visible = false; + this.Height = 50; } - base.OnDraw(graphics2D); - - if (this.isSelectedItem) - { - this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; - this.partLabel.TextColor = RGBA_Bytes.White; - this.selectionCheckBox.TextColor = RGBA_Bytes.White; - } - else if (this.IsHoverItem) - { - RectangleDouble Bounds = LocalBounds; - RoundedRect rectBorder = new RoundedRect(Bounds, 0); - - this.BackgroundColor = RGBA_Bytes.White; - this.partLabel.TextColor = RGBA_Bytes.Black; - this.selectionCheckBox.TextColor = RGBA_Bytes.Black; - - graphics2D.Render(new Stroke(rectBorder, 3), ActiveTheme.Instance.SecondaryAccentColor); - } - else - { - this.BackgroundColor = new RGBA_Bytes(255, 255, 255, 255); - this.partLabel.TextColor = RGBA_Bytes.Black; - this.selectionCheckBox.TextColor = RGBA_Bytes.Black; - } + this.Padding = new BorderDouble(0); + this.Margin = new BorderDouble(6, 0, 6, 6); } } } \ No newline at end of file diff --git a/PrintLibrary/Provider/LibraryProvider.cs b/PrintLibrary/Provider/LibraryProvider.cs index 9b6cd8c25..e4d095dd0 100644 --- a/PrintLibrary/Provider/LibraryProvider.cs +++ b/PrintLibrary/Provider/LibraryProvider.cs @@ -30,24 +30,13 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.PolygonMesh; using System; using System.Collections.Generic; using System.ComponentModel; namespace MatterHackers.MatterControl.PrintLibrary.Provider { - public class ProviderLocatorNode - { - public string Key; - public string Name; - - public ProviderLocatorNode(string key, string name) - { - this.Key = key; - this.Name = name; - } - } - public abstract class LibraryProvider { public static RootedObjectEventHandler CollectionChanged = new RootedObjectEventHandler(); @@ -88,19 +77,21 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public abstract void AddFilesToLibrary(IList files, List providerSavePath, 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 List GetProviderLocator(); - public abstract PrintItemCollection GetCollectionItem(int collectionIndex); public abstract PrintItemCollection GetParentCollectionItem(); public abstract PrintItemWrapper GetPrintItemWrapper(int itemIndex); + // A key,value list that threads into the current collection looks like "key0,displayName0|key1,displayName1|key2,displayName2|...|keyN,displayNameN". + public abstract List GetProviderLocator(); + public abstract void RemoveCollection(string collectionName); public abstract void RemoveItem(PrintItemWrapper printItemWrapper); + public abstract void SaveToLibrary(PrintItemWrapper printItemWrapper, List meshGroupsToSave, List providerSavePath = null); + public abstract void SetCollectionBase(PrintItemCollection collectionBase); #endregion Abstract Methods @@ -124,4 +115,16 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider #endregion Static Methods } + + public class ProviderLocatorNode + { + public string Key; + public string Name; + + public ProviderLocatorNode(string key, string name) + { + this.Key = key; + this.Name = name; + } + } } \ No newline at end of file diff --git a/PrintLibrary/Provider/LibraryProviderFileSystem.cs b/PrintLibrary/Provider/LibraryProviderFileSystem.cs index 48ba126ee..e3e19323f 100644 --- a/PrintLibrary/Provider/LibraryProviderFileSystem.cs +++ b/PrintLibrary/Provider/LibraryProviderFileSystem.cs @@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.PolygonMesh; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -142,30 +143,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider LibraryProvider.OnDataReloaded(null); } - private static void CopyAllFiles(IList files, string destPath) - { - // make sure the directory exists - Directory.CreateDirectory(destPath); - - // save it to the root directory - foreach (string file in files) - { - string outputFileName = Path.Combine(destPath, Path.GetFileName(file)); - // and copy the file - File.Copy(file, outputFileName); - } - } - - private string GetPathFromLocator(List providerLocator) - { - throw new NotImplementedException(); - } - - public override List GetProviderLocator() - { - throw new NotImplementedException(); - } - public override PrintItemCollection GetCollectionItem(int collectionIndex) { string directoryName = currentDirectoryDirectories[collectionIndex]; @@ -200,6 +177,11 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider return new PrintItemWrapper(new DataStorage.PrintItem(Path.GetFileNameWithoutExtension(fileName), fileName, providerLocatorJson)); } + public override List GetProviderLocator() + { + throw new NotImplementedException(); + } + public override void RemoveCollection(string collectionName) { throw new NotImplementedException(); @@ -212,6 +194,11 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider LibraryProvider.OnDataReloaded(null); } + public override void SaveToLibrary(PrintItemWrapper printItemWrapper, List meshGroupsToSave, List providerSavePath) + { + throw new NotImplementedException(); + } + public override void SetCollectionBase(PrintItemCollection collectionBase) { string collectionPath = collectionBase.Key; @@ -224,6 +211,32 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider GetFilesInCurrentDirectory(); } + private static void CopyAllFiles(IList files, string destPath) + { + // make sure the directory exists + try + { + Directory.CreateDirectory(destPath); + } + catch (Exception e) + { + } + + // save it to the root directory + foreach (string file in files) + { + string outputFileName = Path.Combine(destPath, Path.GetFileName(file)); + // and copy the file + try + { + File.Copy(file, outputFileName); + } + catch (Exception e) + { + } + } + } + private void GetFilesInCurrentDirectory() { currentDirectoryDirectories.Clear(); @@ -252,5 +265,12 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } } + + private string GetPathFromLocator(List providerLocator) + { + string pathWithDot = Path.Combine(rootPath, providerLocator[providerLocator.Count - 1].Key); + string pathWithoutDot = pathWithDot.Replace("." + Path.DirectorySeparatorChar, ""); + return pathWithoutDot; + } } } \ No newline at end of file diff --git a/PrintLibrary/Provider/LibraryProviderSelector.cs b/PrintLibrary/Provider/LibraryProviderSelector.cs index ebd947dc7..d7825018f 100644 --- a/PrintLibrary/Provider/LibraryProviderSelector.cs +++ b/PrintLibrary/Provider/LibraryProviderSelector.cs @@ -30,12 +30,12 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrintQueue; -using System; +using MatterHackers.PolygonMesh; using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; -using System.Text; namespace MatterHackers.MatterControl.PrintLibrary.Provider { @@ -179,57 +179,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider libraryProviders[libraryProviderToUseIndex].AddFilesToLibrary(files, subProviderSavePath, reportProgress, callback); } - private int GetProviderIndex(List providerSavePath, out List subProviderSavePath) - { - subProviderSavePath = null; - - if (providerSavePath != null - && providerSavePath.Count > 1) // key 0 is this provider so we want to look at the next provider - { - for (int i = 0; i < libraryProviders.Count; i++) - { - if (libraryProviders[i].ProviderKey == providerSavePath[1].Key) - { - subProviderSavePath = new List(providerSavePath); - subProviderSavePath.RemoveAt(0); - return i; - } - } - } - - return 0; - } - - // A key,value list that threads into the current collection loos like "key0,displayName0|key1,displayName1|key2,displayName2|...|keyN,displayNameN". - public override List GetProviderLocator() - { - if (selectedLibraryProvider == -1) - { - return new List(); - } - else - { - List providerPathNodes = new List(); - bool first = true; - - for (int i = 0; i < providerLocationStack.Count; i++) - { - PrintItemCollection collection = providerLocationStack[i]; - if (first) - { - providerPathNodes.Add(new ProviderLocatorNode(collection.Key, collection.Name)); - first = false; - } - else - { - providerPathNodes.Add(new ProviderLocatorNode(collection.Key, collection.Name)); - } - } - - return providerPathNodes; - } - } - public override PrintItemCollection GetCollectionItem(int collectionIndex) { if (selectedLibraryProvider == -1) @@ -271,6 +220,36 @@ 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 List GetProviderLocator() + { + if (selectedLibraryProvider == -1) + { + return new List(); + } + else + { + List providerPathNodes = new List(); + bool first = true; + + for (int i = 0; i < providerLocationStack.Count; i++) + { + PrintItemCollection collection = providerLocationStack[i]; + if (first) + { + providerPathNodes.Add(new ProviderLocatorNode(collection.Key, collection.Name)); + first = false; + } + else + { + providerPathNodes.Add(new ProviderLocatorNode(collection.Key, collection.Name)); + } + } + + return providerPathNodes; + } + } + public override void RemoveCollection(string collectionName) { if (selectedLibraryProvider == -1) @@ -284,17 +263,36 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } public override void RemoveItem(PrintItemWrapper printItemWrapper) + { + List subProviderSavePath; + int libraryProviderToUseIndex = GetProviderIndex(printItemWrapper, out subProviderSavePath); + + libraryProviders[libraryProviderToUseIndex].RemoveItem(printItemWrapper); + } + + private static List GetProviderPathFromPrintItem(PrintItemWrapper printItemWrapper) { List providerPath = null; if (printItemWrapper.PrintItem.LibraryProviderLocatorJson != null) { providerPath = JsonConvert.DeserializeObject>(printItemWrapper.PrintItem.LibraryProviderLocatorJson); } - - List subProviderSavePath; - int libraryProviderToUseIndex = GetProviderIndex(providerPath, out subProviderSavePath); + return providerPath; + } - libraryProviders[libraryProviderToUseIndex].RemoveItem(printItemWrapper); + public override void SaveToLibrary(PrintItemWrapper printItemWrapper, List meshGroupsToSave, List providerSavePath = null) + { + if (selectedLibraryProvider == -1) + { + throw new NotImplementedException(); + } + else + { + List subProviderSavePath; + int libraryProviderToUseIndex = GetProviderIndex(printItemWrapper, out subProviderSavePath); + + libraryProviders[libraryProviderToUseIndex].SaveToLibrary(printItemWrapper, meshGroupsToSave, subProviderSavePath); + } } public override void SetCollectionBase(PrintItemCollection collectionBase) @@ -341,6 +339,34 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider CollectionChanged.CallEvents(this, null); } + private int GetProviderIndex(PrintItemWrapper printItemWrapper, out List subProviderSavePath) + { + List providerPath = GetProviderPathFromPrintItem(printItemWrapper); + + return GetProviderIndex(providerPath, out subProviderSavePath); + } + + private int GetProviderIndex(List providerSavePath, out List subProviderSavePath) + { + subProviderSavePath = null; + + if (providerSavePath != null + && providerSavePath.Count > 1) // key 0 is this provider so we want to look at the next provider + { + for (int i = 0; i < libraryProviders.Count; i++) + { + if (libraryProviders[i].ProviderKey == providerSavePath[1].Key) + { + subProviderSavePath = new List(providerSavePath); + subProviderSavePath.RemoveAt(0); + return i; + } + } + } + + return 0; + } + #endregion Overriden Abstract Methods } } \ No newline at end of file diff --git a/PrintLibrary/Provider/LibraryProviderSqlite.cs b/PrintLibrary/Provider/LibraryProviderSqlite.cs index 104ea30a7..4c1cc3732 100644 --- a/PrintLibrary/Provider/LibraryProviderSqlite.cs +++ b/PrintLibrary/Provider/LibraryProviderSqlite.cs @@ -31,6 +31,7 @@ using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.PolygonMesh; using System; using System.Collections.Generic; using System.ComponentModel; @@ -39,8 +40,8 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider { public class LibraryProviderSQLite : LibraryProvider { + private static LibraryProviderSQLite instance = null; private string parentKey = null; - static LibraryProviderSQLite instance = null; public new static LibraryProviderSQLite Instance { @@ -55,10 +56,12 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public void SetParentKey(string parentKey) + public static string StaticProviderKey { - this.parentKey = parentKey; - UiThread.RunOnIdle(() => LibraryProvider.OnDataReloaded(null)); + get + { + return "LibraryProviderSqliteKey"; + } } public override int CollectionCount @@ -111,14 +114,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public static string StaticProviderKey - { - get - { - return "LibraryProviderSqliteKey"; - } - } - public override string ProviderKey { get @@ -137,11 +132,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider LibrarySQLiteData.Instance.LoadFilesIntoLibrary(files, reportProgress, callback); } - public override List GetProviderLocator() - { - throw new NotImplementedException(); - } - public override PrintItemCollection GetCollectionItem(int collectionIndex) { throw new NotImplementedException(); @@ -164,6 +154,11 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider return LibrarySQLiteData.Instance.GetPrintItemWrapper(itemIndex); } + public override List GetProviderLocator() + { + throw new NotImplementedException(); + } + public override void RemoveCollection(string collectionName) { throw new NotImplementedException(); @@ -174,8 +169,19 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider LibrarySQLiteData.Instance.RemoveItem(printItemWrapper); } + public override void SaveToLibrary(PrintItemWrapper printItemWrapper, List meshGroupsToSave, List providerSavePath) + { + throw new NotImplementedException(); + } + public override void SetCollectionBase(PrintItemCollection collectionBase) { } + + public void SetParentKey(string parentKey) + { + this.parentKey = parentKey; + UiThread.RunOnIdle(() => LibraryProvider.OnDataReloaded(null)); + } } } \ No newline at end of file diff --git a/PrintLibrary/Provider/LibrarySQLiteData.cs b/PrintLibrary/Provider/LibrarySQLiteData.cs index ed0f6ba3c..55f7feb6e 100644 --- a/PrintLibrary/Provider/LibrarySQLiteData.cs +++ b/PrintLibrary/Provider/LibrarySQLiteData.cs @@ -70,7 +70,7 @@ namespace MatterHackers.MatterControl.PrintLibrary } } - static public void SaveToLibraryFolder(PrintItemWrapper printItemWrapper, List meshGroups, bool AbsolutePositioned) + static public void SaveToLibraryFolder2(PrintItemWrapper printItemWrapper, List meshGroups, bool AbsolutePositioned) { string[] metaData = { "Created By", "MatterControl" }; if (AbsolutePositioned) @@ -339,7 +339,7 @@ namespace MatterHackers.MatterControl.PrintLibrary try { PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem); - SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave, false); + SaveToLibraryFolder2(printItemWrapper, meshToConvertAndSave, false); Instance.AddItem(printItemWrapper); } catch (System.UnauthorizedAccessException) diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 7cb9ab4a0..65277f941 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 7cb9ab4a02c6233ed9a5c83690528336847a2ace +Subproject commit 65277f9413eacbb2cf75da8fda7f2d155d02615f