]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pFigure.cxx
d3ad630d2acccf1c7558f775ee1c0ffc7fa7c284
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pFigure.cxx
1
2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 #include "pFigure.h"
6
7 // ---------------------------------------------------------------------------------------------------------------
8 // WX headers inclusion.
9 // For compilers that support precompilation, includes <wx/wx.h>.
10 // ---------------------------------------------------------------------------------------------------------------
11
12 #ifndef WX_PRECOMP
13 #include <wx/wx.h>
14 #endif
15
16 //----------------------------------------------------------------------------------------------------------------
17 // Class implementation
18 //----------------------------------------------------------------------------------------------------------------
19 /** @file pFigure.cxx */
20 IMPLEMENT_CLASS(pFigure, wxObject)
21
22         //------------------------------------------------------------------------------------------------------------
23         // Constructors & Destructors
24         //------------------------------------------------------------------------------------------------------------
25         /**
26         * Create a figure with edges_n edges
27         * @param edges_n The number of edges of the new figure
28         * @param _w The width to set
29         * @param _h The height to set
30         * @param _orientation The orientation to set
31         */
32         pFigure :: pFigure(int edges_n, int _w, int _h, int _orientation, bool bar_orientation)
33         {
34                 edges = edges_n;
35                 orientation = _orientation;
36                 width = _w;
37                 heigth = _h;
38                 setBarOrientation( bar_orientation );
39         }
40
41         pFigure :: ~pFigure()
42         {
43
44         }
45
46         //------------------------------------------------------------------------------------------------------------
47         // Methods
48         //------------------------------------------------------------------------------------------------------------
49
50         /**
51         * Gets the number of edges of the figure
52         * @retval edges Number of edges in the figure
53         */
54         int pFigure :: getNumberEdges()
55         {
56                 return edges;
57         }
58
59         /**
60         * Sets the vertex points of the figure
61         * @param edges Number of edges in the figure to set
62         */
63         void pFigure :: setNumberEdges(int n_edges)
64         {
65                 edges = n_edges;
66         }
67
68         /**
69         * Gets the vertex points of the figure
70         * @param wxPoint The vector to get the points
71         * @retval points Vertex points distribution in the figure
72         */
73         void pFigure :: getVertexPoints(wxPoint thePoints[])
74         {
75                 if (edges == TRIANGLE)
76                 {
77                         int halfWidth = 0;
78                         int halfHeigth = 0;
79                         if ( barOrientation ) // HORIZONTAL
80                         {
81                                 halfWidth = (int)(width/2);
82                                 halfHeigth = (int)(heigth/2);
83                                 switch ( orientation ) 
84                                 {
85                                   case UP : 
86                                         thePoints[0].x = halfWidth;
87                                         thePoints[0].y = 0;
88                                         thePoints[1].x = width;
89                                         thePoints[1].y = heigth;
90                                         thePoints[2].x = -halfWidth;
91                                         thePoints[2].y = heigth;
92                                         break;
93                                         
94                                   case DOWN : 
95                                         thePoints[0].x = halfWidth;
96                                         thePoints[0].y = heigth;
97                                         thePoints[1].x = width;
98                                         thePoints[1].y = 0;
99                                         thePoints[2].x = -halfWidth;
100                                         thePoints[2].y = 0;
101                                         break;
102
103                                   case LEFT : 
104                                         thePoints[0].x = 0;
105                                         thePoints[0].y = halfHeigth;
106                                         thePoints[1].x = width;
107                                         thePoints[1].y = 0;
108                                         thePoints[2].x = width;
109                                         thePoints[2].y = heigth;
110                                         break;
111
112                                   case RIGHT :          
113                                         thePoints[0].x = width;
114                                         thePoints[0].y = halfHeigth;            
115                                         thePoints[1].x = 0;
116                                         thePoints[1].y = 0;
117                                         thePoints[2].x = 0;
118                                         thePoints[2].y = heigth;
119                                         break;
120                                 }                       
121                         }
122                         else // VERTICAL
123                         {
124                                 halfWidth = (int)(heigth/2);
125                                 halfHeigth = (int)(width/2);
126                                 switch ( orientation ) 
127                                 {
128                                   case UP : 
129                                         thePoints[0].x = halfWidth;
130                                         thePoints[0].y = 0;
131                                         thePoints[1].x = heigth;
132                                         thePoints[1].y = width;
133                                         thePoints[2].x = -halfWidth;
134                                         thePoints[2].y = width;
135                                         break;
136                                         
137                                   case DOWN : 
138                                         thePoints[0].x = halfWidth;
139                                         thePoints[0].y = width;
140                                         thePoints[1].x = heigth;
141                                         thePoints[1].y = 0;
142                                         thePoints[2].x = -halfWidth;
143                                         thePoints[2].y = 0;
144                                         break;
145
146                                   case LEFT : 
147                                         thePoints[0].x = 0;
148                                         thePoints[0].y = halfHeigth;
149                                         thePoints[1].x = heigth;
150                                         thePoints[1].y = -halfHeigth;
151                                         thePoints[2].x = heigth;
152                                         thePoints[2].y = width;
153                                         break;
154
155                                   case RIGHT :          
156                                         thePoints[0].x = heigth;
157                                         thePoints[0].y = halfHeigth;            
158                                         thePoints[1].x = 0;
159                                         thePoints[1].y = -halfHeigth;
160                                         thePoints[2].x = 0;
161                                         thePoints[2].y = width;
162                                         break;
163                                 }       
164                         }                               
165                 }
166                 else if (edges == RECTANGLE)
167                 {
168                         if ( barOrientation ) // HORIZONTAL
169                         {
170                                 thePoints[0].x = 0;
171                                 thePoints[0].y = 0;             
172                                 thePoints[1].x = width;
173                                 thePoints[1].y = 0;
174                                 thePoints[2].x = width;
175                                 thePoints[2].y = heigth;
176                                 thePoints[3].x = 0;
177                                 thePoints[3].y = heigth;
178                         }
179                         else // VERTICAL
180                         {
181                                 thePoints[0].x = 0;
182                                 thePoints[0].y = 0;             
183                                 thePoints[1].x = heigth;
184                                 thePoints[1].y = 0;
185                                 thePoints[2].x = heigth;
186                                 thePoints[2].y = width;
187                                 thePoints[3].x = 0;
188                                 thePoints[3].y = width;
189                         }
190                 }
191         }
192
193         /**
194         * Sets the vertex points of the figure
195         * @param edges Vertex points distribution in the figure to set
196         */
197         void pFigure :: setVertexPoints(wxPoint * n_points)
198         {
199                 v_points = n_points;
200         }
201
202         /*
203         * Sets the heigth of the figure
204         * @param _h The heigth to set
205         */
206         void pFigure :: setHeigth(int _h)
207         {
208                 heigth = _h;
209         }
210
211         /*
212         * Gets the heigth of the figure
213         * @retval heigth The heigth of the figure
214         */
215         int pFigure :: getHeigth()
216         {
217                 return heigth;
218         }
219
220         /*
221         * Sets the width of the figure
222         * @param _w The width to set
223         */
224         void pFigure :: setWidth(int _w)
225         {
226                 width = _w;
227         }
228
229         /*
230         * Gets the width of the figure
231         * @retval width The width of the figure
232         */
233         int pFigure :: getWidth()
234         {
235                 return width;
236         }
237
238         /*
239         * Indicates if a pixel point is inside the figure
240         * @param xFig_PixelPoint The known reference point inside the figure
241         * @param xPixel The x-pixel coord asking for
242         * @retval Returns true if the point is inside
243         */
244         bool pFigure :: isPointInside(int xFig_PixelPoint, int xPixel)
245         {
246                 bool isInside = false;
247
248                 if (edges == TRIANGLE)
249                 {
250                         int halfWidth = (int)(width/2)+1;
251                         int halfHeigth = (int)(heigth/2)+1;
252                         if ( orientation == UP || orientation == DOWN )
253                         {
254                                 isInside = (xPixel>=xFig_PixelPoint-halfWidth) && (xPixel<=xFig_PixelPoint+halfWidth);
255                         }
256                         else if( orientation == LEFT || orientation == RIGHT )
257                         {
258                                 isInside = (xPixel>=xFig_PixelPoint-halfHeigth) && (xPixel<=xFig_PixelPoint+halfHeigth);
259                         }                                               
260                 }
261                 else if (edges == RECTANGLE)
262                 {
263                         isInside = (xPixel >= xFig_PixelPoint) && (xPixel<=xFig_PixelPoint+width);
264                 }
265                 return isInside;
266         }
267
268         /*
269         * Sets the bar orientation 
270         * @ bar_orientation The orientation to set (true for horizontal, false for vertical)
271         */
272         void pFigure :: setBarOrientation(bool bar_orientation)
273         {
274                 barOrientation = bar_orientation;
275         }
276
277         /*
278         * Sets the bar orientation used for triangles
279         * @ bar_orientation The orientation to set (LEFT = -4, RIGHT = -6, UP = -8, DOWN = -2)
280         */
281         void pFigure :: setFigureOrientation(int fig_orientation)
282         {
283                 orientation = fig_orientation;
284         }
285
286
287
288