]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pColorBar.cxx
#2490 creaMaracasVisu Feature New High - Histogram Interaction
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pColorBar.cxx
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 // Class definition include
28 //------------------------------------------------------------------------------------------------------------
29 #include "pColorBar.h"
30 #include <math.h>
31
32 //------------------------------------------------------------------------------------------------------------
33 // Generated events declaration and definition
34 //------------------------------------------------------------------------------------------------------------
35 /*
36 * How to catch generated event: EVT_COMMAND(ID_CONTAINER_WINDOW_LISTENER, wxEVT_TYPE_EVENT, ContainerClass :: determinedEventFor)
37 */
38 BEGIN_DECLARE_EVENT_TYPES()
39         DECLARE_EVENT_TYPE( wxEVT_ADDED_POINT, -1 )
40         DECLARE_EVENT_TYPE( wxEVT_REMOVED_POINT, -1 )
41         DECLARE_EVENT_TYPE( wxEVT_MOVED_POINT, -1 )
42         DECLARE_EVENT_TYPE( wxEVT_CHANGED_POINT, -1 )
43         DECLARE_EVENT_TYPE( wxEVT_ON_COLOR_BAR, -1 )
44 END_DECLARE_EVENT_TYPES()
45
46
47 DEFINE_EVENT_TYPE( wxEVT_ADDED_POINT )
48 DEFINE_EVENT_TYPE( wxEVT_REMOVED_POINT )
49 DEFINE_EVENT_TYPE( wxEVT_MOVED_POINT )
50 DEFINE_EVENT_TYPE( wxEVT_CHANGED_POINT )
51 DEFINE_EVENT_TYPE( wxEVT_ON_COLOR_BAR )
52
53 //------------------------------------------------------------------------------------------------------------
54 // Class implementation
55 //------------------------------------------------------------------------------------------------------------
56 /** file pColorBar.cxx */
57 IMPLEMENT_CLASS(pColorBar, wxScrolledWindow)
58
59 //------------------------------------------------------------------------------------------------------------
60 // Handled events table
61 //------------------------------------------------------------------------------------------------------------
62 BEGIN_EVENT_TABLE(pColorBar, wxScrolledWindow)
63         EVT_PAINT( pColorBar :: onPaint)
64         EVT_SIZE ( pColorBar :: OnSize )
65         EVT_MOTION ( pColorBar :: onMouseMove)
66         EVT_RIGHT_DOWN( pColorBar :: onShowPopupMenu)
67         EVT_LEFT_DCLICK( pColorBar :: onLeftButtonDClick)
68         EVT_LEFT_DOWN( pColorBar :: onLeftClicDown)
69         EVT_LEFT_UP( pColorBar :: onLeftClickUp)
70         EVT_MENU( cntID_DEL_COLOR_POINT, pColorBar :: onDeleteColorPoint)
71         EVT_MENU( cntID_ADD_COLOR_POINT, pColorBar :: onAddColorPoint)
72         EVT_MENU( cntID_CHANGE_COLOR_POINT, pColorBar :: onChangeColourSelectedPoint)
73         EVT_MENU( cntID_TRIANGLES_UP, pColorBar :: onTrianglesUp_Figure)
74         EVT_MENU( cntID_TRIANGLES_DOWN, pColorBar :: onTrianglesDown_Figure)
75         EVT_MENU( cntID_TRIANGLES_LEFT, pColorBar :: onTrianglesLeft_Figure)
76         EVT_MENU( cntID_TRIANGLES_RIGHT, pColorBar :: onTrianglesRight_Figure)
77         EVT_MENU( cntID_RECTANGLES, pColorBar :: onRectangles_Figure)
78         EVT_MENU( cntID_DEGRADE_CONTROL, pColorBar :: onDegradeControl)
79         EVT_MIDDLE_UP( pColorBar :: onShowPopupMenu )
80         EVT_RIGHT_UP ( pColorBar :: onShowPopupMenu )
81 END_EVENT_TABLE()
82
83 //------------------------------------------------------------------------------------------------------------
84 // Constructors & Destructors
85 //------------------------------------------------------------------------------------------------------------
86
87 /*
88 * Creates a colorBar instance 
89 * param *parent Container event listener window
90 * param _w Width of the color bar drawing area
91 * param _h Height of the color bar drawing area
92 * param _bar_orientation VERTICAL (false) or HORIZONTAL (true) direction to set 
93 */
94 pColorBar :: pColorBar (wxWindow *parent, int _w, int _h, bool _bar_orientation)
95 :wxScrolledWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
96 {
97                 _logicalBar = new LogicalColorBar();
98                 colourParent =  GetParent()->GetBackgroundColour();
99                 deviceEndMargin = 0;
100                 acceptedClick = true;
101                 setGapValues (0,6);
102                 setWidth(_w);
103                 setHeight(_h);
104                 
105                 // Setting the default represented values 
106                 setDegradeState(true);  
107                 setStaticLimitsTo(false);
108                 viewingRange = false;
109                 accumTemporalPoints = 0;
110                 deviceEndMargin = 0;
111                 activeState = false;
112                 avaliablePointToMove = -1;
113                                                 
114                 movingPointIndex = -1;
115                 movingNodePoint = NULL;
116                 realX_vertical_line = -1;
117                 guideLineColor          =   wxColour(255,0,0);
118
119                 //TRIANGLES UP
120                 figure = new pFigure( RECTANGLE, FIGURE_WIDTH, bar_height, -2, _bar_orientation );
121                 setOrientation ( _bar_orientation );
122                 
123                 // Appending menu items to the pop-menu
124                 c_popmenu.Append( cntID_ADD_COLOR_POINT, _T("Add color point"), _T("Adds a color point in the clicked point"));
125                 c_popmenu.Append( cntID_DEL_COLOR_POINT, _T("Delete color point"), _T("Deletes the color point at the clicked point"));
126                 c_popmenu.Append( cntID_CHANGE_COLOR_POINT, _T("Change color"), _T("Changes the color at the clicked point"));
127                 c_popmenu.Append ( cntID_DEGRADE_CONTROL, _T("Turn off degrade"), _T("Turns on/off the degrade"),wxITEM_SEPARATOR);
128                 
129                 changesMenu = new wxMenu;
130                 changesMenu->AppendCheckItem ( cntID_TRIANGLES_UP, _T("Triangles up"),_T("Sets triangles up figure"));
131                 changesMenu->AppendCheckItem ( cntID_TRIANGLES_DOWN, _T("Triangles down"),_T("Sets triangles down figure"));
132                 changesMenu->AppendCheckItem ( cntID_TRIANGLES_LEFT, _T("Triangles left"),_T("Sets triangles left figure"));
133                 changesMenu->AppendCheckItem ( cntID_TRIANGLES_RIGHT, _T("Triangles right"),_T("Sets triangles right figure"));
134                 changesMenu->AppendCheckItem ( cntID_RECTANGLES, _T("Rectangles"),_T("Sets rectangle figure"));
135                 c_popmenu.Append(cntID_CHANGE_FIGURE, _T("Change figure"),changesMenu, _T("Changes the figure of the color points"));
136                 changesMenu->Check (cntID_TRIANGLES_UP, true);
137 }
138
139 pColorBar :: ~pColorBar()
140 {
141
142 }
143         //------------------------------------------------------------------------------------------------------------
144         // Color bar proccessed events methods implementation
145         //------------------------------------------------------------------------------------------------------------
146         
147         void pColorBar :: OnSize ( wxSizeEvent &WXUNUSED(event) )
148         {
149                 wxRect rectTotal = GetClientRect();                     
150                 if(getOrientation())
151                 {               
152                         setWidth( rectTotal.GetWidth() - deviceEndMargin );                     
153                 } 
154                 else 
155                 {
156                         setWidth( rectTotal.GetHeight() - deviceEndMargin);                             
157                 }
158                 Refresh();
159         }
160         /**
161         * Reacts to the mouse movement inside the color bar for moving the clicked color point in the x-axis.
162         * Informs the result of the handled event like a wxCommandEvent wxEVT_MOVED_COL_POINT if a point was moved.
163         * param event The mouse actioned event
164         */
165         void pColorBar ::  onMouseMove ( wxMouseEvent& event )
166         {       
167                 if(!event.LeftIsDown())
168                         avaliablePointToMove = -1;
169
170                 if (acceptedClick && activeState && _logicalBar->getCount()>0)
171                 {
172                         bool movedPoint = false;
173                         wxPoint point = event.GetPosition();
174                         double realClicked = getOrientation() ? convertToRealValue(point.x) : convertToRealValue(point.y);
175                         bool rangeToMove = realClicked<=maxX_represented_Tshow && realClicked>=minX_represented_Tshow;//getOrientation() ? (point.x >=deviceStart_x && point.x<=bar_width+deviceStart_x-deviceEndMargin ) : ( point.y>=deviceStart_y && point.y<=bar_width+deviceStart_x-deviceEndMargin);
176                         if ( rangeToMove && acceptedClick && showedColorPoints.size()>0 )
177                         {       
178                                 if ( movingPointIndex == -1 )
179                                 {
180                                         startNode_show = showedColorPoints.front();
181                                         lastNode_show = showedColorPoints.back();
182                                                                         
183                                         //int numberEdges = figure->getNumberEdges(); // JPRx
184                                         //wxPoint points [4]; // JPRx
185                                         //int i=0; // JPRx
186                                         int a;
187                                         for (a=0; a<showedColorPoints.size() && movingPointIndex==-1 ; a++ )
188                                         {
189                                                 pColorPoint * nodePoint = showedColorPoints[a];
190                                                 int point_pixelX = convertToPixelValue(nodePoint -> getRealX());
191                                                 point_pixelX+= deviceStart_x;
192                                                 if ( getOrientation() )
193                                                         movingPointIndex  =  (figure ->isPointInside (point_pixelX,point.x))? a : -1;
194                                                 else
195                                                         movingPointIndex  =  (figure ->isPointInside (point_pixelX,point.y))? a : -1;
196
197                                                 if(movingPointIndex != -1)
198                                                 {
199                                                         movingNodePoint = nodePoint;            
200                                                         if(avaliablePointToMove ==-1)
201                                                                 avaliablePointToMove = movingPointIndex;
202                                                 }                                                                                               
203                                         }                                               
204                                 }
205                                 if (event.LeftIsDown() && movingNodePoint && movingPointIndex!=-1 && avaliablePointToMove==movingPointIndex)
206                                 {                                       
207                                         bool hasPrevPoint = movingPointIndex > 0;
208                                         bool hasNextPoint = movingPointIndex < showedColorPoints.size()-1;
209
210                                         pColorPoint * prevPoint = hasPrevPoint? showedColorPoints[movingPointIndex-1]: NULL; 
211                                         pColorPoint * nextPoint = hasNextPoint ? showedColorPoints[movingPointIndex+1]: NULL;
212
213                                         if ( hasPrevPoint && prevPoint!=NULL )
214                                         {                                                       
215                                                 if ( hasNextPoint && nextPoint!=NULL )
216                                                 {                                                               
217                                                         double previousValue = prevPoint->getRealX();
218                                                         double nextValue = nextPoint->getRealX();
219                                                         movedPoint = prevPoint->isTemporalColor() ? 
220                                                                 ( nextPoint->isTemporalColor() ? (realClicked>=previousValue)&&(realClicked<=nextValue) : (realClicked>=previousValue)&&(realClicked<nextValue))
221                                                                 :(realClicked>previousValue)&&(realClicked<nextValue);  
222                                                         if(!movedPoint)
223                                                                 avaliablePointToMove = movingPointIndex;
224                                                         if(!movedPoint && realClicked<previousValue) 
225                                                         {
226                                                                 realClicked = previousValue+1;
227                                                                 movedPoint = true;
228                                                         }
229                                                         else if(!movedPoint && realClicked>nextValue) 
230                                                         {
231                                                                 realClicked = nextValue-1;
232                                                                 movedPoint = true;
233                                                         }                                                                                                               
234                                                 }
235                                                 else 
236                                                 {
237                                                         if ( !staticLimits )
238                                                         {
239                                                                 // Is the last point
240                                                                 double previousValue = prevPoint->getRealX();
241                                                                 movedPoint = prevPoint->isTemporalColor() ? 
242                                                                         ( realClicked>=previousValue ) && ( realClicked<= maxX_represented_Tshow ) 
243                                                                         : ( realClicked>previousValue ) && ( realClicked<= maxX_represented_Tshow );
244                                                                 if(!movedPoint)
245                                                                         avaliablePointToMove = movingPointIndex;
246                                                                 if(!movedPoint && realClicked<previousValue)
247                                                                 {
248                                                                         realClicked = prevPoint->isTemporalColor()? previousValue: previousValue+1;
249                                                                         movedPoint = true;
250                                                                 }                                                               
251                                                                 else if (!movedPoint && realClicked>=maxX_represented_Tshow) 
252                                                                 {
253                                                                         realClicked = maxX_represented_Tshow;
254                                                                         movedPoint = true;
255                                                                 }                                                               
256                                                         }
257                                                 }
258                                         }
259                                         else
260                                         {
261                                                 if ( hasNextPoint && nextPoint!=NULL )
262                                                 {
263                                                         if ( !staticLimits )
264                                                         {
265                                                                 // Is the first point                                                           
266                                                                 double nextValue = nextPoint->getRealX();
267                                                                 movedPoint = ( nextPoint->isTemporalColor() ? (realClicked<=nextValue) && ( realClicked>= minX_represented_Tshow )
268                                                                         :( realClicked<nextValue ) && ( realClicked>= minX_represented_Tshow ));                                                                                
269                                                                         
270                                                                 if(!movedPoint)
271                                                                         avaliablePointToMove = movingPointIndex;
272                                                                 if(!movedPoint && realClicked>nextValue) 
273                                                                 {
274                                                                         realClicked = nextPoint->isTemporalColor() ? nextValue : nextValue-1;
275                                                                         movedPoint = true;
276                                                                 }       
277                                                                 else if (!movedPoint && realClicked<=minX_represented_Tshow) 
278                                                                 {
279                                                                         realClicked = minX_represented_Tshow;
280                                                                         movedPoint = true;
281                                                                 }                                                               
282                                                         }
283                                                 }
284                                                 else
285                                                 {
286                                                         //Is the only point in the color bar
287                                                         movedPoint = ( realClicked<= maxX_represented_Tshow ) && ( realClicked>= minX_represented_Tshow );      
288                                                         if(!movedPoint)
289                                                                         avaliablePointToMove = movingPointIndex;
290                                                         if (!movedPoint && realClicked<=minX_represented_Tshow) 
291                                                         {
292                                                                 realClicked = minX_represented_Tshow;
293                                                                 movedPoint = true;
294                                                         }
295                                                         else if(!movedPoint && realClicked>=maxX_represented_Tshow) 
296                                                         {
297                                                                 realClicked = maxX_represented_Tshow;
298                                                                 movedPoint = true;
299                                                         }
300                                                 }
301                                         }
302                                         if(viewingRange)
303                                         {  
304                                                 bool movingTempStart = movingNodePoint->getRealX() == startNode_show->getRealX() && movingNodePoint->isTemporalColor();
305                                                 bool movingTempEnd = movingNodePoint->getRealX()== lastNode_show->getRealX() && movingNodePoint->isTemporalColor();
306                                                 if( movingTempStart || movingTempEnd )
307                                                         movedPoint = false;
308                                         }
309                                 }       
310                                         // Inform movedPoint event
311                                 if ( movedPoint )
312                                 {                                       
313                                         movingNodePoint->setRealX ( realClicked );
314                                         RefreshForce();//Refresh to show the point is moved
315                                         createAndSendEvent(wxEVT_MOVED_POINT);                                          
316                                 }
317                                 else
318                                 {
319                                         movingPointIndex = -1;                                          
320                                         //Creating a general event of mouse move to actualize views
321                                         createAndSendEvent( wxEVT_ON_COLOR_BAR );
322                                 }                       
323                         }
324                         else
325                         {
326                                 movingPointIndex = -1;  
327                                 //Creating a general event of mouse move to actualize views
328                                 createAndSendEvent( wxEVT_ON_COLOR_BAR );
329                         }                       
330                         if ( movingPointIndex ==-1 )
331                         {
332                                 RefreshForce();//Refresh to show the point is not selected anymore              
333                         }
334                 }               
335         }
336
337         void pColorBar ::  Refresh(bool eraseBackground , const wxRect* rect )
338         {
339                 wxScrolledWindow::Refresh(false);
340         }
341
342
343         /*
344         * Reacts to the event of drawing the bar and draws it
345         * param &WXUNUSED(event) The correspondig wxPaintEvent actioned event
346         */
347         void pColorBar ::  onPaint ( wxPaintEvent &WXUNUSED(event) )
348         {
349                 repaintView();
350                 if ( getOrientation() ) // HORIZONTAL
351                 {
352                         wxMemoryDC temp_dc;
353                         temp_dc.SelectObject( * colorBar_Bitmap );
354                         wxPaintDC dc( this );
355                                         
356 //                      dc.Blit(deviceStart_x, deviceStart_y, bar_width+deviceStart_x, bar_height+deviceStart_y, &temp_dc, deviceStart_x, deviceStart_y);
357
358                         dc.Blit(deviceStart_x, deviceStart_y, bar_width/*-deviceEndMargin*/, bar_height, &temp_dc, 0, 0);
359
360                         // Bitmap for posible needed information to be shown
361                         /*
362                         temp_dc.SelectObject( * information_Bitmap );
363                         dc.Blit(0,bar_height, width, height, &temp_dc, 0, height);
364                         */
365                 }
366                 else
367                 {
368                         wxMemoryDC temp_dc;
369                         temp_dc.SelectObject( * colorBar_Bitmap );
370                         wxPaintDC dc( this );
371 //                      dc.Blit(deviceStart_y,deviceStart_x, bar_height+deviceStart_y, bar_width+deviceStart_x, &temp_dc, deviceStart_y, deviceStart_x);        
372                         
373                         dc.Blit(deviceStart_y,deviceStart_x, bar_height, bar_width-deviceEndMargin, &temp_dc, 0, 0);                            
374                         // Bitmap for posible needed information to be shown
375                         /*
376                         temp_dc.SelectObject( * information_Bitmap );
377                         dc.Blit(0,bar_width, height, width, &temp_dc, 0, width );
378                         */
379                         temp_dc.SelectObject(wxNullBitmap);
380                 }
381         }
382
383         /**
384         * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
385         * Informs the result of the handled event like a wxCommandEvent wxEVT_ADDED_COL_POINT if the point was inserted succesfully.
386         * param & anEvent The wxCommandEvent actioned event 
387         */
388         void pColorBar ::  onAddColorPoint ( wxCommandEvent& anEvent )
389         {
390                 bool addedPoint = false;
391                 double real_x = getOrientation() ? convertToRealValue( clickedX ) : convertToRealValue( clickedY );
392                 wxColour selectedColor = getSelectedColour();
393                 if (okSelectedColor)
394                 {
395                         addedPoint = addColorPoint (real_x, selectedColor);                     
396                 }
397                 // Inform addedPoint event
398                 if ( addedPoint )
399                 {
400                         //RefreshForce();
401                         createAndSendEvent( wxEVT_ADDED_POINT );                        
402                 }
403         }
404
405         /**
406         * Reacts to the cntID_DEL_COLOR_POINT wxCommandEvent and deletes a color degrade point of the color bar.
407         * Informs the result of the handled event like a wxCommandEvent wxEVT_REMOVED_COL_POINT if the point was succesfully removed.
408         * param & anEvent The wxCommandEvent actioned event 
409         */
410         void pColorBar :: onDeleteColorPoint ( wxCommandEvent& anEvent )
411         {
412                 bool            deletedPoint            = false;
413                 double  real_x                          = getOrientation() ? convertToRealValue( clickedX ) : convertToRealValue( clickedY );
414                                         deletedPoint            = deleteColorPoint(real_x);
415                 // Inform deletedPoint event
416                 if ( deletedPoint )
417                 {
418                         //RefreshForce();
419                         createAndSendEvent( wxEVT_REMOVED_POINT );                      
420                 } //if
421         }
422
423                 /**
424         * Reacts to the cntID_CHANGE_COLOR_POINT wxCommandEvent and changes the assigned color to the selected color degrade point of the color bar.
425         * Informs the result of the handled event like a wxCommandEvent wxEVT_CHANGED_POINT if the point was succesfully removed.
426         * param & anEvent The wxCommandEvent actioned event 
427         */
428         void pColorBar :: onChangeColourSelectedPoint ( wxCommandEvent& anEvent )
429         {
430                 bool changedColour = false;
431                 changedColour = getOrientation() ? changeColor( clickedX ) : changeColor( clickedY );
432                 // Inform deletedPoint event
433                 if ( changedColour )
434                 {
435                         //RefreshForce();
436                         createAndSendEvent( wxEVT_CHANGED_POINT );                      
437                 } // if
438         }
439
440
441         /**
442         * Reacts to the cntID_TRIANGLES_UP wxCommandEvent and changes the assigned figure to -triangles up- for the color points of the color bar.
443         * param & anEvent The wxCommandEvent actioned event 
444         */
445         void pColorBar :: onTrianglesUp_Figure ( wxCommandEvent& anEvent  )
446         {
447                 if( !changesMenu->IsChecked(cntID_TRIANGLES_UP) )
448                 {
449                         changeFigure (-8);
450                         changesMenu->Check (cntID_TRIANGLES_UP, true);
451                         changesMenu->Check (cntID_TRIANGLES_DOWN, false);
452                         changesMenu->Check (cntID_TRIANGLES_LEFT, false);
453                         changesMenu->Check (cntID_TRIANGLES_RIGHT, false);
454                         changesMenu->Check (cntID_RECTANGLES, false);
455                 }
456         }
457         /**
458         * Reacts to the cntID_TRIANGLES_DOWN wxCommandEvent and changes the assigned figure to -triangles down- for the color points of the color bar.
459         * param & anEvent The wxCommandEvent actioned event 
460         */
461         void pColorBar :: onTrianglesDown_Figure ( wxCommandEvent& anEvent  )
462         {
463                 if( !changesMenu->IsChecked(cntID_TRIANGLES_DOWN) )
464                 {
465                         changeFigure (-2);
466                         changesMenu->Check (cntID_TRIANGLES_UP, false);
467                         changesMenu->Check (cntID_TRIANGLES_DOWN, true);
468                         changesMenu->Check (cntID_TRIANGLES_LEFT, false);
469                         changesMenu->Check (cntID_TRIANGLES_RIGHT, false);
470                         changesMenu->Check (cntID_RECTANGLES, false);
471                 }
472         }
473         /**
474         * Reacts to the cntID_TRIANGLES_LEFT wxCommandEvent and changes the assigned figure to -triangles left- for the color points of the color bar.
475         * param & anEvent The wxCommandEvent actioned event 
476         */
477         void pColorBar :: onTrianglesLeft_Figure ( wxCommandEvent& anEvent  )
478         {
479                 if( !changesMenu->IsChecked(cntID_TRIANGLES_LEFT) )
480                 {
481                         changeFigure (-4);
482                         changesMenu->Check (cntID_TRIANGLES_UP, false);
483                         changesMenu->Check (cntID_TRIANGLES_DOWN, false);
484                         changesMenu->Check (cntID_TRIANGLES_LEFT, true);
485                         changesMenu->Check (cntID_TRIANGLES_RIGHT, false);
486                         changesMenu->Check (cntID_RECTANGLES, false);
487                 }
488         }
489         /**
490         * Reacts to the cntID_TRIANGLES_RIGHT wxCommandEvent and changes the assigned figure to -triangles right- for the color points of the color bar.
491         * param & anEvent The wxCommandEvent actioned event 
492         */
493         void pColorBar :: onTrianglesRight_Figure ( wxCommandEvent& anEvent  )
494         {
495                 if( !changesMenu->IsChecked(cntID_TRIANGLES_RIGHT) )
496                 {
497                         changeFigure (-6);
498                         changesMenu->Check (cntID_TRIANGLES_UP, false);
499                         changesMenu->Check (cntID_TRIANGLES_DOWN, false);
500                         changesMenu->Check (cntID_TRIANGLES_LEFT, false);
501                         changesMenu->Check (cntID_TRIANGLES_RIGHT, true);
502                         changesMenu->Check (cntID_RECTANGLES, false);
503                 }
504         }
505         /**
506         * Reacts to the cntID_RECTANGLES wxCommandEvent and changes the assigned figure to -rectangles- for the color points of the color bar.
507         * param & anEvent The wxCommandEvent actioned event 
508         */
509         void pColorBar :: onRectangles_Figure ( wxCommandEvent& anEvent  )
510         {
511                 if( !changesMenu->IsChecked(cntID_TRIANGLES_RIGHT) )
512                 {
513                         changeFigure (RECTANGLE);// RECTANGLE = 4
514                         changesMenu->Check (cntID_TRIANGLES_UP, false);
515                         changesMenu->Check (cntID_TRIANGLES_DOWN, false);
516                         changesMenu->Check (cntID_TRIANGLES_LEFT, false);
517                         changesMenu->Check (cntID_TRIANGLES_RIGHT, false);
518                         changesMenu->Check (cntID_RECTANGLES, true);
519                 }
520         }
521
522         /**
523         * Reacts to the cntID_DEGRADE_CONTROL wxCommandEvent and turns on/off the degrade in the color bar.
524         * param & anEvent The wxCommandEvent actioned event 
525         */
526         void pColorBar ::  onDegradeControl ( wxCommandEvent& anEvent )
527         {
528                 bool degrade = getDegradeState();
529                 wxString nextAction_text;
530                 if(degrade)
531                 {
532                         nextAction_text = _T("Turn on degrade");        
533                         setDegradeState (false);
534                 }
535                 else
536                 {
537                         nextAction_text = _T("Turn off degrade");
538                         setDegradeState (true);
539                 }
540                 c_popmenu.SetLabel ( cntID_DEGRADE_CONTROL, nextAction_text ); 
541         }
542
543         /**
544         * Reacts to the wxEVT_RIGHT_DCLICK wxMouseEvent and adds a color degrade point to the color bar.
545         * Informs the result of the handled event like a wxCommandEvent wxEVT_ADDED_COL_POINT if the point was succesfully inserted.
546         * param & event The wxMouseEvent actioned event 
547         */
548         void pColorBar ::  onLeftButtonDClick (wxMouseEvent& event)
549         {
550                 if (activeState)
551                 {
552                         bool addedPoint = false;
553                         wxPoint point = event.GetPosition();
554                         bool posiblePoint = false;
555                         if( getOrientation() )
556                         {
557                                 posiblePoint = point.x>=deviceStart_x && point.y<= (bar_height + deviceStart_y);
558                         }
559                         else
560                         {
561                                 posiblePoint = point.x>=deviceStart_y && point.x<= (bar_height+deviceStart_y) && point.y>deviceStart_x;
562                         }
563
564                         if (posiblePoint)
565                         {
566                                 double real_x = getOrientation() ? convertToRealValue( point.x ) : convertToRealValue( point.y );
567                                 wxColour selectedColor = getSelectedColour();
568                                 if (okSelectedColor)
569                                 {
570                                         addedPoint = addColorPoint (real_x, selectedColor);                                     
571                                 }
572                                 // Inform addedPoint event
573                                 if ( addedPoint )
574                                 {
575                                         //RefreshForce(); Is all ready refreshed on the adition of the point method
576                                         createAndSendEvent( wxEVT_ADDED_POINT );                        
577                                 }
578                         }
579                 }
580         }
581                 
582         void  pColorBar ::onLeftClicDown(wxMouseEvent& event )
583         {
584                 acceptedClick = true;           
585         }
586
587         void  pColorBar ::onLeftClickUp(wxMouseEvent& event )
588         {       
589                 movingPointIndex = -1;
590                 acceptedClick = false;
591         }
592         /*
593         * Shows the popup menu 
594         */
595         void pColorBar ::  onShowPopupMenu (wxMouseEvent &event)
596         {
597                 if (activeState)
598                 {
599                         if(showedColorPoints.empty())
600                         {
601                                 c_popmenu.Enable(cntID_DEL_COLOR_POINT, false);                 
602                         }
603                         else
604                         {
605                                 c_popmenu.Enable(cntID_DEL_COLOR_POINT, true);
606                         }
607                         bool setClickedValues = false;
608                         if( getOrientation() )
609                         {
610                                 setClickedValues = event.GetX()>=deviceStart_x && event.GetY()<= (bar_height + deviceStart_y);
611                         }
612                         else
613                         {
614                                 setClickedValues = event.GetX()>=deviceStart_y && event.GetX()<= (bar_height+deviceStart_y) && event.GetY()>deviceStart_x;
615                         }
616                         if (setClickedValues)
617                         {
618                                 setClickedX ( event.GetX() );
619                                 setClickedY ( event.GetY() );
620                                 RefreshForce();
621                                 PopupMenu( &c_popmenu, event.GetX(), event.GetY());
622                         }
623                 }
624         }
625         //------------------------------------------------------------------------------------------------------------
626         // Other methods implementation
627         //------------------------------------------------------------------------------------------------------------
628
629         /*
630         * Method that reinitiates attributes of the color bar to the given points
631         * param minRealValue The minimum represented value (real value)
632         * param maxRealValue The maximum represented value (real value)
633         */
634         void pColorBar :: reinitiateColorBar(double minRealValue, double maxRealValue)
635         {
636
637                 _logicalBar -> clearPoints();
638                 showedColorPoints.clear();
639                                 
640                 movingPointIndex = -1;
641                 realX_vertical_line = -1;
642                 activeState = true;
643                 accumTemporalPoints = 0;
644                 viewingRange = false;
645                 setDegradeState(true);                  
646                 setRepresentedValues(minRealValue, maxRealValue);
647         }
648
649         /*
650         * Method that reinitiates  attributes of the color bar and set the points given by parameter
651         * param pointsVector The the vector of the new points, the color points must have at least two points.
652         */
653         void pColorBar :: reinitiateColorBarTo (std::vector<pColorPoint *> pointsVector)
654         {
655                 _logicalBar -> clearPoints();
656                 _logicalBar -> setColorPoints(pointsVector);
657                 showedColorPoints.clear();
658                 
659                 movingPointIndex = -1;
660                 realX_vertical_line = -1;
661                 activeState = true;
662                 accumTemporalPoints = 0;                
663                 viewingRange = false;
664                 setDegradeState(true);                                  
665                 
666                 double minRealValue = _logicalBar -> getMinValue();
667                 double maxRealvalue = _logicalBar -> getMaxValue();
668
669                 setRepresentedValues(minRealValue, maxRealvalue);
670         }
671
672         /*
673         * Method that sets a copy of the points of the color bar to the given pointer parameter
674         * param pointsList The list for getting the points
675         */
676         void pColorBar :: getPointsListWithTemps (std::vector<pColorPoint*> &pointsVector)
677         {               
678                 pColorPoint* cPoint;
679                 for (int a =0; a<showedColorPoints.size() ; a++)        
680                 {
681                         cPoint = showedColorPoints[a];
682                         pColorPoint* copyPoint = new pColorPoint(cPoint->getRealX(), cPoint->getColor( ), (cPoint->isTemporalColor()));
683                         pointsVector.push_back(copyPoint);                      
684                 }
685         }
686
687         /*
688         * Method that sets a copy of the points of the color bar to the given pointer parameter, and sets the default values to the needeed attributes, it doesn't
689         * includes the teporal points created
690         * param pointsList The list for getting the points
691         */
692         
693         void pColorBar :: getAddedColorsPointsList (std::vector<pColorPoint*> &pointsVector)
694         {
695                 pColorPoint* cPoint;
696                 for (int a =0; a<_logicalBar->getCount(); a++)  
697                 {
698                         cPoint = _logicalBar ->getPointAtIndex(a);                      
699                         pColorPoint* copyPoint = new pColorPoint(cPoint->getRealX(), cPoint->getColor( ), (cPoint->isTemporalColor()));
700                         pointsVector.push_back(copyPoint);                      
701                 }
702         }
703         
704
705         /**
706         * Adds a color degrade point to the color bar.
707         * param xRealValue The real xValue of the point
708         * param theColour The assigned color for the point
709         * param temporalStart Indicates if the inserted point is the temporal startShowing point
710         * param temporalEnd Indicates if the inserted point is the temporal startShowing point
711         * return Returns true if the point was succesfully inserted.
712         */
713         bool pColorBar :: addColorPoint (double xRealValue, wxColour theColour/*, bool temporalStart, bool temporalEnd*/)
714         {
715                 bool addedPoint = false;
716                 addedPoint = _logicalBar->addColorPoint(xRealValue,theColour);
717                 if (addedPoint) 
718                         RefreshForce();
719                 return addedPoint;
720         }
721
722
723         /**
724         * Delets a color degrade point to the color bar.
725         * param xRealValue The real xValue of the point to delete       
726         * return Returns true if the point was succesfully inserted.
727         */
728         bool pColorBar :: deleteColorPoint (double xRealValue)
729         {       
730                 pColorPoint* actualPoint;               
731                 bool deletedPoint = false;
732                 for (int a =0; a<showedColorPoints.size() && !deletedPoint; a++)        
733                 {
734                         actualPoint = showedColorPoints[a];
735                         int actualX = (int)actualPoint -> getRealX();
736                         bool isInsideActual = figure -> isPointInside (convertToPixelValue(actualX), convertToPixelValue(xRealValue));
737                         if( actualX == xRealValue || isInsideActual)
738                         {
739                                 movingPointIndex=-1;                                                            
740                                 deletedPoint = _logicalBar->deleteColorPoint(actualPoint -> getRealX());                                        
741                         }                       
742                 }                       
743                 if (deletedPoint) 
744                         RefreshForce();
745                 return deletedPoint;                    
746         }
747
748         /**
749         * Changes the color degrade point color value.
750         * Informs the result of the handled event like a wxCommandEvent wxEVT_CHANGED_COLOR_POINT if the point changed its colour.
751         * param clickedValue The x-coord pixel value of the point to which the color change interests   
752         * return Returns true if the color point was succesfully updated.
753         */
754         bool pColorBar :: changeColor ( int clickedValue )
755         {               
756                 bool colourUpdated = false;
757                 double xRealValue = convertToRealValue( clickedValue );
758                 pColorPoint* actualPoint;
759                 for (int a =0; a<showedColorPoints.size() && !colourUpdated; a++)       
760                 {
761                         actualPoint = showedColorPoints[a];
762                         int actualX = (int)actualPoint -> getRealX();
763                         bool isInsideActual = figure -> isPointInside (convertToPixelValue(actualX), clickedValue);
764                         if( actualX == xRealValue || isInsideActual)
765                         {
766                                 wxColour newColour = getSelectedColour();
767                                 if (okSelectedColor)
768                                 {
769                                         actualPoint -> setColor(newColour);
770                                         colourUpdated = true;                                   
771                                 }                               
772                         }                       
773                 }               
774                 if(colourUpdated)
775                         RefreshForce();
776                 return colourUpdated;
777         }
778
779         /*
780         * Repaints the color bar in horizontal direction mode
781         */
782         void pColorBar ::  repaintView(  )
783         {
784                 wxMemoryDC temp_dc;
785                 temp_dc.SelectObject( * colorBar_Bitmap );              
786                 temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID  ));
787                 temp_dc.SetPen(wxPen( colourParent,1,wxSOLID  ));
788                 if (getOrientation())
789                 {
790                         temp_dc.DrawRectangle(0, 0, bar_width, bar_height);
791                         temp_dc.SetPen(wxPen( wxColour(167,165,191),1,wxSOLID  ));
792                         temp_dc.DrawRectangle(0, 0, bar_width-deviceEndMargin, bar_height);
793                 }
794                 else
795                 {
796                         temp_dc.DrawRectangle(0, 0, bar_height, bar_width);
797                         temp_dc.SetPen(wxPen( wxColour(167,165,191),1,wxSOLID  ));
798                         temp_dc.DrawRectangle(0, 0, bar_height, bar_width-deviceEndMargin);
799                 }
800                 //wxPoint figPoints[4]; // JPRx
801                 
802                 if( _logicalBar -> getCount() >0)
803                 {
804                         updatePointsToDraw();
805                         
806                         int numberEdges = figure->getNumberEdges();
807                         wxPoint points [4];
808                         figure->getVertexPoints(points);
809                         figure ->setVertexPoints (points);
810
811                         int maxValue = showedColorPoints.size();
812                         pColorPoint * iniPoint;
813                         pColorPoint * endPoint;
814                         wxColor intialColor, finalColor;
815                         for (int a=0; a<maxValue; a++)
816                         {
817                                 iniPoint = showedColorPoints[a];
818                                 int ini_pixelX = convertToPixelValue(iniPoint -> getRealX());                           
819                                 intialColor = iniPoint -> getColor();
820                                                                 
821                                 if( a<maxValue-1 )
822                                 {
823                                         if( doingDegrade )
824                                         {
825                                                 endPoint = showedColorPoints[a+1];
826                                                 int end_pixelX = convertToPixelValue(endPoint -> getRealX());
827                                                 finalColor = endPoint -> getColor();                                    
828                                         
829                                                 int rectangle_width = end_pixelX - ini_pixelX;
830                                                 
831                                                 //*************************************************************************************
832                                                 int initial_r = intialColor.Red();
833                                                 int final_r = finalColor.Red()  ;
834                                                 int initial_g = intialColor.Green();
835                                                 int final_g= finalColor.Green();
836                                                 int initial_b = intialColor.Blue();
837                                                 int final_b= finalColor.Blue();
838                                                 
839                                                 float m_scope_r = (float)(final_r-initial_r)/rectangle_width;
840                                                 float m_scope_g = (float)(final_g-initial_g)/rectangle_width;
841                                                 float m_scope_b = (float)(final_b-initial_b)/rectangle_width;                           
842
843                                                 int next_r = initial_r;
844                                                 int next_g = initial_g;
845                                                 int next_b = initial_b;
846
847                                                 float nxt_r = (float)next_r;
848                                                 float nxt_g = (float)next_g;
849                                                 float nxt_b = (float)next_b;
850
851                                                 for (int Xi =ini_pixelX; Xi<= end_pixelX; Xi++)                                         
852                                                 {
853                                                         temp_dc.SetBrush(wxBrush( wxColour(next_r, next_g, next_b),wxSOLID  ));
854                                                         temp_dc.SetPen(wxPen( wxColour(next_r, next_g, next_b),1,wxSOLID  ));
855                                                         if( getOrientation() )
856                                                                 temp_dc.DrawLine(Xi, 0, Xi, bar_height);
857                                                         else
858                                                                 temp_dc.DrawLine(0, Xi, bar_height, Xi);
859
860                                                         nxt_r = (m_scope_r + nxt_r);
861                                                         nxt_g = (m_scope_g + nxt_g);
862                                                         nxt_b = (m_scope_b + nxt_b);
863                                                         
864                                                         next_r = (int)(nxt_r);
865                                                         next_g = (int)(nxt_g);
866                                                         next_b = (int)(nxt_b);                                                          
867                                                 }                                                                       
868                                         }                               
869                                 }
870                                 if( movingPointIndex!=-1 && movingNodePoint!=NULL )
871                                 {                                       
872                                         if ( !(movingNodePoint -> isTemporalColor()) )
873                                         {
874                                                 if( movingNodePoint==iniPoint && movingPointIndex!=-1 )
875                                                 {
876                                                         temp_dc.SetBrush(wxBrush(  wxColour(5,36,180), wxSOLID  ));
877                                                         temp_dc.SetPen(wxPen( wxColour(239,239,239), 1, wxSOLID  ));
878                                                         if (getOrientation())
879                                                                 temp_dc.DrawPolygon(numberEdges, points, ini_pixelX, 0);
880                                                         else
881                                                                 temp_dc.DrawPolygon(numberEdges, points, 0, ini_pixelX);
882                                                 }
883                                                 else
884                                                 {                                               
885                                                                 temp_dc.SetBrush(wxBrush( intialColor, wxSOLID  ));     
886                                                                 if(iniPoint->isTemporalColor())
887                                                                         temp_dc.SetPen(wxPen( intialColor, 1, wxSOLID  ));                      
888                                                                 else
889                                                                         temp_dc.SetPen(wxPen( wxColour(0,0,0), 1, wxSOLID  ));
890                                                                 if (getOrientation())
891                                                                         temp_dc.DrawPolygon(numberEdges, points, ini_pixelX, 0);
892                                                                 else
893                                                                         temp_dc.DrawPolygon(numberEdges, points, 0, ini_pixelX);                                        
894                                                 }
895                                         }
896                                 }
897                                 else
898                                 {
899                                         if ( !(iniPoint -> isTemporalColor()) )
900                                         {
901                                                 temp_dc.SetBrush(wxBrush( intialColor, wxSOLID  ));
902                                                 temp_dc.SetPen(wxPen( wxColour(0,0,0), 1, wxSOLID  ));
903                                                 if (getOrientation())
904                                                         temp_dc.DrawPolygon(numberEdges, points, ini_pixelX, 0);
905                                                 else
906                                                         temp_dc.DrawPolygon(numberEdges, points, 0, ini_pixelX);
907                                         }                                                       
908                                 }               
909                         }
910                         if (realX_vertical_line!=-1)
911                         {
912                                 temp_dc.SetPen(wxPen(  guideLineColor,1,wxDOT  ));
913                                 int pixelX_guide = convertToPixelValue(realX_vertical_line);
914                                 if (getOrientation())
915                                         temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, bar_height);
916                                 else
917                                         temp_dc.DrawLine(0, pixelX_guide, bar_height, pixelX_guide);
918                         }
919                 }
920         }
921         
922         /*
923         * Forces the refresh view of the color bar
924         */
925         void pColorBar ::  RefreshForce ()
926         {
927                 Refresh(false);         
928         }
929         
930         /*
931         * Draws the color bar with its degrades
932         * param recentlyChangedOrientation indicates if the orientation has been changed before calling this method
933         */
934         void pColorBar ::  drawColorBar (bool recentlyChangedOrientation)
935         {
936                 wxRect rectTotal = GetClientRect(); 
937                 if (recentlyChangedOrientation)
938                 {
939                         if ( getOrientation() ) // HORIZONTAL
940                         {
941                                 //SetSize(width, height );
942                                 wxWindow::SetSize( width, height );
943                                 //SetSize( rectTotal.GetWidth(), rectTotal.GetHeight() );
944                                 setWidth(GetClientRect().GetWidth()- deviceEndMargin);
945                                 //setHeight(GetClientRect().GetHeight());
946                                 
947                                 colorBar_Bitmap = new wxBitmap( bar_width+1280, bar_height+1280 );
948                                 //information_Bitmap = new wxBitmap( width-bar_width, height-bar_height );
949                         }
950                         else // VERTICAL
951                         {
952                                 wxWindow::SetSize( height, width );
953                                 //SetSize( rectTotal.GetHeight(), rectTotal.GetWidth() );
954                                 setWidth(GetClientRect().GetHeight()- deviceEndMargin);
955                                 //setHeight(GetClientRect().GetWidth());
956                                 
957                                 //SetWindowStyle( wxNO_FULL_REPAINT_ON_RESIZE );
958                                 colorBar_Bitmap = new wxBitmap( bar_height+1280, bar_width+1280 );
959                                 //information_Bitmap = new wxBitmap( height-bar_height, width-bar_width );
960                         }               
961                 }
962         }
963                 
964         /*
965         * Changes the figure of the color points according to the parameter
966         * param figureOrientation Is the corresponding number for identifying the figure 
967         * RECTANGLE = 4,TRIANGLE LEFT = -4, TRIANGLE RIGHT = -6, TRIANGLE UP = -8, TRIANGLE DOWN = -2
968         */
969         void pColorBar :: changeFigure(int figureOrientation)
970         {               
971                 if ( figureOrientation<1 ) //The figure is a  a rotated triangle 
972                 {
973                         changePointsFigure_Edges(3);
974                         figure -> setFigureOrientation ( figureOrientation );
975                         
976                 }
977                 else //The figure is a rectangle
978                 {
979                         changePointsFigure_Edges(4);
980                 }       
981                 RefreshForce();
982         }
983
984         /**
985         * Changes the figure used for the degreade color points to the indicated one by parameter
986         * param figEdges Is the constant that represents the figure number of edges (TRIANGLE | RECTANGLE)
987         */
988         void pColorBar :: changePointsFigure_Edges(int figEdges)
989         {
990                 figure->setNumberEdges( figEdges);
991         }
992         
993         /**
994         * Gets the constant that represents the figure used for the degreade color points
995         * return figureEdges Is the constant that represents the figure number of edges (TRIANGLE | RECTANGLE)
996         */
997         int pColorBar :: getPointsFigure_Edges ()
998         {
999                 return (figure -> getNumberEdges());
1000         }
1001         
1002         /**
1003         * Sets the height of the drawing bar area
1004         * param _h The height to set
1005         */
1006         void pColorBar ::  setHeight (int _h)
1007         {
1008                 height = _h;
1009                 bar_height = height-gapY;
1010         }
1011
1012         /**
1013         * Sets the height of the drawing bar area
1014         * return _h The height to get
1015         */
1016         int pColorBar :: getHeight()
1017         {
1018                  return height;
1019         }
1020
1021         /**
1022         * Sets the width of the drawing bar area
1023         * param _w The width to set
1024         */
1025         void pColorBar ::  setWidth (int _w)
1026         {
1027                 width = _w;
1028                 bar_width = width-gapX;
1029         }
1030
1031         /**
1032         * Gets the width of the drawing bar area
1033         * param width The width to get
1034         */
1035         int pColorBar :: getWidth ()
1036         {
1037                 return width;                   
1038         }
1039
1040         /**
1041         * Sets the height of the containing rectangle bar
1042         * param _h The height to set
1043         */
1044         void pColorBar ::  setBarHeight (int _h)
1045         {
1046                 bar_height = _h;
1047         }
1048
1049         /**
1050         * Gets the height of the containing rectangle bar
1051         * return bar_height The height to get
1052         */
1053         int pColorBar :: getBarHeight()
1054         {
1055                 return bar_height;
1056         }
1057
1058         /**
1059         * Sets the width of the containing rectangle bar
1060         * param _w The width to set
1061         */
1062         void pColorBar ::  setBarWidth (int _w)
1063         {
1064                 bar_width = _w;
1065         }
1066
1067         /**
1068         * Gets the width of the containing rectangle bar
1069         * return bar_width The width to get
1070         */
1071         int pColorBar :: getBarWidth ()
1072         {
1073                 return bar_width;
1074         }
1075
1076         /**
1077         * Sets the orientation of the color bar
1078         * param _orientation The orientation to set VERTICAL = false, HORIZONTAL = true
1079         */
1080         void pColorBar ::  setOrientation (bool _orientation)
1081         {
1082                 _logicalBar -> setOrientation(_orientation);
1083                 figure -> setBarOrientation (_orientation);
1084         }
1085
1086         /**
1087         * Gets the orientation of the color bar
1088         * return bar_orientation The bar orientation assigned
1089         */
1090         bool pColorBar :: getOrientation ()
1091         {
1092                 return _logicalBar->getOrientation();
1093         }
1094
1095         /**
1096         * Sets the collection of color points
1097         * param _points The new points to set, each one of data type pColorPoint ( xValue, wxColour_assigned)
1098         */
1099         void pColorBar ::  setPoints (std::vector<pColorPoint *> _points)
1100         {
1101                 _logicalBar->clearPoints();
1102                 showedColorPoints.clear();
1103                 _logicalBar->setColorPoints(_points);
1104                 //posible needed to update
1105         }
1106
1107         /**
1108         * Gets the last clickedX pixel coord inside the bar.
1109         * return clickedX The x-coord pixel value
1110         */
1111         int pColorBar :: getClickedX()
1112         {
1113                 return clickedX;
1114         }
1115
1116         /**
1117         * Sets the last clickedX pixel coord inside the bar.
1118         * param xCoordPixel The x-coord value to set
1119         */
1120         void pColorBar :: setClickedX(int xCoordPixel)
1121         {
1122                 clickedX = xCoordPixel;
1123         }
1124
1125         /**
1126         * Gets the last clickedY pixel coord inside the bar.
1127         * return clickedY The y-coord pixel value
1128         */
1129         int pColorBar :: getClickedY()
1130         {
1131                 return clickedY;
1132         }
1133
1134         /**
1135         * Sets the last clickedY pixel coord inside the bar.
1136         * param yCoordPixel The y-coord pixel value to set
1137         */
1138         void pColorBar :: setClickedY(int yCoordPixel)
1139         {
1140                 clickedY = yCoordPixel;
1141         }
1142
1143         /**
1144         * Gets the real x value for a given x-pixel value using the rule real_x = minX_represented_Tshow + ((x_Pixel * (maxX_represented_Tshow - minX_represented_Tshow) ) / bar_width)
1145         * param x_Pixel The pixel value to convert into real value with respect to the x scale
1146         * return realX The real-x value corresponding to the xPixel
1147         */
1148         double pColorBar :: convertToRealValue ( int x_Pixel )
1149         {
1150                 /**
1151                 int newPixel = x_Pixel*(bar_width - deviceEndMargin - deviceStart_x)/(bar_width) ;
1152                 return newPixel*(maxX_represented_Tshow - minX_represented_Tshow)/(bar_width);
1153 */
1154                 return minX_represented_Tshow + ((x_Pixel-deviceStart_x) * (maxX_represented_Tshow - minX_represented_Tshow) ) /( bar_width-deviceEndMargin);           
1155         }
1156
1157         /**
1158         * Gets the x-pixel value for a given x_real value using the rule x_pixel = ((x_real - minX_represented_Tshow) * bar_width)/(maxX_represented_Tshow - minX_represented_Tshow)
1159         * param x_Pixel The pixel value to convert into real value with respect to the x scale
1160         * return realX The real-x value corresponding to the xPixel
1161         */
1162         int pColorBar :: convertToPixelValue (double x_real )
1163         {
1164                 return (int)( ((x_real - minX_represented_Tshow) * (bar_width-deviceEndMargin))/(maxX_represented_Tshow - minX_represented_Tshow) );            
1165         }
1166
1167         /**
1168         * Gets the selected color and updates the state of the okSelectedColor
1169         * return selectedColor Is the selected rbg color
1170         */
1171         wxColour pColorBar :: getSelectedColour()
1172         {
1173                 okSelectedColor = false;
1174                 wxColour col;
1175                 wxColourData data;
1176                 wxColourDialog dialog( GetParent(), &data);
1177
1178                 if ( dialog.ShowModal() == wxID_OK )
1179                 {
1180                         col = dialog.GetColourData().GetColour();
1181                         okSelectedColor = true;
1182                 }
1183                 return col;
1184         }
1185
1186         /**
1187         * Sets the represented minimum and maximunm values
1188         * param minRealValue The minimum represented value (real value)
1189         * param maxRealValue The maximum represented value (real value)
1190         */
1191         void pColorBar :: setRepresentedValues ( double minRealValue, double maxRealValue )
1192         {
1193                 temporalMinXToShow = (int)minRealValue;
1194                 temporalMaxXToShow = (int)maxRealValue;
1195
1196                 minX_represented_Tshow = (int)minRealValue;             
1197                 maxX_represented_Tshow = (int)maxRealValue;
1198                 _logicalBar->setMinValue(minX_represented_Tshow);
1199                 _logicalBar->setMaxValue(maxX_represented_Tshow);
1200         }
1201
1202         /**
1203         * Gets the data of the last point moving in a pColorPoint copy
1204         * return pointData Is a pColorPoint with the data of las moved color
1205         */
1206         pColorPoint * pColorBar :: getLastMovedColorPoint()
1207         {
1208                 pColorPoint * dataPoint = new pColorPoint ( 0, wxColor (0,0,0), false);
1209                 if (movingNodePoint)
1210                 {               
1211                         dataPoint ->setColor(movingNodePoint->getColor());
1212                         dataPoint ->setRealX(movingNodePoint->getRealX());
1213                 }
1214                 return dataPoint;
1215         }
1216
1217         /**
1218         * Sets the gap values for the color bar bitmap
1219         * param gap_x Gap in x
1220         * param gap_y Gap in y
1221         */
1222         void pColorBar :: setGapValues (int gap_x, int gap_y)
1223         {
1224                 gapX = gap_x;
1225                 gapY = gap_y;
1226         }
1227
1228         /**
1229         * Sets the degrade state of the color bar
1230         * param newState The degrade stare to set 
1231         */
1232         void pColorBar :: setDegradeState(bool newState)
1233         {
1234                 doingDegrade = newState;
1235         }
1236
1237         /**
1238         * Gets the degrade state of the color bar
1239         * return doingDegrade is the actual degrade state of the bar
1240         */
1241         bool pColorBar :: getDegradeState()
1242         {
1243                 return doingDegrade;
1244         }
1245
1246         /**
1247         * Sets the visible range of the bar and repaints the bar according to it, the min value must be less than the max value.
1248         * param minToShow Is the minimum value to show in the colorbar
1249         * param maxToShow Is the maximum value to show in the colorbar
1250         */
1251         void pColorBar :: setVisibleRange(int minToShow, int maxToShow)
1252         {
1253                 minX_represented_Tshow = minToShow;
1254                 maxX_represented_Tshow = maxToShow; 
1255                 viewingRange = true;
1256                 RefreshForce();
1257         }
1258
1259         /**
1260         * Sets the state of static or not for the limit color points
1261         * pamar areStatic Is the state to set for the limits
1262         */
1263         void pColorBar :: setStaticLimitsTo(bool areStatic)
1264         {
1265                 staticLimits = areStatic;
1266         }
1267
1268         /**
1269         * Gets the state of static or not for the limit color points
1270         * return staticLimits Is the state for limits
1271         */
1272         bool pColorBar :: getStaticLimits()
1273         {
1274                 return staticLimits;
1275         }
1276
1277         /**
1278         * Sets the device start drawing left-superior (pixel) start point and draws automatically the color bar
1279         * param deviceStart_x Pixel start for x-coord
1280         * param deviceStart_y Pixel start for y-coord
1281         */
1282         void pColorBar :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1283         {
1284                 deviceStart_x = devStart_x;
1285                 deviceStart_y = devStart_y;
1286                 if (getOrientation())
1287                         width += deviceStart_x;
1288                 else
1289                         height += deviceStart_y;
1290                 drawColorBar(true);
1291         }
1292
1293         /**
1294         * Clears the temporal color points of the list
1295         */
1296         void pColorBar :: clearTemporalColors()
1297         {
1298                 
1299         }
1300
1301         /**
1302         * Set active state 
1303         * param activeNow The new state
1304         */
1305         void pColorBar :: setActiveStateTo (bool activeNow)
1306         {
1307                 activeState = activeNow;
1308         }
1309         
1310         /**
1311         * Gets the active state of the bar
1312         *  return isActive The actual state
1313         */
1314         bool pColorBar :: isActive()
1315         {
1316                 return activeState;
1317         }
1318
1319         /**
1320         * Gets the real-x value to draw a vertical line
1321         * return realX_vertical_line The real x value for the vertical line
1322         */
1323         int     pColorBar :: getRealX_vertical_line()
1324         {
1325                 return realX_vertical_line;
1326         }
1327
1328         /**
1329         * Sets the real-x value to draw a vertical line
1330         * param realX_vertical_line The new real x value for the vertical line
1331         */
1332         void pColorBar :: setRealX_vertical_line(int newReal_x)
1333         {
1334                 realX_vertical_line = newReal_x;
1335         }
1336
1337         /**
1338         * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1339         * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1340         */
1341         void pColorBar :: setDeviceEndMargin(int newDeviceEnd_pixels)
1342         {
1343                 deviceEndMargin = newDeviceEnd_pixels;
1344         }
1345
1346         void pColorBar :: createAndSendEvent(WXTYPE theEventType)
1347         {
1348                 wxCommandEvent cevent( theEventType, GetId() );
1349                 cevent.SetEventObject( this );
1350                 GetEventHandler()->ProcessEvent( cevent );
1351         }
1352
1353         
1354         /**
1355                 Returns the number of points that the bar color has
1356         */
1357         int pColorBar::getColorPointsSize()
1358         {
1359                 return _logicalBar->getCount();
1360         }
1361
1362         /*
1363          Get the RGB values of the color point that is in the
1364          index given with respecto to the
1365         */
1366         void pColorBar::getDataAt(int index, double& x,int& red,int& green,int& blue)
1367         {
1368                 //******************************
1369                 _logicalBar->getDataAt(index, x, red, green, blue);
1370         }
1371
1372         /*
1373         * Sets the guide line color
1374         * param theNwGuideLineColor The color to set to the guideLineColor
1375         */
1376         void pColorBar :: setGuideLineColour(wxColour theNwGuideLineColor)
1377         {
1378                 guideLineColor = theNwGuideLineColor;
1379         }
1380
1381         /*
1382         * Gets the guide line color
1383         * return guideLineColor The color of the guideLine
1384         */
1385         wxColour pColorBar :: getGuideLineColour()
1386         {
1387                 return guideLineColor;
1388         }
1389
1390         /*
1391         * Sets the guide line color
1392         * param theNwGuideLineColor The color to set to the guideLineColor
1393         */
1394         void pColorBar :: setBackGroundColour(wxColour theNwBackColor)
1395         {
1396                 colourParent = theNwBackColor;
1397         }
1398
1399         /*
1400         * Gets the guide line color
1401         * return guideLineColor The color of the guideLine
1402         */
1403         wxColour pColorBar :: getBackGroundColour()
1404         {
1405                 return colourParent;
1406         }
1407
1408         /*
1409         * Gets the min value of the color bar
1410         */
1411         double  pColorBar :: getMinValue()
1412         {
1413                 return (double)minX_represented_Tshow;
1414         }
1415
1416         /*
1417         * Gets the max value of the color bar
1418         */
1419         double pColorBar :: getMaxValue()
1420         {
1421                 return (double)maxX_represented_Tshow;
1422         }
1423
1424
1425         void pColorBar :: updatePointsToDraw()
1426         {               
1427                 accumTemporalPoints = 0;                
1428                 if (_logicalBar->getCount()>0)
1429                 {
1430                         showedColorPoints.clear();
1431                         
1432                         int startIndex, endIndex;
1433                         _logicalBar -> getPointersToRangeLimits( showedColorPoints, startIndex, endIndex, minX_represented_Tshow, maxX_represented_Tshow );
1434                 
1435                         int internalCount = _logicalBar->getCount();                                            
1436                         std::deque <pColorPoint*>::iterator iterStart = showedColorPoints.begin( );
1437                         std::deque <pColorPoint*>::iterator iterEnd = showedColorPoints.end( );
1438                         
1439                         int pixelTmpStart = convertToPixelValue (minX_represented_Tshow);
1440                         int pixelTmpEnd = convertToPixelValue (maxX_represented_Tshow);
1441                         int initial_r, final_r, initial_g, final_g, initial_b, final_b, rectangle_width;
1442                         double realINI, realEND;
1443
1444                         bool includeTempStart = false;
1445                         bool includeTempEnd = false;
1446                         //-----------------Adding the first visible point of the list
1447                         if(showedColorPoints.size()>0)
1448                         {
1449                                 includeTempStart = (int)(showedColorPoints.front()->getRealX())>minX_represented_Tshow ;                                                                        
1450                                 includeTempEnd = (int)(showedColorPoints.back()->getRealX())<maxX_represented_Tshow ;                                                                   
1451                                 if( startIndex >= 0 )
1452                                 {
1453                                         if( startIndex == 0 )
1454                                         {
1455                                                 //The temporal showing point for the start should have the same color of the initial point in range at startIndex
1456                                                 _logicalBar -> getDataAt( startIndex, realINI, initial_r, initial_g, initial_b );
1457                                                 realINI = minX_represented_Tshow;
1458                                                 _logicalBar -> getDataAt( startIndex, realEND, final_r, final_g, final_b );                                     
1459                                         }
1460                                         else if( startIndex > 0 )
1461                                         {
1462                                                 _logicalBar -> getDataAt( startIndex-1, realINI, initial_r, initial_g, initial_b );
1463                                                 _logicalBar -> getDataAt( startIndex, realEND, final_r, final_g, final_b );
1464                                         }
1465                                         
1466                                         if( includeTempStart )
1467                                         {
1468                                                 int ini_pixelX = convertToPixelValue( realINI );
1469                                                 int end_pixelX = convertToPixelValue( realEND );
1470
1471                                                 rectangle_width = end_pixelX - ini_pixelX;                                              
1472                                                 
1473                                                 float m_scope_r = (float)(final_r-initial_r)/rectangle_width;
1474                                                 float m_scope_g = (float)(final_g-initial_g)/rectangle_width;
1475                                                 float m_scope_b = (float)(final_b-initial_b)/rectangle_width;           
1476
1477                                                 
1478                                                 float bRed = initial_r - m_scope_r*pixelTmpStart;
1479                                                 float bGreen = initial_g -  m_scope_g*pixelTmpStart;
1480                                                 float bBlue = initial_b - m_scope_b*pixelTmpStart;
1481
1482                                                 showedColorPoints.push_front( new pColorPoint ( minX_represented_Tshow, wxColour( (m_scope_r*pixelTmpStart)+bRed, (m_scope_g*pixelTmpStart)+bGreen, (m_scope_b*pixelTmpStart)+bBlue ), true));                          
1483                                         
1484                                                 accumTemporalPoints ++; 
1485                                         }
1486                                 }                               
1487                                 if( includeTempEnd && minX_represented_Tshow < maxX_represented_Tshow )
1488                                 {       
1489                                         if( internalCount>0 )
1490                                         {
1491                                                 if( endIndex == internalCount-1 )
1492                                                 {
1493                                                         _logicalBar -> getDataAt( endIndex, realINI, initial_r, initial_g, initial_b );
1494                                                         _logicalBar -> getDataAt( endIndex, realEND, final_r, final_g, final_b );
1495                                                         realEND = maxX_represented_Tshow;
1496                                                 }                                               
1497                                                 else
1498                                                 {
1499                                                         _logicalBar -> getDataAt( endIndex, realINI, initial_r, initial_g, initial_b );
1500                                                         _logicalBar -> getDataAt( endIndex+1, realEND, final_r, final_g, final_b );                                                     
1501                                                 }                                       
1502
1503                                                 int ini_pixelX = convertToPixelValue( realINI );
1504                                                 int end_pixelX = convertToPixelValue( realEND );
1505
1506                                                 rectangle_width = end_pixelX - ini_pixelX;                                              
1507                                                 
1508                                                 float m_scope_r = (float)(final_r-initial_r)/rectangle_width;
1509                                                 float m_scope_g = (float)(final_g-initial_g)/rectangle_width;
1510                                                 float m_scope_b = (float)(final_b-initial_b)/rectangle_width;           
1511                                                 
1512                                                 float bRed = initial_r - m_scope_r*pixelTmpEnd;
1513                                                 float bGreen = initial_g -  m_scope_g*pixelTmpEnd;
1514                                                 float bBlue = initial_b - m_scope_b*pixelTmpEnd;
1515                                                 showedColorPoints.push_back( new pColorPoint ( maxX_represented_Tshow, wxColour( ( m_scope_r*pixelTmpEnd)+bRed, (m_scope_g*pixelTmpEnd)+bGreen, (m_scope_b*pixelTmpEnd)+bBlue ), true));                                
1516                                                 accumTemporalPoints ++;                         
1517                                         }                                       
1518                                 }
1519                         }
1520                         else
1521                         {
1522                                 if(_logicalBar->getCount()>0)
1523                                 {
1524                                         if ( minX_represented_Tshow > _logicalBar->getMaxAddedValue() )
1525                                         {
1526                                                 endIndex = _logicalBar->getCount()-1;
1527                                         }
1528                                         else if ( maxX_represented_Tshow < _logicalBar->getMinAddedValue() )
1529                                         {
1530                                                 endIndex = 0;
1531                                         }
1532
1533                                         _logicalBar -> getDataAt( endIndex, realINI, initial_r, initial_g, initial_b );
1534                                         _logicalBar -> getDataAt( endIndex, realEND, final_r, final_g, final_b );
1535                                         
1536                                         realINI = minX_represented_Tshow;
1537                                         realEND = maxX_represented_Tshow;
1538
1539                                         showedColorPoints.push_back( new pColorPoint ( realINI, wxColour( initial_r, initial_g, initial_b ), true));    
1540                                         accumTemporalPoints ++;         
1541                                         showedColorPoints.push_back( new pColorPoint ( realEND, wxColour( initial_r, initial_g, initial_b ), true));    
1542                                         accumTemporalPoints ++;         
1543                                 }
1544                         }
1545                 }               
1546                         
1547                 if ( !showedColorPoints.empty() )
1548                 {
1549                         startNode_show = showedColorPoints.front();
1550                         lastNode_show = showedColorPoints.back();
1551                 }
1552         }
1553