XSGui.cxx

Go to the documentation of this file.
00001 /*
00002  * $Header$
00003  * $Log$
00004  *
00005  * The graphical user interface for the Neutron Cross section database
00006  */
00007 
00008 #define __XSGUI_CXX
00009 
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 
00013 #include <TROOT.h>
00014 #include <TGraph.h>
00015 #include <TFrame.h>
00016 #include <TCanvas.h>
00017 #include <TSystem.h>
00018 #include <TApplication.h>
00019 #include <Riostream.h>
00020 
00021 #include "XSGui.h"
00022 #include "XSVarious.h"
00023 #include "XSElementDlg.h"
00024 #include "XSReactionDlg.h"
00025 
00026 //ClassImp(XSGui)
00027 
00028 const char *filetypes[] = {     "All files",    "*",
00029                                 "Data file",    "*.dat",
00030                                 "ENDF files",   "*.endf",
00031                                 0,              0 };
00032 
00033 /* ----- XSGui ----- */
00034 XSGui::XSGui(const TGWindow *p, UInt_t w, UInt_t h)
00035         : TGMainFrame(p, w, h)
00036 {
00037         // Create the main frame. A TGMainFrame is a top level window.
00038 
00039         // Create menubar and popup menus. The hint objects are used to place
00040         // and group the different menu widgets with respect to eachother.
00041         menuBarLayout = new TGLayoutHints(
00042                                 kLHintsTop | kLHintsLeft | kLHintsExpandX,
00043                                 0, 0, 1, 1);
00044         menuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft,
00045                                 0, 4, 0, 0);
00046         menuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
00047 
00048         // Build up the menus
00049         // First the Main (FILE) menu
00050         fileMenu = new TGPopupMenu(fClient->GetRoot());
00051         fileMenu->AddEntry("&Open...", M_FILE_OPEN);
00052         fileMenu->AddEntry("&Save", M_FILE_SAVE);
00053         fileMenu->AddEntry("S&ave as...", M_FILE_SAVEAS);
00054         fileMenu->AddEntry("&Close", M_FILE_CLOSE);
00055         fileMenu->AddSeparator();
00056         fileMenu->AddEntry("&Print", M_FILE_PRINT);
00057         fileMenu->AddEntry("P&rint setup...", M_FILE_PRINT_SETUP);
00058         fileMenu->AddSeparator();
00059         fileMenu->AddEntry("E&xit", M_FILE_EXIT);
00060 
00061         fileMenu->DisableEntry(M_FILE_SAVEAS);
00062         fileMenu->DisableEntry(M_FILE_CLOSE);
00063 
00064         // The database menu and the current elements in graph
00065         elemMenu = new TGPopupMenu(fClient->GetRoot());
00066         elemMenu->AddEntry("&Reaction", M_ELEM_REACTION);
00067         elemMenu->AddEntry("&Modify", M_ELEM_MODIFY);
00068         elemMenu->AddEntry("&Clear", M_ELEM_CLEAR);
00069         elemMenu->AddSeparator();
00070         elemMenu->AddLabel("Current Elements in Graph");
00071 
00072         // The Currently Editing elements menu
00073         optMenu = new TGPopupMenu(fClient->GetRoot());
00074         optMenu->AddEntry("&Zoom", -1);
00075         optMenu->AddEntry("&Options", -1);
00076 
00077         // The Help Menu
00078         helpMenu = new TGPopupMenu(fClient->GetRoot());
00079         helpMenu->AddEntry("&About",M_HELP_ABOUT);
00080 
00081         // Menu button messages are handled by the main frame (i.e. "this")
00082         // ProcessMessage() method.
00083         fileMenu->Associate(this);
00084         elemMenu->Associate(this);
00085         optMenu->Associate(this);
00086         helpMenu->Associate(this);
00087 
00088         menuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
00089         menuBar->AddPopup("&File", fileMenu, menuBarItemLayout);
00090         menuBar->AddPopup("&Element", elemMenu, menuBarItemLayout);
00091         menuBar->AddPopup("&Options", optMenu, menuBarItemLayout);
00092         menuBar->AddPopup("&Help", helpMenu, menuBarHelpLayout);
00093 
00094         AddFrame(menuBar, menuBarLayout);
00095 
00096         // Create a ROOT Canvas used for drawing...
00097         canvasWindow = new TRootEmbeddedCanvas("Canvas",this,
00098                         600,400);
00099 
00100         // Initialise the canvas
00101         canvas = canvasWindow->GetCanvas();
00102         canvas->SetFillColor(42);
00103         canvas->SetGrid();
00104         canvas->GetFrame()->SetFillColor(21);
00105         canvas->GetFrame()->SetBorderSize(6);
00106         canvas->SetLogx();
00107         canvas->SetLogy();
00108         canvas->Update();
00109 
00110         AddFrame(canvasWindow,
00111                 new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
00112                         0, 0, 2, 2));
00113 
00114         statusBar = new TGStatusBar(this, 60, 20);
00115         AddFrame(statusBar, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
00116                 0, 0, 1, 0));
00117         statusBar->SetText(PRGNAME);
00118 
00119         SetWindowName(PRGNAME);
00120 
00121         MapSubwindows();
00122 
00123         // we need to use GetDefault...() to initialize the layout algorithm...
00124         Resize(GetDefaultSize());
00125 
00126         MapWindow();
00127 } // XSGui
00128 
00129 /* ----- ~XSGui ----- */
00130 XSGui::~XSGui()
00131 {
00132         // Delete all created widgets.
00133         delete menuBarLayout;
00134         delete menuBarItemLayout;
00135         delete menuBarHelpLayout;
00136 
00137         delete fileMenu;
00138         delete elemMenu;
00139         delete optMenu;
00140         delete helpMenu;
00141 
00142         delete statusBar;
00143         delete canvasWindow;
00144 } // ~XSGui
00145 
00146 /* ----- CloseWindow ----- */
00147 void
00148 XSGui::CloseWindow()
00149 {
00150         // Got close message for this MainFrame. Calls parent CloseWindow()
00151         // (which destroys the window) and terminate the application.
00152         // The close message is generated by the window manager when its close
00153         // window menu item is selected.
00154 
00155         TGMainFrame::CloseWindow();
00156         gApplication->Terminate(0);
00157 } // CloseWindow
00158 
00159 /* ----- ProcessMenuMessage ----- */
00160 Bool_t
00161 XSGui::ProcessMenuMessage( Long_t param )
00162 {
00163         switch (param) {
00164                 case M_FILE_OPEN:
00165                     {
00166                         static TString dir(".");
00167                         TGFileInfo fi;
00168                         fi.fFileTypes = filetypes;
00169                         fi.fIniDir    = StrDup(dir);
00170                         new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &fi);
00171                         dir = fi.fIniDir;
00172                      }
00173                      break;
00174 
00175                 case M_FILE_SAVE:
00176                         printf("M_FILE_SAVE\n");
00177                         break;
00178 
00179                 case M_FILE_EXIT:
00180                         // this also terminates theApp
00181                         CloseWindow();
00182                         break;
00183 
00184                 case M_ELEM_REACTION:
00185                         new XSReactionDlg(fClient->GetRoot(), this, 1, 500,600);
00186                         break;
00187 
00188                 case M_HELP_ABOUT:
00189                         // About();
00190                         int     retval;
00191                         new TGMsgBox(fClient->GetRoot(), this,
00192                                 "About", "About....",
00193                                 kMBIconAsterisk, kMBOk, &retval );
00194                         break;
00195 
00196                 default:
00197                         break;
00198         }
00199         return kTRUE;
00200 } // ProcessMenuMessage
00201 
00202 /* ----- ProcessMessage ----- */
00203 Bool_t
00204 XSGui::ProcessMessage(Long_t msg, Long_t param1, Long_t)
00205 {
00206         // Handle messages send to the XSGui object.
00207         char    str[100];
00208 
00209         switch (GET_MSG(msg)) {
00210 
00211                 case kC_COMMAND:
00212                         switch (GET_SUBMSG(msg)) {
00213 
00214                                 case kCM_BUTTON:
00215                                         snprintf(str,100,
00216                                            "Button was pressed, id = %ld\n",
00217                                             param1);
00218                                         statusBar->SetText(str);
00219                                         break;
00220 
00221                                 case kCM_MENUSELECT:
00222                                         if (param1>=0)
00223                                                 statusBar->SetText(menuTip[param1]);
00224                                         else
00225                                                 statusBar->SetText("Undefined Menu!");
00226                                         break;
00227 
00228                                 case kCM_MENU:
00229                                         ProcessMenuMessage(param1);
00230                                         break;
00231 
00232                                 default:
00233                                         break;
00234                         }
00235                 default:
00236                         break;
00237         }
00238         return kTRUE;
00239 } // ProcessMessage
00240 
00241 //---- Main program ----------------------------------------------------------
00242 
00243 TROOT root("GUI", "GUI test environement");
00244 
00245 /* ----- main ----- */
00246 int main(int ac, char *av[])
00247 {
00248         TApplication theApp("App", &ac, av);
00249 
00250         XSGui mainWindow(gClient->GetRoot(), 400, 220);
00251 
00252         XSinitialise();
00253 
00254         theApp.Run();
00255 
00256         XSfinalise();
00257         return 0;
00258 } // main

Generated on Tue Jul 5 15:15:05 2011 for ROOT_528-00b_version by  doxygen 1.5.1