]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/mBarRange.cxx
#3144 creaMaracasVisu Bug New Normal - changeWx28to30
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / mBarRange.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 #include <wx/brush.h>
28 #include <wx/gdicmn.h>
29
30 #include "mBarRange.h"
31
32
33 //const wxEventType wxEVT_TSBAR = wxNewEventType();
34
35 DEFINE_EVENT_TYPE(wxEVT_TSBAR)
36 DEFINE_EVENT_TYPE(wxEVT_TSBAR_ACTUAL)
37 DEFINE_EVENT_TYPE(wxEVT_TSBAR_START)
38 DEFINE_EVENT_TYPE(wxEVT_TSBAR_END)
39 DEFINE_EVENT_TYPE(wxEVT_TSBAR_MOVED)
40 DEFINE_EVENT_TYPE(wxEVT_SELECTION_END)
41
42
43
44 //----------------------------------------------------------------------------
45 //EVENT TABLE
46 //----------------------------------------------------------------------------
47
48 IMPLEMENT_CLASS(mBarRange, wxScrolledWindow)
49 BEGIN_EVENT_TABLE(mBarRange, wxScrolledWindow)
50         EVT_PAINT (mBarRange::OnPaint)
51         EVT_SIZE  (mBarRange::OnSize)
52         EVT_MOTION (mBarRange::OnMouseMove)
53         EVT_RIGHT_DOWN (mBarRange :: onShowPopupMenu)
54         EVT_MENU(cntID_CHANGE_COLOR, mBarRange :: onChangePartColor)
55         EVT_MENU(cntID_ENABLE_ACTUAL, mBarRange :: onEnableRange_Actual)
56         EVT_MENU(cntID_MOVABLE_ACTUAL_BAR, mBarRange :: onMovable_ActualWithBar)
57
58         //
59         EVT_LEFT_DOWN( mBarRange :: onLeftClicDown)
60         EVT_LEFT_UP( mBarRange :: onLeftClickUp)
61
62         EVT_CHAR( mBarRange :: onKey )
63
64         //how to catch the new event (our event)
65         //EVT_COMMAND  (ID_MY_WINDOW, wxEVT_MY_EVENT, MyFrame::OnMyEvent)
66 END_EVENT_TABLE()
67
68
69 //----------------------------------------------------------------------------
70 //CONSTRUCTOR
71 //----------------------------------------------------------------------------
72
73 mBarRange::mBarRange(wxWindow *parent, int w, int h)
74 :wxScrolledWindow(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
75 {
76         acceptedClick           = true;
77         _bitmap_bar                     = NULL;
78         SetWidth (w);
79         SetHeight(h);
80         _initialPoint           = 0;
81         trianglesHalfWidth      = 5;
82         
83
84         // Setting the default parts colors
85         start_Colour            =       wxColour(1,0,255,254);
86         actual_Colour           =       wxColour(255,255,202);
87         end_Colour                      =       wxColour(0,0,255);
88         bar_Colour                      =       wxColour(255,0,255);
89         backgroundColor     =   parent ->GetBackgroundColour();
90         guideLineColor          =   wxColour(255,0,0);
91
92         //actual is in _start and end
93         //false means that it could be anywhere
94         _moveActualWithBar      =       false;
95         _in_rangeProperty       =       false;
96         _selectionMoveId        =       -1;
97         realX_vertical_line =   -1;
98         activeState                     =       false;
99         _actual=0;
100         deviceEndMargin = 0;
101
102         SetOrientation(true);
103         setIfWithActualDrawed(true);
104
105         b_popmenu.Append (cntID_CHANGE_COLOR, _("Change Color"), _("Changes the color of the selected part"));
106         b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
107         b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
108
109         SetSize(w,h);
110 }
111
112 //----------------------------------------------------------------------------
113 //DESTRUCTOR
114 //----------------------------------------------------------------------------
115
116 mBarRange::~mBarRange()
117 {
118 }
119 //---------------------------------------------------------------------------
120 //Draw bar: vertical or Horizontal
121 //---------------------------------------------------------------------------
122 void mBarRange::DrawBar()
123 {
124         //Horizontal
125         if(_orientation)
126         {
127                 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
128                 _bitmap_bar             = new wxBitmap(_w+1280,_h+100);
129                 //SIL//_bitmap_info     = new wxBitmap(_w+100+1280, _h+100);
130         }
131         //vertical
132         else
133         {
134                 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
135                 _bitmap_bar = new wxBitmap(_h+deviceStart_y+100,_w+1280);
136                 _bitmap_info = new wxBitmap(_h+deviceStart_y+100, _w+1280);
137         }
138 }
139 //----------------------------------------------------------------------------
140 //Getters & Setters
141 //----------------------------------------------------------------------------
142 //----------------------------------------------------------------------------
143 //the property condition on actual triangle
144 //----------------------------------------------------------------------------
145 bool mBarRange::GetInRangeProperty()
146 {
147         return _in_rangeProperty;
148 }
149 //----------------------------------------------------------------------------
150 void mBarRange::SetInRangeProperty(bool in)
151 {
152         _in_rangeProperty=in;
153 }
154 //----------------------------------------------------------------------------
155 //the information about the actual triangle in range or not, true if is between start and end
156 //----------------------------------------------------------------------------
157 bool mBarRange::IsActualInRange()
158 {
159         return ( _actual <= _end && _actual >= _start );
160 }
161
162 //----------------------------------------------------------------------------
163 // the position of the rectangle, vertical or horizontal
164 //----------------------------------------------------------------------------
165 bool mBarRange::GetOrientation()
166 {
167         return _orientation;
168 }
169 //-----------------------------------------------------------------------------
170 void mBarRange::SetOrientation(bool orientation)
171 {
172         if(_orientation)
173         {
174                 SetSize(_h,_w);
175         }
176         _orientation=orientation;
177
178 }
179 //----------------------------------------------------------------------------
180 // _start of the pixel rectangle
181 //----------------------------------------------------------------------------
182
183 int mBarRange::GetPixelStart()
184 {
185         return ((_start - _min)*(_w-deviceEndMargin))/(_max - _min);    
186 }
187 //----------------------------------------------------------------------------
188 // param i: value in pixels
189 //----------------------------------------------------------------------------
190 void mBarRange::SetPixelStart(int i)
191 {
192         _start = _min+((i - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
193         
194 }
195 //----------------------------------------------------------------------------
196 // _actual of the pixel rectangle
197 //----------------------------------------------------------------------------
198 int mBarRange::GetPixelActual()
199 {
200         return ((_actual - _min)*(_w-deviceEndMargin))/(_max - _min);
201 }
202 //----------------------------------------------------------------------------
203 // param i: value in pixels
204 //----------------------------------------------------------------------------
205 void mBarRange::SetPixelActual(int i)
206 {
207         _actual = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
208 }
209 //----------------------------------------------------------------------------
210 // _end of the pixel rectangle
211 //----------------------------------------------------------------------------
212 int mBarRange::GetPixelEnd()
213 {
214         return ((_end - _min)*(_w-deviceEndMargin))/(_max - _min);
215 }
216 //----------------------------------------------------------------------------
217 // param i: value in pixels to be converted to real logical value
218 //----------------------------------------------------------------------------
219 void mBarRange::SetPixelEnd(int i)
220 {
221         _end = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
222 }
223 //----------------------------------------------------------------------------
224 // Logical max of the triangle
225 //----------------------------------------------------------------------------
226
227 double mBarRange::GetMax()
228 {
229         return _max;
230 }
231
232 //----------------------------------------------------------------------------
233 void mBarRange::SetMax(double i)
234 {
235         _max=i;
236 }
237 //----------------------------------------------------------------------------
238 // Logical min of the triangle
239 //----------------------------------------------------------------------------
240
241 double mBarRange::GetMin()
242 {
243         return _min;
244 }
245
246 //----------------------------------------------------------------------------
247 void mBarRange::SetMin(double i)
248 {
249         _min=i;
250 }
251
252 //----------------------------------------------------------------------------
253 // pixel dimensions of the rectangle
254 //----------------------------------------------------------------------------
255
256 int mBarRange::GetWidth()
257 {
258         return _w;
259 }
260 //----------------------------------------------------------------------------
261 void mBarRange::SetWidth(int w)
262 {
263         _w=w;
264 }
265 //----------------------------------------------------------------------------
266 int mBarRange::GetHeight()
267 {
268         return _h;
269 }
270
271 //----------------------------------------------------------------------------
272 void mBarRange::SetHeight(int h)
273 {
274         _h=h;   
275 }
276
277 //----------------------------------------------------------------------------
278 // Logical  Start of the rectangle
279 //----------------------------------------------------------------------------
280
281 int mBarRange::filtreValue(int value)
282 {
283         if(value<_min)
284         {
285                 value = _min;
286         } else if (value>_max) {
287                 value = _max;
288         }
289         return value;
290 }
291
292 //----------------------------------------------------------------------------
293 int mBarRange::GetStart()
294 {
295         return _start;
296 }
297 //----------------------------------------------------------------------------
298 // param start: value real units
299 //----------------------------------------------------------------------------
300 void mBarRange::SetStart(int newstart)
301 {
302         _start = filtreValue(newstart);
303
304         if (_start>_end) 
305         { 
306                 _start=_end; 
307         }
308
309         if (_in_rangeProperty==true)
310         {
311                 if (_start>_actual)   { _start=_actual; }
312         }
313
314         RefreshForce(); 
315 }
316 //----------------------------------------------------------------------------
317 // Logical End of the rectangle
318 //----------------------------------------------------------------------------
319
320 int mBarRange::GetEnd()
321 {
322         return _end;
323 }
324 //----------------------------------------------------------------------------
325 // param end: value pixel units
326 //----------------------------------------------------------------------------
327 void mBarRange::SetEnd(int newend)
328 {
329         _end = filtreValue(newend);
330         if (_end<_start) { _end=_start; }
331         if (_in_rangeProperty==true)
332         {
333                 if (_end<_actual)   
334                 {
335                  _end=_actual; 
336                 } // _end
337         }
338         RefreshForce(); 
339 }
340 //----------------------------------------------------------------------------
341 // logical  Actual of the rectangle
342 //----------------------------------------------------------------------------
343 int mBarRange::GetActual()
344 {
345         return _actual;
346 }
347 //----------------------------------------------------------------------------
348 void mBarRange::SetActual(int newactual)
349 {
350         _actual = filtreValue(newactual);
351         if (_in_rangeProperty==true)
352         {
353                 if (_actual<_start) { _actual=_start; }         
354                 if (_actual>_end)   { _actual=_end; }
355         }
356         RefreshForce();
357 }
358
359 //----------------------------------------------------------------------------
360 //
361 //----------------------------------------------------------------------------
362 int mBarRange::GetTrianglesHalfWidth()
363 {
364         return trianglesHalfWidth;
365 }
366
367 //----------------------------------------------------------------------------
368 void mBarRange::SetTrianglesHalfWidth(int nwTriHalfWidth)
369 {
370         trianglesHalfWidth = nwTriHalfWidth;
371 }
372
373 void mBarRange::OnSize( wxSizeEvent &WXUNUSED(event) )
374 {
375         wxRect rectTotal = GetClientRect(); 
376         if(_orientation)
377         {               
378                 SetWidth( rectTotal.GetWidth() - deviceEndMargin );                     
379         }       else    {
380                 SetWidth( rectTotal.GetHeight() - deviceEndMargin);                             
381         }
382         _selectionMoveId = -1;
383         Refresh();              
384 }
385
386 //----------------------------------------------------------------------------
387
388 void mBarRange::Refresh(bool eraseBackground, const wxRect* rect)
389 {
390         wxScrolledWindow::Refresh(false);
391 }
392
393
394 //----------------------------------------------------------------------------
395 //Bar Methods
396 //----------------------------------------------------------------------------
397 void mBarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
398 {
399         if (_bitmap_bar!=NULL)
400         {
401                 //repaint rectangle
402                 if(_orientation)
403                 {
404                         RefreshHorizontalView();
405                         wxMemoryDC temp_dc;
406                         temp_dc.SelectObject( *_bitmap_bar );
407                         wxPaintDC dc( this );
408                         dc.Blit(deviceStart_x-(trianglesHalfWidth+2), deviceStart_y, _w-deviceEndMargin+2*(trianglesHalfWidth+2), _h, &temp_dc, 0, 0);
409                         //repaint info
410 //                      if (_visibleLables)
411 //                      {
412 //                              temp_dc.SelectObject( *_bitmap_info );                          
413 //                              dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+200, &temp_dc, deviceStart_x, deviceStart_y);
414 //                              //dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+60, &temp_dc, 0, 0);
415 //                      }
416         
417                 } else {
418                         RefreshVerticalView();
419                         wxMemoryDC temp_dc;
420                         temp_dc.SelectObject( *_bitmap_bar );
421                         wxPaintDC dc( this );                   
422 //                      dc.Blit(deviceStart_y,deviceStart_x, _h+deviceStart_y-deviceEndMargin,_w+deviceStart_x-deviceEndMargin, &temp_dc, 0, 0);        
423                         dc.Blit(deviceStart_y,deviceStart_x-(trianglesHalfWidth+2), _h,_w-deviceEndMargin+2*(trianglesHalfWidth+2), &temp_dc, 0, 0);    
424                         
425                         //repaint info
426 //                      if (_visibleLables)
427 //                      {
428 //                              temp_dc.SelectObject( *_bitmap_info );
429 //                              dc.Blit(0,_w, _h+deviceStart_y+200, _w+deviceStart_x+200-deviceEndMargin, &temp_dc, deviceStart_y,_w+deviceStart_x);
430 //                      }
431
432                 } 
433         } // _bitmap_bar
434 }
435
436
437 //----------------------------------------------------------------------------
438 //Repaint the bar if it is horizontal
439 //----------------------------------------------------------------------------
440 void mBarRange::RefreshHorizontalView()
441 {
442         wxPoint points[3];
443
444         //int largestNumberWidthInPixels = 15; // JPRx
445         int pxStart             = GetPixelStart();
446         int pxEnd               = GetPixelEnd();
447         int pxActual    = GetPixelActual();
448
449         int letterHeight= 9;
450         int barHeight   = 2*letterHeight;
451         int tempHeight  = _h-(6*letterHeight);  
452         
453         if (_visibleLables)
454         {
455                 barHeight       = (tempHeight>0)  ? tempHeight : (int) _h/2;
456         }
457         else
458                 barHeight       = _h;   
459
460         wxMemoryDC temp_dc;
461         temp_dc.SelectObject( *_bitmap_bar );
462
463         // Background of this widget
464         temp_dc.SetPen(wxPen( backgroundColor ));
465         temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID  ));
466         temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
467         temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID  ));
468         temp_dc.DrawLine(trianglesHalfWidth+2, 0, _w-deviceEndMargin, 0);
469         temp_dc.DrawLine(trianglesHalfWidth+2, barHeight, (_w-deviceEndMargin-trianglesHalfWidth-2), barHeight);
470         temp_dc.SetDeviceOrigin(trianglesHalfWidth+2,0);
471
472         // Filling the bar
473         temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID  ));
474         temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID  ));
475         temp_dc.DrawRectangle( pxStart , 0, pxEnd-pxStart, barHeight);
476
477         //  The Bar
478         if( _selectionMoveId==4 )
479         {
480                 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID  ));
481                 temp_dc.SetPen(wxPen(  wxColour(0,128,0),1,wxSOLID  ));
482         } else {
483                 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID  ));
484                 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID  ));
485         }
486         temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
487
488         // 2 Shadow Triangles: Start and End 
489         temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID  ));
490         temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID  ));
491         points[0].x= 0;
492         points[0].y= barHeight;
493         points[1].x= -trianglesHalfWidth-1;
494         points[1].y= 0;
495         points[2].x= trianglesHalfWidth+2;
496         points[2].y= 0;
497         temp_dc.DrawPolygon(3,points,pxStart,0);
498         temp_dc.DrawPolygon(3,points,pxEnd,0);
499
500         // 2 Triangles: Start and End 
501         points[1].x = -trianglesHalfWidth;      
502         points[2].x = trianglesHalfWidth;
503         
504         //first triangle (start)
505         if( _selectionMoveId == 1 )
506         {
507                 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID  ));
508                 temp_dc.SetPen(wxPen(  wxColour(0,128,0),1,wxSOLID  ));
509         } else {
510                 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID  ));
511                 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID  ));
512         }
513         temp_dc.DrawPolygon(3,points,pxStart,0);
514         //second triangle (end)
515         if( _selectionMoveId == 2 )
516         {
517                 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID  ));
518                 temp_dc.SetPen(wxPen(  wxColour(0,128,0),1,wxSOLID  ));
519         } else {
520                 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID  ));
521                 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID  ));
522         }
523         temp_dc.DrawPolygon(3,points,pxEnd,0);
524
525         if( withActualDrawed )
526         {
527                 // 1 Shadow Triangle: Actual
528                 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID  ));
529                 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID  ));
530                 points[1].x = -trianglesHalfWidth-1;
531                 points[2].x = trianglesHalfWidth+2;
532                 
533                 temp_dc.DrawPolygon(3,points,pxActual,0);
534
535                 // 1 Triangle: Actual (red)
536                 if( _selectionMoveId==3 )
537                 {
538                         temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID  ));
539                         temp_dc.SetPen(wxPen(  wxColour(0,128,0),1,wxSOLID  ));
540                 } else {
541                         temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID  ));
542                         temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID  ));
543                 }
544                 points[1].x = -trianglesHalfWidth;
545                 points[2].x = trianglesHalfWidth;
546                 temp_dc.DrawPolygon(3,points,pxActual,0);
547         }
548
549         if (realX_vertical_line!=-1)
550         {
551                 temp_dc.SetPen(wxPen(  guideLineColor,1,wxDOT ));
552                 int pixelX_guide = ((realX_vertical_line - _min)*(_w-deviceEndMargin))/(_max - _min) ; 
553                 temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, barHeight);
554         }
555
556         //Information Device drawing
557
558         if (_visibleLables)
559         {
560                 //temp_dc.SelectObject( *_bitmap_info );
561                 /*temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID  ));
562                 temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID  ));*/
563                 //temp_dc.DrawRectangle(deviceStart_x,_h+deviceStart_y,_w+deviceStart_x+40,_h+deviceStart_y+40);
564                 //temp_dc.DrawRectangle(0,_h,_w+40-deviceEndMargin,_h+40);
565
566                 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
567                 temp_dc.SetFont(font);
568                 temp_dc.SetTextForeground(*wxBLACK);
569
570                 //the **MIN** value, always at the same y level that corresponds to barHeight+1
571                 wxString text_min;
572 //              text_min<< GetMin();
573                 text_min.Printf(_T("%d"), (int)GetMin() );
574                 
575                 temp_dc.DrawText(text_min,0,barHeight+1);
576
577                 //the **MAX** value always at the same place
578                 wxString text_max;
579 //              text_max << GetMax();
580                 text_max.Printf(_T("%d"), (int)GetMax() );
581
582                 //As there is a margin of 40 extra most numbers (max) should be visibles
583 //              stringSize = temp_dc.GetTextExtent(text_max);
584         wxCoord tmpX,tmpY;
585                 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
586                 wxSize stringSize(tmpX,tmpY);
587                 
588                 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth())/*2*trianglesHalfWidth*/,barHeight+1);     
589                 
590                 //show logical values
591                 //show the **START TRIANGLE** value 
592                 wxString text_start;
593 //              text_start << GetStart();               
594                 text_start.Printf(_T("%d"), (int)GetStart() );
595
596                 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
597                 //show the **END TRIANGLE** value
598                 wxString text_end;
599 //              text_end << GetEnd();
600                 text_end.Printf(_T("%d"), (int)GetEnd() );
601
602 //              stringSize = temp_dc.GetTextExtent(text_end);
603                 temp_dc.GetTextExtent(text_end,&tmpX,&tmpY);
604                 stringSize.SetHeight(tmpY);
605                 stringSize.SetWidth(tmpX);
606                 temp_dc.DrawText(text_end, pxEnd-stringSize.GetWidth(),barHeight+3*letterHeight);
607                 if( withActualDrawed )
608                 {
609                         //show the actual value of actual
610                         wxString text_actual;
611 //                      text_actual << GetActual();
612                         text_actual.Printf(_T("%d"), (int)GetActual() );
613 //                      stringSize = temp_dc.GetTextExtent(text_actual);
614                         temp_dc.GetTextExtent(text_actual,&tmpX,&tmpY);
615                     stringSize.SetHeight(tmpY);
616                     stringSize.SetWidth(tmpX);
617                         temp_dc.DrawText(text_actual, pxActual-(stringSize.GetWidth()/2),barHeight+letterHeight);                       
618                 }                       
619         }
620 }
621
622 //----------------------------------------------------------------------------
623 //Repaint the bar if it is vertical
624 //----------------------------------------------------------------------------
625
626 void mBarRange::RefreshVerticalView()
627 {
628         wxPoint points[3];
629
630         int px1=GetPixelStart();
631         int px2=GetPixelEnd();
632         int px3=GetPixelActual();
633         int letterHeight = 9;
634         int panelHeight = 9*3+_w;
635
636         int barWidth;
637         if (_visibleLables)
638         {
639                 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
640         }
641         else
642                 barWidth = _w;  
643
644         wxMemoryDC temp_dc;
645         temp_dc.SelectObject( *_bitmap_bar );
646
647         // Background
648         temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID  ));
649         temp_dc.SetPen(wxPen( backgroundColor ));
650
651         temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
652         
653
654         temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID  ));
655         temp_dc.DrawLine(0,trianglesHalfWidth+2, 0, _w-deviceEndMargin);
656         temp_dc.DrawLine(barWidth, trianglesHalfWidth+2, barWidth, (_w-deviceEndMargin-trianglesHalfWidth-2));
657         temp_dc.SetDeviceOrigin(0,trianglesHalfWidth+2);
658
659         // Filling the bar
660         temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID  ));
661         temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID  ));
662         temp_dc.DrawRectangle( 0,px1 ,_h, px2-px1 );
663
664
665         //  The Bar
666                 if( _selectionMoveId==4 )
667         {
668                 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID  ));
669                 temp_dc.SetPen(wxPen(  wxColour(0,128,0),1,wxSOLID  ));
670         }
671         else
672         {
673                 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID  ));
674                 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID  ));
675         }
676         temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
677
678
679         // 2 Shadow Triangles: Start and End 
680         points[0].x     = _h;
681         points[0].y     = 0;
682         points[1].x     = 0;
683         points[1].y     = -trianglesHalfWidth-1;
684         points[2].x     = 0;
685         points[2].y     = trianglesHalfWidth+2;
686         temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID  ));
687         temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID  ));
688         temp_dc.DrawPolygon(3,points,0,px1);
689         temp_dc.DrawPolygon(3,points,0,px2);
690
691         // 2 Triangles: Start and End 
692         points[0].x     = _h;
693         points[0].y     = 0;
694         points[1].x     = 0;
695         points[1].y     = -trianglesHalfWidth;
696         points[2].x     = 0;
697         points[2].y     = trianglesHalfWidth;
698         //first triangle (start)
699         if( _selectionMoveId==1 )
700         {
701                 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID  ));
702                 temp_dc.SetPen(wxPen(  wxColour(0,128,0),1,wxSOLID  ));
703         }
704         else
705         {
706                 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID  ));
707                 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID  ));
708         }
709         temp_dc.DrawPolygon(3,points,0,px1);
710         //second triangle (end)
711         if( _selectionMoveId==2 )
712         {
713                 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID  ));
714                 temp_dc.SetPen(wxPen(  wxColour(0,128,0),1,wxSOLID  ));
715         }
716         else
717         {
718                 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID  ));
719                 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID  ));
720         }
721         temp_dc.DrawPolygon(3,points,0,px2);
722
723         if( withActualDrawed )
724         {
725                 // 1 Shadow Triangle: Actual
726                 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID  ));
727                 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID  ));
728                 points[0].x=_h;
729                 points[0].y=0;
730                 points[1].x=0;
731                 points[1].y=-trianglesHalfWidth-1;
732                 points[2].x=0;
733                 points[2].y=trianglesHalfWidth+2;
734                 temp_dc.DrawPolygon(3,points,0,px3);
735
736                 // 1 Triangle: Actual (red)
737                 points[0].x = _h;
738                 points[0].y = 0;
739                 points[1].x = 0;
740                 points[1].y = -trianglesHalfWidth;
741                 points[2].x = 0;
742                 points[2].y = trianglesHalfWidth;
743                 if( _selectionMoveId==3 )
744                 {
745                         temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID  ));
746                         temp_dc.SetPen(wxPen(  wxColour(0,128,0),1,wxSOLID  ));
747                 }
748                 else
749                 {
750                         temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID  ));
751                         temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID  ));
752                 }
753                 temp_dc.DrawPolygon(3,points,0,px3);
754         }
755
756         if (realX_vertical_line!=-1)
757         {
758                 temp_dc.SetPen(wxPen(  guideLineColor,1,wxDOT  ));
759                 int pixelX_guide = realX_vertical_line*_w/(_max-_min)+deviceStart_x; 
760                 temp_dc.DrawLine(0,pixelX_guide, _h, pixelX_guide);
761         }
762
763         //Information Device drawing
764         if (_visibleLables)
765         {
766                 /*temp_dc.SelectObject( *_bitmap_info );
767
768                 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID  ));
769                 temp_dc.SetPen(wxPen( backgroundColor ,1,wxSOLID  ));
770                 temp_dc.DrawRectangle(deviceStart_y,_w+deviceStart_x,_h+deviceStart_y+200,_w+deviceStart_x+200);
771 */
772
773                 temp_dc.SetBackgroundMode(wxTRANSPARENT);
774                 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
775                 temp_dc.SetFont(font);
776                 temp_dc.SetTextForeground(*wxBLACK);
777
778                 //show logical values
779                 //show the actual value of start
780                 wxString text_start;
781 //              text_start<<"Start:"<< GetStart();
782                 text_start.Printf(_T("%s %d"),_T("Start: "), (int)GetStart() );
783                 temp_dc.DrawText( text_start ,deviceStart_y, _w+deviceStart_x+letterHeight+1);
784                 //show the actual value of end
785                 wxString text_end;
786 //              text_end <<"End: "<<GetEnd();
787                 text_end.Printf(_T("%s %d"),_T("End: "), (int)GetEnd() );
788                 temp_dc.DrawText( text_end ,deviceStart_y,_w+deviceStart_x+letterHeight*2 );
789                 if( withActualDrawed )
790                 {
791                         //show the actual value of actual
792                         wxString text_actual;
793 //                      text_actual <<"Actual: " <<GetActual();
794                         text_actual.Printf(_T("%s %d"),_T("Actual: "), (int)GetActual() );
795                         temp_dc.DrawText( text_actual ,deviceStart_y,_w+deviceStart_x+letterHeight*3);
796                 }
797                 //the min value, always at the same place
798                 wxString text_min;
799 //              text_min<<"Min: " << GetMin();
800                 text_min.Printf(_T("%s %d"),_T("Min: "), (int)GetMin() );
801                 temp_dc.DrawText( text_min ,deviceStart_y,_w+deviceStart_x+3);
802                 //the max value always at the samen place
803                 wxString text_max;
804 //              text_max <<"Max: "<< GetMax();
805                 text_max.Printf(_T("%s %d"),_T("Max: "), (int)GetMax() );
806                 //toca calcular cuantol lo corremos
807                 temp_dc.DrawText(text_max,deviceStart_y,_w+deviceStart_x+43);           
808         }
809
810 }
811
812 //----------------------------------------------------------------------------
813 void mBarRange::RefreshForce()
814 {
815         Refresh();
816         Update();
817 }
818 //----------------------------------------------------------------------------
819 void mBarRange::OnMouseMove(wxMouseEvent& event )
820 {
821         if (activeState)
822         {
823                 wxPoint point = event.GetPosition();
824                 int barHeight;
825                 if (_orientation)
826                 {
827                         setClickedX(point.x);
828                         barHeight = point.y;
829                 }
830                 else
831                 {
832                         setClickedX(point.y);
833                         barHeight = point.x;
834                 }
835                 int logicClick = getLogicValueofPixel(clickedX);
836                         
837                 if( _selectionMoveId==-1 )
838                 {
839                         if (barHeight <=_h)
840                         {
841                                 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
842                                 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
843                                 bool in_actualT= withActualDrawed && (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
844                                 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
845
846                                 if( in_actualT )
847                                         _selectionMoveId = 3;
848                                 else if(in_StartTri)
849                                         _selectionMoveId = 1;  
850                                 else if( in_EndTri )
851                                         _selectionMoveId = 2;
852                                 else if( in_movingBar )
853                                         _selectionMoveId = 4;
854                         }
855                 }
856                 else
857                 {
858                         if(acceptedClick)
859                         {
860                                 //is in start triagle
861                                 if( _selectionMoveId ==1 && event.LeftIsDown())
862                                 {
863                                         bool validPos_StartTri = (logicClick<GetEnd() && logicClick >=_min);
864                                         if( validPos_StartTri && !_in_rangeProperty)
865                                         {       
866                                                 SetPixelStart(clickedX);
867                                                 RefreshForce();
868                                                 RefreshHorizontalView();
869                                                 //-------------------------------------------
870                                                 // Sending the event of start triangle moved
871                                                 //-------------------------------------------
872                                                 createAndSendEvent( wxEVT_TSBAR_START );
873                                         }
874                                         //start has to be less than actual
875                                         else if (validPos_StartTri && _in_rangeProperty)
876                                         {
877                                                 if(logicClick<=GetActual())
878                                                 {
879                                                         SetPixelStart(clickedX);
880                                                         RefreshForce();
881                                                 //      RefreshHorizontalView();
882                                                         //-------------------------------------------
883                                                         // Sending the event of start triangle moved
884                                                         //-------------------------------------------
885                                                 createAndSendEvent( wxEVT_TSBAR_START );
886                                                 }
887                                         }
888                                 } // _selectionMoveId == 1
889                                 //is in end triangle
890                                 else if( _selectionMoveId == 2 && event.LeftIsDown() )
891                                 {
892                                         bool validPos_EndTri = logicClick>GetStart()&& logicClick<=_max;  
893                                         if( validPos_EndTri && !_in_rangeProperty )
894                                         {                                       
895                                                 SetPixelEnd(clickedX);
896                                                 RefreshForce();
897         //                                      RefreshHorizontalView();        
898                                                 //-------------------------------------------
899                                                 //Sending the event of end triangle moved
900                                                 //-------------------------------------------
901                                                 createAndSendEvent( wxEVT_TSBAR_END );
902                                         }
903                                         //the end triangle cant be less than actual
904                                         else if( validPos_EndTri && _in_rangeProperty )
905                                         {
906                                                 if(logicClick>=GetActual())
907                                                 {
908                                                         SetPixelEnd(clickedX);
909                                                         RefreshForce();
910                                                 //      RefreshHorizontalView();
911                                                         //-------------------------------------------
912                                                         //Sending the event of end triangle moved
913                                                         //-------------------------------------------
914                                                         createAndSendEvent( wxEVT_TSBAR_END );
915                                                 }
916                                         }
917                                 } 
918                                 //is the actual triangle
919                                 else if( _selectionMoveId == 3 && event.LeftIsDown())
920                                 {
921                                         bool validPos_ActualTri=(logicClick<=_max) && (logicClick>=_min);
922                                         //is in actual triangle but it could be anywhere
923                                         if( validPos_ActualTri && !_in_rangeProperty )
924                                         {
925                                                 SetPixelActual(clickedX);
926                                                 RefreshForce();
927                                                 RefreshHorizontalView();
928                                                 //-------------------------------------------
929                                                 //Sending the event of actual triangle moved
930                                                 //-------------------------------------------
931                                                 createAndSendEvent( wxEVT_TSBAR_ACTUAL );       
932 //                                              createAndSendEvent( 98765 );
933                                         }
934                                         else if( validPos_ActualTri && _in_rangeProperty )
935                                         // the tringle in between start and end
936                                         {
937                                                 if( logicClick>=GetStart() && logicClick<=GetEnd())
938                                                 {
939                                                         SetPixelActual(clickedX);
940                                                         RefreshForce();
941                                                         RefreshHorizontalView();
942                                                         //-------------------------------------------
943                                                         //Sending the event of actual triangle moved
944                                                         //-------------------------------------------
945                                                         createAndSendEvent( wxEVT_TSBAR_ACTUAL );
946                                                 }
947                                         } 
948                                 } 
949                                 //is the bar
950                                 else if ( _selectionMoveId == 4 &&  event.LeftIsDown() )
951                                 {       
952                                         //FILE * f=fopen("E:/borrar/file.txt","a+");
953                                         if(_initialPoint == 0)
954                                         {
955                                                 _initialPoint = logicClick;
956                                                 logicInitial_start = GetStart(); 
957                                                 logicInitial_end = GetEnd();
958                                                 logicInitial_actual = GetActual();
959                                                 //SIL//fprintf(f,"\n\n---- Inicia draggin:\n  logicInitial_start:%d, logicInitial_end:%d,logicInitial_actual:%d \n", _initialPoint,logicInitial_start,logicInitial_end,logicInitial_actual);
960                                         }
961                                         int difference = logicClick -_initialPoint;
962                                         int next_end = difference + logicInitial_end;
963                                         int next_start = difference + logicInitial_start;
964                                         int next_actual = difference + logicInitial_actual;
965                                         
966                                         /*SIL//fprintf(f,"diff:%d, next_end%d, next_start%d, next_actual%d \n", difference,next_end,next_start,next_actual);
967                                         fclose(f);*/
968                                         
969                                         //if actual is not fixed to be in the middle
970                                         if( ((logicClick>next_start) && (logicClick<next_end)&& (next_end<=_max)&& (next_start>=_min)) && !_in_rangeProperty)
971                                         {
972                                                 SetStart(next_start);
973                                                 SetEnd(next_end);
974                                                 if( _moveActualWithBar )
975                                                 {
976                                                         SetActual (next_actual);
977                                                         //-------------------------------------------
978                                                         //Sending the event of actual triangle moved
979                                                         //-------------------------------------------
980                                                         createAndSendEvent( wxEVT_TSBAR_ACTUAL );
981                                                 }
982                                                 RefreshForce();
983                                                 RefreshHorizontalView();        
984                                                                                         
985                                                 //-------------------------------------------
986                                                 // Sending the event that the bar ahs being moved
987                                                 //-------------------------------------------
988                                                 createAndSendEvent( wxEVT_TSBAR_MOVED );
989                                                 //EED
990                                                 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
991                                                 createAndSendEvent( wxEVT_TSBAR_END );
992                                                 createAndSendEvent( wxEVT_TSBAR_START );
993                                         }
994                                         //if actual has to be between start and end
995                                         else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
996                                         {
997                                                 SetStart(next_start);
998                                                 SetEnd(next_end);
999                                                 if( _moveActualWithBar )
1000                                                 {
1001                                                         SetActual (next_actual);
1002                                                         //-------------------------------------------
1003                                                         //Sending the event of actual triangle moved
1004                                                         //-------------------------------------------
1005                                                         createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1006                                                 }
1007                                                 RefreshForce();
1008                                                 RefreshHorizontalView();        
1009                                                 
1010                                                 //-------------------------------------------
1011                                                 // Sending the event that the bar ahs being moved
1012                                                 //-------------------------------------------
1013                                                 createAndSendEvent( wxEVT_TSBAR_MOVED );
1014                                                 //EED
1015                                                 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1016                                                 createAndSendEvent( wxEVT_TSBAR_END );
1017                                                 createAndSendEvent( wxEVT_TSBAR_START );
1018                                         }
1019                                 }                       
1020                         }
1021                         if( !event.LeftIsDown())
1022                         {
1023                                 _initialPoint=0;
1024                                 _selectionMoveId = -1;
1025                                 RefreshForce();
1026                                 //-------------------------------------------
1027                                 //Sending a general event just because
1028                                 //-------------------------------------------
1029                                 //SIL//createAndSendEvent( wxEVT_TSBAR );
1030                                 createAndSendEvent(wxEVT_SELECTION_END);
1031                         }
1032                 }                               
1033         }       
1034 }
1035
1036
1037 /*
1038 * Sets the represented minimum and maximunm values
1039 * param minRealValue The minimum represented value (real value)
1040 * param maxRealValue The maximum represented value (real value)
1041 */
1042 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
1043 {
1044         _min = minRealValue;
1045         _max = maxRealValue;
1046         _start=_min;
1047         _end=_max;
1048 }
1049
1050 /*
1051 * Sets the property for viewing or not the bar labels information
1052 */
1053 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
1054 {
1055         _visibleLables = setVisibleLB;
1056 }
1057
1058 /*
1059         * Sets the property for viewing or not the bar labels information
1060         * return _visibleLables The state of visible labels or not 
1061         */
1062         bool mBarRange ::getIfVisibleLabels ()
1063         {
1064                 return _visibleLables;
1065         }
1066
1067         /**
1068         * Sets the device start drawing left-superior (pixel) start point 
1069         * param deviceStart_x Pixel start for x-coord
1070         * param deviceStart_y Pixel start for y-coord
1071         */
1072         void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1073         {
1074                 deviceStart_x = devStart_x;
1075                 deviceStart_y = devStart_y;
1076                 // For the initialization case
1077                 if (GetPixelEnd()<0)
1078                 {
1079                         if (_orientation)
1080                         {
1081                                 SetPixelStart(deviceStart_x);
1082                                 SetPixelEnd(_w+deviceStart_x);
1083                                 SetPixelActual(deviceStart_x);
1084                         }
1085                         else
1086                         {
1087                                 SetPixelStart(deviceStart_x);
1088                                 SetPixelEnd(_h+deviceStart_x);
1089                                 SetPixelActual(deviceStart_x);
1090                         }
1091                 }
1092                 DrawBar();
1093         }
1094         
1095         /**
1096         * Shows the popup menu 
1097         */
1098         void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1099         {
1100                 if (activeState)
1101                 {
1102                         bool validClic = false;
1103                         if (_orientation)
1104                         {
1105                                 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1106                         }
1107                         else
1108                         {
1109                                 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1110                         }
1111                         if (validClic)
1112                         {
1113                                 if(_orientation)
1114                                         setClickedX(event.GetX());
1115                                 else
1116                                         setClickedX(event.GetY());
1117
1118                                 if (getClickedX()<=_h)
1119                                 {                                               
1120                                         bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1121                                         bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1122                                         bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1123                                         bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1124
1125                                         if(in_StartTri)
1126                                                 _selectionMoveId = 1;
1127                                         else if( in_EndTri )
1128                                                 _selectionMoveId = 2;
1129                                         else if( in_actualT )
1130                                                 _selectionMoveId = 3;
1131                                         else if( in_movingBar )
1132                                                 _selectionMoveId = 4;
1133                                 }                               
1134                                 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1135                         }               
1136                 }
1137         }
1138         
1139         /**
1140         * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1141         * param & anEvent The wxCommandEvent actioned event 
1142         */
1143         void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1144         {
1145                 bool okSelectedColor = false;
1146                 wxColour selectedColour;
1147                 wxColourData data;
1148                 wxColourDialog dialog( GetParent(), &data);
1149
1150                 if ( dialog.ShowModal() == wxID_OK )
1151                 {
1152                         selectedColour = dialog.GetColourData().GetColour();
1153                         okSelectedColor = true;
1154                 }
1155                 if( okSelectedColor )
1156                 {
1157                         if (_selectionMoveId==1 )
1158                                 start_Colour = selectedColour;
1159                         else if (_selectionMoveId==2 )
1160                                 end_Colour = selectedColour;
1161                         else if( _selectionMoveId==3 )
1162                                 actual_Colour = selectedColour;
1163                         else if( _selectionMoveId==4 )
1164                                 bar_Colour = selectedColour;            
1165                 }
1166                 _selectionMoveId = -1;
1167         RefreshForce();
1168                 
1169         }
1170         
1171         /**
1172         * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1173         * param & anEvent The wxCommandEvent actioned event 
1174         */
1175         void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1176         {
1177                 if (!_in_rangeProperty)
1178                 {
1179                         if(IsActualInRange())
1180                         {
1181                                 SetInRangeProperty (true);
1182                                 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1183                         }
1184                 }
1185                 else
1186                 {
1187                         SetInRangeProperty (false);
1188                         b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));                 
1189                 }
1190         }
1191
1192         /**
1193         * Reacts to the cntID_MOVABLE_ACTUAL_BAR wxCommandEvent by enabling or disabling the property of moving the actual triangle with the bar, just when it is inside of it.
1194         * param & anEvent The wxCommandEvent actioned event 
1195         */
1196         void  mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1197         {
1198                 if (_moveActualWithBar )
1199                 {
1200                         _moveActualWithBar = false;
1201                         b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1202                 }
1203                 else
1204                 {
1205                         if(IsActualInRange())
1206                         {
1207                                 _moveActualWithBar = true;
1208                                 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1209                         }
1210                 }
1211         }
1212
1213                 /*
1214         * Set active state 
1215         * param activeNow The new state
1216         */
1217         void mBarRange :: setActiveStateTo (bool activeNow)
1218         {
1219                 activeState = activeNow;
1220         }
1221         
1222         /*
1223         * Gets the active state of the bar
1224         *  return activeState The actual state
1225         */
1226         bool mBarRange :: isActive()
1227         {
1228                 return activeState;
1229         }
1230
1231         /*
1232         * Gets the real-x value to draw a vertical line
1233         * return realX_vertical_line The real x value for the vertical line
1234         */
1235         int     mBarRange :: getRealX_vertical_line()
1236         {
1237                 return realX_vertical_line;
1238         }
1239
1240         /*
1241         * Sets the real-x value to draw a vertical line
1242         * param newReal_x The new real x value for the vertical line
1243         */
1244         void mBarRange :: setRealX_vertical_line(int newReal_x)
1245         {
1246                 realX_vertical_line = newReal_x;
1247         }
1248
1249         /*
1250         * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1251         * return deviceEndMargin The value asigned to the right margin
1252         */
1253         int     mBarRange :: getDeviceEndX()
1254         {
1255                 return deviceEndMargin;
1256         }
1257
1258         /*
1259         * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1260         * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1261         */
1262         void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1263         {
1264                 deviceEndMargin = newDeviceEnd_pixels;
1265         }
1266
1267         /*
1268         * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1269         * return clickedX The x-coord pixel value
1270         */
1271         int mBarRange :: getClickedX()
1272         {
1273                 return clickedX;
1274         }
1275
1276         /*
1277         * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1278         * param nwClickX The x-coord pixel value
1279         */
1280         void mBarRange :: setClickedX(int nwClickX)
1281         {
1282                 clickedX = nwClickX;
1283         }
1284
1285
1286                 /*
1287         * Gets the start porcentage with respect to the represented values of the bar
1288         * return The porcentage represented by the start  showing point
1289         */
1290         float mBarRange :: getStartShowPorcentage()
1291         {
1292                 return (float)( 1+(_start - _max)/(_max-_min));
1293         }
1294
1295         /*
1296         * Gets the end porcentage with respect to the represented values of the bar
1297         * return The porcentage represented by the end showing point
1298         */
1299         float mBarRange :: getEndShowPorcentage()
1300         {
1301                 return (float) (1+(_end - _max)/(_max-_min));
1302         }
1303
1304         /*
1305         * Gets the actual porcentage with respect to the represented values of the bar
1306         * return The porcentage represented by the actual  showing point
1307         */
1308         float mBarRange :: getActualShowPorcentage()
1309         {
1310                 return (float) (1+(_actual - _max)/(_max-_min));
1311         }
1312
1313         int mBarRange :: getLogicValueofPixel(int thePixel)
1314         {
1315                 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1316         }
1317
1318         /*
1319         * Sets the condition for knowing if the actual triangle is being drawed or not
1320         * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1321         */
1322         void mBarRange :: setIfWithActualDrawed(bool drawActual)
1323         {
1324                 if(!withActualDrawed && drawActual)
1325                 {       
1326                         b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1327                         b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));               
1328                 }
1329                 else if (withActualDrawed && !drawActual)
1330                 {
1331                         b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1332                         b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1333                 }
1334                 withActualDrawed = drawActual;
1335                 Refresh();      
1336         }
1337
1338         /*
1339         * Gets the condition for knowing if the actual triangle is being drawed or not
1340         * return withActualDrawed The condition for drawing or not the actual control
1341         */
1342         bool mBarRange :: getIfWithActualDrawed()
1343         {
1344                 return withActualDrawed;
1345         }
1346
1347         void mBarRange::createAndSendEvent(WXTYPE theEventType)
1348         {
1349                 wxCommandEvent cevent( theEventType, GetId() );
1350                 cevent.SetEventObject( this );
1351                 GetEventHandler()->ProcessEvent( cevent );
1352         }
1353
1354         /*
1355         * Sets the background color od the bar
1356         * theColor The color to set to the backgroundColor
1357         */
1358         void mBarRange :: setBackgroundColor(wxColour theColor)
1359         {
1360                 backgroundColor = theColor;
1361         }
1362
1363         /*
1364         * Sets the guide line color
1365         * param theNwGuideLineColor The color to set to the guideLineColor
1366         */
1367         void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1368         {
1369                 guideLineColor = theNwGuideLineColor;
1370         }
1371
1372         /*
1373         * Gets the guide line color
1374         * return guideLineColor The color of the guideLine
1375         */
1376         wxColour mBarRange :: getGuideLineColour()
1377         {
1378                 return guideLineColor;
1379         }
1380
1381         void  mBarRange ::onLeftClicDown(wxMouseEvent& event )
1382         {
1383                 acceptedClick = true;           
1384                 SetFocus();
1385         }
1386
1387         void  mBarRange::onLeftClickUp(wxMouseEvent& event )
1388         {       
1389                 acceptedClick = false;
1390         }
1391
1392 //EED 20 Juillet 2011
1393         void  mBarRange::onKey(wxKeyEvent& event)
1394         {
1395                 int step=0;
1396                 if ((event.GetKeyCode()==314) || (event.GetKeyCode()==317))
1397                 {
1398                         step=-1;
1399                 }
1400                 
1401                 if ((event.GetKeyCode()==315) || (event.GetKeyCode()==316))
1402                 {
1403                         step=1;
1404                 }
1405                 
1406                 if (step!=0)
1407                 {
1408                         if (_selectionMoveId == 1) // start
1409                         {
1410                                 SetStart(GetStart()+step);
1411                                 createAndSendEvent( wxEVT_TSBAR_START );
1412                         }
1413                         
1414                         if (_selectionMoveId == 2) // end
1415                         {
1416                                 SetEnd(GetEnd()+step);
1417                                 createAndSendEvent( wxEVT_TSBAR_END );
1418                         }
1419                 
1420                         if (_selectionMoveId == 3) // actual
1421                         {
1422                                 SetActual(GetActual()+step);
1423                                 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1424                         }
1425                 
1426                         if (_selectionMoveId == 4) // bar
1427                         {
1428                                 if (( GetStart()+step>=_min ) && ( GetEnd()+step<=_max ))
1429                                 {
1430                                         SetStart(GetStart()+step);
1431                                         SetEnd(GetEnd()+step);
1432                                         if (_moveActualWithBar) 
1433                                         { 
1434                                                 SetActual(GetActual()+step); 
1435                                         }
1436                                         createAndSendEvent( wxEVT_TSBAR_START );
1437                                         createAndSendEvent( wxEVT_TSBAR_END );
1438                                         createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1439                                         createAndSendEvent( wxEVT_TSBAR_MOVED );
1440                                 } // Start>_min  &&  End<_max
1441                         }// _selectionMoveId == 4
1442                 } // step
1443         }
1444
1445