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
14class ChangeObjectColorAction : public HistoryAction
15{
16public:
17 using Obj = VisualObject;
18
19 enum class Type
20 {
21 Unselected,
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;
46 ViewportProperty<Color> colors =
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_;
68 ViewportProperty<Color> colors_;
69 std::string name_;
70};
71
74class ChangeFacesColorMapAction : public HistoryAction
75{
76public:
77 using Obj = ObjectMeshHolder;
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
131class ChangeLinesColorMapAction : public HistoryAction
132{
133public:
134 using Obj = ObjectLinesHolder;
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}
Selected
object itself is selected and all its ancestors are selectable
Definition MRObjectsAccess.h:18
unsafe void action(MR.HistoryAction.Type _1)
unsafe ChangeFacesColorMapAction(MR._ByValue_ChangeFacesColorMapAction _other)
unsafe void action(MR.HistoryAction.Type _1)
unsafe ChangeLinesColorMapAction(MR._ByValue_ChangeLinesColorMapAction _other)
unsafe void action(MR.HistoryAction.Type _1)
unsafe ChangeObjectColorAction(MR._ByValue_ChangeObjectColorAction _other)
std::string name(const T &primitive)
Definition MRFeatures.h:309
Definition MRCameraOrientationPlugin.h:8