Salome HOME
0d02c22ec25cb35321ea363d84402a2fe6bfde93
[samples/atomic.git] / ATOMIC_SRC / src / ATOMICGUI / ATOMICGUI_Data.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_Data.h"
23 #include <qobject.h>
24
25 int ATOMICGUI_AtomicMolecule::myMaxId       = 0;
26 int ATOMICGUI_AtomicMolecule::Atom::myMaxId = 0;
27
28 /*! Constructor of Atom */
29 ATOMICGUI_AtomicMolecule::Atom::Atom()
30   : myName( QString::null ), myX( 0. ), myY( 0. ), myZ( 0. ) 
31 {
32   myId = ++myMaxId;
33 }
34
35 /*! Constructor of Atom */
36 ATOMICGUI_AtomicMolecule::Atom::Atom( const QString& name, 
37                                   const double x, 
38                                   const double y, 
39                                   const double z )
40   : myName( name ), myX( x ), myY( y ), myZ( z )
41 {
42   myId = ++myMaxId;
43 }
44
45 /*! Constructor of Molecule */
46 ATOMICGUI_AtomicMolecule::ATOMICGUI_AtomicMolecule( const QString& name )
47 {
48   myId = ++myMaxId;
49   myName = name.isEmpty() ? QObject::tr( "ATOMICGUI_NONAME" ) : name;
50 }
51
52 /*! Destructor of Molecule */
53 ATOMICGUI_AtomicMolecule::~ATOMICGUI_AtomicMolecule()
54 {
55 }
56
57 /*! Adds an atom to the molecule */
58 void ATOMICGUI_AtomicMolecule::addAtom( const QString& atom, 
59                                     const double   x, 
60                                     const double   y, 
61                                     const double   z )
62 {
63   myAtoms.append( Atom( atom, x, y, z ) ); 
64 }
65
66 /*! Removes an atom from molecule by index */
67 void ATOMICGUI_AtomicMolecule::deleteAtom( const int index )
68 {
69   if ( index >= 0 and index < myAtoms.count() )
70     myAtoms.removeAt( index );
71 }
72
73 /*! Gets an atom id by index */
74 int ATOMICGUI_AtomicMolecule::atomId( const int index ) const
75 {
76   if ( index >= 0 and index < myAtoms.count() )
77     return myAtoms[ index ].id();
78   return 0;
79 }
80
81 /*! Gets an atom name by index */
82 QString ATOMICGUI_AtomicMolecule::atomName( const int index ) const
83 {
84   QString n;
85   if ( index >= 0 and index < myAtoms.count() )
86     n = myAtoms[ index ].name();
87   return n;
88 }
89
90 /*! Gets an atom x coordinate by index */
91 double ATOMICGUI_AtomicMolecule::atomX( const int index ) const
92 {
93   if ( index >= 0 and index < myAtoms.count() )
94     return myAtoms[ index ].x();
95   return 0;
96 }
97
98 /*!  Gets an atom y coordinate by index */
99 double ATOMICGUI_AtomicMolecule::atomY( const int index ) const
100 {
101   if ( index >= 0 and index < myAtoms.count() )
102     return myAtoms[ index ].y();
103   return 0;
104 }
105
106 /*! Gets an atom z coordinate by index */
107 double ATOMICGUI_AtomicMolecule::atomZ( const int index ) const
108 {
109   if ( index >= 0 and index < myAtoms.count() )
110     return myAtoms[ index ].z();
111   return 0;
112 }
113
114 /*! Sets a name to the molecule or atom */
115 void ATOMICGUI_AtomicMolecule::setName( const QString& name, const int index )
116 {
117   if ( index < 0 )
118     myName = name;
119   else if ( index >= 0 and index < myAtoms.count() )
120     myAtoms[ index ].myName = name;
121 }