add_subdirectory(data)
add_subdirectory(tests)
-if(OPENBABEL2_FOUND AND OPENGL_FOUND AND EIGEN_FOUND)
-add_subdirectory(compoundviewer)
-endif(OPENBABEL2_FOUND AND OPENGL_FOUND AND EIGEN_FOUND)
-
set(science_LIB_SRCS
element.cpp
spectrum.cpp
+++ /dev/null
-include_directories(
- ${CMAKE_SOURCE_DIR}/..
- ${CMAKE_CURRENT_BINARY_DIR}/..
- )
-
-set( compoundviewer_SRCS
- kalziumglhelperclasses.cpp
- kalziumglwidget.cpp
- openbabel2wrapper.cpp
- kalziumglpart.cpp
- )
-include_directories( ${OPENBABEL2_INCLUDE_DIR} ${EIGEN_INCLUDE_DIR} )
-
-kde4_automoc(${compoundviewer_SRCS})
-add_subdirectory(widgets)
-
-kde4_add_library(compoundviewer SHARED ${compoundviewer_SRCS})
-
-target_link_libraries(compoundviewer ${OPENBABEL2_LIBRARIES} ${QT_QTOPENGL_LIBRARY} ${KDE4_KPARTS_LIBS} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} )
-
-set_target_properties(compoundviewer PROPERTIES VERSION 4.0.0 SOVERSION 4 )
-
-install(TARGETS compoundviewer DESTINATION ${LIB_INSTALL_DIR} )
-
+++ /dev/null
-[Desktop Entry]
-Encoding=UTF-8
-Icon=kalzium
-MimeType=application/ogg;audio/basic;
-Name=KalziumGLPart
-Name[pa]=ਕੈਲਜੀਅਮGLPart
-Name[sv]=Kalzium GL-programdel
-Name[x-test]=xxKalziumGLPartxx
-Comment=An OpenGL-based 3D-renderer for molecules
-Comment[pa]=ਅਣੂ ਲਈ ਓਪਨ-GL ਅਧਾਰਿਤ 3D-ਰੈਂਡਰਿੰਗ
-Comment[sv]=OpenGL-baserad tredimensionell molekyluppritning
-Comment[x-test]=xxAn OpenGL-based 3D-renderer for moleculesxx
-ServiceTypes=KParts/ReadOnlyPart
-Type=Service
-X-KDE-Library=libkalziumglpart
+++ /dev/null
-/***************************************************************************
- copyright : (C) 2006 by Benoit Jacob <jacob@math.jussieu.fr>
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-#include "kalziumglhelperclasses.h"
-
-using namespace OpenBabel;
-using namespace Eigen;
-
-#include<iostream>
-using namespace std;
-
-namespace KalziumGLHelpers
-{
-
-MolStyle::MolStyle( BondStyle bondStyle, AtomStyle atomStyle,
- double singleBondRadius,
- bool renderMultipleBonds,
- double multipleBondRadius,
- double multipleBondShift,
- double atomRadiusFactor )
-{
- m_bondStyle = bondStyle;
- m_atomStyle = atomStyle;
- m_singleBondRadius = singleBondRadius;
- m_renderMultipleBonds = renderMultipleBonds;
- m_multipleBondRadius = multipleBondRadius;
- m_multipleBondShift = multipleBondShift;
- m_atomRadiusFactor = atomRadiusFactor;
-}
-
-double MolStyle::getAtomRadius( int atomicNumber )
-{
- switch( m_atomStyle )
- {
- case ATOMS_USE_FIXED_RADIUS:
- return m_atomRadiusFactor;
- case ATOMS_USE_VAN_DER_WAALS_RADIUS:
- return m_atomRadiusFactor
- * etab.GetVdwRad( atomicNumber );
- default: return 0;
- }
-}
-
-Color::Color( GLfloat red, GLfloat green, GLfloat blue,
- GLfloat alpha )
-{
- m_red = red;
- m_green = green;
- m_blue = blue;
- m_alpha = alpha;
-}
-
-Color::Color( const OBAtom* atom )
-{
- std::vector<double> rgb = etab.GetRGB( atom->GetAtomicNum() );
- m_red = rgb[0];
- m_green = rgb[1];
- m_blue = rgb[2];
- m_alpha = 1.0;
-}
-
-void Color::applyAsMaterials()
-{
- GLfloat ambientColor [] = { m_red / 2, m_green / 2, m_blue / 2,
- m_alpha };
- GLfloat diffuseColor [] = { m_red, m_green, m_blue, m_alpha };
-
- float s = ( 0.5 + fabsf( m_red - m_green )
- + fabsf( m_blue - m_green ) + fabsf( m_blue - m_red ) ) / 4.0;
-
- float t = 1.0 - s;
-
- GLfloat specularColor [] = { s + t * m_red,
- s + t * m_green,
- s + t * m_blue,
- m_alpha };
-
- glMaterialfv( GL_FRONT, GL_AMBIENT, ambientColor );
- glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuseColor );
- glMaterialfv( GL_FRONT, GL_SPECULAR, specularColor );
- glMaterialf( GL_FRONT, GL_SHININESS, 50.0 );
-}
-
-Sphere::Sphere()
-{
- m_vertexBuffer = 0;
- m_indexBuffer = 0;
- m_displayList = 0;
- m_detail = 0;
-}
-
-Sphere::~Sphere()
-{
- freeBuffers();
- if( m_displayList )
- glDeleteLists( m_displayList, 1 );
-}
-
-void Sphere::freeBuffers()
-{
- if( m_indexBuffer )
- {
- delete [] m_indexBuffer;
- m_indexBuffer = 0;
- }
- if( m_vertexBuffer )
- {
- delete [] m_vertexBuffer;
- m_vertexBuffer = 0;
- }
-}
-
-void Sphere::do_draw() const
-{
- glVertexPointer( 3, GL_FLOAT, 0, m_vertexBuffer );
- glNormalPointer( GL_FLOAT, 0, m_vertexBuffer );
- glDrawElements( GL_TRIANGLE_STRIP, m_indexCount,
- GL_UNSIGNED_SHORT, m_indexBuffer );
-}
-
-void Sphere::draw( const Eigen::Vector3d ¢er, double radius ) const
-{
- glPushMatrix();
- glTranslated( center.x(), center.y(), center.z() );
- glScaled( radius, radius, radius );
-#ifdef USE_DISPLAY_LISTS
- glCallList( m_displayList );
-#else
- do_draw();
-#endif
- glPopMatrix();
-}
-
-void Sphere::initialize()
-{
- if( m_detail < 1 ) return;
-
- // compute number of vertices and indices
- m_vertexCount = ( 3 * m_detail + 1 ) * ( 5 * m_detail + 1 );
- m_indexCount = (2 * ( 2 * m_detail + 1 ) + 2 ) * 5 * m_detail;
-
- // deallocate any previously allocated buffer
- freeBuffers();
-
- // allocate memory for buffers
- m_vertexBuffer = new Vector3f[m_vertexCount];
- if( ! m_vertexBuffer ) return;
- m_indexBuffer = new unsigned short[m_indexCount];
- if( ! m_indexBuffer ) return;
-
- // build vertex buffer
- for( int strip = 0; strip < 5; strip++ )
- for( int column = 1; column < m_detail; column++ )
- for( int row = column; row <= 2 * m_detail + column; row++ )
- computeVertex( strip, column, row );
-
- for( int strip = 1; strip < 5; strip++ )
- for( int row = 0; row <= 3 * m_detail; row++ )
- computeVertex( strip, 0, row );
-
- for( int row = 0; row <= 2 * m_detail; row++ )
- computeVertex( 0, 0, row );
-
- for( int row = m_detail; row <= 3 * m_detail; row++ )
- computeVertex( 4, m_detail, row );
-
- // build index buffer
- unsigned int i = 0;
- for( int strip = 0; strip < 5; strip++ )
- for( int column = 0; column < m_detail; column++ )
- {
- int row = column;
- m_indexBuffer[i++] = indexOfVertex( strip, column, row );
- for( ; row <= 2 * m_detail + column; row++ )
- {
- m_indexBuffer[i++] =
- indexOfVertex( strip, column, row );
- m_indexBuffer[i++] =
- indexOfVertex( strip, column + 1, row + 1 );
- }
- m_indexBuffer[i++] = indexOfVertex( strip, column + 1,
- 2 * m_detail + column + 1);
- }
-
-#ifdef USE_DISPLAY_LISTS
- // compile display list and free buffers
- if( ! m_displayList ) m_displayList = glGenLists( 1 );
- if( ! m_displayList ) return;
- glNewList( m_displayList, GL_COMPILE );
- do_draw();
- glEndList();
- freeBuffers();
-#endif
-}
-
-unsigned short Sphere::indexOfVertex( int strip, int column, int row)
-{
- return ( row + ( 3 * m_detail + 1 ) * ( column + m_detail * strip ) );
-}
-
-void Sphere::computeVertex( int strip, int column, int row)
-{
- strip %= 5;
- int next_strip = (strip + 1) % 5;
-
- // the index of the vertex we want to store the result in
- unsigned short index = indexOfVertex( strip, column, row );
-
- // reference to the vertex we want to store the result in
- Vector3f & vertex = m_vertexBuffer[ index ];
-
- // the "golden ratio", useful to construct an icosahedron
- const float phi = ( 1 + sqrt(5.0) ) / 2;
-
- // the 12 vertices of the icosahedron
- const Vector3f northPole( 0, 1, phi );
- const Vector3f northVertices[5] = {
- Vector3f( 0, -1, phi ),
- Vector3f( phi, 0, 1 ),
- Vector3f( 1, phi, 0 ),
- Vector3f( -1, phi, 0 ),
- Vector3f( -phi, 0, 1 ) };
- const Vector3f southVertices[5] = {
- Vector3f( -1, -phi, 0 ),
- Vector3f( 1, -phi, 0 ),
- Vector3f( phi, 0, -1 ),
- Vector3f( 0, 1, -phi ),
- Vector3f( -phi, 0, -1 )
- };
- const Vector3f southPole( 0, -1, -phi );
-
- // pointers to the 3 vertices of the face of the icosahedron
- // in which we are
- const Vector3f *v0, *v1, *v2;
-
- // coordinates of our position inside this face.
- // range from 0 to m_detail.
- int c1, c2;
-
- // first, normalize the global coords row, column
- if( row >= 2 * m_detail && column == 0 )
- {
- strip--;
- if( strip < 0 ) strip += 5;
- next_strip--;
- if( next_strip < 0 ) next_strip += 5;
- column = m_detail;
- }
-
- // next, determine in which face we are, and determine the coords
- // of our position inside this face
- if( row <= m_detail )
- {
- v0 = &northVertices[strip];
- v1 = &northPole;
- v2 = &northVertices[next_strip];
- c1 = m_detail - row;
- c2 = column;
- }
- else if( row >= 2 * m_detail )
- {
- v0 = &southVertices[next_strip];
- v1 = &southPole;
- v2 = &southVertices[strip];
- c1 = row - 2 * m_detail;
- c2 = m_detail - column;
- }
- else if( row <= m_detail + column )
- {
- v0 = &northVertices[next_strip];
- v1 = &southVertices[next_strip];
- v2 = &northVertices[strip];
- c1 = row - m_detail;
- c2 = m_detail - column;
- }
- else
- {
- v0 = &southVertices[strip];
- v1 = &southVertices[next_strip];
- v2 = &northVertices[strip];
- c1 = column;
- c2 = 2 * m_detail - row;
- }
-
- // now, compute the actual coords of the vertex
- float u1 = static_cast<float>(c1) / m_detail;
- float u2 = static_cast<float>(c2) / m_detail;
- vertex = *v0 + u1 * ( *v1 - *v0 ) + u2 * ( *v2 - *v0 );
-
- // project the vertex onto the sphere
- vertex.normalize();
-}
-
-void Sphere::setup( int detail )
-{
- if( detail == m_detail ) return;
- m_detail = detail;
- initialize();
-}
-
-Cylinder::Cylinder()
-{
- m_vertexBuffer = 0;
- m_normalBuffer = 0;
- m_displayList = 0;
- m_faces = 0;
-}
-
-Cylinder::~Cylinder()
-{
- freeBuffers();
- if( m_displayList )
- glDeleteLists( m_displayList, 1 );
-}
-
-void Cylinder::freeBuffers()
-{
- if( m_normalBuffer )
- {
- delete [] m_normalBuffer;
- m_normalBuffer = 0;
- }
- if( m_vertexBuffer )
- {
- delete [] m_vertexBuffer;
- m_vertexBuffer = 0;
- }
-}
-
-void Cylinder::setup( int faces )
-{
- if( faces == m_faces ) return;
- m_faces = faces;
- initialize();
-}
-
-void Cylinder::initialize()
-{
- if( m_faces < 3 ) return;
-
- // compute number of vertices
- m_vertexCount = 2 * m_faces + 2;
-
- // deallocate any previously allocated buffer
- freeBuffers();
-
- // allocate memory for buffers
- m_vertexBuffer = new Vector3f[m_vertexCount];
- if( ! m_vertexBuffer ) return;
- m_normalBuffer = new Vector3f[m_vertexCount];
- if( ! m_normalBuffer ) return;
-
- // build vertex and normal buffers
- for( int i = 0; i <= m_faces; i++ )
- {
- float angle = 2 * M_PI * i / m_faces;
- Vector3f v( cosf(angle), sinf(angle), 0.0f );
- m_normalBuffer[ 2 * i ] = v;
- m_normalBuffer[ 2 * i + 1 ] = v;
- m_vertexBuffer[ 2 * i ] = v;
- m_vertexBuffer[ 2 * i + 1 ] = v;
- m_vertexBuffer[ 2 * i ].z() = 1.0f;
- }
-
-#ifdef USE_DISPLAY_LISTS
- // compile display list and free buffers
- if( ! m_displayList ) m_displayList = glGenLists( 1 );
- if( ! m_displayList ) return;
- glNewList( m_displayList, GL_COMPILE );
- do_draw();
- glEndList();
- freeBuffers();
-#endif
-}
-
-void Cylinder::do_draw() const
-{
- glVertexPointer( 3, GL_FLOAT, 0, m_vertexBuffer );
- glNormalPointer( GL_FLOAT, 0, m_normalBuffer );
- glDrawArrays( GL_QUAD_STRIP, 0, m_vertexCount );
-}
-
-void Cylinder::draw( const Vector3d &end1, const Vector3d &end2,
- double radius, int order, double shift ) const
-{
- // the "axis vector" of the cylinder
- Vector3d axis = end2 - end1;
- double axisNorm = axis.norm();
- if( axisNorm == 0.0 ) return;
- Vector3d axisNormalized = axis / axisNorm;
-
- Vector3d ortho1( axisNormalized.y(), -axisNormalized.x(), 0.0 );
- double ortho1Norm = ortho1.norm();
- if( ortho1Norm > 0.001 ) ortho1 /= ortho1Norm;
- else {
- ortho1 = Vector3d( 0.0,
- axisNormalized.z(),
- -axisNormalized.y() );
- ortho1.normalize();
- }
- ortho1 *= radius;
-
- Vector3d ortho2 = cross( axisNormalized, ortho1 );
-
- // construct the 4D transformation matrix
- Matrix4d matrix;
-
- matrix(0, 0) = ortho1(0);
- matrix(1, 0) = ortho1(1);
- matrix(2, 0) = ortho1(2);
- matrix(3, 0) = 0.0;
-
- matrix(0, 1) = ortho2(0);
- matrix(1, 1) = ortho2(1);
- matrix(2, 1) = ortho2(2);
- matrix(3, 1) = 0.0;
-
- matrix(0, 2) = axis(0);
- matrix(1, 2) = axis(1);
- matrix(2, 2) = axis(2);
- matrix(3, 2) = 0.0;
-
- matrix(0, 3) = end1(0);
- matrix(1, 3) = end1(1);
- matrix(2, 3) = end1(2);
- matrix(3, 3) = 1.0;
-
- //now we can do the actual drawing !
- glPushMatrix();
- glMultMatrixd( matrix.array() );
- if( order == 1 )
-# ifdef USE_DISPLAY_LISTS
- glCallList( m_displayList );
-# else
- do_draw();
-# endif
- else
- {
- double angleOffset = 0.0;
- if( order >= 3 )
- {
- if( order == 3 ) angleOffset = 90.0;
- else angleOffset = 22.5;
- }
-
- double displacementFactor = shift / radius;
- for( int i = 0; i < order; i++)
- {
- glPushMatrix();
- glRotated( angleOffset + 360.0 * i / order,
- 0.0, 0.0, 1.0 );
- glTranslated( displacementFactor, 0.0, 0.0 );
-# ifdef USE_DISPLAY_LISTS
- glCallList( m_displayList );
-# else
- do_draw();
-# endif
- glPopMatrix();
- }
- }
- glPopMatrix();
-}
-
-CharRenderer::CharRenderer()
-{
- m_texture = 0;
- m_displayList = 0;
-}
-
-CharRenderer::~CharRenderer()
-{
- if( m_texture ) glDeleteTextures( 1, &m_texture );
- if( m_displayList ) glDeleteLists( m_displayList, 1 );
-}
-
-bool CharRenderer::initialize( QChar c, const QFont &font, GLenum textureTarget )
-{
- if( m_displayList ) return true;
-
- QFontMetrics fontMetrics ( font );
- m_width = fontMetrics.width( c );
- m_height = fontMetrics.height();
- if( m_width <= 0 || m_height <= 0 ) return false;
- QImage image( m_width, m_height, QImage::Format_RGB32 );
-
- QPainter painter;
- painter.begin( &image );
- painter.setFont( font );
- painter.setRenderHint( QPainter::TextAntialiasing );
- painter.setBackground( Qt::black );
- painter.eraseRect( image.rect() );
- painter.setPen( Qt::blue );
- painter.drawText ( 0, 0, m_width, m_height, Qt::AlignBottom, c );
- painter.end();
-
- GLubyte *bitmap = new GLubyte[ m_width * m_height ];
- if( ! bitmap ) return false;
-
- for( int j = m_height - 1, n = 0; j >= 0; j-- )
- for( int i = 0; i < m_width; i++, n++ )
- {
- bitmap[n] = qBlue( image.pixel( i, j ) );
- }
-
- glGenTextures( 1, &m_texture );
- if( ! m_texture ) return false;
-
- glBindTexture( textureTarget, m_texture );
- glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
- glTexImage2D(
- textureTarget,
- 0,
- GL_ALPHA,
- m_width,
- m_height,
- 0,
- GL_ALPHA,
- GL_UNSIGNED_BYTE,
- bitmap );
- glTexParameteri( textureTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
- glTexParameteri( textureTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
-
- delete [] bitmap;
-
- m_displayList = glGenLists(1);
- if( ! m_displayList ) return false;
-
- glNewList( m_displayList, GL_COMPILE );
- glBindTexture( textureTarget, m_texture );
- glBegin( GL_QUADS );
- glTexCoord2f( 0, 0);
- glVertex2f( 0 , 0 );
- glTexCoord2f( 1, 0);
- glVertex2f( m_width , 0 );
- glTexCoord2f( 1, 1);
- glVertex2f( m_width, m_height );
- glTexCoord2f( 0, 1);
- glVertex2f( 0 , m_height );
- glEnd();
- glTranslatef( m_width, 0, 0 );
- glEndList();
- return true;
-}
-
-TextRenderer::TextRenderer()
-{
- m_glwidget = 0;
- m_isBetweenBeginAndEnd = false;
- m_textureTarget = GL_TEXTURE_2D;
-}
-
-TextRenderer::~TextRenderer()
-{
- QHash<QChar, CharRenderer *>::iterator i = m_charTable.begin();
- while( i != m_charTable.end() )
- {
- delete i.value();
- i = m_charTable.erase(i);
- }
-}
-
-void TextRenderer::setup( const QGLWidget *glwidget, const QFont &font )
-{
- if( m_glwidget ) return;
- m_glwidget = glwidget;
- m_font = font;
-}
-
-void TextRenderer::do_begin()
-{
- m_wasEnabled_LIGHTING = glIsEnabled( GL_LIGHTING );
- m_wasEnabled_FOG = glIsEnabled( GL_FOG );
- m_wasEnabled_textureTarget
- = glIsEnabled( m_textureTarget );
- m_wasEnabled_BLEND = glIsEnabled( GL_BLEND );
- m_wasEnabled_DEPTH_TEST = glIsEnabled( GL_DEPTH_TEST );
- glDisable( GL_LIGHTING );
- glDisable( GL_FOG );
- glEnable( m_textureTarget );
- glEnable( GL_BLEND );
- glDisable( GL_DEPTH_TEST );
- glMatrixMode( GL_PROJECTION );
- glPushMatrix();
- glLoadIdentity();
- glOrtho( 0, m_glwidget->width(), 0, m_glwidget->height(), -1, 1 );
- glMatrixMode( GL_MODELVIEW );
-}
-
-void TextRenderer::begin()
-{
- if( ! m_glwidget ) return;
- if( m_isBetweenBeginAndEnd ) return;
- m_isBetweenBeginAndEnd = true;
- do_begin();
-}
-
-void TextRenderer::do_end()
-{
- if( ! m_wasEnabled_textureTarget )
- glDisable( m_textureTarget );
- if( ! m_wasEnabled_BLEND ) glDisable( GL_BLEND );
- if( m_wasEnabled_DEPTH_TEST ) glEnable( GL_DEPTH_TEST );
- if( m_wasEnabled_LIGHTING ) glEnable( GL_LIGHTING );
- if( m_wasEnabled_FOG ) glEnable( GL_FOG );
- glMatrixMode( GL_PROJECTION );
- glPopMatrix();
- glMatrixMode( GL_MODELVIEW );
-}
-
-void TextRenderer::end()
-{
- if( m_isBetweenBeginAndEnd ) do_end();
- m_isBetweenBeginAndEnd = false;
-}
-
-void TextRenderer::print( int x, int y, const QString &string )
-{
- if( ! m_glwidget ) return;
- if( string.isEmpty() ) return;
-
- if( ! m_isBetweenBeginAndEnd ) do_begin();
-
- glPushMatrix();
- glLoadIdentity();
- glTranslatef( x, y, 0 );
- for( int i = 0; i < string.size(); i++ )
- {
- if( m_charTable.contains( string[i] ) )
- m_charTable.value( string[i] )->draw();
- else
- {
- CharRenderer *c = new CharRenderer;
- if( c->initialize( string[i], m_font, m_textureTarget ) )
- {
- m_charTable.insert( string[i], c);
- c->draw();
- }
- else delete c;
- }
- }
- glPopMatrix();
-
- if( ! m_isBetweenBeginAndEnd ) do_end();
-}
-
-} // namespace KalziumGLHelpers
+++ /dev/null
-/***************************************************************************
- copyright : (C) 2006 by Benoit Jacob <jacob@math.jussieu.fr>
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-#ifndef KALZIUMGLHELPERCLASSES_H
-#define KALZIUMGLHELPERCLASSES_H
-
-#include <QGLWidget>
-#include <GL/glu.h>
-#include <QPainter>
-#include <QImage>
-#include <QChar>
-#include <QHash>
-#include <kdebug.h>
-
-#include <openbabel/mol.h>
-#include <openbabel/obiter.h>
-
-#include <eigen/projective.h>
-
-/** USE_FPS_COUNTER: if defined, the GL Widget will show a frames-per-second
- * counter. Use only for testing: this makes the GL Widget constantly
- * redraw, which under normal circumstances is a waste of CPU time.
- */
-//#define USE_FPS_COUNTER
-
-/** USE_DISPLAY_LISTS: if defined, the whole scene will be stored in
- * an OpenGL display list. The vertex arrays will then be converted into
- * (nested) display lists, in order to avoid replication of geometric data.
- * This option improves performance, especially when rendering complex models,
- * but increases memory usage.
- */
-#define USE_DISPLAY_LISTS
-
-#define ROTATION_SPEED 0.01
-#define TRANSLATION_SPEED 0.01
-
-namespace KalziumGLHelpers
-{
-
-/**
- * This struct represents a style in which to render a molecule
- *
- * @author Benoit Jacob
- */
-struct MolStyle
-{
-
- /** The style in which the bonds are rendered (or not) */
- enum BondStyle
- {
- BONDS_DISABLED, /**< don't render the bonds */
- BONDS_GRAY, /**< render them as gray cylinders */
- BONDS_USE_ATOMS_COLORS /**< render them as cylinders split
- in half in the middle, each half being rendered
- with the color of the atom it touches */
- } m_bondStyle;
-
- /** The style in which the atoms are rendered (or not) */
- enum AtomStyle
- {
- ATOMS_DISABLED,/**< don't render the atoms */
- ATOMS_USE_FIXED_RADIUS, /**< render all atoms with the same,
- fixed radius (given by the m_atomRadiusFactor member,
- which is then interpreted as the radius itself) */
- ATOMS_USE_VAN_DER_WAALS_RADIUS /**< render each atom with
- its own van der Waals radius, multiplied by
- m_atomRadiusFactor */
- } m_atomStyle;
-
- /** The radius ( = half-thickness ) of single bonds */
- double m_singleBondRadius;
- /** If true, multiple bonds will be rendered as such. If false,
- * they will be rendered as single bonds */
- bool m_renderMultipleBonds;
- /** The radius ( = half-thickness ) of each bond inside a
- * multiple bond */
- double m_multipleBondRadius;
- /** Inside a multiple bond, this measures the displacement of each bond
- * from the axis of the multiple bond */
- double m_multipleBondShift;
- /** When using ATOMS_USE_VAN_DER_WAALS_RADIUS, this is the factor by
- * which the van der Waals radii are multiplied, so a value of 1.0 here
- * gives physically realistic rendering. When using
- * ATOMS_USE_FIXED_RADIUS, this s interpreted as the radius itself. */
- double m_atomRadiusFactor;
-
- MolStyle() {}
-
- MolStyle( BondStyle bondStyle, AtomStyle atomStyle,
- double singleBondRadius,
- bool renderMultipleBonds,
- double multipleBondRadius,
- double multipleBondShift,
- double atomRadiusFactor );
-
- /** This function returns the radius in which an atom with given atomic
- * number should be rendered, when using this style */
- double getAtomRadius( int atomicNumber );
-
- /** This function returns the radius in which the passed OBAtom
- * should be rendered, when using this style */
- inline double getAtomRadius( const OpenBabel::OBAtom *atom )
- { return getAtomRadius( atom->GetAtomicNum() ); }
-};
-
-/**
-* This class represents a color in OpenGL float red-green-blue-alpha format.
-*
-* @author Benoit Jacob
-*/
-struct Color
-{
- ///{ The four components of the color, ranging between 0 and 1.
- GLfloat m_red, m_green, m_blue, m_alpha;
- ///}
-
- Color() {}
-
- /**
- * This constructor sets the four components of the color
- * individually. Each one ranges from 0.0 (lowest intensity) to
- * 1.0 (highest intensity). For the alpha component, 0.0 means fully
- * transparent and 1.0 (the default) means fully opaque. */
- Color( GLfloat red, GLfloat green, GLfloat blue,
- GLfloat alpha = 1.0 );
-
- /**
- * This constructor uses OpenBabel to retrieve the color in which
- * the atom should be rendered. */
- Color( const OpenBabel::OBAtom *atom );
-
- /**
- * Sets this color to be the one used by OpenGL for rendering
- * when lighting is disabled. */
- inline void apply()
- {
- glColor4fv( &m_red );
- }
-
- /**
- * Applies nice OpenGL materials using this color as the
- * diffuse color while using different shades for the ambient and
- * specular colors. This is only useful if lighting is enabled. */
- void applyAsMaterials();
-};
-
-/**
-* This class represents and draws a sphere. The sphere is computed as a
-* "geosphere", that is, one starts with an icosahedron, which is the regular
-* solid with 20 triangular faces, and one then sub-tesselates each face into
-* smaller triangles. This is a classical algorithm, known to give very good
-* results.
-*
-* @author Benoit Jacob
-*/
-class Sphere
-{
-protected:
- /** Pointer to the buffer storing the vertex array */
- Eigen::Vector3f *m_vertexBuffer;
- /** Pointer to the buffer storing the indices */
- unsigned short *m_indexBuffer;
- /** The number of vertices, i.e. the size of m_vertexBuffer */
- int m_vertexCount;
- /** The number of indices, i.e. the size of m_indexBuffer */
- int m_indexCount;
- /** The id of the OpenGL display list (used only if this option
- * is turned on) */
- GLuint m_displayList;
-
- /** computes the index (position inside the index buffer)
- * of a vertex given by its position (strip, column, row)
- * inside a certain flat model of the sub-tesselated
- * icosahedron */
- inline unsigned short indexOfVertex(
- int strip, int column, int row);
- /** computes the coordinates
- * of a vertex given by its position (strip, column, row)
- * inside a certain flat model of the sub-tesselated
- * icosahedron */
- void computeVertex( int strip, int column, int row );
- /** the detail-level of the sphere. Must be at least 1.
- * This is interpreted as the number of sub-edges into which
- * each edge of the icosahedron must be split. So the
- * number of faces of the sphere is simply:
- * 20 * detail^2. When detail==1, the sphere is just the
- * icosahedron */
- int m_detail;
-
- void freeBuffers();
- void initialize();
- void do_draw() const;
-
-public:
- Sphere();
- ~Sphere();
-
- /** initializes the sphere with given level of detail. If the
- * sphere was already initialized, any pre-allocated buffers
- * are freed and then re-allocated.
- @param detail the wanted level of detail. See m_detail member */
- void setup( int detail );
-
- /** draws the sphere at specified position and with
- * specified radius */
- void draw( const Eigen::Vector3d ¢er, double radius ) const;
-};
-
-/**
-* This class represents and draws a cylinder
-*
-* @author Benoit Jacob
-*/
-class Cylinder
-{
-protected:
- /** Pointer to the buffer storing the vertex array */
- Eigen::Vector3f *m_vertexBuffer;
- /** Pointer to the buffer storing the normal array */
- Eigen::Vector3f *m_normalBuffer;
- /** The number of vertices, i.e. the size of m_vertexBuffer
- * or equivalently m_normalBuffer */
- int m_vertexCount;
- /** The id of the OpenGL display list (used only if this option
- * is turned on) */
- GLuint m_displayList;
- /** Equals true if the vertex array has been correctly initialized */
- bool m_isValid;
-
- /** the number of faces of the cylinder. This only
- * includes the lateral faces, as the base and top faces (the
- * two discs) are not rendered. */
- int m_faces;
-
- void initialize();
- void freeBuffers();
- void do_draw() const;
-
-public:
- Cylinder();
- ~Cylinder();
- /** initializes the cylinder with given number of faces. If the
- * cylinder was already initialized, any pre-allocated buffers
- * are freed and then re-allocated */
- void setup( int faces );
- /**
- * draws the cylinder at specified position, with specified
- * radius. the order and shift arguments allow to render
- * multiple cylinders at once. If you only want to render one
- * cylinder, leave order and shift at their default values.
- @param end1 the position of the first end of the cylinder.
- that is, the center of the first disc-shaped face.
- @param end2 the position of the second end of the cylinder.
- that is, the center of the second disc-shaped face.
- @param radius the radius of the cylinder
- @param order to render only one cylinder, leave this set to
- the default value, which is 1. If order>1, then order
- parallel cylinders are drawn around the axis
- (end1 - end2).
- @param order this is only meaningful of order>1, otherwise
- just let this set to the default value. When order>1,
- this is interpreted as the displacement of the axis
- of the drawn cylinders from the axis (end1 - end2).
- */
- void draw( const Eigen::Vector3d &end1, const Eigen::Vector3d &end2,
- double radius, int order = 1, double shift = 0.0 ) const;
-};
-
-/** BEEP BEEP BEEP this will likely be removed as Qt 4.2 has something better
-*
-* This is a helper class for TextRenderer, and should probably never be
-* used directly. See TextRenderer.
-*
-* The CharRenderer class represents a character stored as OpenGL rendering
-* data : a texture object and a display list mapping it on a quad and then
-* translating to the right of it.
-*
-* See the m_charTable member of TextRenderer for an example of use of
-* this class.
-*/
-class CharRenderer
-{
- protected:
- /**
- * The OpenGL texture object
- */
- GLuint m_texture;
-
- /**
- * The OpenGL display list
- */
- GLuint m_displayList;
-
- /**
- * Width and height in pixels of the rendered character
- */
- int m_width, m_height;
-
- public:
- CharRenderer();
- ~CharRenderer();
- bool initialize( QChar c, const QFont &font,
- GLenum textureTarget );
- inline void draw()
- {
- glCallList( m_displayList );
- }
-};
-
-
-/** BEEP BEEP BEEP this will likely be removed as Qt 4.2 has something better
-*
-* This class renders text inside a QGLWidget. It replaces the functionality
-* of QGLWidget::renderText(). The advantages over renderText() include:
-* - supports any font, any character encoding supported by Qt
-* (renderText is 8-bit-only and can only use "OpenGL-compatible" fonts)
-* - does not use any library outside Qt (renderText uses FreeType on X11)
-* - renders characters as textured quads instead of calling glDrawPixels,
-* which does not make much of a difference on MesaGL, but can be a lot
-* faster and safer with other (buggy) OpenGL implementations. It will also
-* allow to add more graphical effects in the future, like rotation,
-* if we ever need that.
-* - the characters are stored as 8bpp Alpha, which takes 4 times less
-* memory than the 32bpp RGBA used by renderText.
-* - the characters are rendered on-the-fly on the first time they appear
-* in a QString being printed. This is achieved using a QHash to test whether
-* a character has already been rendered.
-*
-* Recommended usage:
-* The TextRender class is meant to be used from inside a child class of
-* QGLWidget, say MyGLWidget.
-*
-* In the declaration of MyGLWidget, please declare a TextRenderer member:
-*
-* @code
-class MyGLWidget : public QGLWidget
-{
- ...
- TextRenderer m_textRenderer;
- ...
-};
-* @endcode
-*
-* Now, in the constructor of MyGLWidget, please call setup() along these lines:
-*
-* @code
- QFont f;
- f.setStyleHint( QFont::SansSerif, QFont::PreferAntialias );
- m_textRenderer.setup( this, f );
-* @endcode
-*
-* The setup() method should be called only once, which means you have to choose
-* a font once and for all, in the lifetime of your TextRenderer. Any QFont can
-* be used, the above is just an example. Now, to actually render text, in
-* the MyGLWidget::paintGL() method, you can call
-
-* @code
- m_textRenderer.print( x, y, string );
-* @endcode
-
-* where x,y are ints and string is any QString. If you want to choose a color,
-* please call glColor3f or glColor4f before calling print(). Of course you can
-* also call qglColor or Color::apply. You can achieve semitransparent text at
-* no additional cost by choosing a semitransparent color.
-*
-* If you wish to do several calls to print(), it will improve performance
-* to enclose them between a call to begin() and a call to end(), like that:
-*
-* @code
- m_textRenderer.begin();
- m_textRenderer.print( x1, y1, string1 );
- m_textRenderer.print( x2, y2, string2 );
- m_textRenderer.print( x3, y2, string3 );
- m_textRenderer.end();
-* @endcode
-*
-* Please make sure, though, that no relevant OpenGL state change occurs between
-* begin() and end(), except the state changes performed by the TextRenderer
-* itself. In other words, please avoid calling glSomething() between begin() and
-* end(), except if you are sure that this call won't perform a relevant state
-* change.
-*
-* The print() method when called alone, or the begin()-print()-end() group,
-* do restore the OpenGL state as they found it, including the matrices.
-*
-* If you experience rendering problems, you can try the following:
-* - disable some OpenGL state bits. For instance, TextRenderer automatically
-* disables fog and lighting during rendering, because it doesn't work
-* correctly with them enabled. There probably are other OpenGL state bits
-* that have to be disabled, so if your program enables some of them, you
-* might have to disable them before rendering text.
-* - if you experience poor font quality, please consider using an antialiased
-* font.
-*
-* @author Benoit Jacob
-*/
-class TextRenderer
-{
- protected:
- /**
- * The font used for rendering the chars. This is set
- * once and for all by setup(). Note that it is stored
- * by value, so the caller doesn't have to keep it alive.
- */
- QFont m_font;
-
- /**
- * This hash gives the correspondence table between QChars
- * (the keys) and the corresponding CharRenderers (the values).
- * Every time a QChar is being met, either it is found in this
- * table, in which case it can be directly rendered, or it is
- * not found, in which case a new CharRenderer is created for
- * it and added to this table.
- */
- QHash<QChar, CharRenderer*> m_charTable;
-
- /**
- * The QGLWidget in which to render. This is set
- * once and for all by setup().
- */
- const QGLWidget *m_glwidget;
-
- /**
- * This equals true if begin() has been called, but end() hasn't
- * since.
- */
- GLboolean m_isBetweenBeginAndEnd;
-
- ///{ Members used to remember the OpenGL state in order to be able to restore it after rendering. See do_end().
- GLboolean m_wasEnabled_LIGHTING;
- GLboolean m_wasEnabled_textureTarget;
- GLboolean m_wasEnabled_FOG;
- GLboolean m_wasEnabled_BLEND;
- GLboolean m_wasEnabled_DEPTH_TEST;
- ///}
-
- GLenum m_textureTarget;
-
- /**
- * Stores the relevant part of the OpenGL state, and prepares
- * for rendering
- */
- void do_begin();
-
- /**
- * Restores the OpenGL state
- */
- void do_end();
-
- public:
- TextRenderer();
- ~TextRenderer();
-
- /**
- * This should be called only once, before any printing occurs.
- * @param glwidget The QGLWidget in which to render.
- * See m_glwidget member.
- * @param font The QFont to use. See m_font member.
- */
- void setup( const QGLWidget *glwidget, const QFont &font );
-
- /**
- * Prints text at the position (x,y) in window coordinates
- * (0,0) is the bottom left corner
- * @param x the x-coordinate
- * @param y the y-coordinate
- * @param string the QString to print
- */
- void print( int x, int y, const QString &string);
-
- /**
- * Call this before doing multiple calls to print(). This is
- * not necessary, but will improve performance. Don't forget,
- * then, to call end() after.
- */
- void begin();
-
- /**
- * Call this after having called begin() and print().
- */
- void end();
-};
-
-} // namespace KalziumGL
-
-#endif // KALZIUMGLHELPERCLASSES_H
-
+++ /dev/null
-/***************************************************************************
- copyright : (C) 2006 by Carsten Niehaus
- email : cniehaus@kde.org
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-#include <kparts/genericfactory.h>
-
-#include <QStringList>
-
-#include "kalziumglpart.h"
-#include "openbabel2wrapper.h"
-#include "kalziumglwidget.h"
-
-typedef KParts::GenericFactory<KalziumGLPart> KalziumGLPartFactory;
-
-K_EXPORT_COMPONENT_FACTORY (libkalziumglpart, KalziumGLPartFactory)
-
-KalziumGLPart::KalziumGLPart(QWidget* parentWidget, QObject* parent, const QStringList& args)
-{
- kDebug() << "KalziumGLPart::KalziumGLPart()" << endl;
-
- m_widget = new KalziumGLWidget();
- m_widget->setObjectName("KalziumGLWidget-KPart");
-}
-
-KalziumGLPart::~KalziumGLPart()
-{
- kDebug() << "KalziumGLPart::~KalziumGLPart()" << endl;
-}
-
-KAboutData *KalziumGLPart::createAboutData()
-{
- KAboutData* aboutData = new KAboutData( "kalzium", I18N_NOOP("KalziumGLPart"),
- "1.1.1", I18N_NOOP("A cool thing"),
- KAboutData::License_GPL,
- "(c) 2006, Carsten Niehaus", 0, "http://edu.kde.org/kalzium/index.php",
- "kalzium@kde.org");
- aboutData->addAuthor("Carsten Niehaus.",0, "cniehaus@kde.org");
-
- return aboutData;
-}
-
-bool KalziumGLPart::openFile()
-{
- OpenBabel::OBMol* mol = OpenBabel2Wrapper::readMolecule( url().path() );
- mol->Center();
-
- m_widget->slotSetMolecule( mol );
- m_widget->update();
-}
-
-#include "kalziumglpart.moc"
+++ /dev/null
-/***************************************************************************
- copyright : (C) 2006 by Carsten Niehaus
- email : cniehaus@kde.org
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-#ifndef KALZIUMGLPART_H
-#define KALZIUMGLPART_H
-
-#include <kparts/factory.h>
-#include <kparts/genericfactory.h>
-
-#include "kalziumglwidget.h"
-
-class KalziumGLPart : public KParts::ReadOnlyPart
-{
- Q_OBJECT
- public:
- KalziumGLPart(QWidget*, QObject*, const QStringList&);
- virtual ~KalziumGLPart();
-
- static KAboutData* createAboutData();
-
- protected:
- bool openFile();
-
- KalziumGLWidget * m_widget;
-};
-
-#endif // KALZIUMGLPART_H
+++ /dev/null
-/***************************************************************************
- copyright : (C) 2006 by Benoit Jacob
- email : <jacob@math.jussieu.fr>
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-#include "kalziumglwidget.h"
-
-#include <kdebug.h>
-#include <klocale.h>
-
-#include <QMouseEvent>
-#include <QListWidget>
-
-#ifdef USE_FPS_COUNTER
-#include <QTime>
-#endif
-
-#include <openbabel/mol.h>
-#include <eigen/regression.h>
-
-using namespace KalziumGLHelpers;
-using namespace OpenBabel;
-using namespace Eigen;
-
-KalziumGLWidget::KalziumGLWidget( QWidget * parent )
- : QGLWidget( parent )
-{
- m_movedSinceButtonPressed = false;
- m_clickedAtom = 0;
- m_molecule = 0;
- m_detail = 0;
- m_displayList = 0;
- m_haveToRecompileDisplayList = true;
- m_useFog = false;
- m_inZoom = false;
- m_inMeasure = false;
-
- QFont f;
- f.setStyleHint( QFont::SansSerif, QFont::PreferAntialias );
- m_textRenderer.setup( this, f );
-
- setMinimumSize( 100,100 );
- setContextMenuPolicy( Qt::PreventContextMenu );
- setMolStyle( 0 );
-}
-
-KalziumGLWidget::~KalziumGLWidget()
-{
-}
-
-void KalziumGLWidget::initializeGL()
-{
- glClearColor( 0.0, 0.0, 0.0, 1.0 );
- glShadeModel( GL_SMOOTH );
- glEnable( GL_DEPTH_TEST );
- glDepthFunc( GL_LEQUAL );
- glEnable( GL_CULL_FACE );
-
- m_cameraMatrix.loadIdentity();
-
- glEnable( GL_NORMALIZE );
- glEnable( GL_LIGHTING );
- glEnable( GL_LIGHT0 );
-
- GLfloat ambientLight[] = { 0.4, 0.4, 0.4, 1.0 };
- GLfloat diffuseLight[] = { 0.8, 0.8, 0.8, 1.0 };
- GLfloat specularLight[] = { 1.0, 1.0, 1.0, 1.0 };
- GLfloat position[] = { 0.8, 0.7, 1.0, 0.0 };
-
- glLightfv( GL_LIGHT0, GL_AMBIENT, ambientLight );
- glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseLight );
- glLightfv( GL_LIGHT0, GL_SPECULAR, specularLight );
- glLightfv( GL_LIGHT0, GL_POSITION, position );
-
- GLfloat fogColor[] = { 0.0, 0.0, 0.0, 1.0 };
- glFogfv( GL_FOG_COLOR, fogColor );
- glFogi( GL_FOG_MODE, GL_LINEAR );
- glFogf( GL_FOG_DENSITY, 0.45 );
-
- glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
-
- glEnable( GL_COLOR_SUM_EXT );
- glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL_EXT,
- GL_SEPARATE_SPECULAR_COLOR_EXT );
-
- glEnableClientState( GL_VERTEX_ARRAY );
- glEnableClientState( GL_NORMAL_ARRAY );
-
- setupObjects();
-}
-
-void KalziumGLWidget::paintGL()
-{
- if( ! m_molecule )
- {
- glClear( GL_COLOR_BUFFER_BIT );
- glColor3f( 0.0, 1.0, 0.6 );
- m_textRenderer.print( 20, height() - 40,
- i18n("Please load a molecule") );
- return;
- }
-
- renderScene();
-
-#ifdef USE_FPS_COUNTER
- FPSCounter();
- update();
-#endif
-}
-
-void KalziumGLWidget::renderScene( GLenum renderMode,
- const QPoint *mousePosition,
- GLsizei selectionBufferSize,
- GLuint *selectionBuffer,
- GLuint *numberOfHits )
-{
- // if renderMode is not GL_RENDER, check that it is GL_SELECT and that
- // the required arguments have been passed
- if( renderMode != GL_RENDER )
- {
- if( renderMode != GL_SELECT
- || ! mousePosition
- || ! selectionBufferSize
- || ! selectionBuffer
- || ! numberOfHits ) return;
- }
-
- if( renderMode == GL_SELECT )
- {
- glSelectBuffer( selectionBufferSize, selectionBuffer );
- glRenderMode( GL_SELECT );
- }
-
- // set up the projection matrix
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- if( renderMode == GL_SELECT )
- {
- // in GL_SELECT mode, we only want to render a tiny area around
- // the mouse pointer
- GLint viewport[4];
- glGetIntegerv( GL_VIEWPORT, viewport );
- gluPickMatrix( mousePosition->x(),
- viewport[3] - mousePosition->y(),
- 3, 3, viewport);
- }
- double center = m_cameraMatrix.translationVector().norm();
- double molRad = getMolRadius();
- double nearEnd, farEnd;
- if( center < 2.0 * molRad )
- {
- nearEnd = molRad / 12.0;
- farEnd = molRad * 4.0;
- }
- else
- {
- nearEnd = center - molRad * 1.5;
- farEnd = center + molRad * 1.5;
- }
- gluPerspective( 40.0, float( width() ) / height(), nearEnd, farEnd );
-
- glMatrixMode( GL_MODELVIEW );
-
- // clear the buffers when in GL_RENDER mode
- if( renderMode == GL_RENDER )
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
-
- // set up the camera
- glLoadMatrixd ( m_cameraMatrix.array() );
-
- // set up fog
- if( m_useFog && renderMode == GL_RENDER )
- {
- glEnable( GL_FOG );
- GLfloat fogColor[] = { 0.0, 0.0, 0.0, 1.0 };
- glFogfv( GL_FOG_COLOR, fogColor );
- glFogi( GL_FOG_MODE, GL_LINEAR );
- glFogf( GL_FOG_DENSITY, 0.45 );
- glFogf( GL_FOG_START, 0.5 * center + 0.5 * nearEnd );
- glFogf( GL_FOG_END, farEnd );
- }
- else glDisable( GL_FOG );
-
- // initialize the name stack when in GL_SELECT mode
- if( renderMode == GL_SELECT )
- {
- glInitNames();
- glPushName( 0 );
- }
-
-#ifdef USE_DISPLAY_LISTS
- if( m_haveToRecompileDisplayList )
- {
- if( ! m_displayList ) m_displayList = glGenLists( 1 );
- if( ! m_displayList ) return;
- glNewList( m_displayList, GL_COMPILE );
-#endif
-
- renderAtoms();
- renderBonds();
-
-#ifdef USE_DISPLAY_LISTS
- glEndList();
- m_haveToRecompileDisplayList = false;
- }
- glCallList( m_displayList );
-#endif
-
- renderHighlighting();
-
- if( renderMode == GL_SELECT )
- {
- glFlush();
- *numberOfHits = glRenderMode( GL_RENDER );
- }
-}
-
-void KalziumGLWidget::renderAtoms()
-{
- if( m_molStyle.m_atomStyle != MolStyle::ATOMS_DISABLED )
- {
- glDisable( GL_NORMALIZE );
- glEnable( GL_RESCALE_NORMAL );
-
- FOR_ATOMS_OF_MOL( atom, m_molecule )
- {
- drawAtom( &*atom );
- }
-
- glEnable( GL_NORMALIZE );
- glDisable( GL_RESCALE_NORMAL );
- }
-}
-
-void KalziumGLWidget::renderBonds()
-{
- if( m_molStyle.m_bondStyle != MolStyle::BONDS_DISABLED )
- {
- FOR_BONDS_OF_MOL( bond, m_molecule )
- {
- drawBond( &*bond );
- }
- }
-}
-
-void KalziumGLWidget::renderHighlighting()
-{
- glEnable( GL_BLEND );
-
- if( m_clickedAtom )
- {
- Color( 1.0, 1.0, 1.0, 0.4 ).applyAsMaterials();
- glLoadName( m_clickedAtom->GetIdx() );
- m_sphere.draw( m_clickedAtom->GetVector().AsArray(),
- 0.18 + m_molStyle.getAtomRadius( m_clickedAtom ) );
- }
-
- if( m_selectedAtoms.count() )
- {
- Color( 0.3, 0.6, 1.0, 0.7 ).applyAsMaterials();
- glEnable( GL_BLEND );
- foreach(OpenBabel::OBAtom* atom, m_selectedAtoms)
- {
- if( atom != m_clickedAtom )
- {
- glLoadName( atom->GetIdx() );
- m_sphere.draw( atom->GetVector().AsArray(),
- 0.18 + m_molStyle.getAtomRadius(
- atom ) );
- }
- }
- }
-
- glDisable( GL_BLEND );
-}
-
-void KalziumGLWidget::FPSCounter()
-{
-#ifdef USE_FPS_COUNTER
- QTime t;
-
- static bool firstTime = true;
- static int old_time, new_time;
- static int frames;
- static QString s;
-
- if( firstTime )
- {
- t.start();
- firstTime = false;
- old_time = t.elapsed();
- frames = 0;
- }
-
- new_time = t.elapsed();
-
- frames++;
-
- if( new_time - old_time > 200 )
- {
- s = QString::number( 1000 * frames /
- double( new_time - old_time ),
- 'f', 1 );
- s += QString(" FPS");
- frames = 0;
- old_time = new_time;
- }
-
- glColor3f( 1.0, 1.0, 0.0 );
- m_textRenderer.print( 20, 20, s );
-#endif
-}
-
-void KalziumGLWidget::resizeGL( int width, int height )
-{
- glViewport( 0, 0, width , height );
-}
-
-void KalziumGLWidget::mousePressEvent( QMouseEvent * event )
-{
- m_movedSinceButtonPressed = false;
- m_lastDraggingPosition = event->pos ();
- m_initialDraggingPosition = event->pos ();
- computeClickedAtom( event->pos () );
- updateGL();
-}
-
-void KalziumGLWidget::mouseReleaseEvent( QMouseEvent * event )
-{
- (void) event;
- if( m_clickedAtom && ! m_movedSinceButtonPressed )
- {
- if( m_selectedAtoms.contains( m_clickedAtom ) )
- {
- m_selectedAtoms.removeAll(
- m_clickedAtom );
- }
- else m_selectedAtoms.append( m_clickedAtom );
- }
- m_clickedAtom = 0;
- updateGL();
-}
-
-void KalziumGLWidget::mouseMoveEvent( QMouseEvent *event )
-{
- QPoint delta = event->pos() - m_lastDraggingPosition;
- m_lastDraggingPosition = event->pos();
- Vector3d clickedAtomCenter;
- Matrix3d cameraRotation;
-
- if( event->buttons() & ( Qt::LeftButton | Qt::RightButton ) )
- {
- if( m_clickedAtom )
- clickedAtomCenter = Vector3d(
- m_clickedAtom->GetVector().AsArray() );
- if( ( event->pos()
- - m_initialDraggingPosition ).manhattanLength() > 2 )
- m_movedSinceButtonPressed = true;
- m_cameraMatrix.getLinearComponent( & cameraRotation );
- }
-
- if( event->buttons() & Qt::LeftButton )
- {
- // we're dragging with the left mouse button pressed.
- // that means we want to rotate. If an atom is being clicked,
- // then we want to rotate the molecule around that atom.
- // Otherwise, we want rotate the molecule around
- // its own center, which is at the origin since we have
- // already centered it.
-
- // note that here we're multiplying by rotations on the right,
- // because we want to rotate the camera around the molecule,
- // not around the camera itself.
-
- if( m_clickedAtom )
- m_cameraMatrix.translate( clickedAtomCenter );
- m_cameraMatrix.rotate3( delta.x() * ROTATION_SPEED,
- cameraRotation.row(1) );
- m_cameraMatrix.rotate3( delta.y() * ROTATION_SPEED,
- cameraRotation.row(0) );
- if( m_clickedAtom )
- m_cameraMatrix.translate( - clickedAtomCenter );
- }
- if( event->buttons() & Qt::RightButton )
- {
- if( m_clickedAtom )
- {
- m_cameraMatrix.translate( clickedAtomCenter );
- m_cameraMatrix.rotate3( delta.x() * ROTATION_SPEED,
- cameraRotation.row(2) );
- m_cameraMatrix.translate( - clickedAtomCenter );
-
- Vector3d transformedClickedAtomCenter = m_cameraMatrix * clickedAtomCenter;
- Vector3d goal = transformedClickedAtomCenter + Vector3d(0,0,1) * 8.0 * m_molStyle.getAtomRadius( m_clickedAtom );
- double t = TRANSLATION_SPEED * delta.y();
- bool isTooClose = transformedClickedAtomCenter.norm() < 10.0 * m_molStyle.getAtomRadius( m_clickedAtom );
- if( isTooClose && t < 0 ) t = 0;
- if( t > 0.5 ) t = 0.5;
- if( t < -0.5 ) t = -0.5;
- m_cameraMatrix.pretranslate( goal * t );
- }
- else
- {
- m_cameraMatrix.rotate3( delta.x() * ROTATION_SPEED,
- cameraRotation.row(2) );
- }
- }
- if( event->buttons() & ( Qt::LeftButton | Qt::RightButton ) )
- update();
-}
-
-void KalziumGLWidget::wheelEvent( QWheelEvent *event )
-{
-
- m_cameraMatrix.pretranslate( event->delta()
- * TRANSLATION_SPEED * Vector3d(0,0,1) );
- update();
-}
-
-void KalziumGLWidget::rotate( )
-{
-// OK, let's momentarily disable that until I get it working (Benoit)
-
-/*
- kDebug() << "KalziumGLWidget::rotate()" << endl;
- //TODO at this place we need a nice way to rotate
- //based on certain values. For example, we could use two
- //bool variables for x and y rotation. If x is true the
- //molecule will rotate in the x-axis, if false not. Same
- //for y.
- //As I have no idea what this code is doing I just copy&pasted
- //everything from the mousewheel method...
- glPushMatrix();
- glLoadIdentity();
-
- //Benoit, I took those values pretty much at random,
- //no idea what value is for what... :)
- glRotated( 10.0, 0.0, 1.0, 0.0 );
- glRotated( 10.0, 1.0, 0.0, 0.0 );
- glMultMatrixd( m_rotationMatrix );
- glGetDoublev( GL_MODELVIEW_MATRIX, m_rotationMatrix );
- glPopMatrix();
- updateGL();
-*/
-}
-
-void KalziumGLWidget::setupObjects()
-{
- int sphere_detail = 1, cylinder_faces = 2;
-
- double typicalAtomRadius = m_molStyle.getAtomRadius( 6 );
- double typicalBondRadius = m_molStyle.m_singleBondRadius;
-
- if( m_molStyle.m_atomStyle != MolStyle::ATOMS_DISABLED )
- {
- if( typicalAtomRadius < 0.50 )
- sphere_detail = 2 + 2 * m_detail;
- else if( typicalAtomRadius < 1.00 )
- sphere_detail = 3 + 2 * m_detail;
- else sphere_detail = 4 + 3 * m_detail;
- }
-
- if( m_molStyle.m_bondStyle != MolStyle::BONDS_DISABLED )
- {
- if( typicalBondRadius < 0.10 )
- cylinder_faces = 6 + 6 * m_detail;
- else if( typicalBondRadius < 0.20 )
- cylinder_faces = 8 + 8 * m_detail;
- else cylinder_faces = 10 + 8 * m_detail;
- }
-
- m_sphere.setup( sphere_detail );
- m_cylinder.setup( cylinder_faces );
-}
-
-void KalziumGLWidget::drawAtom( OBAtom *atom )
-{
- glLoadName( atom->GetIdx() );
- Color( atom ).applyAsMaterials();
- m_sphere.draw( atom->GetVector().AsArray(),
- m_molStyle.getAtomRadius( atom ) );
-}
-
-void KalziumGLWidget::drawBond( OBBond *bond )
-{
- OBAtom *atom1 = static_cast<OBAtom *>( bond->GetBeginAtom() );
- OBAtom *atom2 = static_cast<OBAtom *>( bond->GetEndAtom() );
-
- Vector3d v1 ( atom1->GetVector().AsArray() );
- Vector3d v2 ( atom2->GetVector().AsArray() );
- Vector3d v3 = ( v1 + v2 ) / 2;
-
- int order;
- if( m_molStyle.m_renderMultipleBonds == false || bond->IsSingle() )
- order = 1;
- else if( bond->IsDouble() ) order = 2;
- else if( bond->IsTriple() ) order = 3;
- else order = bond->GetBondOrder();
-
- double radius;
- if( order == 1 ) radius = m_molStyle.m_singleBondRadius;
- else radius = m_molStyle.m_multipleBondRadius;
-
- switch( m_molStyle.m_bondStyle )
- {
- case MolStyle::BONDS_GRAY:
- glLoadName( 0 );
- Color( 0.55, 0.55, 0.55 ).applyAsMaterials();
- m_cylinder.draw( v1, v2, radius, order,
- m_molStyle.m_multipleBondShift );
- break;
-
- case MolStyle::BONDS_USE_ATOMS_COLORS:
- glLoadName( atom1->GetIdx() );
- Color( atom1 ).applyAsMaterials();
- m_cylinder.draw( v1, v3, radius, order,
- m_molStyle.m_multipleBondShift );
- glLoadName( atom2->GetIdx() );
- Color( atom2 ).applyAsMaterials();
- m_cylinder.draw( v3, v2, radius, order,
- m_molStyle.m_multipleBondShift );
- break;
-
- default: break;
- }
-}
-
-void KalziumGLWidget::slotZoomIn()
-{
- //TODO
- //This slot can be very easily accessed by simply calling it from
- //the GUI. I guess we need a second pair of zoomin/out slots for
- //a more finegrained zooming. For example, if we use the mousewheel
- //for zooming, we might want to use the delta()-value of the mouse-
- //wheel as a factor.
- //But as I have no idea how zooming works in OpenGL I cannot do the
- //coding...
-}
-
-void KalziumGLWidget::slotZoomOut()
-{
- //TODO
- //Comment so slotZoomIn()
-}
-
-void KalziumGLWidget::slotSetMolecule( OpenBabel::OBMol* molecule )
-{
- if ( !molecule ) return;
- m_molecule = molecule;
- m_haveToRecompileDisplayList = true;
- m_selectedAtoms.clear();
- m_clickedAtom = 0;
- prepareMoleculeData();
- setupObjects();
- updateGL();
-}
-
-void KalziumGLWidget::setMolStyle( int style )
-{
- switch( style )
- {
- case 0: // sticks-style
- m_molStyle = MolStyle( MolStyle::BONDS_USE_ATOMS_COLORS,
- MolStyle::ATOMS_USE_FIXED_RADIUS,
- 0.20, false, 0.06, 0.14, 0.20 );
- break;
- case 1: // atoms: smaller van der Waals, bonds: gray
- m_molStyle = MolStyle( MolStyle::BONDS_GRAY,
- MolStyle::ATOMS_USE_VAN_DER_WAALS_RADIUS,
- 0.08, true, 0.08, 0.14, 0.20 );
- break;
- case 2: // atoms: smaller van der Waals, bonds: use atom colors
- m_molStyle = MolStyle( MolStyle::BONDS_USE_ATOMS_COLORS,
- MolStyle::ATOMS_USE_VAN_DER_WAALS_RADIUS,
- 0.08, true, 0.08, 0.14, 0.20 );
- break;
- case 3: // atoms: real van der Waals, bonds: disabled
- m_molStyle = MolStyle( MolStyle::BONDS_DISABLED,
- MolStyle::ATOMS_USE_VAN_DER_WAALS_RADIUS,
- 0.00, false, 0.00, 0.00, 1.00 );
- break;
-
- default: break;
- }
-
- // now, changing the mol style can change the atoms radii, which can
- // cause the camera to suddenly get inside the molecule. In that case,
- // we want to move it to ensure that it is always outside (and at a
- // respectful distance) of the molecule.
-
- if( m_molecule )
- FOR_ATOMS_OF_MOL( atom, m_molecule )
- {
- Vector3d center( (*atom).GetVector().AsArray() );
- Vector3d transformedCenter = m_cameraMatrix * center;
- bool isTooClose = transformedCenter.norm() < 10.0 * m_molStyle.getAtomRadius( &*atom );
- if( isTooClose ) m_cameraMatrix.pretranslate( Vector3d( 0, 0, - 10.0 * m_molStyle.getAtomRadius( &*atom ) ) );
- }
-
-
- m_haveToRecompileDisplayList = true;
-}
-
-void KalziumGLWidget::slotSetMolStyle( int style )
-{
- setMolStyle( style );
- setupObjects();
- updateGL();
-}
-
-void KalziumGLWidget::prepareMoleculeData()
-{
- //Center the molecule
- m_molecule->Center();
-
- // compute the radius of the molecule without the electrons
- // that is, the maximal distance between the center of an atom
- // of the molecule and the center of the molecule
- m_molRadiusWithoutElectrons = 0.0;
- FOR_ATOMS_OF_MOL( a, m_molecule )
- {
- Vector3d v( a->GetVector().AsArray() );
- double rad = v.norm();
- if( rad > m_molRadiusWithoutElectrons )
- m_molRadiusWithoutElectrons = rad;
- }
-
- // compute the molecule's fitting plane
- unsigned int numAtoms = 0, i = 0;
- FOR_ATOMS_OF_MOL( a, m_molecule ) numAtoms++;
- Vector3d * atomCenters = new Vector3d[numAtoms];
- FOR_ATOMS_OF_MOL( a, m_molecule )
- {
- atomCenters[i] = Vector3d( a->GetVector().AsArray() );
- i++;
- }
- Vector4d planeCoeffs;
- computeFittingHyperplane( numAtoms, atomCenters, &planeCoeffs );
- delete[] atomCenters;
-
- // compute rotation matrix to orient the molecule in the (x,y)-plane
- Vector3d planeNormalVector( & planeCoeffs(0) ), v, w;
- planeNormalVector.normalize();
- planeNormalVector.makeOrthoVector( &v );
- w = cross( planeNormalVector, v );
- Matrix3d rotation;
- rotation.setRow( 0, v );
- rotation.setRow( 1, w );
- rotation.setRow( 2, planeNormalVector );
-
- // apply rotation to each atom in the molecule
- FOR_ATOMS_OF_MOL( a, m_molecule )
- {
- Vector3d atomCenter;
- atomCenter = Vector3d( a->GetVector().AsArray() );
- atomCenter = rotation * atomCenter;
- a->SetVector( atomCenter.x(),
- atomCenter.y(),
- atomCenter.z() );
- }
-
- // set up the camera matrix so that the initial point of view
- // is convenient. This is easy because we have already rotated
- // the molecule to orient it approximately in the xy-plane.
-
- m_cameraMatrix.loadTranslation(
- Vector3d( 0, 0, -3.0 * getMolRadius() ) );
-}
-
-double KalziumGLWidget::getMolRadius()
-{
- return m_molRadiusWithoutElectrons + m_molStyle.getAtomRadius( 6 );
-}
-
-void KalziumGLWidget::slotSetDetail( int detail )
-{
- m_detail = detail;
- if( m_detail >= 2 ) m_useFog = true;
- else m_useFog = false;
- setupObjects();
- updateGL();
-}
-
-void KalziumGLWidget::slotAtomsSelected( QList<OpenBabel::OBAtom*> atoms )
-{
- kDebug() << "KalziumGLWidget::slotAtomsSelected() with " << atoms.count() << " atoms" << endl;
- m_selectedAtoms = atoms;
- updateGL();
-}
-
-void KalziumGLWidget::computeClickedAtom(
- const QPoint & mousePosition )
-{
- m_clickedAtom = 0;
- if( ! m_molecule ) return;
-
- const GLsizei selectionBufferSize = 1024;
-
- GLuint i, names,
- minZ = 0xffffffff,
- *ptrNames = 0,
- numberOfNames = 0,
- numberOfHits,
- selectionBuffer[selectionBufferSize],
- *ptr = selectionBuffer;
-
- renderScene( GL_SELECT,
- &mousePosition,
- selectionBufferSize,
- selectionBuffer,
- &numberOfHits );
-
-
- for( i = 0; i < numberOfHits; i++ )
- {
- names = *ptr;
- ptr++;
- if( *ptr < minZ )
- {
- numberOfNames = names;
- minZ = *ptr;
- ptrNames = ptr+2;
- }
- ptr += names+2;
- }
-
- for( i = 0, ptr = ptrNames; i < numberOfNames; i++, ptr++ )
- if( *ptr )
- {
- m_clickedAtom = m_molecule->GetAtom( *ptr );
- return;
- }
-}
-
-#include "kalziumglwidget.moc"
+++ /dev/null
-/***************************************************************************
- copyright : (C) 2006 by Benoit Jacob <jacob@math.jussieu.fr>
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-#ifndef KALZIUMGLWIDGET_H
-#define KALZIUMGLWIDGET_H
-
-#include <libkdeedu_compoundviewer_export.h>
-
-#include "kalziumglhelperclasses.h"
-
-#include <QGLWidget>
-#include <QtGui/QWheelEvent>
-#include <QList>
-#include <QFont>
-
-using namespace KalziumGLHelpers;
-
-/**
- * This class displays the 3D-view of a molecule
- *
- * @author Benoit Jacob
- */
-class COMPOUNDVIEWER_EXPORT KalziumGLWidget : public QGLWidget
-{
- Q_OBJECT
-
- protected:
- GLuint m_displayList;
- bool m_haveToRecompileDisplayList;
-
- TextRenderer m_textRenderer;
-
- /**
- * The geometric model of the sphere (used for atoms).
- */
- Sphere m_sphere;
-
- /**
- * The geometric model of the cylinder (used for bonds).
- */
- Cylinder m_cylinder;
-
- bool m_movedSinceButtonPressed;
-
- QPoint m_lastDraggingPosition;
- QPoint m_initialDraggingPosition;
-
- OpenBabel::OBAtom *m_clickedAtom;
-
- /**
- * Stores the camera position and orientation.
- */
- Eigen::MatrixP3d m_cameraMatrix;
-
- /**
- * The molecule which is displayed
- */
- OpenBabel::OBMol *m_molecule;
-
- /**
- * approximate radius of the molecule,
- * without the electrons.
- */
- GLdouble m_molRadiusWithoutElectrons;
-
- /**
- * The detail-grade from 0 to 2.
- */
- int m_detail;
-
- /**
- * Set this to true to enable the fog effect
- */
- bool m_useFog;
-
- /**
- * The selected atoms
- */
- QList<OpenBabel::OBAtom*> m_selectedAtoms;
-
- /**
- * The style in which the molecule is rendered
- */
- MolStyle m_molStyle;
-
- public:
- /**
- * Constructor
- */
- KalziumGLWidget( QWidget *parent = 0 );
-
- /**
- * Destructor
- */
- ~KalziumGLWidget();
-
- /**
- * @return Returns a pointer to the molecule being worked on
- */
- OpenBabel::OBMol* molecule () const {
- return m_molecule;
- }
-
- signals:
- /**
- * the atoms in @p atoms have been selected by the user
- */
- void atomsSelected( QList<OpenBabel::OBAtom*> atoms );
-
- public slots:
- /**
- * The autorotation timer ended so we have to move the molecule a bit more
- * not needed I guess
- */
- void rotate();
-
- /**
- * sets the molecule which will be displayed
- * @param molecule the molecule to render
- */
- void slotSetMolecule( OpenBabel::OBMol* molecule );
-
- /**
- * zoom in by 10%
- */
- void slotZoomIn();
-
- /**
- * zoom out by 10%
- */
- void slotZoomOut();
-
-
- /**
- * Sets the detail-grade in a range from 0 to 2
- * @param detail the detail-grade of the rendering. 0 is low, 2 is high
- */
- void slotSetDetail( int detail );
-
- /**
- * Sets the molecule style
- * @param style the wanted molecule style
- */
- void slotSetMolStyle( int style );
-
- /**
- * The atoms @p atoms was selected by the user
- */
- void slotAtomsSelected( QList<OpenBabel::OBAtom*> atoms );
-
- /**
- * Activates the zoommode if @p zoom is true
- */
- void slotZoom( bool zoom ){
- m_inZoom = zoom;
- if ( m_inZoom )
- m_inMeasure = false;
- }
-
- /**
- * Activates the measuremode if @p measure is true
- */
- void slotMeasure( bool measure ){
- m_inMeasure = measure;
-
- if ( m_inMeasure )
- m_inZoom = false;
- }
-
- protected:
- ///if true the widget is in zoommode
- bool m_inZoom;
-
- ///if true the widget is in zoommode
- bool m_inMeasure;
-
- /**
- * This method initializes OpenGL. Automatically called by Qt
- */
- void initializeGL();
-
- /**
- * This method does the painting. Automatically called by Qt
- */
- void paintGL();
- void renderAtoms();
- void renderBonds();
- void renderHighlighting();
- void FPSCounter();
-
- /**
- * This method is called by Qt whenever the widget is resized.
- */
- void resizeGL( int width, int height );
-
- void mousePressEvent( QMouseEvent * event );
- void mouseReleaseEvent( QMouseEvent * event );
- void mouseMoveEvent( QMouseEvent * event );
- void wheelEvent( QWheelEvent * event );
-
- /**
- * This method is called by slotSetMolecule. It prepares the
- * molecule for rendering, and computes some useful data about
- * it.
- */
- void prepareMoleculeData();
-
- double getMolRadius();
-
- void drawAtom( OpenBabel::OBAtom *atom );
-
- void drawBond( OpenBabel::OBBond *bond );
-
- void renderScene( GLenum renderMode = GL_RENDER,
- const QPoint * mousePosition = 0,
- GLsizei selectionBufferSize = 0,
- GLuint * selectionBuffer = 0,
- GLuint * numberOfHits = 0 );
-
- /**
- * recomputes the geometry of the geometric objects ( sphere,
- * cylinder ).
- */
- void setupObjects();
-
- /**
- * Sets the molecule style, but contrary to slotSetMolStyle,
- * doesn't call setupObjects and updateGL. Useful for
- * setting the initial style when the GL widget is created.
- * Called by slotSetMolStyle.
- * @param style the wanted molecule style
- */
- void setMolStyle( int style );
-
- void computeClickedAtom( const QPoint & mousePosition );
-};
-#endif // KALZIUMGLWIDGET_H
-
+++ /dev/null
-/*
- This file is part of libkdeedu.
- Copyright (c) 2007 Pino Toscano <toscano.pino@tiscali.it>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#ifndef KDEEDU_COMPOUNDVIEWER_EXPORT_H
-#define KDEEDU_COMPOUNDVIEWER_EXPORT_H
-
-/* needed for KDE_EXPORT macros */
-#include <kdemacros.h>
-
-#if defined Q_OS_WIN
-
-#ifndef COMPOUNDVIEWER_EXPORT
-# ifdef MAKE_COMPOUNDVIEWER_LIB
-# define COMPOUNDVIEWER_EXPORT KDE_EXPORT
-# else
-# define COMPOUNDVIEWER_EXPORT KDE_IMPORT
-# endif
-#endif
-
-#else
-/* export statements for unix */
-#define COMPOUNDVIEWER_EXPORT KDE_EXPORT
-#endif
-
-#endif
+++ /dev/null
-/***************************************************************************
- copyright : (C) 2006 by Carsten Niehaus
- email : cniehaus@kde.org
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-#include "openbabel2wrapper.h"
-
-#include <kdebug.h>
-#include <klocale.h>
-#include <QMessageBox>
-#include <QRegExp>
-
-#include <sstream>
-#include <stdio.h>
-#include <iostream>
-#include <fstream>
-#include <string.h>
-#include <malloc.h>
-
-
-
-#include <QMouseEvent>
-#include <QLayout>
-#include <QListWidget>
-#include <QMessageBox>
-
-
-OpenBabel::OBMol* OpenBabel2Wrapper::readMolecule( const QString& filename )
-{
- OpenBabel::OBConversion Conv;
- OpenBabel::OBFormat *inFormat = NULL;
-
- //the OB2 Molecule
- OpenBabel::OBMol *mol = new OpenBabel::OBMol;
- std::ifstream inFileStream( filename.toLatin1() );
- if ( !inFileStream ) {
- QMessageBox::warning( 0, i18n( "Problem while opening the file" ),
- i18n( "Cannot open the specified file." ) );
- return 0;
- }
-
- //find out which format the file has...
- inFormat = Conv.FormatFromExt( filename.toLatin1() );
- Conv.SetInAndOutFormats( inFormat,inFormat );
- Conv.Read( mol, &inFileStream );
-
- kDebug() << QString::fromLatin1( mol->GetFormula().c_str() ) << " (Weight: " << mol->GetMolWt() << ", Title: "<< mol->GetTitle() << ")" << endl;
-
- return mol;
-}
-
-QString OpenBabel2Wrapper::getFormula( OpenBabel::OBMol* molecule )
-{
- QString formula( molecule->GetFormula().c_str() );
- return formula;
-}
-
-QString OpenBabel2Wrapper::getPrettyFormula( OpenBabel::OBMol* molecule )
-{
- QString formula( molecule->GetFormula().c_str() );
- formula.replace( QRegExp( "(\\d+)" ), "<sub>\\1</sub>" );
- return formula;
-}
+++ /dev/null
-#ifndef OPENBABEL2WRAPPER_H
-#define OPENBABEL2WRAPPER_H
-/***************************************************************************
- copyright : (C) 2006 by Carsten Niehaus
- email : cniehaus@kde.org
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-//includes for OpenBabel2
-#include <openbabel/obconversion.h>
-#include <openbabel/mol.h>
-
-#include <libkdeedu_compoundviewer_export.h>
-
-
-
-/**
- * @author Carsten Niehaus
- */
-class COMPOUNDVIEWER_EXPORT OpenBabel2Wrapper
-{
- public:
- /**
- * This class reads the molecule in the file @p filename. It returns 0 if
- * the file couldn't be read.
- */
- static OpenBabel::OBMol* readMolecule( const QString& filename );
-
- static QString getFormula( OpenBabel::OBMol* molecule );
-
- static QString getPrettyFormula( OpenBabel::OBMol* molecule );
-};
-
-#endif // OPENBABEL2WRAPPER_H
+++ /dev/null
-include_directories(
- ${CMAKE_SOURCE_DIR}/..
- ${CMAKE_CURRENT_BINARY_DIR}/..
- ${CMAKE_CURRENT_SOURCE_DIR}/..
-)
-
-include_directories( ${OPENBABEL2_INCLUDE_DIR} ..)
-
-set(kalziumui_PART_SRCS
- ${CMAKE_CURRENT_SOURCE_DIR}/../kalziumglwidget.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/../kalziumglhelperclasses.cpp
- )
-
-KDE4_ADD_WIDGET_FILES(kalziumui_PART_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/kalziumui.widgets)
-
-kde4_add_plugin(kalziumuiwidgets ${kalziumui_PART_SRCS})
-
-target_link_libraries(kalziumuiwidgets ${OPENBABEL2_LIBRARIES} ${QT_QTOPENGL_LIBRARY} ${QT_QTDESIGNER_LIBRARY} ${KDE4_KDEUI_LIBS} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})
-
-install(TARGETS kalziumuiwidgets DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/designer )
-
+++ /dev/null
-[Global]
-PluginName=KalziumWidgets
-Includes=kcomponentdata.h
-#Init=new KComponentData("kdeeduwidgets");
-
-[KalziumGLWidget]
-ToolTip=A OpenGL based molecule viewer
-WhatsThis=A OpenGL based molecule viewer
-Group=Plot (KDE-Edu)
-ConstructorArgs=(parent)
-
-[KalziumGLWidget]
-ToolTip=A OpenGL based molecule viewer
-WhatsThis=A OpenGL based molecule viewer
-Group=Plot (KDE-Edu)
-ConstructorArgs=(parent)
-