Skip to content

Commit 371a2ce

Browse files
author
Sven Erb
committed
Updated setting of class variables in constructors.
1 parent c3ad99e commit 371a2ce

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

ReaderWriter/3rdPartyFormatAdapters/GCODE/GCodeReaderWriter/GCodeCommand.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public class CircularInterpolationCmd : MovementCommand
257257
public float? yCenterRel;
258258

259259
// Direction of the circular interpolation
260-
public bool isClockwise;
260+
public readonly bool isClockwise;
261261

262262
public CircularInterpolationCmd(PrepCode prepCode, int codeNumer, bool isClockwise, float? xPosition, float? yPosition, float? xCenterRel, float? yCenterRel, float? feedRate, float? acceleration, Dictionary<char, float> miscParams = null, string comment = null)
263263
: base(prepCode, codeNumer, xPosition, yPosition, null, feedRate, acceleration, miscParams, comment)
@@ -269,7 +269,7 @@ public CircularInterpolationCmd(PrepCode prepCode, int codeNumer, bool isClockwi
269269

270270
public CircularInterpolationCmd(PrepCode prepCode, int codeNumber, Dictionary<char, float> commandParams = null, string comment = null) : base(prepCode, codeNumber, commandParams, comment)
271271
{
272-
CheckDirection();
272+
this.isClockwise = CheckDirection();
273273
InitParameterMap();
274274
if (commandParams != null)
275275
{
@@ -279,7 +279,7 @@ public CircularInterpolationCmd(PrepCode prepCode, int codeNumber, Dictionary<ch
279279

280280
public CircularInterpolationCmd(GCode gCode, Dictionary<char, float> commandParams = null, string comment = null) : base(gCode, commandParams, comment)
281281
{
282-
CheckDirection();
282+
this.isClockwise = CheckDirection();
283283
InitParameterMap();
284284
if (commandParams != null)
285285
{
@@ -293,11 +293,11 @@ public CircularInterpolationCmd(GCode gCode, Dictionary<char, float> commandPara
293293
parameterMap.Add('J', (float j) => yCenterRel = j);
294294
}
295295

296-
private void CheckDirection()
296+
private bool CheckDirection()
297297
{
298298
if (this.gCode.codeNumber == 2 || this.gCode.codeNumber == 3)
299299
{
300-
this.isClockwise = this.gCode.codeNumber == 2;
300+
return this.gCode.codeNumber == 2;
301301
}
302302
else
303303
{
@@ -430,25 +430,42 @@ public override string ToString()
430430
public class PositioningToggleCommand : ProgramLogicsCommand
431431
{
432432
public readonly bool isAbsolute;
433-
433+
434+
public PositioningToggleCommand(PrepCode prepCode, int codeNumber, bool isAbsolute, string comment = null) : base(prepCode, codeNumber, null, comment)
435+
{
436+
this.isAbsolute = checkPositioning();
437+
}
434438
public PositioningToggleCommand(PrepCode prepCode, int codeNumber, Dictionary<char, float> commandParams = null, string comment = null) : base(prepCode, codeNumber, commandParams, comment)
435439
{
436-
440+
this.isAbsolute = checkPositioning();
437441
}
438442

439443
public PositioningToggleCommand(GCode gCode, Dictionary<char, float> commandParams = null, string comment = null) : base(gCode, commandParams, comment)
440444
{
445+
this.isAbsolute = checkPositioning();
446+
}
441447

448+
private bool checkPositioning()
449+
{
450+
if (this.gCode.codeNumber == 90 || this.gCode.codeNumber == 91)
451+
{
452+
return this.gCode.codeNumber == 90;
453+
}
454+
else
455+
{
456+
throw new ArgumentException($"Invalid code number for positioning toggle: {this.gCode.codeNumber} in line '{this}'");
457+
}
442458
}
443459

444460
public override string ToString()
445461
{
446462
return base.ToString();
447463
}
448464
}
465+
449466
public class BlockEndCmd : ProgramLogicsCommand
450467
{
451-
public BlockEndCmd(PrepCode prepCode, int codeNumber, Dictionary<char, float> commandParams = null, string comment = null) : base(prepCode, codeNumber, comment)
468+
public BlockEndCmd(PrepCode prepCode, int codeNumber, Dictionary<char, float> commandParams = null, string comment = null) : base(prepCode, codeNumber, null, comment)
452469
{
453470
InitParameterMap();
454471
if (commandParams != null)

0 commit comments

Comments
 (0)