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{
10
15{
16public:
18
19 enum class Type
20 {
23 Back
24 };
25
27 ChangeObjectColorAction( const std::string& name, const std::shared_ptr<VisualObject>& obj, Type type ) :
28 obj_{ obj },
29 type_{ type },
30 name_{ name }
31 {
32 if ( obj_ )
33 colors_ = type_ == Type::Back ? obj_->getBackColorsForAllViewports() :
34 obj_->getFrontColorsForAllViewports( type_ == Type::Selected );
35 }
36
37 virtual std::string name() const override
38 {
39 return name_;
40 }
41
42 virtual void action( HistoryAction::Type ) override
43 {
44 if ( !obj_ )
45 return;
47 type_ == Type::Back ? obj_->getBackColorsForAllViewports() :
48 obj_->getFrontColorsForAllViewports( type_ == Type::Selected );
49 if ( type_ == Type::Back )
50 obj_->setBackColorsForAllViewports( colors_ );
51 else
52 obj_->setFrontColorsForAllViewports( colors_, type_ == Type::Selected );
53 colors_ = colors;
54 }
55
56 static void setObjectDirty( const std::shared_ptr<VisualObject>& )
57 {
58 }
59
60 [[nodiscard]] virtual size_t heapBytes() const override
61 {
62 return name_.capacity();
63 }
64
65private:
66 std::shared_ptr<VisualObject> obj_;
67 Type type_;
69 std::string name_;
70};
71
75{
76public:
78
80 ChangeFacesColorMapAction( const std::string& name, const std::shared_ptr<ObjectMeshHolder>& obj ) :
81 obj_{ obj },
82 name_{ name }
83 {
84 if ( obj )
85 colorMap_ = obj->getFacesColorMap();
86 }
87
89 ChangeFacesColorMapAction( const std::string& name, const std::shared_ptr<ObjectMeshHolder>& obj, FaceColors&& newColorMap ) :
90 obj_{ obj },
91 name_{ name }
92 {
93 if ( obj_ )
94 {
95 colorMap_ = std::move( newColorMap );
96 obj_->updateFacesColorMap( colorMap_ );
97 }
98 }
99
100 virtual std::string name() const override
101 {
102 return name_;
103 }
104
105 virtual void action( HistoryAction::Type ) override
106 {
107 if ( !obj_ )
108 return;
109 obj_->updateFacesColorMap( colorMap_ );
110 }
111
112 static void setObjectDirty( const std::shared_ptr<ObjectMeshHolder>& obj )
113 {
114 if ( obj )
115 obj->setDirtyFlags( DIRTY_PRIMITIVE_COLORMAP );
116 }
117
118 [[nodiscard]] virtual size_t heapBytes() const override
119 {
120 return name_.capacity() + colorMap_.heapBytes();
121 }
122
123private:
124 std::shared_ptr<ObjectMeshHolder> obj_;
125 FaceColors colorMap_;
126 std::string name_;
127};
128
132{
133public:
135
137 ChangeLinesColorMapAction( const std::string& name, const std::shared_ptr<ObjectLinesHolder>& obj ) :
138 obj_{ obj },
139 name_{ name }
140 {
141 if ( obj )
142 colorMap_ = obj->getLinesColorMap();
143 }
144
146 ChangeLinesColorMapAction( const std::string& name, const std::shared_ptr<ObjectLinesHolder>& obj, UndirectedEdgeColors&& newColorMap ) :
147 obj_{ obj },
148 name_{ name }
149 {
150 if ( obj_ )
151 {
152 colorMap_ = std::move( newColorMap );
153 obj_->updateLinesColorMap( colorMap_ );
154 }
155 }
156
157 virtual std::string name() const override
158 {
159 return name_;
160 }
161
162 virtual void action( HistoryAction::Type ) override
163 {
164 if ( !obj_ )
165 return;
166 obj_->updateLinesColorMap( colorMap_ );
167 }
168
169 static void setObjectDirty( const std::shared_ptr<ObjectLinesHolder>& obj )
170 {
171 if ( obj )
172 obj->setDirtyFlags( DIRTY_PRIMITIVE_COLORMAP );
173 }
174
175 [[nodiscard]] virtual size_t heapBytes() const override
176 {
177 return name_.capacity() + colorMap_.heapBytes();
178 }
179
180private:
181 std::shared_ptr<ObjectLinesHolder> obj_;
182 UndirectedEdgeColors colorMap_;
183 std::string name_;
184};
185
186}
Definition MRChangeColoringActions.h:75
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeColoringActions.h:105
virtual std::string name() const override
Definition MRChangeColoringActions.h:100
static void setObjectDirty(const std::shared_ptr< ObjectMeshHolder > &obj)
Definition MRChangeColoringActions.h:112
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:80
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeColoringActions.h:118
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:89
Definition MRChangeColoringActions.h:132
virtual std::string name() const override
Definition MRChangeColoringActions.h:157
static void setObjectDirty(const std::shared_ptr< ObjectLinesHolder > &obj)
Definition MRChangeColoringActions.h:169
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeColoringActions.h:175
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeColoringActions.h:162
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:137
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:146
Definition MRChangeColoringActions.h:15
ChangeObjectColorAction(const std::string &name, const std::shared_ptr< VisualObject > &obj, Type type)
Constructed from original obj.
Definition MRChangeColoringActions.h:27
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeColoringActions.h:60
Type
Definition MRChangeColoringActions.h:20
static void setObjectDirty(const std::shared_ptr< VisualObject > &)
Definition MRChangeColoringActions.h:56
virtual std::string name() const override
Definition MRChangeColoringActions.h:37
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeColoringActions.h:42
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
Definition MRObjectLinesHolder.h:19
Definition MRObjectMeshHolder.h:31
Definition MRViewportProperty.h:17
Visual Object.
Definition MRVisualObject.h:121
@ DIRTY_PRIMITIVE_COLORMAP
Definition MRVisualObject.h:91