Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:35

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     CmsShowViewPopup
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:
0010 //         Created:  Wed Jun 25 15:15:04 EDT 2008
0011 //
0012 
0013 // system include files
0014 #include <iostream>
0015 #include <functional>
0016 #include <cassert>
0017 #include "TGLabel.h"
0018 #include "TGButton.h"
0019 #include "TG3DLine.h"
0020 #include "TGFrame.h"
0021 #include "TGTab.h"
0022 #include "TG3DLine.h"
0023 #include "TEveWindow.h"
0024 
0025 // user include files
0026 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
0027 #include "Fireworks/Core/interface/FWViewBase.h"
0028 #include "Fireworks/Core/interface/FWParameterSetterBase.h"
0029 #include "Fireworks/Core/interface/FWDialogBuilder.h"
0030 #include "Fireworks/Core/interface/FWColorManager.h"
0031 
0032 //
0033 // constants, enums and typedefs
0034 //
0035 
0036 //
0037 // static data member definitions
0038 //
0039 
0040 //
0041 // constructors and destructor
0042 //
0043 CmsShowViewPopup::CmsShowViewPopup(
0044     const TGWindow* p, UInt_t w, UInt_t h, FWColorManager* iCMgr, FWViewBase* vb, TEveWindow* ew)
0045     : TGTransientFrame(gClient->GetDefaultRoot(), p, w, h),
0046       m_mapped(kFALSE),
0047       m_viewLabel(nullptr),
0048       m_paramGUI(nullptr),
0049       m_saveImageButton(nullptr),
0050       m_changeBackground(nullptr),
0051       m_colorManager(iCMgr),
0052       m_viewBase(nullptr),
0053       m_eveWindow(nullptr) {
0054   m_colorManager->colorsHaveChanged_.connect(std::bind(&CmsShowViewPopup::backgroundColorWasChanged, this));
0055 
0056   SetCleanup(kDeepCleanup);
0057 
0058   // label
0059   TGHorizontalFrame* viewFrame = new TGHorizontalFrame(this);
0060   m_viewLabel = new TGLabel(viewFrame, "No view selected");
0061   try {
0062     TGFont* defaultFont = gClient->GetFontPool()->GetFont(m_viewLabel->GetDefaultFontStruct());
0063     m_viewLabel->SetTextFont(gClient->GetFontPool()->GetFont(defaultFont->GetFontAttributes().fFamily,
0064                                                              14,
0065                                                              defaultFont->GetFontAttributes().fWeight + 2,
0066                                                              defaultFont->GetFontAttributes().fSlant));
0067   } catch (...) {
0068     // FIXME: looks like under certain conditions (e.g. in full framework)
0069     // GetFontPool() throws when the default font is not found. This is a
0070     // quick workaround, but we should probably investigate more.
0071   }
0072 
0073   m_viewLabel->SetTextJustify(kTextLeft);
0074   viewFrame->AddFrame(m_viewLabel, new TGLayoutHints(kLHintsExpandX));
0075   AddFrame(viewFrame, new TGLayoutHints(kLHintsExpandX, 2, 2, 0, 0));
0076   // background
0077   m_changeBackground = new TGTextButton(this, "Change Background Color");
0078   backgroundColorWasChanged();
0079   AddFrame(m_changeBackground, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 5));
0080   m_changeBackground->Connect("Clicked()", "CmsShowViewPopup", this, "changeBackground()");
0081   // save image
0082   m_saveImageButton = new TGTextButton(this, "Save Image ...");
0083   AddFrame(m_saveImageButton, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 5));
0084   m_saveImageButton->Connect("Clicked()", "CmsShowViewPopup", this, "saveImage()");
0085 
0086   // content frame
0087   AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsExpandX, 0, 0, 5, 5));
0088   m_paramGUI = new ViewerParameterGUI(this);
0089   AddFrame(m_paramGUI, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
0090 
0091   SetWindowName("View Controller");
0092 }
0093 
0094 // CmsShowViewPopup::CmsShowViewPopup(const CmsShowViewPopup& rhs)
0095 // {
0096 //    // do actual copying here;
0097 // }
0098 
0099 CmsShowViewPopup::~CmsShowViewPopup() {}
0100 
0101 void CmsShowViewPopup::reset(FWViewBase* vb, TEveWindow* ew) {
0102   m_viewBase = vb;
0103   m_eveWindow = ew;
0104 
0105   m_paramGUI->reset();
0106 
0107   // fill content
0108   if (m_viewBase) {
0109     m_saveImageButton->SetEnabled(kTRUE);
0110     m_viewLabel->SetText(m_viewBase->typeName().c_str());
0111     m_viewBase->populateController(*m_paramGUI);
0112     m_paramGUI->populateComplete();
0113 
0114     fMain = m_eveWindow->GetEveFrame();
0115 
0116     if (vb->typeId() >= FWViewType::kTable)
0117       m_saveImageButton->SetText("Print Text To Terminal");
0118     else
0119       m_saveImageButton->SetText("Save Image ...");
0120   } else {
0121     fMain = nullptr;
0122     m_viewLabel->SetText("No view selected");
0123     m_saveImageButton->SetEnabled(kFALSE);
0124   }
0125 
0126   MapSubwindows();
0127   Resize(GetDefaultSize());
0128   Layout();
0129   if (fMain) {
0130     CenterOnParent(kTRUE, TGTransientFrame::kTopRight);
0131   }
0132 }
0133 
0134 void CmsShowViewPopup::CloseWindow() {
0135   UnmapWindow();
0136   closed_.emit();
0137 }
0138 
0139 void CmsShowViewPopup::MapWindow() {
0140   TGWindow::MapWindow();
0141   m_mapped = true;
0142 }
0143 
0144 void CmsShowViewPopup::UnmapWindow() {
0145   TGWindow::UnmapWindow();
0146   m_mapped = false;
0147 }
0148 
0149 void CmsShowViewPopup::saveImage() {
0150   if (m_viewBase)
0151     m_viewBase->promptForSaveImageTo(this);
0152 }
0153 
0154 void CmsShowViewPopup::changeBackground() {
0155   m_colorManager->setBackgroundColorIndex(FWColorManager::kBlackIndex == m_colorManager->backgroundColorIndex()
0156                                               ? FWColorManager::kWhiteIndex
0157                                               : FWColorManager::kBlackIndex);
0158 }
0159 
0160 void CmsShowViewPopup::backgroundColorWasChanged() {
0161   if (FWColorManager::kBlackIndex == m_colorManager->backgroundColorIndex()) {
0162     m_changeBackground->SetText("Change Background Color to White");
0163   } else {
0164     m_changeBackground->SetText("Change Background Color to Black");
0165   }
0166 }
0167 
0168 //==============================================================================
0169 
0170 ViewerParameterGUI::ViewerParameterGUI(const TGFrame* p)
0171     : TGCompositeFrame(p), m_tab(nullptr), m_selectedTabName("Style") {
0172   SetCleanup(kDeepCleanup);
0173 }
0174 
0175 void ViewerParameterGUI::reset() {
0176   // remember selected tab
0177   if (m_tab)
0178     m_selectedTabName = m_tab->GetCurrentTab()->GetString();
0179   else
0180     m_selectedTabName = "Style";
0181 
0182   // remove TGTab as the only child
0183   m_setters.clear();
0184   if (m_tab) {
0185     assert(GetList()->GetSize() == 1);
0186     TGFrameElement* el = (TGFrameElement*)GetList()->First();
0187     TGFrame* f = el->fFrame;
0188 
0189     assert(f == m_tab);
0190     f->UnmapWindow();
0191     RemoveFrame(f);
0192     f->DeleteWindow();
0193     m_tab = nullptr;
0194   }
0195 }
0196 
0197 ViewerParameterGUI& ViewerParameterGUI::requestTab(const char* name) {
0198   if (!m_tab) {
0199     m_tab = new TGTab(this);
0200     AddFrame(m_tab, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
0201   }
0202 
0203   if (!m_tab->GetTabContainer(name))
0204     m_tab->AddTab(name);
0205 
0206   m_tab->SetTab(name);
0207 
0208   return *this;
0209 }
0210 
0211 /* Add parameter setter in the current tab.*/
0212 ViewerParameterGUI& ViewerParameterGUI::addParam(const FWParameterBase* param) {
0213   std::shared_ptr<FWParameterSetterBase> ptr(FWParameterSetterBase::makeSetterFor((FWParameterBase*)param));
0214   ptr->attach((FWParameterBase*)param, this);
0215   TGCompositeFrame* parent = m_tab->GetCurrentContainer();
0216 
0217   TGFrame* pframe = ptr->build(parent);
0218   parent->AddFrame(pframe, new TGLayoutHints(kLHintsExpandX));
0219   m_setters.push_back(ptr);
0220 
0221   pframe->MapWindow();
0222   pframe->MapSubwindows();
0223   pframe->Layout();
0224   parent->MapSubwindows();
0225   parent->Layout();
0226   m_tab->Layout();
0227   parent->Resize(parent->GetDefaultSize());
0228   return *this;
0229 }
0230 
0231 /* Add separator in current tab. */
0232 ViewerParameterGUI& ViewerParameterGUI::separator() {
0233   assert(m_tab);
0234   TGHorizontal3DLine* s = new TGHorizontal3DLine(m_tab->GetCurrentContainer());
0235   m_tab->GetCurrentContainer()->AddFrame(s, new TGLayoutHints(kLHintsExpandX, 4, 4, 2, 2));
0236 
0237   return *this;
0238 }
0239 
0240 TGCompositeFrame* ViewerParameterGUI::getTabContainer() {
0241   assert(m_tab);
0242   return m_tab->GetCurrentContainer();
0243 }
0244 
0245 void ViewerParameterGUI::addFrameToContainer(TGCompositeFrame* x) {
0246   assert(m_tab);
0247   TGCompositeFrame* parent = m_tab->GetCurrentContainer();
0248   parent->AddFrame(x, new TGLayoutHints(kLHintsExpandX, 4, 4, 2, 2));
0249 
0250   parent->MapSubwindows();
0251   parent->Layout();
0252   m_tab->Layout();
0253   parent->Resize(parent->GetDefaultSize());
0254 }
0255 
0256 void ViewerParameterGUI::populateComplete() {
0257   // Set tab - same as it was before, if not exisiting select first time.
0258   if (m_tab) {
0259     bool x = m_tab->SetTab(m_selectedTabName.c_str(), false);
0260     if (!x)
0261       m_tab->SetTab("Style");
0262   }
0263 }