Avogadro
1.1.0
|
00001 /********************************************************************** 00002 Engine - Engine interface and plugin factory. 00003 00004 Copyright (C) 2007 Donald Ephraim Curtis 00005 Copyright (C) 2008 Marcus D. Hanwell 00006 00007 This file is part of the Avogadro molecular editor project. 00008 For more information, see <http://avogadro.openmolecules.net/> 00009 00010 Avogadro is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation; either version 2 of the License, or 00013 (at your option) any later version. 00014 00015 Avogadro is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00023 02110-1301, USA. 00024 **********************************************************************/ 00025 00026 #ifndef ENGINE_H 00027 #define ENGINE_H 00028 00029 #include <avogadro/global.h> 00030 00031 #ifdef ENABLE_GLSL 00032 #include <GL/glew.h> 00033 #else 00034 #include <QGLWidget> 00035 #endif 00036 00037 #include "primitivelist.h" 00038 #include "plugin.h" 00039 00040 #include <QList> 00041 #include <QSettings> 00042 #include <QtPlugin> 00043 00044 #define AVOGADRO_ENGINE(i, t, d) \ 00045 public: \ 00046 static QString staticIdentifier() { return i; } \ 00047 QString identifier() const { return i; } \ 00048 static QString staticName() { return t; } \ 00049 QString name() const { return t; } \ 00050 static QString staticDescription() { return d; } \ 00051 QString description() const \ 00052 { if (m_description.isEmpty()) return d; \ 00053 else return m_description; } 00054 00055 #define AVOGADRO_ENGINE_FACTORY(c) \ 00056 public: \ 00057 Avogadro::Plugin *createInstance(QObject *parent = 0) { return new c(parent); } \ 00058 Avogadro::Plugin::Type type() const { return Avogadro::Plugin::EngineType; } \ 00059 QString identifier() const { return c::staticIdentifier(); } \ 00060 QString name() const { return c::staticName(); } \ 00061 QString description() const { return c::staticDescription(); } 00062 00063 namespace Avogadro { 00064 00065 class PainterDevice; 00066 class Atom; 00067 class Bond; 00068 class Molecule; 00069 class Color; 00070 00083 class EnginePrivate; 00084 class A_EXPORT Engine : public Plugin 00085 { 00086 Q_OBJECT 00087 00088 public: 00095 enum Layer { 00096 Opaque = 0x00, 00097 Transparent = 0x01, 00098 Overlay = 0x02 00099 }; 00100 Q_DECLARE_FLAGS(Layers, Layer) 00101 00102 00108 enum PrimitiveType { 00109 NoPrimitives = 0x00, 00110 Atoms = 0x01, 00111 Bonds = 0x02, 00112 Molecules = 0x04, 00113 Surfaces = 0x08, 00114 Fragments = 0x10 00115 }; 00116 Q_DECLARE_FLAGS(PrimitiveTypes, PrimitiveType) 00117 00118 00124 enum ColorType { 00125 NoColors = 0x00, 00126 ColorPlugins = 0x01, 00127 IndexedColors = 0x02, 00128 ColorGradients = 0x04 00129 }; 00130 Q_DECLARE_FLAGS(ColorTypes, ColorType) 00131 00132 public: 00136 Engine(QObject *parent = 0); 00140 virtual ~Engine(); 00141 00146 virtual QString identifier() const = 0; 00147 00151 Plugin::Type type() const; 00152 00156 QString typeName() const; 00157 00161 virtual QString name() const = 0; 00162 00166 QString alias() const; 00167 00171 void setAlias(const QString &alias); 00172 00176 QString description() const; 00177 00181 void setDescription(const QString &description); 00182 00186 GLuint shader() { return m_shader; } 00187 00191 void setShader(GLuint shader) { m_shader = shader; } 00192 00196 virtual Layers layers() const; 00197 00232 virtual bool renderOpaque(PainterDevice *pd) = 0; 00276 virtual bool renderTransparent(PainterDevice *) { return true; } 00277 00286 virtual bool renderQuick(PainterDevice *pd) 00287 { 00288 renderOpaque(pd); 00289 return true; 00290 } 00291 00297 virtual bool renderPick(PainterDevice *pd) 00298 { 00299 renderQuick(pd); 00300 return true; 00301 } 00302 00306 virtual double transparencyDepth() const; 00307 00311 virtual PrimitiveTypes primitiveTypes() const; 00312 00317 virtual const PrimitiveList primitives() const; 00318 00323 virtual const QList<Atom *> atoms() const; 00324 00329 virtual const QList<Bond *> bonds() const; 00330 00335 virtual void setPrimitives(const PrimitiveList &primitives); 00336 00340 virtual void clearPrimitives(); 00341 00345 virtual const PainterDevice * painterDevice() const { return m_pd; } 00346 00350 virtual void setPainterDevice(const PainterDevice *pd); 00351 00355 virtual const Molecule * molecule() const { return m_molecule; } 00356 00362 virtual double radius(const PainterDevice *pd, const Primitive *primitive = 0) const; 00363 00367 bool isEnabled() const { return m_enabled; } 00368 00373 void setEnabled(bool enabled); 00374 00378 virtual ColorTypes colorTypes() const; 00379 00382 virtual Color *colorMap() { return m_colorMap; } 00383 00387 virtual Engine *clone() const = 0; 00388 00393 virtual QWidget *settingsWidget(); 00394 00403 virtual bool hasSettings(); 00404 00408 virtual void writeSettings(QSettings &settings) const; 00409 00413 virtual void readSettings(QSettings &settings); 00414 00415 Q_SIGNALS: 00420 void changed(); 00421 00425 void enableToggled(bool enabled); 00426 00427 public Q_SLOTS: 00432 virtual void addPrimitive(Primitive *primitive); 00433 00438 virtual void updatePrimitive(Primitive *primitive); 00439 00444 virtual void removePrimitive(Primitive *primitive); 00445 00450 virtual void addAtom(Atom *atom); 00451 00456 virtual void removeAtom(Atom *atom); 00457 00462 virtual void addBond(Bond *bond); 00463 00468 virtual void removeBond(Bond *bond); 00469 00474 virtual void setColorMap(Color *map); 00475 00480 virtual void colorMapChanged(); 00481 00485 virtual void setMolecule(const Molecule *molecule); 00486 00490 virtual void setMolecule(Molecule *molecule); 00491 00492 protected: 00493 EnginePrivate *const d; 00494 GLuint m_shader; 00495 const PainterDevice *m_pd; 00496 const Molecule *m_molecule; 00497 Color *m_colorMap; 00498 bool m_enabled; 00499 bool m_customPrims; 00500 PrimitiveList m_primitives; 00501 QList<Atom *> m_atoms; 00502 QList<Bond *> m_bonds; 00503 QString m_alias; 00504 QString m_description; 00505 00506 virtual void useCustomPrimitives(); 00507 }; 00508 00509 } // end namespace Avogadro 00510 00511 Q_DECLARE_METATYPE(Avogadro::Engine*) 00512 00513 Q_DECLARE_OPERATORS_FOR_FLAGS(Avogadro::Engine::Layers) 00514 Q_DECLARE_OPERATORS_FOR_FLAGS(Avogadro::Engine::PrimitiveTypes) 00515 Q_DECLARE_OPERATORS_FOR_FLAGS(Avogadro::Engine::ColorTypes) 00516 00517 #endif