MeshLib
 
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:
79 ChangeFacesColorMapAction( const std::string& name, const std::shared_ptr<ObjectMeshHolder>& obj ) :
80 obj_{ obj },
81 name_{ name }
82 {
83 if ( obj )
84 colorMap_ = obj->getFacesColorMap();
85 }
86
87 virtual std::string name() const override
88 {
89 return name_;
90 }
91
92 virtual void action( HistoryAction::Type ) override
93 {
94 if ( !obj_ )
95 return;
96 obj_->updateFacesColorMap( colorMap_ );
97 }
98
99 static void setObjectDirty( const std::shared_ptr<ObjectMeshHolder>& obj )
100 {
101 if ( obj )
102 obj->setDirtyFlags( DIRTY_PRIMITIVE_COLORMAP );
103 }
104
105 [[nodiscard]] virtual size_t heapBytes() const override
106 {
107 return name_.capacity() + colorMap_.heapBytes();
108 }
109
110private:
111 std::shared_ptr<ObjectMeshHolder> obj_;
112 FaceColors colorMap_;
113 std::string name_;
114};
115
119{
120public:
123 ChangeLinesColorMapAction( const std::string& name, const std::shared_ptr<ObjectLinesHolder>& obj ) :
124 obj_{ obj },
125 name_{ name }
126 {
127 if ( obj )
128 colorMap_ = obj->getLinesColorMap();
129 }
130
131 virtual std::string name() const override
132 {
133 return name_;
134 }
135
136 virtual void action( HistoryAction::Type ) override
137 {
138 if ( !obj_ )
139 return;
140 obj_->updateLinesColorMap( colorMap_ );
141 }
142
143 static void setObjectDirty( const std::shared_ptr<ObjectLinesHolder>& obj )
144 {
145 if ( obj )
146 obj->setDirtyFlags( DIRTY_PRIMITIVE_COLORMAP );
147 }
148
149 [[nodiscard]] virtual size_t heapBytes() const override
150 {
151 return name_.capacity() + colorMap_.heapBytes();
152 }
153
154private:
155 std::shared_ptr<ObjectLinesHolder> obj_;
156 UndirectedEdgeColors colorMap_;
157 std::string name_;
158};
159
160}
Definition MRChangeColoringActions.h:75
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeColoringActions.h:92
virtual std::string name() const override
Definition MRChangeColoringActions.h:87
static void setObjectDirty(const std::shared_ptr< ObjectMeshHolder > &obj)
Definition MRChangeColoringActions.h:99
ChangeFacesColorMapAction(const std::string &name, const std::shared_ptr< ObjectMeshHolder > &obj)
Constructed from original obj.
Definition MRChangeColoringActions.h:79
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeColoringActions.h:105
Definition MRChangeColoringActions.h:119
virtual std::string name() const override
Definition MRChangeColoringActions.h:131
static void setObjectDirty(const std::shared_ptr< ObjectLinesHolder > &obj)
Definition MRChangeColoringActions.h:143
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeColoringActions.h:149
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeColoringActions.h:136
ChangeLinesColorMapAction(const std::string &name, const std::shared_ptr< ObjectLinesHolder > &obj)
Constructed from original obj.
Definition MRChangeColoringActions.h:123
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:7