From abce5439a597336c8d00123f5d237d1719bade7d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 4 Oct 2016 17:34:37 +0300 Subject: [PATCH] Resolved issue #573. New tool: 'Move Point'. --HG-- branch : develop --- ChangeLog.txt | 1 + .../core/vtooloptionspropertybrowser.cpp | 69 ++- .../core/vtooloptionspropertybrowser.h | 3 + src/app/valentina/dialogs/dialoghistory.cpp | 3 +- src/app/valentina/mainwindow.cpp | 28 +- src/app/valentina/mainwindow.h | 1 + src/app/valentina/mainwindow.ui | 163 +++-- src/app/valentina/share/resources/cursor.qrc | 2 + .../share/resources/cursor/move_cursor.png | Bin 0 -> 553 bytes .../share/resources/cursor/move_cursor@2x.png | Bin 0 -> 1104 bytes .../valentina/share/resources/toolicon.qrc | 2 + .../share/resources/toolicon/32x32/move.png | Bin 0 -> 619 bytes .../resources/toolicon/32x32/move@2x.png | Bin 0 -> 1152 bytes .../share/resources/toolicon/svg/move.svg | 141 +++++ src/app/valentina/xml/vpattern.cpp | 56 +- src/app/valentina/xml/vpattern.h | 1 + src/libs/ifc/schema.qrc | 1 + src/libs/ifc/schema/pattern/v0.3.6.xsd | 582 ++++++++++++++++++ src/libs/ifc/xml/vabstractpattern.cpp | 17 +- src/libs/ifc/xml/vpatternconverter.cpp | 17 +- src/libs/ifc/xml/vpatternconverter.h | 5 +- src/libs/vgeometry/varc.cpp | 13 + src/libs/vgeometry/varc.h | 1 + src/libs/vgeometry/vcubicbezier.cpp | 12 + src/libs/vgeometry/vcubicbezier.h | 1 + src/libs/vgeometry/vcubicbezierpath.cpp | 13 + src/libs/vgeometry/vcubicbezierpath.h | 1 + src/libs/vgeometry/vellipticalarc.cpp | 13 + src/libs/vgeometry/vellipticalarc.h | 1 + src/libs/vgeometry/vpointf.cpp | 15 + src/libs/vgeometry/vpointf.h | 2 + src/libs/vgeometry/vspline.cpp | 14 + src/libs/vgeometry/vspline.h | 1 + src/libs/vgeometry/vsplinepath.cpp | 22 + src/libs/vgeometry/vsplinepath.h | 1 + src/libs/vmisc/def.h | 4 +- src/libs/vtools/dialogs/dialogs.pri | 9 +- src/libs/vtools/dialogs/tooldialogs.h | 1 + src/libs/vtools/dialogs/tools/dialogmove.cpp | 421 +++++++++++++ src/libs/vtools/dialogs/tools/dialogmove.h | 133 ++++ src/libs/vtools/dialogs/tools/dialogmove.ui | 450 ++++++++++++++ src/libs/vtools/tools/drawTools/drawtools.h | 1 + .../tools/drawTools/operation/vtoolmove.cpp | 480 +++++++++++++++ .../tools/drawTools/operation/vtoolmove.h | 128 ++++ src/libs/vtools/tools/tools.pri | 6 +- .../line/operation/vistoolmove.cpp | 319 ++++++++++ .../line/operation/vistoolmove.h | 86 +++ .../vtools/visualization/visualization.pri | 6 +- 48 files changed, 3153 insertions(+), 93 deletions(-) create mode 100644 src/app/valentina/share/resources/cursor/move_cursor.png create mode 100644 src/app/valentina/share/resources/cursor/move_cursor@2x.png create mode 100644 src/app/valentina/share/resources/toolicon/32x32/move.png create mode 100644 src/app/valentina/share/resources/toolicon/32x32/move@2x.png create mode 100644 src/app/valentina/share/resources/toolicon/svg/move.svg create mode 100644 src/libs/ifc/schema/pattern/v0.3.6.xsd create mode 100644 src/libs/vtools/dialogs/tools/dialogmove.cpp create mode 100644 src/libs/vtools/dialogs/tools/dialogmove.h create mode 100644 src/libs/vtools/dialogs/tools/dialogmove.ui create mode 100644 src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp create mode 100644 src/libs/vtools/tools/drawTools/operation/vtoolmove.h create mode 100644 src/libs/vtools/visualization/line/operation/vistoolmove.cpp create mode 100644 src/libs/vtools/visualization/line/operation/vistoolmove.h diff --git a/ChangeLog.txt b/ChangeLog.txt index b47e21610..845ad5487 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -40,6 +40,7 @@ - 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'. +- [#573] New tool: 'Move 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 5a618fc41..864e44aae 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) == 47, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 48, "Not all tools was used in switch."); switch (item->type()) { @@ -191,6 +191,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolFlippingByAxis::Type: ShowOptionsToolFlippingByAxis(item); break; + case VToolMove::Type: + ShowOptionsToolMove(item); + break; default: break; } @@ -205,7 +208,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) == 47, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 48, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -311,6 +314,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VToolFlippingByAxis::Type: UpdateOptionsToolFlippingByAxis(); break; + case VToolMove::Type: + UpdateOptionsToolMove(); + break; default: break; } @@ -346,7 +352,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) == 47, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 48, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -446,6 +452,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolFlippingByAxis::Type: ChangeDataToolFlippingByAxis(prop); break; + case VToolMove::Type: + ChangeDataToolMove(prop); + break; default: break; } @@ -1643,6 +1652,33 @@ void VToolOptionsPropertyBrowser::ChangeDataToolRotation(VProperty *property) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolMove(VProperty *property) +{ + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolMove *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 38: // AttrSuffix + SetOperationSuffix(value.toString()); + break; + case 5: // AttrAngle + i->SetFormulaAngle(value.value()); + break; + case 4: // AttrLength + i->SetFormulaLength(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<GetFormulaAngle(), AttrAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolMove(QGraphicsItem *item) +{ + VToolMove *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool move")); + + AddPropertyOperationSuffix(i, tr("Suffix")); + AddPropertyFormula(tr("Angle"), i->GetFormulaAngle(), AttrAngle); + AddPropertyFormula(tr("Length"), i->GetFormulaLength(), AttrLength); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolFlippingByLine(QGraphicsItem *item) { @@ -2558,6 +2606,21 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolRotation() idToProperty[AttrAngle]->setValue(valueAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolMove() +{ + VToolMove *i = qgraphicsitem_cast(currentItem); + idToProperty[AttrSuffix]->setValue(i->Suffix()); + + QVariant valueAngle; + valueAngle.setValue(i->GetFormulaAngle()); + idToProperty[AttrAngle]->setValue(valueAngle); + + QVariant valueLength; + valueLength.setValue(i->GetFormulaLength()); + idToProperty[AttrLength]->setValue(valueLength); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolFlippingByLine() { diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index f23185bd2..59f59a200 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -158,6 +158,7 @@ private: void ChangeDataToolLineIntersectAxis(VPE::VProperty *property); void ChangeDataToolCurveIntersectAxis(VPE::VProperty *property); void ChangeDataToolRotation(VPE::VProperty *property); + void ChangeDataToolMove(VPE::VProperty *property); void ChangeDataToolFlippingByLine(VPE::VProperty *property); void ChangeDataToolFlippingByAxis(VPE::VProperty *property); @@ -191,6 +192,7 @@ private: void ShowOptionsToolLineIntersectAxis(QGraphicsItem *item); void ShowOptionsToolCurveIntersectAxis(QGraphicsItem *item); void ShowOptionsToolRotation(QGraphicsItem *item); + void ShowOptionsToolMove(QGraphicsItem *item); void ShowOptionsToolFlippingByLine(QGraphicsItem *item); void ShowOptionsToolFlippingByAxis(QGraphicsItem *item); @@ -224,6 +226,7 @@ private: void UpdateOptionsToolLineIntersectAxis(); void UpdateOptionsToolCurveIntersectAxis(); void UpdateOptionsToolRotation(); + void UpdateOptionsToolMove(); void UpdateOptionsToolFlippingByLine(); void UpdateOptionsToolFlippingByAxis(); }; diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index c73d7fb19..3fd144b6b 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) == 47, "Not all tools was used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 48, "Not all tools was used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -389,6 +389,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::Rotation: case Tool::FlippingByLine: case Tool::FlippingByAxis: + case Tool::Move: return QString(); } } diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index a45d2ab8f..07a7c5add 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1058,7 +1058,18 @@ void MainWindow::ToolFlippingByAxis(bool checked) ":/cursor/flipping_axis_cursor.png", tr("Select one or more objects, Enter - confirm selection"), &MainWindow::ClosedDialogWithApply, - &MainWindow::ApplyDialog); + &MainWindow::ApplyDialog); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolMove(bool checked) +{ + ToolSelectOperationObjects(); + SetToolButtonWithApply(checked, Tool::Move, + ":/cursor/move_cursor.png", + tr("Select one or more objects, Enter - confirm selection"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- @@ -1732,6 +1743,7 @@ void MainWindow::InitToolButtons() 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->toolButtonMove, &QToolButton::clicked, this, &MainWindow::ToolMove); connect(ui->toolButtonMidpoint, &QToolButton::clicked, this, &MainWindow::ToolMidpoint); connect(ui->toolButtonLayoutExportAs, &QToolButton::clicked, this, &MainWindow::ExportLayoutAs); } @@ -1761,7 +1773,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) == 47, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 48, "Not all tools was handled."); qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; @@ -1907,6 +1919,9 @@ void MainWindow::CancelTool() case Tool::FlippingByAxis: ui->toolButtonFlippingByAxis->setChecked(false); break; + case Tool::Move: + ui->toolButtonMove->setChecked(false); + break; } // Crash: using CRTL+Z while using line tool. @@ -2956,7 +2971,7 @@ void MainWindow::SetEnableTool(bool enable) } // 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."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 48, "Not all tools were handled."); //Drawing Tools ui->toolButtonEndLine->setEnabled(drawTools); @@ -2993,6 +3008,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonRotation->setEnabled(drawTools); ui->toolButtonFlippingByLine->setEnabled(drawTools); ui->toolButtonFlippingByAxis->setEnabled(drawTools); + ui->toolButtonMove->setEnabled(drawTools); ui->toolButtonMidpoint->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -3275,7 +3291,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) == 47, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 48, "Not all tools was handled."); if (currentTool == lastUsedTool) { @@ -3449,6 +3465,10 @@ void MainWindow::LastUsedTool() ui->toolButtonFlippingByAxis->setChecked(true); ToolFlippingByAxis(true); break; + case Tool::Move: + ui->toolButtonMove->setChecked(true); + ToolMove(true); + break; } } diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 3361c8ecd..198687e40 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -141,6 +141,7 @@ private slots: void ToolRotation(bool checked); void ToolFlippingByLine(bool checked); void ToolFlippingByAxis(bool checked); + void ToolMove(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 aa0b01eed..27f576e5e 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 @@ -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 - 130 + 117 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 - 130 + 117 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 - 130 + 117 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 @@ -1068,7 +1068,7 @@ - + :/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 @@ -1168,7 +1168,7 @@ ... - + :/toolicon/32x32/flipping_line.png:/toolicon/32x32/flipping_line.png @@ -1194,7 +1194,7 @@ ... - + :/toolicon/32x32/flipping_axis.png:/toolicon/32x32/flipping_axis.png @@ -1208,6 +1208,32 @@ + + + + false + + + Move objects + + + ... + + + + :/toolicon/32x32/move.png:/toolicon/32x32/move.png + + + + 32 + 32 + + + + true + + + @@ -1215,7 +1241,7 @@ 0 0 - 130 + 117 104 @@ -1229,7 +1255,7 @@ Tools for creating details. - + :/icon/16x16/toolsectiondetail.png:/icon/16x16/toolsectiondetail.png @@ -1251,7 +1277,7 @@ ... - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -1277,7 +1303,7 @@ ... - + :/toolicon/32x32/new_detail.png:/toolicon/32x32/new_detail.png @@ -1303,7 +1329,7 @@ ... - + :/toolicon/32x32/union.png:/toolicon/32x32/union.png @@ -1329,7 +1355,7 @@ - + :/icon/16x16/toolsectionlayout.png:/icon/16x16/toolsectionlayout.png @@ -1380,7 +1406,7 @@ ... - + :/icon/32x32/export_to_picture_document.png:/icon/32x32/export_to_picture_document.png @@ -1826,7 +1852,7 @@ false - + :/icon/32x32/draw.png:/icon/32x32/draw.png @@ -1850,7 +1876,7 @@ false - + :/icon/32x32/kontur.png:/icon/32x32/kontur.png @@ -1874,7 +1900,7 @@ true - + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png @@ -1892,7 +1918,7 @@ false - + :/icon/32x32/new_draw.png:/icon/32x32/new_draw.png @@ -1913,7 +1939,7 @@ false - + :/icon/32x32/option_draw.png:/icon/32x32/option_draw.png @@ -1937,7 +1963,7 @@ false - + :/icon/32x32/table.png:/icon/32x32/table.png @@ -1961,7 +1987,7 @@ false - + :/icon/32x32/history.png:/icon/32x32/history.png @@ -1982,7 +2008,7 @@ false - + :/icon/32x32/layout.png:/icon/32x32/layout.png @@ -2247,7 +2273,7 @@ false - + :/icon/32x32/pdf.png:/icon/32x32/pdf.png @@ -2337,7 +2363,7 @@ false - + :/icon/32x32/export_to_picture_document.png:/icon/32x32/export_to_picture_document.png @@ -2414,7 +2440,7 @@ false - + :/icon/32x32/syncM.png:/icon/32x32/syncM.png @@ -2453,6 +2479,9 @@
vmaingraphicsview.h
- + + + + diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index 0e75306b5..b2631218b 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -74,5 +74,7 @@ cursor/flipping_line_cursor.png cursor/flipping_axis_cursor.png cursor/flipping_axis_cursor@2x.png + cursor/move_cursor.png + cursor/move_cursor@2x.png diff --git a/src/app/valentina/share/resources/cursor/move_cursor.png b/src/app/valentina/share/resources/cursor/move_cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..a02bd274b8eb528260c3acf9e470c7c02fdce196 GIT binary patch literal 553 zcmV+^0@nSBP)3W7&1%)K21f;kPC6@%gUpd*tvx zSw3O4O+dhpHW5cd#CP0n6VMtW4`>DPw*Z(sViaJmh%&(35P!x1=7Km4&^V$Bpi#tO zML=VSI)FwHbpbO+{GI?X5hBo;C7>1};bFq(0o#3gvjS8?1iAyZ5<)^4u--lX`&2oP zjZ+XI@Fo4wVK09#e&Ot>B5_QgsR-G|RV-i$%eaQixblF_H}nGiMPB9$2ToqrLwv>c zip|s9zy~BF&UwGAs0c`~g-bP?r@4ryI4GR=R{o&w$vW_JxPl&bCj{(cMSM2W9LYTc z#iW<3kJsWooHQLglf7l_U{l;_=f(jNJXbO(YBYZ=o2+}diF@MeOBePLkEUpx=80^k z?BMqB`z~IYZgFF?ghjj^Hs8mc!Z8<`YQ8T1soBLEUdUG7corNV;~RB~%eG;i1aaG@ r`BtZRnyr=xycfsyJ8}CZRg3=t;BWrd@X=&$00000NkvXXu0mjftkCa= literal 0 HcmV?d00001 diff --git a/src/app/valentina/share/resources/cursor/move_cursor@2x.png b/src/app/valentina/share/resources/cursor/move_cursor@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..9feb3e5d8cc17584ac35cd187ccc14e6ac568274 GIT binary patch literal 1104 zcmV-W1h4yvP)QSX3$~RdJ32c;MN&V$GNKZaRmUkz^|v^^r)I5$ zk!uO(trakGEg>dgq$E_u1&oY@Wz7YQgoKR*484RU8w(g}35(hjFtifV2pCEU3(^S~ zItdl&1q_vhP6Z5&gn69{7zzpJbSGfoC1fFBpe6h(8vz3=VNP}e22w)S0tQaPKe87v zP!eY4BVb@8XL30fm?Fm;413T0*Y`6js8YdMBWe63*(afWk@Whk)EAB$N`y z>PM;7xqoy~i6TlUEpS(b=?Z5n%v3lw$H8V7{NCeA=PF^Ief3HwtBzWQj}ykqS!I+V z2QV!I2??bVM{xPNpGvrOfqgLnNw*niKvojUxU$)AWwsYp0NF@Lgf1PUmV_Db|8Yit z$AC=7ghg&xV0PUYkW@I8u(il7puqvW)#kY+T!_868iy}pXN{-uy)fZBixVXtE3q^l zNu+23szSk6GlA{cfnC^->xKS4RsYSA1q3);A@@p9KTzi9uipT`qv z63>8bxCPH+M)NH_jpLXNLf`eYD_|b?bz7S*7{g8YQu8v_@M5b(IvoUm!#(({{qkl` z8IR(|7Uv|w4Nb+*THpC^aaGzxGiDqQ+juWS6%VCNyp@1y?CiGmT{0%b_p!IunzehJ zmT*Vf41S6voZxkA?Yj8gu?^3NuV60=1KtrUTm9y>?jlisj3oY?_#?BIl<~Cq;%yDD zVz&^Bd{_T|MhKEpv0A{Q4*F0IlyRr{!fg$o3UNV$XN6X9Qiupsak`%HTs_l%vjvZf zFWFUvuDO0Q_io_{^&TeEX84*g(jV@)$l3CM_)K+8=<}CFt|{RWA#~o-n_}j}I6e@s z{O978Z!n4L@-AT3jN@9|j+=!6Z9k4%33;n{Q|rnPBzy3JFbK~HZ+q_x@AXqSDm>TU zFocya<7M%U+HVWN*Clw;kp6pRm*%U|%eX(UjQbtjG-%B5#3<=9eFO%>%#Nf_-9;R+%2{aTm+?PQ*^E&c<0 WMvF22)ScA;0000toolicon/32x32/flipping_line.png toolicon/32x32/flipping_axis.png toolicon/32x32/flipping_axis@2x.png + toolicon/32x32/move.png + toolicon/32x32/move@2x.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/move.png b/src/app/valentina/share/resources/toolicon/32x32/move.png new file mode 100644 index 0000000000000000000000000000000000000000..d2526aaae69c0d1e65b2dc4d77a46e38b6f27ea9 GIT binary patch literal 619 zcmV-x0+juUP)I6+sxr;pd!~i?LBi3N`V97c4A95D^;-QA7+D zf~8hsVPhj&3HJU8X#`V=1dKuOg5aglND#qBK~NDDB$AM9B8IWp4IGc>Y}TBe^TM#~ zeBbbUXXl$4mNsabzJ%d~?+G&r_h#AK4z@sV!rO#U*X9=372Uubmm0uBLYU`vHMW5& z`gPn8uw)?qt#W^D(yWx(|f@+al&`J!K-3y(5j|9_Z;FL}YDMfeM+aUGw_G_Vq_ z##y{TDA2BzZJ<_{3m7;b3w{&}1q=+ufFHzc0eHZ^vf+C$RS+I9P$qmcKIXv2@T%s0 z5uIhhH{e|k{Fd}w8LH{~Ru+6C-siw?qN67NW!67g2D}e%a^QEQCuOZpWwG&A;cKO{ zXa*mbUM}^j;5CL@fp_A;GVq?9@yBto6$3rE-voYF=Gx`79X$X5002ovPDHLk FV1i@f4pjgE literal 0 HcmV?d00001 diff --git a/src/app/valentina/share/resources/toolicon/32x32/move@2x.png b/src/app/valentina/share/resources/toolicon/32x32/move@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..0b2eec37f492af502ec07aca7fa7041fc109dbe9 GIT binary patch literal 1152 zcmV-`1b_R9P)OV8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H11N})vK~#90-P+BoRaF?r@y|WCn_~82@2Qn$5sFPB2O3#HC`NAs zL!A^vV52f};G|av{R7QdB#vKLC zvW%sJ@C3-%h<^&2ZJWX8W%yGIO&)79)?*gaLopO1OCVO*Pk`uC!?zB_OiWK3(ZW{3xIeMW{u_+p5y)7jfTN!xq7C7d$3LUPsME&X$oc$Ucpi21YmA;QsS6~hw-U& z;!k0uN)f48j`zd|;Bbr+bsmQH%5#BOeu*)zD*!XGU77$y?ErNIU<6yF`*I(OF|IlQ zBl2zW{)A)p%`4Ert9U5!xKU3)RW$IXa&mxm73v6L2(K$I3tV2ElrUZvF76=qPtxbc z>ZBCsIpN~JlUIb+Ow#X6d26b%QMmYBxZ?CU4eU8bza!O1Db6P0;&+-@DO!7uzPn1+ z5yUgniicr*-=Y7zCF%%bz5H|*BK}Lv>N55t9c*4JLqsU6@wYJXdrW?DX#_uwvwJDE zh)~uFullrq@FrvYQ?Ndnf(RbKU&6%i*1LG}Z$bNxa9d|uOb)a(Y7&e zjdMSa#lmZRyK!aUyuS9=!!jZaY zh<{)EW}E9o1Aj!0aWsV^bPj6$`p2CqjnTMwEvwdIQ&l%72ii;nU z7bXUR2DT~|fTwHmv_yvSEKce!{II~A+5N&CY?kNw$K;}a!v}Z@7uM%mdj17AOZA*9 Swl}Z<0000 + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 5a93aa209..ce88bb98b 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2604,6 +2604,51 @@ void VPattern::ParseToolFlippingByAxis(VMainGraphicsScene *scene, QDomElement &d } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParseToolMove(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 QString angle = GetParametrString(domElement, AttrAngle, "0"); + QString a = angle;//need for saving fixed formula; + const QString length = GetParametrString(domElement, AttrLength, "0"); + QString len = length;//need for saving fixed formula; + const QString suffix = GetParametrString(domElement, AttrSuffix, ""); + + QVector source; + QVector destination; + VAbstractOperation::ExtractData(this, domElement, source, destination); + + VToolMove::Create(id, a, len, suffix, source, destination, scene, this, data, parse, Source::FromFile); + //Rewrite attribute formula. Need for situation when we have wrong formula. + if (a != angle || len != length) + { + SetAttribute(domElement, AttrAngle, a); + SetAttribute(domElement, AttrLength, len); + modified = true; + haveLiteChange(); + } + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating operation of moving"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + catch (qmu::QmuParserError &e) + { + VExceptionObjectError excep(tr("Error creating or updating operation of moving"), domElement); + excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr())); + throw excep; + } +} + //--------------------------------------------------------------------------------------------------------------------- qreal VPattern::EvalFormula(VContainer *data, const QString &formula, bool *ok) const { @@ -2856,7 +2901,8 @@ void VPattern::ParseOperationElement(VMainGraphicsScene *scene, QDomElement &dom const QStringList opers = QStringList() << VToolRotation::ToolType /*0*/ << VToolFlippingByLine::ToolType /*1*/ - << VToolFlippingByAxis::ToolType; /*2*/ + << VToolFlippingByAxis::ToolType /*2*/ + << VToolMove::ToolType; /*3*/ switch (opers.indexOf(type)) { @@ -2869,6 +2915,9 @@ void VPattern::ParseOperationElement(VMainGraphicsScene *scene, QDomElement &dom case 2: //VToolFlippingByAxis::ToolType ParseToolFlippingByAxis(scene, domElement, parse); break; + case 3: //VToolMove::ToolType + ParseToolMove(scene, domElement, parse); + break; default: VException e(tr("Unknown operation type '%1'.").arg(type)); throw e; @@ -3375,7 +3424,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) == 47, "Not all tools was used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 48, "Not all tools was used."); QRectF rec; @@ -3493,6 +3542,9 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::FlippingByAxis: rec = ToolBoundingRect(rec, tool.getId()); break; + case Tool::Move: + 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 a67d9c76e..b21f86751 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -196,6 +196,7 @@ private: 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); + void ParseToolMove(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); qreal EvalFormula(VContainer *data, const QString &formula, bool *ok) const; diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 3f4d890f7..6a0edbcae 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -19,6 +19,7 @@ schema/pattern/v0.3.3.xsd schema/pattern/v0.3.4.xsd schema/pattern/v0.3.5.xsd + schema/pattern/v0.3.6.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd 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..8c062ebb1 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.3.6.xsd @@ -0,0 +1,582 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 83b85ff4a..77a6dae99 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1372,7 +1372,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) == 47); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 48); QStringList expressions; const QDomNodeList list = elementsByTagName(TagPoint); @@ -1443,7 +1443,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) == 47); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 48); QStringList expressions; const QDomNodeList list = elementsByTagName(TagArc); @@ -1504,7 +1504,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) == 47); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 48); QStringList expressions; const QDomNodeList list = elementsByTagName(AttrPathPoint); @@ -1570,7 +1570,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) == 47); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 48); QStringList expressions; const QDomNodeList list = elementsByTagName(TagOperation); @@ -1587,6 +1587,15 @@ QStringList VAbstractPattern::ListOperationExpressions() const { Q_UNUSED(e) } + + try + { + expressions.append(GetParametrString(dom, AttrLength)); + } + catch (VExceptionEmptyParameter &e) + { + Q_UNUSED(e) + } } return expressions; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index dcd2a6eeb..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); @@ -256,6 +258,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000305), fileName); V_FALLTHROUGH case (0x000305): + ToV0_3_6(); + ValidateXML(XSDSchema(0x000306), fileName); + V_FALLTHROUGH + case (0x000306): break; default: break; @@ -423,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 8616f7079..6420a1c2b 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -145,6 +145,19 @@ VArc VArc::Flip(const QLineF &axis, const QString &prefix) const return arc; } +//--------------------------------------------------------------------------------------------------------------------- +VArc VArc::Move(qreal length, qreal angle, const QString &prefix) const +{ + const VPointF center = GetCenter().Move(length, angle); + + const QPointF p1 = VPointF::MovePF(GetP1(), length, angle); + const QPointF p2 = VPointF::MovePF(GetP2(), length, angle); + + VArc arc(center, GetRadius(), QLineF(center, p1).angle(), QLineF(center, p2).angle()); + arc.setName(name() + prefix); + return arc; +} + //--------------------------------------------------------------------------------------------------------------------- VArc::~VArc() {} diff --git a/src/libs/vgeometry/varc.h b/src/libs/vgeometry/varc.h index 3a3c4d0c7..bd7c276e2 100644 --- a/src/libs/vgeometry/varc.h +++ b/src/libs/vgeometry/varc.h @@ -64,6 +64,7 @@ public: 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; + VArc Move(qreal length, qreal angle, 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 3f710e339..551db1f03 100644 --- a/src/libs/vgeometry/vcubicbezier.cpp +++ b/src/libs/vgeometry/vcubicbezier.cpp @@ -90,6 +90,18 @@ VCubicBezier VCubicBezier::Flip(const QLineF &axis, const QString &prefix) const return curve; } +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezier VCubicBezier::Move(qreal length, qreal angle, const QString &prefix) const +{ + const VPointF p1 = GetP1().Move(length, angle); + const VPointF p2 = GetP2().Move(length, angle); + const VPointF p3 = GetP3().Move(length, angle); + const VPointF p4 = GetP4().Move(length, angle); + 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 3e5b138ab..71e952f8a 100644 --- a/src/libs/vgeometry/vcubicbezier.h +++ b/src/libs/vgeometry/vcubicbezier.h @@ -54,6 +54,7 @@ public: 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; + VCubicBezier Move(qreal length, qreal angle, 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 208c38206..a187a866f 100644 --- a/src/libs/vgeometry/vcubicbezierpath.cpp +++ b/src/libs/vgeometry/vcubicbezierpath.cpp @@ -104,6 +104,19 @@ VCubicBezierPath VCubicBezierPath::Flip(const QLineF &axis, const QString &prefi return curve; } +//--------------------------------------------------------------------------------------------------------------------- +VCubicBezierPath VCubicBezierPath::Move(qreal length, qreal angle, const QString &prefix) const +{ + const QVector points = GetCubicPath(); + VCubicBezierPath curve; + for(int i=0; i < points.size(); ++i) + { + curve.append(points.at(i).Move(length, angle)); + } + curve.setName(name() + prefix); + return curve; +} + //--------------------------------------------------------------------------------------------------------------------- VCubicBezierPath::~VCubicBezierPath() { diff --git a/src/libs/vgeometry/vcubicbezierpath.h b/src/libs/vgeometry/vcubicbezierpath.h index d483264f1..93fda4cb7 100644 --- a/src/libs/vgeometry/vcubicbezierpath.h +++ b/src/libs/vgeometry/vcubicbezierpath.h @@ -57,6 +57,7 @@ public: 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; + VCubicBezierPath Move(qreal length, qreal angle, 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 81798cc81..09b5d790f 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -148,6 +148,19 @@ VEllipticalArc VEllipticalArc::Flip(const QLineF &axis, const QString &prefix) c return elArc; } +//--------------------------------------------------------------------------------------------------------------------- +VEllipticalArc VEllipticalArc::Move(qreal length, qreal angle, const QString &prefix) const +{ + const VPointF center = GetCenter().Move(length, angle); + const QPointF p1 = VPointF::MovePF(GetP1(), length, angle); + const QPointF p2 = VPointF::MovePF(GetP2(), length, angle); + 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); + return elArc; +} + //--------------------------------------------------------------------------------------------------------------------- VEllipticalArc::~VEllipticalArc() {} diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h index b77372efd..1f15025e4 100644 --- a/src/libs/vgeometry/vellipticalarc.h +++ b/src/libs/vgeometry/vellipticalarc.h @@ -64,6 +64,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; + VEllipticalArc Move(qreal length, qreal angle, const QString &prefix = QString()) const; virtual ~VEllipticalArc() Q_DECL_OVERRIDE; diff --git a/src/libs/vgeometry/vpointf.cpp b/src/libs/vgeometry/vpointf.cpp index fcb3f529d..12de7bc1c 100644 --- a/src/libs/vgeometry/vpointf.cpp +++ b/src/libs/vgeometry/vpointf.cpp @@ -121,6 +121,13 @@ VPointF VPointF::Flip(const QLineF &axis, const QString &prefix) const return VPointF(p, name() + prefix, mx(), my()); } +//--------------------------------------------------------------------------------------------------------------------- +VPointF VPointF::Move(qreal length, qreal angle, const QString &prefix) const +{ + const QPointF p = MovePF(toQPointF(), length, angle); + return VPointF(p, name() + prefix, mx(), my()); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief mx return offset name respect to x @@ -221,3 +228,11 @@ QPointF VPointF::FlipPF(const QLineF &axis, const QPointF &point) const QTransform matrix = FlippingMatrix(axis); return matrix.map(point); } + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VPointF::MovePF(const QPointF &originPoint, qreal length, qreal angle) +{ + QLineF line(originPoint.x(), originPoint.y(), originPoint.x() + length, originPoint.y()); + line.setAngle(angle); + return line.p2(); +} diff --git a/src/libs/vgeometry/vpointf.h b/src/libs/vgeometry/vpointf.h index 3eb4a25ee..79a67d927 100644 --- a/src/libs/vgeometry/vpointf.h +++ b/src/libs/vgeometry/vpointf.h @@ -66,6 +66,7 @@ public: 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; + VPointF Move(qreal length, qreal angle, const QString &prefix = QString()) const; qreal mx() const; qreal my() const; void setMx(qreal mx); @@ -78,6 +79,7 @@ public: static QPointF RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees); static QPointF FlipPF(const QLineF &axis, const QPointF &point); + static QPointF MovePF(const QPointF &originPoint, qreal length, qreal angle); private: QSharedDataPointer d; }; diff --git a/src/libs/vgeometry/vspline.cpp b/src/libs/vgeometry/vspline.cpp index b9fceff03..b1be7ec0e 100644 --- a/src/libs/vgeometry/vspline.cpp +++ b/src/libs/vgeometry/vspline.cpp @@ -140,6 +140,20 @@ VSpline VSpline::Flip(const QLineF &axis, const QString &prefix) const return spl; } +//--------------------------------------------------------------------------------------------------------------------- +VSpline VSpline::Move(qreal length, qreal angle, const QString &prefix) const +{ + const VPointF p1 = GetP1().Move(length, angle); + const VPointF p4 = GetP4().Move(length, angle); + + const QPointF p2 = VPointF::MovePF(GetP2(), length, angle); + const QPointF p3 = VPointF::MovePF(GetP3(), length, angle); + + 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 325aea0ff..d5d711d49 100644 --- a/src/libs/vgeometry/vspline.h +++ b/src/libs/vgeometry/vspline.h @@ -64,6 +64,7 @@ public: 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; + VSpline Move(qreal length, qreal angle, 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 e21938d11..7dcaf404c 100644 --- a/src/libs/vgeometry/vsplinepath.cpp +++ b/src/libs/vgeometry/vsplinepath.cpp @@ -144,6 +144,28 @@ VSplinePath VSplinePath::Flip(const QLineF &axis, const QString &prefix) const return splPath; } +//--------------------------------------------------------------------------------------------------------------------- +VSplinePath VSplinePath::Move(qreal length, qreal angle, const QString &prefix) const +{ + QVector newPoints(CountPoints()); + for (qint32 i = 1; i <= CountSubSpl(); ++i) + { + const VSpline spl = GetSpline(i).Move(length, angle); + + 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 da3b73c49..2c9545891 100644 --- a/src/libs/vgeometry/vsplinepath.h +++ b/src/libs/vgeometry/vsplinepath.h @@ -62,6 +62,7 @@ public: 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; + VSplinePath Move(qreal length, qreal angle, 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 80a92c9d1..1cab5c9c9 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -111,6 +111,7 @@ enum class Tool : ToolVisHolderType Rotation, FlippingByLine, FlippingByAxis, + Move, Midpoint, LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; @@ -154,7 +155,8 @@ enum class Vis : ToolVisHolderType ToolTrueDarts, ToolRotation, ToolFlippingByLine, - ToolFlippingByAxis + ToolFlippingByAxis, + ToolMove }; enum class VarType : char { Measurement, Increment, LineLength, CurveLength, CurveCLength, LineAngle, CurveAngle, diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index 167b8580d..343b5a64c 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -40,7 +40,8 @@ HEADERS += \ $$PWD/tools/dialoggroup.h \ $$PWD/tools/dialogrotation.h \ $$PWD/tools/dialogflippingbyline.h \ - $$PWD/tools/dialogflippingbyaxis.h + $$PWD/tools/dialogflippingbyaxis.h \ + $$PWD/tools/dialogmove.h SOURCES += \ @@ -81,7 +82,8 @@ SOURCES += \ $$PWD/tools/dialoggroup.cpp \ $$PWD/tools/dialogrotation.cpp \ $$PWD/tools/dialogflippingbyline.cpp \ - $$PWD/tools/dialogflippingbyaxis.cpp + $$PWD/tools/dialogflippingbyaxis.cpp \ + $$PWD/tools/dialogmove.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -120,4 +122,5 @@ FORMS += \ $$PWD/tools/dialoggroup.ui \ $$PWD/tools/dialogrotation.ui \ $$PWD/tools/dialogflippingbyline.ui \ - $$PWD/tools/dialogflippingbyaxis.ui + $$PWD/tools/dialogflippingbyaxis.ui \ + $$PWD/tools/dialogmove.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index 7a884ce90..23f99447c 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -64,6 +64,7 @@ #include "tools/dialogrotation.h" #include "tools/dialogflippingbyline.h" #include "tools/dialogflippingbyaxis.h" +#include "tools/dialogmove.h" #include "support/dialogeditwrongformula.h" #include "support/dialogundo.h" diff --git a/src/libs/vtools/dialogs/tools/dialogmove.cpp b/src/libs/vtools/dialogs/tools/dialogmove.cpp new file mode 100644 index 000000000..0a1960da8 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogmove.cpp @@ -0,0 +1,421 @@ +/************************************************************************ + ** + ** @file dialogmove.cpp + ** @author Roman Telezhynskyi + ** @date 30 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 "dialogmove.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../visualization/visualization.h" +#include "../../visualization/line/operation/vistoolmove.h" +#include "../ifc/xml/vabstractpattern.h" +#include "../ifc/xml/vdomdocument.h" +#include "../qmuparser/qmudef.h" +#include "../support/dialogeditwrongformula.h" +#include "../vgeometry/vpointf.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vcommonsettings.h" +#include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/vtranslatevars.h" +#include "../vwidgets/vabstractmainwindow.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "ui_dialogmove.h" + +class QCloseEvent; +class QWidget; + +//--------------------------------------------------------------------------------------------------------------------- +DialogMove::DialogMove(const VContainer *data, quint32 toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogMove), + flagAngle(false), + flagLength(false), + timerAngle(nullptr), + timerLength(nullptr), + formulaAngle(), + formulaLength(), + formulaBaseHeightAngle(0), + formulaBaseHeightLength(0), + objects(), + stage1(true), + m_suffix() +{ + ui->setupUi(this); + + this->formulaBaseHeightAngle = ui->plainTextEditAngle->height(); + ui->plainTextEditAngle->installEventFilter(this); + + this->formulaBaseHeightLength = ui->plainTextEditLength->height(); + ui->plainTextEditLength->installEventFilter(this); + + ui->lineEditSuffix->setText(qApp->getCurrentDocument()->GenerateSuffix()); + + timerAngle = new QTimer(this); + connect(timerAngle, &QTimer::timeout, this, &DialogMove::EvalAngle); + + timerLength = new QTimer(this); + connect(timerLength, &QTimer::timeout, this, &DialogMove::EvalLength); + + InitOkCancelApply(ui); + + flagName = true; + CheckState(); + + connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogMove::SuffixChanged); + connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogMove::FXAngle); + connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogMove::FXLength); + connect(ui->plainTextEditAngle, &QPlainTextEdit::textChanged, this, &DialogMove::AngleChanged); + connect(ui->plainTextEditLength, &QPlainTextEdit::textChanged, this, &DialogMove::LengthChanged); + connect(ui->pushButtonGrowAngle, &QPushButton::clicked, this, &DialogMove::DeployAngleTextEdit); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogMove::DeployLengthTextEdit); + + vis = new VisToolMove(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogMove::~DialogMove() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogMove::GetAngle() const +{ + return qApp->TrVars()->TryFormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::SetAngle(const QString &value) +{ + formulaAngle = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formulaAngle.length() > 80) + { + this->DeployAngleTextEdit(); + } + ui->plainTextEditAngle->setPlainText(formulaAngle); + + VisToolMove *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetAngle(formulaAngle); + + MoveCursorToEnd(ui->plainTextEditAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogMove::GetLength() const +{ + return qApp->TrVars()->TryFormulaFromUser(formulaLength, qApp->Settings()->GetOsSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::SetLength(const QString &value) +{ + formulaLength = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formulaLength.length() > 80) + { + this->DeployLengthTextEdit(); + } + ui->plainTextEditLength->setPlainText(formulaLength); + + VisToolMove *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetLength(formulaLength); + + MoveCursorToEnd(ui->plainTextEditLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogMove::GetSuffix() const +{ + return m_suffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::SetSuffix(const QString &value) +{ + m_suffix = value; + ui->lineEditSuffix->setText(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogMove::GetObjects() const +{ + return objects.toVector(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::ShowDialog(bool click) +{ + if (stage1 && not click) + { + if (objects.isEmpty()) + { + return; + } + + stage1 = false; + prepare = true; + + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + scene->clearSelection(); + + VisToolMove *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetObjects(objects.toVector()); + operation->VisualMode(); + + VAbstractMainWindow *window = qobject_cast(qApp->getMainWindow()); + SCASSERT(window != nullptr); + connect(operation, &VisToolMove::ToolTip, window, &VAbstractMainWindow::ShowToolTip); + + scene->ToggleArcSelection(false); + scene->ToggleSplineSelection(false); + scene->ToggleSplinePathSelection(false); + + scene->ToggleArcHover(false); + scene->ToggleSplineHover(false); + scene->ToggleSplinePathHover(false); + } + else if (not stage1 && prepare && click) + { + VisToolMove *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + if (operation->LengthValue() > 0) + { + SetAngle(operation->Angle());//Show in dialog angle that a user choose + SetLength(operation->Length()); + setModal(true); + emit ToolTip(""); + timerAngle->start(); + timerLength->start(); + show(); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::ChosenObject(quint32 id, const SceneObject &type) +{ + Q_UNUSED(id); + Q_UNUSED(type); + // do nothing +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::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 DialogMove::DeployAngleTextEdit() +{ + DeployFormula(ui->plainTextEditAngle, ui->pushButtonGrowAngle, formulaBaseHeightAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::DeployLengthTextEdit() +{ + DeployFormula(ui->plainTextEditLength, ui->pushButtonGrowLength, formulaBaseHeightLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::AngleChanged() +{ + labelEditFormula = ui->labelEditAngle; + labelResultCalculation = ui->labelResultAngle; + ValFormulaChanged(flagAngle, ui->plainTextEditAngle, timerAngle, degreeSymbol); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::LengthChanged() +{ + labelEditFormula = ui->labelEditLength; + labelResultCalculation = ui->labelResultLength; + ValFormulaChanged(flagLength, ui->plainTextEditLength, timerLength, degreeSymbol); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::FXAngle() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit angle")); + dialog->SetFormula(GetAngle()); + dialog->setPostfix(degreeSymbol); + if (dialog->exec() == QDialog::Accepted) + { + SetAngle(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::FXLength() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit length")); + dialog->SetFormula(GetLength()); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + SetLength(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::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 DialogMove::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(flagAngle && flagLength && flagName); + SCASSERT(bApply != nullptr); + bApply->setEnabled(bOk->isEnabled()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::SaveData() +{ + m_suffix = ui->lineEditSuffix->text(); + + formulaAngle = ui->plainTextEditAngle->toPlainText(); + formulaAngle.replace("\n", " "); + + formulaLength = ui->plainTextEditLength->toPlainText(); + formulaLength.replace("\n", " "); + + VisToolMove *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + operation->SetObjects(objects.toVector()); + operation->SetAngle(formulaAngle); + operation->SetLength(formulaLength); + operation->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::closeEvent(QCloseEvent *event) +{ + ui->plainTextEditAngle->blockSignals(true); + ui->plainTextEditLength->blockSignals(true); + DialogTool::closeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::EvalAngle() +{ + labelEditFormula = ui->labelEditAngle; + Eval(ui->plainTextEditAngle->toPlainText(), flagAngle, ui->labelResultAngle, degreeSymbol, false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::EvalLength() +{ + labelEditFormula = ui->labelEditLength; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + Eval(ui->plainTextEditLength->toPlainText(), flagLength, ui->labelResultLength, postfix); +} diff --git a/src/libs/vtools/dialogs/tools/dialogmove.h b/src/libs/vtools/dialogs/tools/dialogmove.h new file mode 100644 index 000000000..9608780c6 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogmove.h @@ -0,0 +1,133 @@ +/************************************************************************ + ** + ** @file dialogmove.h + ** @author Roman Telezhynskyi + ** @date 30 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 DIALOGMOVING_H +#define DIALOGMOVING_H + +#include +#include +#include +#include +#include +#include +#include + +#include "../vmisc/def.h" +#include "dialogtool.h" + +class QCloseEvent; +class QTimer; +class QWidget; +class VContainer; + +namespace Ui +{ + class DialogMove; +} + +class DialogMove : public DialogTool +{ + Q_OBJECT + +public: + explicit DialogMove(const VContainer *data, quint32 toolId, QWidget *parent = nullptr); + virtual ~DialogMove(); + + QString GetAngle() const; + void SetAngle(const QString &value); + + QString GetLength() const; + void SetLength(const QString &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: + /** @brief DeployAngleTextEdit grow or shrink formula input */ + void DeployAngleTextEdit(); + void DeployLengthTextEdit(); + + void AngleChanged(); + void LengthChanged(); + + void FXAngle(); + void FXLength(); + + 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; + virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(DialogMove) + Ui::DialogMove *ui; + + /** @brief flagAngle true if value of angle is correct */ + bool flagAngle; + + bool flagLength; + + /** @brief timerAngle timer of check formula of angle */ + QTimer *timerAngle; + + QTimer *timerLength; + + /** @brief angle formula of angle */ + QString formulaAngle; + + QString formulaLength; + + /** @brief formulaBaseHeightAngle base height defined by dialogui */ + int formulaBaseHeightAngle; + + int formulaBaseHeightLength; + + QList objects; + + bool stage1; + + QString m_suffix; + + void EvalAngle(); + void EvalLength(); +}; + +#endif // DIALOGMOVING_H diff --git a/src/libs/vtools/dialogs/tools/dialogmove.ui b/src/libs/vtools/dialogs/tools/dialogmove.ui new file mode 100644 index 000000000..2bdf948d3 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogmove.ui @@ -0,0 +1,450 @@ + + + DialogMove + + + + 0 + 0 + 285 + 232 + + + + Dialog + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calulation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Length: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calulation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + Suffix: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogMove + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogMove + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/tools/drawTools/drawtools.h b/src/libs/vtools/tools/drawTools/drawtools.h index 6adaecdd3..01c9cce94 100644 --- a/src/libs/vtools/tools/drawTools/drawtools.h +++ b/src/libs/vtools/tools/drawTools/drawtools.h @@ -61,5 +61,6 @@ #include "operation/vtoolrotation.h" #include "operation/flipping/vtoolflippingbyline.h" #include "operation/flipping/vtoolflippingbyaxis.h" +#include "operation/vtoolmove.h" #endif // DRAWTOOLS_H diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp new file mode 100644 index 000000000..a95f9472c --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp @@ -0,0 +1,480 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 1 10, 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 "vtoolmove.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../../dialogs/tools/dialogtool.h" +#include "../../../dialogs/tools/dialogmove.h" +#include "../../../visualization/line/operation/vistoolmove.h" +#include "../../../visualization/visualization.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" +#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 VToolMove::ToolType = QStringLiteral("moving"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolMove::~VToolMove() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolMove::setDialog() +{ + SCASSERT(dialog != nullptr); + DialogMove *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + dialogTool->SetAngle(formulaAngle); + dialogTool->SetLength(formulaLength); + dialogTool->SetSuffix(suffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolMove *VToolMove::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogMove *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + QString angle = dialogTool->GetAngle(); + QString length = dialogTool->GetLength(); + const QString suffix = dialogTool->GetSuffix(); + const QVector source = dialogTool->GetObjects(); + VToolMove* operation = Create(0, angle, length, suffix, source, QVector(), scene, doc, data, + Document::FullParse, Source::FromGui); + if (operation != nullptr) + { + operation->dialog = dialogTool; + } + return operation; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolMove *VToolMove::Create(quint32 _id, QString &formulaAngle, QString &formulaLength, + const QString &suffix, const QVector &source, + const QVector &destination, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation) +{ + qreal calcAngle = 0; + qreal calcLength = 0; + + calcAngle = CheckFormula(_id, formulaAngle, data); + calcLength = qApp->toPixel(CheckFormula(_id, formulaLength, data)); + + QVector dest = destination; + + quint32 id = _id; + 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, calcAngle, calcLength, suffix, data)); + break; + case GOType::Arc: + dest.append(CreateArc(id, idObject, calcAngle, calcLength, suffix, data)); + break; + case GOType::EllipticalArc: + //dest.append(CreateItem(id, idObject, angle, suffix)); + break; + case GOType::Spline: + dest.append(CreateCurve(id, idObject, calcAngle, calcLength, suffix, data)); + break; + case GOType::SplinePath: + dest.append(CreateCurveWithSegments(id, idObject, calcAngle, calcLength, suffix, + data)); + break; + case GOType::CubicBezier: + dest.append(CreateCurve(id, idObject, calcAngle, calcLength, suffix, data)); + break; + case GOType::CubicBezierPath: + dest.append(CreateCurveWithSegments(id, idObject, calcAngle, calcLength, 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, calcAngle, calcLength, suffix, data, dest.at(i).id, dest.at(i).mx, + dest.at(i).my); + break; + case GOType::Arc: + UpdateArc(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id); + break; + case GOType::EllipticalArc: + //dest.append(UpdateItem(id, idObject, oPoint, angle, suffix, data)); + break; + case GOType::Spline: + UpdateCurve(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id); + break; + case GOType::SplinePath: + UpdateCurveWithSegments(id, idObject, calcAngle, calcLength, suffix, data, + dest.at(i).id); + break; + case GOType::CubicBezier: + UpdateCurve(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezierPath: + UpdateCurveWithSegments(id, idObject, calcAngle, calcLength, suffix, data, + dest.at(i).id); + break; + case GOType::Unknown: + break; + } +QT_WARNING_POP + } + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + + VDrawTool::AddRecord(id, Tool::Move, doc); + if (parse == Document::FullParse) + { + VToolMove *tool = new VToolMove(doc, data, id, formulaAngle, formulaLength, suffix, source, dest, + typeCreation); + scene->addItem(tool); + InitOperationToolConnections(scene, tool); + doc->AddTool(id, tool); + for (int i = 0; i < source.size(); ++i) + { + doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool()); + } + return tool; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolMove::GetFormulaAngle() const +{ + VFormula fAngle(formulaAngle, getData()); + fAngle.setCheckZero(false); + fAngle.setToolId(id); + fAngle.setPostfix(degreeSymbol); + return fAngle; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolMove::SetFormulaAngle(const VFormula &value) +{ + if (value.error() == false) + { + formulaAngle = value.GetFormula(FormulaType::FromUser); + + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolMove::GetFormulaLength() const +{ + VFormula fLength(formulaLength, getData()); + fLength.setCheckZero(true); + fLength.setToolId(id); + fLength.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + return fLength; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolMove::SetFormulaLength(const VFormula &value) +{ + if (value.error() == false) + { + formulaLength = value.GetFormula(FormulaType::FromUser); + + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolMove::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolMove::SetVisualization() +{ + if (not vis.isNull()) + { + VisToolMove *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->SetObjects(source); + visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle, qApp->Settings()->GetOsSeparator())); + visual->SetLength(qApp->TrVars()->FormulaToUser(formulaLength, qApp->Settings()->GetOsSeparator())); + visual->RefreshGeometry(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolMove::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + DialogMove *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + + doc->SetAttribute(domElement, AttrAngle, dialogTool->GetAngle()); + QString length = dialogTool->GetLength(); + doc->SetAttribute(domElement, AttrLength, length); + doc->SetAttribute(domElement, AttrSuffix, dialogTool->GetSuffix()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolMove::ReadToolAttributes(const QDomElement &domElement) +{ + formulaAngle = doc->GetParametrString(domElement, AttrAngle, "0"); + formulaLength = doc->GetParametrString(domElement, AttrLength, "0"); + suffix = doc->GetParametrString(domElement, AttrSuffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolMove::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VDrawTool::SaveOptions(tag, obj); + + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrAngle, formulaAngle); + doc->SetAttribute(tag, AttrLength, formulaLength); + doc->SetAttribute(tag, AttrSuffix, suffix); + + SaveSourceDestination(tag); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolMove::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolMove::VToolMove(VAbstractPattern *doc, VContainer *data, quint32 id, + const QString &formulaAngle, const QString &formulaLength, const QString &suffix, + const QVector &source, const QVector &destination, + const Source &typeCreation, QGraphicsItem *parent) + : VAbstractOperation(doc, data, id, suffix, source, destination, parent), + formulaAngle(formulaAngle), + formulaLength(formulaLength) +{ + InitOperatedObjects(); + ToolCreation(typeCreation); +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VToolMove::CreatePoint(quint32 idTool, quint32 idItem, qreal angle, + qreal length, const QString &suffix, VContainer *data) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF moved = point->Move(length, angle, suffix); + moved.setIdObject(idTool); + + DestinationItem item; + item.mx = moved.mx(); + item.my = moved.my(); + item.id = data->AddGObject(new VPointF(moved)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VToolMove::CreateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, angle, length, suffix, data); + data->AddArc(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolMove::UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data, quint32 id, qreal mx, qreal my) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF moved = point->Move(length, angle, suffix); + moved.setIdObject(idTool); + moved.setMx(mx); + moved.setMy(my); + data->UpdateGObject(id, new VPointF(moved)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolMove::UpdateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, angle, length, suffix, data, id); + data->AddArc(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolMove::CreateItem(quint32 idTool, quint32 idItem, qreal angle, + qreal length, const QString &suffix, VContainer *data) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item moved = i->Move(length, angle, suffix); + moved.setIdObject(idTool); + + DestinationItem item; + item.mx = INT_MAX; + item.my = INT_MAX; + item.id = data->AddGObject(new Item(moved)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolMove::CreateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, + const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, angle, length, suffix, data); + data->AddSpline(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolMove::CreateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, + qreal length, const QString &suffix, + VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, angle, length, suffix, data); + data->AddCurveWithSegments(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolMove::UpdateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data, quint32 id) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item moved = i->Move(length, angle, suffix); + moved.setIdObject(idTool); + data->UpdateGObject(id, new Item(moved)); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolMove::UpdateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, angle, length, suffix, data, id); + data->AddSpline(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolMove::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length, + const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, angle, length, suffix, data, id); + data->AddCurveWithSegments(data->GeometricObject(id), id); +} diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.h b/src/libs/vtools/tools/drawTools/operation/vtoolmove.h new file mode 100644 index 000000000..54397e970 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.h @@ -0,0 +1,128 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 1 10, 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 VTOOLMOVING_H +#define VTOOLMOVING_H + +#include +#include +#include +#include +#include +#include +#include + +#include "vabstractoperation.h" +#include "../vgeometry/vgeometrydef.h" +#include "../vmisc/def.h" +#include "../ifc/xml/vabstractpattern.h" + +class DialogTool; +class QDomElement; +class QGraphicsSceneContextMenuEvent; +class QPointF; +class VContainer; +class VGObject; +class VMainGraphicsScene; +template class QSharedPointer; +class VFormula; + +class VToolMove : public VAbstractOperation +{ + Q_OBJECT +public: + virtual ~VToolMove(); + virtual void setDialog() Q_DECL_OVERRIDE; + static VToolMove* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data); + static VToolMove* Create(quint32 _id, QString &formulaAngle, QString &formulaLength, 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::Move)}; + + VFormula GetFormulaAngle() const; + void SetFormulaAngle(const VFormula &value); + + VFormula GetFormulaLength() const; + void SetFormulaLength(const VFormula &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(VToolMove) + QString formulaAngle; + QString formulaLength; + + VToolMove(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &formulaAngle, + const QString &formulaLength, const QString &suffix, const QVector &source, + const QVector &destination, const Source &typeCreation, + QGraphicsItem *parent = nullptr); + + static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data); + + template + static DestinationItem CreateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data); + static DestinationItem CreateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data); + template + static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data); + template + static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length, + const QString &suffix, VContainer *data); + + static void UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data, quint32 id, qreal mx, qreal my); + template + static void UpdateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data, quint32 id); + static void UpdateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data, quint32 id); + template + static void UpdateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, + VContainer *data, quint32 id); + template + static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length, + const QString &suffix, VContainer *data, quint32 id); +}; + +#endif // VTOOLMOVING_H diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index d84f0ff2a..7f0366f5d 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -55,7 +55,8 @@ HEADERS += \ $$PWD/drawTools/operation/flipping/vtoolflippingbyline.h \ $$PWD/drawTools/operation/vabstractoperation.h \ $$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.h \ - $$PWD/drawTools/operation/flipping/vabstractflipping.h + $$PWD/drawTools/operation/flipping/vabstractflipping.h \ + $$PWD/drawTools/operation/vtoolmove.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -108,4 +109,5 @@ SOURCES += \ $$PWD/drawTools/operation/flipping/vtoolflippingbyline.cpp \ $$PWD/drawTools/operation/vabstractoperation.cpp \ $$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.cpp \ - $$PWD/drawTools/operation/flipping/vabstractflipping.cpp + $$PWD/drawTools/operation/flipping/vabstractflipping.cpp \ + $$PWD/drawTools/operation/vtoolmove.cpp diff --git a/src/libs/vtools/visualization/line/operation/vistoolmove.cpp b/src/libs/vtools/visualization/line/operation/vistoolmove.cpp new file mode 100644 index 000000000..15803060b --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/vistoolmove.cpp @@ -0,0 +1,319 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 1 10, 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 "vistoolmove.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../ifc/xml/vdomdocument.h" +#include "../vmisc/diagnostic.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" +#include "../vmisc/vabstractapplication.h" +#include "../vpatterndb/vcontainer.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "visoperation.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolMove::VisToolMove(const VContainer *data, QGraphicsItem *parent) + : VisOperation(data, parent), + angle(0), + length(0), + pointOrigin(nullptr), + pointFinish(nullptr) +{ + pointOrigin = InitPoint(supportColor2, this); + pointFinish = InitPoint(supportColor, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolMove::~VisToolMove() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolMove::RefreshGeometry() +{ + if (objects.isEmpty()) + { + return; + } + + int iPoint = -1; + int iCurve = -1; + + const QVector originObjects = CreateOriginObjects(iPoint, iCurve); + + const QPointF origin = GetOriginPoint(originObjects); + DrawPoint(pointOrigin, origin, supportColor2); + + qreal tempAngle = 0; + qreal tempLength = 0; + + QLineF line; + if (qFuzzyIsNull(length)) + { + if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) + { + line = QLineF(origin, Visualization::scenePos); + line.setAngle(CorrectAngle(line.angle())); + } + else + { + line = QLineF(origin, Visualization::scenePos); + } + + tempAngle = line.angle(); + tempLength = line.length(); + } + else + { + line = VGObject::BuildLine(origin, length, angle); + tempAngle = angle; + tempLength = length; + } + DrawLine(this, line, supportColor2, Qt::DashLine); + DrawPoint(pointFinish, line.p2(), supportColor); + + static const QString prefix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + Visualization::toolTip = tr("Length = %1%2, angle = %3°, Shift - sticking angle, " + "Mouse click - finish creation") + .arg(qApp->TrVars()->FormulaToUser(QString::number(qApp->fromPixel(tempLength)), + qApp->Settings()->GetOsSeparator())) + .arg(prefix) + .arg(tempAngle); + + CreateMovedObjects(iPoint, iCurve, tempLength, tempAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VisToolMove::Angle() const +{ + return QString::number(line().angle()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolMove::SetAngle(const QString &expression) +{ + angle = FindVal(expression, Visualization::data->PlainVariables()); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VisToolMove::Length() const +{ + return QString::number(LengthValue()); +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VisToolMove::LengthValue() const +{ + return qApp->fromPixel(line().length()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolMove::SetLength(const QString &expression) +{ + length = FindVal(expression, Visualization::data->PlainVariables()); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +QGraphicsPathItem *VisToolMove::AddOriginCurve(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); + + return path; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +int VisToolMove::AddMovedCurve(qreal angle, qreal length, quint32 id, int i) +{ + const QSharedPointer curve = Visualization::data->template GeometricObject(id); + + ++i; + QGraphicsPathItem *path = GetCurve(i, supportColor); + const Item moved = curve->Move(length, angle); + DrawPath(path, moved.GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + + return i; +} + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VisToolMove::GetOriginPoint(const QVector &objects) +{ + QRectF boundingRect; + for (int i=0; i < objects.size(); ++i) + { + QGraphicsItem *object = objects.at(i); + if (object) + { + QRectF childrenRect = object->childrenBoundingRect(); + //map to scene coordinate. + childrenRect.translate(object->scenePos()); + + QRectF itemRect = object->boundingRect(); + //map to scene coordinate. + itemRect.translate(object->scenePos()); + + boundingRect = boundingRect.united(itemRect); + boundingRect = boundingRect.united(childrenRect); + } + } + + return boundingRect.center(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + +QVector VisToolMove::CreateOriginObjects(int &iPoint, int &iCurve) +{ + QVector originObjects; + + 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); + originObjects.append(point); + + break; + } + case GOType::Arc: + originObjects.append(AddOriginCurve(id, iCurve)); + break; + case GOType::EllipticalArc: + originObjects.append(AddOriginCurve(id, iCurve)); + break; + case GOType::Spline: + originObjects.append(AddOriginCurve(id, iCurve)); + break; + case GOType::SplinePath: + originObjects.append(AddOriginCurve(id, iCurve)); + break; + case GOType::CubicBezier: + originObjects.append(AddOriginCurve(id, iCurve)); + break; + case GOType::CubicBezierPath: + originObjects.append(AddOriginCurve(id, iCurve)); + break; + case GOType::Unknown: + break; + } + } + + return originObjects; +} + +QT_WARNING_POP + +//--------------------------------------------------------------------------------------------------------------------- +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + +void VisToolMove::CreateMovedObjects(int &iPoint, int &iCurve, qreal length, qreal angle) +{ + 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 was handled."); + + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + const QSharedPointer p = Visualization::data->GeometricObject(id); + + ++iPoint; + QGraphicsEllipseItem *point = GetPoint(iPoint, supportColor); + DrawPoint(point, p->Move(length, angle), supportColor); + break; + } + case GOType::Arc: + iCurve = AddMovedCurve(angle, length, id, iCurve); + break; + case GOType::EllipticalArc: + iCurve = AddMovedCurve(angle, length, id, iCurve); + break; + case GOType::Spline: + iCurve = AddMovedCurve(angle, length, id, iCurve); + break; + case GOType::SplinePath: + iCurve = AddMovedCurve(angle, length, id, iCurve); + break; + case GOType::CubicBezier: + iCurve = AddMovedCurve(angle, length, id, iCurve); + break; + case GOType::CubicBezierPath: + iCurve = AddMovedCurve(angle, length, id, iCurve); + break; + case GOType::Unknown: + break; + } + } +} + +QT_WARNING_POP diff --git a/src/libs/vtools/visualization/line/operation/vistoolmove.h b/src/libs/vtools/visualization/line/operation/vistoolmove.h new file mode 100644 index 000000000..9121395a4 --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/vistoolmove.h @@ -0,0 +1,86 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 1 10, 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 VISTOOLMOVE_H +#define VISTOOLMOVE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../ifc/ifcdef.h" +#include "../vmisc/def.h" +#include "visoperation.h" + +class QPointF; +class VContainer; + +class VisToolMove : public VisOperation +{ + Q_OBJECT +public: + explicit VisToolMove(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolMove(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + + QString Angle() const; + void SetAngle(const QString &expression); + + QString Length() const; + qreal LengthValue() const; + void SetLength(const QString &expression); + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolMove)}; +private: + Q_DISABLE_COPY(VisToolMove) + qreal angle; + qreal length; + QGraphicsEllipseItem *pointOrigin; + QGraphicsEllipseItem *pointFinish; + + template + QGraphicsPathItem *AddOriginCurve(quint32 id, int &i); + + template + int AddMovedCurve(qreal angle, qreal length, quint32 id, int i); + + static QPointF GetOriginPoint(const QVector &objects); + + QVector CreateOriginObjects(int &iPoint, int &iCurve); + void CreateMovedObjects(int &iPoint, int &iCurve, qreal length, qreal angle); +}; + +#endif // VISTOOLMOVE_H diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index 4e2775d3f..7eee605f6 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -36,7 +36,8 @@ HEADERS += \ $$PWD/path/vistoolcubicbezier.h \ $$PWD/path/vistoolcubicbezierpath.h \ $$PWD/line/operation/visoperation.h \ - $$PWD/line/operation/vistoolflippingbyaxis.h + $$PWD/line/operation/vistoolflippingbyaxis.h \ + $$PWD/line/operation/vistoolmove.h SOURCES += \ $$PWD/visualization.cpp \ @@ -73,4 +74,5 @@ SOURCES += \ $$PWD/path/vistoolcubicbezier.cpp \ $$PWD/path/vistoolcubicbezierpath.cpp \ $$PWD/line/operation/visoperation.cpp \ - $$PWD/line/operation/vistoolflippingbyaxis.cpp + $$PWD/line/operation/vistoolflippingbyaxis.cpp \ + $$PWD/line/operation/vistoolmove.cpp