00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <iostream>
00016 #include <boost/bind.hpp>
00017 #include <cassert>
00018 #include "TGLabel.h"
00019 #include "TGButton.h"
00020 #include "TG3DLine.h"
00021 #include "TGFrame.h"
00022 #include "TGTab.h"
00023 #include "TG3DLine.h"
00024 #include "TEveWindow.h"
00025
00026
00027 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
00028 #include "Fireworks/Core/interface/FWViewBase.h"
00029 #include "Fireworks/Core/interface/FWParameterSetterBase.h"
00030 #include "Fireworks/Core/src/FWDialogBuilder.h"
00031 #include "Fireworks/Core/interface/FWColorManager.h"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 CmsShowViewPopup::CmsShowViewPopup(const TGWindow* p, UInt_t w, UInt_t h, FWColorManager* iCMgr, FWViewBase* vb, TEveWindow* ew) :
00046 TGTransientFrame(gClient->GetDefaultRoot(),p, w, h),
00047 m_mapped(kFALSE),
00048 m_viewLabel(0),
00049 m_paramGUI(0),
00050 m_saveImageButton(0),
00051 m_changeBackground(0),
00052 m_colorManager(iCMgr),
00053 m_viewBase(0),
00054 m_eveWindow(0)
00055 {
00056 m_colorManager->colorsHaveChanged_.connect(boost::bind(&CmsShowViewPopup::backgroundColorWasChanged,this));
00057
00058 SetCleanup(kDeepCleanup);
00059
00060
00061 TGHorizontalFrame* viewFrame = new TGHorizontalFrame(this);
00062 m_viewLabel = new TGLabel(viewFrame, "No view selected");
00063 try
00064 {
00065 TGFont* defaultFont = gClient->GetFontPool()->GetFont(m_viewLabel->GetDefaultFontStruct());
00066 m_viewLabel->SetTextFont(gClient->GetFontPool()->GetFont(defaultFont->GetFontAttributes().fFamily, 14, defaultFont->GetFontAttributes().fWeight + 2, defaultFont->GetFontAttributes().fSlant));
00067 }
00068 catch(...)
00069 {
00070
00071
00072
00073 }
00074
00075 m_viewLabel->SetTextJustify(kTextLeft);
00076 viewFrame->AddFrame(m_viewLabel, new TGLayoutHints(kLHintsExpandX));
00077 AddFrame(viewFrame, new TGLayoutHints(kLHintsExpandX, 2, 2, 0, 0));
00078
00079 m_changeBackground = new TGTextButton(this,"Change Background Color");
00080 backgroundColorWasChanged();
00081 AddFrame(m_changeBackground, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 5));
00082 m_changeBackground->Connect("Clicked()","CmsShowViewPopup",this,"changeBackground()");
00083
00084 m_saveImageButton= new TGTextButton(this,"Save Image ...");
00085 AddFrame(m_saveImageButton);
00086 m_saveImageButton->Connect("Clicked()","CmsShowViewPopup",this,"saveImage()");
00087
00088
00089 AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsExpandX, 0, 0, 5, 5));
00090 m_paramGUI = new ViewerParameterGUI(this);
00091 AddFrame(m_paramGUI,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY));
00092
00093 SetWindowName("View Controller");
00094 }
00095
00096
00097
00098
00099
00100
00101 CmsShowViewPopup::~CmsShowViewPopup()
00102 {
00103 }
00104
00105 void
00106 CmsShowViewPopup::reset(FWViewBase* vb, TEveWindow* ew)
00107 {
00108 m_viewBase = vb;
00109 m_eveWindow = ew;
00110
00111 m_paramGUI->reset();
00112
00113
00114 if (m_viewBase)
00115 {
00116 m_saveImageButton->SetEnabled(kTRUE);
00117 m_viewLabel->SetText(m_viewBase->typeName().c_str());
00118 m_viewBase->populateController(*m_paramGUI);
00119 m_paramGUI->populateComplete();
00120
00121 fMain = m_eveWindow->GetEveFrame();
00122 }
00123 else
00124 {
00125 fMain = 0;
00126 m_viewLabel->SetText("No view selected");
00127 m_saveImageButton->SetEnabled(kFALSE);
00128 }
00129
00130 MapSubwindows();
00131 Resize(GetDefaultSize());
00132 Layout();
00133 if (fMain)
00134 {
00135 CenterOnParent(kTRUE, TGTransientFrame::kTopRight);
00136 }
00137 }
00138
00139 void
00140 CmsShowViewPopup::CloseWindow()
00141 {
00142 UnmapWindow();
00143 closed_.emit();
00144 }
00145
00146 void
00147 CmsShowViewPopup::MapWindow()
00148 {
00149 TGWindow::MapWindow();
00150 m_mapped = true;
00151 }
00152
00153 void
00154 CmsShowViewPopup::UnmapWindow()
00155 {
00156 TGWindow::UnmapWindow();
00157 m_mapped = false;
00158 }
00159
00160 void
00161 CmsShowViewPopup::saveImage()
00162 {
00163 if (m_viewBase)
00164 m_viewBase->promptForSaveImageTo(this);
00165 }
00166
00167 void
00168 CmsShowViewPopup::changeBackground()
00169 {
00170 m_colorManager->setBackgroundColorIndex( FWColorManager::kBlackIndex == m_colorManager->backgroundColorIndex()?
00171 FWColorManager::kWhiteIndex:
00172 FWColorManager::kBlackIndex);
00173 }
00174
00175 void
00176 CmsShowViewPopup::backgroundColorWasChanged()
00177 {
00178 if (FWColorManager::kBlackIndex == m_colorManager->backgroundColorIndex()) {
00179 m_changeBackground->SetText("Change Background Color to White");
00180 } else {
00181 m_changeBackground->SetText("Change Background Color to Black");
00182 }
00183 }
00184
00185
00186
00187 ViewerParameterGUI::ViewerParameterGUI(const TGFrame* p):
00188 TGCompositeFrame(p),
00189 m_tab(0),
00190 m_selectedTabName("Style")
00191 {
00192 SetCleanup(kDeepCleanup);
00193 }
00194
00195 void
00196 ViewerParameterGUI::reset()
00197 {
00198
00199 if (m_tab)
00200 m_selectedTabName = m_tab->GetCurrentTab()->GetString();
00201 else
00202 m_selectedTabName = "Style";
00203
00204
00205 m_setters.clear();
00206 if (m_tab)
00207 {
00208 assert(GetList()->GetSize() == 1);
00209 TGFrameElement *el = (TGFrameElement*) GetList()->First();
00210 TGFrame* f = el->fFrame;
00211
00212 assert (f == m_tab);
00213 f->UnmapWindow();
00214 RemoveFrame(f);
00215 f->DeleteWindow();
00216 m_tab = 0;
00217 }
00218 }
00219
00220 ViewerParameterGUI&
00221 ViewerParameterGUI::requestTab(const char* name)
00222 {
00223 if (!m_tab)
00224 {
00225 m_tab = new TGTab(this);
00226 AddFrame(m_tab, new TGLayoutHints(kLHintsExpandX |kLHintsExpandY ));
00227 }
00228
00229 if (!m_tab->GetTabContainer(name))
00230 m_tab->AddTab(name);
00231
00232 m_tab->SetTab(name);
00233
00234 return *this;
00235 }
00236
00237
00238 ViewerParameterGUI&
00239 ViewerParameterGUI::addParam( const FWParameterBase* param)
00240 {
00241 boost::shared_ptr<FWParameterSetterBase> ptr( FWParameterSetterBase::makeSetterFor((FWParameterBase*)param) );
00242 ptr->attach((FWParameterBase*)param, this);
00243 TGCompositeFrame* parent = m_tab->GetCurrentContainer();
00244
00245 TGFrame* pframe = ptr->build(parent);
00246 parent->AddFrame(pframe, new TGLayoutHints(kLHintsExpandX));
00247 m_setters.push_back(ptr);
00248
00249 pframe->MapWindow();
00250 pframe->MapSubwindows();
00251 pframe->Layout();
00252 parent->MapSubwindows();
00253 parent->Layout();
00254 m_tab->Layout();
00255 parent->Resize(parent->GetDefaultSize());
00256 return *this;
00257 }
00258
00259
00260
00261
00262 ViewerParameterGUI&
00263 ViewerParameterGUI::separator()
00264 {
00265 assert(m_tab);
00266 TGHorizontal3DLine* s = new TGHorizontal3DLine(m_tab->GetCurrentContainer());
00267 m_tab->GetCurrentContainer()->AddFrame(s, new TGLayoutHints(kLHintsExpandX,4 ,4, 2, 2));
00268
00269 return *this;
00270 }
00271
00272 TGCompositeFrame*
00273 ViewerParameterGUI::getTabContainer()
00274 {
00275 assert (m_tab);
00276 return m_tab->GetCurrentContainer();
00277 }
00278
00279 void
00280 ViewerParameterGUI::addFrameToContainer(TGCompositeFrame* x)
00281 {
00282 assert (m_tab);
00283 TGCompositeFrame* parent = m_tab->GetCurrentContainer();
00284 parent->AddFrame(x,new TGLayoutHints(kLHintsExpandX,4 ,4, 2, 2) );
00285
00286 parent->MapSubwindows();
00287 parent->Layout();
00288 m_tab->Layout();
00289 parent->Resize(parent->GetDefaultSize());
00290 }
00291
00292 void
00293 ViewerParameterGUI::populateComplete()
00294 {
00295
00296 if (m_tab)
00297 {
00298 bool x = m_tab->SetTab(m_selectedTabName.c_str(), false);
00299 if (!x) m_tab->SetTab("Style");
00300 }
00301 }