1 // Copyright (C) 2013-2022 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, or (at your option) any later version.
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 <Basics_OCCTVersion.hxx>
22 #include "CurveCreator_Widget.h"
23 #include "CurveCreator_TreeView.h"
24 #include "CurveCreator_NewSectionDlg.h"
25 #include "CurveCreator_Utils.hxx"
26 #include "CurveCreator_UtilsICurve.hxx"
27 #include "CurveCreator_TableView.h"
29 #include "CurveCreator_Curve.hxx"
30 #include "CurveCreator_Section.hxx"
31 #include <QColorDialog>
33 #include <SUIT_Session.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_ViewManager.h>
38 #include <TopExp_Explorer.hxx>
39 #include "CurveCreator_ShapeFilter.hxx"
41 #include <OCCViewer_ViewManager.h>
42 #include <OCCViewer_ViewPort3d.h>
43 #include <OCCViewer_Utilities.h>
45 #include <QHBoxLayout>
46 #include <QVBoxLayout>
50 #include <QToolButton>
54 #include <QMouseEvent>
55 #include <QApplication>
56 #include <QTableWidget>
60 #include <utilities.h>
62 //#define MEASURE_TIME
66 #define START_MEASURE_TIME \
70 #define END_MEASURE_TIME( theMsg ) \
71 double aTime = aTimer.elapsed() * 0.001; \
72 FILE* aFile = fopen( "performance", "a" ); \
73 fprintf( aFile, "%s = %.3lf sec\n", theMsg, aTime ); \
78 #define START_MEASURE_TIME
79 #define END_MEASURE_TIME( theMsg )
88 CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
89 CurveCreator_ICurve *theCurve,
90 const int theActionFlags,
91 const QStringList& theCoordTitles,
92 Qt::WindowFlags /*fl*/ )
93 : QWidget(parent), myCurve(theCurve), myNewSectionEditor(NULL),
94 myOCCViewer( 0 ), mySection(0),
95 myDragStarted( false ), myDragInteractionStyle( SUIT_ViewModel::STANDARD ),
96 myOld2DMode(OCCViewer_ViewWindow::No2dMode)
98 bool isToEnableClosed = !( theActionFlags & DisableClosedSection );
99 myNewSectionEditor = new CurveCreator_NewSectionDlg( this, isToEnableClosed );
100 myNewSectionEditor->hide();
101 connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()) );
102 connect( myNewSectionEditor, SIGNAL(modifySection()), this, SLOT(onModifySection()) );
103 connect( myNewSectionEditor, SIGNAL(cancelSection()), this, SLOT(onCancelSection()) );
105 QGroupBox* aSectionGroup = new QGroupBox(tr("SECTION_GROUP_TITLE"),this);
108 bool toDrawSectColor = !(theActionFlags & DisableSetColor);
110 mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup, toDrawSectColor);
111 mySectionView->setSelectionMode( QTreeView::ExtendedSelection );
112 connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) );
113 connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) );
114 connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) );
116 myLocalPointView = new CurveCreator_TableView( myCurve, this, theCoordTitles );
117 connect( myLocalPointView, SIGNAL( cellChanged( int, int ) ),
118 this, SLOT( onCellChanged( int, int ) ) );
120 QToolBar* aTB = new QToolBar(tr("SECTION_GROUP_TITLE"), aSectionGroup);
121 // QToolButton* anUndoBtn = new QToolButton(aTB);
123 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
124 QPixmap anUndoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_UNDO")));
125 QPixmap aRedoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_REDO")));
126 QPixmap aNewSectionPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_SECTION")));
127 QPixmap aNewPointPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_POINT")));
128 QPixmap anEditPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
129 QPixmap aDetectPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS")));
130 QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
131 QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
132 QPixmap aRemovePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_DELETE")));
133 QPixmap aJoinPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_JOIN")));
134 QPixmap aBringTogetherPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_BRING_TOGETHER")));
135 QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP")));
136 QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN")));
137 QPixmap aSetColorPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SETCOLOR")));
139 QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"),
140 QKeySequence(Qt::ControlModifier|Qt::Key_Z) );
141 connect(anAct, SIGNAL(triggered()), this, SLOT(onUndo()) );
142 aTB->addAction(anAct);
144 anAct = createAction( REDO_ID, tr("REDO"), aRedoPixmap, tr("REDO_TLT"),
145 QKeySequence(Qt::ControlModifier|Qt::Key_Y) );
146 connect(anAct, SIGNAL(triggered()), this, SLOT(onRedo()) );
147 aTB->addAction(anAct);
151 anAct = createAction( NEW_SECTION_ID, tr("NEW_SECTION"), aNewSectionPixmap, tr("NEW_SECTION_TLT"),
152 QKeySequence(Qt::ControlModifier|Qt::Key_N) );
153 connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) );
154 if ( !(theActionFlags & DisableNewSection) ) {
155 aTB->addAction(anAct);
159 anAct = createAction( ADDITION_MODE_ID, tr("ADDITION_MODE"), aNewPointPixmap, tr("ADDITION_MODE_TLT"),
161 anAct->setCheckable(true);
162 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onAdditionMode(bool)) );
163 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
164 aTB->addAction(anAct);
166 anAct = createAction( MODIFICATION_MODE_ID, tr("MODIFICATION_MODE"), anEditPointsPixmap, tr("MODIFICATION_MODE_TLT"),
168 anAct->setCheckable(true);
169 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onModificationMode(bool)) );
170 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
171 aTB->addAction(anAct);
173 anAct = createAction( DETECTION_MODE_ID, tr("DETECTION_MODE"), aDetectPointsPixmap, tr("DETECTION_MODE_TLT"),
175 anAct->setCheckable(true);
176 connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onDetectionMode(bool)) );
177 connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) );
178 // if ( !(theActionFlags & DisableDetectionMode) ) {
179 // aTB->addAction(anAct);
182 anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), QPixmap(), tr("CLOSE_SECTIONS_TLT"),
183 QKeySequence(Qt::ControlModifier|Qt::Key_W) );
184 connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) );
186 anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), QPixmap(),
187 tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) );
188 connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) );
190 anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"),
191 aPolylinePixmap, tr("SET_SECTIONS_POLYLINE_TLT"),
192 QKeySequence(Qt::ControlModifier|Qt::Key_E) );
193 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) );
195 anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), aSplinePixmap,
196 tr("SET_SECTIONS_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) );
197 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) );
201 anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemovePixmap, tr("REMOVE_TLT"),
202 QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) );
203 connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) );
204 aTB->addAction(anAct);
206 anAct = createAction( SETCOLOR_ID, tr("SETCOLOR"), aSetColorPixmap, tr("SETCOLOR_TLT"),
207 QKeySequence(Qt::ControlModifier|Qt::Key_C ) );
208 connect(anAct, SIGNAL(triggered()), this, SLOT(onSetColor()) );
210 if ( !(theActionFlags & DisableSetColor) )
211 aTB->addAction(anAct);
213 anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"),
214 QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) );
215 connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) );
216 aTB->addAction(anAct);
218 anAct = createAction( BRING_TOGETHER_ID, tr("BRING_TOGETHER"), aBringTogetherPixmap, tr("BRING_TOGETHER_TLT"),
219 QKeySequence(Qt::ControlModifier|Qt::Key_Equal ) );
220 connect( anAct, SIGNAL(triggered()), this, SLOT(onBringTogether()) );
221 aTB->addAction(anAct);
223 anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"),
224 QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) );
225 connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) );
227 anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), QPixmap(), tr("JOIN_ALL_TLT"),
228 QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) );
229 connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) );
231 QVBoxLayout* aSectLayout = new QVBoxLayout();
232 aSectLayout->setMargin( 5 );
233 aSectLayout->setSpacing( 5 );
234 aSectLayout->addWidget(aTB);
236 QSplitter* aSplitter = new QSplitter(aSectionGroup);
237 aSplitter->setOrientation(Qt::Vertical);
239 aSplitter->addWidget(mySectionView);
240 aSplitter->addWidget( myLocalPointView );
242 aSectLayout->addWidget(aSplitter);
243 aSectionGroup->setLayout(aSectLayout);
244 QVBoxLayout* aLay = new QVBoxLayout();
245 aLay->setMargin( 0 );
246 aLay->setSpacing( 5 );
247 // aLay->addLayout(aNameLayout);
248 aLay->addWidget(aSectionGroup);
251 updateActionsStates();
258 void CurveCreator_Widget::setOCCViewer( OCCViewer_Viewer* theViewer )
260 if ( myOCCViewer == theViewer )
264 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
265 ( myOCCViewer->getViewManager() );
266 disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
267 this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
268 disconnect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
269 this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
270 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
271 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
272 disconnect( aViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
273 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
274 // restore normal mode in the viewer
275 SetViewer2DMode(false);
276 // all local contexts should be closed if the viewer is not more used
277 setLocalPointContext( false, true );
280 myOCCViewer = theViewer;
282 OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
283 ( myOCCViewer->getViewManager() );
284 connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
285 this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
286 connect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ),
287 this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
288 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
289 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
290 connect( aViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
291 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
292 SetViewer2DMode(true);
297 * Returns current OCC viewer
299 OCCViewer_Viewer* CurveCreator_Widget::getOCCViewer()
305 * Returns OCC viewer context
307 Handle(AIS_InteractiveContext) CurveCreator_Widget::getAISContext()
309 Handle(AIS_InteractiveContext) aContext;
310 OCCViewer_Viewer* aViewer = getOCCViewer();
312 aContext = aViewer->getAISContext();
318 * Returns OCC viewer view port
320 OCCViewer_ViewPort3d* CurveCreator_Widget::getViewPort()
322 OCCViewer_ViewPort3d* aViewPort = 0;
323 OCCViewer_Viewer* aViewer = getOCCViewer();
325 aViewPort = ((OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView())->getViewPort();
331 * Set interaction style in the OCC viewer
332 * \param theStyle a new style
333 * \return the previous style
335 int CurveCreator_Widget::changeInteractionStyle( int theStyle )
337 OCCViewer_Viewer* aViewer = getOCCViewer();
341 int aPrevStyle = aViewer->interactionStyle();
342 aViewer->setInteractionStyle( theStyle );
347 //=======================================================================
349 // purpose: reset the widget viewer, close local context, clear selection
350 //=======================================================================
351 void CurveCreator_Widget::reset()
356 void CurveCreator_Widget::setCurve( CurveCreator_ICurve* theCurve )
359 mySectionView->setCurve( myCurve );
360 myLocalPointView->setCurve( myCurve );
361 updateActionsStates();
365 void CurveCreator_Widget::onSelectionChanged()
367 updateActionsStates();
369 emit selectionChanged();
370 QList<int> selectedSections = mySectionView->getSelectedSections();
371 CurveCreator_Curve* Curve = ((CurveCreator_Curve*)myCurve);
372 Curve->myCurSectInd.clear();
373 foreach (int sectInd, selectedSections)
374 Curve->myCurSectInd.push_back(sectInd);
377 void CurveCreator_Widget::updateActionsStates()
379 QList<ActionId> anEnabledAct;
381 anEnabledAct << NEW_SECTION_ID << MODIFICATION_MODE_ID;
382 if ( removeEnabled() )
383 anEnabledAct << REMOVE_ID;
384 QList<int> aSelSections = mySectionView->getSelectedSections();
385 if (aSelSections.size() == 1)
386 anEnabledAct << SETCOLOR_ID;
387 CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
389 case CurveCreator_TreeView::ST_NOSEL:{
392 case CurveCreator_TreeView::ST_SECTIONS:{
393 /*if( aSelSections[0] > 0 ){
394 anEnabledAct << UP_ID;
396 if( aSelSections.size() == 1 ){
397 anEnabledAct << ADDITION_MODE_ID << DETECTION_MODE_ID;
399 switch ( getActionMode() ) {
403 QList<int> aSelSection = mySectionView->getSelectedSections();
404 if( aSelSection.size() > 0 ){
405 mySection = aSelSection[0];
406 myPointNum = myCurve->getNbPoints(mySection);
410 case ModificationMode: {
411 if ( myNewSectionEditor->isEnableClosed() )
412 anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID;
413 anEnabledAct << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID;
414 int aSectCnt = myCurve->getNbSections();
416 anEnabledAct << CLEAR_ALL_ID;
418 anEnabledAct << JOIN_ALL_ID;
419 if( aSelSections.size() > 1 ){
420 anEnabledAct << JOIN_ID << BRING_TOGETHER_ID;
424 case DetectionMode: {
429 int aSectCnt = myCurve->getNbSections();
431 anEnabledAct << JOIN_ALL_ID;
432 if( aSelSections.size() > 1 )
433 anEnabledAct << JOIN_ID;
439 /*if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){
440 anEnabledAct << DOWN_ID;
444 /*case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{
445 if( aSelPoints[0].second > 0 ){
446 anEnabledAct << UP_ID;
448 int aLastIndex = aSelPoints.size()-1;
449 int aSect = aSelPoints[0].first;
450 if( aSelPoints[aLastIndex].second < (myCurve->getNbPoints(aSect) - 1)){
451 anEnabledAct << DOWN_ID;
453 if( aSelPoints.size() == 1){
454 anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID;
463 /*int aSelObjsCnt = aSelPoints.size() + aSelSections.size();
464 if( aSelObjsCnt > 0 ){
465 anEnabledAct << REMOVE_ID;
467 if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){
468 anEnabledAct << REMOVE_ALL_ID;
470 if( myCurve->getNbSections() > 1 ){
471 anEnabledAct << JOIN_ALL_ID;
474 QList<ActionId> anIds = myActionMap.keys();
475 for( int i = 0 ; i < anIds.size() ; i++ ){
476 if( myActionMap.contains(anIds[i]) ){
477 if( anEnabledAct.contains(anIds[i]) ){
478 myActionMap[anIds[i]]->setEnabled(true);
481 myActionMap[anIds[i]]->setEnabled(false);
487 void CurveCreator_Widget::onAdditionMode(bool checked)
492 Handle(AIS_InteractiveContext) aContext = getAISContext();
493 if( !myCurve || aContext.IsNull() )
498 QList<int> aSelSection = mySectionView->getSelectedSections();
499 if( aSelSection.size() > 0 ){
500 mySection = aSelSection[0];
502 // emit subOperationStarted( myNewPointEditor );
505 void CurveCreator_Widget::onModificationMode(bool checked)
507 myLocalPointView->setVisible( checked );
510 void CurveCreator_Widget::onDetectionMode(bool /*checked*/)
514 void CurveCreator_Widget::onModeChanged(bool checked)
516 ActionMode aMode = NoneMode;
518 QAction* anAction = (QAction*)sender();
519 switch(myActionMap.key(anAction)) {
520 case ADDITION_MODE_ID:
521 aMode = AdditionMode;
522 if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
523 myActionMap[MODIFICATION_MODE_ID]->trigger();
524 else if (myActionMap[DETECTION_MODE_ID]->isChecked())
525 myActionMap[DETECTION_MODE_ID]->trigger();
527 case MODIFICATION_MODE_ID:
528 aMode = ModificationMode;
529 if (myActionMap[ADDITION_MODE_ID]->isChecked())
530 myActionMap[ADDITION_MODE_ID]->trigger();
531 else if (myActionMap[DETECTION_MODE_ID]->isChecked())
532 myActionMap[DETECTION_MODE_ID]->trigger();
534 case DETECTION_MODE_ID:
535 aMode = DetectionMode;
536 if (myActionMap[ADDITION_MODE_ID]->isChecked())
537 myActionMap[ADDITION_MODE_ID]->trigger();
538 else if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
539 myActionMap[MODIFICATION_MODE_ID]->trigger();
545 updateActionsStates();
547 setLocalPointContext( aMode == ModificationMode, true );
550 void CurveCreator_Widget::onNewSection()
556 myNewSectionEditor->clear();
557 myNewSectionEditor->setEditMode(false);
558 QString aSectName = QString( CurveCreator_UtilsICurve::getUniqSectionName( myCurve ).c_str() );
559 myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline );
560 emit subOperationStarted( myNewSectionEditor, false );
563 void CurveCreator_Widget::onAddNewSection()
567 myCurve->addSection( myNewSectionEditor->getName().toStdString(),
568 myNewSectionEditor->getSectionType(),
569 myNewSectionEditor->isClosed() );
570 mySectionView->sectionAdded( -1 ); // add a new section to the end of list
571 QString aNewName = QString( CurveCreator_UtilsICurve::getUniqSectionName( myCurve ).c_str() );
572 myNewSectionEditor->setSectionName(aNewName);
573 updateActionsStates();
578 void CurveCreator_Widget::onCancelSection()
580 emit subOperationFinished( myNewSectionEditor );
583 QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
584 const QString& theToolTip, const QKeySequence& theShortcut )
586 QAction* anAct = new QAction(theName,this);
587 if( !theImage.isNull() ){
588 anAct->setIcon(theImage);
590 anAct->setShortcut(theShortcut);
591 anAct->setToolTip(theToolTip);
592 myActionMap[theId] = anAct;
596 QAction* CurveCreator_Widget::getAction( ActionId theId )
598 if( myActionMap.contains(theId) )
599 return myActionMap[theId];
603 QAction* CurveCreator_Widget::getAction( ActionMode theMode )
605 ActionId anActionId = NONE_ID;
608 anActionId = ADDITION_MODE_ID;
610 case ModificationMode:
611 anActionId = MODIFICATION_MODE_ID;
614 anActionId = DETECTION_MODE_ID;
619 QAction* anAction = 0;
620 if ( anActionId != NONE_ID && myActionMap.contains( anActionId ) )
621 anAction = myActionMap[anActionId];
625 void CurveCreator_Widget::onEditSection( int theSection )
631 mySection = theSection;
632 QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));
633 bool isClosed = myCurve->isClosed(theSection);
634 CurveCreator::SectionType aType = myCurve->getSectionType(theSection);
635 myNewSectionEditor->setEditMode(true);
636 myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType );
638 emit subOperationStarted( myNewSectionEditor, true );
641 void CurveCreator_Widget::onModifySection()
645 QString aName = myNewSectionEditor->getName();
646 bool isClosed = myNewSectionEditor->isClosed();
647 CurveCreator::SectionType aSectType = myNewSectionEditor->getSectionType();
648 if( myCurve->getSectionName(mySection) != aName.toStdString() )
649 myCurve->setSectionName( mySection, aName.toStdString() );
651 //bool isGeomModified = false;
653 if( myCurve->getSectionType(mySection) != aSectType ) {
654 myCurve->setSectionType( mySection, aSectType );
655 //isGeomModified = true;
658 if( myCurve->isClosed(mySection) != isClosed ) {
659 myCurve->setClosed( mySection, isClosed );
660 //isGeomModified = true;
662 mySectionView->sectionChanged(mySection);
667 void CurveCreator_Widget::onJoin()
671 QList<int> aSections = mySectionView->getSelectedSections();
672 if( aSections.size() == 0 ){
677 std::list<int> aSectionsToJoin;
678 for( int i = 0; i < aSections.size() ; i++ ){
679 aSectionsToJoin.push_back( aSections[i] );
681 //int aMainSect = aSectionsToJoin.front();
682 //int aMainSectSize = myCurve->getNbPoints(aMainSect);
683 if ( myCurve->join( aSectionsToJoin ) )
685 std::list<int>::const_iterator anIt = aSectionsToJoin.begin(),
686 aLast = aSectionsToJoin.end();
687 // the first section should be skipped. It is not removed, but is modified
689 for ( ; anIt != aLast; anIt++ )
690 mySectionView->sectionsRemoved( *anIt );
693 /* The update for the points of the main section
694 int aNewSectSize = myCurve->getNbPoints(aMainSect);
695 if( aNewSectSize != aMainSectSize )
696 mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );*/
700 void CurveCreator_Widget::onRemove()
705 switch( getActionMode() ) {
709 case ModificationMode:
717 void CurveCreator_Widget::onSetColor()
722 QList<int> aSections = mySectionView->getSelectedSections();
723 if (aSections.size() != 1)
726 int aSectNum = aSections[0];
727 Quantity_Color aColor = ((CurveCreator_Curve*)myCurve)->getColorSection( aSectNum );;
729 QColor aQColor = CurveCreator_Utils::colorConv(aColor);
730 QColor aNewQColor = QColorDialog::getColor( aQColor, this );
731 if( !aNewQColor.isValid() )
734 Quantity_Color aNewColor = CurveCreator_Utils::colorConv(aNewQColor);
736 ((CurveCreator_Curve*)myCurve)->setColorSection( aSectNum, aNewColor);
742 void CurveCreator_Widget::onClearAll()
748 mySectionView->reset();
749 updateActionsStates();
753 void CurveCreator_Widget::onJoinAll()
759 std::list<int> aSectionsToJoin;
760 for( int i = 0, aNb = myCurve->getNbSections(); i < aNb ; i++ ){
761 aSectionsToJoin.push_back( i );
763 /*bool aRes = */myCurve->join( aSectionsToJoin );
765 mySectionView->reset();
766 updateActionsStates();
770 void CurveCreator_Widget::onUndoSettings()
775 void CurveCreator_Widget::onSetSpline()
780 QList<int> aSelSections = mySectionView->getSelectedSections();
781 for( int i = 0 ; i < aSelSections.size() ; i++ ){
782 myCurve->setSectionType(aSelSections[i], CurveCreator::Spline );
783 mySectionView->sectionChanged(aSelSections[i]);
788 void CurveCreator_Widget::onSetPolyline()
793 QList<int> aSelSections = mySectionView->getSelectedSections();
794 for( int i = 0 ; i < aSelSections.size() ; i++ ){
795 myCurve->setSectionType( aSelSections[i], CurveCreator::Polyline );
796 mySectionView->sectionChanged( aSelSections[i] );
801 void CurveCreator_Widget::onCloseSections()
806 QList<int> aSelSections = mySectionView->getSelectedSections();
807 for( int i = 0 ; i < aSelSections.size() ; i++ ){
808 myCurve->setClosed(aSelSections[i], true);
809 mySectionView->sectionChanged(aSelSections[i]);
814 void CurveCreator_Widget::onUncloseSections()
819 QList<int> aSelSections = mySectionView->getSelectedSections();
820 for( int i = 0 ; i < aSelSections.size() ; i++ ){
821 myCurve->setClosed(aSelSections[i], false);
822 mySectionView->sectionChanged(aSelSections[i]);
827 void CurveCreator_Widget::onUndo()
832 CurveCreator_ICurve::SectionToPointList aPoints;
833 startCurveModification( aPoints, false );
835 finishCurveModification();
836 mySectionView->reset();
839 void CurveCreator_Widget::onRedo()
843 CurveCreator_ICurve::SectionToPointList aPoints;
844 startCurveModification( aPoints, false );
846 finishCurveModification();
847 mySectionView->reset();
850 void CurveCreator_Widget::updateUndoRedo()
854 QAction* anAct = myActionMap[UNDO_ID];
856 if( myCurve->getNbUndo() != 0 ){
857 anAct->setEnabled(true);
860 anAct->setDisabled(true);
863 anAct = myActionMap[REDO_ID];
865 if( myCurve->getNbRedo() != 0 ){
866 anAct->setEnabled(true);
869 anAct->setDisabled(true);
874 void CurveCreator_Widget::onContextMenu( QPoint thePoint )
876 QList<ActionId> aContextActions;
877 aContextActions << CLEAR_ALL_ID << JOIN_ID << JOIN_ALL_ID << SEPARATOR_ID <<
878 CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID <<
879 SET_SECTIONS_SPLINE_ID;
880 QPoint aGlPoint = mySectionView->mapToGlobal(thePoint);
882 QList<ActionId> aResAct;
883 for( int i = 0 ; i < aContextActions.size() ; i++ ){
884 if( aContextActions[i] != SEPARATOR_ID ){
885 if( myActionMap.contains(aContextActions[i]) ){
886 QAction* anAct = myActionMap[aContextActions[i]];
887 if( anAct->isEnabled() ){
888 aResAct << aContextActions[i];
894 aResAct << SEPARATOR_ID;
900 QMenu* aMenu = new QMenu(this);
901 for( int i = 0 ; i < aResAct.size() ; i++ ){
902 if( aResAct[i] == SEPARATOR_ID ){
903 aMenu->addSeparator();
906 QAction* anAct = myActionMap[aResAct[i]];
907 aMenu->insertAction(NULL, anAct);
910 aMenu->exec(aGlPoint);
913 QList<int> CurveCreator_Widget::getSelectedSections()
915 return mySectionView->getSelectedSections();
918 void CurveCreator_Widget::setSelectedSections( const QList<int>& theSections )
920 mySectionView->setSelectedSections( theSections );
921 updateActionsStates();
926 * According to the widget state, performs the remove action
928 void CurveCreator_Widget::removeSelected()
934 * Checks whether there are some selection to be removed
936 bool CurveCreator_Widget::removeEnabled()
938 bool isEnabled = getActionMode() == ModificationMode;
940 QList<int> aSelSections = mySectionView->getSelectedSections();
941 CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
942 isEnabled = aSelType == CurveCreator_TreeView::ST_SECTIONS &&
943 aSelSections.size() == 1;
948 void CurveCreator_Widget::setActionMode( const ActionMode& theMode )
950 ActionMode aPrevMode = getActionMode();
951 QAction* aPrevAction = getAction( aPrevMode );
952 QAction* anAction = getAction( theMode );
957 if ( aPrevAction->isChecked() ) {
958 aPrevAction->setChecked( false );
961 if ( aPrevMode == ModificationMode )
962 onModificationMode( false );
963 if ( aPrevMode == AdditionMode )
964 onAdditionMode( false );
966 if ( theMode == AdditionMode )
968 anAction->setChecked( true );
969 onModeChanged( true );
974 case ModificationMode:
984 CurveCreator_Widget::ActionMode CurveCreator_Widget::getActionMode() const
986 ActionMode aMode = NoneMode;
988 if ( myActionMap[ADDITION_MODE_ID]->isChecked() )
989 aMode = AdditionMode;
990 else if ( myActionMap[MODIFICATION_MODE_ID]->isChecked() )
991 aMode = ModificationMode;
992 else if ( myActionMap[DETECTION_MODE_ID]->isChecked() )
993 aMode = DetectionMode;
998 void CurveCreator_Widget::SetViewer2DMode(const bool To2D)
1002 myOld2DMode = OCCViewer_Utilities::setViewer2DMode
1003 (myOCCViewer, OCCViewer_ViewWindow::XYPlane);
1005 OCCViewer_Utilities::setViewer2DMode(myOCCViewer, myOld2DMode);
1010 //=================================================================================
1011 // function : GeometryGUI::addCoordsByClick()
1012 // purpose : Manage mouse press events in Addition mode
1013 //=================================================================================
1014 void CurveCreator_Widget::addCoordsByClick( QMouseEvent* pe )
1016 if (pe->button() != Qt::LeftButton)
1019 if ( pe->modifiers() != Qt::ControlModifier ) {
1020 Handle(AIS_InteractiveContext) ic = getAISContext();
1025 OCCViewer_ViewPort3d* vp = getViewPort();
1027 aPnt = CurveCreator_Utils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
1029 // set the coordinates into dialog
1030 CurveCreator::Coordinates aCoords;
1031 aCoords.push_back( aPnt.X() );
1032 aCoords.push_back( aPnt.Y() );
1033 if ( myCurve->getDimension() == 3 ) {
1034 aCoords.push_back( aPnt.Z() );
1036 addNewPoint(aCoords);
1041 * Set the same coordinates on two section extremities.
1042 * Usage: build a closed contour with several sections.
1043 * Works with two points selected, at the extremities of different sections.
1044 * The second point gets the coordinates of the first.
1046 void CurveCreator_Widget::onBringTogether()
1048 MESSAGE("onBringTogether");
1049 ActionMode aMode = getActionMode();
1050 if ( aMode != ModificationMode )
1052 int nbPoints = myLocalPoints.size();
1053 MESSAGE("number of selected points: " << nbPoints);
1056 MESSAGE("works only with two points taken at the extremities of different sections, nothing done");
1060 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = myLocalPoints.begin(),
1061 aLast = myLocalPoints.end();
1062 std::vector<int> sections(nbPoints);
1063 std::vector<int> iPoints(nbPoints);
1064 std::vector<int> nbPtsSection(nbPoints);
1065 std::vector<double> x(nbPoints);
1066 std::vector<double> y(nbPoints);
1068 for ( ; anIt != aLast; anIt++, i++ )
1070 CurveCreator_ICurve::SectionToPoint aSPoint = *anIt;
1071 sections[i] = aSPoint.first;
1072 iPoints[i] = aSPoint.second;
1073 nbPtsSection[i] = myCurve->getNbPoints(sections[i]);
1074 if ((iPoints[i] != 0) && (iPoints[i] != nbPtsSection[i]-1))
1076 MESSAGE("a point is not on a section extremity, nothing done");
1080 CurveCreator_UtilsICurve::getPoint( myCurve, sections[i], iPoints[i], aPoint );
1083 MESSAGE("point: " << sections[i] << " " << iPoints[i] << " " << x[i] << " " << y[i]);
1085 if (sections[1] == sections[0])
1087 MESSAGE("the two points must be at the extremities of different sections, nothing done");
1091 CurveCreator_ICurve::SectionToPointList aSelPoints;
1092 startCurveModification( aSelPoints );
1094 CurveCreator::Coordinates aChangedPos;
1095 aChangedPos.push_back( x[0] ); // apply the first point coordinates to the second point.
1096 aChangedPos.push_back( y[0] );
1097 myCurve->setPoint( sections[1], iPoints[1], aChangedPos );
1099 finishCurveModification( aSelPoints );
1103 * Manage mouse press events
1104 * \param theWindow an owner of the signal
1105 * \param theEvent a mouse event
1107 void CurveCreator_Widget::onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent )
1109 if ( theEvent->button() != Qt::LeftButton )
1112 // Initialize the starting point
1113 myStartPoint.setX( theEvent->x() );
1114 myStartPoint.setY( theEvent->y() );
1116 switch( getActionMode() ) {
1117 case ModificationMode: {
1118 //store initial cursor position for Drag&Drop
1119 setDragStarted( true, theEvent->pos() );
1122 case AdditionMode: {
1123 addCoordsByClick( theEvent );
1132 * Manage mouse release events in Modification mode
1133 * \param theWindow an owner of the signal
1134 * \param theEvent a mouse event
1136 void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow* theWindow, QMouseEvent* theEvent )
1138 ActionMode aMode = getActionMode();
1139 if ( aMode != ModificationMode )
1141 // Emit selectionChanged() signal
1142 getOCCViewer()->performSelectionChanged();
1144 if ( aMode == AdditionMode )
1146 Handle(AIS_InteractiveContext) aCtx = getAISContext();
1147 if ( !aCtx.IsNull() )
1148 aCtx->ClearSelected( Standard_True );
1152 if (theEvent->button() != Qt::LeftButton) return;
1153 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
1155 // Initialize the ending point
1156 myEndPoint.setX( theEvent->x() );
1157 myEndPoint.setY( theEvent->y() );
1159 bool aHasShift = ( theEvent->modifiers() & Qt::ShiftModifier );
1161 // Highlight detected objects
1162 Handle(AIS_InteractiveContext) aCtx = getAISContext();
1163 if ( !aCtx.IsNull() )
1165 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
1170 aCtx->ClearCurrents( false ); // todo: deprecated OCCT API
1172 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
1173 if ( !aView3d.IsNull() )
1175 CurveCreator_Curve* Curve = ((CurveCreator_Curve*)myCurve);
1176 //if (!Curve->myCurSectInd.empty())
1178 aCtx->RemoveFilters();
1179 Handle(CurveCreator_ShapeFilter) filter = new CurveCreator_ShapeFilter();
1180 for (int i=0; i<Curve->myCurSectInd.size(); i++)
1182 int sectInd = Curve->myCurSectInd[i];
1183 const TopoDS_Shape& W = Curve->mySect2Shape(sectInd+1);
1184 TopExp_Explorer exp(W, TopAbs_VERTEX);
1185 for (;exp.More();exp.Next())
1186 filter->AddShape(exp.Current());
1188 aCtx->AddFilter(filter);
1189 #if OCC_VERSION_LARGE <= 0x07030000
1190 if (aCtx->HasOpenedContext())
1192 Handle(AIS_LocalContext) aLctx = aCtx->LocalContext();
1193 aLctx->Filter()->Clear();
1194 aLctx->AddFilter(filter);
1197 // TODO: check if something required
1201 // Initialize the single selection if start and end points are equal,
1202 // otherwise a rectangular selection.
1203 if ( myStartPoint == myEndPoint )
1205 aCtx->MoveTo( myEndPoint.x(), myEndPoint.y(), aView3d, Standard_True );
1207 aCtx->ShiftSelect( Standard_True );
1209 aCtx->Select( Standard_True );
1214 aCtx->ShiftSelect( myStartPoint.x(), myStartPoint.y(), myEndPoint.x(), myEndPoint.y(),
1215 aView3d, Standard_False );
1217 aCtx->Select( myStartPoint.x(), myStartPoint.y(), myEndPoint.x(), myEndPoint.y(),
1218 aView3d, Standard_False );
1223 if ( myDragStarted ) {
1224 CurveCreator_ICurve::SectionToPointList aDraggedPoints;
1225 QMap<CurveCreator_ICurve::SectionToPoint, CurveCreator::Coordinates > anInitialDragPointsCoords;
1227 aDraggedPoints = myDragPoints;
1228 anInitialDragPointsCoords = myInitialDragPointsCoords;
1231 setDragStarted( false );
1233 if ( aDraggedPoints.size() > 0 ) {
1234 // Collect old coordinates of the dragged points
1235 CurveCreator_ICurve::SectionToPointCoordsList anOldPoints;
1236 foreach ( const CurveCreator_ICurve::SectionToPoint aSectionToPoint, anInitialDragPointsCoords.keys() ) {
1237 CurveCreator::Coordinates aCoords = anInitialDragPointsCoords.value( aSectionToPoint );
1238 anOldPoints.push_back( std::make_pair( aSectionToPoint, aCoords ) );
1241 if ( myCurve->canPointsBeSorted() ) {
1242 // Add old coordinates of the curve points (except the dragged points) to the list
1243 for( int aSectionId = 0 ; aSectionId < myCurve->getNbSections() ; aSectionId++ ) {
1244 CurveCreator::Coordinates aCoords;
1245 for ( int aPointId = 0, aNb = myCurve->getNbPoints( aSectionId ); aPointId < aNb; aPointId++ ) {
1246 aCoords = myCurve->getPoint( aSectionId, aPointId );
1247 if ( aCoords.size() < 2 ) {
1251 CurveCreator_ICurve::SectionToPoint aSectionToPoint = std::make_pair( aSectionId, aPointId );
1253 if ( !anInitialDragPointsCoords.contains( aSectionToPoint ) ) {
1254 anOldPoints.push_back( std::make_pair( aSectionToPoint, aCoords ) );
1259 // Apply points sorting
1260 CurveCreator_ICurve::SectionToPointList aPoints;
1261 startCurveModification( aPoints, false );
1263 myCurve->setSkipSorting( false );
1265 CurveCreator_ICurve::SectionToPointCoordsList aCoordList;
1266 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aDraggedPoints.begin(),
1267 aLast = aDraggedPoints.end();
1268 for ( ; anIt != aLast; anIt++ ) {
1269 int aSectionId = anIt->first;
1270 int aPointId = anIt->second;
1271 CurveCreator::Coordinates aPos = myCurve->getPoint( aSectionId, aPointId );
1273 aCoordList.push_back(
1274 std::make_pair( std::make_pair( aSectionId, aPointId ), aPos ) );
1277 myCurve->setSeveralPoints( aCoordList, false );
1279 finishCurveModification( aDraggedPoints );
1281 // if the drag of some points has happened, restore the drag selection
1283 setSelectedPoints( aDraggedPoints );
1284 END_MEASURE_TIME( "drop" );
1287 // Save drag difference
1288 myCurve->saveCoordDiff( anOldPoints );
1291 else // check whether the segment is clicked an a new point should be added to the segment
1293 if ( myStartPoint.x() == myEndPoint.x() && myStartPoint.y() == myEndPoint.y() )
1294 insertPointToSelectedSegment( myEndPoint.x(), myStartPoint.y() );
1297 // updates the input panel table to show the selected point coordinates
1298 updateLocalPointView();
1303 * Manage mouse move events in Modification mode
1304 * \param theWindow an owner of the signal
1305 * \param theEvent a mouse event
1307 void CurveCreator_Widget::onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent )
1309 if ( getActionMode() != ModificationMode || !myDragStarted )
1312 QPoint aPos = theEvent->pos();
1313 if ( (aPos - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() )
1318 moveSelectedPoints( aPos.x(), aPos.y() );
1319 myDragStartPosition = aPos;
1321 END_MEASURE_TIME( "drag" );
1325 * Set zero viewer by the last view closed in
1326 * \param theManager a viewer manager
1328 void CurveCreator_Widget::onLastViewClosed( SUIT_ViewManager* /*theManager*/ )
1333 void CurveCreator_Widget::onMousePress( QMouseEvent* theEvent )
1335 onMousePress( 0, theEvent );
1338 void CurveCreator_Widget::onMouseRelease( QMouseEvent* theEvent )
1340 onMouseRelease( 0, theEvent );
1343 void CurveCreator_Widget::onMouseMove( QMouseEvent* theEvent )
1345 onMouseMove( 0, theEvent );
1348 void CurveCreator_Widget::onCellChanged( int theRow, int /*theColumn*/ )
1350 int aCurrSect = myLocalPointView->getSectionId( theRow );
1351 int aPntIndex = myLocalPointView->getPointId( theRow );
1353 if ( aPntIndex < 0 )
1356 CurveCreator_ICurve::SectionToPointList aSelPoints;
1357 startCurveModification( aSelPoints );
1359 double aX = myLocalPointView->item( theRow, 2 )->data( Qt::UserRole ).toDouble();
1360 double anY = myLocalPointView->item( theRow, 3 )->data( Qt::UserRole ).toDouble();
1361 CurveCreator::Coordinates aChangedPos;
1362 aChangedPos.push_back( aX );
1363 aChangedPos.push_back( anY );
1364 myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos );
1366 finishCurveModification( aSelPoints );
1370 * Removes a selected section from the curve. Updates undo/redo status
1372 void CurveCreator_Widget::removeSection()
1376 QList<int> aSections = mySectionView->getSelectedSections();
1377 for( int i = 0 ; i < aSections.size() ; i++ ){
1378 int aSectNum = aSections[i] - (i);
1379 myCurve->removeSection( aSectNum );
1380 mySectionView->sectionsRemoved( aSectNum );
1382 mySectionView->clearSelection();
1387 * Removes a selected points from the curve. Updates undo/redo status
1389 void CurveCreator_Widget::removePoint()
1391 CurveCreator_ICurve::SectionToPointList aPoints;
1392 getSelectedPoints( aPoints );
1393 if ( aPoints.size() == 0 )
1396 CurveCreator_ICurve::SectionToPointList aSelPoints;
1397 startCurveModification( aSelPoints, false );
1399 myCurve->removeSeveralPoints( aPoints );
1400 finishCurveModification( CurveCreator_ICurve::SectionToPointList() );
1401 mySectionView->reset();
1404 void CurveCreator_Widget::addNewPoint(const CurveCreator::Coordinates& theCoords)
1408 QList<int> aSections = mySectionView->getSelectedSections();
1409 if( aSections.size() == 0 ){
1412 int aSection = aSections[0];
1413 myCurve->addPoints(theCoords, aSection); // add to the end of section
1414 mySectionView->pointsAdded( aSection, myCurve->getNbPoints( aSection ) );
1415 updateActionsStates();
1419 void CurveCreator_Widget::insertPointToSelectedSegment( const int theX,
1422 Handle(AIS_InteractiveContext) aContext = getAISContext();
1424 OCCViewer_ViewPort3d* aViewPort = getViewPort();
1425 Handle(V3d_View) aView;
1427 aView = aViewPort->getView();
1429 if ( aContext.IsNull() || aView.IsNull() )
1432 gp_Pnt aPoint1, aPoint2;
1433 Handle(AIS_InteractiveObject) anAISObject = myCurve->getAISObject();
1434 bool isFoundPoint = CurveCreator_Utils::pointOnObject( aView, anAISObject, theX, theY,
1435 aPoint, aPoint1, aPoint2 );
1436 if ( !isFoundPoint )
1439 // insert the point to the model curve
1440 CurveCreator_ICurve::SectionToPointList aSelPoints;
1441 startCurveModification( aSelPoints );
1443 CurveCreator::Coordinates aCoords;
1444 aCoords.push_back( aPoint.X() );
1445 aCoords.push_back( aPoint.Y() );
1447 CurveCreator_ICurve::SectionToPointList aPoints1, aPoints2;
1448 findSectionsToPoints( aPoint1.X(), aPoint1.Y(), aPoints1 );
1449 findSectionsToPoints( aPoint2.X(), aPoint2.Y(), aPoints2 );
1450 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints1.begin(),
1451 aLast = aPoints1.end();
1452 int aSectionId = -1;
1453 // find the indices of the neighbour point
1454 // there can be a case when a new point is added into two sections
1455 int aPoint1Id = -1, aPoint2Id = -1;
1456 for ( ; anIt != aLast && aSectionId < 0; anIt++ ) {
1457 int aSectionCur = anIt->first;
1458 CurveCreator_ICurve::SectionToPointList::const_iterator anIt2 = aPoints2.begin(),
1459 aLast2 = aPoints2.end();
1460 for ( ; anIt2 != aLast2 && aSectionId < 0; anIt2++ ) {
1461 if ( anIt2->first == aSectionCur ) {
1462 aSectionId = aSectionCur;
1463 aPoint1Id = anIt->second;
1464 aPoint2Id = anIt2->second;
1469 int anInsertPos = -1;
1470 int aLastPoint = myCurve->getNbPoints( aSectionId )-1;
1471 if ( ( aPoint1Id == aLastPoint && aPoint2Id == 0 ) ||
1472 ( aPoint2Id == aLastPoint && aPoint1Id == 0 ) )
1473 anInsertPos = -1; // if the section happens between first and last points
1475 anInsertPos = aPoint1Id < aPoint2Id ? aPoint1Id + 1 : aPoint2Id + 1;
1477 myCurve->addPoints( aCoords, aSectionId, anInsertPos );
1478 mySectionView->pointsAdded( aSectionId, myCurve->getNbPoints( aSectionId ) );
1480 finishCurveModification( aSelPoints );
1482 setSelectedPoints();
1485 void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
1486 const int theYPosition )
1488 OCCViewer_ViewPort3d* aViewPort = getViewPort();
1492 CurveCreator_ICurve::SectionToPointList aPoints;
1493 startCurveModification( aPoints, false );
1495 gp_Pnt aStartPnt = CurveCreator_Utils::ConvertClickToPoint( myDragStartPosition.x(),
1496 myDragStartPosition.y(),
1497 aViewPort->getView() );
1498 gp_Pnt anEndPnt = CurveCreator_Utils::ConvertClickToPoint( theXPosition, theYPosition,
1499 aViewPort->getView() );
1500 double aXDelta = aStartPnt.X() - anEndPnt.X();
1501 double anYDelta = aStartPnt.Y() - anEndPnt.Y();
1503 CurveCreator_ICurve::SectionToPointCoordsList aCoordList;
1504 CurveCreator::Coordinates aChangedPos;
1505 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = myDragPoints.begin(),
1506 aLast = myDragPoints.end();
1507 for ( ; anIt != aLast; anIt++ ) {
1508 int aSectionId = anIt->first;
1509 int aPointId = anIt->second;
1510 aChangedPos = myCurve->getPoint( aSectionId, aPointId );
1511 if ( aChangedPos.size() < 2 )
1514 // Remember drag points coordinates
1516 myInitialDragPointsCoords.insert( std::make_pair( aSectionId, aPointId ), aChangedPos );
1519 aChangedPos[0] = aChangedPos[0] - aXDelta;
1520 aChangedPos[1] = aChangedPos[1] - anYDelta;
1522 aCoordList.push_back(
1523 std::make_pair(std::make_pair( aSectionId, aPointId ),
1526 myCurve->setSeveralPoints( aCoordList, false );
1529 finishCurveModification( myDragPoints );
1532 void CurveCreator_Widget::updateLocalPointView()
1534 if ( myDragStarted )
1536 Handle(AIS_InteractiveContext) aContext = getAISContext();
1537 if ( aContext.IsNull() )
1540 CurveCreator_Utils::getSelectedPoints( aContext, myCurve, myLocalPoints );
1541 //int aNbPoints = myLocalPoints.size();
1543 //bool isRowLimit = aNbPoints > myLocalPointRowLimit;
1544 myLocalPointView->setVisible( getActionMode() == ModificationMode/* && !isRowLimit */);
1546 //if ( !isRowLimit ) {
1547 bool isBlocked = myLocalPointView->blockSignals(true);
1549 myLocalPointView->setLocalPointsToTable( myLocalPoints );
1551 myLocalPointView->blockSignals( isBlocked );
1558 void CurveCreator_Widget::setLocalPointContext( const bool theOpen, const bool isUpdateTable )
1560 CurveCreator_Utils::setLocalPointContext( myCurve, getAISContext(), theOpen );
1561 if ( !theOpen && isUpdateTable )
1562 updateLocalPointView();
1566 * Set drag operation started. Save the position and a list of dragged points
1567 * \param theState the drag operation state: started/finished
1568 * \param thePoint the start drag position
1570 void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& thePoint )
1573 getSelectedPoints( myDragPoints );
1575 myDragStarted = myDragPoints.size();
1576 myDragStartPosition = thePoint;
1577 if ( myDragStarted ) {
1578 // change a viewer interaction style in order to avoid a select rectangle build
1579 myDragInteractionStyle = changeInteractionStyle( SUIT_ViewModel::KEY_FREE );
1580 myCurve->setSkipSorting( true );
1584 if ( myDragStarted )
1585 changeInteractionStyle( myDragInteractionStyle );
1586 myDragStarted = false;
1587 myDragPoints.clear();
1588 myInitialDragPointsCoords.clear();
1593 void CurveCreator_Widget::getSelectedPoints( CurveCreator_ICurve::SectionToPointList& thePoints )
1596 thePoints = myLocalPoints;
1599 void CurveCreator_Widget::setSelectedPoints( const CurveCreator_ICurve::SectionToPointList& thePoints )
1601 if ( myDragStarted )
1603 Handle(AIS_InteractiveContext) aContext = getAISContext();
1604 if ( aContext.IsNull() )
1607 CurveCreator_Utils::setSelectedPoints( aContext, myCurve, thePoints );
1609 updateLocalPointView();
1612 void CurveCreator_Widget::stopActionMode()
1614 setActionMode( NoneMode );
1618 * Get viewer information before perform the curve modification.
1619 * Take a list of selected cuve points an close local context.
1620 * The context should be closed because the curve presentation is
1621 * redisplayed and if it is not closed, when we close the local context
1622 * later, the presentation shown in the local context is disappeared.
1623 * \param thePoints an output list of curve selected points
1624 * \param theFillPoints a flag whether the selection list should be filled
1626 void CurveCreator_Widget::startCurveModification(
1627 CurveCreator_ICurve::SectionToPointList& thePoints,
1628 const bool theFillPoints )
1630 if ( theFillPoints ) {
1632 getSelectedPoints( thePoints );
1634 setLocalPointContext( false );
1638 * Restore the viewer state after the curve modification is done.
1639 * Open local context and select given points inside it.
1640 * \param thePoints a list of curve selected points
1642 void CurveCreator_Widget::finishCurveModification(
1643 const CurveCreator_ICurve::SectionToPointList& thePoints )
1645 if ( getActionMode() == ModificationMode )
1646 setLocalPointContext( true );
1647 setSelectedPoints( thePoints );
1652 * Returns a point index in the model curve by the point coordinates in the viewer
1653 * \param theX the X coordinate of the point
1654 * \param theY the Y coordinate of the point
1656 int CurveCreator_Widget::findLocalPointIndex( int theSectionId, double theX, double theY )
1658 return CurveCreator_UtilsICurve::findLocalPointIndex( myCurve, theSectionId, theX, theY );
1661 void CurveCreator_Widget::findSectionsToPoints( const double theX, const double theY,
1662 CurveCreator_ICurve::SectionToPointList& thePoints )
1664 return CurveCreator_UtilsICurve::findSectionsToPoints( myCurve, theX, theY, thePoints );
1667 void CurveCreator_Widget::convert( const CurveCreator_ICurve::SectionToPointList& thePoints,
1668 QMap<int, QList<int> >& theConvPoints )
1670 return CurveCreator_UtilsICurve::convert( thePoints, theConvPoints );
1674 * Returns whether the container has the value
1675 * \param theList a container of values
1676 * \param theValue a value
1678 bool CurveCreator_Widget::contains( const CurveCreator_ICurve::SectionToPointList& theList,
1679 const CurveCreator_ICurve::SectionToPoint& theValue ) const
1681 return CurveCreator_UtilsICurve::contains( theList, theValue );