diff --git a/ChangeLog.txt b/ChangeLog.txt index 592abbc6e..a8034a2bd 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -39,6 +39,7 @@ - [#424] Improve Formula Wizard dialog. - Added "All/None" menu in detail list area for easier handling of many parts. - [#560] Flipped pattern pieces in Layout. +- [#138] New tool: 'Mirror Point' or 'Symmetric Point'. # Version 0.4.5 - [#435] Valentina doesn't change the cursor. diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index ff55d7efb..5a618fc41 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -75,7 +75,7 @@ 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) == 45, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was used in switch."); switch (item->type()) { @@ -185,6 +185,12 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolRotation::Type: ShowOptionsToolRotation(item); break; + case VToolFlippingByLine::Type: + ShowOptionsToolFlippingByLine(item); + break; + case VToolFlippingByAxis::Type: + ShowOptionsToolFlippingByAxis(item); + break; default: break; } @@ -199,7 +205,7 @@ void VToolOptionsPropertyBrowser::UpdateOptions() } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -299,6 +305,12 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VToolRotation::Type: UpdateOptionsToolRotation(); break; + case VToolFlippingByLine::Type: + UpdateOptionsToolFlippingByLine(); + break; + case VToolFlippingByAxis::Type: + UpdateOptionsToolFlippingByAxis(); + break; default: break; } @@ -334,7 +346,7 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -428,6 +440,12 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolRotation::Type: ChangeDataToolRotation(prop); break; + case VToolFlippingByLine::Type: + ChangeDataToolFlippingByLine(prop); + break; + case VToolFlippingByAxis::Type: + ChangeDataToolFlippingByAxis(prop); + break; default: break; } @@ -556,6 +574,16 @@ void VToolOptionsPropertyBrowser::AddPropertyHCrossPoint(Tool *i, const QString AddProperty(itemProperty, AttrHCrossPoint); } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyAxisType(Tool *i, const QString &propertyName) +{ + auto itemProperty = new VEnumProperty(propertyName); + itemProperty->setLiterals(QStringList()<< tr("Vertical axis") << tr("Horizontal axis")); + itemProperty->setValue(static_cast(i->GetAxisType())-1); + AddProperty(itemProperty, AttrAxisType); +} + //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::AddPropertyLineType(Tool *i, const QString &propertyName, @@ -772,6 +800,20 @@ void VToolOptionsPropertyBrowser::SetHCrossCurvesPoint(const QVariant &value) } } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::SetAxisType(const QVariant &value) +{ + if (auto i = qgraphicsitem_cast(currentItem)) + { + i->SetAxisType(GetCrossPoint(value)); + } + else + { + qWarning()<<"Can't cast item"; + } +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::AddProperty(VProperty *property, const QString &id) { @@ -1601,6 +1643,50 @@ void VToolOptionsPropertyBrowser::ChangeDataToolRotation(VProperty *property) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolFlippingByLine(VProperty *property) +{ + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + switch (PropertiesList().indexOf(id)) + { + case 38: // AttrSuffix + SetOperationSuffix(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + switch (PropertiesList().indexOf(id)) + { + case 39: // AttrAxisType + { + const QVariant value = property->data(VProperty::DPC_Data, Qt::EditRole); + SetAxisType(value); + break; + } + case 38: // AttrSuffix + SetOperationSuffix(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<GetFormulaAngle(), AttrAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolFlippingByLine(QGraphicsItem *item) +{ + VToolFlippingByLine *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool flipping by line")); + + AddPropertyOperationSuffix(i, tr("Suffix")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolFlippingByAxis(QGraphicsItem *item) +{ + VToolFlippingByAxis *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool flipping by axis")); + + AddPropertyAxisType(i, tr("Axis type")); + AddPropertyOperationSuffix(i, tr("Suffix")); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolSinglePoint() { @@ -2451,6 +2558,21 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolRotation() idToProperty[AttrAngle]->setValue(valueAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolFlippingByLine() +{ + VToolFlippingByLine *i = qgraphicsitem_cast(currentItem); + idToProperty[AttrSuffix]->setValue(i->Suffix()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolFlippingByAxis() +{ + VToolFlippingByAxis *i = qgraphicsitem_cast(currentItem); + idToProperty[AttrAxisType]->setValue(static_cast(i->GetAxisType())-1); + idToProperty[AttrSuffix]->setValue(i->Suffix()); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VToolOptionsPropertyBrowser::PropertiesList() const { @@ -2492,6 +2614,7 @@ QStringList VToolOptionsPropertyBrowser::PropertiesList() const << AttrHCrossPoint /* 35 */ << AttrLength1 /* 36 */ << AttrLength2 /* 37 */ - << AttrSuffix; /* 38 */ + << AttrSuffix /* 38 */ + << AttrAxisType; /* 39 */ return attr; } diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index 2c69b5513..f23185bd2 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -90,6 +90,9 @@ private: template void SetHCrossCurvesPoint(const QVariant &value); + template + void SetAxisType(const QVariant &value); + template void AddPropertyObjectName(Tool *i, const QString &propertyName, bool readOnly = false); @@ -111,6 +114,9 @@ private: template void AddPropertyHCrossPoint(Tool *i, const QString &propertyName); + template + void AddPropertyAxisType(Tool *i, const QString &propertyName); + template void AddPropertyLineType(Tool *i, const QString &propertyName, const QMap &styles); @@ -152,6 +158,8 @@ private: void ChangeDataToolLineIntersectAxis(VPE::VProperty *property); void ChangeDataToolCurveIntersectAxis(VPE::VProperty *property); void ChangeDataToolRotation(VPE::VProperty *property); + void ChangeDataToolFlippingByLine(VPE::VProperty *property); + void ChangeDataToolFlippingByAxis(VPE::VProperty *property); void ShowOptionsToolSinglePoint(QGraphicsItem *item); void ShowOptionsToolEndLine(QGraphicsItem *item); @@ -183,6 +191,8 @@ private: void ShowOptionsToolLineIntersectAxis(QGraphicsItem *item); void ShowOptionsToolCurveIntersectAxis(QGraphicsItem *item); void ShowOptionsToolRotation(QGraphicsItem *item); + void ShowOptionsToolFlippingByLine(QGraphicsItem *item); + void ShowOptionsToolFlippingByAxis(QGraphicsItem *item); void UpdateOptionsToolSinglePoint(); void UpdateOptionsToolEndLine(); @@ -214,6 +224,8 @@ private: void UpdateOptionsToolLineIntersectAxis(); void UpdateOptionsToolCurveIntersectAxis(); void UpdateOptionsToolRotation(); + void UpdateOptionsToolFlippingByLine(); + void UpdateOptionsToolFlippingByAxis(); }; #endif // VTOOLOPTIONSPROPERTYBROWSER_H diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index beab2bedb..c73d7fb19 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -207,7 +207,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") 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) == 45, "Not all tools was used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -387,6 +387,8 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::NodeSplinePath: case Tool::Group: case Tool::Rotation: + case Tool::FlippingByLine: + case Tool::FlippingByAxis: return QString(); } } diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index b6d2c79ed..3f0b08067 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1033,6 +1033,28 @@ void MainWindow::ToolRotation(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolFlippingByLine(bool checked) +{ + ToolSelectOperationObjects(); + SetToolButtonWithApply(checked, Tool::FlippingByLine, + ":/cursor/flipping_line_cursor.png", + tr("Select one or more objects, Enter - confirm selection"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolFlippingByAxis(bool checked) +{ + ToolSelectOperationObjects(); + SetToolButtonWithApply(checked, Tool::FlippingByAxis, + ":/cursor/flipping_axis_cursor.png", + tr("Select one or more objects, Enter - confirm selection"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ClosedDialogGroup(int result) { @@ -1702,6 +1724,8 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonTrueDarts, &QToolButton::clicked, this, &MainWindow::ToolTrueDarts); connect(ui->toolButtonGroup, &QToolButton::clicked, this, &MainWindow::ToolGroup); connect(ui->toolButtonRotation, &QToolButton::clicked, this, &MainWindow::ToolRotation); + connect(ui->toolButtonFlippingByLine, &QToolButton::clicked, this, &MainWindow::ToolFlippingByLine); + connect(ui->toolButtonFlippingByAxis, &QToolButton::clicked, this, &MainWindow::ToolFlippingByAxis); connect(ui->toolButtonMidpoint, &QToolButton::clicked, this, &MainWindow::ToolMidpoint); connect(ui->toolButtonLayoutExportAs, &QToolButton::clicked, this, &MainWindow::ExportLayoutAs); } @@ -1731,7 +1755,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") 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) == 45, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was handled."); qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; @@ -1871,6 +1895,12 @@ void MainWindow::CancelTool() case Tool::Rotation: ui->toolButtonRotation->setChecked(false); break; + case Tool::FlippingByLine: + ui->toolButtonFlippingByLine->setChecked(false); + break; + case Tool::FlippingByAxis: + ui->toolButtonFlippingByAxis->setChecked(false); + break; } // Crash: using CRTL+Z while using line tool. @@ -2919,6 +2949,9 @@ void MainWindow::SetEnableTool(bool enable) break; } + // This check helps to find missed tools + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools were handled."); + //Drawing Tools ui->toolButtonEndLine->setEnabled(drawTools); ui->toolButtonLine->setEnabled(drawTools); @@ -2952,6 +2985,8 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonTrueDarts->setEnabled(drawTools); ui->toolButtonGroup->setEnabled(drawTools); ui->toolButtonRotation->setEnabled(drawTools); + ui->toolButtonFlippingByLine->setEnabled(drawTools); + ui->toolButtonFlippingByAxis->setEnabled(drawTools); ui->toolButtonMidpoint->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -3234,7 +3269,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") 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) == 45, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was handled."); if (currentTool == lastUsedTool) { @@ -3400,6 +3435,14 @@ void MainWindow::LastUsedTool() ui->toolButtonRotation->setChecked(true); ToolRotation(true); break; + case Tool::FlippingByLine: + ui->toolButtonFlippingByLine->setChecked(true); + ToolFlippingByLine(true); + break; + case Tool::FlippingByAxis: + ui->toolButtonFlippingByAxis->setChecked(true); + ToolFlippingByAxis(true); + break; } } diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 375ffcda4..3361c8ecd 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -139,6 +139,8 @@ private slots: void ToolUnionDetails(bool checked); void ToolGroup(bool checked); void ToolRotation(bool checked); + void ToolFlippingByLine(bool checked); + void ToolFlippingByAxis(bool checked); void ToolCutArc(bool checked); void ToolLineIntersectAxis(bool checked); void ToolCurveIntersectAxis(bool checked); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index ae7bebe5e..aa0b01eed 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -14,7 +14,7 @@ Valentina - + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png @@ -48,14 +48,14 @@ Tools - 6 + 4 0 0 - 100 + 117 358 @@ -69,7 +69,7 @@ Tools for creating points. - + :/icon/16x16/toolsectionpoint.png:/icon/16x16/toolsectionpoint.png @@ -94,7 +94,7 @@ ... - + :/toolicon/32x32/along_line.png:/toolicon/32x32/along_line.png @@ -120,7 +120,7 @@ ... - + :/toolicon/32x32/normal.png:/toolicon/32x32/normal.png @@ -146,7 +146,7 @@ ... - + :/toolicon/32x32/bisector.png:/toolicon/32x32/bisector.png @@ -172,7 +172,7 @@ ... - + :/toolicon/32x32/shoulder.png:/toolicon/32x32/shoulder.png @@ -198,7 +198,7 @@ ... - + :/toolicon/32x32/point_of_contact.png:/toolicon/32x32/point_of_contact.png @@ -224,7 +224,7 @@ ... - + :/toolicon/32x32/triangle.png:/toolicon/32x32/triangle.png @@ -250,7 +250,7 @@ ... - + :/toolicon/32x32/point_of_intersection.png:/toolicon/32x32/point_of_intersection.png @@ -276,7 +276,7 @@ ... - + :/toolicon/32x32/height.png:/toolicon/32x32/height.png @@ -302,7 +302,7 @@ ... - + :/toolicon/32x32/line_intersect_axis.png:/toolicon/32x32/line_intersect_axis.png @@ -328,7 +328,7 @@ ... - + :/toolicon/32x32/true_darts.png:/toolicon/32x32/true_darts.png @@ -354,7 +354,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -380,7 +380,7 @@ ... - + :/toolicon/32x32/midpoint.png:/toolicon/32x32/midpoint.png @@ -406,7 +406,7 @@ ... - + :/toolicon/32x32/segment.png:/toolicon/32x32/segment.png @@ -427,7 +427,7 @@ 0 0 - 100 + 130 110 @@ -441,7 +441,7 @@ Tools for creating lines. - + :/icon/16x16/toolsectionline.png:/icon/16x16/toolsectionline.png @@ -463,7 +463,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -489,7 +489,7 @@ ... - + :/toolicon/32x32/line.png:/toolicon/32x32/line.png @@ -515,7 +515,7 @@ ... - + :/toolicon/32x32/intersect.png:/toolicon/32x32/intersect.png @@ -536,7 +536,7 @@ 0 0 - 100 + 130 248 @@ -550,7 +550,7 @@ Tools for creating curves. - + :/icon/16x16/toolsectioncurve.png:/icon/16x16/toolsectioncurve.png @@ -572,7 +572,7 @@ ... - + :/toolicon/32x32/spline_cut_point.png:/toolicon/32x32/spline_cut_point.png @@ -598,7 +598,7 @@ ... - + :/toolicon/32x32/cubic_bezier.png:/toolicon/32x32/cubic_bezier.png @@ -624,7 +624,7 @@ ... - + :/toolicon/32x32/splinePath.png:/toolicon/32x32/splinePath.png @@ -650,7 +650,7 @@ ... - + :/toolicon/32x32/splinePath_cut_point.png:/toolicon/32x32/splinePath_cut_point.png @@ -673,7 +673,7 @@ ... - + :/toolicon/32x32/cubic_bezier_path.png:/toolicon/32x32/cubic_bezier_path.png @@ -699,7 +699,7 @@ ... - + :/toolicon/32x32/intersection_curves.png:/toolicon/32x32/intersection_curves.png @@ -725,7 +725,7 @@ ... - + :/toolicon/32x32/curve_intersect_axis.png:/toolicon/32x32/curve_intersect_axis.png @@ -751,7 +751,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -777,7 +777,7 @@ ... - + :/toolicon/32x32/spline.png:/toolicon/32x32/spline.png @@ -798,7 +798,7 @@ 0 0 - 100 + 130 248 @@ -812,7 +812,7 @@ Tools for creating arcs. - + :/icon/16x16/toolsectionarc.png:/icon/16x16/toolsectionarc.png @@ -834,7 +834,7 @@ ... - + :/toolicon/32x32/arc.png:/toolicon/32x32/arc.png @@ -860,7 +860,7 @@ ... - + :/toolicon/32x32/arc_cut.png:/toolicon/32x32/arc_cut.png @@ -886,7 +886,7 @@ ... - + :/toolicon/32x32/arc_intersect_axis.png:/toolicon/32x32/arc_intersect_axis.png @@ -912,7 +912,7 @@ ... - + :/toolicon/32x32/point_of_intersection_arcs.png:/toolicon/32x32/point_of_intersection_arcs.png @@ -938,7 +938,7 @@ ... - + :/toolicon/32x32/point_of_intersection_circles.png:/toolicon/32x32/point_of_intersection_circles.png @@ -964,7 +964,7 @@ ... - + :/toolicon/32x32/point_from_circle_and_tangent.png:/toolicon/32x32/point_from_circle_and_tangent.png @@ -990,7 +990,7 @@ ... - + :/toolicon/32x32/point_from_arc_and_tangent.png:/toolicon/32x32/point_from_arc_and_tangent.png @@ -1016,7 +1016,7 @@ ... - + :/toolicon/32x32/arc_with_length.png:/toolicon/32x32/arc_with_length.png @@ -1042,7 +1042,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -1063,12 +1063,12 @@ 0 0 - 100 - 104 + 130 + 356 - + :/icon/16x16/operations.png:/icon/16x16/operations.png @@ -1090,7 +1090,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -1116,7 +1116,7 @@ ... - + :/toolicon/32x32/group_plus.png:/toolicon/32x32/group_plus.png @@ -1142,7 +1142,7 @@ ... - + :/toolicon/32x32/rotation.png:/toolicon/32x32/rotation.png @@ -1156,6 +1156,58 @@ + + + + false + + + Flipping objects by line + + + ... + + + + :/toolicon/32x32/flipping_line.png:/toolicon/32x32/flipping_line.png + + + + 32 + 32 + + + + true + + + + + + + false + + + Flipping objects by axis + + + ... + + + + :/toolicon/32x32/flipping_axis.png:/toolicon/32x32/flipping_axis.png + + + + 32 + 32 + + + + true + + + @@ -1163,7 +1215,7 @@ 0 0 - 100 + 130 104 @@ -1177,7 +1229,7 @@ Tools for creating details. - + :/icon/16x16/toolsectiondetail.png:/icon/16x16/toolsectiondetail.png @@ -1199,7 +1251,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -1225,7 +1277,7 @@ ... - + :/toolicon/32x32/new_detail.png:/toolicon/32x32/new_detail.png @@ -1251,7 +1303,7 @@ ... - + :/toolicon/32x32/union.png:/toolicon/32x32/union.png @@ -1277,7 +1329,7 @@ - + :/icon/16x16/toolsectionlayout.png:/icon/16x16/toolsectionlayout.png @@ -1328,7 +1380,7 @@ ... - + :/icon/32x32/export_to_picture_document.png:/icon/32x32/export_to_picture_document.png @@ -1774,7 +1826,7 @@ false - + :/icon/32x32/draw.png:/icon/32x32/draw.png @@ -1798,7 +1850,7 @@ false - + :/icon/32x32/kontur.png:/icon/32x32/kontur.png @@ -1822,7 +1874,7 @@ true - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -1840,7 +1892,7 @@ false - + :/icon/32x32/new_draw.png:/icon/32x32/new_draw.png @@ -1861,7 +1913,7 @@ false - + :/icon/32x32/option_draw.png:/icon/32x32/option_draw.png @@ -1885,7 +1937,7 @@ false - + :/icon/32x32/table.png:/icon/32x32/table.png @@ -1909,7 +1961,7 @@ false - + :/icon/32x32/history.png:/icon/32x32/history.png @@ -1930,7 +1982,7 @@ false - + :/icon/32x32/layout.png:/icon/32x32/layout.png @@ -2195,7 +2247,7 @@ false - + :/icon/32x32/pdf.png:/icon/32x32/pdf.png @@ -2285,7 +2337,7 @@ false - + :/icon/32x32/export_to_picture_document.png:/icon/32x32/export_to_picture_document.png @@ -2362,7 +2414,7 @@ false - + :/icon/32x32/syncM.png:/icon/32x32/syncM.png @@ -2401,9 +2453,6 @@
vmaingraphicsview.h
- - - - + diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index 95f4ef5ae..0e75306b5 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -70,5 +70,9 @@ cursor/rotation_cursor@2x.png cursor/midpoint_cursor.png cursor/midpoint_cursor@2x.png + cursor/flipping_line_cursor@2x.png + cursor/flipping_line_cursor.png + cursor/flipping_axis_cursor.png + cursor/flipping_axis_cursor@2x.png diff --git a/src/app/valentina/share/resources/cursor/flipping_axis_cursor.png b/src/app/valentina/share/resources/cursor/flipping_axis_cursor.png new file mode 100644 index 000000000..fb31228bf Binary files /dev/null and b/src/app/valentina/share/resources/cursor/flipping_axis_cursor.png differ diff --git a/src/app/valentina/share/resources/cursor/flipping_axis_cursor@2x.png b/src/app/valentina/share/resources/cursor/flipping_axis_cursor@2x.png new file mode 100644 index 000000000..2c080a51a Binary files /dev/null and b/src/app/valentina/share/resources/cursor/flipping_axis_cursor@2x.png differ diff --git a/src/app/valentina/share/resources/cursor/flipping_line_cursor.png b/src/app/valentina/share/resources/cursor/flipping_line_cursor.png new file mode 100644 index 000000000..c1e80d2f0 Binary files /dev/null and b/src/app/valentina/share/resources/cursor/flipping_line_cursor.png differ diff --git a/src/app/valentina/share/resources/cursor/flipping_line_cursor@2x.png b/src/app/valentina/share/resources/cursor/flipping_line_cursor@2x.png new file mode 100644 index 000000000..7468a233c Binary files /dev/null and b/src/app/valentina/share/resources/cursor/flipping_line_cursor@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon.qrc b/src/app/valentina/share/resources/toolicon.qrc index 9c3014f08..a81206cb6 100644 --- a/src/app/valentina/share/resources/toolicon.qrc +++ b/src/app/valentina/share/resources/toolicon.qrc @@ -68,5 +68,9 @@ toolicon/32x32/rotation@2x.png toolicon/32x32/midpoint.png toolicon/32x32/midpoint@2x.png + toolicon/32x32/flipping_line@2x.png + toolicon/32x32/flipping_line.png + toolicon/32x32/flipping_axis.png + toolicon/32x32/flipping_axis@2x.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/flipping_axis.png b/src/app/valentina/share/resources/toolicon/32x32/flipping_axis.png new file mode 100644 index 000000000..e712f780e Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/flipping_axis.png differ diff --git a/src/app/valentina/share/resources/toolicon/32x32/flipping_axis@2x.png b/src/app/valentina/share/resources/toolicon/32x32/flipping_axis@2x.png new file mode 100644 index 000000000..939dbe116 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/flipping_axis@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon/32x32/flipping_line.png b/src/app/valentina/share/resources/toolicon/32x32/flipping_line.png new file mode 100644 index 000000000..6f1224ab9 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/flipping_line.png differ diff --git a/src/app/valentina/share/resources/toolicon/32x32/flipping_line@2x.png b/src/app/valentina/share/resources/toolicon/32x32/flipping_line@2x.png new file mode 100644 index 000000000..b14e19657 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/flipping_line@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon/svg/flipping_axis.svg b/src/app/valentina/share/resources/toolicon/svg/flipping_axis.svg new file mode 100644 index 000000000..71e9dece9 --- /dev/null +++ b/src/app/valentina/share/resources/toolicon/svg/flipping_axis.svg @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/app/valentina/share/resources/toolicon/svg/flipping_line.svg b/src/app/valentina/share/resources/toolicon/svg/flipping_line.svg new file mode 100644 index 000000000..aa4a3affc --- /dev/null +++ b/src/app/valentina/share/resources/toolicon/svg/flipping_line.svg @@ -0,0 +1,82 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 0899e0748..89af0556d 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2532,7 +2532,7 @@ void VPattern::ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElem QVector source; QVector destination; - VToolRotation::ExtractData(this, domElement, source, destination); + VAbstractOperation::ExtractData(this, domElement, source, destination); VToolRotation::Create(id, center, a, suffix, source, destination, scene, this, data, parse, Source::FromFile); //Rewrite attribute formula. Need for situation when we have wrong formula. @@ -2557,6 +2557,66 @@ void VPattern::ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElem } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParseToolFlippingByLine(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse) +{ + SCASSERT(scene != nullptr); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + + try + { + quint32 id = NULL_ID; + + ToolsCommonAttributes(domElement, id); + const quint32 p1 = GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); + const quint32 p2 = GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); + const QString suffix = GetParametrString(domElement, AttrSuffix, ""); + + QVector source; + QVector destination; + VAbstractOperation::ExtractData(this, domElement, source, destination); + + VToolFlippingByLine::Create(id, p1, p2, suffix, source, destination, scene, this, data, parse, + Source::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating operation of flipping by line"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParseToolFlippingByAxis(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse) +{ + SCASSERT(scene != nullptr); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + + try + { + quint32 id = NULL_ID; + + ToolsCommonAttributes(domElement, id); + const quint32 origin = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + const auto axisType = static_cast(GetParametrUInt(domElement, AttrAxisType, "1")); + const QString suffix = GetParametrString(domElement, AttrSuffix, ""); + + QVector source; + QVector destination; + VAbstractOperation::ExtractData(this, domElement, source, destination); + + VToolFlippingByAxis::Create(id, origin, axisType, suffix, source, destination, scene, this, data, parse, + Source::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating operation of flipping by axis"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } +} + //--------------------------------------------------------------------------------------------------------------------- qreal VPattern::EvalFormula(VContainer *data, const QString &formula, bool *ok) const { @@ -2807,13 +2867,21 @@ void VPattern::ParseOperationElement(VMainGraphicsScene *scene, QDomElement &dom Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(not type.isEmpty(), Q_FUNC_INFO, "type of operation is empty"); - const QStringList opers = QStringList() << VToolRotation::ToolType; /*0*/ + const QStringList opers = QStringList() << VToolRotation::ToolType /*0*/ + << VToolFlippingByLine::ToolType /*1*/ + << VToolFlippingByAxis::ToolType; /*2*/ switch (opers.indexOf(type)) { case 0: //VToolRotation::ToolType ParseToolRotation(scene, domElement, parse); break; + case 1: //VToolFlippingByLine::ToolType + ParseToolFlippingByLine(scene, domElement, parse); + break; + case 2: //VToolFlippingByAxis::ToolType + ParseToolFlippingByAxis(scene, domElement, parse); + break; default: VException e(tr("Unknown operation type '%1'.").arg(type)); throw e; @@ -3319,7 +3387,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") 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) == 45, "Not all tools was used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47, "Not all tools was used."); QRectF rec; @@ -3431,6 +3499,12 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::Rotation: rec = ToolBoundingRect(rec, tool.getId()); break; + case Tool::FlippingByLine: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::FlippingByAxis: + rec = ToolBoundingRect(rec, tool.getId()); + break; //These tools are not accesseble in Draw mode, but still 'history' contains them. case Tool::Detail: case Tool::UnionDetails: diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 9ccf41aa6..a67d9c76e 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -194,6 +194,8 @@ private: void ParseToolArcWithLength(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); + void ParseToolFlippingByLine(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); + void ParseToolFlippingByAxis(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); qreal EvalFormula(VContainer *data, const QString &formula, bool *ok) const; diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index 59ef40b5d..5a47465c1 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -124,6 +124,7 @@ const QString AttrSecondArc = QStringLiteral("secondArc"); const QString AttrCrossPoint = QStringLiteral("crossPoint"); const QString AttrVCrossPoint = QStringLiteral("vCrossPoint"); const QString AttrHCrossPoint = QStringLiteral("hCrossPoint"); +const QString AttrAxisType = QStringLiteral("axisType"); const QString AttrC1Center = QStringLiteral("c1Center"); const QString AttrC2Center = QStringLiteral("c2Center"); const QString AttrC1Radius = QStringLiteral("c1Radius"); diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 750372b2e..900c31aa6 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -125,6 +125,7 @@ extern const QString AttrSecondArc; extern const QString AttrCrossPoint; extern const QString AttrVCrossPoint; extern const QString AttrHCrossPoint; +extern const QString AttrAxisType; extern const QString AttrC1Center; extern const QString AttrC2Center; extern const QString AttrC1Radius; diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 6661ca5b6..c5e1855d9 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -18,6 +18,7 @@ schema/pattern/v0.3.2.xsd schema/pattern/v0.3.3.xsd schema/pattern/v0.3.4.xsd + schema/pattern/v0.3.5.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd @@ -28,5 +29,6 @@ schema/individual_measurements/v0.3.2.xsd schema/individual_measurements/v0.3.3.xsd schema/pattern/v0.3.5.xsd + schema/pattern/v0.3.6.xsd diff --git a/src/libs/ifc/schema/pattern/v0.3.5.xsd b/src/libs/ifc/schema/pattern/v0.3.5.xsd index d872d7977..cf8050fa6 100644 --- a/src/libs/ifc/schema/pattern/v0.3.5.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.5.xsd @@ -209,6 +209,9 @@ + + + @@ -362,7 +365,7 @@ - + @@ -373,15 +376,6 @@ - - - - - - - - - @@ -563,6 +557,12 @@ + + + + + + @@ -578,4 +578,4 @@ - + \ No newline at end of file diff --git a/src/libs/ifc/schema/pattern/v0.3.6.xsd b/src/libs/ifc/schema/pattern/v0.3.6.xsd new file mode 100644 index 000000000..5ee6be0e2 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.3.6.xsd @@ -0,0 +1,590 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 661387eb8..78c45caed 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1373,7 +1373,7 @@ QStringList VAbstractPattern::ListPointExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47); QStringList expressions; const QDomNodeList list = elementsByTagName(TagPoint); @@ -1444,7 +1444,7 @@ QStringList VAbstractPattern::ListArcExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47); QStringList expressions; const QDomNodeList list = elementsByTagName(TagArc); @@ -1505,7 +1505,7 @@ QStringList VAbstractPattern::ListPathPointExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47); QStringList expressions; const QDomNodeList list = elementsByTagName(AttrPathPoint); @@ -1571,7 +1571,7 @@ QStringList VAbstractPattern::ListOperationExpressions() const { // Check if new tool doesn't bring new attribute with a formula. // If no just increment number - Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 47); QStringList expressions; const QDomNodeList list = elementsByTagName(TagOperation); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 116a31769..556d4f07a 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -53,6 +53,7 @@ enum class LabelType : char {NewPatternPiece, NewLabel}; enum class CrossCirclesPoint : char {FirstPoint = 1, SecondPoint = 2}; enum class VCrossCurvesPoint : char {HighestPoint = 1, LowestPoint = 2}; enum class HCrossCurvesPoint : char {LeftmostPoint = 1, RightmostPoint = 2}; +enum class AxisType : char {VerticalAxis = 1, HorizontalAxis = 2}; class VContainer; class VDataTool; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 606555335..6f9788537 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -58,8 +58,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.3.5"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.5.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.3.6"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.6.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -169,6 +169,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000304): return QStringLiteral("://schema/pattern/v0.3.4.xsd"); case (0x000305): + return QStringLiteral("://schema/pattern/v0.3.5.xsd"); + case (0x000306): return CurrentSchema; default: InvalidVersion(ver); @@ -254,7 +256,12 @@ void VPatternConverter::ApplyPatches() case (0x000304): ToV0_3_5(); ValidateXML(XSDSchema(0x000305), fileName); + V_FALLTHROUGH case (0x000305): + ToV0_3_6(); + ValidateXML(XSDSchema(0x000306), fileName); + V_FALLTHROUGH + case (0x000306): break; default: break; @@ -422,6 +429,13 @@ void VPatternConverter::ToV0_3_5() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_3_6() +{ + SetVersion(QStringLiteral("0.3.6")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index cca5e3c2f..87cd058d2 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -55,10 +55,10 @@ public: // GCC 4.6 doesn't allow constexpr and const together #if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) <= 406 static Q_DECL_CONSTEXPR int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 5); + static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 6); #else static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 5); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 6); #endif protected: @@ -94,6 +94,7 @@ private: void ToV0_3_3(); void ToV0_3_4(); void ToV0_3_5(); + void ToV0_3_6(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index dd424fe66..8616f7079 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -131,6 +131,20 @@ VArc VArc::Rotate(const QPointF &originPoint, qreal degrees, const QString &pref return arc; } +//--------------------------------------------------------------------------------------------------------------------- +VArc VArc::Flip(const QLineF &axis, const QString &prefix) const +{ + const VPointF center = GetCenter().Flip(axis); + + const QPointF p1 = VPointF::FlipPF(axis, GetP1()); + const QPointF p2 = VPointF::FlipPF(axis, GetP2()); + + VArc arc(center, GetRadius(), QLineF(center, p1).angle(), QLineF(center, p2).angle()); + arc.setName(name() + prefix); + arc.SetFlipped(true); + return arc; +} + //--------------------------------------------------------------------------------------------------------------------- VArc::~VArc() {} diff --git a/src/libs/vgeometry/varc.h b/src/libs/vgeometry/varc.h index 67caef6e4..3a3c4d0c7 100644 --- a/src/libs/vgeometry/varc.h +++ b/src/libs/vgeometry/varc.h @@ -63,6 +63,7 @@ public: VArc(const VArc &arc); VArc& operator= (const VArc &arc); VArc Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VArc Flip(const QLineF &axis, const QString &prefix = QString()) const; virtual ~VArc() Q_DECL_OVERRIDE; QString GetFormulaRadius () const; diff --git a/src/libs/vgeometry/vcubicbezier.cpp b/src/libs/vgeometry/vcubicbezier.cpp index cfa3b071d..3b3d88786 100644 --- a/src/libs/vgeometry/vcubicbezier.cpp +++ b/src/libs/vgeometry/vcubicbezier.cpp @@ -78,6 +78,18 @@ VCubicBezier VCubicBezier::Rotate(const QPointF &originPoint, qreal degrees, con return curve; } +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezier VCubicBezier::Flip(const QLineF &axis, const QString &prefix) const +{ + const VPointF p1 = GetP1().Flip(axis); + const VPointF p2 = GetP2().Flip(axis); + const VPointF p3 = GetP3().Flip(axis); + const VPointF p4 = GetP4().Flip(axis); + VCubicBezier curve(p1, p2, p3, p4); + curve.setName(name() + prefix); + return curve; +} + //--------------------------------------------------------------------------------------------------------------------- VCubicBezier::~VCubicBezier() { diff --git a/src/libs/vgeometry/vcubicbezier.h b/src/libs/vgeometry/vcubicbezier.h index 8b6c1f338..283141884 100644 --- a/src/libs/vgeometry/vcubicbezier.h +++ b/src/libs/vgeometry/vcubicbezier.h @@ -53,6 +53,7 @@ public: Draw mode = Draw::Calculation); VCubicBezier &operator=(const VCubicBezier &curve); VCubicBezier Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VCubicBezier Flip(const QLineF &axis, const QString &prefix = QString()) const; virtual ~VCubicBezier(); virtual VPointF GetP1() const Q_DECL_OVERRIDE; diff --git a/src/libs/vgeometry/vcubicbezierpath.cpp b/src/libs/vgeometry/vcubicbezierpath.cpp index 496354a8a..1cc4c9c1b 100644 --- a/src/libs/vgeometry/vcubicbezierpath.cpp +++ b/src/libs/vgeometry/vcubicbezierpath.cpp @@ -91,6 +91,19 @@ VCubicBezierPath VCubicBezierPath::Rotate(const QPointF &originPoint, qreal degr return curve; } +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath VCubicBezierPath::Flip(const QLineF &axis, const QString &prefix) const +{ + const QVector points = GetCubicPath(); + VCubicBezierPath curve; + for(int i=0; i < points.size(); ++i) + { + curve.append(points.at(i).Flip(axis)); + } + curve.setName(name() + prefix); + return curve; +} + //--------------------------------------------------------------------------------------------------------------------- VCubicBezierPath::~VCubicBezierPath() { diff --git a/src/libs/vgeometry/vcubicbezierpath.h b/src/libs/vgeometry/vcubicbezierpath.h index b232a7567..c0c38cd8e 100644 --- a/src/libs/vgeometry/vcubicbezierpath.h +++ b/src/libs/vgeometry/vcubicbezierpath.h @@ -56,6 +56,7 @@ public: VCubicBezierPath(const QVector &points, quint32 idObject = 0, Draw mode = Draw::Calculation); VCubicBezierPath &operator=(const VCubicBezierPath &curve); VCubicBezierPath Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VCubicBezierPath Flip(const QLineF &axis, const QString &prefix = QString()) const; virtual ~VCubicBezierPath(); VPointF &operator[](int indx); diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index f501a3392..81798cc81 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -134,6 +134,20 @@ VEllipticalArc VEllipticalArc::Rotate(const QPointF &originPoint, qreal degrees, return elArc; } +//--------------------------------------------------------------------------------------------------------------------- +VEllipticalArc VEllipticalArc::Flip(const QLineF &axis, const QString &prefix) const +{ + const VPointF center = GetCenter().Flip(axis); + const QPointF p1 = VPointF::FlipPF(axis, GetP1()); + const QPointF p2 = VPointF::FlipPF(axis, GetP2()); + const qreal f1 = QLineF(center, p1).angle() - GetRotationAngle(); + const qreal f2 = QLineF(center, p2).angle() - GetRotationAngle(); + VEllipticalArc elArc(center, GetRadius1(), GetRadius2(), f1, f2, GetRotationAngle()); + elArc.setName(name() + prefix); + elArc.SetFlipped(true); + return elArc; +} + //--------------------------------------------------------------------------------------------------------------------- VEllipticalArc::~VEllipticalArc() {} diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h index 79393a70f..b77372efd 100644 --- a/src/libs/vgeometry/vellipticalarc.h +++ b/src/libs/vgeometry/vellipticalarc.h @@ -63,6 +63,7 @@ public: VEllipticalArc& operator= (const VEllipticalArc &arc); VEllipticalArc Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VEllipticalArc Flip(const QLineF &axis, const QString &prefix = QString()) const; virtual ~VEllipticalArc() Q_DECL_OVERRIDE; @@ -99,6 +100,7 @@ private: static int GetQuadransRad(qreal &rad); }; +Q_DECLARE_METATYPE(VEllipticalArc) Q_DECLARE_TYPEINFO(VEllipticalArc, Q_MOVABLE_TYPE); #endif // VELLIPTICALARC_H diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index e9e91f1cd..713239bf7 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "../vmisc/def.h" #include "../vmisc/vmath.h" @@ -575,3 +576,39 @@ int VGObject::GetLengthContour(const QVector &contour, const QVector &contour, const QVector &newPoints); static double accuracyPointOnLine; +protected: + static QTransform FlippingMatrix(const QLineF &axis); private: QSharedDataPointer d; diff --git a/src/libs/vgeometry/vpointf.cpp b/src/libs/vgeometry/vpointf.cpp index 67de60447..fcb3f529d 100644 --- a/src/libs/vgeometry/vpointf.cpp +++ b/src/libs/vgeometry/vpointf.cpp @@ -31,6 +31,7 @@ #include #include #include +#include //--------------------------------------------------------------------------------------------------------------------- /** @@ -113,6 +114,13 @@ VPointF VPointF::Rotate(const QPointF &originPoint, qreal degrees, const QString return VPointF(p, name() + prefix, mx(), my()); } +//--------------------------------------------------------------------------------------------------------------------- +VPointF VPointF::Flip(const QLineF &axis, const QString &prefix) const +{ + const QPointF p = FlipPF(axis, toQPointF()); + return VPointF(p, name() + prefix, mx(), my()); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief mx return offset name respect to x @@ -206,3 +214,10 @@ QPointF VPointF::RotatePF(const QPointF &originPoint, const QPointF &point, qrea axis.setAngle(axis.angle() + degrees); return axis.p2(); } + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VPointF::FlipPF(const QLineF &axis, const QPointF &point) +{ + const QTransform matrix = FlippingMatrix(axis); + return matrix.map(point); +} diff --git a/src/libs/vgeometry/vpointf.h b/src/libs/vgeometry/vpointf.h index 1b4777a7f..3eb4a25ee 100644 --- a/src/libs/vgeometry/vpointf.h +++ b/src/libs/vgeometry/vpointf.h @@ -65,6 +65,7 @@ public: VPointF &operator=(const VPointF &point); operator QPointF() const; VPointF Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VPointF Flip(const QLineF &axis, const QString &prefix = QString()) const; qreal mx() const; qreal my() const; void setMx(qreal mx); @@ -76,6 +77,7 @@ public: void setY(const qreal &value); static QPointF RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees); + static QPointF FlipPF(const QLineF &axis, const QPointF &point); private: QSharedDataPointer d; }; diff --git a/src/libs/vgeometry/vspline.cpp b/src/libs/vgeometry/vspline.cpp index 2234caea0..b9fceff03 100644 --- a/src/libs/vgeometry/vspline.cpp +++ b/src/libs/vgeometry/vspline.cpp @@ -126,6 +126,20 @@ VSpline VSpline::Rotate(const QPointF &originPoint, qreal degrees, const QString return spl; } +//--------------------------------------------------------------------------------------------------------------------- +VSpline VSpline::Flip(const QLineF &axis, const QString &prefix) const +{ + const VPointF p1 = GetP1().Flip(axis); + const VPointF p4 = GetP4().Flip(axis); + + const QPointF p2 = VPointF::FlipPF(axis, GetP2()); + const QPointF p3 = VPointF::FlipPF(axis, GetP3()); + + VSpline spl(p1, p2, p3, p4); + spl.setName(name() + prefix); + return spl; +} + //--------------------------------------------------------------------------------------------------------------------- VSpline::~VSpline() {} diff --git a/src/libs/vgeometry/vspline.h b/src/libs/vgeometry/vspline.h index e648a3c80..78705e496 100644 --- a/src/libs/vgeometry/vspline.h +++ b/src/libs/vgeometry/vspline.h @@ -63,6 +63,7 @@ public: const QString &angle2Formula, qreal c1Length, const QString &c1LengthFormula, qreal c2Length, const QString &c2LengthFormula, quint32 idObject = 0, Draw mode = Draw::Calculation); VSpline Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VSpline Flip(const QLineF &axis, const QString &prefix = QString()) const; virtual ~VSpline(); VSpline &operator=(const VSpline &spl); diff --git a/src/libs/vgeometry/vsplinepath.cpp b/src/libs/vgeometry/vsplinepath.cpp index 8410c8364..bbf0be400 100644 --- a/src/libs/vgeometry/vsplinepath.cpp +++ b/src/libs/vgeometry/vsplinepath.cpp @@ -122,6 +122,28 @@ VSplinePath VSplinePath::Rotate(const QPointF &originPoint, qreal degrees, const return splPath; } +//--------------------------------------------------------------------------------------------------------------------- +VSplinePath VSplinePath::Flip(const QLineF &axis, const QString &prefix) const +{ + QVector newPoints(CountPoints()); + for (qint32 i = 1; i <= CountSubSpl(); ++i) + { + const VSpline spl = GetSpline(i).Flip(axis); + + newPoints[i-1].SetP(spl.GetP1()); + newPoints[i-1].SetAngle2(spl.GetStartAngle(), spl.GetStartAngleFormula()); + newPoints[i-1].SetLength2(spl.GetC1Length(), spl.GetC1LengthFormula()); + + newPoints[i].SetP(spl.GetP4()); + newPoints[i].SetAngle1(spl.GetEndAngle(), spl.GetEndAngleFormula()); + newPoints[i].SetLength1(spl.GetC2Length(), spl.GetC2LengthFormula()); + } + + VSplinePath splPath(newPoints); + splPath.setName(name() + prefix); + return splPath; +} + //--------------------------------------------------------------------------------------------------------------------- VSplinePath::~VSplinePath() {} diff --git a/src/libs/vgeometry/vsplinepath.h b/src/libs/vgeometry/vsplinepath.h index e0dea14d9..424e1de44 100644 --- a/src/libs/vgeometry/vsplinepath.h +++ b/src/libs/vgeometry/vsplinepath.h @@ -61,6 +61,7 @@ public: VSplinePath(const QVector &points, quint32 idObject = 0, Draw mode = Draw::Calculation); VSplinePath(const VSplinePath& splPath); VSplinePath Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; + VSplinePath Flip(const QLineF &axis, const QString &prefix = QString()) const; virtual ~VSplinePath() Q_DECL_OVERRIDE; VSplinePath &operator=(const VSplinePath &path); diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index ad437abd6..31b04099f 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -109,6 +109,8 @@ enum class Tool : ToolVisHolderType UnionDetails, Group, Rotation, + FlippingByLine, + FlippingByAxis, Midpoint, LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; @@ -121,6 +123,7 @@ enum class Vis : ToolVisHolderType SimpleCurve, Line, Path, + Operation, ToolAlongLine, ToolArc, ToolArcWithLength, @@ -149,7 +152,9 @@ enum class Vis : ToolVisHolderType ToolLineIntersectAxis, ToolCurveIntersectAxis, ToolTrueDarts, - ToolRotation + ToolRotation, + ToolFlippingByLine, + ToolFlippingByAxis }; enum class VarType : char { Measurement, Increment, LineLength, CurveLength, LineAngle, CurveAngle, ArcRadius, diff --git a/src/libs/vmisc/vabstractapplication.cpp b/src/libs/vmisc/vabstractapplication.cpp index b3ef4034c..7338fd4eb 100644 --- a/src/libs/vmisc/vabstractapplication.cpp +++ b/src/libs/vmisc/vabstractapplication.cpp @@ -62,22 +62,45 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv) doc(nullptr), openingPattern(false) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + QString rules; +#endif // QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + #if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) // Qt < 5.2 didn't feature categorized logging // Do nothing #else + // In Qt 5.2 need manualy enable debug information for categories. This work // because Qt doesn't provide debug information for categories itself. And in this // case will show our messages. Another situation with Qt 5.3 that has many debug // messages itself. We don't need this information and can turn on later if need. // But here Qt already show our debug messages without enabling. - QLoggingCategory::setFilterRules("*.debug=true\n"); + rules += QLatin1String("*.debug=true\n"); #endif // QT_VERSION < QT_VERSION_CHECK(5, 2, 0) #endif // QT_VERSION < QT_VERSION_CHECK(5, 3, 0) +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 1) +#if defined(V_NO_ASSERT) + // Ignore SSL-related warnings + // See issue #528: Error: QSslSocket: cannot resolve SSLv2_client_method. + rules += QLatin1String("qt.network.ssl.warning=false\n"); + // See issue #568: Certificate checking on Mac OS X. + rules += QLatin1String("qt.network.ssl.critical=false\n" + "qt.network.ssl.fatal=false\n"); +#endif //defined(V_NO_ASSERT) +#endif // QT_VERSION >= QT_VERSION_CHECK(5, 4, 1) + +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + if (not rules.isEmpty()) + { + QLoggingCategory::setFilterRules(rules); + } +#endif // QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) // Enable support for HiDPI bitmap resources setAttribute(Qt::AA_UseHighDpiPixmaps); @@ -90,14 +113,6 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv) // Connect this slot with VApplication::aboutToQuit. Settings()->sync(); }); - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 1) -#if defined(V_NO_ASSERT) - // Ignore SSL-related warnings - // See issue #528: Error: QSslSocket: cannot resolve SSLv2_client_method. - qputenv("QT_LOGGING_RULES", "qt.network.ssl.warning=false"); -#endif //defined(V_NO_ASSERT) -#endif // QT_VERSION >= QT_VERSION_CHECK(5, 4, 1) } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index 5c1cc848e..167b8580d 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -38,7 +38,9 @@ HEADERS += \ $$PWD/tools/dialogcubicbezier.h \ $$PWD/tools/dialogcubicbezierpath.h \ $$PWD/tools/dialoggroup.h \ - $$PWD/tools/dialogrotation.h + $$PWD/tools/dialogrotation.h \ + $$PWD/tools/dialogflippingbyline.h \ + $$PWD/tools/dialogflippingbyaxis.h SOURCES += \ @@ -77,7 +79,9 @@ SOURCES += \ $$PWD/tools/dialogcubicbezier.cpp \ $$PWD/tools/dialogcubicbezierpath.cpp \ $$PWD/tools/dialoggroup.cpp \ - $$PWD/tools/dialogrotation.cpp + $$PWD/tools/dialogrotation.cpp \ + $$PWD/tools/dialogflippingbyline.cpp \ + $$PWD/tools/dialogflippingbyaxis.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -114,4 +118,6 @@ FORMS += \ $$PWD/tools/dialogcubicbezier.ui \ $$PWD/tools/dialogcubicbezierpath.ui \ $$PWD/tools/dialoggroup.ui \ - $$PWD/tools/dialogrotation.ui + $$PWD/tools/dialogrotation.ui \ + $$PWD/tools/dialogflippingbyline.ui \ + $$PWD/tools/dialogflippingbyaxis.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index d82ef4fb2..7a884ce90 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -62,6 +62,8 @@ #include "tools/dialogtruedarts.h" #include "tools/dialoggroup.h" #include "tools/dialogrotation.h" +#include "tools/dialogflippingbyline.h" +#include "tools/dialogflippingbyaxis.h" #include "support/dialogeditwrongformula.h" #include "support/dialogundo.h" diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp new file mode 100644 index 000000000..f5d60d6da --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp @@ -0,0 +1,326 @@ +/************************************************************************ + ** + ** @file dialogflippingbyaxis.cpp + ** @author Roman Telezhynskyi + ** @date 16 9, 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 "dialogflippingbyaxis.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../visualization/visualization.h" +#include "../../visualization/line/operation/vistoolflippingbyaxis.h" +#include "../ifc/xml/vabstractpattern.h" +#include "../ifc/xml/vdomdocument.h" +#include "../qmuparser/qmudef.h" +#include "../vgeometry/vpointf.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vcommonsettings.h" +#include "../vpatterndb/vcontainer.h" +#include "../vwidgets/vabstractmainwindow.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "ui_dialogflippingbyaxis.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogFlippingByAxis::DialogFlippingByAxis(const VContainer *data, const quint32 &toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogFlippingByAxis), + objects(), + stage1(true), + m_suffix() +{ + ui->setupUi(this); + + ui->lineEditSuffix->setText(qApp->getCurrentDocument()->GenerateSuffix()); + + InitOkCancelApply(ui); + + FillComboBoxPoints(ui->comboBoxOriginPoint); + FillComboBoxAxisType(ui->comboBoxAxisType); + + flagName = true; + CheckState(); + + connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogFlippingByAxis::SuffixChanged); + connect(ui->comboBoxOriginPoint, static_cast(&QComboBox::currentIndexChanged), + this, &DialogFlippingByAxis::PointChanged); + + vis = new VisToolFlippingByAxis(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogFlippingByAxis::~DialogFlippingByAxis() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogFlippingByAxis::GetOriginPointId() const +{ + return getCurrentObjectId(ui->comboBoxOriginPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SetOriginPointId(quint32 value) +{ + ChangeCurrentData(ui->comboBoxOriginPoint, value); + VisToolFlippingByAxis *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetOriginPointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +AxisType DialogFlippingByAxis::GetAxisType() const +{ + return getCurrentCrossPoint(ui->comboBoxAxisType); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SetAxisType(AxisType type) +{ + auto index = ui->comboBoxAxisType->findData(static_cast(type)); + if (index != -1) + { + ui->comboBoxAxisType->setCurrentIndex(index); + + auto operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetAxisType(type); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogFlippingByAxis::GetSuffix() const +{ + return m_suffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SetSuffix(const QString &value) +{ + m_suffix = value; + ui->lineEditSuffix->setText(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogFlippingByAxis::GetObjects() const +{ + return objects.toVector(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::ShowDialog(bool click) +{ + if (stage1 && not click) + { + if (objects.isEmpty()) + { + return; + } + + stage1 = false; + + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + scene->clearSelection(); + + VisToolFlippingByAxis *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetObjects(objects.toVector()); + operation->VisualMode(); + + scene->ToggleArcSelection(false); + scene->ToggleSplineSelection(false); + scene->ToggleSplinePathSelection(false); + + scene->ToggleArcHover(false); + scene->ToggleSplineHover(false); + scene->ToggleSplinePathHover(false); + + emit ToolTip(tr("Select origin point")); + } + else if (not stage1 && prepare && click) + { + setModal(true); + emit ToolTip(""); + show(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::ChosenObject(quint32 id, const SceneObject &type) +{ + if (not stage1 && not prepare)// After first choose we ignore all objects + { + if (type == SceneObject::Point) + { + if (objects.contains(id)) + { + emit ToolTip(tr("Select origin point that is not part of the list of objects")); + return; + } + + if (SetObject(id, ui->comboBoxOriginPoint, "")) + { + VisToolFlippingByAxis *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetOriginPointId(id); + operation->RefreshGeometry(); + + prepare = true; + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SelectedObject(bool selected, quint32 object, quint32 tool) +{ + Q_UNUSED(tool) + if (stage1) + { + if (selected) + { + if (not objects.contains(object)) + { + objects.append(object); + } + } + else + { + objects.removeOne(object); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SuffixChanged() +{ + QLineEdit* edit = qobject_cast(sender()); + if (edit) + { + const QString suffix = edit->text(); + if (suffix.isEmpty()) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + CheckState(); + return; + } + else + { + if (m_suffix != suffix) + { + QRegularExpression rx(NameRegExp()); + const QStringList uniqueNames = data->AllUniqueNames(); + for (int i=0; i < uniqueNames.size(); ++i) + { + const QString name = uniqueNames.at(i) + suffix; + if (not rx.match(name).hasMatch() || not data->IsUnique(name)) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + CheckState(); + return; + } + } + } + } + + flagName = true; + ChangeColor(ui->labelSuffix, okColor); + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(flagError && flagName); + SCASSERT(bApply != nullptr); + bApply->setEnabled(bOk->isEnabled()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SaveData() +{ + m_suffix = ui->lineEditSuffix->text(); + + VisToolFlippingByAxis *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + operation->SetObjects(objects.toVector()); + operation->SetOriginPointId(GetOriginPointId()); + operation->SetAxisType(GetAxisType()); + operation->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::PointChanged() +{ + QColor color = okColor; + if (objects.contains(getCurrentObjectId(ui->comboBoxOriginPoint))) + { + flagError = false; + color = errorColor; + } + else + { + flagError = true; + color = okColor; + } + ChangeColor(ui->labelOriginPoint, color); + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::FillComboBoxAxisType(QComboBox *box) +{ + SCASSERT(box != nullptr); + + box->addItem(tr("Vertical axis"), QVariant(static_cast(AxisType::VerticalAxis))); + box->addItem(tr("Horizontal axis"), QVariant(static_cast(AxisType::HorizontalAxis))); +} diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.h b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.h new file mode 100644 index 000000000..ac456dcc9 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.h @@ -0,0 +1,104 @@ +/************************************************************************ + ** + ** @file dialogflippingbyaxis.h + ** @author Roman Telezhynskyi + ** @date 16 9, 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 DIALOGFLIPPINGBYAXIS_H +#define DIALOGFLIPPINGBYAXIS_H + +#include "dialogtool.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "../vmisc/def.h" + +class QWidget; +class VContainer; + +namespace Ui +{ + class DialogFlippingByAxis; +} + +class DialogFlippingByAxis : public DialogTool +{ + Q_OBJECT + +public: + explicit DialogFlippingByAxis(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + virtual ~DialogFlippingByAxis(); + + quint32 GetOriginPointId() const; + void SetOriginPointId(quint32 value); + + AxisType GetAxisType() const; + void SetAxisType(AxisType type); + + QString GetSuffix() const; + void SetSuffix(const QString &value); + + QVector GetObjects() const; + + virtual void ShowDialog(bool click) Q_DECL_OVERRIDE; + +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; + virtual void SelectedObject(bool selected, quint32 object, quint32 tool) Q_DECL_OVERRIDE; + +private slots: + void SuffixChanged(); + +protected: + virtual void CheckState() Q_DECL_OVERRIDE; + virtual void ShowVisualization() Q_DECL_OVERRIDE; + + /** @brief SaveData Put dialog data in local variables */ + virtual void SaveData() Q_DECL_OVERRIDE; + +private slots: + void PointChanged(); + +private: + Q_DISABLE_COPY(DialogFlippingByAxis) + + Ui::DialogFlippingByAxis *ui; + + QList objects; + + bool stage1; + + QString m_suffix; + + static void FillComboBoxAxisType(QComboBox *box); +}; + +#endif // DIALOGFLIPPINGBYAXIS_H diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.ui b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.ui new file mode 100644 index 000000000..d80fc67e4 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.ui @@ -0,0 +1,98 @@ + + + DialogFlippingByAxis + + + + 0 + 0 + 285 + 146 + + + + Dialog + + + + + + + + Origin point: + + + + + + + + + + Suffix: + + + + + + + + + + Axis type: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogFlippingByAxis + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogFlippingByAxis + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp b/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp new file mode 100644 index 000000000..0fc11f2cb --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp @@ -0,0 +1,359 @@ +/************************************************************************ + ** + ** @file dialogflippingbyline.cpp + ** @author Roman Telezhynskyi + ** @date 12 9, 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 "dialogflippingbyline.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../visualization/visualization.h" +#include "../../visualization/line/operation/vistoolflippingbyline.h" +#include "../ifc/xml/vabstractpattern.h" +#include "../ifc/xml/vdomdocument.h" +#include "../qmuparser/qmudef.h" +#include "../vgeometry/vpointf.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vcommonsettings.h" +#include "../vpatterndb/vcontainer.h" +#include "../vwidgets/vabstractmainwindow.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "ui_dialogflippingbyline.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogFlippingByLine::DialogFlippingByLine(const VContainer *data, const quint32 &toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogFlippingByLine), + objects(), + stage1(true), + m_suffix() +{ + ui->setupUi(this); + + ui->lineEditSuffix->setText(qApp->getCurrentDocument()->GenerateSuffix()); + + InitOkCancelApply(ui); + + FillComboBoxPoints(ui->comboBoxFirstLinePoint); + FillComboBoxPoints(ui->comboBoxSecondLinePoint); + + flagName = true; + CheckState(); + + connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogFlippingByLine::SuffixChanged); + connect(ui->comboBoxFirstLinePoint, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogFlippingByLine::PointChanged); + connect(ui->comboBoxSecondLinePoint, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogFlippingByLine::PointChanged); + + vis = new VisToolFlippingByLine(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogFlippingByLine::~DialogFlippingByLine() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogFlippingByLine::GetFirstLinePointId() const +{ + return getCurrentObjectId(ui->comboBoxFirstLinePoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SetFirstLinePointId(quint32 value) +{ + ChangeCurrentData(ui->comboBoxFirstLinePoint, value); + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetFirstLinePointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogFlippingByLine::GetSecondLinePointId() const +{ + return getCurrentObjectId(ui->comboBoxSecondLinePoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SetSecondLinePointId(quint32 value) +{ + ChangeCurrentData(ui->comboBoxSecondLinePoint, value); + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetSecondLinePointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogFlippingByLine::GetSuffix() const +{ + return m_suffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SetSuffix(const QString &value) +{ + m_suffix = value; + ui->lineEditSuffix->setText(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogFlippingByLine::GetObjects() const +{ + return objects.toVector(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::ShowDialog(bool click) +{ + if (stage1 && not click) + { + if (objects.isEmpty()) + { + return; + } + + stage1 = false; + + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + scene->clearSelection(); + + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetObjects(objects.toVector()); + operation->VisualMode(); + + scene->ToggleArcSelection(false); + scene->ToggleSplineSelection(false); + scene->ToggleSplinePathSelection(false); + + scene->ToggleArcHover(false); + scene->ToggleSplineHover(false); + scene->ToggleSplinePathHover(false); + + emit ToolTip(tr("Select first line point")); + } + else if (not stage1 && prepare && click) + { + setModal(true); + emit ToolTip(""); + show(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::ChosenObject(quint32 id, const SceneObject &type) +{ + if (not stage1 && not prepare)// After first choose we ignore all objects + { + if (type == SceneObject::Point) + { + switch (number) + { + case 0: + if (objects.contains(id)) + { + emit ToolTip(tr("Select first line point that is not part of the list of objects")); + return; + } + + if (SetObject(id, ui->comboBoxFirstLinePoint, tr("Select second line point"))) + { + number++; + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetFirstLinePointId(id); + operation->RefreshGeometry(); + } + break; + case 1: + if (objects.contains(id)) + { + emit ToolTip(tr("Select second line point that is not part of the list of objects")); + return; + } + + if (getCurrentObjectId(ui->comboBoxFirstLinePoint) != id) + { + if (SetObject(id, ui->comboBoxSecondLinePoint, "")) + { + if (flagError) + { + number = 0; + prepare = true; + + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetSecondLinePointId(id); + operation->RefreshGeometry(); + } + } + } + break; + default: + break; + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SelectedObject(bool selected, quint32 object, quint32 tool) +{ + Q_UNUSED(tool) + if (stage1) + { + if (selected) + { + if (not objects.contains(object)) + { + objects.append(object); + } + } + else + { + objects.removeOne(object); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SuffixChanged() +{ + QLineEdit* edit = qobject_cast(sender()); + if (edit) + { + const QString suffix = edit->text(); + if (suffix.isEmpty()) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + CheckState(); + return; + } + else + { + if (m_suffix != suffix) + { + QRegularExpression rx(NameRegExp()); + const QStringList uniqueNames = data->AllUniqueNames(); + for (int i=0; i < uniqueNames.size(); ++i) + { + const QString name = uniqueNames.at(i) + suffix; + if (not rx.match(name).hasMatch() || not data->IsUnique(name)) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + CheckState(); + return; + } + } + } + } + + flagName = true; + ChangeColor(ui->labelSuffix, okColor); + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(flagError && flagName); + SCASSERT(bApply != nullptr); + bApply->setEnabled(bOk->isEnabled()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SaveData() +{ + m_suffix = ui->lineEditSuffix->text(); + + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + operation->SetObjects(objects.toVector()); + operation->SetFirstLinePointId(GetFirstLinePointId()); + operation->SetSecondLinePointId(GetSecondLinePointId()); + operation->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::PointChanged() +{ + QColor color = okColor; + flagError = true; + ChangeColor(ui->labelFirstLinePoint, color); + ChangeColor(ui->labelSecondLinePoint, color); + + if (getCurrentObjectId(ui->comboBoxFirstLinePoint) == getCurrentObjectId(ui->comboBoxSecondLinePoint)) + { + flagError = false; + color = errorColor; + ChangeColor(ui->labelFirstLinePoint, color); + ChangeColor(ui->labelSecondLinePoint, color); + } + else if (objects.contains(getCurrentObjectId(ui->comboBoxFirstLinePoint))) + { + flagError = false; + color = errorColor; + ChangeColor(ui->labelFirstLinePoint, color); + } + else if (objects.contains(getCurrentObjectId(ui->comboBoxSecondLinePoint))) + { + flagError = false; + color = errorColor; + ChangeColor(ui->labelSecondLinePoint, color); + } + + CheckState(); +} diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.h b/src/libs/vtools/dialogs/tools/dialogflippingbyline.h new file mode 100644 index 000000000..300cbb0a3 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.h @@ -0,0 +1,102 @@ +/************************************************************************ + ** + ** @file dialogflippingbyline.h + ** @author Roman Telezhynskyi + ** @date 12 9, 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 DIALOGFLIPPINGBYLINE_H +#define DIALOGFLIPPINGBYLINE_H + +#include "dialogtool.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "../vmisc/def.h" + +class QWidget; +class VContainer; + +namespace Ui +{ + class DialogFlippingByLine; +} + +class DialogFlippingByLine : public DialogTool +{ + Q_OBJECT + +public: + explicit DialogFlippingByLine(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + virtual ~DialogFlippingByLine(); + + quint32 GetFirstLinePointId() const; + void SetFirstLinePointId(quint32 value); + + quint32 GetSecondLinePointId() const; + void SetSecondLinePointId(quint32 value); + + QString GetSuffix() const; + void SetSuffix(const QString &value); + + QVector GetObjects() const; + + virtual void ShowDialog(bool click) Q_DECL_OVERRIDE; + +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; + virtual void SelectedObject(bool selected, quint32 object, quint32 tool) Q_DECL_OVERRIDE; + +private slots: + void SuffixChanged(); + +protected: + virtual void CheckState() Q_DECL_OVERRIDE; + virtual void ShowVisualization() Q_DECL_OVERRIDE; + + /** @brief SaveData Put dialog data in local variables */ + virtual void SaveData() Q_DECL_OVERRIDE; + +private slots: + void PointChanged(); + +private: + Q_DISABLE_COPY(DialogFlippingByLine) + + Ui::DialogFlippingByLine *ui; + + QList objects; + + bool stage1; + + QString m_suffix; +}; + +#endif // DIALOGFLIPPINGBYLINE_H diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui b/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui new file mode 100644 index 000000000..81d43f46f --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui @@ -0,0 +1,104 @@ + + + DialogFlippingByLine + + + + 0 + 0 + 285 + 146 + + + + Dialog + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + + + First line point: + + + + + + + + + + Suffix: + + + + + + + + + + Second line point: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogFlippingByLine + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogFlippingByLine + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.cpp b/src/libs/vtools/dialogs/tools/dialogrotation.cpp index 679e0f266..c4de302fd 100644 --- a/src/libs/vtools/dialogs/tools/dialogrotation.cpp +++ b/src/libs/vtools/dialogs/tools/dialogrotation.cpp @@ -48,7 +48,7 @@ #include #include "../../visualization/visualization.h" -#include "../../visualization/line/vistoolrotation.h" +#include "../../visualization/line/operation/vistoolrotation.h" #include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vdomdocument.h" #include "../qmuparser/qmudef.h" @@ -197,7 +197,7 @@ void DialogRotation::ShowDialog(bool click) scene->ToggleSplineHover(false); scene->ToggleSplinePathHover(false); - emit ToolTip("Select origin point"); + emit ToolTip(tr("Select origin point")); } else if (not stage1 && prepare && click) { @@ -234,6 +234,7 @@ void DialogRotation::ChosenObject(quint32 id, const SceneObject &type) { if (objects.contains(id)) { + emit ToolTip(tr("Select origin point that is not part of the list of objects")); return; } diff --git a/src/libs/vtools/tools/drawTools/drawtools.h b/src/libs/vtools/tools/drawTools/drawtools.h index f52094158..6adaecdd3 100644 --- a/src/libs/vtools/tools/drawTools/drawtools.h +++ b/src/libs/vtools/tools/drawTools/drawtools.h @@ -59,5 +59,7 @@ #include "toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h" #include "toolpoint/tooldoublepoint/vtooltruedarts.h" #include "operation/vtoolrotation.h" +#include "operation/flipping/vtoolflippingbyline.h" +#include "operation/flipping/vtoolflippingbyaxis.h" #endif // DRAWTOOLS_H diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp new file mode 100644 index 000000000..8cbd99b95 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp @@ -0,0 +1,195 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 9, 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 "vabstractflipping.h" +#include "../vgeometry/vabstractcurve.h" +#include "../vgeometry/varc.h" +#include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" +#include "../vgeometry/vgobject.h" +#include "../vgeometry/vpointf.h" +#include "../vgeometry/vspline.h" +#include "../vgeometry/vsplinepath.h" + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractFlipping::~VAbstractFlipping() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractFlipping::VAbstractFlipping(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, + const QVector &source, const QVector &destination, + QGraphicsItem *parent) + : VAbstractOperation(doc, data, id, suffix, source, destination, parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractFlipping::CreateDestination(Source typeCreation, quint32 &id, QVector &dest, + const QVector &source, const QPointF &fPoint, const QPointF &sPoint, + const QString &suffix, VAbstractPattern *doc, VContainer *data, + const Document &parse) +{ + if (typeCreation == Source::FromGui) + { + dest.clear();// Try to avoid mistake, value must be empty + + id = data->getNextId();//Just reserve id for tool + + for (int i = 0; i < source.size(); ++i) + { + const quint32 idObject = source.at(i); + const QSharedPointer obj = data->GetGObject(idObject); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(static_cast(obj->getType())) + { + case GOType::Point: + dest.append(CreatePoint(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::Arc: + dest.append(CreateArc(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::EllipticalArc: + //dest.append(CreateItem(id, idObject, fPoint, sPoint, suffix)); + break; + case GOType::Spline: + dest.append(CreateCurve(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::SplinePath: + dest.append(CreateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::CubicBezier: + dest.append(CreateCurve(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::CubicBezierPath: + dest.append(CreateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::Unknown: + break; + } +QT_WARNING_POP + } + } + else + { + for (int i = 0; i < source.size(); ++i) + { + const quint32 idObject = source.at(i); + const QSharedPointer obj = data->GetGObject(idObject); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(static_cast(obj->getType())) + { + case GOType::Point: + UpdatePoint(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id, dest.at(i).mx, + dest.at(i).my); + break; + case GOType::Arc: + UpdateArc(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::EllipticalArc: + //dest.append(UpdateItem(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::Spline: + UpdateCurve(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::SplinePath: + UpdateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezier: + UpdateCurve(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezierPath: + UpdateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data, + dest.at(i).id); + break; + case GOType::Unknown: + break; + } +QT_WARNING_POP + } + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VAbstractFlipping::CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + + DestinationItem item; + item.mx = rotated.mx(); + item.my = rotated.my(); + item.id = data->AddGObject(new VPointF(rotated)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VAbstractFlipping::CreateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + data->AddArc(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractFlipping::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id, + qreal mx, qreal my) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + rotated.setMx(mx); + rotated.setMy(my); + data->UpdateGObject(id, new VPointF(rotated)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractFlipping::UpdateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + data->AddArc(data->GeometricObject(id), id); +} diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h new file mode 100644 index 000000000..0bc98b1be --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h @@ -0,0 +1,151 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 9, 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 VABSTRACTFLIPPING_H +#define VABSTRACTFLIPPING_H + +#include + +#include "../vabstractoperation.h" + +class VAbstractFlipping : public VAbstractOperation +{ + Q_OBJECT +public: + virtual ~VAbstractFlipping(); +protected: + VAbstractFlipping(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, + const QVector &source, const QVector &destination, + QGraphicsItem *parent = nullptr); + + static void CreateDestination(Source typeCreation, quint32 &id, QVector &dest, + const QVector &source, const QPointF &fPoint, const QPointF &sPoint, + const QString &suffix, VAbstractPattern *doc, VContainer *data, + const Document &parse); + + static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + + template + static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + template + static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + template + static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + + static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); + template + static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id); + static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id); + template + static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id); + template + static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, + quint32 id); +private: + Q_DISABLE_COPY(VAbstractFlipping) +}; + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VAbstractFlipping::CreateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + + DestinationItem item; + item.mx = INT_MAX; + item.my = INT_MAX; + item.id = data->AddGObject(new Item(rotated)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VAbstractFlipping::CreateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + data->AddCurve(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VAbstractFlipping::CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, + VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + data->AddCurveWithSegments(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractFlipping::UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + data->UpdateGObject(id, new Item(rotated)); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractFlipping::UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + data->AddCurve(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractFlipping::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, + quint32 id) +{ + UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + data->AddCurveWithSegments(data->GeometricObject(id), id); +} + +#endif // VABSTRACTFLIPPING_H diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp new file mode 100644 index 000000000..42d22be86 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp @@ -0,0 +1,248 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 9, 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 "vtoolflippingbyaxis.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../../../dialogs/tools/dialogtool.h" +#include "../../../../dialogs/tools/dialogflippingbyaxis.h" +#include "../../../../visualization/line/operation/vistoolflippingbyaxis.h" +#include "../../../../visualization/visualization.h" +#include "../vgeometry/vpointf.h" +#include "../vpatterndb/vtranslatevars.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vcommonsettings.h" +#include "../vmisc/diagnostic.h" +#include "../vmisc/logging.h" +#include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/vformula.h" +#include "../ifc/ifcdef.h" +#include "../ifc/exception/vexception.h" +#include "../vwidgets/vabstractsimple.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "../../../vabstracttool.h" +#include "../../../vdatatool.h" +#include "../../vdrawtool.h" + +class QDomElement; +class QGraphicsSceneContextMenuEvent; +class QPainter; +class QStyleOptionGraphicsItem; +class QWidget; +template class QSharedPointer; + +const QString VToolFlippingByAxis::ToolType = QStringLiteral("flippingByAxis"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByAxis::~VToolFlippingByAxis() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::setDialog() +{ + SCASSERT(dialog != nullptr); + DialogFlippingByAxis *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + dialogTool->SetOriginPointId(m_originPointId); + dialogTool->SetAxisType(m_axisType); + dialogTool->SetSuffix(suffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByAxis *VToolFlippingByAxis::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogFlippingByAxis *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const quint32 originPointId = dialogTool->GetOriginPointId(); + const AxisType axisType = dialogTool->GetAxisType(); + const QString suffix = dialogTool->GetSuffix(); + const QVector source = dialogTool->GetObjects(); + VToolFlippingByAxis* operation = Create(0, originPointId, axisType, suffix, source, QVector(), + scene, doc, data, Document::FullParse, Source::FromGui); + if (operation != nullptr) + { + operation->dialog = dialogTool; + } + return operation; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByAxis *VToolFlippingByAxis::Create(const quint32 _id, quint32 originPointId, AxisType axisType, + const QString &suffix, const QVector &source, + const QVector &destination, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation) +{ + const auto originPoint = *data->GeometricObject(originPointId); + const QPointF fPoint = originPoint; + + QPointF sPoint; + if (axisType == AxisType::VerticalAxis) + { + sPoint = QPointF(fPoint.x(), fPoint.y() + 100); + } + else + { + sPoint = QPointF(fPoint.x() + 100, fPoint.y()); + } + + QVector dest = destination; + + quint32 id = _id; + CreateDestination(typeCreation, id, dest, source, fPoint, sPoint, suffix, doc, data, parse); + + VDrawTool::AddRecord(id, Tool::FlippingByAxis, doc); + if (parse == Document::FullParse) + { + VToolFlippingByAxis *tool = new VToolFlippingByAxis(doc, data, id, originPointId, axisType, suffix, source, + dest, typeCreation); + scene->addItem(tool); + InitOperationToolConnections(scene, tool); + doc->AddTool(id, tool); + doc->IncrementReferens(originPoint.getIdTool()); + for (int i = 0; i < source.size(); ++i) + { + doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool()); + } + return tool; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +AxisType VToolFlippingByAxis::GetAxisType() const +{ + return m_axisType; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::SetAxisType(AxisType value) +{ + m_axisType = value; + + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::SetVisualization() +{ + if (vis != nullptr) + { + VisToolFlippingByAxis *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->SetObjects(source); + visual->SetOriginPointId(m_originPointId); + visual->SetAxisType(m_axisType); + visual->RefreshGeometry(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + DialogFlippingByAxis *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + + doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->GetOriginPointId())); + doc->SetAttribute(domElement, AttrAxisType, QString().setNum(static_cast(dialogTool->GetAxisType()))); + doc->SetAttribute(domElement, AttrSuffix, dialogTool->GetSuffix()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::ReadToolAttributes(const QDomElement &domElement) +{ + m_originPointId = doc->GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + m_axisType = static_cast(doc->GetParametrUInt(domElement, AttrAxisType, "1")); + suffix = doc->GetParametrString(domElement, AttrSuffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VDrawTool::SaveOptions(tag, obj); + + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrCenter, QString().setNum(m_originPointId)); + doc->SetAttribute(tag, AttrAxisType, QString().setNum(static_cast(m_axisType))); + doc->SetAttribute(tag, AttrSuffix, suffix); + + SaveSourceDestination(tag); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByAxis::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByAxis::VToolFlippingByAxis(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 originPointId, + AxisType axisType, const QString &suffix, + const QVector &source, const QVector &destination, + const Source &typeCreation, QGraphicsItem *parent) + : VAbstractFlipping(doc, data, id, suffix, source, destination, parent), + m_originPointId(originPointId), + m_axisType(axisType) +{ + InitOperatedObjects(); + ToolCreation(typeCreation); +} + diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.h b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.h new file mode 100644 index 000000000..5159446e1 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.h @@ -0,0 +1,77 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 9, 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 VTOOLFLIPPINGBYAXIS_H +#define VTOOLFLIPPINGBYAXIS_H + +#include + +#include "vabstractflipping.h" + +class VToolFlippingByAxis : public VAbstractFlipping +{ + Q_OBJECT +public: + virtual ~VToolFlippingByAxis(); + virtual void setDialog() Q_DECL_OVERRIDE; + static VToolFlippingByAxis* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data); + static VToolFlippingByAxis* Create(const quint32 _id, quint32 originPointId, AxisType axisType, + const QString &suffix, const QVector &source, + const QVector &destination, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation); + + static const QString ToolType; + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Tool::FlippingByAxis)}; + + AxisType GetAxisType() const; + void SetAxisType(AxisType value); + + virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; +protected: + virtual void SetVisualization() Q_DECL_OVERRIDE; + virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(VToolFlippingByAxis) + + quint32 m_originPointId; + AxisType m_axisType; + + VToolFlippingByAxis(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 originPointId, + AxisType axisType, const QString &suffix, const QVector &source, + const QVector &destination, const Source &typeCreation, + QGraphicsItem *parent = nullptr); +}; + +#endif // VTOOLFLIPPINGBYAXIS_H diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp new file mode 100644 index 000000000..3b2165e14 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp @@ -0,0 +1,227 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 "vtoolflippingbyline.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../../../dialogs/tools/dialogtool.h" +#include "../../../../dialogs/tools/dialogflippingbyline.h" +#include "../../../../visualization/line/operation/vistoolflippingbyline.h" +#include "../../../../visualization/visualization.h" +#include "../vgeometry/vpointf.h" +#include "../vpatterndb/vtranslatevars.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vcommonsettings.h" +#include "../vmisc/diagnostic.h" +#include "../vmisc/logging.h" +#include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/vformula.h" +#include "../ifc/ifcdef.h" +#include "../ifc/exception/vexception.h" +#include "../vwidgets/vabstractsimple.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "../../../vabstracttool.h" +#include "../../../vdatatool.h" +#include "../../vdrawtool.h" + +class QDomElement; +class QGraphicsSceneContextMenuEvent; +class QPainter; +class QStyleOptionGraphicsItem; +class QWidget; +template class QSharedPointer; + +const QString VToolFlippingByLine::ToolType = QStringLiteral("flippingByLine"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByLine::~VToolFlippingByLine() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::setDialog() +{ + SCASSERT(dialog != nullptr); + DialogFlippingByLine *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + dialogTool->SetFirstLinePointId(m_firstLinePointId); + dialogTool->SetSecondLinePointId(m_secondLinePointId); + dialogTool->SetSuffix(suffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByLine *VToolFlippingByLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogFlippingByLine *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const quint32 firstLinePointId = dialogTool->GetFirstLinePointId(); + const quint32 secondLinePointId = dialogTool->GetSecondLinePointId(); + const QString suffix = dialogTool->GetSuffix(); + const QVector source = dialogTool->GetObjects(); + VToolFlippingByLine* operation = Create(0, firstLinePointId, secondLinePointId, suffix, source, + QVector(), scene, doc, data, Document::FullParse, + Source::FromGui); + if (operation != nullptr) + { + operation->dialog = dialogTool; + } + return operation; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByLine *VToolFlippingByLine::Create(const quint32 _id, quint32 firstLinePointId, quint32 secondLinePointId, + const QString &suffix, const QVector &source, + const QVector &destination, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation) +{ + const auto firstPoint = *data->GeometricObject(firstLinePointId); + const QPointF fPoint = firstPoint; + + const auto secondPoint = *data->GeometricObject(secondLinePointId); + const QPointF sPoint = secondPoint; + + QVector dest = destination; + + quint32 id = _id; + CreateDestination(typeCreation, id, dest, source, fPoint, sPoint, suffix, doc, data, parse); + + VDrawTool::AddRecord(id, Tool::FlippingByLine, doc); + if (parse == Document::FullParse) + { + VToolFlippingByLine *tool = new VToolFlippingByLine(doc, data, id, firstLinePointId, secondLinePointId, suffix, + source, dest, typeCreation); + scene->addItem(tool); + InitOperationToolConnections(scene, tool); + doc->AddTool(id, tool); + doc->IncrementReferens(firstPoint.getIdTool()); + doc->IncrementReferens(secondPoint.getIdTool()); + for (int i = 0; i < source.size(); ++i) + { + doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool()); + } + return tool; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::SetVisualization() +{ + if (vis != nullptr) + { + VisToolFlippingByLine *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->SetObjects(source); + visual->SetFirstLinePointId(m_firstLinePointId); + visual->SetSecondLinePointId(m_secondLinePointId); + visual->RefreshGeometry(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + DialogFlippingByLine *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + + doc->SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->GetFirstLinePointId())); + doc->SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->GetSecondLinePointId())); + doc->SetAttribute(domElement, AttrSuffix, dialogTool->GetSuffix()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::ReadToolAttributes(const QDomElement &domElement) +{ + m_firstLinePointId = doc->GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); + m_secondLinePointId = doc->GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); + suffix = doc->GetParametrString(domElement, AttrSuffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VDrawTool::SaveOptions(tag, obj); + + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrP1Line, QString().setNum(m_firstLinePointId)); + doc->SetAttribute(tag, AttrP2Line, QString().setNum(m_secondLinePointId)); + doc->SetAttribute(tag, AttrSuffix, suffix); + + SaveSourceDestination(tag); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByLine::VToolFlippingByLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstLinePointId, + quint32 secondLinePointId, const QString &suffix, + const QVector &source, const QVector &destination, + const Source &typeCreation, QGraphicsItem *parent) + : VAbstractFlipping(doc, data, id, suffix, source, destination, parent), + m_firstLinePointId(firstLinePointId), + m_secondLinePointId(secondLinePointId) +{ + InitOperatedObjects(); + ToolCreation(typeCreation); +} diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h new file mode 100644 index 000000000..6d11c77c5 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h @@ -0,0 +1,74 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 VTOOLFLIPPINGBYLINE_H +#define VTOOLFLIPPINGBYLINE_H + +#include + +#include "vabstractflipping.h" + +class VToolFlippingByLine : public VAbstractFlipping +{ + Q_OBJECT +public: + virtual ~VToolFlippingByLine(); + virtual void setDialog() Q_DECL_OVERRIDE; + static VToolFlippingByLine* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data); + static VToolFlippingByLine* Create(const quint32 _id, quint32 firstLinePointId, quint32 secondLinePointId, + const QString &suffix, const QVector &source, + const QVector &destination, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation); + + static const QString ToolType; + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Tool::FlippingByLine)}; + + virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; +protected: + virtual void SetVisualization() Q_DECL_OVERRIDE; + virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(VToolFlippingByLine) + + quint32 m_firstLinePointId; + quint32 m_secondLinePointId; + + VToolFlippingByLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstLinePointId, + quint32 secondLinePointId, const QString &suffix, const QVector &source, + const QVector &destination, const Source &typeCreation, + QGraphicsItem *parent = nullptr); +}; + +#endif // VTOOLFLIPPINGBYLINE_H diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp new file mode 100644 index 000000000..6396bfe0b --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -0,0 +1,610 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 "vabstractoperation.h" +#include "../../../undocommands/label/operationmovelabel.h" +#include "../vgeometry/vpointf.h" + +const QString VAbstractOperation::TagItem = QStringLiteral("item"); +const QString VAbstractOperation::TagSource = QStringLiteral("source"); +const QString VAbstractOperation::TagDestination = QStringLiteral("destination"); + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractOperation::~VAbstractOperation() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractOperation::getTagName() const +{ + return VAbstractPattern::TagOperation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SetEnabled(bool enabled) +{ + this->setEnabled(enabled); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractOperation::Suffix() const +{ + return suffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SetSuffix(const QString &suffix) +{ + // Don't know if need check name here. + this->suffix = suffix; + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::GroupVisibility(quint32 object, bool visible) +{ + if (operatedObjects.contains(object)) + { + VAbstractSimple *obj = operatedObjects.value(object); + if (obj->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(obj); + SCASSERT(item != nullptr); + item->setVisible(visible); + } + else + { + VSimpleCurve *item = qobject_cast(obj); + SCASSERT(item != nullptr); + item->setVisible(visible); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(painter); + Q_UNUSED(option); + Q_UNUSED(widget); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, + QVector &destination) +{ + SCASSERT(doc != nullptr) + const QDomNodeList nodeList = domElement.childNodes(); + for (qint32 i = 0; i < nodeList.size(); ++i) + { + const QDomElement dataElement = nodeList.at(i).toElement(); + if (not dataElement.isNull() && dataElement.tagName() == TagSource) + { + source.clear(); + const QDomNodeList srcList = dataElement.childNodes(); + for (qint32 j = 0; j < srcList.size(); ++j) + { + const QDomElement element = srcList.at(j).toElement(); + if (not element.isNull()) + { + source.append(doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR)); + } + } + } + + if (not dataElement.isNull() && dataElement.tagName() == TagDestination) + { + destination.clear(); + const QDomNodeList srcList = dataElement.childNodes(); + for (qint32 j = 0; j < srcList.size(); ++j) + { + const QDomElement element = srcList.at(j).toElement(); + if (not element.isNull()) + { + DestinationItem d; + d.id = doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR); + d.mx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, QString::number(INT_MAX))); + d.my = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, QString::number(INT_MAX))); + destination.append(d); + } + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::FullUpdateFromFile() +{ + ReadAttributes(); + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); + } + } + SetVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowHover(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSelecting(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowPointHover(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowPointSelecting(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowPointLabelHover(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->AllowLabelHover(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowPointLabelSelecting(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->AllowLabelSelecting(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSplineHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::Spline); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSplineSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::Spline); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSplinePathHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::SplinePath); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSplinePathSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::SplinePath); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowArcHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::Arc); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowArcSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::Arc); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::Disable(bool disable, const QString &namePP) +{ + enabled = !CorrectDisable(disable, namePP); + SetEnabled(enabled); + + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + i.value()->SetEnabled(enabled); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::ObjectSelected(bool selected, quint32 objId) +{ + emit ChangedToolSelection(selected, objId, id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::DeleteFromLabel() +{ + try + { + DeleteTool(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::LabelChangePosition(const QPointF &pos, quint32 labelId) +{ + if (operatedObjects.contains(labelId)) + { + VAbstractSimple *obj = operatedObjects.value(labelId); + if (obj->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(obj); + SCASSERT(item != nullptr); + ChangePosition(item, labelId, pos); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractOperation::VAbstractOperation(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, + const QVector &source, const QVector &destination, + QGraphicsItem *parent) + : VDrawTool(doc, data, id), + QGraphicsLineItem(parent), + suffix(suffix), + source(source), + destination(destination), + operatedObjects() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AddToFile() +{ + QDomElement domElement = doc->createElement(getTagName()); + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOptions(domElement, obj); + AddToCalculation(domElement); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(id); + if (domElement.isElement()) + { + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOptions(domElement, obj); + } + else + { + qCDebug(vTool, "Can't find tool with id = %u", id); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::UpdateNamePosition(quint32 id) +{ + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + auto moveLabel = new OperationMoveLabel(this->id, doc, point->mx(), point->my(), id); + connect(moveLabel, &OperationMoveLabel::ChangePosition, this, &VAbstractOperation::DoChangePosition); + qApp->getUndoStack()->push(moveLabel); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SaveSourceDestination(QDomElement &tag) +{ + doc->RemoveAllChildren(tag); + + QDomElement tagObjects = doc->createElement(TagSource); + for (int i = 0; i < source.size(); ++i) + { + QDomElement item = doc->createElement(TagItem); + doc->SetAttribute(item, AttrIdObject, source.at(i)); + tagObjects.appendChild(item); + } + tag.appendChild(tagObjects); + + tagObjects = doc->createElement(TagDestination); + for (int i = 0; i < destination.size(); ++i) + { + QDomElement item = doc->createElement(TagItem); + doc->SetAttribute(item, AttrIdObject, destination.at(i).id); + + if (not VFuzzyComparePossibleNulls(destination.at(i).mx, INT_MAX) && + not VFuzzyComparePossibleNulls(destination.at(i).my, INT_MAX)) + { + doc->SetAttribute(item, AttrMx, qApp->fromPixel(destination.at(i).mx)); + doc->SetAttribute(item, AttrMy, qApp->fromPixel(destination.at(i).my)); + } + + tagObjects.appendChild(item); + } + tag.appendChild(tagObjects); +} + +//--------------------------------------------------------------------------------------------------------------------- +VSimpleCurve *VAbstractOperation::InitCurve(quint32 id, VContainer *data, GOType curveType) +{ + VSimpleCurve *curve = new VSimpleCurve(id, QColor(baseColor), *data->GetPatternUnit(), &factor); + curve->setParentItem(this); + curve->SetType(curveType); + connect(curve, &VSimpleCurve::Selected, this, &VAbstractOperation::ObjectSelected); + connect(curve, &VSimpleCurve::ShowContextMenu, [this](QGraphicsSceneContextMenuEvent * event) + { + contextMenuEvent(event); + }); + connect(curve, &VSimpleCurve::Delete, this, &VAbstractOperation::DeleteFromLabel); + curve->RefreshGeometry(VAbstractTool::data.GeometricObject(id)); + operatedObjects.insert(id, curve); + return curve; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::DoChangePosition(quint32 id, qreal mx, qreal my) +{ + if (operatedObjects.contains(id)) + { + VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); + point->setMx(mx); + point->setMy(my); + VAbstractTool::data.UpdateGObject(id, point); + + VSimplePoint *item = qobject_cast(operatedObjects.value(id)); + SCASSERT(item != nullptr); + + item->RefreshGeometry(*point); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowCurveHover(bool enabled, GOType type) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() != GOType::Point) + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + if (item->GetType() == type) + { + item->setAcceptHoverEvents(enabled); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowCurveSelecting(bool enabled, GOType type) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() != GOType::Point) + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + if (item->GetType() == type) + { + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos) +{ + const QPointF p = pos - item->pos(); + DoChangePosition(id, p.x(), p.y()); + UpdateNamePosition(id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::InitOperatedObjects() +{ + for (int i = 0; i < destination.size(); ++i) + { + const DestinationItem object = destination.at(i); + const QSharedPointer obj = VAbstractTool::data.GetGObject(object.id); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + VSimplePoint *point = new VSimplePoint(object.id, QColor(baseColor), + *VAbstractTool::data.GetPatternUnit(), &factor); + point->setParentItem(this); + point->SetType(GOType::Point); + connect(point, &VSimplePoint::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Point); + }); + connect(point, &VSimplePoint::Selected, this, &VAbstractOperation::ObjectSelected); + connect(point, &VSimplePoint::ShowContextMenu, [this](QGraphicsSceneContextMenuEvent * event) + { + contextMenuEvent(event); + }); + connect(point, &VSimplePoint::Delete, this, &VAbstractOperation::DeleteFromLabel); + connect(point, &VSimplePoint::NameChangedPosition, this, &VAbstractOperation::LabelChangePosition); + point->RefreshGeometry(*VAbstractTool::data.GeometricObject(object.id)); + operatedObjects.insert(object.id, point); + break; + } + case GOType::Arc: + case GOType::EllipticalArc: + { + VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), GOType::Arc); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Arc); + }); + break; + } + case GOType::Spline: + case GOType::CubicBezier: + { + VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), GOType::Spline); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Spline); + }); + break; + } + case GOType::SplinePath: + case GOType::CubicBezierPath: + { + VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), GOType::SplinePath); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::SplinePath); + }); + break; + } + case GOType::Unknown: + break; + } +QT_WARNING_POP + } +} diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h new file mode 100644 index 000000000..e10123df3 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -0,0 +1,203 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 VABSTRACTOPERATION_H +#define VABSTRACTOPERATION_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../vdrawtool.h" +#include "../vwidgets/vsimplecurve.h" +#include "../vwidgets/vsimplepoint.h" + +struct DestinationItem +{ + quint32 id; + qreal mx; + qreal my; +}; + +class VAbstractSimple; +class VAbstractPattern; +class QDomElement; +class QPainter; +class QPointF; +class QStyleOptionGraphicsItem; +class QWidget; +class VContainer; + +// FIXME. I don't know how to use QGraphicsItem properly, so just took first available finished class. +// QGraphicsItem itself produce case where clicking on empty space produce call to QGraphicsItem. +// And i don't know how to fix it. +class VAbstractOperation : public VDrawTool, public QGraphicsLineItem +{ + Q_OBJECT + // Fix warning "Class implements the interface QGraphicsItem but does not list it + // in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!" + Q_INTERFACES(QGraphicsItem) +public: + virtual ~VAbstractOperation(); + + static const QString TagItem; + static const QString TagSource; + static const QString TagDestination; + + virtual QString getTagName() const Q_DECL_OVERRIDE; + + void SetEnabled(bool enabled); + + QString Suffix() const; + void SetSuffix(const QString &suffix); + + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE; + + static void ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, + QVector &destination); +public slots: + virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; + virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; + + virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; + virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; + + void AllowPointHover(bool enabled); + void AllowPointSelecting(bool enabled); + + void AllowPointLabelHover(bool enabled); + void AllowPointLabelSelecting(bool enabled); + + void AllowSplineHover(bool enabled); + void AllowSplineSelecting(bool enabled); + + void AllowSplinePathHover(bool enabled); + void AllowSplinePathSelecting(bool enabled); + + void AllowArcHover(bool enabled); + void AllowArcSelecting(bool enabled); + + virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; + void ObjectSelected(bool selected, quint32 objId); + void DeleteFromLabel(); + void LabelChangePosition(const QPointF &pos, quint32 labelId); +protected: + QString suffix; + + QVector source; + QVector destination; + + QMap operatedObjects; + + VAbstractOperation(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, + const QVector &source, const QVector &destination, + QGraphicsItem *parent = nullptr); + + virtual void AddToFile() Q_DECL_OVERRIDE; + virtual void RefreshDataInFile() Q_DECL_OVERRIDE; + + void UpdateNamePosition(quint32 id); + void SaveSourceDestination(QDomElement &tag); + + template + void ShowToolVisualization(bool show); + + VSimpleCurve *InitCurve(quint32 id, VContainer *data, GOType curveType); + + template + static void InitOperationToolConnections(VMainGraphicsScene *scene, T *tool); + + void InitOperatedObjects(); +protected slots: + void DoChangePosition(quint32 id, qreal mx, qreal my); +private: + Q_DISABLE_COPY(VAbstractOperation) + + void AllowCurveHover(bool enabled, GOType type); + void AllowCurveSelecting(bool enabled, GOType type); + + void ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos); +}; + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractOperation::ShowToolVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + AddVisualization(); + SetVisualization(); + } + else + { + if (T *visual = qobject_cast(vis)) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractOperation::InitOperationToolConnections(VMainGraphicsScene *scene, T *tool) +{ + SCASSERT(scene != nullptr); + SCASSERT(tool != nullptr); + + InitDrawToolConnections(scene, tool); + + QObject::connect(scene, &VMainGraphicsScene::EnablePointItemHover, tool, &T::AllowPointHover); + QObject::connect(scene, &VMainGraphicsScene::EnablePointItemSelection, tool, &T::AllowPointSelecting); + QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemHover, tool, &T::AllowPointLabelHover); + QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemSelection, tool, &T::AllowPointLabelSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemHover, tool, &T::AllowSplineHover); + QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemSelection, tool, &T::AllowSplineSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemHover, tool, &T::AllowSplinePathHover); + QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemSelection, tool, &T::AllowSplinePathSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableArcItemHover, tool, &T::AllowArcHover); + QObject::connect(scene, &VMainGraphicsScene::EnableArcItemSelection, tool, &T::AllowArcSelecting); +} + +#endif // VABSTRACTOPERATION_H diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index 07d80ff05..a02019573 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -44,8 +44,7 @@ #include "../../../dialogs/tools/dialogtool.h" #include "../../../dialogs/tools/dialogrotation.h" -#include "../../../undocommands/label/rotationmovelabel.h" -#include "../../../visualization/line/vistoolrotation.h" +#include "../../../visualization/line/operation/vistoolrotation.h" #include "../../../visualization/visualization.h" #include "../vgeometry/vabstractcurve.h" #include "../vgeometry/varc.h" @@ -66,8 +65,6 @@ #include "../ifc/exception/vexception.h" #include "../vwidgets/vabstractsimple.h" #include "../vwidgets/vmaingraphicsscene.h" -#include "../vwidgets/vsimplecurve.h" -#include "../vwidgets/vsimplepoint.h" #include "../../vabstracttool.h" #include "../../vdatatool.h" #include "../vdrawtool.h" @@ -79,90 +76,18 @@ class QStyleOptionGraphicsItem; class QWidget; template class QSharedPointer; -const QString VToolRotation::ToolType = QStringLiteral("rotation"); -const QString VToolRotation::TagItem = QStringLiteral("item"); -const QString VToolRotation::TagSource = QStringLiteral("source"); -const QString VToolRotation::TagDestination = QStringLiteral("destination"); +const QString VToolRotation::ToolType = QStringLiteral("rotation"); //--------------------------------------------------------------------------------------------------------------------- VToolRotation::VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, const QString &angle, const QString &suffix, const QVector &source, const QVector &destination, const Source &typeCreation, QGraphicsItem *parent) - : VDrawTool(doc, data, id), - QGraphicsLineItem(parent), + : VAbstractOperation(doc, data, id, suffix, source, destination, parent), origPointId(origPointId), - formulaAngle(angle), - suffix(suffix), - source(source), - destination(destination), - rObjects() + formulaAngle(angle) { - for (int i = 0; i < destination.size(); ++i) - { - const DestinationItem object = destination.at(i); - const QSharedPointer obj = data->GetGObject(object.id); - - // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); - -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wswitch-default") - switch(static_cast(obj->getType())) - { - case GOType::Point: - { - VSimplePoint *point = new VSimplePoint(object.id, QColor(baseColor), *data->GetPatternUnit(), &factor); - point->setParentItem(this); - point->SetType(GOType::Point); - connect(point, &VSimplePoint::Choosed, [this](quint32 id) - { - emit ChoosedTool(id, SceneObject::Point); - }); - connect(point, &VSimplePoint::Selected, this, &VToolRotation::ObjectSelected); - connect(point, &VSimplePoint::ShowContextMenu, this, &VToolRotation::contextMenuEvent); - connect(point, &VSimplePoint::Delete, this, &VToolRotation::DeleteFromLabel); - connect(point, &VSimplePoint::NameChangedPosition, this, &VToolRotation::LabelChangePosition); - point->RefreshGeometry(*VAbstractTool::data.GeometricObject(object.id)); - rObjects.insert(object.id, point); - break; - } - case GOType::Arc: - case GOType::EllipticalArc: - { - VSimpleCurve *curve = InitCurve(object.id, data, GOType::Arc); - connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) - { - emit ChoosedTool(id, SceneObject::Arc); - }); - break; - } - case GOType::Spline: - case GOType::CubicBezier: - { - VSimpleCurve *curve = InitCurve(object.id, data, GOType::Spline); - connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) - { - emit ChoosedTool(id, SceneObject::Spline); - }); - break; - } - case GOType::SplinePath: - case GOType::CubicBezierPath: - { - VSimpleCurve *curve = InitCurve(object.id, data, GOType::SplinePath); - connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) - { - emit ChoosedTool(id, SceneObject::SplinePath); - }); - break; - } - case GOType::Unknown: - break; - } -QT_WARNING_POP - } - + InitOperatedObjects(); ToolCreation(typeCreation); } @@ -317,7 +242,7 @@ QT_WARNING_POP { VToolRotation *tool = new VToolRotation(doc, data, id, origin, angle, suffix, source, dest, typeCreation); scene->addItem(tool); - InitRotationToolConnections(scene, tool); + InitOperationToolConnections(scene, tool); doc->AddTool(id, tool); doc->IncrementReferens(originPoint.getIdTool()); for (int i = 0; i < source.size(); ++i) @@ -329,61 +254,6 @@ QT_WARNING_POP return nullptr; } -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, - QVector &destination) -{ - SCASSERT(doc != nullptr) - const QDomNodeList nodeList = domElement.childNodes(); - for (qint32 i = 0; i < nodeList.size(); ++i) - { - const QDomElement dataElement = nodeList.at(i).toElement(); - if (not dataElement.isNull() && dataElement.tagName() == TagSource) - { - source.clear(); - const QDomNodeList srcList = dataElement.childNodes(); - for (qint32 j = 0; j < srcList.size(); ++j) - { - const QDomElement element = srcList.at(j).toElement(); - if (not element.isNull()) - { - source.append(doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR)); - } - } - } - - if (not dataElement.isNull() && dataElement.tagName() == TagDestination) - { - destination.clear(); - const QDomNodeList srcList = dataElement.childNodes(); - for (qint32 j = 0; j < srcList.size(); ++j) - { - const QDomElement element = srcList.at(j).toElement(); - if (not element.isNull()) - { - DestinationItem d; - d.id = doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR); - d.mx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, QString::number(INT_MAX))); - d.my = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, QString::number(INT_MAX))); - destination.append(d); - } - } - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VToolRotation::getTagName() const -{ - return VAbstractPattern::TagOperation; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::SetEnabled(bool enabled) -{ - this->setEnabled(enabled); -} - //--------------------------------------------------------------------------------------------------------------------- VFormula VToolRotation::GetFormulaAngle() const { @@ -406,263 +276,12 @@ void VToolRotation::SetFormulaAngle(const VFormula &value) } } -//--------------------------------------------------------------------------------------------------------------------- -QString VToolRotation::Suffix() const -{ - return suffix; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::SetSuffix(const QString &suffix) -{ - // Don't know if need check name here. - this->suffix = suffix; - QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); - SaveOption(obj); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::GroupVisibility(quint32 object, bool visible) -{ - if (rObjects.contains(object)) - { - VAbstractSimple *obj = rObjects.value(object); - if (obj->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(obj); - SCASSERT(item != nullptr); - item->setVisible(visible); - } - else - { - VSimpleCurve *item = qobject_cast(obj); - SCASSERT(item != nullptr); - item->setVisible(visible); - } - } -} - //--------------------------------------------------------------------------------------------------------------------- void VToolRotation::ShowVisualization(bool show) { ShowToolVisualization(show); } -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::FullUpdateFromFile() -{ - ReadAttributes(); - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); - } - } - SetVisualization(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowHover(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setAcceptHoverEvents(enabled); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setAcceptHoverEvents(enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSelecting(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowPointHover(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setAcceptHoverEvents(enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowPointSelecting(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowPointLabelHover(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->AllowLabelHover(enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowPointLabelSelecting(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->AllowLabelSelecting(enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSplineHover(bool enabled) -{ - AllowCurveHover(enabled, GOType::Spline); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSplineSelecting(bool enabled) -{ - AllowCurveSelecting(enabled, GOType::Spline); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSplinePathHover(bool enabled) -{ - AllowCurveHover(enabled, GOType::SplinePath); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSplinePathSelecting(bool enabled) -{ - AllowCurveSelecting(enabled, GOType::SplinePath); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowArcHover(bool enabled) -{ - AllowCurveHover(enabled, GOType::Arc); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowArcSelecting(bool enabled) -{ - AllowCurveSelecting(enabled, GOType::Arc); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AddToFile() -{ - QDomElement domElement = doc->createElement(getTagName()); - QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); - SaveOptions(domElement, obj); - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::RefreshDataInFile() -{ - QDomElement domElement = doc->elementById(id); - if (domElement.isElement()) - { - QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); - SaveOptions(domElement, obj); - } - else - { - qCDebug(vTool, "Can't find tool with id = %u", id); - } -} - //--------------------------------------------------------------------------------------------------------------------- void VToolRotation::SetVisualization() { @@ -678,63 +297,6 @@ void VToolRotation::SetVisualization() } } -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(painter); - Q_UNUSED(option); - Q_UNUSED(widget); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::Disable(bool disable, const QString &namePP) -{ - enabled = !CorrectDisable(disable, namePP); - SetEnabled(enabled); - - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - i.value()->SetEnabled(enabled); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::ObjectSelected(bool selected, quint32 objId) -{ - emit ChangedToolSelection(selected, objId, id); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::DeleteFromLabel() -{ - try - { - DeleteTool(); - } - catch(const VExceptionToolWasDeleted &e) - { - Q_UNUSED(e); - return;//Leave this method immediately!!! - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::LabelChangePosition(const QPointF &pos, quint32 labelId) -{ - if (rObjects.contains(labelId)) - { - VAbstractSimple *obj = rObjects.value(labelId); - if (obj->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(obj); - SCASSERT(item != nullptr); - ChangePosition(item, labelId, pos); - } - } -} - //--------------------------------------------------------------------------------------------------------------------- void VToolRotation::SaveDialog(QDomElement &domElement) { @@ -765,33 +327,7 @@ void VToolRotation::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrAngle, formulaAngle); doc->SetAttribute(tag, AttrSuffix, suffix); - doc->RemoveAllChildren(tag); - - QDomElement tagObjects = doc->createElement(TagSource); - for (int i = 0; i < source.size(); ++i) - { - QDomElement item = doc->createElement(TagItem); - doc->SetAttribute(item, AttrIdObject, source.at(i)); - tagObjects.appendChild(item); - } - tag.appendChild(tagObjects); - - tagObjects = doc->createElement(TagDestination); - for (int i = 0; i < destination.size(); ++i) - { - QDomElement item = doc->createElement(TagItem); - doc->SetAttribute(item, AttrIdObject, destination.at(i).id); - - if (not VFuzzyComparePossibleNulls(destination.at(i).mx, INT_MAX) && - not VFuzzyComparePossibleNulls(destination.at(i).my, INT_MAX)) - { - doc->SetAttribute(item, AttrMx, qApp->fromPixel(destination.at(i).mx)); - doc->SetAttribute(item, AttrMy, qApp->fromPixel(destination.at(i).my)); - } - - tagObjects.appendChild(item); - } - tag.appendChild(tagObjects); + SaveSourceDestination(tag); } //--------------------------------------------------------------------------------------------------------------------- @@ -808,32 +344,6 @@ void VToolRotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) } } -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::DoChangePosition(quint32 id, qreal mx, qreal my) -{ - if (rObjects.contains(id)) - { - VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); - point->setMx(mx); - point->setMy(my); - VAbstractTool::data.UpdateGObject(id, point); - - VSimplePoint *item = qobject_cast(rObjects.value(id)); - SCASSERT(item != nullptr); - - item->RefreshGeometry(*point); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::UpdateNamePosition(quint32 id) -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - auto moveLabel = new RotationMoveLabel(this->id, doc, point->mx(), point->my(), id); - connect(moveLabel, &RotationMoveLabel::ChangePosition, this, &VToolRotation::DoChangePosition); - qApp->getUndoStack()->push(moveLabel); -} - //--------------------------------------------------------------------------------------------------------------------- DestinationItem VToolRotation::CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data) @@ -942,121 +452,3 @@ void VToolRotation::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, cons UpdateItem(idTool, idItem, origin, angle, suffix, data, id); data->AddCurveWithSegments(data->GeometricObject(id), id); } - -//--------------------------------------------------------------------------------------------------------------------- -template -void VToolRotation::ShowToolVisualization(bool show) -{ - if (show) - { - if (vis == nullptr) - { - AddVisualization(); - SetVisualization(); - } - else - { - if (T *visual = qobject_cast(vis)) - { - visual->show(); - } - } - } - else - { - delete vis; - vis = nullptr; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos) -{ - const QPointF p = pos - item->pos(); - DoChangePosition(id, p.x(), p.y()); - UpdateNamePosition(id); -} - -//--------------------------------------------------------------------------------------------------------------------- -VSimpleCurve *VToolRotation::InitCurve(quint32 id, VContainer *data, GOType curveType) -{ - VSimpleCurve *curve = new VSimpleCurve(id, QColor(baseColor), *data->GetPatternUnit(), &factor); - curve->setParentItem(this); - curve->SetType(curveType); - connect(curve, &VSimpleCurve::Selected, this, &VToolRotation::ObjectSelected); - connect(curve, &VSimpleCurve::ShowContextMenu, this, &VToolRotation::contextMenuEvent); - connect(curve, &VSimpleCurve::Delete, this, &VToolRotation::DeleteFromLabel); - curve->RefreshGeometry(VAbstractTool::data.GeometricObject(id)); - rObjects.insert(id, curve); - return curve; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowCurveHover(bool enabled, GOType type) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() != GOType::Point) - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - if (item->GetType() == type) - { - item->setAcceptHoverEvents(enabled); - } - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowCurveSelecting(bool enabled, GOType type) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() != GOType::Point) - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - if (item->GetType() == type) - { - item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); - } - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AddSourceObject(VAbstractPattern *doc, QDomElement &domElement, quint32 objId) -{ - QDomElement obj = doc->createElement(TagItem); - doc->SetAttribute(obj, AttrIdObject, objId); - domElement.appendChild(obj); -} - -//--------------------------------------------------------------------------------------------------------------------- -template -void VToolRotation::InitRotationToolConnections(VMainGraphicsScene *scene, T *tool) -{ - SCASSERT(scene != nullptr); - SCASSERT(tool != nullptr); - - InitDrawToolConnections(scene, tool); - - QObject::connect(scene, &VMainGraphicsScene::EnablePointItemHover, tool, &T::AllowPointHover); - QObject::connect(scene, &VMainGraphicsScene::EnablePointItemSelection, tool, &T::AllowPointSelecting); - QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemHover, tool, &T::AllowPointLabelHover); - QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemSelection, tool, &T::AllowPointLabelSelecting); - - QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemHover, tool, &T::AllowSplineHover); - QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemSelection, tool, &T::AllowSplineSelecting); - - QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemHover, tool, &T::AllowSplinePathHover); - QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemSelection, tool, &T::AllowSplinePathSelecting); - - QObject::connect(scene, &VMainGraphicsScene::EnableArcItemHover, tool, &T::AllowArcHover); - QObject::connect(scene, &VMainGraphicsScene::EnableArcItemSelection, tool, &T::AllowArcSelecting); -} diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h index 41e54cda2..0920158db 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h @@ -30,18 +30,14 @@ #define VTOOLROTATION_H #include -#include -#include -#include #include #include #include -#include #include #include #include -#include "../vdrawtool.h" +#include "vabstractoperation.h" #include "../vgeometry/vgeometrydef.h" #include "../vmisc/def.h" #include "../ifc/xml/vabstractpattern.h" @@ -49,35 +45,16 @@ class DialogTool; class QDomElement; class QGraphicsSceneContextMenuEvent; -class QPainter; class QPointF; -class QStyleOptionGraphicsItem; -class QWidget; class VContainer; class VGObject; class VMainGraphicsScene; template class QSharedPointer; - -struct DestinationItem -{ - quint32 id; - qreal mx; - qreal my; -}; - -class VAbstractSimple; class VFormula; -class VSimpleCurve; -// FIXME. I don't know how to use QGraphicsItem properly, so just took first available finished class. -// QGraphicsItem itself produce case where clicking on empty space produce call to QGraphicsItem. -// And i don't know how to fix it. -class VToolRotation : public VDrawTool, public QGraphicsLineItem +class VToolRotation : public VAbstractOperation { Q_OBJECT - // Fix warning "Class implements the interface QGraphicsItem but does not list it - // in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!" - Q_INTERFACES(QGraphicsItem) public: virtual ~VToolRotation(); virtual void setDialog() Q_DECL_OVERRIDE; @@ -87,85 +64,34 @@ public: const QVector &source, const QVector &destination, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); - static void ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, - QVector &destination); + static const QString ToolType; - static const QString TagItem; - static const QString TagSource; - static const QString TagDestination; + virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::Rotation)}; - virtual QString getTagName() const Q_DECL_OVERRIDE; - - void SetEnabled(bool enabled); VFormula GetFormulaAngle() const; void SetFormulaAngle(const VFormula &value); - QString Suffix() const; - void SetSuffix(const QString &suffix); - - virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE; - -public slots: - virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; - - virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; - virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; - - void AllowPointHover(bool enabled); - void AllowPointSelecting(bool enabled); - - void AllowPointLabelHover(bool enabled); - void AllowPointLabelSelecting(bool enabled); - - void AllowSplineHover(bool enabled); - void AllowSplineSelecting(bool enabled); - - void AllowSplinePathHover(bool enabled); - void AllowSplinePathSelecting(bool enabled); - - void AllowArcHover(bool enabled); - void AllowArcSelecting(bool enabled); - - virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; - void ObjectSelected(bool selected, quint32 objId); - void DeleteFromLabel(); - void LabelChangePosition(const QPointF &pos, quint32 labelId); protected: - virtual void AddToFile() Q_DECL_OVERRIDE; - virtual void RefreshDataInFile() Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; -private slots: - void DoChangePosition(quint32 id, qreal mx, qreal my); - private: Q_DISABLE_COPY(VToolRotation) quint32 origPointId; QString formulaAngle; - QString suffix; - - QVector source; - QVector destination; - - QMap rObjects; VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, const QString &formulaAngle, const QString &suffix, const QVector &source, const QVector &destination, const Source &typeCreation, QGraphicsItem *parent = nullptr); - void UpdateNamePosition(quint32 id); - static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data); @@ -178,8 +104,8 @@ private: static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data); template - static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, - const QString &suffix, VContainer *data); + static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, + qreal formulaAngle, const QString &suffix, VContainer *data); static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); @@ -194,21 +120,6 @@ private: template static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data, quint32 id); - - template - void ShowToolVisualization(bool show); - - void ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos); - - VSimpleCurve *InitCurve(quint32 id, VContainer *data, GOType curveType); - - template - static void InitRotationToolConnections(VMainGraphicsScene *scene, T *tool); - - void AllowCurveHover(bool enabled, GOType type); - void AllowCurveSelecting(bool enabled, GOType type); - - static void AddSourceObject(VAbstractPattern *doc, QDomElement &domElement, quint32 objId); }; #endif // VTOOLROTATION_H diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 9ca6a2cd2..833e3d73d 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -50,9 +50,13 @@ HEADERS += \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h \ - $$PWD/drawTools/operation/vtoolrotation.h \ - $$PWD/vtextgraphicsitem.h \ - $$PWD/vgrainlineitem.h + $$PWD/drawTools/operation/vtoolrotation.h \ + $$PWD/vtextgraphicsitem.h \ + $$PWD/vgrainlineitem.h \ + $$PWD/drawTools/operation/flipping/vtoolflippingbyline.h \ + $$PWD/drawTools/operation/vabstractoperation.h \ + $$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.h \ + $$PWD/drawTools/operation/flipping/vabstractflipping.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -102,4 +106,8 @@ SOURCES += \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp \ $$PWD/drawTools/operation/vtoolrotation.cpp \ $$PWD/vtextgraphicsitem.cpp \ - $$PWD/vgrainlineitem.cpp + $$PWD/vgrainlineitem.cpp \ + $$PWD/drawTools/operation/flipping/vtoolflippingbyline.cpp \ + $$PWD/drawTools/operation/vabstractoperation.cpp \ + $$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.cpp \ + $$PWD/drawTools/operation/flipping/vabstractflipping.cpp diff --git a/src/libs/vtools/undocommands/label/rotationmovelabel.cpp b/src/libs/vtools/undocommands/label/operationmovelabel.cpp similarity index 89% rename from src/libs/vtools/undocommands/label/rotationmovelabel.cpp rename to src/libs/vtools/undocommands/label/operationmovelabel.cpp index 89b2994e8..d83066110 100644 --- a/src/libs/vtools/undocommands/label/rotationmovelabel.cpp +++ b/src/libs/vtools/undocommands/label/operationmovelabel.cpp @@ -26,7 +26,7 @@ ** *************************************************************************/ -#include "rotationmovelabel.h" +#include "operationmovelabel.h" #include #include @@ -43,8 +43,8 @@ class QUndoCommand; //--------------------------------------------------------------------------------------------------------------------- -RotationMoveLabel::RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, - QUndoCommand *parent) +OperationMoveLabel::OperationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, + QUndoCommand *parent) : MoveAbstractLabel(doc, idPoint, x, y, parent), m_idTool(idTool) { @@ -69,14 +69,14 @@ RotationMoveLabel::RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, doub } //--------------------------------------------------------------------------------------------------------------------- -RotationMoveLabel::~RotationMoveLabel() +OperationMoveLabel::~OperationMoveLabel() { } //--------------------------------------------------------------------------------------------------------------------- -bool RotationMoveLabel::mergeWith(const QUndoCommand *command) +bool OperationMoveLabel::mergeWith(const QUndoCommand *command) { - const RotationMoveLabel *moveCommand = static_cast(command); + const OperationMoveLabel *moveCommand = static_cast(command); SCASSERT(moveCommand != nullptr); if (moveCommand->GetToolId() != m_idTool && moveCommand->GetPointId() != nodeId) @@ -93,13 +93,13 @@ bool RotationMoveLabel::mergeWith(const QUndoCommand *command) } //--------------------------------------------------------------------------------------------------------------------- -int RotationMoveLabel::id() const +int OperationMoveLabel::id() const { return static_cast(UndoCommand::RotationMoveLabel); } //--------------------------------------------------------------------------------------------------------------------- -void RotationMoveLabel::Do(double mx, double my) +void OperationMoveLabel::Do(double mx, double my) { qCDebug(vUndo, "New mx %f", mx); qCDebug(vUndo, "New my %f", my); @@ -118,7 +118,7 @@ void RotationMoveLabel::Do(double mx, double my) } //--------------------------------------------------------------------------------------------------------------------- -QDomElement RotationMoveLabel::GetDestinationObject(quint32 idTool, quint32 idPoint) const +QDomElement OperationMoveLabel::GetDestinationObject(quint32 idTool, quint32 idPoint) const { const QDomElement tool = doc->elementById(idTool); if (tool.isElement()) diff --git a/src/libs/vtools/undocommands/label/rotationmovelabel.h b/src/libs/vtools/undocommands/label/operationmovelabel.h similarity index 83% rename from src/libs/vtools/undocommands/label/rotationmovelabel.h rename to src/libs/vtools/undocommands/label/operationmovelabel.h index 5308ddd02..b88f57f5b 100644 --- a/src/libs/vtools/undocommands/label/rotationmovelabel.h +++ b/src/libs/vtools/undocommands/label/operationmovelabel.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file moverotationlabel.h + ** @file operationmovelabel.h ** @author Roman Telezhynskyi ** @date 13 5, 2016 ** @@ -26,8 +26,8 @@ ** *************************************************************************/ -#ifndef ROTATIONMOVELABEL_H -#define ROTATIONMOVELABEL_H +#ifndef OPERATIONMOVELABEL_H +#define OPERATIONMOVELABEL_H #include #include @@ -42,13 +42,13 @@ class QDomElement; class QUndoCommand; class VAbstractPattern; -class RotationMoveLabel : public MoveAbstractLabel +class OperationMoveLabel : public MoveAbstractLabel { Q_OBJECT public: - RotationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, + OperationMoveLabel(quint32 idTool, VAbstractPattern *doc, double x, double y, quint32 idPoint, QUndoCommand *parent = nullptr); - virtual ~RotationMoveLabel(); + virtual ~OperationMoveLabel(); virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; virtual int id() const Q_DECL_OVERRIDE; @@ -57,16 +57,16 @@ public: protected: virtual void Do(double mx, double my) Q_DECL_OVERRIDE; private: - Q_DISABLE_COPY(RotationMoveLabel) + Q_DISABLE_COPY(OperationMoveLabel) quint32 m_idTool; QDomElement GetDestinationObject(quint32 idTool, quint32 idPoint) const; }; //--------------------------------------------------------------------------------------------------------------------- -inline quint32 RotationMoveLabel::GetToolId() const +inline quint32 OperationMoveLabel::GetToolId() const { return m_idTool; } -#endif // ROTATIONMOVELABEL_H +#endif // OPERATIONMOVELABEL_H diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index 39a455dc1..216944bb2 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -21,9 +21,9 @@ HEADERS += \ $$PWD/label/movedoublelabel.h \ $$PWD/addgroup.h \ $$PWD/delgroup.h \ - $$PWD/label/rotationmovelabel.h \ $$PWD/label/moveabstractlabel.h \ - $$PWD/toggledetailinlayout.h + $$PWD/toggledetailinlayout.h \ + $$PWD/label/operationmovelabel.h SOURCES += \ $$PWD/addtocalc.cpp \ @@ -45,6 +45,6 @@ SOURCES += \ $$PWD/label/movedoublelabel.cpp \ $$PWD/addgroup.cpp \ $$PWD/delgroup.cpp \ - $$PWD/label/rotationmovelabel.cpp \ $$PWD/label/moveabstractlabel.cpp \ - $$PWD/toggledetailinlayout.cpp + $$PWD/toggledetailinlayout.cpp \ + $$PWD/label/operationmovelabel.cpp diff --git a/src/libs/vtools/visualization/line/operation/visoperation.cpp b/src/libs/vtools/visualization/line/operation/visoperation.cpp new file mode 100644 index 000000000..03d3aa7a9 --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/visoperation.cpp @@ -0,0 +1,179 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 "visoperation.h" +#include "../vgeometry/vabstractcurve.h" +#include "../vgeometry/varc.h" +#include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" +#include "../vgeometry/vellipticalarc.h" +#include "../vgeometry/vgeometrydef.h" +#include "../vgeometry/vgobject.h" +#include "../vgeometry/vpointf.h" +#include "../vgeometry/vspline.h" +#include "../vgeometry/vsplinepath.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisOperation::VisOperation(const VContainer *data, QGraphicsItem *parent) + : VisLine(data, parent), + objects(), + supportColor2(Qt::darkGreen), + points(), + curves() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +VisOperation::~VisOperation() +{ + qDeleteAll(points); + qDeleteAll(curves); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisOperation::SetObjects(QVector objects) +{ + this->objects = objects; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisOperation::VisualMode(const quint32 &pointId) +{ + Q_UNUSED(pointId); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + + Visualization::scenePos = scene->getScenePos(); + RefreshGeometry(); + + AddOnScene(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *VisOperation::GetPoint(quint32 i, const QColor &color) +{ + if (not points.isEmpty() && static_cast(points.size() - 1) >= i) + { + return points.at(static_cast(i)); + } + else + { + auto point = InitPoint(color, this); + points.append(point); + return point; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsPathItem *VisOperation::GetCurve(quint32 i, const QColor &color) +{ + if (not curves.isEmpty() && static_cast(curves.size() - 1) >= i) + { + return curves.at(static_cast(i)); + } + else + { + auto curve = InitItem(color, this); + curves.append(curve); + return curve; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") +void VisOperation::RefreshFlippedObjects(const QPointF &firstPoint, const QPointF &secondPoint) +{ + int iPoint = -1; + int iCurve = -1; + for (int i = 0; i < objects.size(); ++i) + { + const quint32 id = objects.at(i); + const QSharedPointer obj = Visualization::data->GetGObject(id); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + const QSharedPointer p = Visualization::data->GeometricObject(id); + + ++iPoint; + QGraphicsEllipseItem *point = GetPoint(iPoint, supportColor2); + DrawPoint(point, *p, supportColor2); + + ++iPoint; + point = GetPoint(iPoint, supportColor); + + if (object1Id != NULL_ID) + { + DrawPoint(point, p->Flip(QLineF(firstPoint, secondPoint)), supportColor); + } + break; + } + case GOType::Arc: + { + iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::EllipticalArc: + { + iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::Spline: + { + iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::SplinePath: + { + iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::CubicBezier: + { + iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::CubicBezierPath: + { + iCurve = AddFlippedCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::Unknown: + break; + } + } +} +QT_WARNING_POP diff --git a/src/libs/vtools/visualization/line/operation/visoperation.h b/src/libs/vtools/visualization/line/operation/visoperation.h new file mode 100644 index 000000000..6e698e81d --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/visoperation.h @@ -0,0 +1,88 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 VISOPERATION_H +#define VISOPERATION_H + +#include + +#include "../visline.h" + +class VisOperation : public VisLine +{ + Q_OBJECT +public: + explicit VisOperation(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisOperation(); + + void SetObjects(QVector objects); + + virtual void VisualMode(const quint32 &pointId = NULL_ID) Q_DECL_OVERRIDE; + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolRotation)}; +protected: + QVector objects; + QColor supportColor2; + + QVector points; + QVector curves; + + QGraphicsEllipseItem * GetPoint(quint32 i, const QColor &color); + QGraphicsPathItem * GetCurve(quint32 i, const QColor &color); + + template + int AddFlippedCurve(const QPointF &firstPoint, const QPointF &secondPoint, quint32 id, int i); + + void RefreshFlippedObjects(const QPointF &firstPoint, const QPointF &secondPoint); +private: + Q_DISABLE_COPY(VisOperation) +}; + +//--------------------------------------------------------------------------------------------------------------------- +template +int VisOperation::AddFlippedCurve(const QPointF &firstPoint, const QPointF &secondPoint, quint32 id, int i) +{ + const QSharedPointer curve = Visualization::data->template GeometricObject(id); + + ++i; + QGraphicsPathItem *path = GetCurve(i, supportColor2); + DrawPath(path, curve->GetPath(PathDirection::Show), supportColor2, Qt::SolidLine, Qt::RoundCap); + + ++i; + path = GetCurve(i, supportColor); + if (object1Id != NULL_ID) + { + const Item flipped = curve->Flip(QLineF(firstPoint, secondPoint)); + DrawPath(path, flipped.GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + } + + return i; +} + +#endif // VISOPERATION_H diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp new file mode 100644 index 000000000..2b20e984f --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp @@ -0,0 +1,87 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 9, 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 "vistoolflippingbyaxis.h" +#include "../vgeometry/vpointf.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolFlippingByAxis::VisToolFlippingByAxis(const VContainer *data, QGraphicsItem *parent) + : VisOperation(data, parent), + m_axisType(AxisType::VerticalAxis), + point1(nullptr) +{ + point1 = InitPoint(supportColor2, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolFlippingByAxis::~VisToolFlippingByAxis() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByAxis::RefreshGeometry() +{ + if (objects.isEmpty()) + { + return; + } + + QPointF firstPoint; + QPointF secondPoint; + + if (object1Id != NULL_ID) + { + firstPoint = *Visualization::data->GeometricObject(object1Id); + DrawPoint(point1, firstPoint, supportColor2); + + if (m_axisType == AxisType::VerticalAxis) + { + secondPoint = QPointF(firstPoint.x(), firstPoint.y() + 100); + } + else + { + secondPoint = QPointF(firstPoint.x() + 100, firstPoint.y()); + } + + DrawLine(this, Axis(firstPoint, secondPoint), supportColor2, Qt::DashLine); + } + + RefreshFlippedObjects(firstPoint, secondPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByAxis::SetOriginPointId(quint32 value) +{ + object1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByAxis::SetAxisType(AxisType value) +{ + m_axisType = value; +} diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h new file mode 100644 index 000000000..301f33dcd --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h @@ -0,0 +1,59 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 9, 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 VISTOOLFLIPPINGBYAXIS_H +#define VISTOOLFLIPPINGBYAXIS_H + +#include + +#include "visoperation.h" +#include "../ifc/xml/vabstractpattern.h" + +class VisToolFlippingByAxis : public VisOperation +{ + Q_OBJECT +public: + explicit VisToolFlippingByAxis(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolFlippingByAxis(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + + void SetOriginPointId(quint32 value); + void SetAxisType(AxisType value); + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolFlippingByAxis)}; +private: + Q_DISABLE_COPY(VisToolFlippingByAxis) + + AxisType m_axisType; + + QGraphicsEllipseItem *point1; +}; + +#endif // VISTOOLFLIPPINGBYAXIS_H diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp new file mode 100644 index 000000000..ce808d1b0 --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp @@ -0,0 +1,90 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 "vistoolflippingbyline.h" +#include "../vgeometry/vpointf.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolFlippingByLine::VisToolFlippingByLine(const VContainer *data, QGraphicsItem *parent) + : VisOperation(data, parent), + object2Id(NULL_ID), + point1(nullptr), + point2(nullptr) +{ + point1 = InitPoint(supportColor2, this); + point2 = InitPoint(supportColor2, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolFlippingByLine::~VisToolFlippingByLine() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByLine::RefreshGeometry() +{ + if (objects.isEmpty()) + { + return; + } + + QPointF firstPoint; + QPointF secondPoint; + + if (object1Id != NULL_ID) + { + firstPoint = *Visualization::data->GeometricObject(object1Id); + DrawPoint(point1, firstPoint, supportColor2); + + if (object2Id == NULL_ID) + { + secondPoint = Visualization::scenePos; + } + else + { + secondPoint = *Visualization::data->GeometricObject(object2Id); + DrawPoint(point2, secondPoint, supportColor2); + } + + DrawLine(this, QLineF(firstPoint, secondPoint), supportColor2, Qt::DashLine); + } + + RefreshFlippedObjects(firstPoint, secondPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByLine::SetFirstLinePointId(quint32 value) +{ + object1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByLine::SetSecondLinePointId(quint32 value) +{ + object2Id = value; +} diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h new file mode 100644 index 000000000..21768a03a --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h @@ -0,0 +1,57 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 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 VISTOOLFLIPPINGBYLINE_H +#define VISTOOLFLIPPINGBYLINE_H + +#include + +#include "visoperation.h" + +class VisToolFlippingByLine : public VisOperation +{ + Q_OBJECT +public: + explicit VisToolFlippingByLine(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolFlippingByLine(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + + void SetFirstLinePointId(quint32 value); + void SetSecondLinePointId(quint32 value); + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolFlippingByLine)}; +private: + Q_DISABLE_COPY(VisToolFlippingByLine) + quint32 object2Id; + QGraphicsEllipseItem *point1; + QGraphicsEllipseItem *point2; +}; + +#endif // VISTOOLFLIPPINGBYLINE_H diff --git a/src/libs/vtools/visualization/line/vistoolrotation.cpp b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp similarity index 80% rename from src/libs/vtools/visualization/line/vistoolrotation.cpp rename to src/libs/vtools/visualization/line/operation/vistoolrotation.cpp index 2101cfb46..b2179db23 100644 --- a/src/libs/vtools/visualization/line/vistoolrotation.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp @@ -53,22 +53,17 @@ #include "../vmisc/vabstractapplication.h" #include "../vpatterndb/vcontainer.h" #include "../vwidgets/vmaingraphicsscene.h" -#include "../visualization.h" -#include "visline.h" +#include "visoperation.h" class QPointF; //--------------------------------------------------------------------------------------------------------------------- VisToolRotation::VisToolRotation(const VContainer *data, QGraphicsItem *parent) - : VisLine(data, parent), + : VisOperation(data, parent), angle(INT_MIN), - objects(), point(nullptr), angleArc(nullptr), - xAxis(nullptr), - supportColor2(Qt::darkGreen), - points(), - curves() + xAxis(nullptr) { point = InitPoint(supportColor2, this); angleArc = InitItem(supportColor2, this); @@ -78,8 +73,6 @@ VisToolRotation::VisToolRotation(const VContainer *data, QGraphicsItem *parent) //--------------------------------------------------------------------------------------------------------------------- VisToolRotation::~VisToolRotation() { - qDeleteAll(points); - qDeleteAll(curves); } //--------------------------------------------------------------------------------------------------------------------- @@ -198,12 +191,6 @@ void VisToolRotation::RefreshGeometry() QT_WARNING_POP -//--------------------------------------------------------------------------------------------------------------------- -void VisToolRotation::SetObjects(QVector objects) -{ - this->objects = objects; -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolRotation::SetOriginPointId(quint32 value) { @@ -222,51 +209,6 @@ void VisToolRotation::SetAngle(const QString &expression) angle = FindVal(expression, Visualization::data->PlainVariables()); } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolRotation::VisualMode(const quint32 &pointId) -{ - Q_UNUSED(pointId); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr); - - Visualization::scenePos = scene->getScenePos(); - RefreshGeometry(); - - AddOnScene(); -} - -//--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *VisToolRotation::GetPoint(quint32 i, const QColor &color) -{ - if (not points.isEmpty() && static_cast(points.size() - 1) >= i) - { - return points.at(static_cast(i)); - } - else - { - auto point = InitPoint(color, this); - points.append(point); - return point; - } - return nullptr; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGraphicsPathItem *VisToolRotation::GetCurve(quint32 i, const QColor &color) -{ - if (not curves.isEmpty() && static_cast(curves.size() - 1) >= i) - { - return curves.at(static_cast(i)); - } - else - { - auto curve = InitItem(color, this); - curves.append(curve); - return curve; - } - return nullptr; -} - //--------------------------------------------------------------------------------------------------------------------- template int VisToolRotation::AddCurve(qreal angle, const QPointF &origin, quint32 id, int i) diff --git a/src/libs/vtools/visualization/line/vistoolrotation.h b/src/libs/vtools/visualization/line/operation/vistoolrotation.h similarity index 82% rename from src/libs/vtools/visualization/line/vistoolrotation.h rename to src/libs/vtools/visualization/line/operation/vistoolrotation.h index 988fff1a7..2f262dcc2 100644 --- a/src/libs/vtools/visualization/line/vistoolrotation.h +++ b/src/libs/vtools/visualization/line/operation/vistoolrotation.h @@ -41,12 +41,12 @@ #include "../ifc/ifcdef.h" #include "../vmisc/def.h" -#include "visline.h" +#include "visoperation.h" class QPointF; class VContainer; -class VisToolRotation : public VisLine +class VisToolRotation : public VisOperation { Q_OBJECT public: @@ -55,30 +55,19 @@ public: virtual void RefreshGeometry() Q_DECL_OVERRIDE; - void SetObjects(QVector objects); void SetOriginPointId(quint32 value); QString Angle() const; void SetAngle(const QString &expression); - virtual void VisualMode(const quint32 &pointId = NULL_ID) Q_DECL_OVERRIDE; - virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolRotation)}; private: Q_DISABLE_COPY(VisToolRotation) qreal angle; - QVector objects; QGraphicsEllipseItem *point; QGraphicsPathItem *angleArc; QGraphicsLineItem *xAxis; - QColor supportColor2; - - QVector points; - QVector curves; - - QGraphicsEllipseItem * GetPoint(quint32 i, const QColor &color); - QGraphicsPathItem * GetCurve(quint32 i, const QColor &color); template int AddCurve(qreal angle, const QPointF &origin, quint32 id, int i); diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index fce6c442e..4e2775d3f 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -22,6 +22,8 @@ HEADERS += \ $$PWD/line/vistoolpointofintersectioncircles.h \ $$PWD/line/vistoolpointfromcircleandtangent.h \ $$PWD/line/vistoolpointfromarcandtangent.h \ + $$PWD/line/operation/vistoolrotation.h \ + $$PWD/line/operation/vistoolflippingbyline.h \ $$PWD/path/vispath.h \ $$PWD/path/vistoolarc.h \ $$PWD/path/vistoolcutarc.h \ @@ -33,7 +35,8 @@ HEADERS += \ $$PWD/path/vistoolpointofintersectioncurves.h \ $$PWD/path/vistoolcubicbezier.h \ $$PWD/path/vistoolcubicbezierpath.h \ - visualization/line/vistoolrotation.h + $$PWD/line/operation/visoperation.h \ + $$PWD/line/operation/vistoolflippingbyaxis.h SOURCES += \ $$PWD/visualization.cpp \ @@ -56,6 +59,8 @@ SOURCES += \ $$PWD/line/vistoolpointofintersectioncircles.cpp \ $$PWD/line/vistoolpointfromcircleandtangent.cpp \ $$PWD/line/vistoolpointfromarcandtangent.cpp \ + $$PWD/line/operation/vistoolrotation.cpp \ + $$PWD/line/operation/vistoolflippingbyline.cpp \ $$PWD/path/vispath.cpp \ $$PWD/path/vistoolarc.cpp \ $$PWD/path/vistoolcutarc.cpp \ @@ -67,4 +72,5 @@ SOURCES += \ $$PWD/path/vistoolpointofintersectioncurves.cpp \ $$PWD/path/vistoolcubicbezier.cpp \ $$PWD/path/vistoolcubicbezierpath.cpp \ - visualization/line/vistoolrotation.cpp + $$PWD/line/operation/visoperation.cpp \ + $$PWD/line/operation/vistoolflippingbyaxis.cpp diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 39e50881e..3f5c649de 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -52,7 +52,8 @@ SOURCES += \ tst_vellipticalarc.cpp \ tst_vcubicbezierpath.cpp \ tst_vgobject.cpp \ - tst_vsplinepath.cpp + tst_vsplinepath.cpp \ + tst_vpointf.cpp win32-msvc*:SOURCES += stable.cpp @@ -75,7 +76,8 @@ HEADERS += \ tst_vellipticalarc.h \ tst_vcubicbezierpath.h \ tst_vgobject.h \ - tst_vsplinepath.h + tst_vsplinepath.h \ + tst_vpointf.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 36d818382..02cf31d74 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -46,6 +46,7 @@ #include "tst_vcubicbezierpath.h" #include "tst_vgobject.h" #include "tst_vsplinepath.h" +#include "tst_vpointf.h" #include "../vmisc/def.h" @@ -80,6 +81,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_VAbstractCurve()); ASSERT_TEST(new TST_VCubicBezierPath()); ASSERT_TEST(new TST_VGObject()); + ASSERT_TEST(new TST_VPointF()); return status; } diff --git a/src/test/ValentinaTest/tst_varc.cpp b/src/test/ValentinaTest/tst_varc.cpp index ba2fbfb4c..207050c34 100644 --- a/src/test/ValentinaTest/tst_varc.cpp +++ b/src/test/ValentinaTest/tst_varc.cpp @@ -246,3 +246,74 @@ void TST_VArc::TestRotation() const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); QVERIFY2(rotatedArc.name().endsWith(prefix), qUtf8Printable(errorMsg)); } + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VArc::TestFlip_data() +{ + QTest::addColumn("center"); + QTest::addColumn("radius"); + QTest::addColumn("startAngle"); + QTest::addColumn("endAngle"); + QTest::addColumn("axis"); + QTest::addColumn("prefix"); + + const qreal radius = 5; + QPointF center(10, 5); + + QPointF p1(10, 0); + QPointF p2(5, 5); + + QLineF axis(QPointF(4, 6), QPointF(12, 6)); + + QTest::newRow("Vertical axis") << center << radius << QLineF(center, p1).angle() << QLineF(center, p2).angle() + << axis << "a2"; + + p1 = QPointF(15, 5); + p2 = QPointF(10, 0); + + axis = QLineF(QPointF(9, -1), QPointF(9, 6)); + + QTest::newRow("Horizontal axis") << center << radius << QLineF(center, p1).angle() << QLineF(center, p2).angle() + << axis << "a2"; + + QLineF l(center.x(), center.y(), center.x() + radius, center.y()); + + l.setAngle(45); + p2 = l.p2(); + + l.setAngle(225); + p1 = l.p2(); + + l.setAngle(45+90); + l.setLength(5); + + const QPointF p1Axis = l.p2(); + axis = QLineF(p1Axis.x(), p1Axis.y(), p1Axis.x() + radius, p1Axis.y()); + axis.setAngle(45); + + QTest::newRow("Diagonal axis") << center << radius << QLineF(center, p1).angle() << QLineF(center, p2).angle() + << axis << "a2"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VArc::TestFlip() +{ + QFETCH(QPointF, center); + QFETCH(qreal, radius); + QFETCH(qreal, startAngle); + QFETCH(qreal, endAngle); + QFETCH(QLineF, axis); + QFETCH(QString, prefix); + + VArc originArc(center, radius, startAngle, endAngle); + const VArc res = originArc.Flip(axis, prefix); + + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); + + QVERIFY2(res.IsFlipped(), qUtf8Printable("The arc is not flipped")); + + QCOMPARE(originArc.GetLength()*-1, res.GetLength()); + QCOMPARE(originArc.GetRadius(), res.GetRadius()); + QCOMPARE(originArc.AngleArc(), res.AngleArc()); +} diff --git a/src/test/ValentinaTest/tst_varc.h b/src/test/ValentinaTest/tst_varc.h index 770c2a7a7..74f62f2ed 100644 --- a/src/test/ValentinaTest/tst_varc.h +++ b/src/test/ValentinaTest/tst_varc.h @@ -44,6 +44,8 @@ private slots: void TestGetPoints(); void TestRotation_data(); void TestRotation(); + void TestFlip_data(); + void TestFlip(); }; #endif // TST_VARC_H diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp index 023884d47..5abd8b583 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.cpp +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -31,6 +31,7 @@ #include "../vlayout/vabstractdetail.h" #include "../vmisc/logging.h" +#include #include //--------------------------------------------------------------------------------------------------------------------- @@ -455,3 +456,43 @@ void TST_VEllipticalArc::TestRotation() const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); QVERIFY2(rotatedArc.name().endsWith(prefix), qUtf8Printable(errorMsg)); } + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VEllipticalArc::TestFlip_data() +{ + QTest::addColumn("elArc"); + QTest::addColumn("axis"); + QTest::addColumn("prefix"); + + const VEllipticalArc elArc(QPointF(), 10., 20.0, 1., 91., 0.); + + QLineF axis(QPointF(600, 30), QPointF(600, 1800)); + + QTest::newRow("Vertical axis") << elArc << axis << "a2"; + + axis = QLineF(QPointF(600, 30), QPointF(1200, 30)); + + QTest::newRow("Horizontal axis") << elArc << axis << "a2"; + + axis = QLineF(QPointF(600, 30), QPointF(600, 1800)); + axis.setAngle(45); + + QTest::newRow("Diagonal axis") << elArc << axis << "a2"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VEllipticalArc::TestFlip() +{ + QFETCH(VEllipticalArc, elArc); + QFETCH(QLineF, axis); + QFETCH(QString, prefix); + + const VEllipticalArc res = elArc.Flip(axis, prefix); + + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); + + QCOMPARE(qRound(elArc.GetLength()*-1), qRound(res.GetLength())); + QCOMPARE(elArc.GetRadius1(), res.GetRadius1()); + QCOMPARE(elArc.GetRadius2(), res.GetRadius2()); +} diff --git a/src/test/ValentinaTest/tst_vellipticalarc.h b/src/test/ValentinaTest/tst_vellipticalarc.h index 17e8fc2b1..61f1f678c 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.h +++ b/src/test/ValentinaTest/tst_vellipticalarc.h @@ -51,6 +51,8 @@ private slots: void TestGetPoints4(); void TestRotation_data(); void TestRotation(); + void TestFlip_data(); + void TestFlip(); private: Q_DISABLE_COPY(TST_VEllipticalArc) diff --git a/src/test/ValentinaTest/tst_vpointf.cpp b/src/test/ValentinaTest/tst_vpointf.cpp new file mode 100644 index 000000000..6d3b983ba --- /dev/null +++ b/src/test/ValentinaTest/tst_vpointf.cpp @@ -0,0 +1,86 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 10 9, 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_vpointf.h" +#include "../vgeometry/vpointf.h" +#include "../vmisc/logging.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_VPointF::TST_VPointF(QObject *parent) + : QObject(parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VPointF::TestFlip_data() +{ + QTest::addColumn("originPoint"); + QTest::addColumn("axis"); + QTest::addColumn("flipped"); + QTest::addColumn("prefix"); + + VPointF originPoint; + QLineF axis = QLineF(QPointF(5, 0), QPointF(5, 10)); + QPointF flipped = QPointF(10, 0); + + QTest::newRow("Vertical axis") << originPoint << axis << flipped << "a2"; + + axis = QLineF(QPointF(0, 5), QPointF(10, 5)); + flipped = QPointF(0, 10); + + QTest::newRow("Horizontal axis") << originPoint << axis << flipped << "a2"; + + QLineF l = QLineF(QPointF(), QPointF(10, 0)); + l.setAngle(315); + flipped = l.p2(); + l.setLength(l.length()/2.0); + + axis = QLineF(l.p2(), l.p1()); + axis.setAngle(axis.angle()+90); + + QTest::newRow("Diagonal axis") << originPoint << axis << flipped << "a2"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VPointF::TestFlip() +{ + QFETCH(VPointF, originPoint); + QFETCH(QLineF, axis); + QFETCH(QPointF, flipped); + QFETCH(QString, prefix); + + const VPointF res = originPoint.Flip(axis, prefix); + + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); + + QCOMPARE(flipped.toPoint(), res.toQPointF().toPoint()); +} + diff --git a/src/test/ValentinaTest/tst_vpointf.h b/src/test/ValentinaTest/tst_vpointf.h new file mode 100644 index 000000000..903acfa38 --- /dev/null +++ b/src/test/ValentinaTest/tst_vpointf.h @@ -0,0 +1,47 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 10 9, 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_VPOINTF_H +#define TST_VPOINTF_H + +#include +#include + +class TST_VPointF : public QObject +{ + Q_OBJECT +public: + explicit TST_VPointF(QObject *parent = nullptr); +private slots: + void TestFlip_data(); + void TestFlip(); +private: + Q_DISABLE_COPY(TST_VPointF) +}; + +#endif // TST_VPOINTF_H diff --git a/src/test/ValentinaTest/tst_vspline.cpp b/src/test/ValentinaTest/tst_vspline.cpp index b5c0e206e..364274b87 100644 --- a/src/test/ValentinaTest/tst_vspline.cpp +++ b/src/test/ValentinaTest/tst_vspline.cpp @@ -28,6 +28,7 @@ #include "tst_vspline.h" #include "../vgeometry/vspline.h" +#include "../vmisc/logging.h" #include @@ -388,6 +389,49 @@ void TST_VSpline::TestLengthByPoint() QVERIFY(qAbs(resLength - length) < ToPixel(0.5, Unit::Mm)); } +//--------------------------------------------------------------------------------------------------------------------- +void TST_VSpline::TestFlip_data() +{ + QTest::addColumn("spl"); + QTest::addColumn("axis"); + QTest::addColumn("prefix"); + + VPointF p1(1168.8582803149607, 39.999874015748034, "p1", 5.0000125984251973, 9.9999874015748045); + VPointF p4(681.33729132409951, 1815.7969526662778, "p4", 5.0000125984251973, 9.9999874015748045); + + VSpline spl(p1, p4, 229.381, 41.6325, 0.96294100000000005, 1.00054, 1); + + QLineF axis(QPointF(600, 30), QPointF(600, 1800)); + + QTest::newRow("Vertical axis") << spl << axis << "a2"; + + axis = QLineF(QPointF(600, 30), QPointF(1200, 30)); + + QTest::newRow("Horizontal axis") << spl << axis << "a2"; + + axis = QLineF(QPointF(600, 30), QPointF(600, 1800)); + axis.setAngle(45); + + QTest::newRow("Diagonal axis") << spl << axis << "a2"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VSpline::TestFlip() +{ + QFETCH(VSpline, spl); + QFETCH(QLineF, axis); + QFETCH(QString, prefix); + + const VSpline res = spl.Flip(axis, prefix); + + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); + + QCOMPARE(spl.GetLength(), res.GetLength()); + QCOMPARE(spl.GetC1Length(), res.GetC1Length()); + QCOMPARE(spl.GetC2Length(), res.GetC2Length()); +} + //--------------------------------------------------------------------------------------------------------------------- void TST_VSpline::CompareSplines(const VSpline &spl1, const VSpline &spl2) const { diff --git a/src/test/ValentinaTest/tst_vspline.h b/src/test/ValentinaTest/tst_vspline.h index 7e910baf9..776274222 100644 --- a/src/test/ValentinaTest/tst_vspline.h +++ b/src/test/ValentinaTest/tst_vspline.h @@ -51,6 +51,8 @@ private slots: void TestParametrT(); void TestLengthByPoint_data(); void TestLengthByPoint(); + void TestFlip_data(); + void TestFlip(); private: Q_DISABLE_COPY(TST_VSpline) diff --git a/src/test/ValentinaTest/tst_vsplinepath.cpp b/src/test/ValentinaTest/tst_vsplinepath.cpp index 14af3e847..586bd36e9 100644 --- a/src/test/ValentinaTest/tst_vsplinepath.cpp +++ b/src/test/ValentinaTest/tst_vsplinepath.cpp @@ -135,3 +135,64 @@ void TST_VSplinePath::TestRotation() } } +//--------------------------------------------------------------------------------------------------------------------- +void TST_VSplinePath::TestFlip_data() +{ + QTest::addColumn>("originPoints"); + QTest::addColumn("axis"); + QTest::addColumn("prefix"); + + QVector originPoints; + + { + VPointF pSpline(30, 39.999874015748034, "X", 5.0000125984251973, 9.9999874015748045); + VSplinePoint p(pSpline, 89.208600000000004, "89.2086", 269.20859999999999, "269.209", 0, "0", + 153.33618897637794, "4.05702"); + originPoints.append(p); + } + + { + VPointF pSpline(198.77104389529981, 249.18158602595835, "X", 5.0000125984251973, 9.9999874015748045); + VSplinePoint p(pSpline, 146.43199999999999, "146.432", 326.43200000000002, "326.432", + 36.387590551181106, "0.962755", 60.978897637795278, "1.6134"); + originPoints.append(p); + } + + { + VPointF pSpline(820.42771653543309, 417.95262992125987, "X", 5.0000125984251973, 9.9999874015748045); + VSplinePoint p(pSpline, 173.39500000000001, "173.395", 353.39499999999998, "353.395", + 381.23716535433073, "10.0869", 0, "0"); + originPoints.append(p); + } + + QLineF axis(QPointF(0, 0), QPointF(0, 10)); + + QTest::newRow("Vertical axis") << originPoints << axis << "a2"; + + axis = QLineF(QPointF(0, 0), QPointF(10, 0)); + + QTest::newRow("Horizontal axis") << originPoints << axis << "a2"; + + axis = QLineF(QPointF(0, 0), QPointF(0, 10)); + axis.setAngle(45); + + QTest::newRow("Diagonal axis") << originPoints << axis << "a2"; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VSplinePath::TestFlip() +{ + QFETCH(QVector, originPoints); + QFETCH(QLineF, axis); + QFETCH(QString, prefix); + + const VSplinePath splPath(originPoints); + const VSplinePath res = splPath.Flip(axis, prefix); + + const QString errorMsg = QString("The name doesn't contain the prefix '%1'.").arg(prefix); + QVERIFY2(res.name().endsWith(prefix), qUtf8Printable(errorMsg)); + + QCOMPARE(splPath.GetLength(), res.GetLength()); + QCOMPARE(splPath.CountPoints(), res.CountPoints()); +} + diff --git a/src/test/ValentinaTest/tst_vsplinepath.h b/src/test/ValentinaTest/tst_vsplinepath.h index 0baec27a2..60362ba95 100644 --- a/src/test/ValentinaTest/tst_vsplinepath.h +++ b/src/test/ValentinaTest/tst_vsplinepath.h @@ -39,6 +39,8 @@ public: private slots: void TestRotation_data(); void TestRotation(); + void TestFlip_data(); + void TestFlip(); private: Q_DISABLE_COPY(TST_VSplinePath) };