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, bool cloneMesh ) :
20 objMesh_{ obj },
21 name_{ std::move( name ) }
22 {
23 if ( objMesh_ )
24 {
25 data_ = objMesh_->data();
26 if ( cloneMesh && data_.mesh )
27 data_.mesh = std::make_shared<Mesh>( *data_.mesh );
28 }
29 }
30
32 ChangeMeshDataAction( std::string name, const std::shared_ptr<ObjectMesh>& obj, ObjectMeshData&& newData ) :
33 objMesh_{ obj },
34 name_{ std::move( name ) }
35 {
36 if ( objMesh_ )
37 {
38 data_ = std::move( newData );
39 objMesh_->updateData( data_ );
40 }
41 }
42
43 virtual std::string name() const override
44 {
45 return name_;
46 }
47
48 virtual void action( HistoryAction::Type ) override
49 {
50 if ( !objMesh_ )
51 return;
52
53 objMesh_->updateData( data_ );
54 }
55
56 static void setObjectDirty( const std::shared_ptr<ObjectMesh>& obj )
57 {
58 if ( obj )
59 obj->setDirtyFlags( DIRTY_ALL );
60 }
61
62 [[nodiscard]] virtual size_t heapBytes() const override
63 {
64 return name_.capacity() + data_.heapBytes();
65 }
66
67 const std::shared_ptr<ObjectMesh>& obj() const { return objMesh_; }
68
69 const ObjectMeshData& data() const { return data_; }
70
71private:
72 std::shared_ptr<ObjectMesh> objMesh_;
73 ObjectMeshData data_;
74
75 std::string name_;
76};
77
79
80} // 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:48
virtual std::string name() const override
Definition MRChangeMeshDataAction.h:43
const std::shared_ptr< ObjectMesh > & obj() const
Definition MRChangeMeshDataAction.h:67
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeMeshDataAction.h:62
ChangeMeshDataAction(std::string name, const std::shared_ptr< ObjectMesh > &obj, bool cloneMesh)
use this constructor to remember object's data before making any changes in it
Definition MRChangeMeshDataAction.h:19
const ObjectMeshData & data() const
Definition MRChangeMeshDataAction.h:69
static void setObjectDirty(const std::shared_ptr< ObjectMesh > &obj)
Definition MRChangeMeshDataAction.h:56
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:32
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
Definition MRObjectMesh.h:11
@ DIRTY_ALL
Definition MRVisualObject.h:97
Definition MRCameraOrientationPlugin.h:8
mesh and its per-element attributes for ObjectMeshHolder
Definition MRObjectMeshData.h:14
MRMESH_API size_t heapBytes() const
returns the amount of memory this object occupies on heap
std::shared_ptr< Mesh > mesh
Definition MRObjectMeshData.h:15