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