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_TableView.h"
30 #include <SUIT_Session.h>
31 #include <SUIT_Desktop.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_ViewManager.h>
35 #include <OCCViewer_ViewWindow.h>
36 #include <OCCViewer_ViewManager.h>
37 #include <OCCViewer_ViewPort3d.h>
38 #include "OCCViewer_Utilities.h"
40 #include <BRep_Tool.hxx>
42 #include <TopoDS_Vertex.hxx>
43 #include <TopoDS_Wire.hxx>
44 #include <TopoDS_Edge.hxx>
47 #include <TopExp_Explorer.hxx>
49 #include <GeomAPI_ProjectPointOnCurve.hxx>
51 #include <AIS_ListOfInteractive.hxx>
52 #include <AIS_ListIteratorOfListOfInteractive.hxx>
53 #include <AIS_Shape.hxx>
54 #include <AIS_Point.hxx>
55 #include <AIS_Line.hxx>
56 #include <Geom_Point.hxx>
57 #include <Geom_BSplineCurve.hxx>
58 #include <Geom_Line.hxx>
59 #include <StdSelect_BRepOwner.hxx>
61 #include <QHBoxLayout>
62 #include <QVBoxLayout>
66 #include <QToolButton>
70 #include <QMouseEvent>
71 #include <QApplication>
72 #include <QTableWidget>
74 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
75 const int SECTION_NAME_COLUMN_WIDTH = 75;
76 const int POINT_INDEX_COLUMN_WIDTH = 40;
78 const int SCENE_PIXEL_TOLERANCE = 10;
80 CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
81 CurveCreator_ICurve *theCurve,
83 : QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0),
84 myDragStarted( false ), myDragInteractionStyle( SUIT_ViewModel::STANDARD ),
87 myNewSectionEditor = new CurveCreator_NewSectionDlg( this );
88 myNewSectionEditor->hide();
89 connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()) );
90 connect( myNewSectionEditor, SIGNAL(modifySection()), this, SLOT(onModifySection()) );
91 connect( myNewSectionEditor, SIGNAL(cancelSection()), this, SLOT(onCancelSection()) );
93 QGroupBox* aSectionGroup = new QGroupBox(tr("Sections"),this);
95 mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup);
96 connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) );
97 connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) );
98 connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) );
100 myLocalPointView = new QTableWidget();
101 myLocalPointView->setItemDelegate( new CurveCreator_TableItemDelegate( myLocalPointView ) );
102 myLocalPointView->setVisible( false );
103 myLocalPointView->setColumnCount( 4 );
104 myLocalPointView->setColumnWidth( 0, SECTION_NAME_COLUMN_WIDTH );
105 myLocalPointView->setColumnWidth( 1, POINT_INDEX_COLUMN_WIDTH );
107 //aLabels << tr( "SECTION_LABEL" ) << tr( "IDENTIFIER_LABEL" ) << tr( "X_POSITION_LBL" ) << tr( "Y_POSITION_LBL" );
108 aLabels << tr( "Section" ) << "Index" << tr( "X" ) << tr( "Y" );
109 myLocalPointView->setHorizontalHeaderLabels( aLabels );
110 connect( myLocalPointView, SIGNAL( cellChanged( int, int ) ),
111 this, SLOT( onCellChanged( int, int ) ) );
113 QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup);
114 // QToolButton* anUndoBtn = new QToolButton(aTB);
116 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
117 QPixmap anUndoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_UNDO")));
118 QPixmap aRedoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_REDO")));
119 QPixmap aNewSectionPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_SECTION")));
120 QPixmap aNewPointPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_POINT")));
121 QPixmap anEditPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
122 QPixmap aDetectPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
123 QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
124 QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
125 QPixmap aRemovePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_DELETE")));
126 QPixmap aJoinPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_JOIN")));
127 QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP")));
128 QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN")));
130 QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"),
131 QKeySequence(Qt::ControlModifier|Qt::Key_Z) );
132 connect(anAct, SIGNAL(triggered()), this, SLOT(onUndo()) );
133 aTB->addAction(anAct);
135 anAct = createAction( REDO_ID, tr("REDO"), aRedoPixmap, tr("REDO_TLT"),
136 QKeySequence(Qt::ControlModifier|Qt::Key_Y) );
137 connect(anAct, SIGNAL(triggered()), this, SLOT(onRedo()) );
138 aTB->addAction(anAct);
142 anAct = createAction( NEW_SECTION_ID, tr("NEW_SECTION"), aNewSectionPixmap, tr("NEW_SECTION_TLT"),
143 QKeySequence(Qt::ControlModifier|Qt::Key_N) );
144 connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) );
145 aTB->addAction(anAct);
148 anAct = createAction( ADDITION_MODE_ID, tr("ADDITION_MODE"), aNewPointPixmap, tr("ADDITION_MODE_TLT"),
150 anAct->setCheckable(true);
151 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onAdditionMode(bool)) );
152 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
153 aTB->addAction(anAct);
155 anAct = createAction( MODIFICATION_MODE_ID, tr("MODIFICATION_MODE"), anEditPointsPixmap, tr("MODIFICATION_MODE_TLT"),
157 anAct->setCheckable(true);
158 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onModificationMode(bool)) );
159 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
160 aTB->addAction(anAct);
162 anAct = createAction( DETECTION_MODE_ID, tr("DETECTION_MODE"), aDetectPointsPixmap, tr("DETECTION_MODE_TLT"),
164 anAct->setCheckable(true);
165 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onDetectionMode(bool)) );
166 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
167 aTB->addAction(anAct);
169 anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), QPixmap(), tr("CLOSE_SECTIONS_TLT"),
170 QKeySequence(Qt::ControlModifier|Qt::Key_W) );
171 connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) );
173 anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), QPixmap(),
174 tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) );
175 connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) );
177 anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"),
178 aPolylinePixmap, tr("SET_POLYLINE_TLT"),
179 QKeySequence(Qt::ControlModifier|Qt::Key_E) );
180 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) );
182 anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), aSplinePixmap,
183 tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) );
184 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) );
186 anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemovePixmap, tr("REMOVE_TLT"),
187 QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) );
188 connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) );
189 aTB->addAction(anAct);
191 //aTB->addSeparator();
193 //anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"),
194 // QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) );
195 //connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) );
196 //aTB->addAction(anAct);
198 anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"),
199 QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) );
200 connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) );
203 //anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), QPixmap(), tr("JOIN_ALL_TLT"),
204 // QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) );
205 //connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) );
207 QVBoxLayout* aSectLayout = new QVBoxLayout();
208 aSectLayout->setMargin( 5 );
209 aSectLayout->setSpacing( 5 );
210 aSectLayout->addWidget(aTB);
211 aSectLayout->addWidget(mySectionView);
212 aSectLayout->addWidget( myLocalPointView );
213 aSectionGroup->setLayout(aSectLayout);
214 QVBoxLayout* aLay = new QVBoxLayout();
215 aLay->setMargin( 0 );
216 aLay->setSpacing( 5 );
217 // aLay->addLayout(aNameLayout);
218 aLay->addWidget(aSectionGroup);
220 onSelectionChanged();
226 void CurveCreator_Widget::setOCCViewer( OCCViewer_Viewer* theViewer )
228 if ( myOCCViewer == theViewer )
232 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
233 ( myOCCViewer->getViewManager() );
234 disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
235 this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
236 disconnect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
237 this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
238 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
239 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
240 disconnect( aViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
241 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
242 // restore normal mode in the viewer
243 OCCViewer_Utilities::setViewer2DMode( myOCCViewer, OCCViewer_ViewWindow::No2dMode );
244 // all local contexts should be closed if the viewer is not more used
245 setLocalPointContext( false, true );
248 myOCCViewer = theViewer;
250 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
251 ( myOCCViewer->getViewManager() );
252 connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
253 this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
254 connect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
255 this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
256 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
257 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
258 connect( aViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
259 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
260 OCCViewer_Utilities::setViewer2DMode( myOCCViewer, OCCViewer_ViewWindow::XYPlane );
265 * Returns current OCC viewer
267 OCCViewer_Viewer* CurveCreator_Widget::getOCCViewer()
273 * Returns OCC viewer context
275 Handle(AIS_InteractiveContext) CurveCreator_Widget::getAISContext()
277 Handle(AIS_InteractiveContext) aContext;
278 OCCViewer_Viewer* aViewer = getOCCViewer();
280 aContext = aViewer->getAISContext();
286 * Returns OCC viewer view port
288 OCCViewer_ViewPort3d* CurveCreator_Widget::getViewPort()
290 OCCViewer_ViewPort3d* aViewPort = 0;
291 OCCViewer_Viewer* aViewer = getOCCViewer();
293 aViewPort = ((OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView())->getViewPort();
299 * Set interaction style in the OCC viewer
300 * \param theStyle a new style
301 * \return the previous style
303 int CurveCreator_Widget::changeInteractionStyle( int theStyle )
305 OCCViewer_Viewer* aViewer = getOCCViewer();
309 int aPrevStyle = aViewer->interactionStyle();
310 aViewer->setInteractionStyle( theStyle );
316 * Set interaction style in the OCC viewer
317 * \param theStyle a new style
318 * \return the previous style
320 void CurveCreator_Widget::setObjectsSelected(const AIS_ListOfInteractive& theList)
322 OCCViewer_Viewer* aViewer = getOCCViewer();
324 aViewer->setObjectsSelected(theList);
327 //=======================================================================
329 // purpose: reset the widget viewer, close local context, clear selection
330 //=======================================================================
331 void CurveCreator_Widget::reset()
335 //=======================================================================
336 // function: getUniqSectionName
337 // purpose: return unique section name
338 //=======================================================================
339 std::string CurveCreator_Widget::getUniqSectionName( CurveCreator_ICurve* theCurve ) const
341 for( int i = 0 ; i < 1000000 ; i++ ){
343 sprintf( aBuffer, "Section_%d", i+1 );
344 std::string aName(aBuffer);
346 for( j = 0 ; j < theCurve->getNbSections() ; j++ ){
347 if( theCurve->getSectionName(j) == aName )
350 if( j == theCurve->getNbSections() )
356 void CurveCreator_Widget::setCurve( CurveCreator_ICurve* theCurve )
359 mySectionView->setCurve(myCurve);
360 onSelectionChanged();
364 void CurveCreator_Widget::onSelectionChanged()
366 QList<ActionId> anEnabledAct;
368 anEnabledAct << NEW_SECTION_ID << MODIFICATION_MODE_ID;
369 if ( removeEnabled() )
370 anEnabledAct << REMOVE_ID;
371 QList<int> aSelSections = mySectionView->getSelectedSections();
372 QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints();
373 CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
375 case CurveCreator_TreeView::ST_NOSEL:{
378 case CurveCreator_TreeView::ST_SECTIONS:{
379 /*if( aSelSections[0] > 0 ){
380 anEnabledAct << UP_ID;
382 if( aSelSections.size() == 1 ){
383 anEnabledAct << ADDITION_MODE_ID << DETECTION_MODE_ID;
385 switch ( getActionMode() ) {
389 QList<int> aSelSection = mySectionView->getSelectedSections();
390 if( aSelSection.size() > 0 ){
391 mySection = aSelSection[0];
392 myPointNum = myCurve->getNbPoints(mySection);
396 case ModificationMode: {
397 anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID;
398 int aSectCnt = myCurve->getNbSections();
400 anEnabledAct << CLEAR_ALL_ID;
403 // anEnabledAct << JOIN_ALL_ID;
404 //if( aSelSections.size() > 1 ){
405 // anEnabledAct << JOIN_ID;
409 case DetectionMode: {
416 /*if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){
417 anEnabledAct << DOWN_ID;
421 /*case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{
422 if( aSelPoints[0].second > 0 ){
423 anEnabledAct << UP_ID;
425 int aLastIndex = aSelPoints.size()-1;
426 int aSect = aSelPoints[0].first;
427 if( aSelPoints[aLastIndex].second < (myCurve->getNbPoints(aSect) - 1)){
428 anEnabledAct << DOWN_ID;
430 if( aSelPoints.size() == 1){
431 anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID;
438 /*int aSelObjsCnt = aSelPoints.size() + aSelSections.size();
439 if( aSelObjsCnt > 0 ){
440 anEnabledAct << REMOVE_ID;
442 if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){
443 anEnabledAct << REMOVE_ALL_ID;
446 //if( myCurve->getNbSections() > 1 ){
447 // anEnabledAct << JOIN_ALL_ID;
450 QList<ActionId> anIds = myActionMap.keys();
451 for( int i = 0 ; i < anIds.size() ; i++ ){
452 if( myActionMap.contains(anIds[i]) ){
453 if( anEnabledAct.contains(anIds[i]) ){
454 myActionMap[anIds[i]]->setEnabled(true);
457 myActionMap[anIds[i]]->setEnabled(false);
462 emit selectionChanged();
465 void CurveCreator_Widget::onAdditionMode(bool checked)
470 Handle(AIS_InteractiveContext) aContext = getAISContext();
471 if( !myCurve || aContext.IsNull() )
476 QList<int> aSelSection = mySectionView->getSelectedSections();
477 if( aSelSection.size() > 0 ){
478 mySection = aSelSection[0];
481 QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
482 if( aSelPoints.size() > 0 ){
483 mySection = aSelPoints[0].first;
484 myPointNum = aSelPoints[0].second + 1;
487 // emit subOperationStarted( myNewPointEditor );
490 void CurveCreator_Widget::onModificationMode(bool checked)
492 myLocalPointView->setVisible( checked );
495 void CurveCreator_Widget::onDetectionMode(bool checked)
499 void CurveCreator_Widget::onModeChanged(bool checked)
501 ActionMode aMode = NoneMode;
503 QAction* anAction = (QAction*)sender();
504 switch(myActionMap.key(anAction)) {
505 case ADDITION_MODE_ID:
506 aMode = AdditionMode;
507 if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
508 myActionMap[MODIFICATION_MODE_ID]->trigger();
509 else if (myActionMap[DETECTION_MODE_ID]->isChecked())
510 myActionMap[DETECTION_MODE_ID]->trigger();
512 case MODIFICATION_MODE_ID:
513 aMode = ModificationMode;
514 if (myActionMap[ADDITION_MODE_ID]->isChecked())
515 myActionMap[ADDITION_MODE_ID]->trigger();
516 else if (myActionMap[DETECTION_MODE_ID]->isChecked())
517 myActionMap[DETECTION_MODE_ID]->trigger();
519 case DETECTION_MODE_ID:
520 aMode = DetectionMode;
521 if (myActionMap[ADDITION_MODE_ID]->isChecked())
522 myActionMap[ADDITION_MODE_ID]->trigger();
523 else if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
524 myActionMap[MODIFICATION_MODE_ID]->trigger();
528 onSelectionChanged();
529 setLocalPointContext( aMode == ModificationMode, true );
532 void CurveCreator_Widget::onAddNewPoint(const CurveCreator::Coordinates& theCoords)
536 //myCurve->addPoints(theCoords, mySection, myPointNum );
537 //mySectionView->pointsAdded( mySection, myPointNum );
539 QList<int> aSections = mySectionView->getSelectedSections();
540 if( aSections.size() == 0 ){
543 int aSection = aSections[0];
544 myCurve->addPoints(theCoords, aSection); // add to the end of section
545 mySectionView->pointsAdded( aSection, myCurve->getNbPoints( aSection ) );
546 onSelectionChanged();
550 void CurveCreator_Widget::onNewSection()
554 myNewSectionEditor->clear();
555 myNewSectionEditor->setEditMode(false);
556 QString aSectName = QString( getUniqSectionName(myCurve).c_str() );
557 myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline );
558 emit subOperationStarted( myNewSectionEditor );
561 void CurveCreator_Widget::onAddNewSection()
565 myCurve->addSection( myNewSectionEditor->getName().toStdString(), myNewSectionEditor->getSectionType(),
566 myNewSectionEditor->isClosed() );
567 mySectionView->sectionAdded( -1 ); // add a new section to the end of list
568 QString aNewName = QString(getUniqSectionName(myCurve).c_str());
569 myNewSectionEditor->setSectionName(aNewName);
570 onSelectionChanged();
575 void CurveCreator_Widget::onCancelSection()
577 emit subOperationFinished( myNewSectionEditor );
580 QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
581 const QString& theToolTip, const QKeySequence& theShortcut )
583 QAction* anAct = new QAction(theName,this);
584 if( !theImage.isNull() ){
585 anAct->setIcon(theImage);
587 anAct->setShortcut(theShortcut);
588 anAct->setToolTip(theToolTip);
589 myActionMap[theId] = anAct;
593 QAction* CurveCreator_Widget::getAction(ActionId theId)
595 if( myActionMap.contains(theId) )
596 return myActionMap[theId];
600 CurveCreator_Widget::ActionMode CurveCreator_Widget::getActionMode() const
602 ActionMode aMode = NoneMode;
604 if ( myActionMap[ADDITION_MODE_ID]->isChecked() )
605 aMode = AdditionMode;
606 else if ( myActionMap[MODIFICATION_MODE_ID]->isChecked() )
607 aMode = ModificationMode;
608 else if ( myActionMap[DETECTION_MODE_ID]->isChecked() )
609 aMode = DetectionMode;
614 void CurveCreator_Widget::onEditSection( int theSection )
618 mySection = theSection;
619 QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
620 bool isClosed = myCurve->isClosed(theSection);
621 CurveCreator::SectionType aType = myCurve->getSectionType(theSection);
622 myNewSectionEditor->setEditMode(true);
623 myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType );
625 emit subOperationStarted( myNewSectionEditor );
628 void CurveCreator_Widget::onModifySection()
632 QString aName = myNewSectionEditor->getName();
633 bool isClosed = myNewSectionEditor->isClosed();
634 CurveCreator::SectionType aSectType = myNewSectionEditor->getSectionType();
635 // myCurve->startOperation();
636 if( myCurve->getSectionName(mySection) != aName.toStdString() )
637 myCurve->setSectionName( mySection , aName.toStdString() );
639 if( myCurve->getSectionType(mySection) != aSectType )
640 myCurve->setSectionType( mySection, aSectType );
642 if( myCurve->isClosed(mySection) != isClosed )
643 myCurve->setClosed( mySection, isClosed );
644 // myCurve->finishOperation();
645 mySectionView->sectionChanged(mySection);
650 /*void CurveCreator_Widget::onEditPoint( int theSection, int thePoint )
652 if( !myNewPointEditor || !myEdit )
654 mySection = theSection;
655 myPointNum = thePoint;
656 QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
657 myNewPointEditor->setEditMode(true);
658 myNewPointEditor->setSectionName(aSectName);
659 myNewPointEditor->setDimension( myCurve->getDimension() );
660 CurveCreator::Coordinates aCoords = myCurve->getCoordinates(theSection,thePoint);
661 myNewPointEditor->setCoordinates(aCoords);
662 emit subOperationStarted( myNewPointEditor );
665 void CurveCreator_Widget::onModifyPoint()
669 CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates();
670 myEdit->setCoordinates( aCoords, mySection, myPointNum );
671 mySectionView->pointDataChanged( mySection, myPointNum );
676 void CurveCreator_Widget::onJoin()
680 QList<int> aSections = mySectionView->getSelectedSections();
681 if( aSections.size() == 0 ){
684 int aMainSect = aSections[0];
685 int aMainSectSize = myCurve->getNbPoints(aMainSect);
686 // myCurve->startOperation();
687 for( int i = 1 ; i < aSections.size() ; i++ ){
688 int aSectNum = aSections[i] - (i-1);
689 myCurve->join( aMainSect, aSectNum );
690 mySectionView->sectionsRemoved( aSectNum );
692 // myCurve->finishOperation();
693 int aNewSectSize = myCurve->getNbPoints(aMainSect);
694 if( aNewSectSize != aMainSectSize )
695 mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );
699 void CurveCreator_Widget::onRemove()
704 switch( getActionMode() ) {
708 case ModificationMode:
716 void CurveCreator_Widget::onClearAll()
721 mySectionView->reset();
722 onSelectionChanged();
726 void CurveCreator_Widget::onJoinAll()
731 mySectionView->reset();
732 onSelectionChanged();
736 void CurveCreator_Widget::onUndoSettings()
741 void CurveCreator_Widget::onSetSpline()
745 QList<int> aSelSections = mySectionView->getSelectedSections();
746 // myCurve->startOperation();
747 for( int i = 0 ; i < aSelSections.size() ; i++ ){
748 myCurve->setSectionType(aSelSections[i], CurveCreator::Spline );
749 mySectionView->sectionChanged(aSelSections[i]);
751 // myCurve->finishOperation();
755 void CurveCreator_Widget::onSetPolyline()
759 // myCurve->startOperation();
760 QList<int> aSelSections = mySectionView->getSelectedSections();
761 for( int i = 0 ; i < aSelSections.size() ; i++ ){
762 myCurve->setSectionType( aSelSections[i], CurveCreator::Polyline );
763 mySectionView->sectionChanged( aSelSections[i] );
765 // myCurve->finishOperation();
769 void CurveCreator_Widget::onCloseSections()
773 // myCurve->startOperation();
774 QList<int> aSelSections = mySectionView->getSelectedSections();
775 for( int i = 0 ; i < aSelSections.size() ; i++ ){
776 myCurve->setClosed(aSelSections[i], true);
777 mySectionView->sectionChanged(aSelSections[i]);
779 // myCurve->finishOperation();
783 void CurveCreator_Widget::onUncloseSections()
787 // myCurve->startOperation();
788 QList<int> aSelSections = mySectionView->getSelectedSections();
789 for( int i = 0 ; i < aSelSections.size() ; i++ ){
790 myCurve->setClosed(aSelSections[i], false);
791 mySectionView->sectionChanged(aSelSections[i]);
793 // myCurve->finishOperation();
797 void CurveCreator_Widget::onUndo()
802 CurveCreator_Widget::SectionToPointList aPoints;
803 startCurveModification( aPoints, false );
805 finishCurveModification();
806 mySectionView->reset();
809 void CurveCreator_Widget::onRedo()
813 CurveCreator_Widget::SectionToPointList aPoints;
814 startCurveModification( aPoints, false );
816 finishCurveModification();
817 mySectionView->reset();
820 void CurveCreator_Widget::updateUndoRedo()
824 QAction* anAct = myActionMap[UNDO_ID];
826 if( myCurve->getNbUndo() != 0 ){
827 anAct->setEnabled(true);
830 anAct->setDisabled(true);
833 anAct = myActionMap[REDO_ID];
835 if( myCurve->getNbRedo() != 0 ){
836 anAct->setEnabled(true);
839 anAct->setDisabled(true);
844 void CurveCreator_Widget::onContextMenu( QPoint thePoint )
846 QList<ActionId> aContextActions;
847 aContextActions << CLEAR_ALL_ID << JOIN_ALL_ID << SEPARATOR_ID <<
848 CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID <<
849 SET_SECTIONS_SPLINE_ID;
850 QPoint aGlPoint = mySectionView->mapToGlobal(thePoint);
852 QList<ActionId> aResAct;
853 for( int i = 0 ; i < aContextActions.size() ; i++ ){
854 if( aContextActions[i] != SEPARATOR_ID ){
855 if( myActionMap.contains(aContextActions[i]) ){
856 QAction* anAct = myActionMap[aContextActions[i]];
857 if( anAct->isEnabled() ){
858 aResAct << aContextActions[i];
864 aResAct << SEPARATOR_ID;
870 QMenu* aMenu = new QMenu(this);
871 for( int i = 0 ; i < aResAct.size() ; i++ ){
872 if( aResAct[i] == SEPARATOR_ID ){
873 aMenu->addSeparator();
876 QAction* anAct = myActionMap[aResAct[i]];
877 aMenu->insertAction(NULL, anAct);
880 aMenu->exec(aGlPoint);
883 QList<int> CurveCreator_Widget::getSelectedSections()
885 return mySectionView->getSelectedSections();
888 QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints()
890 return mySectionView->getSelectedPoints();
894 * According to the widget state, performs the remove action
896 void CurveCreator_Widget::removeSelected()
902 * Checks whether there are some selection to be removed
904 bool CurveCreator_Widget::removeEnabled()
906 bool isEnabled = getActionMode() == ModificationMode;
908 QList<int> aSelSections = mySectionView->getSelectedSections();
909 CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
910 isEnabled = aSelType == CurveCreator_TreeView::ST_SECTIONS &&
911 aSelSections.size() == 1;
917 //=================================================================================
918 // function : GeometryGUI::onGetCoordsByClick()
919 // purpose : Manage mouse press events in Additon mode
920 //=================================================================================
921 void CurveCreator_Widget::onGetCoordsByClick( QMouseEvent* pe )
923 if (pe->button() != Qt::LeftButton)
926 if ( pe->modifiers() != Qt::ControlModifier ) {
927 Handle(AIS_InteractiveContext) ic = getAISContext();
934 if ( pe->modifiers() == Qt::ShiftModifier )
935 ic->ShiftSelect(); // Append selection
937 ic->Select(); // New selection
939 /*TopoDS_Shape aShape;
942 if ( ic->MoreSelected() )
943 aShape = ic->SelectedShape();
945 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
946 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
949 OCCViewer_ViewPort3d* vp = getViewPort();
950 aPnt = CurveCreator_Utils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
952 // set the coordinates into dialog
953 CurveCreator::Coordinates aCoords;
954 aCoords.push_back( aPnt.X() );
955 aCoords.push_back( aPnt.Y() );
956 if ( myCurve->getDimension() == 3 ) {
957 aCoords.push_back( aPnt.Z() );
959 onAddNewPoint(aCoords);
960 // myNewPointEditor->setCoordinates( aCoords );
965 * Manage mouse press events
966 * \param theWindow an owner of the signal
967 * \param theEvent a mouse event
969 void CurveCreator_Widget::onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent )
971 if ( theEvent->button() != Qt::LeftButton )
974 switch( getActionMode() ) {
975 case ModificationMode: {
976 //store initial cursor position for Drag&Drop
977 setDragStarted( true, theEvent->pos() );
981 onGetCoordsByClick( theEvent );
990 * Manage mouse release events in Modification mode
991 * \param theWindow an owner of the signal
992 * \param theEvent a mouse event
994 void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent )
996 if ( getActionMode() != ModificationMode )
999 if ( myDragStarted ) {
1000 bool isDragged = myDragged;
1001 CurveCreator_Widget::SectionToPointList aDraggedPoints;
1003 aDraggedPoints = myDragPoints;
1005 setDragStarted( false );
1006 // if the drag of some points has happened, restore the drag selection
1007 if ( aDraggedPoints.size() > 0 )
1008 setSelectedPonts( aDraggedPoints );
1010 else // check whether the segment is clicked an a new point should be added to the segment
1011 insertPointToSelectedSegment( theEvent->pos().x(), theEvent->pos().y() );
1013 // updates the input panel table to show the selected point coordinates
1014 updateLocalPointView();
1018 * Manage mouse move events in Modification mode
1019 * \param theWindow an owner of the signal
1020 * \param theEvent a mouse event
1022 void CurveCreator_Widget::onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent )
1024 if ( getActionMode() != ModificationMode || !myDragStarted )
1027 QPoint aPos = theEvent->pos();
1028 if ( (aPos - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() )
1031 moveSelectedPoints( aPos.x(), aPos.y() );
1032 myDragStartPosition = aPos;
1036 * Set zero viewer by the last view closed in
1037 * \param theManager a viewer manager
1039 void CurveCreator_Widget::onLastViewClosed( SUIT_ViewManager* theManager )
1044 void CurveCreator_Widget::onMousePress( QMouseEvent* theEvent )
1046 onMousePress( 0, theEvent );
1049 void CurveCreator_Widget::onMouseRelease( QMouseEvent* theEvent )
1051 onMouseRelease( 0, theEvent );
1054 void CurveCreator_Widget::onMouseMove( QMouseEvent* theEvent )
1056 onMouseMove( 0, theEvent );
1059 void CurveCreator_Widget::onCellChanged( int theRow, int theColumn )
1061 int aCurrSect = getSectionId( theRow );
1062 int aPntIndex = getPointId( theRow );
1064 if ( aPntIndex < 0 )
1067 SectionToPointList aSelPoints;
1068 startCurveModification( aSelPoints );
1070 double aX = myLocalPointView->item( theRow, 2 )->data( Qt::UserRole ).toDouble();
1071 double anY = myLocalPointView->item( theRow, 3 )->data( Qt::UserRole ).toDouble();
1072 std::deque<float> aChangedPos;
1073 aChangedPos.push_back( aX );
1074 aChangedPos.push_back( anY );
1075 myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos );
1077 finishCurveModification( aSelPoints );
1081 * Removes a selected section from the curve. Updates undo/redo status
1083 void CurveCreator_Widget::removeSection()
1085 QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
1088 // myCurve->startOperation();
1089 for( int i = 0 ; i < aSelPoints.size() ; i++ ){
1090 if( aCurrSect != aSelPoints[i].first ){
1092 aCurrSect = aSelPoints[i].first;
1094 int aPntIndx = aSelPoints[i].second - aRemoveCnt;
1095 myCurve->removePoint( aCurrSect, aPntIndx );
1096 mySectionView->pointsRemoved( aCurrSect, aPntIndx );
1099 QList<int> aSections = mySectionView->getSelectedSections();
1100 for( int i = 0 ; i < aSections.size() ; i++ ){
1101 int aSectNum = aSections[i] - (i);
1102 myCurve->removeSection( aSectNum );
1103 mySectionView->sectionsRemoved( aSectNum );
1105 // myCurve->finishOperation();
1106 mySectionView->clearSelection();
1111 * Removes a selected points from the curve. Updates undo/redo status
1113 void CurveCreator_Widget::removePoint()
1115 SectionToPointList aPoints;
1116 getSelectedPonts( aPoints );
1117 if ( aPoints.size() == 0 )
1120 SectionToPointList aSelPoints;
1121 startCurveModification( aSelPoints, false );
1123 myCurve->removeSeveralPoints( aPoints );
1124 finishCurveModification( SectionToPointList() );
1127 void CurveCreator_Widget::insertPointToSelectedSegment( const int theX,
1130 Handle(AIS_InteractiveContext) aContext = getAISContext();
1132 OCCViewer_ViewPort3d* aViewPort = getViewPort();
1133 Handle(V3d_View) aView;
1135 aView = aViewPort->getView();
1137 if ( aContext.IsNull() || aView.IsNull() )
1140 gp_Pnt aPoint1, aPoint2;
1141 bool isFoundPoint = CurveCreator_Utils::getNeighbourPoints( aContext, aView, theX, theY,
1142 aPoint, aPoint1, aPoint2 );
1143 if ( !isFoundPoint )
1146 // insert the point to the model curve
1147 SectionToPointList aSelPoints;
1148 startCurveModification( aSelPoints );
1150 CurveCreator::Coordinates aCoords;
1151 aCoords.push_back( aPoint.X() );
1152 aCoords.push_back( aPoint.Y() );
1154 SectionToPointList aPoints1, aPoints2;
1155 findSectionsToPoints( aPoint1.X(), aPoint1.Y(), aPoints1 );
1156 findSectionsToPoints( aPoint2.X(), aPoint2.Y(), aPoints2 );
1157 SectionToPointList::const_iterator anIt = aPoints1.begin(), aLast = aPoints1.end();
1158 int aSectionId = -1;
1159 // there can be a case when a new point is added into two sections
1160 int aPoint1Id = -1, aPoint2Id = -1;
1161 for ( ; anIt != aLast && aSectionId < 0; anIt++ ) {
1162 int aSectionCur = anIt->first;
1163 SectionToPointList::const_iterator anIt2 = aPoints2.begin(), aLast2 = aPoints2.end();
1164 for ( ; anIt2 != aLast2 && aSectionId < 0; anIt2++ ) {
1165 if ( anIt2->first == aSectionCur ) {
1166 aSectionId = aSectionCur;
1167 aPoint1Id = anIt->second;
1168 aPoint2Id = anIt2->second;
1173 int anInsertPos = -1;
1174 int aLastPoint = myCurve->getNbPoints( aSectionId )-1;
1175 if ( ( aPoint1Id == aLastPoint && aPoint2Id == 0 ) ||
1176 ( aPoint2Id == aLastPoint && aPoint1Id == 0 ) )
1177 anInsertPos = -1; // if the section happens between first and last points
1179 anInsertPos = aPoint1Id < aPoint2Id ? aPoint1Id + 1 : aPoint2Id + 1;
1181 myCurve->addPoints( aCoords, aSectionId, anInsertPos );
1182 mySectionView->pointsAdded( aSectionId, myCurve->getNbPoints( aSectionId ) );
1184 finishCurveModification( aSelPoints );
1189 void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
1190 const int theYPosition )
1192 OCCViewer_ViewPort3d* aViewPort = getViewPort();
1196 SectionToPointList aPoints;
1197 startCurveModification( aPoints, false );
1199 gp_Pnt aStartPnt = CurveCreator_Utils::ConvertClickToPoint( myDragStartPosition.x(),
1200 myDragStartPosition.y(),
1201 aViewPort->getView() );
1202 gp_Pnt anEndPnt = CurveCreator_Utils::ConvertClickToPoint( theXPosition, theYPosition,
1203 aViewPort->getView() );
1204 double aXDelta = aStartPnt.X() - anEndPnt.X();
1205 double anYDelta = aStartPnt.Y() - anEndPnt.Y();
1207 CurveCreator_ICurve::SectionToPointCoordsList aCoordList;
1208 std::deque<float> aChangedPos;
1209 SectionToPointList::const_iterator anIt = myDragPoints.begin(), aLast = myDragPoints.end();
1210 for ( ; anIt != aLast; anIt++ ) {
1211 int aSectionId = anIt->first;
1212 int aPointId = anIt->second;
1213 aChangedPos = myCurve->getPoint( aSectionId, aPointId );
1214 if ( aChangedPos.size() < 2 )
1216 aChangedPos[0] = aChangedPos[0] - aXDelta;
1217 aChangedPos[1] = aChangedPos[1] - anYDelta;
1219 aCoordList.push_back(
1220 std::make_pair(std::make_pair( aSectionId, aPointId ),
1223 myCurve->setSeveralPoints( aCoordList );
1226 finishCurveModification( myDragPoints );
1229 void CurveCreator_Widget::updateLocalPointView()
1231 if ( myDragStarted )
1233 Handle(AIS_InteractiveContext) aContext = getAISContext();
1234 if ( aContext.IsNull() )
1237 std::list<float> aSelectedList = CurveCreator_Utils::getSelectedPoints( aContext );
1239 std::list<float>::const_iterator anIt = aSelectedList.begin(), aLast = aSelectedList.end();
1241 bool isBlocked = myLocalPointView->blockSignals(true);
1242 myLocalPointView->setRowCount( 0 );
1243 for ( ; anIt != aLast; anIt++ )
1250 addLocalPointToTable( aX, anY );
1252 myLocalPointView->blockSignals(isBlocked);
1258 void CurveCreator_Widget::setLocalPointContext( const bool theOpen, const bool isUpdateTable )
1260 CurveCreator_Utils::setLocalPointContext( getAISContext(), theOpen );
1261 if ( !theOpen && isUpdateTable )
1262 updateLocalPointView();
1265 void CurveCreator_Widget::addLocalPointToTable( const double theX, const double theY )
1267 SectionToPointList aPoints;
1268 findSectionsToPoints( theX, theY, aPoints );
1270 SectionToPointList aSkipList;
1271 // table could not contain two equal value rows
1272 int aRowId = myLocalPointView->rowCount();
1273 double aCurrentX, aCurrentY;
1274 int aSectionId, aPointId;
1275 SectionToPoint aPoint;
1276 for ( int i = 0; i < aRowId; i++ ) {
1277 aCurrentX = myLocalPointView->item( i, 2 )->data( Qt::UserRole ).toDouble();
1278 aCurrentY = myLocalPointView->item( i, 3 )->data( Qt::UserRole ).toDouble();
1279 if ( fabs( aCurrentX - theX ) < LOCAL_SELECTION_TOLERANCE &&
1280 fabs( aCurrentY - theY ) < LOCAL_SELECTION_TOLERANCE ) {
1281 aPoint = std::make_pair<int, int>( getSectionId( i ), getPointId( i ) );
1282 if ( !contains( aSkipList, aPoint ) )
1283 aSkipList.push_back( aPoint );
1286 if ( aSkipList.size() == aPoints.size() )
1289 QTableWidgetItem* anItem;
1290 SectionToPointList::const_iterator anIt = aPoints.begin(), aLast = aPoints.end();
1291 for ( ; anIt != aLast; anIt++ ) {
1293 if ( contains( aSkipList, aPoint ) )
1296 myLocalPointView->setRowCount( aRowId+1 );
1297 aSectionId = aPoint.first;
1298 aPointId = aPoint.second;
1300 anItem = new QTableWidgetItem( myCurve->getSectionName( aSectionId ).c_str() );
1301 anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled );
1302 anItem->setData( Qt::UserRole, aSectionId );
1303 myLocalPointView->setItem( aRowId, 0, anItem );
1305 anItem = new QTableWidgetItem( QString::number( aPointId + 1 ) );
1306 anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled );
1307 anItem->setData( Qt::UserRole, aPointId );
1308 myLocalPointView->setItem( aRowId, 1, anItem );
1310 anItem = new QTableWidgetItem( QString::number( theX ) );
1311 anItem->setData( Qt::UserRole, theX );
1312 myLocalPointView->setItem( aRowId, 2, anItem );
1314 anItem = new QTableWidgetItem( QString::number( theY ) );
1315 anItem->setData( Qt::UserRole, theY );
1316 myLocalPointView->setItem( aRowId, 3, anItem );
1321 * Set drag operation started. Save the position and a list of dragged points
1322 * \param theState the drag operation state: started/finished
1323 * \param thePoint the start drag position
1325 void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& thePoint )
1328 getSelectedPonts( myDragPoints );
1329 myDragStarted = myDragPoints.size();
1330 myDragStartPosition = thePoint;
1331 if ( myDragStarted ) {
1332 // change a viewer interaction style in order to avoid a select rectangle build
1333 myDragInteractionStyle = changeInteractionStyle( SUIT_ViewModel::KEY_FREE );
1337 if ( myDragStarted )
1338 changeInteractionStyle( myDragInteractionStyle );
1339 myDragStarted = false;
1340 myDragPoints.clear();
1345 void CurveCreator_Widget::getSelectedPonts( CurveCreator_Widget::SectionToPointList& thePoints )
1348 for ( int i = 0, aNb = myLocalPointView->rowCount(); i < aNb; i++ )
1349 thePoints.push_back( std::make_pair( getSectionId( i ), getPointId( i ) ) );
1352 void CurveCreator_Widget::setSelectedPonts( const CurveCreator_Widget::SectionToPointList& thePoints )
1354 if ( myDragStarted )
1356 Handle(AIS_InteractiveContext) ic = getAISContext();
1357 if ( ic.IsNull() || !ic->HasOpenedContext() )
1360 AIS_ListOfInteractive aListToSelect;
1361 AIS_ListOfInteractive aDisplayedList;
1362 ic->DisplayedObjects( aDisplayedList );
1364 SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end();
1365 SectionToPoint aSToPoint;
1366 for( ; anIt != aLast; anIt++ ) {
1369 for ( AIS_ListIteratorOfListOfInteractive it( aDisplayedList ); it.More(); it.Next() )
1371 Handle(AIS_InteractiveObject) anAIS = it.Value();
1372 if ( anAIS.IsNull() )
1374 Handle(AIS_Point) anAISPoint = Handle(AIS_Point)::DownCast( anAIS );
1375 if ( anAISPoint.IsNull() )
1378 TopoDS_Vertex aVertex = TopoDS::Vertex( anAISPoint->Vertex() );
1380 if ( aVertex.IsNull() )
1383 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
1385 SectionToPointList aPoints;
1386 findSectionsToPoints( aPnt.X(), aPnt.Y(), aPoints );
1388 SectionToPointList::const_iterator anIt = aPoints.begin(), aLast = aPoints.end();
1389 SectionToPoint aPoint;
1390 for ( ; anIt != aLast; anIt++ ) {
1392 if ( aPoint.first == aSToPoint.first && aPoint.second == aSToPoint.second )
1393 aListToSelect.Append( anAIS );
1398 ic->ClearSelected( Standard_False );
1399 setObjectsSelected( aListToSelect );
1400 updateLocalPointView();
1404 * Get viewer information before perform the curve modification.
1405 * Take a list of selected cuve points an close local context.
1406 * The context should be closed because the curve presentation is
1407 * redisplayed and if it is not closed, when we close the local context
1408 * later, the presentation shown in the local context is disappeared.
1409 * \param thePoints an output list of curve selected points
1410 * \param theFillPoints a flag whether the selection list should be filled
1412 void CurveCreator_Widget::startCurveModification(
1413 CurveCreator_Widget::SectionToPointList& thePoints,
1414 const bool theFillPoints )
1416 if ( theFillPoints ) {
1418 getSelectedPonts( thePoints );
1420 setLocalPointContext( false );
1424 * Restore the viewer state after the curve modification is done.
1425 * Open local context and select given points inside it.
1426 * \param thePoints a list of curve selected points
1428 void CurveCreator_Widget::finishCurveModification(
1429 const CurveCreator_Widget::SectionToPointList& thePoints )
1431 if ( getActionMode() == ModificationMode )
1432 setLocalPointContext( true );
1433 setSelectedPonts( thePoints );
1438 * Returns a point index in the model curve by the point coordinates in the viewer
1439 * \param theX the X coordinate of the point
1440 * \param theY the Y coordinate of the point
1442 int CurveCreator_Widget::findLocalPointIndex( int theSectionId, float theX, float theY )
1446 CurveCreator::Coordinates aCoords;
1447 for ( int i = 0, aNb = myCurve->getNbPoints( theSectionId ); i < aNb && aPntIndex < 0; i++ ) {
1448 aCoords = myCurve->getPoint( theSectionId, i );
1449 if ( aCoords.size() < 2 )
1451 if ( fabs( aCoords[0] - theX ) < LOCAL_SELECTION_TOLERANCE &&
1452 fabs( aCoords[1] - theY ) < LOCAL_SELECTION_TOLERANCE )
1459 void CurveCreator_Widget::findSectionsToPoints( const double theX, const double theY,
1460 CurveCreator_Widget::SectionToPointList& thePoints )
1465 for ( int i = 0, aNb = myCurve->getNbSections(); i < aNb; i++ ) {
1466 aPointId = findLocalPointIndex( i, theX, theY );
1469 SectionToPoint aPoint = std::make_pair( i, aPointId );
1470 if ( !contains( thePoints, aPoint ) )
1471 thePoints.push_back( aPoint );
1475 void CurveCreator_Widget::convert( const SectionToPointList& thePoints,
1476 QMap<int, QList<int> >& theConvPoints )
1478 theConvPoints.clear();
1480 SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end();
1482 int aSectionId, aPointId;
1483 for ( ; anIt != aLast; anIt++ ) {
1484 aSectionId = anIt->first;
1485 aPointId = anIt->second;
1487 if ( theConvPoints.contains( aSectionId ) )
1488 aPoints = theConvPoints[aSectionId];
1489 if ( aPoints.contains( aPointId ) )
1491 aPoints.append( aPointId );
1492 theConvPoints[aSectionId] = aPoints;
1497 * Returns a section index from the table
1498 * \param theRowId a table row
1500 int CurveCreator_Widget::getSectionId( const int theRowId ) const
1502 return myLocalPointView->item( theRowId, 0 )->data( Qt::UserRole ).toInt();
1506 * Returns a point index from the table
1507 * \param theRowId a table row
1509 int CurveCreator_Widget::getPointId( const int theRowId ) const
1511 return myLocalPointView->item( theRowId, 1 )->data( Qt::UserRole ).toInt();
1515 * Returns whethe the container has the value
1516 * \param theList a container of values
1517 * \param theValue a value
1519 bool CurveCreator_Widget::contains( const CurveCreator_Widget::SectionToPointList& theList,
1520 const CurveCreator_Widget::SectionToPoint& theValue ) const
1522 bool isFound = false;
1524 SectionToPointList::const_iterator anIt = theList.begin(), aLast = theList.end();
1525 for ( ; anIt != aLast && !isFound; anIt++ )
1526 isFound = anIt->first == theValue.first && anIt->second == theValue.second;