MeshLib C++ Docs
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
13class ChangeObjectAction : public HistoryAction
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}
unsafe ChangeObjectAction(MR._ByValue_ChangeObjectAction _other)
unsafe void action(MR.HistoryAction.Type _1)
size_t heapBytes(const BitSet &bs)
returns the amount of memory given BitSet occupies on heap
Definition MRMesh/MRBitSet.h:298
std::string name(const T &primitive)
Definition MRFeatures.h:309
Definition MRCameraOrientationPlugin.h:8