/** ****************************************************************** * * Module Name : scope.cpp * * Author/Date : C.B. Lirakis / 28-Aud-04 * * Description : * * Restrictions/Limitations : * * Change Descriptions : * * Classification : Unclassified * * References : * * * RCS header info. * ---------------- * $RCSfile: classic.cpp,v $ * $Author: clirakis $ * $Date: 2004/08/17 08:55:39 $ * $Locker: clirakis $ * $Name: $ * $Revision: 1.4 $ * * $Log: classic.cpp,v $ * * * ******************************************************************* */ #ifndef lint /// RCS Information static char rcsid[]="$Header: /home/clirakis/Work/Navo/2004/RTD/envclone/RCS/classic.cpp,v 1.4 2004/08/17 08:55:39 clirakis Exp clirakis $"; #endif // System includes. #include using namespace std; #include #include #include #include /* ROOT includes */ #include "TCanvas.h" #include "TFrame.h" #include "TGMsgBox.h" #include "TObjString.h" #include "TTimeStamp.h" /// Local Includes. /** * Create an oscilliscope type display. */ class OScope { // ClassDef(OScope, 0) RQ_OBJECT("OScope") private: /** * Private variables making up plotting surface and dialog. */ TGMenuBar *fMenuBar; // Menu bar TGPopupMenu *fMenuFile; // menu items file /* * Layout hints for graphical frame, and canvas then * for the menus and their individual items. */ TGLayoutHints *fL1,; TGLayoutHints *fMenuBarLayout, *fMenuBarItemLayout; TRootEmbeddedCanvas *fEmbeddedCanvas; // Embedded canvas for plotting TGMainFrame *fTop; /* * Private helper functions */ void DoLoad(); void DoSaveAs(); public: /* * OScope constructor * p - parent window handle * w - Width of window to be created. * h - height of window to be created. * * Thie inherits all the properties of TGMainFrame. */ OScope(const TGWindow *p, UInt_t w, UInt_t h, UInt_t Options = kVerticalFrame); /* * OScope destructor. * clean up, deallocate any dynamically allocated objects, and * close the windows created. */ virtual ~OScope(); /** * This method handles the close window events. */ virtual void CloseWindow(); /** * Method for handling the menu item selections. */ void HandleMenu(Int_t id); }; /* * Enumerations for menu and other buttons. */ enum OScopeCommandIdentifiers { M_FILE_EXIT=100, }; /** ****************************************************************** * * Function Name : OScope constructor * * Description : Create the window then load the preference file * containing the dynamic information for filling the plots * to be displayed. * * Inputs : p - Parent window handle * w - width of child in pixels * h - height of child in pixels * * Returns : fully constructed OScope class. * * Error Conditions : none currently. * ******************************************************************* */ OScope::OScope(const TGWindow *p, UInt_t w, UInt_t h, UInt_t Options) { int i; fTop = new TGMainFrame( p, w, h, Options); fTop->Connect("CloseWindow()", "OScope", this, "CloseWindow()"); /* * Variables used in managing preferences. * Set all these to null indicating that they are not currently * in use. If the destructor is called this * will prevent a inadvertent delete of the created * object. These are very specific to this application. */ // Setup a viewing frame here. /* * Create layout hints for the menubar, popup menus and menu items. */ fMenuBarLayout = new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX, 0, 0, 1, 1); fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 1, 4, 0, 0); /* * The first menu, is named "File" and has only an exit * item associated with it. This looks very similar to what is * recommended in standard style guides such as the Motif Style Guide. * The M_xxx_xxx specifies an integer number that is associated with * each button on the popup menu. */ fMenuFile = new TGPopupMenu(gClient->GetRoot()); fMenuFile->AddSeparator(); fMenuFile->AddEntry("E&xit" , M_FILE_EXIT); /* * So now, create the menubar, and then add the * "File" and "Help" popups associated with that menubar. * The layout is primarily horizontal. (This makes sense.) */ fMenuBar = new TGMenuBar( fTop, 1, 1, kHorizontalFrame); fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout); /* * Each menu needs some sort of callback function to * service its needs. Selecting an item on the popup menu * will then activate this callback and pass in the integer * number specified. The callback is just one big enormus * switch statement that is connected to the right thing. * We don't necessarily have to do it that way, but is * does work. * * Both the File and Help popup menus are connected to the * same callback function for convienence. */ fMenuFile->Connect("Activated(Int_t)", "OScope", this, "HandleMenu(Int_t)"); /* * Finally, add this frame to the overall parent frame. */ fTop->AddFrame(fMenuBar, fMenuBarLayout); /* * The remaining space I want to be a frame to hold the graphs * and plots produced. They are not used at this point * but are created for use later. */ fL1 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX | kLHintsExpandY, 2, 2, 5, 1); fEmbeddedCanvas = new TRootEmbeddedCanvas("MyName", fTop, 1200, 200); fTop->AddFrame( fEmbeddedCanvas, fL1); /* * The next series of 3 calls are pretty self explanitory. * The main window is actually painted on the screen. */ fTop->MapSubwindows(); fTop->Resize(); fTop->SetWindowName("Root Oscilloscope"); fTop->MapWindow(); fTop->Move(10,10); } /** ****************************************************************** * * Function Name : OScope destructor * * Description : Does the cleanup for the class. Specifically * deletes (deallocates) any dynamically allocated objects * called for during the life of the class. * * Inputs : None * * Returns : None * * Error Conditions : None * * Unit Tested on: * * Unit Tested by: CBL * * ******************************************************************* */ OScope::~OScope() { printf("\nClosing down window now!\n\n\n"); delete fTop; printf("Done!\n"); } /** ****************************************************************** * * Function Name : CloseWindow * * Description : Pretty simple, delete this. * * Inputs : none * * Returns : none * * Error Conditions : none * * Unit Tested on: 30-Jul-04 * * Unit Tested by: CBL * * ******************************************************************* */ void OScope::CloseWindow() { printf("CLOSE WINDOW!\n"); delete this; } /** ****************************************************************** * * Function Name : HandleMenu * * Description : Handle menu items for this dialog. * * Inputs : ID for menu event. * * Returns : none * * Error Conditions : none * * Unit Tested on: 30-Jul-04 * * Unit Tested by: CBL * * ******************************************************************* */ void OScope::HandleMenu(Int_t id) { char filename[512]; Int_t n, save_ret; /* * Handle menu items. * All items for the case statement are declared in an enum * at the head of this file. */ int rc; switch (id) { case M_FILE_EXIT: //CloseWindow(); fTop->SendCloseMessage(); break; default: printf("Menu item %d selected\n", id); break; } } void scope() { new OScope(gClient->GetRoot(), 600, 800); }