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