AliRoot Core  v5-06-15 (45dab64)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONPainterMasterFrame.cxx
Go to the documentation of this file.
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 
19 
20 #include "AliMUONChamberPainter.h"
21 #include "AliMUONPainterGroup.h"
22 #include "AliMUONPainterMatrix.h"
25 #include "AliMUONPainterRegistry.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 
48 
52 
53 const Int_t AliMUONPainterMasterFrame::fgkBorderSize = 10;
54 
55 //_____________________________________________________________________________
57  UInt_t w, UInt_t h, AliMUONPainterMatrix* matrix)
58 : TGCompositeFrame(p,w,h,kVerticalFrame),
59 fNavigationFrame(0x0),
60 fPainterMatrixFrame(0x0),
61 fBackButton(0x0),
62 fForwardButton(0x0),
63 fGroupTitle(0x0),
64 fPrintMeButton(0x0),
65 fPrintAsButton(0x0),
66 fNavigation(),
67 fCurrentNavigationPosition(-1),
68 fAttPainterSelectorFrame(0x0)
69 {
71 
72  UInt_t wi = w - fgkBorderSize*2;
73  UInt_t hi = h - fgkBorderSize*3;
74 
75  fNavigationFrame = new TGHorizontalFrame(this,wi);
76 
77  AddFrame(fNavigationFrame,new TGLayoutHints(kLHintsExpandX|kLHintsTop,
78  fgkBorderSize,fgkBorderSize,
79  fgkBorderSize,fgkBorderSize));
80 
81  fBackButton = new TGPictureButton(fNavigationFrame,
82  gClient->GetPicture("tb_back.xpm"));
83 
84  fForwardButton = new TGPictureButton(fNavigationFrame,
85  gClient->GetPicture("tb_forw.xpm"));
86 
87  fPrintMeButton = new TGTextButton(fNavigationFrame,"Print");
88  fPrintAsButton = new TGTextButton(fNavigationFrame,"Print As...");
89 
90  fAttPainterSelectorFrame = new AliMUONAttPainterSelectorFrame(fNavigationFrame,w/2,20);
91 
92  fGroupTitle = new TGLabel(fNavigationFrame,"");
93 
94  fNavigationFrame->AddFrame(fBackButton,new TGLayoutHints(kLHintsCenterY));
95  fNavigationFrame->AddFrame(fForwardButton,new TGLayoutHints(kLHintsCenterY));
96 
97  fNavigationFrame->AddFrame(fAttPainterSelectorFrame,new TGLayoutHints(kLHintsCenterY,10));
98 
99  fNavigationFrame->AddFrame(fPrintMeButton,new TGLayoutHints(kLHintsCenterY,10));
100  fNavigationFrame->AddFrame(fPrintAsButton,new TGLayoutHints(kLHintsCenterY,10));
101 
102  fAttPainterSelectorFrame->Connect("Clicked(AliMUONAttPainter*)",
103  "AliMUONPainterMasterFrame",
104  this,
105  "AttributesChanged(AliMUONAttPainter*)");
106 
107  fNavigationFrame->AddFrame(fGroupTitle,new TGLayoutHints(kLHintsExpandX|kLHintsCenterX|kLHintsCenterY,10));
108 
109  fForwardButton->Connect("Clicked()","AliMUONPainterMasterFrame",
110  this,
111  "Forward()");
112 
113  fBackButton->Connect("Clicked()","AliMUONPainterMasterFrame",
114  this,
115  "Backward()");
116 
117  fPrintMeButton->Connect("Clicked()","AliMUONPainterMasterFrame",
118  this,
119  "PrintMe()");
120 
121  fPrintAsButton->Connect("Clicked()","AliMUONPainterMasterFrame",
122  this,
123  "PrintAs()");
124 
125  UInt_t w1 = wi;
126  // UInt_t h1 = hi - fNavigationFrame->GetHeight() - 3*fgkBorderSize;
127  UInt_t h1 = hi - 7*12;
128 
129  MakeTopPainterMatrix(w1,h1,matrix);
130 
131  AddFrame(fPainterMatrixFrame,new TGLayoutHints(kLHintsExpandX,
132  fgkBorderSize,fgkBorderSize,
133  0,fgkBorderSize));
134 
135  AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Navigation",*fNavigationFrame);
136  AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Main",*this);
137 
138  AliMUONPainterRegistry::Instance()->Connect("PainterMatrixWantToShow(AliMUONPainterMatrix*)",
139  "AliMUONPainterMasterFrame",
140  this,
141  "PainterMatrixWantToShow(AliMUONPainterMatrix*)");
142 
143  fPainterMatrixFrame->DataSourceWasChanged(matrix->DataPattern().Data(),matrix->Data(),matrix->DataIndex());
144 }
145 
146 //_____________________________________________________________________________
148 {
150  Cleanup();
151 }
152 
153 //_____________________________________________________________________________
154 void
156 {
158 
159  Int_t i = AliMUONPainterRegistry::Instance()->Register(painterMatrix);
160 
161  SetNavigation(i);
162 }
163 
164 //_____________________________________________________________________________
165 void
167 {
170 
171  Int_t i = AliMUONPainterRegistry::Instance()->FindIndexOf(group);
172 
173  Int_t alreadyThere(-1);
174 
175  for ( Int_t j = 0; j < fNavigation.GetSize(); ++j )
176  {
177  if ( fNavigation[j] == i ) alreadyThere = j;
178  }
179 
180  if (alreadyThere<0)
181  {
182  SetNavigation(i);
183  }
184  else
185  {
186  fCurrentNavigationPosition = alreadyThere;
187  }
188 
189  ShowPainterMatrix(group);
190 }
191 
192 //_____________________________________________________________________________
193 void
195 {
197 
198  TGFileInfo fileInfo;
199 
200  new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
201  kFDSave,&fileInfo);
202 
203  if ( fileInfo.fFilename )
204  {
205  SaveAs(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)),"RECREATE");
206  }
207 }
208 
209 //_____________________________________________________________________________
210 void
212 {
214 
215  SaveAs(gSystem->ExpandPathName(Form("%s.png",fPainterMatrixFrame->Matrix()->GetName())),"RECREATE");
216 }
217 
218 //_____________________________________________________________________________
219 void
221 {
223 
227 }
228 
229 //_____________________________________________________________________________
230 void
232 {
234 
235  fPainterMatrixFrame->Use(painterMatrix);
236 
237  painterMatrix->Connect("Clicked(AliMUONVPainter*,Double_t*)",
238  "AliMUONPainterMasterFrame",this,
239  "Clicked(AliMUONVPainter*,Double_t*)");
240 
241  painterMatrix->Connect("ShiftClicked(AliMUONVPainter*,Double_t*)",
242  "AliMUONPainterMasterFrame",this,
243  "ShiftClicked(AliMUONVPainter*,Double_t*)");
244 
245  fPainterMatrixFrame->Connect("TitleHasChanged(const char*)",
246  "AliMUONPainterMasterFrame",this,
247  "ChangeTitle(const char*)");
249 
251 
253 
254  //Layout();
255 }
256 
257 //_____________________________________________________________________________
258 void
260 {
262 
263  fGroupTitle->SetText(newTitle);
264  fGroupTitle->Resize();
265  Layout();
266 }
267 
268 //_____________________________________________________________________________
269 void
271 {
274 
275  AliMUONPainterMatrix* group =
277 
278  ShowPainterMatrix(group);
279 
281 }
282 
283 //_____________________________________________________________________________
284 void
286 {
288 
290 
291  AliMUONPainterMatrix* group =
293 
294  ShowPainterMatrix(group);
295 
297 }
298 
299 //_____________________________________________________________________________
300 void
302 {
304 
305  if ( painter->CanBeDetached() )
306  {
308 
309  AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix(painter->Name().Data());
310 
311  AliMUONVPainter* p = painter->Detach();
312 
313  p->SetResponder(1);
314 
315  matrix->Adopt(p);
316 
317  AddPainterMatrix(matrix);
318  ShowPainterMatrix(matrix);
319  }
320  else
321  {
322  painter->DrawHistogram(values);
323  }
324 }
325 
326 //_____________________________________________________________________________
327 void
329 {
331 
332  if ( !painter->CanBeDetached() ) return;
333 
334  AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
335 
336  AliMUONAttPainter a = painter->Attributes();
337 
338  TString basename(Form("%s-DUAL",painter->GetName()));
339 
340  TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Whatname(),basename.Data(),a);
341 
343 
344  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  AliMUONAttPainter a1(a);
352  AliMUONAttPainter a2(a);
353 
354  a2.Invert();
355 
356  a1.SetCathodeAndPlaneDisabled(kTRUE);
357  a2.SetCathodeAndPlaneDisabled(kTRUE);
358 
359  AliMUONVPainter* p1 = AliMUONVPainter::CreatePainter(painter->ClassName(),
360  a1,
361  painter->ID0(),
362  painter->ID1());
363 
364  AliMUONVPainter* p2 = AliMUONVPainter::CreatePainter(painter->ClassName(),
365  a2,
366  painter->ID0(),
367  painter->ID1());
368 
369  if (!p1 || !p2)
370  {
371  Int_t ret;
372  new TGMsgBox(gClient->GetRoot(), this,
373  "Invalid combination", "Cannot create 2 views from this painter",
374  kMBIconExclamation, kMBOk, &ret);
375  PainterMatrixWantToShow(currentMatrix);
376  delete p1;
377  delete p2;
378  return;
379  }
380 
381  p1->UpdateGroupsFrom(*(painter->Master()));
382  p2->UpdateGroupsFrom(*(painter->Master()));
383 
384  p1->SetResponder(1);
385  p2->SetResponder(1);
386 
387  Int_t nx(2);
388  Int_t ny(1);
389 
390  AliMpArea area(painter->Area());
391 
392  if ( area.GetDimensionX() > 1.2*area.GetDimensionY() )
393  {
394  nx = 1;
395  ny = 2;
396  }
397 
398  matrix = new AliMUONPainterMatrix(basename.Data(),nx,ny);
399 
400  matrix->Adopt(p1);
401  matrix->Adopt(p2);
402 
403  AddPainterMatrix(matrix);
404  }
405 
406  matrix->SetData(currentMatrix->DataPattern(),
407  currentMatrix->Data(),
408  currentMatrix->DataIndex());
409 
411 
412  PainterMatrixWantToShow(matrix);
413 }
414 
415 //_____________________________________________________________________________
416 void
417 AliMUONPainterMasterFrame::SaveAs(const char* filename, Option_t* option) const
418 {
420  fPainterMatrixFrame->SaveAs(filename,option);
421 }
422 
423 //_____________________________________________________________________________
424 void
426 {
428 
431 }
432 
433 //_____________________________________________________________________________
434 void
436 {
438 
439  fAttPainterSelectorFrame->Update(painterMatrix.Attributes());
440 }
441 
442 //_____________________________________________________________________________
443 void
445 {
448 
450 
451  if (matrix)
452  {
453  PainterMatrixWantToShow(matrix);
454  }
455  else
456  {
457  AliError("Cannot work without a painterMatrix");
458  }
459 }
460 
461 //_____________________________________________________________________________
462 void
464 {
466 
467  fBackButton->SetEnabled(kTRUE);
468  fForwardButton->SetEnabled(kTRUE);
469 
470  if ( fCurrentNavigationPosition == 0 )
471  {
472  fBackButton->SetEnabled(kFALSE);
473  }
474  if ( fCurrentNavigationPosition == fNavigation.GetSize()-1 )
475  {
476  fForwardButton->SetEnabled(kFALSE);
477  }
478 }
479 
480 //_____________________________________________________________________________
481 void
483 {
485 
486  AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix();
487 
488  AliMUONAttPainter a = currentMatrix->Validate(*newValues);
489 
490  if (!a.IsValid())
491  {
492  Int_t ret;
493  new TGMsgBox(gClient->GetRoot(), this,
494  "Invalid combination", "Change of attributes not possible for this object",
495  kMBIconExclamation, kMBOk, &ret);
496  PainterMatrixWantToShow(currentMatrix);
497  return;
498  }
499 
500  // First check if we already have this matrix available
501 
502  TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Whatname(),currentMatrix->Basename(),a);
503 
505 
506  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  matrix = currentMatrix->Clone(a);
513 
514  AddPainterMatrix(matrix);
515  }
516 
517  matrix->SetData(currentMatrix->DataPattern(),
518  currentMatrix->Data(),
519  currentMatrix->DataIndex());
520 
521  PainterMatrixWantToShow(matrix);
522 }
const char * Whatname() const
void PainterMatrixWantToShow(AliMUONPainterMatrix *group)
virtual const char * GetName() const
Get matrix name.
Widget to select the painter(s) view type.
AliMUONVPainter * Detach() const
void UpdateAttributes(const AliMUONPainterMatrix &painterMatrix)
void ShowPainterMatrix(AliMUONPainterMatrix *group)
void ShiftClicked(AliMUONVPainter *painter, Double_t *values)
virtual Bool_t CanBeDetached() const
Whether this painter can be detached from the current view.
virtual TString Name() const
Get our name.
virtual void SetResponder(const char *pattern)
A rectangle area positioned in plane..
Definition: AliMpArea.h:20
void ChangeTitle(const char *newTitle)
virtual const char * GetName() const
Get our name.
static void SetBackgroundColor(const char *resourceBaseName, TGWindow &window)
static std::string NameIt(const char *what, const char *basename, const AliMUONAttPainter &att)
Int_t Register(AliMUONPainterMatrix *group)
void AddPainterMatrix(AliMUONPainterMatrix *group)
void Use(AliMUONPainterMatrix *group)
Int_t ID0() const
Get our first ID.
static AliMUONVPainter * CreatePainter(const char *className, const AliMUONAttPainter &att, Int_t id1, Int_t id2)
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
static AliMUONPainterRegistry * Instance()
void Connect(const char *sourceMethod, const char *destClassName, void *destObject, const char *destMethod)
const AliMUONAttPainter & Attributes() const
Get our attributes.
Int_t ID1() const
Get our second ID.
Base class for a graphical object representing some part of the MUON tracking system.
Int_t FindIndexOf(AliMUONPainterMatrix *group) const
const char * Basename() const
Base name (short name)
AliMUONPainterMatrix * Clone(const AliMUONAttPainter &attributes) const
void SetCathodeAndPlaneDisabled(Bool_t value)
AliMUONVPainter * Master() const
TGButton * fForwardButton
navigation forward
AliMpArea Area() const
Return the area containing this painter.
The main window for the offline "a la mood" display.
AliMUONAttPainter Validate(const AliMUONAttPainter &att) const
Normalize attributes.
AliMUONVTrackerData * Data() const
void Adopt(AliMUONVPainter *painter)
Adopt a painter in this matrix.
AliMUONPainterMatrix * Matrix() const
Get the matrix pointer.
Widget to plot a matrix of painters.
void UpdateInterface(Bool_t fromScratch)
void AttributesChanged(const AliMUONAttPainter *newValues)
Bool_t IsValid() const
Whether we are valid.
void MakeTopPainterMatrix(UInt_t w, UInt_t h, AliMUONPainterMatrix *matrix)
void AddToHistory(AliMUONPainterMatrix *group)
AliMUONPainterMatrixFrame * fPainterMatrixFrame
main frame with painters
void UpdateGroupsFrom(const AliMUONVPainter &painter)
Basic attributes shared by all painters.
void MouseLeave(const AliMUONVPainter *painter)
Int_t fCurrentNavigationPosition
current position in navigation history
AliMUONPainterMatrix * PainterMatrix(Int_t i) const
void SaveAs(const char *filename="", Option_t *option="") const
void SaveAs(const char *filename="", Option_t *option="") const
AliMUONAttPainterSelectorFrame * fAttPainterSelectorFrame
view type selection frame
TArrayI fNavigation
navigation "history"
void Clicked(AliMUONVPainter *painter, Double_t *values)
TGButton * fBackButton
navigation back
A matrix of AliMUONVPainter.
void Update(const AliMUONAttPainter &att)
const AliMUONAttPainter & Attributes() const
Get our attributes.
virtual void DrawHistogram(Double_t *values=0x0) const