2 #ifndef __pPlotterWindow_h__
3 #define __pPlotterWindow_h__
5 // ----------------------------------------------------------------------------
6 // WX headers inclusion.
7 // For compilers that support precompilation, includes <wx/wx.h>.
8 // ----------------------------------------------------------------------------
10 #include <wx/wxprec.h>
18 //----------------------------------------------------------------------------
20 //----------------------------------------------------------------------------
23 #include "pPlotterLayer.h"
24 #include "pGraphicalFunction.h"
29 /** Command IDs used by pPlotterWindow */
32 pwID_ADDPOINT = 2010, //!< add a point to the function
33 pwID_DELPOINT, //!< delete a point of the function
34 pwID_SHOWPOINTS, //!<shows the points that the function has
35 pwID_STARTDRAWING, //!<let to the user to start drawing the curve
36 pwID_DELFUNCTION, //!<delete a function that is in the plotter
37 pwID_STOPDRAWING,//!<Stops the drawing of the function
38 pwID_ADDNEWPOINT,//!<add a new point to the function.
39 pwID_NOSHOWPOINTS, //!<No show the points of the function.
40 pwID_MYZOOMIN,//!<Zoom in the function
41 pwID_MYZOOMOUT,//!<Zoom out the points of the function.
42 pwID_SPLINE,//!<Spline the actual curve.
43 pwID_LINE,//!<Piecewise the actual curve.
44 pwID_SAVE,//!<Save the function in a .txt file.
45 pwID_LOAD, //!<Load the function from a .txt file.
46 pwID_CHANGECOLOR, //!<Change the color of the function
47 pwID_TRASLATEACTUALFUNCTION, //!<move the actual function
48 pwID_LEFTUP//!<listening a click up
52 #define MAX_FUNCTIONS 7
54 this scale, scales each function with its maximum x, and maximum y
57 #define DEFAULT_SCALE 1
59 this scale with the maximun x and y of all the functions defined
63 this scales with the scale giving by the user of the widget
71 Lets to the user to plot any number of the
74 #define DEFAULT_PLOTTER 1
76 Dont let draw on the plotter, but lets to edit
77 the functions that are editables in the plotter
79 #define HISTOGRAM_PLOTTER 2
81 * THE FACTOR TO ZOOM (IN,OUT)
83 //#define ZOOM_FACTOR 2
84 //----------------------------------------------------------------------------
86 //----------------------------------------------------------------------------
88 class pPlotterWindow: public mpWindow
92 * Constructors and destructor
94 pPlotterWindow( wxWindow *parent, wxWindowID id,
95 const wxPoint &pos = wxDefaultPosition,
96 const wxSize &size = wxDefaultSize,
100 //----------------------------
101 //Handling Options Menu
102 //----------------------------
104 if any parameter is true, is going to be remove from the popUp menu
106 void setPopUpMenu(bool startD,bool stopD,bool smooth,bool line, bool zoomIn,
107 bool zoomOut,bool showPoints,bool noShowPoints,bool changeColor, bool addP,
108 bool delPoint,bool load,bool save);
111 //-------------------------------
112 //Traslating the actual function
113 //-------------------------------
115 Manipulating clicks on the plotter
117 void onLeftUp(wxMouseEvent& event);
120 Move the actual function when the user
123 void onMoveFunction(wxCommandEvent& aEvent);
127 * Change the color of the function
129 void onChangeColor(wxCommandEvent& aEvent);
133 * Load the function from a .txt file
135 void onLoad(wxCommandEvent& aEvent);
138 * Save the points of the function in a .txt file
140 void onSave(wxCommandEvent& aEvent);
144 * Change the type of drawing of the actual function
145 * to a piecewise function
147 void onLine(wxCommandEvent& aEvent);
151 * Spline the points of the actual curve
153 void onSplinePoints(wxCommandEvent& aEvent);
157 * Zoom out the functions
159 void onMyZoomOut(wxCommandEvent& aEvent);
162 * Zoom in the functions
164 void onMyZoomIn(wxCommandEvent& aEvent);
167 * Transform the point clicked from window
168 * to the real value,given by the scale
170 wxPoint getRealPoint(wxPoint pixelPoint);
173 * The user doesnt want see the points of the function
175 void onNoShowPoints(wxCommandEvent& aEvent);
178 Stop the drawing of the actual function
180 void onStopDrawing(wxCommandEvent& aEvent);
183 * Adds a point to the function after the definition of the initial points of the function
184 * know this point is a point of the function
187 void onAddNewPoint(wxCommandEvent& aEvent);
190 * Let to the user to start drawing
192 void onStartDrawing(wxCommandEvent& aEvent);
195 * Listens the event of the mouse when it is moving, this is use to know if the user is moving a pont of the function and in tha way to know when repainting.
197 void onMouseMove(wxMouseEvent& event);
200 * Listens the event mouse left button double click.
201 * if the user give us a double click is because he wants to change
202 * the actual function to the function that has that point
204 void onChangeActual(wxMouseEvent& event);
207 * Add a new point to the function and then repaint
209 void onAddPoint(wxMouseEvent& aEvent);
212 * Deletes a point of the function and then repaint
214 void onDeletePoint(wxCommandEvent& aEvent);
217 * Shows graphicly the discrete points that the function has
219 void onShowPoints(wxCommandEvent& aEvent);
222 * Changes the type according to the specified number of the type. If the second parameter, the boolean one is true indicates that this action must be done in all the funtion, if not it will be applied only to the actual selected function.
225 void changeFuntionType(int aTheType, bool aForAll);
228 * Add a function to the plotter
229 * when the function doesnt come from window
231 int addFunction(pGraphicalFunction * function);
234 * Delete a point of a function
235 * @param point: is the real value that the functon takes, and is gointg to be deleted
237 bool DeletePointFunction(pGraphicalFunction* function,wxPoint point);
240 * Delete a function of the plotter
242 bool deleteFunction(pGraphicalFunction * f);
244 * Sets the actual function
245 * @param newActual: new function
247 void setActualFunction(pGraphicalFunction* newActual);
249 * Get the actual function
251 pGraphicalFunction* getActualFunction();
254 * Creates and returns a graphical funcion according to the indicated vectors.
256 void InitFunctionForVectors( pGraphicalFunction *ff );
257 pGraphicalFunction * getFunctionForVectors( double* vectorX, int sizeX,double * vectorY, int sizeY );
258 pGraphicalFunction * getFunctionForVectors( std::vector<double> *vectorX, std::vector<double> *vectorY );
261 Set the scales according to the size of the window
262 and the maximum given by the user
265 void setActualScales();
271 void setmLog(wxTextCtrl *m_log1)
277 * Actualizes the view range of the plotter and the actual function
278 * @param newMinX Is the min-value to be shown in the x-scale
279 * @param newMaxX Is the max-value to be shown in the x-scale
281 void actualizeViewRange(int newMinX, int newMaxX);
284 * Sets the condition for drawing or not the guide lines
285 * @param ifDrawing The new condition to assing
287 void setLineGuidesCondition(bool ifDrawing)
289 drawGuides = ifDrawing;
294 * Gets the condition for drawing or not the guide lines
295 * @retval drawGuides The assigned condition
297 bool drawGuideLines()
302 * Guide lines menu handler method that reacts to the mpID_LINE_GUIDES cimmand event
303 * event The corresponding event to handle
305 void OnGuideLines (wxCommandEvent &event);
308 writes in t information
310 void writeInText(wxString &t)
316 Get a function in the plotter given the index
318 pGraphicalFunction* getFunction(int index);
321 move the functions that the user wants to move
322 and that were setted in functionsToMove
323 @param porcentageMinX:the porcentage that the minShowed
324 of the funcntions have to be move
325 @param porcentageMaxX:the porcentage that the maxShowed
326 of the funcntions have to be move
329 void moveFunctions(float porcentageMinX,float porcentageMaxX);
331 * Add a function to the plotter
332 * when the function doesnt come from window
334 int addFunctionToMove(pGraphicalFunction * function);
342 pGraphicalFunction* actual;
349 * If is drawing the function
353 * Index of the movig point, if the user is moving
356 int movingPointIndex;
368 Use to Show Information
375 Functions to be move at the same time
377 wxList functionsToMove;
379 the user is moving the function
384 int initialMovingCLick;
387 saving the initial function
389 std::vector<double> backUpActualVector;
391 wants to move the points of the function
395 DECLARE_CLASS (pPlotterWindow)
396 //----------------------------------------------------------------------------
397 // wxWidget macro use declaration for handdling events
398 //----------------------------------------------------------------------------
399 DECLARE_EVENT_TABLE()