Added support exception for some situations.

This commit is contained in:
dismine 2013-09-23 15:08:06 +03:00
parent 91744b39b7
commit 1b7fc8df85
19 changed files with 1212 additions and 336 deletions

View File

@ -87,7 +87,14 @@ SOURCES += main.cpp\
tools/modelingTools/vmodelingpointofcontact.cpp \
tools/modelingTools/vmodelingshoulderpoint.cpp \
tools/modelingTools/vmodelingspline.cpp \
tools/modelingTools/vmodelingsplinepath.cpp
tools/modelingTools/vmodelingsplinepath.cpp \
exception/vexception.cpp \
exception/vexceptionbadid.cpp \
exception/vexceptionwrongparameterid.cpp \
exception/vexceptionconversionerror.cpp \
exception/vexceptionemptyparameter.cpp \
exception/vexceptionobjecterror.cpp \
widgets/vapplication.cpp
HEADERS += mainwindow.h \
widgets/vmaingraphicsscene.h \
@ -170,7 +177,14 @@ HEADERS += mainwindow.h \
tools/modelingTools/vmodelingpointofcontact.h \
tools/modelingTools/vmodelingshoulderpoint.h \
tools/modelingTools/vmodelingspline.h \
tools/modelingTools/vmodelingsplinepath.h
tools/modelingTools/vmodelingsplinepath.h \
exception/vexception.h \
exception/vexceptionbadid.h \
exception/vexceptionwrongparameterid.h \
exception/vexceptionconversionerror.h \
exception/vexceptionemptyparameter.h \
exception/vexceptionobjecterror.h \
widgets/vapplication.h
FORMS += mainwindow.ui \
dialogs/dialogsinglepoint.ui \

View File

@ -22,6 +22,7 @@
#include "vcontainer.h"
#include <QDebug>
#include "options.h"
#include <exception/vexceptionbadid.h>
qint64 VContainer::_id = 0;
@ -80,8 +81,7 @@ val VContainer::GetObject(const QMap<key,val> &obj, key id){
if(obj.contains(id)){
return obj.value(id);
} else {
qCritical()<<"Не можу знайти key = "<<id<<" в таблиці.";
throw"Не можу знайти об'єкт за ключем.";
throw VExceptionBadId(tr("Can't find object"), id);
}
}

View File

