ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
THStockFrame.cxx
Go to the documentation of this file.
1 
8 #include "THStockFrame.h"
9 // so need controller here, need for GetSelected, except...no better for GetSelected
10 #include "../Controllers/ControllerIndicatorTHStock.h"
11 
12 #include "../CommonXAxis.h"
13 
14 //For ROOT dictionnary
16 
17 //List identifier
18 // should be in class, here certainly global
19 enum EIdentifier { HSId1, BtId1, BtId2 };
20 
21 //Add a name, should be in constructor because set the name of the CanvasStock at the same time
22 //needed to retrieve THStockFrame from GUIMainFrame when a pad is clicked
23 THStockFrame::THStockFrame(const TGWindow *p, const char *name_frame, UInt_t w, UInt_t h):
24 TGVerticalFrame(p, w, h), fcontroller(0)
25 {
26 
27 #ifdef DEBUG_CONT_FRAME
28  std::cout << "Entry Constructor THStockFrame name_frame " << name_frame << std::endl;
29 #endif
30  //Not sure assure all deletion ?
31  SetCleanup( kDeepCleanup );
32 
33  // here change options in the constructor
34  // depend calling may change these option, to adapt different application...??
35  // do not change behvior if commented
36  ChangeOptions( ( this->GetOptions() & ~kFitWidth ) | kFitWidth );
37 
38  // setup the name of THStockFrame : namestock_time
39  SetName ( name_frame );
40 
41  // use different name for the embedded canvas, needed ?? in internal ok
42  // need a name for TCanvas, constructor which accepts a winid need
43  std::string name_cstock = "CStock_" + Utils::toString<const char *>( name_frame );
44 #ifdef DEBUG_CONT_FRAME
45  std::cout << "name of the CanvasStock " << name_cstock << std::endl;
46 #endif
47 
48  // Create an embedded canvas widget, fix the size of the main window
49  // and get an wid for it
50  // first is a name, useful ?? no
51  fECanvas = new TRootEmbeddedCanvas(0, this, 650, 400);
52  std::cout << "fECanvas " << fECanvas << std::endl;
53 
54  // if need to delete....
55  Int_t wid = fECanvas->GetCanvasWindowId();
56  //std::cout << "wid " << wid << std::endl;
57 
58  // RootEmbeddedCanvas creates an Canvas, pointed by fCanvas but not deleted !!
59  // can delete it, but no errors certainly due to supp file (provided), no change for my supp file..
60  // bug in ROOT ?? to check
61  delete fECanvas->GetCanvas();
62 
63  // name may allow allow to retrieve...but only one cstock by THStockFrame, may change later
64  // wid may be better
65  fCStock = new CanvasStock( name_cstock.c_str(), (Int_t) 10, (Int_t) 10, wid );
66 #ifdef DEBUG_CONT_FRAME
67  std::cout << "Adopt new CanvasStock " << fCStock << std::endl;
68 #endif
69 
70  // CanvasStock is adopted by the embedded canvas and will be destroyed by it
71  fECanvas->AdoptCanvas(fCStock);
72  // add the embedded canvas to its frame
73  AddFrame ( fECanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY) );
74 
75  // need to set up Selected, here connect to itself
76  // here problem, connect all CanvasStock, send 2 signals
77  // solved problem, keep original to remember mistake
78  //fCStock->Connect( "CanvasStock","Selected(TVirtualPad*,TObject*,Int_t)","THStockFrame", this, "GetSignalSelected( TVirtualPad*,TObject*,Int_t )" );
79  fCStock->Connect("Selected(TVirtualPad*,TObject*,Int_t)","THStockFrame", this, "GetSignalSelected( TVirtualPad*,TObject*,Int_t )" );
80 
81 #ifdef DEBUG_CONT_FRAME
82  std::cout << "fECanvas " << fECanvas << std::endl;
83  std::cout << "fCStock->GetMother()" << fCStock->GetMother() << std::endl;
84  std::cout << "fCStock->GetMother()->GetMother()" << fCStock->GetMother()->GetMother() << std::endl;
85  std::cout << "this (THStockFrame) " << this << std::endl;
86 #endif
87 
89  fslider_frame = new TGHorizontalFrame( this, 600, 1 );
90  AddFrame( fslider_frame, new TGLayoutHints( kLHintsExpandX ,2,2,2,2) );
91 
92  // Add first button
93  fButslider[0] = new TGTextButton ( fslider_frame, "<<", BtId1 );
94  fslider_frame->AddFrame( fButslider[0], new TGLayoutHints( kLHintsLeft ,2,2,2,2) );
95  fButslider[0]->Connect("Clicked()","THStockFrame", this,"HandleButton()");
96 
97  // Add slider
98  fHslider1 = new TGDoubleHSlider( fslider_frame, 600, kDoubleScaleBoth, HSId1);
99  fslider_frame->AddFrame( fHslider1,new TGLayoutHints( kLHintsExpandX ,2,2,2,2) );
100 
101  // PositionChanged() is a function/signal implemented in TGDoubleSlider
102  // slot is the function THStockMainFrame::DoSlider(), to implement
103  // other signal specific to DoubleSlider: Pressed, Released
104  fHslider1->SetRange(0,100);
105  fHslider1->SetPosition(0.0,100.0);
106  fHslider1->Connect("PositionChanged()", "THStockFrame", this, "DoSlider()");
107 
108  // Add second button
109  fButslider[1] = new TGTextButton ( fslider_frame, ">>", BtId2 );
110  fslider_frame->AddFrame( fButslider[1] , new TGLayoutHints( kLHintsLeft ,2,2,2,2 ) );
111  fButslider[1]->Connect("Clicked()","THStockFrame", this,"HandleButton()");
112 
113 }
114 
116 {
117 #ifdef DEBUG_CONT_FRAME
118  std::cout << "Destructor THStockFrame" << std::endl;
119 #endif
120  // fCStock deleted by EmbeddedCanvas, set 0 but not needed
121  fCStock =0;
122 
123  // Clean up used widgets: frames, buttons, layouthints
124  Cleanup();
125  //from tutorial statusBar.C after cleanup, to test
126  //delete fECanvas;
127 }
128 
129 // used when using the slider !!
131 {
132 #ifdef DEBUG_CONT_FRAME
133  std::cout << "Entry THStockFrame::DoSlider()" << std::endl;
134  // function to get position
135  std::cout << "GetMinPosition() " << fHslider1->GetMinPosition();
136  std::cout << "GetMaxPosition() " << fHslider1->GetMaxPosition() << std::endl;
137  std::cout << "Will call fCStock->UpdateTHStock() " << std::endl;
138 #endif
139  // get new position
140  fCStock->SetRangeCommonAxis( fHslider1->GetMinPosition(), fHslider1->GetMaxPosition() );
141 
142  // update all subpad
144 
145 #ifdef DEBUG_CONT_FRAME
146  //std::cout << "THStockFrame::DoSlider GetFirst " << fCStock->GetCommonAxis()->GetFirst() << std::endl;
147  //std::cout << "THStockFrame::DoSlider GetLast " << fCStock->GetCommonAxis()->GetLast() << std::endl;
148  std::cout << " Exit Do Slider " << std::endl;
149 #endif
150 }
151 
152 // First version simple shift slider of a fixed value of 5.0 (over 100.0 in total)
153 // If want to increase one bin only, need more interaction with fcommon_axis
155 {
156 #ifdef DEBUG_CONT_FRAME
157  std::cout << "Entry THStockFrame::HandleButton()" << std::endl;
158 #endif
159 
160  Int_t id;
161  TGButton *btn = (TGButton *) gTQSender;
162  id = btn->WidgetId();
163  //std::cout << "id " << id << std::endl;
164 
165  Double_t fmin, fmax;
166  fmin = fHslider1->GetMinPosition();
167  fmax = fHslider1->GetMaxPosition();
168 
169  Int_t nbbin = fCStock->GetCommonAxis()->GetNbins();
170 
171 #ifdef DEBUG_CONT_FRAME
172  std::cout << " GetMinPosition() " << fHslider1->GetMinPosition();
173  std::cout << " GetMaxPosition() " << fHslider1->GetMaxPosition() << std::endl;
174  std::cout << " fmin " << fmin << " fmax " << fmax << std::endl;
175 #endif
176 
177  switch (id) {
178 
179  case BtId1:
180  {
181 #ifdef DEBUG_CONT_FRAME
182  std::cout << "Press Minus id" << id << std::endl;
183 #endif
184  //Here decrease the shift_futur, do not change the slider
185  if ( fCStock->GetCommonAxis()->GetShift() > 0 ) {
186  std::cout << "will decrease shift_futur from " << fCStock->GetCommonAxis()->GetShift() << std::endl;
187  //should be in CommomAxis, executed by Incr or Decr Shift
188  fCStock->UpdateCommonAxis( nbbin - 1 );
190  std::cout << "after decrease shift_futur from " << fCStock->GetCommonAxis()->GetShift() << std::endl;
191  //fCStock->UpdateAllPad();
192  }
193  //move the slider
194  else {
195 #ifdef DEBUG_CONT_FRAME
196  std::cout << "move the slider BtId1 " << std::endl;
197 #endif
198  fmax -= 5.0;
199  ( (fmin - 5.0) > 0.0 ) ? ( fmin-=5.0 ) : ( fmin = 0.0 );
200  }
201  }
202  break;
203 
204  case BtId2:
205  {
206 #ifdef DEBUG_CONT_FRAME
207  std::cout << "Press Plus " << std::endl;
208 #endif
209  //normal use, if still some data to print on the right
210  if ( fmax < 100.0 ) {
211  // always increase fmin
212  fmin += 5.0;
213  ( (fmax + 5.0) < 100.0 ) ? ( fmax+=5.0 ) : ( fmax=100.0 );
214  }
215  //want to show future
216  else {
217 #ifdef DEBUG_CONT_FRAME
218  std::cout << "move the slider BtId2, want to see future " << std::endl;
219  std::cout << "will increase size of the common axis of 1" << std::endl;
220 #endif
221  // should be together ! to check
222  // here really increase the size, sure should be combined !
223  fCStock->UpdateCommonAxis( nbbin + 1 );
224  // increase the value, but not the size !
226  }
227  }
228  break;
229  }//end switch
230 
231 #ifdef DEBUG_CONT_FRAME
232  std::cout << "new Slider fmin " << fmin << " fmax " << fmax << std::endl;
233  std::cout << "CanvasStock->GetCommonAxis()->GetShift() " << fCStock->GetCommonAxis()->GetShift() << std::endl;
234 #endif
235 
236  // same thing, one should done with the other, difficult here...
237  //Update the slider position
238  fHslider1->SetPosition( fmin, fmax);
239 
240  //Here modify the range if fmax < 100 ;
241  // change nothing if fmax == 100 and increase shift_futur
242  // very important round for the new size in bin to be printed !
243  fCStock->SetRangeCommonAxis( fmin, fmax );
244 
245  // better to group in one function
246  // std::cout << "Call fCStock->UpdateTHStock() " << std::endl;
248 
249  std::cout << "Exit THStockFrame::HandleButton" << std::endl;
250 
251 }
252 
253 // slot, nothing used here, only select the pad and inform controller
254 void THStockFrame::GetSignalSelected( TVirtualPad* pad,TObject* obj,Int_t event )
255 {
256  std::string frame_name;
257 
258  // gPad->GetSelected == pad, gPad problem with multithread
259  // object refer CanvasStock object
260 #ifdef DEBUG_CONT_FRAME
261 
262  std::cout << "Entry Slot THStockFrame::GetSignalSelected " << std::endl;
263  /*
264  std::cout << " gPad " << gPad << std::endl;
265  std::cout << " parameter pad " << pad << std::endl;
266  //gPad give correct selection
267  std::cout << " gPad number " << gPad->GetNumber() << std::endl;
268  std::cout << " gPad classname " << gPad->ClassName() << std::endl; //CanvasStock
269  std::cout << " gPad->GetSelectedPad() " << gPad->GetSelectedPad() << std::endl;
270  std::cout << " gPad->GetSelectedPad()->GetNumber() " << gPad->GetSelectedPad()->GetNumber() << std::endl;
271  //what about object
272  std::cout << " parameter object " << obj << std::endl;
273  std::cout << " parameter object->GetName() " << obj->GetName() << std::endl;
274  std::cout << " parameter object classname " << obj->ClassName() << std::endl;
275  //event
276  std::cout << "Event Int_t " << event << std::endl;
277  // gives CStock_CAC40_DAY, frame name
278  std::cout << "gPad->GetName() " << gPad->GetName() << std::endl;
279  // gives CStock_CAC40_DAY_1 pad name
280  std::cout << "pad->GetName() " << pad->GetName() << std::endl;
281  // ok gives CStock_CAC40_DAY, frame_name, only needed ?
282  */
283  std::cout << "pad->GetMother()->GetName() " << pad->GetMother()->GetName() << std::endl;
284  std::cout << "pad->GetNumber() " << pad->GetNumber() << std::endl;
285  std::cout << "frame_name = gPad->GetName() " << frame_name << std::endl; //CStock_CAC40_DAY
286 #endif
287 
288 
289 
290  // SetCurrent Indicator and THStock
291  //frame_name = gPad->GetName();
292  //
293  frame_name = pad->GetMother()->GetName();
294  frame_name.erase(0,7);
295  std::cout << " after erase frame_name " << frame_name << std::endl;
296  std::cout << "fcontroller " << fcontroller << std::endl;
297 
298  //why 2 times ?? crash somewhere here, frame_name not necessary
299  // here require a fcontroller... can make connect from parent ??
300  // not so bad, just test if !=0
301  //fcontroller->GetSelected( gPad->GetSelectedPad()->GetNumber() );
302  fcontroller->GetSelected( pad->GetNumber() );
303 
304  /* job from the controller
305  SetCurrentTHStockFrame( frame_name );
306  fVMframe_indic->SetCurrentIndicatorFrame( frame_name );
307 
308  //Fill with good name in toolbar
309  std::string namestock = FullName::GetNameStock ( frame_name );
310  TimeScale timescale = FullName::GetTimeScale ( frame_name );
311 
312  fTextResearch->SetText( (FullName::GetNameStock ( frame_name )).c_str() );
313  fComboTime->Select ( timescale + 10 );
314  */
315 #ifdef DEBUG_CONT_FRAME
316  std::cout << "End GetSignalSelected " << std::endl;
317 #endif
318 }
319 
321 
322 // Should be in CanvasStock, accessible from ControllerIndicatorTHStock
325 // avoid this call for Update from RT2
326 /*
327 void THStockFrame::Update()
328 {
329 #ifdef DEBUG_CONT_FRAME
330  std::cout << "\n\tEntry THStockFrame::Update Clean All " << std::endl;
331 #endif
332 
333  CanvasStock *c_stock = GetECanvas();
334  std::cout << "pointer to canvas stock " << c_stock << std::endl;
335 
336  // UpdateCommonAxis included in UpdateTHStock
337  // no problem here, because redraw everything
338  c_stock->UpdateTHStock();
339 
340  // if UpdateTHStock( pad_number ) coming from ControllerIndicator
341  //bool need_fullredraw;
342  // can make full redraw of ObjectStock inside
343  // need_fullredraw = c_stock->UpdateTHStock();
344 
345  // if need_fullredraw, in fact only call Modified
346  // could be in UpdateTHStock
347  c_stock->UpdateAllPad();
348 
349  // this cost nothing, certainly necessary
350  c_stock->Update();
351  std::cout << "After CanvasStock Update " << std::endl;
352 }
353 */
354 
355 /* not working does not inherit from TPad, keep for the remark
356 void THStockFrame::ExecuteEvent(Int_t event, Int_t px, Int_t py)
357 */
Owns a vector of THStock.
Definition: CanvasStock.h:53
void GetSignalSelected(TVirtualPad *, TObject *, Int_t)
virtual ~THStockFrame()
TGTextButton * fButslider[2]
Definition: THStockFrame.h:67
ClassImp(THStockFrame) enum EIdentifier
void IncrShift()
Definition: CommonXAxis.h:73
TRootEmbeddedCanvas * fECanvas
contain one embedded CanvasStock
Definition: THStockFrame.h:58
THStockFrame(const TGWindow *p, const char *, UInt_t w, UInt_t h)
constructor, destructor
TGHorizontalFrame * fslider_frame
Definition: THStockFrame.h:63
CanvasStock * fCStock
1 CanvasStock for each frame, easier
Definition: THStockFrame.h:60
Contains an EmbeddedCanvas and a CanvasStock.
Definition: THStockFrame.h:46
void SetRangeCommonAxis(Double_t MinPos, Double_t MaxPos)
interface to CommonXaxis.
TGDoubleHSlider * fHslider1
Definition: THStockFrame.h:65
ControllerIndicatorTHStock * fcontroller
Definition: THStockFrame.h:54
void DecrShift()
Definition: CommonXAxis.h:74
CommonXAxis * GetCommonAxis() const
Definition: CanvasStock.h:88
Int_t GetNbins()
Definition: CommonXAxis.h:77
Int_t GetShift() const
Definition: CommonXAxis.h:71
void HandleButton()
void UpdateCommonAxis(int new_size)
Resize CommonXaxis, increase size of the axis Update the range (bins) of the Axis (fFirst...
void UpdateTHStock()
to redefine