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
51 MRVIEWER_API virtual uint32_t closeOnDirtyMask_() const;
52
53 MRVIEWER_API virtual void onPluginEnable_() override;
54 MRVIEWER_API virtual void onPluginDisable_() override;
55 MRVIEWER_API virtual bool shouldClose_() const override;
57 bool meshChanged_{ false };
58
59private:
60 std::vector<boost::signals2::scoped_connection> meshChangedConnections_;
61};
62
66class MRVIEWER_CLASS PluginUpdateOnChangeMeshPart : public virtual IPluginUpdate
67{
68public:
69 using UpdateFunc = std::function<void()>;
71 void setUpdateFunc( UpdateFunc func ) { func_ = func; }
72 MRVIEWER_API virtual void preDrawUpdate() override;
73protected:
75 MRVIEWER_API virtual void onPluginEnable_() override;
77 MRVIEWER_API virtual void onPluginDisable_() override;
78private:
79 bool dirty_{ false };
80 UpdateFunc func_;
81 std::vector<boost::signals2::scoped_connection> connections_;
82};
83
86class MRVIEWER_CLASS PluginCloseOnChangePointCloud : public virtual IPluginUpdate
87{
88protected:
89 MRVIEWER_API virtual void onPluginEnable_() override;
90 MRVIEWER_API virtual void onPluginDisable_() override;
91 MRVIEWER_API virtual bool shouldClose_() const override;
93 bool pointCloudChanged_{ false };
94
95private:
96 std::vector<boost::signals2::scoped_connection> pointCloudChangedConnections_;
97};
98
100class MRVIEWER_CLASS PluginCloseOnEscPressed : public virtual IPluginUpdate
101{
102protected:
103 MRVIEWER_API bool shouldClose_() const override;
104};
105
108template<typename ...Updates>
109class PluginUpdateOr : public Updates...
110{
111public:
112 virtual void preDrawUpdate() override
113 {
114 ( Updates::preDrawUpdate(), ... );
115 }
116protected:
117 virtual void onPluginEnable_() override
118 {
119 ( Updates::onPluginEnable_(), ... );
120 }
121 virtual void onPluginDisable_() override
122 {
124 [[maybe_unused]] int dummy;
125 ( void )( dummy = ... = ( Updates::onPluginDisable_(), 0 ) );
126 }
127 virtual bool shouldClose_() const override
128 {
129 return ( Updates::shouldClose_() || ... );
130 }
131};
132
133}
Interface for automatically update StatePlugins internal data.
Definition MRStatePluginUpdate.h:15
Definition MRStatePluginUpdate.h:44
Definition MRStatePluginUpdate.h:87
Helper class to close a dialog-less plugin when the Esc key is pressed.
Definition MRStatePluginUpdate.h:101
Definition MRStatePluginUpdate.h:32
Definition MRStatePluginUpdate.h:67
Definition MRStatePluginUpdate.h:110
virtual void onPluginDisable_()
called when plugin stops
Definition MRStatePluginUpdate.h:24
virtual void onPluginEnable_() override
called when plugin started
virtual bool shouldClose_() const override
called each frame, return true to close plugin
virtual void onPluginDisable_() override
called when plugin stops
bool shouldClose_() const override
called each frame, return true to close plugin
virtual bool shouldClose_() const override
called each frame, return true to close plugin
virtual bool shouldClose_() const override
called each frame, return true to close plugin
virtual ~IPluginUpdate()=default
virtual void onPluginEnable_() override
called when plugin started
virtual uint32_t closeOnDirtyMask_() const
virtual void preDrawUpdate()
called each frame in before drawDialog
Definition MRStatePluginUpdate.h:19
virtual void preDrawUpdate() override
Definition MRStatePluginUpdate.h:112
bool meshChanged_
plugin can return the value to false after mesh change if it changed the mesh by itself and does not ...
Definition MRStatePluginUpdate.h:57
virtual void onPluginDisable_() override
called when plugin stops
std::function< void()> UpdateFunc
Definition MRStatePluginUpdate.h:69
virtual void onPluginEnable_() override
sets dirty initially for first update, so no need to call UpdateFunc manually
virtual void onPluginDisable_() override
called when plugin stops
virtual void onPluginEnable_() override
called when plugin started
virtual void onPluginDisable_() override
clears connections and UpdateFunc
virtual void onPluginDisable_() override
Definition MRStatePluginUpdate.h:121
virtual bool shouldClose_() const
called each frame, return true to close plugin
Definition MRStatePluginUpdate.h:26
virtual void onPluginEnable_()
called when plugin started
Definition MRStatePluginUpdate.h:22
bool pointCloudChanged_
plugin can return the value to false after points change if it changed the mesh by itself and does no...
Definition MRStatePluginUpdate.h:93
virtual void onPluginEnable_() override
Definition MRStatePluginUpdate.h:117
virtual bool shouldClose_() const override
Definition MRStatePluginUpdate.h:127
virtual void preDrawUpdate() override
called each frame in before drawDialog
virtual bool reactOnFaceSelectionChanges_() const
plugin can override it to make this helper class also react on face selections updates
Definition MRStatePluginUpdate.h:47
void setUpdateFunc(UpdateFunc func)
setup your update function that will be called if plugin is dirty in this frame
Definition MRStatePluginUpdate.h:71
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8