ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IndicatorFrame.cxx
Go to the documentation of this file.
1 
8 #include "IndicatorFrame.h"
9 
10 #include "../../utils/FullName.h"
11 #include "../../utils/Utils.h"
12 #include "../Controllers/ControllerIndicatorTHStock.h"
13 #include "../Garbage.h"
14 
15 #include <TGButton.h>
16 #include <TGColorSelect.h>
17 
19 
20 //for ROOT dicionnary
22 
23 IndicatorFrame::IndicatorFrame(const TGWindow *p, const char *name_frame, UInt_t w,UInt_t h):
24 TGVerticalFrame(p, w, h), fcontroller(0)
25 {
26 #ifdef DEBUG_CONT_FRAME
27  std::cout << "Entry Constructor IndicatorFrame w=" << w << " h= " << h <<" name_frame " << name_frame << std::endl;
28 #endif
29 
30  SetCleanup ( kDeepCleanup );
31 
32  // setup the name of IndicatorFrame : namestock_time == THStockFrame name
33  // like this unique relation between indicator or thstcok
34  // need to check if already existing before... to do
35  // certainly not necessary because unique controller now
36  SetName ( name_frame );
37 
38  // Change option inside the class, to get a border
39  // effect ??
40  ChangeOptions( (GetOptions() & ~kRaisedFrame) | kRaisedFrame );
41 }
42 
44 {
45 #ifdef DEBUG_CONT_FRAME
46  std::cout << "Destructor IndicatorFrame " << std::endl;
47 #endif
48  Cleanup();
49 
50 }
51 
52 // check if it is the first, main entry, call from HandleButton at the moment
53 bool IndicatorFrame::CheckFirstPad ( std::string fullname )
54 {
55 #ifdef DEBUG_CONT_FRAME
56  std::cout << "Entry CheckFirstPad with fullname " << fullname << std::endl;
57 #endif
58 
59  TGHorizontalFrame *tghframe;
60  TGFrameElement *el;
61 
62  TList *list = GetList();
63 
64  el = (TGFrameElement * ) list->At(0);
65  tghframe = (TGHorizontalFrame *) el->fFrame;
66 
67  //std::cout << "tghframe GetName " << tghframe->GetName() << std::endl;
68  std::string str_tmp_name = Utils::toString<const char *>( tghframe->GetName() );
69  if ( str_tmp_name == fullname )
70  return true;
71  else
72  return false;
73 }
74 
75 // test if IndicatorFrame List is empty, know if it is the first
77 {
78  if ( GetList()->First() == 0 ) {
79  return true;
80  }
81  else
82  return false;
83 }
84 
86 void IndicatorFrame::AddIndicator( std::string fullname, int color )
87 {
88  std::string indic_label;
89 
90 #ifdef DEBUG_CONT_FRAME
91  std::cout << "\n\t IndicatorFrame::AddIndicator fullname "<< fullname << std::endl;
92 #endif
93 
94  // creates a new indicator label with fullname
95  if ( CheckFirstPad() )
96  indic_label = FullName::GetFrameName( fullname ) ;
97  // add to an existing indicator
98  else
99  indic_label = FullName::GetShortName ( fullname );
100 
101 #ifdef DEBUG_CONT_FRAME
102  std::cout << "indic_label " << indic_label << std::endl;
103 #endif
104 
105  // Create and and Indicator label
106  IndicatorFrameLabel * hframe_label = new IndicatorFrameLabel ( this, indic_label.c_str(), fullname.c_str(), color );
107  AddFrame( hframe_label, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 2,2,2,2) );
108 
109  return;
110 }
111 
112 
116 // cannot delete, crash with signals...
117 void IndicatorFrame::DeleteLines( std::string fullname )
118 {
119 #ifdef DEBUG_CONT_FRAME
120  std::cout << "Entry IndicatorFrame::DeleteLines " << fullname << std::endl;
121 #endif
122 
123  TGFrameElement *el;
124  TIter next( GetList() );
125 
126  while ( (el = ((TGFrameElement *) next())) != 0 ) {
127  if ( el->fFrame->GetName() == fullname ) {
128  std::cout << " Remove " << el->fFrame->GetName() << std::endl;
129 
130  // crash only when deleting a line
131  // Remove the frame, from here
132  RemoveFrame ( el->fFrame );
133  // here crash in all cases, deleting a line and all
134  //HideFrame( el->fFrame );
135  // Remove but not deleted, cannot retrieve after
136  //crash if deleted, problems with signals
137  //el->fFrame = 0;
138  // do not call the destructor
139  //el->fFrame->Delete();
140  //delete (IndicatorFrameLabel*)(el->fFrame);
141 
142  // use garbage collector, frame will be killed after signal ends
143  Garbage & gb = Garbage::getInstance();
144  gb.Add(el->fFrame);
145  //Garbage * gb = Garbage::getInstance();
146  //gb->Add(el->fFrame);
147  }
148  }
149  std::cout << "Ok" << std::endl;
150  //needed for correct apparence ?
151  Resize(GetDefaultSize());
152 }
153 
155 {
156 #ifdef DEBUG_CONT_FRAME
157  std::cout << "Entry IndicatorFrame::HideLines " << std::endl;
158 #endif
159 
160  TGFrameElement *el;
161  TIter next( GetList() );
162 
163  // pass the first one
164  el = ( (TGFrameElement *) next() );
165 #ifdef DEBUG_CONT_FRAME
166  std::cout << " first el->fFrame->GetName() " << el->fFrame->GetName() << std::endl;
167 #endif
168 
169  // no need of main->MapSubwindows();... HideFrame....main->MapWindow(); done implicitly ??
170  while ( (el = ((TGFrameElement *) next())) != 0 ) {
171  std::cout << " Will hide " << el->fFrame->GetName() << std::endl;
172  HideFrame ( el->fFrame );
173  }
174  // try to solve problem visu
175  //Resize();
176  //MapSubwindows();
177 }
178 
180 {
181 #ifdef DEBUG_CONT_FRAME
182  std::cout << "Entry IndicatorFrame::ShowLines " << std::endl;
183 #endif
184 
185  TGFrameElement *el;
186  TIter next( GetList() );
187 
188  // pass the first one, already printed
189  el = ( (TGFrameElement *) next() );
190  std::cout << " first el->fFrame->GetName() " << el->fFrame->GetName() << std::endl;
191 
192  while ( (el = ((TGFrameElement *) next())) != 0 ) {
193  std::cout << " Will show " << el->fFrame->GetName() << std::endl;
194  ShowFrame ( el->fFrame );
195  }
196 }
197 
199 
201 // should be written as Process(), with message for button checks
203 {
204 #ifdef DEBUG_CONT_FRAME
205  std::cout << "Enter IndicatorFrame::HandleButtons" << std::endl;
206 #endif
207 
208  std::string classname;
209  std::string fullname;
210  //mode will be "DELETE", "SHOW", "HIDE"
211  std::string mode;
212  // to know if it is the first entry, will apply all
213  bool first_pad;
214 
215  // Handle all buttons of this class
216  TGButton *btn = (TGButton *) gTQSender;
217 
218  // the fullname was associated to the button, get the name of the IndicatorFrameLabel
219  fullname = btn->GetParent()->GetName();
220  // classname of the button
221  classname = btn->ClassName();
222 
223 #ifdef DEBUG_CONT_FRAME
224  std::cout << "this " << this << std::endl;
225  std::cout << "GetParent->GetParent classname " << btn->GetParent()->GetParent()->ClassName() << std::endl; //IndicatorFrame
226  std::cout << "GetParent->GetParent->GetName " << btn->GetParent()->GetParent()->GetName() << std::endl; //CAC_40
227  //std::cout << "GetParent->classname " << GetParent()->ClassName() << std::endl;
228  //std::cout << "GetParent->GetName " << GetParent()->GetName() << std::endl;
229  //std::cout << "classname " << ClassName() << std::endl;
230  //std::cout << "GetName " << GetName() << std::endl;
231  std::cout << "classname " << classname << std::endl;
232  std::cout << "fullname " << fullname << std::endl; //CAC40_DAY_SMA_10
233 #endif
234 
235  // needed for new version
236  first_pad = CheckFirstPad ( fullname );
237 #ifdef DEBUG_CONT_FRAME
238  std::cout << "first_pad " << first_pad << std::endl;
239 #endif
240 
241  // 3 possibilities: TextButton, CheckButton or ColorSelect
242  // should mix cases, but call controller as much as possible
243  // delete button
244  if ( classname == "TGTextButton" ) {
245 
246  mode = "DELETE";
247  // delete the connection but crash anyway
248  /*
249  btn->Disconnect("Clicked()");
250  btn->Disconnect("Pressed()");
251  //btn->Disconnect();
252  btn->BlockAllSignals( true );
253  //btn->SetEnabled();
254  */
255  // cannot delete the object
256  DeleteLines( fullname );
257 
258  if ( first_pad ) {
259  mode = "DELETE_ALL";
260  }
261  }
262  //show/hide button
263  else if ( classname == "TGCheckButton" ) {
264  // if off
265  if ( btn->IsDown() ) {
266 #ifdef DEBUG_CONT_FRAME
267  std::cout << " TGCheckButton is down, so to show " << std::endl;
268 #endif
269  mode= "SHOW";
270  if ( first_pad ) {
271  mode = "SHOW_ALL";
272  ShowLines();
273  }
274  }
275  // if on, hide but do not delete
276  else {
277 #ifdef DEBUG_CONT_FRAME
278  std::cout << " TGCheckButton is on, so to hide " << std::endl;
279 #endif
280  mode= "HIDE";
281  if ( first_pad ) {
282  mode = "HIDE_ALL";
283  HideLines();
284  }
285  }
286  }
287  // if here send signal, does not even send
288  else if ( classname == "TGColorSelect" ) {
289  // by default the button is black,
290  // should be blue as default, need to update
291 
292  // need to pass the color from the label
293  const IndicatorFrameLabel* fIndicframelabel_current = ( IndicatorFrameLabel *) btn->GetParent ();
294  Pixel_t color = fIndicframelabel_current->GetColorLabel();
295 #ifdef DEBUG_CONT_FRAME
296  std::cout << "Color selected " << std::endl;
297  std::cout << "Pixel_t color " << color << std::endl;
298  std::cout << "unsigned long color " << (unsigned long)color << std::endl;
299 #endif
300  // call controller, need to send the modification to THStockFrame
301  fcontroller->ModifyColorIndic( fullname, (unsigned long) color );
302  }
303  //problem never appeared, could use exception ?? not really keep for debug
304  else {
305  std::cout << "error IndicatorFrame::HandleButtons() classname button not known " << std::endl;
306  exit (1);
307  }
308 
309  //Need to resize if DELETE_ALL or SHOW_ALL. ok works
310  // maybe always ??
311  if ( ( mode == "SHOW_ALL" ) || ( mode == "HIDE_ALL" ) || ( mode == "DELETE_ALL" ) ) {
312  Resize();
313  }
314  // always, when delete problems...
315  // maybe always ?? do not change problem
316  //Resize();
317 
318  // inform controller of the action in all cases, need if IndicatorFrame must be deleted
319  fcontroller->UpdateIndicator( mode, fullname );
320  std::cout << "After fcontroller->UpdateIndicator in IndicatorFrame " << std::endl;
321  return;
322 }
323 
325 {
326  std::cout << "\n\t PrintList IndicatorFrame " << std::endl;
327 
328  //std::cout << "List of fHframe0 " << std::endl;
329  //GetList()->Print();
330  Option_t *opt;
331  opt="";
332  GetList()->Print(opt,3);
333 
334  std::string tmp_name;
335  //TGHorizontalFrame *tghframe;
336 
337  TIter next( GetList() );
338 
339  TGFrameElement *el2;
340 
341  //try to the second order, want to get the name of hidden label
342  TGFrameElement *el;
343  TGHorizontalFrame *el_tgh;
344 
345  while ((el = (TGFrameElement*)next())) {
346  el->Print();
347  std::cout << "name " << el->fFrame->GetName() << std::endl;
348  el_tgh = (TGHorizontalFrame *)el->fFrame;
349  TIter next2( el_tgh->GetList() );
350 
351  //TIter next2( el->GetList() );
352  while ( (el2 = ((TGFrameElement*) next2())) != 0 ) {
353  std::cout << "name2 " << el2->fFrame->GetName() << std::endl;
354  }
355  }
356  //std::cout << "List of fHframe_toolbar " << std::endl;
357  //fHframe_toolbar->GetList()->Print();
358 }
360 
362 //for ROOT dicionnary
364 
365 IndicatorFrameLabel::IndicatorFrameLabel( const TGWindow *p, const char *label, const char *fullname, const int color ) :
366  TGHorizontalFrame( p )
367 {
368 #ifdef DEBUG_CONT_FRAME
369  std::cout << "Entry Constructor IndicatorFrameLabel name_label " << fullname << std::endl;
370  std::cout << "label " << label << std::endl;
371  std::cout << "color " << color << std::endl;
372 #endif
373 
374  SetCleanup ( kDeepCleanup );
375  // Change option inside the class
376  //ChangeOptions( (GetOptions() & ~kRaisedFrame) | kRaisedFrame );
377 
378  // keep fullname for signal, used ??
379  SetName ( fullname );
380  // create the line
381  MakeLineLabel( Utils::toString<std::string>( label ), color );
382 }
383 
385 {
386 #ifdef DEBUG_CONT_FRAME
387  std::cout << "Destructor IndicatorFrameLabel " << std::endl;
388  //std::cout << "bnt HasConnection " << btn->HasConnection("Clicked()") << std::endl;
389 #endif
390  Cleanup();
391 }
392 
393 // need option if color is needed, but may change depending of other
394 // case CAC40 DJ
395 void IndicatorFrameLabel::MakeLineLabel( std::string label, const int color )
396 {
397  std::cout << "Entry IndicatorFrameLabel::MakeLineLabel() label " << label << std::endl;
398 
400  TGCheckButton *checkb = new TGCheckButton( this, "");
401  AddFrame ( checkb, new TGLayoutHints( kLHintsLeft | kLHintsCenterY, 1,1,1,1) );
402  checkb->SetState( kButtonDown );
403 
404  // original version, fParent is IndicatorFrame
405  checkb->Connect( "Clicked()", "IndicatorFrame", (void*)fParent, "HandleButtons()" );
406 
408  flabel_indic = new TGLabel( this, label.c_str() );
409  AddFrame( flabel_indic, new TGLayoutHints( kLHintsLeft | kLHintsCenterY ,2,2,2,2) );
410 
411 
413  TGTextButton *btn = new TGTextButton ( this, " ");
414  btn->ChangeOptions( (btn->GetOptions() & ~kFitHeight) | kFixedHeight );
415  btn->SetHeight( 10 );
416  AddFrame( btn, new TGLayoutHints( kLHintsRight | kLHintsCenterY , 1,1,1,1) );
417  btn->Connect( "Clicked()", "IndicatorFrame", (void*)fParent, "HandleButtons()" );
418  //btn->Connect( "Pressed()", "IndicatorFrame", (void*)fParent, "HandleButtons()" );
419 
421  TGColorSelect* fColorSel = 0;
422  if ( color != -1 ) {
423  // do not work with color , need RGB !
424  // strange if force init color, cannot change the color of the line
425  fColorSel = new TGColorSelect( this ); //, 0x0000ff );
426  AddFrame ( fColorSel, new TGLayoutHints( kLHintsRight | kLHintsCenterY ,2,2,2,2) );
427  //AddFrame ( fColorSel, new TGLayoutHints( kLHintsCenterY ,2,2,2,2) );
428 
429  //Modify text color, could overwrite ColorSelected in internal
430  fColorSel->Connect("ColorSelected(Pixel_t)","IndicatorFrameLabel",this,"SetColorLabel(Pixel_t)");
431  //Say to the parent
432  fColorSel->Connect("ColorSelected(Pixel_t)","IndicatorFrame", (void*)fParent, "HandleButtons()");
433  }
434  // lots of other test here, see previous version, tag 1
435 
437  if ( color != -1 ) {
438  SetColorLabel( color );
439  //SetColor(Pixel_t color, Bool_t emit = kTRUE)
440  fColorSel->SetColor( color, false );
441  }
442  //do not work, see other example
443  //else {
444  //HideFrame( fColorSel );
445  //}
446  Resize(GetDefaultSize());
447 }
448 
450 {
451 #ifdef DEBUG_CONT_FRAME
452  std::cout << "Entry SetColorLabel, slot to change label color " << color << std::endl;
453 #endif
454  flabel_indic->SetTextColor ( color );
455  fcolor_indic = color;
456 }
457 
458 
void HideLines()
hide/show all lines, except the first one
TGLabel * flabel_indic
simple label with indicator name, can change color of the label
void Add(TObject *)
Add a TOBject to be deleted.
Definition: Garbage.cxx:39
Deal with labels in IndicatorFrame.
void ModifyColorIndic(std::string fullname, unsigned long color)
void UpdateIndicator(std::string mode, std::string fullname)
UpdateIndicator, call by IndicatorFrame.
ControllerIndicatorTHStock * fcontroller
virtual ~IndicatorFrame()
void DeleteLines(std::string fullname)
new unique for Label and Indicator
Garbage collector for ROOT TObjects.
Definition: Garbage.h:30
void HandleButtons()
manages all buttons of IndicatorFrameLabel.
Pixel_t fcolor_indic
keep memory of the color of the associated indicator
static Garbage & getInstance()
Definition: Garbage.cxx:19
Pixel_t GetColorLabel() const
void MakeLineLabel(std::string fullname, const int color)
create a line with label and all buttons
void SetColorLabel(Pixel_t color)
Slot when color is changed, modify the text label color.
std::string GetFrameName(const std::string &fname)
Extract NameStock_Timescale (FrameName) from a fullname.
Definition: FullName.cpp:92
Show all data loaded in memory, allow to deal with Button.
std::string GetShortName(const std::string &fname)
Extract Indicator_params (string) from a fullname.
Definition: FullName.cpp:78
ClassImp(IndicatorFrame) IndicatorFrame
void PrintList()
for debug
void AddIndicator(std::string, int color)
Add an indicator , call MakeLineLabel now should be called by ControllerIndicatorTHStockFrame.