2014-08-15 12:48:11 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file visualization.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 15 8, 2014
|
|
|
|
**
|
|
|
|
** @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
|
2014-08-15 12:48:11 +02:00
|
|
|
** <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 "visualization.h"
|
|
|
|
#include "../tools/drawTools/vdrawtool.h"
|
2015-06-18 19:23:24 +02:00
|
|
|
#include "../../vpatterndb/calculator.h"
|
|
|
|
#include "../../vpatterndb/vtranslatevars.h"
|
2014-08-15 15:54:24 +02:00
|
|
|
|
|
|
|
#include <QGraphicsEllipseItem>
|
2014-08-15 12:48:11 +02:00
|
|
|
|
2014-11-24 14:03:34 +01:00
|
|
|
Q_LOGGING_CATEGORY(vVis, "v.visualization")
|
|
|
|
|
2014-08-15 12:48:11 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Visualization::Visualization(const VContainer *data)
|
2016-02-12 19:10:01 +01:00
|
|
|
:QObject(),
|
|
|
|
data(data),
|
|
|
|
factor(VDrawTool::factor),
|
|
|
|
scenePos(QPointF()),
|
|
|
|
mainColor(Qt::red),
|
|
|
|
supportColor(Qt::magenta),
|
|
|
|
lineStyle(Qt::SolidLine),
|
|
|
|
object1Id(NULL_ID),
|
|
|
|
toolTip(QString()),
|
|
|
|
mode(Mode::Creation)
|
2014-08-15 12:48:11 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Visualization::~Visualization()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-01-24 17:15:08 +01:00
|
|
|
void Visualization::setObject1Id(const quint32 &value)
|
2014-08-15 12:48:11 +02:00
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
object1Id = value;
|
2014-08-15 12:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void Visualization::setLineStyle(const Qt::PenStyle &value)
|
|
|
|
{
|
|
|
|
lineStyle = value;
|
|
|
|
InitPen();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-08-15 12:48:11 +02:00
|
|
|
void Visualization::setScenePos(const QPointF &value)
|
|
|
|
{
|
|
|
|
scenePos = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void Visualization::VisualMode(const quint32 &pointId)
|
|
|
|
{
|
2015-05-12 17:15:10 +02:00
|
|
|
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
|
2014-08-15 12:48:11 +02:00
|
|
|
SCASSERT(scene != nullptr);
|
|
|
|
|
2016-01-24 17:15:08 +01:00
|
|
|
this->object1Id = pointId;
|
2014-08-15 12:48:11 +02:00
|
|
|
this->scenePos = scene->getScenePos();
|
|
|
|
RefreshGeometry();
|
|
|
|
|
|
|
|
AddOnScene();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-08-15 12:48:11 +02:00
|
|
|
void Visualization::setMainColor(const QColor &value)
|
|
|
|
{
|
|
|
|
mainColor = value;
|
|
|
|
InitPen();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void Visualization::SetFactor(qreal factor)
|
|
|
|
{
|
2015-06-18 19:23:24 +02:00
|
|
|
CheckFactor(this->factor, factor);
|
2014-08-15 12:48:11 +02:00
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void Visualization::MousePos(const QPointF &scenePos)
|
|
|
|
{
|
|
|
|
this->scenePos = scenePos;
|
|
|
|
RefreshGeometry();
|
|
|
|
if (toolTip.isEmpty() == false)
|
|
|
|
{
|
|
|
|
emit ToolTip(toolTip);
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 15:54:24 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-18 22:11:14 +01:00
|
|
|
QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent, qreal z) const
|
2014-08-15 15:54:24 +02:00
|
|
|
{
|
|
|
|
QGraphicsEllipseItem *point = new QGraphicsEllipseItem(parent);
|
|
|
|
point->setZValue(1);
|
|
|
|
point->setBrush(QBrush(Qt::NoBrush));
|
2015-06-15 11:32:27 +02:00
|
|
|
point->setPen(QPen(color, qApp->toPixel(WidthMainLine(*Visualization::data->GetPatternUnit()))/factor));
|
2015-06-11 19:36:17 +02:00
|
|
|
point->setRect(PointRect(ToPixel(DefPointRadius/*mm*/, Unit::Mm)));
|
2015-11-25 14:45:38 +01:00
|
|
|
point->setPos(QPointF());
|
2014-08-15 15:54:24 +02:00
|
|
|
point->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
2016-03-18 22:11:14 +01:00
|
|
|
point->setZValue(z);
|
2014-08-15 15:54:24 +02:00
|
|
|
point->setVisible(false);
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QRectF Visualization::PointRect(const qreal &radius) const
|
|
|
|
{
|
2014-12-25 15:06:50 +01:00
|
|
|
QRectF rec = QRectF(0, 0, radius*2, radius*2);
|
2014-08-15 15:54:24 +02:00
|
|
|
rec.translate(-rec.center().x(), -rec.center().y());
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-02-25 20:23:16 +01:00
|
|
|
qreal Visualization::FindLength(const QString &expression, const QHash<QString, qreal *> &vars)
|
2014-08-15 15:54:24 +02:00
|
|
|
{
|
2016-02-25 20:23:16 +01:00
|
|
|
return qApp->toPixel(FindVal(expression, vars));
|
2014-08-15 15:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-02-25 20:23:16 +01:00
|
|
|
qreal Visualization::FindVal(const QString &expression, const QHash<QString, qreal *> &vars)
|
2014-08-15 15:54:24 +02:00
|
|
|
{
|
|
|
|
qreal val = 0;
|
|
|
|
if (expression.isEmpty())
|
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Replace line return with spaces for calc if exist
|
|
|
|
QString formula = expression;
|
|
|
|
formula.replace("\n", " ");
|
2015-06-18 10:49:25 +02:00
|
|
|
formula = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
|
2015-10-15 12:07:43 +02:00
|
|
|
Calculator *cal = new Calculator();
|
2016-02-25 20:23:16 +01:00
|
|
|
val = cal->EvalFormula(vars, formula);
|
2014-08-15 15:54:24 +02:00
|
|
|
delete cal;
|
|
|
|
}
|
|
|
|
catch (qmu::QmuParserError &e)
|
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
qDebug() << "\nMath parser error:\n"
|
|
|
|
<< "--------------------------------------\n"
|
|
|
|
<< "Message: " << e.GetMsg() << "\n"
|
|
|
|
<< "Expression: " << e.GetExpr() << "\n"
|
|
|
|
<< "--------------------------------------";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void Visualization::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style)
|
|
|
|
{
|
|
|
|
SCASSERT (point != nullptr);
|
|
|
|
|
|
|
|
point->setPos(pos);
|
2015-06-15 11:32:27 +02:00
|
|
|
point->setPen(QPen(color, qApp->toPixel(WidthMainLine(*Visualization::data->GetPatternUnit()))/factor, style));
|
2014-08-15 15:54:24 +02:00
|
|
|
point->setVisible(true);
|
|
|
|
}
|
2014-08-18 16:42:53 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void Visualization::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color, Qt::PenStyle style)
|
|
|
|
{
|
|
|
|
SCASSERT (lineItem != nullptr);
|
|
|
|
|
2015-06-15 11:32:27 +02:00
|
|
|
lineItem->setPen(QPen(color, qApp->toPixel(WidthHairLine(*Visualization::data->GetPatternUnit()))/factor, style));
|
2014-08-18 16:42:53 +02:00
|
|
|
lineItem->setLine(line);
|
2014-12-24 14:13:13 +01:00
|
|
|
lineItem->setVisible(true);
|
2014-08-18 16:42:53 +02:00
|
|
|
}
|
2014-10-23 10:38:57 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void Visualization::DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &path, const QColor &color,
|
|
|
|
Qt::PenStyle style, Qt::PenCapStyle cap)
|
|
|
|
{
|
|
|
|
SCASSERT (pathItem != nullptr);
|
|
|
|
|
2015-06-15 11:32:27 +02:00
|
|
|
pathItem->setPen(QPen(color, qApp->toPixel(WidthMainLine(*Visualization::data->GetPatternUnit()))/factor, style,
|
|
|
|
cap));
|
2014-10-23 10:38:57 +02:00
|
|
|
pathItem->setPath(path);
|
2014-12-24 14:13:13 +01:00
|
|
|
pathItem->setVisible(true);
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
2016-02-12 19:10:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Mode Visualization::GetMode() const
|
|
|
|
{
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void Visualization::SetMode(const Mode &value)
|
|
|
|
{
|
|
|
|
mode = value;
|
|
|
|
}
|