| 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 |
|
|---|
| 18 | #include <Qt3D/qgeometrydata.h>
|
|---|
| 19 |
|
|---|
| 20 | #include <vector>
|
|---|
| 21 | #include <boost/any.hpp>
|
|---|
| 22 | #include <boost/function.hpp>
|
|---|
| 23 |
|
|---|
| 24 | #include "CodePatterns/Cacheable.hpp"
|
|---|
| 25 | #include "CodePatterns/Observer/Observer.hpp"
|
|---|
| 26 | #include "CodePatterns/ObservedValue.hpp"
|
|---|
| 27 |
|
|---|
| 28 | #include "GLMoleculeObject_bond.hpp"
|
|---|
| 29 |
|
|---|
| 30 | #include "molecule.hpp"
|
|---|
| 31 |
|
|---|
| 32 | class atom;
|
|---|
| 33 | class bond;
|
|---|
| 34 | class GLMoleculeObject_atom;
|
|---|
| 35 | class GLWorldScene;
|
|---|
| 36 | class QtObservedInstanceBoard;
|
|---|
| 37 |
|
|---|
| 38 | class GLMoleculeObject_molecule : public GLMoleculeObject, public Observer
|
|---|
| 39 | {
|
|---|
| 40 | Q_OBJECT
|
|---|
| 41 | public:
|
|---|
| 42 | GLMoleculeObject_molecule(
|
|---|
| 43 | QObject *parent,
|
|---|
| 44 | const moleculeId_t molid,
|
|---|
| 45 | QtObservedInstanceBoard * _board,
|
|---|
| 46 | std::vector<boost::any> _ObservedValues);
|
|---|
| 47 | GLMoleculeObject_molecule(
|
|---|
| 48 | QGLSceneNode *mesh[],
|
|---|
| 49 | QObject *parent,
|
|---|
| 50 | const moleculeId_t molid,
|
|---|
| 51 | QtObservedInstanceBoard * _board,
|
|---|
| 52 | std::vector<boost::any> _ObservedValues);
|
|---|
| 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 |
|
|---|
| 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();
|
|---|
| 73 | void hoverChanged(const atomId_t);
|
|---|
| 74 | void hoverChanged(const moleculeId_t, int);
|
|---|
| 75 | void indexChanged(GLMoleculeObject_molecule *, const moleculeId_t, const moleculeId_t);
|
|---|
| 76 | void atomClicked(atomId_t no);
|
|---|
| 77 | void moleculeClicked(moleculeId_t no);
|
|---|
| 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();
|
|---|
| 84 |
|
|---|
| 85 | private slots:
|
|---|
| 86 | //!> grant GLWorldScene access to private slots
|
|---|
| 87 | friend class GLWorldScene;
|
|---|
| 88 |
|
|---|
| 89 | void wasClicked();
|
|---|
| 90 | void atomInserted(const atomId_t _id);
|
|---|
| 91 | void atomRemoved(const atomId_t _id);
|
|---|
| 92 | void bondInserted(const atomId_t, const atomId_t, const GLMoleculeObject_bond::SideOfBond side);
|
|---|
| 93 | void bondRemoved(const atomId_t leftnr, const atomId_t rightnr);
|
|---|
| 94 | void hoverChangedSignalled(GLMoleculeObject *ob);
|
|---|
| 95 | void changeAtomId(GLMoleculeObject_atom *, const atomId_t, const atomId_t);
|
|---|
| 96 |
|
|---|
| 97 | void setVisible(bool value);
|
|---|
| 98 |
|
|---|
| 99 | void activateObserver();
|
|---|
| 100 | void deactivateObserver();
|
|---|
| 101 |
|
|---|
| 102 | void resetTesselationHull();
|
|---|
| 103 | void resetBoundingBox();
|
|---|
| 104 | void resetIndex();
|
|---|
| 105 | void resetName();
|
|---|
| 106 |
|
|---|
| 107 | void AtomSelected(const atomId_t _id);
|
|---|
| 108 | void AtomUnselected(const atomId_t _id);
|
|---|
| 109 | void Selected();
|
|---|
| 110 | void Unselected();
|
|---|
| 111 |
|
|---|
| 112 | private:
|
|---|
| 113 | static const molecule * const getMolecule(const moleculeId_t _id);
|
|---|
| 114 |
|
|---|
| 115 | void init(const moleculeId_t _molid);
|
|---|
| 116 |
|
|---|
| 117 | private:
|
|---|
| 118 | void addAtomBonds(
|
|---|
| 119 | const bond::ptr &_bond,
|
|---|
| 120 | const GLMoleculeObject_bond::SideOfBond _side
|
|---|
| 121 | );
|
|---|
| 122 |
|
|---|
| 123 | //!> typedef for the internal set of atoms
|
|---|
| 124 | typedef std::set<atomId_t> atoms_t;
|
|---|
| 125 |
|
|---|
| 126 | static molecule::BoundingBoxInfo initBoundingBox();
|
|---|
| 127 |
|
|---|
| 128 | QGeometryData updateTesselationHull() const;
|
|---|
| 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);
|
|---|
| 134 |
|
|---|
| 135 | /** Getter to contained atoms contained in \a ObservedValues.
|
|---|
| 136 | *
|
|---|
| 137 | * \return molecule's contained atoms
|
|---|
| 138 | */
|
|---|
| 139 | atoms_t getPresentAtoms() const;
|
|---|
| 140 |
|
|---|
| 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;
|
|---|
| 153 | //!> list of channels when the name needs to update
|
|---|
| 154 | static const Observable::channels_t NameChannels;
|
|---|
| 155 |
|
|---|
| 156 | private:
|
|---|
| 157 | friend class QtObservedInstanceBoard;
|
|---|
| 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 |
|
|---|
| 175 | /** Initializes all \a _ObservedValues entries.
|
|---|
| 176 | *
|
|---|
| 177 | * \param _ObservedValues vector of ObservedValue to be filled
|
|---|
| 178 | * \param _moid molecule id
|
|---|
| 179 | * \param _molref reference to molecule
|
|---|
| 180 | * \param _subjectKilled ref to function to call on subjectKilled()
|
|---|
| 181 | */
|
|---|
| 182 | static void initObservedValues(
|
|---|
| 183 | std::vector<boost::any> &_ObservedValues,
|
|---|
| 184 | const moleculeId_t _molid,
|
|---|
| 185 | const molecule * const _molref,
|
|---|
| 186 | const boost::function<void(const moleculeId_t)> &_subjectKilled);
|
|---|
| 187 |
|
|---|
| 188 | /** Destroys all \a ObservedValues entries.
|
|---|
| 189 | *
|
|---|
| 190 | * \param _ObservedValues vector of ObservedValue to be destroyed
|
|---|
| 191 | */
|
|---|
| 192 | static void destroyObservedValues(
|
|---|
| 193 | std::vector<boost::any> &_ObservedValues);
|
|---|
| 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 |
|
|---|
| 216 | private:
|
|---|
| 217 |
|
|---|
| 218 | boost::function<QGeometryData ()> TesselationHullUpdater;
|
|---|
| 219 |
|
|---|
| 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;
|
|---|
| 225 |
|
|---|
| 226 | typedef std::map< atomId_t, GLMoleculeObject_atom* > AtomNodeMap;
|
|---|
| 227 | typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap;
|
|---|
| 228 | AtomNodeMap AtomsinSceneMap;
|
|---|
| 229 | BondNodeMap BondsinSceneMap;
|
|---|
| 230 |
|
|---|
| 231 | atomId_t hoverAtomId;
|
|---|
| 232 |
|
|---|
| 233 | //!> we get multiple subjectKilled(), count and call callback() only on last
|
|---|
| 234 | const unsigned int AllsignedOnChannels;
|
|---|
| 235 | unsigned int signedOnChannels;
|
|---|
| 236 |
|
|---|
| 237 | QtObservedInstanceBoard * board;
|
|---|
| 238 | };
|
|---|
| 239 |
|
|---|
| 240 | std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t);
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 | #endif /* GLMOLECULEOBJECT_MOLECULE_HPP_ */
|
|---|