~ubuntu-branches/ubuntu/precise/kalzium/precise

« back to all changes in this revision

Viewing changes to libscience/psetables.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Philip Muškovac
  • Date: 2011-07-03 12:28:58 UTC
  • Revision ID: james.westby@ubuntu.com-20110703122858-q1yyxncs89e4w0hs
Tags: upstream-4.6.90+repack
Import upstream version 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************************************
 
2
 *   Copyright (C) 2005, 2006   by Pino Toscano, toscano.pino@tiscali.it         *
 
3
 *   Copyright (C) 2007         by Carste Niehaus, cniehaus@kde.org              *
 
4
 *   copyright (C) 2010         by Etienne Rebetez, etienne.rebetez@oberwallis.ch*
 
5
 *                                                                               *
 
6
 *   This program is free software; you can redistribute it and/or modify  *
 
7
 *   it under the terms of the GNU General Public License as published by  *
 
8
 *   the Free Software Foundation; either version 2 of the License, or     *
 
9
 *   (at your option) any later version.                                   *
 
10
 *                                                                         *
 
11
 *   This program is distributed in the hope that it will be useful,       *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU General Public License for more details.                          *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU General Public License     *
 
17
 *   along with this program; if not, write to the                         *
 
18
 *   Free Software Foundation, Inc.,                                       *
 
19
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 
20
 ***************************************************************************/
 
21
 
 
22
#include "psetables.h"
 
23
 
 
24
#include <klocale.h>
 
25
#include <kdebug.h>
 
26
 
 
27
 
 
28
pseTables::pseTables()
 
29
{
 
30
    m_tables << pseRegularTable::init();
 
31
    m_tables << pseShortTable::init();
 
32
    m_tables << pseLongTable::init();
 
33
    m_tables << pseDTable::init();
 
34
    m_tables << pseDZTable::init();
 
35
}
 
36
 
 
37
pseTables::~pseTables()
 
38
{
 
39
}
 
40
 
 
41
pseTables *pseTables::instance()
 
42
{
 
43
    static pseTables tables;
 
44
    return &tables;
 
45
}
 
46
 
 
47
QStringList pseTables::tables() const
 
48
{
 
49
    QStringList l;
 
50
    for ( int i = 0; i < m_tables.count(); i++ )
 
51
    {
 
52
        l << m_tables.at( i )->description();
 
53
    }
 
54
    return l;
 
55
}
 
56
 
 
57
pseTable* pseTables::getTabletype(const int tableType)
 
58
{
 
59
    if ( ( tableType < 0 ) || ( tableType >= m_tables.count() ) ) {
 
60
        return 0;
 
61
    }
 
62
 
 
63
    return m_tables.at( tableType );
 
64
}
 
65
 
 
66
pseTable* pseTables::getTabletype(const QString tableName)
 
67
{
 
68
    for ( int i = 0; m_tables.count(); i++ ) {
 
69
        if (tableName == m_tables.at( i )->name() ) {
 
70
            return m_tables.at( i );
 
71
        }
 
72
    }
 
73
    return 0;
 
74
}
 
75
 
 
76
pseTable::pseTable()
 
77
{
 
78
}
 
79
 
 
80
pseTable::~pseTable()
 
81
{
 
82
}
 
83
 
 
84
pseTable *pseTable::init()
 
85
{
 
86
    return 0;
 
87
}
 
88
 
 
89
QString pseTable::name() const
 
90
{
 
91
    return m_name;
 
92
}
 
93
 
 
94
QString pseTable::description() const
 
95
{
 
96
    return m_description;
 
97
}
 
98
 
 
99
QList<int> pseTable::elements() const
 
100
{
 
101
    return m_elementList;
 
102
}
 
103
 
 
104
int pseTable::previousOf( int element ) const
 
105
{
 
106
    int index = m_elementList.indexOf( element );
 
107
    return index > 0 ? m_elementList.at( index - 1 ) : -1;
 
108
}
 
109
 
 
110
int pseTable::nextOf( int element ) const
 
111
{
 
112
    int index = m_elementList.indexOf( element );
 
113
    return index != -1 && ( index < m_elementList.count() - 1 ) ? m_elementList.at( index + 1 ) : -1;
 
114
}
 
115
 
 
116
int pseTable::firstElement() const
 
117
{
 
118
    return m_elementList.first();
 
119
}
 
120
 
 
121
int pseTable::lastElement() const
 
122
{
 
123
    return m_elementList.last();
 
124
}
 
125
 
 
126
QPoint pseTable::elementCoords(const int element) const
 
