| 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 "CodePatterns/Cacheable.hpp"
|
|---|
| 21 | #include "CodePatterns/Observer/Observer.hpp"
|
|---|
| 22 | #include "CodePatterns/ObservedValue.hpp"
|
|---|
| 23 |
|
|---|
| 24 | #include "GLMoleculeObject_bond.hpp"
|
|---|
| 25 |
|
|---|
| 26 | class atom;
|
|---|
| 27 | class bond;
|
|---|
| 28 | class GLMoleculeObject_atom;
|
|---|
| 29 | class GLWorldScene;
|
|---|
| 30 | class molecule;
|
|---|
| 31 |
|
|---|
| 32 | class GLMoleculeObject_molecule : public GLMoleculeObject, public Observer
|
|---|
| 33 | {
|
|---|
| 34 | Q_OBJECT
|
|---|
| 35 | public:
|
|---|
| 36 | GLMoleculeObject_molecule(QObject *parent, const moleculeId_t molid);
|
|---|
| 37 | GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const moleculeId_t molid);
|
|---|
| 38 | virtual ~GLMoleculeObject_molecule();
|
|---|
| 39 |
|
|---|
| 40 | // Observer functions
|
|---|
| 41 | void update(Observable *publisher);
|
|---|
| 42 | void subjectKilled(Observable *publisher);
|
|---|
| 43 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
|---|
| 44 |
|
|---|
| 45 | void initialize(QGLView *view, QGLPainter *painter);
|
|---|
| 46 | void draw(QGLPainter *painter, const QVector4D &cameraPlane);
|
|---|
| 47 |
|
|---|
| 48 | typedef std::pair< atomId_t, atomId_t> BondIds;
|
|---|
| 49 | friend std::ostream &operator<<(std::ostream &ost, const BondIds &t);
|
|---|
| 50 |
|
|---|
| 51 | static BondIds getBondIds(
|
|---|
| 52 | const bond::ptr _bond,
|
|---|
| 53 | const enum GLMoleculeObject_bond::SideOfBond side);
|
|---|
| 54 |
|
|---|
| 55 | signals:
|
|---|
| 56 | void changed();
|
|---|
| 57 | void changeOccured();
|
|---|
| 58 | void hoverChanged(const atomId_t);
|
|---|
| 59 | void hoverChanged(const moleculeId_t, int);
|
|---|
| 60 | void indexChanged(GLMoleculeObject_molecule *, const moleculeId_t, const moleculeId_t);
|
|---|
| 61 | void atomClicked(atomId_t no);
|
|---|
| 62 | void moleculeClicked(moleculeId_t no);
|
|---|
| 63 | void TesselationHullChanged();
|
|---|
| 64 | void BoundingBoxChanged();
|
|---|
| 65 | void IsSelectedChanged();
|
|---|
| 66 | void AtomInserted(const atomId_t _id);
|
|---|
| 67 | void AtomRemoved(const atomId_t _id);
|
|---|
| 68 | void IdChanged();
|
|---|
| 69 |
|
|---|
| 70 | private slots:
|
|---|
| 71 | //!> grant GLWorldScene access to private slots
|
|---|
| 72 | friend class GLWorldScene;
|
|---|
| 73 |
|
|---|
| 74 | void wasClicked();
|
|---|
| 75 | void atomInserted(const atomId_t _id);
|
|---|
| 76 | void atomRemoved(const atomId_t _id);
|
|---|
| 77 | void bondInserted(const atomId_t, const atomId_t, const GLMoleculeObject_bond::SideOfBond side);
|
|---|
| 78 | void bondRemoved(const atomId_t leftnr, const atomId_t rightnr);
|
|---|
| 79 | void hoverChangedSignalled(GLMoleculeObject *ob);
|
|---|
| 80 | void changeAtomId(GLMoleculeObject_atom *, const atomId_t, const atomId_t);
|
|---|
| 81 |
|
|---|
| 82 | void setVisible(bool value);
|
|---|
| 83 |
|
|---|
| 84 | void activateObserver();
|
|---|
| 85 | void deactivateObserver();
|
|---|
| 86 |
|
|---|
| 87 | void resetTesselationHull();
|
|---|
| 88 | void resetBoundingBox();
|
|---|
| 89 | void resetAtoms();
|
|---|
| 90 | void resetIndex();
|
|---|
| 91 | void resetName();
|
|---|
| 92 |
|
|---|
| 93 | void AtomSelected(const atomId_t _id);
|
|---|
| 94 | void AtomUnselected(const atomId_t _id);
|
|---|
| 95 | void Selected();
|
|---|
| 96 | void Unselected();
|
|---|
| 97 |
|
|---|
| 98 | private:
|
|---|
| 99 | static const molecule * const getMolecule(const moleculeId_t _id);
|
|---|
| 100 |
|
|---|
| 101 | private:
|
|---|
| 102 | void addAtomBonds(
|
|---|
| 103 | const bond::ptr &_bond,
|
|---|
| 104 | const GLMoleculeObject_bond::SideOfBond _side
|
|---|
| 105 | );
|
|---|
| 106 | void addAtomBonds(const atom *_atom);
|
|---|
| 107 |
|
|---|
| 108 | //!> typedef for the internal set of atoms
|
|---|
| 109 | typedef std::set<atomId_t> atoms_t;
|
|---|
| 110 |
|
|---|
| 111 | /** Structure for the required information on the bounding box.
|
|---|
| 112 | *
|
|---|
| 113 | */
|
|---|
| 114 | struct BoundingBoxInfo {
|
|---|
| 115 | //!> position of center
|
|---|
| 116 | Vector position;
|
|---|
| 117 | //!> radius of sphere
|
|---|
| 118 | double radius;
|
|---|
| 119 | };
|
|---|
| 120 |
|
|---|
| 121 | /** Structure for the required information on the tesselation hull.
|
|---|
| 122 | *
|
|---|
| 123 | */
|
|---|
| 124 | struct TesselationHullInfo {
|
|---|
| 125 | };
|
|---|
| 126 |
|
|---|
| 127 | QGeometryData updateTesselationHull() const;
|
|---|
| 128 | BoundingBoxInfo updateBoundingBox() const;
|
|---|
| 129 | atoms_t updateAtoms();
|
|---|
| 130 | moleculeId_t updateIndex() const;
|
|---|
| 131 | std::string updateName() const;
|
|---|
| 132 |
|
|---|
| 133 | //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
|
|---|
| 134 | const Observable * owner;
|
|---|
| 135 |
|
|---|
| 136 | //!> internal variable for caching molecule ref in cstor
|
|---|
| 137 | const molecule * const molref;
|
|---|
| 138 |
|
|---|
| 139 | //!> list of channels when contained atoms needs to update
|
|---|
| 140 | static const Observable::channels_t AtomsChannels;
|
|---|
| 141 | //!> list of channels when tesselation hull needs to update
|
|---|
| 142 | static const Observable::channels_t HullChannels;
|
|---|
| 143 | //!> list of channels when bounding box needs to update
|
|---|
| 144 | static const Observable::channels_t BoundingBoxChannels;
|
|---|
| 145 | //!> list of channels when the index needs to update
|
|---|
| 146 | static const Observable::channels_t IndexChannels;
|
|---|
| 147 | //!> list of channels when the name needs to update
|
|---|
| 148 | static const Observable::channels_t NameChannels;
|
|---|
| 149 |
|
|---|
| 150 | boost::function<moleculeId_t ()> MolIndexUpdater;
|
|---|
| 151 | boost::function<std::string ()> MolNameUpdater;
|
|---|
| 152 | boost::function<QGeometryData ()> TesselationHullUpdater;
|
|---|
| 153 | boost::function<BoundingBoxInfo ()> BoundingBoxUpdater;
|
|---|
| 154 | boost::function<atoms_t ()> PresentAtomsUpdater;
|
|---|
| 155 |
|
|---|
| 156 | //!> contains the current molecule index
|
|---|
| 157 | ObservedValue<moleculeId_t> MolIndex;
|
|---|
| 158 | //!> contains the current molecule name
|
|---|
| 159 | ObservedValue<std::string> MolName;
|
|---|
| 160 | //!> contains current version of the tesselation hull on request
|
|---|
| 161 | Cacheable<QGeometryData> TesselationHull;
|
|---|
| 162 | //!> contains newest version of the bounding box on request
|
|---|
| 163 | ObservedValue<BoundingBoxInfo> BoundingBox;
|
|---|
| 164 | //!> contains the current live set of atoms for the molecule
|
|---|
| 165 | ObservedValue<atoms_t> PresentAtoms;
|
|---|
| 166 |
|
|---|
| 167 | //!> contains the set of atoms displayed
|
|---|
| 168 | atoms_t DisplayedAtoms;
|
|---|
| 169 |
|
|---|
| 170 | typedef std::map< atomId_t, GLMoleculeObject_atom* > AtomNodeMap;
|
|---|
| 171 | typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap;
|
|---|
| 172 | AtomNodeMap AtomsinSceneMap;
|
|---|
| 173 | BondNodeMap BondsinSceneMap;
|
|---|
| 174 |
|
|---|
| 175 | atomId_t hoverAtomId;
|
|---|
| 176 | };
|
|---|
| 177 |
|
|---|
| 178 | std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t);
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 | #endif /* GLMOLECULEOBJECT_MOLECULE_HPP_ */
|
|---|