]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pPlotterScaleX.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pPlotterScaleX.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 "pPlotterScaleX.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 #define mpLN10 2.3025850929940456840179914546844
44
45 IMPLEMENT_CLASS(pPlotterScaleX, pPlotterLayer)
46 //----------------------------------------------------------------------------
47 // Methods
48 //----------------------------------------------------------------------------
49 pPlotterScaleX::pPlotterScaleX(wxString aName,int flags) {
50
51         SetName(aName);/*
52         SetFont(*wxSMALL_FONT);
53         SetPen(*wxGREY_PEN);*/
54         wxFont ff( *wxSMALL_FONT);
55         wxPen pp( *wxGREY_PEN);
56         SetPen( pp );
57         SetFont( ff );
58 }
59
60 void pPlotterScaleX::Plot(wxDC& dc, mpWindow& w) 
61 {
62
63         int divisions=20;
64         
65
66         dc.SetPen( m_pen);
67         dc.SetFont( m_font);
68
69         
70         
71         //data
72         float min=(float)w.getMinScrX();
73         float max=(float)w.getMaxScrX();
74         float scrX=(float)w.GetScrX()-100;
75         double scaleX=(scrX/(max-min))*w.getZoomFactor();
76         int offsetpx=w.getOffsetPixelsX();
77         int offsetX=w.getOffsetX();
78
79         //setting origins
80         
81         //EED 14Mai2009
82         //const int orgy   = w.GetScrY()-40;
83 //      dc.SetDeviceOrigin(70,orgy);    
84 //      dc.SetAxisOrientation(true,true);  //EED  MacOx  ???
85         
86         const int orgy   = 40;
87         //dc.SetDeviceOrigin(70,orgy);  
88         dc.SetDeviceOrigin(70,0);       
89         //dc.SetAxisOrientation(true,false);  
90         double sizedc = dc.GetSize().GetY()-orgy;
91                 
92         //const int extend = w.GetScrX()-100; //JPRx
93
94         
95         //draw the axe
96         dc.DrawLine(0,GetYTranslated(sizedc, 0),(max-min)*scaleX,GetYTranslated(sizedc, 0));
97
98         //maximum value in x
99         int d=max-min;
100         if(d<20)
101                 {
102                         int k=d/divisions;
103                         while(k==0)
104                                 {
105                                         divisions--;
106                                         k=d/divisions;
107                                 }
108                 }
109         float step=(max-min)/divisions;
110
111         //drawing the axe with the numbers
112         wxString s;
113         
114         
115         //drawing the first line
116         dc.DrawLine(0,GetYTranslated(sizedc, 0),0,GetYTranslated(sizedc, -10));
117         s.Printf(_T("%d"),(int)(min));
118         dc.DrawText(s,(wxCoord)0,GetYTranslated(sizedc, (wxCoord)-20));
119         
120         for(float i=0;i<=(max);i+=step)
121         {
122                 
123                 int p=(i-min-offsetX)*scaleX+offsetpx;
124                 if(p>=0)
125                 {       
126                         dc.DrawLine(p,0,p,-10);
127                         s.Printf(_T("%d"),(int)(i));
128                         dc.DrawText(s,(wxCoord)p,GetYTranslated(sizedc, (wxCoord)-20));         
129                 }
130         }
131         //drawing the last line
132         int p=(max-min-offsetX)*scaleX+offsetpx;
133         dc.DrawLine(p,GetYTranslated(sizedc, 0),p,GetYTranslated(sizedc, -10));
134         s.Printf(_T("%d"),(int)(max));
135         dc.DrawText(s,(wxCoord)p,GetYTranslated(sizedc, (wxCoord)-20));
136
137 }
138
139