Skip to content

Commit 9583d0c

Browse files
author
Sven Erb
committed
Updated documentation.
1 parent 96944cd commit 9583d0c

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

  • ReaderWriter/3rdPartyFormatAdapters/GCODE/GCodeReaderWriter

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
170170
float angle = 0f;
171171
bool absolutePositioning = true;
172172

173+
// Load command lines from file and transfer to list of GCodeCommand objects.
173174
GCodeCommandList gCodeCommands = new GCodeCommandList(File.ReadAllLines(_filename));
174175

175176
bool VBlocked = true;
@@ -198,6 +199,7 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
198199

199200
switch (gCodeCommands[i])
200201
{
202+
// Process command according to the command-type
201203
case MovementCommand movementCmd:
202204
ProcessMovementCmd(movementCmd);
203205
break;
@@ -218,17 +220,22 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
218220
break;
219221
}
220222

223+
// Reset locking state for new vector blocks
221224
VBlocked = false;
222225

226+
// Update progress
223227
int percentComplete = (i + 1) * 100 / gCodeCommandCount;
224228
progress?.Update("Command " + i + " of ", percentComplete);
225229
}
226230

231+
// Save last work plane to job and merge marking params
227232
NewWorkPlane();
228233
job.MarkingParamsMap.MergeFromWithRemap(MPsMap, out var keyMapping);
229-
foreach (var vectorBlock in addedVectorBlocks) // update all vector block marking param keys after merge
234+
// Update all vector block marking param keys after merge
235+
foreach (var vectorBlock in addedVectorBlocks)
230236
vectorBlock.MarkingParamsKey = keyMapping[vectorBlock.MarkingParamsKey];
231237

