diff --git a/.hgignore b/.hgignore index 166ab3143..acd48da3d 100644 --- a/.hgignore +++ b/.hgignore @@ -89,6 +89,7 @@ cov-int/ /.qmake.stash *.pro.user *.pro.user.* +*.qbs.user *.moc moc_*.cpp qrc_*.cpp diff --git a/ChangeLog.txt b/ChangeLog.txt index 6b7e824f0..a0dd3dde6 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,5 @@ # Version 0.5.0 +- [#395] Create Curve tool which uses point as control handle. - pdftops updated to version 3.04. - [#306] Layout generator optimization. Divide into strips. - Fixed case with duplicate names of curves if they connect same points. 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/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index 878be176c..5c5c462de 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -31,6 +31,7 @@ #include "../vgeometry/varc.h" #include "../vgeometry/vcubicbezier.h" #include "../vgeometry/vsplinepath.h" +#include "../vgeometry/vcubicbezierpath.h" #include "../vgeometry/vpointf.h" #include "../vtools/tools/vabstracttool.h" #include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h" @@ -162,7 +163,7 @@ void DialogHistory::FillTable() { const VToolRecord tool = history.at(i); const QString historyRecord = Record(tool); - if (historyRecord.isEmpty() ==false) + if (not historyRecord.isEmpty()) { currentRow++; @@ -194,12 +195,11 @@ void DialogHistory::FillTable() ui->tableWidget->verticalHeader()->setDefaultSectionSize(20); } +//--------------------------------------------------------------------------------------------------------------------- #if defined(Q_CC_GNU) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wswitch-default" #endif - -//--------------------------------------------------------------------------------------------------------------------- /** * @brief Record return description for record * @param tool record data @@ -208,7 +208,7 @@ void DialogHistory::FillTable() QString DialogHistory::Record(const VToolRecord &tool) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 40, "Not all tools was used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -268,49 +268,39 @@ QString DialogHistory::Record(const VToolRecord &tool) { const QSharedPointer spl = data->GeometricObject(tool.getId()); SCASSERT(spl != nullptr); - return QString(tr("Curve %1_%2")).arg(PointName(spl->GetP1().id())).arg(PointName(spl->GetP4().id())); + return spl->NameForHistory(tr("Curve")); } case Tool::CubicBezier: { const QSharedPointer spl = data->GeometricObject(tool.getId()); SCASSERT(spl != nullptr); - return QString(tr("Cubic bezier curve %1_%2")).arg(PointName(spl->GetP1().id())) - .arg(PointName(spl->GetP4().id())); + return spl->NameForHistory(tr("Cubic bezier curve")); } case Tool::Arc: { const QSharedPointer arc = data->GeometricObject(tool.getId()); SCASSERT(arc != nullptr); - return QString(tr("Arc with center in point %1")).arg(PointName(arc->GetCenter().id())); + return arc->NameForHistory(tr("Arc")); } case Tool::ArcWithLength: { const QSharedPointer arc = data->GeometricObject(tool.getId()); SCASSERT(arc != nullptr); - return QString(tr("Arc with center in point %1 and length %2")).arg(PointName(arc->GetCenter().id())) + return QString(tr("%1 with length %2")) + .arg(arc->NameForHistory(tr("Arc"))) .arg(arc->GetLength()); } case Tool::SplinePath: { const QSharedPointer splPath = data->GeometricObject(tool.getId()); SCASSERT(splPath != nullptr); - const QVector points = splPath->GetSplinePath(); - QString record; - if (points.size() != 0 ) - { - // We use only first and last point name in curve - record = QString(tr("Curve point %1")).arg(PointName(points.at(0).P().id())); - if (points.size() > 1) - { - record.append(QString("_%1").arg(PointName(points.last().P().id()))); - } - } - else - { - qDebug()<<"Not enough points in splinepath"<NameForHistory(tr("Spline path")); + } + case Tool::CubicBezierPath: + { + const QSharedPointer splPath = data->GeometricObject(tool.getId()); + SCASSERT(splPath != nullptr); + return splPath->NameForHistory(tr("Cubic bezier curve path")); } case Tool::PointOfContact: return QString(tr("%4 - point of contact of arc with the center in point %1 and line %2_%3")) @@ -338,43 +328,27 @@ QString DialogHistory::Record(const VToolRecord &tool) { const QSharedPointer arc = data->GeometricObject(AttrUInt(domElem, AttrArc)); SCASSERT(arc != nullptr); - return QString(tr("%1 - cut arc with center %2")) + return QString(tr("%1 - cut %2")) .arg(PointName(tool.getId())) - .arg(PointName(arc->GetCenter().id())); + .arg(arc->NameForHistory(tr("arc"))); } case Tool::CutSpline: { const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline); const QSharedPointer spl = data->GeometricObject(splineId); SCASSERT(spl != nullptr); - return QString(tr("%1 - cut curve %2_%3")) + return QString(tr("%1 - cut %2")) .arg(PointName(tool.getId())) - .arg(PointName(spl->GetP1().id())) - .arg(PointName(spl->GetP4().id())); + .arg(spl->NameForHistory(tr("curve"))); } case Tool::CutSplinePath: { const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath); const QSharedPointer splPath = data->GeometricObject(splinePathId); SCASSERT(splPath != nullptr); - const QVector points = splPath->GetSplinePath(); - QString record; - if (points.size() != 0 ) - { - record = QString(tr("%1 - cut curve path %2")) - .arg(PointName(tool.getId())) - .arg(PointName(points.at(0).P().id())); - if (points.size() > 1) - { - record.append(QString("_%1").arg(PointName(points.last().P().id()))); - } - } - else - { - qDebug()<<"Not enough points in splinepath"<NameForHistory(tr("curve path"))); } case Tool::LineIntersectAxis: return QString(tr("%1 - point of intersection line %2_%3 and axis through point %4")) @@ -409,7 +383,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::NodePoint: case Tool::NodeSpline: case Tool::NodeSplinePath: - break; + return QString(); } } catch (const VExceptionBadId &e) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 91a41adcc..2c6febaaa 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -830,6 +830,16 @@ void MainWindow::ToolSplinePath(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +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); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ToolCutSplinePath handler tool CutSplinePath. @@ -1615,6 +1625,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonCubicBezier, &QToolButton::clicked, this, &MainWindow::ToolCubicBezier); connect(ui->toolButtonArc, &QToolButton::clicked, this, &MainWindow::ToolArc); connect(ui->toolButtonSplinePath, &QToolButton::clicked, this, &MainWindow::ToolSplinePath); + connect(ui->toolButtonCubicBezierPath, &QToolButton::clicked, this, &MainWindow::ToolCubicBezierPath); connect(ui->toolButtonPointOfContact, &QToolButton::clicked, this, &MainWindow::ToolPointOfContact); connect(ui->toolButtonNewDetail, &QToolButton::clicked, this, &MainWindow::ToolDetail); connect(ui->toolButtonHeight, &QToolButton::clicked, this, &MainWindow::ToolHeight); @@ -1669,11 +1680,18 @@ void MainWindow::mouseMove(const QPointF &scenePos) } //--------------------------------------------------------------------------------------------------------------------- +#if defined(Q_CC_GNU) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wswitch-default" +#endif /** * @brief CancelTool cancel tool. */ void MainWindow::CancelTool() { + // 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 handled."); + qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; dialogTool = nullptr; @@ -1692,6 +1710,16 @@ void MainWindow::CancelTool() redoAction->setEnabled(false); return; case Tool::BasePoint: + case Tool::SinglePoint: + case Tool::DoublePoint: + case Tool::LinePoint: + case Tool::AbstractSpline: + case Tool::Cut: + case Tool::LAST_ONE_DO_NOT_USE: + case Tool::NodePoint: + case Tool::NodeArc: + case Tool::NodeSpline: + case Tool::NodeSplinePath: Q_UNREACHABLE(); //-V501 //Nothing to do here because we can't create this tool from main window. break; @@ -1731,6 +1759,9 @@ void MainWindow::CancelTool() case Tool::SplinePath: ui->toolButtonSplinePath->setChecked(false); break; + case Tool::CubicBezierPath: + ui->toolButtonCubicBezierPath->setChecked(false); + break; case Tool::PointOfContact: ui->toolButtonPointOfContact->setChecked(false); break; @@ -1783,13 +1814,6 @@ void MainWindow::CancelTool() case Tool::TrueDarts: ui->toolButtonTrueDarts->setChecked(false); break; - case Tool::NodePoint: - case Tool::NodeArc: - case Tool::NodeSpline: - case Tool::NodeSplinePath: - default: - qDebug()<<"Got wrong tool type. Ignored."; - break; } currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); @@ -1801,6 +1825,10 @@ void MainWindow::CancelTool() redoAction->setEnabled(qApp->getUndoStack()->canRedo()); } +#if defined(Q_CC_GNU) + #pragma GCC diagnostic pop +#endif + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ArrowTool enable arrow tool. @@ -2949,6 +2977,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonCubicBezier->setEnabled(drawTools); ui->toolButtonArc->setEnabled(drawTools); ui->toolButtonSplinePath->setEnabled(drawTools); + ui->toolButtonCubicBezierPath->setEnabled(drawTools); ui->toolButtonPointOfContact->setEnabled(drawTools); ui->toolButtonNewDetail->setEnabled(drawTools); ui->toolButtonHeight->setEnabled(drawTools); @@ -3233,8 +3262,16 @@ void MainWindow::CreateMenus() AddDocks(); } +//--------------------------------------------------------------------------------------------------------------------- +#if defined(Q_CC_GNU) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wswitch-default" +#endif void MainWindow::LastUsedTool() { + // 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 handled."); + if (currentTool == lastUsedTool) { return; @@ -3247,6 +3284,16 @@ void MainWindow::LastUsedTool() ArrowTool(); break; case Tool::BasePoint: + case Tool::SinglePoint: + case Tool::DoublePoint: + case Tool::LinePoint: + case Tool::AbstractSpline: + case Tool::Cut: + case Tool::LAST_ONE_DO_NOT_USE: + case Tool::NodePoint: + case Tool::NodeArc: + case Tool::NodeSpline: + case Tool::NodeSplinePath: Q_UNREACHABLE(); //-V501 //Nothing to do here because we can't create this tool from main window. break; @@ -3282,6 +3329,10 @@ void MainWindow::LastUsedTool() ui->toolButtonSpline->setChecked(true); ToolSpline(true); break; + case Tool::CubicBezier: + ui->toolButtonCubicBezier->setChecked(true); + ToolCubicBezier(true); + break; case Tool::Arc: ui->toolButtonArc->setChecked(true); ToolArc(true); @@ -3290,6 +3341,10 @@ void MainWindow::LastUsedTool() ui->toolButtonSplinePath->setChecked(true); ToolSplinePath(true); break; + case Tool::CubicBezierPath: + ui->toolButtonCubicBezierPath->setChecked(true); + ToolCubicBezierPath(true); + break; case Tool::PointOfContact: ui->toolButtonPointOfContact->setChecked(true); ToolPointOfContact(true); @@ -3362,16 +3417,13 @@ void MainWindow::LastUsedTool() ui->toolButtonTrueDarts->setChecked(true); ToolTrueDarts(true); break; - case Tool::NodePoint: - case Tool::NodeArc: - case Tool::NodeSpline: - case Tool::NodeSplinePath: - default: - qDebug()<<"Got wrong tool type. Ignored."; - break; } } +#if defined(Q_CC_GNU) + #pragma GCC diagnostic pop +#endif + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::AddDocks() { diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 4e54292d4..92829ac41 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -112,6 +112,7 @@ public slots: void ToolCutSpline(bool checked); void ToolArc(bool checked); void ToolSplinePath(bool checked); + void ToolCubicBezierPath(bool checked); void ToolCutSplinePath(bool checked); void ToolPointOfContact(bool checked); void ToolDetail(bool checked); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index 6cc18b312..77b9f7ff2 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -618,7 +618,33 @@ - + + + + false + + + Point intersection curves + + + ... + + + + :/toolicon/32x32/intersection_curves.png:/toolicon/32x32/intersection_curves.png + + + + 32 + 32 + + + + true + + + + false @@ -644,20 +670,17 @@ - - + + false - - Point intersection curves - ... - :/toolicon/32x32/intersection_curves.png:/toolicon/32x32/intersection_curves.png + :/toolicon/32x32/cubic_bezier_path.png:/toolicon/32x32/cubic_bezier_path.png diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index bde68b73c..a52e2b468 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -62,5 +62,7 @@ cursor/intersection_curves_cursor@2x.png cursor/cubic_bezier_cursor.png cursor/cubic_bezier_cursor@2x.png + cursor/cubic_bezier_path_cursor.png + cursor/cubic_bezier_path_cursor@2x.png diff --git a/src/app/valentina/share/resources/cursor/cubic_bezier_cursor.png b/src/app/valentina/share/resources/cursor/cubic_bezier_cursor.png index 6c50010d2..c78b1fec4 100644 Binary files a/src/app/valentina/share/resources/cursor/cubic_bezier_cursor.png and b/src/app/valentina/share/resources/cursor/cubic_bezier_cursor.png differ diff --git a/src/app/valentina/share/resources/cursor/cubic_bezier_cursor@2x.png b/src/app/valentina/share/resources/cursor/cubic_bezier_cursor@2x.png index 1e1522991..317a23efc 100644 Binary files a/src/app/valentina/share/resources/cursor/cubic_bezier_cursor@2x.png and b/src/app/valentina/share/resources/cursor/cubic_bezier_cursor@2x.png differ diff --git a/src/app/valentina/share/resources/cursor/cubic_bezier_path_cursor.png b/src/app/valentina/share/resources/cursor/cubic_bezier_path_cursor.png new file mode 100644 index 000000000..7f6337bf3 Binary files /dev/null and b/src/app/valentina/share/resources/cursor/cubic_bezier_path_cursor.png differ diff --git a/src/app/valentina/share/resources/cursor/cubic_bezier_path_cursor@2x.png b/src/app/valentina/share/resources/cursor/cubic_bezier_path_cursor@2x.png new file mode 100644 index 000000000..59794801b Binary files /dev/null and b/src/app/valentina/share/resources/cursor/cubic_bezier_path_cursor@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon.qrc b/src/app/valentina/share/resources/toolicon.qrc index 48576c6d8..772aa06a7 100644 --- a/src/app/valentina/share/resources/toolicon.qrc +++ b/src/app/valentina/share/resources/toolicon.qrc @@ -60,5 +60,7 @@ toolicon/32x32/intersection_curves@2x.png toolicon/32x32/cubic_bezier.png toolicon/32x32/cubic_bezier@2x.png + toolicon/32x32/cubic_bezier_path.png + toolicon/32x32/cubic_bezier_path@2x.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier.png b/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier.png index def478013..113136d70 100644 Binary files a/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier.png and b/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier.png differ diff --git a/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier@2x.png b/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier@2x.png index 813a94c19..b8d0eebf9 100644 Binary files a/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier@2x.png and b/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier_path.png b/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier_path.png new file mode 100644 index 000000000..7376c983d Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier_path.png differ diff --git a/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier_path@2x.png b/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier_path@2x.png new file mode 100644 index 000000000..05d699564 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/cubic_bezier_path@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon/svg/cubic_bezier.svg b/src/app/valentina/share/resources/toolicon/svg/cubic_bezier.svg index b2a3d3dd7..c60a95c6d 100644 --- a/src/app/valentina/share/resources/toolicon/svg/cubic_bezier.svg +++ b/src/app/valentina/share/resources/toolicon/svg/cubic_bezier.svg @@ -32,7 +32,7 @@ id="namedview12" showgrid="false" inkscape:zoom="14.75" - inkscape:cx="-5.7288133" + inkscape:cx="-4.3389831" inkscape:cy="12.164845" inkscape:window-x="65" inkscape:window-y="24" @@ -60,11 +60,25 @@ id="path4205" inkscape:connector-curvature="0" sodipodi:nodetypes="cc" /> + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 1e8d2373a..e7d0bd65e 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; @@ -3036,7 +3094,7 @@ void VPattern::ToolsCommonAttributes(const QDomElement &domElement, quint32 &id) QRectF VPattern::ActiveDrawBoundingRect() const { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 40, "Not all tools was used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used."); QRectF rec; @@ -3092,6 +3150,9 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::SplinePath: rec = ToolBoundingRect(rec, tool.getId()); break; + case Tool::CubicBezierPath: + rec = ToolBoundingRect(rec, tool.getId()); + break; case Tool::PointOfContact: rec = ToolBoundingRect(rec, tool.getId()); break; @@ -3140,8 +3201,7 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::TrueDarts: rec = ToolBoundingRect(rec, tool.getId()); break; - //Because "history" not only show history of pattern, but help restore current data for each pattern's - //piece, we need add record about details and nodes, but don't show them. + //These tools are not accesseble in Draw mode, but still 'history' contains them. case Tool::Detail: case Tool::UnionDetails: case Tool::NodeArc: @@ -3166,7 +3226,7 @@ QRectF VPattern::ToolBoundingRect(const QRectF &rec, const quint32 &id) const QRectF recTool = rec; if (tools.contains(id)) { - T *vTool = qobject_cast(tools.value(id)); + const T *vTool = qobject_cast(tools.value(id)); SCASSERT(vTool != nullptr); QRectF childrenRect = vTool->childrenBoundingRect(); diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 08724c88c..c65ccb6d1 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -136,7 +136,7 @@ private: void SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject, quint32 &idTool); template - QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const; + QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const; void ParseCurrentPP(); QString GetLabelBase(quint32 index)const; @@ -177,6 +177,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/vabstractcubicbezier.cpp b/src/libs/vgeometry/vabstractcubicbezier.cpp index 9117d2418..2f0686719 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.cpp +++ b/src/libs/vgeometry/vabstractcubicbezier.cpp @@ -126,6 +126,17 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF & return p1234; } +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractCubicBezier::NameForHistory(const QString &toolName) const +{ + QString name = toolName + QString(" %1_%2").arg(GetP1().name()).arg(GetP4().name()); + if (GetDuplicate() > 0) + { + name += QString("_%1").arg(GetDuplicate()); + } + return name; +} + //--------------------------------------------------------------------------------------------------------------------- void VAbstractCubicBezier::CreateName() { diff --git a/src/libs/vgeometry/vabstractcubicbezier.h b/src/libs/vgeometry/vabstractcubicbezier.h index ec8d8b8b9..21d8029ea 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.h +++ b/src/libs/vgeometry/vabstractcubicbezier.h @@ -46,6 +46,8 @@ public: QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const; + virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE; + protected: virtual void CreateName() Q_DECL_OVERRIDE; diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.cpp b/src/libs/vgeometry/vabstractcubicbezierpath.cpp new file mode 100644 index 000000000..d5d7d736d --- /dev/null +++ b/src/libs/vgeometry/vabstractcubicbezierpath.cpp @@ -0,0 +1,228 @@ +/************************************************************************ + ** + ** @file vabstractcubicbezierpath.cpp + ** @author Roman Telezhynskyi + ** @date 16 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 "vabstractcubicbezierpath.h" +#include "../ifc/exception/vexception.h" +#include "vspline.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractCubicBezierPath::VAbstractCubicBezierPath(const GOType &type, const quint32 &idObject, const Draw &mode) + : VAbstractCurve(type, idObject, mode) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractCubicBezierPath::VAbstractCubicBezierPath(const VAbstractCubicBezierPath &curve) + : VAbstractCurve(curve) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractCubicBezierPath &VAbstractCubicBezierPath::operator=(const VAbstractCubicBezierPath &curve) +{ + if ( &curve == this ) + { + return *this; + } + VAbstractCurve::operator=(curve); + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractCubicBezierPath::~VAbstractCubicBezierPath() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetPath return QPainterPath which reprezent spline path. + * @return path. + */ +QPainterPath VAbstractCubicBezierPath::GetPath(PathDirection direction) const +{ + QPainterPath painterPath; + for (qint32 i = 1; i <= CountSubSpl(); ++i) + { + painterPath.addPath(GetSpline(i).GetPath(direction)); + } + return painterPath; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetPathPoints return list of points what located on path. + * @return list. + */ +QVector VAbstractCubicBezierPath::GetPoints() const +{ + QVector pathPoints; + for (qint32 i = 1; i <= CountSubSpl(); ++i) + { + pathPoints += GetSpline(i).GetPoints(); + } + return pathPoints; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetLength return length of spline path. + * @return length. + */ +qreal VAbstractCubicBezierPath::GetLength() const +{ + qreal length = 0; + for (qint32 i = 1; i <= CountSubSpl(); ++i) + { + length += GetSpline(i).GetLength(); + } + return length; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VAbstractCubicBezierPath::Segment(const QPointF &p) const +{ + int index = -1; + for (qint32 i = 1; i <= CountSubSpl(); ++i) + { + const qreal t = GetSpline(i).ParamT(p); + if (not qFuzzyIsNull(t) && qFuzzyCompare(t, -1)) + { + continue; + } + else + { + index = i; + break; + } + } + return index; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief CutSplinePath cut spline path into two. This method don't return two spline path. You must create spline + * paths by yourself. + * Example: + * QPointF spl1p2, spl1p3, spl2p2, spl2p3; + * qint32 p1 = 0, p2 = 0; + * QPointF point = splPath->CutSplinePath(length, p1, p2, spl1p2, spl1p3, spl2p2, spl2p3); + * + * VSplinePoint splP1 = splPath->at(p1); + * VSplinePoint splP2 = splPath->at(p2); + * VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p, splPath->GetKCurve()); + * VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P(), splPath->GetKCurve()); + * @param length length first spline path. + * @param p1 index first spline point in list. + * @param p2 index second spline point in list. + * @param spl1p2 first control point first spline. + * @param spl1p3 second control point first spline. + * @param spl2p2 first control point second spline. + * @param spl2p3 second control point second spline. + * @return cutting point. + */ +QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, + QPointF &spl2p2, QPointF &spl2p3) const +{ + if (CountSubSpl() < 1) + { + throw VException(tr("Can't cut this spline")); + } + + //Always need return two spline paths, so we must correct wrong length. + qreal fullLength = GetLength(); + if (length < fullLength * 0.02) + { + length = fullLength * 0.02; + } + else if ( length > fullLength * 0.98) + { + length = fullLength * 0.98; + } + + fullLength = 0; + for (qint32 i = 1; i <= CountSubSpl(); ++i) + { + const VSpline spl = GetSpline(i); + fullLength += spl.GetLength(); + if (fullLength > length) + { + p1 = i-1; + p2 = i; + return spl.CutSpline(length - (fullLength - spl.GetLength()), spl1p2, spl1p3, spl2p2, spl2p3); + } + } + return QPointF(); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief NameForHistory helps to create name for dialog History. + * @param toolName first part of name. Like 'Spline path' or 'Cubic Bezier path'. + * @return name of curve for history records. + */ +QString VAbstractCubicBezierPath::NameForHistory(const QString &toolName) const +{ + QString name = toolName; + if (CountPoints() > 0) + { + name += QString(" %1").arg(FirstPoint().name()); + if (CountSubSpl() >= 1) + { + name += QString("_%1").arg(LastPoint().name()); + } + + if (GetDuplicate() > 0) + { + name += QString("_%1").arg(GetDuplicate()); + } + } + return name; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractCubicBezierPath::CreateName() +{ + QString name; + if (CountPoints() > 0) + { + name = splPath; + name.append(QString("_%1").arg(FirstPoint().name())); + if (CountSubSpl() >= 2) + { + name.append(QString("_%1").arg(LastPoint().name())); + + if (GetDuplicate() > 0) + { + name += QString("_%1").arg(GetDuplicate()); + } + } + } + setName(name); +} diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.h b/src/libs/vgeometry/vabstractcubicbezierpath.h new file mode 100644 index 000000000..78e2cd0d6 --- /dev/null +++ b/src/libs/vgeometry/vabstractcubicbezierpath.h @@ -0,0 +1,72 @@ +/************************************************************************ + ** + ** @file vabstractcubicbezierpath.h + ** @author Roman Telezhynskyi + ** @date 16 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 VABSTRACTCUBICBEZIERPATH_H +#define VABSTRACTCUBICBEZIERPATH_H + +#include "vabstractcurve.h" + +#include + +class VPointF; +class VSpline; + +class VAbstractCubicBezierPath : public VAbstractCurve +{ + Q_DECLARE_TR_FUNCTIONS(VAbstractCubicBezierPath) +public: + VAbstractCubicBezierPath(const GOType &type, const quint32 &idObject = NULL_ID, + const Draw &mode = Draw::Calculation); + VAbstractCubicBezierPath(const VAbstractCubicBezierPath &curve); + VAbstractCubicBezierPath& operator= (const VAbstractCubicBezierPath &curve); + virtual ~VAbstractCubicBezierPath(); + + virtual qint32 CountSubSpl() const =0; + virtual qint32 CountPoints() const =0; + virtual void Clear() =0; + virtual VSpline GetSpline(qint32 index) const =0; + + virtual QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const Q_DECL_OVERRIDE; + virtual QVector GetPoints() const Q_DECL_OVERRIDE; + virtual qreal GetLength() const Q_DECL_OVERRIDE; + + int Segment(const QPointF &p) const; + + QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, + QPointF &spl2p3) const; + + virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE; + +protected: + virtual void CreateName() Q_DECL_OVERRIDE; + + virtual VPointF FirstPoint() const =0; + virtual VPointF LastPoint() const =0; +}; + +#endif // VABSTRACTCUBICBEZIERPATH_H diff --git a/src/libs/vgeometry/vabstractcurve.h b/src/libs/vgeometry/vabstractcurve.h index fbc32ac7a..6390c9c16 100644 --- a/src/libs/vgeometry/vabstractcurve.h +++ b/src/libs/vgeometry/vabstractcurve.h @@ -65,6 +65,8 @@ public: void SetDuplicate(quint32 number); static QVector CurveIntersectLine(const QVector &points, const QLineF &line); + + virtual QString NameForHistory(const QString &toolName) const=0; protected: QPainterPath ShowDirection(const QVector &points) const; virtual void CreateName() =0; diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index 10ef8393a..408b692a4 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -315,6 +315,23 @@ void VArc::setId(const quint32 &id) CreateName(); } +//--------------------------------------------------------------------------------------------------------------------- +QString VArc::NameForHistory(const QString &toolName) const +{ + QString name = toolName + QString(" %1").arg(this->GetCenter().name()); + + if (VAbstractCurve::id() != NULL_ID) + { + name += QString("_%1").arg(VAbstractCurve::id()); + } + + if (GetDuplicate() > 0) + { + name += QString("_%1").arg(GetDuplicate()); + } + return name; +} + //--------------------------------------------------------------------------------------------------------------------- void VArc::CreateName() { diff --git a/src/libs/vgeometry/varc.h b/src/libs/vgeometry/varc.h index 89ac7b4a2..a1f0077c9 100644 --- a/src/libs/vgeometry/varc.h +++ b/src/libs/vgeometry/varc.h @@ -80,6 +80,7 @@ public: QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const; QPointF CutArc (const qreal &length) const; virtual void setId(const quint32 &id) Q_DECL_OVERRIDE; + virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE; protected: virtual void CreateName() Q_DECL_OVERRIDE; private: diff --git a/src/libs/vgeometry/vcubicbezierpath.cpp b/src/libs/vgeometry/vcubicbezierpath.cpp new file mode 100644 index 000000000..c4c257446 --- /dev/null +++ b/src/libs/vgeometry/vcubicbezierpath.cpp @@ -0,0 +1,249 @@ +/************************************************************************ + ** + ** @file vcubicbezierpath.cpp + ** @author Roman Telezhynskyi + ** @date 16 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 "vcubicbezierpath.h" +#include "vcubicbezierpath_p.h" +#include "vspline.h" +#include "../ifc/exception/vexception.h" + +#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) +# include "../vmisc/vmath.h" +#else +# include +#endif + +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath::VCubicBezierPath(quint32 idObject, Draw mode) + : VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode), + d(new VCubicBezierPathData()) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath::VCubicBezierPath(const VCubicBezierPath &curve) + : VAbstractCubicBezierPath(curve), + d(curve.d) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath::VCubicBezierPath(const QVector &points, quint32 idObject, Draw mode) + : VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode), + d(new VCubicBezierPathData()) +{ + if (points.isEmpty()) + { + return; + } + + d->path = points; + CreateName(); +} + +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath &VCubicBezierPath::operator=(const VCubicBezierPath &curve) +{ + if ( &curve == this ) + { + return *this; + } + VAbstractCurve::operator=(curve); + d = curve.d; + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath::~VCubicBezierPath() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VPointF &VCubicBezierPath::operator[](int indx) +{ + return d->path[indx]; +} + +//--------------------------------------------------------------------------------------------------------------------- +const VPointF &VCubicBezierPath::at(int indx) const +{ + return d->path[indx]; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCubicBezierPath::append(const VPointF &point) +{ + if (d->path.size() > 0 && d->path.last().toQPointF() != point.toQPointF()) + { + return; + } + + d->path.append(point); + CreateName(); +} + +//--------------------------------------------------------------------------------------------------------------------- +qint32 VCubicBezierPath::CountSubSpl() const +{ + return CountSubSpl(d->path.size()); +} + +//--------------------------------------------------------------------------------------------------------------------- +qint32 VCubicBezierPath::CountPoints() const +{ + return d->path.size(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCubicBezierPath::Clear() +{ + d->path.clear(); + SetDuplicate(0); +} + +//--------------------------------------------------------------------------------------------------------------------- +VSpline VCubicBezierPath::GetSpline(qint32 index) const +{ + if (CountPoints() < 4) + { + throw VException(tr("Not enough points to create the spline.")); + } + + if (index < 1 || index > CountSubSpl()) + { + throw VException(tr("This spline does not exist.")); + } + + const qint32 base = SubSplOffset(index); + + // Correction the first control point of each next spline curve except for the first. + QPointF p2 = d->path.at(base + 1).toQPointF(); + if (base + 1 > 1) + { + const QPointF b = d->path.at(base).toQPointF(); + QLineF foot1(b, d->path.at(base - 1).toQPointF()); + QLineF foot2(b, p2); + + foot2.setAngle(foot1.angle() + 180); + p2 = foot2.p2(); + } + + VSpline spl(d->path.at(base), p2, d->path.at(base + 2).toQPointF(), d->path.at(base + 3)); + return spl; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VCubicBezierPath::GetStartAngle() const +{ + if (CountSubSpl() > 0) + { + return GetSpline(1).GetStartAngle(); + } + else + { + return 0; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VCubicBezierPath::GetEndAngle() const +{ + const qint32 count = CountSubSpl(); + if (count > 0) + { + return GetSpline(count).GetEndAngle(); + } + else + { + return 0; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VCubicBezierPath::GetSplinePath() const +{ + return d->path; +} + +//--------------------------------------------------------------------------------------------------------------------- +qint32 VCubicBezierPath::CountSubSpl(qint32 size) +{ + if (size <= 0) + { + return 0; + } + return qFloor(qAbs((size - 4) / 3.0 + 1)); +} + +//--------------------------------------------------------------------------------------------------------------------- +qint32 VCubicBezierPath::SubSplOffset(qint32 subSplIndex) +{ + if (subSplIndex <= 0) + { + return -1; + } + + return (subSplIndex - 1) * 3; +} + +//--------------------------------------------------------------------------------------------------------------------- +qint32 VCubicBezierPath::SubSplPointsCount(qint32 countSubSpl) +{ + if (countSubSpl <= 0) + { + return 0; + } + + return ((countSubSpl - 1) * 3 + 4); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPointF VCubicBezierPath::FirstPoint() const +{ + if (not d->path.isEmpty()) + { + return d->path.first(); + } + else + { + return VPointF(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VPointF VCubicBezierPath::LastPoint() const +{ + const qint32 count = CountSubSpl(); + if (count >= 1) + { + return d->path.at(SubSplOffset(count) + 3);// Take last point of the last real spline + } + else + { + return VPointF(); + } +} diff --git a/src/libs/vgeometry/vcubicbezierpath.h b/src/libs/vgeometry/vcubicbezierpath.h new file mode 100644 index 000000000..b83fbd6f6 --- /dev/null +++ b/src/libs/vgeometry/vcubicbezierpath.h @@ -0,0 +1,77 @@ +/************************************************************************ + ** + ** @file vcubicbezierpath.h + ** @author Roman Telezhynskyi + ** @date 16 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 VCUBICBEZIERPATH_H +#define VCUBICBEZIERPATH_H + +#include "vabstractcubicbezierpath.h" +#include "vpointf.h" + +#include + +class VCubicBezierPathData; +class VSpline; + +class VCubicBezierPath : public VAbstractCubicBezierPath +{ + Q_DECLARE_TR_FUNCTIONS(VCubicBezierPath) +public: + explicit VCubicBezierPath(quint32 idObject = 0, Draw mode = Draw::Calculation); + VCubicBezierPath(const VCubicBezierPath &curve); + VCubicBezierPath(const QVector &points, quint32 idObject = 0, Draw mode = Draw::Calculation); + VCubicBezierPath &operator=(const VCubicBezierPath &curve); + virtual ~VCubicBezierPath(); + + VPointF &operator[](int indx); + + const VPointF &at(int indx) const; + + void append(const VPointF &point); + + virtual qint32 CountSubSpl() const Q_DECL_OVERRIDE; + virtual qint32 CountPoints() const Q_DECL_OVERRIDE; + virtual void Clear() Q_DECL_OVERRIDE; + virtual VSpline GetSpline(qint32 index) const Q_DECL_OVERRIDE; + virtual qreal GetStartAngle () const Q_DECL_OVERRIDE; + virtual qreal GetEndAngle () const Q_DECL_OVERRIDE; + + QVector GetSplinePath() const; + + static qint32 CountSubSpl(qint32 size); + static qint32 SubSplOffset(qint32 subSplIndex); + static qint32 SubSplPointsCount(qint32 countSubSpl); +protected: + virtual VPointF FirstPoint() const Q_DECL_OVERRIDE; + virtual VPointF LastPoint() const Q_DECL_OVERRIDE; +private: + QSharedDataPointer d; +}; + +Q_DECLARE_TYPEINFO(VCubicBezierPath, Q_MOVABLE_TYPE); + +#endif // VCUBICBEZIERPATH_H diff --git a/src/libs/vgeometry/vcubicbezierpath_p.h b/src/libs/vgeometry/vcubicbezierpath_p.h new file mode 100644 index 000000000..34fd9b6f0 --- /dev/null +++ b/src/libs/vgeometry/vcubicbezierpath_p.h @@ -0,0 +1,70 @@ +/************************************************************************ + ** + ** @file vcubicbezierpath_p.h + ** @author Roman Telezhynskyi + ** @date 16 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 VCUBICBEZIERPATH_P_H +#define VCUBICBEZIERPATH_P_H + +#include + +#include "vpointf.h" + +#ifdef Q_CC_GNU + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Weffc++" +#endif + +class VCubicBezierPathData : public QSharedData +{ +public: + + VCubicBezierPathData() + : path() + {} + + VCubicBezierPathData(const VCubicBezierPathData &splPath) + : QSharedData(splPath), + path(splPath.path) + {} + + virtual ~VCubicBezierPathData(); + + /** @brief path list of points. */ + QVector path; + +private: + VCubicBezierPathData &operator=(const VCubicBezierPathData &) Q_DECL_EQ_DELETE; +}; + +VCubicBezierPathData::~VCubicBezierPathData() +{} + +#ifdef Q_CC_GNU +#pragma GCC diagnostic pop +#endif + +#endif // VCUBICBEZIERPATH_P_H diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 0f1485b79..5b56a474c 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -375,6 +375,23 @@ void VEllipticalArc::setId(const quint32 &id) CreateName(); } +//--------------------------------------------------------------------------------------------------------------------- +QString VEllipticalArc::NameForHistory(const QString &toolName) const +{ + QString name = toolName + QString(" %1").arg(this->GetCenter().name()); + + if (VAbstractCurve::id() != NULL_ID) + { + name += QString("_%1").arg(VAbstractCurve::id()); + } + + if (GetDuplicate() > 0) + { + name += QString("_%1").arg(GetDuplicate()); + } + return name; +} + //--------------------------------------------------------------------------------------------------------------------- void VEllipticalArc::CreateName() { diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h index 44a3f2cd1..b2d608c20 100644 --- a/src/libs/vgeometry/vellipticalarc.h +++ b/src/libs/vgeometry/vellipticalarc.h @@ -92,6 +92,7 @@ public: QPointF CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const; QPointF CutArc (const qreal &length) const; virtual void setId(const quint32 &id) Q_DECL_OVERRIDE; + virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE; protected: virtual void CreateName() Q_DECL_OVERRIDE; private: diff --git a/src/libs/vgeometry/vgeometry.pri b/src/libs/vgeometry/vgeometry.pri index 94c1f4a34..60586d110 100644 --- a/src/libs/vgeometry/vgeometry.pri +++ b/src/libs/vgeometry/vgeometry.pri @@ -11,7 +11,9 @@ SOURCES += \ $$PWD/vsplinepoint.cpp \ $$PWD/vellipticalarc.cpp \ $$PWD/vcubicbezier.cpp \ - $$PWD/vabstractcubicbezier.cpp + $$PWD/vabstractcubicbezier.cpp \ + $$PWD/vabstractcubicbezierpath.cpp \ + $$PWD/vcubicbezierpath.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -36,4 +38,7 @@ HEADERS += \ $$PWD/vabstractcurve_p.h \ $$PWD/vcubicbezier.h \ $$PWD/vcubicbezier_p.h \ - $$PWD/vabstractcubicbezier.h + $$PWD/vabstractcubicbezier.h \ + $$PWD/vabstractcubicbezierpath.h \ + $$PWD/vcubicbezierpath.h \ + $$PWD/vcubicbezierpath_p.h 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/vgeometry/vsplinepath.cpp b/src/libs/vgeometry/vsplinepath.cpp index 8928ef402..64a2a5590 100644 --- a/src/libs/vgeometry/vsplinepath.cpp +++ b/src/libs/vgeometry/vsplinepath.cpp @@ -43,13 +43,13 @@ * @param mode mode creation spline path. */ VSplinePath::VSplinePath(quint32 idObject, Draw mode) - : VAbstractCurve(GOType::SplinePath, idObject, mode), + : VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode), d(new VSplinePathData()) {} //--------------------------------------------------------------------------------------------------------------------- VSplinePath::VSplinePath(const QVector &points, qreal kCurve, quint32 idObject, Draw mode) - : VAbstractCurve(GOType::SplinePath, idObject, mode), + : VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode), d(new VSplinePathData()) { if (points.size() < 3) @@ -84,7 +84,7 @@ VSplinePath::VSplinePath(const QVector &points, qreal kCurve, qui //--------------------------------------------------------------------------------------------------------------------- VSplinePath::VSplinePath(const QVector &points, quint32 idObject, Draw mode) - : VAbstractCurve(GOType::SplinePath, idObject, mode), + : VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode), d(new VSplinePathData()) { if (points.isEmpty()) @@ -102,7 +102,7 @@ VSplinePath::VSplinePath(const QVector &points, quint32 idObject, * @param splPath spline path. */ VSplinePath::VSplinePath(const VSplinePath &splPath) - : VAbstractCurve(splPath), + : VAbstractCubicBezierPath(splPath), d(splPath.d) {} @@ -128,12 +128,12 @@ void VSplinePath::append(const VSplinePoint &point) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief Count return count point. + * @brief CountSubSpl return count of simple splines. * @return count. */ -qint32 VSplinePath::Count() const +qint32 VSplinePath::CountSubSpl() const { - if (d->path.size() == 0) + if (d->path.isEmpty()) { return 0; } @@ -151,14 +151,16 @@ qint32 VSplinePath::Count() const */ VSpline VSplinePath::GetSpline(qint32 index) const { - if (Count()<1) + if (CountPoints()<1) { throw VException(tr("Not enough points to create the spline.")); } - if (index < 1 || index > Count()) + + if (index < 1 || index > CountSubSpl()) { throw VException(tr("This spline does not exist.")); } + const VSplinePoint &p1 = d->path.at(index-1); const VSplinePoint &p2 = d->path.at(index); VSpline spl(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(), p1.Length2(), @@ -166,63 +168,6 @@ VSpline VSplinePath::GetSpline(qint32 index) const return spl; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetPath return QPainterPath which reprezent spline path. - * @return path. - */ -QPainterPath VSplinePath::GetPath(PathDirection direction) const -{ - QPainterPath painterPath; - for (qint32 i = 1; i <= Count(); ++i) - { - const VSplinePoint &p1 = d->path.at(i-1); - const VSplinePoint &p2 = d->path.at(i); - VSpline spl(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(), p1.Length2(), - p1.Length2Formula(), p2.Length1(), p2.Length1Formula(), 1); - painterPath.addPath(spl.GetPath(direction)); - } - return painterPath; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetPathPoints return list of points what located on path. - * @return list. - */ -QVector VSplinePath::GetPoints() const -{ - QVector pathPoints; - for (qint32 i = 1; i <= Count(); ++i) - { - const VSplinePoint &p1 = d->path.at(i-1); - const VSplinePoint &p2 = d->path.at(i); - VSpline spl(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(), p1.Length2(), - p1.Length2Formula(), p2.Length1(), p2.Length1Formula(), 1); - pathPoints += spl.GetPoints(); - } - return pathPoints; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetLength return length of spline path. - * @return length. - */ -qreal VSplinePath::GetLength() const -{ - qreal length = 0; - for (qint32 i = 1; i <= Count(); ++i) - { - const VSplinePoint &p1 = d->path.at(i-1); - const VSplinePoint &p2 = d->path.at(i); - VSpline spl(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(), p1.Length2(), - p1.Length2Formula(), p2.Length1(), p2.Length1Formula(), 1); - length += spl.GetLength(); - } - return length; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief UpdatePoint update spline point in list. @@ -232,7 +177,7 @@ qreal VSplinePath::GetLength() const */ void VSplinePath::UpdatePoint(qint32 indexSpline, const SplinePointPosition &pos, const VSplinePoint &point) { - if (indexSpline < 1 || indexSpline > Count()) + if (indexSpline < 1 || indexSpline > CountSubSpl()) { throw VException(tr("This spline does not exist.")); } @@ -255,7 +200,7 @@ void VSplinePath::UpdatePoint(qint32 indexSpline, const SplinePointPosition &pos */ VSplinePoint VSplinePath::GetSplinePoint(qint32 indexSpline, SplinePointPosition pos) const { - if (indexSpline < 1 || indexSpline > Count()) + if (indexSpline < 1 || indexSpline > CountSubSpl()) { throw VException(tr("This spline does not exist.")); } @@ -308,98 +253,12 @@ const VSplinePoint &VSplinePath::at(int indx) const return d->path[indx]; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief CutSplinePath cut spline path into two. This method don't return two spline path. You must create spline - * paths by yourself. - * Example: - * QPointF spl1p2, spl1p3, spl2p2, spl2p3; - * qint32 p1 = 0, p2 = 0; - * QPointF point = splPath->CutSplinePath(length, p1, p2, spl1p2, spl1p3, spl2p2, spl2p3); - * - * VSplinePoint splP1 = splPath->at(p1); - * VSplinePoint splP2 = splPath->at(p2); - * VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p, splPath->GetKCurve()); - * VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P(), splPath->GetKCurve()); - * @param length length first spline path. - * @param p1 index first spline point in list. - * @param p2 index second spline point in list. - * @param spl1p2 first control point first spline. - * @param spl1p3 second control point first spline. - * @param spl2p2 first control point second spline. - * @param spl2p3 second control point second spline. - * @return cutting point. - */ -QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, - QPointF &spl2p2, QPointF &spl2p3) 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; - } - else if ( length > fullLength * 0.98) - { - length = fullLength * 0.98; - } - - fullLength = 0; - for (qint32 i = 1; i <= Count(); ++i) - { - const VSplinePoint &point1 = d->path.at(i-1); - const VSplinePoint &point2 = d->path.at(i); - VSpline spl = VSpline(point1.P(), point2.P(), point1.Angle2(), point1.Angle2Formula(), point2.Angle1(), - point2.Angle1Formula(), point1.Length2(), point1.Length2Formula(), point2.Length1(), - point2.Length1Formula(), 1); - fullLength += spl.GetLength(); - if (fullLength > length) - { - p1 = i-1; - p2 = i; - return spl.CutSpline(length - (fullLength - spl.GetLength()), spl1p2, spl1p3, spl2p2, spl2p3); - } - } - return QPointF(); -} - -//--------------------------------------------------------------------------------------------------------------------- -int VSplinePath::Segment(const QPointF &p) const -{ - int index = -1; - for (qint32 i = 1; i <= Count(); ++i) - { - const VSplinePoint &p1 = d->path.at(i-1); - const VSplinePoint &p2 = d->path.at(i); - VSpline spl = VSpline(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(), - p1.Length2(), p1.Length2Formula(), p2.Length1(), p2.Length1Formula(), 1.0); - - const qreal t = spl.ParamT(p); - - if (qFloor(t) == -1) - { - continue; - } - else - { - index = i; - break; - } - } - return index; -} - //--------------------------------------------------------------------------------------------------------------------- qreal VSplinePath::GetStartAngle() const { - if (CountPoint() > 0) + if (CountPoints() > 0) { - return GetSplinePath().first().Angle1(); + return GetSplinePath().first().Angle2(); } else { @@ -410,9 +269,9 @@ qreal VSplinePath::GetStartAngle() const //--------------------------------------------------------------------------------------------------------------------- qreal VSplinePath::GetEndAngle() const { - if (CountPoint() > 0) + if (CountPoints() > 0) { - return GetSplinePath().last().Angle2(); + return GetSplinePath().last().Angle1(); } else { @@ -421,32 +280,38 @@ qreal VSplinePath::GetEndAngle() const } //--------------------------------------------------------------------------------------------------------------------- -void VSplinePath::CreateName() +VPointF VSplinePath::FirstPoint() const { - QString name; if (not d->path.isEmpty()) { - name = splPath; - name.append(QString("_%1").arg(d->path.first().P().name())); - if (d->path.size() > 1) - { - name.append(QString("_%1").arg(d->path.last().P().name())); - } - - if (GetDuplicate() > 0) - { - name += QString("_%1").arg(GetDuplicate()); - } + return d->path.first().P(); + } + else + { + return VPointF(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VPointF VSplinePath::LastPoint() const +{ + const qint32 count = CountSubSpl(); + if (count >= 1) + { + return d->path.at(count).P();// Take last point of the last real spline + } + else + { + return VPointF(); } - setName(name); } //--------------------------------------------------------------------------------------------------------------------- /** - * @brief CountPoint return count point. + * @brief CountPoints return count of points. * @return count. */ -qint32 VSplinePath::CountPoint() const +qint32 VSplinePath::CountPoints() const { return d->path.size(); } @@ -467,7 +332,7 @@ QVector VSplinePath::GetFSplinePath() const QVector points; points.reserve(d->path.size()); - for (qint32 i = 1; i <= Count(); ++i) + for (qint32 i = 1; i <= CountSubSpl(); ++i) { const VSplinePoint &p1 = d->path.at(i-1); const VSplinePoint &p2 = d->path.at(i); diff --git a/src/libs/vgeometry/vsplinepath.h b/src/libs/vgeometry/vsplinepath.h index d8d788367..5ec9c183f 100644 --- a/src/libs/vgeometry/vsplinepath.h +++ b/src/libs/vgeometry/vsplinepath.h @@ -29,7 +29,7 @@ #ifndef VSPLINEPATH_H #define VSPLINEPATH_H -#include "vabstractcurve.h" +#include "vabstractcubicbezierpath.h" #include "vspline.h" #include "vsplinepoint.h" #include @@ -41,7 +41,7 @@ class VSplinePathData; /** * @brief The VSplinePath class keep information about splinePath. */ -class VSplinePath :public VAbstractCurve +class VSplinePath :public VAbstractCubicBezierPath { Q_DECLARE_TR_FUNCTIONS(VSplinePath) public: @@ -56,14 +56,11 @@ public: VSplinePoint &operator[](int indx); void append(const VSplinePoint &point); - qint32 Count() const; - qint32 CountPoint() const; - void Clear(); - VSpline GetSpline(qint32 index) const; - QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const; - QVector GetPoints() const; - qreal GetLength() const; + virtual qint32 CountSubSpl() const Q_DECL_OVERRIDE; + virtual qint32 CountPoints() const Q_DECL_OVERRIDE; + virtual void Clear() Q_DECL_OVERRIDE; + virtual VSpline GetSpline(qint32 index) const Q_DECL_OVERRIDE; QVector GetSplinePath() const; QVector GetFSplinePath() const; @@ -75,13 +72,9 @@ public: VSplinePoint GetSplinePoint(qint32 indexSpline, SplinePointPosition pos) const; const VSplinePoint &at(int indx) const; - - QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, - QPointF &spl2p3) const; - - int Segment(const QPointF &p) const; protected: - virtual void CreateName() Q_DECL_OVERRIDE; + virtual VPointF FirstPoint() const Q_DECL_OVERRIDE; + virtual VPointF LastPoint() const Q_DECL_OVERRIDE; private: QSharedDataPointer d; }; diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 516f2ab3c..28afb2291 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -80,6 +80,7 @@ enum class Tool : ToolVisHolderType Arc, ArcWithLength, SplinePath, + CubicBezierPath, CutSplinePath, PointOfContact, Detail, @@ -129,6 +130,7 @@ enum class Vis : ToolVisHolderType ToolShoulderPoint, ToolSpline, ToolCubicBezier, + ToolCubicBezierPath, ToolTriangle, ToolCutSpline, ToolSplinePath, 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..bfa063f76 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp @@ -0,0 +1,318 @@ +/************************************************************************ + ** + ** @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); + + if (ui->listWidget->count() > 0) + { + ui->listWidget->setCurrentRow(0); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +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 (AllPathBackboneIds().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) + { + const int size = path.CountPoints(); + if (size >= 7) + { + if (size - VCubicBezierPath::SubSplPointsCount(path.CountSubSpl()) == 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::AllPathBackboneIds() 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 = VCubicBezierPath::CountSubSpl(points.size());// Count subpaths + for (qint32 i = 1; i <= count; ++i) + { + const qint32 base = VCubicBezierPath::SubSplOffset(i); + 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 (AllPathBackboneIds().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..ead6931de --- /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 AllPathBackboneIds() 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/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index 7f0c47b0a..d9dd6e457 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -127,7 +127,7 @@ void DialogSplinePath::SetPath(const VSplinePath &value) this->path = value; ui->listWidget->blockSignals(true); ui->listWidget->clear(); - for (qint32 i = 0; i < path.CountPoint(); ++i) + for (qint32 i = 0; i < path.CountPoints(); ++i) { NewItem(path.at(i)); } @@ -179,7 +179,7 @@ void DialogSplinePath::ChosenObject(quint32 id, const SceneObject &type) SCASSERT(visPath != nullptr); visPath->setPath(path); - if (path.CountPoint() == 1) + if (path.CountPoints() == 1) { visPath->VisualMode(NULL_ID); connect(visPath, &VisToolSplinePath::ToolTip, this, &DialogTool::ShowVisToolTip); @@ -666,7 +666,7 @@ void DialogSplinePath::currentPointChanged(int index) 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.P().id() == path.at(0).P().id() && last.P().id() == path.at(path.CountPoint()-1).P().id()) + if (first.P().id() == path.at(0).P().id() && last.P().id() == path.at(path.CountPoints()-1).P().id()) { newDuplicate = -1; ui->lineEditSplPathName->setText(path.name()); @@ -694,7 +694,7 @@ void DialogSplinePath::ShowDialog(bool click) { if (click == false) { - if (path.CountPoint() >= 3) + if (path.CountPoints() >= 3) { emit ToolTip(""); @@ -888,12 +888,12 @@ QSet DialogSplinePath::AllIds() const //--------------------------------------------------------------------------------------------------------------------- bool DialogSplinePath::IsPathValid() const { - if (path.CountPoint() < 3) + if (path.CountPoints() < 3) { return false; } - return (AllIds().size() == path.CountPoint()); + return (AllIds().size() == path.CountPoints()); } //--------------------------------------------------------------------------------------------------------------------- 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 78a51a3f7..b88c12e7a 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -68,7 +68,7 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3 this->setAcceptHoverEvents(true); const QSharedPointer splPath = data->GeometricObject(id); - for (qint32 i = 1; i<=splPath->Count(); ++i) + for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i) { const VSpline spl = splPath->GetSpline(i); @@ -138,7 +138,7 @@ VToolSplinePath* VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene SCASSERT(dialogTool != nullptr); VSplinePath *path = new VSplinePath(dialogTool->GetPath()); const QString color = dialogTool->GetColor(); - for (qint32 i = 0; i < path->CountPoint(); ++i) + for (qint32 i = 0; i < path->CountPoints(); ++i) { doc->IncrementReferens((*path)[i].P().getIdTool()); } @@ -302,7 +302,7 @@ void VToolSplinePath::SetSplinePathAttributes(QDomElement &domElement, const VSp void VToolSplinePath::UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VSplinePath &path) { VDomDocument::RemoveAllChildren(element); - for (qint32 i = 0; i < path.CountPoint(); ++i) + for (qint32 i = 0; i < path.CountPoints(); ++i) { AddPathPoint(doc, element, path.at(i)); } @@ -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.Count(); ++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()); } } @@ -407,7 +407,7 @@ void VToolSplinePath::SaveDialog(QDomElement &domElement) SCASSERT(dialogTool != nullptr); const VSplinePath splPath = dialogTool->GetPath(); - for (qint32 i = 1; i <= splPath.Count(); ++i) + for (qint32 i = 1; i <= splPath.CountSubSpl(); ++i) { VSpline spl = splPath.GetSpline(i); qint32 j = i*2; @@ -605,7 +605,7 @@ bool VToolSplinePath::IsMovable(int index) const const auto splPath = VAbstractTool::data.GeometricObject(id); //index == -1 - can delete, but decided to left - if (index == -1 || index < 1 || index > splPath->Count()) + if (index == -1 || index < 1 || index > splPath->CountSubSpl()) { return false; } @@ -641,7 +641,7 @@ void VToolSplinePath::RefreshGeometry() qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); const auto splPath = VAbstractTool::data.GeometricObject(id); - for (qint32 i = 1; i<=splPath->Count(); ++i) + for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i) { const qint32 j = i*2; 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/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp index 2cba23674..0f8a20a82 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp @@ -154,7 +154,7 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString VSplinePath *splPath1 = new VSplinePath(); VSplinePath *splPath2 = new VSplinePath(); - for (qint32 i = 0; i < splPath->CountPoint(); i++) + for (qint32 i = 0; i < splPath->CountPoints(); i++) { if (i <= p1 && i < p2) { 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/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 39d1a1b45..0cce48dde 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -216,7 +216,7 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte VSplinePath *path = new VSplinePath(); path->setMode(Draw::Modeling); const QSharedPointer splinePath = data->GeometricObject(det.at(i).getId()); - for (qint32 i = 1; i <= splinePath->Count(); ++i) + for (qint32 i = 1; i <= splinePath->CountSubSpl(); ++i) { const VSplinePoint &point1 = splinePath->at(i-1); const VSplinePoint &point2 = splinePath->at(i); @@ -366,7 +366,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const path->setMode(Draw::Modeling); const QSharedPointer splinePath = data->GeometricObject(det.at(i).getId()); SCASSERT(splinePath != nullptr); - for (qint32 i = 1; i <= splinePath->Count(); ++i) + for (qint32 i = 1; i <= splinePath->CountSubSpl(); ++i) { const VSplinePoint &point1 = splinePath->at(i-1); const VSplinePoint &point2 = splinePath->at(i); diff --git a/src/libs/vtools/visualization/vistoolcubicbezier.cpp b/src/libs/vtools/visualization/vistoolcubicbezier.cpp index 6234c6913..7d534657a 100644 --- a/src/libs/vtools/visualization/vistoolcubicbezier.cpp +++ b/src/libs/vtools/visualization/vistoolcubicbezier.cpp @@ -39,14 +39,16 @@ VisToolCubicBezier::VisToolCubicBezier(const VContainer *data, QGraphicsItem *pa point2(nullptr), point3(nullptr), point4(nullptr), - helpLine(nullptr) + helpLine1(nullptr), + helpLine2(nullptr) { + helpLine1 = InitItem(mainColor, this); + helpLine2 = InitItem(mainColor, this); + point1 = InitPoint(supportColor, this); point2 = InitPoint(supportColor, this); //-V656 point3 = InitPoint(supportColor, this); //-V656 point4 = InitPoint(supportColor, this); //-V656 - - helpLine = InitItem(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- @@ -60,19 +62,17 @@ void VisToolCubicBezier::RefreshGeometry() if (object1Id > NULL_ID) { const auto first = Visualization::data->GeometricObject(object1Id); - DrawPoint(point1, first->toQPointF(), supportColor); + DrawPoint(point1, first->toQPointF(), Qt::DashLine); if (object2Id <= NULL_ID) { - const QLineF line = QLineF(first->toQPointF(), Visualization::scenePos); - DrawLine(helpLine, line, mainColor, lineStyle); + DrawLine(helpLine1, QLineF(first->toQPointF(), Visualization::scenePos), mainColor, Qt::DashLine); } else { - helpLine->setVisible(false); - const auto second = Visualization::data->GeometricObject(object2Id); DrawPoint(point2, second->toQPointF(), supportColor); + DrawLine(helpLine1, QLineF(first->toQPointF(), second->toQPointF()), mainColor, Qt::DashLine); if (object3Id <= NULL_ID) { @@ -89,11 +89,13 @@ void VisToolCubicBezier::RefreshGeometry() { VCubicBezier spline(*first, *second, *third, VPointF(Visualization::scenePos)); DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + DrawLine(helpLine2, QLineF(third->toQPointF(), Visualization::scenePos), mainColor, Qt::DashLine); } else { const auto fourth = Visualization::data->GeometricObject(object4Id); DrawPoint(point4, fourth->toQPointF(), supportColor); + DrawLine(helpLine2, QLineF(fourth->toQPointF(), third->toQPointF()), mainColor, Qt::DashLine); VCubicBezier spline(*first, *second, *third, *fourth); DrawPath(this, spline.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); diff --git a/src/libs/vtools/visualization/vistoolcubicbezier.h b/src/libs/vtools/visualization/vistoolcubicbezier.h index d67fcfdf7..2fc6d5fd9 100644 --- a/src/libs/vtools/visualization/vistoolcubicbezier.h +++ b/src/libs/vtools/visualization/vistoolcubicbezier.h @@ -56,7 +56,8 @@ protected: QGraphicsEllipseItem *point2; QGraphicsEllipseItem *point3; QGraphicsEllipseItem *point4; - QGraphicsLineItem *helpLine; + QGraphicsLineItem *helpLine1; + QGraphicsLineItem *helpLine2; }; #endif // VISTOOLCUBICBEZIER_H diff --git a/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp b/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp new file mode 100644 index 000000000..5e0445836 --- /dev/null +++ b/src/libs/vtools/visualization/vistoolcubicbezierpath.cpp @@ -0,0 +1,280 @@ +/************************************************************************ + ** + ** @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() +{ + const QVector pathPoints = path.GetSplinePath(); + const int size = pathPoints.size(); + if (size > 0) + { + const int countSubSpl = VCubicBezierPath::CountSubSpl(size); + + 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) + { + if (countSubSpl < 1) + { + Creating(pathPoints, size-1); + } + else + { + const qint32 last = VCubicBezierPath::SubSplOffset(countSubSpl) + 3; + Creating(pathPoints, size-1-last); + } + } + + if (countSubSpl >= 1) + { + DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); + + 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); + } + } + + RefreshToolTip(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCubicBezierPath::setPath(const VCubicBezierPath &value) +{ + path = value; + + RefreshToolTip(); +} + +//--------------------------------------------------------------------------------------------------------------------- +// 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) +{ + const int size = pathPoints.size(); + if (pathPoints.isEmpty() || size+1 < pointsLeft) + { + return; + } + + int subSplPoints = 0; + const int subSplCount = VCubicBezierPath::CountSubSpl(size); + if (subSplCount >= 1) + { + subSplPoints = VCubicBezierPath::SubSplPointsCount(subSplCount)-1; + } + + switch(pointsLeft) + { + case 0: + { + const VPointF p1 = pathPoints.last(); + if (pathPoints.size() >= 4) + { + QLineF p1p2(p1.toQPointF(), Visualization::scenePos); + QLineF prP3p1(pathPoints.at(size-2).toQPointF(), p1.toQPointF()); + p1p2.setAngle(prP3p1.angle()); + + const QPointF p2 = p1p2.p2(); + + VSpline spline(p1, p2, Visualization::scenePos, VPointF(Visualization::scenePos)); + DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + + DrawLine(helpLine1, p1p2, mainColor, Qt::DashLine); + + const int preLastPoint = subSplCount * 2; + QGraphicsEllipseItem *p2Ctrl = this->getPoint(ctrlPoints, static_cast(preLastPoint)); + DrawPoint(p2Ctrl, p2, Qt::green); + } + else + { + DrawLine(helpLine1, QLineF(p1.toQPointF(), Visualization::scenePos), mainColor, Qt::DashLine); + } + break; + } + case 1: + { + const VPointF p1 = pathPoints.at(subSplPoints + pointsLeft-1); + QPointF p2 = pathPoints.at(subSplPoints + pointsLeft).toQPointF(); + + if (subSplCount >= 1) + { + QLineF p1p2(p1.toQPointF(), p2); + QLineF prP3p1(pathPoints.at(subSplPoints + pointsLeft-2).toQPointF(), p1.toQPointF()); + p1p2.setAngle(prP3p1.angle()); + p2 = p1p2.p2(); + } + + 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); + + const int preLastPoint = subSplCount * 2; + QGraphicsEllipseItem *p2Ctrl = this->getPoint(ctrlPoints, static_cast(preLastPoint)); + DrawPoint(p2Ctrl, p2, Qt::green); + break; + } + case 2: + { + const VPointF p1 = pathPoints.at(subSplPoints + pointsLeft-2); + QPointF p2 = pathPoints.at(subSplPoints + pointsLeft-1).toQPointF(); + const QPointF p3 = pathPoints.at(subSplPoints + pointsLeft).toQPointF(); + + if (subSplCount >= 1) + { + QLineF p1p2(p1.toQPointF(), p2); + QLineF prP3p1(pathPoints.at(subSplPoints + pointsLeft-3).toQPointF(), p1.toQPointF()); + p1p2.setAngle(prP3p1.angle()); + p2 = p1p2.p2(); + } + + 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); + + const int preLastPoint = subSplCount * 2; + QGraphicsEllipseItem *p2Ctrl = this->getPoint(ctrlPoints, static_cast(preLastPoint)); + DrawPoint(p2Ctrl, p2, Qt::green); + break; + } + default: + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCubicBezierPath::RefreshToolTip() +{ + const int size = path.CountPoints(); + if (size > 0) + { + const int countSubSpl = VCubicBezierPath::CountSubSpl(size); + + if (size < 7) + { + Visualization::toolTip = tr("Curved path: select seven or more points"); + } + else if (size >= 7 && size - VCubicBezierPath::SubSplPointsCount(countSubSpl) == 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"); + } + emit ToolTip(Visualization::toolTip); + } +} diff --git a/src/libs/vtools/visualization/vistoolcubicbezierpath.h b/src/libs/vtools/visualization/vistoolcubicbezierpath.h new file mode 100644 index 000000000..32943d714 --- /dev/null +++ b/src/libs/vtools/visualization/vistoolcubicbezierpath.h @@ -0,0 +1,67 @@ +/************************************************************************ + ** + ** @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; + +private: + QGraphicsEllipseItem *getPoint(QVector &points, quint32 i, qreal z = 0); + QGraphicsLineItem *getLine(quint32 i); + void Creating(const QVector &pathPoints , int pointsLeft); + void RefreshToolTip(); +}; + +#endif // VISTOOLCUBICBEZIERPATH_H diff --git a/src/libs/vtools/visualization/vistoolcutsplinepath.cpp b/src/libs/vtools/visualization/vistoolcutsplinepath.cpp index 2b43faf89..35737a802 100644 --- a/src/libs/vtools/visualization/vistoolcutsplinepath.cpp +++ b/src/libs/vtools/visualization/vistoolcutsplinepath.cpp @@ -73,7 +73,7 @@ void VisToolCutSplinePath::RefreshGeometry() VSplinePath spPath1 = VSplinePath(); VSplinePath spPath2 = VSplinePath(); - for (qint32 i = 0; i < splPath->CountPoint(); i++) + for (qint32 i = 0; i < splPath->CountPoints(); i++) { if (i <= p1 && i < p2) { diff --git a/src/libs/vtools/visualization/vistoolsplinepath.cpp b/src/libs/vtools/visualization/vistoolsplinepath.cpp index a9dfb6617..47e0d16fa 100644 --- a/src/libs/vtools/visualization/vistoolsplinepath.cpp +++ b/src/libs/vtools/visualization/vistoolsplinepath.cpp @@ -53,7 +53,7 @@ VisToolSplinePath::~VisToolSplinePath() //--------------------------------------------------------------------------------------------------------------------- void VisToolSplinePath::RefreshGeometry() { - if (path.CountPoint() > 0) + if (path.CountPoints() > 0) { const QVector pathPoints = path.GetSplinePath(); const int size = pathPoints.size(); @@ -68,9 +68,9 @@ void VisToolSplinePath::RefreshGeometry() { if (size > 1) { - for (qint32 i = 1; i<=path.Count(); ++i) + for (qint32 i = 1; i<=path.CountSubSpl(); ++i) { - const int preLastPoint = (path.Count() - 1) * 2; + const int preLastPoint = (path.CountSubSpl() - 1) * 2; const int lastPoint = preLastPoint + 1; VSpline spl = path.GetSpline(i); @@ -90,7 +90,7 @@ void VisToolSplinePath::RefreshGeometry() DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); } - if (path.CountPoint() < 3) + if (path.CountPoints() < 3) { Visualization::toolTip = tr("Curved path: select three or more points"); } 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 diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index a57763b63..5e6434567 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -56,7 +56,8 @@ SOURCES += \ tst_vdetail.cpp \ tst_vabstractcurve.cpp \ tst_findpoint.cpp \ - tst_vellipticalarc.cpp + tst_vellipticalarc.cpp \ + tst_vcubicbezierpath.cpp HEADERS += \ tst_vposter.h \ @@ -80,7 +81,8 @@ HEADERS += \ tst_vdetail.h \ tst_vabstractcurve.h \ tst_findpoint.h \ - tst_vellipticalarc.h + tst_vellipticalarc.h \ + tst_vcubicbezierpath.h # Set using ccache. Function enable_ccache() defined in common.pri. $$enable_ccache() diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index ec78c032f..a7d7c15e9 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -48,6 +48,7 @@ #include "tst_vdetail.h" #include "tst_findpoint.h" #include "tst_vabstractcurve.h" +#include "tst_vcubicbezierpath.h" int main(int argc, char** argv) { @@ -82,6 +83,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_VCommandLine()); ASSERT_TEST(new TST_TSTranslation()); ASSERT_TEST(new TST_VAbstractCurve()); + ASSERT_TEST(new TST_VCubicBezierPath()); return status; } diff --git a/src/test/ValentinaTest/tst_vcubicbezierpath.cpp b/src/test/ValentinaTest/tst_vcubicbezierpath.cpp new file mode 100644 index 000000000..d4e5a6862 --- /dev/null +++ b/src/test/ValentinaTest/tst_vcubicbezierpath.cpp @@ -0,0 +1,122 @@ +/************************************************************************ + ** + ** @file tst_vcubicbezierpath.cpp + ** @author Roman Telezhynskyi + ** @date 19 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 "tst_vcubicbezierpath.h" +#include "../vgeometry/vcubicbezierpath.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_VCubicBezierPath::TST_VCubicBezierPath(QObject *parent) : + QObject(parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VCubicBezierPath::TestCountSubSpl_data() const +{ + QTest::addColumn("points"); + QTest::addColumn("countSubSpl"); + + QTest::newRow("Empty") << 0 << 0; + QTest::newRow("1 point") << 1 << 0; + QTest::newRow("2 points") << 2 << 0; + QTest::newRow("3 points") << 3 << 0; + QTest::newRow("4 points") << 4 << 1; + QTest::newRow("5 points") << 5 << 1; + QTest::newRow("6 points") << 6 << 1; + QTest::newRow("7 points") << 7 << 2; + QTest::newRow("8 points") << 8 << 2; + QTest::newRow("9 points") << 9 << 2; + QTest::newRow("10 points") << 10 << 3; + QTest::newRow("11 points") << 11 << 3; + QTest::newRow("12 points") << 12 << 3; + QTest::newRow("13 points") << 13 << 4; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VCubicBezierPath::TestCountSubSpl() const +{ + QFETCH(qint32, points); + QFETCH(qint32, countSubSpl); + + const qint32 res = VCubicBezierPath::CountSubSpl(points); + QCOMPARE(res, countSubSpl); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VCubicBezierPath::TestSubSplOffset_data() const +{ + QTest::addColumn("subSplIndex"); + QTest::addColumn("offset"); + + QTest::newRow("Wrong index") << -1 << -1; + QTest::newRow("Wrong index") << 0 << -1; + QTest::newRow("1 subSpl") << 1 << 0; + QTest::newRow("2 subSpls") << 2 << 3; + QTest::newRow("3 subSpls") << 3 << 6; + QTest::newRow("4 subSpls") << 4 << 9; + QTest::newRow("5 subSpls") << 5 << 12; + QTest::newRow("6 subSpls") << 6 << 15; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VCubicBezierPath::TestSubSplOffset() const +{ + QFETCH(qint32, subSplIndex); + QFETCH(qint32, offset); + + const qint32 res = VCubicBezierPath::SubSplOffset(subSplIndex); + QCOMPARE(res, offset); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VCubicBezierPath::TestSubSplPointsCount_data() const +{ + QTest::addColumn("countSubSpl"); + QTest::addColumn("points"); + + QTest::newRow("Wrong count") << -1 << 0; + QTest::newRow("Wrong count") << 0 << 0; + QTest::newRow("1 subSpl") << 1 << 4; + QTest::newRow("2 subSpls") << 2 << 7; + QTest::newRow("3 subSpls") << 3 << 10; + QTest::newRow("4 subSpls") << 4 << 13; + QTest::newRow("5 subSpls") << 5 << 16; + QTest::newRow("6 subSpls") << 6 << 19; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VCubicBezierPath::TestSubSplPointsCount() const +{ + QFETCH(qint32, countSubSpl); + QFETCH(qint32, points); + + const qint32 res = VCubicBezierPath::SubSplPointsCount(countSubSpl); + QCOMPARE(res, points); +} diff --git a/src/test/ValentinaTest/tst_vcubicbezierpath.h b/src/test/ValentinaTest/tst_vcubicbezierpath.h new file mode 100644 index 000000000..166afe157 --- /dev/null +++ b/src/test/ValentinaTest/tst_vcubicbezierpath.h @@ -0,0 +1,53 @@ +/************************************************************************ + ** + ** @file tst_vcubicbezierpath.h + ** @author Roman Telezhynskyi + ** @date 19 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 TST_VCUBICBEZIERPATH_H +#define TST_VCUBICBEZIERPATH_H + +#include + +class TST_VCubicBezierPath : public QObject +{ + Q_OBJECT +public: + explicit TST_VCubicBezierPath(QObject *parent = nullptr); + +private slots: + void TestCountSubSpl_data() const; + void TestCountSubSpl() const; + void TestSubSplOffset_data() const; + void TestSubSplOffset() const; + void TestSubSplPointsCount_data() const; + void TestSubSplPointsCount() const; + +private: + Q_DISABLE_COPY(TST_VCubicBezierPath) + +}; + +#endif // TST_VCUBICBEZIERPATH_H