CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/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.250 2011/09/12 23:12:49 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/FWGeometryTableView.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 
00498    CmsShowTaskExecutor::TaskFunctor f;
00499    f = boost::bind(&FWGUIManager::subviewDestroy, this, sva);
00500    m_tasks->addTask(f);
00501    m_tasks->startDoingTasks();
00502 }
00503 
00504 void
00505 FWGUIManager::subviewDestroy(FWGUISubviewArea* sva)
00506 {  
00507    TEveWindow* ew       = sva->getEveWindow();
00508    FWViewBase* viewBase = m_viewMap[ew];
00509    m_viewMap.erase(ew);
00510    viewBase->destroy();
00511 }
00512 
00513 void
00514 FWGUIManager::subviewDestroyAll()
00515 {
00516    std::vector<FWGUISubviewArea*> sd;
00517    for(ViewMap_i wIt = m_viewMap.begin(); wIt != m_viewMap.end(); ++wIt)
00518    {
00519       FWGUISubviewArea* ar = FWGUISubviewArea::getToolBarFromWindow(wIt->first);
00520       sd.push_back(ar);
00521    }
00522 
00523    for (std::vector<FWGUISubviewArea*>::iterator i= sd.begin(); i !=sd.end(); ++i)
00524    {
00525       if((*i)->isSelected())
00526          setViewPopup(0);
00527       subviewDestroy(*i);
00528    }
00529 
00530    gSystem->ProcessEvents();
00531    gSystem->Sleep(200);
00532 
00533 
00534    
00535    while (m_viewPrimPack->HasChildren())
00536    {
00537       TEveWindow* w = dynamic_cast<TEveWindow*>(m_viewPrimPack->FirstChild());
00538       if (w) w->DestroyWindowAndSlot();
00539    }
00540 
00541    gSystem->Sleep(200);
00542    m_viewSecPack = 0;
00543    gSystem->ProcessEvents();
00544 
00545 }
00546 
00547 void
00548 FWGUIManager::subviewInfoSelected(FWGUISubviewArea* sva)
00549 {
00550    // release button on previously selected
00551    TEveWindow* ew = sva->getEveWindow();
00552    for(ViewMap_i wIt = m_viewMap.begin(); wIt != m_viewMap.end(); ++wIt)
00553    {
00554       if (wIt->first != ew)
00555          FWGUISubviewArea::getToolBarFromWindow(wIt->first)->setInfoButton(kFALSE);
00556    }
00557    setViewPopup(sva->getEveWindow());
00558 }
00559 
00560 void
00561 FWGUIManager::subviewInfoUnselected(FWGUISubviewArea* sva)
00562 {
00563    m_viewPopup->UnmapWindow();
00564 }
00565 
00566 void
00567 FWGUIManager::subviewSwapped(FWGUISubviewArea* sva)
00568 {
00569    TEveWindow* curr = getSwapCandidate();
00570    TEveWindow* swap = sva->getEveWindow();
00571    if (curr) swap->SwapWindow(curr);
00572 
00573    checkSubviewAreaIconState(0);
00574 }
00575 
00576 TGVerticalFrame*
00577 FWGUIManager::createList(TGCompositeFrame *p)
00578 {
00579    TGVerticalFrame *listFrame = new TGVerticalFrame(p, p->GetWidth(), p->GetHeight());
00580 
00581    TGHorizontalFrame* addFrame = new TGHorizontalFrame(listFrame, p->GetWidth(), 10, kRaisedFrame);
00582    TGLabel* addLabel = new TGLabel(addFrame,"Summary View");
00583    addFrame->AddFrame(addLabel, new TGLayoutHints(kLHintsCenterX, 0,0,2,2));
00584    listFrame->AddFrame(addFrame, new TGLayoutHints(kLHintsExpandX | kLHintsTop));
00585 
00586    m_summaryManager = new FWSummaryManager(listFrame,
00587                                            m_context->selectionManager(),
00588                                            (FWEventItemsManager*) m_context->eventItemsManager(),
00589                                            this,
00590                                            m_context->modelChangeManager(),
00591                                            m_context->colorManager());
00592 
00593    const unsigned int backgroundColor=0x2f2f2f;
00594    TGTextButton* addDataButton = new TGTextButton(m_summaryManager->widget(), "Add Collection");
00595    addDataButton->ChangeOptions(kRaisedFrame);
00596    addDataButton->SetBackgroundColor(backgroundColor);
00597    addDataButton->SetTextColor(0xFFFFFF);
00598    addDataButton->SetToolTipText("Show additional collections");
00599    addDataButton->Connect("Clicked()", "FWGUIManager", this, "addData()");
00600    m_summaryManager->widget()->AddFrame(addDataButton, new TGLayoutHints(kLHintsExpandX|kLHintsLeft|kLHintsTop));
00601    listFrame->AddFrame(m_summaryManager->widget(), new TGLayoutHints(kLHintsExpandX|kLHintsExpandY));
00602 
00603    return listFrame;
00604 }
00605 
00606 void
00607 FWGUIManager::createViews(TEveWindowSlot *slot)
00608 {
00609    m_viewPrimPack = slot->MakePack();
00610    m_viewPrimPack->SetHorizontal();
00611    m_viewPrimPack->SetElementName("Views");
00612    m_viewPrimPack->SetShowTitleBar(kFALSE);
00613    m_viewSecPack = 0;
00614 }
00615 
00616 void
00617 FWGUIManager::createEDIFrame() {
00618    if (m_ediFrame == 0) {
00619       m_ediFrame = new CmsShowEDI(m_cmsShowMainFrame, 200, 200, m_context->selectionManager(),m_context->colorManager());
00620       m_ediFrame->CenterOnParent(kTRUE,TGTransientFrame::kTopRight);
00621       m_cmsShowMainFrame->bindCSGActionKeys(m_ediFrame);
00622    }
00623 }
00624 
00625 void
00626 FWGUIManager::showEDIFrame(int iToShow)
00627 {
00628    createEDIFrame();
00629    if(-1 != iToShow) {
00630       m_ediFrame->show(static_cast<FWDataCategories> (iToShow));
00631    }
00632    m_ediFrame->MapRaised();
00633 }
00634 
00635 void
00636 FWGUIManager::showCommonPopup()
00637 {
00638    if (! m_commonPopup)
00639    {
00640       m_commonPopup = new CmsShowCommonPopup(m_context->commonPrefs(), m_cmsShowMainFrame, 200, 200);
00641       m_cmsShowMainFrame->bindCSGActionKeys(m_commonPopup);
00642    }
00643    m_commonPopup->MapRaised();
00644 }
00645 
00646 void
00647 FWGUIManager::createModelPopup()
00648 {
00649    m_modelPopup = new CmsShowModelPopup(m_detailViewManager,m_context->selectionManager(), m_context->colorManager(), m_cmsShowMainFrame, 200, 200);
00650    m_modelPopup->CenterOnParent(kTRUE,TGTransientFrame::kRight);
00651    m_cmsShowMainFrame->bindCSGActionKeys(m_modelPopup);
00652 }
00653 
00654 void
00655 FWGUIManager::showModelPopup()
00656 {
00657    if (!m_modelPopup) createModelPopup();
00658    m_modelPopup->MapRaised();
00659 }
00660 
00661 void
00662 FWGUIManager::popupViewClosed()
00663 {
00664    if (m_viewPopup->getEveWindow())
00665    {
00666       FWGUISubviewArea* sa = FWGUISubviewArea::getToolBarFromWindow(m_viewPopup->getEveWindow());
00667       sa->setInfoButton(kFALSE);
00668    }
00669 }
00670 
00671 void
00672 FWGUIManager::showViewPopup() {
00673    // CSG action .
00674    setViewPopup(0);
00675 }
00676 
00677 void
00678 FWGUIManager::setViewPopup(TEveWindow* ew) {
00679    FWViewBase* vb = ew ? m_viewMap[ew] : 0;
00680    if (m_viewPopup == 0)
00681    {
00682       m_viewPopup = new CmsShowViewPopup(0, 200, 200, m_context->colorManager(), vb, ew);
00683       m_viewPopup->closed_.connect(sigc::mem_fun(*m_guiManager, &FWGUIManager::popupViewClosed));
00684    }
00685    else
00686    {
00687       m_viewPopup->UnmapWindow();
00688    }
00689    m_viewPopup->reset(vb, ew);
00690    m_viewPopup->MapRaised();
00691 }
00692 
00693 void
00694 FWGUIManager::showInvMassDialog()
00695 {
00696    if (! m_invMassDialog)
00697    {
00698       m_invMassDialog = new FWInvMassDialog(m_context->selectionManager());
00699       m_cmsShowMainFrame->bindCSGActionKeys(m_invMassDialog);
00700    }
00701    m_invMassDialog->MapRaised();
00702 }
00703 
00704 void
00705 FWGUIManager::createHelpPopup ()
00706 {
00707    if (m_helpPopup == 0) {
00708       m_helpPopup = new CmsShowHelpPopup("help.html", "CmsShow Help",
00709                                          m_cmsShowMainFrame,
00710                                          800, 600);
00711       m_helpPopup->CenterOnParent(kTRUE,TGTransientFrame::kBottomRight);
00712    }
00713    m_helpPopup->MapWindow();
00714 }
00715 
00716 
00717 void
00718 FWGUIManager::createShortcutPopup ()
00719 {
00720    if (m_shortcutPopup == 0) {
00721       m_shortcutPopup = new CmsShowHelpPopup("shortcuts.html",
00722                                              getAction(cmsshow::sKeyboardShort)->getName().c_str(),
00723                                               m_cmsShowMainFrame, 800, 600);
00724 
00725       m_shortcutPopup->CenterOnParent(kTRUE,TGTransientFrame::kBottomRight);
00726    }
00727    m_shortcutPopup->MapWindow();
00728 }
00729 
00730 void FWGUIManager::createHelpGLPopup ()
00731 {
00732    if (m_helpGLPopup == 0) {
00733       m_helpGLPopup = new CmsShowHelpPopup("helpGL.html",
00734                                             getAction(cmsshow::sHelpGL)->getName().c_str(),
00735                                             m_cmsShowMainFrame, 800, 600);
00736 
00737       m_helpGLPopup->CenterOnParent(kTRUE,TGTransientFrame::kBottomRight);
00738    }
00739    m_helpGLPopup->MapWindow();
00740 }
00741 
00742 void 
00743 FWGUIManager::showSelectedModelContextMenu(Int_t iGlobalX, Int_t iGlobalY, FWViewContextMenuHandlerBase* iHandler)
00744 {
00745    if(!m_context->selectionManager()->selected().empty()) {
00746       m_contextMenuHandler->showSelectedModelContext(iGlobalX,iGlobalY, iHandler);
00747    }
00748 }
00749 
00750 //
00751 // const member functions
00752 //
00753 
00754 FWGUIManager*
00755 FWGUIManager::getGUIManager()
00756 {
00757    return m_guiManager;
00758 }
00759 
00760 const edm::EventBase*
00761 FWGUIManager::getCurrentEvent() const
00762 {
00763    return m_navigator->getCurrentEvent();  
00764 }
00765 
00774 bool
00775 FWGUIManager::promptForConfigurationFile(std::string &result, enum EFileDialogMode mode)
00776 {
00777    static const char* kFileTypes[] = {"Fireworks Configuration files","*.fwc",
00778                                        "All Files","*",
00779                                        0,0};
00780 
00781    static TString dir(".");
00782 
00783    TGFileInfo fi;
00784    fi.fFileTypes = kFileTypes;
00785    fi.fIniDir    = StrDup(dir);
00786    new TGFileDialog(gClient->GetDefaultRoot(), m_cmsShowMainFrame, mode, &fi);
00787    dir = fi.fIniDir;
00788    if (fi.fFilename == 0) // to handle "cancel" button properly
00789       return false;
00790    std::string name = fi.fFilename;
00791    // if the extension isn't already specified by hand, specify it now
00792    std::string ext = kFileTypes[fi.fFileTypeIdx + 1] + 1;
00793    if (ext.size() != 0 && name.find(ext) == name.npos)
00794       name += ext;
00795    result = name;
00796    return true;
00797 }
00798 
00799 
00803 void
00804 FWGUIManager::promptForLoadConfigurationFile()
00805 {
00806    std::string name;
00807    if (!promptForConfigurationFile(name, kFDOpen))
00808       return;
00809   
00810    
00811    loadFromConfigurationFile_(name);
00812 }
00813 
00817 void
00818 FWGUIManager::promptForSaveConfigurationFile()
00819 {
00820    std::string name;
00821    if (!promptForConfigurationFile(name, kFDSave))
00822       return;
00823    writeToConfigurationFile_(name);
00824 }
00825 
00826 void
00827 FWGUIManager::exportImageOfMainView()
00828 {
00829    if (m_viewPrimPack->GetPack()->GetList()->GetSize() > 2)
00830    {
00831       TGFrameElementPack* frameEL = (TGFrameElementPack*) m_viewPrimPack->GetPack()->GetList()->At(1);
00832       TEveCompositeFrame* ef = dynamic_cast<TEveCompositeFrame*>(frameEL->fFrame);
00833       m_viewMap[ef->GetEveWindow()]->promptForSaveImageTo(m_cmsShowMainFrame);
00834    }
00835    else
00836    {
00837       fwLog(fwlog::kError) << "Main view has been destroyed." << std::endl; 
00838    }
00839 }
00840 
00841 void
00842 FWGUIManager::exportImagesOfAllViews()
00843 {
00844    try {
00845       static TString dir(".");
00846       const char *  kImageExportTypes[] = {"PNG",                     "*.png",
00847                                            "GIF",                     "*.gif",
00848                                            "JPEG",                    "*.jpg",
00849                                            "PDF",                     "*.pdf",
00850                                            "Encapsulated PostScript", "*.eps",
00851                                            0, 0};
00852 
00853       TGFileInfo fi;
00854       fi.fFileTypes = kImageExportTypes;
00855       fi.fIniDir    = StrDup(dir);
00856       new TGFileDialog(gClient->GetDefaultRoot(), m_cmsShowMainFrame,
00857                        kFDSave,&fi);
00858       dir = fi.fIniDir;
00859       if (fi.fFilename != 0) {
00860          std::string name = fi.fFilename;
00861          // fi.fFileTypeIdx points to the name of the file type
00862          // selected in the drop-down menu, so fi.fFileTypeIdx gives us
00863          // the extension
00864          std::string ext = kImageExportTypes[fi.fFileTypeIdx + 1] + 1;
00865          if (name.find(ext) == name.npos)
00866             name += ext;
00867          // now add format trailing before the extension
00868          name.insert(name.rfind('.'), "-%u_%u_%u_%s");
00869          exportAllViews(name);
00870       }
00871    }
00872    catch (std::runtime_error &e) { std::cout << e.what() << std::endl; }
00873 }
00874 
00875 void
00876 FWGUIManager::exportAllViews(const std::string& format)
00877 {
00878    // Save all GL views.
00879    // Expects format to have "%d %d %d %s" which are replaced with
00880    //   run-number, event number, lumi block and view-name.
00881    // Blanks in view-name are removed.
00882    // If several views shave the same name, they are post-fixed
00883    // with "_%d". They are sorted by view diagonal.
00884 
00885    typedef std::list<TEveViewer*>           viewer_list_t;
00886    typedef viewer_list_t::iterator          viewer_list_i;
00887 
00888    typedef std::map<TString, viewer_list_t> name_map_t;
00889    typedef name_map_t::iterator             name_map_i;
00890 
00891    name_map_t vls;
00892 
00893    for (ViewMap_i i = m_viewMap.begin(); i != m_viewMap.end(); ++i)
00894    {
00895       TEveViewer *ev = dynamic_cast<TEveViewer*>(i->first);
00896       if (ev)
00897       {
00898          TString name(ev->GetElementName());
00899          name.ReplaceAll(" ", "");
00900          viewer_list_t &l  = vls[name];
00901          viewer_list_i  li = l.begin();
00902          while (li != l.end() && (*li)->GetGLViewer()->ViewportDiagonal() < ev->GetGLViewer()->ViewportDiagonal())
00903             ++li;
00904          l.insert(li, ev);
00905       }
00906    }
00907 
00908    const edm::EventBase *event = getCurrentEvent();
00909    for (name_map_i i = vls.begin(); i != vls.end(); ++i)
00910    {
00911       bool multi_p    = (i->second.size() > 1);
00912       int  view_count = 1;
00913       for (viewer_list_i j = i->second.begin(); j != i->second.end(); ++j, ++view_count)
00914       {
00915          TString view_name(i->first);
00916          if (multi_p)
00917          {
00918             view_name += "_";
00919             view_name += view_count;
00920          }
00921          TString file;
00922          file.Form(format.c_str(), event->id().run(), event->id().event(),
00923                    event->luminosityBlock(), view_name.Data());
00924          (*j)->GetGLViewer()->SavePicture(file);
00925       }
00926    }
00927 }
00928 
00929 static const std::string kMainWindow("main window");
00930 static const std::string kViews("views");
00931 static const std::string kViewArea("view area");
00932 static const std::string kUndocked("undocked views");
00933 static const std::string kControllers("controllers");
00934 static const std::string kCollectionController("collection");
00935 static const std::string kViewController("view");
00936 static const std::string kObjectController("object");
00937 static const std::string kCommonController("common");
00938 
00939 static
00940 void
00941 addWindowInfoTo(const TGFrame* iMain,
00942                 FWConfiguration& oTo)
00943 {
00944    Window_t wdummy;
00945    Int_t ax,ay;
00946    gVirtualX->TranslateCoordinates(iMain->GetId(),
00947                                    gClient->GetDefaultRoot()->GetId(),
00948                                    0,0, //0,0 in local coordinates
00949                                    ax,ay, //coordinates of screen
00950                                    wdummy);
00951    {
00952       std::stringstream s;
00953       s<<ax;
00954       oTo.addKeyValue("x",FWConfiguration(s.str()));
00955    }
00956    {
00957       std::stringstream s;
00958       s<<ay;
00959       oTo.addKeyValue("y",FWConfiguration(s.str()));
00960    }
00961    {
00962       std::stringstream s;
00963       s<<iMain->GetWidth();
00964       oTo.addKeyValue("width",FWConfiguration(s.str()));
00965    }
00966    {
00967       std::stringstream s;
00968       s<<iMain->GetHeight();
00969       oTo.addKeyValue("height",FWConfiguration(s.str()));
00970    }
00971 }
00972 
00973 class areaInfo
00974 {
00975    // helper class to save and restore view area
00976 public:
00977    areaInfo (TGFrameElementPack* frameElement)
00978    {
00979       eveWindow         = 0;
00980       originalSlot      = 0;
00981       undockedMainFrame = 0;
00982       weight = frameElement->fWeight;
00983       undocked = !frameElement->fState;
00984 
00985       TEveCompositeFrame *eveFrame = dynamic_cast<TEveCompositeFrame*>(frameElement->fFrame);
00986       assert(eveFrame);
00987 
00988       if (frameElement->fState)
00989          eveWindow    =  eveFrame->GetEveWindow();
00990       else
00991          originalSlot = eveFrame->GetEveWindow();
00992    }
00993 
00994   areaInfo () : weight(0), undocked(false) {}
00995 
00996    Float_t      weight;
00997    Bool_t       undocked;
00998    TEveWindow  *eveWindow;
00999    TGMainFrame *undockedMainFrame;// cached to help find original slot for undocked windows
01000    TEveWindow  *originalSlot;
01001 };
01002 
01003 static
01004 void
01005 addAreaInfoTo(areaInfo& pInfo,
01006               FWConfiguration& oTo)
01007 {
01008    {
01009       std::stringstream s;
01010       s << pInfo.weight;
01011       oTo.addKeyValue("weight", FWConfiguration(s.str()));
01012    }
01013    {
01014       std::stringstream s;
01015       s<< pInfo.undocked;
01016       oTo.addKeyValue("undocked", FWConfiguration(s.str()));
01017    }
01018 
01019    if (pInfo.undockedMainFrame)
01020    {
01021       FWConfiguration temp(oTo);
01022       addWindowInfoTo(pInfo.undockedMainFrame, temp);
01023       oTo.addKeyValue("UndockedWindowPos", temp);
01024    }
01025 }
01026 
01027 //______________________________________________________________________________
01028 void
01029 FWGUIManager::addTo(FWConfiguration& oTo) const
01030 {
01031    Int_t cfgVersion=3;
01032 
01033    FWConfiguration mainWindow(cfgVersion);
01034    float leftWeight, rightWeight;
01035    addWindowInfoTo(m_cmsShowMainFrame, mainWindow);
01036    {
01037       // write summary view weight
01038       {
01039          std::stringstream ss;
01040          ss << m_cmsShowMainFrame->getSummaryViewWeight();
01041          mainWindow.addKeyValue("summaryWeight",FWConfiguration(ss.str()));
01042       }
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    TGFrameElementPack *seFE;
01079    TIter frame_iterator(sp->GetList());
01080    while ((seFE = (TGFrameElementPack*)frame_iterator() ))
01081    {
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 //----------------------------------------------------------------
01156 void
01157 FWGUIManager::setWindowInfoFrom(const FWConfiguration& iFrom,
01158                                 TGMainFrame* iFrame)
01159 {
01160    int x = atoi(iFrom.valueForKey("x")->value().c_str()) + m_WMOffsetX;
01161    int y = atoi(iFrom.valueForKey("y")->value().c_str()) + m_WMOffsetY;
01162    if (y < m_WMDecorH) y = m_WMDecorH;
01163    int width = atoi(iFrom.valueForKey("width")->value().c_str());
01164    int height = atoi(iFrom.valueForKey("height")->value().c_str());
01165    iFrame->MoveResize(x,y,width,height);
01166    iFrame->SetWMPosition(x, y);
01167 }
01168 
01169 void
01170 FWGUIManager::setFrom(const FWConfiguration& iFrom) {
01171    // main window
01172    if (m_viewSecPack) subviewDestroyAll();
01173 
01174    const FWConfiguration* mw = iFrom.valueForKey(kMainWindow);
01175    assert(mw != 0);
01176    // Window needs to mapped before moving, otherwise move can lead
01177    // to wrong results on some window managers.
01178    m_cmsShowMainFrame->MapWindow();
01179    setWindowInfoFrom(*mw, m_cmsShowMainFrame);
01180    m_cmsShowMainFrame->MapSubwindows();
01181    m_cmsShowMainFrame->Layout();
01182    m_cmsShowMainFrame->MapRaised();
01183 
01184    // set from view reading area info nd view info
01185    float_t leftWeight =1;
01186    float_t rightWeight=1;
01187    if ( mw->version() >= 2 ) {
01188       leftWeight = atof(mw->valueForKey("leftWeight")->value().c_str());
01189       rightWeight = atof(mw->valueForKey("rightWeight")->value().c_str());
01190    }
01191 
01192    if ( mw->version() >= 3 ) {
01193       float summaryWeight = atof(mw->valueForKey("summaryWeight")->value().c_str());
01194       m_cmsShowMainFrame->setSummaryViewWeight(summaryWeight);       
01195    }
01196 
01197    TEveWindowSlot* primSlot = (leftWeight > 0) ? m_viewPrimPack->NewSlotWithWeight(leftWeight) : 0;
01198    m_viewSecPack = m_viewPrimPack->NewSlotWithWeight(rightWeight)->MakePack();
01199    m_viewSecPack->SetVertical();
01200    m_viewSecPack->SetShowTitleBar(kFALSE);
01201 
01202    // views list
01203    const FWConfiguration* views = iFrom.valueForKey(kViews); assert(0!=views);
01204    const FWConfiguration::KeyValues* keyVals = views->keyValues();
01205    const FWConfiguration* viewArea = iFrom.valueForKey(kViewArea);
01206 
01207    // area list (ignored in older version)
01208    if ( viewArea->version() > 1)
01209    {
01210       const FWConfiguration::KeyValues* akv = viewArea->keyValues();
01211       FWConfiguration::KeyValuesIt areaIt = akv->begin();
01212 
01213       for(FWConfiguration::KeyValuesIt it = keyVals->begin(); it!= keyVals->end(); ++it)
01214       {
01215          float weight = atof((areaIt->second).valueForKey("weight")->value().c_str());
01216          TEveWindowSlot* slot = ( m_viewMap.size() || (primSlot == 0) ) ? m_viewSecPack->NewSlotWithWeight(weight) : primSlot;
01217          std::string name = FWViewType::checkNameWithViewVersion(it->first, it->second.version());
01218          ViewMap_i lastViewIt = createView(name, slot);
01219          lastViewIt->second->setFrom(it->second);
01220 
01221          bool  undocked = atof((areaIt->second).valueForKey("undocked")->value().c_str());
01222          if (undocked)
01223          {
01224             TEveWindow* lastWindow = lastViewIt->first;
01225             lastWindow->UndockWindow();
01226             TEveCompositeFrameInMainFrame* emf = dynamic_cast<TEveCompositeFrameInMainFrame*>(lastWindow->GetEveFrame());
01227             if (emf ) {
01228                const TGMainFrame* mf =  dynamic_cast<const TGMainFrame*>(emf->GetParent());
01229                if (mf) {
01230                   m_cmsShowMainFrame->bindCSGActionKeys(mf);
01231                   TGMainFrame* mfp = (TGMainFrame*)mf; // have to cast in non-const
01232                   const FWConfiguration* mwc = (areaIt->second).valueForKey("UndockedWindowPos");
01233                   setWindowInfoFrom(*mwc, mfp);
01234                }
01235             }
01236          }
01237          areaIt++;
01238       }
01239    }
01240    else
01241    {  // create views with same weight in old version
01242       for(FWConfiguration::KeyValuesIt it = keyVals->begin(); it!= keyVals->end(); ++it) {
01243          std::string name = FWViewType::checkNameWithViewVersion(it->first, it->second.version());       
01244          createView(name, m_viewMap.size() ? m_viewSecPack->NewSlot() : primSlot);       
01245 
01246          ViewMap_i lastViewIt = m_viewMap.end(); lastViewIt--;
01247          lastViewIt->second->setFrom(it->second);
01248       }
01249       // handle undocked windows in old version
01250       const FWConfiguration* undocked = iFrom.valueForKey(kUndocked);
01251       if(0!=undocked) {
01252          fwLog(fwlog::kWarning) << "Restrore of undocked windows with old window management not supported." << std::endl;
01253       }
01254    }
01255 
01256    //handle controllers
01257    const FWConfiguration* controllers = iFrom.valueForKey(kControllers);
01258    if(0!=controllers) {
01259       const FWConfiguration::KeyValues* keyVals = controllers->keyValues();
01260       if(0!=keyVals) {
01261          //we have open controllers
01262          for(FWConfiguration::KeyValuesIt it = keyVals->begin(); it != keyVals->end(); ++it)
01263          {
01264             const std::string& controllerName = it->first;
01265             // std::cout <<"found controller "<<controllerName<<std::endl;
01266             if(controllerName == kCollectionController) {
01267                showEDIFrame();
01268                setWindowInfoFrom(it->second,m_ediFrame);
01269             } else if (controllerName == kViewController) {
01270                setViewPopup(0);
01271                setWindowInfoFrom(it->second, m_viewPopup);
01272             } else if (controllerName == kObjectController) {
01273                showModelPopup();
01274                setWindowInfoFrom(it->second, m_modelPopup);
01275             } else if (controllerName == kCommonController) {
01276                showCommonPopup();
01277                setWindowInfoFrom(it->second, m_commonPopup);
01278             }
01279          }
01280       }
01281    }
01282 
01283 
01284    for(ViewMap_i it = m_viewMap.begin(); it != m_viewMap.end(); ++it)
01285    {
01286       if (it->second->typeId() == FWViewType::kGeometryTable)
01287       {
01288          FWGeometryTableView* gv = ( FWGeometryTableView*)it->second;
01289          gv->populate3DViewsFromConfig();
01290       }
01291    }
01292 
01293    // disable first docked view
01294    checkSubviewAreaIconState(0);
01295 
01296  
01297 }
01298 
01299 void
01300 FWGUIManager::openEveBrowserForDebugging() const
01301 {
01302    gEve->GetBrowser()->MapWindow();
01303 }
01304 
01305 //
01306 // toolbar widgets callbacks
01307 //
01308 void
01309 FWGUIManager::delaySliderChanged(Int_t val)
01310 {
01311    Float_t sec = val*0.001;
01312    m_cmsShowMainFrame->setPlayDelayGUI(sec, kFALSE);
01313    changedDelayBetweenEvents_.emit(sec);
01314 }
01315 
01316 void
01317 FWGUIManager::setDelayBetweenEvents(Float_t val)
01318 {
01319    m_cmsShowMainFrame->setPlayDelayGUI(val, kTRUE);
01320 }
01321 
01322 void FWGUIManager::runIdChanged()
01323 {
01324    m_cmsShowMainFrame->m_lumiEntry->SetText("", kFALSE);
01325    m_cmsShowMainFrame->m_lumiEntry->SetFocus();
01326 }
01327 
01328 void FWGUIManager::lumiIdChanged()
01329 {
01330    m_cmsShowMainFrame->m_eventEntry->SetText("", kFALSE);
01331    m_cmsShowMainFrame->m_eventEntry->SetFocus();
01332 }
01333 
01334 void FWGUIManager::eventIdChanged()
01335 {
01336    changedEventId_.emit(m_cmsShowMainFrame->m_runEntry->GetUIntNumber(),
01337                         m_cmsShowMainFrame->m_lumiEntry->GetUIntNumber(),
01338                         m_cmsShowMainFrame->m_eventEntry->GetUIntNumber());
01339 }
01340 
01341 void
01342 FWGUIManager::finishUpColorChange()
01343 {
01344    if (m_commonPopup) m_commonPopup->colorSetChanged();
01345    if (m_modelPopup)  m_modelPopup->colorSetChanged();
01346    if (m_ediFrame)    m_ediFrame->colorSetChanged();
01347 
01348    gEve->FullRedraw3D();
01349 }
01350 //______________________________________________________________________________
01351 
01352 void
01353 FWGUIManager::showEventFilterGUI()
01354 {
01355    showEventFilterGUI_.emit(m_cmsShowMainFrame);
01356 }
01357 
01358 void
01359 FWGUIManager::filterButtonClicked()
01360 {
01361    filterButtonClicked_.emit();
01362 }
01363 
01364 void
01365 FWGUIManager::setFilterButtonText(const char* txt)
01366 {
01367    m_cmsShowMainFrame->m_filterShowGUIBtn->SetText(txt);
01368 }
01369 
01370 void
01371 FWGUIManager::setFilterButtonIcon(int state)
01372 {
01373    int i = state*3;
01374    m_cmsShowMainFrame->m_filterEnableBtn->setIcons(m_cmsShowMainFrame->m_filterIcons[i],
01375                                                    m_cmsShowMainFrame->m_filterIcons[i+1],
01376                                                    m_cmsShowMainFrame->m_filterIcons[i+2]);
01377 }
01378 
01379 void
01380 FWGUIManager::updateEventFilterEnable(bool btnEnabled)
01381 {
01382    m_cmsShowMainFrame->m_filterEnableBtn->SetEnabled(btnEnabled);
01383 }
01384 
01385 void
01386 FWGUIManager::measureWMOffsets()
01387 {
01388   const Int_t x = 100, y = 100;
01389 
01390   TGMainFrame *mf1 = new TGMainFrame(0, 0, 0);
01391   mf1->MapWindow();
01392   mf1->Move(x, y);
01393 
01394   // This seems to be the only reliable way to make sure Move() has been processed.
01395   {
01396     TGMainFrame *mf2 = new TGMainFrame(0, 0, 0);
01397     mf2->MapWindow();
01398     while (!mf2->IsMapped()) gClient->HandleInput();
01399     delete mf2;
01400   }
01401   {
01402     Int_t    xm, ym;
01403     Window_t childdum;
01404     WindowAttributes_t attr;
01405     gVirtualX->TranslateCoordinates(mf1->GetId(), gClient->GetDefaultRoot()->GetId(),
01406                                     0, 0, xm, ym, childdum);
01407     gVirtualX->GetWindowAttributes(mf1->GetId(), attr);
01408     m_WMOffsetX = x - xm;
01409     m_WMOffsetY = y - ym;
01410     m_WMDecorH  = attr.fY;
01411     fwLog(fwlog::kDebug) << Form("FWGUIManager::measureWMOffsets: required (%d,%d), measured(%d, %d) => dx=%d, dy=%d; decor_h=%d.\n",
01412                                  x, y, xm, ym, m_WMOffsetX, m_WMOffsetY, m_WMDecorH);
01413   }
01414   delete mf1;
01415 }
01416 
01417 void
01418 FWGUIManager::resetWMOffsets()
01419 {
01420    m_WMOffsetX = m_WMOffsetY = m_WMDecorH = 0;
01421 }