glsimplemoleculeview.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                     glsimplemoleculeview.h  -  description
00003                              -------------------
00004     begin                : Fri Nov 5 2004
00005     copyright            : (C) 2004-2006 by Ben Swerts
00006     email                : bswerts@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00020 
00021 #ifndef GLSIMPLEMOLECULEVIEW_H
00022 #define GLSIMPLEMOLECULEVIEW_H
00023 
00025 
00026 // STL includes
00027 #include <vector>
00028 
00029 // Qt forward class declarations
00030 class QDomElement;
00031 #include <qfont.h>
00032 
00033 // Xbrabo forward class declarations
00034 class AtomSet;
00035 
00036 // Xbrabo header files
00037 #include "glmoleculeparameters.h"
00038 #include "glview.h"
00039 
00040 class GLSimpleMoleculeView : public GLView
00041 {
00042   Q_OBJECT
00043   
00044   public: 
00046     GLSimpleMoleculeView(AtomSet* atomset, QWidget* parent=0, const char* name=0);      // constructor
00047     ~GLSimpleMoleculeView();            // destructor
00048 
00050     enum DisplayStyle{None, Lines, Tubes, BallAndStick, VanDerWaals};   
00051 
00052     enum DisplaySource{Molecule, Forces};         
00053 
00055     unsigned int displayStyle(const DisplaySource source) const;      // Returns the display style of a certain primitive
00056     bool isShowingElements() const;     // returns whether the atom elements are shown
00057     bool isShowingNumbers() const;      // returns whether the atom numbers are shown
00058     bool isShowingCharges(const unsigned int type) const;   // returns whether charges of a certain type are showing
00059     unsigned int selectedAtoms() const; // returns the number of atoms selected
00060     void loadCML(QDomElement* root);    // loads the setup of the view
00061     void saveCML(QDomElement* root);    // saves the setup of the view
00062     void setDisplayStyle(const DisplaySource source, const unsigned int style); // sets the display style for a certain primitive
00063     void setLabels(const bool element, const bool number, const unsigned int type);       // sets up showing of the labels
00064 
00066     static void setParameters(GLMoleculeParameters params); // sets new OpenGL parameters
00067 
00068   public slots:
00069     void updateAtomSet(const bool reset = false); // updates the view when the atomset has changed
00070     void selectAll(const bool update = true);     // select all atoms
00071     void unselectAll(const bool update = true);   // unselect all atoms
00072 
00073   protected slots:
00074     void reorderShapes();               // orders the shapes based on opacity
00075 
00076   protected:
00078     enum SelectionType{SELECTION_NONE, SELECTION_ATOM, SELECTION_BOND, SELECTION_ANGLE, SELECTION_TORSION, SELECTION_GROUP,
00079                        SELECTION_BONDS, SELECTION_FORCES}; 
00080 
00081     enum ShapeTypes{SHAPE_ATOMS, SHAPE_BONDS, SHAPE_FORCES, SHAPE_LABELS, SHAPE_IC, SHAPE_SELECTION, SHAPE_NEXT};     
00082 
00084     virtual void keyPressEvent(QKeyEvent* e);     // handles key presses
00085     virtual void initializeGL();        // called once upon initialization
00086     virtual void drawItem(const unsigned int);    // draws the item shapes[i]
00087     virtual void updateGLSettings();    // updates the GL View according to parameters
00088     virtual float boundingSphereRadius();         // calculates the radius of the bounding sphere
00089     void clicked(const QPoint& position);         // handles click events
00090     virtual void updateShapes();        // updates the shapes vector
00091 
00093     struct ShapeProperties             
00095     {
00096       unsigned int id;                  
00097       unsigned int opacity;             
00098       unsigned int type;                
00099       bool operator<(ShapeProperties prop) const
00101       {
00102         return opacity > prop.opacity;
00103       }
00104     };  
00105 
00107     GLfloat centerX;                    
00108     GLfloat centerY;                    
00109     GLfloat centerZ;                    
00110     unsigned int selectionType;         
00111     std::list<unsigned int> selectionList;        
00112     std::vector<ShapeProperties> shapes;
00113 
00115     static GLMoleculeParameters moleculeParameters;         
00116 
00117   private:
00119     enum Directions{DIRECTION_X, DIRECTION_Y, DIRECTION_Z}; 
00120     enum StartIndices{START_ATOMS = 100, START_BONDS = 1, START_FORCES = 2, START_SELECTEDATOMS = 3, START_SELECTEDBONDS = 4}; 
00121  
00123     GLuint makeObjects(const int numSlices);      // generates the atom and bond shapes
00124     void changeObjects(const GLuint startList, const int numSlices);  // changes the atom and bond shapes
00125     void selectEntity(const QPoint position);     // selects the entity at the position
00126     void processSelection(const unsigned int id); // updates the selection according to the change in selection of the ID
00127     void centerMolecule();              // calculates the translations needed to have the molecule centered
00128     void drawScene();                   // does the actual repainting of the OpenGL scene
00129     void drawAtoms();                   // draws the atoms in the OpenGL scene
00130     void drawBonds();                   // draws the bonds
00131     void drawLabels();                  // draws the element names&numbers and possibly charges
00132     void drawForces();                  // draws the forces
00133     void drawICValue();                 // draws the value of the currently selected internal coordinate
00134     void drawSelections();              // draws the selected atoms and internal coordinates
00135 
00137     int atomObject;                     
00138     int bondObject;                     
00139     int forceObjectLines;               
00140     int forceObjectTubes;               
00141     unsigned int moleculeStyle;         
00142     unsigned int forcesStyle;           
00143     bool showElements;                  
00144     bool showNumbers;                   
00145     unsigned int chargeType;            
00146     AtomSet* atoms;                     
00147     GLfloat selectionLineWidth;         
00148     GLfloat selectionPointSize;         
00149     float scaleFactor;                  
00150     QFont labelFont;                    
00151 
00152     // private constants (made static for ease) 
00153     static const float cylinderHeight;  
00154 
00155 };
00156 
00157 #endif
00158 

Generated on Fri May 19 14:31:54 2006 for Brabosphere by  doxygen 1.4.6-NO