]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pPlotterWindow.h
creaMaracasVisu Library
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pPlotterWindow.h
1
2 #ifndef __pPlotterWindow_h__
3 #define __pPlotterWindow_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 // Includes
20 //----------------------------------------------------------------------------
21
22
23 #include "pPlotterLayer.h"
24 #include "pGraphicalFunction.h"
25 #include "mathplot.h"
26
27
28
29 /** Command IDs used by pPlotterWindow */
30 enum
31 {
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
49
50 };
51
52 #define MAX_FUNCTIONS 7
53 /**
54  this scale, scales each function with its maximum x, and maximum y
55  in its points
56 */
57 #define DEFAULT_SCALE 1
58 /**
59  this scale with the maximun x  and y of all the functions defined
60 */
61 #define MAX_SCALE 2
62 /**
63  this scales with the scale giving by the user of the widget
64 */
65 #define USER_SCALE 3
66
67 /*
68  Types of Plotter
69 */
70 /*
71  Lets to the user to plot any number of the
72  functions
73 */
74 #define DEFAULT_PLOTTER 1
75 /*
76  Dont let draw on the plotter, but lets to edit
77  the functions that are editables in the plotter
78 */
79 #define HISTOGRAM_PLOTTER 2
80 /**
81 * THE FACTOR TO ZOOM (IN,OUT)
82 */
83 //#define ZOOM_FACTOR 2
84 //----------------------------------------------------------------------------
85 // Class definition
86 //----------------------------------------------------------------------------
87
88 class pPlotterWindow: public mpWindow
89 {
90 public:
91         /**
92         * Constructors and destructor
93         */         
94         pPlotterWindow( wxWindow *parent, wxWindowID id,
95                 const wxPoint &pos = wxDefaultPosition,
96                 const wxSize &size = wxDefaultSize,
97                 int flags = 0);
98         ~pPlotterWindow();
99         
100         //----------------------------
101         //Handling Options Menu
102         //----------------------------
103         /*
104         if any parameter is true, is going to be remove from the popUp menu
105         */
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);
109
110
111         //-------------------------------
112         //Traslating the actual function
113         //-------------------------------
114         /*
115                 Manipulating clicks on the plotter
116         */
117         void onLeftUp(wxMouseEvent& event);
118         
119         /*
120          Move the actual function  when the user
121          is moving the mouse
122         */
123         void onMoveFunction(wxCommandEvent& aEvent);
124
125
126         /**
127         * Change the color of the function
128         */
129         void onChangeColor(wxCommandEvent& aEvent);
130
131
132         /**
133         * Load the function from a .txt file
134         */
135         void onLoad(wxCommandEvent& aEvent);
136
137         /**
138         * Save the points of the function in a .txt file
139         */
140         void onSave(wxCommandEvent& aEvent);
141
142
143         /**
144         * Change the type of drawing of the actual function
145         * to a piecewise function
146         */
147         void onLine(wxCommandEvent& aEvent);
148
149
150         /**
151         * Spline the points of the actual curve
152         */
153         void onSplinePoints(wxCommandEvent& aEvent);
154         
155         
156         /**
157         * Zoom out the functions
158         */
159         void onMyZoomOut(wxCommandEvent& aEvent);
160
161         /**
162         * Zoom in the functions
163         */
164         void onMyZoomIn(wxCommandEvent& aEvent);
165
166         /**
167         * Transform the point clicked  from window
168         * to the real value,given by the scale
169         */
170         wxPoint getRealPoint(wxPoint pixelPoint);         
171
172         /**
173         * The user doesnt want see the points of the function
174         */
175         void onNoShowPoints(wxCommandEvent& aEvent);
176
177         /**
178         Stop the drawing of the actual function
179         */
180         void onStopDrawing(wxCommandEvent& aEvent);
181
182         /**
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
185         *
186         */
187         void onAddNewPoint(wxCommandEvent& aEvent);
188
189         /**
190         * Let to the user to start drawing
191         */
192         void onStartDrawing(wxCommandEvent& aEvent);
193
194         /**
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.
196         */
197         void onMouseMove(wxMouseEvent& event);
198
199         /**
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
203         */
204         void onChangeActual(wxMouseEvent& event);
205
206         /**
207         * Add a new point to the function and then repaint
208         */
209         void onAddPoint(wxMouseEvent& aEvent);
210
211         /**
212         * Deletes a point of the function and then repaint
213         */
214         void onDeletePoint(wxCommandEvent& aEvent);
215
216         /**
217         * Shows graphicly the discrete points that the function has
218         */
219         void onShowPoints(wxCommandEvent& aEvent);
220
221         /**
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.
223         * IS NOT IMPLEMENTED
224         */
225         void changeFuntionType(int aTheType, bool aForAll);
226
227         /**
228         * Add a function to the plotter
229         * when the function doesnt come from window
230         */
231         int addFunction(pGraphicalFunction * function);
232
233         /**
234         *  Delete a point of a function
235         *  @param point: is the real value that the functon takes, and is gointg to be deleted  
236         */
237         bool DeletePointFunction(pGraphicalFunction* function,wxPoint point);
238
239         /**
240         * Delete a function of the plotter
241         */
242         bool deleteFunction(pGraphicalFunction * f);
243         /**
244         *  Sets the actual function
245         *  @param newActual: new function
246         */
247         void  setActualFunction(pGraphicalFunction* newActual);
248         /**
249         *  Get the actual function
250         */
251         pGraphicalFunction* getActualFunction();
252
253         /**
254         * Creates and returns a graphical funcion according to the indicated vectors.
255         */
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 );
259
260         /*
261          Set the scales according to the size of the window
262          and the maximum given by the user
263         */
264
265         void setActualScales();
266         
267         
268
269         //erase
270
271         void setmLog(wxTextCtrl *m_log1)
272         {
273                 m_log=m_log1;
274         }
275
276         /*
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
280         */
281         void actualizeViewRange(int newMinX, int newMaxX);
282
283                 /*
284         * Sets the condition for drawing or not the guide lines
285         * @param ifDrawing The new condition to assing 
286         */
287         void setLineGuidesCondition(bool ifDrawing)
288         {               
289                 drawGuides = ifDrawing;         
290         }
291
292         
293         /*
294         * Gets the condition for drawing or not the guide lines
295         * @retval drawGuides The assigned condition
296         */
297         bool drawGuideLines()
298         {
299                 return drawGuides;
300         }       
301         /*
302         * Guide lines menu handler method that reacts to the mpID_LINE_GUIDES cimmand event
303         * event The corresponding event to handle
304         */
305         void OnGuideLines (wxCommandEvent   &event); 
306
307         /*
308          writes in  t information
309         */
310         void writeInText(wxString &t)
311         {
312                 t=text;
313         }
314         
315         /*
316          Get a function in the plotter given the index
317         */
318         pGraphicalFunction* getFunction(int index);
319         
320         /*
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
327
328         */
329         void moveFunctions(float porcentageMinX,float porcentageMaxX);
330 /**
331         * Add a function to the plotter
332         * when the function doesnt come from window
333         */
334         int addFunctionToMove(pGraphicalFunction * function);
335
336         
337 private:
338
339         /**
340         * Actual Function
341         */
342         pGraphicalFunction* actual;
343         /**
344         * layers
345         */
346         wxList functions;
347
348         /**
349         * If is drawing the function
350         */
351         bool drawing;
352         /**
353         * Index of the movig point, if the user is moving
354         * a poit
355         */
356         int movingPointIndex;
357
358         /**
359         * the way we scale
360          DEFAULT_SCALE 1
361          MAX_SCALE 2
362          USER_SCALE 3
363         */
364         int scaleWay;
365
366         
367         /*
368                 Use to Show Information
369         */
370
371         wxTextCtrl      *m_log;
372         wxString                text;
373
374         /*
375           Functions to be move at the same time
376         */
377         wxList functionsToMove;
378         /*
379          the user is moving the function
380         */
381         bool movingFunction;
382         /*
383         */
384         int initialMovingCLick;
385
386         /*
387                 saving the initial function
388         */
389         std::vector<double> backUpActualVector;
390         /*
391         wants to move the points of the function
392         */
393         bool movingPoints;
394
395         DECLARE_CLASS (pPlotterWindow)
396         //----------------------------------------------------------------------------
397         // wxWidget macro use declaration for handdling events
398         //----------------------------------------------------------------------------
399         DECLARE_EVENT_TABLE()
400 };
401
402 #endif
403
404