source: trunk/MagicSoft/Mars/mbase/MEnv.cc@ 8731

Last change on this file since 8731 was 8731, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 29.3 KB
Line 
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-2007
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// A new special resource is available. With the resource "Include"
34// you can include resources from other files, for example
35//
36// Include: file1.rc file2.rc
37//
38// Including can be done recursively. Resources from the included files
39// have lower priority. This allows to write a resource file with your
40// default resources which then can be included in other files overwriting
41// some of the resources.
42//
43// If given paths are not absolute there base is always th elocation of
44// the including file.
45//
46//////////////////////////////////////////////////////////////////////////////
47#include "MEnv.h"
48
49#include <Gtypes.h>
50#include <TObjString.h>
51
52#include <TPave.h>
53#include <TAttText.h>
54#include <TAttMarker.h>
55#include <THashList.h> // needed since root v5.10/00 (TEnv::GetTable)
56
57#include "MLog.h"
58#include "MLogManip.h"
59
60ClassImp(MEnv);
61
62using namespace std;
63
64//---------------------------------------------------------------------------
65//
66// (Default) constructor. If the given file cannot be accessed SetRcName("")
67// is called which can then be checked by IsValid()
68//
69MEnv::MEnv(const char *name) : TEnv(name)
70{
71 fChecked.SetOwner();
72
73 // If TEnv::TEnv has not set fRcName
74 if (!IsValid())
75 return;
76
77 // ExpandPathName (not done by TEnv::TEnv) and read again
78 TString fname(name);
79 gSystem->ExpandPathName(fname);
80
81 // Is file accessible
82 if (gSystem->AccessPathName(fname, kFileExists))
83 fname = "";
84
85 SetRcName(fname);
86
87 // No file found
88 if (fname.IsNull())
89 return;
90
91 // File has been already processed, but ReadInclude is part of a
92 // derived function, i.e. not yet executed.
93 if (GetEntries()>0 || fname==name)
94 {
95 if (ReadInclude()<0)
96 SetRcName("");
97 return;
98 }
99
100 // File not yet processed. Reread file.
101 if (ReadFile(fname, kEnvLocal)<0)
102 SetRcName("");
103}
104
105//---------------------------------------------------------------------------
106//
107// Process an Include directive and read the corresponding contents
108//
109Int_t MEnv::ReadInclude()
110{
111 // Check for "Include" resource
112 const TString incl = GetValue("Include", "");
113 if (incl.IsNull())
114 return 0;
115
116 const char *dir = gSystem->DirName(GetRcName());
117
118 // Tokenize the array into single files divided by a whitespace
119 TObjArray *arr = incl.Tokenize(" ");
120
121 // We have to rebuild the Include array from scratch to get the
122 // correct sorting for a possible rereading.
123 SetValue("Include", "");
124
125 // FIXME: Make sure that recursions don't crash the system!
126
127 for (int i=0; i<arr->GetEntries(); i++)
128 {
129 // Get file name to include
130 TString fenv = (*arr)[i]->GetName();
131
132 // If the is not anabsolute path we prepend the dir-name
133 // of the including file. This allows that includes
134 // do not necessarily need absolute paths and paths are always
135 // relative to the location of th eincluding file.
136 if (!gSystem->IsAbsoluteFileName(fenv))
137 {
138 fenv.Prepend("/");
139 fenv.Prepend(dir);
140 }
141
142 // Read included file and check if its valid
143 const MEnv env(fenv);
144 if (!env.IsValid())
145 {
146 delete arr;
147 return -1;
148 }
149
150 // Add file name before its childs
151 SetValue("+Include", fenv);
152
153 // If it is valid add entries from include without overwriting,
154 // i.e. the included resources have lower priority
155 AddEnv(env, kFALSE);
156
157 // Get a possible child include from env
158 const TString incl2 = const_cast<MEnv&>(env).GetValue("Include", "");
159 if (!incl2.IsNull())
160 SetValue("+Include", incl2);
161 }
162
163 delete arr;
164
165 // Get final compiled resource
166 TString inc = GetValue("Include", "");
167
168 // Remove obsolete whitespaces for convinience
169 inc.ReplaceAll(" ", " ");
170 inc = inc.Strip(TString::kBoth);
171
172 // Set final resource, now as kEnvLocal (previously set as kEnvChnaged)
173 SetValue("Include", inc, kEnvLocal);
174
175 // FIXME: Remove douplets in the correct order
176
177 return 0;
178}
179
180//---------------------------------------------------------------------------
181//
182// Read and parse the resource file for a certain level.
183// Returns -1 on case of error, 0 in case of success.
184//
185// Check for an include directive
186//
187Int_t MEnv::ReadFile(const char *fname, EEnvLevel level)
188{
189 // First read the file via TEnv
190 if (TEnv::ReadFile(fname, level)<0)
191 return -1;
192
193 return ReadInclude();
194}
195
196//---------------------------------------------------------------------------
197//
198// Make sure that the name used for writing doesn't contain a full path
199//
200const char *MEnv::GetName() const
201{
202 const char *pos = strrchr(GetRcName(), '/');
203 return pos>0 ? pos+1 : GetRcName();
204}
205
206//---------------------------------------------------------------------------
207//
208// Return the total number of entries in the table
209//
210Int_t MEnv::GetEntries() const
211{
212 if (!GetTable())
213 return -1;
214
215 return GetTable()->GetEntries();
216}
217
218//---------------------------------------------------------------------------
219//
220// Compile str+post and make sure that in between there is a unique dot.
221//
222TString MEnv::Compile(TString str, const char *post) const
223{
224 if (!str.IsNull() && !str.EndsWith("."))
225 str += ".";
226
227 str += post;
228
229 return str;
230}
231
232//---------------------------------------------------------------------------
233//
234// Get the value from the table and remember the value as checked
235//
236Int_t MEnv::GetValue(const char *name, Int_t dflt)
237{
238 if (!fChecked.FindObject(name))
239 fChecked.Add(new TObjString(name));
240 return TEnv::GetValue(name, dflt);
241}
242
243//---------------------------------------------------------------------------
244//
245// Get the value from the table and remember the value as checked
246//
247Double_t MEnv::GetValue(const char *name, Double_t dflt)
248{
249 if (!fChecked.FindObject(name))
250 fChecked.Add(new TObjString(name));
251 return TEnv::GetValue(name, dflt);
252}
253
254//---------------------------------------------------------------------------
255//
256// Get the value from the table and remember the value as checked
257//
258const char *MEnv::GetValue(const char *name, const char *dflt)
259{
260 if (!fChecked.FindObject(name))
261 fChecked.Add(new TObjString(name));
262 return TEnv::GetValue(name, dflt);
263}
264
265//---------------------------------------------------------------------------
266//
267// TEnv doen't have a streamer --> cannot be cloned
268// --> we have to clone it ourself
269//
270TObject *MEnv::Clone(const char *) const
271{
272 MEnv *env = new MEnv("/dev/null");
273 env->SetRcName(GetRcName());
274 env->AddEnv(*this);
275 return env;
276}
277
278//---------------------------------------------------------------------------
279//
280// Interprete fill style: Hollow, Solid, Hatch, 0%-100%
281// If no text style is detected the value is converted to an integer.
282//
283Int_t MEnv::GetFillStyle(const char *name, Int_t dftl)
284{
285 TString str = GetValue(name, "");
286 str = str.Strip(TString::kBoth);
287 if (str.IsNull())
288 return dftl;
289
290 str.ToLower();
291
292 switch (str.Hash())
293 {
294 case 2374867578U: return 0; // hollow
295 case 764279305U: return 1001; // solid
296 case 1854683492U: return 2001; // hatch
297 }
298
299 return str.EndsWith("%") ? 4000+str.Atoi() : str.Atoi();
300}
301
302//---------------------------------------------------------------------------
303//
304// Interprete line style: Solid, Dashed, Dotted, DashDotted
305// If no line style is detected the value is converted to an integer.
306//
307Int_t MEnv::GetLineStyle(const char *name, Int_t dftl)
308{
309 TString str = GetValue(name, "");
310 str = str.Strip(TString::kBoth);
311 if (str.IsNull())
312 return dftl;
313
314 str.ToLower();
315
316 switch (str.Hash())
317 {
318 case 764279305U: return kSolid;
319 case 241979881U: return kDashed;
320 case 2391642602U: return kDotted;
321 case 1124931659U: return kDashDotted;
322 }
323
324 return str.Atoi();
325}
326
327//---------------------------------------------------------------------------
328//
329// Interprete alignment: Top, Right, Left, Bottom, Center, tr, cc, bl, ...
330// If no text align is detected the value is converted to an integer.
331//
332// eg.
333// Top Right
334// Bottom Center
335// Center
336// tr
337// br
338// cr
339//
340Int_t MEnv::GetAlign(const char *name, Int_t dftl)
341{
342 TString str = GetValue(name, "");
343 str = str.Strip(TString::kBoth);
344 if (str.IsNull())
345 return dftl;
346
347 str.ToLower();
348
349 switch (str.Hash())
350 {
351 case 29746: return 33; // tr
352 case 25379: return 22; // cc
353 case 25132: return 11; // bl
354
355 case 25388: return 12; // cl
356 case 25394: return 32; // cr
357
358 case 29731: return 23; // tc
359 case 25123: return 32; // bc
360
361 case 29740: return 13; // tl
362 case 25138: return 13; // br
363 }
364
365 Int_t align = 0;
366 if (str.Contains("right", TString::kIgnoreCase))
367 align += 3;
368 if (str.Contains("left", TString::kIgnoreCase))
369 align += 1;
370 if (str.Contains("bottom", TString::kIgnoreCase))
371 align += 10;
372 if (str.Contains("top", TString::kIgnoreCase))
373 align += 30;
374
375 if (str.Contains("center", TString::kIgnoreCase))
376 {
377 if (align==0)
378 return 22;
379 if (align/10==0)
380 return align+20;
381 if (align%10==0)
382 return align+2;
383 }
384
385 return align>0 ? align : str.Atoi();
386}
387
388//---------------------------------------------------------------------------
389//
390// Interprete color: Black, White, Red, Green, Blue, Yellow, Magenta,
391// Cyan, Gray1-5, Grey1-5.
392// If no text color is detected the value is converted to an integer.
393//
394// eg.
395// Red
396// Light Red
397// Dark Red
398//
399Int_t MEnv::GetColor(const char *name, Int_t dftl)
400{
401 TString str = GetValue(name, "");
402
403 str = str.Strip(TString::kBoth);
404 if (str.IsNull())
405 return dftl;
406
407 str.ToLower();
408
409 Int_t offset=0;
410 if (str.Contains("dark"))
411 {
412 str.ReplaceAll("dark", "");
413 str = str.Strip(TString::kBoth);
414 offset = 100;
415 }
416 if (str.Contains("light"))
417 {
418 str.ReplaceAll("light", "");
419 str = str.Strip(TString::kBoth);
420 offset = 150;
421 }
422
423 switch (str.Hash())
424 {
425 case 2368543371U: return kWhite+offset;
426 case 1814927399U: return kBlack+offset;
427 case 7496964U: return kRed+offset;
428 case 2897107074U: return kGreen+offset;
429 case 1702194402U: return kBlue+offset;
430 case 2374817882U: return kYellow+offset;
431 case 2894218701U: return kMagenta+offset;
432 case 1851881955U: return kCyan+offset;
433 case 749623518U: return 19; // grey1
434 case 749623517U: return 18; // grey2
435 case 749623516U: return 17; // grey3
436 case 749623515U: return 16; // grey4
437 case 749623514U: return 15; // grey5
438 case 749623513U: return 14; // grey6
439 case 749623512U: return 13; // grey7
440 case 749623511U: return 12; // grey8
441 case 741234910U: return 19; // gray1
442 case 741234909U: return 18; // gray2
443 case 741234908U: return 17; // gray3
444 case 741234907U: return 16; // gray4
445 case 741234906U: return 15; // gray5
446 case 741234905U: return 14; // gray6
447 case 741234904U: return 13; // gray7
448 case 741234903U: return 12; // gray8
449 }
450 return str.Atoi();
451}
452
453//---------------------------------------------------------------------------
454//
455// As possible convert the color col into a text string which can be
456// interpreted by GetColor before setting the resource value
457//
458void MEnv::SetColor(const char *name, Int_t col)
459{
460 TString val;
461
462 if (col>99 && col<101+kCyan)
463 {
464 val = "Dark ";
465 col -= 100;
466 }
467 if (col>150 && col<151+kCyan)
468 {
469 val = "Light ";
470 col -= 150;
471 }
472
473 switch (col)
474 {
475 case kWhite: val += "White"; break;
476 case kBlack: val += "Black"; break;
477 case kRed: val += "Red"; break;
478 case kGreen: val += "Green"; break;
479 case kBlue: val += "Blue"; break;
480 case kYellow: val += "Yellow"; break;
481 case kMagenta: val += "Magenta"; break;
482 case kCyan: val += "Cyan"; break;
483 case 19: val += "Grey1"; break;
484 case 18: val += "Grey2"; break;
485 case 17: val += "Grey3"; break;
486 case 16: val += "Grey4"; break;
487 case 15: val += "Grey5"; break;
488 case 14: val += "Grey6"; break;
489 case 13: val += "Grey7"; break;
490 case 12: val += "Grey8"; break;
491 }
492
493 if (val.IsNull())
494 val += col;
495
496 SetValue(name, val);
497}
498
499//---------------------------------------------------------------------------
500//
501// As possible convert the alignment align into a text string which can be
502// interpreted by GetAlign before setting the resource value
503//
504void MEnv::SetAlign(const char *name, Int_t align)
505{
506 TString val;
507 if (align==22)
508 {
509 SetValue(name, "Center");
510 return;
511 }
512
513 switch (align%10)
514 {
515 case 1: val += "Left"; break;
516 case 2: val += "Center"; break;
517 case 3: val += "Right"; break;
518 }
519
520 switch (align/10)
521 {
522 case 1: val += "Bottom"; break;
523 case 2: val += "Center"; break;
524 case 3: val += "Top"; break;
525 }
526
527 SetValue(name, val);
528}
529
530//---------------------------------------------------------------------------
531//
532// As possible convert the fill style style into a text string which can be
533// interpreted by GetFillStyle before setting the resource value
534//
535void MEnv::SetFillStyle(const char *name, Int_t style)
536{
537 TString val;
538
539 if (style>3999 && style<4101)
540 val = Form("%d%%", style-4000);
541
542 switch (style)
543 {
544 case 0: val = "Hollow"; break;
545 case 1001: val = "Solid"; break;
546 case 2001: val = "Hatch"; break;
547 }
548
549 if (val.IsNull())
550 val += style;
551
552 SetValue(name, val);
553}
554
555//---------------------------------------------------------------------------
556//
557// As possible convert the line style style into a text string which can be
558// interpreted by GetLineStyle before setting the resource value
559//
560void MEnv::SetLineStyle(const char *name, Int_t style)
561{
562 TString val;
563 switch (style)
564 {
565 case kSolid: val = "Solid"; break;
566 case kDashed: val = "Dashed"; break;
567 case kDotted: val = "Dotted"; break;
568 case kDashDotted: val = "DashDotted"; break;
569 }
570
571 if (val.IsNull())
572 val += style;
573
574 SetValue(name, val);
575}
576
577//---------------------------------------------------------------------------
578//
579// As possible convert the marker style style into a text string which can be
580// interpreted by GetLineStyle before setting the resource value
581//
582void MEnv::SetMarkerStyle(const char *name, Int_t style)
583{
584 TString val;
585 switch (style)
586 {
587 case kDot: val = "dot";
588 case kPlus: val = "plus";
589 case kCircle: val = "circle";
590 case kMultiply: val = "multiply";
591 case kFullDotSmall: val = "fulldotsmall";
592 case kFullDotMedium: val = "fulldotmedium";
593 case kFullDotLarge: val = "fulldotlarge";
594 case kOpenTriangleDown: val = "opentriangledown";
595 case kFullCross: val = "fullcross";
596 case kFullCircle: val = "fullcircle";
597 case kFullSquare: val = "fullsquare";
598 case kFullTriangleDown: val = "fulltriangledown";
599 case kOpenCircle: val = "opencircle";
600 case kOpenSquare: val = "opensquare";
601 case kOpenTriangleUp: val = "opentriangleup";
602 case kOpenDiamond: val = "opendiamond";
603 case kOpenCross: val = "opencross";
604 case kFullStar: val = "fullstar";
605 case kOpenStar: val = "openstar";
606 }
607
608 if (val.IsNull())
609 val += style;
610
611 SetValue(name, val);
612}
613
614//---------------------------------------------------------------------------
615//
616// Get the attributed from a TAttLine (if dftl is given use it as default)
617// name.LineColor <see also GetColor>
618// name.LineStyle
619// name.LineWidth
620// For more details on the meaning see TAttLine
621//
622void MEnv::GetAttLine(const char *name, TAttLine &line, TAttLine *dftl)
623{
624 const TString color = Compile(name, "LineColor");
625 const TString style = Compile(name, "LineStyle");
626 const TString width = Compile(name, "LineWidth");
627
628 if (!dftl)
629 dftl = &line;
630
631 const Color_t col = GetColor(color, dftl->GetLineColor());
632 const Style_t sty = GetLineStyle(style, dftl->GetLineStyle());
633 const Style_t wid = GetValue(width, dftl->GetLineWidth());
634
635 line.SetLineColor(col);
636 line.SetLineStyle(sty);
637 line.SetLineWidth(wid);
638}
639
640//---------------------------------------------------------------------------
641//
642// Get the attributed from a TAttText (if dftl is given use it as default)
643// name.TextColor <see also GetColor>
644// name.TextAlign <see also GetAlign>
645// name.TextAngle
646// name.TextFont
647// name.TextSize
648// For more details on the meaning see TAttText
649//
650void MEnv::GetAttText(const char *name, TAttText &text, TAttText *dftl)
651{
652 const TString color = Compile(name, "TextColor");
653 const TString align = Compile(name, "TextAlign");
654 const TString angle = Compile(name, "TextAngle");
655 const TString font = Compile(name, "TextFont");
656 const TString size = Compile(name, "TextSize");
657
658 if (!dftl)
659 dftl = &text;
660
661 const Color_t col = GetColor(color, dftl->GetTextColor());
662 const Short_t ali = GetAlign(align, dftl->GetTextAlign());
663 const Float_t ang = GetValue(angle, dftl->GetTextAngle());
664 const Font_t fon = GetValue(font, dftl->GetTextFont());
665 const Float_t siz = GetValue(size, dftl->GetTextSize());
666
667 text.SetTextColor(col);
668 text.SetTextAlign(ali);
669 text.SetTextAngle(ang);
670 text.SetTextFont(fon);
671 text.SetTextSize(siz);
672}
673
674//---------------------------------------------------------------------------
675//
676// Get the attributed from a TAttFill (if dftl is given use it as default)
677// name.FillColor <see also GetColor>
678// name.FillStyle <see also GetFillStyle>
679// For more details on the meaning see TAttFill
680//
681void MEnv::GetAttFill(const char *name, TAttFill &fill, TAttFill *dftl)
682{
683 const TString color = Compile(name, "FillColor");
684 const TString style = Compile(name, "FillStyle");
685
686 if (!dftl)
687 dftl = &fill;
688
689 const Color_t col = GetColor(color, dftl->GetFillColor());
690 const Style_t sty = GetFillStyle(style, dftl->GetFillStyle());
691
692 fill.SetFillColor(col);
693 fill.SetFillStyle(sty);
694}
695
696//---------------------------------------------------------------------------
697//
698// Get the attributed from a TAttMarker (if dftl is given use it as default)
699// name.MarkerColor <see also GetColor>
700// name.MarkerStyle
701// name.MarkerSize
702// For more details on the meaning see TAttMarker
703//
704void MEnv::GetAttMarker(const char *name, TAttMarker &marker, TAttMarker *dftl)
705{
706 const TString color = Compile(name, "MarkerColor");
707 const TString style = Compile(name, "MarkerStyle");
708 const TString size = Compile(name, "MarkerSize");
709
710 if (!dftl)
711 dftl = &marker;
712
713 const Color_t col = GetColor(color, dftl->GetMarkerColor());
714 const Style_t sty = GetValue(style, dftl->GetMarkerStyle());
715 const Size_t siz = GetValue(size, dftl->GetMarkerSize());
716
717 marker.SetMarkerColor(col);
718 marker.SetMarkerStyle(sty);
719 marker.SetMarkerSize(siz);
720}
721
722//---------------------------------------------------------------------------
723//
724// Get the attributed from a TPave (if dftl is given use it as default)
725// name.CornerRadius
726// name.BorderSize
727// name.Option
728// Also all resources from TAttLine and TAttFill are supported.
729//
730// For your conveinience: If the CornerRadius is greater than 0 "arc" is
731// added to the options. If it is equal or less than 0 "arc" is removed
732// from the options.
733//
734// For more details on the meaning see TPave
735//
736void MEnv::GetAttPave(const char *str, TPave &pave, TPave *dftl)
737{
738 const TString post(str);
739
740 TString name(pave.GetName());
741 if (!name.IsNull() && name!=pave.ClassName())
742 name = Compile(name, post);
743
744 GetAttLine(name, pave, dftl);
745 GetAttFill(name, pave, dftl);
746
747 const TString corner = Compile(name, "CornerRadius");
748 const TString border = Compile(name, "BorderSize");
749 const TString option = Compile(name, "Option");
750
751 if (!dftl)
752 dftl = &pave;
753
754 const Double_t cor = GetValue(corner, dftl->GetCornerRadius());
755 const Int_t bor = GetValue(border, dftl->GetBorderSize());
756
757 pave.SetCornerRadius(cor);
758 pave.SetBorderSize(bor);
759
760 TString opt = GetValue(option, dftl->GetOption());
761 opt.ToLower();
762
763 const Bool_t has = pave.GetCornerRadius()>0;
764
765 if (has && !opt.Contains("arc"))
766 opt += "arc";
767
768 if (!has && opt.Contains("arc"))
769 opt.ReplaceAll("arc", "");
770
771 pave.SetOption(opt);
772
773}
774
775//---------------------------------------------------------------------------
776//
777// Get the attributed for the TObject obj. Use dftl for default attributes
778// if given.
779//
780// There is support for:
781// TPave <see GetAttPave>
782// TAttLine <see GetAttLine>
783// TAttText <see GetAttText>
784// TAttFill <see GetAttFill>
785// TAttMarker <see GetAttMarker>
786//
787void MEnv::GetAttributes(const char *name, TObject *obj, TObject *dftl)
788{
789 //TAttAxis *line = dynamic_cast<TAttAxis*>(obj);
790 //TAtt3D *line = dynamic_cast<TAtt3D*>(obj);
791 //TAttCanvas *line = dynamic_cast<TAttCanvas*>(obj);
792 //TAttFillCanvas *line = dynamic_cast<TAttFillEitor*>(obj);
793 //TAttLineCanvas *line = dynamic_cast<TAttLineCanvas*>(obj);
794 //TAttLineEditor *line = dynamic_cast<TAttLineEditor*>(obj);
795 //TAttMarkerCanvas *line = dynamic_cast<TAttMarkerCanvas*>(obj);
796 //TAttMarkerEditor *line = dynamic_cast<TAttMarkerEditor*>(obj);
797 //TAttPad *line = dynamic_cast<TAttPad*>(obj);
798 //TAttParticle *line = dynamic_cast<TAttParticle*>(obj);
799 //TAttTextCanvas *line = dynamic_cast<TAttTextCanvas*>(obj);
800 //TAttTextEditor *line = dynamic_cast<TAttTextEditor*>(obj);
801
802 TPave *pave = dynamic_cast<TPave*>(obj);
803 TAttLine *line = dynamic_cast<TAttLine*>(obj);
804 TAttText *text = dynamic_cast<TAttText*>(obj);
805 TAttFill *fill = dynamic_cast<TAttFill*>(obj);
806 TAttMarker *mark = dynamic_cast<TAttMarker*>(obj);
807
808 if (pave)
809 {
810 GetAttPave(name, *pave, dynamic_cast<TPave*>(dftl));
811 return;
812 }
813
814 if (line)
815 GetAttLine(name, *line, dynamic_cast<TAttLine*>(dftl));
816 if (text)
817 GetAttText(name, *text, dynamic_cast<TAttText*>(dftl));
818 if (fill)
819 GetAttFill(name, *fill, dynamic_cast<TAttFill*>(dftl));
820 if (mark)
821 GetAttMarker(name, *mark, dynamic_cast<TAttMarker*>(dftl));
822}
823
824//---------------------------------------------------------------------------
825//
826// Set the resources from a TAttLine:
827// name.LineColor <see also SetColor>
828// name.LineStyle
829// name.LineWidth
830//
831void MEnv::SetAttLine(const char *name, const TAttLine &line)
832{
833 const TString color = Compile(name, "LineColor");
834 const TString style = Compile(name, "LineStyle");
835 const TString width = Compile(name, "LineWidth");
836
837 SetColor(color, line.GetLineColor());
838 SetLineStyle(style, line.GetLineStyle());
839 SetValue(width, line.GetLineWidth());
840}
841
842//---------------------------------------------------------------------------
843//
844// Set the resources from a TAttText:
845// name.TextColor <see also SetColor>
846// name.TextAlign <see also SetAlign>
847// name.TextAngle
848// name.TextFont
849// name.TextSize
850//
851void MEnv::SetAttText(const char *name, const TAttText &text)
852{
853 const TString color = Compile(name, "TextColor");
854 const TString align = Compile(name, "TextAlign");
855 const TString angle = Compile(name, "TextAngle");
856 const TString font = Compile(name, "TextFont");
857 const TString size = Compile(name, "TextSize");
858
859 SetColor(color, text.GetTextColor());
860 SetAlign(align, text.GetTextAlign());
861 SetValue(angle, text.GetTextAngle());
862 SetValue(font, text.GetTextFont());
863 SetValue(size, text.GetTextSize());
864}
865
866//---------------------------------------------------------------------------
867//
868// Set the resources from a TAttFill:
869// name.FillColor <see also SetColor>
870// name.FillStyle <see also SetFillStyle>
871//
872void MEnv::SetAttFill(const char *name, const TAttFill &fill)
873{
874 const TString color = Compile(name, "FillColor");
875 const TString style = Compile(name, "FillStyle");
876
877 SetColor(color, fill.GetFillColor());
878 SetFillStyle(style, fill.GetFillStyle());
879}
880
881//---------------------------------------------------------------------------
882//
883// Set the resources from a TAttMarker:
884// name.MarkerColor <see also SetColor>
885// name.MarkerStyle
886// name.MarkerSize
887//
888void MEnv::SetAttMarker(const char *name, const TAttMarker &marker)
889{
890 const TString color = Compile(name, "MarkerColor");
891 const TString style = Compile(name, "MarkerStyle");
892 const TString size = Compile(name, "MarkerSize");
893
894 SetColor(color, marker.GetMarkerColor());
895 SetMarkerStyle(style, marker.GetMarkerStyle());
896 SetValue(size, marker.GetMarkerSize());
897}
898
899//---------------------------------------------------------------------------
900//
901// Set the resources from a TPave:
902// name.CornerRadius
903// name.BorderSize
904// name.Option
905// Also all resources from TAttLine and TAttFill are supported.
906//
907void MEnv::SetAttPave(const char *str, const TPave &pave)
908{
909 const TString name(str);
910
911 SetAttLine(name, pave);
912 SetAttFill(name, pave);
913
914 const TString corner = Compile(name, "CornerRadius");
915 const TString border = Compile(name, "BorderSize");
916 const TString option = Compile(name, "Option");
917
918 SetValue(corner, const_cast<TPave&>(pave).GetCornerRadius());
919 SetValue(border, const_cast<TPave&>(pave).GetBorderSize());
920 SetValue(option, pave.GetOption());
921}
922
923//---------------------------------------------------------------------------
924//
925// Set the attributed for the TObject obj.
926//
927// There is support for:
928// TPave <see SetAttPave>
929// TAttLine <see SetAttLine>
930// TAttText <see SetAttText>
931// TAttFill <see SetAttFill>
932// TAttMarker <see SetAttMarker>
933//
934void MEnv::SetAttributes(const char *name, const TObject *obj)
935{
936 const TPave *pave = dynamic_cast<const TPave*>(obj);
937 const TAttLine *line = dynamic_cast<const TAttLine*>(obj);
938 const TAttText *text = dynamic_cast<const TAttText*>(obj);
939 const TAttFill *fill = dynamic_cast<const TAttFill*>(obj);
940 const TAttMarker *mark = dynamic_cast<const TAttMarker*>(obj);
941
942 if (pave)
943 {
944 SetAttPave(name, *pave);
945 return;
946 }
947
948 if (line)
949 SetAttLine(name, *line);
950 if (text)
951 SetAttText(name, *text);
952 if (fill)
953 SetAttFill(name, *fill);
954 if (mark)
955 SetAttMarker(name, *mark);
956}
957
958//---------------------------------------------------------------------------
959//
960// Add all values from TEnv env the this MEnv. To not overwrite existing
961// values set overwrite to kFALSE
962//
963void MEnv::AddEnv(const TEnv &env, Bool_t overwrite)
964{
965 if (!GetTable() || !env.GetTable())
966 return;
967
968 TIter Next(env.GetTable());
969
970 TEnvRec *er;
971 while ((er = (TEnvRec*)Next()))
972 {
973 if (overwrite || !Defined(er->GetName()))
974 SetValue(er->GetName(), er->GetValue(), er->GetLevel(), er->GetType());
975 }
976}
977
978//---------------------------------------------------------------------------
979//
980// Add name and full path to output
981//
982void MEnv::PrintEnv(EEnvLevel level) const
983{
984 cout << "# Path: " << GetRcName() << endl;
985 cout << "# Name: " << GetName() << endl;
986 TEnv::PrintEnv(level);
987}
988
989//---------------------------------------------------------------------------
990//
991// Print resources which have never been touched (for debugging)
992//
993void MEnv::PrintUntouched() const
994{
995 int i=0;
996 gLog << inf << flush;
997
998 TString sep = "Untouched Resources in ";
999 sep += GetRcName();
1000 gLog.Separator(sep);
1001 TIter Next(GetTable());
1002 TObject *o=0;
1003
1004 while ((o=Next()))
1005 if (!fChecked.FindObject(o->GetName()))
1006 {
1007 gLog << warn << " - Resource " << o->GetName() << " untouched" << endl;
1008 i++;
1009 }
1010 if (i==0)
1011 gLog << inf << "None." << endl;
1012 else
1013 gLog << inf << i << " resources have not been touched." << endl;
1014}
1015
1016//---------------------------------------------------------------------------
1017//
1018// Return number of resources which have not been touched.
1019//
1020Int_t MEnv::GetNumUntouched() const
1021{
1022 int i=0;
1023 TIter Next(GetTable());
1024 TObject *o=0;
1025 while ((o=Next()))
1026 if (!fChecked.FindObject(o->GetName()))
1027 i++;
1028 return i;
1029}
Note: See TracBrowser for help on using the repository browser.