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 "AliMUONPainterMatrixFrame.h"
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"
30 #include <Riostream.h>
34 #include <TGButtonGroup.h>
36 #include <TGListBox.h>
37 #include <TObjArray.h>
38 #include <TObjString.h>
39 #include <TRootEmbeddedCanvas.h>
44 /// \class AliMUONPainterMatrixFrame
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
50 /// \author Laurent Aphecetche, Subatech
53 ClassImp(AliMUONPainterMatrixFrame)
56 //_____________________________________________________________________________
57 AliMUONPainterMatrixFrame::AliMUONPainterMatrixFrame(const TGWindow* window,
59 : TGCompositeFrame(window,w,h,kVerticalFrame|kDoubleBorder),
63 fResponderButtons(0x0),
66 fPainterHighlighter(new AliMUONPainterHighlighter),
73 const Int_t kBorderSize = 10;
75 UInt_t wi = w - kBorderSize*0;
76 UInt_t hi = h - kBorderSize*1;
79 fCanvasHeight = (UInt_t)(hi*0.75);
81 fMainFrame = new TGHorizontalFrame(this,fCanvasWidth,hi);
83 const Int_t kColorWidth = 100;
85 fColorSlider = new AliMUONPainterColorSlider(fMainFrame,kColorWidth,fCanvasHeight);
87 fView = new TRootEmbeddedCanvas("ec",fMainFrame,fCanvasWidth-kColorWidth,fCanvasHeight,kChildFrame);
89 fInterface = new TGHorizontalFrame(this,fCanvasWidth);
91 fMainFrame->AddFrame(fView, new TGLayoutHints(kLHintsLeft));
92 fMainFrame->AddFrame(fColorSlider,new TGLayoutHints(kLHintsTop|kLHintsRight|kLHintsExpandX|kLHintsCenterY,kBorderSize/2));
94 AliMUONPainterInterfaceHelper::SetBackgroundColor("MatrixFrame.ColorSlider",*fColorSlider);
96 fResponderButtons = new TGButtonGroup(fInterface,"Responder");
98 fOutlineButtons = new TGButtonGroup(fInterface,"Outline");
100 fInterface->AddFrame(fResponderButtons);
101 fInterface->AddFrame(fOutlineButtons);
104 new AliMUONPainterPlotSelector(fInterface);//,wi,interfaceHeight);
106 fInterface->AddFrame(fPlotSelector);//,new TGLayoutHints(kLHintsRight|kLHintsExpandX));
108 fOutlineButtons->Show();
109 fResponderButtons->Show();
111 AddFrame(fMainFrame,new TGLayoutHints(kLHintsExpandX|kLHintsTop,
114 AddFrame(fInterface,new TGLayoutHints(kLHintsExpandX|kLHintsBottom,
118 // Set the connections
120 fPlotSelector->Connect("DataSourceWasChanged(const char*,AliMUONVTrackerData*,Int_t)",
121 "AliMUONPainterMatrixFrame",
123 "DataSourceWasChanged(const char*,AliMUONVTrackerData*,Int_t)");
125 fColorSlider->Connect("DataRangeWasChanged(Double_t*)",
126 "AliMUONPainterMatrixFrame",
128 "DataRangeWasChanged(Double_t*)");
130 fColorSlider->Connect("DataRangeAutoRequested()",
131 "AliMUONPainterMatrixFrame",
133 "DataRangeAutoRequested()");
135 // Set the colors (mainly for debugging frame layout)
137 AliMUONPainterInterfaceHelper::SetBackgroundColor("MatrixFrame.Main",*this);
139 fMainFrame->HideFrame(fColorSlider);
141 fMainFrame->Resize();
144 //_____________________________________________________________________________
145 AliMUONPainterMatrixFrame::~AliMUONPainterMatrixFrame()
148 delete fPainterHighlighter;
149 AliError("Please write a decent dtor for this class !");
152 //_____________________________________________________________________________
154 AliMUONPainterMatrixFrame::ChangeTitle(const TString& title)
158 TitleHasChanged(title.Data());
161 //_____________________________________________________________________________
163 AliMUONPainterMatrixFrame::ChangeTitle(AliMUONVPainter* painter,
164 const char* basename,
165 Double_t x, Double_t y)
167 /// Change the title according to painter
174 if ( basename ) name = basename;
175 else name = painter->PathName();
177 AliMUONVPainter* master = painter->Master();
179 AliMUONPainterGroup* group = master->PlotterGroup();
181 AliDebug(1,Form("Painter is %s plotterGroup is %x %s",
182 painter->PathName().Data(),
184 ( group ? group->Type() : "")));
187 if ( group && group->Data() )
190 name += painter->Describe(*(group->Data()),group->DataIndex(),x,y);
195 name = fPainterMatrix->Name();
198 TitleHasChanged(name.Data());
201 //_____________________________________________________________________________
203 AliMUONPainterMatrixFrame::Clear(Option_t*)
205 /// Clear the view(s)
207 fPainterMatrix = 0x0;
209 AliMUONPainterInterfaceHelper::ClearButtons(*fOutlineButtons);
210 AliMUONPainterInterfaceHelper::ClearButtons(*fResponderButtons);
212 fView->GetCanvas()->SetEditable(kTRUE);
213 fView->GetCanvas()->Clear();
214 fView->GetCanvas()->Modified();
215 fView->GetCanvas()->Update();
216 fView->GetCanvas()->SetEditable(kFALSE);
221 //_____________________________________________________________________________
223 AliMUONPainterMatrixFrame::CreateButtons()
225 /// Create the interface buttons
229 // AliMUONVPainter* painter = fPainterMatrix->Painter(0);
234 fPainterMatrix->GetTypes(types);
236 TIter nextType(&types);
239 while ( ( str = static_cast<TObjString*>(nextType()) ) )
241 AliMUONPainterInterfaceHelper::AddRadioButton(*fResponderButtons,str->String());
242 AliMUONPainterInterfaceHelper::AddCheckButton(*fOutlineButtons,str->String());
245 fOutlineButtons->Connect("Clicked(Int_t)","AliMUONPainterMatrixFrame",
246 this,"OutlineButtonWasClicked(Int_t)");
248 fResponderButtons->Connect("Clicked(Int_t)","AliMUONPainterMatrixFrame",
249 this,"ResponderButtonWasClicked(Int_t)");
252 //_____________________________________________________________________________
254 AliMUONPainterMatrixFrame::DataRangeAutoRequested()
256 /// Get there when the "Auto" button below the color slider is clicked,
257 /// to compute the data range actually painted.
259 Double_t dataMin, dataMax;
263 fPainterMatrix->ComputeDataRange();
265 fPainterMatrix->GetDataRange(dataMin,dataMax);
267 AliDebug(1,Form("dataMin,Max for SetRange=%e,%e",dataMin,dataMax));
271 fColorSlider->SetRange(dataMin,dataMax,emit);
276 //_____________________________________________________________________________
278 AliMUONPainterMatrixFrame::DataRangeWasChanged(Double_t* range)
280 /// Get there when the data range is changed
282 AliDebug(1,Form("range=%e,%e",range[0],range[1]));
284 fPainterMatrix->SetDataRange(range[0],range[1]);
289 //_____________________________________________________________________________
291 AliMUONPainterMatrixFrame::DataSourceWasChanged(const char* type,
292 AliMUONVTrackerData* data,
295 /// Update what to plot
297 TString pattern(type);
299 AliDebug(1,Form("type=%s data=%s index=%d",type,
300 (data ? data->GetName() : "null"),indexInData));
302 AliMUONVTrackerData* d = data;
304 if ( !d || !data || indexInData < 0 || pattern == "" )
311 fPainterMatrix->SetData(pattern,d,indexInData);
315 ChangeTitle(fPainterMatrix->Painter(0));
318 //_____________________________________________________________________________
320 AliMUONPainterMatrixFrame::EventInfo(Int_t event, Int_t px ,Int_t py, TObject* object)
322 /// Used to detect entering/leaving a given painter
324 if (!gPad || !object) return;
326 // cout << "EventInfo : event " << event << " px " << px << " py " << py
327 // << " object " << object << " " << object->GetName() << endl;
331 if ( object->InheritsFrom("AliMUONVPainter") )
333 AliMUONVPainter* p = static_cast<AliMUONVPainter*>(object);
334 p->ExecuteEvent(7,px,py);
339 if ( event == kMouseLeave )
341 if ( object->InheritsFrom("AliMUONVPainter") )
343 AliMUONVPainter* p = static_cast<AliMUONVPainter*>(object);
345 fPainterHighlighter->SetPainter(0x0);
351 if ( event == kMouseEnter )
353 if ( object->InheritsFrom("AliMUONVPainter") )
355 AliMUONVPainter* painter = static_cast<AliMUONVPainter*>(object);
356 if ( painter->IsResponder() && !painter->HandleMouseMotion() )
358 MouseEnter(static_cast<AliMUONVPainter*>(object));
359 fPainterHighlighter->SetPainter(painter);
363 else if ( !painter->HandleMouseMotion() )
365 MouseEnter(static_cast<AliMUONVPainter*>(object));
370 if ( event == kMouseMotion )
372 if ( object->InheritsFrom("AliMUONVPainter") )
374 AliMUONVPainter* painter = static_cast<AliMUONVPainter*>(object);
376 if ( painter->HandleMouseMotion() && painter->IsResponder() )
379 TVirtualPad* padsave = gPad;
380 painter->Pad()->cd();
381 painter->PixelToPad(px,py,pos[0],pos[1]);
382 MouseMotion(static_cast<AliMUONVPainter*>(object),pos);
383 fPainterHighlighter->SetPainter(painter,pos[0],pos[1]);
392 //_____________________________________________________________________________
394 AliMUONPainterMatrixFrame::MouseEnter(AliMUONVPainter* painter)
396 /// Emit a signal to notify that mouse pointer is entering a given painter
398 AliDebug(1,Form("painter=%x %s",painter,painter->PathName().Data()));
400 ChangeTitle(painter);
402 Long_t params[] = { (Long_t)painter };
404 Emit("MouseEnter(AliMUONVPainter*)",params);
408 //_____________________________________________________________________________
410 AliMUONPainterMatrixFrame::MouseLeave(AliMUONVPainter* painter)
412 /// Emit a signal to notify that mouse pointer is leaving a given painter
414 ChangeTitle(fPainterMatrix->Name());
416 Long_t params[] = { (Long_t)painter };
418 Emit("MouseLeave(AliMUONVPainter*)",params);
421 //_____________________________________________________________________________
423 AliMUONPainterMatrixFrame::MouseMotion(AliMUONVPainter* painter, Double_t* position)
425 /// Emit a signal to notify that mouse pointer is moving within a given painter
427 ChangeTitle(painter,painter->NameAtPosition(position[0],position[1]),
428 position[0],position[1]);
430 Long_t params[] = { (Long_t)painter, (Long_t)position };
432 Emit("MouseMotion(AliMUONVPainter*,Double_t*)",params);
436 //_____________________________________________________________________________
438 AliMUONPainterMatrixFrame::ResponderButtonWasClicked(Int_t id)
440 /// One responder button was clicked
442 TGTextButton* button = static_cast<TGTextButton*>(fResponderButtons->GetButton(id));
443 TString pattern = button->GetString();
445 // AliInfo(Form("id=%d button=%d %s",id,button->IsOn(),pattern.Data()));
447 assert(button->IsOn()==1);
449 fPainterMatrix->SetResponder(pattern.Data());
452 //_____________________________________________________________________________
454 AliMUONPainterMatrixFrame::OutlineButtonWasClicked(Int_t id)
456 /// One outline button was clicked
458 TGTextButton* button = static_cast<TGTextButton*>(fOutlineButtons->GetButton(id));
459 TString pattern = button->GetString();
461 fPainterMatrix->SetOutlined(pattern.Data(),button->IsOn());
464 fView->GetCanvas()->Update();
466 // Update the interface (e.g. list of possible responders can have
467 // changed due to visibility change)
468 UpdateInterface(kFALSE);
471 //_____________________________________________________________________________
473 AliMUONPainterMatrixFrame::SaveAs(const char* filename, Option_t* option) const
475 /// Save painter matrix (in the sense of "print") in filename
476 fView->GetCanvas()->SaveAs(filename,option);
479 //_____________________________________________________________________________
481 AliMUONPainterMatrixFrame::TitleHasChanged(const char* title)
483 /// Emit the TitleHasChanged signal
485 Long_t params[] = { (Long_t)title };
486 Emit("TitleHasChanged(const char*)",params);
490 //_____________________________________________________________________________
492 AliMUONPainterMatrixFrame::Update()
494 /// Force update of all canvases
498 fView->GetCanvas()->SetEditable(kTRUE);
500 Bool_t colorSlider = ( fPainterMatrix->Data() != 0x0 );
504 fView->GetCanvas()->SetEditable(kFALSE);
506 AliDebug(1,Form("colorSlider=%d",colorSlider));
510 fMainFrame->ShowFrame(fColorSlider);
514 fMainFrame->HideFrame(fColorSlider);
517 fMainFrame->Layout();
521 //_____________________________________________________________________________
523 AliMUONPainterMatrixFrame::UpdateDataRange()
525 /// Update the data range
529 fPainterMatrix->GetDataRange(min,max);
531 AliDebug(1,Form("min %e max %e",min,max));
535 fPainterMatrix->ComputeDataRange();
536 fPainterMatrix->GetDataRange(min,max);
539 fColorSlider->SetRange(min,max,kFALSE);
542 //_____________________________________________________________________________
544 AliMUONPainterMatrixFrame::UpdateInterface(Bool_t fromScratch)
546 /// Update the full interface
548 if ( fromScratch || fOutlineButtons->GetCount() == 0 )
553 AliMUONPainterInterfaceHelper::Unselect(*fResponderButtons,"*");
554 AliMUONPainterInterfaceHelper::Unselect(*fOutlineButtons,"*");
556 AliMUONVPainter* painter = fPainterMatrix->Painter(0);
559 types.SetOwner(kTRUE);
561 fPainterMatrix->GetTypes(types);
563 // update button states
567 TString theResponder;
569 while ( ( otype = static_cast<TObjString*>(next()) ) )
571 AliMUONPainterGroup* group = painter->Group(otype->String());
573 if ( group && group->IsOutlined() )
575 AliMUONPainterInterfaceHelper::Select(*fOutlineButtons,otype->String().Data());
581 AliMUONPainterGroup* responderGroup = painter->ResponderGroup();
585 AliMUONPainterInterfaceHelper::Select(*fResponderButtons,responderGroup->Type());
589 // update data source view
591 fPlotSelector->Update(*fPainterMatrix);
593 fResponderButtons->Show();
594 fOutlineButtons->Show();
599 //_____________________________________________________________________________
601 AliMUONPainterMatrixFrame::Use(AliMUONPainterMatrix* group)
603 /// Change the matrix used
607 fPainterMatrix = group;
609 fView->GetCanvas()->SetEditable(kTRUE);
611 fView->GetCanvas()->Divide(fPainterMatrix->Nx(),fPainterMatrix->Ny());
613 for ( Int_t i = 0; i < fPainterMatrix->Size(); ++i )
615 AliMUONVPainter* painter = fPainterMatrix->Painter(i);
616 fView->GetCanvas()->cd(i+1);
618 fPainterHighlighter->SetPainter(0x0);
619 fPainterHighlighter->Draw();
624 UpdateInterface(kTRUE);
626 ChangeTitle(fPainterMatrix->Name());
628 fView->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
629 "AliMUONPainterMatrixFrame",this,
630 "EventInfo(Int_t,Int_t,Int_t,TObject*)");
634 //_____________________________________________________________________________
636 AliMUONPainterMatrixFrame::ViewModified()
638 /// Update our canvas
640 for ( Int_t i = 0; i < fPainterMatrix->Size(); ++i )
642 fView->GetCanvas()->GetPad(i+1)->Modified();
644 fView->GetCanvas()->Modified();
645 fView->GetCanvas()->Update();