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

/Go4QtBaseWidgets/TGo4QGraphItem.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 "TGo4QGraphItem.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TPad.h"
00021 #include "TGraph.h"
00022 
00023 #include "Go4GUIRegistry/TGo4GUIRegistry.h"
00024 #include "Go4GUI/TGo4PreviewPanel.h"
00025 #include "Go4GUI/TGo4MonitoredObject.h"
00026 #include "Go4GUI/TGo4BrowserSlots.h"
00027 #include "Go4GUI/TGo4BrowserStatus.h"
00028 #include "Go4GUI/TGo4Browser.h"
00029 #include "Go4GUI/TGo4QRootCanvas.h"
00030 
00031 TGo4QGraphItem::TGo4QGraphItem( QListViewItem* parent, const QString & text, const QString & text1,  const QString & text2)
00032    :TGo4QTHItem (parent, "tgraph.png", text, text1, text2)
00033 {
00034 }
00035 
00036 TGo4QGraphItem::TGo4QGraphItem( QListView* parent, const QString & text, const QString & text1,  const QString & text2)
00037    :TGo4QTHItem (parent, "tgraph.png", text, text1, text2)
00038 {
00039 }
00040 
00041 TGo4QGraphItem::~TGo4QGraphItem(){}
00042 
00043 void TGo4QGraphItem::DrawObj(TGo4PreviewPanel *viewpanel, TPad* currentpad)
00044 {
00045    if(!AssignDrawPanel(viewpanel, currentpad)) return;
00046    TGraph* Gr=dynamic_cast<TGraph *> (GetWorkObject());
00047    if(Gr!=0 && Gr->GetN()>=1)
00048       {
00049          QString realname=Gr->GetName();
00050          TGo4BrowserSlots* browserslots = dynamic_cast <TGo4BrowserSlots *>(fxTGo4GUIRegistry->GetSlotClass("TGo4BrowserSlots"));
00051          TGo4Browser* browser=browserslots->GetBrowserGUI();
00052          if(InFileBrowser())
00053             {
00054                if(browserslots)  //browserslots->AddObjectToLocalList(hist,false);
00055                {
00056                 browserslots->AddObject(Gr,fxDrawPanel->GetQCanvas(),fxDrawPad);
00057                 realname=browserslots->GetAddedItemName();
00058                 //cout <<"DrawObj in file browser sends to membrowser" << endl;
00059                // if item was already there with reference to another pad,
00060                // we have to redraw it on the drop pad               
00061                fxDrawPad->cd();
00062                TGo4QItem *memitem = (TGo4QItem*) browser->ListViewLocal->findItem(realname,0);
00063                if (memitem!=0)
00064                   {
00065                      memitem->DrawObj(fxDrawPanel,fxDrawPad);
00066                   }
00067                }// if(browserslots)
00068             } // if(InFileBrowser())
00069          else
00070             {
00071                TPad* padsav=fxDrawPanel->GetActivePad();
00072                fxDrawPanel->SetActivePad(fxDrawPad);
00073                fxDrawPanel->ClearPad();
00074                Gr->Draw("AP");
00075                fxDrawPanel->UpdatePad(fxDrawPad, Gr->GetHistogram(),false);
00076                fxDrawPanel->SetActivePad(padsav);
00077             }
00078       } //if(Gr!=0 && Gr->GetN()>=1)
00079 }
00080 
00081 void TGo4QGraphItem::UpdateOnline(TObject *fxObj)
00082 {
00083 bool keepscale=IsKeepScale();
00084 TGraph* LocalGraph=dynamic_cast <TGraph*>(GetWorkObject());
00085 TGraph* NewGraph=dynamic_cast <TGraph*>(fxObj);
00086 if(LocalGraph )
00087    {
00088    if(LocalGraph->GetN()>=1)
00089       {
00090       TH1* axeshistogram=LocalGraph->GetHistogram();
00091       Int_t xminbin=0;
00092       Int_t xmaxbin=0;
00093       Double_t ymin=0;
00094       Double_t ymax=0;
00095       if(keepscale && axeshistogram)
00096          {
00097          xminbin=axeshistogram->GetXaxis()->GetFirst();
00098          xmaxbin=axeshistogram->GetXaxis()->GetLast();
00099          ymin=axeshistogram->GetMinimum();
00100          ymax=axeshistogram->GetMaximum();
00101          }
00102       // reset graph on canvas:
00103       LocalGraph->Set(0); // clear array of points
00104       // copy contents of new graph to old one:
00105       Int_t pn=NewGraph->GetN();
00106       Double_t xp=0;
00107       Double_t yp=0;
00108       for(Int_t i=0; i<pn; ++i)
00109          {
00110            NewGraph->GetPoint(i,xp,yp);
00111            LocalGraph->SetPoint(i,xp,yp);
00112          }
00113       axeshistogram=LocalGraph->GetHistogram();
00114       if(keepscale && axeshistogram)
00115          {
00116          TAxis* xax=axeshistogram->GetXaxis();
00117          if(xax) xax->SetRange(xminbin,xmaxbin);
00118          LocalGraph->SetMinimum(ymin);
00119          LocalGraph->SetMaximum(ymax);
00120          }
00121       else
00122          {
00123           if(axeshistogram)
00124               {
00125               axeshistogram->ResetBit(TH1::kIsZoomed);
00126               Double_t oldmin=0;
00127               Double_t oldmax=0;
00128               TH1* newhis=NewGraph->GetHistogram();
00129               if(newhis)
00130                  {
00131                      oldmin=newhis->GetMinimum();
00132                      oldmax=1.1 * newhis->GetMaximum();
00133                  }
00134               LocalGraph->SetMinimum(oldmin);
00135               LocalGraph->SetMaximum(oldmax);
00136               }
00137          }
00138       } // if(LocalGraph->GetN()>=1)
00139    else
00140       {
00141           // case of graph without points: replace old and draw
00142           TGo4QItem::UpdateOnline(fxObj); // overwrite local object in memory list
00143           DrawObj(fxDrawPanel);
00144       }
00145    UpdateDrawPad();
00146 }// if(LocalGraph)
00147 
00148 }
00149 
00150 //----------------------------END OF GO4 SOURCE FILE ---------------------

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