Skip to content

Commit da32ac8

Browse files
author
Sven Erb
committed
Updated to 2D arcs and positions. Added LPBF-Metadata
1 parent 5c75fa9 commit da32ac8

File tree

1 file changed

+31
-27
lines changed
  • ReaderWriter/3rdPartyFormatAdapters/GCODE/GCodeReaderWriter

1 file changed

+31
-27
lines changed

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

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
190190
MetaData = new VectorBlock.Types.VectorBlockMetaData
191191
{
192192
PartKey = 0
193+
},
194+
LpbfMetadata = new VectorBlock.Types.LPBFMetadata
195+
{
196+
StructureType = VectorBlock.Types.StructureType.Part
193197
}
194198
};
195199

@@ -198,6 +202,7 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
198202

199203
for (int i = 0; i < gCodeCommandCount; i++)
200204
{
205+
//commandChanges = commandStateTracker.UpdateState(gCodeCommands[i]);
201206
switch (gCodeCommands[i])
202207
{
203208
// Process command according to the command-type
@@ -234,10 +239,11 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
234239

235240
// Save last work plane to job and merge marking params
236241
NewWorkPlane();
237-
job.MarkingParamsMap.MergeFromWithRemap(MPsMap, out var keyMapping);
242+
//job.MarkingParamsMap.MergeFromWithRemap(MPsMap, out var keyMapping);
243+
job.MarkingParamsMap.MergeFrom(MPsMap);
238244
// Update all vector block marking param keys after merge
239-
foreach (var vectorBlock in addedVectorBlocks)
240-
vectorBlock.MarkingParamsKey = keyMapping[vectorBlock.MarkingParamsKey];
245+
//foreach (var vectorBlock in addedVectorBlocks)
246+
// vectorBlock.MarkingParamsKey = keyMapping[vectorBlock.MarkingParamsKey];
241247

242248
// Add part info to job
243249
Part part = new Part();
@@ -252,7 +258,7 @@ public void ParseGCodeFile(IFileReaderWriterProgress progress = null)
252258
void ProcessMovementCmd(MovementCommand movementCmd)
253259
{
254260
// Check if layer has changed
255-
if (movementCmd.zPosition != null && movementCmd.zPosition != position.Z && !VBempty) //[0].LineSequence3D.Points.Count == 0 && _currentWP.VectorBlocks[0].Arcs3D.Centers.Count == 0)
261+
if (movementCmd.zPosition != null && movementCmd.zPosition != position.Z && !VBempty) //[0].LineSequence.Points.Count == 0 && _currentWP.VectorBlocks[0].Arcs.Centers.Count == 0)
256262
{
257263
NewWorkPlane();
258264
}
@@ -275,41 +281,37 @@ void UpdateLineSequence(LinearInterpolationCmd linearCmd)
275281
// Update speed first to check if marking params changed and new vector block is needed
276282
UpdateSpeed(linearCmd.isOperation, linearCmd.feedRate);
277283

278-
if (_currentVB.LineSequence3D == null)
284+
if (_currentVB.LineSequence == null)
279285
{
280-
_currentVB.LineSequence3D = new VectorBlock.Types.LineSequence3D();
286+
_currentVB.LineSequence = new VectorBlock.Types.LineSequence();
281287
}
282-
_currentVB.LineSequence3D.Points.Add(absolutePositioning
288+
_currentVB.LineSequence.Points.Add(absolutePositioning
283289
? (linearCmd.xPosition ?? position.X) // Use absolute x-positioning
284290
: (position.X + (linearCmd.xPosition ?? 0))); // Use relative xpositioning
285-
_currentVB.LineSequence3D.Points.Add(absolutePositioning
291+
_currentVB.LineSequence.Points.Add(absolutePositioning
286292
? (linearCmd.yPosition ?? position.Y) // Use absolute y-positioning
287293
: (position.Y + (linearCmd.yPosition ?? 0))); // Use relative y-positioning
288-
_currentVB.LineSequence3D.Points.Add(absolutePositioning
289-
? (linearCmd.zPosition ?? position.Z) // Use absolute y-positioning
290-
: (position.Z + (linearCmd.zPosition ?? 0))); // Use relative y-positioning
291294
}
292295

293296
void UpdateArc(CircularInterpolationCmd circularCmd)
294297
{
295298
// Create neccessary variables for conversion of G-Code arc definition to OVF arc definition
296-
Vector3 targetPosition = new Vector3(absolutePositioning ? (circularCmd.xPosition ?? position.X) : (position.X + (circularCmd.xPosition ?? 0)),
297-
absolutePositioning ? (circularCmd.yPosition ?? position.Y) : (position.Y + (circularCmd.yPosition ?? 0)),
298-
absolutePositioning ? (circularCmd.zPosition ?? position.Z) : (position.Z + (circularCmd.zPosition ?? 0)));
299+
Vector2 targetPosition = new Vector2(absolutePositioning ? (circularCmd.xPosition ?? position.X) : (position.X + (circularCmd.xPosition ?? 0)),
300+
absolutePositioning ? (circularCmd.yPosition ?? position.Y) : (position.Y + (circularCmd.yPosition ?? 0)));
299301

300-
Vector3 center = new Vector3(position.X + circularCmd.xCenterRel ?? 0, position.Y + circularCmd.yCenterRel ?? 0, position.Z);
302+
Vector2 center = new Vector2(position.X + circularCmd.xCenterRel ?? 0, position.Y + circularCmd.yCenterRel ?? 0);
301303

302-
Vector3 vectorCP = position - center; // Vector from center to start position
303-
Vector3 vectorCT = targetPosition - center; // Vector from center to target position
304+
Vector2 vectorCP = new Vector2(position.X - center.X, position.Y - center.Y); // Vector from center to start position
305+
Vector2 vectorCT = targetPosition - center; // Vector from center to target position
304306

305-
float dotProduct = Vector3.Dot(Vector3.Normalize(vectorCP), Vector3.Normalize(vectorCT));
307+
float dotProduct = Vector2.Dot(Vector2.Normalize(vectorCP), Vector2.Normalize(vectorCT));
306308
float angleAbs = (float)Math.Acos(dotProduct) * (180.0f / (float)Math.PI);
307309
angle = (circularCmd.isClockwise ? angleAbs : -angleAbs);
308310

309311
// Check if angle has changed, so marking params changed and new vector block is needed
310-
if (angle != _currentVB.Arcs3D.Angle && _currentVB.Arcs3D != null)
312+
if (angle != _currentVB.Arcs.Angle && _currentVB.Arcs != null)
311313
{
312-
if (_currentVB.Arcs3D.Angle != 0 && !VBlocked)
314+
if (_currentVB.Arcs.Angle != 0 && !VBlocked)
313315
{
314316
NewVectorBlock();
315317
}
@@ -319,20 +321,18 @@ void UpdateArc(CircularInterpolationCmd circularCmd)
319321
Update speed after angle to not write a new speed to an old vector block. */
320322
UpdateSpeed(true, circularCmd.feedRate);
321323

322-
if (_currentVB.Arcs3D == null)
324+
if (_currentVB.Arcs == null)
323325
{
324-
_currentVB.Arcs3D = new VectorBlock.Types.Arcs3D
326+
_currentVB.Arcs = new VectorBlock.Types.Arcs
325327
{
326328
Angle = angle,
327329

328330
StartDx = position.X,
329-
StartDy = position.Y,
330-
StartDz = position.Z
331+
StartDy = position.Y
331332
};
332333
}
333-
_currentVB.Arcs3D.Centers.Add(position.X + circularCmd.xCenterRel ?? position.X);
334-
_currentVB.Arcs3D.Centers.Add(position.Y + circularCmd.yCenterRel ?? position.Y);
335-
_currentVB.Arcs3D.Centers.Add(position.Z);
334+
_currentVB.Arcs.Centers.Add(position.X + circularCmd.xCenterRel ?? position.X);
335+
_currentVB.Arcs.Centers.Add(position.Y + circularCmd.yCenterRel ?? position.Y);
336336
}
337337

338338
void UpdateSpeed(bool isOperation, float? newSpeed)
@@ -443,6 +443,10 @@ void NewVectorBlock()
443443
MetaData = new VectorBlock.Types.VectorBlockMetaData
444444
{
445445
PartKey = 0
446+
},
447+
LpbfMetadata = new VectorBlock.Types.LPBFMetadata
448+
{
449+
StructureType = VectorBlock.Types.StructureType.Part
446450
}
447451
};
448452

0 commit comments

Comments
 (0)