]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDEVisu.cxx
- Using TCanvas instead of TGTransientFrame
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDEVisu.cxx
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 // $MpId$
18
19 #include "AliMpDEVisu.h"
20
21 #include "AliMpSlatMotifMap.h"
22 #include "AliMpSt345Reader.h"
23 #include "AliMpSectorReader.h"
24 #include "AliMpSlat.h"
25 #include "AliMpPCB.h"
26 #include "AliMpSectorReader.h"
27 #include "AliMpSector.h"
28 #include "AliMpRow.h"
29 #include "AliMpVRowSegment.h"
30 #include "AliMpVPainter.h"
31 #include "AliMpMotifPosition.h"
32 #include "AliMpMotifMap.h"
33 #include "AliMpDEIterator.h"
34 #include "AliMpDEManager.h"
35 #include "AliMpDetElement.h"
36 #include "AliMpStationType.h"
37 #include "AliMpSegmentation.h"
38 #include "AliMpPad.h"
39 #include "AliMpDDLStore.h"
40 #include "AliMpVPadIterator.h"
41
42 #include "AliLog.h"
43
44 #include <TMath.h>
45 #include <TString.h>
46 #include <TVector2.h>
47 #include <TCanvas.h>
48 #include <TGButton.h>
49 #include <TRootEmbeddedCanvas.h>
50 #include <TGLabel.h>
51 #include <TGComboBox.h>
52 #include <TGNumberEntry.h>
53 #include <TGTextView.h>
54 #include <TGTextEntry.h>
55
56 // Category: graphics
57 //
58 // Class AliMpDEVisu
59 // -----------------------
60 // GUI for drawing segmentation
61 // motif manu and associated channels
62 // date: 2007/01/26
63 // Author: Ch. Finck
64
65 /// \cond CLASSIMP
66 ClassImp(AliMpDEVisu)
67 /// \endcond
68
69 //_________________________________________________________________
70 AliMpDEVisu::AliMpDEVisu(UInt_t w, UInt_t h) 
71 : TGFrame(gClient->GetRoot(), w, h),
72   fkMainWindow(gClient->GetRoot()),
73   fMain(new TGMainFrame(gClient->GetRoot(), w, h)),
74   fEcanvas(0x0),
75   fChamberCombo(0x0),
76   fDECombo(0x0),
77   fNumberEntry(0x0),
78   fPlaneButton(0x0),
79   fZoomButton(0x0),
80   fNameDEView(0x0),
81   fLogMessage(0x0),
82   fLogFile(0x0),
83   fTrashList(0x0),
84   fDEComboIdx(),
85   fCurrentPlane(AliMp::kBendingPlane),
86   fCurrentDetElem(100),
87   fCurrentDEName(),
88   fSegmentation(),
89   fDDLStore(AliMpDDLStore::Instance()),
90   fZoomMode(false)
91 {
92 /// Standard constructor
93
94   fTrashList.SetOwner(kFALSE);
95   
96   // Create canvas widget
97   
98   Int_t width  = Int_t(w*0.99);
99   Int_t height = Int_t(h*0.99);
100   
101   fEcanvas = new TRootEmbeddedCanvas("Ecanvas",fMain, width, height);
102   fEcanvas->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
103                                  "AliMpDEVisu",
104                                  this,
105                                  "HandleMovement(Int_t, Int_t, Int_t, TObject*)");
106
107   // Create a horizontal frame widget with buttons
108   TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain,width,height/6);
109   
110   TGTextButton *draw = new TGTextButton(hframe,"&Draw");
111   draw->Connect("Clicked()","AliMpDEVisu",this,"DrawDE()");
112   hframe->AddFrame(draw, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,15,5,3,4));
113   
114   TGTextButton *exit = new TGTextButton(hframe,"&Exit","gApplication->Terminate(0)");
115   hframe->AddFrame(exit, new TGLayoutHints(kLHintsLeft| kLHintsCenterY,5,5,3,4));
116   
117   
118   Int_t i = 0;
119   Char_t text[20];
120   
121   // chamber label
122   TGLabel* chamberLabel = new TGLabel(hframe, "Chamber :");
123   hframe->AddFrame(chamberLabel, new TGLayoutHints(kLHintsCenterX | kLHintsLeft | kLHintsCenterY, 10, 0, 20, 0));
124   fChamberCombo = new TGComboBox(hframe, kChamberCombo);
125   
126   fDEComboIdx.Set(26);
127   for(i = 0; i < 10; i++)
128   {
129     sprintf(text,"%d",i+1);
130     fChamberCombo->AddEntry(text,i);
131   }
132   fChamberCombo->Resize(40,20);
133   fChamberCombo->Select(0);
134   fChamberCombo->Associate(this);
135   hframe->AddFrame(fChamberCombo, new TGLayoutHints(kLHintsLeft, 10, 0, 9, 0));
136   
137   // DE label
138   TGLabel*  detElemLabel = new TGLabel(hframe, "DE :");
139   hframe->AddFrame(detElemLabel, new TGLayoutHints(kLHintsCenterX | kLHintsLeft | kLHintsCenterY, 10, 0, 20, 0));
140   fDECombo = new TGComboBox(hframe, kDECombo);
141   UpdateComboDE();
142   
143   fDECombo->Resize(80,20);
144   fDECombo->Select(0);
145   fDECombo->Associate(this);
146   hframe->AddFrame(fDECombo, new TGLayoutHints(kLHintsLeft, 10, 0, 9, 0));
147   
148   TGTextButton *next = new TGTextButton(hframe,"&Next");
149   next->Connect("Clicked()","AliMpDEVisu",this,"NextDE()");
150   hframe->AddFrame(next, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,5,5,3,4));
151   
152   // DE name
153   TGLabel*  detElemName = new TGLabel(hframe, "Name :");
154   hframe->AddFrame(detElemName, new TGLayoutHints(kLHintsCenterX | kLHintsLeft | kLHintsCenterY, 10, 0, 20, 0));
155   
156   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
157   fCurrentDEName = detElem->GetDEName();
158   fNameDEView = new TGTextView(hframe, 180, 25, fCurrentDEName.Data(), kDEName);
159   hframe->AddFrame(fNameDEView, new TGLayoutHints(kLHintsLeft, 10, 0, 9, 0));
160
161   // plane type
162   fPlaneButton = new TGCheckButton(hframe, "NB Plane", kPlaneType);
163   fPlaneButton->SetState(kButtonUp);
164   fPlaneButton->Associate(this);
165   hframe->AddFrame(fPlaneButton, new TGLayoutHints(kLHintsLeft, 10, 0, 9, 0));
166   
167   
168   // button motif
169   TGTextButton* drawManu = new TGTextButton(hframe,"&Search");
170   drawManu->Connect("Clicked()","AliMpDEVisu",this,"DrawManuMotif(Bool_t)");
171   drawManu->SetToolTipText("Search for a given manu number");
172   hframe->AddFrame(drawManu, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,15,5,3,4));
173   
174   // entry manu
175   fNumberEntry  = new TGNumberEntry(hframe, 0, 4, -1, 
176                                     TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative,
177                                     TGNumberFormat::kNELLimitMinMax, 1, 1500);
178   fNumberEntry->Resize(60,20);
179   hframe->AddFrame(fNumberEntry, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 0, 9, 0));
180   
181   // reset button
182   TGTextButton *resetManu = new TGTextButton(hframe,"&Reset");
183   resetManu->Connect("Clicked()","AliMpDEVisu",this,"ResetManu()");
184   hframe->AddFrame(resetManu, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,10,5,3,4));
185   
186   // delete window button
187   TGTextButton* deletePopup = new TGTextButton(hframe,"&Delete_Popup");
188   deletePopup->Connect("Clicked()","AliMpDEVisu",this,"DeletePopUp()");
189   deletePopup->SetToolTipText("Delete motif popup window");
190   hframe->AddFrame(deletePopup, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,15,5,3,4));
191   
192   
193   // log mesg
194   TGHorizontalFrame *logFrame = new TGHorizontalFrame(fMain, width/2, height/6);
195   
196   TGLabel*  logName = new TGLabel(logFrame, "Log MSG:");
197   logFrame->AddFrame(logName, new TGLayoutHints(kLHintsCenterX | kLHintsLeft | kLHintsCenterY, 10, 0, 2, 0));
198   
199   fLogMessage = new TGTextView(logFrame, width/2, 60);
200   fLogMessage->ShowBottom();
201   
202   logFrame->AddFrame(fLogMessage, new TGLayoutHints(kLHintsLeft, 10, 0, 2, 0));
203   
204   // clear log mesg
205   TGTextButton* clearLog = new TGTextButton(logFrame,"&Clear");
206   clearLog->Connect("Clicked()","AliMpDEVisu",this,"ClearLogMessage()");
207   clearLog->SetToolTipText("Clear log message");
208   logFrame->AddFrame(clearLog, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,15,5,3,4));
209   
210   // save log mesg
211   TGTextButton* saveLog = new TGTextButton(logFrame,"&Save");
212   saveLog->Connect("Clicked()","AliMpDEVisu",this,"SaveLogMessage()");
213   saveLog->SetToolTipText("Save log message into file");
214   logFrame->AddFrame(saveLog, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,5,5,3,4));
215   
216   // log file name
217   fLogFile = new TGTextEntry(logFrame,"AliMpDEVisu.log");
218   fLogFile->SetToolTipText("Default log file name");
219   logFrame->AddFrame(fLogFile, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 0, 9, 0));
220   
221   // zoom mode
222   fZoomButton = new TGCheckButton(logFrame, new TGHotString("&Zoom Mode"), kZoomMode);
223   fZoomButton->Associate(this);
224   fZoomButton->SetState(kButtonUp);
225
226   logFrame->AddFrame(fZoomButton, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 20, 0, 9, 0));
227   
228   // frame
229   fMain->AddFrame(hframe, new TGLayoutHints(kLHintsLeft | kLHintsCenterY,2,2,10,10));
230   fMain->AddFrame(fEcanvas, new TGLayoutHints(kLHintsCenterX,   10,10,10,10));
231   
232   fMain->AddFrame(logFrame, new TGLayoutHints(kLHintsLeft,2,2,2,10));
233   
234   // Set a name to the main frame
235   fMain->SetWindowName("MUON Detection Element Visualization");
236   
237   // Map all subwindows of main frame
238   fMain->MapSubwindows();
239   
240   // Initialize the layout algorithm
241   fMain->Resize(fMain->GetDefaultSize());
242   
243   // Map main frame
244   fMain->MapWindow();
245   
246   // instance segmentation
247   fSegmentation = AliMpSegmentation::Instance()->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
248   fLogMessage->AddLine("Segmentation loaded");
249   fLogMessage->ShowBottom();
250 }
251
252 //____________________________________________________________
253 AliMpDEVisu::~AliMpDEVisu() 
254 {
255   /// Clean up used widgets: frames, buttons, layouthints
256   
257   fChamberCombo->Delete();
258   fDECombo->Delete();
259   fNumberEntry->Delete();
260   fPlaneButton->Delete();
261   fNameDEView->Delete();
262   fLogMessage->Delete();
263   fLogFile->Delete();
264   fMain->Cleanup();
265   delete fMain;
266 }
267
268 //__________________________________________________________
269 void AliMpDEVisu::HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject* /*select*/)
270 {
271   /// handle cursor mouvement
272   
273   static Int_t eventXold, eventYold;
274   static Int_t eventX0, eventY0;
275   static Int_t linedrawn;
276   
277
278   // enable again  KeyAutoRepeat after HandleKey
279   if (eventType == kKeyPress) {
280     gVirtualX->SetKeyAutoRepeat(kTRUE);
281   }
282
283   fEcanvas->GetCanvas()->cd();
284
285   // zoom mode
286   if (fZoomMode) {
287     
288     if (eventType == kButton1Down) {
289       gVirtualX->SetLineWidth(3);
290       eventX0   = eventX; eventY0   = eventY;
291       eventXold = eventX; eventYold = eventY;
292       linedrawn = 0;
293     }
294     
295     if (eventType == kButton1Motion) {
296       if (linedrawn) gVirtualX->DrawBox(eventX0, eventY0, eventXold, eventYold, TVirtualX::kHollow);
297       eventXold = eventX;
298       eventYold = eventY;
299       linedrawn = 1;
300       gVirtualX->DrawBox(eventX0, eventY0, eventXold, eventYold,  TVirtualX::kHollow);
301     }
302     
303     if (eventType == kButton1Up)
304     {
305       if ( (eventX0 - eventX) && (eventY0 - eventY) ) 
306       {
307         PopUpZoom(eventX0,eventY0,eventX,eventY);
308         linedrawn=1;
309       }
310     }
311     
312     
313   } else {
314     
315     // click mode
316     
317     if (eventType == kButton1Down) {
318       
319       // calculated in pixel 
320       Double_t x = 0.;
321       Double_t y = 0.;
322       
323       EventToReal(eventX,eventY,x,y);
324       
325       // get manu
326       AliMpPad pad = fSegmentation->PadByPosition(TVector2(x,y), false);
327       
328       if (!pad.IsValid()) {
329        
330         fLogMessage->AddLine(Form("PopupManuMotif: No manu for DE: %d at position (%5.2f, %5.2f)",
331                               fCurrentDetElem, x, y));
332         fLogMessage->ShowBottom();
333         return;
334       }
335       
336       Int_t manu = pad.GetLocation().GetFirst();
337       
338       fNumberEntry->SetNumber(manu);
339       
340      
341       fLogMessage->AddLine(Form("PopupManuMotif: DE: %d, manu: %d at position: %5.2f, %5.2f", 
342                                 fCurrentDetElem, manu, x, y));
343       fLogMessage->ShowBottom();
344       
345       DrawManuMotif(true);
346       
347     }
348   }
349 }
350
351 //__________________________________________________________
352 void AliMpDEVisu::DrawDE(Bool_t info) 
353 {
354   /// Draws function graphics in randomly choosen interval
355   
356   if (info)
357     InfoDE();
358   
359   fEcanvas->GetCanvas()->cd();
360   fEcanvas->GetCanvas()->SetEditable(kTRUE);
361   
362   if (AliMpDEManager::GetStationType(fCurrentDetElem) == AliMp::kStation345 ) {
363     
364     DrawSlat("PMCI");
365     
366   } else {
367     
368     DrawQuadrant("RSMCI");
369     
370   }
371   DeletePopUp();
372   fEcanvas->GetCanvas()->SetEditable(kFALSE);
373   
374 }
375
376 //__________________________________________________________
377 void AliMpDEVisu::DrawManuMotif(Bool_t popup) 
378 {
379   //  Draw manu motif in yellow and popup channel motif window
380   
381   fEcanvas->GetCanvas()->SetEditable(kTRUE);
382   
383   if (!fNumberEntry->GetIntNumber()) return;
384   
385   Char_t command[255];
386   
387   if (AliMpDEManager::GetStationType(fCurrentDetElem) == AliMp::kStation345 ) {
388     
389     sprintf(command, "%s%d", "PMCI:", (Int_t)fNumberEntry->GetIntNumber());
390     
391     DrawSlat(command, popup);
392     
393   } else {   
394     
395     sprintf(command, "%s%d", "RSMCI:", (Int_t)fNumberEntry->GetIntNumber());
396     
397     DrawQuadrant(command, popup);
398     
399   }
400   
401   fEcanvas->GetCanvas()->SetEditable(kFALSE);
402 }
403
404 //__________________________________________________________
405 void AliMpDEVisu::DrawSlat(Option_t* option, Bool_t popup) 
406 {
407   /// draw slat segmentation
408   
409   TCanvas *canvas = fEcanvas->GetCanvas();
410   canvas->Clear();
411   
412   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
413   TString nameType =  detElem->GetSegType();
414   
415   AliMpSlatMotifMap mm;
416   AliMpSt345Reader reader(mm);  
417   AliMpSlat* slatCurrent = reader.ReadSlat(nameType.Data(), fCurrentPlane);
418   AliMpSlat* slatOther   = reader.ReadSlat(nameType.Data(), AliMp::OtherPlaneType(fCurrentPlane));
419   
420   AliMpVPainter* painter = AliMpVPainter::CreatePainter(slatCurrent);
421   painter->Draw(option);
422   
423   canvas->Update();
424   
425   Int_t numberOfManu = 
426       slatCurrent->GetNofElectronicCards() + 
427       slatOther->GetNofElectronicCards();
428     
429   fLogMessage->AddLine(Form("DrawSlat: number of manus: %d", numberOfManu));
430   fLogMessage->ShowBottom();   
431   
432   if (popup)
433     PopUpManuMotif(slatCurrent);
434   
435 }
436
437 //__________________________________________________________
438 void AliMpDEVisu::DrawQuadrant(Option_t* option, Bool_t popup)
439 {
440   /// draw quadrant segmentation
441   
442   TCanvas *canvas = fEcanvas->GetCanvas();
443   canvas->Clear();
444   
445   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
446   AliMp::StationType  station = detElem->GetStationType();
447
448   AliMpSectorReader readerCurrent(station, fCurrentPlane);
449   AliMpSector* sectorCurrent = readerCurrent.BuildSector();
450     
451   AliMpSectorReader readerOther(station, AliMp::OtherPlaneType(fCurrentPlane));
452   AliMpSector* sectorOther = readerOther.BuildSector();
453   
454   AliMpVPainter *painter = AliMpVPainter::CreatePainter(sectorCurrent);
455   painter->Draw(option);
456   
457   canvas->Update();
458   
459   Int_t numberOfManu =  
460       sectorCurrent->GetMotifMap()->GetNofMotifPositions() + 
461       sectorOther->GetMotifMap()->GetNofMotifPositions();
462   
463   fLogMessage->AddLine(Form("DrawQuadrant: number of manus: %d", numberOfManu));
464   fLogMessage->ShowBottom();   
465
466   if (popup) 
467     PopUpManuMotif(sectorCurrent);
468  
469 }
470
471 //______________________________________________________________________________
472 void 
473 AliMpDEVisu::EventToReal(Int_t eventX, Int_t eventY, Double_t& x, Double_t& y) const
474 {
475   /// estimate graphic pad sizes
476
477   static TVector2 ul(gPad->XtoPixel(0.01), gPad->YtoPixel(0.99));
478   static TVector2 br(gPad->XtoPixel(0.99), gPad->YtoPixel(0.01));
479
480   static TVector2 padDim = br - ul;
481   
482   // get DE dimension (half size)
483   TVector2 deDim(fSegmentation->Dimensions()*2.0);
484   
485   TVector2 padReal;
486   
487   if (AliMpDEManager::GetStationType(fCurrentDetElem) == AliMp::kStation345 )
488   {
489     // origin at center
490     x = (eventX - ul.X() - padDim.X()/2.)/(padDim.X())*deDim.X(); 
491     y = (br.Y() - eventY - padDim.Y()/2.)/(padDim.Y())*deDim.Y(); 
492     
493   } 
494   else 
495   {
496     // origin at bottom left
497     x = (eventX - ul.X())/(padDim.X())*deDim.X(); 
498     y = (br.Y() - eventY)/(padDim.Y())*deDim.Y(); 
499   }
500   
501 }
502
503 //__________________________________________________________
504 void AliMpDEVisu::ResetManu() 
505 {
506   /// reset manu search entry 
507   fLogMessage->AddLine("Reset Motif Search Entry:");
508   fLogMessage->ShowBottom();
509   fNumberEntry->SetNumber(0);
510   
511 }
512
513 //__________________________________________________________
514 void AliMpDEVisu::DeletePopUp() 
515 {
516 /// delete motif popup windows 
517   
518   if (fTrashList.GetEntries() > 0) 
519   {
520     fLogMessage->AddLine("Delete Motif PopUp Windows:");
521     fLogMessage->ShowBottom();
522     
523     fTrashList.Delete();
524   } 
525 }
526
527 //__________________________________________________________
528 void AliMpDEVisu::SaveLogMessage() 
529 {
530   /// save log message into log file
531   
532   TString logFile = fLogFile->GetDisplayText();
533   fLogMessage->GetText()->Save(logFile.Data());
534
535   fLogMessage->AddLine(Form("SaveLogMessage: saving log message into logfile: %s", logFile.Data()));
536   fLogMessage->ShowBottom();  
537 }
538
539 //__________________________________________________________
540 void AliMpDEVisu::ClearLogMessage() 
541 {
542   /// clear log message 
543   fLogMessage->GetText()->Clear();
544   fLogMessage->AddLine("ClearLogMessage: clear log messages:");
545   fLogMessage->ShowBottom();  
546 }
547
548 //__________________________________________________________
549 void AliMpDEVisu::InfoDE() 
550 {
551   /// info concerning the whole DE
552   
553   AliMpDetElement* detElem = fDDLStore->GetDetElement(fCurrentDetElem);
554   Int_t ddlId        = detElem->GetDdlId();
555   Int_t numberOfBus  = detElem->GetNofBusPatches();
556   
557   Int_t vec[24];
558   for (Int_t i = 0; i <  detElem->GetNofBusPatches(); ++i)
559       vec[i] = detElem->GetBusPatchId(i);
560
561   Int_t firstBus     = TMath::MinElement(detElem->GetNofBusPatches(), vec);
562   Int_t lastBus      = TMath::MaxElement(detElem->GetNofBusPatches(), vec);
563   
564   detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
565   Int_t numberOfSerialManu = detElem->GetNofManus(); // number of manu with an identified serial number
566   
567   fLogMessage->AddLine(Form("DrawDE: detection element: %d, name: %s", 
568                        fCurrentDetElem, fCurrentDEName.Data()));
569   fLogMessage->ShowBottom();   
570   
571   fLogMessage->AddLine(Form("DrawDE: DDL: %d, number of buspatches %d from %d to %d", 
572                             ddlId, numberOfBus, firstBus, lastBus));
573   fLogMessage->ShowBottom();
574   
575   if (numberOfSerialManu != 0) { // not available yet for all DE 
576     fLogMessage->AddLine(Form("DrawDE: number of manus with serial number: %d", numberOfSerialManu));
577     fLogMessage->ShowBottom();
578   }
579   
580 }
581
582 //__________________________________________________________
583 Bool_t AliMpDEVisu::ProcessMessage(Long_t msg, Long_t parm1, Long_t /*parm2*/)
584 {
585   /// process message from widgets actions/entries
586
587   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
588
589   switch(GET_MSG(msg)) 
590   {
591     case kC_COMMAND: 
592       switch (GET_SUBMSG(msg)) 
593       {
594         case kCM_COMBOBOX: 
595           
596           switch (parm1) 
597           {
598             case kChamberCombo: 
599               UpdateComboDE();
600               UpdateNameView();
601               break;
602               
603             case kDECombo:
604               UpdateNameView();
605               break; 
606           }
607           break;
608           
609         case kCM_CHECKBUTTON:
610           switch (parm1) 
611           {
612             case kPlaneType:
613               if (fPlaneButton->GetState() == kButtonDown) {
614                 fCurrentPlane = AliMp::kNonBendingPlane;
615                 if (fNumberEntry->GetIntNumber() && fNumberEntry->GetIntNumber() <= 1024)
616                   fNumberEntry->SetNumber(fNumberEntry->GetIntNumber() + 1024);
617               } else {
618                 fCurrentPlane = AliMp::kBendingPlane;
619                 if (fNumberEntry->GetIntNumber() && fNumberEntry->GetIntNumber() > 1024)
620                   fNumberEntry->SetNumber(fNumberEntry->GetIntNumber() - 1024);
621               }
622               DrawDE();
623               fSegmentation = AliMpSegmentation::Instance()
624                 ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
625               break;
626
627             case kZoomMode:
628                 if (fZoomButton->GetState() == kButtonDown)
629                     fZoomMode = true;
630                 else
631                     fZoomMode = false;
632               break;
633           }
634           break;
635           
636       }
637       break;
638   }
639   return true;
640 }
641
642 //__________________________________________________________
643 void AliMpDEVisu::NextDE()
644 {
645   /// select next DE
646   
647   Int_t next = fDECombo->GetSelected() + 1;
648   
649   if (next < fDECombo->GetNumberOfEntries())
650     fDECombo->Select(next);
651   else 
652     fDECombo->Select(0);
653   
654   UpdateNameView();
655   DrawDE();
656 }
657
658 //__________________________________________________________
659 void AliMpDEVisu::UpdateComboDE()
660 {
661   /// update DE in respect to selected chamber
662   
663   fDECombo->RemoveAll();
664   
665   AliMpDEIterator it;
666   Int_t i = 0;
667   fDEComboIdx.Reset();
668   Char_t text[20];
669   
670   for ( it.First(fChamberCombo->GetSelected()); ! it.IsDone(); it.Next() ) {
671     sprintf(text,"%d",it.CurrentDE()->GetId());
672     fDECombo->AddEntry(text,i);
673     fDEComboIdx[i++] = it.CurrentDE()->GetId();
674   }
675   fDECombo->Select(0);
676 }
677
678 //__________________________________________________________
679 void AliMpDEVisu::UpdateNameView()
680 {
681   /// update DE name in respect to selected DE id.
682   
683   fNameDEView->Clear();
684   
685   fCurrentDetElem = fDEComboIdx[fDECombo->GetSelected()];
686   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
687   fCurrentDEName = detElem->GetDEName();
688   
689   fNameDEView->AddLine(fCurrentDEName.Data());
690   fNameDEView->ShowBottom();
691
692   fSegmentation = AliMpSegmentation::Instance()
693     ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
694 }
695
696 //______________________________________________________________________________
697 void
698 AliMpDEVisu::CreatePopupWindow(Int_t w, Int_t h, const char* windowName,
699                                AliMpVPainter* painter,
700                                const char* option)
701 {
702   // Create transient frame
703   
704   TCanvas* c = new TCanvas(windowName,windowName,-200,100,w,h);
705
706   Int_t n = fTrashList.GetEntries();
707   
708   c->Connect("Closed()","AliMpDEVisu",this,Form("ClosePopupWindow(=%d)",n));
709              
710   fTrashList.AddLast(c);
711   
712   c->Draw();
713   
714   painter->Draw(option);
715   
716   c->Update();
717 }
718
719 //__________________________________________________________
720 void AliMpDEVisu::PopUpManuMotif(AliMpSlat* slat)
721 {
722   /// pop up manu window motif painter for slat
723   
724   // motif painter
725   AliMpMotifPosition* motifPosFound = 0x0;
726   AliMpMotifPosition* motifPos = 0x0;
727   Int_t manuId = 0;
728
729   for ( AliMpSlat::Size_t i = 0; i < slat->GetSize(); ++i ) {
730     
731     AliMpPCB* pcb = slat->GetPCB(i);
732     
733     for ( AliMpPCB::Size_t j = 0; j < slat->GetPCB(i)->GetSize(); ++j ) {
734       
735       motifPos = pcb->GetMotifPosition(j);
736       
737       manuId = motifPos->GetID();
738       if (manuId == (Int_t)fNumberEntry->GetIntNumber()) {
739         motifPosFound = motifPos;
740         break;
741       }
742     }
743     if (motifPosFound)
744       break;
745   }  
746
747   if(motifPosFound) 
748   {
749     InfoManuMotif(motifPosFound);
750
751     TVector2 dimension(motifPosFound->Dimensions());
752
753     Int_t h = 500;
754     Int_t w = Int_t(h*dimension.X()/dimension.Y());
755     AliMpVPainter* painter = AliMpVPainter::CreatePainter(motifPosFound);
756       
757     CreatePopupWindow(w,h,Form("Manu %d",fNumberEntry->GetIntNumber()),
758                       painter,"ZT");
759   }
760 }
761
762 //__________________________________________________________
763 void AliMpDEVisu::PopUpManuMotif(AliMpSector* sector)
764 {
765   /// pop up manu window motif painter for sector
766     
767   // motif painter
768   AliMpMotifPosition* motifPosFound = 0x0;
769   AliMpMotifPosition* motifPos = 0x0;
770   Int_t manuId = 0;
771
772   for (Int_t iRow = 0; iRow < sector->GetNofRows(); ++iRow) {
773     
774     AliMpRow* row = sector->GetRow(iRow);
775     
776     for (Int_t iRowSeg = 0; iRowSeg < sector->GetRow(iRow)->GetNofRowSegments(); ++iRowSeg){
777       
778       for (Int_t iRowSeg = 0; iRowSeg < row->GetNofRowSegments(); ++iRowSeg) {
779         AliMpVRowSegment *rowSegment = row->GetRowSegment(iRowSeg);
780         
781         for (Int_t iMotif = 0; iMotif < rowSegment->GetNofMotifs(); ++iMotif){
782           
783           Int_t motifPositionId = rowSegment->GetMotifPositionId(iMotif);
784           motifPos = rowSegment->GetRow()
785             ->GetMotifMap()->FindMotifPosition(motifPositionId);
786           
787           manuId = motifPos->GetID();
788           if (manuId == (Int_t)fNumberEntry->GetIntNumber()) {
789             motifPosFound = motifPos;
790             break;
791           }
792         }
793         if (motifPosFound)
794           break;
795       }
796     }
797     if (motifPosFound)
798       break;
799   }
800   
801   if(motifPosFound) 
802   {    
803
804     InfoManuMotif(motifPosFound);
805
806     TVector2 dimension(motifPosFound->Dimensions());
807
808     // Create transient frame
809     Int_t h = 400;
810     Int_t w = Int_t(h*dimension.X()/dimension.Y());
811
812     AliMpVPainter* painter = AliMpVPainter::CreatePainter(motifPosFound);
813     
814     CreatePopupWindow(w,h,Form("Manu %d",fNumberEntry->GetIntNumber()),
815                       painter,"ZT");
816     
817   }
818 }
819
820 //__________________________________________________________
821 void AliMpDEVisu::InfoManuMotif(AliMpMotifPosition* motifPos)
822 {
823 /// info for popup manu motif
824
825    // log message
826     Int_t manuId = fNumberEntry->GetIntNumber();
827     TVector2 dimension(motifPos->Dimensions());
828     fLogMessage->AddLine(Form("PopupManuMotif: motif dimension: %5.2f, %5.2f", 
829                               dimension.X()*2., dimension.Y()*2.));
830       
831     fLogMessage->AddLine( Form("PopupManuMotif: pad dimension: %4.2f, %4.2f", 
832                                motifPos->GetMotif()->GetPadDimensions(0).X()*2.,  
833                                motifPos->GetMotif()->GetPadDimensions(0).Y()*2. ));
834
835     fLogMessage->AddLine( Form("PopupManuMotif: manu: %d, serial number: %d, buspatch: %d",
836                                manuId, 
837                                fDDLStore->GetDetElement(fCurrentDetElem)->GetManuSerialFromId(manuId),
838                                fDDLStore->GetBusPatchId(fCurrentDetElem, manuId)) );
839
840     fLogMessage->ShowBottom();
841
842 }
843
844 //______________________________________________________________________________
845 void AliMpDEVisu::PopUpZoom(Int_t ix0, Int_t iy0, Int_t ix1, Int_t iy1)
846 {
847   /// popup zoom window
848
849   Double_t x0,y0;
850   EventToReal(ix0,iy0,x0,y0);
851   Double_t x1,y1;
852   EventToReal(ix1,iy1,x1,y1);
853
854   fLogMessage->AddLine(Form("PopUpZoom: zoom positions (x0, y0: %6.2f, %6.2f), (x1, y1: %6.2f, %6.2f)",
855                              x0, y0, x1, y1));
856   fLogMessage->ShowBottom();
857   
858   // Create transient frame
859   Int_t h = 500;//TMath::Abs(x1-x0);
860   Int_t w = 500;//TMath::Abs(y1-y0);
861
862   AliMpArea area(TVector2((x0+x1)/2.0,(y0+y1)/2.0),
863                   TVector2(TMath::Abs(x1-x0)/2.0,TMath::Abs(y1-y0)/2.0));
864 //  area.Print();
865   
866   if ( area.IsValid() )
867   {
868     AliMpVPadIterator* iterator = fSegmentation->CreateIterator(area);
869     if (iterator)
870     {
871       AliMpVPainter* painter = AliMpVPainter::CreatePainter(iterator);
872       CreatePopupWindow(w,h,"Zoom",painter,"");
873     }
874     else
875     {
876       AliError("could not get iterator for that area");
877     }
878         
879     delete iterator;
880   }
881 }
882
883 //__________________________________________________________
884 void AliMpDEVisu::ClosePopupWindow(Int_t id)
885 {
886   /// close signal
887   fEcanvas->GetCanvas()->cd();
888   fTrashList.RemoveAt(id);
889 }