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