2015-06-05 15:43:41 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vtoolpointfromcircleandtangent.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 3 6, 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 "vtoolpointfromcircleandtangent.h"
|
2015-06-19 16:17:31 +02:00
|
|
|
#include "../../../../dialogs/tools/dialogpointfromcircleandtangent.h"
|
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vgeometry/varc.h"
|
2016-03-24 15:49:15 +01:00
|
|
|
#include "../../../../visualization/line/vistoolpointfromcircleandtangent.h"
|
2015-06-19 16:17:31 +02:00
|
|
|
#include "../vpatterndb/vformula.h"
|
2015-06-05 15:43:41 +02:00
|
|
|
|
|
|
|
const QString VToolPointFromCircleAndTangent::ToolType = QStringLiteral("pointFromCircleAndTangent");
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-06-18 19:23:24 +02:00
|
|
|
VToolPointFromCircleAndTangent::VToolPointFromCircleAndTangent(VAbstractPattern *doc, VContainer *data,
|
|
|
|
const quint32 &id,
|
2015-06-05 15:43:41 +02:00
|
|
|
quint32 circleCenterId, const QString &circleRadius,
|
|
|
|
quint32 tangentPointId, CrossCirclesPoint crossPoint,
|
|
|
|
const Source &typeCreation, QGraphicsItem *parent)
|
2015-06-20 08:23:04 +02:00
|
|
|
:VToolSinglePoint(doc, data, id, parent), circleCenterId(circleCenterId), tangentPointId(tangentPointId),
|
2015-06-05 15:43:41 +02:00
|
|
|
circleRadius(circleRadius), crossPoint(crossPoint)
|
|
|
|
{
|
|
|
|
ToolCreation(typeCreation);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::setDialog()
|
|
|
|
{
|
|
|
|
SCASSERT(dialog != nullptr);
|
|
|
|
DialogPointFromCircleAndTangent *dialogTool = qobject_cast<DialogPointFromCircleAndTangent*>(dialog);
|
|
|
|
SCASSERT(dialogTool != nullptr);
|
|
|
|
const QSharedPointer<VPointF> p = VAbstractTool::data.GeometricObject<VPointF>(id);
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(DialogTool *dialog, VMainGraphicsScene *scene,
|
2015-06-18 19:23:24 +02:00
|
|
|
VAbstractPattern *doc, VContainer *data)
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
|
|
|
SCASSERT(dialog != nullptr);
|
|
|
|
DialogPointFromCircleAndTangent *dialogTool = qobject_cast<DialogPointFromCircleAndTangent*>(dialog);
|
|
|
|
SCASSERT(dialogTool != nullptr);
|
|
|
|
const quint32 circleCenterId = dialogTool->GetCircleCenterId();
|
|
|
|
QString circleRadius = dialogTool->GetCircleRadius();
|
|
|
|
const quint32 tangentPointId = dialogTool->GetTangentPointId();
|
|
|
|
const CrossCirclesPoint pType = dialogTool->GetCrossCirclesPoint();
|
|
|
|
const QString pointName = dialogTool->getPointName();
|
2015-11-02 17:25:29 +01:00
|
|
|
VToolPointFromCircleAndTangent *point = Create(0, pointName, circleCenterId, circleRadius, tangentPointId, pType,
|
|
|
|
5, 10, scene, doc, data, Document::FullParse, Source::FromGui);
|
2015-06-05 15:43:41 +02:00
|
|
|
if (point != nullptr)
|
|
|
|
{
|
|
|
|
point->dialog=dialogTool;
|
|
|
|
}
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(const quint32 _id, const QString &pointName,
|
|
|
|
quint32 circleCenterId, QString &circleRadius,
|
|
|
|
quint32 tangentPointId,
|
|
|
|
CrossCirclesPoint crossPoint, const qreal &mx,
|
|
|
|
const qreal &my, VMainGraphicsScene *scene,
|
2015-06-18 19:23:24 +02:00
|
|
|
VAbstractPattern *doc, VContainer *data,
|
2015-06-05 15:43:41 +02:00
|
|
|
const Document &parse,
|
|
|
|
const Source &typeCreation)
|
|
|
|
{
|
|
|
|
const qreal radius = qApp->toPixel(CheckFormula(_id, circleRadius, data));
|
|
|
|
const VPointF cPoint = *data->GeometricObject<VPointF>(circleCenterId);
|
|
|
|
const VPointF tPoint = *data->GeometricObject<VPointF>(tangentPointId);
|
|
|
|
|
2016-05-14 21:28:09 +02:00
|
|
|
const QPointF point = VToolPointFromCircleAndTangent::FindPoint(tPoint, cPoint, radius,
|
2015-06-05 15:43:41 +02:00
|
|
|
crossPoint);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2015-06-06 08:33:19 +02:00
|
|
|
VDrawTool::AddRecord(id, Tool::PointFromCircleAndTangent, doc);
|
2015-06-05 15:43:41 +02:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
|
|
|
VToolPointFromCircleAndTangent *point = new VToolPointFromCircleAndTangent(doc, data, id, circleCenterId,
|
|
|
|
circleRadius, tangentPointId,
|
|
|
|
crossPoint, typeCreation);
|
|
|
|
scene->addItem(point);
|
2016-03-31 16:01:41 +02:00
|
|
|
InitToolConnections(scene, point);
|
2015-06-05 15:43:41 +02:00
|
|
|
doc->AddTool(id, point);
|
2016-02-02 14:38:30 +01:00
|
|
|
doc->IncrementReferens(cPoint.getIdTool());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return p1;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
return QPointF(0, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 VToolPointFromCircleAndTangent::GetTangentPointId() const
|
|
|
|
{
|
|
|
|
return tangentPointId;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::SetTangentPointId(const quint32 &value)
|
|
|
|
{
|
|
|
|
if (value != NULL_ID)
|
|
|
|
{
|
|
|
|
tangentPointId = value;
|
|
|
|
|
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
|
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 VToolPointFromCircleAndTangent::GetCircleCenterId() const
|
|
|
|
{
|
|
|
|
return circleCenterId;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::SetCircleCenterId(const quint32 &value)
|
|
|
|
{
|
|
|
|
if (value != NULL_ID)
|
|
|
|
{
|
|
|
|
circleCenterId = value;
|
|
|
|
|
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
|
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VFormula VToolPointFromCircleAndTangent::GetCircleRadius() const
|
|
|
|
{
|
|
|
|
VFormula radius(circleRadius, getData());
|
|
|
|
radius.setCheckZero(true);
|
|
|
|
radius.setToolId(id);
|
|
|
|
radius.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit()));
|
|
|
|
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);
|
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
|
|
|
|
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;
|
|
|
|
|
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
|
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::ShowVisualization(bool show)
|
|
|
|
{
|
|
|
|
ShowToolVisualization<VisToolPointFromCircleAndTangent>(show);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::RemoveReferens()
|
|
|
|
{
|
2016-02-02 14:38:30 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2015-11-02 17:25:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ContextMenu<DialogPointFromCircleAndTangent>(this, event);
|
|
|
|
}
|
|
|
|
catch(const VExceptionToolWasDeleted &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return;//Leave this method immediately!!!
|
|
|
|
}
|
2015-06-05 15:43:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolPointFromCircleAndTangent::SaveDialog(QDomElement &domElement)
|
|
|
|
{
|
|
|
|
SCASSERT(dialog != nullptr);
|
|
|
|
DialogPointFromCircleAndTangent *dialogTool = qobject_cast<DialogPointFromCircleAndTangent*>(dialog);
|
|
|
|
SCASSERT(dialogTool != nullptr);
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
if (vis != nullptr)
|
|
|
|
{
|
|
|
|
VisToolPointFromCircleAndTangent *visual = qobject_cast<VisToolPointFromCircleAndTangent *>(vis);
|
|
|
|
SCASSERT(visual != nullptr);
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|