From 4afa48a6d1d403ffa564115570d69c114dfaa388 Mon Sep 17 00:00:00 2001 From: Carsten Niehaus Date: Thu, 6 May 2004 17:13:13 +0000 Subject: [PATCH] third commit. How many files did I add...? svn path=/trunk/kdeedu/kalzium/src/element.h; revision=309156 --- kalzium/src/element.cpp | 252 ++++++++++++++++++++++++++++++++++++++++ kalzium/src/element.h | 188 ++++++++++++++++++++++++++++++ 2 files changed, 440 insertions(+) create mode 100644 kalzium/src/element.cpp create mode 100644 kalzium/src/element.h diff --git a/kalzium/src/element.cpp b/kalzium/src/element.cpp new file mode 100644 index 0000000..f57ed6b --- /dev/null +++ b/kalzium/src/element.cpp @@ -0,0 +1,252 @@ +/*************************************************************************** + * Copyright (C) 2003 by Carsten Niehaus * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "element.h" +#include "prefs.h" +#include +#include +#include + +Element::Element( int num ) +{ + m_number = num; + + /* + * this object is static because this reduces the access to the file + * by 90% (strace counts 16 calls instead of 116 ) + */ + static KSimpleConfig config ( locate( "data", "kalzium/kalziumrc" ) ); + + if ( config.hasGroup( QString::number( num ) ) ) + + config.setGroup( QString::number( num ) ); + m_name=config.readEntry( "Name", "Unknown" ); + m_symbol=config.readEntry( "Symbol", "Unknown" ); + m_weight=config.readDoubleNumEntry( "Weight",0.0 ); + + m_oxstage=config.readEntry( "Ox","0" ); + m_acidbeh=config.readEntry( "acidbeh","0" ); + m_block=config.readEntry( "Block","s" ); + m_EN=config.readDoubleNumEntry( "EN", -1 ); + m_MP=config.readDoubleNumEntry( "MP", -1 ); + m_IE=config.readDoubleNumEntry( "IE", -1 ); + m_IE2=config.readDoubleNumEntry( "IE2", -1 ); + m_AR=config.readDoubleNumEntry( "AR", -1 ); + m_BP=config.readDoubleNumEntry( "BP", -1 ); + m_Density=config.readDoubleNumEntry( "Density", -1 ); + m_group=config.readEntry( "Group","1" ); + m_orbits=config.readEntry( "Orbits","0" ); + m_biological=config.readNumEntry( "biological" , -1 ); + m_az=config.readNumEntry( "az",-1 ); + m_date=config.readNumEntry( "date",-1 ); + + setupXY(); +} + +QString Element::parsedOrbits() +{ + QString orbits = m_orbits; + QRegExp rxs("([a-z])([0-9]+)"); + QRegExp rxb("([a-z]{2}) ",false); + orbits.replace(rxs,"\\1\\2"); //superscript around electron number + orbits.replace(rxb,"\\1 "); //bold around element symbols + return orbits; +} + + + +Element::~Element() +{ +} + +double Element::meanweight() +{ + return m_weight/m_number; +} + +const QString Element::adjustUnits( double val, const int type ) +{ + QString v = QString::null; + + if ( type == 1 ) // convert an energy + { + if ( val == -1 ) + v = i18n( "Value unknown" ); + else { + if ( Prefs::units() == 0 ) + { + val*=96.6; + v = QString::number( val ); + v.append( "kj/mol" ); + } + else // use electronvolt + { + v = QString::number( val ); + v.append( "eV" ); + } + } + } + else if ( type == 0 ) // convert a temperature + { + if ( Prefs::temperature() == 0 ) + { + val+=272.25; + v = QString::number( val ); + v.append( "°C" ); + } + else // use Kelvin + { + v = QString::number( val ); + v.append( "K" ); + } + } + else if ( type == 2 ) // its a lenght + { + v = QString::number( val ); + v.append( " pm" ); + } + else if ( type == 3 ) // its a weight + { + v = QString::number( val ); + v.append( " u" ); + } + else if ( type == 4 ) // its a density + { + v = QString::number( val ); + v.append( " g/m3" ); + } + else if ( type == 5 ) //its a date + { + if ( val < 1600 ) + { + v = i18n( "This element has been know to ancient cultures" ); + } + else + { + v = i18n( "This element was discovered in the year %1" ).arg( QString::number( val ) ); + } + } + else if ( type == 6 ) //its a electronegativity + { + if ( Prefs::electronegativity() == 0 ) //EN2 + { + v = QString::number( val ); + kdDebug() << "EN2" << endl; + } + if ( Prefs::electronegativity() == 1 ) //EN3 + { + v = QString::number( val ); + kdDebug() << "EN3" << endl; + } + if ( Prefs::electronegativity() == 2 ) //Pauling + { + v = QString::number( val ); + kdDebug() << "Pauling" << endl; + } + } + + return v; +} + +/*! + \fn Element::setupXY() + This looks pretty evil and it is. The problem is that a PSE is pretty + irregular and you cannot "calculate" the position. This means that + every type of PSE need such a complicated list of x/y-pairs... + */ +void Element::setupXY() +{ + static const int posXRegular[110] = {1,18, + 1,2,13,14,15,16,17,18, + 1,2,13,14,15,16,17,18, + 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18, + 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18, //Element 54 (Xe) + 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, //Element 71 (Lu) + 4,5,6,7,8,9,10,11,12,13,14,15,16,17,18, + 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, //Element 71 (Lr) + 4,5,6,7,8,9,10}; + static const int posYRegular[110] = {1,1, + 2,2, 2, 2, 2, 2, 2, 2, + 3,3, 3, 3, 3, 3, 3, 3, + 4,4,4,4,4,4,4,4,4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 5,5,5,5,5,5,5,5,5, 5, 5, 5, 5, 5, 5, 5, 5, 5, //Element 54 (Xe) + 6,6,6,8,8,8,8,8,8, 8, 8, 8, 8, 8, 8, 8, 8, //Element 71 (Lr) + 6,6,6,6,6,6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 7,7,7,9,9,9,9,9,9, 9, 9, 9, 9, 9, 9, 9, 9, + 7,7,7,7,7,7,7}; + + +static const int posXSimplified[110] = { + 1,8, + 1,2,3,4,5,6,7,8, + 1,2, + 3,4,5,6,7,8, + 1,2, + 0,0,0,0,0,0,0,0,0,0, //dummy + + 3,4,5,6,7,8,//36 + 1,2, + 0,0,0,0,0,0,0,0,0,0, //dummy + 3,4,5,6,7,8, + 1,2,//56 + 0,0,0,0,0,0,0,0,0,0, //dummy 66 + 0,0,0,0,0,0,0,0,0,0, //dummy 76 + 0,0,0,0, //dummy 80 + 3,4,5,6,7,8, + 1,2}; + + +static const int posYSimplified[110] = { + 1,1, + 2,2,2,2,2,2,2,2, + 3,3, + 3,3,3,3,3,3, + 4,4, + 0,0,0,0,0,0,0,0,0,0, //dummy + + 4,4,4,4,4,4,//36 + 5,5, + 0,0,0,0,0,0,0,0,0,0, //dummy + 5,5,5,5,5,5, + 6,6, + 0,0,0,0,0,0,0,0,0,0, //dummy + 0,0,0,0,0,0,0,0,0,0, //dummy + 0,0,0,0, //dummy 80 + 6,6,6,6,6,6, + 7,7}; + + x = posXRegular[m_number-1]; + y = posYRegular[m_number-1]; + + + s_y = posYSimplified[m_number-1]; + s_x = posXSimplified[m_number-1]; +} + +KalziumDataObject::KalziumDataObject() +{ + for( int i = 1 ; i < 111 ; ++i ) + { + ElementList.append( new Element( i ) ); + } +} + +KalziumDataObject::~KalziumDataObject() +{} + diff --git a/kalzium/src/element.h b/kalzium/src/element.h new file mode 100644 index 0000000..39571e9 --- /dev/null +++ b/kalzium/src/element.h @@ -0,0 +1,188 @@ +/*************************************************************************** + * Copyright (C) 2003 by Carsten Niehaus * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef ELEMENT_H +#define ELEMENT_H + +#include +#include +#include +#include + +class Element; + +typedef QValueList EList; + +class KalziumDataObject +{ + public: + KalziumDataObject(); + ~KalziumDataObject(); + + EList ElementList; + +}; + +/** + * In this class all information available are stored. This means that + * both the chemical date and the data about the position are stored + * in this class. + * @short This class is the represention of a chemical element + * @author Carsten Niehaus +*/ +class Element{ + public: + Element( int ); + ~Element(); + + /** + * @return the number of the element + */ + int number() const {return m_number;} + /** + * @return the date of discovery of the element + */ + int date() const { return m_date; } + /** + * @return the importance of the element for biological + * systems. + * @li 0: blah + * @li 1: blub + * @li 2: blub + * @li 3: blub + * @li 4: blub + * @li 5: blub + * @li 6: blub + */ + int biological() const {return m_biological;} + /** + * @return the condition of aggrgation of the element at + * room temperature. 0 means solid, 1 means liquid, 2 means vapor + */ + int az() const {return m_az;} + + /** + * @return the symbol of the element + */ + QString symbol() const {return m_symbol;} + /** + * @return the name of the element + */ + QString elname() const {return m_name;} + /** + * @return the chemical block (s, p, d, f) of the element + */ + QString block() const {return m_block;} + /** + * @return the group of the element + */ + QString group() const {return m_group;} + /** + * @return the acidic behaviour of the element + */ + QString acidicbeh() const {return m_acidbeh;} + /** + * @return the oxydationstages of the element + */ + QString oxstage() const { return m_oxstage; } + /** + * @return the orbits of the element. The QString is already + * parsed so that the numbers are superscripts and the first + * block is bold. + */ + QString parsedOrbits(); + +//XXX check if its really kelvin!!! + + /** + * @return the boiling point of the element in Kelvin + */ + double boiling() const {return m_BP;} + /** + * @return the melting point of the element in Kelvin + */ + double melting() const {return m_MP;} + /** + * @return the electronegativity of the element in the + * Pauling-scale + */ + double electroneg() const {return m_EN;} + /** + * @return the atomic weight of the element in units + */ + double weight() const {return m_weight;} + /** + * @return the density of the element in gramm per mol + */ + double density() const {return m_Density;} + /** + * @return the radius of the element in picometers + */ + double radius() const {return m_AR;} + /** + * @return the of the element + */ + + //XXX add the rest + double ie() const {return m_IE;} + /** + * @return the of the element + */ + double ie2() const {return m_IE2;} + /** + * @return the of the element + */ + double meanweight(); + + int x, y; //for the RegularPSE + int s_x, s_y; //for the SimplifiedPSE + + /** + * @return the of the element + */ + static const QString adjustUnits( double val, const int type ); + + private: + void setupXY(); + + double m_weight, + m_MP, + m_BP, + m_EN, + m_Density, + m_IE, + m_IE2, + m_AR; + + int m_number, + m_date, + m_az, + m_biological; + + QString m_symbol, + m_name, + m_oxstage, + m_block, + m_group, + m_acidbeh, + m_orbits; +}; + + +#endif -- 2.47.3