From: David Sarrut Date: Fri, 30 Mar 2012 13:17:48 +0000 (+0200) Subject: Add ReadTools and WriteTools X-Git-Tag: v1.3.0~52^2~12 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=2e7e0deb89d7964eaa4373168561a4e43bfc081a;p=clitk.git Add ReadTools and WriteTools --- diff --git a/vv/vvReadState.cxx b/vv/vvReadState.cxx index dafcf3f..7383ecd 100644 --- a/vv/vvReadState.cxx +++ b/vv/vvReadState.cxx @@ -1,6 +1,26 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://www.centreleonberard.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ===========================================================================**/ + #include "vvReadState.h" #include "vvMainWindow.h" #include "vvSlicerManager.h" +#include "vvToolCreatorBase.h" +#include "vvToolBaseBase.h" #include @@ -10,15 +30,22 @@ #include #include +//------------------------------------------------------------------------------ vvReadState::vvReadState() : m_XmlReader(new QXmlStreamReader), m_File(new QFile) { m_NumImages = 0; } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ vvReadState::~vvReadState() { } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvReadState::Run(vvMainWindow* vvWindow, const std::string& file) { assert(vvWindow); @@ -29,29 +56,38 @@ void vvReadState::Run(vvMainWindow* vvWindow, const std::string& file) m_XmlReader->setDevice(m_File.get()); m_Window = vvWindow; QTreeWidget* tree = m_Window->GetTree(); + + // Get the number of images already loaded m_TreeItemCount = tree->topLevelItemCount(); + // Read elements ReadGUI(); ReadTree(); + ReadTools(); } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvReadState::ReadTree() { std::string value; - while (!m_XmlReader->atEnd()) { + while (!m_XmlReader->isEndElement() || value != "Images") { m_XmlReader->readNext(); value = m_XmlReader->qualifiedName().toString().toStdString(); if (m_XmlReader->isStartElement()) { - if (value == "Image") - value = ReadImage(); + if (value == "Image") value = ReadImage(); } } if (m_XmlReader->hasError()) std::cout << "Error " << m_XmlReader->error() << " XML " << std::endl; } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ std::string vvReadState::ReadImage() { std::string value; @@ -67,7 +103,6 @@ std::string vvReadState::ReadImage() while (!m_XmlReader->isEndElement() || value != "Image") { m_XmlReader->readNext(); value = m_XmlReader->qualifiedName().toString().toStdString(); - //std::cout << "Value = " << value << std::endl; if (m_XmlReader->isStartElement()) { if (value == "FileName") { files[0] = m_XmlReader->readElementText().toStdString(); @@ -91,7 +126,10 @@ std::string vvReadState::ReadImage() return value; } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ std::string vvReadState::ReadFusion(int index) { std::string file, value; @@ -137,7 +175,10 @@ std::string vvReadState::ReadFusion(int index) m_Window->ImageInfoChanged(); return value; } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ std::string vvReadState::ReadOverlay(int index) { std::string file, value; @@ -178,7 +219,10 @@ std::string vvReadState::ReadOverlay(int index) m_Window->ImageInfoChanged(); return value; } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ std::string vvReadState::ReadVector(int index) { std::string file, value; @@ -195,9 +239,64 @@ std::string vvReadState::ReadVector(int index) } return value; } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvReadState::ReadGUI() { } +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvReadState::ReadTools() +{ + std::string value; + + while ((!m_XmlReader->hasError()) && (!m_XmlReader->isEndElement() || value != "Tools")) { + m_XmlReader->readNext(); + value = m_XmlReader->qualifiedName().toString().toStdString(); + if (value != "Tools") { + if (m_XmlReader->isStartElement()) { + ReadTool(value); + } + } + } + + if (m_XmlReader->hasError()) + std::cout << "Error " << m_XmlReader->error() << " XML " << std::endl; +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvReadState::ReadTool(const std::string & toolname) +{ + // Find name into vvToolManager::GetInstance()->GetListOfTools(); + vvToolCreatorBase * v = vvToolManager::GetInstance()->GetToolCreatorFromName(toolname.c_str()); + if (v == NULL) { + std::cerr << "Error, I do not know the tool named '" << toolname << "' ; ignored." << std::endl; + std::string value=""; + while (!m_XmlReader->isEndElement() || value != toolname) { + m_XmlReader->readNext(); + value = m_XmlReader->qualifiedName().toString().toStdString(); + if (m_XmlReader->hasError()) { + std::cout << "Error " << m_XmlReader->error() << " XML " << std::endl; + return; + } + } + return; + } + // CreateTool + // std::vector & tools = v->GetListOfTool(); + v->m_XmlReader = m_XmlReader; + v->mReadStateFlag = true; + v->mImageIndex = m_TreeItemCount; + v->MenuSpecificToolSlot(); + v->mReadStateFlag = false; + m_XmlReader = v->m_XmlReader; // Need because auto_ptr operator= release on the right. +} +//------------------------------------------------------------------------------ diff --git a/vv/vvReadState.h b/vv/vvReadState.h index 8d6d560..04607f6 100644 --- a/vv/vvReadState.h +++ b/vv/vvReadState.h @@ -21,10 +21,12 @@ protected: void ReadGUI(); void ReadTree(); - std::string ReadImage(); - std::string ReadFusion(int index); - std::string ReadOverlay(int index); - std::string ReadVector(int index); + void ReadTools(); + void ReadTool(const std::string & toolname); + std::string ReadImage(); + std::string ReadFusion(int index); + std::string ReadOverlay(int index); + std::string ReadVector(int index); std::auto_ptr m_XmlReader; std::auto_ptr m_File; diff --git a/vv/vvSaveState.cxx b/vv/vvSaveState.cxx index c1a7e49..71e22ef 100644 --- a/vv/vvSaveState.cxx +++ b/vv/vvSaveState.cxx @@ -1,5 +1,7 @@ #include "vvSaveState.h" #include "vvMainWindow.h" +#include "vvToolCreatorBase.h" +#include "vvToolBaseBase.h" #include #include @@ -10,14 +12,20 @@ #include #include +//------------------------------------------------------------------------------ vvSaveState::vvSaveState() : m_XmlWriter(new QXmlStreamWriter), m_File(new QFile) { } +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ vvSaveState::~vvSaveState() { } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvSaveState::Run(vvMainWindow* vvWindow, const std::string& file) { assert(vvWindow); @@ -36,16 +44,23 @@ void vvSaveState::Run(vvMainWindow* vvWindow, const std::string& file) SaveGlobals(); SaveGUI(); SaveTree(); + SaveTools(); m_XmlWriter->writeEndDocument(); m_XmlWriter->writeEndElement(); } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvSaveState::SaveGlobals() { m_XmlWriter->writeStartElement("Globals"); m_XmlWriter->writeEndElement(); } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvSaveState::SaveTree() { QTreeWidget* tree = m_Window->GetTree(); @@ -58,7 +73,10 @@ void vvSaveState::SaveTree() } m_XmlWriter->writeEndElement(); } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvSaveState::SaveImage(const QTreeWidgetItem* item, int index) { const vvSlicerManager * slicerManager = m_Window->GetSlicerManagers()[index]; @@ -85,9 +103,13 @@ void vvSaveState::SaveImage(const QTreeWidgetItem* item, int index) SaveVector(item_child); } + // End m_XmlWriter->writeEndElement(); } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvSaveState::SaveFusion(const QTreeWidgetItem* item, const vvSlicerManager* vvManager) { m_XmlWriter->writeStartElement("Fusion"); @@ -100,7 +122,10 @@ void vvSaveState::SaveFusion(const QTreeWidgetItem* item, const vvSlicerManager* m_XmlWriter->writeTextElement("FusionLevel", QString::number(vvManager->GetFusionLevel())); m_XmlWriter->writeEndElement(); } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvSaveState::SaveOverlay(const QTreeWidgetItem* item, const vvSlicerManager* vvManager) { m_XmlWriter->writeStartElement("Overlay"); @@ -112,7 +137,10 @@ void vvSaveState::SaveOverlay(const QTreeWidgetItem* item, const vvSlicerManager m_XmlWriter->writeTextElement("OverlayColor", QString::number(vvManager->GetOverlayColor())); m_XmlWriter->writeEndElement(); } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvSaveState::SaveVector(const QTreeWidgetItem* item) { m_XmlWriter->writeStartElement("Vector"); @@ -120,10 +148,36 @@ void vvSaveState::SaveVector(const QTreeWidgetItem* item) m_XmlWriter->writeTextElement("FileName", QDir::current().absoluteFilePath(filename.c_str())); m_XmlWriter->writeEndElement(); } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvSaveState::SaveGUI() { m_XmlWriter->writeStartElement("GUI"); m_XmlWriter->writeEndElement(); } +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvSaveState::SaveTools() +{ + m_XmlWriter->writeStartElement("Tools"); + // Check if a tool is open and need to be store + std::vector & v = vvToolManager::GetInstance()->GetListOfTools(); + for(uint i=0; i & t = v[i]->GetListOfTool(); + for(uint j=0; jmToolName.toStdString(); + m_XmlWriter->writeStartElement(name.c_str()); + m_XmlWriter->writeTextElement("ToolType_Index", QString::number(i)); + m_XmlWriter->writeTextElement("Tool_Index", QString::number(j)); + t[j]->SaveState(m_XmlWriter); + m_XmlWriter->writeEndElement(); + } + } + m_XmlWriter->writeEndElement(); +} +//------------------------------------------------------------------------------ diff --git a/vv/vvSaveState.h b/vv/vvSaveState.h index 2991580..29a0e40 100644 --- a/vv/vvSaveState.h +++ b/vv/vvSaveState.h @@ -23,6 +23,7 @@ protected: void SaveGlobals(); void SaveGUI(); void SaveTree(); + void SaveTools(); void SaveImage(const QTreeWidgetItem* item, int index); void SaveFusion(const QTreeWidgetItem* item, const vvSlicerManager* slicerManager); void SaveOverlay(const QTreeWidgetItem* item, const vvSlicerManager* slicerManager);