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)
53 const Int_t AliMUONPainterMasterFrame::fgkBorderSize = 10;
55 //_____________________________________________________________________________
56 AliMUONPainterMasterFrame::AliMUONPainterMasterFrame(const TGWindow* p,
57 UInt_t w, UInt_t h, AliMUONPainterMatrix* matrix)
58 : TGCompositeFrame(p,w,h,kVerticalFrame),
59 fNavigationFrame(0x0),
60 fPainterMatrixFrame(0x0),
67 fCurrentNavigationPosition(-1),
68 fAttPainterSelectorFrame(0x0)
72 UInt_t wi = w - fgkBorderSize*2;
73 UInt_t hi = h - fgkBorderSize*3;
75 fNavigationFrame = new TGHorizontalFrame(this,wi);
77 AddFrame(fNavigationFrame,new TGLayoutHints(kLHintsExpandX|kLHintsTop,
78 fgkBorderSize,fgkBorderSize,
79 fgkBorderSize,fgkBorderSize));
81 fBackButton = new TGPictureButton(fNavigationFrame,
82 gClient->GetPicture("tb_back.xpm"));
84 fForwardButton = new TGPictureButton(fNavigationFrame,
85 gClient->GetPicture("tb_forw.xpm"));
87 fPrintMeButton = new TGTextButton(fNavigationFrame,"Print");
88 fPrintAsButton = new TGTextButton(fNavigationFrame,"Print As...");
90 fAttPainterSelectorFrame = new AliMUONAttPainterSelectorFrame(fNavigationFrame,w/2,20);
92 fGroupTitle = new TGLabel(fNavigationFrame,"");
94 fNavigationFrame->AddFrame(fBackButton,new TGLayoutHints(kLHintsCenterY));
95 fNavigationFrame->AddFrame(fForwardButton,new TGLayoutHints(kLHintsCenterY));
97 fNavigationFrame->AddFrame(fAttPainterSelectorFrame,new TGLayoutHints(kLHintsCenterY,10));
99 fNavigationFrame->AddFrame(fPrintMeButton,new TGLayoutHints(kLHintsCenterY,10));
100 fNavigationFrame->AddFrame(fPrintAsButton,new TGLayoutHints(kLHintsCenterY,10));
102 fAttPainterSelectorFrame->Connect("Clicked(AliMUONAttPainter*)",
103 "AliMUONPainterMasterFrame",
105 "AttributesChanged(AliMUONAttPainter*)");
107 fNavigationFrame->AddFrame(fGroupTitle,new TGLayoutHints(kLHintsExpandX|kLHintsCenterX|kLHintsCenterY,10));
109 fForwardButton->Connect("Clicked()","AliMUONPainterMasterFrame",
113 fBackButton->Connect("Clicked()","AliMUONPainterMasterFrame",
117 fPrintMeButton->Connect("Clicked()","AliMUONPainterMasterFrame",
121 fPrintAsButton->Connect("Clicked()","AliMUONPainterMasterFrame",
126 // UInt_t h1 = hi - fNavigationFrame->GetHeight() - 3*fgkBorderSize;
127 UInt_t h1 = hi - 7*12;
129 MakeTopPainterMatrix(w1,h1,matrix);
131 AddFrame(fPainterMatrixFrame,new TGLayoutHints(kLHintsExpandX,
132 fgkBorderSize,fgkBorderSize,
135 AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Navigation",*fNavigationFrame);
136 AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Main",*this);
138 AliDebug(1,Form("fNavigation=%p",&fNavigation));
140 AliMUONPainterRegistry::Instance()->Connect("PainterMatrixWantToShow(AliMUONPainterMatrix*)",
141 "AliMUONPainterMasterFrame",
143 "PainterMatrixWantToShow(AliMUONPainterMatrix*)");
145 fPainterMatrixFrame->DataSourceWasChanged(matrix->DataPattern().Data(),matrix->Data(),matrix->DataIndex());
148 //_____________________________________________________________________________
149 AliMUONPainterMasterFrame::~AliMUONPainterMasterFrame()
155 //_____________________________________________________________________________
157 AliMUONPainterMasterFrame::AddPainterMatrix(AliMUONPainterMatrix* painterMatrix)
159 /// array is adopted (by the registry)
161 AliDebug(1,Form("matrix=%p %s",painterMatrix,painterMatrix->GetName()));
163 Int_t i = AliMUONPainterRegistry::Instance()->Register(painterMatrix);
168 //_____________________________________________________________________________
170 AliMUONPainterMasterFrame::PainterMatrixWantToShow(AliMUONPainterMatrix* group)
172 /// FIXME: should check whether we are the active window before
173 /// responding to this message ?
175 AliDebug(1,Form("group=%p %s",group,group->GetName()));
177 Int_t i = AliMUONPainterRegistry::Instance()->FindIndexOf(group);
179 Int_t alreadyThere(-1);
181 for ( Int_t j = 0; j < fNavigation.GetSize(); ++j )
183 if ( fNavigation[j] == i ) alreadyThere = j;
192 fCurrentNavigationPosition = alreadyThere;
195 ShowPainterMatrix(group);
198 //_____________________________________________________________________________
200 AliMUONPainterMasterFrame::PrintAs() const
202 /// Handle the PrintAs button
206 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
209 if ( fileInfo.fFilename )
211 SaveAs(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)),"RECREATE");
215 //_____________________________________________________________________________
217 AliMUONPainterMasterFrame::PrintMe() const
219 /// Handle the PrintMe button
221 SaveAs(gSystem->ExpandPathName(Form("%s.png",fPainterMatrixFrame->Matrix()->GetName())),"RECREATE");
224 //_____________________________________________________________________________
226 AliMUONPainterMasterFrame::SetNavigation(Int_t i)
228 /// Change navigation position
230 ++fCurrentNavigationPosition;
231 fNavigation.Set(fCurrentNavigationPosition+1);
232 fNavigation[fCurrentNavigationPosition] = i;
235 //_____________________________________________________________________________
237 AliMUONPainterMasterFrame::ShowPainterMatrix(AliMUONPainterMatrix* painterMatrix)
239 /// Change the painter matrix we show
241 fPainterMatrixFrame->Use(painterMatrix);
243 painterMatrix->Connect("Clicked(AliMUONVPainter*,Double_t*)",
244 "AliMUONPainterMasterFrame",this,
245 "Clicked(AliMUONVPainter*,Double_t*)");
247 painterMatrix->Connect("ShiftClicked(AliMUONVPainter*,Double_t*)",
248 "AliMUONPainterMasterFrame",this,
249 "ShiftClicked(AliMUONVPainter*,Double_t*)");
251 fPainterMatrixFrame->Connect("TitleHasChanged(const char*)",
252 "AliMUONPainterMasterFrame",this,
253 "ChangeTitle(const char*)");
256 UpdateAttributes(*(fPainterMatrixFrame->Matrix()));
258 AliMUONPainterRegistry::Instance()->AddToHistory(painterMatrix);
263 //_____________________________________________________________________________
265 AliMUONPainterMasterFrame::ChangeTitle(const char* newTitle)
267 /// Change the top title
269 fGroupTitle->SetText(newTitle);
270 fGroupTitle->Resize();
274 //_____________________________________________________________________________
276 AliMUONPainterMasterFrame::Backward()
278 /// Move back one step in the history
279 --fCurrentNavigationPosition;
281 AliMUONPainterMatrix* group =
282 AliMUONPainterRegistry::Instance()->PainterMatrix(fNavigation[fCurrentNavigationPosition]);
284 ShowPainterMatrix(group);
289 //_____________________________________________________________________________
291 AliMUONPainterMasterFrame::Forward()
293 /// Move forward one step in history
295 ++fCurrentNavigationPosition;
297 AliMUONPainterMatrix* group =
298 AliMUONPainterRegistry::Instance()->PainterMatrix(fNavigation[fCurrentNavigationPosition]);
300 ShowPainterMatrix(group);
305 //_____________________________________________________________________________
307 AliMUONPainterMasterFrame::Clicked(AliMUONVPainter* painter, Double_t* values)
309 /// A given painter was (singly) clicked
311 if ( painter->CanBeDetached() )
313 fPainterMatrixFrame->MouseLeave(painter);
315 AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix(painter->Name().Data());
317 AliMUONVPainter* p = painter->Detach();
323 AddPainterMatrix(matrix);
324 ShowPainterMatrix(matrix);
328 painter->DrawHistogram(values);
332 //_____________________________________________________________________________
334 AliMUONPainterMasterFrame::ShiftClicked(AliMUONVPainter* painter, Double_t*)
336 /// A given painter was shift-clicked
338 if ( !painter->CanBeDetached() ) return;
340 AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
342 AliMUONAttPainter a = painter->Attributes();
344 TString basename(Form("%s-DUAL",painter->GetName()));
346 TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Whatname(),basename.Data(),a);
348 AliMUONPainterMatrix* matrix = AliMUONPainterRegistry::Instance()->PainterMatrix(newName.Data());
352 // No. So we must make a new matrix painter from the existing one,
353 // and add to this new matrix the painters of the other one, but
354 // using the new attributes...
356 // create "opposite" attributes
357 AliMUONAttPainter a1(a);
358 AliMUONAttPainter a2(a);
362 a1.SetCathodeAndPlaneDisabled(kTRUE);
363 a2.SetCathodeAndPlaneDisabled(kTRUE);
365 AliMUONVPainter* p1 = AliMUONVPainter::CreatePainter(painter->ClassName(),
370 AliMUONVPainter* p2 = AliMUONVPainter::CreatePainter(painter->ClassName(),
378 new TGMsgBox(gClient->GetRoot(), this,
379 "Invalid combination", "Cannot create 2 views from this painter",
380 kMBIconExclamation, kMBOk, &ret);
381 PainterMatrixWantToShow(currentMatrix);
387 p1->UpdateGroupsFrom(*(painter->Master()));
388 p2->UpdateGroupsFrom(*(painter->Master()));
396 AliMpArea area(painter->Area());
398 if ( area.GetDimensionX() > 1.2*area.GetDimensionY() )
404 matrix = new AliMUONPainterMatrix(basename.Data(),nx,ny);
409 AddPainterMatrix(matrix);
412 matrix->SetData(currentMatrix->DataPattern(),
413 currentMatrix->Data(),
414 currentMatrix->DataIndex());
416 fPainterMatrixFrame->MouseLeave(painter);
418 PainterMatrixWantToShow(matrix);
421 //_____________________________________________________________________________
423 AliMUONPainterMasterFrame::SaveAs(const char* filename, Option_t* option) const
425 /// Save painter matrix (in the sense of "print") in filename
426 fPainterMatrixFrame->SaveAs(filename,option);
429 //_____________________________________________________________________________
431 AliMUONPainterMasterFrame::Update()
435 fPainterMatrixFrame->Update();
436 fPainterMatrixFrame->UpdateInterface(kFALSE);
439 //_____________________________________________________________________________
441 AliMUONPainterMasterFrame::UpdateAttributes(const AliMUONPainterMatrix& painterMatrix)
443 /// Update the view buttons from the matrix we actually plot
445 fAttPainterSelectorFrame->Update(painterMatrix.Attributes());
448 //_____________________________________________________________________________
450 AliMUONPainterMasterFrame::MakeTopPainterMatrix(UInt_t w, UInt_t h, AliMUONPainterMatrix* matrix)
452 /// Create the first painter matrix that appears when we are create
453 /// FIXME: how to make this more flexible ?
455 fPainterMatrixFrame = new AliMUONPainterMatrixFrame(this,w,h);
459 PainterMatrixWantToShow(matrix);
463 AliError("Cannot work without a painterMatrix");
467 //_____________________________________________________________________________
469 AliMUONPainterMasterFrame::UpdateNavigation()
471 /// Update navigation frame
473 fBackButton->SetEnabled(kTRUE);
474 fForwardButton->SetEnabled(kTRUE);
476 if ( fCurrentNavigationPosition == 0 )
478 fBackButton->SetEnabled(kFALSE);
480 if ( fCurrentNavigationPosition == fNavigation.GetSize()-1 )
482 fForwardButton->SetEnabled(kFALSE);
486 //_____________________________________________________________________________
488 AliMUONPainterMasterFrame::AttributesChanged(const AliMUONAttPainter* newValues)
490 /// Attributes changed (e.g. from cath0 to cath1 or bending to nonbending, etc...)
492 AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
494 AliMUONAttPainter a = currentMatrix->Validate(*newValues);
499 new TGMsgBox(gClient->GetRoot(), this,
500 "Invalid combination", "Change of attributes not possible for this object",
501 kMBIconExclamation, kMBOk, &ret);
502 PainterMatrixWantToShow(currentMatrix);
506 // First check if we already have this matrix available
508 TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Whatname(),currentMatrix->Basename(),a);
510 AliMUONPainterMatrix* matrix = AliMUONPainterRegistry::Instance()->PainterMatrix(newName.Data());
514 // No. So we must make a new matrix painter from the existing one,
515 // and add to this new matrix the painters of the other one, but
516 // using the new attributes...
518 matrix = currentMatrix->Clone(a);
520 AddPainterMatrix(matrix);
523 matrix->SetData(currentMatrix->DataPattern(),
524 currentMatrix->Data(),
525 currentMatrix->DataIndex());
527 PainterMatrixWantToShow(matrix);