@@ -23,13 +23,15 @@ You should have received a copy of the GNU Lesser General Public
2323*/
2424
2525using System ;
26+ using System . Collections ;
2627using System . Collections . Generic ;
2728using System . Linq ;
2829using System . Numerics ;
2930using System . Runtime . CompilerServices ;
3031using System . Security . Cryptography . X509Certificates ;
3132using System . Text ;
3233using System . Text . RegularExpressions ;
34+ using System . Globalization ;
3335using OpenVectorFormat . Utils ;
3436
3537namespace OpenVectorFormat . GCodeReaderWriter
@@ -64,20 +66,7 @@ class ToolParams
6466 int toolNumber ;
6567 }
6668
67- public enum GCodeType
68- {
69- LinearInterpolation ,
70- CircularInterpolation ,
71- Pause ,
72- ToolManipulation ,
73- Monitoring ,
74- ProgramLogics ,
75- BlockEnd ,
76- ProgramEnd ,
77- Misc
78- }
79-
80- internal class GCodeState
69+ public class GCodeState
8170 {
8271 private readonly Dictionary < int , Type > _gCodeTranslations = new Dictionary < int , Type >
8372 {
@@ -88,6 +77,13 @@ internal class GCodeState
8877 { 4 , typeof ( PauseCommand ) } ,
8978 } ;
9079
80+ internal class GCodeProperties
81+ {
82+ internal Type gCodeType ;
83+ internal List < char > recordedParams ;
84+ internal Dictionary < char , float > miscParams ;
85+ }
86+
9187 internal class GCodeMarkingParams
9288 {
9389 // Marking parameters
@@ -109,25 +105,27 @@ internal GCodeMarkingParams()
109105 }
110106 }
111107
112- internal class GCodePositions
108+ internal class GCodePosition
113109 {
114110 internal Vector3 position ;
115111 internal Vector2 centerRel ;
116- internal GCodePositions ( )
112+ internal GCodePosition ( )
117113 {
118114
119115 }
120116 }
121117
122- private Dictionary < int , GCodeType > _mCodeTranslations = new Dictionary < int , GCodeType > ( ) ;
118+ private Dictionary < int , Type > _mCodeTranslations = new Dictionary < int , Type > ( ) ;
123119
124- private Dictionary < int , GCodeType > _tCodeTranslations = new Dictionary < int , GCodeType > ( ) ;
120+ private Dictionary < int , Type > _tCodeTranslations = new Dictionary < int , Type > ( ) ;
125121
126- internal GCodeCommand gCodeCommand ;
122+ public GCodeCommand gCodeCommand ;
127123 internal Vector3 position ;
128124
129125 public GCodeState ( string serializedCmdLine )
130126 {
127+ CultureInfo . DefaultThreadCurrentCulture = CultureInfo . InvariantCulture ;
128+ CultureInfo . DefaultThreadCurrentUICulture = CultureInfo . InvariantCulture ;
131129 this . gCodeCommand = ParseToGCodeCommand ( serializedCmdLine ) ;
132130 }
133131
@@ -145,6 +143,7 @@ public GCodeCommand ParseToGCodeCommand(string serializedCmdLine)
145143 throw new ArgumentException ( $ "Invalid number format: { commandNumber } in line '{ serializedCmdLine } '") ;
146144
147145 Dictionary < char , float > commandParams = new Dictionary < char , float > ( ) ;
146+ Console . WriteLine ( string . Join ( Environment . NewLine , commandArr ) ) ;
148147
149148 foreach ( var commandParam in commandArr . Skip ( 1 ) )
150149 {
@@ -161,13 +160,13 @@ public GCodeCommand ParseToGCodeCommand(string serializedCmdLine)
161160 throw new ArgumentException ( $ "Invalid command parameter format: { commandParam } in line '{ serializedCmdLine } '. Command parameters must be of format <char><float>") ;
162161 }
163162 }
164-
163+ Console . WriteLine ( string . Join ( Environment . NewLine , commandParams ) ) ;
165164 if ( _gCodeTranslations . TryGetValue ( codeNumber , out Type gCodeClassType ) )
166165 {
167- return Activator . CreateInstance ( gCodeClassType , commandParams ) as GCodeCommand ;
166+ return Activator . CreateInstance ( gCodeClassType , new Object [ ] { prepCode , codeNumber , commandParams } ) as GCodeCommand ;
168167 }
169168
170- return Activator . CreateInstance ( typeof ( MiscCommand ) , commandParams ) as GCodeCommand ;
169+ return Activator . CreateInstance ( typeof ( MiscCommand ) , new Object [ ] { prepCode , codeNumber , commandParams } ) as GCodeCommand ;
171170 }
172171
173172 public bool [ ] Update ( string serializedCmdLine )
@@ -241,22 +240,39 @@ public class GCodeCommand
241240
242241 public GCodeCommand ( GCode gCode , Dictionary < char , float > commandParams = null )
243242 {
243+ miscParams = new Dictionary < char , float > ( ) ;
244+ recordedParams = new List < char > ( ) ;
245+ parameterMap = new Dictionary < char , Action < float > > ( ) ;
244246 this . gCode = gCode ;
245247 }
246248
247249 public GCodeCommand ( PrepCode prepCode , int codeNumber , Dictionary < char , float > commandParams = null )
248250 {
251+ miscParams = new Dictionary < char , float > ( ) ;
252+ recordedParams = new List < char > ( ) ;
253+ parameterMap = new Dictionary < char , Action < float > > ( ) ;
249254 this . gCode = new GCode ( prepCode , codeNumber ) ;
250255 }
251256
252257 public GCodeCommand ( GCode gCode )
253258 {
254259 this . gCode = gCode ;
260+ miscParams = new Dictionary < char , float > ( ) ;
261+ recordedParams = new List < char > ( ) ;
262+ parameterMap = new Dictionary < char , Action < float > > ( ) ;
255263 }
256264
257265 public GCodeCommand ( PrepCode prepCode , int codeNumber )
258266 {
259267 this . gCode = new GCode ( prepCode , codeNumber ) ;
268+ miscParams = new Dictionary < char , float > ( ) ;
269+ recordedParams = new List < char > ( ) ;
270+ parameterMap = new Dictionary < char , Action < float > > ( ) ;
271+ }
272+
273+ protected static void InitMaps ( )
274+ {
275+
260276 }
261277
262278 protected static void InitParameterMap ( )
@@ -280,7 +296,12 @@ protected void ParseParams(Dictionary<char, float> commandParams)
280296
281297 public override string ToString ( )
282298 {
283- return gCode . ToString ( ) ;
299+ string outString = gCode . ToString ( ) ;
300+ foreach ( var param in miscParams )
301+ {
302+ outString += $ " { param . Key } { param . Value } ";
303+ }
304+ return outString ;
284305 }
285306 }
286307
@@ -335,7 +356,7 @@ public override string ToString()
335356 }
336357 }
337358
338- internal class LinearInterpolationCmd : MovementCommand
359+ public class LinearInterpolationCmd : MovementCommand
339360 {
340361 internal bool isOperation ;
341362
@@ -618,147 +639,4 @@ public override string ToString()
618639 return outString ;
619640 }
620641 }
621-
622- /*
623- internal class GCodeCommandList : List<GCodeCommand>
624- {
625- //Hier "lookahead" implementieren. Bspw. eine Klasse CommandBlock einführen, die quasi einem VectorBlock ähnlich ist. Den CommmandBlock dann über Lookahed füllen
626- // CommandBLock enthält dann eine Liste von GCodeCommands und deren Gemeinsamkeiten, also feedRate, Accel... bzw. deren Unterscheide, also z.B. positions
627- public void Parse(string serializedCmds)
628- {
629- ToolParams toolParams = new ToolParams();
630- Vector2 lastPosition = new Vector2(0, 0);
631-
632- string[] commandLines = serializedCmds.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
633-
634- foreach (string commandLine in commandLines)
635- {
636- lastPosition = ParseLine(commandLine, lastPosition);
637- }
638- }
639-
640- public Vector2 ParseLine(string commandLine, Vector2 lastPosition)
641- {
642- commandLine = commandLine.Split(';')[0].Trim();
643- string commandString = Regex.Replace(commandLine.Split(' ')[0], @"[A-Z]0(\d)", "$1"); // kann weg
644-
645- char commandChar = commandString[0];
646- if (!Enum.TryParse(commandChar.ToString(), out PrepCode prepCode))
647- throw new ArgumentException($"Invalid preparatory function code: {commandChar}");
648-
649- string commandNumber = commandString.Substring(1);
650- if(!int.TryParse(commandNumber, out int codeNumber))
651- throw new ArgumentException($"Invalid number format: {commandNumber}");
652-
653- GCode gCode = new GCode(prepCode, codeNumber);
654-
655- Dictionary<string, float> cmdParams = new Dictionary<string, float>();
656-
657- foreach (string cmdParam in commandLine.Split(' ').Skip(1))
658- {
659- cmdParams.Add(cmdParam.Substring(0, 1), float.Parse(cmdParam.Substring(1)));
660- }
661-
662- GCodeCommand commandInstance = null;
663-
664- switch (gCode.preparatoryFunctionCode)
665- {
666- case PrepCode.G:
667- switch (gCode.codeNumber)
668- {
669- case 0:
670- commandInstance = new OperationalLinearInterpolationCmd(
671- false,
672- new Vector2(cmdParams["X"], cmdParams["Y"]),
673- new ToolParams(),
674- gCode.preparatoryFunctionCode, gCode.codeNumber,
675- cmdParams["F"]);
676- break;
677- case 1:
678- commandInstance = new OperationalLinearInterpolationCmd(
679- true,
680- new Vector2(cmdParams["X"], cmdParams["Y"]),
681- new ToolParams(),
682- gCode.preparatoryFunctionCode, gCode.codeNumber,
683- cmdParams["F"]);
684- break;
685- case 2:
686- if (cmdParams.ContainsKey("R"))
687- {
688- commandInstance = new CircularInterpolationCmd(
689- lastPosition,
690- new Vector2(cmdParams["X"], cmdParams["Y"]),
691- new Vector2(cmdParams["R"], cmdParams["R"]),
692- new ToolParams(),
693- gCode.preparatoryFunctionCode, gCode.codeNumber,
694- cmdParams["F"]);
695- }
696- else
697- {
698- commandInstance = new CircularInterpolationCmd(
699- lastPosition,
700- new Vector2(cmdParams["X"], cmdParams["Y"]),
701- new Vector2(cmdParams["I"], cmdParams["J"]),
702- new ToolParams(),
703- gCode.preparatoryFunctionCode, gCode.codeNumber,
704- cmdParams["F"]);
705- }
706- break;
707- case 3:
708- if (cmdParams.ContainsKey("R"))
709- {
710- commandInstance = new CircularInterpolationCmd(
711- lastPosition,
712- new Vector2(cmdParams["X"], cmdParams["Y"]),
713- new Vector2(cmdParams["R"], cmdParams["R"]),
714- new ToolParams(),
715- gCode.preparatoryFunctionCode, gCode.codeNumber,
716- cmdParams["F"]);
717- }
718- else
719- {
720- commandInstance = new CircularInterpolationCmd(
721- lastPosition,
722- new Vector2(cmdParams["X"], cmdParams["Y"]),
723- new Vector2(cmdParams["I"], cmdParams["J"]),
724- new ToolParams(),
725- gCode.preparatoryFunctionCode, gCode.codeNumber,
726- cmdParams["F"]);
727- }
728- break;
729- case 4:
730- commandInstance = new PauseCommand(
731- cmdParams["F"]);
732- break;
733- default:
734- commandInstance = new MiscCommand(gCode.preparatoryFunctionCode, gCode.codeNumber, cmdParams);
735- break;
736- }
737- break;
738- case PrepCode.M:
739- switch(gCode.codeNumber)
740- {
741- default:
742- commandInstance = new MiscCommand(gCode.preparatoryFunctionCode, gCode.codeNumber, cmdParams);
743- break;
744- }
745- break;
746- case PrepCode.T:
747- switch(gCode.codeNumber)
748- {
749- default:
750- commandInstance = new ToolChangeCommand(new ToolParams());
751- break;
752- }
753- break;
754- }
755- if (commandInstance != null)
756- {
757- Add(commandInstance);
758- return new Vector2(cmdParams["X"], cmdParams["Y"]);
759- }
760- return lastPosition;
761- }
762- }
763- */
764642}
0 commit comments