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.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2013-11-15 13:41:26 +01:00
|
|
|
** <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-08-20 13:11:12 +02:00
|
|
|
#include "vdetail_p.h"
|
2015-01-03 13:22:55 +01:00
|
|
|
#include "../container/vcontainer.h"
|
|
|
|
#include "vpointf.h"
|
2015-01-07 17:54:43 +01:00
|
|
|
#include "../core/vapplication.h"
|
2015-01-03 13:22:55 +01:00
|
|
|
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief VDetail default contructor. Create empty detail.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
VDetail::VDetail()
|
2015-01-02 18:02:07 +01:00
|
|
|
:VAbstractDetail(), d(new VDetailData)
|
2014-05-02 13:11:30 +02:00
|
|
|
{}
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief VDetail constructor.
|
|
|
|
* @param name detail name.
|
|
|
|
* @param nodes list of nodes.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
VDetail::VDetail(const QString &name, const QVector<VNodeDetail> &nodes)
|
2015-01-02 18:02:07 +01:00
|
|
|
:VAbstractDetail(name), d(new VDetailData(nodes))
|
2014-08-20 13:11:12 +02:00
|
|
|
{}
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief VDetail copy constructor.
|
|
|
|
* @param detail detail.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
VDetail::VDetail(const VDetail &detail)
|
2015-01-02 18:02:07 +01:00
|
|
|
:VAbstractDetail(detail), d (detail.d)
|
2014-05-02 13:11:30 +02:00
|
|
|
{}
|
2013-10-25 13:10:45 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief operator = assignment operator.
|
|
|
|
* @param detail detail.
|
|
|
|
* @return new detail.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
VDetail &VDetail::operator =(const VDetail &detail)
|
|
|
|
{
|
2014-07-27 14:30:28 +02:00
|
|
|
if ( &detail == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2015-01-02 18:02:07 +01:00
|
|
|
VAbstractDetail::operator=(detail);
|
2014-08-20 13:11:12 +02:00
|
|
|
d = detail.d;
|
2013-10-25 13:10:45 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-08-20 13:11:12 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VDetail::~VDetail()
|
|
|
|
{}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief Clear detail full clear.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VDetail::Clear()
|
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
d->nodes.clear();
|
|
|
|
d->mx = 0;
|
|
|
|
d->my = 0;
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief ClearNodes clear list of nodes.
|
|
|
|
*/
|
2014-01-07 11:04:29 +01:00
|
|
|
void VDetail::ClearNodes()
|
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
d->nodes.clear();
|
2014-01-07 11:04:29 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief Containes check if detail containe this id.
|
|
|
|
* @param id object id.
|
|
|
|
* @return true if containe.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
bool VDetail::Containes(const quint32 &id) const
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
for (int i = 0; i < d->nodes.size(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
VNodeDetail node = d->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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief operator [] find node by index in list.
|
|
|
|
* @param indx index node in list.
|
|
|
|
* @return node
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
VNodeDetail &VDetail::operator [](int indx)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
return d->nodes[indx];
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief at find node by index in list.
|
|
|
|
* @param indx index node in list.
|
|
|
|
* @return const node.
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
const VNodeDetail &VDetail::at(int indx) const
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
return d->nodes.at(indx);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief indexOfNode return index in list node using id object.
|
|
|
|
* @param id object (arc, point, spline, splinePath) id.
|
|
|
|
* @return index in list or -1 id can't find.
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
int VDetail::indexOfNode(const quint32 &id) const
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
return indexOfNode(d->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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief id return id detail in list data.
|
|
|
|
* @return id.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 VDetail::id() const
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
return d->_id;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief setId set id detail in list data.
|
|
|
|
* @param id detail id.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void VDetail::setId(const quint32 &id)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
d->_id = id;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
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();
|
2015-03-30 16:27:45 +02:00
|
|
|
if (list.size() < 2)
|
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;
|
|
|
|
}
|
2014-08-20 13:11:12 +02:00
|
|
|
int i = indexOfNode(list, p1);
|
|
|
|
int j1 = 0, j2 = 0;
|
2014-01-02 16:50:01 +01:00
|
|
|
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
int 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();
|
2014-08-20 13:11:12 +02:00
|
|
|
int i = indexOfNode(list, p1);
|
|
|
|
int j = indexOfNode(list, p2);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-08-20 13:11:12 +02:00
|
|
|
int min = qMin(i, j);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief NodeOnEdge return nodes located on edge with index.
|
|
|
|
* @param index index of edge.
|
|
|
|
* @param p1 first node.
|
|
|
|
* @param p2 second node.
|
|
|
|
*/
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief RemoveEdge return detail without edge with index.
|
|
|
|
* @param index idex of edge.
|
|
|
|
* @return detail without edge with index.
|
|
|
|
*/
|
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();
|
|
|
|
|
2015-03-30 14:43:30 +02:00
|
|
|
// Edge can be only segment. We ignore all curves inside segments.
|
|
|
|
const quint32 edges = static_cast<quint32>(listNodePoint().size());
|
2014-02-25 15:55:02 +01:00
|
|
|
quint32 k = 0;
|
2015-03-30 14:43:30 +02:00
|
|
|
for (quint32 i=0; i<edges; ++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);
|
2015-03-30 14:43:30 +02:00
|
|
|
const int j1 = this->indexOfNode(p1.getId());
|
2014-08-20 13:11:12 +02:00
|
|
|
int 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-08-20 13:11:12 +02:00
|
|
|
for (int j=j1; j<j2; ++j)
|
2015-03-30 14:43:30 +02:00
|
|
|
{// Add "segment" except last point. Inside can be curves too.
|
2014-01-07 11:04:29 +01:00
|
|
|
det.append(this->at(j));
|
|
|
|
++k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return det;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief Missing find missing ids in detail. When we deleted object in detail and return this detail need
|
|
|
|
* understand, what nodes need make invisible.
|
|
|
|
* @param det changed detail.
|
|
|
|
* @return list with missing detail.
|
|
|
|
*/
|
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-08-20 13:11:12 +02:00
|
|
|
if (d->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-08-20 13:11:12 +02:00
|
|
|
for (qint32 i = 0; i < d->nodes.size(); ++i)
|
2014-01-13 01:48:31 +01:00
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
set1.insert(d->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
|
|
|
}
|
|
|
|
|
2015-01-03 13:22:55 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPointF> VDetail::ContourPoints(const VContainer *data) const
|
|
|
|
{
|
|
|
|
QVector<QPointF> points;
|
|
|
|
for (int i = 0; i< CountNode(); ++i)
|
|
|
|
{
|
|
|
|
switch (at(i).getTypeTool())
|
|
|
|
{
|
|
|
|
case (Tool::NodePoint):
|
|
|
|
{
|
|
|
|
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(at(i).getId());
|
|
|
|
points.append(point->toQPointF());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (Tool::NodeArc):
|
|
|
|
case (Tool::NodeSpline):
|
|
|
|
case (Tool::NodeSplinePath):
|
|
|
|
{
|
|
|
|
const QSharedPointer<VAbstractCurve> curve = data->GeometricObject<VAbstractCurve>(at(i).getId());
|
|
|
|
|
|
|
|
const QPointF begin = StartSegment(data, i);
|
|
|
|
const QPointF end = EndSegment(data, i);
|
|
|
|
|
|
|
|
points << curve->GetSegmentPoints(begin, end, at(i).getReverse());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug()<<"Get wrong tool type. Ignore."<< static_cast<char>(at(i).getTypeTool());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPointF> VDetail::SeamAllowancePoints(const VContainer *data) const
|
|
|
|
{
|
|
|
|
QVector<QPointF> pointsEkv;
|
2015-03-14 13:38:44 +01:00
|
|
|
if (getSeamAllowance() == false)
|
|
|
|
{
|
|
|
|
return pointsEkv;
|
|
|
|
}
|
|
|
|
|
2015-01-03 13:22:55 +01:00
|
|
|
for (int i = 0; i< CountNode(); ++i)
|
|
|
|
{
|
|
|
|
switch (at(i).getTypeTool())
|
|
|
|
{
|
|
|
|
case (Tool::NodePoint):
|
|
|
|
{
|
|
|
|
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(at(i).getId());
|
2015-03-14 13:38:44 +01:00
|
|
|
QPointF pEkv = point->toQPointF();
|
|
|
|
pEkv.setX(pEkv.x()+at(i).getMx());
|
|
|
|
pEkv.setY(pEkv.y()+at(i).getMy());
|
|
|
|
pointsEkv.append(pEkv);
|
2015-01-03 13:22:55 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (Tool::NodeArc):
|
|
|
|
case (Tool::NodeSpline):
|
|
|
|
case (Tool::NodeSplinePath):
|
|
|
|
{
|
|
|
|
const QSharedPointer<VAbstractCurve> curve = data->GeometricObject<VAbstractCurve>(at(i).getId());
|
|
|
|
|
|
|
|
const QPointF begin = StartSegment(data, i);
|
|
|
|
const QPointF end = EndSegment(data, i);
|
|
|
|
|
|
|
|
QVector<QPointF> nodePoints = curve->GetSegmentPoints(begin, end, at(i).getReverse());
|
2015-03-14 13:38:44 +01:00
|
|
|
pointsEkv << biasPoints(nodePoints, at(i).getMx(), at(i).getMy());
|
2015-01-03 13:22:55 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug()<<"Get wrong tool type. Ignore."<< static_cast<char>(at(i).getTypeTool());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-16 20:35:50 +01:00
|
|
|
|
2015-03-14 13:38:44 +01:00
|
|
|
if (getClosed() == true)
|
2015-01-16 20:35:50 +01:00
|
|
|
{
|
2015-03-14 13:38:44 +01:00
|
|
|
pointsEkv = Equidistant(pointsEkv, EquidistantType::CloseEquidistant, qApp->toPixel(getWidth()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pointsEkv = Equidistant(pointsEkv, EquidistantType::OpenEquidistant, qApp->toPixel(getWidth()));
|
2015-01-16 20:35:50 +01:00
|
|
|
}
|
2015-01-03 13:22:55 +01:00
|
|
|
return pointsEkv;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-07 17:54:43 +01:00
|
|
|
QPainterPath VDetail::ContourPath(const VContainer *data) const
|
|
|
|
{
|
|
|
|
QVector<QPointF> points = ContourPoints(data);
|
|
|
|
QVector<QPointF> pointsEkv = SeamAllowancePoints(data);
|
|
|
|
|
|
|
|
QPainterPath path;
|
|
|
|
|
|
|
|
// contour
|
|
|
|
path.moveTo(points[0]);
|
|
|
|
for (qint32 i = 1; i < points.count(); ++i)
|
|
|
|
{
|
|
|
|
path.lineTo(points.at(i));
|
|
|
|
}
|
|
|
|
path.lineTo(points.at(0));
|
|
|
|
|
|
|
|
// seam allowence
|
|
|
|
if (getSeamAllowance() == true)
|
|
|
|
{
|
2015-03-28 13:26:49 +01:00
|
|
|
if (not pointsEkv.isEmpty())
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2015-03-28 13:26:49 +01:00
|
|
|
QPainterPath ekv;
|
|
|
|
ekv.moveTo(pointsEkv.at(0));
|
|
|
|
for (qint32 i = 1; i < pointsEkv.count(); ++i)
|
|
|
|
{
|
|
|
|
ekv.lineTo(pointsEkv.at(i));
|
|
|
|
}
|
2015-01-07 17:54:43 +01:00
|
|
|
|
2015-03-28 13:26:49 +01:00
|
|
|
path.addPath(ekv);
|
|
|
|
path.setFillRule(Qt::WindingFill);
|
|
|
|
}
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief listNodePoint return list nodes only with points.
|
|
|
|
* @return list points node.
|
|
|
|
*/
|
2014-01-07 11:04:29 +01:00
|
|
|
QVector<VNodeDetail> VDetail::listNodePoint() const
|
|
|
|
{
|
|
|
|
QVector<VNodeDetail> list;
|
2014-08-20 13:11:12 +02:00
|
|
|
for (int i = 0; i < d->nodes.size(); ++i)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
if (d->nodes.at(i).getTypeTool() == Tool::NodePoint)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
list.append(d->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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
int VDetail::indexOfNode(const QVector<VNodeDetail> &list, const quint32 &id)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
2014-08-20 13:11:12 +02:00
|
|
|
for (int i = 0; i < list.size(); ++i)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
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
|
|
|
}
|
2014-08-20 13:11:12 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-03 13:22:55 +01:00
|
|
|
QPointF VDetail::StartSegment(const VContainer *data, const int &i) const
|
|
|
|
{
|
|
|
|
QPointF begin;
|
|
|
|
if (CountNode() > 1)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
if (at(CountNode()-1).getTypeTool() == Tool::NodePoint)
|
|
|
|
{
|
|
|
|
begin = data->GeometricObject<VPointF>(at(CountNode()-1).getId())->toQPointF();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (at(i-1).getTypeTool() == Tool::NodePoint)
|
|
|
|
{
|
|
|
|
begin = data->GeometricObject<VPointF>(at(i-1).getId())->toQPointF();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return begin;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPointF VDetail::EndSegment(const VContainer *data, const int &i) const
|
|
|
|
{
|
|
|
|
QPointF end;
|
|
|
|
if (CountNode() > 2)
|
|
|
|
{
|
|
|
|
if (i == CountNode() - 1)
|
|
|
|
{
|
|
|
|
if (at(0).getTypeTool() == Tool::NodePoint)
|
|
|
|
{
|
|
|
|
end = data->GeometricObject<VPointF>(at(0).getId())->toQPointF();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (at(i+1).getTypeTool() == Tool::NodePoint)
|
|
|
|
{
|
|
|
|
end = data->GeometricObject<VPointF>(at(i+1).getId())->toQPointF();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return end;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief biasPoints bias point.
|
|
|
|
* @param points vector of points.
|
|
|
|
* @param mx offset respect to x.
|
|
|
|
* @param my offset respect to y.
|
|
|
|
* @return new vector biased points.
|
|
|
|
*/
|
|
|
|
QVector<QPointF> VDetail::biasPoints(const QVector<QPointF> &points, const qreal &mx, const qreal &my)
|
|
|
|
{
|
|
|
|
QVector<QPointF> p;
|
|
|
|
for (qint32 i = 0; i < points.size(); ++i)
|
|
|
|
{
|
|
|
|
QPointF point = points.at(i);
|
|
|
|
point.setX(point.x() + mx);
|
|
|
|
point.setY(point.y() + my);
|
|
|
|
p.append(point);
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief append append in the end of list node.
|
|
|
|
* @param node new node.
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
void VDetail::append(const VNodeDetail &node)
|
|
|
|
{
|
|
|
|
d->nodes.append(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief CountNode return count nodes.
|
|
|
|
* @return count.
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
qint32 VDetail::CountNode() const
|
|
|
|
{
|
|
|
|
return d->nodes.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief getMx return bias for X axis.
|
|
|
|
* @return x bias.
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
qreal VDetail::getMx() const
|
|
|
|
{
|
|
|
|
return d->mx;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief setMx set bias for X axis.
|
|
|
|
* @param value new x bias.
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
void VDetail::setMx(const qreal &value)
|
|
|
|
{
|
|
|
|
d->mx = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief getMy get bias for y axis.
|
|
|
|
* @return y axis.
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
qreal VDetail::getMy() const
|
|
|
|
{
|
|
|
|
return d->my;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief setMy set bias for y axis.
|
|
|
|
* @param value new y bias.
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
void VDetail::setMy(const qreal &value)
|
|
|
|
{
|
|
|
|
d->my = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief getNodes return list of nodes.
|
|
|
|
* @return list of nodes.
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
QVector<VNodeDetail> VDetail::getNodes() const
|
|
|
|
{
|
|
|
|
return d->nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 18:02:07 +01:00
|
|
|
/**
|
|
|
|
* @brief setNodes set list of nodes
|
|
|
|
* @param value list of nodes
|
|
|
|
*/
|
2014-08-20 13:11:12 +02:00
|
|
|
void VDetail::setNodes(const QVector<VNodeDetail> &value)
|
|
|
|
{
|
|
|
|
d->nodes = value;
|
|
|
|
}
|