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