diff --git a/AboutPage/AboutPage.cs b/AboutPage/AboutPage.cs index db158e129..e9d8f7327 100644 --- a/AboutPage/AboutPage.cs +++ b/AboutPage/AboutPage.cs @@ -186,15 +186,15 @@ namespace MatterHackers.MatterControl } static string applicationDataPath = DataStorage.ApplicationDataStorage.Instance.ApplicationUserDataPath; - static string updateFileLocation = System.IO.Path.Combine(applicationDataPath, "updates"); + static string updateFileLocation = Path.Combine(applicationDataPath, "updates"); public void InstallUpdate(object sender, MouseEventArgs e) { string downloadToken = ApplicationSettings.Instance.get("CurrentBuildToken"); - string updateFileName = System.IO.Path.Combine(updateFileLocation, "{0}.{1}".FormatWith(downloadToken, InstallerExtension)); + string updateFileName = Path.Combine(updateFileLocation, "{0}.{1}".FormatWith(downloadToken, InstallerExtension)); string releaseVersion = ApplicationSettings.Instance.get("CurrentReleaseVersion"); - string friendlyFileName = System.IO.Path.Combine(updateFileLocation, "MatterControlSetup-{0}.{1}".FormatWith(releaseVersion, InstallerExtension)); + string friendlyFileName = Path.Combine(updateFileLocation, "MatterControlSetup-{0}.{1}".FormatWith(releaseVersion, InstallerExtension)); if (System.IO.File.Exists(friendlyFileName)) { @@ -274,7 +274,7 @@ namespace MatterHackers.MatterControl System.IO.Directory.CreateDirectory(updateFileLocation); } - string updateFileName = System.IO.Path.Combine(updateFileLocation, string.Format("{0}.{1}", downloadToken, InstallerExtension)); + string updateFileName = Path.Combine(updateFileLocation, string.Format("{0}.{1}", downloadToken, InstallerExtension)); WebClient webClient = new WebClient(); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompleted); @@ -307,7 +307,7 @@ namespace MatterHackers.MatterControl void CheckVersionStatus() { string currentBuildToken = ApplicationSettings.Instance.get("CurrentBuildToken"); - string updateFileName = System.IO.Path.Combine(updateFileLocation, string.Format("{0}.{1}", currentBuildToken, InstallerExtension)); + string updateFileName = Path.Combine(updateFileLocation, string.Format("{0}.{1}", currentBuildToken, InstallerExtension)); string applicationBuildToken = VersionInfo.Instance.BuildToken; @@ -335,7 +335,7 @@ namespace MatterHackers.MatterControl { this.updateInitiated = false; string currentBuildToken = ApplicationSettings.Instance.get("CurrentBuildToken"); - string updateFileName = System.IO.Path.Combine(updateFileLocation, string.Format("{0}.{1}", currentBuildToken, InstallerExtension)); + string updateFileName = Path.Combine(updateFileLocation, string.Format("{0}.{1}", currentBuildToken, InstallerExtension)); string applicationBuildToken = VersionInfo.Instance.BuildToken; diff --git a/ActionBar/ActionBarBaseControls.cs b/ActionBar/ActionBarBaseControls.cs index f0c8d7fa9..03506d6eb 100644 --- a/ActionBar/ActionBarBaseControls.cs +++ b/ActionBar/ActionBarBaseControls.cs @@ -48,7 +48,6 @@ namespace MatterHackers.MatterControl.ActionBar } } - //Base widget for use in ButtonViewStates public class ControlButtonViewBase : GuiWidget { diff --git a/ActionBar/ActionBarPlus.cs b/ActionBar/ActionBarPlus.cs index 3ab9cd104..ac8be6ba1 100644 --- a/ActionBar/ActionBarPlus.cs +++ b/ActionBar/ActionBarPlus.cs @@ -19,9 +19,12 @@ namespace MatterHackers.MatterControl { public class ActionBarPlus : FlowLayoutWidget { - public ActionBarPlus() + QueueDataView queueDataView; + + public ActionBarPlus(QueueDataView queueDataView) : base(FlowDirection.TopToBottom) - { + { + this.queueDataView = queueDataView; this.Create(); } @@ -42,7 +45,7 @@ namespace MatterHackers.MatterControl // Add Child Elements this.AddChild(new ActionBar.PrinterActionRow()); - this.AddChild(new PrintStatusRow()); + this.AddChild(new PrintStatusRow(queueDataView)); // Add Handlers ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); diff --git a/ActionBar/PrintActionRow.cs b/ActionBar/PrintActionRow.cs index acb7fe894..2c4a4134b 100644 --- a/ActionBar/PrintActionRow.cs +++ b/ActionBar/PrintActionRow.cs @@ -1,19 +1,12 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Diagnostics; using System.IO; -using System.Threading; - -using MatterHackers.Agg.Image; using MatterHackers.Agg; using MatterHackers.Agg.UI; -using MatterHackers.VectorMath; - -using MatterHackers.MatterControl; -using MatterHackers.MatterControl.PrintQueue; using MatterHackers.Localizations; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.PrintQueue; using MatterHackers.MatterControl.SlicerConfiguration; namespace MatterHackers.MatterControl.ActionBar @@ -42,6 +35,13 @@ namespace MatterHackers.MatterControl.ActionBar TooltipButton reprintButton; TooltipButton doneWithCurrentPartButton; + QueueDataView queueDataView; + + public PrintActionRow(QueueDataView queueDataView) + { + this.queueDataView = queueDataView; + } + protected override void Initialize() { textImageButtonFactory.normalTextColor = RGBA_Bytes.White; @@ -177,14 +177,9 @@ namespace MatterHackers.MatterControl.ActionBar { foreach (string loadedFileName in openParams.FileNames) { - PrintQueueItem queueItem = new PrintQueueItem(System.IO.Path.GetFileNameWithoutExtension(loadedFileName), System.IO.Path.GetFullPath(loadedFileName)); - PrintQueueControl.Instance.AddChild(queueItem); + QueueData.Instance.AddItem(new PrintItem(Path.GetFileNameWithoutExtension(loadedFileName), Path.GetFullPath(loadedFileName))); } - - PrintQueueControl.Instance.EnsureSelection(); - PrintQueueControl.Instance.Invalidate(); } - PrintQueueControl.Instance.SaveDefaultQueue(); } void partToPrint_SliceDone(object sender, EventArgs e) @@ -267,7 +262,7 @@ namespace MatterHackers.MatterControl.ActionBar string message = String.Format(removeFromQueueMessage, pathAndFile); if (StyledMessageBox.ShowMessageBox(message, itemNotFoundMessage, StyledMessageBox.MessageType.YES_NO)) { - PrintQueueControl.Instance.RemoveIndex(PrintQueueControl.Instance.SelectedIndex); + QueueData.Instance.RemoveAt(queueDataView.SelectedIndex); } } } @@ -280,9 +275,9 @@ namespace MatterHackers.MatterControl.ActionBar void onSkipButton_Click(object sender, MouseEventArgs mouseEvent) { - if (PrintQueueControl.Instance.Count > 1) + if (QueueData.Instance.Count > 1) { - PrintQueueControl.Instance.MoveToNext(); + queueDataView.MoveToNext(); } } @@ -296,8 +291,7 @@ namespace MatterHackers.MatterControl.ActionBar void onRemoveButton_Click(object sender, MouseEventArgs mouseEvent) { - PrintQueueControl.Instance.RemoveIndex(PrintQueueControl.Instance.SelectedIndex); - PrintQueueControl.Instance.SaveDefaultQueue(); + QueueData.Instance.RemoveAt(queueDataView.SelectedIndex); } void onPauseButton_Click(object sender, MouseEventArgs mouseEvent) @@ -333,8 +327,7 @@ namespace MatterHackers.MatterControl.ActionBar void onDoneWithCurrentPartButton_Click(object sender, MouseEventArgs mouseEvent) { PrinterCommunication.Instance.ResetToReadyState(); - PrintQueueControl.Instance.RemoveIndex(PrintQueueControl.Instance.SelectedIndex); - PrintQueueControl.Instance.SaveDefaultQueue(); + QueueData.Instance.RemoveAt(queueDataView.SelectedIndex); // We don't have to change the selected index because we should be on the next one as we deleted the one // we were on. } @@ -412,7 +405,7 @@ namespace MatterHackers.MatterControl.ActionBar this.activePrintButtons.Add(startButton); //Show 'skip' button if there are more items in queue - if (PrintQueueControl.Instance.Count > 1) + if (QueueData.Instance.Count > 1) { this.activePrintButtons.Add(skipButton); } diff --git a/ActionBar/PrintStatusRow.cs b/ActionBar/PrintStatusRow.cs index 8731df79e..ebb630839 100644 --- a/ActionBar/PrintStatusRow.cs +++ b/ActionBar/PrintStatusRow.cs @@ -1,24 +1,42 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Globalization; -using System.Diagnostics; -using System.Threading; -using System.IO; +/* +Copyright (c) 2014, Kevin Pope +All rights reserved. -using MatterHackers.Agg.Image; +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 System; +using System.Diagnostics; +using System.Globalization; +using System.IO; using MatterHackers.Agg; using MatterHackers.Agg.UI; -using MatterHackers.VectorMath; using MatterHackers.Agg.VertexSource; -using MatterHackers.MatterControl; -using MatterHackers.MatterControl.DataStorage; +using MatterHackers.Localizations; using MatterHackers.MatterControl.PrintQueue; - -using MatterHackers.PolygonMesh; - -using MatterHackers.Localizations; +using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.ActionBar { @@ -33,6 +51,14 @@ namespace MatterHackers.MatterControl.ActionBar TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; TextWidget activePrintStatus; + + QueueDataView queueDataView; + + public PrintStatusRow(QueueDataView queueDataView) + { + this.queueDataView = queueDataView; + } + string ActivePrintStatusText { set @@ -95,7 +121,7 @@ namespace MatterHackers.MatterControl.ActionBar temperatureWidgets.VAnchor |= VAnchor.ParentTop; temperatureWidgets.Margin = new BorderDouble(left: 6); - FlowLayoutWidget printStatusContainer = getActivePrinterInfo(); + FlowLayoutWidget printStatusContainer = CreateActivePrinterInfoWidget(); printStatusContainer.VAnchor |= VAnchor.ParentTop; FlowLayoutWidget iconContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); @@ -140,7 +166,7 @@ namespace MatterHackers.MatterControl.ActionBar return notifyButton; } - private FlowLayoutWidget getActivePrinterInfo() + private FlowLayoutWidget CreateActivePrinterInfoWidget() { FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom); container.Margin = new BorderDouble(6, 0,6,3); @@ -168,7 +194,7 @@ namespace MatterHackers.MatterControl.ActionBar activePrintInfo = getPrintStatusLabel("", pointSize: 11); activePrintInfo.AutoExpandBoundsToText = true; - PrintActionRow printActionRow = new PrintActionRow(); + PrintActionRow printActionRow = new PrintActionRow(queueDataView); container.AddChild(topRow); container.AddChild(activePrintName); diff --git a/ApplicationView/CompactSlidePanel.cs b/ApplicationView/CompactSlidePanel.cs index 84c77ffef..ac1c7e796 100644 --- a/ApplicationView/CompactSlidePanel.cs +++ b/ApplicationView/CompactSlidePanel.cs @@ -44,7 +44,6 @@ using MatterHackers.MatterControl; using MatterHackers.MatterControl.PrintQueue; using MatterHackers.MatterControl.PrintLibrary; using MatterHackers.MatterControl.SlicerConfiguration; -using MatterHackers.MatterControl.ToolsPage; using MatterHackers.MatterControl.DataStorage; using MatterHackers.Localizations; @@ -63,6 +62,8 @@ namespace MatterHackers.MatterControl RGBA_Bytes unselectedTextColor = ActiveTheme.Instance.TabLabelUnselected; public EventHandler AdvancedControlsLoaded; + QueueDataView queueDataView; + GuiWidget LeftPanel { get { return GetPannel(0); } @@ -73,9 +74,10 @@ namespace MatterHackers.MatterControl get { return GetPannel(1); } } - public CompactSlidePanel() + public CompactSlidePanel(QueueDataView queueDataView) : base(2) { + this.queueDataView = queueDataView; AddElements(); } @@ -89,7 +91,7 @@ namespace MatterHackers.MatterControl this.LeftPanel.AddChild(new PrintProgressBar()); // construct the main controls tab control - mainControlsTabControl = new QueueTab(); + mainControlsTabControl = new QueueTab(queueDataView); advancedControlsButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor; advancedControlsButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor; diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index 109182731..a59fab65e 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -44,7 +44,6 @@ using MatterHackers.MatterControl; using MatterHackers.MatterControl.PrintQueue; using MatterHackers.MatterControl.PrintLibrary; using MatterHackers.MatterControl.SlicerConfiguration; -using MatterHackers.MatterControl.ToolsPage; using MatterHackers.MatterControl.DataStorage; using MatterHackers.Localizations; diff --git a/ApplicationView/QueueTabs.cs b/ApplicationView/QueueTabs.cs index 31bb65bda..1887ce8c5 100644 --- a/ApplicationView/QueueTabs.cs +++ b/ApplicationView/QueueTabs.cs @@ -53,7 +53,6 @@ namespace MatterHackers.MatterControl { class QueueTab : TabControl { - TabPage QueueTabPage; TabPage LibraryTabPage; TabPage HistoryTabPage; @@ -61,9 +60,11 @@ namespace MatterHackers.MatterControl SimpleTextTabWidget AboutTabView; RGBA_Bytes unselectedTextColor = ActiveTheme.Instance.TabLabelUnselected; GuiWidget addedUpdateMark = null; + QueueDataView queueDataView; - public QueueTab() + public QueueTab(QueueDataView queueDataView) { + this.queueDataView = queueDataView; this.TabBar.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; this.TabBar.BorderColor = new RGBA_Bytes(0, 0, 0, 0); this.TabBar.Margin = new BorderDouble(0, 0); @@ -71,7 +72,7 @@ namespace MatterHackers.MatterControl this.Margin = new BorderDouble(top: 4); - QueueTabPage = new TabPage(new QueueControlsWidget(), LocalizedString.Get("Queue").ToUpper()); + QueueTabPage = new TabPage(new BottomToolbar(queueDataView), LocalizedString.Get("Queue").ToUpper()); this.AddTab(new SimpleTextTabWidget(QueueTabPage, 15, ActiveTheme.Instance.TabLabelSelected, new RGBA_Bytes(), unselectedTextColor, new RGBA_Bytes())); @@ -96,15 +97,15 @@ namespace MatterHackers.MatterControl void NumQueueItemsChanged(object sender, EventArgs widgetEvent) { string queueStringBeg = LocalizedString.Get("Queue").ToUpper(); - string queueString = string.Format("{1} ({0})", PrintQueue.PrintQueueControl.Instance.Count, queueStringBeg); - QueueTabPage.Text = string.Format(queueString, PrintQueue.PrintQueueControl.Instance.Count); + string queueString = string.Format("{1} ({0})", QueueData.Instance.Count, queueStringBeg); + QueueTabPage.Text = string.Format(queueString, QueueData.Instance.Count); } event EventHandler unregisterEvents; void AddHandlers() { - PrintQueue.PrintQueueControl.Instance.ItemAdded.RegisterEvent(NumQueueItemsChanged, ref unregisterEvents); - PrintQueue.PrintQueueControl.Instance.ItemRemoved.RegisterEvent(NumQueueItemsChanged, ref unregisterEvents); + QueueData.Instance.ItemAdded.RegisterEvent(NumQueueItemsChanged, ref unregisterEvents); + QueueData.Instance.ItemRemoved.RegisterEvent(NumQueueItemsChanged, ref unregisterEvents); ApplicationWidget.Instance.SetUpdateNotificationTrigger.RegisterEvent(SetUpdateNotification, ref unregisterEvents); } diff --git a/ApplicationView/WidescreenPanel.cs b/ApplicationView/WidescreenPanel.cs index 55bb9e82a..f0f7610c7 100644 --- a/ApplicationView/WidescreenPanel.cs +++ b/ApplicationView/WidescreenPanel.cs @@ -233,6 +233,28 @@ namespace MatterHackers.MatterControl LoadColumnTwo(); } + void LoadCompactView() + { + QueueDataView queueDataView = new QueueDataView(); + + ColumnOne.RemoveAllChildren(); + ColumnOne.AddChild(new ActionBarPlus(queueDataView)); + ColumnOne.AddChild(new CompactSlidePanel(queueDataView)); + ColumnOne.AnchorAll(); + } + + void LoadColumnOne() + { + QueueDataView queueDataView = new QueueDataView(); + + ColumnOne.RemoveAllChildren(); + ColumnOne.VAnchor = VAnchor.ParentBottomTop; + ColumnOne.AddChild(new ActionBarPlus(queueDataView)); + ColumnOne.AddChild(new PrintProgressBar()); + ColumnOne.AddChild(new QueueTab(queueDataView)); + ColumnOne.Width = 500; //Ordering here matters - must go after children are added + } + void LoadColumnTwo() { ColumnTwo.RemoveAllChildren(); @@ -251,30 +273,11 @@ namespace MatterHackers.MatterControl SetVisibleStatus(); } - void LoadColumnZero() - { - ColumnOne.RemoveAllChildren(); - ColumnOne.AddChild(new ActionBarPlus()); - ColumnOne.AddChild(new CompactSlidePanel()); - ColumnOne.AnchorAll(); - } - - void LoadColumnOne() - { - ColumnOne.RemoveAllChildren(); - ColumnOne.VAnchor = VAnchor.ParentBottomTop; - ColumnOne.AddChild(new ActionBarPlus()); - ColumnOne.AddChild(new PrintProgressBar()); - ColumnOne.AddChild(new QueueTab()); - ColumnOne.Width = 500; //Ordering here matters - must go after children are added - } - void LoadColumnThree() { advancedControlsTabControl = CreateNewAdvancedControlsTab(new SliceSettingsWidget.UiState()); ColumnThree.AddChild(advancedControlsTabControl); ColumnThree.Width = 590; //Ordering here matters - must go after children are added - } int UiState = -1; @@ -292,7 +295,7 @@ namespace MatterHackers.MatterControl UiState = 0; ApplicationWidget.Instance.WidescreenMode = false; - LoadColumnZero(); + LoadCompactView(); ColumnThree.Visible = false; ColumnTwo.Visible = false; diff --git a/CustomWidgets/ExportQueueItemWindow.cs b/CustomWidgets/ExportQueueItemWindow.cs index 21ddf2312..305fba145 100644 --- a/CustomWidgets/ExportQueueItemWindow.cs +++ b/CustomWidgets/ExportQueueItemWindow.cs @@ -18,11 +18,11 @@ namespace MatterHackers.MatterControl public class ExportQueueItemWindow : SystemWindow { CheckBox showInFolderAfterSave; - private PrintQueue.PrintQueueItem printQueueItem; + private PrintQueue.RowItem printQueueItem; string pathAndFilenameToSave; bool partIsGCode = false; - public ExportQueueItemWindow(PrintQueue.PrintQueueItem printQueueItem) + public ExportQueueItemWindow(PrintQueue.RowItem printQueueItem) : base(400, 250) { if (Path.GetExtension(printQueueItem.PrintItemWrapper.FileLocation).ToUpper() == ".GCODE") diff --git a/CustomWidgets/PartThumbnailWidget.cs b/CustomWidgets/PartThumbnailWidget.cs index e62eb7104..66067cc1f 100644 --- a/CustomWidgets/PartThumbnailWidget.cs +++ b/CustomWidgets/PartThumbnailWidget.cs @@ -218,7 +218,7 @@ namespace MatterHackers.MatterControl } else { - PrintQueueItem.ShowCantFindFileMessage(printItem); + RowItem.ShowCantFindFileMessage(printItem); } } } diff --git a/DataStorage/Datastore.cs b/DataStorage/Datastore.cs index c1f77815d..fb20393c9 100644 --- a/DataStorage/Datastore.cs +++ b/DataStorage/Datastore.cs @@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl.DataStorage { if (this.applicationPath == null) { - applicationPath = System.IO.Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly ().Location); + applicationPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); } return applicationPath; } @@ -149,7 +149,7 @@ namespace MatterHackers.MatterControl.DataStorage /// public string DatastorePath { - get { return System.IO.Path.Combine(ApplicationUserDataPath, datastoreName); } + get { return Path.Combine(ApplicationUserDataPath, datastoreName); } } public override string ToString() diff --git a/DataStorage/Models.cs b/DataStorage/Models.cs index 4418c9689..97ecec61f 100644 --- a/DataStorage/Models.cs +++ b/DataStorage/Models.cs @@ -1,4 +1,33 @@ -using System; +/* +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 System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/MatterControl.csproj b/MatterControl.csproj index 23bd5b7d7..efce3eead 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -89,6 +89,7 @@ + @@ -117,9 +118,6 @@ - - - @@ -150,7 +148,7 @@ - + @@ -178,14 +176,14 @@ - + - - + + - + diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index b37f6d709..8742aa37f 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -349,7 +349,7 @@ namespace MatterHackers.MatterControl public override void OnClosing(out bool CancelClose) { //Save a snapshot of the prints in queue - PrintQueueControl.Instance.SaveDefaultQueue(); + QueueData.Instance.SaveDefaultQueue(); if (PrinterCommunication.Instance.PrinterIsPrinting) { diff --git a/PartPreviewWindow/GcodeViewBasic.cs b/PartPreviewWindow/GcodeViewBasic.cs index f6f6130a4..9458ab730 100644 --- a/PartPreviewWindow/GcodeViewBasic.cs +++ b/PartPreviewWindow/GcodeViewBasic.cs @@ -28,26 +28,15 @@ either expressed or implied, of the FreeBSD Project. */ using System; -using System.IO; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; using System.ComponentModel; - +using System.IO; using MatterHackers.Agg; -using MatterHackers.Agg.Image; using MatterHackers.Agg.UI; -using MatterHackers.Agg.OpenGlGui; -using MatterHackers.MatterControl.SlicerConfiguration; -using MatterHackers.PolygonMesh; -using MatterHackers.RenderOpenGl; -using MatterHackers.VectorMath; using MatterHackers.GCodeVisualizer; -using MatterHackers.MatterControl.DataStorage; -using MatterHackers.MatterControl; -using MatterHackers.MatterControl.PrintQueue; using MatterHackers.Localizations; +using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.PartPreviewWindow { diff --git a/PartPreviewWindow/SaveAsWindow.cs b/PartPreviewWindow/SaveAsWindow.cs index 761006ace..713e7e241 100644 --- a/PartPreviewWindow/SaveAsWindow.cs +++ b/PartPreviewWindow/SaveAsWindow.cs @@ -113,16 +113,13 @@ namespace MatterHackers.MatterControl PrintItem printItem = new PrintItem(); printItem.Name = newName; - printItem.FileLocation = System.IO.Path.GetFullPath(fileNameAndPath); + printItem.FileLocation = Path.GetFullPath(fileNameAndPath); printItem.PrintItemCollectionID = PrintLibraryListControl.Instance.LibraryCollection.Id; printItem.Commit(); + QueueData.Instance.AddItem(printItem); + PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem); - - PrintQueueItem queueItem = new PrintQueueItem(printItemWrapper); - PrintQueueControl.Instance.AddChild(queueItem); - PrintQueueControl.Instance.SaveDefaultQueue(); - if (addToLibraryOption.Checked) { PrintLibraryListItem libraryItem = new PrintLibraryListItem(printItemWrapper); diff --git a/PartPreviewWindow/View3DTransfromPart.cs b/PartPreviewWindow/View3DTransfromPart.cs index c3c3da4d2..966c1a0f6 100644 --- a/PartPreviewWindow/View3DTransfromPart.cs +++ b/PartPreviewWindow/View3DTransfromPart.cs @@ -28,38 +28,23 @@ either expressed or implied, of the FreeBSD Project. */ using System; -using System.IO; -using System.ComponentModel; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.Globalization; +using System.IO; using System.Threading; - - using MatterHackers.Agg; -using MatterHackers.Agg.Image; using MatterHackers.Agg.UI; -using MatterHackers.Agg.OpenGlGui; -using MatterHackers.PolygonMesh; -using MatterHackers.RenderOpenGl; -using MatterHackers.VectorMath; -using MatterHackers.MeshVisualizer; -using MatterHackers.PolygonMesh.Processors; -using MatterHackers.PolygonMesh.Csg; -using MatterHackers.MarchingSquares; -using MatterHackers.MatterControl.DataStorage; -using MatterHackers.Agg.ImageProcessing; -using MatterHackers.Agg.VertexSource; -using MatterHackers.MatterControl; +using MatterHackers.Localizations; //Added Namespace using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.MeshVisualizer; +using MatterHackers.PolygonMesh; +using MatterHackers.PolygonMesh.Processors; using MatterHackers.RayTracer; using MatterHackers.RayTracer.Traceable; -using MatterHackers.Localizations; //Added Namespace - - -using ClipperLib; - -using OpenTK.Graphics.OpenGL; +using MatterHackers.RenderOpenGl; +using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.PartPreviewWindow { @@ -738,7 +723,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow int subLength = nextPercent - lastPercent; string loadedFileName = filesToLoad[i]; - Mesh copyMesh = StlProcessing.Load(System.IO.Path.GetFullPath(loadedFileName)); + Mesh copyMesh = StlProcessing.Load(Path.GetFullPath(loadedFileName)); if (copyMesh != null) { int halfNextPercent = (nextPercent - lastPercent) / 2; diff --git a/PrintHistory/PrintHistoryListItem.cs b/PrintHistory/PrintHistoryListItem.cs index 23210d660..90238191c 100644 --- a/PrintHistory/PrintHistoryListItem.cs +++ b/PrintHistory/PrintHistoryListItem.cs @@ -155,9 +155,7 @@ namespace MatterHackers.MatterControl.PrintHistory printAgainLink.Click += (sender, e) => { - PrintQueueItem queueItem = new PrintQueueItem(new PrintItemWrapper(printTask.PrintItemId)); - PrintQueueControl.Instance.AddChild(queueItem); - PrintQueueControl.Instance.SaveDefaultQueue(); + QueueData.Instance.AddItem(new PrintItemWrapper(printTask.PrintItemId).PrintItem); }; buttonContainer.AddChild(printAgainLink); diff --git a/PrintLibrary/ExportLibraryItemWindow.cs b/PrintLibrary/ExportLibraryItemWindow.cs index f521423be..ba9199a69 100644 --- a/PrintLibrary/ExportLibraryItemWindow.cs +++ b/PrintLibrary/ExportLibraryItemWindow.cs @@ -27,7 +27,7 @@ namespace MatterHackers.MatterControl.PrintLibrary public ExportLibraryItemWindow(PrintLibraryListItem printLibraryItem) : base(400, 250) { - if (System.IO.Path.GetExtension(printLibraryItem.printItem.FileLocation).ToUpper() == ".GCODE") + if (Path.GetExtension(printLibraryItem.printItem.FileLocation).ToUpper() == ".GCODE") { partIsGCode = true; } @@ -179,7 +179,7 @@ namespace MatterHackers.MatterControl.PrintLibrary filePathToSave += ".gcode"; } - if (System.IO.Path.GetExtension(printQueueItem.printItem.FileLocation).ToUpper() == ".STL") + if (Path.GetExtension(printQueueItem.printItem.FileLocation).ToUpper() == ".STL") { pathAndFilenameToSave = saveParams.FileName; Close(); diff --git a/PrintLibrary/PrintLibraryListControl.cs b/PrintLibrary/PrintLibraryListControl.cs index 974711f9c..9ecd9cb51 100644 --- a/PrintLibrary/PrintLibraryListControl.cs +++ b/PrintLibrary/PrintLibraryListControl.cs @@ -213,8 +213,8 @@ namespace MatterHackers.MatterControl.PrintLibrary if (System.IO.File.Exists(partFullPath)) { PrintItem printItem = new PrintItem(); - printItem.Name = System.IO.Path.GetFileNameWithoutExtension(partFullPath); - printItem.FileLocation = System.IO.Path.GetFullPath(partFullPath); + printItem.Name = Path.GetFileNameWithoutExtension(partFullPath); + printItem.FileLocation = Path.GetFullPath(partFullPath); printItem.PrintItemCollectionID = PrintLibraryListControl.Instance.LibraryCollection.Id; printItem.Commit(); } diff --git a/PrintLibrary/PrintLibraryListItem.cs b/PrintLibrary/PrintLibraryListItem.cs index d5a1db258..e559bde74 100644 --- a/PrintLibrary/PrintLibraryListItem.cs +++ b/PrintLibrary/PrintLibraryListItem.cs @@ -212,7 +212,7 @@ namespace MatterHackers.MatterControl.PrintLibrary } else { - PrintQueueItem.ShowCantFindFileMessage(printItem); + RowItem.ShowCantFindFileMessage(printItem); } } } @@ -364,9 +364,7 @@ namespace MatterHackers.MatterControl.PrintLibrary addToQueueLink.Click += (sender, e) => { - PrintQueueItem queueItem = new PrintQueueItem(this.printItem.Name, this.printItem.FileLocation); - PrintQueueControl.Instance.AddChild(queueItem); - PrintQueueControl.Instance.SaveDefaultQueue(); + QueueData.Instance.AddItem(new PrintItem(this.printItem.Name, this.printItem.FileLocation)); }; viewLink = linkButtonFactory.Generate(LocalizedString.Get("View")); diff --git a/PrintLibrary/PrintLibraryWidget.cs b/PrintLibrary/PrintLibraryWidget.cs index fe9e95eea..a802af755 100644 --- a/PrintLibrary/PrintLibraryWidget.cs +++ b/PrintLibrary/PrintLibraryWidget.cs @@ -154,12 +154,9 @@ namespace MatterHackers.MatterControl.PrintLibrary { foreach (PrintLibraryListItem item in PrintLibraryListControl.Instance.SelectedItems) { - PrintQueue.PrintQueueItem queueItem = new PrintQueue.PrintQueueItem(item.printItem); - PrintQueue.PrintQueueControl.Instance.AddChild(queueItem); + QueueData.Instance.AddItem(item.printItem.PrintItem); } PrintLibraryListControl.Instance.ClearSelectedItems(); - PrintQueue.PrintQueueControl.Instance.EnsureSelection(); - PrintQueueControl.Instance.SaveDefaultQueue(); } private void onLibraryItemsSelected(object sender, EventArgs e) @@ -223,8 +220,8 @@ namespace MatterHackers.MatterControl.PrintLibrary if (extension == ".STL" || extension == ".GCODE") { PrintItem printItem = new PrintItem(); - printItem.Name = System.IO.Path.GetFileNameWithoutExtension(droppedFileName); - printItem.FileLocation = System.IO.Path.GetFullPath(droppedFileName); + printItem.Name = Path.GetFileNameWithoutExtension(droppedFileName); + printItem.FileLocation = Path.GetFullPath(droppedFileName); printItem.PrintItemCollectionID = PrintLibraryListControl.Instance.LibraryCollection.Id; printItem.Commit(); @@ -247,8 +244,8 @@ namespace MatterHackers.MatterControl.PrintLibrary foreach (string loadedFileName in openParams.FileNames) { PrintItem printItem = new PrintItem(); - printItem.Name = System.IO.Path.GetFileNameWithoutExtension(loadedFileName); - printItem.FileLocation = System.IO.Path.GetFullPath(loadedFileName); + printItem.Name = Path.GetFileNameWithoutExtension(loadedFileName); + printItem.FileLocation = Path.GetFullPath(loadedFileName); printItem.PrintItemCollectionID = PrintLibraryListControl.Instance.LibraryCollection.Id; printItem.Commit(); diff --git a/PrintQueue/QueueControlsWidget.cs b/PrintQueue/BottomToolbar.cs similarity index 78% rename from PrintQueue/QueueControlsWidget.cs rename to PrintQueue/BottomToolbar.cs index 50e085e89..f67a25b37 100644 --- a/PrintQueue/QueueControlsWidget.cs +++ b/PrintQueue/BottomToolbar.cs @@ -18,13 +18,16 @@ using MatterHackers.MatterControl.CreatorPlugins; namespace MatterHackers.MatterControl.PrintQueue { - public class QueueControlsWidget : GuiWidget + public class BottomToolbar : GuiWidget { TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory(); PluginChooserWindow pluginChooserWindow; + QueueDataView queueDataView; - public QueueControlsWidget() + public BottomToolbar(QueueDataView queueDataView) { + this.queueDataView = queueDataView; + SetDisplayAttributes(); textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor; @@ -40,7 +43,7 @@ namespace MatterHackers.MatterControl.PrintQueue // Ensure the form opens with no rows selected. //ActiveQueueList.Instance.ClearSelected(); - allControls.AddChild(PrintQueueControl.Instance); + allControls.AddChild(queueDataView); } FlowLayoutWidget buttonPanel1 = new FlowLayoutWidget(); @@ -51,7 +54,7 @@ namespace MatterHackers.MatterControl.PrintQueue Button addToQueueButton = textImageButtonFactory.Generate(LocalizedString.Get("Add"), "icon_circle_plus.png"); buttonPanel1.AddChild(addToQueueButton); addToQueueButton.Margin = new BorderDouble(0, 0, 3, 0); - addToQueueButton.Click += new ButtonBase.ButtonEventHandler(loadFile_Click); + addToQueueButton.Click += new ButtonBase.ButtonEventHandler(addToQueueButton_Click); Button runCreator = textImageButtonFactory.Generate(LocalizedString.Get("Create"), "icon_creator_white_32x32.png"); buttonPanel1.AddChild(runCreator); @@ -74,7 +77,7 @@ namespace MatterHackers.MatterControl.PrintQueue spacer2.HAnchor = HAnchor.ParentLeftRight; buttonPanel1.AddChild(spacer2); - GuiWidget queueMenu = new PrintQueueMenu(); + GuiWidget queueMenu = new QueueOptionsMenu(); queueMenu.VAnchor = VAnchor.ParentTop; buttonPanel1.AddChild(queueMenu); } @@ -92,7 +95,6 @@ namespace MatterHackers.MatterControl.PrintQueue this.AnchorAll(); } - private void OpenPluginChooserWindow() { if (pluginChooserWindow == null) @@ -111,7 +113,7 @@ namespace MatterHackers.MatterControl.PrintQueue void createPartsSheetsButton_Click(object sender, MouseEventArgs mouseEvent) { - List parts = PrintQueueControl.Instance.CreateReadOnlyPartList(); + List parts = QueueData.Instance.CreateReadOnlyPartList(); SaveFileDialogParams saveParams = new SaveFileDialogParams("Save Parts Sheet|*.pdf"); @@ -137,7 +139,7 @@ namespace MatterHackers.MatterControl.PrintQueue void exportQueueButton_Click(object sender, MouseEventArgs mouseEvent) { - List partList = PrintQueueControl.Instance.CreateReadOnlyPartList(); + List partList = QueueData.Instance.CreateReadOnlyPartList(); ProjectFileHandler project = new ProjectFileHandler(partList); project.SaveAs(); } @@ -148,21 +150,17 @@ namespace MatterHackers.MatterControl.PrintQueue List partFiles = project.OpenFromDialog(); if (partFiles != null) { - PrintQueueControl.Instance.RemoveAllChildren(); + QueueData.Instance.RemoveAll(); foreach (PrintItem part in partFiles) { - PrintQueueControl.Instance.AddChild(new PrintQueueItem(part.Name, part.FileLocation)); + QueueData.Instance.AddItem(new PrintItem(part.Name, part.FileLocation)); } - PrintQueueControl.Instance.EnsureSelection(); - PrintQueueControl.Instance.Invalidate(); - PrintQueueControl.Instance.SaveDefaultQueue(); } } void deleteAllFromQueueButton_Click(object sender, MouseEventArgs mouseEvent) { - PrintQueueControl.Instance.RemoveAllChildren(); - PrintQueueControl.Instance.SaveDefaultQueue(); + QueueData.Instance.RemoveAll(); } public override void OnDragEnter(FileDropEventArgs fileDropEventArgs) @@ -198,23 +196,19 @@ namespace MatterHackers.MatterControl.PrintQueue string extension = Path.GetExtension(droppedFileName).ToUpper(); if (extension == ".STL" || extension == ".GCODE") { - PrintQueueItem queueItem = new PrintQueueItem(System.IO.Path.GetFileNameWithoutExtension(droppedFileName), System.IO.Path.GetFullPath(droppedFileName)); - PrintQueueControl.Instance.AddChild(queueItem); + QueueData.Instance.AddItem(new PrintItem(Path.GetFileNameWithoutExtension(droppedFileName), Path.GetFullPath(droppedFileName))); } - PrintQueueControl.Instance.EnsureSelection(); - PrintQueueControl.Instance.Invalidate(); } - PrintQueueControl.Instance.SaveDefaultQueue(); base.OnDragDrop(fileDropEventArgs); } - void loadFile_Click(object sender, MouseEventArgs mouseEvent) + void addToQueueButton_Click(object sender, MouseEventArgs mouseEvent) { - UiThread.RunOnIdle(LoadFileOnIdle); + UiThread.RunOnIdle(AddItemsToQueue); } - void LoadFileOnIdle(object state) + void AddItemsToQueue(object state) { OpenFileDialogParams openParams = new OpenFileDialogParams("Select an STL file, Select a GCODE file|*.stl;*.gcode", multiSelect: true); openParams.ActionButtonLabel = "Add to Queue"; @@ -225,17 +219,9 @@ namespace MatterHackers.MatterControl.PrintQueue { foreach (string loadedFileName in openParams.FileNames) { - PrintQueueItem queueItem = new PrintQueueItem(System.IO.Path.GetFileNameWithoutExtension(loadedFileName), System.IO.Path.GetFullPath(loadedFileName)); - PrintQueueControl.Instance.AddChild(queueItem); + QueueData.Instance.AddItem(new PrintItem(Path.GetFileNameWithoutExtension(loadedFileName), Path.GetFullPath(loadedFileName))); } - if (PrintQueueControl.Instance.Count > 0) - { - PrintQueueControl.Instance.SelectedIndex = PrintQueueControl.Instance.Count - 1; - } - //PrintQueueControl.Instance.EnsureSelection(); - PrintQueueControl.Instance.Invalidate(); } - PrintQueueControl.Instance.SaveDefaultQueue(); } } } diff --git a/PrintQueue/ExportToFolderProcess.cs b/PrintQueue/ExportToFolderProcess.cs index 601f3cfb3..1b8e6260b 100644 --- a/PrintQueue/ExportToFolderProcess.cs +++ b/PrintQueue/ExportToFolderProcess.cs @@ -61,7 +61,7 @@ namespace MatterHackers.MatterControl.PrintQueue public void Start() { - if (PrintQueueControl.Instance.Count > 0) + if (QueueData.Instance.Count > 0) { if (StartingNextPart != null) { @@ -69,17 +69,17 @@ namespace MatterHackers.MatterControl.PrintQueue } savedGCodeFileNames = new List(); - allFilesToExport = PrintQueueControl.Instance.CreateReadOnlyPartList(); + allFilesToExport = QueueData.Instance.CreateReadOnlyPartList(); foreach (PrintItem part in allFilesToExport) { PrintItemWrapper printItemWrapper = new PrintItemWrapper(part); - if (System.IO.Path.GetExtension(part.FileLocation).ToUpper() == ".STL") + if (Path.GetExtension(part.FileLocation).ToUpper() == ".STL") { SlicingQueue.Instance.QueuePartForSlicing(printItemWrapper); printItemWrapper.Done += new EventHandler(sliceItem_Done); printItemWrapper.SlicingOutputMessage += printItemWrapper_SlicingOutputMessage; } - else if (System.IO.Path.GetExtension(part.FileLocation).ToUpper() == ".GCODE") + else if (Path.GetExtension(part.FileLocation).ToUpper() == ".GCODE") { sliceItem_Done(printItemWrapper, null); } diff --git a/PrintQueue/PartsSheet.cs b/PrintQueue/PartsSheetCreator.cs similarity index 99% rename from PrintQueue/PartsSheet.cs rename to PrintQueue/PartsSheetCreator.cs index aa4f05e41..8db09e311 100644 --- a/PrintQueue/PartsSheet.cs +++ b/PrintQueue/PartsSheetCreator.cs @@ -334,7 +334,7 @@ namespace MatterHackers.MatterControl string applicationUserDataPath = ApplicationDataStorage.Instance.ApplicationUserDataPath; string folderToSavePrintsTo = Path.Combine(applicationUserDataPath, "data", "temp", "plateImages"); - string jpegFileName = System.IO.Path.Combine(folderToSavePrintsTo, plateNumber.ToString() + ".jpeg"); + string jpegFileName = Path.Combine(folderToSavePrintsTo, plateNumber.ToString() + ".jpeg"); if (!Directory.Exists(folderToSavePrintsTo)) { diff --git a/PrintQueue/PrintItemWrapper.cs b/PrintQueue/PrintItemWrapper.cs index 48e8b4c7b..90195d7e6 100644 --- a/PrintQueue/PrintItemWrapper.cs +++ b/PrintQueue/PrintItemWrapper.cs @@ -1,4 +1,33 @@ -using System; +/* +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 System; using System.IO; using System.Collections.Generic; using System.Linq; @@ -38,7 +67,7 @@ namespace MatterHackers.MatterControl.PrintQueue public PrintItemWrapper(DataStorage.PrintItem printItem) { this.PrintItem = printItem; - this.fileType = System.IO.Path.GetExtension(printItem.FileLocation).ToUpper(); + this.fileType = Path.GetExtension(printItem.FileLocation).ToUpper(); //if (this.fileType == ".GCODE") //{ //gcodeStatus = GcodeStatuses.Prepared; @@ -48,7 +77,7 @@ namespace MatterHackers.MatterControl.PrintQueue public PrintItemWrapper(int printItemId) { this.PrintItem = DataStorage.Datastore.Instance.dbSQLite.Table().Where(v => v.Id == printItemId).Take(1).FirstOrDefault(); - this.fileType = System.IO.Path.GetExtension(this.PrintItem.FileLocation).ToUpper(); + this.fileType = Path.GetExtension(this.PrintItem.FileLocation).ToUpper(); } bool doneSlicing; @@ -105,8 +134,6 @@ namespace MatterHackers.MatterControl.PrintQueue } } - - public void Delete() { PrintItem.Delete(); diff --git a/PrintQueue/QueueData.cs b/PrintQueue/QueueData.cs new file mode 100644 index 000000000..dff28571b --- /dev/null +++ b/PrintQueue/QueueData.cs @@ -0,0 +1,236 @@ +/* +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 System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; + +using MatterHackers.Agg.Image; +using MatterHackers.Agg; +using MatterHackers.Agg.UI; +using MatterHackers.VectorMath; +using MatterHackers.MatterControl; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.Agg.ImageProcessing; + +namespace MatterHackers.MatterControl.PrintQueue +{ + public class QueueData + { + private List printItems = new List(); + private List PrintItems + { + get { return printItems; } + } + + public RootedObjectEventHandler ItemAdded = new RootedObjectEventHandler(); + public RootedObjectEventHandler ItemRemoved = new RootedObjectEventHandler(); + public RootedObjectEventHandler OrderChanged = new RootedObjectEventHandler(); + + static QueueData instance; + public static QueueData Instance + { + get + { + if (instance == null) + { + instance = new QueueData(); + instance.LoadDefaultQueue(); + } + return instance; + } + } + + public void SwapItemsOnIdle(int indexA, int indexB) + { + UiThread.RunOnIdle(SwapItems, new SwapIndexArgs(indexA, indexB)); + } + + void SwapItems(object state) + { + int indexA = ((SwapIndexArgs)state).indexA; + int indexB = ((SwapIndexArgs)state).indexB; + + if (indexA >= 0 && indexA < Count + && indexB >= 0 && indexB < Count + && indexA != indexB) + { + PrintItem hold = PrintItems[indexA]; + PrintItems[indexA] = PrintItems[indexB]; + PrintItems[indexB] = hold; + + OnOrderChanged(null); + + SaveDefaultQueue(); + } + } + + public void OnOrderChanged(EventArgs e) + { + OrderChanged.CallEvents(this, e); + } + + class IndexArgs : EventArgs + { + internal int index; + internal IndexArgs(int index) + { + this.index = index; + } + } + + class SwapIndexArgs : EventArgs + { + internal int indexA; + internal int indexB; + internal SwapIndexArgs(int indexA, int indexB) + { + this.indexA = indexA; + this.indexB = indexB; + } + } + + public void RemoveIndexOnIdle(int index) + { + UiThread.RunOnIdle(RemoveIndex, new IndexArgs(index)); + } + + void RemoveIndex(object state) + { + IndexArgs removeArgs = state as IndexArgs; + if (removeArgs != null) + { + RemoveAt(removeArgs.index); + } + } + + public void RemoveAt(int index) + { + if (index >= 0 && index < Count) + { + PrintItems.RemoveAt(index); + + OnItemRemoved(new IndexArgs(index)); + + SaveDefaultQueue(); + } + } + + public void OnItemRemoved(EventArgs e) + { + ItemRemoved.CallEvents(this, e); + } + + public PrintItem GetPrintItem(int index) + { + if (index >= 0 && index < PrintItems.Count) + { + return PrintItems[index]; + } + + return null; + } + + public int GetIndex(PrintItem printItem) + { + return PrintItems.IndexOf(printItem); + } + + public string[] GetItemNames() + { + List itemNames = new List(); ; + for (int i = 0; i < PrintItems.Count; i++) + { + itemNames.Add(PrintItems[i].Name); + } + + return itemNames.ToArray(); + } + + public List CreateReadOnlyPartList() + { + List listToReturn = new List(); + for (int i = 0; i < Count; i++) + { + listToReturn.Add(GetPrintItem(i)); + } + return listToReturn; + } + + public void AddItem(PrintItem item) + { + PrintItems.Add(item); + OnItemAdded(new IndexArgs(PrintItems.Count - 1)); + } + + public void LoadDefaultQueue() + { + RemoveAll(); + ManifestFileHandler manifest = new ManifestFileHandler(null); + List partFiles = manifest.ImportFromJson(); + if (partFiles != null) + { + foreach (PrintItem item in partFiles) + { + AddItem(item); + } + } + } + + public void OnItemAdded(EventArgs e) + { + ItemAdded.CallEvents(this, e); + } + + public void SaveDefaultQueue() + { + List partList = CreateReadOnlyPartList(); + ManifestFileHandler manifest = new ManifestFileHandler(partList); + manifest.ExportToJson(); + } + + public int Count + { + get + { + return PrintItems.Count; + } + } + + public void RemoveAll() + { + for (int i = PrintItems.Count-1; i >= 0; i--) + { + RemoveAt(i); + } + } + } +} \ No newline at end of file diff --git a/PrintQueue/PrintQueueControl.cs b/PrintQueue/QueueDataView.cs similarity index 60% rename from PrintQueue/PrintQueueControl.cs rename to PrintQueue/QueueDataView.cs index 8e8d4575b..f56cedf7a 100644 --- a/PrintQueue/PrintQueueControl.cs +++ b/PrintQueue/QueueDataView.cs @@ -1,4 +1,33 @@ -using System; +/* +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 System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -14,25 +43,9 @@ using MatterHackers.Agg.ImageProcessing; namespace MatterHackers.MatterControl.PrintQueue { - public class PrintQueueControl : ScrollableWidget + public class QueueDataView : ScrollableWidget { - public RootedObjectEventHandler ItemAdded = new RootedObjectEventHandler(); - public RootedObjectEventHandler ItemRemoved = new RootedObjectEventHandler(); - - static PrintQueueControl instance; - public static PrintQueueControl Instance - { - get - { - if (instance == null) - { - instance = new PrintQueueControl(); - instance.LoadDefaultQueue(); - instance.EnsureSelection(); - } - return instance; - } - } + event EventHandler unregisterEvents; // make this private so it can only be built from the Instance private void SetDisplayAttributes() @@ -78,42 +91,6 @@ namespace MatterHackers.MatterControl.PrintQueue } } - public void SwapItemsDurringUiAction(int indexA, int indexB) - { - UiThread.RunOnIdle(SwapItems, new SwapIndexArgs(indexA, indexB)); - } - - void SwapItems(object state) - { - int indexA = ((SwapIndexArgs)state).indexA; - int indexB = ((SwapIndexArgs)state).indexB; - int selectedAtEnd = indexB; - // make sure indexA is the smaller index - if (indexA > indexB) - { - int temp = indexA; - indexA = indexB; - indexB = temp; - } - - if (indexA >= 0 && indexA < Count - && indexB >= 0 && indexB < Count - && indexA != indexB) - { - GuiWidget itemA = topToBottomItemList.Children[indexA]; - GuiWidget itemB = topToBottomItemList.Children[indexB]; - topToBottomItemList.RemoveChild(indexB); - topToBottomItemList.RemoveChild(indexA); - topToBottomItemList.AddChild(itemB, indexA); - topToBottomItemList.AddChild(itemA, indexB); - - AddItemHandlers(itemA); - AddItemHandlers(itemB); - - this.SelectedIndex = selectedAtEnd; - } - } - public void MoveToNext() { if (SelectedIndex >= 0 && SelectedIndex < Count) @@ -135,70 +112,19 @@ namespace MatterHackers.MatterControl.PrintQueue if (SelectedIndex >= 0 && SelectedIndex < Count) { int currentIndex = SelectedIndex; - PrintQueueItem replacementItem = new PrintQueueItem(PrintQueueControl.Instance.SelectedPart.Name, PrintQueueControl.Instance.SelectedPart.FileLocation); - this.RemoveChild(SelectedIndex); - this.AddChild(replacementItem); + PrintItem replacementItem = new PrintItem(SelectedPart.Name, SelectedPart.FileLocation); + QueueData.Instance.RemoveAt(SelectedIndex); this.SelectedIndex = currentIndex; } } - class RemoveIndexArgs - { - internal int index; - internal RemoveIndexArgs(int index) - { - this.index = index; - } - } - - class SwapIndexArgs - { - internal int indexA; - internal int indexB; - internal SwapIndexArgs(int indexA, int indexB) - { - this.indexA = indexA; - this.indexB = indexB; - } - } - - public void RemoveIndex(int index) - { - UiThread.RunOnIdle(RemoveIndexAfterEvent, new RemoveIndexArgs(index)); - } - - void RemoveIndexAfterEvent(object state) - { - RemoveIndexArgs removeArgs = state as RemoveIndexArgs; - if (removeArgs != null & removeArgs.index >= 0 && removeArgs.index < Count) - { - int currentIndex = removeArgs.index; - - //If the item to be removed is the active print item, set the active print item to null. - GuiWidget itemHolder = topToBottomItemList.Children[currentIndex]; - PrintQueueItem child = (PrintQueueItem)itemHolder.Children[0]; - if (child.isActivePrint) - { - if (PrinterCommunication.Instance.PrinterIsPrinting) - { - return; - } - PrinterCommunication.Instance.ActivePrintItem = null; - } - RemoveChild(currentIndex); - SelectedIndex = System.Math.Min(SelectedIndex, Count - 1); - - SaveDefaultQueue(); - } - } - public PrintItemWrapper SelectedPart { get { if (SelectedIndex >= 0) { - return GetSTLToPrint(SelectedIndex); + return new PrintItemWrapper(QueueData.Instance.GetPrintItem(SelectedIndex)); } else { @@ -207,12 +133,12 @@ namespace MatterHackers.MatterControl.PrintQueue } } - public PrintQueueItem GetPrintQueueItem(int index) + public RowItem GetPrintQueueItem(int index) { if (index >= 0 && index < topToBottomItemList.Children.Count) { GuiWidget itemHolder = topToBottomItemList.Children[index]; - PrintQueueItem child = (PrintQueueItem)itemHolder.Children[0]; + RowItem child = (RowItem)itemHolder.Children[0]; return child; } @@ -220,76 +146,6 @@ namespace MatterHackers.MatterControl.PrintQueue return null; } - public int GetIndex(PrintItemWrapper printItem) - { - for (int i = 0; i < topToBottomItemList.Children.Count; i++) - { - PrintQueueItem queueItem = GetPrintQueueItem(i); - if (queueItem != null && queueItem.PrintItemWrapper == printItem) - { - return i; - } - } - - return -1; - } - - public string[] GetItemNames() - { - List itemNames = new List(); ; - for (int i = 0; i < topToBottomItemList.Children.Count; i++) - { - PrintQueueItem queueItem = GetPrintQueueItem(i); - if (queueItem != null) - { - itemNames.Add(queueItem.PrintItemWrapper.Name); - } - } - - return itemNames.ToArray(); - } - - public PrintItemWrapper GetSTLToPrint(int index) - { - if(index >= 0 && index < Count) - { - return GetPrintQueueItem(index).PrintItemWrapper; - } - - return null; - } - - public List CreateReadOnlyPartList() - { - List listToReturn = new List(); - for (int i = 0; i < Count; i++) - { - listToReturn.Add(GetSTLToPrint(i).PrintItem); - } - return listToReturn; - } - - public void LoadDefaultQueue() - { - RemoveAllChildren(); - ManifestFileHandler manifest = new ManifestFileHandler(null); - List partFiles = manifest.ImportFromJson(); - if (partFiles != null) - { - foreach (PrintItem part in partFiles) - { - PrintQueueControl.Instance.AddChild(new PrintQueueItem(part.Name, part.FileLocation)); - } - } - } - - public void SaveDefaultQueue() - { - List partList = PrintQueueControl.Instance.CreateReadOnlyPartList(); - ManifestFileHandler manifest = new ManifestFileHandler(partList); - manifest.ExportToJson(); - } - public delegate void SelectedValueChangedEventHandler(object sender, EventArgs e); public event SelectedValueChangedEventHandler SelectedValueChanged; public delegate void HoverValueChangedEventHandler(object sender, EventArgs e); @@ -336,25 +192,25 @@ namespace MatterHackers.MatterControl.PrintQueue GuiWidget child = topToBottomItemList.Children[index]; if (index == selectedIndex) { - ((PrintQueueItem)child.Children[0]).isSelectedItem = true; + ((RowItem)child.Children[0]).isSelectedItem = true; if (!PrinterCommunication.Instance.PrinterIsPrinting && !PrinterCommunication.Instance.PrinterIsPaused) { - ((PrintQueueItem)child.Children[0]).isActivePrint = true; - PrinterCommunication.Instance.ActivePrintItem = ((PrintQueueItem)child.Children[0]).PrintItemWrapper; + ((RowItem)child.Children[0]).isActivePrint = true; + PrinterCommunication.Instance.ActivePrintItem = ((RowItem)child.Children[0]).PrintItemWrapper; } } else { - if (((PrintQueueItem)child.Children[0]).isSelectedItem) + if (((RowItem)child.Children[0]).isSelectedItem) { - ((PrintQueueItem)child.Children[0]).isSelectedItem = false; + ((RowItem)child.Children[0]).isSelectedItem = false; } if (!PrinterCommunication.Instance.PrinterIsPrinting && !PrinterCommunication.Instance.PrinterIsPaused) { - if (((PrintQueueItem)child.Children[0]).isActivePrint) + if (((RowItem)child.Children[0]).isActivePrint) { - ((PrintQueueItem)child.Children[0]).isActivePrint = false; + ((RowItem)child.Children[0]).isActivePrint = false; } } } @@ -408,11 +264,11 @@ namespace MatterHackers.MatterControl.PrintQueue GuiWidget child = topToBottomItemList.Children[index]; if (index == HoverIndex) { - ((PrintQueueItem)child.Children[0]).isHoverItem = true; + ((RowItem)child.Children[0]).isHoverItem = true; } - else if (((PrintQueueItem)child.Children[0]).isHoverItem == true) + else if (((RowItem)child.Children[0]).isHoverItem == true) { - ((PrintQueueItem)child.Children[0]).isHoverItem = false; + ((RowItem)child.Children[0]).isHoverItem = false; } child.Invalidate(); } @@ -422,7 +278,7 @@ namespace MatterHackers.MatterControl.PrintQueue } } - public PrintQueueControl() + public QueueDataView() { Name = "PrintQueueControl"; @@ -435,6 +291,31 @@ namespace MatterHackers.MatterControl.PrintQueue topToBottomItemList.Name = "PrintQueueControl TopToBottom"; topToBottomItemList.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; base.AddChild(topToBottomItemList); + + QueueData.Instance.ItemAdded.RegisterEvent(ItemAddedToQueue, ref unregisterEvents); + QueueData.Instance.ItemRemoved.RegisterEvent(ItemRemovedFromToQueue, ref unregisterEvents); + QueueData.Instance.OrderChanged.RegisterEvent(QueueOrderChanged, ref unregisterEvents); + } + + void ItemAddedToQueue(object sender, EventArgs e) + { + } + + void ItemRemovedFromToQueue(object sender, EventArgs e) + { + } + + void QueueOrderChanged(object sender, EventArgs e) + { + } + + public override void OnClosed(EventArgs e) + { + if (unregisterEvents != null) + { + unregisterEvents(this, null); + } + base.OnClosed(e); } public override void AddChild(GuiWidget childToAdd, int indexInChildrenList = -1) @@ -448,8 +329,6 @@ namespace MatterHackers.MatterControl.PrintQueue topToBottomItemList.AddChild(itemHolder, indexInChildrenList); AddItemHandlers(itemHolder); - - ItemAdded.CallEvents(this, new GuiWidgetEventArgs(childToAdd)); } private void AddItemHandlers(GuiWidget itemHolder) @@ -460,38 +339,6 @@ namespace MatterHackers.MatterControl.PrintQueue itemHolder.ParentChanged += new EventHandler(itemHolder_ParentChanged); } - public override void RemoveAllChildren() - { - for (int i = topToBottomItemList.Children.Count-1; i >= 0; i--) - { - RemoveIndex(i); - } - } - - public override void RemoveChild(int index) - { - GuiWidget childToRemove = topToBottomItemList.Children[index]; - RemoveChild(childToRemove); - } - - 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); - OnItemRemoved(new GuiWidgetEventArgs(childToRemove)); - } - } - } - - private void OnItemRemoved(GuiWidgetEventArgs e) - { - ItemRemoved.CallEvents(this, e); - } - bool settingLocalBounds = false; public override RectangleDouble LocalBounds { @@ -622,7 +469,7 @@ namespace MatterHackers.MatterControl.PrintQueue } } - public PrintQueueItem SelectedPrintQueueItem() + public RowItem SelectedPrintQueueItem() { return GetPrintQueueItem(SelectedIndex); } diff --git a/PrintQueue/PrintQueueMenu.cs b/PrintQueue/QueueOptionsMenu.cs similarity index 86% rename from PrintQueue/PrintQueueMenu.cs rename to PrintQueue/QueueOptionsMenu.cs index bf6487e7a..23929cf53 100644 --- a/PrintQueue/PrintQueueMenu.cs +++ b/PrintQueue/QueueOptionsMenu.cs @@ -17,14 +17,14 @@ using MatterHackers.Localizations; namespace MatterHackers.MatterControl.PrintQueue { - public class PrintQueueMenu : GuiWidget + public class QueueOptionsMenu : GuiWidget { public DropDownMenu MenuDropList; private TupleList> menuItems; ExportToFolderFeedbackWindow exportingWindow = null; - public PrintQueueMenu() + public QueueOptionsMenu() { MenuDropList = new DropDownMenu(LocalizedString.Get("Queue Options"), Direction.Up); MenuDropList.HAnchor |= HAnchor.ParentLeft; @@ -113,7 +113,7 @@ namespace MatterHackers.MatterControl.PrintQueue void PartSheetClickOnIdle(object state) { - List parts = PrintQueueControl.Instance.CreateReadOnlyPartList(); + List parts = QueueData.Instance.CreateReadOnlyPartList(); if (parts.Count > 0) { SaveFileDialogParams saveParams = new SaveFileDialogParams("Save Parts Sheet|*.pdf"); @@ -177,7 +177,7 @@ namespace MatterHackers.MatterControl.PrintQueue string path = FileDialog.SelectFolderDialog(ref selectParams); if (path != null && path != "") { - List parts = PrintQueueControl.Instance.CreateReadOnlyPartList(); + List parts = QueueData.Instance.CreateReadOnlyPartList(); if (parts.Count > 0) { if (exportingWindow == null) @@ -208,7 +208,7 @@ namespace MatterHackers.MatterControl.PrintQueue void ExportQueueToZipOnIdle(object state) { - List partList = PrintQueueControl.Instance.CreateReadOnlyPartList(); + List partList = QueueData.Instance.CreateReadOnlyPartList(); ProjectFileHandler project = new ProjectFileHandler(partList); project.SaveAs(); } @@ -225,14 +225,11 @@ namespace MatterHackers.MatterControl.PrintQueue List partFiles = project.OpenFromDialog(); if (partFiles != null) { - PrintQueueControl.Instance.RemoveAllChildren(); + QueueData.Instance.RemoveAll(); foreach (PrintItem part in partFiles) { - PrintQueueControl.Instance.AddChild(new PrintQueueItem(part.Name, part.FileLocation)); + QueueData.Instance.AddItem(new PrintItem(part.Name, part.FileLocation)); } - PrintQueueControl.Instance.EnsureSelection(); - PrintQueueControl.Instance.Invalidate(); - PrintQueueControl.Instance.SaveDefaultQueue(); } } @@ -244,21 +241,7 @@ namespace MatterHackers.MatterControl.PrintQueue void removeAllPrintsFromQueue (object state) { - - PrintQueueControl.Instance.RemoveAllChildren (); - PrintQueueControl.Instance.SaveDefaultQueue (); + QueueData.Instance.RemoveAll(); } - - void deleteFromQueueButton_Click(object sender, MouseEventArgs mouseEvent) - { - PrintQueueControl.Instance.RemoveIndex(PrintQueueControl.Instance.SelectedIndex); - PrintQueueControl.Instance.SaveDefaultQueue(); - } - - void deleteAllFromQueueButton_Click(object sender, MouseEventArgs mouseEvent) - { - PrintQueueControl.Instance.RemoveAllChildren(); - PrintQueueControl.Instance.SaveDefaultQueue(); - } } } diff --git a/PrintQueue/PrintQueueItem.cs b/PrintQueue/RowItem.cs similarity index 91% rename from PrintQueue/PrintQueueItem.cs rename to PrintQueue/RowItem.cs index 3afd7f273..01a1e0b02 100644 --- a/PrintQueue/PrintQueueItem.cs +++ b/PrintQueue/RowItem.cs @@ -20,7 +20,7 @@ using MatterHackers.PolygonMesh; namespace MatterHackers.MatterControl.PrintQueue { - public class PrintQueueItem : GuiWidget + public class RowItem : GuiWidget { public PrintItemWrapper PrintItemWrapper { get; set; } public RGBA_Bytes WidgetTextColor; @@ -36,16 +36,11 @@ namespace MatterHackers.MatterControl.PrintQueue PartPreviewMainWindow viewingWindow; bool exportingWindowIsOpen = false; bool viewWindowIsOpen = false; + QueueDataView queueDataViewThisIsIn; - - public PrintQueueItem(PrintItemWrapper printItem) - { - this.PrintItemWrapper = printItem; - ConstructPrintQueueItem(); - } - - public PrintQueueItem(string displayName, string fileLocation) + public RowItem(string displayName, string fileLocation, QueueDataView queueDataViewThisIsIn) { + this.queueDataViewThisIsIn = queueDataViewThisIsIn; PrintItem printItem = new PrintItem(); printItem.Name = displayName; printItem.FileLocation = fileLocation; @@ -250,8 +245,8 @@ namespace MatterHackers.MatterControl.PrintQueue Button moveUp = linkButtonFactory.Generate(" ^ "); moveUp.Click += (sender, e) => { - int thisIndexInQueue = PrintQueueControl.Instance.GetIndex(PrintItemWrapper); - PrintQueueControl.Instance.SwapItemsDurringUiAction(thisIndexInQueue, thisIndexInQueue - 1); + int thisIndexInQueue = QueueData.Instance.GetIndex(PrintItemWrapper.PrintItem); + QueueData.Instance.SwapItemsOnIdle(thisIndexInQueue, thisIndexInQueue - 1); }; topToBottom.AddChild(moveUp); } @@ -261,8 +256,8 @@ namespace MatterHackers.MatterControl.PrintQueue Button moveDown = linkButtonFactory.Generate(" v "); moveDown.Click += (sender, e) => { - int thisIndexInQueue = PrintQueueControl.Instance.GetIndex(PrintItemWrapper); - PrintQueueControl.Instance.SwapItemsDurringUiAction(thisIndexInQueue, thisIndexInQueue + 1); + int thisIndexInQueue = QueueData.Instance.GetIndex(PrintItemWrapper.PrintItem); + QueueData.Instance.SwapItemsOnIdle(thisIndexInQueue, thisIndexInQueue + 1); }; topToBottom.AddChild(moveDown); } @@ -341,14 +336,12 @@ namespace MatterHackers.MatterControl.PrintQueue void AddPartToQueue(object state) { PartToAddToQueue partToAddToQueue = (PartToAddToQueue)state; - PrintQueueItem queueItem = new PrintQueueItem(partToAddToQueue.Name, partToAddToQueue.FileLocation); - PrintQueueControl.Instance.AddChild(queueItem, partToAddToQueue.insertAfterIndex); - PrintQueueControl.Instance.SaveDefaultQueue(); + QueueData.Instance.AddItem(new PrintItem(partToAddToQueue.Name, partToAddToQueue.FileLocation)); } public void CreateCopyInQueue() { - int thisIndexInQueue = PrintQueueControl.Instance.GetIndex(PrintItemWrapper); + int thisIndexInQueue = QueueData.Instance.GetIndex(PrintItemWrapper.PrintItem); if (thisIndexInQueue != -1) { string applicationDataPath = ApplicationDataStorage.Instance.ApplicationUserDataPath; @@ -383,7 +376,7 @@ namespace MatterHackers.MatterControl.PrintQueue int copyNumber = 2; string testName = newName; - string[] itemNames = PrintQueueControl.Instance.GetItemNames(); + string[] itemNames = QueueData.Instance.GetItemNames(); // figure out if we have a copy already and increment the number if we do while (true) { @@ -405,15 +398,15 @@ namespace MatterHackers.MatterControl.PrintQueue public void DeletePartFromQueue() { - int thisIndexInQueue = PrintQueueControl.Instance.GetIndex(PrintItemWrapper); - PrintQueueControl.Instance.RemoveIndex(thisIndexInQueue); + int thisIndexInQueue = QueueData.Instance.GetIndex(PrintItemWrapper.PrintItem); + QueueData.Instance.RemoveIndexOnIdle(thisIndexInQueue); } - public static void ShowCantFindFileMessage(PrintItemWrapper printItem) + public static void ShowCantFindFileMessage(PrintItemWrapper printItemWrapper) { UiThread.RunOnIdle((state) => { - string maxLengthName = printItem.FileLocation; + string maxLengthName = printItemWrapper.FileLocation; int maxLength = 43; if (maxLengthName.Length > maxLength) { @@ -428,7 +421,7 @@ namespace MatterHackers.MatterControl.PrintQueue string titleLabel = LocalizedString.Get("Item not Found"); if (StyledMessageBox.ShowMessageBox(message, titleLabel, StyledMessageBox.MessageType.YES_NO)) { - PrintQueueControl.Instance.RemoveIndex(PrintQueueControl.Instance.GetIndex(printItem)); + QueueData.Instance.RemoveIndexOnIdle(QueueData.Instance.GetIndex(printItemWrapper.PrintItem)); } }); } diff --git a/PrinterControls/PrinterConnections/SetupConnectionWidgetBase.cs b/PrinterControls/PrinterConnections/SetupConnectionWidgetBase.cs index 7d304f344..a8a0c5133 100644 --- a/PrinterControls/PrinterConnections/SetupConnectionWidgetBase.cs +++ b/PrinterControls/PrinterConnections/SetupConnectionWidgetBase.cs @@ -59,10 +59,8 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections foreach (string partFile in calibrationPrints) { string partFullPath = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "OEMSettings", "SampleParts", partFile); - PrintQueueControl.Instance.AddChild(new PrintQueueItem(Path.GetFileNameWithoutExtension(partFullPath), partFullPath)); + QueueData.Instance.AddItem(new PrintItem(Path.GetFileNameWithoutExtension(partFullPath), partFullPath)); } - PrintQueue.PrintQueueControl.Instance.EnsureSelection(); - PrintQueueControl.Instance.SaveDefaultQueue(); } } diff --git a/PrinterControls/PrinterConnections/SetupStepInstallDriver.cs b/PrinterControls/PrinterConnections/SetupStepInstallDriver.cs index 011d1e3a5..ae4cbe228 100644 --- a/PrinterControls/PrinterConnections/SetupStepInstallDriver.cs +++ b/PrinterControls/PrinterConnections/SetupStepInstallDriver.cs @@ -123,14 +123,14 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections var driverInstallerProcess = new Process(); // Prepare the process to run // Enter in the command line arguments, everything you would enter after the executable name itself - driverInstallerProcess.StartInfo.Arguments = System.IO.Path.GetFullPath(fileName); + driverInstallerProcess.StartInfo.Arguments = Path.GetFullPath(fileName); // Enter the executable to run, including the complete path string printerDriverInstallerExePathAndFileName = Path.Combine(".", "InfInstaller.exe"); driverInstallerProcess.StartInfo.CreateNoWindow = true; driverInstallerProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - driverInstallerProcess.StartInfo.FileName = System.IO.Path.GetFullPath(printerDriverInstallerExePathAndFileName); + driverInstallerProcess.StartInfo.FileName = Path.GetFullPath(printerDriverInstallerExePathAndFileName); driverInstallerProcess.StartInfo.Verb = "runas"; driverInstallerProcess.StartInfo.UseShellExecute = true; diff --git a/SlicerConfiguration/SliceSettingsWidget.cs b/SlicerConfiguration/SliceSettingsWidget.cs index a8aacaa70..90cfaed10 100644 --- a/SlicerConfiguration/SliceSettingsWidget.cs +++ b/SlicerConfiguration/SliceSettingsWidget.cs @@ -872,7 +872,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration RoundedRect rect = new RoundedRect(LocalBounds,0); graphics2D.Render(rect,new RGBA_Bytes(OverlayColor, 50)); graphics2D.Render(new Stroke(rect, 3),OverlayColor); - } } diff --git a/SlicerConfiguration/SlicingQueue.cs b/SlicerConfiguration/SlicingQueue.cs index 0ffa80133..4dae8b2d7 100644 --- a/SlicerConfiguration/SlicingQueue.cs +++ b/SlicerConfiguration/SlicingQueue.cs @@ -113,9 +113,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration string slic3rRelativePath = Path.Combine("..", "Slic3r", "slic3r.exe"); if (!File.Exists(slic3rRelativePath)) { - slic3rRelativePath = System.IO.Path.Combine(".", "Slic3r", "slic3r.exe"); + slic3rRelativePath = Path.Combine(".", "Slic3r", "slic3r.exe"); } - return System.IO.Path.GetFullPath(slic3rRelativePath); + return Path.GetFullPath(slic3rRelativePath); } case ActivePrinterProfile.SlicingEngineTypes.CuraEngine: @@ -123,15 +123,15 @@ namespace MatterHackers.MatterControl.SlicerConfiguration string curaEngineRelativePath = Path.Combine("..", "CuraEngine.exe"); if (!File.Exists(curaEngineRelativePath)) { - curaEngineRelativePath = System.IO.Path.Combine(".", "CuraEngine.exe"); + curaEngineRelativePath = Path.Combine(".", "CuraEngine.exe"); } - return System.IO.Path.GetFullPath(curaEngineRelativePath); + return Path.GetFullPath(curaEngineRelativePath); } case ActivePrinterProfile.SlicingEngineTypes.MatterSlice: { string materSliceRelativePath = Path.Combine(".", "MatterSlice.exe"); - return System.IO.Path.GetFullPath(materSliceRelativePath); + return Path.GetFullPath(materSliceRelativePath); } default: @@ -144,17 +144,17 @@ namespace MatterHackers.MatterControl.SlicerConfiguration case ActivePrinterProfile.SlicingEngineTypes.Slic3r: { //string parentLocation = Directory.GetParent (ApplicationDataStorage.Instance.ApplicationPath).ToString (); - string applicationPath = System.IO.Path.Combine(ApplicationDataStorage.Instance.ApplicationPath, "Slic3r.app", "Contents", "MacOS", "slic3r"); + string applicationPath = Path.Combine(ApplicationDataStorage.Instance.ApplicationPath, "Slic3r.app", "Contents", "MacOS", "slic3r"); return applicationPath; } case ActivePrinterProfile.SlicingEngineTypes.CuraEngine: { - string applicationPath = System.IO.Path.Combine(ApplicationDataStorage.Instance.ApplicationPath, "CuraEngine"); + string applicationPath = Path.Combine(ApplicationDataStorage.Instance.ApplicationPath, "CuraEngine"); return applicationPath; } case ActivePrinterProfile.SlicingEngineTypes.MatterSlice: { - string applicationPath = System.IO.Path.Combine(ApplicationDataStorage.Instance.ApplicationPath, "MatterSlice"); + string applicationPath = Path.Combine(ApplicationDataStorage.Instance.ApplicationPath, "MatterSlice"); return applicationPath; } diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 1d0d252cc..39ef8699d 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -1959,3 +1959,6 @@ Translated:Downloading updates... English:Duplicate Translated:Duplicate +English:End +Translated:End + diff --git a/ToolsPage/ToolsListControl.cs b/ToolsPage/ToolsListControl.cs deleted file mode 100644 index 21388d45a..000000000 --- a/ToolsPage/ToolsListControl.cs +++ /dev/null @@ -1,550 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.IO; - -using MatterHackers.Agg.Image; -using MatterHackers.Agg; -using MatterHackers.Agg.UI; -using MatterHackers.VectorMath; -using MatterHackers.MatterControl; -using MatterHackers.MatterControl.DataStorage; -using MatterHackers.MatterControl.PrintQueue; - -namespace MatterHackers.MatterControl.ToolsPage -{ - - public class SelectedPrintItems : List - { - public event EventHandler OnAdd; - public event EventHandler OnRemove; - - new public void Add(T item) - { - base.Add(item); - if (null != OnAdd) - { - OnAdd(this, null); - } - } - - new public void Remove(T item) - { - base.Remove(item); - if (null != OnRemove) - { - OnRemove(this, null); - } - } - } - - public class ToolsListControl : ScrollableWidget - { - static ToolsListControl instance; - string keywordFilter; - private DataStorage.PrintItemCollection libraryCollection; - - public static ToolsListControl Instance - { - get - { - if (instance == null) - { - instance = new ToolsListControl(); - instance.LoadLibraryItems(); - } - return instance; - } - } - - public string KeywordFilter - { - get { return keywordFilter; } - set - { - if (this.keywordFilter != value) - { - this.keywordFilter = value; - LoadLibraryItems(); - } - } - } - - private void SetDisplayAttributes() - { - this.MinimumSize = new Vector2(0, 200); - this.AnchorAll(); - this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; - this.AutoScroll = true; - this.ScrollArea.Padding = new BorderDouble(3); - } - - public void RemoveSelectedIndex() - { - if (SelectedIndex >= 0 && SelectedIndex < Count) - { - RemoveChild(SelectedIndex); - } - } - - - public PrintItem SelectedPart - { - get - { - if (SelectedIndex >= 0) - { - return GetSTLToPrint(SelectedIndex); - } - else - { - return null; - } - } - } - - public PrintItem GetSTLToPrint(int index) - { - if(index >= 0 && index < Count) - { - GuiWidget itemHolder = topToBottomItemList.Children[index]; - ToolsListItem child = (ToolsListItem)itemHolder.Children[0]; - return new PrintItem(child.printItem.Name, child.printItem.FileLocation); - } - - return null; - } - - public List CreateReadOnlyPartList() - { - List listToReturn = new List(); - for (int i = 0; i < Count; i++) - { - listToReturn.Add(GetSTLToPrint(i)); - } - return listToReturn; - } - - public DataStorage.PrintItemCollection LibraryCollection - { - get - { - //Retrieve a list of saved printers from the Datastore - if (libraryCollection == null) - { - libraryCollection = DataStorage.Datastore.Instance.dbSQLite.Table().Where(v => v.Name == "_library").Take(1).FirstOrDefault(); - } - - - if (libraryCollection == null) - { - libraryCollection = new PrintItemCollection(); - libraryCollection.Name = "_library"; - libraryCollection.Commit(); - PreloadLibrary(); - } - return libraryCollection; - } - } - - private List GetLibraryParts() - { - List libraryFilesToPreload = new List(); - string setupSettingsPathAndFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "OEMSettings", "PreloadedLibraryFiles.txt"); - if (System.IO.File.Exists(setupSettingsPathAndFile)) - { - try - { - string[] lines = System.IO.File.ReadAllLines(setupSettingsPathAndFile); - foreach (string line in lines) - { - //Ignore commented lines - if (!line.StartsWith("#")) - { - string settingLine = line.Trim(); - libraryFilesToPreload.Add(settingLine); - } - } - } - catch - { - - } - } - return libraryFilesToPreload; - } - - void PreloadLibrary() - { - List calibrationPrints = GetLibraryParts(); - foreach (string partFile in calibrationPrints) - { - string partFullPath = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "OEMSettings", "SampleParts", partFile); - if (System.IO.File.Exists(partFullPath)) - { - PrintItem printItem = new PrintItem(); - printItem.Name = System.IO.Path.GetFileNameWithoutExtension(partFullPath); - printItem.FileLocation = System.IO.Path.GetFullPath(partFullPath); - printItem.PrintItemCollectionID = ToolsListControl.Instance.LibraryCollection.Id; - printItem.Commit(); - } - } - } - - IEnumerable GetLibraryItems(string keyphrase = null) - { - if (LibraryCollection == null) - { - return null; - } - else - { - string query; - if (keyphrase == null) - { - query = string.Format("SELECT * FROM PrintItem WHERE PrintItemCollectionID = {0} ORDER BY Name ASC;", libraryCollection.Id); - } - else - { - query = string.Format("SELECT * FROM PrintItem WHERE PrintItemCollectionID = {0} AND Name LIKE '%{1}%' ORDER BY Name ASC;", libraryCollection.Id, keyphrase); - } - IEnumerable result = (IEnumerable)DataStorage.Datastore.Instance.dbSQLite.Query(query); - return result; - } - } - - public void ClearSelectedItems() - { - List itemsToClear = new List(); - - foreach(ToolsListItem item in instance.SelectedItems) - { - itemsToClear.Add(item); - } - foreach (ToolsListItem item in itemsToClear) - { - item.isSelectedItem = false; - item.selectionCheckBox.Checked = false; - } - } - - public void LoadLibraryItems() - { - RemoveAllChildren(); - IEnumerable partFiles = GetLibraryItems(instance.KeywordFilter); - if (partFiles != null) - { - foreach (PrintItem part in partFiles) - { - ToolsListControl.Instance.AddChild(new ToolsListItem(new PrintItemWrapper(part))); - } - } - } - - - - public void SaveLibraryItems() - { - // - } - - public delegate void SelectedValueChangedEventHandler(object sender, EventArgs e); - public event SelectedValueChangedEventHandler SelectedValueChanged; - public delegate void HoverValueChangedEventHandler(object sender, EventArgs e); - public event HoverValueChangedEventHandler HoverValueChanged; - - protected FlowLayoutWidget topToBottomItemList; - - RGBA_Bytes hoverColor = new RGBA_Bytes(204, 204, 204, 255); - //RGBA_Bytes hoverColor = new RGBA_Bytes(0, 140, 158, 255); - RGBA_Bytes selectedColor = new RGBA_Bytes(180, 180, 180, 255); - //RGBA_Bytes selectedColor = new RGBA_Bytes(0, 95, 107, 255); - RGBA_Bytes baseColor = new RGBA_Bytes(255, 255, 255); - - public SelectedPrintItems SelectedItems = new SelectedPrintItems(); - int selectedIndex = -1; - int hoverIndex = -1; - int dragIndex = -1; - - public 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 DragIndex - { - get - { - return dragIndex; - } - set - { - if (value < -1 || value >= topToBottomItemList.Children.Count) - { - throw new ArgumentOutOfRangeException(); - } - - if (value != dragIndex) - { - dragIndex = value; - } - } - } - - public int HoverIndex - { - get - { - return hoverIndex; - } - set - { - if (value < -1 || value >= topToBottomItemList.Children.Count) - { - throw new ArgumentOutOfRangeException(); - } - - if (value != hoverIndex) - { - hoverIndex = value; - OnHoverIndexChanged(); - - for (int index = 0; index < topToBottomItemList.Children.Count; index++) - { - GuiWidget child = topToBottomItemList.Children[index]; - if (index == HoverIndex) - { - ((ToolsListItem)child.Children[0]).isHoverItem = true; - } - else if (((ToolsListItem)child.Children[0]).isHoverItem == true) - { - ((ToolsListItem)child.Children[0]).isHoverItem = false; - } - child.Invalidate(); - } - - Invalidate(); - } - } - } - - public ToolsListControl() - { - SetDisplayAttributes(); - ScrollArea.HAnchor |= Agg.UI.HAnchor.ParentLeftRight; - - AutoScroll = true; - topToBottomItemList = new FlowLayoutWidget(FlowDirection.TopToBottom); - topToBottomItemList.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; - base.AddChild(topToBottomItemList); - - AddHandlers(); - } - - void AddHandlers() - { - this.MouseLeaveBounds += new EventHandler(control_MouseLeaveBounds); - } - - public override void AddChild(GuiWidget child, int indexInChildrenList = -1) - { - FlowLayoutWidget itemHolder = new FlowLayoutWidget(); - itemHolder.Name = "LB item holder"; - itemHolder.Margin = new BorderDouble(3, 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 += new MouseEventHandler(itemHolder_MouseDownInBounds); - itemHolder.ParentChanged += new EventHandler(itemHolder_ParentChanged); - } - - bool settingLocalBounds = false; - public override RectangleDouble LocalBounds - { - set - { - if (!settingLocalBounds) - { - Vector2 currentTopLeftOffset = new Vector2(); - if (Parent != null) - { - currentTopLeftOffset = TopLeftOffset; - } - settingLocalBounds = true; - if (topToBottomItemList != null) - { - if (VerticalScrollBar.Visible) - { - topToBottomItemList.Width = Math.Max(0, value.Width - ScrollArea.Padding.Width - topToBottomItemList.Margin.Width - VerticalScrollBar.Width); - } - else - { - topToBottomItemList.Width = Math.Max(0, value.Width - ScrollArea.Padding.Width - topToBottomItemList.Margin.Width); - } - } - - base.LocalBounds = value; - if (Parent != null) - { - TopLeftOffset = currentTopLeftOffset; - } - settingLocalBounds = false; - } - } - } - - public void RemoveSelectedItems() - { - foreach (ToolsListItem item in instance.SelectedItems) - { - RemoveChild(item); - item.printItem.Delete(); - } - } - - 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 override void RemoveAllChildren() - { - topToBottomItemList.RemoveAllChildren(); - } - - 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 -= new MouseEventHandler(itemHolder_MouseDownInBounds); - itemHolder.ParentChanged -= new EventHandler(itemHolder_ParentChanged); - } - - void itemHolder_MouseDownInBounds(object sender, MouseEventArgs mouseEvent) - { - - } - - void control_MouseLeaveBounds(object sender, EventArgs e) - { - HoverIndex = -1; - } - - 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(); - } - } - } - - 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 void ClearSelected() - { - if (selectedIndex != -1) - { - selectedIndex = -1; - OnSelectedIndexChanged(); - } - } - - public GuiWidget SelectedItem - { - get - { - if (SelectedIndex != -1) - { - return Children[SelectedIndex]; - } - - return null; - } - - set - { - for (int i = 0; i < Children.Count; i++) - { - if (Children[SelectedIndex] == value) - { - SelectedIndex = i; - } - } - } - } - } -} \ No newline at end of file diff --git a/ToolsPage/ToolsListItem.cs b/ToolsPage/ToolsListItem.cs deleted file mode 100644 index bf3c2a83c..000000000 --- a/ToolsPage/ToolsListItem.cs +++ /dev/null @@ -1,250 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Globalization; -using System.Threading; -using System.IO; - -using MatterHackers.Agg.Image; -using MatterHackers.Agg.VertexSource; -using MatterHackers.Agg; -using MatterHackers.Agg.UI; -using MatterHackers.VectorMath; -using MatterHackers.MatterControl.PartPreviewWindow; -using MatterHackers.MatterControl.DataStorage; -using MatterHackers.MatterControl; -using MatterHackers.MatterControl.PrintQueue; - -using MatterHackers.PolygonMesh; - -namespace MatterHackers.MatterControl.ToolsPage -{ - public class ToolsListItem : ClickWidget - { - public PrintItemWrapper printItem; - public RGBA_Bytes WidgetTextColor; - public RGBA_Bytes WidgetBackgroundColor; - - public bool isActivePrint = false; - public bool isSelectedItem = false; - public bool isHoverItem = false; - TextWidget partLabel; - Button viewLink; - Button removeLink; - public CheckBox selectionCheckBox; - FlowLayoutWidget buttonContainer; - LinkButtonFactory linkButtonFactory = new LinkButtonFactory(); - - public ToolsListItem(PrintItemWrapper printItem) - { - this.printItem = printItem; - linkButtonFactory.fontSize = 10; - linkButtonFactory.textColor = RGBA_Bytes.White; - - WidgetTextColor = RGBA_Bytes.Black; - WidgetBackgroundColor = RGBA_Bytes.White; - - TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; - - SetDisplayAttributes(); - - FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.LeftToRight); - mainContainer.HAnchor |= Agg.UI.HAnchor.ParentLeftRight; - { - GuiWidget selectionCheckBoxContainer = new GuiWidget(); - selectionCheckBoxContainer.VAnchor = VAnchor.Max_FitToChildren_ParentHeight; - selectionCheckBoxContainer.HAnchor = Agg.UI.HAnchor.FitToChildren; - selectionCheckBoxContainer.Margin = new BorderDouble(left: 6); - selectionCheckBox = new CheckBox(""); - selectionCheckBox.VAnchor = VAnchor.ParentCenter; - selectionCheckBox.HAnchor = HAnchor.ParentCenter; - selectionCheckBoxContainer.AddChild(selectionCheckBox); - - FlowLayoutWidget leftColumn = new FlowLayoutWidget(FlowDirection.TopToBottom); - leftColumn.VAnchor |= VAnchor.ParentTop; - - FlowLayoutWidget middleColumn = new FlowLayoutWidget(FlowDirection.TopToBottom); - middleColumn.VAnchor |= VAnchor.ParentTop; - middleColumn.HAnchor |= HAnchor.ParentLeftRight; - middleColumn.Padding = new BorderDouble(6); - middleColumn.Margin = new BorderDouble(10,0); - { - string labelName = textInfo.ToTitleCase(printItem.Name); - labelName = labelName.Replace('_', ' '); - partLabel = new TextWidget(labelName, pointSize: 12); - partLabel.TextColor = WidgetTextColor; - partLabel.MinimumSize = new Vector2(1, 16); - middleColumn.AddChild(partLabel); - } - - FlowLayoutWidget rightColumn = new FlowLayoutWidget(FlowDirection.TopToBottom); - rightColumn.VAnchor |= VAnchor.ParentCenter; - - buttonContainer = new FlowLayoutWidget(); - buttonContainer.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; - buttonContainer.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight; - { - viewLink = linkButtonFactory.Generate("View"); - viewLink.Margin = new BorderDouble(left: 10, right:10); - viewLink.VAnchor = VAnchor.ParentCenter; - - removeLink = linkButtonFactory.Generate("Remove"); - removeLink.Margin = new BorderDouble(right: 10); - removeLink.VAnchor = VAnchor.ParentCenter; - - buttonContainer.AddChild(viewLink); - buttonContainer.AddChild(removeLink); - } - rightColumn.AddChild(buttonContainer); - - mainContainer.AddChild(selectionCheckBoxContainer); - mainContainer.AddChild(leftColumn); - mainContainer.AddChild(middleColumn); - mainContainer.AddChild(rightColumn); - } - this.AddChild(mainContainer); - AddHandlers(); - } - - void SetDisplayAttributes() - { - this.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight; - this.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; - this.Height = 28; - this.BackgroundColor = this.WidgetBackgroundColor; - this.Padding = new BorderDouble(0); - this.Margin = new BorderDouble(6,0,6,6); - } - - event EventHandler unregisterEvents; - void AddHandlers() - { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); - viewLink.Click += new ButtonBase.ButtonEventHandler(onViewLinkClick); - removeLink.Click += new ButtonBase.ButtonEventHandler(onRemoveLinkClick); - selectionCheckBox.CheckedStateChanged += selectionCheckBox_CheckedStateChanged; - } - - public override void OnClosed(EventArgs e) - { - if (unregisterEvents != null) - { - unregisterEvents(this, null); - } - base.OnClosed(e); - } - - private void onClick(object sender, MouseEventArgs e) - { - if (this.isSelectedItem == false) - { - this.isSelectedItem = true; - ToolsListControl.Instance.SelectedItems.Add(this); - } - } - - private void selectionCheckBox_CheckedStateChanged(object sender, EventArgs e) - { - if (selectionCheckBox.Checked == true) - { - this.isSelectedItem = true; - ToolsListControl.Instance.SelectedItems.Add(this); - } - else - { - this.isSelectedItem = false; - ToolsListControl.Instance.SelectedItems.Remove(this); - } - } - - private void onAddLinkClick(object sender, MouseEventArgs e) - { - } - - void RemoveThisFromPrintLibrary(object state) - { - ToolsListControl.Instance.RemoveChild(this); - this.printItem.Delete(); - } - - private void onRemoveLinkClick(object sender, MouseEventArgs e) - { - UiThread.RunOnIdle(RemoveThisFromPrintLibrary); - } - - private void onViewLinkClick(object sender, MouseEventArgs e) - { - UiThread.RunOnIdle(onViewLinkClick); - } - - private void onViewLinkClick(object state) - { - string pathAndFile = this.printItem.FileLocation; - Console.WriteLine(pathAndFile); - if (File.Exists(pathAndFile)) - { - new PartPreviewMainWindow(this.printItem); - } - else - { - string message = String.Format("Cannot find\n'{0}'.\nWould you like to remove it from the queue?", pathAndFile); - if (StyledMessageBox.ShowMessageBox(message, "Item not found", StyledMessageBox.MessageType.YES_NO)) - { - ToolsListControl.Instance.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.isHoverItem) - { - buttonContainer.Visible = true; - } - else - { - buttonContainer.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; - - //RectangleDouble Bounds = LocalBounds; - //RoundedRect rectBorder = new RoundedRect(Bounds, 0); - //graphics2D.Render(new Stroke(rectBorder, 3), RGBA_Bytes.White); - } - - else if (this.isHoverItem) - { - RectangleDouble Bounds = LocalBounds; - RoundedRect rectBorder = new RoundedRect(Bounds, 0); - - this.BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor; - this.partLabel.TextColor = RGBA_Bytes.White; - this.selectionCheckBox.TextColor = RGBA_Bytes.White; - - graphics2D.Render(new Stroke(rectBorder, 3), ActiveTheme.Instance.PrimaryAccentColor); - } - else - { - this.BackgroundColor = RGBA_Bytes.White; - this.partLabel.TextColor = RGBA_Bytes.Black; - this.selectionCheckBox.TextColor = RGBA_Bytes.Black; - } - - } - } -} diff --git a/ToolsPage/ToolsWidget.cs b/ToolsPage/ToolsWidget.cs deleted file mode 100644 index 100da72f8..000000000 --- a/ToolsPage/ToolsWidget.cs +++ /dev/null @@ -1,237 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Collections; -using System.IO; -using System.Diagnostics; -using System.Threading; - -using MatterHackers.Agg.Image; -using MatterHackers.Agg.VertexSource; -using MatterHackers.Agg; -using MatterHackers.Agg.UI; -using MatterHackers.VectorMath; -using MatterHackers.MatterControl.DataStorage; -using MatterHackers.MatterControl.PrintQueue; -using MatterHackers.Localizations; - -namespace MatterHackers.MatterControl.ToolsPage -{ - public class ToolsWidget : GuiWidget - { - TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory(); - TextImageButtonFactory searchButtonFactory = new TextImageButtonFactory(); - Button deleteFromLibraryButton; - Button addToQueueButton; - Button searchButton; - MHTextEditWidget searchInput; - - public ToolsWidget() - { - SetDisplayAttributes(); - - textImageButtonFactory.normalTextColor = RGBA_Bytes.White; - textImageButtonFactory.hoverTextColor = RGBA_Bytes.White; - textImageButtonFactory.disabledTextColor = RGBA_Bytes.White; - textImageButtonFactory.pressedTextColor = RGBA_Bytes.White; - textImageButtonFactory.borderWidth = 0; - - searchButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryBackgroundColor; - searchButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryBackgroundColor; - searchButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryBackgroundColor; - searchButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryBackgroundColor; - searchButtonFactory.borderWidth = 0; - - FlowLayoutWidget allControls = new FlowLayoutWidget(FlowDirection.TopToBottom); - { - FlowLayoutWidget searchPanel = new FlowLayoutWidget(); - searchPanel.BackgroundColor = new RGBA_Bytes(180, 180, 180); - searchPanel.HAnchor = HAnchor.ParentLeftRight; - searchPanel.Padding = new BorderDouble(3, 3); - { - searchInput = new MHTextEditWidget(); - searchInput.Margin = new BorderDouble(6, 0); - searchInput.HAnchor = HAnchor.ParentLeftRight; - searchInput.VAnchor = VAnchor.ParentCenter; - - searchButton = searchButtonFactory.Generate("Search"); - searchButton.Margin = new BorderDouble(right:9); - - searchPanel.AddChild(searchInput); - searchPanel.AddChild(searchButton); - } - - FlowLayoutWidget buttonPanel = new FlowLayoutWidget(); - buttonPanel.HAnchor = HAnchor.ParentLeftRight; - buttonPanel.Padding = new BorderDouble(0, 3); - { - Button addToLibrary = textImageButtonFactory.Generate(LocalizedString.Get("Import"), "icon_import_white_32x32.png"); - buttonPanel.AddChild(addToLibrary); - addToLibrary.Margin = new BorderDouble(0, 0, 3, 0); - addToLibrary.Click += new ButtonBase.ButtonEventHandler(loadFile_Click); - - deleteFromLibraryButton = textImageButtonFactory.Generate(LocalizedString.Get("Delete")); - deleteFromLibraryButton.Margin = new BorderDouble(3, 0); - deleteFromLibraryButton.Click += new ButtonBase.ButtonEventHandler(deleteFromQueueButton_Click); - deleteFromLibraryButton.Visible = false; - buttonPanel.AddChild(deleteFromLibraryButton); - - addToQueueButton = textImageButtonFactory.Generate(LocalizedString.Get("Add to Queue")); - addToQueueButton.Margin = new BorderDouble(3, 0); - addToQueueButton.Click += new ButtonBase.ButtonEventHandler(addToQueueButton_Click); - addToQueueButton.Visible = false; - buttonPanel.AddChild(addToQueueButton); - - GuiWidget spacer = new GuiWidget(); - spacer.HAnchor = HAnchor.ParentLeftRight; - buttonPanel.AddChild(spacer); - } - - allControls.AddChild(searchPanel); - allControls.AddChild(ToolsListControl.Instance); - allControls.AddChild(buttonPanel); - } - allControls.AnchorAll(); - - this.AddChild(allControls); - - AddHandlers(); - } - - private void AddHandlers() - { - ToolsListControl.Instance.SelectedItems.OnAdd += onLibraryItemsSelected; - ToolsListControl.Instance.SelectedItems.OnRemove += onLibraryItemsSelected; - searchInput.ActualTextEditWidget.EnterPressed += new KeyEventHandler(searchInputEnterPressed); - searchButton.Click += searchButtonClick; - searchInput.ActualTextEditWidget.KeyUp += searchInputKeyUp; - } - - void searchInputKeyUp(object sender, KeyEventArgs keyEvent) - { - searchButtonClick(null, null); - } - - void searchInputEnterPressed(object sender, KeyEventArgs keyEvent) - { - searchButtonClick(null, null); - } - - void searchButtonClick(object sender, MouseEventArgs mouseEvent) - { - string textToSend = searchInput.Text.Trim(); - ToolsListControl.Instance.KeywordFilter = textToSend; - } - - private void addToQueueButton_Click(object sender, MouseEventArgs e) - { - foreach (ToolsListItem item in ToolsListControl.Instance.SelectedItems) - { - PrintQueue.PrintQueueItem queueItem = new PrintQueue.PrintQueueItem(item.printItem); - PrintQueue.PrintQueueControl.Instance.AddChild(queueItem); - } - ToolsListControl.Instance.ClearSelectedItems(); - PrintQueue.PrintQueueControl.Instance.EnsureSelection(); - PrintQueueControl.Instance.SaveDefaultQueue(); - } - - private void onLibraryItemsSelected(object sender, EventArgs e) - { - List selectedItemsList = (List)sender; - if (selectedItemsList.Count > 0) - { - addToQueueButton.Visible = true; - deleteFromLibraryButton.Visible = true; - } - else - { - addToQueueButton.Visible = false; - deleteFromLibraryButton.Visible = false; - } - } - - private void SetDisplayAttributes() - { - this.Padding = new BorderDouble(3); - this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; - this.AnchorAll(); - } - - void deleteFromQueueButton_Click(object sender, MouseEventArgs mouseEvent) - { - ToolsListControl.Instance.RemoveSelectedItems(); - } - - public override void OnDragEnter(FileDropEventArgs fileDropEventArgs) - { - foreach (string file in fileDropEventArgs.DroppedFiles) - { - string extension = Path.GetExtension(file).ToUpper(); - if (extension == ".STL" || extension == ".GCODE") - { - fileDropEventArgs.AcceptDrop = true; - } - } - base.OnDragEnter(fileDropEventArgs); - } - - public override void OnDragOver(FileDropEventArgs fileDropEventArgs) - { - foreach (string file in fileDropEventArgs.DroppedFiles) - { - string extension = Path.GetExtension(file).ToUpper(); - if (extension == ".STL" || extension == ".GCODE") - { - fileDropEventArgs.AcceptDrop = true; - } - } - base.OnDragOver(fileDropEventArgs); - } - - public override void OnDragDrop(FileDropEventArgs fileDropEventArgs) - { - foreach (string droppedFileName in fileDropEventArgs.DroppedFiles) - { - string extension = Path.GetExtension(droppedFileName).ToUpper(); - if (extension == ".STL" || extension == ".GCODE") - { - PrintItem printItem = new PrintItem(); - printItem.Name = System.IO.Path.GetFileNameWithoutExtension(droppedFileName); - printItem.FileLocation = System.IO.Path.GetFullPath(droppedFileName); - printItem.PrintItemCollectionID = ToolsListControl.Instance.LibraryCollection.Id; - printItem.Commit(); - - ToolsListItem queueItem = new ToolsListItem(new PrintItemWrapper(printItem)); - ToolsListControl.Instance.AddChild(queueItem); - } - ToolsListControl.Instance.Invalidate(); - } - ToolsListControl.Instance.SaveLibraryItems(); - - base.OnDragDrop(fileDropEventArgs); - } - - void loadFile_Click(object sender, MouseEventArgs mouseEvent) - { - OpenFileDialogParams openParams = new OpenFileDialogParams("Select an STL file, Select a GCODE file|*.stl;*.gcode", multiSelect: true); - FileDialog.OpenFileDialog(ref openParams); - if (openParams.FileNames != null) - { - foreach (string loadedFileName in openParams.FileNames) - { - PrintItem printItem = new PrintItem(); - printItem.Name = System.IO.Path.GetFileNameWithoutExtension(loadedFileName); - printItem.FileLocation = System.IO.Path.GetFullPath(loadedFileName); - printItem.PrintItemCollectionID = ToolsListControl.Instance.LibraryCollection.Id; - printItem.Commit(); - - ToolsListItem queueItem = new ToolsListItem(new PrintItemWrapper(printItem)); - ToolsListControl.Instance.AddChild(queueItem); - } - ToolsListControl.Instance.Invalidate(); - } - ToolsListControl.Instance.SaveLibraryItems(); - } - } -} diff --git a/Utilities/ProjectFileHandler.cs b/Utilities/ProjectFileHandler.cs index bcf1c8df8..c876648b5 100644 --- a/Utilities/ProjectFileHandler.cs +++ b/Utilities/ProjectFileHandler.cs @@ -162,8 +162,8 @@ namespace MatterHackers.MatterControl } static string applicationDataPath = ApplicationDataStorage.Instance.ApplicationUserDataPath; - static string defaultManifestPathAndFileName = System.IO.Path.Combine(applicationDataPath,"data", "temp", "project-assembly", "manifest.json"); - static string defaultProjectPathAndFileName = System.IO.Path.Combine(applicationDataPath,"data", "default.zip"); + static string defaultManifestPathAndFileName = Path.Combine(applicationDataPath, "data", "temp", "project-assembly", "manifest.json"); + static string defaultProjectPathAndFileName = Path.Combine(applicationDataPath, "data", "default.zip"); public static void EmptyFolder(System.IO.DirectoryInfo directory) { @@ -290,8 +290,8 @@ namespace MatterHackers.MatterControl } if (zipEntry.Name == "manifest.json" - || System.IO.Path.GetExtension(zipEntry.Name).ToUpper() == ".STL" - || System.IO.Path.GetExtension(zipEntry.Name).ToUpper() == ".GCODE") + || Path.GetExtension(zipEntry.Name).ToUpper() == ".STL" + || Path.GetExtension(zipEntry.Name).ToUpper() == ".GCODE") { string extractedFileName = Path.Combine(stagingFolder, zipEntry.Name);