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