diff --git a/Library/Provider/LibraryProvider.cs b/Library/Provider/LibraryProvider.cs index a318845f6..7a35039a1 100644 --- a/Library/Provider/LibraryProvider.cs +++ b/Library/Provider/LibraryProvider.cs @@ -42,161 +42,10 @@ using System.Threading.Tasks; namespace MatterHackers.MatterControl.PrintLibrary.Provider { - - public abstract class ClassicSqliteStorageProvider : LibraryProvider - { - private string keywordFilter = string.Empty; - - protected PrintItemCollection baseLibraryCollection; - - protected List childCollections = new List(); - - public ClassicSqliteStorageProvider(LibraryProvider parentLibraryProvider) - : base(parentLibraryProvider) - { - - } - - protected virtual void AddStlOrGcode(string loadedFileName, string displayName) - { - string extension = Path.GetExtension(loadedFileName).ToUpper(); - - PrintItem printItem = new PrintItem(); - printItem.Name = displayName; - printItem.FileLocation = Path.GetFullPath(loadedFileName); - printItem.PrintItemCollectionID = this.baseLibraryCollection.Id; - printItem.Commit(); - - if ((extension != "" && MeshFileIo.ValidFileExtensions().Contains(extension))) - { - List meshToConvertAndSave = MeshFileIo.Load(loadedFileName); - - try - { - PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem, this); - SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave, false); - } - 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, this); - 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(); - } - } - - protected static void SaveToLibraryFolder(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(); - } - - public override PrintItemCollection GetCollectionItem(int collectionIndex) - { - return childCollections[collectionIndex]; - } - - public override bool Visible - { - get { return true; } - } - - public override void Dispose() - { - } - - public override string ProviderData - { - get - { - return baseLibraryCollection.Id.ToString(); - } - } - - public override string KeywordFilter - { - get - { - return keywordFilter; - } - - set - { - keywordFilter = value; - } - } - - protected IEnumerable GetChildCollections() - { - string query = string.Format("SELECT * FROM PrintItemCollection WHERE ParentCollectionID = {0} ORDER BY Name ASC;", baseLibraryCollection.Id); - IEnumerable result = (IEnumerable)Datastore.Instance.dbSQLite.Query(query); - return result; - } - - public IEnumerable GetLibraryItems(string keyphrase = null) - { - string query; - if (keyphrase == null) - { - query = string.Format("SELECT * FROM PrintItem WHERE PrintItemCollectionID = {0} ORDER BY Name ASC;", baseLibraryCollection.Id); - } - else - { - query = string.Format("SELECT * FROM PrintItem WHERE PrintItemCollectionID = {0} AND Name LIKE '%{1}%' ORDER BY Name ASC;", baseLibraryCollection.Id, keyphrase); - } - IEnumerable result = (IEnumerable)Datastore.Instance.dbSQLite.Query(query); - return result; - } - } - public abstract class LibraryProvider : IDisposable { - public event EventHandler DataReloaded; + protected Dictionary itemReportProgressHandlers = new Dictionary(); + private LibraryProvider parentLibraryProvider = null; public LibraryProvider(LibraryProvider parentLibraryProvider) @@ -204,26 +53,16 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider this.parentLibraryProvider = parentLibraryProvider; } + public event EventHandler DataReloaded; + public LibraryProvider ParentLibraryProvider { get { return parentLibraryProvider; } } #region Member Methods - public bool HasParent - { - get - { - if (this.ParentLibraryProvider != null) - { - return true; - } + private static ImageBuffer normalFolderImage = null; - return false; - } - } + private static ImageBuffer upFolderImage = null; - public abstract bool Visible { get; } - - static ImageBuffer normalFolderImage = null; public static ImageBuffer NormalFolderImage { get @@ -240,7 +79,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - static ImageBuffer upFolderImage = null; public static ImageBuffer UpFolderImage { get @@ -257,6 +95,19 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } + public bool HasParent + { + get + { + if (this.ParentLibraryProvider != null) + { + return true; + } + + return false; + } + } + public void AddFilesToLibrary(IList files, ReportProgressRatio reportProgress = null) { foreach (string loadedFileName in files) @@ -295,7 +146,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider providerLocator.AddRange(ParentLibraryProvider.GetProviderLocator()); } - providerLocator.Add(new ProviderLocatorNode(ProviderKey, Name, ProviderData)); + providerLocator.Add(new ProviderLocatorNode(ProviderKey, Name)); return providerLocator; } @@ -308,20 +159,12 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public abstract int ItemCount { get; } - public abstract string KeywordFilter { get; set; } - - public abstract string Name { get; } - - public abstract string ProviderData { get; } - public abstract string ProviderKey { get; } public abstract void AddCollectionToLibrary(string collectionName); public abstract void AddItem(PrintItemWrapper itemToAdd); - public abstract void Dispose(); - public abstract PrintItemCollection GetCollectionItem(int collectionIndex); public abstract Task GetPrintItemWrapperAsync(int itemIndex); @@ -332,10 +175,10 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public abstract void RemoveCollection(int collectionIndexToRemove); - public abstract void RenameCollection(int collectionIndexToRename, string newName); - public abstract void RemoveItem(int itemIndexToRemove); + public abstract void RenameCollection(int collectionIndexToRename, string newName); + public abstract void RenameItem(int itemIndexToRename, string newName); #endregion Abstract Methods @@ -352,26 +195,65 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider #endregion Static Methods + public virtual string KeywordFilter { get; set; } + + public virtual string StatusMessage + { + get { return ""; } + } + + public virtual void Dispose() + { + } + public virtual int GetCollectionChildCollectionCount(int collectionIndex) { return GetProviderForCollection(GetCollectionItem(collectionIndex)).CollectionCount; } - public class ProgressPlug + public virtual ImageBuffer GetCollectionFolderImage(int collectionIndex) { - public ReportProgressRatio ProgressOutput; - - public void ProgressInput(double progress0To1, string processingState, out bool continueProcessing) - { - continueProcessing = true; - if (ProgressOutput != null) - { - ProgressOutput(progress0To1, processingState, out continueProcessing); - } - } + return NormalFolderImage; } - protected Dictionary itemReportProgressHandlers = new Dictionary(); + public virtual int GetCollectionItemCount(int collectionIndex) + { + return GetProviderForCollection(GetCollectionItem(collectionIndex)).ItemCount; + } + + public virtual GuiWidget GetItemThumbnail(int printItemIndex) + { + var printItemWrapper = GetPrintItemWrapperAsync(printItemIndex).Result; + return new PartThumbnailWidget(printItemWrapper, "part_icon_transparent_40x40.png", "building_thumbnail_40x40.png", PartThumbnailWidget.ImageSizes.Size50x50); + } + + public virtual string GetPrintItemName(int itemIndex) + { + return ""; + } + + public LibraryProvider GetRootProvider() + { + LibraryProvider parent = this; + while (parent != null) + { + parent = parent.ParentLibraryProvider; + } + + return parent; + } + + public string Name { get; protected set; } + + public virtual bool IsItemProtected(int itemIndex) + { + return false; + } + + public virtual bool IsItemReadOnly(int itemIndex) + { + return false; + } public void RegisterForProgress(int itemIndex, ReportProgressRatio reportProgress) { @@ -388,61 +270,28 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - protected ProgressPlug GetItemProgressPlug(int itemIndex) - { - if (!itemReportProgressHandlers.ContainsKey(itemIndex)) - { + protected ProgressPlug GetItemProgressPlug(int itemIndex) + { + if (!itemReportProgressHandlers.ContainsKey(itemIndex)) + { itemReportProgressHandlers.Add(itemIndex, new ProgressPlug()); } - return itemReportProgressHandlers[itemIndex]; - } - - public virtual int GetCollectionItemCount(int collectionIndex) - { - return GetProviderForCollection(GetCollectionItem(collectionIndex)).ItemCount; + return itemReportProgressHandlers[itemIndex]; } - public virtual string StatusMessage + public class ProgressPlug { - get { return ""; } - } + public ReportProgressRatio ProgressOutput; - public virtual ImageBuffer GetCollectionFolderImage(int collectionIndex) - { - return NormalFolderImage; - } - - public virtual GuiWidget GetItemThumbnail(int printItemIndex) - { - var printItemWrapper = GetPrintItemWrapperAsync(printItemIndex).Result; - return new PartThumbnailWidget(printItemWrapper, "part_icon_transparent_40x40.png", "building_thumbnail_40x40.png", PartThumbnailWidget.ImageSizes.Size50x50); - } - - public virtual string GetPrintItemName(int itemIndex) - { - return ""; - } - - public virtual bool IsItemProtected(int itemIndex) - { - return false; - } - - public virtual bool IsItemReadOnly(int itemIndex) - { - return false; - } - - public LibraryProvider GetRootProvider() - { - LibraryProvider parent = this; - while (parent != null) + public void ProgressInput(double progress0To1, string processingState, out bool continueProcessing) { - parent = parent.ParentLibraryProvider; + continueProcessing = true; + if (ProgressOutput != null) + { + ProgressOutput(progress0To1, processingState, out continueProcessing); + } } - - return parent; } } @@ -450,13 +299,11 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider { public string Key; public string Name; - public string ProviderData; - public ProviderLocatorNode(string key, string name, string providerData) + public ProviderLocatorNode(string key, string name) { this.Key = key; this.Name = name; - this.ProviderData = providerData; } } } \ No newline at end of file diff --git a/Library/Provider/LibraryProviderFileSystem.cs b/Library/Provider/LibraryProviderFileSystem.cs index f69651986..4db38937f 100644 --- a/Library/Provider/LibraryProviderFileSystem.cs +++ b/Library/Provider/LibraryProviderFileSystem.cs @@ -70,15 +70,14 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider private string currentDirectory = "."; private List currentDirectoryDirectories = new List(); private List currentDirectoryFiles = new List(); - private string description; private FileSystemWatcher directoryWatcher = new FileSystemWatcher(); private string keywordFilter = string.Empty; private string rootPath; - public LibraryProviderFileSystem(string rootPath, string description, LibraryProvider parentLibraryProvider) + public LibraryProviderFileSystem(string rootPath, string name, LibraryProvider parentLibraryProvider) : base(parentLibraryProvider) { - this.description = description; + this.Name = name; this.rootPath = rootPath; directoryWatcher.Path = rootPath; @@ -149,14 +148,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public void ChangeName(string newName) { - description = newName; - } - - public override string Name { get { return description; } } - - public override string ProviderData - { - get { return rootPath; } + this.Name = newName; } public override string ProviderKey @@ -167,11 +159,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public override bool Visible - { - get { return true; } - } - public override void AddCollectionToLibrary(string collectionName) { string directoryPath = Path.Combine(rootPath, currentDirectory, collectionName); diff --git a/Library/Provider/LibraryProviderHistory.cs b/Library/Provider/LibraryProviderHistory.cs index f3c4d63e7..5af9ab752 100644 --- a/Library/Provider/LibraryProviderHistory.cs +++ b/Library/Provider/LibraryProviderHistory.cs @@ -63,16 +63,15 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public class LibraryProviderHistory : ClassicSqliteStorageProvider + public class LibraryProviderHistory : LibraryProvider { private static LibraryProviderHistory instance = null; public LibraryProviderHistory(PrintItemCollection baseLibraryCollection, LibraryProvider parentLibraryProvider) : base(parentLibraryProvider) { - this.baseLibraryCollection = baseLibraryCollection; - //PrintHistoryData.Instance.ItemAdded.RegisterEvent((sender, e) => OnDataReloaded(null), ref unregisterEvent); + this.Name = "Print History"; } public static LibraryProvider Instance @@ -129,14 +128,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public override string Name - { - get - { - return "Print History"; - } - } - public override string ProviderKey { get @@ -163,7 +154,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public override PrintItemCollection GetCollectionItem(int collectionIndex) { - return childCollections[collectionIndex]; + throw new NotImplementedException(); } public async override Task GetPrintItemWrapperAsync(int index) diff --git a/Library/Provider/LibraryProviderQueue.cs b/Library/Provider/LibraryProviderQueue.cs index d0c32d3a4..2bd0a0808 100644 --- a/Library/Provider/LibraryProviderQueue.cs +++ b/Library/Provider/LibraryProviderQueue.cs @@ -62,7 +62,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public class LibraryProviderQueue : ClassicSqliteStorageProvider + public class LibraryProviderQueue : LibraryProvider { private static LibraryProviderQueue instance = null; @@ -71,9 +71,8 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public LibraryProviderQueue(PrintItemCollection baseLibraryCollection, LibraryProvider parentLibraryProvider) : base(parentLibraryProvider) { - this.baseLibraryCollection = baseLibraryCollection; - QueueData.Instance.ItemAdded.RegisterEvent((sender, e) => OnDataReloaded(null), ref unregisterEvent); + this.Name = "Print Queue"; } public static LibraryProvider Instance @@ -89,6 +88,16 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } + public override int GetCollectionItemCount(int collectionIndex) + { + return base.GetCollectionItemCount(collectionIndex); + } + + public override PrintItemCollection GetCollectionItem(int collectionIndex) + { + throw new NotImplementedException(); + } + public override string GetPrintItemName(int itemIndex) { return QueueData.Instance.GetItemName(itemIndex); @@ -128,14 +137,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public override string Name - { - get - { - return "Print Queue"; - } - } - public override string ProviderKey { get diff --git a/Library/Provider/LibraryProviderSelector.cs b/Library/Provider/LibraryProviderSelector.cs index e4fb387ed..eb35a3cff 100644 --- a/Library/Provider/LibraryProviderSelector.cs +++ b/Library/Provider/LibraryProviderSelector.cs @@ -60,6 +60,8 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public LibraryProviderSelector(Action setCurrentLibraryProvider) : base(null) { + this.Name = "Home".Localize(); + this.setCurrentLibraryProvider = setCurrentLibraryProvider; ApplicationController.Instance.CloudSyncStatusChanged.RegisterEvent(CloudSyncStatusChanged, ref unregisterEvents); @@ -176,11 +178,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public override bool Visible - { - get { return true; } - } - public override void Dispose() { } @@ -205,19 +202,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public override string Name - { - get - { - return "Home".Localize(); - } - } - - public override string ProviderData - { - get { return ""; } - } - public override string ProviderKey { get diff --git a/Library/Provider/LibraryProviderSqlite.cs b/Library/Provider/LibraryProviderSqlite.cs index 909ddcb61..5550ada33 100644 --- a/Library/Provider/LibraryProviderSqlite.cs +++ b/Library/Provider/LibraryProviderSqlite.cs @@ -62,6 +62,137 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } + public abstract class ClassicSqliteStorageProvider : LibraryProvider + { + protected PrintItemCollection baseLibraryCollection; + protected List childCollections = new List(); + private string keywordFilter = string.Empty; + + public ClassicSqliteStorageProvider(LibraryProvider parentLibraryProvider) + : base(parentLibraryProvider) + { + } + + public override string KeywordFilter + { + get + { + return keywordFilter; + } + + set + { + keywordFilter = value; + } + } + + public override PrintItemCollection GetCollectionItem(int collectionIndex) + { + return childCollections[collectionIndex]; + } + + public IEnumerable GetLibraryItems(string keyphrase = null) + { + string query; + if (keyphrase == null) + { + query = string.Format("SELECT * FROM PrintItem WHERE PrintItemCollectionID = {0} ORDER BY Name ASC;", baseLibraryCollection.Id); + } + else + { + query = string.Format("SELECT * FROM PrintItem WHERE PrintItemCollectionID = {0} AND Name LIKE '%{1}%' ORDER BY Name ASC;", baseLibraryCollection.Id, keyphrase); + } + IEnumerable result = (IEnumerable)Datastore.Instance.dbSQLite.Query(query); + return result; + } + + protected static void SaveToLibraryFolder(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(); + } + + protected virtual void AddStlOrGcode(string loadedFileName, string displayName) + { + string extension = Path.GetExtension(loadedFileName).ToUpper(); + + PrintItem printItem = new PrintItem(); + printItem.Name = displayName; + printItem.FileLocation = Path.GetFullPath(loadedFileName); + printItem.PrintItemCollectionID = this.baseLibraryCollection.Id; + printItem.Commit(); + + if ((extension != "" && MeshFileIo.ValidFileExtensions().Contains(extension))) + { + List meshToConvertAndSave = MeshFileIo.Load(loadedFileName); + + try + { + PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem, this); + SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave, false); + } + 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, this); + 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(); + } + } + + protected IEnumerable GetChildCollections() + { + string query = string.Format("SELECT * FROM PrintItemCollection WHERE ParentCollectionID = {0} ORDER BY Name ASC;", baseLibraryCollection.Id); + IEnumerable result = (IEnumerable)Datastore.Instance.dbSQLite.Query(query); + return result; + } + } + public class LibraryProviderSQLite : ClassicSqliteStorageProvider { public bool PreloadingCalibrationFiles = false; @@ -70,12 +201,10 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider private List printItems = new List(); - private string visibleName; - public LibraryProviderSQLite(PrintItemCollection baseLibraryCollection, LibraryProvider parentLibraryProvider, string visibleName) : base(parentLibraryProvider) { - this.visibleName = visibleName; + this.Name = visibleName; if (baseLibraryCollection == null) { @@ -142,14 +271,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public override string Name - { - get - { - return visibleName; - } - } - public override string ProviderKey { get diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 8e65da62f..8d9f6e03a 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 8e65da62fb98f278c3ea819a0d023585e07cad23 +Subproject commit 8d9f6e03a29a901ac674e6f3e3e3dd2e8aeb8f13