MeshLib C++ Docs
Loading...
Searching...
No Matches
MRChangeVertsColorMapAction.h
Go to the documentation of this file.
1#pragma once
2#include "MRHistoryAction.h"
3#include "MRVisualObject.h" //Color and DIRTY_VERTS_COLORMAP
4#include <memory>
5
6namespace MR
7{
8
11template<typename T>
13{
14public:
15 using Obj = T;
16
18 ChangeVertsColorMapAction( const std::string& name, const std::shared_ptr<T>& obj ) :
19 obj_{ obj },
20 name_{ name }
21 {
22 if ( obj )
23 vertsColorMap_ = obj->getVertsColorMap();
24 }
25
27 ChangeVertsColorMapAction( const std::string& name, const std::shared_ptr<T>& obj, VertColors&& newVertsColorMap ) :
28 obj_{ obj },
29 name_{ name }
30 {
31 if ( obj_ )
32 {
33 vertsColorMap_ = std::move( newVertsColorMap );
34 obj_->updateVertsColorMap( vertsColorMap_ );
35 }
36 }
37
38 virtual std::string name() const override
39 {
40 return name_;
41 }
42
43 virtual void action( HistoryAction::Type ) override
44 {
45 if ( !obj_ )
46 return;
47 obj_->updateVertsColorMap( vertsColorMap_ );
48 }
49
50 static void setObjectDirty( const std::shared_ptr<T>& obj )
51 {
52 if ( obj )
53 obj->setDirtyFlags( DIRTY_VERTS_COLORMAP );
54 }
55
56 [[nodiscard]] virtual size_t heapBytes() const override
57 {
58 return name_.capacity() + vertsColorMap_.capacity();
59 }
60
61private:
62 std::shared_ptr<T> obj_;
63 VertColors vertsColorMap_;
64 std::string name_;
65};
66
67}
Definition MRChangeVertsColorMapAction.h:13
static void setObjectDirty(const std::shared_ptr< T > &obj)
Definition MRChangeVertsColorMapAction.h:50
ChangeVertsColorMapAction(const std::string &name, const std::shared_ptr< T > &obj, VertColors &&newVertsColorMap)
use this constructor to remember object's vertex colors and immediate set new value
Definition MRChangeVertsColorMapAction.h:27
virtual std::string name() const override
Definition MRChangeVertsColorMapAction.h:38
T Obj
Definition MRChangeVertsColorMapAction.h:15
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeVertsColorMapAction.h:56
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeVertsColorMapAction.h:43
ChangeVertsColorMapAction(const std::string &name, const std::shared_ptr< T > &obj)
use this constructor to remember object's vertex colors before making any changes in them
Definition MRChangeVertsColorMapAction.h:18
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
@ DIRTY_VERTS_COLORMAP
Definition MRVisualObject.h:90