X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvReadState.cxx;fp=vv%2FvvReadState.cxx;h=6ad544b17f990bb65d134ccc2c3af1ad30e5bcc0;hb=acdc20ec4afc95db1db29bf8d885a3b72c9c7ee0;hp=0000000000000000000000000000000000000000;hpb=3de84bda64063da470fb7a12abd38c98ed14bfd3;p=clitk.git diff --git a/vv/vvReadState.cxx b/vv/vvReadState.cxx new file mode 100644 index 0000000..6ad544b --- /dev/null +++ b/vv/vvReadState.cxx @@ -0,0 +1,144 @@ +#include "vvReadState.h" +#include "vvMainWindow.h" + +#include + +#include +#include + +#include +#include + +vvReadState::vvReadState() : m_XmlReader(new QXmlStreamReader), m_File(new QFile) +{ +} + +vvReadState::~vvReadState() +{ +} + +void vvReadState::Run(vvMainWindow* vvWindow, const std::string& file) +{ + assert(vvWindow); + + m_File->setFileName(file.c_str()); + m_File->open(QIODevice::ReadOnly); + m_XmlReader->setDevice(m_File.get()); + m_Window = vvWindow; + QTreeWidget* tree = m_Window->GetTree(); + m_TreeItemCount = tree->topLevelItemCount(); + + ReadGUI(); + ReadTree(); +} + +void vvReadState::ReadTree() +{ + std::string value; + + while (!m_XmlReader->atEnd()) { + m_XmlReader->readNext(); + value = m_XmlReader->qualifiedName().toString().toStdString(); + if (m_XmlReader->isStartElement()) { + 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; + int current_index = -1; + std::vector files(1); + + QXmlStreamAttributes attributes = m_XmlReader->attributes(); + if (!m_XmlReader->hasError()) + current_index = attributes.value("Index").toString().toInt(); + + current_index += m_TreeItemCount; + + 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(); + if (!m_XmlReader->hasError()) { + m_Window->LoadImages(files, vvImageReader::IMAGE); + } + } + else if (current_index >= 0) { + if (value == "Fusion") + value = ReadFusion(current_index); + else if (value == "Overlay") + value = ReadOverlay(current_index); + else if (value == "Vector") + value = ReadVector(current_index); + } + } + } + + return value; +} + +std::string vvReadState::ReadFusion(int index) +{ + std::string file, value; + while (!m_XmlReader->isEndElement() || value != "Fusion") { + m_XmlReader->readNext(); + value = m_XmlReader->qualifiedName().toString().toStdString(); + if (m_XmlReader->isStartElement()) { + if (value == "FileName") { + file = m_XmlReader->readElementText().toStdString(); + if (!m_XmlReader->hasError()) + m_Window->AddFusionImage(index, file.c_str()); + } + } + } + return value; +} + +std::string vvReadState::ReadOverlay(int index) +{ + std::string file, value; + while (!m_XmlReader->isEndElement() || value != "Overlay") { + m_XmlReader->readNext(); + value = m_XmlReader->qualifiedName().toString().toStdString(); + if (m_XmlReader->isStartElement()) { + if (value == "FileName") { + file = m_XmlReader->readElementText().toStdString(); + if (!m_XmlReader->hasError()) + m_Window->AddOverlayImage(index, file.c_str()); + } + } + } + return value; +} + +std::string vvReadState::ReadVector(int index) +{ + std::string file, value; + while (!m_XmlReader->isEndElement() || value != "Vector") { + m_XmlReader->readNext(); + value = m_XmlReader->qualifiedName().toString().toStdString(); + if (m_XmlReader->isStartElement()) { + if (value == "FileName") { + file = m_XmlReader->readElementText().toStdString(); + if (!m_XmlReader->hasError()) + m_Window->AddField(file.c_str(), index); + } + } + } + return value; +} + +void vvReadState::ReadGUI() +{ + +} +