Victor
 All Data Structures Functions Variables Friends Pages
Component.h
1 /* This file is part of Victor.
2 
3  Victor is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Victor 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
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with Victor. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 
18 #ifndef _COMPONENT_H_
19 #define _COMPONENT_H_
20 
21 // Includes:
22 #include <vector>
23 #include <string>
24 #include <Bond.h>
25 #include <Loader.h>
26 #include <Saver.h>
27 #include <vector3.h>
28 #include <Visitor.h>
29 
30 // Global constants, typedefs, etc. (to avoid):
31 
32 
33 namespace Victor { namespace Biopool {
34 
39  class Component : public Bond {
40  public:
41 
42  // CONSTRUCTORS/DESTRUCTOR:
43  Component(unsigned int mI = 2, unsigned int mO = 2);
44  Component(const Component& orig);
45  virtual ~Component();
46 
47  // PREDICATES:
48  unsigned int size() const;
49  virtual string getClassName() const = 0;
50  unsigned int getDepth() const;
51 
52  virtual vgVector3<double> getLowerBound(double dist = 0.0);
53  virtual vgVector3<double> getUpperBound(double dist = 0.0);
54  bool collides(Component& other, double dist = 0.0);
55 
56 
57  virtual vgVector3<double> getTrans() const = 0;
58  virtual vgMatrix3<double> getRot() const = 0;
59 
60  Component& getSuperior();
61  bool hasSuperior() const;
62  bool inSync(); // coords in-sync with changes?
63 
64  virtual void save(Saver& s) = 0; // data saver
65 
66  // MODIFIERS:
67 
68  virtual void connectIn(Component* c, unsigned int offset = 1);
69  virtual void connectOut(Component* c, unsigned int offset = 1);
70  virtual Component* unconnectIn();
71  virtual Component* unconnectOut();
72 
73  virtual void insertComponent(Component* c) = 0;
74  virtual void removeComponent(Component* c) = 0;
75  virtual void deleteComponent(Component* c) = 0;
76 
77  void copy(const Component& orig);
78  virtual Component* clone() = 0;
79  virtual void load(Loader& l) = 0; // data loader
80 
81  virtual void setTrans(vgVector3<double> t) = 0;
82  virtual void addTrans(vgVector3<double> t) = 0;
83  virtual void setRot(vgMatrix3<double> r) = 0;
84  virtual void addRot(vgMatrix3<double> r) = 0;
85  virtual void sync() = 0; // synchronize coords with structure
86  virtual void setModified();
87 
88  void setSuperior(Component* c);
89  // ought to be 'protected' but the compiler will not handle
90  // it correctly, if it is ?!
91 
92  virtual void acceptCalculator(EnergyVisitor* v) = 0;
93  virtual void acceptOptimizer(OptimizationVisitor* v) = 0;
94 
95  // OPERATORS:
96  Component& operator=(const Component& orig);
97 
98  protected:
99 
100  // HELPERS:
101  virtual void resetBoundaries() = 0;
102 
103  void setLowerBound(vgVector3<double> _lb);
104  void setUpperBound(vgVector3<double> _ub);
105 
106  // ATTRIBUTES:
107 
108  Component* superior;
109  vector<Component*> components;
110  vgVector3<double> lowerBound; // lower bound for bounding box
111  vgVector3<double> upperBound; // upper bound for bounding box
112  bool modified; // component modified?
113 
114  private:
115 
116  };
117 
118 
119  // ---------------------------------------------------------------------------
120  // Component
121  // -----------------x-------------------x-------------------x-----------------
122 
123  // PREDICATES:
124 
125  inline unsigned int
126  Component::size() const {
127  return components.size();
128  }
129 
130  inline unsigned int
131  Component::getDepth() const {
132  if (superior != NULL)
133  return superior->getDepth() + 1;
134  else
135  return 0;
136  }
137 
138 
146  inline bool
147  Component::collides(Component& other, double dist) {
148  return ( (lowerBound.x <= other.upperBound.x + dist)
149  || (lowerBound.y <= other.upperBound.y + dist)
150  || (lowerBound.z <= other.upperBound.z + dist)
151  || (upperBound.x >= other.lowerBound.x - dist)
152  || (upperBound.y >= other.lowerBound.y - dist)
153  || (upperBound.z >= other.lowerBound.z - dist));
154  }
155 
156  inline Component&
157  Component::getSuperior() {
158  if (superior != NULL)
159  return *superior;
160  else {
161  DEBUG_MSG("Component::getSuperior() Warning: no superior found.");
162  return *this;
163  }
164  }
165 
166  inline bool
167  Component::hasSuperior() const {
168  return (superior != NULL);
169  }
170 
176  inline bool
178  return (!modified && (!hasSuperior() || (getSuperior().inSync())));
179  }
180 
181  // MODIFIERS:
182 
183  inline void Component::setModified() {
184  if (modified)
185  return;
186  modified = true;
187  if (hasSuperior())
188  getSuperior().setModified();
189  }
190 
191  // OPERATORS:
192 
193  // HELPERS:
194 
195  inline void
196  Component::setSuperior(Component* c) {
197  superior = c;
198  }
199 
200  inline void
201  Component::setLowerBound(vgVector3<double> _lb) {
202  lowerBound = _lb;
203  }
204 
205  inline void
206  Component::setUpperBound(vgVector3<double> _ub) {
207  upperBound = _ub;
208  }
209 
210 }} //namespace
211 #endif //_COMPONENT_H_
212 
Defines chemical and abstract bonds between objects which are compositions of atoms.
Definition: Bond.h:37
Base class for saving components (Atoms, Groups, etc.).
Definition: Saver.h:39
Base class for composite structures.
Definition: Component.h:39
Base class for loading components (Atoms, Groups, etc.).
Definition: Loader.h:39
Base class implementing the visitor pattern.
Definition: Visitor.h:38
bool collides(Component &other, double dist=0.0)
Definition: Component.h:147
Base class Optimizacion Patter.
Definition: Visitor.h:66
void copy(const Component &orig)
Definition: Component.cc:101
virtual vgVector3< double > getUpperBound(double dist=0.0)
Definition: Component.cc:65
virtual vgVector3< double > getLowerBound(double dist=0.0)
Definition: Component.cc:51
bool inSync()
Definition: Component.h:177