]> Git trees. - libqmvoc.git/commitdiff
Making reading of chemical datafiles work. I created a small OB-wrapper to hide the...
authorCarsten Niehaus <cniehaus@gmx.de>
Mon, 12 Jun 2006 13:23:30 +0000 (13:23 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Mon, 12 Jun 2006 13:23:30 +0000 (13:23 +0000)
svn path=/trunk/KDE/kdeedu/kalzium/src/openbabel2wrapper.cpp; revision=550626

kalzium/openbabel2wrapper.cpp [new file with mode: 0644]
kalzium/openbabel2wrapper.h [new file with mode: 0644]

diff --git a/kalzium/openbabel2wrapper.cpp b/kalzium/openbabel2wrapper.cpp
new file mode 100644 (file)
index 0000000..b0cb071
--- /dev/null
@@ -0,0 +1,57 @@
+/***************************************************************************
+    copyright            : (C) 2006 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 "openbabel2wrapper.h"
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <QMessageBox>
+
+#include <sstream>
+#include <stdio.h>
+#include <iostream>
+#include <fstream>
+#include <string.h>
+#include <malloc.h>
+
+
+#include <QString>
+#include <QMouseEvent>
+#include <QLayout>
+#include <QListWidget>
+#include <QMessageBox>
+
+
+OpenBabel::OBMol* OpenBabel2Wrapper::readMolecule( const QString& filename )
+{
+       OpenBabel::OBConversion Conv;
+       OpenBabel::OBFormat *inFormat = NULL;
+
+       //the OB2 Molecule
+       OpenBabel::OBMol *mol = new OpenBabel::OBMol;
+       ifstream inFileStream(  filename.toLatin1() );
+       if ( !inFileStream ) {
+               QMessageBox::warning(  0, i18n( "Problem while opening the file" ),
+                               i18n( "Cannot open the specified file." ) );
+               return 0;
+       }
+
+       //find out which format the file has...
+       inFormat = Conv.FormatFromExt( filename.toLatin1() );
+       Conv.SetInAndOutFormats( inFormat,inFormat );
+       Conv.Read( mol, &inFileStream );
+
+       kDebug() << QString::fromLatin1( mol->GetFormula().c_str() )  << " (Weight: " << mol->GetMolWt() << ", Title: "<< mol->GetTitle() << ")" << endl;
+
+       return mol;
+}
diff --git a/kalzium/openbabel2wrapper.h b/kalzium/openbabel2wrapper.h
new file mode 100644 (file)
index 0000000..06b108c
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef OPENBABEL2WRAPPER_H
+#define OPENBABEL2WRAPPER_H
+/***************************************************************************
+    copyright            : (C) 2006 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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+//includes for OpenBabel2
+#include <openbabel/obconversion.h>
+#include <openbabel/mol.h>
+
+#include <QString>
+
+/**
+ * @author Carsten Niehaus
+ */
+class OpenBabel2Wrapper
+{
+       public:
+               /**
+                * This class reads the molecule in the file @p filename. It returns 0 if
+                * the file couldn't be read.
+                */
+               static OpenBabel::OBMol* readMolecule( const QString& filename );
+};
+
+#endif // OPENBABEL2WRAPPER_H