MeshLib C++ Docs
Loading...
Searching...
No Matches
MRChangeScaleAction.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 ChangeScaleAction( const std::string& name, const std::shared_ptr<Object>& obj, float scale ) :
18 obj_{ obj },
19 name_{ name }
20 {
21 if ( obj )
22 {
23 obj->applyScale(scale);
24 scale_ = 1.0f / scale;
25 }
26 }
27
28 virtual std::string name() const override
29 {
30 return name_;
31 }
32
33 virtual void action( HistoryAction::Type ) override
34 {
35 if ( !obj_ )
36 return;
37
38 obj_->applyScale( scale_ );
39 scale_ = 1.0f / scale_;
40 }
41
42 [[nodiscard]] virtual size_t heapBytes() const override
43 {
44 return name_.capacity();
45 }
46
47private:
48 std::shared_ptr<Object> obj_;
49 float scale_ = 1.0f;
50 std::string name_;
51};
52
53}
Definition MRChangeScaleAction.h:14
virtual std::string name() const override
Definition MRChangeScaleAction.h:28
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeScaleAction.h:42
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeScaleAction.h:33
ChangeScaleAction(const std::string &name, const std::shared_ptr< Object > &obj, float scale)
Constructor that performs object scaling, and remembers inverted scale value for undoing.
Definition MRChangeScaleAction.h:17
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19