Ignore:
Timestamp:
11/28/05 11:15:09 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MEnv.cc

    r6553 r7432  
    3434#include "MEnv.h"
    3535
     36#include <Gtypes.h>
    3637#include <TObjString.h>
     38
     39#include <TAttText.h>
     40#include <TAttFill.h>
     41#include <TAttLine.h>
     42#include <TAttMarker.h>
    3743
    3844#include "MLog.h"
     
    6268        fChecked.Add(new TObjString(name));
    6369    return TEnv::GetValue(name, dflt);
     70}
     71
     72Int_t MEnv::GetColor(const char *name, Int_t dftl)
     73{
     74    TString str = GetValue(name, "");
     75
     76    str = str.Strip(TString::kBoth);
     77    if (str.IsNull())
     78        return dftl;
     79
     80    str.ToLower();
     81
     82    switch (str.Hash())
     83    {
     84    case (unsigned)-1926423925/*2368543371*/: return kWhite;
     85    case 1814927399: return kBlack;
     86    case 7496964:    return kRed;
     87    case (unsigned)-1397860222/*2897107074*/: return kGreen;
     88    case 1702194402: return kBlue;
     89    case (unsigned)-1920149414/* 2374817882*/: return kYellow;
     90    case (unsigned)-1400748595/*2894218701*/: return kMagenta;
     91    case 1851881955: return kCyan;
     92    case 749623518: return 18; // grey1
     93    case 749623517: return 17; // grey2
     94    case 749623516: return 16; // grey3
     95    case 749623515: return 15; // grey4
     96    case 749623514: return 14; // grey5
     97    case 741234910: return 18; // gray1
     98    case 741234909: return 17; // gray2
     99    case 741234908: return 16; // gray3
     100    case 741234907: return 15; // gray4
     101    case 741234906: return 14; // gray5
     102    }
     103    return str.Atoi();
     104}
     105
     106TString MEnv::Compile(TString str, const char *post) const
     107{
     108    if (!str.IsNull() && str[str.Length()-1]!='.')
     109        str += ".";
     110
     111    str += post;
     112
     113    return str;
     114}
     115
     116void MEnv::GetAttLine(const char *name, TAttLine &line, TAttLine *dftl)
     117{
     118    const TString color = Compile(name, "LineColor");
     119    const TString style = Compile(name, "LineStyle");
     120    const TString width = Compile(name, "LineWidth");
     121
     122    if (!dftl)
     123        dftl = &line;
     124
     125    const Color_t col = GetColor(color, dftl->GetLineColor());
     126    const Style_t sty = GetValue(style, dftl->GetLineStyle());
     127    const Style_t wid = GetValue(width, dftl->GetLineWidth());
     128
     129    line.SetLineColor(col);
     130    line.SetLineStyle(sty);
     131    line.SetLineWidth(wid);
     132}
     133
     134void MEnv::GetAttText(const char *name, TAttText &text, TAttText *dftl)
     135{
     136   const TString color = Compile(name, "TextColor");
     137   const TString align = Compile(name, "TextAlign");
     138   const TString angle = Compile(name, "TextAngle");
     139   const TString font  = Compile(name, "TextFont");
     140   const TString size  = Compile(name, "TextSize");
     141
     142    if (!dftl)
     143        dftl = &text;
     144
     145    const Color_t col = GetColor(color, dftl->GetTextColor());
     146    const Short_t ali = GetValue(align, dftl->GetTextAlign());
     147    const Float_t ang = GetValue(angle, dftl->GetTextAngle());
     148    const Font_t  fon = GetValue(font,  dftl->GetTextFont());
     149    const Float_t siz = GetValue(size,  dftl->GetTextSize());
     150
     151    text.SetTextColor(col);
     152    text.SetTextAlign(ali);
     153    text.SetTextAngle(ang);
     154    text.SetTextFont(fon);
     155    text.SetTextSize(siz);
     156}
     157
     158void MEnv::GetAttFill(const char *name, TAttFill &fill, TAttFill *dftl)
     159{
     160    const TString color = Compile(name, "FillColor");
     161    const TString style = Compile(name, "FillStyle");
     162
     163    if (!dftl)
     164        dftl = &fill;
     165
     166    const Color_t col = GetColor(color, dftl->GetFillColor());
     167    const Style_t sty = GetValue(style, dftl->GetFillStyle());
     168
     169    fill.SetFillColor(col);
     170    fill.SetFillStyle(sty);
     171}
     172
     173void MEnv::GetAttMarker(const char *name, TAttMarker &marker, TAttMarker *dftl)
     174{
     175    const TString color = Compile(name, "MarkerColor");
     176    const TString style = Compile(name, "MarkerStyle");
     177    const TString size  = Compile(name, "MarkerSize");
     178
     179    if (!dftl)
     180        dftl = &marker;
     181
     182    const Color_t col = GetColor(color, dftl->GetMarkerColor());
     183    const Style_t sty = GetValue(style, dftl->GetMarkerStyle());
     184    const Size_t  siz = GetValue(size,  dftl->GetMarkerSize());
     185
     186    marker.SetMarkerColor(col);
     187    marker.SetMarkerStyle(sty);
     188    marker.SetMarkerSize(siz);
     189}
     190
     191void MEnv::GetAttributes(const char *name, TObject *obj, TObject *dftl)
     192{
     193    //TAttAxis         *line = dynamic_cast<TAttAxis*>(obj);
     194    //TAtt3D           *line = dynamic_cast<TAtt3D*>(obj);
     195    //TAttCanvas       *line = dynamic_cast<TAttCanvas*>(obj);
     196    //TAttFillCanvas   *line = dynamic_cast<TAttFillEitor*>(obj);
     197    //TAttLineCanvas   *line = dynamic_cast<TAttLineCanvas*>(obj);
     198    //TAttLineEditor   *line = dynamic_cast<TAttLineEditor*>(obj);
     199    //TAttMarkerCanvas *line = dynamic_cast<TAttMarkerCanvas*>(obj);
     200    //TAttMarkerEditor *line = dynamic_cast<TAttMarkerEditor*>(obj);
     201    //TAttPad          *line = dynamic_cast<TAttPad*>(obj);
     202    //TAttParticle     *line = dynamic_cast<TAttParticle*>(obj);
     203    //TAttTextCanvas   *line = dynamic_cast<TAttTextCanvas*>(obj);
     204    //TAttTextEditor   *line = dynamic_cast<TAttTextEditor*>(obj);
     205
     206    TAttLine   *line = dynamic_cast<TAttLine*>(/*(TAttLine*)*/obj);
     207    TAttText   *text = dynamic_cast<TAttText*>(/*(TAttText*)*/obj);
     208    TAttFill   *fill = dynamic_cast<TAttFill*>(/*(TAttFill*)*/obj);
     209    TAttMarker *mark = dynamic_cast<TAttMarker*>(/*(TAttMarker*)*/obj);
     210
     211    cout << line << " " << text << " " << fill << " " << mark << endl;
     212
     213    if (line)
     214        GetAttLine(name, *line, dynamic_cast<TAttLine*>(/*(TAttLine*)*/dftl));
     215    if (text)
     216        GetAttText(name, *text, dynamic_cast<TAttText*>(/*(TAttText*)*/dftl));
     217    if (fill)
     218        GetAttFill(name, *fill, dynamic_cast<TAttFill*>(/*(TAttFill*)*/dftl));
     219    if (mark)
     220        GetAttMarker(name, *mark, dynamic_cast<TAttMarker*>(/*(TAttMarker*)*/dftl));
    64221}
    65222
  • trunk/MagicSoft/Mars/mbase/MEnv.h

    r6553 r7432  
    1010#endif
    1111
     12class TAttLine;
     13class TAttMarker;
     14class TAttText;
     15class TAttFill;
     16
    1217class MEnv : public TEnv
    1318{
    1419private:
    1520    TOrdCollection fChecked;
     21
     22    TString Compile(TString str, const char *post) const;
    1623
    1724public:
     
    2229    const char *GetValue(const char *name, const char *dflt);
    2330
     31    Int_t       GetColor(const char *name, Int_t dftl);
     32
     33    void        GetAttributes(const char *name, TObject *obj, TObject *dftl=0);
     34    void        GetAttLine(const char *name, TAttLine &line, TAttLine *dftl=0);
     35    void        GetAttText(const char *name, TAttText &text, TAttText *dftl=0);
     36    void        GetAttFill(const char *name, TAttFill &fill, TAttFill *dftl=0);
     37    void        GetAttMarker(const char *name, TAttMarker &marker, TAttMarker *dftl=0);
     38
    2439    void PrintUntouched() const;
    2540
  • trunk/MagicSoft/Mars/mbase/MTime.cc

    r7384 r7432  
    239239{
    240240    SetMjd(time*1000/kDay+49718);
     241}
     242
     243// --------------------------------------------------------------------------
     244//
     245// Set this to the date of easter corresponding to the given year.
     246// If calculation was not possible it is set to MTime()
     247//
     248// The date corresponding to the year of MTime(-1) is returned
     249// if year<0
     250//
     251// The date corresponding to the Year() is returned if year==0.
     252//
     253//  for more information see: GetEaster and MAstro::GetEasterOffset()
     254//
     255void MTime::SetEaster(Short_t year)
     256{
     257    *this = GetEaster(year==0 ? Year() : year);
    241258}
    242259
     
    515532// The maximum size of the return string is 128 (incl. NULL)
    516533//
    517 TString MTime::GetStringFmt(const char *fmt) const
     534// For dates before 1.1.1902  a null string is returned
     535// For dates after 31.12.2037 a null string is returned
     536//
     537// To change the localization use loc, eg loc = "da_DK", "de_DE".
     538// Leaving the argument empty will just take the default localization.
     539//
     540// If loc is "", each part of the locale that should be modified is set
     541// according  to the environment variables. The details are implementation
     542// dependent.  For glibc, first (regardless of category), the  environment
     543// variable  LC_ALL  is  inspected, next the environment variable with the
     544// same name as the category (LC_COLLATE, LC_CTYPE, LC_MESSAGES,  LC_MONE?
     545// TARY,  LC_NUMERIC,  LC_TIME) and finally the environment variable LANG.
     546// The first existing environment variable is used.
     547//
     548// A  locale  name  is  typically  of the form language[_territory][.code?
     549// set][@modifier], where language is an ISO 639 language code,  territory
     550// is an ISO 3166 country code, and codeset is a character set or encoding
     551// identifier like ISO-8859-1 or UTF-8.   For  a  list  of  all  supported
     552// locales, try "locale -a", cf. locale(1).
     553//
     554TString MTime::GetStringFmt(const char *fmt, const char *loc) const
    518555{
    519556    if (!fmt)
     
    525562    GetDate(y, mon, d);
    526563    GetTime(h, m, s, ms);
     564
     565    if (y<1902 || y>2037)
     566        return "";
    527567
    528568    struct tm time;
     
    535575    time.tm_isdst = 0;
    536576
     577    const TString locale = setlocale(LC_TIME, 0);
     578
     579    setlocale(LC_TIME, loc);
     580
    537581    // recalculate tm_yday and tm_wday
    538582    mktime(&time);
    539583
    540584    char ret[128];
    541     return TString(strftime(ret, 127, fmt, &time) ? ret : "");
     585    const size_t rc = strftime(ret, 127, fmt, &time);
     586
     587    setlocale(LC_TIME, locale);
     588
     589    return rc ? ret : "";
    542590}
    543591
     
    549597// For more information see GetStringFmt
    550598//
    551 Bool_t MTime::SetStringFmt(const char *time, const char *fmt)
     599Bool_t MTime::SetStringFmt(const char *time, const char *fmt, const char *loc)
    552600{
    553601    if (!fmt)
     
    556604    struct tm t;
    557605    memset(&t, 0, sizeof(struct tm));
     606
     607    const TString locale = setlocale(LC_TIME, 0);
     608
     609    setlocale(LC_TIME, loc);
    558610    strptime(time, fmt, &t);
     611    setlocale(LC_TIME, locale);
    559612
    560613    return Set(t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
     
    795848    return out;
    796849}
     850
     851// --------------------------------------------------------------------------
     852//
     853// Calculate the day of easter for the given year.
     854// MTime() is returned if this was not possible.
     855//
     856// In case of the default argument or the year less than zero
     857// the date of eastern of the current year (the year corresponding to
     858// MTime(-1)) is returned.
     859//
     860//  for more information see: MAstro::GetDayOfEaster()
     861//
     862MTime MTime::GetEaster(Short_t year)
     863{
     864    if (year<0)
     865        year = MTime(-1).Year();
     866
     867    const Int_t day = MAstro::GetEasterOffset(year);
     868    if (day<0)
     869        return MTime();
     870
     871    MTime t;
     872    t.Set(year, 3, 1);
     873    t.SetMjd(t.GetMjd() + day);
     874
     875    return t;
     876}
  • trunk/MagicSoft/Mars/mbase/MTime.h

    r7384 r7432  
    8383    Bool_t   SetSqlTimeStamp(const char *str);
    8484    void     SetCT1Time(UInt_t mjd, UInt_t t1, UInt_t t0);
    85     Bool_t   SetStringFmt(const char *time, const char *fmt);
     85    Bool_t   SetStringFmt(const char *time, const char *fmt, const char *loc=0);
    8686    Bool_t   UpdMagicTime(Byte_t h, Byte_t m, Byte_t s, UInt_t ns);
    8787    Bool_t   SetMjd(UInt_t mjd, ULong_t ms, UInt_t ns=0);
    8888    void     SetMjd(Double_t m);
    8989    void     SetAxisTime(Double_t time);
     90    void     SetEaster(Short_t year=0);
    9091
    9192    // Getter functions
     
    9394    Double_t GetGmst() const;
    9495    TString  GetString() const;
    95     TString  GetStringFmt(const char *fmt=0) const;
     96    TString  GetStringFmt(const char *fmt=0, const char *loc=0) const;
    9697    TString  GetSqlDateTime() const;
    9798    TString  GetSqlTimeStamp() const;
     
    112113    }
    113114
    114     UInt_t Year() const  { UShort_t y; Byte_t m, d; GetDate(y,m,d); return y; }
    115     UInt_t Month() const { UShort_t y; Byte_t m, d; GetDate(y,m,d); return m; }
    116     UInt_t Day() const   { UShort_t y; Byte_t m, d; GetDate(y,m,d); return d; }
    117     UInt_t Hour() const  { Byte_t h, m, s; GetTime(h,m,s); return h; }
    118     UInt_t Min() const   { Byte_t h, m, s; GetTime(h,m,s); return m; }
    119     UInt_t Sec() const   { Byte_t h, m, s; GetTime(h,m,s); return s; }
     115    UInt_t Year() const    { UShort_t y; Byte_t m, d; GetDate(y,m,d); return y; }
     116    UInt_t Month() const   { UShort_t y; Byte_t m, d; GetDate(y,m,d); return m; }
     117    UInt_t Day() const     { UShort_t y; Byte_t m, d; GetDate(y,m,d); return d; }
     118    Byte_t WeekDay() const { return TMath::Nint(TMath::Floor(GetMjd()+3))%7; } // Return Day of the week: Sun=0, Mon=1, ..., Sat=6
     119    UInt_t Hour() const    { Byte_t h, m, s; GetTime(h,m,s); return h; }
     120    UInt_t Min() const     { Byte_t h, m, s; GetTime(h,m,s); return m; }
     121    UInt_t Sec() const     { Byte_t h, m, s; GetTime(h,m,s); return s; }
    120122
    121123    Bool_t IsMidnight() const { return (Long_t)fTime==0 && fNanoSec==0; }
     
    155157    bool operator!() const;
    156158
     159    static MTime GetEaster(Short_t year=-1);
     160
    157161    ClassDef(MTime, 3)  //A generalized MARS time stamp
    158162};
Note: See TracChangeset for help on using the changeset viewer.