00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kalziumtabletype.h"
00022
00023 #include "kalziumdataobject.h"
00024 #include "kalziumnumerationtype.h"
00025
00026 #include <klocale.h>
00027 #include <kdebug.h>
00028
00029 #define ELEMENTSIZE 40
00030
00031 static const int posXRegular[117] = {
00032 1, 18,
00033 1, 2, 13, 14, 15, 16, 17, 18,
00034 1, 2, 13, 14, 15, 16, 17, 18,
00035 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
00036 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
00037 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
00038 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
00039 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
00040 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
00041 };
00042
00043 static const int posYRegular[117] = {
00044 1, 1,
00045 2, 2, 2, 2, 2, 2, 2, 2,
00046 3, 3, 3, 3, 3, 3, 3, 3,
00047 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
00048 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
00049 6, 6, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
00050 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
00051 7, 7, 7, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
00052 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
00053 };
00054
00055 static const int posXShort[44] = {
00056 1, 8,
00057 1, 2, 3, 4, 5, 6, 7, 8,
00058 1, 2, 3, 4, 5, 6, 7, 8,
00059 1, 2, 3, 4, 5, 6, 7, 8,
00060 1, 2, 3, 4, 5, 6, 7, 8,
00061 1, 2, 3, 4, 5, 6, 7, 8,
00062 1, 2
00063 };
00064
00065 static const int posYShort[44] = {
00066 1, 1,
00067 2, 2, 2, 2, 2, 2, 2, 2,
00068 3, 3, 3, 3, 3, 3, 3, 3,
00069 4, 4, 4, 4, 4, 4, 4, 4,
00070 5, 5, 5, 5, 5, 5, 5, 5,
00071 6, 6, 6, 6, 6, 6, 6, 6,
00072 7, 7
00073 };
00074
00075 static const int posYD[40] = {
00076 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00077 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00078 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
00079 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
00080 };
00081
00082 static const int posXD[40] = {
00083 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
00084 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
00085 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
00086 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
00087 };
00088
00090 static const int posXDZ[117] = {
00091 1, 2,
00092 2, 2,
00093 3, 4, 5, 6, 7, 8,
00094 1, 2,
00095 3, 4, 5, 6, 7, 8,
00096 1, 2,
00097 9,10,11,12,13,14,15,16,17,18,
00098 3, 4, 5, 6, 7, 8,
00099 1, 2,
00100 9,10,11,12,13,14,15,16,17,18,
00101 3 ,4 ,5 ,6 ,7 ,8 ,
00102 1, 2,
00103 19,20,21,22,23,24,25,26,27,28,29,30,31,32,
00104 9,10,11,12,13,14,15,16,17,18,
00105 3 ,4 ,5 ,6 ,7 ,8 ,
00106 1, 2,
00107 19,20,21,22,23,24,25,26,27,28,29,30,31,32,
00108 9,10,11,12,13,14,15,16,17,18,
00109 3 ,4 ,5 ,6
00110
00111 };
00112
00114 static const int posYDZ[117] = {
00115 1, 1,
00116 2, 2,
00117 3, 3, 3, 3, 3, 3,
00118 4, 4,
00119 5, 5, 5, 5, 5, 5,
00120 6, 6,
00121 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
00122 8, 8, 8, 8, 8, 8,
00123 9, 9,
00124 10,10,10,10,10,10,10,10,10,10,
00125 11,11,11,11,11,11,
00126 12,12,
00127 13,13,13,13,13,13,13,13,13,13,13,13,13,13,
00128 14,14,14,14,14,14,14,14,14,14,
00129 15,15,15,15,15,15,
00130 16,16,
00131 17,17,17,17,17,17,17,17,17,17,17,17,17,17,
00132 18,18,18,18,18,18,18,18,18,18,
00133 19,19,19,19
00134 };
00135
00136
00137 KalziumTableTypeFactory::KalziumTableTypeFactory()
00138 {
00139 m_tables << KalziumClassicTableType::instance();
00140 m_tables << KalziumShortTableType::instance();
00141 m_tables << KalziumDTableType::instance();
00142 m_tables << KalziumDZTableType::instance();
00143 }
00144
00145 KalziumTableTypeFactory* KalziumTableTypeFactory::instance()
00146 {
00147 static KalziumTableTypeFactory kttf;
00148 return &kttf;
00149 }
00150
00151 KalziumTableType* KalziumTableTypeFactory::build( int id ) const
00152 {
00153 if ( ( id < 0 ) || ( id >= m_tables.count() ) )
00154 return 0;
00155
00156 return m_tables.at( id );
00157 }
00158
00159 KalziumTableType* KalziumTableTypeFactory::build( const QByteArray& id ) const
00160 {
00161 for ( int i = 0; i < m_tables.count(); i++ )
00162 {
00163 if ( m_tables.at( i )->name() == id )
00164 return m_tables.at( i );
00165 }
00166
00167
00168 return 0;
00169 }
00170
00171 QStringList KalziumTableTypeFactory::tables() const
00172 {
00173 QStringList l;
00174 for ( int i = 0; i < m_tables.count(); i++ )
00175 {
00176 l << m_tables.at( i )->description();
00177 }
00178 return l;
00179 }
00180
00181
00182 KalziumTableType* KalziumTableType::instance()
00183 {
00184 return 0;
00185 }
00186
00187 KalziumTableType::KalziumTableType()
00188 {
00189 }
00190
00191 KalziumTableType::~KalziumTableType()
00192 {
00193 }
00194
00195 int KalziumTableType::previousOf( int element ) const
00196 {
00197 return element > 1 ? element - 1 : -1;
00198 }
00199
00200 int KalziumTableType::nextOf( int element ) const
00201 {
00202 return element < KalziumDataObject::instance()->numberOfElements() ? element + 1 : -1;
00203 }
00204
00205 int KalziumTableType::firstElement() const
00206 {
00207 return 1;
00208 }
00209
00210 QList<int> KalziumTableType::elementList() const
00211 {
00212 return m_elementList;
00213 }
00214
00215 QRect KalziumTableType::numerationRect( const int num, KalziumNumerationType *nt ) const
00216 {
00217 if ( !nt ) return QRect();
00218
00219 int c = nt->items().count();
00220 if ( ( num < 0 ) || ( num >= c ) )
00221 return QRect();
00222
00223 return QRect( num * ELEMENTSIZE, 0, ELEMENTSIZE, ELEMENTSIZE );
00224 }
00225
00226 QPoint KalziumTableType::elementUnderMouse( const QPoint& coords ) const
00227 {
00228 int X = coords.x() / ELEMENTSIZE;
00229 int Y = coords.y() - ELEMENTSIZE;
00230
00231 X += 1;
00232 Y = Y / ELEMENTSIZE + 1;
00233
00234 return QPoint( X, Y );
00235 }
00236
00238
00239 KalziumClassicTableType* KalziumClassicTableType::instance()
00240 {
00241 static KalziumClassicTableType kctt;
00242 return &kctt;
00243 }
00244
00245 KalziumClassicTableType::KalziumClassicTableType()
00246 : KalziumTableType()
00247 {
00248 const int numElements = KalziumDataObject::instance()->numberOfElements();
00249 for (int i = 1 ; i < numElements ; i++)
00250 m_elementList.append(i);
00251 }
00252
00253 QByteArray KalziumClassicTableType::name() const
00254 {
00255 return "Classic";
00256 }
00257
00258 QString KalziumClassicTableType::description() const
00259 {
00260 return i18n( "Classic Periodic Table" );
00261 }
00262
00263 QSize KalziumClassicTableType::size() const
00264 {
00265 return QSize( ELEMENTSIZE * 18 + 1, ELEMENTSIZE * 11 + 1 );
00266 }
00267
00268 int KalziumClassicTableType::elementAtCoords( const QPoint& coords ) const
00269 {
00270 const QPoint ourcoord = elementUnderMouse( coords );
00271
00272 int x = 0;
00273 int y = 0;
00274 foreach (int counter, m_elementList )
00275 {
00276 x = posXRegular[counter-1];
00277 y = posYRegular[counter-1];
00278 if ( ( ourcoord.x() == x ) && ( ourcoord.y() == y ) ) {
00279 return counter;
00280 }
00281 }
00282
00283
00284 return 0;
00285 }
00286
00287 QRect KalziumClassicTableType::elementRect( const int numelem ) const
00288 {
00289
00290 int x = ( posXRegular[numelem-1] - 1 ) * ELEMENTSIZE;
00291
00292 int y = ( posYRegular[numelem-1] ) * ELEMENTSIZE;
00293
00294 return QRect( x, y, ELEMENTSIZE, ELEMENTSIZE );
00295 }
00296
00298
00299 KalziumShortTableType* KalziumShortTableType::instance()
00300 {
00301 static KalziumShortTableType kctt;
00302 return &kctt;
00303 }
00304
00305 KalziumShortTableType::KalziumShortTableType()
00306 : KalziumTableType()
00307 {
00308
00309
00310
00311 for (int i = 1 ; i < 21 ; i++)
00312 m_elementList.append(i);
00313 for (int i = 31 ; i < 39 ; i++)
00314 m_elementList.append(i);
00315 for (int i = 49 ; i < 57 ; i++)
00316 m_elementList.append(i);
00317 for (int i = 81 ; i < 89 ; i++)
00318 m_elementList.append(i);
00319 }
00320
00321 QByteArray KalziumShortTableType::name() const
00322 {
00323 return "Short";
00324 }
00325
00326 QString KalziumShortTableType::description() const
00327 {
00328 return i18n( "Short Periodic Table" );
00329 }
00330
00331 QSize KalziumShortTableType::size() const
00332 {
00333 return QSize( ELEMENTSIZE * 8 + 1, ELEMENTSIZE * 8 );
00334 }
00335
00336 int KalziumShortTableType::elementAtCoords( const QPoint& coords ) const
00337 {
00338 const QPoint ourcoord = elementUnderMouse( coords );
00339
00340 int x = 0;
00341 int y = 0;
00342
00343 foreach (int counter, m_elementList )
00344 {
00345 int realNum = translateToShort( counter );
00346 x = posXShort[realNum-1];
00347 y = posYShort[realNum-1];
00348
00349 if ( ( ourcoord.x() == x ) && ( ourcoord.y() == y ) ){
00350 return counter;
00351 }
00352 }
00353
00354
00355 return 0;
00356 }
00357
00358 int KalziumShortTableType::translateToShort(int num)
00359 {
00360
00361 if ( num < 21 ) return num;
00362
00363
00364 if ( num < 49 && num > 30 )
00365 return num-10;
00366
00367
00368 if ( num < 57 && num > 48 )
00369 return num-20;
00370
00371
00372 if ( num < 89 && num > 80 )
00373 return num-44;
00374
00375 return 0;
00376 }
00377
00378 QRect KalziumShortTableType::elementRect( const int numelem ) const
00379 {
00380 int realElementNumber = translateToShort(numelem);
00381
00382 if ( realElementNumber == 0 ) {
00383 kDebug() << "This element doesn't exist in this table...";
00384 return QRect( 0,0,0,0 );
00385 } else {
00386 }
00387
00388
00389 int x = ( posXShort[realElementNumber-1] - 1 ) * ELEMENTSIZE;
00390
00391 int y = ( posYShort[realElementNumber-1] ) * ELEMENTSIZE;
00392
00393
00394
00395
00396 return QRect( x, y, ELEMENTSIZE, ELEMENTSIZE );
00397 }
00398
00399 int KalziumShortTableType::previousOf( int element ) const
00400 {
00401 int index = m_elementList.indexOf( element );
00402 return index > 1 ? m_elementList.at( index - 1 ) : -1;
00403 }
00404
00405 int KalziumShortTableType::nextOf( int element ) const
00406 {
00407 int index = m_elementList.indexOf( element );
00408 return index != -1 && ( index < m_elementList.count() - 1 ) ? m_elementList.at( index + 1 ) : -1;
00409 }
00410
00411
00413
00414 KalziumDTableType* KalziumDTableType::instance()
00415 {
00416 static KalziumDTableType kctt;
00417 return &kctt;
00418 }
00419
00420 KalziumDTableType::KalziumDTableType()
00421 : KalziumTableType()
00422 {
00423 for (int i = 21 ; i < 31 ; i++)
00424 m_elementList.append(i);
00425
00426 for (int i = 39 ; i < 49 ; i++)
00427 m_elementList.append(i);
00428
00429 m_elementList.append(57);
00430
00431 for (int i = 72 ; i < 81 ; i++)
00432 m_elementList.append(i);
00433
00434 m_elementList.append(89);
00435
00436 for (int i = 104 ; i < 113 ; i++)
00437 m_elementList.append(i);
00438 }
00439
00440 QByteArray KalziumDTableType::name() const
00441 {
00442 return "D";
00443 }
00444
00445 QString KalziumDTableType::description() const
00446 {
00447 return i18n( "Transition Elements" );
00448 }
00449
00450 int KalziumDTableType::firstElement() const
00451 {
00452
00453 return 21;
00454 }
00455
00456
00457 QSize KalziumDTableType::size() const
00458 {
00459 return QSize( ELEMENTSIZE * 10 + 1, ELEMENTSIZE * 4 );
00460 }
00461
00462 int KalziumDTableType::elementAtCoords( const QPoint& coords ) const
00463 {
00464 const QPoint ourcoord = elementUnderMouse( coords );
00465
00466 int x = 0;
00467 int y = 0;
00468
00469 foreach (int counter, m_elementList )
00470 {
00471 x = posXD[counter-1];
00472 y = posYD[counter-1];
00473 if ( ( ourcoord.x() == x ) && ( ourcoord.y() == y ) ){
00474 return counter;
00475 }
00476 }
00477
00478
00479 return 0;
00480 }
00481
00482 int KalziumDTableType::translateToD(int num)
00483 {
00484 if (num < 21 ) return 0;
00485
00486
00487 if ( num < 31 )
00488 return num-20;
00489
00490
00491 if ( num > 38 && num < 49 )
00492 return num-28;
00493
00494
00495 if ( num == 57 )
00496 return 21;
00497
00498
00499 if ( num > 71 && num < 81 )
00500 return num-50;
00501
00502
00503 if ( num == 89 )
00504 return 31;
00505
00506
00507 if ( num > 103 && num < 113 )
00508 return num-72;
00509
00510 return 0;
00511 }
00512
00513 QRect KalziumDTableType::elementRect( const int numelem ) const
00514 {
00515 int realElementNumber = translateToD(numelem);
00516
00517 if ( realElementNumber == 0 ) {
00518 kDebug() << "This element doesn't exist in this table...";
00519 return QRect( 0,0,0,0 );
00520 } else {
00521 }
00522
00523
00524 int x = ( posXD[realElementNumber-1] - 1 ) * ELEMENTSIZE;
00525
00526 int y = ( posYD[realElementNumber-1] ) * ELEMENTSIZE;
00527
00528
00529
00530 return QRect( x, y, ELEMENTSIZE, ELEMENTSIZE );
00531 }
00532
00533 int KalziumDTableType::previousOf( int element ) const
00534 {
00535 int index = m_elementList.indexOf( element );
00536 return index > 1 ? m_elementList.at( index - 1 ) : -1;
00537 }
00538
00539 int KalziumDTableType::nextOf( int element ) const
00540 {
00541 int index = m_elementList.indexOf( element );
00542 return index != -1 && ( index < m_elementList.count() - 1 ) ? m_elementList.at( index + 1 ) : -1;
00543 }
00544
00546
00547 KalziumDZTableType* KalziumDZTableType::instance()
00548 {
00549 static KalziumDZTableType kctt;
00550 return &kctt;
00551 }
00552
00553 KalziumDZTableType::KalziumDZTableType()
00554 : KalziumTableType()
00555 {
00556 const int numElements = KalziumDataObject::instance()->numberOfElements();
00557 for (int i = 1 ; i < numElements ; i++)
00558 m_elementList.append(i);
00559 }
00560
00561 QByteArray KalziumDZTableType::name() const
00562 {
00563 return "DZ";
00564 }
00565
00566 QString KalziumDZTableType::description() const
00567 {
00568 return i18n( "DZ Periodic Table" );
00569 }
00570
00571 QSize KalziumDZTableType::size() const
00572 {
00573 return QSize( ELEMENTSIZE * 32 + 1, ELEMENTSIZE * 20 + 1 );
00574 }
00575
00576 int KalziumDZTableType::elementAtCoords( const QPoint& coords ) const
00577 {
00578 const QPoint ourcoord = elementUnderMouse( coords );
00579
00580 int x = 0;
00581 int y = 0;
00582 foreach (int counter, m_elementList )
00583 {
00584 x = posXDZ[counter-1];
00585 y = posYDZ[counter-1];
00586 if ( ( ourcoord.x() == x ) && ( ourcoord.y() == y ) ) {
00587 return counter;
00588 }
00589 }
00590
00591
00592 return 0;
00593 }
00594
00595 QRect KalziumDZTableType::elementRect( const int numelem ) const
00596 {
00597 kDebug() << "KalziumDZTableType::elementRect(), num: " << numelem;
00598
00599
00600 int x = ( posXDZ[numelem-1] - 1 ) * ELEMENTSIZE;
00601
00602 int y = ( posYDZ[numelem-1] ) * ELEMENTSIZE;
00603
00604 return QRect( x, y, ELEMENTSIZE, ELEMENTSIZE );
00605 }
00606