]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDEVisu.cxx
c1de220b1b46e55045581dc33cd1b4fb4d9cce06
[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(kTRUE);
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   fNameDECombo->Select(fDEOccurrence[fCurrentDetElem]);
371   TGLBEntry* entry = fNameDECombo->GetSelectedEntry();
372   entry->SetBackgroundColor(0xDDDDDD);
373
374   if (AliMpDEManager::GetStationType(fCurrentDetElem) == AliMp::kStation345 ) {
375     
376     DrawSlat("PMCI");
377     
378   } else {
379     
380     DrawQuadrant("RSMCI");
381     
382   }
383   DeletePopUp();
384   fEcanvas->GetCanvas()->SetEditable(kFALSE);
385   
386 }
387
388 //__________________________________________________________
389 void AliMpDEVisu::DrawManuMotif(Bool_t popup) 
390 {
391   ///  Draw manu motif in yellow and popup channel motif window
392   
393   fEcanvas->GetCanvas()->SetEditable(kTRUE);
394   
395   if (!fNumberEntry->GetIntNumber()) return;
396   
397   Char_t command[255];
398   
399   if (AliMpDEManager::GetStationType(fCurrentDetElem) == AliMp::kStation345 ) {
400     
401     sprintf(command, "%s%d", "PMCI:", (Int_t)fNumberEntry->GetIntNumber());
402     
403     DrawSlat(command, popup);
404     
405   } else {   
406     
407     sprintf(command, "%s%d", "RSMCI:", (Int_t)fNumberEntry->GetIntNumber());
408     
409     DrawQuadrant(command, popup);
410     
411   }
412   
413   fEcanvas->GetCanvas()->SetEditable(kFALSE);
414 }
415
416 //__________________________________________________________
417 void AliMpDEVisu::DrawSlat(Option_t* option, Bool_t popup) 
418 {
419   /// draw slat segmentation
420   
421   TCanvas *canvas = fEcanvas->GetCanvas();
422   canvas->Clear();
423   
424   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
425   TString nameType =  detElem->GetSegType();
426   
427   AliMpSlatMotifMap mm;
428   AliMpSt345Reader reader(mm);  
429   AliMpSlat* slatCurrent = reader.ReadSlat(nameType.Data(), fCurrentPlane);
430   AliMpSlat* slatOther   = reader.ReadSlat(nameType.Data(), AliMp::OtherPlaneType(fCurrentPlane));
431   
432   AliMpVPainter* painter = AliMpVPainter::CreatePainter(slatCurrent);
433   painter->Draw(option);
434   
435   canvas->Update();
436   
437   Int_t numberOfManu = 
438       slatCurrent->GetNofElectronicCards() + 
439       slatOther->GetNofElectronicCards();
440     
441   fLogMessage->AddLine(Form("DrawSlat: number of manus: %d", numberOfManu));
442   fLogMessage->ShowBottom();   
443   
444   if (popup)
445     PopUpManuMotif(slatCurrent);
446   
447 }
448
449 //__________________________________________________________
450 void AliMpDEVisu::DrawQuadrant(Option_t* option, Bool_t popup)
451 {
452   /// draw quadrant segmentation
453   
454   TCanvas *canvas = fEcanvas->GetCanvas();
455   canvas->Clear();
456   
457   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
458   AliMp::StationType  station = detElem->GetStationType();
459
460   AliMpSectorReader readerCurrent(station, fCurrentPlane);
461   AliMpSector* sectorCurrent = readerCurrent.BuildSector();
462     
463   AliMpSectorReader readerOther(station, AliMp::OtherPlaneType(fCurrentPlane));
464   AliMpSector* sectorOther = readerOther.BuildSector();
465   
466   AliMpVPainter *painter = AliMpVPainter::CreatePainter(sectorCurrent);
467   painter->Draw(option);
468   
469   canvas->Update();
470   
471   Int_t numberOfManu =  
472       sectorCurrent->GetMotifMap()->GetNofMotifPositions() + 
473       sectorOther->GetMotifMap()->GetNofMotifPositions();
474   
475   fLogMessage->AddLine(Form("DrawQuadrant: number of manus: %d", numberOfManu));
476   fLogMessage->ShowBottom();   
477
478   if (popup) 
479     PopUpManuMotif(sectorCurrent);
480  
481 }
482
483 //______________________________________________________________________________
484 void 
485 AliMpDEVisu::EventToReal(Int_t eventX, Int_t eventY, Double_t& x, Double_t& y) const
486 {
487   /// estimate graphic pad sizes
488
489   static TVector2 ul(gPad->XtoPixel(0.01), gPad->YtoPixel(0.99));
490   static TVector2 br(gPad->XtoPixel(0.99), gPad->YtoPixel(0.01));
491
492   static TVector2 padDim = br - ul;
493   
494   // get DE dimension (half size)
495   TVector2 deDim(fSegmentation->Dimensions()*2.0);
496   
497   TVector2 padReal;
498   
499   if (AliMpDEManager::GetStationType(fCurrentDetElem) == AliMp::kStation345 )
500   {
501     // origin at center
502     x = (eventX - ul.X() - padDim.X()/2.)/(padDim.X())*deDim.X(); 
503     y = (br.Y() - eventY - padDim.Y()/2.)/(padDim.Y())*deDim.Y(); 
504     
505   } 
506   else 
507   {
508     // origin at bottom left
509     x = (eventX - ul.X())/(padDim.X())*deDim.X(); 
510     y = (br.Y() - eventY)/(padDim.Y())*deDim.Y(); 
511   }
512   
513 }
514
515 //__________________________________________________________
516 void AliMpDEVisu::ResetManu() 
517 {
518   /// reset manu search entry 
519   fLogMessage->AddLine("Reset Motif Search Entry:");
520   fLogMessage->ShowBottom();
521   fNumberEntry->SetNumber(0);
522   
523 }
524
525 //__________________________________________________________
526 void AliMpDEVisu::DeletePopUp() 
527 {
528 /// delete motif popup windows 
529   
530   if (fTrashList.GetEntries() > 0) 
531   {
532     fLogMessage->AddLine("Delete Motif PopUp Windows:");
533     fLogMessage->ShowBottom();
534     
535     fTrashList.Delete();
536   } 
537 }
538
539 //__________________________________________________________
540 void AliMpDEVisu::SaveLogMessage() 
541 {
542   /// save log message into log file
543   
544   TString logFile = fLogFile->GetDisplayText();
545   fLogMessage->GetText()->Save(logFile.Data());
546
547   fLogMessage->AddLine(Form("SaveLogMessage: saving log message into logfile: %s", logFile.Data()));
548   fLogMessage->ShowBottom();  
549 }
550
551 //__________________________________________________________
552 void AliMpDEVisu::ClearLogMessage() 
553 {
554   /// clear log message 
555   fLogMessage->GetText()->Clear();
556   fLogMessage->AddLine("ClearLogMessage: clear log messages:");
557   fLogMessage->ShowBottom();  
558 }
559
560 //__________________________________________________________
561 void AliMpDEVisu::InfoDE() 
562 {
563   /// info concerning the whole DE
564   
565   AliMpDetElement* detElem = fDDLStore->GetDetElement(fCurrentDetElem);
566   Int_t ddlId        = detElem->GetDdlId();
567   Int_t numberOfBus  = detElem->GetNofBusPatches();
568   
569   Int_t vec[24];
570   for (Int_t i = 0; i <  detElem->GetNofBusPatches(); ++i)
571       vec[i] = detElem->GetBusPatchId(i);
572
573   Int_t firstBus     = TMath::MinElement(detElem->GetNofBusPatches(), vec);
574   Int_t lastBus      = TMath::MaxElement(detElem->GetNofBusPatches(), vec);
575   
576   detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
577   Int_t numberOfSerialManu = detElem->GetNofManus(); // number of manu with an identified serial number
578   
579   fLogMessage->AddLine(Form("DrawDE: detection element: %d, name: %s", 
580                        fCurrentDetElem, fCurrentDEName.Data()));
581   fLogMessage->ShowBottom();   
582   
583   fLogMessage->AddLine(Form("DrawDE: DDL: %d, number of buspatches %d from %d to %d", 
584                             ddlId, numberOfBus, firstBus, lastBus));
585   fLogMessage->ShowBottom();
586   
587   if (numberOfSerialManu != 0) { // not available yet for all DE 
588     fLogMessage->AddLine(Form("DrawDE: number of manus with serial number: %d", numberOfSerialManu));
589     fLogMessage->ShowBottom();
590   }
591   
592 }
593
594 //__________________________________________________________
595 Bool_t AliMpDEVisu::ProcessMessage(Long_t msg, Long_t parm1, Long_t /*parm2*/)
596 {
597   /// process message from widgets actions/entries
598
599   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
600
601   switch(GET_MSG(msg)) 
602   {
603     case kC_COMMAND: 
604       switch (GET_SUBMSG(msg)) 
605       {
606         case kCM_COMBOBOX: 
607           
608           switch (parm1) 
609           {
610             case kChamberCombo: 
611               UpdateComboDE();
612               UpdateNameView(kTRUE);
613               break;
614               
615             case kDECombo:
616               UpdateNameView();
617               break; 
618              
619           case kDEName:
620               UpdateComboCH();
621               break;
622           }
623           break;
624           
625         case kCM_CHECKBUTTON:
626           switch (parm1) 
627           {
628             case kPlaneType:
629               if (fPlaneButton->GetState() == kButtonDown) {
630                 fCurrentPlane = AliMp::kNonBendingPlane;
631                 if (fNumberEntry->GetIntNumber() && fNumberEntry->GetIntNumber() <= 1024)
632                   fNumberEntry->SetNumber(fNumberEntry->GetIntNumber() + 1024);
633               } else {
634                 fCurrentPlane = AliMp::kBendingPlane;
635                 if (fNumberEntry->GetIntNumber() && fNumberEntry->GetIntNumber() > 1024)
636                   fNumberEntry->SetNumber(fNumberEntry->GetIntNumber() - 1024);
637               }
638               DrawDE();
639               fSegmentation = AliMpSegmentation::Instance()
640                 ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
641               break;
642
643             case kZoomMode:
644                 if (fZoomButton->GetState() == kButtonDown)
645                     fZoomMode = true;
646                 else
647                     fZoomMode = false;
648               break;
649           }
650           break;
651           
652       }
653       break;
654   }
655   return true;
656 }
657
658 //__________________________________________________________
659 void AliMpDEVisu::NextDE()
660 {
661   /// select next DE
662   
663   Int_t next = fDECombo->GetSelected() + 1;
664   
665   if (next < fDECombo->GetNumberOfEntries())
666     fDECombo->Select(next);
667   else 
668     fDECombo->Select(0);
669   
670   UpdateNameView();
671   DrawDE();
672 }
673
674 //__________________________________________________________
675 void AliMpDEVisu::UpdateComboCH()
676 {
677   /// update Chamber/DE in respect to DE Name
678
679     fCurrentDEName = fNameDEComboIdx[fNameDECombo->GetSelected()];
680
681     AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDEName);
682
683     Int_t idx =  AliMpDEManager::GetChamberId(detElem->GetId());
684     fChamberCombo->Select(idx);
685
686     UpdateComboDE();
687
688     idx = detElem->GetId() % 100;
689     fDECombo->Select(idx);
690
691     fCurrentDetElem = fDEComboIdx[fDECombo->GetSelected()];
692
693     fSegmentation = AliMpSegmentation::Instance()
694         ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
695 }
696
697 //__________________________________________________________
698 void AliMpDEVisu::UpdateComboDE()
699 {
700   /// update DE in respect to selected chamber
701   
702   fDECombo->RemoveAll();
703   
704   AliMpDEIterator it;
705   Int_t i = 0;
706   fDEComboIdx.Reset();
707   
708   for ( it.First(fChamberCombo->GetSelected()); ! it.IsDone(); it.Next() ) {
709     fDECombo->AddEntry(Form("%d",it.CurrentDE()->GetId()), i);
710     fDEComboIdx[i++] = it.CurrentDE()->GetId();
711   }
712   fDECombo->Select(0);
713 }
714
715 //__________________________________________________________
716 void AliMpDEVisu::UpdateNameView(Bool_t firstTime)
717 {
718   /// update DE name in respect to selected DE id.
719     
720   fCurrentDetElem = fDEComboIdx[fDECombo->GetSelected()];
721
722   AliMpDetElement* detElem = AliMpDEManager::GetDetElement(fCurrentDetElem);
723
724   fCurrentDEName = detElem->GetDEName();
725
726   if (firstTime) {
727     AliMpDEIterator it;
728  
729     fNameDECombo->RemoveAll();
730   
731     for ( it.First(fChamberCombo->GetSelected()); !it.IsDone(); it.Next() ) {
732
733       Int_t detElemId = it.CurrentDE()->GetId();
734       TString deName  = it.CurrentDE()->GetDEName();
735
736       Int_t idx = fNameDECombo->GetNumberOfEntries();
737       fNameDECombo->AddEntry(deName.Data(), idx);
738       fNameDEComboIdx[idx]   = deName;
739       fDEOccurrence[detElemId] = idx;
740     }
741   }
742
743   fNameDECombo->Select(fDEOccurrence[fCurrentDetElem]);
744   fSegmentation = AliMpSegmentation::Instance()
745     ->GetMpSegmentation(fCurrentDetElem, detElem->GetCathodType(fCurrentPlane));
746 }
747
748 //______________________________________________________________________________
749 void
750 AliMpDEVisu::CreatePopupWindow(Int_t w, Int_t h, const char* windowName,
751                                AliMpVPainter* painter,
752                                const char* option)
753 {
754   /// Create transient frame
755   
756   TCanvas* c = new TCanvas(windowName,windowName,-200,100,w,h);
757
758   Int_t n = fTrashList.GetEntries();
759   
760   c->Connect("Closed()","AliMpDEVisu",this,Form("ClosePopupWindow(=%d)",n));
761              
762   fTrashList.AddLast(c);
763   
764   c->Draw();
765   
766   painter->Draw(option);
767   
768   c->Update();
769 }
770
771 //__________________________________________________________
772 void AliMpDEVisu::PopUpManuMotif(AliMpSlat* slat)
773 {
774   /// pop up manu window motif painter for slat
775   
776   // motif painter
777   AliMpMotifPosition* motifPosFound = 0x0;
778   AliMpMotifPosition* motifPos = 0x0;
779   Int_t manuId = 0;
780
781   for ( AliMpSlat::Size_t i = 0; i < slat->GetSize(); ++i ) {
782     
783     AliMpPCB* pcb = slat->GetPCB(i);
784     
785     for ( AliMpPCB::Size_t j = 0; j < slat->GetPCB(i)->GetSize(); ++j ) {
786       
787       motifPos = pcb->GetMotifPosition(j);
788       
789       manuId = motifPos->GetID();
790       if (manuId == (Int_t)fNumberEntry->GetIntNumber()) {
791         motifPosFound = motifPos;
792         break;
793       }
794     }
795     if (motifPosFound)
796       break;
797   }  
798
799   if(motifPosFound) 
800   {
801     InfoManuMotif(motifPosFound);
802
803     TVector2 dimension(motifPosFound->Dimensions());
804
805     Int_t h = 500;
806     Int_t w = Int_t(h*dimension.X()/dimension.Y());
807     AliMpVPainter* painter = AliMpVPainter::CreatePainter(motifPosFound);
808       
809     CreatePopupWindow(w,h,Form("Manu %d",fNumberEntry->GetIntNumber()),
810                       painter,"ZT");
811   }
812 }
813
814 //__________________________________________________________
815 void AliMpDEVisu::PopUpManuMotif(AliMpSector* sector)
816 {
817   /// pop up manu window motif painter for sector
818     
819   // motif painter
820   AliMpMotifPosition* motifPosFound = 0x0;
821   AliMpMotifPosition* motifPos = 0x0;
822   Int_t manuId = 0;
823
824   for (Int_t iRow = 0; iRow < sector->GetNofRows(); ++iRow) {
825     
826     AliMpRow* row = sector->GetRow(iRow);
827     
828     for (Int_t iRowSeg = 0; iRowSeg < sector->GetRow(iRow)->GetNofRowSegments(); ++iRowSeg){
829       
830       for (Int_t iRowSeg = 0; iRowSeg < row->GetNofRowSegments(); ++iRowSeg) {
831         AliMpVRowSegment *rowSegment = row->GetRowSegment(iRowSeg);
832         
833         for (Int_t iMotif = 0; iMotif < rowSegment->GetNofMotifs(); ++iMotif){
834           
835           Int_t motifPositionId = rowSegment->GetMotifPositionId(iMotif);
836           motifPos = rowSegment->GetRow()
837             ->GetMotifMap()->FindMotifPosition(motifPositionId);
838           
839           manuId = motifPos->GetID();
840           if (manuId == (Int_t)fNumberEntry->GetIntNumber()) {
841             motifPosFound = motifPos;
842             break;
843           }
844         }
845         if (motifPosFound)
846           break;
847       }
848     }
849     if (motifPosFound)
850       break;
851   }
852   
853   if(motifPosFound) 
854   {    
855
856     InfoManuMotif(motifPosFound);
857
858     TVector2 dimension(motifPosFound->Dimensions());
859
860     // Create transient frame
861     Int_t h = 400;
862     Int_t w = Int_t(h*dimension.X()/dimension.Y());
863
864     AliMpVPainter* painter = AliMpVPainter::CreatePainter(motifPosFound);
865     
866     CreatePopupWindow(w,h,Form("Manu %d",fNumberEntry->GetIntNumber()),
867                       painter,"ZT");
868     
869   }
870 }
871
872 //__________________________________________________________
873 void AliMpDEVisu::InfoManuMotif(AliMpMotifPosition* motifPos)
874 {
875 /// info for popup manu motif
876
877    // log message
878     Int_t manuId = fNumberEntry->GetIntNumber();
879     TVector2 dimension(motifPos->Dimensions());
880     fLogMessage->AddLine(Form("PopupManuMotif: motif dimension: %5.2f, %5.2f", 
881                               dimension.X()*2., dimension.Y()*2.));
882       
883     fLogMessage->AddLine( Form("PopupManuMotif: pad dimension: %4.2f, %4.2f", 
884                                motifPos->GetMotif()->GetPadDimensions(0).X()*2.,  
885                                motifPos->GetMotif()->GetPadDimensions(0).Y()*2. ));
886
887     fLogMessage->AddLine( Form("PopupManuMotif: manu: %d, serial number: %d, buspatch: %d",
888                                manuId, 
889                                fDDLStore->GetDetElement(fCurrentDetElem)->GetManuSerialFromId(manuId),
890                                fDDLStore->GetBusPatchId(fCurrentDetElem, manuId)) );
891
892     fLogMessage->ShowBottom();
893
894 }
895
896 //______________________________________________________________________________
897 void AliMpDEVisu::PopUpZoom(Int_t ix0, Int_t iy0, Int_t ix1, Int_t iy1)
898 {
899   /// popup zoom window
900
901   Double_t x0,y0;
902   EventToReal(ix0,iy0,x0,y0);
903   Double_t x1,y1;
904   EventToReal(ix1,iy1,x1,y1);
905
906   fLogMessage->AddLine(Form("PopUpZoom: zoom positions (x0, y0: %6.2f, %6.2f), (x1, y1: %6.2f, %6.2f)",
907                              x0, y0, x1, y1));
908   fLogMessage->ShowBottom();
909   
910   // Create transient frame
911   Int_t h = 500;//TMath::Abs(x1-x0);
912   Int_t w = 500;//TMath::Abs(y1-y0);
913
914   AliMpArea area(TVector2((x0+x1)/2.0,(y0+y1)/2.0),
915                   TVector2(TMath::Abs(x1-x0)/2.0,TMath::Abs(y1-y0)/2.0));
916 //  area.Print();
917   
918   if ( area.IsValid() )
919   {
920     AliMpVPadIterator* iterator = fSegmentation->CreateIterator(area);
921     if (iterator)
922     {
923       AliMpVPainter* painter = AliMpVPainter::CreatePainter(iterator);
924       CreatePopupWindow(w,h,"Zoom",painter,"");
925     }
926     else
927     {
928       AliError("could not get iterator for that area");
929     }
930         
931     delete iterator;
932   }
933 }
934
935 //__________________________________________________________
936 void AliMpDEVisu::ClosePopupWindow(Int_t id)
937 {
938   /// close signal
939   fEcanvas->GetCanvas()->cd();
940   fTrashList.RemoveAt(id);
941 }