Merge branch 'development' of https://github.com/MatterHackers/MatterControl into development
Conflicts:
Submodules/MatterSlice
Resolved:
Using theirs
This commit is contained in:
commit
dd0fda52c6
23 changed files with 925 additions and 774 deletions
|
|
@ -166,7 +166,7 @@ namespace MatterHackers.MatterControl.DataStorage
|
|||
}
|
||||
}
|
||||
|
||||
internal class Datastore
|
||||
public class Datastore
|
||||
{
|
||||
public bool ConnectionError = false;
|
||||
public ISQLite dbSQLite;
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@
|
|||
<Compile Include="PrintLibrary\CreateFolderWindow.cs" />
|
||||
<Compile Include="PrintLibrary\LibraryRowItemCollection.cs" />
|
||||
<Compile Include="PrintLibrary\LibraryRowItemPart.cs" />
|
||||
<Compile Include="PrintLibrary\Provider\LibraryProviderFactory.cs" />
|
||||
<Compile Include="PrintLibrary\Provider\LibraryProviderPlugin.cs" />
|
||||
<Compile Include="PrintLibrary\Provider\LibraryProviderSelector.cs" />
|
||||
<Compile Include="PrintLibrary\Provider\LibraryProviderFileSystem.cs" />
|
||||
<Compile Include="PrintLibrary\Provider\LibrarySQLiteData.cs" />
|
||||
|
|
|
|||
|
|
@ -1870,8 +1870,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
}
|
||||
|
||||
saveSucceded = true;
|
||||
//LibraryProvider.Instance.SaveToCollection(printItemWrapper.PrintItem.LibraryProviderLocator
|
||||
LibraryProvider.Instance.SaveToLibrary(printItemWrapper, asynchMeshGroups);
|
||||
//LibraryDataView.CurrentLibraryProvider.SaveToCollection(printItemWrapper.PrintItem.LibraryProviderLocator
|
||||
LibraryProviderSQLite.Instance.SaveToLibrary(printItemWrapper, asynchMeshGroups);
|
||||
}
|
||||
catch (System.UnauthorizedAccessException)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -39,10 +39,76 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
{
|
||||
public class LibraryDataView : ScrollableWidget
|
||||
{
|
||||
private event EventHandler unregisterEvents;
|
||||
public SelectedListItems<LibraryRowItem> SelectedItems = new SelectedListItems<LibraryRowItem>();
|
||||
|
||||
protected FlowLayoutWidget topToBottomItemList;
|
||||
|
||||
private static LibraryProvider currentLibraryProvider;
|
||||
|
||||
private RGBA_Bytes baseColor = new RGBA_Bytes(255, 255, 255);
|
||||
|
||||
private bool editMode = false;
|
||||
|
||||
private RGBA_Bytes hoverColor = new RGBA_Bytes(204, 204, 204, 255);
|
||||
|
||||
private int hoverIndex = -1;
|
||||
|
||||
private RGBA_Bytes selectedColor = new RGBA_Bytes(180, 180, 180, 255);
|
||||
|
||||
private int selectedIndex = -1;
|
||||
|
||||
private bool settingLocalBounds = false;
|
||||
|
||||
public LibraryDataView()
|
||||
{
|
||||
// set the display attributes
|
||||
{
|
||||
this.AnchorAll();
|
||||
this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
|
||||
this.ScrollArea.Padding = new BorderDouble(3, 3, 5, 3);
|
||||
}
|
||||
|
||||
ScrollArea.HAnchor = HAnchor.ParentLeftRight;
|
||||
|
||||
AutoScroll = true;
|
||||
topToBottomItemList = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
||||
topToBottomItemList.HAnchor = HAnchor.ParentLeftRight;
|
||||
AddChild(topToBottomItemList);
|
||||
|
||||
AddAllItems();
|
||||
|
||||
this.MouseLeaveBounds += new EventHandler(control_MouseLeaveBounds);
|
||||
LibraryProvider.DataReloaded.RegisterEvent(LibraryDataReloaded, ref unregisterEvents);
|
||||
LibraryProvider.ItemAdded.RegisterEvent(ItemAddedToLibrary, ref unregisterEvents);
|
||||
LibraryProvider.ItemRemoved.RegisterEvent(ItemRemovedFromToLibrary, ref unregisterEvents);
|
||||
}
|
||||
|
||||
public delegate void HoverValueChangedEventHandler(object sender, EventArgs e);
|
||||
|
||||
public event HoverValueChangedEventHandler HoverValueChanged;
|
||||
|
||||
public event Action<object, EventArgs> SelectedValueChanged;
|
||||
|
||||
private event EventHandler unregisterEvents;
|
||||
|
||||
public static LibraryProvider CurrentLibraryProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
if (currentLibraryProvider == null)
|
||||
{
|
||||
currentLibraryProvider = LibraryProviderSelector.Instance;
|
||||
}
|
||||
|
||||
return currentLibraryProvider;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
currentLibraryProvider = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool EditMode
|
||||
{
|
||||
get { return editMode; }
|
||||
|
|
@ -59,80 +125,6 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
}
|
||||
}
|
||||
|
||||
public void RemoveSelectedIndex()
|
||||
{
|
||||
if (SelectedIndex >= 0 && SelectedIndex < Count)
|
||||
{
|
||||
RemoveChild(SelectedIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public PrintItemWrapper SelectedPart
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SelectedIndex >= 0)
|
||||
{
|
||||
return LibraryProvider.Instance.GetPrintItemWrapper(SelectedIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearSelectedItems()
|
||||
{
|
||||
foreach (LibraryRowItem item in SelectedItems)
|
||||
{
|
||||
item.isSelectedItem = false;
|
||||
item.selectionCheckBox.Checked = false;
|
||||
}
|
||||
this.SelectedItems.Clear();
|
||||
}
|
||||
|
||||
public event Action<object, EventArgs> SelectedValueChanged;
|
||||
|
||||
public delegate void HoverValueChangedEventHandler(object sender, EventArgs e);
|
||||
|
||||
public event HoverValueChangedEventHandler HoverValueChanged;
|
||||
|
||||
protected FlowLayoutWidget topToBottomItemList;
|
||||
|
||||
private RGBA_Bytes hoverColor = new RGBA_Bytes(204, 204, 204, 255);
|
||||
private RGBA_Bytes selectedColor = new RGBA_Bytes(180, 180, 180, 255);
|
||||
private RGBA_Bytes baseColor = new RGBA_Bytes(255, 255, 255);
|
||||
|
||||
public SelectedListItems<LibraryRowItem> SelectedItems = new SelectedListItems<LibraryRowItem>();
|
||||
private int selectedIndex = -1;
|
||||
private int hoverIndex = -1;
|
||||
|
||||
private int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return topToBottomItemList.Children.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public int SelectedIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedIndex;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < -1 || value >= topToBottomItemList.Children.Count)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
selectedIndex = value;
|
||||
OnSelectedIndexChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public int HoverIndex
|
||||
{
|
||||
get
|
||||
|
|
@ -170,123 +162,6 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
}
|
||||
}
|
||||
|
||||
public LibraryDataView()
|
||||
{
|
||||
// set the display attributes
|
||||
{
|
||||
this.AnchorAll();
|
||||
this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
|
||||
this.ScrollArea.Padding = new BorderDouble(3, 3, 5, 3);
|
||||
}
|
||||
|
||||
ScrollArea.HAnchor = HAnchor.ParentLeftRight;
|
||||
|
||||
AutoScroll = true;
|
||||
topToBottomItemList = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
||||
topToBottomItemList.HAnchor = HAnchor.ParentLeftRight;
|
||||
AddChild(topToBottomItemList);
|
||||
|
||||
AddAllItems();
|
||||
|
||||
this.MouseLeaveBounds += new EventHandler(control_MouseLeaveBounds);
|
||||
LibraryProvider.DataReloaded.RegisterEvent(LibraryDataReloaded, ref unregisterEvents);
|
||||
LibraryProvider.ItemAdded.RegisterEvent(ItemAddedToLibrary, ref unregisterEvents);
|
||||
LibraryProvider.ItemRemoved.RegisterEvent(ItemRemovedFromToLibrary, ref unregisterEvents);
|
||||
}
|
||||
|
||||
public void RebuildView()
|
||||
{
|
||||
AddAllItems();
|
||||
}
|
||||
|
||||
private void AddAllItems()
|
||||
{
|
||||
topToBottomItemList.RemoveAllChildren();
|
||||
|
||||
PrintItemCollection parent = LibraryProvider.Instance.GetParentCollectionItem();
|
||||
if (parent != null)
|
||||
{
|
||||
LibraryRowItem queueItem = new LibraryRowItemCollection(parent, this, false);
|
||||
AddListItemToTopToBottom(queueItem);
|
||||
}
|
||||
|
||||
for (int i = 0; i < LibraryProvider.Instance.CollectionCount; i++)
|
||||
{
|
||||
PrintItemCollection item = LibraryProvider.Instance.GetCollectionItem(i);
|
||||
LibraryRowItem queueItem = new LibraryRowItemCollection(item, this);
|
||||
AddListItemToTopToBottom(queueItem);
|
||||
}
|
||||
|
||||
for (int i = 0; i < LibraryProvider.Instance.ItemCount; i++)
|
||||
{
|
||||
PrintItemWrapper item = LibraryProvider.Instance.GetPrintItemWrapper(i);
|
||||
LibraryRowItem queueItem = new LibraryRowItemPart(item, this);
|
||||
AddListItemToTopToBottom(queueItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void LibraryDataReloaded(object sender, EventArgs e)
|
||||
{
|
||||
AddAllItems();
|
||||
}
|
||||
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
if (unregisterEvents != null)
|
||||
{
|
||||
unregisterEvents(this, null);
|
||||
}
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
private void ItemAddedToLibrary(object sender, EventArgs e)
|
||||
{
|
||||
IndexArgs addedIndexArgs = e as IndexArgs;
|
||||
PrintItemWrapper item = LibraryProvider.Instance.GetPrintItemWrapper(addedIndexArgs.Index);
|
||||
LibraryRowItem libraryItem = new LibraryRowItemPart(item, this);
|
||||
|
||||
int displayIndexToAdd = addedIndexArgs.Index + LibraryProvider.Instance.CollectionCount;
|
||||
if (LibraryProvider.Instance.HasParent)
|
||||
{
|
||||
displayIndexToAdd++;
|
||||
}
|
||||
AddListItemToTopToBottom(libraryItem, displayIndexToAdd);
|
||||
}
|
||||
|
||||
private void ItemRemovedFromToLibrary(object sender, EventArgs e)
|
||||
{
|
||||
IndexArgs removeIndexArgs = e as IndexArgs;
|
||||
int indexToRemove = removeIndexArgs.Index + LibraryProvider.Instance.CollectionCount;
|
||||
if (LibraryProvider.Instance.HasParent)
|
||||
{
|
||||
indexToRemove++;
|
||||
}
|
||||
topToBottomItemList.RemoveChild(indexToRemove);
|
||||
|
||||
if (LibraryProvider.Instance.ItemCount > 0)
|
||||
{
|
||||
SelectedIndex = Math.Max(SelectedIndex - 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddListItemToTopToBottom(GuiWidget child, int indexInChildrenList = -1)
|
||||
{
|
||||
FlowLayoutWidget itemHolder = new FlowLayoutWidget();
|
||||
itemHolder.Name = "list item holder";
|
||||
itemHolder.Margin = new BorderDouble(0, 0, 0, 0);
|
||||
itemHolder.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
|
||||
itemHolder.AddChild(child);
|
||||
itemHolder.VAnchor = VAnchor.FitToChildren;
|
||||
topToBottomItemList.AddChild(itemHolder, indexInChildrenList);
|
||||
|
||||
itemHolder.MouseEnterBounds += new EventHandler(itemToAdd_MouseEnterBounds);
|
||||
itemHolder.MouseLeaveBounds += new EventHandler(itemToAdd_MouseLeaveBounds);
|
||||
itemHolder.MouseDownInBounds += itemHolder_MouseDownInBounds;
|
||||
itemHolder.ParentChanged += new EventHandler(itemHolder_ParentChanged);
|
||||
}
|
||||
|
||||
private bool settingLocalBounds = false;
|
||||
|
||||
public override RectangleDouble LocalBounds
|
||||
{
|
||||
set
|
||||
|
|
@ -321,122 +196,19 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
}
|
||||
}
|
||||
|
||||
public void RemoveSelectedItems()
|
||||
public int SelectedIndex
|
||||
{
|
||||
foreach (LibraryRowItem item in SelectedItems)
|
||||
get
|
||||
{
|
||||
item.RemoveFromParentCollection();
|
||||
return selectedIndex;
|
||||
}
|
||||
}
|
||||
|
||||
public override void RemoveChild(int index)
|
||||
{
|
||||
topToBottomItemList.RemoveChild(index);
|
||||
}
|
||||
|
||||
public override void RemoveChild(GuiWidget childToRemove)
|
||||
{
|
||||
for (int i = topToBottomItemList.Children.Count - 1; i >= 0; i--)
|
||||
set
|
||||
{
|
||||
GuiWidget itemHolder = topToBottomItemList.Children[i];
|
||||
if (itemHolder == childToRemove || itemHolder.Children[0] == childToRemove)
|
||||
if (value < -1 || value >= topToBottomItemList.Children.Count)
|
||||
{
|
||||
topToBottomItemList.RemoveChild(itemHolder);
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void itemHolder_ParentChanged(object sender, EventArgs e)
|
||||
{
|
||||
FlowLayoutWidget itemHolder = (FlowLayoutWidget)sender;
|
||||
itemHolder.MouseEnterBounds -= new EventHandler(itemToAdd_MouseEnterBounds);
|
||||
itemHolder.MouseLeaveBounds -= new EventHandler(itemToAdd_MouseLeaveBounds);
|
||||
itemHolder.MouseDownInBounds -= itemHolder_MouseDownInBounds;
|
||||
itemHolder.ParentChanged -= new EventHandler(itemHolder_ParentChanged);
|
||||
}
|
||||
|
||||
private void itemHolder_MouseDownInBounds(object sender, MouseEventArgs mouseEvent)
|
||||
{
|
||||
}
|
||||
|
||||
private void control_MouseLeaveBounds(object sender, EventArgs e)
|
||||
{
|
||||
HoverIndex = -1;
|
||||
}
|
||||
|
||||
private void itemToAdd_MouseLeaveBounds(object sender, EventArgs e)
|
||||
{
|
||||
GuiWidget widgetLeft = ((GuiWidget)sender);
|
||||
|
||||
if (SelectedIndex >= 0)
|
||||
{
|
||||
if (widgetLeft != topToBottomItemList.Children[SelectedIndex])
|
||||
{
|
||||
widgetLeft.BackgroundColor = new RGBA_Bytes();
|
||||
widgetLeft.Invalidate();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void itemToAdd_MouseEnterBounds(object sender, EventArgs e)
|
||||
{
|
||||
GuiWidget widgetEntered = ((GuiWidget)sender);
|
||||
for (int index = 0; index < topToBottomItemList.Children.Count; index++)
|
||||
{
|
||||
GuiWidget child = topToBottomItemList.Children[index];
|
||||
if (child == widgetEntered)
|
||||
{
|
||||
HoverIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSelectedIndexChanged()
|
||||
{
|
||||
Invalidate();
|
||||
if (SelectedValueChanged != null)
|
||||
{
|
||||
SelectedValueChanged(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnHoverIndexChanged()
|
||||
{
|
||||
Invalidate();
|
||||
if (HoverValueChanged != null)
|
||||
{
|
||||
HoverValueChanged(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics2D graphics2D)
|
||||
{
|
||||
//activeView.OnDraw(graphics2D);
|
||||
|
||||
base.OnDraw(graphics2D);
|
||||
}
|
||||
|
||||
public override void OnMouseDown(MouseEventArgs mouseEvent)
|
||||
{
|
||||
base.OnMouseDown(mouseEvent);
|
||||
}
|
||||
|
||||
public override void OnMouseUp(MouseEventArgs mouseEvent)
|
||||
{
|
||||
base.OnMouseUp(mouseEvent);
|
||||
}
|
||||
|
||||
public override void OnMouseMove(MouseEventArgs mouseEvent)
|
||||
{
|
||||
base.OnMouseMove(mouseEvent);
|
||||
}
|
||||
|
||||
public void ClearSelected()
|
||||
{
|
||||
if (selectedIndex != -1)
|
||||
{
|
||||
selectedIndex = -1;
|
||||
selectedIndex = value;
|
||||
OnSelectedIndexChanged();
|
||||
}
|
||||
}
|
||||
|
|
@ -464,5 +236,258 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PrintItemWrapper SelectedPart
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SelectedIndex >= 0)
|
||||
{
|
||||
return LibraryDataView.CurrentLibraryProvider.GetPrintItemWrapper(SelectedIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return topToBottomItemList.Children.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddListItemToTopToBottom(GuiWidget child, int indexInChildrenList = -1)
|
||||
{
|
||||
FlowLayoutWidget itemHolder = new FlowLayoutWidget();
|
||||
itemHolder.Name = "list item holder";
|
||||
itemHolder.Margin = new BorderDouble(0, 0, 0, 0);
|
||||
itemHolder.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
|
||||
itemHolder.AddChild(child);
|
||||
itemHolder.VAnchor = VAnchor.FitToChildren;
|
||||
topToBottomItemList.AddChild(itemHolder, indexInChildrenList);
|
||||
|
||||
itemHolder.MouseEnterBounds += new EventHandler(itemToAdd_MouseEnterBounds);
|
||||
itemHolder.MouseLeaveBounds += new EventHandler(itemToAdd_MouseLeaveBounds);
|
||||
itemHolder.MouseDownInBounds += itemHolder_MouseDownInBounds;
|
||||
itemHolder.ParentChanged += new EventHandler(itemHolder_ParentChanged);
|
||||
}
|
||||
|
||||
public void ClearSelected()
|
||||
{
|
||||
if (selectedIndex != -1)
|
||||
{
|
||||
selectedIndex = -1;
|
||||
OnSelectedIndexChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearSelectedItems()
|
||||
{
|
||||
foreach (LibraryRowItem item in SelectedItems)
|
||||
{
|
||||
item.isSelectedItem = false;
|
||||
item.selectionCheckBox.Checked = false;
|
||||
}
|
||||
this.SelectedItems.Clear();
|
||||
}
|
||||
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
if (unregisterEvents != null)
|
||||
{
|
||||
unregisterEvents(this, null);
|
||||
}
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics2D graphics2D)
|
||||
{
|
||||
//activeView.OnDraw(graphics2D);
|
||||
|
||||
base.OnDraw(graphics2D);
|
||||
}
|
||||
|
||||
public void OnHoverIndexChanged()
|
||||
{
|
||||
Invalidate();
|
||||
if (HoverValueChanged != null)
|
||||
{
|
||||
HoverValueChanged(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnMouseDown(MouseEventArgs mouseEvent)
|
||||
{
|
||||
base.OnMouseDown(mouseEvent);
|
||||
}
|
||||
|
||||
public override void OnMouseMove(MouseEventArgs mouseEvent)
|
||||
{
|
||||
base.OnMouseMove(mouseEvent);
|
||||
}
|
||||
|
||||
public override void OnMouseUp(MouseEventArgs mouseEvent)
|
||||
{
|
||||
base.OnMouseUp(mouseEvent);
|
||||
}
|
||||
|
||||
public void OnSelectedIndexChanged()
|
||||
{
|
||||
Invalidate();
|
||||
if (SelectedValueChanged != null)
|
||||
{
|
||||
SelectedValueChanged(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void RebuildView()
|
||||
{
|
||||
AddAllItems();
|
||||
}
|
||||
|
||||
public override void RemoveChild(int index)
|
||||
{
|
||||
topToBottomItemList.RemoveChild(index);
|
||||
}
|
||||
|
||||
public override void RemoveChild(GuiWidget childToRemove)
|
||||
{
|
||||
for (int i = topToBottomItemList.Children.Count - 1; i >= 0; i--)
|
||||
{
|
||||
GuiWidget itemHolder = topToBottomItemList.Children[i];
|
||||
if (itemHolder == childToRemove || itemHolder.Children[0] == childToRemove)
|
||||
{
|
||||
topToBottomItemList.RemoveChild(itemHolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveSelectedIndex()
|
||||
{
|
||||
if (SelectedIndex >= 0 && SelectedIndex < Count)
|
||||
{
|
||||
RemoveChild(SelectedIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveSelectedItems()
|
||||
{
|
||||
foreach (LibraryRowItem item in SelectedItems)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//item.RemoveFromParentCollection();
|
||||
}
|
||||
}
|
||||
|
||||
private void AddAllItems()
|
||||
{
|
||||
topToBottomItemList.RemoveAllChildren();
|
||||
|
||||
if (LibraryDataView.CurrentLibraryProvider.ParentLibraryProvider != null)
|
||||
{
|
||||
PrintItemCollection parent = new PrintItemCollection("..", LibraryDataView.CurrentLibraryProvider.ProviderKey);
|
||||
LibraryRowItem queueItem = new LibraryRowItemCollection(parent, this, LibraryDataView.CurrentLibraryProvider.ParentLibraryProvider);
|
||||
AddListItemToTopToBottom(queueItem);
|
||||
}
|
||||
|
||||
for (int i = 0; i < LibraryDataView.CurrentLibraryProvider.CollectionCount; i++)
|
||||
{
|
||||
PrintItemCollection item = LibraryDataView.CurrentLibraryProvider.GetCollectionItem(i);
|
||||
LibraryRowItem queueItem = new LibraryRowItemCollection(item, this, null);
|
||||
AddListItemToTopToBottom(queueItem);
|
||||
}
|
||||
|
||||
for (int i = 0; i < LibraryDataView.CurrentLibraryProvider.ItemCount; i++)
|
||||
{
|
||||
PrintItemWrapper item = LibraryDataView.CurrentLibraryProvider.GetPrintItemWrapper(i);
|
||||
LibraryRowItem queueItem = new LibraryRowItemPart(item, this);
|
||||
AddListItemToTopToBottom(queueItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void control_MouseLeaveBounds(object sender, EventArgs e)
|
||||
{
|
||||
HoverIndex = -1;
|
||||
}
|
||||
|
||||
private void ItemAddedToLibrary(object sender, EventArgs e)
|
||||
{
|
||||
IndexArgs addedIndexArgs = e as IndexArgs;
|
||||
PrintItemWrapper item = LibraryDataView.CurrentLibraryProvider.GetPrintItemWrapper(addedIndexArgs.Index);
|
||||
LibraryRowItem libraryItem = new LibraryRowItemPart(item, this);
|
||||
|
||||
int displayIndexToAdd = addedIndexArgs.Index + LibraryDataView.CurrentLibraryProvider.CollectionCount;
|
||||
if (LibraryDataView.CurrentLibraryProvider.HasParent)
|
||||
{
|
||||
displayIndexToAdd++;
|
||||
}
|
||||
AddListItemToTopToBottom(libraryItem, displayIndexToAdd);
|
||||
}
|
||||
|
||||
private void itemHolder_MouseDownInBounds(object sender, MouseEventArgs mouseEvent)
|
||||
{
|
||||
}
|
||||
|
||||
private void itemHolder_ParentChanged(object sender, EventArgs e)
|
||||
{
|
||||
FlowLayoutWidget itemHolder = (FlowLayoutWidget)sender;
|
||||
itemHolder.MouseEnterBounds -= new EventHandler(itemToAdd_MouseEnterBounds);
|
||||
itemHolder.MouseLeaveBounds -= new EventHandler(itemToAdd_MouseLeaveBounds);
|
||||
itemHolder.MouseDownInBounds -= itemHolder_MouseDownInBounds;
|
||||
itemHolder.ParentChanged -= new EventHandler(itemHolder_ParentChanged);
|
||||
}
|
||||
|
||||
private void ItemRemovedFromToLibrary(object sender, EventArgs e)
|
||||
{
|
||||
IndexArgs removeIndexArgs = e as IndexArgs;
|
||||
int indexToRemove = removeIndexArgs.Index + LibraryDataView.CurrentLibraryProvider.CollectionCount;
|
||||
if (LibraryDataView.CurrentLibraryProvider.HasParent)
|
||||
{
|
||||
indexToRemove++;
|
||||
}
|
||||
topToBottomItemList.RemoveChild(indexToRemove);
|
||||
|
||||
if (LibraryDataView.CurrentLibraryProvider.ItemCount > 0)
|
||||
{
|
||||
SelectedIndex = Math.Max(SelectedIndex - 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void itemToAdd_MouseEnterBounds(object sender, EventArgs e)
|
||||
{
|
||||
GuiWidget widgetEntered = ((GuiWidget)sender);
|
||||
for (int index = 0; index < topToBottomItemList.Children.Count; index++)
|
||||
{
|
||||
GuiWidget child = topToBottomItemList.Children[index];
|
||||
if (child == widgetEntered)
|
||||
{
|
||||
HoverIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void itemToAdd_MouseLeaveBounds(object sender, EventArgs e)
|
||||
{
|
||||
GuiWidget widgetLeft = ((GuiWidget)sender);
|
||||
|
||||
if (SelectedIndex >= 0)
|
||||
{
|
||||
if (widgetLeft != topToBottomItemList.Children[SelectedIndex])
|
||||
{
|
||||
widgetLeft.BackgroundColor = new RGBA_Bytes();
|
||||
widgetLeft.Invalidate();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LibraryDataReloaded(object sender, EventArgs e)
|
||||
{
|
||||
AddAllItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -221,8 +221,6 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
|
||||
public abstract void RemoveFromCollection();
|
||||
|
||||
public abstract void RemoveFromParentCollection();
|
||||
|
||||
protected abstract SlideWidget GetItemActionButtons();
|
||||
|
||||
protected abstract string GetItemName();
|
||||
|
|
|
|||
|
|
@ -46,13 +46,13 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
{
|
||||
public class LibraryRowItemCollection : LibraryRowItem
|
||||
{
|
||||
LibraryProvider parentProvider;
|
||||
PrintItemCollection collection;
|
||||
bool isSubdirector;
|
||||
|
||||
public LibraryRowItemCollection(PrintItemCollection collection, LibraryDataView libraryDataView, bool isSubdirector = true)
|
||||
public LibraryRowItemCollection(PrintItemCollection collection, LibraryDataView libraryDataView, LibraryProvider parentProvider)
|
||||
: base(libraryDataView)
|
||||
{
|
||||
this.isSubdirector = isSubdirector;
|
||||
this.parentProvider = parentProvider;
|
||||
this.collection = collection;
|
||||
CreateGuiElements();
|
||||
}
|
||||
|
|
@ -77,17 +77,12 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void RemoveFromParentCollection()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private ConditionalClickWidget primaryClickContainer;
|
||||
|
||||
protected override GuiWidget GetThumbnailWidget()
|
||||
{
|
||||
string path = Path.Combine("Icons", "FileDialog", "folder.png");
|
||||
if(!isSubdirector)
|
||||
if(parentProvider != null)
|
||||
{
|
||||
path = Path.Combine("Icons", "FileDialog", "upfolder.png");
|
||||
}
|
||||
|
|
@ -95,6 +90,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
StaticData.Instance.LoadImage(path, imageBuffer);
|
||||
|
||||
ImageWidget folderThumbnail = new ImageWidget(imageBuffer);
|
||||
folderThumbnail.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor;
|
||||
return folderThumbnail;
|
||||
}
|
||||
|
||||
|
|
@ -135,13 +131,13 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
|
||||
private void ChangeCollection()
|
||||
{
|
||||
if (isSubdirector)
|
||||
if (parentProvider == null)
|
||||
{
|
||||
LibraryProvider.Instance.SetCollectionBase(collection);
|
||||
LibraryDataView.CurrentLibraryProvider = LibraryDataView.CurrentLibraryProvider.GetProviderForItem(collection);
|
||||
}
|
||||
else
|
||||
{
|
||||
LibraryProvider.Instance.SetCollectionBase(LibraryProvider.Instance.GetParentCollectionItem());
|
||||
LibraryDataView.CurrentLibraryProvider = parentProvider;
|
||||
}
|
||||
|
||||
UiThread.RunOnIdle(libraryDataView.RebuildView);
|
||||
|
|
|
|||
|
|
@ -137,12 +137,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
|
||||
public override void RemoveFromCollection()
|
||||
{
|
||||
LibraryProvider.Instance.RemoveItem(printItemWrapper);
|
||||
}
|
||||
|
||||
public override void RemoveFromParentCollection()
|
||||
{
|
||||
LibraryProvider.Instance.RemoveItem(printItemWrapper);
|
||||
LibraryDataView.CurrentLibraryProvider.RemoveItem(printItemWrapper);
|
||||
}
|
||||
|
||||
protected override SlideWidget GetItemActionButtons()
|
||||
|
|
@ -211,7 +206,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
|
||||
protected override void RemoveThisFromPrintLibrary()
|
||||
{
|
||||
LibraryProvider.Instance.RemoveItem(this.printItemWrapper);
|
||||
LibraryDataView.CurrentLibraryProvider.RemoveItem(this.printItemWrapper);
|
||||
}
|
||||
|
||||
private void ExportQueueItemWindow_Closed(object sender, EventArgs e)
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
{
|
||||
public class PrintLibraryWidget : GuiWidget
|
||||
{
|
||||
private CreateFolderWindow createFolderWindow = null;
|
||||
private TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
|
||||
private static CreateFolderWindow createFolderWindow = null;
|
||||
private static TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
|
||||
private TextImageButtonFactory editButtonFactory = new TextImageButtonFactory();
|
||||
private TextWidget navigationLabel;
|
||||
private TextWidget breadCrumbDisplay;
|
||||
|
|
@ -52,9 +52,10 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
private FlowLayoutWidget itemOperationButtons;
|
||||
private List<bool> editOperationMultiCapable = new List<bool>();
|
||||
|
||||
private Button addToLibraryButton;
|
||||
private static Button addToLibraryButton;
|
||||
private Button enterEditModeButton;
|
||||
private Button leaveEditModeButton;
|
||||
private static FlowLayoutWidget buttonPanel;
|
||||
private MHTextEditWidget searchInput;
|
||||
private LibraryDataView libraryDataView;
|
||||
|
||||
|
|
@ -135,55 +136,12 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
navigationPanel.AddChild(navigationLabel);
|
||||
navigationPanel.AddChild(new HorizontalSpacer());
|
||||
|
||||
FlowLayoutWidget buttonPanel = new FlowLayoutWidget();
|
||||
buttonPanel = new FlowLayoutWidget();
|
||||
buttonPanel.HAnchor = HAnchor.ParentLeftRight;
|
||||
buttonPanel.Padding = new BorderDouble(0, 3);
|
||||
buttonPanel.MinimumSize = new Vector2(0, 46);
|
||||
{
|
||||
// the add button
|
||||
{
|
||||
addToLibraryButton = textImageButtonFactory.Generate(LocalizedString.Get("Add"), "icon_circle_plus.png");
|
||||
buttonPanel.AddChild(addToLibraryButton);
|
||||
addToLibraryButton.Margin = new BorderDouble(0, 0, 3, 0);
|
||||
addToLibraryButton.Click += new EventHandler((sender, e) => UiThread.RunOnIdle(importToLibraryloadFile_ClickOnIdle));
|
||||
}
|
||||
|
||||
// the create folder button
|
||||
{
|
||||
Button createFolderButton = textImageButtonFactory.Generate(LocalizedString.Get("Create Folder"));
|
||||
buttonPanel.AddChild(createFolderButton);
|
||||
createFolderButton.Margin = new BorderDouble(0, 0, 3, 0);
|
||||
createFolderButton.Click += new EventHandler((sender, e) =>
|
||||
{
|
||||
if (createFolderWindow == null)
|
||||
{
|
||||
createFolderWindow = new CreateFolderWindow(CreateNamedFolder);
|
||||
createFolderWindow.Closed += new EventHandler(CreateFolderWindow_Closed);
|
||||
}
|
||||
else
|
||||
{
|
||||
createFolderWindow.BringToFront();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// the redeem code button
|
||||
{
|
||||
Button redeemCodeButton = textImageButtonFactory.Generate(LocalizedString.Get("Redeem"));
|
||||
buttonPanel.AddChild(redeemCodeButton);
|
||||
redeemCodeButton.Margin = new BorderDouble(0, 0, 3, 0);
|
||||
redeemCodeButton.Click += new EventHandler((sender, e) =>
|
||||
{
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
GuiWidget spacer = new GuiWidget();
|
||||
spacer.HAnchor = HAnchor.ParentLeftRight;
|
||||
buttonPanel.AddChild(spacer);
|
||||
}
|
||||
|
||||
AddLibraryButtonElements();
|
||||
CreateEditBarButtons();
|
||||
|
||||
breadCrumbDisplay = new TextWidget("");
|
||||
|
|
@ -204,14 +162,76 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
AddHandlers();
|
||||
}
|
||||
|
||||
private void CreateFolderWindow_Closed(object sender, EventArgs e)
|
||||
private static void AddLibraryButtonElements()
|
||||
{
|
||||
textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
buttonPanel.RemoveAllChildren();
|
||||
// the add button
|
||||
{
|
||||
addToLibraryButton = textImageButtonFactory.Generate(LocalizedString.Get("Add"), "icon_circle_plus.png");
|
||||
buttonPanel.AddChild(addToLibraryButton);
|
||||
addToLibraryButton.Margin = new BorderDouble(0, 0, 3, 0);
|
||||
addToLibraryButton.Click += new EventHandler((sender, e) => UiThread.RunOnIdle(importToLibraryloadFile_ClickOnIdle));
|
||||
}
|
||||
|
||||
// the create folder button
|
||||
{
|
||||
Button createFolderButton = textImageButtonFactory.Generate(LocalizedString.Get("Create Folder"));
|
||||
buttonPanel.AddChild(createFolderButton);
|
||||
createFolderButton.Margin = new BorderDouble(0, 0, 3, 0);
|
||||
createFolderButton.Click += new EventHandler((sender, e) =>
|
||||
{
|
||||
if (createFolderWindow == null)
|
||||
{
|
||||
createFolderWindow = new CreateFolderWindow(CreateNamedFolder);
|
||||
createFolderWindow.Closed += new EventHandler(CreateFolderWindow_Closed);
|
||||
}
|
||||
else
|
||||
{
|
||||
createFolderWindow.BringToFront();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
//Add extra buttons (ex. from plugins) if available
|
||||
if (privateAddLibraryButton != null)
|
||||
{
|
||||
privateAddLibraryButton(buttonPanel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public delegate void AddLibraryButtonDelegate(GuiWidget extraButtonContainer);
|
||||
|
||||
private static event AddLibraryButtonDelegate privateAddLibraryButton;
|
||||
public static event AddLibraryButtonDelegate AddLibraryButton
|
||||
{
|
||||
add
|
||||
{
|
||||
privateAddLibraryButton += value;
|
||||
// and create button container right away
|
||||
AddLibraryButtonElements();
|
||||
}
|
||||
|
||||
remove
|
||||
{
|
||||
privateAddLibraryButton -= value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void CreateFolderWindow_Closed(object sender, EventArgs e)
|
||||
{
|
||||
this.createFolderWindow = null;
|
||||
createFolderWindow = null;
|
||||
}
|
||||
|
||||
private void CreateNamedFolder(CreateFolderWindow.CreateFolderReturnInfo returnInfo)
|
||||
private static void CreateNamedFolder(CreateFolderWindow.CreateFolderReturnInfo returnInfo)
|
||||
{
|
||||
LibraryProvider.Instance.AddCollectionToLibrary(returnInfo.newName);
|
||||
LibraryDataView.CurrentLibraryProvider.AddCollectionToLibrary(returnInfo.newName);
|
||||
}
|
||||
|
||||
private void CreateEditBarButtons()
|
||||
|
|
@ -256,12 +276,12 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
{
|
||||
libraryDataView.SelectedItems.OnAdd += onLibraryItemsSelected;
|
||||
libraryDataView.SelectedItems.OnRemove += onLibraryItemsSelected;
|
||||
LibraryProvider.CollectionChanged.RegisterEvent(CollectionChanged, ref unregisterEvents);
|
||||
LibraryProvider.DataReloaded.RegisterEvent(LibraryProviderDataReleaded, ref unregisterEvents);
|
||||
}
|
||||
|
||||
private void CollectionChanged(object sender, EventArgs e)
|
||||
private void LibraryProviderDataReleaded(object sender, EventArgs e)
|
||||
{
|
||||
List<ProviderLocatorNode> providerLocator = LibraryProvider.Instance.GetProviderLocator();
|
||||
List<ProviderLocatorNode> providerLocator = LibraryDataView.CurrentLibraryProvider.GetProviderLocator();
|
||||
StringBuilder path = new StringBuilder();
|
||||
bool first = true;
|
||||
foreach (ProviderLocatorNode node in providerLocator)
|
||||
|
|
@ -322,7 +342,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
private void searchButtonClick(object sender, EventArgs mouseEvent)
|
||||
{
|
||||
string searchText = searchInput.Text.Trim();
|
||||
LibraryProvider.Instance.KeywordFilter = searchText;
|
||||
LibraryDataView.CurrentLibraryProvider.KeywordFilter = searchText;
|
||||
libraryDataView.ClearSelectedItems();
|
||||
}
|
||||
|
||||
|
|
@ -441,22 +461,22 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
|
||||
public override void OnDragDrop(FileDropEventArgs fileDropEventArgs)
|
||||
{
|
||||
LibraryProvider.Instance.AddFilesToLibrary(fileDropEventArgs.DroppedFiles, LibraryProvider.Instance.GetProviderLocator());
|
||||
LibraryDataView.CurrentLibraryProvider.AddFilesToLibrary(fileDropEventArgs.DroppedFiles);
|
||||
|
||||
base.OnDragDrop(fileDropEventArgs);
|
||||
}
|
||||
|
||||
private void importToLibraryloadFile_ClickOnIdle()
|
||||
private static void importToLibraryloadFile_ClickOnIdle()
|
||||
{
|
||||
OpenFileDialogParams openParams = new OpenFileDialogParams(ApplicationSettings.OpenPrintableFileParams, multiSelect: true);
|
||||
FileDialog.OpenFileDialog(openParams, onLibraryLoadFileSelected);
|
||||
}
|
||||
|
||||
private void onLibraryLoadFileSelected(OpenFileDialogParams openParams)
|
||||
private static void onLibraryLoadFileSelected(OpenFileDialogParams openParams)
|
||||
{
|
||||
if (openParams.FileNames != null)
|
||||
{
|
||||
LibraryProvider.Instance.AddFilesToLibrary(openParams.FileNames, null);
|
||||
LibraryDataView.CurrentLibraryProvider.AddFilesToLibrary(openParams.FileNames, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,80 +39,98 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
public abstract class LibraryProvider
|
||||
{
|
||||
public static RootedObjectEventHandler CollectionChanged = new RootedObjectEventHandler();
|
||||
public static RootedObjectEventHandler DataReloaded = new RootedObjectEventHandler();
|
||||
public static RootedObjectEventHandler ItemAdded = new RootedObjectEventHandler();
|
||||
public static RootedObjectEventHandler ItemRemoved = new RootedObjectEventHandler();
|
||||
private LibraryProvider parentLibraryProvider = null;
|
||||
|
||||
private static LibraryProvider instance;
|
||||
public LibraryProvider(LibraryProvider parentLibraryProvider)
|
||||
{
|
||||
this.parentLibraryProvider = parentLibraryProvider;
|
||||
}
|
||||
|
||||
public static LibraryProvider Instance
|
||||
public LibraryProvider ParentLibraryProvider { get { return parentLibraryProvider; } }
|
||||
|
||||
#region Member Methods
|
||||
|
||||
public bool HasParent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
if (this.ParentLibraryProvider != null)
|
||||
{
|
||||
instance = new LibraryProviderSelector();
|
||||
return true;
|
||||
}
|
||||
|
||||
return instance;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// A key,value list that threads into the current collection looks like "key0,displayName0|key1,displayName1|key2,displayName2|...|keyN,displayNameN".
|
||||
public List<ProviderLocatorNode> GetProviderLocator()
|
||||
{
|
||||
List<ProviderLocatorNode> providerLocator = new List<ProviderLocatorNode>();
|
||||
if (ParentLibraryProvider != null)
|
||||
{
|
||||
providerLocator.AddRange(ParentLibraryProvider.GetProviderLocator());
|
||||
}
|
||||
|
||||
providerLocator.Add(new ProviderLocatorNode(ProviderKey, Name, ProviderData));
|
||||
|
||||
return providerLocator;
|
||||
}
|
||||
|
||||
#endregion Member Methods
|
||||
|
||||
#region Abstract Methods
|
||||
|
||||
public abstract int CollectionCount { get; }
|
||||
|
||||
public abstract bool HasParent { get; }
|
||||
|
||||
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 AddFilesToLibrary(IList<string> files, List<ProviderLocatorNode> providerSavePath, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null);
|
||||
public abstract void AddFilesToLibrary(IList<string> files, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null);
|
||||
|
||||
public abstract void AddItem(PrintItemWrapper itemToAdd);
|
||||
|
||||
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 LibraryProvider GetProviderForItem(PrintItemCollection collection);
|
||||
|
||||
public abstract void RemoveCollection(string collectionName);
|
||||
public abstract void RemoveCollection(PrintItemCollection collectionToRemove);
|
||||
|
||||
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
|
||||
|
||||
#region Static Methods
|
||||
|
||||
public static void OnDataReloaded(EventArgs eventArgs)
|
||||
{
|
||||
DataReloaded.CallEvents(Instance, eventArgs);
|
||||
DataReloaded.CallEvents(null, eventArgs);
|
||||
}
|
||||
|
||||
public static void OnItemAdded(EventArgs eventArgs)
|
||||
{
|
||||
ItemAdded.CallEvents(Instance, eventArgs);
|
||||
ItemAdded.CallEvents(null, eventArgs);
|
||||
}
|
||||
|
||||
public static void OnItemRemoved(EventArgs eventArgs)
|
||||
{
|
||||
ItemRemoved.CallEvents(Instance, eventArgs);
|
||||
ItemRemoved.CallEvents(null, eventArgs);
|
||||
}
|
||||
|
||||
#endregion Static Methods
|
||||
|
|
@ -122,11 +140,13 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
public string Key;
|
||||
public string Name;
|
||||
public string ProviderData;
|
||||
|
||||
public ProviderLocatorNode(string key, string name)
|
||||
public ProviderLocatorNode(string key, string name, string providerData)
|
||||
{
|
||||
this.Key = key;
|
||||
this.Name = name;
|
||||
this.ProviderData = providerData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -50,18 +50,18 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
private string description;
|
||||
private FileSystemWatcher directoryWatcher = new FileSystemWatcher();
|
||||
private string keywordFilter = string.Empty;
|
||||
private string parentProviderKey = null;
|
||||
private string rootPath;
|
||||
|
||||
public LibraryProviderFileSystem(string rootPath, string description, string parentProviderKey)
|
||||
public LibraryProviderFileSystem(string rootPath, string description, LibraryProvider parentLibraryProvider)
|
||||
: base(parentLibraryProvider)
|
||||
{
|
||||
this.parentProviderKey = parentProviderKey;
|
||||
this.description = description;
|
||||
this.rootPath = rootPath;
|
||||
|
||||
key = keyCount.ToString();
|
||||
keyCount++;
|
||||
SetCollectionBase(null);
|
||||
|
||||
directoryWatcher.Path = rootPath;
|
||||
|
||||
directoryWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
|
||||
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
|
||||
|
|
@ -72,6 +72,8 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
// Begin watching.
|
||||
directoryWatcher.EnableRaisingEvents = true;
|
||||
|
||||
GetFilesAndCollectionsInCurrentDirectory();
|
||||
}
|
||||
|
||||
public override int CollectionCount
|
||||
|
|
@ -82,19 +84,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
}
|
||||
}
|
||||
|
||||
public override bool HasParent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (parentProviderKey != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override int ItemCount
|
||||
{
|
||||
get
|
||||
|
|
@ -123,6 +112,11 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
public override string Name { get { return description; } }
|
||||
|
||||
public override string ProviderData
|
||||
{
|
||||
get { return rootPath; }
|
||||
}
|
||||
|
||||
public override string ProviderKey
|
||||
{
|
||||
get
|
||||
|
|
@ -142,23 +136,15 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
}
|
||||
}
|
||||
|
||||
public override void AddFilesToLibrary(IList<string> files, List<ProviderLocatorNode> providerLocator, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null)
|
||||
public override void AddFilesToLibrary(IList<string> files, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null)
|
||||
{
|
||||
if (providerLocator == null || providerLocator.Count <= 1)
|
||||
{
|
||||
string destPath = rootPath;
|
||||
string destPath = rootPath;
|
||||
|
||||
CopyAllFiles(files, destPath);
|
||||
}
|
||||
else // we have a path that we need to save to
|
||||
{
|
||||
string destPath = GetPathFromLocator(providerLocator);
|
||||
|
||||
CopyAllFiles(files, destPath);
|
||||
}
|
||||
CopyAllFiles(files, destPath);
|
||||
|
||||
GetFilesAndCollectionsInCurrentDirectory();
|
||||
LibraryProvider.OnDataReloaded(null);
|
||||
LibraryProvider.OnItemAdded(null);
|
||||
}
|
||||
|
||||
public override void AddItem(PrintItemWrapper itemToAdd)
|
||||
|
|
@ -169,45 +155,31 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
public override PrintItemCollection GetCollectionItem(int collectionIndex)
|
||||
{
|
||||
string directoryName = currentDirectoryDirectories[collectionIndex];
|
||||
return new PrintItemCollection(Path.GetFileNameWithoutExtension(directoryName), directoryName);
|
||||
}
|
||||
|
||||
public override PrintItemCollection GetParentCollectionItem()
|
||||
{
|
||||
if (currentDirectory == ".")
|
||||
{
|
||||
if (parentProviderKey != null)
|
||||
{
|
||||
return new PrintItemCollection("..", parentProviderKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string parentDirectory = Path.GetDirectoryName(currentDirectory);
|
||||
return new PrintItemCollection("..", parentDirectory);
|
||||
}
|
||||
return new PrintItemCollection(Path.GetFileNameWithoutExtension(directoryName), Path.Combine(rootPath, directoryName));
|
||||
}
|
||||
|
||||
public override PrintItemWrapper GetPrintItemWrapper(int itemIndex)
|
||||
{
|
||||
string fileName = currentDirectoryFiles[itemIndex];
|
||||
List<ProviderLocatorNode> providerLocator = LibraryProvider.Instance.GetProviderLocator();
|
||||
List<ProviderLocatorNode> providerLocator = GetProviderLocator();
|
||||
string providerLocatorJson = JsonConvert.SerializeObject(providerLocator);
|
||||
return new PrintItemWrapper(new DataStorage.PrintItem(Path.GetFileNameWithoutExtension(fileName), fileName, providerLocatorJson));
|
||||
}
|
||||
|
||||
public override List<ProviderLocatorNode> GetProviderLocator()
|
||||
public override LibraryProvider GetProviderForItem(PrintItemCollection collection)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return new LibraryProviderFileSystem(Path.Combine(rootPath, collection.Key), collection.Name, this);
|
||||
}
|
||||
|
||||
public override void RemoveCollection(string collectionName)
|
||||
public override void RemoveCollection(PrintItemCollection collectionToRemove)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
string directoryPath = collectionToRemove.Key;
|
||||
if (Directory.Exists(directoryPath))
|
||||
{
|
||||
Directory.Delete(directoryPath);
|
||||
GetFilesAndCollectionsInCurrentDirectory();
|
||||
LibraryProvider.OnDataReloaded(null);
|
||||
}
|
||||
}
|
||||
|
||||
public override void RemoveItem(PrintItemWrapper printItemWrapper)
|
||||
|
|
@ -222,27 +194,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void SetCollectionBase(PrintItemCollection collectionBase)
|
||||
{
|
||||
if (collectionBase == null)
|
||||
{
|
||||
currentDirectory = ".";
|
||||
}
|
||||
else
|
||||
{
|
||||
string collectionPath = collectionBase.Key;
|
||||
int startOfCurrentDir = collectionPath.IndexOf('.');
|
||||
if (startOfCurrentDir != -1)
|
||||
{
|
||||
this.currentDirectory = collectionPath.Substring(startOfCurrentDir);
|
||||
}
|
||||
}
|
||||
|
||||
GetFilesAndCollectionsInCurrentDirectory();
|
||||
|
||||
directoryWatcher.Path = Path.Combine(rootPath, currentDirectory);
|
||||
}
|
||||
|
||||
private static void CopyAllFiles(IList<string> files, string destPath)
|
||||
{
|
||||
// make sure the directory exists
|
||||
|
|
@ -261,7 +212,35 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
// and copy the file
|
||||
try
|
||||
{
|
||||
File.Copy(file, outputFileName);
|
||||
if (!File.Exists(file))
|
||||
{
|
||||
File.Copy(file, outputFileName);
|
||||
}
|
||||
else // make a new file and append a number so that we are not destructive
|
||||
{
|
||||
string directory = Path.GetDirectoryName(outputFileName);
|
||||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(outputFileName);
|
||||
string extension = Path.GetExtension(outputFileName);
|
||||
// get the filename without a number on the end
|
||||
int lastSpaceIndex = fileNameWithoutExtension.LastIndexOf(' ');
|
||||
if (lastSpaceIndex != -1)
|
||||
{
|
||||
int endingNumber;
|
||||
// check if the last set of characters is a number
|
||||
if (int.TryParse(fileNameWithoutExtension.Substring(lastSpaceIndex), out endingNumber))
|
||||
{
|
||||
fileNameWithoutExtension = fileNameWithoutExtension.Substring(0, lastSpaceIndex);
|
||||
}
|
||||
}
|
||||
int numberToAppend = 2;
|
||||
string fileNameToUse = Path.Combine(directory, fileNameWithoutExtension + " " + numberToAppend.ToString() + extension);
|
||||
while (File.Exists(fileNameToUse))
|
||||
{
|
||||
numberToAppend++;
|
||||
fileNameToUse = Path.Combine(directory, fileNameWithoutExtension + " " + numberToAppend.ToString() + extension);
|
||||
}
|
||||
File.Copy(file, fileNameToUse);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ using System.ComponentModel;
|
|||
|
||||
namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
||||
{
|
||||
public class LibraryProviderFactory
|
||||
public class LibraryProviderPlugin
|
||||
{
|
||||
virtual public LibraryProvider CreateProvider(string parentKey)
|
||||
virtual public LibraryProvider CreateLibraryProvider(LibraryProvider parentLibraryProvider)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
@ -40,64 +40,67 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
public class LibraryProviderSelector : LibraryProvider
|
||||
{
|
||||
private static LibraryProviderSelector instance = null;
|
||||
private List<LibraryProvider> libraryProviders = new List<LibraryProvider>();
|
||||
private int selectedLibraryProvider = -1;
|
||||
|
||||
public LibraryProviderSelector()
|
||||
private LibraryProviderSelector()
|
||||
: base(null)
|
||||
{
|
||||
// put in the sqlite provider
|
||||
libraryProviders.Add(LibraryProviderSQLite.Instance);
|
||||
LibraryProviderSQLite.Instance.SetParentKey(this.ProviderKey);
|
||||
libraryProviders.Add(new LibraryProviderSQLite(null, this));
|
||||
|
||||
// and any directory providers (sd card provider, etc...)
|
||||
libraryProviders.Add(new LibraryProviderFileSystem(Path.Combine("C:\\", "Users", "LarsBrubaker", "Downloads"), "Downloads", this.ProviderKey));
|
||||
//
|
||||
// Add "Downloads" file system example
|
||||
string downloadsDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads");
|
||||
if (Directory.Exists(downloadsDirectory))
|
||||
{
|
||||
libraryProviders.Add(new LibraryProviderFileSystem(downloadsDirectory, "Downloads", this));
|
||||
}
|
||||
|
||||
//#if __ANDROID__
|
||||
//libraryProviders.Add(new LibraryProviderFileSystem(ApplicationDataStorage.Instance.PublicDataStoragePath, "Downloads", this.ProviderKey));
|
||||
|
||||
PrintItemCollection libraryCollection = new PrintItemCollection("Library Folder1", Path.Combine("C:\\", "Users", "LarsBrubaker", "AppData", "Local", "MatterControl", "Library"));
|
||||
//libraryProviders.Add(new LibraryProviderFileSystem(libraryCollection, "Library Folder2", this.ProviderKey));
|
||||
|
||||
// Check for LibraryProvider factories and put them in the list too.
|
||||
PluginFinder<LibraryProviderFactory> libraryFactories = new PluginFinder<LibraryProviderFactory>();
|
||||
foreach (LibraryProviderFactory factory in libraryFactories.Plugins)
|
||||
PluginFinder<LibraryProviderPlugin> libraryProviderPlugins = new PluginFinder<LibraryProviderPlugin>();
|
||||
foreach (LibraryProviderPlugin libraryProviderPlugin in libraryProviderPlugins.Plugins)
|
||||
{
|
||||
libraryProviders.Add(factory.CreateProvider(this.ProviderKey));
|
||||
libraryProviders.Add(libraryProviderPlugin.CreateLibraryProvider(this));
|
||||
}
|
||||
|
||||
providerLocationStack.Add(new PrintItemCollection("..", ProviderKey));
|
||||
}
|
||||
|
||||
public static LibraryProviderSelector Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new LibraryProviderSelector();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
#region Overriden Abstract Methods
|
||||
|
||||
private List<PrintItemCollection> providerLocationStack = new List<PrintItemCollection>();
|
||||
|
||||
public static string LibraryProviderSelectorKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ProviderSelectorKey";
|
||||
}
|
||||
}
|
||||
|
||||
public override int CollectionCount
|
||||
{
|
||||
get
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
{
|
||||
return libraryProviders.Count;
|
||||
}
|
||||
else
|
||||
{
|
||||
return libraryProviders[selectedLibraryProvider].CollectionCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasParent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return libraryProviders[selectedLibraryProvider].HasParent;
|
||||
}
|
||||
return libraryProviders.Count;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,14 +108,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
get
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return libraryProviders[selectedLibraryProvider].ItemCount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -120,25 +116,11 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
get
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return libraryProviders[selectedLibraryProvider].KeywordFilter;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
libraryProviders[selectedLibraryProvider].KeywordFilter = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,32 +132,27 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
}
|
||||
}
|
||||
|
||||
public override string ProviderData
|
||||
{
|
||||
get { return ""; }
|
||||
}
|
||||
|
||||
public override string ProviderKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ProviderSelectorKey";
|
||||
return LibraryProviderSelectorKey;
|
||||
}
|
||||
}
|
||||
|
||||
public override void AddCollectionToLibrary(string collectionName)
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
else
|
||||
{
|
||||
libraryProviders[selectedLibraryProvider].AddCollectionToLibrary(collectionName);
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void AddFilesToLibrary(IList<string> files, List<ProviderLocatorNode> providerSavePath, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null)
|
||||
public override void AddFilesToLibrary(IList<string> files, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null)
|
||||
{
|
||||
List<ProviderLocatorNode> subProviderSavePath;
|
||||
int libraryProviderToUseIndex = GetProviderIndex(providerSavePath, out subProviderSavePath);
|
||||
|
||||
libraryProviders[libraryProviderToUseIndex].AddFilesToLibrary(files, subProviderSavePath, reportProgress, callback);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void AddItem(PrintItemWrapper itemToAdd)
|
||||
|
|
@ -185,85 +162,35 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
public override PrintItemCollection GetCollectionItem(int collectionIndex)
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
{
|
||||
LibraryProvider provider = libraryProviders[collectionIndex];
|
||||
return new PrintItemCollection(provider.Name, provider.ProviderKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return libraryProviders[selectedLibraryProvider].GetCollectionItem(collectionIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public override PrintItemCollection GetParentCollectionItem()
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return libraryProviders[selectedLibraryProvider].GetParentCollectionItem();
|
||||
}
|
||||
LibraryProvider provider = libraryProviders[collectionIndex];
|
||||
return new PrintItemCollection(provider.Name, provider.ProviderKey);
|
||||
}
|
||||
|
||||
public override PrintItemWrapper GetPrintItemWrapper(int itemIndex)
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
if (libraryProviders[0].ProviderKey != LibraryProviderSQLite.StaticProviderKey)
|
||||
{
|
||||
if (libraryProviders[0].ProviderKey != LibraryProviderSQLite.StaticProviderKey)
|
||||
{
|
||||
throw new Exception("It is expected these are the same.");
|
||||
}
|
||||
return libraryProviders[0].GetPrintItemWrapper(itemIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
return libraryProviders[selectedLibraryProvider].GetPrintItemWrapper(itemIndex);
|
||||
throw new Exception("It is expected these are the same.");
|
||||
}
|
||||
return libraryProviders[0].GetPrintItemWrapper(itemIndex);
|
||||
}
|
||||
|
||||
// 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()
|
||||
public override LibraryProvider GetProviderForItem(PrintItemCollection collection)
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
foreach (LibraryProvider libraryProvider in libraryProviders)
|
||||
{
|
||||
return new List<ProviderLocatorNode>();
|
||||
}
|
||||
else
|
||||
{
|
||||
List<ProviderLocatorNode> providerPathNodes = new List<ProviderLocatorNode>();
|
||||
bool first = true;
|
||||
|
||||
for (int i = 0; i < providerLocationStack.Count; i++)
|
||||
if (collection.Key == libraryProvider.ProviderKey)
|
||||
{
|
||||
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 libraryProvider;
|
||||
}
|
||||
|
||||
return providerPathNodes;
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void RemoveCollection(string collectionName)
|
||||
public override void RemoveCollection(PrintItemCollection collectionToRemove)
|
||||
{
|
||||
if (selectedLibraryProvider == -1)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
else
|
||||
{
|
||||
libraryProviders[selectedLibraryProvider].RemoveCollection(collectionName);
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void RemoveItem(PrintItemWrapper printItemWrapper)
|
||||
|
|
@ -276,61 +203,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
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].SaveToLibrary(printItemWrapper, meshGroupsToSave, subProviderSavePath);
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetCollectionBase(PrintItemCollection collectionBase)
|
||||
{
|
||||
// This logic may need to be move legitamately into the virtual functions of the providers rather than all
|
||||
// gathered up here. If you find that this is not working the way you want ask me. LBB
|
||||
if ((providerLocationStack.Count > 2
|
||||
&& collectionBase.Key == providerLocationStack[providerLocationStack.Count - 2].Key)
|
||||
|| (providerLocationStack.Count > 1
|
||||
&& selectedLibraryProvider != -1
|
||||
&& collectionBase.Key == libraryProviders[selectedLibraryProvider].GetParentCollectionItem().Key)
|
||||
)
|
||||
{
|
||||
providerLocationStack.RemoveAt(providerLocationStack.Count - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
providerLocationStack.Add(collectionBase);
|
||||
}
|
||||
|
||||
if (collectionBase.Key == this.ProviderKey)
|
||||
{
|
||||
selectedLibraryProvider = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool wasSet = false;
|
||||
for (int i = 0; i < libraryProviders.Count; i++)
|
||||
{
|
||||
if (libraryProviders[i].ProviderKey == collectionBase.Key)
|
||||
{
|
||||
selectedLibraryProvider = i;
|
||||
wasSet = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!wasSet)
|
||||
{
|
||||
libraryProviders[selectedLibraryProvider].SetCollectionBase(collectionBase);
|
||||
}
|
||||
}
|
||||
|
||||
CollectionChanged.CallEvents(this, null);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private int GetProviderIndex(PrintItemWrapper printItemWrapper, out List<ProviderLocatorNode> subProviderSavePath)
|
||||
|
|
@ -362,5 +235,10 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
}
|
||||
|
||||
#endregion Overriden Abstract Methods
|
||||
|
||||
public static LibraryProvider GetProviderForItem(PrintItemWrapper printItemWrapper)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -35,6 +35,7 @@ using MatterHackers.MatterControl.PrintQueue;
|
|||
using MatterHackers.MatterControl.SettingsManagement;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.PolygonMesh.Processors;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
|
@ -46,26 +47,32 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
public class LibraryProviderSQLite : LibraryProvider
|
||||
{
|
||||
private static LibraryProviderSQLite instance = null;
|
||||
private static PrintItemCollection rotLibraryCollection;
|
||||
private PrintItemCollection baseLibraryCollection;
|
||||
|
||||
private List<PrintItemCollection> childCollections = new List<PrintItemCollection>();
|
||||
private PrintItemCollection collectionBase = GetRootLibraryCollection();
|
||||
private string keywordFilter = string.Empty;
|
||||
private string parentProviderKey = null;
|
||||
|
||||
private List<PrintItemWrapper> printItems = new List<PrintItemWrapper>();
|
||||
|
||||
public LibraryProviderSQLite()
|
||||
public LibraryProviderSQLite(PrintItemCollection baseLibraryCollection, LibraryProvider parentLibraryProvider)
|
||||
: base(parentLibraryProvider)
|
||||
{
|
||||
if (baseLibraryCollection == null)
|
||||
{
|
||||
baseLibraryCollection = GetRootLibraryCollection2(this);
|
||||
}
|
||||
|
||||
this.baseLibraryCollection = baseLibraryCollection;
|
||||
LoadLibraryItems();
|
||||
}
|
||||
|
||||
public new static LibraryProviderSQLite Instance
|
||||
public static LibraryProvider Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new LibraryProviderSQLite();
|
||||
instance = new LibraryProviderSQLite(null, null);
|
||||
}
|
||||
|
||||
return instance;
|
||||
|
|
@ -88,19 +95,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
}
|
||||
}
|
||||
|
||||
public override bool HasParent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (parentProviderKey != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override int ItemCount
|
||||
{
|
||||
get
|
||||
|
|
@ -130,6 +124,14 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
}
|
||||
}
|
||||
|
||||
public override string ProviderData
|
||||
{
|
||||
get
|
||||
{
|
||||
return baseLibraryCollection.Id.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ProviderKey
|
||||
{
|
||||
get
|
||||
|
|
@ -146,30 +148,28 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
return result;
|
||||
}
|
||||
|
||||
public static PrintItemCollection GetRootLibraryCollection()
|
||||
static PrintItemCollection GetRootLibraryCollection2(LibraryProviderSQLite rootLibrary)
|
||||
{
|
||||
// Attempt to initialize the library from the Datastore if null
|
||||
if (rotLibraryCollection == null)
|
||||
{
|
||||
rotLibraryCollection = Datastore.Instance.dbSQLite.Table<PrintItemCollection>().Where(v => v.Name == "_library").Take(1).FirstOrDefault();
|
||||
}
|
||||
PrintItemCollection rootLibraryCollection = Datastore.Instance.dbSQLite.Table<PrintItemCollection>().Where(v => v.Name == "_library").Take(1).FirstOrDefault();
|
||||
|
||||
// If the _library collection is still missing, create and populate it with default content
|
||||
if (rotLibraryCollection == null)
|
||||
if (rootLibraryCollection == null)
|
||||
{
|
||||
rotLibraryCollection = new PrintItemCollection();
|
||||
rotLibraryCollection.Name = "_library";
|
||||
rotLibraryCollection.Commit();
|
||||
rootLibraryCollection = new PrintItemCollection();
|
||||
rootLibraryCollection.Name = "_library";
|
||||
rootLibraryCollection.Commit();
|
||||
|
||||
// Preload library with Oem supplied list of default parts
|
||||
string[] itemsToAdd = SyncCalibrationFilesToDisk(OemSettings.Instance.PreloadedLibraryFiles);
|
||||
if (itemsToAdd.Length > 0)
|
||||
{
|
||||
// Import any files sync'd to disk into the library, then add them to the queue
|
||||
Instance.AddFilesToLibrary(itemsToAdd);
|
||||
rootLibrary.AddFilesToLibrary(itemsToAdd);
|
||||
}
|
||||
}
|
||||
return rotLibraryCollection;
|
||||
|
||||
return rootLibraryCollection;
|
||||
}
|
||||
|
||||
static public void SaveToLibraryFolder(PrintItemWrapper printItemWrapper, List<MeshGroup> meshGroups, bool AbsolutePositioned)
|
||||
|
|
@ -211,7 +211,8 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
return calibrationPrintFileNames.Where(fileName =>
|
||||
{
|
||||
// Filter out items that already exist in the library
|
||||
return Instance.GetLibraryItems(Path.GetFileNameWithoutExtension(fileName)).Count() <= 0;
|
||||
LibraryProviderSQLite rootLibrary = new LibraryProviderSQLite(null, null);
|
||||
return rootLibrary.GetLibraryItems(Path.GetFileNameWithoutExtension(fileName)).Count() <= 0;
|
||||
}).Select(fileName =>
|
||||
{
|
||||
// Copy calibration prints from StaticData to the filesystem before importing into the library
|
||||
|
|
@ -230,11 +231,12 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
public override void AddCollectionToLibrary(string collectionName)
|
||||
{
|
||||
PrintItemCollection newCollection = new PrintItemCollection(collectionName, "");
|
||||
newCollection.ParentCollectionID = collectionBase.Id;
|
||||
newCollection.ParentCollectionID = baseLibraryCollection.Id;
|
||||
newCollection.Commit();
|
||||
LoadLibraryItems();
|
||||
}
|
||||
|
||||
public override void AddFilesToLibrary(IList<string> files, List<ProviderLocatorNode> providerSavePath = null, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null)
|
||||
public override void AddFilesToLibrary(IList<string> files, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null)
|
||||
{
|
||||
if (files != null && files.Count > 0)
|
||||
{
|
||||
|
|
@ -251,11 +253,25 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
loadFilesIntoLibraryBackgroundWorker.RunWorkerAsync(files);
|
||||
}
|
||||
|
||||
if (baseLibraryCollection != null)
|
||||
{
|
||||
LoadLibraryItems();
|
||||
LibraryProvider.OnDataReloaded(null);
|
||||
}
|
||||
}
|
||||
|
||||
public override void AddItem(PrintItemWrapper itemToAdd)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
LibraryProvider.OnDataReloaded(null);
|
||||
}
|
||||
|
||||
void SetProviderLocator(PrintItemWrapper itemToSetProviderLocatorOn)
|
||||
{
|
||||
List<ProviderLocatorNode> providerLocator = GetProviderLocator();
|
||||
string providerLocatorJson = JsonConvert.SerializeObject(providerLocator);
|
||||
itemToSetProviderLocatorOn.PrintItem.LibraryProviderLocatorJson = providerLocatorJson;
|
||||
}
|
||||
|
||||
public void AddItem(PrintItemWrapper item, int indexToInsert = -1)
|
||||
|
|
@ -264,14 +280,15 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
indexToInsert = printItems.Count;
|
||||
}
|
||||
SetProviderLocator(item);
|
||||
printItems.Insert(indexToInsert, item);
|
||||
// Check if the collection we are adding to is the the currently visible collection.
|
||||
List<ProviderLocatorNode> currentDisplayedCollection = LibraryProvider.Instance.GetProviderLocator();
|
||||
if (currentDisplayedCollection.Count > 0 && currentDisplayedCollection[1].Key == LibraryProviderSQLite.StaticProviderKey)
|
||||
List<ProviderLocatorNode> currentDisplayedCollection = GetProviderLocator();
|
||||
if (currentDisplayedCollection.Count > 0 && currentDisplayedCollection[0].Key == LibraryProviderSQLite.StaticProviderKey)
|
||||
{
|
||||
OnItemAdded(new IndexArgs(indexToInsert));
|
||||
}
|
||||
item.PrintItem.PrintItemCollectionID = GetRootLibraryCollection().Id;
|
||||
item.PrintItem.PrintItemCollectionID = baseLibraryCollection.Id;
|
||||
item.PrintItem.Commit();
|
||||
}
|
||||
|
||||
|
|
@ -280,18 +297,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
return childCollections[collectionIndex];
|
||||
}
|
||||
|
||||
public override PrintItemCollection GetParentCollectionItem()
|
||||
{
|
||||
if (parentProviderKey != null)
|
||||
{
|
||||
return new PrintItemCollection("..", parentProviderKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override PrintItemWrapper GetPrintItemWrapper(int index)
|
||||
{
|
||||
if (index >= 0 && index < printItems.Count)
|
||||
|
|
@ -302,9 +307,9 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
return null;
|
||||
}
|
||||
|
||||
public override List<ProviderLocatorNode> GetProviderLocator()
|
||||
public override LibraryProvider GetProviderForItem(PrintItemCollection collection)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return new LibraryProviderSQLite(collection, this);
|
||||
}
|
||||
|
||||
public void LoadLibraryItems()
|
||||
|
|
@ -315,17 +320,28 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
foreach (PrintItem part in partFiles)
|
||||
{
|
||||
printItems.Add(new PrintItemWrapper(part));
|
||||
PrintItemWrapper item = new PrintItemWrapper(part);
|
||||
SetProviderLocator(item);
|
||||
printItems.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
childCollections.Clear();
|
||||
childCollections.AddRange(GetChildCollections());
|
||||
GetChildCollections();
|
||||
IEnumerable<PrintItemCollection> collections = GetChildCollections();
|
||||
if(collections != null)
|
||||
{
|
||||
childCollections.AddRange(collections);
|
||||
}
|
||||
|
||||
LibraryProvider.OnDataReloaded(null);
|
||||
}
|
||||
|
||||
public override void RemoveCollection(string collectionName)
|
||||
public override void RemoveCollection(PrintItemCollection collectionToRemove)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
collectionToRemove.Delete();
|
||||
LoadLibraryItems();
|
||||
LibraryProvider.OnDataReloaded(null);
|
||||
}
|
||||
|
||||
public override void RemoveItem(PrintItemWrapper printItemWrapper)
|
||||
|
|
@ -342,6 +358,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
// and remove it from the data base
|
||||
printItemWrapper.Delete();
|
||||
|
||||
LoadLibraryItems();
|
||||
OnItemRemoved(new IndexArgs(index));
|
||||
}
|
||||
|
||||
|
|
@ -350,25 +367,12 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void SetCollectionBase(PrintItemCollection collectionBase)
|
||||
{
|
||||
this.collectionBase = collectionBase;
|
||||
|
||||
LoadLibraryItems();
|
||||
}
|
||||
|
||||
public void SetParentKey(string parentKey)
|
||||
{
|
||||
this.parentProviderKey = parentKey;
|
||||
UiThread.RunOnIdle(() => LibraryProvider.OnDataReloaded(null));
|
||||
}
|
||||
|
||||
private static void AddStlOrGcode(string loadedFileName, string extension)
|
||||
private static void AddStlOrGcode(LibraryProviderSQLite libraryToAddTo, string loadedFileName, string extension)
|
||||
{
|
||||
PrintItem printItem = new PrintItem();
|
||||
printItem.Name = Path.GetFileNameWithoutExtension(loadedFileName);
|
||||
printItem.FileLocation = Path.GetFullPath(loadedFileName);
|
||||
printItem.PrintItemCollectionID = GetRootLibraryCollection().Id;
|
||||
printItem.PrintItemCollectionID = libraryToAddTo.baseLibraryCollection.Id;
|
||||
printItem.Commit();
|
||||
|
||||
if (MeshFileIo.ValidFileExtensions().Contains(extension))
|
||||
|
|
@ -379,7 +383,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
|
||||
SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave, false);
|
||||
Instance.AddItem(printItemWrapper);
|
||||
libraryToAddTo.AddItem(printItemWrapper);
|
||||
}
|
||||
catch (System.UnauthorizedAccessException)
|
||||
{
|
||||
|
|
@ -402,7 +406,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
|
||||
if (false)
|
||||
{
|
||||
Instance.AddItem(printItemWrapper);
|
||||
libraryToAddTo.AddItem(printItemWrapper);
|
||||
}
|
||||
else // save a copy to the library and update this to point at it
|
||||
{
|
||||
|
|
@ -416,42 +420,31 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
printItemWrapper.PrintItem.Commit();
|
||||
|
||||
// let the queue know that the item has changed so it load the correct part
|
||||
Instance.AddItem(printItemWrapper);
|
||||
libraryToAddTo.AddItem(printItemWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<PrintItemCollection> GetChildCollections()
|
||||
{
|
||||
if (collectionBase != null)
|
||||
{
|
||||
string query;
|
||||
query = string.Format("SELECT * FROM PrintItemCollection WHERE ParentCollectionID = {0} ORDER BY Name ASC;", collectionBase.Id);
|
||||
IEnumerable<PrintItemCollection> result = (IEnumerable<PrintItemCollection>)Datastore.Instance.dbSQLite.Query<PrintItemCollection>(query);
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
string query = string.Format("SELECT * FROM PrintItemCollection WHERE ParentCollectionID = {0} ORDER BY Name ASC;", baseLibraryCollection.Id);
|
||||
IEnumerable<PrintItemCollection> result = (IEnumerable<PrintItemCollection>)Datastore.Instance.dbSQLite.Query<PrintItemCollection>(query);
|
||||
return result;
|
||||
}
|
||||
|
||||
private IEnumerable<PrintItem> GetLibraryItems(string keyphrase = null)
|
||||
{
|
||||
if (collectionBase != null)
|
||||
string query;
|
||||
if (keyphrase == null)
|
||||
{
|
||||
string query;
|
||||
if (keyphrase == null)
|
||||
{
|
||||
query = string.Format("SELECT * FROM PrintItem WHERE PrintItemCollectionID = {0} ORDER BY Name ASC;", collectionBase.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
query = string.Format("SELECT * FROM PrintItem WHERE PrintItemCollectionID = {0} AND Name LIKE '%{1}%' ORDER BY Name ASC;", collectionBase.Id, keyphrase);
|
||||
}
|
||||
IEnumerable<PrintItem> result = (IEnumerable<PrintItem>)Datastore.Instance.dbSQLite.Query<PrintItem>(query);
|
||||
return result;
|
||||
query = string.Format("SELECT * FROM PrintItem WHERE PrintItemCollectionID = {0} ORDER BY Name ASC;", baseLibraryCollection.Id);
|
||||
}
|
||||
|
||||
return null;
|
||||
else
|
||||
{
|
||||
query = string.Format("SELECT * FROM PrintItem WHERE PrintItemCollectionID = {0} AND Name LIKE '%{1}%' ORDER BY Name ASC;", baseLibraryCollection.Id, keyphrase);
|
||||
}
|
||||
IEnumerable<PrintItem> result = (IEnumerable<PrintItem>)Datastore.Instance.dbSQLite.Query<PrintItem>(query);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void loadFilesIntoLibraryBackgoundWorker_DoWork(object sender, DoWorkEventArgs e)
|
||||
|
|
@ -472,13 +465,13 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
{
|
||||
foreach (PrintItem part in partFiles)
|
||||
{
|
||||
AddStlOrGcode(part.FileLocation, Path.GetExtension(part.FileLocation).ToUpper());
|
||||
AddStlOrGcode(this, part.FileLocation, Path.GetExtension(part.FileLocation).ToUpper());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddStlOrGcode(loadedFileName, extension);
|
||||
AddStlOrGcode(this, loadedFileName, extension);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
}
|
||||
PrintItems.Insert(indexToInsert, item);
|
||||
// Check if the collection we are adding to is the the currently visible collection.
|
||||
List<ProviderLocatorNode> currentDisplayedCollection = LibraryProvider.Instance.GetProviderLocator();
|
||||
List<ProviderLocatorNode> currentDisplayedCollection = LibraryProviderSQLite.Instance.GetProviderLocator();
|
||||
if (currentDisplayedCollection.Count > 0 && currentDisplayedCollection[1].Key == LibraryProviderSQLite.StaticProviderKey)
|
||||
{
|
||||
OnItemAdded(new IndexArgs(indexToInsert));
|
||||
|
|
|
|||
|
|
@ -460,7 +460,7 @@ namespace MatterHackers.MatterControl.PrintQueue
|
|||
{
|
||||
foreach (QueueRowItem queueItem in queueDataView.SelectedItems)
|
||||
{
|
||||
LibraryProvider.Instance.AddItem(queueItem.PrintItemWrapper);
|
||||
LibraryDataView.CurrentLibraryProvider.AddItem(queueItem.PrintItemWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ makeit.name="MakeIt"
|
|||
ramps.name="RAMPS"
|
||||
ftdi.name="FTDI"
|
||||
flashforge.name="Flashforge"
|
||||
dremel.name="Dremel 3D Printer"
|
||||
|
||||
[DefaultInstall]
|
||||
CopyINF=arduino.inf
|
||||
|
|
@ -98,6 +99,8 @@ DefaultDestDir=12
|
|||
%ramps.name%=DriverInstall, USB\VID_1A86&PID_7523
|
||||
%ftdi.name%=DriverInstall, USB\VID_0403&PID_6001
|
||||
%flashforge.name%=DriverInstall, USB\VID_23C1&PID_D314&REV_0001
|
||||
%dremel.name%=DriverInstall, USB\VID_2A89&PID_8889&REV_0200
|
||||
%dremel.name%=DriverInstall, USB\VID_2A89&PID_8889
|
||||
|
||||
[DeviceList.NTamd64]
|
||||
%due.bossa.name%=DriverInstall, USB\VID_03EB&PID_6124
|
||||
|
|
@ -138,6 +141,7 @@ DefaultDestDir=12
|
|||
%ramps.name%=DriverInstall, USB\VID_1A86&PID_7523
|
||||
%ftdi.name%=DriverInstall, USB\VID_0403&PID_6001
|
||||
%flashforge.name%=DriverInstall, USB\VID_23C1&PID_D314&REV_0001
|
||||
%dremel.name%=DriverInstall, USB\VID_2A89&PID_8889
|
||||
|
||||
[DeviceList.NTia64]
|
||||
%esplora.bootloader.name%=DriverInstall, USB\VID_2341&PID_003C
|
||||
|
|
@ -175,6 +179,7 @@ DefaultDestDir=12
|
|||
%ramps.name%=DriverInstall, USB\VID_1A86&PID_7523
|
||||
%ftdi.name%=DriverInstall, USB\VID_0403&PID_6001
|
||||
%flashforge.name%=DriverInstall, USB\VID_23C1&PID_D314&REV_0001
|
||||
%dremel.name%=DriverInstall, USB\VID_2A89&PID_8889
|
||||
|
||||
[DriverInstall]
|
||||
include=mdmcpq.inf,usb.inf
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 343 B |
Binary file not shown.
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 505 B |
BIN
StaticData/Icons/credit_card_32x32.png
Normal file
BIN
StaticData/Icons/credit_card_32x32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 233 B |
|
|
@ -57,6 +57,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="MatterControl\MatterControl.UI.cs" />
|
||||
<Compile Include="MatterControl\HtmlParser.cs" />
|
||||
<Compile Include="MatterControl\LibraryProviderTests.cs" />
|
||||
<Compile Include="MatterControl\ReleaseBuildTests.cs" />
|
||||
<Compile Include="MatterControl\Slicing\SliceMappingCLassesTets.cs" />
|
||||
<Compile Include="MatterControl\Slicing\SliceLayersTests.cs" />
|
||||
|
|
|
|||
241
Tests/MatterControl.Tests/MatterControl/LibraryProviderTests.cs
Normal file
241
Tests/MatterControl.Tests/MatterControl/LibraryProviderTests.cs
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
Copyright (c) 2015, Lars Brubaker
|
||||
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.MatterControl;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using MatterHackers.MatterControl.PrintLibrary.Provider;
|
||||
using MatterHackers.MatterControl.PrintQueue;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
using System.IO;
|
||||
using MatterHackers.Agg.PlatformAbstract;
|
||||
using System.Threading;
|
||||
|
||||
namespace MatterControl.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class LibraryProviderTests
|
||||
{
|
||||
string pathToMesh = Path.Combine("..", "..", "..", "TestData", "TestMeshes", "LibraryProviderData");
|
||||
string meshFileName = "Box20x20x10.stl";
|
||||
string meshPathAndFileName;
|
||||
|
||||
bool dataReloaded = false;
|
||||
bool itemAdded = false;
|
||||
bool itemRemoved = false;
|
||||
private event EventHandler unregisterEvents;
|
||||
|
||||
public LibraryProviderTests()
|
||||
{
|
||||
#if !__ANDROID__
|
||||
// Set the static data to point to the directory of MatterControl
|
||||
StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine("..", "..", "..", ".."));
|
||||
#endif
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetupBeforeTest()
|
||||
{
|
||||
meshPathAndFileName = Path.Combine(pathToMesh, meshFileName);
|
||||
|
||||
dataReloaded = false;
|
||||
itemAdded = false;
|
||||
itemRemoved = false;
|
||||
|
||||
LibraryProvider.DataReloaded.RegisterEvent((sender, e) => { dataReloaded = true; }, ref unregisterEvents);
|
||||
LibraryProvider.ItemAdded.RegisterEvent((sender, e) => { itemAdded = true; }, ref unregisterEvents);
|
||||
LibraryProvider.ItemRemoved.RegisterEvent((sender, e) => { itemRemoved = true; }, ref unregisterEvents);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TeardownAfterTest()
|
||||
{
|
||||
unregisterEvents(this, null);
|
||||
}
|
||||
|
||||
[Test, Category("LibraryProviderFileSystem")]
|
||||
public void LibraryProviderFileSystem_NavigationWorking()
|
||||
{
|
||||
Datastore.Instance.Initialize();
|
||||
Thread.Sleep(3000); // wait for the library to finish initializing
|
||||
|
||||
LibraryProviderFileSystem testProvider = new LibraryProviderFileSystem(pathToMesh, "TestPath", null);
|
||||
Assert.IsTrue(testProvider.CollectionCount == 0, "Start with a new database for these tests.");
|
||||
Assert.IsTrue(testProvider.ItemCount == 1, "Start with a new database for these tests.");
|
||||
|
||||
// create a collection and make sure it is on disk
|
||||
dataReloaded = false; // it has been loaded for the default set of parts
|
||||
string collectionName = "Collection1";
|
||||
string createdDirectory = Path.Combine(pathToMesh, collectionName);
|
||||
Assert.IsTrue(!Directory.Exists(createdDirectory));
|
||||
Assert.IsTrue(dataReloaded == false);
|
||||
testProvider.AddCollectionToLibrary(collectionName);
|
||||
Assert.IsTrue(testProvider.CollectionCount == 1);
|
||||
Assert.IsTrue(dataReloaded == true);
|
||||
Assert.IsTrue(Directory.Exists(createdDirectory));
|
||||
|
||||
PrintItemWrapper itemAtRoot = testProvider.GetPrintItemWrapper(0);
|
||||
List<ProviderLocatorNode> providerLocator = itemAtRoot.PrintItem.GetLibraryProviderLocator();
|
||||
Assert.IsTrue(providerLocator.Count == 1);
|
||||
|
||||
// add an item works correctly
|
||||
LibraryProvider subProvider = testProvider.GetProviderForItem(testProvider.GetCollectionItem(0));
|
||||
dataReloaded = false;
|
||||
itemAdded = false;
|
||||
string subPathAndFile = Path.Combine(createdDirectory, meshFileName);
|
||||
Assert.IsTrue(!File.Exists(subPathAndFile));
|
||||
Assert.IsTrue(dataReloaded == false);
|
||||
Assert.IsTrue(itemAdded == false);
|
||||
|
||||
// WIP: saving the name incorectly for this location (does not need to be changed).
|
||||
subProvider.AddFilesToLibrary(new string[] { meshPathAndFileName });
|
||||
Thread.Sleep(3000); // wait for the add to finihs
|
||||
|
||||
Assert.IsTrue(subProvider.ItemCount == 1);
|
||||
Assert.IsTrue(dataReloaded == true);
|
||||
Assert.IsTrue(itemAdded == true);
|
||||
Assert.IsTrue(File.Exists(subPathAndFile));
|
||||
|
||||
// make sure the provider locator is correct
|
||||
|
||||
// remove item works
|
||||
dataReloaded = false;
|
||||
Assert.IsTrue(dataReloaded == false);
|
||||
Assert.IsTrue(itemRemoved == false);
|
||||
subProvider.RemoveItem(subProvider.GetPrintItemWrapper(0));
|
||||
Assert.IsTrue(dataReloaded == true);
|
||||
Assert.IsTrue(itemRemoved == true);
|
||||
Assert.IsTrue(!File.Exists(subPathAndFile));
|
||||
|
||||
// remove collection gets rid of it
|
||||
dataReloaded = false;
|
||||
Assert.IsTrue(dataReloaded == false);
|
||||
testProvider.RemoveCollection(testProvider.GetCollectionItem(0));
|
||||
Assert.IsTrue(dataReloaded == true);
|
||||
Assert.IsTrue(testProvider.CollectionCount == 0);
|
||||
Assert.IsTrue(!Directory.Exists(createdDirectory));
|
||||
}
|
||||
|
||||
private bool NamedCollectionExists(string nameToLookFor)
|
||||
{
|
||||
string query = string.Format("SELECT * FROM PrintItemCollection WHERE Name = '{0}' ORDER BY Name ASC;", nameToLookFor);
|
||||
IEnumerable<PrintItemCollection> result = (IEnumerable<PrintItemCollection>)Datastore.Instance.dbSQLite.Query<PrintItemCollection>(query);
|
||||
foreach (PrintItemCollection collection in result)
|
||||
{
|
||||
if (collection.Name == nameToLookFor)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool NamedItemExists(string nameToLookFor)
|
||||
{
|
||||
string query = string.Format("SELECT * FROM PrintItem WHERE Name = '{0}' ORDER BY Name ASC;", nameToLookFor);
|
||||
IEnumerable<PrintItem> result = (IEnumerable<PrintItem>)Datastore.Instance.dbSQLite.Query<PrintItem>(query);
|
||||
foreach (PrintItem collection in result)
|
||||
{
|
||||
if (collection.Name == nameToLookFor)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
[Test, Category("LibraryProviderSqlite")]
|
||||
public void LibraryProviderSqlite_NavigationWorking()
|
||||
{
|
||||
Datastore.Instance.Initialize();
|
||||
LibraryProviderSQLite testProvider = new LibraryProviderSQLite(null, null);
|
||||
Thread.Sleep(3000); // wait for the library to finish initializing
|
||||
Assert.IsTrue(testProvider.CollectionCount == 0, "Start with a new database for these tests.");
|
||||
Assert.IsTrue(testProvider.ItemCount == 1, "Start with a new database for these tests.");
|
||||
|
||||
// create a collection and make sure it is on disk
|
||||
dataReloaded = false; // it has been loaded for the default set of parts
|
||||
string collectionName = "Collection1";
|
||||
Assert.IsTrue(!NamedCollectionExists(collectionName)); // assert that the record does not exist in the DB
|
||||
Assert.IsTrue(dataReloaded == false);
|
||||
testProvider.AddCollectionToLibrary(collectionName);
|
||||
Assert.IsTrue(testProvider.CollectionCount == 1);
|
||||
Assert.IsTrue(dataReloaded == true);
|
||||
Assert.IsTrue(NamedCollectionExists(collectionName)); // assert that the record does exist in the DB
|
||||
|
||||
PrintItemWrapper itemAtRoot = testProvider.GetPrintItemWrapper(0);
|
||||
List<ProviderLocatorNode> providerLocator = itemAtRoot.PrintItem.GetLibraryProviderLocator();
|
||||
Assert.IsTrue(providerLocator.Count == 1);
|
||||
|
||||
// add an item works correctly
|
||||
dataReloaded = false;
|
||||
itemAdded = false;
|
||||
Assert.IsTrue(!NamedItemExists(collectionName));
|
||||
Assert.IsTrue(dataReloaded == false);
|
||||
Assert.IsTrue(itemAdded == false);
|
||||
|
||||
testProvider.AddFilesToLibrary(new string[] { meshPathAndFileName });
|
||||
Thread.Sleep(3000); // wait for the add to finihs
|
||||
|
||||
Assert.IsTrue(testProvider.ItemCount == 2);
|
||||
Assert.IsTrue(dataReloaded == true);
|
||||
Assert.IsTrue(itemAdded == true);
|
||||
string fileNameWithExtension = Path.GetFileNameWithoutExtension(meshPathAndFileName);
|
||||
Assert.IsTrue(NamedItemExists(fileNameWithExtension));
|
||||
|
||||
// make sure the provider locator is correct
|
||||
|
||||
// remove item works
|
||||
dataReloaded = false;
|
||||
Assert.IsTrue(dataReloaded == false);
|
||||
Assert.IsTrue(itemRemoved == false);
|
||||
testProvider.RemoveItem(testProvider.GetPrintItemWrapper(1));
|
||||
Assert.IsTrue(dataReloaded == true);
|
||||
Assert.IsTrue(itemRemoved == true);
|
||||
Assert.IsTrue(!NamedItemExists(fileNameWithExtension));
|
||||
|
||||
// remove collection gets rid of it
|
||||
dataReloaded = false;
|
||||
Assert.IsTrue(dataReloaded == false);
|
||||
testProvider.RemoveCollection(testProvider.GetCollectionItem(0));
|
||||
Assert.IsTrue(dataReloaded == true);
|
||||
Assert.IsTrue(testProvider.CollectionCount == 0);
|
||||
Assert.IsTrue(!NamedCollectionExists(collectionName)); // assert that the record does not exist in the DB
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
Tests/TestData/TestMeshes/LibraryProviderData/Box20x20x10.stl
Normal file
BIN
Tests/TestData/TestMeshes/LibraryProviderData/Box20x20x10.stl
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue