From: Carsten Niehaus Date: Wed, 7 Jun 2006 15:11:46 +0000 (+0000) Subject: * Adding one more test file (works :) and making everything work, including the class... X-Git-Tag: v3.80.2~75 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=a92122141a17f0b7e63d94ef280618e041d5bccd;p=libqmvoc.git * Adding one more test file (works :) and making everything work, including the class Molecules svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=549135 --- diff --git a/libscience/cmlclasses.cpp b/libscience/cmlclasses.cpp index 7927a23..7771673 100644 --- a/libscience/cmlclasses.cpp +++ b/libscience/cmlclasses.cpp @@ -18,11 +18,20 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "cmlclasses.h" -#include + using namespace CML; -Molecule::Molecule() +#include + +Molecule::Molecule(){} + +QString Molecule::debug() { + qDebug() << "Molecule " << m_id; + foreach( CML::Atom* a, m_atoms ) + qDebug() << a->debug(); + foreach( CML::Bond* b, m_bonds ) + qDebug() << b->debug(); } Atom::Atom() diff --git a/libscience/cmlclasses.h b/libscience/cmlclasses.h index 33e0710..ac76407 100644 --- a/libscience/cmlclasses.h +++ b/libscience/cmlclasses.h @@ -27,12 +27,34 @@ namespace CML { + +class Atom; +class Bond; class EDUSCIENCE_EXPORT Molecule { public: Molecule(); + void setAtoms( QList list ){ + m_atoms = list; + } + + void setBonds( QList list ){ + m_bonds = list; + } + + void setID( const QString& id ){ + m_id = id; + } + + QString debug(); + + private: + QList m_atoms; + QList m_bonds; + + QString m_id; }; class EDUSCIENCE_EXPORT Atom diff --git a/libscience/tests/2-propan-2-yloxypropane.cml b/libscience/tests/2-propan-2-yloxypropane.cml new file mode 100644 index 0000000..0358517 --- /dev/null +++ b/libscience/tests/2-propan-2-yloxypropane.cml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libscience/tests/cml2test.cpp b/libscience/tests/cml2test.cpp index f76a689..39be94a 100644 --- a/libscience/tests/cml2test.cpp +++ b/libscience/tests/cml2test.cpp @@ -28,17 +28,8 @@ int main(int argc, char *argv[]) xmlReader.setContentHandler( handler ); xmlReader.parse( source ); - QList parsedAtoms; - parsedAtoms = handler->getAtoms(); - QList parsedBonds; - parsedBonds = handler->getBonds(); - - kDebug() << "Found " << parsedAtoms.count() << " Atoms and " << parsedBonds.count() << " Bonds!" << endl; - - foreach( CML::Atom* a, parsedAtoms ) - kDebug() << a->debug() << endl; - foreach( CML::Bond* b, parsedBonds ) - kDebug() << b->debug() << endl; + CML::Molecule * mol = handler->getMolecule(); + kDebug() << mol->debug() << endl; return 0; } diff --git a/libscience/xml_cml.cpp b/libscience/xml_cml.cpp index 3b4a3f0..ea6c3c3 100644 --- a/libscience/xml_cml.cpp +++ b/libscience/xml_cml.cpp @@ -32,7 +32,12 @@ bool CMLParser::startElement( const QString&, const QString&, const QString& qName, const QXmlAttributes& attr ) { - if ( qName.toUpper() == "ATOM" ) { + if ( qName.toUpper() == "MOLECULE" ) { + tmp_molecule = new CML::Molecule(); + + tmp_molecule->setID( attr.value( "id" ) ); + } + else if ( qName.toUpper() == "ATOM" ) { tmp_atom = new CML::Atom(); QString x2 = attr.value( "x2"); @@ -77,11 +82,15 @@ bool CMLParser::startElement( const QString&, const QString&, bool CMLParser::endElement( const QString&, const QString&, const QString& qName ) { - if ( qName.toUpper() == "ATOM" ) { + if ( qName.toUpper() == "MOLECULE" ) { + tmp_molecule->setAtoms( getAtoms() ); + tmp_molecule->setBonds( getBonds() ); + } + else if ( qName.toUpper() == "ATOM" ) { localAtoms.append( tmp_atom ); tmp_atom = 0; } - if ( qName.toUpper() == "BOND" ) { + else if ( qName.toUpper() == "BOND" ) { localBonds.append( tmp_bond ); tmp_bond = 0; } diff --git a/libscience/xml_cml.h b/libscience/xml_cml.h index 08bc5e0..45e473f 100644 --- a/libscience/xml_cml.h +++ b/libscience/xml_cml.h @@ -54,12 +54,18 @@ class EDUSCIENCE_EXPORT CMLParser : public QXmlDefaultHandler QList getAtoms(); QList getBonds(); + + CML::Molecule* getMolecule(){ + return tmp_molecule; + } private: QList localAtoms; QList localBonds; CML::Bond *tmp_bond; + + CML::Molecule *tmp_molecule; CML::Atom * tmp_atom; };