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>
35 #include <TGFileDialog.h>
37 #include <TObjArray.h>
38 #include <TObjString.h>
39 #include <TGButtonGroup.h>
43 /// \class AliMUONPainterMasterFrame
45 /// Main window of the 2D display
47 /// \author Laurent Aphecetche, Subatech
50 ClassImp(AliMUONPainterMasterFrame)
55 UInt_t UniqueID(Int_t nx, Int_t ny)
57 return ny | (nx << 8);
60 Int_t Nx(UInt_t uniqueID)
62 return ( uniqueID & 0xFF00 ) >> 8;
65 Int_t Ny(UInt_t uniqueID)
67 return uniqueID & 0xFF;
72 const Int_t AliMUONPainterMasterFrame::fgkBorderSize = 10;
74 //_____________________________________________________________________________
75 AliMUONPainterMasterFrame::AliMUONPainterMasterFrame(const TGWindow* p,
76 UInt_t w, UInt_t h, AliMUONPainterMatrix* matrix)
77 : TGCompositeFrame(p,w,h,kVerticalFrame),
78 fNavigationFrame(0x0),
79 fPainterMatrixFrame(0x0),
86 fCurrentNavigationPosition(-1),
87 fAttPainterSelectorFrame(0x0)
91 UInt_t wi = w - fgkBorderSize*2;
92 UInt_t hi = h - fgkBorderSize*3;
94 fNavigationFrame = new TGHorizontalFrame(this,wi);
96 AddFrame(fNavigationFrame,new TGLayoutHints(kLHintsExpandX|kLHintsTop,
97 fgkBorderSize,fgkBorderSize,
98 fgkBorderSize,fgkBorderSize));
100 fBackButton = new TGPictureButton(fNavigationFrame,
101 gClient->GetPicture("tb_back.xpm"));
103 fForwardButton = new TGPictureButton(fNavigationFrame,
104 gClient->GetPicture("tb_forw.xpm"));
106 fPrintMeButton = new TGTextButton(fNavigationFrame,"Print");
107 fPrintAsButton = new TGTextButton(fNavigationFrame,"Print As...");
109 fAttPainterSelectorFrame = new AliMUONAttPainterSelectorFrame(fNavigationFrame,w/2,20);
111 fGroupTitle = new TGLabel(fNavigationFrame,"");
113 fNavigationFrame->AddFrame(fBackButton,new TGLayoutHints(kLHintsCenterY));
114 fNavigationFrame->AddFrame(fForwardButton,new TGLayoutHints(kLHintsCenterY));
116 fNavigationFrame->AddFrame(fAttPainterSelectorFrame,new TGLayoutHints(kLHintsCenterY,10));
118 fNavigationFrame->AddFrame(fPrintMeButton,new TGLayoutHints(kLHintsCenterY,10));
119 fNavigationFrame->AddFrame(fPrintAsButton,new TGLayoutHints(kLHintsCenterY,10));
121 fAttPainterSelectorFrame->Connect("Clicked(AliMUONAttPainter*)",
122 "AliMUONPainterMasterFrame",
124 "AttributesChanged(AliMUONAttPainter*)");
126 fNavigationFrame->AddFrame(fGroupTitle,new TGLayoutHints(kLHintsExpandX|kLHintsCenterX|kLHintsCenterY,10));
128 fForwardButton->Connect("Clicked()","AliMUONPainterMasterFrame",
132 fBackButton->Connect("Clicked()","AliMUONPainterMasterFrame",
136 fPrintMeButton->Connect("Clicked()","AliMUONPainterMasterFrame",
140 fPrintAsButton->Connect("Clicked()","AliMUONPainterMasterFrame",
145 // UInt_t h1 = hi - fNavigationFrame->GetHeight() - 3*fgkBorderSize;
146 UInt_t h1 = hi - 7*12;
148 MakeTopPainterMatrix(w1,h1,matrix);
150 AddFrame(fPainterMatrixFrame,new TGLayoutHints(kLHintsExpandX,
151 fgkBorderSize,fgkBorderSize,
154 AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Navigation",*fNavigationFrame);
155 AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Main",*this);
157 AliDebug(1,Form("fNavigation=%p",&fNavigation));
159 AliMUONPainterRegistry::Instance()->Connect("PainterMatrixWantToShow(AliMUONPainterMatrix*)",
160 "AliMUONPainterMasterFrame",
162 "PainterMatrixWantToShow(AliMUONPainterMatrix*)");
164 fPainterMatrixFrame->DataSourceWasChanged(matrix->DataPattern().Data(),matrix->Data(),matrix->DataIndex());
167 //_____________________________________________________________________________
168 AliMUONPainterMasterFrame::~AliMUONPainterMasterFrame()
174 //_____________________________________________________________________________
176 AliMUONPainterMasterFrame::AddPainterMatrix(AliMUONPainterMatrix* painterMatrix)
178 /// array is adopted (by the registry)
180 AliDebug(1,Form("matrix=%x %s",painterMatrix,painterMatrix->GetName()));
182 Int_t i = AliMUONPainterRegistry::Instance()->Register(painterMatrix);
187 //_____________________________________________________________________________
189 AliMUONPainterMasterFrame::PainterMatrixWantToShow(AliMUONPainterMatrix* group)
191 /// FIXME: should check whether we are the active window before
192 /// responding to this message ?
194 AliDebug(1,Form("group=%x %s",group,group->GetName()));
196 Int_t i = AliMUONPainterRegistry::Instance()->FindIndexOf(group);
198 Int_t alreadyThere(-1);
200 for ( Int_t j = 0; j < fNavigation.GetSize(); ++j )
202 if ( fNavigation[j] == i ) alreadyThere = j;
211 fCurrentNavigationPosition = alreadyThere;
214 ShowPainterMatrix(group);
217 //_____________________________________________________________________________
219 AliMUONPainterMasterFrame::PrintAs() const
221 /// Handle the PrintAs button
225 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
228 if ( fileInfo.fFilename )
230 SaveAs(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)),"RECREATE");
234 //_____________________________________________________________________________
236 AliMUONPainterMasterFrame::PrintMe() const
238 /// Handle the PrintMe button
240 SaveAs(gSystem->ExpandPathName(Form("%s.png",fPainterMatrixFrame->Matrix()->GetName())),"RECREATE");
243 //_____________________________________________________________________________
245 AliMUONPainterMasterFrame::SetNavigation(Int_t i)
247 /// Change navigation position
249 ++fCurrentNavigationPosition;
250 fNavigation.Set(fCurrentNavigationPosition+1);
251 fNavigation[fCurrentNavigationPosition] = i;
254 //_____________________________________________________________________________
256 AliMUONPainterMasterFrame::ShowPainterMatrix(AliMUONPainterMatrix* painterMatrix)
258 /// Change the painter matrix we show
260 fPainterMatrixFrame->Use(painterMatrix);
262 painterMatrix->Connect("Clicked(AliMUONVPainter*,Double_t*)",
263 "AliMUONPainterMasterFrame",this,
264 "Clicked(AliMUONVPainter*,Double_t*)");
266 painterMatrix->Connect("ShiftClicked(AliMUONVPainter*,Double_t*)",
267 "AliMUONPainterMasterFrame",this,
268 "ShiftClicked(AliMUONVPainter*,Double_t*)");
270 fPainterMatrixFrame->Connect("TitleHasChanged(const char*)",
271 "AliMUONPainterMasterFrame",this,
272 "ChangeTitle(const char*)");
275 UpdateAttributes(*(fPainterMatrixFrame->Matrix()));
277 AliMUONPainterRegistry::Instance()->AddToHistory(painterMatrix);
282 //_____________________________________________________________________________
284 AliMUONPainterMasterFrame::ChangeTitle(const char* newTitle)
286 /// Change the top title
288 fGroupTitle->SetText(newTitle);
289 fGroupTitle->Resize();
293 //_____________________________________________________________________________
295 AliMUONPainterMasterFrame::Backward()
297 /// Move back one step in the history
298 --fCurrentNavigationPosition;
300 AliMUONPainterMatrix* group =
301 AliMUONPainterRegistry::Instance()->PainterMatrix(fNavigation[fCurrentNavigationPosition]);
303 ShowPainterMatrix(group);
308 //_____________________________________________________________________________
310 AliMUONPainterMasterFrame::Forward()
312 /// Move forward one step in history
314 ++fCurrentNavigationPosition;
316 AliMUONPainterMatrix* group =
317 AliMUONPainterRegistry::Instance()->PainterMatrix(fNavigation[fCurrentNavigationPosition]);
319 ShowPainterMatrix(group);
324 //_____________________________________________________________________________
326 AliMUONPainterMasterFrame::Clicked(AliMUONVPainter* painter, Double_t* values)
328 /// A given painter was (singly) clicked
330 if ( painter->CanBeDetached() )
332 fPainterMatrixFrame->MouseLeave(painter);
334 AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix(painter->Name().Data());
336 AliMUONVPainter* p = painter->Detach();
342 AddPainterMatrix(matrix);
343 ShowPainterMatrix(matrix);
347 painter->DrawHistogram(values);
351 //_____________________________________________________________________________
353 AliMUONPainterMasterFrame::ShiftClicked(AliMUONVPainter* painter, Double_t*)
355 /// A given painter was shift-clicked
357 if ( !painter->CanBeDetached() ) return;
359 AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
361 AliMUONAttPainter a = painter->Attributes();
363 TString basename(Form("%s-DUAL",painter->GetName()));
365 TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Whatname(),basename.Data(),a);
367 AliMUONPainterMatrix* matrix = AliMUONPainterRegistry::Instance()->PainterMatrix(newName.Data());
371 // No. So we must make a new matrix painter from the existing one,
372 // and add to this new matrix the painters of the other one, but
373 // using the new attributes...
375 // create "opposite" attributes
376 AliMUONAttPainter a1(a);
377 AliMUONAttPainter a2(a);
381 a1.SetCathodeAndPlaneDisabled(kTRUE);
382 a2.SetCathodeAndPlaneDisabled(kTRUE);
384 AliMUONVPainter* p1 = AliMUONVPainter::CreatePainter(painter->ClassName(),
389 AliMUONVPainter* p2 = AliMUONVPainter::CreatePainter(painter->ClassName(),
397 new TGMsgBox(gClient->GetRoot(), this,
398 "Invalid combination", "Cannot create 2 views from this painter",
399 kMBIconExclamation, kMBOk, &ret);
400 PainterMatrixWantToShow(currentMatrix);
406 p1->UpdateGroupsFrom(*(painter->Master()));
407 p2->UpdateGroupsFrom(*(painter->Master()));
415 AliMpArea area(painter->Area());
417 if ( area.GetDimensionX() > 1.2*area.GetDimensionY() )
423 matrix = new AliMUONPainterMatrix(basename.Data(),nx,ny);
428 AddPainterMatrix(matrix);
431 matrix->SetData(currentMatrix->DataPattern(),
432 currentMatrix->Data(),
433 currentMatrix->DataIndex());
435 fPainterMatrixFrame->MouseLeave(painter);
437 PainterMatrixWantToShow(matrix);
440 //_____________________________________________________________________________
442 AliMUONPainterMasterFrame::SaveAs(const char* filename, Option_t* option) const
444 /// Save painter matrix (in the sense of "print") in filename
445 fPainterMatrixFrame->SaveAs(filename,option);
448 //_____________________________________________________________________________
450 AliMUONPainterMasterFrame::Update()
454 fPainterMatrixFrame->Update();
455 fPainterMatrixFrame->UpdateInterface(kFALSE);
458 //_____________________________________________________________________________
460 AliMUONPainterMasterFrame::UpdateAttributes(const AliMUONPainterMatrix& painterMatrix)
462 /// Update the view buttons from the matrix we actually plot
464 fAttPainterSelectorFrame->Update(painterMatrix.Attributes());
467 //_____________________________________________________________________________
469 AliMUONPainterMasterFrame::MakeTopPainterMatrix(UInt_t w, UInt_t h, AliMUONPainterMatrix* matrix)
471 /// Create the first painter matrix that appears when we are create
472 /// FIXME: how to make this more flexible ?
474 fPainterMatrixFrame = new AliMUONPainterMatrixFrame(this,w,h);
478 PainterMatrixWantToShow(matrix);
482 AliError("Cannot work without a painterMatrix");
486 //_____________________________________________________________________________
488 AliMUONPainterMasterFrame::UpdateNavigation()
490 /// Update navigation frame
492 fBackButton->SetEnabled(kTRUE);
493 fForwardButton->SetEnabled(kTRUE);
495 if ( fCurrentNavigationPosition == 0 )
497 fBackButton->SetEnabled(kFALSE);
499 if ( fCurrentNavigationPosition == fNavigation.GetSize()-1 )
501 fForwardButton->SetEnabled(kFALSE);
505 //_____________________________________________________________________________
507 AliMUONPainterMasterFrame::AttributesChanged(AliMUONAttPainter* newValues)
509 /// Attributes changed (e.g. from cath0 to cath1 or bending to nonbending, etc...)
511 AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
513 AliMUONAttPainter a = currentMatrix->Validate(*newValues);
518 new TGMsgBox(gClient->GetRoot(), this,
519 "Invalid combination", "Change of attributes not possible for this object",
520 kMBIconExclamation, kMBOk, &ret);
521 PainterMatrixWantToShow(currentMatrix);
525 // First check if we already have this matrix available
527 TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Whatname(),currentMatrix->Basename(),a);
529 AliMUONPainterMatrix* matrix = AliMUONPainterRegistry::Instance()->PainterMatrix(newName.Data());
533 // No. So we must make a new matrix painter from the existing one,
534 // and add to this new matrix the painters of the other one, but
535 // using the new attributes...
537 matrix = currentMatrix->Clone(a);
539 AddPainterMatrix(matrix);
542 matrix->SetData(currentMatrix->DataPattern(),
543 currentMatrix->Data(),
544 currentMatrix->DataIndex());
546 PainterMatrixWantToShow(matrix);