]> Creatis software - clitk.git/commitdiff
VV: added links to Read/Save state
authorRomulo Pinho <romulo.pinho@lyon.unicancer.fr>
Fri, 19 Oct 2012 09:52:27 +0000 (11:52 +0200)
committerRomulo Pinho <romulo.pinho@lyon.unicancer.fr>
Fri, 19 Oct 2012 09:52:27 +0000 (11:52 +0200)
vv/vvLinkPanel.cxx
vv/vvLinkPanel.h
vv/vvMainWindow.cxx
vv/vvMainWindow.h
vv/vvReadState.cxx
vv/vvReadState.h
vv/vvSaveState.cxx
vv/vvSaveState.h
vv/vvSlicerManager.h

index 87f3a0fcae8fc364a7d61b04aec414fe30256a5e..5b890d1057de1c5d55bde8edfdd0a1ead29bd9af 100644 (file)
@@ -152,6 +152,29 @@ void vvLinkPanel::linkAll()
 }
 //------------------------------------------------------------------------------
 
+//------------------------------------------------------------------------------
+void vvLinkPanel::addLinkFromIds(QString id1, QString id2)
+{
+  int index1 = -1, index2 = -1;
+  size_t s1 = image1Ids.size();
+  size_t s2 = image2Ids.size();
+  for (size_t i = 0; i < s1 && index1 == -1; i++)
+    if (image1Ids[i] == id1.toStdString())
+      index1 = i;
+
+  if (index1 >= 0)
+    image1ComboBox->setCurrentIndex(index1);
+    
+  for (size_t i = 0; i < s2 && index2 == -1; i++)
+    if (image2Ids[i] == id2.toStdString())
+      index2 = i;
+  
+  if (index1 >= 0 && index2 >= 0) {
+    image2ComboBox->setCurrentIndex(index2);
+    addLink();
+  }
+}
+//------------------------------------------------------------------------------
 
 //------------------------------------------------------------------------------
 void vvLinkPanel::addLink()
@@ -182,7 +205,9 @@ void vvLinkPanel::addLink()
     linkTableWidget->setRowHeight(row,17);
 
     emit addLink(image1Ids[image1ComboBox->currentIndex()].c_str(),
-                 image2Ids[image2ComboBox->currentIndex()].c_str());
+                 image2Ids[image2ComboBox->currentIndex()].c_str(),
+                 true
+                );
     UpdateComboBox2(image1ComboBox->currentIndex());
   }
 
index 2302407bdba3c6c062a96f9d9349e018494185ca..c73cde4966b59045c64d9a4fcfbd3327d3374ba4 100644 (file)
@@ -34,6 +34,7 @@ public:
     ~vvLinkPanel() {}
 
     void addImage(std::string name, std::string id);
+    void addLinkFromIds(QString id1, QString id2);
     void removeImage(int i);
     bool isLinkAll();
 
@@ -44,7 +45,7 @@ public slots :
     void linkAll();
 
 signals:
-    void addLink(QString image1,QString image2);
+    void addLink(QString image1,QString image2,bool);
     void removeLink(QString image1,QString image2);
 
 private:
index 7f468d073b1553385db0336c7e17742698cedde9..bca77cf7b0ab937b0999d01da71206569b925280 100644 (file)
@@ -315,7 +315,7 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
 
   connect(this,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(ShowContextMenu(QPoint)));
 
