diff --git a/src/Mod/CAM/PathSimulator/AppGL/GCodeParser.cpp b/src/Mod/CAM/PathSimulator/AppGL/GCodeParser.cpp index 29c177f42d..b4458efe73 100644 --- a/src/Mod/CAM/PathSimulator/AppGL/GCodeParser.cpp +++ b/src/Mod/CAM/PathSimulator/AppGL/GCodeParser.cpp @@ -41,7 +41,7 @@ GCodeParser::~GCodeParser() bool GCodeParser::Parse(const char* filename) { Operations.clear(); - lastState = {eNop, -1, 0, 0, 0, 0, 0, 0, 0}; + lastState = {eNop, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0}; lastTool = -1; FILE* fl; @@ -163,6 +163,13 @@ bool GCodeParser::ParseLine(const char* ptr) } else if (cmd == 73 || cmd == 81 || cmd == 82 || cmd == 83) { lastState.cmd = eDril; + lastState.retract_z = lastState.z; + } + else if (cmd == 98 || cmd == 99) { + lastState.retract_mode = cmd; + } + else if (cmd == 80) { + lastState.retract_mode = 0; } break; @@ -212,7 +219,13 @@ bool GCodeParser::AddLine(const char* ptr) if (lastState.cmd == eDril) { // split to several motions lastState.cmd = eMoveLiner; - float rPlane = lastState.r; + float rPlane; + if (lastState.retract_mode == 99) { + rPlane = lastState.r; + } + else { + rPlane = lastState.retract_z; + } float finalDepth = lastState.z; lastState.z = rPlane; Operations.push_back(lastState); diff --git a/src/Mod/CAM/PathSimulator/AppGL/GCodeParser.h b/src/Mod/CAM/PathSimulator/AppGL/GCodeParser.h index 7632de8a25..eeda5d69a4 100644 --- a/src/Mod/CAM/PathSimulator/AppGL/GCodeParser.h +++ b/src/Mod/CAM/PathSimulator/AppGL/GCodeParser.h @@ -45,8 +45,8 @@ public: public: std::vector Operations; - MillMotion lastState = {eNop, 0, 0, 0, 0, 0, 0, 0, 0}; - MillMotion lastLastState = {eNop, 0, 0, 0, 0, 0, 0, 0, 0}; + MillMotion lastState = {eNop, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + MillMotion lastLastState = {eNop, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; protected: const char* GetNextToken(const char* ptr, GCToken* token); diff --git a/src/Mod/CAM/PathSimulator/AppGL/MillMotion.h b/src/Mod/CAM/PathSimulator/AppGL/MillMotion.h index e6b854a3b7..ea18aa30e1 100644 --- a/src/Mod/CAM/PathSimulator/AppGL/MillMotion.h +++ b/src/Mod/CAM/PathSimulator/AppGL/MillMotion.h @@ -53,6 +53,8 @@ struct MillMotion float x, y, z; float i, j, k; float r; + char retract_mode; + float retract_z; }; static inline void MotionPosToVec(vec3 vec, const MillMotion* motion)