2015-05-27 12:48:21 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vtoolpointofintersectionarcs.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 25 5, 2015
|
|
|
|
**
|
|
|
|
** @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) 2015 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 "vtoolpointofintersectionarcs.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QLineF>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <new>
|
|
|
|
|
2015-06-19 16:17:31 +02:00
|
|
|
#include "../../../../dialogs/tools/dialogpointofintersectionarcs.h"
|
2016-03-24 15:49:15 +01:00
|
|
|
#include "../../../../visualization/line/vistoolpointofintersectionarcs.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/exception/vexception.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vgeometry/varc.h"
|
|
|
|
#include "../vgeometry/vgobject.h"
|
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vpatterndb/vcontainer.h"
|
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../../../dialogs/tools/dialogtool.h"
|
|
|
|
#include "../../../../visualization/visualization.h"
|
|
|
|
#include "../../../vabstracttool.h"
|
|
|
|
#include "../../vdrawtool.h"
|
|
|
|
#include "vtoolsinglepoint.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
template <class T> class QSharedPointer;
|
2015-05-27 12:48:21 +02:00
|
|
|
|
|
|
|
const QString VToolPointOfIntersectionArcs::ToolType = QStringLiteral("pointOfIntersectionArcs");
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-06-18 19:23:24 +02:00
|
|
|
VToolPointOfIntersectionArcs::VToolPointOfIntersectionArcs(VAbstractPattern *doc, VContainer *data, const quint32 &id,
|
2015-05-27 12:48:21 +02:00
|
|
|
const quint32 &firstArcId, const quint32 &secondArcId,
|
2015-05-30 12:02:20 +02:00
|
|
|
CrossCirclesPoint pType, const Source &typeCreation,
|
2015-05-27 12:48:21 +02:00
|
|
|
QGraphicsItem *parent)
|
2015-06-20 08:23:04 +02:00
|
|
|
:VToolSinglePoint(doc, data, id, parent), firstArcId(firstArcId), secondArcId(secondArcId), crossPoint(pType)
|
2015-05-27 12:48:21 +02:00
|
|
|
{
|
2015-05-28 12:16:59 +02:00
|
|
|
ToolCreation(typeCreation);
|
2015-05-27 12:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointOfIntersectionArcs::setDialog()
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(dialog != nullptr)
|
2015-05-27 12:48:21 +02:00
|
|
|
DialogPointOfIntersectionArcs *dialogTool = qobject_cast<DialogPointOfIntersectionArcs*>(dialog);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(dialogTool != nullptr)
|
2015-05-27 12:48:21 +02:00
|
|
|
const QSharedPointer<VPointF> p = VAbstractTool::data.GeometricObject<VPointF>(id);
|
|
|
|
dialogTool->SetFirstArcId(firstArcId);
|
|
|
|
dialogTool->SetSecondArcId(secondArcId);
|
|
|
|
dialogTool->SetCrossArcPoint(crossPoint);
|
|
|
|
dialogTool->SetPointName(p->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(DialogTool *dialog, VMainGraphicsScene *scene,
|
2015-06-18 19:23:24 +02:00
|
|
|
VAbstractPattern *doc, VContainer *data)
|
2015-05-27 12:48:21 +02:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(dialog != nullptr)
|
2015-05-27 12:48:21 +02:00
|
|
|
DialogPointOfIntersectionArcs *dialogTool = qobject_cast<DialogPointOfIntersectionArcs*>(dialog);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(dialogTool != nullptr)
|
2015-05-27 12:48:21 +02:00
|
|
|
const quint32 firstArcId = dialogTool->GetFirstArcId();
|
|
|
|
const quint32 secondArcId = dialogTool->GetSecondArcId();
|
2015-05-30 12:02:20 +02:00
|
|
|
const CrossCirclesPoint pType = dialogTool->GetCrossArcPoint();
|
2015-05-27 12:48:21 +02:00
|
|
|
const QString pointName = dialogTool->getPointName();
|
2015-11-02 17:25:29 +01:00
|
|
|
VToolPointOfIntersectionArcs *point = Create(0, pointName, firstArcId, secondArcId, pType, 5, 10, scene, doc,
|
|
|
|
data, Document::FullParse, Source::FromGui);
|
2015-05-27 12:48:21 +02:00
|
|
|
if (point != nullptr)
|
|
|
|
{
|
|
|
|
point->dialog=dialogTool;
|
|
|
|
}
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(const quint32 _id, const QString &pointName,
|
|
|
|
const quint32 &firstArcId,
|
2015-05-30 12:02:20 +02:00
|
|
|
const quint32 &secondArcId, CrossCirclesPoint pType,
|
2015-05-27 12:48:21 +02:00
|
|
|
const qreal &mx, const qreal &my,
|
2015-06-18 19:23:24 +02:00
|
|
|
VMainGraphicsScene *scene, VAbstractPattern *doc,
|
2015-05-27 12:48:21 +02:00
|
|
|
VContainer *data, const Document &parse,
|
|
|
|
const Source &typeCreation)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VArc> firstArc = data->GeometricObject<VArc>(firstArcId);
|
|
|
|
const QSharedPointer<VArc> secondArc = data->GeometricObject<VArc>(secondArcId);
|
|
|
|
|
|
|
|
const QPointF point = FindPoint(firstArc.data(), secondArc.data(), pType);
|
|
|
|
quint32 id = _id;
|
|
|
|
if (typeCreation == Source::FromGui)
|
|
|
|
{
|
|
|
|
id = data->AddGObject(new VPointF(point, pointName, mx, my));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data->UpdateGObject(id, new VPointF(point, pointName, mx, my));
|
|
|
|
if (parse != Document::FullParse)
|
|
|
|
{
|
|
|
|
doc->UpdateToolData(id, data);
|
|
|
|
}
|
|
|
|
}
|
2017-02-13 07:55:42 +01:00
|
|
|
|
2015-05-27 12:48:21 +02:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
2017-02-13 07:55:42 +01:00
|
|
|
VDrawTool::AddRecord(id, Tool::PointOfIntersectionArcs, doc);
|
2015-05-27 12:48:21 +02:00
|
|
|
VToolPointOfIntersectionArcs *point = new VToolPointOfIntersectionArcs(doc, data, id, firstArcId,
|
|
|
|
secondArcId, pType, typeCreation);
|
|
|
|
scene->addItem(point);
|
2016-03-31 16:01:41 +02:00
|
|
|
InitToolConnections(scene, point);
|
2015-05-27 12:48:21 +02:00
|
|
|
doc->AddTool(id, point);
|
2016-02-02 14:38:30 +01:00
|
|
|
doc->IncrementReferens(firstArc->getIdTool());
|
|
|
|
doc->IncrementReferens(secondArc->getIdTool());
|
2015-05-27 12:48:21 +02:00
|
|
|
return point;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-05-30 12:02:20 +02:00
|
|
|
QPointF VToolPointOfIntersectionArcs::FindPoint(const VArc *arc1, const VArc *arc2, const CrossCirclesPoint pType)
|
2015-05-27 12:48:21 +02:00
|
|
|
{
|
|
|
|
QPointF p1, p2;
|
2016-05-14 21:28:09 +02:00
|
|
|
const QPointF centerArc1 = arc1->GetCenter();
|
|
|
|
const QPointF centerArc2 = arc2->GetCenter();
|
2015-10-28 15:22:36 +01:00
|
|
|
const int res = VGObject::IntersectionCircles(centerArc1, arc1->GetRadius(), centerArc2, arc2->GetRadius(), p1, p2);
|
2015-05-27 12:48:21 +02:00
|
|
|
|
2015-10-28 15:22:36 +01:00
|
|
|
QLineF r1Arc1(centerArc1, p1);
|
2015-05-29 10:03:16 +02:00
|
|
|
r1Arc1.setLength(r1Arc1.length()+10);
|
|
|
|
|
2015-10-28 15:22:36 +01:00
|
|
|
QLineF r1Arc2(centerArc2, p1);
|
2015-05-29 10:03:16 +02:00
|
|
|
r1Arc2.setLength(r1Arc2.length()+10);
|
|
|
|
|
2015-10-28 15:22:36 +01:00
|
|
|
QLineF r2Arc1(centerArc1, p2);
|
2015-05-29 10:03:16 +02:00
|
|
|
r2Arc1.setLength(r2Arc1.length()+10);
|
|
|
|
|
2015-10-28 15:22:36 +01:00
|
|
|
QLineF r2Arc2(centerArc2, p2);
|
2015-05-29 10:03:16 +02:00
|
|
|
r2Arc2.setLength(r2Arc2.length()+10);
|
|
|
|
|
2015-05-27 12:48:21 +02:00
|
|
|
switch(res)
|
|
|
|
{
|
|
|
|
case 2:
|
2015-05-29 10:03:16 +02:00
|
|
|
{
|
|
|
|
int localRes = 0;
|
|
|
|
bool flagP1 = false;
|
|
|
|
|
|
|
|
if (arc1->IsIntersectLine(r1Arc1) && arc2->IsIntersectLine(r1Arc2))
|
2015-05-27 12:48:21 +02:00
|
|
|
{
|
2015-05-29 10:03:16 +02:00
|
|
|
++localRes;
|
|
|
|
flagP1 = true;
|
2015-05-27 12:48:21 +02:00
|
|
|
}
|
2015-05-29 10:03:16 +02:00
|
|
|
|
|
|
|
if (arc1->IsIntersectLine(r2Arc1) && arc2->IsIntersectLine(r2Arc2))
|
|
|
|
{
|
|
|
|
++localRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(localRes)
|
2015-05-27 12:48:21 +02:00
|
|
|
{
|
2015-05-29 10:03:16 +02:00
|
|
|
case 2:
|
2015-05-30 12:02:20 +02:00
|
|
|
if (pType == CrossCirclesPoint::FirstPoint)
|
2015-05-29 10:03:16 +02:00
|
|
|
{
|
|
|
|
return p1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return p2;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
if (flagP1)
|
|
|
|
{
|
|
|
|
return p1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return p2;
|
|
|
|
}
|
|
|
|
case 0:
|
|
|
|
default:
|
2017-02-22 18:27:53 +01:00
|
|
|
return QPointF();
|
2015-05-27 12:48:21 +02:00
|
|
|
}
|
2015-05-29 10:03:16 +02:00
|
|
|
|
2015-05-27 12:48:21 +02:00
|
|
|
break;
|
2015-05-29 10:03:16 +02:00
|
|
|
}
|
2015-05-27 12:48:21 +02:00
|
|
|
case 1:
|
2015-05-29 10:03:16 +02:00
|
|
|
if (arc1->IsIntersectLine(r1Arc1) && arc2->IsIntersectLine(r1Arc2))
|
|
|
|
{
|
|
|
|
return p1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-22 18:27:53 +01:00
|
|
|
return QPointF();
|
2015-05-29 10:03:16 +02:00
|
|
|
}
|
2015-05-27 12:48:21 +02:00
|
|
|
case 3:
|
|
|
|
case 0:
|
|
|
|
default:
|
2017-02-22 18:27:53 +01:00
|
|
|
return QPointF();
|
2015-05-27 12:48:21 +02:00
|
|
|
}
|
2017-02-22 18:40:50 +01:00
|
|
|
return QPointF();
|
2015-05-27 12:48:21 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 16:13:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VToolPointOfIntersectionArcs::FirstArcName() const
|
|
|
|
{
|
|
|
|
return VAbstractTool::data.GetGObject(firstArcId)->name();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VToolPointOfIntersectionArcs::SecondArcName() const
|
|
|
|
{
|
|
|
|
return VAbstractTool::data.GetGObject(secondArcId)->name();
|
|
|
|
}
|
|
|
|
|
2015-05-27 12:48:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 VToolPointOfIntersectionArcs::GetFirstArcId() const
|
|
|
|
{
|
|
|
|
return firstArcId;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointOfIntersectionArcs::SetFirstArcId(const quint32 &value)
|
|
|
|
{
|
|
|
|
if (value != NULL_ID)
|
|
|
|
{
|
|
|
|
firstArcId = value;
|
|
|
|
|
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
|
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 VToolPointOfIntersectionArcs::GetSecondArcId() const
|
|
|
|
{
|
|
|
|
return secondArcId;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointOfIntersectionArcs::SetSecondArcId(const quint32 &value)
|
|
|
|
{
|
|
|
|
if (value != NULL_ID)
|
|
|
|
{
|
|
|
|
secondArcId = value;
|
|
|
|
|
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
|
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-05-30 12:02:20 +02:00
|
|
|
CrossCirclesPoint VToolPointOfIntersectionArcs::GetCrossCirclesPoint() const
|
2015-05-27 12:48:21 +02:00
|
|
|
{
|
|
|
|
return crossPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-28 15:22:36 +01:00
|
|
|
void VToolPointOfIntersectionArcs::SetCrossCirclesPoint(const CrossCirclesPoint &value)
|
2015-05-27 12:48:21 +02:00
|
|
|
{
|
|
|
|
crossPoint = value;
|
|
|
|
|
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
|
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointOfIntersectionArcs::ShowVisualization(bool show)
|
|
|
|
{
|
|
|
|
ShowToolVisualization<VisToolPointOfIntersectionArcs>(show);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointOfIntersectionArcs::RemoveReferens()
|
|
|
|
{
|
2016-02-02 14:38:30 +01:00
|
|
|
const auto firstArc = VAbstractTool::data.GetGObject(firstArcId);
|
|
|
|
const auto secondArc = VAbstractTool::data.GetGObject(secondArcId);
|
|
|
|
|
|
|
|
doc->DecrementReferens(firstArc->getIdTool());
|
|
|
|
doc->DecrementReferens(secondArc->getIdTool());
|
2015-05-27 12:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointOfIntersectionArcs::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2015-11-02 17:25:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ContextMenu<DialogPointOfIntersectionArcs>(this, event);
|
|
|
|
}
|
|
|
|
catch(const VExceptionToolWasDeleted &e)
|
|
|
|
{
|
2016-12-20 20:19:21 +01:00
|
|
|
Q_UNUSED(e)
|
2015-11-02 17:25:29 +01:00
|
|
|
return;//Leave this method immediately!!!
|
|
|
|
}
|
2015-05-27 12:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointOfIntersectionArcs::SaveDialog(QDomElement &domElement)
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(dialog != nullptr)
|
2015-05-27 12:48:21 +02:00
|
|
|
DialogPointOfIntersectionArcs *dialogTool = qobject_cast<DialogPointOfIntersectionArcs*>(dialog);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(dialogTool != nullptr)
|
2015-05-27 12:48:21 +02:00
|
|
|
doc->SetAttribute(domElement, AttrName, dialogTool->getPointName());
|
|
|
|
doc->SetAttribute(domElement, AttrFirstArc, QString().setNum(dialogTool->GetFirstArcId()));
|
|
|
|
doc->SetAttribute(domElement, AttrSecondArc, QString().setNum(dialogTool->GetSecondArcId()));
|
|
|
|
doc->SetAttribute(domElement, AttrCrossPoint, QString().setNum(static_cast<int>(dialogTool->GetCrossArcPoint())));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointOfIntersectionArcs::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
|
|
|
|
{
|
2015-06-20 08:23:04 +02:00
|
|
|
VToolSinglePoint::SaveOptions(tag, obj);
|
2015-05-27 12:48:21 +02:00
|
|
|
|
|
|
|
doc->SetAttribute(tag, AttrType, ToolType);
|
|
|
|
doc->SetAttribute(tag, AttrFirstArc, firstArcId);
|
|
|
|
doc->SetAttribute(tag, AttrSecondArc, secondArcId);
|
|
|
|
doc->SetAttribute(tag, AttrCrossPoint, static_cast<int>(crossPoint));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointOfIntersectionArcs::ReadToolAttributes(const QDomElement &domElement)
|
|
|
|
{
|
|
|
|
firstArcId = doc->GetParametrUInt(domElement, AttrFirstArc, NULL_ID_STR);
|
|
|
|
secondArcId = doc->GetParametrUInt(domElement, AttrSecondArc, NULL_ID_STR);
|
2015-05-30 12:02:20 +02:00
|
|
|
crossPoint = static_cast<CrossCirclesPoint>(doc->GetParametrUInt(domElement, AttrCrossPoint, "1"));
|
2015-05-27 12:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointOfIntersectionArcs::SetVisualization()
|
|
|
|
{
|
2016-09-24 15:09:09 +02:00
|
|
|
if (not vis.isNull())
|
2015-05-27 12:48:21 +02:00
|
|
|
{
|
|
|
|
VisToolPointOfIntersectionArcs *visual = qobject_cast<VisToolPointOfIntersectionArcs *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(visual != nullptr)
|
2015-05-27 12:48:21 +02:00
|
|
|
|
|
|
|
visual->setArc1Id(firstArcId);
|
|
|
|
visual->setArc2Id(secondArcId);
|
|
|
|
visual->setCrossPoint(crossPoint);
|
|
|
|
visual->RefreshGeometry();
|
|
|
|
}
|
|
|
|
}
|