| 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 | class atom;
|
|---|
| 30 | class molecule;
|
|---|
| 31 | class Shape;
|
|---|
| 32 |
|
|---|
| 33 | class QGLPainter;
|
|---|
| 34 | class QGLSceneNode;
|
|---|
| 35 | class QGLView;
|
|---|
| 36 |
|
|---|
| 37 | class GLMoleculeObject;
|
|---|
| 38 | class GLMoleculeObject_atom;
|
|---|
| 39 | class GLMoleculeObject_molecule;
|
|---|
| 40 | class GLMoleculeObject_shape;
|
|---|
| 41 | class QtSelectionChangedAgent;
|
|---|
| 42 |
|
|---|
| 43 | /** This class contains a list of all molecules in the world.
|
|---|
| 44 | *
|
|---|
| 45 | */
|
|---|
| 46 | class GLWorldScene : public QObject
|
|---|
| 47 | {
|
|---|
| 48 | Q_OBJECT
|
|---|
| 49 | public:
|
|---|
| 50 | GLWorldScene(QObject *parent=0);
|
|---|
| 51 | virtual ~GLWorldScene();
|
|---|
| 52 |
|
|---|
| 53 | //#if !defined(QT_OPENGL_ES_1)
|
|---|
| 54 | // PerPixelEffect *lighting;
|
|---|
| 55 | //#endif
|
|---|
| 56 |
|
|---|
| 57 | void changeMaterials(bool perPixel);
|
|---|
| 58 | QGLSceneNode* getAtom(size_t);
|
|---|
| 59 | QGLSceneNode* getMolecule(size_t);
|
|---|
| 60 | QGLSceneNode* getBond(size_t, size_t);
|
|---|
| 61 |
|
|---|
| 62 | void initialize(QGLView *view, QGLPainter *painter) const;
|
|---|
| 63 | void draw(QGLPainter *painter, const QVector4D &cameraPlane) const;
|
|---|
| 64 |
|
|---|
| 65 | enum SelectionModeType{
|
|---|
| 66 | SelectAtom,
|
|---|
| 67 | SelectMolecule
|
|---|
| 68 | };
|
|---|
| 69 | void setSelectionMode(SelectionModeType mode);
|
|---|
| 70 |
|
|---|
| 71 | void setSelectionChangedAgent(QtSelectionChangedAgent *agent);
|
|---|
| 72 |
|
|---|
| 73 | signals:
|
|---|
| 74 | void changed();
|
|---|
| 75 | // void updated();
|
|---|
| 76 | void changeOccured();
|
|---|
| 77 | void pressed();
|
|---|
| 78 | void released();
|
|---|
| 79 | void clicked();
|
|---|
| 80 | void clicked(atomId_t);
|
|---|
| 81 | void doubleClicked();
|
|---|
| 82 | void hoverChanged(const atomId_t);
|
|---|
| 83 | void hoverChanged(const moleculeId_t, int);
|
|---|
| 84 |
|
|---|
| 85 | private slots:
|
|---|
| 86 | void atomClicked(atomId_t no);
|
|---|
| 87 | void moleculeClicked(moleculeId_t no);
|
|---|
| 88 | void moleculeRemoved(const moleculeId_t _id);
|
|---|
| 89 | void moleculeInserted(const moleculeId_t _id);
|
|---|
| 90 | void atomRemoved(const moleculeId_t _molid, const atomId_t _atomid);
|
|---|
| 91 | void atomInserted(const moleculeId_t _molid, const atomId_t _atomid);
|
|---|
| 92 | void setSelectionModeAtom();
|
|---|
| 93 | void setSelectionModeMolecule();
|
|---|
| 94 | void addShape(const std::string &_name);
|
|---|
| 95 | void removeShape(const std::string &_name);
|
|---|
| 96 | // void update();
|
|---|
| 97 | void moleculesVisibilityChanged(const moleculeId_t _id, bool _visible);
|
|---|
| 98 | void changeMoleculeId(GLMoleculeObject_molecule *, const moleculeId_t, const moleculeId_t);
|
|---|
| 99 |
|
|---|
| 100 | void AtomSelected(const moleculeId_t _molid, const atomId_t);
|
|---|
| 101 | void AtomUnselected(const moleculeId_t _molid, const atomId_t);
|
|---|
| 102 | void MoleculeSelected(const moleculeId_t);
|
|---|
| 103 | void MoleculeUnselected(const moleculeId_t);
|
|---|
| 104 |
|
|---|
| 105 | public:
|
|---|
| 106 | void updateSelectedShapes();
|
|---|
| 107 |
|
|---|
| 108 | private:
|
|---|
| 109 |
|
|---|
| 110 | typedef std::set<moleculeId_t> RemovalMolecule_t;
|
|---|
| 111 | //!> list of molecule ids whose moleculeRemoved we have received but who have not been inserted yet
|
|---|
| 112 | RemovalMolecule_t RemovalMolecules;
|
|---|
| 113 |
|
|---|
| 114 | typedef std::map< moleculeId_t , GLMoleculeObject_molecule* > MoleculeNodeMap;
|
|---|
| 115 | typedef std::map< std::string , GLMoleculeObject_shape* > ShapeNodeMap;
|
|---|
| 116 | MoleculeNodeMap MoleculesinSceneMap;
|
|---|
| 117 | ShapeNodeMap ShapesinSceneMap;
|
|---|
| 118 |
|
|---|
| 119 | //!> enumeration of all possible changes molecule might have missed before instantiation
|
|---|
| 120 | enum StateChangeType {
|
|---|
| 121 | atomInsertedState,
|
|---|
| 122 | atomRemovedState,
|
|---|
| 123 | MAX_StateChangeType
|
|---|
| 124 | };
|
|---|
| 125 | typedef std::multimap< atomId_t, StateChangeType> StateChangeMap_t;
|
|---|
| 126 | typedef std::map< moleculeId_t, StateChangeMap_t> MoleculeMissedStateMap_t;
|
|---|
| 127 | //!> map of all missed state changes
|
|---|
| 128 | MoleculeMissedStateMap_t MoleculeMissedStateMap;
|
|---|
| 129 | //!> flag to indicate whether state map is currently worked on
|
|---|
| 130 | boost::recursive_mutex MoleculeMissedStateMap_mutex;
|
|---|
| 131 |
|
|---|
| 132 | SelectionModeType selectionMode;
|
|---|
| 133 | };
|
|---|
| 134 |
|
|---|
| 135 | #endif /* GLWORLDSCENE_HPP_ */
|
|---|