Salome HOME
Copyright update 2021
[samples/atomic.git] / src / ATOMICGUI / ATOMICGUI_AddAtomOp.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_AddAtomOp.h"
21 #include "ATOMICGUI_AddAtomDlg.h"
22 #include "ATOMICGUI_DataModel.h"
23 #include "ATOMICGUI.h"
24
25 #include <LightApp_Module.h>
26 #include <LightApp_Application.h>
27 #include <SUIT_Desktop.h>
28
29 /*! Constructor */
30 ATOMICGUI_AddAtomOp::ATOMICGUI_AddAtomOp()
31   : ATOMICGUI_Operation(),
32     myDlg( 0 )
33 {
34 }
35
36 /*! Destructor */
37 ATOMICGUI_AddAtomOp::~ATOMICGUI_AddAtomOp()
38 {
39   if ( myDlg )
40     delete myDlg;
41 }
42
43 /*! Returns Operation dialog */
44 LightApp_Dialog* ATOMICGUI_AddAtomOp::dlg() const
45 {
46   if ( !myDlg )
47     const_cast<ATOMICGUI_AddAtomOp*>( this )->myDlg = new ATOMICGUI_AddAtomDlg( module()->getApp()->desktop() );
48
49   return myDlg;
50 }
51
52 /*! slot, called when user presses Apply button of the dialog */
53 void ATOMICGUI_AddAtomOp::onApply()
54 {
55   QStringList entries;
56   atomModule()->selected( entries, false );
57   ATOMICGUI_AddAtomDlg* d = dynamic_cast<ATOMICGUI_AddAtomDlg*>( dlg() );
58   if( dataModel() && d && d->acceptData( entries ) )
59   {
60     QString name;
61     double x, y, z;
62     d->data( name, x, y, z );
63     dataModel()->addAtom( entries.first(), name, x, y, z );
64     module()->getApp()->updateObjectBrowser();
65   }
66 }
67