2015-06-05 15:43:41 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vtoolpointfromcircleandtangent.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 3 6, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-06-05 15:43:41 +02:00
|
|
|
** 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 "vtoolpointfromcircleandtangent.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <new>
|
|
|
|
|
2015-06-19 16:17:31 +02:00
|
|
|
#include "../../../../dialogs/tools/dialogpointfromcircleandtangent.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../../../dialogs/tools/dialogtool.h"
|
|
|
|
#include "../../../../visualization/visualization.h"
|
2016-03-24 15:49:15 +01:00
|
|
|
#include "../../../../visualization/line/vistoolpointfromcircleandtangent.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/exception/vexception.h"
|
|
|
|
#include "../ifc/xml/vdomdocument.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vgeometry/vgobject.h"
|
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vmisc/vabstractapplication.h"
|
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2015-06-19 16:17:31 +02:00
|
|
|
#include "../vpatterndb/vformula.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../../vabstracttool.h"
|
|
|
|
#include "../../vdrawtool.h"
|
|
|
|
#include "vtoolsinglepoint.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
template <class T> class QSharedPointer;
|
2015-06-05 15:43:41 +02:00
|
|
|
|
|
|
|
const QString VToolPointFromCircleAndTangent::ToolType = QStringLiteral("pointFromCircleAndTangent");
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
VToolPointFromCircleAndTangent::VToolPointFromCircleAndTangent(const VToolPointFromCircleAndTangentInitData &initData,
|
|
|
|
QGraphicsItem *parent)
|
|
|
|
:VToolSinglePoint(initData.doc, initData.data, initData.id, parent),
|
|
|
|
circleCenterId(initData.circleCenterId),
|
|
|
|
tangentPointId(initData.tangentPointId),
|
|
|
|
circleRadius(initData.circleRadius),
|
|
|
|
crossPoint(initData.crossPoint)
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
ToolCreation(initData.typeCreation);
|
2015-06-05 15:43:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::setDialog()
|
|
|
|
{
|
2017-04-15 16:39:59 +02:00
|
|
|
SCASSERT(not m_dialog.isNull())
|
|
|
|
QSharedPointer<DialogPointFromCircleAndTangent> dialogTool = m_dialog.objectCast<DialogPointFromCircleAndTangent>();
|
|
|
|
SCASSERT(not dialogTool.isNull())
|
2017-09-17 08:45:18 +02:00
|
|
|
const QSharedPointer<VPointF> p = VAbstractTool::data.GeometricObject<VPointF>(m_id);
|
2015-06-05 15:43:41 +02:00
|
|
|
dialogTool->SetCircleCenterId(circleCenterId);
|
|
|
|
dialogTool->SetCircleRadius(circleRadius);
|
|
|
|
dialogTool->SetCrossCirclesPoint(crossPoint);
|
2015-06-06 08:33:19 +02:00
|
|
|
dialogTool->SetTangentPointId(tangentPointId);
|
2015-06-05 15:43:41 +02:00
|
|
|
dialogTool->SetPointName(p->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-04-15 16:39:59 +02:00
|
|
|
VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(QSharedPointer<DialogTool> dialog,
|
|
|
|
VMainGraphicsScene *scene,
|
2015-06-18 19:23:24 +02:00
|
|
|
VAbstractPattern *doc, VContainer *data)
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
2017-04-15 16:39:59 +02:00
|
|
|
SCASSERT(not dialog.isNull())
|
|
|
|
QSharedPointer<DialogPointFromCircleAndTangent> dialogTool = dialog.objectCast<DialogPointFromCircleAndTangent>();
|
|
|
|
SCASSERT(not dialogTool.isNull())
|
2017-09-18 10:37:23 +02:00
|
|
|
|
|
|
|
VToolPointFromCircleAndTangentInitData initData;
|
|
|
|
initData.circleCenterId = dialogTool->GetCircleCenterId();
|
|
|
|
initData.circleRadius = dialogTool->GetCircleRadius();
|
|
|
|
initData.tangentPointId = dialogTool->GetTangentPointId();
|
|
|
|
initData.crossPoint = dialogTool->GetCrossCirclesPoint();
|
|
|
|
initData.name = dialogTool->getPointName();
|
|
|
|
initData.scene = scene;
|
|
|
|
initData.doc = doc;
|
|
|
|
initData.data = data;
|
|
|
|
initData.parse = Document::FullParse;
|
|
|
|
initData.typeCreation = Source::FromGui;
|
|
|
|
|
|
|
|
VToolPointFromCircleAndTangent *point = Create(initData);
|
2015-06-05 15:43:41 +02:00
|
|
|
if (point != nullptr)
|
|
|
|
{
|
2017-04-15 16:39:59 +02:00
|
|
|
point->m_dialog = dialogTool;
|
2015-06-05 15:43:41 +02:00
|
|
|
}
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-18 10:37:23 +02:00
|
|
|
VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(VToolPointFromCircleAndTangentInitData &initData)
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
const qreal radius = qApp->toPixel(CheckFormula(initData.id, initData.circleRadius, initData.data));
|
|
|
|
const VPointF cPoint = *initData.data->GeometricObject<VPointF>(initData.circleCenterId);
|
|
|
|
const VPointF tPoint = *initData.data->GeometricObject<VPointF>(initData.tangentPointId);
|
2015-06-05 15:43:41 +02:00
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
const QPointF point = VToolPointFromCircleAndTangent::FindPoint(static_cast<QPointF>(tPoint),
|
2017-09-18 10:37:23 +02:00
|
|
|
static_cast<QPointF>(cPoint), radius,
|
|
|
|
initData.crossPoint);
|
2017-09-17 18:52:18 +02:00
|
|
|
|
2017-09-18 10:37:23 +02:00
|
|
|
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
|
|
|
|
p->SetShowLabel(initData.showLabel);
|
2017-09-17 18:52:18 +02:00
|
|
|
|
2017-09-18 10:37:23 +02:00
|
|
|
if (initData.typeCreation == Source::FromGui)
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.id = initData.data->AddGObject(p);
|
2015-06-05 15:43:41 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.data->UpdateGObject(initData.id, p);
|
|
|
|
if (initData.parse != Document::FullParse)
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
initData.doc->UpdateToolData(initData.id, initData.data);
|
2015-06-05 15:43:41 +02:00
|
|
|
}
|
|
|
|
}
|
2017-02-13 07:55:42 +01:00
|
|
|
|
2017-09-18 10:37:23 +02:00
|
|
|
if (initData.parse == Document::FullParse)
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
2017-09-18 10:37:23 +02:00
|
|
|
VAbstractTool::AddRecord(initData.id, Tool::PointFromCircleAndTangent, initData.doc);
|
|
|
|
VToolPointFromCircleAndTangent *point = new VToolPointFromCircleAndTangent(initData);
|
|
|
|
initData.scene->addItem(point);
|
|
|
|
InitToolConnections(initData.scene, point);
|
|
|
|
VAbstractPattern::AddTool(initData.id, point);
|
|
|
|
initData.doc->IncrementReferens(cPoint.getIdTool());
|
|
|
|
initData.doc->IncrementReferens(tPoint.getIdTool());
|
2015-06-05 15:43:41 +02:00
|
|
|
return point;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPointF VToolPointFromCircleAndTangent::FindPoint(const QPointF &p, const QPointF ¢er, qreal radius,
|
|
|
|
const CrossCirclesPoint crossPoint)
|
|
|
|
{
|
|
|
|
QPointF p1, p2;
|
|
|
|
const int res = VGObject::ContactPoints (p, center, radius, p1, p2);
|
|
|
|
|
|
|
|
switch(res)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
if (crossPoint == CrossCirclesPoint::FirstPoint)
|
|
|
|
{
|
|
|
|
return p1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return p2;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
return p1;
|
|
|
|
case 3:
|
|
|
|
case 0:
|
|
|
|
default:
|
2017-02-22 18:27:53 +01:00
|
|
|
return QPointF();
|
2015-06-05 15:43:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 16:13:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VToolPointFromCircleAndTangent::TangentPointName() const
|
|
|
|
{
|
|
|
|
return VAbstractTool::data.GetGObject(tangentPointId)->name();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VToolPointFromCircleAndTangent::CircleCenterPointName() const
|
|
|
|
{
|
|
|
|
return VAbstractTool::data.GetGObject(circleCenterId)->name();
|
|
|
|
}
|
|
|
|
|
2015-06-05 15:43:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VFormula VToolPointFromCircleAndTangent::GetCircleRadius() const
|
|
|
|
{
|
|
|
|
VFormula radius(circleRadius, getData());
|
|
|
|
radius.setCheckZero(true);
|
2017-09-17 08:45:18 +02:00
|
|
|
radius.setToolId(m_id);
|
2017-07-02 13:34:36 +02:00
|
|
|
radius.setPostfix(UnitsToStr(qApp->patternUnit()));
|
2018-01-20 14:37:15 +01:00
|
|
|
radius.Eval();
|
2015-06-05 15:43:41 +02:00
|
|
|
return radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::SetCircleRadius(const VFormula &value)
|
|
|
|
{
|
|
|
|
if (value.error() == false)
|
|
|
|
{
|
|
|
|
if (value.getDoubleValue() > 0)// Formula don't check this, but radius can't be 0 or negative
|
|
|
|
{
|
|
|
|
circleRadius = value.GetFormula(FormulaType::FromUser);
|
2017-09-17 08:45:18 +02:00
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
|
2015-06-05 15:43:41 +02:00
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
CrossCirclesPoint VToolPointFromCircleAndTangent::GetCrossCirclesPoint() const
|
|
|
|
{
|
|
|
|
return crossPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-28 15:22:36 +01:00
|
|
|
void VToolPointFromCircleAndTangent::SetCrossCirclesPoint(const CrossCirclesPoint &value)
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
|
|
|
crossPoint = value;
|
|
|
|
|
2017-09-17 08:45:18 +02:00
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
|
2015-06-05 15:43:41 +02:00
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::ShowVisualization(bool show)
|
|
|
|
{
|
|
|
|
ShowToolVisualization<VisToolPointFromCircleAndTangent>(show);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-15 16:32:23 +02:00
|
|
|
void VToolPointFromCircleAndTangent::ShowContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 id)
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
2015-11-02 17:25:29 +01:00
|
|
|
try
|
|
|
|
{
|
2017-09-15 16:32:23 +02:00
|
|
|
ContextMenu<DialogPointFromCircleAndTangent>(event, id);
|
2015-11-02 17:25:29 +01:00
|
|
|
}
|
|
|
|
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-06-05 15:43:41 +02:00
|
|
|
}
|
|
|
|
|
2017-09-15 16:32:23 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::RemoveReferens()
|
|
|
|
{
|
|
|
|
const auto circleCenter = VAbstractTool::data.GetGObject(circleCenterId);
|
|
|
|
const auto tangentPoint = VAbstractTool::data.GetGObject(tangentPointId);
|
|
|
|
|
|
|
|
doc->DecrementReferens(circleCenter->getIdTool());
|
|
|
|
doc->DecrementReferens(tangentPoint->getIdTool());
|
|
|
|
}
|
|
|
|
|
2015-06-05 15:43:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-10-17 18:35:39 +02:00
|
|
|
void VToolPointFromCircleAndTangent::SaveDialog(QDomElement &domElement, QList<quint32> &oldDependencies,
|
|
|
|
QList<quint32> &newDependencies)
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
2017-04-15 16:39:59 +02:00
|
|
|
SCASSERT(not m_dialog.isNull())
|
|
|
|
QSharedPointer<DialogPointFromCircleAndTangent> dialogTool = m_dialog.objectCast<DialogPointFromCircleAndTangent>();
|
|
|
|
SCASSERT(not dialogTool.isNull())
|
2017-10-17 18:35:39 +02:00
|
|
|
|
|
|
|
AddDependence(oldDependencies, circleCenterId);
|
|
|
|
AddDependence(oldDependencies, tangentPointId);
|
|
|
|
AddDependence(newDependencies, dialogTool->GetTangentPointId());
|
|
|
|
AddDependence(newDependencies, dialogTool->GetCircleCenterId());
|
|
|
|
|
2015-06-05 15:43:41 +02:00
|
|
|
doc->SetAttribute(domElement, AttrName, dialogTool->getPointName());
|
|
|
|
doc->SetAttribute(domElement, AttrCCenter, QString().setNum(dialogTool->GetCircleCenterId()));
|
|
|
|
doc->SetAttribute(domElement, AttrTangent, QString().setNum(dialogTool->GetTangentPointId()));
|
|
|
|
doc->SetAttribute(domElement, AttrCRadius, dialogTool->GetCircleRadius());
|
|
|
|
doc->SetAttribute(domElement, AttrCrossPoint,
|
|
|
|
QString().setNum(static_cast<int>(dialogTool->GetCrossCirclesPoint())));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
|
|
|
|
{
|
2015-06-20 08:23:04 +02:00
|
|
|
VToolSinglePoint::SaveOptions(tag, obj);
|
2015-06-05 15:43:41 +02:00
|
|
|
|
|
|
|
doc->SetAttribute(tag, AttrType, ToolType);
|
|
|
|
doc->SetAttribute(tag, AttrCCenter, circleCenterId);
|
|
|
|
doc->SetAttribute(tag, AttrTangent, tangentPointId);
|
|
|
|
doc->SetAttribute(tag, AttrCRadius, circleRadius);
|
|
|
|
doc->SetAttribute(tag, AttrCrossPoint, static_cast<int>(crossPoint));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::ReadToolAttributes(const QDomElement &domElement)
|
|
|
|
{
|
|
|
|
circleCenterId = doc->GetParametrUInt(domElement, AttrCCenter, NULL_ID_STR);
|
|
|
|
tangentPointId = doc->GetParametrUInt(domElement, AttrTangent, NULL_ID_STR);
|
|
|
|
circleRadius = doc->GetParametrString(domElement, AttrCRadius);
|
|
|
|
crossPoint = static_cast<CrossCirclesPoint>(doc->GetParametrUInt(domElement, AttrCrossPoint, "1"));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::SetVisualization()
|
|
|
|
{
|
2016-09-24 15:09:09 +02:00
|
|
|
if (not vis.isNull())
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
|
|
|
VisToolPointFromCircleAndTangent *visual = qobject_cast<VisToolPointFromCircleAndTangent *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(visual != nullptr)
|
2015-06-05 15:43:41 +02:00
|
|
|
|
2016-01-24 17:15:08 +01:00
|
|
|
visual->setObject1Id(tangentPointId);
|
|
|
|
visual->setObject2Id(circleCenterId);
|
2015-06-05 15:43:41 +02:00
|
|
|
visual->setCRadius(circleRadius);
|
|
|
|
visual->setCrossPoint(crossPoint);
|
|
|
|
visual->RefreshGeometry();
|
|
|
|
}
|
|
|
|
}
|