]> Git trees. - libqmvoc.git/commitdiff
* First version of the IsotopeParser
authorCarsten Niehaus <cniehaus@gmx.de>
Mon, 24 Oct 2005 12:28:23 +0000 (12:28 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Mon, 24 Oct 2005 12:28:23 +0000 (12:28 +0000)
** Missing: errorValue-support

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=473670

libscience/Makefile.am
libscience/element.cpp
libscience/isotope.cpp
libscience/isotope.h
libscience/isotopeparser.cpp [new file with mode: 0644]
libscience/isotopeparser.h [new file with mode: 0644]

index a79ce232f57fcac6dfb6372f2d43575963d0208f..6e34644613eabc75dd867556b0542afb1ea6215c 100644 (file)
@@ -10,6 +10,7 @@ libscience_la_SOURCES = \
        isotope.cpp \
        spectrumparser.cpp \
        elementparser.cpp \
+       isotopeparser.cpp \
        tempunit.cpp \
        chemicaldataobject.cpp
 
index d67bde243d2415eb078e51d6124c5229e6f16ca3..4d4741483b04202fdb8d15b0df4eb9c064a39b25 100644 (file)
@@ -19,8 +19,6 @@
  ***************************************************************************/
 
 #include "element.h"
-#include "spectrum.h"
-#include "isotope.h"
 #include "tempunit.h"
 #include "chemicaldataobject.h"
 
index 40f5bab3ba1075e5b425b15886c4fc693e91b421..34d1b5689d692a955b4015ddd97cfb8dee9864a6 100644 (file)
@@ -37,3 +37,38 @@ Isotope::Isotope( ChemicalDataObject* mass,
 
 Isotope::~Isotope(){}
 
+
+ChemicalDataObject* Isotope::data() const
+{
+       return m_mass;
+}
+
+void Isotope::addData( ChemicalDataObject* o )
+{
+       if ( o->type() == ChemicalDataObject::exactMass )
+               m_mass = o;
+       else if ( o->type() == ChemicalDataObject::atomicNumber )
+               m_identifier = o;
+
+       return;
+}
+
+double Isotope::mass() const
+{
+       return m_mass->value().toDouble();
+}
+
+double Isotope::errorMargin() const
+{
+       return m_mass->errorValue().toDouble();
+}
+
+int Isotope::parentElementNumber() const
+{
+       return m_identifier->value().toInt();
+}
+
+QString Isotope::parentElementSymbol() const
+{
+       return m_parentElementSymbol;
+}
index 3213ed1694339bad39e5506adba01da9a8ceac43..a8cd963dcbed0c68956efaeba305142a0130e007 100644 (file)
@@ -36,13 +36,32 @@ class Isotope
                Isotope(ChemicalDataObject* mass, ChemicalDataObject* ID);
                virtual ~Isotope();
 
+               ChemicalDataObject* data() const;
+
+               double mass() const;
+
+               double errorMargin() const;
+
+               int parentElementNumber() const;
+
+               QString parentElementSymbol() const;
+
+               void addData( ChemicalDataObject* o );
+
        private:
                /**
                 * the symbol of the element the isotope belongs to
                 */
                QString m_parentElementSymbol;
                
+               /**
+                * stores the infomation about the mass of the Isotope
+                */
                ChemicalDataObject* m_mass;
+
+               /**
+                * stores the atomicNumber of the Isotope
+                */
                ChemicalDataObject* m_identifier;
 };
 
diff --git a/libscience/isotopeparser.cpp b/libscience/isotopeparser.cpp
new file mode 100644 (file)
index 0000000..ab23acd
--- /dev/null
@@ -0,0 +1,95 @@
+/***************************************************************************
+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 "isotopeparser.h"
+#include "isotope.h"
+
+#include <qdom.h>
+#include <QList>
+#include <QFile>
+#include <QStringList>
+
+#include <kdebug.h>
+
+IsotopeParser::IsotopeParser()
+       : QXmlDefaultHandler(), 
+       currentIsotope_(0), 
+       inAtomicNumber_(false),
+       inExactMass_(false)
+{
+}
+
+bool IsotopeParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs)
+{
+       if (localName == "isotope") 
+       {
+               currentIsotope_ = new Isotope();
+               inIsotope_ = true;
+       } else if (inIsotope_ && localName == "scalar") 
+       {
+               for (int i = 0; i < attrs.length(); ++i) 
+               {
+                       if (attrs.value(i) == "bo:atomicNumber")
+                               inAtomicNumber_ = true;
+                       else if (attrs.value(i) == "bo:exactMass")
+                               inExactMass_ = true;
+               }
+       }
+       return true;
+}
+               
+bool IsotopeParser::endElement (  const QString & namespaceURI, const QString & localName, const QString & qName )
+{
+       if ( localName == "isotope" )
+       {
+               isotopes_.append(currentIsotope_);
+               
+               currentIsotope_ = 0;
+               currentDataObject_ = 0;
+               inIsotope_ = false;
+       }
+
+       return true;
+}
+
+bool IsotopeParser::characters(const QString &ch)
+{
+       currentDataObject_ = new ChemicalDataObject();
+       ChemicalDataObject::BlueObelisk type;
+       QVariant value;
+
+       if ( inExactMass_ ){
+               value = ch.toDouble();
+               type = ChemicalDataObject::exactMass; 
+               inExactMass_ = false;
+       }
+       else if (inAtomicNumber_) {
+               value = ch.toInt();
+               type = ChemicalDataObject::atomicNumber; 
+               inAtomicNumber_ = false;
+       }
+       else//it is a non known value. Do not create a wrong object but return
+               return true;
+
+       currentDataObject_->setData( value );
+       currentDataObject_->setType( type );
+
+       if ( currentIsotope_ )
+               currentIsotope_->addData( currentDataObject_ );
+
+       return true;
+}
+
+QList<Isotope*> IsotopeParser::getIsotopes()
+{
+       return isotopes_;
+}
diff --git a/libscience/isotopeparser.h b/libscience/isotopeparser.h
new file mode 100644 (file)
index 0000000..c34b509
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef ISOTOPEPARSER_H
+#define ISOTOPEPARSER_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 <QList>
+
+#include <qxml.h>
+
+#include "chemicaldataobject.h"
+
+class Isotope;
+
+/**
+ * @author Carsten Niehaus <cniehaus@kde.org>
+ */
+class IsotopeParser : public QXmlDefaultHandler
+{
+       public:
+               /**
+                * Constructor
+                */
+               IsotopeParser();
+               bool startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs);
+
+               bool endElement (  const QString & namespaceURI, const QString & localName, const QString & qName );
+               
+               bool characters(const QString &ch);
+
+               QList<Isotope*> getIsotopes();
+
+       private:
+               ChemicalDataObject *currentDataObject_;
+               ChemicalDataObject::BlueObeliskUnit currentUnit_;
+               
+               Isotope* currentIsotope_;
+               QList<Isotope*> isotopes_;
+               bool inIsotope_;
+               bool inAtomicNumber_,
+                        inExactMass_;
+};
+#endif // ISOTOPEPARSER_H
+