MeshLib Documentation
Loading...
Searching...
No Matches
MRChangeObjectAction.h
Go to the documentation of this file.
1#pragma once
2#include "MRHistoryAction.h"
3#include "MRObject.h"
4#include "MRVisualObject.h"
5#include "MRHeapBytes.h"
6#include <memory>
7
8namespace MR
9{
10
14{
15public:
17 ChangeObjectAction( const std::string& name, const std::shared_ptr<Object>& obj ):
18 obj_{ obj },
19 name_{name}
20 {
21 if ( obj )
22 {
23 cloneObj_ = obj->clone();
24
25 // do not save ClippedByPlane property in Undo, TODO move the logic in SectionPlugin
26 if ( auto visObj = cloneObj_->asType<VisualObject>() )
27 visObj->setVisualizeProperty( false, VisualizeMaskType::ClippedByPlane, ViewportMask::all() );
28 }
29 }
30
31 virtual std::string name() const override { return name_; }
32
33 virtual void action( HistoryAction::Type ) override
34 {
35 if ( obj_.expired() || !cloneObj_ )
36 return;
37
38 auto obj = obj_.lock();
39 auto children = obj->children();
40 for ( auto& child : children )
41 {
42 child->detachFromParent();
43 cloneObj_->addChild( child );
44 }
45
46 // do not save ClippedByPlane property in Undo, TODO move the logic in SectionPlugin
47 if ( auto visObj = obj->asType<VisualObject>() )
48 visObj->setVisualizeProperty( false, VisualizeMaskType::ClippedByPlane, ViewportMask::all() );
49
50 obj->swap( *cloneObj_ );
51 if ( auto visObj = obj->asType<VisualObject>() )
52 visObj->setDirtyFlags( DIRTY_ALL );
53 }
54
55 [[nodiscard]] virtual size_t heapBytes() const override
56 {
57 return name_.capacity() + MR::heapBytes( cloneObj_ );
58 }
59
60private:
61 std::weak_ptr<Object> obj_;
62 std::shared_ptr<Object> cloneObj_;
63 std::string name_;
64};
65
66}
Definition MRChangeObjectAction.h:14
ChangeObjectAction(const std::string &name, const std::shared_ptr< Object > &obj)
Constructed from original Object.
Definition MRChangeObjectAction.h:17
virtual std::string name() const override
Definition MRChangeObjectAction.h:31
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeObjectAction.h:55
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeObjectAction.h:33
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
static ViewportMask all()
mask meaning all or any viewports
Definition MRViewportId.h:45
Visual Object.
Definition MRVisualObject.h:131
size_t heapBytes(const std::vector< T > &vec)
returns the amount of memory given vector occupies on heap
Definition MRHeapBytes.h:15
@ DIRTY_ALL
Definition MRVisualObject.h:109
Definition MRCameraOrientationPlugin.h:8