-  connect(linkPanel,SIGNAL(addLink(QString,QString)),this,SLOT(AddLink(QString,QString)));
+  connect(linkPanel,SIGNAL(addLink(QString,QString,bool)),this,SLOT(AddLink(QString,QString,bool)));
   connect(linkPanel,SIGNAL(removeLink(QString,QString)),this,SLOT(RemoveLink(QString,QString)));
   connect(overlayPanel,SIGNAL(VFPropertyUpdated(int,int,int,int,double,double,double)),this,SLOT(SetVFProperty(int,int,int,int,double,double,double)));
   connect(overlayPanel,SIGNAL(OverlayPropertyUpdated(int,int,double,double)),
@@ -928,7 +928,7 @@ void vvMainWindow::LoadImages(std::vector<std::string> files, vvImageReader::Loa
         DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
 
         //set the id of the image
-        QString id = files[i].c_str() + QString::number(mSlicerManagers.size()-1);
+        QString id = QDir::current().absoluteFilePath(files[i].c_str()) + QString::number(mSlicerManagers.size()-1);
         item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
         mSlicerManagers.back()->SetId(id.toStdString());
 
@@ -2486,8 +2486,14 @@ void vvMainWindow::LinkAllImages()
 }
 
 //------------------------------------------------------------------------------
-void vvMainWindow::AddLink(QString image1,QString image2)
+void vvMainWindow::AddLink(QString image1,QString image2,bool fromPanel)
 {
+  if (!fromPanel) {
+    // delegate to linkPanel if call came from elsewhere...
+    linkPanel->addLinkFromIds(image1, image2);
+    return;
+  }
+  
   unsigned int sm1 = 0;
   unsigned int sm2 = 0;
 
@@ -3148,7 +3154,7 @@ vvSlicerManager* vvMainWindow::AddImage(vvImage::Pointer image,std::string filen
   DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
 
   //set the id of the image
-  QString id = slicer_manager->GetFileName().c_str() + QString::number(mSlicerManagers.size()-1);
+  QString id = QDir::current().absoluteFilePath(slicer_manager->GetFileName().c_str()) + QString::number(mSlicerManagers.size()-1);
   item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
   mSlicerManagers.back()->SetId(id.toStdString());
 
index 1621c32ea3e417f32c44d9fda482ad6d42706509..e308314c59620094e59ac7bb778856154089283c 100644 (file)
@@ -125,7 +125,7 @@ public slots:
   void ApplyLevelToSetOfImages(double level, unsigned int indexMin, unsigned int indexMax);
   void UpdateLinkManager(std::string id, int slicer, double x, double y, double z, int temps);
   void UpdateLinkedNavigation(std::string id, vvSlicerManager *sm, vvSlicer* refSlicer);
-  void AddLink(QString image1,QString image2);
+  void AddLink(QString image1,QString image2,bool fromPanel = true);
   void RemoveLink(QString image1,QString image2);
   void ChangeImageWithIndexOffset(vvSlicerManager *sm, int slicer, int offset);
 
index 13bb083867ab6e6a008fecba941c92e154b6525b..980bbf1ffeac7a832fc086265f68f14a05911dd0 100644 (file)
@@ -73,6 +73,7 @@ void vvReadState::ReadTree()
 {
   std::string value;
   
+  // read images
   while (!m_XmlReader->isEndElement() || value != "Images") { 
     m_XmlReader->readNext();
     value = m_XmlReader->qualifiedName().toString().toStdString();
@@ -81,6 +82,15 @@ void vvReadState::ReadTree()
     } 
   }
   
+  // read links
+  while (!m_XmlReader->isEndElement() || value != "Links") { 
+    m_XmlReader->readNext();
+    value = m_XmlReader->qualifiedName().toString().toStdString();
+    if (m_XmlReader->isStartElement()) {
+      if (value == "LinkedFrom") value = ReadLink();
+    } 
+  }
+
   if (m_XmlReader->hasError())
     std::cout << "Error " << m_XmlReader->error() << " XML " << std::endl;
 }
@@ -262,6 +272,33 @@ std::string vvReadState::ReadVector(int index)
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+std::string  vvReadState::ReadLink()
+{
+  std::string id_from, id_to, value;
+  
+  QXmlStreamAttributes attributes = m_XmlReader->attributes();
+  if (!m_XmlReader->hasError()) {
+    id_from = attributes.value("Id").toString().toStdString();
+  }
+
+  while (!m_XmlReader->isEndElement() || value != "LinkedFrom") { 
+    m_XmlReader->readNext();
+    value = m_XmlReader->qualifiedName().toString().toStdString();
+    if (m_XmlReader->isStartElement()) {
+      if (value == "LinkedTo") {
+        id_to = m_XmlReader->readElementText().toStdString();
+        if (!m_XmlReader->hasError()) {
+          m_Window->AddLink(id_from.c_str(), id_to.c_str(), false);
+        }
+      }
+    }
+  }
+  
+  return value;
+}
+//------------------------------------------------------------------------------
+
 //------------------------------------------------------------------------------
 void vvReadState::ReadGUI()
 {
index 04607f68790bfa4261145f0526abf7b55a774502..a34c464cfa2bd17a7e0063ba5c54ee7ab50da967 100644 (file)
@@ -27,6 +27,7 @@ protected:
   std::string ReadFusion(int index);
   std::string ReadOverlay(int index);
   std::string ReadVector(int index);
+  std::string ReadLink();
 
   std::auto_ptr<QXmlStreamReader> m_XmlReader;
   std::auto_ptr<QFile> m_File;
index d4a76bd2d9a20010bd4e9df36f48aa651212749a..ecf29da4b5939ff784f4b73eaa84a529ea7e8e61 100644 (file)
@@ -72,6 +72,13 @@ void vvSaveState::SaveTree()
     SaveImage(item, i);
   }
   m_XmlWriter->writeEndElement();
+
+  m_XmlWriter->writeStartElement("Links");
+  for (int i = 0; i < tree->topLevelItemCount(); i++) {
+    const vvSlicerManager * slicerManager = m_Window->GetSlicerManagers()[i];
+    SaveLink(slicerManager);
+  }
+  m_XmlWriter->writeEndElement();
 }
 //------------------------------------------------------------------------------
 
@@ -156,6 +163,24 @@ void vvSaveState::SaveVector(const QTreeWidgetItem* item)
 }
 //------------------------------------------------------------------------------
 
