forked from MatterHackers/MatterSlice
/
main.cs
167 lines (147 loc) · 6.87 KB
/
main.cs
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
Copyright (C) 2013 David Braam
Copyright (c) 2014, Lars Brubaker
This file is part of MatterSlice.
MatterSlice is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MatterSlice is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MatterSlice. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Globalization;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
namespace MatterHackers.MatterSlice
{
public static class MatterSlice
{
static void print_usage()
{
LogOutput.logError("usage: MatterSlice [-h] [-d] [-v] [-m 3x3matrix] [-c <config file>]\n [-s <settingkey>=<value>] -o <output.gcode> <model.stl>\n\n");
LogOutput.logError(" [] enclose optional settings, <> are required.\n\n");
LogOutput.logError(" -h Show this message.\n");
LogOutput.logError(" -d Save the currently loaded settings to settings.ini (usefull to see all settings).\n");
LogOutput.logError(" -v Increment verbose level.\n");
LogOutput.logError(" -m A 3x3 matrix for translating and rotating the layers.\n");
LogOutput.logError(" -c A config file to apply to the current settings.\n Can be applyed multiple times.\n Formated like the default.ini (partial settings are fine).\n");
LogOutput.logError(" -s Specify a setting on the command line.\n Uses the same names and values as default.ini.\n");
LogOutput.logError(" -o Specify the path and filename to save 'output.gcode'.\n");
LogOutput.logError(" model.stl, the file that will be loaded and sliced.\n");
}
static int Main(string[] args)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
return ProcessArgs(args);
}
public static int ProcessArgs(string argsInString)
{
List<string> commands = new List<string>();
foreach (string command in SplitCommandLine.DoSplit(argsInString))
{
commands.Add(command);
}
string[] args = commands.ToArray();
return ProcessArgs(args);
}
public static int ProcessArgs(string[] args)
{
#if DEBUG
Tests.BridgeTests.Run();
#endif
ConfigSettings config = new ConfigSettings();
fffProcessor processor = new fffProcessor(config);
LogOutput.log("\nMatterSlice version {0}\n\n".FormatWith(ConfigConstants.VERSION));
for (int argn = 0; argn < args.Length; argn++)
{
string str = args[argn];
if (str[0] == '-')
{
for (int stringIndex = 1; stringIndex < str.Length; stringIndex++)
{
switch (str[stringIndex])
{
case 'h':
print_usage();
return 0;
case 'v':
LogOutput.verbose_level++;
break;
case 'o':
argn++;
if (!processor.setTargetFile(args[argn]))
{
LogOutput.logError("Failed to open {0} for output.\n".FormatWith(args[argn]));
return 1;
}
break;
case 'c':
{
// Read a config file from the given path
argn++;
if (!config.ReadSettings(args[argn]))
{
LogOutput.logError("Failed to read config '{0}'\n".FormatWith(args[argn]));
}
}
break;
case 'd':
config.DumpSettings("settings.ini");
break;
case 's':
{
argn++;
int equalsPos = args[argn].IndexOf('=');
if (equalsPos != -1)
{
string key = args[argn].Substring(0, equalsPos);
string value = args[argn].Substring(equalsPos+1);
if (key.Length > 1)
{
if (!config.SetSetting(key, value))
{
LogOutput.logError("Setting not found: {0} {1}\n".FormatWith(key, value));
}
}
}
}
break;
case 'm':
argn++;
throw new NotImplementedException("m");
#if false
sscanf(argv[argn], "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
&config.matrix.m[0][0], &config.matrix.m[0][1], &config.matrix.m[0][2],
&config.matrix.m[1][0], &config.matrix.m[1][1], &config.matrix.m[1][2],
&config.matrix.m[2][0], &config.matrix.m[2][1], &config.matrix.m[2][2]);
#endif
break;
default:
throw new NotImplementedException("Unknown option: {0}\n".FormatWith(str));
LogOutput.logError("Unknown option: {0}\n".FormatWith(str));
break;
}
}
}
else
{
processor.processFile(args[argn]);
}
}
processor.finalize();
return 0;
}
public static void AssertDebugNotDefined()
{
#if DEBUG
throw new Exception("DEBUG is defined and should not be!");
#endif
}
}
}