1 |
#include <stdlib.h> |
2 |
#include <stdio.h> |
3 |
#include <string.h> |
4 |
#include <iostream> |
5 |
|
6 |
#include "RigidBodyStamp.hpp" |
7 |
|
8 |
char RigidBodyStamp::errMsg[500]; |
9 |
|
10 |
RigidBodyStamp::RigidBodyStamp(){ |
11 |
|
12 |
unhandled = NULL; |
13 |
have_position = 0; |
14 |
have_orientation = 0; |
15 |
have_atoms = 0; |
16 |
have_extras = 0; |
17 |
} |
18 |
|
19 |
RigidBodyStamp::~RigidBodyStamp(){ |
20 |
int i; |
21 |
|
22 |
if( unhandled != NULL ) delete unhandled; |
23 |
|
24 |
if( atoms != NULL ){ |
25 |
for( i=0; i<n_atoms; i++ ) delete atoms[i]; |
26 |
} |
27 |
} |
28 |
|
29 |
void RigidBodyStamp::setPosition( double x, double y, double z ){ |
30 |
|
31 |
pos[0] = x; |
32 |
pos[1] = y; |
33 |
pos[2] = z; |
34 |
|
35 |
// Do I tell atoms about this? |
36 |
|
37 |
have_position = 1; |
38 |
} |
39 |
|
40 |
void RigidBodyStamp::setOrientation( double phi, double theta, double psi ){ |
41 |
|
42 |
// in order of application (see Goldstein) |
43 |
|
44 |
ornt[0] = phi; |
45 |
ornt[1] = theta; |
46 |
ornt[2] = psi; |
47 |
|
48 |
// Do I tell atoms about this? |
49 |
|
50 |
have_orientation = 1; |
51 |
} |
52 |
|
53 |
char* RigidBodyStamp::assignString( char* lhs, char* rhs ){ |
54 |
|
55 |
if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs ); |
56 |
else unhandled->add( lhs, rhs ); |
57 |
have_extras = 1; |
58 |
return NULL; |
59 |
} |
60 |
|
61 |
char* RigidBodyStamp::assignDouble( char* lhs, double rhs ){ |
62 |
int i; |
63 |
|
64 |
if( !strcmp( lhs, "nAtoms" ) ){ |
65 |
n_atoms = (int)rhs; |
66 |
|
67 |
if( have_atoms ){ |
68 |
sprintf( errMsg, |
69 |
"RigidBodyStamp error, n_atoms already declared" |
70 |
" for this RigidBody.\n"); |
71 |
return strdup( errMsg ); |
72 |
} |
73 |
have_atoms = 1; |
74 |
atoms = new AtomStamp*[n_atoms]; |
75 |
for( i=0; i<n_atoms; i++ ) atoms[i] = NULL; |
76 |
} |
77 |
else { |
78 |
if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs ); |
79 |
else unhandled->add( lhs, rhs ); |
80 |
have_extras = 1; |
81 |
} |
82 |
return NULL; |
83 |
} |
84 |
|
85 |
char* RigidBodyStamp::assignInt( char* lhs, int rhs ){ |
86 |
int i; |
87 |
|
88 |
if( !strcmp( lhs, "nAtoms" ) ){ |
89 |
n_atoms = rhs; |
90 |
|
91 |
if( have_atoms ){ |
92 |
sprintf( errMsg, |
93 |
"RigidBodyStamp error, n_atoms already declared for" |
94 |
" this RigidBody.\n"); |
95 |
return strdup( errMsg ); |
96 |
} |
97 |
have_atoms = 1; |
98 |
atoms = new AtomStamp*[n_atoms]; |
99 |
for( i=0; i<n_atoms; i++ ) atoms[i] = NULL; |
100 |
} |
101 |
else { |
102 |
if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs ); |
103 |
else unhandled->add( lhs, rhs ); |
104 |
have_extras = 1; |
105 |
} |
106 |
return NULL; |
107 |
} |
108 |
|
109 |
char* RigidBodyStamp::addAtom( AtomStamp* the_atom, int atomIndex ){ |
110 |
|
111 |
if( have_atoms && atomIndex < n_atoms ) atoms[atomIndex] = the_atom; |
112 |
else{ |
113 |
if( have_atoms ){ |
114 |
sprintf( errMsg, "RigidBodyStamp error, %d out of nAtoms range", |
115 |
atomIndex ); |
116 |
return strdup( errMsg ); |
117 |
} |
118 |
else return strdup("RigidBodyStamp error, nAtoms not given before" |
119 |
"first atom declaration." ); |
120 |
} |
121 |
return NULL; |
122 |
} |
123 |
|
124 |
char* RigidBodyStamp::checkMe( void ){ |
125 |
|
126 |
int i; |
127 |
short int no_atom; |
128 |
|
129 |
if( !have_atoms ){ |
130 |
return strdup( "RigidBodyStamp error. RigidBody contains no atoms." ); |
131 |
} |
132 |
|
133 |
no_atom = 0; |
134 |
for( i=0; i<n_atoms; i++ ){ |
135 |
if( atoms[i] == NULL ) no_atom = 1; |
136 |
} |
137 |
|
138 |
if( no_atom ){ |
139 |
sprintf( errMsg, |
140 |
"RigidBodyStamp error. Not all of the atoms were" |
141 |
" declared in this RigidBody."); |
142 |
return strdup( errMsg ); |
143 |
} |
144 |
|
145 |
return NULL; |
146 |
|
147 |
} |