From 6f5199c5d187d28281f9c0dfa720098545e28738 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 5 Aug 2017 11:03:19 +0300 Subject: [PATCH] Performance optimization. --HG-- branch : develop --- src/libs/ifc/xml/vdomdocument.cpp | 5 ++- src/libs/ifc/xml/vtoolrecord.cpp | 11 ------ src/libs/ifc/xml/vtoolrecord.h | 7 ++++ src/libs/vpatterndb/vpiece.cpp | 37 ++++++++++++-------- src/libs/vpatterndb/vpiece.h | 12 ++++--- src/libs/vtools/tools/vtoolseamallowance.cpp | 12 +++++-- 6 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index f57116ebf..7199346df 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -330,19 +330,18 @@ quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QStri QString parametr; quint32 id = 0; - const QString message = QObject::tr("Can't convert toUInt parameter"); try { parametr = GetParametrString(domElement, name, defValue); id = parametr.toUInt(&ok); if (ok == false) { - throw VExceptionConversionError(message, name); + throw VExceptionConversionError(QObject::tr("Can't convert toUInt parameter"), name); } } catch (const VExceptionEmptyParameter &e) { - VExceptionConversionError excep(message, name); + VExceptionConversionError excep(QObject::tr("Can't convert toUInt parameter"), name); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } diff --git a/src/libs/ifc/xml/vtoolrecord.cpp b/src/libs/ifc/xml/vtoolrecord.cpp index 4ad60c5e5..0bae21e9c 100644 --- a/src/libs/ifc/xml/vtoolrecord.cpp +++ b/src/libs/ifc/xml/vtoolrecord.cpp @@ -48,17 +48,6 @@ VToolRecord::VToolRecord(const quint32 &id, const Tool &typeTool, const QString :id(id), typeTool(typeTool), nameDraw(nameDraw) {} -//--------------------------------------------------------------------------------------------------------------------- -bool VToolRecord::operator==(const VToolRecord &record) const -{ - bool isEqual = false; - if (id == record.getId() && typeTool == record.getTypeTool() && nameDraw == record.getNameDraw()) - { - isEqual = true; - } - return isEqual; -} - //--------------------------------------------------------------------------------------------------------------------- VToolRecord &VToolRecord::operator=(const VToolRecord &record) { diff --git a/src/libs/ifc/xml/vtoolrecord.h b/src/libs/ifc/xml/vtoolrecord.h index 27fa4e820..20792aa04 100644 --- a/src/libs/ifc/xml/vtoolrecord.h +++ b/src/libs/ifc/xml/vtoolrecord.h @@ -123,4 +123,11 @@ inline void VToolRecord::setNameDraw(const QString &value) nameDraw = value; } +//--------------------------------------------------------------------------------------------------------------------- +inline bool VToolRecord::operator==(const VToolRecord &record) const +{ + // Id should be enough + return id == record.getId()/* && typeTool == record.getTypeTool() && nameDraw == record.getNameDraw()*/; +} + #endif // VTOOLRECORD_H diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index ffefc4cf2..5bfcf21ed 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -410,7 +410,7 @@ QVector VPiece::SeamAllowancePoints(const VContainer *data) const } //--------------------------------------------------------------------------------------------------------------------- -QVector VPiece::PassmarksLines(const VContainer *data) const +QVector VPiece::PassmarksLines(const VContainer *data, const QVector &seamAllowance) const { const QVector unitedPath = GetUnitedPath(data); if (not IsSeamAllowance() || not IsPassmarksPossible(unitedPath)) @@ -431,7 +431,7 @@ QVector VPiece::PassmarksLines(const VContainer *data) const const int previousIndex = VPiecePath::FindInLoopNotExcludedUp(i, unitedPath); const int nextIndex = VPiecePath::FindInLoopNotExcludedDown(i, unitedPath); - passmarks += CreatePassmark(unitedPath, previousIndex, i, nextIndex, data); + passmarks += CreatePassmark(unitedPath, previousIndex, i, nextIndex, data, seamAllowance); } return passmarks; @@ -460,18 +460,23 @@ QPainterPath VPiece::MainPathPath(const VContainer *data) const //--------------------------------------------------------------------------------------------------------------------- QPainterPath VPiece::SeamAllowancePath(const VContainer *data) const { - const QVector pointsEkv = SeamAllowancePoints(data); + return SeamAllowancePath(SeamAllowancePoints(data)); +} + +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath VPiece::SeamAllowancePath(const QVector &points) const +{ QPainterPath ekv; // seam allowence if (IsSeamAllowance() && not IsSeamAllowanceBuiltIn()) { - if (not pointsEkv.isEmpty()) + if (not points.isEmpty()) { - ekv.moveTo(pointsEkv.at(0)); - for (qint32 i = 1; i < pointsEkv.count(); ++i) + ekv.moveTo(points.at(0)); + for (qint32 i = 1; i < points.count(); ++i) { - ekv.lineTo(pointsEkv.at(i)); + ekv.lineTo(points.at(i)); } ekv.setFillRule(Qt::WindingFill); @@ -482,9 +487,9 @@ QPainterPath VPiece::SeamAllowancePath(const VContainer *data) const } //--------------------------------------------------------------------------------------------------------------------- -QPainterPath VPiece::PassmarksPath(const VContainer *data) const +QPainterPath VPiece::PassmarksPath(const VContainer *data, const QVector &seamAllowance) const { - const QVector passmarks = PassmarksLines(data); + const QVector passmarks = PassmarksLines(data, seamAllowance); QPainterPath path; // seam allowence @@ -1048,7 +1053,8 @@ bool VPiece::IsPassmarkVisible(const QVector &path, int passmarkInde //--------------------------------------------------------------------------------------------------------------------- QVector VPiece::CreatePassmark(const QVector &path, int previousIndex, int passmarkIndex, - int nextIndex, const VContainer *data) const + int nextIndex, const VContainer *data, + const QVector &seamAllowance) const { SCASSERT(data != nullptr); @@ -1079,7 +1085,7 @@ QVector VPiece::CreatePassmark(const QVector &path, int prev if (not IsSeamAllowanceBuiltIn()) { QVector lines; - lines += SAPassmark(path, previousSAPoint, passmarkSAPoint, nextSAPoint, data, passmarkIndex); + lines += SAPassmark(path, previousSAPoint, passmarkSAPoint, nextSAPoint, data, passmarkIndex, seamAllowance); if (qApp->Settings()->IsDoublePassmark() && not IsHideMainPath() && path.at(passmarkIndex).IsMainPathNode() @@ -1099,7 +1105,7 @@ QVector VPiece::CreatePassmark(const QVector &path, int prev //--------------------------------------------------------------------------------------------------------------------- QVector VPiece::SAPassmark(const QVector &path, VSAPoint &previousSAPoint, const VSAPoint &passmarkSAPoint, VSAPoint &nextSAPoint, const VContainer *data, - int passmarkIndex) const + int passmarkIndex, const QVector &seamAllowance) const { QPointF seamPassmarkSAPoint; if (not GetSeamPassmarkSAPoint(previousSAPoint, passmarkSAPoint, nextSAPoint, data, seamPassmarkSAPoint)) @@ -1135,12 +1141,15 @@ QVector VPiece::SAPassmark(const QVector &path, VSAPoint &pr } else if (node.GetPassmarkAngleType() == PassmarkAngleType::Intersection) { + QVector seamPoints; + seamAllowance.isEmpty() ? seamPoints = SeamAllowancePoints(data) : seamPoints = seamAllowance; + { // first passmark QLineF line(previousSAPoint, passmarkSAPoint); line.setLength(line.length()*100); // Hope 100 is enough - const QVector intersections = VAbstractCurve::CurveIntersectLine(SeamAllowancePoints(data), line); + const QVector intersections = VAbstractCurve::CurveIntersectLine(seamPoints, line); if (intersections.isEmpty()) { return QVector(); // Something wrong @@ -1157,7 +1166,7 @@ QVector VPiece::SAPassmark(const QVector &path, VSAPoint &pr QLineF line(nextSAPoint, passmarkSAPoint); line.setLength(line.length()*100); // Hope 100 is enough - const QVector intersections = VAbstractCurve::CurveIntersectLine(SeamAllowancePoints(data), line); + const QVector intersections = VAbstractCurve::CurveIntersectLine(seamPoints, line); if (intersections.isEmpty()) { diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 830275322..9a2cc340c 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -69,11 +69,14 @@ public: QVector MainPathPoints(const VContainer *data) const; QVector MainPathNodePoints(const VContainer *data, bool showExcluded = false) const; QVector SeamAllowancePoints(const VContainer *data) const; - QVector PassmarksLines(const VContainer *data) const; + QVector PassmarksLines(const VContainer *data, + const QVector &seamAllowance = QVector()) const; QPainterPath MainPathPath(const VContainer *data) const; QPainterPath SeamAllowancePath(const VContainer *data) const; - QPainterPath PassmarksPath(const VContainer *data) const; + QPainterPath SeamAllowancePath(const QVector &points) const; + QPainterPath PassmarksPath(const VContainer *data, + const QVector &seamAllowance = QVector()) const; bool IsInLayout() const; void SetInLayout(bool inLayout); @@ -133,10 +136,11 @@ private: bool IsPassmarkVisible(const QVector &path, int passmarkIndex) const; QVector CreatePassmark(const QVector &path, int previousIndex, int passmarkIndex, int nextIndex, - const VContainer *data) const; + const VContainer *data, + const QVector &seamAllowance = QVector()) const; QVector SAPassmark(const QVector &path, VSAPoint &previousSAPoint, const VSAPoint &passmarkSAPoint, VSAPoint &nextSAPoint, const VContainer *data, - int passmarkIndex) const; + int passmarkIndex, const QVector &seamAllowance = QVector()) const; QVector BuiltInSAPassmark(const QVector &path, const VSAPoint &previousSAPoint, const VSAPoint &passmarkSAPoint, const VSAPoint &nextSAPoint, const VContainer *data, int passmarkIndex) const; diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 9fcbf2a85..6ea8ba99e 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -1207,13 +1207,21 @@ void VToolSeamAllowance::RefreshGeometry() } this->setPath(path); - m_passmarks->setPath(detail.PassmarksPath(this->getData())); + + QVector seamAllowancePoints; + + if (detail.IsSeamAllowance()) + { + seamAllowancePoints = detail.SeamAllowancePoints(this->getData()); + } + + m_passmarks->setPath(detail.PassmarksPath(this->getData(), seamAllowancePoints)); this->setPos(detail.GetMx(), detail.GetMy()); if (detail.IsSeamAllowance() && not detail.IsSeamAllowanceBuiltIn()) { - path.addPath(detail.SeamAllowancePath(this->getData())); + path.addPath(detail.SeamAllowancePath(seamAllowancePoints)); path.setFillRule(Qt::OddEvenFill); m_seamAllowance->setPath(path); }