MeshLib C++ Docs
Loading...
Searching...
No Matches
MRObjectGcode.h
Go to the documentation of this file.
1#pragma once
3#include "MRGcodeProcessor.h"
4#include "MRColor.h"
5
6namespace MR
7{
8
9using GcodeSource = std::vector<std::string>;
10
13class MRMESH_CLASS ObjectGcode : public ObjectLinesHolder
14{
15public:
16 MRMESH_API ObjectGcode();
17 ObjectGcode( ObjectGcode&& ) = default;
18 ObjectGcode& operator=( ObjectGcode&& ) = default;
19
20 constexpr static const char* StaticTypeName() noexcept { return "ObjectGcode"; }
21 virtual const char* typeName() const override { return StaticTypeName(); }
22
23 constexpr static const char* StaticClassName() noexcept { return "G-code"; }
24 virtual std::string className() const override { return StaticClassName(); }
25
26 constexpr static const char* StaticClassNameInPlural() noexcept { return "G-codes"; }
27 virtual std::string classNameInPlural() const override { return StaticClassNameInPlural(); }
28
29 MRMESH_API virtual std::shared_ptr<Object> clone() const override;
30 MRMESH_API virtual std::shared_ptr<Object> shallowClone() const override;
31
32 MRMESH_API virtual void setCNCMachineSettings( const CNCMachineSettings& cncSettings );
33 virtual const CNCMachineSettings& getCNCMachineSettings() const { return cncMachineSettings_; }
34
35 MRMESH_API virtual void setGcodeSource( const std::shared_ptr<GcodeSource>& gcodeSource );
36 virtual const std::shared_ptr<GcodeSource>& gcodeSource() const { return gcodeSource_; }
37 // get action list (produced from g-code source)
38 virtual const std::vector<GcodeProcessor::MoveAction>& actionList() const { return actionList_; }
39 // get mapping of tool path polyline segment id to source line number of g-code source
40 virtual const std::vector<int>& segmentToSourceLineMap() const { return segmentToSourceLineMap_; }
41
42 MRMESH_API virtual void setDirtyFlags( uint32_t mask, bool invalidateCaches = true ) override;
43
45 ObjectGcode( ProtectedStruct, const ObjectGcode& obj ) : ObjectGcode( obj ) {}
46
47 MRMESH_API virtual std::vector<std::string> getInfoLines() const override;
48
49 // set drawing feedrate as gradient of brightness
50 MRMESH_API void switchFeedrateGradient( bool isFeedrateGradientEnabled );
51 bool isFeedrateGradient() const { return feedrateGradientEnabled_; }
52
53 MRMESH_API void setIdleColor( const Color& color );
54 const Color& getIdleColor() const { return idleColor_; }
55
57 using GcodeChangedSignal = Signal<void( uint32_t mask )>;
58 GcodeChangedSignal gcodeChangedSignal;
59
60 MRMESH_API virtual bool select( bool isSelected ) override;
61 MRMESH_API virtual void setFrontColor( const Color& color, bool selected, ViewportId viewportId = {} ) override;
62
64 [[nodiscard]] MRMESH_API virtual size_t heapBytes() const override;
65
66protected:
67 ObjectGcode( const ObjectGcode& other ) = default;
68
70 MRMESH_API virtual void swapBase_( Object& other ) override;
73 MRMESH_API virtual void swapSignals_( Object& other ) override;
74
75 MRMESH_API virtual void serializeFields_( Json::Value& root ) const override;
76
77 MRMESH_API void deserializeFields_( const Json::Value& root ) override;
78
79private:
80 std::shared_ptr<GcodeSource> gcodeSource_;
81 std::vector<GcodeProcessor::MoveAction> actionList_;
82 CNCMachineSettings cncMachineSettings_;
83 void updateHeapUsageCache_();
84 size_t nonTrivialHeapUsageCache_{ 0 };
85
86 std::vector<int> segmentToSourceLineMap_;
87
88 Color idleColor_ = Color(0.3f, 0.3f, 0.3f);
89 float maxFeedrate_ = 0.f;
90 bool feedrateGradientEnabled_ = true;
91
92 void updateColors_();
93 void updateAll_();
94};
95
96}
#define MRMESH_API
Definition MRMeshFwd.h:80
#define MRMESH_CLASS
Definition MRMeshFwd.h:87
Definition MRCameraOrientationPlugin.h:8
int heapBytes(FloatGrid grid)