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 <functional>
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 }
CmsShowViewPopup::~CmsShowViewPopup
~CmsShowViewPopup() override
Definition: CmsShowViewPopup.cc:99
CmsShowViewPopup::reset
void reset(FWViewBase *, TEveWindow *ew)
Definition: CmsShowViewPopup.cc:101
CmsShowViewPopup::m_saveImageButton
TGTextButton * m_saveImageButton
Definition: CmsShowViewPopup.h:117
ViewerParameterGUI::addFrameToContainer
void addFrameToContainer(TGCompositeFrame *)
Definition: CmsShowViewPopup.cc:245
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
ViewerParameterGUI
Definition: CmsShowViewPopup.h:49
FWViewBase::typeName
const std::string & typeName() const
Definition: FWViewBase.cc:107
CmsShowViewPopup::m_mapped
bool m_mapped
Definition: CmsShowViewPopup.h:113
CmsShowViewPopup::m_viewBase
FWViewBase * m_viewBase
Definition: CmsShowViewPopup.h:121
FWColorManager::colorsHaveChanged_
sigc::signal< void > colorsHaveChanged_
Definition: FWColorManager.h:101
FWParameterBase
Definition: FWParameterBase.h:31
cms::cuda::assert
assert(be >=bs)
ViewerParameterGUI::ViewerParameterGUI
ViewerParameterGUI(const TGFrame *)
Definition: CmsShowViewPopup.cc:170
CmsShowViewPopup::MapWindow
void MapWindow() override
Definition: CmsShowViewPopup.cc:139
CmsShowViewPopup::m_viewLabel
TGLabel * m_viewLabel
Definition: CmsShowViewPopup.h:115
FWColorManager::backgroundColorIndex
BackgroundColorIndex backgroundColorIndex() const
Definition: FWColorManager.cc:260
DDAxes::x
ViewerParameterGUI::m_selectedTabName
std::string m_selectedTabName
Definition: CmsShowViewPopup.h:65
CmsShowViewPopup::backgroundColorWasChanged
void backgroundColorWasChanged()
Definition: CmsShowViewPopup.cc:160
FWViewBase::typeId
FWViewType::EType typeId() const
Definition: FWViewBase.h:42
alignCSCRings.s
s
Definition: alignCSCRings.py:92
CmsShowViewPopup::CloseWindow
void CloseWindow() override
Definition: CmsShowViewPopup.cc:134
ViewerParameterGUI::separator
ViewerParameterGUI & separator()
Definition: CmsShowViewPopup.cc:232
CmsShowViewPopup::m_paramGUI
ViewerParameterGUI * m_paramGUI
Definition: CmsShowViewPopup.h:116
FWColorManager.h
w
const double w
Definition: UKUtility.cc:23
ViewerParameterGUI::m_tab
TGTab * m_tab
Definition: CmsShowViewPopup.h:64
CmsShowViewPopup::m_eveWindow
TEveWindow * m_eveWindow
Definition: CmsShowViewPopup.h:122
ViewerParameterGUI::reset
void reset()
Definition: CmsShowViewPopup.cc:175
h
FWDialogBuilder.h
CmsShowViewPopup::UnmapWindow
void UnmapWindow() override
Definition: CmsShowViewPopup.cc:144
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
ViewerParameterGUI::getTabContainer
TGCompositeFrame * getTabContainer()
Definition: CmsShowViewPopup.cc:240
FWViewBase::populateController
virtual void populateController(ViewerParameterGUI &) const
Definition: FWViewBase.h:49
FWParameterSetterBase.h
FWColorManager
Definition: FWColorManager.h:45
FWParameterSetterBase::makeSetterFor
static std::shared_ptr< FWParameterSetterBase > makeSetterFor(FWParameterBase *)
Definition: FWParameterSetterBase.cc:83
CmsShowViewPopup::closed_
sigc::signal< void > closed_
Definition: CmsShowViewPopup.h:102
FWColorManager::setBackgroundColorIndex
void setBackgroundColorIndex(BackgroundColorIndex)
Definition: FWColorManager.cc:206
FWColorManager::kWhiteIndex
Definition: FWColorManager.h:73
ViewerParameterGUI::m_setters
std::vector< std::shared_ptr< FWParameterSetterBase > > m_setters
Definition: CmsShowViewPopup.h:67
FWViewBase.h
ViewerParameterGUI::populateComplete
void populateComplete()
Definition: CmsShowViewPopup.cc:256
CmsShowViewPopup::saveImage
void saveImage()
Definition: CmsShowViewPopup.cc:149
genVertex_cff.x
x
Definition: genVertex_cff.py:13
CmsShowViewPopup.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
FWColorManager::kBlackIndex
Definition: FWColorManager.h:73
FWViewBase::promptForSaveImageTo
void promptForSaveImageTo(TGFrame *) const
Definition: FWViewBase.cc:62
FWViewBase
Definition: FWViewBase.h:36
CmsShowViewPopup::changeBackground
void changeBackground()
Definition: CmsShowViewPopup.cc:154
CmsShowViewPopup::m_changeBackground
TGTextButton * m_changeBackground
Definition: CmsShowViewPopup.h:118
CmsShowViewPopup::CmsShowViewPopup
CmsShowViewPopup(const TGWindow *p=nullptr, UInt_t w=200, UInt_t h=200, FWColorManager *cm=nullptr, FWViewBase *wb=nullptr, TEveWindow *ew=nullptr)
Definition: CmsShowViewPopup.cc:43
class-composition.parent
parent
Definition: class-composition.py:98
ViewerParameterGUI::addParam
ViewerParameterGUI & addParam(const FWParameterBase *)
Definition: CmsShowViewPopup.cc:212
CmsShowViewPopup::m_colorManager
FWColorManager * m_colorManager
Definition: CmsShowViewPopup.h:120
ViewerParameterGUI::requestTab
ViewerParameterGUI & requestTab(const char *)
Definition: CmsShowViewPopup.cc:197
FWViewType::kTable
Definition: FWViewType.h:39