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 int theLocalPointRowLimit )
111 : QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0),
112 myDragStarted( false ), myDragInteractionStyle( SUIT_ViewModel::STANDARD ),
113 myOCCViewer( 0 ), myLocalPointRowLimit( theLocalPointRowLimit )
115 myNewSectionEditor = new CurveCreator_NewSectionDlg( this );
116 myNewSectionEditor->hide();
117 connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()) );
118 connect( myNewSectionEditor, SIGNAL(modifySection()), this, SLOT(onModifySection()) );
119 connect( myNewSectionEditor, SIGNAL(cancelSection()), this, SLOT(onCancelSection()) );
121 QGroupBox* aSectionGroup = new QGroupBox(tr("Sections"),this);
123 mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup);
124 connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) );
125 connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) );
126 connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) );
128 myLocalPointView = new CurveCreator_TableView( myCurve, this );
129 connect( myLocalPointView, SIGNAL( cellChanged( int, int ) ),
130 this, SLOT( onCellChanged( int, int ) ) );
132 QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup);
133 // QToolButton* anUndoBtn = new QToolButton(aTB);
135 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
136 QPixmap anUndoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_UNDO")));
137 QPixmap aRedoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_REDO")));
138 QPixmap aNewSectionPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_SECTION")));
139 QPixmap aNewPointPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_POINT")));
140 QPixmap anEditPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
141 QPixmap aDetectPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
142 QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
143 QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
144 QPixmap aRemovePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_DELETE")));
145 QPixmap aJoinPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_JOIN")));
146 QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP")));
147 QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN")));
149 QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"),
150 QKeySequence(Qt::ControlModifier|Qt::Key_Z) );
151 connect(anAct, SIGNAL(triggered()), this, SLOT(onUndo()) );
152 aTB->addAction(anAct);
154 anAct = createAction( REDO_ID, tr("REDO"), aRedoPixmap, tr("REDO_TLT"),
155 QKeySequence(Qt::ControlModifier|Qt::Key_Y) );
156 connect(anAct, SIGNAL(triggered()), this, SLOT(onRedo()) );
157 aTB->addAction(anAct);
161 anAct = createAction( NEW_SECTION_ID, tr("NEW_SECTION"), aNewSectionPixmap, tr("NEW_SECTION_TLT"),
162 QKeySequence(Qt::ControlModifier|Qt::Key_N) );
163 connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) );
164 aTB->addAction(anAct);
167 anAct = createAction( ADDITION_MODE_ID, tr("ADDITION_MODE"), aNewPointPixmap, tr("ADDITION_MODE_TLT"),
169 anAct->setCheckable(true);
170 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onAdditionMode(bool)) );
171 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
172 aTB->addAction(anAct);
174 anAct = createAction( MODIFICATION_MODE_ID, tr("MODIFICATION_MODE"), anEditPointsPixmap, tr("MODIFICATION_MODE_TLT"),
176 anAct->setCheckable(true);
177 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onModificationMode(bool)) );
178 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
179 aTB->addAction(anAct);
181 anAct = createAction( DETECTION_MODE_ID, tr("DETECTION_MODE"), aDetectPointsPixmap, tr("DETECTION_MODE_TLT"),
183 anAct->setCheckable(true);
184 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onDetectionMode(bool)) );
185 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
186 aTB->addAction(anAct);
188 anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), QPixmap(), tr("CLOSE_SECTIONS_TLT"),
189 QKeySequence(Qt::ControlModifier|Qt::Key_W) );
190 connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) );
192 anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), QPixmap(),
193 tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) );
194 connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) );
196 anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"),
197 aPolylinePixmap, tr("SET_POLYLINE_TLT"),
198 QKeySequence(Qt::ControlModifier|Qt::Key_E) );
199 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) );
201 anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), aSplinePixmap,
202 tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) );
203 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) );
205 anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemovePixmap, tr("REMOVE_TLT"),
206 QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) );
207 connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) );
208 aTB->addAction(anAct);
210 //aTB->addSeparator();
212 //anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"),
213 // QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) );
214 //connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) );
215 //aTB->addAction(anAct);
217 anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"),
218 QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) );
219 connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) );
222 //anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), QPixmap(), tr("JOIN_ALL_TLT"),
223 // QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) );
224 //connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) );
226 QVBoxLayout* aSectLayout = new QVBoxLayout();
227 aSectLayout->setMargin( 5 );
228 aSectLayout->setSpacing( 5 );
229 aSectLayout->addWidget(aTB);
230 aSectLayout->addWidget(mySectionView);
231 aSectLayout->addWidget( myLocalPointView );
232 aSectionGroup->setLayout(aSectLayout);
233 QVBoxLayout* aLay = new QVBoxLayout();
234 aLay->setMargin( 0 );
235 aLay->setSpacing( 5 );
236 // aLay->addLayout(aNameLayout);
237 aLay->addWidget(aSectionGroup);
240 updateActionsStates();
247 void CurveCreator_Widget::setOCCViewer( OCCViewer_Viewer* theViewer )
249 if ( myOCCViewer == theViewer )
253 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
254 ( myOCCViewer->getViewManager() );
255 disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
256 this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
257 disconnect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
258 this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
259 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
260 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
261 disconnect( aViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
262 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
263 // restore normal mode in the viewer
264 OCCViewer_Utilities::setViewer2DMode( myOCCViewer, OCCViewer_ViewWindow::No2dMode );
265 // all local contexts should be closed if the viewer is not more used
266 setLocalPointContext( false, true );
269 myOCCViewer = theViewer;
271 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
272 ( myOCCViewer->getViewManager() );
273 connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
274 this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
275 connect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
276 this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
277 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
278 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
279 connect( aViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
280 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
281 OCCViewer_Utilities::setViewer2DMode( myOCCViewer, OCCViewer_ViewWindow::XYPlane );
286 * Returns current OCC viewer
288 OCCViewer_Viewer* CurveCreator_Widget::getOCCViewer()
294 * Returns OCC viewer context
296 Handle(AIS_InteractiveContext) CurveCreator_Widget::getAISContext()
298 Handle(AIS_InteractiveContext) aContext;
299 OCCViewer_Viewer* aViewer = getOCCViewer();
301 aContext = aViewer->getAISContext();
307 * Returns OCC viewer view port
309 OCCViewer_ViewPort3d* CurveCreator_Widget::getViewPort()
311 OCCViewer_ViewPort3d* aViewPort = 0;
312 OCCViewer_Viewer* aViewer = getOCCViewer();
314 aViewPort = ((OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView())->getViewPort();
320 * Set interaction style in the OCC viewer
321 * \param theStyle a new style
322 * \return the previous style
324 int CurveCreator_Widget::changeInteractionStyle( int theStyle )
326 OCCViewer_Viewer* aViewer = getOCCViewer();
330 int aPrevStyle = aViewer->interactionStyle();
331 aViewer->setInteractionStyle( theStyle );
337 * Set interaction style in the OCC viewer
338 * \param theStyle a new style
339 * \return the previous style
341 void CurveCreator_Widget::setObjectsSelected(const AIS_ListOfInteractive& theList)
343 OCCViewer_Viewer* aViewer = getOCCViewer();
345 aViewer->setObjectsSelected(theList);
348 //=======================================================================
350 // purpose: reset the widget viewer, close local context, clear selection
351 //=======================================================================
352 void CurveCreator_Widget::reset()
356 void CurveCreator_Widget::setCurve( CurveCreator_ICurve* theCurve )
359 mySectionView->setCurve( myCurve );
360 myLocalPointView->setCurve( myCurve );
361 updateActionsStates();
365 void CurveCreator_Widget::onSelectionChanged()
367 updateActionsStates();
369 emit selectionChanged();
372 void CurveCreator_Widget::updateActionsStates()
374 QList<ActionId> anEnabledAct;
376 anEnabledAct << NEW_SECTION_ID << MODIFICATION_MODE_ID;
377 if ( removeEnabled() )
378 anEnabledAct << REMOVE_ID;
379 QList<int> aSelSections = mySectionView->getSelectedSections();
380 QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints();
381 CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
383 case CurveCreator_TreeView::ST_NOSEL:{
386 case CurveCreator_TreeView::ST_SECTIONS:{
387 /*if( aSelSections[0] > 0 ){
388 anEnabledAct << UP_ID;
390 if( aSelSections.size() == 1 ){
391 anEnabledAct << ADDITION_MODE_ID << DETECTION_MODE_ID;
393 switch ( getActionMode() ) {
397 QList<int> aSelSection = mySectionView->getSelectedSections();
398 if( aSelSection.size() > 0 ){
399 mySection = aSelSection[0];
400 myPointNum = myCurve->getNbPoints(mySection);
404 case ModificationMode: {
405 anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID;
406 int aSectCnt = myCurve->getNbSections();
408 anEnabledAct << CLEAR_ALL_ID;
411 // anEnabledAct << JOIN_ALL_ID;
412 //if( aSelSections.size() > 1 ){
413 // anEnabledAct << JOIN_ID;
417 case DetectionMode: {
424 /*if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){
425 anEnabledAct << DOWN_ID;
429 /*case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{
430 if( aSelPoints[0].second > 0 ){
431 anEnabledAct << UP_ID;
433 int aLastIndex = aSelPoints.size()-1;
434 int aSect = aSelPoints[0].first;
435 if( aSelPoints[aLastIndex].second < (myCurve->getNbPoints(aSect) - 1)){
436 anEnabledAct << DOWN_ID;
438 if( aSelPoints.size() == 1){
439 anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID;
446 /*int aSelObjsCnt = aSelPoints.size() + aSelSections.size();
447 if( aSelObjsCnt > 0 ){
448 anEnabledAct << REMOVE_ID;
450 if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){
451 anEnabledAct << REMOVE_ALL_ID;
454 //if( myCurve->getNbSections() > 1 ){
455 // anEnabledAct << JOIN_ALL_ID;
458 QList<ActionId> anIds = myActionMap.keys();
459 for( int i = 0 ; i < anIds.size() ; i++ ){
460 if( myActionMap.contains(anIds[i]) ){
461 if( anEnabledAct.contains(anIds[i]) ){
462 myActionMap[anIds[i]]->setEnabled(true);
465 myActionMap[anIds[i]]->setEnabled(false);
471 void CurveCreator_Widget::onAdditionMode(bool checked)
476 Handle(AIS_InteractiveContext) aContext = getAISContext();
477 if( !myCurve || aContext.IsNull() )
482 QList<int> aSelSection = mySectionView->getSelectedSections();
483 if( aSelSection.size() > 0 ){
484 mySection = aSelSection[0];
487 QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
488 if( aSelPoints.size() > 0 ){
489 mySection = aSelPoints[0].first;
490 myPointNum = aSelPoints[0].second + 1;
493 // emit subOperationStarted( myNewPointEditor );
496 void CurveCreator_Widget::onModificationMode(bool checked)
498 myLocalPointView->setVisible( checked );
501 void CurveCreator_Widget::onDetectionMode(bool checked)
505 void CurveCreator_Widget::onModeChanged(bool checked)
507 ActionMode aMode = NoneMode;
509 QAction* anAction = (QAction*)sender();
510 switch(myActionMap.key(anAction)) {
511 case ADDITION_MODE_ID:
512 aMode = AdditionMode;
513 if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
514 myActionMap[MODIFICATION_MODE_ID]->trigger();
515 else if (myActionMap[DETECTION_MODE_ID]->isChecked())
516 myActionMap[DETECTION_MODE_ID]->trigger();
518 case MODIFICATION_MODE_ID:
519 aMode = ModificationMode;
520 if (myActionMap[ADDITION_MODE_ID]->isChecked())
521 myActionMap[ADDITION_MODE_ID]->trigger();
522 else if (myActionMap[DETECTION_MODE_ID]->isChecked())
523 myActionMap[DETECTION_MODE_ID]->trigger();
525 case DETECTION_MODE_ID:
526 aMode = DetectionMode;
527 if (myActionMap[ADDITION_MODE_ID]->isChecked())
528 myActionMap[ADDITION_MODE_ID]->trigger();
529 else if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
530 myActionMap[MODIFICATION_MODE_ID]->trigger();
534 updateActionsStates();
536 setLocalPointContext( aMode == ModificationMode, true );
539 void CurveCreator_Widget::onAddNewPoint(const CurveCreator::Coordinates& theCoords)
543 //myCurve->addPoints(theCoords, mySection, myPointNum );
544 //mySectionView->pointsAdded( mySection, myPointNum );
546 QList<int> aSections = mySectionView->getSelectedSections();
547 if( aSections.size() == 0 ){
550 int aSection = aSections[0];
551 myCurve->addPoints(theCoords, aSection); // add to the end of section
552 mySectionView->pointsAdded( aSection, myCurve->getNbPoints( aSection ) );
553 updateActionsStates();
557 void CurveCreator_Widget::onNewSection()
561 myNewSectionEditor->clear();
562 myNewSectionEditor->setEditMode(false);
563 QString aSectName = QString( CurveCreator_UtilsICurve::getUniqSectionName( myCurve ).c_str() );
564 myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline );
565 emit subOperationStarted( myNewSectionEditor );
568 void CurveCreator_Widget::onAddNewSection()
572 myCurve->addSection( myNewSectionEditor->getName().toStdString(),
573 myNewSectionEditor->getSectionType(),
574 myNewSectionEditor->isClosed() );
575 mySectionView->sectionAdded( -1 ); // add a new section to the end of list
576 QString aNewName = QString( CurveCreator_UtilsICurve::getUniqSectionName( myCurve ).c_str() );
577 myNewSectionEditor->setSectionName(aNewName);
578 updateActionsStates();
583 void CurveCreator_Widget::onCancelSection()
585 emit subOperationFinished( myNewSectionEditor );
588 QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
589 const QString& theToolTip, const QKeySequence& theShortcut )
591 QAction* anAct = new QAction(theName,this);
592 if( !theImage.isNull() ){
593 anAct->setIcon(theImage);
595 anAct->setShortcut(theShortcut);
596 anAct->setToolTip(theToolTip);
597 myActionMap[theId] = anAct;
601 QAction* CurveCreator_Widget::getAction(ActionId theId)
603 if( myActionMap.contains(theId) )
604 return myActionMap[theId];
608 CurveCreator_Widget::ActionMode CurveCreator_Widget::getActionMode() const
610 ActionMode aMode = NoneMode;
612 if ( myActionMap[ADDITION_MODE_ID]->isChecked() )
613 aMode = AdditionMode;
614 else if ( myActionMap[MODIFICATION_MODE_ID]->isChecked() )
615 aMode = ModificationMode;
616 else if ( myActionMap[DETECTION_MODE_ID]->isChecked() )
617 aMode = DetectionMode;
622 void CurveCreator_Widget::onEditSection( int theSection )
626 mySection = theSection;
627 QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
628 bool isClosed = myCurve->isClosed(theSection);
629 CurveCreator::SectionType aType = myCurve->getSectionType(theSection);
630 myNewSectionEditor->setEditMode(true);
631 myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType );
633 emit subOperationStarted( myNewSectionEditor );
636 void CurveCreator_Widget::onModifySection()
640 QString aName = myNewSectionEditor->getName();
641 bool isClosed = myNewSectionEditor->isClosed();
642 CurveCreator::SectionType aSectType = myNewSectionEditor->getSectionType();
643 // myCurve->startOperation();
644 if( myCurve->getSectionName(mySection) != aName.toStdString() )
645 myCurve->setSectionName( mySection , aName.toStdString() );
647 if( myCurve->getSectionType(mySection) != aSectType )
648 myCurve->setSectionType( mySection, aSectType );
650 if( myCurve->isClosed(mySection) != isClosed )
651 myCurve->setClosed( mySection, isClosed );
652 // myCurve->finishOperation();
653 mySectionView->sectionChanged(mySection);
658 /*void CurveCreator_Widget::onEditPoint( int theSection, int thePoint )
660 if( !myNewPointEditor || !myEdit )
662 mySection = theSection;
663 myPointNum = thePoint;
664 QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
665 myNewPointEditor->setEditMode(true);
666 myNewPointEditor->setSectionName(aSectName);
667 myNewPointEditor->setDimension( myCurve->getDimension() );
668 CurveCreator::Coordinates aCoords = myCurve->getCoordinates(theSection,thePoint);
669 myNewPointEditor->setCoordinates(aCoords);
670 emit subOperationStarted( myNewPointEditor );
673 void CurveCreator_Widget::onModifyPoint()
677 CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates();
678 myEdit->setCoordinates( aCoords, mySection, myPointNum );
679 mySectionView->pointDataChanged( mySection, myPointNum );
684 void CurveCreator_Widget::onJoin()
688 QList<int> aSections = mySectionView->getSelectedSections();
689 if( aSections.size() == 0 ){
692 int aMainSect = aSections[0];
693 int aMainSectSize = myCurve->getNbPoints(aMainSect);
694 // myCurve->startOperation();
695 for( int i = 1 ; i < aSections.size() ; i++ ){
696 int aSectNum = aSections[i] - (i-1);
697 myCurve->join( aMainSect, aSectNum );
698 mySectionView->sectionsRemoved( aSectNum );
700 // myCurve->finishOperation();
701 int aNewSectSize = myCurve->getNbPoints(aMainSect);
702 if( aNewSectSize != aMainSectSize )
703 mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );
707 void CurveCreator_Widget::onRemove()
712 switch( getActionMode() ) {
716 case ModificationMode:
724 void CurveCreator_Widget::onClearAll()
729 mySectionView->reset();
730 updateActionsStates();
734 void CurveCreator_Widget::onJoinAll()
739 mySectionView->reset();
740 updateActionsStates();
744 void CurveCreator_Widget::onUndoSettings()
749 void CurveCreator_Widget::onSetSpline()
753 QList<int> aSelSections = mySectionView->getSelectedSections();
754 // myCurve->startOperation();
755 for( int i = 0 ; i < aSelSections.size() ; i++ ){
756 myCurve->setSectionType(aSelSections[i], CurveCreator::Spline );
757 mySectionView->sectionChanged(aSelSections[i]);
759 // myCurve->finishOperation();
763 void CurveCreator_Widget::onSetPolyline()
767 // myCurve->startOperation();
768 QList<int> aSelSections = mySectionView->getSelectedSections();
769 for( int i = 0 ; i < aSelSections.size() ; i++ ){
770 myCurve->setSectionType( aSelSections[i], CurveCreator::Polyline );
771 mySectionView->sectionChanged( aSelSections[i] );
773 // myCurve->finishOperation();
777 void CurveCreator_Widget::onCloseSections()
781 // myCurve->startOperation();
782 QList<int> aSelSections = mySectionView->getSelectedSections();
783 for( int i = 0 ; i < aSelSections.size() ; i++ ){
784 myCurve->setClosed(aSelSections[i], true);
785 mySectionView->sectionChanged(aSelSections[i]);
787 // myCurve->finishOperation();
791 void CurveCreator_Widget::onUncloseSections()
795 // myCurve->startOperation();
796 QList<int> aSelSections = mySectionView->getSelectedSections();
797 for( int i = 0 ; i < aSelSections.size() ; i++ ){
798 myCurve->setClosed(aSelSections[i], false);
799 mySectionView->sectionChanged(aSelSections[i]);
801 // myCurve->finishOperation();
805 void CurveCreator_Widget::onUndo()
810 CurveCreator_ICurve::SectionToPointList aPoints;
811 startCurveModification( aPoints, false );
813 finishCurveModification();
814 mySectionView->reset();
817 void CurveCreator_Widget::onRedo()
821 CurveCreator_ICurve::SectionToPointList aPoints;
822 startCurveModification( aPoints, false );
824 finishCurveModification();
825 mySectionView->reset();
828 void CurveCreator_Widget::updateUndoRedo()
832 QAction* anAct = myActionMap[UNDO_ID];
834 if( myCurve->getNbUndo() != 0 ){
835 anAct->setEnabled(true);
838 anAct->setDisabled(true);
841 anAct = myActionMap[REDO_ID];
843 if( myCurve->getNbRedo() != 0 ){
844 anAct->setEnabled(true);
847 anAct->setDisabled(true);
852 void CurveCreator_Widget::onContextMenu( QPoint thePoint )
854 QList<ActionId> aContextActions;
855 aContextActions << CLEAR_ALL_ID << JOIN_ALL_ID << SEPARATOR_ID <<
856 CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID <<
857 SET_SECTIONS_SPLINE_ID;
858 QPoint aGlPoint = mySectionView->mapToGlobal(thePoint);
860 QList<ActionId> aResAct;
861 for( int i = 0 ; i < aContextActions.size() ; i++ ){
862 if( aContextActions[i] != SEPARATOR_ID ){
863 if( myActionMap.contains(aContextActions[i]) ){
864 QAction* anAct = myActionMap[aContextActions[i]];
865 if( anAct->isEnabled() ){
866 aResAct << aContextActions[i];
872 aResAct << SEPARATOR_ID;
878 QMenu* aMenu = new QMenu(this);
879 for( int i = 0 ; i < aResAct.size() ; i++ ){
880 if( aResAct[i] == SEPARATOR_ID ){
881 aMenu->addSeparator();
884 QAction* anAct = myActionMap[aResAct[i]];
885 aMenu->insertAction(NULL, anAct);
888 aMenu->exec(aGlPoint);
891 QList<int> CurveCreator_Widget::getSelectedSections()
893 return mySectionView->getSelectedSections();
896 QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints()
898 return mySectionView->getSelectedPoints();
902 * According to the widget state, performs the remove action
904 void CurveCreator_Widget::removeSelected()
910 * Checks whether there are some selection to be removed
912 bool CurveCreator_Widget::removeEnabled()
914 bool isEnabled = getActionMode() == ModificationMode;
916 QList<int> aSelSections = mySectionView->getSelectedSections();
917 CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
918 isEnabled = aSelType == CurveCreator_TreeView::ST_SECTIONS &&
919 aSelSections.size() == 1;
925 //=================================================================================
926 // function : GeometryGUI::onGetCoordsByClick()
927 // purpose : Manage mouse press events in Additon mode
928 //=================================================================================
929 void CurveCreator_Widget::onGetCoordsByClick( QMouseEvent* pe )
931 if (pe->button() != Qt::LeftButton)
934 if ( pe->modifiers() != Qt::ControlModifier ) {
935 Handle(AIS_InteractiveContext) ic = getAISContext();
942 if ( pe->modifiers() == Qt::ShiftModifier )
943 ic->ShiftSelect(); // Append selection
945 ic->Select(); // New selection
947 /*TopoDS_Shape aShape;
950 if ( ic->MoreSelected() )
951 aShape = ic->SelectedShape();
953 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
954 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
957 OCCViewer_ViewPort3d* vp = getViewPort();
958 aPnt = CurveCreator_Utils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
960 // set the coordinates into dialog
961 CurveCreator::Coordinates aCoords;
962 aCoords.push_back( aPnt.X() );
963 aCoords.push_back( aPnt.Y() );
964 if ( myCurve->getDimension() == 3 ) {
965 aCoords.push_back( aPnt.Z() );
967 onAddNewPoint(aCoords);
968 // myNewPointEditor->setCoordinates( aCoords );
973 * Manage mouse press events
974 * \param theWindow an owner of the signal
975 * \param theEvent a mouse event
977 void CurveCreator_Widget::onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent )
979 if ( theEvent->button() != Qt::LeftButton )
982 switch( getActionMode() ) {
983 case ModificationMode: {
984 //store initial cursor position for Drag&Drop
985 setDragStarted( true, theEvent->pos() );
989 onGetCoordsByClick( theEvent );
998 * Manage mouse release events in Modification mode
999 * \param theWindow an owner of the signal
1000 * \param theEvent a mouse event
1002 void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent )
1004 if ( getActionMode() != ModificationMode )
1007 if ( myDragStarted ) {
1008 bool isDragged = myDragged;
1009 CurveCreator_ICurve::SectionToPointList aDraggedPoints;
1011 aDraggedPoints = myDragPoints;
1013 setDragStarted( false );
1014 // if the drag of some points has happened, restore the drag selection
1015 if ( aDraggedPoints.size() > 0 )
1018 setSelectedPonts( aDraggedPoints );
1019 END_MEASURE_TIME( "drop" );
1022 else // check whether the segment is clicked an a new point should be added to the segment
1023 insertPointToSelectedSegment( theEvent->pos().x(), theEvent->pos().y() );
1025 // updates the input panel table to show the selected point coordinates
1026 updateLocalPointView();
1030 * Manage mouse move events in Modification mode
1031 * \param theWindow an owner of the signal
1032 * \param theEvent a mouse event
1034 void CurveCreator_Widget::onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent )
1036 if ( getActionMode() != ModificationMode || !myDragStarted )
1039 QPoint aPos = theEvent->pos();
1040 if ( (aPos - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() )
1045 moveSelectedPoints( aPos.x(), aPos.y() );
1046 myDragStartPosition = aPos;
1048 END_MEASURE_TIME( "drag" );
1052 * Set zero viewer by the last view closed in
1053 * \param theManager a viewer manager
1055 void CurveCreator_Widget::onLastViewClosed( SUIT_ViewManager* theManager )
1060 void CurveCreator_Widget::onMousePress( QMouseEvent* theEvent )
1062 onMousePress( 0, theEvent );
1065 void CurveCreator_Widget::onMouseRelease( QMouseEvent* theEvent )
1067 onMouseRelease( 0, theEvent );
1070 void CurveCreator_Widget::onMouseMove( QMouseEvent* theEvent )
1072 onMouseMove( 0, theEvent );
1075 void CurveCreator_Widget::onCellChanged( int theRow, int theColumn )
1077 int aCurrSect = myLocalPointView->getSectionId( theRow );
1078 int aPntIndex = myLocalPointView->getPointId( theRow );
1080 if ( aPntIndex < 0 )
1083 CurveCreator_ICurve::SectionToPointList aSelPoints;
1084 startCurveModification( aSelPoints );
1086 double aX = myLocalPointView->item( theRow, 2 )->data( Qt::UserRole ).toDouble();
1087 double anY = myLocalPointView->item( theRow, 3 )->data( Qt::UserRole ).toDouble();
1088 std::deque<float> aChangedPos;
1089 aChangedPos.push_back( aX );
1090 aChangedPos.push_back( anY );
1091 myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos );
1093 finishCurveModification( aSelPoints );
1097 * Removes a selected section from the curve. Updates undo/redo status
1099 void CurveCreator_Widget::removeSection()
1101 QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
1104 // myCurve->startOperation();
1105 for( int i = 0 ; i < aSelPoints.size() ; i++ ){
1106 if( aCurrSect != aSelPoints[i].first ){
1108 aCurrSect = aSelPoints[i].first;
1110 int aPntIndx = aSelPoints[i].second - aRemoveCnt;
1111 myCurve->removePoint( aCurrSect, aPntIndx );
1112 mySectionView->pointsRemoved( aCurrSect, aPntIndx );
1115 QList<int> aSections = mySectionView->getSelectedSections();
1116 for( int i = 0 ; i < aSections.size() ; i++ ){
1117 int aSectNum = aSections[i] - (i);
1118 myCurve->removeSection( aSectNum );
1119 mySectionView->sectionsRemoved( aSectNum );
1121 // myCurve->finishOperation();
1122 mySectionView->clearSelection();
1127 * Removes a selected points from the curve. Updates undo/redo status
1129 void CurveCreator_Widget::removePoint()
1131 CurveCreator_ICurve::SectionToPointList aPoints;
1132 getSelectedPonts( aPoints );
1133 if ( aPoints.size() == 0 )
1136 CurveCreator_ICurve::SectionToPointList aSelPoints;
1137 startCurveModification( aSelPoints, false );
1139 myCurve->removeSeveralPoints( aPoints );
1140 finishCurveModification( CurveCreator_ICurve::SectionToPointList() );
1143 void CurveCreator_Widget::insertPointToSelectedSegment( const int theX,
1146 Handle(AIS_InteractiveContext) aContext = getAISContext();
1148 OCCViewer_ViewPort3d* aViewPort = getViewPort();
1149 Handle(V3d_View) aView;
1151 aView = aViewPort->getView();
1153 if ( aContext.IsNull() || aView.IsNull() )
1156 gp_Pnt aPoint1, aPoint2;
1157 bool isFoundPoint = CurveCreator_Utils::getNeighbourPoints( aContext, aView, theX, theY,
1158 aPoint, aPoint1, aPoint2 );
1159 if ( !isFoundPoint )
1162 // insert the point to the model curve
1163 CurveCreator_ICurve::SectionToPointList aSelPoints;
1164 startCurveModification( aSelPoints );
1166 CurveCreator::Coordinates aCoords;
1167 aCoords.push_back( aPoint.X() );
1168 aCoords.push_back( aPoint.Y() );
1170 CurveCreator_ICurve::SectionToPointList aPoints1, aPoints2;
1171 findSectionsToPoints( aPoint1.X(), aPoint1.Y(), aPoints1 );
1172 findSectionsToPoints( aPoint2.X(), aPoint2.Y(), aPoints2 );
1173 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints1.begin(),
1174 aLast = aPoints1.end();
1175 int aSectionId = -1;
1176 // there can be a case when a new point is added into two sections
1177 int aPoint1Id = -1, aPoint2Id = -1;
1178 for ( ; anIt != aLast && aSectionId < 0; anIt++ ) {
1179 int aSectionCur = anIt->first;
1180 CurveCreator_ICurve::SectionToPointList::const_iterator anIt2 = aPoints2.begin(),
1181 aLast2 = aPoints2.end();
1182 for ( ; anIt2 != aLast2 && aSectionId < 0; anIt2++ ) {
1183 if ( anIt2->first == aSectionCur ) {
1184 aSectionId = aSectionCur;
1185 aPoint1Id = anIt->second;
1186 aPoint2Id = anIt2->second;
1191 int anInsertPos = -1;
1192 int aLastPoint = myCurve->getNbPoints( aSectionId )-1;
1193 if ( ( aPoint1Id == aLastPoint && aPoint2Id == 0 ) ||
1194 ( aPoint2Id == aLastPoint && aPoint1Id == 0 ) )
1195 anInsertPos = -1; // if the section happens between first and last points
1197 anInsertPos = aPoint1Id < aPoint2Id ? aPoint1Id + 1 : aPoint2Id + 1;
1199 myCurve->addPoints( aCoords, aSectionId, anInsertPos );
1200 mySectionView->pointsAdded( aSectionId, myCurve->getNbPoints( aSectionId ) );
1202 finishCurveModification( aSelPoints );
1207 void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
1208 const int theYPosition )
1210 OCCViewer_ViewPort3d* aViewPort = getViewPort();
1214 CurveCreator_ICurve::SectionToPointList aPoints;
1215 startCurveModification( aPoints, false );
1217 gp_Pnt aStartPnt = CurveCreator_Utils::ConvertClickToPoint( myDragStartPosition.x(),
1218 myDragStartPosition.y(),
1219 aViewPort->getView() );
1220 gp_Pnt anEndPnt = CurveCreator_Utils::ConvertClickToPoint( theXPosition, theYPosition,
1221 aViewPort->getView() );
1222 double aXDelta = aStartPnt.X() - anEndPnt.X();
1223 double anYDelta = aStartPnt.Y() - anEndPnt.Y();
1225 CurveCreator_ICurve::SectionToPointCoordsList aCoordList;
1226 std::deque<float> aChangedPos;
1227 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = myDragPoints.begin(),
1228 aLast = myDragPoints.end();
1229 for ( ; anIt != aLast; anIt++ ) {
1230 int aSectionId = anIt->first;
1231 int aPointId = anIt->second;
1232 aChangedPos = myCurve->getPoint( aSectionId, aPointId );
1233 if ( aChangedPos.size() < 2 )
1235 aChangedPos[0] = aChangedPos[0] - aXDelta;
1236 aChangedPos[1] = aChangedPos[1] - anYDelta;
1238 aCoordList.push_back(
1239 std::make_pair(std::make_pair( aSectionId, aPointId ),
1242 myCurve->setSeveralPoints( aCoordList );
1245 finishCurveModification( myDragPoints );
1248 void CurveCreator_Widget::updateLocalPointView()
1250 if ( myDragStarted )
1252 Handle(AIS_InteractiveContext) aContext = getAISContext();
1253 if ( aContext.IsNull() )
1256 std::list<float> aSelectedList = CurveCreator_Utils::getSelectedPoints( aContext );
1257 int aNbPoints = aSelectedList.size()/3;
1258 bool isRowLimit = aNbPoints > myLocalPointRowLimit;
1259 myLocalPointView->setVisible( !isRowLimit );
1263 std::list<float>::const_iterator anIt = aSelectedList.begin(), aLast = aSelectedList.end();
1265 bool isBlocked = myLocalPointView->blockSignals(true);
1266 myLocalPointView->setRowCount( 0 );
1267 for ( ; anIt != aLast; anIt++ )
1274 myLocalPointView->addLocalPointToTable( aX, anY );
1276 myLocalPointView->blockSignals(isBlocked);
1282 void CurveCreator_Widget::setLocalPointContext( const bool theOpen, const bool isUpdateTable )
1284 CurveCreator_Utils::setLocalPointContext( getAISContext(), theOpen );
1285 if ( !theOpen && isUpdateTable )
1286 updateLocalPointView();
1290 * Set drag operation started. Save the position and a list of dragged points
1291 * \param theState the drag operation state: started/finished
1292 * \param thePoint the start drag position
1294 void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& thePoint )
1297 getSelectedPonts( myDragPoints );
1298 myDragStarted = myDragPoints.size();
1299 myDragStartPosition = thePoint;
1300 if ( myDragStarted ) {
1301 // change a viewer interaction style in order to avoid a select rectangle build
1302 myDragInteractionStyle = changeInteractionStyle( SUIT_ViewModel::KEY_FREE );
1306 if ( myDragStarted )
1307 changeInteractionStyle( myDragInteractionStyle );
1308 myDragStarted = false;
1309 myDragPoints.clear();
1314 void CurveCreator_Widget::getSelectedPonts( CurveCreator_ICurve::SectionToPointList& thePoints )
1317 for ( int i = 0, aNb = myLocalPointView->rowCount(); i < aNb; i++ )
1318 thePoints.push_back( std::make_pair( myLocalPointView->getSectionId( i ),
1319 myLocalPointView->getPointId( i ) ) );
1323 bool CurveCreator_Widget::isIntersectVertexToPoint( const TopoDS_Vertex& theVertex,
1324 const CurveCreator_ICurve::SectionToPoint& theSToPoint )
1326 bool isIntersect = false;
1327 if ( theVertex.IsNull() )
1331 CurveCreator_UtilsICurve::getPoint( myCurve, theSToPoint.first, theSToPoint.second,
1333 gp_Pnt aVertexPoint = BRep_Tool::Pnt( theVertex );
1334 isIntersect = fabs( aVertexPoint.X() - aSPoint.X() ) < LOCAL_SELECTION_TOLERANCE &&
1335 fabs( aVertexPoint.Y() - aSPoint.Y() ) < LOCAL_SELECTION_TOLERANCE;
1341 void CurveCreator_Widget::setSelectedPonts( const CurveCreator_ICurve::SectionToPointList& thePoints )
1343 if ( myDragStarted )
1346 Handle(AIS_InteractiveContext) ic = getAISContext();
1347 if ( ic.IsNull() || !ic->HasOpenedContext() )
1350 AIS_ListOfInteractive aListToSelect;
1351 AIS_ListOfInteractive aDisplayedList;
1352 ic->DisplayedObjects( aDisplayedList );
1353 ic->ClearSelected( Standard_False );
1355 bool isSelectedVertex = false;
1357 //ASL: std::vector<TopoDS_Vertex> aVetexVec;
1358 for ( AIS_ListIteratorOfListOfInteractive it( aDisplayedList ); it.More(); it.Next() )
1360 Handle(AIS_InteractiveObject) anAIS = it.Value();
1361 if ( anAIS.IsNull() )
1363 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast( anAIS );
1364 if ( anAISShape.IsNull() )
1368 /*ASL: const TopoDS_Shape& aShape = anAISShape->Shape();
1369 TopExp_Explorer aExpV( aShape, TopAbs_VERTEX);
1370 for ( ; aExpV.More(); aExpV.Next() )
1372 const TopoDS_Vertex& aVertex = TopoDS::Vertex( aExpV.Current() );
1373 aVetexVec.push_back( aVertex );
1377 //ASL: we convert list of point indices to list of points coordinates
1378 int aSize = thePoints.size();
1379 std::vector<gp_Pnt> aPntsToSelect( aSize );
1381 CurveCreator_ICurve::SectionToPointList::const_iterator
1382 aPIt = thePoints.begin(), aPLast = thePoints.end();
1383 CurveCreator_ICurve::SectionToPoint aSToPoint;
1384 for( int i=0; aPIt != aPLast; aPIt++, i++ )
1386 gp_Pnt aPntToSelect;
1387 CurveCreator_UtilsICurve::getPoint( myCurve, aPIt->first, aPIt->second, aPntToSelect );
1388 aPntsToSelect[i] = aPntToSelect;
1392 //ASL: we switch off automatic highlight to improve performance of selection
1393 ic->SetAutomaticHilight( Standard_False );
1395 Handle_SelectMgr_Selection aSelection = anAISShape->Selection( AIS_Shape::SelectionMode( TopAbs_VERTEX ) );
1396 for( aSelection->Init(); aSelection->More(); aSelection->Next() )
1398 Handle_SelectBasics_SensitiveEntity aSenEntity = aSelection->Sensitive();
1399 Handle_Select3D_SensitivePoint aSenPnt = Handle_Select3D_SensitivePoint::DownCast( aSenEntity );
1401 gp_Pnt anOwnerPnt = aSenPnt->Point();
1402 Handle_SelectMgr_EntityOwner anOwner = Handle_SelectMgr_EntityOwner::DownCast( aSenPnt->OwnerId() );
1405 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(),
1406 aLast = thePoints.end();
1407 bool isFound = false;
1408 for( int i=0; i<aSize; i++ )
1410 bool isIntersect = fabs( aPntsToSelect[i].X() - anOwnerPnt.X() ) < LOCAL_SELECTION_TOLERANCE &&
1411 fabs( aPntsToSelect[i].Y() - anOwnerPnt.Y() ) < LOCAL_SELECTION_TOLERANCE;
1414 ic->AddOrRemoveSelected( anOwner, Standard_False );
1421 /*ASL: std::vector<TopoDS_Vertex>::const_iterator aVecIt = aVetexVec.begin(), aVecLast = aVetexVec.end();
1422 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(),
1423 aLast = thePoints.end();
1424 int aSize = aVetexVec.size();
1425 CurveCreator_ICurve::SectionToPoint aSToPoint;
1426 int anAddedSize = 0;
1427 for( ; anIt != aLast; anIt++ ) {
1430 for ( aVecIt = aVetexVec.begin(); aVecIt != aVecLast; aVecIt++ )
1432 TopoDS_Vertex aVertex = TopoDS::Vertex( *aVecIt );
1433 if ( isIntersectVertexToPoint( aVertex, aSToPoint ) ) {
1434 ic->AddOrRemoveSelected( aVertex, Standard_False );
1435 isSelectedVertex = true;
1441 //ASL: we switch on again automatic highlight (otherwise selection will not be shown)
1442 // and call HilightPicked to draw selected owners
1443 ic->SetAutomaticHilight( Standard_True );
1444 ic->LocalContext()->HilightPicked( Standard_True );
1446 //ic->UpdateCurrentViewer();
1447 if ( !isSelectedVertex )
1448 setObjectsSelected( aListToSelect );
1449 updateLocalPointView();
1453 * Get viewer information before perform the curve modification.
1454 * Take a list of selected cuve points an close local context.
1455 * The context should be closed because the curve presentation is
1456 * redisplayed and if it is not closed, when we close the local context
1457 * later, the presentation shown in the local context is disappeared.
1458 * \param thePoints an output list of curve selected points
1459 * \param theFillPoints a flag whether the selection list should be filled
1461 void CurveCreator_Widget::startCurveModification(
1462 CurveCreator_ICurve::SectionToPointList& thePoints,
1463 const bool theFillPoints )
1465 if ( theFillPoints ) {
1467 getSelectedPonts( thePoints );
1469 setLocalPointContext( false );
1473 * Restore the viewer state after the curve modification is done.
1474 * Open local context and select given points inside it.
1475 * \param thePoints a list of curve selected points
1477 void CurveCreator_Widget::finishCurveModification(
1478 const CurveCreator_ICurve::SectionToPointList& thePoints )
1480 if ( getActionMode() == ModificationMode )
1481 setLocalPointContext( true );
1482 setSelectedPonts( thePoints );
1487 * Returns a point index in the model curve by the point coordinates in the viewer
1488 * \param theX the X coordinate of the point
1489 * \param theY the Y coordinate of the point
1491 int CurveCreator_Widget::findLocalPointIndex( int theSectionId, float theX, float theY )
1493 return CurveCreator_UtilsICurve::findLocalPointIndex( myCurve, theSectionId, theX, theY );
1496 void CurveCreator_Widget::findSectionsToPoints( const double theX, const double theY,
1497 CurveCreator_ICurve::SectionToPointList& thePoints )
1499 return CurveCreator_UtilsICurve::findSectionsToPoints( myCurve, theX, theY, thePoints );
1502 void CurveCreator_Widget::convert( const CurveCreator_ICurve::SectionToPointList& thePoints,
1503 QMap<int, QList<int> >& theConvPoints )
1505 return CurveCreator_UtilsICurve::convert( thePoints, theConvPoints );
1509 * Returns whethe the container has the value
1510 * \param theList a container of values
1511 * \param theValue a value
1513 bool CurveCreator_Widget::contains( const CurveCreator_ICurve::SectionToPointList& theList,
1514 const CurveCreator_ICurve::SectionToPoint& theValue ) const
1516 return CurveCreator_UtilsICurve::contains( theList, theValue );