1 //----------------------------------------------------------------------------
5 DEFINE_EVENT_TYPE(wxEVT_TSBAR)
6 DEFINE_EVENT_TYPE(wxEVT_TSBAR_ACTUAL)
7 DEFINE_EVENT_TYPE(wxEVT_TSBAR_START)
8 DEFINE_EVENT_TYPE(wxEVT_TSBAR_END)
9 DEFINE_EVENT_TYPE(wxEVT_TSBAR_MOVED)
10 DEFINE_EVENT_TYPE(wxEVT_SELECTION_END)
12 //----------------------------------------------------------------------------
14 //----------------------------------------------------------------------------
16 IMPLEMENT_CLASS(mBarRange, wxScrolledWindow)
17 BEGIN_EVENT_TABLE(mBarRange, wxScrolledWindow)
18 EVT_PAINT (mBarRange::OnPaint)
19 EVT_SIZE (mBarRange::OnSize)
20 EVT_MOTION (mBarRange::OnMouseMove)
21 EVT_RIGHT_DOWN (mBarRange :: onShowPopupMenu)
22 EVT_MENU(cntID_CHANGE_COLOR, mBarRange :: onChangePartColor)
23 EVT_MENU(cntID_ENABLE_ACTUAL, mBarRange :: onEnableRange_Actual)
24 EVT_MENU(cntID_MOVABLE_ACTUAL_BAR, mBarRange :: onMovable_ActualWithBar)
27 EVT_LEFT_DOWN( mBarRange :: onLeftClicDown)
28 EVT_LEFT_UP( mBarRange :: onLeftClickUp)
30 //how to catch the new event (our event)
31 //EVT_COMMAND (ID_MY_WINDOW, wxEVT_MY_EVENT, MyFrame::OnMyEvent)
35 //----------------------------------------------------------------------------
37 //----------------------------------------------------------------------------
39 mBarRange::mBarRange(wxWindow *parent, int w, int h)
40 :wxScrolledWindow(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
47 trianglesHalfWidth = 5;
49 wxColour start_Colour;
51 // Setting the default parts colors
52 start_Colour = wxColour(0,0,255);
53 actual_Colour = wxColour(255,255,202);
54 end_Colour = wxColour(0,0,255);
55 bar_Colour = wxColour(255,0,255);
56 backgroundColor = parent ->GetBackgroundColour();
57 guideLineColor = wxColour(255,0,0);
59 //actual is in _start and end
60 //false means that it could be anywhere
61 _moveActualWithBar = false;
62 _in_rangeProperty = false;
63 _selectionMoveId = -1;
64 realX_vertical_line = -1;
70 setIfWithActualDrawed(true);
72 b_popmenu.Append (cntID_CHANGE_COLOR, _("Change Color"), _("Changes the color of the selected part"));
73 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
74 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
79 //----------------------------------------------------------------------------
81 //----------------------------------------------------------------------------
83 mBarRange::~mBarRange()
86 //---------------------------------------------------------------------------
87 //Draw bar: vertical or Horizontal
88 //---------------------------------------------------------------------------
89 void mBarRange::DrawBar()
94 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
95 _bitmap_bar = new wxBitmap(_w+1280,_h+100);
96 //SIL//_bitmap_info = new wxBitmap(_w+100+1280, _h+100);
101 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
102 _bitmap_bar = new wxBitmap(_h+deviceStart_y+100,_w+1280);
103 _bitmap_info = new wxBitmap(_h+deviceStart_y+100, _w+1280);
106 //----------------------------------------------------------------------------
108 //----------------------------------------------------------------------------
109 //----------------------------------------------------------------------------
110 //the property condition on actual triangle
111 //----------------------------------------------------------------------------
112 bool mBarRange::GetInRangeProperty()
114 return _in_rangeProperty;
116 //----------------------------------------------------------------------------
117 void mBarRange::SetInRangeProperty(bool in)
119 _in_rangeProperty=in;
121 //----------------------------------------------------------------------------
122 //the information about the actual triangle in range or not, true if is between start and end
123 //----------------------------------------------------------------------------
124 bool mBarRange::IsActualInRange()
126 return ( _actual <= _end && _actual >= _start );
129 //----------------------------------------------------------------------------
130 // the position of the rectangle, vertical or horizontal
131 //----------------------------------------------------------------------------
132 bool mBarRange::GetOrientation()
136 //-----------------------------------------------------------------------------
137 void mBarRange::SetOrientation(bool orientation)
143 _orientation=orientation;
146 //----------------------------------------------------------------------------
147 // _start of the pixel rectangle
148 //----------------------------------------------------------------------------
150 int mBarRange::GetPixelStart()
152 return ((_start - _min)*(_w-deviceEndMargin))/(_max - _min);
154 //----------------------------------------------------------------------------
155 // param i: value in pixels
156 //----------------------------------------------------------------------------
157 void mBarRange::SetPixelStart(int i)
159 _start = _min+((i - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
162 //----------------------------------------------------------------------------
163 // _actual of the pixel rectangle
164 //----------------------------------------------------------------------------
165 int mBarRange::GetPixelActual()
167 return ((_actual - _min)*(_w-deviceEndMargin))/(_max - _min);
169 //----------------------------------------------------------------------------
170 // param i: value in pixels
171 //----------------------------------------------------------------------------
172 void mBarRange::SetPixelActual(int i)
174 _actual = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
176 //----------------------------------------------------------------------------
177 // _end of the pixel rectangle
178 //----------------------------------------------------------------------------
179 int mBarRange::GetPixelEnd()
181 return ((_end - _min)*(_w-deviceEndMargin))/(_max - _min);
183 //----------------------------------------------------------------------------
184 // param i: value in pixels to be converted to real logical value
185 //----------------------------------------------------------------------------
186 void mBarRange::SetPixelEnd(int i)
188 _end = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
190 //----------------------------------------------------------------------------
191 // Logical max of the triangle
192 //----------------------------------------------------------------------------
194 double mBarRange::GetMax()
199 //----------------------------------------------------------------------------
200 void mBarRange::SetMax(double i)
204 //----------------------------------------------------------------------------
205 // Logical min of the triangle
206 //----------------------------------------------------------------------------
208 double mBarRange::GetMin()
213 //----------------------------------------------------------------------------
214 void mBarRange::SetMin(double i)
219 //----------------------------------------------------------------------------
220 // pixel dimensions of the rectangle
221 //----------------------------------------------------------------------------
223 int mBarRange::GetWidth()
227 //----------------------------------------------------------------------------
228 void mBarRange::SetWidth(int w)
232 //----------------------------------------------------------------------------
233 int mBarRange::GetHeight()
238 //----------------------------------------------------------------------------
239 void mBarRange::SetHeight(int h)
244 //----------------------------------------------------------------------------
245 // Logical Start of the rectangle
246 //----------------------------------------------------------------------------
248 int mBarRange::GetStart()
253 //----------------------------------------------------------------------------
254 // param start: value real units
255 //----------------------------------------------------------------------------
256 void mBarRange::SetStart(int newstart)
263 //----------------------------------------------------------------------------
264 // Logical End of the rectangle
265 //----------------------------------------------------------------------------
267 int mBarRange::GetEnd()
271 //----------------------------------------------------------------------------
272 // param end: value pixel units
273 //----------------------------------------------------------------------------
274 void mBarRange::SetEnd(int nwend)
281 //----------------------------------------------------------------------------
282 // logical Actual of the rectangle
283 //----------------------------------------------------------------------------
284 int mBarRange::GetActual()
288 //----------------------------------------------------------------------------
289 void mBarRange::SetActual(int actual)
293 else if (actual>_max)
299 //----------------------------------------------------------------------------
301 //----------------------------------------------------------------------------
302 int mBarRange::GetTrianglesHalfWidth()
304 return trianglesHalfWidth;
306 //----------------------------------------------------------------------------
307 void mBarRange::SetTrianglesHalfWidth(int nwTriHalfWidth)
309 trianglesHalfWidth = nwTriHalfWidth;
312 void mBarRange::OnSize( wxSizeEvent &WXUNUSED(event) )
314 wxRect rectTotal = GetClientRect();
317 SetWidth( rectTotal.GetWidth() - deviceEndMargin );
321 SetWidth( rectTotal.GetHeight() - deviceEndMargin);
323 _selectionMoveId = -1;
327 //----------------------------------------------------------------------------
329 void mBarRange::Refresh(bool eraseBackground, const wxRect* rect)
333 //ff=fopen ("c:/temp/xxx.txt", "a+");
334 //fprintf( ff , "mBarRange :: Refresh 01\n" );
337 wxScrolledWindow::Refresh(false);
341 //ff=fopen ("c:/temp/xx.txt", "a+");
342 //fprintf( ff , "mBarRange :: Refresh 02\n" );
347 //----------------------------------------------------------------------------
349 //----------------------------------------------------------------------------
350 void mBarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
355 //ff=fopen ("c:/temp/xx.txt", "a+");
356 //fprintf( ff , "pColorBar :: OnPaint 01\n" );
359 if (_bitmap_bar!=NULL){
363 RefreshHorizontalView();
365 temp_dc.SelectObject( *_bitmap_bar );
366 wxPaintDC dc( this );
367 dc.Blit(deviceStart_x-(trianglesHalfWidth+2), deviceStart_y, _w-deviceEndMargin+2*(trianglesHalfWidth+2), _h, &temp_dc, 0, 0);
369 // if (_visibleLables)
371 // temp_dc.SelectObject( *_bitmap_info );
372 // dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+200, &temp_dc, deviceStart_x, deviceStart_y);
373 // //dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+60, &temp_dc, 0, 0);
377 RefreshVerticalView();
379 temp_dc.SelectObject( *_bitmap_bar );
380 wxPaintDC dc( this );
381 // dc.Blit(deviceStart_y,deviceStart_x, _h+deviceStart_y-deviceEndMargin,_w+deviceStart_x-deviceEndMargin, &temp_dc, 0, 0);
382 dc.Blit(deviceStart_y,deviceStart_x-(trianglesHalfWidth+2), _h,_w-deviceEndMargin+2*(trianglesHalfWidth+2), &temp_dc, 0, 0);
385 // if (_visibleLables)
387 // temp_dc.SelectObject( *_bitmap_info );
388 // dc.Blit(0,_w, _h+deviceStart_y+200, _w+deviceStart_x+200-deviceEndMargin, &temp_dc, deviceStart_y,_w+deviceStart_x);
396 //ff=fopen ("c:/temp/xx.txt", "a+");
397 //fprintf( ff , "pColorBar :: OnPaint 02\n" );
402 //----------------------------------------------------------------------------
403 //Repaint the bar if it is horizontal
404 //----------------------------------------------------------------------------
405 void mBarRange::RefreshHorizontalView()
410 //ff=fopen ("c:/temp/xxx.txt", "a+");
411 //fprintf( ff , "mBarRange :: RefreshHorizontalView 01\n" );
416 int largestNumberWidthInPixels = 15;
417 int pxStart=GetPixelStart();
418 int pxEnd=GetPixelEnd();
419 int pxActual=GetPixelActual();
422 int letterHeight = 9;
423 int barHeight = 2*letterHeight;
424 int tempHeight = _h-(6*letterHeight);
429 barHeight = (tempHeight>0) ? tempHeight : (int) _h/2;
435 temp_dc.SelectObject( *_bitmap_bar );
438 // Background of this widget
441 temp_dc.SetPen(wxPen( backgroundColor ));
442 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
444 temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
447 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
448 temp_dc.DrawLine(trianglesHalfWidth+2, 0, _w-deviceEndMargin, 0);
449 temp_dc.DrawLine(trianglesHalfWidth+2, barHeight, (_w-deviceEndMargin-trianglesHalfWidth-2), barHeight);
450 temp_dc.SetDeviceOrigin(trianglesHalfWidth+2,0);
454 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
455 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
456 temp_dc.DrawRectangle( pxStart , 0, pxEnd-pxStart, barHeight);
460 if( _selectionMoveId==4 )
462 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
463 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
467 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
468 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
470 temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
472 // 2 Shadow Triangles: Start and End
473 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
474 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
476 points[0].y= barHeight;
477 points[1].x= -trianglesHalfWidth-1;
479 points[2].x= trianglesHalfWidth+2;
481 temp_dc.DrawPolygon(3,points,pxStart,0);
482 temp_dc.DrawPolygon(3,points,pxEnd,0);
484 // 2 Triangles: Start and End
485 points[1].x = -trianglesHalfWidth;
486 points[2].x = trianglesHalfWidth;
488 //first triangle (start)
489 if( _selectionMoveId == 1 )
491 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
492 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
496 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
497 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
499 temp_dc.DrawPolygon(3,points,pxStart,0);
500 //second triangle (end)
501 if( _selectionMoveId == 2 )
503 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
504 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
508 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
509 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
511 temp_dc.DrawPolygon(3,points,pxEnd,0);
513 if( withActualDrawed )
515 // 1 Shadow Triangle: Actual
516 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
517 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
518 points[1].x = -trianglesHalfWidth-1;
519 points[2].x = trianglesHalfWidth+2;
521 temp_dc.DrawPolygon(3,points,pxActual,0);
523 // 1 Triangle: Actual (red)
524 if( _selectionMoveId==3 )
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( actual_Colour,wxSOLID ));
532 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
534 points[1].x = -trianglesHalfWidth;
535 points[2].x = trianglesHalfWidth;
536 temp_dc.DrawPolygon(3,points,pxActual,0);
539 if (realX_vertical_line!=-1)
541 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
542 int pixelX_guide = ((realX_vertical_line - _min)*(_w-deviceEndMargin))/(_max - _min) ;
543 temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, barHeight);
546 //Information Device drawing
550 //temp_dc.SelectObject( *_bitmap_info );
551 /*temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID ));
552 temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID ));*/
553 //temp_dc.DrawRectangle(deviceStart_x,_h+deviceStart_y,_w+deviceStart_x+40,_h+deviceStart_y+40);
554 //temp_dc.DrawRectangle(0,_h,_w+40-deviceEndMargin,_h+40);
556 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
557 temp_dc.SetFont(font);
558 temp_dc.SetTextForeground(*wxBLACK);
561 //the **MIN** value, always at the same y level that corresponds to barHeight+1
563 // text_min<< GetMin();
564 text_min.Printf(_T("%d"), (int)GetMin() );
566 temp_dc.DrawText(text_min,0,barHeight+1);
568 //the **MAX** value always at the same place
570 // text_max << GetMax();
571 text_max.Printf(_T("%d"), (int)GetMax() );
573 //As there is a margin of 40 extra most numbers (max) should be visibles
574 // stringSize = temp_dc.GetTextExtent(text_max);
576 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
577 wxSize stringSize(tmpX,tmpY);
579 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth())/*2*trianglesHalfWidth*/,barHeight+1);
581 //show logical values
582 //show the **START TRIANGLE** value
584 // text_start << GetStart();
585 text_start.Printf(_T("%d"), (int)GetStart() );
587 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
588 //show the **END TRIANGLE** value
590 // text_end << GetEnd();
591 text_end.Printf(_T("%d"), (int)GetEnd() );
593 // stringSize = temp_dc.GetTextExtent(text_end);
594 temp_dc.GetTextExtent(text_end,&tmpX,&tmpY);
595 stringSize.SetHeight(tmpY);
596 stringSize.SetWidth(tmpX);
597 temp_dc.DrawText(text_end, pxEnd-stringSize.GetWidth(),barHeight+3*letterHeight);
598 if( withActualDrawed )
600 //show the actual value of actual
601 wxString text_actual;
602 // text_actual << GetActual();
603 text_actual.Printf(_T("%d"), (int)GetActual() );
604 // stringSize = temp_dc.GetTextExtent(text_actual);
605 temp_dc.GetTextExtent(text_actual,&tmpX,&tmpY);
606 stringSize.SetHeight(tmpY);
607 stringSize.SetWidth(tmpX);
608 temp_dc.DrawText(text_actual, pxActual-(stringSize.GetWidth()/2),barHeight+letterHeight);
613 //ff=fopen ("c:/temp/xxx.txt", "a+");
614 //fprintf( ff , "mBarRange :: RefreshHorizontalView 02\n" );
618 //----------------------------------------------------------------------------
619 //Repaint the bar if it is vertical
620 //----------------------------------------------------------------------------
622 void mBarRange::RefreshVerticalView()
627 //ff=fopen ("c:/temp/xxx.txt", "a+");
628 //fprintf( ff , "mBarRange :: RefreshVerticalView 01\n" );
632 int px1=GetPixelStart();
633 int px2=GetPixelEnd();
634 int px3=GetPixelActual();
635 int letterHeight = 9;
636 int panelHeight = 9*3+_w;
641 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
647 temp_dc.SelectObject( *_bitmap_bar );
650 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
651 temp_dc.SetPen(wxPen( backgroundColor ));
653 temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
656 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
657 temp_dc.DrawLine(0,trianglesHalfWidth+2, 0, _w-deviceEndMargin);
658 temp_dc.DrawLine(barWidth, trianglesHalfWidth+2, barWidth, (_w-deviceEndMargin-trianglesHalfWidth-2));
659 temp_dc.SetDeviceOrigin(0,trianglesHalfWidth+2);
662 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
663 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
664 temp_dc.DrawRectangle( 0,px1 ,_h, px2-px1 );
668 if( _selectionMoveId==4 )
670 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
671 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
675 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
676 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
678 temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
681 // 2 Shadow Triangles: Start and End
685 points[1].y=-trianglesHalfWidth-1;
687 points[2].y=trianglesHalfWidth+2;
688 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
689 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
690 temp_dc.DrawPolygon(3,points,0,px1);
691 temp_dc.DrawPolygon(3,points,0,px2);
693 // 2 Triangles: Start and End
697 points[1].y=-trianglesHalfWidth;
699 points[2].y=trianglesHalfWidth;
700 //first triangle (start)
701 if( _selectionMoveId==1 )
703 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
704 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
708 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
709 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
711 temp_dc.DrawPolygon(3,points,0,px1);
712 //second triangle (end)
713 if( _selectionMoveId==2 )
715 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
716 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
720 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
721 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
723 temp_dc.DrawPolygon(3,points,0,px2);
725 if( withActualDrawed )
727 // 1 Shadow Triangle: Actual
728 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
729 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
733 points[1].y=-trianglesHalfWidth-1;
735 points[2].y=trianglesHalfWidth+2;
736 temp_dc.DrawPolygon(3,points,0,px3);
738 // 1 Triangle: Actual (red)
742 points[1].y = -trianglesHalfWidth;
744 points[2].y = trianglesHalfWidth;
745 if( _selectionMoveId==3 )
747 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
748 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
752 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
753 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
755 temp_dc.DrawPolygon(3,points,0,px3);
758 if (realX_vertical_line!=-1)
760 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
761 int pixelX_guide = realX_vertical_line*_w/(_max-_min)+deviceStart_x;
762 temp_dc.DrawLine(0,pixelX_guide, _h, pixelX_guide);
765 //Information Device drawing
768 /*temp_dc.SelectObject( *_bitmap_info );
770 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
771 temp_dc.SetPen(wxPen( backgroundColor ,1,wxSOLID ));
772 temp_dc.DrawRectangle(deviceStart_y,_w+deviceStart_x,_h+deviceStart_y+200,_w+deviceStart_x+200);
775 temp_dc.SetBackgroundMode(wxTRANSPARENT);
776 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
777 temp_dc.SetFont(font);
778 temp_dc.SetTextForeground(*wxBLACK);
780 //show logical values
781 //show the actual value of start
783 // text_start<<"Start:"<< GetStart();
784 text_start.Printf(_T("%s %d"),_T("Start: "), (int)GetStart() );
785 temp_dc.DrawText( text_start ,deviceStart_y, _w+deviceStart_x+letterHeight+1);
786 //show the actual value of end
788 // text_end <<"End: "<<GetEnd();
789 text_end.Printf(_T("%s %d"),_T("End: "), (int)GetEnd() );
790 temp_dc.DrawText( text_end ,deviceStart_y,_w+deviceStart_x+letterHeight*2 );
791 if( withActualDrawed )
793 //show the actual value of actual
794 wxString text_actual;
795 // text_actual <<"Actual: " <<GetActual();
796 text_actual.Printf(_T("%s %d"),_T("Actual: "), (int)GetActual() );
797 temp_dc.DrawText( text_actual ,deviceStart_y,_w+deviceStart_x+letterHeight*3);
799 //the min value, always at the same place
801 // text_min<<"Min: " << GetMin();
802 text_min.Printf(_T("%s %d"),_T("Min: "), (int)GetMin() );
803 temp_dc.DrawText( text_min ,deviceStart_y,_w+deviceStart_x+3);
804 //the max value always at the samen place
806 // text_max <<"Max: "<< GetMax();
807 text_max.Printf(_T("%s %d"),_T("Max: "), (int)GetMax() );
808 //toca calcular cuantol lo corremos
809 temp_dc.DrawText(text_max,deviceStart_y,_w+deviceStart_x+43);
814 //----------------------------------------------------------------------------
815 void mBarRange::RefreshForce()
820 //----------------------------------------------------------------------------
821 void mBarRange::OnMouseMove(wxMouseEvent& event )
825 //ff=fopen ("c:/temp/xxx.txt", "a+");
826 //fprintf( ff , "mBarRange :: OnMouseMove 01\n" );
829 int px1=GetPixelStart();
830 int px2=GetPixelEnd();
831 int px3=GetPixelActual();
834 wxPoint point = event.GetPosition();
838 setClickedX(point.x);
843 setClickedX(point.y);
846 int logicClick = getLogicValueofPixel(clickedX);
848 if( _selectionMoveId==-1 )
852 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
853 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
854 bool in_actualT= withActualDrawed && (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
855 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
858 _selectionMoveId = 3;
860 _selectionMoveId = 1;
862 _selectionMoveId = 2;
863 else if( in_movingBar )
864 _selectionMoveId = 4;
871 //is in start triagle
872 if( _selectionMoveId ==1 && event.LeftIsDown())
874 bool validPos_StartTri = (logicClick<GetEnd() && logicClick >=_min);
875 if( validPos_StartTri && !_in_rangeProperty)
877 SetPixelStart(clickedX);
879 RefreshHorizontalView();
880 //-------------------------------------------
881 // Sending the event of start triangle moved
882 //-------------------------------------------
883 createAndSendEvent( wxEVT_TSBAR_START );
885 //start has to be less than actual
886 else if (validPos_StartTri && _in_rangeProperty)
888 if(logicClick<=GetActual())
890 SetPixelStart(clickedX);
892 // RefreshHorizontalView();
893 //-------------------------------------------
894 // Sending the event of start triangle moved
895 //-------------------------------------------
896 createAndSendEvent( wxEVT_TSBAR_START );
899 } // _selectionMoveId == 1
901 else if( _selectionMoveId == 2 && event.LeftIsDown() )
903 bool validPos_EndTri = logicClick>GetStart()&& logicClick<=_max;
904 if( validPos_EndTri && !_in_rangeProperty )
906 SetPixelEnd(clickedX);
908 // RefreshHorizontalView();
909 //-------------------------------------------
910 //Sending the event of end triangle moved
911 //-------------------------------------------
912 createAndSendEvent( wxEVT_TSBAR_END );
914 //the end triangle cant be less than actual
915 else if( validPos_EndTri && _in_rangeProperty )
917 if(logicClick>=GetActual())
919 SetPixelEnd(clickedX);
921 // RefreshHorizontalView();
922 //-------------------------------------------
923 //Sending the event of end triangle moved
924 //-------------------------------------------
925 createAndSendEvent( wxEVT_TSBAR_END );
929 //is the actual triangle
930 else if( _selectionMoveId == 3 && event.LeftIsDown())
932 bool validPos_ActualTri=(logicClick<=_max) && (logicClick>=_min);
933 //is in actual triangle but it could be anywhere
934 if( validPos_ActualTri && !_in_rangeProperty )
936 SetPixelActual(clickedX);
938 RefreshHorizontalView();
939 //-------------------------------------------
940 //Sending the event of actual triangle moved
941 //-------------------------------------------
942 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
944 else if( validPos_ActualTri && _in_rangeProperty )
945 // the tringle in between start and end
947 if( logicClick>=GetStart() && logicClick<=GetEnd())
949 SetPixelActual(clickedX);
951 RefreshHorizontalView();
952 //-------------------------------------------
953 //Sending the event of actual triangle moved
954 //-------------------------------------------
955 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
960 else if ( _selectionMoveId == 4 && event.LeftIsDown() )
962 //FILE * f=fopen("E:/borrar/file.txt","a+");
963 if(_initialPoint == 0)
965 _initialPoint = logicClick;
966 logicInitial_start = GetStart();
967 logicInitial_end = GetEnd();
968 logicInitial_actual = GetActual();
969 //SIL//fprintf(f,"\n\n---- Inicia draggin:\n logicInitial_start:%d, logicInitial_end:%d,logicInitial_actual:%d \n", _initialPoint,logicInitial_start,logicInitial_end,logicInitial_actual);
971 int difference = logicClick -_initialPoint;
972 int next_end = difference + logicInitial_end;
973 int next_start = difference + logicInitial_start;
974 int next_actual = difference + logicInitial_actual;
976 /*SIL//fprintf(f,"diff:%d, next_end%d, next_start%d, next_actual%d \n", difference,next_end,next_start,next_actual);
979 //if actual is not fixed to be in the middle
980 if( ((logicClick>next_start) && (logicClick<next_end)&& (next_end<=_max)&& (next_start>=_min)) && !_in_rangeProperty)
982 SetStart(next_start);
984 if( _moveActualWithBar )
986 SetActual (next_actual);
987 //-------------------------------------------
988 //Sending the event of actual triangle moved
989 //-------------------------------------------
990 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
993 RefreshHorizontalView();
995 //-------------------------------------------
996 // Sending the event that the bar ahs being moved
997 //-------------------------------------------
998 createAndSendEvent( wxEVT_TSBAR_MOVED );
1000 //if actual has to be between start and end
1001 else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
1003 SetStart(next_start);
1005 if( _moveActualWithBar )
1007 SetActual (next_actual);
1008 //-------------------------------------------
1009 //Sending the event of actual triangle moved
1010 //-------------------------------------------
1011 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1014 RefreshHorizontalView();
1016 //-------------------------------------------
1017 // Sending the event that the bar ahs being moved
1018 //-------------------------------------------
1019 createAndSendEvent( wxEVT_TSBAR_MOVED );
1023 if( !event.LeftIsDown())
1026 _selectionMoveId = -1;
1028 //-------------------------------------------
1029 //Sending a general event just because
1030 //-------------------------------------------
1031 //SIL//createAndSendEvent( wxEVT_TSBAR );
1032 createAndSendEvent(wxEVT_SELECTION_END);
1038 //ff=fopen ("c:/temp/xxx.txt", "a+");
1039 //fprintf( ff , " mBarRange :: OnMouseMove 02\n" );
1044 * Sets the represented minimum and maximunm values
1045 * param minRealValue The minimum represented value (real value)
1046 * param maxRealValue The maximum represented value (real value)
1048 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
1050 _min = minRealValue;
1051 _max = maxRealValue;
1057 * Sets the property for viewing or not the bar labels information
1059 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
1061 _visibleLables = setVisibleLB;
1065 * Sets the property for viewing or not the bar labels information
1066 * return _visibleLables The state of visible labels or not
1068 bool mBarRange ::getIfVisibleLabels ()
1070 return _visibleLables;
1074 * Sets the device start drawing left-superior (pixel) start point
1075 * param deviceStart_x Pixel start for x-coord
1076 * param deviceStart_y Pixel start for y-coord
1078 void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1080 deviceStart_x = devStart_x;
1081 deviceStart_y = devStart_y;
1082 // For the initialization case
1083 if (GetPixelEnd()<0)
1087 SetPixelStart(deviceStart_x);
1088 SetPixelEnd(_w+deviceStart_x);
1089 SetPixelActual(deviceStart_x);
1093 SetPixelStart(deviceStart_x);
1094 SetPixelEnd(_h+deviceStart_x);
1095 SetPixelActual(deviceStart_x);
1102 * Shows the popup menu
1104 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1108 bool validClic = false;
1111 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1115 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1120 setClickedX(event.GetX());
1122 setClickedX(event.GetY());
1124 if (getClickedX()<=_h)
1126 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1127 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1128 bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1129 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1132 _selectionMoveId = 1;
1133 else if( in_EndTri )
1134 _selectionMoveId = 2;
1135 else if( in_actualT )
1136 _selectionMoveId = 3;
1137 else if( in_movingBar )
1138 _selectionMoveId = 4;
1140 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1146 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1147 * param & anEvent The wxCommandEvent actioned event
1149 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1151 bool okSelectedColor = false;
1152 wxColour selectedColour;
1154 wxColourDialog dialog( GetParent(), &data);
1156 if ( dialog.ShowModal() == wxID_OK )
1158 selectedColour = dialog.GetColourData().GetColour();
1159 okSelectedColor = true;
1161 if( okSelectedColor )
1163 if (_selectionMoveId==1 )
1164 start_Colour = selectedColour;
1165 else if (_selectionMoveId==2 )
1166 end_Colour = selectedColour;
1167 else if( _selectionMoveId==3 )
1168 actual_Colour = selectedColour;
1169 else if( _selectionMoveId==4 )
1170 bar_Colour = selectedColour;
1172 _selectionMoveId = -1;
1178 * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1179 * param & anEvent The wxCommandEvent actioned event
1181 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1183 if (!_in_rangeProperty)
1185 if(IsActualInRange())
1187 SetInRangeProperty (true);
1188 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1193 SetInRangeProperty (false);
1194 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
1199 * Reacts to the cntID_MOVABLE_ACTUAL_BAR wxCommandEvent by enabling or disabling the property of moving the actual triangle with the bar, just when it is inside of it.
1200 * param & anEvent The wxCommandEvent actioned event
1202 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1204 if (_moveActualWithBar )
1206 _moveActualWithBar = false;
1207 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1211 if(IsActualInRange())
1213 _moveActualWithBar = true;
1214 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1221 * param activeNow The new state
1223 void mBarRange :: setActiveStateTo (bool activeNow)
1225 activeState = activeNow;
1229 * Gets the active state of the bar
1230 * return activeState The actual state
1232 bool mBarRange :: isActive()
1238 * Gets the real-x value to draw a vertical line
1239 * return realX_vertical_line The real x value for the vertical line
1241 int mBarRange :: getRealX_vertical_line()
1243 return realX_vertical_line;
1247 * Sets the real-x value to draw a vertical line
1248 * param newReal_x The new real x value for the vertical line
1250 void mBarRange :: setRealX_vertical_line(int newReal_x)
1252 realX_vertical_line = newReal_x;
1256 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1257 * return deviceEndMargin The value asigned to the right margin
1259 int mBarRange :: getDeviceEndX()
1261 return deviceEndMargin;
1265 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1266 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1268 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1270 deviceEndMargin = newDeviceEnd_pixels;
1274 * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1275 * return clickedX The x-coord pixel value
1277 int mBarRange :: getClickedX()
1283 * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1284 * param nwClickX The x-coord pixel value
1286 void mBarRange :: setClickedX(int nwClickX)
1288 clickedX = nwClickX;
1293 * Gets the start porcentage with respect to the represented values of the bar
1294 * return The porcentage represented by the start showing point
1296 float mBarRange :: getStartShowPorcentage()
1298 return (float)( 1+(_start - _max)/(_max-_min));
1302 * Gets the end porcentage with respect to the represented values of the bar
1303 * return The porcentage represented by the end showing point
1305 float mBarRange :: getEndShowPorcentage()
1307 return (float) (1+(_end - _max)/(_max-_min));
1311 * Gets the actual porcentage with respect to the represented values of the bar
1312 * return The porcentage represented by the actual showing point
1314 float mBarRange :: getActualShowPorcentage()
1316 return (float) (1+(_actual - _max)/(_max-_min));
1319 int mBarRange :: getLogicValueofPixel(int thePixel)
1321 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1325 * Sets the condition for knowing if the actual triangle is being drawed or not
1326 * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1328 void mBarRange :: setIfWithActualDrawed(bool drawActual)
1330 if(!withActualDrawed && drawActual)
1332 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1333 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
1335 else if (withActualDrawed && !drawActual)
1337 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1338 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1340 withActualDrawed = drawActual;
1345 * Gets the condition for knowing if the actual triangle is being drawed or not
1346 * return withActualDrawed The condition for drawing or not the actual control
1348 bool mBarRange :: getIfWithActualDrawed()
1350 return withActualDrawed;
1353 void mBarRange :: createAndSendEvent(WXTYPE theEventType)
1355 wxCommandEvent cevent( theEventType, GetId() );
1356 cevent.SetEventObject( this );
1357 GetEventHandler()->ProcessEvent( cevent );
1361 * Sets the background color od the bar
1362 * theColor The color to set to the backgroundColor
1364 void mBarRange :: setBackgroundColor(wxColour theColor)
1366 backgroundColor = theColor;
1370 * Sets the guide line color
1371 * param theNwGuideLineColor The color to set to the guideLineColor
1373 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1375 guideLineColor = theNwGuideLineColor;
1379 * Gets the guide line color
1380 * return guideLineColor The color of the guideLine
1382 wxColour mBarRange :: getGuideLineColour()
1384 return guideLineColor;
1387 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
1389 acceptedClick = true;
1392 void mBarRange ::onLeftClickUp(wxMouseEvent& event )
1394 acceptedClick = false;