wxChart.cxx

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

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1