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"
28 #include <GEOMUtils.hxx>
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>
39 #include <BRep_Tool.hxx>
42 #include <AIS_ListOfInteractive.hxx>
43 #include <AIS_ListIteratorOfListOfInteractive.hxx>
44 #include <AIS_Shape.hxx>
45 #include <AIS_Point.hxx>
46 #include <SelectMgr_EntityOwner.hxx>
47 //#include <StdSelect_BRepOwner.hxx>
49 #include <QHBoxLayout>
50 #include <QVBoxLayout>
54 #include <QToolButton>
58 #include <QMouseEvent>
59 #include <QApplication>
60 #include <QTableWidget>
62 #define LOCAL_SELECTION_TOLERANCE 0.0001
64 CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
65 CurveCreator_ICurve *theCurve,
67 QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0)
69 myNewSectionEditor = new CurveCreator_NewSectionDlg( this );
70 myNewSectionEditor->hide();
71 connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()) );
72 connect( myNewSectionEditor, SIGNAL(modifySection()), this, SLOT(onModifySection()) );
73 connect( myNewSectionEditor, SIGNAL(cancelSection()), this, SLOT(onCancelSection()) );
75 QGroupBox* aSectionGroup = new QGroupBox(tr("Sections"),this);
77 mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup);
78 connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) );
79 connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) );
80 connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) );
82 myLocalPointView = new QTableWidget();
83 myLocalPointView->setVisible( false );
84 myLocalPointView->setColumnCount( 3 );
86 //aLabels << tr( "IDENTIFIER_LABEL" ) << tr( "X_POSITION_LBL" ) << tr( "Y_POSITION_LBL" );
87 aLabels << tr( "id" ) << tr( "X" ) << tr( "Y" );
88 myLocalPointView->setHorizontalHeaderLabels( aLabels );
89 connect( myLocalPointView, SIGNAL( cellChanged( int, int ) ),
90 this, SLOT( onLocalPointChanged( int, int ) ) );
92 QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup);
93 // QToolButton* anUndoBtn = new QToolButton(aTB);
95 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
96 QPixmap anUndoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_UNDO")));
97 QPixmap aRedoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_REDO")));
98 QPixmap aNewSectionPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_SECTION")));
99 QPixmap aNewPointPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_POINT")));
100 QPixmap anEditPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
101 QPixmap aDetectPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
102 QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
103 QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
104 QPixmap aRemovePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_DELETE")));
105 QPixmap aJoinPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_JOIN")));
106 QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP")));
107 QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN")));
109 QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"),
110 QKeySequence(Qt::ControlModifier|Qt::Key_Z) );
111 connect(anAct, SIGNAL(triggered()), this, SLOT(onUndo()) );
112 aTB->addAction(anAct);
114 anAct = createAction( REDO_ID, tr("REDO"), aRedoPixmap, tr("REDO_TLT"),
115 QKeySequence(Qt::ControlModifier|Qt::Key_Y) );
116 connect(anAct, SIGNAL(triggered()), this, SLOT(onRedo()) );
117 aTB->addAction(anAct);
121 anAct = createAction( NEW_SECTION_ID, tr("NEW_SECTION"), aNewSectionPixmap, tr("NEW_SECTION_TLT"),
122 QKeySequence(Qt::ControlModifier|Qt::Key_N) );
123 connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) );
124 aTB->addAction(anAct);
127 anAct = createAction( ADDITION_MODE_ID, tr("ADDITION_MODE"), aNewPointPixmap, tr("ADDITION_MODE_TLT"),
129 anAct->setCheckable(true);
130 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onAdditionMode(bool)) );
131 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
132 aTB->addAction(anAct);
134 anAct = createAction( MODIFICATION_MODE_ID, tr("MODIFICATION_MODE"), anEditPointsPixmap, tr("MODIFICATION_MODE_TLT"),
136 anAct->setCheckable(true);
137 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onModificationMode(bool)) );
138 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
139 aTB->addAction(anAct);
141 anAct = createAction( DETECTION_MODE_ID, tr("DETECTION_MODE"), aDetectPointsPixmap, tr("DETECTION_MODE_TLT"),
143 anAct->setCheckable(true);
144 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onDetectionMode(bool)) );
145 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
146 aTB->addAction(anAct);
148 anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), QPixmap(), tr("CLOSE_SECTIONS_TLT"),
149 QKeySequence(Qt::ControlModifier|Qt::Key_W) );
150 connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) );
152 anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), QPixmap(),
153 tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) );
154 connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) );
156 anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"),
157 aPolylinePixmap, tr("SET_POLYLINE_TLT"),
158 QKeySequence(Qt::ControlModifier|Qt::Key_E) );
159 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) );
161 anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), aSplinePixmap,
162 tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) );
163 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) );
165 anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemovePixmap, tr("REMOVE_TLT"),
166 QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) );
167 connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) );
168 aTB->addAction(anAct);
171 anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"),
172 QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) );
173 connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) );
174 aTB->addAction(anAct);
177 anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"),
178 QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) );
179 connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) );
181 anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), QPixmap(), tr("JOIN_ALL_TLT"),
182 QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) );
183 connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) );
185 QVBoxLayout* aSectLayout = new QVBoxLayout();
186 aSectLayout->setMargin( 5 );
187 aSectLayout->setSpacing( 5 );
188 aSectLayout->addWidget(aTB);
189 aSectLayout->addWidget(mySectionView);
190 aSectLayout->addWidget( myLocalPointView );
191 aSectionGroup->setLayout(aSectLayout);
192 QVBoxLayout* aLay = new QVBoxLayout();
193 aLay->setMargin( 0 );
194 aLay->setSpacing( 5 );
195 // aLay->addLayout(aNameLayout);
196 aLay->addWidget(aSectionGroup);
198 onSelectionChanged();
200 /*OCCViewer_Viewer* anOCCViewer = getOCCViewer();
202 OCCViewer_ViewWindow* aWnd = dynamic_cast<OCCViewer_ViewWindow*>(anOCCViewer->getViewManager()->getActiveView());
204 aWnd->installEventFilter( this );
208 //=======================================================================
209 // function: getUniqSectionName
210 // purpose: return unique section name
211 //=======================================================================
212 OCCViewer_Viewer* CurveCreator_Widget::getOCCViewer()
214 OCCViewer_Viewer* anOCCViewer = 0;
216 OCCViewer_ViewWindow* aViewWindow = 0;
217 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
219 aViewWindow = dynamic_cast<OCCViewer_ViewWindow*>(SUIT_Session::session()->activeApplication()->desktop()->activeWindow());
220 if ( aViewWindow == 0 )
222 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>(aViewWindow->getViewManager());
223 if ( aViewManager == 0 )
226 anOCCViewer = aViewManager->getOCCViewer();
231 \brief Customize event handling
232 \param watched event receiver object
234 \return \c true if the event processing should be stopped
236 /*bool CurveCreator_Widget::eventFilter( QObject* theWatched, QEvent* theEvent )
238 OCCViewer_Viewer* anOCCViewer = getOCCViewer();
239 Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext();
240 bool isLocalContext = aContext->HasOpenedContext();
241 if ( !isLocalContext )
242 return QWidget::eventFilter( theWatched, theEvent );
244 bool isProcessed = true;
249 //=======================================================================
250 // function: getUniqSectionName
251 // purpose: return unique section name
252 //=======================================================================
253 std::string CurveCreator_Widget::getUniqSectionName( CurveCreator_ICurve* theCurve ) const
255 for( int i = 0 ; i < 1000000 ; i++ ){
257 sprintf( aBuffer, "Section_%d", i+1 );
258 std::string aName(aBuffer);
260 for( j = 0 ; j < theCurve->getNbSections() ; j++ ){
261 if( theCurve->getSectionName(j) == aName )
264 if( j == theCurve->getNbSections() )
270 void CurveCreator_Widget::setCurve( CurveCreator_ICurve* theCurve )
273 mySectionView->setCurve(myCurve);
274 onSelectionChanged();
278 void CurveCreator_Widget::onSelectionChanged()
280 QList<ActionId> anEnabledAct;
282 anEnabledAct << NEW_SECTION_ID;
283 QList<int> aSelSections = mySectionView->getSelectedSections();
284 QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints();
285 CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
287 case CurveCreator_TreeView::ST_NOSEL:{
290 case CurveCreator_TreeView::ST_SECTIONS:{
291 /*if( aSelSections[0] > 0 ){
292 anEnabledAct << UP_ID;
294 if( aSelSections.size() == 1 ){
295 anEnabledAct << ADDITION_MODE_ID << MODIFICATION_MODE_ID << DETECTION_MODE_ID;
297 if (myActionMap[ADDITION_MODE_ID]->isChecked()) {
300 QList<int> aSelSection = mySectionView->getSelectedSections();
301 if( aSelSection.size() > 0 ){
302 mySection = aSelSection[0];
303 myPointNum = myCurve->getNbPoints(mySection);
305 } else if (myActionMap[MODIFICATION_MODE_ID]->isChecked()) {
306 anEnabledAct << REMOVE_ID;
307 anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID;
308 int aSectCnt = myCurve->getNbSections();
310 anEnabledAct << CLEAR_ALL_ID;
312 anEnabledAct << JOIN_ALL_ID;
313 if( aSelSections.size() > 1 ){
314 anEnabledAct << JOIN_ID;
316 } else if (myActionMap[DETECTION_MODE_ID]->isChecked()) {
317 } else { //no active mode
319 /*if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){
320 anEnabledAct << DOWN_ID;
324 /*case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{
325 if( aSelPoints[0].second > 0 ){
326 anEnabledAct << UP_ID;
328 int aLastIndex = aSelPoints.size()-1;
329 int aSect = aSelPoints[0].first;
330 if( aSelPoints[aLastIndex].second < (myCurve->getNbPoints(aSect) - 1)){
331 anEnabledAct << DOWN_ID;
333 if( aSelPoints.size() == 1){
334 anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID;
341 /*int aSelObjsCnt = aSelPoints.size() + aSelSections.size();
342 if( aSelObjsCnt > 0 ){
343 anEnabledAct << REMOVE_ID;
345 if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){
346 anEnabledAct << REMOVE_ALL_ID;
348 if( myCurve->getNbSections() > 1 ){
349 anEnabledAct << JOIN_ALL_ID;
352 QList<ActionId> anIds = myActionMap.keys();
353 for( int i = 0 ; i < anIds.size() ; i++ ){
354 if( myActionMap.contains(anIds[i]) ){
355 if( anEnabledAct.contains(anIds[i]) ){
356 myActionMap[anIds[i]]->setEnabled(true);
359 myActionMap[anIds[i]]->setEnabled(false);
363 emit selectionChanged();
366 void CurveCreator_Widget::onAdditionMode(bool checked)
370 OCCViewer_Viewer* anOCCViewer = getOCCViewer();
371 Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext();
372 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
373 (anOCCViewer->getViewManager());
374 // if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) {
377 /* myGuiState = aViewWindow->saveState();
378 anOCCViewer->enableMultiselection(false);
379 anOCCViewer->enableSelection(false);*/
380 connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
381 this, SLOT( onGetCoordsByClick( SUIT_ViewWindow*, QMouseEvent* ) ) );
383 disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
384 this, SLOT( onGetCoordsByClick( SUIT_ViewWindow*, QMouseEvent* ) ) );
385 /* anOCCViewer->enableMultiselection(true);
386 anOCCViewer->enableSelection(true);
387 aViewWindow->restoreState( myGuiState );*/
394 QList<int> aSelSection = mySectionView->getSelectedSections();
395 if( aSelSection.size() > 0 ){
396 mySection = aSelSection[0];
399 QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
400 if( aSelPoints.size() > 0 ){
401 mySection = aSelPoints[0].first;
402 myPointNum = aSelPoints[0].second + 1;
405 // emit subOperationStarted( myNewPointEditor );
408 void CurveCreator_Widget::onModificationMode(bool checked)
410 myLocalPointView->setVisible( checked );
411 OCCViewer_Viewer* anOCCViewer = getOCCViewer();
412 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
413 (anOCCViewer->getViewManager());
415 SUIT_ViewWindow* aViewWindow = 0;
416 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
418 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
419 if ( aViewWindow == 0 )
421 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();*/
422 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) {
424 connect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
425 this, SLOT( onPointSelect( SUIT_ViewWindow*, QMouseEvent* ) ) );
426 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
427 this, SLOT( onPointDrag( SUIT_ViewWindow*, QMouseEvent* ) ) );
430 disconnect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
431 this, SLOT( onPointSelect( SUIT_ViewWindow*, QMouseEvent* ) ) );
432 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
433 this, SLOT( onPointDrag( SUIT_ViewWindow*, QMouseEvent* ) ) );
437 //NDS OCCViewer_ViewWindow* anOCCWnd = dynamic_cast<OCCViewer_ViewWindow*>(aViewWindow);
438 //anOCCWnd->activateStartPointSelection();
439 // activate selection ------>
440 //OCCViewer_Viewer* anOCCViewer = dynamic_cast<OCCViewer_Viewer*>(aViewManager->getViewModel());
442 setLocalPointContext( true );
445 void CurveCreator_Widget::onDetectionMode(bool checked)
449 void CurveCreator_Widget::onModeChanged(bool checked)
451 setLocalPointContext( false );
453 QAction* anAction = (QAction*)sender();
454 switch(myActionMap.key(anAction)) {
455 case ADDITION_MODE_ID:
456 if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
457 myActionMap[MODIFICATION_MODE_ID]->trigger();
458 else if (myActionMap[DETECTION_MODE_ID]->isChecked())
459 myActionMap[DETECTION_MODE_ID]->trigger();
461 case MODIFICATION_MODE_ID:
462 if (myActionMap[ADDITION_MODE_ID]->isChecked())
463 myActionMap[ADDITION_MODE_ID]->trigger();
464 else if (myActionMap[DETECTION_MODE_ID]->isChecked())
465 myActionMap[DETECTION_MODE_ID]->trigger();
467 case DETECTION_MODE_ID:
468 if (myActionMap[ADDITION_MODE_ID]->isChecked())
469 myActionMap[ADDITION_MODE_ID]->trigger();
470 else if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
471 myActionMap[MODIFICATION_MODE_ID]->trigger();
475 onSelectionChanged();
478 void CurveCreator_Widget::onAddNewPoint(const CurveCreator::Coordinates& theCoords)
482 myCurve->addPoints(theCoords, mySection, myPointNum );
483 mySectionView->pointsAdded( mySection, myPointNum );
485 onSelectionChanged();
489 void CurveCreator_Widget::onNewSection()
493 myNewSectionEditor->clear();
494 myNewSectionEditor->setEditMode(false);
495 QString aSectName = QString( getUniqSectionName(myCurve).c_str() );
496 myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline );
497 emit subOperationStarted( myNewSectionEditor );
500 void CurveCreator_Widget::onAddNewSection()
504 myCurve->addSection( myNewSectionEditor->getName().toStdString(), myNewSectionEditor->getSectionType(),
505 myNewSectionEditor->isClosed() );
506 mySectionView->sectionAdded( -1 ); // add a new section to the end of list
507 QString aNewName = QString(getUniqSectionName(myCurve).c_str());
508 myNewSectionEditor->setSectionName(aNewName);
509 onSelectionChanged();
514 void CurveCreator_Widget::onCancelSection()
516 emit subOperationFinished( myNewSectionEditor );
519 QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
520 const QString& theToolTip, const QKeySequence& theShortcut )
522 QAction* anAct = new QAction(theName,this);
523 if( !theImage.isNull() ){
524 anAct->setIcon(theImage);
526 anAct->setShortcut(theShortcut);
527 anAct->setToolTip(theToolTip);
528 myActionMap[theId] = anAct;
532 QAction* CurveCreator_Widget::getAction(ActionId theId)
534 if( myActionMap.contains(theId) )
535 return myActionMap[theId];
539 void CurveCreator_Widget::onEditSection( int theSection )
543 mySection = theSection;
544 QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
545 bool isClosed = myCurve->isClosed(theSection);
546 CurveCreator::SectionType aType = myCurve->getSectionType(theSection);
547 myNewSectionEditor->setEditMode(true);
548 myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType );
550 emit subOperationStarted( myNewSectionEditor );
553 void CurveCreator_Widget::onModifySection()
557 QString aName = myNewSectionEditor->getName();
558 bool isClosed = myNewSectionEditor->isClosed();
559 CurveCreator::SectionType aSectType = myNewSectionEditor->getSectionType();
560 // myCurve->startOperation();
561 myCurve->setClosed( isClosed, mySection );
562 myCurve->setSectionName( mySection , aName.toStdString() );
563 myCurve->setSectionType( mySection, aSectType );
564 // myCurve->finishOperation();
565 mySectionView->sectionChanged(mySection);
570 /*void CurveCreator_Widget::onEditPoint( int theSection, int thePoint )
572 if( !myNewPointEditor || !myEdit )
574 mySection = theSection;
575 myPointNum = thePoint;
576 QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
577 myNewPointEditor->setEditMode(true);
578 myNewPointEditor->setSectionName(aSectName);
579 myNewPointEditor->setDimension( myCurve->getDimension() );
580 CurveCreator::Coordinates aCoords = myCurve->getCoordinates(theSection,thePoint);
581 myNewPointEditor->setCoordinates(aCoords);
582 emit subOperationStarted( myNewPointEditor );
585 void CurveCreator_Widget::onModifyPoint()
589 CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates();
590 myEdit->setCoordinates( aCoords, mySection, myPointNum );
591 mySectionView->pointDataChanged( mySection, myPointNum );
596 void CurveCreator_Widget::onJoin()
600 QList<int> aSections = mySectionView->getSelectedSections();
601 if( aSections.size() == 0 ){
604 int aMainSect = aSections[0];
605 int aMainSectSize = myCurve->getNbPoints(aMainSect);
606 // myCurve->startOperation();
607 for( int i = 1 ; i < aSections.size() ; i++ ){
608 int aSectNum = aSections[i] - (i-1);
609 myCurve->join( aMainSect, aSectNum );
610 mySectionView->sectionsRemoved( aSectNum );
612 // myCurve->finishOperation();
613 int aNewSectSize = myCurve->getNbPoints(aMainSect);
614 if( aNewSectSize != aMainSectSize )
615 mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );
619 void CurveCreator_Widget::onRemove()
623 QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
626 // myCurve->startOperation();
627 for( int i = 0 ; i < aSelPoints.size() ; i++ ){
628 if( aCurrSect != aSelPoints[i].first ){
630 aCurrSect = aSelPoints[i].first;
632 int aPntIndx = aSelPoints[i].second - aRemoveCnt;
633 myCurve->removePoint( aCurrSect, aPntIndx );
634 mySectionView->pointsRemoved( aCurrSect, aPntIndx );
637 QList<int> aSections = mySectionView->getSelectedSections();
638 for( int i = 0 ; i < aSections.size() ; i++ ){
639 int aSectNum = aSections[i] - (i);
640 myCurve->removeSection( aSectNum );
641 mySectionView->sectionsRemoved( aSectNum );
643 // myCurve->finishOperation();
644 mySectionView->clearSelection();
648 void CurveCreator_Widget::onClearAll()
653 mySectionView->reset();
654 onSelectionChanged();
658 void CurveCreator_Widget::onJoinAll()
663 mySectionView->reset();
664 onSelectionChanged();
668 void CurveCreator_Widget::onUndoSettings()
673 void CurveCreator_Widget::onSetSpline()
677 QList<int> aSelSections = mySectionView->getSelectedSections();
678 // myCurve->startOperation();
679 for( int i = 0 ; i < aSelSections.size() ; i++ ){
680 myCurve->setSectionType(aSelSections[i], CurveCreator::Spline );
681 mySectionView->sectionChanged(aSelSections[i]);
683 // myCurve->finishOperation();
687 void CurveCreator_Widget::onSetPolyline()
691 // myCurve->startOperation();
692 QList<int> aSelSections = mySectionView->getSelectedSections();
693 for( int i = 0 ; i < aSelSections.size() ; i++ ){
694 myCurve->setSectionType( aSelSections[i], CurveCreator::Polyline );
695 mySectionView->sectionChanged( aSelSections[i] );
697 // myCurve->finishOperation();
701 void CurveCreator_Widget::onCloseSections()
705 // myCurve->startOperation();
706 QList<int> aSelSections = mySectionView->getSelectedSections();
707 for( int i = 0 ; i < aSelSections.size() ; i++ ){
708 myCurve->setClosed(true, aSelSections[i]);
709 mySectionView->sectionChanged(aSelSections[i]);
711 // myCurve->finishOperation();
715 void CurveCreator_Widget::onUncloseSections()
719 // myCurve->startOperation();
720 QList<int> aSelSections = mySectionView->getSelectedSections();
721 for( int i = 0 ; i < aSelSections.size() ; i++ ){
722 myCurve->setClosed(false, aSelSections[i]);
723 mySectionView->sectionChanged(aSelSections[i]);
725 // myCurve->finishOperation();
729 void CurveCreator_Widget::onUndo()
734 mySectionView->reset();
738 void CurveCreator_Widget::onRedo()
743 mySectionView->reset();
747 void CurveCreator_Widget::updateUndoRedo()
749 QAction* anAct = myActionMap[UNDO_ID];
751 if( myCurve->getNbUndo() != 0 ){
752 anAct->setEnabled(true);
755 anAct->setDisabled(true);
758 anAct = myActionMap[REDO_ID];
760 if( myCurve->getNbRedo() != 0 ){
761 anAct->setEnabled(true);
764 anAct->setDisabled(true);
769 void CurveCreator_Widget::onContextMenu( QPoint thePoint )
771 QList<ActionId> aContextActions;
772 aContextActions << CLEAR_ALL_ID << JOIN_ALL_ID << SEPARATOR_ID <<
773 CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID <<
774 SET_SECTIONS_SPLINE_ID;
775 QPoint aGlPoint = mySectionView->mapToGlobal(thePoint);
777 QList<ActionId> aResAct;
778 for( int i = 0 ; i < aContextActions.size() ; i++ ){
779 if( aContextActions[i] != SEPARATOR_ID ){
780 if( myActionMap.contains(aContextActions[i]) ){
781 QAction* anAct = myActionMap[aContextActions[i]];
782 if( anAct->isEnabled() ){
783 aResAct << aContextActions[i];
789 aResAct << SEPARATOR_ID;
795 QMenu* aMenu = new QMenu(this);
796 for( int i = 0 ; i < aResAct.size() ; i++ ){
797 if( aResAct[i] == SEPARATOR_ID ){
798 aMenu->addSeparator();
801 QAction* anAct = myActionMap[aResAct[i]];
802 aMenu->insertAction(NULL, anAct);
805 aMenu->exec(aGlPoint);
808 QList<int> CurveCreator_Widget::getSelectedSections()
810 return mySectionView->getSelectedSections();
813 QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints()
815 return mySectionView->getSelectedPoints();
818 //=================================================================================
819 // function : GeometryGUI::onGetCoordsByClick()
820 // purpose : Manage mouse press events in Additon mode
821 //=================================================================================
822 void CurveCreator_Widget::onGetCoordsByClick( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe )
824 if (pe->button() != Qt::LeftButton)
827 if ( theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
828 pe->modifiers() != Qt::ControlModifier ) {
829 OCCViewer_Viewer* anOCCViewer =
830 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
831 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
836 if ( pe->modifiers() == Qt::ShiftModifier )
837 ic->ShiftSelect(); // Append selection
839 ic->Select(); // New selection
841 /*TopoDS_Shape aShape;
844 if ( ic->MoreSelected() )
845 aShape = ic->SelectedShape();
847 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
848 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
851 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
852 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
854 // set the coordinates into dialog
855 CurveCreator::Coordinates aCoords;
856 aCoords.push_back( aPnt.X() );
857 aCoords.push_back( aPnt.Y() );
858 if ( myCurve->getDimension() == 3 ) {
859 aCoords.push_back( aPnt.Z() );
861 onAddNewPoint(aCoords);
862 // myNewPointEditor->setCoordinates( aCoords );
866 //=================================================================================
867 // function : HYDROGUI_PolylineOp::onPointSelect()
868 // purpose : Manage mouse press events in Modification mode
869 //=================================================================================
870 void CurveCreator_Widget::onPointSelect( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe )
872 //store initial cursor position for Drag&Drop
873 if (pe->button() == Qt::LeftButton)
874 myDragStartPosition = pe->pos();
877 OCCViewer_Viewer* anOCCViewer =
878 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
879 Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext();
881 //ic->InitSelected();
882 //if ( pe->modifiers() == Qt::ShiftModifier )
883 // ic->ShiftSelect(); // Append selection
885 // ic->Select(); // New selection
887 /*ic->InitSelected();
888 if ( ic->MoreSelected() ) {
889 TopoDS_Shape aShape = ic->SelectedShape();
890 Standard_Boolean hasdet = ic->HasDetectedShape();
891 Standard_Boolean hassel = ic->HasSelectedShape();
892 Standard_Integer nbcur = ic->NbCurrents();
893 Standard_Integer nbsel = ic->NbSelected();
895 if ( aShape.ShapeType() == TopAbs_VERTEX )
896 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
899 Qt::KeyboardModifiers modifiers = pe->modifiers();
900 // aSketcherDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog*/
902 updateLocalPointView();
905 //=================================================================================
906 // function : GeometryGUI::onPointDrag()
907 // purpose : Manage mouse move events in Modification mode
908 //=================================================================================
909 void CurveCreator_Widget::onPointDrag( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe )
911 if ( !(pe->buttons() & Qt::LeftButton) )
913 if ( (pe->pos() - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() )
916 QDrag *drag = new QDrag(this);
917 QMimeData *mimeData = new QMimeData;
919 mimeData->setData(mimeType, data);
920 drag->setMimeData(mimeData);
922 Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
926 void CurveCreator_Widget::onLocalPointChanged( int theRow, int theColumn )
928 setLocalPointContext( false );
930 QList<int> aSelSections = mySectionView->getSelectedSections();
934 std::deque<float> aChangedPos;
935 float aPrevX, aPrevY, aX, anY;
936 for( int i = 0 ; i < aSelSections.size() ; i++ ){
937 aCurrSect = aSelSections[i];
939 aPrevX = myLocalPointView->item( theRow, 1 )->data( Qt::UserRole ).toDouble();
940 aPrevY = myLocalPointView->item( theRow, 2 )->data( Qt::UserRole ).toDouble();
942 aPntIndex = findLocalPointIndex( aCurrSect, aPrevX, aPrevY );
946 aX = myLocalPointView->item( theRow, 1 )->text().toDouble();
947 anY = myLocalPointView->item( theRow, 2 )->text().toDouble();
949 aChangedPos.push_back( aX );
950 aChangedPos.push_back( anY );
951 myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos );
953 updateLocalPointView();
955 setLocalPointContext( true );
958 int CurveCreator_Widget::findLocalPointIndex( int theSectionId, float theX, float theY )
962 CurveCreator::Coordinates aCoords;
963 for ( int i = 0, aNb = myCurve->getNbPoints( theSectionId ); i < aNb && aPntIndex < 0; i++ ) {
964 aCoords = myCurve->getPoint( theSectionId, i );
965 if ( aCoords.size() < 2 )
967 if ( fabs( aCoords[0] - theX ) < LOCAL_SELECTION_TOLERANCE &&
968 fabs( aCoords[1] - theY ) < LOCAL_SELECTION_TOLERANCE )
975 void CurveCreator_Widget::updateLocalPointView()
977 OCCViewer_Viewer* anOCCViewer = getOCCViewer();
980 Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext();
982 bool isBlocked = myLocalPointView->blockSignals(true);
984 myLocalPointView->setRowCount( 0 );
985 for ( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() ) {
986 TopoDS_Vertex aVertex;
987 TopoDS_Shape aShape = aContext->SelectedShape();
988 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
989 aVertex = TopoDS::Vertex( aContext->SelectedShape() );
991 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
992 if ( !anOwner.IsNull() ) {
993 Handle(AIS_InteractiveObject) anAIS = Handle(AIS_InteractiveObject)::DownCast( anOwner->Selectable() );
994 if ( !anAIS.IsNull() ) {
995 Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast( anAIS);
996 if ( !aPoint.IsNull() )
997 aVertex = TopoDS::Vertex( aPoint->Vertex() );
999 if ( aVertex.IsNull() ) {
1000 // the following happens if there are no points in the current curve, there is only a shape
1001 /*Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
1002 if ( aBrepOwner.IsNull() )
1004 if ( aBrepOwner->HasShape() ) {
1005 const TopoDS_Shape& aShape = aBrepOwner->Shape();
1006 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
1008 aVertex = TopoDS::Vertex( aShape );
1013 if ( aVertex.IsNull() )
1015 aPnt = BRep_Tool::Pnt( aVertex );
1016 addLocalPointToTable( aPnt.X(), aPnt.Y() );
1019 myLocalPointView->blockSignals(isBlocked);
1022 void CurveCreator_Widget::setLocalPointContext( const bool theOpen )
1024 OCCViewer_Viewer* anOCCViewer = getOCCViewer();
1025 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
1028 // Open local context if there is no one
1029 bool allObjects = true;
1030 if ( !ic->HasOpenedContext() ) {
1031 ic->ClearCurrents( false );
1032 ic->OpenLocalContext( allObjects, true, true );
1034 AIS_ListOfInteractive aList;
1035 ic->DisplayedObjects( aList );
1037 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
1040 int theMode = TopAbs_VERTEX;
1041 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
1043 Handle(AIS_InteractiveObject) anAIS = it.Value();
1044 if ( !anAIS.IsNull() )
1046 if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) )
1048 ic->Load( anAIS, -1, false );
1049 ic->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)theMode ) );
1051 else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) )
1053 ic->Load( anAIS, -1, false );
1054 ic->Activate( anAIS, theMode );
1061 ic->CloseAllContexts();
1065 void CurveCreator_Widget::addLocalPointToTable( const double theX, const double theY )
1067 int aRowId = myLocalPointView->rowCount();
1068 double aCurrentX, aCurrentY;
1069 for ( int i = 0; i < aRowId; i++ ) {
1070 aCurrentX = myLocalPointView->item( i, 1 )->data( Qt::UserRole ).toDouble();
1071 aCurrentY = myLocalPointView->item( i, 2 )->data( Qt::UserRole ).toDouble();
1072 if ( fabs( aCurrentX - theX ) < LOCAL_SELECTION_TOLERANCE &&
1073 fabs( aCurrentY - theY ) < LOCAL_SELECTION_TOLERANCE )
1076 QTableWidgetItem* anItem;
1078 myLocalPointView->setRowCount( aRowId+1 );
1079 myLocalPointView->setItem( aRowId, 0, new QTableWidgetItem( QString::number( aRowId + 1 ) ) );
1081 anItem = new QTableWidgetItem( QString::number( theX ) );
1082 anItem->setData( Qt::UserRole, theX );
1083 myLocalPointView->setItem( aRowId, 1, anItem );
1085 anItem = new QTableWidgetItem( QString::number( theY ) );
1086 anItem->setData( Qt::UserRole, theY );
1087 myLocalPointView->setItem( aRowId, 2, anItem );