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_Curve.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 <QHBoxLayout>
43 #include <QVBoxLayout>
47 #include <QToolButton>
51 #include <QMouseEvent>
52 #include <QApplication>
54 CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
55 CurveCreator_Curve *theCurve,
57 QWidget(parent), myNewPointEditor(NULL), myNewSectionEditor(NULL), myEdit(NULL), myCurve(theCurve)
60 myEdit = new CurveCreator_CurveEditor( myCurve );
62 CurveCreator::Dimension aDim = CurveCreator::Dim2d;
64 aDim = myCurve->getDimension();
65 myNewPointEditor = new CurveCreator_NewPointDlg( aDim, this );
66 myNewPointEditor->hide();
67 // connect( myNewPointEditor, SIGNAL(addPoint()), this, SLOT(onAddNewPoint()) );
68 connect( myNewPointEditor, SIGNAL(modifyPoint()), this, SLOT(onModifyPoint()) );
69 connect( myNewPointEditor, SIGNAL(cancelPoint()), this, SLOT(onCancelPoint()) );
71 myNewSectionEditor = new CurveCreator_NewSectionDlg( this );
72 myNewSectionEditor->hide();
73 connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()) );
74 connect( myNewSectionEditor, SIGNAL(modifySection()), this, SLOT(onModifySection()) );
75 connect( myNewSectionEditor, SIGNAL(cancelSection()), this, SLOT(onCancelSection()) );
77 QGroupBox* aSectionGroup = new QGroupBox(tr("Sections"),this);
79 mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup);
80 connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) );
81 connect( mySectionView, SIGNAL(pointEntered(int,int)), this, SLOT(onEditPoint(int,int)) );
82 connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) );
83 connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) );
84 QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup);
85 // QToolButton* anUndoBtn = new QToolButton(aTB);
87 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
88 QPixmap anUndoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_UNDO")));
89 QPixmap aRedoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_REDO")));
90 QPixmap aNewSectionPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_SECTION")));
91 QPixmap aNewPointPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_POINT")));
92 QPixmap anEditPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
93 QPixmap aDetectPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
94 QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
95 QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
96 QPixmap aRemovePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_DELETE")));
97 QPixmap aJoinPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_JOIN")));
98 QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP")));
99 QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN")));
101 /* QPixmap anUndoPixmap = QPixmap(tr(":images/ICON_UNDO"));
102 QPixmap aRedoPixmap = QPixmap(tr(":images/ICON_REDO"));
103 QPixmap aNewSectionPixmap = QPixmap(tr(":images/ICON_NEW_SECTION"));
104 QPixmap aNewPointPixmap = QPixmap(tr(":images/ICON_NEW_POINT"));
105 QPixmap aPolylinePixmap = QPixmap(tr(":images/ICON_POLYLINE"));
106 QPixmap aSplinePixmap = QPixmap(tr(":images/ICON_SPLINE"));
107 QPixmap aRemovePixmap = QPixmap(tr(":images/ICON_REMOVE"));
108 QPixmap aJoinPixmap = QPixmap(tr(":images/ICON_JOIN"));
109 QPixmap aStepUpPixmap = QPixmap(tr(":images/ICON_STEP_UP"));
110 QPixmap aStepDownPixmap = QPixmap(tr(":images/ICON_STEP_DOWN"));*/
112 QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"),
113 QKeySequence(Qt::ControlModifier|Qt::Key_Z) );
114 connect(anAct, SIGNAL(triggered()), this, SLOT(onUndo()) );
115 aTB->addAction(anAct);
117 anAct = createAction( REDO_ID, tr("REDO"), aRedoPixmap, tr("REDO_TLT"),
118 QKeySequence(Qt::ControlModifier|Qt::Key_Y) );
119 connect(anAct, SIGNAL(triggered()), this, SLOT(onRedo()) );
120 aTB->addAction(anAct);
124 anAct = createAction( NEW_SECTION_ID, tr("NEW_SECTION"), aNewSectionPixmap, tr("NEW_SECTION_TLT"),
125 QKeySequence(Qt::ControlModifier|Qt::Key_N) );
126 connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) );
127 aTB->addAction(anAct);
130 anAct = createAction( INSERT_SECTION_BEFORE_ID, tr("INSERT_SECTION_BEFORE"), QPixmap(),
131 tr("INSERT_SECTION_BEFORE_TLT"),
132 QKeySequence(Qt::ControlModifier | Qt::Key_Insert ) );
133 connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertSectionBefore()) );
135 anAct = createAction( INSERT_SECTION_AFTER_ID, tr("INSERT_SECTION_AFTER"), QPixmap(),
136 tr("INSERT_SECTION_AFTER_TLT"),
137 QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Insert ) );
138 connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertSectionAfter()) );
140 anAct = createAction( ADDITION_MODE_ID, tr("ADDITION_MODE"), aNewPointPixmap, tr("ADDITION_MODE_TLT"),
142 anAct->setCheckable(true);
143 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onAdditionMode(bool)) );
144 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
145 aTB->addAction(anAct);
147 anAct = createAction( MODIFICATION_MODE_ID, tr("MODIFICATION_MODE"), anEditPointsPixmap, tr("MODIFICATION_MODE_TLT"),
149 anAct->setCheckable(true);
150 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onModificationMode(bool)) );
151 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
152 aTB->addAction(anAct);
154 anAct = createAction( DETECTION_MODE_ID, tr("DETECTION_MODE"), aDetectPointsPixmap, tr("DETECTION_MODE_TLT"),
156 anAct->setCheckable(true);
157 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onDetectPoints(bool)) );
158 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
159 aTB->addAction(anAct);
161 anAct = createAction( INSERT_POINT_BEFORE_ID, tr("INSERT_POINT_BEFORE"), QPixmap(),
162 tr("INSERT_POINT_BEFORE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_B) );
163 connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertPointBefore()) );
165 anAct = createAction( INSERT_POINT_AFTER_ID, tr("INSERT_POINT_AFTER"), QPixmap(),
166 tr("INSERT_POINT_AFTER_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_M) );
167 connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertPointAfter()) );
169 anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), QPixmap(), tr("CLOSE_SECTIONS_TLT"),
170 QKeySequence(Qt::ControlModifier|Qt::Key_W) );
171 connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) );
173 anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), QPixmap(),
174 tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) );
175 connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) );
177 anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"),
178 aPolylinePixmap, tr("SET_POLYLINE_TLT"),
179 QKeySequence(Qt::ControlModifier|Qt::Key_E) );
180 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) );
182 anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), aSplinePixmap,
183 tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) );
184 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) );
186 anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemovePixmap, tr("REMOVE_TLT"),
187 QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) );
188 connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) );
189 aTB->addAction(anAct);
192 anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"),
193 QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) );
194 connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) );
195 aTB->addAction(anAct);
198 anAct = createAction( UP_ID, tr("STEP_UP"), aStepUpPixmap, tr("STEP_UP_TLT"),
199 QKeySequence(Qt::ControlModifier|Qt::Key_Up ) );
200 connect( anAct, SIGNAL(triggered()), this, SLOT(onMoveUp()) );
202 anAct = createAction( DOWN_ID, tr("STEP_DOWN"), aStepDownPixmap, tr("STEP_DOWN"),
203 QKeySequence(Qt::ControlModifier|Qt::Key_Down ) );
204 connect( anAct, SIGNAL(triggered()), this, SLOT(onMoveDown()) );
206 anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"),
207 QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) );
208 connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) );
210 anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), QPixmap(), tr("JOIN_ALL_TLT"),
211 QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) );
212 connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) );
214 QVBoxLayout* aSectLayout = new QVBoxLayout();
215 aSectLayout->setMargin( 5 );
216 aSectLayout->setSpacing( 5 );
217 aSectLayout->addWidget(aTB);
218 aSectLayout->addWidget(mySectionView);
219 aSectionGroup->setLayout(aSectLayout);
220 QVBoxLayout* aLay = new QVBoxLayout();
221 aLay->setMargin( 0 );
222 aLay->setSpacing( 5 );
223 // aLay->addLayout(aNameLayout);
224 aLay->addWidget(aSectionGroup);
226 onSelectionChanged();
229 void CurveCreator_Widget::setCurve( CurveCreator_Curve* theCurve )
231 if( myEdit != NULL ){
236 mySectionView->setCurve(myCurve);
237 if( myCurve != NULL ){
238 myEdit = new CurveCreator_CurveEditor(myCurve);
240 onSelectionChanged();
244 void CurveCreator_Widget::onSelectionChanged()
246 QList<ActionId> anEnabledAct;
248 anEnabledAct << NEW_SECTION_ID;
249 QList<int> aSelSections = mySectionView->getSelectedSections();
250 QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints();
251 CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
253 case CurveCreator_TreeView::ST_NOSEL:{
256 case CurveCreator_TreeView::ST_SECTIONS:{
257 /*if( aSelSections[0] > 0 ){
258 anEnabledAct << UP_ID;
260 if( aSelSections.size() == 1 ){
261 anEnabledAct << ADDITION_MODE_ID << MODIFICATION_MODE_ID << DETECTION_MODE_ID;
263 if (myActionMap[ADDITION_MODE_ID]->isChecked()) {
266 QList<int> aSelSection = mySectionView->getSelectedSections();
267 if( aSelSection.size() > 0 ){
268 mySection = aSelSection[0];
269 myPointNum = myCurve->getNbPoints(mySection);
271 } else if (myActionMap[MODIFICATION_MODE_ID]->isChecked()) {
272 anEnabledAct << REMOVE_ID;
273 anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID;
274 int aSectCnt = myCurve->getNbSections();
276 anEnabledAct << CLEAR_ALL_ID;
278 anEnabledAct << JOIN_ALL_ID;
279 if( aSelSections.size() > 1 ){
280 anEnabledAct << JOIN_ID;
282 } else if (myActionMap[DETECTION_MODE_ID]->isChecked()) {
283 } else { //no active mode
285 /*if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){
286 anEnabledAct << DOWN_ID;
290 /*case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{
291 if( aSelPoints[0].second > 0 ){
292 anEnabledAct << UP_ID;
294 int aLastIndex = aSelPoints.size()-1;
295 int aSect = aSelPoints[0].first;
296 if( aSelPoints[aLastIndex].second < (myCurve->getNbPoints(aSect) - 1)){
297 anEnabledAct << DOWN_ID;
299 if( aSelPoints.size() == 1){
300 anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID;
307 /*int aSelObjsCnt = aSelPoints.size() + aSelSections.size();
308 if( aSelObjsCnt > 0 ){
309 anEnabledAct << REMOVE_ID;
311 if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){
312 anEnabledAct << REMOVE_ALL_ID;
314 if( myCurve->getNbSections() > 1 ){
315 anEnabledAct << JOIN_ALL_ID;
318 QList<ActionId> anIds = myActionMap.keys();
319 for( int i = 0 ; i < anIds.size() ; i++ ){
320 if( myActionMap.contains(anIds[i]) ){
321 if( anEnabledAct.contains(anIds[i]) ){
322 myActionMap[anIds[i]]->setEnabled(true);
325 myActionMap[anIds[i]]->setEnabled(false);
329 emit selectionChanged();
332 void CurveCreator_Widget::onAdditionMode(bool checked)
337 SUIT_ViewWindow* aViewWindow = 0;
338 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
340 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
341 if ( aViewWindow == 0 )
343 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
345 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) {
347 connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
348 this, SLOT( onGetPointByClick( SUIT_ViewWindow*, QMouseEvent* ) ) );
350 disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
351 this, SLOT( onGetPointByClick( SUIT_ViewWindow*, QMouseEvent* ) ) );
358 QList<int> aSelSection = mySectionView->getSelectedSections();
359 if( aSelSection.size() > 0 ){
360 mySection = aSelSection[0];
363 QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
364 if( aSelPoints.size() > 0 ){
365 mySection = aSelPoints[0].first;
366 myPointNum = aSelPoints[0].second + 1;
372 mySection = myCurve->getNbSections() - 1;
374 aSectName = QString::fromStdString( myCurve->getSectionName(mySection));
375 if( myPointNum < 0 ){
376 myPointNum = myCurve->getNbPoints(mySection);
378 myNewPointEditor->clear();
379 myNewPointEditor->setEditMode(false);
380 myNewPointEditor->setSectionName(aSectName);
381 myNewPointEditor->setDimension(myCurve->getDimension());
383 // emit subOperationStarted( myNewPointEditor );
386 void CurveCreator_Widget::onModificationMode(bool checked)
388 SUIT_ViewWindow* aViewWindow = 0;
389 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
391 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
392 if ( aViewWindow == 0 )
394 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
395 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) {
397 // connect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
398 // this, SLOT( onPointSelect( SUIT_ViewWindow*, QMouseEvent* ) ) );
399 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
400 this, SLOT( onPointDrag( SUIT_ViewWindow*, QMouseEvent* ) ) );
403 // disconnect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
404 // this, SLOT( onPointSelect( SUIT_ViewWindow*, QMouseEvent* ) ) );
405 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
406 this, SLOT( onPointDrag( SUIT_ViewWindow*, QMouseEvent* ) ) );
412 void CurveCreator_Widget::onDetectPoints(bool checked)
416 void CurveCreator_Widget::onModeChanged(bool checked)
419 QAction* anAction = (QAction*)sender();
420 switch(myActionMap.key(anAction)) {
421 case ADDITION_MODE_ID:
422 if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
423 myActionMap[MODIFICATION_MODE_ID]->trigger();
424 else if (myActionMap[DETECTION_MODE_ID]->isChecked())
425 myActionMap[DETECTION_MODE_ID]->trigger();
427 case MODIFICATION_MODE_ID:
428 if (myActionMap[ADDITION_MODE_ID]->isChecked())
429 myActionMap[ADDITION_MODE_ID]->trigger();
430 else if (myActionMap[DETECTION_MODE_ID]->isChecked())
431 myActionMap[DETECTION_MODE_ID]->trigger();
433 case DETECTION_MODE_ID:
434 if (myActionMap[ADDITION_MODE_ID]->isChecked())
435 myActionMap[ADDITION_MODE_ID]->trigger();
436 else if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
437 myActionMap[MODIFICATION_MODE_ID]->trigger();
441 onSelectionChanged();
444 void CurveCreator_Widget::onAddNewPoint(const CurveCreator::Coordinates& theCoords)
448 // CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates();
449 myEdit->insertPoints(theCoords, mySection, myPointNum );
450 mySectionView->pointsAdded( mySection, myPointNum );
451 // myNewPointEditor->clear();
453 onSelectionChanged();
457 void CurveCreator_Widget::onNewSection()
461 myNewSectionEditor->clear();
462 myNewSectionEditor->setEditMode(false);
463 QString aSectName = QString( myCurve->getUnicSectionName().c_str() );
464 myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline );
465 emit subOperationStarted( myNewSectionEditor );
468 void CurveCreator_Widget::onAddNewSection()
472 CurveCreator::Coordinates aCoords;
473 myEdit->addSection( myNewSectionEditor->getName().toStdString(), myNewSectionEditor->getSectionType(),
474 myNewSectionEditor->isClosed(), aCoords );
475 mySectionView->sectionAdded( mySection );
476 QString aNewName = QString(myCurve->getUnicSectionName().c_str());
477 myNewSectionEditor->setSectionName(aNewName);
479 onSelectionChanged();
484 void CurveCreator_Widget::onCancelPoint()
486 emit subOperationFinished( myNewPointEditor );
489 void CurveCreator_Widget::onCancelSection()
491 emit subOperationFinished( myNewSectionEditor );
494 QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
495 const QString& theToolTip, const QKeySequence& theShortcut )
497 QAction* anAct = new QAction(theName,this);
498 if( !theImage.isNull() ){
499 anAct->setIcon(theImage);
501 anAct->setShortcut(theShortcut);
502 anAct->setToolTip(theToolTip);
503 myActionMap[theId] = anAct;
507 QAction* CurveCreator_Widget::getAction(ActionId theId)
509 if( myActionMap.contains(theId) )
510 return myActionMap[theId];
514 void CurveCreator_Widget::onEditSection( int theSection )
518 mySection = theSection;
519 QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
520 bool isClosed = myCurve->isClosed(theSection);
521 CurveCreator::Type aType = myCurve->getType(theSection);
522 myNewSectionEditor->setEditMode(true);
523 myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType );
525 emit subOperationStarted( myNewSectionEditor );
528 void CurveCreator_Widget::onModifySection()
532 QString aName = myNewSectionEditor->getName();
533 bool isClosed = myNewSectionEditor->isClosed();
534 CurveCreator::Type aSectType = myNewSectionEditor->getSectionType();
535 myEdit->startOperation();
536 myEdit->setClosed( isClosed, mySection );
537 myEdit->setName( aName.toStdString(), mySection );
538 myEdit->setType( aSectType, mySection );
539 myEdit->finishOperation();
540 mySectionView->sectionChanged(mySection);
545 void CurveCreator_Widget::onEditPoint( int theSection, int thePoint )
547 if( !myNewPointEditor || !myEdit )
549 mySection = theSection;
550 myPointNum = thePoint;
551 QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
552 myNewPointEditor->setEditMode(true);
553 myNewPointEditor->setSectionName(aSectName);
554 myNewPointEditor->setDimension( myCurve->getDimension() );
555 CurveCreator::Coordinates aCoords = myCurve->getCoordinates(theSection,thePoint);
556 myNewPointEditor->setCoordinates(aCoords);
557 emit subOperationStarted( myNewPointEditor );
560 void CurveCreator_Widget::onModifyPoint()
564 CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates();
565 myEdit->setCoordinates( aCoords, mySection, myPointNum );
566 mySectionView->pointDataChanged( mySection, myPointNum );
571 void CurveCreator_Widget::onJoin()
575 QList<int> aSections = mySectionView->getSelectedSections();
576 if( aSections.size() == 0 ){
579 int aMainSect = aSections[0];
580 int aMainSectSize = myCurve->getNbPoints(aMainSect);
581 myEdit->startOperation();
582 for( int i = 1 ; i < aSections.size() ; i++ ){
583 int aSectNum = aSections[i] - (i-1);
584 myEdit->join( aMainSect, aSectNum );
585 mySectionView->sectionsRemoved( aSectNum );
587 myEdit->finishOperation();
588 int aNewSectSize = myCurve->getNbPoints(aMainSect);
589 if( aNewSectSize != aMainSectSize )
590 mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );
594 void CurveCreator_Widget::onRemove()
598 QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
601 myEdit->startOperation();
602 for( int i = 0 ; i < aSelPoints.size() ; i++ ){
603 if( aCurrSect != aSelPoints[i].first ){
605 aCurrSect = aSelPoints[i].first;
607 int aPntIndx = aSelPoints[i].second - aRemoveCnt;
608 myEdit->removePoints(aCurrSect,aPntIndx, 1);
609 mySectionView->pointsRemoved( aCurrSect, aPntIndx );
612 QList<int> aSections = mySectionView->getSelectedSections();
613 for( int i = 0 ; i < aSections.size() ; i++ ){
614 int aSectNum = aSections[i] - (i);
615 myEdit->removeSection( aSectNum );
616 mySectionView->sectionsRemoved( aSectNum );
618 myEdit->finishOperation();
619 mySectionView->clearSelection();
623 void CurveCreator_Widget::onMoveUp()
627 if( mySectionView->getSelectionType() == CurveCreator_TreeView::ST_SECTIONS ){
629 QList<int> aSections = mySectionView->getSelectedSections();
630 for( int i = 0 ; i < aSections.size() ; i++ ){
631 int anIndx = aSections[i];
632 myEdit->moveSection( anIndx, anIndx-1);
633 mySectionView->sectionsSwapped( anIndx, -1 );
638 QList< QPair<int,int> > aPoints = mySectionView->getSelectedPoints();
639 for( int i = 0 ; i < aPoints.size() ; i++ ){
640 int aSection = aPoints[i].first;
641 int aPoint = aPoints[i].second;
642 myEdit->movePoint(aSection, aPoint, aPoint-2);
643 mySectionView->pointsSwapped( aSection, aPoint, -1 );
649 void CurveCreator_Widget::onMoveDown()
653 if( mySectionView->getSelectionType() == CurveCreator_TreeView::ST_SECTIONS ){
655 QList<int> aSections = mySectionView->getSelectedSections();
656 for( int i = aSections.size()-1 ; i >=0 ; i-- ){
657 int anIndx = aSections[i];
658 myEdit->moveSection( anIndx, anIndx+1);
659 mySectionView->sectionsSwapped( anIndx, 1 );
664 QList< QPair<int,int> > aPoints = mySectionView->getSelectedPoints();
665 for( int i = aPoints.size() - 1; i >= 0 ; i-- ){
666 int aSection = aPoints[i].first;
667 int aPoint = aPoints[i].second;
668 myEdit->movePoint(aSection, aPoint, aPoint+1);
669 mySectionView->pointsSwapped( aSection, aPoint, 1 );
675 void CurveCreator_Widget::onClearAll()
680 mySectionView->reset();
681 onSelectionChanged();
685 void CurveCreator_Widget::onJoinAll()
690 mySectionView->reset();
691 onSelectionChanged();
695 void CurveCreator_Widget::onInsertSectionBefore()
700 void CurveCreator_Widget::onInsertSectionAfter()
705 void CurveCreator_Widget::onInsertPointBefore()
710 void CurveCreator_Widget::onInsertPointAfter()
715 void CurveCreator_Widget::onUndoSettings()
720 void CurveCreator_Widget::onSetSpline()
724 QList<int> aSelSections = mySectionView->getSelectedSections();
725 myEdit->startOperation();
726 for( int i = 0 ; i < aSelSections.size() ; i++ ){
727 myEdit->setType(CurveCreator::BSpline, aSelSections[i]);
728 mySectionView->sectionChanged(aSelSections[i]);
730 myEdit->finishOperation();
734 void CurveCreator_Widget::onSetPolyline()
738 myEdit->startOperation();
739 QList<int> aSelSections = mySectionView->getSelectedSections();
740 for( int i = 0 ; i < aSelSections.size() ; i++ ){
741 myEdit->setType(CurveCreator::Polyline, aSelSections[i]);
742 mySectionView->sectionChanged(aSelSections[i]);
744 myEdit->finishOperation();
748 void CurveCreator_Widget::onCloseSections()
752 myEdit->startOperation();
753 QList<int> aSelSections = mySectionView->getSelectedSections();
754 for( int i = 0 ; i < aSelSections.size() ; i++ ){
755 myEdit->setClosed(true, aSelSections[i]);
756 mySectionView->sectionChanged(aSelSections[i]);
758 myEdit->finishOperation();
762 void CurveCreator_Widget::onUncloseSections()
766 myEdit->startOperation();
767 QList<int> aSelSections = mySectionView->getSelectedSections();
768 for( int i = 0 ; i < aSelSections.size() ; i++ ){
769 myEdit->setClosed(false, aSelSections[i]);
770 mySectionView->sectionChanged(aSelSections[i]);
772 myEdit->finishOperation();
776 void CurveCreator_Widget::onUndo()
781 mySectionView->reset();
785 void CurveCreator_Widget::onRedo()
790 mySectionView->reset();
794 void CurveCreator_Widget::updateUndoRedo()
796 QAction* anAct = myActionMap[UNDO_ID];
798 if( myEdit->getNbUndo() != 0 ){
799 anAct->setEnabled(true);
802 anAct->setDisabled(true);
805 anAct = myActionMap[REDO_ID];
807 if( myEdit->getNbRedo() != 0 ){
808 anAct->setEnabled(true);
811 anAct->setDisabled(true);
816 void CurveCreator_Widget::onContextMenu( QPoint thePoint )
818 QList<ActionId> aContextActions;
819 aContextActions << CLEAR_ALL_ID << JOIN_ALL_ID << SEPARATOR_ID <<
820 CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID <<
821 SET_SECTIONS_SPLINE_ID;
822 QPoint aGlPoint = mySectionView->mapToGlobal(thePoint);
824 QList<ActionId> aResAct;
825 for( int i = 0 ; i < aContextActions.size() ; i++ ){
826 if( aContextActions[i] != SEPARATOR_ID ){
827 if( myActionMap.contains(aContextActions[i]) ){
828 QAction* anAct = myActionMap[aContextActions[i]];
829 if( anAct->isEnabled() ){
830 aResAct << aContextActions[i];
836 aResAct << SEPARATOR_ID;
842 QMenu* aMenu = new QMenu(this);
843 for( int i = 0 ; i < aResAct.size() ; i++ ){
844 if( aResAct[i] == SEPARATOR_ID ){
845 aMenu->addSeparator();
848 QAction* anAct = myActionMap[aResAct[i]];
849 aMenu->insertAction(NULL, anAct);
852 aMenu->exec(aGlPoint);
855 QList<int> CurveCreator_Widget::getSelectedSections()
857 return mySectionView->getSelectedSections();
860 QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints()
862 return mySectionView->getSelectedPoints();
865 bool CurveCreator_Widget::isInstantSketchingEnabled() const
867 if( myNewPointEditor )
868 return myNewPointEditor->isInstantSketchingEnabled();
872 void CurveCreator_Widget::setInstantSketchingEnabled( const bool theState )
874 if( myNewPointEditor )
875 myNewPointEditor->setInstantSketchingEnabled( theState );
878 //=================================================================================
879 // function : GeometryGUI::onGetPointByClick()
880 // purpose : Manage mouse press events in Additon mode
881 //=================================================================================
882 void CurveCreator_Widget::onGetPointByClick( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe )
884 if ( myNewPointEditor && theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
885 pe->modifiers() != Qt::ControlModifier ) {
886 OCCViewer_Viewer* anOCCViewer =
887 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
888 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
893 if ( pe->modifiers() == Qt::ShiftModifier )
894 ic->ShiftSelect(); // Append selection
896 ic->Select(); // New selection
898 /*TopoDS_Shape aShape;
901 if ( ic->MoreSelected() )
902 aShape = ic->SelectedShape();
904 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
905 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
908 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
909 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
911 // set the coordinates into dialog
912 CurveCreator::Coordinates aCoords;
913 aCoords.push_back( aPnt.X() );
914 aCoords.push_back( aPnt.Y() );
915 if ( myCurve->getDimension() == 3 ) {
916 aCoords.push_back( aPnt.Z() );
918 onAddNewPoint(aCoords);
919 // myNewPointEditor->setCoordinates( aCoords );
923 //=================================================================================
924 // function : GeometryGUI::onPointDrag()
925 // purpose : Manage mouse move events in Modification mode
926 //=================================================================================
927 void CurveCreator_Widget::onPointDrag( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe )
929 if ( !(pe->buttons() & Qt::LeftButton) )
931 if ( (pe->pos() - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() )
934 QDrag *drag = new QDrag(this);
935 QMimeData *mimeData = new QMimeData;
937 mimeData->setData(mimeType, data);
938 drag->setMimeData(mimeData);
940 Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);