]> Creatis software - clitk.git/blobdiff - vv/vvQPacsConnection.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvQPacsConnection.cxx
index 920876877e43f1cdf996abece4163803cee248ae..4ae0d33b9981bdddc7a31e98e2f2aa0b55c16b7f 100644 (file)
@@ -7,14 +7,16 @@
 #include <QDateTime>
 #include "vvPacsSettingsDialog.h"
 #include "vvUtils.h"
-
+#include <algorithm>
+#include <itkGDCMImageIO.h>
+#include <itkGDCMSeriesFileNames.h>
 
 
 vvQPacsConnection::vvQPacsConnection(QWidget *i_parent)
        :QDialog(i_parent)
 {
        ui.setupUi(this);
-       setWindowTitle(QString::fromUtf8("PACS CONNECTIONHHHH"));
+       setWindowTitle(QString::fromUtf8("PACS CONNECTION"));
        createTreeView();
        ui.tabFilter->setTabText(0,QString(tr("Modality")));
        ui.tabFilter->setTabText(1,QString(tr("Date")));
@@ -29,10 +31,18 @@ vvQPacsConnection::vvQPacsConnection(QWidget *i_parent)
        connect(ui.networkCombo,SIGNAL(currentIndexChanged(int)),this,SLOT(chooseServer(int)));
        connect(ui.removeNetworkButton,SIGNAL(clicked()),this,SLOT(removeServer()));
        connect(ui.NetworkButton,SIGNAL(clicked()),this,SLOT(modifyServer()));
+       connect(ui.exitButton,SIGNAL(clicked()),this,SLOT(close()));
        
        update();
 }
 
+// Exit window
+bool vvQPacsConnection::close()
+{
+    QApplication::restoreOverrideCursor();
+    return QWidget::close();
+}
+
 // remote a Dicom Server in VV settings
 void vvQPacsConnection::removeServer()
 {
@@ -45,8 +55,13 @@ void vvQPacsConnection::removeServer()
 // modify a Dicom Server in VV settings
 void vvQPacsConnection::modifyServer()
 {
+       int indexCombo = ui.networkCombo->currentIndex();
+       removeDicomServer(m_nickname);
        AddDicomServer(ui.NameEdit->text().toStdString(),ui.AETitleEdit->text().toStdString(),ui.AdressEdit->text().toStdString(),ui.PortEdit->text().toStdString());
-       removeServer();
+       ui.networkCombo->clear();
+       ui.networkCombo->addItem(QString());
+       ui.networkCombo->addItems(getDicomServers());
+       ui.networkCombo->setCurrentIndex(indexCombo);
 }
 
 // refresh the list of Dicom Servers available from VV settings
@@ -182,10 +197,10 @@ void vvQPacsConnection::createTreeView()
 // clean the different model Trees
 void vvQPacsConnection::cleanTree()
 {
-       Patientmodel->removeRows(0,Patientmodel->rowCount(),QModelIndex());
-       Studymodel->removeRows(0,Patientmodel->rowCount(),QModelIndex());
-       Seriesmodel->removeRows(0,Patientmodel->rowCount(),QModelIndex());
-       Imagesmodel->removeRows(0,Patientmodel->rowCount(),QModelIndex());
+       Patientmodel->removeRows(0,Patientmodel->rowCount());
+       Studymodel->removeRows(0,Patientmodel->rowCount());
+       Seriesmodel->removeRows(0,Patientmodel->rowCount());
+       Imagesmodel->removeRows(0,Patientmodel->rowCount());
 
 }
 
@@ -197,19 +212,20 @@ void vvQPacsConnection::selectStudies(const QModelIndex &index)
        Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
        Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
        manageSeriesFilter(true);
-        m_query = mQFactory.getQueryPatient("",m_patient);
        convertDataSet( findQuery( mQFactory.getQueryforStudy(m_patient, false)) , Studymodel, mQFactory.getQueryKeysforStudy("",true));
 }
 
 
+void vvQPacsConnection::clearMove()
+{
 
+}
 
 void vvQPacsConnection::selectSeries(const QModelIndex &index)
 {
        m_study= Studymodel->data(index.sibling(index.row(),3)).toString().toStdString();
        Seriesmodel->removeRows(0, Seriesmodel->rowCount());
        Imagesmodel->removeRows(0, Imagesmodel->rowCount());
-       m_query = mQFactory.getQueryforSeries(m_patient,m_study, false);
     convertDataSet( findQuery( mQFactory.getQueryforSeries(m_patient,m_study, false)), Seriesmodel, mQFactory.getSeriesKeys("","",true));
        
 }
