CMS 3D CMS Logo

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