Salome HOME
fe6d6b8848cf55a46adf683ab10d816ef845d594
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Widget.cxx
1 // Copyright (C) 2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
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
28 #include <GEOMUtils.hxx>
29
30 #include <SUIT_Session.h>
31 #include <SUIT_Desktop.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_ViewManager.h>
34
35 #include <OCCViewer_ViewWindow.h>
36 #include <OCCViewer_ViewManager.h>
37 #include <OCCViewer_ViewPort3d.h>
38
39 #include <BRep_Tool.hxx>
40 #include <TopoDS.hxx>
41
42 #include <AIS_ListOfInteractive.hxx>
43 #include <AIS_ListIteratorOfListOfInteractive.hxx>
44 #include <AIS_Shape.hxx>
45 #include <AIS_Point.hxx>
46 #include <StdSelect_BRepOwner.hxx>
47
48 #include <QHBoxLayout>
49 #include <QVBoxLayout>
50 #include <QLabel>
51 #include <QLineEdit>
52 #include <QGroupBox>
53 #include <QToolButton>
54 #include <QToolBar>
55 #include <QAction>
56 #include <QMenu>
57 #include <QMouseEvent>
58 #include <QApplication>
59 #include <QTableWidget>
60
61 #define LOCAL_SELECTION_TOLERANCE 0.0001
62
63 CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
64                                          CurveCreator_ICurve *theCurve,
65                                          Qt::WindowFlags fl) :
66     QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0)
67 {
68     myNewSectionEditor = new CurveCreator_NewSectionDlg( this );
69     myNewSectionEditor->hide();
70     connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()) );
71     connect( myNewSectionEditor, SIGNAL(modifySection()), this, SLOT(onModifySection()) );
72     connect( myNewSectionEditor, SIGNAL(cancelSection()), this, SLOT(onCancelSection()) );
73
74     QGroupBox* aSectionGroup = new QGroupBox(tr("Sections"),this);
75
76     mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup);
77     connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) );
78     connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) );
79     connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) );
80
81     myLocalPointView = new QTableWidget();
82     myLocalPointView->setVisible( false );
83     myLocalPointView->setColumnCount( 3 );
84     QStringList aLabels;
85     //aLabels << tr( "IDENTIFIER_LABEL" ) << tr( "X_POSITION_LBL" ) << tr( "Y_POSITION_LBL" );
86     aLabels << tr( "id" ) << tr( "X" ) << tr( "Y" );
87     myLocalPointView->setHorizontalHeaderLabels( aLabels );
88     connect( myLocalPointView, SIGNAL( cellChanged( int, int ) ),
89              this, SLOT( onLocalPointChanged( int, int ) ) );
90
91     QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup);
92 //    QToolButton* anUndoBtn = new QToolButton(aTB);
93
94     SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
95     QPixmap anUndoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_UNDO")));
96     QPixmap aRedoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_REDO")));
97     QPixmap aNewSectionPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_SECTION")));
98     QPixmap aNewPointPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_POINT")));
99     QPixmap anEditPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
100     QPixmap aDetectPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
101     QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
102     QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
103     QPixmap aRemovePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_DELETE")));
104     QPixmap aJoinPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_JOIN")));
105     QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP")));
106     QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN")));
107
108     QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"), 
109                                    QKeySequence(Qt::ControlModifier|Qt::Key_Z) );
110     connect(anAct, SIGNAL(triggered()), this, SLOT(onUndo()) );
111     aTB->addAction(anAct);
112
113     anAct = createAction( REDO_ID, tr("REDO"), aRedoPixmap, tr("REDO_TLT"), 
114                           QKeySequence(Qt::ControlModifier|Qt::Key_Y) );
115     connect(anAct, SIGNAL(triggered()), this, SLOT(onRedo()) );
116     aTB->addAction(anAct);
117
118     aTB->addSeparator();
119
120     anAct = createAction( NEW_SECTION_ID, tr("NEW_SECTION"), aNewSectionPixmap, tr("NEW_SECTION_TLT"), 
121                           QKeySequence(Qt::ControlModifier|Qt::Key_N) );
122     connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) );
123     aTB->addAction(anAct);
124     aTB->addSeparator();
125
126     anAct = createAction( ADDITION_MODE_ID, tr("ADDITION_MODE"), aNewPointPixmap, tr("ADDITION_MODE_TLT"), 
127                           QKeySequence() );
128     anAct->setCheckable(true);
129     connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onAdditionMode(bool)) );
130     connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
131     aTB->addAction(anAct);
132     
133     anAct = createAction( MODIFICATION_MODE_ID, tr("MODIFICATION_MODE"), anEditPointsPixmap, tr("MODIFICATION_MODE_TLT"), 
134                           QKeySequence() );
135     anAct->setCheckable(true);
136     connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onModificationMode(bool)) );
137     connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
138     aTB->addAction(anAct);
139
140     anAct = createAction( DETECTION_MODE_ID, tr("DETECTION_MODE"), aDetectPointsPixmap, tr("DETECTION_MODE_TLT"), 
141                           QKeySequence() );
142     anAct->setCheckable(true);
143     connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onDetectionMode(bool)) );
144     connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
145     aTB->addAction(anAct);
146
147     anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), QPixmap(), tr("CLOSE_SECTIONS_TLT"), 
148                           QKeySequence(Qt::ControlModifier|Qt::Key_W) );
149     connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) );
150
151     anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), QPixmap(), 
152                           tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) );
153     connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) );
154
155     anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"), 
156                           aPolylinePixmap, tr("SET_POLYLINE_TLT"), 
157                           QKeySequence(Qt::ControlModifier|Qt::Key_E) );
158     connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) );
159
160     anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), aSplinePixmap, 
161                           tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) );
162     connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) );
163
164     anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemovePixmap, tr("REMOVE_TLT"), 
165                           QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) );
166     connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) );
167     aTB->addAction(anAct);
168     aTB->addSeparator();
169
170     anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"), 
171                           QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) );
172     connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) );
173     aTB->addAction(anAct);
174     aTB->addSeparator();
175
176     anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"), 
177                           QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) );
178     connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) );
179
180     anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), QPixmap(), tr("JOIN_ALL_TLT"), 
181                           QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) );
182     connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) );
183
184     QVBoxLayout* aSectLayout = new QVBoxLayout();
185     aSectLayout->setMargin( 5 );
186     aSectLayout->setSpacing( 5 );
187     aSectLayout->addWidget(aTB);
188     aSectLayout->addWidget(mySectionView);
189     aSectLayout->addWidget( myLocalPointView );
190     aSectionGroup->setLayout(aSectLayout);
191     QVBoxLayout* aLay = new QVBoxLayout();
192     aLay->setMargin( 0 );
193     aLay->setSpacing( 5 );
194 //    aLay->addLayout(aNameLayout);
195     aLay->addWidget(aSectionGroup);
196     setLayout(aLay);
197     onSelectionChanged();
198
199     /*OCCViewer_Viewer* anOCCViewer = getOCCViewer();
200     if (anOCCViewer) {
201       OCCViewer_ViewWindow* aWnd = dynamic_cast<OCCViewer_ViewWindow*>(anOCCViewer->getViewManager()->getActiveView());
202       if ( aWnd )
203         aWnd->installEventFilter( this );
204     }*/
205 }
206
207 //=======================================================================
208 // function: getUniqSectionName
209 // purpose: return unique section name
210 //=======================================================================
211 OCCViewer_Viewer* CurveCreator_Widget::getOCCViewer()
212 {
213   OCCViewer_Viewer* anOCCViewer = 0;
214
215   OCCViewer_ViewWindow* aViewWindow = 0;
216   SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
217   if ( activeStudy )
218     aViewWindow = dynamic_cast<OCCViewer_ViewWindow*>(SUIT_Session::session()->activeApplication()->desktop()->activeWindow());
219   if ( aViewWindow == 0 )
220     return anOCCViewer;
221   OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>(aViewWindow->getViewManager());
222   if ( aViewManager == 0 )
223     return anOCCViewer;
224
225   anOCCViewer = aViewManager->getOCCViewer();
226   return anOCCViewer;
227 }
228
229 /*!
230   \brief Customize event handling
231   \param watched event receiver object
232   \param e event
233   \return \c true if the event processing should be stopped
234 */
235 /*bool CurveCreator_Widget::eventFilter( QObject* theWatched, QEvent* theEvent )
236 {
237   OCCViewer_Viewer* anOCCViewer = getOCCViewer();
238   Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext();
239   bool isLocalContext = aContext->HasOpenedContext();
240   if ( !isLocalContext )
241     return QWidget::eventFilter( theWatched, theEvent );
242
243   bool isProcessed = true;
244
245   return isProcessed;
246 }*/
247
248 //=======================================================================
249 // function: getUniqSectionName
250 // purpose: return unique section name
251 //=======================================================================
252 std::string CurveCreator_Widget::getUniqSectionName( CurveCreator_ICurve* theCurve ) const
253 {
254   for( int i = 0 ; i < 1000000 ; i++ ){
255       char aBuffer[255];
256       sprintf( aBuffer, "Section_%d", i+1 );
257       std::string aName(aBuffer);
258       int j;
259       for( j = 0 ; j < theCurve->getNbSections() ; j++ ){
260         if( theCurve->getSectionName(j) == aName )
261             break;
262       }
263       if( j == theCurve->getNbSections() )
264           return aName;
265   }
266   return "";
267 }
268
269 void CurveCreator_Widget::setCurve( CurveCreator_ICurve* theCurve )
270 {
271   myCurve = theCurve;
272   mySectionView->setCurve(myCurve);
273   onSelectionChanged();
274   updateUndoRedo();
275 }
276
277 void CurveCreator_Widget::onSelectionChanged()
278 {
279   QList<ActionId> anEnabledAct;
280   if( myCurve ){
281     anEnabledAct << NEW_SECTION_ID;
282     QList<int> aSelSections = mySectionView->getSelectedSections();
283     QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints();
284     CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
285     switch( aSelType ){
286     case CurveCreator_TreeView::ST_NOSEL:{
287       break;
288     }
289     case CurveCreator_TreeView::ST_SECTIONS:{
290       /*if( aSelSections[0] > 0 ){
291         anEnabledAct << UP_ID;
292       }*/
293       if( aSelSections.size() == 1 ){
294         anEnabledAct << ADDITION_MODE_ID << MODIFICATION_MODE_ID << DETECTION_MODE_ID;
295       }
296       if (myActionMap[ADDITION_MODE_ID]->isChecked()) {
297         mySection = -1;
298         myPointNum = -1;
299         QList<int> aSelSection = mySectionView->getSelectedSections();
300         if( aSelSection.size() > 0 ){
301           mySection = aSelSection[0];
302           myPointNum = myCurve->getNbPoints(mySection);
303         }
304       } else if (myActionMap[MODIFICATION_MODE_ID]->isChecked()) {
305         anEnabledAct << REMOVE_ID;
306         anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID;
307         int aSectCnt = myCurve->getNbSections();
308         if( aSectCnt > 0 )
309           anEnabledAct << CLEAR_ALL_ID;
310         if( aSectCnt > 1 )
311           anEnabledAct << JOIN_ALL_ID;
312         if( aSelSections.size() > 1 ){
313           anEnabledAct << JOIN_ID;
314         }
315       } else if (myActionMap[DETECTION_MODE_ID]->isChecked()) {
316       } else { //no active mode
317       }
318       /*if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){
319         anEnabledAct << DOWN_ID;
320       }*/
321       break;
322     }
323     /*case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{
324       if( aSelPoints[0].second > 0 ){
325         anEnabledAct << UP_ID;
326       }
327       int aLastIndex = aSelPoints.size()-1;
328       int aSect = aSelPoints[0].first;
329       if( aSelPoints[aLastIndex].second < (myCurve->getNbPoints(aSect) - 1)){
330         anEnabledAct << DOWN_ID;
331       }
332       if( aSelPoints.size() == 1){
333         anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID;
334       }
335       break;
336     }*/
337
338     }
339     
340     /*int aSelObjsCnt = aSelPoints.size() + aSelSections.size();
341     if( aSelObjsCnt > 0 ){
342       anEnabledAct << REMOVE_ID;
343     }
344     if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){
345       anEnabledAct << REMOVE_ALL_ID;
346     }*/
347     if( myCurve->getNbSections() > 1 ){
348       anEnabledAct << JOIN_ALL_ID;
349     }
350   }
351   QList<ActionId> anIds = myActionMap.keys();
352   for( int i = 0 ; i < anIds.size() ; i++ ){
353     if( myActionMap.contains(anIds[i]) ){
354       if( anEnabledAct.contains(anIds[i]) ){
355         myActionMap[anIds[i]]->setEnabled(true);
356       }
357       else{
358         myActionMap[anIds[i]]->setEnabled(false);
359       }
360     }
361   }
362   emit selectionChanged();
363 }
364
365 void CurveCreator_Widget::onAdditionMode(bool checked)
366 {
367   if( !myCurve )
368     return;
369   OCCViewer_Viewer* anOCCViewer = getOCCViewer();
370   Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext();
371   OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
372                                                     (anOCCViewer->getViewManager());
373 //  if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) {
374   if( anOCCViewer ) {
375     if (checked) {
376 /*      myGuiState = aViewWindow->saveState();
377       anOCCViewer->enableMultiselection(false);
378       anOCCViewer->enableSelection(false);*/
379       connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
380              this, SLOT( onGetCoordsByClick( SUIT_ViewWindow*, QMouseEvent* ) ) );
381     } else {
382       disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
383              this, SLOT( onGetCoordsByClick( SUIT_ViewWindow*, QMouseEvent* ) ) );
384 /*      anOCCViewer->enableMultiselection(true);
385       anOCCViewer->enableSelection(true);
386       aViewWindow->restoreState( myGuiState );*/
387       return;
388     }
389   }
390
391   mySection= -1;
392   myPointNum = -1;
393   QList<int> aSelSection = mySectionView->getSelectedSections();
394   if( aSelSection.size() > 0 ){
395     mySection = aSelSection[0];
396   }
397   else{
398     QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
399     if( aSelPoints.size() > 0 ){
400       mySection = aSelPoints[0].first;
401       myPointNum = aSelPoints[0].second + 1;
402     }
403   }
404 //  emit subOperationStarted( myNewPointEditor );
405 }
406
407 void CurveCreator_Widget::onModificationMode(bool checked)
408 {
409   myLocalPointView->setVisible( checked );
410   OCCViewer_Viewer* anOCCViewer = getOCCViewer();
411   OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
412                                                     (anOCCViewer->getViewManager());
413 /*
414   SUIT_ViewWindow* aViewWindow = 0;
415   SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
416   if ( activeStudy )
417     aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
418   if ( aViewWindow == 0 )
419     return;
420   SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();*/
421   if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) {
422     if (checked) {
423       connect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
424              this, SLOT( onPointSelect( SUIT_ViewWindow*, QMouseEvent* ) ) );
425       connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
426              this, SLOT( onPointDrag( SUIT_ViewWindow*, QMouseEvent* ) ) );
427     }
428     else {
429       disconnect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
430              this, SLOT( onPointSelect( SUIT_ViewWindow*, QMouseEvent* ) ) );
431       disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
432              this, SLOT( onPointDrag( SUIT_ViewWindow*, QMouseEvent* ) ) );
433       return;
434     }
435   }
436   //NDS OCCViewer_ViewWindow* anOCCWnd = dynamic_cast<OCCViewer_ViewWindow*>(aViewWindow);
437   //anOCCWnd->activateStartPointSelection();
438     // activate selection ------>
439   //OCCViewer_Viewer* anOCCViewer = dynamic_cast<OCCViewer_Viewer*>(aViewManager->getViewModel());
440
441   setLocalPointContext( true );
442 }
443
444 void CurveCreator_Widget::onDetectionMode(bool checked)
445 {
446 }
447
448 void CurveCreator_Widget::onModeChanged(bool checked)
449 {
450   setLocalPointContext( false );
451   if (checked) {
452     QAction* anAction = (QAction*)sender();
453     switch(myActionMap.key(anAction)) {
454       case ADDITION_MODE_ID:
455         if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
456           myActionMap[MODIFICATION_MODE_ID]->trigger();
457         else if (myActionMap[DETECTION_MODE_ID]->isChecked())
458           myActionMap[DETECTION_MODE_ID]->trigger();
459         break;
460       case MODIFICATION_MODE_ID:
461         if (myActionMap[ADDITION_MODE_ID]->isChecked())
462           myActionMap[ADDITION_MODE_ID]->trigger();
463         else if (myActionMap[DETECTION_MODE_ID]->isChecked())
464           myActionMap[DETECTION_MODE_ID]->trigger();
465         break;
466       case DETECTION_MODE_ID:
467         if (myActionMap[ADDITION_MODE_ID]->isChecked())
468           myActionMap[ADDITION_MODE_ID]->trigger();
469         else if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
470           myActionMap[MODIFICATION_MODE_ID]->trigger();
471         break;
472     }
473   }
474   onSelectionChanged();
475 }
476
477 void CurveCreator_Widget::onAddNewPoint(const CurveCreator::Coordinates& theCoords)
478 {
479   if( !myCurve )
480     return;
481   myCurve->addPoints(theCoords, mySection, myPointNum );
482   mySectionView->pointsAdded( mySection, myPointNum );
483   myPointNum++;
484   onSelectionChanged();
485   updateUndoRedo();
486 }
487
488 void CurveCreator_Widget::onNewSection()
489 {
490   if( !myCurve )
491     return;
492   myNewSectionEditor->clear();
493   myNewSectionEditor->setEditMode(false);
494   QString aSectName = QString( getUniqSectionName(myCurve).c_str() );
495   myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline );
496   emit subOperationStarted( myNewSectionEditor );
497 }
498
499 void CurveCreator_Widget::onAddNewSection()
500 {
501   if( !myCurve )
502     return;
503   myCurve->addSection( myNewSectionEditor->getName().toStdString(), myNewSectionEditor->getSectionType(),
504                       myNewSectionEditor->isClosed() );
505   mySectionView->sectionAdded( -1 ); // add a new section to the end of list
506   QString aNewName = QString(getUniqSectionName(myCurve).c_str());
507   myNewSectionEditor->setSectionName(aNewName);
508   onSelectionChanged();
509   updateUndoRedo();
510   onCancelSection();
511 }
512
513 void CurveCreator_Widget::onCancelSection()
514 {
515   emit subOperationFinished( myNewSectionEditor );
516 }
517
518 QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
519                                             const QString& theToolTip, const QKeySequence& theShortcut )
520 {
521   QAction* anAct = new QAction(theName,this);
522   if( !theImage.isNull() ){
523     anAct->setIcon(theImage);
524   }
525   anAct->setShortcut(theShortcut);
526   anAct->setToolTip(theToolTip);
527   myActionMap[theId] = anAct;
528   return anAct;
529 }
530
531 QAction* CurveCreator_Widget::getAction(ActionId theId)
532 {
533   if( myActionMap.contains(theId) )
534     return myActionMap[theId];
535   return NULL;
536 }
537
538 void CurveCreator_Widget::onEditSection( int theSection )
539 {
540   if( !myCurve )
541     return;
542   mySection = theSection;
543   QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
544   bool isClosed = myCurve->isClosed(theSection);
545   CurveCreator::SectionType aType = myCurve->getSectionType(theSection);
546   myNewSectionEditor->setEditMode(true);
547   myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType );
548
549   emit subOperationStarted( myNewSectionEditor );
550 }
551
552 void CurveCreator_Widget::onModifySection()
553 {
554   if( !myCurve )
555     return;
556   QString aName = myNewSectionEditor->getName();
557   bool isClosed = myNewSectionEditor->isClosed();
558   CurveCreator::SectionType aSectType = myNewSectionEditor->getSectionType();
559 //  myCurve->startOperation();
560   myCurve->setClosed( isClosed, mySection );
561   myCurve->setSectionName( mySection , aName.toStdString() );
562   myCurve->setSectionType( mySection, aSectType );
563 //  myCurve->finishOperation();
564   mySectionView->sectionChanged(mySection);
565   updateUndoRedo();
566   onCancelSection();
567 }
568
569 /*void CurveCreator_Widget::onEditPoint( int theSection, int thePoint )
570 {
571   if( !myNewPointEditor || !myEdit )
572     return;
573   mySection = theSection;
574   myPointNum = thePoint;
575   QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
576   myNewPointEditor->setEditMode(true);
577   myNewPointEditor->setSectionName(aSectName);
578   myNewPointEditor->setDimension( myCurve->getDimension() );
579   CurveCreator::Coordinates aCoords = myCurve->getCoordinates(theSection,thePoint);
580   myNewPointEditor->setCoordinates(aCoords);
581   emit subOperationStarted( myNewPointEditor );
582 }
583
584 void CurveCreator_Widget::onModifyPoint()
585 {
586   if( !myEdit )
587     return;
588   CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates();
589   myEdit->setCoordinates( aCoords, mySection, myPointNum );
590   mySectionView->pointDataChanged( mySection, myPointNum );
591   updateUndoRedo();
592   onCancelPoint();
593 }*/
594
595 void CurveCreator_Widget::onJoin()
596 {
597   if( !myCurve )
598     return;
599   QList<int> aSections = mySectionView->getSelectedSections();
600   if( aSections.size() == 0 ){
601     return;
602   }
603   int aMainSect = aSections[0];
604   int aMainSectSize = myCurve->getNbPoints(aMainSect);
605 //  myCurve->startOperation();
606   for( int i = 1 ; i < aSections.size() ; i++ ){
607     int aSectNum = aSections[i] - (i-1);
608     myCurve->join( aMainSect, aSectNum );
609     mySectionView->sectionsRemoved( aSectNum );
610   }
611 //  myCurve->finishOperation();
612   int aNewSectSize = myCurve->getNbPoints(aMainSect);
613   if( aNewSectSize != aMainSectSize )
614     mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );
615   updateUndoRedo();
616 }
617
618 void CurveCreator_Widget::onRemove()
619 {
620   if( !myCurve )
621     return;
622   QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
623   int aCurrSect=-1;
624   int aRemoveCnt = 0;
625 //  myCurve->startOperation();
626   for( int i = 0 ; i < aSelPoints.size() ; i++ ){
627     if( aCurrSect != aSelPoints[i].first ){
628       aRemoveCnt = 0;
629       aCurrSect = aSelPoints[i].first;
630     }
631     int aPntIndx = aSelPoints[i].second - aRemoveCnt;
632     myCurve->removePoint( aCurrSect, aPntIndx );
633     mySectionView->pointsRemoved( aCurrSect, aPntIndx );
634     aRemoveCnt++;
635   }
636   QList<int> aSections = mySectionView->getSelectedSections();
637   for( int i = 0 ; i < aSections.size() ; i++ ){
638     int aSectNum = aSections[i] - (i);
639     myCurve->removeSection( aSectNum );
640     mySectionView->sectionsRemoved( aSectNum );
641   }
642 //  myCurve->finishOperation();
643   mySectionView->clearSelection();
644   updateUndoRedo();
645 }
646
647 void CurveCreator_Widget::onClearAll()
648 {
649   if( !myCurve )
650     return;
651   myCurve->clear();
652   mySectionView->reset();
653   onSelectionChanged();
654   updateUndoRedo();
655 }
656
657 void CurveCreator_Widget::onJoinAll()
658 {
659   if( !myCurve )
660     return;
661   myCurve->join();
662   mySectionView->reset();
663   onSelectionChanged();
664   updateUndoRedo();
665 }
666
667 void CurveCreator_Widget::onUndoSettings()
668 {
669
670 }
671
672 void CurveCreator_Widget::onSetSpline()
673 {
674   if( !myCurve )
675     return;
676   QList<int> aSelSections = mySectionView->getSelectedSections();
677 //  myCurve->startOperation();
678   for( int i = 0 ; i < aSelSections.size() ; i++ ){
679     myCurve->setSectionType(aSelSections[i], CurveCreator::Spline );
680     mySectionView->sectionChanged(aSelSections[i]);
681   }
682 //  myCurve->finishOperation();
683   updateUndoRedo();
684 }
685
686 void CurveCreator_Widget::onSetPolyline()
687 {
688   if( !myCurve )
689     return;
690 //  myCurve->startOperation();
691   QList<int> aSelSections = mySectionView->getSelectedSections();
692   for( int i = 0 ; i < aSelSections.size() ; i++ ){
693     myCurve->setSectionType( aSelSections[i], CurveCreator::Polyline );
694     mySectionView->sectionChanged( aSelSections[i] );
695   }
696 //  myCurve->finishOperation();
697   updateUndoRedo();
698 }
699
700 void CurveCreator_Widget::onCloseSections()
701 {
702   if( !myCurve )
703     return;
704 //  myCurve->startOperation();
705   QList<int> aSelSections = mySectionView->getSelectedSections();
706   for( int i = 0 ; i < aSelSections.size() ; i++ ){
707     myCurve->setClosed(true, aSelSections[i]);
708     mySectionView->sectionChanged(aSelSections[i]);
709   }
710 //  myCurve->finishOperation();
711   updateUndoRedo();
712 }
713
714 void CurveCreator_Widget::onUncloseSections()
715 {
716   if( !myCurve )
717     return;
718 //  myCurve->startOperation();
719   QList<int> aSelSections = mySectionView->getSelectedSections();
720   for( int i = 0 ; i < aSelSections.size() ; i++ ){
721     myCurve->setClosed(false, aSelSections[i]);
722     mySectionView->sectionChanged(aSelSections[i]);
723   }
724 //  myCurve->finishOperation();
725   updateUndoRedo();
726 }
727
728 void CurveCreator_Widget::onUndo()
729 {
730     if( !myCurve )
731       return;
732     myCurve->undo();
733     mySectionView->reset();
734     updateUndoRedo();
735 }
736
737 void CurveCreator_Widget::onRedo()
738 {
739     if( !myCurve )
740       return;
741     myCurve->redo();
742     mySectionView->reset();
743     updateUndoRedo();
744 }
745
746 void CurveCreator_Widget::updateUndoRedo()
747 {
748     QAction* anAct = myActionMap[UNDO_ID];
749     if( anAct != 0 ){
750         if( myCurve->getNbUndo() != 0 ){
751             anAct->setEnabled(true);
752         }
753         else{
754             anAct->setDisabled(true);
755         }
756     }
757     anAct = myActionMap[REDO_ID];
758     if( anAct != 0 ){
759         if( myCurve->getNbRedo() != 0 ){
760             anAct->setEnabled(true);
761         }
762         else{
763             anAct->setDisabled(true);
764         }
765     }
766 }
767
768 void CurveCreator_Widget::onContextMenu( QPoint thePoint )
769 {
770   QList<ActionId> aContextActions;
771   aContextActions << CLEAR_ALL_ID << JOIN_ALL_ID << SEPARATOR_ID <<
772                      CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID <<
773                      SET_SECTIONS_SPLINE_ID;
774   QPoint aGlPoint = mySectionView->mapToGlobal(thePoint);
775   bool isVis = false;
776   QList<ActionId> aResAct;
777   for( int i = 0 ; i < aContextActions.size() ; i++ ){
778     if( aContextActions[i] != SEPARATOR_ID ){
779       if( myActionMap.contains(aContextActions[i]) ){
780         QAction* anAct = myActionMap[aContextActions[i]];
781         if( anAct->isEnabled() ){
782           aResAct << aContextActions[i];
783           isVis = true;
784         }
785       }
786     }
787     else{
788       aResAct << SEPARATOR_ID;
789     }
790   }
791   if( !isVis )
792     return;
793
794   QMenu* aMenu = new QMenu(this);
795   for( int i = 0 ; i < aResAct.size() ; i++ ){
796     if( aResAct[i] == SEPARATOR_ID ){
797       aMenu->addSeparator();
798     }
799     else{
800       QAction* anAct = myActionMap[aResAct[i]];
801       aMenu->insertAction(NULL, anAct);
802     }
803   }
804   aMenu->exec(aGlPoint);
805 }
806
807 QList<int> CurveCreator_Widget::getSelectedSections()
808 {
809   return mySectionView->getSelectedSections();
810 }
811
812 QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints()
813 {
814   return mySectionView->getSelectedPoints();
815 }
816
817 //=================================================================================
818 // function : GeometryGUI::onGetCoordsByClick()
819 // purpose  : Manage mouse press events in Additon mode
820 //=================================================================================
821 void CurveCreator_Widget::onGetCoordsByClick( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe )
822 {
823   if (pe->button() != Qt::LeftButton)
824     return;
825
826   if ( theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
827        pe->modifiers() != Qt::ControlModifier ) {
828     OCCViewer_Viewer* anOCCViewer =
829       ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
830     Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
831
832     gp_Pnt aPnt;    
833
834     ic->InitSelected();
835     if ( pe->modifiers() == Qt::ShiftModifier )
836       ic->ShiftSelect();  // Append selection
837     else
838       ic->Select();       // New selection
839
840     /*TopoDS_Shape aShape;
841
842     ic->InitSelected();
843     if ( ic->MoreSelected() )
844       aShape = ic->SelectedShape();
845
846     if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
847       aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
848     else*/
849     {
850       OCCViewer_ViewPort3d* vp =  ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
851       aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
852     }
853     // set the coordinates into dialog
854     CurveCreator::Coordinates aCoords;
855     aCoords.push_back( aPnt.X() );
856     aCoords.push_back( aPnt.Y() );
857     if ( myCurve->getDimension() == 3 ) {
858       aCoords.push_back( aPnt.Z() );
859     }
860     onAddNewPoint(aCoords);
861 //    myNewPointEditor->setCoordinates( aCoords );
862   }
863 }
864
865 //=================================================================================
866 // function : HYDROGUI_PolylineOp::onPointSelect()
867 // purpose  : Manage mouse press events in Modification mode
868 //=================================================================================
869 void CurveCreator_Widget::onPointSelect( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe )
870 {
871   //store initial cursor position for Drag&Drop
872   if (pe->button() == Qt::LeftButton)
873     myDragStartPosition = pe->pos();
874   
875   //gp_Pnt aPnt;
876   OCCViewer_Viewer* anOCCViewer = 
877       ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
878   Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext();
879   
880   //ic->InitSelected();
881   //if ( pe->modifiers() == Qt::ShiftModifier )
882   //  ic->ShiftSelect();  // Append selection
883   //else
884   //  ic->Select();       // New selection
885   
886   /*ic->InitSelected();
887   if ( ic->MoreSelected() ) {
888     TopoDS_Shape aShape = ic->SelectedShape();
889     Standard_Boolean hasdet = ic->HasDetectedShape();
890     Standard_Boolean hassel = ic->HasSelectedShape();
891     Standard_Integer nbcur = ic->NbCurrents();
892     Standard_Integer nbsel = ic->NbSelected();
893     if(!aShape.IsNull())
894       if ( aShape.ShapeType() == TopAbs_VERTEX )
895         aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
896   }
897   
898   Qt::KeyboardModifiers modifiers = pe->modifiers();
899 //  aSketcherDlg->OnPointSelected( modifiers, aPnt );  // "feed" the point to point construction dialog*/
900
901   updateLocalPointView();
902 }
903
904 //=================================================================================
905 // function : GeometryGUI::onPointDrag()
906 // purpose  : Manage mouse move events in Modification mode
907 //=================================================================================
908 void CurveCreator_Widget::onPointDrag( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe )
909 {
910   if ( !(pe->buttons() & Qt::LeftButton) )
911     return;
912   if ( (pe->pos() - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() )
913     return;
914 /*  
915   QDrag *drag = new QDrag(this);
916   QMimeData *mimeData = new QMimeData;
917   
918   mimeData->setData(mimeType, data);
919   drag->setMimeData(mimeData);
920   
921   Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
922   */
923 }
924
925 void CurveCreator_Widget::onLocalPointChanged( int theRow, int theColumn )
926 {
927   QList<int> aSelSections = mySectionView->getSelectedSections();
928   if ( aSelSections.size() < 0 )
929     return;
930
931   int aSection = aSelSections[0];
932
933   QList<int> aSelPoints;
934   getSelectedPonts( aSection, aSelPoints );
935   setLocalPointContext( false );
936
937   int aPntIndex = -1;
938   int aCurrSect=-1;
939   std::deque<float> aChangedPos;
940   float aPrevX, aPrevY, aX, anY;
941   //for( int i = 0 ; i < aSelSections.size() ; i++ ){
942     aCurrSect = aSection;//aSelSections[i];
943
944     aPrevX = myLocalPointView->item( theRow, 1 )->data( Qt::UserRole ).toDouble();
945     aPrevY = myLocalPointView->item( theRow, 2 )->data( Qt::UserRole ).toDouble();
946
947     aPntIndex = findLocalPointIndex( aCurrSect, aPrevX, aPrevY );
948     if ( aPntIndex >= 0 ) {
949       aX  = myLocalPointView->item( theRow, 1 )->text().toDouble();
950       anY = myLocalPointView->item( theRow, 2 )->text().toDouble();
951       aChangedPos.clear();
952       aChangedPos.push_back( aX );
953       aChangedPos.push_back( anY );
954       myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos );
955     }
956   //}
957   setLocalPointContext( true );
958   setSelectedPonts( aSection, aSelPoints );
959 }
960
961 int CurveCreator_Widget::findLocalPointIndex( int theSectionId, float theX, float theY )
962 {
963   int aPntIndex = -1;
964
965   CurveCreator::Coordinates aCoords;
966   for ( int i = 0, aNb = myCurve->getNbPoints( theSectionId ); i < aNb && aPntIndex < 0; i++ ) {
967     aCoords = myCurve->getPoint( theSectionId, i );
968     if ( aCoords.size() < 2 )
969       continue;
970     if ( fabs( aCoords[0] - theX ) < LOCAL_SELECTION_TOLERANCE &&
971          fabs( aCoords[1] - theY ) < LOCAL_SELECTION_TOLERANCE )
972       aPntIndex = i;
973   }
974
975   return aPntIndex;
976 }
977
978 void CurveCreator_Widget::updateLocalPointView()
979 {
980   OCCViewer_Viewer* anOCCViewer = getOCCViewer();
981   if ( !anOCCViewer )
982     return;
983   Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext();
984
985   bool isBlocked = myLocalPointView->blockSignals(true);
986   gp_Pnt aPnt;
987   myLocalPointView->setRowCount( 0 );
988   for ( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() ) {
989     TopoDS_Vertex aVertex;
990     TopoDS_Shape aShape = aContext->SelectedShape();
991     if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
992       aVertex = TopoDS::Vertex( aContext->SelectedShape() );
993     else {
994       Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
995       if ( !anOwner.IsNull() ) {
996         Handle(AIS_InteractiveObject) anAIS = Handle(AIS_InteractiveObject)::DownCast( anOwner->Selectable() );
997         if ( !anAIS.IsNull() ) {
998           Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast( anAIS);
999           if ( !aPoint.IsNull() )
1000             aVertex = TopoDS::Vertex( aPoint->Vertex() );
1001         }
1002         if ( aVertex.IsNull() ) {
1003           // the following happens if there are no points in the current curve, there is only a shape
1004           /*Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1005           if ( aBrepOwner.IsNull() )
1006             continue;
1007           if ( aBrepOwner->HasShape() ) {
1008             const TopoDS_Shape& aShape = aBrepOwner->Shape();
1009             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
1010             {
1011               aVertex = TopoDS::Vertex( aShape );
1012             }
1013           }*/
1014         }
1015       }
1016       if ( aVertex.IsNull() )
1017         continue;
1018       aPnt = BRep_Tool::Pnt( aVertex );
1019       addLocalPointToTable( aPnt.X(), aPnt.Y() );
1020     }
1021   }
1022   myLocalPointView->blockSignals(isBlocked);
1023 }
1024
1025 void CurveCreator_Widget::setLocalPointContext( const bool theOpen )
1026 {
1027   OCCViewer_Viewer* anOCCViewer = getOCCViewer();
1028   Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
1029
1030   if ( theOpen ) {
1031     // Open local context if there is no one
1032     bool allObjects = true;
1033     if ( !ic->HasOpenedContext() ) {
1034       ic->ClearCurrents( false );
1035       ic->OpenLocalContext( allObjects, true, true );
1036     }
1037     AIS_ListOfInteractive aList;
1038     ic->DisplayedObjects( aList );
1039     int aLSize = 0;
1040     for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
1041       aLSize++;
1042
1043     int theMode = TopAbs_VERTEX;
1044     for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
1045     {
1046       Handle(AIS_InteractiveObject) anAIS = it.Value();
1047       if ( !anAIS.IsNull() )
1048       {
1049         if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) )
1050         {
1051           ic->Load( anAIS, -1, false );
1052           ic->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)theMode ) );
1053         }
1054         else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) )
1055         {
1056           ic->Load( anAIS, -1, false );
1057           ic->Activate( anAIS, theMode );
1058         }
1059       }
1060       continue;
1061     }
1062   }
1063   else {
1064     ic->CloseAllContexts();
1065   }
1066 }
1067
1068 void CurveCreator_Widget::addLocalPointToTable( const double theX, const double theY )
1069 {
1070   int aRowId = myLocalPointView->rowCount();
1071   double aCurrentX, aCurrentY;
1072   for ( int i = 0; i < aRowId; i++ ) {
1073     aCurrentX = myLocalPointView->item( i, 1 )->data( Qt::UserRole ).toDouble();
1074     aCurrentY = myLocalPointView->item( i, 2 )->data( Qt::UserRole ).toDouble();
1075     if ( fabs( aCurrentX - theX ) < LOCAL_SELECTION_TOLERANCE &&
1076          fabs( aCurrentY - theY ) < LOCAL_SELECTION_TOLERANCE )
1077       return;
1078   }
1079   QTableWidgetItem* anItem;
1080
1081   myLocalPointView->setRowCount( aRowId+1 );
1082   anItem = new QTableWidgetItem( QString::number( aRowId + 1 ) );
1083   anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled );
1084   myLocalPointView->setItem( aRowId, 0, anItem );
1085
1086   anItem = new QTableWidgetItem( QString::number( theX ) );
1087   anItem->setData( Qt::UserRole, theX );
1088   myLocalPointView->setItem( aRowId, 1, anItem );
1089
1090   anItem = new QTableWidgetItem( QString::number( theY ) );
1091   anItem->setData( Qt::UserRole, theY );
1092   myLocalPointView->setItem( aRowId, 2, anItem );
1093 }
1094
1095 void CurveCreator_Widget::getSelectedPonts( int theSectionId, QList<int>& thePoints )
1096 {
1097   float aPrevX, aPrevY;
1098   int aPntIndex;
1099   for ( int i = 0, aNb = myLocalPointView->rowCount(); i < aNb; i++ ) {
1100     aPrevX = myLocalPointView->item( i, 1 )->data( Qt::UserRole ).toDouble();
1101     aPrevY = myLocalPointView->item( i, 2 )->data( Qt::UserRole ).toDouble();
1102
1103     aPntIndex = findLocalPointIndex( theSectionId, aPrevX, aPrevY );
1104     if ( aPntIndex >= 0 )
1105       thePoints.append( aPntIndex );
1106   }
1107 }
1108
1109 void CurveCreator_Widget::setSelectedPonts( const int theSectionId, const QList<int>& thePoints )
1110 {
1111   OCCViewer_Viewer* anOCCViewer = getOCCViewer();
1112   if ( !anOCCViewer )
1113     return;
1114
1115   AIS_ListOfInteractive aListToSelect;
1116
1117   Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
1118   if ( !ic->HasOpenedContext() )
1119     return;
1120
1121   AIS_ListOfInteractive aDisplayedList;
1122   ic->DisplayedObjects( aDisplayedList );
1123   for ( AIS_ListIteratorOfListOfInteractive it( aDisplayedList ); it.More(); it.Next() )
1124   {
1125     Handle(AIS_InteractiveObject) anAIS = it.Value();
1126     if ( anAIS.IsNull() )
1127       continue;
1128     Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast( anAIS );
1129     if ( aPoint.IsNull() )
1130       continue;
1131
1132     TopoDS_Vertex aVertex = TopoDS::Vertex( aPoint->Vertex() );
1133
1134     if ( aVertex.IsNull() )
1135       continue;
1136
1137     gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
1138     int aPointIndex = findLocalPointIndex( theSectionId, aPnt.X(), aPnt.Y() );
1139     if ( thePoints.contains( aPointIndex ) )
1140       aListToSelect.Append( anAIS );
1141   }
1142
1143   anOCCViewer->setObjectsSelected( aListToSelect );
1144   updateLocalPointView();
1145 }