2017-07-18 18:15:10 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using MatterHackers.Agg;
|
2014-06-19 16:09:38 -07:00
|
|
|
|
using MatterHackers.Agg.PlatformAbstract;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2017-03-15 16:17:06 -07:00
|
|
|
|
using MatterHackers.DataConverters3D;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.GCodeVisualizer;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2014-06-19 15:55:20 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2014-10-30 17:37:28 -07:00
|
|
|
|
using MatterHackers.MatterControl.DataStorage;
|
2016-09-13 15:59:45 -07:00
|
|
|
|
using MatterHackers.MatterControl.PrinterCommunication.Io;
|
2014-06-19 15:55:20 -07:00
|
|
|
|
using MatterHackers.MatterControl.PrintQueue;
|
2015-11-06 17:05:49 -08:00
|
|
|
|
using MatterHackers.MatterControl.Queue.OptionsMenu;
|
2014-06-19 15:55:20 -07:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2014-10-17 18:45:15 -07:00
|
|
|
|
using MatterHackers.PolygonMesh;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
2017-08-08 20:05:13 -07:00
|
|
|
|
public class ExportPrintItemPage : WizardPage
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
private CheckBox showInFolderAfterSave;
|
|
|
|
|
|
private CheckBox applyLeveling;
|
|
|
|
|
|
private PrintItemWrapper printItemWrapper;
|
|
|
|
|
|
private string gcodePathAndFilenameToSave;
|
|
|
|
|
|
private bool partIsGCode = false;
|
|
|
|
|
|
private string documentsPath;
|
|
|
|
|
|
|
2017-08-08 20:05:13 -07:00
|
|
|
|
public ExportPrintItemPage(PrintItemWrapper printItemWrapper)
|
|
|
|
|
|
: base(unlocalizedTextForTitle: "File export options:")
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
this.printItemWrapper = printItemWrapper;
|
|
|
|
|
|
if (Path.GetExtension(printItemWrapper.FileLocation).ToUpper() == ".GCODE")
|
|
|
|
|
|
{
|
|
|
|
|
|
partIsGCode = true;
|
|
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
2015-11-13 18:06:44 -08:00
|
|
|
|
this.Name = "Export Item Window";
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
CreateWindowContent();
|
2016-07-18 16:18:12 -07:00
|
|
|
|
PrinterSettings.PrintLevelingEnabledChanged.RegisterEvent(ReloadAfterPrinterProfileChanged, ref unregisterEvents);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void CreateWindowContent()
|
|
|
|
|
|
{
|
2017-03-06 17:32:46 -08:00
|
|
|
|
bool modelCanBeExported = !partIsGCode;
|
|
|
|
|
|
|
|
|
|
|
|
if(modelCanBeExported
|
|
|
|
|
|
&& printItemWrapper != null
|
|
|
|
|
|
&& (printItemWrapper.PrintItem.Protected
|
|
|
|
|
|
|| printItemWrapper.PrintItem.ReadOnly))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-03-06 17:32:46 -08:00
|
|
|
|
modelCanBeExported = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (modelCanBeExported)
|
|
|
|
|
|
{
|
|
|
|
|
|
// put in stl export
|
2017-08-08 20:31:05 -07:00
|
|
|
|
Button exportAsStlButton = textImageButtonFactory.Generate("Export as".Localize() + " STL");
|
2017-03-07 14:13:35 -08:00
|
|
|
|
exportAsStlButton.Name = "Export as STL button";
|
2017-08-07 15:47:27 -07:00
|
|
|
|
exportAsStlButton.HAnchor = HAnchor.Left;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
exportAsStlButton.Cursor = Cursors.Hand;
|
2017-01-17 14:47:04 -08:00
|
|
|
|
exportAsStlButton.Click += exportSTL_Click;
|
2017-08-08 20:05:13 -07:00
|
|
|
|
contentRow.AddChild(exportAsStlButton);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-03-06 17:32:46 -08:00
|
|
|
|
// put in amf export
|
2017-08-08 20:31:05 -07:00
|
|
|
|
Button exportAsAmfButton = textImageButtonFactory.Generate("Export as".Localize() + " AMF");
|
2017-03-07 14:13:35 -08:00
|
|
|
|
exportAsAmfButton.Name = "Export as AMF button";
|
2017-08-07 15:47:27 -07:00
|
|
|
|
exportAsAmfButton.HAnchor = HAnchor.Left;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
exportAsAmfButton.Cursor = Cursors.Hand;
|
2017-01-17 14:47:04 -08:00
|
|
|
|
exportAsAmfButton.Click += exportAMF_Click;
|
2017-08-08 20:05:13 -07:00
|
|
|
|
contentRow.AddChild(exportAsAmfButton);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-09 14:33:27 -08:00
|
|
|
|
bool showExportGCodeButton = ActiveSliceSettings.Instance.PrinterSelected || partIsGCode;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
if (showExportGCodeButton)
|
|
|
|
|
|
{
|
2017-08-08 20:31:05 -07:00
|
|
|
|
Button exportGCode = textImageButtonFactory.Generate("Export as".Localize() + " G-Code");
|
2015-12-31 12:57:00 -08:00
|
|
|
|
exportGCode.Name = "Export as GCode Button";
|
2017-08-07 15:47:27 -07:00
|
|
|
|
exportGCode.HAnchor = HAnchor.Left;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
exportGCode.Cursor = Cursors.Hand;
|
2017-01-17 14:47:04 -08:00
|
|
|
|
exportGCode.Click += (s, e) =>
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(ExportGCode_Click);
|
2017-01-17 14:47:04 -08:00
|
|
|
|
};
|
2017-08-08 20:05:13 -07:00
|
|
|
|
contentRow.AddChild(exportGCode);
|
2014-06-23 13:18:51 -07:00
|
|
|
|
|
2017-07-20 00:50:50 -07:00
|
|
|
|
var gcodeExportPlugins = PluginFinder.CreateInstancesOf<ExportGcodePlugin>();
|
2016-03-17 08:57:58 -07:00
|
|
|
|
|
2017-07-20 00:50:50 -07:00
|
|
|
|
foreach (ExportGcodePlugin plugin in gcodeExportPlugins)
|
2016-03-17 08:57:58 -07:00
|
|
|
|
{
|
2017-03-06 17:32:46 -08:00
|
|
|
|
if (plugin.EnabledForCurrentPart(printItemWrapper))
|
|
|
|
|
|
{
|
|
|
|
|
|
//Create export button for each Plugin found
|
|
|
|
|
|
string exportButtonText = plugin.GetButtonText().Localize();
|
2016-03-17 10:14:29 -07:00
|
|
|
|
|
2017-03-06 17:32:46 -08:00
|
|
|
|
Button exportButton = textImageButtonFactory.Generate(exportButtonText);
|
2017-08-07 15:47:27 -07:00
|
|
|
|
exportButton.HAnchor = HAnchor.Left;
|
2017-03-06 17:32:46 -08:00
|
|
|
|
exportButton.Cursor = Cursors.Hand;
|
|
|
|
|
|
exportButton.Click += (s, e) =>
|
2016-03-17 08:57:58 -07:00
|
|
|
|
{
|
2017-03-06 17:32:46 -08:00
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
2016-03-17 10:14:29 -07:00
|
|
|
|
// Close the export window
|
|
|
|
|
|
Close();
|
|
|
|
|
|
|
|
|
|
|
|
// Open a SaveFileDialog. If Save is clicked, slice the part if needed and pass the plugin the
|
|
|
|
|
|
// path to the gcode file and the target save path
|
|
|
|
|
|
FileDialog.SaveFileDialog(
|
2017-03-06 17:32:46 -08:00
|
|
|
|
new SaveFileDialogParams(plugin.GetExtensionFilter())
|
2016-03-17 08:57:58 -07:00
|
|
|
|
{
|
2017-03-06 17:32:46 -08:00
|
|
|
|
Title = "MatterControl: Export File",
|
|
|
|
|
|
FileName = printItemWrapper.Name,
|
|
|
|
|
|
ActionButtonLabel = "Export"
|
|
|
|
|
|
},
|
|
|
|
|
|
(SaveFileDialogParams saveParam) =>
|
2016-03-17 10:14:29 -07:00
|
|
|
|
{
|
2017-03-06 17:32:46 -08:00
|
|
|
|
string extension = Path.GetExtension(saveParam.FileName);
|
|
|
|
|
|
if (extension == "")
|
2016-12-13 12:15:05 -08:00
|
|
|
|
{
|
2017-03-06 17:32:46 -08:00
|
|
|
|
saveParam.FileName += plugin.GetFileExtension();
|
2016-12-13 12:15:05 -08:00
|
|
|
|
}
|
2016-03-17 10:14:29 -07:00
|
|
|
|
|
2017-03-06 17:32:46 -08:00
|
|
|
|
if (partIsGCode)
|
2016-03-17 10:14:29 -07:00
|
|
|
|
{
|
2017-03-06 17:32:46 -08:00
|
|
|
|
try
|
2016-03-17 10:14:29 -07:00
|
|
|
|
{
|
2017-03-06 17:32:46 -08:00
|
|
|
|
plugin.Generate(printItemWrapper.FileLocation, saveParam.FileName);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
2016-12-13 12:15:05 -08:00
|
|
|
|
{
|
2017-03-06 17:32:46 -08:00
|
|
|
|
StyledMessageBox.ShowMessageBox(null, exception.Message, "Couldn't save file".Localize());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SlicingQueue.Instance.QueuePartForSlicing(printItemWrapper);
|
|
|
|
|
|
|
|
|
|
|
|
printItemWrapper.SlicingDone += (printItem, eventArgs) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
PrintItemWrapper sliceItem = (PrintItemWrapper)printItem;
|
|
|
|
|
|
if (File.Exists(sliceItem.GetGCodePathAndFileName()))
|
2016-12-13 12:15:05 -08:00
|
|
|
|
{
|
2017-03-06 17:32:46 -08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
plugin.Generate(sliceItem.GetGCodePathAndFileName(), saveParam.FileName);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
StyledMessageBox.ShowMessageBox(null, exception.Message, "Couldn't save file".Localize());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2016-12-13 12:15:05 -08:00
|
|
|
|
}
|
2017-03-06 17:32:46 -08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}; // End exportButton Click handler
|
2016-03-17 10:14:29 -07:00
|
|
|
|
|
2017-08-08 20:05:13 -07:00
|
|
|
|
contentRow.AddChild(exportButton);
|
2017-03-06 17:32:46 -08:00
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-08 20:05:13 -07:00
|
|
|
|
contentRow.AddChild(new VerticalSpacer());
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
// If print leveling is enabled then add in a check box 'Apply Leveling During Export' and default checked.
|
2016-09-27 12:47:15 -07:00
|
|
|
|
if (showExportGCodeButton && ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.print_leveling_enabled))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-08-08 20:31:05 -07:00
|
|
|
|
applyLeveling = new CheckBox("Apply leveling to G-Code during export".Localize(), ActiveTheme.Instance.PrimaryTextColor, 10);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
applyLeveling.Checked = true;
|
2017-08-07 15:47:27 -07:00
|
|
|
|
applyLeveling.HAnchor = HAnchor.Left;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
applyLeveling.Cursor = Cursors.Hand;
|
|
|
|
|
|
//applyLeveling.Margin = new BorderDouble(top: 10);
|
2017-08-08 20:05:13 -07:00
|
|
|
|
contentRow.AddChild(applyLeveling);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: make this work on the mac and then delete this if
|
|
|
|
|
|
if (OsInformation.OperatingSystem == OSType.Windows
|
|
|
|
|
|
|| OsInformation.OperatingSystem == OSType.X11)
|
|
|
|
|
|
{
|
2017-01-04 07:23:30 -08:00
|
|
|
|
showInFolderAfterSave = new CheckBox("Show file in folder after save".Localize(), ActiveTheme.Instance.PrimaryTextColor, 10);
|
2017-08-07 15:47:27 -07:00
|
|
|
|
showInFolderAfterSave.HAnchor = HAnchor.Left;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
showInFolderAfterSave.Cursor = Cursors.Hand;
|
|
|
|
|
|
//showInFolderAfterSave.Margin = new BorderDouble(top: 10);
|
2017-08-08 20:05:13 -07:00
|
|
|
|
contentRow.AddChild(showInFolderAfterSave);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!showExportGCodeButton)
|
|
|
|
|
|
{
|
2017-08-08 20:31:05 -07:00
|
|
|
|
var noGCodeMessage = new TextWidget(
|
|
|
|
|
|
"Note".Localize() + ": " + "To enable GCode export, select a printer profile.".Localize(),
|
|
|
|
|
|
textColor: ActiveTheme.Instance.PrimaryTextColor,
|
|
|
|
|
|
pointSize: 10);
|
2017-08-07 15:47:27 -07:00
|
|
|
|
noGCodeMessage.HAnchor = HAnchor.Left;
|
2017-08-08 20:05:13 -07:00
|
|
|
|
contentRow.AddChild(noGCodeMessage);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-08 20:05:13 -07:00
|
|
|
|
footerRow.AddChild(new HorizontalSpacer());
|
|
|
|
|
|
footerRow.AddChild(cancelButton);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string Get8Name(string longName)
|
|
|
|
|
|
{
|
|
|
|
|
|
longName.Replace(' ', '_');
|
|
|
|
|
|
return longName.Substring(0, Math.Min(longName.Length, 8));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-11 12:06:40 -07:00
|
|
|
|
private void ExportGCode_Click()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2014-12-06 11:12:05 -08:00
|
|
|
|
SaveFileDialogParams saveParams = new SaveFileDialogParams("Export GCode|*.gcode", title: "Export GCode");
|
2014-01-29 19:09:30 -08:00
|
|
|
|
saveParams.Title = "MatterControl: Export File";
|
|
|
|
|
|
saveParams.ActionButtonLabel = "Export";
|
2015-04-08 15:20:10 -07:00
|
|
|
|
saveParams.FileName = Path.GetFileNameWithoutExtension(printItemWrapper.Name);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-02-06 15:24:51 -08:00
|
|
|
|
Close();
|
2014-10-11 15:11:26 -07:00
|
|
|
|
FileDialog.SaveFileDialog(saveParams, onExportGcodeFileSelected);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2014-02-27 16:58:29 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private void onExportGcodeFileSelected(SaveFileDialogParams saveParams)
|
2014-10-11 15:11:26 -07:00
|
|
|
|
{
|
2016-02-12 10:26:40 -08:00
|
|
|
|
if (!string.IsNullOrEmpty(saveParams.FileName))
|
2014-10-11 15:11:26 -07:00
|
|
|
|
{
|
2016-03-17 08:57:58 -07:00
|
|
|
|
ExportGcodeCommandLineUtility(saveParams.FileName);
|
2014-10-11 15:11:26 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-09-23 17:17:51 -07:00
|
|
|
|
public void ExportGcodeCommandLineUtility(String nameOfFile)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrEmpty(nameOfFile))
|
|
|
|
|
|
{
|
|
|
|
|
|
gcodePathAndFilenameToSave = nameOfFile;
|
|
|
|
|
|
string extension = Path.GetExtension(gcodePathAndFilenameToSave);
|
|
|
|
|
|
if (extension == "")
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Delete(gcodePathAndFilenameToSave);
|
|
|
|
|
|
gcodePathAndFilenameToSave += ".gcode";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string sourceExtension = Path.GetExtension(printItemWrapper.FileLocation).ToUpper();
|
|
|
|
|
|
if (MeshFileIo.ValidFileExtensions().Contains(sourceExtension))
|
|
|
|
|
|
{
|
|
|
|
|
|
SlicingQueue.Instance.QueuePartForSlicing(printItemWrapper);
|
|
|
|
|
|
printItemWrapper.SlicingDone += sliceItem_Done;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (partIsGCode)
|
|
|
|
|
|
{
|
|
|
|
|
|
SaveGCodeToNewLocation(printItemWrapper.FileLocation, gcodePathAndFilenameToSave);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-04-14 17:15:58 -07:00
|
|
|
|
|
2016-09-13 15:59:45 -07:00
|
|
|
|
private void SaveGCodeToNewLocation(string gcodeFilename, string dest)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-09-23 17:17:51 -07:00
|
|
|
|
try
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-07-14 13:55:02 -07:00
|
|
|
|
GCodeFileStream gCodeFileStream = new GCodeFileStream(GCodeFile.Load(gcodeFilename, CancellationToken.None));
|
2017-06-30 18:25:26 -07:00
|
|
|
|
|
|
|
|
|
|
bool addLevelingStream = ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.print_leveling_enabled) && applyLeveling.Checked;
|
2017-07-13 18:43:48 -07:00
|
|
|
|
var queueStream = new QueuedCommandsStream(gCodeFileStream);
|
2017-06-30 18:25:26 -07:00
|
|
|
|
|
|
|
|
|
|
// this is added to ensure we are rewriting the G0 G1 commands as needed
|
|
|
|
|
|
GCodeStream finalStream = addLevelingStream
|
2017-07-13 18:43:48 -07:00
|
|
|
|
? new ProcessWriteRegexStream(new PrintLevelingStream(queueStream, false), queueStream)
|
|
|
|
|
|
: new ProcessWriteRegexStream(queueStream, queueStream);
|
2017-06-30 18:25:26 -07:00
|
|
|
|
|
|
|
|
|
|
using (StreamWriter file = new StreamWriter(dest))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-06-30 18:25:26 -07:00
|
|
|
|
string nextLine = finalStream.ReadLine();
|
|
|
|
|
|
while (nextLine != null)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-06-30 18:25:26 -07:00
|
|
|
|
if (nextLine.Trim().Length > 0)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-06-30 18:25:26 -07:00
|
|
|
|
file.WriteLine(nextLine);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2017-06-30 18:25:26 -07:00
|
|
|
|
nextLine = finalStream.ReadLine();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2015-09-23 17:17:51 -07:00
|
|
|
|
}
|
2017-06-30 18:25:26 -07:00
|
|
|
|
|
2015-09-23 17:17:51 -07:00
|
|
|
|
ShowFileIfRequested(dest);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2016-12-13 12:15:05 -08:00
|
|
|
|
catch (Exception e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-06-30 18:25:26 -07:00
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
2016-12-13 12:15:05 -08:00
|
|
|
|
StyledMessageBox.ShowMessageBox(null, e.Message, "Couldn't save file".Localize());
|
|
|
|
|
|
});
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ShowFileIfRequested(string filename)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (OsInformation.OperatingSystem == OSType.Windows)
|
2014-01-29 19:09:30 -08:00
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
if (showInFolderAfterSave.Checked)
|
2014-01-29 19:09:30 -08:00
|
|
|
|
{
|
2014-07-28 13:48:28 -07:00
|
|
|
|
#if IS_WINDOWS_FORMS
|
2015-04-08 15:20:10 -07:00
|
|
|
|
WindowsFormsAbstract.ShowFileInFolder(filename);
|
2014-07-28 13:48:28 -07:00
|
|
|
|
#endif
|
2014-01-29 19:09:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-03 13:06:08 -08:00
|
|
|
|
public override void OnClosed(ClosedEventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-03-17 08:57:58 -07:00
|
|
|
|
printItemWrapper.SlicingDone -= sliceItem_Done;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
if (unregisterEvents != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
unregisterEvents(this, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-29 06:55:12 -08:00
|
|
|
|
private EventHandler unregisterEvents;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
private void ReloadAfterPrinterProfileChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
CreateWindowContent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void exportAMF_Click(object sender, EventArgs mouseEvent)
|
|
|
|
|
|
{
|
2015-06-11 12:06:40 -07:00
|
|
|
|
UiThread.RunOnIdle(() =>
|
2015-02-06 15:24:51 -08:00
|
|
|
|
{
|
2017-03-15 16:17:06 -07:00
|
|
|
|
SaveFileDialogParams saveParams = new SaveFileDialogParams("Save as AMF|*.amf", initialDirectory: documentsPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
Title = "MatterControl: Export File",
|
|
|
|
|
|
ActionButtonLabel = "Export",
|
|
|
|
|
|
FileName = printItemWrapper.Name
|
|
|
|
|
|
};
|
2015-02-06 15:24:51 -08:00
|
|
|
|
|
|
|
|
|
|
Close();
|
|
|
|
|
|
FileDialog.SaveFileDialog(saveParams, onExportAmfFileSelected);
|
|
|
|
|
|
});
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2014-02-07 16:26:46 -08:00
|
|
|
|
|
2015-07-21 11:10:01 -07:00
|
|
|
|
private async void onExportAmfFileSelected(SaveFileDialogParams saveParams)
|
2015-02-06 15:24:51 -08:00
|
|
|
|
{
|
2015-07-21 11:10:01 -07:00
|
|
|
|
await Task.Run(() => SaveAmf(saveParams));
|
2015-02-06 15:24:51 -08:00
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-07-21 11:10:01 -07:00
|
|
|
|
private void SaveAmf(SaveFileDialogParams saveParams)
|
2015-02-06 15:24:51 -08:00
|
|
|
|
{
|
2015-09-23 17:17:51 -07:00
|
|
|
|
try
|
2015-02-06 15:24:51 -08:00
|
|
|
|
{
|
2016-02-12 10:26:40 -08:00
|
|
|
|
if (!string.IsNullOrEmpty(saveParams.FileName))
|
2015-02-06 15:24:51 -08:00
|
|
|
|
{
|
2015-09-23 17:17:51 -07:00
|
|
|
|
string filePathToSave = saveParams.FileName;
|
|
|
|
|
|
if (filePathToSave != null && filePathToSave != "")
|
2015-02-06 15:24:51 -08:00
|
|
|
|
{
|
2015-09-23 17:17:51 -07:00
|
|
|
|
string extension = Path.GetExtension(filePathToSave);
|
|
|
|
|
|
if (extension == "")
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Delete(filePathToSave);
|
|
|
|
|
|
filePathToSave += ".amf";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Path.GetExtension(printItemWrapper.FileLocation).ToUpper() == Path.GetExtension(filePathToSave).ToUpper())
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Copy(printItemWrapper.FileLocation, filePathToSave, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-07-14 13:55:02 -07:00
|
|
|
|
IObject3D item = Object3D.Load(printItemWrapper.FileLocation, CancellationToken.None);
|
2017-03-15 16:17:06 -07:00
|
|
|
|
MeshFileIo.Save(item, filePathToSave);
|
2015-09-23 17:17:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
ShowFileIfRequested(filePathToSave);
|
2015-02-06 15:24:51 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-12-13 12:15:05 -08:00
|
|
|
|
catch (Exception e)
|
2015-09-23 17:17:51 -07:00
|
|
|
|
{
|
2016-12-13 12:15:05 -08:00
|
|
|
|
UiThread.RunOnIdle (() => {
|
|
|
|
|
|
StyledMessageBox.ShowMessageBox(null, e.Message, "Couldn't save file".Localize());
|
|
|
|
|
|
});
|
2015-09-23 17:17:51 -07:00
|
|
|
|
}
|
2015-02-06 15:24:51 -08:00
|
|
|
|
}
|
2014-11-06 07:16:55 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private void exportSTL_Click(object sender, EventArgs mouseEvent)
|
2015-02-06 15:24:51 -08:00
|
|
|
|
{
|
2015-06-11 12:06:40 -07:00
|
|
|
|
UiThread.RunOnIdle(() =>
|
2015-02-06 15:24:51 -08:00
|
|
|
|
{
|
|
|
|
|
|
SaveFileDialogParams saveParams = new SaveFileDialogParams("Save as STL|*.stl");
|
|
|
|
|
|
saveParams.Title = "MatterControl: Export File";
|
|
|
|
|
|
saveParams.ActionButtonLabel = "Export";
|
|
|
|
|
|
saveParams.FileName = printItemWrapper.Name;
|
|
|
|
|
|
|
|
|
|
|
|
Close();
|
|
|
|
|
|
FileDialog.SaveFileDialog(saveParams, onExportStlFileSelected);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2014-11-06 07:16:55 -08:00
|
|
|
|
|
2015-07-21 11:10:01 -07:00
|
|
|
|
private async void onExportStlFileSelected(SaveFileDialogParams saveParams)
|
2015-02-06 15:24:51 -08:00
|
|
|
|
{
|
2015-07-21 11:10:01 -07:00
|
|
|
|
await Task.Run(() => SaveStl(saveParams));
|
2015-02-06 15:24:51 -08:00
|
|
|
|
}
|
2014-11-06 07:16:55 -08:00
|
|
|
|
|
2015-07-21 11:10:01 -07:00
|
|
|
|
private void SaveStl(SaveFileDialogParams saveParams)
|
2014-10-11 15:11:26 -07:00
|
|
|
|
{
|
2015-09-23 17:17:51 -07:00
|
|
|
|
try
|
2014-02-18 12:51:11 -08:00
|
|
|
|
{
|
2016-02-12 10:26:40 -08:00
|
|
|
|
if (!string.IsNullOrEmpty(saveParams.FileName))
|
2014-10-11 15:11:26 -07:00
|
|
|
|
{
|
2015-09-23 17:17:51 -07:00
|
|
|
|
string filePathToSave = saveParams.FileName;
|
|
|
|
|
|
if (filePathToSave != null && filePathToSave != "")
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-09-23 17:17:51 -07:00
|
|
|
|
string extension = Path.GetExtension(filePathToSave);
|
|
|
|
|
|
if (extension == "")
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Delete(filePathToSave);
|
|
|
|
|
|
filePathToSave += ".stl";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Path.GetExtension(printItemWrapper.FileLocation).ToUpper() == Path.GetExtension(filePathToSave).ToUpper())
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Copy(printItemWrapper.FileLocation, filePathToSave, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-07-14 13:55:02 -07:00
|
|
|
|
IObject3D loadedItem = Object3D.Load(printItemWrapper.FileLocation, CancellationToken.None);
|
2017-03-15 16:17:06 -07:00
|
|
|
|
|
|
|
|
|
|
if (!MeshFileIo.Save(new List<MeshGroup> { loadedItem.Flatten() }, filePathToSave))
|
2016-12-13 12:15:05 -08:00
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle (() => {
|
|
|
|
|
|
StyledMessageBox.ShowMessageBox(null, "AMF to STL conversion failed", "Couldn't save file".Localize());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2015-09-23 17:17:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
ShowFileIfRequested(filePathToSave);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2014-10-11 15:11:26 -07:00
|
|
|
|
}
|
2014-02-18 12:51:11 -08:00
|
|
|
|
}
|
2016-12-13 12:15:05 -08:00
|
|
|
|
catch (Exception e)
|
2015-09-23 17:17:51 -07:00
|
|
|
|
{
|
2016-12-13 12:15:05 -08:00
|
|
|
|
UiThread.RunOnIdle (() => {
|
|
|
|
|
|
StyledMessageBox.ShowMessageBox(null, e.Message, "Couldn't save file".Localize());
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2015-09-23 17:17:51 -07:00
|
|
|
|
}
|
2014-10-11 15:11:26 -07:00
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private void sliceItem_Done(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
PrintItemWrapper sliceItem = (PrintItemWrapper)sender;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-07-21 08:10:05 -07:00
|
|
|
|
printItemWrapper.SlicingDone -= sliceItem_Done;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
SaveGCodeToNewLocation(sliceItem.GetGCodePathAndFileName(), gcodePathAndFilenameToSave);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|