diff --git a/DataStorage/Models.cs b/DataStorage/Models.cs index a564df070..c5287c50e 100644 --- a/DataStorage/Models.cs +++ b/DataStorage/Models.cs @@ -177,6 +177,14 @@ namespace MatterHackers.MatterControl.DataStorage public class PrintItemCollection : Entity { + public PrintItemCollection() + { } + + public PrintItemCollection(string name, string id) + { + this.Name = name; + } + public string Name { get; set; } } diff --git a/MatterControl.csproj b/MatterControl.csproj index 8c33d9e95..241b39e4b 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -205,6 +205,8 @@ + + diff --git a/PrintLibrary/LibraryDataView.cs b/PrintLibrary/LibraryDataView.cs index b52007cfb..5f1013213 100644 --- a/PrintLibrary/LibraryDataView.cs +++ b/PrintLibrary/LibraryDataView.cs @@ -33,6 +33,7 @@ using MatterHackers.Agg.UI; using MatterHackers.MatterControl.PrintQueue; using MatterHackers.VectorMath; using System; +using MatterHackers.MatterControl.DataStorage; namespace MatterHackers.MatterControl.PrintLibrary { @@ -188,21 +189,9 @@ namespace MatterHackers.MatterControl.PrintLibrary AutoScroll = true; topToBottomItemList = new FlowLayoutWidget(FlowDirection.TopToBottom); topToBottomItemList.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; - base.AddChild(topToBottomItemList); + AddChild(topToBottomItemList); - for (int i = 0; i < LibraryProvider.CurrentProvider.CollectionCount; i++) - { - PrintItemWrapper item = LibraryProvider.CurrentProvider.GetCollectionItemWrapper(i); - LibraryRowItem queueItem = new LibraryRowItem(item, this); - AddChild(queueItem); - } - - for (int i = 0; i < LibraryProvider.CurrentProvider.ItemCount; i++) - { - PrintItemWrapper item = LibraryProvider.CurrentProvider.GetPrintItemWrapper(i); - LibraryRowItem queueItem = new LibraryRowItem(item, this); - AddChild(queueItem); - } + AddAllItems(); this.MouseLeaveBounds += new EventHandler(control_MouseLeaveBounds); LibraryProvider.DataReloaded.RegisterEvent(LibraryDataReloaded, ref unregisterEvents); @@ -210,17 +199,31 @@ namespace MatterHackers.MatterControl.PrintLibrary LibraryProvider.ItemRemoved.RegisterEvent(ItemRemovedFromToLibrary, ref unregisterEvents); } - private void LibraryDataReloaded(object sender, EventArgs e) + private void AddAllItems() { - this.RemoveListItems(); + topToBottomItemList.RemoveAllChildren(); + + for (int i = 0; i < LibraryProvider.CurrentProvider.CollectionCount; i++) + { + PrintItemCollection item = LibraryProvider.CurrentProvider.GetCollectionItem(i); + LibraryRowItem queueItem = new LibraryRowItemCollection(item, this); + AddListItemToTopToBottom(queueItem); + } + for (int i = 0; i < LibraryProvider.CurrentProvider.ItemCount; i++) { PrintItemWrapper item = LibraryProvider.CurrentProvider.GetPrintItemWrapper(i); - LibraryRowItem queueItem = new LibraryRowItem(item, this); - AddChild(queueItem); + 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) @@ -234,8 +237,8 @@ namespace MatterHackers.MatterControl.PrintLibrary { IndexArgs addedIndexArgs = e as IndexArgs; PrintItemWrapper item = LibraryProvider.CurrentProvider.GetPrintItemWrapper(addedIndexArgs.Index); - LibraryRowItem libraryItem = new LibraryRowItem(item, this); - AddChild(libraryItem, addedIndexArgs.Index); + LibraryRowItem libraryItem = new LibraryRowItemPart(item, this); + AddListItemToTopToBottom(libraryItem, addedIndexArgs.Index); } private void ItemRemovedFromToLibrary(object sender, EventArgs e) @@ -249,10 +252,10 @@ namespace MatterHackers.MatterControl.PrintLibrary } } - public override void AddChild(GuiWidget child, int indexInChildrenList = -1) + public void AddListItemToTopToBottom(GuiWidget child, int indexInChildrenList = -1) { FlowLayoutWidget itemHolder = new FlowLayoutWidget(); - itemHolder.Name = "LB item holder"; + itemHolder.Name = "list item holder"; itemHolder.Margin = new BorderDouble(0, 0, 0, 0); itemHolder.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; itemHolder.AddChild(child); @@ -305,7 +308,7 @@ namespace MatterHackers.MatterControl.PrintLibrary { foreach (LibraryRowItem item in SelectedItems) { - LibraryProvider.CurrentProvider.RemoveItem(item.printItemWrapper); + item.RemoveFromParentCollection(); } } @@ -326,11 +329,6 @@ namespace MatterHackers.MatterControl.PrintLibrary } } - public void RemoveListItems() - { - topToBottomItemList.RemoveAllChildren(); - } - private void itemHolder_ParentChanged(object sender, EventArgs e) { FlowLayoutWidget itemHolder = (FlowLayoutWidget)sender; diff --git a/PrintLibrary/LibraryRowItem.cs b/PrintLibrary/LibraryRowItem.cs index 72b7c5445..105526b6c 100644 --- a/PrintLibrary/LibraryRowItem.cs +++ b/PrintLibrary/LibraryRowItem.cs @@ -41,24 +41,20 @@ using System.IO; namespace MatterHackers.MatterControl.PrintLibrary { - public class LibraryRowItem : GuiWidget + public abstract class LibraryRowItem : GuiWidget { - public PrintItemWrapper printItemWrapper; public RGBA_Bytes WidgetTextColor; public RGBA_Bytes WidgetBackgroundColor; - public bool isActivePrint = false; public bool isSelectedItem = false; private bool isHoverItem = false; - private TextWidget partLabel; + protected TextWidget partLabel; public CheckBox selectionCheckBox; private LinkButtonFactory linkButtonFactory = new LinkButtonFactory(); - private bool viewWindowIsOpen = false; - private PartPreviewMainWindow viewingWindow; - private LibraryDataView libraryDataView; - private SlideWidget rightButtonOverlay; - private GuiWidget selectionCheckBoxContainer; + protected LibraryDataView libraryDataView; + protected SlideWidget rightButtonOverlay; + protected GuiWidget selectionCheckBoxContainer; private bool editMode = false; public bool EditMode @@ -93,10 +89,13 @@ namespace MatterHackers.MatterControl.PrintLibrary } } - public LibraryRowItem(PrintItemWrapper printItem, LibraryDataView libraryDataView) + public LibraryRowItem(LibraryDataView libraryDataView) { this.libraryDataView = libraryDataView; - this.printItemWrapper = printItem; + } + + protected void CreateGuiElements() + { this.Cursor = Cursors.Hand; linkButtonFactory.fontSize = 10; @@ -121,8 +120,6 @@ namespace MatterHackers.MatterControl.PrintLibrary primaryFlow.HAnchor = HAnchor.ParentLeftRight; primaryFlow.VAnchor = VAnchor.ParentBottomTop; - PartThumbnailWidget thumbnailWidget = new PartThumbnailWidget(printItem, "part_icon_transparent_40x40.png", "building_thumbnail_40x40.png", PartThumbnailWidget.ImageSizes.Size50x50); - selectionCheckBoxContainer = new GuiWidget(); selectionCheckBoxContainer.VAnchor = VAnchor.ParentBottomTop; selectionCheckBoxContainer.Width = 40; @@ -138,7 +135,7 @@ namespace MatterHackers.MatterControl.PrintLibrary middleColumn.VAnchor = Agg.UI.VAnchor.ParentBottomTop; middleColumn.Margin = new BorderDouble(10, 6); { - string labelName = textInfo.ToTitleCase(printItem.Name); + string labelName = textInfo.ToTitleCase(GetItemName()); labelName = labelName.Replace('_', ' '); partLabel = new TextWidget(labelName, pointSize: 14); partLabel.TextColor = WidgetTextColor; @@ -147,7 +144,9 @@ namespace MatterHackers.MatterControl.PrintLibrary middleColumn.AddChild(partLabel); } primaryFlow.AddChild(selectionCheckBoxContainer); - primaryFlow.AddChild(thumbnailWidget); + + + primaryFlow.AddChild(GetThumbnailWidget()); primaryFlow.AddChild(middleColumn); primaryContainer.AddChild(primaryFlow); @@ -169,60 +168,13 @@ namespace MatterHackers.MatterControl.PrintLibrary AddHandlers(); } + protected abstract string GetItemName(); + + protected abstract GuiWidget GetThumbnailWidget(); + private ConditionalClickWidget primaryClickContainer; - private SlideWidget getItemActionButtons() - { - SlideWidget buttonContainer = new SlideWidget(); - buttonContainer.VAnchor = VAnchor.ParentBottomTop; - - FlowLayoutWidget buttonFlowContainer = new FlowLayoutWidget(FlowDirection.LeftToRight); - buttonFlowContainer.VAnchor = VAnchor.ParentBottomTop; - - TextWidget printLabel = new TextWidget("Print".Localize()); - printLabel.TextColor = RGBA_Bytes.White; - printLabel.VAnchor = VAnchor.ParentCenter; - printLabel.HAnchor = HAnchor.ParentCenter; - - FatFlatClickWidget printButton = new FatFlatClickWidget(printLabel); - printButton.VAnchor = VAnchor.ParentBottomTop; - printButton.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; - printButton.Width = 100; - printButton.Click += (sender, e) => - { - if (!PrinterCommunication.PrinterConnectionAndCommunication.Instance.PrintIsActive) - { - QueueData.Instance.AddItem(this.printItemWrapper, 0); - QueueData.Instance.SelectedIndex = QueueData.Instance.Count - 1; - PrinterCommunication.PrinterConnectionAndCommunication.Instance.PrintActivePartIfPossible(); - } - else - { - QueueData.Instance.AddItem(this.printItemWrapper); - } - buttonContainer.SlideOut(); - this.Invalidate(); - }; ; - - TextWidget viewButtonLabel = new TextWidget("View".Localize()); - viewButtonLabel.TextColor = RGBA_Bytes.White; - viewButtonLabel.VAnchor = VAnchor.ParentCenter; - viewButtonLabel.HAnchor = HAnchor.ParentCenter; - - FatFlatClickWidget viewButton = new FatFlatClickWidget(viewButtonLabel); - viewButton.VAnchor = VAnchor.ParentBottomTop; - viewButton.BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor; - viewButton.Width = 100; - viewButton.Click += onViewPartClick; - - buttonFlowContainer.AddChild(viewButton); - buttonFlowContainer.AddChild(printButton); - - buttonContainer.AddChild(buttonFlowContainer); - buttonContainer.Width = 200; - - return buttonContainer; - } + protected abstract SlideWidget getItemActionButtons(); private void SetDisplayAttributes() { @@ -318,65 +270,7 @@ namespace MatterHackers.MatterControl.PrintLibrary { } - private void RemoveThisFromPrintLibrary() - { - LibraryProvider.CurrentProvider.RemoveItem(this.printItemWrapper); - } - - private void onRemoveLinkClick(object sender, EventArgs e) - { - UiThread.RunOnIdle(RemoveThisFromPrintLibrary); - } - - private void onOpenPartViewClick(object sender, EventArgs e) - { - UiThread.RunOnIdle(() => openPartView()); - } - - 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 (viewWindowIsOpen == false) - { - viewingWindow = new PartPreviewMainWindow(this.printItemWrapper, View3DWidget.AutoRotate.Enabled, openMode); - this.viewWindowIsOpen = true; - viewingWindow.Closed += new EventHandler(PartPreviewMainWindow_Closed); - } - else - { - if (viewingWindow != null) - { - viewingWindow.BringToFront(); - } - } - } - - private void PartPreviewMainWindow_Closed(object sender, EventArgs e) - { - viewWindowIsOpen = false; - } - - 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); - } - } + protected abstract void RemoveThisFromPrintLibrary(); private void onConfirmRemove(bool messageBoxResponse) { @@ -430,5 +324,15 @@ namespace MatterHackers.MatterControl.PrintLibrary this.selectionCheckBox.TextColor = RGBA_Bytes.Black; } } + + public abstract void RemoveFromParentCollection(); + + public abstract void AddToQueue(); + + public abstract void RemoveFromCollection(); + + public abstract void Edit(); + + public abstract void Export(); } } \ No newline at end of file diff --git a/PrintLibrary/LibraryRowItemCollection.cs b/PrintLibrary/LibraryRowItemCollection.cs new file mode 100644 index 000000000..a4a4b5647 --- /dev/null +++ b/PrintLibrary/LibraryRowItemCollection.cs @@ -0,0 +1,161 @@ +/* +Copyright (c) 2014, Kevin Pope +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. +*/ + +using MatterHackers.Agg; +using MatterHackers.Agg.UI; +using MatterHackers.Agg.VertexSource; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.PrintLibrary.Provider; +using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.VectorMath; +using System; +using System.Globalization; +using System.IO; + +namespace MatterHackers.MatterControl.PrintLibrary +{ + public class LibraryRowItemCollection : LibraryRowItem + { + PrintItemCollection collection; + + public LibraryRowItemCollection(PrintItemCollection collection, LibraryDataView libraryDataView) + : base(libraryDataView) + { + this.collection = collection; + CreateGuiElements(); + } + + public override void Export() + { + throw new NotImplementedException(); + } + + public override void Edit() + { + throw new NotImplementedException(); + } + + public override void RemoveFromCollection() + { + throw new NotImplementedException(); + } + + public override void AddToQueue() + { + throw new NotImplementedException(); + } + + public override void RemoveFromParentCollection() + { + throw new NotImplementedException(); + } + + private ConditionalClickWidget primaryClickContainer; + + protected override GuiWidget GetThumbnailWidget() + { + PartThumbnailWidget thumbnailWidget = new PartThumbnailWidget(null, "part_icon_transparent_40x40.png", "building_thumbnail_40x40.png", PartThumbnailWidget.ImageSizes.Size50x50); + return thumbnailWidget; + } + + protected override string GetItemName() + { + return collection.Name; + } + + protected override SlideWidget getItemActionButtons() + { + SlideWidget buttonContainer = new SlideWidget(); + buttonContainer.VAnchor = VAnchor.ParentBottomTop; + + FlowLayoutWidget buttonFlowContainer = new FlowLayoutWidget(FlowDirection.LeftToRight); + buttonFlowContainer.VAnchor = VAnchor.ParentBottomTop; + + TextWidget openLabel = new TextWidget("Open".Localize()); + openLabel.TextColor = RGBA_Bytes.White; + openLabel.VAnchor = VAnchor.ParentCenter; + openLabel.HAnchor = HAnchor.ParentCenter; + + FatFlatClickWidget openButton = new FatFlatClickWidget(openLabel); + openButton.VAnchor = VAnchor.ParentBottomTop; + openButton.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; + openButton.Width = 100; + openButton.Click += (sender, e) => + { + throw new NotImplementedException(); + }; + + buttonFlowContainer.AddChild(openButton); + + buttonContainer.AddChild(buttonFlowContainer); + buttonContainer.Width = 200; + + return buttonContainer; + } + + private void SetDisplayAttributes() + { + //this.VAnchor = Agg.UI.VAnchor.FitToChildren; + this.HAnchor = Agg.UI.HAnchor.ParentLeftRight; + if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + { + this.Height = 65; + } + else + { + this.Height = 50; + } + + this.Padding = new BorderDouble(0); + this.Margin = new BorderDouble(6, 0, 6, 6); + } + + private void onAddLinkClick(object sender, EventArgs e) + { + } + + protected override void RemoveThisFromPrintLibrary() + { + throw new NotImplementedException(); + } + + 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(); + } + } +} \ No newline at end of file diff --git a/PrintLibrary/LibraryRowItemPart.cs b/PrintLibrary/LibraryRowItemPart.cs new file mode 100644 index 000000000..41b1916fa --- /dev/null +++ b/PrintLibrary/LibraryRowItemPart.cs @@ -0,0 +1,355 @@ +/* +Copyright (c) 2014, Kevin Pope +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. +*/ + +using MatterHackers.Agg; +using MatterHackers.Agg.UI; +using MatterHackers.Agg.VertexSource; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.PrintLibrary.Provider; +using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.VectorMath; +using System; +using System.Globalization; +using System.IO; + +namespace MatterHackers.MatterControl.PrintLibrary +{ + public class LibraryRowItemPart : LibraryRowItem + { + public PrintItemWrapper printItemWrapper; + + private ExportPrintItemWindow exportingWindow; + + public bool isActivePrint = false; + + private PartPreviewMainWindow viewingWindow; + + public LibraryRowItemPart(PrintItemWrapper printItem, LibraryDataView libraryDataView) + : base(libraryDataView) + { + this.printItemWrapper = printItem; + CreateGuiElements(); + } + + private ConditionalClickWidget primaryClickContainer; + + protected override SlideWidget getItemActionButtons() + { + SlideWidget buttonContainer = new SlideWidget(); + buttonContainer.VAnchor = VAnchor.ParentBottomTop; + + FlowLayoutWidget buttonFlowContainer = new FlowLayoutWidget(FlowDirection.LeftToRight); + buttonFlowContainer.VAnchor = VAnchor.ParentBottomTop; + + TextWidget printLabel = new TextWidget("Print".Localize()); + printLabel.TextColor = RGBA_Bytes.White; + printLabel.VAnchor = VAnchor.ParentCenter; + printLabel.HAnchor = HAnchor.ParentCenter; + + FatFlatClickWidget printButton = new FatFlatClickWidget(printLabel); + printButton.VAnchor = VAnchor.ParentBottomTop; + printButton.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; + printButton.Width = 100; + printButton.Click += (sender, e) => + { + if (!PrinterCommunication.PrinterConnectionAndCommunication.Instance.PrintIsActive) + { + QueueData.Instance.AddItem(this.printItemWrapper, 0); + QueueData.Instance.SelectedIndex = QueueData.Instance.Count - 1; + PrinterCommunication.PrinterConnectionAndCommunication.Instance.PrintActivePartIfPossible(); + } + else + { + QueueData.Instance.AddItem(this.printItemWrapper); + } + buttonContainer.SlideOut(); + this.Invalidate(); + }; ; + + TextWidget viewButtonLabel = new TextWidget("View".Localize()); + viewButtonLabel.TextColor = RGBA_Bytes.White; + viewButtonLabel.VAnchor = VAnchor.ParentCenter; + viewButtonLabel.HAnchor = HAnchor.ParentCenter; + + FatFlatClickWidget viewButton = new FatFlatClickWidget(viewButtonLabel); + viewButton.VAnchor = VAnchor.ParentBottomTop; + viewButton.BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor; + viewButton.Width = 100; + viewButton.Click += onViewPartClick; + + buttonFlowContainer.AddChild(viewButton); + buttonFlowContainer.AddChild(printButton); + + buttonContainer.AddChild(buttonFlowContainer); + buttonContainer.Width = 200; + + return buttonContainer; + } + + private void ExportQueueItemWindow_Closed(object sender, EventArgs e) + { + exportingWindow = null; + } + + private void OpenExportWindow() + { + if (exportingWindow == null) + { + exportingWindow = new ExportPrintItemWindow(this.printItemWrapper); + exportingWindow.Closed += new EventHandler(ExportQueueItemWindow_Closed); + exportingWindow.ShowAsSystemWindow(); + } + else + { + exportingWindow.BringToFront(); + } + } + + private void OpenExportWindow(PrintItemWrapper printItem) + { + if (exportingWindow == null) + { + exportingWindow = new ExportPrintItemWindow(printItem); + exportingWindow.Closed += new EventHandler(ExportQueueItemWindow_Closed); + exportingWindow.ShowAsSystemWindow(); + } + else + { + exportingWindow.BringToFront(); + } + } + + private void SetDisplayAttributes() + { + //this.VAnchor = Agg.UI.VAnchor.FitToChildren; + this.HAnchor = Agg.UI.HAnchor.ParentLeftRight; + if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + { + this.Height = 65; + } + else + { + this.Height = 50; + } + + this.Padding = new BorderDouble(0); + this.Margin = new BorderDouble(6, 0, 6, 6); + } + + public override void RemoveFromParentCollection() + { + LibraryProvider.CurrentProvider.RemoveItem(printItemWrapper); + } + + public override void Export() + { + OpenExportWindow(printItemWrapper); + } + + public override void Edit() + { + OpenPartViewWindow(PartPreviewWindow.View3DWidget.OpenMode.Editing); + } + + public override void RemoveFromCollection() + { + LibraryProvider.CurrentProvider.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); + } + } + } + + private void selectionCheckBox_CheckedStateChanged(object sender, EventArgs e) + { + if (selectionCheckBox.Checked == true) + { + this.isSelectedItem = true; + libraryDataView.SelectedItems.Add(this); + } + else + { + this.isSelectedItem = false; + libraryDataView.SelectedItems.Remove(this); + } + } + + private void onAddLinkClick(object sender, EventArgs e) + { + } + + 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.CurrentProvider.RemoveItem(this.printItemWrapper); + } + + private void onRemoveLinkClick(object sender, EventArgs e) + { + UiThread.RunOnIdle(RemoveThisFromPrintLibrary); + } + + private void onOpenPartViewClick(object sender, EventArgs e) + { + UiThread.RunOnIdle(() => openPartView()); + } + + 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); + } + 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; + } + + 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; + } + } + } +} \ No newline at end of file diff --git a/PrintLibrary/PrintLibraryWidget.cs b/PrintLibrary/PrintLibraryWidget.cs index dad71c13a..ad530cd8e 100644 --- a/PrintLibrary/PrintLibraryWidget.cs +++ b/PrintLibrary/PrintLibraryWidget.cs @@ -245,7 +245,7 @@ namespace MatterHackers.MatterControl.PrintLibrary { foreach (LibraryRowItem item in libraryDataView.SelectedItems) { - QueueData.Instance.AddItem(item.printItemWrapper); + item.AddToQueue(); } libraryDataView.ClearSelectedItems(); } @@ -290,7 +290,7 @@ namespace MatterHackers.MatterControl.PrintLibrary { foreach (LibraryRowItem item in libraryDataView.SelectedItems) { - LibraryProvider.CurrentProvider.RemoveItem(item.printItemWrapper); + item.RemoveFromCollection(); } libraryDataView.ClearSelectedItems(); @@ -305,7 +305,7 @@ namespace MatterHackers.MatterControl.PrintLibrary if (libraryDataView.SelectedItems.Count == 1) { LibraryRowItem libraryItem = libraryDataView.SelectedItems[0]; - OpenExportWindow(libraryItem.printItemWrapper); + libraryItem.Export(); } } @@ -315,25 +315,7 @@ namespace MatterHackers.MatterControl.PrintLibrary if (libraryDataView.SelectedItems.Count == 1) { LibraryRowItem libraryItem = libraryDataView.SelectedItems[0]; - libraryItem.OpenPartViewWindow(PartPreviewWindow.View3DWidget.OpenMode.Editing); - } - } - - private void OpenExportWindow(PrintItemWrapper printItem) - { - if (exportingWindowIsOpen == false) - { - exportingWindow = new ExportPrintItemWindow(printItem); - this.exportingWindowIsOpen = true; - exportingWindow.Closed += new EventHandler(ExportQueueItemWindow_Closed); - exportingWindow.ShowAsSystemWindow(); - } - else - { - if (exportingWindow != null) - { - exportingWindow.BringToFront(); - } + libraryItem.Edit(); } } diff --git a/PrintLibrary/Provider/LibraryProvider.cs b/PrintLibrary/Provider/LibraryProvider.cs index ece925436..0509bcbe4 100644 --- a/PrintLibrary/Provider/LibraryProvider.cs +++ b/PrintLibrary/Provider/LibraryProvider.cs @@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project. */ using MatterHackers.Agg; +using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrintQueue; using System; using System.Collections.Generic; @@ -70,7 +71,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public abstract void AddFilesToLibrary(IList files, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null); - public abstract PrintItemWrapper GetCollectionItemWrapper(int collectionIndex); + public abstract PrintItemCollection GetCollectionItem(int collectionIndex); public abstract PrintItemWrapper GetPrintItemWrapper(int itemIndex); diff --git a/PrintLibrary/Provider/LibraryProviderFileSystem.cs b/PrintLibrary/Provider/LibraryProviderFileSystem.cs index 41f60a1b0..dd756f503 100644 --- a/PrintLibrary/Provider/LibraryProviderFileSystem.cs +++ b/PrintLibrary/Provider/LibraryProviderFileSystem.cs @@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project. */ using MatterHackers.Agg; +using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrintQueue; using System; using System.Collections.Generic; @@ -95,10 +96,10 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider throw new NotImplementedException(); } - public override PrintItemWrapper GetCollectionItemWrapper(int collectionIndex) + public override PrintItemCollection GetCollectionItem(int collectionIndex) { string directoryName = currentDirectoryDirectories[collectionIndex]; - return new PrintItemWrapper(new DataStorage.PrintItem("", directoryName)); + return new PrintItemCollection(Path.GetFileNameWithoutExtension(directoryName), directoryName); } public override PrintItemWrapper GetPrintItemWrapper(int itemIndex) diff --git a/PrintLibrary/Provider/LibraryProviderSqlite.cs b/PrintLibrary/Provider/LibraryProviderSqlite.cs index bd9df59f7..b3d23f2d0 100644 --- a/PrintLibrary/Provider/LibraryProviderSqlite.cs +++ b/PrintLibrary/Provider/LibraryProviderSqlite.cs @@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project. */ using MatterHackers.Agg; +using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrintQueue; using System; using System.Collections.Generic; @@ -81,7 +82,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider return LibrarySQLiteData.Instance.GetPrintItemWrapper(itemIndex); } - public override PrintItemWrapper GetCollectionItemWrapper(int collectionIndex) + public override PrintItemCollection GetCollectionItem(int collectionIndex) { throw new NotImplementedException(); } diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 1270424e7..374e753c0 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -3316,3 +3316,6 @@ Translated:Location: 'Settings & Controls' -> 'Settings' -> 'Filament' -> 'Filam English:Location: 'Settings & Controls' -> 'Settings' -> 'Filament' -> 'Extrusion' -> 'Frist Layer' Translated:Location: 'Settings & Controls' -> 'Settings' -> 'Filament' -> 'Extrusion' -> 'Frist Layer' +English:Open +Translated:Open +