| 1 | /* ======================================================================== *\
|
|---|
| 2 | !
|
|---|
| 3 | ! *
|
|---|
| 4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 8 | ! *
|
|---|
| 9 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 10 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 11 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 12 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 13 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 14 | ! * or implied warranty.
|
|---|
| 15 | ! *
|
|---|
| 16 | !
|
|---|
| 17 | !
|
|---|
| 18 | ! Author(s): Nicola Galante 09/2004 <mailto:nicola.galante@pi.infn.it>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MagicTrigger
|
|---|
| 28 | // ------------
|
|---|
| 29 | //
|
|---|
| 30 | // Camera Display Games: Reversi
|
|---|
| 31 | //
|
|---|
| 32 | // Start the game by:
|
|---|
| 33 | // MagicReversi reversi;
|
|---|
| 34 | //
|
|---|
| 35 | // Rules:
|
|---|
| 36 | // ------
|
|---|
| 37 | //
|
|---|
| 38 | // Use the mouse to put a stone at some place. If between your newly
|
|---|
| 39 | // placed stone and the next stone (in a row) of your color are stones
|
|---|
| 40 | // of other colors this stones are won by you. You can only place a
|
|---|
| 41 | // stone if you win at least one stone from your 'enemy'. If you
|
|---|
| 42 | // cannot do so, you are skipped. If nobody can make a move anymore
|
|---|
| 43 | // the game is over. The player has won who has the most stones in
|
|---|
| 44 | // his own color.
|
|---|
| 45 | // The present player is indicated by <*>
|
|---|
| 46 | // Use the Escape key to abort a game.
|
|---|
| 47 | // If the game was aborted or has been stopped youcan access the
|
|---|
| 48 | // options in the context menu.
|
|---|
| 49 | //
|
|---|
| 50 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 51 | #include "MagicTriggerDisplay.h"
|
|---|
| 52 |
|
|---|
| 53 | #include <iostream>
|
|---|
| 54 |
|
|---|
| 55 | #include <KeySymbols.h>
|
|---|
| 56 |
|
|---|
| 57 | #include <TText.h>
|
|---|
| 58 | #include <TMarker.h>
|
|---|
| 59 | #include <TRandom.h>
|
|---|
| 60 | #include <TCanvas.h>
|
|---|
| 61 | #include <TClonesArray.h>
|
|---|
| 62 | #include <TInterpreter.h>
|
|---|
| 63 | #include <TRootEmbeddedCanvas.h>
|
|---|
| 64 | #include <TGButton.h>
|
|---|
| 65 | #include <TGTextEntry.h>
|
|---|
| 66 | #include <TGTextBuffer.h>
|
|---|
| 67 | #include <TGClient.h>
|
|---|
| 68 | #include <RQ_OBJECT.h>
|
|---|
| 69 |
|
|---|
| 70 | #include "MHexagon.h"
|
|---|
| 71 |
|
|---|
| 72 | #include "MGeomPix.h"
|
|---|
| 73 | #include "MGeomCamCT1.h"
|
|---|
| 74 | #include "MGeomCamMagic.h"
|
|---|
| 75 | #include "MagicTriggerButton.h"
|
|---|
| 76 | #include "MMcTriggerLvl2.h"
|
|---|
| 77 |
|
|---|
| 78 | ClassImp(MagicTriggerDisplay);
|
|---|
| 79 |
|
|---|
| 80 | using namespace std;
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 | void MagicTriggerDisplay::Free()
|
|---|
| 84 | {
|
|---|
| 85 | if (!fGeomCam)
|
|---|
| 86 | return;
|
|---|
| 87 |
|
|---|
| 88 | fPixels->Delete();
|
|---|
| 89 | fText->Delete();
|
|---|
| 90 | fFlags->Delete();
|
|---|
| 91 |
|
|---|
| 92 | delete fText;
|
|---|
| 93 | delete fFlags;
|
|---|
| 94 | delete fPixels;
|
|---|
| 95 |
|
|---|
| 96 | delete fGeomCam;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | void MagicTriggerDisplay::SetNewCamera(MGeomCam *geom)
|
|---|
| 100 | {
|
|---|
| 101 | Free();
|
|---|
| 102 |
|
|---|
| 103 | //
|
|---|
| 104 | // Reset the display geometry
|
|---|
| 105 | //
|
|---|
| 106 | fW=0;
|
|---|
| 107 | fH=0;
|
|---|
| 108 |
|
|---|
| 109 | //
|
|---|
| 110 | // Set new camera
|
|---|
| 111 | //
|
|---|
| 112 | fGeomCam = geom;
|
|---|
| 113 |
|
|---|
| 114 | //
|
|---|
| 115 | // create the hexagons of the display
|
|---|
| 116 | //
|
|---|
| 117 | fNumPixels = fGeomCam->GetNumPixels();
|
|---|
| 118 | fRange = fGeomCam->GetMaxRadius();
|
|---|
| 119 |
|
|---|
| 120 | //
|
|---|
| 121 | // Construct all hexagons. Use new-operator with placement
|
|---|
| 122 | //
|
|---|
| 123 | fPixels = new TClonesArray("MHexagon", fNumPixels);
|
|---|
| 124 |
|
|---|
| 125 | for (UInt_t i=0; i<fNumPixels; i++)
|
|---|
| 126 | {
|
|---|
| 127 | MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
|
|---|
| 128 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
|
|---|
| 129 | h.SetBit(kNoContextMenu|kCannotPick);
|
|---|
| 130 | #endif
|
|---|
| 131 |
|
|---|
| 132 | //const MGeomPix &pix = (*fGeomCam)[i];
|
|---|
| 133 |
|
|---|
| 134 | }
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | // ------------------------------------------------------------------------
|
|---|
| 138 | //
|
|---|
| 139 | // Draw all pixels of the camera
|
|---|
| 140 | // (means apend all pixelobjects to the current pad)
|
|---|
| 141 | //
|
|---|
| 142 | void MagicTriggerDisplay::DrawHexagons()
|
|---|
| 143 | {
|
|---|
| 144 | for (UInt_t i=0; i<fNumPixels; i++)
|
|---|
| 145 | (*this)[i].Draw();
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | // ------------------------------------------------------------------------
|
|---|
| 149 | //
|
|---|
| 150 | // default constructor
|
|---|
| 151 | //
|
|---|
| 152 | MagicTriggerDisplay::MagicTriggerDisplay(const TGWindow *p, UInt_t w, UInt_t h)
|
|---|
| 153 | : fGeomCam(NULL), fW(0), fH(0)
|
|---|
| 154 | {
|
|---|
| 155 | // Create a main frame
|
|---|
| 156 | fMain = new TGMainFrame(p,w,h);
|
|---|
| 157 |
|
|---|
| 158 | // Create a canvas widjet
|
|---|
| 159 | fEcanvas = new TRootEmbeddedCanvas("Ecanvas",fMain,w,h);
|
|---|
| 160 | fMain->AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX |
|
|---|
| 161 | kLHintsExpandY, 10, 10, 10, 1));
|
|---|
| 162 | fMain->SetWindowName("MAGIC trigger display");
|
|---|
| 163 |
|
|---|
| 164 | // Create horizontal frame widjets
|
|---|
| 165 | TGHorizontalFrame *hFrame = new TGHorizontalFrame(fMain, 200, 40);
|
|---|
| 166 |
|
|---|
| 167 | //this->Connect("SetValue(Int_t,Int_t","MagicTriggerDisplay",this,"Update(Int_t,Int_t)");
|
|---|
| 168 |
|
|---|
| 169 | // Macrocells stuff
|
|---|
| 170 | cellBackward = new MagicTriggerButton(hFrame,"<<");
|
|---|
| 171 | cellBackward->SetValue(-1,0);
|
|---|
| 172 | //cellBackward->Connect("Signal(Int_t,Int_t)","MagicTriggerDisplay",this,"Update(Int_t,Int_t)");
|
|---|
| 173 | cellBackward->Connect("Signal(Int_t,Int_t)","MagicTriggerDisplay",this,"Update(Int_t,Int_t)");
|
|---|
| 174 | //TQObject::Connect(cellBackward,"Clicked()","MagicTriggerDisplay",this,"Update()");
|
|---|
| 175 | hFrame->AddFrame(cellBackward, new TGLayoutHints(kLHintsCenterX,5,3,3,4));
|
|---|
| 176 |
|
|---|
| 177 | fCellEntry = new TGTextEntry(hFrame, new TGTextBuffer());
|
|---|
| 178 | fCellEntry->Resize(30,fCellEntry->GetDefaultHeight());
|
|---|
| 179 | hFrame->AddFrame(fCellEntry, new TGLayoutHints(kLHintsCenterX,3,3,3,4));
|
|---|
| 180 |
|
|---|
| 181 | MagicTriggerButton *cellForward = new MagicTriggerButton(hFrame,">>");
|
|---|
| 182 | cellForward->SetValue(1,0);
|
|---|
| 183 | cellForward->Connect("Signal(Int_t,Int_t)","MagicTriggerDisplay",this,"Update(Int_t,Int_t)");
|
|---|
| 184 | hFrame->AddFrame(cellForward, new TGLayoutHints(kLHintsCenterX,3,5,3,4));
|
|---|
| 185 |
|
|---|
| 186 | // Draw button
|
|---|
| 187 | MagicTriggerButton *draw = new MagicTriggerButton(hFrame,"&Draw");
|
|---|
| 188 | draw->SetValue(-10,-10);
|
|---|
| 189 | draw->Connect("Signal(Int_t,Int_t)","MagicTriggerDisplay",this,"Update(Int_t,Int_t)");
|
|---|
| 190 | hFrame->AddFrame(draw, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
|
|---|
| 191 |
|
|---|
| 192 | // LUT stuff
|
|---|
| 193 | MagicTriggerButton *LUTBackward = new MagicTriggerButton(hFrame,"<<");
|
|---|
| 194 | LUTBackward->SetValue(0,-1);
|
|---|
| 195 | LUTBackward->Connect("Signal(Int_t,Int_t)","MagicTriggerDisplay",this,"Update(Int_t,Int_t)");
|
|---|
| 196 | hFrame->AddFrame(LUTBackward, new TGLayoutHints(kLHintsCenterX,5,3,3,4));
|
|---|
| 197 |
|
|---|
| 198 | fLUTEntry = new TGTextEntry(hFrame, new TGTextBuffer());
|
|---|
| 199 | fLUTEntry->Resize(30,fCellEntry->GetDefaultHeight());
|
|---|
| 200 | hFrame->AddFrame(fLUTEntry, new TGLayoutHints(kLHintsCenterX,3,3,3,4));
|
|---|
| 201 |
|
|---|
| 202 | MagicTriggerButton *LUTForward = new MagicTriggerButton(hFrame,">>");
|
|---|
| 203 | LUTForward->SetValue(0,1);
|
|---|
| 204 | LUTForward->Connect("Signal(Int_t,Int_t)","MagicTriggerDisplay",this,"Update(Int_t,Int_t)");
|
|---|
| 205 | hFrame->AddFrame(LUTForward, new TGLayoutHints(kLHintsCenterX,3,5,3,4));
|
|---|
| 206 |
|
|---|
| 207 | // Exit stuff
|
|---|
| 208 | TGHorizontalFrame *hExitFrame = new TGHorizontalFrame(fMain, 200, 40);
|
|---|
| 209 | TGTextButton *exit = new TGTextButton(hExitFrame,"&Exit",
|
|---|
| 210 | "gApplication->Terminate(0)");
|
|---|
| 211 |
|
|---|
| 212 | hExitFrame->AddFrame(exit, new TGLayoutHints(kLHintsCenterX,5,5,10,4));
|
|---|
| 213 |
|
|---|
| 214 | fMain->AddFrame(hFrame, new TGLayoutHints(kLHintsCenterX,2,2,2,2));
|
|---|
| 215 | fMain->AddFrame(hExitFrame, new TGLayoutHints(kLHintsCenterX,2,2,2,2));
|
|---|
| 216 |
|
|---|
| 217 | fMain->MapSubwindows();
|
|---|
| 218 | fMain->Resize(fMain->GetDefaultSize());
|
|---|
| 219 | fMain->MapWindow();
|
|---|
| 220 |
|
|---|
| 221 | SetNewCamera(new MGeomCamMagic);
|
|---|
| 222 |
|
|---|
| 223 | fTrig = new MMcTriggerLvl2();
|
|---|
| 224 | fPixelsInLUT = fTrig->GetPixelsInLut();
|
|---|
| 225 | fPixelsInCell = fTrig->GetPixelsInCell();
|
|---|
| 226 |
|
|---|
| 227 | cn = ln = 1;
|
|---|
| 228 | //
|
|---|
| 229 | // Make sure, that the object is destroyed when the canvas/pad is
|
|---|
| 230 | // destroyed. Make also sure, that the interpreter doesn't try to
|
|---|
| 231 | // delete it a second time.
|
|---|
| 232 | //
|
|---|
| 233 | SetBit(kCanDelete);
|
|---|
| 234 | gInterpreter->DeleteGlobal(this);
|
|---|
| 235 |
|
|---|
| 236 | Draw();
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | // ------------------------------------------------------------------------
|
|---|
| 240 | //
|
|---|
| 241 | // Destructor. Deletes TClonesArrays for hexagons and legend elements.
|
|---|
| 242 | //
|
|---|
| 243 | // ------------------------------------------------------------------------
|
|---|
| 244 | //
|
|---|
| 245 | // This is called at any time the canvas should get repainted.
|
|---|
| 246 | // Here we maintain an aspect ratio of 5/4=1.15. This makes sure,
|
|---|
| 247 | // that the camera image doesn't get distorted by resizing the canvas.
|
|---|
| 248 | //
|
|---|
| 249 | void MagicTriggerDisplay::Update(const Int_t cell, const Int_t lut)
|
|---|
| 250 | {
|
|---|
| 251 | Int_t pixid;
|
|---|
| 252 | char text[10];
|
|---|
| 253 |
|
|---|
| 254 | switch(cell){
|
|---|
| 255 | case -10:
|
|---|
| 256 | cn = atoi(fCellEntry->GetText());
|
|---|
| 257 | ln = atoi(fLUTEntry->GetText());
|
|---|
| 258 | cout << "cn"<<cn<<" ln="<<ln<<endl;
|
|---|
| 259 | break;
|
|---|
| 260 | case 0:
|
|---|
| 261 | if(lut==1) ln = atoi(fLUTEntry->GetText())+1;
|
|---|
| 262 | else if(lut==-1) ln = atoi(fLUTEntry->GetText()) - 1;
|
|---|
| 263 | else cout << "MagicTriggerDisplay::Update ERROR: BAD lut number sent by signal" << endl;
|
|---|
| 264 | break;
|
|---|
| 265 | case 1:
|
|---|
| 266 | if(lut==0) cn = atoi(fCellEntry->GetText()) + 1;
|
|---|
| 267 | else cout << "MagicTriggerDisplay::Update ERROR: BAD lut number sent by signal" << endl;
|
|---|
| 268 | break;
|
|---|
| 269 | case -1:
|
|---|
| 270 | if(lut==0) cn = atoi(fCellEntry->GetText()) - 1;
|
|---|
| 271 | else cout << "MagicTriggerDisplay::Update ERROR: BAD lut number sent by signal" << endl;
|
|---|
| 272 | break;
|
|---|
| 273 | default:
|
|---|
| 274 | cout << "Invalid cell number sent by the signal";
|
|---|
| 275 | break;
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | if((cn>=kMinCell) && (cn<=kMaxCell) && (ln>=kMinLUT) && (ln<=kMaxLUT)){
|
|---|
| 279 | sprintf(text,"%i",ln);
|
|---|
| 280 | fLUTEntry->SetText(text);
|
|---|
| 281 | sprintf(text,"%i",cn);
|
|---|
| 282 | fCellEntry->SetText(text);
|
|---|
| 283 | for(UInt_t i=0; i<fNumPixels; i++)
|
|---|
| 284 | (*this)[i].SetFillColor(22);
|
|---|
| 285 | for(Int_t i=0; i<12; i++){
|
|---|
| 286 | //cout << "cacca" << endl;
|
|---|
| 287 | //cout << fPixelsInLUT[(ln-1)*kMaxLUT+i]-1 << endl;
|
|---|
| 288 | //cout << "--" << endl;
|
|---|
| 289 | pixid = fPixelsInCell[(fPixelsInLUT[(ln-1)*12+i]-1)*kMaxCell+(cn-1)]-1;
|
|---|
| 290 | //cout << "molla" << endl;
|
|---|
| 291 | cout << "pixid=" << pixid << endl;
|
|---|
| 292 | (*this)[pixid].SetFillColor(28);
|
|---|
| 293 | //cout << "profumata" << endl;
|
|---|
| 294 | }
|
|---|
| 295 | DrawHexagons();
|
|---|
| 296 | fDrawingPad->Modified();
|
|---|
| 297 | fDrawingPad->Update();
|
|---|
| 298 | }
|
|---|
| 299 | else{
|
|---|
| 300 | cn = atoi(fCellEntry->GetText());
|
|---|
| 301 | ln = atoi(fLUTEntry->GetText());
|
|---|
| 302 | cout << "Che cazzo fai PIRLA!" << endl;
|
|---|
| 303 | }
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 | // ------------------------------------------------------------------------
|
|---|
| 307 | //
|
|---|
| 308 | // Call this function to draw the camera layout into your canvas.
|
|---|
| 309 | // Setup a drawing canvas. Add this object and all child objects
|
|---|
| 310 | // (hexagons, etc) to the current pad. If no pad exists a new one is
|
|---|
| 311 | // created.
|
|---|
| 312 | //
|
|---|
| 313 | void MagicTriggerDisplay::Draw(Option_t *opt)
|
|---|
| 314 | {
|
|---|
| 315 | // root 3.02:
|
|---|
| 316 | // gPad->SetFixedAspectRatio()
|
|---|
| 317 |
|
|---|
| 318 | //fDrawingPad = fEcanvas->GetCanvas();
|
|---|
| 319 | //if (fDrawingPad)
|
|---|
| 320 | // return;
|
|---|
| 321 |
|
|---|
| 322 | //
|
|---|
| 323 | // if no canvas is yet existing to draw into, create a new one
|
|---|
| 324 | //
|
|---|
| 325 | //if (!gPad)
|
|---|
| 326 | //{
|
|---|
| 327 | // /*TCanvas *c =*/ new TCanvas("MagicReversi", "Magic Reversi", 0, 0, 800, 800);
|
|---|
| 328 | //c->ToggleEventStatus();
|
|---|
| 329 | // fIsAllocated = kTRUE;
|
|---|
| 330 | //}
|
|---|
| 331 | //else
|
|---|
| 332 | //fIsAllocated = kTRUE;
|
|---|
| 333 |
|
|---|
| 334 | fDrawingPad = gPad;
|
|---|
| 335 | fDrawingPad->SetBorderMode(0);
|
|---|
| 336 | fDrawingPad->SetFillColor(22);
|
|---|
| 337 |
|
|---|
| 338 | //
|
|---|
| 339 | // Append this object, so that the aspect ratio is maintained
|
|---|
| 340 | // (Paint-function is called)
|
|---|
| 341 | //
|
|---|
| 342 | AppendPad(opt);
|
|---|
| 343 |
|
|---|
| 344 | //
|
|---|
| 345 | // Draw the title text
|
|---|
| 346 | //
|
|---|
| 347 | //for (int i=0; i<6; i++)
|
|---|
| 348 | //{
|
|---|
| 349 | // fUsrTxt[i] = new TText;
|
|---|
| 350 | // fUsrTxt[i]->SetTextAlign(13); // left/bottom
|
|---|
| 351 | // fUsrTxt[i]->SetTextSize(0.03);
|
|---|
| 352 | // fUsrTxt[i]->SetTextColor(kRed+i);
|
|---|
| 353 | //#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
|
|---|
| 354 | // fUsrTxt[i]->SetBit(kNoContextMenu|kCannotPick);
|
|---|
| 355 | //#endif
|
|---|
| 356 | // fUsrTxt[i]->Draw();
|
|---|
| 357 | //}
|
|---|
| 358 |
|
|---|
| 359 | //
|
|---|
| 360 | // Reset the game pad
|
|---|
| 361 | //
|
|---|
| 362 | //Reset();
|
|---|
| 363 | DrawHexagons();
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | void MagicTriggerDisplay::Paint(Option_t *opt)
|
|---|
| 367 | {
|
|---|
| 368 | const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
|
|---|
| 369 | const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
|
|---|
| 370 |
|
|---|
| 371 | //
|
|---|
| 372 | // Check for a change in width or height, and make sure, that the
|
|---|
| 373 | // first call also sets the range
|
|---|
| 374 | //
|
|---|
| 375 | if (w*fH == h*fW && fW && fH)
|
|---|
| 376 | return;
|
|---|
| 377 |
|
|---|
| 378 | //
|
|---|
| 379 | // Calculate aspect ratio (5/4=1.25 recommended)
|
|---|
| 380 | //
|
|---|
| 381 | const Double_t ratio = (Double_t)w/h;
|
|---|
| 382 |
|
|---|
| 383 | Float_t x;
|
|---|
| 384 | Float_t y;
|
|---|
| 385 |
|
|---|
| 386 | if (ratio>1.0)
|
|---|
| 387 | {
|
|---|
| 388 | x = fRange*(ratio*2-1);
|
|---|
| 389 | y = fRange;
|
|---|
| 390 | }
|
|---|
| 391 | else
|
|---|
| 392 | {
|
|---|
| 393 | x = fRange;
|
|---|
| 394 | y = fRange/ratio;
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | fH = h;
|
|---|
| 398 | fW = w;
|
|---|
| 399 | //
|
|---|
| 400 | // Set new range
|
|---|
| 401 | //
|
|---|
| 402 | fDrawingPad->Range(-fRange, -y, x, y);
|
|---|
| 403 | }
|
|---|