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 EVT_CHAR( mBarRange :: onKey )
36 //how to catch the new event (our event)
37 //EVT_COMMAND (ID_MY_WINDOW, wxEVT_MY_EVENT, MyFrame::OnMyEvent)
41 //----------------------------------------------------------------------------
43 //----------------------------------------------------------------------------
45 mBarRange::mBarRange(wxWindow *parent, int w, int h)
46 :wxScrolledWindow(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
53 trianglesHalfWidth = 5;
55 wxColour start_Colour;
57 // Setting the default parts colors
58 start_Colour = wxColour(0,0,255);
59 actual_Colour = wxColour(255,255,202);
60 end_Colour = wxColour(0,0,255);
61 bar_Colour = wxColour(255,0,255);
62 backgroundColor = parent ->GetBackgroundColour();
63 guideLineColor = wxColour(255,0,0);
65 //actual is in _start and end
66 //false means that it could be anywhere
67 _moveActualWithBar = false;
68 _in_rangeProperty = false;
69 _selectionMoveId = -1;
70 realX_vertical_line = -1;
76 setIfWithActualDrawed(true);
78 b_popmenu.Append (cntID_CHANGE_COLOR, _("Change Color"), _("Changes the color of the selected part"));
79 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
80 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
85 //----------------------------------------------------------------------------
87 //----------------------------------------------------------------------------
89 mBarRange::~mBarRange()
92 //---------------------------------------------------------------------------
93 //Draw bar: vertical or Horizontal
94 //---------------------------------------------------------------------------
95 void mBarRange::DrawBar()
100 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
101 _bitmap_bar = new wxBitmap(_w+1280,_h+100);
102 //SIL//_bitmap_info = new wxBitmap(_w+100+1280, _h+100);
107 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
108 _bitmap_bar = new wxBitmap(_h+deviceStart_y+100,_w+1280);
109 _bitmap_info = new wxBitmap(_h+deviceStart_y+100, _w+1280);
112 //----------------------------------------------------------------------------
114 //----------------------------------------------------------------------------
115 //----------------------------------------------------------------------------
116 //the property condition on actual triangle
117 //----------------------------------------------------------------------------
118 bool mBarRange::GetInRangeProperty()
120 return _in_rangeProperty;
122 //----------------------------------------------------------------------------
123 void mBarRange::SetInRangeProperty(bool in)
125 _in_rangeProperty=in;
127 //----------------------------------------------------------------------------
128 //the information about the actual triangle in range or not, true if is between start and end
129 //----------------------------------------------------------------------------
130 bool mBarRange::IsActualInRange()
132 return ( _actual <= _end && _actual >= _start );
135 //----------------------------------------------------------------------------
136 // the position of the rectangle, vertical or horizontal
137 //----------------------------------------------------------------------------
138 bool mBarRange::GetOrientation()
142 //-----------------------------------------------------------------------------
143 void mBarRange::SetOrientation(bool orientation)
149 _orientation=orientation;
152 //----------------------------------------------------------------------------
153 // _start of the pixel rectangle
154 //----------------------------------------------------------------------------
156 int mBarRange::GetPixelStart()
158 return ((_start - _min)*(_w-deviceEndMargin))/(_max - _min);
160 //----------------------------------------------------------------------------
161 // param i: value in pixels
162 //----------------------------------------------------------------------------
163 void mBarRange::SetPixelStart(int i)
165 _start = _min+((i - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
168 //----------------------------------------------------------------------------
169 // _actual of the pixel rectangle
170 //----------------------------------------------------------------------------
171 int mBarRange::GetPixelActual()
173 return ((_actual - _min)*(_w-deviceEndMargin))/(_max - _min);
175 //----------------------------------------------------------------------------
176 // param i: value in pixels
177 //----------------------------------------------------------------------------
178 void mBarRange::SetPixelActual(int i)
180 _actual = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
182 //----------------------------------------------------------------------------
183 // _end of the pixel rectangle
184 //----------------------------------------------------------------------------
185 int mBarRange::GetPixelEnd()
187 return ((_end - _min)*(_w-deviceEndMargin))/(_max - _min);
189 //----------------------------------------------------------------------------
190 // param i: value in pixels to be converted to real logical value
191 //----------------------------------------------------------------------------
192 void mBarRange::SetPixelEnd(int i)
194 _end = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
196 //----------------------------------------------------------------------------
197 // Logical max of the triangle
198 //----------------------------------------------------------------------------
200 double mBarRange::GetMax()
205 //----------------------------------------------------------------------------
206 void mBarRange::SetMax(double i)
210 //----------------------------------------------------------------------------
211 // Logical min of the triangle
212 //----------------------------------------------------------------------------
214 double mBarRange::GetMin()
219 //----------------------------------------------------------------------------
220 void mBarRange::SetMin(double i)
225 //----------------------------------------------------------------------------
226 // pixel dimensions of the rectangle
227 //----------------------------------------------------------------------------
229 int mBarRange::GetWidth()
233 //----------------------------------------------------------------------------
234 void mBarRange::SetWidth(int w)
238 //----------------------------------------------------------------------------
239 int mBarRange::GetHeight()
244 //----------------------------------------------------------------------------
245 void mBarRange::SetHeight(int h)
250 //----------------------------------------------------------------------------
251 // Logical Start of the rectangle
252 //----------------------------------------------------------------------------
254 int mBarRange::filtreValue(int value)
265 int mBarRange::GetStart()
269 //----------------------------------------------------------------------------
270 // param start: value real units
271 //----------------------------------------------------------------------------
272 void mBarRange::SetStart(int newstart)
274 _start = filtreValue(newstart);
275 if (_start>_end) { _start=_end; }
276 if (_in_rangeProperty==true)
278 if (_start>_actual) { _start=_actual; }
282 //----------------------------------------------------------------------------
283 // Logical End of the rectangle
284 //----------------------------------------------------------------------------
286 int mBarRange::GetEnd()
290 //----------------------------------------------------------------------------
291 // param end: value pixel units
292 //----------------------------------------------------------------------------
293 void mBarRange::SetEnd(int newend)
295 _end = filtreValue(newend);
296 if (_end<_start) { _end=_start; }
297 if (_in_rangeProperty==true)
299 if (_end<_actual) { _end=_actual; }
303 //----------------------------------------------------------------------------
304 // logical Actual of the rectangle
305 //----------------------------------------------------------------------------
306 int mBarRange::GetActual()
310 //----------------------------------------------------------------------------
311 void mBarRange::SetActual(int newactual)
313 _actual = filtreValue(newactual);
314 if (_in_rangeProperty==true)
316 if (_actual<_start) { _actual=_start; }
317 if (_actual>_end) { _actual=_end; }
322 //----------------------------------------------------------------------------
324 //----------------------------------------------------------------------------
325 int mBarRange::GetTrianglesHalfWidth()
327 return trianglesHalfWidth;
329 //----------------------------------------------------------------------------
330 void mBarRange::SetTrianglesHalfWidth(int nwTriHalfWidth)
332 trianglesHalfWidth = nwTriHalfWidth;
335 void mBarRange::OnSize( wxSizeEvent &WXUNUSED(event) )
337 wxRect rectTotal = GetClientRect();
340 SetWidth( rectTotal.GetWidth() - deviceEndMargin );
344 SetWidth( rectTotal.GetHeight() - deviceEndMargin);
346 _selectionMoveId = -1;
350 //----------------------------------------------------------------------------
352 void mBarRange::Refresh(bool eraseBackground, const wxRect* rect)
356 //ff=fopen ("c:/temp/xxx.txt", "a+");
357 //fprintf( ff , "mBarRange :: Refresh 01\n" );
360 wxScrolledWindow::Refresh(false);
364 //ff=fopen ("c:/temp/xx.txt", "a+");
365 //fprintf( ff , "mBarRange :: Refresh 02\n" );
370 //----------------------------------------------------------------------------
372 //----------------------------------------------------------------------------
373 void mBarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
378 //ff=fopen ("c:/temp/xx.txt", "a+");
379 //fprintf( ff , "pColorBar :: OnPaint 01\n" );
382 if (_bitmap_bar!=NULL){
386 RefreshHorizontalView();
388 temp_dc.SelectObject( *_bitmap_bar );
389 wxPaintDC dc( this );
390 dc.Blit(deviceStart_x-(trianglesHalfWidth+2), deviceStart_y, _w-deviceEndMargin+2*(trianglesHalfWidth+2), _h, &temp_dc, 0, 0);
392 // if (_visibleLables)
394 // temp_dc.SelectObject( *_bitmap_info );
395 // dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+200, &temp_dc, deviceStart_x, deviceStart_y);
396 // //dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+60, &temp_dc, 0, 0);
400 RefreshVerticalView();
402 temp_dc.SelectObject( *_bitmap_bar );
403 wxPaintDC dc( this );
404 // dc.Blit(deviceStart_y,deviceStart_x, _h+deviceStart_y-deviceEndMargin,_w+deviceStart_x-deviceEndMargin, &temp_dc, 0, 0);
405 dc.Blit(deviceStart_y,deviceStart_x-(trianglesHalfWidth+2), _h,_w-deviceEndMargin+2*(trianglesHalfWidth+2), &temp_dc, 0, 0);
408 // if (_visibleLables)
410 // temp_dc.SelectObject( *_bitmap_info );
411 // dc.Blit(0,_w, _h+deviceStart_y+200, _w+deviceStart_x+200-deviceEndMargin, &temp_dc, deviceStart_y,_w+deviceStart_x);
419 //ff=fopen ("c:/temp/xx.txt", "a+");
420 //fprintf( ff , "pColorBar :: OnPaint 02\n" );
425 //----------------------------------------------------------------------------
426 //Repaint the bar if it is horizontal
427 //----------------------------------------------------------------------------
428 void mBarRange::RefreshHorizontalView()
433 //ff=fopen ("c:/temp/xxx.txt", "a+");
434 //fprintf( ff , "mBarRange :: RefreshHorizontalView 01\n" );
439 //int largestNumberWidthInPixels = 15; // JPRx
440 int pxStart = GetPixelStart();
441 int pxEnd = GetPixelEnd();
442 int pxActual = GetPixelActual();
446 int barHeight = 2*letterHeight;
447 int tempHeight = _h-(6*letterHeight);
452 barHeight = (tempHeight>0) ? tempHeight : (int) _h/2;
458 temp_dc.SelectObject( *_bitmap_bar );
461 // Background of this widget
464 temp_dc.SetPen(wxPen( backgroundColor ));
465 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
467 temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
470 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
471 temp_dc.DrawLine(trianglesHalfWidth+2, 0, _w-deviceEndMargin, 0);
472 temp_dc.DrawLine(trianglesHalfWidth+2, barHeight, (_w-deviceEndMargin-trianglesHalfWidth-2), barHeight);
473 temp_dc.SetDeviceOrigin(trianglesHalfWidth+2,0);
477 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
478 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
479 temp_dc.DrawRectangle( pxStart , 0, pxEnd-pxStart, barHeight);
483 if( _selectionMoveId==4 )
485 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
486 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
490 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
491 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
493 temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
495 // 2 Shadow Triangles: Start and End
496 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
497 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
499 points[0].y= barHeight;
500 points[1].x= -trianglesHalfWidth-1;
502 points[2].x= trianglesHalfWidth+2;
504 temp_dc.DrawPolygon(3,points,pxStart,0);
505 temp_dc.DrawPolygon(3,points,pxEnd,0);
507 // 2 Triangles: Start and End
508 points[1].x = -trianglesHalfWidth;
509 points[2].x = trianglesHalfWidth;
511 //first triangle (start)
512 if( _selectionMoveId == 1 )
514 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
515 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
519 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
520 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
522 temp_dc.DrawPolygon(3,points,pxStart,0);
523 //second triangle (end)
524 if( _selectionMoveId == 2 )
526 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
527 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
531 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
532 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
534 temp_dc.DrawPolygon(3,points,pxEnd,0);
536 if( withActualDrawed )
538 // 1 Shadow Triangle: Actual
539 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
540 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
541 points[1].x = -trianglesHalfWidth-1;
542 points[2].x = trianglesHalfWidth+2;
544 temp_dc.DrawPolygon(3,points,pxActual,0);
546 // 1 Triangle: Actual (red)
547 if( _selectionMoveId==3 )
549 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
550 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
554 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
555 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
557 points[1].x = -trianglesHalfWidth;
558 points[2].x = trianglesHalfWidth;
559 temp_dc.DrawPolygon(3,points,pxActual,0);
562 if (realX_vertical_line!=-1)
564 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
565 int pixelX_guide = ((realX_vertical_line - _min)*(_w-deviceEndMargin))/(_max - _min) ;
566 temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, barHeight);
569 //Information Device drawing
573 //temp_dc.SelectObject( *_bitmap_info );
574 /*temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID ));
575 temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID ));*/
576 //temp_dc.DrawRectangle(deviceStart_x,_h+deviceStart_y,_w+deviceStart_x+40,_h+deviceStart_y+40);
577 //temp_dc.DrawRectangle(0,_h,_w+40-deviceEndMargin,_h+40);
579 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
580 temp_dc.SetFont(font);
581 temp_dc.SetTextForeground(*wxBLACK);
584 //the **MIN** value, always at the same y level that corresponds to barHeight+1
586 // text_min<< GetMin();
587 text_min.Printf(_T("%d"), (int)GetMin() );
589 temp_dc.DrawText(text_min,0,barHeight+1);
591 //the **MAX** value always at the same place
593 // text_max << GetMax();
594 text_max.Printf(_T("%d"), (int)GetMax() );
596 //As there is a margin of 40 extra most numbers (max) should be visibles
597 // stringSize = temp_dc.GetTextExtent(text_max);
599 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
600 wxSize stringSize(tmpX,tmpY);
602 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth())/*2*trianglesHalfWidth*/,barHeight+1);
604 //show logical values
605 //show the **START TRIANGLE** value
607 // text_start << GetStart();
608 text_start.Printf(_T("%d"), (int)GetStart() );
610 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
611 //show the **END TRIANGLE** value
613 // text_end << GetEnd();
614 text_end.Printf(_T("%d"), (int)GetEnd() );
616 // stringSize = temp_dc.GetTextExtent(text_end);
617 temp_dc.GetTextExtent(text_end,&tmpX,&tmpY);
618 stringSize.SetHeight(tmpY);
619 stringSize.SetWidth(tmpX);
620 temp_dc.DrawText(text_end, pxEnd-stringSize.GetWidth(),barHeight+3*letterHeight);
621 if( withActualDrawed )
623 //show the actual value of actual
624 wxString text_actual;
625 // text_actual << GetActual();
626 text_actual.Printf(_T("%d"), (int)GetActual() );
627 // stringSize = temp_dc.GetTextExtent(text_actual);
628 temp_dc.GetTextExtent(text_actual,&tmpX,&tmpY);
629 stringSize.SetHeight(tmpY);
630 stringSize.SetWidth(tmpX);
631 temp_dc.DrawText(text_actual, pxActual-(stringSize.GetWidth()/2),barHeight+letterHeight);
636 //ff=fopen ("c:/temp/xxx.txt", "a+");
637 //fprintf( ff , "mBarRange :: RefreshHorizontalView 02\n" );
641 //----------------------------------------------------------------------------
642 //Repaint the bar if it is vertical
643 //----------------------------------------------------------------------------
645 void mBarRange::RefreshVerticalView()
650 //ff=fopen ("c:/temp/xxx.txt", "a+");
651 //fprintf( ff , "mBarRange :: RefreshVerticalView 01\n" );
655 int px1=GetPixelStart();
656 int px2=GetPixelEnd();
657 int px3=GetPixelActual();
658 int letterHeight = 9;
659 int panelHeight = 9*3+_w;
664 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
670 temp_dc.SelectObject( *_bitmap_bar );
673 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
674 temp_dc.SetPen(wxPen( backgroundColor ));
676 temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
679 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
680 temp_dc.DrawLine(0,trianglesHalfWidth+2, 0, _w-deviceEndMargin);
681 temp_dc.DrawLine(barWidth, trianglesHalfWidth+2, barWidth, (_w-deviceEndMargin-trianglesHalfWidth-2));
682 temp_dc.SetDeviceOrigin(0,trianglesHalfWidth+2);
685 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
686 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
687 temp_dc.DrawRectangle( 0,px1 ,_h, px2-px1 );
691 if( _selectionMoveId==4 )
693 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
694 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
698 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
699 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
701 temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
704 // 2 Shadow Triangles: Start and End
708 points[1].y = -trianglesHalfWidth-1;
710 points[2].y = trianglesHalfWidth+2;
711 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
712 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
713 temp_dc.DrawPolygon(3,points,0,px1);
714 temp_dc.DrawPolygon(3,points,0,px2);
716 // 2 Triangles: Start and End
720 points[1].y = -trianglesHalfWidth;
722 points[2].y = trianglesHalfWidth;
723 //first triangle (start)
724 if( _selectionMoveId==1 )
726 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
727 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
731 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
732 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
734 temp_dc.DrawPolygon(3,points,0,px1);
735 //second triangle (end)
736 if( _selectionMoveId==2 )
738 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
739 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
743 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
744 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
746 temp_dc.DrawPolygon(3,points,0,px2);
748 if( withActualDrawed )
750 // 1 Shadow Triangle: Actual
751 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
752 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
756 points[1].y=-trianglesHalfWidth-1;
758 points[2].y=trianglesHalfWidth+2;
759 temp_dc.DrawPolygon(3,points,0,px3);
761 // 1 Triangle: Actual (red)
765 points[1].y = -trianglesHalfWidth;
767 points[2].y = trianglesHalfWidth;
768 if( _selectionMoveId==3 )
770 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
771 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
775 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
776 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
778 temp_dc.DrawPolygon(3,points,0,px3);
781 if (realX_vertical_line!=-1)
783 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
784 int pixelX_guide = realX_vertical_line*_w/(_max-_min)+deviceStart_x;
785 temp_dc.DrawLine(0,pixelX_guide, _h, pixelX_guide);
788 //Information Device drawing
791 /*temp_dc.SelectObject( *_bitmap_info );
793 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
794 temp_dc.SetPen(wxPen( backgroundColor ,1,wxSOLID ));
795 temp_dc.DrawRectangle(deviceStart_y,_w+deviceStart_x,_h+deviceStart_y+200,_w+deviceStart_x+200);
798 temp_dc.SetBackgroundMode(wxTRANSPARENT);
799 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
800 temp_dc.SetFont(font);
801 temp_dc.SetTextForeground(*wxBLACK);
803 //show logical values
804 //show the actual value of start
806 // text_start<<"Start:"<< GetStart();
807 text_start.Printf(_T("%s %d"),_T("Start: "), (int)GetStart() );
808 temp_dc.DrawText( text_start ,deviceStart_y, _w+deviceStart_x+letterHeight+1);
809 //show the actual value of end
811 // text_end <<"End: "<<GetEnd();
812 text_end.Printf(_T("%s %d"),_T("End: "), (int)GetEnd() );
813 temp_dc.DrawText( text_end ,deviceStart_y,_w+deviceStart_x+letterHeight*2 );
814 if( withActualDrawed )
816 //show the actual value of actual
817 wxString text_actual;
818 // text_actual <<"Actual: " <<GetActual();
819 text_actual.Printf(_T("%s %d"),_T("Actual: "), (int)GetActual() );
820 temp_dc.DrawText( text_actual ,deviceStart_y,_w+deviceStart_x+letterHeight*3);
822 //the min value, always at the same place
824 // text_min<<"Min: " << GetMin();
825 text_min.Printf(_T("%s %d"),_T("Min: "), (int)GetMin() );
826 temp_dc.DrawText( text_min ,deviceStart_y,_w+deviceStart_x+3);
827 //the max value always at the samen place
829 // text_max <<"Max: "<< GetMax();
830 text_max.Printf(_T("%s %d"),_T("Max: "), (int)GetMax() );
831 //toca calcular cuantol lo corremos
832 temp_dc.DrawText(text_max,deviceStart_y,_w+deviceStart_x+43);
837 //----------------------------------------------------------------------------
838 void mBarRange::RefreshForce()
843 //----------------------------------------------------------------------------
844 void mBarRange::OnMouseMove(wxMouseEvent& event )
848 //ff=fopen ("c:/temp/xxx.txt", "a+");
849 //fprintf( ff , "mBarRange :: OnMouseMove 01\n" );
852 //int px1=GetPixelStart(); // JPRx
853 //int px2=GetPixelEnd(); // JPRx
854 //int px3=GetPixelActual(); // JPRx
857 wxPoint point = event.GetPosition();
861 setClickedX(point.x);
866 setClickedX(point.y);
869 int logicClick = getLogicValueofPixel(clickedX);
871 if( _selectionMoveId==-1 )
875 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
876 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
877 bool in_actualT= withActualDrawed && (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
878 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
881 _selectionMoveId = 3;
883 _selectionMoveId = 1;
885 _selectionMoveId = 2;
886 else if( in_movingBar )
887 _selectionMoveId = 4;
894 //is in start triagle
895 if( _selectionMoveId ==1 && event.LeftIsDown())
897 bool validPos_StartTri = (logicClick<GetEnd() && logicClick >=_min);
898 if( validPos_StartTri && !_in_rangeProperty)
900 SetPixelStart(clickedX);
902 RefreshHorizontalView();
903 //-------------------------------------------
904 // Sending the event of start triangle moved
905 //-------------------------------------------
906 createAndSendEvent( wxEVT_TSBAR_START );
908 //start has to be less than actual
909 else if (validPos_StartTri && _in_rangeProperty)
911 if(logicClick<=GetActual())
913 SetPixelStart(clickedX);
915 // RefreshHorizontalView();
916 //-------------------------------------------
917 // Sending the event of start triangle moved
918 //-------------------------------------------
919 createAndSendEvent( wxEVT_TSBAR_START );
922 } // _selectionMoveId == 1
924 else if( _selectionMoveId == 2 && event.LeftIsDown() )
926 bool validPos_EndTri = logicClick>GetStart()&& logicClick<=_max;
927 if( validPos_EndTri && !_in_rangeProperty )
929 SetPixelEnd(clickedX);
931 // RefreshHorizontalView();
932 //-------------------------------------------
933 //Sending the event of end triangle moved
934 //-------------------------------------------
935 createAndSendEvent( wxEVT_TSBAR_END );
937 //the end triangle cant be less than actual
938 else if( validPos_EndTri && _in_rangeProperty )
940 if(logicClick>=GetActual())
942 SetPixelEnd(clickedX);
944 // RefreshHorizontalView();
945 //-------------------------------------------
946 //Sending the event of end triangle moved
947 //-------------------------------------------
948 createAndSendEvent( wxEVT_TSBAR_END );
952 //is the actual triangle
953 else if( _selectionMoveId == 3 && event.LeftIsDown())
955 bool validPos_ActualTri=(logicClick<=_max) && (logicClick>=_min);
956 //is in actual triangle but it could be anywhere
957 if( validPos_ActualTri && !_in_rangeProperty )
959 SetPixelActual(clickedX);
961 RefreshHorizontalView();
962 //-------------------------------------------
963 //Sending the event of actual triangle moved
964 //-------------------------------------------
965 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
966 // createAndSendEvent( 98765 );
968 else if( validPos_ActualTri && _in_rangeProperty )
969 // the tringle in between start and end
971 if( logicClick>=GetStart() && logicClick<=GetEnd())
973 SetPixelActual(clickedX);
975 RefreshHorizontalView();
976 //-------------------------------------------
977 //Sending the event of actual triangle moved
978 //-------------------------------------------
979 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
984 else if ( _selectionMoveId == 4 && event.LeftIsDown() )
986 //FILE * f=fopen("E:/borrar/file.txt","a+");
987 if(_initialPoint == 0)
989 _initialPoint = logicClick;
990 logicInitial_start = GetStart();
991 logicInitial_end = GetEnd();
992 logicInitial_actual = GetActual();
993 //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);
995 int difference = logicClick -_initialPoint;
996 int next_end = difference + logicInitial_end;
997 int next_start = difference + logicInitial_start;
998 int next_actual = difference + logicInitial_actual;
1000 /*SIL//fprintf(f,"diff:%d, next_end%d, next_start%d, next_actual%d \n", difference,next_end,next_start,next_actual);
1003 //if actual is not fixed to be in the middle
1004 if( ((logicClick>next_start) && (logicClick<next_end)&& (next_end<=_max)&& (next_start>=_min)) && !_in_rangeProperty)
1006 SetStart(next_start);
1008 if( _moveActualWithBar )
1010 SetActual (next_actual);
1011 //-------------------------------------------
1012 //Sending the event of actual triangle moved
1013 //-------------------------------------------
1014 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1017 RefreshHorizontalView();
1019 //-------------------------------------------
1020 // Sending the event that the bar ahs being moved
1021 //-------------------------------------------
1022 createAndSendEvent( wxEVT_TSBAR_MOVED );
1024 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1025 createAndSendEvent( wxEVT_TSBAR_END );
1026 createAndSendEvent( wxEVT_TSBAR_START );
1028 //if actual has to be between start and end
1029 else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
1031 SetStart(next_start);
1033 if( _moveActualWithBar )
1035 SetActual (next_actual);
1036 //-------------------------------------------
1037 //Sending the event of actual triangle moved
1038 //-------------------------------------------
1039 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1042 RefreshHorizontalView();
1044 //-------------------------------------------
1045 // Sending the event that the bar ahs being moved
1046 //-------------------------------------------
1047 createAndSendEvent( wxEVT_TSBAR_MOVED );
1049 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1050 createAndSendEvent( wxEVT_TSBAR_END );
1051 createAndSendEvent( wxEVT_TSBAR_START );
1055 if( !event.LeftIsDown())
1058 _selectionMoveId = -1;
1060 //-------------------------------------------
1061 //Sending a general event just because
1062 //-------------------------------------------
1063 //SIL//createAndSendEvent( wxEVT_TSBAR );
1064 createAndSendEvent(wxEVT_SELECTION_END);
1070 //ff=fopen ("c:/temp/xxx.txt", "a+");
1071 //fprintf( ff , " mBarRange :: OnMouseMove 02\n" );
1076 * Sets the represented minimum and maximunm values
1077 * param minRealValue The minimum represented value (real value)
1078 * param maxRealValue The maximum represented value (real value)
1080 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
1082 _min = minRealValue;
1083 _max = maxRealValue;
1089 * Sets the property for viewing or not the bar labels information
1091 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
1093 _visibleLables = setVisibleLB;
1097 * Sets the property for viewing or not the bar labels information
1098 * return _visibleLables The state of visible labels or not
1100 bool mBarRange ::getIfVisibleLabels ()
1102 return _visibleLables;
1106 * Sets the device start drawing left-superior (pixel) start point
1107 * param deviceStart_x Pixel start for x-coord
1108 * param deviceStart_y Pixel start for y-coord
1110 void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1112 deviceStart_x = devStart_x;
1113 deviceStart_y = devStart_y;
1114 // For the initialization case
1115 if (GetPixelEnd()<0)
1119 SetPixelStart(deviceStart_x);
1120 SetPixelEnd(_w+deviceStart_x);
1121 SetPixelActual(deviceStart_x);
1125 SetPixelStart(deviceStart_x);
1126 SetPixelEnd(_h+deviceStart_x);
1127 SetPixelActual(deviceStart_x);
1134 * Shows the popup menu
1136 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1140 bool validClic = false;
1143 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1147 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1152 setClickedX(event.GetX());
1154 setClickedX(event.GetY());
1156 if (getClickedX()<=_h)
1158 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1159 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1160 bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1161 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1164 _selectionMoveId = 1;
1165 else if( in_EndTri )
1166 _selectionMoveId = 2;
1167 else if( in_actualT )
1168 _selectionMoveId = 3;
1169 else if( in_movingBar )
1170 _selectionMoveId = 4;
1172 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1178 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1179 * param & anEvent The wxCommandEvent actioned event
1181 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1183 bool okSelectedColor = false;
1184 wxColour selectedColour;
1186 wxColourDialog dialog( GetParent(), &data);
1188 if ( dialog.ShowModal() == wxID_OK )
1190 selectedColour = dialog.GetColourData().GetColour();
1191 okSelectedColor = true;
1193 if( okSelectedColor )
1195 if (_selectionMoveId==1 )
1196 start_Colour = selectedColour;
1197 else if (_selectionMoveId==2 )
1198 end_Colour = selectedColour;
1199 else if( _selectionMoveId==3 )
1200 actual_Colour = selectedColour;
1201 else if( _selectionMoveId==4 )
1202 bar_Colour = selectedColour;
1204 _selectionMoveId = -1;
1210 * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1211 * param & anEvent The wxCommandEvent actioned event
1213 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1215 if (!_in_rangeProperty)
1217 if(IsActualInRange())
1219 SetInRangeProperty (true);
1220 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1225 SetInRangeProperty (false);
1226 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
1231 * 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.
1232 * param & anEvent The wxCommandEvent actioned event
1234 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1236 if (_moveActualWithBar )
1238 _moveActualWithBar = false;
1239 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1243 if(IsActualInRange())
1245 _moveActualWithBar = true;
1246 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1253 * param activeNow The new state
1255 void mBarRange :: setActiveStateTo (bool activeNow)
1257 activeState = activeNow;
1261 * Gets the active state of the bar
1262 * return activeState The actual state
1264 bool mBarRange :: isActive()
1270 * Gets the real-x value to draw a vertical line
1271 * return realX_vertical_line The real x value for the vertical line
1273 int mBarRange :: getRealX_vertical_line()
1275 return realX_vertical_line;
1279 * Sets the real-x value to draw a vertical line
1280 * param newReal_x The new real x value for the vertical line
1282 void mBarRange :: setRealX_vertical_line(int newReal_x)
1284 realX_vertical_line = newReal_x;
1288 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1289 * return deviceEndMargin The value asigned to the right margin
1291 int mBarRange :: getDeviceEndX()
1293 return deviceEndMargin;
1297 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1298 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1300 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1302 deviceEndMargin = newDeviceEnd_pixels;
1306 * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1307 * return clickedX The x-coord pixel value
1309 int mBarRange :: getClickedX()
1315 * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1316 * param nwClickX The x-coord pixel value
1318 void mBarRange :: setClickedX(int nwClickX)
1320 clickedX = nwClickX;
1325 * Gets the start porcentage with respect to the represented values of the bar
1326 * return The porcentage represented by the start showing point
1328 float mBarRange :: getStartShowPorcentage()
1330 return (float)( 1+(_start - _max)/(_max-_min));
1334 * Gets the end porcentage with respect to the represented values of the bar
1335 * return The porcentage represented by the end showing point
1337 float mBarRange :: getEndShowPorcentage()
1339 return (float) (1+(_end - _max)/(_max-_min));
1343 * Gets the actual porcentage with respect to the represented values of the bar
1344 * return The porcentage represented by the actual showing point
1346 float mBarRange :: getActualShowPorcentage()
1348 return (float) (1+(_actual - _max)/(_max-_min));
1351 int mBarRange :: getLogicValueofPixel(int thePixel)
1353 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1357 * Sets the condition for knowing if the actual triangle is being drawed or not
1358 * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1360 void mBarRange :: setIfWithActualDrawed(bool drawActual)
1362 if(!withActualDrawed && drawActual)
1364 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1365 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
1367 else if (withActualDrawed && !drawActual)
1369 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1370 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1372 withActualDrawed = drawActual;
1377 * Gets the condition for knowing if the actual triangle is being drawed or not
1378 * return withActualDrawed The condition for drawing or not the actual control
1380 bool mBarRange :: getIfWithActualDrawed()
1382 return withActualDrawed;
1385 void mBarRange::createAndSendEvent(WXTYPE theEventType)
1387 wxCommandEvent cevent( theEventType, GetId() );
1388 cevent.SetEventObject( this );
1389 GetEventHandler()->ProcessEvent( cevent );
1393 * Sets the background color od the bar
1394 * theColor The color to set to the backgroundColor
1396 void mBarRange :: setBackgroundColor(wxColour theColor)
1398 backgroundColor = theColor;
1402 * Sets the guide line color
1403 * param theNwGuideLineColor The color to set to the guideLineColor
1405 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1407 guideLineColor = theNwGuideLineColor;
1411 * Gets the guide line color
1412 * return guideLineColor The color of the guideLine
1414 wxColour mBarRange :: getGuideLineColour()
1416 return guideLineColor;
1420 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
1422 acceptedClick = true;
1426 void mBarRange::onLeftClickUp(wxMouseEvent& event )
1428 acceptedClick = false;
1431 //EED 20 Juillet 2011
1432 void mBarRange::onKey(wxKeyEvent& event)
1435 if ((event.GetKeyCode()==314) || (event.GetKeyCode()==317))
1440 if ((event.GetKeyCode()==315) || (event.GetKeyCode()==316))
1447 if (_selectionMoveId == 1) // start
1449 SetStart(GetStart()+step);
1450 createAndSendEvent( wxEVT_TSBAR_START );
1453 if (_selectionMoveId == 2) // end
1455 SetEnd(GetEnd()+step);
1456 createAndSendEvent( wxEVT_TSBAR_END );
1459 if (_selectionMoveId == 3) // actual
1461 SetActual(GetActual()+step);
1462 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1465 if (_selectionMoveId == 4) // bar
1467 if (( GetStart()+step>=_min ) && ( GetEnd()+step<=_max ))
1469 SetStart(GetStart()+step);
1470 SetEnd(GetEnd()+step);
1471 if (_moveActualWithBar)
1473 SetActual(GetActual()+step);
1475 createAndSendEvent( wxEVT_TSBAR_START );
1476 createAndSendEvent( wxEVT_TSBAR_END );
1477 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1478 createAndSendEvent( wxEVT_TSBAR_MOVED );
1479 } // Start>_min && End<_max
1480 }// _selectionMoveId == 4
1486 printf("EED mBarRange::onKey code:%d\n", event.GetKeyCode());