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