+/**
+ * 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();
+ std::vector<int> sections(nbPoints);
+ std::vector<int> iPoints(nbPoints);
+ std::vector<int> nbPtsSection(nbPoints);
+ std::vector<double> x(nbPoints);
+ std::vector<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) && (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 );
+}
+