]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pPlotterScaleX.cxx
45d0abe3b71b5b970551bccee8611be282e3839b
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pPlotterScaleX.cxx
1 //----------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------
4 #include "pPlotterScaleX.h"
5
6 // ----------------------------------------------------------------------------
7 // WX headers inclusion.
8 // For compilers that support precompilation, includes <wx/wx.h>.
9 // ----------------------------------------------------------------------------
10
11 #ifndef WX_PRECOMP
12 #include <wx/wx.h>
13 #endif
14
15 //----------------------------------------------------------------------------
16 // Class implementation
17 //----------------------------------------------------------------------------
18 #define mpLN10 2.3025850929940456840179914546844
19
20 IMPLEMENT_CLASS(pPlotterScaleX, pPlotterLayer)
21 //----------------------------------------------------------------------------
22 // Methods
23 //----------------------------------------------------------------------------
24 pPlotterScaleX::pPlotterScaleX(wxString aName,int flags) {
25
26         SetName(aName);/*
27         SetFont(*wxSMALL_FONT);
28         SetPen(*wxGREY_PEN);*/
29         wxFont ff( *wxSMALL_FONT);
30         wxPen pp( *wxGREY_PEN);
31         SetPen( pp );
32         SetFont( ff );
33 }
34
35 void pPlotterScaleX::Plot(wxDC& dc, mpWindow& w) 
36 {
37
38         int divisions=20;
39         
40
41         dc.SetPen( m_pen);
42         dc.SetFont( m_font);
43
44         
45         
46         //data
47         float min=(float)w.getMinScrX();
48         float max=(float)w.getMaxScrX();
49         float scrX=(float)w.GetScrX()-100;
50         double scaleX=(scrX/(max-min))*w.getZoomFactor();
51         int offsetpx=w.getOffsetPixelsX();
52         int offsetX=w.getOffsetX();
53
54         //setting origins
55         
56         //EED 14Mai2009
57         //const int orgy   = w.GetScrY()-40;
58 //      dc.SetDeviceOrigin(70,orgy);    
59 //      dc.SetAxisOrientation(true,true);  //EED  MacOx  ???
60         
61         const int orgy   = 40;
62         //dc.SetDeviceOrigin(70,orgy);  
63         dc.SetDeviceOrigin(70,0);       
64         //dc.SetAxisOrientation(true,false);  
65         double sizedc = dc.GetSize().GetY()-orgy;
66                 
67         //const int extend = w.GetScrX()-100; //JPRx
68
69         
70         //draw the axe
71         dc.DrawLine(0,GetYTranslated(sizedc, 0),(max-min)*scaleX,GetYTranslated(sizedc, 0));
72
73         //maximum value in x
74         int d=max-min;
75         if(d<20)
76                 {
77                         int k=d/divisions;
78                         while(k==0)
79                                 {
80                                         divisions--;
81                                         k=d/divisions;
82                                 }
83                 }
84         float step=(max-min)/divisions;
85
86         //drawing the axe with the numbers
87         wxString s;
88         
89         
90         //drawing the first line
91         dc.DrawLine(0,GetYTranslated(sizedc, 0),0,GetYTranslated(sizedc, -10));
92         s.Printf(_T("%d"),(int)(min));
93         dc.DrawText(s,(wxCoord)0,GetYTranslated(sizedc, (wxCoord)-20));
94         
95         for(float i=0;i<=(max);i+=step)
96         {
97                 
98                 int p=(i-min-offsetX)*scaleX+offsetpx;
99                 if(p>=0)
100                 {       
101                         dc.DrawLine(p,0,p,-10);
102                         s.Printf(_T("%d"),(int)(i));
103                         dc.DrawText(s,(wxCoord)p,GetYTranslated(sizedc, (wxCoord)-20));         
104                 }
105         }
106         //drawing the last line
107         int p=(max-min-offsetX)*scaleX+offsetpx;
108         dc.DrawLine(p,GetYTranslated(sizedc, 0),p,GetYTranslated(sizedc, -10));
109         s.Printf(_T("%d"),(int)(max));
110         dc.DrawText(s,(wxCoord)p,GetYTranslated(sizedc, (wxCoord)-20));
111
112 }
113
114