MeshLib C++ Docs
Loading...
Searching...
No Matches
MRChangeMeshDataAction.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRHistoryAction.h"
4#include "MRObjectMesh.h"
5
6namespace MR
7{
8
11
14{
15public:
16 using Obj = ObjectMesh;
17
19 ChangeMeshDataAction( std::string name, const std::shared_ptr<ObjectMesh>& obj ) :
20 objMesh_{ obj },
21 name_{ std::move( name ) }
22 {
23 if ( objMesh_ )
24 data_ = objMesh_->data();
25 }
26
28 ChangeMeshDataAction( std::string name, const std::shared_ptr<ObjectMesh>& obj, ObjectMeshData&& newData ) :
29 objMesh_{ obj },
30 name_{ std::move( name ) }
31 {
32 if ( objMesh_ )
33 {
34 data_ = std::move( newData );
35 objMesh_->updateData( data_ );
36 }
37 }
38
39 virtual std::string name() const override
40 {
41 return name_;
42 }
43
44 virtual void action( HistoryAction::Type ) override
45 {
46 if ( !objMesh_ )
47 return;
48
49 objMesh_->updateData( data_ );
50 }
51
52 static void setObjectDirty( const std::shared_ptr<ObjectMesh>& obj )
53 {
54 if ( obj )
55 obj->setDirtyFlags( DIRTY_ALL );
56 }
57
58 [[nodiscard]] virtual size_t heapBytes() const override
59 {
60 return name_.capacity() + data_.heapBytes();
61 }
62
63private:
64 std::shared_ptr<ObjectMesh> objMesh_;
65 ObjectMeshData data_;
66
67 std::string name_;
68};
69
71
72} // namespace MR
Undo action for ObjectMeshData change.
Definition MRChangeMeshDataAction.h:14
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeMeshDataAction.h:44
virtual std::string name() const override
Definition MRChangeMeshDataAction.h:39
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshDataAction.h:58
static void setObjectDirty(const std::shared_ptr< ObjectMesh > &obj)
Definition MRChangeMeshDataAction.h:52
ChangeMeshDataAction(std::string name, const std::shared_ptr< ObjectMesh > &obj, ObjectMeshData &&newData)
use this constructor to remember object's data and immediately set new data
Definition MRChangeMeshDataAction.h:28
ChangeMeshDataAction(std::string name, const std::shared_ptr< ObjectMesh > &obj)
use this constructor to remember object's data before making any changes in it
Definition MRChangeMeshDataAction.h:19
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
Definition MRObjectMesh.h:11
@ DIRTY_ALL
Definition MRVisualObject.h:99
mesh and its per-element attributes for ObjectMeshHolder
Definition MRObjectMeshData.h:12
MRMESH_API size_t heapBytes() const
returns the amount of memory this object occupies on heap