Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4CanvasProxy.h"
00015
00016 #include "TROOT.h"
00017 #include "TObjArray.h"
00018 #include "TClass.h"
00019 #include "TFrame.h"
00020 #include "TPaveText.h"
00021 #include "TObjString.h"
00022 #include "THStack.h"
00023 #include "TH1.h"
00024
00025 #include "TGo4Slot.h"
00026 #include "TGo4ObjectProxy.h"
00027 #include "TGo4HStackProxy.h"
00028 #include "TGo4ObjectManager.h"
00029
00030 class TGo4CanvasLevelIter : public TGo4LevelIter {
00031 protected:
00032 TIterator* fIter;
00033 TObject* fCurrent;
00034 TObjArray fStacks;
00035 public:
00036 TGo4CanvasLevelIter(TPad* pad) :
00037 TGo4LevelIter(),
00038 fIter(0),
00039 fCurrent(0),
00040 fStacks()
00041 {
00042 fIter = pad->GetListOfPrimitives()->MakeIterator();
00043 fStacks.SetOwner(kTRUE);
00044 }
00045
00046 virtual ~TGo4CanvasLevelIter()
00047 {
00048 delete fIter;
00049 }
00050
00051 virtual Bool_t next()
00052 {
00053 bool skip = false;
00054 do {
00055 skip = false;
00056 fCurrent = fIter->Next();
00057
00058 if (fCurrent==0) break;
00059
00060 TFrame* fr = dynamic_cast<TFrame*>(fCurrent);
00061 if (fr!=0) { skip = true; continue; }
00062
00063 TPaveText* ptxt = dynamic_cast<TPaveText*> (fCurrent);
00064 if ((ptxt!=0) && (strcmp(ptxt->GetName(),"title")==0)) { skip = true; continue; }
00065
00066 if (dynamic_cast<TPave*>(fCurrent) != 0) { skip = true; continue; }
00067
00068 if (fCurrent->GetName()==0) { skip = true; continue; }
00069
00070 if (strlen(fCurrent->GetName())==0) { skip = true; continue; }
00071
00072 if (strcmp(fCurrent->GetName(), fCurrent->ClassName())==0) { skip = true; continue; }
00073
00074
00075 if (fStacks.FindObject(fCurrent->GetName()) && fCurrent->InheritsFrom(TH1F::Class())) { skip = true; continue; }
00076
00077 } while(skip);
00078
00079 if (fCurrent && fCurrent->InheritsFrom(THStack::Class()))
00080 fStacks.Add(new TObjString(fCurrent->GetName()));
00081
00082 return (fCurrent!=0);
00083 }
00084
00085 virtual Bool_t isfolder()
00086 {
00087 return (dynamic_cast<TPad*>(fCurrent)!=0) ||
00088 (dynamic_cast<THStack*>(fCurrent)!=0);
00089 }
00090
00091 virtual TGo4LevelIter* subiterator()
00092 {
00093 TPad* subpad = dynamic_cast<TPad*>(fCurrent);
00094 if (subpad!=0) return new TGo4CanvasLevelIter(subpad);
00095 THStack* hs = dynamic_cast<THStack*> (fCurrent);
00096 if (hs!=0) return TGo4HStackProxy::ProduceIter(hs);
00097 return 0;
00098 }
00099
00100 virtual const char* name()
00101 {
00102 return fCurrent->GetName();
00103 }
00104
00105 virtual const char* info()
00106 {
00107 return fCurrent->ClassName();
00108 }
00109
00110 virtual Int_t GetKind()
00111 {
00112 return isfolder() ? TGo4Access::kndFolder : TGo4Access::kndObject;
00113 }
00114
00115 virtual const char* GetClassName()
00116 {
00117 return fCurrent->ClassName();
00118 }
00119 };
00120
00121
00122
00123 TGo4CanvasProxy::TGo4CanvasProxy() :
00124 TGo4Proxy(),
00125 fCanvas(0),
00126 fOwner(kFALSE)
00127 {
00128 }
00129
00130 TGo4CanvasProxy::TGo4CanvasProxy(TCanvas* c, Bool_t owner) :
00131 TGo4Proxy(),
00132 fCanvas(c),
00133 fOwner(owner)
00134 {
00135 }
00136
00137 TGo4CanvasProxy::~TGo4CanvasProxy()
00138 {
00139 if (fOwner) delete fCanvas;
00140 }
00141
00142 Int_t TGo4CanvasProxy::GetObjectKind()
00143 {
00144 return (fCanvas!=0) ? TGo4Access::kndFolder : TGo4Access::kndNone;
00145 }
00146
00147 const char* TGo4CanvasProxy::GetContainedClassName()
00148 {
00149 return fCanvas ? fCanvas->ClassName() : 0;
00150 }
00151
00152 void TGo4CanvasProxy::Initialize(TGo4Slot* slot)
00153 {
00154 TGo4ObjectManager* om = slot->GetOM();
00155 if (om!=0) om->RegisterObjectWith(fCanvas, slot);
00156 }
00157
00158 void TGo4CanvasProxy::Finalize(TGo4Slot* slot)
00159 {
00160 TGo4ObjectManager* om = slot->GetOM();
00161 if (om!=0) om->UnregisterObject(fCanvas, slot);
00162 }
00163
00164 Bool_t TGo4CanvasProxy::RemoveRegisteredObject(TObject* obj)
00165 {
00166 if (obj==fCanvas) {
00167 fCanvas = 0;
00168 fOwner = kFALSE;
00169 }
00170 return kFALSE;
00171 }
00172
00173 void TGo4CanvasProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
00174 {
00175 const char* objname = 0;
00176 if (fCanvas!=0)
00177 objname = fCanvas->GetName();
00178
00179 if (!onlyobjs)
00180 slot->SetPar("CanvasProxy::CanvasName", objname);
00181
00182 if ((dir==0) || (fCanvas==0)) return;
00183
00184 dir->cd();
00185
00186 fCanvas->Write(objname);
00187 }
00188
00189 void TGo4CanvasProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
00190 {
00191 const char* objname = slot->GetPar("CanvasProxy::CanvasName");
00192 if ((objname==0) || (dir==0)) return;
00193
00194 dir->cd();
00195
00196 AssignObject(slot, dir->Get(objname), kTRUE);
00197 }
00198
00199 Bool_t TGo4CanvasProxy::IsAcceptObject(TClass* cl)
00200 {
00201 return (cl!=0) && cl->InheritsFrom(TCanvas::Class());
00202 }
00203
00204 Bool_t TGo4CanvasProxy::AssignObject(TGo4Slot* slot, TObject* obj, Bool_t owner)
00205 {
00206 Finalize(slot);
00207 if ((fCanvas!=0) && fOwner) delete fCanvas;
00208
00209 fCanvas = dynamic_cast<TCanvas*> (obj);
00210 fOwner = owner && (fCanvas!=0);
00211
00212 if ((fCanvas==0) && (obj!=0) && owner) delete obj;
00213
00214 Initialize(slot);
00215
00216 slot->ForwardEvent(slot, TGo4Slot::evObjAssigned);
00217
00218 return fCanvas!=0;
00219 }
00220
00221 TObject* TGo4CanvasProxy::GetAssignedObject()
00222 {
00223 return fCanvas;
00224 }
00225
00226 TGo4Access* TGo4CanvasProxy::ProduceProxy(TCanvas* canv, const char* name)
00227 {
00228 if (canv==0) return 0;
00229 if ((name==0) || (*name==0)) return new TGo4ObjectAccess(canv);
00230
00231 TPad* curpad = canv;
00232 const char* curname = name;
00233
00234 while (curpad!=0) {
00235 const char* slash = strchr(curname,'/');
00236 UInt_t len = (slash!=0) ? slash - curname : strlen(curname);
00237 TIter iter(curpad->GetListOfPrimitives());
00238 TObject* obj = 0;
00239 while ((obj = iter())!=0)
00240 if ((strlen(obj->GetName())==len) &&
00241 (strncmp(obj->GetName(), curname, len)==0)) break;
00242 if (obj==0) return 0;
00243
00244
00245
00246 if (slash==0) return new TGo4ObjectAccess(obj);
00247
00248 curname = slash+1;
00249
00250 curpad = dynamic_cast<TPad*>(obj);
00251
00252 if (curpad==0) {
00253 THStack* hs = dynamic_cast<THStack*> (obj);
00254 if (hs!=0)
00255 return TGo4HStackProxy::ProduceProxy(hs, curname);
00256 }
00257 }
00258
00259 return 0;
00260 }
00261
00262 TGo4LevelIter* TGo4CanvasProxy::ProduceIter(TCanvas* canv)
00263 {
00264 return new TGo4CanvasLevelIter(canv);
00265 }