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