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