34 #include <QMessageBox>
35 #include <QScrollArea>
38 #include <QVBoxLayout>
39 #include <QtCore/QCoreApplication>
40 #include <QtCore/QList>
42 #include "../WMainWindow.h"
43 #include "../WQtCombinerActionList.h"
44 #include "../WQtGui.h"
45 #include "../WQtModuleConfig.h"
46 #include "../events/WEventTypes.h"
47 #include "../events/WModuleAssocEvent.h"
48 #include "../events/WModuleConnectEvent.h"
49 #include "../events/WModuleConnectorEvent.h"
50 #include "../events/WModuleDeleteEvent.h"
51 #include "../events/WModuleDisconnectEvent.h"
52 #include "../events/WModuleReadyEvent.h"
53 #include "../events/WModuleRemovedEvent.h"
54 #include "../events/WRoiAssocEvent.h"
55 #include "../events/WRoiRemoveEvent.h"
56 #include "../events/WRoiSortEvent.h"
57 #include "../guiElements/WQtDataModuleInput.h"
58 #include "../guiElements/WQtMenuFiltered.h"
59 #include "../guiElements/WQtModuleMetaInfo.h"
60 #include "../networkEditor/WQtNetworkEditor.h"
61 #include "WQtBranchTreeItem.h"
62 #include "WQtColormapper.h"
63 #include "WQtControlPanel.h"
64 #include "core/common/WLogger.h"
65 #include "core/common/WPredicateHelper.h"
66 #include "core/dataHandler/WDataSet.h"
67 #include "core/kernel/WDataModule.h"
68 #include "core/kernel/WKernel.h"
69 #include "core/kernel/WModule.h"
70 #include "core/kernel/WModuleContainer.h"
71 #include "core/kernel/WModuleFactory.h"
72 #include "core/kernel/WROIManager.h"
76 m_ignoreSelectionChange( false ),
77 m_activeModule(
WModule::SPtr() ),
80 setObjectName(
"Control Panel Dock" );
83 setMinimumWidth( 200 );
98 separator->setSeparator(
true );
105 "Add Module and Connect",
138 m_configModuleFilterAction->setToolTip(
"Having trouble finding your module? This opens the module configuration, which allows you to define the "
139 "modules that should be shown or hidden." );
176 QWidget* treeWidgetContainer =
new QWidget();
177 QVBoxLayout* treeWidgetContainerLayout =
new QVBoxLayout();
178 treeWidgetContainer->setLayout( treeWidgetContainerLayout );
179 QLabel* treeWidgetDeprecation =
new QLabel(
"<h1><b><font color=#f00>The module tree is deprecated.</font></b></h1>"
180 "Use the tab \"Modules\" instead. This will be removed in the next release." );
181 treeWidgetDeprecation->setMargin( 25 );
182 treeWidgetDeprecation->setWordWrap(
true );
184 treeWidgetContainerLayout->addWidget( treeWidgetDeprecation );
193 m_roiTreeWidget->setToolTip(
"Regions of intrest (ROIs) for selecting fiber clusters. Branches are combined using logic <b>or</b>, "
194 "inside the branches the ROIs are combined using logic <b>and</b>." );
202 m_roiTreeWidget->setSelectionMode( QAbstractItemView::SingleSelection );
207 this->setAllowedAreas( Qt::AllDockWidgetAreas );
208 this->setFeatures( QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
212 m_tiModules->setText( 0, QString(
"Subject-independent Modules" ) );
213 m_tiModules->setToolTip( 0,
"Subject-independent modules and modules for which no parent module could be detected." );
256 connect(
m_colormapper, SIGNAL( textureSelectionChanged( osg::ref_ptr< WGETexture3D > ) ),
264 subject->setText( 0, QString::fromStdString( name ) );
265 subject->setToolTip( 0, QString::fromStdString(
"All data and modules that are children of this tree item belong to the subject \"" +
273 if(
event->type() == WQT_ROI_ASSOC_EVENT )
284 if(
event->type() == WQT_ROI_REMOVE_EVENT )
295 if(
event->type() == WQT_ROI_SORT_EVENT )
307 if(
event->type() == WQT_ASSOC_EVENT )
314 "ControlPanel", LL_DEBUG );
319 std::string d = e1->
getModule()->getDeprecationMessage();
320 std::string m =
"The module \"" + e1->
getModule()->getName() +
"\" is marked deprecated. You should avoid using it."
323 QMessageBox::warning(
this,
"Deprecation Warning", QString::fromStdString( m ) );
328 if( std::dynamic_pointer_cast< WDataModule >( e1->
getModule() ).get() )
341 if(
event->type() == WQT_READY_EVENT )
349 "ControlPanel", LL_WARNING );
355 for( std::list< WQtTreeItem* >::const_iterator it = items.begin(); it != items.end(); ++it )
357 ( *it )->setDisabled(
false );
366 if(
event->type() == WQT_MODULE_CONNECT_EVENT )
373 "ControlPanel", LL_WARNING );
378 std::shared_ptr< WModule > mIn = e->
getInput()->getModule();
379 std::shared_ptr< WModule > mOut = e->
getOutput()->getModule();
416 if(
event->type() == WQT_MODULE_DISCONNECT_EVENT )
423 "ControlPanel", LL_WARNING );
428 std::shared_ptr< WModule > mIn = e->
getInput()->getModule();
429 std::shared_ptr< WModule > mOut = e->
getOutput()->getModule();
436 for( std::list< WQtTreeItem* >::const_iterator iter = items.begin(); iter != items.end(); ++iter )
440 for( std::list< WQtTreeItem* >::const_iterator citer = childs.begin(); citer != childs.end(); ++citer )
442 if( ( *citer )->getHandledInput() == e->
getInput()->getName() )
444 ( *iter )->removeChild( *citer );
448 ( *citer )->setHidden(
true );
449 ( *citer )->setHandledInput(
"" );
450 ( *citer )->setHandledOutput(
"" );
457 bool oneVisible =
false;
458 for( std::list< WQtTreeItem* >::const_iterator iter = items.begin(); iter != items.end(); ++iter )
460 oneVisible = oneVisible || !( *iter )->isHidden();
464 ( *items.begin() )->setHidden(
false );
469 if(
event->type() == WQT_MODULE_DELETE_EVENT )
476 "ControlPanel", LL_WARNING );
483 "ControlPanel", LL_DEBUG );
490 if( lastTreeItem && ( module.use_count() != 1 ) )
492 wlog::error(
"ControlPanel" ) <<
"Removed module has strange usage count: " << module.use_count() <<
". Should be 1 here. " <<
493 "Module reference is held by someone else.";
499 if(
event->type() == WQT_MODULE_REMOVE_EVENT )
506 "ControlPanel", LL_WARNING );
512 for( std::list< WQtTreeItem* >::const_iterator iter = items.begin(); iter != items.end(); ++iter )
514 ( *iter )->gotRemoved();
523 "ControlPanel", LL_DEBUG );
529 if(
event->type() == WQT_MODULE_CONNECTOR_EVENT )
536 "ControlPanel", LL_WARNING );
544 "ControlPanel", LL_WARNING );
553 return WQtDockWidget::event(
event );
558 std::list< WQtTreeItem* > l;
561 QTreeWidgetItemIterator it( where );
565 std::shared_ptr< WModule > itemModule = std::shared_ptr< WModule >();
572 if( !itemModule.get() )
579 if( module == itemModule )
601 subject->setExpanded(
true );
603 item->setDisabled(
true );
604 item->setExpanded(
true );
615 bool firstItem =
true;
617 for( WModule::InputConnectorList::const_iterator iter = cons.begin(); iter != cons.end(); ++iter )
621 item->setDisabled(
true );
622 item->setExpanded(
true );
627 item->setHidden(
true );
637 item->setDisabled(
true );
652 for(
int branchID = 0; branchID <
m_tiRois->childCount(); ++branchID )
669 branchItem->setExpanded(
true );
672 newItem->setDisabled(
false );
682 for(
int branchID = 0; branchID <
m_tiRois->childCount(); ++branchID )
685 for(
int roiID = 0; roiID < branchTreeItem->childCount(); ++roiID )
688 if( roiTreeItem && roiTreeItem->
getRoi() == roi )
692 if( branchTreeItem->childCount() == 0 )
694 delete branchTreeItem;
715 return std::shared_ptr< WModule >();
784 std::shared_ptr< WModule > module;
785 std::shared_ptr< WProperties > props;
794 switch( item->type() )
804 props = (
static_cast< WQtBranchTreeItem*
>( item ) )->getBranch()->getProperties();
808 props = (
static_cast< WQtRoiTreeItem*
>( item ) )->getRoi()->getProperties();
816 buildPropTab( props, std::shared_ptr< WProperties >(),
"ROI" );
822 buildPropTab( texture->getProperties(), texture->getInformationProperties(),
"Colormap" );
834 currentModule = std::dynamic_pointer_cast< WModule >( (
dynamic_cast< WQtModuleTreeItem*
>( *it ) )->getModule() );
837 if( currentModule == module )
846 std::shared_ptr< WDataModule > dataModule;
847 dataModule = std::dynamic_pointer_cast< WDataModule >( (
dynamic_cast< WQtDatasetTreeItem*
>( *it ) )->getModule() );
850 if( dataModule == module )
915 wlog::debug(
"ControlPanel" ) <<
"Activating module \"" << module->getName() <<
"\".";
919 WAssert( items.size(),
"No item found for module " + module->getName() );
921 for( std::list< WQtTreeItem* >::const_iterator it = items.begin(); it != items.end(); ++it )
923 ( *it )->setSelected(
true );
937 m_tabWidget->addTab( metaInfoWidget,
"About && Help" );
940 if( !module->isCrashed() )
942 std::string name = module->getName();
944 if( namePropCandidate )
946 WPropString nameProp = namePropCandidate->toPropString();
949 name = ( name == nameProp->get() ) ? name : name +
" - " + nameProp->get();
953 WDataModule::SPtr dataModule = std::dynamic_pointer_cast< WDataModule >( module );
960 buildPropTab( module->getProperties(), module->getInformationProperties(), name );
965 bool foundTab =
false;
966 std::map< QString, int > priorityList;
970 for(
int idx = 0; idx <
m_tabWidget->count(); ++idx )
981 priorityList[
m_tabWidget->tabText( idx ) ] = idx + 1;
987 if( priorityList[
"Settings" ] != 0 )
989 m_tabWidget->setCurrentIndex( priorityList[
"Settings" ] - 1 );
991 else if( priorityList[
"Information" ] != 0 )
993 m_tabWidget->setCurrentIndex( priorityList[
"Settings" ] - 1 );
1007 if(
m_moduleTreeWidget->selectedItems().at( 0 )->childCount() != 0 || module->isCrashed() )
1022 QWidget* tab = NULL;
1023 QWidget* infoTab = NULL;
1027 QSizePolicy sizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
1028 sizePolicy.setHorizontalStretch( 0 );
1029 sizePolicy.setVerticalStretch( 0 );
1034 tab =
new QWidget(
this );
1035 QVBoxLayout* tabLayout =
new QVBoxLayout();
1036 tabLayout->setSpacing( 0 );
1037 tabLayout->setAlignment( Qt::AlignTop );
1038 tab->setLayout( tabLayout );
1039 tabLayout->setContentsMargins( QMargins( 0, 0, 0, 0 ) );
1044 tabLayout->addWidget( inject );
1049 propWidget->
setName(
"Settings" );
1050 tab->setSizePolicy( sizePolicy );
1056 propInfoWidget->
setName(
"Information" );
1057 infoTab->setSizePolicy( sizePolicy );
1070 else if( infoIdx != -1 )
1156 if( !content || !propContents || propContents->
isEmpty() )
1166 QScrollArea* sa =
new QScrollArea();
1167 sa->setWidget( content );
1168 sa->setWidgetResizable(
true );
1189 osg::ref_ptr< WROI > roi;
1203 osg::ref_ptr< WROI >roi;
1211 roi =(
static_cast< WQtRoiTreeItem*
>( branch->child( 0 ) ) )->getRoi();
1216 if( branch->childCount() > 0 )
1218 roi =(
static_cast< WQtRoiTreeItem*
>( branch->child( 0 ) ) )->getRoi();
1226 QAction* result = WQtDockWidget::toggleViewAction();
1228 #if defined( __APPLE__ )
1229 shortcut.append( QKeySequence( Qt::CTRL + Qt::Key_F9 ) );
1231 shortcut.append( QKeySequence( Qt::Key_F9 ) );
1233 result->setShortcuts( shortcut );
1250 "ControlPanel", LL_WARNING );
1284 osg::ref_ptr< WROI >roi;
1321 for(
int branchID = 0; branchID <
m_tiRois->childCount(); ++branchID )
1326 for(
int roiID = 0; roiID < branchTreeItem->childCount(); ++roiID )
1340 droppedRoi = roiTreeItem->
getRoi();
1341 droppedBranch = branchTreeItem->
getBranch();
1342 droppedBranchTreeItem = branchTreeItem;
1348 roiTreeItem->parent()->setExpanded(
true );
1354 if( !( droppedBranch && droppedBranchTreeItem ) )
1356 wlog::error(
"WQtControlPanel::handleRoiDragDrop" ) <<
"Was not able to find dropped ROI item. This should not happen!";
1361 if( realParent != droppedBranch )
1364 realParent->removeRoi( droppedRoi );
1365 droppedBranch->addRoi( droppedRoi );
1371 QCoreApplication::postEvent(
this,
new WRoiSortEvent( droppedBranchTreeItem ) );
std::shared_ptr< WDataModule > SPtr
Convenience typedef for a std::shared_ptr< WDataModule >.
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
std::shared_ptr< WModuleContainer > getRootContainer() const
Returns the root module container.
std::shared_ptr< WROIManager > getRoiManager()
get for roi manager
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
This class contains the main window and the layout of the widgets within the window.
WIconManager * getIconManager()
Return icon manager.
void setCompatiblesToolbar(WQtCombinerToolbar *toolbar=NULL)
This method removes the old compatibles toolbar and sets the specified one.
void addGlobalMenu(QWidget *widget)
Add the default OW menu to the given widget using addAction.
WQtCombinerToolbar * getCompatiblesToolbar()
This method returns the a pointer to the current compatibles toolbar.
WQtNetworkEditor * getNetworkEditor()
Returns a pointer to the network editor object.
Event signalling a new module has been associated with the root container in the kernel.
std::shared_ptr< WModule > getModule()
Getter for the module that got associated.
Event signalling a module connection was established.
std::shared_ptr< WModuleConnector > getOutput() const
Gets the output connector involved in this connection event.
std::shared_ptr< WModuleConnector > getInput() const
Gets the input connector involved in this connection event.
Event signalling a module connector changed its data.
WModule::SPtr getModule() const
Gets the module (owner) of the connector.
Event signalling a module item should be deleted.
WQtTreeItem * getTreeItem()
Getter for the tree item that got outdated.
Event signalling a module connection was closed.
std::shared_ptr< WModuleConnector > getInput() const
Gets the input connector involved in this connection event.
std::shared_ptr< WModuleConnector > getOutput() const
Gets the output connector involved in this connection event.
static SPtr getModuleFactory()
Returns instance of the module factory to use to create modules.
Event signalling a new module has been associated with the root container in the kernel.
std::shared_ptr< WModule > getModule()
Getter for the module that got associated.
Event signalling a module was removed from the kernel root container.
std::shared_ptr< WModule > getModule()
Getter for the module that got removed.
Class representing a single module of OpenWalnut.
std::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
std::vector< std::shared_ptr< WModuleInputConnector > > InputConnectorList
The type for the list of input connectors.
std::shared_ptr< WPropertyBase > SPtr
Convenience typedef for a std::shared_ptr< WPropertyBase >
This class represents a ROI branch in the tree widget.
WQtRoiTreeItem * addRoiItem(osg::ref_ptr< WROI >)
Add a ROI to the tree view.
std::shared_ptr< WRMBranch > getBranch()
getter
QWidget * getWidget() const
Create a representation widget for this item.
void updateRoiManagerSorting()
Update internal Roi Manager sorting using the sorting of the children of this tree item.
This widget controls the colormapper of openwalnut.
This class represents a list of actions to apply a bunch of modules to others.
static void deepDeleteActionList(QList< QAction * > &l)
Clears a hierarchy of QActions in a list.
QAction * m_disconnectAction
Action which disconnects a connector from the module.
void deactivateModuleSelection(bool selectTopmost=true)
Used to clean the GUI from any module specify widgets.
QAction * m_connectWithModuleAction
Action which uses a compatibles list (submenu) to connect a selected item with other existing modules...
void connectSlots()
helper funtion to connect all qt widgets with their functions
WQtDockWidget * getModuleDock() const
Gets the module dock widget.
QAction * m_addModuleAction
Action which uses a list of all modules allowing them to be added without any connections.
void removeRoi(osg::ref_ptr< WROI > roi)
Removes a ROI entry from the control panel.
bool m_ignoreSelectionChange
If true, a selection change does not cause the property tab to rebuild.
std::list< WQtTreeItem * > findItemsByModule(std::shared_ptr< WModule > module, QTreeWidgetItem *where)
Searches the specified tree for all tree items matching the specified module.
WQtDockWidget * m_roiDock
the dock widget with the ROI tree
WQtDatasetTreeItem * addDataset(std::shared_ptr< WModule > module, int subjectId=0)
Adds a dataset entry to any given subject in the tree widget.
WQtModuleConfig & getModuleConfig() const
Returns the module config dialog.
WQtSubjectTreeItem * addSubject(std::string name)
Adds a subject entry to the tree widget.
osg::ref_ptr< WROI > getSelectedRoi()
Returns the currently selected ROI.
virtual bool event(QEvent *event)
Custom event dispatcher.
QAction * m_deleteModuleAction
The action to remove a module from the tree.
void deleteModule()
delete a module
void selectUpperMostEntry()
Selects the uppermost entry in the module tree.
WQtModuleConfig * m_moduleFilterConfig
The WQtCombinerActionList needs some predicate which decides whether to exclude a certain module from...
WQtModuleTreeItem * addModule(std::shared_ptr< WModule > module)
Adds a module to the control panel.
QTabWidget * m_tabWidget
pointer to the tab widget
virtual ~WQtControlPanel()
Default Destructor.
WQtCombinerActionList m_connectWithPrototypeActionList
List all actions created for applying a prototype.
int getFirstSubject()
Helper function to return the first subject id in the tree widget.
void clearAndDeleteTabs()
As QTabWidget::clear() does not delete tabs, we have to manage that ourselves.
WQtDockWidget * m_moduleDock
the dock widget with the module tree
WQtCombinerActionList m_addModuleActionList
List all actions created for applying a prototype.
QAction * getRoiDeleteAction() const
Return the action to delete a selected roi.
WQtModuleHeaderTreeItem * m_tiModules
header for modules
void completeGuiSetup()
Complete own GUI setup.
void handleRoiDragDrop(QDropEvent *event)
function to notify the ROI manager of any drag&drop action in the ROI tree
void reselectTreeItem()
This de-selects and re-selects the current item.
WQtTreeWidget * m_moduleTreeWidget
pointer to the tree widget
WQtTreeWidget * m_roiTreeWidget
pointer to the tree widget
WQtDockWidget * getColormapperDock() const
Gets the colormapper dock.
WMainWindow * m_mainWindow
Reference to the main window of the application.
QAction * toggleViewAction() const
Returns a checkable action that can be used to show or close this dock widget.
void selectDataModule(osg::ref_ptr< WGETexture3D > texture)
Will be called to select the data module for the given texture.
QAction * getMissingModuleAction() const
Returns an action which can be triggered by the user if some module are missing.
QAction * m_deleteRoiAction
The action to remove a ROI from the tree.
void selectTreeItem()
function that gets called when a tree item is selected, on a new select that tab widget is rebuilt wi...
void setActiveModule(WModule::SPtr module, bool forceUpdate=false)
Sets the module which is now active.
WQtDockWidget * getRoiDock() const
Gets the ROI dock widget.
WQtCombinerActionList m_disconnectActionList
List all actions created for applying a prototype.
void changeTreeItem(QTreeWidgetItem *item, int column)
Function gets change when a change to a tree item occurs.
QAction * m_connectWithPrototypeAction
Action which uses a compatibles list (submenu) to connect a selected item with other prototypes.
void createCompatibleButtons(std::shared_ptr< WModule > module)
fills the modul toolbar with buttons for modules that are compatible with the currently selected data...
osg::ref_ptr< WROI > getFirstRoiInSelectedBranch()
Returns the first ROI in the currently selected branch.
void addRoi(osg::ref_ptr< WROI > roi)
Adds a ROI entry to the control panel.
WQtControlPanel(WMainWindow *parent=0)
Constructor.
void deleteROITreeItem()
delete a ROI tree item
WQtRoiHeaderTreeItem * m_tiRois
header for ROIs
int addTabWidgetContent(QWidget *content, WQtPropertyGroupWidget *propContents)
Adds a page to the context widget.
WQtColormapper * m_colormapper
the colormapper control widget
WQtCombinerActionList m_connectWithModuleActionList
List all actions created for applying a prototype.
std::shared_ptr< WModule > getSelectedModule()
Returns the module currently selected in control panel.
QString m_previousTab
The title of the last selected tab in the control panel.
QAction * m_configModuleFilterAction
Action giving the user fast access to the module config dialog.
QTreeWidgetItem * findModuleItem(WModule::SPtr module) const
Search the tree item representing this module.
void selectRoiTreeItem(QTreeWidgetItem *item)
function that gets called when a tree item is selected, on a new select that tab widget is rebuilt wi...
void buildPropTab(std::shared_ptr< WProperties > props, std::shared_ptr< WProperties > infoProps, const std::string &name, QWidget *inject=NULL)
function that builds the property tab
WModule::SPtr m_activeModule
The module currently active.
Tree widget item to represent a dataset in the control panel tree widget.
static WMainWindow * getMainWindow()
Returns the current main window instance or NULL if not existent.
A class which acts as a binary predicate to check exclusion of modules by name using a whitelist and ...
Tree widget item to represent a module in the control panel tree widget.
void setGlobalAddMenu(QMenu *menu)
Set the given menu as new global add-modules menu.
Container widget to hold the WQtNetworkScene.
void selectByModule(WModule::SPtr module)
Select the item representing the given module.
WQtNetworkEditorView * getView()
Get the view handling the scene.
void clearSelection()
Clears the selection.
QList< QGraphicsItem * > selectedItems() const
Query a list of selected items.
This class represents a WModule as QGraphicsItem and contains a reference to its in- and outports.
std::shared_ptr< WModule > getModule()
Get the WModule represented by this object.
A tree widget item to represent a ROI in the control panel.
osg::ref_ptr< WROI > getRoi()
Getter.
QWidget * createWidget() const
Create a representation widget for this item.
tree widget item to represent a subject in the dataset brwoser tree widget
WQtDatasetTreeItem * addDatasetItem(std::shared_ptr< WModule > module)
add a dataset item below this subject in the tree
Base class for all items in the control panel tree.
WModule::SPtr getModule()
Get for the module pointer.
virtual void handleCheckStateChange()
Handle changes in check state.
std::shared_ptr< WRMBranch > SPtr
Convenience type for a shared pointer of this type.
osg::ref_ptr< WROI > RefPtr
Ref Pointer type.
Event signalling a new ROI has been associated with the ROI manager in the kernel.
osg::ref_ptr< WROI > getRoi()
Getter for the ROI that got associated.
Event signalling a ROI has been removed from the ROI manager in the kernel.
osg::ref_ptr< WROI > getRoi()
Getter for the ROI that got removed.
Event signalling that a sorting of the ROIs needs to be done.
WQtBranchTreeItem * getBranch()
Getter for the branch.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
WStreamedLogger error(const std::string &source)
Logging an error message.