1 // Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "CurveCreator_Widget.h"
21 #include "CurveCreator_TreeView.h"
22 #include "CurveCreator_ICurve.hxx"
23 //#include "CurveCreator_CurveEditor.hxx"
24 #include "CurveCreator.hxx"
25 //#include "CurveCreator_NewPointDlg.h"
26 #include "CurveCreator_NewSectionDlg.h"
27 #include "CurveCreator_Utils.h"
28 #include "CurveCreator_UtilsICurve.hxx"
29 #include "CurveCreator_TableView.h"
31 #include <SUIT_Session.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_ViewManager.h>
36 #include <OCCViewer_ViewWindow.h>
37 #include <OCCViewer_ViewManager.h>
38 #include <OCCViewer_ViewPort3d.h>
39 #include "OCCViewer_Utilities.h"
41 #include <BRep_Tool.hxx>
43 #include <TopoDS_Vertex.hxx>
44 #include <TopoDS_Wire.hxx>
45 #include <TopoDS_Edge.hxx>
48 #include <TopExp_Explorer.hxx>
50 #include <GeomAPI_ProjectPointOnCurve.hxx>
52 #include <AIS_ListOfInteractive.hxx>
53 #include <AIS_ListIteratorOfListOfInteractive.hxx>
54 #include <AIS_Shape.hxx>
55 #include <AIS_Point.hxx>
56 #include <AIS_Line.hxx>
57 #include <AIS_LocalContext.hxx>
58 #include <Geom_Point.hxx>
59 #include <Geom_BSplineCurve.hxx>
60 #include <Geom_Line.hxx>
61 #include <StdSelect_BRepOwner.hxx>
62 #include <SelectMgr_Selection.hxx>
63 #include <Select3D_SensitivePoint.hxx>
65 #include <QHBoxLayout>
66 #include <QVBoxLayout>
70 #include <QToolButton>
74 #include <QMouseEvent>
75 #include <QApplication>
76 #include <QTableWidget>
83 #define START_MEASURE_TIME \
87 #define END_MEASURE_TIME( theMsg ) \
88 double aTime = aTimer.elapsed() * 0.001; \
89 FILE* aFile = fopen( "performance", "a" ); \
90 fprintf( aFile, "%s = %.3lf sec\n", theMsg, aTime ); \
95 #define START_MEASURE_TIME
96 #define END_MEASURE_TIME( theMsg )
105 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
107 CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
108 CurveCreator_ICurve *theCurve,
110 : QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0),
111 myDragStarted( false ), myDragInteractionStyle( SUIT_ViewModel::STANDARD ),
114 myNewSectionEditor = new CurveCreator_NewSectionDlg( this );
115 myNewSectionEditor->hide();
116 connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()) );
117 connect( myNewSectionEditor, SIGNAL(modifySection()), this, SLOT(onModifySection()) );
118 connect( myNewSectionEditor, SIGNAL(cancelSection()), this, SLOT(onCancelSection()) );
120 QGroupBox* aSectionGroup = new QGroupBox(tr("Sections"),this);
122 mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup);
123 connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) );
124 connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) );
125 connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) );
127 myLocalPointView = new CurveCreator_TableView( myCurve, this );
128 connect( myLocalPointView, SIGNAL( cellChanged( int, int ) ),
129 this, SLOT( onCellChanged( int, int ) ) );
131 QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup);
132 // QToolButton* anUndoBtn = new QToolButton(aTB);
134 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
135 QPixmap anUndoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_UNDO")));
136 QPixmap aRedoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_REDO")));
137 QPixmap aNewSectionPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_SECTION")));
138 QPixmap aNewPointPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_POINT")));
139 QPixmap anEditPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
140 QPixmap aDetectPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
141 QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
142 QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
143 QPixmap aRemovePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_DELETE")));
144 QPixmap aJoinPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_JOIN")));
145 QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP")));
146 QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN")));
148 QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"),
149 QKeySequence(Qt::ControlModifier|Qt::Key_Z) );
150 connect(anAct, SIGNAL(triggered()), this, SLOT(onUndo()) );
151 aTB->addAction(anAct);
153 anAct = createAction( REDO_ID, tr("REDO"), aRedoPixmap, tr("REDO_TLT"),
154 QKeySequence(Qt::ControlModifier|Qt::Key_Y) );
155 connect(anAct, SIGNAL(triggered()), this, SLOT(onRedo()) );
156 aTB->addAction(anAct);
160 anAct = createAction( NEW_SECTION_ID, tr("NEW_SECTION"), aNewSectionPixmap, tr("NEW_SECTION_TLT"),
161 QKeySequence(Qt::ControlModifier|Qt::Key_N) );
162 connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) );
163 aTB->addAction(anAct);
166 anAct = createAction( ADDITION_MODE_ID, tr("ADDITION_MODE"), aNewPointPixmap, tr("ADDITION_MODE_TLT"),
168 anAct->setCheckable(true);
169 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onAdditionMode(bool)) );
170 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
171 aTB->addAction(anAct);
173 anAct = createAction( MODIFICATION_MODE_ID, tr("MODIFICATION_MODE"), anEditPointsPixmap, tr("MODIFICATION_MODE_TLT"),
175 anAct->setCheckable(true);
176 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onModificationMode(bool)) );
177 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
178 aTB->addAction(anAct);
180 anAct = createAction( DETECTION_MODE_ID, tr("DETECTION_MODE"), aDetectPointsPixmap, tr("DETECTION_MODE_TLT"),
182 anAct->setCheckable(true);
183 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onDetectionMode(bool)) );
184 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
185 aTB->addAction(anAct);
187 anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), QPixmap(), tr("CLOSE_SECTIONS_TLT"),
188 QKeySequence(Qt::ControlModifier|Qt::Key_W) );
189 connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) );
191 anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), QPixmap(),
192 tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) );
193 connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) );
195 anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"),
196 aPolylinePixmap, tr("SET_POLYLINE_TLT"),
197 QKeySequence(Qt::ControlModifier|Qt::Key_E) );
198 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) );
200 anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), aSplinePixmap,
201 tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) );
202 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) );
204 anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemovePixmap, tr("REMOVE_TLT"),
205 QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) );
206 connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) );
207 aTB->addAction(anAct);
209 //aTB->addSeparator();
211 //anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"),
212 // QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) );
213 //connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) );
214 //aTB->addAction(anAct);
216 anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"),
217 QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) );
218 connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) );
221 //anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), QPixmap(), tr("JOIN_ALL_TLT"),
222 // QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) );
223 //connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) );
225 QVBoxLayout* aSectLayout = new QVBoxLayout();
226 aSectLayout->setMargin( 5 );
227 aSectLayout->setSpacing( 5 );
228 aSectLayout->addWidget(aTB);
229 aSectLayout->addWidget(mySectionView);
230 aSectLayout->addWidget( myLocalPointView );
231 aSectionGroup->setLayout(aSectLayout);
232 QVBoxLayout* aLay = new QVBoxLayout();
233 aLay->setMargin( 0 );
234 aLay->setSpacing( 5 );
235 // aLay->addLayout(aNameLayout);
236 aLay->addWidget(aSectionGroup);
239 updateActionsStates();
246 void CurveCreator_Widget::setOCCViewer( OCCViewer_Viewer* theViewer )
248 if ( myOCCViewer == theViewer )
252 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
253 ( myOCCViewer->getViewManager() );
254 disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
255 this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
256 disconnect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
257 this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
258 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
259 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
260 disconnect( aViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
261 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
262 // restore normal mode in the viewer
263 OCCViewer_Utilities::setViewer2DMode( myOCCViewer, OCCViewer_ViewWindow::No2dMode );
264 // all local contexts should be closed if the viewer is not more used
265 setLocalPointContext( false, true );
268 myOCCViewer = theViewer;
270 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
271 ( myOCCViewer->getViewManager() );
272 connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
273 this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
274 connect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
275 this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
276 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
277 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
278 connect( aViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
279 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
280 OCCViewer_Utilities::setViewer2DMode( myOCCViewer, OCCViewer_ViewWindow::XYPlane );
285 * Returns current OCC viewer
287 OCCViewer_Viewer* CurveCreator_Widget::getOCCViewer()
293 * Returns OCC viewer context
295 Handle(AIS_InteractiveContext) CurveCreator_Widget::getAISContext()
297 Handle(AIS_InteractiveContext) aContext;
298 OCCViewer_Viewer* aViewer = getOCCViewer();
300 aContext = aViewer->getAISContext();
306 * Returns OCC viewer view port
308 OCCViewer_ViewPort3d* CurveCreator_Widget::getViewPort()
310 OCCViewer_ViewPort3d* aViewPort = 0;
311 OCCViewer_Viewer* aViewer = getOCCViewer();
313 aViewPort = ((OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView())->getViewPort();
319 * Set interaction style in the OCC viewer
320 * \param theStyle a new style
321 * \return the previous style
323 int CurveCreator_Widget::changeInteractionStyle( int theStyle )
325 OCCViewer_Viewer* aViewer = getOCCViewer();
329 int aPrevStyle = aViewer->interactionStyle();
330 aViewer->setInteractionStyle( theStyle );
336 * Set interaction style in the OCC viewer
337 * \param theStyle a new style
338 * \return the previous style
340 void CurveCreator_Widget::setObjectsSelected(const AIS_ListOfInteractive& theList)
342 OCCViewer_Viewer* aViewer = getOCCViewer();
344 aViewer->setObjectsSelected(theList);
347 //=======================================================================
349 // purpose: reset the widget viewer, close local context, clear selection
350 //=======================================================================
351 void CurveCreator_Widget::reset()
355 void CurveCreator_Widget::setCurve( CurveCreator_ICurve* theCurve )
358 mySectionView->setCurve( myCurve );
359 myLocalPointView->setCurve( myCurve );
360 updateActionsStates();
364 void CurveCreator_Widget::onSelectionChanged()
366 updateActionsStates();
368 emit selectionChanged();
371 void CurveCreator_Widget::updateActionsStates()
373 QList<ActionId> anEnabledAct;
375 anEnabledAct << NEW_SECTION_ID << MODIFICATION_MODE_ID;
376 if ( removeEnabled() )
377 anEnabledAct << REMOVE_ID;
378 QList<int> aSelSections = mySectionView->getSelectedSections();
379 QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints();
380 CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
382 case CurveCreator_TreeView::ST_NOSEL:{
385 case CurveCreator_TreeView::ST_SECTIONS:{
386 /*if( aSelSections[0] > 0 ){
387 anEnabledAct << UP_ID;
389 if( aSelSections.size() == 1 ){
390 anEnabledAct << ADDITION_MODE_ID << DETECTION_MODE_ID;
392 switch ( getActionMode() ) {
396 QList<int> aSelSection = mySectionView->getSelectedSections();
397 if( aSelSection.size() > 0 ){
398 mySection = aSelSection[0];
399 myPointNum = myCurve->getNbPoints(mySection);
403 case ModificationMode: {
404 anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID;
405 int aSectCnt = myCurve->getNbSections();
407 anEnabledAct << CLEAR_ALL_ID;
410 // anEnabledAct << JOIN_ALL_ID;
411 //if( aSelSections.size() > 1 ){
412 // anEnabledAct << JOIN_ID;
416 case DetectionMode: {
423 /*if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){
424 anEnabledAct << DOWN_ID;
428 /*case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{
429 if( aSelPoints[0].second > 0 ){
430 anEnabledAct << UP_ID;
432 int aLastIndex = aSelPoints.size()-1;
433 int aSect = aSelPoints[0].first;
434 if( aSelPoints[aLastIndex].second < (myCurve->getNbPoints(aSect) - 1)){
435 anEnabledAct << DOWN_ID;
437 if( aSelPoints.size() == 1){
438 anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID;
445 /*int aSelObjsCnt = aSelPoints.size() + aSelSections.size();
446 if( aSelObjsCnt > 0 ){
447 anEnabledAct << REMOVE_ID;
449 if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){
450 anEnabledAct << REMOVE_ALL_ID;
453 //if( myCurve->getNbSections() > 1 ){
454 // anEnabledAct << JOIN_ALL_ID;
457 QList<ActionId> anIds = myActionMap.keys();
458 for( int i = 0 ; i < anIds.size() ; i++ ){
459 if( myActionMap.contains(anIds[i]) ){
460 if( anEnabledAct.contains(anIds[i]) ){
461 myActionMap[anIds[i]]->setEnabled(true);
464 myActionMap[anIds[i]]->setEnabled(false);
470 void CurveCreator_Widget::onAdditionMode(bool checked)
475 Handle(AIS_InteractiveContext) aContext = getAISContext();
476 if( !myCurve || aContext.IsNull() )
481 QList<int> aSelSection = mySectionView->getSelectedSections();
482 if( aSelSection.size() > 0 ){
483 mySection = aSelSection[0];
486 QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
487 if( aSelPoints.size() > 0 ){
488 mySection = aSelPoints[0].first;
489 myPointNum = aSelPoints[0].second + 1;
492 // emit subOperationStarted( myNewPointEditor );
495 void CurveCreator_Widget::onModificationMode(bool checked)
497 myLocalPointView->setVisible( checked );
500 void CurveCreator_Widget::onDetectionMode(bool checked)
504 void CurveCreator_Widget::onModeChanged(bool checked)
506 ActionMode aMode = NoneMode;
508 QAction* anAction = (QAction*)sender();
509 switch(myActionMap.key(anAction)) {
510 case ADDITION_MODE_ID:
511 aMode = AdditionMode;
512 if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
513 myActionMap[MODIFICATION_MODE_ID]->trigger();
514 else if (myActionMap[DETECTION_MODE_ID]->isChecked())
515 myActionMap[DETECTION_MODE_ID]->trigger();
517 case MODIFICATION_MODE_ID:
518 aMode = ModificationMode;
519 if (myActionMap[ADDITION_MODE_ID]->isChecked())
520 myActionMap[ADDITION_MODE_ID]->trigger();
521 else if (myActionMap[DETECTION_MODE_ID]->isChecked())
522 myActionMap[DETECTION_MODE_ID]->trigger();
524 case DETECTION_MODE_ID:
525 aMode = DetectionMode;
526 if (myActionMap[ADDITION_MODE_ID]->isChecked())
527 myActionMap[ADDITION_MODE_ID]->trigger();
528 else if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
529 myActionMap[MODIFICATION_MODE_ID]->trigger();
533 updateActionsStates();
535 setLocalPointContext( aMode == ModificationMode, true );
538 void CurveCreator_Widget::onAddNewPoint(const CurveCreator::Coordinates& theCoords)
542 //myCurve->addPoints(theCoords, mySection, myPointNum );
543 //mySectionView->pointsAdded( mySection, myPointNum );
545 QList<int> aSections = mySectionView->getSelectedSections();
546 if( aSections.size() == 0 ){
549 int aSection = aSections[0];
550 myCurve->addPoints(theCoords, aSection); // add to the end of section
551 mySectionView->pointsAdded( aSection, myCurve->getNbPoints( aSection ) );
552 updateActionsStates();
556 void CurveCreator_Widget::onNewSection()
560 myNewSectionEditor->clear();
561 myNewSectionEditor->setEditMode(false);
562 QString aSectName = QString( CurveCreator_UtilsICurve::getUniqSectionName( myCurve ).c_str() );
563 myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline );
564 emit subOperationStarted( myNewSectionEditor );
567 void CurveCreator_Widget::onAddNewSection()
571 myCurve->addSection( myNewSectionEditor->getName().toStdString(),
572 myNewSectionEditor->getSectionType(),
573 myNewSectionEditor->isClosed() );
574 mySectionView->sectionAdded( -1 ); // add a new section to the end of list
575 QString aNewName = QString( CurveCreator_UtilsICurve::getUniqSectionName( myCurve ).c_str() );
576 myNewSectionEditor->setSectionName(aNewName);
577 updateActionsStates();
582 void CurveCreator_Widget::onCancelSection()
584 emit subOperationFinished( myNewSectionEditor );
587 QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
588 const QString& theToolTip, const QKeySequence& theShortcut )
590 QAction* anAct = new QAction(theName,this);
591 if( !theImage.isNull() ){
592 anAct->setIcon(theImage);
594 anAct->setShortcut(theShortcut);
595 anAct->setToolTip(theToolTip);
596 myActionMap[theId] = anAct;
600 QAction* CurveCreator_Widget::getAction(ActionId theId)
602 if( myActionMap.contains(theId) )
603 return myActionMap[theId];
607 CurveCreator_Widget::ActionMode CurveCreator_Widget::getActionMode() const
609 ActionMode aMode = NoneMode;
611 if ( myActionMap[ADDITION_MODE_ID]->isChecked() )
612 aMode = AdditionMode;
613 else if ( myActionMap[MODIFICATION_MODE_ID]->isChecked() )
614 aMode = ModificationMode;
615 else if ( myActionMap[DETECTION_MODE_ID]->isChecked() )
616 aMode = DetectionMode;
621 void CurveCreator_Widget::onEditSection( int theSection )
625 mySection = theSection;
626 QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
627 bool isClosed = myCurve->isClosed(theSection);
628 CurveCreator::SectionType aType = myCurve->getSectionType(theSection);
629 myNewSectionEditor->setEditMode(true);
630 myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType );
632 emit subOperationStarted( myNewSectionEditor );
635 void CurveCreator_Widget::onModifySection()
639 QString aName = myNewSectionEditor->getName();
640 bool isClosed = myNewSectionEditor->isClosed();
641 CurveCreator::SectionType aSectType = myNewSectionEditor->getSectionType();
642 // myCurve->startOperation();
643 if( myCurve->getSectionName(mySection) != aName.toStdString() )
644 myCurve->setSectionName( mySection , aName.toStdString() );
646 if( myCurve->getSectionType(mySection) != aSectType )
647 myCurve->setSectionType( mySection, aSectType );
649 if( myCurve->isClosed(mySection) != isClosed )
650 myCurve->setClosed( mySection, isClosed );
651 // myCurve->finishOperation();
652 mySectionView->sectionChanged(mySection);
657 /*void CurveCreator_Widget::onEditPoint( int theSection, int thePoint )
659 if( !myNewPointEditor || !myEdit )
661 mySection = theSection;
662 myPointNum = thePoint;
663 QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
664 myNewPointEditor->setEditMode(true);
665 myNewPointEditor->setSectionName(aSectName);
666 myNewPointEditor->setDimension( myCurve->getDimension() );
667 CurveCreator::Coordinates aCoords = myCurve->getCoordinates(theSection,thePoint);
668 myNewPointEditor->setCoordinates(aCoords);
669 emit subOperationStarted( myNewPointEditor );
672 void CurveCreator_Widget::onModifyPoint()
676 CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates();
677 myEdit->setCoordinates( aCoords, mySection, myPointNum );
678 mySectionView->pointDataChanged( mySection, myPointNum );
683 void CurveCreator_Widget::onJoin()
687 QList<int> aSections = mySectionView->getSelectedSections();
688 if( aSections.size() == 0 ){
691 int aMainSect = aSections[0];
692 int aMainSectSize = myCurve->getNbPoints(aMainSect);
693 // myCurve->startOperation();
694 for( int i = 1 ; i < aSections.size() ; i++ ){
695 int aSectNum = aSections[i] - (i-1);
696 myCurve->join( aMainSect, aSectNum );
697 mySectionView->sectionsRemoved( aSectNum );
699 // myCurve->finishOperation();
700 int aNewSectSize = myCurve->getNbPoints(aMainSect);
701 if( aNewSectSize != aMainSectSize )
702 mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );
706 void CurveCreator_Widget::onRemove()
711 switch( getActionMode() ) {
715 case ModificationMode:
723 void CurveCreator_Widget::onClearAll()
728 mySectionView->reset();
729 updateActionsStates();
733 void CurveCreator_Widget::onJoinAll()
738 mySectionView->reset();
739 updateActionsStates();
743 void CurveCreator_Widget::onUndoSettings()
748 void CurveCreator_Widget::onSetSpline()
752 QList<int> aSelSections = mySectionView->getSelectedSections();
753 // myCurve->startOperation();
754 for( int i = 0 ; i < aSelSections.size() ; i++ ){
755 myCurve->setSectionType(aSelSections[i], CurveCreator::Spline );
756 mySectionView->sectionChanged(aSelSections[i]);
758 // myCurve->finishOperation();
762 void CurveCreator_Widget::onSetPolyline()
766 // myCurve->startOperation();
767 QList<int> aSelSections = mySectionView->getSelectedSections();
768 for( int i = 0 ; i < aSelSections.size() ; i++ ){
769 myCurve->setSectionType( aSelSections[i], CurveCreator::Polyline );
770 mySectionView->sectionChanged( aSelSections[i] );
772 // myCurve->finishOperation();
776 void CurveCreator_Widget::onCloseSections()
780 // myCurve->startOperation();
781 QList<int> aSelSections = mySectionView->getSelectedSections();
782 for( int i = 0 ; i < aSelSections.size() ; i++ ){
783 myCurve->setClosed(aSelSections[i], true);
784 mySectionView->sectionChanged(aSelSections[i]);
786 // myCurve->finishOperation();
790 void CurveCreator_Widget::onUncloseSections()
794 // myCurve->startOperation();
795 QList<int> aSelSections = mySectionView->getSelectedSections();
796 for( int i = 0 ; i < aSelSections.size() ; i++ ){
797 myCurve->setClosed(aSelSections[i], false);
798 mySectionView->sectionChanged(aSelSections[i]);
800 // myCurve->finishOperation();
804 void CurveCreator_Widget::onUndo()
809 CurveCreator_ICurve::SectionToPointList aPoints;
810 startCurveModification( aPoints, false );
812 finishCurveModification();
813 mySectionView->reset();
816 void CurveCreator_Widget::onRedo()
820 CurveCreator_ICurve::SectionToPointList aPoints;
821 startCurveModification( aPoints, false );
823 finishCurveModification();
824 mySectionView->reset();
827 void CurveCreator_Widget::updateUndoRedo()
831 QAction* anAct = myActionMap[UNDO_ID];
833 if( myCurve->getNbUndo() != 0 ){
834 anAct->setEnabled(true);
837 anAct->setDisabled(true);
840 anAct = myActionMap[REDO_ID];
842 if( myCurve->getNbRedo() != 0 ){
843 anAct->setEnabled(true);
846 anAct->setDisabled(true);
851 void CurveCreator_Widget::onContextMenu( QPoint thePoint )
853 QList<ActionId> aContextActions;
854 aContextActions << CLEAR_ALL_ID << JOIN_ALL_ID << SEPARATOR_ID <<
855 CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID <<
856 SET_SECTIONS_SPLINE_ID;
857 QPoint aGlPoint = mySectionView->mapToGlobal(thePoint);
859 QList<ActionId> aResAct;
860 for( int i = 0 ; i < aContextActions.size() ; i++ ){
861 if( aContextActions[i] != SEPARATOR_ID ){
862 if( myActionMap.contains(aContextActions[i]) ){
863 QAction* anAct = myActionMap[aContextActions[i]];
864 if( anAct->isEnabled() ){
865 aResAct << aContextActions[i];
871 aResAct << SEPARATOR_ID;
877 QMenu* aMenu = new QMenu(this);
878 for( int i = 0 ; i < aResAct.size() ; i++ ){
879 if( aResAct[i] == SEPARATOR_ID ){
880 aMenu->addSeparator();
883 QAction* anAct = myActionMap[aResAct[i]];
884 aMenu->insertAction(NULL, anAct);
887 aMenu->exec(aGlPoint);
890 QList<int> CurveCreator_Widget::getSelectedSections()
892 return mySectionView->getSelectedSections();
895 QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints()
897 return mySectionView->getSelectedPoints();
901 * According to the widget state, performs the remove action
903 void CurveCreator_Widget::removeSelected()
909 * Checks whether there are some selection to be removed
911 bool CurveCreator_Widget::removeEnabled()
913 bool isEnabled = getActionMode() == ModificationMode;
915 QList<int> aSelSections = mySectionView->getSelectedSections();
916 CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
917 isEnabled = aSelType == CurveCreator_TreeView::ST_SECTIONS &&
918 aSelSections.size() == 1;
924 //=================================================================================
925 // function : GeometryGUI::onGetCoordsByClick()
926 // purpose : Manage mouse press events in Additon mode
927 //=================================================================================
928 void CurveCreator_Widget::onGetCoordsByClick( QMouseEvent* pe )
930 if (pe->button() != Qt::LeftButton)
933 if ( pe->modifiers() != Qt::ControlModifier ) {
934 Handle(AIS_InteractiveContext) ic = getAISContext();
941 if ( pe->modifiers() == Qt::ShiftModifier )
942 ic->ShiftSelect(); // Append selection
944 ic->Select(); // New selection
946 /*TopoDS_Shape aShape;
949 if ( ic->MoreSelected() )
950 aShape = ic->SelectedShape();
952 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
953 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
956 OCCViewer_ViewPort3d* vp = getViewPort();
957 aPnt = CurveCreator_Utils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
959 // set the coordinates into dialog
960 CurveCreator::Coordinates aCoords;
961 aCoords.push_back( aPnt.X() );
962 aCoords.push_back( aPnt.Y() );
963 if ( myCurve->getDimension() == 3 ) {
964 aCoords.push_back( aPnt.Z() );
966 onAddNewPoint(aCoords);
967 // myNewPointEditor->setCoordinates( aCoords );
972 * Manage mouse press events
973 * \param theWindow an owner of the signal
974 * \param theEvent a mouse event
976 void CurveCreator_Widget::onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent )
978 if ( theEvent->button() != Qt::LeftButton )
981 switch( getActionMode() ) {
982 case ModificationMode: {
983 //store initial cursor position for Drag&Drop
984 setDragStarted( true, theEvent->pos() );
988 onGetCoordsByClick( theEvent );
997 * Manage mouse release events in Modification mode
998 * \param theWindow an owner of the signal
999 * \param theEvent a mouse event
1001 void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent )
1003 if ( getActionMode() != ModificationMode )
1006 if ( myDragStarted ) {
1007 bool isDragged = myDragged;
1008 CurveCreator_ICurve::SectionToPointList aDraggedPoints;
1010 aDraggedPoints = myDragPoints;
1012 setDragStarted( false );
1013 // if the drag of some points has happened, restore the drag selection
1014 if ( aDraggedPoints.size() > 0 )
1017 setSelectedPonts( aDraggedPoints );
1018 END_MEASURE_TIME( "drop" );
1021 else // check whether the segment is clicked an a new point should be added to the segment
1022 insertPointToSelectedSegment( theEvent->pos().x(), theEvent->pos().y() );
1024 // updates the input panel table to show the selected point coordinates
1025 updateLocalPointView();
1029 * Manage mouse move events in Modification mode
1030 * \param theWindow an owner of the signal
1031 * \param theEvent a mouse event
1033 void CurveCreator_Widget::onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent )
1035 if ( getActionMode() != ModificationMode || !myDragStarted )
1038 QPoint aPos = theEvent->pos();
1039 if ( (aPos - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() )
1044 moveSelectedPoints( aPos.x(), aPos.y() );
1045 myDragStartPosition = aPos;
1047 END_MEASURE_TIME( "drag" );
1051 * Set zero viewer by the last view closed in
1052 * \param theManager a viewer manager
1054 void CurveCreator_Widget::onLastViewClosed( SUIT_ViewManager* theManager )
1059 void CurveCreator_Widget::onMousePress( QMouseEvent* theEvent )
1061 onMousePress( 0, theEvent );
1064 void CurveCreator_Widget::onMouseRelease( QMouseEvent* theEvent )
1066 onMouseRelease( 0, theEvent );
1069 void CurveCreator_Widget::onMouseMove( QMouseEvent* theEvent )
1071 onMouseMove( 0, theEvent );
1074 void CurveCreator_Widget::onCellChanged( int theRow, int theColumn )
1076 int aCurrSect = myLocalPointView->getSectionId( theRow );
1077 int aPntIndex = myLocalPointView->getPointId( theRow );
1079 if ( aPntIndex < 0 )
1082 CurveCreator_ICurve::SectionToPointList aSelPoints;
1083 startCurveModification( aSelPoints );
1085 double aX = myLocalPointView->item( theRow, 2 )->data( Qt::UserRole ).toDouble();
1086 double anY = myLocalPointView->item( theRow, 3 )->data( Qt::UserRole ).toDouble();
1087 std::deque<float> aChangedPos;
1088 aChangedPos.push_back( aX );
1089 aChangedPos.push_back( anY );
1090 myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos );
1092 finishCurveModification( aSelPoints );
1096 * Removes a selected section from the curve. Updates undo/redo status
1098 void CurveCreator_Widget::removeSection()
1100 QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
1103 // myCurve->startOperation();
1104 for( int i = 0 ; i < aSelPoints.size() ; i++ ){
1105 if( aCurrSect != aSelPoints[i].first ){
1107 aCurrSect = aSelPoints[i].first;
1109 int aPntIndx = aSelPoints[i].second - aRemoveCnt;
1110 myCurve->removePoint( aCurrSect, aPntIndx );
1111 mySectionView->pointsRemoved( aCurrSect, aPntIndx );
1114 QList<int> aSections = mySectionView->getSelectedSections();
1115 for( int i = 0 ; i < aSections.size() ; i++ ){
1116 int aSectNum = aSections[i] - (i);
1117 myCurve->removeSection( aSectNum );
1118 mySectionView->sectionsRemoved( aSectNum );
1120 // myCurve->finishOperation();
1121 mySectionView->clearSelection();
1126 * Removes a selected points from the curve. Updates undo/redo status
1128 void CurveCreator_Widget::removePoint()
1130 CurveCreator_ICurve::SectionToPointList aPoints;
1131 getSelectedPonts( aPoints );
1132 if ( aPoints.size() == 0 )
1135 CurveCreator_ICurve::SectionToPointList aSelPoints;
1136 startCurveModification( aSelPoints, false );
1138 myCurve->removeSeveralPoints( aPoints );
1139 finishCurveModification( CurveCreator_ICurve::SectionToPointList() );
1142 void CurveCreator_Widget::insertPointToSelectedSegment( const int theX,
1145 Handle(AIS_InteractiveContext) aContext = getAISContext();
1147 OCCViewer_ViewPort3d* aViewPort = getViewPort();
1148 Handle(V3d_View) aView;
1150 aView = aViewPort->getView();
1152 if ( aContext.IsNull() || aView.IsNull() )
1155 gp_Pnt aPoint1, aPoint2;
1156 bool isFoundPoint = CurveCreator_Utils::getNeighbourPoints( aContext, aView, theX, theY,
1157 aPoint, aPoint1, aPoint2 );
1158 if ( !isFoundPoint )
1161 // insert the point to the model curve
1162 CurveCreator_ICurve::SectionToPointList aSelPoints;
1163 startCurveModification( aSelPoints );
1165 CurveCreator::Coordinates aCoords;
1166 aCoords.push_back( aPoint.X() );
1167 aCoords.push_back( aPoint.Y() );
1169 CurveCreator_ICurve::SectionToPointList aPoints1, aPoints2;
1170 findSectionsToPoints( aPoint1.X(), aPoint1.Y(), aPoints1 );
1171 findSectionsToPoints( aPoint2.X(), aPoint2.Y(), aPoints2 );
1172 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints1.begin(),
1173 aLast = aPoints1.end();
1174 int aSectionId = -1;
1175 // there can be a case when a new point is added into two sections
1176 int aPoint1Id = -1, aPoint2Id = -1;
1177 for ( ; anIt != aLast && aSectionId < 0; anIt++ ) {
1178 int aSectionCur = anIt->first;
1179 CurveCreator_ICurve::SectionToPointList::const_iterator anIt2 = aPoints2.begin(),
1180 aLast2 = aPoints2.end();
1181 for ( ; anIt2 != aLast2 && aSectionId < 0; anIt2++ ) {
1182 if ( anIt2->first == aSectionCur ) {
1183 aSectionId = aSectionCur;
1184 aPoint1Id = anIt->second;
1185 aPoint2Id = anIt2->second;
1190 int anInsertPos = -1;
1191 int aLastPoint = myCurve->getNbPoints( aSectionId )-1;
1192 if ( ( aPoint1Id == aLastPoint && aPoint2Id == 0 ) ||
1193 ( aPoint2Id == aLastPoint && aPoint1Id == 0 ) )
1194 anInsertPos = -1; // if the section happens between first and last points
1196 anInsertPos = aPoint1Id < aPoint2Id ? aPoint1Id + 1 : aPoint2Id + 1;
1198 myCurve->addPoints( aCoords, aSectionId, anInsertPos );
1199 mySectionView->pointsAdded( aSectionId, myCurve->getNbPoints( aSectionId ) );
1201 finishCurveModification( aSelPoints );
1206 void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
1207 const int theYPosition )
1209 OCCViewer_ViewPort3d* aViewPort = getViewPort();
1213 CurveCreator_ICurve::SectionToPointList aPoints;
1214 startCurveModification( aPoints, false );
1216 gp_Pnt aStartPnt = CurveCreator_Utils::ConvertClickToPoint( myDragStartPosition.x(),
1217 myDragStartPosition.y(),
1218 aViewPort->getView() );
1219 gp_Pnt anEndPnt = CurveCreator_Utils::ConvertClickToPoint( theXPosition, theYPosition,
1220 aViewPort->getView() );
1221 double aXDelta = aStartPnt.X() - anEndPnt.X();
1222 double anYDelta = aStartPnt.Y() - anEndPnt.Y();
1224 CurveCreator_ICurve::SectionToPointCoordsList aCoordList;
1225 std::deque<float> aChangedPos;
1226 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = myDragPoints.begin(),
1227 aLast = myDragPoints.end();
1228 for ( ; anIt != aLast; anIt++ ) {
1229 int aSectionId = anIt->first;
1230 int aPointId = anIt->second;
1231 aChangedPos = myCurve->getPoint( aSectionId, aPointId );
1232 if ( aChangedPos.size() < 2 )
1234 aChangedPos[0] = aChangedPos[0] - aXDelta;
1235 aChangedPos[1] = aChangedPos[1] - anYDelta;
1237 aCoordList.push_back(
1238 std::make_pair(std::make_pair( aSectionId, aPointId ),
1241 myCurve->setSeveralPoints( aCoordList );
1244 finishCurveModification( myDragPoints );
1247 void CurveCreator_Widget::updateLocalPointView()
1249 if ( myDragStarted )
1251 Handle(AIS_InteractiveContext) aContext = getAISContext();
1252 if ( aContext.IsNull() )
1255 std::list<float> aSelectedList = CurveCreator_Utils::getSelectedPoints( aContext );
1257 std::list<float>::const_iterator anIt = aSelectedList.begin(), aLast = aSelectedList.end();
1259 bool isBlocked = myLocalPointView->blockSignals(true);
1260 myLocalPointView->setRowCount( 0 );
1261 for ( ; anIt != aLast; anIt++ )
1268 myLocalPointView->addLocalPointToTable( aX, anY );
1270 myLocalPointView->blockSignals(isBlocked);
1276 void CurveCreator_Widget::setLocalPointContext( const bool theOpen, const bool isUpdateTable )
1278 CurveCreator_Utils::setLocalPointContext( getAISContext(), theOpen );
1279 if ( !theOpen && isUpdateTable )
1280 updateLocalPointView();
1284 * Set drag operation started. Save the position and a list of dragged points
1285 * \param theState the drag operation state: started/finished
1286 * \param thePoint the start drag position
1288 void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& thePoint )
1291 getSelectedPonts( myDragPoints );
1292 myDragStarted = myDragPoints.size();
1293 myDragStartPosition = thePoint;
1294 if ( myDragStarted ) {
1295 // change a viewer interaction style in order to avoid a select rectangle build
1296 myDragInteractionStyle = changeInteractionStyle( SUIT_ViewModel::KEY_FREE );
1300 if ( myDragStarted )
1301 changeInteractionStyle( myDragInteractionStyle );
1302 myDragStarted = false;
1303 myDragPoints.clear();
1308 void CurveCreator_Widget::getSelectedPonts( CurveCreator_ICurve::SectionToPointList& thePoints )
1311 for ( int i = 0, aNb = myLocalPointView->rowCount(); i < aNb; i++ )
1312 thePoints.push_back( std::make_pair( myLocalPointView->getSectionId( i ),
1313 myLocalPointView->getPointId( i ) ) );
1317 bool CurveCreator_Widget::isIntersectVertexToPoint( const TopoDS_Vertex& theVertex,
1318 const CurveCreator_ICurve::SectionToPoint& theSToPoint )
1320 bool isIntersect = false;
1321 if ( theVertex.IsNull() )
1325 CurveCreator_UtilsICurve::getPoint( myCurve, theSToPoint.first, theSToPoint.second,
1327 gp_Pnt aVertexPoint = BRep_Tool::Pnt( theVertex );
1328 isIntersect = fabs( aVertexPoint.X() - aSPoint.X() ) < LOCAL_SELECTION_TOLERANCE &&
1329 fabs( aVertexPoint.Y() - aSPoint.Y() ) < LOCAL_SELECTION_TOLERANCE;
1335 void CurveCreator_Widget::setSelectedPonts( const CurveCreator_ICurve::SectionToPointList& thePoints )
1337 if ( myDragStarted )
1340 Handle(AIS_InteractiveContext) ic = getAISContext();
1341 if ( ic.IsNull() || !ic->HasOpenedContext() )
1344 AIS_ListOfInteractive aListToSelect;
1345 AIS_ListOfInteractive aDisplayedList;
1346 ic->DisplayedObjects( aDisplayedList );
1347 ic->ClearSelected( Standard_False );
1349 bool isSelectedVertex = false;
1351 //ASL: std::vector<TopoDS_Vertex> aVetexVec;
1352 for ( AIS_ListIteratorOfListOfInteractive it( aDisplayedList ); it.More(); it.Next() )
1354 Handle(AIS_InteractiveObject) anAIS = it.Value();
1355 if ( anAIS.IsNull() )
1357 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast( anAIS );
1358 if ( anAISShape.IsNull() )
1362 /*ASL: const TopoDS_Shape& aShape = anAISShape->Shape();
1363 TopExp_Explorer aExpV( aShape, TopAbs_VERTEX);
1364 for ( ; aExpV.More(); aExpV.Next() )
1366 const TopoDS_Vertex& aVertex = TopoDS::Vertex( aExpV.Current() );
1367 aVetexVec.push_back( aVertex );
1371 //ASL: we convert list of point indices to list of points coordinates
1372 int aSize = thePoints.size();
1373 std::vector<gp_Pnt> aPntsToSelect( aSize );
1375 CurveCreator_ICurve::SectionToPointList::const_iterator
1376 aPIt = thePoints.begin(), aPLast = thePoints.end();
1377 CurveCreator_ICurve::SectionToPoint aSToPoint;
1378 for( int i=0; aPIt != aPLast; aPIt++, i++ )
1380 gp_Pnt aPntToSelect;
1381 CurveCreator_UtilsICurve::getPoint( myCurve, aPIt->first, aPIt->second, aPntToSelect );
1382 aPntsToSelect[i] = aPntToSelect;
1386 //ASL: we switch off automatic highlight to improve performance of selection
1387 ic->SetAutomaticHilight( Standard_False );
1389 Handle_SelectMgr_Selection aSelection = anAISShape->Selection( AIS_Shape::SelectionMode( TopAbs_VERTEX ) );
1390 for( aSelection->Init(); aSelection->More(); aSelection->Next() )
1392 Handle_SelectBasics_SensitiveEntity aSenEntity = aSelection->Sensitive();
1393 Handle_Select3D_SensitivePoint aSenPnt = Handle_Select3D_SensitivePoint::DownCast( aSenEntity );
1395 gp_Pnt anOwnerPnt = aSenPnt->Point();
1396 Handle_SelectMgr_EntityOwner anOwner = Handle_SelectMgr_EntityOwner::DownCast( aSenPnt->OwnerId() );
1399 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(),
1400 aLast = thePoints.end();
1401 bool isFound = false;
1402 for( int i=0; i<aSize; i++ )
1404 bool isIntersect = fabs( aPntsToSelect[i].X() - anOwnerPnt.X() ) < LOCAL_SELECTION_TOLERANCE &&
1405 fabs( aPntsToSelect[i].Y() - anOwnerPnt.Y() ) < LOCAL_SELECTION_TOLERANCE;
1408 ic->AddOrRemoveSelected( anOwner, Standard_False );
1415 /*ASL: std::vector<TopoDS_Vertex>::const_iterator aVecIt = aVetexVec.begin(), aVecLast = aVetexVec.end();
1416 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(),
1417 aLast = thePoints.end();
1418 int aSize = aVetexVec.size();
1419 CurveCreator_ICurve::SectionToPoint aSToPoint;
1420 int anAddedSize = 0;
1421 for( ; anIt != aLast; anIt++ ) {
1424 for ( aVecIt = aVetexVec.begin(); aVecIt != aVecLast; aVecIt++ )
1426 TopoDS_Vertex aVertex = TopoDS::Vertex( *aVecIt );
1427 if ( isIntersectVertexToPoint( aVertex, aSToPoint ) ) {
1428 ic->AddOrRemoveSelected( aVertex, Standard_False );
1429 isSelectedVertex = true;
1435 //ASL: we switch on again automatic highlight (otherwise selection will not be shown)
1436 // and call HilightPicked to draw selected owners
1437 ic->SetAutomaticHilight( Standard_True );
1438 ic->LocalContext()->HilightPicked( Standard_True );
1440 //ic->UpdateCurrentViewer();
1441 if ( !isSelectedVertex )
1442 setObjectsSelected( aListToSelect );
1443 updateLocalPointView();
1447 * Get viewer information before perform the curve modification.
1448 * Take a list of selected cuve points an close local context.
1449 * The context should be closed because the curve presentation is
1450 * redisplayed and if it is not closed, when we close the local context
1451 * later, the presentation shown in the local context is disappeared.
1452 * \param thePoints an output list of curve selected points
1453 * \param theFillPoints a flag whether the selection list should be filled
1455 void CurveCreator_Widget::startCurveModification(
1456 CurveCreator_ICurve::SectionToPointList& thePoints,
1457 const bool theFillPoints )
1459 if ( theFillPoints ) {
1461 getSelectedPonts( thePoints );
1463 setLocalPointContext( false );
1467 * Restore the viewer state after the curve modification is done.
1468 * Open local context and select given points inside it.
1469 * \param thePoints a list of curve selected points
1471 void CurveCreator_Widget::finishCurveModification(
1472 const CurveCreator_ICurve::SectionToPointList& thePoints )
1474 if ( getActionMode() == ModificationMode )
1475 setLocalPointContext( true );
1476 setSelectedPonts( thePoints );
1481 * Returns a point index in the model curve by the point coordinates in the viewer
1482 * \param theX the X coordinate of the point
1483 * \param theY the Y coordinate of the point
1485 int CurveCreator_Widget::findLocalPointIndex( int theSectionId, float theX, float theY )
1487 return CurveCreator_UtilsICurve::findLocalPointIndex( myCurve, theSectionId, theX, theY );
1490 void CurveCreator_Widget::findSectionsToPoints( const double theX, const double theY,
1491 CurveCreator_ICurve::SectionToPointList& thePoints )
1493 return CurveCreator_UtilsICurve::findSectionsToPoints( myCurve, theX, theY, thePoints );
1496 void CurveCreator_Widget::convert( const CurveCreator_ICurve::SectionToPointList& thePoints,
1497 QMap<int, QList<int> >& theConvPoints )
1499 return CurveCreator_UtilsICurve::convert( thePoints, theConvPoints );
1503 * Returns whethe the container has the value
1504 * \param theList a container of values
1505 * \param theValue a value
1507 bool CurveCreator_Widget::contains( const CurveCreator_ICurve::SectionToPointList& theList,
1508 const CurveCreator_ICurve::SectionToPoint& theValue ) const
1510 return CurveCreator_UtilsICurve::contains( theList, theValue );