00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef GLWIDGET_H
00028 #define GLWIDGET_H
00029
00030 #include <avogadro/global.h>
00031
00032 #include <Eigen/Core>
00033
00034 #ifdef ENABLE_GLSL
00035 #include <GL/glew.h>
00036 #endif
00037
00038 #include <QtOpenGL/QGLWidget>
00039
00040 class QUndoStack;
00041 class QMouseEvent;
00042 class QGLContext;
00043 class QSettings;
00044
00045 namespace Avogadro {
00046
00047 class Primitive;
00048 class Atom;
00049 class Bond;
00050 class Molecule;
00051 class Camera;
00052 class Painter;
00053 class Tool;
00054 class ToolGroup;
00055 class Extension;
00056 class Color;
00057 class Engine;
00058 class Painter;
00059 class PrimitiveList;
00060
00061 bool engineLessThan( const Engine* lhs, const Engine* rhs );
00062
00081 class GLHit;
00082 class GLThread;
00083 class GLWidgetPrivate;
00084 class GLPainterDevice;
00085 class A_EXPORT GLWidget : public QGLWidget
00086 {
00087 friend class GLThread;
00088
00089 Q_OBJECT
00090 Q_PROPERTY(QColor background READ background WRITE setBackground)
00091
00092
00093 public:
00098 GLWidget(QWidget *parent = 0);
00099
00106 explicit GLWidget(const QGLFormat &format, QWidget *parent = 0, const GLWidget * shareWidget = 0);
00107
00115 GLWidget(Molecule *molecule, const QGLFormat &format, QWidget *parent = 0, const GLWidget * shareWidget = 0);
00116
00120 ~GLWidget();
00121
00122 void renderText(double x, double y, double z, const QString &str, const QFont &font, int listBase=2000);
00126 void setQuickRender(bool enabled);
00127
00131 bool quickRender() const;
00132
00136 void setRenderUnitCellAxes(bool enabled);
00137
00141 bool renderUnitCellAxes() const;
00142
00146 int deviceWidth() { return width(); }
00147
00151 int deviceHeight() { return height(); }
00152
00158 QSize sizeHint() const;
00159
00166 QSize minimumSizeHint() const;
00167
00171 double radius(const Primitive *p) const;
00172
00176 Tool* tool() const;
00177
00181 QColor background() const;
00182
00186 void setColorMap(Color *);
00187
00191 Color *colorMap() const;
00192
00196 void setUndoStack(QUndoStack *undoStack);
00197
00201 QUndoStack* undoStack() const;
00202
00206 const Molecule* molecule() const;
00207
00211 Molecule* molecule();
00212
00216 Camera * camera() const;
00217
00221 QList<Engine *> engines() const;
00222
00226 QList<GLHit> hits(int x, int y, int w, int h);
00227
00233 Primitive* computeClickedPrimitive(const QPoint& p);
00234
00240 Atom* computeClickedAtom(const QPoint& p);
00241
00247 Bond* computeClickedBond(const QPoint& p);
00248
00252 const Eigen::Vector3d & center() const;
00256 const Eigen::Vector3d & normalVector() const;
00260 double radius() const;
00264 const Atom *farthestAtom() const;
00265
00269 void setQuality(int quality);
00270
00274 int quality() const;
00275
00279 void setFogLevel(int level);
00280
00284 int fogLevel() const;
00285
00289 void setRenderAxes(bool renderAxes);
00290
00294 bool renderAxes();
00295
00299 void setRenderDebug(bool renderDebug);
00300
00304 bool renderDebug();
00305
00309 void setToolGroup(ToolGroup *toolGroup);
00310
00314 ToolGroup * toolGroup() const;
00315
00319 void setExtensions(QList<Extension*> extensions);
00320
00328 Painter *painter() const;
00329
00341 PrimitiveList selectedPrimitives() const;
00342
00349 void toggleSelected(PrimitiveList primitives);
00350
00355 void toggleSelected();
00356
00364 void setSelected(PrimitiveList primitives, bool select = true);
00365
00369 void clearSelected();
00370
00374 bool isSelected(const Primitive *p) const;
00375
00383 bool addNamedSelection(const QString &name, PrimitiveList &primitives);
00389 void removeNamedSelection(const QString &name);
00395 void removeNamedSelection(int index);
00401 void renameNamedSelection(int index, const QString &name);
00407 QList<QString> namedSelections();
00414 PrimitiveList namedSelectionPrimitives(const QString &name);
00422 PrimitiveList namedSelectionPrimitives(int index);
00423
00435 void setUnitCells(int a, int b, int c);
00436
00441 void setUnitCellColor(const QColor c);
00442
00446 void clearUnitCell();
00447
00451 int aCells();
00452
00456 int bCells();
00457
00461 int cCells();
00462
00466 static GLWidget *m_current;
00467
00471 static GLWidget *current();
00472
00476 static void setCurrent(GLWidget *current);
00477
00481 void renderNow();
00482
00486 virtual void writeSettings(QSettings &settings) const;
00487
00491 virtual void readSettings(QSettings &settings);
00492
00493
00494 protected:
00495 friend class GLGraphicsView;
00500 virtual void initializeGL();
00501
00506 virtual void paintGL();
00507
00512 virtual void paintGL2();
00513
00517 virtual void resizeGL(int, int);
00518
00522 virtual void paintEvent(QPaintEvent *event);
00523
00527 virtual void resizeEvent(QResizeEvent *event);
00528
00532 virtual bool event(QEvent *event);
00533
00537 virtual void mousePressEvent(QMouseEvent * event);
00538
00542 virtual void mouseReleaseEvent(QMouseEvent * event);
00543
00547 virtual void mouseMoveEvent(QMouseEvent * event);
00548
00552 virtual void wheelEvent(QWheelEvent * event);
00553
00558 virtual void keyPressEvent(QKeyEvent *event);
00559
00564 virtual void keyReleaseEvent(QKeyEvent *event);
00565
00572 virtual void render();
00573
00580 virtual void renderCrystal(GLuint displayList);
00581
00587 virtual void renderCrystalAxes();
00588
00592 virtual void renderAxesOverlay();
00593
00597 virtual void renderDebugOverlay();
00598
00605
00606
00607
00608 private:
00609 GLWidgetPrivate * const d;
00610
00614 void constructor(const GLWidget *shareWidget =0);
00615
00619 inline double computeFramesPerSecond();
00620
00621 bool m_glslEnabled;
00622 Tool* m_navigateTool;
00623
00624 public Q_SLOTS:
00625
00629 void setTool(Tool *tool);
00630
00636 void setBackground(const QColor &background);
00637
00642 void setMolecule(Molecule *molecule);
00643
00647 void unselectPrimitive(Primitive *);
00648
00652 void unselectAtom(Atom *);
00653
00657 void unselectBond(Bond *);
00658
00663 void addEngine(Engine *engine);
00664
00669 void removeEngine(Engine *engine);
00670
00674 void loadDefaultEngines();
00675
00679 void reloadEngines();
00680
00684 void invalidateDLs();
00685
00689 void updateGeometry();
00690
00694 void toolsDestroyed();
00695
00696 Q_SIGNALS:
00700 void mousePress(QMouseEvent * event);
00701
00705 void mouseRelease( QMouseEvent * event );
00706
00710 void mouseMove( QMouseEvent * event );
00711
00715 void wheel( QWheelEvent * event);
00716
00720 void moleculeChanged(Molecule *newMolecule);
00721
00725 void engineAdded(Engine *engine);
00726
00730 void engineRemoved(Engine *engine);
00731
00736 void resized();
00737
00741 void namedSelectionsChanged();
00742
00746 void activated(GLWidget *);
00747
00751 void unitCellAxesRenderChanged(bool enabled);
00752
00753
00754 };
00755
00756 }
00757
00758 #endif