Avogadro
1.1.0
|
Engine plugin interface. More...
#include <avogadro/engine.h>
Public Types | |
enum | Layer { Opaque = 0x00, Transparent = 0x01, Overlay = 0x02 } |
enum | PrimitiveType { NoPrimitives = 0x00, Atoms = 0x01, Bonds = 0x02, Molecules = 0x04, Surfaces = 0x08, Fragments = 0x10 } |
enum | ColorType { NoColors = 0x00, ColorPlugins = 0x01, IndexedColors = 0x02, ColorGradients = 0x04 } |
Public Slots | |
virtual void | addPrimitive (Primitive *primitive) |
virtual void | updatePrimitive (Primitive *primitive) |
virtual void | removePrimitive (Primitive *primitive) |
virtual void | addAtom (Atom *atom) |
virtual void | removeAtom (Atom *atom) |
virtual void | addBond (Bond *bond) |
virtual void | removeBond (Bond *bond) |
virtual void | setColorMap (Color *map) |
virtual void | colorMapChanged () |
virtual void | setMolecule (const Molecule *molecule) |
virtual void | setMolecule (Molecule *molecule) |
Signals | |
void | changed () |
void | enableToggled (bool enabled) |
Public Member Functions | |
Engine (QObject *parent=0) | |
virtual | ~Engine () |
virtual QString | identifier () const =0 |
Plugin::Type | type () const |
QString | typeName () const |
virtual QString | name () const =0 |
QString | alias () const |
void | setAlias (const QString &alias) |
QString | description () const |
void | setDescription (const QString &description) |
GLuint | shader () |
void | setShader (GLuint shader) |
virtual Layers | layers () const |
virtual bool | renderOpaque (PainterDevice *pd)=0 |
virtual bool | renderTransparent (PainterDevice *) |
virtual bool | renderQuick (PainterDevice *pd) |
virtual bool | renderPick (PainterDevice *pd) |
virtual double | transparencyDepth () const |
virtual PrimitiveTypes | primitiveTypes () const |
virtual const PrimitiveList | primitives () const |
virtual const QList< Atom * > | atoms () const |
virtual const QList< Bond * > | bonds () const |
virtual void | setPrimitives (const PrimitiveList &primitives) |
virtual void | clearPrimitives () |
virtual const PainterDevice * | painterDevice () const |
virtual void | setPainterDevice (const PainterDevice *pd) |
virtual const Molecule * | molecule () const |
virtual double | radius (const PainterDevice *pd, const Primitive *primitive=0) const |
bool | isEnabled () const |
void | setEnabled (bool enabled) |
virtual ColorTypes | colorTypes () const |
virtual Color * | colorMap () |
virtual Engine * | clone () const =0 |
virtual QWidget * | settingsWidget () |
virtual bool | hasSettings () |
virtual void | writeSettings (QSettings &settings) const |
virtual void | readSettings (QSettings &settings) |
Protected Member Functions | |
virtual void | useCustomPrimitives () |
Protected Attributes | |
EnginePrivate *const | d |
GLuint | m_shader |
const PainterDevice * | m_pd |
const Molecule * | m_molecule |
Color * | m_colorMap |
bool | m_enabled |
bool | m_customPrims |
PrimitiveList | m_primitives |
QList< Atom * > | m_atoms |
QList< Bond * > | m_bonds |
QString | m_alias |
QString | m_description |
Engine plugin interface.
This class provides an interface for our engines. Subclasses of this class are loaded by the GLWidget and used to render different parts of our project (Molecule, Atom, Bond, Residue) depending on what style of engine we are implementing.
Color schemes used by the engine This also affects the tabs in the Display Settings windows. Default: ColorPlugins
ColorPlugins |
predefined colors in the engine (e.g., overlays) |
IndexedColors |
uses color plugins defined in color.h (default) |
ColorGradients |
uses a set of colors defined in indexcolor.h |
Reimplemented from Avogadro::Plugin.
Avogadro::Engine::Engine | ( | QObject * | parent = 0 | ) |
Constructor
Avogadro::Engine::~Engine | ( | ) | [virtual] |
Destructor
References QObject::disconnect().
void Avogadro::Engine::addAtom | ( | Atom * | atom | ) | [virtual, slot] |
Add the Atom to the engines atom list.
atom | to be added to the atom list. |
References QList::append(), changed(), and QList::contains().
void Avogadro::Engine::addBond | ( | Bond * | bond | ) | [virtual, slot] |
Add the Bond to the engines bond list.
bond | to be added to the bond list. |
References QList::append(), changed(), and QList::contains().
void Avogadro::Engine::addPrimitive | ( | Primitive * | primitive | ) | [virtual, slot] |
Add the primitive to the engines PrimitiveList.
primitive | to be added to the PrimitiveList. |
References QList::append(), Avogadro::PrimitiveList::append(), Avogadro::Primitive::AtomType, Avogadro::Primitive::BondType, changed(), QList::contains(), and Avogadro::PrimitiveList::contains().
QString Avogadro::Engine::alias | ( | ) | const |
References QString::isEmpty(), and name().
Referenced by Avogadro::PythonEngine::clone(), setAlias(), and writeSettings().
const QList< Atom * > Avogadro::Engine::atoms | ( | ) | const [virtual] |
References Avogadro::Molecule::atoms().
const QList< Bond * > Avogadro::Engine::bonds | ( | ) | const [virtual] |
References Avogadro::Molecule::bonds().
void Avogadro::Engine::changed | ( | ) | [signal] |
Signals that something has been changed and the engine needs to render after these changes were made.
Referenced by addAtom(), addBond(), addPrimitive(), clearPrimitives(), colorMapChanged(), removeAtom(), removeBond(), removePrimitive(), setColorMap(), setEnabled(), setPrimitives(), and updatePrimitive().
void Avogadro::Engine::clearPrimitives | ( | ) | [virtual] |
Clear the primitives of the engine instance.
References changed(), QList::clear(), and Avogadro::PrimitiveList::clear().
virtual Engine* Avogadro::Engine::clone | ( | ) | const [pure virtual] |
Implemented in Avogadro::PythonEngine.
virtual Color* Avogadro::Engine::colorMap | ( | ) | [inline, virtual] |
void Avogadro::Engine::colorMapChanged | ( | ) | [virtual, slot] |
Accept that the color map changed and call for an update (e.g., the user modified the settings)
References changed().
Referenced by setColorMap().
Engine::ColorTypes Avogadro::Engine::colorTypes | ( | ) | const [virtual] |
References ColorPlugins.
QString Avogadro::Engine::description | ( | ) | const [virtual] |
Reimplemented from Avogadro::Plugin.
Reimplemented in Avogadro::PythonEngine.
Referenced by setDescription(), and writeSettings().
void Avogadro::Engine::enableToggled | ( | bool | enabled | ) | [signal] |
Signals that the engine has been enabled or disabled.
Referenced by setEnabled().
bool Avogadro::Engine::hasSettings | ( | ) | [virtual] |
This method can provide a much faster way of determining if an Engine has a configuration dialog, it should be reimplemented in classes to avoid the settings wigdet being constructed in order to check whether an engine has settings.
References settingsWidget().
virtual QString Avogadro::Engine::identifier | ( | ) | const [pure virtual] |
Virtual unique identifier - needing for saving and loading state.
Implements Avogadro::Plugin.
Implemented in Avogadro::PythonEngine.
Referenced by Avogadro::GLWidget::loadDefaultEngines(), readSettings(), and writeSettings().
bool Avogadro::Engine::isEnabled | ( | ) | const [inline] |
Referenced by Avogadro::PythonEngine::clone(), Avogadro::GLWidget::hits(), Avogadro::GLWidget::radius(), Avogadro::GLWidget::render(), and writeSettings().
Engine::Layers Avogadro::Engine::layers | ( | ) | const [virtual] |
Reimplemented in Avogadro::PythonEngine.
Referenced by Avogadro::GLWidget::render().
virtual const Molecule* Avogadro::Engine::molecule | ( | ) | const [inline, virtual] |
Get the Molecule for the engine.
Referenced by setMolecule().
virtual QString Avogadro::Engine::name | ( | ) | const [pure virtual] |
Implements Avogadro::Plugin.
Implemented in Avogadro::PythonEngine.
Referenced by alias().
virtual const PainterDevice* Avogadro::Engine::painterDevice | ( | ) | const [inline, virtual] |
Get the PainterDevice for the engine.
const PrimitiveList Avogadro::Engine::primitives | ( | ) | const [virtual] |
Referenced by setPrimitives().
Engine::PrimitiveTypes Avogadro::Engine::primitiveTypes | ( | ) | const [virtual] |
double Avogadro::Engine::radius | ( | const PainterDevice * | pd, |
const Primitive * | primitive = 0 |
||
) | const [virtual] |
Get the radius of the primitive referred to.
pd | is the painter device used for rendering (e.g., if a primitive is selected) |
primitive | is the Primitive to get the radius of. |
Referenced by Avogadro::GLWidget::radius().
void Avogadro::Engine::readSettings | ( | QSettings & | settings | ) | [virtual] |
Read in the settings that have been saved for the engine instance.
Reimplemented from Avogadro::Plugin.
Reimplemented in Avogadro::PythonEngine.
References identifier(), setAlias(), setDescription(), setEnabled(), QVariant::toBool(), QVariant::toString(), and QSettings::value().
void Avogadro::Engine::removeAtom | ( | Atom * | atom | ) | [virtual, slot] |
Remove the Atom from from the engines atom list.
atom | to be removed from the atom list. |
References changed(), and QList::removeAll().
void Avogadro::Engine::removeBond | ( | Bond * | bond | ) | [virtual, slot] |
Remove the Bond from from the engines bond list.
bond | to be removed from the bond list. |
References changed(), and QList::removeAll().
void Avogadro::Engine::removePrimitive | ( | Primitive * | primitive | ) | [virtual, slot] |
Remove the primitive from from the engines PrimitiveList.
primitive | to be removed from the PrimitiveList. |
References Avogadro::Primitive::AtomType, Avogadro::Primitive::BondType, changed(), QList::removeAll(), and Avogadro::PrimitiveList::removeAll().
virtual bool Avogadro::Engine::renderOpaque | ( | PainterDevice * | pd | ) | [pure virtual] |
Render opaque elements. This function is allowed to render whatever opaque primitives it wishes. There is no requirement that it render every primitive.
During generation of the GL view engines will have their render functions called at most once. It is the responsibility of the engine to render all of the objects in it's queue if it can.
true
if the rendering was completed successfully, false
otherwiseExample
Color *map = colorMap(); // possible custom color map if (!map) map = pd->colorMap(); // fall back to global color map // Get a list of bonds and render them QList<Primitive *> list; list = primitives().subList(Primitive::BondType); foreach(Primitive *p, list) render(static_cast<const Bond *>(p)) return true;
For more information on the various primitive lists available see PrimitiveList.
Implemented in Avogadro::PythonEngine.
Referenced by Avogadro::GLWidget::render().
virtual bool Avogadro::Engine::renderPick | ( | PainterDevice * | pd | ) | [inline, virtual] |
Render all elements the engine is responsible for quickly with an emphasis on speed and only rendering things which can be picked. Things such as color can be neglected here as this is never seen.
Referenced by Avogadro::GLWidget::hits().
virtual bool Avogadro::Engine::renderQuick | ( | PainterDevice * | pd | ) | [inline, virtual] |
Render all elements the engine is responsible for quickly with an emphasis on maintaining interactivity even with very large molecules. By default this function calls renderOpaque but in most cases should be implemented and tuned using large molecule test cases. The GLWidget ensures dynamic scaling of geometric primitives is off before calling this rendering function.
virtual bool Avogadro::Engine::renderTransparent | ( | PainterDevice * | ) | [inline, virtual] |
Render transparent elements. This function is allowed to render whatever transparent primitives it wishes. There is no requirement that it render every primitive.
During generation of the GL view engines will have their render functions called at most once. It is the responsibility of the engine to render all of the objects in it's queue if it can.
true
if the rendering was completed successfully, false
otherwiseExample
Color *map = colorMap(); // possible custom color map if (!map) map = pd->colorMap(); // fall back to global color map // Get a list of atoms and render the selected ones as transparent spheres QList<Primitive *> list; list = primitives().subList(Primitive::AtomType); foreach(Primitive *p, list) { const Atom *a = static_cast<const Atom *>(p); // Render the selection highlight if (pd->isSelected(a)) { map->set(0.3, 0.6, 1.0, 0.7); glEnable(GL_BLEND); pd->painter()->setColor(map); pd->painter()->setName(a); pd->painter()->drawSphere(a->pos(), 0.1 + radius( a )); glDisable(GL_BLEND); } }
For more information on the various primitive lists available see PrimitiveList.
Referenced by Avogadro::GLWidget::render().
void Avogadro::Engine::setAlias | ( | const QString & | alias | ) |
alias | the new alias for the engine instance. |
References alias().
Referenced by Avogadro::PythonEngine::clone(), and readSettings().
void Avogadro::Engine::setColorMap | ( | Color * | map | ) | [virtual, slot] |
Set the color map to be used for this engine. The default is to color each atom by element.
map | is the new colors to be used |
References changed(), colorMapChanged(), QObject::connect(), and QObject::disconnect().
void Avogadro::Engine::setDescription | ( | const QString & | description | ) |
description | the new description of this engine. |
References description().
Referenced by readSettings().
void Avogadro::Engine::setEnabled | ( | bool | enabled | ) |
Setter to enable or disable the engine instance.
enabled | true to enable the egine, false to disable the engine. |
References changed(), and enableToggled().
Referenced by Avogadro::PythonEngine::clone(), Avogadro::GLWidget::loadDefaultEngines(), and readSettings().
void Avogadro::Engine::setMolecule | ( | const Molecule * | molecule | ) | [virtual, slot] |
Slot to set the Molecule pointer for this engine.
References QList::clear(), Avogadro::PrimitiveList::clear(), and QObject::disconnect().
Referenced by setPainterDevice().
void Avogadro::Engine::setMolecule | ( | Molecule * | molecule | ) | [virtual, slot] |
Slot to set the Molecule pointer for this engine.
References QList::clear(), Avogadro::PrimitiveList::clear(), QObject::disconnect(), and molecule().
void Avogadro::Engine::setPainterDevice | ( | const PainterDevice * | pd | ) | [virtual] |
Set the PainterDevice pointer for this engine.
References setMolecule().
Referenced by Avogadro::GLWidget::addEngine().
void Avogadro::Engine::setPrimitives | ( | const PrimitiveList & | primitives | ) | [virtual] |
Set the primitives that the engine instance can render.
primitives | the PrimitiveList the engine can render from. |
References QList::append(), Avogadro::Primitive::AtomType, Avogadro::Primitive::BondType, changed(), QList::clear(), primitives(), and Avogadro::PrimitiveList::subList().
void Avogadro::Engine::setShader | ( | GLuint | shader | ) | [inline] |
Set the active GLSL shader for this engine, only used if GLSL is supported.
QWidget * Avogadro::Engine::settingsWidget | ( | ) | [virtual] |
Reimplemented from Avogadro::Plugin.
Reimplemented in Avogadro::PythonEngine.
Referenced by hasSettings().
GLuint Avogadro::Engine::shader | ( | ) | [inline] |
Referenced by Avogadro::GLWidget::render().
double Avogadro::Engine::transparencyDepth | ( | ) | const [virtual] |
Reimplemented in Avogadro::PythonEngine.
Plugin::Type Avogadro::Engine::type | ( | ) | const [virtual] |
Plugin Type
Implements Avogadro::Plugin.
QString Avogadro::Engine::typeName | ( | ) | const |
Plugin Type Name (Engines)
References QObject::tr().
void Avogadro::Engine::updatePrimitive | ( | Primitive * | primitive | ) | [virtual, slot] |
Update the primitive in the engines PrimitiveList.
primitive | to be updated in the PrimitiveList. |
References changed().
void Avogadro::Engine::writeSettings | ( | QSettings & | settings | ) | const [virtual] |
Write the engine settings so that they can be saved between sessions.
Reimplemented from Avogadro::Plugin.
Reimplemented in Avogadro::PythonEngine.
References alias(), description(), identifier(), QString::isEmpty(), isEnabled(), and QSettings::setValue().