Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "QmitkExtFileOpenAction.h"
00019
00020 #include <QFileDialog>
00021 #include <QFileInfo>
00022 #include <mitkDataNodeFactory.h>
00023
00024 #include "mitkCoreObjectFactory.h"
00025 #include "mitkSceneIO.h"
00026 #include "mitkProgressBar.h"
00027
00028 #include <mitkCoreExtObjectFactory.h>
00029 #include <mitkDataStorageEditorInput.h>
00030 #include <berryIEditorPart.h>
00031 #include <berryIWorkbenchPage.h>
00032 #include <berryIPreferencesService.h>
00033 #include <berryPlatform.h>
00034
00035 #include "mitkProperties.h"
00036 #include "mitkNodePredicateData.h"
00037 #include "mitkNodePredicateNot.h"
00038 #include "mitkNodePredicateProperty.h"
00039
00040
00041 #include "QmitkStdMultiWidgetEditor.h"
00042
00043 QmitkExtFileOpenAction::QmitkExtFileOpenAction(berry::IWorkbenchWindow::Pointer window)
00044 : QAction(0)
00045 {
00046 this->init(window);
00047 }
00048
00049 QmitkExtFileOpenAction::QmitkExtFileOpenAction(const QIcon & icon, berry::IWorkbenchWindow::Pointer window)
00050 : QAction(0)
00051 {
00052 this->setIcon(icon);
00053
00054 this->init(window);
00055 }
00056
00057 void QmitkExtFileOpenAction::init(berry::IWorkbenchWindow::Pointer window)
00058 {
00059 m_Window = window;
00060 this->setParent(static_cast<QWidget*>(m_Window->GetShell()->GetControl()));
00061 this->setText("&Open...");
00062 this->setToolTip("Open data files (images, surfaces,...) and project files (.mitk)");
00063
00064 berry::IPreferencesService::Pointer prefService
00065 = berry::Platform::GetServiceRegistry()
00066 .GetServiceById<berry::IPreferencesService>(berry::IPreferencesService::ID);
00067
00068 m_GeneralPreferencesNode = prefService->GetSystemPreferences()->Node("/General");
00069
00070 this->connect(this, SIGNAL(triggered(bool)), this, SLOT(Run()));
00071 }
00072
00073 void QmitkExtFileOpenAction::Run()
00074 {
00078 static QString m_LastPath;
00079
00080 if(m_GeneralPreferencesNode.Lock().IsNotNull())
00081 {
00082 if(m_LastPath.isEmpty())
00083 m_LastPath = QString::fromStdString(m_GeneralPreferencesNode.Lock()->Get("LastFileOpenPath", ""));
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 std::stringstream ss;
00097 ss << mitk::CoreObjectFactory::GetInstance()->GetFileExtensions();
00098
00099 std::string fileExtensions = ss.str();
00100 fileExtensions.append(";;MITK Scene Files (*.mitk)");
00101 fileExtensions.insert( fileExtensions.find("all (") + 5, "*.mitk " );
00102
00103 QStringList fileNames = QFileDialog::getOpenFileNames(NULL, "Open", m_LastPath, fileExtensions.c_str() );
00104
00105
00106
00107
00108 if (fileNames.empty())
00109 return;
00110
00111 QFileInfo info(fileNames.at(0));
00112 m_LastPath = info.filePath();
00113
00114 if(m_GeneralPreferencesNode.Lock().IsNotNull())
00115 {
00116 m_GeneralPreferencesNode.Lock()->Put("LastFileOpenPath", m_LastPath.toStdString());
00117 m_GeneralPreferencesNode.Lock()->Flush();
00118 }
00119
00120 mitk::DataStorageEditorInput::Pointer editorInput;
00121 mitk::DataStorage::Pointer dataStorage;
00122 QmitkStdMultiWidgetEditor::Pointer multiWidgetEditor;
00123 berry::IEditorPart::Pointer editor = m_Window->GetActivePage()->GetActiveEditor();
00124
00125 if (editor.Cast<QmitkStdMultiWidgetEditor>().IsNull())
00126 {
00127 editorInput = new mitk::DataStorageEditorInput();
00128 dataStorage = editorInput->GetDataStorageReference()->GetDataStorage();
00129 }
00130 else
00131 {
00132 multiWidgetEditor = editor.Cast<QmitkStdMultiWidgetEditor>();
00133 dataStorage = multiWidgetEditor->GetEditorInput().Cast<mitk::DataStorageEditorInput>()->GetDataStorageReference()->GetDataStorage();
00134 }
00135
00136 if (multiWidgetEditor.IsNull())
00137 {
00138 berry::IEditorPart::Pointer editor = m_Window->GetActivePage()->OpenEditor(editorInput, QmitkStdMultiWidgetEditor::EDITOR_ID);
00139 multiWidgetEditor = editor.Cast<QmitkStdMultiWidgetEditor>();
00140 }
00141 else
00142 {
00143 multiWidgetEditor->GetStdMultiWidget()->RequestUpdate();
00144 }
00145
00146 bool dsmodified = false;
00147
00148 for (QStringList::Iterator fileName = fileNames.begin();
00149 fileName != fileNames.end(); ++fileName)
00150 {
00151 if ( fileName->right(5) == ".mitk" )
00152 {
00153 mitk::SceneIO::Pointer sceneIO = mitk::SceneIO::New();
00154
00155 bool clearDataStorageFirst(false);
00156 mitk::ProgressBar::GetInstance()->AddStepsToDo(2);
00157 dataStorage = sceneIO->LoadScene( fileName->toLocal8Bit().constData(), dataStorage, clearDataStorageFirst );
00158 dsmodified = true;
00159 mitk::ProgressBar::GetInstance()->Progress(2);
00160 }
00161 else
00162 {
00163 mitk::DataNodeFactory::Pointer nodeReader = mitk::DataNodeFactory::New();
00164 try
00165 {
00166 nodeReader->SetFileName(fileName->toLocal8Bit().data());
00167 nodeReader->Update();
00168 for ( unsigned int i = 0 ; i < nodeReader->GetNumberOfOutputs( ); ++i )
00169 {
00170 mitk::DataNode::Pointer node;
00171 node = nodeReader->GetOutput(i);
00172 if ( node->GetData() != NULL )
00173 {
00174 dataStorage->Add(node);
00175 dsmodified = true;
00176 }
00177 }
00178 }
00179 catch(...)
00180 {
00181
00182 }
00183 }
00184 }
00185
00186
00187 if(dsmodified)
00188 {
00189
00190 mitk::NodePredicateNot::Pointer pred
00191 = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox"
00192 , mitk::BoolProperty::New(false)));
00193
00194 mitk::DataStorage::SetOfObjects::ConstPointer rs = dataStorage->GetSubset(pred);
00195
00196 mitk::TimeSlicedGeometry::Pointer bounds = dataStorage->ComputeBoundingGeometry3D(rs);
00197
00198 mitk::RenderingManager::GetInstance()->InitializeViews(bounds);
00199 }
00200 }