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 <StdSelect_BRepOwner.hxx>
48 #include <QHBoxLayout>
49 #include <QVBoxLayout>
53 #include <QToolButton>
57 #include <QMouseEvent>
58 #include <QApplication>
59 #include <QTableWidget>
61 #define LOCAL_SELECTION_TOLERANCE 0.0001
63 CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
64 CurveCreator_ICurve *theCurve,
66 QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0)
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()) );
74 QGroupBox* aSectionGroup = new QGroupBox(tr("Sections"),this);
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)) );
81 myLocalPointView = new QTableWidget();
82 myLocalPointView->setVisible( false );
83 myLocalPointView->setColumnCount( 3 );
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 ) ) );
91 QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup);
92 // QToolButton* anUndoBtn = new QToolButton(aTB);
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")));
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);
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);
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);
126 anAct = createAction( ADDITION_MODE_ID, tr("ADDITION_MODE"), aNewPointPixmap, tr("ADDITION_MODE_TLT"),
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);
133 anAct = createAction( MODIFICATION_MODE_ID, tr("MODIFICATION_MODE"), anEditPointsPixmap, tr("MODIFICATION_MODE_TLT"),
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);
140 anAct = createAction( DETECTION_MODE_ID, tr("DETECTION_MODE"), aDetectPointsPixmap, tr("DETECTION_MODE_TLT"),
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);
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()) );
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()) );
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()) );
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()) );
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);
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);
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()) );
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()) );
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);
197 onSelectionChanged();
199 /*OCCViewer_Viewer* anOCCViewer = getOCCViewer();
201 OCCViewer_ViewWindow* aWnd = dynamic_cast<OCCViewer_ViewWindow*>(anOCCViewer->getViewManager()->getActiveView());
203 aWnd->installEventFilter( this );
207 //=======================================================================
208 // function: getUniqSectionName
209 // purpose: return unique section name
210 //=======================================================================
211 OCCViewer_Viewer* CurveCreator_Widget::getOCCViewer()
213 OCCViewer_Viewer* anOCCViewer = 0;
215 OCCViewer_ViewWindow* aViewWindow = 0;
216 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
218 aViewWindow = dynamic_cast<OCCViewer_ViewWindow*>(SUIT_Session::session()->activeApplication()->desktop()->activeWindow());
219 if ( aViewWindow == 0 )
221 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>(aViewWindow->getViewManager());
222 if ( aViewManager == 0 )
225 anOCCViewer = aViewManager->getOCCViewer();
230 \brief Customize event handling
231 \param watched event receiver object
233 \return \c true if the event processing should be stopped
235 /*bool CurveCreator_Widget::eventFilter( QObject* theWatched, QEvent* theEvent )
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 );
243 bool isProcessed = true;
248 //=======================================================================
249 // function: getUniqSectionName
250 // purpose: return unique section name
251 //=======================================================================
252 std::string CurveCreator_Widget::getUniqSectionName( CurveCreator_ICurve* theCurve ) const
254 for( int i = 0 ; i < 1000000 ; i++ ){
256 sprintf( aBuffer, "Section_%d", i+1 );
257 std::string aName(aBuffer);
259 for( j = 0 ; j < theCurve->getNbSections() ; j++ ){
260 if( theCurve->getSectionName(j) == aName )
263 if( j == theCurve->getNbSections() )
269 void CurveCreator_Widget::setCurve( CurveCreator_ICurve* theCurve )
272 mySectionView->setCurve(myCurve);
273 onSelectionChanged();
277 void CurveCreator_Widget::onSelectionChanged()
279 QList<ActionId> anEnabledAct;
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();
286 case CurveCreator_TreeView::ST_NOSEL:{
289 case CurveCreator_TreeView::ST_SECTIONS:{
290 /*if( aSelSections[0] > 0 ){
291 anEnabledAct << UP_ID;
293 if( aSelSections.size() == 1 ){
294 anEnabledAct << ADDITION_MODE_ID << MODIFICATION_MODE_ID << DETECTION_MODE_ID;
296 if (myActionMap[ADDITION_MODE_ID]->isChecked()) {
299 QList<int> aSelSection = mySectionView->getSelectedSections();
300 if( aSelSection.size() > 0 ){
301 mySection = aSelSection[0];
302 myPointNum = myCurve->getNbPoints(mySection);
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();
309 anEnabledAct << CLEAR_ALL_ID;
311 anEnabledAct << JOIN_ALL_ID;
312 if( aSelSections.size() > 1 ){
313 anEnabledAct << JOIN_ID;
315 } else if (myActionMap[DETECTION_MODE_ID]->isChecked()) {
316 } else { //no active mode
318 /*if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){
319 anEnabledAct << DOWN_ID;
323 /*case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{
324 if( aSelPoints[0].second > 0 ){
325 anEnabledAct << UP_ID;
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;
332 if( aSelPoints.size() == 1){
333 anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID;
340 /*int aSelObjsCnt = aSelPoints.size() + aSelSections.size();
341 if( aSelObjsCnt > 0 ){
342 anEnabledAct << REMOVE_ID;
344 if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){
345 anEnabledAct << REMOVE_ALL_ID;
347 if( myCurve->getNbSections() > 1 ){
348 anEnabledAct << JOIN_ALL_ID;
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);
358 myActionMap[anIds[i]]->setEnabled(false);
362 emit selectionChanged();
365 void CurveCreator_Widget::onAdditionMode(bool checked)
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() ) {
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* ) ) );
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 );*/
393 QList<int> aSelSection = mySectionView->getSelectedSections();
394 if( aSelSection.size() > 0 ){
395 mySection = aSelSection[0];
398 QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
399 if( aSelPoints.size() > 0 ){
400 mySection = aSelPoints[0].first;
401 myPointNum = aSelPoints[0].second + 1;
404 // emit subOperationStarted( myNewPointEditor );
407 void CurveCreator_Widget::onModificationMode(bool checked)
409 myLocalPointView->setVisible( checked );
410 OCCViewer_Viewer* anOCCViewer = getOCCViewer();
411 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
412 (anOCCViewer->getViewManager());
414 SUIT_ViewWindow* aViewWindow = 0;
415 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
417 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
418 if ( aViewWindow == 0 )
420 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();*/
421 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) {
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* ) ) );
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* ) ) );
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());
441 setLocalPointContext( true );
444 void CurveCreator_Widget::onDetectionMode(bool checked)
448 void CurveCreator_Widget::onModeChanged(bool checked)
450 setLocalPointContext( false );
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();
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();
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();
474 onSelectionChanged();
477 void CurveCreator_Widget::onAddNewPoint(const CurveCreator::Coordinates& theCoords)
481 myCurve->addPoints(theCoords, mySection, myPointNum );
482 mySectionView->pointsAdded( mySection, myPointNum );
484 onSelectionChanged();
488 void CurveCreator_Widget::onNewSection()
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 );
499 void CurveCreator_Widget::onAddNewSection()
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();
513 void CurveCreator_Widget::onCancelSection()
515 emit subOperationFinished( myNewSectionEditor );
518 QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
519 const QString& theToolTip, const QKeySequence& theShortcut )
521 QAction* anAct = new QAction(theName,this);
522 if( !theImage.isNull() ){
523 anAct->setIcon(theImage);
525 anAct->setShortcut(theShortcut);
526 anAct->setToolTip(theToolTip);
527 myActionMap[theId] = anAct;
531 QAction* CurveCreator_Widget::getAction(ActionId theId)
533 if( myActionMap.contains(theId) )
534 return myActionMap[theId];
538 void CurveCreator_Widget::onEditSection( int theSection )
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 );
549 emit subOperationStarted( myNewSectionEditor );
552 void CurveCreator_Widget::onModifySection()
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);
569 /*void CurveCreator_Widget::onEditPoint( int theSection, int thePoint )
571 if( !myNewPointEditor || !myEdit )
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 );
584 void CurveCreator_Widget::onModifyPoint()
588 CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates();
589 myEdit->setCoordinates( aCoords, mySection, myPointNum );
590 mySectionView->pointDataChanged( mySection, myPointNum );
595 void CurveCreator_Widget::onJoin()
599 QList<int> aSections = mySectionView->getSelectedSections();
600 if( aSections.size() == 0 ){
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 );
611 // myCurve->finishOperation();
612 int aNewSectSize = myCurve->getNbPoints(aMainSect);
613 if( aNewSectSize != aMainSectSize )
614 mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );
618 void CurveCreator_Widget::onRemove()
622 QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
625 // myCurve->startOperation();
626 for( int i = 0 ; i < aSelPoints.size() ; i++ ){
627 if( aCurrSect != aSelPoints[i].first ){
629 aCurrSect = aSelPoints[i].first;
631 int aPntIndx = aSelPoints[i].second - aRemoveCnt;
632 myCurve->removePoint( aCurrSect, aPntIndx );
633 mySectionView->pointsRemoved( aCurrSect, aPntIndx );
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 );
642 // myCurve->finishOperation();
643 mySectionView->clearSelection();
647 void CurveCreator_Widget::onClearAll()
652 mySectionView->reset();
653 onSelectionChanged();
657 void CurveCreator_Widget::onJoinAll()
662 mySectionView->reset();
663 onSelectionChanged();
667 void CurveCreator_Widget::onUndoSettings()
672 void CurveCreator_Widget::onSetSpline()
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]);
682 // myCurve->finishOperation();
686 void CurveCreator_Widget::onSetPolyline()
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] );
696 // myCurve->finishOperation();
700 void CurveCreator_Widget::onCloseSections()
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]);
710 // myCurve->finishOperation();
714 void CurveCreator_Widget::onUncloseSections()
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]);
724 // myCurve->finishOperation();
728 void CurveCreator_Widget::onUndo()
733 mySectionView->reset();
737 void CurveCreator_Widget::onRedo()
742 mySectionView->reset();
746 void CurveCreator_Widget::updateUndoRedo()
748 QAction* anAct = myActionMap[UNDO_ID];
750 if( myCurve->getNbUndo() != 0 ){
751 anAct->setEnabled(true);
754 anAct->setDisabled(true);
757 anAct = myActionMap[REDO_ID];
759 if( myCurve->getNbRedo() != 0 ){
760 anAct->setEnabled(true);
763 anAct->setDisabled(true);
768 void CurveCreator_Widget::onContextMenu( QPoint thePoint )
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);
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];
788 aResAct << SEPARATOR_ID;
794 QMenu* aMenu = new QMenu(this);
795 for( int i = 0 ; i < aResAct.size() ; i++ ){
796 if( aResAct[i] == SEPARATOR_ID ){
797 aMenu->addSeparator();
800 QAction* anAct = myActionMap[aResAct[i]];
801 aMenu->insertAction(NULL, anAct);
804 aMenu->exec(aGlPoint);
807 QList<int> CurveCreator_Widget::getSelectedSections()
809 return mySectionView->getSelectedSections();
812 QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints()
814 return mySectionView->getSelectedPoints();
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 )
823 if (pe->button() != Qt::LeftButton)
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();
835 if ( pe->modifiers() == Qt::ShiftModifier )
836 ic->ShiftSelect(); // Append selection
838 ic->Select(); // New selection
840 /*TopoDS_Shape aShape;
843 if ( ic->MoreSelected() )
844 aShape = ic->SelectedShape();
846 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
847 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
850 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
851 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
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() );
860 onAddNewPoint(aCoords);
861 // myNewPointEditor->setCoordinates( aCoords );
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 )
871 //store initial cursor position for Drag&Drop
872 if (pe->button() == Qt::LeftButton)
873 myDragStartPosition = pe->pos();
876 OCCViewer_Viewer* anOCCViewer =
877 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
878 Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext();
880 //ic->InitSelected();
881 //if ( pe->modifiers() == Qt::ShiftModifier )
882 // ic->ShiftSelect(); // Append selection
884 // ic->Select(); // New selection
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();
894 if ( aShape.ShapeType() == TopAbs_VERTEX )
895 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
898 Qt::KeyboardModifiers modifiers = pe->modifiers();
899 // aSketcherDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog*/
901 updateLocalPointView();
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 )
910 if ( !(pe->buttons() & Qt::LeftButton) )
912 if ( (pe->pos() - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() )
915 QDrag *drag = new QDrag(this);
916 QMimeData *mimeData = new QMimeData;
918 mimeData->setData(mimeType, data);
919 drag->setMimeData(mimeData);
921 Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
925 void CurveCreator_Widget::onLocalPointChanged( int theRow, int theColumn )
927 QList<int> aSelSections = mySectionView->getSelectedSections();
928 if ( aSelSections.size() < 0 )
931 int aSection = aSelSections[0];
933 QList<int> aSelPoints;
934 getSelectedPonts( aSection, aSelPoints );
935 setLocalPointContext( false );
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];
944 aPrevX = myLocalPointView->item( theRow, 1 )->data( Qt::UserRole ).toDouble();
945 aPrevY = myLocalPointView->item( theRow, 2 )->data( Qt::UserRole ).toDouble();
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();
952 aChangedPos.push_back( aX );
953 aChangedPos.push_back( anY );
954 myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos );
957 setLocalPointContext( true );
958 setSelectedPonts( aSection, aSelPoints );
961 int CurveCreator_Widget::findLocalPointIndex( int theSectionId, float theX, float theY )
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 )
970 if ( fabs( aCoords[0] - theX ) < LOCAL_SELECTION_TOLERANCE &&
971 fabs( aCoords[1] - theY ) < LOCAL_SELECTION_TOLERANCE )
978 void CurveCreator_Widget::updateLocalPointView()
980 OCCViewer_Viewer* anOCCViewer = getOCCViewer();
983 Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext();
985 bool isBlocked = myLocalPointView->blockSignals(true);
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() );
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() );
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() )
1007 if ( aBrepOwner->HasShape() ) {
1008 const TopoDS_Shape& aShape = aBrepOwner->Shape();
1009 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
1011 aVertex = TopoDS::Vertex( aShape );
1016 if ( aVertex.IsNull() )
1018 aPnt = BRep_Tool::Pnt( aVertex );
1019 addLocalPointToTable( aPnt.X(), aPnt.Y() );
1022 myLocalPointView->blockSignals(isBlocked);
1025 void CurveCreator_Widget::setLocalPointContext( const bool theOpen )
1027 OCCViewer_Viewer* anOCCViewer = getOCCViewer();
1028 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
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 );
1037 AIS_ListOfInteractive aList;
1038 ic->DisplayedObjects( aList );
1040 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
1043 int theMode = TopAbs_VERTEX;
1044 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
1046 Handle(AIS_InteractiveObject) anAIS = it.Value();
1047 if ( !anAIS.IsNull() )
1049 if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) )
1051 ic->Load( anAIS, -1, false );
1052 ic->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)theMode ) );
1054 else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) )
1056 ic->Load( anAIS, -1, false );
1057 ic->Activate( anAIS, theMode );
1064 ic->CloseAllContexts();
1068 void CurveCreator_Widget::addLocalPointToTable( const double theX, const double theY )
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 )
1079 QTableWidgetItem* anItem;
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 );
1086 anItem = new QTableWidgetItem( QString::number( theX ) );
1087 anItem->setData( Qt::UserRole, theX );
1088 myLocalPointView->setItem( aRowId, 1, anItem );
1090 anItem = new QTableWidgetItem( QString::number( theY ) );
1091 anItem->setData( Qt::UserRole, theY );
1092 myLocalPointView->setItem( aRowId, 2, anItem );
1095 void CurveCreator_Widget::getSelectedPonts( int theSectionId, QList<int>& thePoints )
1097 float aPrevX, aPrevY;
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();
1103 aPntIndex = findLocalPointIndex( theSectionId, aPrevX, aPrevY );
1104 if ( aPntIndex >= 0 )
1105 thePoints.append( aPntIndex );
1109 void CurveCreator_Widget::setSelectedPonts( const int theSectionId, const QList<int>& thePoints )
1111 OCCViewer_Viewer* anOCCViewer = getOCCViewer();
1115 AIS_ListOfInteractive aListToSelect;
1117 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
1118 if ( !ic->HasOpenedContext() )
1121 AIS_ListOfInteractive aDisplayedList;
1122 ic->DisplayedObjects( aDisplayedList );
1123 for ( AIS_ListIteratorOfListOfInteractive it( aDisplayedList ); it.More(); it.Next() )
1125 Handle(AIS_InteractiveObject) anAIS = it.Value();
1126 if ( anAIS.IsNull() )
1128 Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast( anAIS );
1129 if ( aPoint.IsNull() )
1132 TopoDS_Vertex aVertex = TopoDS::Vertex( aPoint->Vertex() );
1134 if ( aVertex.IsNull() )
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 );
1143 anOCCViewer->setObjectsSelected( aListToSelect );
1144 updateLocalPointView();