MeshLib
 
Loading...
Searching...
No Matches
MRStatePluginUpdate.h
Go to the documentation of this file.
1#pragma once
2#include "MRViewerFwd.h"
3#include "exports.h"
4#include "MRMesh/MRSignal.h"
5#include <memory>
6
7namespace MR
8{
9
10// Interface for automatically update StatePlugins internal data
12{
13public:
14 virtual ~IPluginUpdate() = default;
15 // called each frame in before drawDialog
16 virtual void preDrawUpdate() {}
17protected:
18 // called when plugin started
19 virtual void onPluginEnable_() { }
20 // called when plugin stops
21 virtual void onPluginDisable_() { }
22 // called each frame, return true to close plugin
23 virtual bool shouldClose_() const { return false; }
24};
25
26// Helper class to close plugin if any of active objects was removed from scene
27// inherit your plugin from it
28class MRVIEWER_CLASS PluginCloseOnSelectedObjectRemove : public virtual IPluginUpdate
29{
30protected:
31 MRVIEWER_API virtual void onPluginEnable_() override;
32 MRVIEWER_API virtual void onPluginDisable_() override;
33 MRVIEWER_API virtual bool shouldClose_() const override;
34private:
35 std::vector<std::shared_ptr<MR::Object>> selectedObjs_;
36};
37
38// Helper class to close plugin if any of active object meshes was changed
39// inherit your plugin from it
40class MRVIEWER_CLASS PluginCloseOnChangeMesh : public virtual IPluginUpdate
41{
42protected:
43 MRVIEWER_API virtual void onPluginEnable_() override;
44 MRVIEWER_API virtual void onPluginDisable_() override;
45 MRVIEWER_API virtual bool shouldClose_() const override;
46 // plugin can return the value to false after mesh change if it changed the mesh by itself and does not want to close
47 bool meshChanged_{ false };
48
49private:
50 std::vector<boost::signals2::scoped_connection> meshChangedConnections_;
51};
52
53// Helper class to update plugin if any of active object meshes or selected faces have changed
54// note that events only marks plugin dirty and update happens before drawDialog function
55// inherit your plugin from it
56class MRVIEWER_CLASS PluginUpdateOnChangeMeshPart : public virtual IPluginUpdate
57{
58public:
59 using UpdateFunc = std::function<void()>;
60 // setup your update function that will be called if plugin is dirty in this frame
61 void setUpdateFunc( UpdateFunc func ) { func_ = func; }
62 MRVIEWER_API virtual void preDrawUpdate() override;
63protected:
64 // sets dirty initially for first update, so no need to call UpdateFunc manually
65 MRVIEWER_API virtual void onPluginEnable_() override;
66 // clears connections and UpdateFunc
67 MRVIEWER_API virtual void onPluginDisable_() override;
68private:
69 bool dirty_{ false };
70 UpdateFunc func_;
71 std::vector<boost::signals2::scoped_connection> connections_;
72};
73
74// Helper class to close plugin if any of active object points was changed
75// inherit your plugin from it
76class MRVIEWER_CLASS PluginCloseOnChangePointCloud : public virtual IPluginUpdate
77{
78protected:
79 MRVIEWER_API virtual void onPluginEnable_() override;
80 MRVIEWER_API virtual void onPluginDisable_() override;
81 MRVIEWER_API virtual bool shouldClose_() const override;
82 // plugin can return the value to false after points change if it changed the mesh by itself and does not want to close
83 bool pointCloudChanged_{ false };
84
85private:
86 std::vector<boost::signals2::scoped_connection> pointCloudChangedConnections_;
87};
88
89// Helper class to close a dialog-less plugin when the Esc key is pressed
90class MRVIEWER_CLASS PluginCloseOnEscPressed : public virtual IPluginUpdate
91{
92protected:
93 MRVIEWER_API bool shouldClose_() const override;
94};
95
96// Runs all preDrawUpdate and all shouldClose_ checks
97// shouldClose_ returns true if at least on of checks was ture
98template<typename ...Updates>
99class PluginUpdateOr : public Updates...
100{
101public:
102 virtual void preDrawUpdate() override
103 {
104 ( Updates::preDrawUpdate(), ... );
105 }
106protected:
107 virtual void onPluginEnable_() override
108 {
109 ( Updates::onPluginEnable_(), ... );
110 }
111 virtual void onPluginDisable_() override
112 {
113 // disconnect in reversed order
114 [[maybe_unused]] int dummy;
115 ( void )( dummy = ... = ( Updates::onPluginDisable_(), 0 ) );
116 }
117 virtual bool shouldClose_() const override
118 {
119 return ( Updates::shouldClose_() || ... );
120 }
121};
122
123}
Definition MRStatePluginUpdate.h:12
virtual void onPluginDisable_()
Definition MRStatePluginUpdate.h:21
virtual ~IPluginUpdate()=default
virtual void preDrawUpdate()
Definition MRStatePluginUpdate.h:16
virtual bool shouldClose_() const
Definition MRStatePluginUpdate.h:23
virtual void onPluginEnable_()
Definition MRStatePluginUpdate.h:19
Definition MRStatePluginUpdate.h:41
virtual MRVIEWER_API void onPluginEnable_() override
virtual MRVIEWER_API bool shouldClose_() const override
virtual MRVIEWER_API void onPluginDisable_() override
Definition MRStatePluginUpdate.h:77
virtual MRVIEWER_API void onPluginEnable_() override
virtual MRVIEWER_API bool shouldClose_() const override
virtual MRVIEWER_API void onPluginDisable_() override
Definition MRStatePluginUpdate.h:91
MRVIEWER_API bool shouldClose_() const override
Definition MRStatePluginUpdate.h:29
virtual MRVIEWER_API bool shouldClose_() const override
virtual MRVIEWER_API void onPluginDisable_() override
virtual MRVIEWER_API void onPluginEnable_() override
Definition MRStatePluginUpdate.h:57
virtual MRVIEWER_API void onPluginDisable_() override
std::function< void()> UpdateFunc
Definition MRStatePluginUpdate.h:59
virtual MRVIEWER_API void onPluginEnable_() override
virtual MRVIEWER_API void preDrawUpdate() override
void setUpdateFunc(UpdateFunc func)
Definition MRStatePluginUpdate.h:61
Definition MRStatePluginUpdate.h:100
virtual void preDrawUpdate() override
Definition MRStatePluginUpdate.h:102
virtual void onPluginDisable_() override
Definition MRStatePluginUpdate.h:111
virtual void onPluginEnable_() override
Definition MRStatePluginUpdate.h:107
virtual bool shouldClose_() const override
Definition MRStatePluginUpdate.h:117
Definition MRCameraOrientationPlugin.h:7