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