From 3546c2a55713db52f44ef10a9e0f070cba184406 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 15 Aug 2014 16:54:24 +0300 Subject: [PATCH] Visualization for VToolArc. --HG-- branch : develop --- src/app/dialogs/tools/dialogarc.cpp | 30 +++++- src/app/dialogs/tools/dialogarc.h | 5 + src/app/dialogs/tools/dialogshoulderpoint.cpp | 1 - src/app/geometry/varc.cpp | 11 ++ src/app/geometry/varc.h | 1 + src/app/visualization/visline.cpp | 100 ------------------ src/app/visualization/visline.h | 8 +- src/app/visualization/vispath.cpp | 62 +++++++++++ src/app/visualization/vispath.h | 52 +++++++++ src/app/visualization/vistoolalongline.cpp | 6 +- src/app/visualization/vistoolarc.cpp | 77 ++++++++++++++ src/app/visualization/vistoolarc.h | 54 ++++++++++ src/app/visualization/vistoolbisector.cpp | 8 +- src/app/visualization/vistoolendline.cpp | 2 +- src/app/visualization/vistoolheight.cpp | 8 +- .../visualization/vistoollineintersect.cpp | 10 +- src/app/visualization/vistoolnormal.cpp | 6 +- .../visualization/vistoolpointofcontact.cpp | 8 +- .../vistoolpointofintersection.cpp | 6 +- .../visualization/vistoolshoulderpoint.cpp | 8 +- src/app/visualization/vistooltriangle.cpp | 10 +- src/app/visualization/visualization.cpp | 73 +++++++++++++ src/app/visualization/visualization.h | 7 ++ src/app/visualization/visualization.pri | 8 +- 24 files changed, 414 insertions(+), 147 deletions(-) create mode 100644 src/app/visualization/vispath.cpp create mode 100644 src/app/visualization/vispath.h create mode 100644 src/app/visualization/vistoolarc.cpp create mode 100644 src/app/visualization/vistoolarc.h diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index f79600cc4..aa05e25c4 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -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(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(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogarc.h b/src/app/dialogs/tools/dialogarc.h index c97f0b51a..823d7f69f 100644 --- a/src/app/dialogs/tools/dialogarc.h +++ b/src/app/dialogs/tools/dialogarc.h @@ -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(); diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index dbdc200d9..2f6cc298c 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -108,7 +108,6 @@ void DialogShoulderPoint::PointNameChanged() CheckState(); } - //--------------------------------------------------------------------------------------------------------------------- void DialogShoulderPoint::ShowVisualization() { diff --git a/src/app/geometry/varc.cpp b/src/app/geometry/varc.cpp index 558493191..95f599b19 100644 --- a/src/app/geometry/varc.cpp +++ b/src/app/geometry/varc.cpp @@ -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 diff --git a/src/app/geometry/varc.h b/src/app/geometry/varc.h index 7a8852cc7..5acd5830e 100644 --- a/src/app/geometry/varc.h +++ b/src/app/geometry/varc.h @@ -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; diff --git a/src/app/visualization/visline.cpp b/src/app/visualization/visline.cpp index 216ded754..f9e20fda0 100644 --- a/src/app/visualization/visline.cpp +++ b/src/app/visualization/visline.cpp @@ -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 { diff --git a/src/app/visualization/visline.h b/src/app/visualization/visline.h index cc0d0db60..5a360747d 100644 --- a/src/app/visualization/visline.h +++ b/src/app/visualization/visline.h @@ -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 Item *InitItem(const QColor &color) { diff --git a/src/app/visualization/vispath.cpp b/src/app/visualization/vispath.cpp new file mode 100644 index 000000000..de449d555 --- /dev/null +++ b/src/app/visualization/vispath.cpp @@ -0,0 +1,62 @@ +/************************************************************************ + ** + ** @file vispath.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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); +} diff --git a/src/app/visualization/vispath.h b/src/app/visualization/vispath.h new file mode 100644 index 000000000..e9bb8ddd6 --- /dev/null +++ b/src/app/visualization/vispath.h @@ -0,0 +1,52 @@ +/************************************************************************ + ** + ** @file vispath.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#ifndef VISPATH_H +#define VISPATH_H + +#include "visualization.h" +#include + +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 diff --git a/src/app/visualization/vistoolalongline.cpp b/src/app/visualization/vistoolalongline.cpp index 2ceacbe2d..9e8b6b4e8 100644 --- a/src/app/visualization/vistoolalongline.cpp +++ b/src/app/visualization/vistoolalongline.cpp @@ -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(supportColor); - point = InitPoint(mainColor); + point = InitPoint(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolarc.cpp b/src/app/visualization/vistoolarc.cpp new file mode 100644 index 000000000..bf2edf31e --- /dev/null +++ b/src/app/visualization/vistoolarc.cpp @@ -0,0 +1,77 @@ +/************************************************************************ + ** + ** @file vistoolarc.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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(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); +} diff --git a/src/app/visualization/vistoolarc.h b/src/app/visualization/vistoolarc.h new file mode 100644 index 000000000..3c06737c8 --- /dev/null +++ b/src/app/visualization/vistoolarc.h @@ -0,0 +1,54 @@ +/************************************************************************ + ** + ** @file vistoolarc.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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 diff --git a/src/app/visualization/vistoolbisector.cpp b/src/app/visualization/vistoolbisector.cpp index bae67c682..3e7d07171 100644 --- a/src/app/visualization/vistoolbisector.cpp +++ b/src/app/visualization/vistoolbisector.cpp @@ -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(supportColor); - line2P2 = InitPoint(supportColor); + line2P2 = InitPoint(supportColor, this); line2 = InitItem(supportColor); - point = InitPoint(mainColor); + point = InitPoint(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolendline.cpp b/src/app/visualization/vistoolendline.cpp index 3195b07b8..865f3e2c1 100644 --- a/src/app/visualization/vistoolendline.cpp +++ b/src/app/visualization/vistoolendline.cpp @@ -40,7 +40,7 @@ VisToolEndLine::VisToolEndLine(const VContainer *data, QGraphicsItem *parent) { this->mainColor = Qt::red; - point = InitPoint(mainColor); + point = InitPoint(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolheight.cpp b/src/app/visualization/vistoolheight.cpp index 39b84c10a..7991a4c34 100644 --- a/src/app/visualization/vistoolheight.cpp +++ b/src/app/visualization/vistoolheight.cpp @@ -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(supportColor); line_intersection = InitItem(supportColor); - point = InitPoint(mainColor); + point = InitPoint(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoollineintersect.cpp b/src/app/visualization/vistoollineintersect.cpp index 838bce2ed..4243df7d2 100644 --- a/src/app/visualization/vistoollineintersect.cpp +++ b/src/app/visualization/vistoollineintersect.cpp @@ -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(supportColor); - line2P1 = InitPoint(supportColor); - line2P2 = InitPoint(supportColor); + line2P1 = InitPoint(supportColor, this); + line2P2 = InitPoint(supportColor, this); - point = InitPoint(mainColor); + point = InitPoint(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolnormal.cpp b/src/app/visualization/vistoolnormal.cpp index a1b8ee4f3..a95a8302b 100644 --- a/src/app/visualization/vistoolnormal.cpp +++ b/src/app/visualization/vistoolnormal.cpp @@ -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(supportColor); - point = InitPoint(mainColor); + point = InitPoint(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolpointofcontact.cpp b/src/app/visualization/vistoolpointofcontact.cpp index f8468f058..5930b9310 100644 --- a/src/app/visualization/vistoolpointofcontact.cpp +++ b/src/app/visualization/vistoolpointofcontact.cpp @@ -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(supportColor); - point = InitPoint(mainColor); + point = InitPoint(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolpointofintersection.cpp b/src/app/visualization/vistoolpointofintersection.cpp index 080bb31fe..31131b120 100644 --- a/src/app/visualization/vistoolpointofintersection.cpp +++ b/src/app/visualization/vistoolpointofintersection.cpp @@ -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(supportColor); - point = InitPoint(mainColor); + point = InitPoint(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolshoulderpoint.cpp b/src/app/visualization/vistoolshoulderpoint.cpp index fe7721e36..85d3978d7 100644 --- a/src/app/visualization/vistoolshoulderpoint.cpp +++ b/src/app/visualization/vistoolshoulderpoint.cpp @@ -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(supportColor); - line2P2 = InitPoint(supportColor); + line2P2 = InitPoint(supportColor, this); line2 = InitItem(supportColor); line3 = InitItem(supportColor); - point = InitPoint(mainColor); + point = InitPoint(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistooltriangle.cpp b/src/app/visualization/vistooltriangle.cpp index 1e580fbea..b61ed7a01 100644 --- a/src/app/visualization/vistooltriangle.cpp +++ b/src/app/visualization/vistooltriangle.cpp @@ -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(supportColor); - hypotenuseP1 = InitPoint(supportColor); - hypotenuseP2 = InitPoint(supportColor); + hypotenuseP1 = InitPoint(supportColor, this); + hypotenuseP2 = InitPoint(supportColor, this); foot1 = InitItem(supportColor); foot2 = InitItem(supportColor); - point = InitPoint(mainColor); + point = InitPoint(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/visualization.cpp b/src/app/visualization/visualization.cpp index 2b19f9cf5..ae079d60e 100644 --- a/src/app/visualization/visualization.cpp +++ b/src/app/visualization/visualization.cpp @@ -28,6 +28,9 @@ #include "visualization.h" #include "../tools/drawTools/vdrawtool.h" +#include "../container/calculator.h" + +#include //--------------------------------------------------------------------------------------------------------------------- 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); +} diff --git a/src/app/visualization/visualization.h b/src/app/visualization/visualization.h index 80c7feff7..b6ff20e4f 100644 --- a/src/app/visualization/visualization.h +++ b/src/app/visualization/visualization.h @@ -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 void AddItem(Item *item) { diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index f3f4432f5..4a9cef1b8 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -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