Skip to content

Commit 8a8fd6e

Browse files
committed
1.8
* all about the counter and overflow * removed application settings and added ini file * removed need for ndesk.options.dll * some fixes....
1 parent 0bbbaba commit 8a8fd6e

File tree

8 files changed

+1530
-126
lines changed

8 files changed

+1530
-126
lines changed

Slic3rPostProcessing/Options.cs

Lines changed: 1253 additions & 0 deletions
Large diffs are not rendered by default.

Slic3rPostProcessing/Program.cs

Lines changed: 70 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
using System.Text;
66
using System.Text.RegularExpressions;
77
using System.Diagnostics;
8-
using NDesk.Options;
98
using System.Globalization;
9+
using System.Configuration;
10+
using System.Collections.Specialized;
11+
using Mono.Options;
1012

1113
namespace Slic3rPostProcessing
1214
{
@@ -21,6 +23,8 @@ internal class Program
2123
public static int ConsoleWidth { get; set; }
2224

2325
public static string strTimeformat = "yyMMdd-HHmmss";
26+
public static int intExportCounter;
27+
public static int intSizeOfCounter;
2428

2529
/// <summary>
2630
/// Post processing for Slic3r to color the toolpaths to view in Craftware
@@ -34,17 +38,22 @@ private static int Main(string[] args)
3438
{
3539
Properties.Settings.Default.Reload();
3640

37-
if (Properties.Settings.Default._UpdateRequired == true)
41+
string inifile = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "settings.ini");
42+
INI inisettings = new INI(inifile);
43+
44+
if (!File.Exists(inifile))
3845
{
39-
Properties.Settings.Default.Upgrade();
40-
Properties.Settings.Default._UpdateRequired = false;
41-
Properties.Settings.Default.Save();
46+
inisettings.WriteValue("ExportCounter", "PostProcessing", 0.ToString());
47+
inisettings.WriteValue("CounterPadding", "PostProcessing", 6.ToString());
48+
inisettings.Save();
4249
}
4350

51+
int.TryParse(inisettings.GetValue("ExportCounter", "PostProcessing"), out intExportCounter);
52+
int.TryParse(inisettings.GetValue("CounterPadding", "PostProcessing"), out intSizeOfCounter);
53+
4454
bool show_help = false;
4555

4656
int verbosity = 3;
47-
int intSizeOfCounter = Properties.Settings.Default._intCounterSize;
4857
double stopbeadheater = 0d;
4958
string strINputFile = null;
5059
string strOUTputFile = null;
@@ -67,11 +76,9 @@ private static int Main(string[] args)
6776
os.Add("o|output=", "The {OUTPUT} filename. " + Environment.NewLine + "Optional. {INPUT} will get overwritten if {OUTPUT} is not specified. File extension will be added if omitted.",
6877
o => strOUTputFile = o);
6978

70-
os.Add("c|counter=", "Adds an export-counter to the FRONT of the filename ({+ or -})." + Environment.NewLine + "Default: -c+ (true)" + Environment.NewLine + "If the timestamp is set to true as well, only the counter will be added.",
79+
os.Add("c|counter=", "Adds an export-counter to the FRONT of the filename ({+ or -}). Default: -c+ (true)" + Environment.NewLine + "Next counter: " + (intExportCounter).ToString("D" + intSizeOfCounter) + Environment.NewLine + "(If the timestamp is set to true as well, only the counter will be added.)",
7180
c => booCounter = c != null);
7281

73-
os.Add("cd|counterdigits=", "Counter padded with this many zeros {1-10}. Default " + intSizeOfCounter.ToString() + ". Next counter: " + (Properties.Settings.Default.export_counter + 1).ToString("D" + intSizeOfCounter.ToString()), (int cd) => { if (cd > 0 & cd < 11) intSizeOfCounter = cd; });
74-
7582
os.Add("r|removeconfig=", "Removes Configuration at end of file ({+ or -}). Everything after \"END FOOTER\" will be removed." + Environment.NewLine + "Default: -r- (false).",
7683
r => booRemoveConfig = r != null);
7784

@@ -128,23 +135,16 @@ private static int Main(string[] args)
128135

129136
if (booResetCounter)
130137
{
131-
Properties.Settings.Default.export_counter = 0;
132-
Properties.Settings.Default.Save();
138+
intExportCounter = 0;
139+
inisettings.WriteValue("ExportCounter", "PostProcessing", 0.ToString());
140+
inisettings.Save();
133141
Environment.Exit(3);
134142
return 3;
135143
}
136144

137-
if (Properties.Settings.Default._intCounterSize != intSizeOfCounter)
138-
{
139-
// add settings to user-settings
140-
Properties.Settings.Default._intCounterSize = intSizeOfCounter;
141-
Properties.Settings.Default.Save();
142-
//
143-
}
144-
145145
if (strINputFile == null)
146146
{
147-
// Console.WriteLine("I need an arguement; your's not good!");
147+
// Console.WriteLine("I need an argument; your's not good!");
148148
ShowHelp(os);
149149
Environment.Exit(1);
150150
return 1;
@@ -444,12 +444,6 @@ private static int Main(string[] args)
444444

445445
if (booCounter & booTimestamp) booTimestamp = false;
446446

447-
if (booCounter)
448-
{
449-
Properties.Settings.Default.export_counter++;
450-
Properties.Settings.Default.Save();
451-
}
452-
453447
Logger.LogInfo("Output :");
454448
if (strOUTputFile != null & File.Exists(newfilename))
455449
{
@@ -464,8 +458,8 @@ private static int Main(string[] args)
464458
}
465459
else if (booCounter)
466460
{
467-
string newfile = strOUTputFile.PrependCounter(intSizeOfCounter);
468-
File.Move(newfilename, strOUTputFile.PrependCounter(intSizeOfCounter));
461+
string newfile = strOUTputFile.PrependCounter();
462+
File.Move(newfilename, newfile);
469463
PrintFileSummary(newfile);
470464
}
471465
else
@@ -486,7 +480,7 @@ private static int Main(string[] args)
486480
}
487481
else if (booCounter)
488482
{
489-
string newfile = strINputFile.PrependCounter(intSizeOfCounter);
483+
string newfile = strINputFile.PrependCounter();
490484
File.Move(newfilename, newfile);
491485
PrintFileSummary(newfile);
492486
}
@@ -500,6 +494,18 @@ private static int Main(string[] args)
500494
if (stopbeadheater > 0) { Logger.LogInfo("Bed Heater disabled after height " + stopbeadheater + " mm."); }
501495
if (booRemoveConfig) { Logger.LogInfo("Configuration/Settings have been removed from GCode."); }
502496

497+
intExportCounter++;
498+
inisettings.WriteValue("ExportCounter", "PostProcessing", intExportCounter.ToString());
499+
inisettings.Save();
500+
501+
string ts = ((char)('\u25a0')).ToString().PadRight(5, '\u25a0');
502+
Logger.LogInfo(ts + " All Done " + ts);
503+
504+
//
505+
//
506+
//
507+
// END OF EVERYTHING
508+
503509
#if DEBUG
504510
{
505511
Console.WriteLine("Press any key to continue . . .");
@@ -509,10 +515,6 @@ private static int Main(string[] args)
509515
System.Threading.Thread.Sleep(500);
510516
#endif
511517

512-
string ts = ((char)('\u25a0')).ToString();
513-
ts = ts.PadRight(5, '\u25a0');
514-
Logger.LogInfo(ts + " All Done " + ts);
515-
516518
Environment.Exit(0);
517519
return 0;
518520
}
@@ -584,22 +586,22 @@ private static bool WaitForFile(string filename, int timeout = 30)
584586

585587
private static void Progressbar(double Progress, bool ReportAsPercentage = true, int Value = -1)
586588
{
587-
int conswidth = ConsoleWidth - 20;
589+
int conswidth = ConsoleWidth - 2;
588590
char pad = '\u2588'; // '█';
589591
char spad = '\u2591'; // '░';
590592
string prog = "";
591593
string progformat = "";
592-
double newprog;
593-
594-
newprog = (Value != -1) ? Value : Progress / 100;
594+
double newprog = (Value != -1) ? Value : Progress / 100;
595595

596-
progformat = ReportAsPercentage ? String.Format("{0:P0} ", newprog).PadRight(5) : String.Format("{0} ", newprog).PadRight(5);
596+
progformat = ReportAsPercentage ? String.Format("{0:P0} ", newprog).PadRight(5).PadLeft(10) : String.Format("{0} ", newprog).PadRight(5).PadLeft(10);
597+
//progformat = " " + progformat;
597598

598-
double doh = Progress / 100 * conswidth;
599+
conswidth -= progformat.Length;
600+
double consprog = Progress / 100 * conswidth;
599601

600-
int progr = (int)Math.Round(doh, 0);
602+
int progr = (int)Math.Round(consprog, 0);
601603

602-
string mynewfunkyprogressbar = " " +
604+
string mynewfunkyprogressbar =
603605
progformat +
604606
prog.PadLeft(progr, pad) +
605607
prog.PadLeft(conswidth - progr, spad);
@@ -630,37 +632,39 @@ private static string TrimComment(string line)
630632

631633
private static void ShowHelp(OptionSet p)
632634
{
635+
string pathname = Path.GetFullPath(System.Reflection.Assembly.GetEntryAssembly().Location);
636+
633637
ConsoleColor fg = Console.ForegroundColor;
634638
ConsoleColor bg = Console.BackgroundColor;
635639

636640
Console.WriteLine();
637641
Console.BackgroundColor = ConsoleColor.Black;
638642
Console.ForegroundColor = ConsoleColor.Yellow;
639643

640-
string textnote = "This program is for use with Slic3r (or standalone).";
641-
int paaad = (Program.ConsoleWidth - textnote.Length) / 2;
644+
string textnote = "This program is for use with Slic3r (standalone use see below).";
645+
int paddin = (Program.ConsoleWidth - textnote.Length) / 2;
642646

643-
Console.WriteLine("".PadLeft(paaad) + textnote.PadRight(Program.ConsoleWidth - paaad));
647+
Console.WriteLine("".PadLeft(paddin) + textnote.PadRight(Program.ConsoleWidth - paddin));
644648
Console.ResetColor();
645649
Console.WriteLine();
646650
Console.WriteLine(" Print Settings -> Output options");
647651
Console.WriteLine(" * Enable Verbose G-Code (!)");
648652

649-
Console.WriteLine(" * Put this filename " + Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location) + " in Post-Processing Scripts.");
650-
Console.WriteLine(" Current filename: \"" + System.Reflection.Assembly.GetEntryAssembly().Location + "\"");
653+
Console.WriteLine(" * Put this filename in Post-Processing Scripts:");
654+
Console.WriteLine(" \"" + pathname + "\"");
651655

652656
Console.WriteLine("");
653657
Console.WriteLine(" Printer Settings:");
654-
Console.WriteLine(" * Add \"; START Header\" and \"; END Header\" to your Start GCode.");
655-
Console.WriteLine(" * Add \"; START Footer\" and \"; END Footer\" to your End GCode.");
658+
Console.WriteLine(" * Add \'; START Header\' and \'; END Header\' to your Start GCode.");
659+
Console.WriteLine(" * Add \'; START Footer\' and \'; END Footer\' to your End GCode.");
656660

657661
Console.WriteLine();
658662
Console.BackgroundColor = ConsoleColor.Black;
659663
Console.ForegroundColor = ConsoleColor.Yellow;
660664

661-
textnote = "Standalone usage: Slic3rPostProcessing [OPTIONS]";
662-
paaad = (Program.ConsoleWidth - textnote.Length) / 2;
663-
Console.WriteLine("".PadLeft(paaad) + textnote.PadRight(Program.ConsoleWidth - paaad));
665+
textnote = "Standalone use: Slic3rPostProcessing [OPTIONS]";
666+
paddin = (Program.ConsoleWidth - textnote.Length) / 2;
667+
Console.WriteLine("".PadLeft(paddin) + textnote.PadRight(Program.ConsoleWidth - paddin));
664668

665669
Console.ResetColor();
666670
Console.WriteLine();
@@ -709,6 +713,11 @@ public static class DonotReset
709713

710714
public static class MyExtensions
711715
{
716+
public static double hoch(this double das, double Exponent)
717+
{
718+
return Math.Pow(das, Exponent);
719+
}
720+
712721
public static string AppendTimeStamp(this string fileName)
713722
{
714723
return Path.Combine(Path.GetDirectoryName(fileName),
@@ -718,14 +727,19 @@ public static string AppendTimeStamp(this string fileName)
718727
+ Path.GetExtension(fileName));
719728
}
720729

721-
public static string PrependCounter(this string fileName, int digits)
730+
/// <summary>
731+
/// Adds counter to fileName
732+
/// </summary>
733+
/// <param name="fileName">Filename to add counter to</param>
734+
/// <param name="counter">Counter to add</param>
735+
/// <param name="digits">Number of digits padded with zero</param>
736+
/// <returns></returns>
737+
public static string PrependCounter(this string fileName)
722738
{
723-
int counter = Properties.Settings.Default.export_counter;
724-
725-
string numformat = "D" + digits.ToString();
739+
string numformat = "D" + Program.intSizeOfCounter.ToString();
726740

727741
return Path.Combine(Path.GetDirectoryName(fileName),
728-
counter.ToString(numformat)
742+
Program.intExportCounter.ToString(numformat)
729743
+ "_"
730744
+ Path.GetFileNameWithoutExtension(fileName)
731745
+ Path.GetExtension(fileName));

Slic3rPostProcessing/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.7.*")]
35+
[assembly: AssemblyVersion("1.8")]
3636
//[assembly: AssemblyFileVersion("1.0.0.0")]

Slic3rPostProcessing/Properties/Settings.Designer.cs

Lines changed: 0 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
<?xml version='1.0' encoding='utf-8'?>
2-
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Slic3rPostProcessing.Properties" GeneratedClassName="Settings">
2+
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
33
<Profiles />
4-
<Settings>
5-
<Setting Name="export_counter" Type="System.Int32" Scope="User">
6-
<Value Profile="(Default)">0</Value>
7-
</Setting>
8-
<Setting Name="_UpdateRequired" Type="System.Boolean" Scope="User">
9-
<Value Profile="(Default)">True</Value>
10-
</Setting>
11-
<Setting Name="_intCounterSize" Type="System.Int32" Scope="User">
12-
<Value Profile="(Default)">5</Value>
13-
</Setting>
14-
</Settings>
4+
<Settings />
155
</SettingsFile>

Slic3rPostProcessing/Slic3rPostProcessing.csproj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@
4545
<SignAssembly>false</SignAssembly>
4646
</PropertyGroup>
4747
<ItemGroup>
48-
<Reference Include="NDesk.Options, Version=0.2.1.0, Culture=neutral, processorArchitecture=MSIL">
49-
<HintPath>..\packages\NDesk.Options.0.2.1\lib\NDesk.Options.dll</HintPath>
50-
<Private>True</Private>
51-
</Reference>
5248
<Reference Include="System" />
5349
<Reference Include="System.Core" />
5450
<Reference Include="System.Xml.Linq" />
@@ -58,6 +54,8 @@
5854
<Reference Include="System.Xml" />
5955
</ItemGroup>
6056
<ItemGroup>
57+
<Compile Include="clsINI.cs" />
58+
<Compile Include="Options.cs" />
6159
<Compile Include="Program.cs" />
6260
<Compile Include="Properties\AssemblyInfo.cs" />
6361
<Compile Include="Properties\Settings.Designer.cs">
@@ -79,7 +77,12 @@
7977
</ItemGroup>
8078
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8179
<PropertyGroup>
82-
<PostBuildEvent>if "$(ConfigurationName)" == "Release" xcopy "$(TargetPath)" "c:\MyProgramme\Slic3r_PostProcessing\" /r /y /c /v /q</PostBuildEvent>
80+
<PostBuildEvent>if "$(ConfigurationName)" == "Release" xcopy "$(TargetDir)*.*" "c:\MyProgramme\Slic3r_PostProcessing\" /r /y /c /v /q
81+
if "$(ConfigurationName)" == "Release" xcopy "$(TargetDir)*.*" "i:\H Technologiezentrum\Simulation\3D_Printing\Sofware\Slic3r_PostProcessing\" /r /y /c /v /q
82+
83+
84+
85+
</PostBuildEvent>
8386
</PropertyGroup>
8487
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
8588
Other similar extension points exist, see Microsoft.Common.targets.

Slic3rPostProcessing/app.config

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<configuration>
33
<configSections>
4-
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
5-
<section name="Slic3rPostProcessing.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
6-
</sectionGroup>
74
</configSections>
8-
<userSettings>
9-
<Slic3rPostProcessing.Properties.Settings>
10-
<setting name="export_counter" serializeAs="String">
11-
<value>0</value>
12-
</setting>
13-
<setting name="_UpdateRequired" serializeAs="String">
14-
<value>True</value>
15-
</setting>
16-
<setting name="_intCounterSize" serializeAs="String">
17-
<value>5</value>
18-
</setting>
19-
</Slic3rPostProcessing.Properties.Settings>
20-
</userSettings>
215
</configuration>

0 commit comments

Comments
 (0)