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#include "MRHeapBytes.h"
8
9namespace MR
10{
13
14
19{
20public:
22
23 enum class Type
24 {
28 };
29
31 ChangeObjectColorAction( const std::string& name, const std::shared_ptr<VisualObject>& obj, Type type ) :
32 obj_{ obj },
33 type_{ type },
34 name_{ name }
35 {
36 if ( obj_ )
37 colors_ = type_ == Type::Back ? obj_->getBackColorsForAllViewports() :
38 obj_->getFrontColorsForAllViewports( type_ == Type::Selected );
39 }
40
41 virtual std::string name() const override
42 {
43 return name_;
44 }
45
46 virtual void action( HistoryAction::Type ) override
47 {
48 if ( !obj_ )
49 return;
51 type_ == Type::Back ? obj_->getBackColorsForAllViewports() :
52 obj_->getFrontColorsForAllViewports( type_ == Type::Selected );
53 if ( type_ == Type::Back )
54 obj_->setBackColorsForAllViewports( colors_ );
55 else
56 obj_->setFrontColorsForAllViewports( colors_, type_ == Type::Selected );
57 colors_ = colors;
58 }
59
60 static void setObjectDirty( const std::shared_ptr<VisualObject>& )
61 {
62 }
63
64 [[nodiscard]] virtual size_t heapBytes() const override
65 {
66 return name_.capacity();
67 }
68
69private:
70 std::shared_ptr<VisualObject> obj_;
71 Type type_;
73 std::string name_;
74};
75
79{
80public:
82
84 ChangeFacesColorMapAction( const std::string& name, const std::shared_ptr<ObjectMeshHolder>& obj ) :
85 obj_{ obj },
86 name_{ name }
87 {
88 if ( obj )
89 colorMap_ = obj->getFacesColorMap();
90 }
91
93 ChangeFacesColorMapAction( const std::string& name, const std::shared_ptr<ObjectMeshHolder>& obj, FaceColors&& newColorMap ) :
94 obj_{ obj },
95 name_{ name }
96 {
97 if ( obj_ )
98 {
99 colorMap_ = std::move( newColorMap );
100 obj_->updateFacesColorMap( colorMap_ );
101 }
102 }
103
104 virtual std::string name() const override
105 {
106 return name_;
107 }
108
109 virtual void action( HistoryAction::Type ) override
110 {
111 if ( !obj_ )
112 return;
113 obj_->updateFacesColorMap( colorMap_ );
114 }
115
116 static void setObjectDirty( const std::shared_ptr<ObjectMeshHolder>& obj )
117 {
118 if ( obj )
119 obj->setDirtyFlags( DIRTY_PRIMITIVE_COLORMAP );
120 }
121
122 [[nodiscard]] virtual size_t heapBytes() const override
123 {
124 return name_.capacity() + colorMap_.heapBytes();
125 }
126
127private:
128 std::shared_ptr<ObjectMeshHolder> obj_;
129 FaceColors colorMap_;
130 std::string name_;
131};
132
136{
137public:
139
141 ChangeLinesColorMapAction( const std::string& name, const std::shared_ptr<ObjectLinesHolder>& obj ) :
142 obj_{ obj },
143 name_{ name }
144 {
145 if ( obj )
146 colorMap_ = obj->getLinesColorMap();
147 }
148
150 ChangeLinesColorMapAction( const std::string& name, const std::shared_ptr<ObjectLinesHolder>& obj, UndirectedEdgeColors&& newColorMap ) :
151 obj_{ obj },
152 name_{ name }
153 {
154 if ( obj_ )
155 {
156 colorMap_ = std::move( newColorMap );
157 obj_->updateLinesColorMap( colorMap_ );
158 }
159 }
160
161 virtual std::string name() const override
162 {
163 return name_;
164 }
165
166 virtual void action( HistoryAction::Type ) override
167 {
168 if ( !obj_ )
169 return;
170 obj_->updateLinesColorMap( colorMap_ );
171 }
172
173 static void setObjectDirty( const std::shared_ptr<ObjectLinesHolder>& obj )
174 {
175 if ( obj )
176 obj->setDirtyFlags( DIRTY_PRIMITIVE_COLORMAP );
177 }
178
179 [[nodiscard]] virtual size_t heapBytes() const override
180 {
181 return name_.capacity() + colorMap_.heapBytes();
182 }
183
184private:
185 std::shared_ptr<ObjectLinesHolder> obj_;
186 UndirectedEdgeColors colorMap_;
187 std::string name_;
188};
189
190}
Definition MRObjectLinesHolder.h:32
Definition MRObjectMeshHolder.h:37
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:31
VisualObject Obj
Definition MRChangeColoringActions.h:21
ObjectLinesHolder Obj
Definition MRChangeColoringActions.h:138
virtual std::string name() const override
Definition MRChangeColoringActions.h:161
static void setObjectDirty(const std::shared_ptr< ObjectLinesHolder > &obj)
Definition MRChangeColoringActions.h:173
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeColoringActions.h:179
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeColoringActions.h:166
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeColoringActions.h:109
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:141
virtual std::string name() const override
Definition MRChangeColoringActions.h:104
static void setObjectDirty(const std::shared_ptr< ObjectMeshHolder > &obj)
Definition MRChangeColoringActions.h:116
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeColoringActions.h:64
ObjectMeshHolder Obj
Definition MRChangeColoringActions.h:81
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:150
Type
Definition MRChangeColoringActions.h:24
Type
Definition MRHistoryAction.h:27
static void setObjectDirty(const std::shared_ptr< VisualObject > &)
Definition MRChangeColoringActions.h:60
virtual std::string name() const override
Definition MRChangeColoringActions.h:41
HistoryAction()=default
explicitly define ctors to avoid warning C5267: definition of implicit copy constructor is deprecated...
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:84
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeColoringActions.h:122
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeColoringActions.h:46
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:93
@ Back
Definition MRChangeColoringActions.h:27
@ Unselected
Definition MRChangeColoringActions.h:25
@ Selected
Definition MRChangeColoringActions.h:26
@ DIRTY_PRIMITIVE_COLORMAP
Definition MRVisualObject.h:87
only for bindings generation
Definition MRCameraOrientationPlugin.h:8