00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4QItem.h"
00017
00018 #include <iostream.h>
00019
00020 #include "TCanvas.h"
00021 #include "TH2.h"
00022 #include "TObject.h"
00023 #include "TKey.h"
00024 #include "TFile.h"
00025 #include "TNamed.h"
00026
00027 #include "qimage.h"
00028 #include "qdragobject.h"
00029
00030 #include "Go4GUIRegistry/TGo4GUIRegistry.h"
00031 #include "Go4LockGuard/TGo4LockGuard.h"
00032 #include "Go4StatusBase/TGo4Status.h"
00033 #include "Go4GUI/TGo4PadOptions.h"
00034 #include "Go4GUI/TGo4PreviewPanel.h"
00035 #include "Go4GUI/TGo4PreviewPanelSlots.h"
00036 #include "Go4GUI/TGo4BrowserStatus.h"
00037 #include "Go4GUI/TGo4BrowserSlots.h"
00038 #include "Go4GUI/TGo4MonitoredListStatus.h"
00039 #include "Go4GUI/TGo4MonitoredListSlots.h"
00040 #include "Go4GUI/TGo4MonitoredObject.h"
00041 #include "Go4GUI/TGo4ASImage.h"
00042 #include "Go4GUI/TGo4MainWindow.h"
00043
00044 void TGo4QItem::UpdateOnline(TObject* ob)
00045 {
00046
00047 TObject* oldobject=GetWorkObject();
00048 TObject* newcopy=0;
00049 Text_t obname[256];
00050 if(ob) snprintf(obname,256,"%s",ob->GetName());
00051 if(fbMonitorDone)
00052 {
00053
00054
00055 TGo4BrowserSlots* brslots=dynamic_cast <TGo4BrowserSlots *> (fxTGo4GUIRegistry->GetSlotClass("TGo4BrowserSlots"));
00056 if(brslots)
00057 {
00058 TGo4BrowserStatus* brstat=dynamic_cast <TGo4BrowserStatus *> (brslots->GetStatus());
00059 brstat->OverWriteLocalObject(dynamic_cast <TNamed*>(ob));
00060 newcopy=brstat->GetObjectfromLocalList(obname);
00061 fxItemObject=newcopy;
00062 }
00063 }
00064 else
00065 {
00066
00067
00068 TGo4MonitoredListSlots* monslots=dynamic_cast <TGo4MonitoredListSlots *> (fxTGo4GUIRegistry->GetSlotClass("TGo4MonitoredListSlots"));
00069 if(monslots)
00070 {
00071 TGo4MonitoredListStatus* monstat=dynamic_cast <TGo4MonitoredListStatus *> (monslots->GetStatus());
00072 newcopy=ob->Clone();
00073 if(newcopy)
00074 {
00075 monstat->RemoveMonitoredObject(oldobject);
00076 monstat->AddToMonitoredObjectList(newcopy);
00077 TGo4MonitoredObject* MonitoredObj = monstat->GetMonitoredObject(obname);
00078 if(MonitoredObj)
00079 {
00080 MonitoredObj->SetMonitoredObject(newcopy);
00081 MonitoredObj->SetMonObjItem(this);
00082 }
00083 fxItemObject=MonitoredObj;
00084 }
00085
00086 }
00087 }
00088 }
00089
00090 TGo4QItem::TGo4QItem( QListViewItem* parent, const char* pixmap, const QString & text, const QString & text1, const QString & text2)
00091 :QListViewItem (parent, text, text1, text2)
00092 {
00093 fxKey=0;
00094 fxObj=0;
00095 fxRootFile=0;
00096 fxItemObject=0;
00097 fxDrawCanvas=0;
00098 fxDrawPad=0;
00099 fxDrawPanel=0;
00100 fxTGo4GUIRegistry = TGo4GUIRegistry::Instance();
00101 fbMonitorDone=false;
00102 if (pixmap!=0)
00103 setPixmap(0, TGo4MainWindow::uic_load_pixmap(pixmap));
00104 }
00105
00106 TGo4QItem::TGo4QItem( QListView* parent, const char* pixmap, const QString & text, const QString & text1, const QString & text2)
00107 :QListViewItem (parent, text, text1, text2)
00108 {
00109 fxKey=0;
00110 fxObj=0;
00111 fxRootFile=0;
00112 fxItemObject=0;
00113 fxDrawCanvas=0;
00114 fxDrawPad=0;
00115 fxDrawPanel=0;
00116 fxTGo4GUIRegistry = TGo4GUIRegistry::Instance();
00117 fbMonitorDone=true;
00118 if (pixmap!=0)
00119 setPixmap(0, TGo4MainWindow::uic_load_pixmap(pixmap));
00120 }
00121
00122 TGo4QItem::~TGo4QItem()
00123 {
00124 }
00125
00126 void TGo4QItem::ItemDBkRemote()
00127 {
00128
00129 }
00130 void TGo4QItem::ItemDBkLocal()
00131 {
00132
00133 }
00134 void TGo4QItem::ItemDBkMem()
00135 {
00136
00137 }
00138
00139 void TGo4QItem::DrawObj(TGo4PreviewPanel* , TPad*)
00140 {
00141
00142 }
00143 void TGo4QItem::GetOnlineObj()
00144 {
00145
00146 }
00147 void TGo4QItem::GetRemoteObj()
00148 {
00149 }
00150
00151 void TGo4QItem::AddToMonitorList()
00152 {
00153 }
00154
00155
00156 void TGo4QItem::AddToMemoryList()
00157 {
00158 }
00159
00160 bool TGo4QItem::IsLogYScale()
00161 {
00162 bool rev=false;
00163 TGo4MainWindow* mw= (TGo4MainWindow*) fxTGo4GUIRegistry->GetMainWindow();
00164 if(mw->CheckViewpanel(fxDrawPanel) && IsExisting(fxDrawCanvas, fxDrawPad)) {
00165 TGo4PadOptions* popt=fxDrawPanel->GetPadOptions(fxDrawPad);
00166 if(popt) rev = popt->GetHisYStyle()>0;
00167 } else {
00168
00169 SetDrawCanvas(0);
00170 SetDrawPad(0);
00171 SetDrawPanel(0);
00172 rev = false;
00173 }
00174 return rev;
00175 }
00176
00177
00178 bool TGo4QItem::IsKeepScale()
00179 {
00180 bool rev=false;
00181 TGo4MainWindow* mw= (TGo4MainWindow*) fxTGo4GUIRegistry->GetMainWindow();
00182 if(mw->CheckViewpanel(fxDrawPanel) && IsExisting(fxDrawCanvas, fxDrawPad)) {
00183 TGo4PadOptions* popt=fxDrawPanel->GetPadOptions(fxDrawPad);
00184 if(popt) rev=!(popt->GetAutoScale());
00185 } else {
00186
00187 SetDrawCanvas(0);
00188 SetDrawPad(0);
00189 SetDrawPanel(0);
00190 rev=false;
00191 }
00192 return rev;
00193 }
00194
00195 void TGo4QItem::SetKeepScale(bool val)
00196 {
00197 TGo4MainWindow* mw= (TGo4MainWindow*) fxTGo4GUIRegistry->GetMainWindow();
00198 if(mw->CheckViewpanel(fxDrawPanel) && IsExisting(fxDrawCanvas, fxDrawPad)) {
00199
00200 TGo4PadOptions* popt=fxDrawPanel->GetPadOptions(fxDrawPad);
00201 if(popt)
00202 popt->SetAutoScale(!val);
00203 }
00204 }
00205
00206 void TGo4QItem::UpdateDrawPad() {
00207 TCanvas* c=0;
00208 TPad* Pad=0;
00209
00210 TGo4MonitoredObject *MonitoredObj =
00211 dynamic_cast <TGo4MonitoredObject *> (fxItemObject);
00212 if(MonitoredObj) {
00213 c=MonitoredObj->GetCanvas();
00214 Pad=MonitoredObj->GetPad();
00215 } else {
00216 c=fxDrawCanvas;
00217 Pad=fxDrawPad;
00218 }
00219
00220 if(!IsExisting(c,Pad)) {
00221 if(MonitoredObj) {
00222 MonitoredObj->SetPad(0);
00223 MonitoredObj->SetCanvas(0);
00224 MonitoredObj->SetPreViewPanel(0);
00225 }
00226 SetDrawCanvas(0);
00227 SetDrawPad(0);
00228 SetDrawPanel(0);
00229 } else {
00230 #ifdef __GO4USEASIMAGE__
00231
00232 {
00233 TGo4LockGuard glob;
00234 TObject* work=GetWorkObject();
00235 QString doptions="";
00236 TGo4ASImage* oldimage=0;
00237 TPad* padsav=0;
00238 TGo4MainWindow* mw= (TGo4MainWindow*) fxTGo4GUIRegistry->GetMainWindow();
00239 if(mw->CheckViewpanel(fxDrawPanel))
00240 {
00241
00242 oldimage=fxDrawPanel->GetPadImage(fxDrawPad);
00243 padsav=fxDrawPanel->GetActivePad();
00244 }
00245 if(work && work->InheritsFrom("TH2") && oldimage)
00246 {
00247
00248 fxDrawPad->cd();
00249 TH2* map=dynamic_cast<TH2*>(work);
00250 oldimage->SetHistogramRanges(map);
00251 TGo4ASImage* pic=new TGo4ASImage(map);
00252 pic->SetPalette(&(oldimage->GetPalette()));
00253 fxDrawPad->Clear();
00254 delete oldimage;
00255 pic->Draw();
00256 if(padsav) padsav->cd();
00257 }
00259 }
00260 #endif // __GO4USEASIMAGE__
00261
00262 TGo4MainWindow* mw= (TGo4MainWindow*) fxTGo4GUIRegistry->GetMainWindow();
00263 if(mw->CheckViewpanel(fxDrawPanel)) fxDrawPanel->UpdateMarkersHistogram();
00264 Pad->Modified();
00265 Pad->Update();
00266 }
00267 }
00268
00269 bool TGo4QItem::AssignDrawPanel(TGo4PreviewPanel* pan, TPad* currentpad)
00270 {
00271 TGo4MainWindow* mw= (TGo4MainWindow*) fxTGo4GUIRegistry->GetMainWindow();
00272 if(!mw->CheckViewpanel(pan)) return kFALSE;
00273 Bool_t rev=kFALSE;
00274
00275 TGo4MonitoredObject* MonitoredObj=dynamic_cast <TGo4MonitoredObject *> (fxItemObject);
00276 TCanvas* can=pan->GetCanvas();
00277 TPad* pad;
00278 if(currentpad)
00279 pad=currentpad;
00280 else
00281 pad=pan->GetActivePad();
00282 if(IsExisting(can, pad))
00283 {
00284 SetDrawCanvas(can);
00285 SetDrawPad(pad);
00286 SetDrawPanel(pan);
00287 if(MonitoredObj)
00288 {
00289 MonitoredObj->SetPreViewPanel(fxDrawPanel);
00290 MonitoredObj->SetCanvas(fxDrawCanvas);
00291 MonitoredObj->SetPad(fxDrawPad);
00292 }
00293 rev=kTRUE;
00294 }
00295 else
00296 {
00297 SetDrawCanvas(0);
00298 SetDrawPad(0);
00299 SetDrawPanel(0);
00300 if(MonitoredObj)
00301 {
00302 MonitoredObj->SetPreViewPanel(0);
00303 MonitoredObj->SetCanvas(0);
00304 MonitoredObj->SetPad(0);
00305 }
00306 rev=kFALSE;
00307 }
00308 return rev;
00309 }
00310
00311
00312 bool TGo4QItem::IsExisting(TCanvas* can, TPad* pad) {
00313 if ((can==0) || (pad==0)) return kFALSE;
00314 TObject* entry = gROOT->GetListOfCanvases()->FindObject(can);
00315 if(entry)
00316 return (IsSubPad(can,pad));
00317 else
00318 return kFALSE;
00319 }
00320
00321 bool TGo4QItem::IsSubPad(TPad* mother, TPad* subpad)
00322 {
00323 if(mother==0 || subpad==0) return kFALSE;
00324 if(mother==subpad) return kTRUE;
00325 TList* primlist=mother->GetListOfPrimitives();
00326 if(primlist==0) return kFALSE;
00327 Bool_t rev=kFALSE;
00328 TIterator* liter=primlist->MakeIterator();
00329 TObject* next=0;
00330 while((next=liter->Next())!=0)
00331 {
00332 if(next->InheritsFrom("TPad"))
00333 {
00334 TPad* pad=dynamic_cast<TPad*>(next);
00335 if(subpad==pad)
00336 {
00337
00338 rev=kTRUE;
00339 break;
00340 }
00341 else if (IsSubPad(pad,subpad))
00342 {
00343 rev=kTRUE;
00344 break;
00345 }
00346 else ;
00347 }
00348 else{ }
00349 }
00350 delete liter;
00351
00352 return rev;
00353 }
00354
00355 TObject* TGo4QItem::GetWorkObject()
00356 {
00357 TObject *Monitored=0;
00358 if (fxItemObject!=0) {
00359 TGo4MonitoredObject *MonitoredObj =
00360 dynamic_cast <TGo4MonitoredObject *> (fxItemObject);
00361 if(MonitoredObj!=0)
00362 Monitored = MonitoredObj->GetMonitoredObject();
00363 else
00364 Monitored = fxItemObject;
00365 return Monitored;
00366 } else
00367 if (fxObj!=0) {
00368 return fxObj;
00369 } else
00370 if(fxKey!=0){
00371
00372 if(fxRootFile) fxRootFile->cd();
00373 TObject *fObj=fxKey->ReadObj();
00374 SetFileObj(fObj);
00375 return fObj;
00376 }
00377 return 0;
00378 }
00379
00380 bool TGo4QItem::InFileBrowser() {
00381 return listView()->name() == QString("FileListView");
00382 }
00383
00384 bool TGo4QItem::InMemoryBrowser() {
00385 return listView()->name() == QString("ListViewLocal");
00386 }
00387
00388 bool TGo4QItem::InMonitoringList() {
00389 return listView()->name() == QString("ListViewMonitor");
00390 }
00391
00392
00393
00394