[c67518] | 1 | /*
|
---|
| 2 | * GLMoleculeObject_molecule.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Mar 30, 2012
|
---|
| 5 | * Author: ankele
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef GLMOLECULEOBJECT_MOLECULE_HPP_
|
---|
| 9 | #define GLMOLECULEOBJECT_MOLECULE_HPP_
|
---|
| 10 |
|
---|
| 11 | // include config.h
|
---|
| 12 | #ifdef HAVE_CONFIG_H
|
---|
| 13 | #include <config.h>
|
---|
| 14 | #endif
|
---|
| 15 |
|
---|
| 16 | #include "GLMoleculeObject.hpp"
|
---|
| 17 |
|
---|
[6c16a0] | 18 | #include <Qt3D/qgeometrydata.h>
|
---|
| 19 |
|
---|
[7c7c4a] | 20 | #include <vector>
|
---|
| 21 | #include <boost/any.hpp>
|
---|
[8688ef] | 22 | #include <boost/function.hpp>
|
---|
[7c7c4a] | 23 |
|
---|
[6c16a0] | 24 | #include "CodePatterns/Cacheable.hpp"
|
---|
[c67518] | 25 | #include "CodePatterns/Observer/Observer.hpp"
|
---|
[6c16a0] | 26 | #include "CodePatterns/ObservedValue.hpp"
|
---|
[c67518] | 27 |
|
---|
| 28 | #include "GLMoleculeObject_bond.hpp"
|
---|
| 29 |
|
---|
[e39e7a] | 30 | #include "molecule.hpp"
|
---|
| 31 |
|
---|
[c67518] | 32 | class atom;
|
---|
| 33 | class bond;
|
---|
[8c001a] | 34 | class GLMoleculeObject_atom;
|
---|
| 35 | class GLWorldScene;
|
---|
[c67518] | 36 |
|
---|
| 37 | class GLMoleculeObject_molecule : public GLMoleculeObject, public Observer
|
---|
| 38 | {
|
---|
| 39 | Q_OBJECT
|
---|
| 40 | public:
|
---|
[704d59] | 41 | GLMoleculeObject_molecule(QObject *parent, const moleculeId_t molid);
|
---|
| 42 | GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const moleculeId_t molid);
|
---|
[c67518] | 43 | virtual ~GLMoleculeObject_molecule();
|
---|
| 44 |
|
---|
| 45 | // Observer functions
|
---|
| 46 | void update(Observable *publisher);
|
---|
| 47 | void subjectKilled(Observable *publisher);
|
---|
| 48 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
| 49 |
|
---|
[8c001a] | 50 | void initialize(QGLView *view, QGLPainter *painter);
|
---|
| 51 | void draw(QGLPainter *painter, const QVector4D &cameraPlane);
|
---|
| 52 |
|
---|
| 53 | typedef std::pair< atomId_t, atomId_t> BondIds;
|
---|
| 54 | friend std::ostream &operator<<(std::ostream &ost, const BondIds &t);
|
---|
| 55 |
|
---|
| 56 | static BondIds getBondIds(
|
---|
| 57 | const bond::ptr _bond,
|
---|
| 58 | const enum GLMoleculeObject_bond::SideOfBond side);
|
---|
| 59 |
|
---|
| 60 | signals:
|
---|
| 61 | void changed();
|
---|
| 62 | void changeOccured();
|
---|
[704d59] | 63 | void hoverChanged(const atomId_t);
|
---|
| 64 | void hoverChanged(const moleculeId_t, int);
|
---|
[6c16a0] | 65 | void indexChanged(GLMoleculeObject_molecule *, const moleculeId_t, const moleculeId_t);
|
---|
[8c001a] | 66 | void atomClicked(atomId_t no);
|
---|
[9a7ef9] | 67 | void moleculeClicked(moleculeId_t no);
|
---|
[6c16a0] | 68 | void TesselationHullChanged();
|
---|
| 69 | void BoundingBoxChanged();
|
---|
| 70 | void IsSelectedChanged();
|
---|
| 71 | void AtomInserted(const atomId_t _id);
|
---|
| 72 | void AtomRemoved(const atomId_t _id);
|
---|
| 73 | void IdChanged();
|
---|
[7c7c4a] | 74 | void InstanceRemoved(const moleculeId_t);
|
---|
[8c001a] | 75 |
|
---|
| 76 | private slots:
|
---|
| 77 | //!> grant GLWorldScene access to private slots
|
---|
| 78 | friend class GLWorldScene;
|
---|
| 79 |
|
---|
[9a7ef9] | 80 | void wasClicked();
|
---|
[2f76d2] | 81 | void atomInserted(const atomId_t _id);
|
---|
| 82 | void atomRemoved(const atomId_t _id);
|
---|
[6c16a0] | 83 | void bondInserted(const atomId_t, const atomId_t, const GLMoleculeObject_bond::SideOfBond side);
|
---|
[8c001a] | 84 | void bondRemoved(const atomId_t leftnr, const atomId_t rightnr);
|
---|
| 85 | void hoverChangedSignalled(GLMoleculeObject *ob);
|
---|
[6c16a0] | 86 | void changeAtomId(GLMoleculeObject_atom *, const atomId_t, const atomId_t);
|
---|
[8c001a] | 87 |
|
---|
[34e7fdb] | 88 | void setVisible(bool value);
|
---|
| 89 |
|
---|
[73b13c] | 90 | void activateObserver();
|
---|
[6c16a0] | 91 | void deactivateObserver();
|
---|
| 92 |
|
---|
| 93 | void resetTesselationHull();
|
---|
| 94 | void resetBoundingBox();
|
---|
| 95 | void resetAtoms();
|
---|
| 96 | void resetIndex();
|
---|
[5b61e5] | 97 | void resetName();
|
---|
[6c16a0] | 98 |
|
---|
[015f8c] | 99 | void AtomSelected(const atomId_t _id);
|
---|
| 100 | void AtomUnselected(const atomId_t _id);
|
---|
| 101 | void Selected();
|
---|
| 102 | void Unselected();
|
---|
| 103 |
|
---|
[6c16a0] | 104 | private:
|
---|
| 105 | static const molecule * const getMolecule(const moleculeId_t _id);
|
---|
[73b13c] | 106 |
|
---|
[c67518] | 107 | private:
|
---|
[8c001a] | 108 | void addAtomBonds(
|
---|
| 109 | const bond::ptr &_bond,
|
---|
| 110 | const GLMoleculeObject_bond::SideOfBond _side
|
---|
| 111 | );
|
---|
[ca4b63b] | 112 | void addAtomBonds(const atomId_t _id);
|
---|
[8c001a] | 113 |
|
---|
[6c16a0] | 114 | //!> typedef for the internal set of atoms
|
---|
| 115 | typedef std::set<atomId_t> atoms_t;
|
---|
| 116 |
|
---|
[8688ef] | 117 | static molecule::BoundingBoxInfo initBoundingBox();
|
---|
[6fe4f7] | 118 |
|
---|
[6c16a0] | 119 | QGeometryData updateTesselationHull() const;
|
---|
[8688ef] | 120 | static molecule::BoundingBoxInfo updateBoundingBox(
|
---|
| 121 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
| 122 | static moleculeId_t updateIndex();
|
---|
| 123 | static std::string updateName(
|
---|
| 124 | const boost::function<const moleculeId_t ()> &_getMolIndex);
|
---|
[6c16a0] | 125 |
|
---|
| 126 | //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
|
---|
| 127 | const Observable * owner;
|
---|
| 128 |
|
---|
| 129 | //!> internal variable for caching molecule ref in cstor
|
---|
| 130 | const molecule * const molref;
|
---|
| 131 |
|
---|
| 132 | //!> list of channels when contained atoms needs to update
|
---|
| 133 | static const Observable::channels_t AtomsChannels;
|
---|
| 134 | //!> list of channels when tesselation hull needs to update
|
---|
| 135 | static const Observable::channels_t HullChannels;
|
---|
| 136 | //!> list of channels when bounding box needs to update
|
---|
| 137 | static const Observable::channels_t BoundingBoxChannels;
|
---|
| 138 | //!> list of channels when the index needs to update
|
---|
| 139 | static const Observable::channels_t IndexChannels;
|
---|
[5b61e5] | 140 | //!> list of channels when the name needs to update
|
---|
| 141 | static const Observable::channels_t NameChannels;
|
---|
[6c16a0] | 142 |
|
---|
[7c7c4a] | 143 | private:
|
---|
| 144 | /** Observed Values **/
|
---|
| 145 |
|
---|
| 146 | //!> enumeration of observed values to match with entries in ObservedValues
|
---|
| 147 | enum ObservedTypes {
|
---|
| 148 | //!> contains the current molecule index
|
---|
| 149 | MolIndex,
|
---|
| 150 | //!> contains the current molecule name
|
---|
| 151 | MolName,
|
---|
| 152 | //!> contains newest version of the bounding box on request
|
---|
| 153 | BoundingBox,
|
---|
| 154 | //!> contains the current live set of atoms for the molecule
|
---|
| 155 | PresentAtoms,
|
---|
| 156 | //!> gives the size of the enumeration
|
---|
| 157 | MAX_ObservedTypes
|
---|
| 158 | };
|
---|
| 159 |
|
---|
| 160 | //!> vector with all observed values
|
---|
| 161 | std::vector<boost::any> ObservedValues;
|
---|
| 162 |
|
---|
[8688ef] | 163 | /** Initializes all \a _ObservedValues entries.
|
---|
[7c7c4a] | 164 | *
|
---|
[8688ef] | 165 | * \param _ObservedValues vector of ObservedValue to be filled
|
---|
[7c7c4a] | 166 | * \param _moid molecule id
|
---|
[8688ef] | 167 | * \param _molref reference to molecule
|
---|
| 168 | * \param _subjectKilled ref to function to call on subjectKilled()
|
---|
[7c7c4a] | 169 | */
|
---|
[8688ef] | 170 | static void initObservedValues(
|
---|
| 171 | std::vector<boost::any> &_ObservedValues,
|
---|
| 172 | const moleculeId_t _molid,
|
---|
| 173 | const molecule * const _molref,
|
---|
| 174 | const boost::function<void()> &_subjectKilled);
|
---|
[7c7c4a] | 175 |
|
---|
| 176 | /** Destroys all \a ObservedValues entries.
|
---|
| 177 | *
|
---|
[8688ef] | 178 | * \param _ObservedValues vector of ObservedValue to be destroyed
|
---|
[7c7c4a] | 179 | */
|
---|
[8688ef] | 180 | static void destroyObservedValues(
|
---|
| 181 | std::vector<boost::any> &_ObservedValues);
|
---|
[7c7c4a] | 182 |
|
---|
| 183 | /** Getter to molecule index contained in \a ObservedValues.
|
---|
| 184 | *
|
---|
| 185 | * \return molecule's index
|
---|
| 186 | */
|
---|
| 187 | moleculeId_t getMolIndex() const;
|
---|
| 188 |
|
---|
| 189 | /** Getter to molecule name contained in \a ObservedValues.
|
---|
| 190 | *
|
---|
| 191 | * \return molecule's name
|
---|
| 192 | */
|
---|
| 193 | std::string getMolName() const;
|
---|
| 194 |
|
---|
| 195 | /** Getter to molecule's bounding box contained in \a ObservedValues.
|
---|
| 196 | *
|
---|
| 197 | * \return molecule's bounding box
|
---|
| 198 | */
|
---|
| 199 | molecule::BoundingBoxInfo getBoundingBox() const;
|
---|
| 200 |
|
---|
| 201 | /** Getter to contained atoms contained in \a ObservedValues.
|
---|
| 202 | *
|
---|
| 203 | * \return molecule's contained atoms
|
---|
| 204 | */
|
---|
| 205 | atoms_t getPresentAtoms() const;
|
---|
| 206 |
|
---|
| 207 | /** Counts how many ObservedValues got subjectKilled.
|
---|
| 208 | *
|
---|
| 209 | * This is used to give InstanceRemoved() signal only when each and every
|
---|
| 210 | * ObservedValue (and the instance itself) has been subjectKilled by the
|
---|
| 211 | * monitored Observable. Only then can we safely remove the instance.
|
---|
| 212 | *
|
---|
| 213 | */
|
---|
| 214 | void countsubjectKilled();
|
---|
| 215 |
|
---|
| 216 | //!> counts how many ObservedValues have already been subjectKilled()
|
---|
| 217 | mutable size_t subjectKilledCount;
|
---|
| 218 |
|
---|
[8688ef] | 219 | private:
|
---|
| 220 |
|
---|
| 221 | boost::function<QGeometryData ()> TesselationHullUpdater;
|
---|
| 222 |
|
---|
[6c16a0] | 223 | //!> contains current version of the tesselation hull on request
|
---|
| 224 | Cacheable<QGeometryData> TesselationHull;
|
---|
| 225 |
|
---|
| 226 | //!> contains the set of atoms displayed
|
---|
| 227 | atoms_t DisplayedAtoms;
|
---|
[7b5984] | 228 |
|
---|
[8c001a] | 229 | typedef std::map< atomId_t, GLMoleculeObject_atom* > AtomNodeMap;
|
---|
| 230 | typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap;
|
---|
| 231 | AtomNodeMap AtomsinSceneMap;
|
---|
| 232 | BondNodeMap BondsinSceneMap;
|
---|
| 233 |
|
---|
[704d59] | 234 | atomId_t hoverAtomId;
|
---|
[c67518] | 235 | };
|
---|
| 236 |
|
---|
[8c001a] | 237 | std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t);
|
---|
[c67518] | 238 |
|
---|
| 239 |
|
---|
| 240 | #endif /* GLMOLECULEOBJECT_MOLECULE_HPP_ */
|
---|