]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliColourStore.cxx
Bugfix in AliPoints2Memory
[u/mrichter/AliRoot.git] / AliGeant4 / AliColourStore.cxx
1 // $Id$
2 // Category: visualization
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class AliColourStore
7 // --------------------
8 // See the class description in the header file.
9
10 #include "AliColourStore.h"
11 #include "AliGlobals.h"
12
13 // static data members
14
15 //_____________________________________________________________________________
16 AliColourStore* AliColourStore::fgInstance = 0;
17
18 //_____________________________________________________________________________
19 AliColourStore::AliColourStore() 
20 {
21   // fill predefined colours 
22   G4int id0 = 1000;
23      
24   fColours.push_back(TColor(id0 + 0,  0.99, 0.99, 0.99, "White"));   
25   fColours.push_back(TColor(id0 + 1,  0.00, 0.00, 0.00, "Black"));  
26   fColours.push_back(TColor(id0 + 2,  0.99, 0.00, 0.00, "Red"));  
27   fColours.push_back(TColor(id0 + 3,  0.99, 0.50, 0.00, "Red2")); 
28   fColours.push_back(TColor(id0 + 4,  0.00, 0.00, 0.99, "Green"));   
29   fColours.push_back(TColor(id0 + 5,  0.00, 0.50, 0.99, "Green2"));   
30   fColours.push_back(TColor(id0 + 6,  0.50, 0.00, 0.99, "Green3"));
31   fColours.push_back(TColor(id0 + 7,  0.00, 0.99, 0.00, "Blue"));
32   fColours.push_back(TColor(id0 + 8,  0.00, 0.99, 0.99, "Blue2"));
33   fColours.push_back(TColor(id0 + 9,  0.00, 0.99, 0.50, "Blue3"));
34   fColours.push_back(TColor(id0 + 10, 0.99, 0.00, 0.99, "Yellow"));    
35   fColours.push_back(TColor(id0 + 11, 0.99, 0.99, 0.00, "Magenta"));    
36   fColours.push_back(TColor(id0 + 12, 0.50, 0.99, 0.00, "Magenta2"));   
37   fColours.push_back(TColor(id0 + 13, 0.99, 0.00, 0.50, "Brown"));
38   fColours.push_back(TColor(id0 + 14, 0.30, 0.30, 0.30, "Gray"));       
39 }
40
41 //_____________________________________________________________________________
42 AliColourStore::AliColourStore(const AliColourStore& right) {
43 // 
44   AliGlobals::Exception(
45     "Attempt to copy AliColourStore singleton.");
46 }
47
48 //_____________________________________________________________________________
49 AliColourStore::~AliColourStore() {
50 //
51 }
52
53 // operators
54
55 //_____________________________________________________________________________
56 AliColourStore& AliColourStore::operator=(const AliColourStore& right)
57 {
58   // check assignement to self
59   if (this == &right) return *this;
60
61   AliGlobals::Exception(
62     "Attempt to assign AliColourStore singleton.");
63     
64   return *this;  
65 }    
66
67 // static methods
68   
69 //_____________________________________________________________________________
70 AliColourStore* AliColourStore::Instance() 
71 {
72 // Returns the singleton instance.
73 // Creates the instance if it does not exist.
74 // ---
75
76   if (fgInstance == 0 )
77     fgInstance = new AliColourStore();
78   
79   return fgInstance;
80 }
81
82 // public methods
83
84 //_____________________________________________________________________________
85 G4Colour AliColourStore::GetColour(const G4String& name) const
86 {
87 // Retrieves the colour by name.
88 // ---
89
90   ColourConstIterator it;  
91   for (it = fColours.begin(); it != fColours.end(); it++) 
92     if (name == (*it).GetName()) return GetColour(*it);
93   
94   G4String text = "Colour " + name + " is not defined.";
95   AliGlobals::Exception(text);
96   return 0;
97 }
98     
99 //_____________________________________________________________________________
100 G4Colour AliColourStore::GetColour(const TColor& color) const
101 {
102 // Converts TColor to G4Colour.
103 // ---
104
105   return G4Colour(color.GetRed(), color.GetBlue(), color.GetGreen());
106 }
107     
108 //_____________________________________________________________________________
109 G4String AliColourStore::GetColoursList() const
110 {
111 // Returns the list of all defined colours names.
112 // ---
113
114   G4String list = "";
115   ColourConstIterator it;
116
117   for (it = fColours.begin(); it != fColours.end(); it++) {
118     list += (*it).GetName();
119     list += " ";
120   }
121   
122   return list;
123
124        
125 //_____________________________________________________________________________
126 G4String AliColourStore::GetColoursListWithCommas() const
127 {
128 // Returns the list of all defined colours names
129 // with commas.
130 // ---
131
132   G4String list = "";
133   G4int i = 0;
134   ColourConstIterator it;
135
136   for (it = fColours.begin(); it != fColours.end(); it++) {
137     list += (*it).GetName();
138     if (i++ < fColours.size()-1) list += ", ";
139   }
140   
141   return list;
142