diff --git a/share/translations.pro b/share/translations.pro index 5cc97ecdb..6701b5a6d 100644 --- a/share/translations.pro +++ b/share/translations.pro @@ -10,11 +10,13 @@ TEMPLATE = app DEPENDPATH += \ ../src/app \ ../src/libs/qmuparser \ - ../src/libs/vpropertyexplorer + ../src/libs/vpropertyexplorer \ + ../src/libs/ifc include(../src/app/app.pri) include(../src/libs/qmuparser/qmuparser.pri) include(../src/libs/vpropertyexplorer/vpropertyexplorer.pri) +include(../src/libs/ifc/ifc.pri) # Add here path to new translation file with name "valentina_*_*.ts" if you want to add new language. # Same paths in variable INSTALL_TRANSLATIONS (app.pro). diff --git a/src/app/app.pri b/src/app/app.pri index 89a39befa..bfc1e20c3 100644 --- a/src/app/app.pri +++ b/src/app/app.pri @@ -1,7 +1,6 @@ # Suport subdirectories. Just better project code tree. include(container/container.pri) include(dialogs/dialogs.pri) -include(exception/exception.pri) include(geometry/geometry.pri) include(tools/tools.pri) include(widgets/widgets.pri) diff --git a/src/app/app.pro b/src/app/app.pro index 68ef40daa..1985d19f2 100644 --- a/src/app/app.pro +++ b/src/app/app.pro @@ -51,7 +51,6 @@ RESOURCES += \ share/resources/icon.qrc \ # All other icons except cursors and Windows theme. share/resources/cursor.qrc \ # Tools cursor icons. share/resources/theme.qrc \ # Windows theme icons. - share/resources/schema.qrc \ # Schemas for validation xml files. share/resources/measurements.qrc \ # For measurements files that we save as resource. share/resources/flags.qrc @@ -346,6 +345,14 @@ else:unix: LIBS += -L$${OUT_PWD}/../libs/vpropertyexplorer/$${DESTDIR} -lvproper INCLUDEPATH += $${PWD}/../libs/vpropertyexplorer DEPENDPATH += $${PWD}/../libs/vpropertyexplorer +# IFC static library +unix|win32: LIBS += -L$$OUT_PWD/../libs/ifc/$${DESTDIR}/ -lifc + +INCLUDEPATH += $$PWD/../libs/ifc +DEPENDPATH += $$PWD/../libs/ifc + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../libs/ifc/$${DESTDIR}/ifc.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../libs/ifc/$${DESTDIR}/libifc.a # Strip after you link all libaries. CONFIG(release, debug|release){ diff --git a/src/app/container/vcontainer.h b/src/app/container/vcontainer.h index 1b00c557d..cb40925d9 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -32,7 +32,7 @@ #include "variables.h" #include "../geometry/vdetail.h" #include "../geometry/vgobject.h" -#include "../exception/vexceptionbadid.h" +#include "../libs/ifc/exception/vexceptionbadid.h" #include "../geometry/vabstractcurve.h" #include diff --git a/src/app/core/vapplication.cpp b/src/app/core/vapplication.cpp index 042b383c6..74bb563de 100644 --- a/src/app/core/vapplication.cpp +++ b/src/app/core/vapplication.cpp @@ -27,11 +27,11 @@ *************************************************************************/ #include "vapplication.h" -#include "../exception/vexceptionobjecterror.h" -#include "../exception/vexceptionbadid.h" -#include "../exception/vexceptionconversionerror.h" -#include "../exception/vexceptionemptyparameter.h" -#include "../exception/vexceptionwrongid.h" +#include "../libs/ifc/exception/vexceptionobjecterror.h" +#include "../libs/ifc/exception/vexceptionbadid.h" +#include "../libs/ifc/exception/vexceptionconversionerror.h" +#include "../libs/ifc/exception/vexceptionemptyparameter.h" +#include "../libs/ifc/exception/vexceptionwrongid.h" #include "vmaingraphicsview.h" #include "../container/calculator.h" #include "../version.h" @@ -2039,53 +2039,6 @@ QString VApplication::STDescription(const QString &id) const return QString(); } -//--------------------------------------------------------------------------------------------------------------------- -bool VApplication::SafeCopy(const QString &source, const QString &destination, QString &error) -{ - bool result = false; - -#ifdef Q_OS_WIN32 - qt_ntfs_permission_lookup++; // turn checking on -#endif /*Q_OS_WIN32*/ - - QFile patternFile(destination); - patternFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner); - // We need here temporary file because we want restore document after error of copying temp file. - QTemporaryFile tempOfPattern; - if (tempOfPattern.open()) - { - if (patternFile.exists()) - { - patternFile.copy(tempOfPattern.fileName()); - } - } - if ( patternFile.exists() == false || patternFile.remove() ) - { - QFile sourceFile(source); - if ( sourceFile.copy(patternFile.fileName()) == false ) - { - error = tr("Could not copy temp file to document file"); - tempOfPattern.copy(destination); - result = false; - } - else - { - result = true; - } - } - else - { - error = tr("Could not remove document file"); - result = false; - } - -#ifdef Q_OS_WIN32 - qt_ntfs_permission_lookup--; // turn off check permission again -#endif /*Q_OS_WIN32*/ - - return result; -} - //--------------------------------------------------------------------------------------------------------------------- void VApplication::StartLogging() { diff --git a/src/app/core/vapplication.h b/src/app/core/vapplication.h index 3b18c6e17..7122d424d 100644 --- a/src/app/core/vapplication.h +++ b/src/app/core/vapplication.h @@ -106,7 +106,6 @@ public: static QStringList LabelLanguages(); QString STDescription(const QString &id)const; - static bool SafeCopy(const QString &source, const QString &destination, QString &error); void StartLogging(); QTextStream *LogFile(); diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index c95860b6b..055979b35 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -64,7 +64,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par { VDomDocument::ValidateXML("://schema/individual_measurements.xsd", filePath); m = new VIndividualMeasurements(data); - m->setContent(filePath); + m->setXMLContent(filePath); } catch (VException &e) { @@ -527,7 +527,7 @@ void DialogIncrements::OpenTable() VDomDocument::ValidateXML("://schema/individual_measurements.xsd", filePath); m1 = new VIndividualMeasurements(data); - m1->setContent(filePath); + m1->setXMLContent(filePath); } catch (VException &e) { @@ -567,7 +567,7 @@ void DialogIncrements::OpenTable() VDomDocument::ValidateXML("://schema/standard_measurements.xsd", filePath); m1 = new VStandardMeasurements(data); - m1->setContent(filePath); + m1->setXMLContent(filePath); Unit mUnit = m1->MUnit(); if (qApp->patternUnit() != mUnit) { diff --git a/src/app/dialogs/app/dialogindividualmeasurements.cpp b/src/app/dialogs/app/dialogindividualmeasurements.cpp index f7c8718ce..8adcc8649 100644 --- a/src/app/dialogs/app/dialogindividualmeasurements.cpp +++ b/src/app/dialogs/app/dialogindividualmeasurements.cpp @@ -111,7 +111,7 @@ void DialogIndividualMeasurements::DialogAccepted() { VDomDocument::ValidateXML("://schema/individual_measurements.xsd", _tablePath); VIndividualMeasurements m(data); - m.setContent(_tablePath); + m.setXMLContent(_tablePath); const qint32 index = ui->comboBoxUnits->currentIndex(); Unit unit = VDomDocument::StrToUnits(ui->comboBoxUnits->itemData(index).toString()); m.setUnit(unit); @@ -215,7 +215,7 @@ void DialogIndividualMeasurements::OpenTable() fileName.clear(); } VIndividualMeasurements m(data); - m.setContent(fileName); + m.setXMLContent(fileName); ui->labelGivenName->setText(m.GivenName()); ui->labelFamilyName->setText(m.FamilyName()); ui->lineEditPathExistM->setText(fileName); diff --git a/src/app/dialogs/app/dialogstandardmeasurements.cpp b/src/app/dialogs/app/dialogstandardmeasurements.cpp index e6701d4b5..356074ed7 100644 --- a/src/app/dialogs/app/dialogstandardmeasurements.cpp +++ b/src/app/dialogs/app/dialogstandardmeasurements.cpp @@ -99,7 +99,7 @@ void DialogStandardMeasurements::DialogAccepted() { VDomDocument::ValidateXML("://schema/standard_measurements.xsd", _tablePath); VStandardMeasurements m(data); - m.setContent(_tablePath); + m.setXMLContent(_tablePath); qApp->setPatternUnit(m.MUnit()); } catch (VException &e) @@ -170,7 +170,7 @@ void DialogStandardMeasurements::LoadStandardTables() { VDomDocument::ValidateXML("://schema/standard_measurements.xsd", fi.absoluteFilePath()); VStandardMeasurements m(data); - m.setContent(fi.absoluteFilePath()); + m.setXMLContent(fi.absoluteFilePath()); if (m.MUnit() == Unit::Inch) { qCWarning(vStMeasur)<<"We do not support inches for standard table. Ignore table" diff --git a/src/app/dialogs/app/dialogundo.cpp b/src/app/dialogs/app/dialogundo.cpp index 8e5e1223e..705adee55 100644 --- a/src/app/dialogs/app/dialogundo.cpp +++ b/src/app/dialogs/app/dialogundo.cpp @@ -29,7 +29,7 @@ #include "dialogundo.h" #include "ui_dialogundo.h" #include "../../core/vapplication.h" -#include "../../exception/vexceptionundo.h" +#include "../../libs/ifc/exception/vexceptionundo.h" #include #include diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index 7349aedbb..00eef7b31 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -34,7 +34,7 @@ #include "../../geometry/vpointf.h" #include "../../container/vcontainer.h" -#include "../../xml/vdomdocument.h" +#include "../../libs/ifc/xml/vdomdocument.h" #include "../../visualization/vistoolarc.h" //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogdetail.cpp b/src/app/dialogs/tools/dialogdetail.cpp index 92943718f..b4bded7e0 100644 --- a/src/app/dialogs/tools/dialogdetail.cpp +++ b/src/app/dialogs/tools/dialogdetail.cpp @@ -34,7 +34,7 @@ #include "../../geometry/vpointf.h" #include "../../geometry/vsplinepath.h" #include "../../container/vcontainer.h" -#include "../../xml/vdomdocument.h" +#include "../../libs/ifc/xml/vdomdocument.h" //--------------------------------------------------------------------------------------------------------------------- /** diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index beb8b405a..f2f40b050 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -36,7 +36,7 @@ #include "../../../libs/qmuparser/qmuparsererror.h" #include "../../core/vapplication.h" #include "../../core/vsettings.h" -#include "../../xml/vdomdocument.h" +#include "../../libs/ifc/xml/vdomdocument.h" #include #include #include diff --git a/src/app/geometry/vsplinepath.cpp b/src/app/geometry/vsplinepath.cpp index 33df03750..d2c49976b 100644 --- a/src/app/geometry/vsplinepath.cpp +++ b/src/app/geometry/vsplinepath.cpp @@ -28,7 +28,7 @@ #include "vsplinepath.h" #include "vsplinepath_p.h" -#include "../exception/vexception.h" +#include "../libs/ifc/exception/vexception.h" //--------------------------------------------------------------------------------------------------------------------- VSplinePath::VSplinePath(qreal kCurve, quint32 idObject, Draw mode) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index f32764cfe..8f86adf6a 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -44,6 +44,7 @@ #include "undocommands/renamepp.h" #include "vtooloptionspropertybrowser.h" #include "options.h" +#include "../libs/ifc/xml/vpatternconverter.h" #include #include @@ -166,7 +167,7 @@ void MainWindow::ActionNewPP() path = stMeasurements.tablePath(); qCDebug(vMainWindow)<<"Table path:"<setOpeningPattern();//Begin opening file try { - VDomDocument::ValidateXML("://schema/pattern.xsd", fileName); - doc->setContent(fileName); + VPatternConverter converter(fileName); + converter.Convert(); + + VDomDocument::ValidateXML(VPatternConverter::CurrentSchema, fileName); + doc->setXMLContent(fileName); qApp->setPatternUnit(doc->MUnit()); qApp->setPatternType(doc->MType()); @@ -2368,7 +2372,7 @@ void MainWindow::LoadPattern(const QString &fileName) { VStandardMeasurements m(pattern); VDomDocument::ValidateXML("://schema/standard_measurements.xsd", path); - m.setContent(path); + m.setXMLContent(path); if (m.MUnit() == Unit::Inch) { QMessageBox::critical(this, tr("Wrong units."), @@ -2483,7 +2487,7 @@ void MainWindow::ReopenFilesAfterCrash(QStringList &args) for (int i = 0; i < restoreFiles.size(); ++i) { QString error; - if (VApplication::SafeCopy(restoreFiles.at(i) +".autosave", restoreFiles.at(i), error)) + if (VDomDocument::SafeCopy(restoreFiles.at(i) +".autosave", restoreFiles.at(i), error)) { QFile autoFile(restoreFiles.at(i) +".autosave"); autoFile.remove(); diff --git a/src/app/options.h b/src/app/options.h index fb12f3d19..5d1c9e37b 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -29,8 +29,8 @@ #ifndef OPTIONS_H #define OPTIONS_H -#include #include +#include "../libs/ifc/ifcdef.h" #ifdef Q_OS_WIN32 # if defined( Q_CC_MSVC ) // MSVC USED @@ -46,12 +46,8 @@ extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; class QString; class QStringList; -static const quint32 null_id = 0; - #define SceneSize 50000 #define DefPointRadius 2.0//mm -#define NULL_ID null_id//use this value for initialization variables that keeps id values. 0 mean uknown id value. -#define NULL_ID_STR "0" extern const QString nameRegExp; extern const QString degreeSymbol; @@ -122,8 +118,6 @@ enum class Vis : unsigned char enum class Source : char { FromGui, FromFile, FromTool }; enum class Draw : char { Calculation, Modeling }; -enum class Unit : char { Mm, Cm, Inch }; -enum class MeasurementsType : char { Standard, Individual }; enum class NodeDetail : char { Contour, Modeling }; enum class Contour : char { OpenContour, CloseContour }; enum class EquidistantType : char { OpenEquidistant, CloseEquidistant }; @@ -324,76 +318,4 @@ extern const QString cm_Oprt; extern const QString mm_Oprt; extern const QString in_Oprt; -/* - * This macros SCASSERT (for Stop and Continue Assert) will break into the debugger on the line of the assert and allow - * you to continue afterwards should you choose to. - * idea: Q_ASSERT no longer pauses debugger - http://qt-project.org/forums/viewthread/13148 - * Usefull links: - * 1. What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__? - - * https://stackoverflow.com/questions/4384765/whats-the-difference-between-pretty-function-function-func - * - * 2. Windows Predefined Macros - http://msdn.microsoft.com/library/b0084kay.aspx - * - * 3. Windows DebugBreak function - http://msdn.microsoft.com/en-us/library/ms679297%28VS.85%29.aspx - * - * 4. Continue to debug after failed assertion on Linux? [C/C++] - - * https://stackoverflow.com/questions/1721543/continue-to-debug-after-failed-assertion-on-linux-c-c - */ -#ifndef QT_NO_DEBUG -#ifdef Q_OS_WIN32 -#ifdef Q_CC_MSVC -#define SCASSERT(cond) \ -{ \ - if (!(cond)) \ - { \ - qDebug("ASSERT: %s in %s (%s:%u)", \ - #cond, __FUNCSIG__, __FILE__, __LINE__); \ - DebugBreak(); \ - } \ -} \ - -#else - -#define SCASSERT(cond) \ -{ \ - if (!(cond)) \ - { \ - qDebug("ASSERT: %s in %s (%s:%u)", \ - #cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\ - DebugBreak(); \ - } \ -} \ - -#endif /*Q_CC_MSVC*/ -#else -#define SCASSERT(cond) \ -{ \ - if (!(cond)) \ - { \ - qDebug("ASSERT: %s in %s (%s:%u)", \ - #cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\ - std::raise(SIGTRAP); \ - } \ -} \ - -#endif /* Q_OS_WIN32 */ -#else // define but disable this function if debugging is not set -#define SCASSERT(cond) qt_noop(); -#endif /* QT_NO_DEBUG */ - -// Detect whether the compiler supports C++11 noexcept exception specifications. -# if defined(__clang__) -# if __has_feature(cxx_noexcept) -# define V_NOEXCEPT_EXPR(x) noexcept(x) // Clang 3.0 and above have noexcept -# endif -# elif defined(__GNUC__) -# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__GXX_EXPERIMENTAL_CXX0X__) -# define V_NOEXCEPT_EXPR(x) noexcept(x) // GCC 4.7 and following have noexcept -# endif -# elif defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 180021114 -# define QMUP_NOEXCEPT_EXPR(x) noexcept(x) -# else -# define V_NOEXCEPT_EXPR(x) -# endif - #endif // OPTIONS_H diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index 228a9f85b..0902db7ba 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -34,7 +34,7 @@ #include "../container/calculator.h" #include "../../undocommands/addtocalc.h" #include "../../undocommands/savetooloptions.h" -#include "../../exception/vexceptionundo.h" +#include "../../libs/ifc/exception/vexceptionundo.h" qreal VDrawTool::factor = 1; diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index 9d610b7a5..597618386 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -30,7 +30,7 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialogalongline.h" #include "../../geometry/vpointf.h" -#include "../../exception/vexceptionobjecterror.h" +#include "../../libs/ifc/exception/vexceptionobjecterror.h" #include "../../visualization/vistoolalongline.h" const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); diff --git a/src/app/xml/vabstractmeasurements.cpp b/src/app/xml/vabstractmeasurements.cpp index 81c6a7f0c..fbf3339b7 100644 --- a/src/app/xml/vabstractmeasurements.cpp +++ b/src/app/xml/vabstractmeasurements.cpp @@ -33,7 +33,7 @@ const QString VAbstractMeasurements::AttrValue = QStringLiteral("value"); //--------------------------------------------------------------------------------------------------------------------- VAbstractMeasurements::VAbstractMeasurements(VContainer *data) - :VDomDocument(data) + :VDomDocument(), data(data) { SCASSERT(data != nullptr) } diff --git a/src/app/xml/vabstractmeasurements.h b/src/app/xml/vabstractmeasurements.h index 5de17cc73..ac64c9828 100644 --- a/src/app/xml/vabstractmeasurements.h +++ b/src/app/xml/vabstractmeasurements.h @@ -29,7 +29,8 @@ #ifndef VABSTRACTMEASUREMENTS_H #define VABSTRACTMEASUREMENTS_H -#include "vdomdocument.h" +#include "../libs/ifc/xml/vdomdocument.h" +#include "../container/vcontainer.h" class VAbstractMeasurements : public VDomDocument { @@ -42,6 +43,9 @@ public: static const QString AttrValue; static qreal UnitConvertor(qreal value, const Unit &from, const Unit &to); protected: + /** @brief data container with data. */ + VContainer *data; + void Measurement(const QString &tag); virtual void ReadMeasurement(const QDomElement &domElement, const QString &tag) = 0; private: diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 1d7f20c0b..ed8efa99e 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -32,11 +32,12 @@ #include "../tools/vtooluniondetails.h" #include "../tools/drawTools/drawtools.h" #include "../tools/nodeDetails/nodedetails.h" -#include "../exception/vexceptionobjecterror.h" -#include "../exception/vexceptionwrongid.h" -#include "../exception/vexceptionconversionerror.h" -#include "../exception/vexceptionemptyparameter.h" -#include "../exception/vexceptionundo.h" +#include "../libs/ifc/exception/vexceptionobjecterror.h" +#include "../libs/ifc/exception/vexceptionwrongid.h" +#include "../libs/ifc/exception/vexceptionconversionerror.h" +#include "../libs/ifc/exception/vexceptionemptyparameter.h" +#include "../libs/ifc/exception/vexceptionundo.h" +#include "../libs/ifc/xml/vpatternconverter.h" #include "../core/undoevent.h" #include "../core/vsettings.h" #include "vstandardmeasurements.h" @@ -121,7 +122,7 @@ const QString VPattern::IncrementDescription = QStringLiteral("description"); //--------------------------------------------------------------------------------------------------------------------- VPattern::VPattern(VContainer *data, Draw *mode, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, QObject *parent) - : QObject(parent), VDomDocument(data), nameActivPP(QString()), tools(QHash()), + : QObject(parent), VDomDocument(), data(data), nameActivPP(QString()), tools(QHash()), history(QVector()), cursor(0), patternPieces(QStringList()), mode(mode), sceneDraw(sceneDraw), sceneDetail(sceneDetail) { @@ -146,7 +147,7 @@ void VPattern::CreateEmptyFile(const QString &tablePath) patternElement.appendChild(createComment("Valentina pattern format.")); QDomElement version = createElement(TagVersion); - QDomText newNodeText = createTextNode(VAL_STR_VERSION); + QDomText newNodeText = createTextNode(VPatternConverter::PatternMaxVerStr); version.appendChild(newNodeText); patternElement.appendChild(version); @@ -2431,13 +2432,13 @@ void VPattern::SetNotes(const QString &text) //--------------------------------------------------------------------------------------------------------------------- QString VPattern::GetVersion() const { - return UniqueTagText(TagVersion, VAL_STR_VERSION); + return UniqueTagText(TagVersion, VPatternConverter::PatternMaxVerStr); } //--------------------------------------------------------------------------------------------------------------------- void VPattern::SetVersion() { - setTagText(TagVersion, VAL_STR_VERSION); + setTagText(TagVersion, VPatternConverter::PatternMaxVerStr); emit patternChanged(false); } @@ -2572,14 +2573,14 @@ void VPattern::UpdateMeasurements() { VStandardMeasurements m(data); ValidateXML("://schema/standard_measurements.xsd", path); - m.setContent(path); + m.setXMLContent(path); m.Measurements(); } else { VIndividualMeasurements m(data); ValidateXML("://schema/individual_measurements.xsd", path); - m.setContent(path); + m.setXMLContent(path); m.Measurements(); } } diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 50eb05f00..0765ae62f 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -29,8 +29,9 @@ #ifndef VPATTERN_H #define VPATTERN_H -#include "vdomdocument.h" +#include "../libs/ifc/xml/vdomdocument.h" #include "vtoolrecord.h" +#include "../container/vcontainer.h" class VDataTool; class VMainGraphicsScene; @@ -38,16 +39,6 @@ class VMainGraphicsScene; enum class Document : char { LiteParse, LitePPParse, FullParse }; enum class LabelType : char {NewPatternPiece, NewLabel}; -/* - VAL_VERSION is (major << 16) + (minor << 8) + patch. -*/ -// version without patch part -#define VAL_MIN_VERSION 0x000100 -// max support version of format -#define VAL_VERSION 0x000101 - -#define VAL_STR_VERSION "0.1.1" - /** * @brief The VPattern class working with pattern file. */ @@ -233,6 +224,9 @@ protected: private: Q_DISABLE_COPY(VPattern) + /** @brief data container with data. */ + VContainer *data; + /** @brief nameActivDraw name current pattern peace. */ QString nameActivPP; diff --git a/src/app/xml/xml.pri b/src/app/xml/xml.pri index b1de7e167..a26d7d4aa 100644 --- a/src/app/xml/xml.pri +++ b/src/app/xml/xml.pri @@ -3,7 +3,6 @@ HEADERS += \ $$PWD/vtoolrecord.h \ - $$PWD/vdomdocument.h \ $$PWD/vpattern.h \ $$PWD/vstandardmeasurements.h \ $$PWD/vindividualmeasurements.h \ @@ -11,7 +10,6 @@ HEADERS += \ SOURCES += \ $$PWD/vtoolrecord.cpp \ - $$PWD/vdomdocument.cpp \ $$PWD/vpattern.cpp \ $$PWD/vstandardmeasurements.cpp \ $$PWD/vindividualmeasurements.cpp \ diff --git a/src/app/exception/exception.pri b/src/libs/ifc/exception/exception.pri similarity index 100% rename from src/app/exception/exception.pri rename to src/libs/ifc/exception/exception.pri diff --git a/src/app/exception/vexception.cpp b/src/libs/ifc/exception/vexception.cpp similarity index 99% rename from src/app/exception/vexception.cpp rename to src/libs/ifc/exception/vexception.cpp index 25ab65a2b..051c6d60f 100644 --- a/src/app/exception/vexception.cpp +++ b/src/libs/ifc/exception/vexception.cpp @@ -31,7 +31,6 @@ #include #include #include -#include "../options.h" #include Q_LOGGING_CATEGORY(vExcep, "v.excep") diff --git a/src/app/exception/vexception.h b/src/libs/ifc/exception/vexception.h similarity index 98% rename from src/app/exception/vexception.h rename to src/libs/ifc/exception/vexception.h index ebd560157..3cf192406 100644 --- a/src/app/exception/vexception.h +++ b/src/libs/ifc/exception/vexception.h @@ -31,8 +31,7 @@ #include #include -#include -#include "../options.h" +#include "ifcdef.h" class QWidget; diff --git a/src/app/exception/vexceptionbadid.cpp b/src/libs/ifc/exception/vexceptionbadid.cpp similarity index 99% rename from src/app/exception/vexceptionbadid.cpp rename to src/libs/ifc/exception/vexceptionbadid.cpp index c26f03182..7b2dad8f1 100644 --- a/src/app/exception/vexceptionbadid.cpp +++ b/src/libs/ifc/exception/vexceptionbadid.cpp @@ -27,7 +27,6 @@ *************************************************************************/ #include "vexceptionbadid.h" -#include "../options.h" //--------------------------------------------------------------------------------------------------------------------- /** diff --git a/src/app/exception/vexceptionbadid.h b/src/libs/ifc/exception/vexceptionbadid.h similarity index 100% rename from src/app/exception/vexceptionbadid.h rename to src/libs/ifc/exception/vexceptionbadid.h diff --git a/src/app/exception/vexceptionconversionerror.cpp b/src/libs/ifc/exception/vexceptionconversionerror.cpp similarity index 100% rename from src/app/exception/vexceptionconversionerror.cpp rename to src/libs/ifc/exception/vexceptionconversionerror.cpp diff --git a/src/app/exception/vexceptionconversionerror.h b/src/libs/ifc/exception/vexceptionconversionerror.h similarity index 100% rename from src/app/exception/vexceptionconversionerror.h rename to src/libs/ifc/exception/vexceptionconversionerror.h diff --git a/src/app/exception/vexceptionemptyparameter.cpp b/src/libs/ifc/exception/vexceptionemptyparameter.cpp similarity index 100% rename from src/app/exception/vexceptionemptyparameter.cpp rename to src/libs/ifc/exception/vexceptionemptyparameter.cpp diff --git a/src/app/exception/vexceptionemptyparameter.h b/src/libs/ifc/exception/vexceptionemptyparameter.h similarity index 100% rename from src/app/exception/vexceptionemptyparameter.h rename to src/libs/ifc/exception/vexceptionemptyparameter.h diff --git a/src/app/exception/vexceptionobjecterror.cpp b/src/libs/ifc/exception/vexceptionobjecterror.cpp similarity index 100% rename from src/app/exception/vexceptionobjecterror.cpp rename to src/libs/ifc/exception/vexceptionobjecterror.cpp diff --git a/src/app/exception/vexceptionobjecterror.h b/src/libs/ifc/exception/vexceptionobjecterror.h similarity index 100% rename from src/app/exception/vexceptionobjecterror.h rename to src/libs/ifc/exception/vexceptionobjecterror.h diff --git a/src/app/exception/vexceptionundo.cpp b/src/libs/ifc/exception/vexceptionundo.cpp similarity index 100% rename from src/app/exception/vexceptionundo.cpp rename to src/libs/ifc/exception/vexceptionundo.cpp diff --git a/src/app/exception/vexceptionundo.h b/src/libs/ifc/exception/vexceptionundo.h similarity index 100% rename from src/app/exception/vexceptionundo.h rename to src/libs/ifc/exception/vexceptionundo.h diff --git a/src/app/exception/vexceptionwrongid.cpp b/src/libs/ifc/exception/vexceptionwrongid.cpp similarity index 100% rename from src/app/exception/vexceptionwrongid.cpp rename to src/libs/ifc/exception/vexceptionwrongid.cpp diff --git a/src/app/exception/vexceptionwrongid.h b/src/libs/ifc/exception/vexceptionwrongid.h similarity index 100% rename from src/app/exception/vexceptionwrongid.h rename to src/libs/ifc/exception/vexceptionwrongid.h diff --git a/src/libs/ifc/ifc.pri b/src/libs/ifc/ifc.pri new file mode 100644 index 000000000..124d558f1 --- /dev/null +++ b/src/libs/ifc/ifc.pri @@ -0,0 +1,13 @@ +# Suport subdirectories. Just better project code tree. +include(exception/exception.pri) +include(xml/xml.pri) + +# ADD TO EACH PATH $$PWD VARIABLE!!!!!! +# This need for corect working file translations.pro + +HEADERS += \ + $$PWD/stable.h \ + $$PWD/ifcdef.h + +SOURCES += \ + $$PWD/stable.cpp diff --git a/src/libs/ifc/ifc.pro b/src/libs/ifc/ifc.pro new file mode 100644 index 000000000..411f569c5 --- /dev/null +++ b/src/libs/ifc/ifc.pro @@ -0,0 +1,88 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-12-10T17:53:37 +# +#------------------------------------------------- + +# File with common stuff for whole project +include(../../../Valentina.pri) + +# Library work with xml. +QT += xml xmlpatterns printsupport + +# We don't need gui library. +QT -= gui + +# Name of library +TARGET = ifc # Internal Format Converter + +# We want create library +TEMPLATE = lib + +CONFIG += \ + staticlib \# Making static library + c++11 # We use C++11 standard + +# Use out-of-source builds (shadow builds) +CONFIG -= debug_and_release debug_and_release_target + +include(ifc.pri) + +# This is static library so no need in "make install" + +# directory for executable file +DESTDIR = bin + +# files created moc +MOC_DIR = moc + +# objecs files +OBJECTS_DIR = obj + +# Resource files. This files will be included in binary. +RESOURCES += \ + schema.qrc # Schemas for validation xml files. + +# Set using ccache. Function enable_ccache() defined in Valentina.pri. +$$enable_ccache() + +# Set precompiled headers. Function set_PCH() defined in Valentina.pri. +$$set_PCH() + +CONFIG(debug, debug|release){ + # Debug mode + unix { + #Turn on compilers warnings. + *-g++{ + QMAKE_CXXFLAGS += \ + # Key -isystem disable checking errors in system headers. + -isystem "$${OUT_PWD}/$${MOC_DIR}" \ + $$GCC_DEBUG_CXXFLAGS # See Valentina.pri for more details. + } + clang*{ + QMAKE_CXXFLAGS += \ + # Key -isystem disable checking errors in system headers. + -isystem "$${OUT_PWD}/$${MOC_DIR}" \ + $$CLANG_DEBUG_CXXFLAGS # See Valentina.pri for more details. + } + } else { + *-g++{ + QMAKE_CXXFLAGS += $$GCC_DEBUG_CXXFLAGS # See Valentina.pri for more details. + } + } + +}else{ + # Release mode + + !unix:*-g++{ + QMAKE_CXXFLAGS += -fno-omit-frame-pointer # Need for exchndl.dll + } + + !macx:!win32-msvc*{ + # Turn on debug symbols in release mode on Unix systems. + # On Mac OS X temporarily disabled. TODO: find way how to strip binary file. + QMAKE_CXXFLAGS_RELEASE += -g -gdwarf-3 + QMAKE_CFLAGS_RELEASE += -g -gdwarf-3 + QMAKE_LFLAGS_RELEASE = + } +} diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h new file mode 100644 index 000000000..79d0c2179 --- /dev/null +++ b/src/libs/ifc/ifcdef.h @@ -0,0 +1,114 @@ +/************************************************************************ + ** + ** @file ifcdef.h + ** @author Roman Telezhynskyi + ** @date 10 12, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 IFCDEF_H +#define IFCDEF_H + +#include + +enum class Unit : char { Mm, Cm, Inch }; +enum class MeasurementsType : char { Standard, Individual }; + +static const quint32 null_id = 0; + +#define NULL_ID null_id//use this value for initialization variables that keeps id values. 0 mean uknown id value. +#define NULL_ID_STR "0" + +/* + * This macros SCASSERT (for Stop and Continue Assert) will break into the debugger on the line of the assert and allow + * you to continue afterwards should you choose to. + * idea: Q_ASSERT no longer pauses debugger - http://qt-project.org/forums/viewthread/13148 + * Usefull links: + * 1. What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__? - + * https://stackoverflow.com/questions/4384765/whats-the-difference-between-pretty-function-function-func + * + * 2. Windows Predefined Macros - http://msdn.microsoft.com/library/b0084kay.aspx + * + * 3. Windows DebugBreak function - http://msdn.microsoft.com/en-us/library/ms679297%28VS.85%29.aspx + * + * 4. Continue to debug after failed assertion on Linux? [C/C++] - + * https://stackoverflow.com/questions/1721543/continue-to-debug-after-failed-assertion-on-linux-c-c + */ +#ifndef QT_NO_DEBUG +#ifdef Q_OS_WIN32 +#ifdef Q_CC_MSVC +#define SCASSERT(cond) \ +{ \ + if (!(cond)) \ + { \ + qDebug("ASSERT: %s in %s (%s:%u)", \ + #cond, __FUNCSIG__, __FILE__, __LINE__); \ + DebugBreak(); \ + } \ +} \ + +#else + +#define SCASSERT(cond) \ +{ \ + if (!(cond)) \ + { \ + qDebug("ASSERT: %s in %s (%s:%u)", \ + #cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\ + DebugBreak(); \ + } \ +} \ + +#endif /*Q_CC_MSVC*/ +#else +#define SCASSERT(cond) \ +{ \ + if (!(cond)) \ + { \ + qDebug("ASSERT: %s in %s (%s:%u)", \ + #cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\ + std::raise(SIGTRAP); \ + } \ +} \ + +#endif /* Q_OS_WIN32 */ +#else // define but disable this function if debugging is not set +#define SCASSERT(cond) qt_noop(); +#endif /* QT_NO_DEBUG */ + +// Detect whether the compiler supports C++11 noexcept exception specifications. +# if defined(__clang__) +# if __has_feature(cxx_noexcept) +# define V_NOEXCEPT_EXPR(x) noexcept(x) // Clang 3.0 and above have noexcept +# endif +# elif defined(__GNUC__) +# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__GXX_EXPERIMENTAL_CXX0X__) +# define V_NOEXCEPT_EXPR(x) noexcept(x) // GCC 4.7 and following have noexcept +# endif +# elif defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 180021114 +# define QMUP_NOEXCEPT_EXPR(x) noexcept(x) +# else +# define V_NOEXCEPT_EXPR(x) +# endif + +#endif // IFCDEF_H diff --git a/src/app/share/resources/schema.qrc b/src/libs/ifc/schema.qrc similarity index 78% rename from src/app/share/resources/schema.qrc rename to src/libs/ifc/schema.qrc index 9209df5ca..ce37b86bc 100644 --- a/src/app/share/resources/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -1,7 +1,7 @@ - schema/pattern.xsd schema/individual_measurements.xsd schema/standard_measurements.xsd + schema/pattern/v0.1.1.xsd diff --git a/src/app/share/resources/schema/individual_measurements.xsd b/src/libs/ifc/schema/individual_measurements.xsd similarity index 100% rename from src/app/share/resources/schema/individual_measurements.xsd rename to src/libs/ifc/schema/individual_measurements.xsd diff --git a/src/app/share/resources/schema/pattern.xsd b/src/libs/ifc/schema/pattern/v0.1.1.xsd similarity index 100% rename from src/app/share/resources/schema/pattern.xsd rename to src/libs/ifc/schema/pattern/v0.1.1.xsd diff --git a/src/app/share/resources/schema/standard_measurements.xsd b/src/libs/ifc/schema/standard_measurements.xsd similarity index 100% rename from src/app/share/resources/schema/standard_measurements.xsd rename to src/libs/ifc/schema/standard_measurements.xsd diff --git a/src/libs/ifc/stable.cpp b/src/libs/ifc/stable.cpp new file mode 100644 index 000000000..877ab2ddf --- /dev/null +++ b/src/libs/ifc/stable.cpp @@ -0,0 +1,30 @@ +/************************************************************************ + ** + ** @file stable.cpp + ** @author Roman Telezhynskyi + ** @date 10 12, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 . + ** + *************************************************************************/ + +// Build the precompiled headers. +#include "stable.h" diff --git a/src/libs/ifc/stable.h b/src/libs/ifc/stable.h new file mode 100644 index 000000000..c2c2a7780 --- /dev/null +++ b/src/libs/ifc/stable.h @@ -0,0 +1,67 @@ +/************************************************************************ + ** + ** @file stable.h + ** @author Roman Telezhynskyi + ** @date 10 12, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 STABLE_H +#define STABLE_H + +/* I like to include this pragma too, so the build log indicates if pre-compiled headers were in use. */ +#ifndef __clang__ +#pragma message("Compiling precompiled headers for IFC library.\n") +#endif + +/* Add C includes here */ + +#if defined __cplusplus +/* Add C++ includes here */ + +#ifdef QT_CORE_LIB +#include +#endif + +#ifdef QT_XML_LIB +# include +#endif + +//In Windows you can't use those headers in all modes. +#if !defined(Q_OS_WIN) +# ifdef QT_PRINTSUPPORT_LIB +# include +# endif + +# ifdef QT_XMLPATTERNS_LIB +# include +# endif + +# ifdef QT_NETWORK_LIB +# include +# endif +#endif/*Q_OS_WIN*/ + +#endif/*__cplusplus*/ + +#endif // STABLE_H diff --git a/src/libs/ifc/xml/vabstractconverter.cpp b/src/libs/ifc/xml/vabstractconverter.cpp new file mode 100644 index 000000000..a5fec8d05 --- /dev/null +++ b/src/libs/ifc/xml/vabstractconverter.cpp @@ -0,0 +1,160 @@ +/************************************************************************ + ** + ** @file vabstractconverter.cpp + ** @author Roman Telezhynskyi + ** @date 10 12, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 "vabstractconverter.h" +#include "exception/vexception.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractConverter::VAbstractConverter(const QString &fileName) + :VDomDocument(), ver(0x0), fileName(fileName) +{ + this->setXMLContent(fileName); + const QString version = GetVersionStr(); + ver = GetVersion(version); +} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractConverter::~VAbstractConverter() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractConverter::Convert() const +{ + if (ver == MaxVer()) + { + return; + } + + QString error; + const QString backupFileName = fileName +".backup"; + if (SafeCopy(fileName, backupFileName, error) == false) + { + const QString errorMsg(tr("Error creation backup file: %1.").arg(error)); + throw VException(errorMsg); + } + + ApplyPatches(); + + QFile file(backupFileName); + file.remove(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractConverter::GetVersionStr() const +{ + const QDomNodeList nodeList = this->elementsByTagName(TagVersion); + if (nodeList.isEmpty()) + { + const QString errorMsg(tr("Couldn't get version information.")); + throw VException(errorMsg); + } + + if (nodeList.count() > 1) + { + const QString errorMsg(tr("Too many tags <%1> in file.").arg(TagVersion)); + throw VException(errorMsg); + } + + const QDomNode domNode = nodeList.at(0); + if (domNode.isNull() == false && domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + return domElement.text(); + } + } + return QString(QStringLiteral("0.0.0")); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VAbstractConverter::GetVersion(const QString &version) const +{ + ValidateVersion(version); + + QStringList ver = version.split("."); + + bool ok = false; + int major = ver.at(0).toInt(&ok); + if (ok == false) + { + return 0x0; + } + + ok = false; + int minor = ver.at(1).toInt(&ok); + if (ok == false) + { + return 0x0; + } + + ok = false; + int patch = ver.at(2).toInt(&ok); + if (ok == false) + { + return 0x0; + } + + return (major<<16)|(minor<<8)|(patch); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractConverter::ValidateVersion(const QString &version) const +{ + QRegExp rx(QStringLiteral("^(0|([1-9][0-9]*)).(0|([1-9][0-9]*)).(0|([1-9][0-9]*))$")); + + if (rx.exactMatch(version) == false) + { + const QString errorMsg(tr("Version \"%1\" invalid.").arg(version)); + throw VException(errorMsg); + } + + if (version == QLatin1String("0.0.0")) + { + const QString errorMsg(tr("Version \"0.0.0\" invalid.")); + throw VException(errorMsg); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractConverter::CheckVersion(int ver) const +{ + if (ver < MinVer()) + { + const QString errorMsg(tr("Invalid version. Minimum supported version is %1").arg(MinVerStr())); + throw VException(errorMsg); + } + + if (ver > MaxVer()) + { + const QString errorMsg(tr("Invalid version. Maximum supported version is %1").arg(MaxVerStr())); + throw VException(errorMsg); + } +} diff --git a/src/libs/ifc/xml/vabstractconverter.h b/src/libs/ifc/xml/vabstractconverter.h new file mode 100644 index 000000000..a4cc94ecd --- /dev/null +++ b/src/libs/ifc/xml/vabstractconverter.h @@ -0,0 +1,67 @@ +/************************************************************************ + ** + ** @file vabstractconverter.h + ** @author Roman Telezhynskyi + ** @date 10 12, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 VABSTRACTCONVERTER_H +#define VABSTRACTCONVERTER_H + +#include "vdomdocument.h" + +class VAbstractConverter :public VDomDocument +{ + +public: + VAbstractConverter(const QString &fileName); + virtual ~VAbstractConverter(); + + void Convert() const; + +protected: + int ver; + QString fileName; + + int GetVersion(const QString &version) const; + void CheckVersion(int ver) const; + + virtual int MinVer() const =0; + virtual int MaxVer() const =0; + + virtual QString MinVerStr() const =0; + virtual QString MaxVerStr() const =0; + + virtual QString XSDSchema(int ver) const =0; + virtual void ApplyPatches() const =0; + +private: + Q_DISABLE_COPY(VAbstractConverter) + + QString GetVersionStr() const; + + void ValidateVersion(const QString &version) const; +}; + +#endif // VABSTRACTCONVERTER_H diff --git a/src/app/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp similarity index 92% rename from src/app/xml/vdomdocument.cpp rename to src/libs/ifc/xml/vdomdocument.cpp index 56ecdcc94..5dcf8d698 100644 --- a/src/app/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -27,11 +27,9 @@ *************************************************************************/ #include "vdomdocument.h" -#include "../exception/vexceptionconversionerror.h" -#include "../exception/vexceptionemptyparameter.h" -#include "../exception/vexceptionbadid.h" -#include "../options.h" -#include "../core/vapplication.h" +#include "exception/vexceptionconversionerror.h" +#include "exception/vexceptionemptyparameter.h" +#include "exception/vexceptionbadid.h" #include #include @@ -100,8 +98,8 @@ const QString VDomDocument::UnitINCH = QStringLiteral("inch"); const QString VDomDocument::TagVersion = QStringLiteral("version"); //--------------------------------------------------------------------------------------------------------------------- -VDomDocument::VDomDocument(VContainer *data) - : QDomDocument(), data(data), map(QHash()) +VDomDocument::VDomDocument() + : QDomDocument(), map(QHash()) {} //--------------------------------------------------------------------------------------------------------------------- @@ -412,7 +410,7 @@ void VDomDocument::ValidateXML(const QString &schema, const QString &fileName) } //--------------------------------------------------------------------------------------------------------------------- -void VDomDocument::setContent(const QString &fileName) +void VDomDocument::setXMLContent(const QString &fileName) { QFile file(fileName); if (file.open(QIODevice::ReadOnly) == false) @@ -536,7 +534,7 @@ bool VDomDocument::SaveDocument(const QString &fileName, QString &error) tempFile.close(); } //Copy document to file - bool result = VApplication::SafeCopy(temp, fileName, error); + bool result = VDomDocument::SafeCopy(temp, fileName, error); tempFile.remove();//Clear temp file return result; @@ -635,3 +633,50 @@ QDomElement VDomDocument::NodeById(const quint32 &nodeId) } return domElement; } + +//--------------------------------------------------------------------------------------------------------------------- +bool VDomDocument::SafeCopy(const QString &source, const QString &destination, QString &error) +{ + bool result = false; + +#ifdef Q_OS_WIN32 + qt_ntfs_permission_lookup++; // turn checking on +#endif /*Q_OS_WIN32*/ + + QFile patternFile(destination); + patternFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner); + // We need here temporary file because we want restore document after error of copying temp file. + QTemporaryFile tempOfPattern; + if (tempOfPattern.open()) + { + if (patternFile.exists()) + { + patternFile.copy(tempOfPattern.fileName()); + } + } + if ( patternFile.exists() == false || patternFile.remove() ) + { + QFile sourceFile(source); + if ( sourceFile.copy(patternFile.fileName()) == false ) + { + error = tr("Could not copy temp file to document file"); + tempOfPattern.copy(destination); + result = false; + } + else + { + result = true; + } + } + else + { + error = tr("Could not remove document file"); + result = false; + } + +#ifdef Q_OS_WIN32 + qt_ntfs_permission_lookup--; // turn off check permission again +#endif /*Q_OS_WIN32*/ + + return result; +} diff --git a/src/app/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h similarity index 96% rename from src/app/xml/vdomdocument.h rename to src/libs/ifc/xml/vdomdocument.h index 132bc8e35..34aa2215f 100644 --- a/src/app/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -31,8 +31,10 @@ #include #include -#include "../container/vcontainer.h" #include +#include + +#include "ifcdef.h" Q_DECLARE_LOGGING_CATEGORY(vXML) @@ -80,7 +82,7 @@ public: /** * @param data container with variables */ - VDomDocument(VContainer *data); + VDomDocument(); virtual ~VDomDocument(); QDomElement elementById(const QString& id); void removeAllChilds(QDomElement &element); @@ -104,7 +106,7 @@ public: qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; static void ValidateXML(const QString &schema, const QString &fileName); - void setContent(const QString &fileName); + void setXMLContent(const QString &fileName); static Unit StrToUnits(const QString &unit); static QString UnitsToStr(const Unit &unit, const bool translate = false); virtual bool SaveDocument(const QString &fileName, QString &error); @@ -116,12 +118,12 @@ public: QDomNode ParentNodeById(const quint32 &nodeId); QDomElement CloneNodeById(const quint32 &nodeId); QDomElement NodeById(const quint32 &nodeId); -protected: - /** @brief data container with data. */ - VContainer *data; + static bool SafeCopy(const QString &source, const QString &destination, QString &error); +protected: void setTagText(const QString &tag, const QString &text); QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const; + private: Q_DISABLE_COPY(VDomDocument) /** @brief Map used for finding element by id. */ diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp new file mode 100644 index 000000000..fc4241195 --- /dev/null +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -0,0 +1,122 @@ +/************************************************************************ + ** + ** @file vpatternconverter.cpp + ** @author Roman Telezhynskyi + ** @date 11 12, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 "vpatternconverter.h" +#include "exception/vexception.h" + +#include + +const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.1"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.1.1"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.1.1.xsd"); + +//--------------------------------------------------------------------------------------------------------------------- +VPatternConverter::VPatternConverter(const QString &fileName) + :VAbstractConverter(fileName) +{ + const QString schema = XSDSchema(ver); + ValidateXML(schema, fileName); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPatternConverter::~VPatternConverter() +{} + +//--------------------------------------------------------------------------------------------------------------------- +int VPatternConverter::MinVer() const +{ + return GetVersion(PatternMinVerStr); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VPatternConverter::MaxVer() const +{ + return GetVersion(PatternMaxVerStr); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPatternConverter::MinVerStr() const +{ + return PatternMinVerStr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPatternConverter::MaxVerStr() const +{ + return PatternMaxVerStr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPatternConverter::XSDSchema(int ver) const +{ + CheckVersion(ver); + + switch(ver) + { + case (0x000101): + return CurrentSchema; + default: + { + const QString errorMsg(tr("Unexpected version \"%1\".").arg(ver, 0, 16)); + throw VException(errorMsg); + break; + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ApplyPatches() const +{ + try + { + switch(ver) + { + case (0x000101): + break; + default: + break; + } + } + catch (VException &e) + { + QString error; + const QString backupFileName = fileName +".backup"; + if (SafeCopy(backupFileName, fileName, error) == false) + { + const QString errorMsg(tr("Error restoring backup file: %1.").arg(error)); + VException excep(errorMsg); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + + QFile file(backupFileName); + file.remove(); + + throw e; + } +} diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h new file mode 100644 index 000000000..e4d3db2b3 --- /dev/null +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -0,0 +1,58 @@ +/************************************************************************ + ** + ** @file vpatternconverter.h + ** @author Roman Telezhynskyi + ** @date 11 12, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 VPATTERNCONVERTER_H +#define VPATTERNCONVERTER_H + +#include "vabstractconverter.h" + +class VPatternConverter : public VAbstractConverter +{ +public: + VPatternConverter(const QString &fileName); + virtual ~VPatternConverter(); + + static const QString PatternMaxVerStr; + static const QString CurrentSchema; + +protected: + virtual int MinVer() const; + virtual int MaxVer() const; + + virtual QString MinVerStr() const; + virtual QString MaxVerStr() const; + + QString XSDSchema(int ver) const; + virtual void ApplyPatches() const; + +private: + Q_DISABLE_COPY(VPatternConverter) + static const QString PatternMinVerStr; +}; + +#endif // VPATTERNCONVERTER_H diff --git a/src/libs/ifc/xml/xml.pri b/src/libs/ifc/xml/xml.pri new file mode 100644 index 000000000..c64e090e9 --- /dev/null +++ b/src/libs/ifc/xml/xml.pri @@ -0,0 +1,12 @@ +# ADD TO EACH PATH $$PWD VARIABLE!!!!!! +# This need for corect working file translations.pro + +HEADERS += \ + $$PWD/vabstractconverter.h \ + $$PWD/vdomdocument.h \ + $$PWD/vpatternconverter.h + +SOURCES += \ + $$PWD/vabstractconverter.cpp \ + $$PWD/vdomdocument.cpp \ + $$PWD/vpatternconverter.cpp diff --git a/src/libs/libs.pro b/src/libs/libs.pro index bd493ca45..5084ac28c 100644 --- a/src/libs/libs.pro +++ b/src/libs/libs.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs CONFIG += ordered SUBDIRS = qmuparser \ - vpropertyexplorer + vpropertyexplorer \ + ifc