From e343cc801827b0543f231fc780a0c7580720deb4 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 5 Jun 2018 12:22:31 +0300 Subject: [PATCH] Fixed issue #854. Union Details Tool version 1 breaks a pattern. --HG-- branch : develop --- src/libs/vtools/tools/vtooluniondetails.cpp | 68 +++++++++++++++------ 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 7c97ec86e..60da8045b 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -1187,14 +1187,6 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector VToolPiecePath::Create(initNodeData); record.path = idPath; newDetail.GetCustomSARecords().append(record); - - if (initData.version == 1) - { - // TODO. Delete if minimal supported version is 0.7.0 - Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 0), - "Time to refactor the code."); - nodeChildren.prepend(idPath); - } } children += nodeChildren; } @@ -1247,14 +1239,6 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector VToolPiecePath::Create(initNodeData); newDetail.GetInternalPaths().append(idPath); - - if (initData.version == 1) - { - // TODO. Delete if minimal supported version is 0.7.0 - Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 0), - "Time to refactor the code."); - nodeChildren.prepend(idPath); - } } children += nodeChildren; } @@ -1399,10 +1383,59 @@ void UpdateUnitedNodes(const VToolUnionDetailsInitData &initData, qreal dx, qrea } } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief FixChildren fix bug in first version of Union Details Tool. + * + * Bugged code produces incorrect order which breaks convention. This function fix the excpected order. + */ +QVector FixChildren(QVector records, QVector children, VContainer *data) +{ + // TODO. Delete if minimal supported version is 0.7.0 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 0), + "Time to refactor the code."); + SCASSERT(data != nullptr) + + if (records.isEmpty()) + { + return children; + } + + QVector fixedChildren; + while(not records.isEmpty()) + { + const qint32 childrenIndex = records.size()-1; + if (children.size() > childrenIndex) + { + fixedChildren.append(children.takeAt(childrenIndex)); + + const VPiecePath path = data->GetPiecePath(records.takeFirst()); + for (int i=0; i < path.CountNodes(); ++i) + { + if (children.size() > childrenIndex) + { + fixedChildren.append(children.takeAt(childrenIndex)); + } + } + } + } + + return fixedChildren; +} + //--------------------------------------------------------------------------------------------------------------------- void UpdateUnitedDetailPaths(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle, const QVector &records, QVector children) { + if (initData.version == 1) + { + // TODO. Delete if minimal supported version is 0.7.0 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 0), + "Time to refactor the code."); + // Fixing bug in first version of the tool. Mostly for backward compatibility. + children = FixChildren(records, children, initData.data); + } + for (auto record : records) { const VPiecePath path = initData.data->GetPiecePath(record); @@ -1422,14 +1455,13 @@ void UpdateUnitedDetailPaths(const VToolUnionDetailsInitData &initData, qreal dx const VPieceNode &node = path.at(j); const quint32 id = TakeNextId(children); updatedPath.Append(VPieceNode(id, node.GetTypeTool(), node.GetReverse())); - QVector nodeChildren = {id}; + QVector nodeChildren {id}; UpdatePathNode(initData.data, path.at(j), nodeChildren, dx, dy, pRotate, angle); } initData.data->UpdatePiecePath(updatedId, updatedPath); } else { - for (int j=0; j < path.CountNodes(); ++j) { const quint32 id = TakeNextId(children);