removed crash on loading picked points from a file.

This commit is contained in:
Guido Ranzuglia granzuglia 2010-07-02 10:21:34 +00:00
parent b90783d20e
commit 0e996ee1db
2 changed files with 100 additions and 97 deletions

View File

@ -19,100 +19,100 @@
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
/* A class representing a set of point names that is used
* as a template a user can fill out to create a PickedPoints
*
*
* @author Oscar Barney
*/
#include "pickPointsTemplate.h"
#include <QtGui>
//xml stuff
#include <QtXml/QDomDocument>
#include <QtXml/QDomElement>
#include <QtXml/QDomNode>
//Define Constants
const QString PickPointsTemplate::fileExtension = ".pptpl";
const QString PickPointsTemplate::rootName = "PickPointsTemplate";
const QString PickPointsTemplate::pointElementName = "point";
const QString PickPointsTemplate::pointName = "name";
bool PickPointsTemplate::save(QString filename,
std::vector<QString> *pointNameVector){
QDomDocument doc(rootName);
QDomElement root = doc.createElement(rootName);
doc.appendChild(root);
//create an element for each point
for (int i = 0; i < pointNameVector->size(); ++i) {
QString name = pointNameVector->at(i);
QDomElement tag = doc.createElement(pointElementName);
tag.setAttribute(pointName, name);
//append the element to the root
root.appendChild(tag);
}
//create a file and write the data
QFile file(filename);
file.open(QIODevice::WriteOnly);
QTextStream qstream(&file);
doc.save(qstream,1);
file.close();
return true;
}
bool PickPointsTemplate::load(QString filename,
std::vector<QString> *pointNameVector){
QDomDocument doc;
pointNameVector->clear();
QFile file(filename);
QString errorMessage;
if (file.open(QIODevice::ReadOnly) && doc.setContent(&file, &errorMessage))
{
file.close();
QDomElement root = doc.documentElement();
if (root.nodeName() == rootName)
{
qDebug() << "About to read a " << rootName << " xml document";
for(QDomElement element = root.firstChildElement(pointElementName);
!element.isNull();
element = element.nextSiblingElement(pointElementName))
{
QString name = element.attribute(pointName);
qDebug() << "Reading point with name " << name;
pointNameVector->push_back(name);
}
} else {
//file is of unknown type
qDebug() << "Failed, tried to read a " << rootName << " xml document";
return false;
}
} else {
// problem opening the file
qDebug() << "problem reading from the file, setContent error: " << errorMessage;
return false;
}
return true;
}
QString PickPointsTemplate::getDefaultTemplateFileName()
{
return QDir::homePath() + "/.pickPointsTemplate" + fileExtension;
}
****************************************************************************/
/* A class representing a set of point names that is used
* as a template a user can fill out to create a PickedPoints
*
*
* @author Oscar Barney
*/
#include "pickPointsTemplate.h"
#include <QtGui>
//xml stuff
#include <QtXml/QDomDocument>
#include <QtXml/QDomElement>
#include <QtXml/QDomNode>
//Define Constants
const QString PickPointsTemplate::fileExtension = ".pptpl";
const QString PickPointsTemplate::rootName = "PickPointsTemplate";
const QString PickPointsTemplate::pointElementName = "point";
const QString PickPointsTemplate::pointName = "name";
bool PickPointsTemplate::save(QString filename,
std::vector<QString> *pointNameVector){
QDomDocument doc(rootName);
QDomElement root = doc.createElement(rootName);
doc.appendChild(root);
//create an element for each point
for (int i = 0; i < pointNameVector->size(); ++i) {
QString name = pointNameVector->at(i);
QDomElement tag = doc.createElement(pointElementName);
tag.setAttribute(pointName, name);
//append the element to the root
root.appendChild(tag);
}
//create a file and write the data
QFile file(filename);
file.open(QIODevice::WriteOnly);
QTextStream qstream(&file);
doc.save(qstream,1);
file.close();
return true;
}
bool PickPointsTemplate::load(QString filename,
std::vector<QString> *pointNameVector){
QDomDocument doc;
pointNameVector->clear();
QFile file(filename);
QString errorMessage;
if (file.open(QIODevice::ReadOnly) && doc.setContent(&file, &errorMessage))
{
file.close();
QDomElement root = doc.documentElement();
if (root.nodeName() == rootName)
{
qDebug() << "About to read a " << rootName << " xml document";
for(QDomElement element = root.firstChildElement(pointElementName);
!element.isNull();
element = element.nextSiblingElement(pointElementName))
{
QString name = element.attribute(pointName);
qDebug() << "Reading point with name " << name;
pointNameVector->push_back(name);
}
} else {
//file is of unknown type
qDebug() << "Failed, tried to read a " << rootName << " xml document";
return false;
}
} else {
// problem opening the file
qDebug() << "problem reading from the file, setContent error: " << errorMessage;
return false;
}
return true;
}
QString PickPointsTemplate::getDefaultTemplateFileName()
{
return QDir::homePath() + "/.pickPointsTemplate" + fileExtension;
}

View File

@ -380,6 +380,8 @@ bool PickPointsDialog::drawNormalAsPin()
void PickPointsDialog::addPoint(vcg::Point3f &point, QString &name, bool present)
{
//bool result = GLPickTri<CMeshO>::PickNearestFace(currentMousePosition.x(),gla->height()-currentMousePosition.y(),
// mm.cm, face);
CMeshO::FaceType *face = 0;
//qDebug() << "present: " << present;
@ -736,6 +738,7 @@ PickedPoints * PickPointsDialog::getPickedPoints()
}
void PickPointsDialog::loadPoints(QString filename){
vcg::tri::UpdateFlags<CMeshO>::FaceProjection(meshModel->cm);
//clear the points tree and template in case it was loaded
clearTemplate();