]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pColorBar.cxx
be5e98aa1047d60e3e8e1f95bfbf7091461c8661
[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                 }
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                 }
438         }
439         /**
440         * Reacts to the cntID_TRIANGLES_UP wxCommandEvent and changes the assigned figure to -triangles up- for the color points of the color bar.
441         * param & anEvent The wxCommandEvent actioned event 
442         */
443         void pColorBar :: onTrianglesUp_Figure ( wxCommandEvent& anEvent  )
444         {
445                 if( !changesMenu->IsChecked(cntID_TRIANGLES_UP) )
446                 {
447                         changeFigure (-8);
448                         changesMenu->Check (cntID_TRIANGLES_UP, true);
449                         changesMenu->Check (cntID_TRIANGLES_DOWN, false);
450                         changesMenu->Check (cntID_TRIANGLES_LEFT, false);
451                         changesMenu->Check (cntID_TRIANGLES_RIGHT, false);
452                         changesMenu->Check (cntID_RECTANGLES, false);
453                 }
454         }
455         /**
456         * Reacts to the cntID_TRIANGLES_DOWN wxCommandEvent and changes the assigned figure to -triangles down- for the color points of the color bar.
457         * param & anEvent The wxCommandEvent actioned event 
458         */
459         void pColorBar :: onTrianglesDown_Figure ( wxCommandEvent& anEvent  )
460         {
461                 if( !changesMenu->IsChecked(cntID_TRIANGLES_DOWN) )
462                 {
463                         changeFigure (-2);
464                         changesMenu->Check (cntID_TRIANGLES_UP, false);
465                         changesMenu->Check (cntID_TRIANGLES_DOWN, true);
466                         changesMenu->Check (cntID_TRIANGLES_LEFT, false);
467                         changesMenu->Check (cntID_TRIANGLES_RIGHT, false);
468                         changesMenu->Check (cntID_RECTANGLES, false);
469                 }
470         }
471         /**
472         * Reacts to the cntID_TRIANGLES_LEFT wxCommandEvent and changes the assigned figure to -triangles left- for the color points of the color bar.
473         * param & anEvent The wxCommandEvent actioned event 
474         */
475         void pColorBar :: onTrianglesLeft_Figure ( wxCommandEvent& anEvent  )
476         {
477                 if( !changesMenu->IsChecked(cntID_TRIANGLES_LEFT) )
478                 {
479                         changeFigure (-4);
480                         changesMenu->Check (cntID_TRIANGLES_UP, false);
481                         changesMenu->Check (cntID_TRIANGLES_DOWN, false);
482                         changesMenu->Check (cntID_TRIANGLES_LEFT, true);
483                         changesMenu->Check (cntID_TRIANGLES_RIGHT, false);
484                         changesMenu->Check (cntID_RECTANGLES, false);
485                 }
486         }
487         /**
488         * Reacts to the cntID_TRIANGLES_RIGHT wxCommandEvent and changes the assigned figure to -triangles right- for the color points of the color bar.
489         * param & anEvent The wxCommandEvent actioned event 
490         */
491         void pColorBar :: onTrianglesRight_Figure ( wxCommandEvent& anEvent  )
492         {
493                 if( !changesMenu->IsChecked(cntID_TRIANGLES_RIGHT) )
494                 {
495                         changeFigure (-6);
496                         changesMenu->Check (cntID_TRIANGLES_UP, false);
497                         changesMenu->Check (cntID_TRIANGLES_DOWN, false);
498                         changesMenu->Check (cntID_TRIANGLES_LEFT, false);
499                         changesMenu->Check (cntID_TRIANGLES_RIGHT, true);
500                         changesMenu->Check (cntID_RECTANGLES, false);
501                 }
502         }
503         /**
504         * Reacts to the cntID_RECTANGLES wxCommandEvent and changes the assigned figure to -rectangles- for the color points of the color bar.
505         * param & anEvent The wxCommandEvent actioned event 
506         */
507         void pColorBar :: onRectangles_Figure ( wxCommandEvent& anEvent  )
508         {
509                 if( !changesMenu->IsChecked(cntID_TRIANGLES_RIGHT) )
510                 {
511                         changeFigure (RECTANGLE);// RECTANGLE = 4
512                         changesMenu->Check (cntID_TRIANGLES_UP, false);
513                         changesMenu->Check (cntID_TRIANGLES_DOWN, false);
514                         changesMenu->Check (cntID_TRIANGLES_LEFT, false);
515                         changesMenu->Check (cntID_TRIANGLES_RIGHT, false);
516                         changesMenu->Check (cntID_RECTANGLES, true);
517                 }
518         }
519
520         /**
521         * Reacts to the cntID_DEGRADE_CONTROL wxCommandEvent and turns on/off the degrade in the color bar.
522         * param & anEvent The wxCommandEvent actioned event 
523         */
524         void pColorBar ::  onDegradeControl ( wxCommandEvent& anEvent )
525         {
526                 bool degrade = getDegradeState();
527                 wxString nextAction_text;
528                 if(degrade)
529                 {
530                         nextAction_text = _T("Turn on degrade");        
531                         setDegradeState (false);
532                 }
533                 else
534                 {
535                         nextAction_text = _T("Turn off degrade");
536                         setDegradeState (true);
537                 }
538                 c_popmenu.SetLabel ( cntID_DEGRADE_CONTROL, nextAction_text ); 
539         }
540
541         /**
542         * Reacts to the wxEVT_RIGHT_DCLICK wxMouseEvent and adds a color degrade point to the color bar.
543         * Informs the result of the handled event like a wxCommandEvent wxEVT_ADDED_COL_POINT if the point was succesfully inserted.
544         * param & event The wxMouseEvent actioned event 
545         */
546         void pColorBar ::  onLeftButtonDClick (wxMouseEvent& event)
547         {
548                 if (activeState)
549                 {
550                         bool addedPoint = false;
551                         wxPoint point = event.GetPosition();
552                         bool posiblePoint = false;
553                         if( getOrientation() )
554                         {
555                                 posiblePoint = point.x>=deviceStart_x && point.y<= (bar_height + deviceStart_y);
556                         }
557                         else
558                         {
559                                 posiblePoint = point.x>=deviceStart_y && point.x<= (bar_height+deviceStart_y) && point.y>deviceStart_x;
560                         }
561
562                         if (posiblePoint)
563                         {
564                                 double real_x = getOrientation() ? convertToRealValue( point.x ) : convertToRealValue( point.y );
565                                 wxColour selectedColor = getSelectedColour();
566                                 if (okSelectedColor)
567                                 {
568                                         addedPoint = addColorPoint (real_x, selectedColor);                                     
569                                 }
570                                 // Inform addedPoint event
571                                 if ( addedPoint )
572                                 {
573                                         //RefreshForce(); Is all ready refreshed on the adition of the point method
574                                         createAndSendEvent( wxEVT_ADDED_POINT );                        
575                                 }
576                         }
577                 }
578         }
579                 
580         void  pColorBar ::onLeftClicDown(wxMouseEvent& event )
581         {
582                 acceptedClick = true;           
583         }
584
585         void  pColorBar ::onLeftClickUp(wxMouseEvent& event )
586         {       
587                 movingPointIndex = -1;
588                 acceptedClick = false;
589         }
590         /*
591         * Shows the popup menu 
592         */
593         void pColorBar ::  onShowPopupMenu (wxMouseEvent &event)
594         {
595                 if (activeState)
596                 {
597                         if(showedColorPoints.empty())
598                         {
599                                 c_popmenu.Enable(cntID_DEL_COLOR_POINT, false);                 
600                         }
601                         else
602                         {
603                                 c_popmenu.Enable(cntID_DEL_COLOR_POINT, true);
604                         }
605                         bool setClickedValues = false;
606                         if( getOrientation() )
607                         {
608                                 setClickedValues = event.GetX()>=deviceStart_x && event.GetY()<= (bar_height + deviceStart_y);
609                         }
610                         else
611                         {
612                                 setClickedValues = event.GetX()>=deviceStart_y && event.GetX()<= (bar_height+deviceStart_y) && event.GetY()>deviceStart_x;
613                         }
614                         if (setClickedValues)
615                         {
616                                 setClickedX ( event.GetX() );
617                                 setClickedY ( event.GetY() );
618                                 RefreshForce();
619                                 PopupMenu( &c_popmenu, event.GetX(), event.GetY());
620                         }
621                 }
622         }
623         //------------------------------------------------------------------------------------------------------------
624         // Other methods implementation
625         //------------------------------------------------------------------------------------------------------------
626
627         /*
628         * Method that reinitiates attributes of the color bar to the given points
629         * param minRealValue The minimum represented value (real value)
630         * param maxRealValue The maximum represented value (real value)
631         */
632         void pColorBar :: reinitiateColorBar(double minRealValue, double maxRealValue)
633         {
634
635                 _logicalBar -> clearPoints();
636                 showedColorPoints.clear();
637                                 
638                 movingPointIndex = -1;
639                 realX_vertical_line = -1;
640                 activeState = true;
641                 accumTemporalPoints = 0;
642                 viewingRange = false;
643                 setDegradeState(true);                  
644                 setRepresentedValues(minRealValue, maxRealValue);
645         }
646
647         /*
648         * Method that reinitiates  attributes of the color bar and set the points given by parameter
649         * param pointsVector The the vector of the new points, the color points must have at least two points.
650         */
651         void pColorBar :: reinitiateColorBarTo (std::vector<pColorPoint *> pointsVector)
652         {
653                 _logicalBar -> clearPoints();
654                 _logicalBar -> setColorPoints(pointsVector);
655                 showedColorPoints.clear();
656                 
657                 movingPointIndex = -1;
658                 realX_vertical_line = -1;
659                 activeState = true;
660                 accumTemporalPoints = 0;                
661                 viewingRange = false;
662                 setDegradeState(true);                                  
663                 
664                 double minRealValue = _logicalBar -> getMinValue();
665                 double maxRealvalue = _logicalBar -> getMaxValue();
666
667                 setRepresentedValues(minRealValue, maxRealvalue);
668         }
669
670         /*
671         * Method that sets a copy of the points of the color bar to the given pointer parameter
672         * param pointsList The list for getting the points
673         */
674         void pColorBar :: getPointsListWithTemps (std::vector<pColorPoint*> &pointsVector)
675         {               
676                 pColorPoint* cPoint;
677                 for (int a =0; a<showedColorPoints.size() ; a++)        
678                 {
679                         cPoint = showedColorPoints[a];
680                         pColorPoint* copyPoint = new pColorPoint(cPoint->getRealX(), cPoint->getColor( ), (cPoint->isTemporalColor()));
681                         pointsVector.push_back(copyPoint);                      
682                 }
683         }
684
685         /*
686         * 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
687         * includes the teporal points created
688         * param pointsList The list for getting the points
689         */
690         
691         void pColorBar :: getAddedColorsPointsList (std::vector<pColorPoint*> &pointsVector)
692         {
693                 pColorPoint* cPoint;
694                 for (int a =0; a<_logicalBar->getCount(); a++)  
695                 {
696                         cPoint = _logicalBar ->getPointAtIndex(a);                      
697                         pColorPoint* copyPoint = new pColorPoint(cPoint->getRealX(), cPoint->getColor( ), (cPoint->isTemporalColor()));
698                         pointsVector.push_back(copyPoint);                      
699                 }
700         }
701         
702
703         /**
704         * Adds a color degrade point to the color bar.
705         * param xRealValue The real xValue of the point
706         * param theColour The assigned color for the point
707         * param temporalStart Indicates if the inserted point is the temporal startShowing point
708         * param temporalEnd Indicates if the inserted point is the temporal startShowing point
709         * return Returns true if the point was succesfully inserted.
710         */
711         bool pColorBar :: addColorPoint (double xRealValue, wxColour theColour/*, bool temporalStart, bool temporalEnd*/)
712         {
713                 bool addedPoint = false;
714                 addedPoint = _logicalBar->addColorPoint(xRealValue,theColour);
715                 if (addedPoint) 
716                         RefreshForce();
717                 return addedPoint;
718         }
719
720
721         /**
722         * Delets a color degrade point to the color bar.
723         * param xRealValue The real xValue of the point to delete       
724         * return Returns true if the point was succesfully inserted.
725         */
726         bool pColorBar :: deleteColorPoint (double xRealValue)
727         {       
728                 pColorPoint* actualPoint;               
729                 bool deletedPoint = false;
730                 for (int a =0; a<showedColorPoints.size() && !deletedPoint; a++)        
731                 {
732                         actualPoint = showedColorPoints[a];
733                         int actualX = (int)actualPoint -> getRealX();
734                         bool isInsideActual = figure -> isPointInside (convertToPixelValue(actualX), convertToPixelValue(xRealValue));
735                         if( actualX == xRealValue || isInsideActual)
736                         {
737                                 movingPointIndex=-1;                                                            
738                                 deletedPoint = _logicalBar->deleteColorPoint(actualPoint -> getRealX());                                        
739                         }                       
740                 }                       
741                 if (deletedPoint) 
742                         RefreshForce();
743                 return deletedPoint;                    
744         }
745
746         /**
747         * Changes the color degrade point color value.
748         * Informs the result of the handled event like a wxCommandEvent wxEVT_CHANGED_COLOR_POINT if the point changed its colour.
749         * param clickedValue The x-coord pixel value of the point to which the color change interests   
750         * return Returns true if the color point was succesfully updated.
751         */
752         bool pColorBar :: changeColor ( int clickedValue )
753         {               
754                 bool colourUpdated = false;
755                 double xRealValue = convertToRealValue( clickedValue );
756                 pColorPoint* actualPoint;
757                 for (int a =0; a<showedColorPoints.size() && !colourUpdated; a++)       
758                 {
759                         actualPoint = showedColorPoints[a];
760                         int actualX = (int)actualPoint -> getRealX();
761                         bool isInsideActual = figure -> isPointInside (convertToPixelValue(actualX), clickedValue);
762                         if( actualX == xRealValue || isInsideActual)
763                         {
764                                 wxColour newColour = getSelectedColour();
765                                 if (okSelectedColor)
766                                 {
767                                         actualPoint -> setColor(newColour);
768                                         colourUpdated = true;                                   
769                                 }                               
770                         }                       
771                 }               
772                 if(colourUpdated)
773                         RefreshForce();
774                 return colourUpdated;
775         }
776
777         /*
778         * Repaints the color bar in horizontal direction mode
779         */
780         void pColorBar ::  repaintView(  )
781         {
782                 wxMemoryDC temp_dc;
783                 temp_dc.SelectObject( * colorBar_Bitmap );              
784                 temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID  ));
785                 temp_dc.SetPen(wxPen( colourParent,1,wxSOLID  ));
786                 if (getOrientation())
787                 {
788                         temp_dc.DrawRectangle(0, 0, bar_width, bar_height);
789                         temp_dc.SetPen(wxPen( wxColour(167,165,191),1,wxSOLID  ));
790                         temp_dc.DrawRectangle(0, 0, bar_width-deviceEndMargin, bar_height);
791                 }
792                 else
793                 {
794                         temp_dc.DrawRectangle(0, 0, bar_height, bar_width);
795                         temp_dc.SetPen(wxPen( wxColour(167,165,191),1,wxSOLID  ));
796                         temp_dc.DrawRectangle(0, 0, bar_height, bar_width-deviceEndMargin);
797                 }
798                 //wxPoint figPoints[4]; // JPRx
799                 
800                 if( _logicalBar -> getCount() >0)
801                 {
802                         updatePointsToDraw();
803                         
804                         int numberEdges = figure->getNumberEdges();
805                         wxPoint points [4];
806                         figure->getVertexPoints(points);
807                         figure ->setVertexPoints (points);
808
809                         int maxValue = showedColorPoints.size();
810                         pColorPoint * iniPoint;
811                         pColorPoint * endPoint;
812                         wxColor intialColor, finalColor;
813                         for (int a=0; a<maxValue; a++)
814                         {
815                                 iniPoint = showedColorPoints[a];
816                                 int ini_pixelX = convertToPixelValue(iniPoint -> getRealX());                           
817                                 intialColor = iniPoint -> getColor();
818                                                                 
819                                 if( a<maxValue-1 )
820                                 {
821                                         if( doingDegrade )
822                                         {
823                                                 endPoint = showedColorPoints[a+1];
824                                                 int end_pixelX = convertToPixelValue(endPoint -> getRealX());
825                                                 finalColor = endPoint -> getColor();                                    
826                                         
827                                                 int rectangle_width = end_pixelX - ini_pixelX;
828                                                 
829                                                 //*************************************************************************************
830                                                 int initial_r = intialColor.Red();
831                                                 int final_r = finalColor.Red()  ;
832                                                 int initial_g = intialColor.Green();
833                                                 int final_g= finalColor.Green();
834                                                 int initial_b = intialColor.Blue();
835                                                 int final_b= finalColor.Blue();
836                                                 
837                                                 float m_scope_r = (float)(final_r-initial_r)/rectangle_width;
838                                                 float m_scope_g = (float)(final_g-initial_g)/rectangle_width;
839                                                 float m_scope_b = (float)(final_b-initial_b)/rectangle_width;                           
840
841                                                 int next_r = initial_r;
842                                                 int next_g = initial_g;
843                                                 int next_b = initial_b;
844
845                                                 float nxt_r = (float)next_r;
846                                                 float nxt_g = (float)next_g;
847                                                 float nxt_b = (float)next_b;
848
849                                                 for (int Xi =ini_pixelX; Xi<= end_pixelX; Xi++)                                         
850                                                 {
851                                                         temp_dc.SetBrush(wxBrush( wxColour(next_r, next_g, next_b),wxSOLID  ));
852                                                         temp_dc.SetPen(wxPen( wxColour(next_r, next_g, next_b),1,wxSOLID  ));
853                                                         if( getOrientation() )
854                                                                 temp_dc.DrawLine(Xi, 0, Xi, bar_height);
855                                                         else
856                                                                 temp_dc.DrawLine(0, Xi, bar_height, Xi);
857
858                                                         nxt_r = (m_scope_r + nxt_r);
859                                                         nxt_g = (m_scope_g + nxt_g);
860                                                         nxt_b = (m_scope_b + nxt_b);
861                                                         
862                                                         next_r = (int)(nxt_r);
863                                                         next_g = (int)(nxt_g);
864                                                         next_b = (int)(nxt_b);                                                          
865                                                 }                                                                       
866                                         }                               
867                                 }
868                                 if( movingPointIndex!=-1 && movingNodePoint!=NULL )
869                                 {                                       
870                                         if ( !(movingNodePoint -> isTemporalColor()) )
871                                         {
872                                                 if( movingNodePoint==iniPoint && movingPointIndex!=-1 )
873                                                 {
874                                                         temp_dc.SetBrush(wxBrush(  wxColour(5,36,180), wxSOLID  ));
875                                                         temp_dc.SetPen(wxPen( wxColour(239,239,239), 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                                                 else
882                                                 {                                               
883                                                                 temp_dc.SetBrush(wxBrush( intialColor, wxSOLID  ));     
884                                                                 if(iniPoint->isTemporalColor())
885                                                                         temp_dc.SetPen(wxPen( intialColor, 1, wxSOLID  ));                      
886                                                                 else
887                                                                         temp_dc.SetPen(wxPen( wxColour(0,0,0), 1, wxSOLID  ));
888                                                                 if (getOrientation())
889                                                                         temp_dc.DrawPolygon(numberEdges, points, ini_pixelX, 0);
890                                                                 else
891                                                                         temp_dc.DrawPolygon(numberEdges, points, 0, ini_pixelX);                                        
892                                                 }
893                                         }
894                                 }
895                                 else
896                                 {
897                                         if ( !(iniPoint -> isTemporalColor()) )
898                                         {
899                                                 temp_dc.SetBrush(wxBrush( intialColor, wxSOLID  ));
900                                                 temp_dc.SetPen(wxPen( wxColour(0,0,0), 1, wxSOLID  ));
901                                                 if (getOrientation())
902                                                         temp_dc.DrawPolygon(numberEdges, points, ini_pixelX, 0);
903                                                 else
904                                                         temp_dc.DrawPolygon(numberEdges, points, 0, ini_pixelX);
905                                         }                                                       
906                                 }               
907                         }
908                         if (realX_vertical_line!=-1)
909                         {
910                                 temp_dc.SetPen(wxPen(  guideLineColor,1,wxDOT  ));
911                                 int pixelX_guide = convertToPixelValue(realX_vertical_line);
912                                 if (getOrientation())
913                                         temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, bar_height);
914                                 else
915                                         temp_dc.DrawLine(0, pixelX_guide, bar_height, pixelX_guide);
916                         }
917                 }
918         }
919         
920         /*
921         * Forces the refresh view of the color bar
922         */
923         void pColorBar ::  RefreshForce ()
924         {
925                 Refresh(false);         
926         }
927         
928         /*
929         * Draws the color bar with its degrades
930         * param recentlyChangedOrientation indicates if the orientation has been changed before calling this method
931         */
932         void pColorBar ::  drawColorBar (bool recentlyChangedOrientation)
933         {
934                 wxRect rectTotal = GetClientRect(); 
935                 if (recentlyChangedOrientation)
936                 {
937                         if ( getOrientation() ) // HORIZONTAL
938                         {
939                                 //SetSize(width, height );
940                                 wxWindow::SetSize( width, height );
941                                 //SetSize( rectTotal.GetWidth(), rectTotal.GetHeight() );
942                                 setWidth(GetClientRect().GetWidth()- deviceEndMargin);
943                                 //setHeight(GetClientRect().GetHeight());
944                                 
945                                 colorBar_Bitmap = new wxBitmap( bar_width+1280, bar_height+1280 );
946                                 //information_Bitmap = new wxBitmap( width-bar_width, height-bar_height );
947                         }
948                         else // VERTICAL
949                         {
950                                 wxWindow::SetSize( height, width );
951                                 //SetSize( rectTotal.GetHeight(), rectTotal.GetWidth() );
952                                 setWidth(GetClientRect().GetHeight()- deviceEndMargin);
953                                 //setHeight(GetClientRect().GetWidth());
954                                 
955                                 //SetWindowStyle( wxNO_FULL_REPAINT_ON_RESIZE );
956                                 colorBar_Bitmap = new wxBitmap( bar_height+1280, bar_width+1280 );
957                                 //information_Bitmap = new wxBitmap( height-bar_height, width-bar_width );
958                         }               
959                 }
960         }
961                 
962         /*
963         * Changes the figure of the color points according to the parameter
964         * param figureOrientation Is the corresponding number for identifying the figure 
965         * RECTANGLE = 4,TRIANGLE LEFT = -4, TRIANGLE RIGHT = -6, TRIANGLE UP = -8, TRIANGLE DOWN = -2
966         */
967         void pColorBar :: changeFigure(int figureOrientation)
968         {               
969                 if ( figureOrientation<1 ) //The figure is a  a rotated triangle 
970                 {
971                         changePointsFigure_Edges(3);
972                         figure -> setFigureOrientation ( figureOrientation );
973                         
974                 }
975                 else //The figure is a rectangle
976                 {
977                         changePointsFigure_Edges(4);
978                 }       
979                 RefreshForce();
980         }
981
982         /**
983         * Changes the figure used for the degreade color points to the indicated one by parameter
984         * param figEdges Is the constant that represents the figure number of edges (TRIANGLE | RECTANGLE)
985         */
986         void pColorBar :: changePointsFigure_Edges(int figEdges)
987         {
988                 figure->setNumberEdges( figEdges);
989         }
990         
991         /**
992         * Gets the constant that represents the figure used for the degreade color points
993         * return figureEdges Is the constant that represents the figure number of edges (TRIANGLE | RECTANGLE)
994         */
995         int pColorBar :: getPointsFigure_Edges ()
996         {
997                 return (figure -> getNumberEdges());
998         }
999         
1000         /**
1001         * Sets the height of the drawing bar area
1002         * param _h The height to set
1003         */
1004         void pColorBar ::  setHeight (int _h)
1005         {
1006                 height = _h;
1007                 bar_height = height-gapY;
1008         }
1009
1010         /**
1011         * Sets the height of the drawing bar area
1012         * return _h The height to get
1013         */
1014         int pColorBar :: getHeight()
1015         {
1016                  return height;
1017         }
1018
1019         /**
1020         * Sets the width of the drawing bar area
1021         * param _w The width to set
1022         */
1023         void pColorBar ::  setWidth (int _w)
1024         {
1025                 width = _w;
1026                 bar_width = width-gapX;
1027         }
1028
1029         /**
1030         * Gets the width of the drawing bar area
1031         * param width The width to get
1032         */
1033         int pColorBar :: getWidth ()
1034         {
1035                 return width;                   
1036         }
1037
1038         /**
1039         * Sets the height of the containing rectangle bar
1040         * param _h The height to set
1041         */
1042         void pColorBar ::  setBarHeight (int _h)
1043         {
1044                 bar_height = _h;
1045         }
1046
1047         /**
1048         * Gets the height of the containing rectangle bar
1049         * return bar_height The height to get
1050         */
1051         int pColorBar :: getBarHeight()
1052         {
1053                 return bar_height;
1054         }
1055
1056         /**
1057         * Sets the width of the containing rectangle bar
1058         * param _w The width to set
1059         */
1060         void pColorBar ::  setBarWidth (int _w)
1061         {
1062                 bar_width = _w;
1063         }
1064
1065         /**
1066         * Gets the width of the containing rectangle bar
1067         * return bar_width The width to get
1068         */
1069         int pColorBar :: getBarWidth ()
1070         {
1071                 return bar_width;
1072         }
1073
1074         /**
1075         * Sets the orientation of the color bar
1076         * param _orientation The orientation to set VERTICAL = false, HORIZONTAL = true
1077         */
1078         void pColorBar ::  setOrientation (bool _orientation)
1079         {
1080                 _logicalBar -> setOrientation(_orientation);
1081                 figure -> setBarOrientation (_orientation);
1082         }
1083
1084         /**
1085         * Gets the orientation of the color bar
1086         * return bar_orientation The bar orientation assigned
1087         */
1088         bool pColorBar :: getOrientation ()
1089         {
1090                 return _logicalBar->getOrientation();
1091         }
1092
1093         /**
1094         * Sets the collection of color points
1095         * param _points The new points to set, each one of data type pColorPoint ( xValue, wxColour_assigned)
1096         */
1097         void pColorBar ::  setPoints (std::vector<pColorPoint *> _points)
1098         {
1099                 _logicalBar->clearPoints();
1100                 showedColorPoints.clear();
1101                 _logicalBar->setColorPoints(_points);
1102                 //posible needed to update
1103         }
1104
1105         /**
1106         * Gets the last clickedX pixel coord inside the bar.
1107         * return clickedX The x-coord pixel value
1108         */
1109         int pColorBar :: getClickedX()
1110         {
1111                 return clickedX;
1112         }
1113
1114         /**
1115         * Sets the last clickedX pixel coord inside the bar.
1116         * param xCoordPixel The x-coord value to set
1117         */
1118         void pColorBar :: setClickedX(int xCoordPixel)
1119         {
1120                 clickedX = xCoordPixel;
1121         }
1122
1123         /**
1124         * Gets the last clickedY pixel coord inside the bar.
1125         * return clickedY The y-coord pixel value
1126         */
1127         int pColorBar :: getClickedY()
1128         {
1129                 return clickedY;
1130         }
1131
1132         /**
1133         * Sets the last clickedY pixel coord inside the bar.
1134         * param yCoordPixel The y-coord pixel value to set
1135         */
1136         void pColorBar :: setClickedY(int yCoordPixel)
1137         {
1138                 clickedY = yCoordPixel;
1139         }
1140
1141         /**
1142         * 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)
1143         * param x_Pixel The pixel value to convert into real value with respect to the x scale
1144         * return realX The real-x value corresponding to the xPixel
1145         */
1146         double pColorBar :: convertToRealValue ( int x_Pixel )
1147         {
1148                 /**
1149                 int newPixel = x_Pixel*(bar_width - deviceEndMargin - deviceStart_x)/(bar_width) ;
1150                 return newPixel*(maxX_represented_Tshow - minX_represented_Tshow)/(bar_width);
1151 */
1152                 return minX_represented_Tshow + ((x_Pixel-deviceStart_x) * (maxX_represented_Tshow - minX_represented_Tshow) ) /( bar_width-deviceEndMargin);           
1153         }
1154
1155         /**
1156         * 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)
1157         * param x_Pixel The pixel value to convert into real value with respect to the x scale
1158         * return realX The real-x value corresponding to the xPixel
1159         */
1160         int pColorBar :: convertToPixelValue (double x_real )
1161         {
1162                 return (int)( ((x_real - minX_represented_Tshow) * (bar_width-deviceEndMargin))/(maxX_represented_Tshow - minX_represented_Tshow) );            
1163         }
1164
1165         /**
1166         * Gets the selected color and updates the state of the okSelectedColor
1167         * return selectedColor Is the selected rbg color
1168         */
1169         wxColour pColorBar :: getSelectedColour()
1170         {
1171                 okSelectedColor = false;
1172                 wxColour col;
1173                 wxColourData data;
1174                 wxColourDialog dialog( GetParent(), &data);
1175
1176                 if ( dialog.ShowModal() == wxID_OK )
1177                 {
1178                         col = dialog.GetColourData().GetColour();
1179                         okSelectedColor = true;
1180                 }
1181                 return col;
1182         }
1183
1184         /**
1185         * Sets the represented minimum and maximunm values
1186         * param minRealValue The minimum represented value (real value)
1187         * param maxRealValue The maximum represented value (real value)
1188         */
1189         void pColorBar :: setRepresentedValues ( double minRealValue, double maxRealValue )
1190         {
1191                 temporalMinXToShow = (int)minRealValue;
1192                 temporalMaxXToShow = (int)maxRealValue;
1193
1194                 minX_represented_Tshow = (int)minRealValue;             
1195                 maxX_represented_Tshow = (int)maxRealValue;
1196                 _logicalBar->setMinValue(minX_represented_Tshow);
1197                 _logicalBar->setMaxValue(maxX_represented_Tshow);
1198         }
1199
1200         /**
1201         * Gets the data of the last point moving in a pColorPoint copy
1202         * return pointData Is a pColorPoint with the data of las moved color
1203         */
1204         pColorPoint * pColorBar :: getLastMovedColorPoint()
1205         {
1206                 pColorPoint * dataPoint = new pColorPoint ( 0, wxColor (0,0,0), false);
1207                 if (movingNodePoint)
1208                 {               
1209                         dataPoint ->setColor(movingNodePoint->getColor());
1210                         dataPoint ->setRealX(movingNodePoint->getRealX());
1211                 }
1212                 return dataPoint;
1213         }
1214
1215         /**
1216         * Sets the gap values for the color bar bitmap
1217         * param gap_x Gap in x
1218         * param gap_y Gap in y
1219         */
1220         void pColorBar :: setGapValues (int gap_x, int gap_y)
1221         {
1222                 gapX = gap_x;
1223                 gapY = gap_y;
1224         }
1225
1226         /**
1227         * Sets the degrade state of the color bar
1228         * param newState The degrade stare to set 
1229         */
1230         void pColorBar :: setDegradeState(bool newState)
1231         {
1232                 doingDegrade = newState;
1233         }
1234
1235         /**
1236         * Gets the degrade state of the color bar
1237         * return doingDegrade is the actual degrade state of the bar
1238         */
1239         bool pColorBar :: getDegradeState()
1240         {
1241                 return doingDegrade;
1242         }
1243
1244         /**
1245         * Sets the visible range of the bar and repaints the bar according to it, the min value must be less than the max value.
1246         * param minToShow Is the minimum value to show in the colorbar
1247         * param maxToShow Is the maximum value to show in the colorbar
1248         */
1249         void pColorBar :: setVisibleRange(int minToShow, int maxToShow)
1250         {
1251                 minX_represented_Tshow = minToShow;
1252                 maxX_represented_Tshow = maxToShow; 
1253                 viewingRange = true;
1254                 RefreshForce();
1255         }
1256
1257         /**
1258         * Sets the state of static or not for the limit color points
1259         * pamar areStatic Is the state to set for the limits
1260         */
1261         void pColorBar :: setStaticLimitsTo(bool areStatic)
1262         {
1263                 staticLimits = areStatic;
1264         }
1265
1266         /**
1267         * Gets the state of static or not for the limit color points
1268         * return staticLimits Is the state for limits
1269         */
1270         bool pColorBar :: getStaticLimits()
1271         {
1272                 return staticLimits;
1273         }
1274
1275         /**
1276         * Sets the device start drawing left-superior (pixel) start point and draws automatically the color bar
1277         * param deviceStart_x Pixel start for x-coord
1278         * param deviceStart_y Pixel start for y-coord
1279         */
1280         void pColorBar :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1281         {
1282                 deviceStart_x = devStart_x;
1283                 deviceStart_y = devStart_y;
1284                 if (getOrientation())
1285                         width += deviceStart_x;
1286                 else
1287                         height += deviceStart_y;
1288                 drawColorBar(true);
1289         }
1290
1291         /**
1292         * Clears the temporal color points of the list
1293         */
1294         void pColorBar :: clearTemporalColors()
1295         {
1296                 
1297         }
1298
1299         /**
1300         * Set active state 
1301         * param activeNow The new state
1302         */
1303         void pColorBar :: setActiveStateTo (bool activeNow)
1304         {
1305                 activeState = activeNow;
1306         }
1307         
1308         /**
1309         * Gets the active state of the bar
1310         *  return isActive The actual state
1311         */
1312         bool pColorBar :: isActive()
1313         {
1314                 return activeState;
1315         }
1316
1317         /**
1318         * Gets the real-x value to draw a vertical line
1319         * return realX_vertical_line The real x value for the vertical line
1320         */
1321         int     pColorBar :: getRealX_vertical_line()
1322         {
1323                 return realX_vertical_line;
1324         }
1325
1326         /**
1327         * Sets the real-x value to draw a vertical line
1328         * param realX_vertical_line The new real x value for the vertical line
1329         */
1330         void pColorBar :: setRealX_vertical_line(int newReal_x)
1331         {
1332                 realX_vertical_line = newReal_x;
1333         }
1334
1335         /**
1336         * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1337         * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1338         */
1339         void pColorBar :: setDeviceEndMargin(int newDeviceEnd_pixels)
1340         {
1341                 deviceEndMargin = newDeviceEnd_pixels;
1342         }
1343
1344         void pColorBar :: createAndSendEvent(WXTYPE theEventType)
1345         {
1346                 wxCommandEvent cevent( theEventType, GetId() );
1347                 cevent.SetEventObject( this );
1348                 GetEventHandler()->ProcessEvent( cevent );
1349         }
1350
1351         
1352         /**
1353                 Returns the number of points that the bar color has
1354         */
1355         int pColorBar::getColorPointsSize()
1356         {
1357                 return _logicalBar->getCount();
1358         }
1359
1360         /*
1361          Get the RGB values of the color point that is in the
1362          index given with respecto to the
1363         */
1364         void pColorBar::getDataAt(int index, double& x,int& red,int& green,int& blue)
1365         {
1366                 //******************************
1367                 _logicalBar->getDataAt(index, x, red, green, blue);
1368         }
1369
1370         /*
1371         * Sets the guide line color
1372         * param theNwGuideLineColor The color to set to the guideLineColor
1373         */
1374         void pColorBar :: setGuideLineColour(wxColour theNwGuideLineColor)
1375         {
1376                 guideLineColor = theNwGuideLineColor;
1377         }
1378
1379         /*
1380         * Gets the guide line color
1381         * return guideLineColor The color of the guideLine
1382         */
1383         wxColour pColorBar :: getGuideLineColour()
1384         {
1385                 return guideLineColor;
1386         }
1387
1388         /*
1389         * Sets the guide line color
1390         * param theNwGuideLineColor The color to set to the guideLineColor
1391         */
1392         void pColorBar :: setBackGroundColour(wxColour theNwBackColor)
1393         {
1394                 colourParent = theNwBackColor;
1395         }
1396
1397         /*
1398         * Gets the guide line color
1399         * return guideLineColor The color of the guideLine
1400         */
1401         wxColour pColorBar :: getBackGroundColour()
1402         {
1403                 return colourParent;
1404         }
1405
1406         /*
1407         * Gets the min value of the color bar
1408         */
1409         double  pColorBar :: getMinValue()
1410         {
1411                 return (double)minX_represented_Tshow;
1412         }
1413
1414         /*
1415         * Gets the max value of the color bar
1416         */
1417         double pColorBar :: getMaxValue()
1418         {
1419                 return (double)maxX_represented_Tshow;
1420         }
1421
1422
1423         void pColorBar :: updatePointsToDraw()
1424         {               
1425                 accumTemporalPoints = 0;                
1426                 if (_logicalBar->getCount()>0)
1427                 {
1428                         showedColorPoints.clear();
1429                         
1430                         int startIndex, endIndex;
1431                         _logicalBar -> getPointersToRangeLimits( showedColorPoints, startIndex, endIndex, minX_represented_Tshow, maxX_represented_Tshow );
1432                 
1433                         int internalCount = _logicalBar->getCount();                                            
1434                         std::deque <pColorPoint*>::iterator iterStart = showedColorPoints.begin( );
1435                         std::deque <pColorPoint*>::iterator iterEnd = showedColorPoints.end( );
1436                         
1437                         int pixelTmpStart = convertToPixelValue (minX_represented_Tshow);
1438                         int pixelTmpEnd = convertToPixelValue (maxX_represented_Tshow);
1439                         int initial_r, final_r, initial_g, final_g, initial_b, final_b, rectangle_width;
1440                         double realINI, realEND;
1441
1442                         bool includeTempStart = false;
1443                         bool includeTempEnd = false;
1444                         //-----------------Adding the first visible point of the list
1445                         if(showedColorPoints.size()>0)
1446                         {
1447                                 includeTempStart = (int)(showedColorPoints.front()->getRealX())>minX_represented_Tshow ;                                                                        
1448                                 includeTempEnd = (int)(showedColorPoints.back()->getRealX())<maxX_represented_Tshow ;                                                                   
1449                                 if( startIndex >= 0 )
1450                                 {
1451                                         if( startIndex == 0 )
1452                                         {
1453                                                 //The temporal showing point for the start should have the same color of the initial point in range at startIndex
1454                                                 _logicalBar -> getDataAt( startIndex, realINI, initial_r, initial_g, initial_b );
1455                                                 realINI = minX_represented_Tshow;
1456                                                 _logicalBar -> getDataAt( startIndex, realEND, final_r, final_g, final_b );                                     
1457                                         }
1458                                         else if( startIndex > 0 )
1459                                         {
1460                                                 _logicalBar -> getDataAt( startIndex-1, realINI, initial_r, initial_g, initial_b );
1461                                                 _logicalBar -> getDataAt( startIndex, realEND, final_r, final_g, final_b );
1462                                         }
1463                                         
1464                                         if( includeTempStart )
1465                                         {
1466                                                 int ini_pixelX = convertToPixelValue( realINI );
1467                                                 int end_pixelX = convertToPixelValue( realEND );
1468
1469                                                 rectangle_width = end_pixelX - ini_pixelX;                                              
1470                                                 
1471                                                 float m_scope_r = (float)(final_r-initial_r)/rectangle_width;
1472                                                 float m_scope_g = (float)(final_g-initial_g)/rectangle_width;
1473                                                 float m_scope_b = (float)(final_b-initial_b)/rectangle_width;           
1474
1475                                                 
1476                                                 float bRed = initial_r - m_scope_r*pixelTmpStart;
1477                                                 float bGreen = initial_g -  m_scope_g*pixelTmpStart;
1478                                                 float bBlue = initial_b - m_scope_b*pixelTmpStart;
1479
1480                                                 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));                          
1481                                         
1482                                                 accumTemporalPoints ++; 
1483                                         }
1484                                 }                               
1485                                 if( includeTempEnd && minX_represented_Tshow < maxX_represented_Tshow )
1486                                 {       
1487                                         if( internalCount>0 )
1488                                         {
1489                                                 if( endIndex == internalCount-1 )
1490                                                 {
1491                                                         _logicalBar -> getDataAt( endIndex, realINI, initial_r, initial_g, initial_b );
1492                                                         _logicalBar -> getDataAt( endIndex, realEND, final_r, final_g, final_b );
1493                                                         realEND = maxX_represented_Tshow;
1494                                                 }                                               
1495                                                 else
1496                                                 {
1497                                                         _logicalBar -> getDataAt( endIndex, realINI, initial_r, initial_g, initial_b );
1498                                                         _logicalBar -> getDataAt( endIndex+1, realEND, final_r, final_g, final_b );                                                     
1499                                                 }                                       
1500
1501                                                 int ini_pixelX = convertToPixelValue( realINI );
1502                                                 int end_pixelX = convertToPixelValue( realEND );
1503
1504                                                 rectangle_width = end_pixelX - ini_pixelX;                                              
1505                                                 
1506                                                 float m_scope_r = (float)(final_r-initial_r)/rectangle_width;
1507                                                 float m_scope_g = (float)(final_g-initial_g)/rectangle_width;
1508                                                 float m_scope_b = (float)(final_b-initial_b)/rectangle_width;           
1509                                                 
1510                                                 float bRed = initial_r - m_scope_r*pixelTmpEnd;
1511                                                 float bGreen = initial_g -  m_scope_g*pixelTmpEnd;
1512                                                 float bBlue = initial_b - m_scope_b*pixelTmpEnd;
1513                                                 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));                                
1514                                                 accumTemporalPoints ++;                         
1515                                         }                                       
1516                                 }
1517                         }
1518                         else
1519                         {
1520                                 if(_logicalBar->getCount()>0)
1521                                 {
1522                                         if ( minX_represented_Tshow > _logicalBar->getMaxAddedValue() )
1523                                         {
1524                                                 endIndex = _logicalBar->getCount()-1;
1525                                         }
1526                                         else if ( maxX_represented_Tshow < _logicalBar->getMinAddedValue() )
1527                                         {
1528                                                 endIndex = 0;
1529                                         }
1530
1531                                         _logicalBar -> getDataAt( endIndex, realINI, initial_r, initial_g, initial_b );
1532                                         _logicalBar -> getDataAt( endIndex, realEND, final_r, final_g, final_b );
1533                                         
1534                                         realINI = minX_represented_Tshow;
1535                                         realEND = maxX_represented_Tshow;
1536
1537                                         showedColorPoints.push_back( new pColorPoint ( realINI, wxColour( initial_r, initial_g, initial_b ), true));    
1538                                         accumTemporalPoints ++;         
1539                                         showedColorPoints.push_back( new pColorPoint ( realEND, wxColour( initial_r, initial_g, initial_b ), true));    
1540                                         accumTemporalPoints ++;         
1541                                 }
1542                         }
1543                 }               
1544                         
1545                 if ( !showedColorPoints.empty() )
1546                 {
1547                         startNode_show = showedColorPoints.front();
1548                         lastNode_show = showedColorPoints.back();
1549                 }
1550         }
1551