--- /dev/null
--- /dev/null
++SUBDIRS = .
++
++INCLUDES= $(all_includes)
++
++lib_LTLIBRARIES = libphysics.la
++
++libextdate_la_SOURCES = element.cpp \
++ spectrum.cpp \
++ isotope.cpp \
++ spectrumparser.cpp
++
++EXTRA_DIST = element.cpp element.h \
++ spectrum.cpp spectrum.h \
++ isotope.cpp isotope.h \
++ spectrumparser.cpp spectrumparser.h
++
++libextdate_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 4:0:0
++libextdate_la_LIBADD = $(LIB_KDEUI)
++
++METASOURCES = AUTO
--- /dev/null
--- /dev/null
++/***************************************************************************
++ * Copyright (C) 2003, 2004, 2005 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., *
++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
++ ***************************************************************************/
++
++#include "element.h"
++#include "prefs.h"
++#include "spectrum.h"
++#include "isotope.h"
++#include "tempunit.h"
++
++#include <kdebug.h>
++#include <klocale.h>
++#include <kurl.h>
++#include <kstandarddirs.h>
++
++Element::Element()
++{
++ m_radioactive = false;
++ m_artificial = false;
++ m_abundance = 0;
++}
++
++Isotope* Element::isotopeByNucleons( int numberOfNucleons )
++{
++ QList<Isotope*>::ConstIterator it = m_isotopeList.begin();
++ const QList<Isotope*>::ConstIterator itEnd = m_isotopeList.end();
++
++ for ( ; it != itEnd; ++it )
++ {
++ if ( ( ( *it )->neutrons() + ( *it )->protones() ) == numberOfNucleons )
++ return *it;
++ }
++ return 0;
++}
++
++QString Element::parsedOrbits( bool canBeEmpty )
++{
++ if ( m_orbits.isEmpty() )
++ if ( !canBeEmpty )
++ return i18n( "structure means orbital configuration in this case", "Unknown structure" );
++ else
++ return "";
++
++ QString orbits = m_orbits;
++ QRegExp rxs("([a-z])([0-9]+)");
++ QRegExp rxb("([a-z]{2}) ",false);
++ orbits.replace(rxs,"\\1<sup>\\2</sup>"); //superscript around electron number
++ orbits.replace(rxb,"<b>\\1</b> "); //bold around element symbols
++ return orbits;
++}
++
++Element::~Element()
++{
++}
++
++double Element::meanmass()
++{
++ return m_mass/m_number;
++}
++
++const QString Element::adjustRadius( RADIUSTYPE rtype )
++{
++ double val = 0.0;
++ QString v;
++
++ switch ( rtype )
++ {
++ case ATOMIC:
++ val = m_RadiusAR;
++ break;
++ case IONIC:
++ val = m_RadiusIon;
++ break;
++ case COVALENT:
++ val = m_RadiusCR;
++ break;
++ case VDW:
++ val = m_RadiusVDW;
++ break;
++ }
++
++ if ( val <= 0 )
++ v = i18n( "Value unknown" );
++ else
++ v = i18n( "%1 is a length, eg: 12.3 pm", "%1 pm" ).arg( QString::number( val ) );
++ return v;
++}
++
++const QString Element::adjustUnits( const int type, double value )
++{
++ QString v;
++ if ( type == IE ) //an ionization energy
++ {
++ if ( Prefs::energies() == 0 )
++ {
++ value*=96.6;
++ v = QString::number( value );
++ v.append( " kJ/mol" );
++ }
++ else // use electronvolt
++ {
++ v = QString::number( value );
++ v.append( " eV" );
++ }
++ }
++ return v;
++}
++
++const QString Element::adjustUnits( const int type )
++{
++ QString v = QString::null;
++
++ double val = 0.0; //the value to convert
++
++ if ( type == BOILINGPOINT || type == MELTINGPOINT ) // convert a temperature
++ {
++ if ( type == BOILINGPOINT )
++ val = boiling();
++ else
++ val = melting();
++
++ if ( val <= 0 )
++ v = i18n( "Value unknown" );
++ else
++ {
++ double newvalue = TempUnit::convert( val, (int)TempUnit::Kelvin, Prefs::temperature() );
++ switch (Prefs::temperature()) {
++ case 0: //Kelvin
++ v = i18n( "%1 is the temperature in Kelvin", "%1 K" ).arg( newvalue );
++ break;
++ case 1://Kelvin to Celsius
++ v = i18n( "%1 is the temperature in Celsius", "%1 %2C" ).arg( newvalue ).arg( QChar(0xB0) );
++ break;
++ case 2: // Kelvin to Fahrenheit
++ v = i18n( "%1 is the temperature in Fahrenheit", "%1 %2F" ).arg( newvalue ).arg( QChar(0xB0) );
++ break;
++ case 3: // Kelvin to Rankine
++ v = i18n( "%1 is the temperature in Rankine", "%1 %2Ra" ).arg( newvalue ).arg( QChar(0xB0) );
++ break;
++ case 4: // Kelvin to Reamur
++ v = i18n( "%1 is the temperature in Reamur", "%1 %2R" ).arg( newvalue ).arg( QChar(0xB0) );
++ break;
++ }
++ }
++ }
++ else if ( type == EN ) //Electronegativity
++ {
++ val = electroneg();
++ if ( val <= 0 )
++ v = i18n( "Value not defined" );
++ else
++ v = QString::number( val );
++ }
++ else if ( type == EA ) //Electron affinity
++ {
++ val = electroaf();
++ if ( val == 0.0 )
++ v = i18n( "Value not defined" );
++ else
++ {
++ if ( Prefs::energies() == 0 )
++ {
++ v = i18n( "%1 kJ/mol" ).arg( QString::number( val ) );
++ }
++ else // use electronvolt
++ {
++ val/=96.6;
++ v = i18n( "%1 eV" ).arg( QString::number( val ) );
++ }
++ }
++ }
++ else if ( type == MASS ) // its a mass
++ {
++ val = mass();
++ if ( val <= 0 )
++ v = i18n( "Value unknown" );
++ else
++ v = i18n( "%1 u" ).arg( QString::number( val ) );
++ }
++ else if ( type == DENSITY ) // its a density
++ {
++ val = density();
++
++ if ( val <= 0 )
++ v = i18n( "Value unknown" );
++ else
++ {
++ if ( boiling() < 295.0 )//gasoline
++ {
++ v = i18n( "%1 g/L" ).arg( QString::number( val ) );
++ }
++ else//liquid or solid
++ {
++ v = i18n( "%1 g/cm<sup>3</sup>" ).arg( QString::number( val ) );
++ }
++ }
++ }
++ else if ( type == DATE ) //its a date
++ {
++ val = date();
++ if ( val < 1600 )
++ {
++ v = i18n( "This element was known to ancient cultures" );
++ }
++ else
++ {
++ v = i18n( "This element was discovered in the year %1" ).arg( QString::number( val ) );
++ }
++ }
++
++ return v;
++}
++
++void Element::setRadius( RADIUSTYPE type, double value, const QString& name )
++{
++ switch ( type )
++ {
++ case ATOMIC:
++ m_RadiusAR = value;
++ break;
++ case IONIC:
++ m_RadiusIon = value;
++ m_ionvalue = name;
++ break;
++ case COVALENT:
++ m_RadiusCR = value;
++ break;
++ case VDW:
++ m_RadiusVDW = value;
++ break;
++ }
++}
++
++double Element::radius( RADIUSTYPE type )
++{
++ switch ( type )
++ {
++ case ATOMIC:
++ return m_RadiusAR;
++ break;
++ case IONIC:
++ return m_RadiusIon;
++ break;
++ case COVALENT:
++ return m_RadiusCR;
++ break;
++ case VDW:
++ return m_RadiusVDW;
++ break;
++ }
++ return 0.0;
++}
++
--- /dev/null
-#define ELEMENTSIZE 40
-
-#include <qcolor.h>
-#include <qlist.h>
+ /***************************************************************************
+ * Copyright (C) 2003, 2004, 2005 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., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+ #ifndef ELEMENT_H
+ #define ELEMENT_H
+
- void setupXY();
-
++#include <QColor>
++#include <QList>
+
+ class Element;
+ class QDomDocument;
+ class QPainter;
+ class QPoint;
+ class QFont;
+ class QRect;
+ class Spectrum;
+ class Isotope;
+
+ struct coordinate;
+
+ typedef QList<Element*> EList;
+ typedef QList<coordinate> CList;
+ typedef QList<double> doubleList;
+
+ struct coordinate{
+ int x;
+ int y;
+ };
+
+ /**
+ * In this class all information about an element 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();
+
+ virtual ~Element();
+
+ /**
+ * @returns a pointer to the istope with @p numberOfNucleons
+ * nucleons
+ */
+ Isotope* isotopeByNucleons( int numberOfNucleons );
+
+ enum RADIUSTYPE
+ {
+ ATOMIC = 0,
+ IONIC,
+ VDW, //van der Waals radius
+ COVALENT
+ };
+
+ /**
+ * @return the number of the element
+ */
+ int number() const {
+ return m_number;
+ }
+
+ /**
+ * @return if the Element is radioactive
+ */
+ bool radioactive() const{
+ return m_radioactive;
+ }
+
+ /**
+ * @return if the Element is artificial
+ */
+ bool artificial() const{
+ return m_artificial;
+ }
+
+ /**
+ * @return the information where the name of the Element comes from
+ */
+ QString nameOrigin() const{
+ return m_origin;
+ }
+
+ QString orbits() const{
+ return m_orbits;
+ }
+
+ void setMass( double value ) { m_mass = value; }
+ void setEN( double value ) { m_EN = value; }
+ void setEA( double value ) { m_EA = value; }
+ void setMeltingpoint( double value ) { m_MP = value; }
+ void setBoilingpoint( double value ) { m_BP = value; }
+
+ /**
+ * sets the density of the Element
+ * @param value the density of the Element
+ */
+ void setDensity( double value ) { m_Density = value; }
+
+ /**
+ * set the radius of the radiustype @p type to the value @p value.
+ * The ionicradius also has a name @p name. This will store the charge of
+ * the ion (for example, +2 or -3 )
+ */
+ void setRadius( RADIUSTYPE type, double value, const QString& name = 0 );
+
+ void setDate( int date ) { m_date = date; }
+ void setPeriod( int period ){ m_period = period; }
+ void setBiologicalMeaning( int value ) { m_biological = value; }
+ void setNumber( int num ){ m_number = num; }
+
+ /**
+ * set the abundance in crustal rocks [pm]
+ * @param abundance the abundace in crustal rocks
+ */
+ void setAbundance( int abundance ){ m_abundance = abundance; }
+
+ void setScientist( const QString& value ) { m_scientist = value; }
+ void setCrysatalstructure( const QString& value ) { m_crystalstructure = value; }
+ void setName( const QString& value ) { m_name = value; }
+ void setOrigin( const QString& value ) { m_origin = value; }
+ void setBlock( const QString& value ) { m_block = value; }
+ void setGroup( const QString& value ) { m_group = value; }
+ void setFamily( const QString& value ) { m_family = value; }
+ void setOrbits( const QString& value ) { m_orbits = value; }
+ void setSymbol( const QString& value ) { m_symbol = value; }
+ void setOxydation( const QString& value ) { m_oxstage = value; }
+ void setAcidicbehaviour( const QString& value ) { m_acidbeh = value; }
+ void setIsotopes( const QString& value ) { m_isotopes = value; }
+
+ void setArtificial(){ m_artificial = true; }
+ void setRadioactive(){ m_radioactive = true; }
+
+ void setIonisationList( doubleList l ){ m_ionenergies = l; }
+
+ QList<Isotope*> isotopes() const{
+ return m_isotopeList;
+ }
+
+ QList<double> spectrumList() const{
+ return m_spectrumList;
+ }
+
+ void setIsotopeList( QList<Isotope*> list ){
+ m_isotopeList = list;
+ }
+
+ /**
+ * sets the Spectrum of the Element
+ * @param spec the Spectrum of the Element
+ */
+ void setSpectrum( Spectrum *spec ){
+ m_spectrum = spec;
+ }
+
+ /**
+ * @return if the element has information about spectra
+ */
+ bool hasSpectrum() const{
+ return m_hasSpectrum;
+ }
+
+ /**
+ * define if the element has a known Spectrum
+ * @param value if true, the Element has a Spectrum
+ */
+ void setHasSepctrum(bool value){
+ m_hasSpectrum = value;
+ }
+
+ /**
+ * @return the Spectrum of the element
+ */
+ Spectrum* spectrum() const{
+ return m_spectrum;
+ }
+
+ doubleList ionisationList() const{
+ return m_ionenergies;
+ }
+
+ /**
+ * @return the date of discovery of the element
+ */
+ int date() const {
+ return m_date;
+ }
+
+ /**
+ * return the correct color of the element at the
+ * temperature @p temp
+ */
+ QColor currentColor( const double temp );
+
+ /**
+ * mutator for the element's color
+ */
+ void setElementColor( const QColor &c ) { m_Color = c; }
+
+ /**
+ * @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 abundance in crustal rocks in parts per million
+ */
+ int abundance() const {
+ return 12;
+ }
+
+ /**
+ * @return the symbol of the element
+ */
+ QString symbol() const {
+ return m_symbol;
+ }
+
+ /**
+ * @return the scientist who discovered the element
+ */
+ QString scientist() const{
+ return m_scientist;
+ }
+
+ /**
+ * @return the crystal structure of the element
+ */
+ QString crystalstructure() const{
+ return m_crystalstructure;
+ }
+
+ /**
+ * @return the name of the element
+ */
+ QString elname() const {
+ return m_name;
+ }
+
+ //FIXME I need to add a way to have more than one ionic radius
+ QString ioncharge() const{
+ return m_ionvalue;
+ }
+
+ /**
+ * @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;
+ }
+
+ int period() const {
+ return m_period;
+ }
+
+ QString family() const {
+ return m_family;
+ }
+
+ /**
+ * @return the acidic behavior 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.
+ * @param canBeEmpty specifies if the string returned can be
+ * empty instead of a "Unknown structure" one.
+ */
+ QString parsedOrbits( bool canBeEmpty = false );
+
+ /**
+ * @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 electroaffinity of the element
+ */
+ double electroaf() const {
+ return m_EA;
+ }
+
+ /**
+ * @return the atomic mass of the element in units
+ */
+ double mass() const {
+ return m_mass;
+ }
+
+ /**
+ * @return the density of the element in gramms per mol
+ */
+ double density() const {
+ return m_Density;
+ }
+
+ /**
+ * @return the radius of the element in picometers
+ */
+ double radius( RADIUSTYPE type );
+
+ /**
+ * @return the mean mass of the element
+ */
+ double meanmass();
+
+ int x, y; //for the RegularPeriodicTableView
+
+ /**
+ * adjusts the units for the data. The user can
+ * for example define if Fahrenheit, Kelvin or
+ * Degrees Celsius should be used for the temperature.
+ * This method takes care of that and adjust the
+ * values.
+ * @param type the TYPE of the data
+ * @return the adjusted datastring
+ */
+ const QString adjustUnits( const int type );
+
+ const QString adjustRadius( RADIUSTYPE rtype );
+
+ /**
+ * adjusts the units for the data. The user can
+ * for example define if Fahrenheit, Kelvin or
+ * Degrees Celsius should be used for the temperature.
+ * This method takes care of that and adjust the
+ * values. Depending on @p type a unit will be
+ * added to the adjusted value.
+ * @param type the TYPE of the data
+ * @param value the value of the data.
+ * @return the adjusted datastring
+ */
+ const QString adjustUnits( const int type, double value );
+
+ /**
+ * types of datas
+ */
+ enum TYPE
+ {
+ NOGRADIENT = 0,
+ ATOMICRADIUS,
+ COVALENTRADIUS,
+ VDWRADIUS,
+ MASS,
+ DENSITY,
+ BOILINGPOINT,
+ MELTINGPOINT,
+ EN,
+ EA,
+ DATE,
+ IE,
+ IONICRADIUS
+ };
+
+ QPoint pos() const;
+ QPoint coords() const;
+
+ /**
+ * accessor for the element's color
+ */
+ QColor elementColor() const {
+ return m_Color;
+ }
+
- int xPos() const;
- int yPos() const;
-
+ private:
+ /**
+ * the integer num represents the number of the element
+ */
+ int m_ElementNumber;
+
+ Spectrum *m_spectrum;
+
+ bool m_hasSpectrum;
+
+ QList<Isotope*> m_isotopeList;
+
+ QList<double> m_spectrumList;
+
+ QColor m_Color;
+
-
- public:
- /**
- * draw the rectangle with the information
- * @param p painter to do the drawing on
- * @param value the value to display as text
- * @param c the color used to paint the element
- */
- virtual void drawGradient( QPainter* p, const QString& value, const QColor& c);
-
- /**
- * Draw the Element grayed out. Used in the timeline
- * @param p the painter used for the painting
- */
- virtual void drawGrayedOut( QPainter* p );
-
- /**
- * draw the rectangle with the information
- * @param p painter to do the drawing on
- * @param simple if True more information will be shown
- * @param isCrystal whether the elements should draw its crystal structure
- */
- virtual void drawSelf( QPainter* p, bool simple = false, bool isCrystal = false );
-
- virtual void drawStateOfMatter( QPainter* p, double temperature );
+ double m_mass,
+ m_MP,
+ m_BP,
+ m_EN,
+ m_EA,
+ m_Density,
+ m_RadiusAR,
+ m_RadiusCR,
+ m_RadiusVDW,
+ m_RadiusIon;
+
+
+ int m_number,
+ m_date,
+ m_biological,
+ m_period,
+ m_abundance;
+
+ QString m_symbol,
+ m_name,
+ m_origin,
+ m_oxstage,
+ m_block,
+ m_group,
+ m_family,
+ m_acidbeh,
+ m_orbits,
+ m_isotopes,
+ m_scientist,
+ m_crystalstructure,
+ m_ionvalue;
+
+ bool m_artificial,
+ m_radioactive;
+
+ doubleList m_ionenergies;
+ };
+
+
+ #endif
--- /dev/null
-QString Spectrum::bandsAsHtml()
-{
- QString html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head><title>Chemical data</title>i<body>";
-
- html += "<table>";
-
- QList<band*>::const_iterator it = m_bandlist.begin();
- const QList<band*>::const_iterator itEnd = m_bandlist.end();
- for (;it!=itEnd;++it)
- {
- html += QString( "<tr>" )
- + "<td>" + i18n( "Wavelength: %1 nm" ).arg( ( *it )->wavelength ) + "</td>"
- + "<td>" + i18n( "Intensity: %1" ).arg( ( *it )->intensity ) + "</td>"
- + "<td>" + i18n( "Probability: %1 10<sup>8</sup>s<sup>-1</sup>" ).arg( ( *it )->aki ) + "</td>"
- + "<td>" + i18n( "Energy 1: %1" ).arg( ( *it )->energy1 ) + "</td>"
- + "<td>" + i18n( "Energy 2: %1" ).arg( ( *it )->energy2 ) + "</td>"
- + "<td>" + i18n( "Electron Configuration 1: %1" ).arg( ( *it )->electronconfig1 ) + "</td>"
- + "<td>" + i18n( "Electron Configuration 2: %1" ).arg( ( *it )->electronconfig2 ) + "</td>"
- + "<td>" + i18n( "Term 1: %1" ).arg( ( *it )->term1 ) + "</td>"
- + "<td>" + i18n( "Term 2: %1" ).arg( ( *it )->term2 ) + "</td>"
- + "<td>" + i18n( "J 1: %1" ).arg( ( *it )->J1 ) + "</td>"
- + "<td>" + i18n( "J 2: %1" ).arg( ( *it )->J2 ) + "</td>"
- + "</tr>\n";
- }
-
- html += "</table>";
-
- html += "</body></html>";
- return html;
-}
+ /***************************************************************************
+ * Copyright (C) 2005 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., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+ #include "spectrum.h"
+
+ #include "element.h"
+
+ #include <klocale.h>
+
+ #include <math.h>
+
+ double Spectrum::minBand()
+ {
+ double value = ( *m_bandlist.begin() )->wavelength;
+ QList<band*>::const_iterator it = m_bandlist.begin();
+ const QList<band*>::const_iterator itEnd = m_bandlist.end();
+ for (;it!=itEnd;++it)
+ {
+ if ( value > ( *it )->wavelength )
+ value = ( *it )->wavelength;
+ }
+ return value;
+ }
+
+ double Spectrum::maxBand()
+ {
+ double value = ( *m_bandlist.begin() )->wavelength;
+ QList<band*>::const_iterator it = m_bandlist.begin();
+ const QList<band*>::const_iterator itEnd = m_bandlist.end();
+ for (;it!=itEnd;++it)
+ {
+ if ( value < ( *it )->wavelength )
+ value = ( *it )->wavelength;
+ }
+ return value;
+ }
+
+
+ Spectrum* Spectrum::adjustToWavelength( double min, double max )
+ {
+ Spectrum *spec = new Spectrum();
+
+ QList<band*>::const_iterator it = m_bandlist.begin();
+ const QList<band*>::const_iterator itEnd = m_bandlist.end();
+
+ for ( ; it != itEnd; ++it )
+ {
+ if ( ( *it )->wavelength < min || ( *it )->wavelength > max )
+ continue;
+
+ spec->addBand( *it );
+ }
+
+ spec->adjustMinMax();
+
+ return spec;
+ }
+
+ void Spectrum::adjustIntensities()
+ {
+ int maxInt = 0;
+ QList<band*>::Iterator it = m_bandlist.begin();
+ const QList<band*>::Iterator itEnd = m_bandlist.end();
+
+ //find the highest intensity
+ for ( ; it != itEnd; ++it )
+ {
+ if ( ( *it )->intensity > maxInt )
+ maxInt = ( *it )->intensity;
+ }
+
+ //check if an adjustment is needed or not
+ if ( maxInt == 1000 ) return;
+
+ double max = ( double ) maxInt;
+
+ //now adjust the intensities.
+ it = m_bandlist.begin();
+ for ( ; it != itEnd; ++it )
+ {
+ double curInt = ( ( double )( *it )->intensity );
+
+ double newInt = max*1000/curInt;
+ ( *it )->intensity = ( int ) round( newInt );
+ }
+ }
+
+ QList<double> Spectrum::wavelengths( double min, double max )
+ {
+ QList<double> list;
+
+ QList<band*>::const_iterator it = m_bandlist.begin();
+ const QList<band*>::const_iterator itEnd = m_bandlist.end();
+
+ for ( ; it != itEnd; ++it )
+ {
+ if ( ( *it )->wavelength < min || ( *it )->wavelength > max )
+ continue;
+
+ list.append( ( *it )->wavelength );
+ }
+
+ return list;
+ }
+
+
--- /dev/null
-#include <qlist.h>
-#include <qstring.h>
+ #ifndef SPECTRUM_H
+ #define SPECTRUM_H
+ /***************************************************************************
+ * Copyright (C) 2005 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., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
- /**
- * @return the data of a spectrum as HTML code
- */
- QString bandsAsHtml();
-
++#include <QList>
++#include <QString>
+
+ class Element;
+
+ /**
+ * @author Carsten Niehaus
+ *
+ * This class represents an spectrum with all its properties
+ */
+ class Spectrum
+ {
+ public:
+ /**
+ * This spectrum doesn't belong to any element
+ */
+ Spectrum(){};
+
+ /**
+ * public destructor
+ */
+ ~Spectrum(){};
+
+ /**
+ * a band is one line in the spectrum of an element
+ */
+ class band
+ {
+ public:
+ band(){
+ wavelength = -1.0;
+ aki = -1.0;
+ energy1 = -1.0;
+ energy2 = -1.0;
+ intensity = -1;
+ }
+
+ ///in nm
+ double wavelength;
+
+ ///Transition Probabilities
+ ///10^8s-1 (1000000000 per second)
+ double aki;
+
+ ///number of energylevels per centimeter
+ double energy1;
+
+ ///number of energylevels per centimeter
+ double energy2;
+
+ ///relative. The highest is per definition 1000
+ int intensity;
+
+ QString electronconfig1;
+ QString electronconfig2;
+ QString term1;
+ QString term2;
+ QString J1;
+ QString J2;
+ };
+
+ /**
+ * adds the band @p b to the internal
+ * lists of bands
+ */
+ void addBand( Spectrum::band* b ){
+ if ( b )
+ m_bandlist.append( b );
+ }
+
+ /**
+ * @param min the lowest allowed wavalength in nanometer
+ * @param max the highest allowed wavalength in nanometer
+ *
+ * @returns a spectrum with the wavelength in the range
+ * of @p min to @p max. The intensities are readjusted
+ * so that the biggest intensity is again 1000 and the
+ * others are adopted.
+ */
+ Spectrum* adjustToWavelength( double min, double max );
+
+ /**
+ * sets the highest intensity to 1000 and adjusts the
+ * others
+ */
+ void adjustIntensities();
+
+ /**
+ * @param min the lowest allowed wavalength in nanometer
+ * @param max the highest allowed wavalength in nanometer
+ *
+ * @return the wavelength in a QList<double>
+ */
+ QList<double> wavelengths( double min, double max );
+
+ /**
+ * @return the smallest wavelength
+ */
+ double min() const{
+ return m_min;
+ }
+
+ /**
+ * @return the highest wavelength
+ */
+ double max() const{
+ return m_max;
+ }
+
+ /**
+ * @return the list of bands of the spectrum
+ */
+ QList<Spectrum::band*> bandlist(){
+ return m_bandlist;
+ }
+
+ QList<Spectrum::band*> bandList(){
+ return bandlist();
+ }
+
+ /**
+ * cache the values of the biggest and
+ * smallest wavelenght
+ */
+ void adjustMinMax(){
+ m_min = minBand();
+ m_max = maxBand();
+ }
+
- Element* parentElement()
- { return m_parentElement; }
+ /**
+ * @return the parent element of this spectrum
+ */
- * @return the biggest wavelength
++ Element* parentElement() {
++ return m_parentElement;
++ }
+
+ private:
+ /**
+ * @return the smallest wavelength
+ */
+ double minBand();
+
+ /**
++ * @return the bigest wavelength
+ */
+ double maxBand();
+
+ /**
+ * the internal dataset
+ */
+ QList<band*> m_bandlist;
+
+ /**
+ * the cached values of the highest and lowest wavelength
+ */
+ double m_max, m_min;
+
+ Element* m_parentElement;
+ };
+ #endif // SPECTRUM_H
--- /dev/null
-#include "../spectrum.h"
+ /***************************************************************************
+ copyright : (C) 2005 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 "spectrumparser.h"
++#include "spectrum.h"
+
+ #include <QList>
+ #include <qbytearray.h>
+ #include <qdom.h>
+ #include <qfile.h>
+ #include <qregexp.h>
+ #include <qtextstream.h>
+ #include <QString>
+
+ #include <kdebug.h>
+
+ SpectrumParser::SpectrumParser(const QString& filename)
+ {
+ // m_file = QFile(filename);
+ }
+
+ SpectrumParser::SpectrumParser(const QFile& file)
+ {
+ // m_file = file;
+ }
+
+ void SpectrumParser::saveSpectrum( Spectrum *spectrum )
+ {
+ if ( !spectrum ) return;
+
+ QDomDocument doc( "SpectrumDocument" );
+
+ QFile docfile( "/home/carsten/test.xml" );
+ // QTextStream stream( m_file );
+
+ QList<Spectrum::band*> blist = spectrum->bandlist();
+
+ QDomElement docelem = doc.createElement( "spectrum" );
+ doc.appendChild( docelem );
+
+ foreach( Spectrum::band* band, blist )
+ {
+ QDomElement bandelem = doc.createElement( "band" );
+ bandelem.setAttribute( "wavelength", band->wavelength );
+ bandelem.setAttribute( "intensity", band->intensity );
+ bandelem.setAttribute( "aki", band->aki );
+ bandelem.setAttribute( "energy1", band->energy1 );
+ bandelem.setAttribute( "energy2", band->energy2 );
+ bandelem.setAttribute( "term1", band->term1 );
+ bandelem.setAttribute( "term2", band->term2 );
+ bandelem.setAttribute( "electronconfig1", band->electronconfig1 );
+ bandelem.setAttribute( "electronconfig2", band->electronconfig2 );
+ bandelem.setAttribute( "J1", band->J1 );
+ bandelem.setAttribute( "J2", band->J2 );
+ docelem.appendChild( bandelem );
+ }
+
+
+
+ kdDebug() << "Text: " << doc.toString() << endl;
+ }