]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPainterColorSlider.cxx
Add Config/HighVoltage directory and entry
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterColorSlider.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
18 #include "AliMUONPainterColorSlider.h"
19 #include "AliMUONPainterHelper.h"
20 #include "AliLog.h"
21 #include <TGNumberEntry.h>
22 #include <TGButton.h>
23 #include <TMath.h>
24
25 ///\class AliMUONPainterColorSlider
26 ///
27 /// A painter color palette
28 ///
29 ///\author Laurent Aphecetche, Subatech
30
31 ///\cond CLASSIMP
32 ClassImp(AliMUONPainterColorSlider)
33 ///\endcond
34
35 //_____________________________________________________________________________
36 AliMUONPainterColorSlider::AliMUONPainterColorSlider(const TGWindow* p, 
37                                                      UInt_t w, UInt_t h)
38 : TGCompositeFrame(p,w,h,kVerticalFrame),
39   fEntryMin(0x0),
40   fEntryMax(0x0),
41   fMin(FLT_MAX),
42   fMax(-FLT_MAX)
43 {
44     /// ctor
45     Int_t ndivisions(20);
46   
47     Int_t hsize = (h-100)/(ndivisions+2);
48   Int_t topBorder(5);
49   
50   Double_t min(0.0);
51   Double_t max(1.0);
52   
53   Double_t step = (max-min)/ndivisions;
54   
55   for ( Int_t i = -1; i <= ndivisions+1; ++i ) 
56   {
57     Double_t value = max - (min + step*i);
58     
59     Int_t color = AliMUONPainterHelper::Instance()->ColorFromValue(value,
60                                                                    min,max);
61     Pixel_t pixel = gVirtualX->GetPixel(color);
62     TGVerticalFrame* frame = new TGVerticalFrame(this,w,hsize,kFixedSize,pixel);
63     
64     AddFrame(frame,new TGLayoutHints(kLHintsExpandX,0,0,topBorder,0));
65     
66     topBorder = 0;
67   }
68   
69   fEntryMax = new TGNumberEntry(this);
70   
71   AddFrame(fEntryMax,new TGLayoutHints(kLHintsExpandX,0,0,topBorder,0));
72     
73   fEntryMin = new TGNumberEntry(this);
74   
75   AddFrame(fEntryMin,new TGLayoutHints(kLHintsExpandX,0,0,topBorder,0));
76   
77 //  fEntryMin->SetFormat(TGNumberFormat::kNESRealOne);
78 //  fEntryMax->SetFormat(TGNumberFormat::kNESRealOne);
79   
80   TGTextButton* button = new TGTextButton(this,"Auto");
81   
82   AddFrame(button,new TGLayoutHints(kLHintsExpandX,0,0,topBorder,0));
83   
84   button->Connect("Clicked()","AliMUONPainterColorSlider",this,"DataRangeAutoRequested()");
85   
86   fEntryMax->Connect("ValueSet(Long_t)","AliMUONPainterColorSlider",this,"DataRangeWasChanged(Double_t*)");
87   fEntryMin->Connect("ValueSet(Long_t)","AliMUONPainterColorSlider",this,"DataRangeWasChanged(Double_t*)");
88 }
89
90 //_____________________________________________________________________________
91 AliMUONPainterColorSlider::~AliMUONPainterColorSlider()
92 {
93   /// dtor
94 }
95
96 //_____________________________________________________________________________
97 void 
98 AliMUONPainterColorSlider::DataRangeAutoRequested()
99 {
100   /// Signal that the "Auto" button was clicked
101   AliDebug(1,"");
102   Emit("DataRangeAutoRequested()");
103 }
104
105 //_____________________________________________________________________________
106 void 
107 AliMUONPainterColorSlider::DataRangeWasChanged(Double_t*)
108 {
109   /// Data range was changed
110   
111   Double_t values[] = { fEntryMin->GetNumber(), fEntryMax->GetNumber() };
112   
113   Long_t param[] = { (Long_t)values };
114   
115   AliDebug(1,Form("double min %e max %e",values[0],values[1]));
116   
117   Emit("DataRangeWasChanged(Double_t*)",param);
118 }
119
120 //_____________________________________________________________________________
121 void 
122 AliMUONPainterColorSlider::SetRange(Double_t min, Double_t max, Bool_t emit)
123 {
124   /// Set the data range
125   
126   AliDebug(1,Form("min %e max %e emit %d",min,max,emit));
127   
128   fMin = min;
129   fMax = max;
130   
131   fEntryMin->SetNumber(fMin);
132   fEntryMax->SetNumber(fMax);
133   
134   if ( emit ) 
135   {
136     DataRangeWasChanged(0x0);
137   }
138 }
139