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 vtoollinepoint.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
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2013-11-15 13:41:26 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/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-07-30 20:46:40 +02:00
|
|
|
#include "vtoollinepoint.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QColor>
|
|
|
|
#include <QGraphicsLineItem>
|
|
|
|
#include <QLineF>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QPointF>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <Qt>
|
|
|
|
#include <new>
|
|
|
|
|
|
|
|
#include "../ifc/xml/vabstractpattern.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"
|
2015-10-08 20:11:50 +02:00
|
|
|
#include "../vgeometry/vpointf.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../../../vabstracttool.h"
|
|
|
|
#include "../../../vdrawtool.h"
|
|
|
|
#include "../vtoolsinglepoint.h"
|
2017-06-23 11:25:02 +02:00
|
|
|
#include "../vwidgets/scalesceneitems.h"
|
2022-08-22 10:34:02 +02:00
|
|
|
#include "../vwidgets/global.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
template <class T> class QSharedPointer;
|
2013-07-30 20:46:40 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief VToolLinePoint constructor.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
* @param id object id in container.
|
|
|
|
* @param typeLine line type.
|
2015-02-07 12:17:31 +01:00
|
|
|
* @param lineColor line color.
|
2014-09-11 18:52:02 +02:00
|
|
|
* @param formula string with length formula.
|
2014-06-13 19:02:41 +02:00
|
|
|
* @param basePointId id base line point.
|
|
|
|
* @param angle line angle.
|
|
|
|
* @param parent parent object.
|
|
|
|
*/
|
2015-06-18 19:23:24 +02:00
|
|
|
VToolLinePoint::VToolLinePoint(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine,
|
2015-02-07 12:17:31 +01:00
|
|
|
const QString &lineColor, const QString &formula, const quint32 &basePointId,
|
2020-10-28 13:09:56 +01:00
|
|
|
const qreal &angle, const QString ¬es, QGraphicsItem *parent)
|
|
|
|
:VToolSinglePoint(doc, data, id, notes, parent), formulaLength(formula), angle(angle), basePointId(basePointId),
|
2016-08-02 14:12:13 +02:00
|
|
|
mainLine(nullptr), lineColor(lineColor)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2017-05-16 12:07:53 +02:00
|
|
|
this->m_lineType = typeLine;
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT_X(basePointId != 0, Q_FUNC_INFO, "basePointId == 0"); //-V654 //-V712
|
2017-03-31 16:04:11 +02:00
|
|
|
QPointF point1 = static_cast<QPointF>(*data->GeometricObject<VPointF>(basePointId));
|
|
|
|
QPointF point2 = static_cast<QPointF>(*data->GeometricObject<VPointF>(id));
|
2022-03-16 16:43:09 +01:00
|
|
|
QLineF line(point1 - point2, QPointF());
|
|
|
|
mainLine = new VScaledLine(line, this);
|
2018-02-06 18:30:27 +01:00
|
|
|
mainLine->SetBoldLine(false);
|
2013-07-30 20:46:40 +02:00
|
|
|
mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
|
2022-03-16 16:43:09 +01:00
|
|
|
mainLine->setVisible(not line.isNull());
|
2013-07-30 20:46:40 +02:00
|
|
|
}
|
|
|
|
|
2014-10-04 21:12:46 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolLinePoint::~VToolLinePoint()
|
|
|
|
{
|
|
|
|
delete mainLine;
|
|
|
|
}
|
|
|
|
|
2017-06-16 13:53:08 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolLinePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
2017-06-23 11:25:02 +02:00
|
|
|
QPen mPen = mainLine->pen();
|
|
|
|
mPen.setColor(CorrectColor(this, lineColor));
|
|
|
|
mPen.setStyle(LineStyleToPenStyle(m_lineType));
|
2017-06-16 13:53:08 +02:00
|
|
|
|
2017-06-23 11:25:02 +02:00
|
|
|
mainLine->setPen(mPen);
|
2017-06-16 13:53:08 +02:00
|
|
|
|
|
|
|
VToolSinglePoint::paint(painter, option, widget);
|
|
|
|
}
|
|
|
|
|
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 VToolLinePoint::RefreshGeometry()
|
|
|
|
{
|
2017-09-17 08:45:18 +02:00
|
|
|
VToolSinglePoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<VPointF>(m_id));
|
|
|
|
QPointF point = static_cast<QPointF>(*VDrawTool::data.GeometricObject<VPointF>(m_id));
|
2017-03-31 16:04:11 +02:00
|
|
|
QPointF basePoint = static_cast<QPointF>(*VDrawTool::data.GeometricObject<VPointF>(basePointId));
|
2022-03-16 16:43:09 +01:00
|
|
|
QLineF line(basePoint - point, QPointF());
|
|
|
|
mainLine->setLine(line);
|
|
|
|
mainLine->setVisible(not line.isNull());
|
2013-07-31 13:34:39 +02:00
|
|
|
}
|
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 RemoveReferens decrement value of reference.
|
|
|
|
*/
|
|
|
|
void VToolLinePoint::RemoveReferens()
|
|
|
|
{
|
2016-02-02 14:38:30 +01:00
|
|
|
const auto basePoint = VAbstractTool::data.GetGObject(basePointId);
|
|
|
|
doc->DecrementReferens(basePoint->getIdTool());
|
2014-06-13 19:02:41 +02:00
|
|
|
}
|
|
|
|
|
2015-05-28 14:13:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolLinePoint::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
|
|
|
|
{
|
2015-06-20 08:23:04 +02:00
|
|
|
VToolSinglePoint::SaveOptions(tag, obj);
|
2015-05-28 14:13:37 +02:00
|
|
|
|
2017-05-16 12:07:53 +02:00
|
|
|
doc->SetAttribute(tag, AttrTypeLine, m_lineType);
|
2015-05-28 14:13:37 +02:00
|
|
|
doc->SetAttribute(tag, AttrLineColor, lineColor);
|
|
|
|
}
|
|
|
|
|
2015-02-06 13:31:40 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-06-23 11:25:02 +02:00
|
|
|
void VToolLinePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2018-02-06 18:30:27 +01:00
|
|
|
mainLine->SetBoldLine(true);
|
2017-06-23 11:25:02 +02:00
|
|
|
VToolSinglePoint::hoverEnterEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolLinePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2018-02-06 18:30:27 +01:00
|
|
|
mainLine->SetBoldLine(false);
|
2017-06-23 11:25:02 +02:00
|
|
|
VToolSinglePoint::hoverLeaveEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-23 13:50:48 +02:00
|
|
|
QString VToolLinePoint::MakeToolTip() const
|
|
|
|
{
|
|
|
|
const QSharedPointer<VPointF> first = VAbstractTool::data.GeometricObject<VPointF>(basePointId);
|
2017-09-17 08:45:18 +02:00
|
|
|
const QSharedPointer<VPointF> second = VAbstractTool::data.GeometricObject<VPointF>(m_id);
|
2017-08-23 13:50:48 +02:00
|
|
|
|
|
|
|
const QLineF line(static_cast<QPointF>(*first), static_cast<QPointF>(*second));
|
|
|
|
|
|
|
|
const QString toolTip = QString("<table>"
|
2017-09-17 09:24:34 +02:00
|
|
|
"<tr> <td><b>%6:</b> %7</td> </tr>"
|
2017-08-23 13:50:48 +02:00
|
|
|
"<tr> <td><b>%1:</b> %2 %3</td> </tr>"
|
|
|
|
"<tr> <td><b>%4:</b> %5°</td> </tr>"
|
|
|
|
"</table>")
|
|
|
|
.arg(tr("Length"))
|
2021-02-06 14:52:21 +01:00
|
|
|
.arg(VAbstractValApplication::VApp()->fromPixel(line.length()))
|
|
|
|
.arg(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true), tr("Angle"))
|
2017-09-17 09:24:34 +02:00
|
|
|
.arg(line.angle())
|
2018-03-14 14:39:15 +01:00
|
|
|
.arg(tr("Label"), second->name());
|
2017-08-23 13:50:48 +02:00
|
|
|
return toolTip;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-05-25 08:24:16 +02:00
|
|
|
void VToolLinePoint::Disable(bool disable, const QString &namePP)
|
2015-02-06 13:31:40 +01:00
|
|
|
{
|
2015-06-20 08:23:04 +02:00
|
|
|
VToolSinglePoint::Disable(disable, namePP);
|
2017-06-16 13:53:08 +02:00
|
|
|
mainLine->setEnabled(isEnabled());
|
2015-02-06 13:31:40 +01:00
|
|
|
}
|
|
|
|
|
2015-05-28 14:36:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief FullUpdateFromFile update tool data form file.
|
|
|
|
*/
|
|
|
|
void VToolLinePoint::FullUpdateFromFile()
|
|
|
|
{
|
|
|
|
ReadAttributes();
|
|
|
|
RefreshGeometry();
|
|
|
|
SetVisualization();
|
|
|
|
}
|
|
|
|
|
2014-09-01 17:36:08 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
qreal VToolLinePoint::GetAngle() const
|
2014-09-01 17:36:08 +02:00
|
|
|
{
|
|
|
|
return angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void VToolLinePoint::SetAngle(const qreal &value)
|
2014-09-01 17:36:08 +02:00
|
|
|
{
|
|
|
|
angle = value;
|
2017-09-17 08:45:18 +02:00
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
|
2014-09-01 17:36:08 +02:00
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:11:50 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VToolLinePoint::GetLineColor() const
|
|
|
|
{
|
|
|
|
return lineColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolLinePoint::SetLineColor(const QString &value)
|
|
|
|
{
|
|
|
|
lineColor = value;
|
|
|
|
|
2017-09-17 08:45:18 +02:00
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
|
2016-05-19 12:11:50 +02:00
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
|
2014-08-30 21:58:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
VFormula VToolLinePoint::GetFormulaLength() const
|
2014-08-28 13:05:58 +02:00
|
|
|
{
|
2014-08-30 12:41:21 +02:00
|
|
|
VFormula fLength(formulaLength, this->getData());
|
2018-02-22 13:59:39 +01:00
|
|
|
fLength.setCheckZero(false);
|
2017-09-17 08:45:18 +02:00
|
|
|
fLength.setToolId(m_id);
|
2021-02-06 14:52:21 +01:00
|
|
|
fLength.setPostfix(UnitsToStr(VAbstractValApplication::VApp()->patternUnits()));
|
2018-01-20 14:37:15 +01:00
|
|
|
fLength.Eval();
|
2014-08-30 12:41:21 +02:00
|
|
|
|
|
|
|
return fLength;
|
2014-08-28 13:05:58 +02:00
|
|
|
}
|
2014-08-30 21:58:31 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void VToolLinePoint::SetFormulaLength(const VFormula &value)
|
2014-08-30 21:58:31 +02:00
|
|
|
{
|
|
|
|
if (value.error() == false)
|
|
|
|
{
|
2015-02-03 11:17:04 +01:00
|
|
|
formulaLength = value.GetFormula(FormulaType::FromUser);
|
2014-08-30 21:58:31 +02:00
|
|
|
|
2017-09-17 08:45:18 +02:00
|
|
|
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(m_id);
|
2014-08-30 21:58:31 +02:00
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
}
|
2017-03-19 16:13:02 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VToolLinePoint::BasePointName() const
|
|
|
|
{
|
|
|
|
return VAbstractTool::data.GetGObject(basePointId)->name();
|
|
|
|
}
|