Ignore:
Timestamp:
03/01/09 21:54:27 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mtools/MagicReversi.cc

    r8756 r9369  
    22!
    33! *
    4 ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
     4! * This file is part of CheObs, the Modular Analysis and Reconstruction
    55! * Software. It is distributed to you in the hope that it can be a useful
    66! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
     
    99! * Permission to use, copy, modify and distribute this software and its
    1010! * documentation for any purpose is hereby granted without fee,
    11 ! * provided that the above copyright notice appear in all copies and
     11! * provided that the above copyright notice appears in all copies and
    1212! * that both that copyright notice and this permission notice appear
    1313! * in supporting documentation. It is provided "as is" without express
     
    1616!
    1717!
    18 !   Author(s): Thomas Bretz 03/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
     18!   Author(s): Thomas Bretz3/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2003
     20!   Copyright: CheObs Software Development, 2000-2009
    2121!
    2222!
     
    6262#include <TInterpreter.h>
    6363
    64 #include "MHexagon.h"
     64#include "MH.h"
    6565
    6666#include "MGeomPix.h"
     
    8888        return;
    8989
    90     fPixels->Delete();
    9190    fText->Delete();
    9291    fFlags->Delete();
     
    9493    delete fText;
    9594    delete fFlags;
    96     delete fPixels;
    9795
    9896    delete fGeomCam;
     
    113111
    114112    Reset();
    115     DrawHexagons();
    116113}
    117114
     
    119116{
    120117    Free();
    121 
    122     //
    123     //  Reset the display geometry
    124     //
    125     fW=0;
    126     fH=0;
    127118
    128119    //
     
    144135    fText   = new TClonesArray("TText",    fNumPixels);
    145136    fFlags  = new TClonesArray("TMarker",  fNumPixels);
    146     fPixels = new TClonesArray("MHexagon", fNumPixels);
     137    fColors.Set(fNumPixels);
    147138
    148139    for (UInt_t i=0; i<fNumPixels; i++)
    149140    {
    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];
    154142
    155143        TText &t = *new ((*fText)[i]) TText;
    156144        t.SetTextFont(122);
    157145        t.SetTextAlign(22);   // centered/centered
    158         t.SetTextSize(0.3*h.GetD()/fRange);
     146        t.SetTextSize(0.3*pix.GetT()/fRange);
    159147#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    160148        t.SetBit(kNoContextMenu|kCannotPick);
    161149#endif
    162 
    163         const MGeomPix &pix = (*fGeomCam)[i];
    164150
    165151        TMarker &m = *new ((*fFlags)[i]) TMarker(pix.GetX(), pix.GetY(), kOpenStar);
     
    170156}
    171157
     158/*
    172159// ------------------------------------------------------------------------
    173160//
     
    180167        (*this)[i].Draw();
    181168}
     169*/
    182170
    183171void MagicReversi::Init()
     
    201189//
    202190MagicReversi::MagicReversi()
    203     : fGeomCam(NULL), fDone(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
     191    : fGeomCam(NULL), fDone(NULL)
    204192{
    205193    SetNewCamera(new MGeomCamMagic);
     
    209197
    210198MagicReversi::MagicReversi(const MGeomCam &geom)
    211     : fGeomCam(NULL), fDone(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
     199    : fGeomCam(NULL), fDone(NULL)
    212200{
    213201    SetNewCamera(static_cast<MGeomCam*>(geom.Clone()));
     
    229217    if (fDone)
    230218        delete fDone;
    231 
    232     if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
    233     {
    234         fDrawingPad->RecursiveRemove(this);
    235         delete fDrawingPad;
    236     }
    237219}
    238220
     
    245227void MagicReversi::Paint(Option_t *opt)
    246228{
    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:
    287237    for (UInt_t i=0; i<fNumPixels; i++)
    288238    {
    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;
    290248        GetFlag(i)->SetMarkerSize(20.0*r/fRange);
     249
     250        if (pix.TestBit(kHasFlag))
     251            GetFlag(i)->Paint();
     252
     253        GetText(i)->Paint();
    291254    }
    292255}
     
    301264void MagicReversi::Draw(Option_t *option)
    302265{
    303     // root 3.02:
    304     // gPad->SetFixedAspectRatio()
    305 
    306     if (fDrawingPad)
    307         return;
    308 
    309266    //
    310267    // if no canvas is yet existing to draw into, create a new one
    311268    //
    312269    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);
    323273
    324274    //
     
    347297    //
    348298    Reset();
    349     DrawHexagons();
    350299}
    351300
     
    411360    for (UInt_t i=0; i<fNumPixels; i++)
    412361    {
    413         Remove(GetText(i));
    414         Remove(GetFlag(i));
    415 
    416         (*this)[i].SetFillColor(kEmpty);
     362        fColors[i] = kEmpty;
    417363        (*fGeomCam)[i].ResetBit(kUserBits);
    418364
    419365        GetFlag(i)->SetMarkerColor(kBlack);
     366        GetText(i)->SetText(0, 0, "");
    420367    }
    421368
     
    427374    for (int i=1; i<5*fNumUsers; i++)
    428375    {
    429         (*this)[i-1].SetFillColor(i%fNumUsers+kRed);
     376        fColors[i-1] = i%fNumUsers+kRed;
    430377        fUsrPts[i%fNumUsers]++;
    431378    }
     
    433380    Update();
    434381
    435     fDrawingPad->SetFillColor(22);
     382    gPad->SetFillColor(22);
    436383
    437384#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    438     fDrawingPad->SetBit(kNoContextMenu);
    439385    SetBit(kNoContextMenu);
    440386#endif
     
    468414    fDone->Draw();
    469415
    470     fDrawingPad->SetFillColor(winner+kRed);
     416    gPad->SetFillColor(winner+kRed);
    471417
    472418#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
    473     fDrawingPad->ResetBit(kNoContextMenu);
    474419    ResetBit(kNoContextMenu);
    475420#endif
    476 }
    477 
    478 void MagicReversi::Remove(TObject *obj)
    479 {
    480     fDrawingPad->RecursiveRemove(obj);
    481421}
    482422
     
    495435        {
    496436            idx = fGeomCam->GetNeighbor(idx, dir);
    497             if (idx<0 || (*this)[idx].GetFillColor()==kEmpty)
     437            if (idx<0 || fColors[idx]==kEmpty)
    498438                break;
    499439
    500             if ((*this)[idx].GetFillColor()==col)
     440            if (fColors[idx]==col)
    501441            {
    502442                if (length!=0)
     
    523463                idx = fGeomCam->GetNeighbor(idx, dir);
    524464
    525                 fUsrPts[(*this)[idx].GetFillColor()-kRed]--;
     465                fUsrPts[fColors[idx]-kRed]--;
    526466                fUsrPts[fNumUser]++;
    527467
    528                 (*this)[idx].SetFillColor(col);
     468                fColors[idx] = col;
    529469            }
    530470    }
     
    536476{
    537477    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))
    539479            return kTRUE;
    540480    return kFALSE;
     
    557497    {
    558498        Done();
    559         fDrawingPad->Modified();
    560         fDrawingPad->Update();
     499        gPad->Modified();
     500        gPad->Update();
    561501        return;
    562502    }
     
    564504    UInt_t idx;
    565505    for (idx=0; idx<fNumPixels; idx++)
    566         if ((*fPixels)[idx]->DistancetoPrimitive(px, py)==0)
     506        if ((*fGeomCam)[idx].DistancetoPrimitive(px, py)<=0)
    567507            break;
    568508
     
    570510        return;
    571511
    572     if (event==kButton1Down && (*this)[idx].GetFillColor()==kEmpty)
     512    if (event==kButton1Down && fColors[idx]==kEmpty)
    573513    {
    574514        if (!Flip(idx, kTRUE))
     
    577517        fUsrPts[fNumUser]++;
    578518
    579         (*this)[idx].SetFillColor(kRed+fNumUser);
     519        fColors[idx] = kRed+fNumUser;
    580520
    581521        Int_t start = fNumUser;
     
    600540    }
    601541
    602     fDrawingPad->Modified();
    603 }
     542    gPad->Modified();
     543}
Note: See TracChangeset for help on using the changeset viewer.