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->polyline() )
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_->polyline() )
86 clonePoints_ = p->points;
87 }
88
89 virtual std::string name() const override
90 {
91 return name_;
92 }
93
94 virtual void action( HistoryAction::Type ) override
95 {
96 if ( !objLines_ )
97 return;
98
99 if ( auto p = objLines_->varPolyline() )
100 {
101 std::swap( p->points, clonePoints_ );
102 objLines_->setDirtyFlags( DIRTY_POSITION );
103 }
104 }
105
106 static void setObjectDirty( const std::shared_ptr<ObjectLines>& obj )
107 {
108 if ( obj )
109 obj->setDirtyFlags( DIRTY_POSITION );
110 }
111
112 [[nodiscard]] virtual size_t heapBytes() const override
113 {
114 return name_.capacity() + clonePoints_.heapBytes();
115 }
116
117private:
118 std::shared_ptr<ObjectLines> objLines_;
119 VertCoords clonePoints_;
120
121 std::string name_;
122};
123
126{
127public:
129
131 ChangePolylineTopologyAction( std::string name, const std::shared_ptr<ObjectLines>& obj ) :
132 objLines_{ obj },
133 name_{ std::move( name ) }
134 {
135 if ( !objLines_ )
136 return;
137 if ( auto p = objLines_->polyline() )
138 cloneTopology_ = p->topology;
139 }
140
141 virtual std::string name() const override
142 {
143 return name_;
144 }
145
146 virtual void action( HistoryAction::Type ) override
147 {
148 if ( !objLines_ )
149 return;
150
151 if ( auto p = objLines_->varPolyline() )
152 {
153 std::swap( p->topology, cloneTopology_ );
154 objLines_->setDirtyFlags( DIRTY_FACE );
155 }
156 }
157
158 static void setObjectDirty( const std::shared_ptr<ObjectLines>& obj )
159 {
160 if ( obj )
161 obj->setDirtyFlags( DIRTY_FACE );
162 }
163
164 [[nodiscard]] virtual size_t heapBytes() const override
165 {
166 return name_.capacity() + cloneTopology_.heapBytes();
167 }
168
169private:
170 std::shared_ptr<ObjectLines> objLines_;
171 PolylineTopology cloneTopology_;
172
173 std::string name_;
174};
175
177
178} // namespace MR
Undo action for ObjectLines polyline change.
Definition MRChangePolylineAction.h:16
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
Undo action for ObjectLines points only (not topology) change.
Definition MRChangePolylineAction.h:74
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePolylineAction.h:94
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:112
static void setObjectDirty(const std::shared_ptr< ObjectLines > &obj)
Definition MRChangePolylineAction.h:106
virtual std::string name() const override
Definition MRChangePolylineAction.h:89
Undo action for ObjectLines topology only (not points) change.
Definition MRChangePolylineAction.h:126
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePolylineAction.h:146
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePolylineAction.h:164
virtual std::string name() const override
Definition MRChangePolylineAction.h:141
static void setObjectDirty(const std::shared_ptr< ObjectLines > &obj)
Definition MRChangePolylineAction.h:158
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:131
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
Definition MRObjectLines.h:11
Definition MRPolylineTopology.h:15
MRMESH_API size_t heapBytes() const
returns the amount of memory this object occupies on heap
size_t heapBytes(const BitSet &bs)
returns the amount of memory given BitSet occupies on heap
Definition MRMesh/MRBitSet.h:226
@ DIRTY_POSITION
Definition MRVisualObject.h:80
@ DIRTY_FACE
Definition MRVisualObject.h:89
@ DIRTY_ALL
Definition MRVisualObject.h:100
Definition MRCameraOrientationPlugin.h:8