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