2014-04-19 11:51:02 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2014, Kevin Pope
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
2015-04-08 15:20:10 -07:00
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2014-04-19 11:51:02 -07:00
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
2015-04-08 15:20:10 -07:00
|
|
|
|
list of conditions and the following disclaimer.
|
2014-04-19 11:51:02 -07:00
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2015-04-08 15:20:10 -07:00
|
|
|
|
and/or other materials provided with the distribution.
|
2014-04-19 11:51:02 -07:00
|
|
|
|
|
|
|
|
|
|
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
|
2015-04-08 15:20:10 -07:00
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
2014-04-19 11:51:02 -07:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.Agg.PlatformAbstract;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.MatterControl.DataStorage;
|
2014-06-19 11:25:28 -07:00
|
|
|
|
using MatterHackers.MatterControl.PrinterCommunication;
|
2016-07-13 13:39:11 -07:00
|
|
|
|
using MatterHackers.MatterControl.SetupWizard;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PrintQueue
|
|
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public class QueueOptionsMenu : GuiWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
public DropDownMenu MenuDropList;
|
|
|
|
|
|
private TupleList<string, Func<bool>> menuItems;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private ExportToFolderFeedbackWindow exportingWindow = null;
|
2014-02-18 12:51:11 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public QueueOptionsMenu()
|
|
|
|
|
|
{
|
2015-05-26 18:28:57 -07:00
|
|
|
|
MenuDropList = new DropDownMenu("Queue".Localize() + "... ", Direction.Up);
|
2015-08-18 13:01:29 -07:00
|
|
|
|
MenuDropList.Name = "Queue... Menu";
|
2015-04-08 15:20:10 -07:00
|
|
|
|
MenuDropList.VAnchor = VAnchor.ParentBottomTop;
|
|
|
|
|
|
MenuDropList.BorderWidth = 1;
|
|
|
|
|
|
MenuDropList.MenuAsWideAsItems = false;
|
|
|
|
|
|
MenuDropList.BorderColor = ActiveTheme.Instance.SecondaryTextColor;
|
|
|
|
|
|
MenuDropList.Margin = new BorderDouble(4, 0, 1, 0);
|
2014-10-17 15:33:01 -07:00
|
|
|
|
MenuDropList.AlignToRightEdge = true;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2014-10-17 15:33:01 -07:00
|
|
|
|
SetMenuItems();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
this.MenuDropList.SelectionChanged += new EventHandler(MenuDropList_SelectionChanged);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MenuDropList_SelectionChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
string menuSelection = ((DropDownMenu)sender).SelectedValue;
|
|
|
|
|
|
foreach (Tuple<string, Func<bool>> item in menuItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.Item1 == menuSelection)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.Item2 != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.Item2();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetMenuItems()
|
|
|
|
|
|
{
|
|
|
|
|
|
menuItems = new TupleList<string, Func<bool>>();
|
2016-07-26 15:41:05 -07:00
|
|
|
|
|
|
|
|
|
|
#if !__ANDROID__
|
2015-04-08 15:20:10 -07:00
|
|
|
|
menuItems.Add(new Tuple<string, Func<bool>>("Design".Localize(), null));
|
|
|
|
|
|
menuItems.Add(new Tuple<string, Func<bool>>(" Export to Zip".Localize(), exportQueueToZipMenu_Click));
|
2016-07-18 14:40:42 -07:00
|
|
|
|
menuItems.Add(new Tuple<string, Func<bool>>("G-Code".Localize(), null));
|
2015-03-14 16:00:04 -07:00
|
|
|
|
menuItems.Add(new Tuple<string, Func<bool>>(" Export to Folder or SD Card".Localize(), exportGCodeToFolderButton_Click));
|
2015-04-08 15:20:10 -07:00
|
|
|
|
//menuItems.Add(new Tuple<string, Func<bool>>("X3G", null));
|
2015-03-14 16:00:04 -07:00
|
|
|
|
//menuItems.Add(new Tuple<string, Func<bool>>("Export to Folder".Localize(), exportX3GButton_Click));
|
2016-07-26 15:41:05 -07:00
|
|
|
|
#endif
|
2014-06-19 11:25:28 -07:00
|
|
|
|
|
2016-07-12 17:46:48 -07:00
|
|
|
|
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_sd_card_reader))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
menuItems.Add(new Tuple<string, Func<bool>>("SD Card", null));
|
2015-03-14 16:00:04 -07:00
|
|
|
|
menuItems.Add(new Tuple<string, Func<bool>>(" Load Files".Localize(), loadFilesFromSDButton_Click));
|
|
|
|
|
|
menuItems.Add(new Tuple<string, Func<bool>>(" Eject SD Card".Localize(), ejectSDCardButton_Click));
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The pdf export library is not working on the mac at the moment so we don't include the
|
|
|
|
|
|
// part sheet export option on mac.
|
2014-10-27 13:53:23 -07:00
|
|
|
|
if (OsInformation.OperatingSystem == OSType.Windows)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-03-14 16:00:04 -07:00
|
|
|
|
menuItems.Add(new Tuple<string, Func<bool>>("Other".Localize(), null));
|
|
|
|
|
|
menuItems.Add(new Tuple<string, Func<bool>>(" Create Part Sheet".Localize(), createPartsSheetsButton_Click));
|
|
|
|
|
|
menuItems.Add(new Tuple<string, Func<bool>>(" Remove All".Localize(), removeAllFromQueueButton_Click));
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2015-08-18 13:01:29 -07:00
|
|
|
|
// mac cannot export to pdf
|
2015-03-14 16:00:04 -07:00
|
|
|
|
menuItems.Add(new Tuple<string, Func<bool>>("Other".Localize(), null));
|
|
|
|
|
|
menuItems.Add(new Tuple<string, Func<bool>>(" Remove All".Localize(), removeAllFromQueueButton_Click));
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
BorderDouble padding = MenuDropList.MenuItemsPadding;
|
|
|
|
|
|
//Add the menu items to the menu itself
|
|
|
|
|
|
foreach (Tuple<string, Func<bool>> item in menuItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.Item2 == null)
|
2014-10-17 15:33:01 -07:00
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
MenuDropList.MenuItemsPadding = new BorderDouble(5, 0, padding.Right, 3);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
MenuDropList.MenuItemsPadding = new BorderDouble(10, 5, padding.Right, 5);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-13 11:49:09 -08:00
|
|
|
|
MenuItem menuItem = MenuDropList.AddItem(item.Item1);
|
|
|
|
|
|
if(item.Item2 == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
menuItem.Enabled = false;
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MenuDropList.Padding = padding;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool createPartsSheetsButton_Click()
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(PartSheetClickOnIdle);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-11 12:06:40 -07:00
|
|
|
|
private void PartSheetClickOnIdle()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
#if !__ANDROID__
|
|
|
|
|
|
List<PrintItem> parts = QueueData.Instance.CreateReadOnlyPartList();
|
|
|
|
|
|
if (parts.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
FileDialog.SaveFileDialog(
|
|
|
|
|
|
new SaveFileDialogParams("Save Parts Sheet|*.pdf")
|
2014-10-17 15:33:01 -07:00
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
ActionButtonLabel = "Save Parts Sheet".Localize(),
|
|
|
|
|
|
Title = string.Format("{0}: {1}", "MatterControl".Localize(), "Save".Localize())
|
|
|
|
|
|
},
|
|
|
|
|
|
(saveParams) =>
|
2014-10-17 15:33:01 -07:00
|
|
|
|
{
|
2016-02-12 10:26:40 -08:00
|
|
|
|
if (!string.IsNullOrEmpty(saveParams.FileName))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
PartsSheet currentPartsInQueue = new PartsSheet(parts, saveParams.FileName);
|
2014-10-17 15:33:01 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
currentPartsInQueue.SaveSheets();
|
2014-10-17 15:33:01 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
SavePartsSheetFeedbackWindow feedbackWindow = new SavePartsSheetFeedbackWindow(parts.Count, parts[0].Name, ActiveTheme.Instance.PrimaryBackgroundColor);
|
|
|
|
|
|
currentPartsInQueue.UpdateRemainingItems += feedbackWindow.StartingNextPart;
|
|
|
|
|
|
currentPartsInQueue.DoneSaving += feedbackWindow.DoneSaving;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
feedbackWindow.ShowAsSystemWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private string pleaseSelectPrinterMessage = "Before you can export printable files, you must select a printer.";
|
|
|
|
|
|
private string pleaseSelectPrinterTitle = "Please select a printer";
|
|
|
|
|
|
|
2015-06-11 12:06:40 -07:00
|
|
|
|
private void MustSelectPrinterMessage()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
StyledMessageBox.ShowMessageBox(null, pleaseSelectPrinterMessage, pleaseSelectPrinterTitle);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool exportGCodeToFolderButton_Click()
|
2014-08-19 18:10:38 -07:00
|
|
|
|
{
|
2016-07-21 15:05:59 -07:00
|
|
|
|
if (!ActiveSliceSettings.Instance.PrinterSelected)
|
2014-08-19 18:10:38 -07:00
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(MustSelectPrinterMessage);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(SelectLocationToExportGCode);
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2014-08-19 18:10:38 -07:00
|
|
|
|
return true;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2014-08-19 18:10:38 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private bool exportX3GButton_Click()
|
|
|
|
|
|
{
|
2016-07-21 15:05:59 -07:00
|
|
|
|
if (!ActiveSliceSettings.Instance.PrinterSelected)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(MustSelectPrinterMessage);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(SelectLocationToExportGCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
2014-08-19 18:10:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private void ExportToFolderFeedbackWindow_Closed(object sender, EventArgs e)
|
2014-02-18 12:51:11 -08:00
|
|
|
|
{
|
2014-03-05 12:00:37 -08:00
|
|
|
|
this.exportingWindow = null;
|
2014-02-18 12:51:11 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-11 12:06:40 -07:00
|
|
|
|
private void SelectLocationToExportGCode()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
SelectFolderDialogParams selectParams = new SelectFolderDialogParams("Select Location To Save Files");
|
2015-03-14 16:00:04 -07:00
|
|
|
|
selectParams.ActionButtonLabel = "Export".Localize();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
selectParams.Title = "MatterControl: Select A Folder";
|
|
|
|
|
|
|
|
|
|
|
|
FileDialog.SelectFolderDialog(selectParams, onSelectFolderDialog);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void onSelectFolderDialog(SelectFolderDialogParams openParams)
|
|
|
|
|
|
{
|
|
|
|
|
|
string path = openParams.FolderPath;
|
|
|
|
|
|
if (path != null && path != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
List<PrintItem> parts = QueueData.Instance.CreateReadOnlyPartList();
|
|
|
|
|
|
if (parts.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (exportingWindow == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
exportingWindow = new ExportToFolderFeedbackWindow(parts.Count, parts[0].Name, ActiveTheme.Instance.PrimaryBackgroundColor);
|
|
|
|
|
|
exportingWindow.Closed += new EventHandler(ExportToFolderFeedbackWindow_Closed);
|
|
|
|
|
|
exportingWindow.ShowAsSystemWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
exportingWindow.BringToFront();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExportToFolderProcess exportToFolderProcess = new ExportToFolderProcess(parts, path);
|
|
|
|
|
|
exportToFolderProcess.StartingNextPart += exportingWindow.StartingNextPart;
|
|
|
|
|
|
exportToFolderProcess.UpdatePartStatus += exportingWindow.UpdatePartStatus;
|
|
|
|
|
|
exportToFolderProcess.DoneSaving += exportingWindow.DoneSaving;
|
|
|
|
|
|
exportToFolderProcess.Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool exportQueueToZipMenu_Click()
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(ExportQueueToZipOnIdle);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-11 12:06:40 -07:00
|
|
|
|
private void ExportQueueToZipOnIdle()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
List<PrintItem> partList = QueueData.Instance.CreateReadOnlyPartList();
|
|
|
|
|
|
ProjectFileHandler project = new ProjectFileHandler(partList);
|
|
|
|
|
|
project.SaveAs();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool loadFilesFromSDButton_Click()
|
|
|
|
|
|
{
|
|
|
|
|
|
QueueData.Instance.LoadFilesFromSD();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool ejectSDCardButton_Click()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Remove all the QueueData.SdCardFileName parts from the queue
|
|
|
|
|
|
QueueData.Instance.RemoveAllSdCardFiles();
|
|
|
|
|
|
PrinterConnectionAndCommunication.Instance.SendLineToPrinterNow("M22"); // (Release SD card)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool removeAllFromQueueButton_Click()
|
2014-03-24 17:31:24 -07:00
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
UiThread.RunOnIdle(removeAllPrintsFromQueue);
|
2014-03-24 17:31:24 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-11 12:06:40 -07:00
|
|
|
|
private void removeAllPrintsFromQueue()
|
2014-03-24 17:31:24 -07:00
|
|
|
|
{
|
2014-04-15 18:13:27 -07:00
|
|
|
|
QueueData.Instance.RemoveAll();
|
2014-03-24 17:31:24 -07:00
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|