MeshLib C++ Docs
Loading...
Searching...
No Matches
MRChangePolylineAction.h
Go to the documentation of this file.
1#pragma once
2#include "MRHistoryAction.h"
3#include "MRObjectLines.h"
4#include "MRPolyline.h"
5#include "MRHeapBytes.h"
6#include <memory>
7
8namespace MR
9{
10
13
16{
17public:
19
21 ChangePolylineAction( std::string name, const std::shared_ptr<ObjectLines>& obj ) :
22 objLines_{ obj },
23 name_{ std::move( name ) }
24 {
25 if ( obj )
26 {
27 if ( auto p = obj->polylinePtr() )
28 clonePolyline_ = std::make_shared<Polyline3>( *p );
29 }
30 }
31
33 ChangePolylineAction( std::string name, const std::shared_ptr<ObjectLines>& obj, std::shared_ptr<Polyline3> newPolyline ) :
34 objLines_{ obj },
35 name_{ std::move( name ) }
36 {
37 if ( obj )
38 clonePolyline_ = obj->updatePolyline( std::move( newPolyline ) );
39 }
40
41 virtual std::string name() const override
42 {
43 return name_;
44 }
45
46 virtual void action( HistoryAction::Type ) override
47 {
48 if ( !objLines_ )
49 return;
50
51 clonePolyline_ = objLines_->updatePolyline( clonePolyline_ );
52 }
53
54 static void setObjectDirty( const std::shared_ptr<ObjectLines>& obj )
55 {
56 if ( obj )
57 obj->setDirtyFlags( DIRTY_ALL );
58 }
59
60 [[nodiscard]] virtual size_t heapBytes() const override
61 {
62 return name_.capacity() + MR::heapBytes( clonePolyline_ );
63 }
64
65private:
66 std::shared_ptr<ObjectLines> objLines_;
67 std::shared_ptr<Polyline3> clonePolyline_;
68
69 std::string name_;
70};
71
74{
75public:
77
79 ChangePolylinePointsAction( std::string name, const std::shared_ptr<ObjectLines>& obj ) :
80 objLines_{ obj },
81 name_{ std::move( name ) }
82 {
83 if ( !objLines_ )
84 return;
85 if ( auto p = objLines_->polylinePtr() )
86 clonePoints_ = p->points;
87 }
88
90 ChangePolylinePointsAction( std::string name, const std::shared_ptr<ObjectLines>& obj, VertCoords && newPoints ) :
91 objLines_{ obj },
92 clonePoints_{ std::move( newPoints ) },
93 name_{ std::move( name ) }
94 {
96 }
97
98 virtual std::string name() const override
99 {
100 return name_;
101 }
102
103 virtual void action( HistoryAction::Type ) override
104 {
105 if ( !objLines_ )
106 return;
107
108 if ( auto p = objLines_->varPolyline() )
109 {
110 std::swap( p->points, clonePoints_ );
111 objLines_->setDirtyFlags( DIRTY_POSITION );
112 }
113 }
114
115 static void setObjectDirty( const std::shared_ptr<ObjectLines>& obj )
116 {
117 if ( obj )
118 obj->setDirtyFlags( DIRTY_POSITION );
119 }
120
121 [[nodiscard]] virtual size_t heapBytes() const override
122 {
123 return name_.capacity() + clonePoints_.heapBytes();
124 }
125
126private:
127 std::shared_ptr<ObjectLines> objLines_;
128 VertCoords clonePoints_;
129
130 std::string name_;
131};
132
135{
136public:
138
140 ChangePolylineTopologyAction( std::string name, const std::shared_ptr<ObjectLines>& obj ) :
141 objLines_{ obj },
142 name_{ std::move( name ) }
143 {
144 if ( !objLines_ )
145 return;
146 if ( auto p = objLines_->polylinePtr() )
147 cloneTopology_ = p->topology;
148 }
149
150 virtual std::string name() const override
151 {
152 return name_;
153 }
154
155 virtual void action( HistoryAction::Type ) override
156 {
157 if ( !objLines_ )
158 return;
159
160 if ( auto p = objLines_->varPolyline() )
161 {
162 std::swap( p->topology, cloneTopology_ );
163 objLines_->setDirtyFlags( DIRTY_FACE );
164 }
165 }
166
167 static void setObjectDirty( const std::shared_ptr<ObjectLines>& obj )
168 {
169 if ( obj )
170 obj->setDirtyFlags( DIRTY_FACE );
171 }
172
173 [[nodiscard]] virtual size_t heapBytes() const override
174 {
175 return name_.capacity() + cloneTopology_.heapBytes();
176 }
177
178private:
179 std::shared_ptr<ObjectLines> objLines_;
180 PolylineTopology cloneTopology_;
181
182 std::string name_;
183};
184
185
189{
190public:
192
194 ChangeOnePointInPolylineAction( std::string name, const std::shared_ptr<ObjectLines>& obj, VertId pointId ) :
195 objPoints_{ obj },
196 pointId_{ pointId },
197 name_{ std::move( name ) }
198 {
199 if ( obj )
200 {
201 if ( auto m = obj->polylinePtr() )
202 if ( m->points.size() > pointId_ )
203 safeCoords_ = m->points[pointId_];
204 }
205 }
206
208 ChangeOnePointInPolylineAction( std::string name, const std::shared_ptr<ObjectLines>& obj, VertId pointId, const Vector3f & newCoords ) :
209 objPoints_{ obj },
210 pointId_{ pointId },
211 safeCoords_{ newCoords },
212 name_{ std::move( name ) }
213 {
215 }
216
217 virtual std::string name() const override
218 {
219 return name_;
220 }
221
222 virtual void action( HistoryAction::Type ) override
223 {
224 if ( !objPoints_ )
225 return;
226
227 if ( auto m = objPoints_->varPolyline() )
228 {
229 if ( m->points.size() > pointId_ )
230 {
231 std::swap( safeCoords_, m->points[pointId_] );
232 objPoints_->setDirtyFlags( DIRTY_POSITION );
233 }
234 }
235 }
236
237 static void setObjectDirty( const std::shared_ptr<ObjectLines>& obj )
238 {
239 if ( obj )
240 obj->setDirtyFlags( DIRTY_POSITION );
241 }
242
243 [[nodiscard]] virtual size_t heapBytes() const override
244 {
245 return name_.capacity();
246 }
247
248private:
249 std::shared_ptr<ObjectLines> objPoints_;
250 VertId pointId_;
251 Vector3f safeCoords_;
252
253 std::string name_;
254};
255
257
258}
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePolylineAction.h:222
virtual std::string name() const override
Definition MRChangePolylineAction.h:217
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePolylineAction.h:243
ChangeOnePointInPolylineAction(std::string name, const std::shared_ptr< ObjectLines > &obj, VertId pointId, const Vector3f &newCoords)
use this constructor to remember point's coordinates and immediate set new coordinates
Definition MRChangePolylineAction.h:208
ChangeOnePointInPolylineAction(std::string name, const std::shared_ptr< ObjectLines > &obj, VertId pointId)
use this constructor to remember point's coordinates before making any changes in it
Definition MRChangePolylineAction.h:194
static void setObjectDirty(const std::shared_ptr< ObjectLines > &obj)
Definition MRChangePolylineAction.h:237
ObjectLines Obj
Definition MRChangePolylineAction.h:191
ChangePolylineAction(std::string name, const std::shared_ptr< ObjectLines > &obj)
use this constructor to remember object's polyline before making any changes in it
Definition MRChangePolylineAction.h:21
static void setObjectDirty(const std::shared_ptr< ObjectLines > &obj)
Definition MRChangePolylineAction.h:54
virtual std::string name() const override
Definition MRChangePolylineAction.h:41
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePolylineAction.h:60
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePolylineAction.h:46
ChangePolylineAction(std::string name, const std::shared_ptr< ObjectLines > &obj, std::shared_ptr< Polyline3 > newPolyline)
use this constructor to remember object's polyline and immediately set new polyline
Definition MRChangePolylineAction.h:33
ObjectLines Obj
Definition MRChangePolylineAction.h:18
ObjectLines Obj
Definition MRChangePolylineAction.h:76
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePolylineAction.h:103
ChangePolylinePointsAction(std::string name, const std::shared_ptr< ObjectLines > &obj, VertCoords &&newPoints)
use this constructor to remember object's lines points and immediate set new value
Definition MRChangePolylineAction.h:90
ChangePolylinePointsAction(std::string name, const std::shared_ptr< ObjectLines > &obj)
use this constructor to remember object's lines points before making any changes in it
Definition MRChangePolylineAction.h:79
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePolylineAction.h:121
static void setObjectDirty(const std::shared_ptr< ObjectLines > &obj)
Definition MRChangePolylineAction.h:115
virtual std::string name() const override
Definition MRChangePolylineAction.h:98
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePolylineAction.h:155
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePolylineAction.h:173
virtual std::string name() const override
Definition MRChangePolylineAction.h:150
static void setObjectDirty(const std::shared_ptr< ObjectLines > &obj)
Definition MRChangePolylineAction.h:167
ChangePolylineTopologyAction(std::string name, const std::shared_ptr< ObjectLines > &obj)
use this constructor to remember object's lines points before making any changes in it
Definition MRChangePolylineAction.h:140
ObjectLines Obj
Definition MRChangePolylineAction.h:137
Definition MRObjectLines.h:14
Definition MRPolylineTopology.h:18
size_t heapBytes(const BitSet &bs)
returns the amount of memory given BitSet occupies on heap
Definition MRBitSet.h:377
Type
Definition MRHistoryAction.h:27
HistoryAction()=default
explicitly define ctors to avoid warning C5267: definition of implicit copy constructor is deprecated...
@ Redo
Definition MRHistoryAction.h:29
@ DIRTY_POSITION
Definition MRVisualObject.h:77
@ DIRTY_FACE
Definition MRVisualObject.h:85
@ DIRTY_ALL
Definition MRVisualObject.h:94
only for bindings generation
Definition MRCameraOrientationPlugin.h:8