MeshLib Documentation
Loading...
Searching...
No Matches
MRRibbonMenu.h
Go to the documentation of this file.
1#pragma once
2#include "ImGuiMenu.h"
3#include "MRRibbonMenuItem.h"
7#include "MRAsyncTimer.h"
8#include "MRRibbonSchema.h"
9#include "MRToolbar.h"
10#include "MRMesh/MRSignal.h"
12#include <type_traits>
13#include <array>
14
15namespace MR
16{
17
18class Object;
19
20
22{
23 None, // no menu present
24 SceneTree, // only scene tree is present
25 All // both scene tree and top panel are present
26};
27
28// Class to control and render ribbon-style menu
29// stores menu items,
30// menu structure is provided by `menuItemsStructure.json` file (parsed on init)
31class MRVIEWER_CLASS RibbonMenu : public ImGuiMenu
32{
33 struct CustomContextMenuCheckbox
34 {
35 using Setter = std::function<void( std::shared_ptr<Object> object, ViewportId id, bool checked )>;
36 using Getter = std::function<bool( std::shared_ptr<Object> object, ViewportId id )>;
37 Setter setter;
38 Getter getter;
39 // display a checkBox when only these types of objects are selected
40 // by default, it is always hidden
41 SelectedTypesMask selectedMask = SelectedTypesMask( -1 );
42 };
43
44public:
45 // returns RibonMenu from ViewerInstance()
46 MRVIEWER_API static std::shared_ptr<RibbonMenu> instance();
47
48 // adds a custom checkBox to the context menu
49 // it is applied to the selected objects
50 MRVIEWER_API void setCustomContextCheckbox(
51 const std::string& name,
52 CustomContextMenuCheckbox customContextMenuCheckbox );
53
54 MRVIEWER_API virtual void init( MR::Viewer* _viewer ) override;
55
56 MRVIEWER_API virtual void shutdown() override;
57
59 MRVIEWER_API void openToolbarCustomize();
60
61 MRVIEWER_API virtual void load_font( int font_size = 13 ) override;
62
63 MRVIEWER_API virtual std::filesystem::path getMenuFontPath() const override;
64
65 // set top panel pinned and unpinned
66 MRVIEWER_API virtual void pinTopPanel( bool on );
67 MRVIEWER_API bool isTopPannelPinned() const;
68 // this functions allow you to get top panel height (before scaling)
69 int getTopPanelOpenedHeight() const { return topPanelOpenedHeight_; }
70 int getTopPanelHiddenHeight() const { return topPanelHiddenHeight_; }
71 int getTopPanelCurrentHeight() const { return currentTopPanelHeight_; }
72 // set maximum wait time (in seconds) before top panel is closed after mouse leaves it (only when not pinned)
73 // minimum value is 0 seconds, panel will close immediately after mouse leaves it
74 void setTopPanelMaxOpenedTimer( float sec ) { openedMaxSecs_ = std::max( 0.0f, sec ); }
75
77 MRVIEWER_API virtual void setQuickAccessListVersion( int version );
79 MRVIEWER_API virtual void readQuickAccessList( const Json::Value& root );
80
82 MRVIEWER_API void resetQuickAccessList();
83
85 Vector2i getSceneSize() { return Vector2i( int( sceneSize_.x ), int( sceneSize_.y ) ); };
86
88 MRVIEWER_API void setSceneSize( const Vector2i& size );
89
91 bool hasActiveBlockingItem() const { return bool( activeBlockingItem_.item ); }
93 bool hasAnyActiveItem() const { return bool( activeBlockingItem_.item ) || !activeNonBlockingItems_.empty(); }
94
96 MRVIEWER_API void updateItemStatus( const std::string& itemName );
97
99 int getActiveTabIndex() const { return activeTabIndex_; }
100
101
103 RibbonFontManager& getFontManager() { return fontManager_; };
104
106 RibbonButtonDrawer& getRibbonButtonDrawer() { return buttonDrawer_; }
107
109 Toolbar& getToolbar() { return toolbar_; }
110
112 RibbonNotifier& getRibbonNotifier() { return notifier_; };
113
114 void setActiveListPos( const ImVec2& pos ) { activeListPos_ = pos; }
115
117 void showActiveList() { activeListPressed_ = true; };
118
121 MRVIEWER_API virtual void pushNotification( const RibbonNotification& notification );
122
124 MRVIEWER_API static void cloneTree( const std::vector<std::shared_ptr<Object>>& selectedObjects );
126 MRVIEWER_API static void cloneSelectedPart( const std::shared_ptr<Object>& object );
127
128 using TabChangedSignal = boost::signals2::signal<void( int prevTabId, int newTabId )>;
131
133 bool getAutoCloseBlockingPlugins() const { return autoCloseBlockingPlugins_; }
135 void setAutoCloseBlockingPlugins( bool value ) { autoCloseBlockingPlugins_ = value; }
136
138 RibbonLayoutMode getLayoutMode() const { return layoutMode_; }
140 MRVIEWER_API virtual void setLayoutMode( RibbonLayoutMode mode );
141
142 // ======== selected objects options drawing
143 bool drawGroupUngroupButton( const std::vector<std::shared_ptr<Object>>& selected );
144 bool drawSelectSubtreeButton( const std::vector<std::shared_ptr<Object>>& selected );
145 bool drawCloneButton( const std::vector<std::shared_ptr<Object>>& selected );
146 bool drawCustomCheckBox( const std::vector<std::shared_ptr<Object>>& selected, SelectedTypesMask selectedMask );
147 bool drawCloneSelectionButton( const std::vector<std::shared_ptr<Object>>& selected );
148 bool drawMergeSubtreeButton( const std::vector<std::shared_ptr<Object>>& selected );
149protected:
150 // draw single item
151 MRVIEWER_API virtual void drawBigButtonItem_( const MenuItemInfo& item );
152 // draw set of small text buttons
153 MRVIEWER_API virtual void drawSmallButtonsSet_( const std::vector<std::string>& group, int setFrontIndex, int setLength,
154 bool withText );
155
156 // Configuration of ribbon group
158 {
159 int numBig{ 0 };
160 int numSmallText{ 0 };
161 int numSmall{ 0 };
162 };
163 using DrawTabConfig = std::vector<DrawGroupConfig>;
164 // draw group of items
165 MRVIEWER_API virtual DrawTabConfig setupItemsGroupConfig_( const std::vector<std::string>& groupsInTab, const std::string& tabName, bool centerItems );
166 MRVIEWER_API virtual void setupItemsGroup_( const std::vector<std::string>& groupsInTab, const std::string& tabName );
167 MRVIEWER_API virtual void drawItemsGroup_( const std::string& tabName, const std::string& groupName,
168 DrawGroupConfig config );
169 // ribbon menu item pressed
170 // requiremetnsHint - text that is showed if tool is unavailable (if empty then tool is available)
171 // returns true if item was actually activated or deactivated with press action
172 MRVIEWER_API virtual bool itemPressed_( const std::shared_ptr<RibbonMenuItem>& item, const std::string& requiremetnsHint = {} );
173
174 MRVIEWER_API virtual void drawActiveBlockingDialog_();
175 MRVIEWER_API virtual void drawActiveNonBlockingDialogs_();
176
177 MRVIEWER_API virtual void postResize_( int width, int height ) override;
178 MRVIEWER_API virtual void postRescale_( float x, float y ) override;
179
181 {
182 std::shared_ptr<RibbonMenuItem> item;
183 // this flag is needed to correctly fix position of UI dialog (temporary, while plugin dialogs are floating in viewport)
184 bool dialogPositionFixed{ false };
185 };
187 std::vector<DialogItemPtr> activeNonBlockingItems_;
188 MRVIEWER_API virtual void drawItemDialog_( DialogItemPtr& itemPtr );
189
190 // Draw ribbon top panel
191 MRVIEWER_API virtual void drawTopPanel_( bool drawTabs = true, bool centerItems = false );
192 // Draw scene list window with content
193 MRVIEWER_API virtual void drawRibbonSceneList_();
194 // Draw vertical line at the right border of scene to enable resize of scene list
195 // returns size of scene window
196 MRVIEWER_API virtual Vector2f drawRibbonSceneResizeLine_();
197 // Draw viewport id and projection type for all viewporrts
198 MRVIEWER_API virtual void drawRibbonViewportsLabels_();
199
200 MRVIEWER_API virtual void drawRibbonSceneInformation_( const std::vector<std::shared_ptr<Object>>& selected );
201
202 MRVIEWER_API virtual bool drawCollapsingHeaderTransform_() override;
203 MRVIEWER_API virtual bool drawTransformContextMenu_( const std::shared_ptr<Object>& selected ) override;
204
205 MRVIEWER_API virtual void addRibbonItemShortcut_( const std::string& itemName, const ShortcutKey& key, ShortcutCategory category );
206
207 MRVIEWER_API virtual void setupShortcuts_() override;
208
209 MRVIEWER_API virtual void drawShortcutsWindow_() override;
210 // reads files with panel description
211 MRVIEWER_API virtual void readMenuItemsStructure_();
212
213 std::vector<std::shared_ptr<const Object>> prevFrameSelectedObjectsCache_;
214
215 MRVIEWER_API virtual bool drawCollapsingHeader_( const char* label, ImGuiTreeNodeFlags flags = 0 ) override;
216
217 MRVIEWER_API virtual void highlightBlocking_();
218
219 // draw scene list buttons
220 MRVIEWER_API virtual void drawSceneListButtons_();
221
222 // updates viewport sizes with respect to ribbon top and left panels
223 MRVIEWER_API virtual void fixViewportsSize_( int w, int h );
224
225 // need to be called if you override windows pipeline and use ActiveListPlugin
226 MRVIEWER_API void drawActiveList_();
227
228 RibbonLayoutMode layoutMode_{ RibbonLayoutMode::All };
229
231private:
232 void changeTab_( int newTab );
233
234 std::string getRequirements_( const std::shared_ptr<RibbonMenuItem>& item ) const;
235
236 void drawSearchButton_();
237 void drawCollapseButton_();
238 void drawHelpButton_();
239
240 void sortObjectsRecursive_( std::shared_ptr<Object> object );
241
242 // part of top panel
243 void drawHeaderQuickAccess_();
244 void drawHeaderPannel_();
245 void drawActiveListButton_( float btnSize );
246
247 ImVec2 activeListPos_{ 0,0 };
248 bool activeListPressed_{ false };
249
250 void beginTopPanel_();
251 void endTopPanel_();
252 void drawTopPanelOpened_( bool drawTabs, bool centerItems );
253
254 std::string transformClipboardText_;
255
256 int currentTopPanelHeight_ = 113;
257 int topPanelOpenedHeight_ = 113;
258 int topPanelHiddenHeight_ = 33;
259
260 ImVec2 sceneSize_{ 310, 0 };
261 float informationHeight_{ 0.f };
262 float transformHeight_{ 0.f };
263
264 // how long blocking window will blink in seconds
265 float blockingHighlightTimer_{ 0.0f };
266
267 // current scroll position of tabs panel
268 float tabPanelScroll_{ 0.0f };
269
270 bool autoCloseBlockingPlugins_{ true };
271
272 enum class CollapseState
273 {
274 Closed,
275 Opened,
276 Pinned
277 } collapseState_{ CollapseState::Pinned };
278 // seconds to stay opened if not pinned
279 float openedMaxSecs_{ 2.0f };
280 float openedTimer_{ openedMaxSecs_ };
281
282 int activeTabIndex_{ 0 };
283 RibbonFontManager fontManager_;
284 RibbonButtonDrawer buttonDrawer_;
285
286 std::unordered_map<std::string, CustomContextMenuCheckbox> customCheckBox_;
287
288 Toolbar toolbar_;
289 RibbonNotifier notifier_;
290#ifndef __EMSCRIPTEN__
291 AsyncRequest asyncRequest_;
292#endif // !__EMSCRIPTEN__
293};
294
295// Checks if RibbonMenu is available, if it is - forwards notification to RibbonNotifier. Otherwise - calls showModal() function
296MRVIEWER_API void pushNotification( const RibbonNotification& notification );
297
298}
Definition ImGuiMenu.h:55
class for drawing ribbon menu buttons
Definition MRRibbonButtonDrawer.h:48
Definition MRRibbonFontManager.h:11
Definition MRRibbonMenuSearch.h:17
Definition MRRibbonMenu.h:32
bool hasAnyActiveItem() const
returns true if any plugin is now active
Definition MRRibbonMenu.h:93
virtual MRVIEWER_API void drawSceneListButtons_()
int getTopPanelOpenedHeight() const
Definition MRRibbonMenu.h:69
void setTopPanelMaxOpenedTimer(float sec)
Definition MRRibbonMenu.h:74
void showActiveList()
set active plugins list showed
Definition MRRibbonMenu.h:117
void setActiveListPos(const ImVec2 &pos)
Definition MRRibbonMenu.h:114
bool drawCloneSelectionButton(const std::vector< std::shared_ptr< Object > > &selected)
bool drawGroupUngroupButton(const std::vector< std::shared_ptr< Object > > &selected)
virtual MRVIEWER_API void setupShortcuts_() override
RibbonLayoutMode getLayoutMode() const
returns current layout mode of menu (find more in RibbonLayoutMode comments)
Definition MRRibbonMenu.h:138
virtual MRVIEWER_API void addRibbonItemShortcut_(const std::string &itemName, const ShortcutKey &key, ShortcutCategory category)
virtual MRVIEWER_API void drawActiveNonBlockingDialogs_()
DialogItemPtr activeBlockingItem_
Definition MRRibbonMenu.h:186
virtual MRVIEWER_API void shutdown() override
virtual MRVIEWER_API void drawShortcutsWindow_() override
virtual MRVIEWER_API void drawSmallButtonsSet_(const std::vector< std::string > &group, int setFrontIndex, int setLength, bool withText)
virtual MRVIEWER_API DrawTabConfig setupItemsGroupConfig_(const std::vector< std::string > &groupsInTab, const std::string &tabName, bool centerItems)
bool hasActiveBlockingItem() const
returns true if any blocking plugin is now active
Definition MRRibbonMenu.h:91
MRVIEWER_API bool isTopPannelPinned() const
static MRVIEWER_API std::shared_ptr< RibbonMenu > instance()
virtual MRVIEWER_API bool drawCollapsingHeader_(const char *label, ImGuiTreeNodeFlags flags=0) override
virtual MRVIEWER_API void highlightBlocking_()
bool getAutoCloseBlockingPlugins() const
returns flag defining if closing plugin on opening another one is enabled
Definition MRRibbonMenu.h:133
int getTopPanelHiddenHeight() const
Definition MRRibbonMenu.h:70
virtual MRVIEWER_API void drawActiveBlockingDialog_()
virtual MRVIEWER_API void readMenuItemsStructure_()
Vector2i getSceneSize()
get Scene List window size
Definition MRRibbonMenu.h:85
virtual MRVIEWER_API bool drawCollapsingHeaderTransform_() override
virtual MRVIEWER_API void drawBigButtonItem_(const MenuItemInfo &item)
MRVIEWER_API void drawActiveList_()
virtual MRVIEWER_API void drawRibbonSceneInformation_(const std::vector< std::shared_ptr< Object > > &selected)
virtual MRVIEWER_API void init(MR::Viewer *_viewer) override
static MRVIEWER_API void cloneTree(const std::vector< std::shared_ptr< Object > > &selectedObjects)
clones given objects with sub-objects (except for ancillary and unrecognized children) and undo
virtual MRVIEWER_API void setLayoutMode(RibbonLayoutMode mode)
sets new layout mode for menu, will be applied in next frame (find more in RibbonLayoutMode comments)
virtual MRVIEWER_API void drawItemDialog_(DialogItemPtr &itemPtr)
std::vector< std::shared_ptr< const Object > > prevFrameSelectedObjectsCache_
Definition MRRibbonMenu.h:213
virtual MRVIEWER_API void postResize_(int width, int height) override
virtual MRVIEWER_API void setQuickAccessListVersion(int version)
set quick access menu item list version
virtual MRVIEWER_API bool itemPressed_(const std::shared_ptr< RibbonMenuItem > &item, const std::string &requiremetnsHint={})
virtual MRVIEWER_API Vector2f drawRibbonSceneResizeLine_()
virtual MRVIEWER_API void load_font(int font_size=13) override
MRVIEWER_API void resetQuickAccessList()
reset quick access menu items list to default
virtual MRVIEWER_API void setupItemsGroup_(const std::vector< std::string > &groupsInTab, const std::string &tabName)
virtual MRVIEWER_API void drawItemsGroup_(const std::string &tabName, const std::string &groupName, DrawGroupConfig config)
void setAutoCloseBlockingPlugins(bool value)
sets flag defining if closing plugin on opening another one is enabled or not
Definition MRRibbonMenu.h:135
RibbonFontManager & getFontManager()
get access to Ribbon font manager
Definition MRRibbonMenu.h:103
RibbonNotifier & getRibbonNotifier()
get access to Ribbon notifier
Definition MRRibbonMenu.h:112
static MRVIEWER_API void cloneSelectedPart(const std::shared_ptr< Object > &object)
clones selected part of given object as separate object (faces, points)
virtual MRVIEWER_API void drawTopPanel_(bool drawTabs=true, bool centerItems=false)
virtual MRVIEWER_API void pinTopPanel(bool on)
bool drawSelectSubtreeButton(const std::vector< std::shared_ptr< Object > > &selected)
bool drawCloneButton(const std::vector< std::shared_ptr< Object > > &selected)
virtual MRVIEWER_API std::filesystem::path getMenuFontPath() const override
virtual MRVIEWER_API void readQuickAccessList(const Json::Value &root)
read quick access menu items list from json
RibbonMenuSearch searcher_
Definition MRRibbonMenu.h:230
bool drawCustomCheckBox(const std::vector< std::shared_ptr< Object > > &selected, SelectedTypesMask selectedMask)
Toolbar & getToolbar()
get access to Ribbon Toolbar
Definition MRRibbonMenu.h:109
std::vector< DialogItemPtr > activeNonBlockingItems_
Definition MRRibbonMenu.h:187
boost::signals2::signal< void(int prevTabId, int newTabId)> TabChangedSignal
Definition MRRibbonMenu.h:128
std::vector< DrawGroupConfig > DrawTabConfig
Definition MRRibbonMenu.h:163
virtual MRVIEWER_API void postRescale_(float x, float y) override
bool drawMergeSubtreeButton(const std::vector< std::shared_ptr< Object > > &selected)
RibbonButtonDrawer & getRibbonButtonDrawer()
get access to Ribbon button drawer
Definition MRRibbonMenu.h:106
int getTopPanelCurrentHeight() const
Definition MRRibbonMenu.h:71
MRVIEWER_API void setCustomContextCheckbox(const std::string &name, CustomContextMenuCheckbox customContextMenuCheckbox)
virtual MRVIEWER_API void drawRibbonSceneList_()
virtual MRVIEWER_API void fixViewportsSize_(int w, int h)
MRVIEWER_API void openToolbarCustomize()
open Toolbar Customize modal popup
virtual MRVIEWER_API bool drawTransformContextMenu_(const std::shared_ptr< Object > &selected) override
virtual MRVIEWER_API void pushNotification(const RibbonNotification &notification)
int getActiveTabIndex() const
returns index of active tab in RibbonSchemaHolder::schema().tabsOrder
Definition MRRibbonMenu.h:99
virtual MRVIEWER_API void drawRibbonViewportsLabels_()
MRVIEWER_API void updateItemStatus(const std::string &itemName)
updates status of item if it was changed outside of menu
TabChangedSignal tabChangedSignal
this signal is called when active tab changes
Definition MRRibbonMenu.h:130
MRVIEWER_API void setSceneSize(const Vector2i &size)
set Scene List window size
Definition MRRibbonNotification.h:56
class to draw toolbar and toolbar customize windows
Definition MRToolbar.h:17
Definition MRViewer.h:76
Definition MRViewportId.h:16
@ None
special value not to limit path in one slice
Definition MRVoxelPath.h:33
Definition MRCameraOrientationPlugin.h:8
SelectedTypesMask
Definition ImGuiMenu.h:34
RibbonLayoutMode
Definition MRRibbonMenu.h:22
MRVIEWER_API void pushNotification(const RibbonNotification &notification)
ShortcutCategory
Definition MRShortcutManager.h:28
Definition MRRibbonSchema.h:24
Definition MRRibbonMenu.h:181
std::shared_ptr< RibbonMenuItem > item
Definition MRRibbonMenu.h:182
Definition MRRibbonMenu.h:158
Definition MRRibbonNotification.h:30
Definition MRShortcutManager.h:13