238+
// Add part info to job
232239
Part part = new Part();
233240
part.GeometryInfo = new Part.Types.GeometryInfo()
234241
{
@@ -240,6 +247,7 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
240247

241248
void ProcessMovementCmd(MovementCommand movementCmd)
242249
{
250+
// Check if layer has changed
243251
if (movementCmd.zPosition != null && movementCmd.zPosition != position.Z)
244252
{
245253
NewWorkPlane();
@@ -254,10 +262,12 @@ void ProcessMovementCmd(MovementCommand movementCmd)
254262
break;
255263
}
256264

265+
// Update current position after movement
257266
UpdatePosition(movementCmd);
258267

259268
void UpdateLineSequence(LinearInterpolationCmd linearCmd)
260269
{
270+
// Update speed first to check if marking params changed and new vector block is needed
261271
UpdateSpeed(linearCmd.isOperation, linearCmd.feedRate);
262272

263273
if (_currentVB.LineSequence3D == null)
@@ -277,9 +287,11 @@ void UpdateLineSequence(LinearInterpolationCmd linearCmd)
277287

278288
void UpdateArc(CircularInterpolationCmd circularCmd)
279289
{
290+
// Create neccessary variables for conversion of G-Code arc definition to OVF arc definition
280291
Vector3 targetPosition = new Vector3(absolutePositioning ? (circularCmd.xPosition ?? position.X) : (position.X + (circularCmd.xPosition ?? 0)),
281292
absolutePositioning ? (circularCmd.yPosition ?? position.Y) : (position.Y + (circularCmd.yPosition ?? 0)),
282293
absolutePositioning ? (circularCmd.zPosition ?? position.Z) : (position.Z + (circularCmd.zPosition ?? 0)));
294+
283295
Vector3 center = new Vector3(position.X + circularCmd.xCenterRel ?? 0, position.Y + circularCmd.yCenterRel ?? 0, position.Z);
284296

285297
Vector3 vectorCP = position - center; // Vector from center to start position
@@ -289,6 +301,7 @@ void UpdateArc(CircularInterpolationCmd circularCmd)
289301
float angleAbs = (float)Math.Acos(dotProduct) * (180.0f / (float)Math.PI);
290302
angle = (circularCmd.isClockwise ? angleAbs : -angleAbs);
291303

304+
// Check if angle has changed, so marking params changed and new vector block is needed
292305
if (angle != _currentVB.Arcs3D.Angle && _currentVB.Arcs3D != null)
293306
{
294307
if (_currentVB.Arcs3D.Angle != 0 && !VBlocked)
@@ -297,7 +310,9 @@ void UpdateArc(CircularInterpolationCmd circularCmd)
297310
}
298311
}
299312

300-
UpdateSpeed(true, circularCmd.feedRate); // Update Speed in between to complete all checks for new VBs before adding centers. Update speed after angle to not write a possible new speed to the old VB
313+
/* Update Speed inbetween to complete all checks for new vector blocks before adding centers.
314+
Update speed after angle to not write a new speed to an old vector block. */
315+
UpdateSpeed(true, circularCmd.feedRate);
301316

302317
if (_currentVB.Arcs3D == null)
303318
{
@@ -317,7 +332,8 @@ void UpdateArc(CircularInterpolationCmd circularCmd)
317332

318333
void UpdateSpeed(bool isOperation, float? newSpeed)
319334
{
320-
if(isOperation)
335+
// Check if machine movement is travel or operation move and assign speed accordingly
336+
if (isOperation)
321337
{
322338
if (currentMP.LaserSpeedInMmPerS != 0 && newSpeed != null && currentMP.LaserSpeedInMmPerS != newSpeed)
323339
{
@@ -344,9 +360,12 @@ void UpdateSpeed(bool isOperation, float? newSpeed)
344360

345361
void ProcessPauseCmd(PauseCommand pauseCmd)
346362
{
363+
// Save current vector block and create new vector block for pause
347364
NewVectorBlock();
348365
_currentVB.ExposurePause = new VectorBlock.Types.ExposurePause();
349366
_currentVB.ExposurePause.PauseInUs = (ulong)pauseCmd.duration * 1000;
367+
368+
// Save pause vector block and create new vector block for next command
350369
NewVectorBlock();
351370
}
352371

@@ -382,11 +401,15 @@ void ProcessMiscCmd(MiscCommand miscCmd)
382401

383402
void UpdatePosition(MovementCommand movementCmd)
384403
{
404+
/* Update position with coordinates given in movement command.
405+
If a coordinate is not given, keep the current corrdinate value. */
385406
position = new Vector3(movementCmd.xPosition ?? position.X, movementCmd.yPosition ?? position.Y, movementCmd.zPosition ?? position.Z);
386407
}
387408

388409
int NewMarkingParams()
389410
{
411+
/* Try to get current marking params from cached params.
412+
If not found, create new key and add to cache */
390413
if (cachedMP.TryGetValue(currentMP, out int key)) ;
391414
else
392415
{
@@ -395,18 +418,21 @@ int NewMarkingParams()
395418
cachedMP.Add(currentMP, key);
396419
}
397420

421+
// Create new marking params for next vector block
398422
currentMP = new MarkingParams();
399423

400424
return key;
401425
}
402426

403427
void NewVectorBlock()
404428
{
429+
// Update current vector block with current marking params and add vector block to current work plane
405430
_currentVB.MarkingParamsKey = NewMarkingParams();
406431
_currentWP.VectorBlocks.Add(_currentVB);
407432
_currentWP.NumBlocks++;
408433
addedVectorBlocks.Add(_currentVB);
409434

435+
// Create new vector block
410436
_currentVB = new VectorBlock()
411437
{
412438
MetaData = new VectorBlock.Types.VectorBlockMetaData
@@ -415,15 +441,19 @@ void NewVectorBlock()
415441
}
416442
};
417443

444+
// Lock vector block to prevent creating mulitple new vector blocks for one command
418445
VBlocked = true;
419446
}
420447

421448
void NewWorkPlane()
422449
{
450+
// Update current work plane with current vector block and z-position
423451
NewVectorBlock();
424452
_currentWP.ZPosInMm = position.Z;
425453
job.WorkPlanes.Add(_currentWP);
426454
job.NumWorkPlanes++;
455+
456+
// Create new work plane
427457
_currentWP = new WorkPlane
428458
{
429459
WorkPlaneNumber = job.NumWorkPlanes

0 commit comments

Comments
 (0)