]> Git trees. - libqmvoc.git/commitdiff
* Adding one more test file (works :) and making everything work, including the class...
authorCarsten Niehaus <cniehaus@gmx.de>
Wed, 7 Jun 2006 15:11:46 +0000 (15:11 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Wed, 7 Jun 2006 15:11:46 +0000 (15:11 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=549135

libscience/cmlclasses.cpp
libscience/cmlclasses.h
libscience/tests/2-propan-2-yloxypropane.cml [new file with mode: 0644]
libscience/tests/cml2test.cpp
libscience/xml_cml.cpp
libscience/xml_cml.h

index 7927a23bdb8b83441da8f912b9c8849b05362d93..77716734812ce9e425a2bcaf5cac233608f9f993 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         * 
  ***************************************************************************/
 #include "cmlclasses.h"
-#include <kdebug.h>
+
 using namespace CML;
 
-Molecule::Molecule()
+#include <QDebug>
+
+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()
index 33e0710b042eaf9d96dd70e7d2c70143ff9dee5e..ac76407b2137df0f7438a14c04a3eb5adb7ec412 100644 (file)
 
 namespace CML
 {
+
+class Atom;
+class Bond;
        
 class EDUSCIENCE_EXPORT Molecule
 {
        public:
                Molecule();
 
+               void setAtoms( QList<CML::Atom*> list ){
+                       m_atoms = list;
+               }
+
+               void setBonds( QList<CML::Bond*> list ){
+                       m_bonds = list;
+               }
+
+               void setID( const QString& id ){
+                       m_id = id;
+               }
+
+               QString debug();
+
+       private:
+               QList<CML::Atom*> m_atoms;
+               QList<CML::Bond*> 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 (file)
index 0000000..0358517
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0"?>
+<molecule xmlns="http://www.xml-cml.org/schema/cml2/core" id="2-Propan-2-yloxypropane">
+ <atomArray>
+  <atom id="a1" elementType="H" x3="-2.015900" y3="-0.043200" z3="-0.891400"/>
+  <atom id="a2" elementType="C" x3="-2.487000" y3="-0.089500" z3="-1.877800"/>
+  <atom id="a3" elementType="H" x3="-2.086500" y3="0.722700" z3="-2.492800"/>
+  <atom id="a4" elementType="H" x3="-2.178100" y3="-1.022200" z3="-2.357200"/>
+  <atom id="a5" elementType="C" x3="-4.007200" y3="0.002000" z3="-1.772300"/>
+  <atom id="a6" elementType="H" x3="-4.393900" y3="-0.852900" z3="-1.207900"/>
+  <atom id="a7" elementType="C" x3="-4.414600" y3="1.281600" z3="-1.055800"/>
+  <atom id="a8" elementType="H" x3="-4.007200" y3="1.320200" z3="-0.040900"/>
+  <atom id="a9" elementType="H" x3="-4.075100" y3="2.167200" z3="-1.602900"/>
+  <atom id="a10" elementType="H" x3="-5.504700" y3="1.353300" z3="-0.993200"/>
+  <atom id="a11" elementType="O" x3="-4.588300" y3="0.043500" z3="-3.090000"/>
+  <atom id="a12" elementType="C" x3="-4.971100" y3="-1.241800" z3="-3.616500"/>
+  <atom id="a13" elementType="H" x3="-4.344600" y3="-2.034000" z3="-3.193300"/>
+  <atom id="a14" elementType="C" x3="-6.439200" y3="-1.515700" z3="-3.299800"/>
+  <atom id="a15" elementType="H" x3="-6.608700" y3="-1.568400" z3="-2.221000"/>
+  <atom id="a16" elementType="H" x3="-7.078600" y3="-0.710400" z3="-3.675000"/>
+  <atom id="a17" elementType="H" x3="-6.772500" y3="-2.459700" z3="-3.741100"/>
+  <atom id="a18" elementType="C" x3="-4.750200" y3="-1.199300" z3="-5.121800"/>
+  <atom id="a19" elementType="H" x3="-5.334900" y3="-0.398200" z3="-5.585500"/>
+  <atom id="a20" elementType="H" x3="-3.700200" y3="-0.989300" z3="-5.347800"/>
+  <atom id="a21" elementType="H" x3="-5.022000" y3="-2.148100" z3="-5.594500"/>
+ </atomArray>
+ <bondArray>
+  <bond atomRefs2="a1 a2" order="1"/>
+  <bond atomRefs2="a2 a3" order="1"/>
+  <bond atomRefs2="a2 a4" order="1"/>
+  <bond atomRefs2="a2 a5" order="1"/>
+  <bond atomRefs2="a5 a6" order="1"/>
+  <bond atomRefs2="a5 a7" order="1"/>
+  <bond atomRefs2="a5 a11" order="1"/>
+  <bond atomRefs2="a7 a8" order="1"/>
+  <bond atomRefs2="a7 a9" order="1"/>
+  <bond atomRefs2="a7 a10" order="1"/>
+  <bond atomRefs2="a11 a12" order="1"/>
+  <bond atomRefs2="a12 a13" order="1"/>
+  <bond atomRefs2="a12 a14" order="1"/>
+  <bond atomRefs2="a12 a18" order="1"/>
+  <bond atomRefs2="a14 a15" order="1"/>
+  <bond atomRefs2="a14 a16" order="1"/>
+  <bond atomRefs2="a14 a17" order="1"/>
+  <bond atomRefs2="a18 a19" order="1"/>
+  <bond atomRefs2="a18 a20" order="1"/>
+  <bond atomRefs2="a18 a21" order="1"/>
+ </bondArray>
+</molecule>
index f76a68971ccfc55a184b85aae85ccb0dbeabf994..39be94a8330f629a05c8a272e2ce026535c24b4c 100644 (file)
@@ -28,17 +28,8 @@ int main(int argc, char *argv[])
        xmlReader.setContentHandler( handler );
        xmlReader.parse( source );
        
-       QList<CML::Atom*> parsedAtoms;
-       parsedAtoms = handler->getAtoms();
-       QList<CML::Bond*> 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;
 }
index 3b4a3f03f9a22b374f30f980f49bebee61870b9a..ea6c3c3c1215d3de4e392647a3ee3729e53ad232 100644 (file)
@@ -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;
        }
index 08bc5e067c8b08b8ec1c36794bab076f26fedb61..45e473f925627e0e8bc2dd1a1bdc830bddecd74e 100644 (file)
@@ -54,12 +54,18 @@ class EDUSCIENCE_EXPORT CMLParser : public QXmlDefaultHandler
                
                QList<CML::Atom*> getAtoms();
                QList<CML::Bond*> getBonds();
+               
+               CML::Molecule* getMolecule(){
+                       return tmp_molecule;
+               }
 
        private:
                QList<CML::Atom*> localAtoms;
                QList<CML::Bond*> localBonds;
                
                CML::Bond *tmp_bond;
+               
+               CML::Molecule *tmp_molecule;
 
                CML::Atom * tmp_atom;           
 };