Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4GUI/TGo4PreviewPanelStatus.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE 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 "TGo4PreviewPanelStatus.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TPad.h"
00021 #include "TCanvas.h"
00022 #include "TRefArray.h"
00023 #include "TList.h"
00024 
00025 #include "TGo4PreviewPanelSlots.h"
00026 #include "TGo4PadOptions.h"
00027 
00028 TGo4PreviewPanelStatus::TGo4PreviewPanelStatus(const char* name, const char* title)
00029                     :TGo4Status(name, title), fxSlots(0)
00030 {
00031       PadOptionList= new TList;
00032       listiter = PadOptionList->MakeIterator();
00033       ListOfPads= new TRefArray();
00034 }
00035 
00036 TGo4PreviewPanelStatus::~TGo4PreviewPanelStatus()
00037 {
00038    //   cout << "TGo4PreviewPanelStatus::~TGo4PreviewPanelStatus()"<< endl;
00039        // TGo4LockGuard Global;
00040       PadOptionList->Delete();
00041       delete PadOptionList;
00042       delete listiter;
00043       //ListOfPads->Clear("nodelete");
00044       delete ListOfPads;
00045 }
00046 
00047 void TGo4PreviewPanelStatus::SetPadDrawOption(TPad * SelectedPad, const char *Option, bool DragAddOption)
00048 {
00049    TObject *entry;
00050    bool IntheList=kFALSE;
00051     // TGo4LockGuard Global;
00052     listiter->Reset();
00053    while((entry=listiter->Next()) !=0) {
00054       if(((TGo4PadOptions *)entry)->fxPad==SelectedPad){
00055              IntheList=kTRUE;
00056    //       (dynamic_cast<TGo4PadOptions *>(entry))->fxOption=new TString(Option);
00057           (dynamic_cast<TGo4PadOptions *>(entry))->fxDragAddOption=DragAddOption;
00058           (dynamic_cast<TGo4PadOptions *>(entry))->setHisDrawStyle(Option);
00059 
00060       }
00061    }
00062    if(!IntheList){
00063     //   cout << "TGo4PreviewPanelStatus::SetPadDrawOption" << endl;
00064 
00065       //cout << "  TGo4PreviewPanelStatus::SetPadDrawOption(dragaddopt) for "<<SelectedPad->GetName()<<endl;
00066       fxTGo4PadOptions= new TGo4PadOptions(SelectedPad,Option, DragAddOption);
00067       PadOptionList->Add(fxTGo4PadOptions);
00068       ListOfPads->AddLast(SelectedPad);
00069    }
00070 }
00071 
00072 void TGo4PreviewPanelStatus::SetPadDrawOption(TPad * SelectedPad, const char *Option)
00073 {
00074    TObject *entry;
00075    bool IntheList=kFALSE;
00076     // TGo4LockGuard Global;
00077     listiter->Reset();
00078    while((entry=listiter->Next()) !=0) {
00079       if(((TGo4PadOptions *)entry)->fxPad==SelectedPad){
00080              IntheList=kTRUE;
00081            (dynamic_cast<TGo4PadOptions *>(entry))->setHisDrawStyle(Option);
00082       }
00083    }
00084    if(!IntheList){
00085       //cout << "  TGo4PreviewPanelStatus::SetPadDrawOption new for "<<SelectedPad->GetName() << endl;
00086       fxTGo4PadOptions= new TGo4PadOptions(SelectedPad,Option);
00087       PadOptionList->Add(fxTGo4PadOptions);
00088       ListOfPads->AddLast(SelectedPad);
00089    }
00090 }
00091 
00092 
00093 
00094 void TGo4PreviewPanelStatus::SetPadDrawOption(TPad * SelectedPad, Int_t Xmin, Int_t Xmax, Int_t Ymin, Int_t Ymax)
00095 {
00096    if(SelectedPad==0) return;
00097    TObject *entry=0;
00098    TGo4PadOptions* pop=0;
00099    bool IntheList=kFALSE;
00100     listiter->Reset();
00101    while((entry=listiter->Next()) !=0) 
00102       {
00103          pop=dynamic_cast<TGo4PadOptions*>(entry);
00104          if(pop && pop->fxPad==SelectedPad)
00105           {  
00106             IntheList=kTRUE;
00107             break;
00108           }
00109       }
00110    if(!IntheList){
00111       pop= new TGo4PadOptions(SelectedPad,"");
00112       PadOptionList->Add(pop);
00113       ListOfPads->AddLast(SelectedPad);
00114    }
00115    pop->SetHistogramFullRange(Xmin,Xmax,Ymin,Ymax);
00116    Int_t xlog=SelectedPad->GetLogx();
00117    Int_t ylog=SelectedPad->GetLogy();
00118    Int_t zlog=SelectedPad->GetLogz();
00119    pop->SetHisXStyle(xlog);
00120    pop->SetHisYStyle(ylog);
00121    pop->SetHisZStyle(zlog);
00122 
00123 }
00124 
00125 void TGo4PreviewPanelStatus::SetPadHistogramStats(TPad * SelectedPad, Bool_t showstatistics)
00126 {
00127 TObject *entry;
00128 bool IntheList=kFALSE;
00129  // TGo4LockGuard Global;
00130 listiter->Reset();
00131 while((entry=listiter->Next()) !=0) {
00132    if(((TGo4PadOptions *)entry)->fxPad==SelectedPad){
00133           IntheList=kTRUE;
00134         (dynamic_cast<TGo4PadOptions *>(entry))->SetHisStats(showstatistics);
00135    }
00136 }
00137 if(!IntheList){
00138    fxTGo4PadOptions= new TGo4PadOptions(SelectedPad,"");
00139    fxTGo4PadOptions->SetHisStats(showstatistics);
00140    PadOptionList->Add(fxTGo4PadOptions);
00141    ListOfPads->AddLast(SelectedPad);
00142 
00143 }
00144 
00145 }
00146 
00147 
00148 Bool_t TGo4PreviewPanelStatus::GetPadHistogramStats(TPad * SelectedPad)
00149 {
00150 TObject *entry;
00151 // TGo4LockGuard Global;
00152 Bool_t showstatistics=kTRUE;
00153 listiter->Reset();
00154 while((entry=listiter->Next()) !=0) {
00155 if(((TGo4PadOptions *)entry)->fxPad==SelectedPad){
00156    showstatistics =(dynamic_cast <TGo4PadOptions *> (entry))->IsHisStats();
00157  }
00158 }
00159 return showstatistics;
00160 
00161 }
00162 
00163 void TGo4PreviewPanelStatus::SetPadHistogramTitle(TPad * SelectedPad, Bool_t showtitle)
00164 {
00165 TObject *entry;
00166 bool IntheList=kFALSE;
00167  // TGo4LockGuard Global;
00168 listiter->Reset();
00169 while((entry=listiter->Next()) !=0) {
00170    if(((TGo4PadOptions *)entry)->fxPad==SelectedPad){
00171           IntheList=kTRUE;
00172         (dynamic_cast<TGo4PadOptions *>(entry))->SetHisTitle(showtitle);
00173    }
00174 }
00175 if(!IntheList){
00176    fxTGo4PadOptions= new TGo4PadOptions(SelectedPad,"");
00177    fxTGo4PadOptions->SetHisTitle(showtitle);
00178    PadOptionList->Add(fxTGo4PadOptions);
00179    ListOfPads->AddLast(SelectedPad);
00180 }
00181 }
00182 
00183 
00184 Bool_t TGo4PreviewPanelStatus::GetPadHistogramTitle(TPad * SelectedPad)
00185 {
00186 TObject *entry;
00187 // TGo4LockGuard Global;
00188 Bool_t showtitle=kTRUE;
00189 listiter->Reset();
00190 while((entry=listiter->Next()) !=0) {
00191 if(((TGo4PadOptions *)entry)->fxPad==SelectedPad){
00192    showtitle =(dynamic_cast <TGo4PadOptions *> (entry))->IsHisTitle();
00193  }
00194 }
00195 return showtitle;
00196 
00197 }
00198 
00200 void TGo4PreviewPanelStatus::SetPadLegend(TPad * SelectedPad, Bool_t drawlegend)
00201 {
00202 TObject *entry;
00203 bool IntheList=kFALSE;
00204  // TGo4LockGuard Global;
00205 listiter->Reset();
00206 while((entry=listiter->Next()) !=0) {
00207    if(((TGo4PadOptions *)entry)->fxPad==SelectedPad){
00208           IntheList=kTRUE;
00209         (dynamic_cast<TGo4PadOptions *>(entry))->SetLegendDraw(drawlegend);
00210    }
00211 }
00212 if(!IntheList){
00213    fxTGo4PadOptions= new TGo4PadOptions(SelectedPad,"");
00214    fxTGo4PadOptions->SetLegendDraw(drawlegend);
00215    PadOptionList->Add(fxTGo4PadOptions);
00216    ListOfPads->AddLast(SelectedPad);
00217 
00218 }
00219 }
00220 
00221 
00222 Bool_t TGo4PreviewPanelStatus::GetPadLegend(TPad * SelectedPad)
00223 {
00224 TObject *entry;
00225 // TGo4LockGuard Global;
00226 Bool_t showstatistics=kTRUE;
00227 listiter->Reset();
00228 while((entry=listiter->Next()) !=0) {
00229 if(((TGo4PadOptions *)entry)->fxPad==SelectedPad){
00230    showstatistics =(dynamic_cast <TGo4PadOptions *> (entry))->IsLegendDraw();
00231  }
00232 }
00233 return showstatistics;
00234 
00235 }
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 void TGo4PreviewPanelStatus::SetPadCrosshair(TPad * SelectedPad, Bool_t showcross)
00245 {
00246 // As ROOT crosshair behaviour has changed since version 4.00/08
00247 // we do not support different crosshair modes in subpads anymore
00248 // for these new ROOT versions. JA
00249 TObject *entry;
00250 bool IntheList=kFALSE;
00251  // TGo4LockGuard Global;
00252 listiter->Reset();
00253 while((entry=listiter->Next()) !=0) {
00254    TGo4PadOptions* popt=dynamic_cast<TGo4PadOptions *>(entry);
00255    if(popt->fxPad==SelectedPad)
00256       {
00257           IntheList=kTRUE;
00258           popt->SetCrosshair(showcross);
00259       }
00260 #if __GO4ROOTVERSION__ >= 40008
00261    else
00262       {
00263         popt->SetCrosshair(showcross); // workaround: all pads have same crossoption
00264       }
00265 
00266 #endif
00267 }
00268 if(!IntheList){
00269    fxTGo4PadOptions= new TGo4PadOptions(SelectedPad,"");
00270    fxTGo4PadOptions->SetCrosshair(showcross);
00271    PadOptionList->Add(fxTGo4PadOptions);
00272    ListOfPads->AddLast(SelectedPad);
00273 
00274 }
00275 SelectedPad->SetCrosshair(showcross);
00276 #if __GO4ROOTVERSION__ >= 40008
00277 //SelectedPad->GetCanvas()->SetCrosshair(2);
00278 // note: this does not work as described/intended in ROOT!
00279 // thus no different crossmodes for subpads anymore, sorry...
00280 #endif
00281 SelectedPad->Modified();
00282 SelectedPad->Update();
00283 
00284 
00285 #if __GO4ROOTVERSION__ < 40008
00286 
00287 // have to change the status of all subpads as well, since
00288 // root treats crosshair recursive to all subpads:
00289 TObject* obj=0;
00290 TIter   next(SelectedPad->GetListOfPrimitives());
00291     while ((obj = next()))
00292         {
00293           if (obj->InheritsFrom(TPad::Class()))
00294               {
00295                  TPad *pad = dynamic_cast<TPad*>(obj);
00296                  pad->SetCrosshair(showcross);
00297                  pad->Modified();
00298                  pad->Update();
00299                  SetPadCrosshair(pad,showcross);
00300               }
00301         }
00302 #endif
00303 
00304 }
00305 
00306 
00307 Bool_t TGo4PreviewPanelStatus::GetPadCrosshair(TPad * SelectedPad)
00308 {
00309 TObject *entry;
00310 // TGo4LockGuard Global;
00311 Bool_t showstatistics=kTRUE;
00312 listiter->Reset();
00313 while((entry=listiter->Next()) !=0) {
00314 if(((TGo4PadOptions *)entry)->fxPad==SelectedPad){
00315    showstatistics =(dynamic_cast <TGo4PadOptions *> (entry))->IsCrosshair();
00316  }
00317 }
00318 return showstatistics;
00319 
00320 }
00321 
00322 
00323 
00324 Bool_t TGo4PreviewPanelStatus::GetPadDragOption(TPad *SelectedPad)
00325 {
00326     TObject *entry;
00327     // TGo4LockGuard Global;
00328     bool Option=kFALSE;
00329     listiter->Reset();
00330    while((entry=listiter->Next()) !=0) {
00331       if(((TGo4PadOptions *)entry)->fxPad==SelectedPad){
00332          Option =((TGo4PadOptions *)entry)->fxDragAddOption;
00333       }
00334    }
00335 //   cout << "TGo4PreviewPanelStatus::GetPadDragOption   Option"<< Option <<endl;
00336    return Option;
00337 }
00338 
00339 TGo4PadOptions * TGo4PreviewPanelStatus::GetPadOptions(TPad * Pad)
00340 {
00341     TObject *entry;
00342     // TGo4LockGuard Global;
00343     TGo4PadOptions *DrawOption=0;
00344     listiter->Reset();
00345    while((entry=listiter->Next()) !=0) {
00346       if(((TGo4PadOptions *)entry)->fxPad==Pad){
00347           DrawOption =dynamic_cast <TGo4PadOptions *> (entry);
00348          break;
00349        }
00350    }
00351    return DrawOption;
00352 }
00353 
00354 const char * TGo4PreviewPanelStatus::GetPadStringDrawOption(TPad *SelectedPad)
00355 {
00356     TObject *entry;
00357     // TGo4LockGuard Global;
00358     //cout << "Global Lock held by TGo4PreviewPanelStatus::GetPadDrawOption"<< endl;
00359     const char *Option = 0;
00360     listiter->Reset();
00361    while((entry=listiter->Next()) !=0) {
00362       if(((TGo4PadOptions *)entry)->fxPad==SelectedPad){
00363          Option =(dynamic_cast <TGo4PadOptions *> (entry))->GetStringDrawOption()->Data();
00364        }
00365    }
00366    return Option;
00367 }
00368 
00369 TRefArray* TGo4PreviewPanelStatus::GetListOfPads()
00370 {
00371    //if(ListOfPads)ListOfPads->ls();
00372    return ListOfPads;
00373 }
00374 
00375 void TGo4PreviewPanelStatus::ResetPadOptionsList()
00376 {
00377    PadOptionList->Delete();
00378    listiter->Reset();
00379    ListOfPads->Clear("nodelete");
00380 }
00381 
00382 void TGo4PreviewPanelStatus::UpdateSubPads(TPad* pad)
00383 {
00384 if(pad==0) return;
00385 TList* primlist=pad->GetListOfPrimitives();
00386 if(primlist==0) return;
00387 //cout <<"UpdateSubPads() for pad "<<pad << endl;
00388 TIterator* liter=primlist->MakeIterator();
00389 TObject* next=0;
00390 while((next=liter->Next())!=0)
00391    {
00392       if(next->InheritsFrom("TPad"))
00393          {
00394             TPad* sub=dynamic_cast<TPad*>(next);
00395             if(!ListOfPads->FindObject(next))
00396                {
00397                   SetPadDrawOption(sub,"hist",kFALSE ); // init padoption, add to pad list
00398                   //cout <<"UpdateSubPads inits pad "<<next<<" "<<next->GetName() << endl;
00399                }
00400             UpdateSubPads(sub); // scan all primlists recursively
00401          }
00402    }
00403 delete liter;      
00404 }
00405 
00406 
00407 void TGo4PreviewPanelStatus::RemoveSubPads(TPad* pad)
00408 {   
00409 if(pad==0) return;
00410 TList* primlist=pad->GetListOfPrimitives();
00411 if(primlist==0) return;
00412 //cout <<"PreviewPanelStatus removing subpads of pad "<<pad << endl;
00413 TIterator* liter=primlist->MakeIterator();
00414 TObject* next=0;
00415 while((next=liter->Next())!=0)
00416    {
00417       if(next->InheritsFrom("TPad"))
00418          {
00419             TPad* subpad=dynamic_cast<TPad*>(next);
00420             RemovePad(subpad); // will also remove subsubpads...
00421          }
00422       else{ }
00423    }
00424 delete liter;
00425 }
00426 
00427 void TGo4PreviewPanelStatus::RemovePad(TPad* pad)
00428 {
00429 fxSlots->ClearAllLabels(pad);
00430 fxSlots->ClearLegend(pad,true);
00431 ListOfPads->Remove(pad);
00432 //cout <<"PreviewPanelStatus removed pad "<<pad << endl;
00433 listiter->Reset();
00434 TObject* entry=0;
00435 while((entry=listiter->Next()) !=0)
00436    {
00437       if(((TGo4PadOptions *)entry)->fxPad==pad)
00438          {
00439             PadOptionList->Remove(entry);
00440             delete entry;
00441             //cout <<"PreviewPanelStatus removed from options "<<pad << endl;
00442             break;
00443          }
00444    }
00445 RemoveSubPads(pad);
00446 }
00447 
00448 Int_t TGo4PreviewPanelStatus::GetNoOfPads()
00449 {
00450    //Int_t num=ListOfPads->GetSize();
00451    Int_t num=ListOfPads->GetEntries();   
00452    //cout <<"GetNoOfPads is "<<num << endl;
00453    return num;
00454 }
00455 
00456 
00457 void TGo4PreviewPanelStatus::CleanupPadLists(TCanvas* can)
00458 {   
00459 // note: this method should remove pads from ListOfPads
00460 // that are not existing in canvas and subpads list of primitives
00461 // anymore, after deleting pad with root rmb menu. However,
00462 // this failed, deleted pads were always still found in list of primitives!
00463 // With ListOfPads as TRefArray, root will care for vanished pad references
00464 // To be investigated! JA
00465 return; // disable this thing!
00466 if(can==0) return;
00467 cout <<"CleanupPadLists() for canvas "<<can << endl;
00468 TPad* pad=0;
00469 TRefArray* padlistcopy= new TRefArray;
00470 padlistcopy->AddAll(ListOfPads); 
00471 TIter piter(padlistcopy);
00472 while((pad=dynamic_cast<TPad*>(piter.Next())) !=0) 
00473    {
00474       if(!CheckSubPads(can,pad))               
00475               RemovePad(pad); // pad vanished from viewpanel somehow, we cleanup:
00476    }   
00477 padlistcopy->Clear("nodelete");
00478 delete padlistcopy;   
00479 }
00480 
00481 Bool_t TGo4PreviewPanelStatus::CheckSubPads(TPad* container, TPad* test)
00482 {
00483 if(container==0 || test==0) return kFALSE;
00484 if(container==test) 
00485 {
00486 //   cout <<"found "<<test << endl;
00487 //   cout <<"Name"<<test->GetName() << endl;
00488    return kTRUE; // canvas is also in padlist
00489 }
00490 TObject* entry=0;
00491 TList* primlist=container->GetListOfPrimitives();
00492 TIter priter(primlist);
00493 while((entry=priter.Next()) !=0) 
00494    {
00495       //cout <<"Checking entry: "<<entry->GetName()<<" :class"<<entry->IsA()->GetName() << endl;
00496       TPad* sub=dynamic_cast<TPad*>(entry);
00497       if(sub==0)
00498          {
00499             continue;
00500          }
00501       else
00502          {
00503             if(CheckSubPads(sub,test))
00504                return kTRUE;
00505             else
00506                continue;      
00507          }
00508    }
00509 //cout <<"NOT found "<<test<<" in "<< container << endl;      
00510 return kFALSE;   
00511 }
00512 
00513 
00514 void TGo4PreviewPanelStatus::RefreshListOfPads()
00515 {
00517 // this method is necessary to reserver new id numbers for
00518 // the existing subpads after saving viewpanel into canvas file
00519 // If not done and canvas is loaded back into same session with
00520 // original canvas, root will overwrite references to the source
00521 // pads, thus leading to invalid RefArray. JA
00522 //cout <<"RefreshListOfPads " << endl;   
00523 TList* padlistcopy= new TList; // put real pointers into list
00524 padlistcopy->SetOwner(kFALSE);
00525 padlistcopy->AddAll(ListOfPads);//     
00526 ListOfPads->Clear("nodelete");
00527 TObject* ob=0;
00528 TIter paditer(padlistcopy);
00529 while((ob=paditer.Next())!=0)
00530 {
00531    AssignUID(ob);
00532    ListOfPads->AddLast(ob);
00533    //cout <<"RefreshListOfPads added "<<ob<< "with uid" <<ob->GetUniqueID() << endl;   
00534 }
00535 padlistcopy->Clear("nodelete");
00536 delete padlistcopy;
00537    
00538 }
00539 
00540 void TGo4PreviewPanelStatus::AssignUID(TObject* obj)
00541 {
00542 // helper method to assing new ROOT unique id for pad obj   
00543 if(obj==0) return;
00544 if(ListOfPads->FindObject(obj))
00545    {
00546       //cout <<"TGo4PreviewPanelStatus::AssignUID: Object "<<obj<<" already in list of pads, return" << endl;  
00547       return;
00548    }  
00549 //UInt_t pid=obj->GetUniqueID() & 0xffffff;
00550 //cout <<"TGo4PreviewPanelStatus:: discard old primitive uid: "<<pid << endl; 
00551 TProcessID* spi=TProcessID::GetSessionProcessID();
00552 UInt_t objcount=spi->GetObjectCount();
00553 while(spi->GetObjectWithID(objcount))
00554    {
00555       //cout<<"TGo4PreviewPanelStatus:: found previous object for id "<<objcount << endl;  
00556       // skip already used numbers          
00557       objcount++;
00558    }
00559 obj->SetUniqueID(objcount);
00560 obj->SetBit(kIsReferenced); // otherwise, root might assign new number
00561 //cout <<"TGo4PreviewPanelStatus::AssignUID "<<objcount << endl;   
00562 TProcessID::SetObjectCount(objcount); 
00563 //UInt_t id=
00564 TProcessID::AssignID(obj); //    
00565 //cout <<"TGo4PreviewPanelStatus:: new id is "<<id<<endl;
00566 //cout << " new object count is:"<<TProcessID::GetSessionProcessID()->GetObjectCount()<<endl;
00567 
00568 }
00569 
00570 
00571 
00572 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:56:02 2005 for Go4-v2.10-5 by doxygen1.2.15