1 | #include <stdio.h>
|
---|
2 | #include "pintuple.h"
|
---|
3 |
|
---|
4 |
|
---|
5 | /* --Methode-- */
|
---|
6 | PINTuple::PINTuple(NTupleInterface* nt, bool ad)
|
---|
7 | : PIDrawer()
|
---|
8 | {
|
---|
9 | mNT = nt;
|
---|
10 | mAdDO = ad;
|
---|
11 | SelectXY(NULL, NULL);
|
---|
12 | SelectErrBar();
|
---|
13 | }
|
---|
14 |
|
---|
15 | PINTuple::~PINTuple()
|
---|
16 | {
|
---|
17 | if (mAdDO && mNT) delete mNT;
|
---|
18 | }
|
---|
19 |
|
---|
20 | /* --Methode-- */
|
---|
21 | void PINTuple::SelectXY(const char* px, const char* py)
|
---|
22 | {
|
---|
23 | string name;
|
---|
24 | if (mNT == NULL) xK = yK = -1;
|
---|
25 | if (px == NULL) xK = -1;
|
---|
26 | else { name = px; xK = mNT->ColumnIndex(name); }
|
---|
27 | if (py == NULL) yK = -1;
|
---|
28 | else { name = py; yK = mNT->ColumnIndex(name); }
|
---|
29 | }
|
---|
30 |
|
---|
31 | /* --Methode-- */
|
---|
32 | void PINTuple::SelectErrBar(const char* erbx, const char* erby)
|
---|
33 | {
|
---|
34 | string name;
|
---|
35 | if (mNT == NULL) xebK = yebK = -1;
|
---|
36 | if (erbx == NULL) xebK = -1;
|
---|
37 | else { name = erbx; xebK = mNT->ColumnIndex(name); }
|
---|
38 | if (erby == NULL) yebK = -1;
|
---|
39 | else { name = erby; yebK = mNT->ColumnIndex(name); }
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
43 | /* --Methode-- */
|
---|
44 | void PINTuple::UpdateLimits()
|
---|
45 | {
|
---|
46 | if (!mNT) return;
|
---|
47 | if (mNT->NbLines() <= 0) return;
|
---|
48 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
49 |
|
---|
50 | // Commencer par trouver nos limites
|
---|
51 | double dx, dy;
|
---|
52 | double xmin, xmax, ymin, ymax;
|
---|
53 | xmin = ymin = 9.e19;
|
---|
54 | xmax = ymax = -9.e19;
|
---|
55 | mNT->GetMinMax(xK, xmin, xmax);
|
---|
56 | mNT->GetMinMax(yK, ymin, ymax);
|
---|
57 |
|
---|
58 | dx = 0.02*(xmax-xmin);
|
---|
59 | dy = 0.02*(ymax-ymin);
|
---|
60 |
|
---|
61 | SetLimits(xmin-dx, xmax+dx, ymin-dy, ymax+dy);
|
---|
62 | SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | /* --Methode-- */
|
---|
67 | void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
68 | {
|
---|
69 | double xp,yp,xer,yer;
|
---|
70 | double xl,yl;
|
---|
71 | int nok;
|
---|
72 |
|
---|
73 | if (!mNT) return;
|
---|
74 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
75 | if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
---|
76 |
|
---|
77 | nok = 0;
|
---|
78 | xp = yp = xl = yl = 0;
|
---|
79 | for (int i=0; i<mNT->NbLines(); i++) {
|
---|
80 | xl = xp; yl = yp;
|
---|
81 | xp = mNT->GetCell(i, xK);
|
---|
82 | yp = mNT->GetCell(i, yK);
|
---|
83 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
|
---|
84 | if ( (i > 0) && (mLAtt != PI_NotDefLineAtt) ) // On relie les points ...
|
---|
85 | g->DrawLine(xl, yl, xp, yp);
|
---|
86 | nok++;
|
---|
87 | if ( xebK >= 0 ) {
|
---|
88 | xer = mNT->GetCell(i, xebK);
|
---|
89 | if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
|
---|
90 | }
|
---|
91 | if ( yebK >= 0 ) {
|
---|
92 | yer = mNT->GetCell(i, yebK);
|
---|
93 | if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
|
---|
94 | }
|
---|
95 | g->DrawMarker(xp, yp);
|
---|
96 | }
|
---|
97 |
|
---|
98 | /*
|
---|
99 | sprintf(buff, "NTuple: NEntry= %d NDisp= %d", (int)mNT->NEntry(), nok);
|
---|
100 | g->BaseGraphic()->DrawString(15,15,buff);
|
---|
101 | */
|
---|
102 | return;
|
---|
103 | }
|
---|
104 |
|
---|