1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONPainterMasterFrame.h"
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"
30 #include <Riostream.h>
31 #include <TApplication.h>
34 #include <TGComboBox.h>
36 #include <TObjArray.h>
37 #include <TObjString.h>
38 #include <TGButtonGroup.h>
41 /// \class AliMUONPainterMasterFrame
43 /// Main window of the 2D display
45 /// \author Laurent Aphecetche, Subatech
48 ClassImp(AliMUONPainterMasterFrame)
53 UInt_t UniqueID(Int_t nx, Int_t ny)
55 return ny | (nx << 8);
58 Int_t Nx(UInt_t uniqueID)
60 return ( uniqueID & 0xFF00 ) >> 8;
63 Int_t Ny(UInt_t uniqueID)
65 return uniqueID & 0xFF;
70 const Int_t AliMUONPainterMasterFrame::fgkBorderSize = 10;
72 //_____________________________________________________________________________
73 AliMUONPainterMasterFrame::AliMUONPainterMasterFrame(const TGWindow* p,
75 : TGCompositeFrame(p,w,h,kVerticalFrame),
76 fNavigationFrame(0x0),
77 fPainterMatrixFrame(0x0),
82 fCurrentNavigationPosition(-1),
83 fAttPainterSelectorFrame(0x0)
87 UInt_t wi = w - fgkBorderSize*2;
88 UInt_t hi = h - fgkBorderSize*3;
90 fNavigationFrame = new TGHorizontalFrame(this,wi);
92 AddFrame(fNavigationFrame,new TGLayoutHints(kLHintsExpandX|kLHintsTop,
93 fgkBorderSize,fgkBorderSize,
94 fgkBorderSize,fgkBorderSize));
96 fBackButton = new TGPictureButton(fNavigationFrame,
97 gClient->GetPicture("tb_back.xpm"));
99 fForwardButton = new TGPictureButton(fNavigationFrame,
100 gClient->GetPicture("tb_forw.xpm"));
102 fAttPainterSelectorFrame = new AliMUONAttPainterSelectorFrame(fNavigationFrame,w/2,20);
104 fGroupTitle = new TGLabel(fNavigationFrame,"");
106 fNavigationFrame->AddFrame(fBackButton,new TGLayoutHints(kLHintsCenterY));
107 fNavigationFrame->AddFrame(fForwardButton,new TGLayoutHints(kLHintsCenterY));
109 fNavigationFrame->AddFrame(fAttPainterSelectorFrame,new TGLayoutHints(kLHintsCenterY,10));
111 fAttPainterSelectorFrame->Connect("Clicked(AliMUONAttPainter*)",
112 "AliMUONPainterMasterFrame",
114 "AttributesChanged(AliMUONAttPainter*)");
116 fNavigationFrame->AddFrame(fGroupTitle,new TGLayoutHints(kLHintsExpandX|kLHintsCenterX|kLHintsCenterY,10));
118 fForwardButton->Connect("Clicked()","AliMUONPainterMasterFrame",
122 fBackButton->Connect("Clicked()","AliMUONPainterMasterFrame",
129 // UInt_t h1 = hi - fNavigationFrame->GetHeight() - 3*fgkBorderSize;
130 UInt_t h1 = hi - 7*12;
132 MakeTopPainterMatrix(w1,h1);
134 AddFrame(fPainterMatrixFrame,new TGLayoutHints(kLHintsExpandX,
135 fgkBorderSize,fgkBorderSize,
138 AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Navigation",*fNavigationFrame);
139 AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Main",*this);
141 AliDebug(1,Form("fNavigation=%p",&fNavigation));
143 AliMUONPainterRegistry::Instance()->Connect("PainterMatrixWantToShow(AliMUONPainterMatrix*)",
144 "AliMUONPainterMasterFrame",
146 "PainterMatrixWantToShow(AliMUONPainterMatrix*)");
148 fPainterMatrixFrame->DataSourceWasChanged("*",0x0,-1);
151 //_____________________________________________________________________________
152 AliMUONPainterMasterFrame::~AliMUONPainterMasterFrame()
158 //_____________________________________________________________________________
160 AliMUONPainterMasterFrame::AddPainterMatrix(AliMUONPainterMatrix* painterMatrix)
162 /// array is adopted (by the registry)
164 AliDebug(1,Form("matrix=%x %s",painterMatrix,painterMatrix->GetName()));
166 Int_t i = AliMUONPainterRegistry::Instance()->Register(painterMatrix);
171 //_____________________________________________________________________________
173 AliMUONPainterMasterFrame::PainterMatrixWantToShow(AliMUONPainterMatrix* group)
175 /// FIXME: should check whether we are the active window before
176 /// responding to this message ?
178 AliDebug(1,Form("group=%x %s",group,group->GetName()));
180 Int_t i = AliMUONPainterRegistry::Instance()->FindIndexOf(group);
182 Int_t alreadyThere(-1);
184 for ( Int_t j = 0; j < fNavigation.GetSize(); ++j )
186 if ( fNavigation[j] == i ) alreadyThere = j;
195 fCurrentNavigationPosition = alreadyThere;
198 ShowPainterMatrix(group);
201 //_____________________________________________________________________________
203 AliMUONPainterMasterFrame::SetNavigation(Int_t i)
205 /// Change navigation position
207 ++fCurrentNavigationPosition;
208 fNavigation.Set(fCurrentNavigationPosition+1);
209 fNavigation[fCurrentNavigationPosition] = i;
212 //_____________________________________________________________________________
214 AliMUONPainterMasterFrame::ShowPainterMatrix(AliMUONPainterMatrix* painterMatrix)
216 /// Change the painter matrix we show
218 fPainterMatrixFrame->Use(painterMatrix);
220 painterMatrix->Connect("Clicked(AliMUONVPainter*,Double_t*)",
221 "AliMUONPainterMasterFrame",this,
222 "Clicked(AliMUONVPainter*,Double_t*)");
224 painterMatrix->Connect("ShiftClicked(AliMUONVPainter*,Double_t*)",
225 "AliMUONPainterMasterFrame",this,
226 "ShiftClicked(AliMUONVPainter*,Double_t*)");
228 fPainterMatrixFrame->Connect("TitleHasChanged(const char*)",
229 "AliMUONPainterMasterFrame",this,
230 "ChangeTitle(const char*)");
233 UpdateAttributes(*(fPainterMatrixFrame->Matrix()));
235 AliMUONPainterRegistry::Instance()->AddToHistory(painterMatrix);
240 //_____________________________________________________________________________
242 AliMUONPainterMasterFrame::ChangeTitle(const char* newTitle)
244 /// Change the top title
246 fGroupTitle->SetText(newTitle);
247 fGroupTitle->Resize();
251 //_____________________________________________________________________________
253 AliMUONPainterMasterFrame::Backward()
255 /// Move back one step in the history
256 --fCurrentNavigationPosition;
258 AliMUONPainterMatrix* group =
259 AliMUONPainterRegistry::Instance()->PainterMatrix(fNavigation[fCurrentNavigationPosition]);
261 ShowPainterMatrix(group);
266 //_____________________________________________________________________________
268 AliMUONPainterMasterFrame::Forward()
270 /// Move forward one step in history
272 ++fCurrentNavigationPosition;
274 AliMUONPainterMatrix* group =
275 AliMUONPainterRegistry::Instance()->PainterMatrix(fNavigation[fCurrentNavigationPosition]);
277 ShowPainterMatrix(group);
282 //_____________________________________________________________________________
284 AliMUONPainterMasterFrame::Clicked(AliMUONVPainter* painter, Double_t* values)
286 /// A given painter was (singly) clicked
288 if ( painter->CanBeDetached() )
290 fPainterMatrixFrame->MouseLeave(painter);
292 AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix(painter->Name().Data());
294 AliMUONVPainter* p = painter->Detach();
300 AddPainterMatrix(matrix);
301 ShowPainterMatrix(matrix);
305 painter->DrawHistogram(values);
309 //_____________________________________________________________________________
311 AliMUONPainterMasterFrame::ShiftClicked(AliMUONVPainter* painter, Double_t*)
313 /// A given painter was shift-clicked
315 if ( !painter->CanBeDetached() ) return;
317 AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
319 AliMUONAttPainter a = painter->Attributes();
321 TString basename(Form("%s-DUAL",painter->GetName()));
323 TString newName = AliMUONPainterMatrix::NameIt(basename.Data(),a);
325 AliMUONPainterMatrix* matrix = AliMUONPainterRegistry::Instance()->PainterMatrix(newName.Data());
329 // No. So we must make a new matrix painter from the existing one,
330 // and add to this new matrix the painters of the other one, but
331 // using the new attributes...
333 // create "opposite" attributes
334 AliMUONAttPainter a1(a);
335 AliMUONAttPainter a2(a);
339 a1.SetCathodeAndPlaneDisabled(kTRUE);
340 a2.SetCathodeAndPlaneDisabled(kTRUE);
342 AliMUONVPainter* p1 = AliMUONVPainter::CreatePainter(painter->ClassName(),
347 AliMUONVPainter* p2 = AliMUONVPainter::CreatePainter(painter->ClassName(),
355 new TGMsgBox(gClient->GetRoot(), this,
356 "Invalid combination", "Cannot create 2 views from this painter",
357 kMBIconExclamation, kMBOk, &ret);
358 PainterMatrixWantToShow(currentMatrix);
364 p1->UpdateGroupsFrom(*(painter->Master()));
365 p2->UpdateGroupsFrom(*(painter->Master()));
373 AliMpArea area(painter->Area());
375 if ( area.GetDimensionX() > 1.2*area.GetDimensionY() )
381 matrix = new AliMUONPainterMatrix(basename.Data(),nx,ny);
386 AddPainterMatrix(matrix);
389 matrix->SetData(currentMatrix->DataPattern(),
390 currentMatrix->Data(),
391 currentMatrix->DataIndex());
393 fPainterMatrixFrame->MouseLeave(painter);
395 PainterMatrixWantToShow(matrix);
398 //_____________________________________________________________________________
400 AliMUONPainterMasterFrame::SaveAs(const char* filename, Option_t* option) const
402 /// Save painter matrix (in the sense of "print") in filename
403 fPainterMatrixFrame->SaveAs(filename,option);
406 //_____________________________________________________________________________
408 AliMUONPainterMasterFrame::Update()
412 fPainterMatrixFrame->Update();
415 //_____________________________________________________________________________
417 AliMUONPainterMasterFrame::UpdateAttributes(const AliMUONPainterMatrix& painterMatrix)
419 /// Update the view buttons from the matrix we actually plot
421 fAttPainterSelectorFrame->Update(painterMatrix.Attributes());
424 //_____________________________________________________________________________
426 AliMUONPainterMasterFrame::MakeTopPainterMatrix(UInt_t w, UInt_t h)
428 /// Create the first painter matrix that appears when we are create
429 /// FIXME: how to make this more flexible ?
431 fPainterMatrixFrame = new AliMUONPainterMatrixFrame(this,w,h);
433 AliMUONAttPainter att;
435 att.SetPlane(kTRUE,kFALSE);
436 // att.SetCathode(kTRUE,kFALSE);
437 att.SetViewPoint(kTRUE,kFALSE);
439 TString name = AliMUONPainterMatrix::NameIt("Tracker",att);
441 AliMUONPainterMatrix* painterMatrix = AliMUONPainterRegistry::Instance()->PainterMatrix(name);
445 AliError(Form("Could not get pre-defined painter matrix %s : check that !",name.Data()));
449 PainterMatrixWantToShow(painterMatrix);
450 // fPainterMatrixFrame->Use(painterMatrix);
451 // ShowPainterMatrix(painterMatrix);
455 //_____________________________________________________________________________
457 AliMUONPainterMasterFrame::UpdateNavigation()
459 /// Update navigation frame
461 fBackButton->SetEnabled(kTRUE);
462 fForwardButton->SetEnabled(kTRUE);
464 if ( fCurrentNavigationPosition == 0 )
466 fBackButton->SetEnabled(kFALSE);
468 if ( fCurrentNavigationPosition == fNavigation.GetSize()-1 )
470 fForwardButton->SetEnabled(kFALSE);
474 //_____________________________________________________________________________
476 AliMUONPainterMasterFrame::AttributesChanged(AliMUONAttPainter* newValues)
478 /// Attributes changed (e.g. from cath0 to cath1 or bending to nonbending, etc...)
480 AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
482 AliMUONAttPainter a = currentMatrix->Validate(*newValues);
487 new TGMsgBox(gClient->GetRoot(), this,
488 "Invalid combination", "Change of attributes not possible for this object",
489 kMBIconExclamation, kMBOk, &ret);
490 PainterMatrixWantToShow(currentMatrix);
494 // First check if we already have this matrix available
496 TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Basename(),a);
498 AliMUONPainterMatrix* matrix = AliMUONPainterRegistry::Instance()->PainterMatrix(newName.Data());
502 // No. So we must make a new matrix painter from the existing one,
503 // and add to this new matrix the painters of the other one, but
504 // using the new attributes...
506 matrix = currentMatrix->Clone(a);
508 AddPainterMatrix(matrix);
511 matrix->SetData(currentMatrix->DataPattern(),
512 currentMatrix->Data(),
513 currentMatrix->DataIndex());
515 PainterMatrixWantToShow(matrix);