]> Git trees. - libqmvoc.git/commitdiff
Added new pseTables Class in the science lib of kdeedu.
authorEtienne Rebetez <etienne.rebetez@oberwallis.ch>
Wed, 9 Jun 2010 21:28:30 +0000 (21:28 +0000)
committerEtienne Rebetez <etienne.rebetez@oberwallis.ch>
Wed, 9 Jun 2010 21:28:30 +0000 (21:28 +0000)
Ported kalzium to new pse engine.

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=1136448

libscience/CMakeLists.txt
libscience/psetables.cpp [new file with mode: 0644]
libscience/psetables.h [new file with mode: 0644]

index c7771a3418aeb8d7fb5c084b13a3cf8909db6e48..885b2e00f8a123e8555bbe0b1f8fcd783ecdfd05 100644 (file)
@@ -12,6 +12,7 @@ set(science_LIB_SRCS
    chemicaldataobject.cpp
    moleculeparser.cpp
    parser.cpp
+   psetables.cpp
 )
 
 
@@ -34,5 +35,6 @@ install(FILES
    spectrum.h
    spectrumparser.h
    tempunit.h
+   psetables.h
    DESTINATION ${INCLUDE_INSTALL_DIR}/libkdeedu  COMPONENT Devel
 )
diff --git a/libscience/psetables.cpp b/libscience/psetables.cpp
new file mode 100644 (file)
index 0000000..580a5d9
--- /dev/null
@@ -0,0 +1,366 @@
+/*********************************************************************************
+ *   Copyright (C) 2005, 2006   by Pino Toscano, toscano.pino@tiscali.it         *
+ *   Copyright (C) 2007         by Carste Niehaus, cniehaus@kde.org              *
+ *   copyright (C) 2010         by Etienne Rebetez, etienne.rebetez@oberwallis.ch*
+ *                                                                               *
+ *   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.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#include "psetables.h"
+
+#include <klocale.h>
+#include <kdebug.h>
+
+
+pseTables::pseTables()
+{
+    m_tables << pseRegularTable::init();
+    m_tables << pseShortTable::init();
+    m_tables << pseLongTable::init();
+    m_tables << pseDTable::init();
+    m_tables << pseDZTable::init();
+}
+
+pseTables::~pseTables()
+{
+}
+
+pseTables *pseTables::instance()
+{
+    static pseTables tables;
+    return &tables;
+}
+
+QStringList pseTables::tables() const
+{
+    QStringList l;
+    for ( int i = 0; i < m_tables.count(); i++ )
+    {
+        l << m_tables.at( i )->description();
+    }
+    return l;
+}
+
+pseTable* pseTables::getTabletype(const int tableType)
+{
+    if ( ( tableType < 0 ) || ( tableType >= m_tables.count() ) ) {
+        return 0;
+    }
+
+    return m_tables.at( tableType );
+}
+
+pseTable* pseTables::getTabletype(const QString tableName)
+{
+    for ( int i = 0; m_tables.count(); i++ ) {
+        if (tableName == m_tables.at( i )->name() ) {
+            return m_tables.at( i );
+        }
+    }
+    return 0;
+}
+
+
+
+pseTable::pseTable()
+{
+}
+
+pseTable::~pseTable()
+{
+}
+
+pseTable *pseTable::init()
+{
+    return 0;
+}
+
+QString pseTable::name() const
+{
+    return m_name;
+}
+
+QString pseTable::description() const
+{
+    return m_description;
+}
+
+QList<int> pseTable::elements() const
+{
+    return m_elementList;
+}
+
+QPoint pseTable::elementCoords(const int element)
+{
+    int elementIndex = m_elementList.indexOf( element );
+
+    if ( elementIndex >= 0 && elementIndex < m_elementList.count() ) {
+        return QPoint(m_posX.at( elementIndex ), m_posY.at( elementIndex ) );
+    }
+    return QPoint(0,0);
+}
+
+QPoint pseTable::coordsMax() const
+{
+    int x = 0, y = 0, i;
+
+    for(i = 0; i < m_posX.count(); i++) {
+        if (m_posX.at(i) > x) {
+            x = m_posX.at(i) ;
+        }
+        if (m_posY.at(i) > y) {
+            y = m_posY.at(i);
+        }
+    }
+    return QPoint(x, y);
+}
+
+/// Regular Table Data
+pseRegularTable::pseRegularTable()
+        : pseTable()
+{
+    m_name = "Classic";
+
+    m_description = i18n( "Classic Periodic Table" );
+
+    m_posX <<
+    1 <<                                                                                         18 <<
+    1 << 2 <<                                                      13 << 14 << 15 << 16 << 17 << 18 <<
+    1 << 2 <<                                                      13 << 14 << 15 << 16 << 17 << 18 <<
+    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18 <<
+    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18 << //Element 54 (Xe)
+    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 <<       //Element 58 (Ce) 71 (Lu)
+    4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18 <<
+    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 <<       //Element 71 (Lr)
+    4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18
+    ;
+
+    m_posY <<
+    1 <<                                                                                         1 <<
+    2 << 2 <<                                                      2 <<  2 <<  2 <<  2 <<  2 <<  2 <<
+    3 << 3 <<                                                      3 <<  3 <<  3 <<  3 <<  3 <<  3 <<
+    4 << 4 << 4 << 4 << 4 << 4 << 4 << 4 << 4 << 4 <<  4 <<  4 <<  4 <<  4 <<  4 <<  4 <<  4 <<  4 <<
+    5 << 5 << 5 << 5 << 5 << 5 << 5 << 5 << 5 << 5 <<  5 <<  5 <<  5 <<  5 <<  5 <<  5 <<  5 <<  5 << //Element 54 (Xe)
+    6 << 6 << 6 << 9 << 9 << 9 << 9 << 9 << 9 << 9 <<  9 <<  9 <<  9 <<  9 <<  9 <<  9 <<  9 <<          //Element 71 (Lr)
+    6 << 6 << 6 << 6 << 6 << 6 << 6 << 6 << 6 << 6 <<  6 <<  6 <<  6 <<  6 <<  6 <<
+    7 << 7 << 7 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 <<
+    7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7
+    ;
+
+    // The classic PS has all Elements
+    if (m_posX.count() == m_posY.count() ) {
+        for (int i =  1; i <= m_posX.count(); i ++) {
+            m_elementList.append(i);
+        }
+    }
+}
+
+pseRegularTable *pseRegularTable::init()
+{
+    static pseRegularTable thisTable;
+    return &thisTable;
+}
+
+/// Long Table Data
+pseLongTable::pseLongTable()
+        : pseTable()
+{
+    m_name = "Long";
+
+    m_description = i18n( "Long Periodic Table" );
+
+    m_posX <<
+    1 <<                                                                                                                                                      32 <<
+    1 << 2 <<                                                                                                                        27 <<28 <<29 <<30 <<31 <<32 <<
+    1 << 2 <<                                                                                                                        27 <<28 <<29 <<30 <<31 <<32 <<
+    1 << 2 <<                                                                      17 <<18 <<19 <<20 <<21 <<22 <<23 <<24 <<25 <<26 <<27 <<28 <<29 <<30 <<31 <<32 <<
+    1 << 2 <<                                                                      17 <<18 <<19 <<20 <<21 <<22 <<23 <<24 <<25 <<26 <<27 <<28 <<29 <<30 <<31 <<32 <<
+    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 <<10 <<11 <<12 <<13 <<14 <<15 <<16 <<17 <<18 <<19 <<20 <<21 <<22 <<23 <<24 <<25 <<26 <<27 <<28 <<29 <<30 <<31 <<32 <<
+    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 <<10 <<11 <<12 <<13 <<14 <<15 <<16 <<17 <<18 <<19 <<20 <<21 <<22 <<23 <<24 <<25 <<26 <<27 <<28 <<29 <<30 <<31 <<32
+    ;
+
+    m_posY <<
+    1 <<                                                                                                                                                      1 <<
+    2 << 2 <<                                                                                                                        2  <<2  <<2  <<2  <<2  <<2 <<
+    3 << 3 <<                                                                                                                        3  <<3  <<3  <<3  <<3  <<3 <<
+    4 << 4 <<                                                                      4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4 <<
+    5 << 5 <<                                                                      5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5 <<
+    6 << 6 << 6 << 6 << 6 << 6 << 6 << 6 << 6 <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6  <<6 <<
+    7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7  <<7
+    ;
+
+    // The long PS has all Elements
+    if (m_posX.count() == m_posY.count() ) {
+        for (int i =  1; i <= m_posX.count(); i ++) {
+            m_elementList.append(i);
+        }
+    }
+}
+
+pseLongTable *pseLongTable::init()
+{
+    static pseLongTable thisTable;
+    return &thisTable;
+}
+
+/// Short Table Data
+pseShortTable::pseShortTable()
+        : pseTable()
+{
+    m_name = "Short";
+
+    m_description = i18n( "Short Periodic Table" );
+
+    m_posX <<
+    1 <<                               8 <<//He
+    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 <<//Ne
+    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 <<//Ar
+    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 <<//Kr
+    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 <<//Xe
+    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 <<//Rn
+    1 << 2                  //Fr and Ra
+    ;
+
+    m_posY <<
+    1 <<                               1 <<//He
+    2 << 2 << 2 << 2 << 2 << 2 << 2 << 2 <<//Ne
+    3 << 3 << 3 << 3 << 3 << 3 << 3 << 3 <<//Ar
+    4 << 4 << 4 << 4 << 4 << 4 << 4 << 4 <<//Kr
+    5 << 5 << 5 << 5 << 5 << 5 << 5 << 5 <<//Xe
+    6 << 6 << 6 << 6 << 6 << 6 << 6 << 6 <<//Rn
+    7 << 7                   //Fr and Ra
+    ;
+
+    m_elementList <<
+    1 <<                               2 <<//He
+    3 << 4 << 5 << 6 << 7 << 8 << 9 << 10<<//Ne
+    11<< 12<< 13<< 14<< 15<< 16<< 17<< 18<<//Ar
+    19<< 20<< 31<< 32<< 33<< 34<< 35<< 36<<//Kr
+    37<< 38<< 49<< 50<< 51<< 52<< 53<< 54<<//Xe
+    55<< 56<< 81<< 82<< 83<< 84<< 85<< 86<<//Rn
+    87<< 88                   //Fr and Ra
+    ;
+}
+
+pseShortTable *pseShortTable::init()
+{
+    static pseShortTable thisTable;
+    return &thisTable;
+}
+
+/// D-Group Table Data
+pseDTable::pseDTable()
+        : pseTable()
+{
+    m_name = "D";
+
+    m_description = i18n( "Transition Elements" );
+
+    m_posX <<
+    1<< 2<< 3<< 4<< 5<< 6<< 7<< 8<< 9<< 10<<
+    1<< 2<< 3<< 4<< 5<< 6<< 7<< 8<< 9<< 10<<
+    1<< 2<< 3<< 4<< 5<< 6<< 7<< 8<< 9<< 10<<
+    1<< 2<< 3<< 4<< 5<< 6<< 7<< 8<< 9<< 10
+    ;
+
+    m_posY <<
+    1<< 1<< 1<< 1<< 1<< 1<< 1<< 1<< 1<< 1<<
+    2<< 2<< 2<< 2<< 2<< 2<< 2<< 2<< 2<< 2<<
+    3<< 3<< 3<< 3<< 3<< 3<< 3<< 3<< 3<< 3<<
+    4<< 4<< 4<< 4<< 4<< 4<< 4<< 4<< 4<< 4
+    ;
+
+    m_elementList <<
+    21 << 22 << 23 << 24 << 25 << 26 << 27 << 28 << 29 << 30 <<
+    39 << 40 << 41 << 42 << 43 << 44 << 45 << 46 << 47 << 48 <<
+    57 << 72 << 73 << 74 << 75 << 76 << 77 << 78 << 79 << 80 <<
+    89 << 104<< 105<< 106<< 107<< 108<< 109<< 110<< 111<< 112
+    ;
+}
+
+
+pseDTable *pseDTable::init()
+{
+    static pseDTable thisTable;
+    return &thisTable;
+}
+
+/// DZ Table Data
+pseDZTable::pseDZTable()
+: pseTable()
+{
+    m_name = "DZ";
+
+    m_description = i18n( "DZ Periodic Table" );
+
+    m_posX <<
+    1<< 2<<
+    2<< 2<<
+         3<< 4<< 5<< 6<< 7<< 8<<
+    1<< 2<<
+         3<< 4<< 5<< 6<< 7<< 8<<
+    1<< 2<<
+                           9<<10<<11<<12<<13<<14<<15<<16<<17<<18<<
+         3<< 4<< 5<< 6<< 7<< 8<<
+    1<< 2<<
+                           9<<10<<11<<12<<13<<14<<15<<16<<17<<18<<
+         3 <<4 <<5 <<6 <<7 <<8 <<
+    1<< 2<<
+                                                              19<<20<<21<<22<<23<<24<<25<<26<<27<<28<<29<<30<<31<<32<<
+                           9<<10<<11<<12<<13<<14<<15<<16<<17<<18<<
+         3 <<4 <<5 <<6 <<7 <<8 <<
+    1<< 2<<
+                                                              19<<20<<21<<22<<23<<24<<25<<26<<27<<28<<29<<30<<31<<32<<
+                           9<<10<<11<<12<<13<<14<<15<<16<<17<<18<<
+         3 <<4 <<5 <<6
+    ;
+
+    m_posY <<
+    1<< 1<<
+    2<< 2<<
+         3<< 3<< 3<< 3<< 3<< 3<<
+    4<< 4<<
+         5<< 5<< 5<< 5<< 5<< 5<<
+    6<< 6<<
+                          7<< 7<< 7<< 7<< 7<< 7<< 7<< 7<< 7<< 7<<
+         8<< 8<< 8<< 8<< 8<< 8<<
+    9<< 9<<
+                          10<<10<<10<<10<<10<<10<<10<<10<<10<<10<<
+         11<<11<<11<<11<<11<<11<<
+    12<<12<<
+                                                              13<<13<<13<<13<<13<<13<<13<<13<<13<<13<<13<<13<<13<<13<<
+                          14<<14<<14<<14<<14<<14<<14<<14<<14<<14<<
+         15<<15<<15<<15<<15<<15<<
+    16<<16<<
+                                                              17<<17<<17<<17<<17<<17<<17<<17<<17<<17<<17<<17<<17<<17<<
+                          18<<18<<18<<18<<18<<18<<18<<18<<18<<18<<
+         19<<19<<19<<19
+    ;
+
+    // The DZ PS has all Elements
+    if (m_posX.count() == m_posY.count() ) {
+        for (int i =  1; i <= m_posX.count(); i ++) {
+            m_elementList.append(i);
+        }
+    }
+
+}
+
+pseDZTable *pseDZTable::init()
+{
+    static pseDZTable thisTable;
+    return &thisTable;
+}
\ No newline at end of file
diff --git a/libscience/psetables.h b/libscience/psetables.h
new file mode 100644 (file)
index 0000000..7e49575
--- /dev/null
@@ -0,0 +1,162 @@
+/*********************************************************************************
+ *   Copyright (C) 2005, 2006   by Pino Toscano, toscano.pino@tiscali.it         *
+ *   Copyright (C) 2007         by Carste Niehaus, cniehaus@kde.org              *
+ *   copyright (C) 2010         by Etienne Rebetez, etienne.rebetez@oberwallis.ch*
+ *                                                                               *
+ *   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.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#ifndef PSETABLES_H
+#define PSETABLES_H
+
+#include "libkdeedu_science_export.h"
+
+#include <QPoint>
+#include <QList>
+#include <QStringList>
+
+class pseTable;
+
+/**
+ * Holds all periodic system tables and make them accesible.
+ */
+class SCIENCE_EXPORT pseTables
+{
+public:
+    static pseTables *instance();
+
+    ~pseTables();
+
+    /**
+    * Returns the KalziumTableType with the @p id specified.
+    * It will gives 0 if none found.
+    */
+    pseTable* getTabletype(const int tableType);
+
+    /**
+    * Returns the KalziumTableType whose name is the @p id
+    * specified.
+    * It will gives 0 if none found.
+    */
+    pseTable* getTabletype(const QString tableType);
+
+    /**
+     * Returns a list with the names of the table types we support.
+     */
+    QStringList tables() const;
+
+private:
+    pseTables();
+    QList<pseTable*> m_tables;
+    int m_currentTable;
+};
+
+
+/**
+ * defines a Periodic Table.
+ * Holds the position (x,y) and all the displaed elements
+ */
+class SCIENCE_EXPORT pseTable
+{
+public:
+    static pseTable *init();
+
+    virtual ~pseTable();
+
+    /**
+     * Returns the ID of this table type.
+     */
+    virtual QString name() const;
+
+    /**
+     * Returns a short description of the periodic table in use
+     */
+    virtual QString description() const;
+
+    /**
+     * Returns the coordinates of an element  @p element in
+     * the periodic system.
+     */
+    virtual QPoint elementCoords(int element);
+
+    /**
+     * Returns a list with all elements in the actual periodic table
+     */
+    virtual QList<int> elements() const;
+
+    /**
+     * Returns the maximal Coordinates of the periodic table.
+     */
+    virtual QPoint coordsMax() const;
+
+protected:
+    pseTable();
+
+    QString m_name;
+    QString m_description;
+
+    QList<int> m_posX;
+    QList<int> m_posY;
+    QList<int> m_elementList;
+};
+
+
+
+class pseRegularTable : public pseTable
+{
+public:
+    static pseRegularTable *init();
+
+private:
+    pseRegularTable();
+};
+
+class pseLongTable : public pseTable
+{
+public:
+    static pseLongTable *init();
+
+private:
+    pseLongTable();
+};
+
+class pseShortTable : public pseTable
+{
+public:
+    static pseShortTable *init();
+
+private:
+    pseShortTable();
+};
+
+class pseDTable : public pseTable
+{
+public:
+    static pseDTable *init();
+
+private:
+    pseDTable();
+};
+
+class pseDZTable : public pseTable
+{
+public:
+    static pseDZTable *init();
+
+private:
+    pseDZTable();
+};
+#endif // PSTABLES_H