1 // Copyright (C) 2013-2014 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 "CurveCreator_NewPointDlg.h"
22 #include <QGridLayout>
23 #include <QVBoxLayout>
25 #include <QDoubleSpinBox>
26 #include <QDialogButtonBox>
27 #include <QDoubleValidator>
28 #include <QRegExpValidator>
29 #include <QAbstractButton>
30 #include <QPushButton>
33 CurveCreator_NewPointDlg::CurveCreator_NewPointDlg(CurveCreator::Dimension theDim, QWidget *parent) :
34 QWidget(parent), myX(NULL), myY(NULL), myZ(NULL), myIsEdit(false), myDim(theDim),
35 myIsInstantSketchingEnabled(false)
37 QString aTitle = QString(tr("ADD_NEW_POINT"));
38 setWindowTitle(aTitle);
40 QFrame* aFrame = new QFrame( this );
41 QVBoxLayout* aLayout = new QVBoxLayout( aFrame );
43 QFrame* aCoordFrame = new QFrame( aFrame );
44 QGridLayout* aCoordLayout = new QGridLayout( aCoordFrame );
46 QLabel* aLbl = new QLabel( tr("X_COORD"), this);
47 myX = new QDoubleSpinBox(this);
48 aCoordLayout->addWidget(aLbl, 0, 0);
49 aCoordLayout->addWidget(myX, 0, 1 );
51 aLbl = new QLabel( tr("Y_COORD"), this);
52 myY = new QDoubleSpinBox(this);
53 aCoordLayout->addWidget(aLbl, 1, 0 );
54 aCoordLayout->addWidget(myY, 1, 1 );
56 myZLabel = new QLabel( tr("Z_COORD"), this);
57 myZ = new QDoubleSpinBox(this);
58 aCoordLayout->addWidget(myZLabel, 2,0 );
59 aCoordLayout->addWidget(myZ, 2,1 );
61 if( theDim != CurveCreator::Dim3d ){
66 myBtnFrame = new QFrame( aFrame );
67 QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame );
69 myAddBtn = new QPushButton( tr( "ADD_BTN" ), myBtnFrame );
70 myCancelBtn = new QPushButton( tr( "CANCEL" ), myBtnFrame );
72 connect( myCancelBtn, SIGNAL( clicked() ), this, SIGNAL( cancelPoint() ) );
74 aBtnsLayout->addWidget( myAddBtn );
75 aBtnsLayout->addStretch( 1 );
76 aBtnsLayout->addWidget( myCancelBtn );
78 aLayout->addWidget( aCoordFrame, 0 );
79 aLayout->addWidget( myBtnFrame, 1 );
85 void CurveCreator_NewPointDlg::setSectionName( const QString& theName )
87 mySectionName = theName;
91 void CurveCreator_NewPointDlg::setEditMode( bool isEdit )
95 myAddBtn->setText(tr("OK"));
96 myAddBtn->disconnect( SIGNAL( clicked() ) );
97 connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( modifyPoint() ) );
100 myAddBtn->setText(tr("ADD_BTN"));
101 myAddBtn->disconnect( SIGNAL( clicked() ) );
102 connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addPoint() ) );
107 void CurveCreator_NewPointDlg::updateTitle()
111 if( mySectionName.isEmpty() ){
112 aTitle = tr("ADD_NEW_POINT");
115 aTitle = QString(tr("ADD_NEW_POINT_TO_%1")).arg(mySectionName);
119 aTitle = tr("SET_POINT_COORDINATES");
121 setWindowTitle(aTitle);
124 CurveCreator::Coordinates CurveCreator_NewPointDlg::getCoordinates() const
126 CurveCreator::Coordinates aCoords;
127 double anX = myX->value();
128 aCoords.push_back(anX);
129 double anY = myY->value();
130 aCoords.push_back(anY);
131 if( myDim == CurveCreator::Dim3d ){
132 double aZ = myZ->value();
133 aCoords.push_back(aZ);
138 void CurveCreator_NewPointDlg::clear()
145 void CurveCreator_NewPointDlg::setDimension(CurveCreator::Dimension theDim)
147 if( theDim == CurveCreator::Dim2d ){
157 void CurveCreator_NewPointDlg::setCoordinates( const CurveCreator::Coordinates& theCoords )
159 double anX = theCoords[0];
161 double anY = theCoords[1];
163 if( theCoords.size() == 3 ){
164 double aZ = theCoords[2];
167 if( isInstantSketchingEnabled() )
171 bool CurveCreator_NewPointDlg::isInstantSketchingEnabled() const
173 return myIsInstantSketchingEnabled;
176 void CurveCreator_NewPointDlg::setInstantSketchingEnabled( const bool theState )
178 myIsInstantSketchingEnabled = theState;
181 //=======================================================================
182 // function: initSpinBox
184 //=======================================================================
185 void CurveCreator_NewPointDlg::initSpinBox(QDoubleSpinBox *theSpinBox)
187 const double aCoordMin = -1.e+15;
188 const double aCoordMax = 1.e+15;
189 const double aStep = 10;
190 const int aPrecision = 6;
192 theSpinBox->setDecimals( qAbs( aPrecision ) );
193 theSpinBox->setRange(aCoordMin, aCoordMax);
194 theSpinBox->setSingleStep(aStep);
195 theSpinBox->setValue(0.0);