[907636] | 1 | /*
|
---|
| 2 | * GLWorldScene.hpp
|
---|
| 3 | *
|
---|
| 4 | * This is based on the Qt3D example "teaservice", specifically parts of teaservice.cpp.
|
---|
| 5 | *
|
---|
| 6 | * Created on: Aug 17, 2011
|
---|
| 7 | * Author: heber
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | #ifndef GLWORLDSCENE_HPP_
|
---|
| 11 | #define GLWORLDSCENE_HPP_
|
---|
| 12 |
|
---|
| 13 | // include config.h
|
---|
| 14 | #ifdef HAVE_CONFIG_H
|
---|
| 15 | #include <config.h>
|
---|
| 16 | #endif
|
---|
| 17 |
|
---|
| 18 | #include <Qt/qobject.h>
|
---|
| 19 |
|
---|
[2ad1ec] | 20 | #include <iosfwd>
|
---|
| 21 |
|
---|
[a13f2b] | 22 | #include <boost/bimap.hpp>
|
---|
[bd6768] | 23 | #include <boost/thread/recursive_mutex.hpp>
|
---|
| 24 |
|
---|
[88c8ec] | 25 | #include "Bond/bond.hpp"
|
---|
[2ad1ec] | 26 | #include "GLMoleculeObject_bond.hpp"
|
---|
[c67518] | 27 | #include "GLMoleculeObject_molecule.hpp"
|
---|
[3e93332] | 28 | #include "types.hpp"
|
---|
[2ad1ec] | 29 |
|
---|
[1b07b1] | 30 | #include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
|
---|
[96f14a] | 31 | #include "UIElements/Qt4/InstanceBoard/QtObservedBond.hpp"
|
---|
[1b07b1] | 32 | #include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
|
---|
| 33 |
|
---|
[f75491] | 34 | class Shape;
|
---|
[7188b1] | 35 |
|
---|
[907636] | 36 | class QGLPainter;
|
---|
| 37 | class QGLSceneNode;
|
---|
| 38 | class QGLView;
|
---|
| 39 |
|
---|
| 40 | class GLMoleculeObject;
|
---|
| 41 | class GLMoleculeObject_atom;
|
---|
[c67518] | 42 | class GLMoleculeObject_molecule;
|
---|
[284551] | 43 | class GLMoleculeObject_shape;
|
---|
[907636] | 44 |
|
---|
[2f7988] | 45 | class QtObservedInstanceBoard;
|
---|
[15c8a9] | 46 |
|
---|
[907636] | 47 | /** This class contains a list of all molecules in the world.
|
---|
| 48 | *
|
---|
| 49 | */
|
---|
| 50 | class GLWorldScene : public QObject
|
---|
| 51 | {
|
---|
| 52 | Q_OBJECT
|
---|
| 53 | public:
|
---|
[15c8a9] | 54 | GLWorldScene(
|
---|
[2f7988] | 55 | QtObservedInstanceBoard * _board,
|
---|
[15c8a9] | 56 | QObject *parent=0);
|
---|
[907636] | 57 | virtual ~GLWorldScene();
|
---|
| 58 |
|
---|
| 59 | //#if !defined(QT_OPENGL_ES_1)
|
---|
| 60 | // PerPixelEffect *lighting;
|
---|
| 61 | //#endif
|
---|
| 62 |
|
---|
| 63 | void changeMaterials(bool perPixel);
|
---|
| 64 | QGLSceneNode* getAtom(size_t);
|
---|
[c67518] | 65 | QGLSceneNode* getMolecule(size_t);
|
---|
[907636] | 66 | QGLSceneNode* getBond(size_t, size_t);
|
---|
| 67 |
|
---|
| 68 | void initialize(QGLView *view, QGLPainter *painter) const;
|
---|
[72a4c1] | 69 | void draw(QGLPainter *painter, const QVector4D &cameraPlane) const;
|
---|
[907636] | 70 |
|
---|
[6966b7] | 71 | enum SelectionModeType{
|
---|
| 72 | SelectAtom,
|
---|
| 73 | SelectMolecule
|
---|
| 74 | };
|
---|
| 75 | void setSelectionMode(SelectionModeType mode);
|
---|
| 76 |
|
---|
[907636] | 77 | signals:
|
---|
| 78 | void changed();
|
---|
[f714763] | 79 | // void updated();
|
---|
[65487f] | 80 | void changeOccured();
|
---|
[7188b1] | 81 | void pressed();
|
---|
| 82 | void released();
|
---|
| 83 | void clicked();
|
---|
| 84 | void clicked(atomId_t);
|
---|
| 85 | void doubleClicked();
|
---|
[704d59] | 86 | void hoverChanged(const atomId_t);
|
---|
| 87 | void hoverChanged(const moleculeId_t, int);
|
---|
[bd6768] | 88 | void atomConnected(QtObservedAtom::ptr);
|
---|
| 89 | void bondConnected(QtObservedBond::ptr);
|
---|
[907636] | 90 |
|
---|
| 91 | private slots:
|
---|
[bd6768] | 92 |
|
---|
| 93 | void clickAtom(atomId_t no);
|
---|
| 94 | void connectAtom(QtObservedAtom::ptr);
|
---|
| 95 | void insertAtom(QtObservedAtom::ptr);
|
---|
| 96 | void removeAtom(ObservedValue_Index_t _atomid);
|
---|
| 97 |
|
---|
| 98 | void connectBond(QtObservedBond::ptr);
|
---|
| 99 | void insertBond(QtObservedBond::ptr);
|
---|
| 100 | void removeBond(ObservedValue_Index_t _bondid);
|
---|
| 101 |
|
---|
| 102 | void clickMolecule(moleculeId_t no);
|
---|
| 103 | void insertMolecule(QtObservedMolecule::ptr);
|
---|
| 104 | void removeMolecule(ObservedValue_Index_t _molid);
|
---|
| 105 |
|
---|
[6966b7] | 106 | void setSelectionModeAtom();
|
---|
| 107 | void setSelectionModeMolecule();
|
---|
[bd6768] | 108 |
|
---|
[07136a] | 109 | void addShape(const std::string &_name);
|
---|
| 110 | void removeShape(const std::string &_name);
|
---|
[f714763] | 111 | // void update();
|
---|
[f91ef6] | 112 | void moleculesVisibilityChanged(ObservedValue_Index_t _id, bool _visible);
|
---|
[f1b5ca] | 113 | void hoverChangedSignalled(GLMoleculeObject *ob);
|
---|
[284551] | 114 |
|
---|
[bd6768] | 115 | void reparentAtom();
|
---|
| 116 | void reparentBondLeft();
|
---|
| 117 | void reparentBondRight();
|
---|
| 118 |
|
---|
[502614] | 119 | private:
|
---|
[a13f2b] | 120 |
|
---|
| 121 | GLMoleculeObject_molecule *getMoleculeObject(
|
---|
| 122 | const ObservedValue_Index_t _molid) const;
|
---|
| 123 |
|
---|
| 124 | void resetParent(
|
---|
| 125 | GLMoleculeObject *_obj,
|
---|
| 126 | GLMoleculeObject_molecule *_molobj);
|
---|
| 127 |
|
---|
[502614] | 128 | void reparentBond(
|
---|
| 129 | QtObservedBond *_bond,
|
---|
[507f3c] | 130 | const QtObservedAtom::ptr _atom,
|
---|
[502614] | 131 | const GLMoleculeObject_bond::SideOfBond _side);
|
---|
| 132 |
|
---|
| 133 | GLMoleculeObject_bond *getBondInScene(
|
---|
| 134 | const ObservedValue_Index_t _bondid,
|
---|
| 135 | GLMoleculeObject_bond::SideOfBond _side) const;
|
---|
| 136 |
|
---|
[284551] | 137 | public:
|
---|
[85c36d] | 138 | void updateSelectedShapes();
|
---|
[907636] | 139 |
|
---|
[2ad1ec] | 140 | private:
|
---|
| 141 |
|
---|
[f1b5ca] | 142 | //!> id of atom hovered over
|
---|
| 143 | atomId_t hoverAtomId;
|
---|
| 144 |
|
---|
[136842] | 145 | typedef std::map< ObservedValue_Index_t, GLMoleculeObject_molecule* > MoleculeNodeMap;
|
---|
[f1b5ca] | 146 | typedef std::map< ObservedValue_Index_t, GLMoleculeObject_atom* > AtomNodeMap;
|
---|
[bd6768] | 147 | typedef std::multimap< ObservedValue_Index_t, GLMoleculeObject_bond* > BondNodeMap;
|
---|
[284551] | 148 | typedef std::map< std::string , GLMoleculeObject_shape* > ShapeNodeMap;
|
---|
[f1b5ca] | 149 |
|
---|
[502614] | 150 | //!> typedef for storing the current parent to each atom node in scene, NULL indicates GLWorldScene is parent
|
---|
[a13f2b] | 151 | typedef boost::bimap<
|
---|
| 152 | boost::bimaps::set_of< ObservedValue_Index_t >,
|
---|
| 153 | boost::bimaps::multiset_of< ObservedValue_Index_t >
|
---|
| 154 | > AtomNodeParentMap_t;
|
---|
[502614] | 155 | //!> typedef for storing the current parent to each bond node in scene, NULL indicates GLWorldScene is parent
|
---|
[a13f2b] | 156 | typedef boost::bimap<
|
---|
| 157 | boost::bimaps::set_of< ObservedValue_Index_t >,
|
---|
| 158 | boost::bimaps::multiset_of< ObservedValue_Index_t >
|
---|
| 159 | > BondNodeParentMap_t;
|
---|
[bd6768] | 160 |
|
---|
[136842] | 161 | typedef std::map< ObservedValue_Index_t, QtObservedAtom::ptr > ObservedAtoms_t;
|
---|
| 162 | typedef std::map< ObservedValue_Index_t, QtObservedBond::ptr > ObservedBonds_t;
|
---|
| 163 |
|
---|
[bd6768] | 164 | //!> mutex to ascertain atomic access to NodeParentMaps
|
---|
| 165 | boost::recursive_mutex AtomNodeParentMap_mutex;
|
---|
| 166 | boost::recursive_mutex BondNodeParentMap_mutex;
|
---|
| 167 |
|
---|
[f1b5ca] | 168 | AtomNodeMap AtomsinSceneMap;
|
---|
| 169 | BondNodeMap BondsinSceneMap;
|
---|
[c67518] | 170 | MoleculeNodeMap MoleculesinSceneMap;
|
---|
[284551] | 171 | ShapeNodeMap ShapesinSceneMap;
|
---|
[bd6768] | 172 | AtomNodeParentMap_t AtomNodeParentMap;
|
---|
[a13f2b] | 173 | std::vector<BondNodeParentMap_t> BondNodeParentMaps;
|
---|
[9c259e] | 174 |
|
---|
[136842] | 175 | //!> stored observed atom such that its signals may always be safely evaluated
|
---|
| 176 | ObservedAtoms_t ObservedAtoms;
|
---|
| 177 | //!> stored observed bond such that its signals may always be safely evaluated
|
---|
| 178 | ObservedBonds_t ObservedBonds;
|
---|
| 179 |
|
---|
[6966b7] | 180 | SelectionModeType selectionMode;
|
---|
[15c8a9] | 181 |
|
---|
[2f7988] | 182 | QtObservedInstanceBoard * board;
|
---|
[907636] | 183 | };
|
---|
| 184 |
|
---|
| 185 | #endif /* GLWORLDSCENE_HPP_ */
|
---|