]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pLogicalFunction.h
216cb92d2516a27161889c32e29659dc747a913d
[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
79         /**
80         Get Point list of the funcion
81         @param return points
82         */
83         /*virtual*/
84         void GetPoints(wxList &points)
85         {
86                 points = realPoints;
87         }  
88         /*
89         * 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  
90         * x1-validPointRange<x<x1+validPointRange y1-validPointRange<y<y1+validPointRange
91         */
92         int validPointOnFunction(wxPoint realPoint);
93
94         //returns the index in the list of the point  
95         int getIndexOf(wxPoint realpoint);
96
97         /*
98         * This metohd returns the node of the point that is the movingPointIndex position in the list of points.
99         * @param: int movingPointIndex, Is the index value of the searched node.
100         * @return: Return a pointer to the node corresponding to the index value by parameter.
101         */
102         wxNode* GetPointAt( int movingPointIndex);
103
104         /*
105         * Includes a point between two existing points of the this function. The new point (x,y) was not defined when the function was created.
106         *@ return Returns true is the point was succcesfully added to the funcion.
107         */
108         bool AddNewPoint(int x,int y);
109
110         /**
111         * this method add a new logical point to the function, this point is one of those used to draw the function
112         */
113         bool AddPoint(int aX, int aY,bool order=true);
114
115         /**
116         * deletes the point given by the  user  from the collection of logical points of the function
117         */
118         bool DeletePoint(int aX, int aY);
119
120         /**
121         * 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.
122         */
123         bool changePoint(wxPoint newCoords, int movingIndexPoint);
124
125         /**
126         * Evaluates if the given point belongs to the function.
127         * IS NO USED
128         */
129         //bool hasPoint(wxPoint aAPoint);
130
131         /**
132         * Returns the real x values of the control points of the function. It dont includes the points calculated by interpolation.
133         */
134         double * getX_RealValues();
135
136         /**
137         * Returns the real y values of the control points of the function. It dont includes the points calculated by interpolation.
138         */
139         double* getY_RealValues();
140         /*
141         * This method orders the list of points taking into account that the last appended node in the list (realPoint) is the only one disordered.
142         * @return Returns true if the last point included has a valid value for x and was ordered, according to the definition of function.
143         */
144         bool orderPoints();
145
146         /**
147         * This method get a pointer to the node in the real points list that is inmediately previous to the searched by parameter.
148         * @pre The seached point (realX, realY) is not the first point of the list.
149         * @param realX
150         * @param realY
151         * IS NOT USED
152         */
153         //wxNode * findPreviousNodeTo( int realX, int realY );
154
155         /*
156          * sets the start point of the function
157          */
158         void  setStartPoints();
159
160         /*
161          * sets the end point of the function
162          */
163         void setEndPoints();
164
165         /*
166          * set the max value in x and y between all the points of the function
167          */
168         void setMaxPoints();
169
170
171         /*
172          * set the min value in x and y between all the points of the function
173          */
174         void setMinPoints();
175         /*
176          * Set Up startPoint, endPoint, maxY,maxX points        
177         */
178         void setUp();
179
180
181         //set if the function has to draw the points  
182         //void SetShowPoints(bool showPoints);
183
184         //get the paramater showPointsF
185         //bool getShowPoints();
186
187         //-----------------------
188         // Persistence
189         //-----------------------
190
191         /*
192          Save the points of the function
193         */
194         void save(wxString fileName);
195         /*
196          Load the points of a function 
197         */
198         void load(wxString fileName);
199
200         //----------------------------
201         //Getters and Setters
202         //----------------------------
203
204         void setStartX(double aStartX);
205
206         double getStartX();
207
208         void setStartY(double aStartY);
209
210         double getStartY();
211
212         void setEndX(double aEndX);
213
214         double getEndX();
215
216         void setEndY(double aEndY);
217
218         double getEndY();
219
220         void setScaleX(double aScaleX);
221
222         double getScaleX();
223
224         void setScaleY(double aScaleY);
225
226         double getScaleY();
227
228         void setMinX(double aMinX);
229
230         double getMinX();
231
232         void setMinY(double aMinY);
233
234         double getMinY();
235
236         void setMaxX(double aMaxX);
237
238         double getMaxX();
239
240         void setMaxY(double aMaxY);
241
242         double getMaxY();
243
244         void setOffsetX(double aOffsetX);
245
246         double getOffsetX();
247
248         void setOffsetY(double aOffsetY);
249
250         double getOffsetY();
251
252         void setType(int aType);
253
254         int getType();
255
256         int getValidPointRange();
257
258         void setValidPointRange(int theRange);
259
260         /**
261         * Deletes a point of the function given its index 
262         */
263         bool deletePointAt(int index);
264         /*
265         * Returns the number of points that the function
266         * has
267         */
268         int getSizePoints();
269
270         void getDirection(bool &dir);
271
272
273
274 private:
275
276         /**
277         * Is the initial discrete point on x axis of the drawed function.
278         */
279         double _startX;
280         /**
281         * Is the initial discrete point on y axis of the drawed function.
282         */
283         double _startY;
284         /**
285         * Is the last discrete point on x axis of the drawed function.
286         */
287         double _endX;
288         /**
289         * Is the last discrete point on y axis of the drawed function.
290         */
291         double _endY;
292         /**
293         * Is the x-scale percentage according to the context device.
294         */
295         double _scaleX;
296         /**
297         * Is the y-scale percentage according to the context device.
298         */
299         double _scaleY;
300         /**
301         * Is the minimun x-real value reacheable by the function.
302         */
303         double _minX;
304         /**
305         * Is the minimun y-real value reacheable by the function.
306         */
307         double _minY;
308         /**
309         * Is the maximun y-real value reacheable by the function.
310         */
311         double _maxX;
312
313         /**
314         * Is the maximun y-real value reacheable by the function.
315         */
316         double _maxY;
317
318         /**
319         * Is the logical x-offset of the drawed function.
320         */
321         double _offsetX;
322         /**
323         * Is the logical y-offset of the drawed function.
324         */
325         double _offsetY;
326         /**
327         * Is the way of how points are going to be connected. It could be smooth, line.
328         */
329         int _type;
330         /**
331         * The list of the function points
332         */
333         wxList realPoints;
334
335         /**
336         *  x-values
337         */
338         double x_Values[MAX_POINTS];
339         /**
340         *  y-values
341         */
342         double y_Values[MAX_POINTS];
343         /**
344         *  node of the realPoints where are we
345         */
346         //wxNode* node;
347         
348         /**
349         * Number that determines the radius range for the valid area the point (sensible radius). Default value 5.
350         */
351         int validPointRange;
352
353         /**
354         * 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.
355         * It is initialized when the second point is included in the funcion.
356         */
357         bool leftToRigthDef;
358
359         /**
360         * Indicates if the user is drawing the function
361         */
362         //bool drawing;
363
364
365         DECLARE_CLASS (pLogicalFunction)
366 };
367
368 #endif
369
370