Page MenuHomePhabricator

materialeditorcherryselection.patch

Authored By
goch
Dec 16 2009, 6:09 PM
Size
9 KB
Referenced Files
None
Subscribers
None

materialeditorcherryselection.patch

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<QmitkMITKSurfaceMaterialEditorView>(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<const cherry::IStructuredSelection>();
+ this->SelectionChanged(cherry::SmartPointer<IWorkbenchPart>(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<const cherry::IStructuredSelection>() ) // 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<const cherry::IStructuredSelection>();
+
+ //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<mitk::DataTreeNodeObject>())
+ {
+ 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<mitk::Image*>( 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 <QmitkFunctionality.h>
-
+#include <cherryISelectionListener.h>
+#include <cherryIStructuredSelection.h>
#include <string>
#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<std::string> fixedProperties;
std::list<std::string> 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 @@
</widget>
</item>
<item>
- <widget class="QGroupBox" name="groupBox_ImageViewSelect">
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>16</height>
- </size>
- </property>
- <property name="baseSize">
- <size>
- <width>0</width>
- <height>16</height>
- </size>
- </property>
- <property name="title">
- <string>Surface</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <widget class="QmitkDataStorageComboBox" name="m_ImageSelector">
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>8</height>
- </size>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item>
<widget class="QGroupBox" name="groupBox_ShaderSelect">
<property name="title">
<string>Properties</string>
@@ -87,11 +56,6 @@
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
- <class>QmitkDataStorageComboBox</class>
- <extends>QComboBox</extends>
- <header>QmitkDataStorageComboBox.h</header>
- </customwidget>
- <customwidget>
<class>QmitkRenderWindow</class>
<extends>QListView</extends>
<header>QmitkRenderWindow.h</header>

File Metadata

Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
317
Default Alt Text
materialeditorcherryselection.patch (9 KB)

Event Timeline

Change from selection combo box to cherry selection service