Fix tool Union Details's dialog.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-01-17 13:49:55 +02:00
parent bfd76b4e60
commit 7490200806
3 changed files with 123 additions and 8 deletions

View File

@ -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<VPieceNode> 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<VPieceNode> 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. * @brief listNodePoint return list nodes only with points.
@ -679,3 +769,23 @@ VSAPoint VPiecePath::CurvePoint(const VSAPoint &candidate, const VContainer *dat
} }
return point; 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<VPieceNode> &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;
}

View File

@ -81,6 +81,9 @@ public:
int indexOfNode(quint32 id) const; int indexOfNode(quint32 id) const;
void NodeOnEdge(quint32 index, VPieceNode &p1, VPieceNode &p2) 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<VPieceNode> ListNodePoint() const; QVector<VPieceNode> ListNodePoint() const;
@ -106,6 +109,7 @@ private:
static VSAPoint CurvePoint(const VSAPoint &candidate, const VContainer *data, const VPieceNode &node, static VSAPoint CurvePoint(const VSAPoint &candidate, const VContainer *data, const VPieceNode &node,
const QSharedPointer<VAbstractCurve> &curve); const QSharedPointer<VAbstractCurve> &curve);
static int indexOfNode(const QVector<VPieceNode> &list, quint32 id);
}; };
Q_DECLARE_TYPEINFO(VPiecePath, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(VPiecePath, Q_MOVABLE_TYPE);

View File

@ -33,7 +33,8 @@
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/vdetail.h" #include "../vpatterndb/vpiece.h"
#include "../vpatterndb/vpiecenode.h"
#include "dialogtool.h" #include "dialogtool.h"
#include "ui_dialoguniondetails.h" #include "ui_dialoguniondetails.h"
@ -96,8 +97,8 @@ bool DialogUnionDetails::CheckObject(const quint32 &id, const quint32 &idDetail)
{ {
return false; return false;
} }
const VDetail det = data->GetDetail(idDetail); const VPiece det = data->GetPiece(idDetail);
return det.Containes(id); return det.GetPath().Contains(id);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -107,8 +108,8 @@ bool DialogUnionDetails::CheckDetail(const quint32 &idDetail) const
{ {
return false; return false;
} }
const VDetail det = data->GetDetail(idDetail); const VPiece det = data->GetPiece(idDetail);
if (det.CountNode() >= 3 && det.listNodePoint().size() >= 2) if (det.GetPath().CountNodes() >= 3 && det.GetPath().ListNodePoint().size() >= 2)
{ {
return true; return true;
} }
@ -166,11 +167,11 @@ void DialogUnionDetails::ChoosedDetail(const quint32 &id, const SceneObject &typ
emit ToolTip(tr("Select a unique point")); emit ToolTip(tr("Select a unique point"));
return; return;
} }
VDetail d = data->GetDetail(idDetail); VPiece d = data->GetPiece(idDetail);
if (d.OnEdge(p1, id)) if (d.GetPath().OnEdge(p1, id))
{ {
p2 = id; p2 = id;
index = d.Edge(p1, p2); index = d.GetPath().Edge(p1, p2);
++numberD; ++numberD;
if (numberD > 1) if (numberD > 1)
{ {