@ -33,12 +33,14 @@
#include "geometry/vsplinepath.h"
#include "geometry/vdetail.h"
#include "widgets/vitem.h"
#include <QCoreApplication>
/**
* @brief The VContainer class
*/
class VContainer
{
Q_DECLARE_TR_FUNCTIONS(VContainer)
public:
/**
* @brief VContainer

34
exception/vexception.cpp Normal file
View File

@ -0,0 +1,34 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vexception.h"
VException::VException(const QString &what):QException(), what(what){
Q_ASSERT_X(!what.isEmpty(), Q_FUNC_INFO, "Error message is empty");
}
VException::VException(const VException &e):what(e.What()){
}
QString VException::ErrorMessage() const{
QString error = QString("Exception: %1").arg(what);
return error;
}

44
exception/vexception.h Normal file
View File

@ -0,0 +1,44 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef VEXCEPTION_H
#define VEXCEPTION_H
#include <QException>
#include <QString>
class VException : public QException
{
public:
VException(const QString &what);
VException(const VException &e);
virtual ~VException() noexcept(true){}
void raise() const { throw *this; }
VException *clone() const { return new VException(*this); }
virtual QString ErrorMessage() const;
virtual QString DetailedInformation() const { return QString(); }
QString What() const {return what;}
protected:
QString what;
};
#endif // VEXCEPTION_H

View File

@ -0,0 +1,44 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vexceptionbadid.h"
VExceptionBadId::VExceptionBadId(const QString &what, const qint64 &id):VException(what), id(id),
key(QString()){
}
VExceptionBadId::VExceptionBadId(const QString &what, const QString &key):VException(what), id(0), key(key)
{
}
VExceptionBadId::VExceptionBadId(const VExceptionBadId &e):VException(e), id(e.BadId()), key(e.BadKey()){
}
QString VExceptionBadId::ErrorMessage() const{
QString error;
if(key.isEmpty()){
error = QString("ExceptionBadId: %1, id = %2").arg(what).arg(id);
} else {
error = QString("ExceptionBadId: %1, id = %2").arg(what).arg(key);
}
return error;
}

View File

@ -0,0 +1,42 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef VEXCEPTIONBADID_H
#define VEXCEPTIONBADID_H
#include "vexception.h"
class VExceptionBadId : public VException
{
public:
VExceptionBadId(const QString &what, const qint64 &id);
VExceptionBadId(const QString &what, const QString &key);
VExceptionBadId(const VExceptionBadId &e);
virtual ~VExceptionBadId() noexcept(true){}
virtual QString ErrorMessage() const;
qint64 BadId() const {return id; }
QString BadKey() const {return key; }
protected:
qint64 id;
QString key;
};
#endif // VEXCEPTIONBADID_H

View File

@ -0,0 +1,36 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vexceptionconversionerror.h"
VExceptionConversionError::VExceptionConversionError(const QString &what, const QString &str)
:VException(what), str(str){
Q_ASSERT_X(!str.isEmpty(), Q_FUNC_INFO, "Error converting string is empty");
}
VExceptionConversionError::VExceptionConversionError(const VExceptionConversionError &e):
VException(e), str(e.String()){
}
QString VExceptionConversionError::ErrorMessage() const{
QString error = QString("ExceptionConversionError: %1 %2").arg(what, str);
return error;
}

View File

@ -0,0 +1,39 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef VEXCEPTIONCONVERSIONERROR_H
#define VEXCEPTIONCONVERSIONERROR_H
#include "vexception.h"
class VExceptionConversionError : public VException
{
public:
VExceptionConversionError(const QString &what, const QString &str);
VExceptionConversionError(const VExceptionConversionError &e);
virtual ~VExceptionConversionError() noexcept(true) {}
virtual QString ErrorMessage() const;
QString String() const {return str;}
protected:
QString str;
};
#endif // VEXCEPTIONCONVERSIONERROR_H

View File

@ -0,0 +1,50 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vexceptionemptyparameter.h"
#include <QDebug>
VExceptionEmptyParameter::VExceptionEmptyParameter(const QString &what, const QString &name,
const QDomElement &domElement): VException(what), name(name),
tagText(QString()), tagName(QString()), lineNumber(-1){
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "Parameter name is empty");
if(domElement.isText()){
QDomText text = domElement.toText();
tagText = text.data();
}
tagName = domElement.tagName();
lineNumber = domElement.lineNumber();
}
VExceptionEmptyParameter::VExceptionEmptyParameter(const VExceptionEmptyParameter &e):VException(e),
name(e.Name()), tagName(e.TagName()), tagText(e.TagText()), lineNumber(e.LineNumber()){
}
QString VExceptionEmptyParameter::ErrorMessage() const{
QString error = QString("ExceptionEmptyParameter: %1 %2").arg(what, name);
return error;
}
QString VExceptionEmptyParameter::DetailedInformation() const{
QString detail = QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText);
return detail;
}

View File

@ -0,0 +1,47 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef VEXCEPTIONEMPTYPARAMETER_H
#define VEXCEPTIONEMPTYPARAMETER_H
#include "vexception.h"
#include "QDomElement"
class VExceptionEmptyParameter : public VException
{
public:
VExceptionEmptyParameter(const QString &what, const QString &name, const QDomElement &domElement);
VExceptionEmptyParameter(const VExceptionEmptyParameter &e);
virtual ~VExceptionEmptyParameter() noexcept(true) {}
virtual QString ErrorMessage() const;
virtual QString DetailedInformation() const;
QString Name() const {return name;}
QString TagText() const {return tagText;}
QString TagName() const {return tagName;}
qint32 LineNumber() const {return lineNumber;}
protected:
QString name;
QString tagText;
QString tagName;
qint32 lineNumber;
};
#endif // VEXCEPTIONEMPTYPARAMETER_H

View File

@ -0,0 +1,61 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vexceptionobjecterror.h"
#include <QDebug>
VExceptionObjectError::VExceptionObjectError(const QString &what, const QDomElement &domElement):
VException(what), tagText(QString()), tagName(QString()), lineNumber(-1), moreInfo(QString()){
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
if(domElement.isText()){
QDomText text = domElement.toText();
tagText = text.data();
}
tagName = domElement.tagName();
lineNumber = domElement.lineNumber();
}
VExceptionObjectError::VExceptionObjectError(const VExceptionObjectError &e):VException(e),
tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()), moreInfo(e.MoreInformation()){
}
QString VExceptionObjectError::ErrorMessage() const{
QString error = QString("ExceptionObjectError: %1").arg(what);
return error;
}
QString VExceptionObjectError::DetailedInformation() const{
QString detail;
if(!moreInfo.isEmpty()){
QString i = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText);
detail = QString("%1\n%2").arg(moreInfo, i);
} else {
detail = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText);
}
return detail;
}
void VExceptionObjectError::AddMoreInformation(const QString &info){
if(info.isEmpty()){
qWarning()<<"Error additional information is empty."<<Q_FUNC_INFO;
}
this->moreInfo.append(info);
}

View File

@ -0,0 +1,48 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef VEXCEPTIONOBJECTERROR_H
#define VEXCEPTIONOBJECTERROR_H
#include "vexception.h"
#include <QDomElement>
class VExceptionObjectError : public VException
{
public:
VExceptionObjectError(const QString &what, const QDomElement &domElement);
VExceptionObjectError(const VExceptionObjectError &e);
virtual ~VExceptionObjectError() noexcept(true) {}
virtual QString ErrorMessage() const;
virtual QString DetailedInformation() const;
QString TagText() const {return tagText;}
QString TagName() const {return tagName;}
qint32 LineNumber() const {return lineNumber;}
void AddMoreInformation(const QString &info);
QString MoreInformation() const {return moreInfo;}
protected:
QString tagText;
QString tagName;
qint32 lineNumber;
QString moreInfo;
};
#endif // VEXCEPTIONOBJECTERROR_H

View File

@ -0,0 +1,48 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vexceptionwrongparameterid.h"
#include <QDebug>
VExceptionWrongParameterId::VExceptionWrongParameterId(const QString &what, const QDomElement &domElement):
VException(what), tagText(QString()), tagName(QString()), lineNumber(-1){
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
if(domElement.isText()){
QDomText text = domElement.toText();
tagText = text.data();
}
tagName = domElement.tagName();
lineNumber = domElement.lineNumber();
}
VExceptionWrongParameterId::VExceptionWrongParameterId(const VExceptionWrongParameterId &e):VException(e),
tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()){
}
QString VExceptionWrongParameterId::ErrorMessage() const{
QString error = QString("ExceptionWrongParameterId: %1").arg(what);
return error;
}
QString VExceptionWrongParameterId::DetailedInformation() const{
QString detail = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText);
return detail;
}

View File

@ -0,0 +1,45 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef VEXCEPTIONWRONGPARAMETERID_H
#define VEXCEPTIONWRONGPARAMETERID_H
#include "vexception.h"
#include <QDomElement>
class VExceptionWrongParameterId : public VException
{
public:
VExceptionWrongParameterId(const QString &what, const QDomElement &domElement);
VExceptionWrongParameterId(const VExceptionWrongParameterId &e);
virtual ~VExceptionWrongParameterId() noexcept(true){}
virtual QString ErrorMessage() const;
virtual QString DetailedInformation() const;
QString TagText() const {return tagText;}
QString TagName() const {return tagName;}
qint32 LineNumber() const {return lineNumber;}
protected:
QString tagText;
QString tagName;
qint32 lineNumber;
};
#endif // VEXCEPTIONWRONGPARAMETERID_H

View File

@ -30,6 +30,11 @@
#include <QFileDialog>
#include <QDebug>
#include "geometry/vspline.h"
#include <QMessageBox>
#include "exception/vexceptionobjecterror.h"
#include "exception/vexceptionconversionerror.h"
#include "exception/vexceptionemptyparameter.h"
#include "exception/vexceptionwrongparameterid.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow), tool(Tools::ArrowTool), currentScene(0), sceneDraw(0),
@ -732,17 +737,68 @@ void MainWindow::ActionOpen(){
QString fName = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter);
if(fName.isEmpty())
return;
fileName = fName;
QFileInfo info(fileName);
QString title(info.fileName());
title.append("-Valentina");
setWindowTitle(title);
QFile file(fileName);
QFile file(fName);
QString errorMsg;
qint32 errorLine = 0;
qint32 errorColumn = 0;
if(file.open(QIODevice::ReadOnly)){
if(doc->setContent(&file)){
if(doc->setContent(&file, &errorMsg, &errorLine, &errorColumn)){
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
try{
doc->Parse(Document::FullParse, sceneDraw, sceneDetails);
}
catch(const VExceptionObjectError &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error parsing file."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setDetailedText(e.DetailedInformation());
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
file.close();
return;
}
catch(const VExceptionConversionError &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error can't convert value."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
file.close();
return;
}
catch(const VExceptionEmptyParameter &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error empty parameter."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setDetailedText(e.DetailedInformation());
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
file.close();
return;
}
catch(const VExceptionWrongParameterId &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error wrong id."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setDetailedText(e.DetailedInformation());
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
file.close();
return;
}
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged);
QString nameDraw = doc->GetNameActivDraw();
@ -756,9 +812,26 @@ void MainWindow::ActionOpen(){
SetEnableTool(false);
}
SetEnableWidgets(true);
} else {
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error parsing pattern file."));
msgBox.setInformativeText(errorMsg);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
QString error = QString(tr("Error in line %1 column %2")).arg(errorLine, errorColumn);
msgBox.setDetailedText(error);
msgBox.exec();
file.close();
return;
}
file.close();
}
fileName = fName;
QFileInfo info(fileName);
QString title(info.fileName());
title.append("-Valentina");
setWindowTitle(title);
}
void MainWindow::ActionNew(){

102
widgets/vapplication.cpp Normal file
View File

@ -0,0 +1,102 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vapplication.h"
#include <QtGui>
#include <QMessageBox>
#include "exception/vexceptionobjecterror.h"
#include "exception/vexceptionbadid.h"
#include "exception/vexceptionconversionerror.h"
#include "exception/vexceptionemptyparameter.h"
#include "exception/vexceptionwrongparameterid.h"
VApplication::VApplication(int & argc, char ** argv) :
QApplication(argc, argv){
}
// reimplemented from QApplication so we can throw exceptions in slots
bool VApplication::notify(QObject *receiver, QEvent *event){
try {
return QApplication::notify(receiver, event);
}
catch(const VExceptionObjectError &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error parsing file. Program will be terminated."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setDetailedText(e.DetailedInformation());
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
abort();
}
catch(const VExceptionBadId &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error bad id. Program will be terminated."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
abort();
}
catch(const VExceptionConversionError &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error can't convert value. Program will be terminated."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
abort();
}
catch(const VExceptionEmptyParameter &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error empty parameter. Program will be terminated."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setDetailedText(e.DetailedInformation());
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
abort();
}
catch(const VExceptionWrongParameterId &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error wrong id. Program will be terminated."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setDetailedText(e.DetailedInformation());
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
abort();
}
catch(std::exception& e) {
qCritical() << "Exception thrown:" << e.what();
}
return false;
}

15
widgets/vapplication.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef VAPPLICATION_H
#define VAPPLICATION_H
#include <QApplication>
class VApplication : public QApplication
{
Q_OBJECT
public:
VApplication(int &argc, char ** argv);
virtual ~VApplication() { }
virtual bool notify(QObject * receiver, QEvent * event);
};
#endif // VAPPLICATION_H

View File

@ -28,7 +28,11 @@
#include "options.h"
#include "container/calculator.h"
#include "geometry/vsplinepoint.h"
#include "exception/vexceptionwrongparameterid.h"
#include "exception/vexceptionconversionerror.h"
#include "exception/vexceptionemptyparameter.h"
#include "exception/vexceptionbadid.h"
#include "exception/vexceptionobjecterror.h"
VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Mode *mode) : QDomDocument(),
@ -324,8 +328,11 @@ void VDomDocument::ParseIncrementsElement(const QDomNode &node){
}
qint64 VDomDocument::GetParametrId(const QDomElement &domElement) const{
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
qint64 id = GetParametrLongLong(domElement, "id");
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
if(id <= 0){
throw VExceptionWrongParameterId(tr("Got wrong parameter id. Need only id > 0."), domElement);
}
return id;
}
@ -335,20 +342,20 @@ qint64 VDomDocument::GetParametrLongLong(const QDomElement &domElement, const QS
bool ok = false;
QString parametr = GetParametrString(domElement, name);
qint64 id = parametr.toLongLong(&ok);
QString error("can't convert parametr ");
error.append(name);
Q_ASSERT_X(ok, Q_FUNC_INFO, error.toLatin1().data());
if(ok == false){
throw VExceptionConversionError(tr("Can't convert toLongLong parameter"), name);
}
return id;
}
QString VDomDocument::GetParametrString(const QDomElement &domElement, const QString &name) const{
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
QString parametr = domElement.attribute(name, "");
QString error("get empty parametr ");
error.append(name);
Q_ASSERT_X(!parametr.isEmpty(), Q_FUNC_INFO, error.toLatin1().data());
return parametr;
QString parameter = domElement.attribute(name, "");
if(parameter.isEmpty()){
throw VExceptionEmptyParameter(tr("Got empty parameter"), name, domElement);
}
return parameter;
}
qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QString &name) const{
@ -357,9 +364,9 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri
bool ok = false;
QString parametr = GetParametrString(domElement, name);
qreal param = parametr.toDouble(&ok);
QString error("can't convert parametr ");
error.append(name);
Q_ASSERT_X(ok, Q_FUNC_INFO, error.toLatin1().data());
if(ok == false){
throw VExceptionConversionError(tr("Can't convert toDouble parameter"), name);
}
return param;
}
@ -423,72 +430,79 @@ void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDo
Document::Enum parse){
Q_CHECK_PTR(sceneDetail);
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
VDetail detail;
VDetail oldDetail;
qint64 id = GetParametrId(domElement);
detail.setName(GetParametrString(domElement, "name"));
detail.setMx(toPixel(GetParametrDouble(domElement, "mx")));
detail.setMy(toPixel(GetParametrDouble(domElement, "my")));
try{
VDetail detail;
VDetail oldDetail;
qint64 id = GetParametrId(domElement);
detail.setName(GetParametrString(domElement, "name"));
detail.setMx(toPixel(GetParametrDouble(domElement, "mx")));
detail.setMy(toPixel(GetParametrDouble(domElement, "my")));
QDomNodeList nodeList = domElement.childNodes();
qint32 num = nodeList.size();
for(qint32 i = 0; i < num; ++i){
QDomElement element = nodeList.at(i).toElement();
if(!element.isNull()){
if(element.tagName() == "node"){
qint64 id = GetParametrLongLong(element, "idObject");
Tools::Enum tool;
Draw::Mode mode;
NodeDetail::Type nodeType = NodeDetail::Contour;
QString t = GetParametrString(element, "type");
if(t == "NodePoint"){
tool = Tools::NodePoint;
VPointF point = data->GetModelingPoint(id);
mode = point.getMode();
oldDetail.append(VNodeDetail(point.getIdObject(), tool, mode, NodeDetail::Contour));
} else if(t == "NodeArc"){
tool = Tools::NodeArc;
VArc arc = data->GetModelingArc(id);
mode = arc.getMode();
oldDetail.append(VNodeDetail(arc.getIdObject(), tool, mode, NodeDetail::Contour));
} else if(t == "NodeSpline"){
tool = Tools::NodeSpline;
VSpline spl = data->GetModelingSpline(id);
mode = spl.getMode();
oldDetail.append(VNodeDetail(spl.getIdObject(), tool, mode, NodeDetail::Contour));
} else if(t == "NodeSplinePath"){
tool = Tools::NodeSplinePath;
VSplinePath splPath = data->GetModelingSplinePath(id);
mode = splPath.getMode();
oldDetail.append(VNodeDetail(splPath.getIdObject(), tool, mode, NodeDetail::Contour));
} else if(t == "AlongLineTool"){
tool = Tools::AlongLineTool;
} else if(t == "ArcTool"){
tool = Tools::ArcTool;
} else if(t == "BisectorTool"){
tool = Tools::BisectorTool;
} else if(t == "EndLineTool"){
tool = Tools::EndLineTool;
} else if(t == "LineIntersectTool"){
tool = Tools::LineIntersectTool;
} else if(t == "LineTool"){
tool = Tools::LineTool;
} else if(t == "NormalTool"){
tool = Tools::NormalTool;
} else if(t == "PointOfContact"){
tool = Tools::PointOfContact;
} else if(t == "ShoulderPointTool"){
tool = Tools::ShoulderPointTool;
} else if(t == "SplinePathTool"){
tool = Tools::SplinePathTool;
} else if(t == "SplineTool"){
tool = Tools::SplineTool;
QDomNodeList nodeList = domElement.childNodes();
qint32 num = nodeList.size();
for(qint32 i = 0; i < num; ++i){
QDomElement element = nodeList.at(i).toElement();
if(!element.isNull()){
if(element.tagName() == "node"){
qint64 id = GetParametrLongLong(element, "idObject");
Tools::Enum tool;
Draw::Mode mode;
NodeDetail::Type nodeType = NodeDetail::Contour;
QString t = GetParametrString(element, "type");
if(t == "NodePoint"){
tool = Tools::NodePoint;
VPointF point = data->GetModelingPoint(id);
mode = point.getMode();
oldDetail.append(VNodeDetail(point.getIdObject(), tool, mode, NodeDetail::Contour));
} else if(t == "NodeArc"){
tool = Tools::NodeArc;
VArc arc = data->GetModelingArc(id);
mode = arc.getMode();
oldDetail.append(VNodeDetail(arc.getIdObject(), tool, mode, NodeDetail::Contour));
} else if(t == "NodeSpline"){
tool = Tools::NodeSpline;
VSpline spl = data->GetModelingSpline(id);
mode = spl.getMode();
oldDetail.append(VNodeDetail(spl.getIdObject(), tool, mode, NodeDetail::Contour));
} else if(t == "NodeSplinePath"){
tool = Tools::NodeSplinePath;
VSplinePath splPath = data->GetModelingSplinePath(id);
mode = splPath.getMode();
oldDetail.append(VNodeDetail(splPath.getIdObject(), tool, mode, NodeDetail::Contour));
} else if(t == "AlongLineTool"){
tool = Tools::AlongLineTool;
} else if(t == "ArcTool"){
tool = Tools::ArcTool;
} else if(t == "BisectorTool"){
tool = Tools::BisectorTool;
} else if(t == "EndLineTool"){
tool = Tools::EndLineTool;
} else if(t == "LineIntersectTool"){
tool = Tools::LineIntersectTool;
} else if(t == "LineTool"){
tool = Tools::LineTool;
} else if(t == "NormalTool"){
tool = Tools::NormalTool;
} else if(t == "PointOfContact"){
tool = Tools::PointOfContact;
} else if(t == "ShoulderPointTool"){
tool = Tools::ShoulderPointTool;
} else if(t == "SplinePathTool"){
tool = Tools::SplinePathTool;
} else if(t == "SplineTool"){
tool = Tools::SplineTool;
}
detail.append(VNodeDetail(id, tool, mode, nodeType));
}
detail.append(VNodeDetail(id, tool, mode, nodeType));
}
}
VToolDetail::Create(id, detail, oldDetail, sceneDetail, this, data, parse, Tool::FromFile);
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating detail"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
VToolDetail::Create(id, detail, oldDetail, sceneDetail, this, data, parse, Tool::FromFile);
}
void VDomDocument::ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement,
@ -515,175 +529,238 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of point is empty");
if(type == "single"){
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal x = toPixel(GetParametrDouble(domElement, "x"));
qreal y = toPixel(GetParametrDouble(domElement, "y"));
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal x = toPixel(GetParametrDouble(domElement, "x"));
qreal y = toPixel(GetParametrDouble(domElement, "y"));
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
data->UpdatePoint(id, VPointF(x, y, name, mx, my));
VDrawTool::AddRecord(id, Tools::SinglePointTool, this);
if(parse != Document::FullParse){
UpdateToolData(id, data);
data->UpdatePoint(id, VPointF(x, y, name, mx, my));
VDrawTool::AddRecord(id, Tools::SinglePointTool, this);
if(parse != Document::FullParse){
UpdateToolData(id, data);
}
if(parse == Document::FullParse){
VToolSinglePoint *spoint = new VToolSinglePoint(this, data, id, Tool::FromFile);
Q_CHECK_PTR(spoint);
scene->addItem(spoint);
connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
tools[id] = spoint;
}
return;
}
if(parse == Document::FullParse){
VToolSinglePoint *spoint = new VToolSinglePoint(this, data, id, Tool::FromFile);
Q_CHECK_PTR(spoint);
scene->addItem(spoint);
connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
tools[id] = spoint;
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating single point"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
if(type == "endLine"){
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
QString typeLine = GetParametrString(domElement, "typeLine");
QString formula = GetParametrString(domElement, "length");
qint64 basePointId = GetParametrLongLong(domElement, "basePoint");
qreal angle = GetParametrDouble(domElement, "angle");
if(mode == Draw::Calculation){
VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, scene, this,
data, parse, Tool::FromFile);
} else {
VModelingEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, this,
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
QString typeLine = GetParametrString(domElement, "typeLine");
QString formula = GetParametrString(domElement, "length");
qint64 basePointId = GetParametrLongLong(domElement, "basePoint");
qreal angle = GetParametrDouble(domElement, "angle");
if(mode == Draw::Calculation){
VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, scene, this,
data, parse, Tool::FromFile);
} else {
VModelingEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, this,
data, parse, Tool::FromFile);
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point of end line"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
if(type == "alongLine"){
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
QString typeLine = GetParametrString(domElement, "typeLine");
QString formula = GetParametrString(domElement, "length");
qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
if(mode == Draw::Calculation){
VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my,
scene, this, data, parse, Tool::FromFile);
} else {
VModelingAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my,
this, data, parse, Tool::FromFile);
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
QString typeLine = GetParametrString(domElement, "typeLine");
QString formula = GetParametrString(domElement, "length");
qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
if(mode == Draw::Calculation){
VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my,
scene, this, data, parse, Tool::FromFile);
} else {
VModelingAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my,
this, data, parse, Tool::FromFile);
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point along line"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
if(type == "shoulder"){
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
QString typeLine = GetParametrString(domElement, "typeLine");
QString formula = GetParametrString(domElement, "length");
qint64 p1Line = GetParametrLongLong(domElement, "p1Line");
qint64 p2Line = GetParametrLongLong(domElement, "p2Line");
qint64 pShoulder = GetParametrLongLong(domElement, "pShoulder");
if(mode == Draw::Calculation){
VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my,
scene, this, data, parse, Tool::FromFile);
} else {
VModelingShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx,
my, this, data, parse, Tool::FromFile);
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
QString typeLine = GetParametrString(domElement, "typeLine");
QString formula = GetParametrString(domElement, "length");
qint64 p1Line = GetParametrLongLong(domElement, "p1Line");
qint64 p2Line = GetParametrLongLong(domElement, "p2Line");
qint64 pShoulder = GetParametrLongLong(domElement, "pShoulder");
if(mode == Draw::Calculation){
VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my,
scene, this, data, parse, Tool::FromFile);
} else {
VModelingShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx,
my, this, data, parse, Tool::FromFile);
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point of shoulder"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
if(type == "normal"){
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
QString typeLine = GetParametrString(domElement, "typeLine");
QString formula = GetParametrString(domElement, "length");
qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
qreal angle = GetParametrDouble(domElement, "angle");
if(mode == Draw::Calculation){
VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle,
mx, my, scene, this, data, parse, Tool::FromFile);
} else {
VModelingNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle,
mx, my, this, data, parse, Tool::FromFile);
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
QString typeLine = GetParametrString(domElement, "typeLine");
QString formula = GetParametrString(domElement, "length");
qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
qreal angle = GetParametrDouble(domElement, "angle");
if(mode == Draw::Calculation){
VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle,
mx, my, scene, this, data, parse, Tool::FromFile);
} else {
VModelingNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle,
mx, my, this, data, parse, Tool::FromFile);
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point of normal"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
if(type == "bisector"){
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
QString typeLine = GetParametrString(domElement, "typeLine");
QString formula = GetParametrString(domElement, "length");
qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
qint64 thirdPointId = GetParametrLongLong(domElement, "thirdPoint");
if(mode == Draw::Calculation){
VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine,
name, mx, my, scene, this, data, parse, Tool::FromFile);
} else {
VModelingBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine,
name, mx, my, this, data, parse, Tool::FromFile);
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
QString typeLine = GetParametrString(domElement, "typeLine");
QString formula = GetParametrString(domElement, "length");
qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
qint64 thirdPointId = GetParametrLongLong(domElement, "thirdPoint");
if(mode == Draw::Calculation){
VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine,
name, mx, my, scene, this, data, parse, Tool::FromFile);
} else {
VModelingBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine,
name, mx, my, this, data, parse, Tool::FromFile);
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point of bisector"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
if(type == "lineIntersect"){
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
qint64 p1Line1Id = GetParametrLongLong(domElement, "p1Line1");
qint64 p2Line1Id = GetParametrLongLong(domElement, "p2Line1");
qint64 p1Line2Id = GetParametrLongLong(domElement, "p1Line2");
qint64 p2Line2Id = GetParametrLongLong(domElement, "p2Line2");
if(mode == Draw::Calculation){
VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my,
scene, this, data, parse, Tool::FromFile);
} else {
VModelingLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my,
this, data, parse, Tool::FromFile);
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
qint64 p1Line1Id = GetParametrLongLong(domElement, "p1Line1");
qint64 p2Line1Id = GetParametrLongLong(domElement, "p2Line1");
qint64 p1Line2Id = GetParametrLongLong(domElement, "p1Line2");
qint64 p2Line2Id = GetParametrLongLong(domElement, "p2Line2");
if(mode == Draw::Calculation){
VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my,
scene, this, data, parse, Tool::FromFile);
} else {
VModelingLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my,
this, data, parse, Tool::FromFile);
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point of lineintersection"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
if(type == "pointOfContact"){
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
QString radius = GetParametrString(domElement, "radius");
qint64 center = GetParametrLongLong(domElement, "center");
qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
if(mode == Draw::Calculation){
VToolPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, my,
scene, this, data, parse, Tool::FromFile);
} else {
VModelingPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx,
my, this, data, parse, Tool::FromFile);
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
QString radius = GetParametrString(domElement, "radius");
qint64 center = GetParametrLongLong(domElement, "center");
qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
if(mode == Draw::Calculation){
VToolPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, my,
scene, this, data, parse, Tool::FromFile);
} else {
VModelingPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx,
my, this, data, parse, Tool::FromFile);
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point of contact"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
if(type == "modeling"){
qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, "idObject");
QString tObject = GetParametrString(domElement, "typeObject");
VPointF point;
Draw::Mode typeObject;
if(tObject == "Calculation"){
typeObject = Draw::Calculation;
point = data->GetPoint(idObject );
} else {
typeObject = Draw::Modeling;
point = data->GetModelingPoint(idObject);
try{
qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, "idObject");
QString tObject = GetParametrString(domElement, "typeObject");
VPointF point;
Draw::Mode typeObject;
if(tObject == "Calculation"){
typeObject = Draw::Calculation;
point = data->GetPoint(idObject );
} else {
typeObject = Draw::Modeling;
point = data->GetModelingPoint(idObject);
}
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
data->UpdateModelingPoint(id, VPointF(point.x(), point.y(), point.name(), mx, my, typeObject,
idObject ));
data->IncrementReferens(idObject, Scene::Point, typeObject);
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating modeling point"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
qreal my = toPixel(GetParametrDouble(domElement, "my"));
data->UpdateModelingPoint(id, VPointF(point.x(), point.y(), point.name(), mx, my, typeObject,
idObject ));
data->IncrementReferens(idObject, Scene::Point, typeObject);
return;
}
}
@ -691,13 +768,20 @@ void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement
Document::Enum parse, Draw::Mode mode){
Q_CHECK_PTR(scene);
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
qint64 id = GetParametrId(domElement);
qint64 firstPoint = GetParametrLongLong(domElement, "firstPoint");
qint64 secondPoint = GetParametrLongLong(domElement, "secondPoint");
if(mode == Draw::Calculation){
VToolLine::Create(id, firstPoint, secondPoint, scene, this, data, parse, Tool::FromFile);
} else {
VModelingLine::Create(id, firstPoint, secondPoint, this, data, parse, Tool::FromFile);
try{
qint64 id = GetParametrId(domElement);
qint64 firstPoint = GetParametrLongLong(domElement, "firstPoint");
qint64 secondPoint = GetParametrLongLong(domElement, "secondPoint");
if(mode == Draw::Calculation){
VToolLine::Create(id, firstPoint, secondPoint, scene, this, data, parse, Tool::FromFile);
} else {
VModelingLine::Create(id, firstPoint, secondPoint, this, data, parse, Tool::FromFile);
}
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating line"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
@ -707,100 +791,128 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of spline is empty");
if(type == "simple"){
qint64 id = GetParametrId(domElement);
qint64 point1 = GetParametrLongLong(domElement, "point1");
qint64 point4 = GetParametrLongLong(domElement, "point4");
qreal angle1 = GetParametrDouble(domElement, "angle1");
qreal angle2 = GetParametrDouble(domElement, "angle2");
qreal kAsm1 = GetParametrDouble(domElement, "kAsm1");
qreal kAsm2 = GetParametrDouble(domElement, "kAsm2");
qreal kCurve = GetParametrDouble(domElement, "kCurve");
if(mode == Draw::Calculation){
VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this,
data, parse, Tool::FromFile);
} else {
VModelingSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, this,
try{
qint64 id = GetParametrId(domElement);
qint64 point1 = GetParametrLongLong(domElement, "point1");
qint64 point4 = GetParametrLongLong(domElement, "point4");
qreal angle1 = GetParametrDouble(domElement, "angle1");
qreal angle2 = GetParametrDouble(domElement, "angle2");
qreal kAsm1 = GetParametrDouble(domElement, "kAsm1");
qreal kAsm2 = GetParametrDouble(domElement, "kAsm2");
qreal kCurve = GetParametrDouble(domElement, "kCurve");
if(mode == Draw::Calculation){
VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this,
data, parse, Tool::FromFile);
} else {
VModelingSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, this,
data, parse, Tool::FromFile);
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating simple curve"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
if(type == "path"){
qint64 id = GetParametrId(domElement);
qreal kCurve = GetParametrDouble(domElement, "kCurve");
VSplinePath path(data->DataPoints(), kCurve);
try{
qint64 id = GetParametrId(domElement);
qreal kCurve = GetParametrDouble(domElement, "kCurve");
VSplinePath path(data->DataPoints(), kCurve);
QDomNodeList nodeList = domElement.childNodes();
qint32 num = nodeList.size();
for(qint32 i = 0; i < num; ++i){
QDomElement element = nodeList.at(i).toElement();
if(!element.isNull()){
if(element.tagName() == "pathPoint"){
qreal kAsm1 = GetParametrDouble(element, "kAsm1");
qreal angle = GetParametrDouble(element, "angle");
qreal kAsm2 = GetParametrDouble(element, "kAsm2");
qint64 pSpline = GetParametrLongLong(element, "pSpline");
VSplinePoint splPoint(pSpline, kAsm1, angle, kAsm2);
path.append(splPoint);
QDomNodeList nodeList = domElement.childNodes();
qint32 num = nodeList.size();
for(qint32 i = 0; i < num; ++i){
QDomElement element = nodeList.at(i).toElement();
if(!element.isNull()){
if(element.tagName() == "pathPoint"){
qreal kAsm1 = GetParametrDouble(element, "kAsm1");
qreal angle = GetParametrDouble(element, "angle");
qreal kAsm2 = GetParametrDouble(element, "kAsm2");
qint64 pSpline = GetParametrLongLong(element, "pSpline");
VSplinePoint splPoint(pSpline, kAsm1, angle, kAsm2);
path.append(splPoint);
}
}
}
if(mode == Draw::Calculation){
VToolSplinePath::Create(id, path, scene, this, data, parse, Tool::FromFile);
} else {
VModelingSplinePath::Create(id, path, this, data, parse, Tool::FromFile);
}
return;
}
if(mode == Draw::Calculation){
VToolSplinePath::Create(id, path, scene, this, data, parse, Tool::FromFile);
} else {
VModelingSplinePath::Create(id, path, this, data, parse, Tool::FromFile);
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating curve path"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
if(type == "modelingSpline"){
qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, "idObject");
QString tObject = GetParametrString(domElement, "typeObject");
VSpline spl;
Draw::Mode typeObject;
if(tObject == "Calculation"){
typeObject = Draw::Calculation;
spl = data->GetSpline(idObject);
} else {
typeObject = Draw::Modeling;
spl = data->GetModelingSpline(idObject);
try{
qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, "idObject");
QString tObject = GetParametrString(domElement, "typeObject");
VSpline spl;
Draw::Mode typeObject;
if(tObject == "Calculation"){
typeObject = Draw::Calculation;
spl = data->GetSpline(idObject);
} else {
typeObject = Draw::Modeling;
spl = data->GetModelingSpline(idObject);
}
spl.setMode(typeObject);
spl.setIdObject(idObject);
data->UpdateModelingSpline(id, spl);
if(typeObject == Draw::Calculation){
data->IncrementReferens(spl.GetP1(), Scene::Point, Draw::Calculation);
data->IncrementReferens(spl.GetP4(), Scene::Point, Draw::Calculation);
} else {
data->IncrementReferens(spl.GetP1(), Scene::Point, Draw::Modeling);
data->IncrementReferens(spl.GetP4(), Scene::Point, Draw::Modeling);
}
return;
}
spl.setMode(typeObject);
spl.setIdObject(idObject);
data->UpdateModelingSpline(id, spl);
if(typeObject == Draw::Calculation){
data->IncrementReferens(spl.GetP1(), Scene::Point, Draw::Calculation);
data->IncrementReferens(spl.GetP4(), Scene::Point, Draw::Calculation);
} else {
data->IncrementReferens(spl.GetP1(), Scene::Point, Draw::Modeling);
data->IncrementReferens(spl.GetP4(), Scene::Point, Draw::Modeling);
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating modeling simple curve"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
if(type == "modelingPath"){
qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, "idObject");
QString tObject = GetParametrString(domElement, "typeObject");
VSplinePath path;
Draw::Mode typeObject;
if(tObject == "Calculation"){
typeObject = Draw::Calculation;
path = data->GetSplinePath(idObject);
} else {
typeObject = Draw::Modeling;
path = data->GetModelingSplinePath(idObject);
}
path.setMode(typeObject);
path.setIdObject(idObject);
data->UpdateModelingSplinePath(id, path);
const QVector<VSplinePoint> *points = path.GetPoint();
for(qint32 i = 0; i<points->size(); ++i){
if(typeObject == Draw::Calculation){
data->IncrementReferens(points->at(i).P(), Scene::Point, Draw::Calculation);
try{
qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, "idObject");
QString tObject = GetParametrString(domElement, "typeObject");
VSplinePath path;
Draw::Mode typeObject;
if(tObject == "Calculation"){
typeObject = Draw::Calculation;
path = data->GetSplinePath(idObject);
} else {
data->IncrementReferens(points->at(i).P(), Scene::Point, Draw::Modeling);
typeObject = Draw::Modeling;
path = data->GetModelingSplinePath(idObject);
}
path.setMode(typeObject);
path.setIdObject(idObject);
data->UpdateModelingSplinePath(id, path);
const QVector<VSplinePoint> *points = path.GetPoint();
for(qint32 i = 0; i<points->size(); ++i){
if(typeObject == Draw::Calculation){
data->IncrementReferens(points->at(i).P(), Scene::Point, Draw::Calculation);
} else {
data->IncrementReferens(points->at(i).P(), Scene::Point, Draw::Modeling);
}
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating modeling curve path"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
}
@ -810,43 +922,63 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of spline is empty");
if(type == "simple"){
qint64 id = GetParametrId(domElement);
qint64 center = GetParametrLongLong(domElement, "center");
QString radius = GetParametrString(domElement, "radius");
QString f1 = GetParametrString(domElement, "angle1");
QString f2 = GetParametrString(domElement, "angle2");
if(mode == Draw::Calculation){
VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Tool::FromFile);
} else {
VModelingArc::Create(id, center, radius, f1, f2, this, data, parse, Tool::FromFile);
try{
qint64 id = GetParametrId(domElement);
qint64 center = GetParametrLongLong(domElement, "center");
QString radius = GetParametrString(domElement, "radius");
QString f1 = GetParametrString(domElement, "angle1");
QString f2 = GetParametrString(domElement, "angle2");
if(mode == Draw::Calculation){
VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Tool::FromFile);
} else {
VModelingArc::Create(id, center, radius, f1, f2, this, data, parse, Tool::FromFile);
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating simple arc"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
return;
}
if(type == "modeling"){
qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, "idObject");
QString tObject = GetParametrString(domElement, "typeObject");
VArc arc;
Draw::Mode typeObject;
if(tObject == "Calculation"){
typeObject = Draw::Calculation;
arc = data->GetArc(idObject);
} else {
typeObject = Draw::Modeling;
arc = data->GetModelingArc(idObject);
try{
qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, "idObject");
QString tObject = GetParametrString(domElement, "typeObject");
VArc arc;
Draw::Mode typeObject;
if(tObject == "Calculation"){
typeObject = Draw::Calculation;
arc = data->GetArc(idObject);
} else {
typeObject = Draw::Modeling;
arc = data->GetModelingArc(idObject);
}
arc.setMode(typeObject);
arc.setIdObject(idObject);
data->UpdateModelingArc(id, arc);
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating modeling arc"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
arc.setMode(typeObject);
arc.setIdObject(idObject);
data->UpdateModelingArc(id, arc);
return;
}
}
void VDomDocument::FullUpdateTree(){
VMainGraphicsScene *scene = new VMainGraphicsScene();
Q_CHECK_PTR(scene);
data->ClearObject();
Parse(Document::LiteParse, scene, scene);
try{
data->ClearObject();
Parse(Document::LiteParse, scene, scene);
}
catch(...){
delete scene;
throw;
}
delete scene;
setCurrentData();
emit FullUpdateFromFile();