]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pPlotterScaleY.cxx
#3472 TDx
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pPlotterScaleY.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 //----------------------------------------------------------------------------
27 // Class definition include
28 //----------------------------------------------------------------------------
29 #include "pPlotterScaleY.h"
30
31 // ----------------------------------------------------------------------------
32 // WX headers inclusion.
33 // For compilers that support precompilation, includes <wx/wx.h>.
34 // ----------------------------------------------------------------------------
35
36 #ifndef WX_PRECOMP
37 #include <wx/wx.h>
38 #endif
39
40 //----------------------------------------------------------------------------
41 // Class implementation
42 //----------------------------------------------------------------------------
43
44 #define mpLN10 2.3025850929940456840179914546844
45
46 IMPLEMENT_CLASS(pPlotterScaleY, pPlotterLayer)
47 //----------------------------------------------------------------------------
48 // Methods
49 //----------------------------------------------------------------------------
50 pPlotterScaleY::pPlotterScaleY(wxString aName,int flags) {
51
52         SetName(aName);/*
53         SetFont(*wxSMALL_FONT);
54         SetPen(*wxGREY_PEN);*/
55         wxFont ff( *wxSMALL_FONT);
56         wxPen pp( *wxGREY_PEN);
57         SetPen( pp );
58         SetFont( ff );
59 }
60
61 void pPlotterScaleY::Plot(wxDC& dc, mpWindow& w) 
62 {
63
64         int divisions=20;
65         
66         dc.SetPen( m_pen);
67         dc.SetFont( m_font);
68         
69         //data
70         float min= (float)w.getMinScrY();
71         float max=(float)w.getMaxScrY();
72         float scrY=(float)w.GetScrY()-50;
73         double scaleY=(scrY/(max-min))*w.getZoomFactor();
74         int offsetpy=w.getOffsetPixelsY();
75         int offsetY=w.getOffsetY();
76
77
78         //setting origins
79         
80 //EED 14Mai2009
81 //      const int orgy   = w.GetScrY()-40;
82 //      dc.SetDeviceOrigin(70,orgy);
83 //      dc.SetAxisOrientation(true,true);  //EED  MacOx ??? 
84         
85         const int orgy   = 40;
86         //dc.SetDeviceOrigin(70,orgy);
87         dc.SetDeviceOrigin(70,0);
88         double sizedc = dc.GetSize().GetY()-orgy;
89         //dc.SetAxisOrientation(true,false);  
90
91         //      const int extend = w.GetScrY()-50;   //EED
92         
93         //draw the axe
94         dc.DrawLine( 0,GetYTranslated(sizedc, 0), 0, GetYTranslated(sizedc, (max-min)*scaleY));
95
96         //maximum value in Y
97         int d=max-min;
98         if(d<20)
99                 {
100                         int k=d/divisions;
101                         while(k==0)
102                                 {
103                                         divisions--;
104                                         k=d/divisions;
105                                 }
106                 }
107         float step=(max-min)/divisions;
108         
109
110         //drawing the axe with the numbers
111         wxString s;
112         //drawing the first line
113         dc.DrawLine(0,GetYTranslated(sizedc, 0),-10,GetYTranslated(sizedc, 0));
114         s.Printf(_T("%d"),(int)(min));
115         dc.DrawText(s,(wxCoord)-20,GetYTranslated(sizedc, (wxCoord)0));
116         
117         
118         for(float i=0;i<=(max);i+=step)
119         {
120                 
121                 int p=(i-min-offsetY)*scaleY+offsetpy;
122                 if(p>=0)
123                 {       
124                         dc.DrawLine(0,GetYTranslated(sizedc, p),-10,GetYTranslated(sizedc, p));
125                         s.Printf(_T("%d"),(int)(i));
126                         dc.DrawText(s,(wxCoord)-20,GetYTranslated(sizedc, (wxCoord)p));
127                 }
128         }       
129         //drawing the last line
130         int p=(max-min-offsetY)*scaleY+offsetpy;
131         dc.DrawLine(0,GetYTranslated(sizedc, p),-10,GetYTranslated(sizedc, p));
132         s.Printf(_T("%d"),(int)(max));
133         dc.DrawText(s,(wxCoord)-20,GetYTranslated(sizedc, (wxCoord)p));
134 }
135
136
137