Unite nodes to be able to show passmarks from custom seam allowance included as

main path.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-03-30 12:26:06 +03:00
parent d3ab7f5b16
commit f05cd909a2
4 changed files with 125 additions and 69 deletions

View File

@ -226,11 +226,12 @@ QVector<QPointF> VPiece::SeamAllowancePoints(const VContainer *data) const
int recordIndex = -1; int recordIndex = -1;
bool insertingCSA = false; bool insertingCSA = false;
const qreal width = ToPixel(GetSAWidth(), *data->GetPatternUnit()); const qreal width = ToPixel(GetSAWidth(), *data->GetPatternUnit());
const QVector<VPieceNode> unitedPath = GetUnitedPath(data);
QVector<VSAPoint> pointsEkv; QVector<VSAPoint> pointsEkv;
for (int i = 0; i< d->m_path.CountNodes(); ++i) for (int i = 0; i< unitedPath.size(); ++i)
{ {
const VPieceNode &node = d->m_path.at(i); const VPieceNode &node = unitedPath.at(i);
if (node.IsExcluded()) if (node.IsExcluded())
{ {
continue;// skip excluded node continue;// skip excluded node
@ -245,21 +246,18 @@ QVector<QPointF> VPiece::SeamAllowancePoints(const VContainer *data) const
pointsEkv.append(VPiecePath::PreparePointEkv(node, data)); pointsEkv.append(VPiecePath::PreparePointEkv(node, data));
recordIndex = IsCSAStart(records, node.GetId()); recordIndex = IsCSAStart(records, node.GetId());
if (recordIndex != -1) if (recordIndex != -1 && records.at(recordIndex).includeType == PiecePathIncludeType::AsCustomSA)
{ {
insertingCSA = true; insertingCSA = true;
const VPiecePath path = data->GetPiecePath(records.at(recordIndex).path); const VPiecePath path = data->GetPiecePath(records.at(recordIndex).path);
QVector<VSAPoint> r = path.SeamAllowancePoints(data, width, records.at(recordIndex).reverse); QVector<VSAPoint> r = path.SeamAllowancePoints(data, width, records.at(recordIndex).reverse);
if (records.at(recordIndex).includeType == PiecePathIncludeType::AsCustomSA) for (int j = 0; j < r.size(); ++j)
{ {
for (int j = 0; j < r.size(); ++j) r[j].SetAngleType(PieceNodeAngle::ByLength);
{ r[j].SetSABefore(0);
r[j].SetAngleType(PieceNodeAngle::ByLength); r[j].SetSAAfter(0);
r[j].SetSABefore(0);
r[j].SetSAAfter(0);
}
} }
pointsEkv += r; pointsEkv += r;
@ -286,8 +284,8 @@ QVector<QPointF> VPiece::SeamAllowancePoints(const VContainer *data) const
{ {
const QSharedPointer<VAbstractCurve> curve = data->GeometricObject<VAbstractCurve>(node.GetId()); const QSharedPointer<VAbstractCurve> curve = data->GeometricObject<VAbstractCurve>(node.GetId());
pointsEkv += VPiecePath::CurveSeamAllowanceSegment(data, d->m_path.GetNodes(), curve, i, pointsEkv += VPiecePath::CurveSeamAllowanceSegment(data, unitedPath, curve, i, node.GetReverse(),
node.GetReverse(), width); width);
} }
} }
break; break;
@ -303,16 +301,17 @@ QVector<QPointF> VPiece::SeamAllowancePoints(const VContainer *data) const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<QLineF> VPiece::PassmarksLines(const VContainer *data) const QVector<QLineF> VPiece::PassmarksLines(const VContainer *data) const
{ {
if (not IsSeamAllowance() || not IsPassmarksPossible()) const QVector<VPieceNode> unitedPath = GetUnitedPath(data);
if (not IsSeamAllowance() || not IsPassmarksPossible(unitedPath))
{ {
return QVector<QLineF>(); return QVector<QLineF>();
} }
QVector<QLineF> passmarks; QVector<QLineF> passmarks;
for (int i = 0; i< d->m_path.CountNodes(); ++i) for (int i = 0; i< unitedPath.size(); ++i)
{ {
const VPieceNode &node = d->m_path.at(i); const VPieceNode &node = unitedPath.at(i);
if (node.IsExcluded() || not node.IsPassmark()) if (node.IsExcluded() || not node.IsPassmark())
{ {
continue;// skip node continue;// skip node
@ -323,24 +322,24 @@ QVector<QLineF> VPiece::PassmarksLines(const VContainer *data) const
int previousIndex = 0; int previousIndex = 0;
if (passmarkIndex == 0) if (passmarkIndex == 0)
{ {
previousIndex = VPiecePath::FindInLoopNotExcludedUp(d->m_path.CountNodes()-1, d->m_path.GetNodes()); previousIndex = VPiecePath::FindInLoopNotExcludedUp(unitedPath.size()-1, unitedPath);
} }
else else
{ {
previousIndex = VPiecePath::FindInLoopNotExcludedUp(passmarkIndex-1, d->m_path.GetNodes()); previousIndex = VPiecePath::FindInLoopNotExcludedUp(passmarkIndex-1, unitedPath);
} }
int nextIndex = 0; int nextIndex = 0;
if (passmarkIndex == d->m_path.CountNodes()-1) if (passmarkIndex == unitedPath.size()-1)
{ {
nextIndex = VPiecePath::FindInLoopNotExcludedDown(0, d->m_path.GetNodes()); nextIndex = VPiecePath::FindInLoopNotExcludedDown(0, unitedPath);
} }
else else
{ {
nextIndex = VPiecePath::FindInLoopNotExcludedDown(passmarkIndex+1, d->m_path.GetNodes()); nextIndex = VPiecePath::FindInLoopNotExcludedDown(passmarkIndex+1, unitedPath);
} }
passmarks += CreatePassmark(previousIndex, passmarkIndex, nextIndex, data); passmarks += CreatePassmark(unitedPath, previousIndex, passmarkIndex, nextIndex, data);
} }
return passmarks; return passmarks;
@ -644,6 +643,47 @@ const VGrainlineData &VPiece::GetGrainlineGeometry() const
return d->m_glGrainline; return d->m_glGrainline;
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<VPieceNode> VPiece::GetUnitedPath(const VContainer *data) const
{
SCASSERT(data != nullptr)
QVector<VPieceNode> united = d->m_path.GetNodes();
const QVector<CustomSARecord> records = FilterRecords(GetValidRecords());
for (int i = 0; i < records.size(); ++i)
{
if (records.at(i).includeType == PiecePathIncludeType::AsMainPath)
{
const int indexStartPoint = VPiecePath::indexOfNode(united, records.at(i).startPoint);
const int indexEndPoint = VPiecePath::indexOfNode(united, records.at(i).endPoint);
if (indexStartPoint == -1 || indexEndPoint == -1)
{
continue;
}
const QVector<VPieceNode> midBefore = united.mid(0, indexStartPoint+1);
const QVector<VPieceNode> midAfter = united.mid(indexEndPoint);
QVector<VPieceNode> customNodes = data->GetPiecePath(records.at(i).path).GetNodes();
if (records.at(i).reverse)
{
customNodes = VGObject::GetReversePoints(customNodes);
// Additionally reverse all curves
for (int j = 0; j < customNodes.size(); ++j)
{ // don't make a check because node point will ignore the change
customNodes[j].SetReverse(not customNodes.at(j).GetReverse());
}
}
united = midBefore + customNodes + midAfter;
}
}
return united;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<CustomSARecord> VPiece::GetValidRecords() const QVector<CustomSARecord> VPiece::GetValidRecords() const
{ {
@ -719,16 +759,16 @@ QVector<CustomSARecord> VPiece::FilterRecords(QVector<CustomSARecord> records) c
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<VSAPoint> VPiece::GetNodeSAPoints(int index, const VContainer *data) const QVector<VSAPoint> VPiece::GetNodeSAPoints(const QVector<VPieceNode> &path, int index, const VContainer *data) const
{ {
SCASSERT(data != nullptr) SCASSERT(data != nullptr)
if (index < 0 || index >= d->m_path.CountNodes()) if (index < 0 || index >= path.size())
{ {
return QVector<VSAPoint>(); return QVector<VSAPoint>();
} }
const VPieceNode &node = d->m_path.at(index); const VPieceNode &node = path.at(index);
QVector<VSAPoint> points; QVector<VSAPoint> points;
if (node.GetTypeTool() == Tool::NodePoint) if (node.GetTypeTool() == Tool::NodePoint)
@ -740,18 +780,18 @@ QVector<VSAPoint> VPiece::GetNodeSAPoints(int index, const VContainer *data) con
const QSharedPointer<VAbstractCurve> curve = data->GeometricObject<VAbstractCurve>(node.GetId()); const QSharedPointer<VAbstractCurve> curve = data->GeometricObject<VAbstractCurve>(node.GetId());
const qreal width = ToPixel(GetSAWidth(), *data->GetPatternUnit()); const qreal width = ToPixel(GetSAWidth(), *data->GetPatternUnit());
points += VPiecePath::CurveSeamAllowanceSegment(data, d->m_path.GetNodes(), curve, index, node.GetReverse(), points += VPiecePath::CurveSeamAllowanceSegment(data, path, curve, index, node.GetReverse(), width);
width);
} }
return points; return points;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VPiece::GetPassmarkSAPoint(int index, const VContainer *data, VSAPoint &point) const bool VPiece::GetPassmarkSAPoint(const QVector<VPieceNode> &path, int index, const VContainer *data,
VSAPoint &point) const
{ {
SCASSERT(data != nullptr) SCASSERT(data != nullptr)
const QVector<VSAPoint> points = GetNodeSAPoints(index, data); const QVector<VSAPoint> points = GetNodeSAPoints(path, index, data);
if (points.isEmpty() || points.size() > 1) if (points.isEmpty() || points.size() > 1)
{ {
@ -763,12 +803,12 @@ bool VPiece::GetPassmarkSAPoint(int index, const VContainer *data, VSAPoint &poi
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VPiece::GetPassmarkPreviousSAPoint(int index, const VSAPoint &passmarkSAPoint, const VContainer *data, bool VPiece::GetPassmarkPreviousSAPoint(const QVector<VPieceNode> &path, int index, const VSAPoint &passmarkSAPoint,
VSAPoint &point) const const VContainer *data, VSAPoint &point) const
{ {
SCASSERT(data != nullptr) SCASSERT(data != nullptr)
const QVector<VSAPoint> points = GetNodeSAPoints(index, data); const QVector<VSAPoint> points = GetNodeSAPoints(path, index, data);
if (points.isEmpty()) if (points.isEmpty())
{ {
@ -796,10 +836,10 @@ bool VPiece::GetPassmarkPreviousSAPoint(int index, const VSAPoint &passmarkSAPoi
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VPiece::GetPassmarkNextSAPoint(int index, const VSAPoint &passmarkSAPoint, const VContainer *data, bool VPiece::GetPassmarkNextSAPoint(const QVector<VPieceNode> &path, int index, const VSAPoint &passmarkSAPoint,
VSAPoint &point) const const VContainer *data, VSAPoint &point) const
{ {
const QVector<VSAPoint> points = GetNodeSAPoints(index, data); const QVector<VSAPoint> points = GetNodeSAPoints(path, index, data);
if (points.isEmpty()) if (points.isEmpty())
{ {
@ -855,14 +895,14 @@ bool VPiece::GetSeamPassmarkSAPoint(const VSAPoint &previousSAPoint, const VSAPo
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VPiece::IsPassmarksPossible() const bool VPiece::IsPassmarksPossible(const QVector<VPieceNode> &path) const
{ {
int countPointNodes = 0; int countPointNodes = 0;
int countOthers = 0; int countOthers = 0;
for (int i = 0; i< d->m_path.CountNodes(); ++i) for (int i = 0; i< path.size(); ++i)
{ {
const VPieceNode &node = d->m_path.at(i); const VPieceNode &node = path.at(i);
if (node.IsExcluded()) if (node.IsExcluded())
{ {
continue;// skip node continue;// skip node
@ -875,14 +915,14 @@ bool VPiece::IsPassmarksPossible() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VPiece::IsPassmarkVisible(int passmarkIndex) const bool VPiece::IsPassmarkVisible(const QVector<VPieceNode> &path, int passmarkIndex) const
{ {
if (passmarkIndex < 0 || passmarkIndex >= d->m_path.CountNodes()) if (passmarkIndex < 0 || passmarkIndex >= path.size())
{ {
return false; return false;
} }
const VPieceNode &node = d->m_path.at(passmarkIndex); const VPieceNode &node = path.at(passmarkIndex);
if (node.GetTypeTool() != Tool::NodePoint || not node.IsPassmark() || node.IsExcluded()) if (node.GetTypeTool() != Tool::NodePoint || not node.IsPassmark() || node.IsExcluded())
{ {
return false; return false;
@ -896,41 +936,44 @@ bool VPiece::IsPassmarkVisible(int passmarkIndex) const
for (int i = 0; i < records.size(); ++i) for (int i = 0; i < records.size(); ++i)
{ {
const int indexStartPoint = d->m_path.indexOfNode(records.at(i).startPoint); if (records.at(i).includeType == PiecePathIncludeType::AsCustomSA)
const int indexEndPoint = d->m_path.indexOfNode(records.at(i).endPoint);
if (passmarkIndex > indexStartPoint && passmarkIndex < indexEndPoint)
{ {
return false; const int indexStartPoint = VPiecePath::indexOfNode(path, records.at(i).startPoint);
const int indexEndPoint = VPiecePath::indexOfNode(path, records.at(i).endPoint);
if (passmarkIndex > indexStartPoint && passmarkIndex < indexEndPoint)
{
return false;
}
} }
} }
return true; return true;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<QLineF> VPiece::CreatePassmark(int previousIndex, int passmarkIndex, int nextIndex, QVector<QLineF> VPiece::CreatePassmark(const QVector<VPieceNode> &path, int previousIndex, int passmarkIndex,
const VContainer *data) const int nextIndex, const VContainer *data) const
{ {
SCASSERT(data != nullptr); SCASSERT(data != nullptr);
if (not IsPassmarkVisible(passmarkIndex)) if (not IsPassmarkVisible(path, passmarkIndex))
{ {
return QVector<QLineF>(); return QVector<QLineF>();
} }
VSAPoint passmarkSAPoint; VSAPoint passmarkSAPoint;
if (not GetPassmarkSAPoint(passmarkIndex, data, passmarkSAPoint)) if (not GetPassmarkSAPoint(path, passmarkIndex, data, passmarkSAPoint))
{ {
return QVector<QLineF>(); // Something wrong return QVector<QLineF>(); // Something wrong
} }
VSAPoint previousSAPoint; VSAPoint previousSAPoint;
if (not GetPassmarkPreviousSAPoint(previousIndex, passmarkSAPoint, data, previousSAPoint)) if (not GetPassmarkPreviousSAPoint(path, previousIndex, passmarkSAPoint, data, previousSAPoint))
{ {
return QVector<QLineF>(); // Something wrong return QVector<QLineF>(); // Something wrong
} }
VSAPoint nextSAPoint; VSAPoint nextSAPoint;
if (not GetPassmarkNextSAPoint(nextIndex, passmarkSAPoint, data, nextSAPoint)) if (not GetPassmarkNextSAPoint(path, nextIndex, passmarkSAPoint, data, nextSAPoint))
{ {
return QVector<QLineF>(); // Something wrong return QVector<QLineF>(); // Something wrong
} }
@ -948,7 +991,7 @@ QVector<QLineF> VPiece::CreatePassmark(int previousIndex, int passmarkIndex, int
QVector<QLineF> passmarksLines; QVector<QLineF> passmarksLines;
const qreal passmarkLength = VAbstractPiece::MaxLocalSA(passmarkSAPoint, width) * 0.25; const qreal passmarkLength = VAbstractPiece::MaxLocalSA(passmarkSAPoint, width) * 0.25;
const VPieceNode &node = d->m_path.at(passmarkIndex); const VPieceNode &node = path.at(passmarkIndex);
if (node.GetPassmarkAngleType() == PassmarkAngleType::Straightforward) if (node.GetPassmarkAngleType() == PassmarkAngleType::Straightforward)
{ {
QLineF line = QLineF(seamPassmarkSAPoint, passmarkSAPoint); QLineF line = QLineF(seamPassmarkSAPoint, passmarkSAPoint);

View File

@ -113,23 +113,26 @@ public:
private: private:
QSharedDataPointer<VPieceData> d; QSharedDataPointer<VPieceData> d;
QVector<VPieceNode> GetUnitedPath(const VContainer *data) const;
QVector<CustomSARecord> GetValidRecords() const; QVector<CustomSARecord> GetValidRecords() const;
QVector<CustomSARecord> FilterRecords(QVector<CustomSARecord> records) const; QVector<CustomSARecord> FilterRecords(QVector<CustomSARecord> records) const;
QVector<VSAPoint> GetNodeSAPoints(int index, const VContainer *data) const; QVector<VSAPoint> GetNodeSAPoints(const QVector<VPieceNode> &path, int index, const VContainer *data) const;
bool GetPassmarkSAPoint(int index, const VContainer *data, VSAPoint &point) const; bool GetPassmarkSAPoint(const QVector<VPieceNode> &path, int index, const VContainer *data, VSAPoint &point) const;
bool GetPassmarkPreviousSAPoint(int index, const VSAPoint &passmarkSAPoint, const VContainer *data, bool GetPassmarkPreviousSAPoint(const QVector<VPieceNode> &path, int index, const VSAPoint &passmarkSAPoint,
VSAPoint &point) const; const VContainer *data, VSAPoint &point) const;
bool GetPassmarkNextSAPoint(int index, const VSAPoint &passmarkSAPoint, const VContainer *data, bool GetPassmarkNextSAPoint(const QVector<VPieceNode> &path, int index, const VSAPoint &passmarkSAPoint,
VSAPoint &point) const; const VContainer *data, VSAPoint &point) const;
bool GetSeamPassmarkSAPoint(const VSAPoint &previousSAPoint, const VSAPoint &passmarkSAPoint, bool GetSeamPassmarkSAPoint(const VSAPoint &previousSAPoint, const VSAPoint &passmarkSAPoint,
const VSAPoint &nextSAPoint, const VContainer *data, QPointF &point) const; const VSAPoint &nextSAPoint, const VContainer *data, QPointF &point) const;
bool IsPassmarksPossible() const; bool IsPassmarksPossible(const QVector<VPieceNode> &path) const;
bool IsPassmarkVisible(int passmarkIndex) const; bool IsPassmarkVisible(const QVector<VPieceNode> &path, int passmarkIndex) const;
QVector<QLineF> CreatePassmark(int previousIndex, int passmarkIndex, int nextIndex, const VContainer *data) const; QVector<QLineF> CreatePassmark(const QVector<VPieceNode> &path, int previousIndex, int passmarkIndex, int nextIndex,
const VContainer *data) const;
static int IsCSAStart(const QVector<CustomSARecord> &records, quint32 id); static int IsCSAStart(const QVector<CustomSARecord> &records, quint32 id);
}; };

View File

@ -466,15 +466,7 @@ QVector<quint32> VPiecePath::MissingNodes(const VPiecePath &path) const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VPiecePath::indexOfNode(quint32 id) const int VPiecePath::indexOfNode(quint32 id) const
{ {
for (int i = 0; i < d->m_nodes.size(); ++i) return indexOfNode(d->m_nodes, id);
{
if (d->m_nodes.at(i).GetId() == id)
{
return i;
}
}
qDebug()<<"Can't find node.";
return -1;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -768,6 +760,20 @@ QPointF VPiecePath::NodeNextPoint(const VContainer *data, int i) const
return point; return point;
} }
//---------------------------------------------------------------------------------------------------------------------
int VPiecePath::indexOfNode(const QVector<VPieceNode> &nodes, quint32 id)
{
for (int i = 0; i < nodes.size(); ++i)
{
if (nodes.at(i).GetId() == id)
{
return i;
}
}
qDebug()<<"Can't find node.";
return -1;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VPiecePath::FindInLoopNotExcludedUp(int candidate, const QVector<VPieceNode> &nodes) int VPiecePath::FindInLoopNotExcludedUp(int candidate, const QVector<VPieceNode> &nodes)
{ {
@ -827,6 +833,8 @@ int VPiecePath::FindInLoopNotExcludedDown(int candidate, const QVector<VPieceNod
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VSAPoint VPiecePath::PreparePointEkv(const VPieceNode &node, const VContainer *data) VSAPoint VPiecePath::PreparePointEkv(const VPieceNode &node, const VContainer *data)
{ {
SCASSERT(data !=nullptr)
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(node.GetId()); const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(node.GetId());
VSAPoint p(point->toQPointF()); VSAPoint p(point->toQPointF());

View File

@ -94,6 +94,8 @@ public:
QPointF NodePreviousPoint(const VContainer *data, int i) const; QPointF NodePreviousPoint(const VContainer *data, int i) const;
QPointF NodeNextPoint(const VContainer *data, int i) const; QPointF NodeNextPoint(const VContainer *data, int i) const;
static int indexOfNode(const QVector<VPieceNode> &nodes, quint32 id);
static int FindInLoopNotExcludedUp(int candidate, const QVector<VPieceNode> &nodes); static int FindInLoopNotExcludedUp(int candidate, const QVector<VPieceNode> &nodes);
static int FindInLoopNotExcludedDown(int candidate, const QVector<VPieceNode> &nodes); static int FindInLoopNotExcludedDown(int candidate, const QVector<VPieceNode> &nodes);