+/*=========================================================================
+ 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()) {
+ 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;
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();
return value;
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
std::string vvReadState::ReadFusion(int index)
{
std::string file, value;
m_Window->ImageInfoChanged();
return value;
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
std::string vvReadState::ReadOverlay(int index)
{
std::string file, value;
m_Window->ImageInfoChanged();
return value;
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
std::string vvReadState::ReadVector(int index)
{
std::string file, value;
}
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.
+}
+//------------------------------------------------------------------------------
#include "vvSaveState.h"
#include "vvMainWindow.h"
+#include "vvToolCreatorBase.h"
+#include "vvToolBaseBase.h"
#include <QDir>
#include <QFile>
#include <cassert>
#include <string>
+//------------------------------------------------------------------------------
vvSaveState::vvSaveState() : m_XmlWriter(new QXmlStreamWriter), m_File(new QFile)
{
}
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
vvSaveState::~vvSaveState()
{
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
void vvSaveState::Run(vvMainWindow* vvWindow, const std::string& file)
{
assert(vvWindow);
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();
}
m_XmlWriter->writeEndElement();
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
void vvSaveState::SaveImage(const QTreeWidgetItem* item, int index)
{
const vvSlicerManager * slicerManager = m_Window->GetSlicerManagers()[index];
SaveVector(item_child);
}
+ // End
m_XmlWriter->writeEndElement();
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
void vvSaveState::SaveFusion(const QTreeWidgetItem* item, const vvSlicerManager* vvManager)
{
m_XmlWriter->writeStartElement("Fusion");
m_XmlWriter->writeTextElement("FusionLevel", QString::number(vvManager->GetFusionLevel()));
m_XmlWriter->writeEndElement();
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
void vvSaveState::SaveOverlay(const QTreeWidgetItem* item, const vvSlicerManager* vvManager)
{
m_XmlWriter->writeStartElement("Overlay");
m_XmlWriter->writeTextElement("OverlayColor", QString::number(vvManager->GetOverlayColor()));
m_XmlWriter->writeEndElement();
}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
void vvSaveState::SaveVector(const QTreeWidgetItem* item)
{
m_XmlWriter->writeStartElement("Vector");
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<vvToolCreatorBase *> & v = vvToolManager::GetInstance()->GetListOfTools();
+ for(uint i=0; i<v.size(); i++) {
+ std::vector<vvToolBaseBase*> & t = v[i]->GetListOfTool();
+ for(uint j=0; j<t.size(); j++) {
+ std::string name = v[i]->mToolName.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();
+}
+//------------------------------------------------------------------------------