127
{
 
128
    int x = -1, y = -1;
 
129
    int elementIndex = m_elementList.indexOf( element );
 
130
 
 
131
    if ( elementIndex >= 0 && elementIndex < m_elementList.count() ) {
 
132
        // The positions lists are defined with the base of 1.
 
133
        // But coordinates start mostly with 0.
 
134
        x = m_posX.at( elementIndex ) - 1;
 
135
        y = m_posY.at( elementIndex ) - 1;
 
136
    }
 
137
    return QPoint(x, y);
 
138
}
 
139
 
 
140
QPoint pseTable::tableSize() const
 
141
{
 
142
    int x = 0, y = 0, i;
 
143
 
 
144
    for (i = 0; i < m_posX.count(); ++i) {
 
145
        if ( m_posX.at(i) > x)
 
146
            x = m_posX.at(i);
 
147
 
 
148
        if ( m_posY.at(i) > y)
 
149
            y = m_posY.at(i);
 
150
    }
 
151
    return QPoint(x, y);
 
152
}
 
153
 
 
154
int pseTable::numerationAtPos( int xPos ) const
 
155
{
 
156
  if ( xPos >= 0 && xPos < m_xCoordsNumeration.count() ) {
 
157
     return m_xCoordsNumeration.at( xPos ) - 1;
 
158
  }
 
159
  return -1;
 
160
}
 
161
 
 
162
/// Regular Table Data
 
163
pseRegularTable::pseRegularTable()
 
164
        : pseTable()
 
165
{
 
166
    m_name = "Classic";
 
167
 
 
168
    m_description = i18n( "Classic Periodic Table" );
 
169
 
 
170
    m_xCoordsNumeration <<
 
171
    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18;
 
172
 
 
173
    m_posX <<
 
174
    1 <<                                                                                         18 <<
 
175
    1 << 2 <<                                                      13 << 14 << 15 << 16 << 17 << 18 <<
 
176
    1 << 2 <<                                                      13 << 14 << 15 << 16 << 17 << 18 <<
 
177
    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18 <<
 
178
    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18 << //Element 54 (Xe)
 
179
    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 <<       //Element 58 (Ce) 71 (Lu)
 
180
    4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18 <<
 
181
    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 <<       //Element 71 (Lr)
 
182
    4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18
 
183
    ;
 
184
 
 
185
    m_posY <<
 
186
    1 <<                                                                                         1 <<
 
187
    2 << 2 <<                                                      2 <<  2 <<  2 <<  2 <<  2 <<  2 <<
 
188
    3 << 3 <<                                                      3 <<  3 <<  3 <<  3 <<  3 <<  3 <<
 
189
    4 << 4 << 4 << 4 << 4 << 4 << 4 << 4 << 4 << 4 <<  4 <<  4 <<  4 <<  4 <<  4 <<  4 <<  4 <<  4 <<
 
190
    5 << 5 << 5 << 5 << 5 << 5 << 5 << 5 << 5 << 5 <<  5 <<  5 <<  5 <<  5 <<  5 <<  5 <<  5 <<  5 << //Element 54 (Xe)
 
191
    6 << 6 << 6 << 9 << 9 << 9 << 9 << 9 << 9 << 9 <<  9 <<  9 <<  9 <<  9 <<  9 <<  9 <<  9 <<          //Element 71 (Lr)
 
192
    6 << 6 << 6 << 6 << 6 << 6 << 6 << 6 << 6 << 6 <<  6 <<  6 <<  6 <<  6 <<  6 <<
 
193
    7 << 7 << 7 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 << 10 <<
 
194
    7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7 << 7
 
195
    ;
 
196
 
 
197
    // The classic PS has all Elements
 
198
    if (m_posX.count() == m_posY.count() ) {
 
199
        for (int i =  1; i <= m_posX.count(); i ++) {
 
200
            m_elementList.append(i);
 
201
        }
 
202
    }
 
203
}
 
204
 
 
205
pseRegularTable *pseRegularTable::init()
 
206
{
 
207
    static pseRegularTable thisTable;
 
208
    return &thisTable;
 
209
}
 
210
 
 
211
/// Long Table Data
 
212
pseLongTable::pseLongTable()
 
213
        : pseTable()
 
