source: branches/Mars_use_drstimefiles/macros/tutorials/calendar.C@ 18403

Last change on this file since 18403 was 7894, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 5.6 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 8/2006 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2004-2006
21!
22!
23\* ======================================================================== */
24
25///////////////////////////////////////////////////////////////////////////
26//
27// calendar.C
28//
29// example of how to use MCalendar to draw your calendar
30//
31// For more details of the usage and the resources resources please
32// refer to the class reference of MCalendar and the descriptions
33// of its member functions.
34//
35// To write an output file check the end of the loop.
36//
37// For more information on the setup see also
38// macros/tutorials/calendar.rc
39// macros/tutorials/holidays.rc
40//
41///////////////////////////////////////////////////////////////////////////
42
43void calendar()
44{
45 // 2, 10, 13
46 gStyle->SetTextFont(6*10+2);
47
48 // Define the path where your resource files are located
49 TString rcpath = "macros/tutorials/";
50
51 // Define the path where your images are
52 TString imgpath = "./";
53
54 // Create the object containing your setup
55 MEnv env(rcpath+"calendar.rc");
56
57 // Create the display to show your calendar
58 MStatusDisplay *d = new MStatusDisplay(1426, 1050);
59
60 // Define the first and last month which you want to make a
61 // piece of
62 Int_t first=1;
63 Int_t last=12;
64
65 // Loop over all months
66 for (Int_t month=first; month<=last; month++)
67 {
68 // Create an object do draw your calendar
69 MCalendar *cal=new MCalendar;
70 cal->SetBit(kCanDelete);
71
72 // Set the month and year you want to draw it for
73 cal->SetDate(month, 2006);
74
75 // Read resource file defining the layout.
76 // You could also skip this line. In this case a nice
77 // default layout is used instead
78 cal->ReadResourceFile(rcpath+"calendar.rc");
79
80 // Read file containing the holidays.
81 // You could also skip this file. In this case
82 // only New Year, Easter and Christmas are shown.
83 cal->ReadHolidayFile(rcpath+"holidays.rc");
84
85 // Get the image corresponding to the month
86 TASImage *img = cal->GetImage(&env, imgpath);
87 if (!img)
88 {
89 delete cal;
90 continue;
91 }
92
93 // Check whether the layout should be horizontal or vertical
94 Bool_t hor = img->GetWidth()>img->GetHeight();
95 Int_t background = kWhite;
96
97 // Define layout of day-table for this month
98 if (hor)
99 cal->SetLayout(2, 0.05, 0.1, 0.015, 0.03);
100 else
101 cal->SetLayout(1, 0.05, 0.05, 0.005, 0);
102
103 // Get the name of the month
104 TString strmonth = cal->GetStringFmt("%b");
105 // convert Umlauts to "StatusDisplay-charset"
106 MCalendar::ConvertUTF8(strmonth, kFALSE);
107
108 // Add a new tab for this month
109 TCanvas &c = d->AddTab(strmonth);
110 // Set background color for the tab
111 c.SetFillColor(background);
112
113 // conver month name to latex format
114 MCalendar::Convert2Latex(strmonth);
115
116 // Create the main pad
117 TPad *pad2;
118 if (hor)
119 pad2=new TPad("Dat", "Data", 0, 0.01, 1, 0.3);
120 else
121 pad2=new TPad("Dat", "Data", 0.5, 0.19, 1, 0.81);
122 pad2->SetBorderMode(0);
123 pad2->SetFillColor(background);
124 pad2->SetBit(kCanDelete);
125
126 // Draw the image to your month-tab
127 c.cd();
128
129 if (hor)
130 cal->DrawImage(*img, 0, 0.305, 0.628, 1, kTRUE);
131 else
132 cal->DrawImage(*img, 0, 0, 0.5, 0.99, kTRUE);
133
134 gPad->SetFixedAspectRatio();
135 delete img;
136
137 // Draw the date to your month-tab
138 Double_t x1, y1, x2, y2;
139 gPad->GetPadPar(x1, y1, x2, y2);
140
141 c.cd();
142
143 // "comic" is the ttf-font name. You find other ones typically
144 // in $ROOTSYS/fonts or /usr/X11R6/lib/X11/fonts/truetype
145 if (hor)
146 cal->DrawTTFDate(0.64, 0.83, 1, 1, "%B %Y", 0.072, "comic");
147 else
148 cal->DrawTTFDate(0.5, 0.83, 1, 1, "%B %Y", 0.085, "comic");
149
150
151 c.cd();
152
153 // Get description and draw description
154 TString txt = env.GetValue(Form("%02d.Text", month), "");
155 if (!txt.IsNull())
156 {
157 MCalendar::Convert2Latex(txt);
158
159 TAttText att1(11, 0, kBlack, 42, 0.023);
160 if (hor)
161 cal->DrawDate(0.63, 0.31, txt, att1);
162 else
163 cal->DrawDate(0.5, 0.01, txt, att1);
164
165 }
166
167 // Now make sure that everything is displayed as expected...
168 pad2->Draw();
169
170 gROOT->SetSelectedPad(0);
171 pad2->cd();
172 cal->Draw();
173
174 pad2->Modified();
175 pad2->Update();
176
177 c.Update();
178
179 // Uncomment this lines to write a postscript (or pdf) file
180 //TString psfile = "calendar.ps";
181 //if (month==first) psfile+="(";
182 //if (month==last) psfile+=")";
183 //c.Print(psfile, "portrait");
184 }
185}
Note: See TracBrowser for help on using the repository browser.