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