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{
11
12
15{
16public:
17 virtual ~IPluginUpdate() = default;
19 virtual void preDrawUpdate() {}
20protected:
22 virtual void onPluginEnable_() { }
24 virtual void onPluginDisable_() { }
26 virtual bool shouldClose_() const { return false; }
27};
28
31class MRVIEWER_CLASS PluginCloseOnSelectedObjectRemove : public virtual IPluginUpdate
32{
33protected:
34 MRVIEWER_API virtual void onPluginEnable_() override;
35 MRVIEWER_API virtual void onPluginDisable_() override;
36 MRVIEWER_API virtual bool shouldClose_() const override;
37private:
38 std::vector<std::shared_ptr<MR::Object>> selectedObjs_;
39};
40
43class MRVIEWER_CLASS PluginCloseOnChangeMesh : public virtual IPluginUpdate
44{
45protected:
47 MRVIEWER_API virtual bool reactOnFaceSelectionChanges_() const { return false; }
48
49 MRVIEWER_API virtual void onPluginEnable_() override;
50 MRVIEWER_API virtual void onPluginDisable_() override;
51 MRVIEWER_API virtual bool shouldClose_() const override;
53 bool meshChanged_{ false };
54
55private:
56 std::vector<boost::signals2::scoped_connection> meshChangedConnections_;
57};
58
62class MRVIEWER_CLASS PluginUpdateOnChangeMeshPart : public virtual IPluginUpdate
63{
64public:
65 using UpdateFunc = std::function<void()>;
67 void setUpdateFunc( UpdateFunc func ) { func_ = func; }
68 MRVIEWER_API virtual void preDrawUpdate() override;
69protected:
71 MRVIEWER_API virtual void onPluginEnable_() override;
73 MRVIEWER_API virtual void onPluginDisable_() override;
74private:
75 bool dirty_{ false };
76 UpdateFunc func_;
77 std::vector<boost::signals2::scoped_connection> connections_;
78};
79
82class MRVIEWER_CLASS PluginCloseOnChangePointCloud : public virtual IPluginUpdate
83{
84protected:
85 MRVIEWER_API virtual void onPluginEnable_() override;
86 MRVIEWER_API virtual void onPluginDisable_() override;
87 MRVIEWER_API virtual bool shouldClose_() const override;
89 bool pointCloudChanged_{ false };
90
91private:
92 std::vector<boost::signals2::scoped_connection> pointCloudChangedConnections_;
93};
94
96class MRVIEWER_CLASS PluginCloseOnEscPressed : public virtual IPluginUpdate
97{
98protected:
99 MRVIEWER_API bool shouldClose_() const override;
100};
101
104template<typename ...Updates>
105class PluginUpdateOr : public Updates...
106{
107public:
108 virtual void preDrawUpdate() override
109 {
110 ( Updates::preDrawUpdate(), ... );
111 }
112protected:
113 virtual void onPluginEnable_() override
114 {
115 ( Updates::onPluginEnable_(), ... );
116 }
117 virtual void onPluginDisable_() override
118 {
120 [[maybe_unused]] int dummy;
121 ( void )( dummy = ... = ( Updates::onPluginDisable_(), 0 ) );
122 }
123 virtual bool shouldClose_() const override
124 {
125 return ( Updates::shouldClose_() || ... );
126 }
127};
128
129}
Interface for automatically update StatePlugins internal data.
Definition MRStatePluginUpdate.h:15
Definition MRStatePluginUpdate.h:44
Definition MRStatePluginUpdate.h:83
Helper class to close a dialog-less plugin when the Esc key is pressed.
Definition MRStatePluginUpdate.h:97
Definition MRStatePluginUpdate.h:32
Definition MRStatePluginUpdate.h:63
Definition MRStatePluginUpdate.h:106
virtual void onPluginDisable_()
called when plugin stops
Definition MRStatePluginUpdate.h:24
virtual MRVIEWER_API bool shouldClose_() const override
called each frame, return true to close plugin
MRVIEWER_API bool shouldClose_() const override
called each frame, return true to close plugin
virtual MRVIEWER_API void onPluginEnable_() override
called when plugin started
virtual MRVIEWER_API void onPluginEnable_() override
called when plugin started
virtual MRVIEWER_API void onPluginDisable_() override
called when plugin stops
virtual ~IPluginUpdate()=default
virtual MRVIEWER_API void onPluginEnable_() override
called when plugin started
virtual MRVIEWER_API bool reactOnFaceSelectionChanges_() const
plugin can override it to make this helper class also react on face selections updates
Definition MRStatePluginUpdate.h:47
virtual MRVIEWER_API void onPluginDisable_() override
clears connections and UpdateFunc
virtual void preDrawUpdate()
called each frame in before drawDialog
Definition MRStatePluginUpdate.h:19
virtual void preDrawUpdate() override
Definition MRStatePluginUpdate.h:108
std::function< void()> UpdateFunc
Definition MRStatePluginUpdate.h:65
virtual MRVIEWER_API bool shouldClose_() const override
called each frame, return true to close plugin
virtual MRVIEWER_API void onPluginEnable_() override
sets dirty initially for first update, so no need to call UpdateFunc manually
virtual void onPluginDisable_() override
Definition MRStatePluginUpdate.h:117
virtual bool shouldClose_() const
called each frame, return true to close plugin
Definition MRStatePluginUpdate.h:26
virtual MRVIEWER_API void preDrawUpdate() override
called each frame in before drawDialog
virtual void onPluginEnable_()
called when plugin started
Definition MRStatePluginUpdate.h:22
virtual MRVIEWER_API bool shouldClose_() const override
called each frame, return true to close plugin
virtual void onPluginEnable_() override
Definition MRStatePluginUpdate.h:113
virtual MRVIEWER_API void onPluginDisable_() override
called when plugin stops
virtual bool shouldClose_() const override
Definition MRStatePluginUpdate.h:123
virtual MRVIEWER_API void onPluginDisable_() override
called when plugin stops
void setUpdateFunc(UpdateFunc func)
setup your update function that will be called if plugin is dirty in this frame
Definition MRStatePluginUpdate.h:67
only for bindings generation
Definition MRCameraOrientationPlugin.h:8