ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIMainFrame.cxx
Go to the documentation of this file.
1 
7 // trick to debug with 2 terminal, to save somewhere else
8 //http://www.dirac.org/linux/gdb/07-Debugging_Ncurses_Programs.php
9 //http://www.dirac.org/linux/gdb/04-Breakpoints_And_Watchpoints.php
10 
11 #include "GUIMainFrame.h"
12 
13 // used forward declaration in .h
14 #include "GUIMainController.h"
15 #include "RealTime2.h"
16 #include "Garbage.h"
17 
18 //for ROOT dictionary, gcc say ; extra, change nothing for bug
20 
21 // Main Frame of the application, owns the menu bar
22 // here creates realtime RT2
23 GUIMainFrame::GUIMainFrame(const TGWindow *p, UInt_t w,UInt_t h,
24  GUIMainController *control )
25 : TGMainFrame(p, w, h), fcontroller( control )
26 {
27 #ifdef DEBUG_CONT_FRAME
28  std::cout << "\n\tEntry Constructor GUIMainFrame" << std::endl;
29 #endif
30 
31  // done for killing all child, if correct not needed ?? but better ??
32  // seems good habit, otherwise need a specific delete for all widgets ??
33  // not working...
34  SetCleanup ( kDeepCleanup );
35 
36  //Garbage collector for ROOT objects, because problem with signals
37  // problem when deleted, if nothing has been loaded ?? not the reason
39  //Garbage *gb = Garbage::getInstance();
40  // important to be on the heap
41  TTimer *tt = new TTimer( &gb, 1000 ); // default synchrone
42  //TTimer tt( &gb, 1000 ); will not work
43  tt->Start(1000, false );
44 
45  SetName("GUIMainFrame");
46 
47  //this belongs to mainframe
48  CreateMenu();
49 
50  // will contain the main gui of something, can be different stuffs
51  // empty frame, will contain MainIndicatorTHStockFrame
52  fHframe0 = new TGHorizontalFrame(this,w,h,kFitHeight|kFitWidth);
53  AddFrame(fHframe0, new TGLayoutHints( kLHintsLeft | kLHintsExpandX | kLHintsExpandY ,2,2,2,2));
54 
55 //#ifdef DEBUG_CONT_FRAME
56  //std::cout << "fHframe0 " << fHframe0 << std::endl;
57  //std::cout << "GetFrame " << GetFrame() << std::endl;
58  //std::cout << "GetfHframe0 " << GetfHframe0() << std::endl;
59 //#endif
60 
61  //Set a name
62  SetWindowName("GUIStock");
63 
64  // Test with new RealTime2, set
65  frealtime2 = RealTime2::getInstance();
66  std::cout << "GetStatus RealTime2 " << frealtime2->GetStatus() << std::endl;
67  //Connect( "RealTime2", "Timeout()", "GUIMainFrame", this, "UpdateRT2(=true)");
68 
69  // connect the TimeOut, TimeOut will be emitted manually
70  frealtime2->Connect("Timeout()","GUIMainFrame", this, "CheckUpdateRT()");
71  // from tetris example, make a loop, without no call, miss addtimer ??
72  // for development run the timer by default, should be not, but manually
73  frealtime2->Start( 1000 ); // here use AddTimer if not overloaded, equivalent
74 }
75 
77 {
78 #ifdef DEBUG_CONT_FRAME
79  std::cout << "Destructor GUIMainFrame" << std::endl;
80 #endif
81  /*
82  if ( fHframe0 != 0 ) {
83  std::cout << "fHframe0 different of 0, delete it " << std::endl;
84  // crash, but composite frame are never deleted
85  //delete fHframe0;
86  }*/
87  // try cleanup after the explicit deletion, more logic ??
88  // Cleanup and delete all object added by AddFrame
89  Cleanup();
90 
91 #ifdef DEBUG_CONT_FRAME
92  std::cout << "after cleanup destructor GUIMainFrame" << std::endl;
93 #endif
94 }
95 
96 
98 {
99  // First PopupMenu Main
100  fMenuFile = new TGPopupMenu(fClient->GetDefaultRoot());
101  fMenuFile->AddEntry("&Load", kLoadStock);
102  fMenuFile->AddSeparator();
103  fMenuFile->AddEntry("&Quit", kQuit);
104 
105  //connect action to HandleMenu
106  fMenuFile->Connect("Activated(Int_t)", "GUIMainFrame", this, "HandleMenu(Int_t)");
107  fMenuFile->Connect("PoppedUp()", "GUIMainFrame", this, "HandlePopup()");
108  fMenuFile->Connect("PoppedDown()", "GUIMainFrame", this, "HandlePopdown()");
109 
110  // Second PopupMenu
111  fMenuUpdate = new TGPopupMenu( fClient->GetDefaultRoot());
112  fMenuUpdate->AddEntry("CSV", kUpdateCSV);
113  fMenuUpdate->AddEntry("dCSV", kUpdatedCSV);
114 
115  //connect these entries
116  fMenuUpdate->Connect("Activated(Int_t)", "GUIMainFrame", this, "HandleMenu(Int_t)");
117 
118  //MenuLayout
119  fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1);
120  fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
121 
122  //CreateMenuBar
123  fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
124  fMenuBar->AddPopup("&Main", fMenuFile, fMenuBarItemLayout);
125  fMenuBar->AddPopup("&Update", fMenuUpdate, fMenuBarItemLayout);
126 
127  AddFrame(fMenuBar, fMenuBarLayout);
128  //for cheking, done manually
129  //PrintList();
130 }
131 
132 
134 {
135 #ifdef DEBUG_CONT_FRAME
136  std::cout << "Entry GUIMainFrame::CloseWindow()" << std::endl;
137 #endif
138  // Got close message for this MainFrame. Terminates the application.
139  // should delete all subframes, not done
140  Cleanup();
141  //std::cout << "after cleanup" << std::endl;
142  gApplication->Terminate();
143 }
144 
147 {
148  // use id
149  switch (id) {
150 
151  // just for test this function
152  // Deal with first Main popup
153  // works to delete ! or to keep for tests
154  case kLoadStock:
155  {
156  //ugly code, but just a test
157  //Stock *stock;
158  //std::cout << "Will Load Stock CAC40" << std::endl;
159  //change order
160  //fstockmanager->InsertVec_Stock("CAC40");
161  //im->Load( "CAC40", DAY, Indicator::SMA, tmp_vec );
162  //stock = fstockmanager->Load( "CAC40", DAY, Indicator::StockCSV );
163  //fstockmanager->InsertVec_Stock( stock );
164 
165  //std::vector<int> tmp_vec;
166  //tmp_vec.push_back(10);
167 
168  //very ugly
169  //fstockmanager->Load( "CAC40", DAY, Indicator::SMA, tmp_vec );
170 
171 
172  // need to say to CanvasStock
173  //Stock *st= fstockmanager->Find("CAC40");
174  //no need
175  //CanvasStock *cs = (CanvasStock *) fHSframe_current->GetECanvas();
176  //CanvasStock *cs = GetECanvas();
177 
178  //cs->AddListDataStockToMap( st->GetListData( DAY, Indicator::StockCSV) );
179 
180  //cs->AddListDataStockToMap( st->GetListData( DAY, Indicator::SMA) );
181  //cs->AddListDataStockToMap( st->GetListData( DAY, "SMA_10") );
182  //cs->AddListDataStockToMap( st->GetListData( DAY, Indicator::Volume) );
183  //cs->Modified();
184  //cs->Update();
185 
186  /*
187  std::cout << "Print List of fHSframe " << std::endl;
188 
189  std::cout << "Print Name of MainFrame " << std::endl;
190  std::cout << this->GetName() << std::endl;
191 
192  std::cout << "\nGetOptions of Frame " << std::endl;
193  //std::cout << "fIndicframe :" << fMIndicframe_current->GetOptions() << std::endl;
194  // std::cout << "fHSframe :" << fHSframe_current->GetOptions() << std::endl;
195  std::cout << "fHframe0 :" << fHframe0->GetOptions() << std::endl;
196  */
197  }
198  break;
199 
200  case kQuit:
202  CloseWindow();
203  break;
204 
205  // 2nd popup, Update stocks
206  case kUpdateCSV:
207  //get the stock selected
208  {
209  std::cout << "\n\t UpdateCSV not implemented" << std::endl;
210  //UpdateStock( DAY );
211  //UpdateStock();
212  }
213  break;
214 
215  // here make tests for real time, will be in another function after
216  // here may keep an equivalent to FORCE Update, need python wrapper
217  case kUpdatedCSV:
218  {
219  std::cout << "\n\tUpdate dCSV realtime not yet really implemented " << std::endl;
220  //UpdateStock( dcsv );
221  //UpdateStock();
222  }
223  break;
224 
225  default:
226  //printf("Menu item %d selected\n", id);
227  std::cout << "Menu item " << id << "Selected but not implemented" << std::endl;
228  break;
229  } //End switch
230 
231 }
232 
237 void GUIMainFrame::UpdateRT( std::vector<std::string> & message) // ( bool automatic )
238 {
239 #ifdef DEBUG_CONT_FRAME
240  //std::cout << "\n\t GUIMainFrame::UpdateTimer automatic = " << automatic << std::endl;
241  std::cout << "\n\t GUIMainFrame::UpdateRT( message ) " << std::endl;
242 #endif
243  frealtime2->SetMessage( message );
244 }
245 
248 {
249 #ifdef DEBUG_CONT_FRAME
250  std::cout << "\n\t GUIMainFrame::CheckUpdateRT " << std::endl;
251 #endif
252 
253  std::vector<std::string > message;
254  message = frealtime2->GetMessage();
255 
256  if ( message.empty() ) {
257 #ifdef DEBUG_CONT_FRAME
258  std::cout << "CkeckUpdateRT, Message is empty return " << std::endl;
259 #endif
260  return;
261  }
262 
263  // now need to update the graphs
264 /*
265 #ifdef DEBUG_CONT_FRAME
266  std::cout << "message : " << message[0] << "," << message[1] << std::endl;
267 #endif
268 */
269  // should go back to controller, easier to maintain
270  fcontroller->Updated( message );
271 }
274 {
275  std::cout << "GUIMainFrame::PrintList " << std::endl;
276  std::cout << "List of fHframe0 " << std::endl;
277  fHframe0->GetList()->Print();
278 }
279 
280 
TGPopupMenu * fMenuUpdate
Definition: GUIMainFrame.h:63
TGLayoutHints * fMenuBarLayout
Definition: GUIMainFrame.h:65
virtual void Updated(std::vector< std::string > &message)
Called through the timer RT2, when new data are present.
RealTime2 * frealtime2
RealTime, singleton, initialized in constructor, set to on by default keep in main frame because ROOT...
Definition: GUIMainFrame.h:51
GUIMainController * fcontroller
need a pointer to the controller to send messages, validation, click...
Definition: GUIMainFrame.h:45
Main controller of the application, linked to the view GUIMainFrame.
void UpdateRT(std::vector< std::string > &message)
set by thread of fstockmanger, register the message in frealtime2 and quit
void SetMessage(std::vector< std::string > &message)
deal with the list, fill and remove, protected by lock_guard
Definition: RealTime2.cxx:41
RealTime2 derives from TTimer.
TGPopupMenu * fMenuFile
Definition: GUIMainFrame.h:62
virtual ~GUIMainFrame()
void CloseWindow()
TGHorizontalFrame * fHframe0
main sub-window for both IndicatorFrame and THStockFrame, owns by GUIMainFrame now will be the main f...
Definition: GUIMainFrame.h:56
Garbage collector for ROOT TObjects.
Definition: Garbage.h:30
static RealTime2 * getInstance()
public access
Definition: RealTime2.cxx:14
void PrintList()
for info, depreceated, only one frame0 here
static Garbage & getInstance()
Definition: Garbage.cxx:19
TGLayoutHints * fMenuBarItemLayout
Definition: GUIMainFrame.h:66
GUIMainframe definition.
Definition: GUIMainFrame.h:31
void CheckUpdateRT()
Slot for TimeOut of ReaTime2.
ClassImp(GUIMainFrame) GUIMainFrame
void HandleMenu(Int_t id)
slots
Main graphic frame for GUIStock application.
TGMenuBar * fMenuBar
Definition: GUIMainFrame.h:61
std::vector< std::string > GetMessage()
Definition: RealTime2.cxx:56
void CreateMenu()
private methods