From 7490200806784450da604d5ded7b6dc1a65bcd69 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 17 Jan 2017 13:49:55 +0200 Subject: [PATCH] Fix tool Union Details's dialog. --HG-- branch : feature --- src/libs/vpatterndb/vpiecepath.cpp | 110 ++++++++++++++++++ src/libs/vpatterndb/vpiecepath.h | 4 + .../dialogs/tools/dialoguniondetails.cpp | 17 +-- 3 files changed, 123 insertions(+), 8 deletions(-) diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp index e0ed91595..9d3e6216d 100644 --- a/src/libs/vpatterndb/vpiecepath.cpp +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -387,6 +387,96 @@ void VPiecePath::NodeOnEdge(quint32 index, VPieceNode &p1, VPieceNode &p2) const } } +//--------------------------------------------------------------------------------------------------------------------- +bool VPiecePath::Contains(quint32 id) const +{ + for (int i = 0; i < d->m_nodes.size(); ++i) + { + if (d->m_nodes.at(i).GetId() == id) + { + return true; + } + } + return false; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief OnEdge checks if two poins located on the edge. Edge is line between two points. If between two points + * located arcs or splines ignore this. + * @param p1 id first point. + * @param p2 id second point. + * @return true - on edge, false - no. + */ +bool VPiecePath::OnEdge(quint32 p1, quint32 p2) const +{ + const QVector list = ListNodePoint(); + if (list.size() < 2) + { + qDebug()<<"Not enough points."; + return false; + } + int i = indexOfNode(list, p1); + int j1 = 0, j2 = 0; + + if (i == list.size() - 1) + { + j1 = i-1; + j2 = 0; + } + else if (i == 0) + { + j1 = list.size() - 1; + j2 = i + 1; + } + else + { + j1 = i - 1; + j2 = i + 1; + } + + if (list.at(j1).GetId() == p2 || list.at(j2).GetId() == p2) + { + return true; + } + else + { + return false; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Edge return edge index in detail. Edge is line between two points. If between two points + * located arcs or splines ignore this. + * @param p1 id first point. + * @param p2 id second point. + * @return edge index or -1 if points don't located on edge + */ +int VPiecePath::Edge(quint32 p1, quint32 p2) const +{ + if (OnEdge(p1, p2) == false) + { + qDebug()<<"Points don't on edge."; + return -1; + } + + const QVector list = ListNodePoint(); + int i = indexOfNode(list, p1); + int j = indexOfNode(list, p2); + + int min = qMin(i, j); + + if (min == 0 && (i == list.size() - 1 || j == list.size() - 1)) + { + return list.size() - 1; + } + else + { + return min; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief listNodePoint return list nodes only with points. @@ -679,3 +769,23 @@ VSAPoint VPiecePath::CurvePoint(const VSAPoint &candidate, const VContainer *dat } return point; } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief indexOfNode return index in list node using id object. + * @param list list nodes detail. + * @param id object (arc, point, spline, splinePath) id. + * @return index in list or -1 id can't find. + */ +int VPiecePath::indexOfNode(const QVector &list, quint32 id) +{ + for (int i = 0; i < list.size(); ++i) + { + if (list.at(i).GetId() == id) + { + return i; + } + } + qDebug()<<"Can't find node."; + return -1; +} diff --git a/src/libs/vpatterndb/vpiecepath.h b/src/libs/vpatterndb/vpiecepath.h index 557d8541d..9f80b1293 100644 --- a/src/libs/vpatterndb/vpiecepath.h +++ b/src/libs/vpatterndb/vpiecepath.h @@ -81,6 +81,9 @@ public: int indexOfNode(quint32 id) const; void NodeOnEdge(quint32 index, VPieceNode &p1, VPieceNode &p2) const; + bool Contains(quint32 id) const; + bool OnEdge(quint32 p1, quint32 p2) const; + int Edge(quint32 p1, quint32 p2) const; QVector ListNodePoint() const; @@ -106,6 +109,7 @@ private: static VSAPoint CurvePoint(const VSAPoint &candidate, const VContainer *data, const VPieceNode &node, const QSharedPointer &curve); + static int indexOfNode(const QVector &list, quint32 id); }; Q_DECLARE_TYPEINFO(VPiecePath, Q_MOVABLE_TYPE); diff --git a/src/libs/vtools/dialogs/tools/dialoguniondetails.cpp b/src/libs/vtools/dialogs/tools/dialoguniondetails.cpp index 0078616b1..8c54a9dee 100644 --- a/src/libs/vtools/dialogs/tools/dialoguniondetails.cpp +++ b/src/libs/vtools/dialogs/tools/dialoguniondetails.cpp @@ -33,7 +33,8 @@ #include "../ifc/ifcdef.h" #include "../vpatterndb/vcontainer.h" -#include "../vpatterndb/vdetail.h" +#include "../vpatterndb/vpiece.h" +#include "../vpatterndb/vpiecenode.h" #include "dialogtool.h" #include "ui_dialoguniondetails.h" @@ -96,8 +97,8 @@ bool DialogUnionDetails::CheckObject(const quint32 &id, const quint32 &idDetail) { return false; } - const VDetail det = data->GetDetail(idDetail); - return det.Containes(id); + const VPiece det = data->GetPiece(idDetail); + return det.GetPath().Contains(id); } //--------------------------------------------------------------------------------------------------------------------- @@ -107,8 +108,8 @@ bool DialogUnionDetails::CheckDetail(const quint32 &idDetail) const { return false; } - const VDetail det = data->GetDetail(idDetail); - if (det.CountNode() >= 3 && det.listNodePoint().size() >= 2) + const VPiece det = data->GetPiece(idDetail); + if (det.GetPath().CountNodes() >= 3 && det.GetPath().ListNodePoint().size() >= 2) { return true; } @@ -166,11 +167,11 @@ void DialogUnionDetails::ChoosedDetail(const quint32 &id, const SceneObject &typ emit ToolTip(tr("Select a unique point")); return; } - VDetail d = data->GetDetail(idDetail); - if (d.OnEdge(p1, id)) + VPiece d = data->GetPiece(idDetail); + if (d.GetPath().OnEdge(p1, id)) { p2 = id; - index = d.Edge(p1, p2); + index = d.GetPath().Edge(p1, p2); ++numberD; if (numberD > 1) {