+//------------------------------------------------------------------------------
+void vvSaveState::SaveLink(const vvSlicerManager* vvManager)
+{
+  typedef std::list<std::string> LinkListType;
+  LinkListType links = vvManager->GetLinks();
+  if (!links.empty()) {
+    std::string my_id = vvManager->GetId();
+    m_XmlWriter->writeStartElement("LinkedFrom");
+    m_XmlWriter->writeAttribute("Id", my_id.c_str());
+    typename LinkListType::iterator i;
+    for (i = links.begin(); i != links.end(); i++) {
+      std::string link_id = *i;
+      m_XmlWriter->writeTextElement("LinkedTo", link_id.c_str());
+    }
+    m_XmlWriter->writeEndElement();
+  }
+}
+//------------------------------------------------------------------------------
 
 //------------------------------------------------------------------------------
 void vvSaveState::SaveGUI()
index 29a0e405803fc64fbec339bd6c69dc2855e21132..4f96c063e15a61e413fa1bbb531422111603ff6f 100644 (file)
@@ -28,6 +28,7 @@ protected:
   void SaveFusion(const QTreeWidgetItem* item, const vvSlicerManager* slicerManager);
   void SaveOverlay(const QTreeWidgetItem* item, const vvSlicerManager* slicerManager);
   void SaveVector(const QTreeWidgetItem* item);
+  void SaveLink(const vvSlicerManager* slicerManager);
 
   std::auto_ptr<QXmlStreamWriter> m_XmlWriter;
   std::auto_ptr<QFile> m_File;
index 1824524ade043e8a4fb8a74a05ade831bbfe43fa..dcac673216f1af7eef36b8394dfa32bb6dbbf8f9 100644 (file)
@@ -99,7 +99,7 @@ class vvSlicerManager : public QObject {
   vvImage::Pointer GetVF()     { return mVF; }
   int GetType()                { return mType; }
   void SetId(std::string id)   { mId = id; }
-  std::string GetId()          { return mId; }
+  std::string GetId()  const        { return mId; }
   int GetDimension() {
     if (mImage) return mImage->GetNumberOfDimensions();
     else return -1;
@@ -193,6 +193,10 @@ class vvSlicerManager : public QObject {
     mLinkedId.remove(oldId); 
   }
   
+  std::list<std::string> GetLinks() const {
+    return mLinkedId;
+  }
+  
   bool IsLinked() {
     return mLinkedId.size() > 0;
   }