valentina/src/app/puzzle/vppiece.cpp

260 lines
7.8 KiB
C++
Raw Normal View History

2020-04-13 18:58:16 +02:00
/************************************************************************
**
2020-05-23 15:42:51 +02:00
** @file vppiece.cpp
2020-04-13 18:58:16 +02:00
** @author Ronan Le Tiec
** @date 13 4, 2020
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2020 Valentina project
** <https://gitlab.com/smart-pattern/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/>.
**
*************************************************************************/
2020-05-23 15:42:51 +02:00
#include "vppiece.h"
2020-04-13 18:58:16 +02:00
2020-05-09 11:13:29 +02:00
#include <QtMath>
2020-05-23 15:29:57 +02:00
#include "vppiecelist.h"
2020-05-10 10:51:54 +02:00
#include "../vmisc/def.h"
#include <QIcon>
#include <QLoggingCategory>
#include <QPainter>
Q_LOGGING_CATEGORY(pPiece, "p.piece")
2020-04-18 11:54:34 +02:00
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
VPPiece::VPPiece()
2020-04-13 18:58:16 +02:00
{
}
2020-04-18 11:54:34 +02:00
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
VPPiece::~VPPiece()
2020-04-18 11:54:34 +02:00
{
}
2020-04-26 12:09:28 +02:00
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
QString VPPiece::GetName() const
2020-04-26 12:09:28 +02:00
{
return m_name;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetName(const QString &name)
2020-04-26 12:09:28 +02:00
{
m_name = name;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
QUuid VPPiece::GetUuid() const
2020-04-26 12:09:28 +02:00
{
return m_uuid;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetUuid(const QUuid &uuid)
2020-04-26 12:09:28 +02:00
{
m_uuid = uuid;
}
2020-04-26 15:36:20 +02:00
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
QVector<QPointF> VPPiece::GetCuttingLine() const
2020-04-26 15:36:20 +02:00
{
return m_cuttingLine;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetCuttingLine(const QVector<QPointF> &cuttingLine)
2020-04-26 15:36:20 +02:00
{
m_cuttingLine = cuttingLine;
}
2020-05-01 19:08:48 +02:00
2020-05-02 12:17:06 +02:00
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
QVector<QPointF> VPPiece::GetSeamLine() const
2020-05-02 12:17:06 +02:00
{
return m_seamLine;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetSeamLine(const QVector<QPointF> &seamLine)
2020-05-02 12:17:06 +02:00
{
m_seamLine = seamLine;
}
2020-05-01 19:08:48 +02:00
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
bool VPPiece::GetShowSeamLine() const
2020-05-01 19:08:48 +02:00
{
return m_showSeamline;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetShowSeamLine(bool value)
2020-05-01 19:08:48 +02:00
{
m_showSeamline = value;
2020-05-05 17:40:36 +02:00
emit PropertiesChanged();
2020-05-01 19:08:48 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
bool VPPiece::GetPieceMirrored() const
2020-05-01 19:08:48 +02:00
{
return m_mirrorPiece;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetPieceMirrored(bool value)
2020-05-01 19:08:48 +02:00
{
m_mirrorPiece = value;
2020-05-05 17:40:36 +02:00
emit PropertiesChanged();
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetPosition(QPointF point)
2020-05-05 17:40:36 +02:00
{
m_transform.translate(point.x() - m_transform.dx(), point.y() - m_transform.dy());
emit PositionChanged();
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
QPointF VPPiece::GetPosition()
2020-05-05 17:40:36 +02:00
{
return QPointF(m_transform.dx(), m_transform.dy());
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetRotation(qreal angle)
2020-05-05 17:40:36 +02:00
{
2020-05-09 14:45:36 +02:00
// qreal currentAngle = GetRotation();
// qreal newAngle = angle - currentAngle;
2020-05-09 11:13:29 +02:00
2020-05-09 14:45:36 +02:00
// m_transform.rotate(newAngle);
2020-05-09 11:13:29 +02:00
2020-05-10 10:51:54 +02:00
if(not VFuzzyComparePossibleNulls(m_pieceAngle, angle))
2020-05-09 11:13:29 +02:00
{
2020-05-09 14:45:36 +02:00
m_pieceAngle = angle;
2020-05-09 11:13:29 +02:00
2020-05-09 14:45:36 +02:00
// make sure the angle is [0 <= angle < 360]
while(m_pieceAngle >= 360)
{
m_pieceAngle -= 360;
}
2020-05-09 11:13:29 +02:00
2020-05-09 14:45:36 +02:00
while(m_pieceAngle < 0)
{
m_pieceAngle += 360;
}
2020-05-09 11:13:29 +02:00
2020-05-09 14:45:36 +02:00
emit RotationChanged();
}
2020-05-01 19:08:48 +02:00
}
2020-05-05 17:40:36 +02:00
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
qreal VPPiece::GetRotation()
2020-05-05 17:40:36 +02:00
{
2020-05-09 11:13:29 +02:00
return m_pieceAngle;
// We don't use the QTransform vor now because the math behind it to retrieve the angle is not trivial.
// TODO / FIXME: we can use QTransform later for optimization
// QTransform tmpTransform = m_transform;
// tmpTransform.translate(-tmpTransform.dx(), -tmpTransform.dy()); // make sure there is only the rotation in the matrix
// qreal angle = qRadiansToDegrees(qAcos(tmpTransform.m11()));
// qCDebug(pPiece, "new angle : %f", angle);
// return angle;
2020-05-05 17:40:36 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetIsSelected(bool value)
2020-05-05 17:40:36 +02:00
{
if(m_isSelected != value)
{
m_isSelected = value;
emit SelectionChanged();
}
2020-05-05 17:40:36 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
bool VPPiece::GetIsSelected()
2020-05-05 17:40:36 +02:00
{
return m_isSelected;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetIsGrainlineEnabled(bool value)
{
m_isGrainlineEnabled = value;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
bool VPPiece::GetIsGrainlineEnabled()
{
return m_isGrainlineEnabled;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetGrainlineAngle(qreal value)
{
m_grainlineAngle = value;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
qreal VPPiece::GetGrainlineAngle()
{
return m_grainlineAngle;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetGrainline(QVector<QPointF> grainline)
{
m_grainline = grainline;
}
2020-05-05 17:40:36 +02:00
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
QVector<QPointF> VPPiece::GetGrainline()
{
return m_grainline;
}
2020-05-05 17:40:36 +02:00
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
VPPieceList* VPPiece::GetPieceList()
{
2020-05-23 15:29:57 +02:00
return m_pieceList;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:42:51 +02:00
void VPPiece::SetPieceList(VPPieceList* pieceList)
{
2020-05-23 15:29:57 +02:00
if(pieceList != m_pieceList)
{
2020-05-23 15:29:57 +02:00
m_pieceList = pieceList;
}
}