diff --git a/src/app/dialogs/tools/dialogcutarc.cpp b/src/app/dialogs/tools/dialogcutarc.cpp index 062f17ec9..54327dd10 100644 --- a/src/app/dialogs/tools/dialogcutarc.cpp +++ b/src/app/dialogs/tools/dialogcutarc.cpp @@ -31,6 +31,8 @@ #include "../../geometry/varc.h" #include "../../container/vcontainer.h" +#include "../../visualization/vistoolcutarc.h" +#include "../../widgets/vmaingraphicsscene.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -40,7 +42,7 @@ */ DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidget *parent) : DialogTool(data, toolId, parent), ui(new Ui::DialogCutArc), pointName(QString()), formula(QString()), arcId(0), - formulaBaseHeight(0) + formulaBaseHeight(0), path(nullptr) { ui->setupUi(this); InitVariables(ui); @@ -62,6 +64,8 @@ DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidge connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutArc::NamePointChanged); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutArc::FormulaTextChanged); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutArc::DeployFormulaTextEdit); + + path = new VisToolCutArc(data); } //--------------------------------------------------------------------------------------------------------------------- @@ -70,6 +74,18 @@ void DialogCutArc::FormulaTextChanged() this->FormulaChangedPlainText(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutArc::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor); + scene->addItem(path); + path->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogCutArc::DeployFormulaTextEdit() { @@ -79,6 +95,7 @@ void DialogCutArc::DeployFormulaTextEdit() //--------------------------------------------------------------------------------------------------------------------- DialogCutArc::~DialogCutArc() { + delete path; delete ui; } @@ -94,6 +111,8 @@ void DialogCutArc::ChosenObject(quint32 id, const SceneObject &type) { const VArc *arc = data->GeometricObject(id); ChangeCurrentText(ui->comboBoxArc, arc->name()); + path->VisualMode(id); + prepare = true; emit ToolTip(""); this->setModal(true); this->show(); @@ -107,6 +126,10 @@ void DialogCutArc::SaveData() formula = ui->plainTextEditFormula->toPlainText(); formula.replace("\n", " "); arcId = getCurrentObjectId(ui->comboBoxArc); + + path->setPoint1Id(arcId); + path->setLength(formula); + path->RefreshGeometry(); } //--------------------------------------------------------------------------------------------------------------------- @@ -117,6 +140,7 @@ void DialogCutArc::SaveData() void DialogCutArc::setArcId(const quint32 &value) { setCurrentArcId(ui->comboBoxArc, arcId, value, ComboBoxCutArc::CutArc); + path->setPoint1Id(arcId); } //--------------------------------------------------------------------------------------------------------------------- @@ -133,6 +157,7 @@ void DialogCutArc::setFormula(const QString &value) this->DeployFormulaTextEdit(); } ui->plainTextEditFormula->setPlainText(formula); + path->setLength(formula); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogcutarc.h b/src/app/dialogs/tools/dialogcutarc.h index 63a0fb380..a01f5c1e5 100644 --- a/src/app/dialogs/tools/dialogcutarc.h +++ b/src/app/dialogs/tools/dialogcutarc.h @@ -36,6 +36,8 @@ namespace Ui class DialogCutArc; } +class VisToolCutArc; + /** * @brief The DialogCutArc class dialog for ToolCutArc. */ @@ -66,6 +68,7 @@ public slots: */ void FormulaTextChanged(); protected: + virtual void ShowVisualization(); /** * @brief SaveData Put dialog data in local variables */ @@ -82,11 +85,12 @@ private: QString formula; /** @brief arcId keep id of arc */ - quint32 arcId; + quint32 arcId; /** @brief formulaBaseHeight base height defined by dialogui */ - int formulaBaseHeight; + int formulaBaseHeight; + VisToolCutArc *path; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/geometry/varc.cpp b/src/app/geometry/varc.cpp index 95f599b19..f26f9aaa6 100644 --- a/src/app/geometry/varc.cpp +++ b/src/app/geometry/varc.cpp @@ -222,6 +222,15 @@ QPointF VArc::CutArc(const qreal &length, VArc &arc1, VArc &arc2) const return line.p2(); } + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VArc::CutArc(const qreal &length) const +{ + VArc arc1; + VArc arc2; + return this->CutArc(length, arc1, arc2); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief setId keep id arc in data. diff --git a/src/app/geometry/varc.h b/src/app/geometry/varc.h index 5acd5830e..00a5c8d97 100644 --- a/src/app/geometry/varc.h +++ b/src/app/geometry/varc.h @@ -61,6 +61,7 @@ public: qreal AngleArc() const; QVector GetPoints () const; QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const; + QPointF CutArc (const qreal &length) const; virtual void setId(const quint32 &id); private: /** @brief f1 start angle in degree. */ diff --git a/src/app/visualization/vispath.cpp b/src/app/visualization/vispath.cpp index de449d555..137cddeec 100644 --- a/src/app/visualization/vispath.cpp +++ b/src/app/visualization/vispath.cpp @@ -57,6 +57,6 @@ void VisPath::DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &path, co { SCASSERT (pathItem != nullptr); - pathItem->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, style)); + pathItem->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor, style)); pathItem->setPath(path); } diff --git a/src/app/visualization/vistoolcutarc.cpp b/src/app/visualization/vistoolcutarc.cpp new file mode 100644 index 000000000..646beacb5 --- /dev/null +++ b/src/app/visualization/vistoolcutarc.cpp @@ -0,0 +1,64 @@ +/************************************************************************ + ** + ** @file vistoolcutarc.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 "vistoolcutarc.h" +#include "../geometry/varc.h" +#include "../container/vcontainer.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCutArc::VisToolCutArc(const VContainer *data, QGraphicsItem *parent) + :VisPath(data, parent), point(nullptr), length(0) +{ + point = InitPoint(mainColor, this); + point->setZValue(2); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCutArc::~VisToolCutArc() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCutArc::RefreshGeometry() +{ + if (point1Id > 0) + { + const VArc *arc = Visualization::data->GeometricObject(point1Id); + DrawPath(this, arc->GetPath(), supportColor); + + if (qFuzzyCompare(1 + length, 1 + 0) == false) + { + DrawPoint(point, arc->CutArc(length), mainColor); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCutArc::setLength(const QString &expression) +{ + length = FindLength(expression); +} diff --git a/src/app/visualization/vistoolcutarc.h b/src/app/visualization/vistoolcutarc.h new file mode 100644 index 000000000..0ece3790f --- /dev/null +++ b/src/app/visualization/vistoolcutarc.h @@ -0,0 +1,49 @@ +/************************************************************************ + ** + ** @file vistoolcutarc.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 VISTOOLCUTARC_H +#define VISTOOLCUTARC_H + +#include "vispath.h" + +class VisToolCutArc : public VisPath +{ + Q_OBJECT +public: + VisToolCutArc(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolCutArc(); + + virtual void RefreshGeometry(); + void setLength(const QString &expression); +protected: + Q_DISABLE_COPY(VisToolCutArc) + QGraphicsEllipseItem *point; + qreal length; +}; + +#endif // VISTOOLCUTARC_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index 4a9cef1b8..5fe9225ef 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -17,7 +17,8 @@ HEADERS += \ visualization/vistoollineintersect.h \ visualization/visualization.h \ visualization/vistoolarc.h \ - visualization/vispath.h + visualization/vispath.h \ + visualization/vistoolcutarc.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ @@ -38,4 +39,5 @@ SOURCES += \ visualization/vistoollineintersect.cpp \ visualization/visualization.cpp \ visualization/vistoolarc.cpp \ - visualization/vispath.cpp + visualization/vispath.cpp \ + visualization/vistoolcutarc.cpp