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