kalzium
labelengine.cpp
Go to the documentation of this file.00001 /********************************************************************** 00002 LabelEngine - Engine for displaying labels. 00003 00004 Copyright (C) 2007 Donald Ephraim Curtis <donald-curtis@uiowa.edu> 00005 Copyright (C) 2007 Benoit Jacob <jacob@math.jussieu.fr> 00006 00007 This file is part of the Avogadro molecular editor project. 00008 For more information, see <http://avogadro.sourceforge.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 #include "labelengine.h" 00027 #include <config.h> 00028 00029 #include <avogadro/primitive.h> 00030 #include <avogadro/color.h> 00031 #include <avogadro/glwidget.h> 00032 #include <avogadro/camera.h> 00033 00034 #include <openbabel/obiter.h> 00035 #include <eigen/regression.h> 00036 00037 #include <QtPlugin> 00038 #include <QMessageBox> 00039 00040 using namespace std; 00041 using namespace OpenBabel; 00042 using namespace Avogadro; 00043 using namespace Eigen; 00044 00045 bool LabelEngine::render(GLWidget *gl) 00046 { 00047 if(gl->labelsStyle() == 0) return true; 00048 gl->painter()->beginText(); 00049 QList<Primitive *> list; 00050 00051 list = queue().primitiveList(Primitive::AtomType); 00052 00053 foreach( Primitive *p, list ) { 00054 Atom *atom = static_cast<const Atom *>(p); 00055 const Vector3d pos = atom->pos(); 00056 00057 double renderRadius = gl->renderingEngine()->radius(atom) + 0.05; 00058 00059 double zDistance = gl->camera()->distance(pos); 00060 00061 if(zDistance < 50.0) { 00062 QString str; 00063 if(gl->labelsStyle() == 1) { 00064 str = QString::number(atom->GetIdx()); 00065 } else if(gl->labelsStyle() == 2) { 00066 str = QString::fromAscii(etab.GetSymbol(atom->GetAtomicNum())); 00067 } else { 00068 str = QString::fromAscii(etab.GetName(atom->GetAtomicNum()).data()); 00069 } 00070 00071 Vector3d zAxis = gl->camera()->backtransformedZAxis(); 00072 00073 Vector3d drawPos = pos + zAxis * renderRadius; 00074 00075 glColor3f(1.0, 1.0, 1.0); 00076 gl->painter()->drawText(drawPos, str); 00077 } 00078 } 00079 gl->painter()->endText(); 00080 return true; 00081 } 00082 00083 #include "labelengine.moc" 00084 00085 Q_EXPORT_PLUGIN2(labelengine, LabelEngineFactory)
KDE 4.0 API Reference