MeshLib
 
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
32 virtual std::string name() const override
33 {
34 return name_;
35 }
36
37 virtual void action( HistoryAction::Type ) override
38 {
39 if ( !objLines_ )
40 return;
41
42 clonePolyline_ = objLines_->updatePolyline( clonePolyline_ );
43 }
44
45 static void setObjectDirty( const std::shared_ptr<ObjectLines>& obj )
46 {
47 if ( obj )
48 obj->setDirtyFlags( DIRTY_ALL );
49 }
50
51 [[nodiscard]] virtual size_t heapBytes() const override
52 {
53 return name_.capacity() + MR::heapBytes( clonePolyline_ );
54 }
55
56private:
57 std::shared_ptr<ObjectLines> objLines_;
58 std::shared_ptr<Polyline3> clonePolyline_;
59
60 std::string name_;
61};
62
65{
66public:
68
70 ChangePolylinePointsAction( std::string name, const std::shared_ptr<ObjectLines>& obj ) :
71 objLines_{ obj },
72 name_{ std::move( name ) }
73 {
74 if ( !objLines_ )
75 return;
76 if ( auto p = objLines_->polyline() )
77 clonePoints_ = p->points;
78 }
79
80 virtual std::string name() const override
81 {
82 return name_;
83 }
84
85 virtual void action( HistoryAction::Type ) override
86 {
87 if ( !objLines_ )
88 return;
89
90 if ( auto p = objLines_->varPolyline() )
91 {
92 std::swap( p->points, clonePoints_ );
93 objLines_->setDirtyFlags( DIRTY_POSITION );
94 }
95 }
96
97 static void setObjectDirty( const std::shared_ptr<ObjectLines>& obj )
98 {
99 if ( obj )
100 obj->setDirtyFlags( DIRTY_POSITION );
101 }
102
103 [[nodiscard]] virtual size_t heapBytes() const override
104 {
105 return name_.capacity() + clonePoints_.heapBytes();
106 }
107
108private:
109 std::shared_ptr<ObjectLines> objLines_;
110 VertCoords clonePoints_;
111
112 std::string name_;
113};
114
117{
118public:
120
122 ChangePolylineTopologyAction( std::string name, const std::shared_ptr<ObjectLines>& obj ) :
123 objLines_{ obj },
124 name_{ std::move( name ) }
125 {
126 if ( !objLines_ )
127 return;
128 if ( auto p = objLines_->polyline() )
129 cloneTopology_ = p->topology;
130 }
131
132 virtual std::string name() const override
133 {
134 return name_;
135 }
136
137 virtual void action( HistoryAction::Type ) override
138 {
139 if ( !objLines_ )
140 return;
141
142 if ( auto p = objLines_->varPolyline() )
143 {
144 std::swap( p->topology, cloneTopology_ );
145 objLines_->setDirtyFlags( DIRTY_FACE );
146 }
147 }
148
149 static void setObjectDirty( const std::shared_ptr<ObjectLines>& obj )
150 {
151 if ( obj )
152 obj->setDirtyFlags( DIRTY_FACE );
153 }
154
155 [[nodiscard]] virtual size_t heapBytes() const override
156 {
157 return name_.capacity() + cloneTopology_.heapBytes();
158 }
159
160private:
161 std::shared_ptr<ObjectLines> objLines_;
162 PolylineTopology cloneTopology_;
163
164 std::string name_;
165};
166
168
169} // namespace MR
List< Vector3f^> VertCoords
Definition MRDotNet/MRMeshFwd.h:95
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:45
virtual std::string name() const override
Definition MRChangePolylineAction.h:32
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePolylineAction.h:51
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePolylineAction.h:37
Undo action for ObjectLines points only (not topology) change.
Definition MRChangePolylineAction.h:65
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePolylineAction.h:85
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:70
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePolylineAction.h:103
static void setObjectDirty(const std::shared_ptr< ObjectLines > &obj)
Definition MRChangePolylineAction.h:97
virtual std::string name() const override
Definition MRChangePolylineAction.h:80
Undo action for ObjectLines topology only (not points) change.
Definition MRChangePolylineAction.h:117
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePolylineAction.h:137
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePolylineAction.h:155
virtual std::string name() const override
Definition MRChangePolylineAction.h:132
static void setObjectDirty(const std::shared_ptr< ObjectLines > &obj)
Definition MRChangePolylineAction.h:149
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:122
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
MRMESH_API size_t heapBytes(const FloatGrid &grid)
returns the amount of heap memory occupied by grid
@ DIRTY_POSITION
Definition MRVisualObject.h:90
@ DIRTY_FACE
Definition MRVisualObject.h:99
@ DIRTY_ALL
Definition MRVisualObject.h:109
Definition MRCameraOrientationPlugin.h:7