MeshLib Documentation
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
14{
15public:
17 ObjectGcode( ObjectGcode&& ) = default;
19
20 constexpr static const char* TypeName() noexcept { return "ObjectGcode"; }
21 virtual const char* typeName() const override { return TypeName(); }
22
23 MRMESH_API virtual std::shared_ptr<Object> clone() const override;
24 MRMESH_API virtual std::shared_ptr<Object> shallowClone() const override;
25
26 MRMESH_API virtual void setCNCMachineSettings( const CNCMachineSettings& cncSettings );
27 virtual const CNCMachineSettings& getCNCMachineSettings() const { return cncMachineSettings_; }
28
29 MRMESH_API virtual void setGcodeSource( const std::shared_ptr<GcodeSource>& gcodeSource );
30 virtual const std::shared_ptr<GcodeSource>& gcodeSource() const { return gcodeSource_; }
31 // get action list (produced from g-code source)
32 virtual const std::vector<GcodeProcessor::MoveAction>& actionList() const { return actionList_; }
33 // get mapping of tool path polyline segment id to source line number of g-code source
34 virtual const std::vector<int>& segmentToSourceLineMap() const { return segmentToSourceLineMap_; }
35
36 MRMESH_API virtual void setDirtyFlags( uint32_t mask, bool invalidateCaches = true ) override;
37
40
41 MRMESH_API virtual std::vector<std::string> getInfoLines() const override;
42 virtual std::string getClassName() const override { return "G-code"; }
43
44 // set drawing feedrate as gradient of brightness
45 MRMESH_API void switchFeedrateGradient( bool isFeedrateGradientEnabled );
46 bool isFeedrateGradient() const { return feedrateGradientEnabled_; }
47
48 MRMESH_API void setIdleColor( const Color& color );
49 const Color& getIdleColor() const { return idleColor_; }
50
52 using GcodeChangedSignal = Signal<void( uint32_t mask )>;
54
55 MRMESH_API virtual bool select( bool isSelected ) override;
56 MRMESH_API virtual void setFrontColor( const Color& color, bool selected, ViewportId viewportId = {} ) override;
57
59 [[nodiscard]] MRMESH_API virtual size_t heapBytes() const override;
60
61protected:
62 ObjectGcode( const ObjectGcode& other ) = default;
63
65 MRMESH_API virtual void swapBase_( Object& other ) override;
68 MRMESH_API virtual void swapSignals_( Object& other ) override;
69
70 MRMESH_API virtual void serializeFields_( Json::Value& root ) const override;
71
72 MRMESH_API void deserializeFields_( const Json::Value& root ) override;
73
74private:
75 std::shared_ptr<GcodeSource> gcodeSource_;
76 std::vector<GcodeProcessor::MoveAction> actionList_;
77 CNCMachineSettings cncMachineSettings_;
78 void updateHeapUsageCache_();
79 size_t nonTrivialHeapUsageCache_{ 0 };
80
81 std::vector<int> segmentToSourceLineMap_;
82
83 Color idleColor_ = Color(0.3f, 0.3f, 0.3f);
84 float maxFeedrate_ = 0.f;
85 bool feedrateGradientEnabled_ = true;
86
87 void updateColors_();
88 void updateAll_();
89};
90
91}
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
#define MRMESH_CLASS
Definition MRMesh/MRMeshFwd.h:50
class with CNC machine emulation settings
Definition MRCNCMachineSettings.h:14
Definition MRObjectGcode.h:14
MRMESH_API void setIdleColor(const Color &color)
virtual MRMESH_API void setGcodeSource(const std::shared_ptr< GcodeSource > &gcodeSource)
virtual const CNCMachineSettings & getCNCMachineSettings() const
Definition MRObjectGcode.h:27
MRMESH_API ObjectGcode()
const Color & getIdleColor() const
Definition MRObjectGcode.h:49
virtual MRMESH_API bool select(bool isSelected) override
selects the object, returns true if value changed, otherwise returns false
virtual const std::vector< GcodeProcessor::MoveAction > & actionList() const
Definition MRObjectGcode.h:32
virtual MRMESH_API void swapBase_(Object &other) override
swaps this object with other
virtual const std::vector< int > & segmentToSourceLineMap() const
Definition MRObjectGcode.h:34
MRMESH_API void switchFeedrateGradient(bool isFeedrateGradientEnabled)
virtual MRMESH_API size_t heapBytes() const override
returns the amount of memory this object occupies on heap
bool isFeedrateGradient() const
Definition MRObjectGcode.h:46
ObjectGcode(ProtectedStruct, const ObjectGcode &obj)
Definition MRObjectGcode.h:39
virtual MRMESH_API std::vector< std::string > getInfoLines() const override
return several info lines that can better describe the object in the UI
virtual MRMESH_API void serializeFields_(Json::Value &root) const override
serializeFields_: serializeBaseFields_ plus polyline serialization
virtual MRMESH_API void setCNCMachineSettings(const CNCMachineSettings &cncSettings)
virtual const std::shared_ptr< GcodeSource > & gcodeSource() const
Definition MRObjectGcode.h:30
ObjectGcode(const ObjectGcode &other)=default
virtual MRMESH_API void setFrontColor(const Color &color, bool selected, ViewportId viewportId={}) override
sets color of object when it is selected/not-selected (depending on argument) in given viewport
ObjectGcode & operator=(ObjectGcode &&)=default
virtual std::string getClassName() const override
return human readable name of subclass
Definition MRObjectGcode.h:42
static constexpr const char * TypeName() noexcept
Definition MRObjectGcode.h:20
virtual MRMESH_API std::shared_ptr< Object > shallowClone() const override
virtual MRMESH_API void swapSignals_(Object &other) override
virtual MRMESH_API void setDirtyFlags(uint32_t mask, bool invalidateCaches=true) override
ObjectGcode(ObjectGcode &&)=default
virtual const char * typeName() const override
Definition MRObjectGcode.h:21
virtual MRMESH_API std::shared_ptr< Object > clone() const override
GcodeChangedSignal gcodeChangedSignal
Definition MRObjectGcode.h:53
MRMESH_API void deserializeFields_(const Json::Value &root) override
deserializeFields_: deserializeBaseFields_ plus polyline deserialization
Definition MRObjectLinesHolder.h:19
named object in the data model
Definition MRObject.h:60
Definition MRViewportId.h:16
Definition MRCameraOrientationPlugin.h:8
std::vector< std::string > GcodeSource
Definition MRMesh/MRMeshFwd.h:522
Definition MRColor.h:9
Definition MRObject.h:246