CMS 3D CMS Logo

FWGUISubviewArea.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWGUISubviewArea
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Fri Feb 15 14:13:33 EST 2008
11 //
12 
13 // system include files
14 #include <cassert>
15 #include <stdexcept>
16 #include <iostream>
17 
18 #include "TSystem.h"
19 #include "TGButton.h"
20 #include "TEveWindow.h"
21 
26 
27 //==============================================================================
28 // Workaround around bloody squeaking TGPictureButton.
29 // Want to get signal when pressed and released.
30 // This is needed for "info" button which "stays down".
31 //------------------------------------------------------------------------------
32 namespace {
33  class XXXButton : public TGPictureButton {
34  Int_t fXState;
35 
36  public:
37  XXXButton(const TGWindow* p, const TGPicture* pic) : TGPictureButton(p, pic), fXState(kButtonUp) {}
38 
39  void SetState(EButtonState state, Bool_t emit = kFALSE) override {
40  TGPictureButton::SetState(state, kFALSE);
41  if ((fXState == kButtonUp && fState == kButtonEngaged) || (fState == kButtonUp && fXState == kButtonEngaged)) {
42  fXState = fState;
43  Clicked();
44  }
45  }
46  };
47 } // namespace
48 //==============================================================================
49 
50 //
51 // constructors and destructor
52 //
53 FWGUISubviewArea::FWGUISubviewArea(TEveCompositeFrame* ef, TGCompositeFrame* parent, Int_t height)
54  : TGHorizontalFrame(parent, 20, height),
55  m_frame(ef),
56  m_swapButton(nullptr),
57  m_undockButton(nullptr),
58  m_dockButton(nullptr),
59  m_closeButton(nullptr),
60  m_infoButton(nullptr) {
61  UInt_t lh = kLHintsNormal | kLHintsExpandX | kLHintsExpandY;
62 
63  // info
64  m_infoButton = new XXXButton(this, infoIcon());
65  m_infoButton->ChangeOptions(kRaisedFrame);
66  m_infoButton->SetDisabledPicture(infoDisabledIcon());
67  AddFrame(m_infoButton, new TGLayoutHints(lh));
68  m_infoButton->AllowStayDown(kTRUE);
69  m_infoButton->Connect("Clicked()", "FWGUISubviewArea", this, "selectButtonToggle()");
70  m_infoButton->SetToolTipText("Edit View");
71 
72  //swap
73  m_swapButton = new TGPictureButton(this, swapIcon());
74  m_swapButton->SetDisabledPicture(swapDisabledIcon());
75  m_swapButton->SetToolTipText("Swap with the first view or select window to swap with click on toolbar.");
76  m_swapButton->ChangeOptions(kRaisedFrame);
77  m_swapButton->SetHeight(height);
78  AddFrame(m_swapButton, new TGLayoutHints(lh));
79  m_swapButton->Connect("Clicked()", "FWGUISubviewArea", this, "swap()");
80 
81  // dock
82  if (dynamic_cast<const TGMainFrame*>(ef->GetParent())) {
83  m_dockButton = new TGPictureButton(this, dockIcon());
84  m_dockButton->ChangeOptions(kRaisedFrame);
85  m_dockButton->ChangeOptions(kRaisedFrame);
86  m_dockButton->SetToolTipText("Dock view");
87  m_dockButton->SetHeight(height);
88  AddFrame(m_dockButton, new TGLayoutHints(lh));
89  m_dockButton->Connect("Clicked()", "FWGUISubviewArea", this, "dock()");
90  } else {
91  // undock
92  m_undockButton = new TGPictureButton(this, undockIcon());
93  m_undockButton->ChangeOptions(kRaisedFrame);
94  m_undockButton->SetDisabledPicture(undockDisabledIcon());
95  m_undockButton->SetToolTipText("Undock view to own window");
96  m_undockButton->SetHeight(height);
97  AddFrame(m_undockButton, new TGLayoutHints(lh));
98  m_undockButton->Connect("Clicked()", "FWGUISubviewArea", this, "undock()");
99  }
100  // destroy
101  m_closeButton = new TGPictureButton(this, closeIcon());
102  m_closeButton->ChangeOptions(kRaisedFrame);
103  m_closeButton->SetToolTipText("Close view");
104  m_closeButton->SetHeight(height);
105  AddFrame(m_closeButton, new TGLayoutHints(lh));
106  m_closeButton->Connect("Clicked()", "FWGUISubviewArea", this, "destroy()");
107 
109 }
110 
112  //std::cout <<"IN dstr FWGUISubviewArea"<<std::endl;
113  m_closeButton->Disconnect("Clicked()", this, "destroy()");
114  m_infoButton->Disconnect("Clicked()", this, "selectButtonToggle()");
115 }
116 
117 //______________________________________________________________________________
118 //
119 // actions
120 //
121 
123  if (isSelected())
124  selected_(this);
125  else
126  unselected_(this);
127 }
128 
129 void FWGUISubviewArea::unselect() { m_infoButton->SetState(kButtonUp); }
130 
131 void FWGUISubviewArea::setSwapIcon(bool isOn) { m_swapButton->SetEnabled(isOn); }
132 
133 void FWGUISubviewArea::swap() { swap_(this); }
134 
136 
138  TEveWindow* ew = m_frame->GetEveWindow();
139  ew->UndockWindow();
140  TEveCompositeFrameInMainFrame* emf = dynamic_cast<TEveCompositeFrameInMainFrame*>(ew->GetEveFrame());
141  if (emf) {
142  const TGMainFrame* mf = dynamic_cast<const TGMainFrame*>(emf->GetParent());
143  if (mf)
145  }
146 }
147 
149  TGWindow* w = (TGWindow*)(m_frame->GetParent());
150  w->UnmapWindow();
151  TTimer::SingleShot(0, m_frame->ClassName(), m_frame, "MainFrameClosed()");
152 }
153 
154 //
155 // const member functions
156 //
157 bool FWGUISubviewArea::isSelected() const { return m_infoButton->IsDown(); }
158 
159 //______________________________________________________________________________
160 TEveWindow* FWGUISubviewArea::getEveWindow() { return m_frame->GetEveWindow(); }
161 
162 //______________________________________________________________________________
163 // static member functions
164 //
165 const TGPicture* FWGUISubviewArea::swapIcon() {
166  static const TGPicture* s_icon = nullptr;
167  if (nullptr == s_icon) {
168  const char* cmspath = gSystem->Getenv("CMSSW_BASE");
169  if (nullptr == cmspath) {
170  throw std::runtime_error("CMSSW_BASE environment variable not set");
171  }
172  s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "moveup.png");
173  }
174  return s_icon;
175 }
176 
178  static const TGPicture* s_icon = nullptr;
179  if (nullptr == s_icon) {
180  const char* cmspath = gSystem->Getenv("CMSSW_BASE");
181  if (nullptr == cmspath) {
182  throw std::runtime_error("CMSSW_BASE environment variable not set");
183  }
184  s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "moveup-disabled.png");
185  }
186  return s_icon;
187 }
188 
189 const TGPicture* FWGUISubviewArea::closeIcon() {
190  static const TGPicture* s_icon = nullptr;
191  if (nullptr == s_icon) {
192  const char* cmspath = gSystem->Getenv("CMSSW_BASE");
193  if (nullptr == cmspath) {
194  throw std::runtime_error("CMSSW_BASE environment variable not set");
195  }
196  s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "delete.png");
197  }
198  return s_icon;
199 }
200 
202  static const TGPicture* s_icon = nullptr;
203  if (nullptr == s_icon) {
204  const char* cmspath = gSystem->Getenv("CMSSW_BASE");
205  if (nullptr == cmspath) {
206  throw std::runtime_error("CMSSW_BASE environment variable not set");
207  }
208  s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "delete-disabled.png");
209  }
210  return s_icon;
211 }
212 
213 const TGPicture* FWGUISubviewArea::undockIcon() {
214  static const TGPicture* s_icon = nullptr;
215  if (nullptr == s_icon) {
216  const char* cmspath = gSystem->Getenv("CMSSW_BASE");
217  if (nullptr == cmspath) {
218  throw std::runtime_error("CMSSW_BASE environment variable not set");
219  }
220  s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "expand.png");
221  }
222  return s_icon;
223 }
224 
225 const TGPicture* FWGUISubviewArea::dockIcon() {
226  static const TGPicture* s_icon = nullptr;
227  if (nullptr == s_icon) {
228  const char* cmspath = gSystem->Getenv("CMSSW_BASE");
229  if (nullptr == cmspath) {
230  throw std::runtime_error("CMSSW_BASE environment variable not set");
231  }
232  s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "dock.png");
233  }
234  return s_icon;
235 }
236 
238  static const TGPicture* s_icon = nullptr;
239  if (nullptr == s_icon) {
240  const char* cmspath = gSystem->Getenv("CMSSW_BASE");
241  if (nullptr == cmspath) {
242  throw std::runtime_error("CMSSW_BASE environment variable not set");
243  }
244  s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "expand-disabled.png");
245  }
246  return s_icon;
247 }
248 
249 const TGPicture* FWGUISubviewArea::infoIcon() {
250  static const TGPicture* s_icon = nullptr;
251  if (nullptr == s_icon) {
252  const char* cmspath = gSystem->Getenv("CMSSW_BASE");
253  if (nullptr == cmspath) {
254  throw std::runtime_error("CMSSW_BASE environment variable not set");
255  }
256  s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "info.png");
257  }
258  return s_icon;
259 }
260 
262  static const TGPicture* s_icon = nullptr;
263  if (nullptr == s_icon) {
264  const char* cmspath = gSystem->Getenv("CMSSW_BASE");
265  if (nullptr == cmspath) {
266  throw std::runtime_error("CMSSW_BASE environment variable not set");
267  }
268  s_icon = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "info-disabled.png");
269  }
270  return s_icon;
271 }
272 
273 void FWGUISubviewArea::setInfoButton(bool downp) { m_infoButton->SetState(downp ? kButtonEngaged : kButtonUp, false); }
274 
276  // horizontal frame
277  TGFrameElement* el = (TGFrameElement*)w->GetEveFrame()->GetList()->First();
278  TGCompositeFrame* hf = (TGCompositeFrame*)el->fFrame;
279  // subview last in the horizontal frame
280  el = (TGFrameElement*)hf->GetList()->Last();
281  FWGUISubviewArea* ar = dynamic_cast<FWGUISubviewArea*>(el->fFrame);
282  return ar;
283 }
TGPictureButton * m_undockButton
static const TString & coreIcondir()
TEveWindow * getEveWindow()
TGPictureButton * m_dockButton
static const TGPicture * swapIcon()
static const TGPicture * undockIcon()
T w() const
static const TGPicture * swapDisabledIcon()
bool int lh
Definition: SIMDVec.h:27
static const TGPicture * infoIcon()
void setInfoButton(bool downp)
static const TGPicture * closeDisabledIcon()
sigc::signal< void(FWGUISubviewArea *)> swap_
CmsShowMainFrame * getMainFrame() const
Definition: FWGUIManager.h:197
void connectSubviewAreaSignals(FWGUISubviewArea *)
static const TGPicture * undockDisabledIcon()
bool isSelected() const
~FWGUISubviewArea() override
FWGUISubviewArea(TEveCompositeFrame *ef, TGCompositeFrame *parent, Int_t height)
static FWGUISubviewArea * getToolBarFromWindow(TEveWindow *)
static const TGPicture * infoDisabledIcon()
TGPictureButton * m_swapButton
TGPictureButton * m_closeButton
TEveCompositeFrame * m_frame
static const TGPicture * dockIcon()
static FWGUIManager * getGUIManager()
sigc::signal< void(FWGUISubviewArea *)> unselected_
sigc::signal< void(FWGUISubviewArea *)> selected_
void bindCSGActionKeys(const TGMainFrame *f) const
static const TGPicture * closeIcon()
TGPictureButton * m_infoButton
sigc::signal< void(FWGUISubviewArea *)> goingToBeDestroyed_