diff --git a/src/app/dialogs/tools/dialogcutsplinepath.cpp b/src/app/dialogs/tools/dialogcutsplinepath.cpp index c6ad759b1..6c01dd21d 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/app/dialogs/tools/dialogcutsplinepath.cpp @@ -32,6 +32,7 @@ #include "../../geometry/vsplinepath.h" #include "../../container/vcontainer.h" #include "../../xml/vpattern.h" +#include "../../visualization/vistoolcutsplinepath.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -41,7 +42,7 @@ */ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent) :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), formula(QString()), - splinePathId(NULL_ID), formulaBaseHeight(0) + splinePathId(NULL_ID), formulaBaseHeight(0), path(nullptr) { ui->setupUi(this); InitVariables(ui); @@ -50,7 +51,7 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 & labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); - InitOkCancel(ui); + InitOkCancelApply(ui); flagFormula = false; CheckState(); @@ -62,11 +63,14 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 & connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSplinePath::NamePointChanged); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSplinePath::FormulaChanged); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSplinePath::DeployFormulaTextEdit); + + path = new VisToolCutSplinePath(data); } //--------------------------------------------------------------------------------------------------------------------- DialogCutSplinePath::~DialogCutSplinePath() { + delete path; delete ui; } @@ -96,6 +100,7 @@ void DialogCutSplinePath::setFormula(const QString &value) this->DeployFormulaTextEdit(); } ui->plainTextEditFormula->setPlainText(formula); + path->setLength(formula); } //--------------------------------------------------------------------------------------------------------------------- @@ -106,6 +111,7 @@ void DialogCutSplinePath::setFormula(const QString &value) void DialogCutSplinePath::setSplinePathId(const quint32 &value) { setCurrentSplinePathId(ui->comboBoxSplinePath, splinePathId, value, ComboBoxCutSpline::CutSpline); + path->setPoint1Id(splinePathId); } //--------------------------------------------------------------------------------------------------------------------- @@ -122,6 +128,8 @@ void DialogCutSplinePath::ChosenObject(quint32 id, const SceneObject &type) { if (SetObject(id, ui->comboBoxSplinePath, "")) { + path->VisualMode(id); + prepare = true; this->setModal(true); this->show(); } @@ -136,6 +144,10 @@ void DialogCutSplinePath::SaveData() formula = ui->plainTextEditFormula->toPlainText(); formula.replace("\n", " "); splinePathId = getCurrentObjectId(ui->comboBoxSplinePath); + + path->setPoint1Id(splinePathId); + path->setLength(formula); + path->RefreshGeometry(); } //--------------------------------------------------------------------------------------------------------------------- @@ -143,3 +155,15 @@ void DialogCutSplinePath::DeployFormulaTextEdit() { DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutSplinePath::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor); + scene->addItem(path); + path->RefreshGeometry(); + } +} diff --git a/src/app/dialogs/tools/dialogcutsplinepath.h b/src/app/dialogs/tools/dialogcutsplinepath.h index 46d299379..ff06576c1 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.h +++ b/src/app/dialogs/tools/dialogcutsplinepath.h @@ -36,6 +36,8 @@ namespace Ui class DialogCutSplinePath; } +class VisToolCutSplinePath; + /** * @brief The DialogCutSplinePath class dialog for ToolCutSplinePath. */ @@ -61,6 +63,7 @@ public slots: */ void DeployFormulaTextEdit(); protected: + virtual void ShowVisualization(); /** * @brief SaveData Put dialog data in local variables */ @@ -79,6 +82,8 @@ private: /** @brief formulaBaseHeight base height defined by dialogui */ int formulaBaseHeight; + + VisToolCutSplinePath *path; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogcutsplinepath.ui b/src/app/dialogs/tools/dialogcutsplinepath.ui index 3a1cb2a0f..788de6c27 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.ui +++ b/src/app/dialogs/tools/dialogcutsplinepath.ui @@ -392,7 +392,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index e4558ee3a..9ec7f6495 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -535,9 +535,10 @@ void MainWindow::ToolSplinePath(bool checked) */ void MainWindow::ToolCutSplinePath(bool checked) { - SetToolButton(checked, Tool::CutSplinePath, - ":/cursor/splinepath_cut_point_cursor.png", tr("Select curve path"), - &MainWindow::ClosedDialog); + SetToolButtonWithApply(checked, Tool::CutSplinePath, + ":/cursor/splinepath_cut_point_cursor.png", tr("Select curve path"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index 4d54f0494..fc8d73562 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -30,6 +30,8 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialogcutsplinepath.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolcutsplinepath.h" +#include "vabstractspline.h" #include "../../geometry/vsplinepath.h" @@ -169,16 +171,16 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(), spl1.GetAngle1())); VSplinePoint cutPoint; - if (typeCreation == Source::FromGui) - { - cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), spl1.GetAngle2()+180, - spl1.GetAngle2()); - } - else - { +// if (typeCreation == Source::FromGui) +// { +// cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), spl2.GetKasm1(), +// spl1.GetAngle2()); +// } +// else +// { cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), spl2.GetKasm1(), spl1.GetAngle2()+180); - } +// } splPath1->append(cutPoint); continue; } @@ -245,33 +247,38 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString //--------------------------------------------------------------------------------------------------------------------- void VToolCutSplinePath::ShowVisualization(bool show) { -// if (show) -// { -// if (vis == nullptr) -// { -// VisTool * visual = new VisTool(getData()); -// VMainGraphicsScene *scene = qApp->getCurrentScene(); -// connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); -// scene->addItem(visual); + if (show) + { + if (vis == nullptr) + { + VisToolCutSplinePath *visual = new VisToolCutSplinePath(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); -// // add options -// visual->RefreshGeometry(); -// vis = visual; -// } -// else -// { -// VisTool * visual = qobject_cast(vis); -// if (visual != nullptr) -// { -// visual->show(); -// } -// } -// } -// else -// { -// delete vis; -// vis = nullptr; -// } + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolCutSplinePath *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } + if (VAbstractSpline *parentCurve = qobject_cast(doc->getTool(curveCutId))) + { + parentCurve->ShowFoot(show); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -281,6 +288,14 @@ void VToolCutSplinePath::ShowVisualization(bool show) void VToolCutSplinePath::FullUpdateFromFile() { FullUpdateCurveFromFile(AttrSplinePath); + + if (vis != nullptr) + { + VisToolCutSplinePath *visual = qobject_cast(vis); + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolcutsplinepath.cpp b/src/app/visualization/vistoolcutsplinepath.cpp new file mode 100644 index 000000000..9bf157428 --- /dev/null +++ b/src/app/visualization/vistoolcutsplinepath.cpp @@ -0,0 +1,118 @@ +/************************************************************************ + ** + ** @file vistoolcutsplinepath.cpp + ** @author Roman Telezhynskyi + ** @date 7 9, 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 "vistoolcutsplinepath.h" +#include "../container/vcontainer.h" +#include "../geometry/vsplinepath.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCutSplinePath::VisToolCutSplinePath(const VContainer *data, QGraphicsItem *parent) + :VisPath(data, parent), point(nullptr), splPath1(nullptr), splPath2(nullptr), length(0) +{ + splPath1 = InitItem(Qt::darkGreen, this); + splPath1->setFlag(QGraphicsItem::ItemStacksBehindParent, false); + splPath2 = InitItem(Qt::darkRed, this); + splPath2->setFlag(QGraphicsItem::ItemStacksBehindParent, false); + + point = InitPoint(mainColor, this); + point->setZValue(2); + point->setFlag(QGraphicsItem::ItemStacksBehindParent, false); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCutSplinePath::~VisToolCutSplinePath() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCutSplinePath::RefreshGeometry() +{ + if (point1Id > 0) + { + const QSharedPointer splPath = Visualization::data->GeometricObject(point1Id); + DrawPath(this, splPath->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + + if (qFuzzyCompare(1 + length, 1 + 0) == false) + { + QPointF spl1p2, spl1p3, spl2p2, spl2p3; + qint32 p1 = 0, p2 = 0; + + const QPointF cutPoint = splPath->CutSplinePath(length, p1, p2, spl1p2, spl1p3, spl2p2, spl2p3); + VPointF p = VPointF(cutPoint); + + VSplinePoint splP1 = splPath->at(p1); + VSplinePoint splP2 = splPath->at(p2); + const VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, p, splPath->getKCurve()); + const VSpline spl2 = VSpline(p, spl2p2, spl2p3, splP2.P(), splPath->getKCurve()); + + VSplinePath spPath1 = VSplinePath(); + VSplinePath spPath2 = VSplinePath(); + + for (qint32 i = 0; i < splPath->CountPoint(); i++) + { + if (i <= p1 && i < p2) + { + if (i == p1) + { + spPath1.append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(), + spl1.GetAngle1())); + VSplinePoint cutPoint; + cutPoint = VSplinePoint(p, spl1.GetKasm2(), spl1.GetAngle2(), spl2.GetKasm1(), + spl1.GetAngle2()+180); + spPath1.append(cutPoint); + continue; + } + spPath1.append(splPath->at(i)); + } + else + { + if (i == p2) + { + const VSplinePoint cutPoint = VSplinePoint(p, spl1.GetKasm2(), spl2.GetAngle1()+180, + spl2.GetKasm1(), spl2.GetAngle1()); + spPath2.append(cutPoint); + spPath2.append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2(), splP2.KAsm2(), + spl2.GetAngle2()+180)); + continue; + } + spPath2.append(splPath->at(i)); + } + } + + DrawPoint(point, cutPoint, mainColor); + + DrawPath(splPath1, spPath1.GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); + DrawPath(splPath2, spPath2.GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCutSplinePath::setLength(const QString &expression) +{ + length = FindLength(expression); +} diff --git a/src/app/visualization/vistoolcutsplinepath.h b/src/app/visualization/vistoolcutsplinepath.h new file mode 100644 index 000000000..6dd4bdfcb --- /dev/null +++ b/src/app/visualization/vistoolcutsplinepath.h @@ -0,0 +1,53 @@ +/************************************************************************ + ** + ** @file vistoolcutsplinepath.h + ** @author Roman Telezhynskyi + ** @date 7 9, 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 VISTOOLCUTSPLINEPATH_H +#define VISTOOLCUTSPLINEPATH_H + +#include "vispath.h" + +class VisToolCutSplinePath : public VisPath +{ + Q_OBJECT +public: + VisToolCutSplinePath(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolCutSplinePath(); + + virtual void RefreshGeometry(); + void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolCutSpline)}; +protected: + Q_DISABLE_COPY(VisToolCutSplinePath) + QGraphicsEllipseItem *point; + QGraphicsPathItem *splPath1; + QGraphicsPathItem *splPath2; + qreal length; +}; + +#endif // VISTOOLCUTSPLINEPATH_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index e35bd2fe8..abd4a6ea3 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -20,7 +20,8 @@ HEADERS += \ visualization/vistoolcutarc.h \ visualization/vistoolspline.h \ visualization/vistoolcutspline.h \ - visualization/vistoolsplinepath.h + visualization/vistoolsplinepath.h \ + visualization/vistoolcutsplinepath.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ @@ -44,4 +45,5 @@ SOURCES += \ visualization/vistoolcutarc.cpp \ visualization/vistoolspline.cpp \ visualization/vistoolcutspline.cpp \ - visualization/vistoolsplinepath.cpp + visualization/vistoolsplinepath.cpp \ + visualization/vistoolcutsplinepath.cpp diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 58f901c37..4d575376b 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -2452,7 +2452,10 @@ void VPattern::PrepareForParse(const Document &parse) else if (parse == Document::LiteParse) { data->ClearUniqueNames(); - data->ClearVariables(); + data->ClearVariables(VarType::ArcLength); + data->ClearVariables(VarType::LineAngle); + data->ClearVariables(VarType::LineLength); + data->ClearVariables(VarType::SplineLength); } }