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