Index: mitk/Modules/Bundles/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorView.cpp =================================================================== --- mitk/Modules/Bundles/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorView.cpp (revision 20878) +++ mitk/Modules/Bundles/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorView.cpp (working copy) @@ -21,7 +21,12 @@ #include "mitkBaseRenderer.h" #include "mitkNodePredicateDataType.h" #include "mitkProperties.h" +#include "mitkIDataStorageService.h" +#include "mitkDataTreeNodeObject.h" +#include "cherryIEditorPart.h" +#include "cherryIWorkbenchPage.h" + #include "mitkShaderEnumProperty.h" #include "mitkShaderRepository.h" @@ -88,9 +93,6 @@ void QmitkMITKSurfaceMaterialEditorView::InitPreviewWindow() { - - - usedTimer=0; m_MaterialProperty = mitk::MaterialProperty::New(); @@ -116,20 +118,17 @@ m_Controls->m_PreviewRenderWindow->GetRenderer()->SetMapperID( mitk::BaseRenderer::Standard3D ); sphereSource->Delete(); - - //m_DataTreeNode->GetPropertyList(); - - //m_Controls->m_ShaderPropertyList->setNode( m_DataTreeNode ); } void QmitkMITKSurfaceMaterialEditorView::RefreshPropertiesList() { - mitk::DataTreeNode* SrcND = m_Controls->m_ImageSelector->GetSelectedNode(); + mitk::DataTreeNode* SrcND = m_SelectedDataTreeNode; mitk::DataTreeNode* DstND = m_DataTreeNode; mitk::PropertyList* DstPL = DstND->GetPropertyList(); + m_Controls->m_ShaderPropertyList->SetPropertyList( 0 ); DstPL->Clear(); @@ -188,6 +187,7 @@ } m_Controls->m_ShaderPropertyList->SetPropertyList( DstPL ); + //m_Controls->m_PreviewRenderWindow->GetRenderer()->GetVtkRenderer()->ResetCameraClippingRange(); } /* @@ -245,15 +245,26 @@ this->CreateConnections(); // define data type for combobox - m_Controls->m_ImageSelector->SetDataStorage( this->GetDefaultDataStorage() ); + /* m_Controls->m_ImageSelector->SetDataStorage( this->GetDefaultDataStorage() ); m_Controls->m_ImageSelector->SetPredicate( mitk::NodePredicateDataType::New("Surface") ); InitPreviewWindow(); connect( m_Controls->m_ImageSelector, SIGNAL( OnSelectionChanged(const mitk::DataTreeNode::Pointer) ), this, SLOT( SurfaceSelected() ) ); - RefreshPropertiesList(); + RefreshPropertiesList(); */ + InitPreviewWindow(); + + // listener for selected entry in the data manager + m_SelectionListener = cherry::ISelectionListener::Pointer(new cherry::SelectionChangedAdapter(this, &QmitkMITKSurfaceMaterialEditorView::SelectionChanged)); + this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener(/*"org.mitk.views.datamanager",*/ m_SelectionListener); + cherry::ISelection::ConstPointer selection( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection()); + m_CurrentSelection = selection.Cast(); + this->SelectionChanged(cherry::SmartPointer(NULL), selection); + + RefreshPropertiesList(); + } } @@ -285,6 +296,42 @@ QmitkFunctionality::Deactivated(); } + +void QmitkMITKSurfaceMaterialEditorView::SelectionChanged(cherry::IWorkbenchPart::Pointer sourcepart, cherry::ISelection::ConstPointer selection) +{ + if ( sourcepart == this || // prevents being notified by own selection events + !selection.Cast() ) // checks that the selection is a IStructuredSelection and not NULL + { + return; // otherwise we get "null selection" events each time the view is activated/focussed + } + + LOG_INFO << "selection changed"; + // save current selection in member variable + m_CurrentSelection = selection.Cast(); + + //bool newReferenceImageSelected(false); + + // TODO warning when two images are selected + // do something with the selected items + if(m_CurrentSelection) + { + // iterate selection + for (cherry::IStructuredSelection::iterator i = m_CurrentSelection->Begin(); i != m_CurrentSelection->End(); ++i) + { + // extract datatree node + if (mitk::DataTreeNodeObject::Pointer nodeObj = i->Cast()) + { + m_SelectedDataTreeNode = nodeObj->GetDataTreeNode(); + LOG_INFO << "Node '" << m_SelectedDataTreeNode->GetName() << "' selected"; + + SurfaceSelected(); + return; + } + } + } + //TODO: warning if m_InputImageNode is NULL +} + void QmitkMITKSurfaceMaterialEditorView::SurfaceSelected() { postRefresh(); @@ -295,36 +342,6 @@ postRefresh(); } - -/* - mitk::DataTreeNode* node = m_Controls->m_ImageSelector->GetSelectedNode(); - if (!node) - { - // Nothing selected. Inform the user and return - QMessageBox::information( NULL, "Template functionality", "Please load and select an image before starting some action."); - return; - } - - // here we have a valid mitk::DataTreeNode - - // a node itself is not very useful, we need its data item (the image) - mitk::BaseData* data = node->GetData(); - if (data) - { - // test if this data item is really an image or not (could also be a surface or something totally different) - mitk::Image* image = dynamic_cast( data ); - if (image) - { - std::string name("(no name)"); - node->GetName(name); - - QMessageBox::information( NULL, "Image processing", - QString( "Doing something to '%1'" ).arg(name.c_str()) ); - - // at this point anything can be done using the mitk::Image image. - } - }*/ - void QmitkMITKSurfaceMaterialEditorView::postRefresh() { if(usedTimer) Index: mitk/Modules/Bundles/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorView.h =================================================================== --- mitk/Modules/Bundles/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorView.h (revision 20878) +++ mitk/Modules/Bundles/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorView.h (working copy) @@ -20,7 +20,8 @@ #define _QMITKMITKSURFACEMATERIALEDITORVIEW_H_INCLUDED #include - +#include +#include #include #include "ui_QmitkMITKSurfaceMaterialEditorViewControls.h" @@ -83,7 +84,8 @@ virtual void StdMultiWidgetNotAvailable(); protected slots: - + + void SelectionChanged(cherry::IWorkbenchPart::Pointer sourcepart, cherry::ISelection::ConstPointer selection); void SurfaceSelected(); protected: @@ -92,12 +94,13 @@ QmitkStdMultiWidget* m_MultiWidget; -public: +private: mitk::MaterialProperty::Pointer m_MaterialProperty; mitk::Surface::Pointer m_Surface; mitk::DataStorage::Pointer m_DataTree; mitk::DataTreeNode::Pointer m_DataTreeNode; + mitk::DataTreeNode::Pointer m_SelectedDataTreeNode; std::list fixedProperties; std::list shaderProperties; @@ -118,7 +121,8 @@ void shaderEnumChange(const itk::Object *caller, const itk::EventObject &event); - + cherry::IStructuredSelection::ConstPointer m_CurrentSelection; + cherry::ISelectionListener::Pointer m_SelectionListener; }; Index: mitk/Modules/Bundles/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorViewControls.ui =================================================================== --- mitk/Modules/Bundles/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorViewControls.ui (revision 20878) +++ mitk/Modules/Bundles/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorViewControls.ui (working copy) @@ -40,37 +40,6 @@ - - - - 0 - 16 - - - - - 0 - 16 - - - - Surface - - - - - - - 0 - 8 - - - - - - - - Properties @@ -87,11 +56,6 @@ - QmitkDataStorageComboBox - QComboBox -
QmitkDataStorageComboBox.h
-
- QmitkRenderWindow QListView
QmitkRenderWindow.h