Salome HOME
Copyright update 2021
[samples/atomic.git] / src / ATOMICGUI / ATOMICGUI_AddAtomDlg.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ATOMICGUI_AddAtomDlg.h"
21 #include <qlayout.h>
22 #include <qlineedit.h>
23 #include <qlabel.h>
24 #include <QtxDoubleSpinBox.h>
25
26 #define DBL_MAX 1000.0
27
28 /*! Constructor */
29 ATOMICGUI_AddAtomDlg::ATOMICGUI_AddAtomDlg( QWidget* parent )
30 : LightApp_Dialog( parent, 0, false, true, OK | Apply | Close )
31 {
32   setWindowTitle( tr( "CAPTION" ) );
33
34   QGridLayout* main = new QGridLayout( mainFrame() );
35
36   QLabel* xn = new QLabel( tr( "ATOMIC_ATOM" ) + ":", mainFrame() );
37   myName = new QLineEdit( mainFrame() );
38
39   QLabel* xl = new QLabel( "X:", mainFrame() );
40   myX = new QtxDoubleSpinBox( -DBL_MAX, DBL_MAX, 1, mainFrame() );
41   myX->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
42
43   QLabel* yl = new QLabel( "Y:", mainFrame() );
44   myY = new QtxDoubleSpinBox( -DBL_MAX, DBL_MAX, 1, mainFrame() );
45   myY->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
46
47   QLabel* zl = new QLabel( "Z:", mainFrame() );
48   myZ = new QtxDoubleSpinBox( -DBL_MAX, DBL_MAX, 1, mainFrame() );
49   myZ->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
50
51   main->addWidget( xn,      0, 0 );
52   main->addWidget( myName,  0, 1 );
53   main->addWidget( xl,  1, 0 );
54   main->addWidget( myX, 1, 1 );
55   main->addWidget( yl,  2, 0 );
56   main->addWidget( myY, 2, 1 );
57   main->addWidget( zl,  3, 0 );
58   main->addWidget( myZ, 3, 1 );
59
60   setButtonPosition( Right, Close );
61
62   myX->setValue( 0 );
63   myY->setValue( 0 );
64   myZ->setValue( 0 );
65 }
66
67 /*! Destructor */
68 ATOMICGUI_AddAtomDlg::~ATOMICGUI_AddAtomDlg()
69 {
70 }
71
72 /*! Validates data. */
73 bool ATOMICGUI_AddAtomDlg::acceptData( const QStringList& selected ) const
74 {
75   // check selection
76   if( selected.count()!=1 )
77     return false;
78
79   // check entered data
80   return !myName->text().toLatin1().trimmed().isEmpty();
81 }
82
83 /*! Returns values of dialog widgets. */
84 void ATOMICGUI_AddAtomDlg::data( QString& name, double& x, double& y, double& z ) const
85 {
86   name = myName->text().toLatin1().trimmed();
87   x = myX->value();
88   y = myY->value();
89   z = myZ->value();
90 }