diff --git a/src/app/puzzle/undocommands/vpundocommand.cpp b/src/app/puzzle/undocommands/vpundocommand.cpp index bf1918940..c6f8786f0 100644 --- a/src/app/puzzle/undocommands/vpundocommand.cpp +++ b/src/app/puzzle/undocommands/vpundocommand.cpp @@ -41,11 +41,13 @@ QT_WARNING_POP //--------------------------------------------------------------------------------------------------------------------- VPUndoCommand::VPUndoCommand(QUndoCommand *parent) - : QUndoCommand(parent) -{} + : QUndoCommand(parent) +{ +} //--------------------------------------------------------------------------------------------------------------------- VPUndoCommand::VPUndoCommand(bool allowMerge, QUndoCommand *parent) - : QUndoCommand(parent), - m_allowMerge(allowMerge) -{} + : QUndoCommand(parent), + m_allowMerge(allowMerge) +{ +} diff --git a/src/app/tape/dialogs/dialogmdatabase.cpp b/src/app/tape/dialogs/dialogmdatabase.cpp index c4c0ea74e..3b0c8526b 100644 --- a/src/app/tape/dialogs/dialogmdatabase.cpp +++ b/src/app/tape/dialogs/dialogmdatabase.cpp @@ -27,9 +27,9 @@ *************************************************************************/ #include "dialogmdatabase.h" -#include "ui_dialogmdatabase.h" #include "../mapplication.h" #include "../vpatterndb/measurements.h" +#include "ui_dialogmdatabase.h" #include "../vmisc/compatibility.h" #include @@ -39,10 +39,10 @@ //--------------------------------------------------------------------------------------------------------------------- DialogMDataBase::DialogMDataBase(const QStringList &list, QWidget *parent) - :QDialog(parent), - ui(new Ui::DialogMDataBase), - m_selectMode(true), - m_list(list) + : QDialog(parent), + ui(new Ui::DialogMDataBase), + m_selectMode(true), + m_list(list) { ui->setupUi(this); @@ -64,9 +64,9 @@ DialogMDataBase::DialogMDataBase(const QStringList &list, QWidget *parent) //--------------------------------------------------------------------------------------------------------------------- DialogMDataBase::DialogMDataBase(QWidget *parent) - :QDialog(parent), - ui(new Ui::DialogMDataBase), - m_selectMode(false) + : QDialog(parent), + ui(new Ui::DialogMDataBase), + m_selectMode(false) { ui->setupUi(this); @@ -100,7 +100,7 @@ auto DialogMDataBase::GetNewNames() const -> QStringList { QStringList newNames; QTreeWidgetItemIterator it(ui->treeWidget, - QTreeWidgetItemIterator::NoChildren | QTreeWidgetItemIterator::Checked ); + QTreeWidgetItemIterator::NoChildren | QTreeWidgetItemIterator::Checked); while (*it) { const QString name = (*it)->data(0, Qt::UserRole).toString(); @@ -119,22 +119,22 @@ auto DialogMDataBase::GetNewNames() const -> QStringList //--------------------------------------------------------------------------------------------------------------------- void DialogMDataBase::RetranslateGroups() { - RetranslateGroup(m_groupA, "A. " + tr("Direct Height", "Measurement section"), ListGroupA()); - RetranslateGroup(m_groupB, "B. " + tr("Direct Width", "Measurement section"), ListGroupB()); - RetranslateGroup(m_groupC, "C. " + tr("Indentation", "Measurement section"), ListGroupC()); - RetranslateGroup(m_groupD, "D. " + tr("Hand", "Measurement section"), ListGroupD()); - RetranslateGroup(m_groupE, "E. " + tr("Foot", "Measurement section"), ListGroupE()); - RetranslateGroup(m_groupF, "F. " + tr("Head", "Measurement section"), ListGroupF()); - RetranslateGroup(m_groupG, "G. " + tr("Circumference and Arc", "Measurement section"), ListGroupG()); - RetranslateGroup(m_groupH, "H. " + tr("Vertical", "Measurement section"), ListGroupH()); - RetranslateGroup(m_groupI, "I. " + tr("Horizontal", "Measurement section"), ListGroupI()); - RetranslateGroup(m_groupJ, "J. " + tr("Bust", "Measurement section"), ListGroupJ()); - RetranslateGroup(m_groupK, "K. " + tr("Balance", "Measurement section"), ListGroupK()); - RetranslateGroup(m_groupL, "L. " + tr("Arm", "Measurement section"), ListGroupL()); - RetranslateGroup(m_groupM, "M. " + tr("Leg", "Measurement section"), ListGroupM()); - RetranslateGroup(m_groupN, "N. " + tr("Crotch and Rise", "Measurement section"), ListGroupN()); - RetranslateGroup(m_groupO, "O. " + tr("Men & Tailoring", "Measurement section"), ListGroupO()); - RetranslateGroup(m_groupP, "P. " + tr("Historical & Specialty", "Measurement section"), ListGroupP()); + RetranslateGroup(m_groupA, "A. " + tr("Direct Height", "Measurement section"), ListGroupA()); + RetranslateGroup(m_groupB, "B. " + tr("Direct Width", "Measurement section"), ListGroupB()); + RetranslateGroup(m_groupC, "C. " + tr("Indentation", "Measurement section"), ListGroupC()); + RetranslateGroup(m_groupD, "D. " + tr("Hand", "Measurement section"), ListGroupD()); + RetranslateGroup(m_groupE, "E. " + tr("Foot", "Measurement section"), ListGroupE()); + RetranslateGroup(m_groupF, "F. " + tr("Head", "Measurement section"), ListGroupF()); + RetranslateGroup(m_groupG, "G. " + tr("Circumference and Arc", "Measurement section"), ListGroupG()); + RetranslateGroup(m_groupH, "H. " + tr("Vertical", "Measurement section"), ListGroupH()); + RetranslateGroup(m_groupI, "I. " + tr("Horizontal", "Measurement section"), ListGroupI()); + RetranslateGroup(m_groupJ, "J. " + tr("Bust", "Measurement section"), ListGroupJ()); + RetranslateGroup(m_groupK, "K. " + tr("Balance", "Measurement section"), ListGroupK()); + RetranslateGroup(m_groupL, "L. " + tr("Arm", "Measurement section"), ListGroupL()); + RetranslateGroup(m_groupM, "M. " + tr("Leg", "Measurement section"), ListGroupM()); + RetranslateGroup(m_groupN, "N. " + tr("Crotch and Rise", "Measurement section"), ListGroupN()); + RetranslateGroup(m_groupO, "O. " + tr("Men & Tailoring", "Measurement section"), ListGroupO()); + RetranslateGroup(m_groupP, "P. " + tr("Historical & Specialty", "Measurement section"), ListGroupP()); RetranslateGroup(m_groupQ, "Q. " + tr("Patternmaking measurements", "Measurement section"), ListGroupQ()); ShowDescription(ui->treeWidget->currentItem(), 0); @@ -144,8 +144,8 @@ void DialogMDataBase::RetranslateGroups() auto DialogMDataBase::ImgTag(const QString &number) -> QString { QString imgUrl(QStringLiteral("")); // In case of error - const QString filePath = QStringLiteral("://diagrams/%1.svg") - .arg(MapDiagrams(VAbstractApplication::VApp()->TrVars(), number)); + const QString filePath = + QStringLiteral("://diagrams/%1.svg").arg(MapDiagrams(VAbstractApplication::VApp()->TrVars(), number)); if (QFileInfo::exists(filePath)) { // Load your SVG @@ -203,7 +203,7 @@ auto DialogMDataBase::eventFilter(QObject *target, QEvent *event) -> bool if (target == ui->treeWidget && event->type() == QEvent::KeyPress) { auto *keyEvent = static_cast(event); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) - switch(keyEvent->key()) + switch (keyEvent->key()) { case Qt::Key_Up: { @@ -262,8 +262,7 @@ void DialogMDataBase::UpdateChecks(QTreeWidgetItem *item, int column) } for (int j = 0; j < parent->childCount(); ++j) { - if (j != parent->indexOfChild(item) - && item->checkState(0) != parent->child(j)->checkState(0)) + if (j != parent->indexOfChild(item) && item->checkState(0) != parent->child(j)->checkState(0)) { diff = true; } @@ -379,22 +378,22 @@ void DialogMDataBase::FilterMeasurements(const QString &search) //--------------------------------------------------------------------------------------------------------------------- void DialogMDataBase::InitDataBase(const QStringList &list) { - InitGroup(&m_groupA, "A. " + tr("Direct Height", "Measurement section"), ListGroupA(), list); - InitGroup(&m_groupB, "B. " + tr("Direct Width", "Measurement section"), ListGroupB(), list); - InitGroup(&m_groupC, "C. " + tr("Indentation", "Measurement section"), ListGroupC(), list); - InitGroup(&m_groupD, "D. " + tr("Hand", "Measurement section"), ListGroupD(), list); - InitGroup(&m_groupE, "E. " + tr("Foot", "Measurement section"), ListGroupE(), list); - InitGroup(&m_groupF, "F. " + tr("Head", "Measurement section"), ListGroupF(), list); - InitGroup(&m_groupG, "G. " + tr("Circumference and Arc", "Measurement section"), ListGroupG(), list); - InitGroup(&m_groupH, "H. " + tr("Vertical", "Measurement section"), ListGroupH(), list); - InitGroup(&m_groupI, "I. " + tr("Horizontal", "Measurement section"), ListGroupI(), list); - InitGroup(&m_groupJ, "J. " + tr("Bust", "Measurement section"), ListGroupJ(), list); - InitGroup(&m_groupK, "K. " + tr("Balance", "Measurement section"), ListGroupK(), list); - InitGroup(&m_groupL, "L. " + tr("Arm", "Measurement section"), ListGroupL(), list); - InitGroup(&m_groupM, "M. " + tr("Leg", "Measurement section"), ListGroupM(), list); - InitGroup(&m_groupN, "N. " + tr("Crotch and Rise", "Measurement section"), ListGroupN(), list); - InitGroup(&m_groupO, "O. " + tr("Men & Tailoring", "Measurement section"), ListGroupO(), list); - InitGroup(&m_groupP, "P. " + tr("Historical & Specialty", "Measurement section"), ListGroupP(), list); + InitGroup(&m_groupA, "A. " + tr("Direct Height", "Measurement section"), ListGroupA(), list); + InitGroup(&m_groupB, "B. " + tr("Direct Width", "Measurement section"), ListGroupB(), list); + InitGroup(&m_groupC, "C. " + tr("Indentation", "Measurement section"), ListGroupC(), list); + InitGroup(&m_groupD, "D. " + tr("Hand", "Measurement section"), ListGroupD(), list); + InitGroup(&m_groupE, "E. " + tr("Foot", "Measurement section"), ListGroupE(), list); + InitGroup(&m_groupF, "F. " + tr("Head", "Measurement section"), ListGroupF(), list); + InitGroup(&m_groupG, "G. " + tr("Circumference and Arc", "Measurement section"), ListGroupG(), list); + InitGroup(&m_groupH, "H. " + tr("Vertical", "Measurement section"), ListGroupH(), list); + InitGroup(&m_groupI, "I. " + tr("Horizontal", "Measurement section"), ListGroupI(), list); + InitGroup(&m_groupJ, "J. " + tr("Bust", "Measurement section"), ListGroupJ(), list); + InitGroup(&m_groupK, "K. " + tr("Balance", "Measurement section"), ListGroupK(), list); + InitGroup(&m_groupL, "L. " + tr("Arm", "Measurement section"), ListGroupL(), list); + InitGroup(&m_groupM, "M. " + tr("Leg", "Measurement section"), ListGroupM(), list); + InitGroup(&m_groupN, "N. " + tr("Crotch and Rise", "Measurement section"), ListGroupN(), list); + InitGroup(&m_groupO, "O. " + tr("Men & Tailoring", "Measurement section"), ListGroupO(), list); + InitGroup(&m_groupP, "P. " + tr("Historical & Specialty", "Measurement section"), ListGroupP(), list); InitGroup(&m_groupQ, "Q. " + tr("Patternmaking measurements", "Measurement section"), ListGroupQ(), list); } @@ -415,14 +414,14 @@ void DialogMDataBase::FilterGroup(QTreeWidgetItem *group, const QString &search) SCASSERT(group != nullptr) bool match = false; - for (int i=0; i < group->childCount(); ++i) + for (int i = 0; i < group->childCount(); ++i) { QTreeWidgetItem *childItem = group->child(i); - const QString description = QTextDocumentFragment::fromHtml(ItemFullDescription(childItem, false)) - .toPlainText(); + const QString description = + QTextDocumentFragment::fromHtml(ItemFullDescription(childItem, false)).toPlainText(); - const bool hidden = not childItem->text(0).contains(search, Qt::CaseInsensitive) - && not description.contains(search, Qt::CaseInsensitive); + const bool hidden = not childItem->text(0).contains(search, Qt::CaseInsensitive) && + not description.contains(search, Qt::CaseInsensitive); childItem->setHidden(hidden); if (not hidden) @@ -474,7 +473,7 @@ void DialogMDataBase::AddMeasurement(QTreeWidgetItem *group, const QString &name } const QString text = VAbstractApplication::VApp()->TrVars()->MNumber(name) + ". " + - VAbstractApplication::VApp()->TrVars()->MToUser(name); + VAbstractApplication::VApp()->TrVars()->MToUser(name); m->setText(0, text); m->setToolTip(0, text); m->setData(0, Qt::UserRole, name); @@ -518,8 +517,8 @@ auto DialogMDataBase::ItemFullDescription(QTreeWidgetItem *item, bool showImage) "normal\"> %1
%2. %3

" "

%4

") - .arg(imgTag, number, VAbstractApplication::VApp()->TrVars()->GuiText(name), - VAbstractApplication::VApp()->TrVars()->Description(name)); + .arg(imgTag, number, VAbstractApplication::VApp()->TrVars()->GuiText(name), + VAbstractApplication::VApp()->TrVars()->Description(name)); return text; } @@ -530,7 +529,7 @@ void DialogMDataBase::RetranslateGroup(QTreeWidgetItem *group, const QString &gr group->setText(0, groupText); group->setToolTip(0, groupText); - for (int i=0; iTrVars()->MNumber(name) + ". " + - VAbstractApplication::VApp()->TrVars()->MToUser(name); + VAbstractApplication::VApp()->TrVars()->MToUser(name); QTreeWidgetItem *m = group->child(index); m->setText(0, text); @@ -577,43 +576,27 @@ auto DialogMDataBase::GlobalCheckState() const -> Qt::CheckState if (m_selectMode) { - if (m_groupA->checkState(0) == Qt::Unchecked && - m_groupB->checkState(0) == Qt::Unchecked && - m_groupC->checkState(0) == Qt::Unchecked && - m_groupD->checkState(0) == Qt::Unchecked && - m_groupE->checkState(0) == Qt::Unchecked && - m_groupF->checkState(0) == Qt::Unchecked && - m_groupG->checkState(0) == Qt::Unchecked && - m_groupH->checkState(0) == Qt::Unchecked && - m_groupI->checkState(0) == Qt::Unchecked && - m_groupJ->checkState(0) == Qt::Unchecked && - m_groupK->checkState(0) == Qt::Unchecked && - m_groupL->checkState(0) == Qt::Unchecked && - m_groupM->checkState(0) == Qt::Unchecked && - m_groupN->checkState(0) == Qt::Unchecked && - m_groupO->checkState(0) == Qt::Unchecked && - m_groupP->checkState(0) == Qt::Unchecked && + if (m_groupA->checkState(0) == Qt::Unchecked && m_groupB->checkState(0) == Qt::Unchecked && + m_groupC->checkState(0) == Qt::Unchecked && m_groupD->checkState(0) == Qt::Unchecked && + m_groupE->checkState(0) == Qt::Unchecked && m_groupF->checkState(0) == Qt::Unchecked && + m_groupG->checkState(0) == Qt::Unchecked && m_groupH->checkState(0) == Qt::Unchecked && + m_groupI->checkState(0) == Qt::Unchecked && m_groupJ->checkState(0) == Qt::Unchecked && + m_groupK->checkState(0) == Qt::Unchecked && m_groupL->checkState(0) == Qt::Unchecked && + m_groupM->checkState(0) == Qt::Unchecked && m_groupN->checkState(0) == Qt::Unchecked && + m_groupO->checkState(0) == Qt::Unchecked && m_groupP->checkState(0) == Qt::Unchecked && m_groupQ->checkState(0) == Qt::Unchecked) { return Qt::Checked; } - if (m_groupA->checkState(0) == Qt::Checked && - m_groupB->checkState(0) == Qt::Checked && - m_groupC->checkState(0) == Qt::Checked && - m_groupD->checkState(0) == Qt::Checked && - m_groupE->checkState(0) == Qt::Checked && - m_groupF->checkState(0) == Qt::Checked && - m_groupG->checkState(0) == Qt::Checked && - m_groupH->checkState(0) == Qt::Checked && - m_groupI->checkState(0) == Qt::Checked && - m_groupJ->checkState(0) == Qt::Checked && - m_groupK->checkState(0) == Qt::Checked && - m_groupL->checkState(0) == Qt::Checked && - m_groupM->checkState(0) == Qt::Checked && - m_groupN->checkState(0) == Qt::Checked && - m_groupO->checkState(0) == Qt::Checked && - m_groupP->checkState(0) == Qt::Checked && + if (m_groupA->checkState(0) == Qt::Checked && m_groupB->checkState(0) == Qt::Checked && + m_groupC->checkState(0) == Qt::Checked && m_groupD->checkState(0) == Qt::Checked && + m_groupE->checkState(0) == Qt::Checked && m_groupF->checkState(0) == Qt::Checked && + m_groupG->checkState(0) == Qt::Checked && m_groupH->checkState(0) == Qt::Checked && + m_groupI->checkState(0) == Qt::Checked && m_groupJ->checkState(0) == Qt::Checked && + m_groupK->checkState(0) == Qt::Checked && m_groupL->checkState(0) == Qt::Checked && + m_groupM->checkState(0) == Qt::Checked && m_groupN->checkState(0) == Qt::Checked && + m_groupO->checkState(0) == Qt::Checked && m_groupP->checkState(0) == Qt::Checked && m_groupQ->checkState(0) == Qt::Checked) { return Qt::Unchecked; diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index 10aa963c0..37256c9cf 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -28,13 +28,14 @@ #include "dialogsavelayout.h" #include "../core/vapplication.h" +#include "../ifc/exception/vexception.h" +#include "../vlayout/vlayoutexporter.h" #include "../vmisc/vvalentinasettings.h" #include "ui_dialogsavelayout.h" + #if QT_VERSION < QT_VERSION_CHECK(5, 7, 0) #include "../vmisc/backport/qoverload.h" #endif // QT_VERSION < QT_VERSION_CHECK(5, 7, 0) -#include "../ifc/exception/vexception.h" -#include "../vlayout/vlayoutexporter.h" #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/diagnostic.h" diff --git a/src/libs/ifc/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h index a39530f35..8a534ccc7 100644 --- a/src/libs/ifc/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -35,20 +35,20 @@ #include #include #include -#include -#include #include #include -#include +#include #include +#include +#include #include "../ifcdef.h" +#include "../qmuparser/qmudef.h" #include "../vmisc/def.h" #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/diagnostic.h" #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/literals.h" -#include "../qmuparser/qmudef.h" class QDomElement; class QDomNode; @@ -84,6 +84,7 @@ QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor") class VDomDocument : public QObject, public QDomDocument { Q_OBJECT // NOLINT + public: static const QString AttrId; static const QString AttrText; @@ -100,19 +101,18 @@ public: virtual ~VDomDocument(); auto elementById(quint32 id, const QString &tagName = QString(), bool updateCache = true) -> QDomElement; - template - void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const; + template void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const; template void SetAttributeOrRemoveIf(QDomElement &domElement, const QString &name, const T &value, - const std::function &removeCondition) const; + const std::function &removeCondition) const; static auto GetParametrUInt(const QDomElement &domElement, const QString &name, const QString &defValue) -> quint32; static auto GetParametrInt(const QDomElement &domElement, const QString &name, const QString &defValue) -> int; static auto GetParametrBool(const QDomElement &domElement, const QString &name, const QString &defValue) -> bool; static auto GetParametrUsage(const QDomElement &domElement, const QString &name) -> NodeUsage; - static void SetParametrUsage(QDomElement& domElement, const QString &name, const NodeUsage &value); + static void SetParametrUsage(QDomElement &domElement, const QString &name, const NodeUsage &value); static auto GetParametrString(const QDomElement &domElement, const QString &name, const QString &defValue = QString()) -> QString; @@ -120,7 +120,7 @@ public: static auto GetParametrDouble(const QDomElement &domElement, const QString &name, const QString &defValue) -> qreal; static auto GetParametrId(const QDomElement &domElement) -> quint32; - virtual void setXMLContent(const QString &fileName); + virtual void setXMLContent(const QString &fileName); static auto UnitsHelpString() -> QString; auto CreateElementWithText(const QString &tagName, const QString &text) -> QDomElement; @@ -131,7 +131,7 @@ public: auto Patch() const -> QString; virtual auto GetFormatVersionStr() const -> QString; static auto GetFormatVersion(const QString &version) -> unsigned; - static void RemoveAllChildren(QDomElement &domElement); + static void RemoveAllChildren(QDomElement &domElement); auto ParentNodeById(const quint32 &nodeId) -> QDomNode; auto CloneNodeById(const quint32 &nodeId) -> QDomElement; @@ -140,9 +140,9 @@ public: static auto SafeCopy(const QString &source, const QString &destination, QString &error) -> bool; auto GetLabelTemplate(const QDomElement &element) const -> QVector; - void SetLabelTemplate(QDomElement &element, const QVector &lines); + void SetLabelTemplate(QDomElement &element, const QVector &lines); - void TestUniqueId() const; + void TestUniqueId() const; void RefreshElementIdCache(); @@ -153,7 +153,7 @@ protected: auto setTagText(QDomElement &domElement, const QString &text) -> bool; auto UniqueTag(const QString &tagName) const -> QDomElement; auto UniqueTagText(const QString &tagName, const QString &defVal = QString()) const -> QString; - void CollectId(const QDomElement &node, QVector &vector)const; + void CollectId(const QDomElement &node, QVector &vector) const; static void ValidateVersion(const QString &version); @@ -164,7 +164,7 @@ private: // cppcheck-suppress unknownMacro Q_DISABLE_COPY_MOVE(VDomDocument) // NOLINT /** @brief Map used for finding element by id. */ - QHash m_elementIdCache; + QHash m_elementIdCache; QFutureWatcher> *m_watcher; static auto find(QHash &cache, const QDomElement &node, quint32 id) -> bool; @@ -223,14 +223,14 @@ template <> inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, const MeasurementsType &value) const { - domElement.setAttribute(name, value == MeasurementsType::Multisize ? QStringLiteral("multisize") : - QStringLiteral("individual")); + domElement.setAttribute(name, value == MeasurementsType::Multisize ? QStringLiteral("multisize") + : QStringLiteral("individual")); } //--------------------------------------------------------------------------------------------------------------------- template inline void VDomDocument::SetAttributeOrRemoveIf(QDomElement &domElement, const QString &name, const T &value, - const std::function &removeCondition) const + const std::function &removeCondition) const { not removeCondition(value) ? SetAttribute(domElement, name, value) : domElement.removeAttribute(name); } diff --git a/src/libs/qmuparser/qmudef.h b/src/libs/qmuparser/qmudef.h index 8e7047e25..cbc3c0042 100644 --- a/src/libs/qmuparser/qmudef.h +++ b/src/libs/qmuparser/qmudef.h @@ -90,6 +90,10 @@ Class &operator=(Class &&) = delete; #endif +#ifndef Q_DISABLE_ASSIGN +#define Q_DISABLE_ASSIGN(Class) Class &operator=(const Class &) = delete; +#endif + #ifndef Q_DISABLE_ASSIGN_MOVE #define Q_DISABLE_ASSIGN_MOVE(Class) \ Q_DISABLE_ASSIGN(Class) \ diff --git a/src/libs/qmuparser/qmuformulabase.cpp b/src/libs/qmuparser/qmuformulabase.cpp index 2a4ae5a3b..335e8fded 100644 --- a/src/libs/qmuparser/qmuformulabase.cpp +++ b/src/libs/qmuparser/qmuformulabase.cpp @@ -34,7 +34,7 @@ namespace qmu //--------------------------------------------------------------------------------------------------------------------- QmuFormulaBase::QmuFormulaBase() - :QmuParser() + : QmuParser() { } @@ -55,22 +55,25 @@ void QmuFormulaBase::InitCharSets() { QString symbolsStr; { - //String with all unique symbols for supported alphabets. - //See script alphabets.py for generation and more information. - //Note. MSVC doesn't support normal string concatenation for long string. That's why we use QStringList in this - //case. - const QStringList symbols - { - QStringLiteral("ցЀĆЈVӧĎАғΕĖӅИқΝĞơРңњΥĦШҫ̆έجگĮаҳѕεشԶиһνԾрÃυلՆӝшËύՎїPÓՖXӛӟŞãզhëҔծpóӞնxßվāŁЃֆĉЋΊCŬđҐГΒęҘЛΚŘġҠУGا"), - QStringLiteral("հЫΪŪدԱҰгβطԹõлκKՁÀуςهՉÈыvیՑÐSOřӘћաőcӐթèkàѓżűðsķչøӥӔĀփӣІĈΏЎґĐΗЖҙĘȚΟОҡĠآΧЦتίЮұİزηжԸغẽοоÁՀقχц"), - QStringLiteral("ÉՈيюÑՐђӋіәťӆўáŠĺѐfөըnñŰӤӨӹոľЁրăЉŭċΌБӸēłΔҖЙŤěΜӜDСձģΤӰЩīņحάҮбưԳصδHйԻŇμӴсՃمτƠщՋόєLQŹՓŕÖYśÞaգĽ"), - QStringLiteral("æiŽիӓîqճöyջþĂօЄӦΉĊЌΑĒДҗјΙȘĚМΡéĵĢФūӚΩبĪЬүќαذԲдҷιظԺмρՂфÇωوՊьÏՒTŚĻJբdçժlïӪղtպӫAւąЇΆčŃЏΎĕӯЗΖEțŮ"), - QStringLiteral("ĝПΞأĥĹЧΦثÆӳЯήIسŲԵзζԽпξكՅÄчφNMՍӌяώӢӲՕÔWÎŝÜџёźեägխoӒյôwĶBžսüЂĄև̈ЊČƏљΓВҕĔӮΛКĜΣТҥĤکΫЪƯخγвŅԴϊضλкԼ"), - QStringLiteral("ĴσтÅՄنϋъÍՌRӕՔZÝŜbåդﻩjíլļrӵմӱzýռپêЅքćچΈЍďΐҒЕůėژșΘØҚНğńءΠFҢХħΨҪЭųįҶرΰҲеԷňعθҺнԿفπÂхՇψÊэšՏÒUəÚѝ"), - QStringLiteral("ŻşҤӑâeէŐımկòuշÕúտŔ") - }; + // String with all unique symbols for supported alphabets. + // See script alphabets.py for generation and more information. + // Note. MSVC doesn't support normal string concatenation for long string. That's why we use QStringList in this + // case. + const QStringList symbols{ + QStringLiteral( + "ցЀĆЈVӧĎАғΕĖӅИқΝĞơРңњΥĦШҫ̆έجگĮаҳѕεشԶиһνԾрÃυلՆӝшËύՎїPÓՖXӛӟŞãզhëҔծpóӞնxßվāŁЃֆĉЋΊCŬđҐГΒęҘЛΚŘġҠУGا"), + QStringLiteral("հЫΪŪدԱҰгβطԹõлκKՁÀуςهՉÈыvیՑÐSOřӘћաőcӐթèkàѓżűðsķչøӥӔĀփӣІĈΏЎґĐΗЖҙĘȚΟОҡĠآΧЦتίЮұİزηжԸغẽοоÁՀقχц"), + QStringLiteral( + "ÉՈيюÑՐђӋіәťӆўáŠĺѐfөըnñŰӤӨӹոľЁրăЉŭċΌБӸēłΔҖЙŤěΜӜDСձģΤӰЩīņحάҮбưԳصδHйԻŇμӴсՃمτƠщՋόєLQŹՓŕÖYśÞaգĽ"), + QStringLiteral( + "æiŽիӓîqճöyջþĂօЄӦΉĊЌΑĒДҗјΙȘĚМΡéĵĢФūӚΩبĪЬүќαذԲдҷιظԺмρՂфÇωوՊьÏՒTŚĻJբdçժlïӪղtպӫAւąЇΆčŃЏΎĕӯЗΖEțŮ"), + QStringLiteral( + "ĝПΞأĥĹЧΦثÆӳЯήIسŲԵзζԽпξكՅÄчφNMՍӌяώӢӲՕÔWÎŝÜџёźեägխoӒյôwĶBžսüЂĄև̈ЊČƏљΓВҕĔӮΛКĜΣТҥĤکΫЪƯخγвŅԴϊضλкԼ"), + QStringLiteral( + "ĴσтÅՄنϋъÍՌRӕՔZÝŜbåդﻩjíլļrӵմӱzýռپêЅքćچΈЍďΐҒЕůėژșΘØҚНğńءΠFҢХħΨҪЭųįҶرΰҲеԷňعθҺнԿفπÂхՇψÊэšՏÒUəÚѝ"), + QStringLiteral("ŻşҤӑâeէŐımկòuշÕúտŔ")}; - symbolsStr = symbols.join(QString()); + symbolsStr = symbols.join(QString()); } INIT_LOCALE_VARIABLES(m_locale); @@ -153,7 +156,7 @@ void QmuFormulaBase::SetSepForTr(bool osSeparator, bool fromUser) } } - SetSepForEval();//Same separators (internal) as for eval. + SetSepForEval(); // Same separators (internal) as for eval. } //--------------------------------------------------------------------------------------------------------------------- @@ -177,13 +180,13 @@ void QmuFormulaBase::SetSepForEval() * @param map map with tokens * @param val token that need delete */ -void QmuFormulaBase::RemoveAll(QMap &map, const QString &val) +void QmuFormulaBase::RemoveAll(QMap &map, const QString &val) { - const QList listKeys = map.keys(val);//Take all keys that contain token. + const QList listKeys = map.keys(val); // Take all keys that contain token. for (auto key : listKeys) { map.remove(key); } } -}// namespace qmu +} // namespace qmu diff --git a/src/libs/qmuparser/qmuformulabase.h b/src/libs/qmuparser/qmuformulabase.h index 6d7025993..d9e19c92b 100644 --- a/src/libs/qmuparser/qmuformulabase.h +++ b/src/libs/qmuparser/qmuformulabase.h @@ -43,7 +43,7 @@ public: void SetSepForTr(bool osSeparator, bool fromUser); - static void RemoveAll(QMap &map, const QString &val); + static void RemoveAll(QMap &map, const QString &val); protected: static auto AddVariable(const QString &a_szName, void *a_pUserData) -> qreal *; diff --git a/src/libs/qmuparser/text.h b/src/libs/qmuparser/text.h index 35645bfee..ba801ed85 100644 --- a/src/libs/qmuparser/text.h +++ b/src/libs/qmuparser/text.h @@ -43,13 +43,13 @@ QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wunused-variable") QT_WARNING_DISABLE_CLANG("-Wunused-variable") -//static auto endl Q_DECL_UNUSED = ::endl; // NOLINT -//static auto flush Q_DECL_UNUSED = ::flush; // NOLINT +// static auto endl Q_DECL_UNUSED = ::endl; // NOLINT +// static auto flush Q_DECL_UNUSED = ::flush; // NOLINT static auto dec Q_DECL_UNUSED = ::dec; // NOLINT -//static auto SkipEmptyParts Q_DECL_UNUSED = QString::SkipEmptyParts; // NOLINT +// static auto SkipEmptyParts Q_DECL_UNUSED = QString::SkipEmptyParts; // NOLINT QT_WARNING_POP -} // namespace Qt +} // namespace Qt #endif diff --git a/src/libs/vdxf/libdxfrw/drw_entities.cpp b/src/libs/vdxf/libdxfrw/drw_entities.cpp index 6c966569d..9ff45b95b 100644 --- a/src/libs/vdxf/libdxfrw/drw_entities.cpp +++ b/src/libs/vdxf/libdxfrw/drw_entities.cpp @@ -11,11 +11,11 @@ ** along with this program. If not, see . ** ******************************************************************************/ -#include #include "drw_entities.h" -#include "intern/dxfreader.h" -#include "intern/drw_dbg.h" #include "drw_reserve.h" +#include "intern/drw_dbg.h" +#include "intern/dxfreader.h" +#include #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/diagnostic.h" #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) @@ -23,22 +23,26 @@ //! Calculate arbitrary axis /*! -* Calculate arbitrary axis for apply extrusions -* @author Rallaz -*/ -void DRW_Entity::calculateAxis(DRW_Coord extPoint){ - //Follow the arbitrary DXF definitions for extrusion axes. - if (fabs(extPoint.x) < 0.015625 && fabs(extPoint.y) < 0.015625) { - //If we get here, implement Ax = Wy x N where Wy is [0,1,0] per the DXF spec. - //The cross product works out to Wy.y*N.z-Wy.z*N.y, Wy.z*N.x-Wy.x*N.z, Wy.x*N.y-Wy.y*N.x - //Factoring in the fixed values for Wy gives N.z,0,-N.x + * Calculate arbitrary axis for apply extrusions + * @author Rallaz + */ +void DRW_Entity::calculateAxis(DRW_Coord extPoint) +{ + // Follow the arbitrary DXF definitions for extrusion axes. + if (fabs(extPoint.x) < 0.015625 && fabs(extPoint.y) < 0.015625) + { + // If we get here, implement Ax = Wy x N where Wy is [0,1,0] per the DXF spec. + // The cross product works out to Wy.y*N.z-Wy.z*N.y, Wy.z*N.x-Wy.x*N.z, Wy.x*N.y-Wy.y*N.x + // Factoring in the fixed values for Wy gives N.z,0,-N.x extAxisX.x = extPoint.z; extAxisX.y = 0; extAxisX.z = -extPoint.x; - } else { - //Otherwise, implement Ax = Wz x N where Wz is [0,0,1] per the DXF spec. - //The cross product works out to Wz.y*N.z-Wz.z*N.y, Wz.z*N.x-Wz.x*N.z, Wz.x*N.y-Wz.y*N.x - //Factoring in the fixed values for Wz gives -N.y,N.x,0. + } + else + { + // Otherwise, implement Ax = Wz x N where Wz is [0,0,1] per the DXF spec. + // The cross product works out to Wz.y*N.z-Wz.z*N.y, Wz.z*N.x-Wz.x*N.z, Wz.x*N.y-Wz.y*N.x + // Factoring in the fixed values for Wz gives -N.y,N.x,0. extAxisX.x = -extPoint.y; extAxisX.y = extPoint.x; extAxisX.z = 0; @@ -46,7 +50,7 @@ void DRW_Entity::calculateAxis(DRW_Coord extPoint){ extAxisX.unitize(); - //Ay = N x Ax + // Ay = N x Ax extAxisY.x = (extPoint.y * extAxisX.z) - (extAxisX.y * extPoint.z); extAxisY.y = (extPoint.z * extAxisX.x) - (extAxisX.z * extPoint.x); extAxisY.z = (extPoint.x * extAxisX.y) - (extAxisX.x * extPoint.y); @@ -56,14 +60,15 @@ void DRW_Entity::calculateAxis(DRW_Coord extPoint){ //! Extrude a point using arbitrary axis /*! -* apply extrusion in a point using arbitrary axis (previous calculated) -* @author Rallaz -*/ -void DRW_Entity::extrudePoint(DRW_Coord extPoint, DRW_Coord *point) const{ + * apply extrusion in a point using arbitrary axis (previous calculated) + * @author Rallaz + */ +void DRW_Entity::extrudePoint(DRW_Coord extPoint, DRW_Coord *point) const +{ double px, py, pz; - px = (extAxisX.x*point->x)+(extAxisY.x*point->y)+(extPoint.x*point->z); - py = (extAxisX.y*point->x)+(extAxisY.y*point->y)+(extPoint.y*point->z); - pz = (extAxisX.z*point->x)+(extAxisY.z*point->y)+(extPoint.z*point->z); + px = (extAxisX.x * point->x) + (extAxisY.x * point->y) + (extPoint.x * point->z); + py = (extAxisX.y * point->x) + (extAxisY.y * point->y) + (extPoint.y * point->z); + pz = (extAxisX.z * point->x) + (extAxisY.z * point->y) + (extPoint.z * point->z); point->x = px; point->y = py; @@ -72,124 +77,129 @@ void DRW_Entity::extrudePoint(DRW_Coord extPoint, DRW_Coord *point) const{ auto DRW_Entity::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 5: - handle = static_cast(reader->getHandleString()); - break; - case 330: - parentHandle = static_cast(reader->getHandleString()); - break; - case 8: - layer = reader->getUtf8String(); - break; - case 6: - lineType = reader->getUtf8String(); - break; - case 62: - color = reader->getInt32(); - break; - case 370: - lWeight = DRW_LW_Conv::dxfInt2lineWidth(reader->getInt32()); - break; - case 48: - ltypeScale = reader->getDouble(); - break; - case 60: - visible = reader->getBool(); - break; - case 420: - color24 = reader->getInt32(); - break; - case 430: - colorName = reader->getString(); - break; - case 67: - space = static_cast(reader->getInt32()); - break; - case 102: - parseDxfGroups(code, reader); - break; - case 1000: - case 1001: - case 1002: - case 1003: - case 1004: - case 1005: - extData.push_back(new DRW_Variant(code, reader->getString())); - break; - case 1010: - case 1011: - case 1012: - case 1013: - curr = new DRW_Variant(); - curr->addCoord(); - curr->setCoordX(reader->getDouble()); - curr->code = code; - extData.push_back(curr); - break; - case 1020: - case 1021: - case 1022: - case 1023: - if (curr) - curr->setCoordY(reader->getDouble()); - break; - case 1030: - case 1031: - case 1032: - case 1033: - if (curr) - curr->setCoordZ(reader->getDouble()); - curr=nullptr; - break; - case 1040: - case 1041: - case 1042: - extData.push_back(new DRW_Variant(code, reader->getDouble() )); - break; - case 1070: - case 1071: - extData.push_back(new DRW_Variant(code, reader->getInt32() )); - break; - default: - break; + switch (code) + { + case 5: + handle = static_cast(reader->getHandleString()); + break; + case 330: + parentHandle = static_cast(reader->getHandleString()); + break; + case 8: + layer = reader->getUtf8String(); + break; + case 6: + lineType = reader->getUtf8String(); + break; + case 62: + color = reader->getInt32(); + break; + case 370: + lWeight = DRW_LW_Conv::dxfInt2lineWidth(reader->getInt32()); + break; + case 48: + ltypeScale = reader->getDouble(); + break; + case 60: + visible = reader->getBool(); + break; + case 420: + color24 = reader->getInt32(); + break; + case 430: + colorName = reader->getString(); + break; + case 67: + space = static_cast(reader->getInt32()); + break; + case 102: + parseDxfGroups(code, reader); + break; + case 1000: + case 1001: + case 1002: + case 1003: + case 1004: + case 1005: + extData.push_back(new DRW_Variant(code, reader->getString())); + break; + case 1010: + case 1011: + case 1012: + case 1013: + curr = new DRW_Variant(); + curr->addCoord(); + curr->setCoordX(reader->getDouble()); + curr->code = code; + extData.push_back(curr); + break; + case 1020: + case 1021: + case 1022: + case 1023: + if (curr) + curr->setCoordY(reader->getDouble()); + break; + case 1030: + case 1031: + case 1032: + case 1033: + if (curr) + curr->setCoordZ(reader->getDouble()); + curr = nullptr; + break; + case 1040: + case 1041: + case 1042: + extData.push_back(new DRW_Variant(code, reader->getDouble())); + break; + case 1070: + case 1071: + extData.push_back(new DRW_Variant(code, reader->getInt32())); + break; + default: + break; } return true; } -//parses dxf 102 groups to read entity +// parses dxf 102 groups to read entity auto DRW_Entity::parseDxfGroups(int code, dxfReader *reader) -> bool { std::list ls; DRW_Variant c; int nc; - std::string appName= reader->getString(); - if (!appName.empty() && appName.at(0)== '{'){ - c.addString(appName.substr(1, static_cast(appName.size()-1))); + std::string appName = reader->getString(); + if (!appName.empty() && appName.at(0) == '{') + { + c.addString(appName.substr(1, static_cast(appName.size() - 1))); c.code = code; ls.push_back(c); - while (code !=102 && appName.at(0)== '}'){ + while (code != 102 && appName.at(0) == '}') + { reader->readRec(&nc); c.code = code; if (code == 330 || code == 360) c.addInt(reader->getHandleString()); - else { - switch (reader->type) { - case dxfReader::STRING: - c.addString(reader->getString()); - break; - case dxfReader::INT32: - case dxfReader::INT64: - c.addInt(reader->getInt32()); - break; - case dxfReader::DOUBLE: - c.addDouble(reader->getDouble()); - break; - case dxfReader::BOOL: - c.addInt(reader->getInt32()); - break; - default: - break; + else + { + switch (reader->type) + { + case dxfReader::STRING: + c.addString(reader->getString()); + break; + case dxfReader::INT32: + case dxfReader::INT64: + c.addInt(reader->getInt32()); + break; + case dxfReader::DOUBLE: + c.addDouble(reader->getDouble()); + break; + case dxfReader::BOOL: + c.addInt(reader->getInt32()); + break; + default: + break; } } ls.push_back(c); @@ -202,31 +212,32 @@ auto DRW_Entity::parseDxfGroups(int code, dxfReader *reader) -> bool auto DRW_Point::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 10: - basePoint.x = reader->getDouble(); - break; - case 20: - basePoint.y = reader->getDouble(); - break; - case 30: - basePoint.z = reader->getDouble(); - break; - case 39: - thickness = reader->getDouble(); - break; - case 210: - haveExtrusion = true; - extPoint.x = reader->getDouble(); - break; - case 220: - extPoint.y = reader->getDouble(); - break; - case 230: - extPoint.z = reader->getDouble(); - break; - default: - return DRW_Entity::parseCode(code, reader); + switch (code) + { + case 10: + basePoint.x = reader->getDouble(); + break; + case 20: + basePoint.y = reader->getDouble(); + break; + case 30: + basePoint.z = reader->getDouble(); + break; + case 39: + thickness = reader->getDouble(); + break; + case 210: + haveExtrusion = true; + extPoint.x = reader->getDouble(); + break; + case 220: + extPoint.y = reader->getDouble(); + break; + case 230: + extPoint.z = reader->getDouble(); + break; + default: + return DRW_Entity::parseCode(code, reader); } return true; @@ -234,12 +245,13 @@ auto DRW_Point::parseCode(int code, dxfReader *reader) -> bool auto DRW_ASTMNotch::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 50: - angle = reader->getDouble(); - break; - default: - return DRW_Point::parseCode(code, reader); + switch (code) + { + case 50: + angle = reader->getDouble(); + break; + default: + return DRW_Point::parseCode(code, reader); } return true; @@ -247,27 +259,30 @@ auto DRW_ASTMNotch::parseCode(int code, dxfReader *reader) -> bool auto DRW_Line::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 11: - secPoint.x = reader->getDouble(); - break; - case 21: - secPoint.y = reader->getDouble(); - break; - case 31: - secPoint.z = reader->getDouble(); - break; - default: - return DRW_Point::parseCode(code, reader); + switch (code) + { + case 11: + secPoint.x = reader->getDouble(); + break; + case 21: + secPoint.y = reader->getDouble(); + break; + case 31: + secPoint.z = reader->getDouble(); + break; + default: + return DRW_Point::parseCode(code, reader); } return true; } -void DRW_Circle::applyExtrusion(){ - if (haveExtrusion) { - //NOTE: Commenting these out causes the the arcs being tested to be located - //on the other side of the y axis (all x dimensions are negated). +void DRW_Circle::applyExtrusion() +{ + if (haveExtrusion) + { + // NOTE: Commenting these out causes the the arcs being tested to be located + // on the other side of the y axis (all x dimensions are negated). calculateAxis(extPoint); extrudePoint(extPoint, &basePoint); } @@ -275,48 +290,53 @@ void DRW_Circle::applyExtrusion(){ auto DRW_Circle::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 40: - radious = reader->getDouble(); - break; - default: - return DRW_Point::parseCode(code, reader); + switch (code) + { + case 40: + radious = reader->getDouble(); + break; + default: + return DRW_Point::parseCode(code, reader); } return true; } -void DRW_Arc::applyExtrusion(){ +void DRW_Arc::applyExtrusion() +{ DRW_Circle::applyExtrusion(); - if(haveExtrusion){ + if (haveExtrusion) + { // If the extrusion vector has a z value less than 0, the angles for the arc // have to be mirrored since DXF files use the right hand rule. // Note that the following code only handles the special case where there is a 2D // drawing with the z axis heading into the paper (or rather screen). An arbitrary // extrusion axis (with x and y values greater than 1/64) may still have issues. - if (fabs(extPoint.x) < 0.015625 && fabs(extPoint.y) < 0.015625 && extPoint.z < 0.0) { - staangle=M_PI-staangle; - endangle=M_PI-endangle; + if (fabs(extPoint.x) < 0.015625 && fabs(extPoint.y) < 0.015625 && extPoint.z < 0.0) + { + staangle = M_PI - staangle; + endangle = M_PI - endangle; double temp = staangle; - staangle=endangle; - endangle=temp; + staangle = endangle; + endangle = temp; } } } auto DRW_Arc::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 50: - staangle = reader->getDouble()/ ARAD; - break; - case 51: - endangle = reader->getDouble()/ ARAD; - break; - default: - return DRW_Circle::parseCode(code, reader); + switch (code) + { + case 50: + staangle = reader->getDouble() / ARAD; + break; + case 51: + endangle = reader->getDouble() / ARAD; + break; + default: + return DRW_Circle::parseCode(code, reader); } return true; @@ -324,86 +344,98 @@ auto DRW_Arc::parseCode(int code, dxfReader *reader) -> bool auto DRW_Ellipse::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 40: - ratio = reader->getDouble(); - break; - case 41: - staparam = reader->getDouble(); - break; - case 42: - endparam = reader->getDouble(); - break; - default: - return DRW_Line::parseCode(code, reader); + switch (code) + { + case 40: + ratio = reader->getDouble(); + break; + case 41: + staparam = reader->getDouble(); + break; + case 42: + endparam = reader->getDouble(); + break; + default: + return DRW_Line::parseCode(code, reader); } return true; } -void DRW_Ellipse::applyExtrusion(){ - if (haveExtrusion) { +void DRW_Ellipse::applyExtrusion() +{ + if (haveExtrusion) + { calculateAxis(extPoint); extrudePoint(extPoint, &secPoint); double intialparam = staparam; - if (extPoint.z < 0.){ + if (extPoint.z < 0.) + { staparam = M_PIx2 - endparam; endparam = M_PIx2 - intialparam; } } } -//if ratio > 1 minor axis are greather than major axis, correct it -void DRW_Ellipse::correctAxis(){ +// if ratio > 1 minor axis are greather than major axis, correct it +void DRW_Ellipse::correctAxis() +{ bool complete = false; - if (DRW_FuzzyComparePossibleNulls(staparam, endparam)) { + if (DRW_FuzzyComparePossibleNulls(staparam, endparam)) + { staparam = 0.0; - endparam = M_PIx2; //2*M_PI; + endparam = M_PIx2; // 2*M_PI; complete = true; } - if (ratio > 1){ - if ( fabs(endparam - staparam - M_PIx2) < 1.0e-10) + if (ratio > 1) + { + if (fabs(endparam - staparam - M_PIx2) < 1.0e-10) complete = true; double incX = secPoint.x; secPoint.x = -(secPoint.y * ratio); - secPoint.y = incX*ratio; - ratio = 1/ratio; - if (!complete){ + secPoint.y = incX * ratio; + ratio = 1 / ratio; + if (!complete) + { if (staparam < M_PI_2) - staparam += M_PI *2; + staparam += M_PI * 2; if (endparam < M_PI_2) - endparam += M_PI *2; + endparam += M_PI * 2; endparam -= M_PI_2; staparam -= M_PI_2; } } } -//parts are the number of vertex to split polyline, default 128 -void DRW_Ellipse::toPolyline(DRW_Polyline *pol, int parts){ +// parts are the number of vertex to split polyline, default 128 +void DRW_Ellipse::toPolyline(DRW_Polyline *pol, int parts) +{ double radMajor, radMinor, cosRot, sinRot, incAngle, curAngle; - radMajor = sqrt(secPoint.x*secPoint.x + secPoint.y*secPoint.y); - radMinor = radMajor*ratio; - //calculate sin & cos of included angle + radMajor = sqrt(secPoint.x * secPoint.x + secPoint.y * secPoint.y); + radMinor = radMajor * ratio; + // calculate sin & cos of included angle incAngle = atan2(secPoint.y, secPoint.x); cosRot = cos(incAngle); sinRot = sin(incAngle); incAngle = M_PIx2 / parts; curAngle = staparam; int i = static_cast(curAngle / incAngle); - do { - if (curAngle > endparam) { + do + { + if (curAngle > endparam) + { curAngle = endparam; - i = parts+2; + i = parts + 2; } double cosCurr = cos(curAngle); double sinCurr = sin(curAngle); - double x = basePoint.x + (cosCurr*cosRot*radMajor) - (sinCurr*sinRot*radMinor); - double y = basePoint.y + (cosCurr*sinRot*radMajor) + (sinCurr*cosRot*radMinor); - pol->addVertex( DRW_Vertex(x, y, 0.0, 0.0)); - curAngle = (++i)*incAngle; - } while (iaddVertex(DRW_Vertex(x, y, 0.0, 0.0)); + curAngle = (++i) * incAngle; + } while (i < parts); + if (fabs(endparam - staparam - M_PIx2) < 1.0e-10) + { pol->flags = 1; } pol->layer = this->layer; @@ -413,8 +445,10 @@ void DRW_Ellipse::toPolyline(DRW_Polyline *pol, int parts){ pol->extPoint = this->extPoint; } -void DRW_Trace::applyExtrusion(){ - if (haveExtrusion) { +void DRW_Trace::applyExtrusion() +{ + if (haveExtrusion) + { calculateAxis(extPoint); extrudePoint(extPoint, &basePoint); extrudePoint(extPoint, &secPoint); @@ -425,27 +459,28 @@ void DRW_Trace::applyExtrusion(){ auto DRW_Trace::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 12: - thirdPoint.x = reader->getDouble(); - break; - case 22: - thirdPoint.y = reader->getDouble(); - break; - case 32: - thirdPoint.z = reader->getDouble(); - break; - case 13: - fourPoint.x = reader->getDouble(); - break; - case 23: - fourPoint.y = reader->getDouble(); - break; - case 33: - fourPoint.z = reader->getDouble(); - break; - default: - return DRW_Line::parseCode(code, reader); + switch (code) + { + case 12: + thirdPoint.x = reader->getDouble(); + break; + case 22: + thirdPoint.y = reader->getDouble(); + break; + case 32: + thirdPoint.z = reader->getDouble(); + break; + case 13: + fourPoint.x = reader->getDouble(); + break; + case 23: + fourPoint.y = reader->getDouble(); + break; + case 33: + fourPoint.z = reader->getDouble(); + break; + default: + return DRW_Line::parseCode(code, reader); } return true; @@ -453,12 +488,13 @@ auto DRW_Trace::parseCode(int code, dxfReader *reader) -> bool auto DRW_3Dface::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 70: - invisibleflag = reader->getInt32(); - break; - default: - return DRW_Trace::parseCode(code, reader); + switch (code) + { + case 70: + invisibleflag = reader->getInt32(); + break; + default: + return DRW_Trace::parseCode(code, reader); } return true; @@ -466,15 +502,16 @@ auto DRW_3Dface::parseCode(int code, dxfReader *reader) -> bool auto DRW_Block::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 2: - name = reader->getUtf8String(); - break; - case 70: - flags = reader->getInt32(); - break; - default: - return DRW_Point::parseCode(code, reader); + switch (code) + { + case 2: + name = reader->getUtf8String(); + break; + case 70: + flags = reader->getInt32(); + break; + default: + return DRW_Point::parseCode(code, reader); } return true; @@ -482,46 +519,50 @@ auto DRW_Block::parseCode(int code, dxfReader *reader) -> bool auto DRW_Insert::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 2: - name = reader->getUtf8String(); - break; - case 41: - xscale = reader->getDouble(); - break; - case 42: - yscale = reader->getDouble(); - break; - case 43: - zscale = reader->getDouble(); - break; - case 50: - angle = reader->getDouble(); - angle = angle/ARAD; //convert to radian - break; - case 70: - colcount = reader->getInt32(); - break; - case 71: - rowcount = reader->getInt32(); - break; - case 44: - colspace = reader->getDouble(); - break; - case 45: - rowspace = reader->getDouble(); - break; - default: - return DRW_Point::parseCode(code, reader); + switch (code) + { + case 2: + name = reader->getUtf8String(); + break; + case 41: + xscale = reader->getDouble(); + break; + case 42: + yscale = reader->getDouble(); + break; + case 43: + zscale = reader->getDouble(); + break; + case 50: + angle = reader->getDouble(); + angle = angle / ARAD; // convert to radian + break; + case 70: + colcount = reader->getInt32(); + break; + case 71: + rowcount = reader->getInt32(); + break; + case 44: + colspace = reader->getDouble(); + break; + case 45: + rowspace = reader->getDouble(); + break; + default: + return DRW_Point::parseCode(code, reader); } return true; } -void DRW_LWPolyline::applyExtrusion(){ - if (haveExtrusion) { +void DRW_LWPolyline::applyExtrusion() +{ + if (haveExtrusion) + { calculateAxis(extPoint); - for (unsigned int i=0; ix, vert->y, elevation); extrudePoint(extPoint, &v); @@ -533,55 +574,58 @@ void DRW_LWPolyline::applyExtrusion(){ auto DRW_LWPolyline::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 10: { - vertex = new DRW_Vertex2D(); - vertlist.push_back(vertex); - vertex->x = reader->getDouble(); - break; } - case 20: - if(vertex != NULL) - vertex->y = reader->getDouble(); - break; - case 40: - if(vertex != NULL) - vertex->stawidth = reader->getDouble(); - break; - case 41: - if(vertex != NULL) - vertex->endwidth = reader->getDouble(); - break; - case 42: - if(vertex != NULL) - vertex->bulge = reader->getDouble(); - break; - case 38: - elevation = reader->getDouble(); - break; - case 39: - thickness = reader->getDouble(); - break; - case 43: - width = reader->getDouble(); - break; - case 70: - flags = reader->getInt32(); - break; - case 90: - vertexnum = reader->getInt32(); - return DRW::reserve( vertlist, vertexnum); - case 210: - haveExtrusion = true; - extPoint.x = reader->getDouble(); - break; - case 220: - extPoint.y = reader->getDouble(); - break; - case 230: - extPoint.z = reader->getDouble(); - break; - default: - return DRW_Entity::parseCode(code, reader); + switch (code) + { + case 10: + { + vertex = new DRW_Vertex2D(); + vertlist.push_back(vertex); + vertex->x = reader->getDouble(); + break; + } + case 20: + if (vertex != NULL) + vertex->y = reader->getDouble(); + break; + case 40: + if (vertex != NULL) + vertex->stawidth = reader->getDouble(); + break; + case 41: + if (vertex != NULL) + vertex->endwidth = reader->getDouble(); + break; + case 42: + if (vertex != NULL) + vertex->bulge = reader->getDouble(); + break; + case 38: + elevation = reader->getDouble(); + break; + case 39: + thickness = reader->getDouble(); + break; + case 43: + width = reader->getDouble(); + break; + case 70: + flags = reader->getInt32(); + break; + case 90: + vertexnum = reader->getInt32(); + return DRW::reserve(vertlist, vertexnum); + case 210: + haveExtrusion = true; + extPoint.x = reader->getDouble(); + break; + case 220: + extPoint.y = reader->getDouble(); + break; + case 230: + extPoint.z = reader->getDouble(); + break; + default: + return DRW_Entity::parseCode(code, reader); } return true; @@ -589,36 +633,37 @@ auto DRW_LWPolyline::parseCode(int code, dxfReader *reader) -> bool auto DRW_Text::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 40: - height = reader->getDouble(); - break; - case 41: - widthscale = reader->getDouble(); - break; - case 50: - angle = reader->getDouble(); - break; - case 51: - oblique = reader->getDouble(); - break; - case 71: - textgen = reader->getInt32(); - break; - case 72: - alignH = static_cast(reader->getInt32()); - break; - case 73: - alignV = static_cast(reader->getInt32()); - break; - case 1: - text = reader->getUtf8String(); - break; - case 7: - style = reader->getUtf8String(); - break; - default: - return DRW_Line::parseCode(code, reader); + switch (code) + { + case 40: + height = reader->getDouble(); + break; + case 41: + widthscale = reader->getDouble(); + break; + case 50: + angle = reader->getDouble(); + break; + case 51: + oblique = reader->getDouble(); + break; + case 71: + textgen = reader->getInt32(); + break; + case 72: + alignH = static_cast(reader->getInt32()); + break; + case 73: + alignV = static_cast(reader->getInt32()); + break; + case 1: + text = reader->getUtf8String(); + break; + case 7: + style = reader->getUtf8String(); + break; + default: + return DRW_Line::parseCode(code, reader); } return true; @@ -626,120 +671,127 @@ auto DRW_Text::parseCode(int code, dxfReader *reader) -> bool auto DRW_MText::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 1: - text += reader->getString(); - text = reader->toUtf8String(text); - break; - case 11: - hasXAxisVec = true; - return DRW_Text::parseCode(code, reader); - case 3: - text += reader->getString(); - break; - case 44: - interlin = reader->getDouble(); - break; - case 71: { - // Attachment point - Attach a = static_cast(reader->getInt32()); + switch (code) + { + case 1: + text += reader->getString(); + text = reader->toUtf8String(text); + break; + case 11: + hasXAxisVec = true; + return DRW_Text::parseCode(code, reader); + case 3: + text += reader->getString(); + break; + case 44: + interlin = reader->getDouble(); + break; + case 71: + { + // Attachment point + Attach a = static_cast(reader->getInt32()); - QT_WARNING_PUSH - QT_WARNING_DISABLE_GCC("-Wswitch-default") + QT_WARNING_PUSH + QT_WARNING_DISABLE_GCC("-Wswitch-default") - switch(a) { - case TopLeft: - alignV = VTop; - alignH = HLeft; - break; - case TopCenter: - alignV = VTop; - alignH = HCenter; - break; - case TopRight: - alignV = VTop; - alignH = HRight; - break; - case MiddleLeft: - alignV = VMiddle; - alignH = HLeft; - break; - case MiddleCenter: - alignV = VMiddle; - alignH = HCenter; - break; - case MiddleRight: - alignV = VMiddle; - alignH = HRight; - break; - case BottomLeft: - alignV = VBottom; - alignH = HLeft; - break; - case BottomCenter: - alignV = VBottom; - alignH = HCenter; - break; - case BottomRight: - alignV = VBottom; - alignH = HRight; - break; + switch (a) + { + case TopLeft: + alignV = VTop; + alignH = HLeft; + break; + case TopCenter: + alignV = VTop; + alignH = HCenter; + break; + case TopRight: + alignV = VTop; + alignH = HRight; + break; + case MiddleLeft: + alignV = VMiddle; + alignH = HLeft; + break; + case MiddleCenter: + alignV = VMiddle; + alignH = HCenter; + break; + case MiddleRight: + alignV = VMiddle; + alignH = HRight; + break; + case BottomLeft: + alignV = VBottom; + alignH = HLeft; + break; + case BottomCenter: + alignV = VBottom; + alignH = HCenter; + break; + case BottomRight: + alignV = VBottom; + alignH = HRight; + break; + } + + QT_WARNING_POP } - - QT_WARNING_POP - } break; - case 72: - // To prevent redirection to DRW_Text::parseCode. - // This code meaning is different for MTEXT. - // Actually: Drawing direction break; - case 73: - // To prevent redirection to DRW_Text::parseCode. - // This code meaning is different for MTEXT. - // Actually: Mtext line spacing style - break; - default: - return DRW_Text::parseCode(code, reader); + case 72: + // To prevent redirection to DRW_Text::parseCode. + // This code meaning is different for MTEXT. + // Actually: Drawing direction + break; + case 73: + // To prevent redirection to DRW_Text::parseCode. + // This code meaning is different for MTEXT. + // Actually: Mtext line spacing style + break; + default: + return DRW_Text::parseCode(code, reader); } return true; } -void DRW_MText::updateAngle(){ - if (hasXAxisVec) { - angle = atan2(secPoint.y, secPoint.x)*180/M_PI; +void DRW_MText::updateAngle() +{ + if (hasXAxisVec) + { + angle = atan2(secPoint.y, secPoint.x) * 180 / M_PI; } } auto DRW_Polyline::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 70: - flags = reader->getInt32(); - break; - case 40: - defstawidth = reader->getDouble(); - break; - case 41: - defendwidth = reader->getDouble(); - break; - case 71: - vertexcount = reader->getInt32(); - break; - case 72: - facecount = reader->getInt32(); - break; - case 73: - smoothM = reader->getInt32(); - break; - case 74: - smoothN = reader->getInt32(); - break; - case 75: - curvetype = reader->getInt32(); - break; - default: - return DRW_Point::parseCode(code, reader); + switch (code) + { + case 70: + flags = reader->getInt32(); + break; + case 40: + defstawidth = reader->getDouble(); + break; + case 41: + defendwidth = reader->getDouble(); + break; + case 71: + vertexcount = reader->getInt32(); + break; + case 72: + facecount = reader->getInt32(); + break; + case 73: + smoothM = reader->getInt32(); + break; + case 74: + smoothN = reader->getInt32(); + break; + case 75: + curvetype = reader->getInt32(); + break; + default: + return DRW_Point::parseCode(code, reader); } return true; @@ -747,39 +799,40 @@ auto DRW_Polyline::parseCode(int code, dxfReader *reader) -> bool auto DRW_Vertex::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 70: - flags = reader->getInt32(); - break; - case 40: - stawidth = reader->getDouble(); - break; - case 41: - endwidth = reader->getDouble(); - break; - case 42: - bulge = reader->getDouble(); - break; - case 50: - tgdir = reader->getDouble(); - break; - case 71: - vindex1 = reader->getInt32(); - break; - case 72: - vindex2 = reader->getInt32(); - break; - case 73: - vindex3 = reader->getInt32(); - break; - case 74: - vindex4 = reader->getInt32(); - break; - case 91: - identifier = reader->getInt32(); - break; - default: - return DRW_Point::parseCode(code, reader); + switch (code) + { + case 70: + flags = reader->getInt32(); + break; + case 40: + stawidth = reader->getDouble(); + break; + case 41: + endwidth = reader->getDouble(); + break; + case 42: + bulge = reader->getDouble(); + break; + case 50: + tgdir = reader->getDouble(); + break; + case 71: + vindex1 = reader->getInt32(); + break; + case 72: + vindex2 = reader->getInt32(); + break; + case 73: + vindex3 = reader->getInt32(); + break; + case 74: + vindex4 = reader->getInt32(); + break; + case 91: + identifier = reader->getInt32(); + break; + default: + return DRW_Point::parseCode(code, reader); } return true; @@ -787,107 +840,139 @@ auto DRW_Vertex::parseCode(int code, dxfReader *reader) -> bool auto DRW_Hatch::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 2: - name = reader->getUtf8String(); - break; - case 70: - solid = reader->getInt32(); - break; - case 71: - associative = reader->getInt32(); - break; - case 72: /*edge type*/ - if (ispol){ //if is polyline is a as_bulge flag + switch (code) + { + case 2: + name = reader->getUtf8String(); break; - } else if (reader->getInt32() == 1){ //line - addLine(); - } else if (reader->getInt32() == 2){ //arc - addArc(); - } else if (reader->getInt32() == 3){ //elliptic arc - addEllipse(); - } else if (reader->getInt32() == 4){ //spline - addSpline(); - } - break; - case 10: - if (pt) pt->basePoint.x = reader->getDouble(); - else if (pline) { - plvert = pline->addVertex(); - plvert->x = reader->getDouble(); - } - break; - case 20: - if (pt) pt->basePoint.y = reader->getDouble(); - else if (plvert) plvert ->y = reader->getDouble(); - break; - case 11: - if (line) line->secPoint.x = reader->getDouble(); - else if (ellipse) ellipse->secPoint.x = reader->getDouble(); - break; - case 21: - if (line) line->secPoint.y = reader->getDouble(); - else if (ellipse) ellipse->secPoint.y = reader->getDouble(); - break; - case 40: - if (arc) arc->radious = reader->getDouble(); - else if (ellipse) ellipse->ratio = reader->getDouble(); - break; - case 41: - scale = reader->getDouble(); - break; - case 42: - if (plvert) plvert ->bulge = reader->getDouble(); - break; - case 50: - if (arc) arc->staangle = reader->getDouble()/ARAD; - else if (ellipse) ellipse->staparam = reader->getDouble()/ARAD; - break; - case 51: - if (arc) arc->endangle = reader->getDouble()/ARAD; - else if (ellipse) ellipse->endparam = reader->getDouble()/ARAD; - break; - case 52: - angle = reader->getDouble(); - break; - case 73: - if (arc) arc->isccw = reader->getInt32(); - else if (pline) pline->flags = reader->getInt32(); - break; - case 75: - hstyle = reader->getInt32(); - break; - case 76: - hpattern = reader->getInt32(); - break; - case 77: - doubleflag = reader->getInt32(); - break; - case 78: - deflines = reader->getInt32(); - break; - case 91: - loopsnum = reader->getInt32(); - return DRW::reserve( looplist, loopsnum); - case 92: - loop = new DRW_HatchLoop(reader->getInt32()); - looplist.push_back(loop); - if (reader->getInt32() & 2) { - ispol = true; + case 70: + solid = reader->getInt32(); + break; + case 71: + associative = reader->getInt32(); + break; + case 72: /*edge type*/ + if (ispol) + { // if is polyline is a as_bulge flag + break; + } + else if (reader->getInt32() == 1) + { // line + addLine(); + } + else if (reader->getInt32() == 2) + { // arc + addArc(); + } + else if (reader->getInt32() == 3) + { // elliptic arc + addEllipse(); + } + else if (reader->getInt32() == 4) + { // spline + addSpline(); + } + break; + case 10: + if (pt) + pt->basePoint.x = reader->getDouble(); + else if (pline) + { + plvert = pline->addVertex(); + plvert->x = reader->getDouble(); + } + break; + case 20: + if (pt) + pt->basePoint.y = reader->getDouble(); + else if (plvert) + plvert->y = reader->getDouble(); + break; + case 11: + if (line) + line->secPoint.x = reader->getDouble(); + else if (ellipse) + ellipse->secPoint.x = reader->getDouble(); + break; + case 21: + if (line) + line->secPoint.y = reader->getDouble(); + else if (ellipse) + ellipse->secPoint.y = reader->getDouble(); + break; + case 40: + if (arc) + arc->radious = reader->getDouble(); + else if (ellipse) + ellipse->ratio = reader->getDouble(); + break; + case 41: + scale = reader->getDouble(); + break; + case 42: + if (plvert) + plvert->bulge = reader->getDouble(); + break; + case 50: + if (arc) + arc->staangle = reader->getDouble() / ARAD; + else if (ellipse) + ellipse->staparam = reader->getDouble() / ARAD; + break; + case 51: + if (arc) + arc->endangle = reader->getDouble() / ARAD; + else if (ellipse) + ellipse->endparam = reader->getDouble() / ARAD; + break; + case 52: + angle = reader->getDouble(); + break; + case 73: + if (arc) + arc->isccw = reader->getInt32(); + else if (pline) + pline->flags = reader->getInt32(); + break; + case 75: + hstyle = reader->getInt32(); + break; + case 76: + hpattern = reader->getInt32(); + break; + case 77: + doubleflag = reader->getInt32(); + break; + case 78: + deflines = reader->getInt32(); + break; + case 91: + loopsnum = reader->getInt32(); + return DRW::reserve(looplist, loopsnum); + case 92: + loop = new DRW_HatchLoop(reader->getInt32()); + looplist.push_back(loop); + if (reader->getInt32() & 2) + { + ispol = true; + clearEntities(); + pline = new DRW_LWPolyline; + loop->objlist.push_back(pline); + } + else + ispol = false; + break; + case 93: + if (pline) + pline->vertexnum = reader->getInt32(); + else if (loop) + loop->numedges = reader->getInt32(); // aqui reserve + break; + case 98: // seed points ?? clearEntities(); - pline = new DRW_LWPolyline; - loop->objlist.push_back(pline); - } else ispol = false; - break; - case 93: - if (pline) pline->vertexnum = reader->getInt32(); - else if (loop) loop->numedges = reader->getInt32();//aqui reserve - break; - case 98: //seed points ?? - clearEntities(); - break; - default: - return DRW_Point::parseCode(code, reader); + break; + default: + return DRW_Point::parseCode(code, reader); } return true; @@ -895,92 +980,97 @@ auto DRW_Hatch::parseCode(int code, dxfReader *reader) -> bool auto DRW_Spline::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 210: - normalVec.x = reader->getDouble(); - break; - case 220: - normalVec.y = reader->getDouble(); - break; - case 230: - normalVec.z = reader->getDouble(); - break; - case 12: - tgStart.x = reader->getDouble(); - break; - case 22: - tgStart.y = reader->getDouble(); - break; - case 32: - tgStart.z = reader->getDouble(); - break; - case 13: - tgEnd.x = reader->getDouble(); - break; - case 23: - tgEnd.y = reader->getDouble(); - break; - case 33: - tgEnd.z = reader->getDouble(); - break; - case 70: - flags = reader->getInt32(); - break; - case 71: - degree = reader->getInt32(); - break; - case 72: - nknots = reader->getInt32(); - break; - case 73: - ncontrol = reader->getInt32(); - break; - case 74: - nfit = reader->getInt32(); - break; - case 42: - tolknot = reader->getDouble(); - break; - case 43: - tolcontrol = reader->getDouble(); - break; - case 44: - tolfit = reader->getDouble(); - break; - case 10: { - controlpoint = new DRW_Coord(); - controllist.push_back(controlpoint); - controlpoint->x = reader->getDouble(); - break; } - case 20: - if(controlpoint != NULL) - controlpoint->y = reader->getDouble(); - break; - case 30: - if(controlpoint != NULL) - controlpoint->z = reader->getDouble(); - break; - case 11: { - fitpoint = new DRW_Coord(); - fitlist.push_back(fitpoint); - fitpoint->x = reader->getDouble(); - break; } - case 21: - if(fitpoint != NULL) - fitpoint->y = reader->getDouble(); - break; - case 31: - if(fitpoint != NULL) - fitpoint->z = reader->getDouble(); - break; - case 40: - knotslist.push_back(reader->getDouble()); - break; - case 41: - weightlist.push_back(reader->getDouble()); - break; - default: - return DRW_Entity::parseCode(code, reader); + switch (code) + { + case 210: + normalVec.x = reader->getDouble(); + break; + case 220: + normalVec.y = reader->getDouble(); + break; + case 230: + normalVec.z = reader->getDouble(); + break; + case 12: + tgStart.x = reader->getDouble(); + break; + case 22: + tgStart.y = reader->getDouble(); + break; + case 32: + tgStart.z = reader->getDouble(); + break; + case 13: + tgEnd.x = reader->getDouble(); + break; + case 23: + tgEnd.y = reader->getDouble(); + break; + case 33: + tgEnd.z = reader->getDouble(); + break; + case 70: + flags = reader->getInt32(); + break; + case 71: + degree = reader->getInt32(); + break; + case 72: + nknots = reader->getInt32(); + break; + case 73: + ncontrol = reader->getInt32(); + break; + case 74: + nfit = reader->getInt32(); + break; + case 42: + tolknot = reader->getDouble(); + break; + case 43: + tolcontrol = reader->getDouble(); + break; + case 44: + tolfit = reader->getDouble(); + break; + case 10: + { + controlpoint = new DRW_Coord(); + controllist.push_back(controlpoint); + controlpoint->x = reader->getDouble(); + break; + } + case 20: + if (controlpoint != NULL) + controlpoint->y = reader->getDouble(); + break; + case 30: + if (controlpoint != NULL) + controlpoint->z = reader->getDouble(); + break; + case 11: + { + fitpoint = new DRW_Coord(); + fitlist.push_back(fitpoint); + fitpoint->x = reader->getDouble(); + break; + } + case 21: + if (fitpoint != NULL) + fitpoint->y = reader->getDouble(); + break; + case 31: + if (fitpoint != NULL) + fitpoint->z = reader->getDouble(); + break; + case 40: + knotslist.push_back(reader->getDouble()); + break; + case 41: + weightlist.push_back(reader->getDouble()); + break; + default: + return DRW_Entity::parseCode(code, reader); } return true; @@ -988,39 +1078,40 @@ auto DRW_Spline::parseCode(int code, dxfReader *reader) -> bool auto DRW_Image::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 12: - vVector.x = reader->getDouble(); - break; - case 22: - vVector.y = reader->getDouble(); - break; - case 32: - vVector.z = reader->getDouble(); - break; - case 13: - sizeu = reader->getDouble(); - break; - case 23: - sizev = reader->getDouble(); - break; - case 340: - ref = static_cast(reader->getHandleString()); - break; - case 280: - clip = reader->getInt32(); - break; - case 281: - brightness = reader->getInt32(); - break; - case 282: - contrast = reader->getInt32(); - break; - case 283: - fade = reader->getInt32(); - break; - default: - return DRW_Line::parseCode(code, reader); + switch (code) + { + case 12: + vVector.x = reader->getDouble(); + break; + case 22: + vVector.y = reader->getDouble(); + break; + case 32: + vVector.z = reader->getDouble(); + break; + case 13: + sizeu = reader->getDouble(); + break; + case 23: + sizev = reader->getDouble(); + break; + case 340: + ref = static_cast(reader->getHandleString()); + break; + case 280: + clip = reader->getInt32(); + break; + case 281: + brightness = reader->getInt32(); + break; + case 282: + contrast = reader->getInt32(); + break; + case 283: + fade = reader->getInt32(); + break; + default: + return DRW_Line::parseCode(code, reader); } return true; @@ -1028,121 +1119,122 @@ auto DRW_Image::parseCode(int code, dxfReader *reader) -> bool auto DRW_Dimension::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 1: - text = reader->getUtf8String(); - break; - case 2: - name = reader->getString(); - break; - case 3: - style = reader->getUtf8String(); - break; - case 70: - type = reader->getInt32(); - break; - case 71: - align = reader->getInt32(); - break; - case 72: - linesty = reader->getInt32(); - break; - case 10: - defPoint.x = reader->getDouble(); - break; - case 20: - defPoint.y = reader->getDouble(); - break; - case 30: - defPoint.z = reader->getDouble(); - break; - case 11: - textPoint.x = reader->getDouble(); - break; - case 21: - textPoint.y = reader->getDouble(); - break; - case 31: - textPoint.z = reader->getDouble(); - break; - case 12: - clonePoint.x = reader->getDouble(); - break; - case 22: - clonePoint.y = reader->getDouble(); - break; - case 32: - clonePoint.z = reader->getDouble(); - break; - case 13: - def1.x = reader->getDouble(); - break; - case 23: - def1.y = reader->getDouble(); - break; - case 33: - def1.z = reader->getDouble(); - break; - case 14: - def2.x = reader->getDouble(); - break; - case 24: - def2.y = reader->getDouble(); - break; - case 34: - def2.z = reader->getDouble(); - break; - case 15: - circlePoint.x = reader->getDouble(); - break; - case 25: - circlePoint.y = reader->getDouble(); - break; - case 35: - circlePoint.z = reader->getDouble(); - break; - case 16: - arcPoint.x = reader->getDouble(); - break; - case 26: - arcPoint.y = reader->getDouble(); - break; - case 36: - arcPoint.z = reader->getDouble(); - break; - case 41: - linefactor = reader->getDouble(); - break; - case 42: - actual = reader->getDouble(); - hasActual = not qFuzzyIsNull(actual); - break; - case 53: - rot = reader->getDouble(); - break; - case 50: - angle = reader->getDouble(); - break; - case 52: - oblique = reader->getDouble(); - break; - case 40: - length = reader->getDouble(); - break; - case 51: - hdir = reader->getDouble(); - break; - case 210: - extPoint.x = reader->getDouble(); - break; - case 220: - extPoint.y = reader->getDouble(); - break; - case 230: - extPoint.z = reader->getDouble(); - break; - default: - return DRW_Entity::parseCode(code, reader); + switch (code) + { + case 1: + text = reader->getUtf8String(); + break; + case 2: + name = reader->getString(); + break; + case 3: + style = reader->getUtf8String(); + break; + case 70: + type = reader->getInt32(); + break; + case 71: + align = reader->getInt32(); + break; + case 72: + linesty = reader->getInt32(); + break; + case 10: + defPoint.x = reader->getDouble(); + break; + case 20: + defPoint.y = reader->getDouble(); + break; + case 30: + defPoint.z = reader->getDouble(); + break; + case 11: + textPoint.x = reader->getDouble(); + break; + case 21: + textPoint.y = reader->getDouble(); + break; + case 31: + textPoint.z = reader->getDouble(); + break; + case 12: + clonePoint.x = reader->getDouble(); + break; + case 22: + clonePoint.y = reader->getDouble(); + break; + case 32: + clonePoint.z = reader->getDouble(); + break; + case 13: + def1.x = reader->getDouble(); + break; + case 23: + def1.y = reader->getDouble(); + break; + case 33: + def1.z = reader->getDouble(); + break; + case 14: + def2.x = reader->getDouble(); + break; + case 24: + def2.y = reader->getDouble(); + break; + case 34: + def2.z = reader->getDouble(); + break; + case 15: + circlePoint.x = reader->getDouble(); + break; + case 25: + circlePoint.y = reader->getDouble(); + break; + case 35: + circlePoint.z = reader->getDouble(); + break; + case 16: + arcPoint.x = reader->getDouble(); + break; + case 26: + arcPoint.y = reader->getDouble(); + break; + case 36: + arcPoint.z = reader->getDouble(); + break; + case 41: + linefactor = reader->getDouble(); + break; + case 42: + actual = reader->getDouble(); + hasActual = not qFuzzyIsNull(actual); + break; + case 53: + rot = reader->getDouble(); + break; + case 50: + angle = reader->getDouble(); + break; + case 52: + oblique = reader->getDouble(); + break; + case 40: + length = reader->getDouble(); + break; + case 51: + hdir = reader->getDouble(); + break; + case 210: + extPoint.x = reader->getDouble(); + break; + case 220: + extPoint.y = reader->getDouble(); + break; + case 230: + extPoint.z = reader->getDouble(); + break; + default: + return DRW_Entity::parseCode(code, reader); } return true; @@ -1150,91 +1242,94 @@ auto DRW_Dimension::parseCode(int code, dxfReader *reader) -> bool auto DRW_Leader::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 3: - style = reader->getUtf8String(); - break; - case 71: - arrow = reader->getInt32(); - break; - case 72: - leadertype = reader->getInt32(); - break; - case 73: - flag = reader->getInt32(); - break; - case 74: - hookline = reader->getInt32(); - break; - case 75: - hookflag = reader->getInt32(); - break; - case 76: - vertnum = reader->getInt32(); - break; - case 77: - coloruse = reader->getInt32(); - break; - case 40: - textheight = reader->getDouble(); - break; - case 41: - textwidth = reader->getDouble(); - break; - case 10: { - vertexpoint = new DRW_Coord(); - vertexlist.push_back(vertexpoint); - vertexpoint->x = reader->getDouble(); - break; } - case 20: - if(vertexpoint != NULL) - vertexpoint->y = reader->getDouble(); - break; - case 30: - if(vertexpoint != NULL) - vertexpoint->z = reader->getDouble(); - break; - case 340: - annotHandle = static_cast(reader->getHandleString()); - break; - case 210: - extrusionPoint.x = reader->getDouble(); - break; - case 220: - extrusionPoint.y = reader->getDouble(); - break; - case 230: - extrusionPoint.z = reader->getDouble(); - break; - case 211: - horizdir.x = reader->getDouble(); - break; - case 221: - horizdir.y = reader->getDouble(); - break; - case 231: - horizdir.z = reader->getDouble(); - break; - case 212: - offsetblock.x = reader->getDouble(); - break; - case 222: - offsetblock.y = reader->getDouble(); - break; - case 232: - offsetblock.z = reader->getDouble(); - break; - case 213: - offsettext.x = reader->getDouble(); - break; - case 223: - offsettext.y = reader->getDouble(); - break; - case 233: - offsettext.z = reader->getDouble(); - break; - default: - return DRW_Entity::parseCode(code, reader); + switch (code) + { + case 3: + style = reader->getUtf8String(); + break; + case 71: + arrow = reader->getInt32(); + break; + case 72: + leadertype = reader->getInt32(); + break; + case 73: + flag = reader->getInt32(); + break; + case 74: + hookline = reader->getInt32(); + break; + case 75: + hookflag = reader->getInt32(); + break; + case 76: + vertnum = reader->getInt32(); + break; + case 77: + coloruse = reader->getInt32(); + break; + case 40: + textheight = reader->getDouble(); + break; + case 41: + textwidth = reader->getDouble(); + break; + case 10: + { + vertexpoint = new DRW_Coord(); + vertexlist.push_back(vertexpoint); + vertexpoint->x = reader->getDouble(); + break; + } + case 20: + if (vertexpoint != NULL) + vertexpoint->y = reader->getDouble(); + break; + case 30: + if (vertexpoint != NULL) + vertexpoint->z = reader->getDouble(); + break; + case 340: + annotHandle = static_cast(reader->getHandleString()); + break; + case 210: + extrusionPoint.x = reader->getDouble(); + break; + case 220: + extrusionPoint.y = reader->getDouble(); + break; + case 230: + extrusionPoint.z = reader->getDouble(); + break; + case 211: + horizdir.x = reader->getDouble(); + break; + case 221: + horizdir.y = reader->getDouble(); + break; + case 231: + horizdir.z = reader->getDouble(); + break; + case 212: + offsetblock.x = reader->getDouble(); + break; + case 222: + offsetblock.y = reader->getDouble(); + break; + case 232: + offsetblock.z = reader->getDouble(); + break; + case 213: + offsettext.x = reader->getDouble(); + break; + case 223: + offsettext.y = reader->getDouble(); + break; + case 233: + offsettext.z = reader->getDouble(); + break; + default: + return DRW_Entity::parseCode(code, reader); } return true; @@ -1242,27 +1337,30 @@ auto DRW_Leader::parseCode(int code, dxfReader *reader) -> bool auto DRW_Viewport::parseCode(int code, dxfReader *reader) -> bool { - switch (code) { - case 40: - pswidth = reader->getDouble(); - break; - case 41: - psheight = reader->getDouble(); - break; - case 68: - vpstatus = reader->getInt32(); - break; - case 69: - vpID = reader->getInt32(); - break; - case 12: { - centerPX = reader->getDouble(); - break; } - case 22: - centerPY = reader->getDouble(); - break; - default: - return DRW_Point::parseCode(code, reader); + switch (code) + { + case 40: + pswidth = reader->getDouble(); + break; + case 41: + psheight = reader->getDouble(); + break; + case 68: + vpstatus = reader->getInt32(); + break; + case 69: + vpID = reader->getInt32(); + break; + case 12: + { + centerPX = reader->getDouble(); + break; + } + case 22: + centerPY = reader->getDouble(); + break; + default: + return DRW_Point::parseCode(code, reader); } return true; diff --git a/src/libs/vdxf/libdxfrw/drw_interface.h b/src/libs/vdxf/libdxfrw/drw_interface.h index 26c7eb463..a62bb6f50 100644 --- a/src/libs/vdxf/libdxfrw/drw_interface.h +++ b/src/libs/vdxf/libdxfrw/drw_interface.h @@ -16,8 +16,8 @@ #include #include "drw_entities.h" -#include "drw_objects.h" #include "drw_header.h" +#include "drw_objects.h" #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/diagnostic.h" @@ -34,27 +34,27 @@ QT_WARNING_DISABLE_GCC("-Wsuggest-final-methods") * * @author Rallaz */ -class DRW_Interface { +class DRW_Interface +{ public: - DRW_Interface() { - } + DRW_Interface() {} virtual ~DRW_Interface() = default; /** Called when header is parsed. */ - virtual void addHeader(const DRW_Header *) { } + virtual void addHeader(const DRW_Header *) {} /** Called for every line Type. */ - virtual void addLType(const DRW_LType &) { } + virtual void addLType(const DRW_LType &) {} /** Called for every layer. */ - virtual void addLayer(const DRW_Layer &) { } + virtual void addLayer(const DRW_Layer &) {} /** Called for every dim style. */ - virtual void addDimStyle(const DRW_Dimstyle &) { } + virtual void addDimStyle(const DRW_Dimstyle &) {} /** Called for every VPORT table. */ - virtual void addVport(const DRW_Vport &) { } + virtual void addVport(const DRW_Vport &) {} /** Called for every text style. */ - virtual void addTextStyle(const DRW_Textstyle &) { } + virtual void addTextStyle(const DRW_Textstyle &) {} /** Called for every AppId entry. */ - virtual void addAppId(const DRW_AppId &) { } + virtual void addAppId(const DRW_AppId &) {} /** * Called for every block. Note: all entities added after this @@ -62,143 +62,142 @@ public: * * @see endBlock() */ - virtual void addBlock(const DRW_Block &) { } + virtual void addBlock(const DRW_Block &) {} /** Called to end the current block */ - virtual void endBlock() { } + virtual void endBlock() {} /** Called for every point */ - virtual void addPoint(const DRW_Point &) { } + virtual void addPoint(const DRW_Point &) {} /** Called for every line */ - virtual void addLine(const DRW_Line &) { } + virtual void addLine(const DRW_Line &) {} /** Called for every ray */ - virtual void addRay(const DRW_Ray &) { } + virtual void addRay(const DRW_Ray &) {} /** Called for every xline */ - virtual void addXline(const DRW_Xline &) { } + virtual void addXline(const DRW_Xline &) {} /** Called for every arc */ - virtual void addArc(const DRW_Arc &) { } + virtual void addArc(const DRW_Arc &) {} /** Called for every circle */ - virtual void addCircle(const DRW_Circle &) { } + virtual void addCircle(const DRW_Circle &) {} /** Called for every ellipse */ - virtual void addEllipse(const DRW_Ellipse &) { } + virtual void addEllipse(const DRW_Ellipse &) {} /** Called for every lwpolyline */ - virtual void addLWPolyline(const DRW_LWPolyline &) { } + virtual void addLWPolyline(const DRW_LWPolyline &) {} /** Called for every polyline start */ - virtual void addPolyline(const DRW_Polyline &) { } + virtual void addPolyline(const DRW_Polyline &) {} /** Called for every spline */ - virtual void addSpline(const DRW_Spline *) { } + virtual void addSpline(const DRW_Spline *) {} - /** Called for every spline knot value */ - virtual void addKnot(const DRW_Entity &) { } + /** Called for every spline knot value */ + virtual void addKnot(const DRW_Entity &) {} /** Called for every insert. */ - virtual void addInsert(const DRW_Insert &) { } + virtual void addInsert(const DRW_Insert &) {} /** Called for every trace start */ - virtual void addTrace(const DRW_Trace &) { } + virtual void addTrace(const DRW_Trace &) {} /** Called for every 3dface start */ - virtual void add3dFace(const DRW_3Dface &) { } + virtual void add3dFace(const DRW_3Dface &) {} /** Called for every solid start */ - virtual void addSolid(const DRW_Solid &) { } - + virtual void addSolid(const DRW_Solid &) {} /** Called for every Multi Text entity. */ - virtual void addMText(const DRW_MText &) { } + virtual void addMText(const DRW_MText &) {} /** Called for every Text entity. */ - virtual void addText(const DRW_Text &) { } + virtual void addText(const DRW_Text &) {} /** * Called for every aligned dimension entity. */ - virtual void addDimAlign(const DRW_DimAligned *) { } + virtual void addDimAlign(const DRW_DimAligned *) {} /** * Called for every linear or rotated dimension entity. */ - virtual void addDimLinear(const DRW_DimLinear *) { } + virtual void addDimLinear(const DRW_DimLinear *) {} - /** + /** * Called for every radial dimension entity. */ - virtual void addDimRadial(const DRW_DimRadial *) { } + virtual void addDimRadial(const DRW_DimRadial *) {} - /** + /** * Called for every diametric dimension entity. */ - virtual void addDimDiametric(const DRW_DimDiametric *) { } + virtual void addDimDiametric(const DRW_DimDiametric *) {} - /** + /** * Called for every angular dimension (2 lines version) entity. */ - virtual void addDimAngular(const DRW_DimAngular *) { } + virtual void addDimAngular(const DRW_DimAngular *) {} - /** + /** * Called for every angular dimension (3 points version) entity. */ - virtual void addDimAngular3P(const DRW_DimAngular3p *) { } + virtual void addDimAngular3P(const DRW_DimAngular3p *) {} /** * Called for every ordinate dimension entity. */ - virtual void addDimOrdinate(const DRW_DimOrdinate *) { } + virtual void addDimOrdinate(const DRW_DimOrdinate *) {} /** - * Called for every leader start. - */ - virtual void addLeader(const DRW_Leader *) { } + * Called for every leader start. + */ + virtual void addLeader(const DRW_Leader *) {} - /** - * Called for every hatch entity. - */ - virtual void addHatch(const DRW_Hatch *) { } + /** + * Called for every hatch entity. + */ + virtual void addHatch(const DRW_Hatch *) {} /** * Called for every viewport entity. */ - virtual void addViewport(const DRW_Viewport &) { } + virtual void addViewport(const DRW_Viewport &) {} /** - * Called for every image entity. - */ - virtual void addImage(const DRW_Image *) { } + * Called for every image entity. + */ + virtual void addImage(const DRW_Image *) {} - /** - * Called for every image definition. - */ - virtual void linkImage(const DRW_ImageDef *) { } + /** + * Called for every image definition. + */ + virtual void linkImage(const DRW_ImageDef *) {} /** * Called for every comment in the DXF file (code 999). */ - virtual void addComment(const char *) { } + virtual void addComment(const char *) {} /** * Called for PLOTSETTINGS object definition. */ virtual void addPlotSettings(const DRW_PlotSettings *) {} - virtual void writeHeader(DRW_Header &) { } - virtual void writeBlocks() { } - virtual void writeBlockRecords() { } - virtual void writeEntities() { } - virtual void writeLTypes() { } - virtual void writeLayers() { } - virtual void writeTextstyles() { } - virtual void writeVports() { } - virtual void writeDimstyles() { } + virtual void writeHeader(DRW_Header &) {} + virtual void writeBlocks() {} + virtual void writeBlockRecords() {} + virtual void writeEntities() {} + virtual void writeLTypes() {} + virtual void writeLayers() {} + virtual void writeTextstyles() {} + virtual void writeVports() {} + virtual void writeDimstyles() {} virtual void writeObjects() {} - virtual void writeAppId() { } + virtual void writeAppId() {} }; QT_WARNING_POP diff --git a/src/libs/vdxf/libdxfrw/libdxfrw.cpp b/src/libs/vdxf/libdxfrw/libdxfrw.cpp index 4f06abc4e..a89f94107 100644 --- a/src/libs/vdxf/libdxfrw/libdxfrw.cpp +++ b/src/libs/vdxf/libdxfrw/libdxfrw.cpp @@ -10,18 +10,17 @@ ** along with this program. If not, see . ** ******************************************************************************/ - #include "libdxfrw.h" -#include -#include -#include -#include -#include -#include +#include "intern/drw_dbg.h" #include "intern/drw_textcodec.h" #include "intern/dxfreader.h" #include "intern/dxfwriter.h" -#include "intern/drw_dbg.h" +#include +#include +#include +#include +#include +#include #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/diagnostic.h" #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) @@ -37,45 +36,48 @@ secObjects };*/ -dxfRW::dxfRW(const char* name) - : version(), - fileName(name), - codePage(), - binFile(), - reader(nullptr), - writer(nullptr), - iface(), - header(), - nextentity(), - entCount(), - wlayer0(), - dimstyleStd(), - applyExt(false), - writingBlock(), - elParts(128), //parts number when convert ellipse to polyline - blockMap(), - imageDef(), - currHandle() +dxfRW::dxfRW(const char *name) + : version(), + fileName(name), + codePage(), + binFile(), + reader(nullptr), + writer(nullptr), + iface(), + header(), + nextentity(), + entCount(), + wlayer0(), + dimstyleStd(), + applyExt(false), + writingBlock(), + elParts(128), // parts number when convert ellipse to polyline + blockMap(), + imageDef(), + currHandle() { DRW_DBGSL(DRW_dbg::Level::None); } -dxfRW::~dxfRW(){ +dxfRW::~dxfRW() +{ delete reader; delete writer; - for (std::vector::iterator it=imageDef.begin(); it!=imageDef.end(); ++it) + for (std::vector::iterator it = imageDef.begin(); it != imageDef.end(); ++it) delete *it; imageDef.clear(); } -void dxfRW::setDebug(DRW::DebugLevel lvl){ - switch (lvl){ - case DRW::DebugLevel::Debug: - DRW_DBGSL(DRW_dbg::Level::Debug); - break; - default: - DRW_DBGSL(DRW_dbg::Level::None); +void dxfRW::setDebug(DRW::DebugLevel lvl) +{ + switch (lvl) + { + case DRW::DebugLevel::Debug: + DRW_DBGSL(DRW_dbg::Level::Debug); + break; + default: + DRW_DBGSL(DRW_dbg::Level::None); } } @@ -84,12 +86,14 @@ auto dxfRW::read(DRW_Interface *interface_, bool ext) -> bool drw_assert(fileName.empty() == false); applyExt = ext; std::ifstream filestr; - if (nullptr == interface_) { + if (nullptr == interface_) + { return setError(DRW::BAD_UNKNOWN); } DRW_DBG("dxfRW::read 1def\n"); - filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary); - if (!filestr.is_open() || !filestr.good()) { + filestr.open(fileName.c_str(), std::ios_base::in | std::ios::binary); + if (!filestr.is_open() || !filestr.good()) + { return setError(DRW::BAD_OPEN); } @@ -97,20 +101,23 @@ auto dxfRW::read(DRW_Interface *interface_, bool ext) -> bool char line2[22] = "AutoCAD Binary DXF\r\n"; line2[20] = static_cast(26); line2[21] = '\0'; - filestr.read (line, 22); + filestr.read(line, 22); filestr.close(); iface = interface_; DRW_DBG("dxfRW::read 2\n"); - if (strcmp(line, line2) == 0) { - filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary); + if (strcmp(line, line2) == 0) + { + filestr.open(fileName.c_str(), std::ios_base::in | std::ios::binary); binFile = true; - //skip sentinel - filestr.seekg (22, std::ios::beg); + // skip sentinel + filestr.seekg(22, std::ios::beg); reader = new dxfReaderBinary(&filestr); DRW_DBG("dxfRW::read binary file\n"); - } else { + } + else + { binFile = false; - filestr.open (fileName.c_str(), std::ios_base::in); + filestr.open(fileName.c_str(), std::ios_base::in); reader = new dxfReaderAscii(&filestr); } @@ -131,14 +138,17 @@ auto dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin) -> bool iface = interface_; try { - if (binFile) { - filestr.open (fileName.c_str(), std::ios_base::out | std::ios::binary | std::ios::trunc); - //write sentinel + if (binFile) + { + filestr.open(fileName.c_str(), std::ios_base::out | std::ios::binary | std::ios::trunc); + // write sentinel filestr << "AutoCAD Binary DXF\r\n" << static_cast(26) << '\0'; writer = new dxfWriterBinary(&filestr); DRW_DBG("dxfRW::read binary file\n"); - } else { - filestr.open (fileName.c_str(), std::ios_base::out | std::ios::trunc); + } + else + { + filestr.open(fileName.c_str(), std::ios_base::out | std::ios::trunc); writer = new dxfWriterAscii(&filestr); std::string comm = std::string("dxfrw ") + std::string(DRW_VERSION); writer->writeString(999, comm); @@ -149,7 +159,8 @@ auto dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin) -> bool entCount = FIRSTHANDLE; header.write(writer, version); writer->writeString(0, "ENDSEC"); - if (ver > DRW::AC1009) { + if (ver > DRW::AC1009) + { writer->writeString(0, "SECTION"); writer->writeString(2, "CLASSES"); writer->writeString(0, "ENDSEC"); @@ -168,7 +179,8 @@ auto dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin) -> bool iface->writeEntities(); writer->writeString(0, "ENDSEC"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(0, "SECTION"); writer->writeString(2, "OBJECTS"); writeObjects(); @@ -178,7 +190,7 @@ auto dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin) -> bool filestr.flush(); filestr.close(); } - catch(std::ofstream::failure &writeErr) + catch (std::ofstream::failure &writeErr) { errorString = writeErr.what(); delete writer; @@ -218,26 +230,33 @@ auto dxfRW::writeEntity(DRW_Entity *ent) -> bool writer->writeString(5, toHexStr(static_cast(ent->handle))); } - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbEntity"); } if (ent->space == 1) writer->writeInt16(67, 1); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeUtf8String(8, ent->layer); writer->writeUtf8String(6, ent->lineType); - } else { + } + else + { writer->writeUtf8Caps(8, ent->layer); writer->writeUtf8Caps(6, ent->lineType); } writer->writeInt16(62, ent->color); - if (version > DRW::AC1015 && ent->color24 >= 0) { + if (version > DRW::AC1015 && ent->color24 >= 0) + { writer->writeInt32(420, ent->color24); } - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeInt16(370, DRW_LW_Conv::lineWidth2dxfInt(ent->lWeight)); } - if (version >= DRW::AC1014) { + if (version >= DRW::AC1014) + { writeAppData(ent->appData); } return true; @@ -245,25 +264,32 @@ auto dxfRW::writeEntity(DRW_Entity *ent) -> bool auto dxfRW::writeAppData(const std::list> &appData) -> bool { - for(const auto& group : appData) { - //Search for application name + for (const auto &group : appData) + { + // Search for application name bool found = false; - for(const auto& data : group) { - if(data.code == 102 && data.type == DRW_Variant::STRING) { + for (const auto &data : group) + { + if (data.code == 102 && data.type == DRW_Variant::STRING) + { writer->writeString(102, "{" + *(data.content.s)); found = true; break; } } - if(found) { - for(const auto& data : group) { - if(data.code == 102) { + if (found) + { + for (const auto &data : group) + { + if (data.code == 102) + { continue; } - switch(data.type) { + switch (data.type) + { case DRW_Variant::STRING: writer->writeString(data.code, *(data.content.s)); break; @@ -291,21 +317,25 @@ auto dxfRW::writeLineType(DRW_LType *ent) -> bool { std::string strname = ent->name; - transform(strname.begin(), strname.end(), strname.begin(),::toupper); -//do not write linetypes handled by library - if (strname == "BYLAYER" || strname == "BYBLOCK" || strname == "CONTINUOUS") { + transform(strname.begin(), strname.end(), strname.begin(), ::toupper); + // do not write linetypes handled by library + if (strname == "BYLAYER" || strname == "BYBLOCK" || strname == "CONTINUOUS") + { return true; } writer->writeString(0, "LTYPE"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, toHexStr(++entCount)); - if (version > DRW::AC1012) { + if (version > DRW::AC1012) + { writer->writeString(330, "5"); } writer->writeString(100, "AcDbSymbolTableRecord"); writer->writeString(100, "AcDbLinetypeTableRecord"); writer->writeUtf8String(2, ent->name); - } else + } + else writer->writeUtf8Caps(2, ent->name); writer->writeInt16(70, ent->flags); writer->writeUtf8String(3, ent->desc); @@ -314,9 +344,11 @@ auto dxfRW::writeLineType(DRW_LType *ent) -> bool writer->writeInt16(73, ent->size); writer->writeDouble(40, ent->length); - for (unsigned int i = 0; i< ent->path.size(); i++){ + for (unsigned int i = 0; i < ent->path.size(); i++) + { writer->writeDouble(49, ent->path.at(i)); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeInt16(74, 0); } } @@ -326,68 +358,87 @@ auto dxfRW::writeLineType(DRW_LType *ent) -> bool auto dxfRW::writeLayer(DRW_Layer *ent) -> bool { writer->writeString(0, "LAYER"); - if (!wlayer0 && ent->name == "0") { + if (!wlayer0 && ent->name == "0") + { wlayer0 = true; - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "10"); } - } else { - if (version > DRW::AC1009) { + } + else + { + if (version > DRW::AC1009) + { writer->writeString(5, toHexStr(++entCount)); } } - if (version > DRW::AC1012) { + if (version > DRW::AC1012) + { writer->writeString(330, "2"); } - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbSymbolTableRecord"); writer->writeString(100, "AcDbLayerTableRecord"); writer->writeUtf8String(2, ent->name); - } else { + } + else + { writer->writeUtf8Caps(2, ent->name); } writer->writeInt16(70, ent->flags); writer->writeInt16(62, ent->color); - if (version > DRW::AC1015 && ent->color24 >= 0) { + if (version > DRW::AC1015 && ent->color24 >= 0) + { writer->writeInt32(420, ent->color24); } - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeUtf8String(6, ent->lineType); - if (! ent->plotF) + if (!ent->plotF) writer->writeBool(290, ent->plotF); writer->writeInt16(370, DRW_LW_Conv::lineWidth2dxfInt(ent->lWeight)); writer->writeString(390, "F"); - } else + } + else writer->writeUtf8Caps(6, ent->lineType); - if (!ent->extData.empty()){ + if (!ent->extData.empty()) + { writeExtData(ent->extData); } -// writer->writeString(347, "10012"); + // writer->writeString(347, "10012"); return true; } auto dxfRW::writeTextstyle(DRW_Textstyle *ent) -> bool { writer->writeString(0, "STYLE"); - if (!dimstyleStd) { - //stringstream cause crash in OS/X, bug#3597944 - std::string name=ent->name; + if (!dimstyleStd) + { + // stringstream cause crash in OS/X, bug#3597944 + std::string name = ent->name; transform(name.begin(), name.end(), name.begin(), toupper); if (name == "STANDARD") dimstyleStd = true; } - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, toHexStr(++entCount)); } - if (version > DRW::AC1012) { + if (version > DRW::AC1012) + { writer->writeString(330, "2"); } - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbSymbolTableRecord"); writer->writeString(100, "AcDbTextStyleTableRecord"); writer->writeUtf8String(2, ent->name); - } else { + } + else + { writer->writeUtf8Caps(2, ent->name); } writer->writeInt16(70, ent->flags); @@ -396,14 +447,17 @@ auto dxfRW::writeTextstyle(DRW_Textstyle *ent) -> bool writer->writeDouble(50, ent->oblique); writer->writeInt16(71, ent->genFlag); writer->writeDouble(42, ent->lastHeight); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeUtf8String(3, ent->font); writer->writeUtf8String(4, ent->bigFont); writer->writeUtf8String(1001, "ACAD"); writer->writeUtf8String(1000, ent->font); if (ent->fontFamily != 0) writer->writeInt32(1071, ent->fontFamily); - } else { + } + else + { writer->writeUtf8Caps(3, ent->font); writer->writeUtf8Caps(4, ent->bigFont); } @@ -412,19 +466,22 @@ auto dxfRW::writeTextstyle(DRW_Textstyle *ent) -> bool auto dxfRW::writeVport(DRW_Vport *ent) -> bool { - if (!dimstyleStd) { + if (!dimstyleStd) + { ent->name = "*ACTIVE"; dimstyleStd = true; } writer->writeString(0, "VPORT"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, toHexStr(++entCount)); if (version > DRW::AC1012) writer->writeString(330, "2"); writer->writeString(100, "AcDbSymbolTableRecord"); writer->writeString(100, "AcDbViewportTableRecord"); writer->writeUtf8String(2, ent->name); - } else + } + else writer->writeUtf8Caps(2, ent->name); writer->writeInt16(70, ent->flags); writer->writeDouble(10, ent->lowerLeft.x); @@ -460,7 +517,8 @@ auto dxfRW::writeVport(DRW_Vport *ent) -> bool writer->writeInt16(76, ent->grid); writer->writeInt16(77, ent->snapStyle); writer->writeInt16(78, ent->snapIsopair); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeInt16(281, 0); writer->writeInt16(65, 1); writer->writeDouble(110, 0.0); @@ -474,9 +532,10 @@ auto dxfRW::writeVport(DRW_Vport *ent) -> bool writer->writeDouble(132, 0.0); writer->writeInt16(79, 0); writer->writeDouble(146, 0.0); - if (version > DRW::AC1018) { + if (version > DRW::AC1018) + { writer->writeString(348, "10020"); - writer->writeInt16(60, ent->gridBehavior);//v2007 undocummented see DRW_Vport class + writer->writeInt16(60, ent->gridBehavior); // v2007 undocummented see DRW_Vport class writer->writeInt16(61, 5); writer->writeBool(292, 1); writer->writeInt16(282, 1); @@ -492,36 +551,41 @@ auto dxfRW::writeVport(DRW_Vport *ent) -> bool auto dxfRW::writeDimstyle(DRW_Dimstyle *ent) -> bool { writer->writeString(0, "DIMSTYLE"); - if (!dimstyleStd) { + if (!dimstyleStd) + { std::string name = ent->name; - std::transform(name.begin(), name.end(), name.begin(),::toupper); + std::transform(name.begin(), name.end(), name.begin(), ::toupper); if (name == "STANDARD") dimstyleStd = true; } - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(105, toHexStr(++entCount)); } - if (version > DRW::AC1012) { + if (version > DRW::AC1012) + { writer->writeString(330, "A"); } - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbSymbolTableRecord"); writer->writeString(100, "AcDbDimStyleTableRecord"); writer->writeUtf8String(2, ent->name); - } else + } + else writer->writeUtf8Caps(2, ent->name); writer->writeInt16(70, ent->flags); - if ( version <= DRW::AC1009 || !(ent->dimpost.empty()) ) + if (version <= DRW::AC1009 || !(ent->dimpost.empty())) writer->writeUtf8String(3, ent->dimpost); - if ( version <= DRW::AC1009 || !(ent->dimapost.empty()) ) + if (version <= DRW::AC1009 || !(ent->dimapost.empty())) writer->writeUtf8String(4, ent->dimapost); - if ( version <= DRW::AC1009 || !(ent->dimblk.empty()) ) + if (version <= DRW::AC1009 || !(ent->dimblk.empty())) writer->writeUtf8String(5, ent->dimblk); - if ( version <= DRW::AC1009 || !(ent->dimblk1.empty()) ) + if (version <= DRW::AC1009 || !(ent->dimblk1.empty())) writer->writeUtf8String(6, ent->dimblk1); - if ( version <= DRW::AC1009 || !(ent->dimblk2.empty()) ) + if (version <= DRW::AC1009 || !(ent->dimblk2.empty())) writer->writeUtf8String(7, ent->dimblk2); writer->writeDouble(40, ent->dimscale); writer->writeDouble(41, ent->dimasz); @@ -540,7 +604,8 @@ auto dxfRW::writeDimstyle(DRW_Dimstyle *ent) -> bool writer->writeDouble(145, ent->dimtvp); writer->writeDouble(146, ent->dimtfac); writer->writeDouble(147, ent->dimgap); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeDouble(148, ent->dimaltrnd); } writer->writeInt16(71, ent->dimtol); @@ -551,7 +616,8 @@ auto dxfRW::writeDimstyle(DRW_Dimstyle *ent) -> bool writer->writeInt16(76, ent->dimse2); writer->writeInt16(77, ent->dimtad); writer->writeInt16(78, ent->dimzin); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeInt16(79, ent->dimazin); } writer->writeInt16(170, ent->dimalt); @@ -563,10 +629,12 @@ auto dxfRW::writeDimstyle(DRW_Dimstyle *ent) -> bool writer->writeInt16(176, ent->dimclrd); writer->writeInt16(177, ent->dimclre); writer->writeInt16(178, ent->dimclrt); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeInt16(179, ent->dimadec); } - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { if (version < DRW::AC1015) writer->writeInt16(270, ent->dimunit); writer->writeInt16(271, ent->dimdec); @@ -575,13 +643,15 @@ auto dxfRW::writeDimstyle(DRW_Dimstyle *ent) -> bool writer->writeInt16(274, ent->dimalttd); writer->writeInt16(275, ent->dimaunit); } - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeInt16(276, ent->dimfrac); writer->writeInt16(277, ent->dimlunit); writer->writeInt16(278, ent->dimdsep); writer->writeInt16(279, ent->dimtmove); } - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeInt16(280, ent->dimjust); writer->writeInt16(281, ent->dimsd1); writer->writeInt16(282, ent->dimsd2); @@ -593,13 +663,16 @@ auto dxfRW::writeDimstyle(DRW_Dimstyle *ent) -> bool writer->writeInt16(287, ent->dimfit); writer->writeInt16(288, ent->dimupt); } - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeInt16(289, ent->dimatfit); } - if (version > DRW::AC1009 && !ent->dimtxsty.empty()) { + if (version > DRW::AC1009 && !ent->dimtxsty.empty()) + { writer->writeUtf8String(340, ent->dimtxsty); } - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeUtf8String(341, ent->dimldrblk); writer->writeInt16(371, ent->dimlwd); writer->writeInt16(372, ent->dimlwe); @@ -610,20 +683,24 @@ auto dxfRW::writeDimstyle(DRW_Dimstyle *ent) -> bool auto dxfRW::writeAppId(DRW_AppId *ent) -> bool { std::string strname = ent->name; - transform(strname.begin(), strname.end(), strname.begin(),::toupper); -//do not write mandatory ACAD appId, handled by library + transform(strname.begin(), strname.end(), strname.begin(), ::toupper); + // do not write mandatory ACAD appId, handled by library if (strname == "ACAD") return true; writer->writeString(0, "APPID"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, toHexStr(++entCount)); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "9"); } writer->writeString(100, "AcDbSymbolTableRecord"); writer->writeString(100, "AcDbRegAppTableRecord"); writer->writeUtf8String(2, ent->name); - } else { + } + else + { writer->writeUtf8Caps(2, ent->name); } writer->writeInt16(70, ent->flags); @@ -634,12 +711,14 @@ auto dxfRW::writePoint(DRW_Point *ent) -> bool { writer->writeString(0, "POINT"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbPoint"); } writer->writeDouble(10, ent->basePoint.x); writer->writeDouble(20, ent->basePoint.y); - if (not qFuzzyIsNull(ent->basePoint.z)) { + if (not qFuzzyIsNull(ent->basePoint.z)) + { writer->writeDouble(30, ent->basePoint.z); } return true; @@ -661,17 +740,21 @@ auto dxfRW::writeLine(DRW_Line *ent) -> bool { writer->writeString(0, "LINE"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbLine"); } writer->writeDouble(10, ent->basePoint.x); writer->writeDouble(20, ent->basePoint.y); - if (not qFuzzyIsNull(ent->basePoint.z) || not qFuzzyIsNull(ent->secPoint.z)) { + if (not qFuzzyIsNull(ent->basePoint.z) || not qFuzzyIsNull(ent->secPoint.z)) + { writer->writeDouble(30, ent->basePoint.z); writer->writeDouble(11, ent->secPoint.x); writer->writeDouble(21, ent->secPoint.y); writer->writeDouble(31, ent->secPoint.z); - } else { + } + else + { writer->writeDouble(11, ent->secPoint.x); writer->writeDouble(21, ent->secPoint.y); } @@ -682,19 +765,23 @@ auto dxfRW::writeRay(DRW_Ray *ent) -> bool { writer->writeString(0, "RAY"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbRay"); } DRW_Coord crd = ent->secPoint; crd.unitize(); writer->writeDouble(10, ent->basePoint.x); writer->writeDouble(20, ent->basePoint.y); - if (not qFuzzyIsNull(ent->basePoint.z) || not qFuzzyIsNull(ent->secPoint.z)) { + if (not qFuzzyIsNull(ent->basePoint.z) || not qFuzzyIsNull(ent->secPoint.z)) + { writer->writeDouble(30, ent->basePoint.z); writer->writeDouble(11, crd.x); writer->writeDouble(21, crd.y); writer->writeDouble(31, crd.z); - } else { + } + else + { writer->writeDouble(11, crd.x); writer->writeDouble(21, crd.y); } @@ -705,19 +792,23 @@ auto dxfRW::writeXline(DRW_Xline *ent) -> bool { writer->writeString(0, "XLINE"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbXline"); } DRW_Coord crd = ent->secPoint; crd.unitize(); writer->writeDouble(10, ent->basePoint.x); writer->writeDouble(20, ent->basePoint.y); - if (not qFuzzyIsNull(ent->basePoint.z) || not qFuzzyIsNull(ent->secPoint.z)) { + if (not qFuzzyIsNull(ent->basePoint.z) || not qFuzzyIsNull(ent->secPoint.z)) + { writer->writeDouble(30, ent->basePoint.z); writer->writeDouble(11, crd.x); writer->writeDouble(21, crd.y); writer->writeDouble(31, crd.z); - } else { + } + else + { writer->writeDouble(11, crd.x); writer->writeDouble(21, crd.y); } @@ -728,12 +819,14 @@ auto dxfRW::writeCircle(DRW_Circle *ent) -> bool { writer->writeString(0, "CIRCLE"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbCircle"); } writer->writeDouble(10, ent->basePoint.x); writer->writeDouble(20, ent->basePoint.y); - if (not qFuzzyIsNull(ent->basePoint.z)) { + if (not qFuzzyIsNull(ent->basePoint.z)) + { writer->writeDouble(30, ent->basePoint.z); } writer->writeDouble(40, ent->radious); @@ -744,31 +837,36 @@ auto dxfRW::writeArc(DRW_Arc *ent) -> bool { writer->writeString(0, "ARC"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbCircle"); } writer->writeDouble(10, ent->basePoint.x); writer->writeDouble(20, ent->basePoint.y); - if (not qFuzzyIsNull(ent->basePoint.z)) { + if (not qFuzzyIsNull(ent->basePoint.z)) + { writer->writeDouble(30, ent->basePoint.z); } writer->writeDouble(40, ent->radious); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbArc"); } - writer->writeDouble(50, ent->staangle*ARAD); - writer->writeDouble(51, ent->endangle*ARAD); + writer->writeDouble(50, ent->staangle * ARAD); + writer->writeDouble(51, ent->endangle * ARAD); return true; } auto dxfRW::writeEllipse(DRW_Ellipse *ent) -> bool { - //verify axis/ratio and params for full ellipse + // verify axis/ratio and params for full ellipse ent->correctAxis(); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(0, "ELLIPSE"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbEllipse"); } writer->writeDouble(10, ent->basePoint.x); @@ -780,9 +878,11 @@ auto dxfRW::writeEllipse(DRW_Ellipse *ent) -> bool writer->writeDouble(40, ent->ratio); writer->writeDouble(41, ent->staparam); writer->writeDouble(42, ent->endparam); - } else { + } + else + { DRW_Polyline pol; - //RLZ: copy properties + // RLZ: copy properties ent->toPolyline(&pol, elParts); writePolyline(&pol); } @@ -793,7 +893,8 @@ auto dxfRW::writeTrace(DRW_Trace *ent) -> bool { writer->writeString(0, "TRACE"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbTrace"); } writer->writeDouble(10, ent->basePoint.x); @@ -815,7 +916,8 @@ auto dxfRW::writeSolid(DRW_Solid *ent) -> bool { writer->writeString(0, "SOLID"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbTrace"); } writer->writeDouble(10, ent->basePoint.x); @@ -837,7 +939,8 @@ auto dxfRW::write3dface(DRW_3Dface *ent) -> bool { writer->writeString(0, "3DFACE"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbFace"); } writer->writeDouble(10, ent->basePoint.x); @@ -858,10 +961,12 @@ auto dxfRW::write3dface(DRW_3Dface *ent) -> bool auto dxfRW::writeLWPolyline(DRW_LWPolyline *ent) -> bool { - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(0, "LWPOLYLINE"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbPolyline"); } ent->vertexnum = static_cast(ent->vertlist.size()); @@ -872,7 +977,8 @@ auto dxfRW::writeLWPolyline(DRW_LWPolyline *ent) -> bool writer->writeDouble(38, ent->elevation); if (not qFuzzyIsNull(ent->thickness)) writer->writeDouble(39, ent->thickness); - for (int i = 0; i< ent->vertexnum; i++){ + for (int i = 0; i < ent->vertexnum; i++) + { DRW_Vertex2D *v = ent->vertlist.at(static_cast(i)); writer->writeDouble(10, v->x); writer->writeDouble(20, v->y); @@ -883,8 +989,10 @@ auto dxfRW::writeLWPolyline(DRW_LWPolyline *ent) -> bool if (not qFuzzyIsNull(v->bulge)) writer->writeDouble(42, v->bulge); } - } else { - //RLZ: TODO convert lwpolyline in polyline (not exist in acad 12) + } + else + { + // RLZ: TODO convert lwpolyline in polyline (not exist in acad 12) } return true; } @@ -894,67 +1002,87 @@ auto dxfRW::writePolyline(DRW_Polyline *ent) -> bool writer->writeString(0, "POLYLINE"); writeEntity(ent); bool is3d = false; - if (version > DRW::AC1009) { - if (ent->flags & 8 || ent->flags & 16) { + if (version > DRW::AC1009) + { + if (ent->flags & 8 || ent->flags & 16) + { writer->writeString(100, "AcDb3dPolyline"); is3d = true; - } else { + } + else + { writer->writeString(100, "AcDb2dPolyline"); } - } else + } + else writer->writeInt16(66, 1); writer->writeDouble(10, 0.0); writer->writeDouble(20, 0.0); writer->writeDouble(30, ent->basePoint.z); - if (not qFuzzyIsNull(ent->thickness)) { + if (not qFuzzyIsNull(ent->thickness)) + { writer->writeDouble(39, ent->thickness); } writer->writeInt16(70, ent->flags); - if (not qFuzzyIsNull(ent->defstawidth)) { + if (not qFuzzyIsNull(ent->defstawidth)) + { writer->writeDouble(40, ent->defstawidth); } - if (not qFuzzyIsNull(ent->defendwidth)) { + if (not qFuzzyIsNull(ent->defendwidth)) + { writer->writeDouble(41, ent->defendwidth); } - if (ent->flags & 16 || ent->flags & 32) { + if (ent->flags & 16 || ent->flags & 32) + { writer->writeInt16(71, ent->vertexcount); writer->writeInt16(72, ent->facecount); } - if (ent->smoothM != 0) { + if (ent->smoothM != 0) + { writer->writeInt16(73, ent->smoothM); } - if (ent->smoothN != 0) { + if (ent->smoothN != 0) + { writer->writeInt16(74, ent->smoothN); } - if (ent->curvetype != 0) { + if (ent->curvetype != 0) + { writer->writeInt16(75, ent->curvetype); } - DRW_Coord crd = ent->extPoint; - if (not qFuzzyIsNull(crd.x) || not qFuzzyIsNull(crd.y) || not DRW_FuzzyComparePossibleNulls(crd.z, 1)) { + DRW_Coord crd = ent->extPoint; + if (not qFuzzyIsNull(crd.x) || not qFuzzyIsNull(crd.y) || not DRW_FuzzyComparePossibleNulls(crd.z, 1)) + { writer->writeDouble(210, crd.x); writer->writeDouble(220, crd.y); writer->writeDouble(230, crd.z); } size_t vertexnum = ent->vertlist.size(); - for (size_t i = 0; i < vertexnum; i++) { + for (size_t i = 0; i < vertexnum; i++) + { DRW_Vertex *v = ent->vertlist.at(i); writer->writeString(0, "VERTEX"); writeEntity(ent); if (version > DRW::AC1009) { writer->writeString(100, "AcDbVertex"); - if(is3d) { + if (is3d) + { writer->writeString(100, "AcDb3dPolylineVertex"); - } else { + } + else + { writer->writeString(100, "AcDb2dVertex"); } } - if ( (v->flags & 128) && !(v->flags & 64) ) { + if ((v->flags & 128) && !(v->flags & 64)) + { writer->writeDouble(10, 0); writer->writeDouble(20, 0); writer->writeDouble(30, 0); - } else { + } + else + { writer->writeDouble(10, v->basePoint.x); writer->writeDouble(20, v->basePoint.y); writer->writeDouble(30, v->basePoint.z); @@ -965,26 +1093,34 @@ auto dxfRW::writePolyline(DRW_Polyline *ent) -> bool writer->writeDouble(41, v->endwidth); if (not qFuzzyIsNull(v->bulge)) writer->writeDouble(42, v->bulge); - if (v->flags != 0) { + if (v->flags != 0) + { writer->writeInt16(70, ent->flags); } - if (v->flags & 2) { + if (v->flags & 2) + { writer->writeDouble(50, v->tgdir); } - if ( v->flags & 128 ) { - if (v->vindex1 != 0) { + if (v->flags & 128) + { + if (v->vindex1 != 0) + { writer->writeInt16(71, v->vindex1); } - if (v->vindex2 != 0) { + if (v->vindex2 != 0) + { writer->writeInt16(72, v->vindex2); } - if (v->vindex3 != 0) { + if (v->vindex3 != 0) + { writer->writeInt16(73, v->vindex3); } - if (v->vindex4 != 0) { + if (v->vindex4 != 0) + { writer->writeInt16(74, v->vindex4); } - if ( !(v->flags & 64) ) { + if (!(v->flags & 64)) + { writer->writeInt32(91, v->identifier); } } @@ -996,10 +1132,12 @@ auto dxfRW::writePolyline(DRW_Polyline *ent) -> bool auto dxfRW::writeSpline(DRW_Spline *ent) -> bool { - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(0, "SPLINE"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbSpline"); } writer->writeDouble(210, ent->normalVec.x); @@ -1012,28 +1150,34 @@ auto dxfRW::writeSpline(DRW_Spline *ent) -> bool writer->writeInt16(74, ent->nfit); writer->writeDouble(42, ent->tolknot); writer->writeDouble(43, ent->tolcontrol); - //RLZ: warning check if nknots are correct and ncontrol - for (int i = 0; i< ent->nknots; i++){ + // RLZ: warning check if nknots are correct and ncontrol + for (int i = 0; i < ent->nknots; i++) + { writer->writeDouble(40, ent->knotslist.at(static_cast(i))); } - for (int i = 0; i< static_cast(ent->weightlist.size()); i++) { + for (int i = 0; i < static_cast(ent->weightlist.size()); i++) + { writer->writeDouble(41, ent->weightlist.at(static_cast(i))); } - for (int i = 0; i< ent->ncontrol; i++){ + for (int i = 0; i < ent->ncontrol; i++) + { DRW_Coord *crd = ent->controllist.at(static_cast(i)); writer->writeDouble(10, crd->x); writer->writeDouble(20, crd->y); writer->writeDouble(30, crd->z); } - } else { - //RLZ: TODO convert spline in polyline (not exist in acad 12) + } + else + { + // RLZ: TODO convert spline in polyline (not exist in acad 12) } return true; } auto dxfRW::writeHatch(DRW_Hatch *ent) -> bool { - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(0, "HATCH"); writeEntity(ent); writer->writeString(100, "AcDbHatch"); @@ -1048,55 +1192,67 @@ auto dxfRW::writeHatch(DRW_Hatch *ent) -> bool writer->writeInt16(71, ent->associative); ent->loopsnum = static_cast(ent->looplist.size()); writer->writeInt16(91, ent->loopsnum); - //write paths data - for (int i = 0; i< ent->loopsnum; i++){ + // write paths data + for (int i = 0; i < ent->loopsnum; i++) + { DRW_HatchLoop *loop = ent->looplist.at(static_cast(i)); writer->writeInt16(92, loop->type); - if ( (loop->type & 2) == 2){ - //RLZ: polyline boundary writeme - } else { - //boundary path + if ((loop->type & 2) == 2) + { + // RLZ: polyline boundary writeme + } + else + { + // boundary path loop->update(); writer->writeInt16(93, loop->numedges); - for (int j = 0; jnumedges; ++j) { - switch ( (loop->objlist.at(static_cast(j)))->eType) { - case DRW::LINE: { - writer->writeInt16(72, 1); - DRW_Line* l = static_cast(loop->objlist.at(static_cast(j))); - writer->writeDouble(10, l->basePoint.x); - writer->writeDouble(20, l->basePoint.y); - writer->writeDouble(11, l->secPoint.x); - writer->writeDouble(21, l->secPoint.y); - break; } - case DRW::ARC: { - writer->writeInt16(72, 2); - DRW_Arc* a = static_cast(loop->objlist.at(static_cast(j))); - writer->writeDouble(10, a->basePoint.x); - writer->writeDouble(20, a->basePoint.y); - writer->writeDouble(40, a->radious); - writer->writeDouble(50, a->staangle*ARAD); - writer->writeDouble(51, a->endangle*ARAD); - writer->writeInt16(73, a->isccw); - break; } - case DRW::ELLIPSE: { - writer->writeInt16(72, 3); - DRW_Ellipse* a = static_cast(loop->objlist.at(static_cast(j))); - a->correctAxis(); - writer->writeDouble(10, a->basePoint.x); - writer->writeDouble(20, a->basePoint.y); - writer->writeDouble(11, a->secPoint.x); - writer->writeDouble(21, a->secPoint.y); - writer->writeDouble(40, a->ratio); - writer->writeDouble(50, a->staparam*ARAD); - writer->writeDouble(51, a->endparam*ARAD); - writer->writeInt16(73, a->isccw); - break; } - case DRW::SPLINE: - //RLZ: spline boundary writeme -// writer->writeInt16(72, 4); - break; - default: - break; + for (int j = 0; j < loop->numedges; ++j) + { + switch ((loop->objlist.at(static_cast(j)))->eType) + { + case DRW::LINE: + { + writer->writeInt16(72, 1); + DRW_Line *l = static_cast(loop->objlist.at(static_cast(j))); + writer->writeDouble(10, l->basePoint.x); + writer->writeDouble(20, l->basePoint.y); + writer->writeDouble(11, l->secPoint.x); + writer->writeDouble(21, l->secPoint.y); + break; + } + case DRW::ARC: + { + writer->writeInt16(72, 2); + DRW_Arc *a = static_cast(loop->objlist.at(static_cast(j))); + writer->writeDouble(10, a->basePoint.x); + writer->writeDouble(20, a->basePoint.y); + writer->writeDouble(40, a->radious); + writer->writeDouble(50, a->staangle * ARAD); + writer->writeDouble(51, a->endangle * ARAD); + writer->writeInt16(73, a->isccw); + break; + } + case DRW::ELLIPSE: + { + writer->writeInt16(72, 3); + DRW_Ellipse *a = static_cast(loop->objlist.at(static_cast(j))); + a->correctAxis(); + writer->writeDouble(10, a->basePoint.x); + writer->writeDouble(20, a->basePoint.y); + writer->writeDouble(11, a->secPoint.x); + writer->writeDouble(21, a->secPoint.y); + writer->writeDouble(40, a->ratio); + writer->writeDouble(50, a->staparam * ARAD); + writer->writeDouble(51, a->endparam * ARAD); + writer->writeInt16(73, a->isccw); + break; + } + case DRW::SPLINE: + // RLZ: spline boundary writeme + // writer->writeInt16(72, 4); + break; + default: + break; } } writer->writeInt16(97, 0); @@ -1104,25 +1260,29 @@ auto dxfRW::writeHatch(DRW_Hatch *ent) -> bool } writer->writeInt16(75, ent->hstyle); writer->writeInt16(76, ent->hpattern); - if (!ent->solid){ + if (!ent->solid) + { writer->writeDouble(52, ent->angle); writer->writeDouble(41, ent->scale); writer->writeInt16(77, ent->doubleflag); writer->writeInt16(78, ent->deflines); } -/* if (ent->deflines > 0){ - writer->writeInt16(78, ent->deflines); - }*/ + /* if (ent->deflines > 0){ + writer->writeInt16(78, ent->deflines); + }*/ writer->writeInt32(98, 0); - } else { - //RLZ: TODO verify in acad12 + } + else + { + // RLZ: TODO verify in acad12 } return true; } auto dxfRW::writeLeader(DRW_Leader *ent) -> bool { - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(0, "LEADER"); writeEntity(ent); writer->writeString(100, "AcDbLeader"); @@ -1136,24 +1296,29 @@ auto dxfRW::writeLeader(DRW_Leader *ent) -> bool writer->writeDouble(41, ent->textwidth); writer->writeDouble(76, ent->vertnum); writer->writeDouble(76, static_cast(ent->vertexlist.size())); - for (unsigned int i=0; ivertexlist.size(); i++) { + for (unsigned int i = 0; i < ent->vertexlist.size(); i++) + { DRW_Coord *vert = ent->vertexlist.at(i); writer->writeDouble(10, vert->x); writer->writeDouble(20, vert->y); writer->writeDouble(30, vert->z); } - } else { - //RLZ: todo not supported by acad 12 saved as unnamed block + } + else + { + // RLZ: todo not supported by acad 12 saved as unnamed block } return true; } auto dxfRW::writeDimension(DRW_Dimension *ent) -> bool { - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(0, "DIMENSION"); writeEntity(ent); writer->writeString(100, "AcDbDimension"); - if (!ent->getName().empty()){ + if (!ent->getName().empty()) + { writer->writeString(2, ent->getName()); } writer->writeDouble(10, ent->getDefPoint().x); @@ -1162,110 +1327,127 @@ auto dxfRW::writeDimension(DRW_Dimension *ent) -> bool writer->writeDouble(11, ent->getTextPoint().x); writer->writeDouble(21, ent->getTextPoint().y); writer->writeDouble(31, ent->getTextPoint().z); - if ( !(ent->type & 32)) - ent->type = ent->type +32; + if (!(ent->type & 32)) + ent->type = ent->type + 32; writer->writeInt16(70, ent->type); - if ( !(ent->getText().empty()) ) + if (!(ent->getText().empty())) writer->writeUtf8String(1, ent->getText()); writer->writeInt16(71, ent->getAlign()); - if ( ent->getTextLineStyle() != 1) + if (ent->getTextLineStyle() != 1) writer->writeInt16(72, ent->getTextLineStyle()); - if ( not DRW_FuzzyComparePossibleNulls(ent->getTextLineFactor(), 1)) + if (not DRW_FuzzyComparePossibleNulls(ent->getTextLineFactor(), 1)) writer->writeDouble(41, ent->getTextLineFactor()); writer->writeUtf8String(3, ent->getStyle()); - if ( not qFuzzyIsNull(ent->getTextLineFactor())) + if (not qFuzzyIsNull(ent->getTextLineFactor())) writer->writeDouble(53, ent->getDir()); writer->writeDouble(210, ent->getExtrusion().x); writer->writeDouble(220, ent->getExtrusion().y); writer->writeDouble(230, ent->getExtrusion().z); - if ( ent->hasActualMeasurement()) + if (ent->hasActualMeasurement()) writer->writeDouble(42, ent->getActualMeasurement()); - switch (ent->eType) { - case DRW::DIMALIGNED: - case DRW::DIMLINEAR: { - DRW_DimAligned * dd = static_cast(ent); - writer->writeString(100, "AcDbAlignedDimension"); - DRW_Coord crd = dd->getClonepoint(); - if (not qFuzzyIsNull(crd.x) || not qFuzzyIsNull(crd.y) || not qFuzzyIsNull(crd.z)) { - writer->writeDouble(12, crd.x); - writer->writeDouble(22, crd.y); - writer->writeDouble(32, crd.z); + switch (ent->eType) + { + case DRW::DIMALIGNED: + case DRW::DIMLINEAR: + { + DRW_DimAligned *dd = static_cast(ent); + writer->writeString(100, "AcDbAlignedDimension"); + DRW_Coord crd = dd->getClonepoint(); + if (not qFuzzyIsNull(crd.x) || not qFuzzyIsNull(crd.y) || not qFuzzyIsNull(crd.z)) + { + writer->writeDouble(12, crd.x); + writer->writeDouble(22, crd.y); + writer->writeDouble(32, crd.z); + } + writer->writeDouble(13, dd->getDef1Point().x); + writer->writeDouble(23, dd->getDef1Point().y); + writer->writeDouble(33, dd->getDef1Point().z); + writer->writeDouble(14, dd->getDef2Point().x); + writer->writeDouble(24, dd->getDef2Point().y); + writer->writeDouble(34, dd->getDef2Point().z); + if (ent->eType == DRW::DIMLINEAR) + { + DRW_DimLinear *dl = static_cast(ent); + if (not qFuzzyIsNull(dl->getAngle())) + writer->writeDouble(50, dl->getAngle()); + if (not qFuzzyIsNull(dl->getOblique())) + writer->writeDouble(52, dl->getOblique()); + writer->writeString(100, "AcDbRotatedDimension"); + } + break; } - writer->writeDouble(13, dd->getDef1Point().x); - writer->writeDouble(23, dd->getDef1Point().y); - writer->writeDouble(33, dd->getDef1Point().z); - writer->writeDouble(14, dd->getDef2Point().x); - writer->writeDouble(24, dd->getDef2Point().y); - writer->writeDouble(34, dd->getDef2Point().z); - if (ent->eType == DRW::DIMLINEAR) { - DRW_DimLinear * dl = static_cast(ent); - if (not qFuzzyIsNull(dl->getAngle())) - writer->writeDouble(50, dl->getAngle()); - if (not qFuzzyIsNull(dl->getOblique())) - writer->writeDouble(52, dl->getOblique()); - writer->writeString(100, "AcDbRotatedDimension"); + case DRW::DIMRADIAL: + { + DRW_DimRadial *dd = static_cast(ent); + writer->writeString(100, "AcDbRadialDimension"); + writer->writeDouble(15, dd->getDiameterPoint().x); + writer->writeDouble(25, dd->getDiameterPoint().y); + writer->writeDouble(35, dd->getDiameterPoint().z); + writer->writeDouble(40, dd->getLeaderLength()); + break; } - break; } - case DRW::DIMRADIAL: { - DRW_DimRadial * dd = static_cast(ent); - writer->writeString(100, "AcDbRadialDimension"); - writer->writeDouble(15, dd->getDiameterPoint().x); - writer->writeDouble(25, dd->getDiameterPoint().y); - writer->writeDouble(35, dd->getDiameterPoint().z); - writer->writeDouble(40, dd->getLeaderLength()); - break; } - case DRW::DIMDIAMETRIC: { - DRW_DimDiametric * dd = static_cast(ent); - writer->writeString(100, "AcDbDiametricDimension"); - writer->writeDouble(15, dd->getDiameter1Point().x); - writer->writeDouble(25, dd->getDiameter1Point().y); - writer->writeDouble(35, dd->getDiameter1Point().z); - writer->writeDouble(40, dd->getLeaderLength()); - break; } - case DRW::DIMANGULAR: { - DRW_DimAngular * dd = static_cast(ent); - writer->writeString(100, "AcDb2LineAngularDimension"); - writer->writeDouble(13, dd->getFirstLine1().x); - writer->writeDouble(23, dd->getFirstLine1().y); - writer->writeDouble(33, dd->getFirstLine1().z); - writer->writeDouble(14, dd->getFirstLine2().x); - writer->writeDouble(24, dd->getFirstLine2().y); - writer->writeDouble(34, dd->getFirstLine2().z); - writer->writeDouble(15, dd->getSecondLine1().x); - writer->writeDouble(25, dd->getSecondLine1().y); - writer->writeDouble(35, dd->getSecondLine1().z); - writer->writeDouble(16, dd->getDimPoint().x); - writer->writeDouble(26, dd->getDimPoint().y); - writer->writeDouble(36, dd->getDimPoint().z); - break; } - case DRW::DIMANGULAR3P: { - DRW_DimAngular3p * dd = static_cast(ent); - writer->writeDouble(13, dd->getFirstLine().x); - writer->writeDouble(23, dd->getFirstLine().y); - writer->writeDouble(33, dd->getFirstLine().z); - writer->writeDouble(14, dd->getSecondLine().x); - writer->writeDouble(24, dd->getSecondLine().y); - writer->writeDouble(34, dd->getSecondLine().z); - writer->writeDouble(15, dd->getVertexPoint().x); - writer->writeDouble(25, dd->getVertexPoint().y); - writer->writeDouble(35, dd->getVertexPoint().z); - break; } - case DRW::DIMORDINATE: { - DRW_DimOrdinate * dd = static_cast(ent); - writer->writeString(100, "AcDbOrdinateDimension"); - writer->writeDouble(13, dd->getFirstLine().x); - writer->writeDouble(23, dd->getFirstLine().y); - writer->writeDouble(33, dd->getFirstLine().z); - writer->writeDouble(14, dd->getSecondLine().x); - writer->writeDouble(24, dd->getSecondLine().y); - writer->writeDouble(34, dd->getSecondLine().z); - break; } - default: - break; + case DRW::DIMDIAMETRIC: + { + DRW_DimDiametric *dd = static_cast(ent); + writer->writeString(100, "AcDbDiametricDimension"); + writer->writeDouble(15, dd->getDiameter1Point().x); + writer->writeDouble(25, dd->getDiameter1Point().y); + writer->writeDouble(35, dd->getDiameter1Point().z); + writer->writeDouble(40, dd->getLeaderLength()); + break; + } + case DRW::DIMANGULAR: + { + DRW_DimAngular *dd = static_cast(ent); + writer->writeString(100, "AcDb2LineAngularDimension"); + writer->writeDouble(13, dd->getFirstLine1().x); + writer->writeDouble(23, dd->getFirstLine1().y); + writer->writeDouble(33, dd->getFirstLine1().z); + writer->writeDouble(14, dd->getFirstLine2().x); + writer->writeDouble(24, dd->getFirstLine2().y); + writer->writeDouble(34, dd->getFirstLine2().z); + writer->writeDouble(15, dd->getSecondLine1().x); + writer->writeDouble(25, dd->getSecondLine1().y); + writer->writeDouble(35, dd->getSecondLine1().z); + writer->writeDouble(16, dd->getDimPoint().x); + writer->writeDouble(26, dd->getDimPoint().y); + writer->writeDouble(36, dd->getDimPoint().z); + break; + } + case DRW::DIMANGULAR3P: + { + DRW_DimAngular3p *dd = static_cast(ent); + writer->writeDouble(13, dd->getFirstLine().x); + writer->writeDouble(23, dd->getFirstLine().y); + writer->writeDouble(33, dd->getFirstLine().z); + writer->writeDouble(14, dd->getSecondLine().x); + writer->writeDouble(24, dd->getSecondLine().y); + writer->writeDouble(34, dd->getSecondLine().z); + writer->writeDouble(15, dd->getVertexPoint().x); + writer->writeDouble(25, dd->getVertexPoint().y); + writer->writeDouble(35, dd->getVertexPoint().z); + break; + } + case DRW::DIMORDINATE: + { + DRW_DimOrdinate *dd = static_cast(ent); + writer->writeString(100, "AcDbOrdinateDimension"); + writer->writeDouble(13, dd->getFirstLine().x); + writer->writeDouble(23, dd->getFirstLine().y); + writer->writeDouble(33, dd->getFirstLine().z); + writer->writeDouble(14, dd->getSecondLine().x); + writer->writeDouble(24, dd->getSecondLine().y); + writer->writeDouble(34, dd->getSecondLine().z); + break; + } + default: + break; } - } else { - //RLZ: todo not supported by acad 12 saved as unnamed block + } + else + { + // RLZ: todo not supported by acad 12 saved as unnamed block } return true; } @@ -1279,10 +1461,12 @@ auto dxfRW::writeInsert(DRW_Insert *ent) -> bool { writer->writeString(0, "INSERT"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbBlockReference"); writer->writeUtf8String(2, ent->name); - } else + } + else writer->writeUtf8Caps(2, ent->name); writer->writeDouble(10, ent->basePoint.x); writer->writeDouble(20, ent->basePoint.y); @@ -1290,7 +1474,7 @@ auto dxfRW::writeInsert(DRW_Insert *ent) -> bool writer->writeDouble(41, ent->xscale); writer->writeDouble(42, ent->yscale); writer->writeDouble(43, ent->zscale); - writer->writeDouble(50, (ent->angle)*ARAD); //in dxf angle is writed in degrees + writer->writeDouble(50, (ent->angle) * ARAD); // in dxf angle is writed in degrees writer->writeInt16(70, ent->colcount); writer->writeInt16(71, ent->rowcount); writer->writeDouble(44, ent->colspace); @@ -1302,10 +1486,11 @@ auto dxfRW::writeText(DRW_Text *ent) -> bool { writer->writeString(0, "TEXT"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbText"); } -// writer->writeDouble(39, ent->thickness); + // writer->writeDouble(39, ent->thickness); writer->writeDouble(10, ent->basePoint.x); writer->writeDouble(20, ent->basePoint.y); writer->writeDouble(30, ent->basePoint.z); @@ -1319,10 +1504,12 @@ auto dxfRW::writeText(DRW_Text *ent) -> bool else writer->writeUtf8Caps(7, ent->style); writer->writeInt16(71, ent->textgen); - if (ent->alignH != DRW_Text::HLeft) { + if (ent->alignH != DRW_Text::HLeft) + { writer->writeInt16(72, ent->alignH); } - if (ent->alignH != DRW_Text::HLeft || ent->alignV != DRW_Text::VBaseLine) { + if (ent->alignH != DRW_Text::HLeft || ent->alignV != DRW_Text::VBaseLine) + { writer->writeDouble(11, ent->secPoint.x); writer->writeDouble(21, ent->secPoint.y); writer->writeDouble(31, ent->secPoint.z); @@ -1330,10 +1517,12 @@ auto dxfRW::writeText(DRW_Text *ent) -> bool writer->writeDouble(210, ent->extPoint.x); writer->writeDouble(220, ent->extPoint.y); writer->writeDouble(230, ent->extPoint.z); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbText"); } - if (ent->alignV != DRW_Text::VBaseLine) { + if (ent->alignV != DRW_Text::VBaseLine) + { writer->writeInt16(73, ent->alignV); } return true; @@ -1341,7 +1530,8 @@ auto dxfRW::writeText(DRW_Text *ent) -> bool auto dxfRW::writeMText(DRW_MText *ent) -> bool { - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(0, "MTEXT"); writeEntity(ent); writer->writeString(100, "AcDbMText"); @@ -1355,9 +1545,10 @@ auto dxfRW::writeMText(DRW_MText *ent) -> bool std::string text = writer->fromUtf8String(ent->text); int i; - for(i =0; (text.size()-static_cast(i)) > 250; ) { + for (i = 0; (text.size() - static_cast(i)) > 250;) + { writer->writeString(3, text.substr(static_cast(i), 250)); - i +=250; + i += 250; } writer->writeString(1, text.substr(static_cast(i))); writer->writeString(7, ent->style); @@ -1367,9 +1558,11 @@ auto dxfRW::writeMText(DRW_MText *ent) -> bool writer->writeDouble(50, ent->angle); writer->writeInt16(73, ent->alignV); writer->writeDouble(44, ent->interlin); -//RLZ ... 11, 21, 31 needed? - } else { - //RLZ: TODO convert mtext in text lines (not exist in acad 12) + // RLZ ... 11, 21, 31 needed? + } + else + { + // RLZ: TODO convert mtext in text lines (not exist in acad 12) } return true; } @@ -1378,7 +1571,8 @@ auto dxfRW::writeViewport(DRW_Viewport *ent) -> bool { writer->writeString(0, "VIEWPORT"); writeEntity(ent); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbViewport"); } writer->writeDouble(10, ent->basePoint.x); @@ -1389,23 +1583,27 @@ auto dxfRW::writeViewport(DRW_Viewport *ent) -> bool writer->writeDouble(41, ent->psheight); writer->writeInt16(68, ent->vpstatus); writer->writeInt16(69, ent->vpID); - writer->writeDouble(12, ent->centerPX);//RLZ: verify if exist in V12 - writer->writeDouble(22, ent->centerPY);//RLZ: verify if exist in V12 + writer->writeDouble(12, ent->centerPX); // RLZ: verify if exist in V12 + writer->writeDouble(22, ent->centerPY); // RLZ: verify if exist in V12 return true; } auto dxfRW::writeImage(DRW_Image *ent, const std::string &name) -> DRW_ImageDef * { - if (version > DRW::AC1009) { - //search if exist imagedef with this mane (image inserted more than 1 time) - //RLZ: imagedef_reactor seem needed to read in acad + if (version > DRW::AC1009) + { + // search if exist imagedef with this mane (image inserted more than 1 time) + // RLZ: imagedef_reactor seem needed to read in acad DRW_ImageDef *id = NULL; - for (unsigned int i=0; iname == name ) { + for (unsigned int i = 0; i < imageDef.size(); i++) + { + if (imageDef.at(i)->name == name) + { id = imageDef.at(i); } } - if (id == NULL) { + if (id == NULL) + { id = new DRW_ImageDef(); imageDef.push_back(id); id->handle = static_cast(++entCount); @@ -1437,24 +1635,27 @@ auto dxfRW::writeImage(DRW_Image *ent, const std::string &name) -> DRW_ImageDef id->reactors[idReactor] = toHexStr(static_cast(ent->handle)); return id; } - return NULL; //not exist in acad 12 + return NULL; // not exist in acad 12 } auto dxfRW::writeBlockRecord(std::string name) -> bool { - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(0, "BLOCK_RECORD"); writer->writeString(5, toHexStr(++entCount)); blockMap[name] = entCount; - entCount = 2+entCount;//reserve 2 for BLOCK & ENDBLOCK - if (version > DRW::AC1014) { + entCount = 2 + entCount; // reserve 2 for BLOCK & ENDBLOCK + if (version > DRW::AC1014) + { writer->writeString(330, "1"); } writer->writeString(100, "AcDbSymbolTableRecord"); writer->writeString(100, "AcDbBlockTableRecord"); writer->writeUtf8String(2, name); - if (version > DRW::AC1018) { + if (version > DRW::AC1018) + { // writer->writeInt16(340, 22); writer->writeInt16(70, 0); writer->writeInt16(280, 1); @@ -1466,40 +1667,49 @@ auto dxfRW::writeBlockRecord(std::string name) -> bool auto dxfRW::writeBlock(DRW_Block *bk) -> bool { - if (writingBlock) { + if (writingBlock) + { writer->writeString(0, "ENDBLK"); - if (version > DRW::AC1009) { - writer->writeString(5, toHexStr(currHandle+2)); - if (version > DRW::AC1014) { + if (version > DRW::AC1009) + { + writer->writeString(5, toHexStr(currHandle + 2)); + if (version > DRW::AC1014) + { writer->writeString(330, toHexStr(currHandle)); } writer->writeString(100, "AcDbEntity"); } writer->writeString(8, bk->layer); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbBlockEnd"); } } writingBlock = true; writer->writeString(0, "BLOCK"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { currHandle = (*(blockMap.find(bk->name))).second; - writer->writeString(5, toHexStr(currHandle+1)); - if (version > DRW::AC1014) { + writer->writeString(5, toHexStr(currHandle + 1)); + if (version > DRW::AC1014) + { writer->writeString(330, toHexStr(currHandle)); } writer->writeString(100, "AcDbEntity"); } writer->writeString(8, bk->layer); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(100, "AcDbBlockBegin"); writer->writeUtf8String(2, bk->name); - } else + } + else writer->writeUtf8Caps(2, bk->name); writer->writeInt16(70, bk->flags); writer->writeDouble(10, bk->basePoint.x); writer->writeDouble(20, bk->basePoint.y); - if (not qFuzzyIsNull(bk->basePoint.z)) { + if (not qFuzzyIsNull(bk->basePoint.z)) + { writer->writeDouble(30, bk->basePoint.z); } if (version > DRW::AC1009) @@ -1515,45 +1725,53 @@ auto dxfRW::writeTables() -> bool { writer->writeString(0, "TABLE"); writer->writeString(2, "VPORT"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "8"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "0"); } writer->writeString(100, "AcDbSymbolTable"); } - writer->writeInt16(70, 1); //end table def -/*** VPORT ***/ - dimstyleStd =false; + writer->writeInt16(70, 1); // end table def + /*** VPORT ***/ + dimstyleStd = false; iface->writeVports(); - if (!dimstyleStd) { + if (!dimstyleStd) + { DRW_Vport portact; portact.name = "*ACTIVE"; writeVport(&portact); } writer->writeString(0, "ENDTAB"); -/*** LTYPE ***/ + /*** LTYPE ***/ writer->writeString(0, "TABLE"); writer->writeString(2, "LTYPE"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "5"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "0"); } writer->writeString(100, "AcDbSymbolTable"); } - writer->writeInt16(70, 4); //end table def -//Mandatory linetypes + writer->writeInt16(70, 4); // end table def + // Mandatory linetypes writer->writeString(0, "LTYPE"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "14"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "5"); } writer->writeString(100, "AcDbSymbolTableRecord"); writer->writeString(100, "AcDbLinetypeTableRecord"); writer->writeString(2, "ByBlock"); - } else + } + else writer->writeString(2, "BYBLOCK"); writer->writeInt16(70, 0); writer->writeString(3, ""); @@ -1562,15 +1780,18 @@ auto dxfRW::writeTables() -> bool writer->writeDouble(40, 0.0); writer->writeString(0, "LTYPE"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "15"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "5"); } writer->writeString(100, "AcDbSymbolTableRecord"); writer->writeString(100, "AcDbLinetypeTableRecord"); writer->writeString(2, "ByLayer"); - } else + } + else writer->writeString(2, "BYLAYER"); writer->writeInt16(70, 0); writer->writeString(3, ""); @@ -1579,15 +1800,19 @@ auto dxfRW::writeTables() -> bool writer->writeDouble(40, 0.0); writer->writeString(0, "LTYPE"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "16"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "5"); } writer->writeString(100, "AcDbSymbolTableRecord"); writer->writeString(100, "AcDbLinetypeTableRecord"); writer->writeString(2, "Continuous"); - } else { + } + else + { writer->writeString(2, "CONTINUOUS"); } writer->writeInt16(70, 0); @@ -1595,42 +1820,48 @@ auto dxfRW::writeTables() -> bool writer->writeInt16(72, 65); writer->writeInt16(73, 0); writer->writeDouble(40, 0.0); -//Application linetypes + // Application linetypes iface->writeLTypes(); writer->writeString(0, "ENDTAB"); -/*** LAYER ***/ + /*** LAYER ***/ writer->writeString(0, "TABLE"); writer->writeString(2, "LAYER"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "2"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "0"); } writer->writeString(100, "AcDbSymbolTable"); } - writer->writeInt16(70, 1); //end table def - wlayer0 =false; + writer->writeInt16(70, 1); // end table def + wlayer0 = false; iface->writeLayers(); - if (!wlayer0 && version > DRW::AC1009) { + if (!wlayer0 && version > DRW::AC1009) + { DRW_Layer lay0; lay0.name = '0'; writeLayer(&lay0); } writer->writeString(0, "ENDTAB"); -/*** STYLE ***/ + /*** STYLE ***/ writer->writeString(0, "TABLE"); writer->writeString(2, "STYLE"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "3"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "0"); } writer->writeString(100, "AcDbSymbolTable"); } - writer->writeInt16(70, 3); //end table def - dimstyleStd =false; + writer->writeInt16(70, 3); // end table def + dimstyleStd = false; iface->writeTextstyles(); - if (!dimstyleStd) { + if (!dimstyleStd) + { DRW_Textstyle tsty; tsty.name = "Standard"; writeTextstyle(&tsty); @@ -1639,42 +1870,50 @@ auto dxfRW::writeTables() -> bool writer->writeString(0, "TABLE"); writer->writeString(2, "VIEW"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "6"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "0"); } writer->writeString(100, "AcDbSymbolTable"); } - writer->writeInt16(70, 0); //end table def + writer->writeInt16(70, 0); // end table def writer->writeString(0, "ENDTAB"); writer->writeString(0, "TABLE"); writer->writeString(2, "UCS"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "7"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "0"); } writer->writeString(100, "AcDbSymbolTable"); } - writer->writeInt16(70, 0); //end table def + writer->writeInt16(70, 0); // end table def writer->writeString(0, "ENDTAB"); writer->writeString(0, "TABLE"); writer->writeString(2, "APPID"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "9"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "0"); } writer->writeString(100, "AcDbSymbolTable"); } - writer->writeInt16(70, 1); //end table def + writer->writeInt16(70, 1); // end table def writer->writeString(0, "APPID"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "12"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "9"); } writer->writeString(100, "AcDbSymbolTableRecord"); @@ -1687,45 +1926,53 @@ auto dxfRW::writeTables() -> bool writer->writeString(0, "TABLE"); writer->writeString(2, "DIMSTYLE"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(5, "A"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "0"); } writer->writeString(100, "AcDbSymbolTable"); } - writer->writeInt16(70, 1); //end table def - if (version > DRW::AC1014) { + writer->writeInt16(70, 1); // end table def + if (version > DRW::AC1014) + { writer->writeString(100, "AcDbDimStyleTable"); - writer->writeInt16(71, 1); //end table def + writer->writeInt16(71, 1); // end table def } - dimstyleStd =false; + dimstyleStd = false; iface->writeDimstyles(); - if (!dimstyleStd) { + if (!dimstyleStd) + { DRW_Dimstyle dsty; dsty.name = "Standard"; writeDimstyle(&dsty); } writer->writeString(0, "ENDTAB"); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(0, "TABLE"); writer->writeString(2, "BLOCK_RECORD"); writer->writeString(5, "1"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "0"); } writer->writeString(100, "AcDbSymbolTable"); - writer->writeInt16(70, 2); //end table def + writer->writeInt16(70, 2); // end table def writer->writeString(0, "BLOCK_RECORD"); writer->writeString(5, "1F"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "1"); } writer->writeString(100, "AcDbSymbolTableRecord"); writer->writeString(100, "AcDbBlockTableRecord"); writer->writeString(2, "*Model_Space"); - if (version > DRW::AC1018) { + if (version > DRW::AC1018) + { // writer->writeInt16(340, 22); writer->writeInt16(70, 0); writer->writeInt16(280, 1); @@ -1733,13 +1980,15 @@ auto dxfRW::writeTables() -> bool } writer->writeString(0, "BLOCK_RECORD"); writer->writeString(5, "1E"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "1"); } writer->writeString(100, "AcDbSymbolTableRecord"); writer->writeString(100, "AcDbBlockTableRecord"); writer->writeString(2, "*Paper_Space"); - if (version > DRW::AC1018) { + if (version > DRW::AC1018) + { // writer->writeInt16(340, 22); writer->writeInt16(70, 0); writer->writeInt16(280, 1); @@ -1748,10 +1997,11 @@ auto dxfRW::writeTables() -> bool } /* always call writeBlockRecords to iface for prepare unnamed blocks */ iface->writeBlockRecords(); - if (version > DRW::AC1009) { + if (version > DRW::AC1009) + { writer->writeString(0, "ENDTAB"); } -return true; + return true; } auto dxfRW::writeBlocks() -> bool @@ -1864,8 +2114,8 @@ auto dxfRW::writeBlocks() -> bool writer->writeString(0, "ENDBLK"); if (version > DRW::AC1009) { - writer->writeString(5, toHexStr(currHandle+2)); -// writer->writeString(5, "1D"); + writer->writeString(5, toHexStr(currHandle + 2)); + // writer->writeString(5, "1D"); if (version > DRW::AC1014) { writer->writeString(330, toHexStr(currHandle)); @@ -1886,14 +2136,16 @@ auto dxfRW::writeObjects() -> bool writer->writeString(0, "DICTIONARY"); std::string imgDictH; writer->writeString(5, "C"); - if (version > DRW::AC1014) { + if (version > DRW::AC1014) + { writer->writeString(330, "0"); } writer->writeString(100, "AcDbDictionary"); writer->writeInt16(281, 1); writer->writeString(3, "ACAD_GROUP"); writer->writeString(350, "D"); - if (imageDef.size() != 0) { + if (imageDef.size() != 0) + { writer->writeString(3, "ACAD_IMAGE_DICT"); imgDictH = toHexStr(++entCount); writer->writeString(350, imgDictH); @@ -1903,47 +2155,54 @@ auto dxfRW::writeObjects() -> bool writer->writeString(330, "C"); writer->writeString(100, "AcDbDictionary"); writer->writeInt16(281, 1); -//write IMAGEDEF_REACTOR - for (unsigned int i=0; ireactors.begin() ; it != id->reactors.end(); ++it ) { + for (auto it = id->reactors.begin(); it != id->reactors.end(); ++it) + { writer->writeString(0, "IMAGEDEF_REACTOR"); writer->writeString(5, (*it).first); writer->writeString(330, (*it).second); writer->writeString(100, "AcDbRasterImageDefReactor"); - writer->writeInt16(90, 2); //version 2=R14 to v2010 + writer->writeInt16(90, 2); // version 2=R14 to v2010 writer->writeString(330, (*it).second); } } - if (imageDef.size() != 0) { + if (imageDef.size() != 0) + { writer->writeString(0, "DICTIONARY"); writer->writeString(5, imgDictH); writer->writeString(330, "C"); writer->writeString(100, "AcDbDictionary"); writer->writeInt16(281, 1); - for (unsigned int i=0; iname.find_last_of("/\\"); - f2 =imageDef.at(i)->name.find_last_of('.'); + f2 = imageDef.at(i)->name.find_last_of('.'); ++f1; - writer->writeString(3, imageDef.at(i)->name.substr(f1,f2-f1)); - writer->writeString(350, toHexStr(static_cast(imageDef.at(i)->handle)) ); + writer->writeString(3, imageDef.at(i)->name.substr(f1, f2 - f1)); + writer->writeString(350, toHexStr(static_cast(imageDef.at(i)->handle))); } } - for (unsigned int i=0; iwriteString(0, "IMAGEDEF"); - writer->writeString(5, toHexStr(static_cast(id->handle)) ); - if (version > DRW::AC1014) { -// writer->writeString(330, '0'); handle to DICTIONARY + writer->writeString(5, toHexStr(static_cast(id->handle))); + if (version > DRW::AC1014) + { + // writer->writeString(330, '0'); handle to DICTIONARY } writer->writeString(102, "{ACAD_REACTORS"); - for (auto it=id->reactors.begin() ; it != id->reactors.end(); ++it ) { + for (auto it = id->reactors.begin(); it != id->reactors.end(); ++it) + { writer->writeString(330, (*it).first); } writer->writeString(102, "}"); writer->writeString(100, "AcDbRasterImageDef"); - writer->writeInt16(90, 0); //version 0=R14 to v2010 + writer->writeInt16(90, 0); // version 0=R14 to v2010 writer->writeUtf8String(1, id->fileName); writer->writeDouble(10, id->u); writer->writeDouble(20, id->v); @@ -1952,9 +2211,10 @@ auto dxfRW::writeObjects() -> bool writer->writeInt16(280, id->loaded); writer->writeInt16(281, id->resolution); } - //no more needed imageDef, delete it - while (!imageDef.empty()) { - imageDef.pop_back(); + // no more needed imageDef, delete it + while (!imageDef.empty()) + { + imageDef.pop_back(); } iface->writeObjects(); @@ -1964,45 +2224,50 @@ auto dxfRW::writeObjects() -> bool auto dxfRW::writeExtData(const std::vector &ed) -> bool { - for (std::vector::const_iterator it=ed.begin(); it!=ed.end(); ++it){ - switch ((*it)->code) { - case 1000: - case 1001: - case 1002: - case 1003: - case 1004: - case 1005: - {int cc = (*it)->code; - if ((*it)->type == DRW_Variant::STRING) - writer->writeUtf8String(cc, *(*it)->content.s); -// writer->writeUtf8String((*it)->code, (*it)->content.s); - break;} - case 1010: - case 1011: - case 1012: - case 1013: - if ((*it)->type == DRW_Variant::COORD) { - writer->writeDouble((*it)->code, (*it)->content.v->x); - writer->writeDouble((*it)->code+10 , (*it)->content.v->y); - writer->writeDouble((*it)->code+20 , (*it)->content.v->z); + for (std::vector::const_iterator it = ed.begin(); it != ed.end(); ++it) + { + switch ((*it)->code) + { + case 1000: + case 1001: + case 1002: + case 1003: + case 1004: + case 1005: + { + int cc = (*it)->code; + if ((*it)->type == DRW_Variant::STRING) + writer->writeUtf8String(cc, *(*it)->content.s); + // writer->writeUtf8String((*it)->code, (*it)->content.s); + break; } - break; - case 1040: - case 1041: - case 1042: - if ((*it)->type == DRW_Variant::DOUBLE) - writer->writeDouble((*it)->code, (*it)->content.d); - break; - case 1070: - if ((*it)->type == DRW_Variant::INTEGER) - writer->writeInt16((*it)->code, (*it)->content.i); - break; - case 1071: - if ((*it)->type == DRW_Variant::INTEGER) - writer->writeInt32((*it)->code, (*it)->content.i); - break; - default: - break; + case 1010: + case 1011: + case 1012: + case 1013: + if ((*it)->type == DRW_Variant::COORD) + { + writer->writeDouble((*it)->code, (*it)->content.v->x); + writer->writeDouble((*it)->code + 10, (*it)->content.v->y); + writer->writeDouble((*it)->code + 20, (*it)->content.v->z); + } + break; + case 1040: + case 1041: + case 1042: + if ((*it)->type == DRW_Variant::DOUBLE) + writer->writeDouble((*it)->code, (*it)->content.d); + break; + case 1070: + if ((*it)->type == DRW_Variant::INTEGER) + writer->writeInt16((*it)->code, (*it)->content.i); + break; + case 1071: + if ((*it)->type == DRW_Variant::INTEGER) + writer->writeInt32((*it)->code, (*it)->content.i); + break; + default: + break; } } return true; @@ -2016,72 +2281,90 @@ auto dxfRW::processDxf() -> bool int code = -1; bool inSection = false; - reader->setIgnoreComments( false); - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG(" code\n"); + reader->setIgnoreComments(false); + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG(" code\n"); /* at this level we should only get: 999 - Comment 0 - SECTION or EOF 2 - section name everything else between "2 - section name" and "0 - ENDSEC" is handled in process() methods */ - switch (code) { + switch (code) + { case 999: // when DXF was created by libdxfrw, first record is a comment with dxfrw version info - header.addComment( reader->getString()); + header.addComment(reader->getString()); continue; case 0: // ignore further comments, as libdxfrw doesn't support comments in sections - reader->setIgnoreComments( true); - if (!inSection) { - std::string sectionstr {reader->getString()}; + reader->setIgnoreComments(true); + if (!inSection) + { + std::string sectionstr{reader->getString()}; - if ("SECTION" == sectionstr) { - DRW_DBG(sectionstr); DRW_DBG(" new section\n"); + if ("SECTION" == sectionstr) + { + DRW_DBG(sectionstr); + DRW_DBG(" new section\n"); inSection = true; continue; } - if ("EOF" == sectionstr) { - return true; //found EOF terminate + if ("EOF" == sectionstr) + { + return true; // found EOF terminate } } - else { + else + { // in case SECTION was unknown or not supported - if ("ENDSEC" == reader->getString()) { + if ("ENDSEC" == reader->getString()) + { inSection = false; } } break; case 2: - if (inSection) { - bool processed {false}; - std::string sectionname {reader->getString()}; + if (inSection) + { + bool processed{false}; + std::string sectionname{reader->getString()}; - DRW_DBG(sectionname); DRW_DBG(" process section\n"); - if ("HEADER" == sectionname) { + DRW_DBG(sectionname); + DRW_DBG(" process section\n"); + if ("HEADER" == sectionname) + { processed = processHeader(); } - else if ("TABLES" == sectionname) { + else if ("TABLES" == sectionname) + { processed = processTables(); } - else if ("BLOCKS" == sectionname) { + else if ("BLOCKS" == sectionname) + { processed = processBlocks(); } - else if ("ENTITIES" == sectionname) { + else if ("ENTITIES" == sectionname) + { processed = processEntities(false); } - else if ("OBJECTS" == sectionname) { + else if ("OBJECTS" == sectionname) + { processed = processObjects(); } - else { - //TODO handle CLASSES + else + { + // TODO handle CLASSES DRW_DBG("section unknown or not supported\n"); continue; } - if (!processed) { + if (!processed) + { DRW_DBG(" failed\n"); return setError(DRW::BAD_READ_SECTION); } @@ -2095,11 +2378,12 @@ auto dxfRW::processDxf() -> bool inSection = false; break; } -/* if (!more) - return true;*/ + /* if (!more) + return true;*/ } - if (0 == code && "EOF" == reader->getString()) { + if (0 == code && "EOF" == reader->getString()) + { // in case the final EOF has no newline we end up here! // this is caused by filestr->good() which is false for missing newline on EOF return true; @@ -2115,20 +2399,26 @@ auto dxfRW::processHeader() -> bool DRW_DBG("dxfRW::processHeader\n"); int code; std::string sectionstr; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG(" processHeader\n"); - if (code == 0) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG(" processHeader\n"); + if (code == 0) + { sectionstr = reader->getString(); - DRW_DBG(sectionstr); DRW_DBG(" processHeader\n\n"); - if (sectionstr == "ENDSEC") { + DRW_DBG(sectionstr); + DRW_DBG(" processHeader\n\n"); + if (sectionstr == "ENDSEC") + { iface->addHeader(&header); - return true; //found ENDSEC terminate + return true; // found ENDSEC terminate } DRW_DBG("unexpected 0 code in header!\n"); return setError(DRW::BAD_READ_HEADER); } - if (!header.parseCode(code, reader)) { + if (!header.parseCode(code, reader)) + { return setError(DRW::BAD_CODE_PARSED); } } @@ -2144,43 +2434,71 @@ auto dxfRW::processTables() -> bool int code; std::string sectionstr; bool more = true; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (code == 0) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (code == 0) + { sectionstr = reader->getString(); - DRW_DBG(sectionstr); DRW_DBG(" processHeader\n\n"); - if (sectionstr == "TABLE") { + DRW_DBG(sectionstr); + DRW_DBG(" processHeader\n\n"); + if (sectionstr == "TABLE") + { more = reader->readRec(&code); - DRW_DBG(code); DRW_DBG("\n"); - if (!more) { - return setError(DRW::BAD_READ_TABLES); //wrong dxf file + DRW_DBG(code); + DRW_DBG("\n"); + if (!more) + { + return setError(DRW::BAD_READ_TABLES); // wrong dxf file } - if (code == 2) { + if (code == 2) + { sectionstr = reader->getString(); - DRW_DBG(sectionstr); DRW_DBG(" processHeader\n\n"); - //found section, process it - if (sectionstr == "LTYPE") { + DRW_DBG(sectionstr); + DRW_DBG(" processHeader\n\n"); + // found section, process it + if (sectionstr == "LTYPE") + { processLType(); - } else if (sectionstr == "LAYER") { + } + else if (sectionstr == "LAYER") + { processLayer(); - } else if (sectionstr == "STYLE") { + } + else if (sectionstr == "STYLE") + { processTextStyle(); - } else if (sectionstr == "VPORT") { + } + else if (sectionstr == "VPORT") + { processVports(); - } else if (sectionstr == "VIEW") { -// processView(); - } else if (sectionstr == "UCS") { -// processUCS(); - } else if (sectionstr == "APPID") { + } + else if (sectionstr == "VIEW") + { + // processView(); + } + else if (sectionstr == "UCS") + { + // processUCS(); + } + else if (sectionstr == "APPID") + { processAppId(); - } else if (sectionstr == "DIMSTYLE") { + } + else if (sectionstr == "DIMSTYLE") + { processDimStyle(); - } else if (sectionstr == "BLOCK_RECORD") { -// processBlockRecord(); + } + else if (sectionstr == "BLOCK_RECORD") + { + // processBlockRecord(); } } - } else if (sectionstr == "ENDSEC") { - return true; //found ENDSEC terminate + } + else if (sectionstr == "ENDSEC") + { + return true; // found ENDSEC terminate } } } @@ -2195,24 +2513,35 @@ auto dxfRW::processLType() -> bool std::string sectionstr; bool reading = false; DRW_LType ltype; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (code == 0) { - if (reading) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (code == 0) + { + if (reading) + { ltype.update(); iface->addLType(ltype); } sectionstr = reader->getString(); - DRW_DBG(sectionstr); DRW_DBG("\n"); - if (sectionstr == "LTYPE") { + DRW_DBG(sectionstr); + DRW_DBG("\n"); + if (sectionstr == "LTYPE") + { reading = true; ltype.reset(); - } else if (sectionstr == "ENDTAB") { - return true; //found ENDTAB terminate } - } else if (reading) { - if (!ltype.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + else if (sectionstr == "ENDTAB") + { + return true; // found ENDTAB terminate + } + } + else if (reading) + { + if (!ltype.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } } @@ -2227,22 +2556,32 @@ auto dxfRW::processLayer() -> bool std::string sectionstr; bool reading = false; DRW_Layer layer; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (code == 0) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (code == 0) + { if (reading) iface->addLayer(layer); sectionstr = reader->getString(); - DRW_DBG(sectionstr); DRW_DBG("\n"); - if (sectionstr == "LAYER") { + DRW_DBG(sectionstr); + DRW_DBG("\n"); + if (sectionstr == "LAYER") + { reading = true; layer.reset(); - } else if (sectionstr == "ENDTAB") { - return true; //found ENDTAB terminate } - } else if (reading) { - if (!layer.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + else if (sectionstr == "ENDTAB") + { + return true; // found ENDTAB terminate + } + } + else if (reading) + { + if (!layer.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } } @@ -2257,21 +2596,31 @@ auto dxfRW::processDimStyle() -> bool std::string sectionstr; bool reading = false; DRW_Dimstyle dimSty; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (code == 0) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (code == 0) + { if (reading) iface->addDimStyle(dimSty); sectionstr = reader->getString(); - DRW_DBG(sectionstr); DRW_DBG("\n"); - if (sectionstr == "DIMSTYLE") { + DRW_DBG(sectionstr); + DRW_DBG("\n"); + if (sectionstr == "DIMSTYLE") + { reading = true; dimSty.reset(); - } else if (sectionstr == "ENDTAB") { - return true; //found ENDTAB terminate } - } else if (reading) { - if (!dimSty.parseCode(code, reader)) { + else if (sectionstr == "ENDTAB") + { + return true; // found ENDTAB terminate + } + } + else if (reading) + { + if (!dimSty.parseCode(code, reader)) + { return setError(DRW::BAD_CODE_PARSED); } } @@ -2287,22 +2636,32 @@ auto dxfRW::processTextStyle() -> bool std::string sectionstr; bool reading = false; DRW_Textstyle TxtSty; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (code == 0) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (code == 0) + { if (reading) iface->addTextStyle(TxtSty); sectionstr = reader->getString(); - DRW_DBG(sectionstr); DRW_DBG("\n"); - if (sectionstr == "STYLE") { + DRW_DBG(sectionstr); + DRW_DBG("\n"); + if (sectionstr == "STYLE") + { reading = true; TxtSty.reset(); - } else if (sectionstr == "ENDTAB") { - return true; //found ENDTAB terminate } - } else if (reading) { - if (!TxtSty.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + else if (sectionstr == "ENDTAB") + { + return true; // found ENDTAB terminate + } + } + else if (reading) + { + if (!TxtSty.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } } @@ -2317,22 +2676,32 @@ auto dxfRW::processVports() -> bool std::string sectionstr; bool reading = false; DRW_Vport vp; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (code == 0) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (code == 0) + { if (reading) iface->addVport(vp); sectionstr = reader->getString(); - DRW_DBG(sectionstr); DRW_DBG("\n"); - if (sectionstr == "VPORT") { + DRW_DBG(sectionstr); + DRW_DBG("\n"); + if (sectionstr == "VPORT") + { reading = true; vp.reset(); - } else if (sectionstr == "ENDTAB") { - return true; //found ENDTAB terminate } - } else if (reading) { - if (!vp.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + else if (sectionstr == "ENDTAB") + { + return true; // found ENDTAB terminate + } + } + else if (reading) + { + if (!vp.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } } @@ -2347,21 +2716,31 @@ auto dxfRW::processAppId() -> bool std::string sectionstr; bool reading = false; DRW_AppId vp; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (code == 0) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (code == 0) + { if (reading) iface->addAppId(vp); sectionstr = reader->getString(); - DRW_DBG(sectionstr); DRW_DBG("\n"); - if (sectionstr == "APPID") { + DRW_DBG(sectionstr); + DRW_DBG("\n"); + if (sectionstr == "APPID") + { reading = true; vp.reset(); - } else if (sectionstr == "ENDTAB") { - return true; //found ENDTAB terminate } - } else if (reading) { - if (!vp.parseCode(code, reader)) { + else if (sectionstr == "ENDTAB") + { + return true; // found ENDTAB terminate + } + } + else if (reading) + { + if (!vp.parseCode(code, reader)) + { return setError(DRW::BAD_CODE_PARSED); } } @@ -2377,15 +2756,22 @@ auto dxfRW::processBlocks() -> bool DRW_DBG("dxfRW::processBlocks\n"); int code; std::string sectionstr; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (code == 0) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (code == 0) + { sectionstr = reader->getString(); - DRW_DBG(sectionstr); DRW_DBG("\n"); - if (sectionstr == "BLOCK") { + DRW_DBG(sectionstr); + DRW_DBG("\n"); + if (sectionstr == "BLOCK") + { processBlock(); - } else if (sectionstr == "ENDSEC") { - return true; //found ENDSEC terminate + } + else if (sectionstr == "ENDSEC") + { + return true; // found ENDSEC terminate } } } @@ -2398,24 +2784,32 @@ auto dxfRW::processBlock() -> bool DRW_DBG("dxfRW::processBlock"); int code; DRW_Block block; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addBlock(block); - if (nextentity == "ENDBLK") { + if (nextentity == "ENDBLK") + { iface->endBlock(); - return true; //found ENDBLK, terminate - } else { + return true; // found ENDBLK, terminate + } + else + { processEntities(true); iface->endBlock(); - return true; //found ENDBLK, terminate + return true; // found ENDBLK, terminate } } - if (!block.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!block.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2428,68 +2822,120 @@ auto dxfRW::processEntities(bool isblock) -> bool { DRW_DBG("dxfRW::processEntities\n"); int code; - if (!reader->readRec(&code)){ + if (!reader->readRec(&code)) + { return setError(DRW::BAD_READ_ENTITIES); } - if (code == 0) { + if (code == 0) + { nextentity = reader->getString(); - } else if (!isblock) { - return setError(DRW::BAD_READ_ENTITIES); //first record in entities is 0 + } + else if (!isblock) + { + return setError(DRW::BAD_READ_ENTITIES); // first record in entities is 0 } - bool processed {false}; - do { - if (nextentity == "ENDSEC" || nextentity == "ENDBLK") { - return true; //found ENDSEC or ENDBLK terminate - } else if (nextentity == "POINT") { + bool processed{false}; + do + { + if (nextentity == "ENDSEC" || nextentity == "ENDBLK") + { + return true; // found ENDSEC or ENDBLK terminate + } + else if (nextentity == "POINT") + { processed = processPoint(); - } else if (nextentity == "LINE") { + } + else if (nextentity == "LINE") + { processed = processLine(); - } else if (nextentity == "CIRCLE") { + } + else if (nextentity == "CIRCLE") + { processed = processCircle(); - } else if (nextentity == "ARC") { + } + else if (nextentity == "ARC") + { processed = processArc(); - } else if (nextentity == "ELLIPSE") { + } + else if (nextentity == "ELLIPSE") + { processed = processEllipse(); - } else if (nextentity == "TRACE") { + } + else if (nextentity == "TRACE") + { processed = processTrace(); - } else if (nextentity == "SOLID") { + } + else if (nextentity == "SOLID") + { processed = processSolid(); - } else if (nextentity == "INSERT") { + } + else if (nextentity == "INSERT") + { processed = processInsert(); - } else if (nextentity == "LWPOLYLINE") { + } + else if (nextentity == "LWPOLYLINE") + { processed = processLWPolyline(); - } else if (nextentity == "POLYLINE") { + } + else if (nextentity == "POLYLINE") + { processed = processPolyline(); - } else if (nextentity == "TEXT") { + } + else if (nextentity == "TEXT") + { processed = processText(); - } else if (nextentity == "MTEXT") { + } + else if (nextentity == "MTEXT") + { processed = processMText(); - } else if (nextentity == "HATCH") { + } + else if (nextentity == "HATCH") + { processed = processHatch(); - } else if (nextentity == "SPLINE") { + } + else if (nextentity == "SPLINE") + { processed = processSpline(); - } else if (nextentity == "3DFACE") { + } + else if (nextentity == "3DFACE") + { processed = process3dface(); - } else if (nextentity == "VIEWPORT") { + } + else if (nextentity == "VIEWPORT") + { processed = processViewport(); - } else if (nextentity == "IMAGE") { + } + else if (nextentity == "IMAGE") + { processed = processImage(); - } else if (nextentity == "DIMENSION") { + } + else if (nextentity == "DIMENSION") + { processed = processDimension(); - } else if (nextentity == "LEADER") { + } + else if (nextentity == "LEADER") + { processed = processLeader(); - } else if (nextentity == "RAY") { + } + else if (nextentity == "RAY") + { processed = processRay(); - } else if (nextentity == "XLINE") { + } + else if (nextentity == "XLINE") + { processed = processXline(); - } else { - if (!reader->readRec(&code)) { - return setError(DRW::BAD_READ_ENTITIES); //end of file without ENDSEC + } + else + { + if (!reader->readRec(&code)) + { + return setError(DRW::BAD_READ_ENTITIES); // end of file without ENDSEC } - if (code == 0) { + if (code == 0) + { nextentity = reader->getString(); } processed = true; @@ -2505,19 +2951,24 @@ auto dxfRW::processEllipse() -> bool DRW_DBG("dxfRW::processEllipse"); int code; DRW_Ellipse ellipse; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); if (applyExt) ellipse.applyExtrusion(); iface->addEllipse(ellipse); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!ellipse.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!ellipse.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2529,19 +2980,24 @@ auto dxfRW::processTrace() -> bool DRW_DBG("dxfRW::processTrace"); int code; DRW_Trace trace; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); if (applyExt) trace.applyExtrusion(); iface->addTrace(trace); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!trace.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!trace.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2553,19 +3009,24 @@ auto dxfRW::processSolid() -> bool DRW_DBG("dxfRW::processSolid"); int code; DRW_Solid solid; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); if (applyExt) solid.applyExtrusion(); iface->addSolid(solid); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!solid.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!solid.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2577,17 +3038,22 @@ auto dxfRW::process3dface() -> bool DRW_DBG("dxfRW::process3dface"); int code; DRW_3Dface face; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->add3dFace(face); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!face.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!face.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2599,17 +3065,22 @@ auto dxfRW::processViewport() -> bool DRW_DBG("dxfRW::processViewport"); int code; DRW_Viewport vp; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addViewport(vp); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!vp.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!vp.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2621,17 +3092,22 @@ auto dxfRW::processPoint() -> bool DRW_DBG("dxfRW::processPoint\n"); int code; DRW_Point point; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addPoint(point); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!point.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!point.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2643,17 +3119,22 @@ auto dxfRW::processLine() -> bool DRW_DBG("dxfRW::processLine\n"); int code; DRW_Line line; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addLine(line); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!line.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!line.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2665,17 +3146,22 @@ auto dxfRW::processRay() -> bool DRW_DBG("dxfRW::processRay\n"); int code; DRW_Ray line; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addRay(line); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!line.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!line.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2687,17 +3173,22 @@ auto dxfRW::processXline() -> bool DRW_DBG("dxfRW::processXline\n"); int code; DRW_Xline line; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addXline(line); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!line.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!line.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2709,19 +3200,24 @@ auto dxfRW::processCircle() -> bool DRW_DBG("dxfRW::processPoint\n"); int code; DRW_Circle circle; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); if (applyExt) circle.applyExtrusion(); iface->addCircle(circle); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!circle.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!circle.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2733,19 +3229,24 @@ auto dxfRW::processArc() -> bool DRW_DBG("dxfRW::processPoint\n"); int code; DRW_Arc arc; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); if (applyExt) arc.applyExtrusion(); iface->addArc(arc); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!arc.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!arc.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2757,17 +3258,22 @@ auto dxfRW::processInsert() -> bool DRW_DBG("dxfRW::processInsert"); int code; DRW_Insert insert; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addInsert(insert); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!insert.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!insert.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2779,19 +3285,24 @@ auto dxfRW::processLWPolyline() -> bool DRW_DBG("dxfRW::processLWPolyline"); int code; DRW_LWPolyline pl; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); if (applyExt) pl.applyExtrusion(); iface->addLWPolyline(pl); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!pl.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!pl.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2803,19 +3314,25 @@ auto dxfRW::processPolyline() -> bool DRW_DBG("dxfRW::processPolyline"); int code; DRW_Polyline pl; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); - if (nextentity != "VERTEX") { + DRW_DBG(nextentity); + DRW_DBG("\n"); + if (nextentity != "VERTEX") + { iface->addPolyline(pl); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } processVertex(&pl); } - if (!pl.parseCode(code, reader)) { //parseCode just initialize the members of pl + if (!pl.parseCode(code, reader)) + { // parseCode just initialize the members of pl return setError(DRW::BAD_CODE_PARSED); } } @@ -2828,22 +3345,29 @@ auto dxfRW::processVertex(DRW_Polyline *pl) -> bool DRW_DBG("dxfRW::processVertex"); int code; std::unique_ptr v(new DRW_Vertex()); - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { pl->appendVertex(v.release()); nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); - if (nextentity == "SEQEND") { - return true; //found SEQEND no more vertex, terminate + DRW_DBG(nextentity); + DRW_DBG("\n"); + if (nextentity == "SEQEND") + { + return true; // found SEQEND no more vertex, terminate } - if (nextentity == "VERTEX"){ - v.reset(new DRW_Vertex()); //another vertex + if (nextentity == "VERTEX") + { + v.reset(new DRW_Vertex()); // another vertex } } - if (!v->parseCode(code, reader)) { //the members of v are reinitialized here - return setError( DRW::BAD_CODE_PARSED); + if (!v->parseCode(code, reader)) + { // the members of v are reinitialized here + return setError(DRW::BAD_CODE_PARSED); } } @@ -2855,17 +3379,22 @@ auto dxfRW::processText() -> bool DRW_DBG("dxfRW::processText"); int code; DRW_Text txt; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addText(txt); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!txt.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!txt.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2877,18 +3406,23 @@ auto dxfRW::processMText() -> bool DRW_DBG("dxfRW::processMText"); int code; DRW_MText txt; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); txt.updateAngle(); iface->addMText(txt); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!txt.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!txt.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2900,17 +3434,22 @@ auto dxfRW::processHatch() -> bool DRW_DBG("dxfRW::processHatch"); int code; DRW_Hatch hatch; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addHatch(&hatch); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!hatch.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!hatch.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2922,17 +3461,22 @@ auto dxfRW::processSpline() -> bool DRW_DBG("dxfRW::processSpline"); int code; DRW_Spline sp; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addSpline(&sp); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!sp.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!sp.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2944,17 +3488,22 @@ auto dxfRW::processImage() -> bool DRW_DBG("dxfRW::processImage"); int code; DRW_Image img; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addImage(&img); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!img.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!img.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -2966,55 +3515,75 @@ auto dxfRW::processDimension() -> bool DRW_DBG("dxfRW::processDimension"); int code; DRW_Dimension dim; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); int type = dim.type & 0x0F; QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") - switch (type) { - case 0: { - DRW_DimLinear d(dim); - iface->addDimLinear(&d); - break; } - case 1: { - DRW_DimAligned d(dim); - iface->addDimAlign(&d); - break; } - case 2: { - DRW_DimAngular d(dim); - iface->addDimAngular(&d); - break;} - case 3: { - DRW_DimDiametric d(dim); - iface->addDimDiametric(&d); - break; } - case 4: { - DRW_DimRadial d(dim); - iface->addDimRadial(&d); - break; } - case 5: { - DRW_DimAngular3p d(dim); - iface->addDimAngular3P(&d); - break; } - case 6: { - DRW_DimOrdinate d(dim); - iface->addDimOrdinate(&d); - break; } + switch (type) + { + case 0: + { + DRW_DimLinear d(dim); + iface->addDimLinear(&d); + break; + } + case 1: + { + DRW_DimAligned d(dim); + iface->addDimAlign(&d); + break; + } + case 2: + { + DRW_DimAngular d(dim); + iface->addDimAngular(&d); + break; + } + case 3: + { + DRW_DimDiametric d(dim); + iface->addDimDiametric(&d); + break; + } + case 4: + { + DRW_DimRadial d(dim); + iface->addDimRadial(&d); + break; + } + case 5: + { + DRW_DimAngular3p d(dim); + iface->addDimAngular3P(&d); + break; + } + case 6: + { + DRW_DimOrdinate d(dim); + iface->addDimOrdinate(&d); + break; + } } // cppcheck-suppress unknownMacro QT_WARNING_POP - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!dim.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!dim.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -3026,17 +3595,22 @@ auto dxfRW::processLeader() -> bool DRW_DBG("dxfRW::processLeader"); int code; DRW_Leader leader; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addLeader(&leader); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!leader.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!leader.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -3049,35 +3623,42 @@ auto dxfRW::processObjects() -> bool { DRW_DBG("dxfRW::processObjects\n"); int code; - if (!reader->readRec(&code) || 0 != code){ - return setError(DRW::BAD_READ_OBJECTS); //first record in objects must be 0 + if (!reader->readRec(&code) || 0 != code) + { + return setError(DRW::BAD_READ_OBJECTS); // first record in objects must be 0 } bool processed = false; nextentity = reader->getString(); - do { - if ("ENDSEC" == nextentity) { - return true; //found ENDSEC terminate + do + { + if ("ENDSEC" == nextentity) + { + return true; // found ENDSEC terminate } - if ("IMAGEDEF" == nextentity) { + if ("IMAGEDEF" == nextentity) + { processed = processImageDef(); } - else if ("PLOTSETTINGS" == nextentity) { + else if ("PLOTSETTINGS" == nextentity) + { processed = processPlotSettings(); } - else { - if (!reader->readRec(&code)) { - return setError(DRW::BAD_READ_OBJECTS); //end of file without ENDSEC + else + { + if (!reader->readRec(&code)) + { + return setError(DRW::BAD_READ_OBJECTS); // end of file without ENDSEC } - if (code == 0) { + if (code == 0) + { nextentity = reader->getString(); } processed = true; } - } - while (processed); + } while (processed); return setError(DRW::BAD_READ_OBJECTS); } @@ -3087,17 +3668,22 @@ auto dxfRW::processImageDef() -> bool DRW_DBG("dxfRW::processImageDef"); int code; DRW_ImageDef img; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->linkImage(&img); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!img.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!img.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -3109,17 +3695,22 @@ auto dxfRW::processPlotSettings() -> bool DRW_DBG("dxfRW::processPlotSettings"); int code; DRW_PlotSettings ps; - while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); - if (0 == code) { + while (reader->readRec(&code)) + { + DRW_DBG(code); + DRW_DBG("\n"); + if (0 == code) + { nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); + DRW_DBG(nextentity); + DRW_DBG("\n"); iface->addPlotSettings(&ps); - return true; //found new entity or ENDSEC, terminate + return true; // found new entity or ENDSEC, terminate } - if (!ps.parseCode(code, reader)) { - return setError( DRW::BAD_CODE_PARSED); + if (!ps.parseCode(code, reader)) + { + return setError(DRW::BAD_CODE_PARSED); } } @@ -3145,8 +3736,8 @@ auto dxfRW::writePlotSettings(DRW_PlotSettings *ent) -> bool auto dxfRW::toHexStr(int n) -> std::string { #if defined(__APPLE__) - char buffer[9]= {'\0'}; - snprintf(buffer,9, "%X", n); + char buffer[9] = {'\0'}; + snprintf(buffer, 9, "%X", n); return std::string(buffer); #else std::ostringstream Convert; diff --git a/src/libs/vlayout/vabstractpiece.h b/src/libs/vlayout/vabstractpiece.h index 027967e89..380558aa3 100644 --- a/src/libs/vlayout/vabstractpiece.h +++ b/src/libs/vlayout/vabstractpiece.h @@ -29,17 +29,17 @@ #ifndef VABSTRACTPIECE_H #define VABSTRACTPIECE_H -#include -#include -#include -#include #include +#include #include +#include +#include +#include -#include "../vmisc/compatibility.h" #include "../vgeometry/vgobject.h" -#include "vsapoint.h" +#include "../vmisc/compatibility.h" #include "vrawsapoint.h" +#include "vsapoint.h" class VAbstractPieceData; class QPainterPath; @@ -48,11 +48,12 @@ class VContainer; class VRawSAPoint; class VLayoutPlaceLabel; -using PlaceLabelImg = QVector >; +using PlaceLabelImg = QVector>; class VAbstractPiece { Q_DECLARE_TR_FUNCTIONS(VAbstractPiece) // NOLINT + public: VAbstractPiece(); VAbstractPiece(const VAbstractPiece &piece); @@ -109,28 +110,27 @@ public: static auto Equidistant(QVector points, qreal width, const QString &name) -> QVector; static auto SumTrapezoids(const QVector &points) -> qreal; - template - static auto CheckLoops(QVector points) -> QVector; + template static auto CheckLoops(QVector points) -> QVector; static auto EkvPoint(QVector points, const VSAPoint &p1Line1, const VSAPoint &p2Line1, - const VSAPoint &p1Line2, const VSAPoint &p2Line2, qreal width, - bool *needRollback = nullptr) -> QVector; + const VSAPoint &p1Line2, const VSAPoint &p2Line2, qreal width, bool *needRollback = nullptr) + -> QVector; static auto ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qreal width) -> QLineF; static auto IsAllowanceValid(const QVector &base, const QVector &allowance) -> bool; template - static auto IsInsidePolygon(const QVector &path, const QVector &polygon, - qreal accuracy = accuracyPointOnLine) -> bool; + static auto IsInsidePolygon(const QVector &path, const QVector &polygon, qreal accuracy = accuracyPointOnLine) + -> bool; template static auto CorrectEquidistantPoints(const QVector &points, bool removeFirstAndLast = true) -> QVector; - static auto RollbackSeamAllowance(QVector points, const QLineF &cuttingEdge, - bool *success) -> QVector; + static auto RollbackSeamAllowance(QVector points, const QLineF &cuttingEdge, bool *success) + -> QVector; - static auto GrainlineMainLine(const VGrainlineData &geom, const VContainer *pattern, - const QRectF &boundingRect) -> QLineF; + static auto GrainlineMainLine(const VGrainlineData &geom, const VContainer *pattern, const QRectF &boundingRect) + -> QLineF; - friend auto operator<< (QDataStream& dataStream, const VAbstractPiece& piece) -> QDataStream&; - friend auto operator>> (QDataStream& dataStream, VAbstractPiece& piece) -> QDataStream&; + friend auto operator<<(QDataStream &dataStream, const VAbstractPiece &piece) -> QDataStream &; + friend auto operator>>(QDataStream &dataStream, VAbstractPiece &piece) -> QDataStream &; static auto PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLabelImg; static auto LabelShapePath(const VLayoutPlaceLabel &label) -> QPainterPath; @@ -144,19 +144,17 @@ protected: template static auto CheckPointOnLine(QVector &points, const T &iPoint, const T &prevPoint, const T &nextPoint) -> bool; - static auto IsItemContained(const QRectF &parentBoundingRect, const QVector &shape, qreal &dX, - qreal &dY) -> bool; + static auto IsItemContained(const QRectF &parentBoundingRect, const QVector &shape, qreal &dX, qreal &dY) + -> bool; static auto CorrectPosition(const QRectF &parentBoundingRect, QVector points) -> QVector; - static auto FindGrainlineGeometry(const VGrainlineData& geom, const VContainer *pattern, qreal &length, + static auto FindGrainlineGeometry(const VGrainlineData &geom, const VContainer *pattern, qreal &length, qreal &rotationAngle, QPointF &pos) -> bool; - template - static auto ComparePoints(QVector &points, const T &p1, const T &p2, qreal accuracy) -> bool; - template - static auto CompareFirstAndLastPoints(QVector &points, qreal accuracy) -> void; - template - static auto CheckLoop(const QVector &points, bool &loopFound) -> QVector; + template static auto ComparePoints(QVector &points, const T &p1, const T &p2, qreal accuracy) -> bool; + template static auto CompareFirstAndLastPoints(QVector &points, qreal accuracy) -> void; + template static auto CheckLoop(const QVector &points, bool &loopFound) -> QVector; template static auto IntersectionPoint(QPointF crosPoint, const T &l1p1, const T &l1p2, const T &l2p1, const T &l2p2) -> T; + private: QSharedDataPointer d; }; @@ -210,17 +208,17 @@ inline auto VAbstractPiece::CheckPointOnLine(QVector &points, template inline auto VAbstractPiece::CorrectEquidistantPoints(const QVector &points, bool removeFirstAndLast) -> QVector { -// DumpVector(points, QStringLiteral("input.json.XXXXXX")); // Uncomment for dumping test data - if (points.size()<4)//Better don't check if only three points. We can destroy equidistant. + // DumpVector(points, QStringLiteral("input.json.XXXXXX")); // Uncomment for dumping test data + if (points.size() < 4) // Better don't check if only three points. We can destroy equidistant. { - qDebug()<<"Only three points."; + qDebug() << "Only three points."; return points; } - //Clear equivalent points + // Clear equivalent points QVector buf1 = RemoveDublicates(points, removeFirstAndLast); - if (buf1.size()<3) + if (buf1.size() < 3) { return buf1; } @@ -229,10 +227,10 @@ inline auto VAbstractPiece::CorrectEquidistantPoints(const QVector &points, b vsizetype next = -1; QVector buf2; - //Remove point on line + // Remove point on line for (qint32 i = 0; i < buf1.size(); ++i) - {// In this case we alwayse will have bounded intersection, so all is need is to check if point is on line. - // Unfortunatelly QLineF::intersect can't be used in this case because of the floating-point accuraccy problem. + { // In this case we alwayse will have bounded intersection, so all is need is to check if point is on line. + // Unfortunatelly QLineF::intersect can't be used in this case because of the floating-point accuraccy problem. if (prev == -1) { if (i == 0) @@ -247,7 +245,7 @@ inline auto VAbstractPiece::CorrectEquidistantPoints(const QVector &points, b } else { - prev = i-1; + prev = i - 1; } } @@ -263,7 +261,7 @@ inline auto VAbstractPiece::CorrectEquidistantPoints(const QVector &points, b } else { - next = i+1; + next = i + 1; } const T &iPoint = buf1.at(i); @@ -283,7 +281,7 @@ inline auto VAbstractPiece::CorrectEquidistantPoints(const QVector &points, b buf2 = RemoveDublicates(buf2, false); -// DumpVector(buf2, QStringLiteral("output.json.XXXXXX")); // Uncomment for dumping test data + // DumpVector(buf2, QStringLiteral("output.json.XXXXXX")); // Uncomment for dumping test data return buf2; } @@ -306,11 +304,11 @@ inline auto VAbstractPiece::RemoveDublicates(const QVector &points, bool remo for (int i = 0; i < points.size(); ++i) { - for (int j = i+1; j < points.size(); ++j) + for (int j = i + 1; j < points.size(); ++j) { if (not ComparePoints(p, points.at(i), points.at(j), accuracy)) { - i = j-1; + i = j - 1; break; } } @@ -403,16 +401,15 @@ inline auto VAbstractPiece::ComparePoints(QVector &points, con } //--------------------------------------------------------------------------------------------------------------------- -template -inline auto VAbstractPiece::CompareFirstAndLastPoints(QVector &points, qreal accuracy) -> void +template inline auto VAbstractPiece::CompareFirstAndLastPoints(QVector &points, qreal accuracy) -> void { if (points.isEmpty()) { return; } - const T& first = ConstFirst(points); - const T& last = ConstLast(points); + const T &first = ConstFirst(points); + const T &last = ConstLast(points); qreal testAccuracy = accuracy; if (last.TurnPoint()) @@ -437,16 +434,15 @@ inline auto VAbstractPiece::CompareFirstAndLastPoints(QVector &points, qreal } //--------------------------------------------------------------------------------------------------------------------- -template <> -inline auto VAbstractPiece::CompareFirstAndLastPoints(QVector &points, qreal accuracy) -> void +template <> inline auto VAbstractPiece::CompareFirstAndLastPoints(QVector &points, qreal accuracy) -> void { if (points.isEmpty()) { return; } - const VRawSAPoint& first = ConstFirst(points); - const VRawSAPoint& last = ConstLast(points); + const VRawSAPoint &first = ConstFirst(points); + const VRawSAPoint &last = ConstLast(points); qreal testAccuracy = accuracy; if ((first.Primary() && last.Primary()) || last.TurnPoint()) @@ -493,7 +489,7 @@ inline auto VAbstractPiece::IsInsidePolygon(const QVector &path, const QVecto for (auto i = 0; i < path.count(); ++i) { int nextI = -1; - if (i < path.count()-1) + if (i < path.count() - 1) { nextI = i + 1; } @@ -511,7 +507,7 @@ inline auto VAbstractPiece::IsInsidePolygon(const QVector &path, const QVecto for (auto j = 0; j < polygon.count(); ++j) { int nextJ = -1; - if (j < polygon.count()-1) + if (j < polygon.count() - 1) { nextJ = j + 1; } @@ -529,13 +525,11 @@ inline auto VAbstractPiece::IsInsidePolygon(const QVector &path, const QVecto QPointF crosPoint; const auto type = Intersects(baseSegment, allowanceSegment, &crosPoint); - if (type == QLineF::BoundedIntersection - && not VFuzzyComparePoints(baseSegment.p1(), crosPoint, accuracy) - && not VFuzzyComparePoints(baseSegment.p2(), crosPoint, accuracy) - && not VGObject::IsPointOnLineviaPDP(allowanceSegment.p1(), baseSegment.p1(), baseSegment.p2(), - accuracy) - && not VGObject::IsPointOnLineviaPDP(allowanceSegment.p2(), baseSegment.p1(), baseSegment.p2(), - accuracy)) + if (type == QLineF::BoundedIntersection && not VFuzzyComparePoints(baseSegment.p1(), crosPoint, accuracy) && + not VFuzzyComparePoints(baseSegment.p2(), crosPoint, accuracy) && + not VGObject::IsPointOnLineviaPDP(allowanceSegment.p1(), baseSegment.p1(), baseSegment.p2(), + accuracy) && + not VGObject::IsPointOnLineviaPDP(allowanceSegment.p2(), baseSegment.p1(), baseSegment.p2(), accuracy)) { return false; } @@ -544,7 +538,8 @@ inline auto VAbstractPiece::IsInsidePolygon(const QVector &path, const QVecto // Just instersection edges is not enough. The base must be inside of the allowance. QPolygonF allowancePolygon(polygon); - return std::all_of(path.begin(), path.end(), [allowancePolygon](const T &point) + return std::all_of(path.begin(), path.end(), + [allowancePolygon](const T &point) { return allowancePolygon.containsPoint(point, Qt::WindingFill); }); } @@ -554,10 +549,9 @@ inline auto VAbstractPiece::IsInsidePolygon(const QVector &path, const QVecto * @param points vector of points of equidistant. * @return vector of points of equidistant. */ -template -inline auto VAbstractPiece::CheckLoops(QVector points) -> QVector +template inline auto VAbstractPiece::CheckLoops(QVector points) -> QVector { -// DumpVector(points, QStringLiteral("input.json.XXXXXX")); // Uncomment for dumping test data + // DumpVector(points, QStringLiteral("input.json.XXXXXX")); // Uncomment for dumping test data /*If we got less than 4 points no need seek loops.*/ if (points.size() < 4) @@ -578,13 +572,12 @@ inline auto VAbstractPiece::CheckLoops(QVector points) -> QVector } } -// DumpVector(ekvPoints, QStringLiteral("output.json.XXXXXX")); // Uncomment for dumping test data + // DumpVector(ekvPoints, QStringLiteral("output.json.XXXXXX")); // Uncomment for dumping test data return points; } //--------------------------------------------------------------------------------------------------------------------- -template -inline auto VAbstractPiece::CheckLoop(const QVector &points, bool &loopFound) -> QVector +template inline auto VAbstractPiece::CheckLoop(const QVector &points, bool &loopFound) -> QVector { loopFound = false; @@ -598,23 +591,28 @@ inline auto VAbstractPiece::CheckLoop(const QVector &points, bool &loopFound) { /*Last three points no need to check.*/ /*Triangle can not contain a loop*/ - if (loopFound || i > points.size()-4) + if (loopFound || i > points.size() - 4) { ekvPoints.append(points.at(i)); continue; } - enum LoopIntersectType { NoIntersection, BoundedIntersection, ParallelIntersection }; + enum LoopIntersectType + { + NoIntersection, + BoundedIntersection, + ParallelIntersection + }; QPointF crosPoint; LoopIntersectType status = NoIntersection; - const QLineF line1(points.at(i), points.at(i+1)); + const QLineF line1(points.at(i), points.at(i + 1)); const int limit = pathClosed && i == 0 ? 2 : 1; qint32 j; - for (j = i+2; j < points.size()-limit; ++j) + for (j = i + 2; j < points.size() - limit; ++j) { - QLineF line2(points.at(j), points.at(j+1)); + QLineF line2(points.at(j), points.at(j + 1)); const QLineF::IntersectType intersect = Intersects(line1, line2, &crosPoint); if (intersect == QLineF::NoIntersection) @@ -622,7 +620,7 @@ inline auto VAbstractPiece::CheckLoop(const QVector &points, bool &loopFound) // i.e. they are parallel. But parallel also mean they can be on the same line. // Method IsLineSegmentOnLineSegment will check it. if (VGObject::IsLineSegmentOnLineSegment(line1, line2)) - {// Now we really sure that segments are on the same line and have real intersections. + { // Now we really sure that segments are on the same line and have real intersections. status = ParallelIntersection; break; } @@ -636,32 +634,33 @@ inline auto VAbstractPiece::CheckLoop(const QVector &points, bool &loopFound) switch (status) { - case ParallelIntersection: - /*We have found a loop.*/ - ekvPoints.append(points.at(i)); - ekvPoints.append(points.at(j+1)); - i = j+1; // Skip a loop - loopFound = true; - break; - case BoundedIntersection: - ekvPoints.append(points.at(i)); - ekvPoints.append(IntersectionPoint(crosPoint, points.at(i), points.at(i+1), points.at(j), points.at(j+1))); - i = j; - loopFound = true; - break; - case NoIntersection: - /*We have not found loop.*/ - ekvPoints.append(points.at(i)); - break; - default: - break; + case ParallelIntersection: + /*We have found a loop.*/ + ekvPoints.append(points.at(i)); + ekvPoints.append(points.at(j + 1)); + i = j + 1; // Skip a loop + loopFound = true; + break; + case BoundedIntersection: + ekvPoints.append(points.at(i)); + ekvPoints.append( + IntersectionPoint(crosPoint, points.at(i), points.at(i + 1), points.at(j), points.at(j + 1))); + i = j; + loopFound = true; + break; + case NoIntersection: + /*We have not found loop.*/ + ekvPoints.append(points.at(i)); + break; + default: + break; } } return ekvPoints; } //--------------------------------------------------------------------------------------------------------------------- -template +template inline auto VAbstractPiece::IntersectionPoint(QPointF crosPoint, const T &l1p1, const T &l1p2, const T &l2p1, const T &l2p2) -> T { @@ -683,7 +682,7 @@ inline auto VAbstractPiece::IntersectionPoint(QPointF crosPoint, const T &l1p1, } //--------------------------------------------------------------------------------------------------------------------- -template<> +template <> inline auto VAbstractPiece::IntersectionPoint(QPointF crosPoint, const QPointF & /*unused*/, const QPointF & /*unused*/, const QPointF & /*unused*/, const QPointF & /*unused*/) -> QPointF diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index dac957350..7203a26ba 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -33,42 +33,42 @@ #include #include -#include "../vmisc/def.h" -#include "../vmisc/vmath.h" -#include "../vmisc/compatibility.h" -#include "vlayoutpiece.h" -#include "vlayoutpaper.h" #include "../ifc/exception/vexceptionterminatedposition.h" +#include "../vmisc/compatibility.h" +#include "../vmisc/def.h" +#include "vlayoutpaper.h" +#include "vlayoutpiece.h" //--------------------------------------------------------------------------------------------------------------------- VLayoutGenerator::VLayoutGenerator(QObject *parent) - : QObject(parent), - papers(), - bank(new VBank()), - paperHeight(0), - paperWidth(0), - margins(), - usePrinterFields(true), + : QObject(parent), + papers(), + bank(new VBank()), + paperHeight(0), + paperWidth(0), + margins(), + usePrinterFields(true), #ifdef Q_CC_MSVC - // See https://stackoverflow.com/questions/15750917/initializing-stdatomic-bool - stopGeneration(ATOMIC_VAR_INIT(false)), + // See https://stackoverflow.com/questions/15750917/initializing-stdatomic-bool + stopGeneration(ATOMIC_VAR_INIT(false)), #else - stopGeneration(false), + stopGeneration(false), #endif - state(LayoutErrors::NoError), - shift(0), - rotate(true), - followGrainline(false), - rotationNumber(2), - autoCropLength(false), - autoCropWidth(false), - saveLength(false), - unitePages(false), - stripOptimizationEnabled(false), - multiplier(1), - stripOptimization(false), - textAsPaths(false) -{} + state(LayoutErrors::NoError), + shift(0), + rotate(true), + followGrainline(false), + rotationNumber(2), + autoCropLength(false), + autoCropWidth(false), + saveLength(false), + unitePages(false), + stripOptimizationEnabled(false), + multiplier(1), + stripOptimization(false), + textAsPaths(false) +{ +} //--------------------------------------------------------------------------------------------------------------------- VLayoutGenerator::~VLayoutGenerator() @@ -149,10 +149,10 @@ void VLayoutGenerator::Generate(const QElapsedTimer &timer, qint64 timeout, Layo auto SetStrip = [this, b](int &side) { - if (side >= b*2) + if (side >= b * 2) { stripOptimizationEnabled = true; - side = qFloor(side / qFloor(side/b)); + side = qFloor(side / qFloor(side / b)); } }; @@ -224,7 +224,7 @@ void VLayoutGenerator::Generate(const QElapsedTimer &timer, qint64 timeout, Layo { return; } - } while(bank->LeftToArrange() > 0); + } while (bank->LeftToArrange() > 0); if (stopGeneration.load()) { @@ -329,7 +329,7 @@ auto VLayoutGenerator::GetGlobalContours() const -> QList //--------------------------------------------------------------------------------------------------------------------- auto VLayoutGenerator::GetAllDetailsItems() const -> QList> { - QList > list; + QList> list; list.reserve(papers.count()); for (const auto &paper : papers) { @@ -341,7 +341,7 @@ auto VLayoutGenerator::GetAllDetailsItems() const -> QList QVector> { - QVector > list; + QVector> list; list.reserve(papers.count()); for (const auto &paper : papers) { @@ -459,9 +459,9 @@ void VLayoutGenerator::GatherPages() { int paperHeight = qRound(rec.y() + rec.height()); - if (i != papers.size()-1) + if (i != papers.size() - 1) { - paperHeight += qRound(bank->GetLayoutWidth()*2); + paperHeight += qRound(bank->GetLayoutWidth() * 2); } if (length + paperHeight <= PageHeight()) @@ -472,7 +472,7 @@ void VLayoutGenerator::GatherPages() else { length = 0; // Start new paper - ++j;// New paper + ++j; // New paper UniteDetails(j, nDetails, length, i); length += paperHeight; } @@ -481,9 +481,9 @@ void VLayoutGenerator::GatherPages() { int paperWidth = qRound(rec.x() + rec.width()); - if (i != papers.size()-1) + if (i != papers.size() - 1) { - paperWidth += qRound(bank->GetLayoutWidth()*2); + paperWidth += qRound(bank->GetLayoutWidth() * 2); } if (length + paperWidth <= PageWidth()) @@ -494,7 +494,7 @@ void VLayoutGenerator::GatherPages() else { length = 0; // Start new paper - ++j;// New paper + ++j; // New paper UniteDetails(j, nDetails, length, i); length += paperWidth; } @@ -534,7 +534,7 @@ void VLayoutGenerator::OptimizeWidth() newDetails.reserve(details.size()); for (auto &d : details) { - IsPortrait() ? d.Translate(-rec.x()+1, 0) : d.Translate(0, -rec.y()+1); + IsPortrait() ? d.Translate(-rec.x() + 1, 0) : d.Translate(0, -rec.y() + 1); newDetails.append(d); } @@ -551,7 +551,7 @@ void VLayoutGenerator::UnitePages() } QList papersLength; - QList > nDetails; + QList> nDetails; qreal length = 0; int j = 0; // papers count @@ -570,9 +570,9 @@ void VLayoutGenerator::UnitePages() paperHeight = papers.at(i).GetHeight(); } - if (i != papers.size()-1) + if (i != papers.size() - 1) { - paperHeight = qRound(paperHeight + bank->GetLayoutWidth()*2); + paperHeight = qRound(paperHeight + bank->GetLayoutWidth() * 2); } if (length + paperHeight <= QIMAGE_MAX) @@ -584,7 +584,7 @@ void VLayoutGenerator::UnitePages() else { length = 0; // Start new paper - ++j;// New paper + ++j; // New paper UniteDetails(j, nDetails, length, i); length += paperHeight; UnitePapers(j, papersLength, length); @@ -603,9 +603,9 @@ void VLayoutGenerator::UnitePages() paperWidth = papers.at(i).GetWidth(); } - if (i != papers.size()-1) + if (i != papers.size() - 1) { - paperWidth = qRound(paperWidth + bank->GetLayoutWidth()*2); + paperWidth = qRound(paperWidth + bank->GetLayoutWidth() * 2); } if (length + paperWidth <= QIMAGE_MAX) @@ -617,7 +617,7 @@ void VLayoutGenerator::UnitePages() else { length = 0; // Start new paper - ++j;// New paper + ++j; // New paper UniteDetails(j, nDetails, length, i); length += paperWidth; UnitePapers(j, papersLength, length); @@ -629,8 +629,8 @@ void VLayoutGenerator::UnitePages() nPapers.reserve(nDetails.size()); for (int i = 0; i < nDetails.size(); ++i) { - const int height = IsPortrait() ? qRound(papersLength.at(i)+accuracyPointOnLine*4) : PageHeight(); - const int width = IsPortrait() ? PageWidth() : qRound(papersLength.at(i)+accuracyPointOnLine*4); + const int height = IsPortrait() ? qRound(papersLength.at(i) + accuracyPointOnLine * 4) : PageHeight(); + const int width = IsPortrait() ? PageWidth() : qRound(papersLength.at(i) + accuracyPointOnLine * 4); VLayoutPaper paper(height, width, bank->GetLayoutWidth()); paper.SetShift(shift); @@ -649,10 +649,10 @@ void VLayoutGenerator::UnitePages() } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutGenerator::UniteDetails(int j, QList > &nDetails, qreal length, int i) const +void VLayoutGenerator::UniteDetails(int j, QList> &nDetails, qreal length, int i) const { if ((j == 0 && nDetails.isEmpty()) || j >= nDetails.size()) - {//First or new details in paper + { // First or new details in paper nDetails.insert(j, MoveDetails(length, papers.at(i).GetDetails())); } else @@ -708,7 +708,7 @@ auto VLayoutGenerator::MasterPage() const -> VLayoutPaper return ConstFirst(papers); } - QList > nDetails; + QList> nDetails; qreal length = 0; const int j = 0; // papers count. Always 1. @@ -727,9 +727,9 @@ auto VLayoutGenerator::MasterPage() const -> VLayoutPaper paperHeight = papers.at(i).GetHeight(); } - if (i != papers.size()-1) + if (i != papers.size() - 1) { - paperHeight = qRound(paperHeight + bank->GetLayoutWidth()*2); + paperHeight = qRound(paperHeight + bank->GetLayoutWidth() * 2); } UniteDetails(j, nDetails, length, i); @@ -748,9 +748,9 @@ auto VLayoutGenerator::MasterPage() const -> VLayoutPaper paperWidth = papers.at(i).GetWidth(); } - if (i != papers.size()-1) + if (i != papers.size() - 1) { - paperWidth = qRound(paperWidth + bank->GetLayoutWidth()*2); + paperWidth = qRound(paperWidth + bank->GetLayoutWidth() * 2); } UniteDetails(j, nDetails, length, i); @@ -758,8 +758,8 @@ auto VLayoutGenerator::MasterPage() const -> VLayoutPaper } } - const int height = IsPortrait() ? qRound(length+accuracyPointOnLine*4) : PageHeight(); - const int width = IsPortrait() ? PageWidth() : qRound(length+accuracyPointOnLine*4); + const int height = IsPortrait() ? qRound(length + accuracyPointOnLine * 4) : PageHeight(); + const int width = IsPortrait() ? PageWidth() : qRound(length + accuracyPointOnLine * 4); VLayoutPaper paper(height, width, bank->GetLayoutWidth()); paper.SetShift(shift); diff --git a/src/libs/vlayout/vlayoutpoint.h b/src/libs/vlayout/vlayoutpoint.h index e42d59485..db9c83227 100644 --- a/src/libs/vlayout/vlayoutpoint.h +++ b/src/libs/vlayout/vlayoutpoint.h @@ -28,10 +28,10 @@ #ifndef VLAYOUTPOINT_H #define VLAYOUTPOINT_H -#include -#include #include +#include #include +#include #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/diagnostic.h" @@ -62,20 +62,19 @@ private: bool m_curvePoint{false}; }; -Q_DECLARE_METATYPE(VLayoutPoint) // NOLINT +Q_DECLARE_METATYPE(VLayoutPoint) // NOLINT Q_DECLARE_TYPEINFO(VLayoutPoint, Q_MOVABLE_TYPE); // NOLINT //--------------------------------------------------------------------------------------------------------------------- -template -inline auto CastTo(const QVector &points, QVector &casted) -> void +template inline auto CastTo(const QVector &points, QVector &casted) -> void { Q_UNUSED(points) Q_UNUSED(casted) } //--------------------------------------------------------------------------------------------------------------------- -//upcast -template ::value>::type* = nullptr> +// upcast +template ::value>::type * = nullptr> inline auto CastTo(const QVector &points, QVector &casted) -> void { casted.clear(); @@ -87,8 +86,8 @@ inline auto CastTo(const QVector &points, QVector &casted) -> voi } //--------------------------------------------------------------------------------------------------------------------- -//downcast -template ::value>::type* = nullptr> +// downcast +template ::value>::type * = nullptr> inline auto CastTo(const QVector &points, QVector &casted) -> void { casted.clear(); @@ -109,13 +108,15 @@ auto operator>>(QDataStream &, VLayoutPoint &) -> QDataStream &; //--------------------------------------------------------------------------------------------------------------------- Q_DECL_CONSTEXPR inline VLayoutPoint::VLayoutPoint(qreal xpos, qreal ypos) - : QPointF(xpos, ypos) -{} + : QPointF(xpos, ypos) +{ +} //--------------------------------------------------------------------------------------------------------------------- Q_DECL_CONSTEXPR inline VLayoutPoint::VLayoutPoint(QPointF p) - : QPointF(p) -{} + : QPointF(p) +{ +} //--------------------------------------------------------------------------------------------------------------------- Q_DECL_CONSTEXPR inline auto VLayoutPoint::TurnPoint() const -> bool diff --git a/src/libs/vlayout/vprintlayout.cpp b/src/libs/vlayout/vprintlayout.cpp index aaeac7acd..27b0677e8 100644 --- a/src/libs/vlayout/vprintlayout.cpp +++ b/src/libs/vlayout/vprintlayout.cpp @@ -27,31 +27,30 @@ *************************************************************************/ #include "vprintlayout.h" -#include -#include -#include -#include -#include -#include -#include #include +#include #include +#include +#include +#include +#include +#include #include #include -#include +#include #include -#include +#include +#include -#include "dialogs/dialoglayoutscale.h" +#include "../ifc/exception/vexception.h" +#include "../ifc/xml/vwatermarkconverter.h" +#include "../vformat/vwatermark.h" +#include "../vmisc/compatibility.h" #include "../vmisc/vabstractvalapplication.h" +#include "../vpropertyexplorer/checkablemessagebox.h" +#include "dialogs/dialoglayoutscale.h" #include "dialogs/vabstractlayoutdialog.h" #include "vposter.h" -#include "../vformat/vwatermark.h" -#include "../ifc/xml/vwatermarkconverter.h" -#include "../ifc/exception/vexception.h" -#include "../vmisc/vmath.h" -#include "../vpropertyexplorer/checkablemessagebox.h" -#include "../vmisc/compatibility.h" namespace { @@ -59,9 +58,7 @@ namespace auto FindPageSizeId(QSizeF size) -> QPageSize::PageSizeId { auto TestSize = [size](float width, float height) - { - return size == QSizeF(width, height) || size == QSizeF(height, width); - }; + { return size == QSizeF(width, height) || size == QSizeF(height, width); }; constexpr int A0Width = 841; constexpr int A0Height = 1189; @@ -116,15 +113,15 @@ auto FindPageSizeId(QSizeF size) -> QPageSize::PageSizeId } //--------------------------------------------------------------------------------------------------------------------- -Q_REQUIRED_RESULT auto PreparePrinter( - const QPrinterInfo &info, QPrinter::PrinterMode mode = QPrinter::ScreenResolution) -> QSharedPointer; +Q_REQUIRED_RESULT auto PreparePrinter(const QPrinterInfo &info, QPrinter::PrinterMode mode = QPrinter::ScreenResolution) + -> QSharedPointer; auto PreparePrinter(const QPrinterInfo &info, QPrinter::PrinterMode mode) -> QSharedPointer { QPrinterInfo tmpInfo = info; - if(tmpInfo.isNull() || tmpInfo.printerName().isEmpty()) + if (tmpInfo.isNull() || tmpInfo.printerName().isEmpty()) { const QStringList list = QPrinterInfo::availablePrinterNames(); - if(list.isEmpty()) + if (list.isEmpty()) { return {}; } @@ -136,12 +133,13 @@ auto PreparePrinter(const QPrinterInfo &info, QPrinter::PrinterMode mode) -> QSh printer->setResolution(static_cast(PrintDPI)); return printer; } -} // namespace +} // namespace //--------------------------------------------------------------------------------------------------------------------- VPrintLayout::VPrintLayout(QObject *parent) - : QObject(parent) -{} + : QObject(parent) +{ +} //--------------------------------------------------------------------------------------------------------------------- VPrintLayout::~VPrintLayout() @@ -161,7 +159,7 @@ void VPrintLayout::PrintOrigin() { if (not IsPagesUniform()) { - qCritical()<(PrintDPI)); @@ -235,7 +233,7 @@ void VPrintLayout::PrintLayout() } // display print dialog and if accepted print QPrinterInfo info = QPrinterInfo::printerInfo(m_layoutPrinterName); - if(info.isNull() || info.printerName().isEmpty()) + if (info.isNull() || info.printerName().isEmpty()) { info = QPrinterInfo::defaultPrinter(); } @@ -280,7 +278,7 @@ void VPrintLayout::PrintPreview() } QPrinterInfo info = QPrinterInfo::printerInfo(m_layoutPrinterName); - if(info.isNull() || info.printerName().isEmpty()) + if (info.isNull() || info.printerName().isEmpty()) { info = QPrinterInfo::defaultPrinter(); } @@ -324,7 +322,7 @@ void VPrintLayout::PrintPages(QPrinter *printer) painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(QPen(Qt::black, VAbstractApplication::VApp()->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); + painter.setBrush(QBrush(Qt::NoBrush)); vsizetype count = 0; QSharedPointer> poster; @@ -334,7 +332,7 @@ void VPrintLayout::PrintPages(QPrinter *printer) { // when isTiled, the landscape tiles have to be rotated, because the pages // stay portrait in the pdf - if(m_tiledPDFOrientation == PageOrientation::Landscape) + if (m_tiledPDFOrientation == PageOrientation::Landscape) { const int angle = -90; painter.rotate(angle); @@ -344,7 +342,7 @@ void VPrintLayout::PrintPages(QPrinter *printer) poster = QSharedPointer>(new QVector()); posterazor = QSharedPointer(new VPoster(printer)); - for (int i=0; i < m_layoutScenes.size(); ++i) + for (int i = 0; i < m_layoutScenes.size(); ++i) { auto *paper = qgraphicsitem_cast(m_layoutPapers.at(i)); if (paper != nullptr) @@ -421,8 +419,8 @@ void VPrintLayout::PrintPages(QPrinter *printer) if (m_isTiled) { // Draw tile - posterData = posterazor->Tile(paper, poster->at(index), m_layoutScenes.size(), data, - m_watermarkPath); + posterData = + posterazor->Tile(paper, poster->at(index), m_layoutScenes.size(), data, m_watermarkPath); } PreparePaper(paperIndex); @@ -431,8 +429,8 @@ void VPrintLayout::PrintPages(QPrinter *printer) QRectF source; m_isTiled ? source = poster->at(index).rect : source = paper->rect(); - m_layoutScenes.at(paperIndex)->render(&painter, VPrintLayout::SceneTargetRect(printer, source), source, - Qt::IgnoreAspectRatio); + m_layoutScenes.at(paperIndex) + ->render(&painter, VPrintLayout::SceneTargetRect(printer, source), source, Qt::IgnoreAspectRatio); if (m_isTiled) { @@ -475,12 +473,12 @@ void VPrintLayout::SetPrinterPrinterMargins(QPrinter *printer) } else { - if(m_tiledPDFOrientation == PageOrientation::Landscape) + if (m_tiledPDFOrientation == PageOrientation::Landscape) { // because when painting we have a -90rotation in landscape mode, // see function PrintPages. - printerMargins = QMarginsF(m_tiledMargins.bottom(), m_tiledMargins.left(), m_tiledMargins.top(), - m_tiledMargins.right()); + printerMargins = + QMarginsF(m_tiledMargins.bottom(), m_tiledMargins.left(), m_tiledMargins.top(), m_tiledMargins.right()); } else { @@ -500,12 +498,12 @@ void VPrintLayout::SetPrinterOutputFileName(QPrinter *printer, PrintType printTy { SCASSERT(printer != nullptr) - switch(printType) + switch (printType) { case PrintType::PrintPDF: { - const QString outputFileName = filePath.isEmpty() ? QDir::homePath() + QDir::separator() + DocName() - : filePath; + const QString outputFileName = + filePath.isEmpty() ? QDir::homePath() + QDir::separator() + DocName() : filePath; printer->setOutputFileName(outputFileName + QStringLiteral(".pdf")); #ifdef Q_OS_MAC @@ -516,7 +514,7 @@ void VPrintLayout::SetPrinterOutputFileName(QPrinter *printer, PrintType printTy break; } case PrintType::PrintNative: - printer->setOutputFileName(QString());//Disable printing to file if was enabled. + printer->setOutputFileName(QString()); // Disable printing to file if was enabled. printer->setOutputFormat(QPrinter::NativeFormat); break; case PrintType::PrintPreview: /*do nothing*/ @@ -542,13 +540,13 @@ void VPrintLayout::SetPrinterPageSize(QPrinter *printer) { if (m_isLayoutPortrait) { - height = FromPixel(paper->rect().height() + m_layoutMargins.top() + m_layoutMargins.bottom(), - Unit::Mm); + height = + FromPixel(paper->rect().height() + m_layoutMargins.top() + m_layoutMargins.bottom(), Unit::Mm); } else { - width = FromPixel(paper->rect().width() + m_layoutMargins.left() + m_layoutMargins.right(), - Unit::Mm); + width = + FromPixel(paper->rect().width() + m_layoutMargins.left() + m_layoutMargins.right(), Unit::Mm); } } } @@ -560,13 +558,13 @@ void VPrintLayout::SetPrinterPageSize(QPrinter *printer) { if (m_isLayoutPortrait) { - width = FromPixel(paper->rect().width() + m_layoutMargins.left() + m_layoutMargins.right(), - Unit::Mm); + width = + FromPixel(paper->rect().width() + m_layoutMargins.left() + m_layoutMargins.right(), Unit::Mm); } else { - height = FromPixel(paper->rect().height() + m_layoutMargins.top() + m_layoutMargins.bottom(), - Unit::Mm); + height = + FromPixel(paper->rect().height() + m_layoutMargins.top() + m_layoutMargins.bottom(), Unit::Mm); } } } @@ -619,7 +617,7 @@ void VPrintLayout::PreparePaper(vsizetype index) const m_layoutScenes.at(index)->setBackgroundBrush(brush); m_layoutShadows.at(index)->setVisible(false); const float thinPen = 0.1F; - paper->setPen(QPen(Qt::white, thinPen, Qt::NoPen));// border + paper->setPen(QPen(Qt::white, thinPen, Qt::NoPen)); // border } QTransform matrix; @@ -648,7 +646,7 @@ void VPrintLayout::RestorePaper(vsizetype index) const } QTransform matrix; - matrix.scale(1./m_xscale, 1./m_yscale); + matrix.scale(1. / m_xscale, 1. / m_yscale); QList paperDetails = m_layoutDetails.at(index); for (auto *detail : paperDetails) @@ -670,12 +668,13 @@ auto VPrintLayout::IsPagesUniform() const -> bool auto *paper = qgraphicsitem_cast(m_layoutPapers.at(0)); SCASSERT(paper != nullptr) - return std::all_of(m_layoutPapers.begin(), m_layoutPapers.end(), [paper](QGraphicsItem *paperItem) - { - auto *p = qgraphicsitem_cast(paperItem); - SCASSERT(p != nullptr) - return paper->rect() == p->rect(); - }); + return std::all_of(m_layoutPapers.begin(), m_layoutPapers.end(), + [paper](QGraphicsItem *paperItem) + { + auto *p = qgraphicsitem_cast(paperItem); + SCASSERT(p != nullptr) + return paper->rect() == p->rect(); + }); } //--------------------------------------------------------------------------------------------------------------------- @@ -711,8 +710,9 @@ auto VPrintLayout::WatermarkData() const -> VWatermarkData catch (VException &e) { const QString errorMsg = tr("File error.\n\n%1\n\n%2").arg(e.ErrorMessage(), e.DetailedInformation()); - VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + VAbstractApplication::VApp()->IsPedantic() + ? throw VException(errorMsg) + : qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; } } @@ -730,10 +730,10 @@ auto VPrintLayout::ContinueIfLayoutStale(QWidget *parent) -> int } Utils::CheckableMessageBox msgBox(parent); - msgBox.setIconPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion).pixmap(32, 32) ); + msgBox.setIconPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion).pixmap(32, 32)); msgBox.setWindowTitle(tr("The layout is stale.")); msgBox.setText(tr("The layout was not updated since last pattern modification. Do you want to continue?")); - msgBox.setStandardButtons(QDialogButtonBox::Yes|QDialogButtonBox::No); + msgBox.setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No); msgBox.setDefaultButton(QDialogButtonBox::No); int dialogResult = msgBox.exec(); @@ -756,7 +756,7 @@ auto VPrintLayout::SceneTargetRect(QPrinter *printer, const QRectF &source) -> Q qreal x; qreal y; - if(printer->fullPage()) + if (printer->fullPage()) { QPageLayout layout = printer->pageLayout(); layout.setUnits(QPageLayout::Millimeter); @@ -766,7 +766,8 @@ auto VPrintLayout::SceneTargetRect(QPrinter *printer, const QRectF &source) -> Q } else { - x = 0; y = 0; + x = 0; + y = 0; } QPair scaleDiff = PrinterScaleDiff(printer); diff --git a/src/libs/vlayout/vrawsapoint.h b/src/libs/vlayout/vrawsapoint.h index 0d6c024a0..9b0614d7a 100644 --- a/src/libs/vlayout/vrawsapoint.h +++ b/src/libs/vlayout/vrawsapoint.h @@ -64,27 +64,30 @@ private: bool m_primary{false}; }; -Q_DECLARE_METATYPE(VRawSAPoint) // NOLINT +Q_DECLARE_METATYPE(VRawSAPoint) // NOLINT Q_DECLARE_TYPEINFO(VRawSAPoint, Q_MOVABLE_TYPE); // NOLINT //--------------------------------------------------------------------------------------------------------------------- Q_DECL_CONSTEXPR inline VRawSAPoint::VRawSAPoint(qreal xpos, qreal ypos) - : VLayoutPoint(xpos, ypos) -{} + : VLayoutPoint(xpos, ypos) +{ +} //--------------------------------------------------------------------------------------------------------------------- Q_DECL_CONSTEXPR inline VRawSAPoint::VRawSAPoint(QPointF p) - : VLayoutPoint(p) -{} + : VLayoutPoint(p) +{ +} //--------------------------------------------------------------------------------------------------------------------- Q_DECL_CONSTEXPR inline VRawSAPoint::VRawSAPoint(const VLayoutPoint &p) - : VLayoutPoint(p) -{} + : VLayoutPoint(p) +{ +} //--------------------------------------------------------------------------------------------------------------------- Q_DECL_RELAXED_CONSTEXPR inline VRawSAPoint::VRawSAPoint(QPointF p, bool curvePoint, bool turnPoint) - : VLayoutPoint(p) + : VLayoutPoint(p) { SetCurvePoint(curvePoint); SetTurnPoint(turnPoint); @@ -92,8 +95,8 @@ Q_DECL_RELAXED_CONSTEXPR inline VRawSAPoint::VRawSAPoint(QPointF p, bool curvePo //--------------------------------------------------------------------------------------------------------------------- Q_DECL_RELAXED_CONSTEXPR inline VRawSAPoint::VRawSAPoint(QPointF p, bool curvePoint, bool turnPoint, bool loopPoint) - : VLayoutPoint(p), - m_loopPoint(loopPoint) + : VLayoutPoint(p), + m_loopPoint(loopPoint) { SetCurvePoint(curvePoint); SetTurnPoint(turnPoint); diff --git a/src/libs/vlayout/vsapoint.h b/src/libs/vlayout/vsapoint.h index 9ef9e108f..2a11ada18 100644 --- a/src/libs/vlayout/vsapoint.h +++ b/src/libs/vlayout/vsapoint.h @@ -28,15 +28,16 @@ #ifndef VSAPOINT_H #define VSAPOINT_H -#include #include +#include + +#include "../vgeometry/vgeometrydef.h" +#include "../vmisc/def.h" +#include "vlayoutpoint.h" #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/diagnostic.h" #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) -#include "../vmisc/def.h" -#include "../vgeometry/vgeometrydef.h" -#include "vlayoutpoint.h" QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Weffc++") @@ -99,7 +100,7 @@ public: static constexpr qreal passmarkFactor{0.5}; static constexpr qreal maxPassmarkLength{MmToPixel(10.)}; - static constexpr qreal minSAWidth{accuracyPointOnLine + accuracyPointOnLine*0.5}; + static constexpr qreal minSAWidth{accuracyPointOnLine + accuracyPointOnLine * 0.5}; private: qreal m_before{-1}; @@ -114,23 +115,26 @@ private: bool m_passmarkClockwiseOpening{false}; }; -Q_DECLARE_METATYPE(VSAPoint) // NOLINT +Q_DECLARE_METATYPE(VSAPoint) // NOLINT Q_DECLARE_TYPEINFO(VSAPoint, Q_MOVABLE_TYPE); // NOLINT //--------------------------------------------------------------------------------------------------------------------- Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(qreal xpos, qreal ypos) - : VLayoutPoint(xpos, ypos) -{} + : VLayoutPoint(xpos, ypos) +{ +} //--------------------------------------------------------------------------------------------------------------------- Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(QPointF p) - : VLayoutPoint(p) -{} + : VLayoutPoint(p) +{ +} //--------------------------------------------------------------------------------------------------------------------- Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(const VLayoutPoint &p) - : VLayoutPoint(p) -{} + : VLayoutPoint(p) +{ +} //--------------------------------------------------------------------------------------------------------------------- Q_DECL_CONSTEXPR inline auto VSAPoint::GetSABefore() const -> qreal diff --git a/src/libs/vmisc/backport/qoverload.h b/src/libs/vmisc/backport/qoverload.h index 6731a6e80..77156d9d5 100644 --- a/src/libs/vmisc/backport/qoverload.h +++ b/src/libs/vmisc/backport/qoverload.h @@ -40,45 +40,48 @@ QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Weffc++") -template -struct QNonConstOverload +template struct QNonConstOverload { template Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...)) const noexcept -> decltype(ptr) - { return ptr; } + { + return ptr; + } - template - static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...)) noexcept -> decltype(ptr) - { return ptr; } + template static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...)) noexcept -> decltype(ptr) + { + return ptr; + } }; -template -struct QConstOverload +template struct QConstOverload { template Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...) const) const noexcept -> decltype(ptr) - { return ptr; } + { + return ptr; + } template static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...) const) noexcept -> decltype(ptr) - { return ptr; } + { + return ptr; + } }; -template -struct QOverload : QConstOverload, QNonConstOverload +template struct QOverload : QConstOverload, QNonConstOverload { using QConstOverload::of; using QConstOverload::operator(); using QNonConstOverload::of; using QNonConstOverload::operator(); - template - Q_DECL_CONSTEXPR auto operator()(R (*ptr)(Args...)) const noexcept -> decltype(ptr) - { return ptr; } + template Q_DECL_CONSTEXPR auto operator()(R (*ptr)(Args...)) const noexcept -> decltype(ptr) + { + return ptr; + } - template - static Q_DECL_CONSTEXPR auto of(R (*ptr)(Args...)) noexcept -> decltype(ptr) - { return ptr; } + template static Q_DECL_CONSTEXPR auto of(R (*ptr)(Args...)) noexcept -> decltype(ptr) { return ptr; } }; #if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304 // C++14 diff --git a/src/libs/vmisc/backport/text.h b/src/libs/vmisc/backport/text.h index 1a5d08aca..5d34659a2 100644 --- a/src/libs/vmisc/backport/text.h +++ b/src/libs/vmisc/backport/text.h @@ -43,13 +43,13 @@ QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wunused-variable") QT_WARNING_DISABLE_CLANG("-Wunused-variable") -static auto endl Q_DECL_UNUSED = ::endl; // NOLINT -static auto flush Q_DECL_UNUSED = ::flush; // NOLINT -static auto dec Q_DECL_UNUSED = ::dec; // NOLINT +static auto endl Q_DECL_UNUSED = ::endl; // NOLINT +static auto flush Q_DECL_UNUSED = ::flush; // NOLINT +static auto dec Q_DECL_UNUSED = ::dec; // NOLINT static auto SkipEmptyParts Q_DECL_UNUSED = QString::SkipEmptyParts; // NOLINT QT_WARNING_POP -} // namespace Qt +} // namespace Qt #endif diff --git a/src/libs/vmisc/fpm/fixed.hpp b/src/libs/vmisc/fpm/fixed.hpp index 556456a40..b73d8d2e0 100644 --- a/src/libs/vmisc/fpm/fixed.hpp +++ b/src/libs/vmisc/fpm/fixed.hpp @@ -1,17 +1,13 @@ #ifndef FPM_FIXED_HPP #define FPM_FIXED_HPP +#include #include #include #include #include #include #include -#include - -#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) -#include "../diagnostic.h" -#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) namespace fpm { @@ -21,8 +17,7 @@ namespace fpm //! unsigned type. //! \tparam IntermediateType the integer type used to store intermediate results during calculations. //! \tparam FractionBits the number of bits of the BaseType used to store the fraction -template -class fixed +template class fixed { static_assert(std::is_integral::value, "BaseType must be an integral type"); static_assert(FractionBits > 0, "FractionBits must be greater than zero"); @@ -36,42 +31,50 @@ class fixed // is incorrect (flips from positive to negative), so we must extend the size to IntermediateType. static constexpr IntermediateType FRACTION_MULT = IntermediateType(1) << FractionBits; - struct raw_construct_tag {}; - constexpr inline fixed(BaseType val, raw_construct_tag /*unused*/) noexcept : m_value(val) {} + struct raw_construct_tag + { + }; + constexpr inline fixed(BaseType val, raw_construct_tag /*unused*/) noexcept + : m_value(val) + { + } public: inline fixed() noexcept = default; // Converts an integral number to the fixed-point type. // Like static_cast, this truncates bits that don't fit. - template ::value>::type* = nullptr> + template ::value>::type * = nullptr> constexpr inline explicit fixed(T val) noexcept - : m_value(static_cast(val * FRACTION_MULT)) - {} + : m_value(static_cast(val * FRACTION_MULT)) + { + } // Converts an floating-point number to the fixed-point type. // Like static_cast, this truncates bits that don't fit. - template ::value>::type* = nullptr> + template ::value>::type * = nullptr> constexpr inline explicit fixed(T val) noexcept - : m_value(static_cast((val >= 0.0) ? (val * FRACTION_MULT + T{0.5}) : (val * FRACTION_MULT - T{0.5}))) - {} + : m_value(static_cast((val >= 0.0) ? (val * FRACTION_MULT + T{0.5}) : (val * FRACTION_MULT - T{0.5}))) + { + } // Constructs from another fixed-point type with possibly different underlying representation. // Like static_cast, this truncates bits that don't fit. template - constexpr inline explicit fixed(fixed val) noexcept - : m_value(from_fixed_point(val.raw_value()).raw_value()) - {} + constexpr inline explicit fixed(fixed val) noexcept + : m_value(from_fixed_point(val.raw_value()).raw_value()) + { + } // Explicit conversion to a floating-point type - template ::value>::type* = nullptr> + template ::value>::type * = nullptr> constexpr inline explicit operator T() const noexcept { return static_cast(m_value) / FRACTION_MULT; } // Explicit conversion to an integral type - template ::value>::type* = nullptr> + template ::value>::type * = nullptr> constexpr inline explicit operator T() const noexcept { return static_cast(m_value / FRACTION_MULT); @@ -79,33 +82,27 @@ public: // Returns the raw underlying value of this type. // Do not use this unless you know what you're doing. - constexpr inline auto raw_value() const noexcept -> BaseType - { - return m_value; - } + constexpr inline auto raw_value() const noexcept -> BaseType { return m_value; } //! Constructs a fixed-point number from another fixed-point number. //! \tparam NumFractionBits the number of bits used by the fraction in \a value. //! \param value the integer fixed-point number template FractionBits)>::type* = nullptr> + typename std::enable_if<(NumFractionBits > FractionBits)>::type * = nullptr> static constexpr inline auto from_fixed_point(T value) noexcept -> fixed { // To correctly round the last bit in the result, we need one more bit of information. // We do this by multiplying by two before dividing and adding the LSB to the real result. - return fixed(static_cast( - value / (T(1) << (NumFractionBits - FractionBits)) + - (value / (T(1) << (NumFractionBits - FractionBits - 1)) % 2)), - raw_construct_tag{}); + return fixed(static_cast(value / (T(1) << (NumFractionBits - FractionBits)) + + (value / (T(1) << (NumFractionBits - FractionBits - 1)) % 2)), + raw_construct_tag{}); } template ::type* = nullptr> + typename std::enable_if<(NumFractionBits <= FractionBits)>::type * = nullptr> static constexpr inline auto from_fixed_point(T value) noexcept -> fixed { - return fixed(static_cast( - value * (T(1) << (FractionBits - NumFractionBits))), - raw_construct_tag{}); + return fixed(static_cast(value * (T(1) << (FractionBits - NumFractionBits))), raw_construct_tag{}); } // Constructs a fixed-point number from its raw underlying value. @@ -127,56 +124,53 @@ public: // Arithmetic member operators // - constexpr inline auto operator-() const noexcept -> fixed - { - return fixed::from_raw_value(-m_value); - } + constexpr inline auto operator-() const noexcept -> fixed { return fixed::from_raw_value(-m_value); } - inline auto operator+=(const fixed& y) noexcept -> fixed& + inline auto operator+=(const fixed &y) noexcept -> fixed & { m_value += y.m_value; return *this; } - template ::value>::type* = nullptr> - inline auto operator+=(I y) noexcept -> fixed& + template ::value>::type * = nullptr> + inline auto operator+=(I y) noexcept -> fixed & { m_value += y * FRACTION_MULT; return *this; } - inline auto operator-=(const fixed& y) noexcept -> fixed& + inline auto operator-=(const fixed &y) noexcept -> fixed & { m_value -= y.m_value; return *this; } - template ::value>::type* = nullptr> - inline auto operator-=(I y) noexcept -> fixed& + template ::value>::type * = nullptr> + inline auto operator-=(I y) noexcept -> fixed & { m_value -= y * FRACTION_MULT; return *this; } - inline auto operator*=(const fixed& y) noexcept -> fixed& + inline auto operator*=(const fixed &y) noexcept -> fixed & { // Normal fixed-point multiplication is: x * y / 2**FractionBits. // To correctly round the last bit in the result, we need one more bit of information. // We do this by multiplying by two before dividing and adding the LSB to the real result. - auto value = static_cast( + auto value = static_cast( static_cast(static_cast(m_value) * y.m_value) / (FRACTION_MULT / 2)); m_value = static_cast((value / 2) + (value % 2)); return *this; } - template ::value>::type* = nullptr> - inline auto operator*=(I y) noexcept -> fixed& + template ::value>::type * = nullptr> + inline auto operator*=(I y) noexcept -> fixed & { m_value *= y; return *this; } - inline auto operator/=(const fixed& y) noexcept -> fixed& + inline auto operator/=(const fixed &y) noexcept -> fixed & { assert(y.m_value != 0); // Normal fixed-point division is: x * 2**FractionBits / y. @@ -187,8 +181,8 @@ public: return *this; } - template ::value>::type* = nullptr> - inline auto operator/=(I y) noexcept -> fixed& + template ::value>::type * = nullptr> + inline auto operator/=(I y) noexcept -> fixed & { m_value /= y; return *this; @@ -198,15 +192,15 @@ public: // Shift operators // - template ::value>::type* = nullptr> - inline auto operator>>=(I y) noexcept -> fixed& + template ::value>::type * = nullptr> + inline auto operator>>=(I y) noexcept -> fixed & { m_value >>= y; return *this; } - template ::value>::type* = nullptr> - inline auto operator<<=(I y) noexcept -> fixed& + template ::value>::type * = nullptr> + inline auto operator<<=(I y) noexcept -> fixed & { m_value <<= y; return *this; @@ -229,21 +223,21 @@ using fixed_8_24 = fixed; // template -constexpr inline auto operator+(const fixed& x, const fixed& y) noexcept -> fixed +constexpr inline auto operator+(const fixed &x, const fixed &y) noexcept -> fixed { return fixed(x) += y; } template ::value>::type* = nullptr> -constexpr inline auto operator+(const fixed& x, T y) noexcept -> fixed + typename std::enable_if::value>::type * = nullptr> +constexpr inline auto operator+(const fixed &x, T y) noexcept -> fixed { return fixed(x) += y; } template ::value>::type* = nullptr> -constexpr inline auto operator+(T x, const fixed& y) noexcept -> fixed + typename std::enable_if::value>::type * = nullptr> +constexpr inline auto operator+(T x, const fixed &y) noexcept -> fixed { return fixed(y) += x; } @@ -253,21 +247,21 @@ constexpr inline auto operator+(T x, const fixed& y) noexcept -> fixed< // template -constexpr inline auto operator-(const fixed& x, const fixed& y) noexcept -> fixed +constexpr inline auto operator-(const fixed &x, const fixed &y) noexcept -> fixed { return fixed(x) -= y; } template ::value>::type* = nullptr> -constexpr inline auto operator-(const fixed& x, T y) noexcept -> fixed + typename std::enable_if::value>::type * = nullptr> +constexpr inline auto operator-(const fixed &x, T y) noexcept -> fixed { return fixed(x) -= y; } template ::value>::type* = nullptr> -constexpr inline auto operator-(T x, const fixed& y) noexcept -> fixed + typename std::enable_if::value>::type * = nullptr> +constexpr inline auto operator-(T x, const fixed &y) noexcept -> fixed { return fixed(x) -= y; } @@ -277,21 +271,21 @@ constexpr inline auto operator-(T x, const fixed& y) noexcept -> fixed< // template -constexpr inline auto operator*(const fixed& x, const fixed& y) noexcept -> fixed +constexpr inline auto operator*(const fixed &x, const fixed &y) noexcept -> fixed { return fixed(x) *= y; } template ::value>::type* = nullptr> -constexpr inline auto operator*(const fixed& x, T y) noexcept -> fixed + typename std::enable_if::value>::type * = nullptr> +constexpr inline auto operator*(const fixed &x, T y) noexcept -> fixed { return fixed(x) *= y; } template ::value>::type* = nullptr> -constexpr inline auto operator*(T x, const fixed& y) noexcept -> fixed + typename std::enable_if::value>::type * = nullptr> +constexpr inline auto operator*(T x, const fixed &y) noexcept -> fixed { return fixed(y) *= x; } @@ -301,21 +295,21 @@ constexpr inline auto operator*(T x, const fixed& y) noexcept -> fixed< // template -constexpr inline auto operator/(const fixed& x, const fixed& y) noexcept -> fixed +constexpr inline auto operator/(const fixed &x, const fixed &y) noexcept -> fixed { return fixed(x) /= y; } template ::value>::type* = nullptr> -constexpr inline auto operator/(const fixed& x, T y) noexcept -> fixed + typename std::enable_if::value>::type * = nullptr> +constexpr inline auto operator/(const fixed &x, T y) noexcept -> fixed { return fixed(x) /= y; } template ::value>::type* = nullptr> -constexpr inline auto operator/(T x, const fixed& y) noexcept -> fixed + typename std::enable_if::value>::type * = nullptr> +constexpr inline auto operator/(T x, const fixed &y) noexcept -> fixed { return fixed(x) /= y; } @@ -325,15 +319,15 @@ constexpr inline auto operator/(T x, const fixed& y) noexcept -> fixed< // template ::value>::type* = nullptr> -constexpr inline auto operator>>(const fixed& x, T y) noexcept -> fixed + typename std::enable_if::value>::type * = nullptr> +constexpr inline auto operator>>(const fixed &x, T y) noexcept -> fixed { return fixed(x) >>= y; } template ::value>::type* = nullptr> -constexpr inline auto operator<<(const fixed& x, T y) noexcept -> fixed + typename std::enable_if::value>::type * = nullptr> +constexpr inline auto operator<<(const fixed &x, T y) noexcept -> fixed { return fixed(x) <<= y; } @@ -343,37 +337,37 @@ constexpr inline auto operator<<(const fixed& x, T y) noexcept -> fixed // template -constexpr inline auto operator==(const fixed& x, const fixed& y) noexcept -> bool +constexpr inline auto operator==(const fixed &x, const fixed &y) noexcept -> bool { return x.raw_value() == y.raw_value(); } template -constexpr inline auto operator!=(const fixed& x, const fixed& y) noexcept -> bool +constexpr inline auto operator!=(const fixed &x, const fixed &y) noexcept -> bool { return x.raw_value() != y.raw_value(); } template -constexpr inline auto operator<(const fixed& x, const fixed& y) noexcept -> bool +constexpr inline auto operator<(const fixed &x, const fixed &y) noexcept -> bool { return x.raw_value() < y.raw_value(); } template -constexpr inline auto operator>(const fixed& x, const fixed& y) noexcept -> bool +constexpr inline auto operator>(const fixed &x, const fixed &y) noexcept -> bool { return x.raw_value() > y.raw_value(); } template -constexpr inline auto operator<=(const fixed& x, const fixed& y) noexcept -> bool +constexpr inline auto operator<=(const fixed &x, const fixed &y) noexcept -> bool { return x.raw_value() <= y.raw_value(); } template -constexpr inline auto operator>=(const fixed& x, const fixed& y) noexcept -> bool +constexpr inline auto operator>=(const fixed &x, const fixed &y) noexcept -> bool { return x.raw_value() >= y.raw_value(); } @@ -388,7 +382,7 @@ QT_WARNING_DISABLE_CLANG("-Wunneeded-internal-declaration") static constexpr auto max_digits10(int bits) -> int { // 8.24 fixed-point equivalent of (int)ceil(bits * std::log10(2)); - using T = long long; // NOLINT(google-runtime-int) + using T = long long; // NOLINT(google-runtime-int) return static_cast((T{bits} * 5050445 + (T{1} << 24) - 1) >> 24); // NOLINT(hicpp-signed-bitwise) } @@ -396,8 +390,8 @@ static constexpr auto max_digits10(int bits) -> int static constexpr auto digits10(int bits) -> int { // 8.24 fixed-point equivalent of (int)(bits * std::log10(2)); - using T = long long; // NOLINT(google-runtime-int) - return static_cast((T{bits} * 5050445) >> 24); //NOLINT(hicpp-signed-bitwise) + using T = long long; // NOLINT(google-runtime-int) + return static_cast((T{bits} * 5050445) >> 24); // NOLINT(hicpp-signed-bitwise) } QT_WARNING_POP @@ -409,8 +403,7 @@ QT_WARNING_POP namespace std // NOLINT(cert-dcl58-cpp) { -template -struct hash> +template struct hash> { using argument_type = fpm::fixed; using result_type = std::size_t; @@ -425,8 +418,7 @@ private: std::hash m_hash; }; -template -struct numeric_limits> +template struct numeric_limits> { static constexpr bool is_specialized = true; static constexpr bool is_signed = std::numeric_limits::is_signed; @@ -461,87 +453,77 @@ struct numeric_limits> static constexpr bool traps = true; static constexpr bool tinyness_before = false; - static constexpr auto lowest() noexcept -> fpm::fixed + static constexpr auto lowest() noexcept -> fpm::fixed { - return fpm::fixed::from_raw_value(std::numeric_limits::lowest()); + return fpm::fixed::from_raw_value(std::numeric_limits::lowest()); } - static constexpr auto min() noexcept -> fpm::fixed + static constexpr auto min() noexcept -> fpm::fixed { return lowest(); } + + static constexpr auto max() noexcept -> fpm::fixed { - return lowest(); + return fpm::fixed::from_raw_value(std::numeric_limits::max()); } - static constexpr auto max() noexcept -> fpm::fixed - { - return fpm::fixed::from_raw_value(std::numeric_limits::max()); - } + static constexpr auto epsilon() noexcept -> fpm::fixed { return fpm::fixed::from_raw_value(1); } - static constexpr auto epsilon() noexcept -> fpm::fixed - { - return fpm::fixed::from_raw_value(1); - } + static constexpr auto round_error() noexcept -> fpm::fixed { return fpm::fixed(1) / 2; } - static constexpr auto round_error() noexcept -> fpm::fixed - { - return fpm::fixed(1) / 2; - } - - static constexpr auto denorm_min() noexcept -> fpm::fixed - { - return min(); - } + static constexpr auto denorm_min() noexcept -> fpm::fixed { return min(); } }; // See https://stackoverflow.com/a/46719572/3045403 #if __cplusplus < 201703L template -constexpr bool numeric_limits>::is_specialized; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::is_specialized; // NOLINT(readability-redundant-declaration) template -constexpr bool numeric_limits>::is_signed; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::is_signed; // NOLINT(readability-redundant-declaration) template -constexpr bool numeric_limits>::is_integer; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::is_integer; // NOLINT(readability-redundant-declaration) template -constexpr bool numeric_limits>::is_exact; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::is_exact; // NOLINT(readability-redundant-declaration) template -constexpr bool numeric_limits>::has_infinity; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::has_infinity; // NOLINT(readability-redundant-declaration) template -constexpr bool numeric_limits>::has_quiet_NaN; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::has_quiet_NaN; // NOLINT(readability-redundant-declaration) template -constexpr bool numeric_limits>::has_signaling_NaN; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::has_signaling_NaN; // NOLINT(readability-redundant-declaration) template -constexpr std::float_denorm_style numeric_limits>::has_denorm; // NOLINT(readability-redundant-declaration) +constexpr std::float_denorm_style + numeric_limits>::has_denorm; // NOLINT(readability-redundant-declaration) template -constexpr bool numeric_limits>::has_denorm_loss; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::has_denorm_loss; // NOLINT(readability-redundant-declaration) template -constexpr std::float_round_style numeric_limits>::round_style; // NOLINT(readability-redundant-declaration) +constexpr std::float_round_style + numeric_limits>::round_style; // NOLINT(readability-redundant-declaration) template -constexpr bool numeric_limits>::is_iec_559; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::is_iec_559; // NOLINT(readability-redundant-declaration) template -constexpr bool numeric_limits>::is_bounded; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::is_bounded; // NOLINT(readability-redundant-declaration) template -constexpr bool numeric_limits>::is_modulo; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::is_modulo; // NOLINT(readability-redundant-declaration) template -constexpr int numeric_limits>::digits; // NOLINT(readability-redundant-declaration) +constexpr int numeric_limits>::digits; // NOLINT(readability-redundant-declaration) template -constexpr int numeric_limits>::digits10; // NOLINT(readability-redundant-declaration) +constexpr int numeric_limits>::digits10; // NOLINT(readability-redundant-declaration) template -constexpr int numeric_limits>::max_digits10; // NOLINT(readability-redundant-declaration) +constexpr int numeric_limits>::max_digits10; // NOLINT(readability-redundant-declaration) template -constexpr int numeric_limits>::radix; // NOLINT(readability-redundant-declaration) +constexpr int numeric_limits>::radix; // NOLINT(readability-redundant-declaration) template -constexpr int numeric_limits>::min_exponent; // NOLINT(readability-redundant-declaration) +constexpr int numeric_limits>::min_exponent; // NOLINT(readability-redundant-declaration) template -constexpr int numeric_limits>::min_exponent10; // NOLINT(readability-redundant-declaration) +constexpr int numeric_limits>::min_exponent10; // NOLINT(readability-redundant-declaration) template -constexpr int numeric_limits>::max_exponent; // NOLINT(readability-redundant-declaration) +constexpr int numeric_limits>::max_exponent; // NOLINT(readability-redundant-declaration) template -constexpr int numeric_limits>::max_exponent10; // NOLINT(readability-redundant-declaration) +constexpr int numeric_limits>::max_exponent10; // NOLINT(readability-redundant-declaration) template -constexpr bool numeric_limits>::traps; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::traps; // NOLINT(readability-redundant-declaration) template -constexpr bool numeric_limits>::tinyness_before; // NOLINT(readability-redundant-declaration) +constexpr bool numeric_limits>::tinyness_before; // NOLINT(readability-redundant-declaration) #endif -} // namespace std +} // namespace std #endif diff --git a/src/libs/vmisc/fpm/math.hpp b/src/libs/vmisc/fpm/math.hpp index 70cf00786..5093c9ef5 100644 --- a/src/libs/vmisc/fpm/math.hpp +++ b/src/libs/vmisc/fpm/math.hpp @@ -37,9 +37,12 @@ inline auto find_highest_bit(unsigned long long value) noexcept -> long #if defined(_WIN64) _BitScanReverse64(&index, value); #else - if (_BitScanReverse(&index, static_cast(value >> 32)) != 0) { + if (_BitScanReverse(&index, static_cast(value >> 32)) != 0) + { index += 32; - } else { + } + else + { _BitScanReverse(&index, static_cast(value & 0xfffffffflu)); } #endif @@ -47,20 +50,19 @@ inline auto find_highest_bit(unsigned long long value) noexcept -> long #elif defined(__GNUC__) || defined(__clang__) return sizeof(value) * 8 - 1 - __builtin_clzll(value); // NOLINT #else -# error "your platform does not support find_highest_bit()" +#error "your platform does not support find_highest_bit()" #endif } QT_WARNING_POP -} // namespace detail +} // namespace detail // // Classification methods // -template -constexpr inline auto fpclassify(fixed x) noexcept -> int +template constexpr inline auto fpclassify(fixed x) noexcept -> int { return (x.raw_value() == 0) ? FP_ZERO : FP_NORMAL; } @@ -83,14 +85,12 @@ constexpr inline auto isnan(fixed /*unused*/) noexcept -> bool return false; } -template -constexpr inline auto isnormal(fixed x) noexcept -> bool +template constexpr inline auto isnormal(fixed x) noexcept -> bool { return x.raw_value() != 0; } -template -constexpr inline auto signbit(fixed x) noexcept -> bool +template constexpr inline auto signbit(fixed x) noexcept -> bool { return x.raw_value() < 0; } @@ -126,7 +126,7 @@ constexpr inline auto islessgreater(fixed x, fixed y) noexcept } template -constexpr inline auto isunordered(fixed /*x*/, fixed /*y*/) noexcept -> bool +constexpr inline auto isunordered(fixed /*x*/, fixed /*y*/) noexcept -> bool { return false; } @@ -134,8 +134,7 @@ constexpr inline auto isunordered(fixed /*x*/, fixed /*y*/) // // Nearest integer operations // -template -inline auto ceil(fixed x) noexcept -> fixed +template inline auto ceil(fixed x) noexcept -> fixed { constexpr auto FRAC = B(1) << F; auto value = x.raw_value(); @@ -146,8 +145,7 @@ inline auto ceil(fixed x) noexcept -> fixed return fixed::from_raw_value(value / FRAC * FRAC); } -template -inline auto floor(fixed x) noexcept -> fixed +template inline auto floor(fixed x) noexcept -> fixed { constexpr auto FRAC = B(1) << F; auto value = x.raw_value(); @@ -158,23 +156,20 @@ inline auto floor(fixed x) noexcept -> fixed return fixed::from_raw_value(value / FRAC * FRAC); } -template -inline auto trunc(fixed x) noexcept -> fixed +template inline auto trunc(fixed x) noexcept -> fixed { constexpr auto FRAC = B(1) << F; return fixed::from_raw_value(x.raw_value() / FRAC * FRAC); } -template -inline auto round(fixed x) noexcept -> fixed +template inline auto round(fixed x) noexcept -> fixed { constexpr auto FRAC = B(1) << F; auto value = x.raw_value() / (FRAC / 2); return fixed::from_raw_value(((value / 2) + (value % 2)) * FRAC); } -template -auto nearbyint(fixed x) noexcept -> fixed +template auto nearbyint(fixed x) noexcept -> fixed { // Rounding mode is assumed to be FE_TONEAREST constexpr auto FRAC = B(1) << F; @@ -196,8 +191,7 @@ constexpr inline auto rint(fixed x) noexcept -> fixed // // Mathematical functions // -template -constexpr inline auto abs(fixed x) noexcept -> fixed +template constexpr inline auto abs(fixed x) noexcept -> fixed { return (x >= fixed{0}) ? x : -x; } @@ -205,21 +199,17 @@ constexpr inline auto abs(fixed x) noexcept -> fixed template constexpr inline auto fmod(fixed x, fixed y) noexcept -> fixed { - return - assert(y.raw_value() != 0), - fixed::from_raw_value(x.raw_value() % y.raw_value()); + return assert(y.raw_value() != 0), fixed::from_raw_value(x.raw_value() % y.raw_value()); } template constexpr inline auto remainder(fixed x, fixed y) noexcept -> fixed { - return - assert(y.raw_value() != 0), - x - nearbyint(x / y) * y; + return assert(y.raw_value() != 0), x - nearbyint(x / y) * y; } template -inline auto remquo(fixed x, fixed y, int* quo) noexcept -> fixed +inline auto remquo(fixed x, fixed y, int *quo) noexcept -> fixed { assert(y.raw_value() != 0); assert(quo != nullptr); @@ -234,17 +224,15 @@ inline auto remquo(fixed x, fixed y, int* quo) noexcept -> fix template constexpr inline auto copysign(fixed x, fixed y) noexcept -> fixed { - return - x = abs(x), - (y >= fixed{0}) ? x : -x; + return x = abs(x), (y >= fixed{0}) ? x : -x; } template constexpr inline auto nextafter(fixed from, fixed to) noexcept -> fixed { - return from == to ? to : - to > from ? fixed::from_raw_value(from.raw_value() + 1) - : fixed::from_raw_value(from.raw_value() - 1); + return from == to ? to + : to > from ? fixed::from_raw_value(from.raw_value() + 1) + : fixed::from_raw_value(from.raw_value() - 1); } template @@ -254,7 +242,7 @@ constexpr inline auto nexttoward(fixed from, fixed to) noexcep } template -inline auto modf(fixed x, fixed* iptr) noexcept -> fixed +inline auto modf(fixed x, fixed *iptr) noexcept -> fixed { const auto raw = x.raw_value(); constexpr auto FRAC = B{1} << F; @@ -262,23 +250,23 @@ inline auto modf(fixed x, fixed* iptr) noexcept -> fixed::from_raw_value(raw % FRAC); } - // // Power functions // template ::value>::type* = nullptr> + typename std::enable_if::value>::type * = nullptr> auto pow(fixed base, T exp) noexcept -> fixed { using Fixed = fixed; - if (base == Fixed(0)) { + if (base == Fixed(0)) + { assert(exp > 0); return Fixed(0); } - Fixed result {1}; + Fixed result{1}; if (exp < 0) { for (Fixed intermediate = base; exp != 0; exp /= 2, intermediate *= intermediate) @@ -307,7 +295,8 @@ auto pow(fixed base, fixed exp) noexcept -> fixed { using Fixed = fixed; - if (base == Fixed(0)) { + if (base == Fixed(0)) + { assert(exp > Fixed(0)); return Fixed(0); } @@ -331,11 +320,11 @@ auto pow(fixed base, fixed exp) noexcept -> fixed return exp2(log2(base) * exp); } -template -auto exp(fixed x) noexcept -> fixed +template auto exp(fixed x) noexcept -> fixed { using Fixed = fixed; - if (x < Fixed(0)) { + if (x < Fixed(0)) + { return 1 / exp(-x); } constexpr auto FRAC = B(1) << F; @@ -343,8 +332,8 @@ auto exp(fixed x) noexcept -> fixed x -= x_int; assert(x >= Fixed(0) && x < Fixed(1)); - constexpr auto fA = Fixed::template from_fixed_point<63>( 128239257017632854LL); // 1.3903728105644451e-2 - constexpr auto fB = Fixed::template from_fixed_point<63>( 320978614890280666LL); // 3.4800571158543038e-2 + constexpr auto fA = Fixed::template from_fixed_point<63>(128239257017632854LL); // 1.3903728105644451e-2 + constexpr auto fB = Fixed::template from_fixed_point<63>(320978614890280666LL); // 3.4800571158543038e-2 constexpr auto fC = Fixed::template from_fixed_point<63>(1571680799599592947LL); // 1.7040197373796334e-1 constexpr auto fD = Fixed::template from_fixed_point<63>(4603349000587966862LL); // 4.9909609871464493e-1 constexpr auto fE = Fixed::template from_fixed_point<62>(4612052447974689712LL); // 1.0000794567422495 @@ -352,11 +341,11 @@ auto exp(fixed x) noexcept -> fixed return pow(Fixed::e(), x_int) * (((((fA * x + fB) * x + fC) * x + fD) * x + fE) * x + fF); } -template -auto exp2(fixed x) noexcept -> fixed +template auto exp2(fixed x) noexcept -> fixed { using Fixed = fixed; - if (x < Fixed(0)) { + if (x < Fixed(0)) + { return 1 / exp2(-x); } constexpr auto FRAC = B(1) << F; @@ -364,23 +353,21 @@ auto exp2(fixed x) noexcept -> fixed x -= x_int; assert(x >= Fixed(0) && x < Fixed(1)); - constexpr auto fA = Fixed::template from_fixed_point<63>( 17491766697771214LL); // 1.8964611454333148e-3 - constexpr auto fB = Fixed::template from_fixed_point<63>( 82483038782406547LL); // 8.9428289841091295e-3 - constexpr auto fC = Fixed::template from_fixed_point<63>( 515275173969157690LL); // 5.5866246304520701e-2 + constexpr auto fA = Fixed::template from_fixed_point<63>(17491766697771214LL); // 1.8964611454333148e-3 + constexpr auto fB = Fixed::template from_fixed_point<63>(82483038782406547LL); // 8.9428289841091295e-3 + constexpr auto fC = Fixed::template from_fixed_point<63>(515275173969157690LL); // 5.5866246304520701e-2 constexpr auto fD = Fixed::template from_fixed_point<63>(2214897896212987987LL); // 2.4013971109076949e-1 constexpr auto fE = Fixed::template from_fixed_point<63>(6393224161192452326LL); // 6.9315475247516736e-1 constexpr auto fF = Fixed::template from_fixed_point<63>(9223371050976163566LL); // 9.9999989311082668e-1 return Fixed(1 << x_int) * (((((fA * x + fB) * x + fC) * x + fD) * x + fE) * x + fF); } -template -auto expm1(fixed x) noexcept -> fixed +template auto expm1(fixed x) noexcept -> fixed { return exp(x) - 1; // cppcheck-suppress unpreciseMathCall } -template -auto log2(fixed x) noexcept -> fixed +template auto log2(fixed x) noexcept -> fixed { using Fixed = fixed; assert(x > Fixed(0)); @@ -399,37 +386,33 @@ auto log2(fixed x) noexcept -> fixed x = Fixed::from_raw_value(value); assert(x >= Fixed(1) && x < Fixed(2)); - constexpr auto fA = Fixed::template from_fixed_point<63>( 413886001457275979LL); // 4.4873610194131727e-2 + constexpr auto fA = Fixed::template from_fixed_point<63>(413886001457275979LL); // 4.4873610194131727e-2 constexpr auto fB = Fixed::template from_fixed_point<63>(-3842121857793256941LL); // -4.1656368651734915e-1 - constexpr auto fC = Fixed::template from_fixed_point<62>( 7522345947206307744LL); // 1.6311487636297217 + constexpr auto fC = Fixed::template from_fixed_point<62>(7522345947206307744LL); // 1.6311487636297217 constexpr auto fD = Fixed::template from_fixed_point<61>(-8187571043052183818LL); // -3.5507929249026341 - constexpr auto fE = Fixed::template from_fixed_point<60>( 5870342889289496598LL); // 5.0917108110420042 + constexpr auto fE = Fixed::template from_fixed_point<60>(5870342889289496598LL); // 5.0917108110420042 constexpr auto fF = Fixed::template from_fixed_point<61>(-6457199832668582866LL); // -2.8003640347009253 return Fixed(highest - F) + (((((fA * x + fB) * x + fC) * x + fD) * x + fE) * x + fF); } -template -auto log(fixed x) noexcept -> fixed +template auto log(fixed x) noexcept -> fixed { using Fixed = fixed; return log2(x) / log2(Fixed::e()); } -template -auto log10(fixed x) noexcept -> fixed +template auto log10(fixed x) noexcept -> fixed { using Fixed = fixed; return log2(x) / log2(Fixed(10)); } -template -auto log1p(fixed x) noexcept -> fixed +template auto log1p(fixed x) noexcept -> fixed { return log(1 + x); // cppcheck-suppress unpreciseMathCall } -template -auto cbrt(fixed x) noexcept -> fixed +template auto cbrt(fixed x) noexcept -> fixed { using Fixed = fixed; @@ -447,7 +430,7 @@ auto cbrt(fixed x) noexcept -> fixed // based on the square root algorithm. // We start at the greatest power of eight that's less than the argument. - int ofs = ((detail::find_highest_bit(x.raw_value()) + 2*F) / 3 * 3); + int ofs = ((detail::find_highest_bit(x.raw_value()) + 2 * F) / 3 * 3); I num = I{x.raw_value()}; I res = 0; @@ -456,7 +439,7 @@ auto cbrt(fixed x) noexcept -> fixed for (; ofs >= 0; ofs -= 3) { res += res; - const I val = (3*res*(res + 1) + 1) << ofs; + const I val = (3 * res * (res + 1) + 1) << ofs; if (num >= val) { num -= val; @@ -480,8 +463,7 @@ auto cbrt(fixed x) noexcept -> fixed return Fixed::from_raw_value(static_cast(res)); } -template -auto sqrt(fixed x) noexcept -> fixed +template auto sqrt(fixed x) noexcept -> fixed { using Fixed = fixed; @@ -523,15 +505,14 @@ template auto hypot(fixed x, fixed y) noexcept -> fixed { assert(x != 0 || y != 0); - return sqrt(x*x + y*y); + return sqrt(x * x + y * y); } // // Trigonometry functions // -template -auto sin(fixed x) noexcept -> fixed +template auto sin(fixed x) noexcept -> fixed { // This sine uses a fifth-order curve-fitting approximation originally // described by Jasper Vijn on coranac.com which has a worst-case @@ -543,34 +524,35 @@ auto sin(fixed x) noexcept -> fixed x = x / Fixed::half_pi(); // Take x modulo one rotation, so [-4..+4]. - if (x < Fixed(0)) { + if (x < Fixed(0)) + { x += Fixed(4); } int sign = +1; - if (x > Fixed(2)) { + if (x > Fixed(2)) + { // Reduce domain to [0..2]. sign = -1; x -= Fixed(2); } - if (x > Fixed(1)) { + if (x > Fixed(1)) + { // Reduce domain to [0..1]. x = Fixed(2) - x; } - const Fixed x2 = x*x; - return sign * x * (Fixed::pi() - x2*(Fixed::two_pi() - 5 - x2*(Fixed::pi() - 3)))/2; + const Fixed x2 = x * x; + return sign * x * (Fixed::pi() - x2 * (Fixed::two_pi() - 5 - x2 * (Fixed::pi() - 3))) / 2; } -template -inline auto cos(fixed x) noexcept -> fixed +template inline auto cos(fixed x) noexcept -> fixed { return sin(fixed::half_pi() + x); } -template -inline auto tan(fixed x) noexcept -> fixed +template inline auto tan(fixed x) noexcept -> fixed { auto cx = cos(x); @@ -581,21 +563,22 @@ inline auto tan(fixed x) noexcept -> fixed return sin(x) / cx; } -namespace detail { +namespace detail +{ // Calculates atan(x) assuming that x is in the range [0,1] -template -auto atan_sanitized(fixed x) noexcept -> fixed +template auto atan_sanitized(fixed x) noexcept -> fixed { using Fixed = fixed; assert(x >= Fixed(0) && x <= Fixed(1)); - constexpr auto fA = Fixed::template from_fixed_point<63>( 716203666280654660LL); // 0.0776509570923569 + constexpr auto fA = Fixed::template from_fixed_point<63>(716203666280654660LL); // 0.0776509570923569 constexpr auto fB = Fixed::template from_fixed_point<63>(-2651115102768076601LL); // -0.287434475393028 - constexpr auto fC = Fixed::template from_fixed_point<63>( 9178930894564541004LL); // 0.995181681698119 (PI/4 - A - B) + constexpr auto fC = + Fixed::template from_fixed_point<63>(9178930894564541004LL); // 0.995181681698119 (PI/4 - A - B) const auto xx = x * x; - return ((fA*xx + fB)*xx + fC)*x; + return ((fA * xx + fB) * xx + fC) * x; } // Calculate atan(y / x), assuming x != 0. @@ -613,28 +596,31 @@ auto atan_div(fixed y, fixed x) noexcept -> fixed // Make sure y and x are positive. // If y / x is negative (when y or x, but not both, are negative), negate the result to // keep the correct outcome. - if (y < Fixed(0)) { - if (x < Fixed(0)) { + if (y < Fixed(0)) + { + if (x < Fixed(0)) + { return atan_div(-y, -x); } return -atan_div(-y, x); } - if (x < Fixed(0)) { + if (x < Fixed(0)) + { return -atan_div(y, -x); } assert(y >= Fixed(0)); - assert(x > Fixed(0)); + assert(x > Fixed(0)); - if (y > x) { + if (y > x) + { return Fixed::half_pi() - detail::atan_sanitized(x / y); } return detail::atan_sanitized(y / x); } -} // namespace detail +} // namespace detail -template -auto atan(fixed x) noexcept -> fixed +template auto atan(fixed x) noexcept -> fixed { using Fixed = fixed; if (x < Fixed(0)) @@ -650,8 +636,7 @@ auto atan(fixed x) noexcept -> fixed return detail::atan_sanitized(x); } -template -auto asin(fixed x) noexcept -> fixed +template auto asin(fixed x) noexcept -> fixed { using Fixed = fixed; assert(x >= Fixed(-1) && x <= Fixed(+1)); @@ -664,8 +649,7 @@ auto asin(fixed x) noexcept -> fixed return detail::atan_div(x, sqrt(yy)); } -template -auto acos(fixed x) noexcept -> fixed +template auto acos(fixed x) noexcept -> fixed { using Fixed = fixed; assert(x >= Fixed(-1) && x <= Fixed(+1)); @@ -675,7 +659,7 @@ auto acos(fixed x) noexcept -> fixed return Fixed::pi(); } const auto yy = Fixed(1) - x * x; - return Fixed(2)*detail::atan_div(sqrt(yy), Fixed(1) + x); + return Fixed(2) * detail::atan_div(sqrt(yy), Fixed(1) + x); } template @@ -697,6 +681,6 @@ auto atan2(fixed y, fixed x) noexcept -> fixed return ret; } -} // namespace fpm +} // namespace fpm #endif diff --git a/src/libs/vmisc/vtextcodec.cpp b/src/libs/vmisc/vtextcodec.cpp index ea6d19fd6..4a8f212e3 100644 --- a/src/libs/vmisc/vtextcodec.cpp +++ b/src/libs/vmisc/vtextcodec.cpp @@ -38,19 +38,18 @@ namespace //--------------------------------------------------------------------------------------------------------------------- auto QtCodecs() -> QMap { - static auto codecs = QMap - { - {QStringConverter::Latin1, {"ISO-8859-1", "ANSI_1252", "CP1252", "windows-1252", "LATIN1", "CP819", "CSISO", - "IBM819", "ISO_8859-1", "APPLE ROMAN", "ISO8859-1", "ISO8859-15", "ISO-IR-100", "L1", "IBM 850", - "850"}}, // Western Europe + static auto codecs = QMap{ + {QStringConverter::Latin1, + {"ISO-8859-1", "ANSI_1252", "CP1252", "windows-1252", "LATIN1", "CP819", "CSISO", "IBM819", "ISO_8859-1", + "APPLE ROMAN", "ISO8859-1", "ISO8859-15", "ISO-IR-100", "L1", "IBM 850", "850"}}, // Western Europe {QStringConverter::Utf8, {"UTF-8", "UTF8", "UTF8-BIT"}}, {QStringConverter::Utf16, {"UTF-16", "UTF16", "UTF16-BIT"}}, - {QStringConverter::Utf16BE, {"UTF-16BE"}}, + {QStringConverter::Utf16BE, {"UTF-16BE"}}, {QStringConverter::Utf16LE, {"UTF-16LE"}}, - {QStringConverter::Utf32, {"UTF-32"}}, - {QStringConverter::Utf32BE, {"UTF-32BE"}}, - {QStringConverter::Utf32LE, {"UTF-32LE"}}, - {QStringConverter::System, {"System"}}, + {QStringConverter::Utf32, {"UTF-32"}}, + {QStringConverter::Utf32BE, {"UTF-32BE"}}, + {QStringConverter::Utf32LE, {"UTF-32LE"}}, + {QStringConverter::System, {"System"}}, }; return codecs; @@ -59,27 +58,21 @@ auto QtCodecs() -> QMap //--------------------------------------------------------------------------------------------------------------------- auto CodecMibs() -> QMap { - static auto mibs = QMap - { - {QStringConverter::Utf8, 106}, - {QStringConverter::Utf16, 1015}, - {QStringConverter::Utf16BE, 1013}, - {QStringConverter::Utf16LE, 1014}, - {QStringConverter::Utf32, 1017}, - {QStringConverter::Utf32BE, 1018}, - {QStringConverter::Utf32LE, 1019}, - {QStringConverter::Latin1, 4}, - {QStringConverter::System, 0}, + static auto mibs = QMap{ + {QStringConverter::Utf8, 106}, {QStringConverter::Utf16, 1015}, {QStringConverter::Utf16BE, 1013}, + {QStringConverter::Utf16LE, 1014}, {QStringConverter::Utf32, 1017}, {QStringConverter::Utf32BE, 1018}, + {QStringConverter::Utf32LE, 1019}, {QStringConverter::Latin1, 4}, {QStringConverter::System, 0}, }; return mibs; } -} // namespace +} // namespace //--------------------------------------------------------------------------------------------------------------------- VTextCodec::VTextCodec(QStringConverter::Encoding encoding) - : m_encoding(encoding) -{} + : m_encoding(encoding) +{ +} //--------------------------------------------------------------------------------------------------------------------- auto VTextCodec::codecForName(const QString &name) -> VTextCodec * diff --git a/src/libs/vobj/delaunay.cpp b/src/libs/vobj/delaunay.cpp index 7cd8d1329..49e0f3620 100644 --- a/src/libs/vobj/delaunay.cpp +++ b/src/libs/vobj/delaunay.cpp @@ -17,11 +17,11 @@ ** along with this program. If not, see . */ +#include #include #include #include #include -#include #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/diagnostic.h" @@ -41,84 +41,82 @@ extern void exactinit(); extern auto incircle(real *pa, real *pb, real *pc, real *pd) -> real; #endif -#define ON_RIGHT 1 -#define ON_SEG 0 -#define ON_LEFT -1 +#define ON_RIGHT 1 +#define ON_SEG 0 +#define ON_LEFT -1 -#define OUTSIDE -1 -#define ON_CIRCLE 0 -#define INSIDE 1 - -struct delaunay_s; -struct face_s; -struct halfedge_s; -struct point2d_s; +#define OUTSIDE -1 +#define ON_CIRCLE 0 +#define INSIDE 1 +struct delaunay_s; +struct face_s; +struct halfedge_s; +struct point2d_s; #ifdef USE_DOUBLE -# define REAL_ZERO 0.0 -# define REAL_ONE 1.0 -# define REAL_TWO 2.0 -# define REAL_FOUR 4.0 -# define TOLERANCE (1024.0 * 1024.0) +#define REAL_ZERO 0.0 +#define REAL_ONE 1.0 +#define REAL_TWO 2.0 +#define REAL_FOUR 4.0 +#define TOLERANCE (1024.0 * 1024.0) #else -# define REAL_ZERO 0.0f -# define REAL_ONE 1.0f -# define REAL_TWO 2.0f -# define REAL_FOUR 4.0f -# define TOLERANCE (16.0f ) +#define REAL_ZERO 0.0f +#define REAL_ONE 1.0f +#define REAL_TWO 2.0f +#define REAL_FOUR 4.0f +#define TOLERANCE (16.0f) #endif -#define EPSILON (REAL_ONE / TOLERANCE) +#define EPSILON (REAL_ONE / TOLERANCE) -typedef point2d_s point2d_t; -typedef face_s face_t; -typedef halfedge_s halfedge_t; -typedef delaunay_s delaunay_t; +typedef point2d_s point2d_t; +typedef face_s face_t; +typedef halfedge_s halfedge_t; +typedef delaunay_s delaunay_t; typedef real mat3_t[3][3]; struct point2d_s { - real x, y; /* point coordinates */ - halfedge_t* he; /* point halfedge */ - quint32 idx; /* point index in input buffer */ + real x, y; /* point coordinates */ + halfedge_t *he; /* point halfedge */ + quint32 idx; /* point index in input buffer */ }; struct face_s { -/* real radius; - real cx, cy; - point2d_t* p[3]; -*/ - halfedge_t* he; /* a pointing half edge */ - quint32 num_verts; /* number of vertices on this face */ + /* real radius; + real cx, cy; + point2d_t* p[3]; + */ + halfedge_t *he; /* a pointing half edge */ + quint32 num_verts; /* number of vertices on this face */ }; struct halfedge_s { - point2d_t* vertex; /* vertex */ - halfedge_t* pair; /* pair */ - halfedge_t* next; /* next */ - halfedge_t* prev; /* next^-1 */ - face_t* face; /* halfedge face */ + point2d_t *vertex; /* vertex */ + halfedge_t *pair; /* pair */ + halfedge_t *next; /* next */ + halfedge_t *prev; /* next^-1 */ + face_t *face; /* halfedge face */ }; struct delaunay_s { - halfedge_t* rightmost_he; /* right most halfedge */ - halfedge_t* leftmost_he; /* left most halfedge */ - point2d_t** points; /* pointer to points */ - face_t* faces; /* faces of delaunay */ - quint32 num_faces; /* face count */ - quint32 start_point; /* start point index */ - quint32 end_point; /* end point index */ + halfedge_t *rightmost_he; /* right most halfedge */ + halfedge_t *leftmost_he; /* left most halfedge */ + point2d_t **points; /* pointer to points */ + face_t *faces; /* faces of delaunay */ + quint32 num_faces; /* face count */ + quint32 start_point; /* start point index */ + quint32 end_point; /* end point index */ }; - /* -* 3x3 matrix determinant -*/ -//static real det3( mat3_t *m ) + * 3x3 matrix determinant + */ +// static real det3( mat3_t *m ) //{ // real res; @@ -130,78 +128,79 @@ struct delaunay_s //} /* -* allocate a point -*/ + * allocate a point + */ static auto point_alloc() -> point2d_t * { - point2d_t* p; + point2d_t *p; - p = (point2d_t*)malloc(sizeof(point2d_t)); - assert( p != nullptr ); -// cppcheck-suppress memsetClassFloat + p = (point2d_t *)malloc(sizeof(point2d_t)); + assert(p != nullptr); + // cppcheck-suppress memsetClassFloat memset(p, 0, sizeof(point2d_t)); return p; } /* -* free a point -*/ -static void point_free( point2d_t* p ) + * free a point + */ +static void point_free(point2d_t *p) { - assert( p != nullptr ); + assert(p != nullptr); free(p); } /* -* allocate a halfedge -*/ + * allocate a halfedge + */ static auto halfedge_alloc() -> halfedge_t * { - halfedge_t* d; + halfedge_t *d; - d = (halfedge_t*)malloc(sizeof(halfedge_t)); - assert( d != nullptr ); + d = (halfedge_t *)malloc(sizeof(halfedge_t)); + assert(d != nullptr); memset(d, 0, sizeof(halfedge_t)); return d; } /* -* free a halfedge -*/ -static void halfedge_free( halfedge_t* d ) + * free a halfedge + */ +static void halfedge_free(halfedge_t *d) { - assert( d != nullptr ); + assert(d != nullptr); memset(d, 0, sizeof(halfedge_t)); free(d); } /* -* free all delaunay halfedges -*/ -void del_free_halfedges( delaunay_t *del ); -void del_free_halfedges( delaunay_t *del ) + * free all delaunay halfedges + */ +void del_free_halfedges(delaunay_t *del); +void del_free_halfedges(delaunay_t *del) { - quint32 i; - halfedge_t *d, *sig; + quint32 i; + halfedge_t *d, *sig; /* if there is nothing to do */ - if( del->points == nullptr ) + if (del->points == nullptr) return; - for( i = 0; i <= (del->end_point - del->start_point); i++ ) + for (i = 0; i <= (del->end_point - del->start_point); i++) { /* free all the halfedges around the point */ - d = del->points[i]->he; - if( d != nullptr ) + d = del->points[i]->he; + if (d != nullptr) { - do { - sig = d->next; - halfedge_free( d ); - d = sig; - } while( d != del->points[i]->he ); - del->points[i]->he = nullptr; + do + { + sig = d->next; + halfedge_free(d); + d = sig; + } while (d != del->points[i]->he); + del->points[i]->he = nullptr; } } } @@ -209,166 +208,166 @@ void del_free_halfedges( delaunay_t *del ) /* * allocate memory for a face */ -//static face_t* face_alloc() +// static face_t* face_alloc() //{ // face_t *f = (face_t*)malloc(sizeof(face_t)); // assert( f != nullptr ); // memset(f, 0, sizeof(face_t)); // return f; -//} +// } /* * free a face */ -//static void face_free(face_t *f) +// static void face_free(face_t *f) //{ // assert( f != nullptr ); // free(f); -//} +// } /* -* compare 2 points when sorting -*/ + * compare 2 points when sorting + */ static auto cmp_points(const void *_pt0, const void *_pt1) -> int { - point2d_t *pt0, *pt1; + point2d_t *pt0, *pt1; - pt0 = (point2d_t*)(*((point2d_t**)_pt0)); - pt1 = (point2d_t*)(*((point2d_t**)_pt1)); + pt0 = (point2d_t *)(*((point2d_t **)_pt0)); + pt1 = (point2d_t *)(*((point2d_t **)_pt1)); - if( pt0->x < pt1->x ) + if (pt0->x < pt1->x) return -1; - else if( pt0->x > pt1->x ) + else if (pt0->x > pt1->x) return 1; - else if( pt0->y < pt1->y ) + else if (pt0->y < pt1->y) return -1; - else if( pt0->y > pt1->y ) + else if (pt0->y > pt1->y) return 1; assert(0 && "2 or more points share the same exact coordinate"); return 0; /* Should not be given! */ } /* -* classify a point relative to a segment -*/ + * classify a point relative to a segment + */ static auto classify_point_seg(point2d_t *s, point2d_t *e, point2d_t *pt) -> int { - point2d_t se, spt; - real res; + point2d_t se, spt; + real res; - se.x = e->x - s->x; - se.y = e->y - s->y; + se.x = e->x - s->x; + se.y = e->y - s->y; - spt.x = pt->x - s->x; - spt.y = pt->y - s->y; + spt.x = pt->x - s->x; + spt.y = pt->y - s->y; - res = (( se.x * spt.y ) - ( se.y * spt.x )); - if( res < REAL_ZERO ) + res = ((se.x * spt.y) - (se.y * spt.x)); + if (res < REAL_ZERO) return ON_RIGHT; - else if( res > REAL_ZERO ) + else if (res > REAL_ZERO) return ON_LEFT; return ON_SEG; } /* -* classify a point relative to a halfedge, -1 is left, 0 is on, 1 is right -*/ + * classify a point relative to a halfedge, -1 is left, 0 is on, 1 is right + */ static auto del_classify_point(halfedge_t *d, point2d_t *pt) -> int { - point2d_t *s, *e; + point2d_t *s, *e; - s = d->vertex; - e = d->pair->vertex; + s = d->vertex; + e = d->pair->vertex; return classify_point_seg(s, e, pt); } /* -* return the absolute value -*/ -//static real dabs( real a ) + * return the absolute value + */ +// static real dabs( real a ) //{ // if( a < REAL_ZERO ) // return (-a); // return a; -//} +// } /* -* compute the circle given 3 points -*/ + * compute the circle given 3 points + */ #if PREDICATE == LOOSE_PREDICATE -static void compute_circle( point2d_t *pt0, point2d_t *pt1, point2d_t *pt2, real *cx, real *cy, real *radius ) +static void compute_circle(point2d_t *pt0, point2d_t *pt1, point2d_t *pt2, real *cx, real *cy, real *radius) { - mat3_t ma, mbx, mby, mc; - real x0y0, x1y1, x2y2; - real a, bx, by, c; + mat3_t ma, mbx, mby, mc; + real x0y0, x1y1, x2y2; + real a, bx, by, c; /* calculate x0y0, .... */ - x0y0 = pt0->x * pt0->x + pt0->y * pt0->y; - x1y1 = pt1->x * pt1->x + pt1->y * pt1->y; - x2y2 = pt2->x * pt2->x + pt2->y * pt2->y; + x0y0 = pt0->x * pt0->x + pt0->y * pt0->y; + x1y1 = pt1->x * pt1->x + pt1->y * pt1->y; + x2y2 = pt2->x * pt2->x + pt2->y * pt2->y; /* setup A matrix */ - ma[0][0] = pt0->x; - ma[0][1] = pt0->y; - ma[1][0] = pt1->x; - ma[1][1] = pt1->y; - ma[2][0] = pt2->x; - ma[2][1] = pt2->y; - ma[0][2] = ma[1][2] = ma[2][2] = REAL_ONE; + ma[0][0] = pt0->x; + ma[0][1] = pt0->y; + ma[1][0] = pt1->x; + ma[1][1] = pt1->y; + ma[2][0] = pt2->x; + ma[2][1] = pt2->y; + ma[0][2] = ma[1][2] = ma[2][2] = REAL_ONE; /* setup Bx matrix */ - mbx[0][0] = x0y0; - mbx[1][0] = x1y1; - mbx[2][0] = x2y2; - mbx[0][1] = pt0->y; - mbx[1][1] = pt1->y; - mbx[2][1] = pt2->y; - mbx[0][2] = mbx[1][2] = mbx[2][2] = REAL_ONE; + mbx[0][0] = x0y0; + mbx[1][0] = x1y1; + mbx[2][0] = x2y2; + mbx[0][1] = pt0->y; + mbx[1][1] = pt1->y; + mbx[2][1] = pt2->y; + mbx[0][2] = mbx[1][2] = mbx[2][2] = REAL_ONE; /* setup By matrix */ - mby[0][0] = x0y0; - mby[1][0] = x1y1; - mby[2][0] = x2y2; - mby[0][1] = pt0->x; - mby[1][1] = pt1->x; - mby[2][1] = pt2->x; - mby[0][2] = mby[1][2] = mby[2][2] = REAL_ONE; + mby[0][0] = x0y0; + mby[1][0] = x1y1; + mby[2][0] = x2y2; + mby[0][1] = pt0->x; + mby[1][1] = pt1->x; + mby[2][1] = pt2->x; + mby[0][2] = mby[1][2] = mby[2][2] = REAL_ONE; /* setup C matrix */ - mc[0][0] = x0y0; - mc[1][0] = x1y1; - mc[2][0] = x2y2; - mc[0][1] = pt0->x; - mc[1][1] = pt1->x; - mc[2][1] = pt2->x; - mc[0][2] = pt0->y; - mc[1][2] = pt1->y; - mc[2][2] = pt2->y; + mc[0][0] = x0y0; + mc[1][0] = x1y1; + mc[2][0] = x2y2; + mc[0][1] = pt0->x; + mc[1][1] = pt1->x; + mc[2][1] = pt2->x; + mc[0][2] = pt0->y; + mc[1][2] = pt1->y; + mc[2][2] = pt2->y; /* compute a, bx, by and c */ - a = det3(&ma); - bx = det3(&mbx); - by = -det3(&mby); - c = -det3(&mc); + a = det3(&ma); + bx = det3(&mbx); + by = -det3(&mby); + c = -det3(&mc); - *cx = bx / (REAL_TWO * a); - *cy = by / (REAL_TWO * a); - *radius = sqrt(bx * bx + by * by - REAL_FOUR * a * c) / (REAL_TWO * dabs(a)); + *cx = bx / (REAL_TWO * a); + *cy = by / (REAL_TWO * a); + *radius = sqrt(bx * bx + by * by - REAL_FOUR * a * c) / (REAL_TWO * dabs(a)); } #endif /* -* test if a point is inside a circle given by 3 points, 1 if inside, 0 if outside -*/ + * test if a point is inside a circle given by 3 points, 1 if inside, 0 if outside + */ static auto in_circle(point2d_t *pt0, point2d_t *pt1, point2d_t *pt2, point2d_t *p) -> int { #if PREDICATE == EXACT_PREDICATE - real res = incircle(&(pt0->x), &(pt1->x), &(pt2->x), &(p->x)); - if( res > REAL_ZERO ) + real res = incircle(&(pt0->x), &(pt1->x), &(pt2->x), &(p->x)); + if (res > REAL_ZERO) return INSIDE; - else if( res < REAL_ZERO ) + else if (res < REAL_ZERO) return OUTSIDE; return ON_CIRCLE; @@ -377,73 +376,72 @@ static auto in_circle(point2d_t *pt0, point2d_t *pt1, point2d_t *pt2, point2d_t real cx, cy, radius; compute_circle(pt0, pt1, pt2, &cx, &cy, &radius); - real distance = sqrt((p->x - cx) * (p->x - cx) + (p->y - cy) * (p->y - cy)); - if( distance < radius - EPSILON ) + real distance = sqrt((p->x - cx) * (p->x - cx) + (p->y - cy) * (p->y - cy)); + if (distance < radius - EPSILON) return INSIDE; - else if(distance > radius + EPSILON ) + else if (distance > radius + EPSILON) return OUTSIDE; return ON_CIRCLE; #endif #if PREDICATE == FAST_PREDICATE - mat3_t ma, mbx, mby, mc; - real x0y0, x1y1, x2y2; - real a, bx, by, c, res; + mat3_t ma, mbx, mby, mc; + real x0y0, x1y1, x2y2; + real a, bx, by, c, res; /* calculate x0y0, .... */ - x0y0 = pt0->x * pt0->x + pt0->y * pt0->y; - x1y1 = pt1->x * pt1->x + pt1->y * pt1->y; - x2y2 = pt2->x * pt2->x + pt2->y * pt2->y; + x0y0 = pt0->x * pt0->x + pt0->y * pt0->y; + x1y1 = pt1->x * pt1->x + pt1->y * pt1->y; + x2y2 = pt2->x * pt2->x + pt2->y * pt2->y; /* setup A matrix */ - ma[0][0] = pt0->x; - ma[0][1] = pt0->y; - ma[1][0] = pt1->x; - ma[1][1] = pt1->y; - ma[2][0] = pt2->x; - ma[2][1] = pt2->y; - ma[0][2] = ma[1][2] = ma[2][2] = REAL_ONE; + ma[0][0] = pt0->x; + ma[0][1] = pt0->y; + ma[1][0] = pt1->x; + ma[1][1] = pt1->y; + ma[2][0] = pt2->x; + ma[2][1] = pt2->y; + ma[0][2] = ma[1][2] = ma[2][2] = REAL_ONE; /* setup Bx matrix */ - mbx[0][0] = x0y0; - mbx[1][0] = x1y1; - mbx[2][0] = x2y2; - mbx[0][1] = pt0->y; - mbx[1][1] = pt1->y; - mbx[2][1] = pt2->y; - mbx[0][2] = mbx[1][2] = mbx[2][2] = REAL_ONE; + mbx[0][0] = x0y0; + mbx[1][0] = x1y1; + mbx[2][0] = x2y2; + mbx[0][1] = pt0->y; + mbx[1][1] = pt1->y; + mbx[2][1] = pt2->y; + mbx[0][2] = mbx[1][2] = mbx[2][2] = REAL_ONE; /* setup By matrix */ - mby[0][0] = x0y0; - mby[1][0] = x1y1; - mby[2][0] = x2y2; - mby[0][1] = pt0->x; - mby[1][1] = pt1->x; - mby[2][1] = pt2->x; - mby[0][2] = mby[1][2] = mby[2][2] = REAL_ONE; + mby[0][0] = x0y0; + mby[1][0] = x1y1; + mby[2][0] = x2y2; + mby[0][1] = pt0->x; + mby[1][1] = pt1->x; + mby[2][1] = pt2->x; + mby[0][2] = mby[1][2] = mby[2][2] = REAL_ONE; /* setup C matrix */ - mc[0][0] = x0y0; - mc[1][0] = x1y1; - mc[2][0] = x2y2; - mc[0][1] = pt0->x; - mc[1][1] = pt1->x; - mc[2][1] = pt2->x; - mc[0][2] = pt0->y; - mc[1][2] = pt1->y; - mc[2][2] = pt2->y; + mc[0][0] = x0y0; + mc[1][0] = x1y1; + mc[2][0] = x2y2; + mc[0][1] = pt0->x; + mc[1][1] = pt1->x; + mc[2][1] = pt2->x; + mc[0][2] = pt0->y; + mc[1][2] = pt1->y; + mc[2][2] = pt2->y; /* compute a, bx, by and c */ - a = det3(&ma); - bx = det3(&mbx); - by = -det3(&mby); - c = -det3(&mc); + a = det3(&ma); + bx = det3(&mbx); + by = -det3(&mby); + c = -det3(&mc); - res = a * (p->x * p->x + p->y * p->y ) - bx * p->x - by * p->y + c; + res = a * (p->x * p->x + p->y * p->y) - bx * p->x - by * p->y + c; - - if( res < REAL_ZERO ) + if (res < REAL_ZERO) return INSIDE; - else if( res > REAL_ZERO ) + else if (res > REAL_ZERO) return OUTSIDE; return ON_CIRCLE; @@ -451,226 +449,222 @@ static auto in_circle(point2d_t *pt0, point2d_t *pt1, point2d_t *pt2, point2d_t } /* -* initialize delaunay segment -*/ + * initialize delaunay segment + */ static auto del_init_seg(delaunay_t *del, int start) -> int { - halfedge_t *d0, *d1; - point2d_t *pt0, *pt1; + halfedge_t *d0, *d1; + point2d_t *pt0, *pt1; /* init delaunay */ - del->start_point = static_cast(start); - del->end_point = static_cast(start + 1); + del->start_point = static_cast(start); + del->end_point = static_cast(start + 1); /* setup pt0 and pt1 */ - pt0 = del->points[start]; - pt1 = del->points[start + 1]; + pt0 = del->points[start]; + pt1 = del->points[start + 1]; /* allocate the halfedges and setup them */ - d0 = halfedge_alloc(); - d1 = halfedge_alloc(); + d0 = halfedge_alloc(); + d1 = halfedge_alloc(); - d0->vertex = pt0; - d1->vertex = pt1; + d0->vertex = pt0; + d1->vertex = pt1; - d0->next = d0->prev = d0; - d1->next = d1->prev = d1; + d0->next = d0->prev = d0; + d1->next = d1->prev = d1; - d0->pair = d1; - d1->pair = d0; + d0->pair = d1; + d1->pair = d0; - pt0->he = d0; - pt1->he = d1; - - del->rightmost_he = d1; - del->leftmost_he = d0; + pt0->he = d0; + pt1->he = d1; + del->rightmost_he = d1; + del->leftmost_he = d0; return 0; } /* -* initialize delaunay triangle -*/ + * initialize delaunay triangle + */ static auto del_init_tri(delaunay_t *del, int start) -> int { - halfedge_t *d0, *d1, *d2, *d3, *d4, *d5; - point2d_t *pt0, *pt1, *pt2; + halfedge_t *d0, *d1, *d2, *d3, *d4, *d5; + point2d_t *pt0, *pt1, *pt2; /* initiate delaunay */ - del->start_point = static_cast(start); - del->end_point = static_cast(start + 2); + del->start_point = static_cast(start); + del->end_point = static_cast(start + 2); /* setup the points */ - pt0 = del->points[start]; - pt1 = del->points[start + 1]; - pt2 = del->points[start + 2]; + pt0 = del->points[start]; + pt1 = del->points[start + 1]; + pt2 = del->points[start + 2]; /* allocate the 6 halfedges */ - d0 = halfedge_alloc(); - d1 = halfedge_alloc(); - d2 = halfedge_alloc(); - d3 = halfedge_alloc(); - d4 = halfedge_alloc(); - d5 = halfedge_alloc(); + d0 = halfedge_alloc(); + d1 = halfedge_alloc(); + d2 = halfedge_alloc(); + d3 = halfedge_alloc(); + d4 = halfedge_alloc(); + d5 = halfedge_alloc(); - if( classify_point_seg(pt0, pt2, pt1) == ON_LEFT ) /* first case */ + if (classify_point_seg(pt0, pt2, pt1) == ON_LEFT) /* first case */ { /* set halfedges points */ - d0->vertex = pt0; - d1->vertex = pt2; - d2->vertex = pt1; + d0->vertex = pt0; + d1->vertex = pt2; + d2->vertex = pt1; - d3->vertex = pt2; - d4->vertex = pt1; - d5->vertex = pt0; + d3->vertex = pt2; + d4->vertex = pt1; + d5->vertex = pt0; /* set points halfedges */ - pt0->he = d0; - pt1->he = d2; - pt2->he = d1; + pt0->he = d0; + pt1->he = d2; + pt2->he = d1; /* next and next -1 setup */ - d0->next = d5; - d0->prev = d5; + d0->next = d5; + d0->prev = d5; - d1->next = d3; - d1->prev = d3; + d1->next = d3; + d1->prev = d3; - d2->next = d4; - d2->prev = d4; + d2->next = d4; + d2->prev = d4; - d3->next = d1; - d3->prev = d1; + d3->next = d1; + d3->prev = d1; - d4->next = d2; - d4->prev = d2; + d4->next = d2; + d4->prev = d2; - d5->next = d0; - d5->prev = d0; + d5->next = d0; + d5->prev = d0; /* set halfedges pair */ - d0->pair = d3; - d3->pair = d0; + d0->pair = d3; + d3->pair = d0; - d1->pair = d4; - d4->pair = d1; + d1->pair = d4; + d4->pair = d1; - d2->pair = d5; - d5->pair = d2; + d2->pair = d5; + d5->pair = d2; - del->rightmost_he = d1; - del->leftmost_he = d0; - - } else /* 2nd case */ + del->rightmost_he = d1; + del->leftmost_he = d0; + } + else /* 2nd case */ { /* set halfedges points */ - d0->vertex = pt0; - d1->vertex = pt1; - d2->vertex = pt2; + d0->vertex = pt0; + d1->vertex = pt1; + d2->vertex = pt2; - d3->vertex = pt1; - d4->vertex = pt2; - d5->vertex = pt0; + d3->vertex = pt1; + d4->vertex = pt2; + d5->vertex = pt0; /* set points halfedges */ - pt0->he = d0; - pt1->he = d1; - pt2->he = d2; + pt0->he = d0; + pt1->he = d1; + pt2->he = d2; /* next and next -1 setup */ - d0->next = d5; - d0->prev = d5; + d0->next = d5; + d0->prev = d5; - d1->next = d3; - d1->prev = d3; + d1->next = d3; + d1->prev = d3; - d2->next = d4; - d2->prev = d4; + d2->next = d4; + d2->prev = d4; - d3->next = d1; - d3->prev = d1; + d3->next = d1; + d3->prev = d1; - d4->next = d2; - d4->prev = d2; + d4->next = d2; + d4->prev = d2; - d5->next = d0; - d5->prev = d0; + d5->next = d0; + d5->prev = d0; /* set halfedges pair */ - d0->pair = d3; - d3->pair = d0; + d0->pair = d3; + d3->pair = d0; - d1->pair = d4; - d4->pair = d1; + d1->pair = d4; + d4->pair = d1; - d2->pair = d5; - d5->pair = d2; + d2->pair = d5; + d5->pair = d2; - del->rightmost_he = d2; - del->leftmost_he = d0; + del->rightmost_he = d2; + del->leftmost_he = d0; } return 0; } /* -* remove an edge given a halfedge -*/ -static void del_remove_edge( halfedge_t *d ) + * remove an edge given a halfedge + */ +static void del_remove_edge(halfedge_t *d) { - halfedge_t *next, *prev, *pair, *orig_pair; + halfedge_t *next, *prev, *pair, *orig_pair; - orig_pair = d->pair; + orig_pair = d->pair; - next = d->next; - prev = d->prev; - pair = d->pair; + next = d->next; + prev = d->prev; + pair = d->pair; assert(next != nullptr); assert(prev != nullptr); - next->prev = prev; - prev->next = next; - + next->prev = prev; + prev->next = next; /* check to see if we have already removed pair */ - if( pair ) - pair->pair = nullptr; + if (pair) + pair->pair = nullptr; /* check to see if the vertex points to this halfedge */ - if( d->vertex->he == d ) - d->vertex->he = next; + if (d->vertex->he == d) + d->vertex->he = next; - d->vertex = nullptr; - d->next = nullptr; - d->prev = nullptr; - d->pair = nullptr; + d->vertex = nullptr; + d->next = nullptr; + d->prev = nullptr; + d->pair = nullptr; - next = orig_pair->next; - prev = orig_pair->prev; - pair = orig_pair->pair; + next = orig_pair->next; + prev = orig_pair->prev; + pair = orig_pair->pair; assert(next != nullptr); assert(prev != nullptr); - next->prev = prev; - prev->next = next; - + next->prev = prev; + prev->next = next; /* check to see if we have already removed pair */ - if( pair ) - pair->pair = nullptr; + if (pair) + pair->pair = nullptr; /* check to see if the vertex points to this halfedge */ - if( orig_pair->vertex->he == orig_pair ) - orig_pair->vertex->he = next; - - orig_pair->vertex = nullptr; - orig_pair->next = nullptr; - orig_pair->prev = nullptr; - orig_pair->pair = nullptr; + if (orig_pair->vertex->he == orig_pair) + orig_pair->vertex->he = next; + orig_pair->vertex = nullptr; + orig_pair->next = nullptr; + orig_pair->prev = nullptr; + orig_pair->pair = nullptr; /* finally free the halfedges */ halfedge_free(d); @@ -678,416 +672,424 @@ static void del_remove_edge( halfedge_t *d ) } /* -* pass through all the halfedges on the left side and validate them -*/ + * pass through all the halfedges on the left side and validate them + */ static auto del_valid_left(halfedge_t *b) -> halfedge_t * { - point2d_t *g, *d, *u, *v; - halfedge_t *c, *du, *dg; + point2d_t *g, *d, *u, *v; + halfedge_t *c, *du, *dg; - g = b->vertex; /* base halfedge point */ - dg = b; + g = b->vertex; /* base halfedge point */ + dg = b; - d = b->pair->vertex; /* pair(halfedge) point */ - b = b->next; + d = b->pair->vertex; /* pair(halfedge) point */ + b = b->next; - u = b->pair->vertex; /* next(pair(halfedge)) point */ - du = b->pair; + u = b->pair->vertex; /* next(pair(halfedge)) point */ + du = b->pair; - v = b->next->pair->vertex; /* pair(next(next(halfedge)) point */ + v = b->next->pair->vertex; /* pair(next(next(halfedge)) point */ - if( classify_point_seg(g, d, u) == ON_LEFT ) + if (classify_point_seg(g, d, u) == ON_LEFT) { /* 3 points aren't colinear */ /* as long as the 4 points belong to the same circle, do the cleaning */ - assert( v != u && "1: floating point precision error"); - while( v != d && v != g && in_circle(g, d, u, v) == INSIDE ) + assert(v != u && "1: floating point precision error"); + while (v != d && v != g && in_circle(g, d, u, v) == INSIDE) { - c = b->next; - du = b->next->pair; + c = b->next; + du = b->next->pair; del_remove_edge(b); - b = c; - u = du->vertex; - v = b->next->pair->vertex; + b = c; + u = du->vertex; + v = b->next->pair->vertex; } - assert( v != u && "2: floating point precision error"); - if( v != d && v != g && in_circle(g, d, u, v) == ON_CIRCLE ) + assert(v != u && "2: floating point precision error"); + if (v != d && v != g && in_circle(g, d, u, v) == ON_CIRCLE) { - du = du->prev; + du = du->prev; del_remove_edge(b); } - } else /* treat the case where the 3 points are colinear */ - du = dg; + } + else /* treat the case where the 3 points are colinear */ + du = dg; assert(du->pair); return du; } /* -* pass through all the halfedges on the right side and validate them -*/ + * pass through all the halfedges on the right side and validate them + */ static auto del_valid_right(halfedge_t *b) -> halfedge_t * { - point2d_t *rv, *lv, *u, *v; - halfedge_t *c, *dd, *du; + point2d_t *rv, *lv, *u, *v; + halfedge_t *c, *dd, *du; - b = b->pair; - rv = b->vertex; - dd = b; - lv = b->pair->vertex; - b = b->prev; - u = b->pair->vertex; - du = b->pair; + b = b->pair; + rv = b->vertex; + dd = b; + lv = b->pair->vertex; + b = b->prev; + u = b->pair->vertex; + du = b->pair; - v = b->prev->pair->vertex; + v = b->prev->pair->vertex; - if( classify_point_seg(lv, rv, u) == ON_LEFT ) + if (classify_point_seg(lv, rv, u) == ON_LEFT) { - assert( v != u && "1: floating point precision error"); - while( v != lv && v != rv && in_circle(lv, rv, u, v) == INSIDE ) + assert(v != u && "1: floating point precision error"); + while (v != lv && v != rv && in_circle(lv, rv, u, v) == INSIDE) { - c = b->prev; - du = c->pair; + c = b->prev; + du = c->pair; del_remove_edge(b); - b = c; - u = du->vertex; - v = b->prev->pair->vertex; + b = c; + u = du->vertex; + v = b->prev->pair->vertex; } - assert( v != u && "1: floating point precision error"); - if( v != lv && v != rv && in_circle(lv, rv, u, v) == ON_CIRCLE ) + assert(v != u && "1: floating point precision error"); + if (v != lv && v != rv && in_circle(lv, rv, u, v) == ON_CIRCLE) { - du = du->next; + du = du->next; del_remove_edge(b); } - } else - du = dd; + } + else + du = dd; assert(du->pair); return du; } - /* -* validate a link -*/ + * validate a link + */ static auto del_valid_link(halfedge_t *b) -> halfedge_t * { - point2d_t *g, *g_p, *d, *d_p; - halfedge_t *gd, *dd, *new_gd, *new_dd; + point2d_t *g, *g_p, *d, *d_p; + halfedge_t *gd, *dd, *new_gd, *new_dd; - g = b->vertex; - gd = del_valid_left(b); - g_p = gd->vertex; + g = b->vertex; + gd = del_valid_left(b); + g_p = gd->vertex; assert(b->pair); - d = b->pair->vertex; - dd = del_valid_right(b); - d_p = dd->vertex; + d = b->pair->vertex; + dd = del_valid_right(b); + d_p = dd->vertex; assert(b->pair); - if( g != g_p && d != d_p ) + if (g != g_p && d != d_p) { - int a = in_circle(g, d, g_p, d_p); + int a = in_circle(g, d, g_p, d_p); - if( a != ON_CIRCLE ) + if (a != ON_CIRCLE) { - if( a == INSIDE ) + if (a == INSIDE) { // cppcheck-suppress unreadVariable - g_p = g; - gd = b; + g_p = g; + gd = b; } else { // cppcheck-suppress unreadVariable d_p = d; - dd = b->pair; + dd = b->pair; } } } /* create the 2 halfedges */ - new_gd = halfedge_alloc(); - new_dd = halfedge_alloc(); + new_gd = halfedge_alloc(); + new_dd = halfedge_alloc(); /* setup new_gd and new_dd */ - new_gd->vertex = gd->vertex; - new_gd->pair = new_dd; - new_gd->prev = gd; - new_gd->next = gd->next; - gd->next->prev = new_gd; - gd->next = new_gd; + new_gd->vertex = gd->vertex; + new_gd->pair = new_dd; + new_gd->prev = gd; + new_gd->next = gd->next; + gd->next->prev = new_gd; + gd->next = new_gd; - new_dd->vertex = dd->vertex; - new_dd->pair = new_gd; - new_dd->prev = dd->prev; - dd->prev->next = new_dd; - new_dd->next = dd; - dd->prev = new_dd; + new_dd->vertex = dd->vertex; + new_dd->pair = new_gd; + new_dd->prev = dd->prev; + dd->prev->next = new_dd; + new_dd->next = dd; + dd->prev = new_dd; return new_gd; } /* -* find the lower tangent between the two delaunay, going from left to right (returns the left half edge) -*/ + * find the lower tangent between the two delaunay, going from left to right (returns the left half edge) + */ static auto del_get_lower_tangent(delaunay_t *left, delaunay_t *right) -> halfedge_t * { - halfedge_t *right_d, *left_d, *new_ld, *new_rd; - int sl, sr; + halfedge_t *right_d, *left_d, *new_ld, *new_rd; + int sl, sr; - left_d = left->rightmost_he; - right_d = right->leftmost_he; + left_d = left->rightmost_he; + right_d = right->leftmost_he; - do { + do + { point2d_t *pl = left_d->prev->pair->vertex; point2d_t *pr = right_d->pair->vertex; - if( (sl = classify_point_seg(left_d->vertex, right_d->vertex, pl)) == ON_RIGHT ) { - left_d = left_d->prev->pair; + if ((sl = classify_point_seg(left_d->vertex, right_d->vertex, pl)) == ON_RIGHT) + { + left_d = left_d->prev->pair; } - if( (sr = classify_point_seg(left_d->vertex, right_d->vertex, pr)) == ON_RIGHT ) { - right_d = right_d->pair->next; + if ((sr = classify_point_seg(left_d->vertex, right_d->vertex, pr)) == ON_RIGHT) + { + right_d = right_d->pair->next; } - } while( sl == ON_RIGHT || sr == ON_RIGHT ); + } while (sl == ON_RIGHT || sr == ON_RIGHT); /* create the 2 halfedges */ - new_ld = halfedge_alloc(); - new_rd = halfedge_alloc(); + new_ld = halfedge_alloc(); + new_rd = halfedge_alloc(); /* setup new_gd and new_dd */ - new_ld->vertex = left_d->vertex; - new_ld->pair = new_rd; - new_ld->prev = left_d->prev; - left_d->prev->next = new_ld; - new_ld->next = left_d; - left_d->prev = new_ld; + new_ld->vertex = left_d->vertex; + new_ld->pair = new_rd; + new_ld->prev = left_d->prev; + left_d->prev->next = new_ld; + new_ld->next = left_d; + left_d->prev = new_ld; - new_rd->vertex = right_d->vertex; - new_rd->pair = new_ld; - new_rd->prev = right_d->prev; - right_d->prev->next = new_rd; - new_rd->next = right_d; - right_d->prev = new_rd; + new_rd->vertex = right_d->vertex; + new_rd->pair = new_ld; + new_rd->prev = right_d->prev; + right_d->prev->next = new_rd; + new_rd->next = right_d; + right_d->prev = new_rd; return new_ld; } /* -* link the 2 delaunay together -*/ -static void del_link( delaunay_t *result, delaunay_t *left, delaunay_t *right ) + * link the 2 delaunay together + */ +static void del_link(delaunay_t *result, delaunay_t *left, delaunay_t *right) { - point2d_t *u, *v, *ml, *mr; - halfedge_t *base; + point2d_t *u, *v, *ml, *mr; + halfedge_t *base; - assert( left->points == right->points ); + assert(left->points == right->points); /* save the most right point and the most left point */ - ml = left->leftmost_he->vertex; - mr = right->rightmost_he->vertex; + ml = left->leftmost_he->vertex; + mr = right->rightmost_he->vertex; - base = del_get_lower_tangent(left, right); + base = del_get_lower_tangent(left, right); - u = base->next->pair->vertex; - v = base->pair->prev->pair->vertex; + u = base->next->pair->vertex; + v = base->pair->prev->pair->vertex; - while( del_classify_point(base, u) == ON_LEFT || - del_classify_point(base, v) == ON_LEFT ) + while (del_classify_point(base, u) == ON_LEFT || del_classify_point(base, v) == ON_LEFT) { - base = del_valid_link(base); - u = base->next->pair->vertex; - v = base->pair->prev->pair->vertex; + base = del_valid_link(base); + u = base->next->pair->vertex; + v = base->pair->prev->pair->vertex; } - right->rightmost_he = mr->he; - left->leftmost_he = ml->he; + right->rightmost_he = mr->he; + left->leftmost_he = ml->he; /* TODO: this part is not needed, and can be optimized */ - while( del_classify_point( right->rightmost_he, right->rightmost_he->prev->pair->vertex ) == ON_RIGHT ) - right->rightmost_he = right->rightmost_he->prev; + while (del_classify_point(right->rightmost_he, right->rightmost_he->prev->pair->vertex) == ON_RIGHT) + right->rightmost_he = right->rightmost_he->prev; - while( del_classify_point( left->leftmost_he, left->leftmost_he->prev->pair->vertex ) == ON_RIGHT ) - left->leftmost_he = left->leftmost_he->prev; + while (del_classify_point(left->leftmost_he, left->leftmost_he->prev->pair->vertex) == ON_RIGHT) + left->leftmost_he = left->leftmost_he->prev; - result->leftmost_he = left->leftmost_he; - result->rightmost_he = right->rightmost_he; - result->points = left->points; - result->start_point = left->start_point; - result->end_point = right->end_point; + result->leftmost_he = left->leftmost_he; + result->rightmost_he = right->rightmost_he; + result->points = left->points; + result->start_point = left->start_point; + result->end_point = right->end_point; } /* -* divide and conquer delaunay -*/ -void del_divide_and_conquer( delaunay_t *del, int start, int end ); -void del_divide_and_conquer( delaunay_t *del, int start, int end ) + * divide and conquer delaunay + */ +void del_divide_and_conquer(delaunay_t *del, int start, int end); +void del_divide_and_conquer(delaunay_t *del, int start, int end) { - delaunay_t left, right; + delaunay_t left, right; - int n = (end - start + 1); + int n = (end - start + 1); - if( n > 3 ) + if (n > 3) { - int i = (n / 2) + (n & 1); - left.points = del->points; - right.points = del->points; - del_divide_and_conquer( &left, start, start + i - 1 ); - del_divide_and_conquer( &right, start + i, end ); - del_link( del, &left, &right ); - } else - if( n == 3 ) - del_init_tri( del, start ); - else - if( n == 2 ) - del_init_seg( del, start ); + int i = (n / 2) + (n & 1); + left.points = del->points; + right.points = del->points; + del_divide_and_conquer(&left, start, start + i - 1); + del_divide_and_conquer(&right, start + i, end); + del_link(del, &left, &right); + } + else if (n == 3) + del_init_tri(del, start); + else if (n == 2) + del_init_seg(del, start); } -static void build_halfedge_face( delaunay_t *del, halfedge_t *d ) +static void build_halfedge_face(delaunay_t *del, halfedge_t *d) { - halfedge_t *curr; + halfedge_t *curr; /* test if the halfedge has already a pointing face */ - if( d->face != nullptr ) + if (d->face != nullptr) return; - del->faces = (face_t*)realloc(del->faces, (del->num_faces + 1) * sizeof(face_t)); + del->faces = (face_t *)realloc(del->faces, (del->num_faces + 1) * sizeof(face_t)); - face_t *f = &(del->faces[del->num_faces]); - curr = d; - f->he = d; - f->num_verts = 0; - do { - curr->face = f; + face_t *f = &(del->faces[del->num_faces]); + curr = d; + f->he = d; + f->num_verts = 0; + do + { + curr->face = f; (f->num_verts)++; - curr = curr->pair->prev; - } while( curr != d ); + curr = curr->pair->prev; + } while (curr != d); (del->num_faces)++; -/* if( d->face.radius < 0.0 ) - { - d->face.p[0] = d->vertex; - d->face.p[1] = d->pair->vertex; - d->face.p[2] = d->pair->prev->pair->vertex; - - if( classify_point_seg( d->face.p[0], d->face.p[1], d->face.p[2] ) == ON_LEFT ) + /* if( d->face.radius < 0.0 ) { - compute_circle(d->face.p[0], d->face.p[1], d->face.p[2], &(d->face.cx), &(d->face.cy), &(d->face.radius)); + d->face.p[0] = d->vertex; + d->face.p[1] = d->pair->vertex; + d->face.p[2] = d->pair->prev->pair->vertex; + + if( classify_point_seg( d->face.p[0], d->face.p[1], d->face.p[2] ) == ON_LEFT ) + { + compute_circle(d->face.p[0], d->face.p[1], d->face.p[2], &(d->face.cx), &(d->face.cy), + &(d->face.radius)); + } } - } -*/ + */ } /* -* build the faces for all the halfedge -*/ -void del_build_faces( delaunay_t *del ); -void del_build_faces( delaunay_t *del ) + * build the faces for all the halfedge + */ +void del_build_faces(delaunay_t *del); +void del_build_faces(delaunay_t *del) { - quint32 i; - halfedge_t *curr; + quint32 i; + halfedge_t *curr; - del->num_faces = 0; - del->faces = nullptr; + del->num_faces = 0; + del->faces = nullptr; /* build external face first */ build_halfedge_face(del, del->rightmost_he->pair); - for( i = del->start_point; i <= del->end_point; i++ ) + for (i = del->start_point; i <= del->end_point; i++) { - curr = del->points[i]->he; + curr = del->points[i]->he; - do { - build_halfedge_face( del, curr ); - curr = curr->next; - } while( curr != del->points[i]->he ); + do + { + build_halfedge_face(del, curr); + curr = curr->next; + } while (curr != del->points[i]->he); } } /* -*/ + */ auto delaunay2d_from(del_point2d_t *points, quint32 num_points) -> delaunay2d_t * { - delaunay2d_t* res = nullptr; - delaunay_t del; - quint32 i; - quint32* faces = nullptr; + delaunay2d_t *res = nullptr; + delaunay_t del; + quint32 i; + quint32 *faces = nullptr; - del.num_faces = 0; //Warning using uninitialized value + del.num_faces = 0; // Warning using uninitialized value #if PREDICATE == EXACT_PREDICATE exactinit(); #endif /* allocate the points */ - del.points = (point2d_t**)malloc(num_points * sizeof(point2d_t*)); - assert( del.points != nullptr ); - memset(del.points, 0, num_points * sizeof(point2d_t*)); + del.points = (point2d_t **)malloc(num_points * sizeof(point2d_t *)); + assert(del.points != nullptr); + memset(del.points, 0, num_points * sizeof(point2d_t *)); /* copy the points */ - for( i = 0; i < num_points; i++ ) + for (i = 0; i < num_points; i++) { - del.points[i] = point_alloc(); - del.points[i]->idx = i; - del.points[i]->x = points[i].x; - del.points[i]->y = points[i].y; + del.points[i] = point_alloc(); + del.points[i]->idx = i; + del.points[i]->x = points[i].x; + del.points[i]->y = points[i].y; } - qsort(del.points, num_points, sizeof(point2d_t*), cmp_points); + qsort(del.points, num_points, sizeof(point2d_t *), cmp_points); - if( num_points >= 3 ) { + if (num_points >= 3) + { quint32 fbuff_size = 0; quint32 j = 0; - del_divide_and_conquer( &del, 0, static_cast(num_points - 1) ); - del_build_faces( &del ); + del_divide_and_conquer(&del, 0, static_cast(num_points - 1)); + del_build_faces(&del); - for( i = 0; i < del.num_faces; i++ ) - fbuff_size += del.faces[i].num_verts + 1; + for (i = 0; i < del.num_faces; i++) + fbuff_size += del.faces[i].num_verts + 1; - faces = (quint32*)malloc(sizeof(quint32) * fbuff_size); + faces = (quint32 *)malloc(sizeof(quint32) * fbuff_size); - for( i = 0; i < del.num_faces; i++ ) + for (i = 0; i < del.num_faces; i++) { - halfedge_t *curr; + halfedge_t *curr; - faces[j] = del.faces[i].num_verts; + faces[j] = del.faces[i].num_verts; j++; - curr = del.faces[i].he; - do { - faces[j] = curr->vertex->idx; + curr = del.faces[i].he; + do + { + faces[j] = curr->vertex->idx; j++; - curr = curr->pair->prev; - } while( curr != del.faces[i].he ); + curr = curr->pair->prev; + } while (curr != del.faces[i].he); } - del_free_halfedges( &del ); + del_free_halfedges(&del); free(del.faces); - for( i = 0; i < num_points; i++ ) + for (i = 0; i < num_points; i++) point_free(del.points[i]); free(del.points); } - res = (delaunay2d_t*)malloc(sizeof(delaunay2d_t)); - res->num_points = num_points; - res->points = (del_point2d_t*)malloc(sizeof(del_point2d_t) * num_points); + res = (delaunay2d_t *)malloc(sizeof(delaunay2d_t)); + res->num_points = num_points; + res->points = (del_point2d_t *)malloc(sizeof(del_point2d_t) * num_points); memcpy(res->points, points, sizeof(del_point2d_t) * num_points); - res->num_faces = del.num_faces; - res->faces = faces; + res->num_faces = del.num_faces; + res->faces = faces; return res; } -void delaunay2d_release(delaunay2d_t *del) { +void delaunay2d_release(delaunay2d_t *del) +{ free(del->faces); free(del->points); free(del); diff --git a/src/libs/vobj/predicates.cpp b/src/libs/vobj/predicates.cpp index f9704c617..8a530b4d6 100644 --- a/src/libs/vobj/predicates.cpp +++ b/src/libs/vobj/predicates.cpp @@ -107,10 +107,6 @@ #include -#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) -#include "../vmisc/diagnostic.h" -#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) - QT_WARNING_PUSH QT_WARNING_DISABLE_MSVC(4701) // cppcheck-suppress unknownMacro @@ -136,7 +132,7 @@ QT_WARNING_DISABLE_CLANG("-Wconditional-uninitialized") /* To try this out, write "#define INEXACT volatile" below. Normally, */ /* however, INEXACT should be defined to be nothing. ("#define INEXACT".) */ -#define INEXACT /* Nothing */ +#define INEXACT /* Nothing */ /* #define INEXACT volatile */ #define REALPRINT doubleprint @@ -150,10 +146,9 @@ QT_WARNING_DISABLE_CLANG("-Wconditional-uninitialized") /* which is disastrously slow. A faster way on IEEE machines might be to */ /* mask the appropriate bit, but that's difficult to do in C. */ -#define Absolute(a) ((a) >= 0.0 ? (a) : -(a)) +#define Absolute(a) ((a) >= 0.0 ? (a) : -(a)) /* #define Absolute(a) fabs(a) */ - /* Many of the operations are broken up into two pieces, a main part that */ /* performs an approximate operation, and a "tail" that computes the */ /* roundoff error of that operation. */ @@ -167,98 +162,98 @@ QT_WARNING_DISABLE_CLANG("-Wconditional-uninitialized") /* The input parameter `x' (or the highest numbered `x_' parameter) must */ /* also be declared `INEXACT'. */ -#define Fast_Two_Sum_Tail(a, b, x, y) \ - bvirt = x - a; \ - y = b - bvirt +#define Fast_Two_Sum_Tail(a, b, x, y) \ + bvirt = x - a; \ + y = b - bvirt -#define Fast_Two_Sum(a, b, x, y) \ - x = (qreal) (a + b); \ - Fast_Two_Sum_Tail(a, b, x, y) +#define Fast_Two_Sum(a, b, x, y) \ + x = (qreal)(a + b); \ + Fast_Two_Sum_Tail(a, b, x, y) -#define Two_Sum_Tail(a, b, x, y) \ - bvirt = (qreal) (x - a); \ - avirt = x - bvirt; \ - bround = b - bvirt; \ - around = a - avirt; \ - y = around + bround +#define Two_Sum_Tail(a, b, x, y) \ + bvirt = (qreal)(x - a); \ + avirt = x - bvirt; \ + bround = b - bvirt; \ + around = a - avirt; \ + y = around + bround -#define Two_Sum(a, b, x, y) \ - x = (qreal) (a + b); \ - Two_Sum_Tail(a, b, x, y) +#define Two_Sum(a, b, x, y) \ + x = (qreal)(a + b); \ + Two_Sum_Tail(a, b, x, y) -#define Two_Diff_Tail(a, b, x, y) \ - bvirt = (qreal) (a - x); \ - avirt = x + bvirt; \ - bround = bvirt - b; \ - around = a - avirt; \ - y = around + bround +#define Two_Diff_Tail(a, b, x, y) \ + bvirt = (qreal)(a - x); \ + avirt = x + bvirt; \ + bround = bvirt - b; \ + around = a - avirt; \ + y = around + bround -#define Two_Diff(a, b, x, y) \ - x = (qreal) (a - b); \ - Two_Diff_Tail(a, b, x, y) +#define Two_Diff(a, b, x, y) \ + x = (qreal)(a - b); \ + Two_Diff_Tail(a, b, x, y) -#define Split(a, ahi, alo) \ - c = (qreal) (splitter * a); \ - abig = (qreal) (c - a); \ - ahi = c - abig; \ - alo = a - ahi +#define Split(a, ahi, alo) \ + c = (qreal)(splitter * a); \ + abig = (qreal)(c - a); \ + ahi = c - abig; \ + alo = a - ahi -#define Two_Product_Tail(a, b, x, y) \ - Split(a, ahi, alo); \ - Split(b, bhi, blo); \ - err1 = x - (ahi * bhi); \ - err2 = err1 - (alo * bhi); \ - err3 = err2 - (ahi * blo); \ - y = (alo * blo) - err3 +#define Two_Product_Tail(a, b, x, y) \ + Split(a, ahi, alo); \ + Split(b, bhi, blo); \ + err1 = x - (ahi * bhi); \ + err2 = err1 - (alo * bhi); \ + err3 = err2 - (ahi * blo); \ + y = (alo * blo) - err3 -#define Two_Product(a, b, x, y) \ - x = (qreal) (a * b); \ - Two_Product_Tail(a, b, x, y) +#define Two_Product(a, b, x, y) \ + x = (qreal)(a * b); \ + Two_Product_Tail(a, b, x, y) /* Two_Product_Presplit() is Two_Product() where one of the inputs has */ /* already been split. Avoids redundant splitting. */ -#define Two_Product_Presplit(a, b, bhi, blo, x, y) \ - x = (qreal) (a * b); \ - Split(a, ahi, alo); \ - err1 = x - (ahi * bhi); \ - err2 = err1 - (alo * bhi); \ - err3 = err2 - (ahi * blo); \ - y = (alo * blo) - err3 +#define Two_Product_Presplit(a, b, bhi, blo, x, y) \ + x = (qreal)(a * b); \ + Split(a, ahi, alo); \ + err1 = x - (ahi * bhi); \ + err2 = err1 - (alo * bhi); \ + err3 = err2 - (ahi * blo); \ + y = (alo * blo) - err3 /* Square() can be done more quickly than Two_Product(). */ -#define Square_Tail(a, x, y) \ - Split(a, ahi, alo); \ - err1 = x - (ahi * ahi); \ - err3 = err1 - ((ahi + ahi) * alo); \ - y = (alo * alo) - err3 +#define Square_Tail(a, x, y) \ + Split(a, ahi, alo); \ + err1 = x - (ahi * ahi); \ + err3 = err1 - ((ahi + ahi) * alo); \ + y = (alo * alo) - err3 -#define Square(a, x, y) \ - x = (qreal) (a * a); \ - Square_Tail(a, x, y) +#define Square(a, x, y) \ + x = (qreal)(a * a); \ + Square_Tail(a, x, y) /* Macros for summing expansions of various fixed lengths. These are all */ /* unrolled versions of Expansion_Sum(). */ -#define Two_One_Sum(a1, a0, b, x2, x1, x0) \ - Two_Sum(a0, b , _i, x0); \ - Two_Sum(a1, _i, x2, x1) +#define Two_One_Sum(a1, a0, b, x2, x1, x0) \ + Two_Sum(a0, b, _i, x0); \ + Two_Sum(a1, _i, x2, x1) -#define Two_One_Diff(a1, a0, b, x2, x1, x0) \ - Two_Diff(a0, b , _i, x0); \ - Two_Sum( a1, _i, x2, x1) +#define Two_One_Diff(a1, a0, b, x2, x1, x0) \ + Two_Diff(a0, b, _i, x0); \ + Two_Sum(a1, _i, x2, x1) -#define Two_Two_Sum(a1, a0, b1, b0, x3, x2, x1, x0) \ - Two_One_Sum(a1, a0, b0, _j, _0, x0); \ - Two_One_Sum(_j, _0, b1, x3, x2, x1) +#define Two_Two_Sum(a1, a0, b1, b0, x3, x2, x1, x0) \ + Two_One_Sum(a1, a0, b0, _j, _0, x0); \ + Two_One_Sum(_j, _0, b1, x3, x2, x1) -#define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0) \ - Two_One_Diff(a1, a0, b0, _j, _0, x0); \ - Two_One_Diff(_j, _0, b1, x3, x2, x1) +#define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0) \ + Two_One_Diff(a1, a0, b0, _j, _0, x0); \ + Two_One_Diff(_j, _0, b1, x3, x2, x1) -qreal splitter; /* = 2^ceiling(p / 2) + 1. Used to split floats in half. */ -qreal epsilon; /* = 2^(-p). Used to estimate roundoff errors. */ +qreal splitter; /* = 2^ceiling(p / 2) + 1. Used to split floats in half. */ +qreal epsilon; /* = 2^(-p). Used to estimate roundoff errors. */ /* A set of coefficients used to calculate maximum roundoff errors. */ qreal resulterrbound; qreal ccwerrboundA, ccwerrboundB, ccwerrboundC; @@ -463,8 +458,9 @@ auto scale_expansion_zeroelim(int elen, qreal *e, qreal b, qreal *h) -> int /* e Split(b, bhi, blo); Two_Product_Presplit(e[0], b, bhi, blo, Q, hh); hindex = 0; - if (hh != 0) { - h[hindex++] = hh; + if (hh != 0) + { + h[hindex++] = hh; } for (eindex = 1; eindex < elen; eindex++) { @@ -579,12 +575,12 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) INEXACT qreal _i, _j; qreal _0; - adx = (qreal) (pa[0] - pd[0]); - bdx = (qreal) (pb[0] - pd[0]); - cdx = (qreal) (pc[0] - pd[0]); - ady = (qreal) (pa[1] - pd[1]); - bdy = (qreal) (pb[1] - pd[1]); - cdy = (qreal) (pc[1] - pd[1]); + adx = (qreal)(pa[0] - pd[0]); + bdx = (qreal)(pb[0] - pd[0]); + cdx = (qreal)(pc[0] - pd[0]); + ady = (qreal)(pa[1] - pd[1]); + bdy = (qreal)(pb[1] - pd[1]); + cdy = (qreal)(pc[1] - pd[1]); Two_Product(bdx, cdy, bdxcdy1, bdxcdy0); Two_Product(cdx, bdy, cdxbdy1, cdxbdy0); @@ -632,19 +628,19 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) Two_Diff_Tail(pb[1], pd[1], bdy, bdytail); Two_Diff_Tail(pc[0], pd[0], cdx, cdxtail); Two_Diff_Tail(pc[1], pd[1], cdy, cdytail); - if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0) - && (adytail == 0.0) && (bdytail == 0.0) && (cdytail == 0.0)) + if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0) && (adytail == 0.0) && (bdytail == 0.0) && + (cdytail == 0.0)) { return det; } errbound = iccerrboundC * permanent + resulterrbound * Absolute(det); - det += ((adx * adx + ady * ady) * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) - + 2.0 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx)) - + ((bdx * bdx + bdy * bdy) * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) - + 2.0 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx)) - + ((cdx * cdx + cdy * cdy) * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) - + 2.0 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx)); + det += ((adx * adx + ady * ady) * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) + + 2.0 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx)) + + ((bdx * bdx + bdy * bdy) * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) + + 2.0 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx)) + + ((cdx * cdx + cdy * cdy) * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) + + 2.0 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx)); if ((det >= errbound) || (-det >= errbound)) { return det; @@ -689,7 +685,9 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; } if (adytail != 0.0) { @@ -705,7 +703,9 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; } if (bdxtail != 0.0) { @@ -721,7 +721,9 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; } if (bdytail != 0.0) { @@ -737,7 +739,9 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; } if (cdxtail != 0.0) { @@ -750,13 +754,12 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) cxtaalen = scale_expansion_zeroelim(4, aa, cdxtail, cxtaa); temp16clen = scale_expansion_zeroelim(cxtaalen, cxtaa, -bdy, temp16c); - temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, - temp16blen, temp16b, temp32a); - temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, - temp32alen, temp32a, temp48); - finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, - temp48, finother); - finswap = finnow; finnow = finother; finother = finswap; + temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); + temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); + finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); + finswap = finnow; + finnow = finother; + finother = finswap; } if (cdytail != 0.0) { @@ -772,7 +775,9 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; } if ((adxtail != 0.0) || (adytail != 0.0)) @@ -812,20 +817,26 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) temp32alen = scale_expansion_zeroelim(axtbctlen, axtbct, 2.0 * adx, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; if (bdytail != 0.0) { temp8len = scale_expansion_zeroelim(4, cc, adxtail, temp8); temp16alen = scale_expansion_zeroelim(temp8len, temp8, bdytail, temp16a); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; } if (cdytail != 0.0) { temp8len = scale_expansion_zeroelim(4, bb, -adxtail, temp8); temp16alen = scale_expansion_zeroelim(temp8len, temp8, cdytail, temp16a); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; } temp32alen = scale_expansion_zeroelim(axtbctlen, axtbct, adxtail, temp32a); @@ -835,7 +846,9 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; } if (adytail != 0.0) { @@ -844,8 +857,9 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) temp32alen = scale_expansion_zeroelim(aytbctlen, aytbct, 2.0 * ady, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); - finswap = finnow; finnow = finother; finother = finswap; - + finswap = finnow; + finnow = finother; + finother = finswap; temp32alen = scale_expansion_zeroelim(aytbctlen, aytbct, adytail, temp32a); aytbcttlen = scale_expansion_zeroelim(bcttlen, bctt, adytail, aytbctt); @@ -854,7 +868,9 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; } } if ((bdxtail != 0.0) || (bdytail != 0.0)) @@ -923,7 +939,9 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; } if (bdytail != 0.0) { @@ -936,7 +954,6 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) finnow = finother; finother = finswap; - temp32alen = scale_expansion_zeroelim(bytcatlen, bytcat, bdytail, temp32a); bytcattlen = scale_expansion_zeroelim(cattlen, catt, bdytail, bytcatt); temp16alen = scale_expansion_zeroelim(bytcattlen, bytcatt, 2.0 * bdy, temp16a); @@ -1003,7 +1020,9 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) temp8len = scale_expansion_zeroelim(4, aa, -cdxtail, temp8); temp16alen = scale_expansion_zeroelim(temp8len, temp8, bdytail, temp16a); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; } temp32alen = scale_expansion_zeroelim(cxtabtlen, cxtabt, cdxtail, temp32a); @@ -1028,7 +1047,6 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) finnow = finother; finother = finswap; - temp32alen = scale_expansion_zeroelim(cytabtlen, cytabt, cdytail, temp32a); cytabttlen = scale_expansion_zeroelim(abttlen, abtt, cdytail, cytabtt); temp16alen = scale_expansion_zeroelim(cytabttlen, cytabtt, 2.0 * cdy, temp16a); @@ -1036,7 +1054,9 @@ auto incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent) temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother); - finswap = finnow; finnow = finother; finother = finswap; + finswap = finnow; + finnow = finother; + finother = finswap; } } @@ -1070,13 +1090,10 @@ auto incircle(qreal *pa, qreal *pb, qreal *pc, qreal *pd) -> qreal bdxady = bdx * ady; clift = cdx * cdx + cdy * cdy; - det = alift * (bdxcdy - cdxbdy) - + blift * (cdxady - adxcdy) - + clift * (adxbdy - bdxady); + det = alift * (bdxcdy - cdxbdy) + blift * (cdxady - adxcdy) + clift * (adxbdy - bdxady); - permanent = (Absolute(bdxcdy) + Absolute(cdxbdy)) * alift - + (Absolute(cdxady) + Absolute(adxcdy)) * blift - + (Absolute(adxbdy) + Absolute(bdxady)) * clift; + permanent = (Absolute(bdxcdy) + Absolute(cdxbdy)) * alift + (Absolute(cdxady) + Absolute(adxcdy)) * blift + + (Absolute(adxbdy) + Absolute(bdxady)) * clift; errbound = iccerrboundA * permanent; if ((det > errbound) || (-det > errbound)) { diff --git a/src/libs/vobj/vobjpaintdevice.cpp b/src/libs/vobj/vobjpaintdevice.cpp index d9a794c16..35b0c7928 100644 --- a/src/libs/vobj/vobjpaintdevice.cpp +++ b/src/libs/vobj/vobjpaintdevice.cpp @@ -37,7 +37,10 @@ //--------------------------------------------------------------------------------------------------------------------- VObjPaintDevice::VObjPaintDevice() - :QPaintDevice(), engine(new VObjEngine()), fileName(), owns_iodevice(1) + : QPaintDevice(), + engine(new VObjEngine()), + fileName(), + owns_iodevice(1) { owns_iodevice = static_cast(false); } diff --git a/src/libs/vpatterndb/vpassmark.cpp b/src/libs/vpatterndb/vpassmark.cpp index 43e174ab8..ea9bf2539 100644 --- a/src/libs/vpatterndb/vpassmark.cpp +++ b/src/libs/vpatterndb/vpassmark.cpp @@ -61,11 +61,11 @@ auto GetSeamPassmarkSAPoint(const VPiecePassmarkData &passmarkData, const QVecto if (needRollback && not seamAllowance.isEmpty()) { ekvPoints.clear(); - ekvPoints += VRawSAPoint(seamAllowance.at(seamAllowance.size()-1)); + ekvPoints += VRawSAPoint(seamAllowance.at(seamAllowance.size() - 1)); } if (ekvPoints.isEmpty()) - { // Just in case + { // Just in case return PassmarkStatus::Error; // Something wrong } @@ -80,9 +80,9 @@ auto PointsToSegments(const QVector &points) -> QVector if (points.size() >= 2) { lines.reserve(points.size() - 1); - for (int i=0; i < points.size()-1; ++i) + for (int i = 0; i < points.size() - 1; ++i) { - QLineF segment = QLineF(points.at(i), points.at(i+1)); + QLineF segment = QLineF(points.at(i), points.at(i + 1)); if (segment.length() > 0) { lines.append(segment); @@ -604,15 +604,14 @@ auto VPiecePassmarkData::toJson() const -> QJsonObject //--------------------------------------------------------------------------------------------------------------------- VPassmark::VPassmark(const VPiecePassmarkData &data) - : m_data(data), - m_null(false) + : m_data(data), + m_null(false) { // Correct distorsion - if (VGObject::IsPointOnLineSegment(m_data.passmarkSAPoint, m_data.previousSAPoint, - m_data.nextSAPoint)) + if (VGObject::IsPointOnLineSegment(m_data.passmarkSAPoint, m_data.previousSAPoint, m_data.nextSAPoint)) { - const QPointF p = VGObject::CorrectDistortion(m_data.passmarkSAPoint, m_data.previousSAPoint, - m_data.nextSAPoint); + const QPointF p = + VGObject::CorrectDistortion(m_data.passmarkSAPoint, m_data.previousSAPoint, m_data.nextSAPoint); m_data.passmarkSAPoint.setX(p.x()); m_data.passmarkSAPoint.setY(p.y()); } @@ -630,16 +629,14 @@ auto VPassmark::FullPassmark(const VPiece &piece, const VContainer *data) const { QVector lines; lines += SAPassmark(piece, data, PassmarkSide::All); - if (VAbstractApplication::VApp()->Settings()->IsDoublePassmark() - && (VAbstractApplication::VApp()->Settings()->IsPieceShowMainPath() || not piece.IsHideMainPath()) - && m_data.isMainPathNode - && m_data.passmarkAngleType != PassmarkAngleType::Intersection - && m_data.passmarkAngleType != PassmarkAngleType::IntersectionOnlyLeft - && m_data.passmarkAngleType != PassmarkAngleType::IntersectionOnlyRight - && m_data.passmarkAngleType != PassmarkAngleType::Intersection2 - && m_data.passmarkAngleType != PassmarkAngleType::Intersection2OnlyLeft - && m_data.passmarkAngleType != PassmarkAngleType::Intersection2OnlyRight - && m_data.isShowSecondPassmark) + if (VAbstractApplication::VApp()->Settings()->IsDoublePassmark() && + (VAbstractApplication::VApp()->Settings()->IsPieceShowMainPath() || not piece.IsHideMainPath()) && + m_data.isMainPathNode && m_data.passmarkAngleType != PassmarkAngleType::Intersection && + m_data.passmarkAngleType != PassmarkAngleType::IntersectionOnlyLeft && + m_data.passmarkAngleType != PassmarkAngleType::IntersectionOnlyRight && + m_data.passmarkAngleType != PassmarkAngleType::Intersection2 && + m_data.passmarkAngleType != PassmarkAngleType::Intersection2OnlyLeft && + m_data.passmarkAngleType != PassmarkAngleType::Intersection2OnlyRight && m_data.isShowSecondPassmark) { lines += BuiltInSAPassmark(piece, data); } @@ -713,7 +710,7 @@ auto VPassmark::Data() const -> VPiecePassmarkData auto VPassmark::FindIntersection(const QLineF &line, const QVector &seamAllowance) -> QLineF { QLineF testLine = line; - testLine.setLength(testLine.length()*10); + testLine.setLength(testLine.length() * 10); QVector intersections = VAbstractCurve::CurveIntersectLine(seamAllowance, testLine); if (not intersections.isEmpty()) { @@ -940,10 +937,10 @@ auto VPassmark::BuiltInSAPassmarkBaseLine(const VPiece &piece) const -> QVector< { const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2' with built " "in seam allowance. User must manually provide length.") - .arg(m_data.nodeName, m_data.pieceName); + .arg(m_data.nodeName, m_data.pieceName); VAbstractApplication::VApp()->IsPedantic() - ? throw VExceptionInvalidNotch(errorMsg) - : qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + ? throw VExceptionInvalidNotch(errorMsg) + : qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; return {}; } } @@ -952,7 +949,7 @@ auto VPassmark::BuiltInSAPassmarkBaseLine(const VPiece &piece) const -> QVector< QLineF edge1 = QLineF(m_data.passmarkSAPoint, m_data.previousSAPoint); QLineF edge2 = QLineF(m_data.passmarkSAPoint, m_data.nextSAPoint); - edge1.setAngle(edge1.angle() + edge1.angleTo(edge2)/2.); + edge1.setAngle(edge1.angle() + edge1.angleTo(edge2) / 2.); edge1.setLength(length); return {edge1}; @@ -994,9 +991,11 @@ auto VPassmark::SAPassmarkBaseLine(const QVector &seamAllowance, const if (rotatedSeamAllowance.size() < 2) { const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'. Seam allowance is " - "empty.").arg(m_data.nodeName, m_data.pieceName); - VAbstractApplication::VApp()->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + "empty.") + .arg(m_data.nodeName, m_data.pieceName); + VAbstractApplication::VApp()->IsPedantic() + ? throw VExceptionInvalidNotch(errorMsg) + : qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; return {}; // Something wrong } @@ -1007,12 +1006,13 @@ auto VPassmark::SAPassmarkBaseLine(const QVector &seamAllowance, const const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'. Cannot find " "position for a notch.") .arg(m_data.nodeName, m_data.pieceName); - VAbstractApplication::VApp()->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + VAbstractApplication::VApp()->IsPedantic() + ? throw VExceptionInvalidNotch(errorMsg) + : qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; return {}; // Something wrong } - const QVector& path = (m_data.passmarkAngleType == PassmarkAngleType::Straightforward || + const QVector &path = (m_data.passmarkAngleType == PassmarkAngleType::Straightforward || m_data.passmarkAngleType == PassmarkAngleType::Bisector) ? rotatedSeamAllowance : seamAllowance; @@ -1022,8 +1022,9 @@ auto VPassmark::SAPassmarkBaseLine(const QVector &seamAllowance, const const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'. Unable to fix a " "notch position.") .arg(m_data.nodeName, m_data.pieceName); - VAbstractApplication::VApp()->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : - qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + VAbstractApplication::VApp()->IsPedantic() + ? throw VExceptionInvalidNotch(errorMsg) + : qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; } if (m_data.passmarkAngleType == PassmarkAngleType::Straightforward) diff --git a/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.h b/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.h index 74f4fe9a0..d1551292c 100644 --- a/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.h +++ b/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.h @@ -21,7 +21,6 @@ #ifndef VFILEPROPERTYEDITOR_H #define VFILEPROPERTYEDITOR_H - #include #include #include @@ -49,10 +48,9 @@ class VPROPERTYEXPLORERSHARED_EXPORT VFileEditWidget : public QWidget Q_OBJECT // NOLINT public: - explicit VFileEditWidget(QWidget* parent, bool is_directory = false); + explicit VFileEditWidget(QWidget *parent, bool is_directory = false); virtual ~VFileEditWidget() override; - //! This function returns the file currently set to this editor auto getFile() const -> QString; @@ -67,12 +65,11 @@ signals: //! This signal is emitted when the user changed the curret file. //! Actions triggering this signal are either using the file dialog //! to select a new file or changing the file path in the line edit. - void dataChangedByUser(const QString &getFile, VFileEditWidget* editor); + void dataChangedByUser(const QString &getFile, VFileEditWidget *editor); //! This signal is emitted whenever dataChangedByUser() gets emmitted //! and is connected to the delegate's commitData() signal - void commitData(QWidget* editor); - + void commitData(QWidget *editor); public slots: //! Sets the current file, does not check if it is valid @@ -84,7 +81,7 @@ public slots: //! Sets a filter for the file field //! \param dialog_filter The filter used for the File Dialog //! \param filter_list The list of file endings. The filters are being checked using regular expressions - void setFilter(const QString& dialog_filter = QString(), const QStringList& filter_list = QStringList()); + void setFilter(const QString &dialog_filter = QString(), const QStringList &filter_list = QStringList()); //! Sets whether the property stores a directory or a file void setDirectory(bool dir); @@ -94,10 +91,10 @@ private slots: void onToolButtonClicked(); protected: - virtual void dragEnterEvent(QDragEnterEvent* event) override; - virtual void dragMoveEvent(QDragMoveEvent* event) override; - virtual void dragLeaveEvent(QDragLeaveEvent* event) override; - virtual void dropEvent(QDropEvent* event) override; + virtual void dragEnterEvent(QDragEnterEvent *event) override; + virtual void dragMoveEvent(QDragMoveEvent *event) override; + virtual void dragLeaveEvent(QDragLeaveEvent *event) override; + virtual void dropEvent(QDropEvent *event) override; //! This function checks the mime data, if it is compatible with the filters virtual auto checkMimeData(const QMimeData *data, QString &file) const -> bool; @@ -106,8 +103,8 @@ protected: virtual auto checkFileFilter(const QString &file) const -> bool; QString CurrentFilePath; - QToolButton* ToolButton; - QLineEdit* FileLineEdit; + QToolButton *ToolButton; + QLineEdit *FileLineEdit; QString FileDialogFilter; QStringList FilterList; @@ -120,6 +117,6 @@ private: QT_WARNING_POP -} +} // namespace VPE #endif // VFILEPROPERTYEDITOR_H diff --git a/src/libs/vpropertyexplorer/vabstractpropertyfactory.h b/src/libs/vpropertyexplorer/vabstractpropertyfactory.h index c5eaf8e37..541e526bf 100644 --- a/src/libs/vpropertyexplorer/vabstractpropertyfactory.h +++ b/src/libs/vpropertyexplorer/vabstractpropertyfactory.h @@ -50,6 +50,6 @@ public: QT_WARNING_POP -} +} // namespace VPE #endif // VABSTRACTPROPERTYFACTORY_H diff --git a/src/libs/vpropertyexplorer/vpropertyformview_p.h b/src/libs/vpropertyexplorer/vpropertyformview_p.h index e08522d45..b4c0e98c6 100644 --- a/src/libs/vpropertyexplorer/vpropertyformview_p.h +++ b/src/libs/vpropertyexplorer/vpropertyformview_p.h @@ -38,10 +38,10 @@ class VPropertyFormViewPrivate : public VPropertyFormWidgetPrivate { public: //! The current property model - VPropertyModel* Model; + VPropertyModel *Model; //! The currently used property set - VPropertySet* PropertySet; + VPropertySet *PropertySet; //! Determines whether the widget needs to be rebuild bool NeedsRebuild; @@ -50,19 +50,31 @@ public: bool IgnoreDataChangedSignal; VPropertyFormViewPrivate() - : VPropertyFormWidgetPrivate(), Model(nullptr), PropertySet(nullptr), NeedsRebuild(false), - IgnoreDataChangedSignal(false) - {} + : VPropertyFormWidgetPrivate(), + Model(nullptr), + PropertySet(nullptr), + NeedsRebuild(false), + IgnoreDataChangedSignal(false) + { + } - explicit VPropertyFormViewPrivate(VPropertyModel* prop_model) - : VPropertyFormWidgetPrivate(), Model(prop_model), PropertySet(nullptr), NeedsRebuild(false), - IgnoreDataChangedSignal(false) - {} + explicit VPropertyFormViewPrivate(VPropertyModel *prop_model) + : VPropertyFormWidgetPrivate(), + Model(prop_model), + PropertySet(nullptr), + NeedsRebuild(false), + IgnoreDataChangedSignal(false) + { + } - explicit VPropertyFormViewPrivate(VPropertySet* prop_set) - : VPropertyFormWidgetPrivate(), Model(nullptr), PropertySet(prop_set), NeedsRebuild(false), - IgnoreDataChangedSignal(false) - {} + explicit VPropertyFormViewPrivate(VPropertySet *prop_set) + : VPropertyFormWidgetPrivate(), + Model(nullptr), + PropertySet(prop_set), + NeedsRebuild(false), + IgnoreDataChangedSignal(false) + { + } virtual ~VPropertyFormViewPrivate() override {} @@ -72,6 +84,6 @@ private: QT_WARNING_POP -} +} // namespace VPE #endif // VPROPERTYFORMVIEW_P_H diff --git a/src/libs/vpropertyexplorer/vpropertyformwidget_p.h b/src/libs/vpropertyexplorer/vpropertyformwidget_p.h index e7dced946..9b9e1e8fc 100644 --- a/src/libs/vpropertyexplorer/vpropertyformwidget_p.h +++ b/src/libs/vpropertyexplorer/vpropertyformwidget_p.h @@ -23,8 +23,8 @@ // ONLY INCLUDE THIS IN .CPP FILES -#include #include "vproperty.h" +#include #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/diagnostic.h" #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) @@ -41,16 +41,28 @@ public: //! Stores either another VPropertyFormWidget (then Editor is null) or an editor widget (then FormWidget is null) struct SEditorWidget { - SEditorWidget() : FormWidget(nullptr), Editor(nullptr) {} - explicit SEditorWidget(VPropertyFormWidget* form_widget) : FormWidget(form_widget), Editor(nullptr) {} - explicit SEditorWidget(QWidget* editor_widget) : FormWidget(nullptr), Editor(editor_widget) {} + SEditorWidget() + : FormWidget(nullptr), + Editor(nullptr) + { + } + explicit SEditorWidget(VPropertyFormWidget *form_widget) + : FormWidget(form_widget), + Editor(nullptr) + { + } + explicit SEditorWidget(QWidget *editor_widget) + : FormWidget(nullptr), + Editor(editor_widget) + { + } - VPropertyFormWidget* FormWidget; - QWidget* Editor; + VPropertyFormWidget *FormWidget; + QWidget *Editor; }; //! The root property to use - QList Properties; + QList Properties; //! Binds the properties to their editors QList EditorWidgets; @@ -61,19 +73,25 @@ public: //! Default constructor VPropertyFormWidgetPrivate() - : Properties(QList()), EditorWidgets(QList()), UpdateEditors(true) - {} + : Properties(QList()), + EditorWidgets(QList()), + UpdateEditors(true) + { + } //! Constructor - explicit VPropertyFormWidgetPrivate(const QList& properties) - : Properties(properties), EditorWidgets(QList()), UpdateEditors(true) - {} + explicit VPropertyFormWidgetPrivate(const QList &properties) + : Properties(properties), + EditorWidgets(QList()), + UpdateEditors(true) + { + } virtual ~VPropertyFormWidgetPrivate() {} }; QT_WARNING_POP -} +} // namespace VPE #endif // VPROPERTYFORMWIDGET_P_H diff --git a/src/libs/vpropertyexplorer/vwidgetproperty_p.h b/src/libs/vpropertyexplorer/vwidgetproperty_p.h index 8e41ca4da..402e49575 100644 --- a/src/libs/vpropertyexplorer/vwidgetproperty_p.h +++ b/src/libs/vpropertyexplorer/vwidgetproperty_p.h @@ -44,18 +44,24 @@ public: QPointer Widget; //! Constructor passing name and type - VWidgetPropertyPrivate(const QString& name, + VWidgetPropertyPrivate(const QString &name, #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QMetaType::Type type, #else QVariant::Type type, #endif - QWidget* widget = nullptr) - : VPropertyPrivate(name, type), Widget(widget) {} + QWidget *widget = nullptr) + : VPropertyPrivate(name, type), + Widget(widget) + { + } //! Constructor VWidgetPropertyPrivate() - : VPropertyPrivate(), Widget(nullptr) {} + : VPropertyPrivate(), + Widget(nullptr) + { + } //! Destructor virtual ~VWidgetPropertyPrivate() override @@ -69,6 +75,6 @@ public: QT_WARNING_POP -} // namespace VPE +} // namespace VPE #endif // VWIDGETPROPERTY_P_H diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp index 3c23384e5..eaa1e2cee 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp @@ -28,8 +28,6 @@ #include "vtoolflippingbyaxis.h" -#include -#include #include #include #include @@ -37,28 +35,27 @@ #include #include #include +#include #include +#include -#include "../../../../dialogs/tools/dialogtool.h" #include "../../../../dialogs/tools/dialogflippingbyaxis.h" +#include "../../../../dialogs/tools/dialogtool.h" #include "../../../../visualization/line/operation/vistoolflippingbyaxis.h" #include "../../../../visualization/visualization.h" -#include "../vgeometry/vpointf.h" -#include "../vpatterndb/vtranslatevars.h" -#include "../vmisc/vabstractapplication.h" -#include "../vmisc/vcommonsettings.h" -#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) -#include "../vmisc/diagnostic.h" -#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) -#include "../vpatterndb/vcontainer.h" -#include "../vpatterndb/vformula.h" -#include "../ifc/ifcdef.h" -#include "../ifc/exception/vexception.h" -#include "../vwidgets/vabstractsimple.h" -#include "../vwidgets/vmaingraphicsscene.h" #include "../../../vabstracttool.h" #include "../../../vdatatool.h" #include "../../vdrawtool.h" +#include "../ifc/exception/vexception.h" +#include "../ifc/ifcdef.h" +#include "../vgeometry/vpointf.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vcommonsettings.h" +#include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/vformula.h" +#include "../vpatterndb/vtranslatevars.h" +#include "../vwidgets/vabstractsimple.h" +#include "../vwidgets/vmaingraphicsscene.h" template class QSharedPointer; @@ -102,7 +99,7 @@ auto VToolFlippingByAxis::Create(const QPointer &dialog, VMainGraphi initData.typeCreation = Source::FromGui; initData.notes = dialogTool->GetNotes(); - VToolFlippingByAxis* operation = Create(initData); + VToolFlippingByAxis *operation = Create(initData); if (operation != nullptr) { operation->m_dialog = dialog; @@ -191,10 +188,10 @@ void VToolFlippingByAxis::ShowContextMenu(QGraphicsSceneContextMenuEvent *event, { ContextMenu(event, id); } - catch(const VExceptionToolWasDeleted &e) + catch (const VExceptionToolWasDeleted &e) { Q_UNUSED(e) - return;//Leave this method immediately!!! + return; // Leave this method immediately!!! } } @@ -229,7 +226,7 @@ void VToolFlippingByAxis::SaveDialog(QDomElement &domElement, QList &ol doc->SetAttribute(domElement, AttrAxisType, QString().setNum(static_cast(dialogTool->GetAxisType()))); doc->SetAttribute(domElement, AttrSuffix, dialogTool->GetSuffix()); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, dialogTool->GetNotes(), - [](const QString ¬es) noexcept {return notes.isEmpty();}); + [](const QString ¬es) noexcept { return notes.isEmpty(); }); source = dialogTool->GetSourceObjects(); SaveSourceDestination(domElement); @@ -262,15 +259,15 @@ auto VToolFlippingByAxis::MakeToolTip() const -> QString { return QStringLiteral(" %1: %2 " "%3") - .arg(tr("Origin point"), OriginPointName()) // 1, 2 - .arg(VisibilityGroupToolTip()); // 3 + .arg(tr("Origin point"), OriginPointName()) // 1, 2 + .arg(VisibilityGroupToolTip()); // 3 } //--------------------------------------------------------------------------------------------------------------------- VToolFlippingByAxis::VToolFlippingByAxis(const VToolFlippingByAxisInitData &initData, QGraphicsItem *parent) - : VAbstractFlipping(initData, parent), - m_originPointId(initData.originPointId), - m_axisType(initData.axisType) + : VAbstractFlipping(initData, parent), + m_originPointId(initData.originPointId), + m_axisType(initData.axisType) { InitOperatedObjects(); ToolCreation(initData.typeCreation); diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp index 232a6623b..eab756759 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp @@ -28,8 +28,6 @@ #include "vtoolflippingbyline.h" -#include -#include #include #include #include @@ -37,14 +35,20 @@ #include #include #include +#include #include +#include -#include "../../../../dialogs/tools/dialogtool.h" #include "../../../../dialogs/tools/dialogflippingbyline.h" +#include "../../../../dialogs/tools/dialogtool.h" #include "../../../../visualization/line/operation/vistoolflippingbyline.h" #include "../../../../visualization/visualization.h" +#include "../../../vabstracttool.h" +#include "../../../vdatatool.h" +#include "../../vdrawtool.h" +#include "../ifc/exception/vexception.h" +#include "../ifc/ifcdef.h" #include "../vgeometry/vpointf.h" -#include "../vpatterndb/vtranslatevars.h" #include "../vmisc/vabstractapplication.h" #include "../vmisc/vcommonsettings.h" #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) @@ -52,13 +56,9 @@ #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vformula.h" -#include "../ifc/ifcdef.h" -#include "../ifc/exception/vexception.h" +#include "../vpatterndb/vtranslatevars.h" #include "../vwidgets/vabstractsimple.h" #include "../vwidgets/vmaingraphicsscene.h" -#include "../../../vabstracttool.h" -#include "../../../vdatatool.h" -#include "../../vdrawtool.h" template class QSharedPointer; @@ -102,7 +102,7 @@ auto VToolFlippingByLine::Create(const QPointer &dialog, VMainGraphi initData.typeCreation = Source::FromGui; initData.notes = dialogTool->GetNotes(); - VToolFlippingByLine* operation = Create(initData); + VToolFlippingByLine *operation = Create(initData); if (operation != nullptr) { operation->m_dialog = dialog; @@ -176,10 +176,10 @@ void VToolFlippingByLine::ShowContextMenu(QGraphicsSceneContextMenuEvent *event, { ContextMenu(event, id); } - catch(const VExceptionToolWasDeleted &e) + catch (const VExceptionToolWasDeleted &e) { Q_UNUSED(e) - return;//Leave this method immediately!!! + return; // Leave this method immediately!!! } } @@ -216,7 +216,7 @@ void VToolFlippingByLine::SaveDialog(QDomElement &domElement, QList &ol doc->SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->GetSecondLinePointId())); doc->SetAttribute(domElement, AttrSuffix, dialogTool->GetSuffix()); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, dialogTool->GetNotes(), - [](const QString ¬es) noexcept {return notes.isEmpty();}); + [](const QString ¬es) noexcept { return notes.isEmpty(); }); source = dialogTool->GetSourceObjects(); SaveSourceDestination(domElement); @@ -250,16 +250,15 @@ auto VToolFlippingByLine::MakeToolTip() const -> QString return QStringLiteral(" %1: %2 " " %3: %4 " "%5") - .arg(tr("First line point"), FirstLinePointName(), - tr("Second line point"), SecondLinePointName()) // 1, 2, 3, 4 - .arg(VisibilityGroupToolTip()); // 5 + .arg(tr("First line point"), FirstLinePointName(), tr("Second line point"), SecondLinePointName()) // 1, 2, 3, 4 + .arg(VisibilityGroupToolTip()); // 5 } //--------------------------------------------------------------------------------------------------------------------- VToolFlippingByLine::VToolFlippingByLine(const VToolFlippingByLineInitData &initData, QGraphicsItem *parent) - : VAbstractFlipping(initData, parent), - m_firstLinePointId(initData.firstLinePointId), - m_secondLinePointId(initData.secondLinePointId) + : VAbstractFlipping(initData, parent), + m_firstLinePointId(initData.firstLinePointId), + m_secondLinePointId(initData.secondLinePointId) { InitOperatedObjects(); ToolCreation(initData.typeCreation); diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp index 9ec2e144f..aa07d12e2 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp @@ -28,8 +28,6 @@ #include "vtoolmove.h" -#include -#include #include #include #include @@ -37,37 +35,39 @@ #include #include #include +#include #include +#include -#include "../../../dialogs/tools/dialogtool.h" #include "../../../dialogs/tools/dialogmove.h" +#include "../../../dialogs/tools/dialogtool.h" #include "../../../visualization/line/operation/vistoolmove.h" #include "../../../visualization/visualization.h" +#include "../../vabstracttool.h" +#include "../../vdatatool.h" +#include "../ifc/exception/vexception.h" +#include "../ifc/ifcdef.h" +#include "../vdrawtool.h" #include "../vgeometry/vabstractcurve.h" #include "../vgeometry/varc.h" -#include "../vgeometry/vellipticalarc.h" #include "../vgeometry/vcubicbezier.h" #include "../vgeometry/vcubicbezierpath.h" +#include "../vgeometry/vellipticalarc.h" #include "../vgeometry/vgobject.h" #include "../vgeometry/vpointf.h" #include "../vgeometry/vspline.h" #include "../vgeometry/vsplinepath.h" -#include "../vpatterndb/vtranslatevars.h" +#include "../vmisc/compatibility.h" #include "../vmisc/vabstractapplication.h" #include "../vmisc/vcommonsettings.h" #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/diagnostic.h" #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) -#include "../vmisc/compatibility.h" #include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vformula.h" -#include "../ifc/ifcdef.h" -#include "../ifc/exception/vexception.h" +#include "../vpatterndb/vtranslatevars.h" #include "../vwidgets/vabstractsimple.h" #include "../vwidgets/vmaingraphicsscene.h" -#include "../../vabstracttool.h" -#include "../../vdatatool.h" -#include "../vdrawtool.h" template class QSharedPointer; @@ -89,7 +89,7 @@ auto GetOriginPoint(const QVector &objects, const VContainer *data, // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); - switch(static_cast(obj->getType())) + switch (static_cast(obj->getType())) { case GOType::Point: originObjects.append(data->GeometricObject(object.id)->toQPointF()); @@ -110,12 +110,12 @@ auto GetOriginPoint(const QVector &objects, const VContainer *data, } QPointF rotationOrigin = originObjects.boundingRect().center(); - QLineF move(rotationOrigin, QPointF(rotationOrigin.x()+calcLength, rotationOrigin.y())); + QLineF move(rotationOrigin, QPointF(rotationOrigin.x() + calcLength, rotationOrigin.y())); move.setAngle(calcAngle); return move.p2(); } QT_WARNING_POP -} +} // namespace //--------------------------------------------------------------------------------------------------------------------- void VToolMove::SetDialog() @@ -159,7 +159,7 @@ auto VToolMove::Create(const QPointer &dialog, VMainGraphicsScene *s initData.typeCreation = Source::FromGui; initData.notes = dialogTool->GetNotes(); - VToolMove* operation = Create(initData); + VToolMove *operation = Create(initData); if (operation != nullptr) { operation->m_dialog = dialog; @@ -176,8 +176,8 @@ auto VToolMove::Create(VToolMoveInitData &initData) -> VToolMove * calcAngle = CheckFormula(initData.id, initData.formulaAngle, initData.data); calcRotationAngle = CheckFormula(initData.id, initData.formulaRotationAngle, initData.data); - calcLength = VAbstractValApplication::VApp()->toPixel(CheckFormula(initData.id, initData.formulaLength, - initData.data)); + calcLength = + VAbstractValApplication::VApp()->toPixel(CheckFormula(initData.id, initData.formulaLength, initData.data)); QPointF rotationOrigin; QSharedPointer originPoint; @@ -194,9 +194,9 @@ auto VToolMove::Create(VToolMoveInitData &initData) -> VToolMove * if (initData.typeCreation == Source::FromGui) { - initData.destination.clear();// Try to avoid mistake, value must be empty + initData.destination.clear(); // Try to avoid mistake, value must be empty - initData.id = initData.data->getNextId();//Just reserve id for tool + initData.id = initData.data->getNextId(); // Just reserve id for tool for (auto object : qAsConst(initData.source)) { @@ -205,9 +205,9 @@ auto VToolMove::Create(VToolMoveInitData &initData) -> VToolMove * // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wswitch-default") - switch(static_cast(obj->getType())) + QT_WARNING_PUSH + QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch (static_cast(obj->getType())) { case GOType::Point: initData.destination.append(CreatePoint(initData.id, object, calcAngle, calcLength, @@ -230,10 +230,9 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") initData.data)); break; case GOType::SplinePath: - initData.destination.append(CreateCurveWithSegments(initData.id, object, calcAngle, - calcLength, calcRotationAngle, - rotationOrigin, initData.suffix, - initData.data)); + initData.destination.append(CreateCurveWithSegments( + initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, + initData.data)); break; case GOType::CubicBezier: initData.destination.append(CreateCurve(initData.id, object, calcAngle, calcLength, @@ -241,19 +240,16 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") initData.suffix, initData.data)); break; case GOType::CubicBezierPath: - initData.destination.append(CreateCurveWithSegments(initData.id, object, - calcAngle, calcLength, - calcRotationAngle, - rotationOrigin, - initData.suffix, - initData.data)); + initData.destination.append(CreateCurveWithSegments( + initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, + initData.data)); break; case GOType::Unknown: case GOType::PlaceLabel: Q_UNREACHABLE(); break; } -QT_WARNING_POP + QT_WARNING_POP } } else @@ -266,9 +262,9 @@ QT_WARNING_POP // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wswitch-default") - switch(static_cast(obj->getType())) + QT_WARNING_PUSH + QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch (static_cast(obj->getType())) { case GOType::Point: UpdatePoint(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, @@ -284,31 +280,30 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") initData.destination.at(i).id); break; case GOType::Spline: - UpdateCurve(initData.id, object, calcAngle, calcLength, calcRotationAngle, - rotationOrigin, initData.suffix, initData.data, initData.destination.at(i).id); + UpdateCurve(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, + initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::SplinePath: - UpdateCurveWithSegments(initData.id, object, calcAngle, calcLength, - calcRotationAngle, rotationOrigin,initData.suffix, - initData.data, initData.destination.at(i).id); + UpdateCurveWithSegments(initData.id, object, calcAngle, calcLength, calcRotationAngle, + rotationOrigin, initData.suffix, initData.data, + initData.destination.at(i).id); break; case GOType::CubicBezier: UpdateCurve(initData.id, object, calcAngle, calcLength, calcRotationAngle, - rotationOrigin,initData.suffix, initData.data, + rotationOrigin, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::CubicBezierPath: UpdateCurveWithSegments(initData.id, object, calcAngle, calcLength, - calcRotationAngle, rotationOrigin, - initData.suffix, initData.data, - initData.destination.at(i).id); + calcRotationAngle, rotationOrigin, initData.suffix, + initData.data, initData.destination.at(i).id); break; case GOType::Unknown: case GOType::PlaceLabel: Q_UNREACHABLE(); break; } -QT_WARNING_POP + QT_WARNING_POP } if (initData.parse != Document::FullParse) { @@ -445,10 +440,10 @@ void VToolMove::ShowContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 i { ContextMenu(event, id); } - catch(const VExceptionToolWasDeleted &e) + catch (const VExceptionToolWasDeleted &e) { Q_UNUSED(e) - return;//Leave this method immediately!!! + return; // Leave this method immediately!!! } } @@ -489,7 +484,7 @@ void VToolMove::SaveDialog(QDomElement &domElement, QList &oldDependenc doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->GetRotationOrigPointId())); doc->SetAttribute(domElement, AttrRotationAngle, dialogTool->GetRotationAngle()); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, dialogTool->GetNotes(), - [](const QString ¬es) noexcept {return notes.isEmpty();}); + [](const QString ¬es) noexcept { return notes.isEmpty(); }); source = dialogTool->GetSourceObjects(); SaveSourceDestination(domElement); @@ -529,25 +524,25 @@ auto VToolMove::MakeToolTip() const -> QString " %6: %7° " " %8: %9 " "%10") - .arg(tr("Angle")) // 1 - .arg(GetFormulaAngle().getDoubleValue()) // 2 - .arg(tr("Length")) // 3 - .arg(GetFormulaLength().getDoubleValue()) // 4 - .arg(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true), // 5 - tr("Rotation angle")) // 6 - .arg(GetFormulaRotationAngle().getDoubleValue()) // 7 - .arg(tr("Rotation origin point"), // 8 - OriginPointName()) // 9 - .arg(VisibilityGroupToolTip()); // 10 + .arg(tr("Angle")) // 1 + .arg(GetFormulaAngle().getDoubleValue()) // 2 + .arg(tr("Length")) // 3 + .arg(GetFormulaLength().getDoubleValue()) // 4 + .arg(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true), // 5 + tr("Rotation angle")) // 6 + .arg(GetFormulaRotationAngle().getDoubleValue()) // 7 + .arg(tr("Rotation origin point"), // 8 + OriginPointName()) // 9 + .arg(VisibilityGroupToolTip()); // 10 } //--------------------------------------------------------------------------------------------------------------------- VToolMove::VToolMove(const VToolMoveInitData &initData, QGraphicsItem *parent) - : VAbstractOperation(initData, parent), - formulaAngle(initData.formulaAngle), - formulaRotationAngle(initData.formulaRotationAngle), - formulaLength(initData.formulaLength), - origPointId(initData.rotationOrigin) + : VAbstractOperation(initData, parent), + formulaAngle(initData.formulaAngle), + formulaRotationAngle(initData.formulaRotationAngle), + formulaLength(initData.formulaLength), + origPointId(initData.rotationOrigin) { InitOperatedObjects(); ToolCreation(initData.typeCreation); @@ -579,8 +574,8 @@ template auto VToolMove::CreateArc(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data) -> DestinationItem { - const DestinationItem item = CreateItem(idTool, sItem, angle, length, rotationAngle, rotationOrigin, suffix, - data); + const DestinationItem item = + CreateItem(idTool, sItem, angle, length, rotationAngle, rotationOrigin, suffix, data); data->AddArc(data->GeometricObject(item.id), item.id); return item; } @@ -648,8 +643,8 @@ template auto VToolMove::CreateCurve(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data) -> DestinationItem { - const DestinationItem item = CreateItem(idTool, sItem, angle, length, rotationAngle, rotationOrigin, suffix, - data); + const DestinationItem item = + CreateItem(idTool, sItem, angle, length, rotationAngle, rotationOrigin, suffix, data); data->AddSpline(data->GeometricObject(item.id), item.id); return item; } @@ -660,8 +655,8 @@ auto VToolMove::CreateCurveWithSegments(quint32 idTool, const SourceItem &sItem, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data) -> DestinationItem { - const DestinationItem item = CreateItem(idTool, sItem, angle, length, rotationAngle, rotationOrigin, suffix, - data); + const DestinationItem item = + CreateItem(idTool, sItem, angle, length, rotationAngle, rotationOrigin, suffix, data); data->AddCurveWithSegments(data->GeometricObject(item.id), item.id); return item; } diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index 7cd102316..2d82e0ca7 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -42,6 +42,11 @@ #include "../../../dialogs/tools/dialogtool.h" #include "../../../visualization/line/operation/vistoolrotation.h" #include "../../../visualization/visualization.h" +#include "../../vabstracttool.h" +#include "../../vdatatool.h" +#include "../ifc/exception/vexception.h" +#include "../ifc/ifcdef.h" +#include "../vdrawtool.h" #include "../vgeometry/varc.h" #include "../vgeometry/vcubicbezier.h" #include "../vgeometry/vcubicbezierpath.h" @@ -52,17 +57,12 @@ #include "../vgeometry/vsplinepath.h" #include "../vmisc/vabstractapplication.h" #include "../vmisc/vcommonsettings.h" +#include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/vformula.h" #include "../vpatterndb/vtranslatevars.h" #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include "../vmisc/diagnostic.h" #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) -#include "../../vabstracttool.h" -#include "../../vdatatool.h" -#include "../ifc/exception/vexception.h" -#include "../ifc/ifcdef.h" -#include "../vdrawtool.h" -#include "../vpatterndb/vcontainer.h" -#include "../vpatterndb/vformula.h" #include "../vwidgets/vmaingraphicsscene.h" class QDomElement; diff --git a/src/libs/vwidgets/vabstractmainwindow.cpp b/src/libs/vwidgets/vabstractmainwindow.cpp index bdf5572a3..7d0cb1fe6 100644 --- a/src/libs/vwidgets/vabstractmainwindow.cpp +++ b/src/libs/vwidgets/vabstractmainwindow.cpp @@ -27,23 +27,23 @@ *************************************************************************/ #include "vabstractmainwindow.h" -#include "../vpropertyexplorer/checkablemessagebox.h" -#include "../vmisc/vabstractapplication.h" #include "../vmisc/compatibility.h" #include "../vmisc/def.h" +#include "../vmisc/vabstractapplication.h" #include "../vmisc/vsysexits.h" +#include "../vpropertyexplorer/checkablemessagebox.h" #include "dialogs/dialogexporttocsv.h" -#include -#include -#include #include +#include #include #include +#include +#include -//#ifdef Q_OS_WIN -//extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; -//#endif /*Q_OS_WIN*/ +// #ifdef Q_OS_WIN +// extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; +// #endif /*Q_OS_WIN*/ #if defined(Q_OS_MAC) #include @@ -75,7 +75,7 @@ auto RecentFiles(const QStringList &paths) -> QStringList QVector table; table.reserve(paths.size()); - for(const auto &path : paths) + for (const auto &path : paths) { table.append(SplitFilePaths(path)); } @@ -83,7 +83,7 @@ auto RecentFiles(const QStringList &paths) -> QStringList auto CreateOptimized = [table](int tableRow) { QStringList optimized; - const QStringList& path = table.at(tableRow); + const QStringList &path = table.at(tableRow); for (int count = 1; count <= path.size(); ++count) { bool isUnique = true; @@ -130,20 +130,20 @@ auto RecentFiles(const QStringList &paths) -> QStringList QStringList recentFiles; recentFiles.reserve(paths.size()); - for(auto &path : optimizedPaths) + for (auto &path : optimizedPaths) { recentFiles.append(path.join(QDir::separator())); } return recentFiles; } -} +} // namespace //--------------------------------------------------------------------------------------------------------------------- VAbstractMainWindow::VAbstractMainWindow(QWidget *parent) - : QMainWindow(parent), - m_curFileFormatVersion(0x0), - m_curFileFormatVersionStr(QLatin1String("0.0.0")) + : QMainWindow(parent), + m_curFileFormatVersion(0x0), + m_curFileFormatVersionStr(QLatin1String("0.0.0")) { for (int i = 0; i < MaxRecentFiles; ++i) { @@ -169,7 +169,8 @@ auto VAbstractMainWindow::ContinueFormatRewrite(const QString ¤tFormatVers msgBox.setText(tr("This file is using previous format version v%1. The current is v%2. " "Saving the file with this app version will update the format version for this " "file. This may prevent you from be able to open the file with older app versions. " - "Do you really want to continue?").arg(currentFormatVersion, maxFormatVersion)); + "Do you really want to continue?") + .arg(currentFormatVersion, maxFormatVersion)); msgBox.setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No); msgBox.setDefaultButton(QDialogButtonBox::No); msgBox.setIconPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion).pixmap(32, 32)); @@ -212,7 +213,7 @@ auto VAbstractMainWindow::CSVFilePath() -> QString return fileName; } - QFileInfo f( fileName ); + QFileInfo f(fileName); if (f.suffix().isEmpty() && f.suffix() != suffix) { fileName += QChar('.') + suffix; @@ -250,7 +251,7 @@ void VAbstractMainWindow::UpdateRecentFileActions() } } - m_separatorAct->setVisible(numRecentFiles>0); + m_separatorAct->setVisible(numRecentFiles > 0); } //--------------------------------------------------------------------------------------------------------------------- @@ -258,9 +259,9 @@ auto VAbstractMainWindow::CheckFilePermissions(const QString &path, QWidget *mes { QFileInfo info(path); -//#ifdef Q_OS_WIN32 -// qt_ntfs_permission_lookup++; // turn checking on -//#endif /*Q_OS_WIN32*/ + // #ifdef Q_OS_WIN32 + // qt_ntfs_permission_lookup++; // turn checking on + // #endif /*Q_OS_WIN32*/ if (not info.exists()) { @@ -269,9 +270,9 @@ auto VAbstractMainWindow::CheckFilePermissions(const QString &path, QWidget *mes const bool isFileWritable = info.isWritable(); -//#ifdef Q_OS_WIN32 -// qt_ntfs_permission_lookup--; // turn it off again -//#endif /*Q_OS_WIN32*/ + // #ifdef Q_OS_WIN32 + // qt_ntfs_permission_lookup--; // turn it off again + // #endif /*Q_OS_WIN32*/ if (not isFileWritable) { @@ -284,13 +285,13 @@ auto VAbstractMainWindow::CheckFilePermissions(const QString &path, QWidget *mes if (messageBox.exec() == QMessageBox::Yes) { -//#ifdef Q_OS_WIN32 -// qt_ntfs_permission_lookup++; // turn checking on -//#endif /*Q_OS_WIN32*/ + // #ifdef Q_OS_WIN32 + // qt_ntfs_permission_lookup++; // turn checking on + // #endif /*Q_OS_WIN32*/ bool changed = QFile::setPermissions(path, QFileInfo(path).permissions() | QFileDevice::WriteUser); -//#ifdef Q_OS_WIN32 -// qt_ntfs_permission_lookup--; // turn it off again -//#endif /*Q_OS_WIN32*/ + // #ifdef Q_OS_WIN32 + // qt_ntfs_permission_lookup--; // turn it off again + // #endif /*Q_OS_WIN32*/ if (not changed) { @@ -317,27 +318,27 @@ auto VAbstractMainWindow::IgnoreLocking(int error, const QString &path, bool gui QMessageBox::StandardButton answer = QMessageBox::Abort; if (guiMode) { - switch(error) + switch (error) { case QLockFile::LockFailedError: answer = QMessageBox::warning(this, tr("Locking file"), tr("This file already opened in another window. Ignore if you want " "to continue (not recommended, can cause a data corruption)."), - QMessageBox::Abort|QMessageBox::Ignore, QMessageBox::Abort); + QMessageBox::Abort | QMessageBox::Ignore, QMessageBox::Abort); break; case QLockFile::PermissionError: answer = QMessageBox::question(this, tr("Locking file"), tr("The lock file could not be created, for lack of permissions. " "Ignore if you want to continue (not recommended, can cause " "a data corruption)."), - QMessageBox::Abort|QMessageBox::Ignore, QMessageBox::Abort); + QMessageBox::Abort | QMessageBox::Ignore, QMessageBox::Abort); break; case QLockFile::UnknownError: answer = QMessageBox::question(this, tr("Locking file"), tr("Unknown error happened, for instance a full partition " "prevented writing out the lock file. Ignore if you want to " "continue (not recommended, can cause a data corruption)."), - QMessageBox::Abort|QMessageBox::Ignore, QMessageBox::Abort); + QMessageBox::Abort | QMessageBox::Ignore, QMessageBox::Abort); break; default: answer = QMessageBox::Abort; @@ -351,7 +352,7 @@ auto VAbstractMainWindow::IgnoreLocking(int error, const QString &path, bool gui qCDebug(abstactMainWindow, "Error type: %d", error); if (not guiMode) { - switch(error) + switch (error) { case QLockFile::LockFailedError: qCCritical(abstactMainWindow, "%s", diff --git a/src/test/ValentinaTest/tst_vabstractpiece.cpp b/src/test/ValentinaTest/tst_vabstractpiece.cpp index d8cf049af..ff1e1fcc9 100644 --- a/src/test/ValentinaTest/tst_vabstractpiece.cpp +++ b/src/test/ValentinaTest/tst_vabstractpiece.cpp @@ -27,10 +27,10 @@ *************************************************************************/ #include "tst_vabstractpiece.h" -#include "../vlayout/vabstractpiece.h" -#include "../vlayout/vrawsapoint.h" #include "../vgeometry/varc.h" #include "../vgeometry/vpointf.h" +#include "../vlayout/vabstractpiece.h" +#include "../vlayout/vrawsapoint.h" #include #include @@ -39,8 +39,9 @@ //--------------------------------------------------------------------------------------------------------------------- TST_VAbstractPiece::TST_VAbstractPiece(QObject *parent) - : AbstractTest(parent) -{} + : AbstractTest(parent) +{ +} //--------------------------------------------------------------------------------------------------------------------- void TST_VAbstractPiece::EquidistantRemoveLoop_data() @@ -57,20 +58,17 @@ void TST_VAbstractPiece::EquidistantRemoveLoop_data() }; // See file src/app/share/collection/test/seamtest1.val - ASSERT_TEST_CASE("Seam test 1. Piece. By angle.", - QStringLiteral("://seamtest1_by_angle/input.json"), + ASSERT_TEST_CASE("Seam test 1. Piece. By angle.", QStringLiteral("://seamtest1_by_angle/input.json"), QStringLiteral("://seamtest1_by_angle/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/test/seamtest1.val - ASSERT_TEST_CASE("Seam test 1. Piece. By angle 2.", - QStringLiteral("://seamtest1_by_angle_2/input.json"), + ASSERT_TEST_CASE("Seam test 1. Piece. By angle 2.", QStringLiteral("://seamtest1_by_angle_2/input.json"), QStringLiteral("://seamtest1_by_angle_2/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/test/seamtest1.val - ASSERT_TEST_CASE("Seam test 1. Piece. By intersection.", - QStringLiteral("://seamtest1_by_intersection/input.json"), + ASSERT_TEST_CASE("Seam test 1. Piece. By intersection.", QStringLiteral("://seamtest1_by_intersection/input.json"), QStringLiteral("://seamtest1_by_intersection/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); @@ -99,206 +97,167 @@ void TST_VAbstractPiece::EquidistantRemoveLoop_data() 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/test/seamtest2.val - ASSERT_TEST_CASE("Seam test 2", - QStringLiteral("://seamtest2/input.json"), - QStringLiteral("://seamtest2/output.json"), - 37.795275590551185 /*seam allowance width (1.0 cm)*/); + ASSERT_TEST_CASE("Seam test 2", QStringLiteral("://seamtest2/input.json"), + QStringLiteral("://seamtest2/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/test/seamtest3.val - ASSERT_TEST_CASE("Seam test 3", - QStringLiteral("://seamtest3/input.json"), - QStringLiteral("://seamtest3/output.json"), - 37.795275590551185 /*seam allowance width (1.0 cm)*/); + ASSERT_TEST_CASE("Seam test 3", QStringLiteral("://seamtest3/input.json"), + QStringLiteral("://seamtest3/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // These are two real cases where equdistant has loop. // See issue #298. Segmented Curve isn't selected in Seam Allowance tool. // https://bitbucket.org/dismine/valentina/issue/298/segmented-curve-isnt-selected-in-seam // See file src/app/share/collection/TestPuzzle.val // Code should clean loops in path. - ASSERT_TEST_CASE("Issue 298. Case1", - QStringLiteral("://Issue_298_case1/input.json"), - QStringLiteral("://Issue_298_case1/output.json"), - 75.59055118110237 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue 298. Case1", QStringLiteral("://Issue_298_case1/input.json"), + QStringLiteral("://Issue_298_case1/output.json"), 75.59055118110237 /*seam allowance width*/); - ASSERT_TEST_CASE("Issue 298. Case2", - QStringLiteral("://Issue_298_case2/input.json"), - QStringLiteral("://Issue_298_case2/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue 298. Case2", QStringLiteral("://Issue_298_case2/input.json"), + QStringLiteral("://Issue_298_case2/output.json"), 37.795275590551185 /*seam allowance width*/); // See issue #548. Bug Detail tool. Case when seam allowance is wrong. // https://bitbucket.org/dismine/valentina/issues/548/bug-detail-tool-case-when-seam-allowance // Files: Steampunk_trousers.val and marie.vit // Actually buggy detail see in file src/app/share/collection/bugs/Steampunk_trousers_issue_#548.val // Code should clean loops in path. - ASSERT_TEST_CASE("Issue 548. Case1", - QStringLiteral("://Issue_548_case1/input.json"), + ASSERT_TEST_CASE("Issue 548. Case1", QStringLiteral("://Issue_548_case1/input.json"), QStringLiteral("://Issue_548_case1/output.json"), 11.338582677165354 /*seam allowance width (0.3 cm)*/); - ASSERT_TEST_CASE("Issue 548. Case2", - QStringLiteral("://Issue_548_case2/input.json"), + ASSERT_TEST_CASE("Issue 548. Case2", QStringLiteral("://Issue_548_case2/input.json"), QStringLiteral("://Issue_548_case2/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); - ASSERT_TEST_CASE("Issue 548. Case3", - QStringLiteral("://Issue_548_case3/input.json"), + ASSERT_TEST_CASE("Issue 548. Case3", QStringLiteral("://Issue_548_case3/input.json"), QStringLiteral("://Issue_548_case3/output.json"), 75.59055118110237 /*seam allowance width (2.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#646.val - ASSERT_TEST_CASE("Issue 646.", - QStringLiteral("://Issue_646/input.json"), - QStringLiteral("://Issue_646/output.json"), - 37.795275590551185 /*seam allowance width (1.0 cm)*/); + ASSERT_TEST_CASE("Issue 646.", QStringLiteral("://Issue_646/input.json"), + QStringLiteral("://Issue_646/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923.val - ASSERT_TEST_CASE("Issue 923. Test 1", - QStringLiteral("://Issue_923_test1/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 1", QStringLiteral("://Issue_923_test1/input.json"), QStringLiteral("://Issue_923_test1/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923.val - ASSERT_TEST_CASE("Issue 923. Test 2", - QStringLiteral("://Issue_923_test2/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 2", QStringLiteral("://Issue_923_test2/input.json"), QStringLiteral("://Issue_923_test2/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923.val - ASSERT_TEST_CASE("Issue 923. Test 3", - QStringLiteral("://Issue_923_test3/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 3", QStringLiteral("://Issue_923_test3/input.json"), QStringLiteral("://Issue_923_test3/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923.val - ASSERT_TEST_CASE("Issue 923. Test 4", - QStringLiteral("://Issue_923_test4/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 4", QStringLiteral("://Issue_923_test4/input.json"), QStringLiteral("://Issue_923_test4/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923.val - ASSERT_TEST_CASE("Issue 923. Test 5", - QStringLiteral("://Issue_923_test5/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 5", QStringLiteral("://Issue_923_test5/input.json"), QStringLiteral("://Issue_923_test5/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923.val - ASSERT_TEST_CASE("Issue 923. Test 6", - QStringLiteral("://Issue_923_test6/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 6", QStringLiteral("://Issue_923_test6/input.json"), QStringLiteral("://Issue_923_test6/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923.val - ASSERT_TEST_CASE("Issue 923. Test 1.1", - QStringLiteral("://Issue_923_test1_1/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 1.1", QStringLiteral("://Issue_923_test1_1/input.json"), QStringLiteral("://Issue_923_test1_1/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923.val - ASSERT_TEST_CASE("Issue 923. Test 2.2", - QStringLiteral("://Issue_923_test2_2/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 2.2", QStringLiteral("://Issue_923_test2_2/input.json"), QStringLiteral("://Issue_923_test2_2/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923.val - ASSERT_TEST_CASE("Issue 923. Test 3.3", - QStringLiteral("://Issue_923_test3_3/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 3.3", QStringLiteral("://Issue_923_test3_3/input.json"), QStringLiteral("://Issue_923_test3_3/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923.val - ASSERT_TEST_CASE("Issue 923. Test 4.4", - QStringLiteral("://Issue_923_test4_4/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 4.4", QStringLiteral("://Issue_923_test4_4/input.json"), QStringLiteral("://Issue_923_test4_4/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923.val - ASSERT_TEST_CASE("Issue 923. Test 5.5", - QStringLiteral("://Issue_923_test5_5/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 5.5", QStringLiteral("://Issue_923_test5_5/input.json"), QStringLiteral("://Issue_923_test5_5/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923.val - ASSERT_TEST_CASE("Issue 923. Test 6.6", - QStringLiteral("://Issue_923_test6_6/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 6.6", QStringLiteral("://Issue_923_test6_6/input.json"), QStringLiteral("://Issue_923_test6_6/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923_test7.val - ASSERT_TEST_CASE("Issue 923. Test 7.1", - QStringLiteral("://Issue_923_test7_1/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 7.1", QStringLiteral("://Issue_923_test7_1/input.json"), QStringLiteral("://Issue_923_test7_1/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923_test7.val - ASSERT_TEST_CASE("Issue 923. Test 7.2", - QStringLiteral("://Issue_923_test7_2/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 7.2", QStringLiteral("://Issue_923_test7_2/input.json"), QStringLiteral("://Issue_923_test7_2/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/Issue_#923_test7.val - ASSERT_TEST_CASE("Issue 923. Test 7.3", - QStringLiteral("://Issue_923_test7_3/input.json"), + ASSERT_TEST_CASE("Issue 923. Test 7.3", QStringLiteral("://Issue_923_test7_3/input.json"), QStringLiteral("://Issue_923_test7_3/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/loop_by_intersection.val - ASSERT_TEST_CASE("Loop for angle by intersection", - QStringLiteral("://loop_by_intersection/input.json"), + ASSERT_TEST_CASE("Loop for angle by intersection", QStringLiteral("://loop_by_intersection/input.json"), QStringLiteral("://loop_by_intersection/output.json"), 39.685039370078741 /*seam allowance width (1.05 cm)*/); // See file valentina_private_collection/bugs/loop_start_point_on_line/loop_start_point_on_line.val // (private collection) - ASSERT_TEST_CASE("Loop for start point on line", - QStringLiteral("://loop_start_point_on_line/input.json"), + ASSERT_TEST_CASE("Loop for start point on line", QStringLiteral("://loop_start_point_on_line/input.json"), QStringLiteral("://loop_start_point_on_line/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file valentina_private_collection/bugs/DP_6_hem/DP_6_hem.val - ASSERT_TEST_CASE("By length", - QStringLiteral("://DP_6_hem_by_length/input.json"), + ASSERT_TEST_CASE("By length", QStringLiteral("://DP_6_hem_by_length/input.json"), QStringLiteral("://DP_6_hem_by_length/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file valentina_private_collection/bugs/DP_6_hem/DP_6_hem.val - ASSERT_TEST_CASE("By intersection", - QStringLiteral("://DP_6_hem_by_intersection/input.json"), + ASSERT_TEST_CASE("By intersection", QStringLiteral("://DP_6_hem_by_intersection/input.json"), QStringLiteral("://DP_6_hem_by_intersection/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file valentina_private_collection/bugs/DP_6_hem/DP_6_hem.val - ASSERT_TEST_CASE("By first edge symmetry", - QStringLiteral("://DP_6_hem_by_first_edge_symmetry/input.json"), + ASSERT_TEST_CASE("By first edge symmetry", QStringLiteral("://DP_6_hem_by_first_edge_symmetry/input.json"), QStringLiteral("://DP_6_hem_by_first_edge_symmetry/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file valentina_private_collection/bugs/DP_6_hem/DP_6_hem.val - ASSERT_TEST_CASE("By second edge symmetry", - QStringLiteral("://DP_6_hem_by_second_edge_symmetry/input.json"), + ASSERT_TEST_CASE("By second edge symmetry", QStringLiteral("://DP_6_hem_by_second_edge_symmetry/input.json"), QStringLiteral("://DP_6_hem_by_second_edge_symmetry/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file valentina_private_collection/bugs/DP_6_hem/DP_6_hem.val - ASSERT_TEST_CASE("By first edge right angle", - QStringLiteral("://DP_6_hem_by_first_edge_right_angle/input.json"), + ASSERT_TEST_CASE("By first edge right angle", QStringLiteral("://DP_6_hem_by_first_edge_right_angle/input.json"), QStringLiteral("://DP_6_hem_by_first_edge_right_angle/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file valentina_private_collection/bugs/DP_6_hem/DP_6_hem.val - ASSERT_TEST_CASE("By second edge right angle", - QStringLiteral("://DP_6_hem_by_second_edge_right_angle/input.json"), + ASSERT_TEST_CASE("By second edge right angle", QStringLiteral("://DP_6_hem_by_second_edge_right_angle/input.json"), QStringLiteral("://DP_6_hem_by_second_edge_right_angle/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file valentina_private_collection/bugs/DP_6/DP_6.val - ASSERT_TEST_CASE("Hem by seam allowance", - QStringLiteral("://DP_6/input.json"), - QStringLiteral("://DP_6/output.json"), - 37.795275590551185 /*seam allowance width (1.0 cm)*/); + ASSERT_TEST_CASE("Hem by seam allowance", QStringLiteral("://DP_6/input.json"), + QStringLiteral("://DP_6/output.json"), 37.795275590551185 /*seam allowance width (1.0 cm)*/); // See file src/app/share/collection/bugs/smart_pattern_#36.val - ASSERT_TEST_CASE("Incorrect position of a notch", - QStringLiteral("://smart_pattern_#36/input.json"), + ASSERT_TEST_CASE("Incorrect position of a notch", QStringLiteral("://smart_pattern_#36/input.json"), QStringLiteral("://smart_pattern_#36/output.json"), 30.236220472440944 /*seam allowance width (0.8 cm)*/); } @@ -332,28 +291,21 @@ void TST_VAbstractPiece::LayoutAllowanceRemoveLoop_data() }; // See file valentina_private_collection/bugs/smart_pattern_#58/smart_pattern_#58.val - ASSERT_TEST_CASE("Loop in layout allowance", - QStringLiteral("://smart_pattern_#58/input.json"), + ASSERT_TEST_CASE("Loop in layout allowance", QStringLiteral("://smart_pattern_#58/input.json"), QStringLiteral("://smart_pattern_#58/output.json"), 18.897637795275593 /*seam allowance width (0.5 cm)*/); // See file src/app/share/collection/bugs/smart_pattern_#99.val - ASSERT_TEST_CASE("Incorrect fix of distortion", - QStringLiteral("://smart_pattern_#99/input.json"), - QStringLiteral("://smart_pattern_#99/output.json"), - 28.346456692913389 /*seam allowance width*/); + ASSERT_TEST_CASE("Incorrect fix of distortion", QStringLiteral("://smart_pattern_#99/input.json"), + QStringLiteral("://smart_pattern_#99/output.json"), 28.346456692913389 /*seam allowance width*/); // See file valentina_private_collection/test/smart_pattern_#120/smart_pattern_#120.val - ASSERT_TEST_CASE("Piece 1", - QStringLiteral("://smart_pattern_#120_piece_1/input.json"), - QStringLiteral("://smart_pattern_#120_piece_1/output.json"), - 37.795275590551185); + ASSERT_TEST_CASE("Piece 1", QStringLiteral("://smart_pattern_#120_piece_1/input.json"), + QStringLiteral("://smart_pattern_#120_piece_1/output.json"), 37.795275590551185); // See file valentina_private_collection/test/smart_pattern_#120/smart_pattern_#120.val - ASSERT_TEST_CASE("Piece 2", - QStringLiteral("://smart_pattern_#120_piece_2/input.json"), - QStringLiteral("://smart_pattern_#120_piece_2/output.json"), - 37.795275590551185); + ASSERT_TEST_CASE("Piece 2", QStringLiteral("://smart_pattern_#120_piece_2/input.json"), + QStringLiteral("://smart_pattern_#120_piece_2/output.json"), 37.795275590551185); } //--------------------------------------------------------------------------------------------------------------------- @@ -388,37 +340,30 @@ void TST_VAbstractPiece::TestAreaCalculation_data() QTest::addColumn("excpectedArea"); { - QVector rect - { - QPointF(), - QPointF(100, 0), - QPointF(100, 50), - QPointF(0, 50), - QPointF() - }; + QVector rect{QPointF(), QPointF(100, 0), QPointF(100, 50), QPointF(0, 50), QPointF()}; - QTest::newRow("Rectangle 100 x 50") << rect << 100.0 * 50.0; + QTest::newRow("Rectangle 100 x 50") << rect << 100.0 * 50.0; } { - VArc circle(VPointF(100, 100, QChar('C'), 0, 0), 100, 35, 35); - circle.SetApproximationScale(maxCurveApproximationScale); - QVector circlePath = circle.GetPoints(); - if (not circlePath.isEmpty() && not VFuzzyComparePoints(ConstFirst(circlePath), ConstLast(circlePath))) - { - circlePath.append(ConstFirst(circlePath)); - } - QTest::newRow("Circle radis 100") << circlePath << M_PI * pow(100, 2); + VArc circle(VPointF(100, 100, QChar('C'), 0, 0), 100, 35, 35); + circle.SetApproximationScale(maxCurveApproximationScale); + QVector circlePath = circle.GetPoints(); + if (not circlePath.isEmpty() && not VFuzzyComparePoints(ConstFirst(circlePath), ConstLast(circlePath))) + { + circlePath.append(ConstFirst(circlePath)); + } + QTest::newRow("Circle radis 100") << circlePath << M_PI * pow(100, 2); } { - VPointF sectorCenter(100, 100, QChar('C'), 0, 0); - VArc sector(sectorCenter, 100, 15, 45); - sector.SetApproximationScale(maxCurveApproximationScale); - QVector sectorPath = sector.GetPoints(); - sectorPath.append(sectorCenter.toQPointF()); - sectorPath.append(ConstFirst(sectorPath)); - QTest::newRow("Sector radius 100, 30 degree") << sectorPath << (M_PI * pow(100, 2) * 30.0) / 360.0; + VPointF sectorCenter(100, 100, QChar('C'), 0, 0); + VArc sector(sectorCenter, 100, 15, 45); + sector.SetApproximationScale(maxCurveApproximationScale); + QVector sectorPath = sector.GetPoints(); + sectorPath.append(sectorCenter.toQPointF()); + sectorPath.append(ConstFirst(sectorPath)); + QTest::newRow("Sector radius 100, 30 degree") << sectorPath << (M_PI * pow(100, 2) * 30.0) / 360.0; } } @@ -428,7 +373,7 @@ void TST_VAbstractPiece::TestAreaCalculation() const QFETCH(QVector, path); QFETCH(qreal, excpectedArea); - const qreal result = qAbs(VAbstractPiece::SumTrapezoids(path)/2.0); + const qreal result = qAbs(VAbstractPiece::SumTrapezoids(path) / 2.0); QVERIFY(qAbs(result - excpectedArea) < MmToPixel(1.0)); } @@ -446,8 +391,7 @@ void TST_VAbstractPiece::RawPathRemoveLoop_data() const }; // See file src/app/share/collection/bugs/smart_pattern_#112.val (private collection) - ASSERT_TEST_CASE("Loop intersection", - QStringLiteral("://smart_pattern_#112/input.json"), + ASSERT_TEST_CASE("Loop intersection", QStringLiteral("://smart_pattern_#112/input.json"), QStringLiteral("://smart_pattern_#112/output.json")); } @@ -936,27 +880,20 @@ void TST_VAbstractPiece::BrokenDetailEquidistant_data() }; // See the file "collection/bugs/Issue_#604.val" (since 0.5.0) - ASSERT_TEST_CASE("Issue #604.", - QStringLiteral("://Issue_604/input.json"), - QStringLiteral("://Issue_604/output.json"), - 11.338582677165354 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue #604.", QStringLiteral("://Issue_604/input.json"), + QStringLiteral("://Issue_604/output.json"), 11.338582677165354 /*seam allowance width*/); // See the file "collection/bugs/Issue_#627.val" - ASSERT_TEST_CASE("Issue #627.", - QStringLiteral("://Issue_627/input.json"), - QStringLiteral("://Issue_627/output.json"), - 56.692913385826778 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue #627.", QStringLiteral("://Issue_627/input.json"), + QStringLiteral("://Issue_627/output.json"), 56.692913385826778 /*seam allowance width*/); // See the file "collection/bugs/Issue_#687.val" - ASSERT_TEST_CASE("Issue #687.", - QStringLiteral("://Issue_687/input.json"), - QStringLiteral("://Issue_687/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue #687.", QStringLiteral("://Issue_687/input.json"), + QStringLiteral("://Issue_687/output.json"), 37.795275590551185 /*seam allowance width*/); // See private test cases in file jacket_issue_#767.val, piece "Fabric_TopCollar" // Curve approximation scale 0.5 - ASSERT_TEST_CASE("Issue #767. Fabric_TopCollar.", - QStringLiteral("://Issue_767_Fabric_TopCollar/input.json"), + ASSERT_TEST_CASE("Issue #767. Fabric_TopCollar.", QStringLiteral("://Issue_767_Fabric_TopCollar/input.json"), QStringLiteral("://Issue_767_Fabric_TopCollar/output.json"), 37.795275590551185 /*seam allowance width*/); @@ -968,63 +905,47 @@ void TST_VAbstractPiece::BrokenDetailEquidistant_data() 37.795275590551185 /*seam allowance width*/); // See private test cases in file collection/bugs/Issue_#883_case1.val, piece "ledge" - ASSERT_TEST_CASE("Issue #883. Piece 'ledge'", - QStringLiteral("://Issue_883_ledge/input.json"), - QStringLiteral("://Issue_883_ledge/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue #883. Piece 'ledge'", QStringLiteral("://Issue_883_ledge/input.json"), + QStringLiteral("://Issue_883_ledge/output.json"), 37.795275590551185 /*seam allowance width*/); // See private test cases in file collection/bugs/Issue_#883_case1.val, piece "prong" - ASSERT_TEST_CASE("Issue #883. Piece 'prong'", - QStringLiteral("://Issue_883_prong/input.json"), - QStringLiteral("://Issue_883_prong/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue #883. Piece 'prong'", QStringLiteral("://Issue_883_prong/input.json"), + QStringLiteral("://Issue_883_prong/output.json"), 37.795275590551185 /*seam allowance width*/); // See the file "collection/bugs/smart_pattern_#145.val" - ASSERT_TEST_CASE("Issue #145", - QStringLiteral("://smart_pattern_#145/input.json"), - QStringLiteral("://smart_pattern_#145/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue #145", QStringLiteral("://smart_pattern_#145/input.json"), + QStringLiteral("://smart_pattern_#145/output.json"), 37.795275590551185 /*seam allowance width*/); // See private test cases in file valentina_private_collection/bugs/women_jacket/women_jacket.val // Point A38, size 32 - ASSERT_TEST_CASE("women_jacket_A38", - QStringLiteral("://women_jacket/input.json"), - QStringLiteral("://women_jacket/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("women_jacket_A38", QStringLiteral("://women_jacket/input.json"), + QStringLiteral("://women_jacket/output.json"), 37.795275590551185 /*seam allowance width*/); // See private test cases in file valentina_private_collection/bugs/hood_1/hood_1.val - ASSERT_TEST_CASE("hood_1", - QStringLiteral("://hood_1/input.json"), - QStringLiteral("://hood_1/output.json"), + ASSERT_TEST_CASE("hood_1", QStringLiteral("://hood_1/input.json"), QStringLiteral("://hood_1/output.json"), 37.795275590551185 /*seam allowance width*/); // See private test cases in file valentina_private_collection/bugs/hood_2/hood_2.val - ASSERT_TEST_CASE("hood_2", - QStringLiteral("://hood_2/input.json"), - QStringLiteral("://hood_2/output.json"), + ASSERT_TEST_CASE("hood_2", QStringLiteral("://hood_2/input.json"), QStringLiteral("://hood_2/output.json"), 37.795275590551185 /*seam allowance width*/); // See the file "collection/bugs/smart_pattern_#184_case1.val" - ASSERT_TEST_CASE("Issue #184 case 1", - QStringLiteral("://smart_pattern_#184_case1/input.json"), + ASSERT_TEST_CASE("Issue #184 case 1", QStringLiteral("://smart_pattern_#184_case1/input.json"), QStringLiteral("://smart_pattern_#184_case1/output.json"), 0.88157480314960635 /*seam allowance width*/); // See the file "collection/bugs/smart_pattern_#184_case2.val" - ASSERT_TEST_CASE("Issue #184 case 2", - QStringLiteral("://smart_pattern_#184_case2/input.json"), + ASSERT_TEST_CASE("Issue #184 case 2", QStringLiteral("://smart_pattern_#184_case2/input.json"), QStringLiteral("://smart_pattern_#184_case2/output.json"), 37.795275590551185 /*seam allowance width*/); // See the file "valentina_private_collection/bugs/custom_seam_allwance_exclude/custom_seam_allwance_exclude.val" - ASSERT_TEST_CASE("Piece 1. CSA Exclude", - QStringLiteral("://custom_seam_allwance_exclude_p1/input.json"), + ASSERT_TEST_CASE("Piece 1. CSA Exclude", QStringLiteral("://custom_seam_allwance_exclude_p1/input.json"), QStringLiteral("://custom_seam_allwance_exclude_p1/output.json"), 37.795275590551185 /*seam allowance width 1 cm*/); // See the file "valentina_private_collection/bugs/custom_seam_allwance_exclude/custom_seam_allwance_exclude.val" - ASSERT_TEST_CASE("Piece 2. CSA Exclude", - QStringLiteral("://custom_seam_allwance_exclude_p2/input.json"), + ASSERT_TEST_CASE("Piece 2. CSA Exclude", QStringLiteral("://custom_seam_allwance_exclude_p2/input.json"), QStringLiteral("://custom_seam_allwance_exclude_p2/output.json"), 37.795275590551185 /*seam allowance width 1 cm*/); } @@ -1037,7 +958,7 @@ void TST_VAbstractPiece::BrokenDetailEquidistant() const QFETCH(QVector, ekvOrig); QVector ekv; - CastTo(VAbstractPiece::Equidistant(points, width, QString()), ekv);// Take result + CastTo(VAbstractPiece::Equidistant(points, width, QString()), ekv); // Take result // Begin comparison ComparePaths(ekv, ekvOrig); @@ -1058,93 +979,63 @@ void TST_VAbstractPiece::EquidistantAngleType_data() }; // See the file "collection/bugs/Issue_#880.val" - ASSERT_TEST_CASE("Issue #880. Piece: Detail.", - QStringLiteral("://Issue_880_Detail/input.json"), - QStringLiteral("://Issue_880_Detail/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue #880. Piece: Detail.", QStringLiteral("://Issue_880_Detail/input.json"), + QStringLiteral("://Issue_880_Detail/output.json"), 37.795275590551185 /*seam allowance width*/); // See the file "collection/bugs/Issue_#880.val" - ASSERT_TEST_CASE("Issue #880. Piece: Detail_1.", - QStringLiteral("://Issue_880_Detail_1/input.json"), - QStringLiteral("://Issue_880_Detail_1/output.json"), - 75.59055118110237 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue #880. Piece: Detail_1.", QStringLiteral("://Issue_880_Detail_1/input.json"), + QStringLiteral("://Issue_880_Detail_1/output.json"), 75.59055118110237 /*seam allowance width*/); // See file src/app/share/collection/bugs/Issue_#937.val - ASSERT_TEST_CASE("Issue 937. Case1", - QStringLiteral("://Issue_937_case_1/input.json"), - QStringLiteral("://Issue_937_case_1/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue 937. Case1", QStringLiteral("://Issue_937_case_1/input.json"), + QStringLiteral("://Issue_937_case_1/output.json"), 37.795275590551185 /*seam allowance width*/); // See file src/app/share/collection/bugs/Issue_#937a.val - ASSERT_TEST_CASE("Issue 937. Case1a", - QStringLiteral("://Issue_937_case_1a/input.json"), - QStringLiteral("://Issue_937_case_1a/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue 937. Case1a", QStringLiteral("://Issue_937_case_1a/input.json"), + QStringLiteral("://Issue_937_case_1a/output.json"), 37.795275590551185 /*seam allowance width*/); // See file src/app/share/collection/bugs/Issue_#937.val - ASSERT_TEST_CASE("Issue 937. Case2", - QStringLiteral("://Issue_937_case_2/input.json"), - QStringLiteral("://Issue_937_case_2/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue 937. Case2", QStringLiteral("://Issue_937_case_2/input.json"), + QStringLiteral("://Issue_937_case_2/output.json"), 37.795275590551185 /*seam allowance width*/); // See file src/app/share/collection/bugs/Issue_#937.val - ASSERT_TEST_CASE("Issue 937. Case3", - QStringLiteral("://Issue_937_case_3/input.json"), - QStringLiteral("://Issue_937_case_3/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue 937. Case3", QStringLiteral("://Issue_937_case_3/input.json"), + QStringLiteral("://Issue_937_case_3/output.json"), 37.795275590551185 /*seam allowance width*/); // See file src/app/share/collection/bugs/Issue_#937.val - ASSERT_TEST_CASE("Issue 937. Case4", - QStringLiteral("://Issue_937_case_4/input.json"), - QStringLiteral("://Issue_937_case_4/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue 937. Case4", QStringLiteral("://Issue_937_case_4/input.json"), + QStringLiteral("://Issue_937_case_4/output.json"), 37.795275590551185 /*seam allowance width*/); // See file src/app/share/collection/bugs/Issue_#937_case5.val - ASSERT_TEST_CASE("Issue 937. Case5", - QStringLiteral("://Issue_937_case_5/input.json"), - QStringLiteral("://Issue_937_case_5/output.json"), - 37.795275590551185 /*seam allowance width*/); + ASSERT_TEST_CASE("Issue 937. Case5", QStringLiteral("://Issue_937_case_5/input.json"), + QStringLiteral("://Issue_937_case_5/output.json"), 37.795275590551185 /*seam allowance width*/); // See file valentina_private_collection/bugs/busty/busty.val - ASSERT_TEST_CASE("Busty", - QStringLiteral("://busty/input.json"), - QStringLiteral("://busty/output.json"), + ASSERT_TEST_CASE("Busty", QStringLiteral("://busty/input.json"), QStringLiteral("://busty/output.json"), 0 /*seam allowance width*/); // See file valentina_private_collection/bugs/panties/panties.val - ASSERT_TEST_CASE("Panties. Piece Case 1", - QStringLiteral("://panties_case1/input.json"), - QStringLiteral("://panties_case1/output.json"), - 26.45669291338583 /*seam allowance width*/); + ASSERT_TEST_CASE("Panties. Piece Case 1", QStringLiteral("://panties_case1/input.json"), + QStringLiteral("://panties_case1/output.json"), 26.45669291338583 /*seam allowance width*/); // See file valentina_private_collection/bugs/panties/panties.val - ASSERT_TEST_CASE("Panties. Piece Case 2", - QStringLiteral("://panties_case2/input.json"), - QStringLiteral("://panties_case2/output.json"), - 26.45669291338583 /*seam allowance width*/); + ASSERT_TEST_CASE("Panties. Piece Case 2", QStringLiteral("://panties_case2/input.json"), + QStringLiteral("://panties_case2/output.json"), 26.45669291338583 /*seam allowance width*/); // See file valentina_private_collection/bugs/smart_pattern_#113/smart_pattern_#113.val - ASSERT_TEST_CASE("Эдит 6", - QStringLiteral("://smart_pattern_#113/input.json"), - QStringLiteral("://smart_pattern_#113/output.json"), - 0.56692913385826771 /*seam allowance width*/); + ASSERT_TEST_CASE("Эдит 6", QStringLiteral("://smart_pattern_#113/input.json"), + QStringLiteral("://smart_pattern_#113/output.json"), 0.56692913385826771 /*seam allowance width*/); // See file valentina_private_collection/bugs/smart_pattern_#118/smart_pattern_#118.val - ASSERT_TEST_CASE("Ретро стринги 3", - QStringLiteral("://smart_pattern_#118/input.json"), - QStringLiteral("://smart_pattern_#118/output.json"), - 26.45669291338583 /*seam allowance width*/); + ASSERT_TEST_CASE("Ретро стринги 3", QStringLiteral("://smart_pattern_#118/input.json"), + QStringLiteral("://smart_pattern_#118/output.json"), 26.45669291338583 /*seam allowance width*/); // See file valentina_private_collection/bugs/smart_pattern_#133/smart_pattern_#133.val - ASSERT_TEST_CASE("Эдит 1", - QStringLiteral("://smart_pattern_#133/input.json"), - QStringLiteral("://smart_pattern_#133/output.json"), - 26.45669291338583 /*seam allowance width*/); + ASSERT_TEST_CASE("Эдит 1", QStringLiteral("://smart_pattern_#133/input.json"), + QStringLiteral("://smart_pattern_#133/output.json"), 26.45669291338583 /*seam allowance width*/); // See file valentina_private_collection/bugs/hat/hat.val - ASSERT_TEST_CASE("hat", - QStringLiteral("://hat/input.json"), - QStringLiteral("://hat/output.json"), + ASSERT_TEST_CASE("hat", QStringLiteral("://hat/input.json"), QStringLiteral("://hat/output.json"), 26.45669291338583 /*seam allowance width*/); } @@ -1156,7 +1047,7 @@ void TST_VAbstractPiece::EquidistantAngleType() const QFETCH(QVector, ekvOrig); QVector ekv; - CastTo(VAbstractPiece::Equidistant(points, width, QString()), ekv);// Take result + CastTo(VAbstractPiece::Equidistant(points, width, QString()), ekv); // Take result // Begin comparison ComparePaths(ekv, ekvOrig); @@ -1213,13 +1104,11 @@ void TST_VAbstractPiece::TestCorrectEquidistantPoints_data() }; // See file src/app/share/collection/bugs/Steampunk_trousers_issue_#548.val - ASSERT_TEST_CASE("Test case issue #548", - QStringLiteral("://Issue_548/input.json"), + ASSERT_TEST_CASE("Test case issue #548", QStringLiteral("://Issue_548/input.json"), QStringLiteral("://Issue_548/output.json")); // See the file "collection/bugs/Issue_#642.val" - ASSERT_TEST_CASE("Test case issue #642", - QStringLiteral("://Issue_642/input.json"), + ASSERT_TEST_CASE("Test case issue #642", QStringLiteral("://Issue_642/input.json"), QStringLiteral("://Issue_642/output.json")); } @@ -1361,14 +1250,12 @@ void TST_VAbstractPiece::IsAllowanceValid_data() const { QVector basePoints = AbstractTest::VectorFromJson(base); QVector allowancePoints = AbstractTest::VectorFromJson(allowance); - QTest::newRow(title) << basePoints << allowancePoints << valid ; + QTest::newRow(title) << basePoints << allowancePoints << valid; }; // See file src/app/share/collection/valid_allowance/case3.val (private collection) - ASSERT_TEST_CASE("Valid seam allowance. Case 3", - QStringLiteral("://valid_allowance_case3/base.json"), - QStringLiteral("://valid_allowance_case3/allowance.json"), - true); + ASSERT_TEST_CASE("Valid seam allowance. Case 3", QStringLiteral("://valid_allowance_case3/base.json"), + QStringLiteral("://valid_allowance_case3/allowance.json"), true); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/test/ValentinaTest/tst_varc.cpp b/src/test/ValentinaTest/tst_varc.cpp index 8c45f793a..9f4d4785f 100644 --- a/src/test/ValentinaTest/tst_varc.cpp +++ b/src/test/ValentinaTest/tst_varc.cpp @@ -38,28 +38,33 @@ void PrepareTestCase(const QPointF ¢er, qreal startAngle, qreal endAngle) { qreal radius = UnitConvertor(1, Unit::Cm, Unit::Px); const qreal threshold = UnitConvertor(2000, Unit::Cm, Unit::Px); - while(radius <= threshold) + while (radius <= threshold) { VArc arc(VPointF(center), radius, startAngle, endAngle); const QVector points = arc.GetPoints(); const QString testStartAngle = QString("Test start angel. Arc radius %1, start angle %2, end angle %3") - .arg(radius).arg(startAngle).arg(endAngle); + .arg(radius) + .arg(startAngle) + .arg(endAngle); QTest::newRow(qUtf8Printable(testStartAngle)) << center << startAngle << points << ConstFirst(points) << true; const QString testEndAngle = QString("Test end angel. Arc radius %1, start angle %2, end angle %3") - .arg(radius).arg(startAngle).arg(endAngle); + .arg(radius) + .arg(startAngle) + .arg(endAngle); QTest::newRow(qUtf8Printable(testEndAngle)) << center << endAngle << points << ConstLast(points) << true; radius += UnitConvertor(5, Unit::Cm, Unit::Px); } } -} // namespace +} // namespace //--------------------------------------------------------------------------------------------------------------------- TST_VArc::TST_VArc(QObject *parent) - :AbstractTest(parent) -{} + : AbstractTest(parent) +{ +} //--------------------------------------------------------------------------------------------------------------------- // cppcheck-suppress unusedFunction @@ -69,7 +74,7 @@ void TST_VArc::CompareTwoWays() const qreal radius = 100; const qreal f1 = 1; const qreal f2 = 46; - const qreal length = M_PI*radius/180*(f2-f1); + const qreal length = M_PI * radius / 180 * (f2 - f1); VArc arc1(center, radius, f1, f2); VArc arc2(length, center, radius, f1); @@ -92,7 +97,7 @@ void TST_VArc::NegativeArc() const qreal radius = 100; const qreal f1 = 1; const qreal f2 = 316; - const qreal length = M_PI*radius/180*45; + const qreal length = M_PI * radius / 180 * 45; VArc arc(-length, center, radius, f1); QCOMPARE(arc.GetLength(), -length); @@ -209,30 +214,31 @@ void TST_VArc::TestGetPoints() const qreal value = qAbs(rLine.length() - radius); // cppcheck-suppress unreadVariable const QString errorMsg = QString("Broken the first rule. All points should be on the same distance from " - "the center. Error ='%1'.").arg(value); + "the center. Error ='%1'.") + .arg(value); QVERIFY2(value <= epsRadius, qUtf8Printable(errorMsg)); } } { - qreal gSquare = 0.0;// geometry square + qreal gSquare = 0.0; // geometry square if (VFuzzyComparePossibleNulls(arc.AngleArc(), 360.0)) - {// circle square + { // circle square gSquare = M_PI * radius * radius; } else - {// sector square + { // sector square gSquare = (M_PI * radius * radius) / 360.0 * arc.AngleArc(); points.append(static_cast(center)); } // calculated square - const qreal cSquare = qAbs(VAbstractPiece::SumTrapezoids(points)/2.0); + const qreal cSquare = qAbs(VAbstractPiece::SumTrapezoids(points) / 2.0); const qreal value = qAbs(gSquare - cSquare); // cppcheck-suppress unreadVariable const QString errorMsg = - QString("Broken the second rule. Interpolation has too big computing error. Error ='%1'.").arg(value); + QString("Broken the second rule. Interpolation has too big computing error. Error ='%1'.").arg(value); const qreal epsSquare = gSquare * 0.24 / 100; // computing error 0.24 % from origin square QVERIFY2(value <= epsSquare, qUtf8Printable(errorMsg)); } @@ -311,7 +317,7 @@ void TST_VArc::TestFlip_data() l.setAngle(225); p1 = l.p2(); - l.setAngle(45+90); + l.setAngle(45 + 90); l.setLength(5); const QPointF p1Axis = l.p2(); @@ -341,7 +347,7 @@ void TST_VArc::TestFlip() QVERIFY2(res.IsFlipped(), qUtf8Printable("The arc is not flipped")); - QCOMPARE(originArc.GetLength()*-1, res.GetLength()); + QCOMPARE(originArc.GetLength() * -1, res.GetLength()); QCOMPARE(originArc.GetRadius(), res.GetRadius()); QCOMPARE(originArc.AngleArc(), res.AngleArc()); } @@ -356,7 +362,7 @@ void TST_VArc::TestCutArc_data() QTest::addColumn("cutLength"); QTest::addColumn("cutPoint"); - QPointF center (189.13625196850393, 344.1267401574803); + QPointF center(189.13625196850393, 344.1267401574803); qreal radius = ToPixel(10, Unit::Cm); qreal startAngle = 45.0; qreal length = ToPixel(-10, Unit::Cm); @@ -364,14 +370,14 @@ void TST_VArc::TestCutArc_data() QPointF cutPoint(539.3657292513009, 202.04366960088566); // See file /src/app/share/collection/bugs/Issue_#957.val - QTest::newRow("Arc -10 cm length, cut length 6 cm") << center << radius << startAngle << length << cutLength - << cutPoint; + QTest::newRow("Arc -10 cm length, cut length 6 cm") + << center << radius << startAngle << length << cutLength << cutPoint; cutLength = ToPixel(-4, Unit::Cm); // Opposite case - QTest::newRow("Arc -10 cm length, cut length -4 cm") << center << radius << startAngle << length << cutLength - << cutPoint; + QTest::newRow("Arc -10 cm length, cut length -4 cm") + << center << radius << startAngle << length << cutLength << cutPoint; startAngle = 135; length = ToPixel(10, Unit::Cm); @@ -379,13 +385,13 @@ void TST_VArc::TestCutArc_data() cutPoint = QPointF(-145.1588983496871, 167.78888781060192); // See file /src/app/share/collection/bugs/Issue_#957.val - QTest::newRow("Arc 10 cm length, cut length -7 cm") << center << radius << startAngle << length << cutLength - << cutPoint; + QTest::newRow("Arc 10 cm length, cut length -7 cm") + << center << radius << startAngle << length << cutLength << cutPoint; // Opposite case cutLength = ToPixel(3, Unit::Cm); - QTest::newRow("Arc 10 cm length, cut length 3 cm") << center << radius << startAngle << length << cutLength - << cutPoint; + QTest::newRow("Arc 10 cm length, cut length 3 cm") + << center << radius << startAngle << length << cutLength << cutPoint; } //--------------------------------------------------------------------------------------------------------------------- @@ -398,7 +404,7 @@ void TST_VArc::TestCutArc() QFETCH(qreal, cutLength); QFETCH(QPointF, cutPoint); - VArc arc (length, VPointF(center), radius, startAngle); + VArc arc(length, VPointF(center), radius, startAngle); arc.SetApproximationScale(0.5); VArc arc1; diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp index b717b83c5..6be82d326 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.cpp +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -34,8 +34,10 @@ #include //--------------------------------------------------------------------------------------------------------------------- -TST_VEllipticalArc::TST_VEllipticalArc(QObject *parent) : AbstractTest(parent) -{} +TST_VEllipticalArc::TST_VEllipticalArc(QObject *parent) + : AbstractTest(parent) +{ +} //--------------------------------------------------------------------------------------------------------------------- void TST_VEllipticalArc::CompareTwoWays_data() @@ -87,7 +89,7 @@ void TST_VEllipticalArc::CompareTwoWays() // cppcheck-suppress unreadVariable QString errorLengthMsg = - QString("Difference between real and computing lengthes bigger than eps = %1. l1 = %2; l2 = %3"); + QString("Difference between real and computing lengthes bigger than eps = %1. l1 = %2; l2 = %3"); QVERIFY2(qAbs(arc2.GetLength() - length) <= lengthEps, qUtf8Printable(errorLengthMsg.arg(lengthEps).arg(arc2.GetLength()).arg(length))); QVERIFY2(qAbs(arc1.GetLength() - arc2.GetLength()) <= lengthEps, @@ -96,10 +98,10 @@ void TST_VEllipticalArc::CompareTwoWays() const qreal angleEps = 0.4; // cppcheck-suppress unreadVariable const QString errorAngleMsg = - QString("Difference between real and computing angles bigger than eps = %1. f1 = %2; f2 = %3"); + QString("Difference between real and computing angles bigger than eps = %1. f1 = %2; f2 = %3"); // compare angles const qreal diff = qAbs(arc1.GetEndAngle() - arc2.GetEndAngle()); - QVERIFY2(qAbs(diff - 360.0*(diff/360.0)) <= angleEps, + QVERIFY2(qAbs(diff - 360.0 * (diff / 360.0)) <= angleEps, qUtf8Printable(errorAngleMsg.arg(angleEps).arg(arc1.GetEndAngle()).arg(arc2.GetEndAngle()))); } @@ -115,21 +117,19 @@ void TST_VEllipticalArc::NegativeArc() const qreal rotationAngle = 0; // Full ellipse - const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); - const qreal length = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h)))/2; + const qreal h = ((radius1 - radius2) * (radius1 - radius2)) / ((radius1 + radius2) * (radius1 + radius2)); + const qreal length = M_PI * (radius1 + radius2) * (1 + 3 * h / (10 + qSqrt(4 - 3 * h))) / 2; VEllipticalArc arc(-length, center, radius1, radius2, f1, rotationAngle); const qreal eps = ToPixel(0.45, Unit::Mm); // computing error // cppcheck-suppress unreadVariable const QString errorMsg = - QString("Difference between real and computing lengthes bigger than eps = %1. v1 = %2; v2 = %3"); + QString("Difference between real and computing lengthes bigger than eps = %1. v1 = %2; v2 = %3"); - QVERIFY2(qAbs(arc.GetLength() + length) <= eps, - qUtf8Printable(errorMsg.arg(eps).arg(arc.GetLength()).arg(length))); + QVERIFY2(qAbs(arc.GetLength() + length) <= eps, qUtf8Printable(errorMsg.arg(eps).arg(arc.GetLength()).arg(length))); const qreal angleEps = 0.4; - QVERIFY2(arc.GetEndAngle() - f2 <= angleEps, - qUtf8Printable(errorMsg.arg(eps).arg(arc.GetEndAngle()).arg(f2))); + QVERIFY2(arc.GetEndAngle() - f2 <= angleEps, qUtf8Printable(errorMsg.arg(eps).arg(arc.GetEndAngle()).arg(f2))); } // cppcheck-suppress unusedFunction @@ -171,23 +171,23 @@ void TST_VEllipticalArc::TestData() QTest::newRow("Full circle: radiuses 150, 200, rotation 30; start 0") << 150.0 << 200.0 << 0.0 << 360.0 << 30.0; QTest::newRow("Full circle: radiuses 1500, 1000; start 0") << 1500.0 << 1000.0 << 0.0 << 360.0 << 0.0; QTest::newRow("Full circle: radiuses 1500, 1000, rotation 50; start 0") << 1500.0 << 1000.0 << 0.0 << 360.0 << 50.0; - QTest::newRow("Full circle: radiuses 15000, 10000, rotation 90; start 0") << 15000.0 << 10000.0 << 0.0 << 360.0 - << 90.0; + QTest::newRow("Full circle: radiuses 15000, 10000, rotation 90; start 0") + << 15000.0 << 10000.0 << 0.0 << 360.0 << 90.0; QTest::newRow("Full circle: radiuses 10, 20; start 90") << 10.0 << 20.0 << 90.0 << 90.0 << 0.0; QTest::newRow("Full circle: radiuses 150, 200; start 90") << 150.0 << 200.0 << 90.0 << 90.0 << 0.0; QTest::newRow("Full circle: radiuses 150, 200, rotation 30; start 90") << 150.0 << 200.0 << 90.0 << 90.0 << 30.0; QTest::newRow("Full circle: radiuses 1500, 1000; start 90") << 1500.0 << 1000.0 << 90.0 << 90.0 << 0.0; - QTest::newRow("Full circle: radiuses 1500, 1000, rotation 50; start 90") << 1500.0 << 1000.0 << 90.0 << 90.0 - << 50.0; - QTest::newRow("Full circle: radiuses 15000, 10000, rotation 90; start 90") << 15000.0 << 10000.0 << 90.0 << 90.0 - << 90.0; + QTest::newRow("Full circle: radiuses 1500, 1000, rotation 50; start 90") + << 1500.0 << 1000.0 << 90.0 << 90.0 << 50.0; + QTest::newRow("Full circle: radiuses 15000, 10000, rotation 90; start 90") + << 15000.0 << 10000.0 << 90.0 << 90.0 << 90.0; QTest::newRow("Arc less than 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 10.5 << 0.0; QTest::newRow("Arc less than 45 degree, radiuses 150, 50, rotation 180") << 150.0 << 50.0 << 0.0 << 10.5 << 180.0; QTest::newRow("Arc less than 45 degree, radiuses 1500, 800, rotation 90") << 1500.0 << 800.0 << 0.0 << 10.5 << 90.0; QTest::newRow("Arc less than 45 degree, radiuses 15000, 10000, rotation 40") - << 50000.0 << 10000.0 << 0.0 << 10.5 << 40.0; + << 50000.0 << 10000.0 << 0.0 << 10.5 << 40.0; QTest::newRow("Arc less than 45 degree, radiuses 15000, 10000") << 15000.0 << 10000.0 << 0.0 << 10.5 << 0.0; QTest::newRow("Arc 45 degree, radiuses 100, 50, rotation 45") << 100.0 << 50.0 << 0.0 << 45.0 << 45.0; @@ -199,11 +199,11 @@ void TST_VEllipticalArc::TestData() QTest::newRow("Arc less than 90 degree, radiuses 100, 400, rotation 50") << 100.0 << 400.0 << 0.0 << 75.0 << 50.0; QTest::newRow("Arc less than 90 degree, radiuses 150, 400, rotation 90") << 150.0 << 400.0 << 0.0 << 75.0 << 90.0; QTest::newRow("Arc less than 90 degree, radiuses 1500, 50000, rotation 180") - << 1500.0 << 50000.0 << 0.0 << 75.0 << 180.0; + << 1500.0 << 50000.0 << 0.0 << 75.0 << 180.0; QTest::newRow("Arc less than 90 degree, radiuses 50000, 5000, rotation 30") - << 50000.0 << 5000.0 << 0.0 << 75.0 << 30.0; + << 50000.0 << 5000.0 << 0.0 << 75.0 << 30.0; QTest::newRow("Arc less than 90 degree, radiuses 90000, 50000, rotation 30") - << 90000.0 << 50000.0 << 0.0 << 75.0 << 30.0; + << 90000.0 << 50000.0 << 0.0 << 75.0 << 30.0; QTest::newRow("Arc 90 degree, radiuses 100, 50, rotation 30") << 100.0 << 50.0 << 0.0 << 90.0 << 30.0; QTest::newRow("Arc 90 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 90.0 << 0.0; @@ -213,11 +213,11 @@ void TST_VEllipticalArc::TestData() QTest::newRow("Arc less than 135 degree, radiuses 100, 50, rotation 60") << 100.0 << 50.0 << 0.0 << 110.6 << 60.0; QTest::newRow("Arc less than 135 degree, radiuses 150, 400, rotation 300") - << 150.0 << 400.0 << 0.0 << 110.6 << 300.0; + << 150.0 << 400.0 << 0.0 << 110.6 << 300.0; QTest::newRow("Arc less than 135 degree, radiuses 1500, 800, rotation 360") - << 1500.0 << 800.0 << 0.0 << 110.6 << 360.0; + << 1500.0 << 800.0 << 0.0 << 110.6 << 360.0; QTest::newRow("Arc less than 135 degree, radiuses 15000, 1500, rotation 290") - << 15000.0 << 1500.0 << 0.0 << 110.6 << 290.0; + << 15000.0 << 1500.0 << 0.0 << 110.6 << 290.0; QTest::newRow("Arc less than 135 degree, radiuses 15000, 1500") << 15000.0 << 1500.0 << 0.0 << 110.6 << 0.0; QTest::newRow("Arc 135 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 135.0 << 0.0; @@ -230,7 +230,7 @@ void TST_VEllipticalArc::TestData() QTest::newRow("Arc less than 180 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 160.7 << 0.0; QTest::newRow("Arc less than 180 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 160.7 << 0.0; QTest::newRow("Arc less than 180 degree, radiuses 15000, 1500, rotation 270") - << 15000.0 << 1500.0 << 0.0 << 160.7 << 270.0; + << 15000.0 << 1500.0 << 0.0 << 160.7 << 270.0; QTest::newRow("Arc less than 180 degree, radiuses 15000, 10000") << 15000.0 << 10000.0 << 0.0 << 160.7 << 0.0; QTest::newRow("Arc 180 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 180.0 << 0.0; @@ -243,7 +243,7 @@ void TST_VEllipticalArc::TestData() QTest::newRow("Arc less than 270 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 150.3 << 0.0; QTest::newRow("Arc less than 270 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 150.3 << 0.0; QTest::newRow("Arc less than 270 degree, radiuses 15000, 1500, rotation 20") - << 15000.0 << 1500.0 << 0.0 << 150.3 << 20.0; + << 15000.0 << 1500.0 << 0.0 << 150.3 << 20.0; QTest::newRow("Arc less than 270 degree, radiuses 15000, 10000") << 15000.0 << 10000.0 << 0.0 << 150.3 << 0.0; QTest::newRow("Arc 270 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 270.0 << 0.0; @@ -256,24 +256,24 @@ void TST_VEllipticalArc::TestData() QTest::newRow("Arc less than 360 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 340.0 << 0.0; QTest::newRow("Arc less than 360 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 340.0 << 0.0; QTest::newRow("Arc less than 360 degree, radiuses 12000, 1200, rotation 30") - << 12000.0 << 1200.0 << 0.0 << 340.0 << 30.0; + << 12000.0 << 1200.0 << 0.0 << 340.0 << 30.0; QTest::newRow("Arc less than 360 degree, radiuses 12000, 10000") << 15000.0 << 10000.0 << 0.0 << 340.0 << 0.0; QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 90.0 << 135.0 << 0.0; QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 150, 400") << 150.0 << 400.0 << 90.0 << 135.0 << 0.0; QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 1500, 800") - << 1500.0 << 800.0 << 90.0 << 135.0 << 0.0; + << 1500.0 << 800.0 << 90.0 << 135.0 << 0.0; QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 13000, 1000") - << 15000.0 << 1000.0 << 90.0 << 135.0 << 0.0; + << 15000.0 << 1000.0 << 90.0 << 135.0 << 0.0; QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 15000, 10000") - << 15000.0 << 10000.0 << 90.0 << 135.0 << 0.0; + << 15000.0 << 10000.0 << 90.0 << 135.0 << 0.0; } //--------------------------------------------------------------------------------------------------------------------- // cppcheck-suppress unusedFunction void TST_VEllipticalArc::TestGetPoints1() { - //Any point must satisfy the equation of ellipse + // Any point must satisfy the equation of ellipse QFETCH(qreal, radius1); QFETCH(qreal, radius2); QFETCH(qreal, startAngle); @@ -291,12 +291,14 @@ void TST_VEllipticalArc::TestGetPoints1() for (auto p : points) { - const qreal equationRes = p.rx()*p.rx()/(radius1*radius1) + p.ry()*p.ry()/(radius2*radius2); + const qreal equationRes = p.rx() * p.rx() / (radius1 * radius1) + p.ry() * p.ry() / (radius2 * radius2); const qreal diff = qAbs(equationRes - 1); // cppcheck-suppress unreadVariable const QString errorMsg = QString("Broken the first rule. Any point must satisfy the equation of ellipse." - "diff = '%1' > eps = '%2'").number(diff).number(eps); - QVERIFY2( diff <= eps, qUtf8Printable(errorMsg)); + "diff = '%1' > eps = '%2'") + .number(diff) + .number(eps); + QVERIFY2(diff <= eps, qUtf8Printable(errorMsg)); } } } @@ -317,7 +319,7 @@ void TST_VEllipticalArc::TestGetPoints2() arc.SetApproximationScale(maxCurveApproximationScale); QVector points = arc.GetPoints(); - const qreal c = qSqrt(qAbs(radius2*radius2 - radius1*radius1)); + const qreal c = qSqrt(qAbs(radius2 * radius2 - radius1 * radius1)); // distance from the center to the focus QPointF focus1 = static_cast(center); @@ -358,19 +360,23 @@ void TST_VEllipticalArc::TestGetPoints2() const qreal distance = distance1.length() + distance2.length(); const qreal eps = distance * 1.1 / 100; // computing error 1.1 % from origin distance - for (int i=0; i < points.size(); ++i) + for (int i = 0; i < points.size(); ++i) { const QLineF rLine1(focus1, points.at(i)); const QLineF rLine2(focus2, points.at(i)); - const qreal resultingDistance = rLine1.length()+rLine2.length(); + const qreal resultingDistance = rLine1.length() + rLine2.length(); const qreal diff = qAbs(resultingDistance - distance); // cppcheck-suppress unreadVariable const QString errorMsg = QString("Broken the first rule, part 2. Distance from the any point to the focus1" " plus distance from this point to the focus2 should be the same. Problem" " with point '%1'. The disired distance is '%2', but resulting distance" - " is '%3'. Difference is '%4' and it biggest than eps '%5')").number(i) - .number(distance).number(resultingDistance).number(diff).number(eps); - QVERIFY2( diff <= eps, qUtf8Printable(errorMsg)); + " is '%3'. Difference is '%4' and it biggest than eps '%5')") + .number(i) + .number(distance) + .number(resultingDistance) + .number(diff) + .number(eps); + QVERIFY2(diff <= eps, qUtf8Printable(errorMsg)); } } @@ -391,14 +397,16 @@ void TST_VEllipticalArc::TestGetPoints3() QVector points = arc.GetPoints(); if (VFuzzyComparePossibleNulls(arc.AngleArc(), 360.0)) - {// calculated full ellipse square + { // calculated full ellipse square const qreal ellipseSquare = M_PI * radius1 * radius2; const qreal epsSquare = ellipseSquare * 1.7 / 100; // computing error 1.7 % from origin square - const qreal arcSquare = qAbs(VAbstractPiece::SumTrapezoids(points)/2.0); + const qreal arcSquare = qAbs(VAbstractPiece::SumTrapezoids(points) / 2.0); const qreal diffSquare = qAbs(ellipseSquare - arcSquare); // cppcheck-suppress unreadVariable const QString errorMsg1 = QString("Broken the second rule. Interpolation has too big computing error. " - "Difference ='%1' bigger than eps = '%2'.").arg(diffSquare).arg(epsSquare); + "Difference ='%1' bigger than eps = '%2'.") + .arg(diffSquare) + .arg(epsSquare); QVERIFY2(diffSquare <= epsSquare, qUtf8Printable(errorMsg1)); } } @@ -419,15 +427,17 @@ void TST_VEllipticalArc::TestGetPoints4() arc.SetApproximationScale(maxCurveApproximationScale); if (VFuzzyComparePossibleNulls(arc.AngleArc(), 360.0)) - {// calculated full ellipse length - const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); - const qreal ellipseLength = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h))); + { // calculated full ellipse length + const qreal h = ((radius1 - radius2) * (radius1 - radius2)) / ((radius1 + radius2) * (radius1 + radius2)); + const qreal ellipseLength = M_PI * (radius1 + radius2) * (1 + 3 * h / (10 + qSqrt(4 - 3 * h))); const qreal epsLength = ToPixel(1, Unit::Mm); // computing error const qreal arcLength = VEllipticalArc(center, radius1, radius2, 0, 360, 0).GetLength(); const qreal diffLength = qAbs(arcLength - ellipseLength); // cppcheck-suppress unreadVariable const QString errorMsg2 = QString("Difference between real and computing lengthes " - "(diff = '%1') bigger than eps = '%2'.").arg(diffLength).arg(epsLength); + "(diff = '%1') bigger than eps = '%2'.") + .arg(diffLength) + .arg(epsLength); QVERIFY2(diffLength <= epsLength, qUtf8Printable(errorMsg2)); } } @@ -452,8 +462,8 @@ void TST_VEllipticalArc::TestGetPoints5() VEllipticalArc arc(center, radius1, radius2, startAngle, endAngle, rotationAngle); arc.SetApproximationScale(maxCurveApproximationScale); - const qreal stAngle = VEllipticalArc::OptimizeAngle(arc.GetStartAngle()+arc.GetRotationAngle()); - const qreal enAngle = VEllipticalArc::OptimizeAngle(arc.GetEndAngle()+arc.GetRotationAngle()); + const qreal stAngle = VEllipticalArc::OptimizeAngle(arc.GetStartAngle() + arc.GetRotationAngle()); + const qreal enAngle = VEllipticalArc::OptimizeAngle(arc.GetEndAngle() + arc.GetRotationAngle()); qreal f1 = QLineF(static_cast(center), arc.GetP1()).angle(); if ((qFuzzyIsNull(f1) && VFuzzyComparePossibleNulls(360, stAngle)) || @@ -503,17 +513,17 @@ void TST_VEllipticalArc::TestRotation_data() QTest::addColumn("degrees"); QTest::addColumn("prefix"); - QTest::newRow("Test el arc 1") << QPointF() << 10. << 20.0 << 1. << 91. << 0.<< QPointF() << 90. << "_r"; - QTest::newRow("Test el arc 2") << QPointF() << 10. << 20.0 << 0. << 90. << 0.<< QPointF() << 90. << "_r"; - QTest::newRow("Test el arc 3.2") << QPointF(10, 10) << 10. << 20.0 << 0. << 90. << 0.<< QPointF() << 90. << "_r"; - QTest::newRow("Test el arc 3.1") << QPointF(10, 10) << 10. << 20.0 << 1. << 91. << 0.<< QPointF() << 90. << "_r"; - QTest::newRow("Test el arc 3") << QPointF(10, 10) << 10. << 20.0 << 1. << 91. << 90.<< QPointF() << 90. << "_r"; - QTest::newRow("Test el arc 4") << QPointF(10, 10) << 10. << 20.0 << 0. << 90. << 90.<< QPointF() << 90. << "_r"; - QTest::newRow("Test el arc 5") << QPointF(10, 10) << 10. << 20.0 << 0. << 180. << 90.<< QPointF() << 90. << "_r"; - QTest::newRow("Test el arc 6") << QPointF(10, 10) << 10. << 20.0 << 1. << 181. << 90.<< QPointF() << 90. << "_r"; - QTest::newRow("Test el arc 7") << QPointF(10, 10) << 10. << 20.0 << 0. << 270. << 90.<< QPointF() << 90. << "_r"; - QTest::newRow("Test el arc 8") << QPointF(10, 10) << 10. << 20.0 << 1. << 271. << 90.<< QPointF() << 90. << "_r"; - QTest::newRow("Test el arc 9") << QPointF(10, 10) << 10. << 20.0 << 0. << 360. << 90.<< QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 1") << QPointF() << 10. << 20.0 << 1. << 91. << 0. << QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 2") << QPointF() << 10. << 20.0 << 0. << 90. << 0. << QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 3.2") << QPointF(10, 10) << 10. << 20.0 << 0. << 90. << 0. << QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 3.1") << QPointF(10, 10) << 10. << 20.0 << 1. << 91. << 0. << QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 3") << QPointF(10, 10) << 10. << 20.0 << 1. << 91. << 90. << QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 4") << QPointF(10, 10) << 10. << 20.0 << 0. << 90. << 90. << QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 5") << QPointF(10, 10) << 10. << 20.0 << 0. << 180. << 90. << QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 6") << QPointF(10, 10) << 10. << 20.0 << 1. << 181. << 90. << QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 7") << QPointF(10, 10) << 10. << 20.0 << 0. << 270. << 90. << QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 8") << QPointF(10, 10) << 10. << 20.0 << 1. << 271. << 90. << QPointF() << 90. << "_r"; + QTest::newRow("Test el arc 9") << QPointF(10, 10) << 10. << 20.0 << 0. << 360. << 90. << QPointF() << 90. << "_r"; } //--------------------------------------------------------------------------------------------------------------------- @@ -533,15 +543,14 @@ void TST_VEllipticalArc::TestRotation() const VEllipticalArc rotatedArc = arcOrigin.Rotate(rotatePoint, degrees, prefix); QVERIFY2(qAbs(arcOrigin.AngleArc() - rotatedArc.AngleArc()) <= 1.6, - qUtf8Printable(QString("a1 = %1, a2 - %2").arg(arcOrigin.AngleArc()).arg(rotatedArc.AngleArc()))); + qUtf8Printable(QString("a1 = %1, a2 - %2").arg(arcOrigin.AngleArc()).arg(rotatedArc.AngleArc()))); // cppcheck-suppress unreadVariable QString errorLengthMsg = - QString("Difference between real and computing lengthes bigger than eps = %1. l1 = %2; l2 = %3"); + QString("Difference between real and computing lengthes bigger than eps = %1. l1 = %2; l2 = %3"); QVERIFY2(qAbs(arcOrigin.GetLength() - rotatedArc.GetLength()) <= ToPixel(1, Unit::Mm), - qUtf8Printable(errorLengthMsg.arg(ToPixel(1, Unit::Mm)) - .arg(arcOrigin.GetLength()) - .arg(rotatedArc.GetLength()))); + qUtf8Printable( + errorLengthMsg.arg(ToPixel(1, Unit::Mm)).arg(arcOrigin.GetLength()).arg(rotatedArc.GetLength()))); QCOMPARE(arcOrigin.GetRadius1(), rotatedArc.GetRadius1()); QCOMPARE(arcOrigin.GetRadius2(), rotatedArc.GetRadius2()); @@ -587,7 +596,7 @@ void TST_VEllipticalArc::TestFlip() const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); - QCOMPARE(qRound(elArc.GetLength()*-1), qRound(res.GetLength())); + QCOMPARE(qRound(elArc.GetLength() * -1), qRound(res.GetLength())); QCOMPARE(elArc.GetRadius1(), res.GetRadius1()); QCOMPARE(elArc.GetRadius2(), res.GetRadius2()); } @@ -600,8 +609,8 @@ void TST_VEllipticalArc::EmptyArc_data() QTest::addColumn("length"); QTest::newRow("Empty elArc") << 0. << 0. << 0.; - QTest::newRow("Radius1 correct") << 50. << 0. << 50.*4; - QTest::newRow("Radius2 correct") << 0. << 30. << 30.*4; + QTest::newRow("Radius1 correct") << 50. << 0. << 50. * 4; + QTest::newRow("Radius2 correct") << 0. << 30. << 30. * 4; } //---------------------------------------------------------------------------------------------------------------------