]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPainterMatrixFrame.cxx
Update of classes in libMUONgraphics and mchview program:
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterMatrixFrame.cxx
CommitLineData
0145e89a 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
18#include "AliMUONPainterMatrixFrame.h"
19
20#include "AliMUONPainterColorSlider.h"
21#include "AliMUONPainterMatrix.h"
22#include "AliMUONPainterGroup.h"
23#include "AliMUONPainterHighlighter.h"
24#include "AliMUONPainterInterfaceHelper.h"
25#include "AliMUONPainterPlotSelector.h"
26#include "AliMUONPainterRegistry.h"
27#include "AliMUONVTrackerData.h"
28#include "AliMUONVPainter.h"
29#include "AliLog.h"
30#include <Riostream.h>
31#include <TCanvas.h>
32#include <TEnv.h>
33#include <TGButton.h>
34#include <TGButtonGroup.h>
35#include <TGFrame.h>
36#include <TGListBox.h>
37#include <TObjArray.h>
38#include <TObjString.h>
39#include <TRootEmbeddedCanvas.h>
40#include <TString.h>
41#include <cassert>
42#include <float.h>
43
44/// \class AliMUONPainterMatrixFrame
45///
46/// A widget to draw a painter matrix, and the corresponding interface
47/// to select what to outline or paint, and which part of the painter
48/// is responding to mouse events
49///
50/// \author Laurent Aphecetche, Subatech
51
52///\cond CLASSIMP
53ClassImp(AliMUONPainterMatrixFrame)
54///\endcond
55
56//_____________________________________________________________________________
57AliMUONPainterMatrixFrame::AliMUONPainterMatrixFrame(const TGWindow* window,
58 UInt_t w, UInt_t h)
59: TGCompositeFrame(window,w,h,kVerticalFrame|kDoubleBorder),
60 fPainterMatrix(0x0),
61 fView(0x0),
62 fInterface(0x0),
63 fResponderButtons(0x0),
64 fOutlineButtons(0x0),
65 fPlotSelector(0x0),
66 fPainterHighlighter(new AliMUONPainterHighlighter),
67 fCanvasWidth(0),
68 fCanvasHeight(0),
69 fMainFrame(0x0),
70 fColorSlider(0x0)
71{
72 /// ctor
73 const Int_t kBorderSize = 10;
74
75 UInt_t wi = w - kBorderSize*0;
76 UInt_t hi = h - kBorderSize*1;
77
78 fCanvasWidth = wi;
79 fCanvasHeight = (UInt_t)(hi*0.75);
80
81 fMainFrame = new TGHorizontalFrame(this,fCanvasWidth,hi);
82
83 const Int_t kColorWidth = 100;
84
9016a84e 85 fColorSlider = new AliMUONPainterColorSlider(fMainFrame,kColorWidth,fCanvasHeight);
0145e89a 86
87 fView = new TRootEmbeddedCanvas("ec",fMainFrame,fCanvasWidth-kColorWidth,fCanvasHeight,kChildFrame);
88
89 fInterface = new TGHorizontalFrame(this,fCanvasWidth);
90
91 fMainFrame->AddFrame(fView, new TGLayoutHints(kLHintsLeft));
9016a84e 92 fMainFrame->AddFrame(fColorSlider,new TGLayoutHints(kLHintsTop|kLHintsRight|kLHintsExpandX|kLHintsCenterY,kBorderSize/2));
0145e89a 93
94 AliMUONPainterInterfaceHelper::SetBackgroundColor("MatrixFrame.ColorSlider",*fColorSlider);
95
96 fResponderButtons = new TGButtonGroup(fInterface,"Responder");
97
98 fOutlineButtons = new TGButtonGroup(fInterface,"Outline");
99
100 fInterface->AddFrame(fResponderButtons);
101 fInterface->AddFrame(fOutlineButtons);
102
103 fPlotSelector =
104 new AliMUONPainterPlotSelector(fInterface);//,wi,interfaceHeight);
105
106 fInterface->AddFrame(fPlotSelector);//,new TGLayoutHints(kLHintsRight|kLHintsExpandX));
107
108 fOutlineButtons->Show();
109 fResponderButtons->Show();
110
111 AddFrame(fMainFrame,new TGLayoutHints(kLHintsExpandX|kLHintsTop,
112 0,0,0,0));
113
114 AddFrame(fInterface,new TGLayoutHints(kLHintsExpandX|kLHintsBottom,
115 0,0,kBorderSize,0));
116
117
118 // Set the connections
119
120 fPlotSelector->Connect("DataSourceWasChanged(const char*,AliMUONVTrackerData*,Int_t)",
121 "AliMUONPainterMatrixFrame",
122 this,
123 "DataSourceWasChanged(const char*,AliMUONVTrackerData*,Int_t)");
124
125 fColorSlider->Connect("DataRangeWasChanged(Double_t*)",
126 "AliMUONPainterMatrixFrame",
127 this,
128 "DataRangeWasChanged(Double_t*)");
129
130 fColorSlider->Connect("DataRangeAutoRequested()",
131 "AliMUONPainterMatrixFrame",
132 this,
133 "DataRangeAutoRequested()");
134
135 // Set the colors (mainly for debugging frame layout)
136
137 AliMUONPainterInterfaceHelper::SetBackgroundColor("MatrixFrame.Main",*this);
138
139 fMainFrame->HideFrame(fColorSlider);
140
141 fMainFrame->Resize();
142}
143
144//_____________________________________________________________________________
145AliMUONPainterMatrixFrame::~AliMUONPainterMatrixFrame()
146{
147 /// dtor
148 delete fPainterHighlighter;
149 AliError("Please write a decent dtor for this class !");
150}
151
152//_____________________________________________________________________________
153void
154AliMUONPainterMatrixFrame::ChangeTitle(const TString& title)
155{
156 /// Change title
157
158 TitleHasChanged(title.Data());
159}
160
161//_____________________________________________________________________________
162void
163AliMUONPainterMatrixFrame::ChangeTitle(AliMUONVPainter* painter,
164 const char* basename,
165 Double_t x, Double_t y)
166{
167 /// Change the title according to painter
168
169 TString name;
170
171 if (painter)
172 {
173
174 if ( basename ) name = basename;
175 else name = painter->PathName();
176
177 AliMUONVPainter* master = painter->Master();
178
179 AliMUONPainterGroup* group = master->PlotterGroup();
180
181 AliDebug(1,Form("Painter is %s plotterGroup is %x %s",
182 painter->PathName().Data(),
183 group,
184 ( group ? group->Type() : "")));
185
186
187 if ( group && group->Data() )
188 {
189 name += "\n";
190 name += painter->Describe(*(group->Data()),group->DataIndex(),x,y);
191 }
192 }
193 else
194 {
195 name = fPainterMatrix->Name();
196 }
197
198 TitleHasChanged(name.Data());
199}
200
201//_____________________________________________________________________________
202void
203AliMUONPainterMatrixFrame::Clear(Option_t*)
204{
205 /// Clear the view(s)
206
207 fPainterMatrix = 0x0;
208
209 AliMUONPainterInterfaceHelper::ClearButtons(*fOutlineButtons);
210 AliMUONPainterInterfaceHelper::ClearButtons(*fResponderButtons);
211
212 fView->GetCanvas()->SetEditable(kTRUE);
213 fView->GetCanvas()->Clear();
214 fView->GetCanvas()->Modified();
215 fView->GetCanvas()->Update();
216 fView->GetCanvas()->SetEditable(kFALSE);
217
218 Layout();
219}
220
221//_____________________________________________________________________________
222void
223AliMUONPainterMatrixFrame::CreateButtons()
224{
225 /// Create the interface buttons
226
227 AliDebug(1,"");
228
229// AliMUONVPainter* painter = fPainterMatrix->Painter(0);
230
231 /// create buttons
232 TObjArray types;
233
234 fPainterMatrix->GetTypes(types);
235
236 TIter nextType(&types);
237 TObjString* str;
238
239 while ( ( str = static_cast<TObjString*>(nextType()) ) )
240 {
241 AliMUONPainterInterfaceHelper::AddRadioButton(*fResponderButtons,str->String());
242 AliMUONPainterInterfaceHelper::AddCheckButton(*fOutlineButtons,str->String());
243 }
244
245 fOutlineButtons->Connect("Clicked(Int_t)","AliMUONPainterMatrixFrame",
246 this,"OutlineButtonWasClicked(Int_t)");
247
248 fResponderButtons->Connect("Clicked(Int_t)","AliMUONPainterMatrixFrame",
249 this,"ResponderButtonWasClicked(Int_t)");
250}
251
252//_____________________________________________________________________________
253void
254AliMUONPainterMatrixFrame::DataRangeAutoRequested()
255{
256 /// Get there when the "Auto" button below the color slider is clicked,
257 /// to compute the data range actually painted.
258
259 Double_t dataMin, dataMax;
260
261 AliDebug(1,"");
262
263 fPainterMatrix->ComputeDataRange();
264
265 fPainterMatrix->GetDataRange(dataMin,dataMax);
266
267 AliDebug(1,Form("dataMin,Max for SetRange=%e,%e",dataMin,dataMax));
268
269 Bool_t emit(kTRUE);
270
271 fColorSlider->SetRange(dataMin,dataMax,emit);
272
273 Update();
274}
275
276//_____________________________________________________________________________
277void
278AliMUONPainterMatrixFrame::DataRangeWasChanged(Double_t* range)
279{
280 /// Get there when the data range is changed
281
282 AliDebug(1,Form("range=%e,%e",range[0],range[1]));
283
284 fPainterMatrix->SetDataRange(range[0],range[1]);
285
286 Update();
287}
288
289//_____________________________________________________________________________
290void
291AliMUONPainterMatrixFrame::DataSourceWasChanged(const char* type,
292 AliMUONVTrackerData* data,
293 Int_t indexInData)
294{
295 /// Update what to plot
296
297 TString pattern(type);
298
299 AliDebug(1,Form("type=%s data=%s index=%d",type,
300 (data ? data->GetName() : "null"),indexInData));
301
302 AliMUONVTrackerData* d = data;
303
304 if ( !d || !data || indexInData < 0 || pattern == "" )
305 {
306 pattern = "*";
307 d = 0;
308 indexInData = -1;
309 }
310
311 fPainterMatrix->SetData(pattern,d,indexInData);
312
313 Update();
314
315 ChangeTitle(fPainterMatrix->Painter(0));
316}
317
318//_____________________________________________________________________________
319void
320AliMUONPainterMatrixFrame::EventInfo(Int_t event, Int_t px ,Int_t py, TObject* object)
321{
322 /// Used to detect entering/leaving a given painter
323
324 if (!gPad || !object) return;
325
326// cout << "EventInfo : event " << event << " px " << px << " py " << py
327// << " object " << object << " " << object->GetName() << endl;
328//
329//
330 if ( event == 7 )
331 {
332 if ( object->InheritsFrom("AliMUONVPainter") )
333 {
334 AliMUONVPainter* p = static_cast<AliMUONVPainter*>(object);
335 p->ExecuteEvent(7,px,py);
336 return;
337 }
338 }
339
340 if ( event == kMouseLeave )
341 {
342 if ( object->InheritsFrom("AliMUONVPainter") )
343 {
344 AliMUONVPainter* p = static_cast<AliMUONVPainter*>(object);
345 MouseLeave(p);
346 fPainterHighlighter->SetPainter(0x0);
347 gPad->Modified();
348 gPad->Update();
349 }
350 }
351
352 if ( event == kMouseEnter )
353 {
354 if ( object->InheritsFrom("AliMUONVPainter") )
355 {
356 AliMUONVPainter* painter = static_cast<AliMUONVPainter*>(object);
357 if ( painter->IsResponder() && !painter->HandleMouseMotion() )
358 {
359 MouseEnter(static_cast<AliMUONVPainter*>(object));
360 fPainterHighlighter->SetPainter(painter);
361 gPad->Modified();
362 gPad->Update();
363 }
364 else if ( !painter->HandleMouseMotion() )
365 {
366 MouseEnter(static_cast<AliMUONVPainter*>(object));
367 }
368 }
369 }
370
371 if ( event == kMouseMotion )
372 {
373 if ( object->InheritsFrom("AliMUONVPainter") )
374 {
375 AliMUONVPainter* painter = static_cast<AliMUONVPainter*>(object);
376
377 if ( painter->HandleMouseMotion() && painter->IsResponder() )
378 {
379 Double_t pos[2];
380 TVirtualPad* padsave = gPad;
381 painter->Pad()->cd();
382 painter->PixelToPad(px,py,pos[0],pos[1]);
383 MouseMotion(static_cast<AliMUONVPainter*>(object),pos);
384 fPainterHighlighter->SetPainter(painter,pos[0],pos[1]);
385 gPad->Modified();
386 gPad->Update();
387 gPad = padsave;
388 }
389 }
390 }
391}
392
393//_____________________________________________________________________________
394void
395AliMUONPainterMatrixFrame::MouseEnter(AliMUONVPainter* painter)
396{
397 /// Emit a signal to notify that mouse pointer is entering a given painter
398
399 AliDebug(1,Form("painter=%x %s",painter,painter->PathName().Data()));
400
401 ChangeTitle(painter);
402
403 Long_t params[] = { (Long_t)painter };
404
405 Emit("MouseEnter(AliMUONVPainter*)",params);
406}
407
408
409//_____________________________________________________________________________
410void
411AliMUONPainterMatrixFrame::MouseLeave(AliMUONVPainter* painter)
412{
413 /// Emit a signal to notify that mouse pointer is leaving a given painter
414
415 ChangeTitle(fPainterMatrix->Name());
416
417 Long_t params[] = { (Long_t)painter };
418
419 Emit("MouseLeave(AliMUONVPainter*)",params);
420}
421
422//_____________________________________________________________________________
423void
424AliMUONPainterMatrixFrame::MouseMotion(AliMUONVPainter* painter, Double_t* position)
425{
426 /// Emit a signal to notify that mouse pointer is moving within a given painter
427
428 ChangeTitle(painter,painter->NameAtPosition(position[0],position[1]),
429 position[0],position[1]);
430
431 Long_t params[] = { (Long_t)painter, (Long_t)position };
432
433 Emit("MouseMotion(AliMUONVPainter*,Double_t*)",params);
434}
435
436
437//_____________________________________________________________________________
438void
439AliMUONPainterMatrixFrame::ResponderButtonWasClicked(Int_t id)
440{
441 /// One responder button was clicked
442
443 TGTextButton* button = static_cast<TGTextButton*>(fResponderButtons->GetButton(id));
444 TString pattern = button->GetString();
445
446// AliInfo(Form("id=%d button=%d %s",id,button->IsOn(),pattern.Data()));
447
448 assert(button->IsOn()==1);
449
450 fPainterMatrix->SetResponder(pattern.Data());
451}
452
453//_____________________________________________________________________________
454void
455AliMUONPainterMatrixFrame::OutlineButtonWasClicked(Int_t id)
456{
457 /// One outline button was clicked
458
459 TGTextButton* button = static_cast<TGTextButton*>(fOutlineButtons->GetButton(id));
460 TString pattern = button->GetString();
461
462 fPainterMatrix->SetOutlined(pattern.Data(),button->IsOn());
463
464 ViewModified();
465 fView->GetCanvas()->Update();
466
467 // Update the interface (e.g. list of possible responders can have
468 // changed due to visibility change)
469 UpdateInterface(kFALSE);
470}
471
472//_____________________________________________________________________________
473void
474AliMUONPainterMatrixFrame::TitleHasChanged(const char* title)
475{
476 /// Emit the TitleHasChanged signal
477
478 Long_t params[] = { (Long_t)title };
479 Emit("TitleHasChanged(const char*)",params);
480}
481
482
483//_____________________________________________________________________________
484void
485AliMUONPainterMatrixFrame::Update()
486{
487 /// Force update of all canvases
488
489 UpdateDataRange();
490
491 fView->GetCanvas()->SetEditable(kTRUE);
492
493 Bool_t colorSlider = ( fPainterMatrix->Data() != 0x0 );
494
495 ViewModified();
496
497 fView->GetCanvas()->SetEditable(kFALSE);
498
499 AliDebug(1,Form("colorSlider=%d",colorSlider));
500
501 if ( colorSlider )
502 {
503 fMainFrame->ShowFrame(fColorSlider);
504 }
505 else
506 {
507 fMainFrame->HideFrame(fColorSlider);
508 }
509
510 fMainFrame->Layout();
511 Layout();
512}
513
514//_____________________________________________________________________________
515void
516AliMUONPainterMatrixFrame::UpdateDataRange()
517{
518 /// Update the data range
519
520 Double_t min, max;
521
522 fPainterMatrix->GetDataRange(min,max);
523
524 AliDebug(1,Form("min %e max %e",min,max));
525
526 if ( min > max )
527 {
528 fPainterMatrix->ComputeDataRange();
529 fPainterMatrix->GetDataRange(min,max);
530 }
531
532 fColorSlider->SetRange(min,max,kFALSE);
533}
534
535//_____________________________________________________________________________
536void
537AliMUONPainterMatrixFrame::UpdateInterface(Bool_t fromScratch)
538{
539 /// Update the full interface
540
541 if ( fromScratch || fOutlineButtons->GetCount() == 0 )
542 {
543 CreateButtons();
544 }
545
546 AliMUONPainterInterfaceHelper::Unselect(*fResponderButtons,"*");
547 AliMUONPainterInterfaceHelper::Unselect(*fOutlineButtons,"*");
548
549 AliMUONVPainter* painter = fPainterMatrix->Painter(0);
550
551 TObjArray types;
552 types.SetOwner(kTRUE);
553
554 fPainterMatrix->GetTypes(types);
555
556 // update button states
557 TIter next(&types);
558 TObjString* otype;
559
560 TString theResponder;
561
562 while ( ( otype = static_cast<TObjString*>(next()) ) )
563 {
564 AliMUONPainterGroup* group = painter->Group(otype->String());
565
566 if ( group && group->IsOutlined() )
567 {
568 AliMUONPainterInterfaceHelper::Select(*fOutlineButtons,otype->String().Data());
569 }
570 }
571
572 if ( painter )
573 {
574 AliMUONPainterGroup* responderGroup = painter->ResponderGroup();
575
576 if (responderGroup)
577 {
578 AliMUONPainterInterfaceHelper::Select(*fResponderButtons,responderGroup->Type());
579 }
580 }
581
582 // update data source view
583
584 fPlotSelector->Update(*fPainterMatrix);
585
586 fResponderButtons->Show();
587 fOutlineButtons->Show();
588
589 Layout();
590}
591
592//_____________________________________________________________________________
593void
594AliMUONPainterMatrixFrame::Use(AliMUONPainterMatrix* group)
595{
596 /// Change the matrix used
597
598 Clear();
599
600 fPainterMatrix = group;
601
602 fView->GetCanvas()->SetEditable(kTRUE);
603
604 fView->GetCanvas()->Divide(fPainterMatrix->Nx(),fPainterMatrix->Ny());
605
606 for ( Int_t i = 0; i < fPainterMatrix->Size(); ++i )
607 {
608 AliMUONVPainter* painter = fPainterMatrix->Painter(i);
609 fView->GetCanvas()->cd(i+1);
610 painter->Draw("R");
611 fPainterHighlighter->SetPainter(0x0);
612 fPainterHighlighter->Draw();
613 }
614
615 Update();
616
617 UpdateInterface(kTRUE);
618
619 ChangeTitle(fPainterMatrix->Name());
620
621 fView->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
622 "AliMUONPainterMatrixFrame",this,
623 "EventInfo(Int_t,Int_t,Int_t,TObject*)");
624
625}
626
627//_____________________________________________________________________________
628void
629AliMUONPainterMatrixFrame::ViewModified()
630{
631 /// Update our canvas
632
633 for ( Int_t i = 0; i < fPainterMatrix->Size(); ++i )
634 {
635 fView->GetCanvas()->GetPad(i+1)->Modified();
636 }
637 fView->GetCanvas()->Modified();
638 fView->GetCanvas()->Update();
639}
640
641