• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kalzium/libscience

  • sources
  • kde-4.12
  • kdeedu
  • kalzium
  • libscience
isotopeparser.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 copyright : (C) 2005-2008 by Carsten Niehaus
3 email : cniehaus@kde.org
4  ***************************************************************************/
5 /***************************************************************************
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  ***************************************************************************/
13 #include "isotopeparser.h"
14 
15 #include "chemicaldataobject.h"
16 #include "isotope.h"
17 #include <kunitconversion/converter.h>
18 #include <QDebug>
19 
20 
21 class IsotopeParser::Private
22 {
23 public:
24  Private()
25  : currentUnit(KUnitConversion::NoUnit),
26  currentErrorValue(QVariant()),
27  currentElementSymbol(QString()),
28  currentIsotope(0),
29  inIsotope(false),
30  inElement(false),
31  inAtomicNumber(false),
32  inExactMass(false),
33  inSpin(false),
34  inMagMoment(false),
35  inHalfLife(false),
36  inAlphaDecayLikeliness(false),
37  inAlphaDecay(false),
38  inBetaplusDecayLikeliness(false),
39  inBetaplusDecay(false),
40  inBetaminusDecayLikeliness(false),
41  inBetaminusDecay(false),
42  inECDecayLikeliness(false),
43  inECDecay(false),
44  inAbundance(false)
45  {
46  }
47 
48  ~Private(){
49  delete currentIsotope;
50  //qDeleteAll(isotopes);
51  }
52 
53  ChemicalDataObject currentDataObject;
54  int currentUnit;
55  QVariant currentErrorValue;
56  QString currentElementSymbol;
57  Isotope* currentIsotope;
58 
59  QList<Isotope*> isotopes;
60 
61  bool inIsotope;
62  bool inElement;
63  bool inAtomicNumber;
64  bool inExactMass;
65  bool inSpin;
66  bool inMagMoment;
67  bool inHalfLife;
68  bool inAlphaDecayLikeliness;
69  bool inAlphaDecay;
70  bool inBetaplusDecayLikeliness;
71  bool inBetaplusDecay;
72  bool inBetaminusDecayLikeliness;
73  bool inBetaminusDecay;
74  bool inECDecayLikeliness;
75  bool inECDecay;
76  bool inAbundance;
77 };
78 
79 IsotopeParser::IsotopeParser()
80  : QXmlDefaultHandler(), d( new Private )
81 {
82 }
83 
84 IsotopeParser::~IsotopeParser()
85 {
86  delete d;
87 }
88 
89 bool IsotopeParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs)
90 {
91  if (localName == "isotopeList")
92  {
93  d->inElement = true;
94 
95  //now save the symbol of the current element
96  for (int i = 0; i < attrs.length(); ++i)
97  {
98  if ( attrs.localName( i ) == "id" )
99  d->currentElementSymbol = attrs.value( i );
100 
101  }
102  } else if ( d->inElement && localName == "isotope")
103  {
104  d->currentIsotope = new Isotope();
105  d->currentIsotope->addData( ChemicalDataObject( QVariant( d->currentElementSymbol ), ChemicalDataObject::symbol ) );
106  d->inIsotope = true;
107  for (int i = 0; i < attrs.length(); ++i)
108  {
109  if ( attrs.localName( i ) == "number" )
110  {
111  d->currentIsotope->setNucleons( attrs.value( i ).toInt() );
112  }
113  }
114  } else if (d->inIsotope && localName == "scalar")
115  {
116  for (int i = 0; i < attrs.length(); ++i)
117  {
118  if ( attrs.localName( i ) == "errorValue" )
119  {
120  d->currentErrorValue = QVariant( attrs.value( i ) );
121  continue;
122  }
123 
124  if (attrs.value(i) == "bo:atomicNumber")
125  d->inAtomicNumber = true;
126  else if (attrs.value(i) == "bo:exactMass")
127  d->inExactMass = true;
128  else if (attrs.value(i) == "bo:halfLife"){
129  for (int i = 0; i < attrs.length(); ++i)
130  {
131  if (attrs.localName(i) == "units") {
132  if ( attrs.value(i) == "siUnits:s" ) {
133  d->currentUnit = KUnitConversion::Second;
134  } else if ( attrs.value(i) == "units:y" ) {
135  d->currentUnit = KUnitConversion::Year;
136  } else {
137  d->currentUnit = KUnitConversion::NoUnit;
138  }
139  }
140  }
141 
142  d->currentDataObject.setUnit( d->currentUnit );
143  d->inHalfLife = true;
144  }
145  else if (attrs.value(i) == "bo:alphaDecay")
146  d->inAlphaDecay = true;
147  else if (attrs.value(i) == "bo:alphaDecayLikeliness")
148  d->inAlphaDecayLikeliness = true;
149  else if (attrs.value(i) == "bo:ecDecay")
150  d->inECDecay = true;
151  else if (attrs.value(i) == "bo:ecDecayLikeliness")
152  d->inECDecayLikeliness = true;
153  else if (attrs.value(i) == "bo:betaminusDecay")
154  d->inBetaminusDecay = true;
155  else if (attrs.value(i) == "bo:betaminusDecayLikeliness")
156  d->inBetaminusDecayLikeliness = true;
157  else if (attrs.value(i) == "bo:betaplusDecay")
158  d->inBetaplusDecay = true;
159  else if (attrs.value(i) == "bo:betaplusDecayLikeliness")
160  d->inBetaplusDecayLikeliness = true;
161  else if (attrs.value(i) == "bo:spin")
162  d->inSpin = true;
163  else if (attrs.value(i) == "bo:magneticMoment")
164  d->inMagMoment = true;
165  else if (attrs.value(i) == "bo:relativeAbundance")
166  d->inAbundance = true;
167  }
168  }
169  return true;
170 }
171 
172 bool IsotopeParser::endElement( const QString&, const QString& localName, const QString& )
173 {
174  if ( localName == "isotope" )
175  {
176  d->isotopes.append(d->currentIsotope);
177 
178  d->currentIsotope = 0;
179  d->inIsotope = false;
180  }
181  else if ( localName == "isotopeList" )
182  {//a new list of isotopes start...
183  d->inElement = false;
184  }
185 
186  return true;
187 }
188 
189 bool IsotopeParser::characters(const QString &ch)
190 {
191  ChemicalDataObject::BlueObelisk type;
192  QVariant value;
193 
194  if (d->inExactMass){
195  value = ch.toDouble();
196  type = ChemicalDataObject::exactMass;
197  d->inExactMass = false;
198  }
199  else if (d->inAtomicNumber) {
200  value = ch.toInt();
201  type = ChemicalDataObject::atomicNumber;
202  d->inAtomicNumber = false;
203  }
204  else if (d->inSpin) {
205  value = ch;
206  type = ChemicalDataObject::spin;
207  d->inSpin = false;
208  }
209  else if (d->inMagMoment) {
210  value = ch;
211  type = ChemicalDataObject::magneticMoment;
212  d->inMagMoment = false;
213  }
214  else if (d->inHalfLife) {
215  value = ch.toDouble();
216  type = ChemicalDataObject::halfLife;
217  d->inHalfLife = false;
218  }
219  else if (d->inAlphaDecay) {
220  value = ch.toDouble();
221  type = ChemicalDataObject::alphaDecay;
222  d->inAlphaDecay = false;
223  }
224  else if (d->inAlphaDecayLikeliness) {
225  value = ch.toDouble();
226  type = ChemicalDataObject::alphaDecayLikeliness;
227  d->inAlphaDecayLikeliness = false;
228  }
229  else if (d->inBetaplusDecay) {
230  value = ch.toDouble();
231  type = ChemicalDataObject::betaplusDecay;
232  d->inBetaplusDecay = false;
233  }
234  else if (d->inBetaplusDecayLikeliness) {
235  value = ch.toDouble();
236  type = ChemicalDataObject::betaplusDecayLikeliness;
237  d->inBetaplusDecayLikeliness = false;
238  }
239  else if (d->inBetaminusDecay) {
240  value = ch.toDouble();
241  type = ChemicalDataObject::betaminusDecay;
242  d->inBetaminusDecay = false;
243  }
244  else if (d->inBetaminusDecayLikeliness) {
245  value = ch.toDouble();
246  type = ChemicalDataObject::betaminusDecayLikeliness;
247  d->inBetaminusDecayLikeliness = false;
248  }
249  else if (d->inECDecayLikeliness) {
250  value = ch.toDouble();
251  type = ChemicalDataObject::ecDecayLikeliness;
252  d->inECDecayLikeliness = false;
253  }
254  else if (d->inECDecay) {
255  value = ch.toDouble();
256  type = ChemicalDataObject::ecDecay;
257  d->inECDecay = false;
258  }
259  else if (d->inAbundance){
260  value = ch;
261  type = ChemicalDataObject::relativeAbundance;
262  d->inAbundance = false;
263  }
264  else//it is a non known value. Do not create a wrong object but return
265  return true;
266 
267  if ( type == ChemicalDataObject::exactMass )
268  {
269  d->currentDataObject.setErrorValue( d->currentErrorValue );
270  }
271 
272  d->currentDataObject.setData( value );
273  d->currentDataObject.setType( type );
274 
275  if ( d->currentIsotope )
276  {
277  d->currentIsotope->addData( d->currentDataObject );
278  }
279 
280  return true;
281 }
282 
283 QList<Isotope*> IsotopeParser::getIsotopes()
284 {
285  return d->isotopes;
286 }
IsotopeParser::getIsotopes
QList< Isotope * > getIsotopes()
Definition: isotopeparser.cpp:283
ChemicalDataObject::spin
The spin.
Definition: chemicaldataobject.h:73
isotopeparser.h
IsotopeParser::startElement
bool startElement(const QString &, const QString &localName, const QString &, const QXmlAttributes &attrs)
Definition: isotopeparser.cpp:89
Isotope
Definition: isotope.h:32
IsotopeParser::characters
bool characters(const QString &ch)
Definition: isotopeparser.cpp:189
isotope.h
ChemicalDataObject::alphaDecayLikeliness
The percentage of alphadecay.
Definition: chemicaldataobject.h:76
ChemicalDataObject::symbol
the symbol of the element
Definition: chemicaldataobject.h:50
ChemicalDataObject::ecDecay
The decayenergy of ecminusdecay in MeV.
Definition: chemicaldataobject.h:83
ChemicalDataObject::relativeAbundance
The abundance, relative to 100.
Definition: chemicaldataobject.h:72
ChemicalDataObject
A ChemicalDataObject is an object which contains information about a chemical element.
Definition: chemicaldataobject.h:38
chemicaldataobject.h
ChemicalDataObject::magneticMoment
The magnetic dipole moment.
Definition: chemicaldataobject.h:74
QXmlDefaultHandler
ChemicalDataObject::betaminusDecay
The decayenergy of betaminusdecay in MeV.
Definition: chemicaldataobject.h:81
ChemicalDataObject::BlueObelisk
BlueObelisk
The BlueObelisk-project defines in their XML file the dataset with the names of the enum plus "bo:"...
Definition: chemicaldataobject.h:47
ChemicalDataObject::betaplusDecayLikeliness
The percentage of betaplusdecay.
Definition: chemicaldataobject.h:78
ChemicalDataObject::halfLife
The halflife.
Definition: chemicaldataobject.h:75
ChemicalDataObject::alphaDecay
The decayenergy of alphadecay in MeV.
Definition: chemicaldataobject.h:77
IsotopeParser::~IsotopeParser
~IsotopeParser()
Definition: isotopeparser.cpp:84
ChemicalDataObject::atomicNumber
The atomic number of the element.
Definition: chemicaldataobject.h:49
ChemicalDataObject::ecDecayLikeliness
The percentage of ecdecay.
Definition: chemicaldataobject.h:82
ChemicalDataObject::exactMass
exact masses of the most common isotopes for each element
Definition: chemicaldataobject.h:53
IsotopeParser::IsotopeParser
IsotopeParser()
Constructor.
Definition: isotopeparser.cpp:79
ChemicalDataObject::betaminusDecayLikeliness
The percentage of betaminusdecay.
Definition: chemicaldataobject.h:80
IsotopeParser::endElement
bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
Definition: isotopeparser.cpp:172
ChemicalDataObject::betaplusDecay
The decayenergy of betaplusdecay in MeV.
Definition: chemicaldataobject.h:79
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:31 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalzium/libscience

Skip menu "kalzium/libscience"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal