#include "spectrum.h"
#include "isotope.h"
#include "kalziumdataobject.h"
+#include "kalziumutils.h"
#include <qdom.h>
#include <qfile.h>
#include <qpainter.h>
#include <qregexp.h>
+#include <qfontmetrics.h>
#include <kdebug.h>
#include <klocale.h>
#include <kurl.h>
#include <kstandarddirs.h>
-#include <math.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 )
return orbits;
}
-
-double Element::strippedValue( double num )
-{
- if ( !finite( num ) )
- return num;
-
- double power;
- power = 1e-6;
- while ( power < num )
- power *= 10;
-
- num = num / power * 10000;
- num = round( num );
-
- return num * power / 10000;
-}
-
-
Element::~Element()
{
}
-
-
double Element::meanmass()
{
return m_mass/m_number;
break;
case 1://Kelvin to Celsius
val-=273.15;
- v = i18n( "%1 is the temperature in Celsius", "%1 C" ).arg( QString::number( val ) );
+ v = i18n( "%1 is the temperature in Celsius", "%1 %2C" ).arg( QString::number( val ) ).arg( "\xB0" );
break;
case 2: // Kelvin to Fahrenheit
val = val * 1.8 - 459.67;
- v = i18n( "%1 is the temperature in Fahrenheit", "%1 F" ).arg( QString::number( val ) );
+ v = i18n( "%1 is the temperature in Fahrenheit", "%1 %2F" ).arg( QString::number( val ) ).arg("\xB0");
break;
}
}
QString text;
QFont symbol_font = p->font();
- symbol_font.setPointSize( 18 );
+
+ symbol_font.setPointSize( 10 );
QFont f = p->font();
f.setPointSize( 9 );
//top left
p->setPen( Qt::black );
- text = QString::number( strippedValue( mass( ) ) );
+ text = QString::number( KalziumUtils::strippedValue( mass( ) ) );
p->drawText( X,Y ,ELEMENTSIZE,h_small,Qt::AlignCenter, text );
text = QString::number( number() );
p->setPen( Qt::black );
p->drawRect( X, Y,ELEMENTSIZE+1,ELEMENTSIZE+1);
}
-
+
QColor Element::currentColor( const double temp )
{
QColor color;
setElementColor( c );
//the height of a "line" inside an element
- int h_small = 15; //the size for the small units like elementnumber
+ int h_small = 10; //the size for the small units like elementnumber
//The X-coordiante
int X = xPos();
p->setPen( Qt::black );
QFont symbol_font = p->font();
- symbol_font.setPointSize( 18 );
QFont f = p->font();
- f.setPointSize( 9 );
-
+
+ f.setPointSize( KalziumUtils::maxSize(value, QRect( X,Y+ELEMENTSIZE-h_small, ELEMENTSIZE, h_small ),f, p ) );
p->setFont( f );
p->drawText( X,Y+ELEMENTSIZE-h_small , ELEMENTSIZE, h_small,Qt::AlignCenter, value );
+ const QRect rect = QRect( X,Y,ELEMENTSIZE-2,ELEMENTSIZE-10 );
+ int goodsize = KalziumUtils::maxSize( symbol(), rect, symbol_font, p );
+ symbol_font.setPointSize( goodsize );
p->setFont( symbol_font );
- p->drawText( X,Y, ELEMENTSIZE,ELEMENTSIZE,Qt::AlignCenter, symbol() );
+ p->drawText( X+1,Y+5, ELEMENTSIZE-2,ELEMENTSIZE-10,Qt::AlignCenter, symbol() );
//border
p->setPen( Qt::black );
void Element::drawSelf( QPainter* p, bool simple, bool isCrystal )
{
//the height of a "line" inside an element
- int h_small = 15; //the size for the small units like elementnumber
+ int h_small = 12; //the size for the small units like elementnumber
//The X-coordiante
int X = xPos();
p->setPen( elementColor() );
p->fillRect( X, Y,ELEMENTSIZE,ELEMENTSIZE, elementColor() );
+ p->setPen( Qt::black );
QString text;
QFont symbol_font = p->font();
- symbol_font.setPointSize( 18 );
+
+ const int max = ELEMENTSIZE-10;
+
+ const QRect rect = QRect( X,Y,ELEMENTSIZE-2,max );
+
+ int goodsize = KalziumUtils::maxSize( symbol(), rect, symbol_font, p );
+ symbol_font.setPointSize( goodsize );
+ p->setFont( symbol_font );
+
+ if ( !simple )
+ p->drawText( X+1,Y+5, ELEMENTSIZE-2,max,Qt::AlignCenter, symbol() );
+ else
+ p->drawText( X+1,Y+5, ELEMENTSIZE-2,max,Qt::AlignHCenter, symbol() );
+
QFont f = p->font();
- f.setPointSize( 9 );
-
+
+ QRect smallRect( X,Y ,ELEMENTSIZE-4,h_small );
+ f.setPointSize( KalziumUtils::maxSize( QString::number( number() ), smallRect, f, p ) );
+
p->setFont( f );
- p->setPen( Qt::black );
if ( !simple )
{//the user only wants a simple periodic table, don't weight the cell
text = i18n( "Crystalsystem hexagonal dense packed", "hdp" );
else if ( structure == "ccp" )
text = i18n( "Crystalsystem cubic close packed", "ccp" );
-// else
-// text = QString::null;
}
else
- text = QString::number( strippedValue( mass( ) ) );
- p->drawText( X,Y ,ELEMENTSIZE,h_small,Qt::AlignCenter, text );
+ text = QString::number( KalziumUtils::strippedValue( mass( ) ) );
+ p->drawText( X+2,Y ,ELEMENTSIZE-4 ,h_small,Qt::AlignCenter, text );
}
-
+
text = QString::number( number() );
- p->drawText( X,Y+ELEMENTSIZE-h_small , ELEMENTSIZE, h_small,Qt::AlignCenter, text );
-
- p->setFont( symbol_font );
- if ( !simple )
- p->drawText( X,Y, ELEMENTSIZE,ELEMENTSIZE,Qt::AlignCenter, symbol() );
- else
- p->drawText( X,Y, ELEMENTSIZE,ELEMENTSIZE,Qt::AlignHCenter, symbol() );
+ p->drawText( X+2,Y+ELEMENTSIZE-h_small , ELEMENTSIZE-4, h_small,Qt::AlignCenter, text );
- p->setPen( Qt::black );
p->drawRect( X, Y,ELEMENTSIZE+1,ELEMENTSIZE+1);
}
#define ELEMENTSIZE 40
#include <qcolor.h>
-#include <qvaluelist.h>
+#include <qlist.h>
class Element;
class QDomDocument;
class QPainter;
class QPoint;
+class QFont;
+class QRect;
class Spectrum;
class Isotope;
struct coordinate;
-typedef QValueList<Element*> EList;
-typedef QValueList<coordinate> CList;
-typedef QValueList<double> doubleList;
+typedef QList<Element*> EList;
+typedef QList<coordinate> CList;
+typedef QList<double> doubleList;
struct coordinate{
int x;
Element();
virtual ~Element();
+
+ /**
+ * @returns a pointer to the istope with @p numberOfNucleons
+ * nucleons
+ */
+ Isotope* isotopeByNucleons( int numberOfNucleons );
enum RADIUSTYPE
{
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;
}
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; }
/**
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 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; }
- void setIonisationList( doubleList l ){
- m_ionenergies = l;
- }
-
- QValueList<Isotope*> isotopes() const{
+ QList<Isotope*> isotopes() const{
return m_isotopeList;
}
- QValueList<double> spectrumList() const{
+ QList<double> spectrumList() const{
return m_spectrumList;
}
- void setIsotopeList( QValueList<Isotope*> list ){
+ 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 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;
}
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
IONICRADIUS
};
- /**
- * calculate the 4-digit value of the value @p w
- * @return the 4-digit value
- */
- static double strippedValue( double w );
-
QPoint pos() const;
QPoint coords() const;
bool m_hasSpectrum;
- QValueList<Isotope*> m_isotopeList;
+ QList<Isotope*> m_isotopeList;
- QValueList<double> m_spectrumList;
+ QList<double> m_spectrumList;
QColor m_Color;
int m_number,
m_date,
m_biological,
- m_period;
+ m_period,
+ m_abundance;
QString m_symbol,
m_name,
#include <kdebug.h>
#include <klocale.h>
-Isotope::Isotope( int neutrons, int protones, double percentage, double weight, double halflife, QString format, bool alphadecay, bool betaplusdecay, bool betaminusdecay, bool ecdecay, double alphapercentage, double betapluspercentage, double betaminuspercentage, double ecpercentage, double decayenergy, QString spin, QString magmoment)
+Isotope::Isotope( int neutrons, int protones, double percentage, double weight, double halflife, QString format, double alphadecay, double betaplusdecay, double betaminusdecay, double ecdecay, double alphapercentage, double betapluspercentage, double betaminuspercentage, double ecpercentage, QString spin, QString magmoment)
{
m_neutrons = neutrons;
m_protones = protones;
m_betaminusdecay = betaminusdecay;
m_ecdecay = ecdecay;
- m_decayenergy = decayenergy;
m_spin = spin;
m_magmoment = magmoment;
double weight,
double halflife,
QString format,
- bool alphadecay,
- bool betaplusdecay,
- bool betaminusdecay,
- bool ecdecay,
+ double alphadecay,
+ double betaplusdecay,
+ double betaminusdecay,
+ double ecdecay,
double alphapercentage,
double betapluspercentage,
double betaminuspercentage,
double ecpercentage,
- double decayenergy,
QString spin,
QString magmoment);
return m_protones;
}
+ /**
+ * @return the number of nucleons of ths isotope
+ */
+ int nucleons() const{
+ return m_protones+m_neutrons;
+ }
+
/**
* the weight of the isotope
*/
}
/**
- * @return true if the isotopes decays in alpha rays
+ * @return the energy of isotope's alpha decay
*/
- bool alphadecay() const{
+ double alphadecay() const{
return m_alphadecay;
}
/**
- * @return true if the isotopes decays in beta plus rays
+ * @return the energy of isotope's beta plus decay
*/
- bool betaplusdecay() const{
+ double betaplusdecay() const{
return m_betaplusdecay;
}
/**
- * @return true if the isotopes decays in beta-minus rays
+ * @return the energy of isotope's beta-minus decay
*/
- bool betaminusdecay() const{
+ double betaminusdecay() const{
return m_betaminusdecay;
}
- bool ecdecay() const{
+ /**
+ * @return the energy of isotope's EC- decay
+ */
+ double ecdecay() const{
return m_ecdecay;
}
-
- double decayenergy() const{
- return m_decayenergy;
- }
-
+
QString spin() const{
return m_spin;
}
*/
int m_protones;
- ///Specify if the decay is of this kind
- bool m_alphadecay;
- ///Specify if the decay is of this kind
- bool m_betaplusdecay;
- ///Specify if the decay is of this kind
- bool m_betaminusdecay;
- ///Specify if the decay is of this kind
- bool m_ecdecay;
+ ///Specify if the decay is the energy
+ double m_alphadecay;
+ ///Specify if the decay is the energy
+ double m_betaplusdecay;
+ ///Specify if the decay is the energy
+ double m_betaminusdecay;
+ ///Specify if the decay is the energy
+ double m_ecdecay;
- double m_decayenergy;
/**
*spin and parity
double Spectrum::minBand()
{
double value = ( *m_bandlist.begin() ).wavelength;
- QValueList<band>::const_iterator it = m_bandlist.begin();
- const QValueList<band>::const_iterator itEnd = m_bandlist.end();
+ 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 )
double Spectrum::maxBand()
{
double value = ( *m_bandlist.begin() ).wavelength;
- QValueList<band>::const_iterator it = m_bandlist.begin();
- const QValueList<band>::const_iterator itEnd = m_bandlist.end();
+ 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 )
{
Spectrum *spec = new Spectrum();
- QValueList<band>::const_iterator it = m_bandlist.begin();
- const QValueList<band>::const_iterator itEnd = m_bandlist.end();
+ QList<band>::const_iterator it = m_bandlist.begin();
+ const QList<band>::const_iterator itEnd = m_bandlist.end();
for ( ; it != itEnd; ++it )
{
void Spectrum::adjustIntensities()
{
int maxInt = 0;
- QValueList<band>::Iterator it = m_bandlist.begin();
- const QValueList<band>::Iterator itEnd = m_bandlist.end();
+ QList<band>::Iterator it = m_bandlist.begin();
+ const QList<band>::Iterator itEnd = m_bandlist.end();
//find the highest intensity
for ( ; it != itEnd; ++it )
}
}
-QValueList<double> Spectrum::wavelengths( double min, double max )
+QList<double> Spectrum::wavelengths( double min, double max )
{
- QValueList<double> list;
+ QList<double> list;
- QValueList<band>::const_iterator it = m_bandlist.begin();
- const QValueList<band>::const_iterator itEnd = m_bandlist.end();
+ QList<band>::const_iterator it = m_bandlist.begin();
+ const QList<band>::const_iterator itEnd = m_bandlist.end();
for ( ; it != itEnd; ++it )
{
html += "<table>";
- QValueList<band>::const_iterator it = m_bandlist.begin();
- const QValueList<band>::const_iterator itEnd = m_bandlist.end();
+ QList<band>::const_iterator it = m_bandlist.begin();
+ const QList<band>::const_iterator itEnd = m_bandlist.end();
for (;it!=itEnd;++it)
{
html += QString( "<tr>" )
***************************************************************************/
#include <qstring.h>
-#include <qvaluelist.h>
+#include <qlist.h>
class QPixmap;
class Element;
* @param min the lowest allowed wavalength in nanometer
* @param max the highest allowed wavalength in nanometer
*
- * @return the wavelength in a QValueList<double>
+ * @return the wavelength in a QList<double>
*/
- QValueList<double> wavelengths( double min, double max );
+ QList<double> wavelengths( double min, double max );
/**
* @return the smallest wavelength
/**
* @return the list of bands of the spectrum
*/
- QValueList<band>* bandlist(){
+ QList<band>* bandlist(){
return &m_bandlist;
}
/**
* the internal dataset
*/
- QValueList<band> m_bandlist;
+ QList<band> m_bandlist;
/**
* the cached values of the highest and lowest wavelength
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005 by Pino Toscano *
+ * toscano.pino@tiscali.it *
+ * *
+ * 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 Steet, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "tempunit.h"
+
+double TempUnit::convert( double value, TempUnit::Unit from, TempUnit::Unit to )
+{
+ /**
+ * These are the four formula needed to convert from
+ * Kelvin the the other units:
+
+ Kelvin Celsius °C = K - 273,15
+ Kelvin Fahrenheit °F = K × 1,8 - 459,67
+ Kelvin Rankine °Ra = K × 1,8
+ Kelvin Reaumur °R = ( K - 273,15 ) × 0,8
+ */
+
+ if ( from != Kelvin )
+ value = convertToKelvin( value, from );
+
+ //now 'value' is in Kelvin
+ switch( to )
+ {
+ case Celsius:
+ return value - 273.16;
+ case Fahrenheit:
+ return value * 1.8 - 459.67;
+ case Rankine:
+ return value * 1.8;
+ case Reaumur:
+ return ( value - 273.15 )* 0.8;
+ case Kelvin:
+ return value;
+ }
+ return value;
+}
+
+double TempUnit::convertToKelvin( const double value, TempUnit::Unit from )
+{
+ switch( from )
+ {
+ case Kelvin:
+ return value;
+ case Celsius:
+ return value + 273.16;
+ case Fahrenheit:
+ return ( value + 459.67 )/1.8;
+ case Rankine:
+ return value / 1.8;
+ case Reaumur:
+ return ( value * 1.25 ) + 273.15;
+ }
+ return value;
+}
+
+double TempUnit::convert( const double value, int from, int to )
+{
+ return convert( value, (TempUnit::Unit)from, (TempUnit::Unit)to );
+}
+
+QStringList TempUnit::unitListSymbols()
+{
+ QStringList list;
+ list << "K";
+ list << QString::fromUtf8("°C");
+ list << QString::fromUtf8("°F");
+ list << QString::fromUtf8("°Ra");
+ list << QString::fromUtf8("°R");
+ return list;
+}
+
+QString TempUnit::unitListSymbol( int i )
+{
+ QStringList l = unitListSymbols();
+ if ( ( i < 0 ) || ( i >= (int)l.count() ) )
+ return l[0];
+ return l[i];
+}
+
+QPair<double, double> TempUnit::rangeForUnit( TempUnit::Unit u )
+{
+ switch( u )
+ {
+ case Kelvin:
+ {
+ return QPair<double, double>( 0.0, 5000.0 );
+ break;
+ }
+ case Celsius:
+ {
+ return QPair<double, double>( -273.16, 4726.84 );
+ break;
+ }
+ case Fahrenheit:
+ {
+ return QPair<double, double>( -459.67, 8540.33 );
+ break;
+ }
+ case Rankine:
+ {
+ return QPair<double, double>( 0.0, 9000.0 );
+ break;
+ }
+ case Reaumur:
+ {
+ return QPair<double, double>( -218.52, 3781.48 );
+ break;
+ }
+ }
+ return QPair<double, double>( 0.0, 5000.0 );
+}
+
+QPair<double, double> TempUnit::rangeForUnit( int u )
+{
+ return rangeForUnit( (TempUnit::Unit)u );
+}
+
--- /dev/null
+#ifndef TEMPUNIT_H
+#define TEMPUNIT_H
+/***************************************************************************
+ * Copyright (C) 2005 by Pino Toscano *
+ * toscano.pino@tiscali.it *
+ * *
+ * 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 Steet, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include <qpair.h>
+#include <qstringlist.h>
+
+/**
+ * This class obtains all the info needed to work with the units of measure
+ * of temperature.
+ *
+ * It has static methods you can call to get the various infos. The most
+ * important methods is convert(), that performs conversions.
+ *
+ * @author Pino Toscano
+ */
+class TempUnit
+{
+ public:
+
+ enum Unit { Kelvin = 0,
+ Celsius,
+ Fahrenheit,
+ Rankine,
+ Reaumur
+ };
+
+ /**
+ * Convert the temperature unit @p value given in the unit
+ * @p from to the unit @p to.
+ *
+ * @return the value converted
+ */
+ static double convert( double value,
+ TempUnit::Unit from,
+ TempUnit::Unit to );
+
+
+ /**
+ * @param value the temperature to convert
+ * @param from the unit from which to convert
+ *
+ * @return the temperature to Kelvin
+ */
+ static double convertToKelvin( const double value,
+ TempUnit::Unit from );
+
+ /**
+ * @overload
+ */
+ static double convert( const double value,
+ int from,
+ int to );
+
+ /**
+ * @return a list with the symbols of the temperature units
+ * we support
+ */
+ static QStringList unitListSymbols();
+
+ /**
+ * @return the symbol of the @p i -th unit
+ */
+ static QString unitListSymbol( int i );
+
+ static QPair<double, double> rangeForUnit( TempUnit::Unit u );
+
+ /**
+ * @overload
+ */
+ static QPair<double, double> rangeForUnit( int u );
+
+};
+#endif // TEMPUNIT_H