summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/oxygen/.cvsignore3
-rw-r--r--noncore/apps/oxygen/TODO1
-rw-r--r--noncore/apps/oxygen/calcdlg.ui243
-rw-r--r--noncore/apps/oxygen/calcdlgui.cpp55
-rw-r--r--noncore/apps/oxygen/calcdlgui.h27
-rw-r--r--noncore/apps/oxygen/kmolcalc.cpp235
-rw-r--r--noncore/apps/oxygen/kmolcalc.h110
-rw-r--r--noncore/apps/oxygen/kmolelements.cpp238
-rw-r--r--noncore/apps/oxygen/kmolelements.h161
-rw-r--r--noncore/apps/oxygen/kmolweights107
-rw-r--r--noncore/apps/oxygen/main.cpp21
-rw-r--r--noncore/apps/oxygen/opie-oxygen.control9
-rw-r--r--noncore/apps/oxygen/oxygen.cpp53
-rw-r--r--noncore/apps/oxygen/oxygen.h22
-rw-r--r--noncore/apps/oxygen/oxygen.pro20
15 files changed, 1305 insertions, 0 deletions
diff --git a/noncore/apps/oxygen/.cvsignore b/noncore/apps/oxygen/.cvsignore
new file mode 100644
index 0000000..2c33e73
--- a/dev/null
+++ b/noncore/apps/oxygen/.cvsignore
@@ -0,0 +1,3 @@
1moc_*
2*.moc
3Makefile*
diff --git a/noncore/apps/oxygen/TODO b/noncore/apps/oxygen/TODO
new file mode 100644
index 0000000..bc60bf4
--- a/dev/null
+++ b/noncore/apps/oxygen/TODO
@@ -0,0 +1 @@
TODO:
diff --git a/noncore/apps/oxygen/calcdlg.ui b/noncore/apps/oxygen/calcdlg.ui
new file mode 100644
index 0000000..e0b19f9
--- a/dev/null
+++ b/noncore/apps/oxygen/calcdlg.ui
@@ -0,0 +1,243 @@
1<!DOCTYPE UI><UI>
2<class>CalcDlg</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>CalcDlg</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>218</width>
15 <height>274</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Network Time</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <widget>
29 <class>QTabWidget</class>
30 <property stdset="1">
31 <name>name</name>
32 <cstring>TabWidgetMain</cstring>
33 </property>
34 <property stdset="1">
35 <name>geometry</name>
36 <rect>
37 <x>10</x>
38 <y>0</y>
39 <width>200</width>
40 <height>260</height>
41 </rect>
42 </property>
43 <property>
44 <name>layoutMargin</name>
45 </property>
46 <property>
47 <name>layoutSpacing</name>
48 </property>
49 <widget>
50 <class>QWidget</class>
51 <property stdset="1">
52 <name>name</name>
53 <cstring>tabMain</cstring>
54 </property>
55 <attribute>
56 <name>title</name>
57 <string>Molweight</string>
58 </attribute>
59 <widget>
60 <class>QFrame</class>
61 <property stdset="1">
62 <name>name</name>
63 <cstring>FrameSystemTime</cstring>
64 </property>
65 <property stdset="1">
66 <name>geometry</name>
67 <rect>
68 <x>2</x>
69 <y>2</y>
70 <width>180</width>
71 <height>220</height>
72 </rect>
73 </property>
74 <property stdset="1">
75 <name>frameShape</name>
76 <enum>StyledPanel</enum>
77 </property>
78 <property stdset="1">
79 <name>frameShadow</name>
80 <enum>Raised</enum>
81 </property>
82 <widget>
83 <class>QLabel</class>
84 <property stdset="1">
85 <name>name</name>
86 <cstring>TextLabel1_4</cstring>
87 </property>
88 <property stdset="1">
89 <name>geometry</name>
90 <rect>
91 <x>1</x>
92 <y>1</y>
93 <width>298</width>
94 <height>16</height>
95 </rect>
96 </property>
97 <property stdset="1">
98 <name>text</name>
99 <string>Formula:</string>
100 </property>
101 </widget>
102 <widget>
103 <class>QLayoutWidget</class>
104 <property stdset="1">
105 <name>name</name>
106 <cstring>Layout7</cstring>
107 </property>
108 <property stdset="1">
109 <name>geometry</name>
110 <rect>
111 <x>0</x>
112 <y>50</y>
113 <width>175</width>
114 <height>30</height>
115 </rect>
116 </property>
117 <hbox>
118 <property stdset="1">
119 <name>margin</name>
120 <number>0</number>
121 </property>
122 <property stdset="1">
123 <name>spacing</name>
124 <number>6</number>
125 </property>
126 <widget>
127 <class>QPushButton</class>
128 <property stdset="1">
129 <name>name</name>
130 <cstring>calculate</cstring>
131 </property>
132 <property stdset="1">
133 <name>text</name>
134 <string>Calculate</string>
135 </property>
136 </widget>
137 <widget>
138 <class>QPushButton</class>
139 <property stdset="1">
140 <name>name</name>
141 <cstring>clear_fields</cstring>
142 </property>
143 <property stdset="1">
144 <name>text</name>
145 <string>Clear</string>
146 </property>
147 </widget>
148 </hbox>
149 </widget>
150 <widget>
151 <class>QLineEdit</class>
152 <property stdset="1">
153 <name>name</name>
154 <cstring>formula</cstring>
155 </property>
156 <property stdset="1">
157 <name>geometry</name>
158 <rect>
159 <x>0</x>
160 <y>20</y>
161 <width>170</width>
162 <height>22</height>
163 </rect>
164 </property>
165 </widget>
166 <widget>
167 <class>QMultiLineEdit</class>
168 <property stdset="1">
169 <name>name</name>
170 <cstring>anal_display</cstring>
171 </property>
172 <property stdset="1">
173 <name>geometry</name>
174 <rect>
175 <x>0</x>
176 <y>130</y>
177 <width>170</width>
178 <height>80</height>
179 </rect>
180 </property>
181 </widget>
182 <widget>
183 <class>QLineEdit</class>
184 <property stdset="1">
185 <name>name</name>
186 <cstring>result</cstring>
187 </property>
188 <property stdset="1">
189 <name>geometry</name>
190 <rect>
191 <x>0</x>
192 <y>100</y>
193 <width>170</width>
194 <height>22</height>
195 </rect>
196 </property>
197 </widget>
198 <widget>
199 <class>QLabel</class>
200 <property stdset="1">
201 <name>name</name>
202 <cstring>TextLabel2_4</cstring>
203 </property>
204 <property stdset="1">
205 <name>geometry</name>
206 <rect>
207 <x>1</x>
208 <y>86</y>
209 <width>298</width>
210 <height>16</height>
211 </rect>
212 </property>
213 <property stdset="1">
214 <name>text</name>
215 <string>Result:</string>
216 </property>
217 </widget>
218 </widget>
219 </widget>
220 <widget>
221 <class>QWidget</class>
222 <property stdset="1">
223 <name>name</name>
224 <cstring>tabNtp</cstring>
225 </property>
226 <attribute>
227 <name>title</name>
228 <string>Nernst</string>
229 </attribute>
230 <grid>
231 <property stdset="1">
232 <name>margin</name>
233 <number>1</number>
234 </property>
235 <property stdset="1">
236 <name>spacing</name>
237 <number>2</number>
238 </property>
239 </grid>
240 </widget>
241 </widget>
242</widget>
243</UI>
diff --git a/noncore/apps/oxygen/calcdlgui.cpp b/noncore/apps/oxygen/calcdlgui.cpp
new file mode 100644
index 0000000..e9b40d3
--- a/dev/null
+++ b/noncore/apps/oxygen/calcdlgui.cpp
@@ -0,0 +1,55 @@
1/***************************************************************************
2 * *
3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or *
6 * ( at your option ) any later version. *
7 * *
8 **************************************************************************/
9#include "oxygen.h"
10
11#include "calcdlgui.h"
12#include "kmolcalc.h"
13#include <qlineedit.h>
14#include <qmultilineedit.h>
15#include <qpushbutton.h>
16
17calcDlgUI::calcDlgUI() : CalcDlg()
18{
19 kmolcalc = new KMolCalc;
20 connect( calculate, SIGNAL( clicked() ), this, SLOT( calc() ) );
21 connect( clear_fields, SIGNAL( clicked() ), this, SLOT( clear() ) );
22}
23
24void calcDlgUI::calc()
25{
26 QString compound( formula->text() );
27 if ( compound.isEmpty() ) {
28 clear();
29 return;
30 }
31 QString errors( kmolcalc->readFormula( compound ) );
32 QString mw, ea;
33 double weight = kmolcalc->getWeight();
34 if ( errors == "OK" ) {
35 mw.setNum( weight );
36 ea = kmolcalc->getEmpFormula() + " :\n" + kmolcalc->getEA();
37 } else {
38 mw = "???";
39 ea = tr( "ERROR: \n" ) + errors + "\n";
40 }
41 result->setText( mw );
42 anal_display->setText( ea );
43}
44
45/**
46 * * Clear all text entry / result fields.
47 * */
48void calcDlgUI::clear()
49{
50 formula->clear();
51 result->clear();
52 anal_display->clear();
53}
54
55
diff --git a/noncore/apps/oxygen/calcdlgui.h b/noncore/apps/oxygen/calcdlgui.h
new file mode 100644
index 0000000..33a1ec1
--- a/dev/null
+++ b/noncore/apps/oxygen/calcdlgui.h
@@ -0,0 +1,27 @@
1
2/***************************************************************************
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * ( at your option ) any later version. *
8 * *
9 **************************************************************************/
10#include <qstring.h>
11#include "calcdlg.h"
12
13class QVBox;
14class KMolCalc;
15
16class calcDlgUI : public CalcDlg
17{
18 Q_OBJECT
19
20 public:
21 calcDlgUI();
22 KMolCalc *kmolcalc;
23
24 public slots:
25 void calc();
26 void clear();
27};
diff --git a/noncore/apps/oxygen/kmolcalc.cpp b/noncore/apps/oxygen/kmolcalc.cpp
new file mode 100644
index 0000000..7257c4a
--- a/dev/null
+++ b/noncore/apps/oxygen/kmolcalc.cpp
@@ -0,0 +1,235 @@
1/*
2 * kmolcalc.cpp
3 *
4 * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
5 * Copyright (C) 2002 Carsten Niehaus <cniehaus@handhelds.org>
6 */
7
8/**
9 * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic
10 * weights and group definitions ELSTABLE, and the currently processed formula, stored
11 * as a list of elements and their coefficients, ELEMENTS.
12 */
13
14#include "kmolcalc.h"
15#include <qdict.h>
16#include <qdir.h>
17#include <qfile.h>
18#include <iostream.h>
19
20
21/**
22 * Construct a new calculator object.
23 */
24KMolCalc::KMolCalc() {
25 elements = new ElementList;
26 elstable = NULL;
27 readElstable();
28}
29
30KMolCalc::~KMolCalc() {
31 delete elements;
32}
33
34void KMolCalc::readElstable() {
35 weight = -1; // not calculated yet
36 if (elstable) delete elstable;
37 elstable = new QDict<SubUnit> (197, TRUE);
38 elstable->setAutoDelete(TRUE);
39 QStringList files = "/home/opie/opie/noncore/apps/oxigen/kmolweights";
40 mwfile = "/home/opie/opie/noncore/apps/oxigen/kmolweights";
41 QFile f(mwfile);
42 QString* latest_f = &mwfile;
43 for (uint i=0; i<files.count(); i++) {
44 if (QFileInfo(QFile(files[i])).lastModified() > QFileInfo(QFile(*latest_f)).lastModified()) {
45 latest_f = &files[i];
46 }
47 }
48 QFile lf(*latest_f);
49 if (f.exists()) readMwfile(f);
50 if (!f.exists()) {
51 readMwfile(lf);
52 writeElstable();
53 } else if (QFileInfo(f).lastModified() < QFileInfo(lf).lastModified()) {
54 // announce
55 QMessageBox::information
56 (0, "Warning:", "Found new global Mw file.\nLocal definitions will be updated.", QMessageBox::Ok);
57 readMwfile(lf);
58 writeElstable();
59 }
60
61}
62
63
64/**
65 * Parse a string S and construct the ElementList this->ELEMENTS, representing the
66 * composition of S. Returns 0 if successful, or an error code (currently -1) if
67 * parsing failed.
68 * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE.
69 * See help files for correct formula syntax.
70 */
71QString KMolCalc::readFormula(const QString& s) {
72 weight = -1;
73 if (elements) delete elements;
74 elements = new ElementList;
75 return KMolCalc::readGroup(s, elements);
76}
77
78// read a formula group recursively. Called by readFormula.
79QString KMolCalc::readGroup(const QString& s, ElementList* els) {
80 if (s.isEmpty()) return QString ("Enter a formula."); //ERROR
81 int sl = s.length();
82 int i = 0;
83 QString errors ("OK");
84 bool ok = TRUE;
85 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
86 double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok));
87 if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR
88 ElementList* elstemp = new ElementList;
89 while (i < sl) {
90 int j = i;
91 if (s[i] == '(') {
92 ElementList* inner = new ElementList;
93 int level = 1; // count levels of nested ( ).
94 while (1) {
95 if (i++ == sl) {
96 delete inner;
97 delete elstemp;
98 return QString ("Bad formula."); //ERROR
99 }
100 if (s[i] == '(') level++;
101 if (s[i] == ')') level--;
102 if (level == 0) break;
103 }
104 errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner);
105 j = ++i;
106 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
107 double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok));
108 if (! ok || suffix == 0) {
109 delete inner;
110 delete elstemp;
111 return QString ("Bad formula."); // ERROR
112 }
113 inner->addTo(*elstemp, suffix);
114 delete inner;
115 inner = NULL;
116 } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) {
117 while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' ||
118 s[i] == '\''));
119 QString elname = s.mid(j, i-j);
120 j = i;
121 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
122 double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok));
123 if (! ok || suffix == 0) {
124 delete elstemp;
125 return QString ("Bad formula."); // ERROR
126 }
127 SubUnit* group = elstable->find(elname);
128 if (group == 0) {
129 delete elstemp;
130 return QString ("Undefined symbol: ") + elname; //ERROR
131 }
132 group->addTo(*elstemp, suffix);
133 } else if (s[i] == '+') {
134 if (elstemp->isEmpty()) {
135 delete elstemp;
136 return QString ("Bad formula."); //ERROR
137 }
138 elstemp->addTo(*els, prefix);
139 delete elstemp;
140 errors = KMolCalc::readGroup(s.mid(i+1, sl-i-1), els);
141 return errors;
142 } else {
143 delete elstemp;
144 return QString ("Bad formula."); //ERROR
145 }
146 }
147 elstemp->addTo(*els, prefix);
148 delete elstemp;
149 return errors;
150}
151
152/**
153 * Calculate and return the molecular weight of the current chemical formula.
154 */
155double KMolCalc::getWeight() {
156 if (weight == -1) weight = elements->getWeight(elstable);
157 return weight;
158}
159
160/**
161 * Return the elemental composition of the current formula, as a string of tab-separated
162 * element - percentage pairs, separated by newlines.
163 */
164QString KMolCalc::getEA() {
165 if (weight == -1) weight = elements->getWeight(elstable);
166 if (weight == -1) return QString("ERROR: Couldn't get Mw..."); // ERROR
167 return elements->getEA(elstable, weight);
168}
169
170/**
171 * Return the empirical formula of the current compound as a QString.
172 */
173QString KMolCalc::getEmpFormula() {
174 return elements->getEmpFormula();
175}
176
177// Read the element definition file.
178void KMolCalc::readMwfile(QFile& f) {
179 if (! f.open(IO_ReadOnly)) return; //ERROR
180 QTextStream fs (&f);
181 QString line;
182 while (! fs.eof()) {
183 line = fs.readLine();
184 SubUnit* s = SubUnit::makeSubUnit(line);
185 elstable->replace(s->getName(), s);
186 }
187 f.close();
188}
189
190/**
191 * Save the element definitions file.
192 */
193void KMolCalc::writeElstable() {
194 QFile f(mwfile);
195 if (! f.open(IO_WriteOnly)) return; //ERROR
196 QTextStream fs (&f);
197 QString line;
198 QDictIterator<SubUnit> it(*elstable);
199 while (it.current()) {
200 it.current()->writeOut(line);
201 fs << line << endl;
202 ++it;
203 }
204 f.close();
205}
206
207/**
208 * Remove a group or element definition from ELSTABLE.
209 */
210void KMolCalc::undefineGroup (const QString& name) {
211 elstable->remove (name);
212}
213
214/**
215 * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes
216 * NAME has valid syntax.
217
218 */
219void KMolCalc::defineElement (const QString& name, double weight) {
220 Element* el = new Element(name, weight);
221 elstable->replace(name, el);
222}
223
224/**
225 * Add a new group definition to the ELSTABLE. Returns 0 if OK, -1 if parsing FORMULA
226 * fails. Assumes the syntax of grpname is correct.
227 */
228QString KMolCalc::defineGroup (const QString& grpname, const QString& formula) {
229 ElementList* els = new ElementList(grpname);
230 QString error = readGroup(formula, els);
231 if (error != "OK") return error;
232 if (els->contains(grpname)) return QString("Can't define a group recursively!\n");
233 elstable->replace(grpname, els);
234 return QString("OK");
235}
diff --git a/noncore/apps/oxygen/kmolcalc.h b/noncore/apps/oxygen/kmolcalc.h
new file mode 100644
index 0000000..c3e02f3
--- a/dev/null
+++ b/noncore/apps/oxygen/kmolcalc.h
@@ -0,0 +1,110 @@
1/*
2 * kmolcalc.h
3 *
4 * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
5 */
6
7
8#ifndef KMOLCALC_H
9#define KMOLCALC_H
10
11#ifdef HAVE_CONFIG_H
12#include <config.h>
13#endif
14
15
16#include "kmolelements.h"
17#include <qdict.h>
18#include <qlist.h>
19#include <qstring.h>
20#include <qfile.h>
21#include <qfileinfo.h>
22#include <qmessagebox.h>
23#include <qtextstream.h>
24
25
26/**
27 * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic
28 * weights and group definitions ELSTABLE, and the currently processed formula, stored
29 * as a list of elements and their coefficients, ELEMENTS.
30 */
31class KMolCalc {
32
33public:
34
35 KMolCalc();
36 ~KMolCalc();
37
38 /**
39 * Parse a string S and construct the ElementList ELEMENTS, representing the composition
40 * of S. Returns "OK" if successful, or an error message if parsing failed.
41 * The elements is S must be valid element or group symbols, as stored in ELSTABLE.
42 * See help files for correct formula syntax.
43 */
44 QString readFormula(const QString& s);
45
46 /**
47 * Calculate and return the molecular weight of the current chemical formula.
48 */
49 double getWeight();
50
51 /**
52 * Return the elemental composition of the current formula, as a string of tab-separated
53 * element - percentage pairs, separated by newlines.
54 */
55 QString getEA();
56
57
58 /**
59 * Return the empirical formula of the current compound as a QString.
60 */
61 QString getEmpFormula();
62
63 /**
64 * Add a new element name - atomic weight record to the ELSTABLE hashtable.
65 * Assumes NAME has valid syntax.
66 */
67 void defineElement(const QString& name, double weight);
68
69 /**
70 * Add a new group definition to the ELSTABLE. Returns "OK" if OK, error message
71 * if parsing FORMULA fails. Assumes the syntax of NAME is correct.
72 */
73 QString defineGroup(const QString& name, const QString& formula);
74
75 /**
76 * Remove a group or element definition from ELSTABLE.
77 */
78 void undefineGroup(const QString& name);
79
80 /**
81 * Save the element definitions file.
82 */
83 void writeElstable();
84
85 /**
86 * Read the element definitions file and construct ELSTABLE.
87 */
88 void readElstable();
89
90 /**
91 * The element dictionary.
92 */
93 QDict<SubUnit>* elstable;
94
95 QString mwfile;
96
97 private:
98 double weight;
99
100 QString readGroup(const QString& s, ElementList* els);
101 void readMwfile(QFile& f);
102 ElementList* elements;
103};
104
105#endif
106
107
108
109
110
diff --git a/noncore/apps/oxygen/kmolelements.cpp b/noncore/apps/oxygen/kmolelements.cpp
new file mode 100644
index 0000000..ce8f9c1
--- a/dev/null
+++ b/noncore/apps/oxygen/kmolelements.cpp
@@ -0,0 +1,238 @@
1/*
2 * kmolelements.cpp
3 *
4 * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
5 */
6
7// classes that store and manipulate chemical formulas represented as
8// lists of elements
9
10#include <stdio.h>
11#include "kmolelements.h"
12
13/**
14 * A generic chemical entity. Can be an element or a group.
15 */
16SubUnit::SubUnit () {}
17
18SubUnit::~SubUnit () {}
19
20/**
21 * Construct a subunit and return a pointer to it. The syntax of LINE is
22 * the one used in the element definition file.
23 */
24SubUnit* SubUnit::makeSubUnit(QString line) {
25 QString name, grpname, weight, coef;
26 QTextStream str (line, IO_ReadOnly);
27 str >> name;
28 if (name != "-group") { // not a group - must be represented as Element
29 str >> weight >> ws;
30 return new Element(name, weight.toDouble());
31 }
32 else {
33 str >> grpname;
34 ElementList* els = new ElementList(grpname); // group - make an ElementList
35 while (!str.eof()) {
36 str >> name >> ws;
37 str >> coef >> ws;
38 els->addElement(name, coef.toDouble());
39 }
40 return els;
41 }
42}
43
44QString SubUnit::getName() const {
45 return QString("None");
46}
47
48/**
49 * Get the molecular weight of THIS, based on the data from ELSTABLE.
50 */
51double SubUnit::getWeight(QDict<SubUnit>* elstable) const {
52 return -1;
53}
54
55/**
56 * A group of elements.
57 */
58ElementList::ElementList () {
59 elements = new QList<ElementCoef>;
60}
61
62ElementList::~ElementList () {
63 delete elements;
64}
65
66
67/**
68 * A group of elements.
69 */
70ElementList::ElementList (QString name) {
71 this->name = name;
72 elements = new QList<ElementCoef>;
73}
74
75/**
76 * Write THIS to LINE, in a format suitable for the element definition file.
77 */
78void ElementList::writeOut(QString& line) {
79 QString coef;
80 line = "-group " + name;
81 ElementCoef* current = elements->first();
82 while (current != 0) {
83 line += " " + current->name + " " + coef.setNum(current->coef, 'g', 10);
84 // precision set to 10 digits
85 current = elements->next();
86 }
87}
88
89/**
90 * Get the molecular weight of THIS, based on the data from ELSTABLE.
91 */
92double ElementList::getWeight(QDict<SubUnit>* elstable) const {
93 double weight = 0;
94 ElementCoef* current = elements->first();
95 while (current != 0) {
96 SubUnit* e = elstable->find(current->name);
97 if (e != 0) {
98 weight += (current->coef) * (e->getWeight(elstable));
99 } else return -1; //ERROR
100 current = elements->next();
101 }
102 return weight;
103}
104
105/**
106 * Return a string representing the elemental composition of THIS, as
107 * a tab-separated element - percentage pairs, separated by newlines.
108 */
109QString ElementList::getEA(QDict<SubUnit>* elstable, double mw) const {
110 if (mw == 0) mw = getWeight(elstable);
111 QString ea;
112 QString temp;
113 ElementCoef* current = elements->first();
114 while (current != 0) {
115 SubUnit* e = elstable->find(current->name);
116 if (e != 0) {
117 double current_percent = 100 * (current->coef) *
118 (e->getWeight(elstable))
119 / mw;
120 ea += current->name + "\t" +
121 temp.setNum(current_percent) + "\n";
122 } else return QString("ERROR!\n"); //ERROR
123 current = elements->next();
124 }
125 return ea;
126}
127
128/**
129 * Return a string representing THIS as an empirical chemical formula.
130 */
131QString ElementList::getEmpFormula() const {
132 QString ef;
133 QString temp;
134 ElementCoef* current = elements->first();
135 while (current != 0) {
136 ef += current->name + temp.setNum(current->coef);
137 current = elements->next();
138 }
139 return ef;
140}
141
142/**
143 * Multiply THIS (i.e. the coefficient of each element) by coef.
144 */
145void ElementList::multiplyBy(double coef) {
146 ElementCoef* current = elements->first();
147 while (current != 0) {
148 (current->coef) *= coef;
149 current = elements->next();
150 }
151}
152
153/**
154 * Add THIS to ELS. THIS is not modified; ELS is.
155 */
156void ElementList::addTo(ElementList& els, double coef) {
157 ElementCoef* current = elements->first();
158 while (current != 0) {
159 els.addElement(current->name, (current->coef) * coef);
160 current = elements->next();
161 }
162}
163
164/**
165 * Add an element to THIS, with a coefficient COEF. If THIS already contains
166 * an element with the same name, adjust its coefficient only; if not, create
167 * a new ElementCoef pair and add to THIS.
168 */
169void ElementList::addElement(const QString& name, double coef) {
170 ElementCoef* current = elements->first();
171 while (current != 0) {
172 if (current->name == name) {
173 current->coef += coef;
174 return;
175 }
176 current = elements->next();
177 }
178 elements->append(new ElementCoef(name, coef));
179}
180
181/**
182 * True iff THIS contains element named NAME.
183 */
184bool ElementList::contains(const QString& name) {
185 ElementCoef* current = elements->first();
186 while (current != 0) {
187 if (current->name == name)
188 return true;
189 current = elements->next();
190 }
191 return false;
192}
193
194bool ElementList::isEmpty() {
195 return elements->isEmpty();
196}
197
198QString ElementList::getName() const {
199 return name;
200}
201
202/**
203 * A chemical element.
204 */
205Element::Element(const QString& n, double w)
206 : weight(w), name(n) { }
207
208
209Element::~Element() {
210}
211
212
213/**
214 * Write THIS to LINE, in a format suitable for the element definition file.
215 */
216void Element::writeOut(QString& line) {
217 line.setNum(weight);
218 line = name + " " + line;
219}
220
221double Element::getWeight(QDict<SubUnit>* elstable) const {
222 return weight;
223}
224
225void Element::addTo(ElementList& els, double coef) {
226 els.addElement(name, coef);
227}
228
229QString Element::getName() const {
230 return name;
231}
232
233/**
234 * An element - coefficient pair. Used to represent elements within an
235 * element list.
236 */
237ElementCoef::ElementCoef(const QString& n, double c) : name(n), coef(c) {}
238
diff --git a/noncore/apps/oxygen/kmolelements.h b/noncore/apps/oxygen/kmolelements.h
new file mode 100644
index 0000000..06d1469
--- a/dev/null
+++ b/noncore/apps/oxygen/kmolelements.h
@@ -0,0 +1,161 @@
1/*
2 * kmolelements.h
3 *
4 * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
5 */
6
7// classes that store and manipulate chemical formulas represented as
8// lists of elements
9
10#ifndef KMOLELEMENTS_H
11#define KMOLELEMENTS_H
12
13
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18
19#include <qlist.h>
20#include <qdict.h>
21#include <qstring.h>
22#include <qtextstream.h>
23
24class ElementCoef;
25class ElementList;
26
27/**
28 * A generic chemical entity. Can be an element or a group.
29 */
30class SubUnit {
31 public:
32
33 SubUnit();
34
35 virtual ~SubUnit();
36
37 /**
38 * Construct a subunit and return a pointer to it. The syntax of LINE is
39 * the one used in the element definition file.
40 */
41 static SubUnit* makeSubUnit(QString line);
42
43 /**
44 * Get the molecular weight of THIS, based on the data from ELSTABLE.
45 */
46 virtual double getWeight(QDict<SubUnit>* elstable) const;
47
48 /**
49 * Add THIS to ELS.
50 */
51 virtual void addTo(ElementList& els, double coef) = 0;
52
53 virtual QString getName() const;
54
55 /**
56 * Write THIS to LINE, in the format used in the definition file.
57 */
58 virtual void writeOut(QString& line) = 0;
59};
60
61
62/**
63 * A group of elements.
64 */
65class ElementList : public SubUnit {
66 public:
67 ElementList ();
68 ElementList (QString name);
69 virtual ~ElementList();
70 double getWeight(QDict<SubUnit>* elstable) const;
71
72 /**
73 * Return a string representing the elemental composition of THIS, as
74 * a tab-separated element - percentage pairs, separated by newlines.
75 */
76 QString getEA(QDict<SubUnit>* elstable, double mw = 0) const;
77
78 /**
79 * Return a string representing THIS as an empirical chemical formula.
80 */
81 QString getEmpFormula() const;
82
83 /**
84 * Multiply THIS (i.e. the coefficient of each element) by coef.
85 */
86 void multiplyBy(double coef);
87
88 /**
89 * Add THIS to ELS. THIS is not modified; ELS is.
90 */
91 void addTo(ElementList& els, double coef);
92
93 /**
94 * Add an element to THIS, with a coefficient COEF.
95 */
96 void addElement(const QString& name, double coef);
97
98 /**
99 * True iff THIS contains element named NAME.
100 */
101 bool contains(const QString& name);
102
103
104 bool isEmpty();
105
106 /**
107 * The name of THIS, as a chemical group.
108 */
109 QString getName() const;
110
111 /**
112 * Write THIS to LINE, in a format suitable for the element definition file.
113 */
114 void writeOut(QString& line);
115
116 private:
117 QString name;
118 QList<ElementCoef>* elements;
119};
120
121/**
122 * A chemical element.
123 */
124class Element : public SubUnit {
125 public:
126 Element(const QString& name, double weight);
127 virtual ~Element();
128 double getWeight(QDict<SubUnit>* elstable) const;
129
130 /**
131 * Add THIS to ELS, with a coefficient COEF.
132 */
133 void addTo(ElementList& els, double coef);
134
135 QString getName() const;
136
137 void writeOut(QString& line);
138
139 private:
140 double weight;
141 QString name;
142};
143
144
145/**
146 * An element - coefficient pair. Used to represent elements within an
147 * element list.
148 */
149class ElementCoef {
150 friend class ElementList;
151 public:
152 ElementCoef(const QString& name, double coef = 1.0);
153 private:
154 QString name;
155 double coef;
156};
157
158
159#endif
160
161
diff --git a/noncore/apps/oxygen/kmolweights b/noncore/apps/oxygen/kmolweights
new file mode 100644
index 0000000..82cbca0
--- a/dev/null
+++ b/noncore/apps/oxygen/kmolweights
@@ -0,0 +1,107 @@
1H 1.00794
2He 4.002602
3Li 6.941
4Be 9.012182
5B 10.811
6C 12.011
7N 14.00674
8O 15.9994
9F 18.9984032
10Ne 20.1797
11Na 22.989768
12Mg 24.3050
13Al 26.981539
14Si 28.0855
15P 30.973762
16S 32.066
17Cl 35.4527
18Ar 39.948
19K 39.0983
20Ca 40.078
21Sc 44.955910
22Ti 47.88
23V 50.9415
24Cr 51.9961
25Mn 54.93805
26Fe 55.847
27Co 58.93320
28Ni 58.6934
29Cu 63.546
30Zn 65.39
31Ga 69.723
32Ge 72.61
33As 74.92159
34Se 78.96
35Br 79.904
36Kr 83.80
37Rb 85.4678
38Sr 87.62
39Y 88.90585
40Zr 91.224
41Nb 92.90638
42Mo 95.94
43Tc 98.9063
44Ru 101.07
45Rh 102.90550
46Pd 106.42
47Ag 107.8682
48Cd 112.411
49In 114.82
50Sn 118.710
51Sb 121.757
52Te 127.60
53I 126.90447
54Xe 131.29
55Cs 132.90543
56Ba 137.327
57La 138.9055
58Ce 140.115
59Pr 140.90765
60Nd 144.24
61Pm 146.9151
62Sm 150.36
63Eu 151.965
64Gd 157.25
65Tb 158.92534
66Dy 162.50
67Ho 164.93032
68Er 167.26
69Tm 168.93421
70Yb 173.04
71Lu 174.967
72Hf 178.49
73Ta 180.9479
74W 183.85
75Re 186.207
76Os 190.2
77Ir 192.22
78Pt 195.08
79Au 196.96654
80Hg 200.59
81Tl 204.3833
82Pb 207.2
83Bi 208.98037
84Po 208.9824
85At 209.9871
86Rn 222.0176
87Fr 223.0197
88Ra 226.0254
89Ac 227.0278
90Th 232.0381
91Pa 231.03588
92U 238.0289
93Np 237.0482
94Pu 244.0642
95Am 243.0614
96Cm 247.0703
97Bk 247.0703
98Cf 251.0796
99Es 252.0829
100Fm 257.0951
101Md 258.0986
102No 259.1009
103Lr 260.1053
104Unq 261.1087
105Unp 262.1138
106Unh 263.1182
107Uns 262.1229
diff --git a/noncore/apps/oxygen/main.cpp b/noncore/apps/oxygen/main.cpp
new file mode 100644
index 0000000..328b61f
--- a/dev/null
+++ b/noncore/apps/oxygen/main.cpp
@@ -0,0 +1,21 @@
1/***************************************************************************
2 * *
3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or *
6 * ( at your option ) any later version. *
7 * *
8 * ***********************************************************************/
9
10
11#include <qpe/qpeapplication.h>
12#include "oxygen.h"
13
14int main(int argc, char **argv)
15{
16 QPEApplication app(argc, argv);
17 Oxygen *oxi = new Oxygen();
18 app.setMainWidget(oxi);
19 oxi->showMaximized();
20 return app.exec();
21}
diff --git a/noncore/apps/oxygen/opie-oxygen.control b/noncore/apps/oxygen/opie-oxygen.control
new file mode 100644
index 0000000..4f84158
--- a/dev/null
+++ b/noncore/apps/oxygen/opie-oxygen.control
@@ -0,0 +1,9 @@
1Files: bin/oxygen apps/Applications/oxygencheckbook.desktop pics/oxygen/oxygen.png
2Priority: optional
3Section: applications
4Maintainer: Carsten Niehaus <cniehaus@handhelds.org>
5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base ($QPE_VERSION)
8Description: Periodic System of the Elements
9 The chemistry application for the Opie-environment
diff --git a/noncore/apps/oxygen/oxygen.cpp b/noncore/apps/oxygen/oxygen.cpp
new file mode 100644
index 0000000..81897e9
--- a/dev/null
+++ b/noncore/apps/oxygen/oxygen.cpp
@@ -0,0 +1,53 @@
1/***************************************************************************
2 * *
3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or *
6 * ( at your option ) any later version. *
7 * *
8 * ***********************************************************************/
9#include "oxygen.h"
10
11#include <qmenubar.h>
12#include <qstatusbar.h>
13#include <qpopupmenu.h>
14#include <qlabel.h>
15#include <qapplication.h>
16#include <qpushbutton.h>
17#include <qfile.h>
18#include <qdir.h>
19#include <qvbox.h>
20#include "calcdlg.h"
21#include "calcdlgui.h"
22
23Oxygen::Oxygen()
24 : QMainWindow()
25{
26 this->setCaption( "Oxygen" );
27 vbox = new QVBox( this );
28 QPushButton *setButton = new QPushButton( "Settings", vbox );
29 connect ( setButton, SIGNAL( clicked() ), this, SLOT( slotSettings() ) );
30 QPushButton *calcButton = new QPushButton( "Calculations", vbox );
31 connect ( calcButton, SIGNAL( clicked() ), this, SLOT( slotCalculations() ) );
32 QPushButton *pseButton = new QPushButton( "PSE", vbox );
33 connect ( pseButton, SIGNAL( clicked() ), this, SLOT( slotPSE() ) );
34
35 setCentralWidget( vbox );
36}
37
38
39void Oxygen::close()
40{
41 QApplication::exit();
42}
43
44//SLOTS
45
46void Oxygen::slotCalculations(){
47 calcDlgUI *CalcDlgUI = new calcDlgUI();
48 CalcDlgUI->show();
49};
50
51void Oxygen::slotSettings(){ };
52void Oxygen::slotPSE(){ };
53
diff --git a/noncore/apps/oxygen/oxygen.h b/noncore/apps/oxygen/oxygen.h
new file mode 100644
index 0000000..1e923ee
--- a/dev/null
+++ b/noncore/apps/oxygen/oxygen.h
@@ -0,0 +1,22 @@
1
2#include <qpe/resource.h>
3#include <qmainwindow.h>
4#include <qtoolbar.h>
5#include <qstring.h>
6#include <qpopupmenu.h>
7
8class QVBox;
9
10class Oxygen : public QMainWindow
11{
12 Q_OBJECT
13
14 public:
15 Oxygen();
16 QVBox *vbox;
17 private slots:
18 void slotCalculations();
19 void slotSettings();
20 void slotPSE();
21 void close();
22};
diff --git a/noncore/apps/oxygen/oxygen.pro b/noncore/apps/oxygen/oxygen.pro
new file mode 100644
index 0000000..c5448e7
--- a/dev/null
+++ b/noncore/apps/oxygen/oxygen.pro
@@ -0,0 +1,20 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 HEADERS = oxygen.h \
4 kmolcalc.h \
5 kmolelements.h \
6 calcdlgui.h
7
8 SOURCES = main.cpp \
9 oxygen.cpp \
10 kmolcalc.cpp \
11 calcdlgui.cpp \
12 kmolelements.cpp
13INCLUDEPATH += $(OPIEDIR)/include
14DEPENDPATH += $(OPIEDIR)/include
15 LIBS += -lqpe
16 INTERFACES= calcdlg.ui
17 TARGET = oxygen
18 DESTDIR = $(OPIEDIR)/bin
19
20TRANSLATIONS = ../../../i18n/de/oxygen.ts