Avogadro  1.1.0
/home/kitware/dashboards/avogadro/libavogadro/src/glpainter_p.h
00001 /**********************************************************************
00002   GLPainter - drawing spheres, cylinders and text in a GLWidget
00003 
00004   Copyright (C) 2007 Benoit Jacob
00005   Copyright (C) 2007 Donald Ephraim Curtis
00006   Copyright (C) 2007-2009 Marcus D. Hanwell
00007   Copyright (C) 2010 Konstantin Tokarev
00008   Copyright (C) 2011 David C. Lonie
00009 
00010   This file is part of the Avogadro molecular editor project.
00011   For more information, see <http://avogadro.openmolecules.net/>
00012 
00013   Avogadro is free software; you can redistribute it and/or modify
00014   it under the terms of the GNU General Public License as published by
00015   the Free Software Foundation; either version 2 of the License, or
00016   (at your option) any later version.
00017 
00018   Avogadro is distributed in the hope that it will be useful,
00019   but WITHOUT ANY WARRANTY; without even the implied warranty of
00020   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021   GNU General Public License for more details.
00022 
00023   You should have received a copy of the GNU General Public License
00024   along with this program; if not, write to the Free Software
00025   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00026   02110-1301, USA.
00027  **********************************************************************/
00028 
00029 #ifndef GLPAINTER_H
00030 #define GLPAINTER_H
00031 
00032 #include <avogadro/global.h>
00033 #include <avogadro/painter.h>
00034 
00035 namespace Avogadro
00036 {
00037 
00049   class GLWidget;
00050   class Color3f;
00051   class GLPainterPrivate;
00052   class GLPainter : public Painter
00053   {
00054     friend class GLWidget;
00055   public:
00056 
00061     GLPainter (int quality=-1);
00062 
00066     ~GLPainter();
00067 
00073     void setQuality(int quality);
00074 
00078     int quality() const;
00079 
00084     void setName(const Primitive *primitive);
00085 
00091     void setName(Primitive::Type type, int id);
00092 
00097     void setColor(const Color *color);
00098 
00103     void setColor(const QColor *color);
00104 
00113     void setColor(float red, float green, float blue, float alpha = 1.0);
00114 
00119     void setColor(QString name);
00120 
00127     void drawSphere(const Eigen::Vector3d &center, double radius);
00128 
00136     void drawCylinder(const Eigen::Vector3d &end1, const Eigen::Vector3d &end2,
00137                       double radius);
00138 
00161     void drawMultiCylinder(const Eigen::Vector3d &end1, const Eigen::Vector3d &end2,
00162                            double radius, int order, double shift);
00163 
00172     void drawCone(const Eigen::Vector3d &base, const Eigen::Vector3d &cap,
00173                   double baseRadius, double capRadius = 0.0);
00174 
00181     void drawLine(const Eigen::Vector3d &start, const Eigen::Vector3d &end,
00182                   double lineWidth);
00183 
00196     void drawMultiLine(const Eigen::Vector3d &start, const Eigen::Vector3d &end,
00197                        double lineWidth, int order, short stipple);
00198 
00207     void drawTriangle(const Eigen::Vector3d &p1, const Eigen::Vector3d &p2,
00208                       const Eigen::Vector3d &p3);
00209 
00218     void drawTriangle(const Eigen::Vector3d &p1, const Eigen::Vector3d &p2,
00219                       const Eigen::Vector3d &p3, const Eigen::Vector3d &n);
00220 
00227     void drawSpline(const QVector<Eigen::Vector3d>& pts, double radius);
00228 
00243     void drawShadedSector(const Eigen::Vector3d & origin,
00244                           const Eigen::Vector3d & direction1,
00245                           const Eigen::Vector3d & direction2, double radius,
00246                           bool alternateAngle = false);
00247 
00262     void drawArc(const Eigen::Vector3d & origin, const Eigen::Vector3d &direction1,
00263                  const Eigen::Vector3d & direction2,
00264                  double radius, double lineWidth, bool alternateAngle = false);
00265 
00274     void drawShadedQuadrilateral(const Eigen::Vector3d & point1,
00275                                  const Eigen::Vector3d & point2,
00276                                  const Eigen::Vector3d & point3,
00277                                  const Eigen::Vector3d & point4);
00278 
00288     void drawQuadrilateral(const Eigen::Vector3d & point1,
00289                            const Eigen::Vector3d & point2,
00290                            const Eigen::Vector3d & point3,
00291                            const Eigen::Vector3d & point4,
00292                            double lineWidth);
00293 
00300     void drawLineLoop(const QList<Eigen::Vector3d> & points,
00301                       const double lineWidth);
00302 
00308     void drawMesh(const Mesh & mesh, int mode = 0);
00309 
00315     void drawColorMesh(const Mesh & mesh, int mode = 0);
00316 
00331     int drawText (int x, int y, const QString &string);
00332 
00347     int drawText(const QPoint& pos, const QString &string);
00348 
00362     int drawText(const Eigen::Vector3d & pos, const QString &string);
00363 
00364     int drawText(const Eigen::Vector3d &pos, const QString &string, const QFont &font);
00365 
00372     void drawBox(const Eigen::Vector3d &corner1,
00373                  const Eigen::Vector3d &corner2);
00374 
00399     void drawBoxEdges(const Eigen::Vector3d &offset,
00400                       const Eigen::Vector3d &v1,
00401                       const Eigen::Vector3d &v2,
00402                       const Eigen::Vector3d &v3,
00403                       const double linewidth);
00404 
00434     void drawBoxEdges(const Eigen::Vector3d &c1,
00435                       const Eigen::Vector3d &c2,
00436                       const Eigen::Vector3d &c3,
00437                       const Eigen::Vector3d &c4,
00438                       const Eigen::Vector3d &c5,
00439                       const Eigen::Vector3d &c6,
00440                       const Eigen::Vector3d &c7,
00441                       const Eigen::Vector3d &c8,
00442                       const double linewidth);
00443 
00451     void drawTorus(const Eigen::Vector3d &pos,
00452                    double majorRadius, double minorRadius);
00453 
00460     void drawEllipsoid(const Eigen::Vector3d &position,
00461                                const Eigen::Matrix3d &matrix);
00462 
00467     void begin(GLWidget *widget);
00468 
00472     void end();
00473 
00477     bool isActive();
00478 
00482     bool isShared();
00483 
00487     static int defaultQuality();
00488 
00492     static int maxQuality();
00493 
00497     void setDynamicScaling(bool scaling);
00498 
00499   protected:
00500     GLPainterPrivate * const d;
00501 
00502     bool m_dynamicScaling;
00503 
00507     void incrementShare();
00508 
00512     void decrementShare();
00513 
00518     void pushName();
00519 
00524     void popName();
00525 
00531     void resetName();
00532 
00537     inline void apply(const Color3f &color);
00538 
00544     inline void applyAsMaterials(const Color3f &color, float alpha = 1.0);
00545   };
00546 } // end namespace Avogadro
00547 
00548 #endif