Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4DrawCloneProxy.cxx

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

Generated on Fri Nov 28 12:59:21 2008 for Go4-v3.04-1 by  doxygen 1.4.2