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

/Go4GUI/TGo4BrowserSlots.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 "TGo4BrowserSlots.h"
00017 
00018 #include <iostream.h>
00019 
00020 // Root Includes
00021 #include "TFile.h"
00022 #include "TFolder.h"
00023 #include "TROOT.h"
00024 #include "TCollection.h"
00025 #include "TIterator.h"
00026 #include "TCanvas.h"
00027 #include "TString.h"
00028 #include "THStack.h"
00029 #include "TH1.h"
00030 #include "TH2.h"
00031 #include "TH3.h"
00032 #include "TGraph.h"
00033 #include "TRefArray.h"
00034 
00035 // Qt Includes
00036 #include "qlistview.h"
00037 #include "qtabwidget.h"
00038 #include "qstring.h"
00039 #include "qptrlist.h"
00040 #include "qmessagebox.h"
00041 
00042 // Go4 Includes
00043 #include "Go4Log/TGo4Log.h"
00044 #include "Go4Analysis/TGo4AnalysisObjectNames.h"
00045 #include "Go4Analysis/TGo4ExportManager.h"
00046 #include "Go4CommandsAnalysis/TGo4ComClearObject.h"
00047 #include "Go4LockGuard/TGo4LockGuard.h"
00048 #include "Go4GUIRegistry/TGo4GUIRegistry.h"
00049 #include "Go4StatusBase/TGo4Picture.h"
00050 #include "Go4StatusBase/TGo4CanvasWrapper.h"
00051 #include "Go4QtBaseWidgets/TGo4QItem.h"
00052 #include "Go4QtBaseWidgets/TGo4QFitterItem.h"
00053 #include "TGo4BrowserStatus.h"
00054 #include "TGo4Browser.h"
00055 #include "TGo4PreviewPanel.h"
00056 #include "TGo4PreviewPanelSlots.h"
00057 #include "TGo4PadOptions.h"
00058 #include "TGo4MonitoredObject.h"
00059 #include "TGo4QRootCanvas.h"
00060 #include "TGo4DockBrowsers.h"
00061 #include "TGo4MainWindow.h"
00062 
00063 TGo4BrowserSlots::TGo4BrowserSlots(const char * name, const char * title, TGo4Browser * p)
00064                  :TGo4SlotsBaseClass(name , title), fxTGo4Browser(p)
00065 {
00066    TGo4LockGuard Global;
00067    fxTGo4GUIRegistry = TGo4GUIRegistry::Instance();
00068    fxTGo4BrowserStatus= new TGo4BrowserStatus("TGo4BrowserStatus", "Status Of Go4 Browser");
00069    fxTGo4GUIRegistry->RegisterSlotClass(this, fxTGo4BrowserStatus, p);
00070    fxTGo4GUIRegistry->SetMemoryBrowser(this);
00071    RootMem=(TFolder *)gROOT->FindObjectAny("ROOT Memory");
00072    OverWriteMode=kTRUE;
00073    fxTGo4DockBrowsers=dynamic_cast <TGo4DockBrowsers *>((fxTGo4Browser->parentWidget()->parentWidget()->parentWidget()->parentWidget()));
00074    TGo4DockBrowserTabs=dynamic_cast <QTabWidget *>((fxTGo4Browser->parentWidget()->parentWidget()->parentWidget()));
00075    fxMainWin = dynamic_cast <TGo4MainWindow *> (fxTGo4GUIRegistry->GetMainWindow());
00076 }
00077 
00078 void TGo4BrowserSlots::SetGUI(TGo4Browser *GUI )
00079 {
00080    // TGo4LockGuard Global;
00081       fxTGo4Browser= GUI;
00082    fxTGo4GUIRegistry->GuiIsChanged(this, GUI);
00083 }
00084 
00085 TGo4Status * TGo4BrowserSlots::GetStatus()
00086 {
00087    return fxTGo4BrowserStatus;
00088 }
00089 
00090 void TGo4BrowserSlots::AddObject(TNamed *fxData, TQRootCanvas *qc, TPad *pad) 
00091 {
00092    if(fxData==0) return;
00093    TGo4LockGuard global;
00094    AddObjectToLocalList(fxData, kTRUE, kFALSE);
00095    TGo4QRootCanvas *gqc= dynamic_cast<TGo4QRootCanvas*> (qc);
00096    if ((pad!=0) && (gqc!=0)) {
00097       TGo4QItem *item1=(TGo4QItem *)fxTGo4Browser->ListViewLocal->findItem(fxAddedItemName.Data(),0);
00098       if(item1!=0) {   
00099          TGo4PreviewPanel *fxPanel=dynamic_cast <TGo4PreviewPanel *>(gqc->parent());
00100          fxPanel->SetActivePad(pad);
00101          item1->DrawObj(fxPanel);
00102          pad->Modified();
00103          pad->Update();
00104       }
00105    }
00106 }
00107 
00108 void TGo4BrowserSlots::AddObject(TNamed *fxData)
00109 {
00110    AddObjectToLocalList(fxData, kTRUE);
00111 }
00112 
00113 const Text_t* TGo4BrowserSlots::AddObjectToLocalList(TNamed *fxData, Bool_t clone, Bool_t changetab) {
00114    TGo4LockGuard Global;
00115    if(fxData==0) return 0;
00116 //   QString NewName;
00121    QString Name = fxData->GetName();
00122    QString ClassName = fxData->ClassName();
00123    if(ClassName=="TGo4CanvasWrapper") ClassName="TCanvas";
00124    if (fxTGo4Browser!=0) {
00125       TObject *ExistingObject= fxTGo4BrowserStatus->GetObjectfromLocalList(Name);
00126       // always create item if object add with clone = false parameter
00127       if (!clone) ExistingObject = 0;
00128       if(OverWriteMode && (ExistingObject!=0)){
00129          /* If overwrite mode is selected, overwrite the object and get the Item corresponding to
00130          to this root object so that we can update the reference later */
00131          TGo4QItem *item1 = (TGo4QItem*) fxTGo4Browser->ListViewLocal->findItem(Name,0);
00132          if (item1!=0) {
00133              item1->UpdateOnline(fxData);
00134              TObject *AddedObject= fxTGo4BrowserStatus->GetObjectfromLocalList(Name);
00135               /* update the reference to the root object in the QListView Item */
00136              item1->SetItemObject(AddedObject);
00137              // default implementation of UpdateOnline now calls
00138              // OverWritLocalObject, which only replaces old object now.
00139              // Other implementations for histo, graph and picture
00140              // will also update the draw pad
00141          }  // if(item1)
00142       } else {
00143          Name = fxTGo4BrowserStatus->AddObjectToLocalListStatus(fxData, clone);
00144          TGo4QItem* item1 = fxTGo4DockBrowsers->CreateListViewItem(fxTGo4Browser->ListViewLocal, Name, ClassName);
00145          if(item1!=0) {
00146               TObject *AddedObject= fxTGo4BrowserStatus->GetObjectfromLocalList(Name);
00147                 /* update the reference to the root object in the QListView Item */
00148               item1->SetItemObject(AddedObject);
00149               item1->SetFileObj(AddedObject);
00150               if(AddedObject) item1->setText(2,AddedObject->GetTitle()); // not yet provided in item factory
00151 
00152               item1->AddToMemoryList(); // needed for picture to get subobjects
00153          }
00154          /*if anything is added to the local browser then change the tab to show it */
00155          if(changetab && TGo4DockBrowserTabs!=0)
00156             TGo4DockBrowserTabs->setCurrentPage(1);
00157          // note: we do not change the tabs in case of normal memory update!
00158       } // if(OverWriteMode)
00159    }else{
00160       Name = fxTGo4BrowserStatus->AddObjectToLocalListStatus(fxData, clone);
00161    } // if(fxTGo4Browser)
00162 fxAddedItemName=Name.ascii(); // return value is not save! uses member buffer directly
00163 return Name; // note: in some cases Name is deleted before return value evaluated!
00164 }
00165 
00166 void TGo4BrowserSlots::AddLocalObject(TNamed * Obj) {
00167    AddObjectToLocalList(Obj, kTRUE);
00168 }
00169 
00170 void TGo4BrowserSlots::LocalItemDoubleClicked(QListViewItem *Item)
00171 {
00172    // TGo4LockGuard Global;
00173    TGo4QFitterItem *FitItem=0;
00174    FitItem=dynamic_cast <TGo4QFitterItem *>(Item);
00175    if (FitItem!=0){
00176       FitItem->ItemDBkLocal();
00177    }else{
00178       PlotLocal();
00179    }
00180 }
00181 
00182 void TGo4BrowserSlots::UpdateLocalList()
00183 {
00184    // TGo4LockGuard Global;
00185    TGo4QItem *Item=0;
00186     QListViewItemIterator it(fxTGo4Browser->ListViewLocal);
00187    // iterate through all items of the list view
00188       for ( ; it.current(); ++it ) {
00189        Item=dynamic_cast <TGo4QItem *> (it.current());
00190        if (Item!=0){
00191          // filter out items with cycle numbers or stack objects.
00192          // these are never found in analysis and cause command traffic...
00193          if(!( Item->text(0).contains(",")  || Item->text(0).contains("THStack")) )
00194                                Item->ItemDBkRemote();
00195        }
00196 
00197    }
00198 
00199 }
00200 
00201 void TGo4BrowserSlots::LocalListDeleteSelection() {
00202    TGo4LockGuard global;
00203    QPtrList <QListViewItem> lst;
00204    lst.setAutoDelete( TRUE );
00205 
00206    if(fxTGo4Browser->ListViewLocal->isMultiSelection()) {
00207        QListViewItemIterator it(fxTGo4Browser->ListViewLocal);
00208       // iterate through all items of the list view
00209        for ( ; it.current(); ++it ) {
00210            if ( it.current()->isSelected() ){
00211              TObject *ObjectToDel =((TGo4QItem *)it.current())->GetItemObject();
00212              fxTGo4BrowserStatus->RemoveObjectfromLocalList(ObjectToDel);
00213              lst.append( it.current() );
00214            }
00215        }
00216    }
00217 }
00218 
00219 void TGo4BrowserSlots::SuperImposeLocal()
00220 {
00221    TGo4LockGuard Global;
00222    TGo4PreviewPanel * viewpanel =fxMainWin->ViewPanelSlot();
00223    viewpanel->ChangeSuperImpose(true);
00224    if(fxTGo4Browser->ListViewLocal->isMultiSelection()) {
00225       QListViewItemIterator it(fxTGo4Browser->ListViewLocal);
00226       // iterate through all items of the list view
00227        for ( ; it.current(); ++it )
00228           {
00229             if ( it.current()->isSelected() )
00230                {
00231                   TGo4QItem* go4qitem=dynamic_cast<TGo4QItem*>(it.current());
00232                   if(go4qitem)
00233                      go4qitem->DrawObj(viewpanel);
00234                } // if(..isSelected)
00235           } // for
00236    } //if(fxTGo4Browser->ListViewLocal->isMultiSelection()){
00237 }
00238 
00239 
00240 void TGo4BrowserSlots::PlotLocal()
00241 {
00242    TGo4LockGuard Global;
00243    QPtrList <TGo4QItem> *SelectedLst = fxTGo4Browser->GetSelectedItems();
00244    int NoOfObjects = SelectedLst->count();
00245    TGo4PreviewPanel* viewpanel =fxMainWin->ViewPanelSlot(NoOfObjects);
00246    TCanvas* canvas= viewpanel->GetCanvas();
00247    canvas->Resize();
00248    QPtrListIterator <TGo4QItem> it(*SelectedLst);
00249    TGo4QItem *Item;
00250    int PadNo=0;
00251    while ( (Item=it.current())!=0){
00252       ++it;
00253       canvas->cd(++PadNo);
00254       Item->DrawObj(viewpanel, (TPad *)gPad);
00255    }
00256    canvas->Update();
00257    //fxTGo4Browser->ListViewLocal->clearSelection();
00258    // we don't clear selection; user might want to reset these histos next
00259    
00260    delete SelectedLst;
00261 }
00262 
00263 TRefArray *TGo4BrowserSlots::GetIndexOfSelectedItems()
00264 {
00265    // TGo4LockGuard Global;
00266    TRefArray *fxRefArray = new TRefArray();
00267    if(fxTGo4Browser->ListViewLocal->isMultiSelection()){
00268       QListViewItemIterator it(fxTGo4Browser->ListViewLocal);
00269       // iterate through all items of the list view
00270           for ( ; it.current(); ++it ) {
00271                if ( it.current()->isSelected() ){
00272                fxRefArray->AddLast(((TGo4QItem *)(it.current()))->GetItemObject());
00273             }
00274            }
00275    }
00276    //fxTGo4Browser->ListViewLocal->clearSelection();
00277    return fxRefArray;
00278 }
00279 
00280 
00281 TGo4BrowserSlots::~TGo4BrowserSlots()
00282 {
00283    // TGo4LockGuard Global;
00284    delete fxTGo4BrowserStatus;
00285 }
00286 
00287 void TGo4BrowserSlots::SynchronizeWithMemory() {
00288    TGo4LockGuard Global;
00289    if (RootMem==0) return;
00290    TCollection* objectlist = RootMem->GetListOfFolders();
00291    TList* scanlist = new TList;
00292    scanlist->AddAll(objectlist);
00293    TIter iter(scanlist); // use copy of root list, might change objectlist in iterator
00294    TObject* entry=0;
00295    while((entry=iter()) !=0) {
00296        QString Name = entry->GetName();
00297        TNamed* named = dynamic_cast<TNamed*> (entry);
00298        if (named) {
00299           objectlist->Remove(named);
00300           // do not delete object if you do not want to clone it
00301           AddObjectToLocalList(named, kTRUE); // clone original object
00302           TObject *AddedObject= fxTGo4BrowserStatus->GetObjectfromLocalList(Name);
00303           if(AddedObject!=named)
00304             {
00305                //cout <<"sync: deleted source object "<<Name << endl;
00306                delete named; // this was cloned   
00307             }
00308           else  
00309             {
00310                cout <<"synchronize memory: source equals target, NEVER COME HERE! "<<Name << endl;
00311                // no delete, since original object is target
00312             }
00313        }
00314    }
00315    scanlist->Clear("nodelete");
00316    delete scanlist;
00317 }
00318 
00319 
00320 void TGo4BrowserSlots::ResetRemoteObj(const char* ObjName)
00321 {
00322    TGo4LockGuard Global;
00323    TGo4ComClearObject *com = new TGo4ComClearObject(ObjName);
00324    fxTGo4GUIRegistry->SubmitCommand(com);
00325 }
00326 
00327 void TGo4BrowserSlots::ExportSelectedItems(const Text_t* filename, const Text_t* filedir, const Text_t* format, const Text_t* description, Bool_t exportall)
00328 {
00329     TGo4ExportManager exman("DiskBrowserExport");
00330     exman.SetOutFile(filename);
00331     exman.SetOutFileComment(description);
00332     exman.SetStartDir();
00333     exman.SetCurrentDir(filedir);
00334     TString convert;
00335     if(format==0)
00336        convert="ROOT";
00337     else
00338        convert=format;
00339     if(exportall)
00340        TGo4Log::Message(1,"Exporting all memory objects to %s",convert.Data());
00341     else
00342        TGo4Log::Message(1,"Exporting selected memory objects to %s",convert.Data());
00343     
00344     Go4Export_t filter;
00345     if(convert.Contains("ASCII"))
00346        {
00347           TGo4Log::Message(0,"Export filter is ASCII");
00348           filter=GO4EX_ASCII;
00349        }
00350     else if (convert.Contains("Radware"))
00351        {
00352           TGo4Log::Message(0,"Export filter is Radware");
00353           filter=GO4EX_RADWARE;
00354        }
00355     else if (convert.Contains("ROOT"))
00356        {
00357           TGo4Log::Message(0,"Export filter is ROOT");
00358           filter=GO4EX_ROOT;
00359        }
00360     else
00361        {
00362           TGo4Log::Message(0,"Export filter is unknown, using ROOT");
00363           filter=GO4EX_ROOT;
00364        }
00365        
00366     if(exportall) {
00367        exman.Export(fxTGo4BrowserStatus->GetLocalListStatus(),filter);
00368     } else {
00369        TCollection* selected = GetIndexOfSelectedItems();
00370        exman.Export(selected, filter);
00371        delete selected;
00372     }
00373 }
00374 
00375 
00376 
00377 
00378 
00379 
00380 //----------------------------END OF GO4 SOURCE FILE ---------------------

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