Files
UVtools/UVtools.WPF/MainWindow.GCode.cs
T
Tiago Conceição c289954753 v2.14.3
- (Add) Exposure time finder: Base layers print modes, a option to speed up the print process and merge all base layers in the same height
- (Add) GCode tab: Allow to temporarily edit and use custom gcode
- (Change) Zcode: Omit M18 at end of the gcode to prevent carrier goes up and crash to the limit at a end of a print
2021-07-12 02:01:02 +01:00

77 lines
2.4 KiB
C#

/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
using System;
using System.IO;
using Avalonia;
using Avalonia.Controls;
using MessageBox.Avalonia.Enums;
using UVtools.WPF.Extensions;
using Helpers = UVtools.WPF.Controls.Helpers;
namespace UVtools.WPF
{
public partial class MainWindow
{
public bool HaveGCode => IsFileLoaded && SlicerFile.SupportsGCode;
public uint GCodeLines => !HaveGCode ? 0 : SlicerFile.GCode.LineCount;
public void OnClickRebuildGcode()
{
if (!HaveGCode) return;
var temp = SlicerFile.SuppressRebuildGCode;
SlicerFile.SuppressRebuildGCode = false;
SlicerFile.RebuildGCode();
SlicerFile.SuppressRebuildGCode = temp;
RaisePropertyChanged(nameof(GCodeLines));
CanSave = true;
}
public async void OnClickGCodeSaveFile()
{
if (!HaveGCode) return;
var dialog = new SaveFileDialog
{
Filters = Helpers.IniFileFilter,
Directory = Path.GetDirectoryName(SlicerFile.FileFullPath),
InitialFileName = $"{Path.GetFileNameWithoutExtension(SlicerFile.FileFullPath)}_gcode.txt"
};
var file = await dialog.ShowAsync(this);
if (string.IsNullOrEmpty(file)) return;
try
{
await using TextWriter tw = new StreamWriter(file);
await tw.WriteAsync(SlicerFile.GCodeStr);
tw.Close();
}
catch (Exception e)
{
await this.MessageBoxError(e.ToString(), "Error occur while save gcode");
return;
}
var result = await this.MessageBoxQuestion(
"GCode save was successful. Do you want open the file in the default editor?",
"GCode save complete");
if (result != ButtonResult.Yes) return;
App.StartProcess(file);
}
public void OnClickGCodeSaveClipboard()
{
if (!HaveGCode) return;
Application.Current.Clipboard.SetTextAsync(SlicerFile.GCodeStr);
}
}
}