isotope.cpp \
spectrumparser.cpp \
elementparser.cpp \
- tempunit.cpp
+ tempunit.cpp \
+ chemicaldataobject.cpp
libscience_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 4:0:0
libscience_la_LIBADD = $(LIB_KDEUI)
--- /dev/null
+/***************************************************************************
+ * 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 "chemicaldataobject.h"
+
+ChemicalDataObject::ChemicalDataObject( QVariant v, BlueObelisk type )
+{
+ m_value = v;
+ m_type = type;
+};
+
+ChemicalDataObject::ChemicalDataObject()
+{
+}
+
+QString ChemicalDataObject::valueAsString()
+{
+ return m_value.toString();
+}
--- /dev/null
+#ifndef CHEMICALDATAOBJECT_H
+#define CHEMICALDATAOBJECT_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. *
+ ***************************************************************************/
+
+#include <QVariant>
+#include <QString>
+
+/**
+ * A ChemicalDataObject is an object which contains information about
+ * a chemical element. This can for example be a boilingpoint. The information
+ * is stored in a QVariant.
+ * This class supports the CML-format defined by the BlueObelisk-Project.
+ *
+ * @author Carsten Niehaus <cniehaus@kde.org
+ */
+class ChemicalDataObject
+{
+ public:
+ /**
+ * The BlueObelisk-project defines in their xml-file the dataset
+ * with the names of the enum plus 'bo:'. So for symbol
+ * it is 'bo:symbol'. To avoid confusion I will choose the very
+ * same naming
+ */
+ enum BlueObelisk
+ {
+ atomicNumber = 0 /**< The atomic number of the element */,
+ symbol/**< the symbol of the element */,
+ name/**< The IUPAC-name of the element */,
+ mass/**< # IUPAC Official Masses */,
+ exactMass/**< exact masses of the most common isotopes for each element */,
+ ionization/**< First inizationenergy */,
+ electronAffinity/**< the electronaffinity of the element */,
+ electronegativityPauling/**< the electronegativity in the definition of Pauling*/,
+ radiusCovalent/**< the covalent radius */,
+ radiusVDW/**< the van der Waals radius */
+ };
+
+ /**
+ * public constructor
+ */
+ ChemicalDataObject();
+
+ /**
+ * public constructor
+ * @param v the data of the object
+ * @param type the type of the data
+ */
+ ChemicalDataObject(QVariant v,
+ BlueObelisk type);
+
+ /**
+ * set the data of this object to @p v
+ */
+ void setData( QVariant v ){
+ m_value = v;
+ }
+
+ /**
+ * public destructor
+ */
+ ~ChemicalDataObject();
+
+ /**
+ * Every ChemicalDataObject contains one data. For example a
+ * integer value which represents the boilingpoint. This method
+ * returns the value as a QString
+ *
+ * For bool, the returned string will be "false" or "true"
+ * For a QString, the QString will be returned
+ * For a int or double, the value will be returned as a QString
+ *
+ * @return the value as a QString.
+ */
+ QString valueAsString();
+
+ /**
+ * Every ChemicalDataObject contains one data. For example a
+ * integer value which represents the boilingpoint. This method
+ * returns the value as a QVariant
+ *
+ * @return the value as a QVariant.
+ */
+ QVariant value() const{
+ return m_value;
+ }
+
+ /**
+ * @return the type of dataset of this object
+ */
+ BlueObelisk type() const{
+ return m_type;
+ }
+
+ /**
+ * @param type the type of this object
+ */
+ void setType( BlueObelisk type ){
+ m_type = type;
+ }
+
+ /**
+ * @overload
+ */
+ void setType( int type ){
+ m_type = ( BlueObelisk ) type;
+ }
+
+ private:
+ QVariant m_value;
+ BlueObelisk m_type;
+};
+
+#endif // CHEMICALDATAOBJECT_H
#include "spectrum.h"
#include "isotope.h"
#include "tempunit.h"
+#include "chemicaldataobject.h"
#include <kdebug.h>
#include <klocale.h>
m_abundance = 0;
}
+QVariant Element::data(ChemicalDataObject::BlueObelisk type)
+{
+ foreach( ChemicalDataObject*o, dataList ) {
+ if ( o->type() == type )
+ return o->value();
+ }
+}
+
+QString Element::dataAsString(ChemicalDataObject::BlueObelisk type)
+{
+ foreach( ChemicalDataObject*o, dataList ) {
+ if ( o->type() == type )
+ return o->valueAsString();
+ }
+}
+
Isotope* Element::isotopeByNucleons( int numberOfNucleons )
{
QList<Isotope*>::ConstIterator it = m_isotopeList.begin();
return 0.0;
}
-
-ChemicalDataObject::ChemicalDataObject( QVariant v, BlueObelisk type )
-{
- m_value = v;
- m_type = type;
-};
-
-ChemicalDataObject::ChemicalDataObject()
-{
-}
-
-QString ChemicalDataObject::valueAsString()
-{
- return m_value.toString();
-}
#include <QList>
#include <QVariant>
-#include <kdemacros.h>
+#include "chemicaldataobject.h"
-class Element;
class QDomDocument;
class QPainter;
class QPoint;
class QFont;
class QRect;
+
class Spectrum;
class Isotope;
+class Element;
+class ChemicalDataObject;
struct coordinate;
return m_Color;
}
+ QList<ChemicalDataObject*> dataList;
+
+ void addData( ChemicalDataObject*o ){
+ dataList.append( o );
+ }
+
+ QVariant data( ChemicalDataObject::BlueObelisk type );
+
+ QString dataAsString( ChemicalDataObject::BlueObelisk type );
+
private:
/**
* the integer num represents the number of the element
doubleList m_ionenergies;
};
-/**
- * @author Carsten Niehaus <cniehaus@kde.org
- */
-class ChemicalDataObject
-{
- public:
- /**
- * The BlueObelisk-project defines in their xml-file the dataset
- * with the names of the enum plus 'bo:'. So for symbol
- * it is 'bo:symbol'. To avoid confusion I will choose the very
- * same naming
- */
- enum BlueObelisk
- {
- atomicNumber = 0 /**< The atomic number of the element */,
- symbol/**< the symbol of the element */,
- name/**< The IUPAC-name of the element */,
- mass/**< # IUPAC Official Masses */,
- exactMass/**< exact masses of the most common isotopes for each element */,
- ionization/**< First inizationenergy */,
- electronAffinity/**< the electronaffinity of the element */,
- electronegativityPauling/**< the electronegativity in the definition of Pauling*/,
- radiusCovalent/**< the covalent radius */,
- radiusVDW/**< the van der Waals radius */
- };
-
- /**
- * public constructor
- */
- ChemicalDataObject();
-
- /**
- * public constructor
- * @param v the data of the object
- * @param type the type of the data
- */
- ChemicalDataObject(QVariant v,
- BlueObelisk type);
-
- /**
- * set the data of this object to @p v
- */
- void setData( QVariant *v ){
- m_value = v;
- }
-
- /**
- * public destructor
- */
- ~ChemicalDataObject();
-
- /**
- * Every ChemicalDataObject contains one data. For example a
- * integer value which represents the boilingpoint. This method
- * returns the value as a QString
- *
- * For bool, the returned string will be "false" or "true"
- * For a QString, the QString will be returned
- * For a int or double, the value will be returned as a QString
- *
- * @return the value as a QString.
- */
- QString valueAsString();
-
- /**
- * Every ChemicalDataObject contains one data. For example a
- * integer value which represents the boilingpoint. This method
- * returns the value as a QVariant
- *
- * @return the value as a QVariant.
- */
- QVariant value() const{
- return m_value;
- }
-
- /**
- * @return the type of dataset of this object
- */
- BlueObelisk type() const{
- return m_type;
- }
-
- /**
- * @param type the type of this object
- */
- void setType( BlueObelisk type ){
- m_type = type;
- }
-
- /**
- * @overload
- */
- void setType( int type ){
- m_type = ( BlueObelisk ) type;
- }
-
- private:
- QVariant m_value;
- BlueObelisk m_type;
-};
-
#endif
inElement_(false),
inName_(false),
inMass_( false ),
+ inExactMass_( false ),
inAtomicNumber_(false),
inSymbol_( false )
{
inElement_ = true;
} else if (inElement_ && localName == "scalar") {
for (int i = 0; i < attrs.length(); ++i) {
+
if (attrs.value(i) == "bo:name")
inName_ = true;
+ if (attrs.value(i) == "bo:exactMass")
+ inExactMass_ = true;
if (attrs.value(i) == "bo:mass")
inMass_ = true;
if (attrs.value(i) == "bo:atomicNumber")
if ( localName == "elementType" )
{
elements_.append(currentElement_);
+//X if ( currentElement_ )
+//X kdDebug() << "Number of ChemicalDataObject: " << currentElement_->dataList.count() << endl;
currentElement_ = 0;
inElement_ = false;
}
bool ElementSaxParser::characters(const QString &ch)
{
+ ChemicalDataObject *dataobject = new ChemicalDataObject();
+ ChemicalDataObject::BlueObelisk type;
+ QVariant value;
+
if (inName_) {
- currentElement_->setName(ch);
+ value = ch;
+ type = ChemicalDataObject::name;
inName_ = false;
}
- if ( inMass_ ){
- currentElement_->setMass( ch.toDouble() );
+ else if ( inMass_ ){
+ value = ch.toDouble();
+ type = ChemicalDataObject::mass;
inMass_ = false;
}
- if (inSymbol_) {
- currentElement_->setSymbol(ch);
+ else if ( inExactMass_ ){
+ value = ch.toDouble();
+ type = ChemicalDataObject::exactMass;
+ inExactMass_ = false;
+ }
+ else if (inSymbol_) {
+ value = ch;
+ type = ChemicalDataObject::symbol;
inSymbol_ = false;
}
- if (inAtomicNumber_) {
- currentElement_->setNumber(ch.toInt());
+ else if (inAtomicNumber_) {
+ value = ch.toInt();
+ type = ChemicalDataObject::atomicNumber;
inAtomicNumber_ = false;
}
+ dataobject->setData( value );
+ dataobject->setType( type );
+
+//X kdDebug() << dataobject->valueAsString() << endl;
+
+ if ( currentElement_ )
+ currentElement_->addData( dataobject );
+
return true;
}
bool inElement_;
bool inName_,
inMass_,
+ inExactMass_,
inAtomicNumber_,
inSymbol_;
};
QFile xmlFile(argv[1]);
QXmlInputSource source(xmlFile);
QXmlSimpleReader reader;
+
reader.setContentHandler(parser);
reader.parse(source);
foreach( Element* e, v ){
if ( e )
- kdDebug() << "(" << e->number() << ", " <<
- e->elementName() << ", " << e->symbol() << ") " <<
- ", mass: " << e->mass() <<
- endl;
+ {
+ QList<ChemicalDataObject*> list = e->dataList;
+
+ //Give me the name of the element
+ kdDebug() << "Name: " << e->dataAsString( ChemicalDataObject::name ) << endl;
+
+//X //give me all you have
+//X foreach( ChemicalDataObject*o, list ){
+//X if ( o )
+//X kdDebug() << o->valueAsString() << endl;
+//X }
+ }
+
}
return 0;