1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 //----------------------------------------------------------------------------
27 #include "mBarRange.h"
30 //const wxEventType wxEVT_TSBAR = wxNewEventType();
32 DEFINE_EVENT_TYPE(wxEVT_TSBAR)
33 DEFINE_EVENT_TYPE(wxEVT_TSBAR_ACTUAL)
34 DEFINE_EVENT_TYPE(wxEVT_TSBAR_START)
35 DEFINE_EVENT_TYPE(wxEVT_TSBAR_END)
36 DEFINE_EVENT_TYPE(wxEVT_TSBAR_MOVED)
37 DEFINE_EVENT_TYPE(wxEVT_SELECTION_END)
41 //----------------------------------------------------------------------------
43 //----------------------------------------------------------------------------
45 IMPLEMENT_CLASS(mBarRange, wxScrolledWindow)
46 BEGIN_EVENT_TABLE(mBarRange, wxScrolledWindow)
47 EVT_PAINT (mBarRange::OnPaint)
48 EVT_SIZE (mBarRange::OnSize)
49 EVT_MOTION (mBarRange::OnMouseMove)
50 EVT_RIGHT_DOWN (mBarRange :: onShowPopupMenu)
51 EVT_MENU(cntID_CHANGE_COLOR, mBarRange :: onChangePartColor)
52 EVT_MENU(cntID_ENABLE_ACTUAL, mBarRange :: onEnableRange_Actual)
53 EVT_MENU(cntID_MOVABLE_ACTUAL_BAR, mBarRange :: onMovable_ActualWithBar)
56 EVT_LEFT_DOWN( mBarRange :: onLeftClicDown)
57 EVT_LEFT_UP( mBarRange :: onLeftClickUp)
59 EVT_CHAR( mBarRange :: onKey )
61 //how to catch the new event (our event)
62 //EVT_COMMAND (ID_MY_WINDOW, wxEVT_MY_EVENT, MyFrame::OnMyEvent)
66 //----------------------------------------------------------------------------
68 //----------------------------------------------------------------------------
70 mBarRange::mBarRange(wxWindow *parent, int w, int h)
71 :wxScrolledWindow(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
78 trianglesHalfWidth = 5;
80 wxColour start_Colour;
82 // Setting the default parts colors
83 start_Colour = wxColour(0,0,255);
84 actual_Colour = wxColour(255,255,202);
85 end_Colour = wxColour(0,0,255);
86 bar_Colour = wxColour(255,0,255);
87 backgroundColor = parent ->GetBackgroundColour();
88 guideLineColor = wxColour(255,0,0);
90 //actual is in _start and end
91 //false means that it could be anywhere
92 _moveActualWithBar = false;
93 _in_rangeProperty = false;
94 _selectionMoveId = -1;
95 realX_vertical_line = -1;
100 SetOrientation(true);
101 setIfWithActualDrawed(true);
103 b_popmenu.Append (cntID_CHANGE_COLOR, _("Change Color"), _("Changes the color of the selected part"));
104 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
105 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
110 //----------------------------------------------------------------------------
112 //----------------------------------------------------------------------------
114 mBarRange::~mBarRange()
117 //---------------------------------------------------------------------------
118 //Draw bar: vertical or Horizontal
119 //---------------------------------------------------------------------------
120 void mBarRange::DrawBar()
125 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
126 _bitmap_bar = new wxBitmap(_w+1280,_h+100);
127 //SIL//_bitmap_info = new wxBitmap(_w+100+1280, _h+100);
132 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
133 _bitmap_bar = new wxBitmap(_h+deviceStart_y+100,_w+1280);
134 _bitmap_info = new wxBitmap(_h+deviceStart_y+100, _w+1280);
137 //----------------------------------------------------------------------------
139 //----------------------------------------------------------------------------
140 //----------------------------------------------------------------------------
141 //the property condition on actual triangle
142 //----------------------------------------------------------------------------
143 bool mBarRange::GetInRangeProperty()
145 return _in_rangeProperty;
147 //----------------------------------------------------------------------------
148 void mBarRange::SetInRangeProperty(bool in)
150 _in_rangeProperty=in;
152 //----------------------------------------------------------------------------
153 //the information about the actual triangle in range or not, true if is between start and end
154 //----------------------------------------------------------------------------
155 bool mBarRange::IsActualInRange()
157 return ( _actual <= _end && _actual >= _start );
160 //----------------------------------------------------------------------------
161 // the position of the rectangle, vertical or horizontal
162 //----------------------------------------------------------------------------
163 bool mBarRange::GetOrientation()
167 //-----------------------------------------------------------------------------
168 void mBarRange::SetOrientation(bool orientation)
174 _orientation=orientation;
177 //----------------------------------------------------------------------------
178 // _start of the pixel rectangle
179 //----------------------------------------------------------------------------
181 int mBarRange::GetPixelStart()
183 return ((_start - _min)*(_w-deviceEndMargin))/(_max - _min);
185 //----------------------------------------------------------------------------
186 // param i: value in pixels
187 //----------------------------------------------------------------------------
188 void mBarRange::SetPixelStart(int i)
190 _start = _min+((i - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
193 //----------------------------------------------------------------------------
194 // _actual of the pixel rectangle
195 //----------------------------------------------------------------------------
196 int mBarRange::GetPixelActual()
198 return ((_actual - _min)*(_w-deviceEndMargin))/(_max - _min);
200 //----------------------------------------------------------------------------
201 // param i: value in pixels
202 //----------------------------------------------------------------------------
203 void mBarRange::SetPixelActual(int i)
205 _actual = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
207 //----------------------------------------------------------------------------
208 // _end of the pixel rectangle
209 //----------------------------------------------------------------------------
210 int mBarRange::GetPixelEnd()
212 return ((_end - _min)*(_w-deviceEndMargin))/(_max - _min);
214 //----------------------------------------------------------------------------
215 // param i: value in pixels to be converted to real logical value
216 //----------------------------------------------------------------------------
217 void mBarRange::SetPixelEnd(int i)
219 _end = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
221 //----------------------------------------------------------------------------
222 // Logical max of the triangle
223 //----------------------------------------------------------------------------
225 double mBarRange::GetMax()
230 //----------------------------------------------------------------------------
231 void mBarRange::SetMax(double i)
235 //----------------------------------------------------------------------------
236 // Logical min of the triangle
237 //----------------------------------------------------------------------------
239 double mBarRange::GetMin()
244 //----------------------------------------------------------------------------
245 void mBarRange::SetMin(double i)
250 //----------------------------------------------------------------------------
251 // pixel dimensions of the rectangle
252 //----------------------------------------------------------------------------
254 int mBarRange::GetWidth()
258 //----------------------------------------------------------------------------
259 void mBarRange::SetWidth(int w)
263 //----------------------------------------------------------------------------
264 int mBarRange::GetHeight()
269 //----------------------------------------------------------------------------
270 void mBarRange::SetHeight(int h)
275 //----------------------------------------------------------------------------
276 // Logical Start of the rectangle
277 //----------------------------------------------------------------------------
279 int mBarRange::filtreValue(int value)
284 } else if (value>_max) {
290 //----------------------------------------------------------------------------
291 int mBarRange::GetStart()
295 //----------------------------------------------------------------------------
296 // param start: value real units
297 //----------------------------------------------------------------------------
298 void mBarRange::SetStart(int newstart)
300 _start = filtreValue(newstart);
307 if (_in_rangeProperty==true)
309 if (_start>_actual) { _start=_actual; }
314 //----------------------------------------------------------------------------
315 // Logical End of the rectangle
316 //----------------------------------------------------------------------------
318 int mBarRange::GetEnd()
322 //----------------------------------------------------------------------------
323 // param end: value pixel units
324 //----------------------------------------------------------------------------
325 void mBarRange::SetEnd(int newend)
327 _end = filtreValue(newend);
328 if (_end<_start) { _end=_start; }
329 if (_in_rangeProperty==true)
338 //----------------------------------------------------------------------------
339 // logical Actual of the rectangle
340 //----------------------------------------------------------------------------
341 int mBarRange::GetActual()
345 //----------------------------------------------------------------------------
346 void mBarRange::SetActual(int newactual)
348 _actual = filtreValue(newactual);
349 if (_in_rangeProperty==true)
351 if (_actual<_start) { _actual=_start; }
352 if (_actual>_end) { _actual=_end; }
357 //----------------------------------------------------------------------------
359 //----------------------------------------------------------------------------
360 int mBarRange::GetTrianglesHalfWidth()
362 return trianglesHalfWidth;
365 //----------------------------------------------------------------------------
366 void mBarRange::SetTrianglesHalfWidth(int nwTriHalfWidth)
368 trianglesHalfWidth = nwTriHalfWidth;
371 void mBarRange::OnSize( wxSizeEvent &WXUNUSED(event) )
373 wxRect rectTotal = GetClientRect();
376 SetWidth( rectTotal.GetWidth() - deviceEndMargin );
378 SetWidth( rectTotal.GetHeight() - deviceEndMargin);
380 _selectionMoveId = -1;
384 //----------------------------------------------------------------------------
386 void mBarRange::Refresh(bool eraseBackground, const wxRect* rect)
388 wxScrolledWindow::Refresh(false);
392 //----------------------------------------------------------------------------
394 //----------------------------------------------------------------------------
395 void mBarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
397 if (_bitmap_bar!=NULL)
402 RefreshHorizontalView();
404 temp_dc.SelectObject( *_bitmap_bar );
405 wxPaintDC dc( this );
406 dc.Blit(deviceStart_x-(trianglesHalfWidth+2), deviceStart_y, _w-deviceEndMargin+2*(trianglesHalfWidth+2), _h, &temp_dc, 0, 0);
408 // if (_visibleLables)
410 // temp_dc.SelectObject( *_bitmap_info );
411 // dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+200, &temp_dc, deviceStart_x, deviceStart_y);
412 // //dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+60, &temp_dc, 0, 0);
416 RefreshVerticalView();
418 temp_dc.SelectObject( *_bitmap_bar );
419 wxPaintDC dc( this );
420 // dc.Blit(deviceStart_y,deviceStart_x, _h+deviceStart_y-deviceEndMargin,_w+deviceStart_x-deviceEndMargin, &temp_dc, 0, 0);
421 dc.Blit(deviceStart_y,deviceStart_x-(trianglesHalfWidth+2), _h,_w-deviceEndMargin+2*(trianglesHalfWidth+2), &temp_dc, 0, 0);
424 // if (_visibleLables)
426 // temp_dc.SelectObject( *_bitmap_info );
427 // dc.Blit(0,_w, _h+deviceStart_y+200, _w+deviceStart_x+200-deviceEndMargin, &temp_dc, deviceStart_y,_w+deviceStart_x);
435 //----------------------------------------------------------------------------
436 //Repaint the bar if it is horizontal
437 //----------------------------------------------------------------------------
438 void mBarRange::RefreshHorizontalView()
442 //int largestNumberWidthInPixels = 15; // JPRx
443 int pxStart = GetPixelStart();
444 int pxEnd = GetPixelEnd();
445 int pxActual = GetPixelActual();
449 int barHeight = 2*letterHeight;
450 int tempHeight = _h-(6*letterHeight);
455 barHeight = (tempHeight>0) ? tempHeight : (int) _h/2;
461 temp_dc.SelectObject( *_bitmap_bar );
464 // Background of this widget
467 temp_dc.SetPen(wxPen( backgroundColor ));
468 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
470 temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
473 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
474 temp_dc.DrawLine(trianglesHalfWidth+2, 0, _w-deviceEndMargin, 0);
475 temp_dc.DrawLine(trianglesHalfWidth+2, barHeight, (_w-deviceEndMargin-trianglesHalfWidth-2), barHeight);
476 temp_dc.SetDeviceOrigin(trianglesHalfWidth+2,0);
480 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
481 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
482 temp_dc.DrawRectangle( pxStart , 0, pxEnd-pxStart, barHeight);
486 if( _selectionMoveId==4 )
488 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
489 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
493 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
494 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
496 temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
498 // 2 Shadow Triangles: Start and End
499 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
500 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
502 points[0].y= barHeight;
503 points[1].x= -trianglesHalfWidth-1;
505 points[2].x= trianglesHalfWidth+2;
507 temp_dc.DrawPolygon(3,points,pxStart,0);
508 temp_dc.DrawPolygon(3,points,pxEnd,0);
510 // 2 Triangles: Start and End
511 points[1].x = -trianglesHalfWidth;
512 points[2].x = trianglesHalfWidth;
514 //first triangle (start)
515 if( _selectionMoveId == 1 )
517 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
518 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
522 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
523 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
525 temp_dc.DrawPolygon(3,points,pxStart,0);
526 //second triangle (end)
527 if( _selectionMoveId == 2 )
529 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
530 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
534 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
535 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
537 temp_dc.DrawPolygon(3,points,pxEnd,0);
539 if( withActualDrawed )
541 // 1 Shadow Triangle: Actual
542 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
543 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
544 points[1].x = -trianglesHalfWidth-1;
545 points[2].x = trianglesHalfWidth+2;
547 temp_dc.DrawPolygon(3,points,pxActual,0);
549 // 1 Triangle: Actual (red)
550 if( _selectionMoveId==3 )
552 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
553 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
557 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
558 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
560 points[1].x = -trianglesHalfWidth;
561 points[2].x = trianglesHalfWidth;
562 temp_dc.DrawPolygon(3,points,pxActual,0);
565 if (realX_vertical_line!=-1)
567 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
568 int pixelX_guide = ((realX_vertical_line - _min)*(_w-deviceEndMargin))/(_max - _min) ;
569 temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, barHeight);
572 //Information Device drawing
576 //temp_dc.SelectObject( *_bitmap_info );
577 /*temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID ));
578 temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID ));*/
579 //temp_dc.DrawRectangle(deviceStart_x,_h+deviceStart_y,_w+deviceStart_x+40,_h+deviceStart_y+40);
580 //temp_dc.DrawRectangle(0,_h,_w+40-deviceEndMargin,_h+40);
582 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
583 temp_dc.SetFont(font);
584 temp_dc.SetTextForeground(*wxBLACK);
587 //the **MIN** value, always at the same y level that corresponds to barHeight+1
589 // text_min<< GetMin();
590 text_min.Printf(_T("%d"), (int)GetMin() );
592 temp_dc.DrawText(text_min,0,barHeight+1);
594 //the **MAX** value always at the same place
596 // text_max << GetMax();
597 text_max.Printf(_T("%d"), (int)GetMax() );
599 //As there is a margin of 40 extra most numbers (max) should be visibles
600 // stringSize = temp_dc.GetTextExtent(text_max);
602 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
603 wxSize stringSize(tmpX,tmpY);
605 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth())/*2*trianglesHalfWidth*/,barHeight+1);
607 //show logical values
608 //show the **START TRIANGLE** value
610 // text_start << GetStart();
611 text_start.Printf(_T("%d"), (int)GetStart() );
613 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
614 //show the **END TRIANGLE** value
616 // text_end << GetEnd();
617 text_end.Printf(_T("%d"), (int)GetEnd() );
619 // stringSize = temp_dc.GetTextExtent(text_end);
620 temp_dc.GetTextExtent(text_end,&tmpX,&tmpY);
621 stringSize.SetHeight(tmpY);
622 stringSize.SetWidth(tmpX);
623 temp_dc.DrawText(text_end, pxEnd-stringSize.GetWidth(),barHeight+3*letterHeight);
624 if( withActualDrawed )
626 //show the actual value of actual
627 wxString text_actual;
628 // text_actual << GetActual();
629 text_actual.Printf(_T("%d"), (int)GetActual() );
630 // stringSize = temp_dc.GetTextExtent(text_actual);
631 temp_dc.GetTextExtent(text_actual,&tmpX,&tmpY);
632 stringSize.SetHeight(tmpY);
633 stringSize.SetWidth(tmpX);
634 temp_dc.DrawText(text_actual, pxActual-(stringSize.GetWidth()/2),barHeight+letterHeight);
640 //----------------------------------------------------------------------------
641 //Repaint the bar if it is vertical
642 //----------------------------------------------------------------------------
644 void mBarRange::RefreshVerticalView()
648 int px1=GetPixelStart();
649 int px2=GetPixelEnd();
650 int px3=GetPixelActual();
651 int letterHeight = 9;
652 int panelHeight = 9*3+_w;
657 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
663 temp_dc.SelectObject( *_bitmap_bar );
666 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
667 temp_dc.SetPen(wxPen( backgroundColor ));
669 temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
672 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
673 temp_dc.DrawLine(0,trianglesHalfWidth+2, 0, _w-deviceEndMargin);
674 temp_dc.DrawLine(barWidth, trianglesHalfWidth+2, barWidth, (_w-deviceEndMargin-trianglesHalfWidth-2));
675 temp_dc.SetDeviceOrigin(0,trianglesHalfWidth+2);
678 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
679 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
680 temp_dc.DrawRectangle( 0,px1 ,_h, px2-px1 );
684 if( _selectionMoveId==4 )
686 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
687 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
691 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
692 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
694 temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
697 // 2 Shadow Triangles: Start and End
701 points[1].y = -trianglesHalfWidth-1;
703 points[2].y = trianglesHalfWidth+2;
704 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
705 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
706 temp_dc.DrawPolygon(3,points,0,px1);
707 temp_dc.DrawPolygon(3,points,0,px2);
709 // 2 Triangles: Start and End
713 points[1].y = -trianglesHalfWidth;
715 points[2].y = trianglesHalfWidth;
716 //first triangle (start)
717 if( _selectionMoveId==1 )
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( start_Colour,wxSOLID ));
725 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
727 temp_dc.DrawPolygon(3,points,0,px1);
728 //second triangle (end)
729 if( _selectionMoveId==2 )
731 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
732 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
736 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
737 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
739 temp_dc.DrawPolygon(3,points,0,px2);
741 if( withActualDrawed )
743 // 1 Shadow Triangle: Actual
744 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
745 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
749 points[1].y=-trianglesHalfWidth-1;
751 points[2].y=trianglesHalfWidth+2;
752 temp_dc.DrawPolygon(3,points,0,px3);
754 // 1 Triangle: Actual (red)
758 points[1].y = -trianglesHalfWidth;
760 points[2].y = trianglesHalfWidth;
761 if( _selectionMoveId==3 )
763 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
764 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
768 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
769 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
771 temp_dc.DrawPolygon(3,points,0,px3);
774 if (realX_vertical_line!=-1)
776 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
777 int pixelX_guide = realX_vertical_line*_w/(_max-_min)+deviceStart_x;
778 temp_dc.DrawLine(0,pixelX_guide, _h, pixelX_guide);
781 //Information Device drawing
784 /*temp_dc.SelectObject( *_bitmap_info );
786 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
787 temp_dc.SetPen(wxPen( backgroundColor ,1,wxSOLID ));
788 temp_dc.DrawRectangle(deviceStart_y,_w+deviceStart_x,_h+deviceStart_y+200,_w+deviceStart_x+200);
791 temp_dc.SetBackgroundMode(wxTRANSPARENT);
792 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
793 temp_dc.SetFont(font);
794 temp_dc.SetTextForeground(*wxBLACK);
796 //show logical values
797 //show the actual value of start
799 // text_start<<"Start:"<< GetStart();
800 text_start.Printf(_T("%s %d"),_T("Start: "), (int)GetStart() );
801 temp_dc.DrawText( text_start ,deviceStart_y, _w+deviceStart_x+letterHeight+1);
802 //show the actual value of end
804 // text_end <<"End: "<<GetEnd();
805 text_end.Printf(_T("%s %d"),_T("End: "), (int)GetEnd() );
806 temp_dc.DrawText( text_end ,deviceStart_y,_w+deviceStart_x+letterHeight*2 );
807 if( withActualDrawed )
809 //show the actual value of actual
810 wxString text_actual;
811 // text_actual <<"Actual: " <<GetActual();
812 text_actual.Printf(_T("%s %d"),_T("Actual: "), (int)GetActual() );
813 temp_dc.DrawText( text_actual ,deviceStart_y,_w+deviceStart_x+letterHeight*3);
815 //the min value, always at the same place
817 // text_min<<"Min: " << GetMin();
818 text_min.Printf(_T("%s %d"),_T("Min: "), (int)GetMin() );
819 temp_dc.DrawText( text_min ,deviceStart_y,_w+deviceStart_x+3);
820 //the max value always at the samen place
822 // text_max <<"Max: "<< GetMax();
823 text_max.Printf(_T("%s %d"),_T("Max: "), (int)GetMax() );
824 //toca calcular cuantol lo corremos
825 temp_dc.DrawText(text_max,deviceStart_y,_w+deviceStart_x+43);
830 //----------------------------------------------------------------------------
831 void mBarRange::RefreshForce()
836 //----------------------------------------------------------------------------
837 void mBarRange::OnMouseMove(wxMouseEvent& event )
841 wxPoint point = event.GetPosition();
845 setClickedX(point.x);
850 setClickedX(point.y);
853 int logicClick = getLogicValueofPixel(clickedX);
855 if( _selectionMoveId==-1 )
859 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
860 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
861 bool in_actualT= withActualDrawed && (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
862 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
865 _selectionMoveId = 3;
867 _selectionMoveId = 1;
869 _selectionMoveId = 2;
870 else if( in_movingBar )
871 _selectionMoveId = 4;
878 //is in start triagle
879 if( _selectionMoveId ==1 && event.LeftIsDown())
881 bool validPos_StartTri = (logicClick<GetEnd() && logicClick >=_min);
882 if( validPos_StartTri && !_in_rangeProperty)
884 SetPixelStart(clickedX);
886 RefreshHorizontalView();
887 //-------------------------------------------
888 // Sending the event of start triangle moved
889 //-------------------------------------------
890 createAndSendEvent( wxEVT_TSBAR_START );
892 //start has to be less than actual
893 else if (validPos_StartTri && _in_rangeProperty)
895 if(logicClick<=GetActual())
897 SetPixelStart(clickedX);
899 // RefreshHorizontalView();
900 //-------------------------------------------
901 // Sending the event of start triangle moved
902 //-------------------------------------------
903 createAndSendEvent( wxEVT_TSBAR_START );
906 } // _selectionMoveId == 1
908 else if( _selectionMoveId == 2 && event.LeftIsDown() )
910 bool validPos_EndTri = logicClick>GetStart()&& logicClick<=_max;
911 if( validPos_EndTri && !_in_rangeProperty )
913 SetPixelEnd(clickedX);
915 // RefreshHorizontalView();
916 //-------------------------------------------
917 //Sending the event of end triangle moved
918 //-------------------------------------------
919 createAndSendEvent( wxEVT_TSBAR_END );
921 //the end triangle cant be less than actual
922 else if( validPos_EndTri && _in_rangeProperty )
924 if(logicClick>=GetActual())
926 SetPixelEnd(clickedX);
928 // RefreshHorizontalView();
929 //-------------------------------------------
930 //Sending the event of end triangle moved
931 //-------------------------------------------
932 createAndSendEvent( wxEVT_TSBAR_END );
936 //is the actual triangle
937 else if( _selectionMoveId == 3 && event.LeftIsDown())
939 bool validPos_ActualTri=(logicClick<=_max) && (logicClick>=_min);
940 //is in actual triangle but it could be anywhere
941 if( validPos_ActualTri && !_in_rangeProperty )
943 SetPixelActual(clickedX);
945 RefreshHorizontalView();
946 //-------------------------------------------
947 //Sending the event of actual triangle moved
948 //-------------------------------------------
949 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
950 // createAndSendEvent( 98765 );
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 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1009 createAndSendEvent( wxEVT_TSBAR_END );
1010 createAndSendEvent( wxEVT_TSBAR_START );
1012 //if actual has to be between start and end
1013 else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
1015 SetStart(next_start);
1017 if( _moveActualWithBar )
1019 SetActual (next_actual);
1020 //-------------------------------------------
1021 //Sending the event of actual triangle moved
1022 //-------------------------------------------
1023 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1026 RefreshHorizontalView();
1028 //-------------------------------------------
1029 // Sending the event that the bar ahs being moved
1030 //-------------------------------------------
1031 createAndSendEvent( wxEVT_TSBAR_MOVED );
1033 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1034 createAndSendEvent( wxEVT_TSBAR_END );
1035 createAndSendEvent( wxEVT_TSBAR_START );
1039 if( !event.LeftIsDown())
1042 _selectionMoveId = -1;
1044 //-------------------------------------------
1045 //Sending a general event just because
1046 //-------------------------------------------
1047 //SIL//createAndSendEvent( wxEVT_TSBAR );
1048 createAndSendEvent(wxEVT_SELECTION_END);
1056 * Sets the represented minimum and maximunm values
1057 * param minRealValue The minimum represented value (real value)
1058 * param maxRealValue The maximum represented value (real value)
1060 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
1062 _min = minRealValue;
1063 _max = maxRealValue;
1069 * Sets the property for viewing or not the bar labels information
1071 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
1073 _visibleLables = setVisibleLB;
1077 * Sets the property for viewing or not the bar labels information
1078 * return _visibleLables The state of visible labels or not
1080 bool mBarRange ::getIfVisibleLabels ()
1082 return _visibleLables;
1086 * Sets the device start drawing left-superior (pixel) start point
1087 * param deviceStart_x Pixel start for x-coord
1088 * param deviceStart_y Pixel start for y-coord
1090 void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1092 deviceStart_x = devStart_x;
1093 deviceStart_y = devStart_y;
1094 // For the initialization case
1095 if (GetPixelEnd()<0)
1099 SetPixelStart(deviceStart_x);
1100 SetPixelEnd(_w+deviceStart_x);
1101 SetPixelActual(deviceStart_x);
1105 SetPixelStart(deviceStart_x);
1106 SetPixelEnd(_h+deviceStart_x);
1107 SetPixelActual(deviceStart_x);
1114 * Shows the popup menu
1116 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1120 bool validClic = false;
1123 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1127 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1132 setClickedX(event.GetX());
1134 setClickedX(event.GetY());
1136 if (getClickedX()<=_h)
1138 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1139 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1140 bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1141 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1144 _selectionMoveId = 1;
1145 else if( in_EndTri )
1146 _selectionMoveId = 2;
1147 else if( in_actualT )
1148 _selectionMoveId = 3;
1149 else if( in_movingBar )
1150 _selectionMoveId = 4;
1152 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1158 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1159 * param & anEvent The wxCommandEvent actioned event
1161 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1163 bool okSelectedColor = false;
1164 wxColour selectedColour;
1166 wxColourDialog dialog( GetParent(), &data);
1168 if ( dialog.ShowModal() == wxID_OK )
1170 selectedColour = dialog.GetColourData().GetColour();
1171 okSelectedColor = true;
1173 if( okSelectedColor )
1175 if (_selectionMoveId==1 )
1176 start_Colour = selectedColour;
1177 else if (_selectionMoveId==2 )
1178 end_Colour = selectedColour;
1179 else if( _selectionMoveId==3 )
1180 actual_Colour = selectedColour;
1181 else if( _selectionMoveId==4 )
1182 bar_Colour = selectedColour;
1184 _selectionMoveId = -1;
1190 * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1191 * param & anEvent The wxCommandEvent actioned event
1193 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1195 if (!_in_rangeProperty)
1197 if(IsActualInRange())
1199 SetInRangeProperty (true);
1200 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1205 SetInRangeProperty (false);
1206 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
1211 * 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.
1212 * param & anEvent The wxCommandEvent actioned event
1214 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1216 if (_moveActualWithBar )
1218 _moveActualWithBar = false;
1219 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1223 if(IsActualInRange())
1225 _moveActualWithBar = true;
1226 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1233 * param activeNow The new state
1235 void mBarRange :: setActiveStateTo (bool activeNow)
1237 activeState = activeNow;
1241 * Gets the active state of the bar
1242 * return activeState The actual state
1244 bool mBarRange :: isActive()
1250 * Gets the real-x value to draw a vertical line
1251 * return realX_vertical_line The real x value for the vertical line
1253 int mBarRange :: getRealX_vertical_line()
1255 return realX_vertical_line;
1259 * Sets the real-x value to draw a vertical line
1260 * param newReal_x The new real x value for the vertical line
1262 void mBarRange :: setRealX_vertical_line(int newReal_x)
1264 realX_vertical_line = newReal_x;
1268 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1269 * return deviceEndMargin The value asigned to the right margin
1271 int mBarRange :: getDeviceEndX()
1273 return deviceEndMargin;
1277 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1278 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1280 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1282 deviceEndMargin = newDeviceEnd_pixels;
1286 * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1287 * return clickedX The x-coord pixel value
1289 int mBarRange :: getClickedX()
1295 * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1296 * param nwClickX The x-coord pixel value
1298 void mBarRange :: setClickedX(int nwClickX)
1300 clickedX = nwClickX;
1305 * Gets the start porcentage with respect to the represented values of the bar
1306 * return The porcentage represented by the start showing point
1308 float mBarRange :: getStartShowPorcentage()
1310 return (float)( 1+(_start - _max)/(_max-_min));
1314 * Gets the end porcentage with respect to the represented values of the bar
1315 * return The porcentage represented by the end showing point
1317 float mBarRange :: getEndShowPorcentage()
1319 return (float) (1+(_end - _max)/(_max-_min));
1323 * Gets the actual porcentage with respect to the represented values of the bar
1324 * return The porcentage represented by the actual showing point
1326 float mBarRange :: getActualShowPorcentage()
1328 return (float) (1+(_actual - _max)/(_max-_min));
1331 int mBarRange :: getLogicValueofPixel(int thePixel)
1333 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1337 * Sets the condition for knowing if the actual triangle is being drawed or not
1338 * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1340 void mBarRange :: setIfWithActualDrawed(bool drawActual)
1342 if(!withActualDrawed && drawActual)
1344 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1345 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
1347 else if (withActualDrawed && !drawActual)
1349 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1350 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1352 withActualDrawed = drawActual;
1357 * Gets the condition for knowing if the actual triangle is being drawed or not
1358 * return withActualDrawed The condition for drawing or not the actual control
1360 bool mBarRange :: getIfWithActualDrawed()
1362 return withActualDrawed;
1365 void mBarRange::createAndSendEvent(WXTYPE theEventType)
1367 wxCommandEvent cevent( theEventType, GetId() );
1368 cevent.SetEventObject( this );
1369 GetEventHandler()->ProcessEvent( cevent );
1373 * Sets the background color od the bar
1374 * theColor The color to set to the backgroundColor
1376 void mBarRange :: setBackgroundColor(wxColour theColor)
1378 backgroundColor = theColor;
1382 * Sets the guide line color
1383 * param theNwGuideLineColor The color to set to the guideLineColor
1385 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1387 guideLineColor = theNwGuideLineColor;
1391 * Gets the guide line color
1392 * return guideLineColor The color of the guideLine
1394 wxColour mBarRange :: getGuideLineColour()
1396 return guideLineColor;
1399 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
1401 acceptedClick = true;
1405 void mBarRange::onLeftClickUp(wxMouseEvent& event )
1407 acceptedClick = false;
1410 //EED 20 Juillet 2011
1411 void mBarRange::onKey(wxKeyEvent& event)
1414 if ((event.GetKeyCode()==314) || (event.GetKeyCode()==317))
1419 if ((event.GetKeyCode()==315) || (event.GetKeyCode()==316))
1426 if (_selectionMoveId == 1) // start
1428 SetStart(GetStart()+step);
1429 createAndSendEvent( wxEVT_TSBAR_START );
1432 if (_selectionMoveId == 2) // end
1434 SetEnd(GetEnd()+step);
1435 createAndSendEvent( wxEVT_TSBAR_END );
1438 if (_selectionMoveId == 3) // actual
1440 SetActual(GetActual()+step);
1441 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1444 if (_selectionMoveId == 4) // bar
1446 if (( GetStart()+step>=_min ) && ( GetEnd()+step<=_max ))
1448 SetStart(GetStart()+step);
1449 SetEnd(GetEnd()+step);
1450 if (_moveActualWithBar)
1452 SetActual(GetActual()+step);
1454 createAndSendEvent( wxEVT_TSBAR_START );
1455 createAndSendEvent( wxEVT_TSBAR_END );
1456 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1457 createAndSendEvent( wxEVT_TSBAR_MOVED );
1458 } // Start>_min && End<_max
1459 }// _selectionMoveId == 4