1 //----------------------------------------------------------------------------
5 //const wxEventType wxEVT_TSBAR = wxNewEventType();
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)
16 //----------------------------------------------------------------------------
18 //----------------------------------------------------------------------------
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)
31 EVT_LEFT_DOWN( mBarRange :: onLeftClicDown)
32 EVT_LEFT_UP( mBarRange :: onLeftClickUp)
34 //how to catch the new event (our event)
35 //EVT_COMMAND (ID_MY_WINDOW, wxEVT_MY_EVENT, MyFrame::OnMyEvent)
39 //----------------------------------------------------------------------------
41 //----------------------------------------------------------------------------
43 mBarRange::mBarRange(wxWindow *parent, int w, int h)
44 :wxScrolledWindow(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
51 trianglesHalfWidth = 5;
53 wxColour start_Colour;
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);
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;
74 setIfWithActualDrawed(true);
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"));
83 //----------------------------------------------------------------------------
85 //----------------------------------------------------------------------------
87 mBarRange::~mBarRange()
90 //---------------------------------------------------------------------------
91 //Draw bar: vertical or Horizontal
92 //---------------------------------------------------------------------------
93 void mBarRange::DrawBar()
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);
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);
110 //----------------------------------------------------------------------------
112 //----------------------------------------------------------------------------
113 //----------------------------------------------------------------------------
114 //the property condition on actual triangle
115 //----------------------------------------------------------------------------
116 bool mBarRange::GetInRangeProperty()
118 return _in_rangeProperty;
120 //----------------------------------------------------------------------------
121 void mBarRange::SetInRangeProperty(bool in)
123 _in_rangeProperty=in;
125 //----------------------------------------------------------------------------
126 //the information about the actual triangle in range or not, true if is between start and end
127 //----------------------------------------------------------------------------
128 bool mBarRange::IsActualInRange()
130 return ( _actual <= _end && _actual >= _start );
133 //----------------------------------------------------------------------------
134 // the position of the rectangle, vertical or horizontal
135 //----------------------------------------------------------------------------
136 bool mBarRange::GetOrientation()
140 //-----------------------------------------------------------------------------
141 void mBarRange::SetOrientation(bool orientation)
147 _orientation=orientation;
150 //----------------------------------------------------------------------------
151 // _start of the pixel rectangle
152 //----------------------------------------------------------------------------
154 int mBarRange::GetPixelStart()
156 return ((_start - _min)*(_w-deviceEndMargin))/(_max - _min);
158 //----------------------------------------------------------------------------
159 // param i: value in pixels
160 //----------------------------------------------------------------------------
161 void mBarRange::SetPixelStart(int i)
163 _start = _min+((i - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
166 //----------------------------------------------------------------------------
167 // _actual of the pixel rectangle
168 //----------------------------------------------------------------------------
169 int mBarRange::GetPixelActual()
171 return ((_actual - _min)*(_w-deviceEndMargin))/(_max - _min);
173 //----------------------------------------------------------------------------
174 // param i: value in pixels
175 //----------------------------------------------------------------------------
176 void mBarRange::SetPixelActual(int i)
178 _actual = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
180 //----------------------------------------------------------------------------
181 // _end of the pixel rectangle
182 //----------------------------------------------------------------------------
183 int mBarRange::GetPixelEnd()
185 return ((_end - _min)*(_w-deviceEndMargin))/(_max - _min);
187 //----------------------------------------------------------------------------
188 // param i: value in pixels to be converted to real logical value
189 //----------------------------------------------------------------------------
190 void mBarRange::SetPixelEnd(int i)
192 _end = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
194 //----------------------------------------------------------------------------
195 // Logical max of the triangle
196 //----------------------------------------------------------------------------
198 double mBarRange::GetMax()
203 //----------------------------------------------------------------------------
204 void mBarRange::SetMax(double i)
208 //----------------------------------------------------------------------------
209 // Logical min of the triangle
210 //----------------------------------------------------------------------------
212 double mBarRange::GetMin()
217 //----------------------------------------------------------------------------
218 void mBarRange::SetMin(double i)
223 //----------------------------------------------------------------------------
224 // pixel dimensions of the rectangle
225 //----------------------------------------------------------------------------
227 int mBarRange::GetWidth()
231 //----------------------------------------------------------------------------
232 void mBarRange::SetWidth(int w)
236 //----------------------------------------------------------------------------
237 int mBarRange::GetHeight()
242 //----------------------------------------------------------------------------
243 void mBarRange::SetHeight(int h)
248 //----------------------------------------------------------------------------
249 // Logical Start of the rectangle
250 //----------------------------------------------------------------------------
252 int mBarRange::GetStart()
257 //----------------------------------------------------------------------------
258 // param start: value real units
259 //----------------------------------------------------------------------------
260 void mBarRange::SetStart(int newstart)
267 //----------------------------------------------------------------------------
268 // Logical End of the rectangle
269 //----------------------------------------------------------------------------
271 int mBarRange::GetEnd()
275 //----------------------------------------------------------------------------
276 // param end: value pixel units
277 //----------------------------------------------------------------------------
278 void mBarRange::SetEnd(int nwend)
285 //----------------------------------------------------------------------------
286 // logical Actual of the rectangle
287 //----------------------------------------------------------------------------
288 int mBarRange::GetActual()
292 //----------------------------------------------------------------------------
293 void mBarRange::SetActual(int actual)
297 else if (actual>_max)
303 //----------------------------------------------------------------------------
305 //----------------------------------------------------------------------------
306 int mBarRange::GetTrianglesHalfWidth()
308 return trianglesHalfWidth;
310 //----------------------------------------------------------------------------
311 void mBarRange::SetTrianglesHalfWidth(int nwTriHalfWidth)
313 trianglesHalfWidth = nwTriHalfWidth;
316 void mBarRange::OnSize( wxSizeEvent &WXUNUSED(event) )
318 wxRect rectTotal = GetClientRect();
321 SetWidth( rectTotal.GetWidth() - deviceEndMargin );
325 SetWidth( rectTotal.GetHeight() - deviceEndMargin);
327 _selectionMoveId = -1;
331 //----------------------------------------------------------------------------
333 void mBarRange::Refresh(bool eraseBackground, const wxRect* rect)
337 //ff=fopen ("c:/temp/xxx.txt", "a+");
338 //fprintf( ff , "mBarRange :: Refresh 01\n" );
341 wxScrolledWindow::Refresh(false);
345 //ff=fopen ("c:/temp/xx.txt", "a+");
346 //fprintf( ff , "mBarRange :: Refresh 02\n" );
351 //----------------------------------------------------------------------------
353 //----------------------------------------------------------------------------
354 void mBarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
359 //ff=fopen ("c:/temp/xx.txt", "a+");
360 //fprintf( ff , "pColorBar :: OnPaint 01\n" );
363 if (_bitmap_bar!=NULL){
367 RefreshHorizontalView();
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);
373 // if (_visibleLables)
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);
381 RefreshVerticalView();
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);
389 // if (_visibleLables)
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);
400 //ff=fopen ("c:/temp/xx.txt", "a+");
401 //fprintf( ff , "pColorBar :: OnPaint 02\n" );
406 //----------------------------------------------------------------------------
407 //Repaint the bar if it is horizontal
408 //----------------------------------------------------------------------------
409 void mBarRange::RefreshHorizontalView()
414 //ff=fopen ("c:/temp/xxx.txt", "a+");
415 //fprintf( ff , "mBarRange :: RefreshHorizontalView 01\n" );
420 //int largestNumberWidthInPixels = 15; // JPRx
421 int pxStart=GetPixelStart();
422 int pxEnd=GetPixelEnd();
423 int pxActual=GetPixelActual();
426 int letterHeight = 9;
427 int barHeight = 2*letterHeight;
428 int tempHeight = _h-(6*letterHeight);
433 barHeight = (tempHeight>0) ? tempHeight : (int) _h/2;
439 temp_dc.SelectObject( *_bitmap_bar );
442 // Background of this widget
445 temp_dc.SetPen(wxPen( backgroundColor ));
446 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
448 temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
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);
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);
464 if( _selectionMoveId==4 )
466 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
467 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
471 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
472 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
474 temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
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 ));
480 points[0].y= barHeight;
481 points[1].x= -trianglesHalfWidth-1;
483 points[2].x= trianglesHalfWidth+2;
485 temp_dc.DrawPolygon(3,points,pxStart,0);
486 temp_dc.DrawPolygon(3,points,pxEnd,0);
488 // 2 Triangles: Start and End
489 points[1].x = -trianglesHalfWidth;
490 points[2].x = trianglesHalfWidth;
492 //first triangle (start)
493 if( _selectionMoveId == 1 )
495 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
496 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
500 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
501 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
503 temp_dc.DrawPolygon(3,points,pxStart,0);
504 //second triangle (end)
505 if( _selectionMoveId == 2 )
507 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
508 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
512 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
513 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
515 temp_dc.DrawPolygon(3,points,pxEnd,0);
517 if( withActualDrawed )
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;
525 temp_dc.DrawPolygon(3,points,pxActual,0);
527 // 1 Triangle: Actual (red)
528 if( _selectionMoveId==3 )
530 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
531 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
535 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
536 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
538 points[1].x = -trianglesHalfWidth;
539 points[2].x = trianglesHalfWidth;
540 temp_dc.DrawPolygon(3,points,pxActual,0);
543 if (realX_vertical_line!=-1)
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);
550 //Information Device drawing
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);
560 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
561 temp_dc.SetFont(font);
562 temp_dc.SetTextForeground(*wxBLACK);
565 //the **MIN** value, always at the same y level that corresponds to barHeight+1
567 // text_min<< GetMin();
568 text_min.Printf(_T("%d"), (int)GetMin() );
570 temp_dc.DrawText(text_min,0,barHeight+1);
572 //the **MAX** value always at the same place
574 // text_max << GetMax();
575 text_max.Printf(_T("%d"), (int)GetMax() );
577 //As there is a margin of 40 extra most numbers (max) should be visibles
578 // stringSize = temp_dc.GetTextExtent(text_max);
580 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
581 wxSize stringSize(tmpX,tmpY);
583 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth())/*2*trianglesHalfWidth*/,barHeight+1);
585 //show logical values
586 //show the **START TRIANGLE** value
588 // text_start << GetStart();
589 text_start.Printf(_T("%d"), (int)GetStart() );
591 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
592 //show the **END TRIANGLE** value
594 // text_end << GetEnd();
595 text_end.Printf(_T("%d"), (int)GetEnd() );
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 )
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);
617 //ff=fopen ("c:/temp/xxx.txt", "a+");
618 //fprintf( ff , "mBarRange :: RefreshHorizontalView 02\n" );
622 //----------------------------------------------------------------------------
623 //Repaint the bar if it is vertical
624 //----------------------------------------------------------------------------
626 void mBarRange::RefreshVerticalView()
631 //ff=fopen ("c:/temp/xxx.txt", "a+");
632 //fprintf( ff , "mBarRange :: RefreshVerticalView 01\n" );
636 int px1=GetPixelStart();
637 int px2=GetPixelEnd();
638 int px3=GetPixelActual();
639 int letterHeight = 9;
640 int panelHeight = 9*3+_w;
645 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
651 temp_dc.SelectObject( *_bitmap_bar );
654 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
655 temp_dc.SetPen(wxPen( backgroundColor ));
657 temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
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);
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 );
672 if( _selectionMoveId==4 )
674 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
675 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
679 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
680 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
682 temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
685 // 2 Shadow Triangles: Start and End
689 points[1].y=-trianglesHalfWidth-1;
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);
697 // 2 Triangles: Start and End
701 points[1].y=-trianglesHalfWidth;
703 points[2].y=trianglesHalfWidth;
704 //first triangle (start)
705 if( _selectionMoveId==1 )
707 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
708 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
712 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
713 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
715 temp_dc.DrawPolygon(3,points,0,px1);
716 //second triangle (end)
717 if( _selectionMoveId==2 )
719 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
720 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
724 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
725 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
727 temp_dc.DrawPolygon(3,points,0,px2);
729 if( withActualDrawed )
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 ));
737 points[1].y=-trianglesHalfWidth-1;
739 points[2].y=trianglesHalfWidth+2;
740 temp_dc.DrawPolygon(3,points,0,px3);
742 // 1 Triangle: Actual (red)
746 points[1].y = -trianglesHalfWidth;
748 points[2].y = trianglesHalfWidth;
749 if( _selectionMoveId==3 )
751 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
752 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
756 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
757 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
759 temp_dc.DrawPolygon(3,points,0,px3);
762 if (realX_vertical_line!=-1)
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);
769 //Information Device drawing
772 /*temp_dc.SelectObject( *_bitmap_info );
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);
779 temp_dc.SetBackgroundMode(wxTRANSPARENT);
780 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
781 temp_dc.SetFont(font);
782 temp_dc.SetTextForeground(*wxBLACK);
784 //show logical values
785 //show the actual value of 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
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 )
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);
803 //the min value, always at the same place
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
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);
818 //----------------------------------------------------------------------------
819 void mBarRange::RefreshForce()
824 //----------------------------------------------------------------------------
825 void mBarRange::OnMouseMove(wxMouseEvent& event )
829 //ff=fopen ("c:/temp/xxx.txt", "a+");
830 //fprintf( ff , "mBarRange :: OnMouseMove 01\n" );
833 //int px1=GetPixelStart(); // JPRx
834 //int px2=GetPixelEnd(); // JPRx
835 //int px3=GetPixelActual(); // JPRx
838 wxPoint point = event.GetPosition();
842 setClickedX(point.x);
847 setClickedX(point.y);
850 int logicClick = getLogicValueofPixel(clickedX);
852 if( _selectionMoveId==-1 )
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);
862 _selectionMoveId = 3;
864 _selectionMoveId = 1;
866 _selectionMoveId = 2;
867 else if( in_movingBar )
868 _selectionMoveId = 4;
875 //is in start triagle
876 if( _selectionMoveId ==1 && event.LeftIsDown())
878 bool validPos_StartTri = (logicClick<GetEnd() && logicClick >=_min);
879 if( validPos_StartTri && !_in_rangeProperty)
881 SetPixelStart(clickedX);
883 RefreshHorizontalView();
884 //-------------------------------------------
885 // Sending the event of start triangle moved
886 //-------------------------------------------
887 createAndSendEvent( wxEVT_TSBAR_START );
889 //start has to be less than actual
890 else if (validPos_StartTri && _in_rangeProperty)
892 if(logicClick<=GetActual())
894 SetPixelStart(clickedX);
896 // RefreshHorizontalView();
897 //-------------------------------------------
898 // Sending the event of start triangle moved
899 //-------------------------------------------
900 createAndSendEvent( wxEVT_TSBAR_START );
903 } // _selectionMoveId == 1
905 else if( _selectionMoveId == 2 && event.LeftIsDown() )
907 bool validPos_EndTri = logicClick>GetStart()&& logicClick<=_max;
908 if( validPos_EndTri && !_in_rangeProperty )
910 SetPixelEnd(clickedX);
912 // RefreshHorizontalView();
913 //-------------------------------------------
914 //Sending the event of end triangle moved
915 //-------------------------------------------
916 createAndSendEvent( wxEVT_TSBAR_END );
918 //the end triangle cant be less than actual
919 else if( validPos_EndTri && _in_rangeProperty )
921 if(logicClick>=GetActual())
923 SetPixelEnd(clickedX);
925 // RefreshHorizontalView();
926 //-------------------------------------------
927 //Sending the event of end triangle moved
928 //-------------------------------------------
929 createAndSendEvent( wxEVT_TSBAR_END );
933 //is the actual triangle
934 else if( _selectionMoveId == 3 && event.LeftIsDown())
936 bool validPos_ActualTri=(logicClick<=_max) && (logicClick>=_min);
937 //is in actual triangle but it could be anywhere
938 if( validPos_ActualTri && !_in_rangeProperty )
940 SetPixelActual(clickedX);
942 RefreshHorizontalView();
943 //-------------------------------------------
944 //Sending the event of actual triangle moved
945 //-------------------------------------------
946 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
947 // createAndSendEvent( 98765 );
948 printf("EED creaMaracasVisu mBarRange::OnMouseMove XXXXXXX \n");
951 else if( validPos_ActualTri && _in_rangeProperty )
952 // the tringle in between start and end
954 if( logicClick>=GetStart() && logicClick<=GetEnd())
956 SetPixelActual(clickedX);
958 RefreshHorizontalView();
959 //-------------------------------------------
960 //Sending the event of actual triangle moved
961 //-------------------------------------------
962 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
967 else if ( _selectionMoveId == 4 && event.LeftIsDown() )
969 //FILE * f=fopen("E:/borrar/file.txt","a+");
970 if(_initialPoint == 0)
972 _initialPoint = logicClick;
973 logicInitial_start = GetStart();
974 logicInitial_end = GetEnd();
975 logicInitial_actual = GetActual();
976 //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);
978 int difference = logicClick -_initialPoint;
979 int next_end = difference + logicInitial_end;
980 int next_start = difference + logicInitial_start;
981 int next_actual = difference + logicInitial_actual;
983 /*SIL//fprintf(f,"diff:%d, next_end%d, next_start%d, next_actual%d \n", difference,next_end,next_start,next_actual);
986 //if actual is not fixed to be in the middle
987 if( ((logicClick>next_start) && (logicClick<next_end)&& (next_end<=_max)&& (next_start>=_min)) && !_in_rangeProperty)
989 SetStart(next_start);
991 if( _moveActualWithBar )
993 SetActual (next_actual);
994 //-------------------------------------------
995 //Sending the event of actual triangle moved
996 //-------------------------------------------
997 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1000 RefreshHorizontalView();
1002 //-------------------------------------------
1003 // Sending the event that the bar ahs being moved
1004 //-------------------------------------------
1005 createAndSendEvent( wxEVT_TSBAR_MOVED );
1007 //if actual has to be between start and end
1008 else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
1010 SetStart(next_start);
1012 if( _moveActualWithBar )
1014 SetActual (next_actual);
1015 //-------------------------------------------
1016 //Sending the event of actual triangle moved
1017 //-------------------------------------------
1018 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1021 RefreshHorizontalView();
1023 //-------------------------------------------
1024 // Sending the event that the bar ahs being moved
1025 //-------------------------------------------
1026 createAndSendEvent( wxEVT_TSBAR_MOVED );
1030 if( !event.LeftIsDown())
1033 _selectionMoveId = -1;
1035 //-------------------------------------------
1036 //Sending a general event just because
1037 //-------------------------------------------
1038 //SIL//createAndSendEvent( wxEVT_TSBAR );
1039 createAndSendEvent(wxEVT_SELECTION_END);
1045 //ff=fopen ("c:/temp/xxx.txt", "a+");
1046 //fprintf( ff , " mBarRange :: OnMouseMove 02\n" );
1051 * Sets the represented minimum and maximunm values
1052 * param minRealValue The minimum represented value (real value)
1053 * param maxRealValue The maximum represented value (real value)
1055 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
1057 _min = minRealValue;
1058 _max = maxRealValue;
1064 * Sets the property for viewing or not the bar labels information
1066 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
1068 _visibleLables = setVisibleLB;
1072 * Sets the property for viewing or not the bar labels information
1073 * return _visibleLables The state of visible labels or not
1075 bool mBarRange ::getIfVisibleLabels ()
1077 return _visibleLables;
1081 * Sets the device start drawing left-superior (pixel) start point
1082 * param deviceStart_x Pixel start for x-coord
1083 * param deviceStart_y Pixel start for y-coord
1085 void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1087 deviceStart_x = devStart_x;
1088 deviceStart_y = devStart_y;
1089 // For the initialization case
1090 if (GetPixelEnd()<0)
1094 SetPixelStart(deviceStart_x);
1095 SetPixelEnd(_w+deviceStart_x);
1096 SetPixelActual(deviceStart_x);
1100 SetPixelStart(deviceStart_x);
1101 SetPixelEnd(_h+deviceStart_x);
1102 SetPixelActual(deviceStart_x);
1109 * Shows the popup menu
1111 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1115 bool validClic = false;
1118 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1122 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1127 setClickedX(event.GetX());
1129 setClickedX(event.GetY());
1131 if (getClickedX()<=_h)
1133 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1134 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1135 bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1136 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1139 _selectionMoveId = 1;
1140 else if( in_EndTri )
1141 _selectionMoveId = 2;
1142 else if( in_actualT )
1143 _selectionMoveId = 3;
1144 else if( in_movingBar )
1145 _selectionMoveId = 4;
1147 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1153 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1154 * param & anEvent The wxCommandEvent actioned event
1156 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1158 bool okSelectedColor = false;
1159 wxColour selectedColour;
1161 wxColourDialog dialog( GetParent(), &data);
1163 if ( dialog.ShowModal() == wxID_OK )
1165 selectedColour = dialog.GetColourData().GetColour();
1166 okSelectedColor = true;
1168 if( okSelectedColor )
1170 if (_selectionMoveId==1 )
1171 start_Colour = selectedColour;
1172 else if (_selectionMoveId==2 )
1173 end_Colour = selectedColour;
1174 else if( _selectionMoveId==3 )
1175 actual_Colour = selectedColour;
1176 else if( _selectionMoveId==4 )
1177 bar_Colour = selectedColour;
1179 _selectionMoveId = -1;
1185 * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1186 * param & anEvent The wxCommandEvent actioned event
1188 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1190 if (!_in_rangeProperty)
1192 if(IsActualInRange())
1194 SetInRangeProperty (true);
1195 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1200 SetInRangeProperty (false);
1201 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
1206 * 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.
1207 * param & anEvent The wxCommandEvent actioned event
1209 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1211 if (_moveActualWithBar )
1213 _moveActualWithBar = false;
1214 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1218 if(IsActualInRange())
1220 _moveActualWithBar = true;
1221 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1228 * param activeNow The new state
1230 void mBarRange :: setActiveStateTo (bool activeNow)
1232 activeState = activeNow;
1236 * Gets the active state of the bar
1237 * return activeState The actual state
1239 bool mBarRange :: isActive()
1245 * Gets the real-x value to draw a vertical line
1246 * return realX_vertical_line The real x value for the vertical line
1248 int mBarRange :: getRealX_vertical_line()
1250 return realX_vertical_line;
1254 * Sets the real-x value to draw a vertical line
1255 * param newReal_x The new real x value for the vertical line
1257 void mBarRange :: setRealX_vertical_line(int newReal_x)
1259 realX_vertical_line = newReal_x;
1263 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1264 * return deviceEndMargin The value asigned to the right margin
1266 int mBarRange :: getDeviceEndX()
1268 return deviceEndMargin;
1272 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1273 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1275 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1277 deviceEndMargin = newDeviceEnd_pixels;
1281 * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1282 * return clickedX The x-coord pixel value
1284 int mBarRange :: getClickedX()
1290 * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1291 * param nwClickX The x-coord pixel value
1293 void mBarRange :: setClickedX(int nwClickX)
1295 clickedX = nwClickX;
1300 * Gets the start porcentage with respect to the represented values of the bar
1301 * return The porcentage represented by the start showing point
1303 float mBarRange :: getStartShowPorcentage()
1305 return (float)( 1+(_start - _max)/(_max-_min));
1309 * Gets the end porcentage with respect to the represented values of the bar
1310 * return The porcentage represented by the end showing point
1312 float mBarRange :: getEndShowPorcentage()
1314 return (float) (1+(_end - _max)/(_max-_min));
1318 * Gets the actual porcentage with respect to the represented values of the bar
1319 * return The porcentage represented by the actual showing point
1321 float mBarRange :: getActualShowPorcentage()
1323 return (float) (1+(_actual - _max)/(_max-_min));
1326 int mBarRange :: getLogicValueofPixel(int thePixel)
1328 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1332 * Sets the condition for knowing if the actual triangle is being drawed or not
1333 * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1335 void mBarRange :: setIfWithActualDrawed(bool drawActual)
1337 if(!withActualDrawed && drawActual)
1339 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1340 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
1342 else if (withActualDrawed && !drawActual)
1344 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1345 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1347 withActualDrawed = drawActual;
1352 * Gets the condition for knowing if the actual triangle is being drawed or not
1353 * return withActualDrawed The condition for drawing or not the actual control
1355 bool mBarRange :: getIfWithActualDrawed()
1357 return withActualDrawed;
1360 void mBarRange::createAndSendEvent(WXTYPE theEventType)
1362 wxCommandEvent cevent( theEventType, GetId() );
1363 cevent.SetEventObject( this );
1364 GetEventHandler()->ProcessEvent( cevent );
1368 * Sets the background color od the bar
1369 * theColor The color to set to the backgroundColor
1371 void mBarRange :: setBackgroundColor(wxColour theColor)
1373 backgroundColor = theColor;
1377 * Sets the guide line color
1378 * param theNwGuideLineColor The color to set to the guideLineColor
1380 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1382 guideLineColor = theNwGuideLineColor;
1386 * Gets the guide line color
1387 * return guideLineColor The color of the guideLine
1389 wxColour mBarRange :: getGuideLineColour()
1391 return guideLineColor;
1394 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
1396 acceptedClick = true;
1399 void mBarRange ::onLeftClickUp(wxMouseEvent& event )
1401 acceptedClick = false;