Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4DrawCloneProxy.h"
00015
00016 #include "TH1.h"
00017 #include "TH2.h"
00018 #include "TGraph.h"
00019 #include "TString.h"
00020
00021 #include "TGo4LockGuard.h"
00022 #include "TGo4ObjectManager.h"
00023 #include "TGo4Picture.h"
00024 #include "TGo4BrowserProxy.h"
00025 #include "TGo4ViewPanel.h"
00026
00027
00028 TGo4DrawCloneProxy::TGo4DrawCloneProxy(TGo4Slot* slot, TGo4ViewPanel* panel) :
00029 TGo4LinkProxy(slot),
00030 fClone(0),
00031 fPanel(panel),
00032 fParentSlot(0)
00033 {
00034 }
00035
00036 TGo4DrawCloneProxy::~TGo4DrawCloneProxy()
00037 {
00038 if (fClone!=0) delete fClone;
00039 }
00040
00041 Bool_t TGo4DrawCloneProxy::AssignClone(TObject* obj, TGo4Slot* slot)
00042 {
00043 TGo4LockGuard lock(0,true);
00044
00045 CleanupClone(slot);
00046 if (obj==0) return kFALSE;
00047
00048 if (!obj->InheritsFrom(TH1::Class()) &&
00049 !obj->InheritsFrom(TGraph::Class())) return kFALSE;
00050
00051 fClone = obj->Clone();
00052 if (fClone->InheritsFrom(TH1::Class()))
00053 ((TH1*) fClone)->SetDirectory(0);
00054 TGo4ObjectManager* om = slot->GetOM();
00055 if ((om!=0) && (fClone!=0))
00056 om->RegisterObjectWith(fClone, slot);
00057
00058 return kTRUE;
00059 }
00060
00061 void TGo4DrawCloneProxy::CleanupClone(TGo4Slot* slot)
00062 {
00063 if (fClone==0) return;
00064 TGo4ObjectManager* om = slot->GetOM();
00065 if (om!=0) {
00066 om->RecursiveRemove(fClone);
00067 om->UnregisterObject(fClone, slot);
00068 }
00069 delete fClone;
00070 fClone = 0;
00071 }
00072
00073 void TGo4DrawCloneProxy::ChangeTitle(TObject* obj)
00074 {
00075 TNamed* src = dynamic_cast<TNamed*> (obj);
00076 TNamed* tgt = dynamic_cast<TNamed*> (fClone);
00077
00078 TGo4Picture* padopt = fPanel->GetPadOptions(fParentSlot->GetParent());
00079
00080 if ((tgt==0) || (src==0) || (padopt==0)) return;
00081 TString title = src->GetTitle();
00082
00083 const char* stime = TGo4BrowserProxy::ItemTime(GetLink());
00084 const char* sdate = TGo4BrowserProxy::ItemDate(GetLink());
00085 const char* itemname = TGo4BrowserProxy::GetLinkedName(fParentSlot);
00086
00087 if ((stime!=0) && padopt->IsTitleTime()) {
00088 title+= " ";
00089 title+=stime;
00090 }
00091 if ((sdate!=0) && padopt->IsTitleDate()) {
00092 title+= " ";
00093 title+=sdate;
00094 }
00095 if ((itemname!=0) && padopt->IsTitleItem()) {
00096 title+= " ";
00097 title+=itemname;
00098 }
00099 tgt->SetTitle(title.Data());
00100 }
00101
00102 void TGo4DrawCloneProxy::UpdateTitle()
00103 {
00104 if (GetLink()!=0)
00105 ChangeTitle(GetLink()->GetAssignedObject());
00106 }
00107
00108 Bool_t TGo4DrawCloneProxy::RemoveRegisteredObject(TObject* obj)
00109 {
00110 if (obj==fClone) fClone = 0;
00111 return kFALSE;
00112 }
00113
00114 void TGo4DrawCloneProxy::Initialize(TGo4Slot* slot)
00115 {
00116 TGo4LinkProxy::Initialize(slot);
00117 if (fClone!=0) {
00118 delete fClone;
00119 Error("Initialize"," Problem in TGo4DrawCloneProxy");
00120 }
00121 fClone = 0;
00122 fParentSlot = slot;
00123
00124 if (GetLink()!=0) {
00125 TObject* obj = GetLink()->GetAssignedObject();
00126 if (obj!=0) AssignClone(obj, slot);
00127 }
00128 }
00129
00130 void TGo4DrawCloneProxy::Finalize(TGo4Slot* slot)
00131 {
00132 CleanupClone(slot);
00133 TGo4LinkProxy::Finalize(slot);
00134 fParentSlot = 0;
00135 }
00136
00137 TObject* TGo4DrawCloneProxy::GetAssignedObject()
00138 {
00139 return (fClone!=0) ? fClone : TGo4LinkProxy::GetAssignedObject();
00140 }
00141
00142 Bool_t TGo4DrawCloneProxy::ProcessEvent(TGo4Slot* slot, TGo4Slot* source, Int_t id, void* param)
00143 {
00144 if (id==TGo4Slot::evObjAssigned) {
00145 TObject* obj = GetLink()->GetAssignedObject();
00146 AssignClone(obj, slot);
00147 ChangeTitle(obj);
00148 } else
00149 if ((id==TGo4Slot::evObjUpdated) || (id==TGo4Slot::evContAssigned)) {
00150 bool res = kFALSE;
00151 TObject* obj = GetLink()->GetAssignedObject();
00152 if (obj!=0) {
00153 Int_t rebinx(0), rebiny(0);
00154 if (fClone!=0)
00155 res = TGo4BrowserProxy::UpdateObjectContent(fClone, obj, &rebinx, &rebiny);
00156 if (!res)
00157 res = AssignClone(obj, slot);
00158 else {
00159 if (rebinx>1) fParentSlot->SetIntPar("::HasRebinX",rebinx);
00160 else fParentSlot->RemovePar("::HasRebinX");
00161 if (rebiny>1) fParentSlot->SetIntPar("::HasRebinY",rebiny);
00162 else fParentSlot->RemovePar("::HasRebinY");
00163 }
00164 }
00165
00166 if (!res) CleanupClone(slot);
00167 else ChangeTitle(obj);
00168 }
00169
00170 return TGo4LinkProxy::ProcessEvent(slot, source, id, param);
00171 }
00172
00173 void TGo4DrawCloneProxy::PerformRebin()
00174 {
00175 if (fClone==0) return;
00176
00177 Int_t rebinx(0), rebiny(0);
00178 fParentSlot->GetIntPar("::DoRebinX", rebinx);
00179 fParentSlot->RemovePar("::DoRebinX");
00180 fParentSlot->GetIntPar("::DoRebinY", rebiny);
00181 fParentSlot->RemovePar("::DoRebinY");
00182
00183 if ((rebinx<2) && (rebiny<2)) return;
00184
00185 if (rebinx==0) rebinx = 1;
00186 if (rebiny==0) rebiny = 1;
00187
00188 TH2* h2 = dynamic_cast<TH2*> (fClone);
00189 if (h2!=0) {
00190 h2->Rebin2D(rebinx, rebiny);
00191 return;
00192 }
00193
00194 TH1* h1 = dynamic_cast<TH1*> (fClone);
00195 if (h1!=0) h1->Rebin(rebinx);
00196 }
00197