1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz 2/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2005
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MEnv
|
---|
28 | //
|
---|
29 | // It is a slightly changed version of TEnv. It logs all resources which are
|
---|
30 | // touched, so that you can print all untouched resources by
|
---|
31 | // PrintUntouched()
|
---|
32 | //
|
---|
33 | //////////////////////////////////////////////////////////////////////////////
|
---|
34 | #include "MEnv.h"
|
---|
35 |
|
---|
36 | #include <Gtypes.h>
|
---|
37 | #include <TObjString.h>
|
---|
38 |
|
---|
39 | #include <TPave.h>
|
---|
40 | #include <TAttText.h>
|
---|
41 | #include <TAttMarker.h>
|
---|
42 | #include <THashList.h> // needed since root v5.10/00 (TEnv::GetTable)
|
---|
43 |
|
---|
44 | #include "MLog.h"
|
---|
45 | #include "MLogManip.h"
|
---|
46 |
|
---|
47 | ClassImp(MEnv);
|
---|
48 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 | //---------------------------------------------------------------------------
|
---|
52 | //
|
---|
53 | // (Default) constructor. If the given file cannot be accessed the data
|
---|
54 | // member fName is set to "" which can then be checked by IsValid()
|
---|
55 | //
|
---|
56 | MEnv::MEnv(const char *name) : TEnv(name), fName(name)
|
---|
57 | {
|
---|
58 | fChecked.SetOwner();
|
---|
59 |
|
---|
60 | if (fName.IsNull())
|
---|
61 | return;
|
---|
62 |
|
---|
63 | TString fname(name);
|
---|
64 | gSystem->ExpandPathName(fname);
|
---|
65 |
|
---|
66 | if (gSystem->AccessPathName(fname, kFileExists))
|
---|
67 | fName = "";
|
---|
68 | }
|
---|
69 |
|
---|
70 | //---------------------------------------------------------------------------
|
---|
71 | //
|
---|
72 | // Compile str+post and make sure that in between there is a unique dot.
|
---|
73 | //
|
---|
74 | TString MEnv::Compile(TString str, const char *post) const
|
---|
75 | {
|
---|
76 | if (!str.IsNull() && !str.EndsWith("."))
|
---|
77 | str += ".";
|
---|
78 |
|
---|
79 | str += post;
|
---|
80 |
|
---|
81 | return str;
|
---|
82 | }
|
---|
83 |
|
---|
84 | //---------------------------------------------------------------------------
|
---|
85 | //
|
---|
86 | // Get the value from the table and remember the value as checked
|
---|
87 | //
|
---|
88 | Int_t MEnv::GetValue(const char *name, Int_t dflt)
|
---|
89 | {
|
---|
90 | if (!fChecked.FindObject(name))
|
---|
91 | fChecked.Add(new TObjString(name));
|
---|
92 | return TEnv::GetValue(name, dflt);
|
---|
93 | }
|
---|
94 |
|
---|
95 | //---------------------------------------------------------------------------
|
---|
96 | //
|
---|
97 | // Get the value from the table and remember the value as checked
|
---|
98 | //
|
---|
99 | Double_t MEnv::GetValue(const char *name, Double_t dflt)
|
---|
100 | {
|
---|
101 | if (!fChecked.FindObject(name))
|
---|
102 | fChecked.Add(new TObjString(name));
|
---|
103 | return TEnv::GetValue(name, dflt);
|
---|
104 | }
|
---|
105 |
|
---|
106 | //---------------------------------------------------------------------------
|
---|
107 | //
|
---|
108 | // Get the value from the table and remember the value as checked
|
---|
109 | //
|
---|
110 | const char *MEnv::GetValue(const char *name, const char *dflt)
|
---|
111 | {
|
---|
112 | if (!fChecked.FindObject(name))
|
---|
113 | fChecked.Add(new TObjString(name));
|
---|
114 | return TEnv::GetValue(name, dflt);
|
---|
115 | }
|
---|
116 |
|
---|
117 | //---------------------------------------------------------------------------
|
---|
118 | //
|
---|
119 | // TEnv doen't have a streamer --> cannot be cloned
|
---|
120 | // --> we have to clone it ourself
|
---|
121 | //
|
---|
122 | TObject *MEnv::Clone(const char *) const
|
---|
123 | {
|
---|
124 | MEnv *env = new MEnv("/dev/null");
|
---|
125 | env->fName = fName;
|
---|
126 | env->AddEnv(*this);
|
---|
127 | return env;
|
---|
128 | }
|
---|
129 |
|
---|
130 | //---------------------------------------------------------------------------
|
---|
131 | //
|
---|
132 | // Interprete fill style: Hollow, Solid, Hatch, 0%-100%
|
---|
133 | // If no text style is detected the value is converted to an integer.
|
---|
134 | //
|
---|
135 | Int_t MEnv::GetFillStyle(const char *name, Int_t dftl)
|
---|
136 | {
|
---|
137 | TString str = GetValue(name, "");
|
---|
138 | str = str.Strip(TString::kBoth);
|
---|
139 | if (str.IsNull())
|
---|
140 | return dftl;
|
---|
141 |
|
---|
142 | str.ToLower();
|
---|
143 |
|
---|
144 | switch (str.Hash())
|
---|
145 | {
|
---|
146 | case 2374867578U: return 0; // hollow
|
---|
147 | case 764279305U: return 1001; // solid
|
---|
148 | case 1854683492U: return 2001; // hatch
|
---|
149 | }
|
---|
150 |
|
---|
151 | return str.EndsWith("%") ? 4000+str.Atoi() : str.Atoi();
|
---|
152 | }
|
---|
153 |
|
---|
154 | //---------------------------------------------------------------------------
|
---|
155 | //
|
---|
156 | // Interprete line style: Solid, Dashed, Dotted, DashDotted
|
---|
157 | // If no line style is detected the value is converted to an integer.
|
---|
158 | //
|
---|
159 | Int_t MEnv::GetLineStyle(const char *name, Int_t dftl)
|
---|
160 | {
|
---|
161 | TString str = GetValue(name, "");
|
---|
162 | str = str.Strip(TString::kBoth);
|
---|
163 | if (str.IsNull())
|
---|
164 | return dftl;
|
---|
165 |
|
---|
166 | str.ToLower();
|
---|
167 |
|
---|
168 | switch (str.Hash())
|
---|
169 | {
|
---|
170 | case 764279305U: return kSolid;
|
---|
171 | case 241979881U: return kDashed;
|
---|
172 | case 2391642602U: return kDotted;
|
---|
173 | case 1124931659U: return kDashDotted;
|
---|
174 | }
|
---|
175 |
|
---|
176 | return str.Atoi();
|
---|
177 | }
|
---|
178 |
|
---|
179 | //---------------------------------------------------------------------------
|
---|
180 | //
|
---|
181 | // Interprete alignment: Top, Right, Left, Bottom, Center, tr, cc, bl, ...
|
---|
182 | // If no text align is detected the value is converted to an integer.
|
---|
183 | //
|
---|
184 | // eg.
|
---|
185 | // Top Right
|
---|
186 | // Bottom Center
|
---|
187 | // Center
|
---|
188 | // tr
|
---|
189 | // br
|
---|
190 | // cr
|
---|
191 | //
|
---|
192 | Int_t MEnv::GetAlign(const char *name, Int_t dftl)
|
---|
193 | {
|
---|
194 | TString str = GetValue(name, "");
|
---|
195 | str = str.Strip(TString::kBoth);
|
---|
196 | if (str.IsNull())
|
---|
197 | return dftl;
|
---|
198 |
|
---|
199 | str.ToLower();
|
---|
200 |
|
---|
201 | switch (str.Hash())
|
---|
202 | {
|
---|
203 | case 29746: return 33; // tr
|
---|
204 | case 25379: return 22; // cc
|
---|
205 | case 25132: return 11; // bl
|
---|
206 |
|
---|
207 | case 25388: return 12; // cl
|
---|
208 | case 25394: return 32; // cr
|
---|
209 |
|
---|
210 | case 29731: return 23; // tc
|
---|
211 | case 25123: return 32; // bc
|
---|
212 |
|
---|
213 | case 29740: return 13; // tl
|
---|
214 | case 25138: return 13; // br
|
---|
215 | }
|
---|
216 |
|
---|
217 | Int_t align = 0;
|
---|
218 | if (str.Contains("right", TString::kIgnoreCase))
|
---|
219 | align += 3;
|
---|
220 | if (str.Contains("left", TString::kIgnoreCase))
|
---|
221 | align += 1;
|
---|
222 | if (str.Contains("bottom", TString::kIgnoreCase))
|
---|
223 | align += 10;
|
---|
224 | if (str.Contains("top", TString::kIgnoreCase))
|
---|
225 | align += 30;
|
---|
226 |
|
---|
227 | if (str.Contains("center", TString::kIgnoreCase))
|
---|
228 | {
|
---|
229 | if (align==0)
|
---|
230 | return 22;
|
---|
231 | if (align/10==0)
|
---|
232 | return align+20;
|
---|
233 | if (align%10==0)
|
---|
234 | return align+2;
|
---|
235 | }
|
---|
236 |
|
---|
237 | return align>0 ? align : str.Atoi();
|
---|
238 | }
|
---|
239 |
|
---|
240 | //---------------------------------------------------------------------------
|
---|
241 | //
|
---|
242 | // Interprete color: Black, White, Red, Green, Blue, Yellow, Magenta,
|
---|
243 | // Cyan, Gray1-5, Grey1-5.
|
---|
244 | // If no text color is detected the value is converted to an integer.
|
---|
245 | //
|
---|
246 | // eg.
|
---|
247 | // Red
|
---|
248 | // Light Red
|
---|
249 | // Dark Red
|
---|
250 | //
|
---|
251 | Int_t MEnv::GetColor(const char *name, Int_t dftl)
|
---|
252 | {
|
---|
253 | TString str = GetValue(name, "");
|
---|
254 |
|
---|
255 | str = str.Strip(TString::kBoth);
|
---|
256 | if (str.IsNull())
|
---|
257 | return dftl;
|
---|
258 |
|
---|
259 | str.ToLower();
|
---|
260 |
|
---|
261 | Int_t offset=0;
|
---|
262 | if (str.Contains("dark"))
|
---|
263 | {
|
---|
264 | str.ReplaceAll("dark", "");
|
---|
265 | str = str.Strip(TString::kBoth);
|
---|
266 | offset = 100;
|
---|
267 | }
|
---|
268 | if (str.Contains("light"))
|
---|
269 | {
|
---|
270 | str.ReplaceAll("light", "");
|
---|
271 | str = str.Strip(TString::kBoth);
|
---|
272 | offset = 150;
|
---|
273 | }
|
---|
274 |
|
---|
275 | switch (str.Hash())
|
---|
276 | {
|
---|
277 | case 2368543371U: return kWhite+offset;
|
---|
278 | case 1814927399U: return kBlack+offset;
|
---|
279 | case 7496964U: return kRed+offset;
|
---|
280 | case 2897107074U: return kGreen+offset;
|
---|
281 | case 1702194402U: return kBlue+offset;
|
---|
282 | case 2374817882U: return kYellow+offset;
|
---|
283 | case 2894218701U: return kMagenta+offset;
|
---|
284 | case 1851881955U: return kCyan+offset;
|
---|
285 | case 749623518U: return 19; // grey1
|
---|
286 | case 749623517U: return 18; // grey2
|
---|
287 | case 749623516U: return 17; // grey3
|
---|
288 | case 749623515U: return 16; // grey4
|
---|
289 | case 749623514U: return 15; // grey5
|
---|
290 | case 749623513U: return 14; // grey6
|
---|
291 | case 749623512U: return 13; // grey7
|
---|
292 | case 749623511U: return 12; // grey8
|
---|
293 | case 741234910U: return 19; // gray1
|
---|
294 | case 741234909U: return 18; // gray2
|
---|
295 | case 741234908U: return 17; // gray3
|
---|
296 | case 741234907U: return 16; // gray4
|
---|
297 | case 741234906U: return 15; // gray5
|
---|
298 | case 741234905U: return 14; // gray6
|
---|
299 | case 741234904U: return 13; // gray7
|
---|
300 | case 741234903U: return 12; // gray8
|
---|
301 | }
|
---|
302 | return str.Atoi();
|
---|
303 | }
|
---|
304 |
|
---|
305 | //---------------------------------------------------------------------------
|
---|
306 | //
|
---|
307 | // As possible convert the color col into a text string which can be
|
---|
308 | // interpreted by GetColor before setting the resource value
|
---|
309 | //
|
---|
310 | void MEnv::SetColor(const char *name, Int_t col)
|
---|
311 | {
|
---|
312 | TString val;
|
---|
313 |
|
---|
314 | if (col>99 && col<101+kCyan)
|
---|
315 | {
|
---|
316 | val = "Dark ";
|
---|
317 | col -= 100;
|
---|
318 | }
|
---|
319 | if (col>150 && col<151+kCyan)
|
---|
320 | {
|
---|
321 | val = "Light ";
|
---|
322 | col -= 150;
|
---|
323 | }
|
---|
324 |
|
---|
325 | switch (col)
|
---|
326 | {
|
---|
327 | case kWhite: val += "White"; break;
|
---|
328 | case kBlack: val += "Black"; break;
|
---|
329 | case kRed: val += "Red"; break;
|
---|
330 | case kGreen: val += "Green"; break;
|
---|
331 | case kBlue: val += "Blue"; break;
|
---|
332 | case kYellow: val += "Yellow"; break;
|
---|
333 | case kMagenta: val += "Magenta"; break;
|
---|
334 | case kCyan: val += "Cyan"; break;
|
---|
335 | case 19: val += "Grey1"; break;
|
---|
336 | case 18: val += "Grey2"; break;
|
---|
337 | case 17: val += "Grey3"; break;
|
---|
338 | case 16: val += "Grey4"; break;
|
---|
339 | case 15: val += "Grey5"; break;
|
---|
340 | case 14: val += "Grey6"; break;
|
---|
341 | case 13: val += "Grey7"; break;
|
---|
342 | case 12: val += "Grey8"; break;
|
---|
343 | }
|
---|
344 |
|
---|
345 | if (val.IsNull())
|
---|
346 | val += col;
|
---|
347 |
|
---|
348 | SetValue(name, val);
|
---|
349 | }
|
---|
350 |
|
---|
351 | //---------------------------------------------------------------------------
|
---|
352 | //
|
---|
353 | // As possible convert the alignment align into a text string which can be
|
---|
354 | // interpreted by GetAlign before setting the resource value
|
---|
355 | //
|
---|
356 | void MEnv::SetAlign(const char *name, Int_t align)
|
---|
357 | {
|
---|
358 | TString val;
|
---|
359 | if (align==22)
|
---|
360 | {
|
---|
361 | SetValue(name, "Center");
|
---|
362 | return;
|
---|
363 | }
|
---|
364 |
|
---|
365 | switch (align%10)
|
---|
366 | {
|
---|
367 | case 1: val += "Left"; break;
|
---|
368 | case 2: val += "Center"; break;
|
---|
369 | case 3: val += "Right"; break;
|
---|
370 | }
|
---|
371 |
|
---|
372 | switch (align/10)
|
---|
373 | {
|
---|
374 | case 1: val += "Bottom"; break;
|
---|
375 | case 2: val += "Center"; break;
|
---|
376 | case 3: val += "Top"; break;
|
---|
377 | }
|
---|
378 |
|
---|
379 | SetValue(name, val);
|
---|
380 | }
|
---|
381 |
|
---|
382 | //---------------------------------------------------------------------------
|
---|
383 | //
|
---|
384 | // As possible convert the fill style style into a text string which can be
|
---|
385 | // interpreted by GetFillStyle before setting the resource value
|
---|
386 | //
|
---|
387 | void MEnv::SetFillStyle(const char *name, Int_t style)
|
---|
388 | {
|
---|
389 | TString val;
|
---|
390 |
|
---|
391 | if (style>3999 && style<4101)
|
---|
392 | val = Form("%d%%", style-4000);
|
---|
393 |
|
---|
394 | switch (style)
|
---|
395 | {
|
---|
396 | case 0: val = "Hollow"; break;
|
---|
397 | case 1001: val = "Solid"; break;
|
---|
398 | case 2001: val = "Hatch"; break;
|
---|
399 | }
|
---|
400 |
|
---|
401 | if (val.IsNull())
|
---|
402 | val += style;
|
---|
403 |
|
---|
404 | SetValue(name, val);
|
---|
405 | }
|
---|
406 |
|
---|
407 | //---------------------------------------------------------------------------
|
---|
408 | //
|
---|
409 | // As possible convert the line style style into a text string which can be
|
---|
410 | // interpreted by GetLineStyle before setting the resource value
|
---|
411 | //
|
---|
412 | void MEnv::SetLineStyle(const char *name, Int_t style)
|
---|
413 | {
|
---|
414 | TString val;
|
---|
415 | switch (style)
|
---|
416 | {
|
---|
417 | case kSolid: val = "Solid"; break;
|
---|
418 | case kDashed: val = "Dashed"; break;
|
---|
419 | case kDotted: val = "Dotted"; break;
|
---|
420 | case kDashDotted: val = "DashDotted"; break;
|
---|
421 | }
|
---|
422 |
|
---|
423 | if (val.IsNull())
|
---|
424 | val += style;
|
---|
425 |
|
---|
426 | SetValue(name, val);
|
---|
427 | }
|
---|
428 |
|
---|
429 | //---------------------------------------------------------------------------
|
---|
430 | //
|
---|
431 | // As possible convert the marker style style into a text string which can be
|
---|
432 | // interpreted by GetLineStyle before setting the resource value
|
---|
433 | //
|
---|
434 | void MEnv::SetMarkerStyle(const char *name, Int_t style)
|
---|
435 | {
|
---|
436 | TString val;
|
---|
437 | switch (style)
|
---|
438 | {
|
---|
439 | case kDot: val = "dot";
|
---|
440 | case kPlus: val = "plus";
|
---|
441 | case kCircle: val = "circle";
|
---|
442 | case kMultiply: val = "multiply";
|
---|
443 | case kFullDotSmall: val = "fulldotsmall";
|
---|
444 | case kFullDotMedium: val = "fulldotmedium";
|
---|
445 | case kFullDotLarge: val = "fulldotlarge";
|
---|
446 | case kOpenTriangleDown: val = "opentriangledown";
|
---|
447 | case kFullCross: val = "fullcross";
|
---|
448 | case kFullCircle: val = "fullcircle";
|
---|
449 | case kFullSquare: val = "fullsquare";
|
---|
450 | case kFullTriangleDown: val = "fulltriangledown";
|
---|
451 | case kOpenCircle: val = "opencircle";
|
---|
452 | case kOpenSquare: val = "opensquare";
|
---|
453 | case kOpenTriangleUp: val = "opentriangleup";
|
---|
454 | case kOpenDiamond: val = "opendiamond";
|
---|
455 | case kOpenCross: val = "opencross";
|
---|
456 | case kFullStar: val = "fullstar";
|
---|
457 | case kOpenStar: val = "openstar";
|
---|
458 | }
|
---|
459 |
|
---|
460 | if (val.IsNull())
|
---|
461 | val += style;
|
---|
462 |
|
---|
463 | SetValue(name, val);
|
---|
464 | }
|
---|
465 |
|
---|
466 | //---------------------------------------------------------------------------
|
---|
467 | //
|
---|
468 | // Get the attributed from a TAttLine (if dftl is given use it as default)
|
---|
469 | // name.LineColor <see also GetColor>
|
---|
470 | // name.LineStyle
|
---|
471 | // name.LineWidth
|
---|
472 | // For more details on the meaning see TAttLine
|
---|
473 | //
|
---|
474 | void MEnv::GetAttLine(const char *name, TAttLine &line, TAttLine *dftl)
|
---|
475 | {
|
---|
476 | const TString color = Compile(name, "LineColor");
|
---|
477 | const TString style = Compile(name, "LineStyle");
|
---|
478 | const TString width = Compile(name, "LineWidth");
|
---|
479 |
|
---|
480 | if (!dftl)
|
---|
481 | dftl = &line;
|
---|
482 |
|
---|
483 | const Color_t col = GetColor(color, dftl->GetLineColor());
|
---|
484 | const Style_t sty = GetLineStyle(style, dftl->GetLineStyle());
|
---|
485 | const Style_t wid = GetValue(width, dftl->GetLineWidth());
|
---|
486 |
|
---|
487 | line.SetLineColor(col);
|
---|
488 | line.SetLineStyle(sty);
|
---|
489 | line.SetLineWidth(wid);
|
---|
490 | }
|
---|
491 |
|
---|
492 | //---------------------------------------------------------------------------
|
---|
493 | //
|
---|
494 | // Get the attributed from a TAttText (if dftl is given use it as default)
|
---|
495 | // name.TextColor <see also GetColor>
|
---|
496 | // name.TextAlign <see also GetAlign>
|
---|
497 | // name.TextAngle
|
---|
498 | // name.TextFont
|
---|
499 | // name.TextSize
|
---|
500 | // For more details on the meaning see TAttText
|
---|
501 | //
|
---|
502 | void MEnv::GetAttText(const char *name, TAttText &text, TAttText *dftl)
|
---|
503 | {
|
---|
504 | const TString color = Compile(name, "TextColor");
|
---|
505 | const TString align = Compile(name, "TextAlign");
|
---|
506 | const TString angle = Compile(name, "TextAngle");
|
---|
507 | const TString font = Compile(name, "TextFont");
|
---|
508 | const TString size = Compile(name, "TextSize");
|
---|
509 |
|
---|
510 | if (!dftl)
|
---|
511 | dftl = &text;
|
---|
512 |
|
---|
513 | const Color_t col = GetColor(color, dftl->GetTextColor());
|
---|
514 | const Short_t ali = GetAlign(align, dftl->GetTextAlign());
|
---|
515 | const Float_t ang = GetValue(angle, dftl->GetTextAngle());
|
---|
516 | const Font_t fon = GetValue(font, dftl->GetTextFont());
|
---|
517 | const Float_t siz = GetValue(size, dftl->GetTextSize());
|
---|
518 |
|
---|
519 | text.SetTextColor(col);
|
---|
520 | text.SetTextAlign(ali);
|
---|
521 | text.SetTextAngle(ang);
|
---|
522 | text.SetTextFont(fon);
|
---|
523 | text.SetTextSize(siz);
|
---|
524 | }
|
---|
525 |
|
---|
526 | //---------------------------------------------------------------------------
|
---|
527 | //
|
---|
528 | // Get the attributed from a TAttFill (if dftl is given use it as default)
|
---|
529 | // name.FillColor <see also GetColor>
|
---|
530 | // name.FillStyle <see also GetFillStyle>
|
---|
531 | // For more details on the meaning see TAttFill
|
---|
532 | //
|
---|
533 | void MEnv::GetAttFill(const char *name, TAttFill &fill, TAttFill *dftl)
|
---|
534 | {
|
---|
535 | const TString color = Compile(name, "FillColor");
|
---|
536 | const TString style = Compile(name, "FillStyle");
|
---|
537 |
|
---|
538 | if (!dftl)
|
---|
539 | dftl = &fill;
|
---|
540 |
|
---|
541 | const Color_t col = GetColor(color, dftl->GetFillColor());
|
---|
542 | const Style_t sty = GetFillStyle(style, dftl->GetFillStyle());
|
---|
543 |
|
---|
544 | fill.SetFillColor(col);
|
---|
545 | fill.SetFillStyle(sty);
|
---|
546 | }
|
---|
547 |
|
---|
548 | //---------------------------------------------------------------------------
|
---|
549 | //
|
---|
550 | // Get the attributed from a TAttMarker (if dftl is given use it as default)
|
---|
551 | // name.MarkerColor <see also GetColor>
|
---|
552 | // name.MarkerStyle
|
---|
553 | // name.MarkerSize
|
---|
554 | // For more details on the meaning see TAttMarker
|
---|
555 | //
|
---|
556 | void MEnv::GetAttMarker(const char *name, TAttMarker &marker, TAttMarker *dftl)
|
---|
557 | {
|
---|
558 | const TString color = Compile(name, "MarkerColor");
|
---|
559 | const TString style = Compile(name, "MarkerStyle");
|
---|
560 | const TString size = Compile(name, "MarkerSize");
|
---|
561 |
|
---|
562 | if (!dftl)
|
---|
563 | dftl = ▮
|
---|
564 |
|
---|
565 | const Color_t col = GetColor(color, dftl->GetMarkerColor());
|
---|
566 | const Style_t sty = GetValue(style, dftl->GetMarkerStyle());
|
---|
567 | const Size_t siz = GetValue(size, dftl->GetMarkerSize());
|
---|
568 |
|
---|
569 | marker.SetMarkerColor(col);
|
---|
570 | marker.SetMarkerStyle(sty);
|
---|
571 | marker.SetMarkerSize(siz);
|
---|
572 | }
|
---|
573 |
|
---|
574 | //---------------------------------------------------------------------------
|
---|
575 | //
|
---|
576 | // Get the attributed from a TPave (if dftl is given use it as default)
|
---|
577 | // name.CornerRadius
|
---|
578 | // name.BorderSize
|
---|
579 | // name.Option
|
---|
580 | // Also all resources from TAttLine and TAttFill are supported.
|
---|
581 | //
|
---|
582 | // For your conveinience: If the CornerRadius is greater than 0 "arc" is
|
---|
583 | // added to the options. If it is equal or less than 0 "arc" is removed
|
---|
584 | // from the options.
|
---|
585 | //
|
---|
586 | // For more details on the meaning see TPave
|
---|
587 | //
|
---|
588 | void MEnv::GetAttPave(const char *str, TPave &pave, TPave *dftl)
|
---|
589 | {
|
---|
590 | const TString post(str);
|
---|
591 |
|
---|
592 | TString name(pave.GetName());
|
---|
593 | if (!name.IsNull() && name!=pave.ClassName())
|
---|
594 | name = Compile(name, post);
|
---|
595 |
|
---|
596 | GetAttLine(name, pave, dftl);
|
---|
597 | GetAttFill(name, pave, dftl);
|
---|
598 |
|
---|
599 | const TString corner = Compile(name, "CornerRadius");
|
---|
600 | const TString border = Compile(name, "BorderSize");
|
---|
601 | const TString option = Compile(name, "Option");
|
---|
602 |
|
---|
603 | if (!dftl)
|
---|
604 | dftl = &pave;
|
---|
605 |
|
---|
606 | const Double_t cor = GetValue(corner, dftl->GetCornerRadius());
|
---|
607 | const Int_t bor = GetValue(border, dftl->GetBorderSize());
|
---|
608 |
|
---|
609 | pave.SetCornerRadius(cor);
|
---|
610 | pave.SetBorderSize(bor);
|
---|
611 |
|
---|
612 | TString opt = GetValue(option, dftl->GetOption());
|
---|
613 | opt.ToLower();
|
---|
614 |
|
---|
615 | const Bool_t has = pave.GetCornerRadius()>0;
|
---|
616 |
|
---|
617 | if (has && !opt.Contains("arc"))
|
---|
618 | opt += "arc";
|
---|
619 |
|
---|
620 | if (!has && opt.Contains("arc"))
|
---|
621 | opt.ReplaceAll("arc", "");
|
---|
622 |
|
---|
623 | pave.SetOption(opt);
|
---|
624 |
|
---|
625 | }
|
---|
626 |
|
---|
627 | //---------------------------------------------------------------------------
|
---|
628 | //
|
---|
629 | // Get the attributed for the TObject obj. Use dftl for default attributes
|
---|
630 | // if given.
|
---|
631 | //
|
---|
632 | // There is support for:
|
---|
633 | // TPave <see GetAttPave>
|
---|
634 | // TAttLine <see GetAttLine>
|
---|
635 | // TAttText <see GetAttText>
|
---|
636 | // TAttFill <see GetAttFill>
|
---|
637 | // TAttMarker <see GetAttMarker>
|
---|
638 | //
|
---|
639 | void MEnv::GetAttributes(const char *name, TObject *obj, TObject *dftl)
|
---|
640 | {
|
---|
641 | //TAttAxis *line = dynamic_cast<TAttAxis*>(obj);
|
---|
642 | //TAtt3D *line = dynamic_cast<TAtt3D*>(obj);
|
---|
643 | //TAttCanvas *line = dynamic_cast<TAttCanvas*>(obj);
|
---|
644 | //TAttFillCanvas *line = dynamic_cast<TAttFillEitor*>(obj);
|
---|
645 | //TAttLineCanvas *line = dynamic_cast<TAttLineCanvas*>(obj);
|
---|
646 | //TAttLineEditor *line = dynamic_cast<TAttLineEditor*>(obj);
|
---|
647 | //TAttMarkerCanvas *line = dynamic_cast<TAttMarkerCanvas*>(obj);
|
---|
648 | //TAttMarkerEditor *line = dynamic_cast<TAttMarkerEditor*>(obj);
|
---|
649 | //TAttPad *line = dynamic_cast<TAttPad*>(obj);
|
---|
650 | //TAttParticle *line = dynamic_cast<TAttParticle*>(obj);
|
---|
651 | //TAttTextCanvas *line = dynamic_cast<TAttTextCanvas*>(obj);
|
---|
652 | //TAttTextEditor *line = dynamic_cast<TAttTextEditor*>(obj);
|
---|
653 |
|
---|
654 | TPave *pave = dynamic_cast<TPave*>(obj);
|
---|
655 | TAttLine *line = dynamic_cast<TAttLine*>(obj);
|
---|
656 | TAttText *text = dynamic_cast<TAttText*>(obj);
|
---|
657 | TAttFill *fill = dynamic_cast<TAttFill*>(obj);
|
---|
658 | TAttMarker *mark = dynamic_cast<TAttMarker*>(obj);
|
---|
659 |
|
---|
660 | if (pave)
|
---|
661 | {
|
---|
662 | GetAttPave(name, *pave, dynamic_cast<TPave*>(dftl));
|
---|
663 | return;
|
---|
664 | }
|
---|
665 |
|
---|
666 | if (line)
|
---|
667 | GetAttLine(name, *line, dynamic_cast<TAttLine*>(dftl));
|
---|
668 | if (text)
|
---|
669 | GetAttText(name, *text, dynamic_cast<TAttText*>(dftl));
|
---|
670 | if (fill)
|
---|
671 | GetAttFill(name, *fill, dynamic_cast<TAttFill*>(dftl));
|
---|
672 | if (mark)
|
---|
673 | GetAttMarker(name, *mark, dynamic_cast<TAttMarker*>(dftl));
|
---|
674 | }
|
---|
675 |
|
---|
676 | //---------------------------------------------------------------------------
|
---|
677 | //
|
---|
678 | // Set the resources from a TAttLine:
|
---|
679 | // name.LineColor <see also SetColor>
|
---|
680 | // name.LineStyle
|
---|
681 | // name.LineWidth
|
---|
682 | //
|
---|
683 | void MEnv::SetAttLine(const char *name, const TAttLine &line)
|
---|
684 | {
|
---|
685 | const TString color = Compile(name, "LineColor");
|
---|
686 | const TString style = Compile(name, "LineStyle");
|
---|
687 | const TString width = Compile(name, "LineWidth");
|
---|
688 |
|
---|
689 | SetColor(color, line.GetLineColor());
|
---|
690 | SetLineStyle(style, line.GetLineStyle());
|
---|
691 | SetValue(width, line.GetLineWidth());
|
---|
692 | }
|
---|
693 |
|
---|
694 | //---------------------------------------------------------------------------
|
---|
695 | //
|
---|
696 | // Set the resources from a TAttText:
|
---|
697 | // name.TextColor <see also SetColor>
|
---|
698 | // name.TextAlign <see also SetAlign>
|
---|
699 | // name.TextAngle
|
---|
700 | // name.TextFont
|
---|
701 | // name.TextSize
|
---|
702 | //
|
---|
703 | void MEnv::SetAttText(const char *name, const TAttText &text)
|
---|
704 | {
|
---|
705 | const TString color = Compile(name, "TextColor");
|
---|
706 | const TString align = Compile(name, "TextAlign");
|
---|
707 | const TString angle = Compile(name, "TextAngle");
|
---|
708 | const TString font = Compile(name, "TextFont");
|
---|
709 | const TString size = Compile(name, "TextSize");
|
---|
710 |
|
---|
711 | SetColor(color, text.GetTextColor());
|
---|
712 | SetAlign(align, text.GetTextAlign());
|
---|
713 | SetValue(angle, text.GetTextAngle());
|
---|
714 | SetValue(font, text.GetTextFont());
|
---|
715 | SetValue(size, text.GetTextSize());
|
---|
716 | }
|
---|
717 |
|
---|
718 | //---------------------------------------------------------------------------
|
---|
719 | //
|
---|
720 | // Set the resources from a TAttFill:
|
---|
721 | // name.FillColor <see also SetColor>
|
---|
722 | // name.FillStyle <see also SetFillStyle>
|
---|
723 | //
|
---|
724 | void MEnv::SetAttFill(const char *name, const TAttFill &fill)
|
---|
725 | {
|
---|
726 | const TString color = Compile(name, "FillColor");
|
---|
727 | const TString style = Compile(name, "FillStyle");
|
---|
728 |
|
---|
729 | SetColor(color, fill.GetFillColor());
|
---|
730 | SetFillStyle(style, fill.GetFillStyle());
|
---|
731 | }
|
---|
732 |
|
---|
733 | //---------------------------------------------------------------------------
|
---|
734 | //
|
---|
735 | // Set the resources from a TAttMarker:
|
---|
736 | // name.MarkerColor <see also SetColor>
|
---|
737 | // name.MarkerStyle
|
---|
738 | // name.MarkerSize
|
---|
739 | //
|
---|
740 | void MEnv::SetAttMarker(const char *name, const TAttMarker &marker)
|
---|
741 | {
|
---|
742 | const TString color = Compile(name, "MarkerColor");
|
---|
743 | const TString style = Compile(name, "MarkerStyle");
|
---|
744 | const TString size = Compile(name, "MarkerSize");
|
---|
745 |
|
---|
746 | SetColor(color, marker.GetMarkerColor());
|
---|
747 | SetMarkerStyle(style, marker.GetMarkerStyle());
|
---|
748 | SetValue(size, marker.GetMarkerSize());
|
---|
749 | }
|
---|
750 |
|
---|
751 | //---------------------------------------------------------------------------
|
---|
752 | //
|
---|
753 | // Set the resources from a TPave:
|
---|
754 | // name.CornerRadius
|
---|
755 | // name.BorderSize
|
---|
756 | // name.Option
|
---|
757 | // Also all resources from TAttLine and TAttFill are supported.
|
---|
758 | //
|
---|
759 | void MEnv::SetAttPave(const char *str, const TPave &pave)
|
---|
760 | {
|
---|
761 | const TString name(str);
|
---|
762 |
|
---|
763 | SetAttLine(name, pave);
|
---|
764 | SetAttFill(name, pave);
|
---|
765 |
|
---|
766 | const TString corner = Compile(name, "CornerRadius");
|
---|
767 | const TString border = Compile(name, "BorderSize");
|
---|
768 | const TString option = Compile(name, "Option");
|
---|
769 |
|
---|
770 | SetValue(corner, const_cast<TPave&>(pave).GetCornerRadius());
|
---|
771 | SetValue(border, const_cast<TPave&>(pave).GetBorderSize());
|
---|
772 | SetValue(option, pave.GetOption());
|
---|
773 | }
|
---|
774 |
|
---|
775 | //---------------------------------------------------------------------------
|
---|
776 | //
|
---|
777 | // Set the attributed for the TObject obj.
|
---|
778 | //
|
---|
779 | // There is support for:
|
---|
780 | // TPave <see SetAttPave>
|
---|
781 | // TAttLine <see SetAttLine>
|
---|
782 | // TAttText <see SetAttText>
|
---|
783 | // TAttFill <see SetAttFill>
|
---|
784 | // TAttMarker <see SetAttMarker>
|
---|
785 | //
|
---|
786 | void MEnv::SetAttributes(const char *name, const TObject *obj)
|
---|
787 | {
|
---|
788 | const TPave *pave = dynamic_cast<const TPave*>(obj);
|
---|
789 | const TAttLine *line = dynamic_cast<const TAttLine*>(obj);
|
---|
790 | const TAttText *text = dynamic_cast<const TAttText*>(obj);
|
---|
791 | const TAttFill *fill = dynamic_cast<const TAttFill*>(obj);
|
---|
792 | const TAttMarker *mark = dynamic_cast<const TAttMarker*>(obj);
|
---|
793 |
|
---|
794 | if (pave)
|
---|
795 | {
|
---|
796 | SetAttPave(name, *pave);
|
---|
797 | return;
|
---|
798 | }
|
---|
799 |
|
---|
800 | if (line)
|
---|
801 | SetAttLine(name, *line);
|
---|
802 | if (text)
|
---|
803 | SetAttText(name, *text);
|
---|
804 | if (fill)
|
---|
805 | SetAttFill(name, *fill);
|
---|
806 | if (mark)
|
---|
807 | SetAttMarker(name, *mark);
|
---|
808 | }
|
---|
809 |
|
---|
810 | //---------------------------------------------------------------------------
|
---|
811 | //
|
---|
812 | // Add all values from TEnv env the this MEnv. To not overwrite existing
|
---|
813 | // values set overwrite to kFALSE
|
---|
814 | //
|
---|
815 | void MEnv::AddEnv(const TEnv &env, Bool_t overwrite)
|
---|
816 | {
|
---|
817 | if (!GetTable() || !env.GetTable())
|
---|
818 | return;
|
---|
819 |
|
---|
820 | TIter Next(env.GetTable());
|
---|
821 |
|
---|
822 | TEnvRec *er;
|
---|
823 | while ((er = (TEnvRec*)Next()))
|
---|
824 | {
|
---|
825 | if (overwrite || !Defined(er->GetName()))
|
---|
826 | SetValue(er->GetName(), er->GetValue(), er->GetLevel(), er->GetType());
|
---|
827 | }
|
---|
828 | }
|
---|
829 |
|
---|
830 | //---------------------------------------------------------------------------
|
---|
831 | //
|
---|
832 | // Print resources which have never been touched (for debugging)
|
---|
833 | //
|
---|
834 | void MEnv::PrintUntouched() const
|
---|
835 | {
|
---|
836 | int i=0;
|
---|
837 | gLog << inf << flush;
|
---|
838 | gLog.Separator("Untouched Resources");
|
---|
839 | TIter Next(GetTable());
|
---|
840 | TObject *o=0;
|
---|
841 |
|
---|
842 | while ((o=Next()))
|
---|
843 | if (!fChecked.FindObject(o->GetName()))
|
---|
844 | {
|
---|
845 | gLog << warn << " - Resource " << o->GetName() << " not touched" << endl;
|
---|
846 | i++;
|
---|
847 | }
|
---|
848 | if (i==0)
|
---|
849 | gLog << inf << "None." << endl;
|
---|
850 | else
|
---|
851 | gLog << inf << i << " resources have not been touched." << endl;
|
---|
852 | }
|
---|
853 |
|
---|
854 | //---------------------------------------------------------------------------
|
---|
855 | //
|
---|
856 | // Return number of resources which have not been touched.
|
---|
857 | //
|
---|
858 | Int_t MEnv::GetNumUntouched() const
|
---|
859 | {
|
---|
860 | int i=0;
|
---|
861 | TIter Next(GetTable());
|
---|
862 | TObject *o=0;
|
---|
863 | while ((o=Next()))
|
---|
864 | if (!fChecked.FindObject(o->GetName()))
|
---|
865 | i++;
|
---|
866 | return i;
|
---|
867 | }
|
---|