Visualization for VToolArc.
--HG-- branch : develop
This commit is contained in:
parent
198b73a40f
commit
3546c2a557
|
@ -35,6 +35,7 @@
|
|||
#include "../../geometry/vpointf.h"
|
||||
#include "../../container/vcontainer.h"
|
||||
#include "../../xml/vdomdocument.h"
|
||||
#include "../../visualization/vistoolarc.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
|
@ -45,7 +46,7 @@
|
|||
DialogArc::DialogArc(const VContainer *data, const quint32 &toolId, QWidget *parent)
|
||||
:DialogTool(data, toolId, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false),
|
||||
timerRadius(nullptr), timerF1(nullptr), timerF2(nullptr), center(0), radius(QString()), f1(QString()),
|
||||
f2(QString()), formulaBaseHeight(0), formulaBaseHeightF1(0), formulaBaseHeightF2(0)
|
||||
f2(QString()), formulaBaseHeight(0), formulaBaseHeightF1(0), formulaBaseHeightF2(0), path(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
@ -86,6 +87,8 @@ DialogArc::DialogArc(const VContainer *data, const quint32 &toolId, QWidget *par
|
|||
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogArc::DeployFormulaTextEdit);
|
||||
connect(ui->pushButtonGrowLengthF1, &QPushButton::clicked, this, &DialogArc::DeployF1TextEdit);
|
||||
connect(ui->pushButtonGrowLengthF2, &QPushButton::clicked, this, &DialogArc::DeployF2TextEdit);
|
||||
|
||||
path = new VisToolArc(data);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -109,6 +112,7 @@ void DialogArc::DeployF2TextEdit()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DialogArc::~DialogArc()
|
||||
{
|
||||
delete path;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
@ -121,6 +125,7 @@ void DialogArc::SetCenter(const quint32 &value)
|
|||
{
|
||||
center = value;
|
||||
ChangeCurrentData(ui->comboBoxBasePoint, center);
|
||||
path->setPoint1Id(center);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -137,6 +142,7 @@ void DialogArc::SetF2(const QString &value)
|
|||
this->DeployF2TextEdit();
|
||||
}
|
||||
ui->plainTextEditF2->setPlainText(f2);
|
||||
path->setF2(f2);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -153,6 +159,7 @@ void DialogArc::SetF1(const QString &value)
|
|||
this->DeployF1TextEdit();
|
||||
}
|
||||
ui->plainTextEditF1->setPlainText(f1);
|
||||
path->setF1(f1);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -169,6 +176,7 @@ void DialogArc::SetRadius(const QString &value)
|
|||
this->DeployFormulaTextEdit();
|
||||
}
|
||||
ui->plainTextEditFormula->setPlainText(radius);
|
||||
path->setRadius(radius);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -184,12 +192,26 @@ void DialogArc::ChosenObject(quint32 id, const SceneObject &type)
|
|||
const VPointF *point = data->GeometricObject<const VPointF *>(id);
|
||||
|
||||
ChangeCurrentText(ui->comboBoxBasePoint, point->name());
|
||||
path->VisualMode(id);
|
||||
prepare = true;
|
||||
emit ToolTip("");
|
||||
this->setModal(true);
|
||||
this->show();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogArc::ShowVisualization()
|
||||
{
|
||||
if (prepare == false)
|
||||
{
|
||||
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
||||
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
|
||||
scene->addItem(path);
|
||||
path->RefreshGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogArc::SaveData()
|
||||
{
|
||||
|
@ -200,6 +222,12 @@ void DialogArc::SaveData()
|
|||
f2 = ui->plainTextEditF2->toPlainText();
|
||||
f2.replace("\n", " ");
|
||||
center = getCurrentObjectId(ui->comboBoxBasePoint);
|
||||
|
||||
path->setPoint1Id(center);
|
||||
path->setRadius(radius);
|
||||
path->setF1(f1);
|
||||
path->setF2(f2);
|
||||
path->RefreshGeometry();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace Ui
|
|||
class DialogArc;
|
||||
}
|
||||
|
||||
class VisToolArc;
|
||||
|
||||
/**
|
||||
* @brief The DialogArc class dialog for ToolArc. Help create arc and edit option.
|
||||
*/
|
||||
|
@ -76,6 +78,7 @@ public slots:
|
|||
void F2Changed();
|
||||
protected:
|
||||
virtual void CheckState();
|
||||
virtual void ShowVisualization();
|
||||
/**
|
||||
* @brief SaveData Put dialog data in local variables
|
||||
*/
|
||||
|
@ -121,6 +124,8 @@ private:
|
|||
int formulaBaseHeightF1;
|
||||
int formulaBaseHeightF2;
|
||||
|
||||
VisToolArc *path;
|
||||
|
||||
void EvalRadius();
|
||||
void EvalF1();
|
||||
void EvalF2();
|
||||
|
|
|
@ -108,7 +108,6 @@ void DialogShoulderPoint::PointNameChanged()
|
|||
CheckState();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogShoulderPoint::ShowVisualization()
|
||||
{
|
||||
|
|
|
@ -62,6 +62,17 @@ VArc::VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QStri
|
|||
_name = QString (arc_+"%1").arg(this->GetCenter().name());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VArc::VArc(VPointF center, qreal radius, qreal f1, qreal f2)
|
||||
: VAbstractCurve(GOType::Arc, 0, Draw::Calculation), f1(f1), formulaF1(QStringLiteral("")), f2(f2),
|
||||
formulaF2(QStringLiteral("")), radius(radius), formulaRadius(QStringLiteral("")), center(center)
|
||||
{
|
||||
_name = QString (arc_+"%1").arg(this->GetCenter().name());
|
||||
formulaF1 = QString("%1").arg(f1);
|
||||
formulaF2 = QString("%1").arg(f2);
|
||||
formulaRadius = QString("%1").arg(radius);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief VArc copy constructor
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
VArc ();
|
||||
VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2,
|
||||
QString formulaF2, quint32 idObject = 0, Draw mode = Draw::Calculation);
|
||||
VArc (VPointF center, qreal radius, qreal f1, qreal f2);
|
||||
VArc(const VArc &arc);
|
||||
VArc& operator= (const VArc &arc);
|
||||
QString GetFormulaF1 () const;
|
||||
|
|
|
@ -27,9 +27,7 @@
|
|||
*************************************************************************/
|
||||
|
||||
#include "visline.h"
|
||||
#include "../container/vcontainer.h"
|
||||
#include "../tools/drawTools/vdrawtool.h"
|
||||
#include "../container/calculator.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisLine::VisLine(const VContainer *data, QGraphicsItem *parent)
|
||||
|
@ -43,81 +41,6 @@ VisLine::VisLine(const VContainer *data, QGraphicsItem *parent)
|
|||
VisLine::~VisLine()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QRectF VisLine::PointRect(const qreal &radius)
|
||||
{
|
||||
QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor);
|
||||
rec.translate(-rec.center().x(), -rec.center().y());
|
||||
return rec;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal VisLine::FindLength(const QString &expression)
|
||||
{
|
||||
qreal length = 0;
|
||||
if (expression.isEmpty())
|
||||
{
|
||||
length = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
// Replace line return with spaces for calc if exist
|
||||
QString formula = expression;
|
||||
formula.replace("\n", " ");
|
||||
formula = qApp->FormulaFromUser(formula);
|
||||
Calculator *cal = new Calculator(Visualization::data);
|
||||
length = cal->EvalFormula(formula);
|
||||
delete cal;
|
||||
}
|
||||
catch (qmu::QmuParserError &e)
|
||||
{
|
||||
length = 0;
|
||||
qDebug() << "\nMath parser error:\n"
|
||||
<< "--------------------------------------\n"
|
||||
<< "Message: " << e.GetMsg() << "\n"
|
||||
<< "Expression: " << e.GetExpr() << "\n"
|
||||
<< "--------------------------------------";
|
||||
}
|
||||
}
|
||||
return qApp->toPixel(FindVal(expression));
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal VisLine::FindVal(const QString &expression)
|
||||
{
|
||||
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", " ");
|
||||
formula = qApp->FormulaFromUser(formula);
|
||||
Calculator *cal = new Calculator(Visualization::data);
|
||||
val = cal->EvalFormula(formula);
|
||||
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 VisLine::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color, Qt::PenStyle style)
|
||||
{
|
||||
|
@ -127,16 +50,6 @@ void VisLine::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QC
|
|||
lineItem->setLine(line);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisLine::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style)
|
||||
{
|
||||
SCASSERT (point != nullptr);
|
||||
|
||||
point->setPos(pos);
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor, style));
|
||||
point->setVisible(true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QLineF VisLine::Line(const QPointF &p1, const qreal &length, const qreal &angle)
|
||||
{
|
||||
|
@ -147,19 +60,6 @@ QLineF VisLine::Line(const QPointF &p1, const qreal &length, const qreal &angle)
|
|||
return line;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QGraphicsEllipseItem *VisLine::InitPoint(const QColor &color)
|
||||
{
|
||||
QGraphicsEllipseItem *point = new QGraphicsEllipseItem(this);
|
||||
point->setZValue(1);
|
||||
point->setBrush(QBrush(Qt::NoBrush));
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
|
||||
point->setRect(PointRect(qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm)));
|
||||
point->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
||||
point->setVisible(false);
|
||||
return point;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal VisLine::CorrectAngle(const qreal &angle) const
|
||||
{
|
||||
|
|
|
@ -43,16 +43,10 @@ public:
|
|||
virtual ~VisLine();
|
||||
|
||||
protected:
|
||||
QRectF PointRect(const qreal &radius);
|
||||
qreal FindLength(const QString &expression);
|
||||
qreal FindVal(const QString &expression);
|
||||
void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,
|
||||
void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,
|
||||
Qt::PenStyle style = Qt::SolidLine);
|
||||
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color,
|
||||
Qt::PenStyle style = Qt::SolidLine);
|
||||
QLineF Line(const QPointF &p1, const qreal& length, const qreal &angle);
|
||||
|
||||
QGraphicsEllipseItem *InitPoint(const QColor &color);
|
||||
template <class Item>
|
||||
Item *InitItem(const QColor &color)
|
||||
{
|
||||
|
|
62
src/app/visualization/vispath.cpp
Normal file
62
src/app/visualization/vispath.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vispath.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.
|
||||
** Copyright (C) 2014 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 "vispath.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisPath::VisPath(const VContainer *data, QGraphicsItem *parent)
|
||||
:Visualization(data), QGraphicsPathItem(parent)
|
||||
{
|
||||
this->setZValue(1);// Show on top real tool
|
||||
InitPen();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisPath::~VisPath()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisPath::InitPen()
|
||||
{
|
||||
this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisPath::AddOnScene()
|
||||
{
|
||||
AddItem(this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisPath::DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &path, const QColor &color, Qt::PenStyle style)
|
||||
{
|
||||
SCASSERT (pathItem != nullptr);
|
||||
|
||||
pathItem->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, style));
|
||||
pathItem->setPath(path);
|
||||
}
|
52
src/app/visualization/vispath.h
Normal file
52
src/app/visualization/vispath.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vispath.h
|
||||
** @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.
|
||||
** Copyright (C) 2014 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/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef VISPATH_H
|
||||
#define VISPATH_H
|
||||
|
||||
#include "visualization.h"
|
||||
#include <QGraphicsPathItem>
|
||||
|
||||
class VisPath : public Visualization, public QGraphicsPathItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VisPath(const VContainer *data, QGraphicsItem *parent = 0);
|
||||
virtual ~VisPath();
|
||||
|
||||
protected:
|
||||
virtual void InitPen();
|
||||
virtual void AddOnScene();
|
||||
|
||||
void DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &path, const QColor &color,
|
||||
Qt::PenStyle style = Qt::SolidLine);
|
||||
private:
|
||||
Q_DISABLE_COPY(VisPath)
|
||||
};
|
||||
|
||||
#endif // VISPATH_H
|
|
@ -37,10 +37,10 @@ VisToolAlongLine::VisToolAlongLine(const VContainer *data, QGraphicsItem *parent
|
|||
this->mainColor = Qt::red;
|
||||
this->setZValue(2);// Show on top real tool
|
||||
|
||||
lineP1 = InitPoint(supportColor);
|
||||
lineP2 = InitPoint(supportColor);
|
||||
lineP1 = InitPoint(supportColor, this);
|
||||
lineP2 = InitPoint(supportColor, this);
|
||||
line = InitItem<QGraphicsLineItem>(supportColor);
|
||||
point = InitPoint(mainColor);
|
||||
point = InitPoint(mainColor, this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
77
src/app/visualization/vistoolarc.cpp
Normal file
77
src/app/visualization/vistoolarc.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vistoolarc.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.
|
||||
** Copyright (C) 2014 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 "vistoolarc.h"
|
||||
#include "../geometry/vpointf.h"
|
||||
#include "../geometry/varc.h"
|
||||
#include "../container/vcontainer.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolArc::VisToolArc(const VContainer *data, QGraphicsItem *parent)
|
||||
:VisPath(data, parent), arcCenter(nullptr), radius(0), f1(0), f2(0)
|
||||
{
|
||||
arcCenter = InitPoint(mainColor, this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolArc::~VisToolArc()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolArc::RefreshGeometry()
|
||||
{
|
||||
if (point1Id > 0)
|
||||
{
|
||||
const VPointF *first = Visualization::data->GeometricObject<const VPointF *>(point1Id);
|
||||
DrawPoint(arcCenter, first->toQPointF(), supportColor);
|
||||
|
||||
if (qFuzzyCompare(1 + radius, 1 + 0) == false && f1 >= 0 && f2 >= 0 && qFuzzyCompare(1 + f1, 1 + f2) == false)
|
||||
{
|
||||
VArc arc = VArc (*first, radius, f1, f2);
|
||||
DrawPath(this, arc.GetPath(), mainColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolArc::setRadius(const QString &expression)
|
||||
{
|
||||
radius = FindLength(expression);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolArc::setF1(const QString &expression)
|
||||
{
|
||||
f1 = FindVal(expression);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolArc::setF2(const QString &expression)
|
||||
{
|
||||
f2 = FindVal(expression);
|
||||
}
|
54
src/app/visualization/vistoolarc.h
Normal file
54
src/app/visualization/vistoolarc.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vistoolarc.h
|
||||
** @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.
|
||||
** Copyright (C) 2014 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/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef VISTOOLARC_H
|
||||
#define VISTOOLARC_H
|
||||
|
||||
|
||||
#include "vispath.h"
|
||||
|
||||
class VisToolArc : public VisPath
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VisToolArc(const VContainer *data, QGraphicsItem *parent = 0);
|
||||
virtual ~VisToolArc();
|
||||
|
||||
virtual void RefreshGeometry();
|
||||
void setRadius(const QString &expression);
|
||||
void setF1(const QString &expression);
|
||||
void setF2(const QString &expression);
|
||||
private:
|
||||
Q_DISABLE_COPY(VisToolArc)
|
||||
QGraphicsEllipseItem *arcCenter;
|
||||
qreal radius;
|
||||
qreal f1;
|
||||
qreal f2;
|
||||
};
|
||||
|
||||
#endif // VISTOOLARC_H
|
|
@ -36,14 +36,14 @@ VisToolBisector::VisToolBisector(const VContainer *data, QGraphicsItem *parent)
|
|||
:VisLine(data, parent), point2Id(0), point3Id(0), point(nullptr), line1P1(nullptr), line1P2(nullptr),
|
||||
line1(nullptr), line2P2(nullptr), line2(nullptr), length(0)
|
||||
{
|
||||
line1P1 = InitPoint(supportColor);
|
||||
line1P2 = InitPoint(supportColor);
|
||||
line1P1 = InitPoint(supportColor, this);
|
||||
line1P2 = InitPoint(supportColor, this);
|
||||
line1 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
line2P2 = InitPoint(supportColor);
|
||||
line2P2 = InitPoint(supportColor, this);
|
||||
line2 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
point = InitPoint(mainColor, this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -40,7 +40,7 @@ VisToolEndLine::VisToolEndLine(const VContainer *data, QGraphicsItem *parent)
|
|||
{
|
||||
this->mainColor = Qt::red;
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
point = InitPoint(mainColor, this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -35,13 +35,13 @@ VisToolHeight::VisToolHeight(const VContainer *data, QGraphicsItem *parent)
|
|||
: VisLine(data, parent), lineP1Id(0), lineP2Id(0), point(nullptr), base_point(nullptr), lineP1(nullptr),
|
||||
lineP2(nullptr), line(nullptr), line_intersection(nullptr)
|
||||
{
|
||||
base_point = InitPoint(supportColor);
|
||||
lineP1 = InitPoint(supportColor);
|
||||
lineP2 = InitPoint(supportColor);
|
||||
base_point = InitPoint(supportColor, this);
|
||||
lineP1 = InitPoint(supportColor, this);
|
||||
lineP2 = InitPoint(supportColor, this);
|
||||
line = InitItem<QGraphicsLineItem>(supportColor);
|
||||
line_intersection = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
point = InitPoint(mainColor, this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -35,14 +35,14 @@ VisToolLineIntersect::VisToolLineIntersect(const VContainer *data, QGraphicsItem
|
|||
:VisLine(data, parent), line1P2Id(0), line2P1Id(0), line2P2Id(0), point(nullptr), line1P1(nullptr),
|
||||
line1P2(nullptr), line1(nullptr), line2P1(nullptr), line2P2(nullptr)
|
||||
{
|
||||
line1P1 = InitPoint(supportColor);
|
||||
line1P2 = InitPoint(supportColor);
|
||||
line1P1 = InitPoint(supportColor, this);
|
||||
line1P2 = InitPoint(supportColor, this);
|
||||
line1 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
line2P1 = InitPoint(supportColor);
|
||||
line2P2 = InitPoint(supportColor);
|
||||
line2P1 = InitPoint(supportColor, this);
|
||||
line2P2 = InitPoint(supportColor, this);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
point = InitPoint(mainColor, this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -37,11 +37,11 @@ VisToolNormal::VisToolNormal(const VContainer *data, QGraphicsItem *parent)
|
|||
{
|
||||
this->mainColor = Qt::red;
|
||||
|
||||
lineP1 = InitPoint(supportColor);
|
||||
lineP2 = InitPoint(supportColor);
|
||||
lineP1 = InitPoint(supportColor, this);
|
||||
lineP2 = InitPoint(supportColor, this);
|
||||
line = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
point = InitPoint(mainColor, this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -35,12 +35,12 @@ VisToolPointOfContact::VisToolPointOfContact(const VContainer *data, QGraphicsIt
|
|||
:VisLine(data, parent), lineP2Id(0), radiusId(0), point(nullptr), lineP1(nullptr), lineP2(nullptr),
|
||||
arc_point(nullptr), circle(nullptr), radius(0)
|
||||
{
|
||||
arc_point = InitPoint(supportColor);
|
||||
lineP1 = InitPoint(supportColor);
|
||||
lineP2 = InitPoint(supportColor);
|
||||
arc_point = InitPoint(supportColor, this);
|
||||
lineP1 = InitPoint(supportColor, this);
|
||||
lineP2 = InitPoint(supportColor, this);
|
||||
circle = InitItem<QGraphicsEllipseItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
point = InitPoint(mainColor, this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -34,11 +34,11 @@
|
|||
VisToolPointOfIntersection::VisToolPointOfIntersection(const VContainer *data, QGraphicsItem *parent)
|
||||
: VisLine(data, parent), point2Id(0), point(nullptr), axisP1(nullptr), axisP2(nullptr), axis2(nullptr)
|
||||
{
|
||||
axisP1 = InitPoint(supportColor);
|
||||
axisP2 = InitPoint(supportColor);
|
||||
axisP1 = InitPoint(supportColor, this);
|
||||
axisP2 = InitPoint(supportColor, this);
|
||||
axis2 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
point = InitPoint(mainColor, this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -35,15 +35,15 @@ VisToolShoulderPoint::VisToolShoulderPoint(const VContainer *data, QGraphicsItem
|
|||
:VisLine(data, parent), lineP1Id(0), lineP2Id(0), point(nullptr), line1P1(nullptr), line1P2(nullptr),
|
||||
line1(nullptr), line2P2(nullptr), line2(nullptr), line3(nullptr), length(0)
|
||||
{
|
||||
line1P1 = InitPoint(supportColor);
|
||||
line1P2 = InitPoint(supportColor);
|
||||
line1P1 = InitPoint(supportColor, this);
|
||||
line1P2 = InitPoint(supportColor, this);
|
||||
line1 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
line2P2 = InitPoint(supportColor);
|
||||
line2P2 = InitPoint(supportColor, this);
|
||||
line2 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
line3 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
point = InitPoint(mainColor, this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -37,15 +37,15 @@ VisToolTriangle::VisToolTriangle(const VContainer *data, QGraphicsItem *parent)
|
|||
:VisLine(data, parent), point2Id(0), hypotenuseP1Id(0), hypotenuseP2Id(0), point(nullptr), axisP1(nullptr),
|
||||
axisP2(nullptr), axis(nullptr), hypotenuseP1(nullptr), hypotenuseP2(nullptr), foot1(nullptr), foot2(nullptr)
|
||||
{
|
||||
axisP1 = InitPoint(supportColor);
|
||||
axisP2 = InitPoint(supportColor);
|
||||
axisP1 = InitPoint(supportColor, this);
|
||||
axisP2 = InitPoint(supportColor, this);
|
||||
axis = InitItem<QGraphicsPathItem>(supportColor);
|
||||
hypotenuseP1 = InitPoint(supportColor);
|
||||
hypotenuseP2 = InitPoint(supportColor);
|
||||
hypotenuseP1 = InitPoint(supportColor, this);
|
||||
hypotenuseP2 = InitPoint(supportColor, this);
|
||||
foot1 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
foot2 = InitItem<QGraphicsLineItem>(supportColor);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
point = InitPoint(mainColor, this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
|
||||
#include "visualization.h"
|
||||
#include "../tools/drawTools/vdrawtool.h"
|
||||
#include "../container/calculator.h"
|
||||
|
||||
#include <QGraphicsEllipseItem>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
Visualization::Visualization(const VContainer *data)
|
||||
|
@ -95,3 +98,73 @@ void Visualization::MousePos(const QPointF &scenePos)
|
|||
emit ToolTip(toolTip);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent) const
|
||||
{
|
||||
QGraphicsEllipseItem *point = new QGraphicsEllipseItem(parent);
|
||||
point->setZValue(1);
|
||||
point->setBrush(QBrush(Qt::NoBrush));
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
|
||||
point->setRect(PointRect(qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm)));
|
||||
point->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
||||
point->setVisible(false);
|
||||
return point;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QRectF Visualization::PointRect(const qreal &radius) const
|
||||
{
|
||||
QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor);
|
||||
rec.translate(-rec.center().x(), -rec.center().y());
|
||||
return rec;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal Visualization::FindLength(const QString &expression)
|
||||
{
|
||||
return qApp->toPixel(FindVal(expression));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal Visualization::FindVal(const QString &expression)
|
||||
{
|
||||
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", " ");
|
||||
formula = qApp->FormulaFromUser(formula);
|
||||
Calculator *cal = new Calculator(Visualization::data);
|
||||
val = cal->EvalFormula(formula);
|
||||
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);
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor, style));
|
||||
point->setVisible(true);
|
||||
}
|
||||
|
|
|
@ -67,6 +67,13 @@ protected:
|
|||
virtual void InitPen()=0;
|
||||
virtual void AddOnScene()=0;
|
||||
|
||||
QGraphicsEllipseItem *InitPoint(const QColor &color, QGraphicsItem *parent) const;
|
||||
QRectF PointRect(const qreal &radius) const;
|
||||
qreal FindLength(const QString &expression);
|
||||
qreal FindVal(const QString &expression);
|
||||
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color,
|
||||
Qt::PenStyle style = Qt::SolidLine);
|
||||
|
||||
template <typename Item>
|
||||
void AddItem(Item *item)
|
||||
{
|
||||
|
|
|
@ -15,7 +15,9 @@ HEADERS += \
|
|||
visualization/vistooltriangle.h \
|
||||
visualization/vistoolpointofcontact.h \
|
||||
visualization/vistoollineintersect.h \
|
||||
visualization/visualization.h
|
||||
visualization/visualization.h \
|
||||
visualization/vistoolarc.h \
|
||||
visualization/vispath.h
|
||||
|
||||
SOURCES += \
|
||||
visualization/vgraphicssimpletextitem.cpp \
|
||||
|
@ -34,4 +36,6 @@ SOURCES += \
|
|||
visualization/vistooltriangle.cpp \
|
||||
visualization/vistoolpointofcontact.cpp \
|
||||
visualization/vistoollineintersect.cpp \
|
||||
visualization/visualization.cpp
|
||||
visualization/visualization.cpp \
|
||||
visualization/vistoolarc.cpp \
|
||||
visualization/vispath.cpp
|
||||
|
|
Loading…
Reference in New Issue
Block a user