001 #include "MainFrame.h"
002
003 #include "TileCalibCentral/IHandlerManager.h"
004 #include "TileCalibCentral/IMainContext.h"
005 #include "TileCalibCentral/IIOVDbConnection.h"
006
007 #include "TileCalibViewPlugin/ViewState.h"
008 #include "TileCalibViewPlugin/IViewManager.h"
009 #include "TileCalibViewPlugin/IView.h"
010
011 #include "SelectionTreeFrame.h"
012
013 #include "TileCalibGUIPlugin/ViewTab.h"
014
015
016 #include "TileCalibGUIPlugin/GButton.h"
017 #include "TileCalibGUIPlugin/GDialog.h"
018 #include "TileCalibGUIPlugin/GPopupMenu.h"
019 #include "TileCalibGUIPlugin/GTabPane.h"
020 #include "TileCalibGUIPlugin/GButton.h"
021
022 #include <TGClient.h>
023 #include <TGButton.h>
024 #include <TGSplitter.h>
025 #include <TGCanvas.h>
026 #include <TGListTree.h>
027 #include <TApplication.h>
028 #include <TGClient.h>
029 #include <TG3DLine.h>
030 #include <TGToolBar.h>
031 #include <TGPicture.h>
032 #include <TGResourcePool.h>
033 #include <TGMenu.h>
034 #include <TGTab.h>
035 #include <TGFileDialog.h>
036
037 #include <iostream>
038 #include <sstream>
039 #include <vector>
040
041 using namespace tilec;
042 using namespace tilec::view;
043 using namespace tilec::gui;
044 using namespace tilec::handler;
045
046 MainFrame::MainFrame(IMainContext *context,
047 const TGWindow *p,
048 UInt_t w, UInt_t h)
049 : AbstractComponent("MainFrame","MainFrame",context),TGMainFrame(p, w, h),m_context(context) {
050 setClassName<MainFrame>();
051 addInterface<IExecutable>();
052
053 GComponent::setDefaultParent(this);
054 GComponent::setDefaultClient(fClient ? fClient : gClient);
055 GComponent::initDefaults();
056
057 gVirtualX->SetDoubleBuffer(999,1);
058 m_handlerManager = (IHandlerManager*)context->getManager("Handler");
059
060 TGGC &menuTitleDef(const_cast<TGGC&>(TGMenuTitle::GetDefaultGC()));
061 TGGC &menuTitleSel(const_cast<TGGC&>(TGMenuTitle::GetDefaultSelectedGC()));
062 menuTitleSel.SetBackground(GComponent::getDefaultBackground());
063 menuTitleDef.SetBackground(GComponent::getDefaultBackground());
064
065 TGGC &frameShadowGC(const_cast<TGGC&>(TGFrame::GetShadowGC()));
066 frameShadowGC.SetBackground(GComponent::getDefaultBackground());
067 TGGC &frameBgGC(const_cast<TGGC&>(TGFrame::GetBckgndGC()));
068 frameBgGC.SetBackground(GComponent::getDefaultBackground());
069
070 SetBackgroundColor(GComponent::getDefaultBackground());
071 std::string title("TileC "+g_main->getProperty("version"));
072 SetWindowName(title.c_str());
073 SetIconName(title.c_str());
074
075
076 m_fileMenu = new TGPopupMenu(p);
077 m_fileMenu->SetBackgroundColor(GComponent::getDefaultBackground());
078 m_fileMenu->ChangeOptions(kRaisedFrame);
079
080 m_helpMenu = new TGPopupMenu(p);
081 m_fileMenu->SetBackgroundColor(GComponent::getDefaultBackground());
082 m_fileMenu->ChangeOptions(kRaisedFrame);
083
084
085 m_fileMenu->Associate(this);
086 m_helpMenu->Associate(this);
087
088
089 m_menuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1);
090 m_menuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
091 m_menuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
092
093
094
095 TGLayoutHints *toolLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 0, 2, 2);
096 m_toolBar = new TGToolBar(this, 60, 20, kHorizontalFrame);
097 m_toolBar->SetBackgroundColor(GComponent::getDefaultBackground());
098
099 m_backButton = new GButton(m_toolBar,"back","TileCalibGUIPlugin/back.png");
100 m_backButton->setToolTip("Navigate back");
101 m_backButton->addActionListener(this);
102 m_toolBar->AddFrame(m_backButton,toolLayout);
103
104 m_forwardButton = new GButton(m_toolBar,"forward","TileCalibGUIPlugin/forward.png");
105 m_forwardButton->setToolTip("Navigate forward");
106 m_forwardButton->addActionListener(this);
107 m_toolBar->AddFrame(m_forwardButton,toolLayout);
108
109 m_saveButton = new GButton(m_toolBar,"save","TileCalibGUIPlugin/filesave.png","Save");
110 m_saveButton->setToolTip("Save");
111 m_saveButton->addActionListener(this);
112 m_toolBar->AddFrame(m_saveButton,toolLayout);
113
114 m_fileImportButton = new GButton(m_toolBar,"import","TileCalibGUIPlugin/fileimport.png","Import");
115 m_fileImportButton->setToolTip("Import");
116 m_fileImportButton->addActionListener(this);
117 m_toolBar->AddFrame(m_fileImportButton,toolLayout);
118
119 m_printButton = new GButton(m_toolBar,"print","TileCalibGUIPlugin/fileprint.png","Print");
120 m_printButton->setToolTip("Print");
121 m_printButton->addActionListener(this);
122 m_toolBar->AddFrame(m_printButton,toolLayout);
123
124 m_configButton = new GButton(m_toolBar,"config","TileCalibGUIPlugin/configure.png","Tools");
125 m_configButton->setToolTip("Configure");
126 m_configButton->addActionListener(this);
127 m_toolBar->AddFrame(m_configButton,toolLayout);
128
129 m_toolBarLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX);
130 m_menuSep = new TGHorizontal3DLine(this);
131 m_toolSep = new TGHorizontal3DLine(this);
132 AddFrame(m_menuSep, m_toolBarLayout);
133 AddFrame(m_toolBar, m_toolBarLayout);
134 AddFrame(m_toolSep, m_toolBarLayout);
135
136
137 m_rootFrame = new TGHorizontalFrame(this, 10, 10);
138 m_rootFrame->SetBackgroundColor(0);
139
140 m_leftFrame = new TGVerticalFrame(m_rootFrame, 160, 10, kFixedWidth);
141 m_leftFrame->SetBackgroundColor(GComponent::getDefaultBackground());
142
143 m_rightFrame = new TGVerticalFrame(m_rootFrame, 10, 10);
144 m_rightFrame->SetBackgroundColor(GComponent::getDefaultBackground());
145
146
147 m_treeFrame = new SelectionTreeFrame(this,m_leftFrame);
148 m_treeCanvLayout = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
149 m_leftFrame->AddFrame(m_treeFrame, m_treeCanvLayout);
150
151 GTabPane *tab = new GTabPane(m_rightFrame);
152 tab->addActionListener(this);
153 m_tab = tab;
154 tab->Associate(this);
155 m_rightFrame->AddFrame(m_tab,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY | kFixedWidth));
156
157 m_leftLayout = new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
158 m_rootFrame->AddFrame(m_leftFrame, m_leftLayout);
159
160 TGVSplitter *m_splitter = new TGVSplitter(m_rootFrame);
161 m_splitter->SetFrame(m_leftFrame, kTRUE);
162 m_splitter->SetBackgroundColor(GComponent::getDefaultBackground());
163
164 m_splitLayout = new TGLayoutHints(kLHintsLeft | kLHintsExpandY | kFixedWidth);
165 m_rootFrame->AddFrame(m_splitter, m_splitLayout);
166
167 m_rightLayout = new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY);
168 m_rootFrame->AddFrame(m_rightFrame, m_rightLayout);
169
170 m_rootLayout = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
171 AddFrame(m_rootFrame, m_rootLayout);
172
173
174
175
176 m_viewManager = g_main->get<IViewManager>("View");
177 if(m_viewManager == 0) {
178 MsgError("No ViewManager found");
179 }
180 else {
181
182
183 addTab();
184 }
185
186 MapSubwindows();
187 MsgDebug("Done initializing");
188 }
189
190 MainFrame::~MainFrame() {
191 }
192
193 void
194 MainFrame::addTab() {
195 std::ostringstream tabName;
196 tabName<<"Tab "<<(m_viewManager->getNumberOfTabs()+1);
197 const std::string tabId(tabName.str());
198 m_tabIDs.push_back(tabId);
199
200 TGCompositeFrame *compFrame = m_tab->addTab(tabId);
201 int rootTabId = m_tab->GetNumberOfTabs()-1;
202 MsgDebug("addTab() Adding tab '"<<tabId<<"' with root id="<<rootTabId);
203 ViewTab *newTab = new ViewTab(tabId,compFrame,m_tab,rootTabId);
204 m_viewManager->addTab(newTab);
205 m_rightFrame->MapSubwindows();
206 m_tab->Layout();
207 }
208
209 void
210 MainFrame::execute(Properties &) {
211
212 Layout();
213 MapWindow();
214 m_treeFrame->HandleExpose(0);
215 }
216
217 Bool_t
218 MainFrame::HandleExpose(Event_t* event) {
219 static bool first = true;
220 if(first) {
221 first = false;
222 m_treeFrame->HandleExpose(event);
223 }
224 return true;
225 }
226
227 void
228 MainFrame::actionPerformed(ActionSignal<GComponent> *as) {
229 void *source = as->getSource();
230 MsgDebug("ActionPerformed '"<<as->getText()<<"'");
231
232 if(source == m_fileMenuNewTabEntry) {
233
234
235
236 addTab();
237 }
238 else if((source == m_fileMenuOpenCatalogEntry) || (source == m_fileImportButton)) {
239 TGFileInfo *fi = new TGFileInfo();
240 const char *fileExts[] = {"File catalogs","*.xml",
241 "CIS","*.cis",
242 "Cesium","*.ces",
243 "CIS fit","*.fit",
244 "CIS flat","*.fla",
245 "Laser","*.las",
246 "CIS opt","*.opt",
247 "Pedestal","*.ped",
248 "Filter","*.ofw",
249 "ROD DSP bin","*.ldr",
250 "ROD FPGA bin","*.fpg",
251 "Logs","*.log",
252 "Data","*.dat",
253 "Root","*.root",
254 "All","*.*",
255 0,0};
256 fi->fFileTypes = fileExts;
257 new TGFileDialog(fClient->GetRoot(),this,kFDOpen,fi);
258 if(fi->fFilename) {
259 GComponent::getRootComponent()->setCursor(GComponent::Watch);
260 try {
261 if(!m_handlerManager->dispatchFile(fi->fFilename)){
262 GDialog::showErrorDialog("Open file","Sorry, file type not supported");
263 }
264 else {
265 MsgVerbose("Import OK, show entry listview");
266 view::IViewManager *viewManager = g_mainContext->get<IViewManager>("View");
267 if(viewManager) viewManager->showView(new ViewState<CondType>("ImportList",CondType("/tile")));
268 }
269 }
270 catch(tilec::iov::FolderNotFoundException &e) {
271 GDialog::showErrorDialog("Import","The destination folder was not found:"+e.what());
272 }
273 catch(Exception &e) {
274 MsgError("Exception caught while importing data: "<<e.what());
275 GDialog::showErrorDialog("Import","Sorry, exception caught while importing, please examine log file for details");
276 }
277 GComponent::getRootComponent()->setCursor(GComponent::Pointer);
278 }
279 }
280 else if((source == m_fileMenuSaveEntry) || (source == m_saveButton)) {
281 IView *view = m_viewManager->getCurrentView();
282 if(view) {
283 if(view->isSavingEnabled()) view->save();
284 else GDialog::showErrorDialog("Save","The current view doesn't support saving");
285 }
286 else GDialog::showErrorDialog("Save","There is nothing to save");
287 }
288 else if(source == m_backButton) {
289 m_viewManager->goBack();
290 }
291 else if(source == m_forwardButton) {
292 m_viewManager->goForward();
293 }
294 else if((source == m_printButton) || (source == m_fileMenuPrintEntry)) {
295 IView *view = m_viewManager->getCurrentView();
296 if(view) {
297 if(view->isPrintingEnabled()) view->print();
298 else GDialog::showErrorDialog("Print","The current view doesn't support printing");
299 }
300 else GDialog::showErrorDialog("Print","There is nothing to print");
301 }
302 else if(source == m_configButton) {
303 m_viewManager->showView(new ViewState<int>("ConfigMain",0));
304 }
305 else if(source == m_bookmarkButton) {
306 IView *view = m_viewManager->getCurrentView();
307 if(view) {
308 if(view->isBookmarkingEnabled());
309 else GDialog::showErrorDialog("Add bookmark","The current view doesn't support bookmarking");
310 }
311 else GDialog::showErrorDialog("Add bookmark","There is nothing to bookmark");
312 }
313 else if(as->getText() == "New tab") {
314 addTab();
315 }
316 else if(as->getText() == "Close tab") {
317 }
318 }
319
320 void
321 MainFrame::CloseWindow() {
322 DestroyWindow();
323 throw CleanShutdown("System shutdown",getID());
324 }
325
326 Bool_t
327 MainFrame::ProcessMessage(Long_t msg, Long_t parm1, Long_t) {
328 switch (GET_MSG(msg)) {
329 case kC_COMMAND: {
330 switch (GET_SUBMSG(msg)) {
331 case kCM_BUTTON:
332 case kCM_CHECKBUTTON:
333 case kCM_RADIOBUTTON: {
334
335
336
337 break;
338 }
339 case kCM_MENU: {
340
341
342
343 break;
344 }
345 case kCM_TAB: {
346
347 int tabId = (int)parm1;
348 MsgDebug("ProcessMessage() Changing to tab "<<tabId<<" '"<<m_tabIDs[tabId]<<"'");
349 m_viewManager->tabChanged(m_tabIDs[tabId]);
350 break;
351 }
352 default: {
353 break;
354 }
355 }
356 break;
357 }
358 default:
359 break;
360 }
361 return kTRUE;
362 }
This page was automatically generated by the
LXR engine.
|
|