]>
Commit | Line | Data |
---|---|---|
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 "AliMUONPainterMasterFrame.h" | |
19 | ||
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" | |
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 <TGLabel.h> | |
36 | #include <TObjArray.h> | |
37 | #include <TObjString.h> | |
38 | #include <TGButtonGroup.h> | |
39 | #include <TGMsgBox.h> | |
40 | ||
41 | /// \class AliMUONPainterMasterFrame | |
42 | /// | |
43 | /// Main window of the 2D display | |
44 | /// | |
45 | /// \author Laurent Aphecetche, Subatech | |
46 | ||
47 | ///\cond CLASSIMP | |
48 | ClassImp(AliMUONPainterMasterFrame) | |
49 | ///\endcond | |
50 | ||
51 | namespace | |
52 | { | |
53 | UInt_t UniqueID(Int_t nx, Int_t ny) | |
54 | { | |
55 | return ny | (nx << 8); | |
56 | } | |
57 | ||
58 | Int_t Nx(UInt_t uniqueID) | |
59 | { | |
60 | return ( uniqueID & 0xFF00 ) >> 8; | |
61 | } | |
62 | ||
63 | Int_t Ny(UInt_t uniqueID) | |
64 | { | |
65 | return uniqueID & 0xFF; | |
66 | } | |
67 | ||
68 | } | |
69 | ||
70 | const Int_t AliMUONPainterMasterFrame::fgkBorderSize = 10; | |
71 | ||
72 | //_____________________________________________________________________________ | |
73 | AliMUONPainterMasterFrame::AliMUONPainterMasterFrame(const TGWindow* p, | |
74 | UInt_t w, UInt_t h) | |
75 | : TGCompositeFrame(p,w,h,kVerticalFrame), | |
76 | fNavigationFrame(0x0), | |
77 | fPainterMatrixFrame(0x0), | |
78 | fBackButton(0x0), | |
79 | fForwardButton(0x0), | |
80 | fGroupTitle(0x0), | |
81 | fNavigation(), | |
82 | fCurrentNavigationPosition(-1), | |
83 | fAttPainterSelectorFrame(0x0) | |
84 | { | |
85 | /// ctor | |
86 | ||
87 | UInt_t wi = w - fgkBorderSize*2; | |
88 | UInt_t hi = h - fgkBorderSize*3; | |
89 | ||
90 | fNavigationFrame = new TGHorizontalFrame(this,wi); | |
91 | ||
92 | AddFrame(fNavigationFrame,new TGLayoutHints(kLHintsExpandX|kLHintsTop, | |
93 | fgkBorderSize,fgkBorderSize, | |
94 | fgkBorderSize,fgkBorderSize)); | |
95 | ||
96 | fBackButton = new TGPictureButton(fNavigationFrame, | |
97 | gClient->GetPicture("tb_back.xpm")); | |
98 | ||
99 | fForwardButton = new TGPictureButton(fNavigationFrame, | |
100 | gClient->GetPicture("tb_forw.xpm")); | |
101 | ||
102 | fAttPainterSelectorFrame = new AliMUONAttPainterSelectorFrame(fNavigationFrame,w/2,20); | |
103 | ||
104 | fGroupTitle = new TGLabel(fNavigationFrame,""); | |
105 | ||
106 | fNavigationFrame->AddFrame(fBackButton,new TGLayoutHints(kLHintsCenterY)); | |
107 | fNavigationFrame->AddFrame(fForwardButton,new TGLayoutHints(kLHintsCenterY)); | |
108 | ||
109 | fNavigationFrame->AddFrame(fAttPainterSelectorFrame,new TGLayoutHints(kLHintsCenterY,10)); | |
110 | ||
111 | fAttPainterSelectorFrame->Connect("Clicked(AliMUONAttPainter*)", | |
112 | "AliMUONPainterMasterFrame", | |
113 | this, | |
114 | "AttributesChanged(AliMUONAttPainter*)"); | |
115 | ||
116 | fNavigationFrame->AddFrame(fGroupTitle,new TGLayoutHints(kLHintsExpandX|kLHintsCenterX|kLHintsCenterY,10)); | |
117 | ||
118 | fForwardButton->Connect("Clicked()","AliMUONPainterMasterFrame", | |
119 | this, | |
120 | "Forward()"); | |
121 | ||
122 | fBackButton->Connect("Clicked()","AliMUONPainterMasterFrame", | |
123 | this, | |
124 | "Backward()"); | |
125 | ||
126 | ||
127 | ||
128 | UInt_t w1 = wi; | |
9016a84e | 129 | // UInt_t h1 = hi - fNavigationFrame->GetHeight() - 3*fgkBorderSize; |
130 | UInt_t h1 = hi - 7*12; | |
0145e89a | 131 | |
132 | MakeTopPainterMatrix(w1,h1); | |
133 | ||
134 | AddFrame(fPainterMatrixFrame,new TGLayoutHints(kLHintsExpandX, | |
135 | fgkBorderSize,fgkBorderSize, | |
136 | 0,fgkBorderSize)); | |
137 | ||
138 | AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Navigation",*fNavigationFrame); | |
139 | AliMUONPainterInterfaceHelper::SetBackgroundColor("MasterFrame.Main",*this); | |
140 | ||
141 | AliDebug(1,Form("fNavigation=%p",&fNavigation)); | |
142 | ||
143 | AliMUONPainterRegistry::Instance()->Connect("PainterMatrixWantToShow(AliMUONPainterMatrix*)", | |
144 | "AliMUONPainterMasterFrame", | |
145 | this, | |
146 | "PainterMatrixWantToShow(AliMUONPainterMatrix*)"); | |
147 | ||
148 | fPainterMatrixFrame->DataSourceWasChanged("*",0x0,-1); | |
149 | } | |
150 | ||
151 | //_____________________________________________________________________________ | |
152 | AliMUONPainterMasterFrame::~AliMUONPainterMasterFrame() | |
153 | { | |
154 | /// dtor | |
155 | Cleanup(); | |
156 | } | |
157 | ||
158 | //_____________________________________________________________________________ | |
159 | void | |
160 | AliMUONPainterMasterFrame::AddPainterMatrix(AliMUONPainterMatrix* painterMatrix) | |
161 | { | |
162 | /// array is adopted (by the registry) | |
163 | ||
164 | AliDebug(1,Form("matrix=%x %s",painterMatrix,painterMatrix->GetName())); | |
165 | ||
166 | Int_t i = AliMUONPainterRegistry::Instance()->Register(painterMatrix); | |
167 | ||
168 | SetNavigation(i); | |
169 | } | |
170 | ||
171 | //_____________________________________________________________________________ | |
172 | void | |
173 | AliMUONPainterMasterFrame::PainterMatrixWantToShow(AliMUONPainterMatrix* group) | |
174 | { | |
9016a84e | 175 | /// FIXME: should check whether we are the active window before |
176 | /// responding to this message ? | |
0145e89a | 177 | |
178 | AliDebug(1,Form("group=%x %s",group,group->GetName())); | |
179 | ||
180 | Int_t i = AliMUONPainterRegistry::Instance()->FindIndexOf(group); | |
181 | ||
182 | Int_t alreadyThere(-1); | |
183 | ||
184 | for ( Int_t j = 0; j < fNavigation.GetSize(); ++j ) | |
185 | { | |
186 | if ( fNavigation[j] == i ) alreadyThere = j; | |
187 | } | |
188 | ||
189 | if (alreadyThere<0) | |
190 | { | |
191 | SetNavigation(i); | |
192 | } | |
193 | else | |
194 | { | |
195 | fCurrentNavigationPosition = alreadyThere; | |
196 | } | |
197 | ||
198 | ShowPainterMatrix(group); | |
199 | } | |
200 | ||
201 | //_____________________________________________________________________________ | |
202 | void | |
203 | AliMUONPainterMasterFrame::SetNavigation(Int_t i) | |
204 | { | |
205 | /// Change navigation position | |
206 | ||
207 | ++fCurrentNavigationPosition; | |
208 | fNavigation.Set(fCurrentNavigationPosition+1); | |
209 | fNavigation[fCurrentNavigationPosition] = i; | |
210 | } | |
211 | ||
212 | //_____________________________________________________________________________ | |
213 | void | |
214 | AliMUONPainterMasterFrame::ShowPainterMatrix(AliMUONPainterMatrix* painterMatrix) | |
215 | { | |
216 | /// Change the painter matrix we show | |
217 | ||
218 | fPainterMatrixFrame->Use(painterMatrix); | |
219 | ||
220 | painterMatrix->Connect("Clicked(AliMUONVPainter*,Double_t*)", | |
221 | "AliMUONPainterMasterFrame",this, | |
222 | "Clicked(AliMUONVPainter*,Double_t*)"); | |
223 | ||
224 | painterMatrix->Connect("ShiftClicked(AliMUONVPainter*,Double_t*)", | |
225 | "AliMUONPainterMasterFrame",this, | |
226 | "ShiftClicked(AliMUONVPainter*,Double_t*)"); | |
227 | ||
228 | fPainterMatrixFrame->Connect("TitleHasChanged(const char*)", | |
229 | "AliMUONPainterMasterFrame",this, | |
230 | "ChangeTitle(const char*)"); | |
231 | UpdateNavigation(); | |
232 | ||
233 | UpdateAttributes(*(fPainterMatrixFrame->Matrix())); | |
234 | ||
235 | AliMUONPainterRegistry::Instance()->AddToHistory(painterMatrix); | |
236 | ||
237 | Layout(); | |
238 | } | |
239 | ||
240 | //_____________________________________________________________________________ | |
241 | void | |
242 | AliMUONPainterMasterFrame::ChangeTitle(const char* newTitle) | |
243 | { | |
244 | /// Change the top title | |
245 | ||
246 | fGroupTitle->SetText(newTitle); | |
247 | fGroupTitle->Resize(); | |
248 | Layout(); | |
249 | } | |
250 | ||
251 | //_____________________________________________________________________________ | |
252 | void | |
253 | AliMUONPainterMasterFrame::Backward() | |
254 | { | |
255 | /// Move back one step in the history | |
256 | --fCurrentNavigationPosition; | |
257 | ||
258 | AliMUONPainterMatrix* group = | |
259 | AliMUONPainterRegistry::Instance()->PainterMatrix(fNavigation[fCurrentNavigationPosition]); | |
260 | ||
261 | ShowPainterMatrix(group); | |
262 | ||
263 | UpdateNavigation(); | |
264 | } | |
265 | ||
266 | //_____________________________________________________________________________ | |
267 | void | |
268 | AliMUONPainterMasterFrame::Forward() | |
269 | { | |
270 | /// Move forward one step in history | |
271 | ||
272 | ++fCurrentNavigationPosition; | |
273 | ||
274 | AliMUONPainterMatrix* group = | |
275 | AliMUONPainterRegistry::Instance()->PainterMatrix(fNavigation[fCurrentNavigationPosition]); | |
276 | ||
277 | ShowPainterMatrix(group); | |
278 | ||
279 | UpdateNavigation(); | |
280 | } | |
281 | ||
282 | //_____________________________________________________________________________ | |
283 | void | |
284 | AliMUONPainterMasterFrame::Clicked(AliMUONVPainter* painter, Double_t* values) | |
285 | { | |
286 | /// A given painter was (singly) clicked | |
0145e89a | 287 | |
49419555 | 288 | if ( painter->CanBeDetached() ) |
289 | { | |
290 | fPainterMatrixFrame->MouseLeave(painter); | |
0145e89a | 291 | |
49419555 | 292 | AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix(painter->Name().Data()); |
0145e89a | 293 | |
49419555 | 294 | AliMUONVPainter* p = painter->Detach(); |
0145e89a | 295 | |
49419555 | 296 | p->SetResponder(1); |
0145e89a | 297 | |
49419555 | 298 | matrix->Adopt(p); |
0145e89a | 299 | |
49419555 | 300 | AddPainterMatrix(matrix); |
301 | ShowPainterMatrix(matrix); | |
302 | } | |
303 | else | |
304 | { | |
305 | painter->DrawHistogram(values); | |
306 | } | |
0145e89a | 307 | } |
308 | ||
309 | //_____________________________________________________________________________ | |
310 | void | |
311 | AliMUONPainterMasterFrame::ShiftClicked(AliMUONVPainter* painter, Double_t*) | |
312 | { | |
313 | /// A given painter was shift-clicked | |
314 | ||
49419555 | 315 | if ( !painter->CanBeDetached() ) return; |
316 | ||
0145e89a | 317 | AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix(); |
318 | ||
319 | AliMUONAttPainter a = painter->Attributes(); | |
320 | ||
321 | TString basename(Form("%s-DUAL",painter->GetName())); | |
322 | ||
323 | TString newName = AliMUONPainterMatrix::NameIt(basename.Data(),a); | |
324 | ||
49419555 | 325 | AliMUONPainterMatrix* matrix = AliMUONPainterRegistry::Instance()->PainterMatrix(newName.Data()); |
0145e89a | 326 | |
327 | if (!matrix) | |
328 | { | |
329 | // No. So we must make a new matrix painter from the existing one, | |
330 | // and add to this new matrix the painters of the other one, but | |
331 | // using the new attributes... | |
332 | ||
333 | // create "opposite" attributes | |
334 | AliMUONAttPainter a1(a); | |
335 | AliMUONAttPainter a2(a); | |
336 | ||
337 | if ( a.IsCathodeDefined() ) | |
338 | { | |
339 | a2.SetCathode(!a.IsCathode0(),!a.IsCathode1()); | |
340 | } | |
341 | ||
342 | if ( a.IsPlaneDefined() ) | |
343 | { | |
344 | a2.SetPlane(!a.IsBendingPlane(),!a.IsNonBendingPlane()); | |
345 | } | |
346 | ||
347 | a1.SetCathodeAndPlaneDisabled(kTRUE); | |
348 | a2.SetCathodeAndPlaneDisabled(kTRUE); | |
49419555 | 349 | |
0145e89a | 350 | AliMUONVPainter* p1 = AliMUONVPainter::CreatePainter(painter->ClassName(), |
351 | a1, | |
352 | painter->ID0(), | |
353 | painter->ID1()); | |
354 | ||
355 | AliMUONVPainter* p2 = AliMUONVPainter::CreatePainter(painter->ClassName(), | |
49419555 | 356 | a2, |
357 | painter->ID0(), | |
358 | painter->ID1()); | |
0145e89a | 359 | |
360 | if (!p1 || !p2) | |
361 | { | |
362 | Int_t ret; | |
363 | new TGMsgBox(gClient->GetRoot(), this, | |
364 | "Invalid combination", "Cannot create 2 views from this painter", | |
365 | kMBIconExclamation, kMBOk, &ret); | |
366 | PainterMatrixWantToShow(currentMatrix); | |
367 | delete p1; | |
368 | delete p2; | |
369 | return; | |
370 | } | |
371 | ||
0145e89a | 372 | p1->UpdateGroupsFrom(*(painter->Master())); |
373 | p2->UpdateGroupsFrom(*(painter->Master())); | |
374 | ||
375 | p1->SetResponder(1); | |
376 | p2->SetResponder(1); | |
377 | ||
378 | Int_t nx(2); | |
379 | Int_t ny(1); | |
380 | ||
381 | AliMpArea area(painter->Area()); | |
49419555 | 382 | |
0145e89a | 383 | if ( area.Dimensions().X() > 1.2*area.Dimensions().Y() ) |
384 | { | |
385 | nx = 1; | |
386 | ny = 2; | |
387 | } | |
388 | ||
389 | matrix = new AliMUONPainterMatrix(basename.Data(),nx,ny); | |
390 | ||
391 | matrix->Adopt(p1); | |
392 | matrix->Adopt(p2); | |
393 | ||
394 | AddPainterMatrix(matrix); | |
395 | } | |
396 | ||
397 | matrix->SetData(currentMatrix->DataPattern(), | |
398 | currentMatrix->Data(), | |
399 | currentMatrix->DataIndex()); | |
400 | ||
401 | fPainterMatrixFrame->MouseLeave(painter); | |
402 | ||
403 | PainterMatrixWantToShow(matrix); | |
404 | } | |
405 | ||
10eb3d17 | 406 | //_____________________________________________________________________________ |
407 | void | |
408 | AliMUONPainterMasterFrame::SaveAs(const char* filename, Option_t* option) const | |
409 | { | |
410 | /// Save painter matrix (in the sense of "print") in filename | |
411 | fPainterMatrixFrame->SaveAs(filename,option); | |
412 | } | |
413 | ||
0145e89a | 414 | //_____________________________________________________________________________ |
415 | void | |
416 | AliMUONPainterMasterFrame::Update() | |
417 | { | |
418 | /// Update ourselves | |
419 | ||
420 | fPainterMatrixFrame->Update(); | |
421 | } | |
422 | ||
423 | //_____________________________________________________________________________ | |
424 | void | |
425 | AliMUONPainterMasterFrame::UpdateAttributes(const AliMUONPainterMatrix& painterMatrix) | |
426 | { | |
427 | /// Update the view buttons from the matrix we actually plot | |
428 | ||
429 | fAttPainterSelectorFrame->Update(painterMatrix.Attributes()); | |
430 | } | |
431 | ||
432 | //_____________________________________________________________________________ | |
433 | void | |
434 | AliMUONPainterMasterFrame::MakeTopPainterMatrix(UInt_t w, UInt_t h) | |
435 | { | |
436 | /// Create the first painter matrix that appears when we are create | |
437 | /// FIXME: how to make this more flexible ? | |
438 | ||
439 | fPainterMatrixFrame = new AliMUONPainterMatrixFrame(this,w,h); | |
440 | ||
441 | AliMUONAttPainter att; | |
442 | ||
49419555 | 443 | att.SetPlane(kTRUE,kFALSE); |
444 | // att.SetCathode(kTRUE,kFALSE); | |
0145e89a | 445 | att.SetViewPoint(kTRUE,kFALSE); |
446 | ||
447 | TString name = AliMUONPainterMatrix::NameIt("Tracker",att); | |
448 | ||
49419555 | 449 | AliMUONPainterMatrix* painterMatrix = AliMUONPainterRegistry::Instance()->PainterMatrix(name); |
0145e89a | 450 | |
451 | if (!painterMatrix) | |
452 | { | |
453 | AliError(Form("Could not get pre-defined painter matrix %s : check that !",name.Data())); | |
454 | } | |
455 | else | |
456 | { | |
457 | PainterMatrixWantToShow(painterMatrix); | |
458 | // fPainterMatrixFrame->Use(painterMatrix); | |
459 | // ShowPainterMatrix(painterMatrix); | |
460 | } | |
461 | } | |
462 | ||
463 | //_____________________________________________________________________________ | |
464 | void | |
465 | AliMUONPainterMasterFrame::UpdateNavigation() | |
466 | { | |
467 | /// Update navigation frame | |
468 | ||
469 | fBackButton->SetEnabled(kTRUE); | |
470 | fForwardButton->SetEnabled(kTRUE); | |
471 | ||
472 | if ( fCurrentNavigationPosition == 0 ) | |
473 | { | |
474 | fBackButton->SetEnabled(kFALSE); | |
475 | } | |
476 | if ( fCurrentNavigationPosition == fNavigation.GetSize()-1 ) | |
477 | { | |
478 | fForwardButton->SetEnabled(kFALSE); | |
479 | } | |
480 | } | |
481 | ||
482 | //_____________________________________________________________________________ | |
483 | void | |
484 | AliMUONPainterMasterFrame::AttributesChanged(AliMUONAttPainter* newValues) | |
485 | { | |
486 | /// Attributes changed (e.g. from cath0 to cath1 or bending to nonbending, etc...) | |
487 | ||
488 | AliMUONPainterMatrix* currentMatrix = fPainterMatrixFrame->Matrix(); | |
489 | ||
490 | AliMUONAttPainter a = currentMatrix->Validate(*newValues); | |
491 | ||
492 | if (!a.IsValid()) | |
493 | { | |
494 | Int_t ret; | |
495 | new TGMsgBox(gClient->GetRoot(), this, | |
496 | "Invalid combination", "Change of attributes not possible for this object", | |
497 | kMBIconExclamation, kMBOk, &ret); | |
498 | PainterMatrixWantToShow(currentMatrix); | |
499 | return; | |
500 | } | |
501 | ||
502 | // First check if we already have this matrix available | |
503 | ||
504 | TString newName = AliMUONPainterMatrix::NameIt(currentMatrix->Basename(),a); | |
505 | ||
49419555 | 506 | AliMUONPainterMatrix* matrix = AliMUONPainterRegistry::Instance()->PainterMatrix(newName.Data()); |
0145e89a | 507 | |
508 | if (!matrix) | |
509 | { | |
510 | // No. So we must make a new matrix painter from the existing one, | |
511 | // and add to this new matrix the painters of the other one, but | |
512 | // using the new attributes... | |
513 | ||
514 | matrix = currentMatrix->Clone(a); | |
515 | ||
516 | AddPainterMatrix(matrix); | |
517 | } | |
518 | ||
519 | matrix->SetData(currentMatrix->DataPattern(), | |
520 | currentMatrix->Data(), | |
521 | currentMatrix->DataIndex()); | |
522 | ||
523 | PainterMatrixWantToShow(matrix); | |
524 | } |