@@ -218,7 +234,6 @@ void vvQPacsConnection::selectImages(const QModelIndex &index)
 {
        m_series = Seriesmodel->data(index.sibling(index.row(),2)).toString().toStdString();
        Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
-       m_query = mQFactory.getQueryforImages(m_patient,m_study, m_series, false);
        convertDataSet( findQuery( mQFactory.getQueryforImages(m_patient,m_study, m_series, false) ),  Imagesmodel, mQFactory.getQueryKeysforImages("","","",true));
  
 }
@@ -304,7 +319,7 @@ std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getKeys()
        //gdcm::Tag tagsdc(8,1030);
        //keys.push_back(std::make_pair(tagsdc, ""));
 
-       //// Accession n°
+       //// Accession
        //gdcm::Tag tagacc(8,50);
        //keys.push_back(std::make_pair(tagacc, ""));
 
@@ -364,21 +379,59 @@ void vvQPacsConnection::chooseServer(int index)
 
 void vvQPacsConnection::on_importButton_clicked()
        {
-       
+               setCursor(QCursor(Qt::WaitCursor));
+               QString path = QString::fromStdString(getCMoveDirectory());
+               QDir dirpath (path);
+               if (dirpath.exists())
+               {
+                       QFileInfoList list = dirpath.entryInfoList( QDir::Files);
+                       QFileInfoList::iterator it_file = dirpath.entryInfoList( QDir::Files).begin();
+                       for(int i = 0; i < list.length() ; i++)
+                       {
+                                       QFile::remove(list.at(i).filePath());
+                       }
+               }
+               else
+               {
+                       dirpath.mkdir(path);
+               }
                bool didItWork =  gdcm::CompositeNetworkFunctions::CMove(m_adress.c_str(),atoi(m_port.c_str()),
-                       gdcm::CompositeNetworkFunctions::ConstructQuery(mQFactory.getMoveQuery().theRoot, mQFactory.getMoveQuery().theLevel ,mQFactory.getMoveQuery().keys,true),
-                       getDicomClientPort(),  getDicomClientAETitle().c_str(), m_aetitle.c_str(),"D:\\move" );
+                       gdcm::CompositeNetworkFunctions::ConstructQuery(mQFactory.getMoveQuery().theRoot, mQFactory.getMoveQuery().theLevel ,mQFactory.getMoveQuery().keys, gdcm::eMove),
+                       getDicomClientPort(),  getDicomClientAETitle().c_str(), m_aetitle.c_str(), path.toStdString().c_str() );
                gdcm::Directory theDir;
-               theDir.Load("D:\\move");
-          m_files =    theDir.GetFilenames();
+               theDir.Load(path.toStdString().c_str());
+     //m_files =       theDir.GetFilenames();
+
+     typedef itk::GDCMSeriesFileNames NamesGeneratorType;
+     NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
+     nameGenerator->SetUseSeriesDetails(true);
+
+     //ds gerer recursive moi-meme pour progress ...
+     nameGenerator->SetInputDirectory(path.toStdString());
+
+     // insert in table
+     typedef std::vector<std::string> SeriesIdContainer;
+     const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
+       std::map<std::string, std::vector<std::string>* > mListOfSeriesFilenames;
+
+
+          m_fileseries.clear();
+          
+     for (unsigned int i=0; i<seriesUID.size(); i++) {
+               m_fileseries.push_back( nameGenerator->GetFileNames(seriesUID[i]));
+        }
+          
           accept();
+         setCursor(QCursor(Qt::ArrowCursor));
        }
 
-std::vector <std::string> vvQPacsConnection::getFileNames()
+
+
+std::vector <std::string> vvQPacsConnection::getFileNames(int i_series)
 {
        std::vector <std::string> filenames;
-       gdcm::Directory::FilenamesType::iterator it = m_files.begin();
-       for (;it != m_files.end(); it++)
+       gdcm::Directory::FilenamesType::iterator it = m_fileseries[i_series].begin();
+       for (;it != m_fileseries[i_series].end(); it++)
                filenames.push_back(it->c_str());
        return filenames;
 }