From 13bc690f67fad5cd7337440d19b4e7a8586dadf4 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 18 Dec 2013 13:13:32 +0200 Subject: [PATCH] New tool CutSpline (Drawing mode). --HG-- branch : feature --- src/dialogs/dialogalongline.cpp | 4 +- src/dialogs/dialogarc.cpp | 2 +- src/dialogs/dialogbisector.cpp | 6 +- src/dialogs/dialogcutspline.cpp | 136 +++++++ src/dialogs/dialogcutspline.h | 94 +++++ src/dialogs/dialogcutspline.ui | 360 ++++++++++++++++++ src/dialogs/dialogcutsplinepath.cpp | 136 +++++++ src/dialogs/dialogcutsplinepath.h | 94 +++++ src/dialogs/dialogcutsplinepath.ui | 360 ++++++++++++++++++ src/dialogs/dialogendline.cpp | 2 +- src/dialogs/dialogheight.cpp | 6 +- src/dialogs/dialoglineintersect.cpp | 8 +- src/dialogs/dialognormal.cpp | 4 +- src/dialogs/dialogpointofcontact.cpp | 6 +- src/dialogs/dialogpointofintersection.cpp | 4 +- src/dialogs/dialogs.h | 2 + src/dialogs/dialogs.pri | 12 +- src/dialogs/dialogshoulderpoint.cpp | 6 +- src/dialogs/dialogspline.cpp | 4 +- src/dialogs/dialogtool.cpp | 116 +++++- src/dialogs/dialogtool.h | 38 +- src/dialogs/dialogtriangle.cpp | 8 +- src/geometry/vspline.cpp | 119 ++++-- src/geometry/vspline.h | 97 ++--- src/geometry/vsplinepath.cpp | 37 ++ src/geometry/vsplinepath.h | 10 + src/mainwindow.cpp | 42 +- src/mainwindow.h | 28 ++ src/mainwindow.ui | 106 ++++-- src/options.h | 2 + src/tools/drawTools/drawtools.h | 2 + src/tools/drawTools/vtoolcutspline.cpp | 247 ++++++++++++ src/tools/drawTools/vtoolcutspline.h | 149 ++++++++ src/tools/drawTools/vtoolcutsplinepath.cpp | 124 ++++++ src/tools/drawTools/vtoolcutsplinepath.h | 122 ++++++ src/tools/drawTools/vtoolendline.h | 2 +- src/tools/modelingTools/modelingtools.h | 2 + .../modelingTools/vmodelingcutspline.cpp | 124 ++++++ src/tools/modelingTools/vmodelingcutspline.h | 112 ++++++ .../modelingTools/vmodelingcutsplinepath.cpp | 126 ++++++ .../modelingTools/vmodelingcutsplinepath.h | 113 ++++++ src/tools/tools.pri | 12 +- src/widgets/vsimplespline.cpp | 59 +++ src/widgets/vsimplespline.h | 96 +++++ src/widgets/vsimplesplinepath.cpp | 55 +++ src/widgets/vsimplesplinepath.h | 60 +++ src/widgets/widgets.pri | 8 +- src/xml/vdomdocument.cpp | 65 +++- 48 files changed, 3181 insertions(+), 146 deletions(-) create mode 100644 src/dialogs/dialogcutspline.cpp create mode 100644 src/dialogs/dialogcutspline.h create mode 100644 src/dialogs/dialogcutspline.ui create mode 100644 src/dialogs/dialogcutsplinepath.cpp create mode 100644 src/dialogs/dialogcutsplinepath.h create mode 100644 src/dialogs/dialogcutsplinepath.ui create mode 100644 src/tools/drawTools/vtoolcutspline.cpp create mode 100644 src/tools/drawTools/vtoolcutspline.h create mode 100644 src/tools/drawTools/vtoolcutsplinepath.cpp create mode 100644 src/tools/drawTools/vtoolcutsplinepath.h create mode 100644 src/tools/modelingTools/vmodelingcutspline.cpp create mode 100644 src/tools/modelingTools/vmodelingcutspline.h create mode 100644 src/tools/modelingTools/vmodelingcutsplinepath.cpp create mode 100644 src/tools/modelingTools/vmodelingcutsplinepath.h create mode 100644 src/widgets/vsimplespline.cpp create mode 100644 src/widgets/vsimplespline.h create mode 100644 src/widgets/vsimplesplinepath.cpp create mode 100644 src/widgets/vsimplesplinepath.h diff --git a/src/dialogs/dialogalongline.cpp b/src/dialogs/dialogalongline.cpp index 3cbe693c0..7cd5aecb2 100644 --- a/src/dialogs/dialogalongline.cpp +++ b/src/dialogs/dialogalongline.cpp @@ -142,8 +142,8 @@ void DialogAlongLine::DialogAccepted() pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); formula = ui->lineEditFormula->text(); - firstPointId = getCurrentPointId(ui->comboBoxFirstPoint); - secondPointId = getCurrentPointId(ui->comboBoxSecondPoint); + firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); + secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); emit DialogClosed(QDialog::Accepted); } diff --git a/src/dialogs/dialogarc.cpp b/src/dialogs/dialogarc.cpp index d9429dd36..0e5db954c 100644 --- a/src/dialogs/dialogarc.cpp +++ b/src/dialogs/dialogarc.cpp @@ -156,7 +156,7 @@ void DialogArc::DialogAccepted() radius = ui->lineEditRadius->text(); f1 = ui->lineEditF1->text(); f2 = ui->lineEditF2->text(); - center = getCurrentPointId(ui->comboBoxBasePoint); + center = getCurrentObjectId(ui->comboBoxBasePoint); emit DialogClosed(QDialog::Accepted); } diff --git a/src/dialogs/dialogbisector.cpp b/src/dialogs/dialogbisector.cpp index 1809dec13..9837832bb 100644 --- a/src/dialogs/dialogbisector.cpp +++ b/src/dialogs/dialogbisector.cpp @@ -186,8 +186,8 @@ void DialogBisector::DialogAccepted() pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); formula = ui->lineEditFormula->text(); - firstPointId = getCurrentPointId(ui->comboBoxFirstPoint); - secondPointId = getCurrentPointId(ui->comboBoxSecondPoint); - thirdPointId = getCurrentPointId(ui->comboBoxThirdPoint); + firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); + secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); + thirdPointId = getCurrentObjectId(ui->comboBoxThirdPoint); emit DialogClosed(QDialog::Accepted); } diff --git a/src/dialogs/dialogcutspline.cpp b/src/dialogs/dialogcutspline.cpp new file mode 100644 index 000000000..72a858f82 --- /dev/null +++ b/src/dialogs/dialogcutspline.cpp @@ -0,0 +1,136 @@ +/************************************************************************ + ** + ** @file dialogcutspline.cpp + ** @author Roman Telezhinsky + ** @date 15 12, 2013 + ** + ** @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) 2013 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 "dialogcutspline.h" +#include "ui_dialogcutspline.h" + +DialogCutSpline::DialogCutSpline(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogCutSpline), pointName(QString()), formula(QString()), + splineId(0) +{ + ui->setupUi(this); + listWidget = ui->listWidget; + labelResultCalculation = ui->labelResultCalculation; + labelDescription = ui->labelDescription; + radioButtonSizeGrowth = ui->radioButtonSizeGrowth; + radioButtonStandartTable = ui->radioButtonStandartTable; + radioButtonIncrements = ui->radioButtonIncrements; + radioButtonLengthLine = ui->radioButtonLengthLine; + radioButtonLengthArc = ui->radioButtonLengthArc; + radioButtonLengthCurve = ui->radioButtonLengthSpline; + lineEditFormula = ui->lineEditFormula; + labelEditFormula = ui->labelEditFormula; + labelEditNamePoint = ui->labelEditNamePoint; + flagFormula = false; + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + connect(bOk, &QPushButton::clicked, this, &DialogCutSpline::DialogAccepted); + flagName = false; + CheckState(); + QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + connect(bCansel, &QPushButton::clicked, this, &DialogCutSpline::DialogRejected); + FillComboBoxSplines(ui->comboBoxSpline); + + connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogCutSpline::PutHere); + connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogCutSpline::PutVal); + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogCutSpline::ValChenged); + + ShowVariable(data->DataBase()); + connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogCutSpline::SizeGrowth); + connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogCutSpline::StandartTable); + connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogCutSpline::Increments); + connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogCutSpline::LengthLines); + connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogCutSpline::LengthArcs); + connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogCutSpline::LengthCurves); + connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogCutSpline::EvalFormula); + connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSpline::NamePointChanged); + connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogCutSpline::FormulaChanged); +} + +DialogCutSpline::~DialogCutSpline() +{ + delete ui; +} + +void DialogCutSpline::setPointName(const QString &value) +{ + pointName = value; + ui->lineEditNamePoint->setText(pointName); +} + +void DialogCutSpline::setFormula(const QString &value) +{ + formula = value; + ui->lineEditFormula->setText(formula); +} + +void DialogCutSpline::setSplineId(const qint64 &value, const qint64 &id) +{ + setCurrentSplineId(ui->comboBoxSpline, splineId, value, id, ComboMode::CutSpline); +} + +void DialogCutSpline::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { + idDetail = id; + return; + } + } + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { + return; + } + } + if (type == Scene::Spline) + { + VSpline spl; + if (mode == Draw::Calculation) + { + spl = data->GetSpline(id); + } + else + { + spl = data->GetSplineModeling(id); + } + ChangeCurrentText(ui->comboBoxSpline, spl.name()); + emit ToolTip(""); + this->show(); + } +} + +void DialogCutSpline::DialogAccepted() +{ + pointName = ui->lineEditNamePoint->text(); + formula = ui->lineEditFormula->text(); + splineId = getCurrentObjectId(ui->comboBoxSpline); + emit DialogClosed(QDialog::Accepted); +} diff --git a/src/dialogs/dialogcutspline.h b/src/dialogs/dialogcutspline.h new file mode 100644 index 000000000..aaea2bdcd --- /dev/null +++ b/src/dialogs/dialogcutspline.h @@ -0,0 +1,94 @@ +/************************************************************************ + ** + ** @file dialogcutspline.h + ** @author Roman Telezhinsky + ** @date 15 12, 2013 + ** + ** @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) 2013 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 DIALOGCUTSPLINE_H +#define DIALOGCUTSPLINE_H + +#include "dialogtool.h" + +namespace Ui { +class DialogCutSpline; +} + +class DialogCutSpline : public DialogTool +{ + Q_OBJECT +public: + DialogCutSpline(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); + ~DialogCutSpline(); + /** + * @brief getPointName return name of point + * @return name + */ + inline QString getPointName() const {return pointName;} + /** + * @brief setPointName set name of point + * @param value name + */ + void setPointName(const QString &value); + /** + * @brief getFormula return string of formula + * @return formula + */ + inline QString getFormula() const {return formula;} + /** + * @brief setFormula set string of formula + * @param value formula + */ + void setFormula(const QString &value); + /** + * @brief getSplineId return id base point of line + * @return id + */ + inline qint64 getSplineId() const {return splineId;} + /** + * @brief setSplineId set id spline + * @param value id + * @param id don't show this id in list + */ + void setSplineId(const qint64 &value, const qint64 &id); +public slots: + /** + * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. + * @param id id of point or detail + * @param type type of object + */ + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + /** + * @brief DialogAccepted save data and emit signal about closed dialog. + */ + virtual void DialogAccepted(); +private: + Q_DISABLE_COPY(DialogCutSpline) + Ui::DialogCutSpline *ui; + QString pointName; + QString formula; + qint64 splineId; +}; + +#endif // DIALOGCUTSPLINE_H diff --git a/src/dialogs/dialogcutspline.ui b/src/dialogs/dialogcutspline.ui new file mode 100644 index 000000000..289a21386 --- /dev/null +++ b/src/dialogs/dialogcutspline.ui @@ -0,0 +1,360 @@ + + + DialogCutSpline + + + + 0 + 0 + 520 + 461 + + + + Dialog + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Length + + + + + + + + 0 + 0 + + + + Formula calculation of length of curve + + + + + + + Calculate formula + + + ... + + + + :/icon/24x24/equal.png:/icon/24x24/equal.png + + + + 24 + 24 + + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value of length + + + _ + + + + + + + + + + + + + + + + 0 + 0 + + + + Curve + + + + + + + Selected curve + + + + + + + ... + + + + :/icon/24x24/putHere.png:/icon/24x24/putHere.png + + + + 24 + 24 + + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Name new point + + + + + + + + + + + + + + Input data + + + + + + + Size and growth + + + true + + + + + + + Standart table + + + + + + + Increments + + + + + + + true + + + Length of lines + + + + + + + true + + + Length of arcs + + + + + + + true + + + Length of curves + + + + + + + + + + + Variables. Click twice to select. + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogCutSpline + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogCutSpline + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/dialogs/dialogcutsplinepath.cpp b/src/dialogs/dialogcutsplinepath.cpp new file mode 100644 index 000000000..3e25a60fa --- /dev/null +++ b/src/dialogs/dialogcutsplinepath.cpp @@ -0,0 +1,136 @@ +/************************************************************************ + ** + ** @file dialogcutsplinrpath.cpp + ** @author Roman Telezhinsky + ** @date 15 12, 2013 + ** + ** @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) 2013 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 "dialogcutsplinepath.h" +#include "ui_dialogcutsplinepath.h" + +DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogCutSplinePath), pointName(QString()), formula(QString()), + splinePathId(0) +{ + ui->setupUi(this); + listWidget = ui->listWidget; + labelResultCalculation = ui->labelResultCalculation; + labelDescription = ui->labelDescription; + radioButtonSizeGrowth = ui->radioButtonSizeGrowth; + radioButtonStandartTable = ui->radioButtonStandartTable; + radioButtonIncrements = ui->radioButtonIncrements; + radioButtonLengthLine = ui->radioButtonLengthLine; + radioButtonLengthArc = ui->radioButtonLengthArc; + radioButtonLengthCurve = ui->radioButtonLengthSpline; + lineEditFormula = ui->lineEditFormula; + labelEditFormula = ui->labelEditFormula; + labelEditNamePoint = ui->labelEditNamePoint; + flagFormula = false; + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + connect(bOk, &QPushButton::clicked, this, &DialogCutSplinePath::DialogAccepted); + flagName = false; + CheckState(); + QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + connect(bCansel, &QPushButton::clicked, this, &DialogCutSplinePath::DialogRejected); + FillComboBoxSplines(ui->comboBoxSplinePath); + + connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogCutSplinePath::PutHere); + connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogCutSplinePath::PutVal); + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogCutSplinePath::ValChenged); + + ShowVariable(data->DataBase()); + connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogCutSplinePath::SizeGrowth); + connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogCutSplinePath::StandartTable); + connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogCutSplinePath::Increments); + connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogCutSplinePath::LengthLines); + connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogCutSplinePath::LengthArcs); + connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogCutSplinePath::LengthCurves); + connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogCutSplinePath::EvalFormula); + connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSplinePath::NamePointChanged); + connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogCutSplinePath::FormulaChanged); +} + +DialogCutSplinePath::~DialogCutSplinePath() +{ + delete ui; +} + +void DialogCutSplinePath::setPointName(const QString &value) +{ + pointName = value; + ui->lineEditNamePoint->setText(pointName); +} + +void DialogCutSplinePath::setFormula(const QString &value) +{ + formula = value; + ui->lineEditFormula->setText(formula); +} + +void DialogCutSplinePath::setSplinePathId(const qint64 &value, const qint64 &id) +{ + setCurrentSplinePathId(ui->comboBoxSplinePath, splinePathId, value, id); +} + +void DialogCutSplinePath::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { + idDetail = id; + return; + } + } + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { + return; + } + } + if (type == Scene::Spline) + { + VSplinePath splPath; + if (mode == Draw::Calculation) + { + splPath = data->GetSplinePath(id); + } + else + { + splPath = data->GetSplinePathModeling(id); + } + ChangeCurrentText(ui->comboBoxSplinePath, splPath.name()); + emit ToolTip(""); + this->show(); + } +} + +void DialogCutSplinePath::DialogAccepted() +{ + pointName = ui->lineEditNamePoint->text(); + formula = ui->lineEditFormula->text(); + splinePathId = getCurrentObjectId(ui->comboBoxSplinePath); + emit DialogClosed(QDialog::Accepted); +} diff --git a/src/dialogs/dialogcutsplinepath.h b/src/dialogs/dialogcutsplinepath.h new file mode 100644 index 000000000..96a434932 --- /dev/null +++ b/src/dialogs/dialogcutsplinepath.h @@ -0,0 +1,94 @@ +/************************************************************************ + ** + ** @file dialogcutsplinrpath.h + ** @author Roman Telezhinsky + ** @date 15 12, 2013 + ** + ** @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) 2013 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 DIALOGCUTSPLINEPATH_H +#define DIALOGCUTSPLINEPATH_H + +#include "dialogtool.h" + +namespace Ui { +class DialogCutSplinePath; +} + +class DialogCutSplinePath : public DialogTool +{ + Q_OBJECT +public: + DialogCutSplinePath(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); + ~DialogCutSplinePath(); + /** + * @brief getPointName return name of point + * @return name + */ + inline QString getPointName() const {return pointName;} + /** + * @brief setPointName set name of point + * @param value name + */ + void setPointName(const QString &value); + /** + * @brief getFormula return string of formula + * @return formula + */ + inline QString getFormula() const {return formula;} + /** + * @brief setFormula set string of formula + * @param value formula + */ + void setFormula(const QString &value); + /** + * @brief getSplineId return id base point of line + * @return id + */ + inline qint64 getSplinePathId() const {return splinePathId;} + /** + * @brief setSplineId set id spline + * @param value id + * @param id don't show this id in list + */ + void setSplinePathId(const qint64 &value, const qint64 &id); +public slots: + /** + * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. + * @param id id of point or detail + * @param type type of object + */ + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + /** + * @brief DialogAccepted save data and emit signal about closed dialog. + */ + virtual void DialogAccepted(); +private: + Q_DISABLE_COPY(DialogCutSplinePath) + Ui::DialogCutSplinePath *ui; + QString pointName; + QString formula; + qint64 splinePathId; +}; + +#endif // DIALOGCUTSPLINEPATH_H diff --git a/src/dialogs/dialogcutsplinepath.ui b/src/dialogs/dialogcutsplinepath.ui new file mode 100644 index 000000000..8ac631fec --- /dev/null +++ b/src/dialogs/dialogcutsplinepath.ui @@ -0,0 +1,360 @@ + + + DialogCutSplinePath + + + + 0 + 0 + 605 + 397 + + + + Dialog + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Length + + + + + + + + 0 + 0 + + + + Formula calculation of length of curve + + + + + + + Calculate formula + + + ... + + + + :/icon/24x24/equal.png:/icon/24x24/equal.png + + + + 24 + 24 + + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value of length + + + _ + + + + + + + + + + + + + + + + 0 + 0 + + + + Curve + + + + + + + Selected curve path + + + + + + + ... + + + + :/icon/24x24/putHere.png:/icon/24x24/putHere.png + + + + 24 + 24 + + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Name new point + + + + + + + + + + + + + + Input data + + + + + + + Size and growth + + + true + + + + + + + Standart table + + + + + + + Increments + + + + + + + true + + + Length of lines + + + + + + + true + + + Length of arcs + + + + + + + true + + + Length of curves + + + + + + + + + + + Variables. Click twice to select. + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogCutSplinePath + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogCutSplinePath + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/dialogs/dialogendline.cpp b/src/dialogs/dialogendline.cpp index b00834019..012e3987d 100644 --- a/src/dialogs/dialogendline.cpp +++ b/src/dialogs/dialogendline.cpp @@ -160,7 +160,7 @@ void DialogEndLine::DialogAccepted() typeLine = GetTypeLine(ui->comboBoxLineType); formula = ui->lineEditFormula->text(); angle = ui->doubleSpinBoxAngle->value(); - basePointId = getCurrentPointId(ui->comboBoxBasePoint); + basePointId = getCurrentObjectId(ui->comboBoxBasePoint); emit DialogClosed(QDialog::Accepted); } diff --git a/src/dialogs/dialogheight.cpp b/src/dialogs/dialogheight.cpp index 1592c40bd..9c8f32b18 100644 --- a/src/dialogs/dialogheight.cpp +++ b/src/dialogs/dialogheight.cpp @@ -144,8 +144,8 @@ void DialogHeight::DialogAccepted() { pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); - basePointId = getCurrentPointId(ui->comboBoxBasePoint); - p1LineId = getCurrentPointId(ui->comboBoxP1Line); - p2LineId = getCurrentPointId(ui->comboBoxP2Line); + basePointId = getCurrentObjectId(ui->comboBoxBasePoint); + p1LineId = getCurrentObjectId(ui->comboBoxP1Line); + p2LineId = getCurrentObjectId(ui->comboBoxP2Line); emit DialogClosed(QDialog::Accepted); } diff --git a/src/dialogs/dialoglineintersect.cpp b/src/dialogs/dialoglineintersect.cpp index 1a96777c5..216a19fec 100644 --- a/src/dialogs/dialoglineintersect.cpp +++ b/src/dialogs/dialoglineintersect.cpp @@ -155,10 +155,10 @@ void DialogLineIntersect::ChoosedObject(qint64 id, const Scene::Scenes &type) void DialogLineIntersect::DialogAccepted() { pointName = ui->lineEditNamePoint->text(); - p1Line1 = getCurrentPointId(ui->comboBoxP1Line1); - p2Line1 = getCurrentPointId(ui->comboBoxP2Line1); - p1Line2 = getCurrentPointId(ui->comboBoxP1Line2); - p2Line2 = getCurrentPointId(ui->comboBoxP2Line2); + p1Line1 = getCurrentObjectId(ui->comboBoxP1Line1); + p2Line1 = getCurrentObjectId(ui->comboBoxP2Line1); + p1Line2 = getCurrentObjectId(ui->comboBoxP1Line2); + p2Line2 = getCurrentObjectId(ui->comboBoxP2Line2); emit DialogClosed(QDialog::Accepted); } diff --git a/src/dialogs/dialognormal.cpp b/src/dialogs/dialognormal.cpp index 84e10f4eb..e9359fbbc 100644 --- a/src/dialogs/dialognormal.cpp +++ b/src/dialogs/dialognormal.cpp @@ -159,8 +159,8 @@ void DialogNormal::DialogAccepted() typeLine = GetTypeLine(ui->comboBoxLineType); formula = ui->lineEditFormula->text(); angle = ui->doubleSpinBoxAngle->value(); - firstPointId = getCurrentPointId(ui->comboBoxFirstPoint); - secondPointId = getCurrentPointId(ui->comboBoxSecondPoint); + firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); + secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); emit DialogClosed(QDialog::Accepted); } diff --git a/src/dialogs/dialogpointofcontact.cpp b/src/dialogs/dialogpointofcontact.cpp index 864f727e7..092f8b748 100644 --- a/src/dialogs/dialogpointofcontact.cpp +++ b/src/dialogs/dialogpointofcontact.cpp @@ -145,9 +145,9 @@ void DialogPointOfContact::DialogAccepted() { pointName = ui.lineEditNamePoint->text(); radius = ui.lineEditFormula->text(); - center = getCurrentPointId(ui.comboBoxCenter); - firstPoint = getCurrentPointId(ui.comboBoxFirstPoint); - secondPoint = getCurrentPointId(ui.comboBoxSecondPoint); + center = getCurrentObjectId(ui.comboBoxCenter); + firstPoint = getCurrentObjectId(ui.comboBoxFirstPoint); + secondPoint = getCurrentObjectId(ui.comboBoxSecondPoint); emit DialogClosed(QDialog::Accepted); } diff --git a/src/dialogs/dialogpointofintersection.cpp b/src/dialogs/dialogpointofintersection.cpp index 3d14e2f3a..c355cf4b0 100644 --- a/src/dialogs/dialogpointofintersection.cpp +++ b/src/dialogs/dialogpointofintersection.cpp @@ -118,8 +118,8 @@ void DialogPointOfIntersection::ChoosedObject(qint64 id, const Scene::Scenes &ty void DialogPointOfIntersection::DialogAccepted() { pointName = ui->lineEditNamePoint->text(); - firstPointId = getCurrentPointId(ui->comboBoxFirstPoint); - secondPointId = getCurrentPointId(ui->comboBoxSecondPoint); + firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); + secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); emit DialogClosed(QDialog::Accepted); } diff --git a/src/dialogs/dialogs.h b/src/dialogs/dialogs.h index c205f2522..06b0c2aa6 100644 --- a/src/dialogs/dialogs.h +++ b/src/dialogs/dialogs.h @@ -45,5 +45,7 @@ #include "dialogspline.h" #include "dialogsplinepath.h" #include "dialogheight.h" +#include "dialogcutspline.h" +#include "dialogcutsplinepath.h" #endif // DIALOGS_H diff --git a/src/dialogs/dialogs.pri b/src/dialogs/dialogs.pri index e6898dd39..d18e02857 100644 --- a/src/dialogs/dialogs.pri +++ b/src/dialogs/dialogs.pri @@ -18,7 +18,9 @@ HEADERS += \ src/dialogs/dialogdetail.h \ src/dialogs/dialogbisector.h \ src/dialogs/dialogarc.h \ - src/dialogs/dialogalongline.h + src/dialogs/dialogalongline.h \ + src/dialogs/dialogcutspline.h \ + src/dialogs/dialogcutsplinepath.h SOURCES += \ src/dialogs/dialogtriangle.cpp \ @@ -39,7 +41,9 @@ SOURCES += \ src/dialogs/dialogdetail.cpp \ src/dialogs/dialogbisector.cpp \ src/dialogs/dialogarc.cpp \ - src/dialogs/dialogalongline.cpp + src/dialogs/dialogalongline.cpp \ + src/dialogs/dialogcutspline.cpp \ + src/dialogs/dialogcutsplinepath.cpp FORMS += \ src/dialogs/dialogtriangle.ui \ @@ -59,4 +63,6 @@ FORMS += \ src/dialogs/dialogdetail.ui \ src/dialogs/dialogbisector.ui \ src/dialogs/dialogarc.ui \ - src/dialogs/dialogalongline.ui + src/dialogs/dialogalongline.ui \ + src/dialogs/dialogcutspline.ui \ + src/dialogs/dialogcutsplinepath.ui diff --git a/src/dialogs/dialogshoulderpoint.cpp b/src/dialogs/dialogshoulderpoint.cpp index 8b7bea2a1..6a6ab18c7 100644 --- a/src/dialogs/dialogshoulderpoint.cpp +++ b/src/dialogs/dialogshoulderpoint.cpp @@ -154,9 +154,9 @@ void DialogShoulderPoint::DialogAccepted() pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); formula = ui->lineEditFormula->text(); - p1Line = getCurrentPointId(ui->comboBoxP1Line); - p2Line = getCurrentPointId(ui->comboBoxP2Line); - pShoulder = getCurrentPointId(ui->comboBoxPShoulder); + p1Line = getCurrentObjectId(ui->comboBoxP1Line); + p2Line = getCurrentObjectId(ui->comboBoxP2Line); + pShoulder = getCurrentObjectId(ui->comboBoxPShoulder); emit DialogClosed(QDialog::Accepted); } diff --git a/src/dialogs/dialogspline.cpp b/src/dialogs/dialogspline.cpp index 208e9f2d3..64776ed81 100644 --- a/src/dialogs/dialogspline.cpp +++ b/src/dialogs/dialogspline.cpp @@ -129,8 +129,8 @@ void DialogSpline::ChoosedObject(qint64 id, const Scene::Scenes &type) void DialogSpline::DialogAccepted() { - p1 = getCurrentPointId(ui->comboBoxP1); - p4 = getCurrentPointId(ui->comboBoxP4); + p1 = getCurrentObjectId(ui->comboBoxP1); + p4 = getCurrentObjectId(ui->comboBoxP4); angle1 = ui->spinBoxAngle1->value(); angle2 = ui->spinBoxAngle2->value(); kAsm1 = ui->doubleSpinBoxKasm1->value(); diff --git a/src/dialogs/dialogtool.cpp b/src/dialogs/dialogtool.cpp index 5ec5f3343..85ae56de9 100644 --- a/src/dialogs/dialogtool.cpp +++ b/src/dialogs/dialogtool.cpp @@ -65,6 +65,7 @@ void DialogTool::showEvent(QShowEvent *event) void DialogTool::FillComboBoxPoints(QComboBox *box, const qint64 &id) const { + Q_ASSERT(box != 0); box->clear(); if (mode == Draw::Calculation) { @@ -109,6 +110,99 @@ void DialogTool::FillComboBoxPoints(QComboBox *box, const qint64 &id) const } } +void DialogTool::FillComboBoxSplines(QComboBox *box, const qint64 &id, ComboMode::ComboBoxCutSpline cut) const +{ + Q_ASSERT(box != 0); + box->clear(); + if (mode == Draw::Calculation) + { + const QHash *spls = data->DataSplines(); + QHashIterator i(*spls); + while (i.hasNext()) + { + i.next(); + if(cut == ComboMode::CutSpline) + { + if (i.key() != id + 1 && i.key() != id + 2) + { + VSpline spl = i.value(); + box->addItem(spl.name(), i.key()); + } + } + else + { + if (i.key() != id) + { + VSpline spl = i.value(); + box->addItem(spl.name(), i.key()); + } + } + } + } + else + { + if (idDetail <= 0) + { + qWarning()<GetDetail(idDetail); + for (ptrdiff_t i = 0; i< det.CountNode(); ++i) + { + if (det[i].getTypeTool() == Tool::SplineTool || + det[i].getTypeTool() == Tool::NodeSpline ) + { + if (det[i].getId() != id) + { + VSpline spl = data->GetSplineModeling(det[i].getId()); + box->addItem(spl.name(), det[i].getId()); + } + } + } + } +} + +void DialogTool::FillComboBoxSplinesPath(QComboBox *box, const qint64 &id) const +{ + Q_ASSERT(box != 0); + box->clear(); + if (mode == Draw::Calculation) + { + const QHash *splPaths = data->DataSplinePaths(); + QHashIterator i(*splPaths); + while (i.hasNext()) + { + i.next(); + if (i.key() != id) + { + VSplinePath splPath = i.value(); + box->addItem(splPath.name(), i.key()); + } + } + } + else + { + if (idDetail <= 0) + { + qWarning()<GetDetail(idDetail); + for (ptrdiff_t i = 0; i< det.CountNode(); ++i) + { + if (det[i].getTypeTool() == Tool::SplinePathTool || + det[i].getTypeTool() == Tool::NodeSplinePath ) + { + if (det[i].getId() != id) + { + VSplinePath splPath = data->GetSplinePathModeling(det[i].getId()); + box->addItem(splPath.name(), det[i].getId()); + } + } + } + } +} + void DialogTool::FillComboBoxTypeLine(QComboBox *box) const { Q_ASSERT(box != 0); @@ -158,7 +252,7 @@ void DialogTool::ChangeCurrentText(QComboBox *box, const QString &value) } else { - qWarning()<currentIndex(); diff --git a/src/dialogs/dialogtool.h b/src/dialogs/dialogtool.h index ca3bff440..9e83ecd92 100644 --- a/src/dialogs/dialogtool.h +++ b/src/dialogs/dialogtool.h @@ -37,6 +37,16 @@ #include #include "../container/vcontainer.h" +namespace ComboMode +{ + /** + * @brief The ComboBoxCutSpline enum + */ + enum ComboBoxCutSpline { CutSpline, NoCutSpline }; + Q_DECLARE_FLAGS(ComboBoxCutSplines, ComboBoxCutSpline) +} +Q_DECLARE_OPERATORS_FOR_FLAGS( ComboMode::ComboBoxCutSplines ) + /** * @brief The DialogTool class parent for all dialog of tools. */ @@ -282,6 +292,14 @@ protected: * @param id don't show this id in list */ void FillComboBoxPoints(QComboBox *box, const qint64 &id = 0)const; + /** + * @brief FillComboBoxSplines fill comboBox list of splines + * @param box comboBox + * @param id don't show id+1 and id+2 in list + */ + void FillComboBoxSplines(QComboBox *box, const qint64 &id = 0, + ComboMode::ComboBoxCutSpline cut = ComboMode::NoCutSpline)const; + void FillComboBoxSplinesPath(QComboBox *box, const qint64 &id = 0)const; /** * @brief FillComboBoxTypeLine fill comboBox list of type lines * @param box comboBox @@ -350,12 +368,30 @@ protected: * @param id don't show this id in list */ void setCurrentPointId(QComboBox *box, qint64 &pointId, const qint64 &value, const qint64 &id) const; + /** + * @brief setCurrentSplineId set current spline id in combobox + * @param box combobox + * @param splineId save current spline id + * @param value spline id + * @param id don't show this id in list + */ + void setCurrentSplineId(QComboBox *box, qint64 &splineId, const qint64 &value, const qint64 &id, + ComboMode::ComboBoxCutSpline cut = ComboMode::NoCutSpline) const; + /** + * @brief setCurrentSplinePathId set current splinePath id in combobox + * @param box combobox + * @param splinePathId save current splinePath id + * @param value splinePath id + * @param id don't show this id in list + */ + void setCurrentSplinePathId(QComboBox *box, qint64 &splinePathId, const qint64 &value, + const qint64 &id) const; /** * @brief getCurrentPointId return current point id in combobox * @param box combobox * @return id or -1 if combobox is empty */ - qint64 getCurrentPointId(QComboBox *box) const; + qint64 getCurrentObjectId(QComboBox *box) const; }; #endif // DIALOGTOOL_H diff --git a/src/dialogs/dialogtriangle.cpp b/src/dialogs/dialogtriangle.cpp index 5c0625b4d..5c405aa2a 100644 --- a/src/dialogs/dialogtriangle.cpp +++ b/src/dialogs/dialogtriangle.cpp @@ -118,10 +118,10 @@ void DialogTriangle::ChoosedObject(qint64 id, const Scene::Scenes &type) void DialogTriangle::DialogAccepted() { pointName = ui->lineEditNamePoint->text(); - firstPointId = getCurrentPointId(ui->comboBoxFirstPoint); - secondPointId = getCurrentPointId(ui->comboBoxSecondPoint); - axisP1Id = getCurrentPointId(ui->comboBoxAxisP1); - axisP2Id = getCurrentPointId(ui->comboBoxAxisP2); + firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); + secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); + axisP1Id = getCurrentObjectId(ui->comboBoxAxisP1); + axisP2Id = getCurrentObjectId(ui->comboBoxAxisP2); emit DialogClosed(QDialog::Accepted); } diff --git a/src/geometry/vspline.cpp b/src/geometry/vspline.cpp index 54e5026a0..bcf6c8447 100644 --- a/src/geometry/vspline.cpp +++ b/src/geometry/vspline.cpp @@ -207,32 +207,99 @@ QLineF::IntersectType VSpline::CrossingSplLine ( const QLineF &line, QPointF *in throw "Не можу знайти точку перетину сплайну з лінією."; } -//void VSpline::CutSpline ( qreal length, VSpline* curFir, VSpline* curSec ) const{ -// if ( length > GetLength()){ -// throw"Не правильна довжина нового сплайну\n"; -// } -// qreal parT = length / GetLength(); -// QLineF seg1_2 ( GetPointP1 (), GetP2 () ); -// seg1_2.setLength(seg1_2.length () * parT); -// QPointF p12 = seg1_2.p2(); -// QLineF seg2_3 ( GetP2 (), GetP3 () ); -// seg2_3.setLength(seg2_3.length () * parT); -// QPointF p23 = seg2_3.p2(); -// QLineF seg12_23 ( p12, p23 ); -// seg12_23.setLength(seg12_23.length () * parT); -// QPointF p123 = seg12_23.p2(); -// QLineF seg3_4 ( GetP3 (), GetPointP4 () ); -// seg3_4.setLength(seg3_4.length () * parT); -// QPointF p34 = seg3_4.p2(); -// QLineF seg23_34 ( p23, p34 ); -// seg23_34.setLength(seg23_34.length () * parT); -// QPointF p234 = seg23_34.p2(); -// QLineF seg123_234 ( p123, p234 ); -// seg123_234.setLength(seg123_234.length () * parT); -// QPointF p1234 = seg123_234.p2(); -// curFir->ModifiSpl ( GetPointP1 (), p12, p123, p1234 ); -// curSec->ModifiSpl ( p1234, p234, p34, GetPointP4 () ); -//} +qreal VSpline::LengthT(qreal t) const +{ + if(t < 0 || t > 1) + { + qWarning()<<"Wrong value t."; + return 0; + } + QLineF seg1_2 ( GetPointP1 ().toQPointF(), GetP2 () ); + seg1_2.setLength(seg1_2.length () * t); + QPointF p12 = seg1_2.p2(); + + QLineF seg2_3 ( GetP2 (), GetP3 () ); + seg2_3.setLength(seg2_3.length () * t); + QPointF p23 = seg2_3.p2(); + + QLineF seg12_23 ( p12, p23 ); + seg12_23.setLength(seg12_23.length () * t); + QPointF p123 = seg12_23.p2(); + + QLineF seg3_4 ( GetP3 (), GetPointP4 ().toQPointF() ); + seg3_4.setLength(seg3_4.length () * t); + QPointF p34 = seg3_4.p2(); + + QLineF seg23_34 ( p23, p34 ); + seg23_34.setLength(seg23_34.length () * t); + QPointF p234 = seg23_34.p2(); + + QLineF seg123_234 ( p123, p234 ); + seg123_234.setLength(seg123_234.length () * t); + QPointF p1234 = seg123_234.p2(); + + return LengthBezier ( GetPointP1().toQPointF(), p12, p123, p1234); +} + +QPointF VSpline::CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3 ) const +{ + //Always need return two splines, so we must correct wrong length. + if(length < GetLength()*0.02) + { + length = GetLength()*0.02; + qWarning()<<"Warning!!! Correction length of cutting. Length too small."; + } + else if ( length > GetLength()*0.98) + { + length = GetLength()*0.98; + qWarning()<<"Warning!!! Correction length of cutting. Length too small."; + } + + // Very stupid way find correct value of t. + // Better first compare with t = 0.5. Find length of spline. + // If length larger, take t = 0.75 and so on. + // If length less, take t = 0.25 and so on. + qreal parT = 0; + qreal step = 0.001; + while (1) + { + parT = parT + step; + qreal splLength = LengthT(parT); + if(splLength >= length || parT > 1){ + break; + } + } + + QLineF seg1_2 ( GetPointP1 ().toQPointF(), GetP2 () ); + seg1_2.setLength(seg1_2.length () * parT); + QPointF p12 = seg1_2.p2(); + + QLineF seg2_3 ( GetP2 (), GetP3 () ); + seg2_3.setLength(seg2_3.length () * parT); + QPointF p23 = seg2_3.p2(); + + QLineF seg12_23 ( p12, p23 ); + seg12_23.setLength(seg12_23.length () * parT); + QPointF p123 = seg12_23.p2(); + + QLineF seg3_4 ( GetP3 (), GetPointP4 ().toQPointF() ); + seg3_4.setLength(seg3_4.length () * parT); + QPointF p34 = seg3_4.p2(); + + QLineF seg23_34 ( p23, p34 ); + seg23_34.setLength(seg23_34.length () * parT); + QPointF p234 = seg23_34.p2(); + + QLineF seg123_234 ( p123, p234 ); + seg123_234.setLength(seg123_234.length () * parT); + QPointF p1234 = seg123_234.p2(); + + spl1p2 = p12; + spl1p3 = p123; + spl2p2 = p234; + spl2p3 = p34; + return p1234; +} //void VSpline::CutSpline ( QPointF point, VSpline* curFir, VSpline* curSec ) const{ // qreal t = param_t (point); diff --git a/src/geometry/vspline.h b/src/geometry/vspline.h index 5fc34cc7a..bbe18d89e 100644 --- a/src/geometry/vspline.h +++ b/src/geometry/vspline.h @@ -40,39 +40,41 @@ class QString; #define M_2PI 6.28318530717958647692528676655900576 /** - * @brief VSpline клас, що реалізує сплайн. + * @brief VSpline class that implements the spline. */ class VSpline { public: - VSpline(); - /** - * @brief VSpline конструктор. - * @param spline сплайн з якого копіюємо. - */ - VSpline (const VSpline &spline ); - /** - * @brief VSpline конструктор. - * @param p1 початкова точка сплайна. - * @param p4 кінцева точка сплайна. - * @param angle1 кут в градусах першої напрямної. - * @param angle2 кут в градусах другої напрямної. - * @param kCurve коефіцієнт кривизни сплайна. - * @param kAsm1 коефіцієнт довжини першої напрямної. - * @param kAsm2 коефіцієнт довжини другої напрямної. - */ - VSpline (const QHash *points, qint64 p1, qint64 p4, qreal angle1, qreal angle2, - qreal kAsm1, qreal kAsm2, qreal kCurve, Draw::Draws mode = Draw::Calculation, - qint64 idObject = 0); - /** - * @brief VSpline конструктор. - * @param p1 початкова точка сплайну. - * @param p2 перша контролююча точка сплайну. - * @param p3 друга контролююча точка сплайну. - * @param p4 кінцева точка сплайну. - */ - VSpline (const QHash *points, qint64 p1, QPointF p2, QPointF p3, qint64 p4, - qreal kCurve, Draw::Draws mode = Draw::Calculation, qint64 idObject = 0); + /** + * @brief VSpline default constructor + */ + VSpline(); + /** + * @brief VSpline constructor. + * @param spline spline from which the copy. + */ + VSpline (const VSpline &spline ); + /** + * @brief VSpline constructor. + * @param p1 початкова точка сплайна. + * @param p4 кінцева точка сплайна. + * @param angle1 кут в градусах першої напрямної. + * @param angle2 кут в градусах другої напрямної. + * @param kCurve коефіцієнт кривизни сплайна. + * @param kAsm1 коефіцієнт довжини першої напрямної. + * @param kAsm2 коефіцієнт довжини другої напрямної. + */ + VSpline (const QHash *points, qint64 p1, qint64 p4, qreal angle1, qreal angle2, + qreal kAsm1, qreal kAsm2, qreal kCurve, Draw::Draws mode = Draw::Calculation, qint64 idObject = 0); + /** + * @brief VSpline конструктор. + * @param p1 початкова точка сплайну. + * @param p2 перша контролююча точка сплайну. + * @param p3 друга контролююча точка сплайну. + * @param p4 кінцева точка сплайну. + */ + VSpline (const QHash *points, qint64 p1, QPointF p2, QPointF p3, qint64 p4, + qreal kCurve, Draw::Draws mode = Draw::Calculation, qint64 idObject = 0); /** * @brief ModifiSpl модифікує сплайн. * @param p1 початкова точка сплайну. @@ -84,7 +86,7 @@ public: * @param kAsm2 коефіцієнт довжини другої напрямної. */ void ModifiSpl ( qint64 p1, qint64 p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, - qreal kCurve); + qreal kCurve); /** * @brief ModifiSpl модифікує сплайн. * @param p1 початкова точка сплайну. @@ -94,17 +96,17 @@ public: */ void ModifiSpl (const qint64 &p1, const QPointF &p2, const QPointF &p3, const qint64 &p4, const qreal &kCurve); - /** - * @brief RotationSpl поворот сплайна навколо точки на кут в градусах проти годиникової стрілки. - * @param pRotate точка навколо якої повертаємо. - * @param angle кут в градусах. - */ +// /** +// * @brief RotationSpl поворот сплайна навколо точки на кут в градусах проти годиникової стрілки. +// * @param pRotate точка навколо якої повертаємо. +// * @param angle кут в градусах. +// */ // void RotationSpl ( QPointF pRotate, qreal angle ); - /** - * @brief BiasSpl зміщує сплайн. - * @param mx зміщення по х координаті. - * @param my зміщення по у координаті. - */ +// /** +// * @brief BiasSpl зміщує сплайн. +// * @param mx зміщення по х координаті. +// * @param my зміщення по у координаті. +// */ // void BiasSpl ( qreal mx, qreal my ); /** * @brief GetP1 повертає першу точку сплайну. @@ -183,13 +185,18 @@ public: * @return результат перевірки. */ QLineF::IntersectType CrossingSplLine(const QLineF &line, QPointF *intersectionPoint ) const; + qreal LengthT(qreal t) const; /** - * @brief CutSpline розрізає сплайн. - * @param length дожина першого сплайну. - * @param curFir перший сплайн. - * @param curSec другий сплайн. + * @brief CutSpline cut spline. GetPointP1() of base spline will return first point for first spline, GetPointP4() + * of base spline will return forth point of second spline. + * @param length length first spline + * @param spl1p2 second point of first spline + * @param spl1p3 third point of first spline + * @param spl2p2 second point of second spline + * @param spl2p3 third point of second spline + * @return point of cutting. This point is forth point of first spline and first point of second spline. */ -// void CutSpline ( qreal length, VSpline* curFir, VSpline* curSec ) const; + QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const; /** * @brief CutSpline розрізає сплайн. * @param point точка що ділить сплайн. diff --git a/src/geometry/vsplinepath.cpp b/src/geometry/vsplinepath.cpp index 79b2acf76..db3adb705 100644 --- a/src/geometry/vsplinepath.cpp +++ b/src/geometry/vsplinepath.cpp @@ -169,3 +169,40 @@ VSplinePoint & VSplinePath::operator[](ptrdiff_t indx) { return path[indx]; } + +QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p3, QPointF &spl2p2) const +{ + if(Count() < 2) + { + throw VException(tr("Can't cut spline path with one point")); + } + + //Always need return two spline paths, so we must correct wrong length. + qreal fullLength = GetLength(); + if(length < fullLength * 0.02) + { + length = fullLength * 0.02; + qWarning()<<"Warning!!! Correction length of cutting. Length too small."; + } + else if ( length > fullLength * 0.98) + { + length = fullLength * 0.98; + qWarning()<<"Warning!!! Correction length of cutting. Length too small."; + } + + fullLength = 0; + for (qint32 i = 1; i <= Count(); ++i) + { + VSpline spl(&points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), path[i-1].KAsm2(), + path[i].KAsm1(), kCurve); + fullLength += spl.GetLength(); + if(fullLength > length) + { + p1 = i-1; + p2 = i; + QPointF spl1p2, spl2p3; + return spl.CutSpline(length - (fullLength - spl.GetLength()), spl1p2, spl1p3, spl2p2, spl2p3); + } + } + return QPointF(); +} diff --git a/src/geometry/vsplinepath.h b/src/geometry/vsplinepath.h index 446c0d7e4..22a294a9d 100644 --- a/src/geometry/vsplinepath.h +++ b/src/geometry/vsplinepath.h @@ -186,6 +186,16 @@ public: * @param name */ void setName(const QString &name) {_name = name;} + /** + * @brief CutSplinePath + * @param length + * @param p1 + * @param p2 + * @param spl1p3 + * @param spl2p2 + * @return + */ + QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p3, QPointF &spl2p2) const; protected: /** * @brief path вектор з точок сплайна. diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index abd97ea9c..828c8261e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -57,6 +57,7 @@ MainWindow::MainWindow(QWidget *parent) dialogDetail(QSharedPointer()), dialogHeight(QSharedPointer()), dialogTriangle(QSharedPointer()), dialogPointOfIntersection(QSharedPointer()), + dialogCutSpline(QSharedPointer()), dialogCutSplinePath (QSharedPointer()), dialogHistory(0), doc(0), data(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), mode(Draw::Calculation) { @@ -104,6 +105,8 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->toolButtonHeight, &QToolButton::clicked, this, &MainWindow::ToolHeight); connect(ui->toolButtonTriangle, &QToolButton::clicked, this, &MainWindow::ToolTriangle); connect(ui->toolButtonPointOfIntersection, &QToolButton::clicked, this, &MainWindow::ToolPointOfIntersection); + connect(ui->toolButtonSplineCutPoint, &QToolButton::clicked, this, &MainWindow::ToolCutSpline); + connect(ui->toolButtonSplinePathCutPoint, &QToolButton::clicked, this, &MainWindow::ToolCutSplinePath); data = new VContainer; @@ -381,6 +384,17 @@ void MainWindow::ClosedDialogSpline(int result) ClosedDialog(dialogSpline, result); } +void MainWindow::ToolCutSpline(bool checked) +{ + SetToolButton(checked, Tool::CutSplineTool, ":/cursor/spline_cut_point_cursor.png", + tr("Select simple curve"), dialogCutSpline, &MainWindow::ClosedDialogCutSpline); +} + +void MainWindow::ClosedDialogCutSpline(int result) +{ + ClosedDialog(dialogCutSpline, result); +} + void MainWindow::ToolArc(bool checked) { SetToolButton(checked, Tool::ArcTool, ":/cursor/arc_cursor.png", @@ -395,8 +409,7 @@ void MainWindow::ClosedDialogArc(int result) void MainWindow::ToolSplinePath(bool checked) { SetToolButton(checked, Tool::SplinePathTool, ":/cursor/splinepath_cursor.png", - tr("Select point of curve path"), dialogSplinePath, - &MainWindow::ClosedDialogSplinePath); + tr("Select point of curve path"), dialogSplinePath, &MainWindow::ClosedDialogSplinePath); } void MainWindow::ClosedDialogSplinePath(int result) @@ -404,6 +417,17 @@ void MainWindow::ClosedDialogSplinePath(int result) ClosedDialog(dialogSplinePath, result); } +void MainWindow::ToolCutSplinePath(bool checked) +{ + SetToolButton(checked, Tool::CutSplinePathTool, ":/cursor/splinepath_cut_point_cursor.png", + tr("Select curve path"), dialogCutSplinePath, &MainWindow::ClosedDialogCutSplinePath); +} + +void MainWindow::ClosedDialogCutSplinePath(int result) +{ + ClosedDialog(dialogCutSplinePath, result); +} + void MainWindow::ToolPointOfContact(bool checked) { SetToolButton(checked, Tool::PointOfContact, ":/cursor/pointcontact_cursor.png", @@ -762,6 +786,18 @@ void MainWindow::CanselTool() currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; + case Tool::CutSplineTool: + dialogCutSpline.clear(); + ui->toolButtonSplineCutPoint->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::CutSplinePathTool: + dialogCutSplinePath.clear(); + ui->toolButtonSplinePathCutPoint->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; default: qWarning()<<"Get wrong tool type. Ignore."; break; @@ -1054,6 +1090,8 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonHeight->setEnabled(enable); ui->toolButtonTriangle->setEnabled(enable); ui->toolButtonPointOfIntersection->setEnabled(enable); + ui->toolButtonSplineCutPoint->setEnabled(enable); + ui->toolButtonSplinePathCutPoint->setEnabled(enable); } void MainWindow::MinimumScrollBar() diff --git a/src/mainwindow.h b/src/mainwindow.h index bdd4fb190..63340c050 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -188,6 +188,11 @@ public slots: * @param checked */ void ToolSpline(bool checked); + /** + * @brief ToolCutSpline handler tool CutSpline + * @param checked true - button is checked + */ + void ToolCutSpline(bool checked); /** * @brief ToolArc * @param checked @@ -198,6 +203,11 @@ public slots: * @param checked */ void ToolSplinePath(bool checked); + /** + * @brief ToolCutSplinePath handler tool CutSplinePath + * @param checked true - button is checked + */ + void ToolCutSplinePath(bool checked); /** * @brief ToolPointOfContact * @param checked @@ -273,6 +283,11 @@ public slots: * @param result */ void ClosedDialogSplinePath(int result); + /** + * @brief ClosedDialogCutSplinePath handler close event tool CutSplinePath + * @param result result of working of dialog + */ + void ClosedDialogCutSplinePath(int result); /** * @brief ClosedDialogPointOfContact * @param result @@ -298,6 +313,11 @@ public slots: * @param result */ void ClosedDialogPointOfIntersection(int result); + /** + * @brief ClosedDialogCutSpline handler close event tool CutSpline + * @param result result of working of dialog + */ + void ClosedDialogCutSpline(int result); /** * @brief About */ @@ -444,6 +464,14 @@ private: * @brief dialogPointOfIntersection */ QSharedPointer dialogPointOfIntersection; + /** + * @brief dialogCutSpline pointer to the dialog tool cut spline + */ + QSharedPointer dialogCutSpline; + /** + * @brief dialogCutSplinePath pointer to the dialog tool cut spline path + */ + QSharedPointer dialogCutSplinePath; /** * @brief dialogHistory */ diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 2ea6899fd..da9da5efe 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -14,7 +14,7 @@ Valentina - + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png @@ -40,7 +40,7 @@ - 0 + 2 @@ -76,7 +76,7 @@ ... - + :/icon/32x32/segment.png:/icon/32x32/segment.png @@ -102,7 +102,7 @@ ... - + :/icon/32x32/shoulder.png:/icon/32x32/shoulder.png @@ -128,7 +128,7 @@ ... - + :/icon/32x32/point_of_contact.png:/icon/32x32/point_of_contact.png @@ -154,7 +154,7 @@ ... - + :/icon/32x32/bisector.png:/icon/32x32/bisector.png @@ -180,7 +180,7 @@ ... - + :/icon/32x32/normal.png:/icon/32x32/normal.png @@ -206,7 +206,7 @@ ... - + :/icon/32x32/along_line.png:/icon/32x32/along_line.png @@ -232,7 +232,7 @@ ... - + :/icon/32x32/height.png:/icon/32x32/height.png @@ -258,7 +258,7 @@ ... - + :/icon/32x32/triangle.png:/icon/32x32/triangle.png @@ -281,7 +281,7 @@ ... - + :/icon/32x32/point_of_intersection.png:/icon/32x32/point_of_intersection.png @@ -331,7 +331,7 @@ ... - + :/icon/32x32/line.png:/icon/32x32/line.png @@ -357,7 +357,7 @@ ... - + :/icon/32x32/intersect.png:/icon/32x32/intersect.png @@ -379,7 +379,7 @@ 0 0 150 - 58 + 104 @@ -407,7 +407,7 @@ ... - + :/icon/32x32/spline.png:/icon/32x32/spline.png @@ -433,7 +433,7 @@ ... - + :/icon/32x32/splinePath.png:/icon/32x32/splinePath.png @@ -447,6 +447,58 @@ + + + + false + + + Tool cut path curve. + + + ... + + + + :/icon/32x32/splinePath_cut_point.png:/icon/32x32/splinePath_cut_point.png + + + + 32 + 32 + + + + true + + + + + + + false + + + Tool cut curve. + + + ... + + + + :/icon/32x32/spline_cut_point.png:/icon/32x32/spline_cut_point.png + + + + 32 + 32 + + + + true + + + @@ -483,7 +535,7 @@ ... - + :/icon/32x32/arc.png:/icon/32x32/arc.png @@ -530,7 +582,7 @@ ... - + :/icon/32x32/new_detail.png:/icon/32x32/new_detail.png @@ -723,7 +775,7 @@ false - + :/icon/32x32/draw.png:/icon/32x32/draw.png @@ -741,7 +793,7 @@ false - + :/icon/32x32/kontur.png:/icon/32x32/kontur.png @@ -759,7 +811,7 @@ true - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -771,7 +823,7 @@ - + :/icon/32x32/new_draw.png:/icon/32x32/new_draw.png @@ -783,7 +835,7 @@ - + :/icon/32x32/option_draw.png:/icon/32x32/option_draw.png @@ -798,7 +850,7 @@ true - + :/icon/32x32/table.png:/icon/32x32/table.png @@ -813,7 +865,7 @@ true - + :/icon/32x32/history.png:/icon/32x32/history.png @@ -822,7 +874,7 @@ - + :/icon/32x32/layout.png:/icon/32x32/layout.png @@ -864,7 +916,7 @@ toolButtonNewDetail - + diff --git a/src/options.h b/src/options.h index 6f86d23d2..52881be48 100644 --- a/src/options.h +++ b/src/options.h @@ -65,8 +65,10 @@ namespace Tool BisectorTool, LineIntersectTool, SplineTool, + CutSplineTool, ArcTool, SplinePathTool, + CutSplinePathTool, PointOfContact, Detail, NodePoint, diff --git a/src/tools/drawTools/drawtools.h b/src/tools/drawTools/drawtools.h index b0102c570..d67adda4d 100644 --- a/src/tools/drawTools/drawtools.h +++ b/src/tools/drawTools/drawtools.h @@ -44,5 +44,7 @@ #include "vtoolheight.h" #include "vtooltriangle.h" #include "vtoolpointofintersection.h" +#include "vtoolcutspline.h" +#include "vtoolcutsplinepath.h" #endif // DRAWTOOLS_H diff --git a/src/tools/drawTools/vtoolcutspline.cpp b/src/tools/drawTools/vtoolcutspline.cpp new file mode 100644 index 000000000..cb18aae95 --- /dev/null +++ b/src/tools/drawTools/vtoolcutspline.cpp @@ -0,0 +1,247 @@ +/************************************************************************ + ** + ** @file vtoolcutspline.cpp + ** @author Roman Telezhinsky + ** @date 15 12, 2013 + ** + ** @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) 2013 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 "vtoolcutspline.h" +#include "../../container/calculator.h" + +const QString VToolCutSpline::ToolType = QStringLiteral("cutSpline"); +const QString VToolCutSpline::AttrSpline = QStringLiteral("spline"); + +VToolCutSpline::VToolCutSpline(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &formula, + const qint64 &splineId, const qint64 &spl1id, const qint64 &spl2id, + const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VToolPoint(doc, data, id, parent), formula(formula), splineId(splineId), + dialogCutSpline(QSharedPointer()), firstSpline(), secondSpline(), spl1id(spl1id), spl2id(spl2id) +{ + Q_ASSERT_X(splineId > 0, Q_FUNC_INFO, "splineId <= 0"); + Q_ASSERT_X(spl1id > 0, Q_FUNC_INFO, "spl1id <= 0"); + Q_ASSERT_X(spl2id > 0, Q_FUNC_INFO, "spl2id <= 0"); + + firstSpline = new VSimpleSpline(spl1id, &factor, ¤tColor); + Q_ASSERT(firstSpline != 0); + RefreshSpline(firstSpline, spl1id, SimpleSpline::ForthPoint); + firstSpline->setParentItem(this); + connect(firstSpline, &VSimpleSpline::Choosed, this, &VToolCutSpline::SplineChoosed); + + secondSpline = new VSimpleSpline(spl2id, &factor, ¤tColor); + Q_ASSERT(secondSpline != 0); + RefreshSpline(secondSpline, spl2id, SimpleSpline::FirstPoint); + secondSpline->setParentItem(this); + connect(secondSpline, &VSimpleSpline::Choosed, this, &VToolCutSpline::SplineChoosed); + + if (typeCreation == Tool::FromGui) + { + AddToFile(); + } +} + +void VToolCutSpline::setDialog() +{ + Q_ASSERT(dialogCutSpline.isNull() == false); + VPointF point = VAbstractTool::data.GetPoint(id); + dialogCutSpline->setFormula(formula); + dialogCutSpline->setSplineId(splineId, id); + dialogCutSpline->setPointName(point.name()); +} + +void VToolCutSpline::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data) +{ + QString pointName = dialog->getPointName(); + QString formula = dialog->getFormula(); + qint64 splineId = dialog->getSplineId(); + Create(0, pointName, formula, splineId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); +} + +void VToolCutSpline::Create(const qint64 _id, const QString &pointName, + const QString &formula, const qint64 &splineId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation) +{ + VSpline spl = data->GetSpline(splineId); + Calculator cal(data); + QString errorMsg; + qreal result = cal.eval(formula, &errorMsg); + if (errorMsg.isEmpty()) + { + QPointF spl1p2, spl1p3, spl2p2, spl2p3; + QPointF point = spl.CutSpline(toPixel(result), spl1p2, spl1p3, spl2p2, spl2p3); + + qint64 id = _id; + qint64 spl1id = 0; + qint64 spl2id = 0; + if (typeCreation == Tool::FromGui) + { + id = data->AddPoint(VPointF(point.x(), point.y(), pointName, mx, my)); + spl1id = id + 1; + spl2id = id + 2; + + VSpline spline1 = VSpline(data->DataPoints(), spl.GetP1(), spl1p2, spl1p3, id, spl.GetKcurve()); + spl1id = data->AddSpline(spline1); + data->AddLengthSpline(spline1.name(), toMM(spline1.GetLength())); + + VSpline spline2 = VSpline(data->DataPoints(), id, spl2p2, spl2p3, spl.GetP4(), spl.GetKcurve()); + spl2id = data->AddSpline(spline2); + data->AddLengthSpline(spline2.name(), toMM(spline2.GetLength())); + } + else + { + data->UpdatePoint(id, VPointF(point.x(), point.y(), pointName, mx, my)); + + spl1id = id + 1; + spl2id = id + 2; + + VSpline spline1 = VSpline(data->DataPoints(), spl.GetP1(), spl1p2, spl1p3, id, spl.GetKcurve()); + data->UpdateSpline(spl1id, spline1); + data->AddLengthSpline(spline1.name(), toMM(spline1.GetLength())); + + VSpline spline2 = VSpline(data->DataPoints(), id, spl2p2, spl2p3, spl.GetP4(), spl.GetKcurve()); + data->UpdateSpline(spl2id, spline2); + data->AddLengthSpline(spline2.name(), toMM(spline2.GetLength())); + + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + //VDrawTool::AddRecord(id, Tool::CutSplineTool, doc); + if (parse == Document::FullParse) + { + VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, spl1id, spl2id, typeCreation); + scene->addItem(point); + connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(point, &VToolPoint::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor); + doc->AddTool(id, point); + doc->AddTool(spl1id, point); + doc->AddTool(spl2id, point); + doc->IncrementReferens(splineId); + } + } +} + +void VToolCutSpline::FullUpdateFromFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + formula = domElement.attribute(AttrLength, ""); + splineId = domElement.attribute(AttrSpline, "").toLongLong(); + } + RefreshGeometry(); +} + +void VToolCutSpline::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogCutSpline->getPointName()); + domElement.setAttribute(AttrLength, dialogCutSpline->getFormula()); + domElement.setAttribute(AttrSpline, QString().setNum(dialogCutSpline->getSplineId())); + emit FullUpdateTree(); + } + } + dialogCutSpline.clear(); +} + +void VToolCutSpline::SplineChoosed(qint64 id) +{ + emit ChoosedTool(id, Scene::Spline); +} + +void VToolCutSpline::ChangedActivDraw(const QString &newName) +{ + if (nameActivDraw == newName) + { + currentColor = Qt::black; + firstSpline->setFlag(QGraphicsItem::ItemIsSelectable, true); + firstSpline->setAcceptHoverEvents(true); + secondSpline->setFlag(QGraphicsItem::ItemIsSelectable, true); + secondSpline->setAcceptHoverEvents(true); + } + else + { + currentColor = Qt::gray; + firstSpline->setFlag(QGraphicsItem::ItemIsSelectable, false); + firstSpline->setAcceptHoverEvents(false); + secondSpline->setFlag(QGraphicsItem::ItemIsSelectable, false); + secondSpline->setAcceptHoverEvents(false); + } + firstSpline->setPen(QPen(currentColor, widthHairLine/factor)); + secondSpline->setPen(QPen(currentColor, widthHairLine/factor)); + VToolPoint::ChangedActivDraw(newName); +} + +void VToolCutSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(dialogCutSpline, this, event); +} + +void VToolCutSpline::AddToFile() +{ + VPointF point = VAbstractTool::data.GetPoint(id); + QDomElement domElement = doc->createElement(TagName); + + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); + + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrSpline, splineId); + + AddToCalculation(domElement); +} + +void VToolCutSpline::RefreshGeometry() +{ + RefreshSpline(firstSpline, spl1id, SimpleSpline::ForthPoint); + RefreshSpline(secondSpline, spl2id, SimpleSpline::FirstPoint); + VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id)); +} + +void VToolCutSpline::RefreshSpline(VSimpleSpline *spline, qint64 splid, SimpleSpline::Translation tr) +{ + VSpline spl = VAbstractTool::data.GetSpline(splid); + QPainterPath path; + path.addPath(spl.GetPath()); + path.setFillRule( Qt::WindingFill ); + if(tr == SimpleSpline::FirstPoint) + { + path.translate(-spl.GetPointP1().toQPointF().x(), -spl.GetPointP1().toQPointF().y()); + } + else + { + path.translate(-spl.GetPointP4().toQPointF().x(), -spl.GetPointP4().toQPointF().y()); + } + spline->setPath(path); +} diff --git a/src/tools/drawTools/vtoolcutspline.h b/src/tools/drawTools/vtoolcutspline.h new file mode 100644 index 000000000..37857ae36 --- /dev/null +++ b/src/tools/drawTools/vtoolcutspline.h @@ -0,0 +1,149 @@ +/************************************************************************ + ** + ** @file vtoolcutspline.h + ** @author Roman Telezhinsky + ** @date 15 12, 2013 + ** + ** @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) 2013 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 VTOOLCUTSPLINE_H +#define VTOOLCUTSPLINE_H + +#include "vtoolpoint.h" +#include "../../dialogs/dialogcutspline.h" +#include "../../widgets/vsimplespline.h" + +/** + * @brief The VToolCutSpline class for tool CutSpline. This tool find point on spline and cut spline on two. + */ +class VToolCutSpline : public VToolPoint +{ + Q_OBJECT +public: + /** + * @brief VToolCutSpline + * @param doc + * @param data + * @param id + * @param formula + * @param splineId + * @param typeCreation + * @param parent + */ + VToolCutSpline(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &formula, + const qint64 &splineId, const qint64 &spl1id, const qint64 &spl2id, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + /** + * @brief setDialog + */ + virtual void setDialog(); + /** + * @brief Create + * @param dialog + * @param scene + * @param doc dom document container + * @param data + */ + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + /** + * @brief Create + * @param _id + * @param pointName + * @param formula + * @param splineId + * @param mx + * @param my + * @param scene + * @param doc dom document container + * @param data + * @param parse + * @param typeCreation + */ + static void Create(const qint64 _id, const QString &pointName, + const QString &formula, const qint64 &splineId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + /** + * @brief ToolType + */ + static const QString ToolType; + static const QString AttrSpline; +public slots: + /** + * @brief FullUpdateFromFile + */ + virtual void FullUpdateFromFile(); + /** + * @brief FullUpdateFromGui + * @param result + */ + virtual void FullUpdateFromGui(int result); + /** + * @brief SplineChoosed + * @param id + */ + void SplineChoosed(qint64 id); + /** + * @brief ChangedActivDraw + * @param newName + */ + virtual void ChangedActivDraw(const QString &newName); +protected: + /** + * @brief contextMenuEvent + * @param event + */ + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + /** + * @brief AddToFile + */ + virtual void AddToFile(); + void RefreshGeometry(); +private: + /** + * @brief formula keep formula of length + */ + QString formula; + /** + * @brief splineId keep id of spline + */ + qint64 splineId; + /** + * @brief DialogCutSpline pointer to the tool's dialog + */ + QSharedPointer dialogCutSpline; + /** + * @brief firstSpline + */ + VSimpleSpline *firstSpline; + /** + * @brief secondSpline + */ + VSimpleSpline *secondSpline; + const qint64 spl1id; + const qint64 spl2id; + void RefreshSpline(VSimpleSpline *spline, qint64 splid, SimpleSpline::Translation tr); +}; + +#endif // VTOOLCUTSPLINE_H diff --git a/src/tools/drawTools/vtoolcutsplinepath.cpp b/src/tools/drawTools/vtoolcutsplinepath.cpp new file mode 100644 index 000000000..e7bac0db7 --- /dev/null +++ b/src/tools/drawTools/vtoolcutsplinepath.cpp @@ -0,0 +1,124 @@ +/************************************************************************ + ** + ** @file vtoolcutsplinepath.cpp + ** @author Roman Telezhinsky + ** @date 15 12, 2013 + ** + ** @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) 2013 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 "vtoolcutsplinepath.h" + +const QString VToolCutSplinePath::ToolType = QStringLiteral("cutSplinePath"); +const QString VToolCutSplinePath::AttrSplinePath = QStringLiteral("splinePath"); + +VToolCutSplinePath::VToolCutSplinePath(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &formula, const qint64 &splinePathId, + const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VToolPoint(doc, data, id, parent), formula(formula), splinePathId(splinePathId), + dialogCutSplinePath(QSharedPointer()), firstSplinePath(), secondSplinePath() +{ + Q_ASSERT_X(splinePathId > 0, Q_FUNC_INFO, "splinePathId <= 0"); + if (typeCreation == Tool::FromGui) + { + AddToFile(); + } +} + +void VToolCutSplinePath::setDialog() +{ + Q_ASSERT(dialogCutSplinePath.isNull() == false); + VPointF point = VAbstractTool::data.GetPoint(id); + dialogCutSplinePath->setFormula(formula); + dialogCutSplinePath->setSplinePathId(splinePathId, id); + dialogCutSplinePath->setPointName(point.name()); +} + +void VToolCutSplinePath::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data) +{ + QString pointName = dialog->getPointName(); + QString formula = dialog->getFormula(); + qint64 splinePathId = dialog->getSplinePathId(); + Create(0, pointName, formula, splinePathId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); +} + +void VToolCutSplinePath::Create(const qint64 _id, const QString &pointName, const QString &formula, + const qint64 &splinePathId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation) +{ + +} + +void VToolCutSplinePath::FullUpdateFromFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + formula = domElement.attribute(AttrLength, ""); + splinePathId = domElement.attribute(AttrSplinePath, "").toLongLong(); + } + RefreshGeometry(); +} + +void VToolCutSplinePath::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogCutSplinePath->getPointName()); + domElement.setAttribute(AttrLength, dialogCutSplinePath->getFormula()); + domElement.setAttribute(AttrSplinePath, QString().setNum(dialogCutSplinePath->getSplinePathId())); + emit FullUpdateTree(); + } + } + dialogCutSplinePath.clear(); +} + +void VToolCutSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(dialogCutSplinePath, this, event); +} + +void VToolCutSplinePath::AddToFile() +{ + VPointF point = VAbstractTool::data.GetPoint(id); + QDomElement domElement = doc->createElement(TagName); + + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); + + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrSplinePath, splinePathId); + + AddToCalculation(domElement); +} + +void VToolCutSplinePath::RefreshGeometry() +{ + VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id)); +} diff --git a/src/tools/drawTools/vtoolcutsplinepath.h b/src/tools/drawTools/vtoolcutsplinepath.h new file mode 100644 index 000000000..8220cedf2 --- /dev/null +++ b/src/tools/drawTools/vtoolcutsplinepath.h @@ -0,0 +1,122 @@ +/************************************************************************ + ** + ** @file vtoolcutsplinepath.h + ** @author Roman Telezhinsky + ** @date 15 12, 2013 + ** + ** @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) 2013 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 VTOOLCUTSPLINEPATH_H +#define VTOOLCUTSPLINEPATH_H + +#include "vtoolpoint.h" +#include "../../dialogs/dialogcutsplinepath.h" +#include "../../widgets/vsimplesplinepath.h" + +class VToolCutSplinePath : public VToolPoint +{ + Q_OBJECT +public: + VToolCutSplinePath(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &formula, + const qint64 &splinePathId, const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + /** + * @brief setDialog + */ + virtual void setDialog(); + /** + * @brief Create + * @param dialog + * @param scene + * @param doc dom document container + * @param data + */ + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data); + /** + * @brief Create + * @param _id + * @param pointName + * @param formula + * @param splineId + * @param mx + * @param my + * @param scene + * @param doc dom document container + * @param data + * @param parse + * @param typeCreation + */ + static void Create(const qint64 _id, const QString &pointName, const QString &formula, + const qint64 &splinePathId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); + /** + * @brief ToolType + */ + static const QString ToolType; + static const QString AttrSplinePath; +public slots: + /** + * @brief FullUpdateFromFile + */ + virtual void FullUpdateFromFile(); + /** + * @brief FullUpdateFromGui + * @param result + */ + virtual void FullUpdateFromGui(int result); +protected: + /** + * @brief contextMenuEvent + * @param event + */ + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + /** + * @brief AddToFile + */ + virtual void AddToFile(); + void RefreshGeometry(); +private: + /** + * @brief formula keep formula of length + */ + QString formula; + /** + * @brief splineId keep id of spline + */ + qint64 splinePathId; + /** + * @brief DialogCutSpline pointer to the tool's dialog + */ + QSharedPointer dialogCutSplinePath; + /** + * @brief firstSplinePath + */ + VSimpleSplinePath *firstSplinePath; + /** + * @brief secondSplinePath + */ + VSimpleSplinePath *secondSplinePath; +}; + +#endif // VTOOLCUTSPLINEPATH_H diff --git a/src/tools/drawTools/vtoolendline.h b/src/tools/drawTools/vtoolendline.h index 35c802911..a43938d7e 100644 --- a/src/tools/drawTools/vtoolendline.h +++ b/src/tools/drawTools/vtoolendline.h @@ -113,7 +113,7 @@ protected: virtual void AddToFile(); private: /** - * @brief dialogEndLine + * @brief dialogEndLine pointer to the dialog */ QSharedPointer dialogEndLine; }; diff --git a/src/tools/modelingTools/modelingtools.h b/src/tools/modelingTools/modelingtools.h index 3203357b1..e81d059fe 100644 --- a/src/tools/modelingTools/modelingtools.h +++ b/src/tools/modelingTools/modelingtools.h @@ -43,5 +43,7 @@ #include "vmodelingheight.h" #include "vmodelingtriangle.h" #include "vmodelingpointofintersection.h" +#include "vmodelingcutspline.h" +#include "vmodelingcutsplinepath.h" #endif // MODELINGTOOLS_H diff --git a/src/tools/modelingTools/vmodelingcutspline.cpp b/src/tools/modelingTools/vmodelingcutspline.cpp new file mode 100644 index 000000000..1fd66f2e8 --- /dev/null +++ b/src/tools/modelingTools/vmodelingcutspline.cpp @@ -0,0 +1,124 @@ +/************************************************************************ + ** + ** @file vmodelingcutspline.cpp + ** @author Roman Telezhinsky + ** @date 15 12, 2013 + ** + ** @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) 2013 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 "vmodelingcutspline.h" + +const QString VModelingCutSpline::ToolType = QStringLiteral("cutSpline"); +const QString VModelingCutSpline::AttrSpline = QStringLiteral("spline"); + +VModelingCutSpline::VModelingCutSpline(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &formula, const qint64 &splineId, + const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VModelingPoint(doc, data, id, parent), formula(formula), splineId(splineId), + dialogCutSpline(QSharedPointer()) +{ + Q_ASSERT_X(splineId > 0, Q_FUNC_INFO, "splineId <= 0"); + if (typeCreation == Tool::FromGui) + { + AddToFile(); + } +} + +void VModelingCutSpline::setDialog() +{ + Q_ASSERT(dialogCutSpline.isNull() == false); + VSpline spl = VAbstractTool::data.GetSplineModeling(id); + dialogCutSpline->setFormula(formula); + dialogCutSpline->setSplineId(splineId, id); + dialogCutSpline->setPointName(spl.name()); +} + +VModelingCutSpline *VModelingCutSpline::Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data) +{ + QString pointName = dialog->getPointName(); + QString formula = dialog->getFormula(); + qint64 splineId = dialog->getSplineId(); + return Create(0, pointName, formula, splineId, 5, 10, doc, data, Document::FullParse, Tool::FromGui); +} + +VModelingCutSpline *VModelingCutSpline::Create(const qint64 _id, const QString &pointName, const QString &formula, + const qint64 &splineId, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation) +{ + +} + +void VModelingCutSpline::FullUpdateFromFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + formula = domElement.attribute(AttrLength, ""); + splineId = domElement.attribute(AttrSpline, "").toLongLong(); + } + RefreshGeometry(); +} + +void VModelingCutSpline::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogCutSpline->getPointName()); + domElement.setAttribute(AttrLength, dialogCutSpline->getFormula()); + domElement.setAttribute(AttrSpline, QString().setNum(dialogCutSpline->getSplineId())); + emit FullUpdateTree(); + } + } + dialogCutSpline.clear(); +} + +void VModelingCutSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(dialogCutSpline, this, event); +} + +void VModelingCutSpline::AddToFile() +{ + VPointF point = VAbstractTool::data.GetPointModeling(id); + QDomElement domElement = doc->createElement(TagName); + + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); + + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrSpline, splineId); + + AddToModeling(domElement); +} + +void VModelingCutSpline::RefreshGeometry() +{ + VModelingPoint::RefreshPointGeometry(VModelingTool::data.GetPointModeling(id)); +} diff --git a/src/tools/modelingTools/vmodelingcutspline.h b/src/tools/modelingTools/vmodelingcutspline.h new file mode 100644 index 000000000..6c9a12471 --- /dev/null +++ b/src/tools/modelingTools/vmodelingcutspline.h @@ -0,0 +1,112 @@ +/************************************************************************ + ** + ** @file vmodelingcutspline.h + ** @author Roman Telezhinsky + ** @date 15 12, 2013 + ** + ** @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) 2013 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 VMODELINGCUTSPLINE_H +#define VMODELINGCUTSPLINE_H + +#include "vmodelingpoint.h" +#include "../../dialogs/dialogcutspline.h" + +class VModelingCutSpline: public VModelingPoint +{ + Q_OBJECT +public: + VModelingCutSpline(VDomDocument *doc, VContainer *data, const qint64 &id,const QString &formula, + const qint64 &splineId, const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + /** + * @brief setDialog + */ + virtual void setDialog(); + /** + * @brief Create + * @param dialog + * @param scene + * @param doc dom document container + * @param data + */ + static VModelingCutSpline* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + /** + * @brief Create + * @param _id + * @param pointName + * @param formula + * @param splineId + * @param mx + * @param my + * @param scene + * @param doc dom document container + * @param data + * @param parse + * @param typeCreation + */ + static VModelingCutSpline* Create(const qint64 _id, const QString &pointName, const QString &formula, + const qint64 &splineId, const qreal &mx, const qreal &my, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); + /** + * @brief ToolType + */ + static const QString ToolType; + static const QString AttrSpline; +public slots: + /** + * @brief FullUpdateFromFile + */ + virtual void FullUpdateFromFile(); + /** + * @brief FullUpdateFromGui + * @param result + */ + virtual void FullUpdateFromGui(int result); +protected: + /** + * @brief contextMenuEvent + * @param event + */ + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + /** + * @brief AddToFile + */ + virtual void AddToFile(); + void RefreshGeometry(); +private: + /** + * @brief formula keep formula of length + */ + QString formula; + /** + * @brief splineId keep id of spline + */ + qint64 splineId; + /** + * @brief DialogCutSpline pointer to the tool's dialog + */ + QSharedPointer dialogCutSpline; +}; + +#endif // VMODELINGCUTSPLINE_H diff --git a/src/tools/modelingTools/vmodelingcutsplinepath.cpp b/src/tools/modelingTools/vmodelingcutsplinepath.cpp new file mode 100644 index 000000000..e2536de86 --- /dev/null +++ b/src/tools/modelingTools/vmodelingcutsplinepath.cpp @@ -0,0 +1,126 @@ +/************************************************************************ + ** + ** @file vmodelingcutsplinepath.cpp + ** @author Roman Telezhinsky + ** @date 15 12, 2013 + ** + ** @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) 2013 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 "vmodelingcutsplinepath.h" + +const QString VModelingCutSplinePath::ToolType = QStringLiteral("cutSplinePath"); +const QString VModelingCutSplinePath::AttrSplinePath = QStringLiteral("splinePath"); + +VModelingCutSplinePath::VModelingCutSplinePath(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &formula, const qint64 &splinePathId, + const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VModelingPoint(doc, data, id, parent), formula(formula), splinePathId(splinePathId), + dialogCutSplinePath(QSharedPointer()) +{ + Q_ASSERT_X(splinePathId > 0, Q_FUNC_INFO, "splinePathId <= 0"); + if (typeCreation == Tool::FromGui) + { + AddToFile(); + } +} + +void VModelingCutSplinePath::setDialog() +{ + Q_ASSERT(dialogCutSplinePath.isNull() == false); + VSplinePath splPath = VAbstractTool::data.GetSplinePath(id); + dialogCutSplinePath->setFormula(formula); + dialogCutSplinePath->setSplinePathId(splinePathId, id); + dialogCutSplinePath->setPointName(splPath.name()); +} + +VModelingCutSplinePath *VModelingCutSplinePath::Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data) +{ + QString pointName = dialog->getPointName(); + QString formula = dialog->getFormula(); + qint64 splinePathId = dialog->getSplinePathId(); + return Create(0, pointName, formula, splinePathId, 5, 10, doc, data, Document::FullParse, Tool::FromGui); +} + +VModelingCutSplinePath *VModelingCutSplinePath::Create(const qint64 _id, const QString &pointName, + const QString &formula, const qint64 &splinePathId, + const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, + const Document::Documents &parse, + const Tool::Sources &typeCreation) +{ + +} + +void VModelingCutSplinePath::FullUpdateFromFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + formula = domElement.attribute(AttrLength, ""); + splinePathId = domElement.attribute(AttrSplinePath, "").toLongLong(); + } + RefreshGeometry(); +} + +void VModelingCutSplinePath::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogCutSplinePath->getPointName()); + domElement.setAttribute(AttrLength, dialogCutSplinePath->getFormula()); + domElement.setAttribute(AttrSplinePath, QString().setNum(dialogCutSplinePath->getSplinePathId())); + emit FullUpdateTree(); + } + } + dialogCutSplinePath.clear(); +} + +void VModelingCutSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(dialogCutSplinePath, this, event); +} + +void VModelingCutSplinePath::AddToFile() +{ + VPointF point = VAbstractTool::data.GetPointModeling(id); + QDomElement domElement = doc->createElement(TagName); + + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); + + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrSplinePath, splinePathId); + + AddToModeling(domElement); +} + +void VModelingCutSplinePath::RefreshGeometry() +{ + VModelingPoint::RefreshPointGeometry(VModelingTool::data.GetPointModeling(id)); +} diff --git a/src/tools/modelingTools/vmodelingcutsplinepath.h b/src/tools/modelingTools/vmodelingcutsplinepath.h new file mode 100644 index 000000000..10d5e13a1 --- /dev/null +++ b/src/tools/modelingTools/vmodelingcutsplinepath.h @@ -0,0 +1,113 @@ +/************************************************************************ + ** + ** @file vmodelingcutsplinepath.h + ** @author Roman Telezhinsky + ** @date 15 12, 2013 + ** + ** @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) 2013 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 VMODELINGCUTSPLINEPATH_H +#define VMODELINGCUTSPLINEPATH_H + +#include "vmodelingpoint.h" +#include "../../dialogs/dialogcutsplinepath.h" + +class VModelingCutSplinePath : public VModelingPoint +{ + Q_OBJECT +public: + VModelingCutSplinePath(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &formula, + const qint64 &splinePathId, const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + /** + * @brief setDialog + */ + virtual void setDialog(); + /** + * @brief Create + * @param dialog + * @param scene + * @param doc dom document container + * @param data + */ + static VModelingCutSplinePath* Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data); + /** + * @brief Create + * @param _id + * @param pointName + * @param formula + * @param splineId + * @param mx + * @param my + * @param scene + * @param doc dom document container + * @param data + * @param parse + * @param typeCreation + */ + static VModelingCutSplinePath* Create(const qint64 _id, const QString &pointName, const QString &formula, + const qint64 &splinePathId, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + /** + * @brief ToolType + */ + static const QString ToolType; + static const QString AttrSplinePath; +public slots: + /** + * @brief FullUpdateFromFile + */ + virtual void FullUpdateFromFile(); + /** + * @brief FullUpdateFromGui + * @param result + */ + virtual void FullUpdateFromGui(int result); +protected: + /** + * @brief contextMenuEvent + * @param event + */ + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + /** + * @brief AddToFile + */ + virtual void AddToFile(); + void RefreshGeometry(); +private: + /** + * @brief formula keep formula of length + */ + QString formula; + /** + * @brief splineId keep id of spline + */ + qint64 splinePathId; + /** + * @brief DialogCutSpline pointer to the tool's dialog + */ + QSharedPointer dialogCutSplinePath; +}; + +#endif // VMODELINGCUTSPLINEPATH_H diff --git a/src/tools/tools.pri b/src/tools/tools.pri index 513853538..e90288cde 100644 --- a/src/tools/tools.pri +++ b/src/tools/tools.pri @@ -45,7 +45,11 @@ HEADERS += \ src/tools/nodeDetails/vnodepoint.h \ src/tools/nodeDetails/vnodearc.h \ src/tools/nodeDetails/vabstractnode.h \ - src/tools/nodeDetails/nodedetails.h + src/tools/nodeDetails/nodedetails.h \ + src/tools/drawTools/vtoolcutspline.h \ + src/tools/modelingTools/vmodelingcutspline.h \ + src/tools/drawTools/vtoolcutsplinepath.h \ + src/tools/modelingTools/vmodelingcutsplinepath.h SOURCES += \ src/tools/vtooldetail.cpp \ @@ -90,4 +94,8 @@ SOURCES += \ src/tools/nodeDetails/vnodespline.cpp \ src/tools/nodeDetails/vnodepoint.cpp \ src/tools/nodeDetails/vnodearc.cpp \ - src/tools/nodeDetails/vabstractnode.cpp + src/tools/nodeDetails/vabstractnode.cpp \ + src/tools/drawTools/vtoolcutspline.cpp \ + src/tools/modelingTools/vmodelingcutspline.cpp \ + src/tools/drawTools/vtoolcutsplinepath.cpp \ + src/tools/modelingTools/vmodelingcutsplinepath.cpp diff --git a/src/widgets/vsimplespline.cpp b/src/widgets/vsimplespline.cpp new file mode 100644 index 000000000..ea70e8f0e --- /dev/null +++ b/src/widgets/vsimplespline.cpp @@ -0,0 +1,59 @@ +/************************************************************************ + ** + ** @file vsimplespline.cpp + ** @author Roman Telezhinsky + ** @date 17 12, 2013 + ** + ** @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) 2013 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 "vsimplespline.h" +#include "../options.h" + +VSimpleSpline::VSimpleSpline(qint64 id, qreal *factor, Qt::GlobalColor *currentColor, QObject *parent) + :QObject(parent), QGraphicsPathItem(), id (id), factor(factor), currentColor(currentColor) +{ + setPen(QPen(Qt::black, widthHairLine/ *factor)); + setFlag(QGraphicsItem::ItemIsSelectable, true); + setAcceptHoverEvents(true); +} + +void VSimpleSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + emit Choosed(id); + } + QGraphicsItem::mouseReleaseEvent(event); +} + +void VSimpleSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + this->setPen(QPen(*currentColor, widthMainLine/ *factor)); +} + +void VSimpleSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + this->setPen(QPen(*currentColor, widthHairLine/ *factor)); +} diff --git a/src/widgets/vsimplespline.h b/src/widgets/vsimplespline.h new file mode 100644 index 000000000..5802948fc --- /dev/null +++ b/src/widgets/vsimplespline.h @@ -0,0 +1,96 @@ +/************************************************************************ + ** + ** @file vsimplespline.h + ** @author Roman Telezhinsky + ** @date 17 12, 2013 + ** + ** @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) 2013 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 VSIMPLESPLINE_H +#define VSIMPLESPLINE_H + +#include + +namespace SimpleSpline +{ + /** + * @brief The Translation enum + */ + enum Translation { FirstPoint, ForthPoint }; + Q_DECLARE_FLAGS(Translations, Translation) +} +Q_DECLARE_OPERATORS_FOR_FLAGS( SimpleSpline::Translations ) + +/** + * @brief The VSimpleSpline class + */ +class VSimpleSpline : public QObject, public QGraphicsPathItem +{ + Q_OBJECT +public: + /** + * @brief VSimpleSpline + * @param id + * @param factor + * @param currentColor + * @param parent + */ + VSimpleSpline(qint64 id, qreal *factor, Qt::GlobalColor *currentColor, QObject *parent = 0); +signals: + /** + * @brief Choosed + * @param id + */ + void Choosed(qint64 id); +protected: + /** + * @brief mouseReleaseEvent + * @param event + */ + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + /** + * @brief hoverMoveEvent + * @param event + */ + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + /** + * @brief hoverLeaveEvent + * @param event + */ + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + /** + * @brief id + */ + qint64 id; + /** + * @brief factor + */ + qreal *factor; + /** + * @brief currentColor + */ + Qt::GlobalColor *currentColor; +}; + +#endif // VSIMPLESPLINE_H diff --git a/src/widgets/vsimplesplinepath.cpp b/src/widgets/vsimplesplinepath.cpp new file mode 100644 index 000000000..134e288ae --- /dev/null +++ b/src/widgets/vsimplesplinepath.cpp @@ -0,0 +1,55 @@ +/************************************************************************ + ** + ** @file vsimplesplinepath.cpp + ** @author Roman Telezhinsky + ** @date 17 12, 2013 + ** + ** @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) 2013 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 "vsimplesplinepath.h" + +VSimpleSplinePath::VSimpleSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qreal *factor, QObject *parent) + :VAbstractTool(doc, data, id, parent), factor(factor) +{ +} + +void VSimpleSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + emit ChoosedTool(id, Scene::SplinePath); + } + QGraphicsItem::mouseReleaseEvent(event); +} + +void VSimpleSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthMainLine/ *factor)); +} + +void VSimpleSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + this->setPen(QPen(currentColor, widthHairLine/ *factor)); +} diff --git a/src/widgets/vsimplesplinepath.h b/src/widgets/vsimplesplinepath.h new file mode 100644 index 000000000..a0b242af3 --- /dev/null +++ b/src/widgets/vsimplesplinepath.h @@ -0,0 +1,60 @@ +/************************************************************************ + ** + ** @file vsimplesplinepath.h + ** @author Roman Telezhinsky + ** @date 17 12, 2013 + ** + ** @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) 2013 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 VSIMPLESPLINEPATH_H +#define VSIMPLESPLINEPATH_H + +#include +#include "../tools/vabstracttool.h" + +class VSimpleSplinePath : public VAbstractTool, public QGraphicsPathItem +{ + Q_OBJECT +public: + VSimpleSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qreal *factor, QObject *parent = 0); +protected: + /** + * @brief mouseReleaseEvent + * @param event + */ + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + /** + * @brief hoverMoveEvent + * @param event + */ + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + /** + * @brief hoverLeaveEvent + * @param event + */ + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + qreal *factor; +}; + +#endif // VSIMPLESPLINEPATH_H diff --git a/src/widgets/widgets.pri b/src/widgets/widgets.pri index 6dbdb83e2..b4f16cf86 100644 --- a/src/widgets/widgets.pri +++ b/src/widgets/widgets.pri @@ -6,7 +6,9 @@ HEADERS += \ src/widgets/vgraphicssimpletextitem.h \ src/widgets/vcontrolpointspline.h \ src/widgets/vapplication.h \ - src/widgets/doubledelegate.h + src/widgets/doubledelegate.h \ + src/widgets/vsimplespline.h \ + src/widgets/vsimplesplinepath.h SOURCES += \ src/widgets/vtablegraphicsview.cpp \ @@ -16,4 +18,6 @@ SOURCES += \ src/widgets/vgraphicssimpletextitem.cpp \ src/widgets/vcontrolpointspline.cpp \ src/widgets/vapplication.cpp \ - src/widgets/doubledelegate.cpp + src/widgets/doubledelegate.cpp \ + src/widgets/vsimplespline.cpp \ + src/widgets/vsimplesplinepath.cpp diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index fe556678f..edb498d28 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -31,15 +31,12 @@ #include "../exception/vexceptionconversionerror.h" #include "../exception/vexceptionemptyparameter.h" #include "../exception/vexceptionuniqueid.h" -#include "../tools/vtooldetail.h" #include "../exception/vexceptionobjecterror.h" #include "../exception/vexceptionbadid.h" +#include "../tools/vtooldetail.h" #include "../tools/drawTools/drawtools.h" #include "../tools/modelingTools/modelingtools.h" -#include "../tools/nodeDetails/vnodepoint.h" -#include "../tools/nodeDetails/vnodespline.h" -#include "../tools/nodeDetails/vnodesplinepath.h" -#include "../tools/nodeDetails/vnodearc.h" +#include "../tools/nodeDetails/nodedetails.h" #include @@ -1104,6 +1101,64 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } + if (type == "cutSpline") + { + try + { + qint64 id = GetParametrId(domElement); + QString name = GetParametrString(domElement, "name"); + qreal mx = toPixel(GetParametrDouble(domElement, "mx")); + qreal my = toPixel(GetParametrDouble(domElement, "my")); + QString formula = GetParametrString(domElement, "length"); + qint64 splineId = GetParametrLongLong(domElement, "spline"); + if (mode == Draw::Calculation) + { + VToolCutSpline::Create(id, name, formula, splineId, mx, my, scene, this, data, parse, + Tool::FromFile); + } + else + { + VModelingCutSpline::Create(id, name, formula, splineId, mx, my, this, data, parse, + Tool::FromFile); + } + return; + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating cut spline point"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + } + if (type == "cutSplinePath") + { + try + { + qint64 id = GetParametrId(domElement); + QString name = GetParametrString(domElement, "name"); + qreal mx = toPixel(GetParametrDouble(domElement, "mx")); + qreal my = toPixel(GetParametrDouble(domElement, "my")); + QString formula = GetParametrString(domElement, "length"); + qint64 splinePathId = GetParametrLongLong(domElement, "splinePath"); + if (mode == Draw::Calculation) + { + VToolCutSplinePath::Create(id, name, formula, splinePathId, mx, my, scene, this, data, parse, + Tool::FromFile); + } + else + { + VModelingCutSplinePath::Create(id, name, formula, splinePathId, mx, my, this, data, parse, + Tool::FromFile); + } + return; + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating cut spline path point"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + } } void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement,