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

/Go4QtBaseWidgets/TGo4QTHItem.cpp

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 "TGo4QTHItem.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TROOT.h"
00021 #include "TPad.h"
00022 #include "TCanvas.h"
00023 #include "THStack.h"
00024 #include "TH2.h"
00025 
00026 #include "Go4CommandsAnalysis/TGo4ComGetObject.h"
00027 #include "Go4GUIRegistry/TGo4GUIRegistry.h"
00028 #include "Go4GUI/TGo4PreviewPanel.h"
00029 #include "Go4GUI/TGo4QRootCanvas.h"
00030 #include "Go4GUI/TGo4MonitoredObject.h"
00031 #include "Go4GUI/TGo4MonitoredListSlots.h"
00032 #include "Go4GUI/TGo4BrowserSlots.h"
00033 #include "Go4GUI/TGo4BrowserStatus.h"
00034 #include "Go4GUI/TGo4Browser.h"
00035 #include "Go4GUI/TGo4PadOptions.h"
00036 #include "Go4GUI/TGo4ASImage.h"
00037 
00038 TGo4QTHItem::TGo4QTHItem( QListViewItem* parent, const char* pixmap, const QString & text, const QString & text1,  const QString & text2)
00039    :TGo4QDragDrop (parent, pixmap, text, text1, text2)
00040 {
00041 }
00042 
00043 TGo4QTHItem::TGo4QTHItem( QListView* parent, const char* pixmap, const QString & text, const QString & text1,  const QString & text2)
00044    :TGo4QDragDrop (parent, pixmap, text, text1, text2)
00045 {
00046 }
00047 
00048 TGo4QTHItem::~TGo4QTHItem()
00049 {
00050 }
00051 
00052 void TGo4QTHItem::ItemDBkMem()
00053 {
00054    cout << " TGo4QTHItem::ItemDBkMem()" <<endl;
00055 }
00056 
00057 void TGo4QTHItem::ItemDBkLocal()
00058 {
00059       cout << " TGo4QTHItem::ItemDBkLocal()" <<endl;
00060 }
00061 
00062 void TGo4QTHItem::ItemDBkRemote()
00063 {
00064    char buffer[256];
00065    sprintf(buffer,"%s","");
00066    if(parent()!=0) snprintf(buffer,255,"%s/",parent()->text(0).data());
00067    strcat(buffer,text(0));
00068    TGo4ComGetObject* com = new TGo4ComGetObject(buffer);
00069    fxTGo4GUIRegistry->SubmitCommand(com, buffer);
00070 }
00071 
00072 void TGo4QTHItem::DrawObj(TGo4PreviewPanel *viewpanel, TPad* currentpad) {
00073    if(!AssignDrawPanel(viewpanel,currentpad)) return;
00074    QString buffer="";
00075    QString buffer1="";
00076 
00077    THStack *hs=0;
00078    TH1* hist=dynamic_cast<TH1*>(GetWorkObject());
00079    if(hist==0) return;
00080    QString realname=hist->GetName();
00081    TGo4BrowserSlots* browserslots = dynamic_cast <TGo4BrowserSlots *>(fxTGo4GUIRegistry->GetSlotClass("TGo4BrowserSlots"));
00082    if(InFileBrowser())
00083       {
00084          if(browserslots)  //browserslots->AddObjectToLocalList(hist,false);
00085              {
00086                 browserslots->AddObject(hist,fxDrawPanel->GetQCanvas(),fxDrawPad);
00087                 realname=browserslots->GetAddedItemName();
00088                //cout <<"DrawObj in file browser sends to membrowser" << endl
00089               }// if(browserslots)
00090          //return;
00091       }
00092    //cout <<"drawing in memory browser..." << endl;
00093    TGo4PadOptions* padoptions=fxDrawPanel->GetPadOptions(fxDrawPad);
00094    const char* drawoptions;
00095    bool statisticson, PadDragAddOption;
00096    if(padoptions)
00097       {
00098          drawoptions=padoptions->GetStringDrawOption()->Data();
00099          statisticson=padoptions->IsHisStats();
00100          PadDragAddOption= padoptions->DragAddOption();
00101       }
00102    else
00103       {
00104          drawoptions="";
00105          statisticson=true;
00106          PadDragAddOption= false;
00107       }
00108    fxDrawPad->cd();
00109 #ifdef __GO4USEASIMAGE__
00110    if(strstr(drawoptions,"asimage") && hist->InheritsFrom("TH2"))
00111       {
00112          // display 2d histo as image
00113          TH2* map=0;
00114          if(!InFileBrowser()) // disable drop from file into asimage for the moment!
00115             {
00116             map=dynamic_cast<TH2*>(hist);
00117             TGo4ASImage* pic=new TGo4ASImage(map);
00118             fxDrawPanel->SetActivePad(fxDrawPad);
00119             fxDrawPanel->ClearPad();
00120             pic->Draw();
00121             fxDrawPanel->UpdatePad(fxDrawPad, map, false);
00122             // later update with image properties (zoom box as limits?)
00123             }
00124             return;
00125       } else {}
00126 #endif //  __GO4USEASIMAGE__
00127    if(!PadDragAddOption)
00128       {
00129      // non superimpose; pad clear is done in dropEvent if necessary
00130      if(InFileBrowser())
00131       {
00132          if(browserslots)
00133              {
00134                // if item was already there with reference to another pad,
00135                // we have to redraw it on the drop pad
00136                TGo4Browser* browser=browserslots->GetBrowserGUI();
00137                TGo4QItem *memitem = (TGo4QItem*) browser->ListViewLocal->findItem(realname,0);
00138                if (memitem!=0)
00139                   {
00140                      memitem->DrawObj(fxDrawPanel,fxDrawPad);
00141                   }
00142              }
00143       }// if (InFileBrowser())
00144      else
00145         {
00146            hist->SetStats(statisticson);
00147            hist->Draw(drawoptions);
00148            fxDrawPanel->UpdatePad(fxDrawPad, hist, true);
00149         }
00150       }
00151    else
00152       {
00153      // superimpose mode
00154       if(InFileBrowser()) return; // disable adding the file histos to stack
00155                                   // will be done by BrowserSlots
00156      TObject *entry=0;
00157      TH1* h1=0;
00158      TIter iter(fxDrawPad->GetListOfPrimitives());
00159      while((entry = iter()) !=0) {
00160          if(entry->InheritsFrom(THStack::Class())){
00161             hs = dynamic_cast<THStack*> (entry);
00162             buffer.append(hs->GetTitle());
00163          }else if(entry->InheritsFrom(TH1::Class())){
00164             h1=dynamic_cast<TH1 *> (entry);
00165             buffer.append(h1->GetTitle());
00166          }
00167       } // while
00168 
00169       buffer1.append(hist->GetTitle());
00170       buffer.append(" : ");
00171       buffer.append(buffer1);
00172       if (hs!=0) {
00173          hs->SetTitle(buffer);
00174          (hs->GetHistogram())->SetTitle(buffer);
00175          // evaluate line colour for dropped:
00176          TList* hlist=hs->GetHists();
00177          if(hlist) {
00178            TH1* lasthist=(TH1*) hlist->Last();
00179            if(lasthist)
00180               hist->SetLineColor(lasthist->GetLineColor()+1);
00181          }
00182       } else {
00183          TDirectory* dirsav = gDirectory;
00184          gROOT->cd();
00185          hs = new THStack(buffer.data(),buffer.data());
00186          dirsav->cd();
00187 
00188          if (h1!=0) {
00189            hs->Add(h1); // put old histogram into stack
00190            hist->SetLineColor(h1->GetLineColor()+1);
00191          }
00192 
00193          if(browserslots)
00194             browserslots->AddObjectToLocalList(hs, kFALSE, kFALSE);
00195       }
00196       hs->Add(hist);
00197       hs->Modified();
00198       // change statistics display of all histograms here:
00199       TList* hlist = hs->GetHists();
00200       if(hlist) {
00201          TIter liter(hlist);
00202          TObject* hob=0;
00203          while((hob=liter())!=0) {
00204            TH1* hi=dynamic_cast<TH1*>(hob);
00205            if(hi) hi->SetStats(statisticson);
00206          }
00207       }
00208       // end stats display for stack
00209       hs->Draw("nostack");
00210       // register stack to memory list
00211       // note: if stack already exists there, UpdateOnline of TGo4QTHStackItem
00212       // is called to add new histograms. Stack in memory list is always
00213       // a copy of the original stack in our pad.
00214       fxDrawPanel->UpdatePad(fxDrawPad, hs);
00215    } // if(!PadDragAddOption)
00216 }
00217 
00218 void TGo4QTHItem::DropAction(QWidget *Recvr)
00219 {
00220    DrawObj(dynamic_cast<TGo4PreviewPanel *>(Recvr));
00221 }
00222 
00223 void TGo4QTHItem::GetOnlineObj()
00224 {
00225    TGo4MonitoredListSlots* fxTGo4MonitoredListSlots;
00226    fxTGo4MonitoredListSlots=dynamic_cast <TGo4MonitoredListSlots *> (fxTGo4GUIRegistry->GetSlotClass("TGo4MonitoredListSlots"));
00227    TGo4ComGetObject* com = new TGo4ComGetObject(text(0).data());
00228    fxTGo4GUIRegistry->SubmitCommand(com,text(0).data(),fxTGo4MonitoredListSlots,kTRUE);
00229 
00230 }
00231 void TGo4QTHItem::UpdateOnline(TObject *fxObj)
00232 {
00233    //cout <<"TGo4QTHItem::UpdateOnline" << endl;
00234    TH1* monhis=dynamic_cast <TH1*>(GetWorkObject());
00235    TH1* newhis=dynamic_cast<TH1*>(fxObj);
00236    if(newhis==0) return; // ignore non histogram objects of same name (case of status)
00237    if((monhis!=0) && (monhis!=fxObj)) { // for sync with memory, source and dest can be equal!
00238       Double_t ymin,ymax;
00239       bool keepscale=IsKeepScale();
00240       if(keepscale) {
00241          ymin = monhis->GetMinimum();
00242          ymax = monhis->GetMaximum();
00243       }
00244       monhis->Reset();
00245       monhis->Add(newhis);
00246       if(keepscale) {
00247          if (IsLogYScale() && (ymin==0) && (ymax>0)) {
00248             ymin = 1.; 
00249             if (ymin>0.01*ymax) ymin = 0.01*ymax;
00250          }
00251          monhis->SetMinimum(ymin); 
00252          monhis->SetMaximum(ymax); 
00253       }
00254       UpdateDrawPad();
00255    } // if(monhis)
00256 }
00257 
00258 void TGo4QTHItem::GetRemoteObj()
00259 {
00260    TGo4ComGetObject* com = new TGo4ComGetObject(text(0).data());
00261     fxTGo4GUIRegistry->SubmitCommand(com,text(0).data());
00262 }
00263 
00264 
00265 
00266 //----------------------------END OF GO4 SOURCE FILE ---------------------

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