Skip to content

Commit ff2b04e

Browse files
author
Sven
committed
Updated LineSequenceParaAdapt usage
1 parent 1e1a352 commit ff2b04e

File tree

1 file changed

+37
-15
lines changed
  • ReaderWriter/3rdPartyFormatAdapters/GCODE/GCodeReaderWriter

1 file changed

+37
-15
lines changed

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

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
200200

201201
//int gCodeCommandCount = gCodeCommands.Count;
202202
int percentComplete = 0;
203+
int numLines = File.ReadLines(_filename).Count();
204+
int numProcessedLines = 0;
203205

204206
using (StreamReader sr = new StreamReader(_filename))
205207
{
@@ -238,13 +240,13 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
238240
VBlocked = false;
239241

240242
// Update progress
241-
/*
242-
if (percentComplete != (int)(i + 1) * 100 / gCodeCommandCount)
243+
if (percentComplete != (int)(numProcessedLines + 1) * 100 / numLines)
243244
{
244-
percentComplete = (i + 1) * 100 / gCodeCommandCount;
245-
progress?.Update("Command " + i + " of " + gCodeCommandCount, percentComplete);
245+
percentComplete = (numProcessedLines + 1) * 100 / numLines;
246+
progress?.Update("Command " + numProcessedLines + " of " + numLines + " processed.", percentComplete);
246247
}
247-
*/
248+
249+
numProcessedLines++;
248250
}
249251
}
250252

@@ -292,8 +294,19 @@ void UpdateLineSequence(LinearInterpolationCmd linearCmd)
292294
// Check if linearCmd is a jump command and create new vector block if true
293295
if (!linearCmd.isOperation)
294296
{
295-
var lastJumpSpeed = currentMP.JumpSpeedInMmS;
296-
NewVectorBlock();
297+
float lastJumpSpeed = 0.0f;
298+
try
299+
{
300+
lastJumpSpeed = currentMP.JumpSpeedInMmS;
301+
}
302+
catch
303+
{
304+
305+
}
306+
if(!VBlocked)
307+
{
308+
NewVectorBlock();
309+
}
297310
currentMP.JumpSpeedInMmS = linearCmd.feedRate ?? lastJumpSpeed;
298311
}
299312

@@ -303,14 +316,20 @@ void UpdateLineSequence(LinearInterpolationCmd linearCmd)
303316
_currentVB.LineSequenceParaAdapt = new VectorBlock.Types.LineSequenceParaAdapt();
304317
_currentVB.LineSequenceParaAdapt.Parameter.Add(VectorBlock.Types.LineSequenceParaAdapt.Types.AdaptedParameter.LaserSpeedInMmPerS);
305318
}
306-
_currentVB.LineSequenceParaAdapt.PointsWithParas.Add(absolutePositioning
319+
_currentVB.LineSequenceParaAdapt.PointsWithParas.Add(
320+
absolutePositioning
307321
? (linearCmd.xPosition ?? position.X) // Use absolute x-positioning
308322
: (position.X + (linearCmd.xPosition ?? 0))); // Use relative xpositioning
309-
_currentVB.LineSequenceParaAdapt.PointsWithParas.Add(absolutePositioning
323+
_currentVB.LineSequenceParaAdapt.PointsWithParas.Add(
324+
absolutePositioning
310325
? (linearCmd.yPosition ?? position.Y) // Use absolute y-positioning
311326
: (position.Y + (linearCmd.yPosition ?? 0))); // Use relative y-positioning
312-
_currentVB.LineSequenceParaAdapt.PointsWithParas.Add(linearCmd.feedRate // Use feedrate from command
313-
?? _currentVB.LineSequenceParaAdapt.PointsWithParas[_currentVB.LineSequenceParaAdapt.PointsWithParas.Count-3]); // Use last saved speed if command does not define a new feedrate
327+
_currentVB.LineSequenceParaAdapt.PointsWithParas.Add(
328+
linearCmd.feedRate
329+
?? (_currentVB.LineSequenceParaAdapt.PointsWithParas.Count >= 3
330+
? _currentVB.LineSequenceParaAdapt.PointsWithParas[_currentVB.LineSequenceParaAdapt.PointsWithParas.Count - 3]
331+
: 0f) // Default to 0 if not enough previous points
332+
);
314333
}
315334

316335
void UpdateArc(CircularInterpolationCmd circularCmd)
@@ -452,10 +471,13 @@ int NewMarkingParams()
452471
void NewVectorBlock()
453472
{
454473
// Update current vector block with current marking params and add vector block to current work plane
455-
_currentVB.MarkingParamsKey = NewMarkingParams();
456-
_currentWP.VectorBlocks.Add(_currentVB);
457-
_currentWP.NumBlocks++;
458-
addedVectorBlocks.Add(_currentVB);
474+
if (!VBempty)
475+
{
476+
_currentVB.MarkingParamsKey = NewMarkingParams();
477+
_currentWP.VectorBlocks.Add(_currentVB);
478+
_currentWP.NumBlocks++;
479+
addedVectorBlocks.Add(_currentVB);
480+
}
459481

460482
// Create new vector block
461483
_currentVB = new VectorBlock()

0 commit comments

Comments
 (0)