2013-12-29 17:48:57 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vtooluniondetails.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-12-29 17:48:57 +01:00
|
|
|
** @date 26 12, 2013
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2013-12-29 17:48:57 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2013-12-29 17:48:57 +01:00
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** 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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vtooluniondetails.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QDomNodeList>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QLineF>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <QUndoStack>
|
|
|
|
#include <QtDebug>
|
|
|
|
#include <new>
|
|
|
|
|
2014-06-08 20:10:57 +02:00
|
|
|
#include "../dialogs/tools/dialoguniondetails.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/xml/vdomdocument.h"
|
2016-07-07 17:04:26 +02:00
|
|
|
#include "../ifc/xml/vpatternconverter.h"
|
2018-11-28 11:00:40 +01:00
|
|
|
#include "../ifc/exception/vexceptionwrongid.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vgeometry/varc.h"
|
2016-12-20 15:51:58 +01:00
|
|
|
#include "../vgeometry/vellipticalarc.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vgeometry/vsplinepath.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vgeometry/vabstractcubicbezier.h"
|
|
|
|
#include "../vgeometry/vabstractcubicbezierpath.h"
|
|
|
|
#include "../vgeometry/vgeometrydef.h"
|
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vgeometry/vspline.h"
|
|
|
|
#include "../vgeometry/vsplinepoint.h"
|
2017-10-15 11:25:20 +02:00
|
|
|
#include "../vgeometry/vplacelabelitem.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2017-01-16 11:08:13 +01:00
|
|
|
#include "../vpatterndb/vpiecepath.h"
|
|
|
|
#include "../vpatterndb/vpiecenode.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../dialogs/tools/dialogtool.h"
|
|
|
|
#include "nodeDetails/vnodearc.h"
|
2016-12-20 15:51:58 +01:00
|
|
|
#include "nodeDetails/vnodeellipticalarc.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "nodeDetails/vnodepoint.h"
|
|
|
|
#include "nodeDetails/vnodespline.h"
|
|
|
|
#include "nodeDetails/vnodesplinepath.h"
|
2017-01-16 16:37:15 +01:00
|
|
|
#include "nodeDetails/vtoolpiecepath.h"
|
2017-02-01 12:31:14 +01:00
|
|
|
#include "nodeDetails/vtoolpin.h"
|
2017-10-15 11:25:20 +02:00
|
|
|
#include "nodeDetails/vtoolplacelabel.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "vdatatool.h"
|
2017-01-16 11:08:13 +01:00
|
|
|
#include "vtoolseamallowance.h"
|
2016-01-07 17:43:08 +01:00
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
const QString VToolUnionDetails::ToolType = QStringLiteral("unionDetails");
|
|
|
|
const QString VToolUnionDetails::TagDetail = QStringLiteral("det");
|
|
|
|
const QString VToolUnionDetails::TagNode = QStringLiteral("node");
|
2016-01-07 17:43:08 +01:00
|
|
|
const QString VToolUnionDetails::TagChildren = QStringLiteral("children");
|
|
|
|
const QString VToolUnionDetails::TagChild = QStringLiteral("child");
|
2014-01-02 16:50:01 +01:00
|
|
|
const QString VToolUnionDetails::AttrIndexD1 = QStringLiteral("indexD1");
|
|
|
|
const QString VToolUnionDetails::AttrIndexD2 = QStringLiteral("indexD2");
|
2013-12-29 17:48:57 +01:00
|
|
|
const QString VToolUnionDetails::AttrIdObject = QStringLiteral("idObject");
|
|
|
|
const QString VToolUnionDetails::AttrNodeType = QStringLiteral("nodeType");
|
|
|
|
const QString VToolUnionDetails::NodeTypeContour = QStringLiteral("Contour");
|
|
|
|
const QString VToolUnionDetails::NodeTypeModeling = QStringLiteral("Modeling");
|
|
|
|
|
2017-10-23 09:45:58 +02:00
|
|
|
// Current version of union tag need for backward compatibility
|
|
|
|
const quint8 VToolUnionDetails::unionVersion = UNION_VERSSION;
|
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
|
|
|
QT_WARNING_DISABLE_INTEL(1418)
|
2016-01-07 17:43:08 +01:00
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_LOGGING_CATEGORY(vToolUnion, "v.toolUnion") // NOLINT
|
2016-01-07 17:43:08 +01:00
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|
2016-01-07 17:43:08 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
namespace
|
|
|
|
{
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-16 16:37:15 +01:00
|
|
|
VPiecePath GetPiecePath(int piece, VAbstractPattern *doc, quint32 id)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2017-08-02 13:10:10 +02:00
|
|
|
const QDomElement tool = doc->elementById(id, VAbstractPattern::TagTools);
|
2017-01-16 11:08:13 +01:00
|
|
|
if (tool.isNull())
|
|
|
|
{
|
|
|
|
VException e(QString("Can't get tool by id='%1'.").arg(id));
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomNodeList nodesList = tool.childNodes();
|
|
|
|
for (qint32 i = 0; i < nodesList.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement element = nodesList.at(i).toElement();
|
2017-01-18 09:17:18 +01:00
|
|
|
if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail && i+1 == piece)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
|
|
|
const QDomNodeList detList = element.childNodes();
|
|
|
|
for (qint32 j = 0; j < detList.size(); ++j)
|
|
|
|
{
|
|
|
|
const QDomElement element = detList.at(j).toElement();
|
2017-01-18 09:17:18 +01:00
|
|
|
if (not element.isNull() && element.tagName() == VAbstractPattern::TagNodes)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
|
|
|
return VAbstractPattern::ParsePieceNodes(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VPiecePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPiecePath GetPiece1MainPath(VAbstractPattern *doc, quint32 id)
|
|
|
|
{
|
2017-01-16 16:37:15 +01:00
|
|
|
return GetPiecePath(1, doc, id);
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPiecePath GetPiece2MainPath(VAbstractPattern *doc, quint32 id)
|
|
|
|
{
|
2017-01-16 16:37:15 +01:00
|
|
|
return GetPiecePath(2, doc, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-18 09:17:18 +01:00
|
|
|
QVector<CustomSARecord> GetPiece2CSAPaths(VAbstractPattern *doc, quint32 id)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
2017-08-02 13:10:10 +02:00
|
|
|
const QDomElement tool = doc->elementById(id, VAbstractPattern::TagTools);
|
2017-01-16 16:37:15 +01:00
|
|
|
if (tool.isNull())
|
|
|
|
{
|
|
|
|
VException e(QString("Can't get tool by id='%1'.").arg(id));
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomNodeList nodesList = tool.childNodes();
|
|
|
|
for (qint32 i = 0; i < nodesList.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement element = nodesList.at(i).toElement();
|
2017-01-18 09:17:18 +01:00
|
|
|
if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail && i+1 == 2)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
|
|
|
const QDomNodeList detList = element.childNodes();
|
|
|
|
for (qint32 j = 0; j < detList.size(); ++j)
|
|
|
|
{
|
|
|
|
const QDomElement element = detList.at(j).toElement();
|
2017-01-18 09:17:18 +01:00
|
|
|
if (not element.isNull() && element.tagName() == VToolSeamAllowance::TagCSA)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
|
|
|
return VAbstractPattern::ParsePieceCSARecords(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVector<CustomSARecord>();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-18 09:17:18 +01:00
|
|
|
QVector<quint32> GetPiece2InternalPaths(VAbstractPattern *doc, quint32 id)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
2017-08-02 13:10:10 +02:00
|
|
|
const QDomElement tool = doc->elementById(id, VAbstractPattern::TagTools);
|
2017-01-16 16:37:15 +01:00
|
|
|
if (tool.isNull())
|
|
|
|
{
|
|
|
|
VException e(QString("Can't get tool by id='%1'.").arg(id));
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomNodeList nodesList = tool.childNodes();
|
|
|
|
for (qint32 i = 0; i < nodesList.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement element = nodesList.at(i).toElement();
|
2017-01-18 09:17:18 +01:00
|
|
|
if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail && i+1 == 2)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
|
|
|
const QDomNodeList detList = element.childNodes();
|
|
|
|
for (qint32 j = 0; j < detList.size(); ++j)
|
|
|
|
{
|
|
|
|
const QDomElement element = detList.at(j).toElement();
|
2017-01-18 09:17:18 +01:00
|
|
|
if (not element.isNull() && element.tagName() == VToolSeamAllowance::TagIPaths)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
|
|
|
return VAbstractPattern::ParsePieceInternalPaths(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVector<quint32>();
|
|
|
|
}
|
|
|
|
|
2017-02-01 12:31:14 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<quint32> GetPiece2Pins(VAbstractPattern *doc, quint32 id)
|
|
|
|
{
|
2017-08-02 13:10:10 +02:00
|
|
|
const QDomElement tool = doc->elementById(id, VAbstractPattern::TagTools);
|
2017-02-01 12:31:14 +01:00
|
|
|
if (tool.isNull())
|
|
|
|
{
|
|
|
|
VException e(QString("Can't get tool by id='%1'.").arg(id));
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomNodeList nodesList = tool.childNodes();
|
|
|
|
for (qint32 i = 0; i < nodesList.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement element = nodesList.at(i).toElement();
|
|
|
|
if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail && i+1 == 2)
|
|
|
|
{
|
|
|
|
const QDomNodeList detList = element.childNodes();
|
|
|
|
for (qint32 j = 0; j < detList.size(); ++j)
|
|
|
|
{
|
|
|
|
const QDomElement element = detList.at(j).toElement();
|
|
|
|
if (not element.isNull() && element.tagName() == VToolSeamAllowance::TagPins)
|
|
|
|
{
|
2017-10-15 11:25:20 +02:00
|
|
|
return VAbstractPattern::ParsePiecePointRecords(element);
|
2017-02-01 12:31:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVector<quint32>();
|
|
|
|
}
|
|
|
|
|
2017-10-23 09:45:58 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<quint32> GetPiece2PlaceLabels(VAbstractPattern *doc, quint32 id)
|
|
|
|
{
|
|
|
|
const QDomElement tool = doc->elementById(id, VAbstractPattern::TagTools);
|
|
|
|
if (tool.isNull())
|
|
|
|
{
|
|
|
|
VException e(QString("Can't get tool by id='%1'.").arg(id));
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomNodeList nodesList = tool.childNodes();
|
|
|
|
for (qint32 i = 0; i < nodesList.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement element = nodesList.at(i).toElement();
|
|
|
|
if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail && i+1 == 2)
|
|
|
|
{
|
|
|
|
const QDomNodeList detList = element.childNodes();
|
|
|
|
for (qint32 j = 0; j < detList.size(); ++j)
|
|
|
|
{
|
|
|
|
const QDomElement element = detList.at(j).toElement();
|
|
|
|
if (not element.isNull() && element.tagName() == VToolSeamAllowance::TagPlaceLabels)
|
|
|
|
{
|
|
|
|
return VAbstractPattern::ParsePiecePointRecords(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVector<quint32>();
|
|
|
|
}
|
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DrawName(VAbstractPattern *doc, quint32 d1id, quint32 d2id)
|
|
|
|
{
|
2017-08-02 13:10:10 +02:00
|
|
|
const QDomElement detail1 = doc->elementById(d1id, VAbstractPattern::TagDetail);
|
2017-01-16 11:08:13 +01:00
|
|
|
if (detail1.isNull())
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2017-08-02 13:10:10 +02:00
|
|
|
const QDomElement detail2 = doc->elementById(d2id, VAbstractPattern::TagDetail);
|
2017-01-16 11:08:13 +01:00
|
|
|
if (detail2.isNull())
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomElement draw1 = detail1.parentNode().parentNode().toElement();
|
|
|
|
if (draw1.isNull() || not draw1.hasAttribute(VAbstractPattern::AttrName))
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomElement draw2 = detail2.parentNode().parentNode().toElement();
|
|
|
|
if (draw2.isNull() || not draw2.hasAttribute(VAbstractPattern::AttrName))
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString draw1Name = draw1.attribute(VAbstractPattern::AttrName);
|
|
|
|
const QString draw2Name = draw2.attribute(VAbstractPattern::AttrName);
|
|
|
|
|
|
|
|
if (draw1Name == draw2Name)
|
|
|
|
{
|
|
|
|
return draw1Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomElement pattern = draw1.parentNode().toElement();
|
|
|
|
if (pattern.isNull())
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
int indexD1 = 0;
|
|
|
|
int indexD2 = 0;
|
|
|
|
const QDomNodeList listDraws = pattern.elementsByTagName(VAbstractPattern::TagDraw);
|
|
|
|
for (int i=0; i < listDraws.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement draw = listDraws.at(i).toElement();
|
|
|
|
if (draw == draw1)
|
|
|
|
{
|
|
|
|
indexD1 = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (draw == draw2)
|
|
|
|
{
|
|
|
|
indexD2 = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (indexD1 >= indexD2)
|
|
|
|
{
|
|
|
|
return draw1Name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return draw2Name;
|
|
|
|
}
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
2017-01-16 11:08:13 +01:00
|
|
|
* @brief BiasRotatePoint bias and rotate point.
|
|
|
|
* @param point point.
|
|
|
|
* @param dx bias x axis.
|
|
|
|
* @param dy bias y axis.
|
2014-06-13 19:02:41 +02:00
|
|
|
* @param pRotate point rotation.
|
|
|
|
* @param angle angle rotation.
|
|
|
|
*/
|
2017-01-16 16:37:15 +01:00
|
|
|
void BiasRotatePoint(VPointF *point, qreal dx, qreal dy, const QPointF &pRotate, qreal angle)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
point->setX(point->x()+dx);
|
|
|
|
point->setY(point->y()+dy);
|
2017-03-31 16:04:11 +02:00
|
|
|
QLineF line(pRotate, static_cast<QPointF>(*point));
|
2017-01-16 11:08:13 +01:00
|
|
|
line.setAngle(line.angle()+angle);
|
|
|
|
point->setX(line.p2().x());
|
|
|
|
point->setY(line.p2().y());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-18 09:17:18 +01:00
|
|
|
void PointsOnEdge(const VPiecePath &path, quint32 index, VPointF &p1, VPointF &p2, VContainer *data)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
|
|
|
VPieceNode det2p1;
|
|
|
|
VPieceNode det2p2;
|
2017-01-18 09:17:18 +01:00
|
|
|
path.NodeOnEdge(index, det2p1, det2p2);
|
2017-01-16 11:08:13 +01:00
|
|
|
p1 = VPointF(*data->GeometricObject<VPointF>(det2p1.GetId()));
|
|
|
|
p2 = VPointF(*data->GeometricObject<VPointF>(det2p2.GetId()));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-18 09:17:18 +01:00
|
|
|
void UnionInitParameters(const VToolUnionDetailsInitData &initData, const VPiecePath &d1Path, const VPiecePath &d2Path,
|
|
|
|
VPieceNode &det1p1, qreal &dx, qreal &dy, qreal &angle)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
|
|
|
VPieceNode det1p2;
|
2017-01-18 09:17:18 +01:00
|
|
|
d1Path.NodeOnEdge(initData.indexD1, det1p1, det1p2);
|
2017-01-16 11:08:13 +01:00
|
|
|
Q_UNUSED(det1p2)
|
|
|
|
|
|
|
|
VPointF point1;
|
|
|
|
VPointF point2;
|
2017-01-18 09:17:18 +01:00
|
|
|
PointsOnEdge(d1Path, initData.indexD1, point1, point2, initData.data);
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
VPointF point3;
|
|
|
|
VPointF point4;
|
2017-01-18 09:17:18 +01:00
|
|
|
PointsOnEdge(d2Path, initData.indexD2, point3, point4, initData.data);
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
dx = point1.x() - point4.x();
|
|
|
|
dy = point1.y() - point4.y();
|
|
|
|
|
|
|
|
point3.setX(point3.x()+dx);
|
|
|
|
point3.setY(point3.y()+dy);
|
|
|
|
|
|
|
|
point4.setX(point4.x()+dx);
|
|
|
|
point4.setY(point4.y()+dy);
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
const QLineF p4p3 = QLineF(static_cast<QPointF>(point4), static_cast<QPointF>(point3));
|
|
|
|
const QLineF p1p2 = QLineF(static_cast<QPointF>(point1), static_cast<QPointF>(point2));
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
angle = p4p3.angleTo(p1p2);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
quint32 AddNodePoint(const VPieceNode &node, const VToolUnionDetailsInitData &initData,
|
2017-01-16 11:08:13 +01:00
|
|
|
QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy,
|
|
|
|
quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
QScopedPointer<VPointF> point(new VPointF(*initData.data->GeometricObject<VPointF>(node.GetId())));
|
|
|
|
point->setMode(Draw::Modeling);
|
|
|
|
|
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
BiasRotatePoint(point.data(), dx, dy, static_cast<QPointF>(*initData.data->GeometricObject<VPointF>(pRotate)),
|
|
|
|
angle);
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
2016-07-06 12:34:05 +02:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
QScopedPointer<VPointF> point1(new VPointF(*point));
|
2016-07-06 12:34:05 +02:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
const quint32 idObject = initData.data->AddGObject(point.take());
|
|
|
|
children.append(idObject);
|
2019-12-29 12:49:57 +01:00
|
|
|
point1->setIdObject(idObject);
|
2017-01-16 11:08:13 +01:00
|
|
|
point1->setMode(Draw::Modeling);
|
|
|
|
const quint32 id = initData.data->AddGObject(point1.take());
|
2017-09-18 10:37:23 +02:00
|
|
|
|
|
|
|
VAbstractNodeInitData initNodeData;
|
|
|
|
initNodeData.id = id;
|
|
|
|
initNodeData.idObject = idObject;
|
|
|
|
initNodeData.doc = initData.doc;
|
|
|
|
initNodeData.data = initData.data;
|
|
|
|
initNodeData.parse = Document::FullParse;
|
|
|
|
initNodeData.typeCreation = Source::FromTool;
|
|
|
|
initNodeData.idTool = initData.id;
|
|
|
|
initNodeData.drawName = drawName;
|
2017-10-23 09:45:58 +02:00
|
|
|
initNodeData.scene = initData.scene;
|
2017-09-18 10:37:23 +02:00
|
|
|
|
|
|
|
VNodePoint::Create(initNodeData);
|
2017-01-16 11:08:13 +01:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2017-02-01 12:31:14 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
quint32 AddPin(quint32 id, const VToolUnionDetailsInitData &initData, QVector<quint32> &children,
|
2017-02-01 12:31:14 +01:00
|
|
|
const QString &drawName, qreal dx, qreal dy, quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
QScopedPointer<VPointF> point(new VPointF(*initData.data->GeometricObject<VPointF>(id)));
|
|
|
|
point->setMode(Draw::Modeling);
|
|
|
|
|
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
BiasRotatePoint(point.data(), dx, dy, static_cast<QPointF>(*initData.data->GeometricObject<VPointF>(pRotate)),
|
|
|
|
angle);
|
2017-02-01 12:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QScopedPointer<VPointF> point1(new VPointF(*point));
|
|
|
|
|
|
|
|
const quint32 idObject = initData.data->AddGObject(point.take());
|
|
|
|
children.append(idObject);
|
|
|
|
point1->setMode(Draw::Modeling);
|
|
|
|
const quint32 idPin = initData.data->AddGObject(point1.take());
|
2017-09-18 10:37:23 +02:00
|
|
|
|
|
|
|
VToolPinInitData initNodeData;
|
|
|
|
initNodeData.id = idPin;
|
|
|
|
initNodeData.pointId = idObject;
|
|
|
|
initNodeData.idObject = NULL_ID;
|
|
|
|
initNodeData.doc = initData.doc;
|
|
|
|
initNodeData.data = initData.data;
|
|
|
|
initNodeData.parse = Document::FullParse;
|
|
|
|
initNodeData.typeCreation = Source::FromTool;
|
|
|
|
initNodeData.idTool = initData.id;
|
|
|
|
initNodeData.drawName = drawName;
|
|
|
|
|
|
|
|
VToolPin::Create(initNodeData);
|
2017-02-01 12:31:14 +01:00
|
|
|
return idPin;
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 AddPlaceLabel(quint32 id, const VToolUnionDetailsInitData &initData, QVector<quint32> &children,
|
|
|
|
const QString &drawName, qreal dx, qreal dy, quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
QScopedPointer<VPlaceLabelItem> label(new VPlaceLabelItem(*initData.data->GeometricObject<VPlaceLabelItem>(id)));
|
|
|
|
|
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
|
|
|
{
|
|
|
|
BiasRotatePoint(label.data(), dx, dy, static_cast<QPointF>(*initData.data->GeometricObject<VPointF>(pRotate)),
|
|
|
|
angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
label->SetCorrectionAngle(label->GetCorrectionAngle() + angle);
|
|
|
|
|
|
|
|
VToolPlaceLabelInitData initNodeData;
|
|
|
|
initNodeData.idObject = NULL_ID;
|
|
|
|
initNodeData.doc = initData.doc;
|
|
|
|
initNodeData.data = initData.data;
|
|
|
|
initNodeData.parse = Document::FullParse;
|
|
|
|
initNodeData.typeCreation = Source::FromTool;
|
|
|
|
initNodeData.idTool = initData.id;
|
|
|
|
initNodeData.drawName = drawName;
|
2017-10-23 09:45:58 +02:00
|
|
|
initNodeData.width = label->GetWidthFormula();
|
|
|
|
initNodeData.height = label->GetHeightFormula();
|
|
|
|
initNodeData.angle = label->GetAngleFormula();
|
2018-07-20 09:30:05 +02:00
|
|
|
initNodeData.visibilityTrigger = label->GetVisibilityTrigger();
|
2017-10-23 09:45:58 +02:00
|
|
|
initNodeData.type = label->GetLabelType();
|
|
|
|
|
|
|
|
QScopedPointer<VPlaceLabelItem> label1(new VPlaceLabelItem(*label));
|
|
|
|
|
|
|
|
initNodeData.centerPoint = initData.data->AddGObject(label.take());
|
|
|
|
children.append(initNodeData.centerPoint);
|
|
|
|
|
|
|
|
const quint32 idLabel = initData.data->AddGObject(label1.take());
|
|
|
|
initNodeData.id = idLabel;
|
2017-10-15 11:25:20 +02:00
|
|
|
|
|
|
|
VToolPlaceLabel::Create(initNodeData);
|
|
|
|
return idLabel;
|
|
|
|
}
|
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
quint32 AddNodeArc(const VPieceNode &node, const VToolUnionDetailsInitData &initData,
|
2017-01-16 11:08:13 +01:00
|
|
|
QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy,
|
|
|
|
quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VArc> arc = initData.data->GeometricObject<VArc>(node.GetId());
|
|
|
|
VPointF p1 = VPointF(arc->GetP1(), "A", 0, 0);
|
|
|
|
VPointF p2 = VPointF(arc->GetP2(), "A", 0, 0);
|
|
|
|
QScopedPointer<VPointF> center(new VPointF(arc->GetCenter()));
|
|
|
|
|
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
const QPointF p = static_cast<QPointF>(*initData.data->GeometricObject<VPointF>(pRotate));
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
BiasRotatePoint(&p1, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(&p2, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(center.data(), dx, dy, p, angle);
|
|
|
|
}
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
QLineF l1(static_cast<QPointF>(*center), static_cast<QPointF>(p1));
|
|
|
|
QLineF l2(static_cast<QPointF>(*center), static_cast<QPointF>(p2));
|
2017-01-16 11:08:13 +01:00
|
|
|
center->setMode(Draw::Modeling);
|
|
|
|
VPointF *tmpCenter = center.take();
|
|
|
|
const quint32 idCenter = initData.data->AddGObject(tmpCenter);
|
|
|
|
Q_UNUSED(idCenter)
|
|
|
|
QScopedPointer<VArc> arc1(new VArc(*tmpCenter, arc->GetRadius(), arc->GetFormulaRadius(), l1.angle(),
|
|
|
|
QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle())));
|
|
|
|
arc1->setMode(Draw::Modeling);
|
|
|
|
|
|
|
|
QScopedPointer<VArc>arc2(new VArc(*arc1));
|
|
|
|
|
|
|
|
const quint32 idObject = initData.data->AddGObject(arc1.take());
|
|
|
|
children.append(idObject);
|
|
|
|
|
2019-12-29 12:49:57 +01:00
|
|
|
arc2->setIdObject(idObject);
|
2017-01-16 11:08:13 +01:00
|
|
|
arc2->setMode(Draw::Modeling);
|
|
|
|
const quint32 id = initData.data->AddGObject(arc2.take());
|
|
|
|
|
2017-09-18 10:37:23 +02:00
|
|
|
VAbstractNodeInitData initNodeData;
|
|
|
|
initNodeData.id = id;
|
|
|
|
initNodeData.idObject = idObject;
|
|
|
|
initNodeData.doc = initData.doc;
|
|
|
|
initNodeData.data = initData.data;
|
|
|
|
initNodeData.parse = Document::FullParse;
|
|
|
|
initNodeData.typeCreation = Source::FromTool;
|
|
|
|
initNodeData.idTool = initData.id;
|
|
|
|
initNodeData.drawName = drawName;
|
|
|
|
|
|
|
|
VNodeArc::Create(initNodeData);
|
2017-01-16 11:08:13 +01:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
quint32 AddNodeElArc(const VPieceNode &node, const VToolUnionDetailsInitData &initData,
|
2017-01-16 11:08:13 +01:00
|
|
|
QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy,
|
|
|
|
quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VEllipticalArc> arc = initData.data->GeometricObject<VEllipticalArc>(node.GetId());
|
|
|
|
VPointF p1 = VPointF(arc->GetP1(), "A", 0, 0);
|
|
|
|
VPointF p2 = VPointF(arc->GetP2(), "A", 0, 0);
|
|
|
|
QScopedPointer<VPointF> center(new VPointF(arc->GetCenter()));
|
|
|
|
|
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
const QPointF p = static_cast<QPointF>(*initData.data->GeometricObject<VPointF>(pRotate));
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
BiasRotatePoint(&p1, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(&p2, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(center.data(), dx, dy, p, angle);
|
|
|
|
}
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
QLineF l1(static_cast<QPointF>(*center), static_cast<QPointF>(p1));
|
|
|
|
QLineF l2(static_cast<QPointF>(*center), static_cast<QPointF>(p2));
|
2017-01-16 11:08:13 +01:00
|
|
|
center->setMode(Draw::Modeling);
|
|
|
|
VPointF *tmpCenter = center.take();
|
|
|
|
quint32 idCenter = initData.data->AddGObject(tmpCenter);
|
|
|
|
Q_UNUSED(idCenter)
|
|
|
|
QScopedPointer<VEllipticalArc> arc1(new VEllipticalArc (*tmpCenter, arc->GetRadius1(), arc->GetRadius2(),
|
|
|
|
arc->GetFormulaRadius1(), arc->GetFormulaRadius2(),
|
|
|
|
l1.angle(), QString().setNum(l1.angle()), l2.angle(),
|
2018-04-12 12:13:19 +02:00
|
|
|
QString().setNum(l2.angle()), 0, QChar('0')));
|
2017-01-16 11:08:13 +01:00
|
|
|
arc1->setMode(Draw::Modeling);
|
|
|
|
|
|
|
|
QScopedPointer<VEllipticalArc> arc2(new VEllipticalArc(*arc1));
|
|
|
|
|
|
|
|
const quint32 idObject = initData.data->AddGObject(arc1.take());
|
|
|
|
children.append(idObject);
|
|
|
|
|
2019-12-29 12:49:57 +01:00
|
|
|
arc2->setIdObject(idObject);
|
2017-01-16 11:08:13 +01:00
|
|
|
arc2->setMode(Draw::Modeling);
|
|
|
|
const quint32 id = initData.data->AddGObject(arc2.take());
|
|
|
|
|
2017-09-18 10:37:23 +02:00
|
|
|
VAbstractNodeInitData initNodeData;
|
|
|
|
initNodeData.id = id;
|
|
|
|
initNodeData.idObject = idObject;
|
|
|
|
initNodeData.doc = initData.doc;
|
|
|
|
initNodeData.data = initData.data;
|
|
|
|
initNodeData.parse = Document::FullParse;
|
|
|
|
initNodeData.typeCreation = Source::FromTool;
|
|
|
|
initNodeData.idTool = initData.id;
|
|
|
|
initNodeData.drawName = drawName;
|
|
|
|
|
|
|
|
VNodeEllipticalArc::Create(initNodeData);
|
2017-01-16 11:08:13 +01:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
quint32 AddNodeSpline(const VPieceNode &node, const VToolUnionDetailsInitData &initData,
|
2017-01-16 11:08:13 +01:00
|
|
|
QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy,
|
|
|
|
quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VAbstractCubicBezier> spline =
|
|
|
|
initData.data->GeometricObject<VAbstractCubicBezier>(node.GetId());
|
|
|
|
|
|
|
|
QScopedPointer<VPointF> p1(new VPointF(spline->GetP1()));
|
|
|
|
VPointF p2 = VPointF(spline->GetP2());
|
|
|
|
VPointF p3 = VPointF(spline->GetP3());
|
|
|
|
QScopedPointer<VPointF> p4(new VPointF(spline->GetP4()));
|
|
|
|
|
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
const QPointF p = static_cast<QPointF>(*initData.data->GeometricObject<VPointF>(pRotate));
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
BiasRotatePoint(p1.data(), dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(&p2, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(&p3, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(p4.data(), dx, dy, p, angle);
|
|
|
|
}
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
VSpline *spl = new VSpline(*p1, static_cast<QPointF>(p2), static_cast<QPointF>(p3), *p4, 0, Draw::Modeling);
|
2017-01-16 11:08:13 +01:00
|
|
|
const quint32 idObject = initData.data->AddGObject(spl);
|
|
|
|
children.append(idObject);
|
|
|
|
|
|
|
|
VSpline *spl1 = new VSpline(*spl);
|
2019-12-29 12:49:57 +01:00
|
|
|
spl1->setIdObject(idObject);
|
2017-01-16 11:08:13 +01:00
|
|
|
spl1->setMode(Draw::Modeling);
|
|
|
|
const quint32 id = initData.data->AddGObject(spl1);
|
2017-09-18 10:37:23 +02:00
|
|
|
|
|
|
|
VAbstractNodeInitData initNodeData;
|
|
|
|
initNodeData.id = id;
|
|
|
|
initNodeData.idObject = idObject;
|
|
|
|
initNodeData.doc = initData.doc;
|
|
|
|
initNodeData.data = initData.data;
|
|
|
|
initNodeData.parse = Document::FullParse;
|
|
|
|
initNodeData.typeCreation = Source::FromTool;
|
|
|
|
initNodeData.idTool = initData.id;
|
|
|
|
initNodeData.drawName = drawName;
|
|
|
|
|
|
|
|
VNodeSpline::Create(initNodeData);
|
2017-01-16 11:08:13 +01:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
quint32 AddNodeSplinePath(const VPieceNode &node, const VToolUnionDetailsInitData &initData,
|
2017-01-16 11:08:13 +01:00
|
|
|
QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy,
|
|
|
|
quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
QScopedPointer<VSplinePath> path(new VSplinePath());
|
|
|
|
path->setMode(Draw::Modeling);
|
|
|
|
const QSharedPointer<VAbstractCubicBezierPath> splinePath =
|
|
|
|
initData.data->GeometricObject<VAbstractCubicBezierPath>(node.GetId());
|
|
|
|
for (qint32 i = 1; i <= splinePath->CountSubSpl(); ++i)
|
|
|
|
{
|
|
|
|
const VSpline spline = splinePath->GetSpline(i);
|
|
|
|
|
|
|
|
QScopedPointer<VPointF> p1(new VPointF(spline.GetP1()));
|
|
|
|
VPointF p2 = VPointF(spline.GetP2());
|
|
|
|
VPointF p3 = VPointF(spline.GetP3());
|
|
|
|
QScopedPointer<VPointF> p4(new VPointF(spline.GetP4()));
|
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
const QPointF p = static_cast<QPointF>(*initData.data->GeometricObject<VPointF>(pRotate));
|
2016-07-06 12:34:05 +02:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
BiasRotatePoint(p1.data(), dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(&p2, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(&p3, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(p4.data(), dx, dy, p, angle);
|
|
|
|
}
|
2016-08-08 16:34:50 +02:00
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
VSpline spl = VSpline(*p1, static_cast<QPointF>(p2), static_cast<QPointF>(p3), *p4);
|
2017-01-16 11:08:13 +01:00
|
|
|
if (i==1)
|
|
|
|
{
|
|
|
|
const qreal angle1 = spl.GetStartAngle()+180;
|
|
|
|
const QString angle1F = QString().number(angle1);
|
2016-07-06 12:34:05 +02:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
path->append(VSplinePoint(*p1, angle1, angle1F, spl.GetStartAngle(), spl.GetStartAngleFormula(),
|
2018-04-12 12:13:19 +02:00
|
|
|
0, QChar('0'), spline.GetC1Length(), spline.GetC1LengthFormula()));
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
const qreal angle2 = spl.GetEndAngle()+180;
|
|
|
|
const QString angle2F = QString().number(angle2);
|
|
|
|
qreal pL2 = 0;
|
2018-04-12 12:13:19 +02:00
|
|
|
QString pL2F('0');
|
2017-01-16 11:08:13 +01:00
|
|
|
if (i+1 <= splinePath->CountSubSpl())
|
2016-12-20 15:51:58 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
const VSpline nextSpline = splinePath->GetSpline(i+1);
|
|
|
|
pL2 = nextSpline.GetC1Length();
|
|
|
|
pL2F = nextSpline.GetC1LengthFormula();
|
|
|
|
}
|
2016-12-20 15:51:58 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
path->append(VSplinePoint(*p4, spl.GetEndAngle(), spl.GetEndAngleFormula(), angle2, angle2F,
|
|
|
|
spline.GetC2Length(), spline.GetC2LengthFormula(), pL2, pL2F));
|
|
|
|
}
|
|
|
|
QScopedPointer<VSplinePath> path1(new VSplinePath(*path));
|
2016-12-20 15:51:58 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
const quint32 idObject = initData.data->AddGObject(path.take());
|
|
|
|
children.append(idObject);
|
2016-12-20 15:51:58 +01:00
|
|
|
|
2019-12-29 12:49:57 +01:00
|
|
|
path1->setIdObject(idObject);
|
2017-01-16 11:08:13 +01:00
|
|
|
path1->setMode(Draw::Modeling);
|
|
|
|
const quint32 id = initData.data->AddGObject(path1.take());
|
|
|
|
|
2017-09-18 10:37:23 +02:00
|
|
|
VAbstractNodeInitData initNodeData;
|
|
|
|
initNodeData.id = id;
|
|
|
|
initNodeData.idObject = idObject;
|
|
|
|
initNodeData.doc = initData.doc;
|
|
|
|
initNodeData.data = initData.data;
|
|
|
|
initNodeData.parse = Document::FullParse;
|
|
|
|
initNodeData.typeCreation = Source::FromTool;
|
|
|
|
initNodeData.idTool = initData.id;
|
|
|
|
initNodeData.drawName = drawName;
|
|
|
|
|
|
|
|
VNodeSplinePath::Create(initNodeData);
|
2017-01-16 11:08:13 +01:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief AddToNewDetail create united detail adding one node per time.
|
|
|
|
*/
|
2017-03-24 13:48:07 +01:00
|
|
|
void AddNodeToNewPath(const VToolUnionDetailsInitData &initData, VPiecePath &newPath, VPieceNode node,
|
2017-09-18 10:37:23 +02:00
|
|
|
QVector<quint32> &children, const QString &drawName, qreal dx = 0, qreal dy = 0,
|
2017-01-16 16:37:15 +01:00
|
|
|
quint32 pRotate = NULL_ID, qreal angle = 0);
|
2017-01-16 11:08:13 +01:00
|
|
|
|
2017-03-24 13:48:07 +01:00
|
|
|
void AddNodeToNewPath(const VToolUnionDetailsInitData &initData, VPiecePath &newPath, VPieceNode node,
|
2017-09-18 10:37:23 +02:00
|
|
|
QVector<quint32> &children, const QString &drawName, qreal dx, qreal dy, quint32 pRotate,
|
|
|
|
qreal angle)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
|
|
|
quint32 id = 0;
|
|
|
|
switch (node.GetTypeTool())
|
|
|
|
{
|
|
|
|
case (Tool::NodePoint):
|
2017-09-18 10:37:23 +02:00
|
|
|
id = AddNodePoint(node, initData, children, drawName, dx, dy, pRotate, angle);
|
2017-01-16 11:08:13 +01:00
|
|
|
break;
|
|
|
|
case (Tool::NodeArc):
|
2017-09-18 10:37:23 +02:00
|
|
|
id = AddNodeArc(node, initData, children, drawName, dx, dy, pRotate, angle);
|
2017-01-16 11:08:13 +01:00
|
|
|
break;
|
|
|
|
case (Tool::NodeElArc):
|
2017-09-18 10:37:23 +02:00
|
|
|
id = AddNodeElArc(node, initData, children, drawName, dx, dy, pRotate, angle);
|
2017-01-16 11:08:13 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSpline):
|
2017-09-18 10:37:23 +02:00
|
|
|
id = AddNodeSpline(node, initData, children, drawName, dx, dy, pRotate, angle);
|
2017-01-16 11:08:13 +01:00
|
|
|
break;
|
|
|
|
case (Tool::NodeSplinePath):
|
2017-09-18 10:37:23 +02:00
|
|
|
id = AddNodeSplinePath(node, initData, children, drawName, dx, dy, pRotate, angle);
|
2017-01-16 11:08:13 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-21 16:18:48 +01:00
|
|
|
|
2017-03-24 13:48:07 +01:00
|
|
|
node.SetId(id);
|
|
|
|
newPath.Append(node);
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void FindIndexJ(qint32 pointsD2, const VPiecePath &d2Path, quint32 indexD2, qint32 &j)
|
|
|
|
{
|
|
|
|
if (pointsD2 == 0)
|
|
|
|
{
|
|
|
|
VPieceNode node1;
|
|
|
|
VPieceNode node2;
|
|
|
|
d2Path.NodeOnEdge(indexD2, node1, node2);
|
|
|
|
const VPiecePath removedD2 = d2Path.RemoveEdge(indexD2);
|
|
|
|
const int k = removedD2.indexOfNode(node2.GetId());
|
|
|
|
SCASSERT(k != -1)
|
|
|
|
if (k == removedD2.CountNodes()-1)
|
|
|
|
{//We have last node in detail, we wil begin from 0
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{// Continue from next node
|
|
|
|
j = k+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-16 16:37:15 +01:00
|
|
|
QDomElement GetTagChildren(VAbstractPattern *doc, quint32 id)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
2017-08-02 13:10:10 +02:00
|
|
|
QDomElement toolUnion = doc->elementById(id, VAbstractPattern::TagTools);
|
2017-01-16 11:08:13 +01:00
|
|
|
if (toolUnion.isNull())
|
|
|
|
{
|
2017-01-16 16:37:15 +01:00
|
|
|
VException e(QString("Can't get tool by id='%1'.").arg(id));
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDomElement tagChildren = toolUnion.firstChildElement(VToolUnionDetails::TagChildren);
|
|
|
|
|
|
|
|
if (tagChildren.isNull())
|
|
|
|
{
|
|
|
|
tagChildren = doc->createElement(VToolUnionDetails::TagChildren);
|
|
|
|
toolUnion.appendChild(tagChildren);
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
return tagChildren;
|
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void SaveChildren(VAbstractPattern *doc, quint32 id, QDomElement section, const QVector<quint32> &children)
|
|
|
|
{
|
2017-02-01 11:22:36 +01:00
|
|
|
if (children.size() > 0)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto child : children)
|
2017-02-01 11:22:36 +01:00
|
|
|
{
|
2019-07-10 12:07:29 +02:00
|
|
|
section.appendChild(doc->CreateElementWithText(VToolUnionDetails::TagChild, QString().setNum(child)));
|
2017-02-01 11:22:36 +01:00
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
|
2017-02-01 11:22:36 +01:00
|
|
|
GetTagChildren(doc, id).appendChild(section);
|
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-16 16:37:15 +01:00
|
|
|
void SaveNodesChildren(VAbstractPattern *doc, quint32 id, const QVector<quint32> &children)
|
|
|
|
{
|
|
|
|
SaveChildren(doc, id, doc->createElement(VAbstractPattern::TagNodes), children);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void SaveCSAChildren(VAbstractPattern *doc, quint32 id, const QVector<quint32> &children)
|
|
|
|
{
|
|
|
|
SaveChildren(doc, id, doc->createElement(VToolSeamAllowance::TagCSA), children);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void SaveInternalPathsChildren(VAbstractPattern *doc, quint32 id, const QVector<quint32> &children)
|
|
|
|
{
|
|
|
|
SaveChildren(doc, id, doc->createElement(VToolSeamAllowance::TagIPaths), children);
|
|
|
|
}
|
|
|
|
|
2017-02-01 12:31:14 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void SavePinsChildren(VAbstractPattern *doc, quint32 id, const QVector<quint32> &children)
|
|
|
|
{
|
|
|
|
SaveChildren(doc, id, doc->createElement(VToolSeamAllowance::TagPins), children);
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void SavePlaceLabelsChildren(VAbstractPattern *doc, quint32 id, const QVector<quint32> &children)
|
|
|
|
{
|
|
|
|
SaveChildren(doc, id, doc->createElement(VToolSeamAllowance::TagPlaceLabels), children);
|
|
|
|
}
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<quint32> GetChildren(VAbstractPattern *doc, quint32 id, const QString &tagName)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
2017-08-02 13:10:10 +02:00
|
|
|
const QDomElement toolUnion = doc->elementById(id, VAbstractPattern::TagTools);
|
2017-01-16 11:08:13 +01:00
|
|
|
if (toolUnion.isNull())
|
|
|
|
{
|
|
|
|
return QVector<quint32>();
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDomElement tagChildren = toolUnion.firstChildElement(VToolUnionDetails::TagChildren);
|
|
|
|
if (tagChildren.isNull())
|
|
|
|
{
|
|
|
|
return QVector<quint32>();
|
|
|
|
}
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
const QDomElement tagNodes = tagChildren.firstChildElement(tagName);
|
2017-01-16 11:08:13 +01:00
|
|
|
if (tagNodes.isNull())
|
|
|
|
{
|
|
|
|
return QVector<quint32>();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<quint32> childrenId;
|
|
|
|
const QDomNodeList listChildren = tagNodes.elementsByTagName(VToolUnionDetails::TagChild);
|
|
|
|
for (int i=0; i < listChildren.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement domElement = listChildren.at(i).toElement();
|
|
|
|
if (not domElement.isNull())
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
childrenId.append(domElement.text().toUInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return childrenId;
|
|
|
|
}
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<quint32> GetNodesChildren(VAbstractPattern *doc, quint32 id)
|
|
|
|
{
|
|
|
|
return GetChildren(doc, id, VAbstractPattern::TagNodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<quint32> GetCSAChildren(VAbstractPattern *doc, quint32 id)
|
|
|
|
{
|
|
|
|
return GetChildren(doc, id, VToolSeamAllowance::TagCSA);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<quint32> GetInternalPathsChildren(VAbstractPattern *doc, quint32 id)
|
|
|
|
{
|
|
|
|
return GetChildren(doc, id, VToolSeamAllowance::TagIPaths);
|
|
|
|
}
|
|
|
|
|
2017-02-01 12:31:14 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<quint32> GetPinChildren(VAbstractPattern *doc, quint32 id)
|
|
|
|
{
|
|
|
|
return GetChildren(doc, id, VToolSeamAllowance::TagPins);
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<quint32> GetPlaceLabelChildren(VAbstractPattern *doc, quint32 id)
|
|
|
|
{
|
|
|
|
return GetChildren(doc, id, VToolSeamAllowance::TagPlaceLabels);
|
|
|
|
}
|
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 TakeNextId(QVector<quint32> &children)
|
|
|
|
{
|
|
|
|
quint32 idChild = NULL_ID;
|
|
|
|
if (not children.isEmpty())
|
|
|
|
{
|
|
|
|
idChild = children.takeFirst();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idChild = NULL_ID;
|
|
|
|
}
|
|
|
|
return idChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void UpdateNodePoint(VContainer *data, const VPieceNode &node, QVector<quint32> &children, qreal dx, qreal dy,
|
|
|
|
quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
QScopedPointer<VPointF> point(new VPointF(*data->GeometricObject<VPointF>(node.GetId())));
|
|
|
|
point->setMode(Draw::Modeling);
|
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
BiasRotatePoint(point.data(), dx, dy, static_cast<QPointF>(*data->GeometricObject<VPointF>(pRotate)), angle);
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
|
|
|
data->UpdateGObject(TakeNextId(children), point.take());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void UpdateNodeArc(VContainer *data, const VPieceNode &node, QVector<quint32> &children, qreal dx, qreal dy,
|
|
|
|
quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(node.GetId());
|
|
|
|
VPointF p1 = VPointF(arc->GetP1());
|
|
|
|
VPointF p2 = VPointF(arc->GetP2());
|
|
|
|
QScopedPointer<VPointF> center(new VPointF(arc->GetCenter()));
|
|
|
|
|
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
const QPointF p = static_cast<QPointF>(*data->GeometricObject<VPointF>(pRotate));
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
BiasRotatePoint(&p1, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(&p2, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(center.data(), dx, dy, p, angle);
|
|
|
|
}
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
QLineF l1(static_cast<QPointF>(*center), static_cast<QPointF>(p1));
|
|
|
|
QLineF l2(static_cast<QPointF>(*center), static_cast<QPointF>(p2));
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
QScopedPointer<VArc> arc1(new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(), l1.angle(),
|
|
|
|
QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle())));
|
|
|
|
arc1->setMode(Draw::Modeling);
|
|
|
|
data->UpdateGObject(TakeNextId(children), arc1.take());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void UpdateNodeElArc(VContainer *data, const VPieceNode &node, QVector<quint32> &children, qreal dx, qreal dy,
|
|
|
|
quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VEllipticalArc> arc = data->GeometricObject<VEllipticalArc>(node.GetId());
|
|
|
|
VPointF p1 = VPointF(arc->GetP1());
|
|
|
|
VPointF p2 = VPointF(arc->GetP2());
|
|
|
|
QScopedPointer<VPointF> center(new VPointF(arc->GetCenter()));
|
|
|
|
|
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
const QPointF p = static_cast<QPointF>(*data->GeometricObject<VPointF>(pRotate));
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
BiasRotatePoint(&p1, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(&p2, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(center.data(), dx, dy, p, angle);
|
|
|
|
}
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
QLineF l1(static_cast<QPointF>(*center), static_cast<QPointF>(p1));
|
|
|
|
QLineF l2(static_cast<QPointF>(*center), static_cast<QPointF>(p2));
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
QScopedPointer<VEllipticalArc> arc1(new VEllipticalArc (*center, arc->GetRadius1(), arc->GetRadius2(),
|
|
|
|
arc->GetFormulaRadius1(), arc->GetFormulaRadius2(),
|
|
|
|
l1.angle(), QString().setNum(l1.angle()), l2.angle(),
|
2018-04-12 12:13:19 +02:00
|
|
|
QString().setNum(l2.angle()), 0, QChar('0')));
|
2017-01-16 11:08:13 +01:00
|
|
|
arc1->setMode(Draw::Modeling);
|
|
|
|
data->UpdateGObject(TakeNextId(children), arc1.take());
|
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void UpdateNodeSpline(VContainer *data, const VPieceNode &node, QVector<quint32> &children, qreal dx, qreal dy,
|
|
|
|
quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VAbstractCubicBezier> spline =
|
|
|
|
data->GeometricObject<VAbstractCubicBezier>(node.GetId());
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
QScopedPointer<VPointF> p1(new VPointF(spline->GetP1()));
|
|
|
|
VPointF p2 = VPointF(spline->GetP2());
|
|
|
|
VPointF p3 = VPointF(spline->GetP3());
|
|
|
|
QScopedPointer<VPointF> p4(new VPointF(spline->GetP4()));
|
2016-08-08 16:34:50 +02:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
const QPointF p = static_cast<QPointF>(*data->GeometricObject<VPointF>(pRotate));
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
BiasRotatePoint(p1.data(), dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(&p2, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(&p3, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(p4.data(), dx, dy, p, angle);
|
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
QScopedPointer<VSpline> spl(new VSpline(*p1, static_cast<QPointF>(p2), static_cast<QPointF>(p3), *p4, 0,
|
|
|
|
Draw::Modeling));
|
2017-01-16 11:08:13 +01:00
|
|
|
data->UpdateGObject(TakeNextId(children), spl.take());
|
|
|
|
}
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void UpdateNodeSplinePath(VContainer *data, const VPieceNode &node, QVector<quint32> &children, qreal dx, qreal dy,
|
|
|
|
quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
QScopedPointer<VSplinePath> path(new VSplinePath());
|
|
|
|
path->setMode(Draw::Modeling);
|
|
|
|
const QSharedPointer<VAbstractCubicBezierPath> splinePath =
|
|
|
|
data->GeometricObject<VAbstractCubicBezierPath>(node.GetId());
|
|
|
|
SCASSERT(splinePath != nullptr)
|
|
|
|
for (qint32 i = 1; i <= splinePath->CountSubSpl(); ++i)
|
|
|
|
{
|
|
|
|
const VSpline spline = splinePath->GetSpline(i);
|
2016-08-08 16:34:50 +02:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
QScopedPointer<VPointF> p1(new VPointF(spline.GetP1()));
|
|
|
|
VPointF p2 = VPointF(spline.GetP2());
|
|
|
|
VPointF p3 = VPointF(spline.GetP3());
|
|
|
|
QScopedPointer<VPointF> p4(new VPointF(spline.GetP4()));
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
const QPointF p = static_cast<QPointF>(*data->GeometricObject<VPointF>(pRotate));
|
2016-03-04 17:08:29 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
BiasRotatePoint(p1.data(), dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(&p2, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(&p3, dx, dy, p, angle);
|
|
|
|
BiasRotatePoint(p4.data(), dx, dy, p, angle);
|
|
|
|
}
|
2016-03-04 17:08:29 +01:00
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
VSpline spl = VSpline(*p1, static_cast<QPointF>(p2), static_cast<QPointF>(p3), *p4);
|
2017-01-16 11:08:13 +01:00
|
|
|
if (i==1)
|
|
|
|
{
|
|
|
|
const qreal angle1 = spl.GetStartAngle()+180;
|
|
|
|
const QString angle1F = QString().number(angle1);
|
2016-03-04 17:08:29 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
path->append(VSplinePoint(*p1, angle1, angle1F, spl.GetStartAngle(), spl.GetStartAngleFormula(),
|
2018-04-12 12:13:19 +02:00
|
|
|
0, QChar('0'), spline.GetC1Length(), spline.GetC1LengthFormula()));
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
2016-03-04 17:08:29 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
const qreal angle2 = spl.GetEndAngle()+180;
|
|
|
|
const QString angle2F = QString().number(angle2);
|
2016-07-06 12:34:05 +02:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
qreal pL2 = 0;
|
2018-04-12 12:13:19 +02:00
|
|
|
QString pL2F('0');
|
2017-01-16 11:08:13 +01:00
|
|
|
if (i+1 <= splinePath->CountSubSpl())
|
|
|
|
{
|
|
|
|
const VSpline nextSpline = splinePath->GetSpline(i+1);
|
|
|
|
pL2 = nextSpline.GetC1Length();
|
|
|
|
pL2F = nextSpline.GetC1LengthFormula();
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
path->append(VSplinePoint(*p4, spl.GetEndAngle(), spl.GetEndAngleFormula(), angle2, angle2F,
|
|
|
|
spline.GetC2Length(), spline.GetC2LengthFormula(), pL2, pL2F));
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
data->UpdateGObject(TakeNextId(children), path.take());
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
2017-01-16 11:08:13 +01:00
|
|
|
* @brief UpdateNodes update nodes of united detail.
|
2014-06-13 19:02:41 +02:00
|
|
|
* @param data container with variables.
|
2017-01-27 13:07:12 +01:00
|
|
|
* @param node detail's node.
|
2016-01-07 17:43:08 +01:00
|
|
|
* @param children list ids of all children.
|
2014-06-13 19:02:41 +02:00
|
|
|
* @param dx bias node x axis.
|
|
|
|
* @param dy bias node y axis.
|
|
|
|
* @param pRotate point rotation.
|
|
|
|
* @param angle angle rotation.
|
|
|
|
*/
|
2017-01-16 16:37:15 +01:00
|
|
|
void UpdatePathNode(VContainer *data, const VPieceNode &node, QVector<quint32> &children,
|
2017-01-16 11:08:13 +01:00
|
|
|
qreal dx = 0, qreal dy = 0, quint32 pRotate = NULL_ID, qreal angle = 0);
|
2017-01-16 16:37:15 +01:00
|
|
|
void UpdatePathNode(VContainer *data, const VPieceNode &node, QVector<quint32> &children, qreal dx, qreal dy,
|
2017-01-16 11:08:13 +01:00
|
|
|
quint32 pRotate, qreal angle)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
switch (node.GetTypeTool())
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodePoint):
|
2017-01-16 11:08:13 +01:00
|
|
|
UpdateNodePoint(data, node, children, dx, dy, pRotate, angle);
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeArc):
|
2017-01-16 11:08:13 +01:00
|
|
|
UpdateNodeArc(data, node, children, dx, dy, pRotate, angle);
|
|
|
|
break;
|
|
|
|
case (Tool::NodeElArc):
|
|
|
|
UpdateNodeElArc(data, node, children, dx, dy, pRotate, angle);
|
|
|
|
break;
|
|
|
|
case (Tool::NodeSpline):
|
|
|
|
UpdateNodeSpline(data, node, children, dx, dy, pRotate, angle);
|
|
|
|
break;
|
|
|
|
case (Tool::NodeSplinePath):
|
|
|
|
UpdateNodeSplinePath(data, node, children, dx, dy, pRotate, angle);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-07-06 12:34:05 +02:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void CreateUnitedNodes(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName,
|
2017-01-16 16:37:15 +01:00
|
|
|
const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
|
|
|
const VPiecePath d1Path = d1.GetPath().RemoveEdge(initData.indexD1);
|
|
|
|
const VPiecePath d2Path = d2.GetPath().RemoveEdge(initData.indexD2);
|
2015-03-31 12:39:10 +02:00
|
|
|
|
2018-04-03 13:36:38 +02:00
|
|
|
const auto unitedPath = VToolUnionDetails::CalcUnitedPath(d1Path, d2Path, initData.indexD2, pRotate);
|
2016-12-20 15:51:58 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
QVector<quint32> children;
|
2017-01-16 16:37:15 +01:00
|
|
|
VPiecePath newPath;
|
2017-09-11 14:56:18 +02:00
|
|
|
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto &path : unitedPath)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
if (path.first)
|
2017-09-11 14:56:18 +02:00
|
|
|
{// first piece
|
2018-04-03 13:36:38 +02:00
|
|
|
AddNodeToNewPath(initData, newPath, path.second, children, drawName);
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
2017-09-11 14:56:18 +02:00
|
|
|
else
|
|
|
|
{// second piece
|
2018-04-03 13:36:38 +02:00
|
|
|
AddNodeToNewPath(initData, newPath, path.second, children, drawName, dx, dy, pRotate, angle);
|
2017-09-11 14:56:18 +02:00
|
|
|
}
|
|
|
|
}
|
2016-12-20 15:51:58 +01:00
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
newDetail.SetPath(newPath);
|
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
SCASSERT(not children.isEmpty())
|
2017-09-18 10:37:23 +02:00
|
|
|
SaveNodesChildren(initData.doc, initData.id, children);
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
2016-12-20 15:51:58 +01:00
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector<quint32> &children,
|
2017-01-16 16:37:15 +01:00
|
|
|
const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy,
|
|
|
|
quint32 pRotate, qreal angle)
|
|
|
|
{
|
2017-01-18 09:17:18 +01:00
|
|
|
QVector<quint32> nodeChildren;
|
2018-04-02 19:38:56 +02:00
|
|
|
const QVector<CustomSARecord> records = d.GetCustomSARecords();
|
|
|
|
for(auto record : records)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
2017-01-16 16:37:15 +01:00
|
|
|
const VPiecePath path = initData.data->GetPiecePath(record.path);
|
|
|
|
VPiecePath newPath = path;
|
|
|
|
newPath.Clear();//Clear nodes
|
|
|
|
for (int i=0; i < path.CountNodes(); ++i)
|
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
AddNodeToNewPath(initData, newPath, path.at(i), nodeChildren, drawName, dx, dy, pRotate, angle);
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
2017-01-18 09:17:18 +01:00
|
|
|
const quint32 idPath = initData.data->AddPiecePath(newPath);
|
2017-09-18 10:37:23 +02:00
|
|
|
|
|
|
|
VToolPiecePathInitData initNodeData;
|
|
|
|
initNodeData.id = idPath;
|
|
|
|
initNodeData.idObject = NULL_ID;
|
|
|
|
initNodeData.scene = initData.scene;
|
|
|
|
initNodeData.doc = initData.doc;
|
|
|
|
initNodeData.data = initData.data;
|
|
|
|
initNodeData.parse = Document::FullParse;
|
|
|
|
initNodeData.typeCreation = Source::FromTool;
|
|
|
|
initNodeData.idTool = initData.id;
|
|
|
|
initNodeData.drawName = drawName;
|
|
|
|
initNodeData.path = newPath;
|
|
|
|
|
|
|
|
VToolPiecePath::Create(initNodeData);
|
2017-01-18 09:17:18 +01:00
|
|
|
record.path = idPath;
|
2017-01-31 15:26:28 +01:00
|
|
|
newDetail.GetCustomSARecords().append(record);
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
2017-01-18 09:17:18 +01:00
|
|
|
children += nodeChildren;
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void CreateUnitedCSA(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName,
|
2017-01-16 16:37:15 +01:00
|
|
|
const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
|
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
const QVector<CustomSARecord> records = d1.GetCustomSARecords();
|
|
|
|
for (auto record : records)
|
2017-01-18 09:17:18 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
newDetail.GetCustomSARecords().append(record);
|
2017-01-18 09:17:18 +01:00
|
|
|
}
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
QVector<quint32> children;
|
2017-09-18 10:37:23 +02:00
|
|
|
CreateUnitedDetailCSA(newDetail, d2, children, drawName, initData, dx, dy, pRotate, angle);
|
|
|
|
SaveCSAChildren(initData.doc, initData.id, children);
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector<quint32> &children,
|
2017-01-16 16:37:15 +01:00
|
|
|
const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx,
|
|
|
|
qreal dy, quint32 pRotate, qreal angle)
|
|
|
|
{
|
2017-01-18 09:17:18 +01:00
|
|
|
QVector<quint32> nodeChildren;
|
2018-04-02 19:38:56 +02:00
|
|
|
const QVector<quint32> internalPaths = d.GetInternalPaths();
|
|
|
|
for(auto iPath : internalPaths)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
const VPiecePath path = initData.data->GetPiecePath(iPath);
|
2017-01-16 16:37:15 +01:00
|
|
|
VPiecePath newPath = path;
|
|
|
|
newPath.Clear();//Clear nodes
|
|
|
|
|
|
|
|
for (int i=0; i < path.CountNodes(); ++i)
|
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
AddNodeToNewPath(initData, newPath, path.at(i), nodeChildren, drawName, dx, dy, pRotate, angle);
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
2017-01-18 09:17:18 +01:00
|
|
|
const quint32 idPath = initData.data->AddPiecePath(newPath);
|
2017-09-18 10:37:23 +02:00
|
|
|
|
|
|
|
VToolPiecePathInitData initNodeData;
|
|
|
|
initNodeData.id = idPath;
|
|
|
|
initNodeData.idObject = NULL_ID;
|
|
|
|
initNodeData.scene = initData.scene;
|
|
|
|
initNodeData.doc = initData.doc;
|
|
|
|
initNodeData.data = initData.data;
|
|
|
|
initNodeData.parse = Document::FullParse;
|
|
|
|
initNodeData.typeCreation = Source::FromTool;
|
|
|
|
initNodeData.idTool = initData.id;
|
|
|
|
initNodeData.drawName = drawName;
|
|
|
|
initNodeData.path = newPath;
|
|
|
|
|
|
|
|
VToolPiecePath::Create(initNodeData);
|
2017-01-31 15:26:28 +01:00
|
|
|
newDetail.GetInternalPaths().append(idPath);
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
2017-01-18 09:17:18 +01:00
|
|
|
children += nodeChildren;
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName,
|
|
|
|
const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
|
|
|
|
qreal angle)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
const QVector<quint32> paths = d1.GetInternalPaths();
|
|
|
|
for (auto path : paths)
|
2017-01-18 09:17:18 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
newDetail.GetInternalPaths().append(path);
|
2017-01-18 09:17:18 +01:00
|
|
|
}
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
QVector<quint32> children;
|
2017-09-18 10:37:23 +02:00
|
|
|
CreateUnitedDetailInternalPaths(newDetail, d2, children, drawName, initData, dx, dy, pRotate, angle);
|
2017-01-16 16:37:15 +01:00
|
|
|
|
2017-09-18 10:37:23 +02:00
|
|
|
SaveInternalPathsChildren(initData.doc, initData.id, children);
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
|
|
|
|
2017-02-01 12:31:14 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void CreateUnitedDetailPins(VPiece &newDetail, const VPiece &d, QVector<quint32> &children,
|
2017-02-01 12:31:14 +01:00
|
|
|
const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy,
|
|
|
|
quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
QVector<quint32> nodeChildren;
|
2018-04-02 19:38:56 +02:00
|
|
|
const QVector<quint32> pins = d.GetPins();
|
|
|
|
for(auto pin : pins)
|
2017-02-01 12:31:14 +01:00
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
const quint32 id = AddPin(pin, initData, children, drawName, dx, dy, pRotate, angle);
|
2017-02-01 12:31:14 +01:00
|
|
|
newDetail.GetPins().append(id);
|
|
|
|
}
|
|
|
|
children += nodeChildren;
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void CreateUnitedDetailPlaceLabels(VPiece &newDetail, const VPiece &d, QVector<quint32> &children,
|
|
|
|
const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx,
|
|
|
|
qreal dy, quint32 pRotate, qreal angle)
|
|
|
|
{
|
|
|
|
QVector<quint32> nodeChildren;
|
2018-04-02 19:38:56 +02:00
|
|
|
const QVector<quint32> placeLabels = d.GetPlaceLabels();
|
|
|
|
for(auto placeLabel : placeLabels)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
const quint32 id = AddPlaceLabel(placeLabel, initData, children, drawName, dx, dy, pRotate, angle);
|
2017-10-15 11:25:20 +02:00
|
|
|
newDetail.GetPlaceLabels().append(id);
|
|
|
|
}
|
|
|
|
children += nodeChildren;
|
|
|
|
}
|
|
|
|
|
2017-02-01 12:31:14 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void CreateUnitedPins(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName,
|
2017-02-01 12:31:14 +01:00
|
|
|
const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
|
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
const auto pins = d1.GetPins();
|
|
|
|
for (auto pin : pins)
|
2017-02-01 12:31:14 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
newDetail.GetPins().append(pin);
|
2017-02-01 12:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QVector<quint32> children;
|
2017-09-18 10:37:23 +02:00
|
|
|
CreateUnitedDetailPins(newDetail, d2, children, drawName, initData, dx, dy, pRotate, angle);
|
|
|
|
SavePinsChildren(initData.doc, initData.id, children);
|
2017-02-01 12:31:14 +01:00
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void CreateUnitedPlaceLabels(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName,
|
|
|
|
const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
|
|
|
|
qreal angle)
|
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
const auto labels = d1.GetPlaceLabels();
|
|
|
|
for (auto label : labels)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
newDetail.GetPlaceLabels().append(label);
|
2017-10-15 11:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QVector<quint32> children;
|
|
|
|
CreateUnitedDetailPlaceLabels(newDetail, d2, children, drawName, initData, dx, dy, pRotate, angle);
|
|
|
|
SavePlaceLabelsChildren(initData.doc, initData.id, children);
|
|
|
|
}
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void UpdateUnitedNodes(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
const VPiecePath d1REPath = GetPiece1MainPath(initData.doc, initData.id).RemoveEdge(initData.indexD1);
|
|
|
|
const VPiecePath d2REPath = GetPiece2MainPath(initData.doc, initData.id).RemoveEdge(initData.indexD2);
|
2016-07-06 12:34:05 +02:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
const qint32 countNodeD1 = d1REPath.CountNodes();
|
|
|
|
const qint32 countNodeD2 = d2REPath.CountNodes();
|
|
|
|
|
2017-09-18 10:37:23 +02:00
|
|
|
QVector<quint32> children = GetNodesChildren(initData.doc, initData.id);
|
2017-01-16 11:08:13 +01:00
|
|
|
if (not children.isEmpty())
|
|
|
|
{
|
|
|
|
// This check need for backward compatibility
|
|
|
|
// Remove check and "else" part if min version is 0.3.2
|
2021-09-11 18:39:38 +02:00
|
|
|
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 3, 2),
|
2017-01-16 11:08:13 +01:00
|
|
|
"Time to refactor the code.");
|
|
|
|
if (children.size() == countNodeD1 + countNodeD2-1)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
const auto unitedPath = VToolUnionDetails::CalcUnitedPath(d1REPath, d2REPath, initData.indexD2, pRotate);
|
2017-09-11 14:56:18 +02:00
|
|
|
|
2019-02-03 14:53:51 +01:00
|
|
|
for (auto &path : unitedPath)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
if (path.first)
|
2017-09-11 14:56:18 +02:00
|
|
|
{// first piece
|
2018-04-03 13:36:38 +02:00
|
|
|
UpdatePathNode(initData.data, path.second, children);
|
2016-07-06 12:34:05 +02:00
|
|
|
}
|
2017-09-11 14:56:18 +02:00
|
|
|
else
|
|
|
|
{// second piece
|
2018-04-03 13:36:38 +02:00
|
|
|
UpdatePathNode(initData.data, path.second, children, dx, dy, pRotate, angle);
|
2017-09-11 14:56:18 +02:00
|
|
|
}
|
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
|
|
|
else // remove if min version is 0.3.2
|
|
|
|
{
|
2017-01-16 16:37:15 +01:00
|
|
|
qint32 pointsD2 = 0; //Keeps number points the second detail, what we have already added.
|
2017-01-16 11:08:13 +01:00
|
|
|
qint32 i = 0;
|
2017-09-11 14:56:18 +02:00
|
|
|
const int indexOfNode = d1REPath.indexOfNode(pRotate);
|
2017-01-16 11:08:13 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if (i > indexOfNode)
|
2016-07-06 12:34:05 +02:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
const int childrenCount = children.size();
|
|
|
|
qint32 j = 0;
|
2017-09-11 14:56:18 +02:00
|
|
|
FindIndexJ(pointsD2, d2REPath, initData.indexD2, j);
|
2017-01-16 11:08:13 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (j >= countNodeD2)
|
|
|
|
{
|
|
|
|
j=0;
|
|
|
|
}
|
2017-01-16 16:37:15 +01:00
|
|
|
UpdatePathNode(initData.data, d2REPath.at(j), children, dx, dy, pRotate, angle);
|
2017-01-16 11:08:13 +01:00
|
|
|
++pointsD2;
|
|
|
|
++j;
|
|
|
|
} while (pointsD2 < childrenCount);
|
|
|
|
break;
|
2016-07-06 12:34:05 +02:00
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
} while (i<countNodeD1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-04 17:08:29 +01:00
|
|
|
|
2018-06-05 11:22:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief FixChildren fix bug in first version of Union Details Tool.
|
|
|
|
*
|
|
|
|
* Bugged code produces incorrect order which breaks convention. This function fix the excpected order.
|
|
|
|
*/
|
|
|
|
QVector<quint32> FixChildren(QVector<quint32> records, QVector<quint32> children, VContainer *data)
|
|
|
|
{
|
|
|
|
// TODO. Delete if minimal supported version is 0.7.0
|
2021-09-11 18:39:38 +02:00
|
|
|
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 7, 0),
|
2018-06-05 11:22:31 +02:00
|
|
|
"Time to refactor the code.");
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
|
|
|
|
if (records.isEmpty())
|
|
|
|
{
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<quint32> fixedChildren;
|
|
|
|
while(not records.isEmpty())
|
|
|
|
{
|
|
|
|
const qint32 childrenIndex = records.size()-1;
|
|
|
|
if (children.size() > childrenIndex)
|
|
|
|
{
|
|
|
|
fixedChildren.append(children.takeAt(childrenIndex));
|
|
|
|
|
|
|
|
const VPiecePath path = data->GetPiecePath(records.takeFirst());
|
|
|
|
for (int i=0; i < path.CountNodes(); ++i)
|
|
|
|
{
|
|
|
|
if (children.size() > childrenIndex)
|
|
|
|
{
|
|
|
|
fixedChildren.append(children.takeAt(childrenIndex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fixedChildren;
|
|
|
|
}
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-18 09:17:18 +01:00
|
|
|
void UpdateUnitedDetailPaths(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
|
|
|
|
qreal angle, const QVector<quint32> &records, QVector<quint32> children)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
2018-06-05 11:22:31 +02:00
|
|
|
if (initData.version == 1)
|
|
|
|
{
|
|
|
|
// TODO. Delete if minimal supported version is 0.7.0
|
2021-09-11 18:39:38 +02:00
|
|
|
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 7, 0),
|
2018-06-05 11:22:31 +02:00
|
|
|
"Time to refactor the code.");
|
|
|
|
// Fixing bug in first version of the tool. Mostly for backward compatibility.
|
|
|
|
children = FixChildren(records, children, initData.data);
|
|
|
|
}
|
|
|
|
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto record : records)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
const VPiecePath path = initData.data->GetPiecePath(record);
|
2017-01-16 16:37:15 +01:00
|
|
|
|
2017-10-23 09:45:58 +02:00
|
|
|
if (initData.version == 1)
|
|
|
|
{
|
|
|
|
// TODO. Delete if minimal supported version is 0.7.0
|
2021-09-11 18:39:38 +02:00
|
|
|
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 7, 0),
|
2017-10-23 09:45:58 +02:00
|
|
|
"Time to refactor the code.");
|
|
|
|
const quint32 updatedId = TakeNextId(children);
|
|
|
|
|
|
|
|
VPiecePath updatedPath(path);
|
|
|
|
updatedPath.Clear();
|
2017-01-18 09:17:18 +01:00
|
|
|
|
2017-10-23 09:45:58 +02:00
|
|
|
for (int j=0; j < path.CountNodes(); ++j)
|
|
|
|
{
|
|
|
|
const VPieceNode &node = path.at(j);
|
|
|
|
const quint32 id = TakeNextId(children);
|
|
|
|
updatedPath.Append(VPieceNode(id, node.GetTypeTool(), node.GetReverse()));
|
2018-06-05 11:22:31 +02:00
|
|
|
QVector<quint32> nodeChildren {id};
|
2017-10-23 09:45:58 +02:00
|
|
|
UpdatePathNode(initData.data, path.at(j), nodeChildren, dx, dy, pRotate, angle);
|
|
|
|
}
|
|
|
|
initData.data->UpdatePiecePath(updatedId, updatedPath);
|
|
|
|
}
|
|
|
|
else
|
2017-01-18 09:17:18 +01:00
|
|
|
{
|
2017-10-23 09:45:58 +02:00
|
|
|
for (int j=0; j < path.CountNodes(); ++j)
|
|
|
|
{
|
|
|
|
const quint32 id = TakeNextId(children);
|
|
|
|
QVector<quint32> nodeChildren = {id};
|
|
|
|
UpdatePathNode(initData.data, path.at(j), nodeChildren, dx, dy, pRotate, angle);
|
|
|
|
}
|
2017-01-18 09:17:18 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void UpdateUnitedDetailCSA(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
|
2017-01-18 09:17:18 +01:00
|
|
|
qreal angle, const QVector<CustomSARecord> &records)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
2017-01-18 09:17:18 +01:00
|
|
|
QVector<quint32> idRecords;
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto record : records)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
idRecords.append(record.path);
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
2017-09-18 10:37:23 +02:00
|
|
|
UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, idRecords, GetCSAChildren(initData.doc, initData.id));
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void UpdateUnitedDetailInternalPaths(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy,
|
2017-01-18 09:17:18 +01:00
|
|
|
quint32 pRotate, qreal angle, const QVector<quint32> &records)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, records,
|
|
|
|
GetInternalPathsChildren(initData.doc, initData.id));
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
|
|
|
|
2017-02-01 12:31:14 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void UpdateUnitedDetailPins(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle,
|
|
|
|
const QVector<quint32> &records)
|
2017-02-01 12:31:14 +01:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
QVector<quint32> children = GetPinChildren(initData.doc, initData.id);
|
2017-02-01 12:31:14 +01:00
|
|
|
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto record : records)
|
2017-02-01 12:31:14 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
QScopedPointer<VPointF> point(new VPointF(*initData.data->GeometricObject<VPointF>(record)));
|
2017-02-01 12:31:14 +01:00
|
|
|
point->setMode(Draw::Modeling);
|
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
BiasRotatePoint(point.data(), dx, dy,
|
|
|
|
static_cast<QPointF>(*initData.data->GeometricObject<VPointF>(pRotate)), angle);
|
2017-02-01 12:31:14 +01:00
|
|
|
}
|
|
|
|
initData.data->UpdateGObject(TakeNextId(children), point.take());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void UpdateUnitedDetailPlaceLabels(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
|
|
|
|
qreal angle, const QVector<quint32> &records)
|
|
|
|
{
|
|
|
|
QVector<quint32> children = GetPlaceLabelChildren(initData.doc, initData.id);
|
|
|
|
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto record : records)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
QSharedPointer<VPlaceLabelItem> parentLabel = initData.data->GeometricObject<VPlaceLabelItem>(record);
|
2017-10-15 11:25:20 +02:00
|
|
|
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
|
|
|
|
{
|
2017-10-23 09:45:58 +02:00
|
|
|
BiasRotatePoint(parentLabel.data(), dx, dy,
|
2017-10-15 11:25:20 +02:00
|
|
|
static_cast<QPointF>(*initData.data->GeometricObject<VPointF>(pRotate)), angle);
|
|
|
|
}
|
2017-10-23 09:45:58 +02:00
|
|
|
QScopedPointer<VPlaceLabelItem> label(new VPlaceLabelItem());
|
|
|
|
label->setName(parentLabel->name());
|
|
|
|
label->setX(parentLabel->x());
|
|
|
|
label->setY(parentLabel->y());
|
|
|
|
label->setMx(parentLabel->mx());
|
|
|
|
label->setMy(parentLabel->my());
|
|
|
|
|
|
|
|
label->SetCorrectionAngle(parentLabel->GetCorrectionAngle()+angle);
|
2017-10-15 11:25:20 +02:00
|
|
|
initData.data->UpdateGObject(TakeNextId(children), label.take());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void CreateUnitedDetail(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
|
|
|
const QString drawName = DrawName(initData.doc, initData.d1id, initData.d2id);
|
|
|
|
SCASSERT(not drawName.isEmpty())
|
|
|
|
|
|
|
|
const VPiece d1 = initData.data->GetPiece(initData.d1id);
|
|
|
|
const VPiece d2 = initData.data->GetPiece(initData.d2id);
|
|
|
|
|
|
|
|
VPiece newDetail;
|
|
|
|
|
2017-09-18 10:37:23 +02:00
|
|
|
CreateUnitedNodes(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle);
|
|
|
|
CreateUnitedCSA(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle);
|
|
|
|
CreateUnitedInternalPaths(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle);
|
|
|
|
CreateUnitedPins(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle);
|
2017-10-15 11:25:20 +02:00
|
|
|
CreateUnitedPlaceLabels(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle);
|
2017-01-16 16:37:15 +01:00
|
|
|
|
|
|
|
newDetail.SetName(QObject::tr("United detail"));
|
2017-01-21 14:24:40 +01:00
|
|
|
QString formulaSAWidth = d1.GetFormulaSAWidth();
|
|
|
|
newDetail.SetFormulaSAWidth(formulaSAWidth, d1.GetSAWidth());
|
2017-01-16 16:37:15 +01:00
|
|
|
newDetail.SetMx(d1.GetMx());
|
|
|
|
newDetail.SetMy(d1.GetMy());
|
2017-01-22 14:21:08 +01:00
|
|
|
newDetail.SetUnited(true);
|
2017-09-18 10:37:23 +02:00
|
|
|
|
|
|
|
VToolSeamAllowanceInitData pieceInitData;
|
|
|
|
pieceInitData.detail = newDetail;
|
|
|
|
pieceInitData.width = formulaSAWidth;
|
|
|
|
pieceInitData.scene = initData.scene;
|
|
|
|
pieceInitData.doc = initData.doc;
|
|
|
|
pieceInitData.data = initData.data;
|
|
|
|
pieceInitData.parse = initData.parse;
|
|
|
|
pieceInitData.typeCreation = Source::FromTool;
|
|
|
|
pieceInitData.drawName = drawName;
|
|
|
|
|
2019-01-22 18:04:24 +01:00
|
|
|
VToolSeamAllowance *piece = VToolSeamAllowance::Create(pieceInitData);
|
|
|
|
if (piece != nullptr)
|
|
|
|
{
|
|
|
|
piece->RefreshGeometry(true); // Refresh internal paths
|
|
|
|
}
|
2017-01-16 16:37:15 +01:00
|
|
|
|
2017-10-26 16:22:12 +02:00
|
|
|
auto DuplicateDetail = [initData](quint32 id)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
2017-10-26 16:22:12 +02:00
|
|
|
VToolSeamAllowanceInitData initPieceData;
|
|
|
|
initPieceData.scene = initData.scene;
|
|
|
|
initPieceData.doc = initData.doc;
|
|
|
|
initPieceData.parse = Document::FullParse;
|
|
|
|
initPieceData.typeCreation = Source::FromGui;
|
|
|
|
initPieceData.drawName = initData.doc->PieceDrawName(id);
|
|
|
|
|
|
|
|
VContainer toolData = VAbstractPattern::getTool(id)->getData();
|
|
|
|
initPieceData.data = &toolData;
|
|
|
|
|
|
|
|
initPieceData.detail = initData.data->GetPiece(id);
|
|
|
|
initPieceData.width = initPieceData.detail.GetFormulaSAWidth();
|
2019-02-03 14:58:35 +01:00
|
|
|
if (VToolSeamAllowance *duplicate = VToolSeamAllowance::Duplicate(initPieceData))
|
2019-01-22 18:04:24 +01:00
|
|
|
{
|
2019-02-03 14:58:35 +01:00
|
|
|
duplicate->RefreshGeometry(true); // Refresh internal paths
|
2019-01-22 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2017-01-16 16:37:15 +01:00
|
|
|
};
|
|
|
|
|
2017-10-26 16:22:12 +02:00
|
|
|
if (initData.retainPieces)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
2017-10-26 16:22:12 +02:00
|
|
|
DuplicateDetail(initData.d1id);
|
|
|
|
DuplicateDetail(initData.d2id);
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
2017-10-26 16:22:12 +02:00
|
|
|
|
|
|
|
auto RemoveDetail = [](quint32 id)
|
|
|
|
{
|
|
|
|
VToolSeamAllowance *toolDet = qobject_cast<VToolSeamAllowance*>(VAbstractPattern::getTool(id));
|
|
|
|
SCASSERT(toolDet != nullptr);
|
|
|
|
toolDet->RemoveWithConfirm(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
RemoveDetail(initData.d1id);
|
|
|
|
RemoveDetail(initData.d2id);
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void UpdateUnitedDetail(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle)
|
2017-01-16 16:37:15 +01:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
UpdateUnitedNodes(initData, dx, dy, pRotate, angle);
|
|
|
|
UpdateUnitedDetailCSA(initData, dx, dy, pRotate, angle, GetPiece2CSAPaths(initData.doc, initData.id));
|
|
|
|
UpdateUnitedDetailInternalPaths(initData, dx, dy, pRotate, angle,
|
|
|
|
GetPiece2InternalPaths(initData.doc, initData.id));
|
|
|
|
UpdateUnitedDetailPins(initData, dx, dy, pRotate, angle, GetPiece2Pins(initData.doc, initData.id));
|
2017-10-23 09:45:58 +02:00
|
|
|
UpdateUnitedDetailPlaceLabels(initData, dx, dy, pRotate, angle, GetPiece2PlaceLabels(initData.doc, initData.id));
|
2017-01-16 16:37:15 +01:00
|
|
|
}
|
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
void UniteDetails(const VToolUnionDetailsInitData &initData)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
|
|
|
VPieceNode det1p1;
|
|
|
|
qreal dx = 0;
|
|
|
|
qreal dy = 0;
|
|
|
|
qreal angle = 0;
|
2016-03-04 17:08:29 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
if (initData.typeCreation == Source::FromGui)
|
|
|
|
{
|
2017-01-18 09:17:18 +01:00
|
|
|
const VPiece d1 = initData.data->GetPiece(initData.d1id);
|
|
|
|
const VPiece d2 = initData.data->GetPiece(initData.d2id);
|
|
|
|
UnionInitParameters(initData, d1.GetPath(), d2.GetPath(), det1p1, dx, dy, angle);
|
2017-09-18 10:37:23 +02:00
|
|
|
CreateUnitedDetail(initData, dx, dy, det1p1.GetId(), angle);
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-11 14:08:55 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
const VPiecePath d1Path = GetPiece1MainPath(initData.doc, initData.id);
|
|
|
|
const VPiecePath d2Path = GetPiece2MainPath(initData.doc, initData.id);
|
|
|
|
UnionInitParameters(initData, d1Path, d2Path, det1p1, dx, dy, angle);
|
|
|
|
UpdateUnitedDetail(initData, dx, dy, det1p1.GetId(), angle);
|
|
|
|
}
|
|
|
|
catch (const VExceptionBadId &)
|
|
|
|
{
|
|
|
|
// There is a chance that the tool depends on an already deleted object. We can skip updating in this case.
|
|
|
|
// We still can get error in child in case we should not get an error here. Debug will be a little bit
|
|
|
|
// obscured. But if this happened something really bad happened.
|
|
|
|
}
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
} // static functions
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
2017-01-16 11:08:13 +01:00
|
|
|
* @brief VToolUnionDetails costructor.
|
|
|
|
* @param initData global init data.
|
|
|
|
* @param parent parent object.
|
2014-06-13 19:02:41 +02:00
|
|
|
*/
|
2017-09-18 10:37:23 +02:00
|
|
|
VToolUnionDetails::VToolUnionDetails(const VToolUnionDetailsInitData &initData, QObject *parent)
|
|
|
|
: VAbstractTool(initData.doc, initData.data, initData.id, parent),
|
2017-01-16 11:08:13 +01:00
|
|
|
d1id(initData.d1id),
|
|
|
|
d2id(initData.d2id),
|
|
|
|
indexD1(initData.indexD1),
|
2017-10-23 09:45:58 +02:00
|
|
|
indexD2(initData.indexD2),
|
|
|
|
version(initData.version)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
ToolCreation(initData.typeCreation);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-08-30 21:58:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VToolUnionDetails::getTagName() const
|
|
|
|
{
|
2016-05-16 19:59:04 +02:00
|
|
|
return VAbstractPattern::TagTools;
|
2014-08-30 21:58:31 +02:00
|
|
|
}
|
|
|
|
|
2014-09-03 15:52:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolUnionDetails::ShowVisualization(bool show)
|
|
|
|
{
|
2014-09-11 18:52:02 +02:00
|
|
|
Q_UNUSED(show)
|
2014-09-03 15:52:16 +02:00
|
|
|
}
|
|
|
|
|
2015-12-26 18:10:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolUnionDetails::incrementReferens()
|
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
VDataTool::incrementReferens();
|
2015-12-26 18:10:02 +01:00
|
|
|
if (_referens == 1)
|
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
const QVector<quint32> objects = GetReferenceObjects();
|
2018-04-02 19:38:56 +02:00
|
|
|
for(auto object : objects)
|
2015-12-26 18:10:02 +01:00
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
doc->IncrementReferens(object);
|
2015-12-26 18:10:02 +01:00
|
|
|
}
|
|
|
|
|
2017-09-17 08:45:18 +02:00
|
|
|
QDomElement domElement = doc->elementById(m_id, getTagName());
|
2015-12-26 18:10:02 +01:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::InUse);
|
2016-01-07 17:43:08 +01:00
|
|
|
}
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-03-04 13:55:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-16 11:08:13 +01:00
|
|
|
void VToolUnionDetails::decrementReferens()
|
2014-03-06 14:28:46 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
VDataTool::decrementReferens();
|
|
|
|
if (_referens == 0)
|
2014-03-06 14:28:46 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
const QVector<quint32> objects = GetReferenceObjects();
|
2018-04-02 19:38:56 +02:00
|
|
|
for(auto object : objects)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
doc->DecrementReferens(object);
|
2014-03-06 14:28:46 +01:00
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
|
2017-09-17 08:45:18 +02:00
|
|
|
QDomElement domElement = doc->elementById(m_id, getTagName());
|
2017-01-16 11:08:13 +01:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
|
|
|
doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::NotInUse);
|
2014-03-06 14:28:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolUnionDetails::GroupVisibility(quint32 object, bool visible)
|
|
|
|
{
|
|
|
|
Q_UNUSED(object)
|
|
|
|
Q_UNUSED(visible)
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
2017-01-16 11:08:13 +01:00
|
|
|
* @brief Create help create tool from GUI.
|
|
|
|
* @param dialog dialog.
|
2014-06-13 19:02:41 +02:00
|
|
|
* @param doc dom document container.
|
2017-01-16 11:08:13 +01:00
|
|
|
* @param data container with variables.
|
|
|
|
*/
|
2018-07-24 13:57:41 +02:00
|
|
|
VToolUnionDetails* VToolUnionDetails::Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene,
|
2017-04-15 16:39:59 +02:00
|
|
|
VAbstractPattern *doc, VContainer *data)
|
2017-01-16 11:08:13 +01:00
|
|
|
{
|
2017-04-15 16:39:59 +02:00
|
|
|
SCASSERT(not dialog.isNull())
|
2018-07-24 13:57:41 +02:00
|
|
|
const QPointer<DialogUnionDetails> dialogTool = qobject_cast<DialogUnionDetails *>(dialog);
|
2017-04-15 16:39:59 +02:00
|
|
|
SCASSERT(not dialogTool.isNull())
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
VToolUnionDetailsInitData initData;
|
|
|
|
initData.d1id = dialogTool->getD1();
|
|
|
|
initData.d2id = dialogTool->getD2();
|
|
|
|
initData.indexD1 = static_cast<quint32>(dialogTool->getIndexD1());
|
|
|
|
initData.indexD2 = static_cast<quint32>(dialogTool->getIndexD2());
|
|
|
|
initData.scene = scene;
|
|
|
|
initData.doc = doc;
|
|
|
|
initData.data = data;
|
|
|
|
initData.parse = Document::FullParse;
|
|
|
|
initData.typeCreation = Source::FromGui;
|
|
|
|
initData.retainPieces = dialogTool->RetainPieces();
|
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractApplication::VApp()->getUndoStack()->beginMacro(tr("union details"));
|
2017-09-18 10:37:23 +02:00
|
|
|
VToolUnionDetails* tool = Create(initData);
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractApplication::VApp()->getUndoStack()->endMacro();
|
2017-01-16 11:08:13 +01:00
|
|
|
return tool;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief Create help create tool.
|
2017-01-27 13:07:12 +01:00
|
|
|
* @param initData contains all init data.
|
2014-06-13 19:02:41 +02:00
|
|
|
*/
|
2017-09-18 10:37:23 +02:00
|
|
|
VToolUnionDetails* VToolUnionDetails::Create(VToolUnionDetailsInitData initData)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
VToolUnionDetails *unionDetails = nullptr;
|
|
|
|
if (initData.typeCreation == Source::FromGui)
|
|
|
|
{
|
2018-09-18 15:38:16 +02:00
|
|
|
initData.id = initData.data->getNextId();
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
|
|
|
else
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
if (initData.parse != Document::FullParse)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.doc->UpdateToolData(initData.id, initData.data);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
//First add tool to file
|
|
|
|
if (initData.parse == Document::FullParse)
|
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
VAbstractTool::AddRecord(initData.id, Tool::UnionDetails, initData.doc);
|
2017-01-16 11:08:13 +01:00
|
|
|
//Scene doesn't show this tool, so doc will destroy this object.
|
2017-09-18 10:37:23 +02:00
|
|
|
unionDetails = new VToolUnionDetails(initData);
|
|
|
|
VAbstractPattern::AddTool(initData.id, unionDetails);
|
2017-01-16 11:08:13 +01:00
|
|
|
// Unfortunatelly doc will destroy all objects only in the end, but we should delete them before each FullParse
|
|
|
|
initData.doc->AddToolOnRemove(unionDetails);
|
|
|
|
}
|
2017-09-18 10:37:23 +02:00
|
|
|
UniteDetails(initData);
|
2017-01-16 11:08:13 +01:00
|
|
|
return unionDetails;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief AddToFile add tag with informations about tool into file.
|
|
|
|
*/
|
2013-12-29 17:48:57 +01:00
|
|
|
void VToolUnionDetails::AddToFile()
|
|
|
|
{
|
2016-05-16 19:59:04 +02:00
|
|
|
QDomElement domElement = doc->createElement(getTagName());
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2017-09-17 08:45:18 +02:00
|
|
|
doc->SetAttribute(domElement, VDomDocument::AttrId, m_id);
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrType, ToolType);
|
|
|
|
doc->SetAttribute(domElement, AttrIndexD1, indexD1);
|
|
|
|
doc->SetAttribute(domElement, AttrIndexD2, indexD2);
|
2017-10-23 09:45:58 +02:00
|
|
|
doc->SetAttribute(domElement, AttrVersion, unionVersion);
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
AddDetail(domElement, data.GetPiece(d1id));
|
|
|
|
AddDetail(domElement, data.GetPiece(d2id));
|
2013-12-29 17:48:57 +01:00
|
|
|
|
|
|
|
AddToModeling(domElement);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief AddDetail add detail to xml file.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @param d detail.
|
|
|
|
*/
|
2017-01-16 11:08:13 +01:00
|
|
|
void VToolUnionDetails::AddDetail(QDomElement &domElement, const VPiece &d) const
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
|
|
|
QDomElement det = doc->createElement(TagDetail);
|
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
// nodes
|
|
|
|
VToolSeamAllowance::AddNodes(doc, det, d);
|
|
|
|
//custom seam allowance
|
|
|
|
VToolSeamAllowance::AddCSARecords(doc, det, d.GetCustomSARecords());
|
|
|
|
VToolSeamAllowance::AddInternalPaths(doc, det, d.GetInternalPaths());
|
2017-01-31 17:09:18 +01:00
|
|
|
VToolSeamAllowance::AddPins(doc, det, d.GetPins());
|
2017-10-23 09:45:58 +02:00
|
|
|
VToolSeamAllowance::AddPlaceLabels(doc, det, d.GetPlaceLabels());
|
2013-12-29 17:48:57 +01:00
|
|
|
|
|
|
|
domElement.appendChild(det);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief AddToModeling add tool to xml tree.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
*/
|
2013-12-29 17:48:57 +01:00
|
|
|
void VToolUnionDetails::AddToModeling(const QDomElement &domElement)
|
|
|
|
{
|
2018-11-28 11:00:40 +01:00
|
|
|
const QDomElement duplicate = doc->elementById(m_id);
|
|
|
|
if (not duplicate.isNull())
|
|
|
|
{
|
|
|
|
throw VExceptionWrongId(tr("This id (%1) is not unique.").arg(m_id), duplicate);
|
|
|
|
}
|
|
|
|
|
2017-01-16 11:08:13 +01:00
|
|
|
const QString drawName = DrawName(doc, d1id, d2id);
|
|
|
|
SCASSERT(not drawName.isEmpty())
|
|
|
|
|
2016-01-07 17:43:08 +01:00
|
|
|
QDomElement modeling = doc->GetDraw(drawName).firstChildElement(VAbstractPattern::TagModeling);
|
|
|
|
if (not modeling.isNull())
|
|
|
|
{
|
|
|
|
modeling.appendChild(domElement);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
qCCritical(vToolUnion, "Can't find tag %s.", qUtf8Printable(VAbstractPattern::TagModeling));
|
2016-01-07 17:43:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 18:49:16 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-16 11:08:13 +01:00
|
|
|
QVector<quint32> VToolUnionDetails::GetReferenceObjects() const
|
2016-03-08 18:49:16 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
QVector<quint32> list;
|
2017-09-17 08:45:18 +02:00
|
|
|
const QDomElement tool = doc->elementById(m_id, getTagName());
|
2017-01-16 11:08:13 +01:00
|
|
|
if (tool.isNull())
|
2016-03-08 18:49:16 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
return list;
|
2016-03-08 18:49:16 +01:00
|
|
|
}
|
|
|
|
|
2017-10-23 09:45:58 +02:00
|
|
|
const QStringList parts = QStringList() << VAbstractPattern::TagNodes /*0*/
|
|
|
|
<< VToolSeamAllowance::TagCSA /*1*/
|
|
|
|
<< VToolSeamAllowance::TagIPaths /*2*/
|
|
|
|
<< VToolSeamAllowance::TagPins /*3*/
|
|
|
|
<< VToolSeamAllowance::TagPlaceLabels; /*4*/
|
2017-01-16 11:08:13 +01:00
|
|
|
|
|
|
|
const QDomNodeList nodesList = tool.childNodes();
|
|
|
|
for (qint32 i = 0; i < nodesList.size(); ++i)
|
2016-03-08 18:49:16 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
const QDomElement element = nodesList.at(i).toElement();
|
|
|
|
if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail)
|
2016-03-08 18:49:16 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
const QDomNodeList detList = element.childNodes();
|
|
|
|
for (qint32 j = 0; j < detList.size(); ++j)
|
2016-03-08 18:49:16 +01:00
|
|
|
{
|
2017-01-16 11:08:13 +01:00
|
|
|
const QDomElement element = detList.at(j).toElement();
|
|
|
|
if (not element.isNull())
|
|
|
|
{
|
|
|
|
switch (parts.indexOf(element.tagName()))
|
|
|
|
{
|
|
|
|
case 0://VAbstractPattern::TagNodes
|
2017-01-18 09:17:18 +01:00
|
|
|
list += ReferenceObjects(element, TagNode, AttrIdObject);
|
2017-01-16 11:08:13 +01:00
|
|
|
break;
|
|
|
|
case 1://VToolSeamAllowance::TagCSA
|
|
|
|
case 2://VToolSeamAllowance::TagIPaths
|
2017-01-18 09:17:18 +01:00
|
|
|
list += ReferenceObjects(element, VToolSeamAllowance::TagRecord,
|
|
|
|
VAbstractPattern::AttrPath);
|
2017-01-16 11:08:13 +01:00
|
|
|
break;
|
2017-07-26 12:56:19 +02:00
|
|
|
case 3://VToolSeamAllowance::TagPins
|
2017-10-23 09:45:58 +02:00
|
|
|
case 4://VToolSeamAllowance::TagPlaceLabels
|
2017-07-26 12:56:19 +02:00
|
|
|
{
|
|
|
|
const QDomNodeList children = element.childNodes();
|
2019-02-03 14:58:35 +01:00
|
|
|
for (qint32 index = 0; index < children.size(); ++index)
|
2017-07-26 12:56:19 +02:00
|
|
|
{
|
2019-02-03 14:58:35 +01:00
|
|
|
const QDomElement record = children.at(index).toElement();
|
2017-07-26 12:56:19 +02:00
|
|
|
if (not record.isNull() && record.tagName() == VToolSeamAllowance::TagRecord)
|
|
|
|
{
|
|
|
|
list.append(record.text().toUInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-08 18:49:16 +01:00
|
|
|
}
|
2016-01-07 17:43:08 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-16 11:08:13 +01:00
|
|
|
return list;
|
2016-01-07 17:43:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-18 09:17:18 +01:00
|
|
|
QVector<quint32> VToolUnionDetails::ReferenceObjects(const QDomElement &root, const QString &tag,
|
|
|
|
const QString &attribute) const
|
2016-01-07 17:43:08 +01:00
|
|
|
{
|
2017-01-18 09:17:18 +01:00
|
|
|
QVector<quint32> objects;
|
2016-01-07 17:43:08 +01:00
|
|
|
|
2017-01-18 09:17:18 +01:00
|
|
|
const QDomNodeList list = root.childNodes();
|
|
|
|
for (qint32 i = 0; i < list.size(); ++i)
|
2016-01-07 17:43:08 +01:00
|
|
|
{
|
2017-01-18 09:17:18 +01:00
|
|
|
const QDomElement element = list.at(i).toElement();
|
|
|
|
if (not element.isNull() && element.tagName() == tag)
|
2016-01-07 17:43:08 +01:00
|
|
|
{
|
2017-01-18 09:17:18 +01:00
|
|
|
const quint32 id = doc->GetParametrUInt(element, attribute, NULL_ID_STR);
|
2017-01-16 11:08:13 +01:00
|
|
|
if (id > NULL_ID)
|
|
|
|
{
|
2017-01-18 09:17:18 +01:00
|
|
|
objects.append(id);
|
2017-01-16 11:08:13 +01:00
|
|
|
}
|
2016-01-07 17:43:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-18 09:17:18 +01:00
|
|
|
return objects;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2017-09-11 14:56:18 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPair<bool, VPieceNode> > VToolUnionDetails::CalcUnitedPath(const VPiecePath &d1Path, const VPiecePath &d2Path,
|
|
|
|
quint32 indexD2, quint32 pRotate)
|
|
|
|
{
|
|
|
|
QVector<QPair<bool, VPieceNode> > path;
|
|
|
|
|
|
|
|
const qint32 countNodeD1 = d1Path.CountNodes();
|
|
|
|
const qint32 countNodeD2 = d2Path.CountNodes();
|
|
|
|
|
|
|
|
qint32 pointsD2 = 0; //Keeps number points the second detail, that we have already added.
|
|
|
|
qint32 i = 0;
|
|
|
|
const int det1P1Index = d1Path.indexOfNode(pRotate);
|
2018-04-07 12:36:56 +02:00
|
|
|
bool checkUniqueness = false;
|
2017-09-11 14:56:18 +02:00
|
|
|
do
|
|
|
|
{
|
2018-04-07 12:36:56 +02:00
|
|
|
VPieceNode node = d1Path.at(i);
|
|
|
|
if (checkUniqueness)
|
|
|
|
{
|
|
|
|
// See issue #835. Union Tool - changes in workpiece tool can't be saved because of double points
|
|
|
|
node.SetCheckUniqueness(false);
|
|
|
|
checkUniqueness = false;
|
|
|
|
}
|
|
|
|
path.append(qMakePair(true, node));
|
2017-09-11 14:56:18 +02:00
|
|
|
++i;
|
|
|
|
if (i > det1P1Index && pointsD2 < countNodeD2-1)
|
|
|
|
{
|
|
|
|
qint32 j = 0;
|
|
|
|
FindIndexJ(pointsD2, d2Path, indexD2, j);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (j >= countNodeD2)
|
|
|
|
{
|
|
|
|
j=0;
|
|
|
|
}
|
|
|
|
path.append(qMakePair(false, d2Path.at(j)));
|
|
|
|
++pointsD2;
|
|
|
|
++j;
|
|
|
|
} while (pointsD2 < countNodeD2-1);
|
2018-04-07 12:36:56 +02:00
|
|
|
checkUniqueness = true;
|
2017-09-11 14:56:18 +02:00
|
|
|
}
|
|
|
|
} while (i < countNodeD1);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|