MeshLib C++ Docs
Loading...
Searching...
No Matches
MRChangeColoringActions.h
Go to the documentation of this file.
1#pragma once
2#include "MRHistoryAction.h"
5#include <memory>
7
8namespace MR
9{
12
13
18{
19public:
21
22 enum class Type
23 {
26 Back
27 };
28
30 ChangeObjectColorAction( const std::string& name, const std::shared_ptr<VisualObject>& obj, Type type ) :
31 obj_{ obj },
32 type_{ type },
33 name_{ name }
34 {
35 if ( obj_ )
36 colors_ = type_ == Type::Back ? obj_->getBackColorsForAllViewports() :
37 obj_->getFrontColorsForAllViewports( type_ == Type::Selected );
38 }
39
40 virtual std::string name() const override
41 {
42 return name_;
43 }
44
45 virtual void action( HistoryAction::Type ) override
46 {
47 if ( !obj_ )
48 return;
50 type_ == Type::Back ? obj_->getBackColorsForAllViewports() :
51 obj_->getFrontColorsForAllViewports( type_ == Type::Selected );
52 if ( type_ == Type::Back )
53 obj_->setBackColorsForAllViewports( colors_ );
54 else
55 obj_->setFrontColorsForAllViewports( colors_, type_ == Type::Selected );
56 colors_ = colors;
57 }
58
59 static void setObjectDirty( const std::shared_ptr<VisualObject>& )
60 {
61 }
62
63 [[nodiscard]] virtual size_t heapBytes() const override
64 {
65 return name_.capacity();
66 }
67
68private:
69 std::shared_ptr<VisualObject> obj_;
70 Type type_;
72 std::string name_;
73};
74
78{
79public:
81
83 ChangeFacesColorMapAction( const std::string& name, const std::shared_ptr<ObjectMeshHolder>& obj ) :
84 obj_{ obj },
85 name_{ name }
86 {
87 if ( obj )
88 colorMap_ = obj->getFacesColorMap();
89 }
90
92 ChangeFacesColorMapAction( const std::string& name, const std::shared_ptr<ObjectMeshHolder>& obj, FaceColors&& newColorMap ) :
93 obj_{ obj },
94 name_{ name }
95 {
96 if ( obj_ )
97 {
98 colorMap_ = std::move( newColorMap );
99 obj_->updateFacesColorMap( colorMap_ );
100 }
101 }
102
103 virtual std::string name() const override
104 {
105 return name_;
106 }
107
108 virtual void action( HistoryAction::Type ) override
109 {
110 if ( !obj_ )
111 return;
112 obj_->updateFacesColorMap( colorMap_ );
113 }
114
115 static void setObjectDirty( const std::shared_ptr<ObjectMeshHolder>& obj )
116 {
117 if ( obj )
118 obj->setDirtyFlags( DIRTY_PRIMITIVE_COLORMAP );
119 }
120
121 [[nodiscard]] virtual size_t heapBytes() const override
122 {
123 return name_.capacity() + colorMap_.heapBytes();
124 }
125
126private:
127 std::shared_ptr<ObjectMeshHolder> obj_;
128 FaceColors colorMap_;
129 std::string name_;
130};
131
135{
136public:
138
140 ChangeLinesColorMapAction( const std::string& name, const std::shared_ptr<ObjectLinesHolder>& obj ) :
141 obj_{ obj },
142 name_{ name }
143 {
144 if ( obj )
145 colorMap_ = obj->getLinesColorMap();
146 }
147
149 ChangeLinesColorMapAction( const std::string& name, const std::shared_ptr<ObjectLinesHolder>& obj, UndirectedEdgeColors&& newColorMap ) :
150 obj_{ obj },
151 name_{ name }
152 {
153 if ( obj_ )
154 {
155 colorMap_ = std::move( newColorMap );
156 obj_->updateLinesColorMap( colorMap_ );
157 }
158 }
159
160 virtual std::string name() const override
161 {
162 return name_;
163 }
164
165 virtual void action( HistoryAction::Type ) override
166 {
167 if ( !obj_ )
168 return;
169 obj_->updateLinesColorMap( colorMap_ );
170 }
171
172 static void setObjectDirty( const std::shared_ptr<ObjectLinesHolder>& obj )
173 {
174 if ( obj )
175 obj->setDirtyFlags( DIRTY_PRIMITIVE_COLORMAP );
176 }
177
178 [[nodiscard]] virtual size_t heapBytes() const override
179 {
180 return name_.capacity() + colorMap_.heapBytes();
181 }
182
183private:
184 std::shared_ptr<ObjectLinesHolder> obj_;
185 UndirectedEdgeColors colorMap_;
186 std::string name_;
187};
188
189}
Definition MRChangeColoringActions.h:78
Definition MRChangeColoringActions.h:135
Definition MRChangeColoringActions.h:18
Definition MRHistoryAction.h:15
Definition MRObjectLinesHolder.h:30
Definition MRObjectMeshHolder.h:35
Definition MRViewportProperty.h:17
Visual Object.
Definition MRVisualObject.h:116
ChangeObjectColorAction(const std::string &name, const std::shared_ptr< VisualObject > &obj, Type type)
Constructed from original obj.
Definition MRChangeColoringActions.h:30
virtual std::string name() const override
Definition MRChangeColoringActions.h:160
static void setObjectDirty(const std::shared_ptr< ObjectLinesHolder > &obj)
Definition MRChangeColoringActions.h:172
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeColoringActions.h:178
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeColoringActions.h:165
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeColoringActions.h:108
ChangeLinesColorMapAction(const std::string &name, const std::shared_ptr< ObjectLinesHolder > &obj)
use this constructor to remember object's line colors before making any changes in them
Definition MRChangeColoringActions.h:140
virtual std::string name() const override
Definition MRChangeColoringActions.h:103
static void setObjectDirty(const std::shared_ptr< ObjectMeshHolder > &obj)
Definition MRChangeColoringActions.h:115
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeColoringActions.h:63
ChangeLinesColorMapAction(const std::string &name, const std::shared_ptr< ObjectLinesHolder > &obj, UndirectedEdgeColors &&newColorMap)
use this constructor to remember object's lines colors and immediate set new value
Definition MRChangeColoringActions.h:149
Type
Definition MRChangeColoringActions.h:23
Type
Definition MRHistoryAction.h:22
static void setObjectDirty(const std::shared_ptr< VisualObject > &)
Definition MRChangeColoringActions.h:59
virtual std::string name() const override
Definition MRChangeColoringActions.h:40
ChangeFacesColorMapAction(const std::string &name, const std::shared_ptr< ObjectMeshHolder > &obj)
use this constructor to remember object's face colors before making any changes in them
Definition MRChangeColoringActions.h:83
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeColoringActions.h:121
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeColoringActions.h:45
ChangeFacesColorMapAction(const std::string &name, const std::shared_ptr< ObjectMeshHolder > &obj, FaceColors &&newColorMap)
use this constructor to remember object's face colors and immediate set new value
Definition MRChangeColoringActions.h:92
@ DIRTY_PRIMITIVE_COLORMAP
Definition MRVisualObject.h:87
only for bindings generation
Definition MRCameraOrientationPlugin.h:8