MeshLib Documentation
Loading...
Searching...
No Matches
MRChangeSceneObjectsOrder.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRHistoryAction.h"
4#include "MRObject.h"
5#include "MRHeapBytes.h"
6
7namespace MR
8{
9
13{
14public:
16 ChangeSceneObjectsOrder( const std::string& name, const std::shared_ptr<Object>& obj ) :
17 obj_( obj ),
18 name_( name )
19 {
20 if ( obj_ )
21 childrenOrder_ = obj_->children();
22 }
23
24 virtual std::string name() const override { return name_; }
25
26 virtual void action( HistoryAction::Type ) override
27 {
28 if ( !obj_ )
29 return;
30
31 std::vector<std::shared_ptr<Object>> oldOrder = obj_->children();
32 for ( auto& child : oldOrder )
33 {
34 child->detachFromParent();
35 }
36 for ( const auto& child : childrenOrder_ )
37 {
38 if ( child->parent() )
39 child->detachFromParent();
40 obj_->addChild( child );
41 }
42 childrenOrder_ = std::move( oldOrder );
43 };
44
45 [[nodiscard]] virtual size_t heapBytes() const override
46 {
47 return MR::heapBytes( childrenOrder_ )
48 + name_.capacity();
49 }
50
51private:
52 std::vector<std::shared_ptr<Object>> childrenOrder_;
53 std::shared_ptr<Object> obj_;
54 std::string name_;
55};
56
57}
Definition MRChangeSceneObjectsOrder.h:13
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeSceneObjectsOrder.h:26
ChangeSceneObjectsOrder(const std::string &name, const std::shared_ptr< Object > &obj)
Constructed before change order.
Definition MRChangeSceneObjectsOrder.h:16
virtual std::string name() const override
Definition MRChangeSceneObjectsOrder.h:24
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeSceneObjectsOrder.h:45
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
size_t heapBytes(const std::vector< T > &vec)
returns the amount of memory given vector occupies on heap
Definition MRHeapBytes.h:15
Definition MRCameraOrientationPlugin.h:8