]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pLogicalFunction.h
creaMaracasVisu Library
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pLogicalFunction.h
1
2 #ifndef __pLogicalFunction_h__
3 #define __pLogicalFunction_h__
4
5 // ----------------------------------------------------------------------------
6 // WX headers inclusion.
7 // For compilers that support precompilation, includes <wx/wx.h>.
8 // ----------------------------------------------------------------------------
9
10 #include <wx/wxprec.h>
11 #ifdef __BORLANDC__
12 #pragma hdrstop
13 #endif
14 #ifndef WX_PRECOMP
15 #include <wx/wx.h>
16 #endif
17
18
19 //----------------------------------------------------------------------------
20 // Includes
21 //----------------------------------------------------------------------------
22
23 #include "pFunctionPoint.h"
24 #include <iostream>
25 #include <fstream>
26 #include <string>
27
28
29
30 class pLogicalFunction;
31 //----------------------------------------------------------------------------
32 // Class definition
33 //----------------------------------------------------------------------------
34 #define MAX_POINTS 50
35
36 //if your are going to change se sensible region  you have to change MOVE in pPlotterLayer
37 #define SENSIBLE_REGION 5
38
39
40 class pLogicalFunction: public wxObject
41 {
42 public:
43
44         //----------------------------------------------------------------------------
45         // Constructors
46         //----------------------------------------------------------------------------
47         pLogicalFunction( );
48
49         ~pLogicalFunction( );
50         
51         /**
52         *Rewind 
53         */
54         /*virtual void Rewind()
55         {
56                 node = realPoints.GetFirst();
57         }
58         */
59         
60         /** Get locus value for next N.
61         Override this function in your implementation.
62         @param x Returns X value
63         @param y Returns Y value
64         */
65         /*virtual bool GetNextXY(double & x, double & y) 
66         {
67                 if(node)
68                 {
69                         pFunctionPoint* p=(pFunctionPoint*)node->GetData();
70                         x=p->getRealX();
71                         y=p->getRealY();
72                         node=node->GetNext();
73                         return true;
74                 }
75                 return false;
76         }
77         /**
78         Get Point list of the funcion
79         @param return points
80         */
81         /*virtual*/
82         void GetPoints(wxList &points)
83         {
84                 points = realPoints;
85         }  
86         /*
87         * validate if the function has that point in a sensible area returning the index where the point was found or -1 if is in not part of the function: define the sensible area is  
88         * x1-validPointRange<x<x1+validPointRange y1-validPointRange<y<y1+validPointRange
89         */
90         int validPointOnFunction(wxPoint realPoint);
91
92         //returns the index in the list of the point  
93         int getIndexOf(wxPoint realpoint);
94
95         /*
96         * This metohd returns the node of the point that is the movingPointIndex position in the list of points.
97         * @param: int movingPointIndex, Is the index value of the searched node.
98         * @return: Return a pointer to the node corresponding to the index value by parameter.
99         */
100         wxNode* GetPointAt( int movingPointIndex);
101
102         /*
103         * Includes a point between two existing points of the this function. The new point (x,y) was not defined when the function was created.
104         *@ return Returns true is the point was succcesfully added to the funcion.
105         */
106         bool AddNewPoint(int x,int y);
107
108         /**
109         * this method add a new logical point to the function, this point is one of those used to draw the function
110         */
111         bool AddPoint(int aX, int aY,bool order=true);
112
113         /**
114         * deletes the point given by the  user  from the collection of logical points of the function
115         */
116         bool DeletePoint(int aX, int aY);
117
118         /**
119         * Change de coordinates of the given point if it is possible and return the result of the invoked action. True if it was possible to do the change.
120         */
121         bool changePoint(wxPoint newCoords, int movingIndexPoint);
122
123         /**
124         * Evaluates if the given point belongs to the function.
125         * IS NO USED
126         */
127         //bool hasPoint(wxPoint aAPoint);
128
129         /**
130         * Returns the real x values of the control points of the function. It dont includes the points calculated by interpolation.
131         */
132         double * getX_RealValues();
133
134         /**
135         * Returns the real y values of the control points of the function. It dont includes the points calculated by interpolation.
136         */
137         double* getY_RealValues();
138         /*
139         * This method orders the list of points taking into account that the last appended node in the list (realPoint) is the only one disordered.
140         * @return Returns true if the last point included has a valid value for x and was ordered, according to the definition of function.
141         */
142         bool orderPoints();
143
144         /**
145         * This method get a pointer to the node in the real points list that is inmediately previous to the searched by parameter.
146         * @pre The seached point (realX, realY) is not the first point of the list.
147         * @param realX
148         * @param realY
149         * IS NOT USED
150         */
151         //wxNode * findPreviousNodeTo( int realX, int realY );
152
153         /*
154          * sets the start point of the function
155          */
156         void  setStartPoints();
157
158         /*
159          * sets the end point of the function
160          */
161         void setEndPoints();
162
163         /*
164          * set the max value in x and y between all the points of the function
165          */
166         void setMaxPoints();
167
168
169         /*
170          * set the min value in x and y between all the points of the function
171          */
172         void setMinPoints();
173         /*
174          * Set Up startPoint, endPoint, maxY,maxX points        
175         */
176         void setUp();
177
178
179         //set if the function has to draw the points  
180         //void SetShowPoints(bool showPoints);
181
182         //get the paramater showPointsF
183         //bool getShowPoints();
184
185         //-----------------------
186         // Persistence
187         //-----------------------
188
189         /*
190          Save the points of the function
191         */
192         void save(wxString fileName);
193         /*
194          Load the points of a function 
195         */
196         void load(wxString fileName);
197
198         //----------------------------
199         //Getters and Setters
200         //----------------------------
201
202         void setStartX(double aStartX);
203
204         double getStartX();
205
206         void setStartY(double aStartY);
207
208         double getStartY();
209
210         void setEndX(double aEndX);
211
212         double getEndX();
213
214         void setEndY(double aEndY);
215
216         double getEndY();
217
218         void setScaleX(double aScaleX);
219
220         double getScaleX();
221
222         void setScaleY(double aScaleY);
223
224         double getScaleY();
225
226         void setMinX(double aMinX);
227
228         double getMinX();
229
230         void setMinY(double aMinY);
231
232         double getMinY();
233
234         void setMaxX(double aMaxX);
235
236         double getMaxX();
237
238         void setMaxY(double aMaxY);
239
240         double getMaxY();
241
242         void setOffsetX(double aOffsetX);
243
244         double getOffsetX();
245
246         void setOffsetY(double aOffsetY);
247
248         double getOffsetY();
249
250         void setType(int aType);
251
252         int getType();
253
254         int getValidPointRange();
255
256         void setValidPointRange(int theRange);
257
258         /**
259         * Deletes a point of the function given its index 
260         */
261         bool deletePointAt(int index);
262         /*
263         * Returns the number of points that the function
264         * has
265         */
266         int getSizePoints();
267
268         void getDirection(bool &dir);
269
270
271
272 private:
273
274         /**
275         * Is the initial discrete point on x axis of the drawed function.
276         */
277         double _startX;
278         /**
279         * Is the initial discrete point on y axis of the drawed function.
280         */
281         double _startY;
282         /**
283         * Is the last discrete point on x axis of the drawed function.
284         */
285         double _endX;
286         /**
287         * Is the last discrete point on y axis of the drawed function.
288         */
289         double _endY;
290         /**
291         * Is the x-scale percentage according to the context device.
292         */
293         double _scaleX;
294         /**
295         * Is the y-scale percentage according to the context device.
296         */
297         double _scaleY;
298         /**
299         * Is the minimun x-real value reacheable by the function.
300         */
301         double _minX;
302         /**
303         * Is the minimun y-real value reacheable by the function.
304         */
305         double _minY;
306         /**
307         * Is the maximun y-real value reacheable by the function.
308         */
309         double _maxX;
310
311         /**
312         * Is the maximun y-real value reacheable by the function.
313         */
314         double _maxY;
315
316         /**
317         * Is the logical x-offset of the drawed function.
318         */
319         double _offsetX;
320         /**
321         * Is the logical y-offset of the drawed function.
322         */
323         double _offsetY;
324         /**
325         * Is the way of how points are going to be connected. It could be smooth, line.
326         */
327         int _type;
328         /**
329         * The list of the function points
330         */
331         wxList realPoints;
332
333         /**
334         *  x-values
335         */
336         double x_Values[MAX_POINTS];
337         /**
338         *  y-values
339         */
340         double y_Values[MAX_POINTS];
341         /**
342         *  node of the realPoints where are we
343         */
344         //wxNode* node;
345         
346         /**
347         * Number that determines the radius range for the valid area the point (sensible radius). Default value 5.
348         */
349         int validPointRange;
350
351         /**
352         * Indicates the way the function is being drawed when defining it. So that it is true if the direction is from left-to-right, and false if it is from right-to-left.
353         * It is initialized when the second point is included in the funcion.
354         */
355         bool leftToRigthDef;
356
357         /**
358         * Indicates if the user is drawing the function
359         */
360         //bool drawing;
361
362
363         DECLARE_CLASS (pLogicalFunction)
364 };
365
366 #endif
367
368