From 84facf1bc847da95b567b0c7531404c170f68cc2 Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Fri, 19 Oct 2012 11:52:27 +0200 Subject: [PATCH] VV: added links to Read/Save state --- vv/vvLinkPanel.cxx | 27 ++++++++++++++++++++++++++- vv/vvLinkPanel.h | 3 ++- vv/vvMainWindow.cxx | 14 ++++++++++---- vv/vvMainWindow.h | 2 +- vv/vvReadState.cxx | 37 +++++++++++++++++++++++++++++++++++++ vv/vvReadState.h | 1 + vv/vvSaveState.cxx | 25 +++++++++++++++++++++++++ vv/vvSaveState.h | 1 + vv/vvSlicerManager.h | 6 +++++- 9 files changed, 108 insertions(+), 8 deletions(-) diff --git a/vv/vvLinkPanel.cxx b/vv/vvLinkPanel.cxx index 87f3a0f..5b890d1 100644 --- a/vv/vvLinkPanel.cxx +++ b/vv/vvLinkPanel.cxx @@ -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()); } diff --git a/vv/vvLinkPanel.h b/vv/vvLinkPanel.h index 2302407..c73cde4 100644 --- a/vv/vvLinkPanel.h +++ b/vv/vvLinkPanel.h @@ -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: diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 7f468d0..bca77cf 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -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 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()); diff --git a/vv/vvMainWindow.h b/vv/vvMainWindow.h index 1621c32..e308314 100644 --- a/vv/vvMainWindow.h +++ b/vv/vvMainWindow.h @@ -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); diff --git a/vv/vvReadState.cxx b/vv/vvReadState.cxx index 13bb083..980bbf1 100644 --- a/vv/vvReadState.cxx +++ b/vv/vvReadState.cxx @@ -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() { diff --git a/vv/vvReadState.h b/vv/vvReadState.h index 04607f6..a34c464 100644 --- a/vv/vvReadState.h +++ b/vv/vvReadState.h @@ -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 m_XmlReader; std::auto_ptr m_File; diff --git a/vv/vvSaveState.cxx b/vv/vvSaveState.cxx index d4a76bd..ecf29da 100644 --- a/vv/vvSaveState.cxx +++ b/vv/vvSaveState.cxx @@ -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 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() diff --git a/vv/vvSaveState.h b/vv/vvSaveState.h index 29a0e40..4f96c06 100644 --- a/vv/vvSaveState.h +++ b/vv/vvSaveState.h @@ -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 m_XmlWriter; std::auto_ptr m_File; diff --git a/vv/vvSlicerManager.h b/vv/vvSlicerManager.h index 1824524..dcac673 100644 --- a/vv/vvSlicerManager.h +++ b/vv/vvSlicerManager.h @@ -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 GetLinks() const { + return mLinkedId; + } + bool IsLinked() { return mLinkedId.size() > 0; } -- 2.47.1