1 //----------------------------------------------------------------------------
5 //const wxEventType wxEVT_TSBAR = wxNewEventType();
7 DEFINE_EVENT_TYPE(wxEVT_TSBAR)
8 DEFINE_EVENT_TYPE(wxEVT_TSBAR_ACTUAL)
9 DEFINE_EVENT_TYPE(wxEVT_TSBAR_START)
10 DEFINE_EVENT_TYPE(wxEVT_TSBAR_END)
11 DEFINE_EVENT_TYPE(wxEVT_TSBAR_MOVED)
12 DEFINE_EVENT_TYPE(wxEVT_SELECTION_END)
16 //----------------------------------------------------------------------------
18 //----------------------------------------------------------------------------
20 IMPLEMENT_CLASS(mBarRange, wxScrolledWindow)
21 BEGIN_EVENT_TABLE(mBarRange, wxScrolledWindow)
22 EVT_PAINT (mBarRange::OnPaint)
23 EVT_SIZE (mBarRange::OnSize)
24 EVT_MOTION (mBarRange::OnMouseMove)
25 EVT_RIGHT_DOWN (mBarRange :: onShowPopupMenu)
26 EVT_MENU(cntID_CHANGE_COLOR, mBarRange :: onChangePartColor)
27 EVT_MENU(cntID_ENABLE_ACTUAL, mBarRange :: onEnableRange_Actual)
28 EVT_MENU(cntID_MOVABLE_ACTUAL_BAR, mBarRange :: onMovable_ActualWithBar)
31 EVT_LEFT_DOWN( mBarRange :: onLeftClicDown)
32 EVT_LEFT_UP( mBarRange :: onLeftClickUp)
34 //how to catch the new event (our event)
35 //EVT_COMMAND (ID_MY_WINDOW, wxEVT_MY_EVENT, MyFrame::OnMyEvent)
39 //----------------------------------------------------------------------------
41 //----------------------------------------------------------------------------
43 mBarRange::mBarRange(wxWindow *parent, int w, int h)
44 :wxScrolledWindow(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
51 trianglesHalfWidth = 5;
53 wxColour start_Colour;
55 // Setting the default parts colors
56 start_Colour = wxColour(0,0,255);
57 actual_Colour = wxColour(255,255,202);
58 end_Colour = wxColour(0,0,255);
59 bar_Colour = wxColour(255,0,255);
60 backgroundColor = parent ->GetBackgroundColour();
61 guideLineColor = wxColour(255,0,0);
63 //actual is in _start and end
64 //false means that it could be anywhere
65 _moveActualWithBar = false;
66 _in_rangeProperty = false;
67 _selectionMoveId = -1;
68 realX_vertical_line = -1;
74 setIfWithActualDrawed(true);
76 b_popmenu.Append (cntID_CHANGE_COLOR, _("Change Color"), _("Changes the color of the selected part"));
77 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
78 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
83 //----------------------------------------------------------------------------
85 //----------------------------------------------------------------------------
87 mBarRange::~mBarRange()
90 //---------------------------------------------------------------------------
91 //Draw bar: vertical or Horizontal
92 //---------------------------------------------------------------------------
93 void mBarRange::DrawBar()
98 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
99 _bitmap_bar = new wxBitmap(_w+1280,_h+100);
100 //SIL//_bitmap_info = new wxBitmap(_w+100+1280, _h+100);
105 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
106 _bitmap_bar = new wxBitmap(_h+deviceStart_y+100,_w+1280);
107 _bitmap_info = new wxBitmap(_h+deviceStart_y+100, _w+1280);
110 //----------------------------------------------------------------------------
112 //----------------------------------------------------------------------------
113 //----------------------------------------------------------------------------
114 //the property condition on actual triangle
115 //----------------------------------------------------------------------------
116 bool mBarRange::GetInRangeProperty()
118 return _in_rangeProperty;
120 //----------------------------------------------------------------------------
121 void mBarRange::SetInRangeProperty(bool in)
123 _in_rangeProperty=in;
125 //----------------------------------------------------------------------------
126 //the information about the actual triangle in range or not, true if is between start and end
127 //----------------------------------------------------------------------------
128 bool mBarRange::IsActualInRange()
130 return ( _actual <= _end && _actual >= _start );
133 //----------------------------------------------------------------------------
134 // the position of the rectangle, vertical or horizontal
135 //----------------------------------------------------------------------------
136 bool mBarRange::GetOrientation()
140 //-----------------------------------------------------------------------------
141 void mBarRange::SetOrientation(bool orientation)
147 _orientation=orientation;
150 //----------------------------------------------------------------------------
151 // _start of the pixel rectangle
152 //----------------------------------------------------------------------------
154 int mBarRange::GetPixelStart()
156 return ((_start - _min)*(_w-deviceEndMargin))/(_max - _min);
158 //----------------------------------------------------------------------------
159 // param i: value in pixels
160 //----------------------------------------------------------------------------
161 void mBarRange::SetPixelStart(int i)
163 _start = _min+((i - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
166 //----------------------------------------------------------------------------
167 // _actual of the pixel rectangle
168 //----------------------------------------------------------------------------
169 int mBarRange::GetPixelActual()
171 return ((_actual - _min)*(_w-deviceEndMargin))/(_max - _min);
173 //----------------------------------------------------------------------------
174 // param i: value in pixels
175 //----------------------------------------------------------------------------
176 void mBarRange::SetPixelActual(int i)
178 _actual = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
180 //----------------------------------------------------------------------------
181 // _end of the pixel rectangle
182 //----------------------------------------------------------------------------
183 int mBarRange::GetPixelEnd()
185 return ((_end - _min)*(_w-deviceEndMargin))/(_max - _min);
187 //----------------------------------------------------------------------------
188 // param i: value in pixels to be converted to real logical value
189 //----------------------------------------------------------------------------
190 void mBarRange::SetPixelEnd(int i)
192 _end = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
194 //----------------------------------------------------------------------------
195 // Logical max of the triangle
196 //----------------------------------------------------------------------------
198 double mBarRange::GetMax()
203 //----------------------------------------------------------------------------
204 void mBarRange::SetMax(double i)
208 //----------------------------------------------------------------------------
209 // Logical min of the triangle
210 //----------------------------------------------------------------------------
212 double mBarRange::GetMin()
217 //----------------------------------------------------------------------------
218 void mBarRange::SetMin(double i)
223 //----------------------------------------------------------------------------
224 // pixel dimensions of the rectangle
225 //----------------------------------------------------------------------------
227 int mBarRange::GetWidth()
231 //----------------------------------------------------------------------------
232 void mBarRange::SetWidth(int w)
236 //----------------------------------------------------------------------------
237 int mBarRange::GetHeight()
242 //----------------------------------------------------------------------------
243 void mBarRange::SetHeight(int h)
248 //----------------------------------------------------------------------------
249 // Logical Start of the rectangle
250 //----------------------------------------------------------------------------
252 int mBarRange::GetStart()
257 //----------------------------------------------------------------------------
258 // param start: value real units
259 //----------------------------------------------------------------------------
260 void mBarRange::SetStart(int newstart)
267 //----------------------------------------------------------------------------
268 // Logical End of the rectangle
269 //----------------------------------------------------------------------------
271 int mBarRange::GetEnd()
275 //----------------------------------------------------------------------------
276 // param end: value pixel units
277 //----------------------------------------------------------------------------
278 void mBarRange::SetEnd(int nwend)
285 //----------------------------------------------------------------------------
286 // logical Actual of the rectangle
287 //----------------------------------------------------------------------------
288 int mBarRange::GetActual()
292 //----------------------------------------------------------------------------
293 void mBarRange::SetActual(int actual)
297 else if (actual>_max)
303 //----------------------------------------------------------------------------
305 //----------------------------------------------------------------------------
306 int mBarRange::GetTrianglesHalfWidth()
308 return trianglesHalfWidth;
310 //----------------------------------------------------------------------------
311 void mBarRange::SetTrianglesHalfWidth(int nwTriHalfWidth)
313 trianglesHalfWidth = nwTriHalfWidth;
316 void mBarRange::OnSize( wxSizeEvent &WXUNUSED(event) )
318 wxRect rectTotal = GetClientRect();
321 SetWidth( rectTotal.GetWidth() - deviceEndMargin );
325 SetWidth( rectTotal.GetHeight() - deviceEndMargin);
327 _selectionMoveId = -1;
331 //----------------------------------------------------------------------------
333 void mBarRange::Refresh(bool eraseBackground, const wxRect* rect)
337 //ff=fopen ("c:/temp/xxx.txt", "a+");
338 //fprintf( ff , "mBarRange :: Refresh 01\n" );
341 wxScrolledWindow::Refresh(false);
345 //ff=fopen ("c:/temp/xx.txt", "a+");
346 //fprintf( ff , "mBarRange :: Refresh 02\n" );
351 //----------------------------------------------------------------------------
353 //----------------------------------------------------------------------------
354 void mBarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
359 //ff=fopen ("c:/temp/xx.txt", "a+");
360 //fprintf( ff , "pColorBar :: OnPaint 01\n" );
363 if (_bitmap_bar!=NULL){
367 RefreshHorizontalView();
369 temp_dc.SelectObject( *_bitmap_bar );
370 wxPaintDC dc( this );
371 dc.Blit(deviceStart_x-(trianglesHalfWidth+2), deviceStart_y, _w-deviceEndMargin+2*(trianglesHalfWidth+2), _h, &temp_dc, 0, 0);
373 // if (_visibleLables)
375 // temp_dc.SelectObject( *_bitmap_info );
376 // dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+200, &temp_dc, deviceStart_x, deviceStart_y);
377 // //dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+60, &temp_dc, 0, 0);
381 RefreshVerticalView();
383 temp_dc.SelectObject( *_bitmap_bar );
384 wxPaintDC dc( this );
385 // dc.Blit(deviceStart_y,deviceStart_x, _h+deviceStart_y-deviceEndMargin,_w+deviceStart_x-deviceEndMargin, &temp_dc, 0, 0);
386 dc.Blit(deviceStart_y,deviceStart_x-(trianglesHalfWidth+2), _h,_w-deviceEndMargin+2*(trianglesHalfWidth+2), &temp_dc, 0, 0);
389 // if (_visibleLables)
391 // temp_dc.SelectObject( *_bitmap_info );
392 // dc.Blit(0,_w, _h+deviceStart_y+200, _w+deviceStart_x+200-deviceEndMargin, &temp_dc, deviceStart_y,_w+deviceStart_x);
400 //ff=fopen ("c:/temp/xx.txt", "a+");
401 //fprintf( ff , "pColorBar :: OnPaint 02\n" );
406 //----------------------------------------------------------------------------
407 //Repaint the bar if it is horizontal
408 //----------------------------------------------------------------------------
409 void mBarRange::RefreshHorizontalView()
414 //ff=fopen ("c:/temp/xxx.txt", "a+");
415 //fprintf( ff , "mBarRange :: RefreshHorizontalView 01\n" );
420 //int largestNumberWidthInPixels = 15; // JPRx
421 int pxStart=GetPixelStart();
422 int pxEnd=GetPixelEnd();
423 int pxActual=GetPixelActual();
426 int letterHeight = 9;
427 int barHeight = 2*letterHeight;
428 int tempHeight = _h-(6*letterHeight);
433 barHeight = (tempHeight>0) ? tempHeight : (int) _h/2;
439 temp_dc.SelectObject( *_bitmap_bar );
442 // Background of this widget
445 temp_dc.SetPen(wxPen( backgroundColor ));
446 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
448 temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
451 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
452 temp_dc.DrawLine(trianglesHalfWidth+2, 0, _w-deviceEndMargin, 0);
453 temp_dc.DrawLine(trianglesHalfWidth+2, barHeight, (_w-deviceEndMargin-trianglesHalfWidth-2), barHeight);
454 temp_dc.SetDeviceOrigin(trianglesHalfWidth+2,0);
458 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
459 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
460 temp_dc.DrawRectangle( pxStart , 0, pxEnd-pxStart, barHeight);
464 if( _selectionMoveId==4 )
466 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
467 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
471 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
472 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
474 temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
476 // 2 Shadow Triangles: Start and End
477 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
478 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
480 points[0].y= barHeight;
481 points[1].x= -trianglesHalfWidth-1;
483 points[2].x= trianglesHalfWidth+2;
485 temp_dc.DrawPolygon(3,points,pxStart,0);
486 temp_dc.DrawPolygon(3,points,pxEnd,0);
488 // 2 Triangles: Start and End
489 points[1].x = -trianglesHalfWidth;
490 points[2].x = trianglesHalfWidth;
492 //first triangle (start)
493 if( _selectionMoveId == 1 )
495 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
496 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
500 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
501 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
503 temp_dc.DrawPolygon(3,points,pxStart,0);
504 //second triangle (end)
505 if( _selectionMoveId == 2 )
507 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
508 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
512 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
513 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
515 temp_dc.DrawPolygon(3,points,pxEnd,0);
517 if( withActualDrawed )
519 // 1 Shadow Triangle: Actual
520 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
521 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
522 points[1].x = -trianglesHalfWidth-1;
523 points[2].x = trianglesHalfWidth+2;
525 temp_dc.DrawPolygon(3,points,pxActual,0);
527 // 1 Triangle: Actual (red)
528 if( _selectionMoveId==3 )
530 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
531 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
535 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
536 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
538 points[1].x = -trianglesHalfWidth;
539 points[2].x = trianglesHalfWidth;
540 temp_dc.DrawPolygon(3,points,pxActual,0);
543 if (realX_vertical_line!=-1)
545 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
546 int pixelX_guide = ((realX_vertical_line - _min)*(_w-deviceEndMargin))/(_max - _min) ;
547 temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, barHeight);
550 //Information Device drawing
554 //temp_dc.SelectObject( *_bitmap_info );
555 /*temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID ));
556 temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID ));*/
557 //temp_dc.DrawRectangle(deviceStart_x,_h+deviceStart_y,_w+deviceStart_x+40,_h+deviceStart_y+40);
558 //temp_dc.DrawRectangle(0,_h,_w+40-deviceEndMargin,_h+40);
560 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
561 temp_dc.SetFont(font);
562 temp_dc.SetTextForeground(*wxBLACK);
565 //the **MIN** value, always at the same y level that corresponds to barHeight+1
567 // text_min<< GetMin();
568 text_min.Printf(_T("%d"), (int)GetMin() );
570 temp_dc.DrawText(text_min,0,barHeight+1);
572 //the **MAX** value always at the same place
574 // text_max << GetMax();
575 text_max.Printf(_T("%d"), (int)GetMax() );
577 //As there is a margin of 40 extra most numbers (max) should be visibles
578 // stringSize = temp_dc.GetTextExtent(text_max);
580 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
581 wxSize stringSize(tmpX,tmpY);
583 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth())/*2*trianglesHalfWidth*/,barHeight+1);
585 //show logical values
586 //show the **START TRIANGLE** value
588 // text_start << GetStart();
589 text_start.Printf(_T("%d"), (int)GetStart() );
591 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
592 //show the **END TRIANGLE** value
594 // text_end << GetEnd();
595 text_end.Printf(_T("%d"), (int)GetEnd() );
597 // stringSize = temp_dc.GetTextExtent(text_end);
598 temp_dc.GetTextExtent(text_end,&tmpX,&tmpY);
599 stringSize.SetHeight(tmpY);
600 stringSize.SetWidth(tmpX);
601 temp_dc.DrawText(text_end, pxEnd-stringSize.GetWidth(),barHeight+3*letterHeight);
602 if( withActualDrawed )
604 //show the actual value of actual
605 wxString text_actual;
606 // text_actual << GetActual();
607 text_actual.Printf(_T("%d"), (int)GetActual() );
608 // stringSize = temp_dc.GetTextExtent(text_actual);
609 temp_dc.GetTextExtent(text_actual,&tmpX,&tmpY);
610 stringSize.SetHeight(tmpY);
611 stringSize.SetWidth(tmpX);
612 temp_dc.DrawText(text_actual, pxActual-(stringSize.GetWidth()/2),barHeight+letterHeight);
617 //ff=fopen ("c:/temp/xxx.txt", "a+");
618 //fprintf( ff , "mBarRange :: RefreshHorizontalView 02\n" );
622 //----------------------------------------------------------------------------
623 //Repaint the bar if it is vertical
624 //----------------------------------------------------------------------------
626 void mBarRange::RefreshVerticalView()
631 //ff=fopen ("c:/temp/xxx.txt", "a+");
632 //fprintf( ff , "mBarRange :: RefreshVerticalView 01\n" );
636 int px1=GetPixelStart();
637 int px2=GetPixelEnd();
638 int px3=GetPixelActual();
639 int letterHeight = 9;
640 int panelHeight = 9*3+_w;
645 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
651 temp_dc.SelectObject( *_bitmap_bar );
654 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
655 temp_dc.SetPen(wxPen( backgroundColor ));
657 temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
660 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
661 temp_dc.DrawLine(0,trianglesHalfWidth+2, 0, _w-deviceEndMargin);
662 temp_dc.DrawLine(barWidth, trianglesHalfWidth+2, barWidth, (_w-deviceEndMargin-trianglesHalfWidth-2));
663 temp_dc.SetDeviceOrigin(0,trianglesHalfWidth+2);
666 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
667 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
668 temp_dc.DrawRectangle( 0,px1 ,_h, px2-px1 );
672 if( _selectionMoveId==4 )
674 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
675 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
679 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
680 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
682 temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
685 // 2 Shadow Triangles: Start and End
689 points[1].y=-trianglesHalfWidth-1;
691 points[2].y=trianglesHalfWidth+2;
692 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
693 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
694 temp_dc.DrawPolygon(3,points,0,px1);
695 temp_dc.DrawPolygon(3,points,0,px2);
697 // 2 Triangles: Start and End
701 points[1].y=-trianglesHalfWidth;
703 points[2].y=trianglesHalfWidth;
704 //first triangle (start)
705 if( _selectionMoveId==1 )
707 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
708 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
712 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
713 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
715 temp_dc.DrawPolygon(3,points,0,px1);
716 //second triangle (end)
717 if( _selectionMoveId==2 )
719 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
720 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
724 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
725 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
727 temp_dc.DrawPolygon(3,points,0,px2);
729 if( withActualDrawed )
731 // 1 Shadow Triangle: Actual
732 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
733 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
737 points[1].y=-trianglesHalfWidth-1;
739 points[2].y=trianglesHalfWidth+2;
740 temp_dc.DrawPolygon(3,points,0,px3);
742 // 1 Triangle: Actual (red)
746 points[1].y = -trianglesHalfWidth;
748 points[2].y = trianglesHalfWidth;
749 if( _selectionMoveId==3 )
751 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
752 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
756 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
757 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
759 temp_dc.DrawPolygon(3,points,0,px3);
762 if (realX_vertical_line!=-1)
764 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
765 int pixelX_guide = realX_vertical_line*_w/(_max-_min)+deviceStart_x;
766 temp_dc.DrawLine(0,pixelX_guide, _h, pixelX_guide);
769 //Information Device drawing
772 /*temp_dc.SelectObject( *_bitmap_info );
774 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
775 temp_dc.SetPen(wxPen( backgroundColor ,1,wxSOLID ));
776 temp_dc.DrawRectangle(deviceStart_y,_w+deviceStart_x,_h+deviceStart_y+200,_w+deviceStart_x+200);
779 temp_dc.SetBackgroundMode(wxTRANSPARENT);
780 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
781 temp_dc.SetFont(font);
782 temp_dc.SetTextForeground(*wxBLACK);
784 //show logical values
785 //show the actual value of start
787 // text_start<<"Start:"<< GetStart();
788 text_start.Printf(_T("%s %d"),_T("Start: "), (int)GetStart() );
789 temp_dc.DrawText( text_start ,deviceStart_y, _w+deviceStart_x+letterHeight+1);
790 //show the actual value of end
792 // text_end <<"End: "<<GetEnd();
793 text_end.Printf(_T("%s %d"),_T("End: "), (int)GetEnd() );
794 temp_dc.DrawText( text_end ,deviceStart_y,_w+deviceStart_x+letterHeight*2 );
795 if( withActualDrawed )
797 //show the actual value of actual
798 wxString text_actual;
799 // text_actual <<"Actual: " <<GetActual();
800 text_actual.Printf(_T("%s %d"),_T("Actual: "), (int)GetActual() );
801 temp_dc.DrawText( text_actual ,deviceStart_y,_w+deviceStart_x+letterHeight*3);
803 //the min value, always at the same place
805 // text_min<<"Min: " << GetMin();
806 text_min.Printf(_T("%s %d"),_T("Min: "), (int)GetMin() );
807 temp_dc.DrawText( text_min ,deviceStart_y,_w+deviceStart_x+3);
808 //the max value always at the samen place
810 // text_max <<"Max: "<< GetMax();
811 text_max.Printf(_T("%s %d"),_T("Max: "), (int)GetMax() );
812 //toca calcular cuantol lo corremos
813 temp_dc.DrawText(text_max,deviceStart_y,_w+deviceStart_x+43);
818 //----------------------------------------------------------------------------
819 void mBarRange::RefreshForce()
824 //----------------------------------------------------------------------------
825 void mBarRange::OnMouseMove(wxMouseEvent& event )
829 //ff=fopen ("c:/temp/xxx.txt", "a+");
830 //fprintf( ff , "mBarRange :: OnMouseMove 01\n" );
833 //int px1=GetPixelStart(); // JPRx
834 //int px2=GetPixelEnd(); // JPRx
835 //int px3=GetPixelActual(); // JPRx
838 wxPoint point = event.GetPosition();
842 setClickedX(point.x);
847 setClickedX(point.y);
850 int logicClick = getLogicValueofPixel(clickedX);
852 if( _selectionMoveId==-1 )
856 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
857 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
858 bool in_actualT= withActualDrawed && (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
859 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
862 _selectionMoveId = 3;
864 _selectionMoveId = 1;
866 _selectionMoveId = 2;
867 else if( in_movingBar )
868 _selectionMoveId = 4;
875 //is in start triagle
876 if( _selectionMoveId ==1 && event.LeftIsDown())
878 bool validPos_StartTri = (logicClick<GetEnd() && logicClick >=_min);
879 if( validPos_StartTri && !_in_rangeProperty)
881 SetPixelStart(clickedX);
883 RefreshHorizontalView();
884 //-------------------------------------------
885 // Sending the event of start triangle moved
886 //-------------------------------------------
887 createAndSendEvent( wxEVT_TSBAR_START );
889 //start has to be less than actual
890 else if (validPos_StartTri && _in_rangeProperty)
892 if(logicClick<=GetActual())
894 SetPixelStart(clickedX);
896 // RefreshHorizontalView();
897 //-------------------------------------------
898 // Sending the event of start triangle moved
899 //-------------------------------------------
900 createAndSendEvent( wxEVT_TSBAR_START );
903 } // _selectionMoveId == 1
905 else if( _selectionMoveId == 2 && event.LeftIsDown() )
907 bool validPos_EndTri = logicClick>GetStart()&& logicClick<=_max;
908 if( validPos_EndTri && !_in_rangeProperty )
910 SetPixelEnd(clickedX);
912 // RefreshHorizontalView();
913 //-------------------------------------------
914 //Sending the event of end triangle moved
915 //-------------------------------------------
916 createAndSendEvent( wxEVT_TSBAR_END );
918 //the end triangle cant be less than actual
919 else if( validPos_EndTri && _in_rangeProperty )
921 if(logicClick>=GetActual())
923 SetPixelEnd(clickedX);
925 // RefreshHorizontalView();
926 //-------------------------------------------
927 //Sending the event of end triangle moved
928 //-------------------------------------------
929 createAndSendEvent( wxEVT_TSBAR_END );
933 //is the actual triangle
934 else if( _selectionMoveId == 3 && event.LeftIsDown())
936 bool validPos_ActualTri=(logicClick<=_max) && (logicClick>=_min);
937 //is in actual triangle but it could be anywhere
938 if( validPos_ActualTri && !_in_rangeProperty )
940 SetPixelActual(clickedX);
942 RefreshHorizontalView();
943 //-------------------------------------------
944 //Sending the event of actual triangle moved
945 //-------------------------------------------
946 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
947 // createAndSendEvent( 98765 );
949 //printf("EED creaMaracasVisu mBarRange::OnMouseMove XXXXXXX \n");
952 else if( validPos_ActualTri && _in_rangeProperty )
953 // the tringle in between start and end
955 if( logicClick>=GetStart() && logicClick<=GetEnd())
957 SetPixelActual(clickedX);
959 RefreshHorizontalView();
960 //-------------------------------------------
961 //Sending the event of actual triangle moved
962 //-------------------------------------------
963 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
968 else if ( _selectionMoveId == 4 && event.LeftIsDown() )
970 //FILE * f=fopen("E:/borrar/file.txt","a+");
971 if(_initialPoint == 0)
973 _initialPoint = logicClick;
974 logicInitial_start = GetStart();
975 logicInitial_end = GetEnd();
976 logicInitial_actual = GetActual();
977 //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);
979 int difference = logicClick -_initialPoint;
980 int next_end = difference + logicInitial_end;
981 int next_start = difference + logicInitial_start;
982 int next_actual = difference + logicInitial_actual;
984 /*SIL//fprintf(f,"diff:%d, next_end%d, next_start%d, next_actual%d \n", difference,next_end,next_start,next_actual);
987 //if actual is not fixed to be in the middle
988 if( ((logicClick>next_start) && (logicClick<next_end)&& (next_end<=_max)&& (next_start>=_min)) && !_in_rangeProperty)
990 SetStart(next_start);
992 if( _moveActualWithBar )
994 SetActual (next_actual);
995 //-------------------------------------------
996 //Sending the event of actual triangle moved
997 //-------------------------------------------
998 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1001 RefreshHorizontalView();
1003 //-------------------------------------------
1004 // Sending the event that the bar ahs being moved
1005 //-------------------------------------------
1006 createAndSendEvent( wxEVT_TSBAR_MOVED );
1008 //if actual has to be between start and end
1009 else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
1011 SetStart(next_start);
1013 if( _moveActualWithBar )
1015 SetActual (next_actual);
1016 //-------------------------------------------
1017 //Sending the event of actual triangle moved
1018 //-------------------------------------------
1019 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1022 RefreshHorizontalView();
1024 //-------------------------------------------
1025 // Sending the event that the bar ahs being moved
1026 //-------------------------------------------
1027 createAndSendEvent( wxEVT_TSBAR_MOVED );
1031 if( !event.LeftIsDown())
1034 _selectionMoveId = -1;
1036 //-------------------------------------------
1037 //Sending a general event just because
1038 //-------------------------------------------
1039 //SIL//createAndSendEvent( wxEVT_TSBAR );
1040 createAndSendEvent(wxEVT_SELECTION_END);
1046 //ff=fopen ("c:/temp/xxx.txt", "a+");
1047 //fprintf( ff , " mBarRange :: OnMouseMove 02\n" );
1052 * Sets the represented minimum and maximunm values
1053 * param minRealValue The minimum represented value (real value)
1054 * param maxRealValue The maximum represented value (real value)
1056 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
1058 _min = minRealValue;
1059 _max = maxRealValue;
1065 * Sets the property for viewing or not the bar labels information
1067 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
1069 _visibleLables = setVisibleLB;
1073 * Sets the property for viewing or not the bar labels information
1074 * return _visibleLables The state of visible labels or not
1076 bool mBarRange ::getIfVisibleLabels ()
1078 return _visibleLables;
1082 * Sets the device start drawing left-superior (pixel) start point
1083 * param deviceStart_x Pixel start for x-coord
1084 * param deviceStart_y Pixel start for y-coord
1086 void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1088 deviceStart_x = devStart_x;
1089 deviceStart_y = devStart_y;
1090 // For the initialization case
1091 if (GetPixelEnd()<0)
1095 SetPixelStart(deviceStart_x);
1096 SetPixelEnd(_w+deviceStart_x);
1097 SetPixelActual(deviceStart_x);
1101 SetPixelStart(deviceStart_x);
1102 SetPixelEnd(_h+deviceStart_x);
1103 SetPixelActual(deviceStart_x);
1110 * Shows the popup menu
1112 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1116 bool validClic = false;
1119 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1123 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1128 setClickedX(event.GetX());
1130 setClickedX(event.GetY());
1132 if (getClickedX()<=_h)
1134 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1135 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1136 bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1137 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1140 _selectionMoveId = 1;
1141 else if( in_EndTri )
1142 _selectionMoveId = 2;
1143 else if( in_actualT )
1144 _selectionMoveId = 3;
1145 else if( in_movingBar )
1146 _selectionMoveId = 4;
1148 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1154 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1155 * param & anEvent The wxCommandEvent actioned event
1157 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1159 bool okSelectedColor = false;
1160 wxColour selectedColour;
1162 wxColourDialog dialog( GetParent(), &data);
1164 if ( dialog.ShowModal() == wxID_OK )
1166 selectedColour = dialog.GetColourData().GetColour();
1167 okSelectedColor = true;
1169 if( okSelectedColor )
1171 if (_selectionMoveId==1 )
1172 start_Colour = selectedColour;
1173 else if (_selectionMoveId==2 )
1174 end_Colour = selectedColour;
1175 else if( _selectionMoveId==3 )
1176 actual_Colour = selectedColour;
1177 else if( _selectionMoveId==4 )
1178 bar_Colour = selectedColour;
1180 _selectionMoveId = -1;
1186 * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1187 * param & anEvent The wxCommandEvent actioned event
1189 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1191 if (!_in_rangeProperty)
1193 if(IsActualInRange())
1195 SetInRangeProperty (true);
1196 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1201 SetInRangeProperty (false);
1202 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
1207 * 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.
1208 * param & anEvent The wxCommandEvent actioned event
1210 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1212 if (_moveActualWithBar )
1214 _moveActualWithBar = false;
1215 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1219 if(IsActualInRange())
1221 _moveActualWithBar = true;
1222 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1229 * param activeNow The new state
1231 void mBarRange :: setActiveStateTo (bool activeNow)
1233 activeState = activeNow;
1237 * Gets the active state of the bar
1238 * return activeState The actual state
1240 bool mBarRange :: isActive()
1246 * Gets the real-x value to draw a vertical line
1247 * return realX_vertical_line The real x value for the vertical line
1249 int mBarRange :: getRealX_vertical_line()
1251 return realX_vertical_line;
1255 * Sets the real-x value to draw a vertical line
1256 * param newReal_x The new real x value for the vertical line
1258 void mBarRange :: setRealX_vertical_line(int newReal_x)
1260 realX_vertical_line = newReal_x;
1264 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1265 * return deviceEndMargin The value asigned to the right margin
1267 int mBarRange :: getDeviceEndX()
1269 return deviceEndMargin;
1273 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1274 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1276 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1278 deviceEndMargin = newDeviceEnd_pixels;
1282 * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1283 * return clickedX The x-coord pixel value
1285 int mBarRange :: getClickedX()
1291 * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1292 * param nwClickX The x-coord pixel value
1294 void mBarRange :: setClickedX(int nwClickX)
1296 clickedX = nwClickX;
1301 * Gets the start porcentage with respect to the represented values of the bar
1302 * return The porcentage represented by the start showing point
1304 float mBarRange :: getStartShowPorcentage()
1306 return (float)( 1+(_start - _max)/(_max-_min));
1310 * Gets the end porcentage with respect to the represented values of the bar
1311 * return The porcentage represented by the end showing point
1313 float mBarRange :: getEndShowPorcentage()
1315 return (float) (1+(_end - _max)/(_max-_min));
1319 * Gets the actual porcentage with respect to the represented values of the bar
1320 * return The porcentage represented by the actual showing point
1322 float mBarRange :: getActualShowPorcentage()
1324 return (float) (1+(_actual - _max)/(_max-_min));
1327 int mBarRange :: getLogicValueofPixel(int thePixel)
1329 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1333 * Sets the condition for knowing if the actual triangle is being drawed or not
1334 * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1336 void mBarRange :: setIfWithActualDrawed(bool drawActual)
1338 if(!withActualDrawed && drawActual)
1340 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1341 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
1343 else if (withActualDrawed && !drawActual)
1345 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1346 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1348 withActualDrawed = drawActual;
1353 * Gets the condition for knowing if the actual triangle is being drawed or not
1354 * return withActualDrawed The condition for drawing or not the actual control
1356 bool mBarRange :: getIfWithActualDrawed()
1358 return withActualDrawed;
1361 void mBarRange::createAndSendEvent(WXTYPE theEventType)
1363 wxCommandEvent cevent( theEventType, GetId() );
1364 cevent.SetEventObject( this );
1365 GetEventHandler()->ProcessEvent( cevent );
1369 * Sets the background color od the bar
1370 * theColor The color to set to the backgroundColor
1372 void mBarRange :: setBackgroundColor(wxColour theColor)
1374 backgroundColor = theColor;
1378 * Sets the guide line color
1379 * param theNwGuideLineColor The color to set to the guideLineColor
1381 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1383 guideLineColor = theNwGuideLineColor;
1387 * Gets the guide line color
1388 * return guideLineColor The color of the guideLine
1390 wxColour mBarRange :: getGuideLineColour()
1392 return guideLineColor;
1395 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
1397 acceptedClick = true;
1400 void mBarRange ::onLeftClickUp(wxMouseEvent& event )
1402 acceptedClick = false;