MeshLib Documentation
Loading...
Searching...
No Matches
MRStatePlugin.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRViewerPlugin.h"
4#include "MRSceneStateCheck.h"
8#include "MRRibbonMenuItem.h"
9#include "ImGuiHelpers.h"
10#include <filesystem>
11
12struct ImGuiContext;
13
14namespace MR
15{
16/*
17Inheritance diagram:
18
19 EP - End Plugin
20 SLP - StateListenerPlugin (optional), if not present EP->SBP
21 ML - MultiListener
22 Con - Connectables (can be a lot of them)
23 ConHold - ConnectionHolder (one for each Connectable)
24 ICon - IConnectable virtual (one for all ConnectionHolder)
25 SBP - StateBasePlugin (pointers of this type stored in Menu)
26 VP - ViewerPlugin
27 RMI - RibbonMenuItem
28 ISSC - ISceneStateCheck virtual
29 SSC Block - Block of SceneStateCheck (this block can have different topology)
30 implements `isAvailable` function from ISSC, that is called from Menu's SBP*
31 (leads to: warning C4250: 'EP': inherits 'SSC' via dominance, OK on clang and gcc)
32 IPU - IPluginUpdate virtual
33 PCC - Block of PluginCloseCheck (this block can have different topology)
34 implements `shouldClose_` `onPluginEnable_` and `onPluginDisable_`
35 functions from IPCC, that is called from Menu's SBP*
36 (leads to: warning C4250: 'EP': inherits 'PCC' via dominance, OK on clang and gcc)
37
38 . ICon
39 /|\‍(virtual) ___________. ISSC
40 / | \ / |(virt)
41 . . . ConHold/ |
42 | | | / |
43 | | | VP / |
44Con . . . . .RMI |
45 \ | / | / |
46 \|/ |/ IPU |
47 ML . SBP .--. (virt) __/
48 \ / / __/
49 \ / / __/
50 SLP . . PU __. SSC Block
51 \ | __/
52 \|__/
53 . EP
54*/
55
56
58{
59 Basic,
60 Mesh,
64 Voxels,
66 Test,
67 Other,
68 Count
69};
70
71class Object;
72
73class MRVIEWER_CLASS StateBasePlugin :
74 public ViewerPlugin,
75 public RibbonMenuItem,
76 public virtual IPluginUpdate,
77 public virtual ISceneSelectionChange
78{
79public:
80 MRVIEWER_API StateBasePlugin( std::string name, StatePluginTabs tab = StatePluginTabs::Other );
81 virtual ~StateBasePlugin() = default;
82
83 MRVIEWER_API virtual void drawDialog( float menuScaling, ImGuiContext* ctx );
84
85 virtual bool action() override { return enable( !isEnabled() ); }
86
87 virtual bool isActive() const override { return isEnabled(); };
88
89 virtual bool blocking() const override { return true; }
90
91 MRVIEWER_API virtual void shutdown() override;
92
93 MRVIEWER_API bool isEnabled() const;
94 MRVIEWER_API virtual bool enable( bool on );
95
96 MRVIEWER_API virtual bool dialogIsOpen() const;
97
98 MRVIEWER_API static const char* UINameSuffix();
99
100 virtual const std::string& uiName() const override { return plugin_name; }
101
102 // deferred set plugin name that will be used for dialog in `ImGuiBeginWindow_`
103 MRVIEWER_API void setUINameDeferred( std::string name );
104
105 MRVIEWER_API StatePluginTabs getTab() const;
106
107 MRVIEWER_API static const char* getTabName( StatePluginTabs tab );
108
109 MRVIEWER_API virtual std::string getTooltip() const;
110
111 // returns special string for sorting plugins in menu (plugin name by default)
112 virtual std::string sortString() const { return name(); }
113
114 // check if search mask satisfies for this plugin
115 MRVIEWER_API bool checkStringMask( const std::string& mask ) const;
116
117 std::string plugin_name;
118
119protected:
120 // begin plugin with given parameters
121 // sets params.collapsed from `dialogIsCollapsed_`
123
124 MRVIEWER_API virtual bool onEnable_();
125 MRVIEWER_API virtual bool onDisable_();
126
127 bool isEnabled_{false};
128 bool dialogIsOpen_{false};
129 bool dialogIsCollapsed_{ false };
130
131 StatePluginTabs tab_{StatePluginTabs::Other};
132};
133
134template<typename ...Connectables>
135class StateListenerPlugin : public StateBasePlugin, public MultiListener<Connectables...>
136{
137public:
139 virtual ~StateListenerPlugin() = default;
140
141 using PluginParent = StateListenerPlugin<Connectables...>;
142 using MultiListenerBase = MultiListener<Connectables...>;
143
144 virtual bool enable( bool on ) override final
145 {
146 if ( StateBasePlugin::enable( on ) )
147 {
148 if ( on )
149 // 10th group to have some extra space before it (at_front, each new active plugin to be first in listeners list)
150 MultiListenerBase::connect( viewer, 10, boost::signals2::at_front );
151 else
153 return true;
154 }
155 return false;
156 }
157};
158
159}
Definition MRStatePluginUpdate.h:12
Definition MRSceneSelectionChange.h:12
Definition MRRibbonMenuItem.h:20
Definition MRStatePlugin.h:78
virtual MRVIEWER_API bool enable(bool on)
static MRVIEWER_API const char * getTabName(StatePluginTabs tab)
virtual bool isActive() const override
Definition MRStatePlugin.h:87
virtual MRVIEWER_API std::string getTooltip() const
virtual MRVIEWER_API bool onDisable_()
MRVIEWER_API StateBasePlugin(std::string name, StatePluginTabs tab=StatePluginTabs::Other)
virtual bool action() override
Definition MRStatePlugin.h:85
std::string plugin_name
Definition MRStatePlugin.h:117
MRVIEWER_API StatePluginTabs getTab() const
virtual const std::string & uiName() const override
Definition MRStatePlugin.h:100
static MRVIEWER_API const char * UINameSuffix()
virtual MRVIEWER_API bool onEnable_()
MRVIEWER_API bool checkStringMask(const std::string &mask) const
virtual ~StateBasePlugin()=default
virtual MRVIEWER_API bool ImGuiBeginWindow_(ImGui::CustomStatePluginWindowParameters params)
virtual MRVIEWER_API void drawDialog(float menuScaling, ImGuiContext *ctx)
virtual MRVIEWER_API bool dialogIsOpen() const
virtual std::string sortString() const
Definition MRStatePlugin.h:112
virtual bool blocking() const override
Definition MRStatePlugin.h:89
MRVIEWER_API bool isEnabled() const
MRVIEWER_API void setUINameDeferred(std::string name)
virtual MRVIEWER_API void shutdown() override
Definition MRViewerFwd.h:60
virtual bool enable(bool on) override final
Definition MRStatePlugin.h:144
virtual ~StateListenerPlugin()=default
Definition MRViewerPlugin.h:27
Viewer * viewer
Definition MRViewerPlugin.h:46
Definition MRCameraOrientationPlugin.h:8
struct MRMESH_CLASS PointCloud
Definition MRMesh/MRMeshFwd.h:477
struct MRMESH_CLASS Mesh
Definition MRMesh/MRMeshFwd.h:475
StatePluginTabs
Definition MRStatePlugin.h:58
Structure that contains parameters for State plugin window with custom style.
Definition ImGuiHelpers.h:179
virtual void disconnect()
Definition MRViewerEventsListener.h:42
virtual void connect(Viewer *viewer, int group=0, boost::signals2::connect_position pos=boost::signals2::connect_position::at_back)
Definition MRViewerEventsListener.h:35