Changeset 9369 for trunk/MagicSoft/Mars/mtools/MagicReversi.cc
- Timestamp:
- 03/01/09 21:54:27 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mtools/MagicReversi.cc
r8756 r9369 2 2 ! 3 3 ! * 4 ! * This file is part of MARS, the MAGICAnalysis and Reconstruction4 ! * This file is part of CheObs, the Modular Analysis and Reconstruction 5 5 ! * Software. It is distributed to you in the hope that it can be a useful 6 6 ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes. … … 9 9 ! * Permission to use, copy, modify and distribute this software and its 10 10 ! * documentation for any purpose is hereby granted without fee, 11 ! * provided that the above copyright notice appear in all copies and11 ! * provided that the above copyright notice appears in all copies and 12 12 ! * that both that copyright notice and this permission notice appear 13 13 ! * in supporting documentation. It is provided "as is" without express … … 16 16 ! 17 17 ! 18 ! Author(s): Thomas Bretz 03/2003 <mailto:tbretz@astro.uni-wuerzburg.de>18 ! Author(s): Thomas Bretz, 3/2003 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200320 ! Copyright: CheObs Software Development, 2000-2009 21 21 ! 22 22 ! … … 62 62 #include <TInterpreter.h> 63 63 64 #include "MH exagon.h"64 #include "MH.h" 65 65 66 66 #include "MGeomPix.h" … … 88 88 return; 89 89 90 fPixels->Delete();91 90 fText->Delete(); 92 91 fFlags->Delete(); … … 94 93 delete fText; 95 94 delete fFlags; 96 delete fPixels;97 95 98 96 delete fGeomCam; … … 113 111 114 112 Reset(); 115 DrawHexagons();116 113 } 117 114 … … 119 116 { 120 117 Free(); 121 122 //123 // Reset the display geometry124 //125 fW=0;126 fH=0;127 118 128 119 // … … 144 135 fText = new TClonesArray("TText", fNumPixels); 145 136 fFlags = new TClonesArray("TMarker", fNumPixels); 146 f Pixels = new TClonesArray("MHexagon",fNumPixels);137 fColors.Set(fNumPixels); 147 138 148 139 for (UInt_t i=0; i<fNumPixels; i++) 149 140 { 150 MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]); 151 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06) 152 h.SetBit(kNoContextMenu|kCannotPick); 153 #endif 141 const MGeom &pix = (*fGeomCam)[i]; 154 142 155 143 TText &t = *new ((*fText)[i]) TText; 156 144 t.SetTextFont(122); 157 145 t.SetTextAlign(22); // centered/centered 158 t.SetTextSize(0.3* h.GetD()/fRange);146 t.SetTextSize(0.3*pix.GetT()/fRange); 159 147 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06) 160 148 t.SetBit(kNoContextMenu|kCannotPick); 161 149 #endif 162 163 const MGeomPix &pix = (*fGeomCam)[i];164 150 165 151 TMarker &m = *new ((*fFlags)[i]) TMarker(pix.GetX(), pix.GetY(), kOpenStar); … … 170 156 } 171 157 158 /* 172 159 // ------------------------------------------------------------------------ 173 160 // … … 180 167 (*this)[i].Draw(); 181 168 } 169 */ 182 170 183 171 void MagicReversi::Init() … … 201 189 // 202 190 MagicReversi::MagicReversi() 203 : fGeomCam(NULL), fDone(NULL) , fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)191 : fGeomCam(NULL), fDone(NULL) 204 192 { 205 193 SetNewCamera(new MGeomCamMagic); … … 209 197 210 198 MagicReversi::MagicReversi(const MGeomCam &geom) 211 : fGeomCam(NULL), fDone(NULL) , fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)199 : fGeomCam(NULL), fDone(NULL) 212 200 { 213 201 SetNewCamera(static_cast<MGeomCam*>(geom.Clone())); … … 229 217 if (fDone) 230 218 delete fDone; 231 232 if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)233 {234 fDrawingPad->RecursiveRemove(this);235 delete fDrawingPad;236 }237 219 } 238 220 … … 245 227 void MagicReversi::Paint(Option_t *opt) 246 228 { 247 const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC()); 248 const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC()); 249 250 // 251 // Check for a change in width or height, and make sure, that the 252 // first call also sets the range 253 // 254 if (w*fH == h*fW && fW && fH) 255 return; 256 257 // 258 // Calculate aspect ratio (5/4=1.25 recommended) 259 // 260 const Double_t ratio = (Double_t)w/h; 261 262 Float_t x; 263 Float_t y; 264 265 if (ratio>1.0) 266 { 267 x = fRange*(ratio*2-1); 268 y = fRange; 269 } 270 else 271 { 272 x = fRange; 273 y = fRange/ratio; 274 } 275 276 fH = h; 277 fW = w; 278 279 // 280 // Set new range 281 // 282 fDrawingPad->Range(-fRange, -y, x, y); 283 284 // 285 // Adopt absolute sized of markers to relative range 286 // 229 const Float_t r = fGeomCam->GetMaxRadius(); 230 231 MH::SetPadRange(-r, -r, r, r*1.1); 232 233 TAttLine line; 234 TAttFill fill; 235 236 // FIXME: 287 237 for (UInt_t i=0; i<fNumPixels; i++) 288 238 { 289 Float_t r = (*this)[i].GetD()*gPad->XtoAbsPixel(1)/325; 239 const MGeom &pix = (*fGeomCam)[i]; 240 241 fill.SetFillColor(fColors[i]); 242 pix.PaintPrimitive(line, fill); 243 244 // 245 // Adopt absolute sized of markers to relative range 246 // 247 Float_t r = (*fGeomCam)[i].GetT()*gPad->XtoAbsPixel(1)/325; 290 248 GetFlag(i)->SetMarkerSize(20.0*r/fRange); 249 250 if (pix.TestBit(kHasFlag)) 251 GetFlag(i)->Paint(); 252 253 GetText(i)->Paint(); 291 254 } 292 255 } … … 301 264 void MagicReversi::Draw(Option_t *option) 302 265 { 303 // root 3.02:304 // gPad->SetFixedAspectRatio()305 306 if (fDrawingPad)307 return;308 309 266 // 310 267 // if no canvas is yet existing to draw into, create a new one 311 268 // 312 269 if (!gPad) 313 { 314 /*TCanvas *c =*/ new TCanvas("MagicReversi", "Magic Reversi", 0, 0, 800, 800); 315 //c->ToggleEventStatus(); 316 fIsAllocated = kTRUE; 317 } 318 else 319 fIsAllocated = kFALSE; 320 321 fDrawingPad = gPad; 322 fDrawingPad->SetBorderMode(0); 270 new TCanvas("MagicReversi", "Magic Reversi", 0, 0, 800, 800); 271 272 gPad->SetBorderMode(0); 323 273 324 274 // … … 347 297 // 348 298 Reset(); 349 DrawHexagons();350 299 } 351 300 … … 411 360 for (UInt_t i=0; i<fNumPixels; i++) 412 361 { 413 Remove(GetText(i)); 414 Remove(GetFlag(i)); 415 416 (*this)[i].SetFillColor(kEmpty); 362 fColors[i] = kEmpty; 417 363 (*fGeomCam)[i].ResetBit(kUserBits); 418 364 419 365 GetFlag(i)->SetMarkerColor(kBlack); 366 GetText(i)->SetText(0, 0, ""); 420 367 } 421 368 … … 427 374 for (int i=1; i<5*fNumUsers; i++) 428 375 { 429 (*this)[i-1].SetFillColor(i%fNumUsers+kRed);376 fColors[i-1] = i%fNumUsers+kRed; 430 377 fUsrPts[i%fNumUsers]++; 431 378 } … … 433 380 Update(); 434 381 435 fDrawingPad->SetFillColor(22);382 gPad->SetFillColor(22); 436 383 437 384 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06) 438 fDrawingPad->SetBit(kNoContextMenu);439 385 SetBit(kNoContextMenu); 440 386 #endif … … 468 414 fDone->Draw(); 469 415 470 fDrawingPad->SetFillColor(winner+kRed);416 gPad->SetFillColor(winner+kRed); 471 417 472 418 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06) 473 fDrawingPad->ResetBit(kNoContextMenu);474 419 ResetBit(kNoContextMenu); 475 420 #endif 476 }477 478 void MagicReversi::Remove(TObject *obj)479 {480 fDrawingPad->RecursiveRemove(obj);481 421 } 482 422 … … 495 435 { 496 436 idx = fGeomCam->GetNeighbor(idx, dir); 497 if (idx<0 || (*this)[idx].GetFillColor()==kEmpty)437 if (idx<0 || fColors[idx]==kEmpty) 498 438 break; 499 439 500 if ( (*this)[idx].GetFillColor()==col)440 if (fColors[idx]==col) 501 441 { 502 442 if (length!=0) … … 523 463 idx = fGeomCam->GetNeighbor(idx, dir); 524 464 525 fUsrPts[ (*this)[idx].GetFillColor()-kRed]--;465 fUsrPts[fColors[idx]-kRed]--; 526 466 fUsrPts[fNumUser]++; 527 467 528 (*this)[idx].SetFillColor(col);468 fColors[idx] = col; 529 469 } 530 470 } … … 536 476 { 537 477 for (unsigned int i=0; i<fNumPixels; i++) 538 if ( (*this)[i].GetFillColor()==kEmpty && Flip(i, kFALSE))478 if (fColors[i]==kEmpty && Flip(i, kFALSE)) 539 479 return kTRUE; 540 480 return kFALSE; … … 557 497 { 558 498 Done(); 559 fDrawingPad->Modified();560 fDrawingPad->Update();499 gPad->Modified(); 500 gPad->Update(); 561 501 return; 562 502 } … … 564 504 UInt_t idx; 565 505 for (idx=0; idx<fNumPixels; idx++) 566 if ((*f Pixels)[idx]->DistancetoPrimitive(px, py)==0)506 if ((*fGeomCam)[idx].DistancetoPrimitive(px, py)<=0) 567 507 break; 568 508 … … 570 510 return; 571 511 572 if (event==kButton1Down && (*this)[idx].GetFillColor()==kEmpty)512 if (event==kButton1Down && fColors[idx]==kEmpty) 573 513 { 574 514 if (!Flip(idx, kTRUE)) … … 577 517 fUsrPts[fNumUser]++; 578 518 579 (*this)[idx].SetFillColor(kRed+fNumUser);519 fColors[idx] = kRed+fNumUser; 580 520 581 521 Int_t start = fNumUser; … … 600 540 } 601 541 602 fDrawingPad->Modified();603 } 542 gPad->Modified(); 543 }
Note:
See TracChangeset
for help on using the changeset viewer.