MeshLib Documentation
Loading...
Searching...
No Matches
MRSwapRootAction.h
Go to the documentation of this file.
1#pragma once
3#include "MRMesh/MRObject.h"
6#include "MRViewer.h"
7#include <memory>
8
9namespace MR
10{
11
13{
14public:
15 // Constructed from original root
16 SwapRootAction( const std::string& name ) :
17 root_{ SceneRoot::getSharedPtr() },
18 scenePath_{ SceneRoot::getScenePath() },
19 name_{ name }
20 {
21 }
22
23 virtual std::string name() const override
24 {
25 return name_;
26 }
27
28 virtual void action( HistoryAction::Type ) override
29 {
30 if ( !root_ )
31 return;
32 std::swap( root_, SceneRoot::getSharedPtr() );
34 auto scenePathClone = SceneRoot::getScenePath();
35 SceneRoot::setScenePath( scenePath_ );
36 scenePath_ = scenePathClone;
37
39 }
40
41 [[nodiscard]] virtual size_t heapBytes() const override
42 {
43 return scenePath_.native().capacity() * sizeof( scenePath_.native()[0] )
44 + name_.capacity()
45 + MR::heapBytes( root_ );
46 }
47
48private:
49 std::shared_ptr<SceneRootObject> root_;
50 std::filesystem::path scenePath_;
51 std::string name_;
52};
53
54}
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
Definition MRSceneRoot.h:40
static MRMESH_API std::shared_ptr< SceneRootObject > & getSharedPtr()
static MRMESH_API const std::filesystem::path & getScenePath()
static MRMESH_API void setScenePath(const std::filesystem::path &scenePath)
Definition MRSwapRootAction.h:13
virtual std::string name() const override
Definition MRSwapRootAction.h:23
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRSwapRootAction.h:28
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRSwapRootAction.h:41
SwapRootAction(const std::string &name)
Definition MRSwapRootAction.h:16
MRVIEWER_API void makeTitleFromSceneRootPath()
void setSceneDirty()
Definition MRViewer.h:174
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
MRVIEWER_API Viewer & getViewerInstance()
returns global instance of Viewer class