00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4Picture.h"
00017
00018 #include <iostream.h>
00019
00020 #include "TObjArray.h"
00021 #include "TObjString.h"
00022 #include "TVirtualPad.h"
00023 #include "TPad.h"
00024 #include "TCanvas.h"
00025 #include "TH1.h"
00026 #include "TGraph.h"
00027 #include "THStack.h"
00028 #include "TStyle.h"
00029 #include "TText.h"
00030 #include "TDatime.h"
00031 #include "TArrayL.h"
00032 #include "TAttLine.h"
00033 #include "TAttFill.h"
00034 #include "TAttMarker.h"
00035
00036 enum OptionsIdentifiers {
00037 op_RangeXMin = 1,
00038 op_RangeXMax = 2,
00039 op_RangeYMin = 3,
00040 op_RangeYMax = 4,
00041
00042 op_LineColor = 5,
00043 op_LineStyle = 6,
00044 op_LineWidth = 7,
00045
00046 op_FillColor = 8,
00047 op_FillStyle = 9,
00048
00049 op_MarkerColor = 10,
00050 op_MarkerSize = 11,
00051 op_MarkerStyle = 12,
00052
00053 op_LogScaleX = 13,
00054 op_LogScaleY = 14,
00055 op_LogScaleZ = 15,
00056
00057 op_HistDraw = 16,
00058 op_HistError = 17,
00059 op_HistCoord = 18,
00060
00061 op_Padxlow = 19,
00062 op_Padylow = 20,
00063 op_Padxup = 21,
00064 op_Padyup = 22,
00065
00066 op_PicHeader = 23,
00067
00068 op_ObjsBound = 0x4000,
00069
00070 op_Style = op_ObjsBound,
00071 op_Draw = op_ObjsBound+1
00072 };
00073
00074
00075 TGo4Picture::TGo4Picture() : TNamed(),
00076 fiNDivX(1), fiNDivY(1), fiPosX(0), fiPosY(0), fxNames(0),
00077 fxObjects(0), fxSubPictures(0),
00078 fiOptSize(0), fxOptIndex(), fxOptValue(), fxOptObjects(0),
00079 fiLastIndex(0) {
00080 }
00081
00082 TGo4Picture::TGo4Picture(const char* name, const char* title, Int_t ndivy, Int_t ndivx) :
00083 TNamed(name, title), fiNDivX(1), fiNDivY(1), fiPosX(0), fiPosY(0), fxNames(0),
00084 fxObjects(0), fxSubPictures(0),
00085 fiOptSize(0), fxOptIndex(), fxOptValue(), fxOptObjects(0),
00086 fiLastIndex(0) {
00087 SetDivision(ndivy, ndivx);
00088 }
00089
00090 TGo4Picture::TGo4Picture(TGo4Picture& picture) : TNamed(),
00091 fiNDivX(1), fiNDivY(1), fiPosX(0), fiPosY(0), fxNames(0),
00092 fxObjects(0), fxSubPictures(0),
00093 fiOptSize(0), fxOptIndex(), fxOptValue(), fxOptObjects(0),
00094 fiLastIndex(0) {
00095 UpdateFrom(&picture);
00096 }
00097
00098 TGo4Picture::~TGo4Picture() {
00099 if (fxNames) delete fxNames;
00100 if (fxObjects) delete fxObjects;
00101 if (fxSubPictures) delete fxSubPictures;
00102 if (fxOptObjects) delete fxOptObjects;
00103 }
00104
00105
00106 void TGo4Picture::SetDrawHeader(Bool_t draw) {
00107 SetOption(PictureIndex, op_PicHeader, draw);
00108 }
00109
00110 Bool_t TGo4Picture::IsDrawHeader() {
00111 Long_t draw;
00112 if (GetOption(PictureIndex, op_PicHeader, draw)) return draw!=0;
00113 return kFALSE;
00114 }
00115
00116
00117 void TGo4Picture::SetDivision(Int_t ndivy, Int_t ndivx) {
00118 if (ndivx<1) fiNDivX = 1; else fiNDivX = ndivx;
00119 if (ndivy<1) fiNDivY = 1; else fiNDivY = ndivy;
00120 }
00121
00122 TGo4Picture* TGo4Picture::FindPic(Int_t posy, Int_t posx) {
00123 if (fxSubPictures==0) return 0; if (posx<0) posx=0; else if(posx>=GetDivX()) posx = GetDivX()-1;
00124 if (posy<0) posy=0; else if(posy>=GetDivY()) posy = GetDivY()-1;
00125 for (Int_t n=0;n<=fxSubPictures->GetLast();n++) {
00126 TGo4Picture* sub = dynamic_cast<TGo4Picture*> (fxSubPictures->At(n));
00127 if (sub!=0)
00128 if (sub->CheckPosition(posy,posx)) return sub;
00129 }
00130 return 0;
00131 }
00132
00133 TGo4Picture* TGo4Picture::Pic(Int_t posy, Int_t posx) {
00134 if (!IsDivided()) return this;
00135 if (posx<0) posx=0; else if(posx>=GetDivX()) posx = GetDivX()-1;
00136 if (posy<0) posy=0; else if(posy>=GetDivY()) posy = GetDivY()-1;
00137 TGo4Picture* sub = FindPic(posy, posx);
00138 if (sub!=0) return sub;
00139 sub = new TGo4Picture("Sub", "Sub picture");
00140 sub->SetPosition(posy, posx);
00141 if (fxSubPictures==0) {
00142 fxSubPictures = new TObjArray();
00143 fxSubPictures->SetOwner(kTRUE);
00144 }
00145 fxSubPictures->Add(sub);
00146 return sub;
00147 }
00148
00149 void TGo4Picture::SetLinesDivision(Int_t numlines, const Int_t* numbers) {
00150 SetDivision(numlines,1);
00151 for (Int_t n=0;n<numlines;n++)
00152 if (numbers[n]>1) Pic(n,0)->SetDivision(1,numbers[n]);
00153 }
00154
00155 void TGo4Picture::SetLinesDivision(Int_t numlines,
00156 Int_t n0, Int_t n1, Int_t n2, Int_t n3, Int_t n4,
00157 Int_t n5, Int_t n6, Int_t n7, Int_t n8, Int_t n9) {
00158 const Int_t numbers[10] = { n0, n1, n2, n3, n4, n5, n6, n7, n8, n9};
00159 SetLinesDivision(numlines, numbers);
00160 }
00161
00162 TGo4Picture* TGo4Picture::LPic(Int_t nline, Int_t ncol) {
00163 if (!IsDivided()) return this;
00164 TGo4Picture* sub = Pic(nline, 0);
00165 if (sub==0) return 0;
00166 if (sub->IsDivided()) return sub->Pic(0,ncol);
00167 else return sub;
00168 }
00169
00170 void TGo4Picture::SetPosition(Int_t posy, Int_t posx) {
00171 fiPosX = posx; fiPosY = posy;
00172 }
00173
00174 Bool_t TGo4Picture::CheckPosition(Int_t posy, Int_t posx) {
00175 return (fiPosX == posx) && (fiPosY == posy);
00176 }
00177
00178 void TGo4Picture::AddH1(TH1* histo, Option_t* DrawOption) {
00179 AddObject(histo, DrawOption);
00180 }
00181
00182 void TGo4Picture::AddH1(Int_t posy, Int_t posx, TH1* histo, Option_t* DrawOption) {
00183 AddObject(posy, posx, histo, DrawOption);
00184 }
00185
00186 void TGo4Picture::AddHStack(THStack* st, Option_t* DrawOption) {
00187 AddObject(st, DrawOption);
00188 }
00189
00190 void TGo4Picture::AddHStack(Int_t posy, Int_t posx, THStack* st, Option_t* DrawOption) {
00191 AddObject(posy, posx, st, DrawOption);
00192 }
00193
00194
00195
00196 void TGo4Picture::AddGraph(TGraph* gr, Option_t* DrawOption) {
00197 AddObject(gr, DrawOption);
00198 }
00199
00200 void TGo4Picture::AddGraph(Int_t posy, Int_t posx, TGraph* gr, Option_t* DrawOption) {
00201 AddObject(posy, posx, gr, DrawOption);
00202 }
00203
00204 void TGo4Picture::AddCondition(TNamed* cond) {
00205 AddObject(cond);
00206 }
00207
00208 void TGo4Picture::AddCondition(Int_t posy, Int_t posx, TNamed* cond) {
00209 AddObject(posy, posx, cond);
00210 }
00211
00212 void TGo4Picture::AddObjName(const char* name, Option_t* DrawOption) {
00213 if (name==0) return;
00214 if (fxNames==0) {
00215 fxNames = new TObjArray();
00216 fxNames->SetOwner(kTRUE);
00217 }
00218 fxNames->Add(new TObjString(name));
00219 SetDrawOption(DrawOption, fxNames->GetLast());
00220 fiLastIndex = fxNames->GetLast();
00221 }
00222
00223 void TGo4Picture::AddObjName(Int_t posy, Int_t posx, const char* name, Option_t* DrawOption) {
00224 if (name!=0)
00225 Pic(posy,posx)->AddObjName(name, DrawOption);
00226 }
00227
00228 void TGo4Picture::ClearObjNames(Bool_t recursive) {
00229 if (fxNames!=0) {
00230 delete fxNames;
00231 fxNames = 0;
00232 }
00233 fiLastIndex = 0;
00234 if (recursive && fxSubPictures)
00235 for (Int_t n=0;n<=fxSubPictures->GetLast();n++) {
00236 TGo4Picture* sub = dynamic_cast<TGo4Picture*> (fxSubPictures->At(n));
00237 if (sub) sub->ClearObjNames(recursive);
00238 }
00239 }
00240
00241 Int_t TGo4Picture::GetNumObjNames() {
00242 return (fxNames==0) ? 0 : fxNames->GetLast()+1;
00243 }
00244
00245 Bool_t TGo4Picture::IsObjNames() {
00246 if (GetNumObjNames()>0) return kTRUE;
00247
00248 if (fxSubPictures)
00249 for (Int_t n=0;n<=fxSubPictures->GetLast();n++) {
00250 TGo4Picture* sub = dynamic_cast<TGo4Picture*> (fxSubPictures->At(n));
00251 if (sub && sub->IsObjNames()) return kTRUE;
00252 }
00253 return kFALSE;
00254 }
00255
00256 const char* TGo4Picture::GetObjName(Int_t n) {
00257 if ((fxNames==0) || (n<0) || (n>fxNames->GetLast())) return 0;
00258 TObjString* str = dynamic_cast<TObjString*> (fxNames->At(n));
00259 if (str!=0) return str->String().Data();
00260 else return 0;
00261 }
00262
00263 void TGo4Picture::AddObject(TObject* obj, Option_t* DrawOption) {
00264 if (obj!=0) {
00265 AddObjName(obj->GetName(), DrawOption);
00266 AddObjectDirectly(obj, DrawOption);
00267 }
00268 }
00269
00270 void TGo4Picture::AddObject(Int_t posy, Int_t posx, TObject* obj, Option_t* DrawOption) {
00271 if (obj!=0) {
00272 AddObjName(posy, posx, obj->GetName(), DrawOption);
00273 AddObjectDirectly(posy, posx, obj, DrawOption);
00274 }
00275 }
00276
00277 void TGo4Picture::AddObjectDirectly(TObject* obj, Option_t* DrawOption) {
00278 if (obj==0) return;
00279 if (fxObjects==0) fxObjects = new TObjArray();
00280 fxObjects->Add(obj);
00281 SetDrawOption(DrawOption, fxObjects->GetLast());
00282 fiLastIndex = fxObjects->GetLast();
00283 }
00284
00285 void TGo4Picture::AddObjectDirectly(Int_t posy, Int_t posx, TObject* obj, Option_t* DrawOption) {
00286 if (obj!=0)
00287 Pic(posy,posx)->AddObjectDirectly(obj, DrawOption);
00288 }
00289
00290 void TGo4Picture::ClearObjects(Bool_t recursive) {
00291 if (fxObjects!=0) {
00292 delete fxObjects;
00293 fxObjects = 0;
00294 }
00295 fiLastIndex = 0;
00296 if (recursive && fxSubPictures)
00297 for (Int_t n=0;n<=fxSubPictures->GetLast();n++) {
00298 TGo4Picture* sub = dynamic_cast<TGo4Picture*> (fxSubPictures->At(n));
00299 if (sub) sub->ClearObjects(recursive);
00300 }
00301 }
00302
00303 Int_t TGo4Picture::GetNumObjects() {
00304 return (fxObjects==0) ? 0 : fxObjects->GetLast()+1;
00305 }
00306
00307 TObject* TGo4Picture::GetObject(Int_t n) {
00308 if ((fxObjects==0) || (n<0) || (n>fxObjects->GetLast())) return 0;
00309 return fxObjects->At(n);
00310 }
00311
00312 TObject* TGo4Picture::FindObject(const char* name) {
00313 if (name==0) return 0;
00314 for (Int_t n=0;n<GetNumObjects();n++)
00315 if (strcmp(GetObject(n)->GetName(),name)==0) return GetObject(n);
00316 return 0;
00317 }
00318
00319 void TGo4Picture::SetObjectsOwnership(Bool_t ownership) {
00320 if (fxObjects) fxObjects->SetOwner(ownership);
00321 if (fxSubPictures)
00322 for (Int_t n=0;n<=fxSubPictures->GetLast();n++) {
00323 TGo4Picture* sub = dynamic_cast<TGo4Picture*> (fxSubPictures->At(n));
00324 if (sub) sub->SetObjectsOwnership(ownership);
00325 }
00326 }
00327
00328 void TGo4Picture::SetRangeX(Double_t min, Double_t max) {
00329 SetOptionD(PictureIndex, op_RangeXMin, min);
00330 SetOptionD(PictureIndex, op_RangeXMax, max);
00331 }
00332
00333 Bool_t TGo4Picture::GetRangeX(Double_t& min, Double_t& max) {
00334 return GetOptionD(PictureIndex, op_RangeXMin, min) &&
00335 GetOptionD(PictureIndex, op_RangeXMax, max);
00336 }
00337
00338 void TGo4Picture::ClearRangeX() {
00339 ClearOption(PictureIndex, op_RangeXMin);
00340 ClearOption(PictureIndex, op_RangeXMax);
00341 }
00342
00343 void TGo4Picture::SetRangeY(Double_t min, Double_t max) {
00344 SetOptionD(PictureIndex, op_RangeYMin, min);
00345 SetOptionD(PictureIndex, op_RangeYMax, max);
00346 }
00347
00348 Bool_t TGo4Picture::GetRangeY(Double_t& min, Double_t& max) {
00349 return GetOptionD(PictureIndex, op_RangeYMin, min) &&
00350 GetOptionD(PictureIndex, op_RangeYMax, max);
00351 }
00352
00353 void TGo4Picture::ClearRangeY() {
00354 ClearOption(PictureIndex, op_RangeYMin);
00355 ClearOption(PictureIndex, op_RangeYMax);
00356 }
00357
00358 void TGo4Picture::SetLogScale(Int_t nscale, Int_t zn) {
00359 Int_t typ;
00360 switch (nscale) {
00361 case 1: typ = op_LogScaleY; break;
00362 case 2: typ = op_LogScaleZ; break;
00363 default: typ = op_LogScaleX;
00364 }
00365 SetOption(PictureIndex, typ, zn);
00366 }
00367
00368 Int_t TGo4Picture::GetLogScale(Int_t nscale) {
00369 Int_t typ;
00370 switch (nscale) {
00371 case 1: typ = op_LogScaleY; break;
00372 case 2: typ = op_LogScaleZ; break;
00373 default: typ = op_LogScaleX;
00374 }
00375 Long_t zn;
00376 if (GetOption(PictureIndex, typ, zn)) return zn;
00377 else return 0;
00378 }
00379
00380 void TGo4Picture::GetLogScales(TVirtualPad* pad) {
00381 if (pad == 0) return;
00382 Long_t zn;
00383 if (GetOption(PictureIndex, op_LogScaleX, zn)) pad->SetLogx(zn);
00384 if (GetOption(PictureIndex, op_LogScaleY, zn)) pad->SetLogy(zn);
00385 if (GetOption(PictureIndex, op_LogScaleZ, zn)) pad->SetLogz(zn);
00386 }
00387
00388 void TGo4Picture::ClearLogScales() {
00389 ClearOption(PictureIndex, op_LogScaleX);
00390 ClearOption(PictureIndex, op_LogScaleY);
00391 ClearOption(PictureIndex, op_LogScaleZ);
00392 }
00393
00394 void TGo4Picture::SetLineAtt(Color_t color, Style_t style, Width_t width, Int_t index) {
00395 CheckIndex(index);
00396 SetOption(index, op_LineColor, color);
00397 SetOption(index, op_LineStyle, style);
00398 SetOption(index, op_LineWidth, width);
00399 }
00400
00401 void TGo4Picture::SetLineAtt(TAttLine* line, Int_t index) {
00402 if (line==0) return;
00403 CheckIndex(index);
00404 SetOption(index, op_LineColor, line->GetLineColor());
00405 SetOption(index, op_LineStyle, line->GetLineStyle());
00406 SetOption(index, op_LineWidth, line->GetLineWidth());
00407 }
00408
00409 void TGo4Picture::GetLineAtt(TAttLine* line, Int_t index) {
00410 if (line==0) return;
00411 CheckIndex(index);
00412 Long_t color, style, width;
00413 if (GetOption(index, op_LineColor, color)) line->SetLineColor(color);
00414 if (GetOption(index, op_LineStyle, style)) line->SetLineStyle(style);
00415 if (GetOption(index, op_LineWidth, width)) line->SetLineWidth(width);
00416 }
00417
00418 void TGo4Picture::ClearLineAtt(Int_t index) {
00419 CheckIndex(index);
00420 ClearOption(index, op_LineColor);
00421 ClearOption(index, op_LineStyle);
00422 ClearOption(index, op_LineWidth);
00423 }
00424
00425 void TGo4Picture::SetFillAtt(Color_t color, Style_t style, Int_t index) {
00426 CheckIndex(index);
00427 SetOption(index, op_FillColor, color);
00428 SetOption(index, op_FillStyle, style);
00429 }
00430
00431 void TGo4Picture::SetFillAtt(TAttFill* fill, Int_t index) {
00432 if (fill==0) return;
00433 CheckIndex(index);
00434 SetOption(index, op_FillColor, fill->GetFillColor());
00435 SetOption(index, op_FillStyle, fill->GetFillStyle());
00436 }
00437
00438 void TGo4Picture::GetFillAtt(TAttFill* fill, Int_t index) {
00439 if (fill==0) return;
00440 CheckIndex(index);
00441 Long_t color, style;
00442 if (GetOption(index, op_FillColor, color)) fill->SetFillColor(color);
00443 if (GetOption(index, op_FillStyle, style)) fill->SetFillStyle(style);
00444 }
00445
00446 void TGo4Picture::ClearFillAtt(Int_t index) {
00447 CheckIndex(index);
00448 ClearOption(index, op_FillColor);
00449 ClearOption(index, op_FillStyle);
00450 }
00451
00452 void TGo4Picture::SetMarkerAtt(Color_t color, Size_t size, Style_t style, Int_t index) {
00453 CheckIndex(index);
00454 SetOption(index, op_MarkerColor, color);
00455 SetOption(index, op_MarkerSize, int(size));
00456 SetOption(index, op_MarkerStyle, style);
00457 }
00458
00459 void TGo4Picture::SetMarkerAtt(TAttMarker* marker, Int_t index) {
00460 if (marker==0) return;
00461 CheckIndex(index);
00462 SetOption(index, op_MarkerColor, marker->GetMarkerColor());
00463 SetOption(index, op_MarkerSize, int(marker->GetMarkerSize()));
00464 SetOption(index, op_MarkerStyle, marker->GetMarkerStyle());
00465 }
00466
00467 void TGo4Picture::GetMarkerAtt(TAttMarker* marker, Int_t index) {
00468 if (marker==0) return;
00469 CheckIndex(index);
00470 Long_t color, size, style;
00471 if (GetOption(index, op_MarkerColor, color)) marker->SetMarkerColor(color);
00472 if (GetOption(index, op_MarkerSize, size)) marker->SetMarkerSize(size);
00473 if (GetOption(index, op_MarkerStyle, style)) marker->SetMarkerStyle(style);
00474 }
00475
00476 void TGo4Picture::ClearMarkerAtt(Int_t index) {
00477 CheckIndex(index);
00478 ClearOption(index, op_MarkerColor);
00479 ClearOption(index, op_MarkerSize);
00480 ClearOption(index, op_MarkerStyle);
00481 }
00482
00483 void TGo4Picture::SetHistDrawStyle(Int_t zn, Int_t index) {
00484 CheckIndex(index);
00485 SetOption(index, op_HistDraw, zn);
00486 }
00487
00488 void TGo4Picture::SetHistErrorStyle(Int_t zn, Int_t index) {
00489 CheckIndex(index);
00490 SetOption(index, op_HistError, zn);
00491 }
00492
00493 void TGo4Picture::SetHistCoordStyle(Int_t zn, Int_t index) {
00494 CheckIndex(index);
00495 SetOption(index, op_HistCoord, zn);
00496 }
00497
00498 Int_t TGo4Picture::GetHistDrawStyle(Int_t index) {
00499 CheckIndex(index);
00500 Long_t zn = 0;
00501 if (GetOption(index, op_HistDraw, zn)) return zn;
00502 else return -1;
00503 }
00504
00505 Int_t TGo4Picture::GetHistErrorStyle(Int_t index) {
00506 CheckIndex(index);
00507 Long_t zn = 0;
00508 if (GetOption(index, op_HistError, zn)) return zn;
00509 else return -1;
00510 }
00511
00512 Int_t TGo4Picture::GetHistCoordStyle(Int_t index) {
00513 CheckIndex(index);
00514 Long_t zn = 0;
00515 if (GetOption(index, op_HistCoord, zn)) return zn;
00516 else return -1;
00517 }
00518
00519 Bool_t TGo4Picture::AppendHistStylesToString(TString* str, Int_t index) {
00520 if (str==0) return kFALSE;
00521 CheckIndex(index);
00522
00523 Long_t zn;
00524 Bool_t isany = kFALSE;
00525
00526 if (GetOption(index, op_HistDraw, zn)) {
00527 isany = kTRUE;
00528 if ((str->Length()>0) && (zn>0)) *str += ", ";
00529 switch (zn) {
00530 case 0: *str += "hist"; break;
00531 case 1: *str += "lego1"; break;
00532 case 2: *str += "lego2"; break;
00533 case 3: *str += "lego3"; break;
00534 case 4: *str += "Surf"; break;
00535 case 5: *str += "Surf1"; break;
00536 case 6: *str += "Surf2"; break;
00537 case 7: *str += "Surf3"; break;
00538 case 8: *str += "Surf4"; break;
00539 case 9: *str += "cont0"; break;
00540 case 10: *str += "cont1"; break;
00541 case 11: *str += "cont2"; break;
00542 case 12: *str += "cont3"; break;
00543 case 13: *str += "contz"; break;
00544 case 14: *str += "col"; break;
00545 case 15: *str += "colz"; break;
00546 case 16: *str += "box"; break;
00547 case 17: *str += "text"; break;
00548 }
00549 }
00550
00551 if (GetOption(index, op_HistCoord, zn)) {
00552 isany = kTRUE;
00553 if ((str->Length()>0) && (zn>0)) *str += ", ";
00554 switch (zn) {
00555 case 0: break;
00556 case 1: *str += "pol"; break;
00557 case 2: *str += "sph"; break;
00558 case 3: *str += "cyl"; break;
00559 }
00560 }
00561
00562 if (GetOption(index, op_HistError, zn)) {
00563 isany = kTRUE;
00564 if ((str->Length()>0) && (zn>0)) *str += ", ";
00565 switch (zn) {
00566 case 0: break;
00567 case 1: *str += "E1"; break;
00568 case 2: *str += "E2"; break;
00569 case 3: *str += "E3"; break;
00570 case 4: *str += "E4"; break;
00571 }
00572 }
00573
00574 return isany;
00575 }
00576
00577 void TGo4Picture::ClearHistStyles(Int_t index) {
00578 CheckIndex(index);
00579 ClearOption(index, op_HistDraw);
00580 ClearOption(index, op_HistError);
00581 ClearOption(index, op_HistCoord);
00582 }
00583
00584
00585 void TGo4Picture::CapturePadData(TVirtualPad* pad, bool takeprop) {
00586 if (pad==0) return;
00587 Clear();
00588
00589 if (takeprop) {
00590 Double_t xlow, ylow, xup, yup;
00591 pad->GetPadPar(xlow, ylow, xup, yup);
00592 SetOptionD(PictureIndex, op_Padxlow, xlow);
00593 SetOptionD(PictureIndex, op_Padylow, ylow);
00594 SetOptionD(PictureIndex, op_Padxup, xup);
00595 SetOptionD(PictureIndex, op_Padyup, yup);
00596 }
00597
00598 TObjOptLink* lnk = (TObjOptLink*) pad->GetListOfPrimitives()->FirstLink();
00599
00600 while (lnk!=0) {
00601 TObject* obj = lnk->GetObject();
00602
00603 if (obj->InheritsFrom(TVirtualPad::Class())) {
00604 TGo4Picture* subpic = new TGo4Picture(obj->GetName(), obj->GetTitle());
00605 AddSubPicture(subpic);
00606 subpic->CapturePadData(dynamic_cast<TVirtualPad*> (obj), true);
00607
00608 } else {
00609 AddObject(obj, lnk->GetOption());
00610 }
00611
00612 lnk = (TObjOptLink*) lnk->Next();
00613 }
00614 }
00615
00616 void TGo4Picture::UpdateObjectsContentFrom(TGo4Picture* source, TVirtualPad* pad) {
00617 if (source==0) return;
00618 Bool_t ObjectsModified = kFALSE;
00619 if ((fxObjects!=0) && (source->fxObjects!=0) &&
00620 (fxObjects->GetLast()==source->fxObjects->GetLast()))
00621 for (int n=0; n<=fxObjects->GetLast(); n++) {
00622 TObject* tgt = fxObjects->At(n);
00623 TObject* src = source->fxObjects->At(n);
00624
00625 if (strcmp(tgt->GetName(), src->GetName())!=0) continue;
00626 if (strcmp(tgt->ClassName(), src->ClassName())!=0) continue;
00627
00628 if (tgt->InheritsFrom(TH1::Class())) {
00629 TH1* htgt = dynamic_cast<TH1*> (tgt);
00630 TH1* hsrc = dynamic_cast<TH1*> (src);
00631 if (htgt && hsrc) {
00632 htgt->Reset();
00633 htgt->Add(hsrc);
00634 ObjectsModified = kTRUE;
00635 }
00636 } else
00637 if (tgt->InheritsFrom(TGraph::Class())) {
00638 TGraph* gtgt = dynamic_cast<TGraph*> (tgt);
00639 TGraph* gsrc = dynamic_cast<TGraph*> (src);
00640 if (gtgt && gsrc) {
00641 gsrc->Set(gtgt->GetN());
00642 for (int i=0;i<gtgt->GetN();i++) {
00643 gtgt->GetX()[i] = gsrc->GetX()[i];
00644 gtgt->GetY()[i] = gsrc->GetY()[i];
00645 }
00646 ObjectsModified = kTRUE;
00647 }
00648 }
00649 }
00650
00651 if (ObjectsModified && (pad!=0)) pad->Modified();
00652
00653 if (IsDivided() && source->IsDivided())
00654 for(Int_t posx=0; posx<GetDivX(); posx++)
00655 for(Int_t posy=0; posy<GetDivY(); posy++) {
00656 TGo4Picture* subpic = FindPic(posy,posx);
00657 TGo4Picture* subpicsrc = source->FindPic(posy,posx);
00658 TVirtualPad* subpad = (pad==0) ? 0 : pad->GetPad(posy*GetDivX() + posx + 1);
00659 if (subpic) subpic->UpdateObjectsContentFrom(subpicsrc, subpad);
00660 }
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672 }
00673
00674 void TGo4Picture::UpdateFrom(TGo4Picture* source, TClass* selectedobjclass) {
00675 if (source==0) return;
00676 Clear();
00677
00678 SetName(source->GetName());
00679 SetTitle(source->GetTitle());
00680
00681 fiNDivX = source->fiNDivX;
00682 fiNDivY = source->fiNDivY;
00683 fiPosX = source->fiPosX;
00684 fiPosY = source->fiPosY;
00685
00686 for (Int_t n=0; n<source->GetNumObjNames();n++)
00687 AddObjName(source->GetObjName(n));
00688
00689 for(Int_t n=0; n<source->GetNumObjects(); n++) {
00690 TObject* obj = source->GetObject(n);
00691 if (obj==0) continue;
00692 if ((selectedobjclass!=0) && !obj->InheritsFrom(selectedobjclass)) continue;
00693 AddObjectDirectly(obj);
00694 }
00695
00696 fiOptSize = source->fiOptSize;
00697 source->fxOptIndex.Copy(fxOptIndex);
00698 source->fxOptValue.Copy(fxOptValue);
00699
00700 if (source->fxOptObjects)
00701 fxOptObjects = (TObjArray*) source->fxOptObjects->Clone();
00702
00703 if (source->fxSubPictures)
00704 for (Int_t n=0;n<=source->fxSubPictures->GetLast();n++) {
00705 TGo4Picture* sub = dynamic_cast<TGo4Picture*> (source->fxSubPictures->At(n));
00706 if (sub) {
00707 TGo4Picture* newsub = new TGo4Picture;
00708 newsub->UpdateFrom(sub, selectedobjclass);
00709 AddSubPicture(newsub);
00710 }
00711 }
00712 }
00713
00714 void TGo4Picture::LocateObjectsFrom(TFolder* folder) {
00715 ClearObjects();
00716 if (folder==0) return;
00717
00718 for (int n=0;n<GetNumObjNames();n++) {
00719 TObject* curr = folder->FindObjectAny(GetObjName(n));
00720 if (curr!=0) {
00721 if (fxObjects==0) fxObjects = new TObjArray();
00722 fxObjects->Add(curr);
00723 }
00724 }
00725 if (fxSubPictures)
00726 for (Int_t n=0;n<=fxSubPictures->GetLast();n++) {
00727 TGo4Picture* sub = dynamic_cast<TGo4Picture*> (fxSubPictures->At(n));
00728 if (sub) sub->LocateObjectsFrom(folder);
00729 }
00730 }
00731
00732 void TGo4Picture::Clear(Option_t* option) {
00733 fiNDivX = 1;
00734 fiNDivY = 1;
00735 fiPosX = 0;
00736 fiPosY = 0;
00737 if (fxNames) { delete fxNames; fxNames = 0; }
00738 if (fxObjects) { delete fxObjects; fxObjects = 0; }
00739 if (fxSubPictures) { delete fxSubPictures; fxSubPictures = 0; }
00740 fiLastIndex = 0;
00741 fiOptSize = 0;
00742 fxOptIndex.Set(0);
00743 fxOptValue.Set(0);
00744 if (fxOptObjects) { delete fxOptObjects; fxOptObjects = 0; }
00745 }
00746
00747 void TGo4Picture::Reset() {
00748
00749 for (Int_t n=0;n<GetNumObjects();n++) {
00750 TH1* obj = dynamic_cast<TH1*> (GetObject(n));
00751 if (obj) obj->Reset();
00752 }
00753
00754 if (fxSubPictures!=0)
00755 for (int n=0;n<=fxSubPictures->GetLast();n++) {
00756 TGo4Picture* sub = dynamic_cast<TGo4Picture*> (fxSubPictures->At(n));
00757 if (sub) sub->Reset();
00758 }
00759 }
00760
00761 Int_t TGo4Picture::FindOptPos(Short_t index, Short_t typ) {
00762 Long_t zn = index + 1 + (typ << 16);
00763 for (Int_t i=0;i<fiOptSize;i++)
00764 if (fxOptIndex[i]==zn) return i;
00765 return -1;
00766 }
00767
00768 Int_t TGo4Picture::ExtendOptPos(Short_t index, Short_t typ) {
00769 Long_t zn = index + 1 + (typ << 16);
00770 if (fxOptIndex.GetSize()==fiOptSize) {
00771 fxOptIndex.Set(fiOptSize+8);
00772 fxOptValue.Set(fiOptSize+8);
00773 }
00774 fxOptIndex[fiOptSize] = zn;
00775 fiOptSize++;
00776 return fiOptSize-1;
00777 }
00778
00779 void TGo4Picture::SetOption(Short_t index, Short_t typ, Long_t value) {
00780 if (typ>=op_ObjsBound) return;
00781 Int_t pos = FindOptPos(index,typ);
00782 if (pos<0) pos = ExtendOptPos(index, typ);
00783 fxOptValue[pos] = value;
00784 }
00785
00786 Bool_t TGo4Picture::GetOption(Short_t index, Short_t typ, Long_t& value) {
00787 if (typ>=op_ObjsBound) return kFALSE;
00788 Int_t pos = FindOptPos(index,typ);
00789 if (pos<0) return kFALSE;
00790 value = fxOptValue[pos];
00791 return kTRUE;
00792 }
00793
00794 void TGo4Picture::SetOptionF(Short_t index, Short_t typ, Float_t value) {
00795 SetOption(index, typ, *((Long_t*) &value));
00796 }
00797
00798 Bool_t TGo4Picture::GetOptionF(Short_t index, Short_t typ, Float_t& value) {
00799 Long_t lvalue;
00800 Bool_t res = GetOption(index, typ, lvalue);
00801 if (res) value = *((Float_t*) &lvalue);
00802 return res;
00803 }
00804
00805 void TGo4Picture::SetOptionD(Short_t index, Short_t typ, Double_t value) {
00806 Float_t v(value);
00807 SetOption(index, typ, *((Long_t*) &v));
00808 }
00809
00810 Bool_t TGo4Picture::GetOptionD(Short_t index, Short_t typ, Double_t& value) {
00811 Long_t lvalue;
00812 Bool_t res = GetOption(index, typ, lvalue);
00813 if (res) value = *((Float_t*) &lvalue);
00814 return res;
00815 }
00816
00817 void TGo4Picture::SetObjOption(Short_t index, Short_t typ, TObject* obj) {
00818 if (obj==0) return;
00819 if (typ<op_ObjsBound) { delete obj; return; }
00820 Int_t pos = FindOptPos(index, typ);
00821 if (pos>=0) {
00822 TObject* old = fxOptObjects->RemoveAt(fxOptValue[pos]);
00823 delete old;
00824 fxOptObjects->AddAt(obj, fxOptValue[pos]);
00825 } else {
00826 pos = ExtendOptPos(index, typ);
00827 if (fxOptObjects==0) {
00828 fxOptObjects = new TObjArray();
00829 fxOptObjects->SetOwner(kTRUE);
00830 }
00831 fxOptObjects->Add(obj);
00832 fxOptValue[pos] = fxOptObjects->GetLast();
00833 }
00834 }
00835
00836 TObject* TGo4Picture::GetObjOption(Short_t index, Short_t typ) {
00837 if (typ<op_ObjsBound) return 0;
00838 Int_t pos = FindOptPos(index, typ);
00839 if (pos<0) return 0;
00840 return fxOptObjects->At(fxOptValue[pos]);
00841 }
00842
00843 void TGo4Picture::SetStrOption(Short_t index, Short_t typ, const char* value) {
00844 if (value==0) return;
00845 SetObjOption(index, typ, new TObjString(value));
00846 }
00847
00848 const char* TGo4Picture::GetStrOption(Short_t index, Short_t typ) {
00849 TObjString* ostr = dynamic_cast<TObjString*> (GetObjOption(index, typ));
00850 if (ostr==0) return 0;
00851 return ostr->String().Data();
00852 }
00853
00854 void TGo4Picture::SetDrawOption(Option_t* option, Int_t index) {
00855 CheckIndex(index);
00856 if (option==0) ClearOption(index, op_Draw);
00857 else SetStrOption(index, op_Draw, option);
00858 }
00859
00860 Option_t* TGo4Picture::GetDrawOption(Int_t index) {
00861 CheckIndex(index);
00862 return (Option_t*) GetStrOption(index, op_Draw);
00863 }
00864
00865 void TGo4Picture::SetStyle(TStyle* style, Int_t index) {
00866 if (style==0) return;
00867 CheckIndex(index);
00868 SetObjOption(index, op_Style, new TStyle(*style));
00869 }
00870
00871 TStyle* TGo4Picture::FindStyle(Int_t index) {
00872 CheckIndex(index);
00873 Int_t pos = FindOptPos(index, op_Style);
00874 if (pos<0) return 0;
00875 return dynamic_cast<TStyle*> (GetObjOption(index, op_Style));
00876 }
00877
00878 TStyle* TGo4Picture::GetStyle(Int_t index) {
00879 CheckIndex(index);
00880 TStyle* style = FindStyle(index);
00881 if (style==0) {
00882 style = new TStyle(*gStyle);
00883 SetObjOption(index, op_Style, style);
00884 }
00885 return style;
00886 }
00887
00888 void TGo4Picture::ClearOption(Short_t index, Short_t typ) {
00889 ClearOption(FindOptPos(index,typ));
00890 }
00891
00892 void TGo4Picture::ClearOption(Int_t pos) {
00893 if (pos<0) return;
00894 Int_t bnd = op_ObjsBound << 16;
00895
00896 if (fxOptIndex[pos]>=bnd) {
00897 for (Int_t i=0;i<fiOptSize;i++)
00898 if (fxOptIndex[i]>=bnd)
00899 if (fxOptValue[i]>fxOptValue[pos]) fxOptValue[i]-=1;
00900 TObject* obj = fxOptObjects->RemoveAt(fxOptValue[pos]);
00901 delete obj;
00902 fxOptObjects->Compress();
00903 if (fxOptObjects->GetLast()<0) {
00904 delete fxOptObjects;
00905 fxOptObjects = 0;
00906 }
00907 }
00908
00909 for (Int_t i=pos;i<fiOptSize-1;i++) {
00910 fxOptIndex[i] = fxOptIndex[i+1];
00911 fxOptValue[i] = fxOptValue[i+1];
00912 }
00913 fiOptSize--;
00914 }
00915
00916 void TGo4Picture::CheckIndex(Int_t& index) {
00917 if(index==UndefIndex)
00918 if (fiLastIndex>=PictureIndex) index = fiLastIndex;
00919 else index = PictureIndex;
00920 }
00921
00922
00923 void TGo4Picture::ClearAllOptions(Short_t index) {
00924 if (index<0) {
00925 fxOptIndex.Set(0);
00926 fxOptValue.Set(0);
00927 if (fxOptObjects) {
00928 delete fxOptObjects;
00929 fxOptObjects = 0;
00930 }
00931 } else {
00932 Int_t pos = 0;
00933 while (pos<fiOptSize)
00934 if ((fxOptIndex[pos] & 0x7fff)==index+1) ClearOption(pos);
00935 else pos++;
00936 }
00937 }
00938
00939 TAxis* TGo4Picture::FindAxis(TVirtualPad* pad, Int_t num) {
00940 if (pad==0) return 0;
00941 TIter next(pad->GetListOfPrimitives());
00942 TObject* obj = 0;
00943 while ( (obj=next()) !=0 ) {
00944 if (obj->InheritsFrom(TH1::Class())) {
00945 TH1* h = (TH1*) obj;
00946 switch (num) {
00947 case 0: return h->GetXaxis();
00948 case 1: return h->GetYaxis();
00949 case 2: return h->GetZaxis();
00950 default: return 0;
00951 }
00952 }
00953 if (obj->InheritsFrom(TGraph::Class())) {
00954 TGraph* gr = (TGraph*) obj;
00955 switch (num) {
00956 case 0: return gr->GetXaxis();
00957 case 1: return gr->GetYaxis();
00958 }
00959 }
00960 }
00961 return 0;
00962 }
00963
00964 Int_t TGo4Picture::GetObjAttIndex(TObject* obj) {
00965 if (obj==0) return UndefIndex;
00966 for (Int_t n=0;n<GetNumObjNames();n++)
00967 if (strcmp(GetObjName(n),obj->GetName())==0) return n;
00968 return UndefIndex;
00969 }
00970
00971 void TGo4Picture::DrawPictureObjects(TVirtualPad* pad) {
00972 if (pad==0) return;
00973 pad->cd();
00974
00975 GetLineAtt(dynamic_cast<TAttLine*> (pad), PictureIndex);
00976 GetFillAtt(dynamic_cast<TAttFill*> (pad), PictureIndex);
00977
00978
00979 for (Int_t n=0;n<GetNumObjects();n++) {
00980 TObject* obj = GetObject(n);
00981 Int_t attindex = GetObjAttIndex(obj);
00982
00983 TStyle* style = FindStyle(attindex);
00984 if (style) {
00985 TStyle* oldstyle = gStyle;
00986 style->cd();
00987 obj->UseCurrentStyle();
00988 oldstyle->cd();
00989 }
00990
00991 GetLineAtt(dynamic_cast<TAttLine*> (obj), attindex);
00992 GetFillAtt(dynamic_cast<TAttFill*> (obj), attindex);
00993 GetMarkerAtt(dynamic_cast<TAttMarker*> (obj), attindex);
00994
00995 if (obj->InheritsFrom(TH1::Class())) {
00996 TString opt(GetDrawOption(attindex));
00997 if (!AppendHistStylesToString(&opt,attindex))
00998 AppendHistStylesToString(&opt,PictureIndex);
00999 obj->Draw(opt.Data());
01000 } else
01001 obj->Draw(GetDrawOption(attindex));
01002 }
01003
01004
01005 TStyle* style = FindStyle(PictureIndex);
01006 if (style) {
01007 TStyle* oldstyle = gStyle;
01008 style->cd();
01009 pad->UseCurrentStyle();
01010 oldstyle->cd();
01011 }
01012
01013 Double_t min, max;
01014 if (GetRangeX(min,max)) {
01015 TAxis* axis = FindAxis(pad, 0);
01016 if (axis) axis->SetRangeUser(min, max);
01017 }
01018
01019 if (GetRangeY(min,max)) {
01020 TAxis* axis = FindAxis(pad, 1);
01021 if (axis) axis->SetRangeUser(min, max);
01022 }
01023
01024 GetLogScales(pad);
01025
01026 if (!IsDivided() && (fxSubPictures!=0))
01027 for (int n=0;n<=fxSubPictures->GetLast();n++) {
01028 TGo4Picture* sub = (TGo4Picture*) fxSubPictures->At(n);
01029 Double_t xlow, ylow, xup, yup;
01030
01031 if (sub->GetOptionD(PictureIndex, op_Padxlow, xlow) &&
01032 sub->GetOptionD(PictureIndex, op_Padylow, ylow) &&
01033 sub->GetOptionD(PictureIndex, op_Padxup, xup) &&
01034 sub->GetOptionD(PictureIndex, op_Padyup, yup)) {
01035 pad->cd();
01036 TPad* subpad = new TPad(sub->GetName(), sub->GetTitle(),
01037 xlow, ylow, xup, yup);
01038 subpad->Draw();
01039 sub->DrawPictureObjects(subpad);
01040 }
01041 }
01042
01043 pad->Modified();
01044 }
01045
01046 TVirtualPad* TGo4Picture::DrawHeader(TVirtualPad* pad) {
01047 if (!IsDrawHeader()) return pad;
01048
01049 pad->Divide(1, 2);
01050
01051 TVirtualPad* pad1 = pad->GetPad(1);
01052 pad1->SetPad(0.,0.96,1.,1.0);
01053 pad1->SetBorderSize(0);
01054
01055 TDatime t;
01056 TString txt(t.AsString());
01057 txt += " Picture: ";
01058 txt += GetName();
01059 if (strcmp(GetName(), GetTitle())!=0) {
01060 txt += " Title: ";
01061 txt += GetTitle();
01062 }
01063
01064 TText* l = new TText(0.01,0.5,txt.Data());
01065 l->SetNDC();
01066 l->SetTextAlign(12);
01067 l->SetTextSize(0.5);
01068 pad1->cd();
01069 l->Draw();
01070
01071 TVirtualPad* pad2 = pad->GetPad(2);
01072 pad2->SetPad(0.,0.0,1.,0.96);
01073 pad2->SetBorderSize(0);
01074
01075 return pad2;
01076 }
01077
01078
01079 void TGo4Picture::DrawPic(TVirtualPad* pad) {
01080 if (pad==0) return;
01081 if (IsDivided()) {
01082 pad->Divide(GetDivX(), GetDivY());
01083 for(Int_t posx=0; posx<GetDivX(); posx++)
01084 for(Int_t posy=0; posy<GetDivY(); posy++) {
01085 TGo4Picture* sub = FindPic(posy,posx);
01086 if (sub) sub->DrawPic(pad->GetPad(posy*GetDivX() + posx + 1));
01087 }
01088 } else DrawPictureObjects(pad);
01089 }
01090
01091 void TGo4Picture::Draw(Option_t* option) {
01092 if (gPad==0) {
01093 TCanvas* c = new TCanvas();
01094 c->cd();
01095 }
01096 if (gPad==0) return;
01097 DrawPic(DrawHeader(gPad));
01098 }
01099
01100 void TGo4Picture::PrintPic(int shift) {
01101 for (int n=0;n<shift;n++) cout << ' ';
01102 if (IsDivided()) {
01103 cout << "Divided numx:" << GetDivX() << " numy:" << GetDivY() << endl;
01104 for(Int_t posx=0; posx<GetDivX(); posx++)
01105 for(Int_t posy=0; posy<GetDivY(); posy++) {
01106 for (int n=0;n<shift+2;n++) cout << ' ';
01107 cout << "subpic x:" << posx << " y:" << posy << endl;
01108 TGo4Picture* sub = FindPic(posy,posx);
01109 if (sub) sub->PrintPic(shift+4);
01110 }
01111 } else {
01112 cout << "Objects:" << endl;
01113 for (Int_t num=0; num<GetNumObjNames(); num++) {
01114 const char* objname = GetObjName(num);
01115 for (int n=0;n<shift+2;n++) cout << ' ';
01116 cout << objname;
01117
01118 Option_t* drawopt = GetDrawOption(num);
01119 if (drawopt) cout << " opt: " << drawopt;
01120
01121 TObject* obj = FindObject(objname);
01122 if (obj!=0) cout << " class: " << obj->ClassName();
01123 cout << endl;
01124 }
01125 }
01126 }
01127
01128 void TGo4Picture::Print(Option_t* option) const {
01129 cout << "Picture " << GetName() << endl;
01130 ((TGo4Picture*)this)->PrintPic(2);
01131 }
01132
01133
01134
01135 void TGo4Picture::AddSubPicture(TGo4Picture* pic) {
01136 if (pic == 0) return;
01137 if (fxSubPictures==0) {
01138 fxSubPictures = new TObjArray();
01139 fxSubPictures->SetOwner(kTRUE);
01140 }
01141 fxSubPictures->Add(pic);
01142 }
01143
01144 ClassImp(TGo4Picture)
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177