MeshLib Documentation
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:
136 ChangeLinesColorMapAction( const std::string& name, const std::shared_ptr<ObjectLinesHolder>& obj ) :
137 obj_{ obj },
138 name_{ name }
139 {
140 if ( obj )
141 colorMap_ = obj->getLinesColorMap();
142 }
143
144 virtual std::string name() const override
145 {
146 return name_;
147 }
148
149 virtual void action( HistoryAction::Type ) override
150 {
151 if ( !obj_ )
152 return;
153 obj_->updateLinesColorMap( colorMap_ );
154 }
155
156 static void setObjectDirty( const std::shared_ptr<ObjectLinesHolder>& obj )
157 {
158 if ( obj )
159 obj->setDirtyFlags( DIRTY_PRIMITIVE_COLORMAP );
160 }
161
162 [[nodiscard]] virtual size_t heapBytes() const override
163 {
164 return name_.capacity() + colorMap_.heapBytes();
165 }
166
167private:
168 std::shared_ptr<ObjectLinesHolder> obj_;
169 UndirectedEdgeColors colorMap_;
170 std::string name_;
171};
172
173}
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:144
static void setObjectDirty(const std::shared_ptr< ObjectLinesHolder > &obj)
Definition MRChangeColoringActions.h:156
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeColoringActions.h:162
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeColoringActions.h:149
ChangeLinesColorMapAction(const std::string &name, const std::shared_ptr< ObjectLinesHolder > &obj)
Constructed from original obj.
Definition MRChangeColoringActions.h:136
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:30
Definition MRViewportProperty.h:17
Visual Object.
Definition MRVisualObject.h:131
@ DIRTY_PRIMITIVE_COLORMAP
Definition MRVisualObject.h:101
Definition MRCameraOrientationPlugin.h:8