From 96130914143e7eeb6f93fd48776e00878926ceeb Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Fri, 27 May 2016 17:03:09 +0200 Subject: [PATCH] curve creator: bring together two extremities of two sections of polylines --- resources/CMakeLists.txt | 1 + resources/bringTogether.png | Bin 0 -> 645 bytes src/CurveCreator/CurveCreator_Widget.cxx | 76 ++++++++++++++++++++++- src/CurveCreator/CurveCreator_Widget.h | 4 +- src/GEOMGUI/GEOM_images.ts | 4 ++ src/GEOMGUI/GEOM_msg_en.ts | 8 +++ 6 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 resources/bringTogether.png diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 3d47d93ed..1936ab51c 100755 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -281,6 +281,7 @@ SET( _res_files closedspline.png edit_points.png join2.png + bringTogether.png new_point.png new_section.png # ADVANCED_RESOURCES: diff --git a/resources/bringTogether.png b/resources/bringTogether.png new file mode 100644 index 0000000000000000000000000000000000000000..f5a5a939cc75d783ae0820d607bfd738da814a4b GIT binary patch literal 645 zcmV;00($+4P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2jB%8 z4mcI%w42rd00IR`L_t(I%dM18XcJKohrhS`TDGW31&OJ8$VDh^#RO5b+4u)Rs28oE zpcWdzQ`MW$>P2tq!Ha^2-YNt<*Sn_%@fH+3iWjX#)W#NU44aGx-wT^fB8_%nSl;fN zZ)bip?gfC4mg!0U!M7LfLLuUYt|C0Ci;T z0Yjx{_r`%Wpqc}T!mT_(5U6gz3Q#sc3*HTQ-Qa+&tRf=S=1UQ2a|28QDPR~l0h}?< zVIb{K7X+99lHpk0NeA=CRg;BhD)2&?51Ormp{hD+*bCfB)fUjR1O32pQ+BH5+dl$# z0_OxoK<4f^S03JV_KHaBVE15qfDOC&vEDdzEKO!h8g{XjM-QCuBhMR!(SvM$dr#l# zEN`1fPbt-}l-fU=U69%Af^4BtwVAx@4kg%Ca}xV*UUin_X~B7bh1(AmrYF(B?2-6eqK>w&VmzM8oOKxwKzX=d@4Nn{;( zEg~yAB6iv6cc3&?zW~&8Xc_0J1ziTd0t3J&Gdfk{mF9iec1bD~14d2YCa}XyL>%~N fwtWUxqmBCw7EE2~Gq44j00000NkvXXu0mjfKT;80 literal 0 HcmV?d00001 diff --git a/src/CurveCreator/CurveCreator_Widget.cxx b/src/CurveCreator/CurveCreator_Widget.cxx index d401b8bc6..fc31c7dd6 100644 --- a/src/CurveCreator/CurveCreator_Widget.cxx +++ b/src/CurveCreator/CurveCreator_Widget.cxx @@ -50,6 +50,8 @@ #include #include +#include + //#define MEASURE_TIME #ifdef MEASURE_TIME @@ -120,6 +122,7 @@ CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); QPixmap aRemovePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_DELETE"))); QPixmap aJoinPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_JOIN"))); + QPixmap aBringTogetherPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_BRING_TOGETHER"))); QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP"))); QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN"))); @@ -183,18 +186,23 @@ CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, tr("SET_SECTIONS_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) ); connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) ); + aTB->addSeparator(); + anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemovePixmap, tr("REMOVE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) ); connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) ); aTB->addAction(anAct); - aTB->addSeparator(); - anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) ); connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) ); aTB->addAction(anAct); + anAct = createAction( BRING_TOGETHER_ID, tr("BRING_TOGETHER"), aBringTogetherPixmap, tr("BRING_TOGETHER_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_Equal ) ); + connect( anAct, SIGNAL(triggered()), this, SLOT(onBringTogether()) ); + aTB->addAction(anAct); + anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"), QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) ); connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) ); @@ -385,7 +393,7 @@ void CurveCreator_Widget::updateActionsStates() if( aSectCnt > 1 ) anEnabledAct << JOIN_ALL_ID; if( aSelSections.size() > 1 ){ - anEnabledAct << JOIN_ID; + anEnabledAct << JOIN_ID << BRING_TOGETHER_ID; } } break; @@ -976,6 +984,68 @@ void CurveCreator_Widget::addCoordsByClick( QMouseEvent* pe ) } } +/** + * Set the same coordinates on two section extremities. + * Usage: build a closed contour with several sections. + * Works with two points selected, at the extremities of different sections. + * The second point gets the coordinates of the first. + */ +void CurveCreator_Widget::onBringTogether() +{ + MESSAGE("onBringTogether"); + ActionMode aMode = getActionMode(); + if ( aMode != ModificationMode ) + return; + int nbPoints = myLocalPoints.size(); + MESSAGE("number of selected points: " << nbPoints); + if (nbPoints != 2) + { + MESSAGE("works only with two points taken at the extremities of different sections, nothing done"); + return; + } + + CurveCreator_ICurve::SectionToPointList::const_iterator anIt = myLocalPoints.begin(), + aLast = myLocalPoints.end(); + int sections[nbPoints]; + int iPoints[nbPoints]; + int nbPtsSection[nbPoints]; + double x[nbPoints]; + double y[nbPoints]; + int i = 0; + for ( ; anIt != aLast; anIt++, i++ ) + { + CurveCreator_ICurve::SectionToPoint aSPoint = *anIt; + sections[i] = aSPoint.first; + iPoints[i] = aSPoint.second; + nbPtsSection[i] = myCurve->getNbPoints(sections[i]); + if ((iPoints[i] != 0) and (iPoints[i] != nbPtsSection[i]-1)) + { + MESSAGE("a point is not on a section extremity, nothing done"); + return; + } + gp_Pnt aPoint; + CurveCreator_UtilsICurve::getPoint( myCurve, sections[i], iPoints[i], aPoint ); + x[i] = aPoint.X(); + y[i] = aPoint.Y(); + MESSAGE("point: " << sections[i] << " " << iPoints[i] << " " << x[i] << " " << y[i]); + } + if (sections[1] == sections[0]) + { + MESSAGE("the two points must be at the extremities of different sections, nothing done"); + return; + } + + CurveCreator_ICurve::SectionToPointList aSelPoints; + startCurveModification( aSelPoints ); + + CurveCreator::Coordinates aChangedPos; + aChangedPos.push_back( x[0] ); // apply the first point coordinates to the second point. + aChangedPos.push_back( y[0] ); + myCurve->setPoint( sections[1], iPoints[1], aChangedPos ); + + finishCurveModification( aSelPoints ); +} + /** * Manage mouse press events * \param theWindow an owner of the signal diff --git a/src/CurveCreator/CurveCreator_Widget.h b/src/CurveCreator/CurveCreator_Widget.h index 87433c553..ca5fe0f91 100644 --- a/src/CurveCreator/CurveCreator_Widget.h +++ b/src/CurveCreator/CurveCreator_Widget.h @@ -115,6 +115,7 @@ protected slots: void onModifySection(); void onCancelSection(); void onJoin(); + void onBringTogether(); void onRemove(); void onClearAll(); void onJoinAll(); @@ -158,7 +159,8 @@ protected: CLEAR_ALL_ID, SEPARATOR_ID, MODIFICATION_MODE_ID, - DETECTION_MODE_ID + DETECTION_MODE_ID, + BRING_TOGETHER_ID }; private: diff --git a/src/GEOMGUI/GEOM_images.ts b/src/GEOMGUI/GEOM_images.ts index cfcccd313..7d21059a1 100644 --- a/src/GEOMGUI/GEOM_images.ts +++ b/src/GEOMGUI/GEOM_images.ts @@ -27,6 +27,10 @@ ICON_CC_JOIN join2.png + + ICON_CC_BRING_TOGETHER + bringTogether.png + ICON_CC_NEW_POINT new_point.png diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index bdb86dfc0..6ed6b8082 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -5914,8 +5914,16 @@ shells and solids on the other hand. JOIN_TLT Join selected sections + + + BRING_TOGETHER + Bring together + BRING_TOGETHER_TLT + Bring together two points on the extremities of two sections + + CLEAR_ALL Clear all -- 2.39.2