CMS 3D CMS Logo

CmsShowViewPopup.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : CmsShowViewPopup
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Wed Jun 25 15:15:04 EDT 2008
11 //
12 
13 // system include files
14 #include <iostream>
15 #include <boost/bind.hpp>
16 #include <cassert>
17 #include "TGLabel.h"
18 #include "TGButton.h"
19 #include "TG3DLine.h"
20 #include "TGFrame.h"
21 #include "TGTab.h"
22 #include "TG3DLine.h"
23 #include "TEveWindow.h"
24 
25 // user include files
31 
32 //
33 // constants, enums and typedefs
34 //
35 
36 //
37 // static data member definitions
38 //
39 
40 //
41 // constructors and destructor
42 //
44  const TGWindow* p, UInt_t w, UInt_t h, FWColorManager* iCMgr, FWViewBase* vb, TEveWindow* ew)
45  : TGTransientFrame(gClient->GetDefaultRoot(), p, w, h),
46  m_mapped(kFALSE),
47  m_viewLabel(nullptr),
48  m_paramGUI(nullptr),
49  m_saveImageButton(nullptr),
50  m_changeBackground(nullptr),
51  m_colorManager(iCMgr),
52  m_viewBase(nullptr),
53  m_eveWindow(nullptr) {
55 
56  SetCleanup(kDeepCleanup);
57 
58  // label
59  TGHorizontalFrame* viewFrame = new TGHorizontalFrame(this);
60  m_viewLabel = new TGLabel(viewFrame, "No view selected");
61  try {
62  TGFont* defaultFont = gClient->GetFontPool()->GetFont(m_viewLabel->GetDefaultFontStruct());
63  m_viewLabel->SetTextFont(gClient->GetFontPool()->GetFont(defaultFont->GetFontAttributes().fFamily,
64  14,
65  defaultFont->GetFontAttributes().fWeight + 2,
66  defaultFont->GetFontAttributes().fSlant));
67  } catch (...) {
68  // FIXME: looks like under certain conditions (e.g. in full framework)
69  // GetFontPool() throws when the default font is not found. This is a
70  // quick workaround, but we should probably investigate more.
71  }
72 
73  m_viewLabel->SetTextJustify(kTextLeft);
74  viewFrame->AddFrame(m_viewLabel, new TGLayoutHints(kLHintsExpandX));
75  AddFrame(viewFrame, new TGLayoutHints(kLHintsExpandX, 2, 2, 0, 0));
76  // background
77  m_changeBackground = new TGTextButton(this, "Change Background Color");
79  AddFrame(m_changeBackground, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 5));
80  m_changeBackground->Connect("Clicked()", "CmsShowViewPopup", this, "changeBackground()");
81  // save image
82  m_saveImageButton = new TGTextButton(this, "Save Image ...");
83  AddFrame(m_saveImageButton, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 5));
84  m_saveImageButton->Connect("Clicked()", "CmsShowViewPopup", this, "saveImage()");
85 
86  // content frame
87  AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsExpandX, 0, 0, 5, 5));
88  m_paramGUI = new ViewerParameterGUI(this);
89  AddFrame(m_paramGUI, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
90 
91  SetWindowName("View Controller");
92 }
93 
94 // CmsShowViewPopup::CmsShowViewPopup(const CmsShowViewPopup& rhs)
95 // {
96 // // do actual copying here;
97 // }
98 
100 
101 void CmsShowViewPopup::reset(FWViewBase* vb, TEveWindow* ew) {
102  m_viewBase = vb;
103  m_eveWindow = ew;
104 
105  m_paramGUI->reset();
106 
107  // fill content
108  if (m_viewBase) {
109  m_saveImageButton->SetEnabled(kTRUE);
110  m_viewLabel->SetText(m_viewBase->typeName().c_str());
113 
114  fMain = m_eveWindow->GetEveFrame();
115 
116  if (vb->typeId() >= FWViewType::kTable)
117  m_saveImageButton->SetText("Print Text To Terminal");
118  else
119  m_saveImageButton->SetText("Save Image ...");
120  } else {
121  fMain = nullptr;
122  m_viewLabel->SetText("No view selected");
123  m_saveImageButton->SetEnabled(kFALSE);
124  }
125 
126  MapSubwindows();
127  Resize(GetDefaultSize());
128  Layout();
129  if (fMain) {
130  CenterOnParent(kTRUE, TGTransientFrame::kTopRight);
131  }
132 }
133 
135  UnmapWindow();
136  closed_.emit();
137 }
138 
140  TGWindow::MapWindow();
141  m_mapped = true;
142 }
143 
145  TGWindow::UnmapWindow();
146  m_mapped = false;
147 }
148 
150  if (m_viewBase)
152 }
153 
158 }
159 
162  m_changeBackground->SetText("Change Background Color to White");
163  } else {
164  m_changeBackground->SetText("Change Background Color to Black");
165  }
166 }
167 
168 //==============================================================================
169 
171  : TGCompositeFrame(p), m_tab(nullptr), m_selectedTabName("Style") {
172  SetCleanup(kDeepCleanup);
173 }
174 
176  // remember selected tab
177  if (m_tab)
178  m_selectedTabName = m_tab->GetCurrentTab()->GetString();
179  else
180  m_selectedTabName = "Style";
181 
182  // remove TGTab as the only child
183  m_setters.clear();
184  if (m_tab) {
185  assert(GetList()->GetSize() == 1);
186  TGFrameElement* el = (TGFrameElement*)GetList()->First();
187  TGFrame* f = el->fFrame;
188 
189  assert(f == m_tab);
190  f->UnmapWindow();
191  RemoveFrame(f);
192  f->DeleteWindow();
193  m_tab = nullptr;
194  }
195 }
196 
198  if (!m_tab) {
199  m_tab = new TGTab(this);
200  AddFrame(m_tab, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
201  }
202 
203  if (!m_tab->GetTabContainer(name))
204  m_tab->AddTab(name);
205 
206  m_tab->SetTab(name);
207 
208  return *this;
209 }
210 
211 /* Add parameter setter in the current tab.*/
213  std::shared_ptr<FWParameterSetterBase> ptr(FWParameterSetterBase::makeSetterFor((FWParameterBase*)param));
214  ptr->attach((FWParameterBase*)param, this);
215  TGCompositeFrame* parent = m_tab->GetCurrentContainer();
216 
217  TGFrame* pframe = ptr->build(parent);
218  parent->AddFrame(pframe, new TGLayoutHints(kLHintsExpandX));
219  m_setters.push_back(ptr);
220 
221  pframe->MapWindow();
222  pframe->MapSubwindows();
223  pframe->Layout();
224  parent->MapSubwindows();
225  parent->Layout();
226  m_tab->Layout();
227  parent->Resize(parent->GetDefaultSize());
228  return *this;
229 }
230 
231 /* Add separator in current tab. */
233  assert(m_tab);
234  TGHorizontal3DLine* s = new TGHorizontal3DLine(m_tab->GetCurrentContainer());
235  m_tab->GetCurrentContainer()->AddFrame(s, new TGLayoutHints(kLHintsExpandX, 4, 4, 2, 2));
236 
237  return *this;
238 }
239 
241  assert(m_tab);
242  return m_tab->GetCurrentContainer();
243 }
244 
246  assert(m_tab);
247  TGCompositeFrame* parent = m_tab->GetCurrentContainer();
248  parent->AddFrame(x, new TGLayoutHints(kLHintsExpandX, 4, 4, 2, 2));
249 
250  parent->MapSubwindows();
251  parent->Layout();
252  m_tab->Layout();
253  parent->Resize(parent->GetDefaultSize());
254 }
255 
257  // Set tab - same as it was before, if not exisiting select first time.
258  if (m_tab) {
259  bool x = m_tab->SetTab(m_selectedTabName.c_str(), false);
260  if (!x)
261  m_tab->SetTab("Style");
262  }
263 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
ViewerParameterGUI(const TGFrame *)
void UnmapWindow() override
std::string m_selectedTabName
const double w
Definition: UKUtility.cc:23
sigc::signal< void > closed_
ViewerParameterGUI & requestTab(const char *)
#define nullptr
ViewerParameterGUI & separator()
const std::string & typeName() const
Definition: FWViewBase.cc:107
void addFrameToContainer(TGCompositeFrame *)
void setBackgroundColorIndex(BackgroundColorIndex)
CmsShowViewPopup(const TGWindow *p=nullptr, UInt_t w=200, UInt_t h=200, FWColorManager *cm=nullptr, FWViewBase *wb=nullptr, TEveWindow *ew=nullptr)
BackgroundColorIndex backgroundColorIndex() const
TGTextButton * m_changeBackground
TGTextButton * m_saveImageButton
void reset(FWViewBase *, TEveWindow *ew)
FWColorManager * m_colorManager
double f[11][100]
std::vector< std::shared_ptr< FWParameterSetterBase > > m_setters
~CmsShowViewPopup() override
FWViewBase * m_viewBase
ViewerParameterGUI & addParam(const FWParameterBase *)
TGCompositeFrame * getTabContainer()
static std::shared_ptr< FWParameterSetterBase > makeSetterFor(FWParameterBase *)
void MapWindow() override
void backgroundColorWasChanged()
void CloseWindow() override
virtual void populateController(ViewerParameterGUI &) const
Definition: FWViewBase.h:49
void promptForSaveImageTo(TGFrame *) const
Definition: FWViewBase.cc:62
sigc::signal< void > colorsHaveChanged_
ViewerParameterGUI * m_paramGUI
TEveWindow * m_eveWindow
FWViewType::EType typeId() const
Definition: FWViewBase.h:42