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