From 7eaadf17612c6e72665b3c6ebaccf4ae54ec5c8c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 23 Jun 2016 20:20:21 +0300 Subject: [PATCH] Resolved issue #480. New tool: Midpoint between two points. --HG-- branch : develop --- ChangeLog.txt | 1 + .../core/vtooloptionspropertybrowser.cpp | 6 +- src/app/valentina/dialogs/dialoghistory.cpp | 3 +- src/app/valentina/mainwindow.cpp | 28 +++++- src/app/valentina/mainwindow.h | 1 + src/app/valentina/mainwindow.ui | 28 +++++- src/app/valentina/share/resources/cursor.qrc | 2 + .../resources/cursor/midpoint_cursor.png | Bin 0 -> 459 bytes .../resources/cursor/midpoint_cursor@2x.png | Bin 0 -> 910 bytes .../valentina/share/resources/toolicon.qrc | 2 + .../resources/toolicon/32x32/midpoint.png | Bin 0 -> 685 bytes .../resources/toolicon/32x32/midpoint@2x.png | Bin 0 -> 1361 bytes .../share/resources/toolicon/svg/midpoint.svg | 89 ++++++++++++++++++ src/app/valentina/xml/vpattern.cpp | 5 +- src/libs/ifc/ifcdef.cpp | 4 +- src/libs/ifc/ifcdef.h | 1 + src/libs/ifc/xml/vabstractpattern.cpp | 8 +- src/libs/vmisc/def.h | 1 + src/libs/vpatterndb/vcontainer.cpp | 6 ++ src/libs/vpatterndb/vcontainer.h | 1 + src/libs/vpatterndb/vtranslatevars.cpp | 1 + .../vtools/dialogs/tools/dialogalongline.cpp | 36 ++++++- .../vtools/dialogs/tools/dialogalongline.h | 6 ++ src/libs/vtools/dialogs/tools/dialogtool.cpp | 6 ++ src/libs/vtools/dialogs/tools/dialogtool.h | 1 + .../toollinepoint/vtoolalongline.cpp | 16 +++- .../ValentinaTest/tst_measurementregexp.cpp | 1 + 27 files changed, 234 insertions(+), 19 deletions(-) create mode 100644 src/app/valentina/share/resources/cursor/midpoint_cursor.png create mode 100644 src/app/valentina/share/resources/cursor/midpoint_cursor@2x.png create mode 100644 src/app/valentina/share/resources/toolicon/32x32/midpoint.png create mode 100644 src/app/valentina/share/resources/toolicon/32x32/midpoint@2x.png create mode 100644 src/app/valentina/share/resources/toolicon/svg/midpoint.svg diff --git a/ChangeLog.txt b/ChangeLog.txt index 7b774bb4b..0584eaf8a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -31,6 +31,7 @@ - [#409] New feature: Export measurement file to Excel .csv. - [#180] New feature: Search field in tape app and dialog Increments. - [#514] Read only setting not working properly. +- [#480] New tool: Midpoint between two points. # Version 0.4.5 - [#435] Valentina doesn't change the cursor. diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 7e440d8a3..17f984845 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) == 43, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was used in switch."); switch (item->type()) { @@ -199,7 +199,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) == 43, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -334,7 +334,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) == 43, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was used in switch."); switch (currentItem->type()) { diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index bd431689e..a70a3aaab 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -208,7 +208,7 @@ void DialogHistory::FillTable() QString DialogHistory::Record(const VToolRecord &tool) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -226,6 +226,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::LinePoint: case Tool::AbstractSpline: case Tool::Cut: + case Tool::Midpoint:// Same as Tool::AlongLine, but tool will never has such type case Tool::LAST_ONE_DO_NOT_USE: Q_UNREACHABLE(); //-V501 break; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 7bfc2906d..fc7d16472 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -610,6 +610,11 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur helpLabel->setText(toolTip); dialogTool = new Dialog(pattern, NULL_ID, this); + if (t == Tool::Midpoint) + { + dialogTool->Build(t); + } + VMainGraphicsScene *scene = qobject_cast(currentScene); SCASSERT(scene != nullptr); @@ -750,6 +755,16 @@ void MainWindow::ToolAlongLine(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolMidpoint(bool checked) +{ + ToolSelectPointByRelease(); + // Reuse DialogAlongLine and VToolAlongLine but with different cursor + SetToolButtonWithApply(checked, Tool::Midpoint, ":/cursor/midpoint_cursor.png", + tr("Select point"), &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ToolShoulderPoint handler tool shoulderPoint. @@ -1750,6 +1765,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->toolButtonMidpoint, &QToolButton::clicked, this, &MainWindow::ToolMidpoint); } //--------------------------------------------------------------------------------------------------------------------- @@ -1790,7 +1806,7 @@ void MainWindow::mouseMove(const QPointF &scenePos) 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) == 43, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was handled."); qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; @@ -1836,6 +1852,9 @@ void MainWindow::CancelTool() case Tool::AlongLine: ui->toolButtonAlongLine->setChecked(false); break; + case Tool::Midpoint: + ui->toolButtonMidpoint->setChecked(false); + break; case Tool::ShoulderPoint: ui->toolButtonShoulderPoint->setChecked(false); break; @@ -3133,6 +3152,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonTrueDarts->setEnabled(drawTools); ui->toolButtonGroup->setEnabled(drawTools); ui->toolButtonRotation->setEnabled(drawTools); + ui->toolButtonMidpoint->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -3412,7 +3432,7 @@ void MainWindow::CreateMenus() 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) == 43, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was handled."); if (currentTool == lastUsedTool) { @@ -3451,6 +3471,10 @@ void MainWindow::LastUsedTool() ui->toolButtonAlongLine->setChecked(true); ToolAlongLine(true); break; + case Tool::Midpoint: + ui->toolButtonMidpoint->setChecked(true); + ToolMidpoint(true); + break; case Tool::ShoulderPoint: ui->toolButtonShoulderPoint->setChecked(true); ToolShoulderPoint(true); diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 6708c07dd..943245dc9 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -104,6 +104,7 @@ public slots: void ToolEndLine(bool checked); void ToolLine(bool checked); void ToolAlongLine(bool checked); + void ToolMidpoint(bool checked); void ToolShoulderPoint(bool checked); void ToolNormal(bool checked); void ToolBisector(bool checked); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index 1da863969..f0904c225 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -48,7 +48,7 @@ Tools - 4 + 0 @@ -368,6 +368,32 @@ + + + + false + + + Midpoint between two points + + + ... + + + + :/toolicon/32x32/midpoint.png:/toolicon/32x32/midpoint.png + + + + 32 + 32 + + + + true + + + diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index cfd41aa80..95f4ef5ae 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -68,5 +68,7 @@ cursor/group_plus_cursor@2x.png cursor/rotation_cursor.png cursor/rotation_cursor@2x.png + cursor/midpoint_cursor.png + cursor/midpoint_cursor@2x.png diff --git a/src/app/valentina/share/resources/cursor/midpoint_cursor.png b/src/app/valentina/share/resources/cursor/midpoint_cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..4c34e88e845195e35cd203f9c5b1c227693043cc GIT binary patch literal 459 zcmV;+0W|)JP)Z zIO3%aKu|=zfMAFufFOwHgn-0|p8#d?4)kh<>>{0U0Z-qQz2XiNQA_4&ALTaBZc;!I z7Z{A$)0$^1$0_pl0tz@lZ_M%94B{BmQ6Cg*#y8QHV7!`H>?0QyP{amW0*r$U`Mu%H z_2X3c+F$>kV>#4tH5FPPr@9VzhB9Z!hVGAs7}43?W(nKqNd@td73`p+`XR)j#mNbJ z`dA;QaLZ+|V~dfNF^)mq6*zCA{S^=x9(7)+q!D5du?NH8V5YH+84O<3Vd$cW0hwo_X0H z%wY%idH&C5AD(%3W}upCs;Ops-T)tfL%Ivm6>IYtBcce_mSX~F)LV}CDY6|Qax-Cr z?EsOR33dRHLRiNhATkJR{2w3^2s;6U9-+X_0HH?6QyxHQ5h?))B|?tM078e5rE-8! zAvgsH4MGOz0HHwmjXQwABgg;57Yzr8o?_7-y$sG9e^(pzT+)`?+|nV_zGbWJpjHz_=Y|JUm)lP(2lTB zMuDM5n0HWYs1W=Fpao%0!64ioqpAiQvpHv}>dax*flMc~$Dn5eJ~qSXuy~I_Nzyp` zm0kk-R20+=4QFBE1gv#JIt7TT;wkns;JEA#rYSx6Pe8NmPAg0eFoZyO1jJ=FUJBqfP%pDHhcOWA zz(d5->^|(*Ge`M?{oscX)6Y*afnmg&a9dWRQ~W#l$4C^GoCMH+t-dz1++n`UbtDEC zPP*HVYz4>zciq>hHaF|3`+7RQoK2cmHfa{~$;7R4zguc6yo#7suVfUdGB4UFWb?-Q z=0{_?P(0?Qz2}IP{*3F&JWMue-peJ;@waX9se>_N7Pz9jCeLGaQr8lv6_`X^&Du1V zq%G%x&%k@29dWgYTv`ze`XVKEi?yDW<9(J8`<5io1B@V^d`BuV;4toolicon/32x32/group_plus@2x.png toolicon/32x32/rotation.png toolicon/32x32/rotation@2x.png + toolicon/32x32/midpoint.png + toolicon/32x32/midpoint@2x.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/midpoint.png b/src/app/valentina/share/resources/toolicon/32x32/midpoint.png new file mode 100644 index 0000000000000000000000000000000000000000..7f3436206de7bbc334a2e5ee25f8fd45ad2e296b GIT binary patch literal 685 zcmV;e0#f~nP)wUxGZOcOt+GsjCjt`y*>ChVgz z&$d9*Q(C@q0(tDgxk@4al!FSZAcq6kT?@pa6fupRwE%SDZi<+|)@lQ~(14>wh|SeT z%;Z>#_=XL&LiDGIuY22*U1O`W>pv}TX{#n6!m0i3Nf_3YV1(Pk!nIAVNFN#0qEGVZ|S%B6jpFiRz zLI^^P{*md$=qaaOS^3;IYxY=o_V~A+?D-=db%SxCG2dZX)euF=;EDp`t-{_>_0;29 ziWtF?S|P5dh+&+p1)>pmQp9V_uLa^TZl{Rnm{$wLEIddNLzw%!NoDPXC8Py6uqMNc zF3vPCTF2#kg(X{Y0JLVfwUiYZLPRcRIM6r9Nb>jV|2gB!Y0R+c1<`ww*)%1*8fLJp zt+>=Q@F9KjAFn(Ves;_I7L=NLuExCTWO5;s5pSlrNOgJu^fD)~Jt8h{!kXtht_zd~ T&oaZ800000NkvXXu0mjfuU9Nv literal 0 HcmV?d00001 diff --git a/src/app/valentina/share/resources/toolicon/32x32/midpoint@2x.png b/src/app/valentina/share/resources/toolicon/32x32/midpoint@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..b35c06d0b92b6150718d76b4a20123213f77dbde GIT binary patch literal 1361 zcmV-X1+MyuP)vfi+*TF;Tvz zGpc|^EXjBd=jQz~G%^}k)y<=CQcsk#X|#>Ba}l#M-ovB@;~R_%)B-gGEa;`Wi?vD9 zHi610J6B*_ovu37z1WFEWDUj#s(}YC|(>YyxYcES-ez^R#^WBpZ2gIoR~!QOZW`i z6J-8huw0x4hC$n3xT4HZskukIGY*#UCoa$1uT;E=v>Yo86%fSn@nKQM;_{-U;}Jy( z4cu8~sMM@fl<*raDl=4SK2nsh7Z;WpDiu$mN30(Vm#`DF%Zt{0YIseYDHCN3m#}?M zd&`sISw#syVtR?Wl9J(hMF~G(T8X)mlHmnK30uTE<7q(!uP93R29rz7HNZ*B;{OqC zqJ(9GcXoGVo7c|mST&`iGAk4IV(qxE`#w#OX9y_-5GA~Z+u@;es#Z>|I-^*QdE;oU zH}+kdmwhe$TV6_uqk|SX~*n;J9v<}Awe7@7Eo_%n|LbyLM%ZhA*p~$7WSM#sNhM_m&wdHA`^FPziP1ajO5I6{eLp z;2jLq8Yj@0#g!&hEjc$=ot^=o4dGpgqumtit*29N5j5{T*8A@$&8S;@fA$(QymD7uWCQE8N>E z@e7y%T1kKoCS>{P{j0dr{SbEK?fG{ObFLdSUbK{ejF4aNLk72D1Kp58u%!e9zRg#; zn<1`n@50QyJzwv<^%MH~f75CLR*5Uz4|fsfiA&VZL?s?{y%9@m1GLIr0PJS-bf#ro zT;W)L3p`e#FF!NZ%;Jg7gD!(snFkDE5!Yw&;b?9azi#Ql3+v;TaAS-y#tHrbk4AkK TD#ZX|00000NkvXXu0mjf2rz%Q literal 0 HcmV?d00001 diff --git a/src/app/valentina/share/resources/toolicon/svg/midpoint.svg b/src/app/valentina/share/resources/toolicon/svg/midpoint.svg new file mode 100644 index 000000000..1be5d299b --- /dev/null +++ b/src/app/valentina/share/resources/toolicon/svg/midpoint.svg @@ -0,0 +1,89 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index d6fd0c0c4..324bf97c7 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -263,6 +263,8 @@ void VPattern::setCurrentData() const VDataTool *vTool = tools.value(id); *data = vTool->getData(); + //Delete special variable if exist + data->RemoveVariable(currentLength); qCDebug(vXML, "Data successfully updated."); } else @@ -3204,7 +3206,7 @@ void VPattern::ToolsCommonAttributes(const QDomElement &domElement, quint32 &id) QRectF VPattern::ActiveDrawBoundingRect() const { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44, "Not all tools was used."); QRectF rec; @@ -3221,6 +3223,7 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::LinePoint: case Tool::AbstractSpline: case Tool::Cut: + case Tool::Midpoint:// Same as Tool::AlongLine, but tool will never has such type case Tool::LAST_ONE_DO_NOT_USE: Q_UNREACHABLE(); break; diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index 65d74d3ff..53b3e1587 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -163,6 +163,7 @@ const QString angle2Spl_ = angle2_V + spl_; const QString angle1SplPath = angle1_V + splPath; const QString angle2SplPath = angle2_V + splPath; const QString seg_ = QStringLiteral("Seg_"); +const QString currentLength = QStringLiteral("CurrentLength"); const QStringList builInVariables = QStringList() << line_ << angleLine_ @@ -179,4 +180,5 @@ const QStringList builInVariables = QStringList() << line_ << angle2Spl_ << angle1SplPath << angle2SplPath - << seg_; + << seg_ + << currentLength; diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 39d65b2f9..93399b39d 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -170,6 +170,7 @@ extern const QString angle2Spl_; extern const QString angle1SplPath; extern const QString angle2SplPath; extern const QString seg_; +extern const QString currentLength; extern const QStringList builInVariables; diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index a8bc66609..2facbd16f 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1235,7 +1235,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) == 43); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44); QStringList expressions; const QDomNodeList list = elementsByTagName(TagPoint); @@ -1306,7 +1306,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) == 43); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44); QStringList expressions; const QDomNodeList list = elementsByTagName(TagArc); @@ -1367,7 +1367,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) == 43); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44); QStringList expressions; const QDomNodeList list = elementsByTagName(AttrPathPoint); @@ -1433,7 +1433,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) == 43); + Q_STATIC_ASSERT(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 44); QStringList expressions; const QDomNodeList list = elementsByTagName(TagOperation); diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index dbb079861..df6f28300 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -103,6 +103,7 @@ enum class Tool : ToolVisHolderType UnionDetails, Group, Rotation, + Midpoint, LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index b28ca3120..1d6fa8fe1 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -420,6 +420,12 @@ void VContainer::AddCurveWithSegments(const QSharedPointervariables.remove(name); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddObject add object to container diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index dce71b92f..2309dccb0 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -129,6 +129,7 @@ public: template void AddVariable(const QString& name, T *var); + void RemoveVariable(const QString& name); void UpdateGObject(quint32 id, VGObject* obj); void UpdateDetail(quint32 id, const VDetail &detail); diff --git a/src/libs/vpatterndb/vtranslatevars.cpp b/src/libs/vpatterndb/vtranslatevars.cpp index a2274b857..102b67165 100644 --- a/src/libs/vpatterndb/vtranslatevars.cpp +++ b/src/libs/vpatterndb/vtranslatevars.cpp @@ -380,6 +380,7 @@ void VTranslateVars::InitVariables() variables.insert(angle2SplPath, translate("VTranslateVars", "Angle2SplPath", "Do not add symbol _ to the end of the name")); variables.insert(seg_, translate("VTranslateVars", "Seg_", "Segment. Left symbol _ in the name")); + variables.insert(currentLength, translate("VTranslateVars", "CurrentLength", "Do not add space between words")); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogalongline.cpp b/src/libs/vtools/dialogs/tools/dialogalongline.cpp index 99dfef4be..f9ddcb36d 100644 --- a/src/libs/vtools/dialogs/tools/dialogalongline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogalongline.cpp @@ -33,6 +33,7 @@ #include "../../../vwidgets/vmaingraphicsscene.h" #include "../../../vpatterndb/vtranslatevars.h" #include "../support/dialogeditwrongformula.h" +#include "../vgeometry/vpointf.h" #include @@ -44,7 +45,7 @@ */ DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId, QWidget *parent) :DialogTool(data, toolId, parent), ui(new Ui::DialogAlongLine), - formula(QString()), formulaBaseHeight(0) + formula(QString()), formulaBaseHeight(0), buildMidpoint(false) { ui->setupUi(this); @@ -93,7 +94,7 @@ void DialogAlongLine::FormulaTextChanged() void DialogAlongLine::PointChanged() { QColor color = okColor; - if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint)) + if (GetFirstPointId() == GetSecondPointId()) { flagError = false; color = errorColor; @@ -103,6 +104,7 @@ void DialogAlongLine::PointChanged() flagError = true; color = okColor; } + SetCurrentLength(); ChangeColor(ui->labelFirstPoint, color); ChangeColor(ui->labelSecondPoint, color); CheckState(); @@ -137,6 +139,9 @@ void DialogAlongLine::DeployFormulaTextEdit() //--------------------------------------------------------------------------------------------------------------------- DialogAlongLine::~DialogAlongLine() { + VContainer *locData = const_cast (data); + locData->RemoveVariable(currentLength); + DeleteVisualization(); delete ui; } @@ -173,6 +178,10 @@ void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type) { line->setObject2Id(id); line->RefreshGeometry(); + if (buildMidpoint) + { + SetFormula(currentLength + QLatin1Literal("/2")); + } prepare = true; this->setModal(true); this->show(); @@ -215,6 +224,20 @@ void DialogAlongLine::closeEvent(QCloseEvent *event) DialogTool::closeEvent(event); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::SetCurrentLength() +{ + const QSharedPointer p1 = data->GeometricObject(GetFirstPointId()); + const QSharedPointer p2 = data->GeometricObject(GetSecondPointId()); + + VLengthLine *length = new VLengthLine(p1.data(), GetFirstPointId(), p2.data(), + GetSecondPointId(), *data->GetPatternUnit()); + length->SetName(currentLength); + + VContainer *locData = const_cast (data); + locData->AddVariable(currentLength, length); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetSecondPointId set id second point of line @@ -229,6 +252,15 @@ void DialogAlongLine::SetSecondPointId(const quint32 &value) line->setObject2Id(value); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogAlongLine::Build(const Tool &type) +{ + if (type == Tool::Midpoint) + { + buildMidpoint = true; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetFirstPointId set id first point of line diff --git a/src/libs/vtools/dialogs/tools/dialogalongline.h b/src/libs/vtools/dialogs/tools/dialogalongline.h index 64965133a..641eef5e1 100644 --- a/src/libs/vtools/dialogs/tools/dialogalongline.h +++ b/src/libs/vtools/dialogs/tools/dialogalongline.h @@ -62,6 +62,8 @@ public: quint32 GetSecondPointId() const; void SetSecondPointId(const quint32 &value); + + virtual void Build(const Tool &type) Q_DECL_OVERRIDE; public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; /** @@ -93,6 +95,10 @@ private: /** @brief formulaBaseHeight base height defined by dialogui */ int formulaBaseHeight; + + bool buildMidpoint; + + void SetCurrentLength(); }; #endif // DIALOGALONGLINE_H diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 200a52287..809635e4d 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -919,6 +919,12 @@ void DialogTool::ShowDialog(bool click) Q_UNUSED(click); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::Build(const Tool &type) +{ + Q_UNUSED(type); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogTool::SetAssociatedTool(VAbstractTool *tool) { diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index e1c51a5da..ee47436bc 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -69,6 +69,7 @@ public: void SetAssociatedTool(VAbstractTool* tool); virtual void ShowDialog(bool click); + virtual void Build(const Tool &type); quint32 GetToolId() const; void SetToolId(const quint32 &value); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp index 2fbca8c73..124d9b4af 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp @@ -250,6 +250,12 @@ VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointNa const QSharedPointer secondPoint = data->GeometricObject(secondPointId); QLineF line = QLineF(*firstPoint, *secondPoint); + //Declare special variable "CurrentLength" + VLengthLine *length = new VLengthLine(firstPoint.data(), firstPointId, secondPoint.data(), + secondPointId, *data->GetPatternUnit()); + length->SetName(currentLength); + data->AddVariable(currentLength, length); + line.setLength(qApp->toPixel(CheckFormula(_id, formula, data))); quint32 id = _id; @@ -270,16 +276,18 @@ VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointNa } } VDrawTool::AddRecord(id, Tool::AlongLine, doc); + VToolAlongLine *point = nullptr; if (parse == Document::FullParse) { - VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId, typeLine, - lineColor, typeCreation); + point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId, typeLine, lineColor, + typeCreation); scene->addItem(point); InitToolConnections(scene, point); doc->AddTool(id, point); doc->IncrementReferens(firstPoint->getIdTool()); doc->IncrementReferens(secondPoint->getIdTool()); - return point; } - return nullptr; + //Very important to delete it. Only this tool need this special variable. + data->RemoveVariable(currentLength); + return point; } diff --git a/src/test/ValentinaTest/tst_measurementregexp.cpp b/src/test/ValentinaTest/tst_measurementregexp.cpp index 44ba83479..f71d54a91 100644 --- a/src/test/ValentinaTest/tst_measurementregexp.cpp +++ b/src/test/ValentinaTest/tst_measurementregexp.cpp @@ -651,6 +651,7 @@ void TST_MeasurementRegExp::CheckUnderlineExists() const data.insert(angle1SplPath, false); data.insert(angle2SplPath, false); data.insert(seg_, true); + data.insert(currentLength, false); //Catch case when new internal variable appears. QCOMPARE(data.size(), builInVariables.size());