00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4BrowserSlots.h"
00017
00018 #include <iostream.h>
00019
00020
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
00036 #include "qlistview.h"
00037 #include "qtabwidget.h"
00038 #include "qstring.h"
00039 #include "qptrlist.h"
00040 #include "qmessagebox.h"
00041
00042
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
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
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
00127 if (!clone) ExistingObject = 0;
00128 if(OverWriteMode && (ExistingObject!=0)){
00129
00130
00131 TGo4QItem *item1 = (TGo4QItem*) fxTGo4Browser->ListViewLocal->findItem(Name,0);
00132 if (item1!=0) {
00133 item1->UpdateOnline(fxData);
00134 TObject *AddedObject= fxTGo4BrowserStatus->GetObjectfromLocalList(Name);
00135
00136 item1->SetItemObject(AddedObject);
00137
00138
00139
00140
00141 }
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
00148 item1->SetItemObject(AddedObject);
00149 item1->SetFileObj(AddedObject);
00150 if(AddedObject) item1->setText(2,AddedObject->GetTitle());
00151
00152 item1->AddToMemoryList();
00153 }
00154
00155 if(changetab && TGo4DockBrowserTabs!=0)
00156 TGo4DockBrowserTabs->setCurrentPage(1);
00157
00158 }
00159 }else{
00160 Name = fxTGo4BrowserStatus->AddObjectToLocalListStatus(fxData, clone);
00161 }
00162 fxAddedItemName=Name.ascii();
00163 return Name;
00164 }
00165
00166 void TGo4BrowserSlots::AddLocalObject(TNamed * Obj) {
00167 AddObjectToLocalList(Obj, kTRUE);
00168 }
00169
00170 void TGo4BrowserSlots::LocalItemDoubleClicked(QListViewItem *Item)
00171 {
00172
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
00185 TGo4QItem *Item=0;
00186 QListViewItemIterator it(fxTGo4Browser->ListViewLocal);
00187
00188 for ( ; it.current(); ++it ) {
00189 Item=dynamic_cast <TGo4QItem *> (it.current());
00190 if (Item!=0){
00191
00192
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
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
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 }
00235 }
00236 }
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
00258
00259
00260 delete SelectedLst;
00261 }
00262
00263 TRefArray *TGo4BrowserSlots::GetIndexOfSelectedItems()
00264 {
00265
00266 TRefArray *fxRefArray = new TRefArray();
00267 if(fxTGo4Browser->ListViewLocal->isMultiSelection()){
00268 QListViewItemIterator it(fxTGo4Browser->ListViewLocal);
00269
00270 for ( ; it.current(); ++it ) {
00271 if ( it.current()->isSelected() ){
00272 fxRefArray->AddLast(((TGo4QItem *)(it.current()))->GetItemObject());
00273 }
00274 }
00275 }
00276
00277 return fxRefArray;
00278 }
00279
00280
00281 TGo4BrowserSlots::~TGo4BrowserSlots()
00282 {
00283
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);
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
00301 AddObjectToLocalList(named, kTRUE);
00302 TObject *AddedObject= fxTGo4BrowserStatus->GetObjectfromLocalList(Name);
00303 if(AddedObject!=named)
00304 {
00305
00306 delete named;
00307 }
00308 else
00309 {
00310 cout <<"synchronize memory: source equals target, NEVER COME HERE! "<<Name << endl;
00311
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