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; // JPRx
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(); // JPRx
830 //int px2=GetPixelEnd(); // JPRx
831 //int px3=GetPixelActual(); // JPRx
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 );
943 printf("EED mBarRange::OnMouseMove \n");
945 else if( validPos_ActualTri && _in_rangeProperty )
946 // the tringle in between start and end
948 if( logicClick>=GetStart() && logicClick<=GetEnd())
950 SetPixelActual(clickedX);
952 RefreshHorizontalView();
953 //-------------------------------------------
954 //Sending the event of actual triangle moved
955 //-------------------------------------------
956 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
961 else if ( _selectionMoveId == 4 && event.LeftIsDown() )
963 //FILE * f=fopen("E:/borrar/file.txt","a+");
964 if(_initialPoint == 0)
966 _initialPoint = logicClick;
967 logicInitial_start = GetStart();
968 logicInitial_end = GetEnd();
969 logicInitial_actual = GetActual();
970 //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);
972 int difference = logicClick -_initialPoint;
973 int next_end = difference + logicInitial_end;
974 int next_start = difference + logicInitial_start;
975 int next_actual = difference + logicInitial_actual;
977 /*SIL//fprintf(f,"diff:%d, next_end%d, next_start%d, next_actual%d \n", difference,next_end,next_start,next_actual);
980 //if actual is not fixed to be in the middle
981 if( ((logicClick>next_start) && (logicClick<next_end)&& (next_end<=_max)&& (next_start>=_min)) && !_in_rangeProperty)
983 SetStart(next_start);
985 if( _moveActualWithBar )
987 SetActual (next_actual);
988 //-------------------------------------------
989 //Sending the event of actual triangle moved
990 //-------------------------------------------
991 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
994 RefreshHorizontalView();
996 //-------------------------------------------
997 // Sending the event that the bar ahs being moved
998 //-------------------------------------------
999 createAndSendEvent( wxEVT_TSBAR_MOVED );
1001 //if actual has to be between start and end
1002 else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
1004 SetStart(next_start);
1006 if( _moveActualWithBar )
1008 SetActual (next_actual);
1009 //-------------------------------------------
1010 //Sending the event of actual triangle moved
1011 //-------------------------------------------
1012 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1015 RefreshHorizontalView();
1017 //-------------------------------------------
1018 // Sending the event that the bar ahs being moved
1019 //-------------------------------------------
1020 createAndSendEvent( wxEVT_TSBAR_MOVED );
1024 if( !event.LeftIsDown())
1027 _selectionMoveId = -1;
1029 //-------------------------------------------
1030 //Sending a general event just because
1031 //-------------------------------------------
1032 //SIL//createAndSendEvent( wxEVT_TSBAR );
1033 createAndSendEvent(wxEVT_SELECTION_END);
1039 //ff=fopen ("c:/temp/xxx.txt", "a+");
1040 //fprintf( ff , " mBarRange :: OnMouseMove 02\n" );
1045 * Sets the represented minimum and maximunm values
1046 * param minRealValue The minimum represented value (real value)
1047 * param maxRealValue The maximum represented value (real value)
1049 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
1051 _min = minRealValue;
1052 _max = maxRealValue;
1058 * Sets the property for viewing or not the bar labels information
1060 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
1062 _visibleLables = setVisibleLB;
1066 * Sets the property for viewing or not the bar labels information
1067 * return _visibleLables The state of visible labels or not
1069 bool mBarRange ::getIfVisibleLabels ()
1071 return _visibleLables;
1075 * Sets the device start drawing left-superior (pixel) start point
1076 * param deviceStart_x Pixel start for x-coord
1077 * param deviceStart_y Pixel start for y-coord
1079 void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1081 deviceStart_x = devStart_x;
1082 deviceStart_y = devStart_y;
1083 // For the initialization case
1084 if (GetPixelEnd()<0)
1088 SetPixelStart(deviceStart_x);
1089 SetPixelEnd(_w+deviceStart_x);
1090 SetPixelActual(deviceStart_x);
1094 SetPixelStart(deviceStart_x);
1095 SetPixelEnd(_h+deviceStart_x);
1096 SetPixelActual(deviceStart_x);
1103 * Shows the popup menu
1105 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1109 bool validClic = false;
1112 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1116 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1121 setClickedX(event.GetX());
1123 setClickedX(event.GetY());
1125 if (getClickedX()<=_h)
1127 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1128 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1129 bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1130 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1133 _selectionMoveId = 1;
1134 else if( in_EndTri )
1135 _selectionMoveId = 2;
1136 else if( in_actualT )
1137 _selectionMoveId = 3;
1138 else if( in_movingBar )
1139 _selectionMoveId = 4;
1141 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1147 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1148 * param & anEvent The wxCommandEvent actioned event
1150 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1152 bool okSelectedColor = false;
1153 wxColour selectedColour;
1155 wxColourDialog dialog( GetParent(), &data);
1157 if ( dialog.ShowModal() == wxID_OK )
1159 selectedColour = dialog.GetColourData().GetColour();
1160 okSelectedColor = true;
1162 if( okSelectedColor )
1164 if (_selectionMoveId==1 )
1165 start_Colour = selectedColour;
1166 else if (_selectionMoveId==2 )
1167 end_Colour = selectedColour;
1168 else if( _selectionMoveId==3 )
1169 actual_Colour = selectedColour;
1170 else if( _selectionMoveId==4 )
1171 bar_Colour = selectedColour;
1173 _selectionMoveId = -1;
1179 * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1180 * param & anEvent The wxCommandEvent actioned event
1182 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1184 if (!_in_rangeProperty)
1186 if(IsActualInRange())
1188 SetInRangeProperty (true);
1189 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1194 SetInRangeProperty (false);
1195 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
1200 * 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.
1201 * param & anEvent The wxCommandEvent actioned event
1203 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1205 if (_moveActualWithBar )
1207 _moveActualWithBar = false;
1208 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1212 if(IsActualInRange())
1214 _moveActualWithBar = true;
1215 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1222 * param activeNow The new state
1224 void mBarRange :: setActiveStateTo (bool activeNow)
1226 activeState = activeNow;
1230 * Gets the active state of the bar
1231 * return activeState The actual state
1233 bool mBarRange :: isActive()
1239 * Gets the real-x value to draw a vertical line
1240 * return realX_vertical_line The real x value for the vertical line
1242 int mBarRange :: getRealX_vertical_line()
1244 return realX_vertical_line;
1248 * Sets the real-x value to draw a vertical line
1249 * param newReal_x The new real x value for the vertical line
1251 void mBarRange :: setRealX_vertical_line(int newReal_x)
1253 realX_vertical_line = newReal_x;
1257 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1258 * return deviceEndMargin The value asigned to the right margin
1260 int mBarRange :: getDeviceEndX()
1262 return deviceEndMargin;
1266 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1267 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1269 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1271 deviceEndMargin = newDeviceEnd_pixels;
1275 * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1276 * return clickedX The x-coord pixel value
1278 int mBarRange :: getClickedX()
1284 * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1285 * param nwClickX The x-coord pixel value
1287 void mBarRange :: setClickedX(int nwClickX)
1289 clickedX = nwClickX;
1294 * Gets the start porcentage with respect to the represented values of the bar
1295 * return The porcentage represented by the start showing point
1297 float mBarRange :: getStartShowPorcentage()
1299 return (float)( 1+(_start - _max)/(_max-_min));
1303 * Gets the end porcentage with respect to the represented values of the bar
1304 * return The porcentage represented by the end showing point
1306 float mBarRange :: getEndShowPorcentage()
1308 return (float) (1+(_end - _max)/(_max-_min));
1312 * Gets the actual porcentage with respect to the represented values of the bar
1313 * return The porcentage represented by the actual showing point
1315 float mBarRange :: getActualShowPorcentage()
1317 return (float) (1+(_actual - _max)/(_max-_min));
1320 int mBarRange :: getLogicValueofPixel(int thePixel)
1322 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1326 * Sets the condition for knowing if the actual triangle is being drawed or not
1327 * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1329 void mBarRange :: setIfWithActualDrawed(bool drawActual)
1331 if(!withActualDrawed && drawActual)
1333 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1334 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
1336 else if (withActualDrawed && !drawActual)
1338 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1339 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1341 withActualDrawed = drawActual;
1346 * Gets the condition for knowing if the actual triangle is being drawed or not
1347 * return withActualDrawed The condition for drawing or not the actual control
1349 bool mBarRange :: getIfWithActualDrawed()
1351 return withActualDrawed;
1354 void mBarRange :: createAndSendEvent(WXTYPE theEventType)
1356 wxCommandEvent cevent( theEventType, GetId() );
1357 cevent.SetEventObject( this );
1358 GetEventHandler()->ProcessEvent( cevent );
1362 * Sets the background color od the bar
1363 * theColor The color to set to the backgroundColor
1365 void mBarRange :: setBackgroundColor(wxColour theColor)
1367 backgroundColor = theColor;
1371 * Sets the guide line color
1372 * param theNwGuideLineColor The color to set to the guideLineColor
1374 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1376 guideLineColor = theNwGuideLineColor;
1380 * Gets the guide line color
1381 * return guideLineColor The color of the guideLine
1383 wxColour mBarRange :: getGuideLineColour()
1385 return guideLineColor;
1388 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
1390 acceptedClick = true;
1393 void mBarRange ::onLeftClickUp(wxMouseEvent& event )
1395 acceptedClick = false;