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