3 #ifndef __pGraphicalFunction_h__
4 #define __pGraphicalFunction_h__
6 // ----------------------------------------------------------------------------
7 // WX headers inclusion.
8 // For compilers that support precompilation, includes <wx/wx.h>.
9 // ----------------------------------------------------------------------------
11 #include <wx/wxprec.h>
20 //----------------------------------------------------------------------------
22 //----------------------------------------------------------------------------
25 #include "pPlotterLayer.h"
26 #include "pFunctionPoint.h"
27 #include "pLogicalFunction.h"
28 #include "pColorPoint.h"
29 #include "vtkKochanekSpline.h"
35 this scale, scales each function with its maximum x, and maximum y
38 #define DEFECT_SCALE 1
40 this scale with the maximun x and y of all the functions defined
44 this scales with the scale giving by the user of the widget
52 Lets to the user to plot any number of the
57 Dont let draw on the plotter, but lets to edit
58 the functions that are editables in the plotter
62 class pGraphicalFunction;
63 //----------------------------------------------------------------------------
65 //----------------------------------------------------------------------------
68 class pGraphicalFunction: public pPlotterLayer
73 pGraphicalFunction(wxString name= wxEmptyString, int flags= mpALIGN_RIGHT);
75 ~pGraphicalFunction( );
77 //---------------------------
79 //---------------------------
82 Get the value of the traslation
85 virtual int getXTraslation()
94 Get the type of the curve
98 virtual int getmType()
104 Get the type of the curve
108 virtual int vGetType()
114 Get _offsetX and _offsetY
117 virtual void getOffsets(int &offsetX,int &offSetY )
119 offsetX=(int)_offsetX;
120 offsetY=(int)_offsetY;
124 * Get the factor zoom
126 virtual void getFactorZoom(float & fz)
133 * Get the value of fromWindow
135 virtual void getFromWindowV(bool &fw)
142 * if the function that is drawing is the actual
144 virtual void getIfActual(bool &actual)
150 * get the max of the function in x and y
152 virtual void getMax(int & maxX, int &maxY)
158 * get the maxShowed of the function in x and y
160 virtual void getMaxShowed(int & maxX, int &maxY)
162 maxX=(int)getMaxXShowed();
163 maxY=(int)getMaxYShowed();
166 * get the minShowed of the function in x and y
168 virtual void getMinShowed(int & minX, int &minY)
170 minX=(int)getMinXShowed();
171 minY=(int)getMinYShowed();
175 * Get screens of the function
177 virtual void getScreens(int & scrX, int & scrY)
186 virtual void setScreens(int scrX,int scrY)
193 * Let us know the scale of the function
195 virtual void getScales(double & scaleX,double & scaleY)
203 * Let us Know if the user has finished the drawing
204 * that starts before.
207 virtual void getDrawing(bool &draw)
213 Let us Know if the user want to see the points of the function
214 of other color than the color of the lines
216 virtual void ifShowPoints(bool & show)
224 virtual void Rewind()
227 node = logicFunction->GetPointAt(0);
231 /** Get locus value for next N.
232 Override this function in your implementation.
233 @param x Returns X value
234 @param y Returns Y value
236 virtual bool GetNextXY(double & x, double & y)
240 pFunctionPoint* p=(pFunctionPoint*)node->GetData();
243 node=node->GetNext();
249 Get Point list of the funcion
252 virtual void GetPoints(wxList &points)
254 logicFunction->GetPoints(points);
255 //points = realPoints;
259 Get the point where the user
263 virtual void getMousePoint(int &x,int &y)
270 * Get the number of points of the function
272 virtual void getSize(int &size)
274 size=getSizePoints();
278 * this method gets the direction of the drawing
280 virtual void getDirection(bool &dir)
282 logicFunction -> getDirection (dir);
285 //---------------------------
287 //---------------------------
289 * 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
290 * x1-validPointRange<x<x1+validPointRange y1-validPointRange<y<y1+validPointRange
292 int validPointOnFunction(wxPoint realPoint);
294 //returns the index in the list of the point
295 int getIndexOf(wxPoint realpoint);
298 * This metohd returns the node of the point that is the movingPointIndex position in the list of points.
299 * @param: int movingPointIndex, Is the index value of the searched node.
300 * @return: Return a pointer to the node corresponding to the index value by parameter.
302 wxNode* GetPointAt( int movingPointIndex);
305 * Includes a point between two existing points of the this function. The new point (x,y) was not defined when the function was created.
306 *@ return Returns true is the point was succcesfully added to the funcion.
308 bool AddNewPoint(int x,int y);
311 * this method add a new logical point to the function, this point is one of those used to draw the function
313 bool AddPoint(int aX, int aY,bool order=true);
316 * deletes the point given by the user from the collection of logical points of the function
318 bool DeletePoint(int aX, int aY);
321 * 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.
323 bool changePoint(wxPoint newCoords, int movingIndexPoint);
326 * Evaluates if the given point belongs to the function.
328 //bool hasPoint(wxPoint aAPoint);
331 * Returns the real x values of the control points of the function. It dont includes the points calculated by interpolation.
333 double * getX_RealValues();
336 * Returns the real y values of the control points of the function. It dont includes the points calculated by interpolation.
338 double* getY_RealValues();
340 * This method orders the list of points taking into account that the last appended node in the list (realPoint) is the only one disordered.
341 * @return Returns true if the last point included has a valid value for x and was ordered, according to the definition of function.
346 * This method get a pointer to the node in the real points list that is inmediately previous to the searched by parameter.
347 * @pre The seached point (realX, realY) is not the first point of the list.
351 //wxNode * findPreviousNodeTo( int realX, int realY );
354 * Deletes a point of the function given its index
356 bool deletePointAt(int index);
358 * Returns the number of points that the function
363 * Set the scales of the function in x and y
367 //----------------------------------
368 // Asking if it has a point (x,y)
369 //----------------------------------
372 * returns true if the point is along the function
375 bool isInFunction(int x, int y);
377 * give us the point that is in the function and is exactly before
378 * the point we are giving
380 wxNode* getBefore(pFunctionPoint* point);
382 * Returns true if the point is in the line
384 bool isInLine(pFunctionPoint* before,pFunctionPoint* next, pFunctionPoint* point);
386 * give us the value of y in the line define by the arguments
388 double interpolateY(double m, int x1,int y1,int x);
390 * Set Up startPoint, endPoint, maxY,maxX points
393 //----------------------------
395 //----------------------------
397 * clear the spline vectors
399 void clearSplineVectors();
403 Initiliaze xSpline and ySpline vectors
405 void initializeSplines();
408 Add the (x,y) points of the function to the
411 void addSplinesPoints();
414 This Method adds the point calculated by
415 the splines to the vectors
417 void initializeSplineVectors();
420 get the spline point for t, in xKSpline and yKSpline
422 void GetSplinePoint(double t, double &x, double &y);
424 returns the xSpline to plotter
426 virtual std::vector<double> getXSpline()
431 returns the ySpline to plotter
433 virtual std::vector<double> getYSpline()
440 Gets the x-offset of the zoom
443 virtual int getOffsetPixelsXv()
449 Gets the offset of the zoom
452 virtual int getOffsetPixelsYv()
457 //-----------------------
459 //-----------------------
462 Save the points of the function
464 void save(wxString fileName);
466 Load the points of a function
468 void load(wxString fileName);
470 //------------------------------
471 // Getters and Setters
472 //------------------------------
474 //set if the function has to draw the points
475 void SetShowPoints(bool showPoints);
477 //get the paramater showPointsF
478 bool getShowPoints();
480 void setScreenX(int scrX);
484 void setScreenY(int scrY);
488 void setStartX(double aStartX);
492 void setStartY(double aStartY);
496 void setEndX(double aEndX);
500 void setEndY(double aEndY);
504 void setScaleX(double aScaleX);
508 void setScaleY(double aScaleY);
512 void setMinX(double aMinX);
516 void setMinY(double aMinY);
520 void setMaxX(double aMaxX);
524 void setMaxY(double aMaxY);
528 void setOffsetX(double aOffsetX);
532 void setOffsetY(double aOffsetY);
536 void setType(int aType);
540 int getValidPointRange();
542 void setValidPointRange(int theRange);
544 void SetDrawing(bool d)
548 //get if the function is being drawed
554 //set the mouse point
555 void SetMousePoint(wxPoint p)
560 wxPoint getMousePoint()
567 void setActual(bool act);
577 void setScaleWay(int typeS);
582 * set fromWindow: it is set to true if the
583 * function was created interactively
585 void setFromWindow(bool w)
591 * Get the value of fromWindow
600 void setFactorZoom(float factor)
607 void setEditable(bool edit)
619 //----------------------------
621 //----------------------------
632 * @param z: the new value
634 void setZoomIn(bool z)
639 * Set the initial drawing point
640 * @param pFunctionPoint* initialPoint
642 void setInitialDrawPoint(pFunctionPoint* initialPoint)
644 initialDrawingPoint=initialPoint;
647 * Get the initial drawing point
648 * @return initialDrawingPoint
650 pFunctionPoint* getInitialDrawPoint()
652 return initialDrawingPoint;
655 * Set the final drawing point
656 * @param pFunctionPoint* finalPoint
658 void setFinalDrawPoint(pFunctionPoint* finalPoint)
660 finalDrawingPoint=finalPoint;
663 * Get the final drawing point
664 * @return finalDrawingPoint
666 pFunctionPoint* getFinallDrawPoint()
668 return finalDrawingPoint;
671 This method set the initial point and the final point of drawing
672 according with the width of the square around the point clicked
675 @param width: width of the square
678 void zooming(int clickedX,int clickedY,int width);
681 * This method sets the offset
683 void setOffsets(int offx,int offy);
686 * This method sets the minShowedX
687 * and the minShowedY, accordig to the offset in
688 * x-axis and y-axis respectively
689 * pre: _offsetX>=0,_offsetY>=0
724 void setMinShowedX(int msx)
731 void setMinShowedY(int msy)
738 void setMaxShowedX(int msx)
745 void setMaxShowedY(int msy)
750 //------------------------
752 //------------------------
755 Gets the x-offset of the zoom
758 int getOffsetPixelsX()
764 Gets the offset of the zoom
767 int getOffsetPixelsY()
772 Set the x-offset of the zoom
774 void setOffsetPixelX(int offX)
779 Set the y-offset of the zoom
781 void setOffsetPixelY(int offY)
789 * Sets the color points of the function by teh given parameter
790 * @param colorVector Is the color points vector to set
792 void setColorPoints(std::vector<pColorPoint *> &colorVector);
795 * Gets the color points of the function in the given parameter
796 * @param colorVector Is the color points list to get the points
798 void getColorPoints(std::vector<pColorPoint *> &colorVector);
802 void setmType(int mt)
806 //-----------------------
808 //-----------------------
810 Set the value of the traslation
812 @param xT value in pixels of the traslation in x-axis
814 void setXTraslation(int xT)
824 * Represents the logical function asociated to this graphical function.
826 pLogicalFunction* logicFunction;
828 * If the function has to showpoints
833 * Is the initial discrete point on x axis of the drawed function.
837 * Is the initial discrete point on y axis of the drawed function.
841 * Is the last discrete point on x axis of the drawed function.
845 * Is the last discrete point on y axis of the drawed function.
849 * Is the x-scale percentage according to the context device.
853 * Is the y-scale percentage according to the context device.
857 * Is the minimun x-real value reacheable by the function.
861 * Is the minimun y-real value reacheable by the function.
865 * Is the maximun x-real value reacheable by the function.
869 * Is the maximun y-real value reacheable by the function.
873 * Is the logical x-offset of the drawed function.
877 * Is the logical y-offset of the drawed function.
881 * Is the way of how points are going to be connected. It could be smooth, line.
885 * The list of the function points
889 * The list of the color points of the function associated to the color bar
891 std::vector<pColorPoint *> f_colorPoints;
894 * node of the realPoints where are we
898 * Number that determines the radius range for the valid area the point (sensible radius). Default value 5.
903 * Indicates if the user is drawing the function
908 * this is for the graphical function
914 * The size of the screen in X
919 * The size of the screen in Y
937 if the function comes from window
945 * The function is editable
949 * if the user did a zoom in/out
953 * initial drawing point
955 pFunctionPoint* initialDrawingPoint;
957 * final drawing point
959 pFunctionPoint* finalDrawingPoint;
961 Minimum point showed to the user
966 Maximum point showed to the user
971 Minimum point showed to the user
976 Maximum point showed to the user
983 Vectors where the spline is stored
985 std::vector<double> xSpline;
987 std::vector<double> ySpline;
992 vtkKochanekSpline* xKSpline;
994 vtkKochanekSpline* yKSpline;
998 offset in pixels where the user has clicked
999 before changing the scale
1004 type of the meaning of the function
1005 DEFAULT=1; the function has no meaning
1006 HISTOGRAM=2. The function represents an histogram
1012 is use for lets the user move the function
1016 DECLARE_CLASS (pGraphicalFunction)