2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vtoolspline.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2013-11-15 13:41:26 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-08-05 10:37:56 +02:00
|
|
|
#include "vtoolspline.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QDomElement>
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QFlags>
|
|
|
|
#include <QForeachContainer>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QList>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QRectF>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <QUndoStack>
|
|
|
|
#include <QVector>
|
|
|
|
#include <Qt>
|
|
|
|
#include <new>
|
|
|
|
|
2015-06-19 16:17:31 +02:00
|
|
|
#include "../../../dialogs/tools/dialogspline.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../../dialogs/tools/dialogtool.h"
|
2015-06-19 16:17:31 +02:00
|
|
|
#include "../../../undocommands/movespline.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../../visualization/visualization.h"
|
2016-03-24 15:49:15 +01:00
|
|
|
#include "../../../visualization/path/vistoolspline.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-02-26 18:44:51 +01:00
|
|
|
#include "../qmuparser/qmutokenparser.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vgeometry/vabstractcurve.h"
|
|
|
|
#include "../vgeometry/vgobject.h"
|
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vgeometry/vspline.h"
|
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2016-08-16 18:57:32 +02:00
|
|
|
#include "../vmisc/vmath.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
|
|
|
#include "../vwidgets/vcontrolpointspline.h"
|
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../vabstracttool.h"
|
|
|
|
#include "../vdrawtool.h"
|
|
|
|
#include "vabstractspline.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
class QDomElement;
|
|
|
|
class QGraphicsSceneContextMenuEvent;
|
|
|
|
class QGraphicsSceneHoverEvent;
|
|
|
|
class QGraphicsSceneMouseEvent;
|
2015-04-01 20:21:24 +02:00
|
|
|
|
2016-02-26 15:38:42 +01:00
|
|
|
const QString VToolSpline::ToolType = QStringLiteral("simpleInteractive");
|
|
|
|
const QString VToolSpline::OldToolType = QStringLiteral("simple");
|
2013-08-05 10:37:56 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief VToolSpline constructor.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
* @param id object id in container.
|
|
|
|
* @param typeCreation way we create this tool.
|
|
|
|
* @param parent parent object.
|
|
|
|
*/
|
2016-05-19 12:11:50 +02:00
|
|
|
VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
|
2014-07-24 12:19:41 +02:00
|
|
|
QGraphicsItem *parent)
|
2015-02-12 11:55:09 +01:00
|
|
|
:VAbstractSpline(doc, data, id, parent), oldPosition()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-17 17:50:33 +02:00
|
|
|
sceneType = SceneObject::Spline;
|
|
|
|
|
2015-06-15 11:32:27 +02:00
|
|
|
this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
|
2015-02-12 11:55:09 +01:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
2016-05-08 17:04:18 +02:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
|
2014-08-17 16:22:30 +02:00
|
|
|
this->setPath(ToolPath());
|
2013-08-05 10:37:56 +02:00
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
|
|
|
|
|
2016-02-27 09:29:32 +01:00
|
|
|
const bool freeAngle1 = qmu::QmuTokenParser::IsSingle(spl->GetStartAngleFormula());
|
|
|
|
const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl->GetC1LengthFormula());
|
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(),
|
2016-05-14 21:28:09 +02:00
|
|
|
spl->GetP1(), *data->GetPatternUnit(), freeAngle1,
|
2016-02-27 09:29:32 +01:00
|
|
|
freeLength1, this);
|
2013-08-05 10:37:56 +02:00
|
|
|
connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this,
|
2013-08-09 08:49:34 +02:00
|
|
|
&VToolSpline::ControlPointChangePosition);
|
|
|
|
connect(this, &VToolSpline::setEnabledPoint, controlPoint1, &VControlPointSpline::setEnabledPoint);
|
2015-04-22 15:13:13 +02:00
|
|
|
connect(controlPoint1, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent);
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoints.append(controlPoint1);
|
2013-08-05 10:37:56 +02:00
|
|
|
|
2016-02-27 09:29:32 +01:00
|
|
|
const bool freeAngle2 = qmu::QmuTokenParser::IsSingle(spl->GetEndAngleFormula());
|
|
|
|
const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl->GetC2LengthFormula());
|
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, spl->GetP3(),
|
2016-05-14 21:28:09 +02:00
|
|
|
spl->GetP4(), *data->GetPatternUnit(), freeAngle2,
|
2016-02-27 09:29:32 +01:00
|
|
|
freeLength2, this);
|
2013-08-05 10:37:56 +02:00
|
|
|
connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this,
|
2013-08-09 08:49:34 +02:00
|
|
|
&VToolSpline::ControlPointChangePosition);
|
|
|
|
connect(this, &VToolSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint);
|
2015-04-22 15:13:13 +02:00
|
|
|
connect(controlPoint2, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent);
|
2013-08-09 08:49:34 +02:00
|
|
|
controlPoints.append(controlPoint2);
|
2013-08-05 10:37:56 +02:00
|
|
|
|
2015-04-22 16:30:48 +02:00
|
|
|
ShowHandles(false);
|
2014-09-06 10:51:46 +02:00
|
|
|
|
2015-05-28 12:16:59 +02:00
|
|
|
ToolCreation(typeCreation);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-10-04 08:37:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolSpline::~VToolSpline()
|
2015-04-29 19:02:03 +02:00
|
|
|
{
|
|
|
|
//Disable cursor-arrow-openhand
|
2015-06-15 15:47:44 +02:00
|
|
|
RestoreOverrideCursor(cursorArrowOpenHand);
|
2015-04-29 19:02:03 +02:00
|
|
|
}
|
2014-10-04 08:37:19 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief setDialog set dialog when user want change tool option.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSpline::setDialog()
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogSpline *dialogTool = qobject_cast<DialogSpline*>(dialog);
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2016-02-15 10:02:55 +01:00
|
|
|
const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
|
|
|
|
dialogTool->SetSpline(*spl);
|
2016-05-19 12:11:50 +02:00
|
|
|
dialogTool->SetColor(spl->GetColor());
|
2013-08-13 18:48:36 +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 scene pointer to scene.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
2014-08-18 16:42:53 +02:00
|
|
|
* @return the created tool
|
2014-06-13 19:02:41 +02:00
|
|
|
*/
|
2015-06-18 19:23:24 +02:00
|
|
|
VToolSpline* VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2016-02-15 10:02:55 +01:00
|
|
|
auto dialogTool = qobject_cast<DialogSpline*>(dialog);
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2016-02-15 10:02:55 +01:00
|
|
|
|
2016-05-19 12:11:50 +02:00
|
|
|
VSpline *spline = new VSpline(dialogTool->GetSpline());
|
|
|
|
|
|
|
|
auto spl = Create(0, spline, dialogTool->GetColor(), scene, doc, data, Document::FullParse, Source::FromGui);
|
2016-02-15 10:02:55 +01:00
|
|
|
|
2014-08-18 16:42:53 +02:00
|
|
|
if (spl != nullptr)
|
|
|
|
{
|
|
|
|
spl->dialog=dialogTool;
|
|
|
|
}
|
|
|
|
return spl;
|
2013-08-13 18:48:36 +02: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.
|
2016-02-26 15:38:42 +01:00
|
|
|
* @param spline spline.
|
2014-06-13 19:02:41 +02:00
|
|
|
* @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-18 16:42:53 +02:00
|
|
|
* @return the created tool
|
2014-06-13 19:02:41 +02:00
|
|
|
*/
|
2016-02-26 15:38:42 +01:00
|
|
|
VToolSpline* VToolSpline::Create(const quint32 _id, VSpline *spline, const QString &color, VMainGraphicsScene *scene,
|
2016-02-15 10:02:55 +01:00
|
|
|
VAbstractPattern *doc, VContainer *data, const Document &parse,
|
|
|
|
const Source &typeCreation)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 id = _id;
|
2016-05-19 12:11:50 +02:00
|
|
|
spline->SetColor(color);
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
id = data->AddGObject(spline);
|
2016-09-24 19:44:06 +02:00
|
|
|
data->AddSpline(data->GeometricObject<VAbstractBezier>(id), id);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
data->UpdateGObject(id, spline);
|
2016-09-24 19:44:06 +02:00
|
|
|
data->AddSpline(data->GeometricObject<VAbstractBezier>(id), id);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse != Document::FullParse)
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
doc->UpdateToolData(id, data);
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-26 20:31:28 +02:00
|
|
|
VDrawTool::AddRecord(id, Tool::Spline, doc);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
2016-05-19 12:11:50 +02:00
|
|
|
auto _spl = new VToolSpline(doc, data, id, typeCreation);
|
2016-02-15 10:02:55 +01:00
|
|
|
scene->addItem(_spl);
|
2016-03-31 16:01:41 +02:00
|
|
|
InitSplineToolConnections(scene, _spl);
|
2016-02-15 10:02:55 +01:00
|
|
|
doc->AddTool(id, _spl);
|
2016-03-10 14:55:04 +01:00
|
|
|
doc->IncrementReferens(spline->GetP1().getIdTool());
|
|
|
|
doc->IncrementReferens(spline->GetP4().getIdTool());
|
2016-02-15 10:02:55 +01:00
|
|
|
return _spl;
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
2014-08-18 16:42:53 +02:00
|
|
|
return nullptr;
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2016-02-26 15:38:42 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolSpline *VToolSpline::Create(const quint32 _id, quint32 point1, quint32 point4, QString &a1, QString &a2,
|
2016-02-27 15:49:10 +01:00
|
|
|
QString &l1, QString &l2, quint32 duplicate, const QString &color,
|
2016-02-26 15:38:42 +01:00
|
|
|
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
|
|
|
|
const Document &parse, const Source &typeCreation)
|
|
|
|
{
|
2016-03-04 17:08:29 +01:00
|
|
|
const qreal calcAngle1 = CheckFormula(_id, a1, data);
|
|
|
|
const qreal calcAngle2 = CheckFormula(_id, a2, data);
|
2016-02-26 15:38:42 +01:00
|
|
|
|
2016-03-04 17:08:29 +01:00
|
|
|
const qreal calcLength1 = qApp->toPixel(CheckFormula(_id, l1, data));
|
|
|
|
const qreal calcLength2 = qApp->toPixel(CheckFormula(_id, l2, data));
|
2016-02-26 15:38:42 +01:00
|
|
|
|
|
|
|
auto p1 = data->GeometricObject<VPointF>(point1);
|
|
|
|
auto p4 = data->GeometricObject<VPointF>(point4);
|
|
|
|
|
2016-02-27 15:49:10 +01:00
|
|
|
auto spline = new VSpline(*p1, *p4, calcAngle1, a1, calcAngle2, a2, calcLength1, l1, calcLength2, l2);
|
2016-02-26 15:38:42 +01:00
|
|
|
if (duplicate > 0)
|
|
|
|
{
|
|
|
|
spline->SetDuplicate(duplicate);
|
|
|
|
}
|
|
|
|
|
|
|
|
return VToolSpline::Create(_id, spline, color, scene, doc, data, parse, typeCreation);
|
|
|
|
}
|
|
|
|
|
2014-09-01 18:36:15 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VSpline VToolSpline::getSpline() const
|
|
|
|
{
|
2016-02-27 11:28:15 +01:00
|
|
|
auto spline = VAbstractTool::data.GeometricObject<VSpline>(id);
|
2014-09-01 18:36:15 +02:00
|
|
|
return *spline.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSpline::setSpline(const VSpline &spl)
|
|
|
|
{
|
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
|
|
|
|
QSharedPointer<VSpline> spline = qSharedPointerDynamicCast<VSpline>(obj);
|
|
|
|
*spline.data() = spl;
|
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
|
2014-09-03 15:52:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSpline::ShowVisualization(bool show)
|
|
|
|
{
|
2015-05-23 15:10:08 +02:00
|
|
|
ShowToolVisualization<VisToolSpline>(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 ControlPointChangePosition handle change position control point.
|
|
|
|
* @param indexSpline position spline in spline list.
|
|
|
|
* @param position position point in spline.
|
|
|
|
* @param pos new position.
|
|
|
|
*/
|
2014-06-12 09:22:29 +02:00
|
|
|
void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const SplinePointPosition &position,
|
2013-11-07 15:40:39 +01:00
|
|
|
const QPointF &pos)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
Q_UNUSED(indexSpline);
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VSpline> spline = VAbstractTool::data.GeometricObject<VSpline>(id);
|
2016-03-04 17:08:29 +01:00
|
|
|
const VSpline spl = CorrectedSpline(*spline, position, pos);
|
2014-06-09 19:39:18 +02:00
|
|
|
|
2016-05-20 14:20:08 +02:00
|
|
|
MoveSpline *moveSpl = new MoveSpline(doc, spline.data(), spl, id);
|
2015-06-16 17:01:17 +02:00
|
|
|
connect(moveSpl, &MoveSpline::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
2014-06-09 19:39:18 +02:00
|
|
|
qApp->getUndoStack()->push(moveSpl);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2015-02-12 12:43:38 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSpline::EnableToolMove(bool move)
|
|
|
|
{
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, move);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief contextMenuEvent handle context menu events.
|
|
|
|
* @param event context menu event.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2015-11-02 17:25:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ContextMenu<DialogSpline>(this, event);
|
|
|
|
}
|
|
|
|
catch(const VExceptionToolWasDeleted &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return;//Leave this method immediately!!!
|
|
|
|
}
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief RemoveReferens decrement value of reference.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSpline::RemoveReferens()
|
|
|
|
{
|
2016-02-02 14:38:30 +01:00
|
|
|
const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
|
|
|
|
doc->DecrementReferens(spl->GetP1().getIdTool());
|
|
|
|
doc->DecrementReferens(spl->GetP4().getIdTool());
|
2013-09-30 18:29:03 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief SaveDialog save options into file after change in dialog.
|
|
|
|
*/
|
2014-02-06 14:57:23 +01:00
|
|
|
void VToolSpline::SaveDialog(QDomElement &domElement)
|
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2016-02-15 10:02:55 +01:00
|
|
|
auto dialogTool = qobject_cast<DialogSpline*>(dialog);
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
|
2016-02-15 10:02:55 +01:00
|
|
|
const VSpline spl = dialogTool->GetSpline();
|
2014-02-06 14:57:23 +01:00
|
|
|
|
2014-08-09 10:43:01 +02:00
|
|
|
controlPoints[0]->blockSignals(true);
|
|
|
|
controlPoints[1]->blockSignals(true);
|
|
|
|
|
2014-02-06 14:57:23 +01:00
|
|
|
controlPoints[0]->setPos(spl.GetP2());
|
|
|
|
controlPoints[1]->setPos(spl.GetP3());
|
2014-08-09 10:43:01 +02:00
|
|
|
|
|
|
|
controlPoints[0]->blockSignals(false);
|
|
|
|
controlPoints[1]->blockSignals(false);
|
2014-02-06 14:57:23 +01:00
|
|
|
|
2016-02-26 15:38:42 +01:00
|
|
|
SetSplineAttributes(domElement, spl);
|
|
|
|
doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor());
|
2014-02-06 14:57:23 +01:00
|
|
|
}
|
|
|
|
|
2014-08-30 21:58:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSpline::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
|
|
|
|
{
|
2015-05-28 14:13:37 +02:00
|
|
|
VAbstractSpline::SaveOptions(tag, obj);
|
|
|
|
|
2016-02-26 15:38:42 +01:00
|
|
|
auto spl = qSharedPointerDynamicCast<VSpline>(obj);
|
2014-08-30 21:58:31 +02:00
|
|
|
SCASSERT(spl.isNull() == false);
|
2016-02-26 15:38:42 +01:00
|
|
|
SetSplineAttributes(tag, *spl);
|
2014-08-30 21:58:31 +02:00
|
|
|
}
|
|
|
|
|
2015-02-12 11:55:09 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSpline::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2015-02-12 12:43:38 +01:00
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
2015-02-12 11:55:09 +01:00
|
|
|
{
|
2015-02-12 12:43:38 +01:00
|
|
|
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
|
|
|
|
{
|
2016-03-05 22:06:54 +01:00
|
|
|
if (IsMovable())
|
2016-02-26 18:44:51 +01:00
|
|
|
{
|
|
|
|
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
|
|
|
|
oldPosition = event->scenePos();
|
|
|
|
event->accept();
|
|
|
|
}
|
2015-02-12 12:43:38 +01:00
|
|
|
}
|
2015-02-12 11:55:09 +01:00
|
|
|
}
|
|
|
|
VAbstractSpline::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-02-12 12:43:38 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
|
|
|
|
{
|
2016-03-05 22:06:54 +01:00
|
|
|
if (IsMovable())
|
2016-02-26 18:44:51 +01:00
|
|
|
{
|
|
|
|
//Disable cursor-arrow-closehand
|
|
|
|
RestoreOverrideCursor(cursorArrowCloseHand);
|
|
|
|
}
|
2015-02-12 12:43:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
VAbstractSpline::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-02-12 11:55:09 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2016-03-05 22:06:54 +01:00
|
|
|
if (IsMovable())
|
2016-02-26 18:44:51 +01:00
|
|
|
{
|
|
|
|
// Don't need check if left mouse button was pressed. According to the Qt documentation "If you do receive this
|
|
|
|
// event, you can be certain that this item also received a mouse press event, and that this item is the current
|
|
|
|
// mouse grabber.".
|
2015-02-12 11:55:09 +01:00
|
|
|
|
2016-02-26 18:44:51 +01:00
|
|
|
// Magic Bezier Drag Equations follow!
|
|
|
|
// "weight" describes how the influence of the drag should be distributed
|
|
|
|
// among the handles; 0 = front handle only, 1 = back handle only.
|
2015-02-12 11:55:09 +01:00
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
const auto spline = VAbstractTool::data.GeometricObject<VSpline>(id);
|
2016-02-26 18:44:51 +01:00
|
|
|
const qreal t = spline->ParamT(oldPosition);
|
2015-02-12 11:55:09 +01:00
|
|
|
|
2016-02-26 18:44:51 +01:00
|
|
|
if (qFloor(t) == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-02-12 11:55:09 +01:00
|
|
|
|
2016-02-26 18:44:51 +01:00
|
|
|
double weight;
|
|
|
|
if (t <= 1.0 / 6.0)
|
|
|
|
{
|
|
|
|
weight = 0;
|
|
|
|
}
|
|
|
|
else if (t <= 0.5)
|
|
|
|
{
|
|
|
|
weight = (pow((6 * t - 1) / 2.0, 3)) / 2;
|
|
|
|
}
|
|
|
|
else if (t <= 5.0 / 6.0)
|
|
|
|
{
|
|
|
|
weight = (1 - pow((6 * (1-t) - 1) / 2.0, 3)) / 2 + 0.5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
weight = 1;
|
|
|
|
}
|
2015-02-12 11:55:09 +01:00
|
|
|
|
2016-02-26 18:44:51 +01:00
|
|
|
const QPointF delta = event->scenePos() - oldPosition;
|
|
|
|
const QPointF offset0 = ((1-weight)/(3*t*(1-t)*(1-t))) * delta;
|
|
|
|
const QPointF offset1 = (weight/(3*t*t*(1-t))) * delta;
|
2015-02-12 11:55:09 +01:00
|
|
|
|
2016-02-26 18:44:51 +01:00
|
|
|
const QPointF p2 = spline->GetP2() + offset0;
|
|
|
|
const QPointF p3 = spline->GetP3() + offset1;
|
2015-02-12 11:55:09 +01:00
|
|
|
|
2016-02-26 18:44:51 +01:00
|
|
|
oldPosition = event->scenePos(); // Now mouse here
|
2015-02-12 11:55:09 +01:00
|
|
|
|
2016-02-27 15:49:10 +01:00
|
|
|
VSpline spl = VSpline(spline->GetP1(), p2, p3, spline->GetP4());
|
2016-01-15 13:57:23 +01:00
|
|
|
|
2016-05-20 14:20:08 +02:00
|
|
|
MoveSpline *moveSpl = new MoveSpline(doc, spline.data(), spl, id);
|
2016-02-26 18:44:51 +01:00
|
|
|
connect(moveSpl, &MoveSpline::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(moveSpl);
|
|
|
|
|
|
|
|
// Each time we move something we call recalculation scene rect. In some cases this can cause moving
|
|
|
|
// objects positions. And this cause infinite redrawing. That's why we wait the finish of saving the last move.
|
|
|
|
static bool changeFinished = true;
|
|
|
|
if (changeFinished)
|
|
|
|
{
|
|
|
|
changeFinished = false;
|
2016-01-15 13:57:23 +01:00
|
|
|
|
2016-02-26 18:44:51 +01:00
|
|
|
const QList<QGraphicsView *> viewList = scene()->views();
|
|
|
|
if (not viewList.isEmpty())
|
2016-01-15 13:57:23 +01:00
|
|
|
{
|
2016-02-26 18:44:51 +01:00
|
|
|
if (QGraphicsView *view = viewList.at(0))
|
|
|
|
{
|
|
|
|
VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
|
|
|
|
SCASSERT(currentScene);
|
|
|
|
const QPointF cursorPosition = currentScene->getScenePos();
|
|
|
|
view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
|
|
|
|
}
|
2016-01-15 13:57:23 +01:00
|
|
|
}
|
2016-02-26 18:44:51 +01:00
|
|
|
changeFinished = true;
|
|
|
|
}
|
2016-01-15 13:57:23 +01:00
|
|
|
}
|
2015-02-12 12:43:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
2016-03-05 22:06:54 +01:00
|
|
|
if (IsMovable())
|
2016-02-26 18:44:51 +01:00
|
|
|
{
|
|
|
|
SetOverrideCursor(cursorArrowOpenHand, 1, 1);
|
|
|
|
}
|
2015-02-12 12:43:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VAbstractSpline::hoverEnterEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
2016-03-05 22:06:54 +01:00
|
|
|
if (IsMovable())
|
2016-02-26 18:44:51 +01:00
|
|
|
{
|
|
|
|
//Disable cursor-arrow-openhand
|
|
|
|
RestoreOverrideCursor(cursorArrowOpenHand);
|
|
|
|
}
|
2015-02-12 12:43:38 +01:00
|
|
|
}
|
2015-02-12 11:55:09 +01:00
|
|
|
|
2015-02-12 12:43:38 +01:00
|
|
|
VAbstractSpline::hoverLeaveEvent(event);
|
2015-02-12 11:55:09 +01:00
|
|
|
}
|
|
|
|
|
2015-05-23 13:40:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSpline::SetVisualization()
|
|
|
|
{
|
2016-09-24 15:09:09 +02:00
|
|
|
if (not vis.isNull())
|
2015-05-23 13:40:43 +02:00
|
|
|
{
|
|
|
|
VisToolSpline *visual = qobject_cast<VisToolSpline *>(vis);
|
|
|
|
SCASSERT(visual != nullptr);
|
|
|
|
|
|
|
|
const QSharedPointer<VSpline> spl = VAbstractTool::data.GeometricObject<VSpline>(id);
|
2016-01-24 17:15:08 +01:00
|
|
|
visual->setObject1Id(spl->GetP1().id());
|
|
|
|
visual->setObject4Id(spl->GetP4().id());
|
2015-06-02 15:53:19 +02:00
|
|
|
visual->SetAngle1(spl->GetStartAngle());
|
|
|
|
visual->SetAngle2(spl->GetEndAngle());
|
2015-05-23 13:40:43 +02:00
|
|
|
visual->SetKAsm1(spl->GetKasm1());
|
|
|
|
visual->SetKAsm2(spl->GetKasm2());
|
|
|
|
visual->SetKCurve(spl->GetKcurve());
|
2016-02-12 19:10:01 +01:00
|
|
|
visual->SetMode(Mode::Show);
|
2015-05-23 13:40:43 +02:00
|
|
|
visual->RefreshGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 22:06:54 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VToolSpline::IsMovable() const
|
|
|
|
{
|
|
|
|
const auto spline = VAbstractTool::data.GeometricObject<VSpline>(id);
|
|
|
|
|
|
|
|
return qmu::QmuTokenParser::IsSingle(spline->GetStartAngleFormula()) &&
|
|
|
|
qmu::QmuTokenParser::IsSingle(spline->GetEndAngleFormula()) &&
|
|
|
|
qmu::QmuTokenParser::IsSingle(spline->GetC1LengthFormula()) &&
|
|
|
|
qmu::QmuTokenParser::IsSingle(spline->GetC2LengthFormula());
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief RefreshGeometry refresh item on scene.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolSpline::RefreshGeometry()
|
|
|
|
{
|
2016-01-15 13:57:09 +01:00
|
|
|
// Very important to disable control points. Without it the pogram can't move the curve.
|
2016-02-12 19:10:01 +01:00
|
|
|
foreach (auto *point, controlPoints)
|
2016-01-15 13:57:09 +01:00
|
|
|
{
|
|
|
|
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:11:50 +02:00
|
|
|
const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
|
|
|
|
|
|
|
|
this->setPen(QPen(CorrectColor(spl->GetColor()),
|
2015-06-15 11:32:27 +02:00
|
|
|
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
|
2015-04-23 17:06:17 +02:00
|
|
|
if (isHovered || detailsMode)
|
2014-08-19 13:16:00 +02:00
|
|
|
{
|
|
|
|
this->setPath(ToolPath(PathDirection::Show));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->setPath(ToolPath());
|
|
|
|
}
|
2014-08-17 16:22:30 +02:00
|
|
|
|
2014-08-09 10:43:01 +02:00
|
|
|
controlPoints[0]->blockSignals(true);
|
|
|
|
controlPoints[1]->blockSignals(true);
|
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
{
|
2016-02-27 09:29:32 +01:00
|
|
|
const bool freeAngle1 = qmu::QmuTokenParser::IsSingle(spl->GetStartAngleFormula());
|
|
|
|
const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl->GetC1LengthFormula());
|
|
|
|
|
2016-05-14 21:28:09 +02:00
|
|
|
const QPointF splinePoint = *VAbstractTool::data.GeometricObject<VPointF>(spl->GetP1().id());
|
2016-02-27 09:29:32 +01:00
|
|
|
controlPoints[0]->RefreshCtrlPoint(1, SplinePointPosition::FirstPoint, spl->GetP2(), splinePoint, freeAngle1,
|
|
|
|
freeLength1);
|
2016-02-12 19:10:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2016-02-27 09:29:32 +01:00
|
|
|
const bool freeAngle2 = qmu::QmuTokenParser::IsSingle(spl->GetEndAngleFormula());
|
|
|
|
const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl->GetC2LengthFormula());
|
|
|
|
|
2016-05-14 21:28:09 +02:00
|
|
|
const QPointF splinePoint = *VAbstractTool::data.GeometricObject<VPointF>(spl->GetP4().id());
|
2016-02-27 09:29:32 +01:00
|
|
|
controlPoints[1]->RefreshCtrlPoint(1, SplinePointPosition::LastPoint, spl->GetP3(), splinePoint, freeAngle2,
|
|
|
|
freeLength2);
|
2016-02-12 19:10:01 +01:00
|
|
|
}
|
2014-08-09 10:43:01 +02:00
|
|
|
|
|
|
|
controlPoints[0]->blockSignals(false);
|
|
|
|
controlPoints[1]->blockSignals(false);
|
2014-09-03 15:52:16 +02:00
|
|
|
|
2015-05-23 13:40:43 +02:00
|
|
|
SetVisualization();
|
2016-01-15 13:57:09 +01:00
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
foreach (auto *point, controlPoints)
|
2016-01-15 13:57:09 +01:00
|
|
|
{
|
|
|
|
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
|
|
|
}
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
2016-02-26 15:38:42 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolSpline::SetSplineAttributes(QDomElement &domElement, const VSpline &spl)
|
|
|
|
{
|
2016-02-26 18:44:51 +01:00
|
|
|
SCASSERT(doc != nullptr);
|
|
|
|
|
2016-02-27 09:29:32 +01:00
|
|
|
doc->SetAttribute(domElement, AttrType, ToolType);
|
2016-02-26 15:38:42 +01:00
|
|
|
doc->SetAttribute(domElement, AttrPoint1, spl.GetP1().id());
|
|
|
|
doc->SetAttribute(domElement, AttrPoint4, spl.GetP4().id());
|
|
|
|
doc->SetAttribute(domElement, AttrAngle1, spl.GetStartAngleFormula());
|
|
|
|
doc->SetAttribute(domElement, AttrAngle2, spl.GetEndAngleFormula());
|
|
|
|
doc->SetAttribute(domElement, AttrLength1, spl.GetC1LengthFormula());
|
|
|
|
doc->SetAttribute(domElement, AttrLength2, spl.GetC2LengthFormula());
|
|
|
|
|
|
|
|
if (spl.GetDuplicate() > 0)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(domElement, AttrDuplicate, spl.GetDuplicate());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (domElement.hasAttribute(AttrDuplicate))
|
|
|
|
{
|
|
|
|
domElement.removeAttribute(AttrDuplicate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-27 15:49:10 +01:00
|
|
|
if (domElement.hasAttribute(AttrKCurve))
|
|
|
|
{
|
|
|
|
domElement.removeAttribute(AttrKCurve);
|
|
|
|
}
|
|
|
|
|
2016-02-26 15:38:42 +01:00
|
|
|
if (domElement.hasAttribute(AttrKAsm1))
|
|
|
|
{
|
|
|
|
domElement.removeAttribute(AttrKAsm1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (domElement.hasAttribute(AttrKAsm2))
|
|
|
|
{
|
|
|
|
domElement.removeAttribute(AttrKAsm2);
|
|
|
|
}
|
|
|
|
}
|