214
{
 
215
    m_name = "Long";
 
216
 
 
217
    m_description = i18n( "Long Periodic Table" );
 
218
 
 
219
    m_xCoordsNumeration <<
 
220
    1 << 2 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 3 << 4 << 5 << 6 << 7 << 8 << 9 <<10 <<11 <<12 <<13 <<14 <<15 <<16 <<17 <<18;
 
221
 
 
222
    m_posX <<
 
223
    1 <<                                                                                                                                                      32 <<
 
224
    1 << 2 <<                                                                                                                        27 <<28 <<29 <<30 <<31 <<32 <<
 
225
    1 << 2 <<                                                                                                                        27 <<28 <<29 <<30 <<31 <<32 <<
 
226
    1 << 2 <<                                                                      17 <<18 <<19 <<20 <<21 <<22 <<23 <<24 <<25 <<26 <<27 <<28 <<29 <<30 <<31 <<32 <<
 
227
    1 << 2 <<                                                                      17 <<18 <<19 <<20 <<21 <<22 <<23 <<24 <<25 <<26 <<27 <<28 <<29 <<30 <<31 <<32 <<
 
228
    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 <<
 
229
    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
 
230
    ;
 
231
 
 
232
    m_posY <<
 
233
    1 <<                                                                                                                                                      1 <<
 
234
    2 << 2 <<                                                                                                                        2  <<2  <<2  <<2  <<2  <<2 <<
 
235
    3 << 3 <<                                                                                                                        3  <<3  <<3  <<3  <<3  <<3 <<
 
236
    4 << 4 <<                                                                      4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4  <<4 <<
 
237
    5 << 5 <<                                                                      5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5  <<5 <<
 
238
    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 <<
 
239
    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
 
240
    ;
 
241
 
 
242
    // The long PS has all Elements
 
243
    if (m_posX.count() == m_posY.count() ) {
 
244
        for (int i =  1; i <= m_posX.count(); i ++) {
 
245
            m_elementList.append(i);
 
246
        }
 
247
    }
 
248
}
 
249
 
 
250
pseLongTable *pseLongTable::init()
 
251
{
 
252
    static pseLongTable thisTable;
 
253
    return &thisTable;
 
254
}
 
255
 
 
256
/// Short Table Data
 
257
pseShortTable::pseShortTable()
 
258
        : pseTable()
 
259
{
 
260
    m_name = "Short";
 
261
 
 
262
    m_description = i18n( "Short Periodic Table" );
 
263
 
 
264
    m_xCoordsNumeration <<
 
265
    1 << 2 <<13 <<14 <<15 <<16 <<17 <<18;
 
266
 
 
267
    m_posX <<
 
268
    1 <<                               8 <<//He
 
269
    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 <<//Ne
 
270
    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 <<//Ar
 
271
    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 <<//Kr
 
272
    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 <<//Xe
 
273
    1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 <<//Rn
 
274
    1 << 2                  //Fr and Ra
 
275
    ;
 
276
 
 
277
    m_posY <<
 
278
    1 <<                               1 <<//He
 
279
    2 << 2 << 2 << 2 << 2 << 2 << 2 << 2 <<//Ne
 
280
    3 << 3 << 3 << 3 << 3 << 3 << 3 << 3 <<//Ar
 
281
    4 << 4 << 4 << 4 << 4 << 4 << 4 << 4 <<//Kr
 
282
    5 << 5 << 5 << 5 << 5 << 5 << 5 << 5 <<//Xe
 
283
    6 << 6 << 6 << 6 << 6 << 6 << 6 << 6 <<//Rn
 
284
    7 << 7                   //Fr and Ra
 
285
    ;
 
286
 
 
287
    m_elementList <<
 
288
    1 <<                               2 <<//He
 
289
    3 << 4 << 5 << 6 << 7 << 8 << 9 << 10<<//Ne
 
290
    11<< 12<< 13<< 14<< 15<< 16<< 17<< 18<<//Ar
 
291
    19<< 20<< 31<< 32<< 33<< 34<< 35<< 36<<//Kr
 
292
    37<< 38<< 49<< 50<< 51<< 52<< 53<< 54<<//Xe
 
293
    55<< 56<< 81<< 82<< 83<< 84<< 85<< 86<<//Rn
 
294
    87<< 88                   //Fr and Ra
 
295
    ;
 
296
}
 
297
 
 
298
pseShortTable *pseShortTable::init()
 
299
{
 
300
    static pseShortTable thisTable;
 
301
    return &thisTable;
 
302
}
 
303
 
 
304
/// D-Group Table Data
 
305
pseDTable::pseDTable()
 
306
        : pseTable()
 
307
{
 
308
    m_name = "D";
 
309
 
 
310
    m_description = i18n( "Transition Elements" );
 
311
 
 
312
    m_xCoordsNumeration <<
 
313
    3<< 4<< 5<< 6<< 7<< 8<< 9<<10<<11<< 12;
 
314
 
 
315
    m_posX <<
 
316
    1<< 2<< 3<< 4<< 5<< 6<< 7<< 8<< 9<< 10<<
 
317
    1<< 2<< 3<< 4<< 5<< 6<< 7<< 8<< 9<< 10<<
 
318
    1<< 2<< 3<< 4<< 5<< 6<< 7<< 8<< 9<< 10<<
 
319
    1<< 2<< 3<< 4<< 5<< 6<< 7<< 8<< 9<< 10
 
320
    ;
 
321
 
 
322
    m_posY <<
 
323
    1<< 1<< 1<< 1<< 1<< 1<< 1<< 1<< 1<< 1<<
 
324
    2<< 2<< 2<< 2<< 2<< 2<< 2<< 2<< 2<< 2<<
 
325
    3<< 3<< 3<< 3<< 3<< 3<< 3<< 3<< 3<< 3<<
 
326
    4<< 4<< 4<< 4<< 4<< 4<< 4<< 4<< 4<< 4
 
327
    ;
 
328
 
 
329
    m_elementList <<
 
330
    21 << 22 << 23 << 24 << 25 << 26 << 27 << 28 << 29 << 30 <<
 
331
    39 << 40 << 41 << 42 << 43 << 44 << 45 << 46 << 47 << 48 <<
 
332
    57 << 72 << 73 << 74 << 75 << 76 << 77 << 78 << 79 << 80 <<
 
333
    89 << 104<< 105<< 106<< 107<< 108<< 109<< 110<< 111<< 112
 
334
    ;
 
335
}
 
