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 //----------------------------------------------------------------------------
28 #include <wx/gdicmn.h>
30 #include "mBarRange.h"
33 //const wxEventType wxEVT_TSBAR = wxNewEventType();
35 DEFINE_EVENT_TYPE(wxEVT_TSBAR)
36 DEFINE_EVENT_TYPE(wxEVT_TSBAR_ACTUAL)
37 DEFINE_EVENT_TYPE(wxEVT_TSBAR_START)
38 DEFINE_EVENT_TYPE(wxEVT_TSBAR_END)
39 DEFINE_EVENT_TYPE(wxEVT_TSBAR_MOVED)
40 DEFINE_EVENT_TYPE(wxEVT_SELECTION_END)
44 //----------------------------------------------------------------------------
46 //----------------------------------------------------------------------------
48 IMPLEMENT_CLASS(mBarRange, wxScrolledWindow)
49 BEGIN_EVENT_TABLE(mBarRange, wxScrolledWindow)
50 EVT_PAINT (mBarRange::OnPaint)
51 EVT_SIZE (mBarRange::OnSize)
52 EVT_MOTION (mBarRange::OnMouseMove)
53 EVT_RIGHT_DOWN (mBarRange :: onShowPopupMenu)
54 EVT_MENU(cntID_CHANGE_COLOR, mBarRange :: onChangePartColor)
55 EVT_MENU(cntID_ENABLE_ACTUAL, mBarRange :: onEnableRange_Actual)
56 EVT_MENU(cntID_MOVABLE_ACTUAL_BAR, mBarRange :: onMovable_ActualWithBar)
59 EVT_LEFT_DOWN( mBarRange :: onLeftClicDown)
60 EVT_LEFT_UP( mBarRange :: onLeftClickUp)
62 EVT_CHAR( mBarRange :: onKey )
64 //how to catch the new event (our event)
65 //EVT_COMMAND (ID_MY_WINDOW, wxEVT_MY_EVENT, MyFrame::OnMyEvent)
69 //----------------------------------------------------------------------------
71 //----------------------------------------------------------------------------
73 mBarRange::mBarRange(wxWindow *parent, int w, int h)
74 :wxScrolledWindow(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
81 trianglesHalfWidth = 5;
84 // Setting the default parts colors
85 start_Colour = wxColour(1,0,255,254);
86 actual_Colour = wxColour(255,255,202);
87 end_Colour = wxColour(0,0,255);
88 bar_Colour = wxColour(255,0,255);
89 backgroundColor = parent ->GetBackgroundColour();
90 guideLineColor = wxColour(255,0,0);
92 //actual is in _start and end
93 //false means that it could be anywhere
94 _moveActualWithBar = false;
95 _in_rangeProperty = false;
96 _selectionMoveId = -1;
97 realX_vertical_line = -1;
102 SetOrientation(true);
103 setIfWithActualDrawed(true);
105 b_popmenu.Append (cntID_CHANGE_COLOR, _("Change Color"), _("Changes the color of the selected part"));
106 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
107 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
112 //----------------------------------------------------------------------------
114 //----------------------------------------------------------------------------
116 mBarRange::~mBarRange()
119 //---------------------------------------------------------------------------
120 //Draw bar: vertical or Horizontal
121 //---------------------------------------------------------------------------
122 void mBarRange::DrawBar()
127 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
128 _bitmap_bar = new wxBitmap(_w+1280,_h+100);
129 //SIL//_bitmap_info = new wxBitmap(_w+100+1280, _h+100);
134 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
135 _bitmap_bar = new wxBitmap(_h+deviceStart_y+100,_w+1280);
136 _bitmap_info = new wxBitmap(_h+deviceStart_y+100, _w+1280);
139 //----------------------------------------------------------------------------
141 //----------------------------------------------------------------------------
142 //----------------------------------------------------------------------------
143 //the property condition on actual triangle
144 //----------------------------------------------------------------------------
145 bool mBarRange::GetInRangeProperty()
147 return _in_rangeProperty;
149 //----------------------------------------------------------------------------
150 void mBarRange::SetInRangeProperty(bool in)
152 _in_rangeProperty=in;
154 //----------------------------------------------------------------------------
155 //the information about the actual triangle in range or not, true if is between start and end
156 //----------------------------------------------------------------------------
157 bool mBarRange::IsActualInRange()
159 return ( _actual <= _end && _actual >= _start );
162 //----------------------------------------------------------------------------
163 // the position of the rectangle, vertical or horizontal
164 //----------------------------------------------------------------------------
165 bool mBarRange::GetOrientation()
169 //-----------------------------------------------------------------------------
170 void mBarRange::SetOrientation(bool orientation)
176 _orientation=orientation;
179 //----------------------------------------------------------------------------
180 // _start of the pixel rectangle
181 //----------------------------------------------------------------------------
183 int mBarRange::GetPixelStart()
185 return ((_start - _min)*(_w-deviceEndMargin))/(_max - _min);
187 //----------------------------------------------------------------------------
188 // param i: value in pixels
189 //----------------------------------------------------------------------------
190 void mBarRange::SetPixelStart(int i)
192 _start = _min+((i - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
195 //----------------------------------------------------------------------------
196 // _actual of the pixel rectangle
197 //----------------------------------------------------------------------------
198 int mBarRange::GetPixelActual()
200 return ((_actual - _min)*(_w-deviceEndMargin))/(_max - _min);
202 //----------------------------------------------------------------------------
203 // param i: value in pixels
204 //----------------------------------------------------------------------------
205 void mBarRange::SetPixelActual(int i)
207 _actual = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
209 //----------------------------------------------------------------------------
210 // _end of the pixel rectangle
211 //----------------------------------------------------------------------------
212 int mBarRange::GetPixelEnd()
214 return ((_end - _min)*(_w-deviceEndMargin))/(_max - _min);
216 //----------------------------------------------------------------------------
217 // param i: value in pixels to be converted to real logical value
218 //----------------------------------------------------------------------------
219 void mBarRange::SetPixelEnd(int i)
221 _end = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
223 //----------------------------------------------------------------------------
224 // Logical max of the triangle
225 //----------------------------------------------------------------------------
227 double mBarRange::GetMax()
232 //----------------------------------------------------------------------------
233 void mBarRange::SetMax(double i)
237 //----------------------------------------------------------------------------
238 // Logical min of the triangle
239 //----------------------------------------------------------------------------
241 double mBarRange::GetMin()
246 //----------------------------------------------------------------------------
247 void mBarRange::SetMin(double i)
252 //----------------------------------------------------------------------------
253 // pixel dimensions of the rectangle
254 //----------------------------------------------------------------------------
256 int mBarRange::GetWidth()
260 //----------------------------------------------------------------------------
261 void mBarRange::SetWidth(int w)
265 //----------------------------------------------------------------------------
266 int mBarRange::GetHeight()
271 //----------------------------------------------------------------------------
272 void mBarRange::SetHeight(int h)
277 //----------------------------------------------------------------------------
278 // Logical Start of the rectangle
279 //----------------------------------------------------------------------------
281 int mBarRange::filtreValue(int value)
286 } else if (value>_max) {
292 //----------------------------------------------------------------------------
293 int mBarRange::GetStart()
297 //----------------------------------------------------------------------------
298 // param start: value real units
299 //----------------------------------------------------------------------------
300 void mBarRange::SetStart(int newstart)
302 _start = filtreValue(newstart);
309 if (_in_rangeProperty==true)
311 if (_start>_actual) { _start=_actual; }
316 //----------------------------------------------------------------------------
317 // Logical End of the rectangle
318 //----------------------------------------------------------------------------
320 int mBarRange::GetEnd()
324 //----------------------------------------------------------------------------
325 // param end: value pixel units
326 //----------------------------------------------------------------------------
327 void mBarRange::SetEnd(int newend)
329 _end = filtreValue(newend);
330 if (_end<_start) { _end=_start; }
331 if (_in_rangeProperty==true)
340 //----------------------------------------------------------------------------
341 // logical Actual of the rectangle
342 //----------------------------------------------------------------------------
343 int mBarRange::GetActual()
347 //----------------------------------------------------------------------------
348 void mBarRange::SetActual(int newactual)
350 _actual = filtreValue(newactual);
351 if (_in_rangeProperty==true)
353 if (_actual<_start) { _actual=_start; }
354 if (_actual>_end) { _actual=_end; }
359 //----------------------------------------------------------------------------
361 //----------------------------------------------------------------------------
362 int mBarRange::GetTrianglesHalfWidth()
364 return trianglesHalfWidth;
367 //----------------------------------------------------------------------------
368 void mBarRange::SetTrianglesHalfWidth(int nwTriHalfWidth)
370 trianglesHalfWidth = nwTriHalfWidth;
373 void mBarRange::OnSize( wxSizeEvent &WXUNUSED(event) )
375 wxRect rectTotal = GetClientRect();
378 SetWidth( rectTotal.GetWidth() - deviceEndMargin );
380 SetWidth( rectTotal.GetHeight() - deviceEndMargin);
382 _selectionMoveId = -1;
386 //----------------------------------------------------------------------------
388 void mBarRange::Refresh(bool eraseBackground, const wxRect* rect)
390 wxScrolledWindow::Refresh(false);
394 //----------------------------------------------------------------------------
396 //----------------------------------------------------------------------------
397 void mBarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
399 if (_bitmap_bar!=NULL)
404 RefreshHorizontalView();
406 temp_dc.SelectObject( *_bitmap_bar );
407 wxPaintDC dc( this );
408 dc.Blit(deviceStart_x-(trianglesHalfWidth+2), deviceStart_y, _w-deviceEndMargin+2*(trianglesHalfWidth+2), _h, &temp_dc, 0, 0);
410 // if (_visibleLables)
412 // temp_dc.SelectObject( *_bitmap_info );
413 // dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+200, &temp_dc, deviceStart_x, deviceStart_y);
414 // //dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+60, &temp_dc, 0, 0);
418 RefreshVerticalView();
420 temp_dc.SelectObject( *_bitmap_bar );
421 wxPaintDC dc( this );
422 // dc.Blit(deviceStart_y,deviceStart_x, _h+deviceStart_y-deviceEndMargin,_w+deviceStart_x-deviceEndMargin, &temp_dc, 0, 0);
423 dc.Blit(deviceStart_y,deviceStart_x-(trianglesHalfWidth+2), _h,_w-deviceEndMargin+2*(trianglesHalfWidth+2), &temp_dc, 0, 0);
426 // if (_visibleLables)
428 // temp_dc.SelectObject( *_bitmap_info );
429 // dc.Blit(0,_w, _h+deviceStart_y+200, _w+deviceStart_x+200-deviceEndMargin, &temp_dc, deviceStart_y,_w+deviceStart_x);
437 //----------------------------------------------------------------------------
438 //Repaint the bar if it is horizontal
439 //----------------------------------------------------------------------------
440 void mBarRange::RefreshHorizontalView()
444 //int largestNumberWidthInPixels = 15; // JPRx
445 int pxStart = GetPixelStart();
446 int pxEnd = GetPixelEnd();
447 int pxActual = GetPixelActual();
450 int barHeight = 2*letterHeight;
451 int tempHeight = _h-(6*letterHeight);
455 barHeight = (tempHeight>0) ? tempHeight : (int) _h/2;
461 temp_dc.SelectObject( *_bitmap_bar );
463 // Background of this widget
464 temp_dc.SetPen(wxPen( backgroundColor ));
465 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
466 temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
467 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
468 temp_dc.DrawLine(trianglesHalfWidth+2, 0, _w-deviceEndMargin, 0);
469 temp_dc.DrawLine(trianglesHalfWidth+2, barHeight, (_w-deviceEndMargin-trianglesHalfWidth-2), barHeight);
470 temp_dc.SetDeviceOrigin(trianglesHalfWidth+2,0);
473 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
474 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
475 temp_dc.DrawRectangle( pxStart , 0, pxEnd-pxStart, barHeight);
478 if( _selectionMoveId==4 )
480 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
481 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
483 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
484 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
486 temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
488 // 2 Shadow Triangles: Start and End
489 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
490 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
492 points[0].y= barHeight;
493 points[1].x= -trianglesHalfWidth-1;
495 points[2].x= trianglesHalfWidth+2;
497 temp_dc.DrawPolygon(3,points,pxStart,0);
498 temp_dc.DrawPolygon(3,points,pxEnd,0);
500 // 2 Triangles: Start and End
501 points[1].x = -trianglesHalfWidth;
502 points[2].x = trianglesHalfWidth;
504 //first triangle (start)
505 if( _selectionMoveId == 1 )
507 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
508 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
510 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
511 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
513 temp_dc.DrawPolygon(3,points,pxStart,0);
514 //second triangle (end)
515 if( _selectionMoveId == 2 )
517 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
518 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
520 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
521 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
523 temp_dc.DrawPolygon(3,points,pxEnd,0);
525 if( withActualDrawed )
527 // 1 Shadow Triangle: Actual
528 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
529 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
530 points[1].x = -trianglesHalfWidth-1;
531 points[2].x = trianglesHalfWidth+2;
533 temp_dc.DrawPolygon(3,points,pxActual,0);
535 // 1 Triangle: Actual (red)
536 if( _selectionMoveId==3 )
538 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
539 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
541 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
542 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
544 points[1].x = -trianglesHalfWidth;
545 points[2].x = trianglesHalfWidth;
546 temp_dc.DrawPolygon(3,points,pxActual,0);
549 if (realX_vertical_line!=-1)
551 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
552 int pixelX_guide = ((realX_vertical_line - _min)*(_w-deviceEndMargin))/(_max - _min) ;
553 temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, barHeight);
556 //Information Device drawing
560 //temp_dc.SelectObject( *_bitmap_info );
561 /*temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID ));
562 temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID ));*/
563 //temp_dc.DrawRectangle(deviceStart_x,_h+deviceStart_y,_w+deviceStart_x+40,_h+deviceStart_y+40);
564 //temp_dc.DrawRectangle(0,_h,_w+40-deviceEndMargin,_h+40);
566 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
567 temp_dc.SetFont(font);
568 temp_dc.SetTextForeground(*wxBLACK);
570 //the **MIN** value, always at the same y level that corresponds to barHeight+1
572 // text_min<< GetMin();
573 text_min.Printf(_T("%d"), (int)GetMin() );
575 temp_dc.DrawText(text_min,0,barHeight+1);
577 //the **MAX** value always at the same place
579 // text_max << GetMax();
580 text_max.Printf(_T("%d"), (int)GetMax() );
582 //As there is a margin of 40 extra most numbers (max) should be visibles
583 // stringSize = temp_dc.GetTextExtent(text_max);
585 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
586 wxSize stringSize(tmpX,tmpY);
588 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth())/*2*trianglesHalfWidth*/,barHeight+1);
590 //show logical values
591 //show the **START TRIANGLE** value
593 // text_start << GetStart();
594 text_start.Printf(_T("%d"), (int)GetStart() );
596 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
597 //show the **END TRIANGLE** value
599 // text_end << GetEnd();
600 text_end.Printf(_T("%d"), (int)GetEnd() );
602 // stringSize = temp_dc.GetTextExtent(text_end);
603 temp_dc.GetTextExtent(text_end,&tmpX,&tmpY);
604 stringSize.SetHeight(tmpY);
605 stringSize.SetWidth(tmpX);
606 temp_dc.DrawText(text_end, pxEnd-stringSize.GetWidth(),barHeight+3*letterHeight);
607 if( withActualDrawed )
609 //show the actual value of actual
610 wxString text_actual;
611 // text_actual << GetActual();
612 text_actual.Printf(_T("%d"), (int)GetActual() );
613 // stringSize = temp_dc.GetTextExtent(text_actual);
614 temp_dc.GetTextExtent(text_actual,&tmpX,&tmpY);
615 stringSize.SetHeight(tmpY);
616 stringSize.SetWidth(tmpX);
617 temp_dc.DrawText(text_actual, pxActual-(stringSize.GetWidth()/2),barHeight+letterHeight);
622 //----------------------------------------------------------------------------
623 //Repaint the bar if it is vertical
624 //----------------------------------------------------------------------------
626 void mBarRange::RefreshVerticalView()
630 int px1=GetPixelStart();
631 int px2=GetPixelEnd();
632 int px3=GetPixelActual();
633 int letterHeight = 9;
634 int panelHeight = 9*3+_w;
639 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
645 temp_dc.SelectObject( *_bitmap_bar );
648 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
649 temp_dc.SetPen(wxPen( backgroundColor ));
651 temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
654 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
655 temp_dc.DrawLine(0,trianglesHalfWidth+2, 0, _w-deviceEndMargin);
656 temp_dc.DrawLine(barWidth, trianglesHalfWidth+2, barWidth, (_w-deviceEndMargin-trianglesHalfWidth-2));
657 temp_dc.SetDeviceOrigin(0,trianglesHalfWidth+2);
660 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
661 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
662 temp_dc.DrawRectangle( 0,px1 ,_h, px2-px1 );
666 if( _selectionMoveId==4 )
668 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
669 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
673 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
674 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
676 temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
679 // 2 Shadow Triangles: Start and End
683 points[1].y = -trianglesHalfWidth-1;
685 points[2].y = trianglesHalfWidth+2;
686 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
687 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
688 temp_dc.DrawPolygon(3,points,0,px1);
689 temp_dc.DrawPolygon(3,points,0,px2);
691 // 2 Triangles: Start and End
695 points[1].y = -trianglesHalfWidth;
697 points[2].y = trianglesHalfWidth;
698 //first triangle (start)
699 if( _selectionMoveId==1 )
701 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
702 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
706 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
707 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
709 temp_dc.DrawPolygon(3,points,0,px1);
710 //second triangle (end)
711 if( _selectionMoveId==2 )
713 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
714 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
718 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
719 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
721 temp_dc.DrawPolygon(3,points,0,px2);
723 if( withActualDrawed )
725 // 1 Shadow Triangle: Actual
726 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
727 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
731 points[1].y=-trianglesHalfWidth-1;
733 points[2].y=trianglesHalfWidth+2;
734 temp_dc.DrawPolygon(3,points,0,px3);
736 // 1 Triangle: Actual (red)
740 points[1].y = -trianglesHalfWidth;
742 points[2].y = trianglesHalfWidth;
743 if( _selectionMoveId==3 )
745 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
746 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
750 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
751 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
753 temp_dc.DrawPolygon(3,points,0,px3);
756 if (realX_vertical_line!=-1)
758 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
759 int pixelX_guide = realX_vertical_line*_w/(_max-_min)+deviceStart_x;
760 temp_dc.DrawLine(0,pixelX_guide, _h, pixelX_guide);
763 //Information Device drawing
766 /*temp_dc.SelectObject( *_bitmap_info );
768 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
769 temp_dc.SetPen(wxPen( backgroundColor ,1,wxSOLID ));
770 temp_dc.DrawRectangle(deviceStart_y,_w+deviceStart_x,_h+deviceStart_y+200,_w+deviceStart_x+200);
773 temp_dc.SetBackgroundMode(wxTRANSPARENT);
774 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
775 temp_dc.SetFont(font);
776 temp_dc.SetTextForeground(*wxBLACK);
778 //show logical values
779 //show the actual value of start
781 // text_start<<"Start:"<< GetStart();
782 text_start.Printf(_T("%s %d"),_T("Start: "), (int)GetStart() );
783 temp_dc.DrawText( text_start ,deviceStart_y, _w+deviceStart_x+letterHeight+1);
784 //show the actual value of end
786 // text_end <<"End: "<<GetEnd();
787 text_end.Printf(_T("%s %d"),_T("End: "), (int)GetEnd() );
788 temp_dc.DrawText( text_end ,deviceStart_y,_w+deviceStart_x+letterHeight*2 );
789 if( withActualDrawed )
791 //show the actual value of actual
792 wxString text_actual;
793 // text_actual <<"Actual: " <<GetActual();
794 text_actual.Printf(_T("%s %d"),_T("Actual: "), (int)GetActual() );
795 temp_dc.DrawText( text_actual ,deviceStart_y,_w+deviceStart_x+letterHeight*3);
797 //the min value, always at the same place
799 // text_min<<"Min: " << GetMin();
800 text_min.Printf(_T("%s %d"),_T("Min: "), (int)GetMin() );
801 temp_dc.DrawText( text_min ,deviceStart_y,_w+deviceStart_x+3);
802 //the max value always at the samen place
804 // text_max <<"Max: "<< GetMax();
805 text_max.Printf(_T("%s %d"),_T("Max: "), (int)GetMax() );
806 //toca calcular cuantol lo corremos
807 temp_dc.DrawText(text_max,deviceStart_y,_w+deviceStart_x+43);
812 //----------------------------------------------------------------------------
813 void mBarRange::RefreshForce()
818 //----------------------------------------------------------------------------
819 void mBarRange::OnMouseMove(wxMouseEvent& event )
823 wxPoint point = event.GetPosition();
827 setClickedX(point.x);
832 setClickedX(point.y);
835 int logicClick = getLogicValueofPixel(clickedX);
837 if( _selectionMoveId==-1 )
841 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
842 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
843 bool in_actualT= withActualDrawed && (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
844 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
847 _selectionMoveId = 3;
849 _selectionMoveId = 1;
851 _selectionMoveId = 2;
852 else if( in_movingBar )
853 _selectionMoveId = 4;
860 //is in start triagle
861 if( _selectionMoveId ==1 && event.LeftIsDown())
863 bool validPos_StartTri = (logicClick<GetEnd() && logicClick >=_min);
864 if( validPos_StartTri && !_in_rangeProperty)
866 SetPixelStart(clickedX);
868 RefreshHorizontalView();
869 //-------------------------------------------
870 // Sending the event of start triangle moved
871 //-------------------------------------------
872 createAndSendEvent( wxEVT_TSBAR_START );
874 //start has to be less than actual
875 else if (validPos_StartTri && _in_rangeProperty)
877 if(logicClick<=GetActual())
879 SetPixelStart(clickedX);
881 // RefreshHorizontalView();
882 //-------------------------------------------
883 // Sending the event of start triangle moved
884 //-------------------------------------------
885 createAndSendEvent( wxEVT_TSBAR_START );
888 } // _selectionMoveId == 1
890 else if( _selectionMoveId == 2 && event.LeftIsDown() )
892 bool validPos_EndTri = logicClick>GetStart()&& logicClick<=_max;
893 if( validPos_EndTri && !_in_rangeProperty )
895 SetPixelEnd(clickedX);
897 // RefreshHorizontalView();
898 //-------------------------------------------
899 //Sending the event of end triangle moved
900 //-------------------------------------------
901 createAndSendEvent( wxEVT_TSBAR_END );
903 //the end triangle cant be less than actual
904 else if( validPos_EndTri && _in_rangeProperty )
906 if(logicClick>=GetActual())
908 SetPixelEnd(clickedX);
910 // RefreshHorizontalView();
911 //-------------------------------------------
912 //Sending the event of end triangle moved
913 //-------------------------------------------
914 createAndSendEvent( wxEVT_TSBAR_END );
918 //is the actual triangle
919 else if( _selectionMoveId == 3 && event.LeftIsDown())
921 bool validPos_ActualTri=(logicClick<=_max) && (logicClick>=_min);
922 //is in actual triangle but it could be anywhere
923 if( validPos_ActualTri && !_in_rangeProperty )
925 SetPixelActual(clickedX);
927 RefreshHorizontalView();
928 //-------------------------------------------
929 //Sending the event of actual triangle moved
930 //-------------------------------------------
931 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
932 // createAndSendEvent( 98765 );
934 else if( validPos_ActualTri && _in_rangeProperty )
935 // the tringle in between start and end
937 if( logicClick>=GetStart() && logicClick<=GetEnd())
939 SetPixelActual(clickedX);
941 RefreshHorizontalView();
942 //-------------------------------------------
943 //Sending the event of actual triangle moved
944 //-------------------------------------------
945 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
950 else if ( _selectionMoveId == 4 && event.LeftIsDown() )
952 //FILE * f=fopen("E:/borrar/file.txt","a+");
953 if(_initialPoint == 0)
955 _initialPoint = logicClick;
956 logicInitial_start = GetStart();
957 logicInitial_end = GetEnd();
958 logicInitial_actual = GetActual();
959 //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);
961 int difference = logicClick -_initialPoint;
962 int next_end = difference + logicInitial_end;
963 int next_start = difference + logicInitial_start;
964 int next_actual = difference + logicInitial_actual;
966 /*SIL//fprintf(f,"diff:%d, next_end%d, next_start%d, next_actual%d \n", difference,next_end,next_start,next_actual);
969 //if actual is not fixed to be in the middle
970 if( ((logicClick>next_start) && (logicClick<next_end)&& (next_end<=_max)&& (next_start>=_min)) && !_in_rangeProperty)
972 SetStart(next_start);
974 if( _moveActualWithBar )
976 SetActual (next_actual);
977 //-------------------------------------------
978 //Sending the event of actual triangle moved
979 //-------------------------------------------
980 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
983 RefreshHorizontalView();
985 //-------------------------------------------
986 // Sending the event that the bar ahs being moved
987 //-------------------------------------------
988 createAndSendEvent( wxEVT_TSBAR_MOVED );
990 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
991 createAndSendEvent( wxEVT_TSBAR_END );
992 createAndSendEvent( wxEVT_TSBAR_START );
994 //if actual has to be between start and end
995 else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
997 SetStart(next_start);
999 if( _moveActualWithBar )
1001 SetActual (next_actual);
1002 //-------------------------------------------
1003 //Sending the event of actual triangle moved
1004 //-------------------------------------------
1005 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1008 RefreshHorizontalView();
1010 //-------------------------------------------
1011 // Sending the event that the bar ahs being moved
1012 //-------------------------------------------
1013 createAndSendEvent( wxEVT_TSBAR_MOVED );
1015 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1016 createAndSendEvent( wxEVT_TSBAR_END );
1017 createAndSendEvent( wxEVT_TSBAR_START );
1021 if( !event.LeftIsDown())
1024 _selectionMoveId = -1;
1026 //-------------------------------------------
1027 //Sending a general event just because
1028 //-------------------------------------------
1029 //SIL//createAndSendEvent( wxEVT_TSBAR );
1030 createAndSendEvent(wxEVT_SELECTION_END);
1038 * Sets the represented minimum and maximunm values
1039 * param minRealValue The minimum represented value (real value)
1040 * param maxRealValue The maximum represented value (real value)
1042 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
1044 _min = minRealValue;
1045 _max = maxRealValue;
1051 * Sets the property for viewing or not the bar labels information
1053 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
1055 _visibleLables = setVisibleLB;
1059 * Sets the property for viewing or not the bar labels information
1060 * return _visibleLables The state of visible labels or not
1062 bool mBarRange ::getIfVisibleLabels ()
1064 return _visibleLables;
1068 * Sets the device start drawing left-superior (pixel) start point
1069 * param deviceStart_x Pixel start for x-coord
1070 * param deviceStart_y Pixel start for y-coord
1072 void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1074 deviceStart_x = devStart_x;
1075 deviceStart_y = devStart_y;
1076 // For the initialization case
1077 if (GetPixelEnd()<0)
1081 SetPixelStart(deviceStart_x);
1082 SetPixelEnd(_w+deviceStart_x);
1083 SetPixelActual(deviceStart_x);
1087 SetPixelStart(deviceStart_x);
1088 SetPixelEnd(_h+deviceStart_x);
1089 SetPixelActual(deviceStart_x);
1096 * Shows the popup menu
1098 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1102 bool validClic = false;
1105 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1109 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1114 setClickedX(event.GetX());
1116 setClickedX(event.GetY());
1118 if (getClickedX()<=_h)
1120 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1121 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1122 bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1123 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1126 _selectionMoveId = 1;
1127 else if( in_EndTri )
1128 _selectionMoveId = 2;
1129 else if( in_actualT )
1130 _selectionMoveId = 3;
1131 else if( in_movingBar )
1132 _selectionMoveId = 4;
1134 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1140 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1141 * param & anEvent The wxCommandEvent actioned event
1143 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1145 bool okSelectedColor = false;
1146 wxColour selectedColour;
1148 wxColourDialog dialog( GetParent(), &data);
1150 if ( dialog.ShowModal() == wxID_OK )
1152 selectedColour = dialog.GetColourData().GetColour();
1153 okSelectedColor = true;
1155 if( okSelectedColor )
1157 if (_selectionMoveId==1 )
1158 start_Colour = selectedColour;
1159 else if (_selectionMoveId==2 )
1160 end_Colour = selectedColour;
1161 else if( _selectionMoveId==3 )
1162 actual_Colour = selectedColour;
1163 else if( _selectionMoveId==4 )
1164 bar_Colour = selectedColour;
1166 _selectionMoveId = -1;
1172 * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1173 * param & anEvent The wxCommandEvent actioned event
1175 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1177 if (!_in_rangeProperty)
1179 if(IsActualInRange())
1181 SetInRangeProperty (true);
1182 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1187 SetInRangeProperty (false);
1188 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
1193 * 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.
1194 * param & anEvent The wxCommandEvent actioned event
1196 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1198 if (_moveActualWithBar )
1200 _moveActualWithBar = false;
1201 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1205 if(IsActualInRange())
1207 _moveActualWithBar = true;
1208 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1215 * param activeNow The new state
1217 void mBarRange :: setActiveStateTo (bool activeNow)
1219 activeState = activeNow;
1223 * Gets the active state of the bar
1224 * return activeState The actual state
1226 bool mBarRange :: isActive()
1232 * Gets the real-x value to draw a vertical line
1233 * return realX_vertical_line The real x value for the vertical line
1235 int mBarRange :: getRealX_vertical_line()
1237 return realX_vertical_line;
1241 * Sets the real-x value to draw a vertical line
1242 * param newReal_x The new real x value for the vertical line
1244 void mBarRange :: setRealX_vertical_line(int newReal_x)
1246 realX_vertical_line = newReal_x;
1250 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1251 * return deviceEndMargin The value asigned to the right margin
1253 int mBarRange :: getDeviceEndX()
1255 return deviceEndMargin;
1259 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1260 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1262 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1264 deviceEndMargin = newDeviceEnd_pixels;
1268 * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1269 * return clickedX The x-coord pixel value
1271 int mBarRange :: getClickedX()
1277 * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1278 * param nwClickX The x-coord pixel value
1280 void mBarRange :: setClickedX(int nwClickX)
1282 clickedX = nwClickX;
1287 * Gets the start porcentage with respect to the represented values of the bar
1288 * return The porcentage represented by the start showing point
1290 float mBarRange :: getStartShowPorcentage()
1292 return (float)( 1+(_start - _max)/(_max-_min));
1296 * Gets the end porcentage with respect to the represented values of the bar
1297 * return The porcentage represented by the end showing point
1299 float mBarRange :: getEndShowPorcentage()
1301 return (float) (1+(_end - _max)/(_max-_min));
1305 * Gets the actual porcentage with respect to the represented values of the bar
1306 * return The porcentage represented by the actual showing point
1308 float mBarRange :: getActualShowPorcentage()
1310 return (float) (1+(_actual - _max)/(_max-_min));
1313 int mBarRange :: getLogicValueofPixel(int thePixel)
1315 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1319 * Sets the condition for knowing if the actual triangle is being drawed or not
1320 * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1322 void mBarRange :: setIfWithActualDrawed(bool drawActual)
1324 if(!withActualDrawed && drawActual)
1326 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1327 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
1329 else if (withActualDrawed && !drawActual)
1331 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1332 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1334 withActualDrawed = drawActual;
1339 * Gets the condition for knowing if the actual triangle is being drawed or not
1340 * return withActualDrawed The condition for drawing or not the actual control
1342 bool mBarRange :: getIfWithActualDrawed()
1344 return withActualDrawed;
1347 void mBarRange::createAndSendEvent(WXTYPE theEventType)
1349 wxCommandEvent cevent( theEventType, GetId() );
1350 cevent.SetEventObject( this );
1351 GetEventHandler()->ProcessEvent( cevent );
1355 * Sets the background color od the bar
1356 * theColor The color to set to the backgroundColor
1358 void mBarRange :: setBackgroundColor(wxColour theColor)
1360 backgroundColor = theColor;
1364 * Sets the guide line color
1365 * param theNwGuideLineColor The color to set to the guideLineColor
1367 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1369 guideLineColor = theNwGuideLineColor;
1373 * Gets the guide line color
1374 * return guideLineColor The color of the guideLine
1376 wxColour mBarRange :: getGuideLineColour()
1378 return guideLineColor;
1381 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
1383 acceptedClick = true;
1387 void mBarRange::onLeftClickUp(wxMouseEvent& event )
1389 acceptedClick = false;
1392 //EED 20 Juillet 2011
1393 void mBarRange::onKey(wxKeyEvent& event)
1396 if ((event.GetKeyCode()==314) || (event.GetKeyCode()==317))
1401 if ((event.GetKeyCode()==315) || (event.GetKeyCode()==316))
1408 if (_selectionMoveId == 1) // start
1410 SetStart(GetStart()+step);
1411 createAndSendEvent( wxEVT_TSBAR_START );
1414 if (_selectionMoveId == 2) // end
1416 SetEnd(GetEnd()+step);
1417 createAndSendEvent( wxEVT_TSBAR_END );
1420 if (_selectionMoveId == 3) // actual
1422 SetActual(GetActual()+step);
1423 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1426 if (_selectionMoveId == 4) // bar
1428 if (( GetStart()+step>=_min ) && ( GetEnd()+step<=_max ))
1430 SetStart(GetStart()+step);
1431 SetEnd(GetEnd()+step);
1432 if (_moveActualWithBar)
1434 SetActual(GetActual()+step);
1436 createAndSendEvent( wxEVT_TSBAR_START );
1437 createAndSendEvent( wxEVT_TSBAR_END );
1438 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1439 createAndSendEvent( wxEVT_TSBAR_MOVED );
1440 } // Start>_min && End<_max
1441 }// _selectionMoveId == 4