MeshLib C++ Docs
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:
44 MRVIEWER_API virtual bool reactOnFaceSelectionChanges_() const { return false; }
45
46 MRVIEWER_API virtual void onPluginEnable_() override;
47 MRVIEWER_API virtual void onPluginDisable_() override;
48 MRVIEWER_API virtual bool shouldClose_() const override;
49 // plugin can return the value to false after mesh change if it changed the mesh by itself and does not want to close
50 bool meshChanged_{ false };
51
52private:
53 std::vector<boost::signals2::scoped_connection> meshChangedConnections_;
54};
55
56// Helper class to update plugin if any of active object meshes or selected faces have changed
57// note that events only marks plugin dirty and update happens before drawDialog function
58// inherit your plugin from it
59class MRVIEWER_CLASS PluginUpdateOnChangeMeshPart : public virtual IPluginUpdate
60{
61public:
62 using UpdateFunc = std::function<void()>;
63 // setup your update function that will be called if plugin is dirty in this frame
64 void setUpdateFunc( UpdateFunc func ) { func_ = func; }
65 MRVIEWER_API virtual void preDrawUpdate() override;
66protected:
67 // sets dirty initially for first update, so no need to call UpdateFunc manually
68 MRVIEWER_API virtual void onPluginEnable_() override;
69 // clears connections and UpdateFunc
70 MRVIEWER_API virtual void onPluginDisable_() override;
71private:
72 bool dirty_{ false };
73 UpdateFunc func_;
74 std::vector<boost::signals2::scoped_connection> connections_;
75};
76
77// Helper class to close plugin if any of active object points was changed
78// inherit your plugin from it
79class MRVIEWER_CLASS PluginCloseOnChangePointCloud : public virtual IPluginUpdate
80{
81protected:
82 MRVIEWER_API virtual void onPluginEnable_() override;
83 MRVIEWER_API virtual void onPluginDisable_() override;
84 MRVIEWER_API virtual bool shouldClose_() const override;
85 // plugin can return the value to false after points change if it changed the mesh by itself and does not want to close
86 bool pointCloudChanged_{ false };
87
88private:
89 std::vector<boost::signals2::scoped_connection> pointCloudChangedConnections_;
90};
91
92// Helper class to close a dialog-less plugin when the Esc key is pressed
93class MRVIEWER_CLASS PluginCloseOnEscPressed : public virtual IPluginUpdate
94{
95protected:
96 MRVIEWER_API bool shouldClose_() const override;
97};
98
99// Runs all preDrawUpdate and all shouldClose_ checks
100// shouldClose_ returns true if at least on of checks was ture
101template<typename ...Updates>
102class PluginUpdateOr : public Updates...
103{
104public:
105 virtual void preDrawUpdate() override
106 {
107 ( Updates::preDrawUpdate(), ... );
108 }
109protected:
110 virtual void onPluginEnable_() override
111 {
112 ( Updates::onPluginEnable_(), ... );
113 }
114 virtual void onPluginDisable_() override
115 {
116 // disconnect in reversed order
117 [[maybe_unused]] int dummy;
118 ( void )( dummy = ... = ( Updates::onPluginDisable_(), 0 ) );
119 }
120 virtual bool shouldClose_() const override
121 {
122 return ( Updates::shouldClose_() || ... );
123 }
124};
125
126}
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 reactOnFaceSelectionChanges_() const
plugin can override it to make this helper class also react on face selections updates
Definition MRStatePluginUpdate.h:44
virtual MRVIEWER_API bool shouldClose_() const override
virtual MRVIEWER_API void onPluginDisable_() override
Definition MRStatePluginUpdate.h:80
virtual MRVIEWER_API void onPluginEnable_() override
virtual MRVIEWER_API bool shouldClose_() const override
virtual MRVIEWER_API void onPluginDisable_() override
Definition MRStatePluginUpdate.h:94
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:60
virtual MRVIEWER_API void onPluginDisable_() override
std::function< void()> UpdateFunc
Definition MRStatePluginUpdate.h:62
virtual MRVIEWER_API void onPluginEnable_() override
virtual MRVIEWER_API void preDrawUpdate() override
void setUpdateFunc(UpdateFunc func)
Definition MRStatePluginUpdate.h:64
Definition MRStatePluginUpdate.h:103
virtual void preDrawUpdate() override
Definition MRStatePluginUpdate.h:105
virtual void onPluginDisable_() override
Definition MRStatePluginUpdate.h:114
virtual void onPluginEnable_() override
Definition MRStatePluginUpdate.h:110
virtual bool shouldClose_() const override
Definition MRStatePluginUpdate.h:120