blob: b46f03a28b99cf29b94fc67c2251a86defdaf024 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/*
* 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.HaveGCode;
public string GCodeStr => SlicerFile?.GCodeStr;
public int GCodeLines => !HaveGCode ? 0 : SlicerFile.GCodeStr.Split('\n').Length;
public void OnClickRebuildGcode()
{
if (!HaveGCode) return;
SlicerFile.RebuildGCode();
RaisePropertyChanged(nameof(GCodeLines));
RaisePropertyChanged(nameof(GCodeStr));
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
{
using (TextWriter tw = new StreamWriter(file))
{
tw.Write(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(GCodeStr);
}
}
}
|