336
 
 
337
 
 
338
pseDTable *pseDTable::init()
 
339
{
 
340
    static pseDTable thisTable;
 
341
    return &thisTable;
 
342
}
 
343
 
 
344
/// DZ Table Data
 
345
pseDZTable::pseDZTable()
 
346
: pseTable()
 
347
{
 
348
    m_name = "DZ";
 
349
 
 
350
    m_description = i18n( "DZ Periodic Table" );
 
351
 
 
352
    m_xCoordsNumeration <<
 
353
    1 << 2 <<13 <<14 <<15 <<16 <<17 <<18 << 3 << 4 << 5 << 6 << 7 << 8 << 9 <<10 <<11 <<12;
 
354
 
 
355
    m_posX <<
 
356
    1<< 2<<
 
357
    2<< 2<<
 
358
         3<< 4<< 5<< 6<< 7<< 8<<
 
359
    1<< 2<<
 
360
         3<< 4<< 5<< 6<< 7<< 8<<
 
361
    1<< 2<<
 
362
                           9<<10<<11<<12<<13<<14<<15<<16<<17<<18<<
 
363
         3<< 4<< 5<< 6<< 7<< 8<<
 
364
    1<< 2<<
 
365
                           9<<10<<11<<12<<13<<14<<15<<16<<17<<18<<
 
366
         3 <<4 <<5 <<6 <<7 <<8 <<
 
367
    1<< 2<<
 
368
                                                              19<<20<<21<<22<<23<<24<<25<<26<<27<<28<<29<<30<<31<<32<<
 
369
                           9<<10<<11<<12<<13<<14<<15<<16<<17<<18<<
 
370
         3 <<4 <<5 <<6 <<7 <<8 <<
 
371
    1<< 2<<
 
372
                                                              19<<20<<21<<22<<23<<24<<25<<26<<27<<28<<29<<30<<31<<32<<
 
373
                           9<<10<<11<<12<<13<<14<<15<<16<<17<<18<<
 
374
         3 <<4 <<5 <<6 <<7 <<8
 
375
    ;
 
376
 
 
377
    m_posY <<
 
378
    1<< 1<<
 
379
    2<< 2<<
 
380
         3<< 3<< 3<< 3<< 3<< 3<<
 
381
    4<< 4<<
 
382
         5<< 5<< 5<< 5<< 5<< 5<<
 
383
    6<< 6<<
 
384
                          7<< 7<< 7<< 7<< 7<< 7<< 7<< 7<< 7<< 7<<
 
385
         8<< 8<< 8<< 8<< 8<< 8<<
 
386
    9<< 9<<
 
387
                         10<<10<<10<<10<<10<<10<<10<<10<<10<<10<<
 
388
         11<<11<<11<<11<<11<<11<<
 
389
    12<<12<<
 
390
 
 
391
                                                              13<<13<<13<<13<<13<<13<<13<<13<<13<<13<<13<<13<<13<<13<<
 
392
                          14<<14<<14<<14<<14<<14<<14<<14<<14<<14<<
 
393
         15<<15<<15<<15<<15<<15<<
 
394
    16<<16<<
 
395
                                                              17<<17<<17<<17<<17<<17<<17<<17<<17<<17<<17<<17<<17<<17<<
 
396
                          18<<18<<18<<18<<18<<18<<18<<18<<18<<18<<
 
397
         19<<19<<19<<19<<19<<19
 
398
    ;
 
399
 
 
400
    // The DZ PS has all Elements
 
401
    if (m_posX.count() == m_posY.count() ) {
 
402
        for (int i =  1; i <= m_posX.count(); i ++) {
 
403
            m_elementList.append(i);
 
404
        }
 
405
    }
 
406
 
 
407
}
 
408
 
 
409
pseDZTable *pseDZTable::init()
 
410
{
 
411
    static pseDZTable thisTable;
 
412
    return &thisTable;
 
413
}