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

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