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 //
34 // constants, enums and typedefs
35 //
36 
37 //
38 // static data member definitions
39 //
40 
41 //
42 // constructors and destructor
43 //
44 CmsShowViewPopup::CmsShowViewPopup(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)
54 {
56 
57  SetCleanup(kDeepCleanup);
58 
59  // label
60  TGHorizontalFrame* viewFrame = new TGHorizontalFrame(this);
61  m_viewLabel = new TGLabel(viewFrame, "No view selected");
62  try
63  {
64  TGFont* defaultFont = gClient->GetFontPool()->GetFont(m_viewLabel->GetDefaultFontStruct());
65  m_viewLabel->SetTextFont(gClient->GetFontPool()->GetFont(defaultFont->GetFontAttributes().fFamily, 14, defaultFont->GetFontAttributes().fWeight + 2, defaultFont->GetFontAttributes().fSlant));
66  }
67  catch(...)
68  {
69  // FIXME: looks like under certain conditions (e.g. in full framework)
70  // GetFontPool() throws when the default font is not found. This is a
71  // quick workaround, but we should probably investigate more.
72  }
73 
74  m_viewLabel->SetTextJustify(kTextLeft);
75  viewFrame->AddFrame(m_viewLabel, new TGLayoutHints(kLHintsExpandX));
76  AddFrame(viewFrame, new TGLayoutHints(kLHintsExpandX, 2, 2, 0, 0));
77  // background
78  m_changeBackground = new TGTextButton(this,"Change Background Color");
80  AddFrame(m_changeBackground, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 5));
81  m_changeBackground->Connect("Clicked()","CmsShowViewPopup",this,"changeBackground()");
82  // save image
83  m_saveImageButton= new TGTextButton(this,"Save Image ...");
84  AddFrame(m_saveImageButton, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 5));
85  m_saveImageButton->Connect("Clicked()","CmsShowViewPopup",this,"saveImage()");
86 
87  // content frame
88  AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsExpandX, 0, 0, 5, 5));
89  m_paramGUI = new ViewerParameterGUI(this);
90  AddFrame(m_paramGUI,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY));
91 
92  SetWindowName("View Controller");
93 }
94 
95 // CmsShowViewPopup::CmsShowViewPopup(const CmsShowViewPopup& rhs)
96 // {
97 // // do actual copying here;
98 // }
99 
101 {
102 }
103 
104 void
106 {
107  m_viewBase = vb;
108  m_eveWindow = ew;
109 
110  m_paramGUI->reset();
111 
112  // fill content
113  if (m_viewBase)
114  {
115  m_saveImageButton->SetEnabled(kTRUE);
116  m_viewLabel->SetText(m_viewBase->typeName().c_str());
119 
120  fMain = m_eveWindow->GetEveFrame();
121 
122  if (vb->typeId() >= FWViewType::kTable)
123  m_saveImageButton->SetText("Print Text To Terminal");
124  else
125  m_saveImageButton->SetText("Save Image ...");
126  }
127  else
128  {
129  fMain = nullptr;
130  m_viewLabel->SetText("No view selected");
131  m_saveImageButton->SetEnabled(kFALSE);
132  }
133 
134  MapSubwindows();
135  Resize(GetDefaultSize());
136  Layout();
137  if (fMain)
138  {
139  CenterOnParent(kTRUE, TGTransientFrame::kTopRight);
140  }
141 
142 
143 
144 }
145 
146 void
148 {
149  UnmapWindow();
150  closed_.emit();
151 }
152 
153 void
155 {
156  TGWindow::MapWindow();
157  m_mapped = true;
158 }
159 
160 void
162 {
163  TGWindow::UnmapWindow();
164  m_mapped = false;
165 }
166 
167 void
169 {
170  if (m_viewBase)
172 }
173 
174 void
176 {
180 }
181 
182 void
184 {
186  m_changeBackground->SetText("Change Background Color to White");
187  } else {
188  m_changeBackground->SetText("Change Background Color to Black");
189  }
190 }
191 
192 //==============================================================================
193 
195  TGCompositeFrame(p),
196  m_tab(nullptr),
197  m_selectedTabName("Style")
198 {
199  SetCleanup(kDeepCleanup);
200 }
201 
202 void
204 {
205  // remember selected tab
206  if (m_tab)
207  m_selectedTabName = m_tab->GetCurrentTab()->GetString();
208  else
209  m_selectedTabName = "Style";
210 
211  // remove TGTab as the only child
212  m_setters.clear();
213  if (m_tab)
214  {
215  assert(GetList()->GetSize() == 1);
216  TGFrameElement *el = (TGFrameElement*) GetList()->First();
217  TGFrame* f = el->fFrame;
218 
219  assert (f == m_tab);
220  f->UnmapWindow();
221  RemoveFrame(f);
222  f->DeleteWindow();
223  m_tab = nullptr;
224  }
225 }
226 
229 {
230  if (!m_tab)
231  {
232  m_tab = new TGTab(this);
233  AddFrame(m_tab, new TGLayoutHints(kLHintsExpandX |kLHintsExpandY ));
234  }
235 
236  if (!m_tab->GetTabContainer(name))
237  m_tab->AddTab(name);
238 
239  m_tab->SetTab(name);
240 
241  return *this;
242 }
243 
244 /* Add parameter setter in the current tab.*/
247 {
248  std::shared_ptr<FWParameterSetterBase> ptr( FWParameterSetterBase::makeSetterFor((FWParameterBase*)param) );
249  ptr->attach((FWParameterBase*)param, this);
250  TGCompositeFrame* parent = m_tab->GetCurrentContainer();
251 
252  TGFrame* pframe = ptr->build(parent);
253  parent->AddFrame(pframe, new TGLayoutHints(kLHintsExpandX));
254  m_setters.push_back(ptr);
255 
256  pframe->MapWindow();
257  pframe->MapSubwindows();
258  pframe->Layout();
259  parent->MapSubwindows();
260  parent->Layout();
261  m_tab->Layout();
262  parent->Resize(parent->GetDefaultSize());
263  return *this;
264 }
265 
266 
267 
268 /* Add separator in current tab. */
271 {
272  assert(m_tab);
273  TGHorizontal3DLine* s = new TGHorizontal3DLine(m_tab->GetCurrentContainer());
274  m_tab->GetCurrentContainer()->AddFrame(s, new TGLayoutHints(kLHintsExpandX,4 ,4, 2, 2));
275 
276  return *this;
277 }
278 
279 TGCompositeFrame*
281 {
282  assert (m_tab);
283  return m_tab->GetCurrentContainer();
284 }
285 
286 void
288 {
289  assert (m_tab);
290  TGCompositeFrame* parent = m_tab->GetCurrentContainer();
291  parent->AddFrame(x,new TGLayoutHints(kLHintsExpandX,4 ,4, 2, 2) );
292 
293  parent->MapSubwindows();
294  parent->Layout();
295  m_tab->Layout();
296  parent->Resize(parent->GetDefaultSize());
297 }
298 
299 void
301 {
302  // Set tab - same as it was before, if not exisiting select first time.
303  if (m_tab)
304  {
305  bool x = m_tab->SetTab(m_selectedTabName.c_str(), false);
306  if (!x) m_tab->SetTab("Style");
307  }
308 }
ViewerParameterGUI(const TGFrame *)
void UnmapWindow() override
std::string m_selectedTabName
const double w
Definition: UKUtility.cc:23
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
sigc::signal< void > closed_
ViewerParameterGUI & requestTab(const char *)
ViewerParameterGUI & separator()
const std::string & typeName() const
Definition: FWViewBase.cc:120
void addFrameToContainer(TGCompositeFrame *)
#define nullptr
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:50
void promptForSaveImageTo(TGFrame *) const
Definition: FWViewBase.cc:73
sigc::signal< void > colorsHaveChanged_
ViewerParameterGUI * m_paramGUI
TEveWindow * m_eveWindow
FWViewType::EType typeId() const
Definition: FWViewBase.h:43