ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIMainController.cxx
Go to the documentation of this file.
1 
8 #include "GUIMainController.h"
9 #include "GUIObserver.h"
10 #include "../src_cpp/StockManager.h"
11 #include "../src_cpp/SMSubject.h"
12 #include "GUIMainFrame.h"
13 
16 
17 // root dependency, may go to MainGUIFrame ??
18 //#include <TGClient.h>
19 
21 {
22  // initialize fstockmanger
23  // here get the global, other controllers call the parent pointer
24  // no global access for child controllers anymore
25  // could be send as a parameter, independent of the ROOT application
27 
28 #ifdef DEBUG_CONT_FRAME
29  std::cout << "\n\tEntry Constructor GUIMainController" << std::endl;
30  std::cout << "this " << this << std::endl;
31  //std::cout << "GetStatus StockManager " << fstockmanager->GetStatus() << " adress " << fstockmanager << std::endl;
32  //std::cout << "GetStatus StockManager::Server " << fstockmanager->GetStatusServer() << std::endl;
33  //std::cout << "GetStatus StockManager " << StockManager::GetStatus() << std::endl;
34  //std::cout << "GetStatus StockManager::Server " << StockManager::GetStatusServer() << std::endl;
35 #endif
36 
37  // gui_observer initialization, here attach gui_observer to StockManager
38  // register the observer here ?? or in main or.. ?? would avoid to store as member
39  gui_observer = new GUIObserver( this );
41 
42  // here choice, send a pointer of the controller, or create a signal after the creation.
43  // if Base class controller and Frame could be done "automatically"
44  // maybe signal is better, more GUI design...to test both
45  // create the unique menu, and a gui_mainframe
46  gui_mainframe = new GUIMainFrame(gClient->GetRoot(),600,400, this);
47 
48  // create first controller child by default, default
49  // need to get validation button
50  // really used ?? fcurrent_controller could be in ControllerBase
52 
53  // moved stuffs here, after the drawing of MainIndicatorTHStockFrame
54  gui_mainframe->MapSubwindows();
55  // see no changes
56  //gui_mainframe->Resize(gui_mainframe->GetDefaultSize());
57  gui_mainframe->Resize();
58  gui_mainframe->MapWindow();
59 
60  // this is necessary only if kMainFrame false ??
61  (( MainControllerIndicatorTHStock *)fcurrent_controller)->GetFrame()->ResetEntries();
62 }
63 
65 {
66 #ifdef DEBUG_CONT_FRAME
67  std::cout << "Destructor GUIMainController " << std::endl;
68 #endif
69 
70  // if Main receive the message to close
71  // should call destructor of the controller first ??
72  // will kill properly if TGMainframe
73 
74  // need to detach the observer !!
75  // maybe safer later ?? could be done in main, where it is created
76  // certainly better in main
77  //fstockmanager-> StockManager::killInstance();
78  //fstockmanager = 0;
79 
80  // delete frame
81  delete gui_mainframe;
82  gui_mainframe = 0;
83 
84  // delete the list of controllers, before or after the frames ??
85  DeleteList();
86 
87 }
88 
89 
96 {
97 #ifdef DEBUG_CONT_FRAME
98  std::cout << "\n\tEntry GUIMainController::CreateMainControllerIndicatorTHStock() kmain " << kmain << std::endl;
99  std::cout << "this " << this << std::endl;
100 #endif
101 
102  // new MainController to be created
103  MainControllerIndicatorTHStock *controller;
104 
105  // creates a controller, who will create the Frame, will be printed in fhFrame0
106  if ( kmain == false ) {
107  controller = new MainControllerIndicatorTHStock( this, "MainIndicatorTHStock_1", gui_mainframe->GetFrame(), false );
108 
109  // else make an independent frame
110  } else {
111  controller = new MainControllerIndicatorTHStock( this, "MainIndicatorTHStock_2", 0, true );
112  }
113  // add to the list of controller
114  AddController ( controller );
115 
116  // need a fcurrent_controller ?? or retrieve from the list later
117  // keep it for the moment, maybe useful
118  //fcurrent_controller = controller;
119 
120 #ifdef DEBUG_CONT_FRAME
121  // prinnt all frames
122  //gui_mainframe->Print();
123  //std::cout << "GUIMainController::CreateMainControllerIndicatorTHStock print controller->GetFrame()->Print()" << std::endl;
124  //controller->GetFrame()->Print();
125  //std::cout << "value of gpad after CreateMainControllerIndicatorTHStock " << gPad << std::endl;
126 #endif
127 
128  // return newly created MainController
129  return controller;
130 }
131 
133 {
134 #ifdef DEBUG_CONT_FRAME
135  std::cout << "Entry GUIMainController::DeleteControllerIndicatorTHStock" << std::endl;
136 #endif
137  // remove the controller from the list
138  RemoveController( control );
139  // delete really the frame associated to the controller
140  //delete control->GetFrame();
141  std::cout << "after delete control->GetFrame" << std::endl;
142  // delete really the controller
143  delete control;
144 }
145 
146 // needed for correct rescaling at the end of MainControllerIndicatorTHStock::Validation
147 // and MainControllerIndicatorTHStock::UpdateIndicator, but seems to work without
149 {
150 #ifdef DEBUG_CONT_FRAME
151  std::cout << "\n\tGUIMainController::UpdateGUIFromController " << std::endl;
152 #endif
153  // work with this one alone ! before not rescaling of the frame
154  // necessary for the first creation
155  gui_mainframe->Resize();
156 }
157 
158 
159 // Update(d)_FromGUIObserver
163 void GUIMainController::Updated( std::vector<std::string> & message )
164 {
165 #ifdef DEBUG_CONT_FRAME
166  std::cout << "Entry GUIMainController::Updated " << std::endl;
167  std::cout << "Message " << message[0] << "," << message[1] << std::endl;
168  std::cout << "Will only broadcast to child controller " << std::endl;
169 #endif
170  std::cout << "Entry GUIMainController::Updated " << std::endl;
171 
172  // check message, only one for the moment
173  //if ( message[0] == "update_dcsv" ) {
174 
175  // just broadcast
176  for ( it_list it = list_controller.begin(); it != list_controller.end(); ++it ) {
177  (*it)->Updated( message );
178  }
179 }
180 
181 /*
182 void GUIMainController::GetSelected( MainControllerIndicatorTHStock *child_controller )
183 {
184 #ifdef DEBUG_CONT_FRAME
185  std::cout << "\n\tEntry GUIMainController::GetSelected child_control " << child_controller << std::endl;
186 #endif
187 
188  // try to list important thing for adding SMA to first pad
189  fcurrent_controller = child_controller;
190  // seems only needed all done in child_controller ??
191 }
192 */
193 
195 
196 void GUIMainController::AddObserver_Message( std::vector<std::string> & message )
197 {
198 #ifdef DEBUG_CONT_FRAME
199  std::cout << "\n\tEntry GUIMainController::AddObserver_Message() from StockManager " << std::endl;
200  std::cout << "message : " << message[0] << ", " << message[1] << std::endl;
201 #endif
202 
203  // new added test with RT2, let here because ROOT dependence
204  // now register the message, for timer
205  gui_mainframe->UpdateRT( message );
206  return;
207 }
208 
std::list< MainControllerIndicatorTHStock * > list_controller
list more convenient, remove if not shown ?, or insert
Definition: Controller.h:108
GUIMainFrame * gui_mainframe
direct link to an unique GUIMainFrame
Controller for a dual frame containing Indicator+THStock(s).
virtual void Updated(std::vector< std::string > &message)
Called through the timer RT2, when new data are present.
void UpdateGUIFromController()
only gui_mainframe->Resize(), but seems necessary when a new frame created
GUIMainController()
Constructor.
Last modified.
void AddObserver_Message(std::vector< std::string > &message)
Only used to setup current_controller, really needed ? not really.
TGCompositeFrame * GetFrame()
Definition: GUIMainFrame.h:78
void UpdateRT(std::vector< std::string > &message)
set by thread of fstockmanger, register the message in frealtime2 and quit
void AddController(MainControllerIndicatorTHStock *control)
Common Function for dealing with the list, need a name, may call other controllers...
Definition: Controller.h:134
virtual void DeleteList(bool call_delete=true)
Iterative call for deleting child controller.
Definition: Controller.h:163
Independent frame, could be kMainFrame or kChild Frame which group one MainIndicatorFrame and THStock...
std::list< MainControllerIndicatorTHStock * >::iterator it_list
useful typedef for the class ( and derivatives !)
Definition: Controller.h:110
static StockManager * getInstance(std::string new_path=".")
Get a singleton instance.
SMSubject * GetSubject()
Get the subject instance.
Definition: StockManager.h:196
void DeleteControllerIndicatorTHStock(MainControllerIndicatorTHStock *control)
Concrete class of an observer.
Definition: GUIObserver.h:29
ControllerBase * fcurrent_controller
most general, may use a more specialized ? seems fine here really needed ?? seems use can be avoided...
virtual void attach(Observer *obs)
function for subject to register
MainControllerIndicatorTHStock * CreateMainControllerIndicatorTHStock(bool kmain=false)
Creates child controllers, contains Indicator+THStock(s).
GUIMainframe definition.
Definition: GUIMainFrame.h:31
GUIObserver * gui_observer
Observer for receiving messages from StockManager.
std::string GetPathData()
Definition: Utils.cpp:42
Main graphic frame for GUIStock application.
StockManager * fstockmanager
keep a pointer to StockManager from constructor.
void RemoveController(MainControllerIndicatorTHStock *control)
Definition: Controller.h:139
see remark below, much easier if composition than derivation in the case of ListController, same for parent_controller as member <U> easily extends to View as well ( ListView possible ), but strong coupling again
Definition: Controller.h:209