MeshLib C++ Docs
Loading...
Searching...
No Matches
MRGcodeProcessor.h
Go to the documentation of this file.
1#pragma once
2#include "MRMeshFwd.h"
3#include "MRVector3.h"
4#include "MRMatrix3.h"
6#include <vector>
7#include <string>
8#include <optional>
9#include <functional>
10
11
12namespace MR
13{
16
17
19class MRMESH_CLASS GcodeProcessor
20{
21public:
22
23 template<typename Vec>
25 {
27 std::vector<Vec> path;
29 std::string warning;
30 };
35 {
37 std::vector<Vector3f> toolDirection;
38 bool idle = true;
39 float feedrate = 100.f;
41 bool valid() const { return action.warning.empty(); }
42 operator bool() const { return valid(); }
43 };
44
46 MRMESH_API void reset();
47
49 MRMESH_API void setGcodeSource( const GcodeSource& gcodeSource );
50
52 MRMESH_API std::vector<MoveAction> processSource();
53
54 struct Command
55 {
56 char key;
57 float value;
58 };
59
62 MRMESH_API MoveAction processLine( const std::string_view& line, std::vector<Command> & externalStorage );
63
65 MRMESH_API void setCNCMachineSettings( const CNCMachineSettings& settings );
66 const CNCMachineSettings& getCNCMachineSettings() { return cncSettings_; }
67
68private:
69 enum class WorkPlane
70 {
71 xy,
72 zx,
73 yz
74 };
75
77 static void parseFrame_( const std::string_view& frame, std::vector<Command> & outCommands );
78 void applyCommand_( const Command& command );
79 void applyCommandG_( const Command& command );
80 MoveAction generateMoveAction_();
81 MoveAction generateReturnToHomeAction_();
82 void resetTemporaryStates_();
83
85
87 MoveAction moveLine_( const Vector3f& newPoint, const Vector3f& newAngles );
89 MoveAction moveArc_( const Vector3f& newPoint, const Vector3f& newAngles, bool clockwise );
90
92 void updateWorkPlane_( WorkPlane wp );
93
95 void updateScaling_();
96
98
100 BaseAction2f getArcPoints2_( const Vector2f& beginPoint, const Vector2f& endPoint, bool clockwise );
102 BaseAction3f getArcPoints3_( const Vector3f& center, const Vector3f& beginPoint, const Vector3f& endPoint, bool clockwise );
106 BaseAction3f getArcPoints3_( float r, const Vector3f& beginPoint, const Vector3f& endPoint, bool clockwise );
107
109 MoveAction getToolRotationPoints_( const Vector3f& newRotationAngles );
110
111 Vector3f calcNewTranslationPos_();
112 Vector3f calcNewRotationAngles_();
113 Vector3f calcRealCoord_( const Vector3f& translationPos, const Vector3f& rotationAngles );
114 void updateRotationAngleAndMatrix_( const Vector3f& rotationAngles );
115 Vector3f calcRealCoordCached_( const Vector3f& translationPos, const Vector3f& rotationAngles );
116 Vector3f calcRealCoordCached_( const Vector3f& translationPos );
117
119 enum class MoveMode
120 {
121 Idle,
122 Line,
123 Clockwise,
124 Counterclockwise
125 };
129 enum class CoordType
130 {
131 Movement,
132 ReturnToHome,
133 Scaling
134 };
135
137 CoordType coordType_ = CoordType::Movement;
138 MoveMode moveMode_ = MoveMode::Idle;
139 WorkPlane workPlane_ = WorkPlane::xy;
140 Matrix3f toWorkPlaneXf_;
141 Vector3f translationPos_;
142 Vector3f rotationAngles_;
143 bool absoluteCoordinates_ = true;
144 Vector3f scaling_ = Vector3f::diagonal( 1.f );
145 bool inches_ = false;
146 float feedrate_ = 100.f;
147 float feedrateMax_ = 0.f;
148
150 std::array<Matrix3f, 3> cacheRotationMatrix_;
151
153 Vector3f inputCoords_;
154 Vector3b inputCoordsReaded_;
155 std::optional<float> radius_;
156 std::optional<Vector3f> arcCenter_;
157 Vector3f inputRotation_;
158 Vector3b inputRotationReaded_;
159
160 std::vector<std::string_view> gcodeSource_;
161
163 float accuracy_ = 1.e-3f;
164 CNCMachineSettings cncSettings_;
165 std::vector<int> rotationAxesOrderMap_ = {0, 1, 2};
166
167};
168
169}
class with CNC machine emulation settings
Definition MRCNCMachineSettings.h:19
class to process g-code source and generate toolpath
Definition MRGcodeProcessor.h:20
MRMESH_API MoveAction processLine(const std::string_view &line, std::vector< Command > &externalStorage)
std::vector< Vec > path
tool movement parsed from gcode
Definition MRGcodeProcessor.h:27
const CNCMachineSettings & getCNCMachineSettings()
Definition MRGcodeProcessor.h:66
std::vector< Vector3f > toolDirection
Definition MRGcodeProcessor.h:37
float value
in lowercase
Definition MRGcodeProcessor.h:57
std::string warning
parser warning
Definition MRGcodeProcessor.h:29
bool valid() const
return true if operation was parsed without warnings
Definition MRGcodeProcessor.h:41
MRMESH_API void setCNCMachineSettings(const CNCMachineSettings &settings)
settings
MRMESH_API void reset()
reset internal states
MRMESH_API std::vector< MoveAction > processSource()
process all lines g-code source and generate corresponding move actions
MRMESH_API void setGcodeSource(const GcodeSource &gcodeSource)
set g-code source
char key
Definition MRGcodeProcessor.h:56
std::vector< std::string > GcodeSource
Definition MRObjectGcode.h:12
BaseAction3f action
Definition MRGcodeProcessor.h:36
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRGcodeProcessor.h:25
Definition MRGcodeProcessor.h:55
structure that stores information about the movement of the tool, specified by some string of command...
Definition MRGcodeProcessor.h:35