| 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 |
|
|---|
| 20 | #include <iosfwd>
|
|---|
| 21 |
|
|---|
| 22 | #include <boost/thread/recursive_mutex.hpp>
|
|---|
| 23 |
|
|---|
| 24 | #include "Bond/bond.hpp"
|
|---|
| 25 | #include "GLMoleculeObject_bond.hpp"
|
|---|
| 26 | #include "GLMoleculeObject_molecule.hpp"
|
|---|
| 27 | #include "types.hpp"
|
|---|
| 28 |
|
|---|
| 29 | #include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
|
|---|
| 30 | #include "UIElements/Qt4/InstanceBoard/QtObservedBond.hpp"
|
|---|
| 31 | #include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
|
|---|
| 32 |
|
|---|
| 33 | class Shape;
|
|---|
| 34 |
|
|---|
| 35 | class QGLPainter;
|
|---|
| 36 | class QGLSceneNode;
|
|---|
| 37 | class QGLView;
|
|---|
| 38 |
|
|---|
| 39 | class GLMoleculeObject;
|
|---|
| 40 | class GLMoleculeObject_atom;
|
|---|
| 41 | class GLMoleculeObject_molecule;
|
|---|
| 42 | class GLMoleculeObject_shape;
|
|---|
| 43 |
|
|---|
| 44 | class QtObservedInstanceBoard;
|
|---|
| 45 |
|
|---|
| 46 | /** This class contains a list of all molecules in the world.
|
|---|
| 47 | *
|
|---|
| 48 | */
|
|---|
| 49 | class GLWorldScene : public QObject
|
|---|
| 50 | {
|
|---|
| 51 | Q_OBJECT
|
|---|
| 52 | public:
|
|---|
| 53 | GLWorldScene(
|
|---|
| 54 | QtObservedInstanceBoard * _board,
|
|---|
| 55 | QObject *parent=0);
|
|---|
| 56 | virtual ~GLWorldScene();
|
|---|
| 57 |
|
|---|
| 58 | //#if !defined(QT_OPENGL_ES_1)
|
|---|
| 59 | // PerPixelEffect *lighting;
|
|---|
| 60 | //#endif
|
|---|
| 61 |
|
|---|
| 62 | void changeMaterials(bool perPixel);
|
|---|
| 63 | QGLSceneNode* getAtom(size_t);
|
|---|
| 64 | QGLSceneNode* getMolecule(size_t);
|
|---|
| 65 | QGLSceneNode* getBond(size_t, size_t);
|
|---|
| 66 |
|
|---|
| 67 | void initialize(QGLView *view, QGLPainter *painter) const;
|
|---|
| 68 | void draw(QGLPainter *painter, const QVector4D &cameraPlane) const;
|
|---|
| 69 |
|
|---|
| 70 | enum SelectionModeType{
|
|---|
| 71 | SelectAtom,
|
|---|
| 72 | SelectMolecule
|
|---|
| 73 | };
|
|---|
| 74 | void setSelectionMode(SelectionModeType mode);
|
|---|
| 75 |
|
|---|
| 76 | signals:
|
|---|
| 77 | void changed();
|
|---|
| 78 | // void updated();
|
|---|
| 79 | void changeOccured();
|
|---|
| 80 | void pressed();
|
|---|
| 81 | void released();
|
|---|
| 82 | void clicked();
|
|---|
| 83 | void clicked(atomId_t);
|
|---|
| 84 | void doubleClicked();
|
|---|
| 85 | void hoverChanged(const atomId_t);
|
|---|
| 86 | void hoverChanged(const moleculeId_t, int);
|
|---|
| 87 | void insertMolecule(QtObservedMolecule::ptr);
|
|---|
| 88 | void removeMolecule(QtObservedMolecule*);
|
|---|
| 89 |
|
|---|
| 90 | private slots:
|
|---|
| 91 | void atomClicked(atomId_t no);
|
|---|
| 92 | void moleculeClicked(moleculeId_t no);
|
|---|
| 93 | void moleculeRemoved(QtObservedMolecule* _mol);
|
|---|
| 94 | void moleculeEmpty(QtObservedMolecule::ptr _mol);
|
|---|
| 95 | void moleculeInserted(QtObservedMolecule::ptr);
|
|---|
| 96 | void moleculeSignOn(QtObservedMolecule::ptr);
|
|---|
| 97 | void moleculeSignOff(ObservedValue_Index_t _id);
|
|---|
| 98 | void moleculesAtomRemoved(ObservedValue_Index_t _atomid, QtObservedMolecule * _mol);
|
|---|
| 99 | void moleculesAtomInserted(QtObservedAtom::ptr, QtObservedMolecule *_mol);
|
|---|
| 100 | void moleculesBondRemoved(ObservedValue_Index_t _bondid, QtObservedMolecule * _mol);
|
|---|
| 101 | void moleculesBondInserted(QtObservedBond::ptr, QtObservedMolecule *_mol);
|
|---|
| 102 | void atomRemoved(ObservedValue_Index_t _atomid);
|
|---|
| 103 | void atomInserted(QtObservedAtom::ptr);
|
|---|
| 104 | void bondRemoved(ObservedValue_Index_t _bondid);
|
|---|
| 105 | void bondInserted(QtObservedBond::ptr);
|
|---|
| 106 | void bondsMoleculeChanged(moleculeId_t _oldid, moleculeId_t _newid);
|
|---|
| 107 | void setSelectionModeAtom();
|
|---|
| 108 | void setSelectionModeMolecule();
|
|---|
| 109 | void addShape(const std::string &_name);
|
|---|
| 110 | void removeShape(const std::string &_name);
|
|---|
| 111 | // void update();
|
|---|
| 112 | void moleculesVisibilityChanged(ObservedValue_Index_t _id, bool _visible);
|
|---|
| 113 |
|
|---|
| 114 | public:
|
|---|
| 115 | void updateSelectedShapes();
|
|---|
| 116 |
|
|---|
| 117 | private:
|
|---|
| 118 |
|
|---|
| 119 | typedef std::map< ObservedValue_Index_t , GLMoleculeObject_molecule* > MoleculeNodeMap;
|
|---|
| 120 | typedef std::map< std::string , GLMoleculeObject_shape* > ShapeNodeMap;
|
|---|
| 121 | MoleculeNodeMap MoleculesinSceneMap;
|
|---|
| 122 | ShapeNodeMap ShapesinSceneMap;
|
|---|
| 123 | //!> flag to indicate whether state map is currently worked on
|
|---|
| 124 | boost::recursive_mutex MoleculeinSceneMap_mutex;
|
|---|
| 125 |
|
|---|
| 126 | //!> enumeration of all possible changes molecule might have missed before instantiation
|
|---|
| 127 | enum StateChangeType {
|
|---|
| 128 | atomInsertedState,
|
|---|
| 129 | atomRemovedState,
|
|---|
| 130 | bondInsertedState,
|
|---|
| 131 | bondRemovedState,
|
|---|
| 132 | MAX_StateChangeType
|
|---|
| 133 | };
|
|---|
| 134 | typedef std::map< ObservedValue_Index_t, QtObservedAtom::ptr> QtObservedAtomMap_t;
|
|---|
| 135 | typedef std::map< ObservedValue_Index_t, QtObservedBond::ptr> QtObservedBondMap_t;
|
|---|
| 136 | typedef std::map< ObservedValue_Index_t, QtObservedMolecule::ptr> QtObservedMoleculeMap_t;
|
|---|
| 137 | typedef std::multimap< ObservedValue_Index_t, StateChangeType> StateChangeMap_t;
|
|---|
| 138 | typedef std::map< ObservedValue_Index_t, StateChangeMap_t> MissedStateMap_t;
|
|---|
| 139 | //!> map of all missed state changes
|
|---|
| 140 | MissedStateMap_t MoleculeMissedStateMap;
|
|---|
| 141 | //!> map to contain all QtObservedAtom that have not been instantiated so far
|
|---|
| 142 | QtObservedAtomMap_t QtObservedAtomMap;
|
|---|
| 143 | //!> map to contain all QtObservedBond that have not been instantiated so far
|
|---|
| 144 | QtObservedBondMap_t QtObservedBondMap;
|
|---|
| 145 | //!> map to contain all QtObservedMolecule that have not been instantiated so far
|
|---|
| 146 | QtObservedMoleculeMap_t QtObservedMoleculeMap;
|
|---|
| 147 |
|
|---|
| 148 | //!> map to get from QtObservedMolecule to the visual representant
|
|---|
| 149 | typedef std::map< QtObservedMolecule* , GLMoleculeObject_molecule* > RemovedMoleculesMap_t;
|
|---|
| 150 | //!> set of all currently removed molecules
|
|---|
| 151 | RemovedMoleculesMap_t RemovedMolecules;
|
|---|
| 152 | //!> set of all currently empty molecules (about to be removed)
|
|---|
| 153 | RemovedMoleculesMap_t EmptyMolecules;
|
|---|
| 154 |
|
|---|
| 155 | //!> flag to indicate whether state map is currently worked on
|
|---|
| 156 | boost::recursive_mutex MoleculeMissedStateMap_mutex;
|
|---|
| 157 |
|
|---|
| 158 | SelectionModeType selectionMode;
|
|---|
| 159 |
|
|---|
| 160 | QtObservedInstanceBoard * board;
|
|---|
| 161 | };
|
|---|
| 162 |
|
|---|
| 163 | #endif /* GLWORLDSCENE_HPP_ */
|
|---|