Skip to content

Commit 420394f

Browse files
author
Sven Erb
committed
Added check to not write empty vectorblocks to workplane.
1 parent 16bf472 commit 420394f

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

  • ReaderWriter/3rdPartyFormatAdapters/GCODE/GCodeReaderWriter

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,13 @@ 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.
174-
GCodeCommandList gCodeCommands = new GCodeCommandList(File.ReadAllLines(_filename));
175-
176173
bool VBlocked = true;
174+
bool VBempty = true;
177175
int MPKey = 0;
178176

177+
// Load command lines from file and transfer to list of GCodeCommand objects.
178+
GCodeCommandList gCodeCommands = new GCodeCommandList(File.ReadAllLines(_filename));
179+
179180
_currentWP = new WorkPlane
180181
{
181182
WorkPlaneNumber = 0
@@ -193,10 +194,10 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
193194
};
194195

195196
int gCodeCommandCount = gCodeCommands.Count;
197+
int percentComplete = 0;
196198

197199
for (int i = 0; i < gCodeCommandCount; i++)
198200
{
199-
200201
switch (gCodeCommands[i])
201202
{
202203
// Process command according to the command-type
@@ -224,22 +225,25 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
224225
VBlocked = false;
225226

226227
// Update progress
227-
int percentComplete = (i + 1) * 100 / gCodeCommandCount;
228-
progress?.Update("Command " + i + " of ", percentComplete);
228+
if (percentComplete != (int) (i + 1) * 100 / gCodeCommandCount)
229+
{
230+
percentComplete = (i + 1) * 100 / gCodeCommandCount;
231+
progress?.Update("Command " + i + " of " + gCodeCommandCount, percentComplete);
232+
}
229233
}
230234

231235
// Save last work plane to job and merge marking params
232236
NewWorkPlane();
233237
job.MarkingParamsMap.MergeFromWithRemap(MPsMap, out var keyMapping);
234238
// Update all vector block marking param keys after merge
235-
foreach (var vectorBlock in addedVectorBlocks)
239+
foreach (var vectorBlock in addedVectorBlocks)
236240
vectorBlock.MarkingParamsKey = keyMapping[vectorBlock.MarkingParamsKey];
237241

238242
// Add part info to job
239243
Part part = new Part();
240244
part.GeometryInfo = new Part.Types.GeometryInfo()
241245
{
242-
BuildHeightInMm = position.Z
246+
BuildHeightInMm = Math.Round(Convert.ToDouble(position.Z), 2)
243247
};
244248
job.PartsMap.Add(0, part);
245249

@@ -248,7 +252,7 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
248252
void ProcessMovementCmd(MovementCommand movementCmd)
249253
{
250254
// Check if layer has changed
251-
if (movementCmd.zPosition != null && movementCmd.zPosition != position.Z)
255+
if (movementCmd.zPosition != null && movementCmd.zPosition != position.Z && !VBempty) //[0].LineSequence3D.Points.Count == 0 && _currentWP.VectorBlocks[0].Arcs3D.Centers.Count == 0)
252256
{
253257
NewWorkPlane();
254258
}
@@ -262,8 +266,9 @@ void ProcessMovementCmd(MovementCommand movementCmd)
262266
break;
263267
}
264268

265-
// Update current position after movement
269+
// Update current position after movement & indicate that the vectorblocks are not empty
266270
UpdatePosition(movementCmd);
271+
VBempty = false;
267272

268273
void UpdateLineSequence(LinearInterpolationCmd linearCmd)
269274
{
@@ -335,9 +340,9 @@ void UpdateSpeed(bool isOperation, float? newSpeed)
335340
// Check if machine movement is travel or operation move and assign speed accordingly
336341
if (isOperation)
337342
{
338-
if (currentMP.LaserSpeedInMmPerS != 0 && newSpeed != null && currentMP.LaserSpeedInMmPerS != newSpeed)
343+
if (newSpeed != null && currentMP.LaserSpeedInMmPerS != newSpeed)
339344
{
340-
if (!VBlocked)
345+
if (currentMP.LaserSpeedInMmPerS != 0 && !VBlocked)
341346
{
342347
NewVectorBlock();
343348
}
@@ -346,9 +351,9 @@ void UpdateSpeed(bool isOperation, float? newSpeed)
346351
}
347352
else
348353
{
349-
if (currentMP.JumpSpeedInMmS != 0 && newSpeed != null && currentMP.JumpSpeedInMmS != newSpeed)
354+
if (newSpeed != null && currentMP.JumpSpeedInMmS != newSpeed)
350355
{
351-
if (!VBlocked)
356+
if (currentMP.JumpSpeedInMmS != 0 && !VBlocked)
352357
{
353358
NewVectorBlock();
354359
}
@@ -443,6 +448,7 @@ void NewVectorBlock()
443448

444449
// Lock vector block to prevent creating mulitple new vector blocks for one command
445450
VBlocked = true;
451+
VBempty = true;
446452
}
447453

448454
void NewWorkPlane()

0 commit comments

Comments
 (0)