ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TPadStock.cxx
Go to the documentation of this file.
1 
8 // lots of call to DistancetoPrimitive
9 //#undef DEBUG
10 
11 #include <TList.h>
12 #include <TFrame.h>
13 #include <TROOT.h>
14 
15 #include "TPadStock.h"
16 
17 #include "EditorObjStock.h"
18 #include "THStock.h"
19 #include "ObjectLine.h"
20 
21 //ROOT dictionary, not needed even if slots received !
22 // because derive from TPad ??
23 
24 // maybe needed for GetClassName ??
25 //ClassImp(TPadStock);
26 
27 TPadStock::TPadStock( const char* name, const char* title, Double_t x1, Double_t y1, Double_t x2, Double_t y2, Color_t color, Short_t bordersize, Short_t bordermode) :
28 TPad ( name, title, x1, y1, x2, y2, color, bordersize, bordermode )
29 {
30 #ifdef DEBUG_OBJSTOCK
31  std::cout << "Constructor TPadStock" << std::endl;
32  std::cout << "this " << this << std::endl;
33 #endif
34 }
35 
37 {
38 #ifdef DEBUG_OBJSTOCK
39  std::cout << "TPadStock::GetTHStock" << std::endl;
40 #endif
41 
42  //THStock *ths = 0;
43  TObject *obj;
44 
45  TIter next( GetListOfPrimitives() );
46  while ( (obj = next()) ) {
47  if ( obj->InheritsFrom("THStock") ) {
48  //std::cout << "Found THStock " << std::endl;
49  return dynamic_cast<THStock*>(obj);
50  }
51  }
52  std::cout << "\t\nTPadStock::GetTHStock NOT FOUND !\n" << std::endl;
53  return nullptr;
54 }
55 
56 void TPadStock::AddToTHStock ( ObjectLine * obj_stock )
57 {
58 #ifdef DEBUG_OBJSTOCK
59  std::cout << "TPadStock AddToTHStock" << std::endl;
60 #endif
61  THStock *ths = GetTHStock();
62 
63  if ( !ths ) {
64  std::cout << "\nERROR TH1 not found in TPadStock::AddToTHStock\n" << std::endl;
65  }
66  ths->Add( obj_stock );
67 }
68 
69 Int_t TPadStock::DistancetoPrimitive(Int_t px, Int_t py)
70 {
72 //#ifdef DEBUG_OBJSTOCK DEBUG_PAD??
73 // std::cout << "\nEntry TPadStock::DistancetoPrimitive" << std::endl;
74 // std::cout << "this " << this << std::endl;
75 //#endif
76  // The distance is computed in pixels units.
77  Int_t pxl, pyl, pxt, pyt;
78  Int_t px1 = gPad->XtoAbsPixel(fX1);
79  Int_t py1 = gPad->YtoAbsPixel(fY1);
80  Int_t px2 = gPad->XtoAbsPixel(fX2);
81  Int_t py2 = gPad->YtoAbsPixel(fY2);
82  if (px1 < px2) {pxl = px1; pxt = px2;}
83  else {pxl = px2; pxt = px1;}
84  if (py1 < py2) {pyl = py1; pyt = py2;}
85  else {pyl = py2; pyt = py1;}
86 
87  // commented, allows to select the object in THStock
88  // Are we inside the box?
89  // ======================
90  /*
91  if ( (px > pxl && px < pxt) && (py > pyl && py < pyt) ) {
92  std::cout << "TPadStock::DistancetoPrimitive return 0 " << std::endl;
93  if (GetFillStyle()) return 0; // if pad is filled
94  }
95  */
96 
97  // Are we on the edges?
98  // ====================
99  Int_t dxl = TMath::Abs(px - pxl);
100  if (py < pyl) dxl += pyl - py; if (py > pyt) dxl += py - pyt;
101  Int_t dxt = TMath::Abs(px - pxt);
102  if (py < pyl) dxt += pyl - py; if (py > pyt) dxt += py - pyt;
103  Int_t dyl = TMath::Abs(py - pyl);
104  if (px < pxl) dyl += pxl - px; if (px > pxt) dyl += px - pxt;
105  Int_t dyt = TMath::Abs(py - pyt);
106  if (px < pxl) dyt += pxl - px; if (px > pxt) dyt += px - pxt;
107 
108  Int_t distance = dxl;
109  if (dxt < distance) distance = dxt;
110  if (dyl < distance) distance = dyl;
111  if (dyt < distance) distance = dyt;
112 
113 #ifdef DEBUG_OBJSTOCK
114  std::cout << "TPadStock::DistancetoPrimitive will return " << distance - Int_t(0.5*fLineWidth) << std::endl;
115 #endif
116  return distance - Int_t(0.5*fLineWidth);
117 }
118 
119 // really needed ?? need to comment AddFirst, works ?? or find better way....
120 // called by THistPainterStock
121 // only when created, now when slider as well
122 // called for sure, really needed ?? to test
123 // called when a line is moved ( gPad->Modified is set )
124 void TPadStock::PaintPadFrameStock(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax)
125 {
126 #ifdef DEBUG_OBJSTOCK
127  std::cout << "Entry TPadStock::PaintPadFrameStock" << std::endl;
128  // called for sure !! by THistPainterStock
129  //std::cout << "Never called !" << std::endl;
130  // should check, print the list of object contained here
131 #endif
132  // Paint histogram/graph frame.
133 
134  if (!fPrimitives) fPrimitives = new TList;
135  TList *glist = GetListOfPrimitives();
136  TFrame *frame = GetFrame();
137  frame->SetX1(xmin);
138  frame->SetX2(xmax);
139  frame->SetY1(ymin);
140  frame->SetY2(ymax);
141  if (!glist->FindObject(fFrame)) {
142  // if not added, will not pick it! and still painted
143  //glist->AddFirst(frame);
144 #ifdef DEBUG_OBJSTOCK
145  std::cout << "TPadStock::PaintPadFrameStock fFrame not found set kMustCleanup ?" << std::endl;
146 #endif
147  fFrame->SetBit(kMustCleanup);
148  }
149 #ifdef DEBUG_OBJSTOCK
150  else {
151  std::cout << "TPadStock::PaintPadFrameStock fFrame found " << std::endl;
152  }
153 #endif
154 
155  if (gROOT->GetForceStyle()) frame->UseCurrentStyle();
156  frame->Paint();
157 }
158 
159 void TPadStock::ExecuteEvent( Int_t event, Int_t px, Int_t py )
160 {
161  // not called when a Line is selected by mouse,
162  // only called when cursor closer to the pad
163 #ifdef DEBUG_OBJSTOCK
164  std::cout << "Entry TPadStock::ExecuteEvent px, py " << px << " " << py << std::endl;
165 #endif
166 
167  // certainly not necessary, just convenient
169 #ifdef DEBUG_OBJSTOCK
170  std::cout << "return directly EditorObjStock is None " << std::endl;
171 #endif
172  return;
173  }
174 
175  // else we are drawing an object
176 #ifdef DEBUG_OBJSTOCK
177  std::cout << "MakePrimitve ObjectStock" << std::endl;
178 #endif
179 
180  ObjectLine * obj;
181 
182  // logic to get the event from her.
183  // if too complexe need intermediate, but already not bad with ObjctLine
184  switch (event) {
185 
186  case kButton1Down:
187 #ifdef DEBUG_OBJSTOCK
188  std::cout << "kButtonDown " << std::endl;
189 #endif
190  // parameter GetMode() only needed here, the other use the created line
191  // could reset to off after
193  gPad->AbsPixeltoX( px ), gPad->AbsPixeltoY( py ), EditorObjStock::GetMode() );
194 
195  // set the parent here, as soon as created
196  // helps for ObjectLine::FinaliseDrawableLine()
197  obj->SetParent ( GetTHStock() );
198  std::cout << "After SetParent " << obj->GetParent()->GetName() << std::endl;
199 
200  if ( EditorObjStock::GetAnchor() ) {
201  std::cout << "CreateObjectLine with anchor" << std::endl;
202  // call anchoring function
204  }
205  break;
206 
207  case kButton1Motion:
209  gPad->AbsPixeltoX( px ), gPad->AbsPixeltoY (py ), EditorObjStock::GetMode() );
210  break;
211 
212  // finalize drawing, can receive the final Object, goal of contructor !!
213  case kButton1Up:
214  // last stage, call directly ObjectLine::Finalise Object, anchoring done inside
216  gPad->AbsPixeltoX( px ),gPad->AbsPixeltoY ( py ), EditorObjStock::GetMode() );
217  //std::cout << "receive a new objectline adress " << obj << std::endl;
218 
219  // better anchoring here ? explicit
220  if ( EditorObjStock::GetAnchor() ) {
221  std::cout << "GetAnchor for final stage " << std::endl;
222  //fParentTHStock->AnchorToIndicator( px, py, this, FactoryObjectStock::kEnd );
224  }
225  // need in base
226  //obj->FinaliseDrawableLine( GetTHStock()->GetCommonXAxis() );
227  ((ObjectLineTendance *)obj)->FinaliseDrawableLine( GetTHStock()->GetCommonXAxis() );
228  // and call finalize here ?? why not ??
229  // test Anchor in one function, better !!
230 
231  // add the object to the THStock
232  AddToTHStock ( obj );
233  // will update all THStocks, maybe can do better ??
234  // a simple draw of obj, set and Paint
235  gPad->Modified();
236  break;
237 
238  // button left to cancel, not so easy
239  default : //badly formatted ??
240 #ifdef DEBUG_OBJSTOCK
241  std::cout << " event not deal by TPadExecuteEvent " << std::endl;
242 #endif
243  break;
244  }
245 
246  // try to force the draw, certainly not best
247  // it redraws all, and all the times ! Modified is important for update to act
248  //Modified(); Update();
249 }
250 
251 
Derive from TH1 will draw the graph.
Definition: THStock.h:59
void PaintPadFrameStock(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax)
Definition: TPadStock.cxx:124
TypeLine GetMode()
virtual void SetParent(THStock *thstock)
void AnchorToIndicator(const int &px, const int &py, ObjectLine *obj_line, FactoryObjectStock::EStageDraw kDraw)
set px, py to the closest indicator point
Definition: THStock.cxx:259
virtual void Add(ObjectLine *obj_stock)
call by Factory, specific to drawable line
Definition: THStock.cxx:231
Seems present because of ExecuteEvent not overloaded by CanvasStock CanvasStock contains Pad...
Regroup sub-hierarchy related to the LineObject :
static ObjectLine * CreateDrawableObjectLine(int stage_draw, double valueX, double valueY, TypeLine mode_obj)
create specifically ObjectLine
class for drawing graph
TPadStock()
Definition: TPadStock.h:34
Used for free drawing of support/tendance Add a general line description with coeef_d and origin : y ...
Definition: ObjectLine.h:230
THStock * GetTHStock() const
Loop over the ListOfPrimitives of TPad.
Definition: TPadStock.cxx:36
virtual void AddToTHStock(ObjectLine *)
Add an ObjectStock to THStock.
Definition: TPadStock.cxx:56
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a box.
Definition: TPadStock.cxx:69
for all ObjectLines
Definition: ObjectLine.h:33
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Called if TPadStock::DistancetoPrimitive return the smallest distance Called only if not candle or an...
Definition: TPadStock.cxx:159
virtual THStock * GetParent() const
public access to parent THStock