Salome HOME
418e23d0cd12df695311c7009cd2626240b21a55
[samples/atomic.git] / src / ATOMICGUI / ATOMICGUI_AddAtomDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21
22 #include <ATOMICGUI_AddAtomDlg.h>
23 #include <qlayout.h>
24 #include <qlineedit.h>
25 #include <qlabel.h>
26 #include <QtxDoubleSpinBox.h>
27
28 #define DBL_MAX 1000.0
29
30 /*! Constructor */
31 ATOMICGUI_AddAtomDlg::ATOMICGUI_AddAtomDlg( QWidget* parent )
32 : LightApp_Dialog( parent, 0, false, true, OK | Apply | Close )
33 {
34   setWindowTitle( tr( "CAPTION" ) );
35
36   QGridLayout* main = new QGridLayout( mainFrame() );
37
38   QLabel* xn = new QLabel( tr( "ATOMIC_ATOM" ) + ":", mainFrame() );
39   myName = new QLineEdit( mainFrame() );
40
41   QLabel* xl = new QLabel( "X:", mainFrame() );
42   myX = new QtxDoubleSpinBox( -DBL_MAX, DBL_MAX, 1, mainFrame() );
43   myX->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
44
45   QLabel* yl = new QLabel( "Y:", mainFrame() );
46   myY = new QtxDoubleSpinBox( -DBL_MAX, DBL_MAX, 1, mainFrame() );
47   myY->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
48
49   QLabel* zl = new QLabel( "Z:", mainFrame() );
50   myZ = new QtxDoubleSpinBox( -DBL_MAX, DBL_MAX, 1, mainFrame() );
51   myZ->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
52
53   main->addWidget( xn,      0, 0 );
54   main->addWidget( myName,  0, 1 );
55   main->addWidget( xl,  1, 0 );
56   main->addWidget( myX, 1, 1 );
57   main->addWidget( yl,  2, 0 );
58   main->addWidget( myY, 2, 1 );
59   main->addWidget( zl,  3, 0 );
60   main->addWidget( myZ, 3, 1 );
61
62   setButtonPosition( Right, Close );
63
64   myX->setValue( 0 );
65   myY->setValue( 0 );
66   myZ->setValue( 0 );
67 }
68
69 /*! Destructor */
70 ATOMICGUI_AddAtomDlg::~ATOMICGUI_AddAtomDlg()
71 {
72 }
73
74 /*! Validates data. */
75 bool ATOMICGUI_AddAtomDlg::acceptData( const QStringList& selected ) const
76 {
77   // check selection
78   if( selected.count()!=1 )
79     return false;
80
81   // check entered data
82   return !myName->text().toLatin1().trimmed().isEmpty();
83 }
84
85 /*! Returns values of dialog widgets. */
86 void ATOMICGUI_AddAtomDlg::data( QString& name, double& x, double& y, double& z ) const
87 {
88   name = myName->text().toLatin1().trimmed();
89   x = myX->value();
90   y = myY->value();
91   z = myZ->value();
92 }