]> SALOME platform Git repositories - modules/geom.git/blob - src/CurveCreator/CurveCreator_NewPointDlg.cxx
Salome HOME
CurveCreator was updated
[modules/geom.git] / src / CurveCreator / CurveCreator_NewPointDlg.cxx
1 #include "CurveCreator_NewPointDlg.h"\r
2 #include <QGridLayout>\r
3 #include <QVBoxLayout>\r
4 #include <QLabel>\r
5 #include <QDoubleSpinBox>\r
6 #include <QDialogButtonBox>\r
7 #include <QDoubleValidator>\r
8 #include <QRegExpValidator>\r
9 #include <QAbstractButton>\r
10 #include <QPushButton>\r
11 #include <QLocale>\r
12 \r
13 CurveCreator_NewPointDlg::CurveCreator_NewPointDlg(CurveCreator::Dimension theDim, QWidget *parent) :\r
14     QDialog(parent), myX(NULL), myY(NULL), myZ(NULL), myIsEdit(false)\r
15 {\r
16     QGridLayout* aCoordLay = new QGridLayout();\r
17 \r
18     QString aTitle = QString(tr("ADD_NEW_POINT"));\r
19     setWindowTitle(aTitle);\r
20 \r
21     QLabel* aLbl = new QLabel( tr("X_COORD"), this);\r
22     myX = new QDoubleSpinBox(this);\r
23      aCoordLay->addWidget(aLbl, 0, 0);\r
24     aCoordLay->addWidget(myX, 0, 1 );\r
25 \r
26     aLbl = new QLabel( tr("Y_COORD"), this);\r
27     myY = new QDoubleSpinBox(this);\r
28     aCoordLay->addWidget(aLbl, 1, 0 );\r
29     aCoordLay->addWidget(myY, 1, 1 );\r
30 \r
31     if( theDim == CurveCreator::Dim3d ){\r
32         aLbl = new QLabel( tr("Z_COORD"), this);\r
33         myZ = new QDoubleSpinBox(this);\r
34          aCoordLay->addWidget(aLbl, 2,0 );\r
35         aCoordLay->addWidget(myZ, 2,1 );\r
36     }\r
37 \r
38     myBtnBox = new QDialogButtonBox(this);\r
39     myAddBtn = myBtnBox->addButton(tr("ADD_BTN"), QDialogButtonBox::AcceptRole );\r
40     myContBtn = myBtnBox->addButton(tr("ADD_CONTINUE_BTN"), QDialogButtonBox::ResetRole );\r
41     myBtnBox->addButton(tr("CANCEL"), QDialogButtonBox::RejectRole );\r
42 \r
43     connect( myBtnBox, SIGNAL(accepted()), this, SLOT(accept()));\r
44     connect( myBtnBox, SIGNAL(rejected()), this, SLOT(reject()));\r
45     connect( myBtnBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(onBtnClicked(QAbstractButton*) ));\r
46     QVBoxLayout* aMainLay = new QVBoxLayout();\r
47     aMainLay->addLayout(aCoordLay);\r
48     aMainLay->addWidget(myBtnBox);\r
49     setLayout(aMainLay);\r
50     clear();\r
51     updateTitle();\r
52 }\r
53 \r
54 void CurveCreator_NewPointDlg::setSectionName( const QString& theName )\r
55 {\r
56     mySectionName = theName;\r
57     updateTitle();\r
58 }\r
59 \r
60 void CurveCreator_NewPointDlg::setEditMode( bool isEdit )\r
61 {\r
62     myIsEdit = isEdit;\r
63     if( myIsEdit ){\r
64         myContBtn->hide();\r
65         myAddBtn->setText(tr("OK"));\r
66     }\r
67     else{\r
68         myContBtn->show();\r
69         myAddBtn->setText(tr("ADD_BTN"));\r
70     }\r
71     updateTitle();\r
72 }\r
73 \r
74 void CurveCreator_NewPointDlg::updateTitle()\r
75 {\r
76     QString aTitle;\r
77     if( !myIsEdit ){\r
78         if( mySectionName.isEmpty() ){\r
79             aTitle = tr("ADD_NEW_POINT");\r
80         }\r
81         else{\r
82             aTitle = QString(tr("ADD_NEW_POINT_TO_%1")).arg(mySectionName);\r
83         }\r
84     }\r
85     else{\r
86         aTitle = tr("SET_POINT_COORDINATES");\r
87     }\r
88     setWindowTitle(aTitle);\r
89 }\r
90 \r
91 CurveCreator::Coordinates CurveCreator_NewPointDlg::getCoordinates() const\r
92 {\r
93     CurveCreator::Coordinates aCoords;\r
94     double anX = myX->value();\r
95     aCoords.push_back(anX);\r
96     double anY = myY->value();\r
97     aCoords.push_back(anY);\r
98     if( myZ ){\r
99         double aZ = myZ->value();\r
100         aCoords.push_back(aZ);\r
101     }\r
102     return aCoords;\r
103 }\r
104 \r
105 void CurveCreator_NewPointDlg::onBtnClicked(QAbstractButton* theBtn )\r
106 {\r
107     if( myBtnBox->buttonRole(theBtn) == QDialogButtonBox::ResetRole ){\r
108         emit addPoint();\r
109     }\r
110 }\r
111 \r
112 void CurveCreator_NewPointDlg::clear()\r
113 {\r
114     initSpinBox(myX);\r
115     initSpinBox(myY);\r
116     if( myZ )\r
117         initSpinBox(myZ);\r
118 }\r
119 \r
120 void CurveCreator_NewPointDlg::setCoordinates( const CurveCreator::Coordinates& theCoords )\r
121 {\r
122     double anX = theCoords[0];\r
123     myX->setValue(anX);\r
124     double anY = theCoords[1];\r
125     myY->setValue(anY);\r
126     if( myZ && ( theCoords.size() == 3)){\r
127         double aZ = theCoords[2];\r
128         myZ->setValue(aZ);\r
129     }\r
130 }\r
131 \r
132 //=======================================================================\r
133 // function: initSpinBox\r
134 // purpose:\r
135 //=======================================================================\r
136 void CurveCreator_NewPointDlg::initSpinBox(QDoubleSpinBox *theSpinBox)\r
137 {\r
138   const double aCoordMin  = -1.e+15;\r
139   const double aCoordMax  = 1.e+15;\r
140   const double aStep      = 10;\r
141   const int    aPrecision = 6;\r
142 \r
143   theSpinBox->setDecimals( qAbs( aPrecision ) );\r
144   theSpinBox->setRange(aCoordMin, aCoordMax);\r
145   theSpinBox->setSingleStep(aStep);\r
146   theSpinBox->setValue(0.0);\r
147 }\r