LCOV - code coverage report
Current view: top level - MUON/MUONgraphics - AliMUONPainterMasterFrame.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 187 0.5 %
Date: 2016-06-14 17:26:59 Functions: 1 25 4.0 %

          Line data    Source code
       1             : /**************************************************************************
       2             : * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             : *                                                                        *
       4             : * Author: The ALICE Off-line Project.                                    *
       5             : * Contributors are mentioned in the code where appropriate.              *
       6             : *                                                                        *
       7             : * Permission to use, copy, modify and distribute this software and its   *
       8             : * documentation strictly for non-commercial purposes is hereby granted   *
       9             : * without fee, provided that the above copyright notice appears in all   *
      10             : * copies and that both the copyright notice and this permission notice   *
      11             : * appear in the supporting documentation. The authors make no claims     *
      12             : * about the suitability of this software for any purpose. It is          *
      13             : * provided "as is" without express or implied warranty.                  *
      14             : **************************************************************************/
      15             : 
      16             : // $Id$
      17             : 
      18             : #include "AliMUONPainterMasterFrame.h"
      19             : 
      20             : #include "AliMUONChamberPainter.h"
      21             : #include "AliMUONPainterGroup.h"
      22             : #include "AliMUONPainterMatrix.h"
      23             : #include "AliMUONPainterMatrixFrame.h"
      24             : #include "AliMUONPainterInterfaceHelper.h"
      25             : #include "AliMUONPainterRegistry.h"
      26             : #include "AliMUONAttPainterSelectorFrame.h"
      27             : #include "AliMUONVPainter.h"
      28             : #include "AliCodeTimer.h"
      29             : #include "AliLog.h"
      30             : #include <Riostream.h>
      31             : #include <TApplication.h>
      32             : #include <TCanvas.h>
      33             : #include <TEnv.h>
      34             : #include <TGComboBox.h>
      35             : #include <TGFileDialog.h>
      36             : #include <TGLabel.h>
      37             : #include <TObjArray.h>
      38             : #include <TObjString.h>
      39             : #include <TGButtonGroup.h>
      40             : #include <TGMsgBox.h>
      41             : #include <TSystem.h>
      42             : 
      43             : /// \class AliMUONPainterMasterFrame
      44             : ///
      45             : /// Main window of the 2D display
      46             : ///
      47             : /// \author Laurent Aphecetche, Subatech
      48             : 
      49             : ///\cond CLASSIMP
      50          12 : ClassImp(AliMUONPainterMasterFrame)
      51             : ///\endcond
      52             : 
      53             : const Int_t AliMUONPainterMasterFrame::fgkBorderSize = 10;
      54             : 
      55             : //_____________________________________________________________________________
      56             : AliMUONPainterMasterFrame::AliMUONPainterMasterFrame(const TGWindow* p, 
      57             :                                                      UInt_t w, UInt_t h, AliMUONPainterMatrix* matrix)
      58           0 : : TGCompositeFrame(p,w,h,kVerticalFrame),
      59           0 : fNavigationFrame(0x0),
      60           0 : fPainterMatrixFrame(0x0),
      61           0 : fBackButton(0x0),
      62           0 : fForwardButton(0x0),
      63           0 : fGroupTitle(0x0),
      64           0 : fPrintMeButton(0x0),
      65           0 : fPrintAsButton(0x0),
      66           0 : fNavigation(),
      67           0 : fCurrentNavigationPosition(-1),
      68           0 : fAttPainterSelectorFrame(0x0)
      69           0 : {  
      70             :   /// ctor
      71             :     
      72           0 :   UInt_t wi = w - fgkBorderSize*2;
      73           0 :   UInt_t hi = h - fgkBorderSize*3;
      74             :   
      75           0 :   fNavigationFrame = new TGHorizontalFrame(this,wi);
      76             :   
      77           0 :   AddFrame(fNavigationFrame,new TGLayoutHints(kLHintsExpandX|kLHintsTop,
      78             :                                               fgkBorderSize,fgkBorderSize,
      79             :                                               fgkBorderSize,fgkBorderSize));
      80             :   
      81           0 :   fBackButton = new TGPictureButton(fNavigationFrame,
      82           0 :                                     gClient->GetPicture("tb_back.xpm"));
      83             :   
      84           0 :   fForwardButton = new TGPictureButton(fNavigationFrame,
      85           0 :                                        gClient->GetPicture("tb_forw.xpm"));    
      86             : 
      87           0 :   fPrintMeButton = new TGTextButton(fNavigationFrame,"Print");
      88           0 :   fPrintAsButton = new TGTextButton(fNavigationFrame,"Print As...");
      89             : 
      90           0 :   fAttPainterSelectorFrame = new AliMUONAttPainterSelectorFrame(fNavigationFrame,w/2,20);
      91             :   
      92           0 :   fGroupTitle = new TGLabel(fNavigationFrame,"");
      93             :   
      94           0 :   fNavigationFrame->AddFrame(fBackButton,new TGLayoutHints(kLHintsCenterY));
      95           0 :   fNavigationFrame->AddFrame(fForwardButton,new TGLayoutHints(kLHintsCenterY));
      96             :   
      97           0 :   fNavigationFrame->AddFrame(fAttPainterSelectorFrame,new TGLayoutHints(kLHintsCenterY,10));
      98             : 
      99           0 :   fNavigationFrame->AddFrame(fPrintMeButton,new TGLayoutHints(kLHintsCenterY,10));
     100           0 :   fNavigationFrame->AddFrame(fPrintAsButton,new TGLayoutHints(kLHintsCenterY,10));
     101             : 
     102           0 :   fAttPainterSelectorFrame->Connect("Clicked(AliMUONAttPainter*)",
     103             :                                     "AliMUONPainterMasterFrame",
     104             :                                     this,
     105             :                                     "AttributesChanged(AliMUONAttPainter*)");
     106             :   
     107           0 :   fNavigationFrame->AddFrame(fGroupTitle,new TGLayoutHints(kLHintsExpandX|kLHintsCenterX|kLHintsCenterY,10));
     108             :   
     109           0 :   fForwardButton->Connect("Clicked()","AliMUONPainterMasterFrame",
     110             :                           this,
     111             :                           "Forward()");
     112             : 
     113           0 :   fBackButton->Connect("Clicked()","AliMUONPainterMasterFrame",
     114             :                           this,
     115             :                           "Backward()");
     116             :     
     117           0 :   fPrintMeButton->Connect("Clicked()","AliMUONPainterMasterFrame",
     118             :                         this,
     119             :                         "PrintMe()");
     120             : 
     121           0 :   fPrintAsButton->Connect("Clicked()","AliMUONPainterMasterFrame",
     122             :                         this,
     123             :                         "PrintAs()");
     124             :   
     125             :   UInt_t w1 = wi;
     126             :   //  UInt_t h1 = hi - fNavigationFrame->GetHeight() - 3*fgkBorderSize;
     127           0 :   UInt_t h1 = hi - 7*12;
     128             :   
     129           0 :   MakeTopPainterMatrix(w1,h1,matrix);
     130             : 
     131           0 :   AddFrame(fPainterMatrixFrame,new TGLayoutHints(kLHintsExpandX,
     132             :                                                 fgkBorderSize,fgkBorderSize,
     133             :                                                 0,fgkBorderSize));
     134             :   
     135           0 :   AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Navigation",*fNavigationFrame);
     136           0 :   AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Main",*this);
     137             :   
     138           0 :   AliMUONPainterRegistry::Instance()->Connect("PainterMatrixWantToShow(AliMUONPainterMatrix*)",
     139             :                                               "AliMUONPainterMasterFrame",
     140             :                                               this,
     141             :                                               "PainterMatrixWantToShow(AliMUONPainterMatrix*)");
     142             :   
     143           0 :   fPainterMatrixFrame->DataSourceWasChanged(matrix->DataPattern().Data(),matrix->Data(),matrix->DataIndex());
     144           0 : }
     145             : 
     146             : //_____________________________________________________________________________
     147           0 : AliMUONPainterMasterFrame::~AliMUONPainterMasterFrame()
     148           0 : {
     149             :   /// dtor
     150           0 :   Cleanup();
     151           0 : }
     152             : 
     153             : //_____________________________________________________________________________
     154             : void
     155             : AliMUONPainterMasterFrame::AddPainterMatrix(AliMUONPainterMatrix* painterMatrix)
     156             : {
     157             :   /// array is adopted (by the registry)
     158             : 
     159           0 :   Int_t i = AliMUONPainterRegistry::Instance()->Register(painterMatrix);
     160             : 
     161           0 :   SetNavigation(i);
     162           0 : }
     163             : 
     164             : //_____________________________________________________________________________
     165             : void
     166             : AliMUONPainterMasterFrame::PainterMatrixWantToShow(AliMUONPainterMatrix* group)
     167             : {
     168             :   /// FIXME: should check whether we are the active window before
     169             :   /// responding to this message ?
     170             : 
     171           0 :   Int_t i = AliMUONPainterRegistry::Instance()->FindIndexOf(group);
     172             : 
     173             :   Int_t alreadyThere(-1);
     174             :   
     175           0 :   for ( Int_t j = 0; j < fNavigation.GetSize(); ++j )
     176             :   {
     177           0 :     if ( fNavigation[j] == i ) alreadyThere = j;
     178             :   }
     179             :   
     180           0 :   if (alreadyThere<0) 
     181             :   {
     182           0 :     SetNavigation(i);
     183           0 :   }
     184             :   else
     185             :   {
     186           0 :     fCurrentNavigationPosition = alreadyThere;
     187             :   }
     188             :   
     189           0 :   ShowPainterMatrix(group);  
     190           0 : }
     191             :      
     192             : //_____________________________________________________________________________
     193             : void
     194             : AliMUONPainterMasterFrame::PrintAs() const
     195             : {
     196             :   /// Handle the PrintAs button
     197             :   
     198           0 :   TGFileInfo fileInfo;
     199             :   
     200           0 :   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
     201             :                    kFDSave,&fileInfo);
     202             :   
     203           0 :   if ( fileInfo.fFilename ) 
     204             :   {
     205           0 :     SaveAs(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)),"RECREATE");
     206             :   }
     207           0 : }
     208             : 
     209             : //_____________________________________________________________________________
     210             : void
     211             : AliMUONPainterMasterFrame::PrintMe() const
     212             : {
     213             :   /// Handle the PrintMe button
     214             :   
     215           0 :   SaveAs(gSystem->ExpandPathName(Form("%s.png",fPainterMatrixFrame->Matrix()->GetName())),"RECREATE");
     216           0 : }
     217             : 
     218             : //_____________________________________________________________________________
     219             : void
     220             : AliMUONPainterMasterFrame::SetNavigation(Int_t i)
     221             : {
     222             :   /// Change navigation position
     223             :   
     224           0 :   ++fCurrentNavigationPosition;
     225           0 :   fNavigation.Set(fCurrentNavigationPosition+1);
     226           0 :   fNavigation[fCurrentNavigationPosition] = i;
     227           0 : }
     228             : 
     229             : //_____________________________________________________________________________
     230             : void
     231             : AliMUONPainterMasterFrame::ShowPainterMatrix(AliMUONPainterMatrix* painterMatrix)
     232             : {
     233             :   /// Change the painter matrix we show
     234             :   
     235           0 :   fPainterMatrixFrame->Use(painterMatrix);
     236             :   
     237           0 :   painterMatrix->Connect("Clicked(AliMUONVPainter*,Double_t*)",
     238           0 :                          "AliMUONPainterMasterFrame",this,
     239             :                          "Clicked(AliMUONVPainter*,Double_t*)");
     240             : 
     241           0 :   painterMatrix->Connect("ShiftClicked(AliMUONVPainter*,Double_t*)",
     242             :                          "AliMUONPainterMasterFrame",this,
     243             :                          "ShiftClicked(AliMUONVPainter*,Double_t*)");
     244             :   
     245           0 :   fPainterMatrixFrame->Connect("TitleHasChanged(const char*)",
     246             :                               "AliMUONPainterMasterFrame",this,
     247             :                               "ChangeTitle(const char*)");
     248           0 :   UpdateNavigation();
     249             :   
     250           0 :   UpdateAttributes(*(fPainterMatrixFrame->Matrix()));
     251             :   
     252           0 :   AliMUONPainterRegistry::Instance()->AddToHistory(painterMatrix);
     253             :   
     254             :   //Layout();
     255           0 : }
     256             : 
     257             : //_____________________________________________________________________________
     258             : void
     259             : AliMUONPainterMasterFrame::ChangeTitle(const char* newTitle)
     260             : {
     261             :   /// Change the top title
     262             :   
     263           0 :   fGroupTitle->SetText(newTitle);
     264           0 :   fGroupTitle->Resize();
     265           0 :   Layout();
     266           0 : }
     267             : 
     268             : //_____________________________________________________________________________
     269             : void
     270             : AliMUONPainterMasterFrame::Backward()
     271             : {
     272             :   /// Move back one step in the history
     273           0 :   --fCurrentNavigationPosition;
     274             :   
     275             :   AliMUONPainterMatrix* group = 
     276           0 :     AliMUONPainterRegistry::Instance()->PainterMatrix(fNavigation[fCurrentNavigationPosition]);
     277             :   
     278           0 :   ShowPainterMatrix(group);
     279             :   
     280           0 :   UpdateNavigation();
     281           0 : }
     282             : 
     283             : //_____________________________________________________________________________
     284             : void
     285             : AliMUONPainterMasterFrame::Forward()
     286             : {
     287             :   /// Move forward one step in history
     288             :   
     289           0 :   ++fCurrentNavigationPosition;
     290             :   
     291             :   AliMUONPainterMatrix* group = 
     292           0 :     AliMUONPainterRegistry::Instance()->PainterMatrix(fNavigation[fCurrentNavigationPosition]);
     293             :   
     294           0 :   ShowPainterMatrix(group);
     295             :   
     296           0 :   UpdateNavigation();
     297           0 : }
     298             : 
     299             : //_____________________________________________________________________________
     300             : void 
     301             : AliMUONPainterMasterFrame::Clicked(AliMUONVPainter* painter, Double_t* values)
     302             : {
     303             :   /// A given painter was (singly) clicked
     304             : 
     305           0 :   if ( painter->CanBeDetached() )
     306             :   {
     307           0 :     fPainterMatrixFrame->MouseLeave(painter);
     308             :   
     309           0 :     AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix(painter->Name().Data());
     310             : 
     311           0 :     AliMUONVPainter* p = painter->Detach();
     312             : 
     313           0 :     p->SetResponder(1);
     314             : 
     315           0 :     matrix->Adopt(p);
     316             :   
     317           0 :     AddPainterMatrix(matrix);
     318           0 :     ShowPainterMatrix(matrix);
     319           0 :   }
     320             :   else
     321             :   {
     322           0 :     painter->DrawHistogram(values);
     323             :   }
     324           0 : }
     325             : 
     326             : //_____________________________________________________________________________
     327             : void 
     328             : AliMUONPainterMasterFrame::ShiftClicked(AliMUONVPainter* painter, Double_t*)
     329             : {
     330             :   /// A given painter was shift-clicked
     331             :   
     332           0 :   if ( !painter->CanBeDetached() ) return;
     333             :   
     334           0 :   AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
     335             :   
     336           0 :   AliMUONAttPainter a = painter->Attributes();
     337             :   
     338           0 :   TString basename(Form("%s-DUAL",painter->GetName()));
     339             :   
     340           0 :   TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Whatname(),basename.Data(),a);
     341             :   
     342           0 :   AliMUONPainterMatrix* matrix = AliMUONPainterRegistry::Instance()->PainterMatrix(newName.Data());
     343             :   
     344           0 :   if (!matrix)
     345             :   {
     346             :     // No. So we must make a new matrix painter from the existing one,
     347             :     // and add to this new matrix the painters of the other one, but
     348             :     // using the new attributes...
     349             :     
     350             :     // create "opposite" attributes
     351           0 :     AliMUONAttPainter a1(a);
     352           0 :     AliMUONAttPainter a2(a);
     353             :   
     354           0 :     a2.Invert();
     355             :     
     356           0 :     a1.SetCathodeAndPlaneDisabled(kTRUE);
     357           0 :     a2.SetCathodeAndPlaneDisabled(kTRUE);
     358             :     
     359           0 :     AliMUONVPainter* p1 = AliMUONVPainter::CreatePainter(painter->ClassName(),
     360             :                                                          a1,
     361           0 :                                                          painter->ID0(),
     362           0 :                                                          painter->ID1());
     363             :     
     364           0 :     AliMUONVPainter* p2 = AliMUONVPainter::CreatePainter(painter->ClassName(),
     365             :                                                          a2,
     366           0 :                                                          painter->ID0(),
     367           0 :                                                          painter->ID1());
     368             :     
     369           0 :     if (!p1 || !p2)
     370             :     {
     371           0 :       Int_t ret;
     372           0 :       new TGMsgBox(gClient->GetRoot(), this,
     373             :                    "Invalid combination", "Cannot create 2 views from this painter",
     374             :                    kMBIconExclamation, kMBOk, &ret);
     375           0 :       PainterMatrixWantToShow(currentMatrix);
     376           0 :       delete p1;
     377           0 :       delete p2;
     378             :       return;
     379           0 :     }
     380             :     
     381           0 :     p1->UpdateGroupsFrom(*(painter->Master()));
     382           0 :     p2->UpdateGroupsFrom(*(painter->Master()));
     383             :     
     384           0 :     p1->SetResponder(1);
     385           0 :     p2->SetResponder(1);
     386             :     
     387             :     Int_t nx(2);
     388             :     Int_t ny(1);
     389             :     
     390           0 :     AliMpArea area(painter->Area());
     391             :     
     392           0 :     if ( area.GetDimensionX() > 1.2*area.GetDimensionY() ) 
     393             :     {
     394             :       nx = 1;
     395             :       ny = 2;
     396           0 :     }
     397             :     
     398           0 :     matrix = new AliMUONPainterMatrix(basename.Data(),nx,ny);
     399             :     
     400           0 :     matrix->Adopt(p1);
     401           0 :     matrix->Adopt(p2);
     402             :     
     403           0 :     AddPainterMatrix(matrix);
     404           0 :   }
     405             :   
     406           0 :   matrix->SetData(currentMatrix->DataPattern(),
     407           0 :                   currentMatrix->Data(),
     408           0 :                   currentMatrix->DataIndex());
     409             :   
     410           0 :   fPainterMatrixFrame->MouseLeave(painter);
     411             :   
     412           0 :   PainterMatrixWantToShow(matrix);
     413           0 : }
     414             : 
     415             : //_____________________________________________________________________________
     416             : void 
     417             : AliMUONPainterMasterFrame::SaveAs(const char* filename, Option_t* option) const
     418             : {
     419             :   /// Save painter matrix (in the sense of "print") in filename
     420           0 :   fPainterMatrixFrame->SaveAs(filename,option);
     421           0 : }
     422             : 
     423             : //_____________________________________________________________________________
     424             : void
     425             : AliMUONPainterMasterFrame::Update()
     426             : {
     427             :   /// Update ourselves
     428             :   
     429           0 :   fPainterMatrixFrame->Update();
     430           0 :   fPainterMatrixFrame->UpdateInterface(kFALSE);
     431           0 : }
     432             : 
     433             : //_____________________________________________________________________________
     434             : void
     435             : AliMUONPainterMasterFrame::UpdateAttributes(const AliMUONPainterMatrix& painterMatrix)
     436             : {
     437             :   /// Update the view buttons from the matrix we actually plot
     438             :   
     439           0 :   fAttPainterSelectorFrame->Update(painterMatrix.Attributes());
     440           0 : }
     441             : 
     442             : //_____________________________________________________________________________
     443             : void
     444             : AliMUONPainterMasterFrame::MakeTopPainterMatrix(UInt_t w, UInt_t h, AliMUONPainterMatrix* matrix)
     445             : {
     446             :   /// Create the first painter matrix that appears when we are create
     447             :   /// FIXME: how to make this more flexible ?
     448             :   
     449           0 :   fPainterMatrixFrame = new AliMUONPainterMatrixFrame(this,w,h);
     450             : 
     451           0 :   if (matrix)
     452             :   {
     453           0 :     PainterMatrixWantToShow(matrix);
     454           0 :   }
     455             :   else
     456             :   {
     457           0 :     AliError("Cannot work without a painterMatrix");
     458             :   }
     459           0 : }
     460             : 
     461             : //_____________________________________________________________________________
     462             : void
     463             : AliMUONPainterMasterFrame::UpdateNavigation()
     464             : {
     465             :   /// Update navigation frame
     466             : 
     467           0 :   fBackButton->SetEnabled(kTRUE);
     468           0 :   fForwardButton->SetEnabled(kTRUE);
     469             : 
     470           0 :   if ( fCurrentNavigationPosition == 0 ) 
     471             :   {
     472           0 :     fBackButton->SetEnabled(kFALSE);
     473           0 :   }
     474           0 :   if ( fCurrentNavigationPosition == fNavigation.GetSize()-1 ) 
     475             :   {
     476           0 :     fForwardButton->SetEnabled(kFALSE);
     477           0 :   }
     478           0 : }
     479             : 
     480             : //_____________________________________________________________________________
     481             : void
     482             : AliMUONPainterMasterFrame::AttributesChanged(const AliMUONAttPainter* newValues)
     483             : {
     484             :   /// Attributes changed (e.g. from cath0 to cath1 or bending to nonbending, etc...)
     485             :   
     486           0 :   AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
     487             :   
     488           0 :   AliMUONAttPainter a = currentMatrix->Validate(*newValues);
     489             :   
     490           0 :   if (!a.IsValid())
     491             :   {
     492           0 :     Int_t ret;
     493           0 :     new TGMsgBox(gClient->GetRoot(), this,
     494             :                  "Invalid combination", "Change of attributes not possible for this object",
     495             :                  kMBIconExclamation, kMBOk, &ret);
     496           0 :     PainterMatrixWantToShow(currentMatrix);
     497             :     return;
     498           0 :   }
     499             :   
     500             :   // First check if we already have this matrix available
     501             :   
     502           0 :   TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Whatname(),currentMatrix->Basename(),a);
     503             :   
     504           0 :   AliMUONPainterMatrix* matrix = AliMUONPainterRegistry::Instance()->PainterMatrix(newName.Data());
     505             : 
     506           0 :   if (!matrix)
     507             :   {
     508             :     // No. So we must make a new matrix painter from the existing one,
     509             :     // and add to this new matrix the painters of the other one, but
     510             :     // using the new attributes...
     511             :     
     512           0 :     matrix = currentMatrix->Clone(a);
     513             :   
     514           0 :     AddPainterMatrix(matrix);
     515             :   }
     516             :   
     517           0 :   matrix->SetData(currentMatrix->DataPattern(),
     518           0 :                   currentMatrix->Data(),
     519           0 :                   currentMatrix->DataIndex());
     520             :   
     521           0 :   PainterMatrixWantToShow(matrix);
     522           0 : }

Generated by: LCOV version 1.11