Working on a Provider SaveToLibrary function.
Some refactoring
This commit is contained in:
parent
c13f583bd7
commit
185fdfc5b6
8 changed files with 359 additions and 307 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<string> files, List<ProviderLocatorNode> 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<ProviderLocatorNode> 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<ProviderLocatorNode> GetProviderLocator();
|
||||
|
||||
public abstract void RemoveCollection(string collectionName);
|
||||
|
||||
public abstract void RemoveItem(PrintItemWrapper printItemWrapper);
|
||||
|
||||
public abstract void SaveToLibrary(PrintItemWrapper printItemWrapper, List<MeshGroup> meshGroupsToSave, List<ProviderLocatorNode> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<string> 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<ProviderLocatorNode> providerLocator)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override List<ProviderLocatorNode> 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<ProviderLocatorNode> 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<MeshGroup> meshGroupsToSave, List<ProviderLocatorNode> 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<string> 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<ProviderLocatorNode> providerLocator)
|
||||
{
|
||||
string pathWithDot = Path.Combine(rootPath, providerLocator[providerLocator.Count - 1].Key);
|
||||
string pathWithoutDot = pathWithDot.Replace("." + Path.DirectorySeparatorChar, "");
|
||||
return pathWithoutDot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<ProviderLocatorNode> providerSavePath, out List<ProviderLocatorNode> 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<ProviderLocatorNode>(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<ProviderLocatorNode> GetProviderLocator()
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
{
|
||||
return new List<ProviderLocatorNode>();
|
||||
}
|
||||
else
|
||||
{
|
||||
List<ProviderLocatorNode> providerPathNodes = new List<ProviderLocatorNode>();
|
||||
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<ProviderLocatorNode> GetProviderLocator()
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
{
|
||||
return new List<ProviderLocatorNode>();
|
||||
}
|
||||
else
|
||||
{
|
||||
List<ProviderLocatorNode> providerPathNodes = new List<ProviderLocatorNode>();
|
||||
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<ProviderLocatorNode> subProviderSavePath;
|
||||
int libraryProviderToUseIndex = GetProviderIndex(printItemWrapper, out subProviderSavePath);
|
||||
|
||||
libraryProviders[libraryProviderToUseIndex].RemoveItem(printItemWrapper);
|
||||
}
|
||||
|
||||
private static List<ProviderLocatorNode> GetProviderPathFromPrintItem(PrintItemWrapper printItemWrapper)
|
||||
{
|
||||
List<ProviderLocatorNode> providerPath = null;
|
||||
if (printItemWrapper.PrintItem.LibraryProviderLocatorJson != null)
|
||||
{
|
||||
providerPath = JsonConvert.DeserializeObject<List<ProviderLocatorNode>>(printItemWrapper.PrintItem.LibraryProviderLocatorJson);
|
||||
}
|
||||
return providerPath;
|
||||
}
|
||||
|
||||
List<ProviderLocatorNode> subProviderSavePath;
|
||||
int libraryProviderToUseIndex = GetProviderIndex(providerPath, out subProviderSavePath);
|
||||
public override void SaveToLibrary(PrintItemWrapper printItemWrapper, List<MeshGroup> meshGroupsToSave, List<ProviderLocatorNode> providerSavePath = null)
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
else
|
||||
{
|
||||
List<ProviderLocatorNode> subProviderSavePath;
|
||||
int libraryProviderToUseIndex = GetProviderIndex(printItemWrapper, out subProviderSavePath);
|
||||
|
||||
libraryProviders[libraryProviderToUseIndex].RemoveItem(printItemWrapper);
|
||||
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<ProviderLocatorNode> subProviderSavePath)
|
||||
{
|
||||
List<ProviderLocatorNode> providerPath = GetProviderPathFromPrintItem(printItemWrapper);
|
||||
|
||||
return GetProviderIndex(providerPath, out subProviderSavePath);
|
||||
}
|
||||
|
||||
private int GetProviderIndex(List<ProviderLocatorNode> providerSavePath, out List<ProviderLocatorNode> 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<ProviderLocatorNode>(providerSavePath);
|
||||
subProviderSavePath.RemoveAt(0);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endregion Overriden Abstract Methods
|
||||
}
|
||||
}
|
||||
|
|
@ -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<ProviderLocatorNode> 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<ProviderLocatorNode> 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<MeshGroup> meshGroupsToSave, List<ProviderLocatorNode> providerSavePath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void SetCollectionBase(PrintItemCollection collectionBase)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetParentKey(string parentKey)
|
||||
{
|
||||
this.parentKey = parentKey;
|
||||
UiThread.RunOnIdle(() => LibraryProvider.OnDataReloaded(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
}
|
||||
}
|
||||
|
||||
static public void SaveToLibraryFolder(PrintItemWrapper printItemWrapper, List<MeshGroup> meshGroups, bool AbsolutePositioned)
|
||||
static public void SaveToLibraryFolder2(PrintItemWrapper printItemWrapper, List<MeshGroup> 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)
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 7cb9ab4a02c6233ed9a5c83690528336847a2ace
|
||||
Subproject commit 65277f9413eacbb2cf75da8fda7f2d155d02615f
|
||||
Loading…
Add table
Add a link
Reference in a new issue