From 19265e1f93ebc2cf7f3f99bc9cab34fef8ce0863 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 18 Mar 2016 23:11:14 +0200 Subject: [PATCH] Succesful build. --HG-- branch : feature --- .../core/vtooloptionspropertybrowser.cpp | 62 ++++ .../core/vtooloptionspropertybrowser.h | 3 + src/app/valentina/mainwindow.cpp | 6 +- src/app/valentina/xml/vpattern.cpp | 72 +++- src/app/valentina/xml/vpattern.h | 1 + src/libs/vgeometry/vpointf.h | 3 + src/libs/vtools/dialogs/dialogs.pri | 9 +- src/libs/vtools/dialogs/tooldialogs.h | 1 + .../dialogs/tools/dialogcubicbezierpath.cpp | 312 ++++++++++++++++++ .../dialogs/tools/dialogcubicbezierpath.h | 80 +++++ .../dialogs/tools/dialogcubicbezierpath.ui | 130 ++++++++ src/libs/vtools/tools/drawTools/drawtools.h | 1 + .../tools/drawTools/toolcurve/vtoolarc.h | 2 +- .../drawTools/toolcurve/vtoolarcwithlength.h | 2 +- .../drawTools/toolcurve/vtoolcubicbezier.h | 2 +- .../toolcurve/vtoolcubicbezierpath.cpp | 254 ++++++++++++++ .../toolcurve/vtoolcubicbezierpath.h | 73 ++++ .../tools/drawTools/toolcurve/vtoolspline.h | 2 +- .../drawTools/toolcurve/vtoolsplinepath.cpp | 6 +- .../drawTools/toolcurve/vtoolsplinepath.h | 5 +- src/libs/vtools/tools/tools.pri | 6 +- .../visualization/vistoolcubicbezierpath.cpp | 206 ++++++++++++ .../visualization/vistoolcubicbezierpath.h | 65 ++++ .../vtools/visualization/vistoolsplinepath.h | 2 +- .../vtools/visualization/visualization.cpp | 3 +- src/libs/vtools/visualization/visualization.h | 2 +- .../vtools/visualization/visualization.pri | 6 +- 27 files changed, 1289 insertions(+), 27 deletions(-) create mode 100644 src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp create mode 100644 src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h create mode 100644 src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui create mode 100644 src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp create mode 100644 src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h create mode 100644 src/libs/vtools/visualization/vistoolcubicbezierpath.cpp create mode 100644 src/libs/vtools/visualization/vistoolcubicbezierpath.h diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 303c70c25..b508af5f5 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -73,6 +73,9 @@ void VToolOptionsPropertyBrowser::ClearPropertyBrowser() //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) { + // This check helps to find missed tools in the switch + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in switch."); + switch (item->type()) { case VToolBasePoint::Type: @@ -141,6 +144,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolSplinePath::Type: ShowOptionsToolSplinePath(item); break; + case VToolCubicBezierPath::Type: + ShowOptionsToolCubicBezierPath(item); + break; case VToolTriangle::Type: ShowOptionsToolTriangle(item); break; @@ -184,6 +190,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() return; } + // This check helps to find missed tools in the switch + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in switch."); + switch (currentItem->type()) { case VToolBasePoint::Type: @@ -252,6 +261,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VToolSplinePath::Type: UpdateOptionsToolSplinePath(); break; + case VToolCubicBezierPath::Type: + UpdateOptionsToolCubicBezierPath(); + break; case VToolTriangle::Type: UpdateOptionsToolTriangle(); break; @@ -310,6 +322,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) return; } + // This check helps to find missed tools in the switch + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in switch."); + switch (currentItem->type()) { case VToolBasePoint::Type: @@ -378,6 +393,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolSplinePath::Type: ChangeDataToolSplinePath(prop); break; + case VToolCubicBezierPath::Type: + ChangeDataToolCubicBezierPath(prop); + break; case VToolTriangle::Type: ChangeDataToolTriangle(prop); break; @@ -1404,6 +1422,30 @@ void VToolOptionsPropertyBrowser::ChangeDataToolSplinePath(VProperty *property) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolCubicBezierPath(VProperty *property) +{ + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolCubicBezierPath *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // AttrName + Q_UNREACHABLE();//The attribute is read only + break; + case 27: // AttrTypeColor + i->SetLineColor(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool cubic bezier curve")); + + AddPropertyObjectName(i, tr("Name"), true); + AddPropertyLineColor(i, tr("Color"), VAbstractTool::ColorsList(), AttrColor); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolTriangle(QGraphicsItem *item) { @@ -2253,6 +2306,15 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSplinePath() idToProperty[AttrColor]->setValue(VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor())); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolCubicBezierPath() +{ + auto i = qgraphicsitem_cast(currentItem); + + idToProperty[AttrName]->setValue(i->name()); + idToProperty[AttrColor]->setValue(VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor())); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolTriangle() { diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index a4847e5dd..6ffd7a12b 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -140,6 +140,7 @@ private: void ChangeDataToolSpline(VPE::VProperty *property); void ChangeDataToolCubicBezier(VPE::VProperty *property); void ChangeDataToolSplinePath(VPE::VProperty *property); + void ChangeDataToolCubicBezierPath(VPE::VProperty *property); void ChangeDataToolTriangle(VPE::VProperty *property); void ChangeDataToolLineIntersectAxis(VPE::VProperty *property); void ChangeDataToolCurveIntersectAxis(VPE::VProperty *property); @@ -169,6 +170,7 @@ private: void ShowOptionsToolSpline(QGraphicsItem *item); void ShowOptionsToolCubicBezier(QGraphicsItem *item); void ShowOptionsToolSplinePath(QGraphicsItem *item); + void ShowOptionsToolCubicBezierPath(QGraphicsItem *item); void ShowOptionsToolTriangle(QGraphicsItem *item); void ShowOptionsToolLineIntersectAxis(QGraphicsItem *item); void ShowOptionsToolCurveIntersectAxis(QGraphicsItem *item); @@ -198,6 +200,7 @@ private: void UpdateOptionsToolSpline(); void UpdateOptionsToolCubicBezier(); void UpdateOptionsToolSplinePath(); + void UpdateOptionsToolCubicBezierPath(); void UpdateOptionsToolTriangle(); void UpdateOptionsToolLineIntersectAxis(); void UpdateOptionsToolCurveIntersectAxis(); diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index a52ca3972..2c6febaaa 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -833,7 +833,11 @@ void MainWindow::ToolSplinePath(bool checked) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolCubicBezierPath(bool checked) { - + SetToolButtonWithApply(checked, Tool::CubicBezierPath, + ":/cursor/cubic_bezier_path_cursor.png", + tr("Select point of cubic bezier path"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 01bde6c92..a7bad80df 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -44,6 +44,7 @@ #include "../vgeometry/varc.h" #include "../vgeometry/vsplinepath.h" #include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" #include "../core/vapplication.h" #include "../vpatterndb/calculator.h" @@ -2129,6 +2130,58 @@ void VPattern::ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParseToolCubicBezierPath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse) +{ + SCASSERT(scene != nullptr); + Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + + try + { + quint32 id = 0; + + ToolsCommonAttributes(domElement, id); + const QString color = GetParametrString(domElement, AttrColor, ColorBlack); + const quint32 duplicate = GetParametrUInt(domElement, AttrDuplicate, "0"); + + QVector points; + + const QDomNodeList nodeList = domElement.childNodes(); + const qint32 num = nodeList.size(); + for (qint32 i = 0; i < num; ++i) + { + const QDomElement element = nodeList.at(i).toElement(); + if (element.isNull() == false) + { + if (element.tagName() == AttrPathPoint) + { + const quint32 pSpline = GetParametrUInt(element, AttrPSpline, NULL_ID_STR); + const VPointF p = *data->GeometricObject(pSpline); + points.append(p); + if (parse == Document::FullParse) + { + IncrementReferens(p.getIdTool()); + } + } + } + } + + auto path = new VCubicBezierPath(points); + if (duplicate > 0) + { + path->SetDuplicate(duplicate); + } + + VToolCubicBezierPath::Create(id, path, color, scene, this, data, parse, Source::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating cubic bezier path curve"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPattern::ParseNodeSpline(const QDomElement &domElement, const Document &parse) { @@ -2425,13 +2478,14 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, QDomElement &domEle Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); - QStringList splines = QStringList() << VToolSpline::OldToolType /*0*/ - << VToolSpline::ToolType /*1*/ - << VToolSplinePath::OldToolType /*2*/ - << VToolSplinePath::ToolType /*3*/ - << VNodeSpline::ToolType /*4*/ - << VNodeSplinePath::ToolType /*5*/ - << VToolCubicBezier::ToolType; /*6*/ + QStringList splines = QStringList() << VToolSpline::OldToolType /*0*/ + << VToolSpline::ToolType /*1*/ + << VToolSplinePath::OldToolType /*2*/ + << VToolSplinePath::ToolType /*3*/ + << VNodeSpline::ToolType /*4*/ + << VNodeSplinePath::ToolType /*5*/ + << VToolCubicBezier::ToolType /*6*/ + << VToolCubicBezierPath::ToolType; /*7*/ switch (splines.indexOf(type)) { case 0: //VToolSpline::OldToolType @@ -2462,6 +2516,10 @@ void VPattern::ParseSplineElement(VMainGraphicsScene *scene, QDomElement &domEle qCDebug(vXML, "VToolCubicBezier."); ParseToolCubicBezier(scene, domElement, parse); break; + case 7: //VToolCubicBezierPath::ToolType + qCDebug(vXML, "VToolCubicBezierPath."); + ParseToolCubicBezierPath(scene, domElement, parse); + break; default: VException e(tr("Unknown spline type '%1'.").arg(type)); throw e; diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 481b0f353..8471662ca 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -176,6 +176,7 @@ private: void ParseOldToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); + void ParseToolCubicBezierPath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseNodeSpline(const QDomElement &domElement, const Document &parse); void ParseNodeSplinePath(const QDomElement &domElement, const Document &parse); diff --git a/src/libs/vgeometry/vpointf.h b/src/libs/vgeometry/vpointf.h index 04fa0d8ae..7494a1405 100644 --- a/src/libs/vgeometry/vpointf.h +++ b/src/libs/vgeometry/vpointf.h @@ -31,6 +31,8 @@ #include "vgobject.h" +#include + class QPointF; class QString; class VPointFData; @@ -69,6 +71,7 @@ private: QSharedDataPointer d; }; +Q_DECLARE_METATYPE(VPointF) Q_DECLARE_TYPEINFO(VPointF, Q_MOVABLE_TYPE); #if defined(Q_CC_INTEL) diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index a432d4e95..fd77d2ce3 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -35,7 +35,8 @@ HEADERS += \ $$PWD/support/dialogundo.h \ $$PWD/tools/dialogtruedarts.h \ $$PWD/tools/dialogpointofintersectioncurves.h \ - $$PWD/tools/dialogcubicbezier.h + $$PWD/tools/dialogcubicbezier.h \ + $$PWD/tools/dialogcubicbezierpath.h SOURCES += \ $$PWD/tools/dialogalongline.cpp \ @@ -70,7 +71,8 @@ SOURCES += \ $$PWD/support/dialogundo.cpp \ $$PWD/tools/dialogtruedarts.cpp \ $$PWD/tools/dialogpointofintersectioncurves.cpp \ - $$PWD/tools/dialogcubicbezier.cpp + $$PWD/tools/dialogcubicbezier.cpp \ + $$PWD/tools/dialogcubicbezierpath.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -104,4 +106,5 @@ FORMS += \ $$PWD/support/dialogundo.ui \ $$PWD/tools/dialogtruedarts.ui \ $$PWD/tools/dialogpointofintersectioncurves.ui \ - $$PWD/tools/dialogcubicbezier.ui + $$PWD/tools/dialogcubicbezier.ui \ + $$PWD/tools/dialogcubicbezierpath.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index c37b25f3b..08326cce0 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -44,6 +44,7 @@ #include "dialogs/tools/dialogspline.h" #include "dialogs/tools/dialogcubicbezier.h" #include "dialogs/tools/dialogsplinepath.h" +#include "dialogs/tools/dialogcubicbezierpath.h" #include "dialogs/tools/dialogheight.h" #include "dialogs/tools/dialogcutarc.h" #include "dialogs/tools/dialogcutspline.h" diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp new file mode 100644 index 000000000..ddb7400b7 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp @@ -0,0 +1,312 @@ +/************************************************************************ + ** + ** @file dialogcubicbezierpath.cpp + ** @author Roman Telezhynskyi + ** @date 18 3, 2016 + ** + ** @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) 2016 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 "dialogcubicbezierpath.h" +#include "ui_dialogcubicbezierpath.h" +#include "../../visualization/vistoolcubicbezierpath.h" + +#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) +# include "../vmisc/vmath.h" +#else +# include +#endif + +//--------------------------------------------------------------------------------------------------------------------- +DialogCubicBezierPath::DialogCubicBezierPath(const VContainer *data, const quint32 &toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogCubicBezierPath), + path(), + newDuplicate(-1) +{ + ui->setupUi(this); + + InitOkCancelApply(ui); + bOk->setEnabled(false); + + FillComboBoxPoints(ui->comboBoxPoint); + FillComboBoxLineColors(ui->comboBoxColor); + + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogCubicBezierPath::PointChanged); + connect(ui->comboBoxPoint, static_cast(&QComboBox::currentIndexChanged), + this, &DialogCubicBezierPath::currentPointChanged); + + vis = new VisToolCubicBezierPath(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogCubicBezierPath::~DialogCubicBezierPath() +{ + DeleteVisualization(); + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath DialogCubicBezierPath::GetPath() const +{ + return path; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::SetPath(const VCubicBezierPath &value) +{ + this->path = value; + ui->listWidget->blockSignals(true); + ui->listWidget->clear(); + for (qint32 i = 0; i < path.CountPoints(); ++i) + { + NewItem(path.at(i)); + } + ui->listWidget->setFocus(Qt::OtherFocusReason); + ui->lineEditSplPathName->setText(path.name()); + + auto visPath = qobject_cast(vis); + SCASSERT(visPath != nullptr); + visPath->setPath(path); + ui->listWidget->blockSignals(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogCubicBezierPath::GetColor() const +{ + return GetComboBoxCurrentData(ui->comboBoxColor); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::SetColor(const QString &value) +{ + ChangeCurrentData(ui->comboBoxColor, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::ChosenObject(quint32 id, const SceneObject &type) +{ + if (type == SceneObject::Point) + { + if (AllIds().contains(id)) + { + return; + } + + const auto point = data->GeometricObject(id); + NewItem(*point); + + SavePath(); + + auto visPath = qobject_cast(vis); + SCASSERT(visPath != nullptr); + visPath->setPath(path); + + if (path.CountPoints() == 1) + { + visPath->VisualMode(NULL_ID); + connect(visPath, &VisToolCubicBezierPath::ToolTip, this, &DialogTool::ShowVisToolTip); + } + else + { + visPath->RefreshGeometry(); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::ShowDialog(bool click) +{ + if (click == false) + { + if (path.CountPoints() >= 7) + { + if (path.CountPoints() - ((path.CountSubSpl() - 1) * 3 + 4) == 0) + {// Accept only if all subpaths are completed + emit ToolTip(""); + + if (not data->IsUnique(path.name())) + { + path.SetDuplicate(DNumber(path.name())); + } + + DialogAccepted(); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::SaveData() +{ + const quint32 d = path.GetDuplicate();//Save previous value + SavePath(); + newDuplicate <= -1 ? path.SetDuplicate(d) : path.SetDuplicate(static_cast(newDuplicate)); + + auto visPath = qobject_cast(vis); + SCASSERT(visPath != nullptr); + visPath->setPath(path); + visPath->SetMode(Mode::Show); + visPath->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::PointChanged(int row) +{ + if (ui->listWidget->count() == 0) + { + return; + } + + const auto p = qvariant_cast(ui->listWidget->item(row)->data(Qt::UserRole)); + DataPoint(p); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::currentPointChanged(int index) +{ + const quint32 id = qvariant_cast(ui->comboBoxPoint->itemData(index)); + QListWidgetItem *item = ui->listWidget->item( ui->listWidget->currentRow() ); + const auto point = data->GeometricObject(id); + DataPoint(*point); + item->setData(Qt::UserRole, QVariant::fromValue(*point)); + + QColor color = okColor; + if (not IsPathValid()) + { + flagError = false; + color = errorColor; + + ui->lineEditSplPathName->setText(tr("Invalid spline path")); + } + else + { + flagError = true; + color = okColor; + + auto first = qvariant_cast(ui->listWidget->item(0)->data(Qt::UserRole)); + auto last = qvariant_cast(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole)); + + if (first.id() == path.at(0).id() && last.id() == path.at(path.CountPoints()-1).id()) + { + newDuplicate = -1; + ui->lineEditSplPathName->setText(path.name()); + } + else + { + VCubicBezierPath newPath = ExtractPath(); + + if (not data->IsUnique(newPath.name())) + { + newDuplicate = DNumber(newPath.name()); + newPath.SetDuplicate(newDuplicate); + } + + ui->lineEditSplPathName->setText(newPath.name()); + } + } + ChangeColor(ui->labelName, color); + ChangeColor(ui->labelPoint, color); + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::NewItem(const VPointF &point) +{ + auto item = new QListWidgetItem(point.name()); + item->setFont(QFont("Times", 12, QFont::Bold)); + item->setData(Qt::UserRole, QVariant::fromValue(point)); + + ui->listWidget->addItem(item); + ui->listWidget->setCurrentItem(item); + if (ui->listWidget->count() >= 7) + { + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + bOk->setEnabled(true); + } + + DataPoint(point); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::DataPoint(const VPointF &p) +{ + ui->comboBoxPoint->blockSignals(true); + ChangeCurrentData(ui->comboBoxPoint, p.id()); + ui->comboBoxPoint->blockSignals(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::SavePath() +{ + path.Clear(); + path = ExtractPath(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QSet DialogCubicBezierPath::AllIds() const +{ + QVector points; + for (qint32 i = 0; i < ui->listWidget->count(); ++i) + { + points.append(qvariant_cast(ui->listWidget->item(i)->data(Qt::UserRole)).id()); + } + + QSet ids; + const qint32 count = qFloor(qAbs((points.size() - 4) / 3 + 1));// Count subpaths + for (qint32 i = 0; i < count; ++i) + { + const qint32 base = (i - 1) * 3; + ids.insert(points.at(base));// The first subpath's point + ids.insert(points.at(base + 3));// The last subpath's point + } + + return ids; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogCubicBezierPath::IsPathValid() const +{ + if (path.CountPoints() < 7) + { + return false; + } + + return (AllIds().size() == path.CountSubSpl() + 1); +} + +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath DialogCubicBezierPath::ExtractPath() const +{ + QVector points; + for (qint32 i = 0; i < ui->listWidget->count(); ++i) + { + points.append(qvariant_cast(ui->listWidget->item(i)->data(Qt::UserRole))); + } + return VCubicBezierPath(points); +} diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h new file mode 100644 index 000000000..a9b56975a --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h @@ -0,0 +1,80 @@ +/************************************************************************ + ** + ** @file dialogcubicbezierpath.h + ** @author Roman Telezhynskyi + ** @date 18 3, 2016 + ** + ** @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) 2016 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 DIALOGCUBICBEZIERPATH_H +#define DIALOGCUBICBEZIERPATH_H + +#include "dialogtool.h" +#include "../vgeometry/vcubicbezierpath.h" + +namespace Ui +{ + class DialogCubicBezierPath; +} + +class DialogCubicBezierPath : public DialogTool +{ + Q_OBJECT + +public: + explicit DialogCubicBezierPath(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + virtual ~DialogCubicBezierPath(); + + VCubicBezierPath GetPath() const; + void SetPath(const VCubicBezierPath &value); + + QString GetColor() const; + void SetColor(const QString &value); +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; + virtual void ShowDialog(bool click) Q_DECL_OVERRIDE; +protected: + virtual void ShowVisualization() Q_DECL_OVERRIDE; + virtual void SaveData() Q_DECL_OVERRIDE; +private slots: + void PointChanged(int row); + void currentPointChanged(int index); + +private: + Q_DISABLE_COPY(DialogCubicBezierPath) + Ui::DialogCubicBezierPath *ui; + + /** @brief path cubic bezier path */ + VCubicBezierPath path; + + qint32 newDuplicate; + + void NewItem(const VPointF &point); + void DataPoint(const VPointF &p); + void SavePath(); + QSet AllIds() const; + bool IsPathValid() const; + VCubicBezierPath ExtractPath() const; +}; + +#endif // DIALOGCUBICBEZIERPATH_H diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui new file mode 100644 index 000000000..85f4b80a7 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui @@ -0,0 +1,130 @@ + + + DialogCubicBezierPath + + + + 0 + 0 + 324 + 327 + + + + Dialog cubic bezier path + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + + + + + + + Point: + + + + + + + + + + + + + + List of points + + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Color: + + + + + + + + + + Name: + + + + + + + true + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogCubicBezierPath + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogCubicBezierPath + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/tools/drawTools/drawtools.h b/src/libs/vtools/tools/drawTools/drawtools.h index fa96e5bfc..5b0bee7ff 100644 --- a/src/libs/vtools/tools/drawTools/drawtools.h +++ b/src/libs/vtools/tools/drawTools/drawtools.h @@ -42,6 +42,7 @@ #include "toolcurve/vtoolspline.h" #include "toolcurve/vtoolcubicbezier.h" #include "toolcurve/vtoolsplinepath.h" +#include "toolcurve/vtoolcubicbezierpath.h" #include "vtoolline.h" #include "toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h" #include "toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h" diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h index 3fe9ddef8..cbcd0f33c 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h @@ -73,7 +73,7 @@ protected: virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: - void RefreshGeometry(); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; }; #endif // VTOOLARC_H diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h index a1c8572e8..e0446548a 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h @@ -74,7 +74,7 @@ protected: virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: - void RefreshGeometry(); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; }; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h index 0bde70ef8..ca8d53ed8 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h @@ -63,7 +63,7 @@ protected: private: Q_DISABLE_COPY(VToolCubicBezier) - void RefreshGeometry (); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; void SetSplineAttributes(QDomElement &domElement, const VCubicBezier &spl); }; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp new file mode 100644 index 000000000..fd07b2304 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp @@ -0,0 +1,254 @@ +/************************************************************************ + ** + ** @file vtoolcubicbezierpath.cpp + ** @author Roman Telezhynskyi + ** @date 18 3, 2016 + ** + ** @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) 2016 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 "vtoolcubicbezierpath.h" +#include "../../../dialogs/tools/dialogcubicbezierpath.h" +#include "../../../visualization/vistoolcubicbezierpath.h" + +const QString VToolCubicBezierPath::ToolType = QStringLiteral("cubicBezierPath"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolCubicBezierPath::VToolCubicBezierPath(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, + const Source &typeCreation, QGraphicsItem *parent) + : VAbstractSpline(doc, data, id, parent) +{ + sceneType = SceneObject::SplinePath; + lineColor = color; + + this->setPath(ToolPath()); + this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setFlag(QGraphicsItem::ItemIsFocusable, true); + this->setAcceptHoverEvents(true); + + ToolCreation(typeCreation); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolCubicBezierPath::~VToolCubicBezierPath() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::setDialog() +{ + SCASSERT(dialog != nullptr); + auto dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + dialogTool->SetPath(*splPath); + dialogTool->SetColor(lineColor); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolCubicBezierPath *VToolCubicBezierPath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + auto dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + auto path = new VCubicBezierPath(dialogTool->GetPath()); + const QString color = dialogTool->GetColor(); + for (qint32 i = 0; i < path->CountPoints(); ++i) + { + doc->IncrementReferens((*path)[i].getIdTool()); + } + VToolCubicBezierPath* spl = Create(0, path, color, scene, doc, data, Document::FullParse, Source::FromGui); + if (spl != nullptr) + { + spl->dialog=dialogTool; + } + return spl; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolCubicBezierPath *VToolCubicBezierPath::Create(const quint32 _id, VCubicBezierPath *path, const QString &color, + VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation) +{ + quint32 id = _id; + if (typeCreation == Source::FromGui) + { + id = data->AddGObject(path); + data->AddCurve(id); + } + else + { + data->UpdateGObject(id, path); + data->AddCurve(id); + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + VDrawTool::AddRecord(id, Tool::CubicBezierPath, doc); + if (parse == Document::FullParse) + { + VToolCubicBezierPath *spl = new VToolCubicBezierPath(doc, data, id, color, typeCreation); + scene->addItem(spl); + connect(spl, &VToolCubicBezierPath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolCubicBezierPath::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, spl, &VToolCubicBezierPath::Disable); + doc->AddTool(id, spl); + return spl; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VCubicBezierPath &path) +{ + VDomDocument::RemoveAllChildren(element); + for (qint32 i = 0; i < path.CountPoints(); ++i) + { + AddPathPoint(doc, element, path.at(i)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath VToolCubicBezierPath::getSplinePath() const +{ + QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + return *splPath.data(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::setSplinePath(const VCubicBezierPath &splPath) +{ + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer splinePath = qSharedPointerDynamicCast(obj); + *splinePath.data() = splPath; + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::RemoveReferens() +{ + const QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + for (qint32 i = 0; i < splPath->CountSubSpl(); ++i) + { + doc->DecrementReferens(splPath->at(i).getIdTool()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + const auto dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + + doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor()); + SetSplinePathAttributes(domElement, dialogTool->GetPath()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VAbstractSpline::SaveOptions(tag, obj); + + QSharedPointer splPath = qSharedPointerDynamicCast(obj); + SCASSERT(splPath.isNull() == false); + + SetSplinePathAttributes(tag, *splPath); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::SetVisualization() +{ + if (vis != nullptr) + { + auto visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + visual->setPath(*splPath.data()); + visual->SetMode(Mode::Show); + visual->RefreshGeometry(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::RefreshGeometry() +{ + isHovered || detailsMode ? setPath(ToolPath(PathDirection::Show)) : setPath(ToolPath()); + + this->setPen(QPen(CorrectColor(lineColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); + + SetVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VPointF &splPoint) +{ + SCASSERT(doc != nullptr); + QDomElement pathPoint = doc->createElement(AttrPathPoint); + doc->SetAttribute(pathPoint, AttrPSpline, splPoint.id()); + domElement.appendChild(pathPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCubicBezierPath::SetSplinePathAttributes(QDomElement &domElement, const VCubicBezierPath &path) +{ + doc->SetAttribute(domElement, AttrType, ToolType); + + if (path.GetDuplicate() > 0) + { + doc->SetAttribute(domElement, AttrDuplicate, path.GetDuplicate()); + } + else + { + if (domElement.hasAttribute(AttrDuplicate)) + { + domElement.removeAttribute(AttrDuplicate); + } + } + + UpdatePathPoints(doc, domElement, path); +} diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h new file mode 100644 index 000000000..29089fe2b --- /dev/null +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h @@ -0,0 +1,73 @@ +/************************************************************************ + ** + ** @file vtoolcubicbezierpath.h + ** @author Roman Telezhynskyi + ** @date 18 3, 2016 + ** + ** @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) 2016 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 VTOOLCUBICBEZIERPATH_H +#define VTOOLCUBICBEZIERPATH_H + +#include "vabstractspline.h" + +class VCubicBezierPath; + +class VToolCubicBezierPath:public VAbstractSpline +{ + Q_OBJECT +public: + VToolCubicBezierPath(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &color, + const Source &typeCreation, QGraphicsItem * parent = nullptr); + virtual ~VToolCubicBezierPath(); + virtual void setDialog() Q_DECL_OVERRIDE; + static VToolCubicBezierPath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data); + static VToolCubicBezierPath *Create(const quint32 _id, VCubicBezierPath *path, const QString &color, + VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation); + + static const QString ToolType; + static void UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VCubicBezierPath &path); + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Tool::CubicBezierPath)}; + + VCubicBezierPath getSplinePath()const; + void setSplinePath(const VCubicBezierPath &splPath); + + virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; + virtual void RemoveReferens() Q_DECL_OVERRIDE; + virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; + virtual void SetVisualization() Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(VToolCubicBezierPath) + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VPointF &splPoint); + void SetSplinePathAttributes(QDomElement &domElement, const VCubicBezierPath &path); +}; + +#endif // VTOOLCUBICBEZIERPATH_H diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h index d3a411123..e404087a6 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h @@ -81,7 +81,7 @@ private: QPointF oldPosition; bool IsMovable() const; - void RefreshGeometry (); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; void SetSplineAttributes(QDomElement &domElement, const VSpline &spl); }; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index e402ba19c..b88c12e7a 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -389,10 +389,10 @@ void VToolSplinePath::AddPathPoint(VAbstractPattern *doc, QDomElement &domElemen */ void VToolSplinePath::RemoveReferens() { - const VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); - for (qint32 i = 0; i < splPath.CountSubSpl(); ++i) + const QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + for (qint32 i = 0; i < splPath->CountSubSpl(); ++i) { - doc->DecrementReferens(splPath.at(i).P().getIdTool()); + doc->DecrementReferens(splPath->at(i).P().getIdTool()); } } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h index dc12005dc..a7035225e 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h @@ -46,7 +46,7 @@ public: const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual ~VToolSplinePath() Q_DECL_OVERRIDE; - virtual void setDialog(); + virtual void setDialog() Q_DECL_OVERRIDE; static VToolSplinePath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolSplinePath *Create(const quint32 _id, VSplinePath *path, const QString &color, @@ -100,11 +100,12 @@ protected: virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; private: + Q_DISABLE_COPY(VToolSplinePath) QPointF oldPosition; int splIndex; bool IsMovable(int index) const; - void RefreshGeometry(); + virtual void RefreshGeometry() Q_DECL_OVERRIDE; static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint); void UpdateControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) const; void SetSplinePathAttributes(QDomElement &domElement, const VSplinePath &path); diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index dcf73d160..a8ed05c2e 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -48,7 +48,8 @@ HEADERS += \ $$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h \ $$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h \ - $$PWD/drawTools/toolcurve/vtoolcubicbezier.h + $$PWD/drawTools/toolcurve/vtoolcubicbezier.h \ + $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -94,4 +95,5 @@ SOURCES += \ $$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp \ $$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp \ - $$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp + $$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \ + $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp diff --git a/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp b/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp new file mode 100644 index 000000000..a519a14c4 --- /dev/null +++ b/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp @@ -0,0 +1,206 @@ +/************************************************************************ + ** + ** @file vistoolcubicbezierpath.cpp + ** @author Roman Telezhynskyi + ** @date 18 3, 2016 + ** + ** @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) 2016 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 "vistoolcubicbezierpath.h" +#include "../vgeometry/vspline.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCubicBezierPath::VisToolCubicBezierPath(const VContainer *data, QGraphicsItem *parent) + : VisPath(data, parent), + mainPoints(), + ctrlPoints(), + lines(), + newCurveSegment(nullptr), + path(), + helpLine1(nullptr), + helpLine2(nullptr) +{ + helpLine1 = InitItem(mainColor, this); + helpLine2 = InitItem(mainColor, this); + + newCurveSegment = InitItem(mainColor, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCubicBezierPath::~VisToolCubicBezierPath() +{ + qDeleteAll(mainPoints); + qDeleteAll(lines); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCubicBezierPath::RefreshGeometry() +{ + if (path.CountPoints() > 0) + { + const QVector pathPoints = path.GetSplinePath(); + const int size = pathPoints.size(); + const int countSubSpl = path.CountSubSpl(); + + for (int i = 0; i < size; ++i) + { + QGraphicsEllipseItem *point = this->getPoint(mainPoints, static_cast(i), 1/*zValue*/); + DrawPoint(point, pathPoints.at(i).toQPointF(), supportColor); + } + + if (mode == Mode::Creation) + { + for (qint32 i = 1; i<=countSubSpl; ++i) + { + const int preLastPoint = (countSubSpl - 1) * 2; + const int lastPoint = preLastPoint + 1; + + const VSpline spl = path.GetSpline(i); + + QGraphicsLineItem *ctrlLine1 = this->getLine(static_cast(preLastPoint)); + DrawLine(ctrlLine1, QLineF(spl.GetP1().toQPointF(), spl.GetP2()), mainColor, Qt::DashLine); + + QGraphicsEllipseItem *p2 = this->getPoint(ctrlPoints, static_cast(preLastPoint)); + DrawPoint(p2, spl.GetP2(), Qt::green); + + QGraphicsLineItem *ctrlLine2 = this->getLine(static_cast(lastPoint)); + DrawLine(ctrlLine2, QLineF(spl.GetP4().toQPointF(), spl.GetP3()), mainColor, Qt::DashLine); + + QGraphicsEllipseItem *p3 = this->getPoint(ctrlPoints, static_cast(lastPoint)); + DrawPoint(p3, spl.GetP3(), Qt::green); + } + + const qint32 last = (countSubSpl - 1) * 3 + 3; + Creating(pathPoints, size-1-last); + } + + if (countSubSpl >= 1) + { + DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); + } + + if (countSubSpl < 7) + { + Visualization::toolTip = tr("Curved path: select seven or more points"); + } + else if (countSubSpl >= 7 && size - ((countSubSpl - 1) * 3 + 4) == 0) + { + Visualization::toolTip = tr("Curved path: select seven or more points, " + "Enter - finish creation"); + } + else + { + Visualization::toolTip = tr("Curved path: select more points for complete segment"); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCubicBezierPath::setPath(const VCubicBezierPath &value) +{ + path = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +VCubicBezierPath VisToolCubicBezierPath::getPath() +{ + return path; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *VisToolCubicBezierPath::getPoint(QVector &points, quint32 i, qreal z) +{ + if (not points.isEmpty() && static_cast(points.size() - 1) >= i) + { + return points.at(static_cast(i)); + } + else + { + auto point = InitPoint(supportColor, this, z); + points.append(point); + return point; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsLineItem *VisToolCubicBezierPath::getLine(quint32 i) +{ + if (static_cast(lines.size() - 1) >= i && lines.isEmpty() == false) + { + return lines.at(static_cast(i)); + } + else + { + auto line = InitItem(mainColor, this); + lines.append(line); + return line; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCubicBezierPath::Creating(const QVector &pathPoints, int pointsLeft) +{ + if (pathPoints.isEmpty() || pathPoints.size()+1 < pointsLeft) + { + return; + } + + switch(pointsLeft) + { + case 0: + { + const QPointF p1 = pathPoints.last().toQPointF(); + DrawLine(helpLine1, QLineF(p1, Visualization::scenePos), mainColor, Qt::DashLine); + break; + } + case 1: + { + const VPointF p1 = pathPoints.at(pointsLeft-1); + const QPointF p2 = pathPoints.at(pointsLeft).toQPointF(); + + DrawLine(helpLine1, QLineF(p1.toQPointF(), p2), mainColor, Qt::DashLine); + + VSpline spline(p1, p2, Visualization::scenePos, VPointF(Visualization::scenePos)); + DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + break; + } + case 2: + { + const VPointF p1 = pathPoints.at(pointsLeft-2); + const QPointF p2 = pathPoints.at(pointsLeft-1).toQPointF(); + const QPointF p3 = pathPoints.at(pointsLeft).toQPointF(); + + DrawLine(helpLine1, QLineF(p1.toQPointF(), p2), mainColor, Qt::DashLine); + DrawLine(helpLine2, QLineF(p3, Visualization::scenePos), mainColor, Qt::DashLine); + + VSpline spline(p1, p2, p3, VPointF(Visualization::scenePos)); + DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + break; + } + default: + break; + } +} diff --git a/src/libs/vtools/visualization/vistoolcubicbezierpath.h b/src/libs/vtools/visualization/vistoolcubicbezierpath.h new file mode 100644 index 000000000..d33ddea1c --- /dev/null +++ b/src/libs/vtools/visualization/vistoolcubicbezierpath.h @@ -0,0 +1,65 @@ +/************************************************************************ + ** + ** @file vistoolcubicbezierpath.h + ** @author Roman Telezhynskyi + ** @date 18 3, 2016 + ** + ** @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) 2016 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 VISTOOLCUBICBEZIERPATH_H +#define VISTOOLCUBICBEZIERPATH_H + +#include "vispath.h" +#include "../vgeometry/vcubicbezierpath.h" + +class VisToolCubicBezierPath : public VisPath +{ + Q_OBJECT +public: + explicit VisToolCubicBezierPath(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolCubicBezierPath(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + + void setPath(const VCubicBezierPath &value); + VCubicBezierPath getPath(); + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolCubicBezierPath)}; + +protected: + Q_DISABLE_COPY(VisToolCubicBezierPath) + QVector mainPoints; + QVector ctrlPoints; + QVector lines; + QGraphicsPathItem *newCurveSegment; + VCubicBezierPath path; + QGraphicsLineItem *helpLine1; + QGraphicsLineItem *helpLine2; + + QGraphicsEllipseItem *getPoint(QVector &points, quint32 i, qreal z = 0); + QGraphicsLineItem *getLine(quint32 i); + void Creating(const QVector &pathPoints , int pointsLeft); +}; + +#endif // VISTOOLCUBICBEZIERPATH_H diff --git a/src/libs/vtools/visualization/vistoolsplinepath.h b/src/libs/vtools/visualization/vistoolsplinepath.h index cbddfef70..8707463ac 100644 --- a/src/libs/vtools/visualization/vistoolsplinepath.h +++ b/src/libs/vtools/visualization/vistoolsplinepath.h @@ -38,7 +38,7 @@ class VisToolSplinePath : public VisPath { Q_OBJECT public: - explicit VisToolSplinePath(const VContainer *data, QGraphicsItem *parent = 0); + explicit VisToolSplinePath(const VContainer *data, QGraphicsItem *parent = nullptr); virtual ~VisToolSplinePath() Q_DECL_OVERRIDE; virtual void RefreshGeometry() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/visualization/visualization.cpp b/src/libs/vtools/visualization/visualization.cpp index 23c151801..cc7c7c3aa 100644 --- a/src/libs/vtools/visualization/visualization.cpp +++ b/src/libs/vtools/visualization/visualization.cpp @@ -113,7 +113,7 @@ void Visualization::MousePos(const QPointF &scenePos) } //--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent) const +QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent, qreal z) const { QGraphicsEllipseItem *point = new QGraphicsEllipseItem(parent); point->setZValue(1); @@ -122,6 +122,7 @@ QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsIte point->setRect(PointRect(ToPixel(DefPointRadius/*mm*/, Unit::Mm))); point->setPos(QPointF()); point->setFlags(QGraphicsItem::ItemStacksBehindParent); + point->setZValue(z); point->setVisible(false); return point; } diff --git a/src/libs/vtools/visualization/visualization.h b/src/libs/vtools/visualization/visualization.h index 03339f02e..f4be1c451 100644 --- a/src/libs/vtools/visualization/visualization.h +++ b/src/libs/vtools/visualization/visualization.h @@ -80,7 +80,7 @@ protected: virtual void InitPen()=0; virtual void AddOnScene()=0; - QGraphicsEllipseItem *InitPoint(const QColor &color, QGraphicsItem *parent) const; + QGraphicsEllipseItem *InitPoint(const QColor &color, QGraphicsItem *parent, qreal z = 0) const; QRectF PointRect(const qreal &radius) const; void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style = Qt::SolidLine); diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index f1139b5ff..ffd124876 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -31,7 +31,8 @@ HEADERS += \ $$PWD/vistoolarcwithlength.h \ $$PWD/vistooltruedarts.h \ $$PWD/vistoolpointofintersectioncurves.h \ - $$PWD/vistoolcubicbezier.h + $$PWD/vistoolcubicbezier.h \ + $$PWD/vistoolcubicbezierpath.h SOURCES += \ $$PWD/visline.cpp \ @@ -63,4 +64,5 @@ SOURCES += \ $$PWD/vistoolarcwithlength.cpp \ $$PWD/vistooltruedarts.cpp \ $$PWD/vistoolpointofintersectioncurves.cpp \ - $$PWD/vistoolcubicbezier.cpp + $$PWD/vistoolcubicbezier.cpp \ + $$PWD/vistoolcubicbezierpath.cpp