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