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