Avogadro  1.1.0
Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | Protected Attributes
Avogadro::Engine Class Reference

Engine plugin interface. More...

#include <avogadro/engine.h>

Inheritance diagram for Avogadro::Engine:
Inheritance graph
[legend]

List of all members.

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 PainterDevicepainterDevice () const
virtual void setPainterDevice (const PainterDevice *pd)
virtual const Moleculemolecule () const
virtual double radius (const PainterDevice *pd, const Primitive *primitive=0) const
bool isEnabled () const
void setEnabled (bool enabled)
virtual ColorTypes colorTypes () const
virtual ColorcolorMap ()
virtual Engineclone () const =0
virtual QWidgetsettingsWidget ()
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 PainterDevicem_pd
const Moleculem_molecule
Colorm_colorMap
bool m_enabled
bool m_customPrims
PrimitiveList m_primitives
QList< Atom * > m_atoms
QList< Bond * > m_bonds
QString m_alias
QString m_description

Detailed Description

Engine plugin interface.

Author:
Donald Ephraim Curtis
Marcus D. Hanwell

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.

See also:
GLWidget::render()

Member Enumeration Documentation

Color schemes used by the engine This also affects the tabs in the Display Settings windows. Default: ColorPlugins

Enumerator:
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.

Different properties of an engine which affect the rendering order. This also affects the tabs in the Display Settings windows. Defulat: Opaque

Enumerator:
Transparent 

renders only opaque bits (default)

Overlay 

renders transparency

Primitives accepted by an engine (or none) This also affects the tabs in the Display Settings windows. Default: Atoms | Bonds

Enumerator:
Atoms 

renders no primitives (e.g., overlays)

Bonds 

renders atoms

Molecules 

renders bonds

Surfaces 

renders whole molecules

Fragments 

renders some kind of surface


Constructor & Destructor Documentation

Avogadro::Engine::Engine ( QObject parent = 0)

Constructor

Destructor

References QObject::disconnect().


Member Function Documentation

void Avogadro::Engine::addAtom ( Atom atom) [virtual, slot]

Add the Atom to the engines atom list.

Parameters:
atomto 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.

Parameters:
bondto be added to the bond list.

References QList::append(), changed(), and QList::contains().

void Avogadro::Engine::addPrimitive ( Primitive primitive) [virtual, slot]
Returns:
the alias of the engine.

References QString::isEmpty(), and name().

Referenced by Avogadro::PythonEngine::clone(), setAlias(), and writeSettings().

const QList< Atom * > Avogadro::Engine::atoms ( ) const [virtual]
Returns:
the engine's Atom list containing all atoms the engine can render.

References Avogadro::Molecule::atoms().

const QList< Bond * > Avogadro::Engine::bonds ( ) const [virtual]
Returns:
the engine's Bond list containing all bonds the engine can render.

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().

Clear the primitives of the engine instance.

References changed(), QList::clear(), and Avogadro::PrimitiveList::clear().

virtual Engine* Avogadro::Engine::clone ( ) const [pure virtual]
Returns:
a pointer to an identical engine or 0 if this fails

Implemented in Avogadro::PythonEngine.

virtual Color* Avogadro::Engine::colorMap ( ) [inline, virtual]
Returns:
the current color map used by this engine
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]
Returns:
the color schemes used by this engine.

References ColorPlugins.

Returns:
engine description.

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.

Returns:
True if the Engine has a settings widget.
Note:
Calls settingsWidget() by default and tests for null.

References settingsWidget().

virtual QString Avogadro::Engine::identifier ( ) const [pure virtual]

Virtual unique identifier - needing for saving and loading state.

Note:
This should not be manually overridden - the Engine macro does it.

Implements Avogadro::Plugin.

Implemented in Avogadro::PythonEngine.

Referenced by Avogadro::GLWidget::loadDefaultEngines(), readSettings(), and writeSettings().

bool Avogadro::Engine::isEnabled ( ) const [inline]
Returns:
true if the engine is enabled or false if it is not.

Referenced by Avogadro::PythonEngine::clone(), Avogadro::GLWidget::hits(), Avogadro::GLWidget::radius(), Avogadro::GLWidget::render(), and writeSettings().

Engine::Layers Avogadro::Engine::layers ( ) const [virtual]
Returns:
the layers used by this engine.

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]
Returns:
a string with the name of the engine.

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]
Returns:
the engine's PrimitiveList containing all primitives the engine can render.

Referenced by setPrimitives().

Engine::PrimitiveTypes Avogadro::Engine::primitiveTypes ( ) const [virtual]
Returns:
the primitive types used by this engine.

References Atoms, and Bonds.

double Avogadro::Engine::radius ( const PainterDevice pd,
const Primitive primitive = 0 
) const [virtual]

Get the radius of the primitive referred to.

Parameters:
pdis the painter device used for rendering (e.g., if a primitive is selected)
primitiveis the Primitive to get the radius of.
Returns:
the radius of the Primitive.

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.

Parameters:
atomto 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.

Parameters:
bondto 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.

Parameters:
primitiveto 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.

Returns:
true if the rendering was completed successfully, false otherwise

Example

 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;
Note:
To allow picking to happen you need to push the object type and name. If objects cannot be picked this may be omitted.

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.

Returns:
true if the rendering was completed successfully, false otherwise

Example

 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);
   }
 }
Note:
To allow picking to happen you need to push the object type and name. If objects cannot be picked this may be omitted.

For more information on the various primitive lists available see PrimitiveList.

Referenced by Avogadro::GLWidget::render().

void Avogadro::Engine::setAlias ( const QString alias)
Parameters:
aliasthe 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.

Parameters:
mapis the new colors to be used

References changed(), colorMapChanged(), QObject::connect(), and QObject::disconnect().

void Avogadro::Engine::setDescription ( const QString description)
Parameters:
descriptionthe new description of this engine.

References description().

Referenced by readSettings().

void Avogadro::Engine::setEnabled ( bool  enabled)

Setter to enable or disable the engine instance.

Parameters:
enabledtrue 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.

Parameters:
primitivesthe 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.

Returns:
a QWidget containing the engine settings or 0 if no settings widget is available.

Reimplemented from Avogadro::Plugin.

Reimplemented in Avogadro::PythonEngine.

Referenced by hasSettings().

GLuint Avogadro::Engine::shader ( ) [inline]
Returns:
The active GLSL shader for this engine, only used if GLSL is supported.

Referenced by Avogadro::GLWidget::render().

double Avogadro::Engine::transparencyDepth ( ) const [virtual]
Returns:
transparency level, rendered low to high.

Reimplemented in Avogadro::PythonEngine.

Plugin::Type Avogadro::Engine::type ( ) const [virtual]

Plugin Type

Implements Avogadro::Plugin.

Plugin Type Name (Engines)

References QObject::tr().

void Avogadro::Engine::updatePrimitive ( Primitive primitive) [virtual, slot]

Update the primitive in the engines PrimitiveList.

Parameters:
primitiveto 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().


The documentation for this class was generated from the following files: