BaseLSPlayer.cpp 27.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/***************************************************************************
 *   Copyright (C) 2004-2006 by Olivier Stezowski & Christian Finck        *
 *   stezow(AT)ipnl.in2p3.fr, cfinck(AT)ires.in2p3.fr                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
17
 *   Free Software Foundation, Inc.,                                       *
18 19 20 21 22 23 24 25 26 27 28 29
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

/** \file BaseLSPlayer.cpp compiled in libGWPHYSICS.so */

#include <Riostream.h>


#ifndef ROOT_KeySymbols
#include "KeySymbols.h"
#endif

30 31 32 33
#ifndef ROOT_TBox
#include "TBox.h"
#endif

34 35 36 37
#ifndef ROOT_TCanvas
#include "TCanvas.h"
#endif

38 39 40 41
#ifndef ROOT_TContextMenu
#include "TContextMenu.h"
#endif

42 43 44 45
#ifndef ROOT_TGaxis
#include "TGaxis.h"
#endif

46 47 48 49
#ifndef ROOT_TGToolTip
#include "TGToolTip.h"
#endif

50 51 52 53 54 55 56 57
#ifndef ROOT_TList
#include "TList.h"
#endif

#ifndef ROOT_TMath
#include "TMath.h"
#endif

58 59 60 61
#ifndef ROOT_TMethod
#include "TMethod.h"
#endif

62 63 64 65
#ifndef ROOT_TPad
#include "TPad.h"
#endif

66 67 68 69
#ifndef ROOT_TVirtualX
#include "TVirtualX.h"
#endif

70 71 72 73 74 75 76 77 78 79 80 81
#ifndef ROOT_TROOT
#include "TROOT.h"
#endif

#ifndef Gw_BaseLSPlayer
#include "BaseLSPlayer.h"
#endif

#ifndef Gw_BaseNucleus
#include "BaseNucleus.h"
#endif

82 83 84 85 86 87 88 89
#ifndef Gw_GammaLink
#include "GammaLink.h"
#endif

#ifndef Gw_NuclearLevel
#include "NuclearLevel.h"
#endif

90 91 92 93
#ifndef Gw_Peak1D
#include "Peak1D.h"
#endif

94 95 96 97 98 99 100 101 102 103
#ifndef Gw_EnsdfLevelSchemeReader
#include "EnsdfLevelSchemeReader.h"
#endif

#ifndef Gw_RadLevelSchemeReader
#include "RadLevelSchemeReader.h"
#endif


using namespace Gw;
104
Float_t BaseLSPlayer::fgDefaultSize[4] = {28000, 32000, 0, 6000};
105
Float_t BaseLSPlayer::fgDefaultWidth   = 600;   
106
Int_t   BaseLSPlayer::fgDefaultToggleColor = 24;
107 108 109 110

//

//__________________________________________________________
111
BaseLSPlayer::BaseLSPlayer(LevelScheme* levelScheme) :
112
	TNamed("BaseLSPlayer", "Default"),
113 114 115 116 117
	fLastX(0),
	fLastY(0),
	fBox(new TBox(0, fgDefaultWidth, 0, fgDefaultWidth)),
	fSelectedLinks(new Cascade()),
	fSelectedLevels(new Cascade()),
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
118 119
    fSelectedCascades(new TList()),
    fNucleiList(new TList()),
120 121
	fLevelScheme(levelScheme),
	fDrawStyle(kUnknown),
122
	fAxis(new LSaxis()),
123 124 125 126
	fInfoTip(new TGToolTip(fBox, "", 350)),
	fIsOnAxis(true),
	fIsTipsOn(true),
	fIsLSSelected(false),
127
    fContextMenu(NULL),
128
	fCColorSelectedLink(BasePeak::gGateColor.k0),
129
    fPositionLabels(0.),
130
	fLog("BaseLSPlayer")
131 132
    //,
   // fURLtoSaveLS("./")
133 134
{ 
  // default constructor
135

136
  fSelectedCascades->SetOwner(false);
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
137
  fNucleiList->SetOwner(true);
138 139 140
  fAxis->SetLineWidth(2);
  fAxis->SetNdivisions(510);
  fAxis->SetLabelSize(0.04);
141 142 143 144 145 146 147 148 149
}

//__________________________________________________________
BaseLSPlayer::~BaseLSPlayer()
{
  // default destructor
  delete fSelectedLinks; // default wise not owner of the links (levels)
  delete fSelectedLevels;
  delete fSelectedCascades;
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
150
  delete fNucleiList;
151
  delete fAxis;
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
  delete fInfoTip;
  delete fBox;
}

//__________________________________________________________
void BaseLSPlayer::SetTipText(TObject* select)
{
  
  TString name(select->ClassName());
  
  if ( name.CompareTo("Gw::Link")  == 0 ) {
    Link* link = static_cast<Link*> ( select );
    fInfoTip->SetText(Form("Strength: %5.1f", link->GetStrength().Get()) );
  }
  
  if ( name.CompareTo("Gw::Level")  == 0 ) {
    fInfoTip->SetText("Level");
  }
  
  if ( select->InheritsFrom("Gw::GammaLink") ) {
    GammaLink* link = static_cast<GammaLink*> ( select );
173 174 175 176
	if (link->IsE()) 
	  fInfoTip->SetText(Form("Strength: %6.1f\nEnergy:   %6.1f\nPolarity:   E%d", link->GetStrength().Get(), link->GetEnergy().Get(), link->GetLambda()) );
	 else
	  fInfoTip->SetText(Form("Strength: %6.1f\nEnergy:   %6.1f\nPolarity:   M%d", link->GetStrength().Get(), link->GetEnergy().Get(), link->GetLambda()) );
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
  }
      
  if ( select->InheritsFrom("Gw::NuclearLevel") ) {
    NuclearLevel* level = static_cast<NuclearLevel*> ( select );
    if ( level->GetParity().IsParity(Parity::kPlus) )
      fInfoTip->SetText(Form("Energy: %6.1f\nSpin: %s+\nHalf-Live: %6.1f", 
                             level->GetEnergy().Get(), 
                             level->GetSpin().GetString(),
                             level->GetT().Get()) );
    else
      fInfoTip->SetText(Form("Energy: %6.1f\nSpin: %s-\nHalf-Live: %6.1f", 
                             level->GetEnergy().Get(), 
                             level->GetSpin().GetString(),
                             level->GetT().Get()) );  
  }
                      
193 194 195 196 197
}

//__________________________________________________________
Bool_t BaseLSPlayer::Connect(TCanvas *canvas)
{
198 199
  fLog.SetProcessMethod("Connect(TCanvas* )");

200 201 202 203 204 205 206
  TCanvas *localCanvas = canvas;
  
  // in this case connect the current canvas	
  if ( canvas == 0x0 ) {
	if ( TVirtualPad::Pad() )
          localCanvas = TVirtualPad::Pad()->GetCanvas();
	else {
207
          fLog << warning << "Pad not existing yet" << nline ; 
208 209 210 211 212 213 214
        }
  } 
  if ( localCanvas) {
    localCanvas->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
                         "Gw::BaseLSPlayer",
                          this,
                         "HandleMovement(Int_t, Int_t, Int_t, TObject*)");
215
    fContextMenu = localCanvas->GetContextMenu();
216
  }
217
  
218 219
  fLog << dolog;
	
220 221 222 223 224 225
  return localCanvas != 0x0;
}

 //__________________________________________________________
Bool_t BaseLSPlayer::Disconnect(TCanvas *canvas)
{
226 227
	fLog.SetProcessMethod("Disconnect(TCanvas* )");

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
	TCanvas *localCanvas = canvas;

	// in this case connect the current canvas	
	if ( canvas == 0x0 ) {
		if ( TVirtualPad::Pad() ) {
			 localCanvas = TVirtualPad::Pad()->GetCanvas();
		} else {
			 fLog << error << "Pad not existing" << dolog; 
		}
	} 
	if ( localCanvas ) {
	  TQObject::Disconnect(localCanvas,"HandleMovement(Int_t, Int_t, Int_t, TObject*)",this); 	
	}

	fContextMenu = 0x0;
	
	fLog << dolog;
	return localCanvas != 0x0;
246 247
} 

248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
void BaseLSPlayer::RefreshLinks()
{
    for(int i=0 ; i<GetLinkList().GetEntries() ; i++) {
        if(GetLinkList().At(i)->InheritsFrom("Gw::Link")) {
            Link* link = static_cast<Link*>(GetLinkList().At(i));

            link->RefreshPoints();
            link->Paint();
        }
    }

    gPad->Modified();
    gPad->Update();
}

263 264 265 266
//__________________________________________________________
void BaseLSPlayer::HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject* select)
{ 
  // handle cursor mouvement
267 268 269
    
   TVirtualPad* pad = TVirtualPad::Pad();
   pad->cd(); 
270

271
   if (eventType == kButton1Up) {
272
       RefreshLinks();
273 274
   }

275 276 277 278 279
   if (eventType == kMouseMotion) {
    // to keep track of the last mouse position
    fLastX = eventX; fLastY = eventY;
     
     if ( select->InheritsFrom("Gw::BaseLSPlayer") || 
280 281
          select->InheritsFrom("Gw::Cascade") ||
          select->InheritsFrom("Gw::LevelScheme") ) {
282 283
       pad->SetCursor(kPointer);
     }
284
     
285 286 287 288 289 290 291 292 293 294 295 296
     if ( select->InheritsFrom("Gw::Link") ) {
       Link* link = static_cast<Link*>(select);
       if ( !link->IsMovable() )
         pad->SetCursor(kPointer);
     }
     
     if ( select->InheritsFrom("Gw::Level") ) {
       Level* level = static_cast<Level*>(select);
       if ( !level->IsMovable() )
         pad->SetCursor(kPointer);
     }
     
297 298 299 300 301 302 303 304 305
     if (fIsTipsOn) {
       if ( select->InheritsFrom("Gw::Link") || select->InheritsFrom("Gw::Level")) {
         SetTipText(select);
         fInfoTip->Show(fLastX, fLastY);
       } else 
         fInfoTip->Hide();
     }
   }

306 307 308
  if( eventType == kKeyPress) {
    TObject *obj = 0x0;
    Int_t keysym = eventY;
309
	Color_t color = 0;
310 311 312
    Bool_t keyPress = false;
    switch ((EKeySym) keysym ) {
      case kKey_s:
313
        color = fCColorSelectedLink;
314 315
        keyPress = true;
        break;
316
      case kKey_0:
317
      case kKey_x:
318
        color = BasePeak::gGateColor.k0;
319
		fCColorSelectedLink = color;
320 321
        keyPress = true;
        break;
322
      case kKey_1:
323
      case kKey_y:
324
		color = BasePeak::gGateColor.k1;
325
		fCColorSelectedLink = color;
326 327
        keyPress = true;
        break;
328
      case kKey_2:
329
      case kKey_z:
330
		color = BasePeak::gGateColor.k2;
331
		fCColorSelectedLink = color;
332 333
        keyPress = true;
        break;
334 335
	  case kKey_3:
		color = BasePeak::gGateColor.k3;
336
		fCColorSelectedLink = color;
337 338 339
        keyPress = true;
        break;
		
340 341 342 343 344 345 346 347
      default:
        keyPress = false;
        break;
    }
    
    if ( select->InheritsFrom("Gw::Link") && keyPress) {
      Link* link = static_cast<Link*>(select);
      if (link->IsSelected()) {
348
        link->SetFillColor( Link::GetDefaultColor() );
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
        link->DeSelected();
        fSelectedLinks->Remove(link);
      } else {
        link->SetFillColor(color);
        link->Selected();
        fSelectedLinks->Add(link);
      }
      TIter next(fSelectedLinks);
      while ( (obj = next()) )
        link = static_cast<Link*> ( obj );
      fLevelScheme->SetCLink(link);
    }
    
    if ( (EKeySym)keysym == kKey_s) {
      
       if ( select->InheritsFrom("Gw::Level") ) {
         Level* level = static_cast<Level*>(select);
         if (level->IsSelected()) {
           level->SetLineColor( Level::GetDefaultColor(level->GetDefaultColor()) );
           level->DeSelected();
           fSelectedLevels->Remove(level);
         } else {
           level->SetLineColor( Level::GetDefaultColor(Level::kSelected) );
           level->Selected();
           fSelectedLevels->Add(level);
         }
         TIter next(fSelectedLevels);
         while ( (obj = next()) )
           level = static_cast<Level*> ( obj );
         fLevelScheme->SetCLevel(level);
       }  
      
      Link* link = 0x0;
      if ( select->InheritsFrom("Gw::Cascade") ) {
        Cascade* cas = static_cast<Cascade*>(select);
        if (cas->IsSelected()) {
          for (Int_t i = 0; i < cas->GetSize(); ++i) {
            link = static_cast<Link*> (cas->At(i));
387
            link->SetFillColor( Link::GetDefaultColor() );
388 389 390 391 392 393 394 395
            link->DeSelected();
          }
          cas->DeSelected();
          cas->SetLabelColor(Cascade::kDefault);
          fSelectedCascades->Remove(cas);
        } else {
          for (Int_t i = 0; i < cas->GetSize(); ++i) {
            link = static_cast<Link*> (cas->At(i));
396
            link->SetFillColor(fCColorSelectedLink);
397 398 399 400 401 402 403 404 405 406 407 408 409
            link->Selected();
          }
          cas->Selected();
          cas->SetLabelColor(Cascade::kSelected);
          fSelectedCascades->Add(cas);
        }
        TIter next(fSelectedCascades);
        while ( (obj = next()) )
          cas = static_cast<Cascade*> ( obj );
        fLevelScheme->SetCCascade(cas);
      }     
    }
    
410 411
    if ( (EKeySym)keysym == kKey_g) 
      ShowGate();
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
412 413 414
	
	if ( (EKeySym)keysym == kKey_P) 
      DrawProjTot();
415

416
    if ( (EKeySym)keysym == kKey_t) {
417
      if (fIsOnAxis == true) {
418
        fIsOnAxis = false;
419 420
        fAxis->SetLineColor(GetDefaultToggleColor());
        fAxis->SetLabelColor(GetDefaultToggleColor());
421 422
      }
      else if (fIsOnAxis == false) {
423
        fIsOnAxis = true;
424 425
        fAxis->SetLineColor(1);
        fAxis->SetLabelColor(1);
426
      }
427 428
    }
      
429 430 431 432 433 434 435 436
    if ( (EKeySym)keysym == kKey_i) {
      if (fIsTipsOn == true) {
        fIsTipsOn = false;
        fInfoTip->Hide();
      } else if (fIsTipsOn == false) 
        fIsTipsOn = true;
    }
    
437 438 439 440 441 442 443 444 445 446 447
    if ( (EKeySym)keysym == kKey_a) {
      if (fIsLSSelected == true) {
        fIsLSSelected = false;
        DeSelect();
      } else if (fIsLSSelected == false) {
        fIsLSSelected = true;
        Select();
      }
    }
    
    
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
448 449 450 451 452 453
    if ( (EKeySym)keysym == kKey_h) {
      cout << "Keys used to interact with LSPlayer: " << endl;
      cout << "\t s: select a link/level/cascade " << endl;
      cout << "\t 1/x: select a link for a gate on x-axis " << endl;
      cout << "\t 2/y: select a link for a gate on y-axis " << endl;
      cout << "\t 3/z: select a link for a gate on z-axis " << endl;
454
      cout << "\t 4  : select a link for a gate on t-axis " << endl;
455
      cout << "\t a:   select the whole level scheme " << endl;
456
      cout << "\t g: Show gates " << endl;
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
457
	  cout << "\t P: Draw total projection " << endl;					
458
	  cout << "\t i: Toggle on/off information tips that appears when passing over an object" << endl; 
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
459
      cout << "\t t: Toggle on/off active LS menu on canvas " << endl;					
460
      cout << "\t l: Popup dialog box for Add Link method " << endl;					
461
      cout << "\t e: Popup dialog box for Add Level method " << endl;					
462 463
	  cout << "\t f: Popup dialog box for Add First Level method " << endl;					
	  cout << "\t G: Popup dialog box for Add Ground Level method " << endl;					
464
      cout << "\t w: Popup dialog box for writing level scheme in a root file " << endl;					
465
      cout << "\t p: Popup dialog box for making projection from registered correlated space " << endl;					
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
466
    }	
467

468 469 470
    if ( (EKeySym)keysym == kKey_l) 
      PopupAddLink();
    
471 472 473
	if ( (EKeySym)keysym == kKey_e) 
      PopupAddLevel();

474 475
    if ( (EKeySym)keysym == kKey_f) 
      PopupAddFirstLevel();
476 477 478
	 
	 if ( (EKeySym)keysym == kKey_G) 
		PopupAddGroundLevel();
479 480 481
    
    if ( (EKeySym)keysym == kKey_w) 
      PopupWriteLS();
482 483 484
	
	if ( (EKeySym)keysym == kKey_p) 
	  PopupDoProject();
485 486 487 488 489 490

    if(eventX != -666)
    {
        pad->Modified();
        pad->Update();
    }
491 492 493 494 495 496 497 498
  }
  
  pad->cd();
}

//__________________________________________________________
Int_t BaseLSPlayer::CollectLinks(Option_t* o) 
{
499 500
    fLog.SetProcessMethod("CollectLinks(Option_t* )");

501 502
  // create link list from pad
  
503
  TVirtualPad* pad = TVirtualPad::Pad();
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
  pad->cd();

  if ( !pad ) {
    fLog << error << "Pad not existing" << dolog; 
    return 0;
  }
  
  TString opt = o;
  if ( !opt.Contains("+") ) 
    fSelectedLinks->Clear();
  
  TObject *obj; Int_t i = 0;
  
  TIter next(TVirtualPad::Pad()->GetListOfPrimitives());
  while ( (obj = next()) )  // iterator skips empty slots
    if ( obj->InheritsFrom("Gw::Link") ) {
      if (!fSelectedLinks->FindObject(obj)) {
        Link* link = static_cast<Link*> (obj);
        if ( link->IsSelected() ) {
            fSelectedLinks->Add(obj); i++;
        }
      }	
    }
  
  fLog << info << Form("Collect %d links", i) << dolog; 
  return i;
}

//__________________________________________________________
Int_t BaseLSPlayer::CollectLevels(Option_t* o) 
534 535 536
{	
    fLog.SetProcessMethod("CollectLevels(Option_t* )");

537 538
  // create link list from pad
  
539
  TVirtualPad* pad = TVirtualPad::Pad();
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
  pad->cd();
  
  if ( !pad ) {
    fLog << error << "Pad not existing" << dolog; 
    return 0;
  }
  
  TString opt = o;
  if ( !opt.Contains("+") ) 
    fSelectedLevels->Clear();
  
  TObject *obj; Int_t i = 0;
  
  TIter next(TVirtualPad::Pad()->GetListOfPrimitives());
  while ( (obj = next()) )  // iterator skips empty slots
    if ( obj->InheritsFrom("Gw::Level") ) {
      if (!fSelectedLevels->FindObject(obj)) {
        Level* level = static_cast<Level*> (obj);
        if ( level->IsSelected() ) {
          fSelectedLevels->Add(obj); i++;
        }
      }	
    }
  
  fLog << info << Form("Collect %d levels", i) << dolog; 
  return i;
}

//__________________________________________________________
Int_t BaseLSPlayer::CollectCascades(Option_t* o) 
{
571 572
    fLog.SetProcessMethod("CollectCascades(Option_t* )");

573 574
  // create link list from pad
  
575
  TVirtualPad* pad = TVirtualPad::Pad();
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
  pad->cd();
  
  if ( !pad ) {
    fLog << error << "Pad not existing" << dolog; 
    return 0;
  }
  
  TString opt = o;
  if ( !opt.Contains("+") ) 
    fSelectedCascades->Clear();
  
  TObject *obj; Int_t i = 0;
  
  TIter next(TVirtualPad::Pad()->GetListOfPrimitives());
  while ( (obj = next()) )  // iterator skips empty slots
    if ( obj->InheritsFrom("Gw::Cascade") ) {
      if (!fSelectedCascades->FindObject(obj)) {
        Cascade* cas = static_cast<Cascade*> (obj);
        if ( cas->IsSelected() ) {
          fSelectedCascades->Add(obj); i++;
        }
      }	
    }
  
  fLog << info << Form("Collect %d cascades", i) << dolog; 
  return i;
}

//__________________________________________________________
605
Int_t BaseLSPlayer::DistancetoPrimitive(Int_t /*px*/, Int_t /*py*/)
606
{
607 608
  Int_t d;
  if (fIsOnAxis)
609
	d = 9999;
610 611 612
  else
    d = 0;
  
613 614 615 616 617 618 619 620
  return d;
}

//__________________________________________________________
void BaseLSPlayer::Draw(Option_t *opt)
{
  // draw level scheme

621
  fLog.SetProcessMethod("Draw(Option_t* )");
622 623 624 625 626 627
  
  TString style(opt);
  style.ToLower();
  
  Level *level;
  Double_t xmin, xmax, ymin, ymax;
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
628 629
  Double_t xminOld = 0.;
  Double_t xmaxOld = 0.;
630
//  Double_t yminOld = 0.;
C. Finck [IPHC]'s avatar
C. Finck [IPHC] committed
631
  Double_t ymaxOld = 0.;
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654

  Double_t xRminOld, xRmaxOld, yRminOld, yRmaxOld;
  Bool_t p1 = false, p2 = false, pL = false;

  TList* levels   = &fLevelScheme->GetLevelList();
  TList* links    = &fLevelScheme->GetLinkList();
  TList* cascades = &fLevelScheme->GetCascadeList();
  TLatex* name    = &fLevelScheme->GetNameLatex();

  // first draw label
  if (!style.Contains("-t"))
    name->Draw("");
  
  if ( levels->GetSize() == 0 ) return;
  
  // switch to current style
  if (style.Contains("rad") && !IsDrawStyle(kRadware))
    DoStyle(kRadware);
  
  if (style.Contains("ensdf") && !IsDrawStyle(kEnsdf)) {
    DoStyle(kEnsdf);
  }
  
655 656 657 658 659 660 661
  // add all levels to the current pad.
  if (!style.Contains("-le"))
    levels->Draw("");
  
  if (!style.Contains("-b"))
    cascades->Draw("");
  
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
  if (!style.Contains("-l"))
    links->Draw("");
  
  // loop over all levels to determine the canvas range
  level = (Level *)levels->First();
  xmin  = level->GetX1(); xmax = level->GetX2(); ymin = level->GetY1(); ymax = level->GetY2();
  
  TIter iter(levels);
  while ( (level = (Level *)iter()) )  {
    if ( level->GetX1() < xmin ) xmin = level->GetX1();
    if ( level->GetX2() > xmax ) xmax = level->GetX2();
    if ( level->GetY1() < ymin ) ymin = level->GetY1();	
    if ( level->GetY1() > ymax ) ymax = level->GetY1();	
  }
  
677 678
  Double_t xRmin = GetXRmin(xmin, xmax);
  Double_t xRmax = GetXRmax(xmin, xmax);
679
  
680 681
  Double_t yRmin = GetYRmin(ymin, ymax);
  Double_t yRmax = GetYRmax(ymin, ymax);
682 683 684 685 686 687 688 689
  
  
  if ( xmin > xmax || ymin > ymax ) {
    fLog << error << Form(" Problem when computing pad range, xmin > xmax or ymin > ymax") << dolog; 
    return;
  }
  
  if ( TVirtualPad::Pad() != 0 ) {  // in principle, gpad exists
690 691 692

    TVirtualPad::Pad()->Connect("RangeAxisChanged()", "BaseLSPlayer", this, "RefreshLinks()");

693 694
    TVirtualPad::Pad()->GetRange(xRminOld, yRminOld, xRmaxOld, yRmaxOld);
    
695 696
    xminOld = GetXMin(xRminOld, xRmaxOld); 
    xmaxOld = GetXMax(xRminOld, xRmaxOld);
697
    
698
//    yminOld = GetYMin(yRminOld, yRmaxOld);
699
    ymaxOld = GetYMax(yRminOld, yRmaxOld);
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
    
    if (xRmin < xRminOld || xRmax > xRmaxOld)
      p1 = true;
    
    if (yRmin < yRminOld || yRmax > xRmaxOld)
      p2 = true;

    if ( p1 && p2) {
      pL= true;
      p1 = false;
      p2 = false;
    }
  }
  
  if (p1) {
    TVirtualPad::Pad()->Range(xRmin, yRminOld, xRmax, yRmaxOld);
716 717 718
	fAxis->SetX1(BaseLSPlayer::GetXAxis(xmin, xmax)); 
	fAxis->SetX2(BaseLSPlayer::GetXAxis(xmin, xmax));
	fAxis->SetY1(0.0); fAxis->SetY2(ymaxOld);
719 720
    fAxis->SetWmin(0.0);
    fAxis->SetWmax(ymaxOld);
721 722 723 724
  }
  
  if (p2) {
    TVirtualPad::Pad()->Range(xRminOld, yRmin, xRmaxOld, yRmax);
725 726 727
	fPositionLabels = BaseLSPlayer::GetYLabels(ymin, ymax);
	fAxis->SetX1(BaseLSPlayer::GetXAxis(xminOld, xmaxOld)); 
	fAxis->SetX2(BaseLSPlayer::GetXAxis(xminOld, xmaxOld));
728 729 730
    fAxis->SetY1(0.0); fAxis->SetY2(ymax);
    fAxis->SetWmin(0.0);
    fAxis->SetWmax(ymax);
731 732 733 734
  }
  
  if (pL) {
    TVirtualPad::Pad()->Range(xRmin, yRmin, xRmax, yRmax);
735 736 737
	fPositionLabels = BaseLSPlayer::GetYLabels(ymin, ymax);
	fAxis->SetX1(BaseLSPlayer::GetXAxis(xmin, xmax)); 
	fAxis->SetX2(BaseLSPlayer::GetXAxis(xmin, xmax));
738 739 740
    fAxis->SetY1(0.0); fAxis->SetY2(ymax);
    fAxis->SetWmin(0.0);
    fAxis->SetWmax(ymax);
741
  }
742
      
743 744
  name->SetNDC();
  name->SetX(0.55); name->SetY(0.95);
745
   
746
  fAxis->Draw();
747 748
  
  AppendPad();
749
  fLog << debug << "End drawing list of levels" << dolog;
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
}  

//__________________________________________________________
void BaseLSPlayer::DoStyle(EDrawStyle style)
{
  // change existing drawing style
  fDrawStyle = style;
  
  TList* list = &GetLinkList();

  for (Int_t i = 0; i < list->GetEntries(); ++i) {
    
    Link* link = static_cast<Link*> ( list->At(i) );
    
    Double_t xi = link->GetX()[1];
    Double_t xf = link->GetX()[5];;
    Double_t x, y, offset1 = 0., offset2 = 0., prop;
    
    if ( style == kRadware ) {
      offset1 = TMath::Max(TMath::Abs(link->GetIL()->GetX2() - link->GetIL()->GetX1())/30., 
                           link->GetStrength().Get()/2.0);
      offset2 = TMath::Min(2.5*offset1, TMath::Abs(link->GetIL()->GetX2() - link->GetIL()->GetX1())/2.);
    }
    
    if ( style == kEnsdf ) {
      offset1 = TMath::Abs(link->GetIL()->GetX2() - link->GetIL()->GetX1())/70.;
      offset2 = 5*offset1;
    }
    
    prop = 3.0/4.0;
    
    if ( link->GetIL() && link->GetFL() ) {
      
      x = xi; y = link->GetY()[1];
      link->SetPoint(0,x-offset1,y);
      link->SetPoint(1,x,y);
      link->SetPoint(2,x+offset1,y);	
      link->SetPoint(8,x-offset1,y);
      
      x = xi + prop*(xf-xi); 
      y = link->GetIL()->GetY1() - prop*(link->GetIL()->GetY1() - link->GetFL()->GetY1());
      link->SetPoint(3,x+offset1,y);
      link->SetPoint(4,x+offset2,y);   
      link->SetPoint(6,x-offset2,y);
      link->SetPoint(7,x-offset1,y);	
      
      x = xf; y = link->GetFL()->GetY1(); 
      link->SetPoint(5,x,y);
    }
  }  
}

//__________________________________________________________
Int_t BaseLSPlayer::ImportLevelScheme(const Char_t* filename, Option_t* opt)
{
  // import file with dedicated readers
  TString fname(filename);
  Int_t ok = 0;
  
Jérémie Dudouet's avatar
Jérémie Dudouet committed
809 810
  TString Options(opt);

811 812 813 814
  bool Noverbose = Options.Contains("NoVerbose");
  Options.ReplaceAll("NoVerbose","");
  Bool_t NoGraphical = Options.Contains("NoGraphical");
  Options.ReplaceAll("NoGraphical","");
Jérémie Dudouet's avatar
Jérémie Dudouet committed
815

816
  if ( fname.EndsWith(".ags") ) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
817
    RadLevelSchemeReader reader(filename, Options.Data());
818
    ok= reader.Import(*fLevelScheme);
819
    if(!NoGraphical) DoStyle(kRadware);
820 821 822
  }	
  
  if ( fname.EndsWith(".ens") ) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
823 824
    EnsdfLevelSchemeReader reader(filename, Options.Data());
    if(Noverbose) reader.SetQuietMode();
825
    ok = reader.Import(*fLevelScheme);
826
    if(!NoGraphical) DoStyle(kEnsdf);
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
  }
  
  return ok;
}   

//__________________________________________________________
Int_t BaseLSPlayer::ReadAGS(const Char_t *filename, Option_t *opt)
{
  // for backward compatibility
  RadLevelSchemeReader reader(filename, opt);
  return reader.Import(*fLevelScheme);
}

//__________________________________________________________
Int_t BaseLSPlayer::ReadENSDF(const Char_t *filename, Option_t *opt)
{
  // for backward compatibility
  EnsdfLevelSchemeReader reader(filename, opt);
  return reader.Import(*fLevelScheme);
}
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861

//-----------------------------------------------------------------------------------------
ClassImp(LSaxis)

//_______________________________________________
LSaxis::LSaxis() 
: TGaxis(),
  fLastX(0),
  fLastY1(0),
  fLastY2(0),
  fFirst1Zoom(true),
  fFirst2Zoom(true),
  fLastY1Zoom(0),
  fLastY2Zoom(0)
{
862
    SetLabelFont(132);
863 864 865 866 867 868 869
}

//__________________________________________________________
void LSaxis::SetY1(Double_t y1)
{
   TGaxis::SetY1(y1);
   if (fFirst1Zoom) {
870
      fLastY1Zoom = (Int_t)y1;
871
	  fFirst1Zoom = false;
872 873 874 875 876
	  if (TVirtualPad::Pad() != 0) {
		 Double_t xRmin, yRmin, xRmax, yRmax;
		 TVirtualPad::Pad()->GetRange(xRmin, yRmin, xRmax, yRmax);
		 fLastX1Zoom = Int_t(BaseLSPlayer::GetXMin(xRmin, xRmax)+0.5);
	  }
877 878 879 880 881 882 883 884
   }
}

//__________________________________________________________
void LSaxis::SetY2(Double_t y2)
{
   TGaxis::SetY2(y2);
   if (fFirst2Zoom) {
885
      fLastY2Zoom = (Int_t)y2;
886
	  fFirst2Zoom = false;
887 888 889 890 891
	  if (TVirtualPad::Pad() != 0) {
		 Double_t xRmin, yRmin, xRmax, yRmax;
		 TVirtualPad::Pad()->GetRange(xRmin, yRmin, xRmax, yRmax);
		 fLastX2Zoom = Int_t(BaseLSPlayer::GetXMax(xRmin, xRmax)+0.5);
	  }
892 893 894 895 896 897 898 899 900 901 902
   }
}

//__________________________________________________________
void LSaxis::ExecuteEvent(Int_t eventType, Int_t eventX, Int_t eventY)
{ 
   // handle cursor mouvement
   
   TVirtualPad* pad = TVirtualPad::Pad();
   pad->cd(); 
   static Int_t eventYOld = 0;
903
   static Bool_t buttonMotion = false;
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
   if (eventType == kMouseMotion) {
	  eventYOld = eventY;
	  pad->SetCursor(kHand);
   }
   
   if (eventType == kButton1Down) {
	  fLastX = eventX; fLastY1 = eventY;
	  gVirtualX->SetLineColor(-1);
   }
   
   if (eventType == kButton1Motion) {
	  gVirtualX->DrawBox(fLastX-10, fLastY1, fLastX+10, eventYOld, TVirtualX::kHollow);
	  gVirtualX->DrawBox(fLastX-10, fLastY1, fLastX+10, eventY,    TVirtualX::kHollow);
	  eventYOld = eventY;
	  fLastY2   = eventY;
919
	  buttonMotion = true;
920 921
   }
   
922
   if (eventType == kButton1Up && buttonMotion) {
923
	  	  
924 925
      fLastY1 = (Int_t)gPad->AbsPixeltoY(fLastY1);
      fLastY2 = (Int_t)gPad->AbsPixeltoY(fLastY2);
926
	  
927 928 929 930 931 932
	  if (fLastY1 > fLastY2) {
		 Int_t tmp = fLastY2;
		 fLastY2 = fLastY1;
		 fLastY1 = tmp;
	  }
	  
933 934 935 936 937 938 939 940 941 942 943 944
	  SetWmin(fLastY1);
	  SetWmax(fLastY2);
	  
	  Double_t yRmin = BaseLSPlayer::GetYRmin(fLastY1, fLastY2);
	  Double_t yRmax = BaseLSPlayer::GetYRmax(fLastY1, fLastY2);
	  
	  Double_t yMin  = BaseLSPlayer::GetYMin(yRmin, yRmax);
	  Double_t yMax  = BaseLSPlayer::GetYMax(yRmin, yRmax);
	  
	  SetY1(yMin); SetY2(yMax);
	  pad->Range(pad->GetX1(), yRmin, pad->GetX2(), yRmax);
	  pad->Modified(true);
945
	  buttonMotion = false;
946 947 948
   }
}

949
//__________________________________________________________
950
void LSaxis::SetRange(Int_t ymin, Int_t ymax, Int_t xmin, Int_t xmax)
951
{
952
   TPad* pad = (TPad*)TVirtualPad::Pad();
953 954
   pad->cd(); 
   
955 956
   SetWmin(ymin);
   SetWmax(ymax);
957
   
958 959
   Double_t yRmin = BaseLSPlayer::GetYRmin(ymin, ymax);
   Double_t yRmax = BaseLSPlayer::GetYRmax(ymin, ymax);
960
   
961 962
   Double_t xRmin = BaseLSPlayer::GetXRmin(xmin, xmax);
   Double_t xRmax = BaseLSPlayer::GetXRmax(xmin, xmax);
963
   
964 965 966 967 968 969 970
   Double_t yAxisMin  = BaseLSPlayer::GetYMin(yRmin, yRmax);
   Double_t yAxisMax  = BaseLSPlayer::GetYMax(yRmin, yRmax);
   
   
   SetY1(yAxisMin); SetY2(yAxisMax);
   SetX1(xmin-(xmax-xmin)*0.1); SetX2(xmin-(xmax-xmin)*0.1);
   pad->Range(xRmin, yRmin, xRmax, yRmax);
971
   pad->Modified(true);
972 973 974 975 976
   
   fLastY1Zoom = ymin;
   fLastY2Zoom = ymax;
   fLastX1Zoom = xmin;
   fLastX2Zoom = xmax;
977 978

   pad->RangeAxisChanged();
979 980
}

981 982 983
//__________________________________________________________
void LSaxis::UnZoom()
{
984
   TPad* pad = (TPad*)TVirtualPad::Pad();
985 986 987 988 989 990 991 992 993 994
   pad->cd(); 
   
   SetWmin(fLastY1Zoom);
   SetWmax(fLastY2Zoom);
   
   Double_t yRmin = BaseLSPlayer::GetYRmin(fLastY1Zoom, fLastY2Zoom);
   Double_t yRmax = BaseLSPlayer::GetYRmax(fLastY1Zoom, fLastY2Zoom);
   
   Double_t yMin  = BaseLSPlayer::GetYMin(yRmin, yRmax);
   Double_t yMax  = BaseLSPlayer::GetYMax(yRmin, yRmax);
995

996 997 998
   SetY1(yMin); SetY2(yMax);

   pad->Range(pad->GetX1(), yRmin, pad->GetX2(), yRmax);
999 1000
   pad->Modified();
   pad->RangeAxisChanged();
1001
}
1002 1003

ClassImp(BaseLSPlayer)