]> SALOME platform Git repositories - modules/geom.git/blob - src/CurveCreator/CurveCreator_Widget.cpp
Salome HOME
CurveCreator was updated
[modules/geom.git] / src / CurveCreator / CurveCreator_Widget.cpp
1 #include "CurveCreator_Widget.h"\r
2 #include "CurveCreator_TreeView.h"\r
3 #include "QVBoxLayout"\r
4 #include "CurveCreator_Curve.hxx"\r
5 #include "CurveCreator_CurveEditor.hxx"\r
6 #include "CurveCreator.hxx"\r
7 #include "CurveCreator_NewPointDlg.h"\r
8 #include "CurveCreator_NewSectionDlg.h"\r
9 \r
10 #include <QHBoxLayout>\r
11 #include <QVBoxLayout>\r
12 #include <QLabel>\r
13 #include <QLineEdit>\r
14 #include <QGroupBox>\r
15 #include <QToolButton>\r
16 #include <QToolBar>\r
17 #include <QAction>\r
18 #include <QMenu>\r
19 \r
20 CurveCreator_Widget::CurveCreator_Widget(QWidget *parent) :\r
21     QWidget(parent), myNewPointEditor(NULL)\r
22 {\r
23 //TODO remove it for debug only\r
24     myCurve = new CurveCreator_Curve(CurveCreator::Dim2d);\r
25     myEdit = new CurveCreator_CurveEditor( myCurve );\r
26     CurveCreator::Coordinates aCoords;\r
27 \r
28     aCoords.push_back(10);\r
29     aCoords.push_back(20);\r
30     aCoords.push_back(1);\r
31     aCoords.push_back(2);\r
32 \r
33     myEdit->addSection("",CurveCreator::BSpline, true, aCoords );\r
34 \r
35     aCoords.clear();\r
36     aCoords.push_back(11);\r
37     aCoords.push_back(21);\r
38     aCoords.push_back(111);\r
39     aCoords.push_back(211);\r
40     aCoords.push_back(101);\r
41     aCoords.push_back(201);\r
42     aCoords.push_back(13);\r
43     aCoords.push_back(25);\r
44     myEdit->addSection("",CurveCreator::Polyline, false, aCoords );\r
45 \r
46     aCoords.clear();\r
47     for( int i = 0 ; i < 1000000 ; i++ ){\r
48         double anX = ((double)i)/10000.;\r
49         double anY = ((double)i)/10000. + 3.4;\r
50         aCoords.push_back(anX);\r
51         aCoords.push_back(anY);\r
52     }\r
53     myEdit->addSection("",CurveCreator::Polyline, true, aCoords );\r
54 \r
55 //TODO end debug\r
56     myNewPointEditor = new CurveCreator_NewPointDlg(myCurve->getDimension(), this);\r
57     connect( myNewPointEditor, SIGNAL(addPoint()), this, SLOT(onAddNewPoint()));\r
58 \r
59     myNewSectionEditor = new CurveCreator_NewSectionDlg(this);\r
60     connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()));\r
61 \r
62     QHBoxLayout* aNameLayout = new QHBoxLayout();\r
63     QLabel* aNameLabel = new QLabel(tr("CURVE_NAME_TLT"), this);\r
64     aNameLayout->addWidget(aNameLabel);\r
65     QLineEdit* aNameEdit = new QLineEdit(this);\r
66     aNameLayout->addWidget(aNameEdit);\r
67 \r
68     QGroupBox* aSectionGroup = new QGroupBox(tr("SECTION_GROUP_TLT"),this);\r
69 \r
70     mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup);\r
71     connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) );\r
72     connect( mySectionView, SIGNAL(pointEntered(int,int)), this, SLOT(onEditPoint(int,int)) );\r
73     connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) );\r
74     connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) );\r
75     QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup);\r
76 //    QToolButton* anUndoBtn = new QToolButton(aTB);\r
77     QAction* anAct = createAction( UNDO_ID, tr("UNDO"), tr(":images/ICON_UNDO"), tr("UNDO_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Z) );\r
78     aTB->addAction(anAct);\r
79 \r
80     anAct = createAction( REDO_ID, tr("REDO"), tr(":images/ICON_REDO"), tr("REDO_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Y) );\r
81     aTB->addAction(anAct);\r
82 \r
83     aTB->addSeparator();\r
84 \r
85     anAct = createAction( NEW_SECTION_ID, tr("ICON_NEW_SECTION"), tr(":images/ICON_NEW_SECTION"), tr("NEW_SECTION_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_N) );\r
86     connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) );\r
87     aTB->addAction(anAct);\r
88 \r
89     anAct = createAction( INSERT_SECTION_BEFORE_ID, tr("INSERT_SECTION_BEFORE"), tr(":images/ICON_INSERT_SECTION_BEFORE"), tr("INSERT_SECTION_BEFORE_TLT"),\r
90                           QKeySequence(Qt::ControlModifier | Qt::Key_Insert ) );\r
91     connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertSectionBefore()) );\r
92 \r
93     anAct = createAction( INSERT_SECTION_AFTER_ID, tr("INSERT_SECTION_AFTER"), tr(":images/ICON_INSERT_SECTION_AFTER"), tr("INSERT_SECTION_AFTER_TLT"),\r
94                           QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Insert ) );\r
95     connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertSectionAfter()) );\r
96 \r
97     anAct = createAction( NEW_POINT_ID, tr("ICON_NEW_POINT"), tr(":images/ICON_NEW_POINT"), tr("NEW_POINT_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_P) );\r
98     connect(anAct, SIGNAL(triggered()), this, SLOT(onNewPoint()) );\r
99     aTB->addAction(anAct);\r
100     aTB->addSeparator();\r
101 \r
102     anAct = createAction( INSERT_POINT_BEFORE_ID, tr("INSERT_POINT_BEFORE"), tr(":images/ICON_POINT_BEFORE"), tr("INSERT_POINT_BEFORE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_B) );\r
103     connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertPointBefore()) );\r
104 \r
105     anAct = createAction( INSERT_POINT_AFTER_ID, tr("INSERT_POINT_AFTER"), tr(":images/ICON_POINT_AFTER"), tr("INSERT_POINT_AFTER_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_M) );\r
106     connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertPointAfter()) );\r
107 \r
108     anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), tr(":images/ICON_CLOSE_SECTIONS"), tr("CLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_W) );\r
109     connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) );\r
110 \r
111     anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), tr(":images/ICON_UNCLOSE_SECTIONS"), tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) );\r
112     connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) );\r
113 \r
114     anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"), tr(":images/ICON_POLYLINE"), tr("SET_POLYLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_E) );\r
115     connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) );\r
116 \r
117     anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), tr(":images/ICON_SPLINE"), tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) );\r
118     connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) );\r
119 \r
120     anAct = createAction( REMOVE_ID, tr("ICON_REMOVE"), tr(":images/ICON_REMOVE"), tr("REMOVE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) );\r
121     connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) );\r
122     aTB->addAction(anAct);\r
123     aTB->addSeparator();\r
124 \r
125     anAct = createAction( JOIN_ID, tr("ICON_JOIN"), tr(":images/ICON_JOIN"), tr("JOIN_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) );\r
126     connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) );\r
127     aTB->addAction(anAct);\r
128     aTB->addSeparator();\r
129 \r
130     anAct = createAction( UP_ID, tr("ICON_STEP_UP"), tr(":images/ICON_STEP_UP"), tr("STEP_UP_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Up ) );\r
131     connect( anAct, SIGNAL(triggered()), this, SLOT(onMoveUp()) );\r
132     aTB->addAction(anAct);\r
133 \r
134     anAct = createAction( DOWN_ID, tr("ICON_STEP_DOWN"), tr(":images/ICON_STEP_DOWN"), tr("STEP_DOWN"), QKeySequence(Qt::ControlModifier|Qt::Key_Down ) );\r
135     connect( anAct, SIGNAL(triggered()), this, SLOT(onMoveDown()) );\r
136     aTB->addAction(anAct);\r
137 \r
138     anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), tr(":images/ICON_CLEAR_ALL"), tr("CLEAR_ALL_TLT"), QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) );\r
139     connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) );\r
140     aTB->addAction(anAct);\r
141 \r
142     anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), tr(":images/ICON_JOIN_ALL"), tr("JOIN_ALL_TLT"), QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) );\r
143     connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) );\r
144     aTB->addAction(anAct);\r
145 \r
146     QVBoxLayout* aSectLayout = new QVBoxLayout();\r
147     aSectLayout->addWidget(aTB);\r
148     aSectLayout->addWidget(mySectionView);\r
149     aSectionGroup->setLayout(aSectLayout);\r
150     QVBoxLayout* aLay = new QVBoxLayout();\r
151     aLay->addLayout(aNameLayout);\r
152     aLay->addWidget(aSectionGroup);\r
153     setLayout(aLay);\r
154     onSelectionChanged();\r
155 }\r
156 \r
157 void CurveCreator_Widget::onSelectionChanged()\r
158 {\r
159     QList<ActionId> anEnabledAct;\r
160     anEnabledAct << NEW_SECTION_ID;\r
161     int aSectCnt = myCurve->getNbPoints();\r
162     if( aSectCnt > 0 )\r
163         anEnabledAct << CLEAR_ALL_ID;\r
164     if( aSectCnt > 1 )\r
165         anEnabledAct << JOIN_ALL_ID;\r
166     QList<int> aSelSections = mySectionView->getSelectedSections();\r
167     QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints();\r
168     CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();\r
169     switch( aSelType ){\r
170     case CurveCreator_TreeView::ST_NOSEL:{\r
171         break;\r
172     }\r
173     case CurveCreator_TreeView::ST_SECTIONS:{\r
174         if( aSelSections.size() > 1 ){\r
175             anEnabledAct << JOIN_ID;\r
176         }\r
177         if( aSelSections[0] > 0 ){\r
178             anEnabledAct << UP_ID;\r
179         }\r
180         if( aSelSections.size() == 1 ){\r
181             anEnabledAct << NEW_POINT_ID << INSERT_SECTION_BEFORE_ID << INSERT_SECTION_AFTER_ID;\r
182         }\r
183         if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){\r
184             anEnabledAct << DOWN_ID;\r
185         }\r
186         anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID;\r
187         break;\r
188     }\r
189     case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{\r
190         if( aSelPoints[0].second > 0 ){\r
191             anEnabledAct << UP_ID;\r
192         }\r
193         int aLastIndex = aSelPoints.size()-1;\r
194         int aSect = aSelPoints[0].first;\r
195         if( aSelPoints[aLastIndex].second < (myCurve->getNbPoints(aSect) - 1)){\r
196             anEnabledAct << DOWN_ID;\r
197         }\r
198         if( aSelPoints.size() == 1){\r
199             anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID;\r
200         }\r
201         break;\r
202     }\r
203     }\r
204     int aSelObjsCnt = aSelPoints.size() + aSelSections.size();\r
205     if( aSelObjsCnt > 0 ){\r
206         anEnabledAct << REMOVE_ID;\r
207     }\r
208     if( myCurve->getNbSections() > 0 ){\r
209         anEnabledAct << REMOVE_ALL_ID;\r
210     }\r
211     if( myCurve->getNbSections() > 1 ){\r
212         anEnabledAct << JOIN_ALL_ID;\r
213     }\r
214     QList<ActionId> anIds = myActionMap.keys();\r
215     for( int i = 0 ; i < anIds.size() ; i++ ){\r
216         if( myActionMap.contains(anIds[i]) ){\r
217             if( anEnabledAct.contains(anIds[i]) ){\r
218                 myActionMap[anIds[i]]->setEnabled(true);\r
219             }\r
220             else{\r
221                 myActionMap[anIds[i]]->setEnabled(false);\r
222             }\r
223         }\r
224     }\r
225 }\r
226 \r
227 void CurveCreator_Widget::onNewPoint()\r
228 {\r
229     mySection= -1;\r
230     myPointNum = -1;\r
231     QList<int> aSelSection = mySectionView->getSelectedSections();\r
232     if( aSelSection.size() > 0 ){\r
233         mySection = aSelSection[0];\r
234     }\r
235     else{\r
236         QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();\r
237         if( aSelPoints.size() > 0 ){\r
238             mySection = aSelPoints[0].first;\r
239             myPointNum = aSelPoints[0].second + 1;\r
240         }\r
241     }\r
242     QString aSectName;\r
243     if( mySection < 0 ){\r
244         mySection = myCurve->getNbSections() - 1;\r
245     }\r
246     aSectName = QString::fromStdString( myCurve->getSectionName(mySection));\r
247     if( myPointNum < 0 ){\r
248         myPointNum = myCurve->getNbPoints(mySection);\r
249     }\r
250     myNewPointEditor->clear();\r
251     myNewPointEditor->setEditMode(false);\r
252     myNewPointEditor->setSectionName(aSectName);\r
253     if( myNewPointEditor->exec() == QDialog::Accepted ){\r
254         onAddNewPoint();\r
255     }\r
256 }\r
257 \r
258 void CurveCreator_Widget::onAddNewPoint()\r
259 {\r
260     CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates();\r
261     myEdit->insertPoints(aCoords, mySection, myPointNum );\r
262     mySectionView->pointsAdded( mySection, myPointNum );\r
263     myNewPointEditor->clear();\r
264     myPointNum++;\r
265 }\r
266 \r
267 void CurveCreator_Widget::onNewSection()\r
268 {\r
269     myNewSectionEditor->clear();\r
270     myNewSectionEditor->setEditMode(false);\r
271     QString aSectName = QString( myCurve->getUnicSectionName().c_str() );\r
272     myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline );\r
273     if( myNewSectionEditor->exec() == QDialog::Accepted ){\r
274         onAddNewSection();\r
275     }\r
276 }\r
277 \r
278 void CurveCreator_Widget::onAddNewSection()\r
279 {\r
280     CurveCreator::Coordinates aCoords;\r
281     myEdit->addSection( myNewSectionEditor->getName().toStdString(), myNewSectionEditor->getSectionType(),\r
282                         myNewSectionEditor->isClosed(), aCoords  );\r
283     mySectionView->sectionAdded( mySection );\r
284     QString aNewName = QString(myCurve->getUnicSectionName().c_str());\r
285     myNewSectionEditor->setSectionName(aNewName);\r
286     mySection++;\r
287 }\r
288 \r
289 QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QString& theImageName,\r
290                                             const QString& theToolTip, const QKeySequence& theShortcut )\r
291 {\r
292     QAction* anAct = new QAction(theName,this);\r
293     QIcon anIcon(theImageName);\r
294     if( !anIcon.isNull() ){\r
295         anAct->setIcon(anIcon);\r
296     }\r
297     anAct->setShortcut(theShortcut);\r
298     anAct->setToolTip(theToolTip);\r
299     myActionMap[theId] = anAct;\r
300     return anAct;\r
301 }\r
302 \r
303 QAction* CurveCreator_Widget::getAction(ActionId theId)\r
304 {\r
305     if( myActionMap.contains(theId) )\r
306         return myActionMap[theId];\r
307     return NULL;\r
308 }\r
309 \r
310 void CurveCreator_Widget::onEditSection( int theSection )\r
311 {\r
312     mySection = theSection;\r
313     QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));\r
314     bool isClosed = myCurve->isClosed(theSection);\r
315     CurveCreator::Type aType = myCurve->getType(theSection);\r
316     myNewSectionEditor->setEditMode(true);\r
317     myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType );\r
318     if( myNewSectionEditor->exec() == QDialog::Accepted ){\r
319         QString aName = myNewSectionEditor->getName();\r
320         bool    isClosed = myNewSectionEditor->isClosed();\r
321         CurveCreator::Type aSectType = myNewSectionEditor->getSectionType();\r
322         myEdit->setClosed( isClosed, mySection );\r
323         myEdit->setName( aName.toStdString(), mySection );\r
324         myEdit->setType( aSectType, mySection );\r
325         mySectionView->sectionChanged(mySection);\r
326     }\r
327 }\r
328 \r
329 void CurveCreator_Widget::onEditPoint( int theSection, int thePoint )\r
330 {\r
331     if( !myNewPointEditor ){\r
332     }\r
333     QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection));\r
334     myNewPointEditor->setEditMode(true);\r
335     myNewPointEditor->setSectionName(aSectName);\r
336     CurveCreator::Coordinates aCoords = myCurve->getCoordinates(theSection,thePoint);\r
337     myNewPointEditor->setCoordinates(aCoords);\r
338     if( myNewPointEditor->exec() == QDialog::Accepted ){\r
339         aCoords = myNewPointEditor->getCoordinates();\r
340         myEdit->setCoordinates(aCoords, theSection, thePoint);\r
341         mySectionView->pointDataChanged(theSection, thePoint );\r
342     }\r
343 }\r
344 \r
345 void CurveCreator_Widget::onJoin()\r
346 {\r
347     QList<int> aSections = mySectionView->getSelectedSections();\r
348     if( aSections.size() == 0 ){\r
349         return;\r
350     }\r
351     int aMainSect = aSections[0];\r
352     int aMainSectSize = myCurve->getNbPoints(aMainSect);\r
353     for( int i = 1 ; i < aSections.size() ; i++ ){\r
354         int aSectNum = aSections[i] - (i-1);\r
355         myEdit->join( aMainSect, aSectNum );\r
356         mySectionView->sectionsRemoved( aSectNum );\r
357     }\r
358     int aNewSectSize = myCurve->getNbPoints(aMainSect);\r
359     if( aNewSectSize != aMainSectSize )\r
360         mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );\r
361 }\r
362 \r
363 void CurveCreator_Widget::onRemove()\r
364 {\r
365     QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();\r
366     int aCurrSect=-1;\r
367     int aRemoveCnt = 0;\r
368     for( int i = 0 ; i < aSelPoints.size() ; i++ ){\r
369         if( aCurrSect != aSelPoints[i].first ){\r
370             aRemoveCnt = 0;\r
371             aCurrSect = aSelPoints[i].first;\r
372         }\r
373         int aPntIndx = aSelPoints[i].second - aRemoveCnt;\r
374         myEdit->removePoints(aCurrSect,aPntIndx, 1);\r
375         mySectionView->pointsRemoved( aCurrSect, aPntIndx );\r
376         aRemoveCnt++;\r
377     }\r
378     QList<int> aSections = mySectionView->getSelectedSections();\r
379     for( int i = 0 ; i < aSections.size() ; i++ ){\r
380         int aSectNum = aSections[i] - (i);\r
381         myEdit->removeSection( aSectNum );\r
382         mySectionView->sectionsRemoved( aSectNum );\r
383     }\r
384     mySectionView->clearSelection();\r
385 }\r
386 \r
387 void CurveCreator_Widget::onMoveUp()\r
388 {\r
389     if( mySectionView->getSelectionType() == CurveCreator_TreeView::ST_SECTIONS ){\r
390 //Move sections\r
391         QList<int> aSections = mySectionView->getSelectedSections();\r
392         for( int i = 0 ; i < aSections.size() ; i++ ){\r
393             int anIndx = aSections[i];\r
394             myEdit->moveSection( anIndx, anIndx-1);\r
395             mySectionView->sectionsSwapped( anIndx, -1 );\r
396         }\r
397     }\r
398     else{\r
399 //Move points\r
400         QList< QPair<int,int> > aPoints = mySectionView->getSelectedPoints();\r
401         for( int i = 0 ; i < aPoints.size() ; i++ ){\r
402             int aSection = aPoints[i].first;\r
403             int aPoint = aPoints[i].second;\r
404             myEdit->movePoint(aSection, aPoint, aPoint-2);\r
405             mySectionView->pointsSwapped( aSection, aPoint, -1 );\r
406         }\r
407     }\r
408 }\r
409 \r
410 void CurveCreator_Widget::onMoveDown()\r
411 {\r
412     if( mySectionView->getSelectionType() == CurveCreator_TreeView::ST_SECTIONS ){\r
413 //Move sections\r
414         QList<int> aSections = mySectionView->getSelectedSections();\r
415         for( int i = aSections.size()-1 ; i >=0 ; i-- ){\r
416             int anIndx = aSections[i];\r
417             myEdit->moveSection( anIndx, anIndx+1);\r
418             mySectionView->sectionsSwapped( anIndx, 1 );\r
419         }\r
420     }\r
421     else{\r
422 //Move points\r
423         QList< QPair<int,int> > aPoints = mySectionView->getSelectedPoints();\r
424         for( int i = aPoints.size() - 1; i >= 0 ; i--  ){\r
425             int aSection = aPoints[i].first;\r
426             int aPoint = aPoints[i].second;\r
427             myEdit->movePoint(aSection, aPoint, aPoint+1);\r
428             mySectionView->pointsSwapped( aSection, aPoint, 1 );\r
429         }\r
430     }\r
431 }\r
432 \r
433 void CurveCreator_Widget::onClearAll()\r
434 {\r
435     myEdit->clear();\r
436     mySectionView->reset();\r
437     onSelectionChanged();\r
438 }\r
439 \r
440 void CurveCreator_Widget::onJoinAll()\r
441 {\r
442     myEdit->join();\r
443     mySectionView->reset();\r
444     onSelectionChanged();\r
445 }\r
446 \r
447 void CurveCreator_Widget::onInsertSectionBefore()\r
448 {\r
449 \r
450 }\r
451 \r
452 void CurveCreator_Widget::onInsertSectionAfter()\r
453 {\r
454 \r
455 }\r
456 \r
457 void CurveCreator_Widget::onInsertPointBefore()\r
458 {\r
459 \r
460 }\r
461 \r
462 void CurveCreator_Widget::onInsertPointAfter()\r
463 {\r
464 \r
465 }\r
466 \r
467 void CurveCreator_Widget::onUndoSettings()\r
468 {\r
469 \r
470 }\r
471 \r
472 void CurveCreator_Widget::onSetSpline()\r
473 {\r
474     QList<int> aSelSections = mySectionView->getSelectedSections();\r
475     for( int i = 0 ; i < aSelSections.size() ; i++ ){\r
476         myEdit->setType(CurveCreator::BSpline, aSelSections[i]);\r
477         mySectionView->sectionChanged(aSelSections[i]);\r
478     }\r
479 }\r
480 \r
481 void CurveCreator_Widget::onSetPolyline()\r
482 {\r
483     QList<int> aSelSections = mySectionView->getSelectedSections();\r
484     for( int i = 0 ; i < aSelSections.size() ; i++ ){\r
485         myEdit->setType(CurveCreator::Polyline, aSelSections[i]);\r
486         mySectionView->sectionChanged(aSelSections[i]);\r
487     }\r
488 }\r
489 \r
490 void CurveCreator_Widget::onCloseSections()\r
491 {\r
492     QList<int> aSelSections = mySectionView->getSelectedSections();\r
493     for( int i = 0 ; i < aSelSections.size() ; i++ ){\r
494         myEdit->setClosed(true, aSelSections[i]);\r
495         mySectionView->sectionChanged(aSelSections[i]);\r
496     }\r
497 }\r
498 \r
499 void CurveCreator_Widget::onUncloseSections()\r
500 {\r
501     QList<int> aSelSections = mySectionView->getSelectedSections();\r
502     for( int i = 0 ; i < aSelSections.size() ; i++ ){\r
503         myEdit->setClosed(false, aSelSections[i]);\r
504         mySectionView->sectionChanged(aSelSections[i]);\r
505     }\r
506 }\r
507 \r
508 void CurveCreator_Widget::onContextMenu( QPoint thePoint )\r
509 {\r
510     QList<ActionId> aContextActions;\r
511     aContextActions << CLEAR_ALL_ID << JOIN_ALL_ID << SEPARATOR_ID <<\r
512                        INSERT_SECTION_BEFORE_ID << INSERT_SECTION_AFTER_ID << SEPARATOR_ID <<\r
513                        CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID <<\r
514                        SET_SECTIONS_SPLINE_ID << SEPARATOR_ID <<\r
515                        INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID;\r
516     QPoint aGlPoint = mySectionView->mapToGlobal(thePoint);\r
517     bool isVis = false;\r
518     QList<ActionId> aResAct;\r
519     for( int i = 0 ; i < aContextActions.size() ; i++ ){\r
520         if( aContextActions[i] != SEPARATOR_ID ){\r
521             if( myActionMap.contains(aContextActions[i]) ){\r
522                 QAction* anAct = myActionMap[aContextActions[i]];\r
523                 if( anAct->isEnabled() ){\r
524                     aResAct << aContextActions[i];\r
525                     isVis = true;\r
526                 }\r
527             }\r
528         }\r
529         else{\r
530             aResAct << SEPARATOR_ID;\r
531         }\r
532     }\r
533     if( !isVis )\r
534         return;\r
535 \r
536     QMenu* aMenu = new QMenu(this);\r
537     for( int i = 0 ; i < aResAct.size() ; i++ ){\r
538         if( aResAct[i] == SEPARATOR_ID ){\r
539             aMenu->addSeparator();\r
540         }\r
541         else{\r
542             QAction* anAct = myActionMap[aResAct[i]];\r
543             aMenu->insertAction(NULL, anAct);\r
544         }\r
545     }\r
546     aMenu->exec(aGlPoint);\r
547 }\r