#include "element.h"
#include "prefs.h"
#include "spectrum.h"
+#include "isotope.h"
+#include "kalziumdataobject.h"
#include <qdom.h>
#include <qfile.h>
{
return QPoint( x, y );
}
-
-KalziumDataObject::KalziumDataObject()
-{
- QDomDocument doc( "datadocument" );
-
- KURL url;
- url.setPath( locate("data", "kalzium/data/"));
- url.setFileName( "data.xml" );
- QFile layoutFile( url.path() );
-
- if (!layoutFile.exists())
- kdDebug() << "data.xml not found" << endl;
-
- if (!layoutFile.open(IO_ReadOnly))
- kdDebug() << "data.xml IO-error" << endl;
-
- ///Check if document is well-formed
- if (!doc.setContent(&layoutFile))
- {
- kdDebug() << "wrong xml" << endl;
- layoutFile.close();
- }
- layoutFile.close();
-
- ElementList = readData( doc );
- m_numOfElements = ElementList.count();
-}
-
-KalziumDataObject::~KalziumDataObject()
-{}
-
-Element* KalziumDataObject::element( int number )
-{
- return *( ElementList.at( number-1 ) );
-}
-
-EList KalziumDataObject::readData( QDomDocument &dataDocument )
-{
- EList list;
- QDomNodeList elementNodes; //the list of all element
- QDomElement domElement; //a single element
-
- //read in all elements
- elementNodes = dataDocument.elementsByTagName( "element" );
-
- for ( uint i = 0; i < elementNodes.count(); ++i )
- {//iterate through all elements
- domElement = ( const QDomElement& ) elementNodes.item( i ).toElement();
-
- double mass = domElement.namedItem( "mass" ).toElement().text().toDouble();
- double en = domElement.namedItem( "electronegativity" ).toElement().text().toDouble();
- double ea = domElement.namedItem( "electronaffinity" ).toElement().text().toDouble();
- double mp = domElement.namedItem( "meltingpoint" ).toElement().text().toDouble();
- double bp = domElement.namedItem( "boilingpoint" ).toElement().text().toDouble();
- double density = domElement.namedItem( "density" ).toElement().text().toDouble();
- double covalent_radius = domElement.namedItem( "radius" ).namedItem( "covalent" ).toElement().text().toDouble();
- //van der Waals-Radius
- double vdw_radius = domElement.namedItem( "radius" ).namedItem( "vdw" ).toElement().text().toDouble();
- double atomic_radius = domElement.namedItem( "radius" ).namedItem( "atomic" ).toElement().text().toDouble();
- double ionic_radius = domElement.namedItem( "radius" ).namedItem( "ionic" ).toElement().text().toDouble();
- QString ionic_charge = domElement.namedItem( "radius" ).namedItem( "ionic" ).toElement().attributeNode( "charge" ).value();
-
- int bio = domElement.namedItem( "biologicalmeaning" ).toElement().text().toInt();
- int radioactive = domElement.namedItem( "radioactive" ).toElement().text().toInt();
- int artificial = domElement.namedItem( "artificial" ).toElement().text().toInt();
- int date = domElement.namedItem( "date" ).toElement().text().toInt();
- int number = domElement.namedItem( "number" ).toElement().text().toInt();
-
- QString scientist = domElement.namedItem( "date" ).toElement().attributeNode( "scientist" ).value();
- QString crystal = domElement.namedItem( "crystalstructure" ).toElement().text();
-
- QDomElement nameE = domElement.namedItem( "name" ).toElement();
- QString name = nameE.text();
- QString origin = nameE.attributeNode( "origin" ).value();
-
- QString block = domElement.namedItem( "block" ).toElement().text();
- QString group = domElement.namedItem( "group" ).toElement().text();
- QString family = domElement.namedItem( "family" ).toElement().text();
- QString orbits = domElement.namedItem( "orbits" ).toElement().text();
- QString symbol = domElement.namedItem( "symbol" ).toElement().text();
- QString oxydation = domElement.namedItem( "oxydation" ).toElement().text();
- QString acidicbehaviour = domElement.namedItem( "acidicbehaviour" ).toElement().text();
-
- QDomNodeList elist = domElement.elementsByTagName( "energy" );
- QValueList<double> ionlist;
- for( uint i = 0; i < elist.length(); i++ )
- {
- ionlist.append( elist.item( i ).toElement().text().toDouble() );
- }
-
- //now read in all the date for the isotopes
- QDomNodeList isotopelist = domElement.elementsByTagName( "isotope" );
- QValueList<Isotope*> isolist;
- for( uint i = 0; i < isotopelist.length(); i++ )
- {
- QDomElement iso = isotopelist.item( i ).toElement();
- double halflife = iso.attributeNode( "halflife" ).value().toDouble();
- double weight = iso.attributeNode( "weight" ).value().toDouble();
- QString format = iso.attributeNode( "halflifeformat" ).value();
- int neutrons = iso.attributeNode( "neutron" ).value().toInt();
- double percentage = iso.attributeNode( "percentage" ).value().toDouble();
- QString alphadecay = iso.attributeNode( "alphadecay" ).value();
- QString betaplusdecay = iso.attributeNode( "betaplusdecay" ).value();
- QString betaminusdecay = iso.attributeNode( "betaminusdecay" ).value();
- QString ecdecay = iso.attributeNode( "ecdecay" ).value();
- double decayenergy = iso.attributeNode( "decayenergy" ).value().toDouble();
- QString spin = iso.attributeNode( "spin" ).value();
- QString magmoment = iso.attributeNode( "magmoment" ).value();
-
- bool alphadecay_ = false, betaminusdecay_ = false, betaplusdecay_ = false, ecdecay_ = false;
- if ( betaplusdecay == "true" ) betaplusdecay_ = true;
- if ( betaminusdecay == "true" ) betaminusdecay_ = true;
- if ( ecdecay == "true" ) ecdecay_ = true;
- if ( alphadecay == "true" ) alphadecay_ = true;
-
-
- Isotope *isotope = new Isotope( neutrons, percentage, weight, halflife, format, alphadecay_, betaplusdecay_, betaminusdecay_, ecdecay_, decayenergy, spin, magmoment );
- isolist.append( isotope );
- }
-
- QDomNodeList spectrumList = domElement.namedItem( "spectra" ).toElement().elementsByTagName( "spectrum" );
-
- Spectrum *spectrum;
- for( uint i = 0; i < spectrumList.length(); i++ )
- {
- spectrum = new Spectrum();
- Spectrum::band b;
- QDomElement spec = spectrumList.item( i ).toElement();
-
- b.intensity = spec.attributeNode( "intensity" ).value().toInt();
- b.wavelength = spec.attributeNode( "wavelength" ).value().toDouble();
- b.aki = spec.attributeNode( "aki" ).value().toDouble();
- b.energy1 = spec.attributeNode( "energy1" ).value().toDouble();
- b.energy2 = spec.attributeNode( "energy2" ).value().toDouble();
- b.electronconfig1 = spec.attributeNode( "electronconfig1" ).value();
- b.electronconfig2 = spec.attributeNode( "electronconfig1" ).value();
- b.term1 = spec.attributeNode( "term1" ).value();
- b.term2 = spec.attributeNode( "term2" ).value();
- b.J1 = spec.attributeNode( "J1" ).value();
- b.J2 = spec.attributeNode( "J2" ).value();
-
- spectrum->addBand( b );
- }
-
- Element *e = new Element();
- e->setSpectrum( spectrum );
- e->setDate(date);
- e->setBiologicalMeaning(bio);
- e->setNumber( number );
- e->setName(i18n(name.utf8()));
- e->setRadius( Element::ATOMIC, atomic_radius );
- e->setRadius( Element::IONIC, ionic_radius, ionic_charge );
- e->setRadius( Element::COVALENT, covalent_radius );
- e->setRadius( Element::VDW, vdw_radius );
-
- if ( artificial == 1 )
- e->setArtificial();
- if ( radioactive == 1 )
- e->setRadioactive();
-
- e->setScientist(scientist);
- e->setCrysatalstructure( crystal );
- e->setOrigin(origin);
- e->setBlock(block);
- e->setGroup(group);
- e->setFamily(family);
- e->setOrbits(orbits);
- e->setSymbol(symbol);
- e->setOxydation(oxydation);
- e->setAcidicbehaviour(acidicbehaviour);
- e->setIonisationList( ionlist );
- e->setIsotopeList( isolist );
-
- e->setMass( mass );
- e->setEN( en );
- e->setEA( ea );
- e->setMeltingpoint( mp );
- e->setBoilingpoint( bp );
- e->setDensity( density );
-
- e->setupXY();
-
- list.append( e );
- coordinate point; point.x = e->x; point.y = e->y;
- CoordinateList.append( point );
- }
-
- return list;
-}
-
-const int KalziumDataObject::numberOfElements() const
-{
- return m_numOfElements;
-}
-
-Isotope::Isotope( int neutrons, double percentage, double weight, double halflife, QString format, bool alphadecay, bool betaplusdecay, bool betaminusdecay, bool ecdecay, double decayenergy, QString spin, QString magmoment )
-{
- m_neutrons = neutrons;
- m_percentage = percentage;
- m_halflife = halflife;
- m_format = format;
- m_weight = weight;
- m_alphadecay = alphadecay;
- m_betaplusdecay = betaplusdecay;
- m_betaminusdecay = betaminusdecay;
- m_ecdecay = ecdecay;
- m_decayenergy = decayenergy;
- m_spin = spin;
- m_magmoment = magmoment;
-}
-
-QString Isotope::halflifeToHtml() const
-{
- QString halflife;
-
- if ( !seconds() )//years
- {
- if ( m_halflife > 1000000 )
- halflife = i18n("%1 million years").arg( m_halflife/1000000.0 );
- if ( m_halflife > 1000000000 )
- halflife = i18n("%1 billion years").arg( m_halflife/1000000000.0 );
- else
- halflife = i18n("%1 years").arg( m_halflife );
- }
- else
- {
- if ( m_halflife < 120 )
- halflife = i18n("%1 seconds").arg( m_halflife );
- else if ( m_halflife > 1000 )
- halflife = i18n("%1 minutes").arg( m_halflife/60.0 );
- else if ( m_halflife > 3600 )
- halflife = i18n("%1 hours").arg( m_halflife/( 60*60 ) );
- if ( m_halflife > 86400 ) //one day
- halflife = i18n("%1 days").arg( m_halflife/( 60*60*24 ) );
- if ( m_halflife > ( 31536000 * 2 ) ) //two year
- halflife = i18n("%1 years").arg( m_halflife/( 3600.0*365 ));
- }
-
- return halflife;
-}
class QPainter;
class QPoint;
class Spectrum;
+class Isotope;
struct coordinate;
typedef QValueList<coordinate> CList;
typedef QValueList<double> doubleList;
-/**
- * @author Carsten Niehaus
- * @author Jörg Buchwald
- *
- * This class represents an Isotope with all its properties
- */
-class Isotope
-{
- public:
- Isotope( int neutrons, double percentage, double weight, double halflife, QString format, bool alphadecay, bool betaplusdecay, bool betaminusdecay, bool ecdecay, double decayenergy, QString spin, QString magmoment);
-
- bool seconds() const{
- if ( m_format == "seconds" )
- return true;
- else
- return false;
- }
-
- /**
- * @return the halflife period of the isotope it if has one. The format
- * is defined by seconds()
- */
- double halflife() const{
- return m_halflife;
- }
-
- double percentage() const{
- return m_percentage;
- }
-
- /**
- * @return the number of neutrons the isotope has
- */
- int neutrons() const{
- return m_neutrons;
- }
-
- double weight() const{
- return m_weight;
- }
-
- bool alphadecay() const{
- return m_alphadecay;
- }
-
- bool betaplusdecay() const{
- return m_betaplusdecay;
- }
-
- bool betaminusdecay() const{
- return m_betaminusdecay;
- }
-
- bool ecdecay() const{
- return m_ecdecay;
- }
-
- double decayenergy() const{
- return m_decayenergy;
- }
-
- QString spin() const{
- return m_spin;
- }
-
- QString magmoment() const{
- return m_magmoment;
- }
-
- QString halflifeToHtml() const;
-
- private:
- /**
- * it is either "years" or "seconds". Usually we use seconds. But some
- * isotopes have half-lifes of billion of years. This simply
- * doesn't fit into a unsigned int or double
- */
- QString m_format;
-
- /**
- * the weight of the isotope
- */
- double m_weight;
-
- /**
- * the half-life of an isotope, usually in seconds
- * @see m_format
- */
- double m_halflife;
-
- /**
- * If 95.2% of the isotopes are of this type, this
- * variable will have the value 95.2
- */
- double m_percentage;
-
- /**
- * the number of neutrons
- */
- int m_neutrons;
-
- ///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;
-
- double m_decayenergy;
-
- /**
- *spin and parity
- */
- QString m_spin;
-
- /**
- * magnetic moment
- */
- QString m_magmoment;
-};
-
-/**
- * @short this class contains all Element-objects as
- * a QValueList<Element*>
- */
-class KalziumDataObject
-{
- public:
- KalziumDataObject();
- ~KalziumDataObject();
-
- /**
- * The list of element in a QValueList<Element*>
- */
- EList ElementList;
-
- CList CoordinateList;
-
- Element* element( int number );
-
- /**
- * @return the number of elements we have
- */
- const int numberOfElements() const;
-
- private:
- EList readData( QDomDocument &dataDocument );
-
- // caching the number of elements
- int m_numOfElements;
-};
-
struct coordinate{
int x;
int y;
--- /dev/null
+#ifndef ISOTOPE_H
+#define ISOTOPE_H
+
+#include <qstring.h>
+
+/**
+ * @author Carsten Niehaus
+ * @author Jörg Buchwald
+ *
+ * This class represents an Isotope with all its properties
+ */
+class Isotope
+{
+ public:
+ Isotope( int neutrons, double percentage, double weight, double halflife, QString format, bool alphadecay, bool betaplusdecay, bool betaminusdecay, bool ecdecay, double decayenergy, QString spin, QString magmoment);
+
+ bool seconds() const{
+ if ( m_format == "seconds" )
+ return true;
+ else
+ return false;
+ }
+
+ /**
+ * @return the halflife period of the isotope it if has one. The format
+ * is defined by seconds()
+ */
+ double halflife() const{
+ return m_halflife;
+ }
+
+ double percentage() const{
+ return m_percentage;
+ }
+
+ /**
+ * @return the number of neutrons the isotope has
+ */
+ int neutrons() const{
+ return m_neutrons;
+ }
+
+ double weight() const{
+ return m_weight;
+ }
+
+ bool alphadecay() const{
+ return m_alphadecay;
+ }
+
+ bool betaplusdecay() const{
+ return m_betaplusdecay;
+ }
+
+ bool betaminusdecay() const{
+ return m_betaminusdecay;
+ }
+
+ bool ecdecay() const{
+ return m_ecdecay;
+ }
+
+ double decayenergy() const{
+ return m_decayenergy;
+ }
+
+ QString spin() const{
+ return m_spin;
+ }
+
+ QString magmoment() const{
+ return m_magmoment;
+ }
+
+ QString halflifeToHtml();
+
+ private:
+ /**
+ * it is either "years" or "seconds". Usually we use seconds. But some
+ * isotopes have half-lifes of billion of years. This simply
+ * doesn't fit into a unsigned int or double
+ */
+ QString m_format;
+
+ /**
+ * the weight of the isotope
+ */
+ double m_weight;
+
+ /**
+ * the half-life of an isotope, usually in seconds
+ * @see m_format
+ */
+ double m_halflife;
+
+ /**
+ * If 95.2% of the isotopes are of this type, this
+ * variable will have the value 95.2
+ */
+ double m_percentage;
+
+ /**
+ * the number of neutrons
+ */
+ int m_neutrons;
+
+ ///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;
+
+ double m_decayenergy;
+
+ /**
+ *spin and parity
+ */
+ QString m_spin;
+
+ /**
+ * magnetic moment
+ */
+ QString m_magmoment;
+};
+
+#endif // ISOTOPE_H