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