2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vdetail.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-08-28 10:55:11 +02:00
|
|
|
#include "vdetail.h"
|
2014-04-17 19:18:26 +02:00
|
|
|
#include <QDebug>
|
2014-06-08 20:10:57 +02:00
|
|
|
#include <QString>
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
VDetail::VDetail()
|
2014-01-21 14:51:41 +01:00
|
|
|
:_id(0), nodes(QVector<VNodeDetail>()), name(QString()), mx(0), my(0), seamAllowance(true), closed(true),
|
2014-06-12 18:56:24 +02:00
|
|
|
width(0)
|
2014-05-02 13:11:30 +02:00
|
|
|
{}
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
VDetail::VDetail(const QString &name, const QVector<VNodeDetail> &nodes)
|
2014-01-21 14:51:41 +01:00
|
|
|
:_id(0), nodes(QVector<VNodeDetail>()), name(name), mx(0), my(0), seamAllowance(true), closed(true),
|
2014-06-12 18:56:24 +02:00
|
|
|
width(0)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-28 10:55:11 +02:00
|
|
|
this->nodes = nodes;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
VDetail::VDetail(const VDetail &detail)
|
2013-12-30 20:33:30 +01:00
|
|
|
:_id(0), nodes(detail.getNodes()), name(detail.getName()), mx(detail.getMx()), my(detail.getMy()),
|
2014-05-02 13:11:30 +02:00
|
|
|
seamAllowance(detail.getSeamAllowance()), closed(detail.getClosed()), width(detail.getWidth())
|
|
|
|
{}
|
2013-10-25 13:10:45 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
VDetail &VDetail::operator =(const VDetail &detail)
|
|
|
|
{
|
2013-12-30 12:28:33 +01:00
|
|
|
_id = detail.id();
|
2013-10-25 13:10:45 +02:00
|
|
|
nodes = detail.getNodes();
|
|
|
|
name = detail.getName();
|
|
|
|
mx = detail.getMx();
|
|
|
|
my = detail.getMy();
|
2014-01-21 14:51:41 +01:00
|
|
|
seamAllowance = detail.getSeamAllowance();
|
2013-10-25 13:10:45 +02:00
|
|
|
closed = detail.getClosed();
|
|
|
|
width = detail.getWidth();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
void VDetail::Clear()
|
|
|
|
{
|
2013-08-28 10:55:11 +02:00
|
|
|
nodes.clear();
|
|
|
|
name.clear();
|
|
|
|
mx = 0;
|
|
|
|
my = 0;
|
2014-01-21 14:51:41 +01:00
|
|
|
seamAllowance = true;
|
2013-10-25 13:10:45 +02:00
|
|
|
closed = true;
|
2014-06-12 18:56:24 +02:00
|
|
|
width = 0;
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-01-07 11:04:29 +01:00
|
|
|
void VDetail::ClearNodes()
|
|
|
|
{
|
|
|
|
nodes.clear();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-25 15:40:24 +01:00
|
|
|
bool VDetail::Containes(const quint32 &id) const
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
for (ptrdiff_t i = 0; i < nodes.size(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
VNodeDetail node = nodes.at(i);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (node.getId() == id)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-06 20:27:43 +01:00
|
|
|
VNodeDetail &VDetail::operator [](ptrdiff_t indx)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-28 10:55:11 +02:00
|
|
|
return nodes[indx];
|
|
|
|
}
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-12-29 17:48:57 +01:00
|
|
|
const VNodeDetail &VDetail::at(ptrdiff_t indx) const
|
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
return nodes.at(indx);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-25 15:40:24 +01:00
|
|
|
ptrdiff_t VDetail::indexOfNode(const quint32 &id) const
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-07 11:04:29 +01:00
|
|
|
return indexOfNode(nodes, id);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-07 11:04:29 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 VDetail::id() const
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-25 15:40:24 +01:00
|
|
|
void VDetail::setId(const quint32 &id)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
|
|
|
_id = id;
|
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-25 15:40:24 +01:00
|
|
|
bool VDetail::OnEdge(const quint32 &p1, const quint32 &p2) const
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-01-07 11:04:29 +01:00
|
|
|
QVector<VNodeDetail> list = listNodePoint();
|
2014-01-27 17:01:24 +01:00
|
|
|
if (list.size() < 3)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"Not enough points.";
|
2014-01-07 11:04:29 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ptrdiff_t i = indexOfNode(list, p1);
|
2014-01-02 16:50:01 +01:00
|
|
|
ptrdiff_t j1 = 0, j2 = 0;
|
|
|
|
|
2014-01-07 11:04:29 +01:00
|
|
|
if (i == list.size() - 1)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
|
|
|
j1 = i-1;
|
|
|
|
j2 = 0;
|
|
|
|
}
|
|
|
|
else if (i == 0)
|
|
|
|
{
|
2014-01-07 11:04:29 +01:00
|
|
|
j1 = list.size() - 1;
|
2014-01-02 16:50:01 +01:00
|
|
|
j2 = i + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
j1 = i - 1;
|
|
|
|
j2 = i + 1;
|
|
|
|
}
|
|
|
|
|
2014-01-07 11:04:29 +01:00
|
|
|
if (list.at(j1).getId() == p2 || list.at(j2).getId() == p2)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-25 15:40:24 +01:00
|
|
|
ptrdiff_t VDetail::Edge(const quint32 &p1, const quint32 &p2) const
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
|
|
|
if (OnEdge(p1, p2) == false)
|
|
|
|
{
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"Points don't on edge.";
|
2014-01-02 16:50:01 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-01-07 11:04:29 +01:00
|
|
|
QVector<VNodeDetail> list = listNodePoint();
|
|
|
|
ptrdiff_t i = indexOfNode(list, p1);
|
|
|
|
ptrdiff_t j = indexOfNode(list, p2);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
|
|
|
ptrdiff_t min = qMin(i, j);
|
|
|
|
|
2014-01-07 11:04:29 +01:00
|
|
|
if (min == 0 && (i == list.size() - 1 || j == list.size() - 1))
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-01-07 11:04:29 +01:00
|
|
|
return list.size() - 1;
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return min;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-25 15:40:24 +01:00
|
|
|
void VDetail::NodeOnEdge(const quint32 &index, VNodeDetail &p1, VNodeDetail &p2) const
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-01-07 11:04:29 +01:00
|
|
|
QVector<VNodeDetail> list = listNodePoint();
|
2014-02-25 15:55:02 +01:00
|
|
|
if (index > static_cast<quint32>(list.size()))
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"Wrong edge index index ="<<index;
|
2014-01-02 16:50:01 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-06-02 09:43:27 +02:00
|
|
|
p1 = list.at(static_cast<int>(index));
|
2014-02-25 15:55:02 +01:00
|
|
|
if (index + 1 > static_cast<quint32>(list.size()) - 1)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-01-07 11:04:29 +01:00
|
|
|
p2 = list.at(0);
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-02 09:43:27 +02:00
|
|
|
p2 = list.at(static_cast<int>(index+1));
|
2014-01-07 11:04:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-25 15:40:24 +01:00
|
|
|
VDetail VDetail::RemoveEdge(const quint32 &index) const
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
|
|
|
VDetail det(*this);
|
|
|
|
det.ClearNodes();
|
|
|
|
|
|
|
|
QVector<VNodeDetail> list = this->listNodePoint();
|
2014-02-25 15:55:02 +01:00
|
|
|
quint32 edge = static_cast<quint32>(list.size());
|
|
|
|
quint32 k = 0;
|
|
|
|
for (quint32 i=0; i<edge; ++i)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
2014-01-27 17:01:24 +01:00
|
|
|
if (i == index)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
2014-06-02 09:43:27 +02:00
|
|
|
det.append(this->at(static_cast<int>(k)));
|
2014-01-07 11:04:29 +01:00
|
|
|
++k;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VNodeDetail p1;
|
|
|
|
VNodeDetail p2;
|
|
|
|
this->NodeOnEdge(i, p1, p2);
|
|
|
|
ptrdiff_t j1 = this->indexOfNode(p1.getId());
|
|
|
|
ptrdiff_t j2 = this->indexOfNode(p2.getId());
|
2014-01-27 17:01:24 +01:00
|
|
|
if (j2 == 0)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
|
|
|
j2 = this->CountNode()-1;
|
2014-01-27 17:01:24 +01:00
|
|
|
if (j1 == j2)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
|
|
|
det.append(this->at(j1));
|
|
|
|
++k;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-01-27 17:01:24 +01:00
|
|
|
for (ptrdiff_t j=j1; j<j2; ++j)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
|
|
|
det.append(this->at(j));
|
|
|
|
++k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return det;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-25 15:40:24 +01:00
|
|
|
QList<quint32> VDetail::Missing(const VDetail &det) const
|
2014-01-13 01:48:31 +01:00
|
|
|
{
|
2014-01-27 17:01:24 +01:00
|
|
|
if (nodes.size() == det.CountNode())
|
2014-01-13 01:48:31 +01:00
|
|
|
{
|
2014-06-12 17:34:44 +02:00
|
|
|
return QList<quint32>();
|
2014-01-13 01:48:31 +01:00
|
|
|
}
|
|
|
|
|
2014-06-12 17:34:44 +02:00
|
|
|
QSet<quint32> set1;
|
2014-01-27 17:01:24 +01:00
|
|
|
for (qint32 i = 0; i < nodes.size(); ++i)
|
2014-01-13 01:48:31 +01:00
|
|
|
{
|
2014-06-12 17:34:44 +02:00
|
|
|
set1.insert(nodes.at(i).getId());
|
2014-01-13 01:48:31 +01:00
|
|
|
}
|
2014-06-12 17:34:44 +02:00
|
|
|
|
|
|
|
QSet<quint32> set2;
|
|
|
|
for (qint32 j = 0; j < det.CountNode(); ++j)
|
|
|
|
{
|
|
|
|
set2.insert(det.at(j).getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
QSet<quint32> set3 = set1.subtract(set2);
|
|
|
|
|
|
|
|
return set3.toList();
|
2014-01-13 01:48:31 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-01-07 11:04:29 +01:00
|
|
|
QVector<VNodeDetail> VDetail::listNodePoint() const
|
|
|
|
{
|
|
|
|
QVector<VNodeDetail> list;
|
|
|
|
for (ptrdiff_t i = 0; i < nodes.size(); ++i)
|
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
if (nodes.at(i).getTypeTool() == Tool::NodePoint)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
list.append(nodes.at(i));
|
2014-01-07 11:04:29 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
2014-01-07 11:04:29 +01:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-25 15:40:24 +01:00
|
|
|
ptrdiff_t VDetail::indexOfNode(const QVector<VNodeDetail> &list, const quint32 &id)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
|
|
|
for (ptrdiff_t i = 0; i < list.size(); ++i)
|
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
if (list.at(i).getId() == id)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"Can't find node.";
|
2014-01-07 11:04:29 +01:00
|
|
|
return -1;
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|