TEveManager.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveManager.cxx 35074 2010-08-30 15:18:02Z matevz $
00002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TEveManager.h"
00013 
00014 #include "TEveSelection.h"
00015 #include "TEveViewer.h"
00016 #include "TEveScene.h"
00017 #include "TEveEventManager.h"
00018 #include "TEveWindowManager.h"
00019 
00020 #include "TEveBrowser.h"
00021 #include "TEveGedEditor.h"
00022 
00023 #include "TGStatusBar.h"
00024 
00025 #include "TGLSAViewer.h"
00026 
00027 #include "TGeoManager.h"
00028 #include "TGeoMatrix.h"
00029 #include "TObjString.h"
00030 #include "TROOT.h"
00031 #include "TFile.h"
00032 #include "TMap.h"
00033 #include "TExMap.h"
00034 #include "TMacro.h"
00035 #include "TFolder.h"
00036 #include "TBrowser.h"
00037 #include "TCanvas.h"
00038 #include "TSystem.h"
00039 #include "TRint.h"
00040 #include "TVirtualX.h"
00041 #include "TEnv.h"
00042 #include "TColor.h"
00043 #include "TVirtualGL.h"
00044 #include "TPluginManager.h"
00045 #include "TPRegexp.h"
00046 #include "TClass.h"
00047 
00048 #include "Riostream.h"
00049 
00050 TEveManager* gEve = 0;
00051 
00052 //______________________________________________________________________________
00053 // TEveManager
00054 //
00055 // Central aplication manager for Eve.
00056 // Manages elements, GUI, GL scenes and GL viewers.
00057 
00058 ClassImp(TEveManager);
00059 
00060 //______________________________________________________________________________
00061 TEveManager::TEveManager(UInt_t w, UInt_t h, Bool_t map_window, Option_t* opt) :
00062    fExcHandler  (0),
00063    fVizDB       (0), fVizDBReplace(kTRUE), fVizDBUpdate(kTRUE),
00064    fGeometries  (0),
00065    fGeometryAliases (0),
00066    fBrowser     (0),
00067 
00068    fMacroFolder (0),
00069 
00070    fWindowManager  (0),
00071    fViewers        (0),
00072    fScenes         (0),
00073    fGlobalScene    (0),
00074    fEventScene     (0),
00075    fCurrentEvent   (0),
00076 
00077    fRedrawDisabled (0),
00078    fResetCameras   (kFALSE),
00079    fDropLogicals   (kFALSE),
00080    fKeepEmptyCont  (kFALSE),
00081    fTimerActive    (kFALSE),
00082    fRedrawTimer    (),
00083 
00084    fStampedElements(0),
00085    fSelection      (0),
00086    fHighlight      (0),
00087 
00088    fOrphanage      (0),
00089    fUseOrphanage   (kFALSE)
00090 {
00091    // Constructor.
00092    // If map_window is true, the TEveBrowser window is mapped.
00093    //
00094    // Option string is first parsed for the following characters:
00095    //   V - spawn a default GL viewer.
00096    //
00097    // The consumed characters are removed from the options and they
00098    // are passed to TEveBrowser for creation of additional plugins.
00099    //
00100    // Default options: "FIV" - file-browser, command-line, GL-viewer.
00101 
00102 
00103    static const TEveException eh("TEveManager::TEveManager ");
00104 
00105    if (gEve != 0)
00106       throw(eh + "There can be only one!");
00107 
00108    gEve = this;
00109 
00110    fExcHandler = new TExceptionHandler;
00111 
00112    fGeometries      = new TMap; fGeometries->SetOwnerKeyValue();
00113    fGeometryAliases = new TMap; fGeometryAliases->SetOwnerKeyValue();
00114    fVizDB           = new TMap; fVizDB->SetOwnerKeyValue();
00115 
00116    fStampedElements = new TExMap;
00117 
00118    fSelection = new TEveSelection("Global Selection");
00119    fSelection->IncDenyDestroy();
00120    fHighlight = new TEveSelection("Global Highlight");
00121    fHighlight->SetHighlightMode();
00122    fHighlight->IncDenyDestroy();
00123 
00124    fOrphanage = new TEveElementList("Global Orphanage");
00125    fOrphanage->IncDenyDestroy();
00126 
00127    fRedrawTimer.Connect("Timeout()", "TEveManager", this, "DoRedraw3D()");
00128    fMacroFolder = new TFolder("EVE", "Visualization macros");
00129    gROOT->GetListOfBrowsables()->Add(fMacroFolder);
00130 
00131 
00132    fWindowManager = new TEveWindowManager("WindowManager", "Manager of EVE windows");
00133 
00134    // Build GUI
00135    fBrowser   = new TEveBrowser(w, h);
00136    fBrowser->Connect("CloseWindow()", "TEveManager", this, "CloseEveWindow()");
00137 
00138    // ListTreeEditor
00139    fBrowser->StartEmbedding(0);
00140    fLTEFrame = new TEveGListTreeEditorFrame;
00141    fBrowser->StopEmbedding("Eve");
00142    fLTEFrame->ConnectSignals();
00143 
00144    // See how many GL viewers are requested, remove from options.
00145    TString str_opt(opt);
00146    TPMERegexp viewer_re("V", "g");
00147    Int_t viewer_count = viewer_re.Substitute(str_opt, "", kFALSE);
00148 
00149    // Create the main window / browse.
00150    fBrowser->InitPlugins(str_opt);
00151    if (map_window)
00152       fBrowser->MapWindow();
00153 
00154    // --------------------------------
00155 
00156    fWindowManager->IncDenyDestroy();
00157    AddToListTree(fWindowManager, kFALSE);
00158 
00159    fViewers = new TEveViewerList("Viewers");
00160    fViewers->IncDenyDestroy();
00161    AddToListTree(fViewers, kFALSE);
00162 
00163    fScenes  = new TEveSceneList ("Scenes");
00164    fScenes->IncDenyDestroy();
00165    AddToListTree(fScenes, kFALSE);
00166 
00167    fGlobalScene = new TEveScene("Geometry scene");
00168    fGlobalScene->IncDenyDestroy();
00169    fScenes->AddElement(fGlobalScene);
00170 
00171    fEventScene = new TEveScene("Event scene");
00172    fEventScene->IncDenyDestroy();
00173    fScenes->AddElement(fEventScene);
00174 
00175    for (Int_t vc = 0; vc < viewer_count; ++vc)
00176    {
00177       TEveViewer* v = SpawnNewViewer(Form("Viewer %d", vc+1));
00178       v->AddScene(fGlobalScene);
00179       v->AddScene(fEventScene);
00180    }
00181 
00182    if (GetDefaultViewer())
00183    {
00184       EditElement(GetDefaultViewer());
00185    }
00186 
00187    /**************************************************************************/
00188    /**************************************************************************/
00189 
00190    gSystem->ProcessEvents();
00191 }
00192 
00193 //______________________________________________________________________________
00194 TEveManager::~TEveManager()
00195 {
00196    // Destructor.
00197 
00198    // Stop timer and deny further redraw requests.
00199    fRedrawTimer.Stop();
00200    fTimerActive = kTRUE;
00201 
00202    delete fCurrentEvent;
00203    fCurrentEvent = 0;
00204 
00205    fGlobalScene->DecDenyDestroy();
00206    fEventScene->DecDenyDestroy();
00207    fScenes->DestroyScenes();
00208    fScenes->DecDenyDestroy();
00209    fScenes->Destroy();
00210    fScenes = 0;
00211 
00212    fViewers->DestroyElements();
00213    fViewers->DecDenyDestroy();
00214    fViewers->Destroy();
00215    fViewers = 0;
00216 
00217    fWindowManager->DestroyWindows();
00218    fWindowManager->DecDenyDestroy();
00219    fWindowManager->Destroy();
00220    fWindowManager = 0;
00221 
00222    fOrphanage->DecDenyDestroy();
00223    fHighlight->DecDenyDestroy();
00224    fSelection->DecDenyDestroy();
00225 
00226    delete fMacroFolder;
00227    delete fStampedElements;
00228    delete fGeometryAliases;
00229    delete fGeometries;
00230    delete fVizDB;
00231    delete fExcHandler;
00232 
00233    fLTEFrame->DeleteWindow();
00234 
00235    fBrowser->Disconnect("CloseWindow()", this, "CloseEveWindow()");
00236    fBrowser->GetMainFrame()->DontCallClose();
00237    fBrowser->GetMainFrame()->CloseWindow();
00238 }
00239 
00240 //______________________________________________________________________________
00241 void TEveManager::ClearOrphanage()
00242 {
00243    // Clear the orphanage.
00244 
00245    Bool_t old_state = fUseOrphanage;
00246    fUseOrphanage = kFALSE;
00247    fOrphanage->DestroyElements();
00248    fUseOrphanage = old_state;
00249 }
00250 
00251 //==============================================================================
00252 
00253 //______________________________________________________________________________
00254 TGWindow* TEveManager::GetMainWindow() const
00255 {
00256    // Get the main window, i.e. EVE-browser.
00257 
00258    return fBrowser;
00259 }
00260 
00261 //______________________________________________________________________________
00262 TEveViewer* TEveManager::GetDefaultViewer() const
00263 {
00264    // Returns the default viewer - the first one in the fViewers list.
00265 
00266    return dynamic_cast<TEveViewer*>(fViewers->FirstChild());
00267 }
00268 
00269 //______________________________________________________________________________
00270 TGLViewer* TEveManager::GetDefaultGLViewer() const
00271 {
00272    // Get TGLViewer of the default TEveViewer.
00273 
00274    TEveViewer *ev = GetDefaultViewer();
00275    return ev ? ev->GetGLViewer() : 0;
00276 }
00277 
00278 //______________________________________________________________________________
00279 TEveGedEditor* TEveManager::GetEditor() const
00280 {
00281    // Returns main object editor.
00282 
00283    return fLTEFrame->GetEditor();
00284 }
00285 
00286 //______________________________________________________________________________
00287 TGStatusBar* TEveManager::GetStatusBar() const
00288 {
00289    // Returns main window status bar.
00290 
00291    return fBrowser->GetStatusBar();
00292 }
00293 
00294 //==============================================================================
00295 
00296 //______________________________________________________________________________
00297 TCanvas* TEveManager::AddCanvasTab(const char* name)
00298 {
00299    // Add a new canvas tab.
00300 
00301    fBrowser->StartEmbedding(1, -1);
00302    TCanvas* c = new TCanvas;
00303    fBrowser->StopEmbedding(name);
00304 
00305    return c;
00306 }
00307 
00308 //______________________________________________________________________________
00309 TEveViewer* TEveManager::SpawnNewViewer(const char* name, const char* title,
00310                                         Bool_t embed)
00311 {
00312    // Create a new GL viewer.
00313 
00314    TEveWindowSlot* slot = 0;
00315    if (embed)
00316    {
00317       slot = fWindowManager->GetCurrentWindowAsSlot();
00318       if (slot == 0)
00319       {
00320          // In principle should have some default/current container
00321          // in TEveWindowManager.
00322          // Also to store closed windows.
00323          slot = TEveWindow::CreateWindowInTab(fBrowser->GetTabRight());
00324       }
00325    }
00326    else
00327    {
00328       slot = TEveWindow::CreateWindowMainFrame();
00329    }
00330 
00331    TEveViewer* v = new TEveViewer(name, title);
00332    v->SpawnGLViewer(embed ? GetEditor() : 0);
00333 
00334    slot->ReplaceWindow(v);
00335 
00336    fViewers->AddElement(v);
00337 
00338    return v;
00339 }
00340 
00341 //______________________________________________________________________________
00342 TEveScene* TEveManager::SpawnNewScene(const char* name, const char* title)
00343 {
00344    // Create a new scene.
00345 
00346    TEveScene* s = new TEveScene(name, title);
00347    AddElement(s, fScenes);
00348    return s;
00349 }
00350 
00351 /******************************************************************************/
00352 // Macro management
00353 /******************************************************************************/
00354 
00355 //______________________________________________________________________________
00356 TMacro* TEveManager::GetMacro(const char* name) const
00357 {
00358    // Find macro in fMacroFolder by name.
00359 
00360    return dynamic_cast<TMacro*>(fMacroFolder->FindObject(name));
00361 }
00362 
00363 /******************************************************************************/
00364 // Editor
00365 /******************************************************************************/
00366 
00367 //______________________________________________________________________________
00368 void TEveManager::EditElement(TEveElement* element)
00369 {
00370    // Show element in default editor.
00371 
00372    static const TEveException eh("TEveManager::EditElement ");
00373 
00374    GetEditor()->DisplayElement(element);
00375 }
00376 
00377 /******************************************************************************/
00378 // 3D TEvePad management
00379 /******************************************************************************/
00380 
00381 //______________________________________________________________________________
00382 void TEveManager::RegisterRedraw3D()
00383 {
00384    // Register a request for 3D redraw.
00385 
00386    fRedrawTimer.Start(0, kTRUE);
00387    fTimerActive = kTRUE;
00388 }
00389 
00390 //______________________________________________________________________________
00391 void TEveManager::DoRedraw3D()
00392 {
00393    // Perform 3D redraw of scenes and viewers whose contents has
00394    // changed.
00395 
00396    static const TEveException eh("TEveManager::DoRedraw3D ");
00397 
00398    // printf("TEveManager::DoRedraw3D redraw triggered\n");
00399 
00400    // Process element visibility changes, mark relevant scenes as changed.
00401    {
00402       TEveElement::List_t scenes;
00403       Long64_t   key, value;
00404       TExMapIter stamped_elements(fStampedElements);
00405       while (stamped_elements.Next(key, value))
00406       {
00407          TEveElement *el = reinterpret_cast<TEveElement*>(key);
00408          if (el->GetChangeBits() & TEveElement::kCBVisibility)
00409          {
00410             el->CollectSceneParents(scenes);
00411          }
00412       }
00413       ScenesChanged(scenes);
00414    }
00415 
00416    // Process changes in scenes.
00417    fScenes ->ProcessSceneChanges(fDropLogicals, fStampedElements);
00418    fViewers->RepaintChangedViewers(fResetCameras, fDropLogicals);
00419 
00420    // Process changed elements again, update GUI (just editor so far,
00421    // but more can come).
00422    {
00423       Long64_t   key, value;
00424       TExMapIter stamped_elements(fStampedElements);
00425       while (stamped_elements.Next(key, value))
00426       {
00427          TEveElement *el = reinterpret_cast<TEveElement*>(key);
00428          if (GetEditor()->GetModel() == el->GetEditorObject(eh))
00429             EditElement(el);
00430          TEveGedEditor::ElementChanged(el);
00431 
00432          el->ClearStamps();
00433       }
00434    }
00435    fStampedElements->Delete();
00436    GetListTree()->ClearViewPort(); // Fix this when several list-trees can be added.
00437 
00438    fResetCameras = kFALSE;
00439    fDropLogicals = kFALSE;
00440 
00441    fTimerActive = kFALSE;
00442 }
00443 
00444 //______________________________________________________________________________
00445 void TEveManager::FullRedraw3D(Bool_t resetCameras, Bool_t dropLogicals)
00446 {
00447    // Perform 3D redraw of all scenes and viewers.
00448 
00449    fScenes ->RepaintAllScenes (dropLogicals);
00450    fViewers->RepaintAllViewers(resetCameras, dropLogicals);
00451 }
00452 
00453 /******************************************************************************/
00454 
00455 //______________________________________________________________________________
00456 void TEveManager::ElementChanged(TEveElement* element, Bool_t update_scenes, Bool_t redraw)
00457 {
00458    // Element was changed, perform framework side action.
00459    // Called from TEveElement::ElementChanged().
00460 
00461    static const TEveException eh("TEveElement::ElementChanged ");
00462 
00463    if (GetEditor()->GetModel() == element->GetEditorObject(eh))
00464       EditElement(element);
00465    TEveGedEditor::ElementChanged(element);
00466 
00467    if (update_scenes) {
00468       TEveElement::List_t scenes;
00469       element->CollectSceneParents(scenes);
00470       ScenesChanged(scenes);
00471    }
00472 
00473    if (redraw)
00474       Redraw3D();
00475 }
00476 
00477 //______________________________________________________________________________
00478 void TEveManager::ScenesChanged(TEveElement::List_t& scenes)
00479 {
00480    // Mark all scenes from the given list as changed.
00481 
00482    for (TEveElement::List_i s=scenes.begin(); s!=scenes.end(); ++s)
00483       ((TEveScene*)*s)->Changed();
00484 }
00485 
00486 //______________________________________________________________________________
00487 void TEveManager::ElementStamped(TEveElement* element)
00488 {
00489    // Mark element as changed -- it will be processed on next redraw.
00490 
00491    UInt_t slot;
00492    if (fStampedElements->GetValue((ULong_t) element, (Long_t) element, slot) == 0)
00493    {
00494       fStampedElements->AddAt(slot, (ULong_t) element, (Long_t) element, 1);
00495    }
00496 }
00497 
00498 
00499 /******************************************************************************/
00500 // GUI interface
00501 /******************************************************************************/
00502 
00503 //______________________________________________________________________________
00504 TGListTree* TEveManager::GetListTree() const
00505 {
00506    // Get default list-tree widget.
00507 
00508    return fLTEFrame->fListTree;
00509 }
00510 
00511 TGListTreeItem*
00512 TEveManager::AddToListTree(TEveElement* re, Bool_t open, TGListTree* lt)
00513 {
00514    // Add element as a top-level to a list-tree.
00515    // Only add a single copy of a render-element as a top level.
00516 
00517    if (lt == 0) lt = GetListTree();
00518    TGListTreeItem* lti = re->AddIntoListTree(lt, (TGListTreeItem*)0);
00519    if (open) lt->OpenItem(lti);
00520    return lti;
00521 }
00522 
00523 //______________________________________________________________________________
00524 void TEveManager::RemoveFromListTree(TEveElement* element,
00525                                      TGListTree* lt, TGListTreeItem* lti)
00526 {
00527    // Remove top-level element from list-tree with specified tree-item.
00528 
00529    static const TEveException eh("TEveManager::RemoveFromListTree ");
00530 
00531    if (lti->GetParent())
00532       throw(eh + "not a top-level item.");
00533 
00534    element->RemoveFromListTree(lt, 0);
00535 }
00536 
00537 /******************************************************************************/
00538 
00539 //______________________________________________________________________________
00540 TGListTreeItem* TEveManager::AddEvent(TEveEventManager* event)
00541 {
00542    // Add a new event and make it the current event.
00543    // It is added into the event-scene and as a top-level list-tree
00544    // item.
00545 
00546    fCurrentEvent = event;
00547    fCurrentEvent->IncDenyDestroy();
00548    AddElement(fCurrentEvent, fEventScene);
00549    return AddToListTree(event, kTRUE);
00550 }
00551 
00552 //______________________________________________________________________________
00553 void TEveManager::AddElement(TEveElement* element, TEveElement* parent)
00554 {
00555    // Add an element. If parent is not specified it is added into
00556    // current event (which is created if does not exist).
00557 
00558    if (parent == 0) {
00559       if (fCurrentEvent == 0)
00560          AddEvent(new TEveEventManager("Event", "Auto-created event directory"));
00561       parent = fCurrentEvent;
00562    }
00563 
00564    parent->AddElement(element);
00565 }
00566 
00567 //______________________________________________________________________________
00568 void TEveManager::AddGlobalElement(TEveElement* element, TEveElement* parent)
00569 {
00570    // Add a global element, i.e. one that does not change on each
00571    // event, like geometry or projection manager.
00572    // If parent is not specified it is added to a global scene.
00573 
00574    if (parent == 0)
00575       parent = fGlobalScene;
00576 
00577    parent->AddElement(element);
00578 }
00579 
00580 /******************************************************************************/
00581 
00582 //______________________________________________________________________________
00583 void TEveManager::RemoveElement(TEveElement* element,
00584                                 TEveElement* parent)
00585 {
00586    // Remove element from parent.
00587 
00588    parent->RemoveElement(element);
00589 }
00590 
00591 //______________________________________________________________________________
00592 void TEveManager::PreDeleteElement(TEveElement* element)
00593 {
00594    // Called from TEveElement prior to its destruction so the
00595    // framework components (like object editor) can unreference it.
00596 
00597    if (GetEditor()->GetEveElement() == element)
00598       EditElement(0);
00599    TEveGedEditor::ElementDeleted(element);
00600 
00601    if (fScenes)
00602       fScenes->DestroyElementRenderers(element);
00603 
00604    if (fStampedElements->GetValue((ULong_t) element, (Long_t) element) != 0)
00605       fStampedElements->Remove((ULong_t) element, (Long_t) element);
00606 
00607    if (element->fImpliedSelected > 0)
00608       fSelection->RemoveImpliedSelected(element);
00609    if (element->fImpliedHighlighted > 0)
00610       fHighlight->RemoveImpliedSelected(element);
00611 }
00612 
00613 /******************************************************************************/
00614 
00615 //______________________________________________________________________________
00616 void TEveManager::ElementSelect(TEveElement* element)
00617 {
00618    // Select an element.
00619    // Now it only calls EditElement() - should also update selection state.
00620 
00621    if (element != 0)
00622       EditElement(element);
00623 }
00624 
00625 //______________________________________________________________________________
00626 Bool_t TEveManager::ElementPaste(TEveElement* element)
00627 {
00628    // Paste has been called.
00629 
00630    // The object to paste is taken from the editor (this is not
00631    // exactly right) and handed to 'element' for pasting.
00632 
00633    TEveElement* src = GetEditor()->GetEveElement();
00634    if (src)
00635       return element->HandleElementPaste(src);
00636    return kFALSE;
00637 }
00638 
00639 
00640 //==============================================================================
00641 // VizDB interface
00642 //==============================================================================
00643 
00644 //______________________________________________________________________________
00645 Bool_t TEveManager::InsertVizDBEntry(const TString& tag, TEveElement* model,
00646                                      Bool_t replace, Bool_t update)
00647 {
00648    // Insert a new visualization-parameter database entry. Returns
00649    // true if the element is inserted successfully.
00650    // If entry with the same key already exists the behaviour depends on the
00651    // 'replace' flag:
00652    //   true  - The old model is deleted and new one is inserted (default).
00653    //           Clients of the old model are transferred to the new one and
00654    //           if 'update' flag is true (default), the new model's parameters
00655    //           are assigned to all clients.
00656    //   false - The old model is kept, false is returned.
00657    //
00658    // If insert is successful, the ownership of the model-element is
00659    // transferred to the manager.
00660 
00661    TPair* pair = (TPair*) fVizDB->FindObject(tag);
00662    if (pair)
00663    {
00664       if (replace)
00665       {
00666          model->IncDenyDestroy();
00667          model->SetRnrChildren(kFALSE);
00668 
00669          TEveElement* old_model = dynamic_cast<TEveElement*>(pair->Value());
00670          while (old_model->HasChildren())
00671          {
00672             TEveElement *el = old_model->FirstChild();
00673             el->SetVizModel(model);
00674             if (update)
00675             {
00676                el->CopyVizParams(model);
00677                el->PropagateVizParamsToProjecteds();
00678             }
00679          }
00680          old_model->DecDenyDestroy();
00681 
00682          pair->SetValue(dynamic_cast<TObject*>(model));
00683          return kTRUE;
00684       }
00685       else
00686       {
00687          return kFALSE;
00688       }
00689    }
00690    else
00691    {
00692       model->IncDenyDestroy();
00693       model->SetRnrChildren(kFALSE);
00694       fVizDB->Add(new TObjString(tag), dynamic_cast<TObject*>(model));
00695       return kTRUE;
00696    }
00697 }
00698 
00699 //______________________________________________________________________________
00700 Bool_t TEveManager::InsertVizDBEntry(const TString& tag, TEveElement* model)
00701 {
00702    // Insert a new visualization-parameter database entry with the default
00703    // parameters for replace and update, as specified by members
00704    // fVizDBReplace(default=kTRUE) and fVizDBUpdate(default=kTRUE).
00705    // See docs of the above function.
00706 
00707    return InsertVizDBEntry(tag, model, fVizDBReplace, fVizDBUpdate);
00708 }
00709 
00710 //______________________________________________________________________________
00711 TEveElement* TEveManager::FindVizDBEntry(const TString& tag)
00712 {
00713    // Find a visualization-parameter database entry corresponding to tag.
00714    // If the entry is not found 0 is returned.
00715 
00716    return dynamic_cast<TEveElement*>(fVizDB->GetValue(tag));
00717 }
00718 
00719 //______________________________________________________________________________
00720 void TEveManager::LoadVizDB(const TString& filename, Bool_t replace, Bool_t update)
00721 {
00722    // Load visualization-parameter database from file filename. The
00723    // replace, update arguments replace the values of fVizDBReplace
00724    // and fVizDBUpdate members for the duration of the macro
00725    // execution.
00726 
00727    Bool_t ex_replace = fVizDBReplace;
00728    Bool_t ex_update  = fVizDBUpdate;
00729    fVizDBReplace = replace;
00730    fVizDBUpdate  = update;
00731 
00732    LoadVizDB(filename);
00733 
00734    fVizDBReplace = ex_replace;
00735    fVizDBUpdate  = ex_update;
00736 }
00737 
00738 //______________________________________________________________________________
00739 void TEveManager::LoadVizDB(const TString& filename)
00740 {
00741    // Load visualization-parameter database from file filename.
00742    // State of data-members fVizDBReplace and fVizDBUpdate determine
00743    // how the registered entries are handled.
00744 
00745    TEveUtil::Macro(filename);
00746    Redraw3D();
00747 }
00748 
00749 //______________________________________________________________________________
00750 void TEveManager::SaveVizDB(const TString& filename)
00751 {
00752    // Save visualization-parameter database to file filename.
00753 
00754    TPMERegexp re("(.+)\\.\\w+");
00755    if (re.Match(filename) != 2) {
00756       Error("SaveVizDB", "filename does not match required format '(.+)\\.\\w+'.");
00757       return;
00758    }
00759 
00760    TString exp_filename(filename);
00761    gSystem->ExpandPathName(exp_filename);
00762 
00763    ofstream out(exp_filename, ios::out | ios::trunc);
00764    out << "void " << re[1] << "()\n";
00765    out << "{\n";
00766    out << "   TEveManager::Create();\n";
00767 
00768    ClearROOTClassSaved();
00769 
00770    Int_t       var_id = 0;
00771    TString     var_name;
00772    TIter       next(fVizDB);
00773    TObjString *key;
00774    while ((key = (TObjString*)next()))
00775    {
00776       TEveElement* mdl = dynamic_cast<TEveElement*>(fVizDB->GetValue(key));
00777       if (mdl)
00778       {
00779          var_name.Form("x%03d", var_id++);
00780          mdl->SaveVizParams(out, key->String(), var_name);
00781       }
00782       else
00783       {
00784          Warning("SaveVizDB", "Saving failed for key '%s'.", key->String().Data());
00785       }
00786    }
00787 
00788    out << "}\n";
00789    out.close();
00790 }
00791 
00792 //==============================================================================
00793 // GeoManager, geometry-alias registration
00794 //==============================================================================
00795 
00796 //______________________________________________________________________________
00797 TGeoManager* TEveManager::GetGeometry(const TString& filename)
00798 {
00799    // Get geometry with given filename.
00800    // This is cached internally so the second time this function is
00801    // called with the same argument the same geo-manager is returned.
00802    // gGeoManager is set to the return value.
00803 
00804    static const TEveException eh("TEveManager::GetGeometry ");
00805 
00806    TString exp_filename = filename;
00807    gSystem->ExpandPathName(exp_filename);
00808    printf("%s loading: '%s' -> '%s'.\n", eh.Data(),
00809           filename.Data(), exp_filename.Data());
00810 
00811    gGeoManager = (TGeoManager*) fGeometries->GetValue(filename);
00812    if (gGeoManager)
00813    {
00814       gGeoIdentity = (TGeoIdentity*) gGeoManager->GetListOfMatrices()->At(0);
00815    }
00816    else
00817    {
00818       Bool_t locked = TGeoManager::IsLocked();
00819       if (locked) {
00820          Warning(eh, "TGeoManager is locked ... unlocking it.");
00821          TGeoManager::UnlockGeometry();
00822       }
00823       if (TGeoManager::Import(filename) == 0) {
00824          throw(eh + "TGeoManager::Import() failed for '" + exp_filename + "'.");
00825       }
00826       if (locked) {
00827          TGeoManager::LockGeometry();
00828       }
00829 
00830       gGeoManager->GetTopVolume()->VisibleDaughters(1);
00831 
00832       // Import colors exported by Gled, if they exist.
00833       {
00834          TFile f(exp_filename, "READ");
00835          TObjArray* collist = (TObjArray*) f.Get("ColorList");
00836          f.Close();
00837          if (collist != 0) {
00838             TIter next(gGeoManager->GetListOfVolumes());
00839             TGeoVolume* vol;
00840             while ((vol = (TGeoVolume*) next()) != 0)
00841             {
00842                Int_t oldID = vol->GetLineColor();
00843                TColor* col = (TColor*)collist->At(oldID);
00844                Float_t r, g, b;
00845                col->GetRGB(r, g, b);
00846                Int_t  newID = TColor::GetColor(r,g,b);
00847                vol->SetLineColor(newID);
00848             }
00849          }
00850       }
00851 
00852       fGeometries->Add(new TObjString(filename), gGeoManager);
00853    }
00854    return gGeoManager;
00855 }
00856 
00857 //______________________________________________________________________________
00858 TGeoManager* TEveManager::GetGeometryByAlias(const TString& alias)
00859 {
00860    // Get geometry with given alias.
00861    // The alias must be registered via RegisterGeometryAlias().
00862 
00863    static const TEveException eh("TEveManager::GetGeometry ");
00864 
00865    TObjString* full_name = (TObjString*) fGeometryAliases->GetValue(alias);
00866    if (!full_name)
00867       throw(eh + "geometry alias '" + alias + "' not registered.");
00868    return GetGeometry(full_name->String());
00869 }
00870 
00871 //______________________________________________________________________________
00872 TGeoManager* TEveManager::GetDefaultGeometry()
00873 {
00874    // Get the default geometry.
00875    // It should be registered via RegisterGeometryName("Default", <URL>).
00876 
00877    return GetGeometryByAlias("Default");
00878 }
00879 
00880 //______________________________________________________________________________
00881 void TEveManager::RegisterGeometryAlias(const TString& alias, const TString& filename)
00882 {
00883    // Register 'name' as an alias for geometry file 'filename'.
00884    // The old aliases are silently overwritten.
00885    // After that the geometry can be retrieved also by calling:
00886    //   gEve->GetGeometryByName(name);
00887 
00888    fGeometryAliases->Add(new TObjString(alias), new TObjString(filename));
00889 }
00890 
00891 //==============================================================================
00892 
00893 //______________________________________________________________________________
00894 void TEveManager::SetStatusLine(const char* text)
00895 {
00896    // Set the text in the right side of browser's status bar.
00897 
00898    fBrowser->SetStatusText(text, 1);
00899 }
00900 
00901 //______________________________________________________________________________
00902 void TEveManager::ClearROOTClassSaved()
00903 {
00904    // Work-around uber ugly hack used in SavePrimitive and co.
00905 
00906    TIter   nextcl(gROOT->GetListOfClasses());
00907    TClass *cls;
00908    while((cls = (TClass *)nextcl()))
00909    {
00910       cls->ResetBit(TClass::kClassSaved);
00911    }
00912 }
00913 
00914 //______________________________________________________________________________
00915 void TEveManager::CloseEveWindow()
00916 {
00917    // Close button haas been clicked on EVE main window (browser).
00918    // Cleanup and terminate application.
00919 
00920    TGMainFrame *mf = (TGMainFrame*) gTQSender;
00921    TEveBrowser *eb = dynamic_cast<TEveBrowser*>(mf);
00922    if (eb == fBrowser)
00923    {
00924       mf->DontCallClose();
00925       Terminate();
00926       gApplication->Terminate();
00927    }
00928 }
00929 
00930 
00931 /******************************************************************************/
00932 // Static initialization.
00933 /******************************************************************************/
00934 
00935 //______________________________________________________________________________
00936 TEveManager* TEveManager::Create(Bool_t map_window, Option_t* opt)
00937 {
00938    // If global TEveManager* gEve is not set initialize it.
00939    // Returns gEve.
00940 
00941    static const TEveException eh("TEveManager::Create ");
00942 
00943    if (gEve == 0)
00944    {
00945       // Make sure that the GUI system is initialized.
00946       if (gROOT->IsBatch())
00947       {
00948          throw eh + "ROOT is running in batch mode.";
00949       }
00950       TApplication::NeedGraphicsLibs();
00951       gApplication->InitializeGraphics();
00952       if (gROOT->IsBatch() || gClient == 0 || gClient->IsZombie())
00953       {
00954          throw eh + "window system not initialized.";
00955       }
00956 
00957       Int_t w = 1024;
00958       Int_t h =  768;
00959 
00960       TEveUtil::SetupEnvironment();
00961       TEveUtil::SetupGUI();
00962       gEve = new TEveManager(w, h, map_window, opt);
00963    }
00964    return gEve;
00965 }
00966 
00967 //______________________________________________________________________________
00968 void TEveManager::Terminate()
00969 {
00970    // Properly terminate global TEveManager.
00971 
00972    if (!gEve) return;
00973 
00974    TEveGedEditor::DestroyEditors();
00975 
00976    delete gEve;
00977    gEve = 0;
00978 }
00979 
00980 //==============================================================================
00981 //==============================================================================
00982 // TEveManager::TExceptionHandler
00983 //==============================================================================
00984 
00985 //______________________________________________________________________________
00986 //
00987 // Exception handler for Eve exceptions.
00988 
00989 ClassImp(TEveManager::TExceptionHandler);
00990 
00991 //______________________________________________________________________________
00992 TStdExceptionHandler::EStatus
00993 TEveManager::TExceptionHandler::Handle(std::exception& exc)
00994 {
00995    // Handle exceptions deriving from TEveException.
00996 
00997    TEveException* ex = dynamic_cast<TEveException*>(&exc);
00998    if (ex) {
00999       Info("Handle", "%s", ex->Data());
01000       gEve->SetStatusLine(ex->Data());
01001       gSystem->Beep();
01002       return kSEHandled;
01003    } else {
01004       return kSEProceed;
01005    }
01006 }

Generated on Tue Jul 5 14:16:12 2011 for ROOT_528-00b_version by  doxygen 1.5.1