void emit_linear(GCodeLine line) { Debug.Assert(line.code == 0 || line.code == 1); double x = GCodeUtil.UnspecifiedValue, y = GCodeUtil.UnspecifiedValue, z = GCodeUtil.UnspecifiedValue; bool found_x = GCodeUtil.TryFindParamNum(line.parameters, "X", ref x); bool found_y = GCodeUtil.TryFindParamNum(line.parameters, "Y", ref y); bool found_z = GCodeUtil.TryFindParamNum(line.parameters, "Z", ref z); Vector3d newPos = (UseRelativePosition) ? Vector3d.Zero : CurPosition; if (found_x) { newPos.x = x; } if (found_y) { newPos.y = y; } if (found_z) { newPos.z = z; } if (UseRelativePosition) { CurPosition += newPos; } else { CurPosition = newPos; } // F is feed rate (this changes?) double f = 0; bool haveF = GCodeUtil.TryFindParamNum(line.parameters, "F", ref f); LinearMoveData move = new LinearMoveData( newPos, (haveF) ? f : GCodeUtil.UnspecifiedValue); bool is_travel = (line.code == 0); if (is_travel) { if (in_travel == false) { listener.BeginTravel(); in_travel = true; in_cut = false; } } else { if (in_cut == false) { listener.BeginCut(); in_travel = false; in_cut = true; } } move.source = line; Debug.Assert(in_travel || in_cut); listener.LinearMoveToAbsolute3d(move); }
protected virtual void EmitLinear(GCodeLine line) { Debug.Assert(line.Code == 0 || line.Code == 1); double x = GCodeUtil.UnspecifiedValue, y = GCodeUtil.UnspecifiedValue, z = GCodeUtil.UnspecifiedValue; bool found_x = GCodeUtil.TryFindParamNum(line.Parameters, "X", ref x); bool found_y = GCodeUtil.TryFindParamNum(line.Parameters, "Y", ref y); bool found_z = GCodeUtil.TryFindParamNum(line.Parameters, "Z", ref z); Vector3d newPos = (UseRelativePosition) ? Vector3d.Zero : CurPosition; if (found_x) { newPos.x = x; } if (found_y) { newPos.y = y; } if (found_z) { newPos.z = z; } if (UseRelativePosition) { CurPosition += newPos; } else { CurPosition = newPos; } // F is feed rate (this changes?) double f = 0; bool haveF = GCodeUtil.TryFindParamNum(line.Parameters, "F", ref f); // A is extrusion stepper. E is also "current" stepper. double a = 0; bool haveA = GCodeUtil.TryFindParamNum(line.Parameters, "A", ref a); if (haveA == false) { haveA = GCodeUtil.TryFindParamNum(line.Parameters, "E", ref a); } if (UseRelativeExtruder) { a = ExtrusionA + a; } LinearMoveData move = new LinearMoveData( newPos, (haveF) ? f : GCodeUtil.UnspecifiedValue, (haveA) ? GCodeUtil.Extrude(a) : GCodeUtil.UnspecifiedPosition); if (haveA == false) { // if we do not have extrusion, this is a travel move if (in_travel == false) { listener.BeginTravel(); in_travel = true; in_extrude = false; } } else if (in_retract) { // if we are in retract, we stay in until we see forward movement Debug.Assert(in_travel); Debug.Assert(a <= LastRetractA + 0.001); if (MathUtil.EpsilonEqual(a, LastRetractA, 0.00001)) { in_retract = false; listener.BeginDeposition(); in_extrude = true; in_travel = false; ExtrusionA = a; } } else if (a < ExtrusionA) { // if extrusion moved backwards, we need to enter travel in_retract = true; LastRetractA = ExtrusionA; ExtrusionA = a; if (in_travel == false) { listener.BeginTravel(); in_travel = true; in_extrude = false; } } else { // if we are in travel, we need to begin extruding if (in_travel) { listener.BeginDeposition(); in_travel = false; in_extrude = true; } if (in_extrude == false) { // handle initialization cases listener.BeginDeposition(); in_extrude = true; } ExtrusionA = a; } move.source = line; Debug.Assert(in_travel || in_extrude); listener.LinearMoveToAbsolute3d(move); }