+/*=========================================================================
+ 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 <qtreewidget.h>
#include <cassert>
#include <string>
+//------------------------------------------------------------------------------
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);
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()) {
+ // read images
+ 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();
}
}
+ // 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;
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
std::string vvReadState::ReadImage()
{
std::string value;
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();
}
}
else if (current_index >= 0) {
- if (value == "Fusion")
+ vvSlicerManager* slicerManager = m_Window->GetSlicerManagers()[current_index];
+ if (value == "Preset") {
+ double vali = m_XmlReader->readElementText().toInt();
+ if (!m_XmlReader->hasError())
+ slicerManager->SetPreset(vali);
+ }
+ else if (value == "Window") {
+ double vald = m_XmlReader->readElementText().toDouble();
+ if (!m_XmlReader->hasError())
+ slicerManager->SetColorWindow(vald);
+ }
+ else if (value == "Level") {
+ double vald = m_XmlReader->readElementText().toDouble();
+ if (!m_XmlReader->hasError())
+ slicerManager->SetColorLevel(vald);
+ }
+ else if (value == "Fusion")
value = ReadFusion(current_index);
else if (value == "Overlay")
value = ReadOverlay(current_index);
return value;
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
std::string vvReadState::ReadFusion(int index)
{
std::string file, value;
if (m_XmlReader->isStartElement()) {
if (value == "FileName") {
file = m_XmlReader->readElementText().toStdString();
- if (!m_XmlReader->hasError())
- m_Window->AddFusionImage(index, file.c_str());
+ if (!m_XmlReader->hasError()) {
+ // TODO: manage sequence of images
+ std::vector<std::string> vec;
+ vec.push_back(file.c_str());
+ m_Window->AddFusionImage(index, vec, vvImageReader::IMAGE);
+ }
}
if (value == "FusionOpacity") {
vali = m_XmlReader->readElementText().toInt();
m_Window->ImageInfoChanged();
return value;
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
std::string vvReadState::ReadOverlay(int index)
{
std::string file, value;
if (m_XmlReader->isStartElement()) {
if (value == "FileName") {
file = m_XmlReader->readElementText().toStdString();
- if (!m_XmlReader->hasError())
- m_Window->AddOverlayImage(index, file.c_str());
+ if (!m_XmlReader->hasError()) {
+ // TODO: manage sequence of images
+ std::vector<std::string> vec;
+ vec.push_back(file.c_str());
+ m_Window->AddOverlayImage(index, vec, vvImageReader::IMAGE);
+ }
}
if (value == "OverlayColorWindow") {
vald = m_XmlReader->readElementText().toDouble();
m_Window->ImageInfoChanged();
return value;
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
std::string vvReadState::ReadVector(int index)
{
std::string file, value;
}
return value;
}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+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()
{
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+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<vvToolBaseBase*> & 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.
+}
+//------------------------------------------------------------------------------