some fixes to the cmake files. It still is not working
[kdeedu-porting.git] / kalzium / libavogadro-kalzium / src / primitive.h
blob2e8a09eb1d49405b749744939858513652e217ce
1 /**********************************************************************
2 Primitive - Wrapper class around the OpenBabel classes
4 Copyright (C) 2007 Donald Ephraim Curtis
6 This file is part of the Avogadro molecular editor project.
7 For more information, see <http://avogadro.sourceforge.net/>
9 Avogadro is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 Avogadro is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 02110-1301, USA.
23 **********************************************************************/
25 #ifndef __PRIMITIVE_H
26 #define __PRIMITIVE_H
28 #include <avogadro/global.h>
30 #include <openbabel/mol.h>
32 #include <QAbstractItemModel>
34 #include <eigen/vector.h>
36 class QReadWriteLock;
38 namespace Avogadro {
40 /**
41 * @class Primitive
42 * Base class for all primitives (Molecule, Atom, Bond, Residue, ...).
45 class PrimitivePrivate;
46 class A_EXPORT Primitive : public QObject
48 Q_OBJECT
49 Q_PROPERTY(Type type READ type)
50 Q_ENUMS(Type)
52 public:
53 /**
54 * This enum allows us to iterate through the various types
55 * of primitives.
57 enum Type {
58 /// Untyped Primitive
59 OtherType=0,
60 /// Molecule Primitive
61 MoleculeType,
62 /// Atom Primitive
63 AtomType,
64 /// Bond Primitive
65 BondType,
66 /// Residue Primitive
67 ResidueType,
68 /// Chain Primitive (i.e., a set of residues)
69 ChainType,
70 /// Surface Primitive
71 SurfaceType,
72 /// Plane Primitive
73 PlaneType,
74 /// Grid Primitive
75 GridType,
76 /// Points (i.e., non-atoms)
77 PointType,
78 /// Vectors (i.e., arrows, dipole moments)
79 VectorType,
80 /// Non-bonded interactions (i.e., non-bond connections)
81 NonbondedType,
82 /// Text annoations
83 TextType,
84 /// End Placeholder
85 LastType,
86 /// First Placeholder
87 FirstType=OtherType
91 /**
92 * Default constructor.
93 * @param parent the object parent
95 Primitive(QObject *parent = 0);
96 /**
97 * Constructor
98 * @param type the primitive type
99 * @param parent the object parent
101 explicit Primitive(Type type, QObject *parent=0);
103 * Deconstructor
105 virtual ~Primitive();
108 * Function used to push changes to a primitive to
109 * the rest of the system. At this time there is no
110 * way (other than this) to generate a signal when
111 * properties of a primitive change.
113 * In the case of the Atom primitive, this should be called
114 * when changes to coordinates have been made.
116 void update();
119 * @property Type
120 * Holds the primitive type
124 * @return the primitive type (one of Primitive::Type)
126 Type type() const;
128 QReadWriteLock *lock();
130 Q_SIGNALS:
132 * Emitted when the primitive has been updated.
134 void updated();
136 protected:
137 PrimitivePrivate * const d_ptr;
138 Primitive(PrimitivePrivate &dd, QObject *parent = 0);
139 Primitive(PrimitivePrivate &dd, Type type, QObject *parent=0);
141 private:
142 Q_DECLARE_PRIVATE(Primitive);
147 * @class Atom
148 * @brief Atom Class
149 * @author Donald Ephraim Curtis
151 * The Atom class is a Primitive subclass that provides a wrapper around
152 * OpenBabel::OBAtom. This class is provided to give more control of
153 * the OpenBabel::OBAtom class through slots/signals provided by the
154 * Primitive superclass.
156 class A_EXPORT Atom : public Primitive, public OpenBabel::OBAtom
158 Q_OBJECT
160 public:
162 * Constructor
164 * @param parent the object parent.
166 Atom(QObject *parent=0) : Primitive(AtomType, parent), OpenBabel::OBAtom() { }
168 /** Returns the position of the atom, as a Eigen::Vector3d. This is similar to
169 * the OBAtom::GetVector() method, which returns the position as a OpenBabel::vector3.
171 * Rationale for inlining: this method only does a cast on the return value of OBAtom::GetVector().
172 * The memory layouts of the types between which it casts are not likely to change: both
173 * types represent 3D vectors of doubles, and there's only one sane way to represent them:
174 * struct{ double x,y,z; }.
176 * @return OBAtom::GetVector() but reinterpret_casted as a const Eigen::Vector3d &
178 inline const Eigen::Vector3d &pos () const
180 return *reinterpret_cast<const Eigen::Vector3d*>(&GetVector());
183 /** Sets the position of the atom, from a Eigen::Vector3d. This is similar to
184 * the OBAtom::SetVector() method, which sets the position from a OpenBabel::vector3.
186 * Rationale for inlining: this method only does a cast on the argument of OBAtom::SetVector().
187 * The memory layouts of the types between which it casts are not likely to change: both
188 * types represent 3D vectors of doubles, and there's only one sane way to represent them:
189 * struct{ double x,y,z; }.
191 inline void setPos(const Eigen::Vector3d &vec)
193 SetVector( *reinterpret_cast<const OpenBabel::vector3*>(&vec) );
198 * @class Bond
199 * @brief Bond Class
200 * @author Donald Ephraim Curtis
202 * The Bond class is a Primitive subclass that provides a wrapper around
203 * OpenBabel::OBBond. This class is provided to give more control of
204 * the OpenBabel::OBBond class through slots/signals provided by the
205 * Primitive superclass.
207 class A_EXPORT Bond : public Primitive, public OpenBabel::OBBond
209 Q_OBJECT
211 public:
213 * Constructor
215 * @param parent the object parent.
217 Bond(QObject *parent=0): Primitive(BondType, parent), OpenBabel::OBBond() { }
221 * @class Residue
222 * @brief Residue Class
223 * @author Donald Ephraim Curtis
225 * The Residue class is a Primitive subclass that provides a wrapper around
226 * OpenBabel::OBResidue. This class is provided to give more control of
227 * the OpenBabel::OBResidue class through slots/signals provided by the
228 * Primitive superclass.
230 class A_EXPORT Residue : public Primitive, public OpenBabel::OBResidue
232 Q_OBJECT
234 public:
236 * Constructor
238 * @param parent the object parent.
240 Residue(QObject *parent=0): Primitive(ResidueType, parent), OpenBabel::OBResidue() { }
244 * @class Molecule
245 * @brief Molecule Class
246 * @author Donald Ephraim Curtis
248 * The Molecule class implements the OpenBabel::OBMol virtual functions
249 * in order to not only use our primitive objects but also to provide signals
250 * based on internal OpenBabel actions. In terms of a Model-View architecture,
251 * this is our model class and is used by our various views to hold
252 * all required data.
254 class MoleculePrivate;
255 class A_EXPORT Molecule : public Primitive, public OpenBabel::OBMol
257 Q_OBJECT
259 public:
261 * Constructor
263 * @param parent the object parent.
265 Molecule(QObject *parent=0);
266 Molecule(const Molecule &other);
267 virtual ~Molecule();
268 void update();
271 * Virtual function inherited from OpenBabel::OBMol.
272 * Creates a new Atom object.
274 * @return pointer to a newly allocated Atom object
276 Atom *CreateAtom(void);
279 * Virtual function inherited from OpenBabel::OBMol.
280 * Creates a new Bond object.
282 * @return pointer to a newly allocated Bond object
284 Bond * CreateBond(void);
287 * Virtual function inherited from OpenBabel::OBMol.
288 * Creates a new Residue object.
290 * @return pointer to a newly allocated Residue object
292 Residue * CreateResidue(void);
295 * Virtual function inherited from OpenBabel::OBMol.
296 * Deletes an Atom object.
298 * @param atom the atom to delete
300 void DestroyAtom(OpenBabel::OBAtom* atom);
303 * Virtual function inherited from OpenBabel::OBMol.
304 * Deletes an Bond object.
306 * @param atom the bond to delete
308 void DestroyBond(OpenBabel::OBBond* bond);
311 * Virtual function inherited from OpenBabel::OBMol.
312 * Deletes an Residue object.
314 * @param atom the residue to delete
316 void DestroyResidue(OpenBabel::OBResidue* residue);
318 const Eigen::Vector3d & center() const;
319 const Eigen::Vector3d & normalVector() const;
320 const double & radius() const;
321 const Atom *farthestAtom() const;
323 Molecule& operator=(const Molecule& other);
325 Molecule& operator+=(const Molecule& other);
327 private:
328 /* shared d_ptr with Primitive */
329 Q_DECLARE_PRIVATE(Molecule);
331 void computeGeomInfo() const;
333 private Q_SLOTS:
335 * Function which handles when a child primitive has been
336 * updated. The response is to find the sender object
337 * and then emit a signal passing the sender as a parameter.
339 * @sa primitiveAdded
340 * @sa primitiveUpdated
341 * @sa primitiveRemoved
343 void updatePrimitive();
345 Q_SIGNALS:
347 * Emitted when a child primitive is added.
349 * @param primitive pointer to the primitive that was added
351 void primitiveAdded(Primitive *primitive);
353 * Emitted when a child primitive is updated.
355 * @param primitive pointer to the primitive that was updated
357 void primitiveUpdated(Primitive *primitive);
359 * Emitted when a child primitive is deleted.
361 * @param primitive pointer to the primitive that was updated before it is free'd
363 void primitiveRemoved(Primitive *primitive);
366 } // namespace Avogadro
368 Q_DECLARE_METATYPE(Avogadro::Primitive*);
370 #endif // __PRIMITIVES_H