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

/Go4GUI/TGo4MonitoredListSlots.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 "TGo4MonitoredListSlots.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TCanvas.h"
00021 
00022 #include "qlistview.h"
00023 #include "qmessagebox.h"
00024 #include "qptrlist.h"
00025 
00026 #include "Go4LockGuard/TGo4LockGuard.h"
00027 #include "Go4StatusBase/TGo4CanvasWrapper.h"
00028 #include "Go4Analysis/TGo4HistogramStatus.h"
00029 #include "Go4CommandsAnalysis/TGo4ComClearObject.h"
00030 #include "Go4GUIRegistry/TGo4GUIRegistry.h"
00031 #include "Go4QtBaseWidgets/TGo4QItem.h"
00032 #include "Go4QtBaseWidgets/TGo4QPicItem.h"
00033 #include "TGo4MonitoredListStatus.h"
00034 #include "TGo4MonitoredList.h"
00035 #include "TGo4BrowserStatus.h"
00036 #include "TGo4BrowserSlots.h"
00037 #include "TGo4PreviewPanelSlots.h"
00038 #include "TGo4PreviewPanel.h"
00039 #include "TGo4MonitoredObject.h"
00040 #include "TGo4PadOptions.h"
00041 #include "TGo4DockBrowsers.h"
00042 #include "TGo4MainWindow.h"
00043 
00044 
00045 TGo4MonitoredListSlots::TGo4MonitoredListSlots(const char * name, const char * title, TGo4MonitoredList * p)
00046                         :TGo4SlotsBaseClass(name , title), fxTGo4MonitoredList(p)
00047 {
00048     // TGo4LockGuard Global;
00049     fxTGo4GUIRegistry = TGo4GUIRegistry::Instance();
00050     fxTGo4MonitoredListStatus= new TGo4MonitoredListStatus("TGo4MonitoredListStatus", "MonitoredList");
00051     fxTGo4GUIRegistry->RegisterSlotClass(this, fxTGo4MonitoredListStatus, p);
00052     fxTGo4DockBrowsers=dynamic_cast <TGo4DockBrowsers *>((fxTGo4MonitoredList->parentWidget()->parentWidget()->parentWidget()->parentWidget()));
00053     fxMainWin = dynamic_cast <TGo4MainWindow *> (fxTGo4GUIRegistry->GetMainWindow());
00054 }
00055 
00056 void TGo4MonitoredListSlots::AddObject(TNamed *fxData)
00057 {
00058     TGo4LockGuard GlobalGuard;
00059     TGo4MonitoredObject *MonitoredObj=0;
00060     TGo4QItem * item1=0;
00061     MonitoredObj = fxTGo4MonitoredListStatus->GetMonitoredObject(fxData->GetName());
00062     if(MonitoredObj!=0){
00063         item1=MonitoredObj->GetMonObjItem();
00064         if (item1 !=0){
00065             item1->SetMonitorDone(false); // in case the object was requested from memory
00066             item1->UpdateOnline((TObject*)fxData);
00067             item1->SetMonitorDone(true);
00068             //cout <<"Monitor done for item "<<fxData->GetName() << endl;
00069          }
00070    }else{ //if(MonitoredObj!=0)
00071            TObject* addedobject=0;
00072          TGo4CanvasWrapper* cwrap=dynamic_cast<TGo4CanvasWrapper*>(fxData);
00073          if(cwrap)
00074             {
00075                //cout <<"MonitoredListSlots::AddObject has canvas wrapper." << endl;
00076                addedobject=cwrap->GetCanvas(kFALSE);
00077             }
00078          else
00079             {
00080                addedobject=fxData;
00081             }
00082       TObject* cloned=addedobject->Clone();
00083       TH1* clonedhis=dynamic_cast<TH1*>(cloned);
00084       if(clonedhis) clonedhis->SetDirectory(0); // avoid histograms to appear in root memory
00085       fxTGo4MonitoredListStatus->AddToMonitoredObjectList(cloned);
00086         QString Name, ClassName;
00087         Name= fxData->GetName();
00088         ClassName=fxData->ClassName();
00089         item1=fxTGo4DockBrowsers->CreateListViewItem(fxTGo4MonitoredList->ListViewMonitor,Name,ClassName);
00090         if (item1!=0){
00091             MonitoredObj = fxTGo4MonitoredListStatus->GetMonitoredObject(Name);
00092          item1->SetItemObject(MonitoredObj);
00093          if(MonitoredObj)
00094             {
00095                TObject* theObject=MonitoredObj->GetMonitoredObject();
00096                if(theObject) item1->setText(2,theObject->GetTitle()); // not yet provided in item factory
00097             }
00098          item1->SetMonitorDone(true);
00099             MonitoredObj->SetMonObjItem(item1);
00100             item1->AddToMonitorList();
00101         }
00102     }
00103 
00104 }
00105 
00106 
00107 void TGo4MonitoredListSlots::PlotSelected()
00108 {
00109     TGo4LockGuard Global;
00110     QPtrList <TGo4QItem> *SelectedLst = fxTGo4MonitoredList->GetSelectedItems();
00111     int NoOfObjects = SelectedLst->count();
00112     TGo4PreviewPanel * viewpanel =fxMainWin->ViewPanelSlot(NoOfObjects);
00113     TCanvas *canvas= viewpanel->GetCanvas();
00114     canvas->Resize();
00115     QPtrListIterator <TGo4QItem> it(*SelectedLst);
00116     TGo4QItem *Item;
00117    int PadNo=0;
00118    while ( (Item=it.current())!=0){
00119         ++it;
00120         canvas->cd(++PadNo);
00121        Item->DrawObj(viewpanel, (TPad *)gPad);
00122     }
00123     canvas->Update();
00124     fxTGo4MonitoredList->ListViewMonitor->clearSelection();
00125     
00126     delete SelectedLst;
00127 }
00128 
00129 void TGo4MonitoredListSlots::DeleteItem()
00130 {
00131     TGo4LockGuard Global;
00132     QPtrList <QListViewItem> *lst = new QPtrList <QListViewItem>;
00133     lst->setAutoDelete( TRUE );
00134 
00135        TObject *ItemToBeRemoved;
00136     QListViewItemIterator it(fxTGo4MonitoredList->ListViewMonitor);
00137         // iterate through all items of the list view
00138     for ( ; it.current(); ++it ) {
00139               if ( it.current()->isSelected() ){
00140                  ItemToBeRemoved = (fxTGo4MonitoredListStatus->GetMonitoredObject(it.current()->text(0)))->GetMonitoredObject();
00141                 fxTGo4MonitoredListStatus->RemoveMonitoredObject(ItemToBeRemoved);
00142                 fxTGo4GUIRegistry->RemoveFromSubmittedList(it.current()->text(0).data());
00143                 lst->append( it.current() );
00144         }
00145      }
00146      delete lst;
00147 }
00148 
00149 void TGo4MonitoredListSlots::ItemDoubleClicked ( QListViewItem *MonitoredObject)
00150 {
00151 // TGo4LockGuard Global;
00152     PlotSelected();
00153 }
00154 void TGo4MonitoredListSlots::SetGUI(TGo4MonitoredList* GUI)
00155 {
00156     fxTGo4MonitoredList=GUI;
00157     fxTGo4GUIRegistry->GuiIsChanged(this, GUI);
00158 }
00159 
00160 TGo4MonitoredList* TGo4MonitoredListSlots::GetGUI() {
00161    return fxTGo4MonitoredList;
00162 }
00163 
00164 TGo4MonitoredListSlots::~TGo4MonitoredListSlots()
00165 {
00166     delete fxTGo4MonitoredListStatus;
00167 }
00168 
00169 void TGo4MonitoredListSlots::StatusChanged(TGo4Status * s)
00170 {
00171 }
00172 TGo4Status * TGo4MonitoredListSlots::GetStatus()
00173 {
00174     return fxTGo4MonitoredListStatus;
00175 }
00176 void TGo4MonitoredListSlots::SendToLocalList()
00177 {
00178     TGo4LockGuard Global();
00179     TGo4QItem * item1=0;
00180        TGo4BrowserSlots*     fxTGo4BrowserSlots;
00181     fxTGo4BrowserSlots = (TGo4BrowserSlots *) fxTGo4GUIRegistry->GetSlotClass("TGo4BrowserSlots");
00182     if (fxTGo4BrowserSlots!=0){
00183         QListViewItemIterator it(fxTGo4MonitoredList->ListViewMonitor);
00184         // iterate through all items of the list view
00185             for ( ; it.current(); ++it ) {
00186                   if ( it.current()->isSelected() ){
00187                           item1=dynamic_cast <TGo4QItem *> (it.current());
00188                         TGo4MonitoredObject *ObjToAdd =dynamic_cast <TGo4MonitoredObject *> (item1->GetItemObject());
00189                         if(ObjToAdd !=0){
00190                      TObject* ob=ObjToAdd->GetMonitoredObject()->Clone();
00191                      TCanvas* can=dynamic_cast<TCanvas*>(ob);
00192                      if(can)
00193                         {
00194                           ob=new TGo4CanvasWrapper(can);
00195                         }
00196 
00197                             fxTGo4BrowserSlots->AddObjectToLocalList(dynamic_cast<TNamed*>(ob));
00198                      delete ob;
00199                         }
00200                 }
00201             }
00202     }
00203 }
00204 
00205 void TGo4MonitoredListSlots::StartMonitoring()
00206 {
00207 
00208     // TGo4LockGuard Global;
00209    if(!IsAllMonitorDone()) return;
00210    TGo4QItem * item1=0;
00211    TGo4QPicItem* picitem=0;
00212     QListViewItemIterator it(fxTGo4MonitoredList->ListViewMonitor);
00213        bool Mon= kFALSE;
00214     // iterate through all items of the list view
00215     for ( ; it.current(); ++it ) {
00216         item1=dynamic_cast <TGo4QItem *> (it.current());
00217         picitem=dynamic_cast <TGo4QPicItem *> (item1); // skip pictures
00218         if (item1!=0 && picitem==0){
00219              item1->GetRemoteObj();
00220           item1->SetMonitorDone(false);
00221               Mon= kTRUE;
00222         }
00223     }
00224 
00225     if(!Mon){
00226         fxTGo4MonitoredList->StopMonitoring();
00227     }
00228 
00229 }
00230 
00231 void TGo4MonitoredListSlots::MonitorVisible()
00232 {
00233     // TGo4LockGuard Global;
00234     if(!IsAllMonitorDone()) return;
00235     TGo4QItem * item1=0;
00236     TGo4QPicItem* picitem=0;
00237     TGo4MonitoredObject *fxTGo4MonitoredObject=0;
00238     bool Vis= kFALSE;
00239     QListViewItemIterator it(fxTGo4MonitoredList->ListViewMonitor);
00240     // iterate through all items of the list view
00241     for ( ; it.current(); ++it ) {
00242         item1=dynamic_cast <TGo4QItem *> (it.current());
00243         picitem=dynamic_cast <TGo4QPicItem *> (item1); // skip pictures
00244         if (item1!=0 && picitem==0){
00245             TObject* itemobject=item1->GetItemObject();
00246          fxTGo4MonitoredObject= dynamic_cast <TGo4MonitoredObject*> (itemobject);
00247             if(fxTGo4MonitoredObject==0)
00248             {
00249                 cout <<"NEVER COME HERE" << endl;
00250                 cout <<"\t item "<<item1->text(0)<<" has no monitored ob" << endl;
00251                 continue;
00252             }
00253 
00254          if(fxTGo4MonitoredObject->GetPreViewPanel()!=0){
00255                  Vis=kTRUE;
00256                  item1->GetRemoteObj();
00257              item1->SetMonitorDone(false);
00258              //cout <<"Requesting monitored object "<<item1->text(0) << endl;
00259             }
00260         }
00261     }
00262 
00263     if(!Vis){
00264          fxTGo4MonitoredList->StopMonitoring();
00265     }
00266 
00267 }
00268 
00269 void TGo4MonitoredListSlots::ResetRemoteObj(const char* ObjName)
00270 {
00271     // TGo4LockGuard Global;
00272     TGo4ComClearObject *com = new TGo4ComClearObject(ObjName);
00273     fxTGo4GUIRegistry->SubmitCommand(com);
00274 }
00275 
00276 Bool_t TGo4MonitoredListSlots::IsAllMonitorDone()
00277 {
00278 Bool_t result=kTRUE;
00279 TGo4QItem * item1=0;
00280 QListViewItemIterator it(fxTGo4MonitoredList->ListViewMonitor);
00281 // iterate through all items of the list view
00282 for ( ; it.current(); ++it )
00283    {
00284         item1=dynamic_cast <TGo4QItem *> (it.current());
00285         if (item1!=0)
00286          {
00287              result=item1->IsMonitorDone();
00288           if(!result) break;
00289          }
00290    }
00291 return result;
00292 }
00293 
00294 //----------------------------END OF GO4 SOURCE FILE ---------------------

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