00001
00002
00003
00004
00005
00006
00007
00008 #include <TGFrame.h>
00009 #include <TGLayout.h>
00010 #include <TGWindow.h>
00011
00012 #include "XSVarious.h"
00013 #include "XSElementList.h"
00014 #include "XSPeriodicTable.h"
00015
00016
00017
00018
00019 XSTblElement::XSTblElement(const TGWindow *p, Int_t z, UInt_t color)
00020 : TGButton(p,z)
00021 {
00022 Z = z;
00023
00024 char str[5];
00025 snprintf(str,5,"%d",Z);
00026 lZ = new TGLabel(this,str);
00027 lName = new TGLabel(this,XSelements->Mnemonic(Z), blueBoldGC);
00028
00029 ChangeBackground(color);
00030
00031 tpZ = NULL;
00032 tpName = NULL;
00033 }
00034
00035
00036 XSTblElement::~XSTblElement()
00037 {
00038 delete lZ;
00039 delete lName;
00040 delete tpZ;
00041 delete tpName;
00042 }
00043
00044
00045 void
00046 XSTblElement::Layout()
00047 {
00048 int w = GetWidth() - 2*fBorderWidth;
00049 int h = (GetHeight() - 2*fBorderWidth) / 2;
00050
00051 lZ->MoveResize(fBorderWidth, fBorderWidth, w, h);
00052 lZ->MapWindow();
00053
00054 lName->MoveResize(fBorderWidth, fBorderWidth+h, w, h);
00055 lName->MapWindow();
00056
00057 if (tpZ == NULL) {
00058 tpZ = new TGToolTip(fClient->GetRoot(),
00059 lZ, XSelements->Name(Z), 1000);
00060 tpName = new TGToolTip(fClient->GetRoot(),
00061 lName, XSelements->Name(Z), 1000);
00062 }
00063
00064 TGButton::Layout();
00065 }
00066
00067
00068 void
00069 XSTblElement::SetState(EButtonState state, Bool_t emit)
00070 {
00071 if (state != fState) {
00072 if (state==kButtonDown ) {
00073 lZ->Move(lZ->GetX()+1, lZ->GetY()+1);
00074 lName->Move(lName->GetX()+1, lName->GetY()+1);
00075 } else
00076 if (state == kButtonUp) {
00077 lZ->Move(lZ->GetX()-1, lZ->GetY()-1);
00078 lName->Move(lName->GetX()-1, lName->GetY()-1);
00079 }
00080 }
00081
00082 TGButton::SetState(state, emit);
00083 }
00084
00085
00086 void
00087 XSTblElement::ChangeBackground( ULong_t color )
00088 {
00089 lZ->ChangeBackground(color);
00090 lName->ChangeBackground(color);
00091 }
00092
00093
00094
00095
00096
00097 static Int_t colwidth[XSPTBL_COLS] =
00098 { 8, 5, 5, 2, 5,
00099 5, 5, 5, 5, 5,
00100 5, 5, 5, 5, 5,
00101 5, 5, 5, 5, 5 };
00102 static Int_t colsum;
00103 static Int_t rowheight[XSPTBL_ROWS] =
00104 { 5, 5, 10, 10, 10, 10, 10, 10, 10, 3, 10, 10 };
00105 static Int_t rowsum;
00106
00107 #define A(x) (Long_t)(char *)(x)
00108 static Long_t ptable[XSPTBL_ROWS][XSPTBL_COLS] = {
00109 { A("Group"), A("1"), A("2"), 0, A("3"), A("4"), A("5"), A("6"), A("7"),
00110 A("8"), A("9"), A("10"), A("11"), A("12"), A("13"), A("14"), A("15"),
00111 A("16"), A("17"), A("18") },
00112 { A("Period"), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
00113 { A("1"), 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2},
00114 { A("2"), 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 8, 9,10},
00115 { A("3"),11,12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,13, 14,15,16,17,18},
00116 { A("4"),19,20, 0,21, 22,23,24,25,26, 27,28,29,30,31, 32,33,34,35,36},
00117 { A("5"),37,38, 0,39, 40,41,42,43,44, 45,46,47,48,49, 50,51,52,53,54},
00118 { A("6"),55,56,A("*"),71, 72,73,74,75,76, 77,78,79,80,81, 82,83,84,85,86},
00119 { A("7"),87,88,A("**"),103, 104,105,106,107,108, 109,110,111,112,113, 114,115,116,117,118},
00120 { 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0 },
00121 { A("* Lanthanoids"),0,0,A("*"),57, 58,59,60,61,62, 63,64,65,66,67, 68,69,70,0,0},
00122 { A("** Actinoids"),0,0,A("**"),89, 90,91,92,93,94, 95,96,97,98,99, 100,101,102,0,0}
00123 };
00124 #undef A
00125
00126
00127 #define COLORS 7
00128
00129
00130
00131
00132
00133
00134
00135
00136 #define w 0
00137 #define A 1
00138 #define B 2
00139 #define Y 3
00140 #define O 4
00141 #define G 5
00142 static const char *colorName[COLORS] = {
00143 "White",
00144 "#CCCCCC",
00145 "#CCCCFF",
00146 "#FFFFCC",
00147 "#FFCCCC",
00148 "#CCFFCC",
00149 "yellow",
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 };
00160
00161 static ULong_t colorPixels[COLORS];
00162
00163 static Byte_t ecolor[XSPTBL_ROWS][XSPTBL_COLS] = {
00164 { A,A,A,w,A, A,A,A,A,A, A,A,A,A,A, A,A,A,A,A },
00165 { A,w,w,w,w, w,w,w,w,w, w,w,w,w,w, w,w,w,w,w },
00166 { A,B,w,w,w, w,w,w,w,w, w,w,w,w,w, w,w,w,w,Y },
00167 { A,B,B,w,w, w,w,w,w,w, w,w,w,w,Y, Y,Y,Y,Y,Y },
00168 { A,B,B,w,w, w,w,w,w,w, w,w,w,w,Y, Y,Y,Y,Y,Y },
00169 { A,B,B,w,O, O,O,O,O,O, O,O,O,O,Y, Y,Y,Y,Y,Y },
00170 { A,B,B,w,O, O,O,O,O,O, O,O,O,O,Y, Y,Y,Y,Y,Y },
00171 { A,B,B,w,O, O,O,O,O,O, O,O,O,O,Y, Y,Y,Y,Y,Y },
00172 { A,B,B,w,O, O,O,O,O,O, O,O,O,O,A, Y,A,Y,A,Y },
00173 { w,w,w,w,w, w,w,w,w,w, w,w,w,w,w, w,w,w,w,w },
00174 { A,A,A,w,G, G,G,G,G,G, G,G,G,G,G, G,G,G,w,w },
00175 { A,A,A,w,G, G,G,G,G,G, G,G,G,G,G, G,G,G,w,w }
00176 };
00177 #undef w
00178 #undef A
00179 #undef B
00180 #undef Y
00181 #undef O
00182 #undef G
00183
00184
00185 XSPeriodicTable::XSPeriodicTable(const TGWindow *msgWnd, const TGWindow* p,
00186 UInt_t w, UInt_t h)
00187 : TGCompositeFrame(p,w,h, kFitWidth | kFitHeight | kSunkenFrame)
00188 {
00189 int i, j;
00190
00191 rowsum = 0;
00192 for (j=0; j<XSPTBL_ROWS; j++)
00193 rowsum += rowheight[j];
00194
00195 colsum = 0;
00196 for (j=0; j<XSPTBL_COLS; j++)
00197 colsum += colwidth[j];
00198
00199
00200 for (i=0; i<COLORS; i++)
00201 gClient->GetColorByName(colorName[i], colorPixels[i]);
00202
00203 for (j=0; j<XSPTBL_ROWS; j++)
00204 for (i=0; i<XSPTBL_COLS; i++) {
00205 long val = ptable[j][i];
00206 int col = colorPixels[ecolor[j][i]];
00207 if (val) {
00208 if (val < 120) {
00209 elem[j][i] = new XSTblElement(this,
00210 val,col);
00211 ((XSTblElement*)elem[j][i])->Associate(msgWnd);
00212 } else {
00213 elem[j][i] = new TGLabel(this,
00214 (char*)val);
00215 elem[j][i]->ChangeBackground(col);
00216 }
00217 } else
00218 elem[j][i] = NULL;
00219 }
00220 ChangeBackground(colorPixels[0]);
00221
00222 width = w;
00223 height = h;
00224 }
00225
00226
00227 XSPeriodicTable::~XSPeriodicTable()
00228 {
00229 for (int j=0; j<XSPTBL_ROWS; j++)
00230 for (int i=0; i<XSPTBL_COLS; i++)
00231 if (elem[j][i])
00232 delete elem[j][i];
00233 }
00234
00235
00236 void
00237 XSPeriodicTable::Layout()
00238 {
00239 int w, h;
00240 Float_t cwidth[XSPTBL_COLS];
00241 Float_t rheight[XSPTBL_ROWS];
00242
00243 TGCompositeFrame::Layout();
00244
00245 w = GetWidth() - 2*fBorderWidth - 4;
00246 h = GetHeight() - 2*fBorderWidth - 4;
00247
00248
00249 for (int i=0; i<XSPTBL_COLS; i++) {
00250 cwidth[i] = (Float_t)(colwidth[i]*w)/(Float_t)colsum;
00251 }
00252
00253 for (int i=0; i<XSPTBL_ROWS; i++) {
00254 rheight[i] = (Float_t)(rowheight[i]*h)/(Float_t)rowsum;
00255 }
00256
00257 Float_t yt = fBorderWidth+2;
00258 for (int j=0; j<XSPTBL_ROWS; j++) {
00259 Float_t xl = fBorderWidth+2;
00260 for (int i=0; i<XSPTBL_COLS; i++) {
00261 if (j<10) {
00262 if (elem[j][i]) {
00263 elem[j][i]->MoveResize(
00264 (int)xl,
00265 (int)yt,
00266 (int)cwidth[i]-1,
00267 (int)rheight[j]-1);
00268 elem[j][i]->MapWindow();
00269 }
00270 xl += cwidth[i];
00271 } else {
00272 if (i<3) {
00273 Float_t w = cwidth[0]+cwidth[1]+
00274 cwidth[2];
00275 if (elem[j][0]) {
00276 elem[j][0]->MoveResize(
00277 (int)xl,
00278 (int)yt,
00279 (int)w-1,
00280 (int)rheight[j]-1);
00281 elem[j][0]->MapWindow();
00282 }
00283 xl += w;
00284 i = 2;
00285 } else {
00286 if (elem[j][i]) {
00287 elem[j][i]->MoveResize(
00288 (int)xl,
00289 (int)yt,
00290 (int)cwidth[i]-1,
00291 (int)rheight[j]-1);
00292 elem[j][i]->MapWindow();
00293 }
00294 xl += cwidth[i];
00295 }
00296 }
00297 }
00298 yt += rheight[j];
00299 }
00300 }
00301
00302
00303 void
00304 XSPeriodicTable::SelectZ( ULong_t Z )
00305 {
00306
00307 for (int j=0; j<XSPTBL_ROWS; j++)
00308 for (int i=0; i<XSPTBL_COLS; i++)
00309 if ((ULong_t)ptable[j][i] == Z) {
00310
00311 elem[j][i]->ChangeBackground(colorPixels[6]);
00312 }
00313 }