Visualization for VToolAlongLine.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-24 13:19:41 +03:00
parent ba7f8f0507
commit 36e90eb86b
14 changed files with 345 additions and 80 deletions

View File

@ -28,6 +28,9 @@
#include "dialogalongline.h" #include "dialogalongline.h"
#include "ui_dialogalongline.h" #include "ui_dialogalongline.h"
#include "../../visualization/vistoolalongline.h"
#include "../../tools/vabstracttool.h"
#include "../../widgets/vmaingraphicsscene.h"
#include <QPushButton> #include <QPushButton>
@ -39,7 +42,7 @@
*/ */
DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), typeLine(QString()), :DialogTool(data, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), typeLine(QString()),
formula(QString()), firstPointId(0), secondPointId(0), formulaBaseHeight(0) formula(QString()), firstPointId(0), secondPointId(0), formulaBaseHeight(0), line(nullptr), prepare(false)
{ {
ui->setupUi(this); ui->setupUi(this);
InitVariables(ui); InitVariables(ui);
@ -67,6 +70,8 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent)
this, &DialogAlongLine::PointChanged); this, &DialogAlongLine::PointChanged);
connect(ui->comboBoxSecondPoint, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged), connect(ui->comboBoxSecondPoint, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &DialogAlongLine::PointChanged); this, &DialogAlongLine::PointChanged);
line = new VisToolAlongLine(data);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -94,6 +99,18 @@ void DialogAlongLine::PointChanged()
CheckState(); CheckState();
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolAlongLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::DeployFormulaTextEdit() void DialogAlongLine::DeployFormulaTextEdit()
{ {
@ -103,6 +120,7 @@ void DialogAlongLine::DeployFormulaTextEdit()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogAlongLine::~DialogAlongLine() DialogAlongLine::~DialogAlongLine()
{ {
delete line;
delete ui; delete ui;
} }
@ -114,25 +132,39 @@ DialogAlongLine::~DialogAlongLine()
*/ */
void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type) void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type)
{ {
if (type == SceneObject::Point) if (prepare == false)// After first choose we ignore all objects
{ {
if (number == 0) if (type == SceneObject::Point)
{ {
if (ChoosedPoint(id, ui->comboBoxFirstPoint, tr("Select second point of line"))) if (number == 0)
{ {
number++; if (ChoosedPoint(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
return;
}
}
if (number == 1)
{
if (ChoosedPoint(id, ui->comboBoxSecondPoint, ""))
{
number = 0;
if (isInitialized == false)
{ {
this->setModal(true); number++;
this->show(); VMainGraphicsScene *scene = qApp->getCurrentScene();
SCASSERT(scene != nullptr);
line->VisualMode(id, scene->getScenePos());
scene->addItem(line);
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolAlongLine::SetFactor);
connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolAlongLine::MousePos);
return;
}
}
if (number == 1)
{
if (ChoosedPoint(id, ui->comboBoxSecondPoint, ""))
{
number = 0;
if (isInitialized == false)
{
line->setPoint2Id(id);
line->setMainColor(Qt::red);
line->RefreshGeometry();
prepare = true;
this->setModal(true);
this->show();
}
} }
} }
} }
@ -164,6 +196,12 @@ void DialogAlongLine::SaveData()
formula.replace("\n", " "); formula.replace("\n", " ");
firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint);
secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint);
line->setPoint1Id(firstPointId);
line->setPoint2Id(secondPointId);
line->setLength(formula);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->RefreshGeometry();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -175,6 +213,7 @@ void DialogAlongLine::SaveData()
void DialogAlongLine::setSecondPointId(const quint32 &value, const quint32 &id) void DialogAlongLine::setSecondPointId(const quint32 &value, const quint32 &id)
{ {
setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id); setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id);
line->setPoint2Id(value);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -186,6 +225,7 @@ void DialogAlongLine::setSecondPointId(const quint32 &value, const quint32 &id)
void DialogAlongLine::setFirstPointId(const quint32 &value, const quint32 &id) void DialogAlongLine::setFirstPointId(const quint32 &value, const quint32 &id)
{ {
setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id); setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id);
line->setPoint1Id(value);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -202,6 +242,7 @@ void DialogAlongLine::setFormula(const QString &value)
this->DeployFormulaTextEdit(); this->DeployFormulaTextEdit();
} }
ui->plainTextEditFormula->setPlainText(formula); ui->plainTextEditFormula->setPlainText(formula);
line->setLength(formula);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -213,6 +254,7 @@ void DialogAlongLine::setTypeLine(const QString &value)
{ {
typeLine = value; typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value); SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -31,6 +31,8 @@
#include "dialogtool.h" #include "dialogtool.h"
class VisToolAlongLine;
namespace Ui namespace Ui
{ {
class DialogAlongLine; class DialogAlongLine;
@ -75,6 +77,8 @@ public slots:
*/ */
void FormulaTextChanged(); void FormulaTextChanged();
void PointChanged(); void PointChanged();
protected:
virtual void ShowVisualization();
private: private:
Q_DISABLE_COPY(DialogAlongLine) Q_DISABLE_COPY(DialogAlongLine)
@ -101,6 +105,9 @@ private:
/** @brief formulaBaseHeight base height defined by dialogui */ /** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight; int formulaBaseHeight;
VisToolAlongLine *line;
/** @brief prepare show if we prepare show dialog after finish working with visual part of tool*/
bool prepare;
/** /**
* @brief SaveData Put dialog data in local variables * @brief SaveData Put dialog data in local variables

View File

@ -151,7 +151,7 @@ void DialogEndLine::setFormula(const QString &value)
this->DeployFormulaTextEdit(); this->DeployFormulaTextEdit();
} }
ui->plainTextEditFormula->setPlainText(formula); ui->plainTextEditFormula->setPlainText(formula);
line->setLength(data, formula); line->setLength(formula);
//QTextCursor cursor = ui->plainTextEditFormula->textCursor(); //QTextCursor cursor = ui->plainTextEditFormula->textCursor();
//cursor.insertText(value); //cursor.insertText(value);
//ui->plainTextEditFormula->setCursor(cursor); //ui->plainTextEditFormula->setCursor(cursor);
@ -207,7 +207,7 @@ void DialogEndLine::ShowDialog(bool click)
} }
this->setModal(true); this->setModal(true);
this->setAngle(line->Angle());//Show in dialog angle what user choose this->setAngle(line->Angle());//Show in dialog angle what user choose
line->setColor(Qt::red);//Now linw will be red line->setMainColor(Qt::red);//Now linw will be red
emit ToolTip(""); emit ToolTip("");
this->show(); this->show();
} }
@ -253,7 +253,7 @@ void DialogEndLine::SaveData()
basePointId = getCurrentObjectId(ui->comboBoxBasePoint); basePointId = getCurrentObjectId(ui->comboBoxBasePoint);
line->setPoint1Id(basePointId); line->setPoint1Id(basePointId);
line->setLength(data, formula); line->setLength(formula);
line->setAngle(angle); line->setAngle(angle);
line->setLineStyle(VAbstractTool::LineStyle(typeLine)); line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->RefreshGeometry(); line->RefreshGeometry();

View File

@ -567,7 +567,6 @@ quint32 DialogTool::getCurrentObjectId(QComboBox *box) const
{ {
SCASSERT(box != nullptr); SCASSERT(box != nullptr);
qint32 index = box->currentIndex(); qint32 index = box->currentIndex();
SCASSERT(index != -1);
if (index != -1) if (index != -1)
{ {
return qvariant_cast<quint32>(box->itemData(index)); return qvariant_cast<quint32>(box->itemData(index));

View File

@ -43,7 +43,8 @@ const QString VToolSpline::ToolType = QStringLiteral("simple");
* @param parent parent object. * @param parent parent object.
*/ */
VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem *parent) :VAbstractSpline(doc, data, id, parent) QGraphicsItem *parent)
:VAbstractSpline(doc, data, id, parent)
{ {
const VSpline *spl = data->GeometricObject<const VSpline *>(id); const VSpline *spl = data->GeometricObject<const VSpline *>(id);
QPainterPath path; QPainterPath path;

View File

@ -42,7 +42,8 @@ const QString VToolSplinePath::ToolType = QStringLiteral("path");
* @param parent parent object. * @param parent parent object.
*/ */
VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
QGraphicsItem *parent) :VAbstractSpline(doc, data, id, parent) QGraphicsItem *parent)
:VAbstractSpline(doc, data, id, parent)
{ {
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(id); const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(id);
QPainterPath path; QPainterPath path;

View File

@ -30,12 +30,15 @@
#include "../container/vcontainer.h" #include "../container/vcontainer.h"
#include "../widgets/vapplication.h" #include "../widgets/vapplication.h"
#include "../tools/drawTools/vdrawtool.h" #include "../tools/drawTools/vdrawtool.h"
#include "../container/calculator.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VisLine::VisLine(const VContainer *data, QGraphicsItem *parent) VisLine::VisLine(const VContainer *data, QGraphicsItem *parent)
:QObject(), QGraphicsLineItem(parent), data(data), factor(VDrawTool::factor), scenePos(QPointF()), :QObject(), QGraphicsLineItem(parent), data(data), factor(VDrawTool::factor), scenePos(QPointF()),
color(Qt::red), lineStyle(Qt::SolidLine), point1Id(0), toolTip(QString()) mainColor(Qt::red), supportColor(Qt::magenta), lineStyle(Qt::SolidLine), point1Id(0), toolTip(QString())
{} {
this->setZValue(1);// Show on top real tool
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VisLine::~VisLine() VisLine::~VisLine()
@ -52,7 +55,7 @@ void VisLine::SetFactor(qreal factor)
void VisLine::setLineStyle(const Qt::PenStyle &value) void VisLine::setLineStyle(const Qt::PenStyle &value)
{ {
lineStyle = value; lineStyle = value;
this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle)); this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -60,14 +63,59 @@ void VisLine::MousePos(const QPointF &scenePos)
{ {
this->scenePos = scenePos; this->scenePos = scenePos;
RefreshGeometry(); RefreshGeometry();
emit ToolTip(toolTip); if (toolTip.isEmpty() == false)
{
emit ToolTip(toolTip);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VisLine::setColor(const QColor &value) QRectF VisLine::PointRect()
{ {
color = value; const qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm);
this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle)); 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(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(length);
}
//---------------------------------------------------------------------------------------------------------------------
void VisLine::setMainColor(const QColor &value)
{
mainColor = value;
this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -79,7 +127,7 @@ void VisLine::setScenePos(const QPointF &value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VisLine::VisualMode(const quint32 &pointId, const QPointF &scenePos) void VisLine::VisualMode(const quint32 &pointId, const QPointF &scenePos)
{ {
this->color = Qt::black; this->mainColor = Qt::black;
this->point1Id = pointId; this->point1Id = pointId;
this->scenePos = scenePos; this->scenePos = scenePos;
RefreshGeometry(); RefreshGeometry();

View File

@ -46,8 +46,8 @@ public:
void setLineStyle(const Qt::PenStyle &value); void setLineStyle(const Qt::PenStyle &value);
virtual void RefreshGeometry()=0; virtual void RefreshGeometry()=0;
void setScenePos(const QPointF &value); void setScenePos(const QPointF &value);
void VisualMode(const quint32 &pointId, const QPointF &scenePos); virtual void VisualMode(const quint32 &pointId, const QPointF &scenePos);
void setColor(const QColor &value); void setMainColor(const QColor &value);
signals: signals:
void ToolTip(const QString &toolTip); void ToolTip(const QString &toolTip);
public slots: public slots:
@ -57,10 +57,13 @@ protected:
const VContainer *data; const VContainer *data;
qreal factor; qreal factor;
QPointF scenePos; QPointF scenePos;
QColor color; QColor mainColor;
QColor supportColor;
Qt::PenStyle lineStyle; Qt::PenStyle lineStyle;
quint32 point1Id; quint32 point1Id;
QString toolTip; QString toolTip;
QRectF PointRect();
qreal FindLength(const QString &expression);
private: private:
Q_DISABLE_COPY(VisLine) Q_DISABLE_COPY(VisLine)
}; };

View File

@ -0,0 +1,135 @@
/************************************************************************
**
** @file vistoolalongline.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 24 7, 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 "vistoolalongline.h"
#include "../container/vcontainer.h"
#include "../geometry/vpointf.h"
#include "../widgets/vapplication.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolAlongLine::VisToolAlongLine(const VContainer *data, QGraphicsItem *parent)
: VisLine(data, parent), point2Id(0), point(nullptr), lineP1(nullptr), lineP2(nullptr), line(nullptr), length(0)
{
this->mainColor = Qt::red;
this->setZValue(2);// Show on top real tool
lineP1 = InitPoint(supportColor);
lineP2 = InitPoint(supportColor);
line = new QGraphicsLineItem(this);
line->setVisible(false);
line->setPen(QPen(supportColor, qApp->toPixel(qApp->widthHairLine())/factor));
line->setZValue(1);
line->setFlags(QGraphicsItem::ItemStacksBehindParent);
point = InitPoint(mainColor);
}
//---------------------------------------------------------------------------------------------------------------------
VisToolAlongLine::~VisToolAlongLine()
{}
//---------------------------------------------------------------------------------------------------------------------
void VisToolAlongLine::setPoint2Id(const quint32 &value)
{
point2Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolAlongLine::setLength(const QString &expression)
{
length = FindLength(expression);
}
//---------------------------------------------------------------------------------------------------------------------
QGraphicsEllipseItem *VisToolAlongLine::InitPoint(const QColor &color)
{
QGraphicsEllipseItem *point = new QGraphicsEllipseItem(this);
point->setVisible(false);
point->setZValue(1);
point->setBrush(QBrush(Qt::NoBrush));
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
point->setRect(PointRect());
return point;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolAlongLine::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,
Qt::PenStyle style)
{
SCASSERT (lineItem != nullptr);
lineItem->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, style));
lineItem->setLine(line);
lineItem->setVisible(true);
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolAlongLine::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color)
{
SCASSERT (point != nullptr);
point->setPos(pos);
point->setVisible(true);
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolAlongLine::RefreshGeometry()
{
if (point1Id > 0)
{
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
DrawPoint(lineP1, first->toQPointF(), supportColor);
if (point2Id <= 0)
{
DrawLine(line, QLineF(first->toQPointF(), scenePos), supportColor);
}
if (point2Id > 0)
{
const VPointF *second = data->GeometricObject<const VPointF *>(point2Id);
DrawPoint(lineP2, second->toQPointF(), supportColor);
DrawLine(line, QLineF(first->toQPointF(), second->toQPointF()), supportColor);
if (qFuzzyCompare(1 + length, 1 + 0) == false)
{
QLineF mainLine = QLineF();
mainLine.setP1(first->toQPointF());
mainLine.setAngle(line->line().angle());
mainLine.setLength(length);
DrawLine(this, mainLine, mainColor, lineStyle);
DrawPoint(point, mainLine.p2(), mainColor);
}
}
}
}

View File

@ -0,0 +1,60 @@
/************************************************************************
**
** @file vistoolalongline.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 24 7, 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 VISTOOLALONGLINE_H
#define VISTOOLALONGLINE_H
#include "visline.h"
class VContainer;
class VisToolAlongLine :public VisLine
{
Q_OBJECT
public:
VisToolAlongLine(const VContainer *data, QGraphicsItem *parent = 0);
virtual ~VisToolAlongLine();
virtual void RefreshGeometry();
void setPoint2Id(const quint32 &value);
void setLength(const QString &expression);
private:
Q_DISABLE_COPY(VisToolAlongLine)
quint32 point2Id;
QGraphicsEllipseItem *point;
QGraphicsEllipseItem *lineP1;
QGraphicsEllipseItem *lineP2;
QGraphicsLineItem *line;
qreal length;
QGraphicsEllipseItem *InitPoint(const QColor &mainColor);
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);
};
#endif // VISTOOLALONGLINE_H

View File

@ -31,7 +31,6 @@
#include "../container/vcontainer.h" #include "../container/vcontainer.h"
#include "../widgets/vapplication.h" #include "../widgets/vapplication.h"
#include "../tools/vabstracttool.h" #include "../tools/vabstracttool.h"
#include "../container/calculator.h"
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QtMath> #include <QtMath>
@ -40,19 +39,14 @@
VisToolEndLine::VisToolEndLine(const VContainer *data, QGraphicsItem *parent) VisToolEndLine::VisToolEndLine(const VContainer *data, QGraphicsItem *parent)
: VisLine(data, parent), length(0), angle(0), point(nullptr) : VisLine(data, parent), length(0), angle(0), point(nullptr)
{ {
this->color = Qt::red; this->mainColor = Qt::red;
this->setZValue(1);// Show on top real tool
point = new QGraphicsEllipseItem(this); point = new QGraphicsEllipseItem(this);
point->setVisible(false); point->setVisible(false);
point->setZValue(1); point->setZValue(1);
point->setBrush(QBrush(Qt::NoBrush)); point->setBrush(QBrush(Qt::NoBrush));
point->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor)); point->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor));
point->setRect(PointRect());
const qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm);
QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor);
rec.translate(-rec.center().x(), -rec.center().y());
point->setRect(rec);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -63,7 +57,7 @@ VisToolEndLine::~VisToolEndLine()
void VisToolEndLine::RefreshGeometry() void VisToolEndLine::RefreshGeometry()
{ {
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id); const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle)); this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
QLineF line; QLineF line;
if (qFuzzyCompare(1 + length, 1 + 0)) if (qFuzzyCompare(1 + length, 1 + 0))
{ {
@ -91,12 +85,12 @@ void VisToolEndLine::RefreshGeometry()
{ {
line = QLineF(); line = QLineF();
line.setP1(first->toQPointF()); line.setP1(first->toQPointF());
line.setLength(qApp->toPixel(length)); line.setLength(length);
line.setAngle(angle); line.setAngle(angle);
point->setPos(line.p2()); point->setPos(line.p2());
point->setVisible(true); point->setVisible(true);
point->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor)); point->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor));
} }
this->setLine(line); this->setLine(line);
toolTip = QString(tr("<b>Point at distance and angle</b>: angle = %1°; <b>Shift</b> - sticking angle, " toolTip = QString(tr("<b>Point at distance and angle</b>: angle = %1°; <b>Shift</b> - sticking angle, "
@ -106,7 +100,7 @@ void VisToolEndLine::RefreshGeometry()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VisToolEndLine::VisualMode(const quint32 &pointId, const QPointF &scenePos) void VisToolEndLine::VisualMode(const quint32 &pointId, const QPointF &scenePos)
{ {
this->color = Qt::black; this->mainColor = Qt::black;
this->point1Id = pointId; this->point1Id = pointId;
this->scenePos = scenePos; this->scenePos = scenePos;
RefreshGeometry(); RefreshGeometry();
@ -158,34 +152,7 @@ void VisToolEndLine::setAngle(const qreal &value)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VisToolEndLine::setLength(const VContainer *data, const QString &expression) void VisToolEndLine::setLength(const QString &expression)
{ {
SCASSERT(data != nullptr); length = FindLength(expression);
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(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"
<< "--------------------------------------";
}
}
} }

View File

@ -44,7 +44,7 @@ public:
void VisualMode(const quint32 &pointId, const QPointF &scenePos); void VisualMode(const quint32 &pointId, const QPointF &scenePos);
qreal Angle() const; qreal Angle() const;
void setAngle(const qreal &value); void setAngle(const qreal &value);
void setLength(const VContainer *data, const QString &expression); void setLength(const QString &expression);
private: private:
Q_DISABLE_COPY(VisToolEndLine) Q_DISABLE_COPY(VisToolEndLine)
qreal CorrectAngle(const qreal &angle) const; qreal CorrectAngle(const qreal &angle) const;

View File

@ -36,7 +36,7 @@
VisToolLine::VisToolLine(const VContainer *data, QGraphicsItem *parent) VisToolLine::VisToolLine(const VContainer *data, QGraphicsItem *parent)
:VisLine(data, parent), point2Id(0) :VisLine(data, parent), point2Id(0)
{ {
this->color = Qt::red; this->mainColor = Qt::red;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -56,7 +56,7 @@ void VisToolLine::RefreshGeometry()
const VPointF *second = data->GeometricObject<const VPointF *>(point2Id); const VPointF *second = data->GeometricObject<const VPointF *>(point2Id);
this->setLine(QLineF(first->toQPointF(), second->toQPointF())); this->setLine(QLineF(first->toQPointF(), second->toQPointF()));
} }
this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle)); this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -5,7 +5,8 @@ HEADERS += \
visualization/vsimplecurve.h \ visualization/vsimplecurve.h \
visualization/visline.h \ visualization/visline.h \
visualization/vistoolline.h \ visualization/vistoolline.h \
visualization/vistoolendline.h visualization/vistoolendline.h \
visualization/vistoolalongline.h
SOURCES += \ SOURCES += \
visualization/vgraphicssimpletextitem.cpp \ visualization/vgraphicssimpletextitem.cpp \
@ -14,4 +15,5 @@ SOURCES += \
visualization/vsimplecurve.cpp \ visualization/vsimplecurve.cpp \
visualization/visline.cpp \ visualization/visline.cpp \
visualization/vistoolline.cpp \ visualization/vistoolline.cpp \
visualization/vistoolendline.cpp visualization/vistoolendline.cpp \
visualization/vistoolalongline.cpp