From 9bb88afaa591e663267f1e70d001dfae1ead6804 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 13 Sep 2016 11:27:44 +0300 Subject: [PATCH] New tool Flipping by line. --HG-- branch : feature --- .../core/vtooloptionspropertybrowser.cpp | 53 +- .../core/vtooloptionspropertybrowser.h | 3 + src/app/valentina/dialogs/dialoghistory.cpp | 3 +- src/app/valentina/mainwindow.cpp | 24 +- src/app/valentina/mainwindow.h | 1 + src/app/valentina/mainwindow.ui | 44 +- src/app/valentina/share/resources/cursor.qrc | 2 + .../resources/cursor/flipping_line_cursor.png | Bin 0 -> 618 bytes .../cursor/flipping_line_cursor@2x.png | Bin 0 -> 1279 bytes .../valentina/share/resources/toolicon.qrc | 2 + .../toolicon/32x32/flipping_line.png | Bin 0 -> 1156 bytes .../toolicon/32x32/flipping_line@2x.png | Bin 0 -> 2553 bytes .../resources/toolicon/svg/flipping_line.svg | 82 +++ src/app/valentina/xml/vpattern.cpp | 43 +- src/app/valentina/xml/vpattern.h | 1 + src/libs/ifc/schema.qrc | 1 + src/libs/ifc/schema/pattern/v0.3.5.xsd | 574 ++++++++++++++++ src/libs/ifc/xml/vabstractpattern.cpp | 8 +- src/libs/ifc/xml/vpatternconverter.cpp | 17 +- src/libs/ifc/xml/vpatternconverter.h | 5 +- src/libs/vmisc/def.h | 5 +- src/libs/vtools/dialogs/dialogs.pri | 9 +- src/libs/vtools/dialogs/tooldialogs.h | 1 + .../dialogs/tools/dialogflippingbyline.cpp | 349 ++++++++++ .../dialogs/tools/dialogflippingbyline.h | 102 +++ .../dialogs/tools/dialogflippingbyline.ui | 98 +++ .../vtools/dialogs/tools/dialogrotation.cpp | 2 +- src/libs/vtools/tools/drawTools/drawtools.h | 1 + .../flipping/vtoolflippingbyline.cpp | 438 ++++++++++++ .../operation/flipping/vtoolflippingbyline.h | 104 +++ .../operation/vabstractoperation.cpp | 610 +++++++++++++++++ .../drawTools/operation/vabstractoperation.h | 203 ++++++ .../drawTools/operation/vtoolrotation.cpp | 622 +----------------- .../tools/drawTools/operation/vtoolrotation.h | 101 +-- src/libs/vtools/tools/tools.pri | 8 +- .../line/operation/visoperation.cpp | 99 +++ .../line/operation/visoperation.h | 62 ++ .../line/operation/vistoolflippingbyline.cpp | 185 ++++++ .../line/operation/vistoolflippingbyline.h | 60 ++ .../line/{ => operation}/vistoolrotation.cpp | 64 +- .../line/{ => operation}/vistoolrotation.h | 15 +- .../vtools/visualization/visualization.pri | 8 +- 42 files changed, 3190 insertions(+), 819 deletions(-) create mode 100644 src/app/valentina/share/resources/cursor/flipping_line_cursor.png create mode 100644 src/app/valentina/share/resources/cursor/flipping_line_cursor@2x.png create mode 100644 src/app/valentina/share/resources/toolicon/32x32/flipping_line.png create mode 100644 src/app/valentina/share/resources/toolicon/32x32/flipping_line@2x.png create mode 100644 src/app/valentina/share/resources/toolicon/svg/flipping_line.svg create mode 100644 src/libs/ifc/schema/pattern/v0.3.5.xsd create mode 100644 src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp create mode 100644 src/libs/vtools/dialogs/tools/dialogflippingbyline.h create mode 100644 src/libs/vtools/dialogs/tools/dialogflippingbyline.ui create mode 100644 src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp create mode 100644 src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h create mode 100644 src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp create mode 100644 src/libs/vtools/tools/drawTools/operation/vabstractoperation.h create mode 100644 src/libs/vtools/visualization/line/operation/visoperation.cpp create mode 100644 src/libs/vtools/visualization/line/operation/visoperation.h create mode 100644 src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp create mode 100644 src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h rename src/libs/vtools/visualization/line/{ => operation}/vistoolrotation.cpp (80%) rename src/libs/vtools/visualization/line/{ => operation}/vistoolrotation.h (82%) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index ff55d7efb..8c2bca58f 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -75,7 +75,7 @@ void VToolOptionsPropertyBrowser::ClearPropertyBrowser() void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was used in switch."); switch (item->type()) { @@ -185,6 +185,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolRotation::Type: ShowOptionsToolRotation(item); break; + case VToolFlippingByLine::Type: + ShowOptionsToolFlippingByLine(item); + break; default: break; } @@ -199,7 +202,7 @@ void VToolOptionsPropertyBrowser::UpdateOptions() } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -299,6 +302,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VToolRotation::Type: UpdateOptionsToolRotation(); break; + case VToolFlippingByLine::Type: + UpdateOptionsToolFlippingByLine(); + break; default: break; } @@ -334,7 +340,7 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -428,6 +434,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolRotation::Type: ChangeDataToolRotation(prop); break; + case VToolFlippingByLine::Type: + ChangeDataToolFlippingByLine(prop); + break; default: break; } @@ -1601,6 +1610,27 @@ void VToolOptionsPropertyBrowser::ChangeDataToolRotation(VProperty *property) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolFlippingByLine(VProperty *property) +{ + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolFlippingByLine *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 38: // AttrSuffix + SetOperationSuffix(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<GetFormulaAngle(), AttrAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolFlippingByLine(QGraphicsItem *item) +{ + VToolFlippingByLine *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool flipping by line")); + + AddPropertyOperationSuffix(i, tr("Suffix")); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolSinglePoint() { @@ -2451,6 +2491,13 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolRotation() idToProperty[AttrAngle]->setValue(valueAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolFlippingByLine() +{ + VToolFlippingByLine *i = qgraphicsitem_cast(currentItem); + idToProperty[AttrSuffix]->setValue(i->Suffix()); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VToolOptionsPropertyBrowser::PropertiesList() const { diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index 2c69b5513..5c521ab47 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -152,6 +152,7 @@ private: void ChangeDataToolLineIntersectAxis(VPE::VProperty *property); void ChangeDataToolCurveIntersectAxis(VPE::VProperty *property); void ChangeDataToolRotation(VPE::VProperty *property); + void ChangeDataToolFlippingByLine(VPE::VProperty *property); void ShowOptionsToolSinglePoint(QGraphicsItem *item); void ShowOptionsToolEndLine(QGraphicsItem *item); @@ -183,6 +184,7 @@ private: void ShowOptionsToolLineIntersectAxis(QGraphicsItem *item); void ShowOptionsToolCurveIntersectAxis(QGraphicsItem *item); void ShowOptionsToolRotation(QGraphicsItem *item); + void ShowOptionsToolFlippingByLine(QGraphicsItem *item); void UpdateOptionsToolSinglePoint(); void UpdateOptionsToolEndLine(); @@ -214,6 +216,7 @@ private: void UpdateOptionsToolLineIntersectAxis(); void UpdateOptionsToolCurveIntersectAxis(); void UpdateOptionsToolRotation(); + void UpdateOptionsToolFlippingByLine(); }; #endif // VTOOLOPTIONSPROPERTYBROWSER_H diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index beab2bedb..2d5ac5ab9 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -207,7 +207,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") QString DialogHistory::Record(const VToolRecord &tool) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45, "Not all tools was used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -387,6 +387,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::NodeSplinePath: case Tool::Group: case Tool::Rotation: + case Tool::FlippingByLine: return QString(); } } diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index b6d2c79ed..1618916c8 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1033,6 +1033,17 @@ void MainWindow::ToolRotation(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolFlippingByLine(bool checked) +{ + ToolSelectOperationObjects(); + SetToolButtonWithApply(checked, Tool::FlippingByLine, + ":/cursor/flipping_line_cursor.png", + tr("Select one or more objects, Enter - confirm selection"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ClosedDialogGroup(int result) { @@ -1702,6 +1713,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonTrueDarts, &QToolButton::clicked, this, &MainWindow::ToolTrueDarts); connect(ui->toolButtonGroup, &QToolButton::clicked, this, &MainWindow::ToolGroup); connect(ui->toolButtonRotation, &QToolButton::clicked, this, &MainWindow::ToolRotation); + connect(ui->toolButtonFlippingByLine, &QToolButton::clicked, this, &MainWindow::ToolFlippingByLine); connect(ui->toolButtonMidpoint, &QToolButton::clicked, this, &MainWindow::ToolMidpoint); connect(ui->toolButtonLayoutExportAs, &QToolButton::clicked, this, &MainWindow::ExportLayoutAs); } @@ -1731,7 +1743,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") void MainWindow::CancelTool() { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was handled."); qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; @@ -1871,6 +1883,9 @@ void MainWindow::CancelTool() case Tool::Rotation: ui->toolButtonRotation->setChecked(false); break; + case Tool::FlippingByLine: + ui->toolButtonFlippingByLine->setChecked(false); + break; } // Crash: using CRTL+Z while using line tool. @@ -2952,6 +2967,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonTrueDarts->setEnabled(drawTools); ui->toolButtonGroup->setEnabled(drawTools); ui->toolButtonRotation->setEnabled(drawTools); + ui->toolButtonFlippingByLine->setEnabled(drawTools); ui->toolButtonMidpoint->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -3234,7 +3250,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") void MainWindow::LastUsedTool() { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was handled."); if (currentTool == lastUsedTool) { @@ -3400,6 +3416,10 @@ void MainWindow::LastUsedTool() ui->toolButtonRotation->setChecked(true); ToolRotation(true); break; + case Tool::FlippingByLine: + ui->toolButtonFlippingByLine->setChecked(true); + ToolFlippingByLine(true); + break; } } diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 375ffcda4..1bb634d1e 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -139,6 +139,7 @@ private slots: void ToolUnionDetails(bool checked); void ToolGroup(bool checked); void ToolRotation(bool checked); + void ToolFlippingByLine(bool checked); void ToolCutArc(bool checked); void ToolLineIntersectAxis(bool checked); void ToolCurveIntersectAxis(bool checked); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index ae7bebe5e..295cb3186 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -48,14 +48,14 @@ Tools - 6 + 4 0 0 - 100 + 117 358 @@ -427,7 +427,7 @@ 0 0 - 100 + 130 110 @@ -536,7 +536,7 @@ 0 0 - 100 + 130 248 @@ -798,7 +798,7 @@ 0 0 - 100 + 130 248 @@ -1063,8 +1063,8 @@ 0 0 - 100 - 104 + 130 + 356 @@ -1156,6 +1156,32 @@ + + + + false + + + Flipping objects by line + + + ... + + + + :/toolicon/32x32/flipping_line.png:/toolicon/32x32/flipping_line.png + + + + 32 + 32 + + + + true + + + @@ -1163,7 +1189,7 @@ 0 0 - 100 + 130 104 @@ -2402,8 +2428,8 @@ - + diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index 95f4ef5ae..cb10b4aef 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -70,5 +70,7 @@ cursor/rotation_cursor@2x.png cursor/midpoint_cursor.png cursor/midpoint_cursor@2x.png + cursor/flipping_line_cursor@2x.png + cursor/flipping_line_cursor.png diff --git a/src/app/valentina/share/resources/cursor/flipping_line_cursor.png b/src/app/valentina/share/resources/cursor/flipping_line_cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..c1e80d2f004eee02e864bd73b85d4f2e33f63038 GIT binary patch literal 618 zcmV-w0+s!VP)?fj9MJ(W0KLLG1)C2m0_}KvHIieY$r-=0cJwufL0_X|i zUx2P7S^;zwQECy;HAFjrt{~b4B#v0^0FWr6Q$S*fjQ|ostZWd_5h7>+Y--Xb5--z( zE%x~t`;bOhtr0f4{)S?Gr%{v6$|#86>SK!lcz`$JKdb&I;{fu=;931cMQew18J{rR zM&VlSSUbA4Gg(n3GZ-9yiZIbW4MY(*i)8&F(5n~)-|Yof+al0WP-&r zxPcjrugcF42s0>z4GoL9g|p&`mqd2sCLSWUEH{@Djxlhy}*+SYk#dwLPcvC!QE={qlC3>=qz}YhUfXzEkQrg>#HVk^L!( z0V@GRA*G<%Vv$5HZ#TH(hwLuG0+mvHJE%?W>N$Az3uihFuz*v%BLDyZ07*qoM6N<$ Eg2HM4bpQYW literal 0 HcmV?d00001 diff --git a/src/app/valentina/share/resources/cursor/flipping_line_cursor@2x.png b/src/app/valentina/share/resources/cursor/flipping_line_cursor@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..7468a233ccdded6d856bfc407abc043395747a05 GIT binary patch literal 1279 zcmVSKnNl; zBfANilwnkosStsfLG|K;hL&JumNl3v@BNX?YuG&dlmzok5+> zIM*}hGXCJtUVFn@`~Uy$|9`E0*4doZS)J8covsh@8O|-XBgIn4*-rfwLO8|tU}SOK z>3g*}9YVj$gl4A$=y#cr4?w?ykd+@mzk$%CeE|IeLPr299zvsz0aP@E6FLW=Vj*+| zKt)1m&@})R2jRG`1E?qn-33rF5RU0SfQo={RL=mEJ%ru>P}UHR=p6uM3*oTd15lO_ zdK*C5LHJki11Kv9|0oQAvVl-Y0A&H;kir5ec?bs;9zaP$=qmsv3*m2l2cRS&{H1RJ zlpKU&04OO4e<}`ul7aAt;sGcL2*n0abO^t9!oiA$aG)E`RuqI%0#FnPzZD>ep4z8{ z3O1eRS}4@bx~Z(VQ#}$lqAF+UQ`)WP={)Tes&nmt6{r=r{`Ter&|Pi9-MN7ap-1r? zz7wG|*AjGJ=T$K|`xuezS1%S6J3)NIs?Pc+G6?dg1cf?c=-JDl|U zmY$YC3m(VPF7)Y%PKDkX4HX~GMYs(E#8PSzxBvI1df?1)Ox1V6cU4328YW<}_^OOU#GN#Pl-W4jA!wVH~}_bPEa?RWCiM}c`~spZ~5lS zfa!(tw^xwOaqmhs_>W?`~orfwc=~;)L_h& zB#x}BZ6ZH)p4Ong&a5-KP17Cn8 z;%n}tVBC46Hj#Wz&0UEv4|Qh1asm)A94}%Kmg6!^4(dkH@-{xA@!rJ8hdVoHIhDY- zSS8l}T=A8BN{~5+unM~gvpcH!wkjt8`!GuUMK~0bf=rrZGxl&|TH>oNzowTHfSH(> zYronkGmvBhcF}krLmGn2Aes`I6NV>bbJmtoolicon/32x32/rotation@2x.png toolicon/32x32/midpoint.png toolicon/32x32/midpoint@2x.png + toolicon/32x32/flipping_line@2x.png + toolicon/32x32/flipping_line.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/flipping_line.png b/src/app/valentina/share/resources/toolicon/32x32/flipping_line.png new file mode 100644 index 0000000000000000000000000000000000000000..6f1224ab9522ab7d1ab53d5825bf704108d69719 GIT binary patch literal 1156 zcmV-~1bh35P)_ub|RA^98NWCb8D6)$rLfI7&jk1i0lAUhLU+@3Z|%KEGpCRsRI;s6}m3_%wb_znjrgrM?x%tNJH!w5nf1W0x7XU<+e+Y4=O+77bl^wvH3$lILAEL=E*&fZ=U{J&v#$)o z17f=OVQhpi7#b8l39=Am2Wq>E*3Whxw&PMU{q;D4<#;LC7UD=SdlXGu$<0q=^8;Ok z6R;z}cjJZxe>lN+mjwlLM^f5Km{0hv9AF>BMTEEo$Ag(uDQ!=_AJecT=U{8s zfc?q9RB^_W@I@7TO@e=3wguUA^1G7n7MgGC4&EOD)5O|-L7a`76a0BRT4ievW?eyU zJI0gS#N^v^_P6yEythI$9e*aD55;ps4(qzu1cli_@o*|K8^b9k7)%?He17Roz~%TW zJ>QZ*d91Ip)y1IM+#qX6f!Bs8vfI{I0hxG;3D}I91mBQsZzr3eczuvH#h`_!P6h6d zfLUTi3wSGmYQ*g`U{eL2Ee^7l1Ygk`ye|T-5-VE3n+a5lca!anD)_BI)*57`AbYSc z@ZJQ>5i452>tf35@LsaLCcWDryF18E1X)K=ysxkDo&-FLW9j#+2~>yolkJr%__73V z4+?ko2i}u_Qu^MQWrF@$YhoSVs2U06d)v~{*Na!pnJc1p)8-F%05bn6U2X~(|{ WR@}oDX!N510000h($8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H133f?DK~#90-J5%GRmC00KYK|C(S#Q33#u&^wN@uOauXh-Qfdr{ z1uImvGQg-++tON#&e+E|?TmfN45NLZl~&r6)?%?BuTl$9P%9O4gYpQiEeuwyC;=Ks zfFw7$zy9$%*X-GIZq7||NiKe8GL!Q=-?L}Gzq|X}-QVspC=74`P)a8XffDO_05BLo zhB((B0%F#6iC0b@bV?A0v|0e%O3gDhZxVqhI`Wi}6-L>L2X z1}cDAzzEa3D>bihAvX_7?{h039Ls4g%BC4!A83Dx2%S9|7Nu;Isjk6%fQ8 zU^m)aS}l7skhHE311ax+0UE7)?Ld=t-RhN>hFf-%_e>g%UYU6BIBeZZdUY8AJP&-# zssDq(kAa4OGCvA|Z$q#J{2=1Nd_WoS9>HJrUhn=DA@{=m_Jy^8e8;6g4RD5K6JQST zxOeT29GNgA7R|{kQ~(?Ci%$Vxrc*q?-Ym;|>tu4kXmq%?=K(3;OTaH3?x}Rfr>?L9 zPL3EbhR(p4{_6m458;jt;fDR~0#1Yccffcw>f3cp0$<3IyPu%=r-5PVhw|A0R}(J& zrYyKAbW|AV-MbsrTIN2OuMW5dI7)Exa$^?UbYKiXm_9%lIZ+sWaoU!T4w!&Wmh5`9 z0Fy(wQ@ne2Y`8P5P@!yyP`*hh7oj{Q#HZ)uJm7k?j}EkKEx_l2wGrGDa2K%1EmXMl zOekCjT;`b!m>K!zfE$265)?lbcs7FD4$KCYxP=Or4}$?Uz^9yB1M|rN(}1V&=MRpf zLf1ub+ku&=LwpcMUjQ971lJ6JKY7ugmoZZ#S``ZDx0>8#D{s=G$cqxLLjt$G)LWPlI zpyOp=sAWz9b6swKI$#c&#lIZEO^g4tTc|MdYKYYUAGXXbkeUYODVN`04)_|Ht}>SG z5ISSq6u~_Xe2(C#fDoSmvDN5eh)%wlYS^+StRns4fO~+S;TL}poz2xna5Du)gi%w$ ztj3>ZZUS?yp*G;GH2T^BbAdXu z-wm<|e;|DaQsWGDTe7KGU(5s_0>0_k{)>wLR|NMUx-bfe5#slPnUB9k?S3fBCl}xcfZbKkbJF48#|J%yG)y25nV_ zZTovt*<3py20VslYHjR7MeTLCzd+aTX`}<=8}`EjF^E47#!Yl=hSo`j?f>g(g>&hE z7_bny!?Eu~qxicK+_ycRFMtW-3!r&1y6Ca73FJD%_QUi7xpF`Z_!Yr4^$v8B^IimZ z5Bkf$X+JESUj)rhqiHW2HPCj0VcXH(Ry-FDC_oP+xM}L`sQCR6+_2byFt!+ye?n(} zHdaF8&4yjAOKmqV1!8G+YRD44OH!L;jRQ*2Eh+aL;d*q_;#dUt?`Svh&Dgx0 z{d(Xm%bWt{7-|=0Rr?$uDh3QjlaH?W)o8On7Qx+!uIe1|<)a|>0)FxBU}hTTCI z6G2wt7vHQay1IT558*A~4uXzZfgYsjuxvxoQNZ4EUPaJJ2o=*nmf%lYAA!_l!`FtOFWK4Oh@r^~+X+tqU&JqJ z1lsIBZrQ2{b`LLY9oVqg1v1|7>Ym(HJvS&ocU@+oUk@_* zWDpPPfLpWR4aYibr#buP62#CiMzg^u;r$JZBM zt|62S0SSCdRDjOlinAyqDO^$l$yMkUw~f8P5@?ztl$V0B7Fj9l6Bkne#`-)rH3*FL zZaEcV)|x@APjQX&8LbS&AFzwTSTRdV$s*%b03^^fbysM+kkTDc{1?JMu{{^elh(_v zTkc5P)ji|f&-7d-bU%3ab8R#q`Vi$I?y9;9y&rksU2Vi(bN%W^VS*z#PE8~CsqFkBK&c0C#gh! P00000NkvXXu0mjfD1ft? literal 0 HcmV?d00001 diff --git a/src/app/valentina/share/resources/toolicon/svg/flipping_line.svg b/src/app/valentina/share/resources/toolicon/svg/flipping_line.svg new file mode 100644 index 000000000..aa4a3affc --- /dev/null +++ b/src/app/valentina/share/resources/toolicon/svg/flipping_line.svg @@ -0,0 +1,82 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index faf18ed06..46c7c42fc 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2519,7 +2519,7 @@ void VPattern::ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElem QVector source; QVector destination; - VToolRotation::ExtractData(this, domElement, source, destination); + VAbstractOperation::ExtractData(this, domElement, source, destination); VToolRotation::Create(id, center, a, suffix, source, destination, scene, this, data, parse, Source::FromFile); //Rewrite attribute formula. Need for situation when we have wrong formula. @@ -2544,6 +2544,36 @@ void VPattern::ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElem } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParseToolFlippingByLine(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse) +{ + SCASSERT(scene != nullptr); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + + try + { + quint32 id = NULL_ID; + + ToolsCommonAttributes(domElement, id); + const quint32 p1 = GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); + const quint32 p2 = GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); + const QString suffix = GetParametrString(domElement, AttrSuffix, ""); + + QVector source; + QVector destination; + VAbstractOperation::ExtractData(this, domElement, source, destination); + + VToolFlippingByLine::Create(id, p1, p2, suffix, source, destination, scene, this, data, parse, + Source::FromFile); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating operation of flipping by line"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } +} + //--------------------------------------------------------------------------------------------------------------------- qreal VPattern::EvalFormula(VContainer *data, const QString &formula, bool *ok) const { @@ -2794,13 +2824,17 @@ void VPattern::ParseOperationElement(VMainGraphicsScene *scene, QDomElement &dom Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(not type.isEmpty(), Q_FUNC_INFO, "type of operation is empty"); - const QStringList opers = QStringList() << VToolRotation::ToolType; /*0*/ + const QStringList opers = QStringList() << VToolRotation::ToolType /*0*/ + << VToolFlippingByLine::ToolType; /*1*/ switch (opers.indexOf(type)) { case 0: //VToolRotation::ToolType ParseToolRotation(scene, domElement, parse); break; + case 1: //VToolFlippingByLine::ToolType + ParseToolFlippingByLine(scene, domElement, parse); + break; default: VException e(tr("Unknown operation type '%1'.").arg(type)); throw e; @@ -3306,7 +3340,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") QRectF VPattern::ActiveDrawBoundingRect() const { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 45, "Not all tools was used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46, "Not all tools was used."); QRectF rec; @@ -3418,6 +3452,9 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::Rotation: rec = ToolBoundingRect(rec, tool.getId()); break; + case Tool::FlippingByLine: + rec = ToolBoundingRect(rec, tool.getId()); + break; //These tools are not accesseble in Draw mode, but still 'history' contains them. case Tool::Detail: case Tool::UnionDetails: diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 9ccf41aa6..5ab917405 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -194,6 +194,7 @@ private: void ParseToolArcWithLength(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); + void ParseToolFlippingByLine(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); 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 c55cd654e..3f4d890f7 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -18,6 +18,7 @@ schema/pattern/v0.3.2.xsd schema/pattern/v0.3.3.xsd schema/pattern/v0.3.4.xsd + schema/pattern/v0.3.5.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.3.5.xsd b/src/libs/ifc/schema/pattern/v0.3.5.xsd new file mode 100644 index 000000000..b54271a63 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.3.5.xsd @@ -0,0 +1,574 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 2d1cf5568..4c0c34ed5 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) == 45); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46); 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) == 45); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46); 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) == 45); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46); 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) == 45); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 46); QStringList expressions; const QDomNodeList list = elementsByTagName(TagOperation); diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 33b652163..dcd2a6eeb 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.4"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.4.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.3.5"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.5.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -167,6 +167,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000303): return QStringLiteral("://schema/pattern/v0.3.3.xsd"); case (0x000304): + return QStringLiteral("://schema/pattern/v0.3.4.xsd"); + case (0x000305): return CurrentSchema; default: InvalidVersion(ver); @@ -250,6 +252,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000304), fileName); V_FALLTHROUGH case (0x000304): + ToV0_3_5(); + ValidateXML(XSDSchema(0x000305), fileName); + V_FALLTHROUGH + case (0x000305): break; default: break; @@ -410,6 +416,13 @@ void VPatternConverter::ToV0_3_4() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_3_5() +{ + SetVersion(QStringLiteral("0.3.5")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index b4af935ac..cca5e3c2f 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, 4); + static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 5); #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, 4); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 5); #endif protected: @@ -93,6 +93,7 @@ private: void ToV0_3_2(); void ToV0_3_3(); void ToV0_3_4(); + void ToV0_3_5(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index ad437abd6..0a51f4199 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -109,6 +109,7 @@ enum class Tool : ToolVisHolderType UnionDetails, Group, Rotation, + FlippingByLine, Midpoint, LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; @@ -121,6 +122,7 @@ enum class Vis : ToolVisHolderType SimpleCurve, Line, Path, + Operation, ToolAlongLine, ToolArc, ToolArcWithLength, @@ -149,7 +151,8 @@ enum class Vis : ToolVisHolderType ToolLineIntersectAxis, ToolCurveIntersectAxis, ToolTrueDarts, - ToolRotation + ToolRotation, + ToolFlippingByLine }; enum class VarType : char { Measurement, Increment, LineLength, CurveLength, LineAngle, CurveAngle, ArcRadius, diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index 5c1cc848e..8b51c331b 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -38,7 +38,8 @@ HEADERS += \ $$PWD/tools/dialogcubicbezier.h \ $$PWD/tools/dialogcubicbezierpath.h \ $$PWD/tools/dialoggroup.h \ - $$PWD/tools/dialogrotation.h + $$PWD/tools/dialogrotation.h \ + $$PWD/tools/dialogflippingbyline.h SOURCES += \ @@ -77,7 +78,8 @@ SOURCES += \ $$PWD/tools/dialogcubicbezier.cpp \ $$PWD/tools/dialogcubicbezierpath.cpp \ $$PWD/tools/dialoggroup.cpp \ - $$PWD/tools/dialogrotation.cpp + $$PWD/tools/dialogrotation.cpp \ + $$PWD/tools/dialogflippingbyline.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -114,4 +116,5 @@ FORMS += \ $$PWD/tools/dialogcubicbezier.ui \ $$PWD/tools/dialogcubicbezierpath.ui \ $$PWD/tools/dialoggroup.ui \ - $$PWD/tools/dialogrotation.ui + $$PWD/tools/dialogrotation.ui \ + $$PWD/tools/dialogflippingbyline.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index d82ef4fb2..9a2e0d09d 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -62,6 +62,7 @@ #include "tools/dialogtruedarts.h" #include "tools/dialoggroup.h" #include "tools/dialogrotation.h" +#include "tools/dialogflippingbyline.h" #include "support/dialogeditwrongformula.h" #include "support/dialogundo.h" diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp b/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp new file mode 100644 index 000000000..39d92d6d6 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp @@ -0,0 +1,349 @@ +/************************************************************************ + ** + ** @file dialogflippingbyline.cpp + ** @author Roman Telezhynskyi + ** @date 12 9, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dialogflippingbyline.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../visualization/visualization.h" +#include "../../visualization/line/operation/vistoolflippingbyline.h" +#include "../ifc/xml/vabstractpattern.h" +#include "../ifc/xml/vdomdocument.h" +#include "../qmuparser/qmudef.h" +#include "../vgeometry/vpointf.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vcommonsettings.h" +#include "../vpatterndb/vcontainer.h" +#include "../vwidgets/vabstractmainwindow.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "ui_dialogflippingbyline.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogFlippingByLine::DialogFlippingByLine(const VContainer *data, const quint32 &toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogFlippingByLine), + objects(), + stage1(true), + m_suffix() +{ + ui->setupUi(this); + + ui->lineEditSuffix->setText(qApp->getCurrentDocument()->GenerateSuffix()); + + InitOkCancelApply(ui); + + FillComboBoxPoints(ui->comboBoxFirstLinePoint); + FillComboBoxPoints(ui->comboBoxSecondLinePoint); + + flagName = true; + CheckState(); + + connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogFlippingByLine::SuffixChanged); + connect(ui->comboBoxFirstLinePoint, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogFlippingByLine::PointChanged); + + vis = new VisToolFlippingByLine(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogFlippingByLine::~DialogFlippingByLine() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogFlippingByLine::GetFirstLinePointId() const +{ + return getCurrentObjectId(ui->comboBoxFirstLinePoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SetFirstLinePointId(quint32 value) +{ + ChangeCurrentData(ui->comboBoxFirstLinePoint, value); + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetFirstLinePointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogFlippingByLine::GetSecondLinePointId() const +{ + return getCurrentObjectId(ui->comboBoxSecondLinePoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SetSecondLinePointId(quint32 value) +{ + ChangeCurrentData(ui->comboBoxSecondLinePoint, value); + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetSecondLinePointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogFlippingByLine::GetSuffix() const +{ + return m_suffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SetSuffix(const QString &value) +{ + m_suffix = value; + ui->lineEditSuffix->setText(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogFlippingByLine::GetObjects() const +{ + return objects.toVector(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::ShowDialog(bool click) +{ + if (stage1 && not click) + { + if (objects.isEmpty()) + { + return; + } + + stage1 = false; + + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + scene->clearSelection(); + + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetObjects(objects.toVector()); + operation->VisualMode(); + + scene->ToggleArcSelection(false); + scene->ToggleSplineSelection(false); + scene->ToggleSplinePathSelection(false); + + scene->ToggleArcHover(false); + scene->ToggleSplineHover(false); + scene->ToggleSplinePathHover(false); + + emit ToolTip("Select first line point"); + } + else if (not stage1 && prepare && click) + { + setModal(true); + emit ToolTip(""); + show(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::ChosenObject(quint32 id, const SceneObject &type) +{ + if (not stage1 && not prepare)// After first choose we ignore all objects + { + if (type == SceneObject::Point) + { + if (objects.contains(id)) + { + return; + } + + switch (number) + { + case 0: + if (SetObject(id, ui->comboBoxFirstLinePoint, tr("Select second line point"))) + { + number++; + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetFirstLinePointId(id); + operation->RefreshGeometry(); + } + break; + case 1: + if (getCurrentObjectId(ui->comboBoxFirstLinePoint) != id) + { + if (SetObject(id, ui->comboBoxSecondLinePoint, "")) + { + if (flagError) + { + number = 0; + prepare = true; + + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetSecondLinePointId(id); + operation->RefreshGeometry(); + } + } + } + break; + default: + break; + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SelectedObject(bool selected, quint32 object, quint32 tool) +{ + Q_UNUSED(tool) + if (stage1) + { + if (selected) + { + if (not objects.contains(object)) + { + objects.append(object); + } + } + else + { + objects.removeOne(object); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SuffixChanged() +{ + QLineEdit* edit = qobject_cast(sender()); + if (edit) + { + const QString suffix = edit->text(); + if (suffix.isEmpty()) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + CheckState(); + return; + } + else + { + if (m_suffix != suffix) + { + QRegularExpression rx(NameRegExp()); + const QStringList uniqueNames = data->AllUniqueNames(); + for (int i=0; i < uniqueNames.size(); ++i) + { + const QString name = uniqueNames.at(i) + suffix; + if (not rx.match(name).hasMatch() || not data->IsUnique(name)) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + CheckState(); + return; + } + } + } + } + + flagName = true; + ChangeColor(ui->labelSuffix, okColor); + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(flagError && flagName); + SCASSERT(bApply != nullptr); + bApply->setEnabled(bOk->isEnabled()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SaveData() +{ + m_suffix = ui->lineEditSuffix->text(); + + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + operation->SetObjects(objects.toVector()); + operation->SetFirstLinePointId(GetFirstLinePointId()); + operation->SetSecondLinePointId(GetSecondLinePointId()); + operation->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::PointChanged() +{ + QColor color = okColor; + flagError = true; + ChangeColor(ui->labelFirstLinePoint, color); + ChangeColor(ui->labelSecondLinePoint, color); + + if (getCurrentObjectId(ui->comboBoxFirstLinePoint) == getCurrentObjectId(ui->comboBoxSecondLinePoint)) + { + flagError = false; + color = errorColor; + ChangeColor(ui->labelFirstLinePoint, color); + ChangeColor(ui->labelSecondLinePoint, color); + } + else if (objects.contains(getCurrentObjectId(ui->comboBoxFirstLinePoint))) + { + flagError = false; + color = errorColor; + ChangeColor(ui->labelFirstLinePoint, color); + } + else if (objects.contains(getCurrentObjectId(ui->comboBoxSecondLinePoint))) + { + flagError = false; + color = errorColor; + ChangeColor(ui->labelSecondLinePoint, color); + } + + CheckState(); +} diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.h b/src/libs/vtools/dialogs/tools/dialogflippingbyline.h new file mode 100644 index 000000000..300cbb0a3 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.h @@ -0,0 +1,102 @@ +/************************************************************************ + ** + ** @file dialogflippingbyline.h + ** @author Roman Telezhynskyi + ** @date 12 9, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DIALOGFLIPPINGBYLINE_H +#define DIALOGFLIPPINGBYLINE_H + +#include "dialogtool.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "../vmisc/def.h" + +class QWidget; +class VContainer; + +namespace Ui +{ + class DialogFlippingByLine; +} + +class DialogFlippingByLine : public DialogTool +{ + Q_OBJECT + +public: + explicit DialogFlippingByLine(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + virtual ~DialogFlippingByLine(); + + quint32 GetFirstLinePointId() const; + void SetFirstLinePointId(quint32 value); + + quint32 GetSecondLinePointId() const; + void SetSecondLinePointId(quint32 value); + + QString GetSuffix() const; + void SetSuffix(const QString &value); + + QVector GetObjects() const; + + virtual void ShowDialog(bool click) Q_DECL_OVERRIDE; + +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; + virtual void SelectedObject(bool selected, quint32 object, quint32 tool) Q_DECL_OVERRIDE; + +private slots: + void SuffixChanged(); + +protected: + virtual void CheckState() Q_DECL_OVERRIDE; + virtual void ShowVisualization() Q_DECL_OVERRIDE; + + /** @brief SaveData Put dialog data in local variables */ + virtual void SaveData() Q_DECL_OVERRIDE; + +private slots: + void PointChanged(); + +private: + Q_DISABLE_COPY(DialogFlippingByLine) + + Ui::DialogFlippingByLine *ui; + + QList objects; + + bool stage1; + + QString m_suffix; +}; + +#endif // DIALOGFLIPPINGBYLINE_H diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui b/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui new file mode 100644 index 000000000..cee345f19 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui @@ -0,0 +1,98 @@ + + + DialogFlippingByLine + + + + 0 + 0 + 285 + 146 + + + + Dialog + + + + + + + + First line point: + + + + + + + + + + Suffix: + + + + + + + + + + Second line point: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogFlippingByLine + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogFlippingByLine + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.cpp b/src/libs/vtools/dialogs/tools/dialogrotation.cpp index 679e0f266..3a9babe2e 100644 --- a/src/libs/vtools/dialogs/tools/dialogrotation.cpp +++ b/src/libs/vtools/dialogs/tools/dialogrotation.cpp @@ -48,7 +48,7 @@ #include #include "../../visualization/visualization.h" -#include "../../visualization/line/vistoolrotation.h" +#include "../../visualization/line/operation/vistoolrotation.h" #include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vdomdocument.h" #include "../qmuparser/qmudef.h" diff --git a/src/libs/vtools/tools/drawTools/drawtools.h b/src/libs/vtools/tools/drawTools/drawtools.h index f52094158..93142cf64 100644 --- a/src/libs/vtools/tools/drawTools/drawtools.h +++ b/src/libs/vtools/tools/drawTools/drawtools.h @@ -59,5 +59,6 @@ #include "toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h" #include "toolpoint/tooldoublepoint/vtooltruedarts.h" #include "operation/vtoolrotation.h" +#include "operation/flipping/vtoolflippingbyline.h" #endif // DRAWTOOLS_H diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp new file mode 100644 index 000000000..7f097942e --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp @@ -0,0 +1,438 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vtoolflippingbyline.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../../../dialogs/tools/dialogtool.h" +#include "../../../../dialogs/tools/dialogflippingbyline.h" +#include "../../../../undocommands/label/rotationmovelabel.h" +#include "../../../../visualization/line/operation/vistoolflippingbyline.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 VToolFlippingByLine::ToolType = QStringLiteral("flippingByLine"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByLine::~VToolFlippingByLine() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::setDialog() +{ + SCASSERT(dialog != nullptr); + DialogFlippingByLine *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + dialogTool->SetFirstLinePointId(m_firstLinePointId); + dialogTool->SetSecondLinePointId(m_secondLinePointId); + dialogTool->SetSuffix(suffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByLine *VToolFlippingByLine::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogFlippingByLine *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const quint32 firstLinePointId = dialogTool->GetFirstLinePointId(); + const quint32 secondLinePointId = dialogTool->GetSecondLinePointId(); + const QString suffix = dialogTool->GetSuffix(); + const QVector source = dialogTool->GetObjects(); + VToolFlippingByLine* operation = Create(0, firstLinePointId, secondLinePointId, suffix, source, + QVector(), scene, doc, data, Document::FullParse, + Source::FromGui); + if (operation != nullptr) + { + operation->dialog = dialogTool; + } + return operation; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByLine *VToolFlippingByLine::Create(const quint32 _id, quint32 firstLinePointId, quint32 secondLinePointId, + const QString &suffix, const QVector &source, + const QVector &destination, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation) +{ + const auto firstPoint = *data->GeometricObject(firstLinePointId); + const QPointF fPoint = firstPoint; + + const auto secondPoint = *data->GeometricObject(secondLinePointId); + const QPointF sPoint = secondPoint; + + QVector dest = destination; + + quint32 id = _id; + if (typeCreation == Source::FromGui) + { + dest.clear();// Try to avoid mistake, value must be empty + + id = data->getNextId();//Just reserve id for tool + + for (int i = 0; i < source.size(); ++i) + { + const quint32 idObject = source.at(i); + const QSharedPointer obj = data->GetGObject(idObject); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(static_cast(obj->getType())) + { + case GOType::Point: + dest.append(CreatePoint(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::Arc: + dest.append(CreateArc(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::EllipticalArc: + //dest.append(CreateItem(id, idObject, fPoint, sPoint, suffix)); + break; + case GOType::Spline: + dest.append(CreateCurve(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::SplinePath: + dest.append(CreateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::CubicBezier: + dest.append(CreateCurve(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::CubicBezierPath: + dest.append(CreateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::Unknown: + break; + } +QT_WARNING_POP + } + } + else + { + for (int i = 0; i < source.size(); ++i) + { + const quint32 idObject = source.at(i); + const QSharedPointer obj = data->GetGObject(idObject); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(static_cast(obj->getType())) + { + case GOType::Point: + UpdatePoint(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id, dest.at(i).mx, + dest.at(i).my); + break; + case GOType::Arc: + UpdateArc(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::EllipticalArc: + //dest.append(UpdateItem(id, idObject, fPoint, sPoint, suffix, data)); + break; + case GOType::Spline: + UpdateCurve(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::SplinePath: + UpdateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezier: + UpdateCurve(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezierPath: + UpdateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data, + dest.at(i).id); + break; + case GOType::Unknown: + break; + } +QT_WARNING_POP + } + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + + VDrawTool::AddRecord(id, Tool::FlippingByLine, doc); + if (parse == Document::FullParse) + { + VToolFlippingByLine *tool = new VToolFlippingByLine(doc, data, id, firstLinePointId, secondLinePointId, suffix, + source, dest, typeCreation); + scene->addItem(tool); + InitOperationToolConnections(scene, tool); + doc->AddTool(id, tool); + doc->IncrementReferens(firstPoint.getIdTool()); + doc->IncrementReferens(secondPoint.getIdTool()); + for (int i = 0; i < source.size(); ++i) + { + doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool()); + } + return tool; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::SetVisualization() +{ + if (vis != nullptr) + { + VisToolFlippingByLine *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->SetObjects(source); + visual->SetFirstLinePointId(m_firstLinePointId); + visual->SetSecondLinePointId(m_secondLinePointId); + visual->RefreshGeometry(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + DialogFlippingByLine *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + + doc->SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->GetFirstLinePointId())); + doc->SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->GetSecondLinePointId())); + doc->SetAttribute(domElement, AttrSuffix, dialogTool->GetSuffix()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::ReadToolAttributes(const QDomElement &domElement) +{ + m_firstLinePointId = doc->GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); + m_secondLinePointId = doc->GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); + suffix = doc->GetParametrString(domElement, AttrSuffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VDrawTool::SaveOptions(tag, obj); + + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrP1Line, QString().setNum(m_firstLinePointId)); + doc->SetAttribute(tag, AttrP2Line, QString().setNum(m_secondLinePointId)); + doc->SetAttribute(tag, AttrSuffix, suffix); + + SaveSourceDestination(tag); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolFlippingByLine::VToolFlippingByLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstLinePointId, + quint32 secondLinePointId, const QString &suffix, + const QVector &source, const QVector &destination, + const Source &typeCreation, QGraphicsItem *parent) + : VAbstractOperation(doc, data, id, suffix, source, destination, parent), + m_firstLinePointId(firstLinePointId), + m_secondLinePointId(secondLinePointId) +{ + InitOperatedObjects(); + ToolCreation(typeCreation); +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VToolFlippingByLine::CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + + DestinationItem item; + item.mx = rotated.mx(); + item.my = rotated.my(); + item.id = data->AddGObject(new VPointF(rotated)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VToolFlippingByLine::CreateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + data->AddArc(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id, + qreal mx, qreal my) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + rotated.setMx(mx); + rotated.setMy(my); + data->UpdateGObject(id, new VPointF(rotated)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolFlippingByLine::UpdateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + data->AddArc(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolFlippingByLine::CreateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + + DestinationItem item; + item.mx = INT_MAX; + item.my = INT_MAX; + item.id = data->AddGObject(new Item(rotated)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolFlippingByLine::CreateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + data->AddCurve(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolFlippingByLine::CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, + VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + data->AddCurveWithSegments(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolFlippingByLine::UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix); + rotated.setIdObject(idTool); + data->UpdateGObject(id, new Item(rotated)); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolFlippingByLine::UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + data->AddCurve(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolFlippingByLine::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, + quint32 id) +{ + UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + data->AddCurveWithSegments(data->GeometricObject(id), id); +} diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h new file mode 100644 index 000000000..485998b8f --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h @@ -0,0 +1,104 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VTOOLFLIPPINGBYLINE_H +#define VTOOLFLIPPINGBYLINE_H + +#include + +#include "../vabstractoperation.h" + +class VToolFlippingByLine : public VAbstractOperation +{ + Q_OBJECT +public: + virtual ~VToolFlippingByLine(); + virtual void setDialog() Q_DECL_OVERRIDE; + static VToolFlippingByLine* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data); + static VToolFlippingByLine* Create(const quint32 _id, quint32 firstLinePointId, quint32 secondLinePointId, + const QString &suffix, const QVector &source, + const QVector &destination, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation); + + static const QString ToolType; + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Tool::FlippingByLine)}; + + virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; +protected: + virtual void SetVisualization() Q_DECL_OVERRIDE; + virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(VToolFlippingByLine) + + quint32 m_firstLinePointId; + quint32 m_secondLinePointId; + + VToolFlippingByLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstLinePointId, + quint32 secondLinePointId, const QString &suffix, const QVector &source, + const QVector &destination, const Source &typeCreation, + QGraphicsItem *parent = nullptr); + + static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + + template + static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + template + static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + template + static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data); + + static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); + template + static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id); + static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id); + template + static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data, quint32 id); + template + static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, + quint32 id); +}; + +#endif // VTOOLFLIPPINGBYLINE_H diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp new file mode 100644 index 000000000..0a032c3a8 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -0,0 +1,610 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vabstractoperation.h" +#include "../../../undocommands/label/rotationmovelabel.h" +#include "../vgeometry/vpointf.h" + +const QString VAbstractOperation::TagItem = QStringLiteral("item"); +const QString VAbstractOperation::TagSource = QStringLiteral("source"); +const QString VAbstractOperation::TagDestination = QStringLiteral("destination"); + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractOperation::~VAbstractOperation() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractOperation::getTagName() const +{ + return VAbstractPattern::TagOperation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SetEnabled(bool enabled) +{ + this->setEnabled(enabled); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractOperation::Suffix() const +{ + return suffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SetSuffix(const QString &suffix) +{ + // Don't know if need check name here. + this->suffix = suffix; + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::GroupVisibility(quint32 object, bool visible) +{ + if (operatedObjects.contains(object)) + { + VAbstractSimple *obj = operatedObjects.value(object); + if (obj->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(obj); + SCASSERT(item != nullptr); + item->setVisible(visible); + } + else + { + VSimpleCurve *item = qobject_cast(obj); + SCASSERT(item != nullptr); + item->setVisible(visible); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(painter); + Q_UNUSED(option); + Q_UNUSED(widget); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, + QVector &destination) +{ + SCASSERT(doc != nullptr) + const QDomNodeList nodeList = domElement.childNodes(); + for (qint32 i = 0; i < nodeList.size(); ++i) + { + const QDomElement dataElement = nodeList.at(i).toElement(); + if (not dataElement.isNull() && dataElement.tagName() == TagSource) + { + source.clear(); + const QDomNodeList srcList = dataElement.childNodes(); + for (qint32 j = 0; j < srcList.size(); ++j) + { + const QDomElement element = srcList.at(j).toElement(); + if (not element.isNull()) + { + source.append(doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR)); + } + } + } + + if (not dataElement.isNull() && dataElement.tagName() == TagDestination) + { + destination.clear(); + const QDomNodeList srcList = dataElement.childNodes(); + for (qint32 j = 0; j < srcList.size(); ++j) + { + const QDomElement element = srcList.at(j).toElement(); + if (not element.isNull()) + { + DestinationItem d; + d.id = doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR); + d.mx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, QString::number(INT_MAX))); + d.my = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, QString::number(INT_MAX))); + destination.append(d); + } + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::FullUpdateFromFile() +{ + ReadAttributes(); + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); + } + } + SetVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowHover(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSelecting(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowPointHover(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowPointSelecting(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowPointLabelHover(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->AllowLabelHover(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowPointLabelSelecting(bool enabled) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->AllowLabelSelecting(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSplineHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::Spline); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSplineSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::Spline); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSplinePathHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::SplinePath); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowSplinePathSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::SplinePath); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowArcHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::Arc); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowArcSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::Arc); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::Disable(bool disable, const QString &namePP) +{ + enabled = !CorrectDisable(disable, namePP); + SetEnabled(enabled); + + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + i.value()->SetEnabled(enabled); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::ObjectSelected(bool selected, quint32 objId) +{ + emit ChangedToolSelection(selected, objId, id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::DeleteFromLabel() +{ + try + { + DeleteTool(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::LabelChangePosition(const QPointF &pos, quint32 labelId) +{ + if (operatedObjects.contains(labelId)) + { + VAbstractSimple *obj = operatedObjects.value(labelId); + if (obj->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(obj); + SCASSERT(item != nullptr); + ChangePosition(item, labelId, pos); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractOperation::VAbstractOperation(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, + const QVector &source, const QVector &destination, + QGraphicsItem *parent) + : VDrawTool(doc, data, id), + QGraphicsLineItem(parent), + suffix(suffix), + source(source), + destination(destination), + operatedObjects() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AddToFile() +{ + QDomElement domElement = doc->createElement(getTagName()); + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOptions(domElement, obj); + AddToCalculation(domElement); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(id); + if (domElement.isElement()) + { + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOptions(domElement, obj); + } + else + { + qCDebug(vTool, "Can't find tool with id = %u", id); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::UpdateNamePosition(quint32 id) +{ + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + auto moveLabel = new RotationMoveLabel(this->id, doc, point->mx(), point->my(), id); + connect(moveLabel, &RotationMoveLabel::ChangePosition, this, &VAbstractOperation::DoChangePosition); + qApp->getUndoStack()->push(moveLabel); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SaveSourceDestination(QDomElement &tag) +{ + doc->RemoveAllChildren(tag); + + QDomElement tagObjects = doc->createElement(TagSource); + for (int i = 0; i < source.size(); ++i) + { + QDomElement item = doc->createElement(TagItem); + doc->SetAttribute(item, AttrIdObject, source.at(i)); + tagObjects.appendChild(item); + } + tag.appendChild(tagObjects); + + tagObjects = doc->createElement(TagDestination); + for (int i = 0; i < destination.size(); ++i) + { + QDomElement item = doc->createElement(TagItem); + doc->SetAttribute(item, AttrIdObject, destination.at(i).id); + + if (not VFuzzyComparePossibleNulls(destination.at(i).mx, INT_MAX) && + not VFuzzyComparePossibleNulls(destination.at(i).my, INT_MAX)) + { + doc->SetAttribute(item, AttrMx, qApp->fromPixel(destination.at(i).mx)); + doc->SetAttribute(item, AttrMy, qApp->fromPixel(destination.at(i).my)); + } + + tagObjects.appendChild(item); + } + tag.appendChild(tagObjects); +} + +//--------------------------------------------------------------------------------------------------------------------- +VSimpleCurve *VAbstractOperation::InitCurve(quint32 id, VContainer *data, GOType curveType) +{ + VSimpleCurve *curve = new VSimpleCurve(id, QColor(baseColor), *data->GetPatternUnit(), &factor); + curve->setParentItem(this); + curve->SetType(curveType); + connect(curve, &VSimpleCurve::Selected, this, &VAbstractOperation::ObjectSelected); + connect(curve, &VSimpleCurve::ShowContextMenu, [this](QGraphicsSceneContextMenuEvent * event) + { + contextMenuEvent(event); + }); + connect(curve, &VSimpleCurve::Delete, this, &VAbstractOperation::DeleteFromLabel); + curve->RefreshGeometry(VAbstractTool::data.GeometricObject(id)); + operatedObjects.insert(id, curve); + return curve; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::DoChangePosition(quint32 id, qreal mx, qreal my) +{ + if (operatedObjects.contains(id)) + { + VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); + point->setMx(mx); + point->setMy(my); + VAbstractTool::data.UpdateGObject(id, point); + + VSimplePoint *item = qobject_cast(operatedObjects.value(id)); + SCASSERT(item != nullptr); + + item->RefreshGeometry(*point); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowCurveHover(bool enabled, GOType type) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() != GOType::Point) + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + if (item->GetType() == type) + { + item->setAcceptHoverEvents(enabled); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::AllowCurveSelecting(bool enabled, GOType type) +{ + QMapIterator i(operatedObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() != GOType::Point) + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + if (item->GetType() == type) + { + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos) +{ + const QPointF p = pos - item->pos(); + DoChangePosition(id, p.x(), p.y()); + UpdateNamePosition(id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::InitOperatedObjects() +{ + for (int i = 0; i < destination.size(); ++i) + { + const DestinationItem object = destination.at(i); + const QSharedPointer obj = VAbstractTool::data.GetGObject(object.id); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + VSimplePoint *point = new VSimplePoint(object.id, QColor(baseColor), + *VAbstractTool::data.GetPatternUnit(), &factor); + point->setParentItem(this); + point->SetType(GOType::Point); + connect(point, &VSimplePoint::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Point); + }); + connect(point, &VSimplePoint::Selected, this, &VAbstractOperation::ObjectSelected); + connect(point, &VSimplePoint::ShowContextMenu, [this](QGraphicsSceneContextMenuEvent * event) + { + contextMenuEvent(event); + }); + connect(point, &VSimplePoint::Delete, this, &VAbstractOperation::DeleteFromLabel); + connect(point, &VSimplePoint::NameChangedPosition, this, &VAbstractOperation::LabelChangePosition); + point->RefreshGeometry(*VAbstractTool::data.GeometricObject(object.id)); + operatedObjects.insert(object.id, point); + break; + } + case GOType::Arc: + case GOType::EllipticalArc: + { + VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), GOType::Arc); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Arc); + }); + break; + } + case GOType::Spline: + case GOType::CubicBezier: + { + VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), GOType::Spline); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Spline); + }); + break; + } + case GOType::SplinePath: + case GOType::CubicBezierPath: + { + VSimpleCurve *curve = InitCurve(object.id, &(VAbstractTool::data), GOType::SplinePath); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::SplinePath); + }); + break; + } + case GOType::Unknown: + break; + } +QT_WARNING_POP + } +} diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h new file mode 100644 index 000000000..e10123df3 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -0,0 +1,203 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VABSTRACTOPERATION_H +#define VABSTRACTOPERATION_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../vdrawtool.h" +#include "../vwidgets/vsimplecurve.h" +#include "../vwidgets/vsimplepoint.h" + +struct DestinationItem +{ + quint32 id; + qreal mx; + qreal my; +}; + +class VAbstractSimple; +class VAbstractPattern; +class QDomElement; +class QPainter; +class QPointF; +class QStyleOptionGraphicsItem; +class QWidget; +class VContainer; + +// FIXME. I don't know how to use QGraphicsItem properly, so just took first available finished class. +// QGraphicsItem itself produce case where clicking on empty space produce call to QGraphicsItem. +// And i don't know how to fix it. +class VAbstractOperation : public VDrawTool, public QGraphicsLineItem +{ + Q_OBJECT + // Fix warning "Class implements the interface QGraphicsItem but does not list it + // in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!" + Q_INTERFACES(QGraphicsItem) +public: + virtual ~VAbstractOperation(); + + static const QString TagItem; + static const QString TagSource; + static const QString TagDestination; + + virtual QString getTagName() const Q_DECL_OVERRIDE; + + void SetEnabled(bool enabled); + + QString Suffix() const; + void SetSuffix(const QString &suffix); + + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE; + + static void ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, + QVector &destination); +public slots: + virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; + virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; + + virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; + virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; + + void AllowPointHover(bool enabled); + void AllowPointSelecting(bool enabled); + + void AllowPointLabelHover(bool enabled); + void AllowPointLabelSelecting(bool enabled); + + void AllowSplineHover(bool enabled); + void AllowSplineSelecting(bool enabled); + + void AllowSplinePathHover(bool enabled); + void AllowSplinePathSelecting(bool enabled); + + void AllowArcHover(bool enabled); + void AllowArcSelecting(bool enabled); + + virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; + void ObjectSelected(bool selected, quint32 objId); + void DeleteFromLabel(); + void LabelChangePosition(const QPointF &pos, quint32 labelId); +protected: + QString suffix; + + QVector source; + QVector destination; + + QMap operatedObjects; + + VAbstractOperation(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, + const QVector &source, const QVector &destination, + QGraphicsItem *parent = nullptr); + + virtual void AddToFile() Q_DECL_OVERRIDE; + virtual void RefreshDataInFile() Q_DECL_OVERRIDE; + + void UpdateNamePosition(quint32 id); + void SaveSourceDestination(QDomElement &tag); + + template + void ShowToolVisualization(bool show); + + VSimpleCurve *InitCurve(quint32 id, VContainer *data, GOType curveType); + + template + static void InitOperationToolConnections(VMainGraphicsScene *scene, T *tool); + + void InitOperatedObjects(); +protected slots: + void DoChangePosition(quint32 id, qreal mx, qreal my); +private: + Q_DISABLE_COPY(VAbstractOperation) + + void AllowCurveHover(bool enabled, GOType type); + void AllowCurveSelecting(bool enabled, GOType type); + + void ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos); +}; + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractOperation::ShowToolVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + AddVisualization(); + SetVisualization(); + } + else + { + if (T *visual = qobject_cast(vis)) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractOperation::InitOperationToolConnections(VMainGraphicsScene *scene, T *tool) +{ + SCASSERT(scene != nullptr); + SCASSERT(tool != nullptr); + + InitDrawToolConnections(scene, tool); + + QObject::connect(scene, &VMainGraphicsScene::EnablePointItemHover, tool, &T::AllowPointHover); + QObject::connect(scene, &VMainGraphicsScene::EnablePointItemSelection, tool, &T::AllowPointSelecting); + QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemHover, tool, &T::AllowPointLabelHover); + QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemSelection, tool, &T::AllowPointLabelSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemHover, tool, &T::AllowSplineHover); + QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemSelection, tool, &T::AllowSplineSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemHover, tool, &T::AllowSplinePathHover); + QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemSelection, tool, &T::AllowSplinePathSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableArcItemHover, tool, &T::AllowArcHover); + QObject::connect(scene, &VMainGraphicsScene::EnableArcItemSelection, tool, &T::AllowArcSelecting); +} + +#endif // VABSTRACTOPERATION_H diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index 07d80ff05..a02019573 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -44,8 +44,7 @@ #include "../../../dialogs/tools/dialogtool.h" #include "../../../dialogs/tools/dialogrotation.h" -#include "../../../undocommands/label/rotationmovelabel.h" -#include "../../../visualization/line/vistoolrotation.h" +#include "../../../visualization/line/operation/vistoolrotation.h" #include "../../../visualization/visualization.h" #include "../vgeometry/vabstractcurve.h" #include "../vgeometry/varc.h" @@ -66,8 +65,6 @@ #include "../ifc/exception/vexception.h" #include "../vwidgets/vabstractsimple.h" #include "../vwidgets/vmaingraphicsscene.h" -#include "../vwidgets/vsimplecurve.h" -#include "../vwidgets/vsimplepoint.h" #include "../../vabstracttool.h" #include "../../vdatatool.h" #include "../vdrawtool.h" @@ -79,90 +76,18 @@ class QStyleOptionGraphicsItem; class QWidget; template class QSharedPointer; -const QString VToolRotation::ToolType = QStringLiteral("rotation"); -const QString VToolRotation::TagItem = QStringLiteral("item"); -const QString VToolRotation::TagSource = QStringLiteral("source"); -const QString VToolRotation::TagDestination = QStringLiteral("destination"); +const QString VToolRotation::ToolType = QStringLiteral("rotation"); //--------------------------------------------------------------------------------------------------------------------- VToolRotation::VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, const QString &angle, const QString &suffix, const QVector &source, const QVector &destination, const Source &typeCreation, QGraphicsItem *parent) - : VDrawTool(doc, data, id), - QGraphicsLineItem(parent), + : VAbstractOperation(doc, data, id, suffix, source, destination, parent), origPointId(origPointId), - formulaAngle(angle), - suffix(suffix), - source(source), - destination(destination), - rObjects() + formulaAngle(angle) { - for (int i = 0; i < destination.size(); ++i) - { - const DestinationItem object = destination.at(i); - const QSharedPointer obj = data->GetGObject(object.id); - - // This check helps to find missed objects in the switch - Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); - -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wswitch-default") - switch(static_cast(obj->getType())) - { - case GOType::Point: - { - VSimplePoint *point = new VSimplePoint(object.id, QColor(baseColor), *data->GetPatternUnit(), &factor); - point->setParentItem(this); - point->SetType(GOType::Point); - connect(point, &VSimplePoint::Choosed, [this](quint32 id) - { - emit ChoosedTool(id, SceneObject::Point); - }); - connect(point, &VSimplePoint::Selected, this, &VToolRotation::ObjectSelected); - connect(point, &VSimplePoint::ShowContextMenu, this, &VToolRotation::contextMenuEvent); - connect(point, &VSimplePoint::Delete, this, &VToolRotation::DeleteFromLabel); - connect(point, &VSimplePoint::NameChangedPosition, this, &VToolRotation::LabelChangePosition); - point->RefreshGeometry(*VAbstractTool::data.GeometricObject(object.id)); - rObjects.insert(object.id, point); - break; - } - case GOType::Arc: - case GOType::EllipticalArc: - { - VSimpleCurve *curve = InitCurve(object.id, data, GOType::Arc); - connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) - { - emit ChoosedTool(id, SceneObject::Arc); - }); - break; - } - case GOType::Spline: - case GOType::CubicBezier: - { - VSimpleCurve *curve = InitCurve(object.id, data, GOType::Spline); - connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) - { - emit ChoosedTool(id, SceneObject::Spline); - }); - break; - } - case GOType::SplinePath: - case GOType::CubicBezierPath: - { - VSimpleCurve *curve = InitCurve(object.id, data, GOType::SplinePath); - connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) - { - emit ChoosedTool(id, SceneObject::SplinePath); - }); - break; - } - case GOType::Unknown: - break; - } -QT_WARNING_POP - } - + InitOperatedObjects(); ToolCreation(typeCreation); } @@ -317,7 +242,7 @@ QT_WARNING_POP { VToolRotation *tool = new VToolRotation(doc, data, id, origin, angle, suffix, source, dest, typeCreation); scene->addItem(tool); - InitRotationToolConnections(scene, tool); + InitOperationToolConnections(scene, tool); doc->AddTool(id, tool); doc->IncrementReferens(originPoint.getIdTool()); for (int i = 0; i < source.size(); ++i) @@ -329,61 +254,6 @@ QT_WARNING_POP return nullptr; } -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, - QVector &destination) -{ - SCASSERT(doc != nullptr) - const QDomNodeList nodeList = domElement.childNodes(); - for (qint32 i = 0; i < nodeList.size(); ++i) - { - const QDomElement dataElement = nodeList.at(i).toElement(); - if (not dataElement.isNull() && dataElement.tagName() == TagSource) - { - source.clear(); - const QDomNodeList srcList = dataElement.childNodes(); - for (qint32 j = 0; j < srcList.size(); ++j) - { - const QDomElement element = srcList.at(j).toElement(); - if (not element.isNull()) - { - source.append(doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR)); - } - } - } - - if (not dataElement.isNull() && dataElement.tagName() == TagDestination) - { - destination.clear(); - const QDomNodeList srcList = dataElement.childNodes(); - for (qint32 j = 0; j < srcList.size(); ++j) - { - const QDomElement element = srcList.at(j).toElement(); - if (not element.isNull()) - { - DestinationItem d; - d.id = doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR); - d.mx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, QString::number(INT_MAX))); - d.my = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, QString::number(INT_MAX))); - destination.append(d); - } - } - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VToolRotation::getTagName() const -{ - return VAbstractPattern::TagOperation; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::SetEnabled(bool enabled) -{ - this->setEnabled(enabled); -} - //--------------------------------------------------------------------------------------------------------------------- VFormula VToolRotation::GetFormulaAngle() const { @@ -406,263 +276,12 @@ void VToolRotation::SetFormulaAngle(const VFormula &value) } } -//--------------------------------------------------------------------------------------------------------------------- -QString VToolRotation::Suffix() const -{ - return suffix; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::SetSuffix(const QString &suffix) -{ - // Don't know if need check name here. - this->suffix = suffix; - QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); - SaveOption(obj); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::GroupVisibility(quint32 object, bool visible) -{ - if (rObjects.contains(object)) - { - VAbstractSimple *obj = rObjects.value(object); - if (obj->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(obj); - SCASSERT(item != nullptr); - item->setVisible(visible); - } - else - { - VSimpleCurve *item = qobject_cast(obj); - SCASSERT(item != nullptr); - item->setVisible(visible); - } - } -} - //--------------------------------------------------------------------------------------------------------------------- void VToolRotation::ShowVisualization(bool show) { ShowToolVisualization(show); } -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::FullUpdateFromFile() -{ - ReadAttributes(); - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); - } - } - SetVisualization(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowHover(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setAcceptHoverEvents(enabled); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setAcceptHoverEvents(enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSelecting(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowPointHover(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setAcceptHoverEvents(enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowPointSelecting(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowPointLabelHover(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->AllowLabelHover(enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowPointLabelSelecting(bool enabled) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - item->AllowLabelSelecting(enabled); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSplineHover(bool enabled) -{ - AllowCurveHover(enabled, GOType::Spline); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSplineSelecting(bool enabled) -{ - AllowCurveSelecting(enabled, GOType::Spline); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSplinePathHover(bool enabled) -{ - AllowCurveHover(enabled, GOType::SplinePath); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowSplinePathSelecting(bool enabled) -{ - AllowCurveSelecting(enabled, GOType::SplinePath); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowArcHover(bool enabled) -{ - AllowCurveHover(enabled, GOType::Arc); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowArcSelecting(bool enabled) -{ - AllowCurveSelecting(enabled, GOType::Arc); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AddToFile() -{ - QDomElement domElement = doc->createElement(getTagName()); - QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); - SaveOptions(domElement, obj); - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::RefreshDataInFile() -{ - QDomElement domElement = doc->elementById(id); - if (domElement.isElement()) - { - QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); - SaveOptions(domElement, obj); - } - else - { - qCDebug(vTool, "Can't find tool with id = %u", id); - } -} - //--------------------------------------------------------------------------------------------------------------------- void VToolRotation::SetVisualization() { @@ -678,63 +297,6 @@ void VToolRotation::SetVisualization() } } -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(painter); - Q_UNUSED(option); - Q_UNUSED(widget); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::Disable(bool disable, const QString &namePP) -{ - enabled = !CorrectDisable(disable, namePP); - SetEnabled(enabled); - - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - i.value()->SetEnabled(enabled); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::ObjectSelected(bool selected, quint32 objId) -{ - emit ChangedToolSelection(selected, objId, id); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::DeleteFromLabel() -{ - try - { - DeleteTool(); - } - catch(const VExceptionToolWasDeleted &e) - { - Q_UNUSED(e); - return;//Leave this method immediately!!! - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::LabelChangePosition(const QPointF &pos, quint32 labelId) -{ - if (rObjects.contains(labelId)) - { - VAbstractSimple *obj = rObjects.value(labelId); - if (obj->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(obj); - SCASSERT(item != nullptr); - ChangePosition(item, labelId, pos); - } - } -} - //--------------------------------------------------------------------------------------------------------------------- void VToolRotation::SaveDialog(QDomElement &domElement) { @@ -765,33 +327,7 @@ void VToolRotation::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrAngle, formulaAngle); doc->SetAttribute(tag, AttrSuffix, suffix); - doc->RemoveAllChildren(tag); - - QDomElement tagObjects = doc->createElement(TagSource); - for (int i = 0; i < source.size(); ++i) - { - QDomElement item = doc->createElement(TagItem); - doc->SetAttribute(item, AttrIdObject, source.at(i)); - tagObjects.appendChild(item); - } - tag.appendChild(tagObjects); - - tagObjects = doc->createElement(TagDestination); - for (int i = 0; i < destination.size(); ++i) - { - QDomElement item = doc->createElement(TagItem); - doc->SetAttribute(item, AttrIdObject, destination.at(i).id); - - if (not VFuzzyComparePossibleNulls(destination.at(i).mx, INT_MAX) && - not VFuzzyComparePossibleNulls(destination.at(i).my, INT_MAX)) - { - doc->SetAttribute(item, AttrMx, qApp->fromPixel(destination.at(i).mx)); - doc->SetAttribute(item, AttrMy, qApp->fromPixel(destination.at(i).my)); - } - - tagObjects.appendChild(item); - } - tag.appendChild(tagObjects); + SaveSourceDestination(tag); } //--------------------------------------------------------------------------------------------------------------------- @@ -808,32 +344,6 @@ void VToolRotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) } } -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::DoChangePosition(quint32 id, qreal mx, qreal my) -{ - if (rObjects.contains(id)) - { - VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); - point->setMx(mx); - point->setMy(my); - VAbstractTool::data.UpdateGObject(id, point); - - VSimplePoint *item = qobject_cast(rObjects.value(id)); - SCASSERT(item != nullptr); - - item->RefreshGeometry(*point); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::UpdateNamePosition(quint32 id) -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - auto moveLabel = new RotationMoveLabel(this->id, doc, point->mx(), point->my(), id); - connect(moveLabel, &RotationMoveLabel::ChangePosition, this, &VToolRotation::DoChangePosition); - qApp->getUndoStack()->push(moveLabel); -} - //--------------------------------------------------------------------------------------------------------------------- DestinationItem VToolRotation::CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data) @@ -942,121 +452,3 @@ void VToolRotation::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, cons UpdateItem(idTool, idItem, origin, angle, suffix, data, id); data->AddCurveWithSegments(data->GeometricObject(id), id); } - -//--------------------------------------------------------------------------------------------------------------------- -template -void VToolRotation::ShowToolVisualization(bool show) -{ - if (show) - { - if (vis == nullptr) - { - AddVisualization(); - SetVisualization(); - } - else - { - if (T *visual = qobject_cast(vis)) - { - visual->show(); - } - } - } - else - { - delete vis; - vis = nullptr; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos) -{ - const QPointF p = pos - item->pos(); - DoChangePosition(id, p.x(), p.y()); - UpdateNamePosition(id); -} - -//--------------------------------------------------------------------------------------------------------------------- -VSimpleCurve *VToolRotation::InitCurve(quint32 id, VContainer *data, GOType curveType) -{ - VSimpleCurve *curve = new VSimpleCurve(id, QColor(baseColor), *data->GetPatternUnit(), &factor); - curve->setParentItem(this); - curve->SetType(curveType); - connect(curve, &VSimpleCurve::Selected, this, &VToolRotation::ObjectSelected); - connect(curve, &VSimpleCurve::ShowContextMenu, this, &VToolRotation::contextMenuEvent); - connect(curve, &VSimpleCurve::Delete, this, &VToolRotation::DeleteFromLabel); - curve->RefreshGeometry(VAbstractTool::data.GeometricObject(id)); - rObjects.insert(id, curve); - return curve; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowCurveHover(bool enabled, GOType type) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() != GOType::Point) - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - if (item->GetType() == type) - { - item->setAcceptHoverEvents(enabled); - } - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AllowCurveSelecting(bool enabled, GOType type) -{ - QMapIterator i(rObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() != GOType::Point) - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr); - if (item->GetType() == type) - { - item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); - } - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::AddSourceObject(VAbstractPattern *doc, QDomElement &domElement, quint32 objId) -{ - QDomElement obj = doc->createElement(TagItem); - doc->SetAttribute(obj, AttrIdObject, objId); - domElement.appendChild(obj); -} - -//--------------------------------------------------------------------------------------------------------------------- -template -void VToolRotation::InitRotationToolConnections(VMainGraphicsScene *scene, T *tool) -{ - SCASSERT(scene != nullptr); - SCASSERT(tool != nullptr); - - InitDrawToolConnections(scene, tool); - - QObject::connect(scene, &VMainGraphicsScene::EnablePointItemHover, tool, &T::AllowPointHover); - QObject::connect(scene, &VMainGraphicsScene::EnablePointItemSelection, tool, &T::AllowPointSelecting); - QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemHover, tool, &T::AllowPointLabelHover); - QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemSelection, tool, &T::AllowPointLabelSelecting); - - QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemHover, tool, &T::AllowSplineHover); - QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemSelection, tool, &T::AllowSplineSelecting); - - QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemHover, tool, &T::AllowSplinePathHover); - QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemSelection, tool, &T::AllowSplinePathSelecting); - - QObject::connect(scene, &VMainGraphicsScene::EnableArcItemHover, tool, &T::AllowArcHover); - QObject::connect(scene, &VMainGraphicsScene::EnableArcItemSelection, tool, &T::AllowArcSelecting); -} diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h index 41e54cda2..0920158db 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h @@ -30,18 +30,14 @@ #define VTOOLROTATION_H #include -#include -#include -#include #include #include #include -#include #include #include #include -#include "../vdrawtool.h" +#include "vabstractoperation.h" #include "../vgeometry/vgeometrydef.h" #include "../vmisc/def.h" #include "../ifc/xml/vabstractpattern.h" @@ -49,35 +45,16 @@ class DialogTool; class QDomElement; class QGraphicsSceneContextMenuEvent; -class QPainter; class QPointF; -class QStyleOptionGraphicsItem; -class QWidget; class VContainer; class VGObject; class VMainGraphicsScene; template class QSharedPointer; - -struct DestinationItem -{ - quint32 id; - qreal mx; - qreal my; -}; - -class VAbstractSimple; class VFormula; -class VSimpleCurve; -// FIXME. I don't know how to use QGraphicsItem properly, so just took first available finished class. -// QGraphicsItem itself produce case where clicking on empty space produce call to QGraphicsItem. -// And i don't know how to fix it. -class VToolRotation : public VDrawTool, public QGraphicsLineItem +class VToolRotation : public VAbstractOperation { Q_OBJECT - // Fix warning "Class implements the interface QGraphicsItem but does not list it - // in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!" - Q_INTERFACES(QGraphicsItem) public: virtual ~VToolRotation(); virtual void setDialog() Q_DECL_OVERRIDE; @@ -87,85 +64,34 @@ public: const QVector &source, const QVector &destination, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); - static void ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector &source, - QVector &destination); + static const QString ToolType; - static const QString TagItem; - static const QString TagSource; - static const QString TagDestination; + virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::Rotation)}; - virtual QString getTagName() const Q_DECL_OVERRIDE; - - void SetEnabled(bool enabled); VFormula GetFormulaAngle() const; void SetFormulaAngle(const VFormula &value); - QString Suffix() const; - void SetSuffix(const QString &suffix); - - virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE; - -public slots: - virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; - - virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; - virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; - - void AllowPointHover(bool enabled); - void AllowPointSelecting(bool enabled); - - void AllowPointLabelHover(bool enabled); - void AllowPointLabelSelecting(bool enabled); - - void AllowSplineHover(bool enabled); - void AllowSplineSelecting(bool enabled); - - void AllowSplinePathHover(bool enabled); - void AllowSplinePathSelecting(bool enabled); - - void AllowArcHover(bool enabled); - void AllowArcSelecting(bool enabled); - - virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; - void ObjectSelected(bool selected, quint32 objId); - void DeleteFromLabel(); - void LabelChangePosition(const QPointF &pos, quint32 labelId); protected: - virtual void AddToFile() Q_DECL_OVERRIDE; - virtual void RefreshDataInFile() Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; -private slots: - void DoChangePosition(quint32 id, qreal mx, qreal my); - private: Q_DISABLE_COPY(VToolRotation) quint32 origPointId; QString formulaAngle; - QString suffix; - - QVector source; - QVector destination; - - QMap rObjects; VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, const QString &formulaAngle, const QString &suffix, const QVector &source, const QVector &destination, const Source &typeCreation, QGraphicsItem *parent = nullptr); - void UpdateNamePosition(quint32 id); - static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data); @@ -178,8 +104,8 @@ private: static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data); template - static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, - const QString &suffix, VContainer *data); + static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, + qreal formulaAngle, const QString &suffix, VContainer *data); static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); @@ -194,21 +120,6 @@ private: template static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle, const QString &suffix, VContainer *data, quint32 id); - - template - void ShowToolVisualization(bool show); - - void ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos); - - VSimpleCurve *InitCurve(quint32 id, VContainer *data, GOType curveType); - - template - static void InitRotationToolConnections(VMainGraphicsScene *scene, T *tool); - - void AllowCurveHover(bool enabled, GOType type); - void AllowCurveSelecting(bool enabled, GOType type); - - static void AddSourceObject(VAbstractPattern *doc, QDomElement &domElement, quint32 objId); }; #endif // VTOOLROTATION_H diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 0391ca475..f50749a81 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -51,7 +51,9 @@ HEADERS += \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h \ $$PWD/drawTools/operation/vtoolrotation.h \ - $$PWD/vtextgraphicsitem.h + $$PWD/vtextgraphicsitem.h \ + $$PWD/drawTools/operation/flipping/vtoolflippingbyline.h \ + $$PWD/drawTools/operation/vabstractoperation.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -100,4 +102,6 @@ SOURCES += \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp \ $$PWD/drawTools/operation/vtoolrotation.cpp \ - $$PWD/vtextgraphicsitem.cpp + $$PWD/vtextgraphicsitem.cpp \ + $$PWD/drawTools/operation/flipping/vtoolflippingbyline.cpp \ + $$PWD/drawTools/operation/vabstractoperation.cpp diff --git a/src/libs/vtools/visualization/line/operation/visoperation.cpp b/src/libs/vtools/visualization/line/operation/visoperation.cpp new file mode 100644 index 000000000..56628e3cb --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/visoperation.cpp @@ -0,0 +1,99 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "visoperation.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisOperation::VisOperation(const VContainer *data, QGraphicsItem *parent) + : VisLine(data, parent), + objects(), + supportColor2(Qt::darkGreen), + points(), + curves() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +VisOperation::~VisOperation() +{ + qDeleteAll(points); + qDeleteAll(curves); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisOperation::SetObjects(QVector objects) +{ + this->objects = objects; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisOperation::VisualMode(const quint32 &pointId) +{ + Q_UNUSED(pointId); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + + Visualization::scenePos = scene->getScenePos(); + RefreshGeometry(); + + AddOnScene(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *VisOperation::GetPoint(quint32 i, const QColor &color) +{ + if (not points.isEmpty() && static_cast(points.size() - 1) >= i) + { + return points.at(static_cast(i)); + } + else + { + auto point = InitPoint(color, this); + points.append(point); + return point; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsPathItem *VisOperation::GetCurve(quint32 i, const QColor &color) +{ + if (not curves.isEmpty() && static_cast(curves.size() - 1) >= i) + { + return curves.at(static_cast(i)); + } + else + { + auto curve = InitItem(color, this); + curves.append(curve); + return curve; + } + return nullptr; +} + diff --git a/src/libs/vtools/visualization/line/operation/visoperation.h b/src/libs/vtools/visualization/line/operation/visoperation.h new file mode 100644 index 000000000..fe4628f04 --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/visoperation.h @@ -0,0 +1,62 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VISOPERATION_H +#define VISOPERATION_H + +#include + +#include "../visline.h" + +class VisOperation : public VisLine +{ + Q_OBJECT +public: + explicit VisOperation(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisOperation(); + + void SetObjects(QVector objects); + + virtual void VisualMode(const quint32 &pointId = NULL_ID) Q_DECL_OVERRIDE; + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolRotation)}; +protected: + QVector objects; + QColor supportColor2; + + QVector points; + QVector curves; + + QGraphicsEllipseItem * GetPoint(quint32 i, const QColor &color); + QGraphicsPathItem * GetCurve(quint32 i, const QColor &color); +private: + Q_DISABLE_COPY(VisOperation) +}; + +#endif // VISOPERATION_H diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp new file mode 100644 index 000000000..0e66bf5b9 --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp @@ -0,0 +1,185 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vistoolflippingbyline.h" +#include "../vgeometry/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" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolFlippingByLine::VisToolFlippingByLine(const VContainer *data, QGraphicsItem *parent) + : VisOperation(data, parent), + object2Id(NULL_ID), + point1(nullptr), + point2(nullptr) +{ + point1 = InitPoint(supportColor2, this); + point2 = InitPoint(supportColor2, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolFlippingByLine::~VisToolFlippingByLine() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") +void VisToolFlippingByLine::RefreshGeometry() +{ + if (objects.isEmpty()) + { + return; + } + + QPointF firstPoint; + QPointF secondPoint; + + if (object1Id != NULL_ID) + { + firstPoint = *Visualization::data->GeometricObject(object1Id); + DrawPoint(point1, firstPoint, supportColor2); + + if (object2Id == NULL_ID) + { + secondPoint = Visualization::scenePos; + } + else + { + secondPoint = *Visualization::data->GeometricObject(object2Id); + DrawPoint(point2, secondPoint, supportColor2); + } + + DrawLine(this, QLineF(firstPoint, secondPoint), supportColor2, Qt::DashLine); + } + + int iPoint = -1; + int iCurve = -1; + for (int i = 0; i < objects.size(); ++i) + { + const quint32 id = objects.at(i); + const QSharedPointer obj = Visualization::data->GetGObject(id); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + const QSharedPointer p = Visualization::data->GeometricObject(id); + + ++iPoint; + QGraphicsEllipseItem *point = GetPoint(iPoint, supportColor2); + DrawPoint(point, *p, supportColor2); + + ++iPoint; + point = GetPoint(iPoint, supportColor); + + if (object1Id != NULL_ID) + { + DrawPoint(point, p->Flip(QLineF(firstPoint, secondPoint)), supportColor); + } + break; + } + case GOType::Arc: + { + iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::EllipticalArc: + { + iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::Spline: + { + iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::SplinePath: + { + iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::CubicBezier: + { + iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::CubicBezierPath: + { + iCurve = AddCurve(firstPoint, secondPoint, id, iCurve); + break; + } + case GOType::Unknown: + break; + } + } +} +QT_WARNING_POP + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByLine::SetFirstLinePointId(quint32 value) +{ + object1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolFlippingByLine::SetSecondLinePointId(quint32 value) +{ + object2Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +int VisToolFlippingByLine::AddCurve(const QPointF &firstPoint, const QPointF &secondPoint, quint32 id, int i) +{ + const QSharedPointer curve = Visualization::data->template GeometricObject(id); + + ++i; + QGraphicsPathItem *path = GetCurve(i, supportColor2); + DrawPath(path, curve->GetPath(PathDirection::Show), supportColor2, Qt::SolidLine, Qt::RoundCap); + + ++i; + path = GetCurve(i, supportColor); + if (object1Id != NULL_ID) + { + const Item flipped = curve->Flip(QLineF(firstPoint, secondPoint)); + DrawPath(path, flipped.GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + } + + return i; +} diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h new file mode 100644 index 000000000..4e9160654 --- /dev/null +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h @@ -0,0 +1,60 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 12 9, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VISTOOLFLIPPINGBYLINE_H +#define VISTOOLFLIPPINGBYLINE_H + +#include + +#include "visoperation.h" + +class VisToolFlippingByLine : public VisOperation +{ + Q_OBJECT +public: + explicit VisToolFlippingByLine(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolFlippingByLine(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + + void SetFirstLinePointId(quint32 value); + void SetSecondLinePointId(quint32 value); + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolFlippingByLine)}; +private: + Q_DISABLE_COPY(VisToolFlippingByLine) + quint32 object2Id; + QGraphicsEllipseItem *point1; + QGraphicsEllipseItem *point2; + + template + int AddCurve(const QPointF &firstPoint, const QPointF &secondPoint, quint32 id, int i); +}; + +#endif // VISTOOLFLIPPINGBYLINE_H diff --git a/src/libs/vtools/visualization/line/vistoolrotation.cpp b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp similarity index 80% rename from src/libs/vtools/visualization/line/vistoolrotation.cpp rename to src/libs/vtools/visualization/line/operation/vistoolrotation.cpp index 2101cfb46..b2179db23 100644 --- a/src/libs/vtools/visualization/line/vistoolrotation.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp @@ -53,22 +53,17 @@ #include "../vmisc/vabstractapplication.h" #include "../vpatterndb/vcontainer.h" #include "../vwidgets/vmaingraphicsscene.h" -#include "../visualization.h" -#include "visline.h" +#include "visoperation.h" class QPointF; //--------------------------------------------------------------------------------------------------------------------- VisToolRotation::VisToolRotation(const VContainer *data, QGraphicsItem *parent) - : VisLine(data, parent), + : VisOperation(data, parent), angle(INT_MIN), - objects(), point(nullptr), angleArc(nullptr), - xAxis(nullptr), - supportColor2(Qt::darkGreen), - points(), - curves() + xAxis(nullptr) { point = InitPoint(supportColor2, this); angleArc = InitItem(supportColor2, this); @@ -78,8 +73,6 @@ VisToolRotation::VisToolRotation(const VContainer *data, QGraphicsItem *parent) //--------------------------------------------------------------------------------------------------------------------- VisToolRotation::~VisToolRotation() { - qDeleteAll(points); - qDeleteAll(curves); } //--------------------------------------------------------------------------------------------------------------------- @@ -198,12 +191,6 @@ void VisToolRotation::RefreshGeometry() QT_WARNING_POP -//--------------------------------------------------------------------------------------------------------------------- -void VisToolRotation::SetObjects(QVector objects) -{ - this->objects = objects; -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolRotation::SetOriginPointId(quint32 value) { @@ -222,51 +209,6 @@ void VisToolRotation::SetAngle(const QString &expression) angle = FindVal(expression, Visualization::data->PlainVariables()); } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolRotation::VisualMode(const quint32 &pointId) -{ - Q_UNUSED(pointId); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr); - - Visualization::scenePos = scene->getScenePos(); - RefreshGeometry(); - - AddOnScene(); -} - -//--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *VisToolRotation::GetPoint(quint32 i, const QColor &color) -{ - if (not points.isEmpty() && static_cast(points.size() - 1) >= i) - { - return points.at(static_cast(i)); - } - else - { - auto point = InitPoint(color, this); - points.append(point); - return point; - } - return nullptr; -} - -//--------------------------------------------------------------------------------------------------------------------- -QGraphicsPathItem *VisToolRotation::GetCurve(quint32 i, const QColor &color) -{ - if (not curves.isEmpty() && static_cast(curves.size() - 1) >= i) - { - return curves.at(static_cast(i)); - } - else - { - auto curve = InitItem(color, this); - curves.append(curve); - return curve; - } - return nullptr; -} - //--------------------------------------------------------------------------------------------------------------------- template int VisToolRotation::AddCurve(qreal angle, const QPointF &origin, quint32 id, int i) diff --git a/src/libs/vtools/visualization/line/vistoolrotation.h b/src/libs/vtools/visualization/line/operation/vistoolrotation.h similarity index 82% rename from src/libs/vtools/visualization/line/vistoolrotation.h rename to src/libs/vtools/visualization/line/operation/vistoolrotation.h index 988fff1a7..2f262dcc2 100644 --- a/src/libs/vtools/visualization/line/vistoolrotation.h +++ b/src/libs/vtools/visualization/line/operation/vistoolrotation.h @@ -41,12 +41,12 @@ #include "../ifc/ifcdef.h" #include "../vmisc/def.h" -#include "visline.h" +#include "visoperation.h" class QPointF; class VContainer; -class VisToolRotation : public VisLine +class VisToolRotation : public VisOperation { Q_OBJECT public: @@ -55,30 +55,19 @@ public: virtual void RefreshGeometry() Q_DECL_OVERRIDE; - void SetObjects(QVector objects); void SetOriginPointId(quint32 value); QString Angle() const; void SetAngle(const QString &expression); - virtual void VisualMode(const quint32 &pointId = NULL_ID) Q_DECL_OVERRIDE; - virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolRotation)}; private: Q_DISABLE_COPY(VisToolRotation) qreal angle; - QVector objects; QGraphicsEllipseItem *point; QGraphicsPathItem *angleArc; QGraphicsLineItem *xAxis; - QColor supportColor2; - - QVector points; - QVector curves; - - QGraphicsEllipseItem * GetPoint(quint32 i, const QColor &color); - QGraphicsPathItem * GetCurve(quint32 i, const QColor &color); template int AddCurve(qreal angle, const QPointF &origin, quint32 id, int i); diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index fce6c442e..6de291625 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -22,6 +22,8 @@ HEADERS += \ $$PWD/line/vistoolpointofintersectioncircles.h \ $$PWD/line/vistoolpointfromcircleandtangent.h \ $$PWD/line/vistoolpointfromarcandtangent.h \ + $$PWD/line/operation/vistoolrotation.h \ + $$PWD/line/operation/vistoolflippingbyline.h \ $$PWD/path/vispath.h \ $$PWD/path/vistoolarc.h \ $$PWD/path/vistoolcutarc.h \ @@ -33,7 +35,7 @@ HEADERS += \ $$PWD/path/vistoolpointofintersectioncurves.h \ $$PWD/path/vistoolcubicbezier.h \ $$PWD/path/vistoolcubicbezierpath.h \ - visualization/line/vistoolrotation.h + $$PWD/line/operation/visoperation.h SOURCES += \ $$PWD/visualization.cpp \ @@ -56,6 +58,8 @@ SOURCES += \ $$PWD/line/vistoolpointofintersectioncircles.cpp \ $$PWD/line/vistoolpointfromcircleandtangent.cpp \ $$PWD/line/vistoolpointfromarcandtangent.cpp \ + $$PWD/line/operation/vistoolrotation.cpp \ + $$PWD/line/operation/vistoolflippingbyline.cpp \ $$PWD/path/vispath.cpp \ $$PWD/path/vistoolarc.cpp \ $$PWD/path/vistoolcutarc.cpp \ @@ -67,4 +71,4 @@ SOURCES += \ $$PWD/path/vistoolpointofintersectioncurves.cpp \ $$PWD/path/vistoolcubicbezier.cpp \ $$PWD/path/vistoolcubicbezierpath.cpp \ - visualization/line/vistoolrotation.cpp + $$PWD/line/operation/visoperation.cpp