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
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** 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"
|
|
|
|
#include "nodeDetails/nodedetails.h"
|
|
|
|
#include "vtooldetail.h"
|
2014-06-08 20:10:57 +02:00
|
|
|
#include "../geometry/vpointf.h"
|
|
|
|
#include "../geometry/varc.h"
|
|
|
|
#include "../geometry/vsplinepath.h"
|
|
|
|
#include "../dialogs/tools/dialoguniondetails.h"
|
2014-06-15 19:07:54 +02:00
|
|
|
#include "../undocommands/adduniondetails.h"
|
2013-12-29 17:48:57 +01:00
|
|
|
|
|
|
|
const QString VToolUnionDetails::TagName = QStringLiteral("tools");
|
|
|
|
const QString VToolUnionDetails::ToolType = QStringLiteral("unionDetails");
|
|
|
|
const QString VToolUnionDetails::TagDetail = QStringLiteral("det");
|
|
|
|
const QString VToolUnionDetails::TagNode = QStringLiteral("node");
|
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");
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief VToolUnionDetails costructor.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data dom document container.
|
|
|
|
* @param id object id in container.
|
|
|
|
* @param d1 first detail.
|
|
|
|
* @param d2 second detail.
|
|
|
|
* @param indexD1 index edge in first detail.
|
|
|
|
* @param indexD2 index edge in second detail.
|
|
|
|
* @param typeCreation way we create this tool.
|
|
|
|
* @param parent parent object.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
VToolUnionDetails::VToolUnionDetails(VPattern *doc, VContainer *data, const quint32 &id, const VDetail &d1,
|
|
|
|
const VDetail &d2, const quint32 &indexD1, const quint32 &indexD2,
|
2014-06-12 09:22:29 +02:00
|
|
|
const Source &typeCreation, QObject *parent)
|
2014-01-02 18:16:16 +01:00
|
|
|
:VAbstractTool(doc, data, id, parent), d1(d1), d2(d2), indexD1(indexD1), indexD2(indexD2)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
|
|
|
AddToFile();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RefreshDataInFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief AddToNewDetail create united detail adding one node per time.
|
|
|
|
* @param tool tool that make union.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
* @param newDetail united detail.
|
|
|
|
* @param det detail what we union.
|
|
|
|
* @param i index node in detail.
|
|
|
|
* @param idTool id tool union details.
|
|
|
|
* @param dx bias node x axis.
|
|
|
|
* @param dy bias node y axis.
|
|
|
|
* @param pRotate point rotation.
|
|
|
|
* @param angle angle rotation.
|
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
void VToolUnionDetails::AddToNewDetail(QObject *tool, VPattern *doc, VContainer *data, VDetail &newDetail,
|
2014-10-05 22:25:07 +02:00
|
|
|
const VDetail &det, const int &i, const quint32 &idTool, const qreal &dx,
|
2014-02-25 15:40:24 +01:00
|
|
|
const qreal &dy, const quint32 &pRotate, const qreal &angle)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 id = 0, idObject = 0;
|
2014-01-02 16:50:01 +01:00
|
|
|
switch (det.at(i).getTypeTool())
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodePoint):
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
if ( qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && (pRotate == 0))
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
id = det.at(i).getId();
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
else
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
VPointF *point = new VPointF(*data->GeometricObject<VPointF>(det.at(i).getId()));
|
2014-06-12 09:22:29 +02:00
|
|
|
point->setMode(Draw::Modeling);
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(point, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
|
2014-01-02 16:50:01 +01:00
|
|
|
angle);
|
|
|
|
idObject = data->AddGObject(point);
|
|
|
|
VPointF *point1 = new VPointF(*point);
|
2014-06-12 09:22:29 +02:00
|
|
|
point1->setMode(Draw::Modeling);
|
2014-01-02 16:50:01 +01:00
|
|
|
id = data->AddGObject(point1);
|
2014-06-12 09:22:29 +02:00
|
|
|
VNodePoint::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeArc):
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
|
|
|
if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
id = det.at(i).getId();
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
else
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(det.at(i).getId());
|
2014-07-25 13:53:39 +02:00
|
|
|
VPointF p1 = VPointF(arc->GetP1(), "A", 0, 0);
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(&p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-07-25 13:53:39 +02:00
|
|
|
VPointF p2 = VPointF(arc->GetP2(), "A", 0, 0);
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF *center = new VPointF(arc->GetCenter());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(center, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
|
2014-01-02 16:50:01 +01:00
|
|
|
angle);
|
|
|
|
|
|
|
|
QLineF l1(center->toQPointF(), p1.toQPointF());
|
|
|
|
QLineF l2(center->toQPointF(), p2.toQPointF());
|
2014-06-12 09:22:29 +02:00
|
|
|
center->setMode(Draw::Modeling);
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 idCenter = data->AddGObject(center);
|
2014-01-02 16:50:01 +01:00
|
|
|
Q_UNUSED(idCenter);
|
|
|
|
VArc *arc1 = new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(),
|
|
|
|
l1.angle(), QString().setNum(l1.angle()), l2.angle(),
|
|
|
|
QString().setNum(l2.angle()));
|
2014-06-12 09:22:29 +02:00
|
|
|
arc1->setMode(Draw::Modeling);
|
2014-01-11 11:11:42 +01:00
|
|
|
idObject = data->AddGObject(arc1);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
|
|
|
VArc *arc2 = new VArc(*arc1);
|
2014-06-12 09:22:29 +02:00
|
|
|
arc2->setMode(Draw::Modeling);
|
2014-01-11 11:11:42 +01:00
|
|
|
id = data->AddGObject(arc2);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-06-12 09:22:29 +02:00
|
|
|
VNodeArc::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSpline):
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
id = det.at(i).getId();
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
else
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VSpline> spline = data->GeometricObject<VSpline>(det.at(i).getId());
|
2014-01-02 16:50:01 +01:00
|
|
|
|
|
|
|
VPointF *p1 = new VPointF(spline->GetP1());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-06-02 09:43:27 +02:00
|
|
|
//quint32 idP1 = data->AddGObject(p1);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-01-12 20:23:44 +01:00
|
|
|
VPointF p2 = VPointF(spline->GetP2());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-01-12 20:23:44 +01:00
|
|
|
VPointF p3 = VPointF(spline->GetP3());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(&p3, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
|
|
|
VPointF *p4 = new VPointF(spline->GetP4());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(p4, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-06-02 09:43:27 +02:00
|
|
|
//quint32 idP4 = data->AddGObject(p4);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-01-12 20:23:44 +01:00
|
|
|
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0,
|
2014-06-12 09:22:29 +02:00
|
|
|
Draw::Modeling);
|
2014-01-07 11:04:29 +01:00
|
|
|
idObject = data->AddGObject(spl);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
|
|
|
VSpline *spl1 = new VSpline(*spl);
|
2014-06-12 09:22:29 +02:00
|
|
|
spl1->setMode(Draw::Modeling);
|
2014-01-07 11:04:29 +01:00
|
|
|
id = data->AddGObject(spl1);
|
2014-06-12 09:22:29 +02:00
|
|
|
VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
|
2014-09-13 22:42:58 +02:00
|
|
|
|
|
|
|
delete p4;
|
|
|
|
delete p1;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSplinePath):
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
|
|
|
if (qFuzzyCompare(dx+1, 1) && qFuzzyCompare(dy+1, 1) && pRotate == 0)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
id = det.at(i).getId();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VSplinePath *path = new VSplinePath();
|
2014-06-12 09:22:29 +02:00
|
|
|
path->setMode(Draw::Modeling);
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(det.at(i).getId());
|
2014-01-08 21:23:08 +01:00
|
|
|
qint32 k = splinePath->getMaxCountPoints();
|
2014-01-02 16:50:01 +01:00
|
|
|
for (qint32 i = 1; i <= splinePath->Count(); ++i)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
VSpline spline(splinePath->at(i-1).P(), splinePath->at(i).P(),
|
|
|
|
splinePath->at(i-1).Angle2(), splinePath->at(i).Angle1(), splinePath->at(i-1).KAsm2(),
|
|
|
|
splinePath->at(i).KAsm1(), splinePath->getKCurve());
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF *p1 = new VPointF(spline.GetP1());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
|
2014-01-02 16:50:01 +01:00
|
|
|
angle);
|
2014-06-02 09:43:27 +02:00
|
|
|
//quint32 idP1 = data->AddGObject(p1);
|
2014-01-08 21:23:08 +01:00
|
|
|
--k;
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF p2 = VPointF(spline.GetP2());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
|
2014-01-02 16:50:01 +01:00
|
|
|
angle);
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF p3 = VPointF(spline.GetP3());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(&p3, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
|
2014-01-02 16:50:01 +01:00
|
|
|
angle);
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF *p4 = new VPointF(spline.GetP4());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(p4, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
|
2014-01-02 16:50:01 +01:00
|
|
|
angle);
|
2014-06-02 09:43:27 +02:00
|
|
|
//quint32 idP4 = data->AddGObject(p4);
|
2014-01-08 21:23:08 +01:00
|
|
|
--k;
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline.GetKcurve());
|
|
|
|
if (i==1)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-02-14 16:16:43 +01:00
|
|
|
path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1()+180,
|
|
|
|
splinePath->at(i-1).KAsm2(), spl.GetAngle1()));
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-09-13 22:42:58 +02:00
|
|
|
path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2(),
|
|
|
|
splinePath->at(i).KAsm2(), spl.GetAngle2()+180));
|
|
|
|
delete p4;
|
|
|
|
delete p1;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-27 17:01:24 +01:00
|
|
|
while (k>=0)
|
2014-01-08 21:23:08 +01:00
|
|
|
{
|
|
|
|
data->getNextId();
|
|
|
|
--k;
|
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
idObject = data->AddGObject(path);
|
|
|
|
|
|
|
|
VSplinePath *path1 = new VSplinePath(*path);
|
2014-06-12 09:22:29 +02:00
|
|
|
path1->setMode(Draw::Modeling);
|
2014-01-02 16:50:01 +01:00
|
|
|
id = data->AddGObject(path1);
|
2014-06-12 09:22:29 +02:00
|
|
|
VNodeSplinePath::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
break;
|
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
2014-01-02 16:50:01 +01:00
|
|
|
break;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
newDetail.append(VNodeDetail(id, det.at(i).getTypeTool(), NodeDetail::Contour));
|
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 UpdatePoints update data for united details.
|
|
|
|
* @param idDetail id united detail.
|
|
|
|
* @param data container with variables.
|
|
|
|
* @param det detail what we union.
|
|
|
|
* @param i index node in detail.
|
|
|
|
* @param idCount count updated or created objects.
|
|
|
|
* @param dx bias node x axis.
|
|
|
|
* @param dy bias node y axis.
|
|
|
|
* @param pRotate point rotation.
|
|
|
|
* @param angle angle rotation.
|
|
|
|
*/
|
2014-10-05 22:25:07 +02:00
|
|
|
void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data, const VDetail &det, const int &i,
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 &idCount, const qreal &dx, const qreal &dy, const quint32 &pRotate,
|
2014-01-02 16:50:01 +01:00
|
|
|
const qreal &angle)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
switch (det.at(i).getTypeTool())
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodePoint):
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-11 11:11:42 +01:00
|
|
|
if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
VPointF *point = new VPointF(*data->GeometricObject<VPointF>(det.at(i).getId()));
|
2014-06-12 09:22:29 +02:00
|
|
|
point->setMode(Draw::Modeling);
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(point, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-01-02 16:50:01 +01:00
|
|
|
++idCount;
|
|
|
|
data->UpdateGObject(idDetail+idCount, point);
|
|
|
|
|
|
|
|
++idCount;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeArc):
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-01-11 11:11:42 +01:00
|
|
|
if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(det.at(i).getId());
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF p1 = VPointF(arc->GetP1());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(&p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF p2 = VPointF(arc->GetP2());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF *center = new VPointF(arc->GetCenter());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(center, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
|
2014-01-02 16:50:01 +01:00
|
|
|
angle);
|
|
|
|
|
|
|
|
QLineF l1(center->toQPointF(), p1.toQPointF());
|
|
|
|
QLineF l2(center->toQPointF(), p2.toQPointF());
|
2014-01-07 11:04:29 +01:00
|
|
|
++idCount;
|
2014-06-12 09:22:29 +02:00
|
|
|
center->setMode(Draw::Modeling);
|
2014-01-07 11:04:29 +01:00
|
|
|
data->UpdateGObject(idDetail+idCount, center);
|
2014-01-02 16:50:01 +01:00
|
|
|
VArc *arc1 = new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(), l1.angle(),
|
|
|
|
QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle()));
|
2014-06-12 09:22:29 +02:00
|
|
|
arc1->setMode(Draw::Modeling);
|
2014-01-02 16:50:01 +01:00
|
|
|
++idCount;
|
|
|
|
data->UpdateGObject(idDetail+idCount, arc1);
|
|
|
|
|
|
|
|
++idCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSpline):
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-01-11 11:11:42 +01:00
|
|
|
if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VSpline> spline = data->GeometricObject<VSpline>(det.at(i).getId());
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF *p1 = new VPointF(spline->GetP1());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-01-07 11:04:29 +01:00
|
|
|
++idCount;
|
|
|
|
data->UpdateGObject(idDetail+idCount, p1);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
|
|
|
VPointF p2 = VPointF(spline->GetP2());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
|
|
|
VPointF p3 = VPointF(spline->GetP3());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(&p3, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
|
|
|
VPointF *p4 = new VPointF(spline->GetP4());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(p4, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
|
2014-01-07 11:04:29 +01:00
|
|
|
++idCount;
|
|
|
|
data->UpdateGObject(idDetail+idCount, p4);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-01-12 20:23:44 +01:00
|
|
|
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0,
|
2014-06-12 09:22:29 +02:00
|
|
|
Draw::Modeling);
|
2014-01-12 20:23:44 +01:00
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
++idCount;
|
|
|
|
data->UpdateGObject(idDetail+idCount, spl);
|
|
|
|
|
|
|
|
++idCount;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSplinePath):
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-01-11 11:11:42 +01:00
|
|
|
if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
VSplinePath *path = new VSplinePath();
|
2014-06-12 09:22:29 +02:00
|
|
|
path->setMode(Draw::Modeling);
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(det.at(i).getId());
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(splinePath != nullptr);
|
2014-01-08 21:23:08 +01:00
|
|
|
qint32 k = splinePath->getMaxCountPoints();
|
2014-01-02 16:50:01 +01:00
|
|
|
for (qint32 i = 1; i <= splinePath->Count(); ++i)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
VSpline spline(splinePath->at(i-1).P(), splinePath->at(i).P(),
|
|
|
|
splinePath->at(i-1).Angle2(), splinePath->at(i).Angle1(), splinePath->at(i-1).KAsm2(),
|
|
|
|
splinePath->at(i).KAsm1(), splinePath->getKCurve());
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF *p1 = new VPointF(spline.GetP1());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
|
2014-01-02 16:50:01 +01:00
|
|
|
angle);
|
2014-01-07 11:04:29 +01:00
|
|
|
++idCount;
|
|
|
|
data->UpdateGObject(idDetail+idCount, p1);
|
2014-01-08 21:23:08 +01:00
|
|
|
--k;
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF p2 = VPointF(spline.GetP2());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
|
2014-01-02 16:50:01 +01:00
|
|
|
angle);
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF p3 = VPointF(spline.GetP3());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(&p3, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
|
2014-01-02 16:50:01 +01:00
|
|
|
angle);
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
VPointF *p4 = new VPointF(spline.GetP4());
|
2014-08-21 14:44:40 +02:00
|
|
|
BiasRotatePoint(p4, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
|
2014-01-02 16:50:01 +01:00
|
|
|
angle);
|
2014-01-07 11:04:29 +01:00
|
|
|
++idCount;
|
|
|
|
data->UpdateGObject(idDetail+idCount, p4);
|
2014-01-08 21:23:08 +01:00
|
|
|
--k;
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline.GetKcurve());
|
|
|
|
if (i==1)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-02-14 16:16:43 +01:00
|
|
|
path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1()+180,
|
|
|
|
splinePath->at(i-1).KAsm2(), spl.GetAngle1()));
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-09-13 22:42:58 +02:00
|
|
|
path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2(),
|
|
|
|
splinePath->at(i).KAsm2(), spl.GetAngle2()+180));
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2014-01-27 17:01:24 +01:00
|
|
|
while (k>=0)
|
2014-01-08 21:23:08 +01:00
|
|
|
{
|
|
|
|
data->getNextId();
|
|
|
|
--k;
|
|
|
|
++idCount;
|
|
|
|
}
|
|
|
|
|
2014-01-02 16:50:01 +01:00
|
|
|
++idCount;
|
|
|
|
data->UpdateGObject(idDetail+idCount, path);
|
|
|
|
|
|
|
|
++idCount;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
break;
|
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
2014-01-02 16:50:01 +01:00
|
|
|
break;
|
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 BiasRotatePoint bias and rotate point.
|
|
|
|
* @param point point.
|
|
|
|
* @param dx bias x axis.
|
|
|
|
* @param dy bias y axis.
|
|
|
|
* @param pRotate point rotation.
|
|
|
|
* @param angle angle rotation.
|
|
|
|
*/
|
2013-12-29 17:48:57 +01:00
|
|
|
void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate,
|
2014-06-16 14:14:46 +02:00
|
|
|
const qreal &angle)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
|
|
|
point->setX(point->x()+dx);
|
|
|
|
point->setY(point->y()+dy);
|
2013-12-31 09:44:54 +01:00
|
|
|
QLineF line(pRotate, point->toQPointF());
|
2014-01-02 16:50:01 +01:00
|
|
|
line.setAngle(line.angle()+angle);
|
2013-12-31 09:44:54 +01:00
|
|
|
point->setX(line.p2().x());
|
|
|
|
point->setY(line.p2().y());
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-08-30 21:58:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VToolUnionDetails::getTagName() const
|
|
|
|
{
|
|
|
|
return VToolUnionDetails::TagName;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief Create help create tool from GUI.
|
|
|
|
* @param dialog dialog.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
*/
|
2014-08-30 21:58:31 +02:00
|
|
|
VToolUnionDetails* VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc,
|
|
|
|
VContainer *data)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogUnionDetails *dialogTool = qobject_cast<DialogUnionDetails*>(dialog);
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
VDetail d1 = data->GetDetail(dialogTool->getD1());
|
|
|
|
VDetail d2 = data->GetDetail(dialogTool->getD2());
|
2014-06-02 09:43:27 +02:00
|
|
|
quint32 indexD1 = static_cast<quint32>(dialogTool->getIndexD1());
|
|
|
|
quint32 indexD2 = static_cast<quint32>(dialogTool->getIndexD2());
|
2014-06-15 19:07:54 +02:00
|
|
|
qApp->getUndoStack()->beginMacro("union details");
|
2014-08-30 21:58:31 +02:00
|
|
|
VToolUnionDetails* tool = nullptr;
|
|
|
|
tool = Create(0, d1, d2, dialogTool->getD1(), dialogTool->getD2(), indexD1, indexD2, scene, doc, data,
|
|
|
|
Document::FullParse, Source::FromGui);
|
2014-06-16 14:14:46 +02:00
|
|
|
qApp->getUndoStack()->endMacro();
|
2014-08-30 21:58:31 +02:00
|
|
|
return tool;
|
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 Create help create tool.
|
|
|
|
* @param _id tool id, 0 if tool doesn't exist yet.
|
|
|
|
* @param d1 first detail.
|
|
|
|
* @param d2 second detail.
|
|
|
|
* @param d1id id first detail.
|
|
|
|
* @param d2id id second detail.
|
|
|
|
* @param indexD1 index edge in first detail.
|
|
|
|
* @param indexD2 index edge in second detail.
|
|
|
|
* @param scene pointer to scene.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
* @param typeCreation way we create this tool.
|
|
|
|
*/
|
2014-08-30 21:58:31 +02:00
|
|
|
VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDetail &d2,
|
|
|
|
const quint32 &d1id, const quint32 &d2id, const quint32 &indexD1,
|
|
|
|
const quint32 &indexD2, VMainGraphicsScene *scene, VPattern *doc,
|
|
|
|
VContainer *data, const Document &parse, const Source &typeCreation)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-02 18:16:16 +01:00
|
|
|
VToolUnionDetails *unionDetails = 0;
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 id = _id;
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
|
|
|
id = data->getNextId();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (parse != Document::FullParse)
|
|
|
|
{
|
|
|
|
doc->UpdateToolData(id, data);
|
|
|
|
}
|
|
|
|
}
|
2014-06-12 09:22:29 +02:00
|
|
|
VAbstractTool::AddRecord(id, Tool::UnionDetails, doc);
|
2013-12-29 17:48:57 +01:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
2014-01-02 18:16:16 +01:00
|
|
|
//Scene doesn't show this tool, so doc will destroy this object.
|
|
|
|
unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation, doc);
|
2014-02-25 15:40:24 +01:00
|
|
|
QHash<quint32, VDataTool*>* tools = doc->getTools();
|
2013-12-29 17:48:57 +01:00
|
|
|
tools->insert(id, unionDetails);
|
2014-10-05 22:25:07 +02:00
|
|
|
for (int i = 0; i < d1.CountNode(); ++i)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
|
|
|
doc->IncrementReferens(d1.at(i).getId());
|
|
|
|
}
|
2014-10-05 22:25:07 +02:00
|
|
|
for (int i = 0; i < d2.CountNode(); ++i)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
|
|
|
doc->IncrementReferens(d2.at(i).getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-03-04 13:55:57 +01:00
|
|
|
VNodeDetail det1p1;
|
|
|
|
VNodeDetail det1p2;
|
|
|
|
d1.NodeOnEdge(indexD1, det1p1, det1p2);
|
|
|
|
Q_UNUSED(det1p2);
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-03-04 13:55:57 +01:00
|
|
|
VPointF point1;
|
|
|
|
VPointF point2;
|
|
|
|
PointsOnEdge(d1, indexD1, point1, point2, data);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-03-04 13:55:57 +01:00
|
|
|
VPointF point3;
|
|
|
|
VPointF point4;
|
|
|
|
PointsOnEdge(d2, indexD2, point3, point4, data);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-03-04 13:55:57 +01:00
|
|
|
const qreal dx = point1.x() - point4.x();
|
|
|
|
const qreal dy = point1.y() - point4.y();
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-03-04 13:55:57 +01:00
|
|
|
point3.setX(point3.x()+dx);
|
|
|
|
point3.setY(point3.y()+dy);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-03-04 13:55:57 +01:00
|
|
|
point4.setX(point4.x()+dx);
|
|
|
|
point4.setY(point4.y()+dy);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-03-04 13:55:57 +01:00
|
|
|
const qreal angle = QLineF(point4.toQPointF(), point3.toQPointF()).angleTo(QLineF(point1.toQPointF(),
|
|
|
|
point2.toQPointF()));
|
|
|
|
qint32 pointsD2 = 0; //Keeps count points second detail, what we already add.
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui)
|
2014-03-06 16:35:24 +01:00
|
|
|
{
|
2014-03-04 13:55:57 +01:00
|
|
|
qint32 j = 0, i = 0;
|
|
|
|
VDetail newDetail;
|
2014-01-07 11:04:29 +01:00
|
|
|
do
|
|
|
|
{
|
2014-03-04 13:55:57 +01:00
|
|
|
AddToNewDetail(unionDetails, doc, data, newDetail, d1.RemoveEdge(indexD1), i, id);
|
2014-01-07 11:04:29 +01:00
|
|
|
++i;
|
2014-03-04 13:55:57 +01:00
|
|
|
if (i > d1.indexOfNode(det1p1.getId()) && pointsD2 < d2.RemoveEdge(indexD2).CountNode()-2)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
do
|
|
|
|
{
|
2014-03-06 14:28:46 +01:00
|
|
|
FindJ(pointsD2, d2, indexD2, j);
|
2014-03-04 13:55:57 +01:00
|
|
|
if (pointsD2 == d2.RemoveEdge(indexD2).CountNode() -2)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2014-03-04 13:55:57 +01:00
|
|
|
if (j >= d2.RemoveEdge(indexD2).CountNode())
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
|
|
|
j=0;
|
|
|
|
}
|
2014-03-04 13:55:57 +01:00
|
|
|
AddToNewDetail(unionDetails, doc, data, newDetail, d2.RemoveEdge(indexD2), j, id, dx, dy,
|
|
|
|
det1p1.getId(), angle);
|
2014-01-02 16:50:01 +01:00
|
|
|
++pointsD2;
|
|
|
|
++j;
|
2014-03-04 13:55:57 +01:00
|
|
|
} while (pointsD2 < d2.RemoveEdge(indexD2).CountNode());
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
2014-05-01 13:33:40 +02:00
|
|
|
} while (i < d1.RemoveEdge(indexD1).CountNode());
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2013-12-30 19:59:33 +01:00
|
|
|
newDetail.setName("Detail");
|
2014-06-15 19:07:54 +02:00
|
|
|
newDetail.setWidth(d1.getWidth());
|
2014-06-12 09:22:29 +02:00
|
|
|
VToolDetail::Create(0, newDetail, scene, doc, data, parse, Source::FromTool);
|
2014-02-25 15:40:24 +01:00
|
|
|
QHash<quint32, VDataTool*>* tools = doc->getTools();
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(tools != nullptr);
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-03-04 13:55:57 +01:00
|
|
|
{
|
|
|
|
VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(d1id));
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(toolDet != nullptr);
|
2014-06-15 19:07:54 +02:00
|
|
|
bool ask = false;
|
|
|
|
toolDet->Remove(ask);
|
2014-03-04 13:55:57 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
|
2014-03-04 13:55:57 +01:00
|
|
|
VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(d2id));
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(toolDet != nullptr);
|
2014-06-15 19:07:54 +02:00
|
|
|
bool ask = false;
|
|
|
|
toolDet->Remove(ask);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 idCount = 0;
|
2014-01-02 16:50:01 +01:00
|
|
|
qint32 j = 0, i = 0;
|
2014-01-07 11:04:29 +01:00
|
|
|
do
|
|
|
|
{
|
2014-03-04 13:55:57 +01:00
|
|
|
UpdatePoints(id, data, d1.RemoveEdge(indexD1), i, idCount);
|
2014-01-07 11:04:29 +01:00
|
|
|
++i;
|
2014-03-04 13:55:57 +01:00
|
|
|
if (i > d1.indexOfNode(det1p1.getId()) && pointsD2 < d2.RemoveEdge(indexD2).CountNode()-2)
|
2014-01-07 11:04:29 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
do
|
|
|
|
{
|
2014-03-06 14:28:46 +01:00
|
|
|
FindJ(pointsD2, d2, indexD2, j);
|
2014-03-04 13:55:57 +01:00
|
|
|
if (pointsD2 == d2.RemoveEdge(indexD2).CountNode()-2)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2014-03-04 13:55:57 +01:00
|
|
|
if (j >= d2.RemoveEdge(indexD2).CountNode())
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
|
|
|
j=0;
|
|
|
|
}
|
2014-03-04 13:55:57 +01:00
|
|
|
UpdatePoints(id, data, d2.RemoveEdge(indexD2), j, idCount, dx, dy, det1p1.getId(), angle);
|
2014-01-02 16:50:01 +01:00
|
|
|
++pointsD2;
|
|
|
|
++j;
|
2014-03-04 13:55:57 +01:00
|
|
|
} while (pointsD2 < d2.RemoveEdge(indexD2).CountNode());
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
2014-03-04 13:55:57 +01:00
|
|
|
} while (i<d1.RemoveEdge(indexD1).CountNode());
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-08-30 21:58:31 +02:00
|
|
|
return nullptr;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 09:43:27 +02:00
|
|
|
void VToolUnionDetails::PointsOnEdge(const VDetail &d, const quint32 &index, VPointF &p1, VPointF &p2, VContainer *data)
|
2014-03-04 13:55:57 +01:00
|
|
|
{
|
|
|
|
VNodeDetail det2p1;
|
|
|
|
VNodeDetail det2p2;
|
|
|
|
d.NodeOnEdge(index, det2p1, det2p2);
|
2014-08-21 14:44:40 +02:00
|
|
|
p1 = VPointF(*data->GeometricObject<VPointF>(det2p1.getId()));
|
|
|
|
p2 = VPointF(*data->GeometricObject<VPointF>(det2p2.getId()));
|
2014-03-04 13:55:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 09:43:27 +02:00
|
|
|
void VToolUnionDetails::FindJ(const qint32 &pointsD2, const VDetail &d2, const quint32 &indexD2, qint32 &j)
|
2014-03-06 14:28:46 +01:00
|
|
|
{
|
|
|
|
if (pointsD2 == 0)
|
|
|
|
{
|
|
|
|
VNodeDetail node1;
|
|
|
|
VNodeDetail node2;
|
|
|
|
d2.NodeOnEdge(indexD2, node1, node2);
|
2014-10-05 22:25:07 +02:00
|
|
|
int k = d2.RemoveEdge(indexD2).indexOfNode(node2.getId());
|
2014-03-06 14:28:46 +01:00
|
|
|
if (k == d2.RemoveEdge(indexD2).CountNode()-1)
|
|
|
|
{
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
j = d2.RemoveEdge(indexD2).indexOfNode(node2.getId())+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief GetDetailFromFile parse detail from file.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @return detail stored in file.
|
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
QVector<VDetail> VToolUnionDetails::GetDetailFromFile(VPattern *doc, const QDomElement &domElement)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
|
|
|
QVector<VDetail> vector;
|
|
|
|
QDomNodeList detailList = domElement.childNodes();
|
|
|
|
qint32 num = detailList.size();
|
|
|
|
for (qint32 i = 0; i < num; ++i)
|
|
|
|
{
|
|
|
|
QDomElement element = detailList.at(i).toElement();
|
|
|
|
if (element.isNull() == false)
|
|
|
|
{
|
|
|
|
if (element.tagName() == VToolUnionDetails::TagDetail)
|
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
VDetail d;
|
|
|
|
QDomNodeList nodeList = element.childNodes();
|
2013-12-29 17:48:57 +01:00
|
|
|
qint32 num = nodeList.size();
|
|
|
|
for (qint32 j = 0; j < num; ++j)
|
|
|
|
{
|
|
|
|
QDomElement element = nodeList.at(j).toElement();
|
|
|
|
if (element.isNull() == false)
|
|
|
|
{
|
|
|
|
if (element.tagName() == VToolUnionDetails::TagNode)
|
|
|
|
{
|
2014-10-29 12:06:50 +01:00
|
|
|
quint32 id = doc->GetParametrUInt(element, VToolDetail::AttrIdObject, NULL_ID_STR);
|
2014-03-19 19:27:11 +01:00
|
|
|
qreal mx = qApp->toPixel(doc->GetParametrDouble(element, VAbstractTool::AttrMx, "0.0"));
|
|
|
|
qreal my = qApp->toPixel(doc->GetParametrDouble(element, VAbstractTool::AttrMy, "0.0"));
|
2014-06-17 11:50:11 +02:00
|
|
|
Tool tool = Tool::NodePoint;
|
2014-06-12 09:22:29 +02:00
|
|
|
NodeDetail nodeType = NodeDetail::Contour;
|
2013-12-29 17:48:57 +01:00
|
|
|
QString t = doc->GetParametrString(element, "type", "NodePoint");
|
|
|
|
if (t == "NodePoint")
|
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
tool = Tool::NodePoint;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
else if (t == "NodeArc")
|
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
tool = Tool::NodeArc;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
else if (t == "NodeSpline")
|
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
tool = Tool::NodeSpline;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
else if (t == "NodeSplinePath")
|
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
tool = Tool::NodeSplinePath;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
d.append(VNodeDetail(id, tool, nodeType, mx, my));
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
vector.append(d);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return vector;
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
QDomElement domElement = doc->createElement(TagName);
|
|
|
|
|
2014-03-21 11:08:29 +01:00
|
|
|
doc->SetAttribute(domElement, VDomDocument::AttrId, id);
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrType, ToolType);
|
|
|
|
doc->SetAttribute(domElement, AttrIndexD1, indexD1);
|
|
|
|
doc->SetAttribute(domElement, AttrIndexD2, indexD2);
|
2013-12-29 17:48:57 +01:00
|
|
|
|
|
|
|
AddDetail(domElement, d1);
|
|
|
|
AddDetail(domElement, d2);
|
|
|
|
|
|
|
|
AddToModeling(domElement);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
|
|
|
|
*/
|
2013-12-29 17:48:57 +01:00
|
|
|
void VToolUnionDetails::RefreshDataInFile()
|
|
|
|
{
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrIndexD1, indexD1);
|
|
|
|
doc->SetAttribute(domElement, AttrIndexD2, indexD2);
|
2013-12-29 17:48:57 +01:00
|
|
|
|
|
|
|
QDomNode domNode = domElement.firstChild();
|
|
|
|
domNode = UpdateDetail(domNode, d1);
|
|
|
|
UpdateDetail(domNode, d2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-30 21:58:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolUnionDetails::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
|
|
|
|
{
|
2014-09-11 18:52:02 +02:00
|
|
|
Q_UNUSED(tag)
|
|
|
|
Q_UNUSED(obj)
|
2014-08-30 21:58:31 +02:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2013-12-29 17:48:57 +01:00
|
|
|
void VToolUnionDetails::AddDetail(QDomElement &domElement, VDetail &d)
|
|
|
|
{
|
|
|
|
QDomElement det = doc->createElement(TagDetail);
|
|
|
|
|
2014-10-05 22:25:07 +02:00
|
|
|
for (int i = 0; i < d.CountNode(); ++i)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
AddNode(det, d.at(i));
|
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 AddNode add node to xml file.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @param node node.
|
|
|
|
*/
|
2014-01-02 16:50:01 +01:00
|
|
|
void VToolUnionDetails::AddNode(QDomElement &domElement, const VNodeDetail &node)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-06-25 14:23:01 +02:00
|
|
|
//Right now method similar to method in class VToolDetail.
|
|
|
|
VToolDetail::AddNode(doc, domElement, node);
|
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 UpdateDetail update detail in xml tree.
|
|
|
|
* @param domNode dom node.
|
|
|
|
* @param d detail.
|
|
|
|
* @return return next detail tag in xml tree if exist.
|
|
|
|
*/
|
2014-01-02 16:50:01 +01:00
|
|
|
QDomNode VToolUnionDetails::UpdateDetail(const QDomNode &domNode, const VDetail &d)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
|
|
|
//QDomNode domNode = domElement.firstChild();
|
|
|
|
while (domNode.isNull() == false)
|
|
|
|
{
|
|
|
|
if (domNode.isElement())
|
|
|
|
{
|
|
|
|
QDomElement domElement = domNode.toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
if (domElement.tagName() == VToolUnionDetails::TagDetail)
|
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
doc->removeAllChilds(domElement);//delete all nodes in detail
|
2014-10-05 22:25:07 +02:00
|
|
|
for (int i = 0; i < d.CountNode(); ++i)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-01-02 16:50:01 +01:00
|
|
|
AddNode(domElement, d.at(i));//rewrite nodes of detail
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2014-01-02 16:50:01 +01:00
|
|
|
break;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return domNode.nextSibling();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2014-06-15 19:07:54 +02:00
|
|
|
AddUnionDetails *addUnion = new AddUnionDetails(domElement, doc);
|
|
|
|
connect(addUnion, &AddUnionDetails::NeedFullParsing, doc, &VPattern::NeedFullParsing);
|
|
|
|
qApp->getUndoStack()->push(addUnion);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|