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