CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Fireworks/Core/src/CmsShowViewPopup.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     CmsShowViewPopup
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:
00010 //         Created:  Wed Jun 25 15:15:04 EDT 2008
00011 // $Id: CmsShowViewPopup.cc,v 1.35 2013/04/24 20:55:45 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 #include <iostream>
00016 #include <boost/bind.hpp>
00017 #include <cassert>
00018 #include "TGLabel.h"
00019 #include "TGButton.h"
00020 #include "TG3DLine.h"
00021 #include "TGFrame.h"
00022 #include "TGTab.h"
00023 #include "TG3DLine.h"
00024 #include "TEveWindow.h"
00025 
00026 // user include files
00027 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
00028 #include "Fireworks/Core/interface/FWViewBase.h"
00029 #include "Fireworks/Core/interface/FWParameterSetterBase.h"
00030 #include "Fireworks/Core/src/FWDialogBuilder.h"
00031 #include "Fireworks/Core/interface/FWColorManager.h"
00032 
00033 
00034 //
00035 // constants, enums and typedefs
00036 //
00037 
00038 //
00039 // static data member definitions
00040 //
00041 
00042 //
00043 // constructors and destructor
00044 //
00045 CmsShowViewPopup::CmsShowViewPopup(const TGWindow* p, UInt_t w, UInt_t h, FWColorManager* iCMgr, FWViewBase* vb, TEveWindow* ew) :
00046    TGTransientFrame(gClient->GetDefaultRoot(),p, w, h),
00047    m_mapped(kFALSE),
00048    m_viewLabel(0),
00049    m_paramGUI(0),
00050    m_saveImageButton(0),
00051    m_changeBackground(0),
00052    m_colorManager(iCMgr),
00053    m_viewBase(0),
00054    m_eveWindow(0)
00055 {
00056    m_colorManager->colorsHaveChanged_.connect(boost::bind(&CmsShowViewPopup::backgroundColorWasChanged,this));
00057 
00058    SetCleanup(kDeepCleanup);
00059 
00060    // label
00061    TGHorizontalFrame* viewFrame = new TGHorizontalFrame(this);
00062    m_viewLabel = new TGLabel(viewFrame, "No view selected");
00063    try
00064    {
00065       TGFont* defaultFont = gClient->GetFontPool()->GetFont(m_viewLabel->GetDefaultFontStruct());
00066       m_viewLabel->SetTextFont(gClient->GetFontPool()->GetFont(defaultFont->GetFontAttributes().fFamily, 14, defaultFont->GetFontAttributes().fWeight + 2, defaultFont->GetFontAttributes().fSlant));
00067    }
00068    catch(...)
00069    {
00070       // FIXME: looks like under certain conditions (e.g. in full framework)
00071       // GetFontPool() throws when the default font is not found. This is a
00072       // quick workaround, but we should probably investigate more.
00073    }
00074 
00075    m_viewLabel->SetTextJustify(kTextLeft);
00076    viewFrame->AddFrame(m_viewLabel, new TGLayoutHints(kLHintsExpandX));
00077    AddFrame(viewFrame, new TGLayoutHints(kLHintsExpandX, 2, 2, 0, 0));
00078    // background
00079    m_changeBackground = new TGTextButton(this,"Change Background Color");
00080    backgroundColorWasChanged();
00081    AddFrame(m_changeBackground, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 5));
00082    m_changeBackground->Connect("Clicked()","CmsShowViewPopup",this,"changeBackground()");
00083    // save image
00084    m_saveImageButton= new TGTextButton(this,"Save Image ...");
00085    AddFrame(m_saveImageButton, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 5));
00086    m_saveImageButton->Connect("Clicked()","CmsShowViewPopup",this,"saveImage()");
00087 
00088   // content frame
00089    AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsExpandX, 0, 0, 5, 5));
00090    m_paramGUI = new ViewerParameterGUI(this);
00091    AddFrame(m_paramGUI,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY));
00092 
00093    SetWindowName("View Controller");
00094 }
00095 
00096 // CmsShowViewPopup::CmsShowViewPopup(const CmsShowViewPopup& rhs)
00097 // {
00098 //    // do actual copying here;
00099 // }
00100 
00101 CmsShowViewPopup::~CmsShowViewPopup()
00102 {
00103 }
00104 
00105 void
00106 CmsShowViewPopup::reset(FWViewBase* vb, TEveWindow* ew)
00107 {
00108    m_viewBase = vb;
00109    m_eveWindow = ew;
00110 
00111    m_paramGUI->reset();
00112 
00113    // fill content
00114    if (m_viewBase)
00115    {
00116       m_saveImageButton->SetEnabled(kTRUE);
00117       m_viewLabel->SetText(m_viewBase->typeName().c_str());
00118       m_viewBase->populateController(*m_paramGUI);
00119       m_paramGUI->populateComplete();
00120 
00121       fMain = m_eveWindow->GetEveFrame();
00122 
00123       if (vb->typeId() >= FWViewType::kTable)
00124          m_saveImageButton->SetText("Print Text To Terminal");
00125       else
00126          m_saveImageButton->SetText("Save Image ...");
00127    }
00128    else
00129    {
00130       fMain = 0;
00131       m_viewLabel->SetText("No view selected");
00132       m_saveImageButton->SetEnabled(kFALSE);
00133    }
00134 
00135    MapSubwindows();
00136    Resize(GetDefaultSize());
00137    Layout();
00138    if (fMain)
00139    {
00140       CenterOnParent(kTRUE, TGTransientFrame::kTopRight);
00141    }
00142 
00143   
00144 
00145 }
00146 
00147 void
00148 CmsShowViewPopup::CloseWindow()
00149 {
00150    UnmapWindow();
00151    closed_.emit();
00152 }
00153 
00154 void
00155 CmsShowViewPopup::MapWindow()
00156 {
00157    TGWindow::MapWindow();
00158    m_mapped = true;
00159 }
00160 
00161 void
00162 CmsShowViewPopup::UnmapWindow()
00163 {
00164    TGWindow::UnmapWindow();
00165    m_mapped = false;
00166 }
00167 
00168 void
00169 CmsShowViewPopup::saveImage()
00170 {
00171    if (m_viewBase)
00172       m_viewBase->promptForSaveImageTo(this);
00173 }
00174 
00175 void
00176 CmsShowViewPopup::changeBackground()
00177 {
00178    m_colorManager->setBackgroundColorIndex( FWColorManager::kBlackIndex == m_colorManager->backgroundColorIndex()?
00179                                             FWColorManager::kWhiteIndex:
00180                                             FWColorManager::kBlackIndex);
00181 }
00182 
00183 void
00184 CmsShowViewPopup::backgroundColorWasChanged()
00185 {
00186    if (FWColorManager::kBlackIndex == m_colorManager->backgroundColorIndex()) {
00187       m_changeBackground->SetText("Change Background Color to White");
00188    } else {
00189       m_changeBackground->SetText("Change Background Color to Black");
00190    }
00191 }
00192 
00193 //==============================================================================
00194 
00195 ViewerParameterGUI::ViewerParameterGUI(const TGFrame* p):
00196    TGCompositeFrame(p),
00197    m_tab(0),
00198    m_selectedTabName("Style")
00199 {
00200    SetCleanup(kDeepCleanup);
00201 }
00202 
00203 void
00204 ViewerParameterGUI::reset()
00205 {  
00206    // remember selected tab
00207    if (m_tab) 
00208       m_selectedTabName =  m_tab->GetCurrentTab()->GetString();
00209    else
00210       m_selectedTabName = "Style";
00211 
00212    // remove TGTab as the only child
00213    m_setters.clear();
00214    if (m_tab)
00215    {
00216       assert(GetList()->GetSize() == 1);
00217       TGFrameElement *el = (TGFrameElement*) GetList()->First();
00218       TGFrame* f = el->fFrame;
00219 
00220       assert (f == m_tab);
00221       f->UnmapWindow();
00222       RemoveFrame(f);
00223       f->DeleteWindow();
00224       m_tab = 0;
00225    }
00226 }
00227 
00228 ViewerParameterGUI&
00229 ViewerParameterGUI::requestTab(const char* name)
00230 {
00231    if (!m_tab)
00232    {
00233       m_tab = new TGTab(this);
00234       AddFrame(m_tab,  new TGLayoutHints(kLHintsExpandX |kLHintsExpandY ));
00235    }
00236 
00237    if (!m_tab->GetTabContainer(name))
00238       m_tab->AddTab(name);
00239 
00240    m_tab->SetTab(name);
00241 
00242    return *this;
00243 }
00244 
00245 /* Add parameter setter in the current tab.*/
00246 ViewerParameterGUI&
00247 ViewerParameterGUI::addParam( const FWParameterBase* param)
00248 {
00249    boost::shared_ptr<FWParameterSetterBase> ptr( FWParameterSetterBase::makeSetterFor((FWParameterBase*)param) );
00250    ptr->attach((FWParameterBase*)param, this);
00251    TGCompositeFrame* parent = m_tab->GetCurrentContainer();
00252 
00253    TGFrame* pframe = ptr->build(parent);
00254    parent->AddFrame(pframe, new TGLayoutHints(kLHintsExpandX));
00255    m_setters.push_back(ptr);
00256 
00257    pframe->MapWindow();
00258    pframe->MapSubwindows();
00259    pframe->Layout();
00260    parent->MapSubwindows();
00261    parent->Layout();
00262    m_tab->Layout();
00263    parent->Resize(parent->GetDefaultSize());
00264    return *this;
00265 }
00266    
00267 
00268 
00269 /* Add separator in current tab. */
00270 ViewerParameterGUI&
00271 ViewerParameterGUI::separator()
00272 {
00273    assert(m_tab);
00274    TGHorizontal3DLine* s = new TGHorizontal3DLine(m_tab->GetCurrentContainer());
00275    m_tab->GetCurrentContainer()->AddFrame(s, new TGLayoutHints(kLHintsExpandX,4 ,4, 2, 2));
00276 
00277    return *this;
00278 }
00279 
00280 TGCompositeFrame* 
00281 ViewerParameterGUI::getTabContainer()
00282 {
00283    assert (m_tab);
00284    return m_tab->GetCurrentContainer();
00285 }
00286 
00287 void 
00288 ViewerParameterGUI::addFrameToContainer(TGCompositeFrame* x)
00289 {
00290    assert (m_tab);
00291    TGCompositeFrame* parent =  m_tab->GetCurrentContainer();
00292    parent->AddFrame(x,new TGLayoutHints(kLHintsExpandX,4 ,4, 2, 2) );
00293 
00294    parent->MapSubwindows();
00295    parent->Layout();
00296    m_tab->Layout();
00297    parent->Resize(parent->GetDefaultSize());
00298 }
00299 
00300 void
00301 ViewerParameterGUI::populateComplete()
00302 {
00303    // Set tab - same as it was before, if not exisiting select first time.
00304    if (m_tab) 
00305    {
00306       bool x = m_tab->SetTab(m_selectedTabName.c_str(), false);
00307       if (!x) m_tab->SetTab("Style");
00308    }
00309 }