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