Made PrintItemWarppers have a ProviderLocator rather than a Provider
Fixed some null reference bugs Fixed a bug with copy to library changing the queues file path Made save as work better.
This commit is contained in:
parent
fa97829073
commit
a0659dc8bb
10 changed files with 126 additions and 64 deletions
|
|
@ -231,7 +231,9 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
|
|||
}
|
||||
|
||||
// Dispose of all children below this one.
|
||||
while (currentLibraryProvider != null)
|
||||
// Dispose of all children below this one.
|
||||
while (currentLibraryProvider != null
|
||||
&& currentLibraryProvider.ParentLibraryProvider != null)
|
||||
{
|
||||
LibraryProvider parent = currentLibraryProvider.ParentLibraryProvider;
|
||||
currentLibraryProvider.Dispose();
|
||||
|
|
@ -368,7 +370,9 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
|
|||
|
||||
var provider = this.CurrentLibraryProvider;
|
||||
|
||||
if (provider != null && provider.ProviderKey != "ProviderSelectorKey")
|
||||
if (provider != null)
|
||||
{
|
||||
if (provider.ProviderKey != "ProviderSelectorKey")
|
||||
{
|
||||
PrintItemCollection parent = new PrintItemCollection("..", provider.ProviderKey);
|
||||
LibrarySelectorRowItem queueItem = new LibrarySelectorRowItem(parent, -1, this, provider.ParentLibraryProvider, GetThumbnailWidget(provider.ParentLibraryProvider, parent, LibraryProvider.UpFolderImage));
|
||||
|
|
@ -385,6 +389,7 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LibraryDataReloaded(object sender, EventArgs e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -693,6 +693,8 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
string stlHashCode = this.ItemWrapper.FileHashCode.ToString();
|
||||
|
||||
if (stlHashCode != "0")
|
||||
{
|
||||
ImageBuffer bigRender = LoadImageFromDisk(this, stlHashCode);
|
||||
if (bigRender == null)
|
||||
{
|
||||
|
|
@ -721,5 +723,8 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -391,8 +391,12 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
}
|
||||
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
if (this.libraryDataView != null
|
||||
&& this.libraryDataView.CurrentLibraryProvider != null)
|
||||
{
|
||||
this.libraryDataView.CurrentLibraryProvider.DataReloaded -= UpdateStatus;
|
||||
}
|
||||
|
||||
if (unregisterEvents != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -128,13 +128,13 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
foreach (PrintItem part in partFiles)
|
||||
{
|
||||
AddItem(new PrintItemWrapper(part, this));
|
||||
AddItem(new PrintItemWrapper(part, this.GetProviderLocator()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddItem(new PrintItemWrapper(new PrintItem(Path.GetFileNameWithoutExtension(loadedFileName), loadedFileName), this));
|
||||
AddItem(new PrintItemWrapper(new PrintItem(Path.GetFileNameWithoutExtension(loadedFileName), loadedFileName), this.GetProviderLocator()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
string fileName = currentDirectoryFiles[itemIndex];
|
||||
|
||||
return new PrintItemWrapper(new DataStorage.PrintItem(GetPrintItemName(itemIndex), fileName), this);
|
||||
return new PrintItemWrapper(new DataStorage.PrintItem(GetPrintItemName(itemIndex), fileName), this.GetProviderLocator());
|
||||
}
|
||||
|
||||
public override LibraryProvider GetProviderForCollection(PrintItemCollection collection)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ using MatterHackers.Agg.UI;
|
|||
using System.Threading.Tasks;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.PlatformAbstract;
|
||||
using System.Threading;
|
||||
|
||||
namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
||||
{
|
||||
|
|
@ -287,5 +288,49 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
LibraryProvider purchasedProvider = PurchasedLibraryCreator.CreateLibraryProvider(this, SetCurrentLibraryProvider);
|
||||
return purchasedProvider;
|
||||
}
|
||||
|
||||
#if false
|
||||
public static async Task<LibraryProvider> GetLibraryFromLocator(List<ProviderLocatorNode> libraryProviderLocator)
|
||||
{
|
||||
LibraryProviderSelector selector = new LibraryProviderSelector(null, true);
|
||||
|
||||
LibraryProvider lastProvider = null;
|
||||
|
||||
if (libraryProviderLocator.Count > 1)
|
||||
{
|
||||
ProviderLocatorNode selectorNode = libraryProviderLocator[1];
|
||||
foreach (ILibraryCreator libraryCreator in selector.libraryCreators)
|
||||
{
|
||||
if (libraryCreator.ProviderKey == selectorNode.Key)
|
||||
{
|
||||
// We found the right creatory, make the library and then iterate through it to get to the correct sub library
|
||||
lastProvider = libraryCreator.CreateLibraryProvider(null, null);
|
||||
for (int i = 2; i < libraryProviderLocator.Count; i++)
|
||||
{
|
||||
ProviderLocatorNode currentNode = libraryProviderLocator[i];
|
||||
|
||||
// wait for our current providre to finish loading
|
||||
while (lastProvider.CollectionCount == 0)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
// now find the next sub provider and go to it
|
||||
for (int collectionIndex = 0; collectionIndex < lastProvider.CollectionCount; collectionIndex++)
|
||||
{
|
||||
PrintItemCollection collection = lastProvider.GetCollectionItem(collectionIndex);
|
||||
if (collection.Key == currentNode.Key)
|
||||
{
|
||||
lastProvider = lastProvider.GetProviderForCollection(collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lastProvider;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -312,7 +312,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
if (index >= 0 && index < printItems.Count)
|
||||
{
|
||||
return new PrintItemWrapper(printItems[index], this);
|
||||
return new PrintItemWrapper(printItems[index], this.GetProviderLocator());
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
@ -373,23 +373,15 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
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
|
||||
// if it is not already in the right location
|
||||
if (!printItemWrapper.FileLocation.Contains(ApplicationDataStorage.Instance.ApplicationLibraryDataPath))
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -409,7 +401,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
try
|
||||
{
|
||||
PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem, this);
|
||||
PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem, this.GetProviderLocator());
|
||||
SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave, false);
|
||||
}
|
||||
catch (System.UnauthorizedAccessException)
|
||||
|
|
@ -430,7 +422,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
}
|
||||
else // it is not a mesh so just add it
|
||||
{
|
||||
PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem, this);
|
||||
PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem, this.GetProviderLocator());
|
||||
string sourceFileName = printItem.FileLocation;
|
||||
string newFileName = Path.ChangeExtension(Path.GetRandomFileName(), Path.GetExtension(printItem.FileLocation));
|
||||
string destFileName = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, newFileName);
|
||||
|
|
|
|||
|
|
@ -1847,7 +1847,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
PrintItem printItem = new PrintItem();
|
||||
printItem.Name = returnInfo.newName;
|
||||
printItem.FileLocation = Path.GetFullPath(returnInfo.fileNameAndPath);
|
||||
printItemWrapper = new PrintItemWrapper(printItem, returnInfo.destinationLibraryProvider);
|
||||
printItemWrapper = new PrintItemWrapper(printItem, returnInfo.destinationLibraryProvider.GetProviderLocator());
|
||||
}
|
||||
|
||||
// we sent the data to the asynch lists but we will not pull it back out (only use it as a temp holder).
|
||||
|
|
@ -1881,7 +1881,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
&& returnInfo.destinationLibraryProvider != null)
|
||||
{
|
||||
// save this part to correct library provider
|
||||
returnInfo.destinationLibraryProvider.AddItem(printItemWrapper);
|
||||
LibraryProvider libraryToSaveTo = returnInfo.destinationLibraryProvider;
|
||||
if (libraryToSaveTo != null)
|
||||
{
|
||||
libraryToSaveTo.AddItem(printItemWrapper);
|
||||
libraryToSaveTo.Dispose();
|
||||
}
|
||||
}
|
||||
else // we have already save it and the library should pick it up
|
||||
{
|
||||
|
|
@ -2036,9 +2041,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
if (saveAsWindow == null)
|
||||
{
|
||||
List<ProviderLocatorNode> providerLocator = null;
|
||||
if (printItemWrapper.SourceLibraryProvider != null)
|
||||
if (printItemWrapper.SourceLibraryProviderLocator != null)
|
||||
{
|
||||
providerLocator = printItemWrapper.SourceLibraryProvider.GetProviderLocator();
|
||||
providerLocator = printItemWrapper.SourceLibraryProviderLocator;
|
||||
}
|
||||
saveAsWindow = new SaveAsWindow(MergeAndSavePartsToNewMeshFile, providerLocator, true, true);
|
||||
saveAsWindow.Closed += new EventHandler(SaveAsWindow_Closed);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ using MatterHackers.MatterControl.DataStorage;
|
|||
using MatterHackers.MatterControl.PrintLibrary.Provider;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
|
|
@ -62,14 +63,14 @@ namespace MatterHackers.MatterControl.PrintQueue
|
|||
|
||||
private FileSystemWatcher diskFileWatcher = new FileSystemWatcher();
|
||||
|
||||
public PrintItemWrapper(DataStorage.PrintItem printItem, LibraryProvider sourceLibraryProvider = null)
|
||||
public PrintItemWrapper(DataStorage.PrintItem printItem, List<ProviderLocatorNode> sourceLibraryProviderLocator = null)
|
||||
{
|
||||
this.PrintItem = printItem;
|
||||
UpdateFileTracking(FileLocation);
|
||||
|
||||
this.fileType = Path.GetExtension(FileLocation).ToUpper();
|
||||
|
||||
SourceLibraryProvider = sourceLibraryProvider;
|
||||
SourceLibraryProviderLocator = sourceLibraryProviderLocator;
|
||||
}
|
||||
|
||||
public PrintItemWrapper(int printItemId)
|
||||
|
|
@ -283,7 +284,7 @@ namespace MatterHackers.MatterControl.PrintQueue
|
|||
|
||||
public bool SlicingHadError { get { return slicingHadError; } }
|
||||
|
||||
public LibraryProvider SourceLibraryProvider { get; private set; }
|
||||
public List<ProviderLocatorNode> SourceLibraryProviderLocator { get; private set; }
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -492,10 +492,15 @@ namespace MatterHackers.MatterControl.PrintQueue
|
|||
if (returnInfo != null)
|
||||
{
|
||||
List<QueueRowItem> selectedItems = new List<QueueRowItem>(queueDataView.SelectedItems);
|
||||
LibraryProvider libraryToSaveTo = returnInfo.destinationLibraryProvider;
|
||||
if (libraryToSaveTo != null)
|
||||
{
|
||||
foreach (QueueRowItem queueItem in selectedItems)
|
||||
{
|
||||
PrintItemWrapper printItemWrapper = new PrintItemWrapper(queueItem.PrintItemWrapper.PrintItem, returnInfo.destinationLibraryProvider);
|
||||
returnInfo.destinationLibraryProvider.AddItem(printItemWrapper);
|
||||
PrintItemWrapper printItemWrapper = new PrintItemWrapper(new PrintItem(queueItem.PrintItemWrapper.PrintItem.Name, queueItem.PrintItemWrapper.FileLocation), returnInfo.destinationLibraryProvider.GetProviderLocator());
|
||||
libraryToSaveTo.AddItem(printItemWrapper);
|
||||
}
|
||||
libraryToSaveTo.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue