Skip to content

Commit 283cea7

Browse files
committed
... all the small things ...
1 parent 3d452c4 commit 283cea7

File tree

2 files changed

+77
-52
lines changed

2 files changed

+77
-52
lines changed

Slic3rPostProcessing/Program.cs

Lines changed: 76 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,38 @@ private static int Main(string[] args)
6262

6363
ConsoleWidth = Logger.GetConsoleWidth();
6464

65-
var p = new OptionSet() {
66-
{ "i|input=", "The {INPUTFILE} to process. " + Environment.NewLine + "If file extention is omitted, .gcode will be assumed.",
67-
v => strINputFile=v },
68-
{ "o|output=", "The {OUTPUTFILE} filename. " + Environment.NewLine + "Optional. {INPUTFILE} will get overwritten if {OUTPUTFILE} is not specified. File extension will be added if omitted.",
69-
v => strOUTputFile=v },
70-
{ "c|counter=","Adds an export-counter to the FRONT of the filename." + Environment.NewLine + "{+ or -}; Default = + " + Environment.NewLine + "If the timestamp is set to true, too, then only the counter will be added.",
71-
t => booCounter = t != null },
72-
{ "f|formatstamp=","{FORMAT} of the timestamp. " + Environment.NewLine + "Default: " + strTimeformat + Environment.NewLine + "(right now: "+DateTime.Now.ToString(strTimeformat)+")" ,
73-
tf => strTimeformat = tf },
74-
{ "s|stopbedheater=","Stops heating of the bed after this height in millimeter; Default = 0 = off",
75-
(double s) => { if ( s >= 0 ) stopbeadheater = s; } },
76-
{ "t|timestamp=","Adds a timestamp to the END of the filename." + Environment.NewLine + "{+ or -}; Default = -",
77-
t => booTimestamp = t != null },
78-
{ "v|verbosity=", "Debug message verbosity. Default: "+ verbosity +". " + Environment.NewLine + "{INT}:" + Environment.NewLine + "0 = Off " + Environment.NewLine + "1 = Error " + Environment.NewLine + "2 = Warning " + Environment.NewLine + "3 = Info " + Environment.NewLine + "4 = Verbose (will output EVERY line of GCode! There will be LOTS of output!)",
79-
(int v) => { if ( v >= 0 & v <5) verbosity = v; } },
80-
{ "resetcounter=","Reset export-counter to zero and exit (3).",
81-
t => booResetCounter = t != null },
82-
{ "h|help", "Show this message and exit (2). Nothing will be done.",
83-
v => show_help = v != null },
84-
};
65+
OptionSet os = new OptionSet();
66+
os.Add("i|input=", "The {INPUTFILE} to process. " + Environment.NewLine + "If file extention is omitted, .gcode will be assumed.",
67+
v => strINputFile = v);
68+
69+
os.Add("o|output=", "The {OUTPUTFILE} filename. " + Environment.NewLine + "Optional. {INPUTFILE} will get overwritten if {OUTPUTFILE} is not specified. File extension will be added if omitted.",
70+
v => strOUTputFile = v);
71+
72+
os.Add("c|counter=", "Adds an export-counter to the FRONT of the filename." + Environment.NewLine + "{+ or -}; Default = + " + Environment.NewLine + "If the timestamp is set to true, too, then only the counter will be added.",
73+
t => booCounter = t != null);
74+
75+
os.Add("f|formatstamp=", "{FORMAT} of the timestamp. " + Environment.NewLine + "Default: " + strTimeformat + Environment.NewLine + "(right now: " + DateTime.Now.ToString(strTimeformat) + ")",
76+
tf => strTimeformat = tf);
77+
78+
os.Add("s|stopbedheater=", "Stops heating of the bed after this height in millimeter; Default = 0 = off",
79+
(double s) => { if (s >= 0) stopbeadheater = s; });
80+
81+
os.Add("t|timestamp=", "Adds a timestamp to the END of the filename." + Environment.NewLine + "{+ or -}; Default = -",
82+
t => booTimestamp = t != null);
83+
84+
os.Add("v|verbosity=", "Debug message verbosity. Default: " + verbosity + ". " + Environment.NewLine + "{INT}:" + Environment.NewLine + "0 = Off " + Environment.NewLine + "1 = Error " + Environment.NewLine + "2 = Warning " + Environment.NewLine + "3 = Info " + Environment.NewLine + "4 = Verbose (will output EVERY line of GCode! There will be LOTS of output!)",
85+
(int v) => { if (v >= 0 & v < 5) verbosity = v; });
86+
87+
os.Add("resetcounter=", "Reset export-counter to zero and exit (3).",
88+
t => booResetCounter = t != null);
89+
90+
os.Add("h|help", "Show this message and exit (2). Nothing will be done.",
91+
v => show_help = v != null);
8592

8693
List<string> extra;
8794
try
8895
{
89-
extra = p.Parse(args);
96+
extra = os.Parse(args);
9097

9198
if (extra.Count == 1 & args.Length == 1) strINputFile = extra[0];
9299

@@ -98,14 +105,14 @@ private static int Main(string[] args)
98105
catch (OptionException e)
99106
{
100107
Logger.LogError(e.Message);
101-
ShowHelp(p);
108+
ShowHelp(os);
102109
Environment.Exit(1);
103110
return 1;
104111
}
105112

106113
if (show_help)
107114
{
108-
ShowHelp(p);
115+
ShowHelp(os);
109116
Environment.Exit(2);
110117
return 2;
111118
}
@@ -121,17 +128,17 @@ private static int Main(string[] args)
121128
if (strINputFile == null)
122129
{
123130
// Console.WriteLine("I need an arguement; your's not good!");
124-
ShowHelp(p);
131+
ShowHelp(os);
125132
Environment.Exit(1);
126133
return 1;
127134
}
128135
else
129136
{
130-
if (!WaitForFile(strINputFile, 30))
137+
if (!WaitForFile(strINputFile, 5))
131138
{
132139
Console.WriteLine(" ");
133-
Logger.LogWarning("I assume there is no file:");
134-
PrintFileSummary(strINputFile);
140+
Logger.LogWarning("File not found:");
141+
PrintFileSummary(strINputFile, true);
135142
Logger.LogWarning("Please try again later or check your input.");
136143
#if DEBUG
137144
{
@@ -220,21 +227,24 @@ private static int Main(string[] args)
220227

221228
if (StartGCode == true & EndGCode == false)
222229
{
223-
Match matchlayerheight = Regex.Match(l, @"^(?:G1)\s(Z(\d+(\.\d+)?|\.\d+?))", RegexOptions.IgnoreCase);
224-
225-
if (matchlayerheight.Success)
230+
//
231+
// Stop Bed Heater
232+
if (stopbeadheater > 0)
226233
{
227-
currentlayerheight = Convert.ToDouble(matchlayerheight.Groups[2].Value);
228-
Logger.LogVerbose("Current Layer Height: " + currentlayerheight + " mm");
229-
if (stopbeadheater > 0)
234+
Match matchlayerheight = Regex.Match(l, @"^(?:G1)\s(Z(\d+(\.\d+)?|\.\d+?))", RegexOptions.IgnoreCase);
235+
236+
if (matchlayerheight.Success)
230237
{
238+
currentlayerheight = Convert.ToDouble(matchlayerheight.Groups[2].Value);
239+
Logger.LogVerbose("Current Layer Height: " + currentlayerheight + " mm");
240+
231241
if (currentlayerheight >= stopbeadheater & (bedheaterstopped == false))
232242
{
233243
sb.AppendLine("M140 S0; Stop Bed Heater on Layer Height " + currentlayerheight + " mm");
244+
sb.AppendLine("M117 Stopping Bed Heater.");
245+
234246
bedheaterstopped = true;
235247
stopbeadheater = currentlayerheight;
236-
sb.AppendLine(l);
237-
continue;
238248
}
239249
}
240250
}
@@ -465,7 +475,7 @@ private static int Main(string[] args)
465475
catch (Exception ex)
466476
{
467477
Logger.LogError(ex.Message);
468-
ShowHelp(p);
478+
ShowHelp(os);
469479
Environment.Exit(1);
470480
return 1;
471481
}
@@ -496,7 +506,7 @@ private static bool WaitForFile(string filename, int timeout = 30)
496506
if (wait == waitfor + 1)
497507
{
498508
Console.WriteLine("");
499-
Logger.LogInfo("Waiting for input file (" + Path.GetFileName(filename) + ") at " + Environment.NewLine + " " + Path.GetDirectoryName(filename));
509+
Logger.LogInfo("Waiting for input file (" + Path.GetFileName(filename) + ") at " + Environment.NewLine + " " + Path.GetDirectoryName(filename));
500510
}
501511

502512
int prog = 100 - (dt * 100 / timeout);
@@ -553,10 +563,18 @@ private static void Progressbar(double Progress, bool ReportAsPercentage = true,
553563
Logger.LogInfoOverwrite(mynewfunkyprogressbar);
554564
}
555565

556-
private static void PrintFileSummary(string filename)
566+
private static void PrintFileSummary(string filename, bool asWarning = false)
557567
{
558-
Logger.LogInfo(" File name : \"" + Path.GetFileName(filename) + "\"");
559-
if (Path.GetDirectoryName(filename) != "") Logger.LogInfo(" Directory : \"" + Path.GetDirectoryName(filename) + "\"");
568+
if (asWarning)
569+
{
570+
Logger.LogWarning(" File name : \"" + Path.GetFileName(filename) + "\"");
571+
if (Path.GetDirectoryName(filename) != "") Logger.LogWarning(" Directory : \"" + Path.GetDirectoryName(filename) + "\"");
572+
}
573+
else
574+
{
575+
Logger.LogInfo(" File name : \"" + Path.GetFileName(filename) + "\"");
576+
if (Path.GetDirectoryName(filename) != "") Logger.LogInfo(" Directory : \"" + Path.GetDirectoryName(filename) + "\"");
577+
}
560578
}
561579

562580
private static string TrimComment(string line)
@@ -576,8 +594,7 @@ private static void ShowHelp(OptionSet p)
576594
Console.ForegroundColor = ConsoleColor.Yellow;
577595

578596
string textnote = "This program is for use with Slic3r (or standalone).";
579-
int textlength = textnote.Length;
580-
int paaad = (Program.ConsoleWidth - textlength) / 2;
597+
int paaad = (Program.ConsoleWidth - textnote.Length) / 2;
581598

582599
Console.WriteLine("".PadLeft(paaad) + textnote.PadRight(Program.ConsoleWidth - paaad));
583600
Console.ResetColor();
@@ -590,7 +607,11 @@ private static void ShowHelp(OptionSet p)
590607
Console.WriteLine();
591608
Console.BackgroundColor = ConsoleColor.Black;
592609
Console.ForegroundColor = ConsoleColor.Yellow;
593-
Console.WriteLine("Standalone usage: Slic3rPostProcessing [OPTIONS]".PadRight(Program.ConsoleWidth));
610+
611+
textnote = "Standalone usage: Slic3rPostProcessing [OPTIONS]";
612+
paaad = (Program.ConsoleWidth - textnote.Length) / 2;
613+
Console.WriteLine("".PadLeft(paaad) + textnote.PadRight(Program.ConsoleWidth - paaad));
614+
594615
Console.ResetColor();
595616
Console.WriteLine();
596617
Console.WriteLine("Options:");
@@ -672,7 +693,8 @@ internal class Logger
672693
public static int GetConsoleWidth()
673694
{
674695
// IntPtr myHandle = Process.GetCurrentProcess().MainWindowHandle;
675-
// NOW WHAT?! What do I do with myHandle? I Need the console!
696+
// NOW WHAT?! What do I do with myHandle? I Need the console to return
697+
// the width of the window.
676698

677699
//return Console.WindowWidth;
678700

@@ -681,7 +703,7 @@ public static int GetConsoleWidth()
681703

682704
public static void LogInfo(string message)
683705
{
684-
Trace.WriteLineIf(Logger.traceSwitch.TraceInfo, "Info : " + message);
706+
Trace.WriteLineIf(Logger.traceSwitch.TraceInfo, "Info : " + message);
685707
}
686708

687709
/// <summary>
@@ -709,10 +731,16 @@ public static void LogError(string message)
709731

710732
public static void LogWarning(string message)
711733
{
712-
Console.ForegroundColor = ConsoleColor.Yellow;
713-
Console.BackgroundColor = ConsoleColor.Black;
714-
Trace.WriteLineIf(Logger.traceSwitch.TraceWarning, "WARNING : " + message);
734+
string warn = "WARNING :";
735+
736+
Console.ForegroundColor = ConsoleColor.Black;
737+
Console.BackgroundColor = ConsoleColor.Yellow;
738+
Trace.WriteLineIf(Logger.traceSwitch.TraceWarning, warn);
715739
Console.ResetColor();
740+
741+
Console.SetCursorPosition(warn.Length + 1, Console.CursorTop - 1);
742+
Trace.WriteIf(Logger.traceSwitch.TraceWarning, message);
743+
Trace.WriteLineIf(Logger.traceSwitch.TraceWarning, "");
716744
}
717745

718746
public static void LogError(Exception e)

Slic3rPostProcessing/Slic3rPostProcessing.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
</Compile>
6868
</ItemGroup>
6969
<ItemGroup>
70-
<Content Include="S3erPP.ico" />
7170
<Content Include="SPPIcon.ico" />
7271
</ItemGroup>
7372
<ItemGroup>
@@ -81,9 +80,7 @@
8180
</ItemGroup>
8281
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8382
<PropertyGroup>
84-
<PostBuildEvent>if "$(ConfigurationName)" == "Release" xcopy "$(TargetPath)" "c:\MyProgramme\Slic3r_PostProcessing\" /r /y /c /v /q
85-
86-
</PostBuildEvent>
83+
<PostBuildEvent>if "$(ConfigurationName)" == "Release" xcopy "$(TargetPath)" "c:\MyProgramme\Slic3r_PostProcessing\" /r /y /c /v /q</PostBuildEvent>
8784
</PropertyGroup>
8885
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
8986
Other similar extension points exist, see Microsoft.Common.targets.

0 commit comments

Comments
 (0)