Made PrintItemWrapper able to take a containing LibraryPrivider handle
Made the providers pass themselves when building PrintItemWrappers Fixed the bug with print history not setting the correct item to print Took out LibrarySQLiteData (not replaced with LibraryProviderSQLite) Made code go through the new SQLite provider to add parts during setup Starting work on Save as Window to save to queue or provider and do provider selection
This commit is contained in:
parent
a0d4c68ae4
commit
5f4ea81a4c
12 changed files with 48 additions and 427 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<PrintItem> GetLibraryItems(string keyphrase = null)
|
||||
public IEnumerable<PrintItem> GetLibraryItems(string keyphrase = null)
|
||||
{
|
||||
string query;
|
||||
if (keyphrase == 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<PrintItemWrapper> printItems = new List<PrintItemWrapper>();
|
||||
|
||||
public List<PrintItemWrapper> 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<MeshGroup> 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<ProviderLocatorNode> 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<DataStorage.PrintItemCollection>().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<string> 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<DataStorage.PrintItem> 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<DataStorage.PrintItem> result = (IEnumerable<DataStorage.PrintItem>)DataStorage.Datastore.Instance.dbSQLite.Query<DataStorage.PrintItem>(query);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadLibraryItems()
|
||||
{
|
||||
PrintItems.Clear();
|
||||
IEnumerable<DataStorage.PrintItem> 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<string> 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<string> fileList = e.Argument as IList<string>;
|
||||
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<PrintItem> 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<MeshGroup> 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -212,7 +212,6 @@
|
|||
<Compile Include="Library\Provider\LibraryProviderPlugin.cs" />
|
||||
<Compile Include="Library\Provider\LibraryProviderSelector.cs" />
|
||||
<Compile Include="Library\Provider\LibraryProviderFileSystem.cs" />
|
||||
<Compile Include="Library\Provider\LibrarySQLiteData.cs" />
|
||||
<Compile Include="Library\Provider\LibraryProviderSqlite.cs" />
|
||||
<Compile Include="Library\Provider\LibraryProvider.cs" />
|
||||
<Compile Include="Utilities\SelectedListItems.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<SaveAsReturnInfo> functionToCallOnSaveAs;
|
||||
private TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
|
||||
private MHTextEditWidget textToAddWidget;
|
||||
private LibraryProvider selectedLibraryProvider;
|
||||
|
||||
public SaveAsWindow(Action<SaveAsReturnInfo> functionToCallOnSaveAs)
|
||||
public SaveAsWindow(Action<SaveAsReturnInfo> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<string> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 13e34491b66fa023f574e5664921ad959441b048
|
||||
Subproject commit 21a75172a175c25f2e21990d8b0833af2a3f129e
|
||||
Loading…
Add table
Add a link
Reference in a new issue