CMS 3D CMS Logo

CMSSW_4_4_3_patch1/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.30 2011/09/07 20:21:19 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       m_saveImageButton->SetEnabled(kTRUE);
00115       m_viewLabel->SetText(m_viewBase->typeName().c_str());
00116       m_viewBase->populateController(*m_paramGUI);
00117       m_paramGUI->populateComplete();
00118 
00119       fMain = m_eveWindow->GetEveFrame();
00120    }
00121    else {
00122       fMain = 0;
00123       m_viewLabel->SetText("No view selected");
00124       m_saveImageButton->SetEnabled(kFALSE);
00125    }
00126 
00127    MapSubwindows();
00128    Resize(GetDefaultSize());
00129    Layout();
00130    if (fMain)
00131    {
00132       CenterOnParent(kTRUE, TGTransientFrame::kTopRight);
00133    }
00134 }
00135 
00136 void
00137 CmsShowViewPopup::CloseWindow()
00138 {
00139    UnmapWindow();
00140    closed_.emit();
00141 }
00142 
00143 void
00144 CmsShowViewPopup::MapWindow()
00145 {
00146    TGWindow::MapWindow();
00147    m_mapped = true;
00148 }
00149 
00150 void
00151 CmsShowViewPopup::UnmapWindow()
00152 {
00153    TGWindow::UnmapWindow();
00154    m_mapped = false;
00155 }
00156 
00157 void
00158 CmsShowViewPopup::saveImage()
00159 {
00160    if(m_viewBase)
00161       m_viewBase->promptForSaveImageTo(this);
00162 }
00163 
00164 void
00165 CmsShowViewPopup::changeBackground()
00166 {
00167    m_colorManager->setBackgroundColorIndex( FWColorManager::kBlackIndex == m_colorManager->backgroundColorIndex()?
00168                                             FWColorManager::kWhiteIndex:
00169                                             FWColorManager::kBlackIndex);
00170 }
00171 
00172 void
00173 CmsShowViewPopup::backgroundColorWasChanged()
00174 {
00175    if(FWColorManager::kBlackIndex == m_colorManager->backgroundColorIndex()) {
00176       m_changeBackground->SetText("Change Background Color to White");
00177    } else {
00178       m_changeBackground->SetText("Change Background Color to Black");
00179    }
00180 }
00181 
00182 //==============================================================================
00183 
00184 ViewerParameterGUI::ViewerParameterGUI(const TGFrame* p):
00185    TGCompositeFrame(p),
00186    m_tab(0),
00187    m_selectedTabName("Style")
00188 {
00189    SetCleanup(kDeepCleanup);
00190 }
00191 
00192 void
00193 ViewerParameterGUI::reset()
00194 {  
00195    // remember selected tab
00196    if (m_tab) 
00197       m_selectedTabName =  m_tab->GetCurrentTab()->GetString();
00198    else
00199       m_selectedTabName = "Style";
00200 
00201    // remove TGTab as the only child
00202    m_setters.clear();
00203    if (m_tab)
00204    {
00205       assert( GetList()->GetSize() == 1);
00206       TGFrameElement *el = (TGFrameElement*) GetList()->First();
00207       TGFrame* f = el->fFrame;
00208 
00209       assert (f == m_tab);
00210       f->UnmapWindow();
00211       RemoveFrame(f);
00212       f->DestroyWindow();
00213       m_tab = 0;
00214    }
00215 }
00216 
00217 ViewerParameterGUI&
00218 ViewerParameterGUI::requestTab(const char* name)
00219 {
00220    if (!m_tab)
00221    {
00222       m_tab = new TGTab(this);
00223       AddFrame(m_tab,  new TGLayoutHints(kLHintsExpandX |kLHintsExpandY ));
00224    }
00225 
00226    if (!m_tab->GetTabContainer(name))
00227       m_tab->AddTab(name);
00228 
00229    m_tab->SetTab(name);
00230 
00231    return *this;
00232 }
00233 
00234 /* Add parameter setter in the current tab.*/
00235 ViewerParameterGUI&
00236 ViewerParameterGUI::addParam( const FWParameterBase* param)
00237 {
00238    boost::shared_ptr<FWParameterSetterBase> ptr( FWParameterSetterBase::makeSetterFor((FWParameterBase*)param) );
00239    ptr->attach((FWParameterBase*)param, this);
00240    TGCompositeFrame* parent = m_tab->GetCurrentContainer();
00241 
00242    TGFrame* pframe = ptr->build(parent);
00243    parent->AddFrame(pframe, new TGLayoutHints(kLHintsExpandX));
00244    m_setters.push_back(ptr);
00245 
00246    pframe->MapWindow();
00247    pframe->MapSubwindows();
00248    pframe->Layout();
00249    parent->MapSubwindows();
00250    parent->Layout();
00251    m_tab->Layout();
00252    parent->Resize(parent->GetDefaultSize());
00253    return *this;
00254 }
00255    
00256 
00257 
00258 /* Add separator in current tab. */
00259 ViewerParameterGUI&
00260 ViewerParameterGUI::separator()
00261 {
00262    assert(m_tab);
00263    TGHorizontal3DLine* s = new TGHorizontal3DLine(m_tab->GetCurrentContainer());
00264    m_tab->GetCurrentContainer()->AddFrame(s, new TGLayoutHints(kLHintsExpandX,4 ,4, 2, 2));
00265 
00266    return *this;
00267 }
00268 
00269 TGCompositeFrame* 
00270 ViewerParameterGUI::getTabContainer()
00271 {
00272    assert (m_tab);
00273    return m_tab->GetCurrentContainer();
00274 }
00275 
00276 void 
00277 ViewerParameterGUI::addFrameToContainer(TGCompositeFrame* x)
00278 {
00279    assert (m_tab);
00280    TGCompositeFrame* parent =  m_tab->GetCurrentContainer();
00281    parent->AddFrame(x,new TGLayoutHints(kLHintsExpandX,4 ,4, 2, 2) );
00282 
00283    parent->MapSubwindows();
00284    parent->Layout();
00285    m_tab->Layout();
00286    parent->Resize(parent->GetDefaultSize());
00287 }
00288 
00289 void
00290 ViewerParameterGUI::populateComplete()
00291 {
00292    // Set tab - same as it was before, if not exisiting select first time.
00293    if (m_tab) 
00294    {
00295       bool x = m_tab->SetTab(m_selectedTabName.c_str(), false);
00296       if (!x) m_tab->SetTab("Style");
00297    }
00298 }
00299