CMS 3D CMS Logo

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