From e64b6e39c14f4d68272feba67c0a1e153aa2f843 Mon Sep 17 00:00:00 2001 From: Etienne Rebetez Date: Wed, 9 Jun 2010 21:28:30 +0000 Subject: [PATCH] Added new pseTables Class in the science lib of kdeedu. Ported kalzium to new pse engine. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=1136448 --- libscience/CMakeLists.txt | 2 + libscience/psetables.cpp | 366 ++++++++++++++++++++++++++++++++++++++ libscience/psetables.h | 162 +++++++++++++++++ 3 files changed, 530 insertions(+) create mode 100644 libscience/psetables.cpp create mode 100644 libscience/psetables.h diff --git a/libscience/CMakeLists.txt b/libscience/CMakeLists.txt index c7771a3..885b2e0 100644 --- a/libscience/CMakeLists.txt +++ b/libscience/CMakeLists.txt @@ -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 index 0000000..580a5d9 --- /dev/null +++ b/libscience/psetables.cpp @@ -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 +#include + + +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 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 < +#include +#include + +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 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 elements() const; + + /** + * Returns the maximal Coordinates of the periodic table. + */ + virtual QPoint coordsMax() const; + +protected: + pseTable(); + + QString m_name; + QString m_description; + + QList m_posX; + QList m_posY; + QList 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 -- 2.47.3