ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjectLine.cxx
Go to the documentation of this file.
1 
8 #include <iostream>
9 
10 #include <TPad.h>
11 // only for ObjectLine
12 #include <KeySymbols.h>
13 
14 #include "ObjectLine.h"
15 
16 #include "ListObjectStock.h"
17 #include "THStock.h"
18 #include "../CommonXAxis.h"
19 
20 // for ROOT dictionary
24 
26 
34 // protected function, should be able to call constructor from another constructor
35 // C++ 11 possible no ??
36 // now much more class, specificity done by the sub-class
37 // can still use default ?
38 void ObjectLine::InitLine( double x0, double y0, double x1, double y1)
39 {
40 #ifdef DEBUG_OBJSTOCK
41  std::cout << "ObjectLine::InitLine " << std::endl;
42 #endif
43 
44  // first check x0<x1, need for bin and date
45  // correct automatically
46  if ( x0 > x1 ) {
47  double t_x1 = x1;
48  double t_y1 = y1;
49  x1 = x0;
50  x0 = t_x1;
51  y1 = y0;
52  y0 = t_y1;
53  }
54  // construct the line
55  fline = new TLine ( x0, y0, x1, y1 );
56  //std::cout << " x0 x1 y0, y1 " << x0 << " " << x1 << " " << y0 << " " << y1 << std::endl;
57  // use as default
58  fline->SetLineWidth( 2 );
59  fline->SetLineColor ( 4 );
60 }
61 
62 // maybe need a clean constructor here, used by derived class now
64 {
65 #ifdef DEBUG_OBJSTOCK
66  std::cout << "Entry Constructor default Base ObjectLine " << std::endl;
67 #endif
68 }
69 
70 // used by ObjectStockIndicator, fits well
72 {
73 #ifdef DEBUG_OBJSTOCK
74  std::cout << "ObjectLine::ObjectLine( Int_t typeline, valueY ) " << " valuey0 " << valuey0 << std::endl;
75 #endif
76 
77  // set the type, kSupp, kTendance..
78  fTypeLine = tline;
79  InitLine ( 0., valuey0, 1.0, valuey0);
80 }
81 
82 // used ?? not sure
83 //should use init now
84 ObjectLine::ObjectLine ( double x0, double y0, double x1, double y1) : //, Int_t kMode ) :
86 {
87 #ifdef DEBUG_OBJSTOCK
88  std::cout << "Constructor ObjectLine with 4 arguments call InitLine " << std::endl;
89 #endif
90  InitLine ( x0, y0, x1, y1 );
91  // no use of kMode
92 }
93 
94 // extrapolate should be Tendance, here ObjectLine only for date, bin maybe
95 std::vector<float> ObjectLine::GetValues(int px, int py, time_t &date ) const
96 {
97 #ifdef DEBUG_OBJSTOCK
98  std::cout << "Entry ObjectLine::GetValues px/py where used to move ?? px/py " << px << " " << py << std::endl;
99 #endif
100 
101  std::vector<float> values;
102  Int_t bin;
103  Int_t bin2 = -1; //need because ref not work with default ??
104 
105  // to make clear
106  // bin send as reference, no use of bin, but keep existing function,
107  // -1 do not look for bin2 closer (Only PStockLine)
108  date = fParentTHStock->GetDateBinFromPixel( px, py, bin, bin2 );
109 #ifdef DEBUG_OBJSTOCK
110  std::cout << "ObjectLine::GetValues, need to extrapolate " << std::endl;
111  std::cout << "date " << date << " " << Utils::Time_tToString( date )<< " bin " << bin << std::endl;
112 #endif
113 
114  //Here want to exprapolateY
115  //Float_t value_pt = (Float_t) ExtrapolateYPad ( gPad->AbsPixeltoX( px ) );
116  // extrapolate should be Tendance, here ObjectLine only for date, bin maybe
117  // cannot use from ObjectLine, Extrapolate need coeff_d, origin
118  //double value_pt = ExtrapolateYPad ( gPad->AbsPixeltoX( px ) );
119  //std::cout << "value extrapolated " << value_pt << std::endl;
120  //values.push_back ( value_pt );
121  values.push_back ( 0. );
122  return values;
123 }
124 
125 // ok works, but should be overriden, do not want object point to Base !
126 Int_t ObjectLine::DistancetoPrimitive(Int_t px, Int_t py, AbstractObjectStock** object )
127 {
128 #ifdef DEBUG_OBJSTOCK
129  std::cout << "ObjectLine::DistancetoPrimitive return dist " << fline->DistancetoPrimitive( px, py ) << std::endl;
130  std::cout << "fline->ClassName() " << fline->ClassName() << std::endl;
131 #endif
132 
133  *object = this;
134  return fline->DistancetoPrimitive( px, py );
135 }
136 
137 // Take over TLine::Paint, could make better ??, not really need to SetValues
138 // no need of TParam here, SetValues or individual set up should work
139 // or if kLine, need to set Y0,Y1, X0=0,X1=1
140 
141 // very simple, all work done by thstock, could move a part ??
142 // here some extrapolation, easier for other, acess to bin ?? with parent
143 // anchor ?? with parent can call function DistancetoPoint of THStock ?? and gPad accessible from here !!
144 void ObjectLine::Paint( const Option_t* ) //option
145 {
146 #ifdef DEBUG_OBJSTOCK
147  std::cout << "\tObjectLine::Paint" << std::endl;
148 #endif
149  //keep for test
150  //std::cout << "X0 " << fline->GetX1() << " XtoPad " << gPad->XtoPad(fline->GetX1()) << std::endl;
151  //std::cout << "X1 " << fline->GetX2() << " XtoPad " << gPad->XtoPad(fline->GetX2()) << std::endl;
152  //std::cout << "Y0 " << fline->GetY1() << " XtoPad " << gPad->XtoPad(fline->GetY1()) << std::endl;
153  //std::cout << "Y1 " << fline->GetY2() << " XtoPad " << gPad->XtoPad(fline->GetY2()) << std::endl;
154  // X's already setup to correct in Pad coordinates from THStock::Paint
155  fline->PaintLine( fline->GetX1(), fline->GetY1(),
156  fline->GetX2(), fline->GetY2() );
157  // or use GetX0/X1 internal, more computation for nothing
158  //fline->PaintLine( GetX0(), GetY0(), GetX1(), GetY1() );
159 }
160 
162 
163 // Constructor
164 ObjectLineIndicator::ObjectLineIndicator ( std::string name, double value ) :
165  ObjectLine( TypeLine::kSupport, (double)value ) {//, name_line( name ) {
166 #ifdef DEBUG_OBJSTOCK
167  std::cout << "Entry Constructor ObjectLineIndicator name " << name << " value " << value << std::endl;
168  //std::
169 #endif
170  name_line = name;
171  // fixed here, no default for this value
172  fModeLine = kLine;
173 
174  //std::cout << " Before SetY " << std::endl;
175  /* crash
176  SetY0( value );
177  SetY1( value );
178  */
179  // why valueY0/Y1 certianly not here, but for Tendance
180  //std::cout << " End Constructor ObjectLineIndicator " << std::endl;
181 }
182 
183 std::vector<std::string> ObjectLineIndicator::MakeStringForStatusBar( int px, int /*py*/ ) const
184 {
185 #ifdef DEBUG_OBJSTOCK
186  std::cout << "Entry ObjectLineIndicator::MakeStringForStatusBar " << std::endl;
187  std::cout << "px " << px << std::endl;
188  std::cout << "NameObject " << GetNameObject() << std::endl;
189  std::cout << "fParentTHStock " << fParentTHStock << std::endl;
190 #endif
191  std::vector<std::string> vec_string;
192  std::string str1;
193 
194  int bin2;
195  int bin = fParentTHStock->GetBinFromPixel( px, bin2 );
196 #ifdef DEBUG_OBJSTOCK
197  std::cout << "bin " << bin << "bin2 " << bin2 << std::endl;
198 #endif
199 
200  time_t date = fParentTHStock->GetDateFromBin( bin );
201  vec_string.push_back( Utils::Time_tToString( date, true ) );
202 
203  str1 = GetNameObject() + " " + Utils::toString<float>( GetY0() );
204  vec_string.push_back( str1 );
205  return vec_string;
206 }
207 
209 {
210 #ifdef DEBUG_OBJSTOCK
211  std::cout << "ObjectLineIndicator::SetObjectStock easy than general function " << std::endl;
212  std::cout << "Hparam.xmin/xmax " << Hparam_stock.xmin << " Hparam_stock.xmax " << Hparam_stock.xmax << std::endl;
213 #endif
214  SetX0 ( Hparam_stock.xmin );
215  SetX1 ( Hparam_stock.xmax );
216 }
217 
219 
220 // Constructor used when manual drawing, cannot set up all data
221 // need to call FinalizeDrawableLine to complete
222 ObjectLineTendance::ObjectLineTendance( TypeLine & tline, double valueX, double valueY) :
223  ObjectLine(), coeff_d ( 0. ), origin ( 0 ), valueY0(0.), valueY1(0.),
224  ftbegin(0), ftend(0),fbin_begin(0),fbin_end(0)
225 {
226 #ifdef DEBUG_OBJSTOCK
227  std::cout << "Const ObjectLineTendance::ObjectLineTendance( int mode_line, doubleX, doubleY ) " << std::endl;
228  std::cout << "test X " << valueX << std::endl;
229  std::cout << "test Y " << valueY << std::endl;
230  //std::cout << "int modeline " << modeline << std::endl;
231 #endif
232  // Set the type support/tendance
233  fTypeLine = tline;
234  // use kSegment for Tendance by default
236 
237  InitLine ( valueX, valueY, valueX, valueY );
238  // set up all other member, later
239  // after finishing drawing in Finalise
240 }
241 
242 // need to recalculate in Pad axis, everytime it is paint
243 // reclaculated coeff_d in the axis of Pad Y is fine ( user ),
244 // x0/1 is modified ( can come from bin or time or Hparam_stock.xmin/max)
245 void ObjectLineTendance::RecalcCoeff_origin( double x0, double x1)
246 {
247 #ifdef DEBUG_OBJSTOCK
248  std::cout << "ObjectLineTendance::RecalcCoeff_origin" << std::endl;
249  std::cout << "x0 " << x0 << " x1 " << x1 << std::endl;
250 #endif
251 
252  double y0, y1;
253 
254  // use initial values, set up when first drawn : should correspond to bin and date
255  y0 = valueY0; y1 = valueY1;
256  // try with normal one, not they may be overwriten by extrapolation !
257  //y0 = GetY0(); //y1 = GetY1();
258 
259  //check y1 - yo sign, use Abs, no can keep negative
260  coeff_d = ( y1 - y0 ) / ( x1 - x0 );
261  origin = y0 - coeff_d * x0; // == y1 - coeff_d * x1
262 
263 #ifdef DEBUG_OBJSTOCK
264  std::cout << "y0 " << y0 << " y1 " << y1 << std::endl;
265  std:: cout << " coeff origin " << coeff_d << " " << origin << std::endl;
266  // just for test, origin should be equal
267  std:: cout << " should be equal coeff origin " << coeff_d << " " << y1 - coeff_d * x1 << std::endl;
268 #endif
269 }
270 
271 // cannot access intern data member ? to check
272 void ObjectLineTendance::InitCoeff_origin( double x0, double x1, double y0, double y1 )
273 {
274 #ifdef DEBUG_OBJSTOCK
275  std::cout << "ObjectLineTendance::InitCoeff_origin" << std::endl;
276  //std::cout << "x0 " << x0 << " x1 " << x1 << std::endl;
277 #endif
278 
279  //check y1 - yo sign, use Abs
280  coeff_d = ( y1 - y0 ) / ( x1 - x0 );
281  origin = y0 - coeff_d * x0; // == y1 - coeff_d * x1
282 
283 #ifdef DEBUG_OBJSTOCK
284  std:: cout << " coeff origin " << coeff_d << " " << origin << std::endl;
285 #endif
286  // just for test, origin should be equal
287  //std:: cout << " coeff origin " << coeff_d << " " << y1 - coeff_d * x1 << std::endl;
288 }
289 
290 
291 double ObjectLineTendance::GetXBorder( double y ) const
292 {
293 #ifdef DEBUG_OBJSTOCK
294  std::cout << "GetXBorder y " << y << std::endl;
295 #endif
296  double x_cross;
297 
298  x_cross = ( y - origin ) / coeff_d;
299  //std::cout << "ObjectLine::GetXBorder x return " << x_cross << std::endl;
300  return x_cross;
301 }
302 
303 double ObjectLineTendance::ExtrapolateYPad ( double x ) const
304 {
305 #ifdef DEBUG_OBJSTOCK
306  std::cout << "ExtrapolateYPad coeff_d origin " << coeff_d << " " << origin << std::endl;
307 #endif
308  double y_extra;
309  //std::cout << "ExtrapolateYPad coeff_d origin " << coeff_d << " " << origin << std::endl;
310  y_extra = coeff_d * x + origin;
311  //std::cout << "ExtrapolateYPad x= " << x << " y_extra= " << y_extra << std::endl;
312  return y_extra;
313 }
314 
316 {
317 #ifdef DEBUG_OBJSTOCK
318  std::cout << "\n\tEntry ObjectLineTendance::FinaliseDrawableLine()" << std::endl;
319  std::cout << "fcommon_axis " << fcommon_xaxis_th << std::endl;
320 #endif
321 
322 
323  //get closer bin / can get from obj_stock
324  Int_t bin_x0 = fcommon_xaxis_th->GetXAxis()->FindBin( GetX0() );
325  Int_t bin_x1 = fcommon_xaxis_th->GetXAxis()->FindBin( GetX1() );
326  SetBins ( bin_x0, bin_x1 );
327 
328 #ifdef DEBUG_OBJSTOCK
329  std::cout << "set bins " << bin_x0 << " " << bin_x1 << std::endl;
330  std::cout << "set bins ok " << std::endl;
331  std::cout << "test fParentTHStock " << fParentTHStock << std::endl;
332 #endif
333 
334  // need to use the parent THStock here, or could use fcommon_xaxis ?
335  time_t t0 = fParentTHStock->GetDateFromBin ( bin_x0 );
336  //std::cout << "after GetDateFromBin " << std::endl;
337  time_t t1 = fParentTHStock->GetDateFromBin ( bin_x1 );
338  //Set the ObjectLine, time or bin ?? make both
339  SetTimes( t0, t1 );
340  //std::cout << "Set Times t0/t1 " << t0 << " " << t1 << std::endl;
341 
342  InitCoeff_origin ( GetX0(), GetX1(), GetY0(), GetY1() );
343 
344  //keep final initial data in data member, keep Yvalues after extrapolation
345  // could keep the values centered in the bin, make it easier ??
346  SetInitValuesY();
347 #ifdef DEBUG_OBJSTOCK
348  std::cout << "InitValuesY Y0/Y1 " << valueY0 << " " << valueY1 << std::endl;
349 #endif
350  // aprroximate X to middle of the bin, common for all ??
351  SetX0( fcommon_xaxis_th->GetXAxis()->GetBinCenter( bin_x0 ) );
352  SetX1( fcommon_xaxis_th->GetXAxis()->GetBinCenter( bin_x1 ) );
353 #ifdef DEBUG_OBJSTOCK
354  std::cout << "new X0 X1 " << GetX0() << " " << GetX1() << std::endl;
355 #endif
356 
357  // Extrapolate with previous Yvalues, fine like this
358  SetY0( ExtrapolateYPad( GetX0() ));
359  SetY1( ExtrapolateYPad( GetX1() ));
360 #ifdef DEBUG_OBJSTOCK
361  std::cout << "GetY0/Y1 after extrapolate " << GetY0() << " " << GetY1() << std::endl;
362 #endif
363 }
364 
365 //set the origin after a rotation, assure than actual position x,y is kept
366 void ObjectLineTendance::SetOrigin ( double & x, double & y )
367 {
368 #ifdef DEBUG_OBJSTOCK
369  std::cout << "Set origin " << x << " " << y << " " << origin << std::endl;
370 #endif
371  origin = y - coeff_d * x;
372 #ifdef DEBUG_OBJSTOCK
373  std::cout << "new origin " << origin << std::endl;
374 #endif
375 }
376 
377 std::vector<std::string> ObjectLineTendance::MakeStringForStatusBar( int px, int py ) const
378 {
379 #ifdef DEBUG_OBJSTOCK
380  std::cout << "Entry ObjectLineTendance::MakeStringForStatusBar px/py " << std::endl;
381 #endif
382  std::string text_str0, text_str1;
383  std::vector<std::string> vec_string;
384 
385  std::vector<float> values;
386  double fvalues;
387  time_t date;
388 
389  if ( IsSupport() ) {
390  values.push_back ( GetY0() );
391  text_str0= "";
392  text_str1 = "Support = " + Utils::toString(values[0]);
393  } else {
394 #ifdef DEBUG_OBJSTOCK
395  std::cout << "ObjectLineTendance::MakeStringForStatusBar, call get value to extrapolate " << std::endl;
396 #endif
397  // values not used, only want the date from px
398  values = GetValues( px, py, date );
399  text_str0 = Utils::Time_tToString( date, true );
400  // overwrite values
401  fvalues = ExtrapolateYPad( gPad->AbsPixeltoX( px ) );
402  //std::cout << "new value " << std::endl;
403  text_str1 = "Tendance = "+ Utils::toString<double>(fvalues);
404  }
405 
406  vec_string.push_back(text_str0);
407  vec_string.push_back(text_str1);
408  return vec_string;
409 }
410 
411 // to reoptimise, to use ToPaint()
412 // 2 main case, Support or Tendance, but can use same logic ??
414 {
415 #ifdef DEBUG_OBJSTOCK
416  std::cout << "Entry ObjectLineTendance::SetObjectStock " << std::endl;
417  std::cout << "Hparam_stock.xfirst/xlast " << Hparam_stock.xfirst << " " << Hparam_stock.xlast << std::endl;
418 #endif
419 
420  double tmp_x;
421  // not used by kLine ?? but still exists ?? to check
422  int bin_x0 = GetBinBegin();
423  int bin_x1 = GetBinEnd();
424 
425  // default xvalues of the reference bin in pad coordinate
426  double tmp_x0 = gPad->XtoPad( fcommon_xaxis_th->GetXAxis()->GetBinCenter( bin_x0 ) );
427  double tmp_x1 = gPad->XtoPad( fcommon_xaxis_th->GetXAxis()->GetBinCenter( bin_x1 ) );
428 
429  // best, always true coeff in Pad coordinate, after just need to modify X and extrapolate
430  // dependent of the Pad ?? or can store it ?? to check
431  RecalcCoeff_origin( tmp_x0, tmp_x1 );
432 
433  // comment for compilation test without Hparam_stock
434  // introduce different cases, can generalise ?
435  // kLine [-inf, +inf]
436  if ( IsLine() ) {
437 #ifdef DEBUG_OBJSTOCK
438  std::cout << "IsLine true" << std::endl;
439 #endif
440  // all case line extends to the full pad
441  SetX0 ( Hparam_stock.xmin );
442  SetX1 ( Hparam_stock.xmax );
443 
444  // simpler case it is a straight horizontal line
445  /*
446  if ( IsSupport() ) {
447  // just check if need to be printed
448  //std::cout << "PaintLine because object_line->IsSupport true continue " << std::endl;
449  //paint only if inside the pad, can use only y0 == y1
450 
451  // to cjheck why this test
452  // original version, not sure what was GetValueY0 ??
453  //if ( ( GetValueY0() > Hparam_stock.ymin) && ( GetValueY0() < Hparam_stock.ymax) )
454  //Paint();
455  //continue;
456  // now can exit after paint
457  //return;
458  }
459  */
460  // else a compelte line
461  // extrapolate the Y value to the border limit
462  SetY0 ( ExtrapolateYPad ( Hparam_stock.xmin ) );
463  SetY1 ( ExtrapolateYPad ( Hparam_stock.xmax ) );
464  }
465 
466  else {
467  //else not Line, HalfLine or Segment (Segment = 2 HalfLine), complexe but less code
468  // HalfLine1 [point, inf], check position of X0, apply to Segment as well
469  if ( IsHalfLine1() || IsSegment() ) {
470  //std::cout << "kHalfLine1 or Segment " << std::endl;
471 
472  if ( bin_x0 < Hparam_stock.xfirst ) {
473  bin_x0 = Hparam_stock.xfirst;
474  // recompute tmp_x0, otherwise use default
475  // could get lowedge here
476  tmp_x0 = gPad->XtoPad( fcommon_xaxis_th->GetXAxis()->GetBinCenter( bin_x0 ) );
477  //std::cout << "modified bin_x0 " << Hparam_stock.xfirst << " and tmp_x0 " << tmp_x0 << std::endl; // modify tmp_x0
478  }
479  //std::cout <<"SetX0/Y0 to "<< tmp_x0 << " " << object_line->ExtrapolateYPad ( tmp_x0 ) << std::endl;
480  // SetX0 and Y0 coeff_d is correct
481  SetX0 ( tmp_x0 );
482  SetY0 ( ExtrapolateYPad ( tmp_x0 ) );
483 
484  // needed is HalfLine extrapolate for X1
485  if ( IsHalfLine1() ) {
486  //std::cout << "kHalfLine1 only" << std::endl;
487  //SetX1 and Y1 for the half line
488  SetX1 ( Hparam_stock.xmax );
489  SetY1 ( ExtrapolateYPad ( Hparam_stock.xmax ) );
490 
491  //test bad effect
492  if ( bin_x0 == Hparam_stock.xlast) {
493 #ifdef DEBUG_OBJSTOCK
494  std::cout << "bad effect " << std::endl;
495  // could exit here
496 #endif
497  //doNotDraw = true;
498  }
499  }
500  }
501  // HalfLine2 [-inf, point]
502  if ( IsHalfLine2() || IsSegment() ) {
503  //std::cout << "kHalfLine2 or Segment " << std::endl;
504  if ( bin_x1 > Hparam_stock.xlast ) {
505  bin_x1 = Hparam_stock.xlast;
506  //recompute tmp_x1
507  tmp_x1 = gPad->XtoPad( fcommon_xaxis_th->GetXAxis()->GetBinCenter( bin_x1 ) );
508  //std::cout << "modified bin_x1 " << Hparam_stock.xlast << " and tmp_x1 " << tmp_x1 << std::endl;
509  }
510  //Should set X1, for both half line and segment
511  //std::cout << "SetX1/Y1 to tmp_x1 " << tmp_x1 << " " << object_line->ExtrapolateYPad ( tmp_x1 ) << std::endl;
512  SetX1 ( tmp_x1 );
513  SetY1 ( ExtrapolateYPad ( tmp_x1 ) );
514  // finalize HalfLine2
515  if ( IsHalfLine2() ) {
516  //SetX0 and Y0 for the half line
517  SetX0 ( Hparam_stock.xmin );
518  SetY0 ( ExtrapolateYPad ( Hparam_stock.xmin ) );
519  //test bad effect
520  if ( bin_x1 == Hparam_stock.xfirst) {
521 #ifdef DEBUG_OBJSTOCK
522  std::cout << " bad effect kHalfLine2 " << std::endl;
523  // could exit here
524 #endif
525  //doNotDraw = true;
526  }
527  }
528  }
529  } //else not kLine, miss the indentation
530 
531  //test Y outside border, apply for all even segment
532  //here group all cases, could make a function, not needed now but later..
533 #ifdef DEBUG_OBJSTOCK
534  std::cout << "Pad Ymin/max " << Hparam_stock.ymin << " " << Hparam_stock.ymax << std::endl;
535 #endif
536  // check Y1
537  if ( ( GetY1() < Hparam_stock.ymin) || ( GetY1() > Hparam_stock.ymax) ) {
538  //std::cout << "out of Y1 border !!! " << std::endl;
539  //cannot been both so case
540  if ( GetY1() < Hparam_stock.ymin ) {
541  //Extrapolate coeff_d is good here
542  tmp_x = GetXBorder ( Hparam_stock.ymin );
543  } else {
544  tmp_x = GetXBorder ( Hparam_stock.ymax );
545  }
546  //ok get correct X in Pad, apply both cases
547  SetX1( tmp_x );
548  SetY1( ExtrapolateYPad ( tmp_x ) );
549  }
550  //same for Y0
551  if ( ( GetY0() < Hparam_stock.ymin) || ( GetY0() > Hparam_stock.ymax) ) {
552  //std::cout << "out of Y0 border !!! " << std::endl;
553  if ( GetY0() < Hparam_stock.ymin ) {
554  tmp_x = GetXBorder ( Hparam_stock.ymin );
555  } else {
556  tmp_x = GetXBorder ( Hparam_stock.ymax );
557  }
558  SetX0( tmp_x );
559  SetY0( ExtrapolateYPad ( tmp_x ) );
560  }
561 }
562 
563 void ObjectLineTendance::Paint( const Option_t* )
564 {
565 #ifdef DEBUG_OBJSTOCK
566  std::cout << "ObjectLineTendance::Paint " << std::endl;
567  //std::cout << "fline " << fline << std::endl;
568  //std::cout << "GetX0/X1 " << GetX0() << " " << GetX1() << std::endl;
569  //std::cout << "GetY0/Y1 " << GetY0() << " " << GetY1() << std::endl;
570 #endif
571  // should be as simple as, ok works !
572  fline->Paint();
573 }
574 
575 void ObjectLineTendance::ExecuteEvent(Int_t event, Int_t px, Int_t py)
576 {
577  int kMaxDiff = 20; // default 20
578  // all come from TLine, static ?? memo between call
579  // all memorized between call, cannot be parallelized
580  static bool p1, p2, pL;
581  static int d1,d2,px1,px2,py1,py2;
582  static int pxold, pyold, px1old, py1old, px2old, py2old;
583  int dx, dy;
584 
585 #ifdef DEBUG_OBJSTOCK
586  std::cout << "Entry ObjectLineTendance::ExecuteEvent " << std::endl;
587  std::cout << "pxold/pyold " << pxold << " " << pyold << std::endl;
588  std::cout << "px/py " << px << " " << py << std::endl;
589 #endif
590 
591  switch (event) {
592 
593  // no break, so always called first when button is stayed down, then call the appropriate event
594  case kButton1Down:
595  #ifdef DEBUG_OBJSTOCK
596  std::cout << " kButton1Down no break , setLineColor(-1) " << std::endl;
597  #endif
598 
599  gVirtualX->SetLineColor(-1);
600  TAttLine::Modify(); //Change line attributes only if necessary
601  // No break !!! so call kMouseMotion or other just after
602  // really needed ??
603  break;
604 
605  // select a part of the line : extremity or full line
606  // always called even if not selected
607  case kMouseMotion:
608  #ifdef DEBUG_OBJSTOCK
609  std::cout << "kMouseMotion " << std::endl;
610  #endif
611  px1 = gPad->XtoAbsPixel( GetX0() );
612  py1 = gPad->YtoAbsPixel( GetY0() );
613  px2 = gPad->XtoAbsPixel( GetX1() );
614  py2 = gPad->YtoAbsPixel( GetY1() );
615  //std::cout << "px1 / py1 " << px1 << " " << py1 << std::endl;
616  //default false, need because static ??
617  p1 = p2 = pL = kFALSE;
618 
619  d1 = abs(px1 - px) + abs(py1-py); //simply take sum of pixels differences
620  if (d1 < kMaxDiff) { //*-*================>OK take point number 1
621  px1old = px1; py1old = py1;
622  p1 = kTRUE;
623  gPad->SetCursor(kPointer);
624  return;
625  }
626  d2 = abs(px2 - px) + abs(py2-py); //simply take sum of pixels differences
627  if (d2 < kMaxDiff) { //*-*================>OK take point number 2
628  px2old = px2; py2old = py2;
629  p2 = kTRUE;
630  gPad->SetCursor(kPointer);
631  return;
632  }
633  // if end point not selected, more than kMaxDiff select the full line
634  //std::cout << "no end point selected, set pL true " << std::endl;
635  pL = kTRUE;
636  pxold = px; pyold = py;
637  gPad->SetCursor(kMove);
638  break;
639 
640  // move one point of the line
641  case kButton1Motion:
642  #ifdef DEBUG_OBJSTOCK
643  std::cout << "kButton1Motion " << std::endl;
644  #endif
645  if (p1) {
646  // same trick here ?? redraw to delete the line !!
647  gVirtualX->DrawLine(px1old, py1old, px2, py2);
648  gVirtualX->DrawLine(px, py, px2, py2);
649  px1old = px;
650  py1old = py;
651  }
652  if (p2) {
653  gVirtualX->DrawLine(px1, py1, px2old, py2old);
654  gVirtualX->DrawLine(px1, py1, px, py);
655  px2old = px;
656  py2old = py;
657  }
658  if (pL) {
659  gVirtualX->DrawLine(px1, py1, px2, py2);
660  dx = px-pxold; dy = py-pyold;
661  px1 += dx; py1 += dy; px2 += dx; py2 += dy;
662  gVirtualX->DrawLine(px1, py1, px2, py2);
663  pxold = px;
664  pyold = py;
665  }
666  break;
667 
668  // when release button, set value
669  case kButton1Up:
670  #ifdef DEBUG_OBJSTOCK
671  std::cout << "kButton1Up " << std::endl;
672  #endif
673  //??
674  //if (gROOT->IsEscaped()) {
675  // gROOT->SetEscape(kFALSE);
676  // break;
677  //}
678  //do not make test NDC
679 
680  //need to check if moved, otherwise just for selection
681  //no good, called everytime..
682  if ( ( px==pxold ) && ( py=pyold ) ) {
683  std::cout << "px==pxold && py==pyold what to do !!!" << std::endl;
684  }
685 #ifdef DEBUG_OBJSTOCK
686  std::cout << "p1, p2, pL " << p1 << " " << p2 << " " << pL << std::endl;
687 #endif
688 
689  // good to do, replace with real value, avoid gPad !!
690  // could use an intermadiate, and finally set the final values
691 
692  // move line if pl is true
693  // move extremity if p1/p2 is true
694  // p1/p2 use only px, could be real value
695  if (p1) {
696  SetX0 ( gPad->PadtoX(gPad->AbsPixeltoX(px)) );
697  SetY0 ( gPad->PadtoY(gPad->AbsPixeltoY(py)) );
698  }
699  if (p2) {
700  SetX1 ( gPad->PadtoX(gPad->AbsPixeltoX(px)) );
701  SetY1 ( gPad->PadtoY(gPad->AbsPixeltoY(py)) );
702  }
703  // set both extremity to new values
704  if (pL) {
705  SetX0 ( gPad->PadtoX(gPad->AbsPixeltoX(px1)) );
706  SetY0 ( gPad->PadtoY(gPad->AbsPixeltoY(py1)) );
707  SetX1 ( gPad->PadtoX(gPad->AbsPixeltoX(px2)) );
708  SetY1 ( gPad->PadtoY(gPad->AbsPixeltoY(py2)) );
709  }
710 
711  /* test support / fibo
712  if (TestBit(kVertical)) {
713  if (p1) fX2 = fX1;
714  if (p2) fX1 = fX2;
715  }
716  if (TestBit(kHorizontal)) {
717  if (p1) fY2 = fY1;
718  if (p2) fY1 = fY2;
719  }*/
720  // need same, test Support/tendance
721 #ifdef DEBUG_OBJSTOCK
722  std::cout << " IsSupport ? " << IsSupport() << std::endl;
723 #endif
724  if ( IsSupport() ) {
725  if ( p1 ) SetY1( GetY0() );
726  if ( p2 ) SetY0( GetY1() );
727  // pL should be ok for support, it is ok for support
728  }
729 
730  // here particular code, need to change YValues
731  // need check Anchor, all done in THStock, simpler to call THStock function ??
732 
733  // specificity of LineTendance,
734  // ok move the line !!
735  // but do make a support a tendance !!
736  // Set InitValues, will set the real value for drawing
737  SetInitValuesY();
738 
739  // reset pX ?? will be reset after anyway
740  // reset when kMouseMotion, strange...
741  // try with setup to FALSE here
742  p1 = p2 = pL = kFALSE;
743 
744  // need to check if moved, otherwise just for selection
745  // last commented
746  // fParentTHStock->MoveObjectLine ( this ); //can check, Anchor, set bin if different
747  // std::cout << "last commented MoveObjectLine " << std::endl;
748 
749  gPad->Modified(kTRUE);
750  // why this ?? not change anything
751  //gVirtualX->SetLineColor(-1);
752  break;
753 
754  //try with keyboard, ok use px py
755  case kKeyPress:
756  #ifdef DEBUG_OBJSTOCK
757  std::cout << "kKeyPress " << event << " px " << px << " py " << py << std::endl;
758  #endif
759  Int_t key, keysym;
760  //if key pressed pixel changed to key value, no access to position anymore
761  key = px;
762  keysym = py;
763  //printf("symbol = %c (%x)\n", key, keysym);
764 
765  // can send own function to deal with all possibilites, anyway need to call THStock ?? not sure
766  switch ((EKeySym)keysym) {
767 
768  // translation T
769  case kKey_t:
771 //#ifdef DEBUG_OBJSTOCK
772  // std::cout << "set Transalation" << std::endl;
773  std::cout << "get kTranslate " << EditorObjStock::GetTranslate() << std::endl;
774 //#endif
775  break;
776  // rotation R
777  case kKey_r:
779 //#ifdef DEBUG_OBJSTOCK
780 // std::cout << "set Rotation" << std::endl;
781  std::cout << "get kRotat " << EditorObjStock::GetRotate() << std::endl;
782 //#endif
783  break;
784 
785  // deal with move, left rigth no used yet
786  case kKey_Left:
787  std::cout<<"left arrow"<<std::endl;
788  break;
789  case kKey_Right:
790  std::cout<<"rightarrow"<<std::endl;
791  break;
792 
793  case kKey_Down:
794  std::cout<<"down arrow, last commented "<<std::endl; // down sense is down, or send key to function ?? better !
795  //if ( EditorObjStock::GetTranslate() ) fParentTHStock->TranslateObjStock( this, false, "transl", pxold, pyold );
796  //if ( EditorObjStock::GetRotate() ) fParentTHStock->TranslateObjStock( this, false, "rotat", pxold, pyold );
797  MoveObjectLine( false );
798  break;
799 
800  case kKey_Up:
801  std::cout << "up arrow, last commented " << std::endl; // up sense is true
802  //std::cout << " gettranslate " << EditorObjStock::GetTranslate () << std::endl;
803  //if ( EditorObjStock::GetTranslate() ) fParentTHStock->TranslateObjStock( this, true, "transl", pxold, pyold );
804  //if ( EditorObjStock::GetRotate() ) fParentTHStock->TranslateObjStock( this, true, "rotat", pxold, pyold );
805  // pass only the direction ( positive/negative )
806  MoveObjectLine( true );
807  break;
808 
809  case kKey_Return:
810  std::cout << "kKey_Return " << std::endl;
811  break;
812 
813  default :
814  //#ifdef DEBUG_OBJSTOCK
815  std::cout << "default case unset trans and rotat" << std::endl;
816  //#endif
817  //need a graphic in GUIMainFrame, how to unset automatically ??
818  //EditorObjStock::SetTranslate ( false );
819  //EditorObjStock::SetRotate ( false );
820  break;
821  }
822  return;
823 
824  default :
825 //#ifdef DEBUG_OBJSTOCK
826  std::cout << "default case no event associated, nothing to do " << std::endl;
827 //#endif
828  break;
829  } //end switch
830 
831 }
832 
833 // new added, see later for polymorphisme,
834 // but here the only clas to be movable for the moment
835 // THStock::TranslateObjStock ( ObjectLine * obj_stock, bool sense, std::string mode, Int_t pxold, Int_t pyold )
836 void ObjectLineTendance::MoveObjectLine( bool kdir ) //kModeMove kmove )
837 {
838 #ifdef DEBUG_OBJSTOCK
839  std::cout << "Entry ObjectLineTendance::MoveObjectLine " << std::endl;
840  std::cout << "kdir " << kdir << std::endl; // " ,kmove " << kmove <<
841 #endif
842 
843  double new_coeff,old_coeff = 0.;
844 
845  // apply a translation, only along Y
847 #ifdef DEBUG_OBJSTOCK
848  std::cout << "mode translation " << std::endl;
849 #endif
850  // increase positively
851  if ( kdir == true ) {
852  SetY0 ( GetY0() + 5. ); SetY1 ( GetY1() + 5. );
853  // negatively
854  } else {
855  /*valueY0 -= 5.0; valueY1 -= 5.0;*/
856  SetY0 ( GetY0() - 5. ); SetY1 ( GetY1() - 5. );
857  }
858 
859 #ifdef DEBUG_OBJSTOCK
860  std::cout << "new valueY0 " << valueY0 << std::endl;
861  std::cout << "new valueY1 " << valueY1 << std::endl;
862  std::cout << "new Y0/Y1 " << GetY0() << "/" << GetY1() << std::endl;
863 #endif
864 
865  // apply a rotation
866  } else if ( EditorObjStock::GetRotate() ) {
867 #ifdef DEBUG_OBJSTOCK
868  std::cout << "mode rotation " << std::endl;
869 #endif
870  old_coeff = GetCoeffD();
871 #ifdef DEBUG_OBJSTOCK
872  std::cout << "old_coeff " << old_coeff << std::endl;
873 #endif
874  // increase positively
875  if ( kdir == true ) {
876  new_coeff = old_coeff * 1.025;
877  //SetCoeffD ( new_coeff );
878 
879  } else {
880  new_coeff = old_coeff * 0.975;
881  //SetCoeffD ( old_coeff*0.975 );
882  //SetCoeffD ( new_coeff );
883 
884  }
885  SetCoeffD ( new_coeff );
886 #ifdef DEBUG_OBJSTOCK
887  std::cout << "new coeff " << GetCoeffD() << std::endl;
888 #endif
889  // original call, from THStock
890  /*
891  //need to set origin, at which x ?? for all segment, halfline... current position is good
892  obj_stock->SetOrigin( gPad->AbsPixeltoX(pxold), gPad->AbsPixeltoY(pyold) );
893  //need to extrapolate Y, X not modified
894  //work like this for all line, halflinem segment
895  obj_stock->SetY0 ( obj_stock->ExtrapolateYPad ( GetXPadFromBin (obj_stock->GetBinBegin()) ) );
896  obj_stock->SetY1 ( obj_stock->ExtrapolateYPad ( GetXPadFromBin (obj_stock->GetBinEnd ()) ) );
897  */
898  }
899  // any of tranlsate or rotate is set to true
900 #ifdef DEBUG_OBJSTOCK
901  else {
902 
903  std::cout << "any transl or rotate selected " << std::endl;
904  }
905 #endif
906  // once common data have been set, finalize it
907  // logic in Finalize, correct Y0/Y1 and then
908  SetInitValuesY();
909 
910  // both are required for working, could be in a calling function
911  gPad->Modified();
912  gPad->Update();
913 
914  // could have something similar
915  //Modified();
916  //Update();
917  // or
918  //fParentTHStock->Modified();
919  //fParentTHStock->Update();
920 }
921 
922 
ClassImp(ObjectLine) ClassImp(ObjectLineIndicator) ClassImp(ObjectLineTendance) void ObjectLine
wrapper to TLine constructor
Definition: ObjectLine.cxx:21
void SetY0(double y0)
Definition: ObjectLine.h:102
double coeff_d
most general for drawing a line, y = ax + b and moving as well, rotate a, translate b ! a and b not f...
Definition: ObjectLine.h:236
virtual std::string GetNameObject() const
pure-virtual access
Definition: ObjectLine.h:80
ObjectLineIndicator()
constructors
Definition: ObjectLine.h:182
double GetY1() const
Definition: ObjectLine.h:98
virtual std::vector< float > GetValues(int px, int py, time_t &date) const
used by MakeStringForStatusBar only base in ObjectLine should be very simple
Definition: ObjectLine.cxx:95
virtual void SetObjectStock(ListDataStockBase *, CommonXAxis *, Hparam_stock_t &)
implements a easy way for this case only set to xmin xmax
Definition: ObjectLine.cxx:208
Double_t xmin
Definition: Hparam_stock.h:32
ModeLine fModeLine
kLine, kSegment, kHalfSegment0, kHalfSegment1
Definition: ObjectLine.h:46
virtual bool IsHalfLine1()
Definition: ObjectLine.h:121
double valueY0
save initial values, y's overridden if Lines Y initial values , no overloaded by line->SetY, here stay constant associated to fbin_begin/fend
Definition: ObjectLine.h:241
TLine * fline
use composition TLine*, valable for all derived class
Definition: ObjectLine.h:51
void SetBins(Int_t bin_x0, Int_t bin_x1)
Definition: ObjectLine.h:286
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py, AbstractObjectStock **obj)
Definition: ObjectLine.cxx:126
Double_t ymin
Definition: Hparam_stock.h:36
return values
Definition: ObjectStock.cxx:37
void InitCoeff_origin(double x0, double x1, double y0, double y1)
Definition: ObjectLine.cxx:272
void SetCoeffD(double &new_coeff)
Definition: ObjectLine.h:271
virtual void Paint(const Option_t *="")
Paint the objet, to overide.
Definition: ObjectLine.cxx:563
virtual void MoveObjectLine(bool kdir)
pass the direction ( positive, negative ) to extend
Definition: ObjectLine.cxx:836
double GetCoeffD() const
member functions specific
Definition: ObjectLine.h:270
virtual std::vector< std::string > MakeStringForStatusBar(int px, int py) const
specific output for ObjectLineIndicator
Definition: ObjectLine.cxx:183
double GetX0() const
wrapper functions to fline, need public for all ??
Definition: ObjectLine.h:95
Hparam_stock_t Hparam_stock
Int_t GetBinFromPixel(Int_t px, Int_t &total_bin) const
called by ObjectStock, for StatusBar
Definition: THStock.cxx:509
virtual void SetObjectStock(ListDataStockBase *, CommonXAxis *, Hparam_stock_t &)
used for from the listdata
Definition: ObjectLine.cxx:413
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Make all drawable modification, move by mouse and arrow.
Definition: ObjectLine.cxx:575
Define the template ListObjectStock<T> in a separate header.
Regroup sub-hierarchy related to the LineObject :
virtual bool IsSupport() const
Definition: ObjectLine.h:134
void InitLine(double x0, double y0, double x1, double y1)
Double_t xmax
Definition: Hparam_stock.h:33
virtual bool IsLine()
Definition: ObjectLine.h:120
virtual void Paint(const Option_t *="")
Paint the objet, to overide.
Definition: ObjectLine.cxx:144
std::string toString(const T &t)
Definition: Utils.h:69
std::string Time_tToString(const time_t &time, const bool b_hour)
Return a string representing the date All times are expressed in the localtime.
Definition: Utils.cpp:157
virtual void SetTimes(time_t begin, time_t end)
Definition: ObjectLine.h:283
time_t GetDateFromBin(Int_t bin) const
called by ObjectLine need the date from a bin
Definition: THStock.cxx:488
TypeLine fTypeLine
TypeLine, enum : kNone, kSupport, kTendance, kFibo.
Definition: ObjectLine.h:48
class for drawing graph
virtual double GetXBorder(double y) const
specific for extrapolation return X value where border is crossed
Definition: ObjectLine.cxx:291
TAxis * GetXAxis()
Definition: CommonXAxis.h:54
void SetOrigin(double &x, double &y)
Definition: ObjectLine.cxx:366
virtual double ExtrapolateYPad(double) const
extrapolate y fom line equation
Definition: ObjectLine.cxx:303
double GetY0() const
Definition: ObjectLine.h:97
Used for free drawing of support/tendance Add a general line description with coeef_d and origin : y ...
Definition: ObjectLine.h:230
virtual std::vector< std::string > MakeStringForStatusBar(int px, int py) const
create the string for the StatusBar
Definition: ObjectLine.cxx:377
void FinaliseDrawableLine(CommonXAxis *fcommon_xaxis_th)
set up all data member after drawing.
Definition: ObjectLine.cxx:315
Abstract base class for the ListDataStock, for storing base pointers in vectors.
Definition: ListDataStock.h:50
void SetY1(double y1)
Definition: ObjectLine.h:103
std::string name_line
add a name, absent in AbstractObjectStock
Definition: ObjectLine.h:38
virtual bool IsHalfLine2()
Definition: ObjectLine.h:122
void SetX0(double x0)
Definition: ObjectLine.h:100
Define an abstract base class for all objects to be painted in a THStock.
Int_t GetBinBegin() const
Definition: ObjectLine.h:278
double GetX1() const
Definition: ObjectLine.h:96
virtual bool IsSegment()
Definition: ObjectLine.h:123
for all ObjectLines
Definition: ObjectLine.h:33
TypeLine
c++ 11 style, used by both EditorObjectStock and ObjectLine cannot make dictionary with enum class ! ...
void SetX1(double x1)
Definition: ObjectLine.h:101
Line for drawing with indicator, eg, RSI 30-70 Could be in Collection or in THStock They are fixed : ...
Definition: ObjectLine.h:178
time_t GetDateBinFromPixel(Int_t px, Int_t py, Int_t &bin, Int_t &bin2) const
return both the date and two bins called only ObjectLine::GetValues
Definition: THStock.cxx:531
void RecalcCoeff_origin(double x0, double x1)
mathematical functions
Definition: ObjectLine.cxx:245
ObjectLineTendance()
default constructor
Definition: ObjectLine.h:258
Int_t GetBinEnd() const
Definition: ObjectLine.h:279
Double_t ymax
Definition: Hparam_stock.h:37