CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/Fireworks/Core/src/FWGUIManager.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWGUIManager
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Mon Feb 11 11:06:40 EST 2008
00011 // $Id: FWGUIManager.cc,v 1.236 2011/03/22 18:10:19 amraktad Exp $
00012 
00013 
00014 //
00015 
00016 // system include files
00017 #include <boost/bind.hpp>
00018 #include <stdexcept>
00019 #include <iostream>
00020 #include <cstdio>
00021 #include <sstream>
00022 
00023 #include "TGButton.h"
00024 #include "TGLabel.h"
00025 #include "TSystem.h"
00026 #include "TGLViewer.h"
00027 #include "TEveBrowser.h"
00028 #include "TEveManager.h"
00029 #include "TGPack.h"
00030 #include "TEveWindow.h"
00031 #include "TEveViewer.h"
00032 #include "TEveWindowManager.h"
00033 #include "TEveSelection.h"
00034 #include "TVirtualX.h"
00035 #include "TFile.h"
00036 
00037 // user include files
00038 #include "Fireworks/Core/interface/FWGUIManager.h"
00039 #include "Fireworks/Core/interface/Context.h"
00040 #include "Fireworks/Core/interface/FWGUISubviewArea.h"
00041 
00042 #include "Fireworks/Core/interface/FWSelectionManager.h"
00043 #include "Fireworks/Core/interface/FWEventItemsManager.h"
00044 #include "Fireworks/Core/interface/FWSummaryManager.h"
00045 #include "Fireworks/Core/interface/FWColorManager.h"
00046 #include "Fireworks/Core/interface/FWDetailViewManager.h"
00047 #include "Fireworks/Core/interface/FWViewBase.h"
00048 #include "Fireworks/Core/interface/FWViewType.h"
00049 #include "Fireworks/Core/interface/FWViewManagerManager.h"
00050 #include "Fireworks/Core/interface/FWJobMetadataManager.h"
00051 #include "Fireworks/Core/interface/FWInvMassDialog.h"
00052 #include "Fireworks/Core/interface/FWGeometryBrowser.h"
00053 
00054 #include "Fireworks/Core/interface/FWConfiguration.h"
00055 
00056 #include "Fireworks/Core/interface/CmsShowMainFrame.h"
00057 #include "Fireworks/Core/interface/FWNavigatorBase.h"
00058 
00059 #include "Fireworks/Core/src/FWGUIEventDataAdder.h"
00060 #include "Fireworks/Core/src/FWNumberEntry.h"
00061 
00062 #include "Fireworks/Core/interface/CSGAction.h"
00063 
00064 #include "Fireworks/Core/interface/ActionsList.h"
00065 
00066 #include "Fireworks/Core/interface/CmsShowEDI.h"
00067 #include "Fireworks/Core/interface/CmsShowCommonPopup.h"
00068 #include "Fireworks/Core/interface/CmsShowModelPopup.h"
00069 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
00070 
00071 #include "Fireworks/Core/interface/CmsShowHelpPopup.h"
00072 
00073 #include "Fireworks/Core/src/CmsShowTaskExecutor.h"
00074 
00075 #include "Fireworks/Core/interface/FWTypeToRepresentations.h"
00076 #include "Fireworks/Core/interface/FWIntValueListener.h"
00077 #include "Fireworks/Core/interface/FWCustomIconsButton.h"
00078 
00079 #include "Fireworks/Core/src/FWModelContextMenuHandler.h"
00080 
00081 #include "Fireworks/Core/interface/fwLog.h"
00082 
00083 #include "FWCore/Common/interface/EventBase.h"
00084 
00085 
00086 // constants, enums and typedefs
00087 //
00088 //
00089 // static data member definitions
00090 //
00091 FWGUIManager* FWGUIManager::m_guiManager = 0;
00092 
00093 //
00094 // constructors and destructor
00095 //
00096 FWGUIManager::FWGUIManager(fireworks::Context* ctx,
00097                            const FWViewManagerManager* iVMMgr,
00098                            FWNavigatorBase* navigator):
00099    m_context(ctx),
00100    m_summaryManager(0),
00101    m_detailViewManager(0),
00102    m_viewManagerManager(iVMMgr),
00103    m_contextMenuHandler(0),
00104    m_navigator(navigator),
00105    m_dataAdder(0),
00106    m_ediFrame(0),
00107    m_modelPopup(0),
00108    m_viewPopup(0),
00109    m_commonPopup(0),
00110    m_invMassDialog(0),
00111    m_geoBrowser(0),
00112    m_helpPopup(0),
00113    m_shortcutPopup(0),
00114    m_helpGLPopup(0),
00115    m_tasks(new CmsShowTaskExecutor),
00116    m_WMOffsetX(0), m_WMOffsetY(0), m_WMDecorH(0)
00117 {
00118    m_guiManager = this;
00119 
00120    measureWMOffsets();
00121 
00122    FWEventItemsManager* im = (FWEventItemsManager*) m_context->eventItemsManager();
00123    im->newItem_.connect(boost::bind(&FWGUIManager::newItem, this, _1) );
00124 
00125    m_context->colorManager()->colorsHaveChangedFinished_.connect(boost::bind(&FWGUIManager::finishUpColorChange,this));
00126 
00127   
00128    TEveCompositeFrame::IconBarCreator_foo foo =  &FWGUIManager::makeGUIsubview;
00129    TEveCompositeFrame::SetupFrameMarkup(foo, 20, 4, false);
00130 
00131    {
00132       //NOTE: by making sure we defaultly open to a fraction of the full screen size we avoid
00133       // causing the program to go into full screen mode under default SL4 window manager
00134       UInt_t width = gClient->GetDisplayWidth();
00135       UInt_t height = static_cast<UInt_t>(gClient->GetDisplayHeight()*.8);
00136       //try to deal with multiple horizontally placed monitors.  Since present monitors usually
00137       // have less than 2000 pixels horizontally, when we see more it is a good indicator that
00138       // we are dealing with more than one monitor.
00139       while(width > 2000) {
00140          width /= 2;
00141       }
00142       width = static_cast<UInt_t>(width*.8);
00143       m_cmsShowMainFrame = new CmsShowMainFrame(gClient->GetRoot(),
00144                                                 width,
00145                                                 height,
00146                                                 this);
00147       m_cmsShowMainFrame->SetWindowName("CmsShow");
00148       m_cmsShowMainFrame->SetCleanup(kDeepCleanup);
00149       for (int i = 0 ; i < FWViewType::kTypeSize; ++i)
00150       {
00151          bool separator = (i == FWViewType::kGlimpse || i == FWViewType::kTableHLT);
00152          CSGAction* action = m_cmsShowMainFrame->createNewViewerAction(FWViewType::idToName(i), separator);
00153          action->activated.connect(boost::bind(&FWGUIManager::newViewSlot, this, FWViewType::idToName(i)));
00154       }
00155 
00156       m_detailViewManager  = new FWDetailViewManager(m_context->colorManager());
00157       m_contextMenuHandler = new FWModelContextMenuHandler(m_context->selectionManager(), m_detailViewManager, m_context->colorManager(), this);
00158 
00159       m_geoBrowser = new FWGeometryBrowser(getGUIManager());
00160       m_cmsShowMainFrame->bindCSGActionKeys(m_geoBrowser);
00161 
00162       getAction(cmsshow::sExportImage)->activated.connect(sigc::mem_fun(*this, &FWGUIManager::exportImageOfMainView));
00163       getAction(cmsshow::sExportAllImages)->activated.connect(sigc::mem_fun(*this, &FWGUIManager::exportImagesOfAllViews));
00164       getAction(cmsshow::sLoadConfig)->activated.connect(sigc::mem_fun(*this, &FWGUIManager::promptForLoadConfigurationFile));
00165       getAction(cmsshow::sSaveConfig)->activated.connect(writeToPresentConfigurationFile_);
00166       getAction(cmsshow::sSaveConfigAs)->activated.connect(sigc::mem_fun(*this,&FWGUIManager::promptForSaveConfigurationFile));
00167       getAction(cmsshow::sShowEventDisplayInsp)->activated.connect(boost::bind( &FWGUIManager::showEDIFrame,this,-1));
00168       getAction(cmsshow::sShowMainViewCtl)->activated.connect(sigc::mem_fun(*m_guiManager, &FWGUIManager::showViewPopup));
00169       getAction(cmsshow::sShowObjInsp)->activated.connect(sigc::mem_fun(*m_guiManager, &FWGUIManager::showModelPopup));
00170 
00171       getAction(cmsshow::sBackgroundColor)->activated.connect(sigc::mem_fun(m_context->colorManager(), &FWColorManager::switchBackground));
00172       getAction(cmsshow::sShowCommonInsp)->activated.connect(sigc::mem_fun(*m_guiManager, &FWGUIManager::showCommonPopup));
00173 
00174       getAction(cmsshow::sShowInvMassDialog)->activated.connect(sigc::mem_fun(*m_guiManager, &FWGUIManager::showInvMassDialog));
00175       getAction(cmsshow::sShowGeometryTable)->activated.connect(sigc::mem_fun(*m_guiManager, &FWGUIManager::showGeometryBrowser));
00176 
00177       getAction(cmsshow::sShowAddCollection)->activated.connect(sigc::mem_fun(*m_guiManager, &FWGUIManager::addData));
00178       assert(getAction(cmsshow::sHelp) != 0);
00179       getAction(cmsshow::sHelp)->activated.connect(sigc::mem_fun(*m_guiManager, &FWGUIManager::createHelpPopup));
00180       assert(getAction(cmsshow::sKeyboardShort) != 0);
00181       getAction(cmsshow::sKeyboardShort)->activated.connect(sigc::mem_fun(*m_guiManager, &FWGUIManager::createShortcutPopup));
00182       getAction(cmsshow::sHelpGL)->activated.connect(sigc::mem_fun(*m_guiManager, &FWGUIManager::createHelpGLPopup));
00183 
00184       // toolbar special widget with non-void actions
00185       m_cmsShowMainFrame->m_delaySliderListener->valueChanged_.connect(boost::bind(&FWGUIManager::delaySliderChanged,this,_1));
00186 
00187       TQObject::Connect(m_cmsShowMainFrame->m_runEntry,   "ReturnPressed()", "FWGUIManager", this, "runIdChanged()");
00188       TQObject::Connect(m_cmsShowMainFrame->m_lumiEntry,  "ReturnPressed()", "FWGUIManager", this, "lumiIdChanged()");
00189       TQObject::Connect(m_cmsShowMainFrame->m_eventEntry, "ReturnPressed()", "FWGUIManager", this, "eventIdChanged()");
00190 
00191       TQObject::Connect(m_cmsShowMainFrame->m_filterShowGUIBtn, "Clicked()", "FWGUIManager", this, "showEventFilterGUI()");
00192       TQObject::Connect(m_cmsShowMainFrame->m_filterEnableBtn,  "Clicked()", "FWGUIManager", this, "filterButtonClicked()"); 
00193 
00194       TQObject::Connect(gEve->GetWindowManager(), "WindowSelected(TEveWindow*)", "FWGUIManager", this, "checkSubviewAreaIconState(TEveWindow*)");
00195       TQObject::Connect(gEve->GetWindowManager(), "WindowDocked(TEveWindow*)"  , "FWGUIManager", this, "checkSubviewAreaIconState(TEveWindow*)");
00196       TQObject::Connect(gEve->GetWindowManager(), "WindowUndocked(TEveWindow*)", "FWGUIManager", this, "checkSubviewAreaIconState(TEveWindow*)");
00197    }
00198 }
00199 
00200 void FWGUIManager::connectSubviewAreaSignals(FWGUISubviewArea* a)
00201 {
00202    a->goingToBeDestroyed_.connect(boost::bind(&FWGUIManager::subviewIsBeingDestroyed, this, _1));
00203    a->selected_.connect(boost::bind(&FWGUIManager::subviewInfoSelected, this, _1));
00204    a->unselected_.connect(boost::bind(&FWGUIManager::subviewInfoUnselected, this, _1));
00205    a->swap_.connect(boost::bind(&FWGUIManager::subviewSwapped, this, _1));
00206 }
00207 
00208 //
00209 // Destructor
00210 //
00211 FWGUIManager::~FWGUIManager()
00212 {
00213    delete m_invMassDialog;
00214    delete m_summaryManager;
00215    delete m_detailViewManager;
00216    delete m_cmsShowMainFrame;
00217    delete m_viewPopup;
00218    delete m_ediFrame;
00219    delete m_contextMenuHandler;
00220 
00221 }
00222 
00223 void
00224 FWGUIManager::evePreTerminate()
00225 {
00226    gEve->GetWindowManager()->Disconnect("WindowSelected(TEveWindow*)", this, "checkSubviewAreaIconState(TEveWindow*)");
00227    gEve->GetWindowManager()->Disconnect("WindowDocked(TEveWindow*)", this, "checkSubviewAreaIconState(TEveWindow*)");
00228    gEve->GetWindowManager()->Disconnect("WindowUndocked(TEveWindow*)", this, "checkSubviewAreaIconState(TEveWindow*)");
00229 
00230    // avoid emit signals at end
00231    gEve->GetSelection()->Disconnect();
00232    gEve->GetHighlight()->Disconnect();
00233    gEve->GetSelection()->RemoveElements();
00234    gEve->GetHighlight()->RemoveElements();
00235     
00236    m_cmsShowMainFrame->UnmapWindow();
00237    for(ViewMap_i wIt = m_viewMap.begin(); wIt != m_viewMap.end(); ++wIt)
00238    {
00239      TEveCompositeFrameInMainFrame* mainFrame = dynamic_cast<TEveCompositeFrameInMainFrame*>((*wIt).first->GetEveFrame());
00240      //  main frames not to watch dying
00241       if (mainFrame) mainFrame->UnmapWindow();
00242      // destroy
00243       (*wIt).second->destroy();
00244    }
00245 }
00246 
00247 //______________________________________________________________________________
00248 // subviews construction
00249 //
00250 
00251 TGFrame*
00252 FWGUIManager::makeGUIsubview(TEveCompositeFrame* cp, TGCompositeFrame* parent, Int_t height)
00253 {
00254    TGFrame* frame = new FWGUISubviewArea(cp, parent, height);
00255    return frame;
00256 }
00257 
00258 void
00259 FWGUIManager::registerViewBuilder(const std::string& iName,
00260                                   ViewBuildFunctor& iBuilder)
00261 {
00262    m_nameToViewBuilder[iName]=iBuilder;
00263 }
00264 
00265 
00266 void
00267 FWGUIManager::newViewSlot(const std::string& iName)
00268 {
00269    // this function have to exist, becuse CSGAction binds to void functions 
00270    createView(iName);
00271 }
00272 
00273 FWGUIManager::ViewMap_i
00274 FWGUIManager::createView(const std::string& iName, TEveWindowSlot* slot)
00275 {
00276    NameToViewBuilder::iterator itFind = m_nameToViewBuilder.find(iName);
00277    assert (itFind != m_nameToViewBuilder.end());
00278    if(itFind == m_nameToViewBuilder.end()) {
00279       throw std::runtime_error(std::string("Unable to create view named ")+iName+" because it is unknown");
00280    }
00281    
00282    if (!slot)
00283    {
00284       if (m_viewSecPack)
00285       {
00286          slot = m_viewSecPack->NewSlot();
00287       }
00288       else
00289       {
00290          slot = m_viewPrimPack->NewSlot();
00291          m_viewSecPack = m_viewPrimPack->NewSlot()->MakePack();
00292          m_viewSecPack->SetShowTitleBar(kFALSE);
00293       }
00294    }
00295    TEveCompositeFrame *ef = slot->GetEveFrame();
00296    FWViewBase* viewBase = itFind->second(slot, iName);
00297    //in future, get context from 'view'
00298    FWViewContextMenuHandlerBase* base= viewBase->contextMenuHandler();
00299    viewBase->openSelectedModelContextMenu_.connect(boost::bind(&FWGUIManager::showSelectedModelContextMenu ,m_guiManager,_1,_2,base));
00300    
00301    TEveWindow *eveWindow = ef->GetEveWindow();
00302    eveWindow->SetElementName(iName.c_str());
00303 
00304    std::pair<ViewMap_i,bool> insertPair = m_viewMap.insert(std::make_pair(eveWindow, viewBase));
00305    return insertPair.first;
00306 }
00307 
00308 
00309 //
00310 // actions
00311 //
00312 
00313 void
00314 FWGUIManager::enableActions(bool enable)
00315 {
00316    m_cmsShowMainFrame->enableActions(enable);
00317 }
00318 
00319 void
00320 FWGUIManager::titleChanged(const char *subtitle)
00321 {
00322    char title[128];
00323    snprintf(title,127,"cmsShow: %s", subtitle);
00324    m_cmsShowMainFrame->SetWindowName(title);
00325 }
00326 
00327 void
00328 FWGUIManager::eventChangedCallback() {
00329    // To be replaced when we can get index from fwlite::Event
00330    
00331    TEveViewerList* viewers = gEve->GetViewers();
00332    for (TEveElement::List_i i=viewers->BeginChildren(); i!= viewers->EndChildren(); ++i)
00333    {
00334       TEveViewer* ev = dynamic_cast<TEveViewer*>(*i);
00335       if (ev)
00336          ev->GetGLViewer()->DeleteOverlayAnnotations();
00337    }
00338    
00339    m_cmsShowMainFrame->loadEvent(*getCurrentEvent());
00340    m_detailViewManager->newEventCallback();
00341 }
00342 
00343 CSGAction*
00344 FWGUIManager::getAction(const std::string name)
00345 {
00346    return m_cmsShowMainFrame->getAction(name);
00347 }
00348 
00349 CSGContinuousAction*
00350 FWGUIManager::playEventsAction()
00351 {
00352    return m_cmsShowMainFrame->playEventsAction();
00353 }
00354 
00355 CSGContinuousAction*
00356 FWGUIManager::playEventsBackwardsAction()
00357 {
00358    return m_cmsShowMainFrame->playEventsBackwardsAction();
00359 }
00360 
00361 CSGContinuousAction*
00362 FWGUIManager::loopAction()
00363 {
00364    return m_cmsShowMainFrame->loopAction();
00365 }
00366 
00367 void
00368 FWGUIManager::disablePrevious()
00369 {
00370    m_cmsShowMainFrame->enablePrevious(false);
00371 }
00372 
00373 void
00374 FWGUIManager::disableNext()
00375 {
00376    m_cmsShowMainFrame->enableNext(false);
00377 }
00378 
00379 void
00380 FWGUIManager::setPlayMode(bool play)
00381 {
00382    m_cmsShowMainFrame->m_runEntry->SetEnabled(!play);
00383    m_cmsShowMainFrame->m_eventEntry->SetEnabled(!play);
00384 }
00385 
00386 void
00387 FWGUIManager::updateStatus(const char* status) {
00388    m_cmsShowMainFrame->updateStatusBar(status);
00389 }
00390 
00391 void
00392 FWGUIManager::clearStatus()
00393 {
00394    m_cmsShowMainFrame->clearStatusBar();
00395 }
00396 
00397 void
00398 FWGUIManager::processGUIEvents()
00399 {
00400    gSystem->ProcessEvents();
00401 }
00402 
00403 void
00404 FWGUIManager::newItem(const FWEventItem* iItem)
00405 {
00406 #if defined(THIS_WILL_NEVER_BE_DEFINED)
00407    m_selectionItemsComboBox->AddEntry(iItem->name().c_str(),iItem->id());
00408    if(iItem->id()==0) {
00409       m_selectionItemsComboBox->Select(0);
00410    }
00411 #endif
00412 }
00413 
00414 void
00415 FWGUIManager::addData()
00416 {
00417    if (0==m_dataAdder) {
00418       m_dataAdder = new FWGUIEventDataAdder(100,100,
00419                                             (FWEventItemsManager*) m_context->eventItemsManager(),
00420                                             m_cmsShowMainFrame,
00421                                             m_context->metadataManager());
00422    }
00423    m_dataAdder->show();
00424 }
00425 
00426 
00427 //  subview actions
00428 //
00429 
00430 TEveWindow*
00431 FWGUIManager::getSwapCandidate()
00432 {
00433    TEveWindow* swapCandidate =0;
00434 
00435    if ( gEve->GetWindowManager()->GetCurrentWindow())
00436    {
00437       swapCandidate = gEve->GetWindowManager()->GetCurrentWindow();
00438    }
00439    else
00440    {
00441       // swap with first docked view
00442       TEveCompositeFrame* pef;
00443       TGFrameElementPack *pel;
00444 
00445       // check if there is view in prim pack
00446       TGPack* pp = m_viewPrimPack->GetPack();
00447       if ( pp->GetList()->GetSize() > 2)
00448       {
00449          pel = (TGFrameElementPack*) pp->GetList()->At(1);
00450          if (pel->fState) // is first undocked
00451          {
00452             pef = dynamic_cast<TEveCompositeFrame*>(pel->fFrame);
00453             if ( pef && pef->GetEveWindow())
00454                swapCandidate = pef->GetEveWindow();
00455          }
00456       }
00457       if (swapCandidate == 0)
00458       {
00459          // no eve window found in primary check secondary
00460          TGPack* sp = m_viewSecPack->GetPack();
00461          Int_t nf = sp->GetList()->GetSize();
00462          TIter frame_iterator(sp->GetList());
00463          for (Int_t i=0; i<nf; ++i) {
00464             pel = (TGFrameElementPack*)frame_iterator();
00465             pef = dynamic_cast<TEveCompositeFrame*>(pel->fFrame);
00466             if ( pef && pef->GetEveWindow())
00467             {
00468                swapCandidate =  pef->GetEveWindow() ;
00469                break;
00470             }
00471          }
00472       }
00473    }
00474 
00475    return swapCandidate;
00476 }
00477 
00478 void
00479 FWGUIManager::checkSubviewAreaIconState(TEveWindow* /*ew*/)
00480 {
00481    // First argumet is needed for signals/slot symetry
00482 
00483    // disable swap on the first left TEveCompositeFrame
00484    // check info button
00485    TEveWindow* current  = getSwapCandidate();
00486    bool checkInfoBtn    = m_viewPopup ? m_viewPopup->mapped() : 0;
00487    TEveWindow* selected = m_viewPopup ? m_viewPopup->getEveWindow() : 0;
00488 
00489    for (ViewMap_i it = m_viewMap.begin(); it != m_viewMap.end(); it++)
00490    {
00491       FWGUISubviewArea* ar = FWGUISubviewArea::getToolBarFromWindow(it->first);
00492       ar->setSwapIcon(current != it->first);
00493       if (checkInfoBtn && selected)
00494          ar->setInfoButton(selected == it->first);
00495    }
00496 }
00497 
00498 void
00499 FWGUIManager::subviewIsBeingDestroyed(FWGUISubviewArea* sva)
00500 {
00501    if(sva->isSelected()) {
00502       setViewPopup(0);
00503    }
00504 
00505    CmsShowTaskExecutor::TaskFunctor f;
00506    f = boost::bind(&FWGUIManager::subviewDestroy, this, sva);
00507    m_tasks->addTask(f);
00508    m_tasks->startDoingTasks();
00509 }
00510 
00511 void
00512 FWGUIManager::subviewDestroy(FWGUISubviewArea* sva)
00513 {  
00514    TEveWindow* ew       = sva->getEveWindow();
00515    FWViewBase* viewBase = m_viewMap[ew];
00516    m_viewMap.erase(ew);
00517    viewBase->destroy();
00518 }
00519 
00520 void
00521 FWGUIManager::subviewDestroyAll()
00522 {
00523    std::vector<FWGUISubviewArea*> sd;
00524    for(ViewMap_i wIt = m_viewMap.begin(); wIt != m_viewMap.end(); ++wIt)
00525    {
00526       FWGUISubviewArea* ar = FWGUISubviewArea::getToolBarFromWindow(wIt->first);
00527       sd.push_back(ar);
00528    }
00529 
00530    for (std::vector<FWGUISubviewArea*>::iterator i= sd.begin(); i !=sd.end(); ++i)
00531    {
00532       if((*i)->isSelected())
00533          setViewPopup(0);
00534       subviewDestroy(*i);
00535    }
00536 
00537    gSystem->ProcessEvents();
00538    gSystem->Sleep(200);
00539 
00540 
00541    
00542    while (m_viewPrimPack->HasChildren())
00543    {
00544       TEveWindow* w = dynamic_cast<TEveWindow*>(m_viewPrimPack->FirstChild());
00545       if (w) w->DestroyWindowAndSlot();
00546    }
00547 
00548    gSystem->Sleep(200);
00549    m_viewSecPack = 0;
00550    gSystem->ProcessEvents();
00551 
00552 }
00553 
00554 void
00555 FWGUIManager::subviewInfoSelected(FWGUISubviewArea* sva)
00556 {
00557    // release button on previously selected
00558    TEveWindow* ew = sva->getEveWindow();
00559    for(ViewMap_i wIt = m_viewMap.begin(); wIt != m_viewMap.end(); ++wIt)
00560    {
00561       if (wIt->first != ew)
00562          FWGUISubviewArea::getToolBarFromWindow(wIt->first)->setInfoButton(kFALSE);
00563    }
00564    setViewPopup(sva->getEveWindow());
00565 }
00566 
00567 void
00568 FWGUIManager::subviewInfoUnselected(FWGUISubviewArea* sva)
00569 {
00570    m_viewPopup->UnmapWindow();
00571 }
00572 
00573 void
00574 FWGUIManager::subviewSwapped(FWGUISubviewArea* sva)
00575 {
00576    TEveWindow* curr = getSwapCandidate();
00577    TEveWindow* swap = sva->getEveWindow();
00578    if (curr) swap->SwapWindow(curr);
00579 
00580    checkSubviewAreaIconState(0);
00581 }
00582 
00583 TGVerticalFrame*
00584 FWGUIManager::createList(TGCompositeFrame *p)
00585 {
00586    TGVerticalFrame *listFrame = new TGVerticalFrame(p, p->GetWidth(), p->GetHeight());
00587 
00588    TGHorizontalFrame* addFrame = new TGHorizontalFrame(listFrame, p->GetWidth(), 10, kRaisedFrame);
00589    TGLabel* addLabel = new TGLabel(addFrame,"Summary View");
00590    addFrame->AddFrame(addLabel, new TGLayoutHints(kLHintsCenterX, 0,0,2,2));
00591    listFrame->AddFrame(addFrame, new TGLayoutHints(kLHintsExpandX | kLHintsTop));
00592 
00593    m_summaryManager = new FWSummaryManager(listFrame,
00594                                            m_context->selectionManager(),
00595                                            (FWEventItemsManager*) m_context->eventItemsManager(),
00596                                            this,
00597                                            m_context->modelChangeManager(),
00598                                            m_context->colorManager());
00599 
00600    const unsigned int backgroundColor=0x2f2f2f;
00601    TGTextButton* addDataButton = new TGTextButton(m_summaryManager->widget(), "Add Collection");
00602    addDataButton->ChangeOptions(kRaisedFrame);
00603    addDataButton->SetBackgroundColor(backgroundColor);
00604    addDataButton->SetTextColor(0xFFFFFF);
00605    addDataButton->SetToolTipText("Show additional collections");
00606    addDataButton->Connect("Clicked()", "FWGUIManager", this, "addData()");
00607    m_summaryManager->widget()->AddFrame(addDataButton, new TGLayoutHints(kLHintsExpandX|kLHintsLeft|kLHintsTop));
00608    listFrame->AddFrame(m_summaryManager->widget(), new TGLayoutHints(kLHintsExpandX|kLHintsExpandY));
00609 
00610    return listFrame;
00611 }
00612 
00613 void
00614 FWGUIManager::createViews(TEveWindowSlot *slot)
00615 {
00616    m_viewPrimPack = slot->MakePack();
00617    m_viewPrimPack->SetHorizontal();
00618    m_viewPrimPack->SetElementName("Views");
00619    m_viewPrimPack->SetShowTitleBar(kFALSE);
00620    m_viewSecPack = 0;
00621 }
00622 
00623 void
00624 FWGUIManager::createEDIFrame() {
00625    if (m_ediFrame == 0) {
00626       m_ediFrame = new CmsShowEDI(m_cmsShowMainFrame, 200, 200, m_context->selectionManager(),m_context->colorManager());
00627       m_ediFrame->CenterOnParent(kTRUE,TGTransientFrame::kTopRight);
00628       m_cmsShowMainFrame->bindCSGActionKeys(m_ediFrame);
00629    }
00630 }
00631 
00632 void
00633 FWGUIManager::showEDIFrame(int iToShow)
00634 {
00635    createEDIFrame();
00636    if(-1 != iToShow) {
00637       m_ediFrame->show(static_cast<FWDataCategories> (iToShow));
00638    }
00639    m_ediFrame->MapRaised();
00640 }
00641 
00642 void
00643 FWGUIManager::showCommonPopup()
00644 {
00645    if (! m_commonPopup)
00646    {
00647       m_commonPopup = new CmsShowCommonPopup(m_context->commonPrefs(), m_cmsShowMainFrame, 200, 200);
00648       m_cmsShowMainFrame->bindCSGActionKeys(m_commonPopup);
00649    }
00650    m_commonPopup->MapRaised();
00651 }
00652 
00653 void
00654 FWGUIManager::createModelPopup()
00655 {
00656    m_modelPopup = new CmsShowModelPopup(m_detailViewManager,m_context->selectionManager(), m_context->colorManager(), m_cmsShowMainFrame, 200, 200);
00657    m_modelPopup->CenterOnParent(kTRUE,TGTransientFrame::kRight);
00658    m_cmsShowMainFrame->bindCSGActionKeys(m_modelPopup);
00659 }
00660 
00661 void
00662 FWGUIManager::showModelPopup()
00663 {
00664    if (!m_modelPopup) createModelPopup();
00665    m_modelPopup->MapRaised();
00666 }
00667 
00668 void
00669 FWGUIManager::popupViewClosed()
00670 {
00671    if (m_viewPopup->getEveWindow())
00672    {
00673       FWGUISubviewArea* sa = FWGUISubviewArea::getToolBarFromWindow(m_viewPopup->getEveWindow());
00674       sa->setInfoButton(kFALSE);
00675    }
00676 }
00677 
00678 void
00679 FWGUIManager::showViewPopup() {
00680    // CSG action .
00681    setViewPopup(0);
00682 }
00683 
00684 void
00685 FWGUIManager::setViewPopup(TEveWindow* ew) {
00686    FWViewBase* vb = ew ? m_viewMap[ew] : 0;
00687    if (m_viewPopup == 0)
00688    {
00689       m_viewPopup = new CmsShowViewPopup(0, 200, 200, m_context->colorManager(), vb, ew);
00690       m_viewPopup->closed_.connect(sigc::mem_fun(*m_guiManager, &FWGUIManager::popupViewClosed));
00691    }
00692    else
00693    {
00694       m_viewPopup->UnmapWindow();
00695    }
00696    m_viewPopup->reset(vb, ew);
00697    m_viewPopup->MapRaised();
00698 }
00699 
00700 void
00701 FWGUIManager::showInvMassDialog()
00702 {
00703    if (! m_invMassDialog)
00704    {
00705       m_invMassDialog = new FWInvMassDialog(m_context->selectionManager());
00706       m_cmsShowMainFrame->bindCSGActionKeys(m_invMassDialog);
00707    }
00708    m_invMassDialog->MapRaised();
00709 }
00710 
00711 void
00712 FWGUIManager::showGeometryBrowser()
00713 {
00714   m_geoBrowser->browse();
00715    m_geoBrowser->MapRaised();
00716 }
00717 
00718 void
00719 FWGUIManager::createHelpPopup ()
00720 {
00721    if (m_helpPopup == 0) {
00722       m_helpPopup = new CmsShowHelpPopup("help.html", "CmsShow Help",
00723                                          m_cmsShowMainFrame,
00724                                          800, 600);
00725       m_helpPopup->CenterOnParent(kTRUE,TGTransientFrame::kBottomRight);
00726    }
00727    m_helpPopup->MapWindow();
00728 }
00729 
00730 
00731 void
00732 FWGUIManager::createShortcutPopup ()
00733 {
00734    if (m_shortcutPopup == 0) {
00735       m_shortcutPopup = new CmsShowHelpPopup("shortcuts.html",
00736                                              getAction(cmsshow::sKeyboardShort)->getName().c_str(),
00737                                               m_cmsShowMainFrame, 800, 600);
00738 
00739       m_shortcutPopup->CenterOnParent(kTRUE,TGTransientFrame::kBottomRight);
00740    }
00741    m_shortcutPopup->MapWindow();
00742 }
00743 
00744 void FWGUIManager::createHelpGLPopup ()
00745 {
00746    if (m_helpGLPopup == 0) {
00747       m_helpGLPopup = new CmsShowHelpPopup("helpGL.html",
00748                                             getAction(cmsshow::sHelpGL)->getName().c_str(),
00749                                             m_cmsShowMainFrame, 800, 600);
00750 
00751       m_helpGLPopup->CenterOnParent(kTRUE,TGTransientFrame::kBottomRight);
00752    }
00753    m_helpGLPopup->MapWindow();
00754 }
00755 
00756 void 
00757 FWGUIManager::showSelectedModelContextMenu(Int_t iGlobalX, Int_t iGlobalY, FWViewContextMenuHandlerBase* iHandler)
00758 {
00759    if(!m_context->selectionManager()->selected().empty()) {
00760       m_contextMenuHandler->showSelectedModelContext(iGlobalX,iGlobalY, iHandler);
00761    }
00762 }
00763 
00764  //
00765 // const member functions
00766 //
00767 
00768 FWGUIManager*
00769 FWGUIManager::getGUIManager()
00770 {
00771    return m_guiManager;
00772 }
00773 
00774 const edm::EventBase*
00775 FWGUIManager::getCurrentEvent() const
00776 {
00777    return m_navigator->getCurrentEvent();  
00778 }
00779 
00788 bool
00789 FWGUIManager::promptForConfigurationFile(std::string &result, enum EFileDialogMode mode)
00790 {
00791    static const char* kFileTypes[] = {"Fireworks Configuration files","*.fwc",
00792                                        "All Files","*",
00793                                        0,0};
00794 
00795    static TString dir(".");
00796 
00797    TGFileInfo fi;
00798    fi.fFileTypes = kFileTypes;
00799    fi.fIniDir    = StrDup(dir);
00800    new TGFileDialog(gClient->GetDefaultRoot(), m_cmsShowMainFrame, mode, &fi);
00801    dir = fi.fIniDir;
00802    if (fi.fFilename == 0) // to handle "cancel" button properly
00803       return false;
00804    std::string name = fi.fFilename;
00805    // if the extension isn't already specified by hand, specify it now
00806    std::string ext = kFileTypes[fi.fFileTypeIdx + 1] + 1;
00807    if (ext.size() != 0 && name.find(ext) == name.npos)
00808       name += ext;
00809    result = name;
00810    return true;
00811 }
00812 
00813 
00817 void
00818 FWGUIManager::promptForLoadConfigurationFile()
00819 {
00820    std::string name;
00821    if (!promptForConfigurationFile(name, kFDOpen))
00822       return;
00823   
00824    
00825    loadFromConfigurationFile_(name);
00826 }
00827 
00831 void
00832 FWGUIManager::promptForSaveConfigurationFile()
00833 {
00834    std::string name;
00835    if (!promptForConfigurationFile(name, kFDSave))
00836       return;
00837    writeToConfigurationFile_(name);
00838 }
00839 
00840 void
00841 FWGUIManager::exportImageOfMainView()
00842 {
00843    TGFrameElementPack* frameEL = (TGFrameElementPack*) m_viewPrimPack->GetPack()->GetList()->At(1);
00844    TEveCompositeFrame* ef = dynamic_cast<TEveCompositeFrame*>(frameEL->fFrame);
00845    m_viewMap[ef->GetEveWindow()]->promptForSaveImageTo(m_cmsShowMainFrame);
00846 }
00847 
00848 void
00849 FWGUIManager::exportImagesOfAllViews()
00850 {
00851    try {
00852       static TString dir(".");
00853       const char *  kImageExportTypes[] = {"PNG",                     "*.png",
00854                                            "GIF",                     "*.gif",
00855                                            "JPEG",                    "*.jpg",
00856                                            "PDF",                     "*.pdf",
00857                                            "Encapsulated PostScript", "*.eps",
00858                                            0, 0};
00859 
00860       TGFileInfo fi;
00861       fi.fFileTypes = kImageExportTypes;
00862       fi.fIniDir    = StrDup(dir);
00863       new TGFileDialog(gClient->GetDefaultRoot(), m_cmsShowMainFrame,
00864                        kFDSave,&fi);
00865       dir = fi.fIniDir;
00866       if (fi.fFilename != 0) {
00867          std::string name = fi.fFilename;
00868          // fi.fFileTypeIdx points to the name of the file type
00869          // selected in the drop-down menu, so fi.fFileTypeIdx gives us
00870          // the extension
00871          std::string ext = kImageExportTypes[fi.fFileTypeIdx + 1] + 1;
00872          if (name.find(ext) == name.npos)
00873             name += ext;
00874          // now add format trailing before the extension
00875          name.insert(name.rfind('.'), "-%d_%d_%d_%s");
00876          exportAllViews(name);
00877       }
00878    }
00879    catch (std::runtime_error &e) { std::cout << e.what() << std::endl; }
00880 }
00881 
00882 void
00883 FWGUIManager::exportAllViews(const std::string& format)
00884 {
00885    // Save all GL views.
00886    // Expects format to have "%d %d %d %s" which are replaced with
00887    //   run-number, event number, lumi block and view-name.
00888    // Blanks in view-name are removed.
00889    // If several views shave the same name, they are post-fixed
00890    // with "_%d". They are sorted by view diagonal.
00891 
00892    typedef std::list<TEveViewer*>           viewer_list_t;
00893    typedef viewer_list_t::iterator          viewer_list_i;
00894 
00895    typedef std::map<TString, viewer_list_t> name_map_t;
00896    typedef name_map_t::iterator             name_map_i;
00897 
00898    name_map_t vls;
00899 
00900    for (ViewMap_i i = m_viewMap.begin(); i != m_viewMap.end(); ++i)
00901    {
00902       TEveViewer *ev = dynamic_cast<TEveViewer*>(i->first);
00903       if (ev)
00904       {
00905          TString name(ev->GetElementName());
00906          name.ReplaceAll(" ", "");
00907          viewer_list_t &l  = vls[name];
00908          viewer_list_i  li = l.begin();
00909          while (li != l.end() && (*li)->GetGLViewer()->ViewportDiagonal() < ev->GetGLViewer()->ViewportDiagonal())
00910             ++li;
00911          l.insert(li, ev);
00912       }
00913    }
00914 
00915    const edm::EventBase *event = getCurrentEvent();
00916    for (name_map_i i = vls.begin(); i != vls.end(); ++i)
00917    {
00918       bool multi_p    = (i->second.size() > 1);
00919       int  view_count = 1;
00920       for (viewer_list_i j = i->second.begin(); j != i->second.end(); ++j, ++view_count)
00921       {
00922          TString view_name(i->first);
00923          if (multi_p)
00924          {
00925             view_name += "_";
00926             view_name += view_count;
00927          }
00928          TString file;
00929          file.Form(format.c_str(), event->id().run(), event->id().event(),
00930                    event->luminosityBlock(), view_name.Data());
00931          (*j)->GetGLViewer()->SavePicture(file);
00932       }
00933    }
00934 }
00935 
00936 static const std::string kMainWindow("main window");
00937 static const std::string kViews("views");
00938 static const std::string kViewArea("view area");
00939 static const std::string kUndocked("undocked views");
00940 static const std::string kControllers("controllers");
00941 static const std::string kCollectionController("collection");
00942 static const std::string kViewController("view");
00943 static const std::string kObjectController("object");
00944 static const std::string kCommonController("common");
00945 
00946 static
00947 void
00948 addWindowInfoTo(const TGFrame* iMain,
00949                 FWConfiguration& oTo)
00950 {
00951    Window_t wdummy;
00952    Int_t ax,ay;
00953    gVirtualX->TranslateCoordinates(iMain->GetId(),
00954                                    gClient->GetDefaultRoot()->GetId(),
00955                                    0,0, //0,0 in local coordinates
00956                                    ax,ay, //coordinates of screen
00957                                    wdummy);
00958    {
00959       std::stringstream s;
00960       s<<ax;
00961       oTo.addKeyValue("x",FWConfiguration(s.str()));
00962    }
00963    {
00964       std::stringstream s;
00965       s<<ay;
00966       oTo.addKeyValue("y",FWConfiguration(s.str()));
00967    }
00968    {
00969       std::stringstream s;
00970       s<<iMain->GetWidth();
00971       oTo.addKeyValue("width",FWConfiguration(s.str()));
00972    }
00973    {
00974       std::stringstream s;
00975       s<<iMain->GetHeight();
00976       oTo.addKeyValue("height",FWConfiguration(s.str()));
00977    }
00978 }
00979 
00980 class areaInfo
00981 {
00982    // helper class to save and restore view area
00983 public:
00984    areaInfo (TGFrameElementPack* frameElement)
00985    {
00986       eveWindow          = 0;
00987       originalSlot      = 0;
00988       undockedMainFrame = 0;
00989       weight = frameElement->fWeight;
00990       undocked = !frameElement->fState;
00991 
00992       TEveCompositeFrame *eveFrame = dynamic_cast<TEveCompositeFrame*>(frameElement->fFrame);
00993       assert(eveFrame);
00994 
00995       if (frameElement->fState)
00996          eveWindow    =  eveFrame->GetEveWindow();
00997       else
00998          originalSlot = eveFrame->GetEveWindow();
00999    }
01000 
01001    areaInfo () {}
01002 
01003    Float_t     weight;
01004    Bool_t      undocked;
01005    TEveWindow *eveWindow;
01006    TGMainFrame *undockedMainFrame;// cached to help find original slot for undocked windows
01007    TEveWindow  *originalSlot;
01008 };
01009 
01010 static
01011 void
01012 addAreaInfoTo(areaInfo& pInfo,
01013               FWConfiguration& oTo)
01014 {
01015    {
01016       std::stringstream s;
01017       s << pInfo.weight;
01018       oTo.addKeyValue("weight", FWConfiguration(s.str()));
01019    }
01020    {
01021       std::stringstream s;
01022       s<< pInfo.undocked;
01023       oTo.addKeyValue("undocked", FWConfiguration(s.str()));
01024    }
01025 
01026    if (pInfo.undockedMainFrame)
01027    {
01028       FWConfiguration temp(oTo);
01029       addWindowInfoTo(pInfo.undockedMainFrame, temp);
01030       oTo.addKeyValue("UndockedWindowPos", temp);
01031    }
01032 }
01033 
01034 //______________________________________________________________________________
01035 void
01036 FWGUIManager::addTo(FWConfiguration& oTo) const
01037 {
01038    Int_t cfgVersion=2;
01039 
01040    FWConfiguration mainWindow(cfgVersion);
01041    float leftWeight, rightWeight;
01042    addWindowInfoTo(m_cmsShowMainFrame, mainWindow);
01043    {
01044       // write proportions of horizontal pack (can be standalone item outside main frame)
01045       if ( m_viewPrimPack->GetPack()->GetList()->GetSize() > 2)
01046       {
01047          TGFrameElementPack *frameEL;
01048          frameEL = (TGFrameElementPack*) m_viewPrimPack->GetPack()->GetList()->At(1); // read every second  element, first on is splitter
01049          leftWeight = frameEL->fWeight;
01050          frameEL = (TGFrameElementPack*)  m_viewPrimPack->GetPack()->GetList()->At(3);
01051          rightWeight = frameEL->fWeight;
01052       }
01053       else
01054       {
01055          leftWeight = 0;
01056          rightWeight = 1;
01057       }
01058       std::stringstream sL;
01059       sL<<leftWeight;
01060       mainWindow.addKeyValue("leftWeight",FWConfiguration(sL.str()));
01061       std::stringstream sR;
01062       sR<<rightWeight;
01063       mainWindow.addKeyValue("rightWeight",FWConfiguration(sR.str()));
01064    }
01065    oTo.addKeyValue(kMainWindow, mainWindow, true);
01066 
01067    //------------------------------------------------------------
01068    // organize info about all docked frames includding hidden, which point to undocked
01069    std::vector<areaInfo> wpacked;
01070    if (leftWeight > 0)
01071    {
01072       TGPack* pp = m_viewPrimPack->GetPack();
01073       TGFrameElementPack *frameEL = (TGFrameElementPack*) pp->GetList()->At(1);
01074       if (frameEL->fWeight > 0)
01075          wpacked.push_back(areaInfo(frameEL));
01076    }
01077    TGPack* sp = m_viewSecPack->GetPack();
01078    Int_t nf = sp->GetList()->GetSize();
01079    TIter frame_iterator(sp->GetList());
01080    for (Int_t i=0; i<nf; ++i) {
01081       TGFrameElementPack *seFE = (TGFrameElementPack*)frame_iterator();
01082       if (seFE->fWeight)
01083          wpacked.push_back(areaInfo(seFE));
01084    }
01085 
01086    //  undocked info
01087    
01088    for(ViewMap_i wIt = m_viewMap.begin(); wIt != m_viewMap.end(); ++wIt)
01089    {
01090       TEveWindow* ew = wIt->first;
01091       TEveCompositeFrameInMainFrame* mainFrame = dynamic_cast<TEveCompositeFrameInMainFrame*>(ew->GetEveFrame());
01092       if (mainFrame)
01093       {
01094          for(std::vector<areaInfo>::iterator pIt = wpacked.begin(); pIt != wpacked.end(); ++pIt)
01095          {
01096             if ((*pIt).originalSlot && mainFrame->GetOriginalSlot() == (*pIt).originalSlot)
01097             {
01098                (*pIt).eveWindow = wIt->first;
01099                (*pIt).undockedMainFrame = (TGMainFrame*)mainFrame;
01100                // printf("found original slot for docked view %s\n", pInfo->viewBase->typeName().c_str());
01101                break;
01102             }// found match
01103          }
01104       }// end main frames
01105    }
01106    
01107    //------------------------------------------------------------
01108    // add sorted list in view area and FW-views configuration
01109    FWConfiguration views(1);
01110    FWConfiguration viewArea(cfgVersion);
01111    for(std::vector<areaInfo>::iterator it = wpacked.begin(); it != wpacked.end(); ++it)
01112    {
01113       TEveWindow* ew = (*it).eveWindow;
01114       if (ew) {
01115          FWViewBase* wb = m_viewMap[ew];
01116          FWConfiguration tempWiew(wb->version());
01117          wb->addTo(tempWiew);
01118          views.addKeyValue(wb->typeName(), tempWiew, true);
01119          FWConfiguration tempArea(cfgVersion);
01120          addAreaInfoTo((*it), tempArea);
01121          viewArea.addKeyValue(wb->typeName(), tempArea, true);
01122       }
01123    }
01124    oTo.addKeyValue(kViews, views, true);
01125    oTo.addKeyValue(kViewArea, viewArea, true);
01126 
01127    //------------------------------------------------------------
01128    //Remember where controllers were placed if they are open
01129    FWConfiguration controllers(1);
01130    {
01131       if(0!=m_ediFrame && m_ediFrame->IsMapped()) {
01132          FWConfiguration temp(1);
01133          addWindowInfoTo(m_ediFrame, temp);
01134          controllers.addKeyValue(kCollectionController,temp,true);
01135       }
01136       if(0!=m_viewPopup && m_viewPopup->IsMapped()) {
01137          FWConfiguration temp(1);
01138          addWindowInfoTo(m_viewPopup, temp);
01139          controllers.addKeyValue(kViewController,temp,true);
01140       }
01141       if(0!=m_modelPopup && m_modelPopup->IsMapped()) {
01142          FWConfiguration temp(1);
01143          addWindowInfoTo(m_modelPopup, temp);
01144          controllers.addKeyValue(kObjectController,temp,true);
01145       }
01146       if(0!=m_commonPopup && m_commonPopup->IsMapped()) {
01147          FWConfiguration temp(1);
01148          addWindowInfoTo(m_commonPopup, temp);
01149          controllers.addKeyValue(kCommonController,temp,true);
01150       }
01151    }
01152    oTo.addKeyValue(kControllers,controllers,true);
01153 
01154    //______________________________________________________________________________
01155    // geometry 
01156    FWConfiguration rootGeo;
01157    {
01158      m_geoBrowser->addTo(rootGeo);
01159    }
01160    oTo.addKeyValue("geo-browser",rootGeo,true);
01161 }
01162 
01163 //----------------------------------------------------------------
01164 void
01165 FWGUIManager::setWindowInfoFrom(const FWConfiguration& iFrom,
01166                                 TGMainFrame* iFrame)
01167 {
01168    int x = atoi(iFrom.valueForKey("x")->value().c_str()) + m_WMOffsetX;
01169    int y = atoi(iFrom.valueForKey("y")->value().c_str()) + m_WMOffsetY;
01170    if (y < m_WMDecorH) y = m_WMDecorH;
01171    int width = atoi(iFrom.valueForKey("width")->value().c_str());
01172    int height = atoi(iFrom.valueForKey("height")->value().c_str());
01173    iFrame->MoveResize(x,y,width,height);
01174    iFrame->SetWMPosition(x, y);
01175 }
01176 
01177 void
01178 FWGUIManager::setFrom(const FWConfiguration& iFrom) {
01179    // main window
01180    if (m_viewSecPack) subviewDestroyAll();
01181 
01182    const FWConfiguration* mw = iFrom.valueForKey(kMainWindow);
01183    assert(mw != 0);
01184    // Window needs to mapped before moving, otherwise move can lead
01185    // to wrong results on some window managers.
01186    m_cmsShowMainFrame->MapWindow();
01187    setWindowInfoFrom(*mw, m_cmsShowMainFrame);
01188    m_cmsShowMainFrame->MapSubwindows();
01189    m_cmsShowMainFrame->Layout();
01190    m_cmsShowMainFrame->MapRaised();
01191 
01192    // set from view reading area info nd view info
01193    float_t leftWeight =1;
01194    float_t rightWeight=1;
01195    if ( mw->version() == 2 ) {
01196       leftWeight = atof(mw->valueForKey("leftWeight")->value().c_str());
01197       rightWeight = atof(mw->valueForKey("rightWeight")->value().c_str());
01198    }
01199 
01200    TEveWindowSlot* primSlot = (leftWeight > 0) ? m_viewPrimPack->NewSlotWithWeight(leftWeight) : 0;
01201    m_viewSecPack = m_viewPrimPack->NewSlotWithWeight(rightWeight)->MakePack();
01202    m_viewSecPack->SetVertical();
01203    m_viewSecPack->SetShowTitleBar(kFALSE);
01204 
01205    // views list
01206    const FWConfiguration* views = iFrom.valueForKey(kViews); assert(0!=views);
01207    const FWConfiguration::KeyValues* keyVals = views->keyValues();
01208    const FWConfiguration* viewArea = iFrom.valueForKey(kViewArea);
01209 
01210    // area list (ignored in older version)
01211    if ( viewArea->version() > 1)
01212    {
01213       const FWConfiguration::KeyValues* akv = viewArea->keyValues();
01214       FWConfiguration::KeyValuesIt areaIt = akv->begin();
01215 
01216       for(FWConfiguration::KeyValuesIt it = keyVals->begin(); it!= keyVals->end(); ++it)
01217       {
01218          float weight = atof((areaIt->second).valueForKey("weight")->value().c_str());
01219          TEveWindowSlot* slot = ( m_viewMap.size() || (primSlot == 0) ) ? m_viewSecPack->NewSlotWithWeight(weight) : primSlot;
01220          std::string name = FWViewType::checkNameWithViewVersion(it->first, it->second.version());
01221          ViewMap_i lastViewIt = createView(name, slot);
01222          lastViewIt->second->setFrom(it->second);
01223 
01224          bool  undocked = atof((areaIt->second).valueForKey("undocked")->value().c_str());
01225          if (undocked)
01226          {
01227             TEveWindow* lastWindow = lastViewIt->first;
01228             lastWindow->UndockWindow();
01229             TEveCompositeFrameInMainFrame* emf = dynamic_cast<TEveCompositeFrameInMainFrame*>(lastWindow->GetEveFrame());
01230             const TGMainFrame* mf =  dynamic_cast<const TGMainFrame*>(emf->GetParent());
01231             m_cmsShowMainFrame->bindCSGActionKeys(mf);
01232             TGMainFrame* mfp = (TGMainFrame*)mf;
01233             const FWConfiguration* mwc = (areaIt->second).valueForKey("UndockedWindowPos");
01234             setWindowInfoFrom(*mwc, mfp);
01235          }
01236          areaIt++;
01237       }
01238    }
01239    else
01240    {  // create views with same weight in old version
01241       for(FWConfiguration::KeyValuesIt it = keyVals->begin(); it!= keyVals->end(); ++it) {
01242          std::string name = FWViewType::checkNameWithViewVersion(it->first, it->second.version());       
01243          createView(name, m_viewMap.size() ? m_viewSecPack->NewSlot() : primSlot);       
01244 
01245          ViewMap_i lastViewIt = m_viewMap.end(); lastViewIt--;
01246          lastViewIt->second->setFrom(it->second);
01247       }
01248       // handle undocked windows in old version
01249       const FWConfiguration* undocked = iFrom.valueForKey(kUndocked);
01250       if(0!=undocked) {
01251          fwLog(fwlog::kWarning) << "Restrore of undocked windows with old window management not supported." << std::endl;
01252       }
01253    }
01254 
01255    //handle controllers
01256    const FWConfiguration* controllers = iFrom.valueForKey(kControllers);
01257    if(0!=controllers) {
01258       const FWConfiguration::KeyValues* keyVals = controllers->keyValues();
01259       if(0!=keyVals) {
01260          //we have open controllers
01261          for(FWConfiguration::KeyValuesIt it = keyVals->begin(); it != keyVals->end(); ++it)
01262          {
01263             const std::string& controllerName = it->first;
01264             // std::cout <<"found controller "<<controllerName<<std::endl;
01265             if(controllerName == kCollectionController) {
01266                showEDIFrame();
01267                setWindowInfoFrom(it->second,m_ediFrame);
01268             } else if (controllerName == kViewController) {
01269                setViewPopup(0);
01270                setWindowInfoFrom(it->second, m_viewPopup);
01271             } else if (controllerName == kObjectController) {
01272                showModelPopup();
01273                setWindowInfoFrom(it->second, m_modelPopup);
01274             } else if (controllerName == kCommonController) {
01275                showCommonPopup();
01276                setWindowInfoFrom(it->second, m_commonPopup);
01277             }
01278          }
01279       }
01280    }
01281 
01282    // disable fist docked view
01283    checkSubviewAreaIconState(0);
01284 
01285   //______________________________________________________________________________
01286   const FWConfiguration* rootGeo = iFrom.valueForKey("geo-browser");
01287   if (rootGeo)     
01288      m_geoBrowser->setFrom(*rootGeo);
01289 }
01290 
01291 void
01292 FWGUIManager::openEveBrowserForDebugging() const
01293 {
01294    gEve->GetBrowser()->MapWindow();
01295 }
01296 
01297 //
01298 // toolbar widgets callbacks
01299 //
01300 void
01301 FWGUIManager::delaySliderChanged(Int_t val)
01302 {
01303    Float_t sec = val*0.001;
01304    m_cmsShowMainFrame->setPlayDelayGUI(sec, kFALSE);
01305    changedDelayBetweenEvents_.emit(sec);
01306 }
01307 
01308 void
01309 FWGUIManager::setDelayBetweenEvents(Float_t val)
01310 {
01311    m_cmsShowMainFrame->setPlayDelayGUI(val, kTRUE);
01312 }
01313 
01314 void FWGUIManager::runIdChanged()
01315 {
01316    m_cmsShowMainFrame->m_lumiEntry->SetText("", kFALSE);
01317    m_cmsShowMainFrame->m_lumiEntry->SetFocus();
01318 }
01319 
01320 void FWGUIManager::lumiIdChanged()
01321 {
01322    m_cmsShowMainFrame->m_eventEntry->SetText("", kFALSE);
01323    m_cmsShowMainFrame->m_eventEntry->SetFocus();
01324 }
01325 
01326 void FWGUIManager::eventIdChanged()
01327 {
01328    changedEventId_.emit(m_cmsShowMainFrame->m_runEntry->GetUIntNumber(),
01329                         m_cmsShowMainFrame->m_lumiEntry->GetUIntNumber(),
01330                         m_cmsShowMainFrame->m_eventEntry->GetUIntNumber());
01331 }
01332 
01333 void
01334 FWGUIManager::finishUpColorChange()
01335 {
01336    if (m_commonPopup) m_commonPopup->colorSetChanged();
01337    if (m_modelPopup)  m_modelPopup->colorSetChanged();
01338    if (m_ediFrame)    m_ediFrame->colorSetChanged();
01339 
01340    gEve->FullRedraw3D();
01341 }
01342 //______________________________________________________________________________
01343 
01344 void
01345 FWGUIManager::showEventFilterGUI()
01346 {
01347    showEventFilterGUI_.emit(m_cmsShowMainFrame);
01348 }
01349 
01350 void
01351 FWGUIManager::filterButtonClicked()
01352 {
01353    filterButtonClicked_.emit();
01354 }
01355 
01356 void
01357 FWGUIManager::setFilterButtonText(const char* txt)
01358 {
01359    m_cmsShowMainFrame->m_filterShowGUIBtn->SetText(txt);
01360 }
01361 
01362 void
01363 FWGUIManager::setFilterButtonIcon(int state)
01364 {
01365    int i = state*3;
01366    m_cmsShowMainFrame->m_filterEnableBtn->setIcons(m_cmsShowMainFrame->m_filterIcons[i],
01367                                                    m_cmsShowMainFrame->m_filterIcons[i+1],
01368                                                    m_cmsShowMainFrame->m_filterIcons[i+2]);
01369 }
01370 
01371 void
01372 FWGUIManager::updateEventFilterEnable(bool btnEnabled)
01373 {
01374    m_cmsShowMainFrame->m_filterEnableBtn->SetEnabled(btnEnabled);
01375 }
01376 
01377 void
01378 FWGUIManager::measureWMOffsets()
01379 {
01380   const Int_t x = 100, y = 100;
01381 
01382   TGMainFrame *mf1 = new TGMainFrame(0, 0, 0);
01383   mf1->MapWindow();
01384   mf1->Move(x, y);
01385 
01386   // This seems to be the only reliable way to make sure Move() has been processed.
01387   {
01388     TGMainFrame *mf2 = new TGMainFrame(0, 0, 0);
01389     mf2->MapWindow();
01390     while (!mf2->IsMapped()) gClient->HandleInput();
01391     delete mf2;
01392   }
01393   {
01394     Int_t    xm, ym;
01395     Window_t childdum;
01396     WindowAttributes_t attr;
01397     gVirtualX->TranslateCoordinates(mf1->GetId(), gClient->GetDefaultRoot()->GetId(),
01398                                     0, 0, xm, ym, childdum);
01399     gVirtualX->GetWindowAttributes(mf1->GetId(), attr);
01400     m_WMOffsetX = x - xm;
01401     m_WMOffsetY = y - ym;
01402     m_WMDecorH  = attr.fY;
01403     fwLog(fwlog::kDebug) << Form("FWGUIManager::measureWMOffsets: required (%d,%d), measured(%d, %d) => dx=%d, dy=%d; decor_h=%d.\n",
01404                                  x, y, xm, ym, m_WMOffsetX, m_WMOffsetY, m_WMDecorH);
01405   }
01406   delete mf1;
01407 }
01408 
01409 void
01410 FWGUIManager::resetWMOffsets()
01411 {
01412    m_WMOffsetX = m_WMOffsetY = m_WMDecorH = 0;
01413 }