1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
|
//##########################################################################
//# #
//# CLOUDCOMPARE #
//# #
//# This program is free software; you can redistribute it and/or modify #
//# it under the terms of the GNU General Public License as published by #
//# the Free Software Foundation; version 2 or later of the License. #
//# #
//# This program is distributed in the hope that it will be useful, #
//# but WITHOUT ANY WARRANTY; without even the implied warranty of #
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
//# GNU General Public License for more details. #
//# #
//# COPYRIGHT: CloudCompare project #
//# #
//##########################################################################
#include <QAction>
#include <QMenu>
#include <QToolBar>
#include <QWidget>
#include "ccConsole.h"
#include "ccGLWindow.h"
#include "ccGLFilterPluginInterface.h"
#include "ccIOFilterPluginInterface.h"
#include "ccMainAppInterface.h"
#include "ccPluginInfoDlg.h"
#include "ccPluginUIManager.h"
#include "ccStdPluginInterface.h"
ccPluginUIManager::ccPluginUIManager( ccMainAppInterface *appInterface, QWidget *parent )
: QObject( parent )
, m_parentWidget( parent )
, m_appInterface( appInterface )
, m_pluginMenu( nullptr )
, m_glFilterMenu( nullptr )
, m_actionRemoveFilter( nullptr )
, m_glFilterActions( this )
, m_mainPluginToolbar( nullptr )
, m_showPluginToolbar( nullptr )
, m_glFiltersToolbar( nullptr )
, m_showGLFilterToolbar( nullptr )
{
setupActions();
setupMenus();
setupToolbars();
}
ccPluginUIManager::~ccPluginUIManager()
{
}
void ccPluginUIManager::init( const ccPluginInterfaceList &plugins )
{
m_pluginMenu->setEnabled( false );
m_glFilterMenu->setEnabled( false );
m_mainPluginToolbar->setVisible( false );
QVector<ccStdPluginInterface *> coreStdPlugins;
QVector<ccStdPluginInterface *> thirdPartyStdPlugins;
QVector<QAction *> coreGLActions;
QVector<QAction *> thirdPartyGLActions;
for ( ccPluginInterface *plugin : plugins )
{
if ( plugin == nullptr )
{
Q_ASSERT( false );
continue;
}
const QString pluginName = plugin->getName();
Q_ASSERT( !pluginName.isEmpty() );
if ( pluginName.isEmpty() )
{
// should be unreachable - we have already checked for this in ccPlugins::Find()
continue;
}
switch ( plugin->getType() )
{
case CC_STD_PLUGIN: //standard plugin
{
ccStdPluginInterface *stdPlugin = static_cast<ccStdPluginInterface*>( plugin );
stdPlugin->setMainAppInterface( m_appInterface );
if ( stdPlugin->isCore() )
{
coreStdPlugins.append( stdPlugin );
}
else
{
thirdPartyStdPlugins.append( stdPlugin );
}
m_plugins.push_back( stdPlugin );
break;
}
case CC_GL_FILTER_PLUGIN: //GL filter
{
ccGLFilterPluginInterface *glPlugin = static_cast<ccGLFilterPluginInterface*>( plugin );
QAction* action = new QAction( pluginName, this );
action->setToolTip( glPlugin->getDescription() );
action->setIcon( glPlugin->getIcon() );
action->setCheckable( true );
// store the plugin's interface pointer in the QAction data so we can access it in enableGLFilter()
QVariant v;
v.setValue( glPlugin );
action->setData( v );
connect( action, &QAction::triggered, this, &ccPluginUIManager::enableGLFilter );
m_glFilterActions.addAction( action );
if ( glPlugin->isCore() )
{
coreGLActions.append( action );
}
else
{
thirdPartyGLActions.append( action );
}
m_plugins.push_back( glPlugin );
break;
}
case CC_IO_FILTER_PLUGIN:
{
ccIOFilterPluginInterface *ioPlugin = static_cast<ccIOFilterPluginInterface*>( plugin );
// there are no menus or toolbars for I/O plugins
m_plugins.push_back( ioPlugin );
break;
}
}
}
// add core standard plugins to menu & tool bar
for ( ccStdPluginInterface *plugin : coreStdPlugins )
{
QList<QAction *> actions = plugin->getActions();
addActionsToMenu( plugin, actions );
addActionsToToolBar( plugin, actions );
plugin->onNewSelection( m_appInterface->getSelectedEntities() );
}
// add 3rd standard party plugins to menu & tool bar (if any )
if ( !thirdPartyStdPlugins.isEmpty() )
{
m_pluginMenu->addSection( "3rd Party" );
for ( ccStdPluginInterface *plugin : thirdPartyStdPlugins )
{
QList<QAction *> actions = plugin->getActions();
addActionsToMenu( plugin, actions );
addActionsToToolBar( plugin, actions );
plugin->onNewSelection( m_appInterface->getSelectedEntities() );
}
}
// add core GL plugins to menu & tool bar
for ( QAction *action : coreGLActions )
{
m_glFilterMenu->addAction( action );
m_glFiltersToolbar->addAction( action );
}
// add 3rd GL party plugins to menu & tool bar (if any )
if ( !thirdPartyGLActions.isEmpty() )
{
m_glFilterMenu->addSection( "3rd Party" );
for ( QAction *action : thirdPartyGLActions )
{
m_glFilterMenu->addAction( action );
m_glFiltersToolbar->addAction( action );
}
}
m_pluginMenu->setEnabled( !m_pluginMenu->isEmpty() );
if ( m_mainPluginToolbar->isEnabled() )
{
m_showPluginToolbar->setEnabled( true );
}
m_glFilterMenu->setEnabled( !m_glFilterMenu->isEmpty() );
m_glFiltersToolbar->setEnabled( !m_glFilterMenu->isEmpty() ); // [sic] we have toolbar actions if we have them in the menu
m_showPluginToolbar->setChecked( m_mainPluginToolbar->isEnabled() );
if ( m_glFiltersToolbar->isEnabled() )
{
m_showGLFilterToolbar->setEnabled( true );
}
m_showGLFilterToolbar->setChecked( m_glFiltersToolbar->isEnabled() );
}
QMenu *ccPluginUIManager::pluginMenu() const
{
return m_pluginMenu;
}
QMenu *ccPluginUIManager::shaderAndFilterMenu() const
{
return m_glFilterMenu;
}
QToolBar *ccPluginUIManager::mainPluginToolbar()
{
return m_mainPluginToolbar;
}
QList<QToolBar *> &ccPluginUIManager::additionalPluginToolbars()
{
return m_additionalPluginToolbars;
}
QAction *ccPluginUIManager::actionShowMainPluginToolbar()
{
return m_showPluginToolbar;
}
QToolBar *ccPluginUIManager::glFiltersToolbar()
{
return m_glFiltersToolbar;
}
QAction *ccPluginUIManager::actionShowGLFilterToolbar()
{
return m_showGLFilterToolbar;
}
void ccPluginUIManager::updateMenus()
{
ccGLWindow *active3DView = m_appInterface->getActiveGLWindow();
const bool hasActiveView = (active3DView != nullptr);
const QList<QAction*> actionList = m_glFilterActions.actions();
for ( QAction* action : actionList )
{
action->setEnabled( hasActiveView );
}
}
void ccPluginUIManager::handleSelectionChanged()
{
const ccHObject::Container &selectedEntities = m_appInterface->getSelectedEntities();
for ( ccPluginInterface *plugin : m_plugins )
{
if ( plugin->getType() == CC_STD_PLUGIN )
{
ccStdPluginInterface *stdPlugin = static_cast<ccStdPluginInterface *>(plugin);
stdPlugin->onNewSelection( selectedEntities );
}
}
}
void ccPluginUIManager::showAboutDialog() const
{
ccPluginInfoDlg about;
about.setPluginPaths( ccPluginManager::pluginPaths() );
about.setPluginList( m_plugins );
about.exec();
}
void ccPluginUIManager::setupActions()
{
m_actionRemoveFilter = new QAction( QIcon( ":/CC/images/noFilter.png" ), tr( "Remove Filter" ), this );
m_actionRemoveFilter->setEnabled( false );
connect( m_actionRemoveFilter, &QAction::triggered, this, &ccPluginUIManager::disableGLFilter );
m_showPluginToolbar = new QAction( tr( "Plugins" ), this );
m_showPluginToolbar->setCheckable( true );
m_showPluginToolbar->setEnabled( false );
m_showGLFilterToolbar = new QAction( tr( "GL Filters" ), this );
m_showGLFilterToolbar->setCheckable( true );
m_showGLFilterToolbar->setEnabled( false );
}
void ccPluginUIManager::setupMenus()
{
m_pluginMenu = new QMenu( tr( "Plugins" ), m_parentWidget );
m_glFilterMenu = new QMenu( tr( "Shaders && Filters" ), m_parentWidget );
m_glFilterMenu->addAction( m_actionRemoveFilter );
m_glFilterActions.setExclusive( true );
}
void ccPluginUIManager::addActionsToMenu( ccStdPluginInterface *stdPlugin, const QList<QAction *> &actions )
{
// If the plugin has more than one action we create its own menu
if ( actions.size() > 1 )
{
QMenu *menu = new QMenu( stdPlugin->getName(), m_parentWidget);
menu->setIcon( stdPlugin->getIcon() );
menu->setEnabled( true );
for ( QAction* action : actions )
{
menu->addAction( action );
}
m_pluginMenu->addMenu( menu );
}
else // otherwise we just add it to the main menu
{
Q_ASSERT( actions.count() == 1 );
m_pluginMenu->addAction( actions.at( 0 ) );
}
}
void ccPluginUIManager::setupToolbars()
{
m_mainPluginToolbar = new QToolBar( tr( "Plugins" ), m_parentWidget );
m_mainPluginToolbar->setObjectName( QStringLiteral( "Main Plugin Toolbar" ) );
connect( m_showPluginToolbar, &QAction::toggled, m_mainPluginToolbar, &QToolBar::setVisible );
m_glFiltersToolbar = new QToolBar( tr( "GL Filters" ), m_parentWidget );
m_glFiltersToolbar->setObjectName( QStringLiteral( "GL Plugin Toolbar" ) );
m_glFiltersToolbar->addAction( m_actionRemoveFilter );
connect( m_showGLFilterToolbar, &QAction::toggled, m_glFiltersToolbar, &QToolBar::setVisible );
}
void ccPluginUIManager::addActionsToToolBar( ccStdPluginInterface *stdPlugin, const QList<QAction *> &actions )
{
const QString pluginName = stdPlugin->getName();
// If the plugin has more than one action we create its own tool bar
if ( actions.size() > 1 )
{
QToolBar *toolBar = new QToolBar( pluginName + QStringLiteral( " toolbar" ), m_parentWidget );
if ( toolBar != nullptr )
{
m_additionalPluginToolbars.push_back( toolBar );
toolBar->setObjectName( pluginName );
toolBar->setEnabled( true );
for ( QAction* action : actions )
{
toolBar->addAction( action );
}
}
}
else // otherwise we just add it to the main tool bar
{
Q_ASSERT( actions.count() == 1 );
m_mainPluginToolbar->addAction( actions.at( 0 ) );
}
}
void ccPluginUIManager::enableGLFilter()
{
ccGLWindow *win = m_appInterface->getActiveGLWindow();
if ( win == nullptr )
{
ccLog::Warning( "[GL filter] No active 3D view" );
return;
}
QAction *action = qobject_cast<QAction*>(sender());
Q_ASSERT( action != nullptr );
ccGLFilterPluginInterface *plugin = action->data().value<ccGLFilterPluginInterface *>();
if ( plugin == nullptr )
{
return;
}
if ( win->areGLFiltersEnabled() )
{
ccGlFilter *filter = plugin->getFilter();
if ( filter != nullptr )
{
win->setGlFilter( filter );
m_actionRemoveFilter->setEnabled( true );
ccConsole::Print( "Note: go to << Display > Shaders & Filters > No filter >> to disable GL filter" );
}
else
{
ccConsole::Error( "Can't load GL filter (an error occurred)!" );
}
}
else
{
ccConsole::Error( "GL filters not supported!" );
}
}
void ccPluginUIManager::disableGLFilter()
{
ccGLWindow *win = m_appInterface->getActiveGLWindow();
if ( win != nullptr )
{
win->setGlFilter( nullptr );
win->redraw( false );
m_actionRemoveFilter->setEnabled( false );
m_glFilterActions.checkedAction()->setChecked( false );
}
}
|