diff --git a/Library/LibraryRowItemPart.cs b/Library/LibraryRowItemPart.cs index 1916efdc4..ab5d1bf0a 100644 --- a/Library/LibraryRowItemPart.cs +++ b/Library/LibraryRowItemPart.cs @@ -261,7 +261,7 @@ namespace MatterHackers.MatterControl.PrintLibrary if (!PrinterCommunication.PrinterConnectionAndCommunication.Instance.PrintIsActive) { - QueueData.Instance.AddItem(newItem, 0); + QueueData.Instance.AddItem(newItem, indexToInsert: 0); QueueData.Instance.SelectedIndex = QueueData.Instance.Count - 1; PrinterCommunication.PrinterConnectionAndCommunication.Instance.PrintActivePartIfPossible(); } diff --git a/Library/Provider/LibraryProviderFileSystem.cs b/Library/Provider/LibraryProviderFileSystem.cs index 4db007247..c51eb4bf1 100644 --- a/Library/Provider/LibraryProviderFileSystem.cs +++ b/Library/Provider/LibraryProviderFileSystem.cs @@ -181,7 +181,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider { string fileName = currentDirectoryFiles[itemIndex]; - return new PrintItemWrapper(new DataStorage.PrintItem(Path.GetFileNameWithoutExtension(fileName), fileName)); + return new PrintItemWrapper(new DataStorage.PrintItem(Path.GetFileNameWithoutExtension(fileName), fileName), this); } public override LibraryProvider GetProviderForItem(PrintItemCollection collection) diff --git a/Library/Provider/LibraryProviderSqlite.cs b/Library/Provider/LibraryProviderSqlite.cs index 1de1c038b..cc64bab15 100644 --- a/Library/Provider/LibraryProviderSqlite.cs +++ b/Library/Provider/LibraryProviderSqlite.cs @@ -321,7 +321,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider { foreach (PrintItem part in partFiles) { - PrintItemWrapper item = new PrintItemWrapper(part); + PrintItemWrapper item = new PrintItemWrapper(part, this); printItems.Add(item); } } @@ -380,7 +380,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider try { - PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem); + PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem, libraryToAddTo); SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave, false); libraryToAddTo.AddItem(printItemWrapper); } @@ -402,7 +402,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } else // it is not a mesh so just add it { - PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem); + PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem, libraryToAddTo); if (false) { libraryToAddTo.AddItem(printItemWrapper); @@ -431,7 +431,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider return result; } - private IEnumerable GetLibraryItems(string keyphrase = null) + public IEnumerable GetLibraryItems(string keyphrase = null) { string query; if (keyphrase == null) diff --git a/Library/Provider/LibrarySQLiteData.cs b/Library/Provider/LibrarySQLiteData.cs deleted file mode 100644 index ca456f038..000000000 --- a/Library/Provider/LibrarySQLiteData.cs +++ /dev/null @@ -1,384 +0,0 @@ -/* -Copyright (c) 2014, Kevin Pope -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -The views and conclusions contained in the software and documentation are those -of the authors and should not be interpreted as representing official policies, -either expressed or implied, of the FreeBSD Project. -*/ - -using MatterHackers.Agg; -using MatterHackers.Agg.PlatformAbstract; -using MatterHackers.Agg.UI; -using MatterHackers.MatterControl.DataStorage; -using MatterHackers.MatterControl.PrintQueue; -using MatterHackers.MatterControl.SettingsManagement; -using MatterHackers.PolygonMesh; -using MatterHackers.PolygonMesh.Processors; -using MatterHackers.MatterControl.PrintLibrary.Provider; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; - -namespace MatterHackers.MatterControl.PrintLibrary -{ - public class LibrarySQLiteData - { - private List printItems = new List(); - - public List PrintItems - { - get { return printItems; } - } - - private DataStorage.PrintItemCollection libraryCollection; - - private static LibrarySQLiteData instance; - - public static LibrarySQLiteData Instance - { - get - { - if (instance == null) - { - instance = new LibrarySQLiteData(); - instance.LoadLibraryItems(); - } - return instance; - } - } - - static public void SaveToLibraryFolder2(PrintItemWrapper printItemWrapper, List meshGroups, bool AbsolutePositioned) - { - string[] metaData = { "Created By", "MatterControl" }; - if (AbsolutePositioned) - { - metaData = new string[] { "Created By", "MatterControl", "BedPosition", "Absolute" }; - } - if (printItemWrapper.FileLocation.Contains(ApplicationDataStorage.Instance.ApplicationLibraryDataPath)) - { - MeshOutputSettings outputInfo = new MeshOutputSettings(MeshOutputSettings.OutputType.Binary, metaData); - MeshFileIo.Save(meshGroups, printItemWrapper.FileLocation, outputInfo); - } - else // save a copy to the library and update this to point at it - { - string fileName = Path.ChangeExtension(Path.GetRandomFileName(), ".amf"); - printItemWrapper.FileLocation = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, fileName); - - MeshOutputSettings outputInfo = new MeshOutputSettings(MeshOutputSettings.OutputType.Binary, metaData); - MeshFileIo.Save(meshGroups, printItemWrapper.FileLocation, outputInfo); - - printItemWrapper.PrintItem.Commit(); - - // let the queue know that the item has changed so it load the correct part - QueueData.Instance.SaveDefaultQueue(); - } - - printItemWrapper.OnFileHasChanged(); - } - - private string keywordFilter = ""; - - public string KeywordFilter - { - get { return keywordFilter; } - set - { - if (this.keywordFilter != value) - { - this.keywordFilter = value; - LoadLibraryItems(); - } - } - } - - public void AddItem(PrintItemWrapper item, int indexToInsert = -1) - { - if (indexToInsert == -1) - { - indexToInsert = PrintItems.Count; - } - PrintItems.Insert(indexToInsert, item); - // Check if the collection we are adding to is the the currently visible collection. - List currentDisplayedCollection = LibraryProviderSQLite.Instance.GetProviderLocator(); - if (currentDisplayedCollection.Count > 0 && currentDisplayedCollection[1].Key == LibraryProviderSQLite.StaticProviderKey) - { - //OnItemAdded(new IndexArgs(indexToInsert)); - } - item.PrintItem.PrintItemCollectionID = RootLibraryCollection.Id; - item.PrintItem.Commit(); - } - - public void AddCollection(PrintItemCollection collection) - { - collection.Commit(); - } - - public void RemoveItem(PrintItemWrapper printItemWrapper) - { - int index = PrintItems.IndexOf(printItemWrapper); - if (index < 0) - { - // It may be possible to have the same item in the remove list twice. - // so if it is not in the PrintItems then ignore it. - return; - } - PrintItems.RemoveAt(index); - - // and remove it from the data base - printItemWrapper.Delete(); - } - - public PrintItemWrapper GetPrintItemWrapper(int index) - { - if (index >= 0 && index < ItemCount) - { - return PrintItems[index]; - } - - return null; - } - - public DataStorage.PrintItemCollection RootLibraryCollection - { - get - { - // Attempt to initialize the library from the Datastore if null - if (libraryCollection == null) - { - libraryCollection = DataStorage.Datastore.Instance.dbSQLite.Table().Where(v => v.Name == "_library").Take(1).FirstOrDefault(); - } - - // If the _library collection is still missing, create and populate it with default content - if (libraryCollection == null) - { - libraryCollection = new PrintItemCollection(); - libraryCollection.Name = "_library"; - libraryCollection.Commit(); - - // Preload library with Oem supplied list of default parts - string[] itemsToAdd = LibrarySQLiteData.SyncCalibrationFilesToDisk(OemSettings.Instance.PreloadedLibraryFiles); - if (itemsToAdd.Length > 0) - { - // Import any files sync'd to disk into the library, then add them to the queue - LibrarySQLiteData.Instance.LoadFilesIntoLibrary(itemsToAdd); - } - } - return libraryCollection; - } - } - - internal static string[] SyncCalibrationFilesToDisk(List calibrationPrintFileNames) - { - // Ensure the CalibrationParts directory exists to store/import the files from disk - string tempPath = Path.Combine(ApplicationDataStorage.Instance.ApplicationUserDataPath, "data", "temp", "calibration-parts"); - Directory.CreateDirectory(tempPath); - - // Build a list of temporary files that should be imported into the library - return calibrationPrintFileNames.Where(fileName => - { - // Filter out items that already exist in the library - return LibrarySQLiteData.Instance.GetLibraryItems(Path.GetFileNameWithoutExtension(fileName)).Count() <= 0; - }).Select(fileName => - { - // Copy calibration prints from StaticData to the filesystem before importing into the library - string tempFile = Path.Combine(tempPath, Path.GetFileName(fileName)); - using (FileStream outstream = File.OpenWrite(tempFile)) - using (Stream instream = StaticData.Instance.OpenSteam(Path.Combine("OEMSettings", "SampleParts", fileName))) - { - instream.CopyTo(outstream); - } - - // Project the new filename to the output - return tempFile; - }).ToArray(); - } - - internal IEnumerable GetLibraryItems(string keyphrase = null) - { - if (RootLibraryCollection == null) - { - return null; - } - else - { - string query; - if (keyphrase == null) - { - query = string.Format("SELECT * FROM PrintItem WHERE PrintItemCollectionID = {0} ORDER BY Name ASC;", libraryCollection.Id); - } - else - { - query = string.Format("SELECT * FROM PrintItem WHERE PrintItemCollectionID = {0} AND Name LIKE '%{1}%' ORDER BY Name ASC;", libraryCollection.Id, keyphrase); - } - IEnumerable result = (IEnumerable)DataStorage.Datastore.Instance.dbSQLite.Query(query); - return result; - } - } - - public void LoadLibraryItems() - { - PrintItems.Clear(); - IEnumerable partFiles = GetLibraryItems(keywordFilter); - if (partFiles != null) - { - foreach (PrintItem part in partFiles) - { - PrintItems.Add(new PrintItemWrapper(part)); - } - } - OnDataReloaded(null); - } - - public void OnDataReloaded(EventArgs e) - { - LibraryProvider.OnDataReloaded(e); - } - - public void SaveLibraryItems() - { - // - } - - public int ItemCount - { - get - { - return PrintItems.Count; - } - } - - public void LoadFilesIntoLibrary(IList files, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null) - { - if (files != null && files.Count > 0) - { - BackgroundWorker loadFilesIntoLibraryBackgroundWorker = new BackgroundWorker(); - loadFilesIntoLibraryBackgroundWorker.WorkerReportsProgress = true; - - loadFilesIntoLibraryBackgroundWorker.DoWork += new DoWorkEventHandler(loadFilesIntoLibraryBackgoundWorker_DoWork); - loadFilesIntoLibraryBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(loadFilesIntoLibraryBackgroundWorker_RunWorkerCompleted); - - if (callback != null) - { - loadFilesIntoLibraryBackgroundWorker.RunWorkerCompleted += callback; - } - - loadFilesIntoLibraryBackgroundWorker.RunWorkerAsync(files); - } - } - - private void loadFilesIntoLibraryBackgoundWorker_DoWork(object sender, DoWorkEventArgs e) - { - IList fileList = e.Argument as IList; - foreach (string loadedFileName in fileList) - { - string extension = Path.GetExtension(loadedFileName).ToUpper(); - if (MeshFileIo.ValidFileExtensions().Contains(extension) - || extension == ".GCODE" - || extension == ".ZIP") - { - if (extension == ".ZIP") - { - ProjectFileHandler project = new ProjectFileHandler(null); - List partFiles = project.ImportFromProjectArchive(loadedFileName); - if (partFiles != null) - { - foreach (PrintItem part in partFiles) - { - AddStlOrGcode(part.FileLocation, Path.GetExtension(part.FileLocation).ToUpper()); - } - } - } - else - { - AddStlOrGcode(loadedFileName, extension); - } - } - } - } - - private static void AddStlOrGcode(string loadedFileName, string extension) - { - PrintItem printItem = new PrintItem(); - printItem.Name = Path.GetFileNameWithoutExtension(loadedFileName); - printItem.FileLocation = Path.GetFullPath(loadedFileName); - printItem.PrintItemCollectionID = LibrarySQLiteData.Instance.RootLibraryCollection.Id; - printItem.Commit(); - - if (MeshFileIo.ValidFileExtensions().Contains(extension)) - { - List meshToConvertAndSave = MeshFileIo.Load(loadedFileName); - - try - { - PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem); - SaveToLibraryFolder2(printItemWrapper, meshToConvertAndSave, false); - Instance.AddItem(printItemWrapper); - } - catch (System.UnauthorizedAccessException) - { - UiThread.RunOnIdle(() => - { - //Do something special when unauthorized? - StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes, unauthorized access", "Unable to save"); - }); - } - catch - { - UiThread.RunOnIdle(() => - { - StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save"); - }); - } - } - else // it is not a mesh so just add it - { - PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem); - if (false) - { - LibrarySQLiteData.Instance.AddItem(printItemWrapper); - } - else // save a copy to the library and update this to point at it - { - string sourceFileName = printItem.FileLocation; - string newFileName = Path.ChangeExtension(Path.GetRandomFileName(), Path.GetExtension(printItem.FileLocation)); - string destFileName = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, newFileName); - - File.Copy(sourceFileName, destFileName, true); - - printItemWrapper.FileLocation = destFileName; - printItemWrapper.PrintItem.Commit(); - - // let the queue know that the item has changed so it load the correct part - LibrarySQLiteData.Instance.AddItem(printItemWrapper); - } - } - } - - private void loadFilesIntoLibraryBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - } - } -} \ No newline at end of file diff --git a/MatterControl.csproj b/MatterControl.csproj index de8c1e19e..d7e2c97d2 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -212,7 +212,6 @@ - diff --git a/PartPreviewWindow/SaveAsWindow.cs b/PartPreviewWindow/SaveAsWindow.cs index 1ca564b57..9db588e04 100644 --- a/PartPreviewWindow/SaveAsWindow.cs +++ b/PartPreviewWindow/SaveAsWindow.cs @@ -4,6 +4,7 @@ using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.PrintLibrary.Provider; using MatterHackers.MatterControl.PrintQueue; using System; using System.IO; @@ -12,17 +13,19 @@ namespace MatterHackers.MatterControl { public class SaveAsWindow : SystemWindow { - private CheckBox addToLibraryOption; private Action functionToCallOnSaveAs; private TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory(); private MHTextEditWidget textToAddWidget; + private LibraryProvider selectedLibraryProvider; - public SaveAsWindow(Action functionToCallOnSaveAs) + public SaveAsWindow(Action functionToCallOnSaveAs, LibraryProvider startingLibraryProvider) : base(480, 250) { Title = "MatterControl - Save As"; AlwaysOnTopOfMain = true; + selectedLibraryProvider = startingLibraryProvider; + this.functionToCallOnSaveAs = functionToCallOnSaveAs; FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom); @@ -75,15 +78,10 @@ namespace MatterHackers.MatterControl textToAddWidget.HAnchor = HAnchor.ParentLeftRight; textToAddWidget.Margin = new BorderDouble(5); - addToLibraryOption = new CheckBox("Also save to Library".Localize(), ActiveTheme.Instance.PrimaryTextColor); - addToLibraryOption.Margin = new BorderDouble(5); - addToLibraryOption.HAnchor = HAnchor.ParentLeftRight; - middleRowContainer.AddChild(textBoxHeader); middleRowContainer.AddChild(textBoxHeaderFull); middleRowContainer.AddChild(textToAddWidget); middleRowContainer.AddChild(new HorizontalSpacer()); - middleRowContainer.AddChild(addToLibraryOption); topToBottom.AddChild(middleRowContainer); //Creates button container on the bottom of window @@ -137,7 +135,7 @@ namespace MatterHackers.MatterControl string fileName = Path.ChangeExtension(Path.GetRandomFileName(), ".amf"); string fileNameAndPath = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, fileName); - SaveAsReturnInfo returnInfo = new SaveAsReturnInfo(newName, fileNameAndPath, addToLibraryOption.Checked); + SaveAsReturnInfo returnInfo = new SaveAsReturnInfo(newName, fileNameAndPath, selectedLibraryProvider); functionToCallOnSaveAs(returnInfo); CloseOnIdle(); } @@ -147,22 +145,19 @@ namespace MatterHackers.MatterControl { public string fileNameAndPath; public string newName; - public bool placeInLibrary; public PrintItemWrapper printItemWrapper; - public SaveAsReturnInfo(string newName, string fileNameAndPath, bool placeInLibrary) + public SaveAsReturnInfo(string newName, string fileNameAndPath, LibraryProvider destinationLibraryProvider) { this.newName = newName; this.fileNameAndPath = fileNameAndPath; - this.placeInLibrary = placeInLibrary; PrintItem printItem = new PrintItem(); printItem.Name = newName; printItem.FileLocation = Path.GetFullPath(fileNameAndPath); - printItem.PrintItemCollectionID = LibrarySQLiteData.Instance.RootLibraryCollection.Id; - printItem.Commit(); + throw new NotImplementedException(); - printItemWrapper = new PrintItemWrapper(printItem); + printItemWrapper = new PrintItemWrapper(printItem, destinationLibraryProvider); } } } diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index 4d50b67c2..0ffe0f485 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -1388,7 +1388,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { if (saveAsWindow == null) { - saveAsWindow = new SaveAsWindow(MergeAndSavePartsToNewMeshFile); + saveAsWindow = new SaveAsWindow(MergeAndSavePartsToNewMeshFile, printItemWrapper.SourceLibraryProvider); saveAsWindow.Closed += (sender2, e2) => { saveAsWindow = null; @@ -1913,15 +1913,20 @@ namespace MatterHackers.MatterControl.PartPreviewWindow if (returnInfo != null) { - QueueData.Instance.AddItem(printItemWrapper); - if (!PrinterConnectionAndCommunication.Instance.PrintIsActive) - { - QueueData.Instance.SelectedIndex = QueueData.Instance.Count - 1; - } + throw new NotImplementedException(); - if (returnInfo.placeInLibrary) + if (returnInfo.printItemWrapper.SourceLibraryProvider != null) { - LibrarySQLiteData.Instance.AddItem(printItemWrapper); + throw new NotImplementedException(); + // save this part to correct library provider + } + else // there is no library provider so save it to the queue + { + QueueData.Instance.AddItem(printItemWrapper); + if (!PrinterConnectionAndCommunication.Instance.PrintIsActive) + { + QueueData.Instance.SelectedIndex = QueueData.Instance.Count - 1; + } } } @@ -2036,7 +2041,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { if (saveAsWindow == null) { - saveAsWindow = new SaveAsWindow(MergeAndSavePartsToNewMeshFile); + saveAsWindow = new SaveAsWindow(MergeAndSavePartsToNewMeshFile, printItemWrapper.SourceLibraryProvider); saveAsWindow.Closed += new EventHandler(SaveAsWindow_Closed); } else diff --git a/PrinterControls/PrinterConnections/PrinterSetupStatus.cs b/PrinterControls/PrinterConnections/PrinterSetupStatus.cs index aca8ce7fc..c3ac8587d 100644 --- a/PrinterControls/PrinterConnections/PrinterSetupStatus.cs +++ b/PrinterControls/PrinterConnections/PrinterSetupStatus.cs @@ -3,6 +3,7 @@ using MatterHackers.Agg.PlatformAbstract; using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.PrintLibrary.Provider; using MatterHackers.MatterControl.PrintQueue; using System; using System.Collections.Generic; @@ -54,14 +55,12 @@ namespace MatterHackers.MatterControl // Load the calibration file names List calibrationPrintFileNames = LoadCalibrationPartNamesForPrinter(this.ActivePrinter.Make, this.ActivePrinter.Model); - string[] itemsToAdd = LibrarySQLiteData.SyncCalibrationFilesToDisk(calibrationPrintFileNames); + string[] itemsToAdd = LibraryProviderSQLite.SyncCalibrationFilesToDisk(calibrationPrintFileNames); if (itemsToAdd.Length > 0) { // Import any files sync'd to disk into the library, then add them to the queue - LibrarySQLiteData.Instance.LoadFilesIntoLibrary(itemsToAdd, null, (sender, e) => - { - AddItemsToQueue(calibrationPrintFileNames, QueueData.Instance.GetItemNames()); - }); + LibraryProviderSQLite.Instance.AddFilesToLibrary(itemsToAdd); + AddItemsToQueue(calibrationPrintFileNames, QueueData.Instance.GetItemNames()); } else { @@ -83,10 +82,12 @@ namespace MatterHackers.MatterControl } // If the library item does not exist in the queue, add it - var libraryItem = LibrarySQLiteData.Instance.GetLibraryItems(nameOnly).FirstOrDefault(); - if (libraryItem != null) + foreach (PrintItem libraryItem in ((LibraryProviderSQLite)LibraryProviderSQLite.Instance).GetLibraryItems(nameOnly)) { - QueueData.Instance.AddItem(new PrintItemWrapper(libraryItem)); + if (libraryItem != null) + { + QueueData.Instance.AddItem(new PrintItemWrapper(libraryItem)); + } } } } diff --git a/Queue/PrintItemWrapper.cs b/Queue/PrintItemWrapper.cs index 15aba26d0..e5474e5db 100644 --- a/Queue/PrintItemWrapper.cs +++ b/Queue/PrintItemWrapper.cs @@ -31,6 +31,7 @@ using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.PrintLibrary.Provider; using MatterHackers.MatterControl.SlicerConfiguration; using System; using System.IO; @@ -58,10 +59,12 @@ namespace MatterHackers.MatterControl.PrintQueue private long writeTime = 0; - public PrintItemWrapper(DataStorage.PrintItem printItem) + public PrintItemWrapper(DataStorage.PrintItem printItem, LibraryProvider sourceLibraryProvider = null) { this.PrintItem = printItem; this.fileType = Path.GetExtension(printItem.FileLocation).ToUpper(); + + SourceLibraryProvider = sourceLibraryProvider; } public PrintItemWrapper(int printItemId) @@ -79,6 +82,8 @@ namespace MatterHackers.MatterControl.PrintQueue public bool CurrentlySlicing { get; set; } + public LibraryProvider SourceLibraryProvider { get; private set; } + public bool DoneSlicing { get diff --git a/Queue/QueueData.cs b/Queue/QueueData.cs index 514a0585f..355a5fc8c 100644 --- a/Queue/QueueData.cs +++ b/Queue/QueueData.cs @@ -300,7 +300,7 @@ namespace MatterHackers.MatterControl.PrintQueue public enum ValidateSizeOn32BitSystems { Required, Skip } - public void AddItem(PrintItemWrapper item, ValidateSizeOn32BitSystems checkSize = ValidateSizeOn32BitSystems.Required, int indexToInsert = -1) + public void AddItem(PrintItemWrapper item, int indexToInsert = -1, ValidateSizeOn32BitSystems checkSize = ValidateSizeOn32BitSystems.Required) { if (Is32Bit()) { @@ -380,7 +380,7 @@ namespace MatterHackers.MatterControl.PrintQueue { foreach (PrintItem item in partFiles) { - AddItem(new PrintItemWrapper(item), QueueData.ValidateSizeOn32BitSystems.Skip); + AddItem(new PrintItemWrapper(item), -1, QueueData.ValidateSizeOn32BitSystems.Skip); } } RemoveAllSdCardFiles(); diff --git a/Queue/QueueDataWidget.cs b/Queue/QueueDataWidget.cs index 54a46c64d..71580065c 100644 --- a/Queue/QueueDataWidget.cs +++ b/Queue/QueueDataWidget.cs @@ -472,7 +472,7 @@ namespace MatterHackers.MatterControl.PrintQueue private void AddPartCopyToQueue(object state) { var partInfo = state as PartToAddToQueue; - QueueData.Instance.AddItem(new PrintItemWrapper(partInfo.PrintItem), QueueData.ValidateSizeOn32BitSystems.Skip, partInfo.InsertAfterIndex); + QueueData.Instance.AddItem(new PrintItemWrapper(partInfo.PrintItem), partInfo.InsertAfterIndex, QueueData.ValidateSizeOn32BitSystems.Skip); } private void addToLibraryButton_Click(object sender, EventArgs mouseEvent) diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 13e34491b..21a75172a 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 13e34491b66fa023f574e5664921ad959441b048 +Subproject commit 21a75172a175c25f2e21990d8b0833af2a3f129e