diff --git a/Valentina.pro b/Valentina.pro index f91931541..71702db3a 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -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 \ diff --git a/container/vcontainer.cpp b/container/vcontainer.cpp index 649a0f8ab..c04486c7a 100644 --- a/container/vcontainer.cpp +++ b/container/vcontainer.cpp @@ -22,6 +22,7 @@ #include "vcontainer.h" #include #include "options.h" +#include qint64 VContainer::_id = 0; @@ -80,8 +81,7 @@ val VContainer::GetObject(const QMap &obj, key id){ if(obj.contains(id)){ return obj.value(id); } else { - qCritical()<<"Не можу знайти key = "< /** * @brief The VContainer class */ class VContainer { + Q_DECLARE_TR_FUNCTIONS(VContainer) public: /** * @brief VContainer diff --git a/exception/vexception.cpp b/exception/vexception.cpp new file mode 100644 index 000000000..a22df35a3 --- /dev/null +++ b/exception/vexception.cpp @@ -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 . + ** + ****************************************************************************/ + +#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; +} diff --git a/exception/vexception.h b/exception/vexception.h new file mode 100644 index 000000000..fc53c3d77 --- /dev/null +++ b/exception/vexception.h @@ -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 . + ** + ****************************************************************************/ + + +#ifndef VEXCEPTION_H +#define VEXCEPTION_H + +#include +#include + +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 diff --git a/exception/vexceptionbadid.cpp b/exception/vexceptionbadid.cpp new file mode 100644 index 000000000..82f686f48 --- /dev/null +++ b/exception/vexceptionbadid.cpp @@ -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 . + ** + ****************************************************************************/ + +#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; +} + diff --git a/exception/vexceptionbadid.h b/exception/vexceptionbadid.h new file mode 100644 index 000000000..caa9fcd54 --- /dev/null +++ b/exception/vexceptionbadid.h @@ -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 . + ** + ****************************************************************************/ + +#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 diff --git a/exception/vexceptionconversionerror.cpp b/exception/vexceptionconversionerror.cpp new file mode 100644 index 000000000..7bfbf1366 --- /dev/null +++ b/exception/vexceptionconversionerror.cpp @@ -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 . + ** + ****************************************************************************/ + +#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; +} diff --git a/exception/vexceptionconversionerror.h b/exception/vexceptionconversionerror.h new file mode 100644 index 000000000..f0650a50d --- /dev/null +++ b/exception/vexceptionconversionerror.h @@ -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 . + ** + ****************************************************************************/ + +#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 diff --git a/exception/vexceptionemptyparameter.cpp b/exception/vexceptionemptyparameter.cpp new file mode 100644 index 000000000..480084f77 --- /dev/null +++ b/exception/vexceptionemptyparameter.cpp @@ -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 . + ** + ****************************************************************************/ + +#include "vexceptionemptyparameter.h" +#include + +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; +} diff --git a/exception/vexceptionemptyparameter.h b/exception/vexceptionemptyparameter.h new file mode 100644 index 000000000..286b0bfac --- /dev/null +++ b/exception/vexceptionemptyparameter.h @@ -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 . + ** + ****************************************************************************/ + +#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 diff --git a/exception/vexceptionobjecterror.cpp b/exception/vexceptionobjecterror.cpp new file mode 100644 index 000000000..9c4f36c83 --- /dev/null +++ b/exception/vexceptionobjecterror.cpp @@ -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 . + ** + ****************************************************************************/ + +#include "vexceptionobjecterror.h" +#include + +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."<moreInfo.append(info); +} diff --git a/exception/vexceptionobjecterror.h b/exception/vexceptionobjecterror.h new file mode 100644 index 000000000..f0e36bb99 --- /dev/null +++ b/exception/vexceptionobjecterror.h @@ -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 . + ** + ****************************************************************************/ + +#ifndef VEXCEPTIONOBJECTERROR_H +#define VEXCEPTIONOBJECTERROR_H + +#include "vexception.h" +#include + +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 diff --git a/exception/vexceptionwrongparameterid.cpp b/exception/vexceptionwrongparameterid.cpp new file mode 100644 index 000000000..31b3d95e4 --- /dev/null +++ b/exception/vexceptionwrongparameterid.cpp @@ -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 . + ** + ****************************************************************************/ + +#include "vexceptionwrongparameterid.h" +#include + +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; +} diff --git a/exception/vexceptionwrongparameterid.h b/exception/vexceptionwrongparameterid.h new file mode 100644 index 000000000..1b8e611f6 --- /dev/null +++ b/exception/vexceptionwrongparameterid.h @@ -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 . + ** + ****************************************************************************/ + +#ifndef VEXCEPTIONWRONGPARAMETERID_H +#define VEXCEPTIONWRONGPARAMETERID_H + +#include "vexception.h" +#include + +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 diff --git a/mainwindow.cpp b/mainwindow.cpp index aa23992c9..30fede2e8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -30,6 +30,11 @@ #include #include #include "geometry/vspline.h" +#include +#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(&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(&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(){ diff --git a/widgets/vapplication.cpp b/widgets/vapplication.cpp new file mode 100644 index 000000000..b8f658bcc --- /dev/null +++ b/widgets/vapplication.cpp @@ -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 . + ** + ****************************************************************************/ + +#include "vapplication.h" +#include +#include +#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; +} diff --git a/widgets/vapplication.h b/widgets/vapplication.h new file mode 100644 index 000000000..80d3f516c --- /dev/null +++ b/widgets/vapplication.h @@ -0,0 +1,15 @@ +#ifndef VAPPLICATION_H +#define VAPPLICATION_H + +#include + +class VApplication : public QApplication +{ + Q_OBJECT +public: + VApplication(int &argc, char ** argv); + virtual ~VApplication() { } + virtual bool notify(QObject * receiver, QEvent * event); +}; + +#endif // VAPPLICATION_H diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp index 4d45dde7b..2cc3a03b6 100644 --- a/xml/vdomdocument.cpp +++ b/xml/vdomdocument.cpp @@ -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 *points = path.GetPoint(); - for(qint32 i = 0; isize(); ++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 *points = path.GetPoint(); + for(qint32 i = 0; isize(); ++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();