00001
00002
00003
00004 #ifdef __GNUG__
00005 #pragma implementation "chart.h"
00006 #endif
00007
00008 #ifdef __BORLANDC__
00009 #pragma hdrstop
00010 #endif
00011
00012
00013 #include "wx/wxprec.h"
00014 #ifndef WX_PRECOMP
00015 #include "wx/wx.h"
00016 #endif
00017
00018
00019 #include "chart.h"
00020 #include <math.h>
00021
00022
00023
00024
00025 wxDataSet::wxDataSet(wxPen *lStyle, wxBrush *dStyle, int dWidth,
00026 int lWidth, int dGap, int pMark, int disValues)
00027 {
00028 m_lineStyle = lStyle;
00029 m_dataStyle = dStyle;
00030 m_dataWidth = dWidth;
00031 m_lineWidth = lWidth;
00032 m_pointMark = pMark;
00033 m_displayValues = disValues;
00034 m_display = false;
00035 m_rowsList = NULL;
00036 m_text = NULL;
00037 }
00038
00039 wxDataSet::wxDataSet(wxPen *lStyle, wxBrush *dStyle,
00040 wxString *lText, bool lDisplay)
00041 {
00042 m_lineStyle = lStyle;
00043 m_dataStyle = dStyle;
00044 m_display = lDisplay;
00045 m_text = lText;
00046 m_rowsList = NULL;
00047 m_dataWidth = 0;
00048 m_lineWidth = 0;
00049 m_pointMark = 0;
00050 m_displayValues = 0;
00051 }
00052
00053
00054
00055 wxDataSet::wxDataSet()
00056 {
00057 m_lineStyle = NULL;
00058 m_dataStyle = NULL;
00059 m_dataWidth = 0;
00060 m_lineWidth = 0;
00061 m_pointMark = 0;
00062 m_displayValues = 0;
00063 m_display = false;
00064 m_rowsList = NULL;
00065 m_text = NULL;
00066 }
00067
00068
00069 wxDataSet::~wxDataSet()
00070 {
00071
00072 }
00073
00074
00075
00076
00077
00078
00079
00080 BEGIN_EVENT_TABLE(wxChart, wxWindow)
00081 EVT_PAINT(wxChart::OnPaint)
00082 END_EVENT_TABLE()
00083
00084
00085
00086 wxChart::wxChart(wxFrame *parent, wxWindowID id,
00087 const wxPoint& pos, const wxSize& size,
00088 long style, const wxString& name)
00089 : wxWindow(parent, id, pos, size, style, name)
00090 {
00091
00092 SetMaxWidthHeight(size.GetWidth(), size.GetHeight());
00093 SetCenterChart(pos.x + (GetLargeur()/2), pos.y + (GetHauteur()/2));
00094
00095 InitDataSet();
00096
00097 InitChart();
00098 }
00099
00100
00101
00102 wxChart::~wxChart()
00103 {
00104
00105 }
00106
00107
00108
00109 void wxChart::InitChart()
00110 {
00111 SetShowPer(false);
00112
00113 for(int i=0; i<m_NumDataSet ; i++)
00114 ShowDataSet(false, i);
00115
00116 InitData();
00117 }
00118
00119
00120
00121
00122
00123 static double st_difference(double val, int multi, bool sens=true)
00124 {
00125 double retour=0;
00126 div_t result;
00127
00128 result = div(int(val), multi);
00129
00130 if ( sens )
00131 {
00132 if ( val > 1)
00133 {
00134 if ( result.rem == 0 )
00135 {
00136 if (val - (int)val > 0 )
00137 retour = (multi - result.rem) - (val - int(val));
00138 }
00139 else
00140 {
00141 retour = (multi - result.rem) - (val - int(val));
00142 }
00143 }
00144 }
00145
00146 else
00147 retour = result.rem + (val - (int)val);
00148
00149 return retour;
00150 }
00151
00152 static double st_decalage(double IncX, double MinX)
00153 {
00154 double retour = 0.00;
00155 div_t result;
00156
00157 if (IncX >= 1)
00158 {
00159 result = div(MinX, IncX);
00160 if ( result.rem == 0 )
00161 {
00162 if (MinX - (int)MinX > 0 )
00163 retour = ((result.quot + 1) * IncX) - MinX;
00164 }
00165 else
00166 {
00167 retour = ((result.quot+1) * IncX) - MinX;
00168 }
00169 }
00170 return retour;
00171 }
00172
00173
00174 static double st_origine(double IncX, double MinX)
00175 {
00176 double retour = MinX;
00177 div_t result;
00178
00179 if (IncX >=1)
00180 {
00181 result = div(MinX, IncX);
00182 if (result.rem == 0)
00183 {
00184 if (MinX - (int)MinX > 0 )
00185 retour = (result.quot + 1) * IncX;
00186 }
00187 else
00188 {
00189 retour = (result.quot + 1) * IncX;
00190 }
00191 }
00192 return retour;
00193 }
00194
00195
00196 static void st_InverseCol(double *l_MinCol, double *l_MaxCol)
00197 {
00198 if (*l_MinCol > *l_MaxCol)
00199 {
00200 int tempo = *l_MaxCol;
00201 *l_MaxCol = *l_MinCol;
00202 *l_MinCol = tempo;
00203 }
00204
00205 }
00206
00207
00208
00209 void wxChart::SetInfX(double inf)
00210 {
00211 m_InfX = inf;
00212 }
00213
00214 void wxChart::SetSupX(double sup)
00215 {
00216 m_SupX = sup;
00217 }
00218
00219
00220 void wxChart::SetSupY(double sup)
00221 {
00222 m_SupY = sup;
00223 }
00224
00225
00226
00227 void wxChart::SetIncAxisX(double minor, double major)
00228 {
00229 m_MinorIncX = minor;
00230 m_MajorIncX = major;
00231 }
00232
00233 void wxChart::SetIncAxisY(double minor, double major)
00234 {
00235 m_MinorIncY = minor;
00236 m_MajorIncY = major;
00237 }
00238
00239
00240 void wxChart::SetInitEdge()
00241 {
00242 SetEdgeTop(15);
00243 SetEdgeBottom(35);
00244 SetEdgeLeft(37);
00245 SetEdgeRight(15);
00246 }
00247
00248
00249
00250 void wxChart::SetChartBounds()
00251 {
00252 m_Top = m_CenterY - (m_MaxHauteur/2) + m_EdgeTop;
00253 m_Bottom = m_CenterY + (m_MaxHauteur/2) - m_EdgeBottom;
00254 m_Left = m_CenterX - (m_MaxLargeur/2) + m_EdgeLeft;
00255 m_Right = m_CenterX + (m_MaxLargeur/2) - m_EdgeRight;
00256
00257 }
00258
00259 void wxChart::SetChartBoundsLegend()
00260 {
00261 m_TopLegend = m_CenterY - (m_MaxHauteur/2) + m_EdgeTopLegend;
00262 m_BottomLegend = m_CenterY + (m_MaxHauteur/2) - m_EdgeBottomLegend;
00263 m_LeftLegend = m_CenterX - (m_MaxLargeur/2) + m_EdgeLeftLegend;
00264 m_RightLegend = m_CenterX + (m_MaxLargeur/2) - m_EdgeRightLegend;
00265 }
00266
00267
00268 void wxChart::SetCadreLegend(int nbr, int *bottom)
00269 {
00270 int val=GetEdgeBottom();
00271 div_t result = div(nbr, 2);
00272
00273 if (result.rem == 0)
00274 val+= (nbr * 10) + 5;
00275 else
00276 val+= (( nbr + 1 ) * 10) + 5;
00277
00278 *bottom = val;
00279
00280 SetEdgeTopLegend(m_CenterY + (m_MaxHauteur/2) - val + 33);
00281 SetEdgeBottomLegend(8);
00282
00283 int l_left = GetEdgeLeft();
00284 int l_right = GetEdgeRight();
00285
00286
00287 if (nbr == 1)
00288 {
00289 l_left+=m_CenterX - (m_MaxLargeur/3);
00290 l_right+=m_CenterX - (m_MaxLargeur/3);
00291 }
00292
00293 SetEdgeLeftLegend(l_left);
00294 SetEdgeRightLegend(l_right);
00295 }
00296
00297
00298
00299 void wxChart::SetShowPer(bool per)
00300 {
00301 m_ShowPer = per;
00302
00303 }
00304
00305
00306 void wxChart::SetMaxValue(double max)
00307 {
00308
00309 m_MaxValue = max;
00310 }
00311
00312
00313
00314
00315 double wxChart::MaxValue()
00316 {
00317 double data, val = 1.00;
00318 int maxdata = GetNumDataSet()-1;
00319 int maxitem = GetNumItem();
00320
00321
00322 for(int a=0; a < maxdata; a++)
00323 {
00324 if (GetShowDataSet(a))
00325 {
00326 for(int j=0; j<=maxitem; j++)
00327 {
00328 if ( IsEmpty(a,j) == false )
00329 {
00330 data = GetDataY(a,j);
00331 if (data > val)
00332 val = data;
00333 }
00334 }
00335 }
00336 }
00337 return val;
00338 }
00339
00340
00341
00342 double wxChart::MinCol(double min)
00343 {
00344 double retour = 0.00;
00345 int maxdata = GetNumDataSet()-1;
00346
00347
00348 for(int a=0; a < maxdata; a++)
00349 {
00350 if (GetShowDataSet(a))
00351 {
00352 if (min > retour)
00353 retour = min;
00354 a = maxdata - 1;
00355 }
00356 }
00357
00358 return retour;
00359 }
00360
00361
00362 double wxChart::MaxCol(double max)
00363 {
00364 double retour = 1.00;
00365 int maxdata = GetNumDataSet()-1;
00366
00367
00368 for(int a=0; a < maxdata; a++)
00369 {
00370 if (GetShowDataSet(a))
00371 {
00372 if (max > retour)
00373 retour = max;
00374 a = maxdata - 1;
00375 }
00376 }
00377
00378 return retour;
00379 }
00380
00381
00382
00383 void wxChart::SetStepSizeX(double stepX)
00384 {
00385 m_StepSizeX = stepX;
00386 }
00387
00388 void wxChart::SetStepSizeY(double stepY)
00389 {
00390 m_StepSizeY = stepY;
00391 }
00392
00393
00394 void wxChart::SetStepSizePer(double stepPer)
00395 {
00396 m_StepSizePer = stepPer;
00397 }
00398
00399
00400 void wxChart::SetCenterChart(int x, int y)
00401 {
00402 m_CenterX = x;
00403 m_CenterY = y;
00404 }
00405
00406 void wxChart::SetMaxWidthHeight(int x,int y)
00407 {
00408 m_MaxLargeur = x;
00409 m_MaxHauteur = y;
00410 }
00411
00412
00413 void wxChart::SetMinX(double MinX)
00414 {
00415 m_MinX = MinX;
00416 }
00417
00418
00419 void wxChart::SetMaxX(double MaxX)
00420 {
00421 m_MaxX = MaxX;
00422 }
00423
00424
00425
00426 void wxChart::SetEdgeTop(int top)
00427 {
00428 m_EdgeTop = top;
00429 }
00430
00431 void wxChart::SetEdgeBottom(int bottom)
00432 {
00433 m_EdgeBottom = bottom;
00434 }
00435
00436 void wxChart::SetEdgeLeft(int left)
00437 {
00438 m_EdgeLeft = left;
00439 }
00440
00441 void wxChart::SetEdgeRight(int right)
00442 {
00443 m_EdgeRight = right;
00444 }
00445
00446
00447 void wxChart::SetEdgeTopLegend(int top)
00448 {
00449 m_EdgeTopLegend = top;
00450 }
00451
00452 void wxChart::SetEdgeBottomLegend(int bottom)
00453 {
00454 m_EdgeBottomLegend = bottom;
00455 }
00456
00457 void wxChart::SetEdgeLeftLegend(int left)
00458 {
00459 m_EdgeLeftLegend = left;
00460 }
00461
00462
00463 void wxChart::SetEdgeRightLegend(int right)
00464 {
00465 m_EdgeRightLegend = right;
00466 }
00467
00468
00469
00470 void wxChart::SetNumDataSet(int num)
00471 {
00472 m_NumDataSet = num;
00473 }
00474
00475 void wxChart::SetNumItem(int num)
00476 {
00477 m_NumItem = num;
00478 }
00479
00480
00481 int wxChart::GetShow()
00482 {
00483 int retour = 0;
00484
00485 for(int i=0; i < m_NumDataSet ; i++)
00486 {
00487 if (GetShowDataSet(i))
00488 retour++;
00489 }
00490 return retour;
00491 }
00492
00493
00494 void wxChart::InitDataSet()
00495 {
00496
00497
00498 SetNumDataSet(8);
00499 for(int i=0; i<MAX_DATASET ; i++)
00500 m_dataSetArray[i]=NULL;
00501
00502
00503 wxColour *BlueColour = new wxColour(0,0,255);
00504 wxColour *GreyColour = new wxColour(192,192,192);
00505 wxColour *YellowColour = new wxColour(255,255,0);
00506 wxColour *VioletColour = new wxColour(255,0,255);
00507 wxColour *CyanColour = new wxColour(0,255,255);
00508
00509
00510
00511
00512 m_dataSetArray[wxArea] =
00513 new wxDataSet(wxRED_PEN, wxRED_BRUSH, (wxString*)"Area");
00514
00515 m_dataSetArray[wxPerimeter] =
00516 new wxDataSet(new wxPen(*BlueColour, 1, wxSOLID),
00517 new wxBrush(*BlueColour, wxSOLID),
00518 (wxString*)"Perimeter");
00519
00520 m_dataSetArray[wxDiameterArea] =
00521 new wxDataSet(new wxPen(*GreyColour, 1, wxSOLID),
00522 new wxBrush(*GreyColour, wxSOLID),
00523 (wxString*)"Diameter from area");
00524
00525 m_dataSetArray[wxDiameterPerimeter] =
00526 new wxDataSet(new wxPen(*YellowColour, 1, wxSOLID),
00527 new wxBrush(*YellowColour, wxSOLID),
00528 (wxString*)"Diameter from perimeter");
00529
00530 m_dataSetArray[wxMinimumDiameter] =
00531 new wxDataSet(new wxPen(*VioletColour, 1, wxSOLID),
00532 new wxBrush(*VioletColour, wxSOLID),
00533 (wxString*)"Minimum diameter");
00534
00535 m_dataSetArray[wxMaximumDiameter] =
00536 new wxDataSet(new wxPen(*CyanColour, 1, wxSOLID),
00537 new wxBrush(*CyanColour, wxSOLID),
00538 (wxString*)"Maximum diameter");
00539
00540 m_dataSetArray[wxAverageDiameter] =
00541 new wxDataSet(wxBLACK_PEN, wxBLACK_BRUSH, (wxString*)"Average diameter");
00542
00543 m_dataSetArray[wxStenosis] =
00544 new wxDataSet(wxGREEN_PEN, wxGREEN_BRUSH, (wxString*)"Stenosis");
00545
00546 }
00547
00548
00549
00550
00551 void wxChart::OnPaint(wxPaintEvent& event)
00552 {
00553 wxPaintDC dc(this);
00554 Draw(dc);
00555 }
00556
00557
00558
00559 void wxChart::Draw(wxDC& dc)
00560 {
00561 wxBrush *dataBrush;
00562 wxPen *dataPen;
00563
00564
00565
00566 dc.BeginDrawing();
00567 dc.Clear();
00568
00569
00570
00571
00572 dc.SetFont(*(new wxFont(1, wxDEFAULT, wxNORMAL, wxLIGHT)));
00573
00574
00575
00576 wxSize size = GetClientSize();
00577 SetMaxWidthHeight(size.GetWidth(), size.GetHeight());
00578 SetCenterChart((GetLargeur()/2), (GetHauteur()/2));
00579 SetInitEdge();
00580
00581
00582
00583 ShowDataSet(true,wxArea);
00584 ShowDataSet(true,wxPerimeter);
00585 ShowDataSet(true,wxDiameterArea);
00586 ShowDataSet(false,wxDiameterPerimeter);
00587 ShowDataSet(false,wxMinimumDiameter);
00588 ShowDataSet(false,wxMaximumDiameter);
00589 ShowDataSet(false,wxAverageDiameter);
00590 ShowDataSet(false,wxStenosis);
00591
00592 m_ShowPer = true;
00593
00594
00595 if (m_ShowPer)
00596 {
00597 SetEdgeRight(45);
00598 ShowDataSet(true,wxStenosis);
00599 }
00600
00601
00602
00603
00604 int nbr = GetShow();
00605 if (nbr > 0)
00606 {
00607 SetCadreLegend(nbr, &m_EdgeBottom);
00608 SetChartBoundsLegend();
00609 DrawLegend(dc, nbr);
00610 }
00611
00612
00613
00614 SetMinX(MinCol(0));
00615 SetMaxX(MaxCol(1));
00616 SetInfX(st_difference(m_MinX,10,false));
00617 SetSupX(st_difference(m_MaxX,10,true));
00618
00619
00620
00621
00622 SetNumItem(6);
00623 SetData(wxStenosis, 0, 0, -45);
00624 SetData(wxStenosis, 1, 0.4, 0);
00625 SetData(wxStenosis, 2, 0.6, -15);
00626 SetData(wxStenosis, 3, 0.8, 0);
00627 SetData(wxStenosis, 4, 0.9, 100);
00628 SetData(wxStenosis, 5, 1, 0);
00629
00630
00631 SetData(wxArea,0, 0, 0.8);
00632 SetData(wxArea,1, 0.2, 0.6);
00633 SetData(wxArea,2, 0.3, 0.8);
00634 SetData(wxArea,3, 0.4, 1);
00635 SetData(wxArea,4, 0.8, 0.4);
00636 SetData(wxArea,5, 1, 0.2);
00637
00638
00639
00640 SetMaxValue(MaxValue());
00641 SetSupY(st_difference(m_MaxValue, 10, true));
00642
00643
00644
00645 SetIncAxisX((m_MaxX + m_SupX - (m_MinX - m_InfX)) / (double)MINOR_STEP,
00646 (m_MaxX + m_SupX - (m_MinX - m_InfX)) / (double)MAJOR_STEP);
00647 SetIncAxisY((m_MaxValue + m_SupY) / (double)MINOR_STEP,
00648 (m_MaxValue + m_SupY) / (double)MAJOR_STEP);
00649
00650 SetStepSizeX(( m_MaxLargeur - (m_EdgeLeft + m_EdgeRight + m_SupX + m_InfX)) /
00651 (m_MaxX - m_MinX));
00652 SetStepSizeY(( m_MaxHauteur - (m_EdgeBottom + m_EdgeTop + m_SupY )) /
00653 (m_MaxValue));
00654 SetStepSizePer(( m_MaxHauteur - (m_EdgeBottom + m_EdgeTop)) /
00655 (double)MAX_PER);
00656
00657
00658
00659
00660
00661 SetChartBounds();
00662 DrawGrille(dc);
00663 DrawAxe(dc);
00664 if (m_ShowPer)
00665 DrawAxePer(dc);
00666
00667
00668
00669
00670 dc.DestroyClippingRegion();
00671 dc.SetClippingRegion(m_Left , m_Top ,
00672 GetLargeur() - (m_EdgeRight + m_EdgeLeft ),
00673 GetHauteur() - (m_EdgeTop + m_EdgeBottom ));
00674
00675
00676
00677
00678 int maxdataset = GetNumDataSet();
00679 for(int a=0; a < maxdataset; a++)
00680 {
00681 if(m_dataSetArray[a] && m_dataSetArray[a]->GetShow())
00682 {
00683 dataBrush = m_dataSetArray[a]->GetDataStyle();
00684 dataPen = m_dataSetArray[a]->GetLineStyle();
00685 dc.SetBrush(*dataBrush);
00686 dc.SetPen(*dataPen);
00687 DrawLine(dc, a);
00688 }
00689 }
00690
00691
00692
00693 dc.DestroyClippingRegion();
00694 dc.EndDrawing();
00695 }
00696
00697
00698
00699 void wxChart::DrawAxe(wxDC& dc)
00700 {
00701 double x,y;
00702 double val, supx;
00703 char text[20];
00704 int widthx,heighty;
00705
00706 double minorIncStepY= m_MinorIncY * m_StepSizeY;
00707 double majorIncStepY= m_MajorIncY * m_StepSizeY;
00708
00709 double minorIncStepX= m_MinorIncX * m_StepSizeX;
00710 double majorIncStepX= m_MajorIncX * m_StepSizeX;
00711
00712 dc.SetPen(*wxBLACK_PEN);
00713 dc.SetBrush(*wxBLACK_BRUSH);
00714
00715
00716 dc.DrawLine(m_Left, m_Bottom+(7*MARGE/4), m_Right, m_Bottom+(7*MARGE/4));
00717
00718 dc.DrawLine(m_Left-(7*MARGE/4), m_Bottom, m_Left-(7*MARGE/4), m_Top);
00719
00720
00721
00722 val=0.00;
00723 for(x=m_Left,y=m_Bottom; y >= m_Top; y-=majorIncStepY, val+=m_MajorIncY)
00724 {
00725 dc.DrawLine(m_Left-7-(7*MARGE/4),y,m_Left-(7*MARGE/4),y);
00726 sprintf(text,"%g", val);
00727 dc.GetTextExtent(text,&widthx,&heighty);
00728 dc.DrawText(text,m_Left-10-widthx-(7*MARGE/4),y-(heighty/2));
00729 }
00730
00731 if (m_SupY == 0 )
00732 {
00733 dc.DrawLine(m_Left-7-(7*MARGE/4),m_Top,m_Left-(7*MARGE/4),m_Top);
00734 sprintf(text,"%g", val);
00735 dc.GetTextExtent(text,&widthx,&heighty);
00736 dc.DrawText(text,m_Left-10-widthx-(7*MARGE/4),m_Top-(heighty/2));
00737 }
00738
00739
00740 for(x=m_Left,y=m_Bottom; y >= m_Top; y-=minorIncStepY)
00741 {
00742 dc.DrawLine(m_Left-3-(7*MARGE/4),y,m_Left-(7*MARGE/4),y);
00743 }
00744
00745
00746
00747 supx = st_decalage(m_MajorIncX, m_MinX) * m_StepSizeX;
00748 val = st_origine(m_MajorIncX, m_MinX);
00749 for(y=m_Bottom,x=m_Left + supx; x <= m_Right; x+=majorIncStepX, val+=m_MajorIncX)
00750 {
00751 dc.DrawLine(x,m_Bottom+7+(7*MARGE/4),x,m_Bottom+(7*MARGE/4));
00752 sprintf(text,"%g", val);
00753 dc.GetTextExtent(text,&widthx,&heighty);
00754 dc.DrawText(text,x-(widthx/2),y+3+heighty);
00755 }
00756
00757 if ( m_SupX == 0 )
00758 {
00759 dc.DrawLine(m_Right,m_Bottom+7+(7*MARGE/4),m_Right,m_Bottom+(7*MARGE/4));
00760 sprintf(text,"%g", val);
00761 dc.GetTextExtent(text,&widthx,&heighty);
00762 dc.DrawText(text,m_Right-(widthx/2),m_Right+3+heighty);
00763 }
00764
00765 supx = st_decalage(m_MinorIncX, m_MinX) * m_StepSizeX;
00766
00767 for(y=m_Bottom,x=m_Left + supx; x <= m_Right; x+=minorIncStepX)
00768 {
00769 dc.DrawLine(x,m_Bottom+3+(7*MARGE/4),x,m_Bottom+(7*MARGE/4));
00770 }
00771 }
00772
00773
00774 void wxChart::DrawAxePer(wxDC& dc)
00775 {
00776 double x,y;
00777 double val;
00778 char text[20];
00779 int widthx,heighty;
00780
00781 double minorIncStepPer= MINOR_PER * m_StepSizePer;
00782 double majorIncStepPer= MAJOR_PER * m_StepSizePer;
00783
00784 dc.SetPen(*wxBLACK_PEN);
00785 dc.SetBrush(*wxBLACK_BRUSH);
00786
00787
00788 dc.DrawLine(m_Right+(7*MARGE/4), m_Bottom, m_Right+(7*MARGE/4), m_Top);
00789
00790
00791 val=0.00;
00792 for(x=m_Right,y=m_Bottom; y >= m_Top; y-=majorIncStepPer, val+=MAJOR_PER)
00793 {
00794 dc.DrawLine(m_Right+(7*MARGE/4),y,m_Right+7+(7*MARGE/4),y);
00795 sprintf(text,"%g",(val-(MAX_PER/2)));
00796 dc.GetTextExtent(text,&widthx,&heighty);
00797 dc.DrawText(text,m_Right+10+(7*MARGE/4),y-(heighty/2));
00798 }
00799 dc.DrawLine(m_Right+(7*MARGE/4),m_Top,m_Right+7+(7*MARGE/4),m_Top);
00800 sprintf(text,"%g",(val-(MAX_PER/2)));
00801 dc.GetTextExtent(text,&widthx,&heighty);
00802 dc.DrawText(text,m_Right+10+(7*MARGE/4),m_Top-(heighty/2));
00803
00804
00805 for(x=m_Right,y=m_Bottom; y >= m_Top; y-=minorIncStepPer)
00806 {
00807 dc.DrawLine(m_Right+(7*MARGE/4),y,m_Right+3+(7*MARGE/4),y);
00808 }
00809 }
00810
00811
00812
00813 void wxChart::DrawGrille(wxDC& dc)
00814 {
00815 double x,y;
00816 double val;
00817 double minorIncStepY = m_MinorIncY * m_StepSizeY;
00818 double minorIncStepX = m_MinorIncX * m_StepSizeX;
00819
00820 dc.SetBrush(*wxLIGHT_GREY_BRUSH);
00821
00822
00823 wxPen *Pen = new wxPen(*wxLIGHT_GREY, 1, wxDOT);
00824 dc.SetPen(*Pen);
00825
00826
00827
00828 for(x=m_Left,y=m_Bottom; y >= m_Top; y-=minorIncStepY)
00829 dc.DrawLine(m_Left-MARGE,y,m_Right+MARGE,y);
00830 if (m_SupY == 0)
00831 dc.DrawLine(m_Left-MARGE,m_Top,m_Right+MARGE,m_Top);
00832
00833
00834 val = st_decalage(m_MinorIncX, m_MinX) * m_StepSizeX;
00835 for(y=m_Bottom, x=m_Left + val ; x <= m_Right; x+=minorIncStepX)
00836 dc.DrawLine(x,m_Bottom+MARGE,x,m_Top-MARGE);
00837 if (m_SupX == 0)
00838 dc.DrawLine(m_Right,m_Bottom+MARGE,m_Right,m_Top-MARGE);
00839
00840
00841 Pen->SetStyle(wxSOLID);
00842 dc.SetPen(*Pen);
00843 dc.DrawLine(m_Left-MARGE, m_Top-MARGE, m_Right+MARGE, m_Top-MARGE);
00844 dc.DrawLine(m_Right+MARGE, m_Top-MARGE, m_Right+MARGE, m_Bottom+MARGE);
00845 dc.DrawLine(m_Right+MARGE, m_Bottom+MARGE, m_Left-MARGE, m_Bottom+MARGE);
00846 dc.DrawLine(m_Left-MARGE, m_Bottom+MARGE, m_Left-MARGE, m_Top-MARGE);
00847 }
00848
00849
00850
00851 void wxChart::DrawLegend(wxDC& dc, int nbre)
00852 {
00853
00854 wxString *string;
00855 wxPen *dataPen;
00856 wxBrush *dataBrush;
00857 int widthx, heighty, l_posx, l_posy;
00858 char text[30];
00859 int haut_ligne, compt = 0;
00860 int l_haut = m_BottomLegend - m_TopLegend;
00861 int l_larg = m_RightLegend - m_LeftLegend;
00862 div_t result = div(nbre,2);
00863 div_t resulta;
00864 int l_debut = 30, l_trait = 15, l_space = 10;
00865
00866 if (result.rem == 0)
00867 haut_ligne = l_haut / result.quot;
00868 else
00869 haut_ligne = l_haut / (result.quot+1);
00870
00871
00872 dc.SetPen(*wxBLACK_PEN);
00873 dc.SetBrush(*wxBLACK_BRUSH);
00874 dc.DrawLine(m_LeftLegend, m_TopLegend, m_RightLegend, m_TopLegend);
00875 dc.DrawLine(m_RightLegend, m_TopLegend, m_RightLegend, m_BottomLegend);
00876 dc.DrawLine(m_RightLegend, m_BottomLegend, m_LeftLegend, m_BottomLegend);
00877 dc.DrawLine(m_LeftLegend, m_BottomLegend, m_LeftLegend, m_TopLegend);
00878
00879
00880 int maxdataset = GetNumDataSet();
00881 for (int a=0; a < maxdataset; a++)
00882 {
00883 if (m_dataSetArray[a] && m_dataSetArray[a]->GetShow())
00884 {
00885 compt++;
00886
00887 string = m_dataSetArray[a]->GetText();
00888 sprintf(text,"%s",string);
00889 dc.GetTextExtent(text,&widthx,&heighty);
00890
00891 resulta = div(compt, 2);
00892 l_posx = m_LeftLegend;
00893 l_posy = m_TopLegend;
00894 if (resulta.rem == 0)
00895 {
00896 l_posx+= l_larg/2;
00897 l_posy+= (haut_ligne * resulta.quot);
00898 }
00899 else
00900 l_posy+= (haut_ligne * (resulta.quot+1));
00901
00902 l_posy-= (haut_ligne/2);
00903
00904
00905 if (nbre==1)
00906 l_posx = m_LeftLegend + ((l_larg - l_trait - l_space - widthx)/2) - l_debut;
00907
00908
00909 dataBrush = m_dataSetArray[a]->GetDataStyle();
00910 dataPen = m_dataSetArray[a]->GetLineStyle();
00911 dataPen->SetWidth(2);
00912 dc.SetBrush(*dataBrush);
00913 dc.SetPen(*dataPen);
00914 dc.DrawLine(l_posx + l_debut, l_posy, l_posx + l_debut + 15, l_posy);
00915 dataPen->SetWidth(1);
00916
00917 dc.SetFont(*(new wxFont(1, wxDEFAULT, wxNORMAL, wxBOLD)));
00918 dc.SetPen(*wxBLACK_PEN);
00919 dc.SetBrush(*wxBLACK_BRUSH);
00920 dc.DrawText(text,l_posx + l_debut + l_trait + l_space ,l_posy - (heighty/2));
00921 dc.SetFont(*(new wxFont(1, wxDEFAULT, wxNORMAL, wxLIGHT)));
00922 }
00923 }
00924 }
00925
00926
00927
00928 void wxChart::DrawLine(wxDC &dc, int a)
00929 {
00930 int compt=0;
00931 double val;
00932 double mid = m_Bottom - ((m_Bottom-m_Top)/2);
00933 int maxitem = GetNumItem();
00934
00935 float yprec, xprec;
00936 float xsuiv, ysuiv;
00937
00938 for(int j=0; j < maxitem; j++)
00939 {
00940 if ( IsEmpty(a,j) == false )
00941 {
00942 compt++;
00943 xsuiv = m_Left + ((GetDataX(a,j) - m_MinX ) * m_StepSizeX);
00944 val = GetDataY(a,j);
00945 if ( a == wxStenosis)
00946
00947 ysuiv = mid - (val * m_StepSizePer);
00948 else
00949
00950 ysuiv = m_Bottom - (val * m_StepSizeY);
00951
00952 if (compt > 1)
00953 dc.DrawLine(xprec, yprec, xsuiv, ysuiv);
00954
00955
00956 xprec = xsuiv;
00957 yprec = ysuiv;
00958 }
00959 }
00960 }
00961
00962
00963
00964
00965 void wxChart::OnLeftClick(wxDC &dc, double x, double y, int keys)
00966 {
00967
00968 }
00969
00970 void wxChart::OnRightClick(wxDC &dc, double x, double y, int keys)
00971 {
00972
00973 }
00974
00975
00976
00977
00978 void wxChart::InitData()
00979 {
00980 SetNumItem(0);
00981 for(int a=0; a<MAX_DATASET; a++)
00982 {
00983 for(int j=0; j<MAX_ITEM; j++)
00984 {
00985 m_table[a][j].x=0.00;
00986 m_table[a][j].y=0.00;
00987 m_table[a][j].empty = true;
00988 }
00989 }
00990 }
00991
00992 bool wxChart::IsEmpty(int a, int j)
00993 {
00994 return m_table[a][j].empty;
00995 }
00996
00997
00998 double wxChart::GetDataX(int a, int j)
00999 {
01000
01001 return m_table[a][j].x;
01002 }
01003
01004 double wxChart::GetDataY(int a, int j)
01005 {
01006
01007 return m_table[a][j].y;
01008 }
01009
01010
01011 void wxChart::SetData(int a, int j, double x, double y)
01012 {
01013 m_table[a][j].x = x;
01014 m_table[a][j].y = y;
01015 m_table[a][j].empty = false;
01016 }
01017
01018
01019 void wxChart::ShowDataSet(bool show,int dataset)
01020 {
01021 if(m_dataSetArray[dataset])
01022 m_dataSetArray[dataset]->Show(show);
01023 }
01024
01025 bool wxChart::GetShowDataSet(int dataset)
01026 {
01027
01028 if(m_dataSetArray[dataset])
01029 return m_dataSetArray[dataset]->GetShow();
01030 else
01031 return 1;
01032 }
01033
01034