/usr/include/avogadro/glwidget.h is in libavogadro-dev 1.2.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 | /**********************************************************************
GLWidget - general OpenGL display
Copyright (C) 2006-2009 Geoffrey R. Hutchison
Copyright (C) 2006,2007 Donald Ephraim Curtis
Copyright (C) 2007-2009 Marcus D. Hanwell
This file is part of the Avogadro molecular editor project.
For more information, see <http://avogadro.cc/>
Avogadro is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Avogadro is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
**********************************************************************/
#ifndef GLWIDGET_H
#define GLWIDGET_H
#include "config.h"
#include <avogadro/global.h>
#include <Eigen/Core>
#ifdef ENABLE_GLSL
#include <GL/glew.h>
#endif
#include <QtOpenGL/QGLWidget>
class QGLContext;
class QLabel;
class QMouseEvent;
class QSettings;
class QUndoStack;
namespace Avogadro {
class Primitive;
class Atom;
class Bond;
class Molecule;
class Camera;
class Painter;
class Tool;
class ToolGroup;
class Extension;
class Color;
class Engine;
class Painter;
class PrimitiveList;
bool engineLessThan( const Engine* lhs, const Engine* rhs );
/**
* @class GLWidget glwidget.h <avogadro/glwidget.h>
* @brief GL widget class for rendering molecules.
* @author Donald Ephraim Curtis
* @author Marcus D. Hanwell
*
* This widget provides a 3D graphical view of a molecule. In terms
* of the Model-View architecture we consider
* the Molecule the model and GLWidget a view of this model.
* The widget relies on various Engine subclasses to handle the
* rendering of the 3d objects.
*
* Each engine is allocated a PrimitiveList object. This queue contains
* all primitivew which that engine is responsible for rendering for this
* GLWidget. Thus, we can have one queue containing only the bonds, and
* one queue containing only the atoms which would allow bonds and atoms
* to be rendered by two different engines.
*/
class GLHit;
class GLThread;
class GLWidgetPrivate;
class GLPainterDevice;
class A_EXPORT GLWidget : public QGLWidget
{
friend class GLThread;
Q_OBJECT
Q_PROPERTY(QColor background READ background WRITE setBackground)
// Q_PROPERTY(float scale READ scale WRITE setScale)
public:
/**
* Constructor.
* @param parent the widget parent.
*/
GLWidget(QWidget *parent = 0);
/**
* Constructor.
* @param format the QGLFormat information.
* @param parent the widget parent.
* @param shareWidget a widget to share the same graphics -- i.e., the underlying GLPainterDevice
*/
explicit GLWidget(const QGLFormat &format, QWidget *parent = 0, const GLWidget * shareWidget = 0);
/**
* Constructor.
* @param molecule the molecule to view.
* @param format the QGLFormat information.
* @param parent the widget parent.
* @param shareWidget a widget to share the same graphics -- i.e., the underlying GLPainterDevice
*/
GLWidget(Molecule *molecule, const QGLFormat &format, QWidget *parent = 0, const GLWidget * shareWidget = 0);
/**
* Destructor.
*/
~GLWidget();
void renderText(double x, double y, double z, const QString &str, const QFont &font, int listBase=2000);
/**
* @param enabled True if quick render is desired when moving the view.
*/
void setQuickRender(bool enabled);
/**
* @return True if quick rendering is being used.
*/
bool quickRender() const;
/**
* @param enabled True if we should render the unit cell axes
*/
void setRenderUnitCellAxes(bool enabled);
/**
* @return True if unit cell axes are being rendered.
*/
bool renderUnitCellAxes() const;
/**
* @return the width of the widget in pixels.
*/
int deviceWidth() { return width(); }
/**
* @return the height of the widget in pixels.
*/
int deviceHeight() { return height(); }
/**
* Virtual function setting the size hint for this widget.
*
* @return the preferred size of the widget.
*/
QSize sizeHint() const;
/**
* Virtual function setting the minimum size hit for this widget.
*
* @return the minimum size the widget can take without causing
* unspecified behaviour.
*/
QSize minimumSizeHint() const;
/**
* @return the radius of the primitive object for this glwidget.
*/
double radius(const Primitive *p) const;
/**
* @return the active Tool.
*/
Tool* tool() const;
/**
* @return the current background color of the rendering area.
*/
QColor background() const;
/**
* Set the current global color map for Primitives.
*/
void setColorMap(Color *);
/**
* @return the current global color map for Primitives.
*/
Color *colorMap() const;
/**
* @param undoStack the new undoStack.
*/
void setUndoStack(QUndoStack *undoStack);
/**
* @return the current GLWidget undoStack.
*/
QUndoStack* undoStack() const;
/**
* @return the current Molecule being viewed.
*/
const Molecule* molecule() const;
/**
* @return the current Molecule being viewed.
*/
Molecule* molecule();
/**
* @return a pointer to the Camera of this widget.
*/
Camera * camera() const;
/**
* @return a list of engines.
*/
QList<Engine *> engines() const;
/**
* Get the hits for a region starting at (x, y) of size (w * h).
*/
QList<GLHit> hits(int x, int y, int w, int h);
/**
* Take a point and figure out which is the closest Primitive under that point.
* @param p the point on the widget that was clicked.
* @return the closest Primitive that was clicked or 0 if nothing.
*/
Primitive* computeClickedPrimitive(const QPoint& p);
/**
* Take a point and figure out which is the closest Atom under that point.
* @param p the point on the widget that was clicked.
* @return the closest Atom that was clicked or 0 if nothing.
*/
Atom* computeClickedAtom(const QPoint& p);
/**
* Take a point and figure out which is the closest Bond under that point.
* @param p the point on the widget that was clicked.
* @return the closest Bond that was clicked or 0 if nothing.
*/
Bond* computeClickedBond(const QPoint& p);
/**
* @return the point at the center of the Molecule.
*/
const Eigen::Vector3d & center() const;
/**
* @return the normalVector for the entire Molecule.
*/
const Eigen::Vector3d & normalVector() const;
/**
* @return the radius of the Molecule.
*/
double radius() const;
/**
* @return the Atom farthest away from the camera.
*/
const Atom *farthestAtom() const;
/**
* @param quality set the global quality of the widget.
*/
void setQuality(int quality);
/**
* @return the global quality of the widget.
*/
int quality() const;
/**
* @param level Set the global fog level of the widget.
*/
void setFogLevel(int level);
/**
* @return The global fog level of the widget.
*/
int fogLevel() const;
/**
* Set to render x, y, z axes as an overlay in the bottom left of the widget.
*/
void setRenderAxes(bool renderAxes);
/**
* @return true if the x, y, z axes are being rendered.
*/
bool renderAxes();
/**
* Set to render the "debug info" (i.e., FPS, number of atoms, etc.)
*/
void setRenderDebug(bool renderDebug);
/**
* @return true if the debug panel is being drawn
*/
bool renderDebug();
/**
* Set to render the modelview matrix along with the debugging overlay
*/
void setRenderModelViewDebug(bool renderModelViewDebug);
/**
* @return true if the modelview matrix is to printed on the debug
* overlay
*/
bool renderModelViewDebug() const;
/**
* Set the ToolGroup of the GLWidget.
*/
void setToolGroup(ToolGroup *toolGroup);
/**
* @return the ToolGroup of the GLWidget.
*/
ToolGroup * toolGroup() const;
/**
* Set the extensions.
*/
void setExtensions(QList<Extension*> extensions);
/** Returns the Painter of this widget. For instance, to draw a sphere in this
* widget, you could do:
* @code
painter()->drawSphere(center, radius)
* @endcode
* @sa class Painter
*/
Painter *painter() const;
/** @name Selection Methods
* These methods are used to manipulate user-selected primitives.
* Each view tracks a list of selected objects (e.g., atoms)
* which can be passed to engines, tools, or used for tasks like
* copying selected atoms, etc.
* @{
*/
/**
* @return the current selected primitives (all Primitive types)
*/
PrimitiveList selectedPrimitives() const;
/**
* Toggle the selection for the atoms in the supplied list.
* That is, if the primitive is selected, deselect it and vice-versa.
*
* @param primitives the set of objects to update.
*/
void toggleSelected(PrimitiveList primitives);
/**
* Toggle the selection for the GLWidget, that is if the primitive is
* selected, deselect it and vice-versa.
*/
void toggleSelected();
/**
* Change the selection status for the atoms in the supplied list.
* All objects in the list will have the same selection status.
*
* @param primitives the set of objects to update.
* @param select whether to select or deselect the objects.
*/
void setSelected(PrimitiveList primitives, bool select = true); // do we pass by value intentionally
/**
* Deselect all objects.
*/
void clearSelected();
/**
* @return true if the Primitive is selected.
*/
bool isSelected(const Primitive *p) const;
/**
* Add a new named selection.
*
* @param name name of the new selection.
* @param primitives the primitives ids.
* @return true if the name is not taken
*/
bool addNamedSelection(const QString &name, PrimitiveList &primitives);
/**
* Remove a named selection by name.
*
* @param name name of the selection to remove.
*/
void removeNamedSelection(const QString &name);
/**
* Remove a named selection by index. Using the index is useful in Models.
*
* @param index index of the selection to remove.
*/
void removeNamedSelection(int index);
/**
* Rename a named selection by index. Using the index is useful in Models.
*
* @param index index of the selection to rename.
*/
void renameNamedSelection(int index, const QString &name);
/**
* Get the names of all named selections.
*
* @return a list with all the named selections.
*/
QList<QString> namedSelections();
/**
* Get the primitives of a named selections by name.
*
* @param name name of the selection.
* @return the primitives for this named selection.
*/
PrimitiveList namedSelectionPrimitives(const QString &name);
/**
* Get the primitives of a named selections by index.
* Using the index is useful in Models.
*
* @param index index of the selection.
* @return the primitives for this named selection.
*/
PrimitiveList namedSelectionPrimitives(int index);
/* end selection method grouping */
/** @} */
/**
* Set the number of unit cells for a periodic molecule like a crystal
* a, b, and c, are the three primitive unit cell axes.
* Does nothing if the molecule does not have a unit cell defined.
*
* @param a number of unit cells to display along the a axis.
* @param b number of unit cells to display along the b axis.
* @param c number of unit cells to display along the c axis.
*/
void setUnitCells(int a, int b, int c);
/**
* Set the color of unit cells
* @param c color of unit cells
*/
void setUnitCellColor(const QColor c);
/**
* @param b Whether to draw lattice edges for all repeated unit cells
* (false) or only the original one (true).
*/
void setOnlyRenderOriginalUnitCell(bool b);
/**
* Clear the unit cell data.
*/
void clearUnitCell();
/**
* @return The number of unit cells to display along the a axis.
*/
int aCells() const;
/**
* @return The number of unit cells to display along the b axis.
*/
int bCells() const;
/**
* @return The number of unit cells to display along the c axis.
*/
int cCells() const;
/**
* @return The color of the rendered unit cell.
*/
Color unitCellColor() const;
/**
* @return Whether to draw lattice edges for all repeated unit cells
* (false) or only the original one (true).
*/
bool onlyRenderOriginalUnitCell();
/**
* The type of projection
*/
enum ProjectionType
{
Perspective = 1,
Orthographic = 2
};
/**
* Set the type of projection
* @param type type of projection
*/
void setProjection(ProjectionType type);
/**
* Get the type of projection
* @return type of projection
*/
ProjectionType projection() const;
/**
* Static pointer to the current GLWidget.
*/
static GLWidget *m_current;
/**
* @return a pointer to the current GLWidget.
*/
static GLWidget *current();
/**
* Set this instance of the GLWidget as the current GLWidget instance.
*/
static void setCurrent(GLWidget *current);
/**
* Trigger a render for GL2PS.
*/
void renderNow();
/**
* Write the settings of the GLWidget in order to save them to disk.
*/
virtual void writeSettings(QSettings &settings) const;
/**
* Read the settings of the GLWidget and restore them.
*/
virtual void readSettings(QSettings &settings);
protected:
friend class GLGraphicsView;
/**
* Virtual function called by QGLWidget on initialization of
* the GL area.
*/
virtual void initializeGL();
/**
* Virtual function called by GLWidget before render() to set up the
* display correctly.
*/
virtual void paintGL();
/**
* Virtual function called by GLGraphicsView before render() to set up the
* display correctly and leave it in an appropriate state after.
*/
virtual void paintGL2();
/**
* Virtual function called whn the GL area is resized
*/
virtual void resizeGL(int, int);
/**
* Virtual function called when the GL area needs repainting.
*/
virtual void paintEvent(QPaintEvent *event);
/**
* Called on resize of the GLWidget to perform resizing of the display.
*/
virtual void resizeEvent(QResizeEvent *event);
/**
* Focus Event
*/
virtual bool event(QEvent *event);
/**
* Virtual function reaction to mouse press in the GL rendering area.
*/
virtual void mousePressEvent(QMouseEvent * event);
/**
* Virtual function reaction to mouse release in the GL rendering area.
*/
virtual void mouseReleaseEvent(QMouseEvent * event);
/**
* Virtual function reaction to mouse being moved in the GL rendering area.
*/
virtual void mouseMoveEvent(QMouseEvent * event);
/**
* Virtual function reaction to mouse while in the GL rendering area.
*/
virtual void wheelEvent(QWheelEvent * event);
/**
* Virtual function reaction to a mouse double-click while in the GL rendering area.
* @since version 1.1
*/
virtual void mouseDoubleClickEvent(QMouseEvent *event);
/**
* Response to key press events.
* @param event the key event information
*/
virtual void keyPressEvent(QKeyEvent *event);
/**
* Response to key release events.
* @param event the key event information
*/
virtual void keyReleaseEvent(QKeyEvent *event);
/**
* Render the scene. To be used in both modes GL_RENDER and GL_SELECT.
* This function calls the render functions of the engines as well as the
* paint events of the tools and is where everything drawn onto the widget
* is called from.
*/
virtual void render();
/**
* Render a full crystal cell
* Called by render() automatically
*
* @param displayList the display list of the primitive unit cell
*/
virtual void renderCrystal(GLuint displayList);
/**
* Render crystal unit cell axes
* called by renderCrystal() automatically
*
*/
virtual void renderCrystalAxes();
/**
* Renders a parallelepiped with defining edge vectors \a v1, \a
* v2, \a v3, with offset \a offset. If the cube intersects the
* viewing volume's near-plane, an appropriate line-loop is
* rendered at the intersection to prevent "missing corners"
* that are visually disturbing.
*
* See
* http://davidlonie.blogspot.com/2011/04/gracefully-clipping-parallelepiped-in.html
* for pictures of what this does.
*
* @param offset Origin for edge vectors
* @param v1 Vector defining one edge starting from \a offset
* @param v2 Vector defining a second edge starting from \a offset
* @param v3 Vector defining a third edge starting from \a offset
* @param lineWidth Width of the lines used to draw the edges
*
* @return True if the parallelepiped is clipped, false otherwise.
*/
virtual bool renderClippedBox(const Eigen::Vector3d &offset,
const Eigen::Vector3d &v1,
const Eigen::Vector3d &v2,
const Eigen::Vector3d &v3,
double lineWidth );
/**
* Render x, y, z axes as an overlay on the bottom left of the widget.
*/
virtual void renderAxesOverlay();
/**
* @deprecated Use renderTextOverlay instead.
* @sa addTextOverlay
* @sa setRenderDebug
*/
virtual void renderDebugOverlay();
/**
* Render a text overlay. This renders all valid strings added
* by addTextOverlay, as well as debug info if needed.
* @sa addTextOverlay
* @sa setRenderDebug
*/
virtual void renderTextOverlay();
/**
* This will return a painting condition that must be met each time
* before a GLThread can run.
*
* @return painting condition.
*/
// QWaitCondition *paintCondition() const;
private:
GLWidgetPrivate * const d;
/**
* Helper function called by all constructors.
*/
void constructor(const GLWidget *shareWidget =0);
/**
* Compute the average frames per second over the last 200+ ms.
*/
inline double computeFramesPerSecond();
/** Read settings and create required engines */
void loadEngines(QSettings &settings);
bool m_glslEnabled;
Tool* m_navigateTool; /// NavigateTool is a super tool
public Q_SLOTS:
/**
* Set the active Tool of the GLWidget.
*/
void setTool(Tool *tool);
/**
* Set the background color of the rendering area (the default is black).
*
* @param background the new background color.
*/
void setBackground(const QColor &background);
/**
* Set the molecule model for this view.
* @param molecule the molecule to view.
*/
void setMolecule(Molecule *molecule);
/**
* A primitive, was removed, so update the selection
*/
void unselectPrimitive(Primitive *);
/**
* An atom, was removed, so update the selection
*/
void unselectAtom(Atom *);
/**
* A bond, was removed, so update the selection
*/
void unselectBond(Bond *);
/**
* Add an engine to the GLWidget.
* @param engine Engine to add to this widget.
*/
void addEngine(Engine *engine);
/**
* Remove an engine from the GLWidget.
* @param engine Engine to remove from this widget.
*/
void removeEngine(Engine *engine);
/**
* Reset to default engines (one of each factory).
*/
void loadDefaultEngines();
/**
* Reload the engine plugins.
*/
void reloadEngines();
/**
* Signal that something changed and the display lists should be invalidated.
*/
void invalidateDLs();
/**
* update the Molecule geometry.
*/
void updateGeometry();
/**
* One or more tools are deleted..
*/
void toolsDestroyed();
/**
* Adds the QLabel @a label to the list of text drawn in the
* text overlay.
*
* @note The GLWidget does not take ownership of the label, but
* retains a QPointer to it. When the QLabel's text should no
* longer be rendered, simply delete the QLabel elsewhere and
* call render().
*
* @sa renderTextOverlay
*/
void addTextOverlay(QLabel* label);
/**
* @overload
*
* Adds the QLabels in @a labels to the list of strings drawn in the
* text overlay.
*
* @note The GLWidget does not take ownership of the string, but
* retains a QPointer to it. When the QLabel's text should no
* longer be rendered, simply delete the QLabel elsewhere and
* call render().
*
* @note Call this functions instead of repeatedly calling
* addTextOverlay(QLabel*) guarantees that all the strings will
* be drawn consecutively.
*
* @sa renderTextOverlay
*/
void addTextOverlay(const QList<QLabel*> &labels);
Q_SIGNALS:
/**
* Signal for the mouse press event which is passed to the tools.
*/
void mousePress(QMouseEvent * event);
/**
* Signal for the mouse release event which is passed to the tools.
*/
void mouseRelease( QMouseEvent * event );
/**
* Signal for the mouse move event which is passed to the tools.
*/
void mouseMove( QMouseEvent * event );
/**
* Signal for the mouse double-click event which is passed to the tools.
*/
void mouseDoubleClick( QMouseEvent * event );
/**
* Signal for the mouse wheel event which is passed to the tools.
*/
void wheel( QWheelEvent * event);
/**
* Signal that the Molecule has changed.
*/
void moleculeChanged(Molecule *newMolecule);
/**
* Signal that an Engine has been added to the GLWidget.
*/
void engineAdded(Engine *engine);
/**
* Signal that an Engine has been removed from the GLWidget.
*/
void engineRemoved(Engine *engine);
/**
* Signal that the GLWidget has resized. Can be used to update child
* widgets, see overlay extension for example.
*/
void resized();
/**
* Named selections have changed.
*/
void namedSelectionsChanged();
/**
* Signal that this GLWidget was activated.
*/
void activated(GLWidget *);
/**
* Signal that the unit cell axis display has changed
*/
void unitCellAxesRenderChanged(bool enabled);
};
} // end namespace Avogadro
#endif
|