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;
131 MakeTopPainterMatrix(w1,h1);
133 AddFrame(fPainterMatrixFrame,new TGLayoutHints(kLHintsExpandX,
134 fgkBorderSize,fgkBorderSize,
137 AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Navigation",*fNavigationFrame);
138 AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Main",*this);
140 AliDebug(1,Form("fNavigation=%p",&fNavigation));
142 AliMUONPainterRegistry::Instance()->Connect("PainterMatrixWantToShow(AliMUONPainterMatrix*)",
143 "AliMUONPainterMasterFrame",
145 "PainterMatrixWantToShow(AliMUONPainterMatrix*)");
147 fPainterMatrixFrame->DataSourceWasChanged("*",0x0,-1);
150 //_____________________________________________________________________________
151 AliMUONPainterMasterFrame::~AliMUONPainterMasterFrame()
157 //_____________________________________________________________________________
159 AliMUONPainterMasterFrame::AddPainterMatrix(AliMUONPainterMatrix* painterMatrix)
161 /// array is adopted (by the registry)
163 AliDebug(1,Form("matrix=%x %s",painterMatrix,painterMatrix->GetName()));
165 Int_t i = AliMUONPainterRegistry::Instance()->Register(painterMatrix);
170 //_____________________________________________________________________________
172 AliMUONPainterMasterFrame::PainterMatrixWantToShow(AliMUONPainterMatrix* group)
174 // FIXME: should check whether we are the active window before
175 // responding to this message
177 AliDebug(1,Form("group=%x %s",group,group->GetName()));
179 Int_t i = AliMUONPainterRegistry::Instance()->FindIndexOf(group);
181 Int_t alreadyThere(-1);
183 for ( Int_t j = 0; j < fNavigation.GetSize(); ++j )
185 if ( fNavigation[j] == i ) alreadyThere = j;
194 fCurrentNavigationPosition = alreadyThere;
197 ShowPainterMatrix(group);
200 //_____________________________________________________________________________
202 AliMUONPainterMasterFrame::SetNavigation(Int_t i)
204 /// Change navigation position
206 ++fCurrentNavigationPosition;
207 fNavigation.Set(fCurrentNavigationPosition+1);
208 fNavigation[fCurrentNavigationPosition] = i;
211 //_____________________________________________________________________________
213 AliMUONPainterMasterFrame::ShowPainterMatrix(AliMUONPainterMatrix* painterMatrix)
215 /// Change the painter matrix we show
217 fPainterMatrixFrame->Use(painterMatrix);
219 painterMatrix->Connect("Clicked(AliMUONVPainter*,Double_t*)",
220 "AliMUONPainterMasterFrame",this,
221 "Clicked(AliMUONVPainter*,Double_t*)");
223 painterMatrix->Connect("ShiftClicked(AliMUONVPainter*,Double_t*)",
224 "AliMUONPainterMasterFrame",this,
225 "ShiftClicked(AliMUONVPainter*,Double_t*)");
227 fPainterMatrixFrame->Connect("TitleHasChanged(const char*)",
228 "AliMUONPainterMasterFrame",this,
229 "ChangeTitle(const char*)");
232 UpdateAttributes(*(fPainterMatrixFrame->Matrix()));
234 AliMUONPainterRegistry::Instance()->AddToHistory(painterMatrix);
239 //_____________________________________________________________________________
241 AliMUONPainterMasterFrame::ChangeTitle(const char* newTitle)
243 /// Change the top title
245 fGroupTitle->SetText(newTitle);
246 fGroupTitle->Resize();
250 //_____________________________________________________________________________
252 AliMUONPainterMasterFrame::Backward()
254 /// Move back one step in the history
255 --fCurrentNavigationPosition;
257 AliMUONPainterMatrix* group =
258 AliMUONPainterRegistry::Instance()->PainterMatrix(fNavigation[fCurrentNavigationPosition]);
260 ShowPainterMatrix(group);
265 //_____________________________________________________________________________
267 AliMUONPainterMasterFrame::Forward()
269 /// Move forward one step in history
271 ++fCurrentNavigationPosition;
273 AliMUONPainterMatrix* group =
274 AliMUONPainterRegistry::Instance()->PainterMatrix(fNavigation[fCurrentNavigationPosition]);
276 ShowPainterMatrix(group);
281 //_____________________________________________________________________________
283 AliMUONPainterMasterFrame::Clicked(AliMUONVPainter* painter, Double_t* values)
285 /// A given painter was (singly) clicked
287 AliDebug(1,Form("%s x %7.3f y %7.3f",painter->GetName(),values[0],values[1]));
291 fPainterMatrixFrame->MouseLeave(painter);
293 AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix(painter->Name().Data());
295 AliMUONVPainter* p = painter->Detach();
301 AddPainterMatrix(matrix);
302 ShowPainterMatrix(matrix);
305 //_____________________________________________________________________________
307 AliMUONPainterMasterFrame::ShiftClicked(AliMUONVPainter* painter, Double_t*)
309 /// A given painter was shift-clicked
311 AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
313 AliMUONAttPainter a = painter->Attributes();
315 TString basename(Form("%s-DUAL",painter->GetName()));
317 TString newName = AliMUONPainterMatrix::NameIt(basename.Data(),a);
319 AliMUONPainterMatrix* matrix =
320 AliMUONPainterRegistry::Instance()->FindPainterMatrix(newName.Data());
324 // No. So we must make a new matrix painter from the existing one,
325 // and add to this new matrix the painters of the other one, but
326 // using the new attributes...
328 // create "opposite" attributes
329 AliMUONAttPainter a1(a);
330 AliMUONAttPainter a2(a);
332 if ( a.IsCathodeDefined() )
334 a2.SetCathode(!a.IsCathode0(),!a.IsCathode1());
337 if ( a.IsPlaneDefined() )
339 a2.SetPlane(!a.IsBendingPlane(),!a.IsNonBendingPlane());
342 a1.SetCathodeAndPlaneDisabled(kTRUE);
343 a2.SetCathodeAndPlaneDisabled(kTRUE);
345 AliMUONVPainter* p1 = AliMUONVPainter::CreatePainter(painter->ClassName(),
350 AliMUONVPainter* p2 = AliMUONVPainter::CreatePainter(painter->ClassName(),
358 new TGMsgBox(gClient->GetRoot(), this,
359 "Invalid combination", "Cannot create 2 views from this painter",
360 kMBIconExclamation, kMBOk, &ret);
361 PainterMatrixWantToShow(currentMatrix);
367 AliInfo(Form("Starting from %s will generate %s and %s",
372 p1->UpdateGroupsFrom(*(painter->Master()));
373 p2->UpdateGroupsFrom(*(painter->Master()));
381 AliMpArea area(painter->Area());
383 if ( area.Dimensions().X() > 1.2*area.Dimensions().Y() )
389 matrix = new AliMUONPainterMatrix(basename.Data(),nx,ny);
394 AddPainterMatrix(matrix);
397 matrix->SetData(currentMatrix->DataPattern(),
398 currentMatrix->Data(),
399 currentMatrix->DataIndex());
401 fPainterMatrixFrame->MouseLeave(painter);
403 PainterMatrixWantToShow(matrix);
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.SetCathode(kTRUE,kFALSE);
436 att.SetViewPoint(kTRUE,kFALSE);
438 TString name = AliMUONPainterMatrix::NameIt("Tracker",att);
440 AliMUONPainterMatrix* painterMatrix = AliMUONPainterRegistry::Instance()->FindPainterMatrix(name);
444 AliError(Form("Could not get pre-defined painter matrix %s : check that !",name.Data()));
448 PainterMatrixWantToShow(painterMatrix);
449 // fPainterMatrixFrame->Use(painterMatrix);
450 // ShowPainterMatrix(painterMatrix);
454 //_____________________________________________________________________________
456 AliMUONPainterMasterFrame::UpdateNavigation()
458 /// Update navigation frame
460 fBackButton->SetEnabled(kTRUE);
461 fForwardButton->SetEnabled(kTRUE);
463 if ( fCurrentNavigationPosition == 0 )
465 fBackButton->SetEnabled(kFALSE);
467 if ( fCurrentNavigationPosition == fNavigation.GetSize()-1 )
469 fForwardButton->SetEnabled(kFALSE);
473 //_____________________________________________________________________________
475 AliMUONPainterMasterFrame::AttributesChanged(AliMUONAttPainter* newValues)
477 /// Attributes changed (e.g. from cath0 to cath1 or bending to nonbending, etc...)
479 AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
481 AliMUONAttPainter a = currentMatrix->Validate(*newValues);
486 new TGMsgBox(gClient->GetRoot(), this,
487 "Invalid combination", "Change of attributes not possible for this object",
488 kMBIconExclamation, kMBOk, &ret);
489 PainterMatrixWantToShow(currentMatrix);
493 // First check if we already have this matrix available
495 TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Basename(),a);
497 AliMUONPainterMatrix* matrix =
498 AliMUONPainterRegistry::Instance()->FindPainterMatrix(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);