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)
290 int mBarRange::GetStart()
294 //----------------------------------------------------------------------------
295 // param start: value real units
296 //----------------------------------------------------------------------------
297 void mBarRange::SetStart(int newstart)
299 _start = filtreValue(newstart);
300 if (_start>_end) { _start=_end; }
301 if (_in_rangeProperty==true)
303 if (_start>_actual) { _start=_actual; }
307 //----------------------------------------------------------------------------
308 // Logical End of the rectangle
309 //----------------------------------------------------------------------------
311 int mBarRange::GetEnd()
315 //----------------------------------------------------------------------------
316 // param end: value pixel units
317 //----------------------------------------------------------------------------
318 void mBarRange::SetEnd(int newend)
320 _end = filtreValue(newend);
321 if (_end<_start) { _end=_start; }
322 if (_in_rangeProperty==true)
324 if (_end<_actual) { _end=_actual; }
328 //----------------------------------------------------------------------------
329 // logical Actual of the rectangle
330 //----------------------------------------------------------------------------
331 int mBarRange::GetActual()
335 //----------------------------------------------------------------------------
336 void mBarRange::SetActual(int newactual)
338 _actual = filtreValue(newactual);
339 if (_in_rangeProperty==true)
341 if (_actual<_start) { _actual=_start; }
342 if (_actual>_end) { _actual=_end; }
347 //----------------------------------------------------------------------------
349 //----------------------------------------------------------------------------
350 int mBarRange::GetTrianglesHalfWidth()
352 return trianglesHalfWidth;
354 //----------------------------------------------------------------------------
355 void mBarRange::SetTrianglesHalfWidth(int nwTriHalfWidth)
357 trianglesHalfWidth = nwTriHalfWidth;
360 void mBarRange::OnSize( wxSizeEvent &WXUNUSED(event) )
362 wxRect rectTotal = GetClientRect();
365 SetWidth( rectTotal.GetWidth() - deviceEndMargin );
369 SetWidth( rectTotal.GetHeight() - deviceEndMargin);
371 _selectionMoveId = -1;
375 //----------------------------------------------------------------------------
377 void mBarRange::Refresh(bool eraseBackground, const wxRect* rect)
379 wxScrolledWindow::Refresh(false);
383 //----------------------------------------------------------------------------
385 //----------------------------------------------------------------------------
386 void mBarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
388 if (_bitmap_bar!=NULL){
392 RefreshHorizontalView();
394 temp_dc.SelectObject( *_bitmap_bar );
395 wxPaintDC dc( this );
396 dc.Blit(deviceStart_x-(trianglesHalfWidth+2), deviceStart_y, _w-deviceEndMargin+2*(trianglesHalfWidth+2), _h, &temp_dc, 0, 0);
398 // if (_visibleLables)
400 // temp_dc.SelectObject( *_bitmap_info );
401 // dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+200, &temp_dc, deviceStart_x, deviceStart_y);
402 // //dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+60, &temp_dc, 0, 0);
406 RefreshVerticalView();
408 temp_dc.SelectObject( *_bitmap_bar );
409 wxPaintDC dc( this );
410 // dc.Blit(deviceStart_y,deviceStart_x, _h+deviceStart_y-deviceEndMargin,_w+deviceStart_x-deviceEndMargin, &temp_dc, 0, 0);
411 dc.Blit(deviceStart_y,deviceStart_x-(trianglesHalfWidth+2), _h,_w-deviceEndMargin+2*(trianglesHalfWidth+2), &temp_dc, 0, 0);
414 // if (_visibleLables)
416 // temp_dc.SelectObject( *_bitmap_info );
417 // dc.Blit(0,_w, _h+deviceStart_y+200, _w+deviceStart_x+200-deviceEndMargin, &temp_dc, deviceStart_y,_w+deviceStart_x);
426 //----------------------------------------------------------------------------
427 //Repaint the bar if it is horizontal
428 //----------------------------------------------------------------------------
429 void mBarRange::RefreshHorizontalView()
433 //int largestNumberWidthInPixels = 15; // JPRx
434 int pxStart = GetPixelStart();
435 int pxEnd = GetPixelEnd();
436 int pxActual = GetPixelActual();
440 int barHeight = 2*letterHeight;
441 int tempHeight = _h-(6*letterHeight);
446 barHeight = (tempHeight>0) ? tempHeight : (int) _h/2;
452 temp_dc.SelectObject( *_bitmap_bar );
455 // Background of this widget
458 temp_dc.SetPen(wxPen( backgroundColor ));
459 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
461 temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
464 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
465 temp_dc.DrawLine(trianglesHalfWidth+2, 0, _w-deviceEndMargin, 0);
466 temp_dc.DrawLine(trianglesHalfWidth+2, barHeight, (_w-deviceEndMargin-trianglesHalfWidth-2), barHeight);
467 temp_dc.SetDeviceOrigin(trianglesHalfWidth+2,0);
471 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
472 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
473 temp_dc.DrawRectangle( pxStart , 0, pxEnd-pxStart, barHeight);
477 if( _selectionMoveId==4 )
479 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
480 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
484 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
485 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
487 temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
489 // 2 Shadow Triangles: Start and End
490 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
491 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
493 points[0].y= barHeight;
494 points[1].x= -trianglesHalfWidth-1;
496 points[2].x= trianglesHalfWidth+2;
498 temp_dc.DrawPolygon(3,points,pxStart,0);
499 temp_dc.DrawPolygon(3,points,pxEnd,0);
501 // 2 Triangles: Start and End
502 points[1].x = -trianglesHalfWidth;
503 points[2].x = trianglesHalfWidth;
505 //first triangle (start)
506 if( _selectionMoveId == 1 )
508 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
509 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
513 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
514 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
516 temp_dc.DrawPolygon(3,points,pxStart,0);
517 //second triangle (end)
518 if( _selectionMoveId == 2 )
520 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
521 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
525 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
526 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
528 temp_dc.DrawPolygon(3,points,pxEnd,0);
530 if( withActualDrawed )
532 // 1 Shadow Triangle: Actual
533 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
534 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
535 points[1].x = -trianglesHalfWidth-1;
536 points[2].x = trianglesHalfWidth+2;
538 temp_dc.DrawPolygon(3,points,pxActual,0);
540 // 1 Triangle: Actual (red)
541 if( _selectionMoveId==3 )
543 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
544 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
548 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
549 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
551 points[1].x = -trianglesHalfWidth;
552 points[2].x = trianglesHalfWidth;
553 temp_dc.DrawPolygon(3,points,pxActual,0);
556 if (realX_vertical_line!=-1)
558 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
559 int pixelX_guide = ((realX_vertical_line - _min)*(_w-deviceEndMargin))/(_max - _min) ;
560 temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, barHeight);
563 //Information Device drawing
567 //temp_dc.SelectObject( *_bitmap_info );
568 /*temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID ));
569 temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID ));*/
570 //temp_dc.DrawRectangle(deviceStart_x,_h+deviceStart_y,_w+deviceStart_x+40,_h+deviceStart_y+40);
571 //temp_dc.DrawRectangle(0,_h,_w+40-deviceEndMargin,_h+40);
573 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
574 temp_dc.SetFont(font);
575 temp_dc.SetTextForeground(*wxBLACK);
578 //the **MIN** value, always at the same y level that corresponds to barHeight+1
580 // text_min<< GetMin();
581 text_min.Printf(_T("%d"), (int)GetMin() );
583 temp_dc.DrawText(text_min,0,barHeight+1);
585 //the **MAX** value always at the same place
587 // text_max << GetMax();
588 text_max.Printf(_T("%d"), (int)GetMax() );
590 //As there is a margin of 40 extra most numbers (max) should be visibles
591 // stringSize = temp_dc.GetTextExtent(text_max);
593 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
594 wxSize stringSize(tmpX,tmpY);
596 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth())/*2*trianglesHalfWidth*/,barHeight+1);
598 //show logical values
599 //show the **START TRIANGLE** value
601 // text_start << GetStart();
602 text_start.Printf(_T("%d"), (int)GetStart() );
604 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
605 //show the **END TRIANGLE** value
607 // text_end << GetEnd();
608 text_end.Printf(_T("%d"), (int)GetEnd() );
610 // stringSize = temp_dc.GetTextExtent(text_end);
611 temp_dc.GetTextExtent(text_end,&tmpX,&tmpY);
612 stringSize.SetHeight(tmpY);
613 stringSize.SetWidth(tmpX);
614 temp_dc.DrawText(text_end, pxEnd-stringSize.GetWidth(),barHeight+3*letterHeight);
615 if( withActualDrawed )
617 //show the actual value of actual
618 wxString text_actual;
619 // text_actual << GetActual();
620 text_actual.Printf(_T("%d"), (int)GetActual() );
621 // stringSize = temp_dc.GetTextExtent(text_actual);
622 temp_dc.GetTextExtent(text_actual,&tmpX,&tmpY);
623 stringSize.SetHeight(tmpY);
624 stringSize.SetWidth(tmpX);
625 temp_dc.DrawText(text_actual, pxActual-(stringSize.GetWidth()/2),barHeight+letterHeight);
631 //----------------------------------------------------------------------------
632 //Repaint the bar if it is vertical
633 //----------------------------------------------------------------------------
635 void mBarRange::RefreshVerticalView()
639 int px1=GetPixelStart();
640 int px2=GetPixelEnd();
641 int px3=GetPixelActual();
642 int letterHeight = 9;
643 int panelHeight = 9*3+_w;
648 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
654 temp_dc.SelectObject( *_bitmap_bar );
657 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
658 temp_dc.SetPen(wxPen( backgroundColor ));
660 temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
663 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
664 temp_dc.DrawLine(0,trianglesHalfWidth+2, 0, _w-deviceEndMargin);
665 temp_dc.DrawLine(barWidth, trianglesHalfWidth+2, barWidth, (_w-deviceEndMargin-trianglesHalfWidth-2));
666 temp_dc.SetDeviceOrigin(0,trianglesHalfWidth+2);
669 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
670 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
671 temp_dc.DrawRectangle( 0,px1 ,_h, px2-px1 );
675 if( _selectionMoveId==4 )
677 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
678 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
682 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
683 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
685 temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
688 // 2 Shadow Triangles: Start and End
692 points[1].y = -trianglesHalfWidth-1;
694 points[2].y = trianglesHalfWidth+2;
695 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
696 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
697 temp_dc.DrawPolygon(3,points,0,px1);
698 temp_dc.DrawPolygon(3,points,0,px2);
700 // 2 Triangles: Start and End
704 points[1].y = -trianglesHalfWidth;
706 points[2].y = trianglesHalfWidth;
707 //first triangle (start)
708 if( _selectionMoveId==1 )
710 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
711 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
715 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
716 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
718 temp_dc.DrawPolygon(3,points,0,px1);
719 //second triangle (end)
720 if( _selectionMoveId==2 )
722 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
723 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
727 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
728 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
730 temp_dc.DrawPolygon(3,points,0,px2);
732 if( withActualDrawed )
734 // 1 Shadow Triangle: Actual
735 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
736 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
740 points[1].y=-trianglesHalfWidth-1;
742 points[2].y=trianglesHalfWidth+2;
743 temp_dc.DrawPolygon(3,points,0,px3);
745 // 1 Triangle: Actual (red)
749 points[1].y = -trianglesHalfWidth;
751 points[2].y = trianglesHalfWidth;
752 if( _selectionMoveId==3 )
754 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
755 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
759 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
760 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
762 temp_dc.DrawPolygon(3,points,0,px3);
765 if (realX_vertical_line!=-1)
767 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
768 int pixelX_guide = realX_vertical_line*_w/(_max-_min)+deviceStart_x;
769 temp_dc.DrawLine(0,pixelX_guide, _h, pixelX_guide);
772 //Information Device drawing
775 /*temp_dc.SelectObject( *_bitmap_info );
777 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
778 temp_dc.SetPen(wxPen( backgroundColor ,1,wxSOLID ));
779 temp_dc.DrawRectangle(deviceStart_y,_w+deviceStart_x,_h+deviceStart_y+200,_w+deviceStart_x+200);
782 temp_dc.SetBackgroundMode(wxTRANSPARENT);
783 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
784 temp_dc.SetFont(font);
785 temp_dc.SetTextForeground(*wxBLACK);
787 //show logical values
788 //show the actual value of start
790 // text_start<<"Start:"<< GetStart();
791 text_start.Printf(_T("%s %d"),_T("Start: "), (int)GetStart() );
792 temp_dc.DrawText( text_start ,deviceStart_y, _w+deviceStart_x+letterHeight+1);
793 //show the actual value of end
795 // text_end <<"End: "<<GetEnd();
796 text_end.Printf(_T("%s %d"),_T("End: "), (int)GetEnd() );
797 temp_dc.DrawText( text_end ,deviceStart_y,_w+deviceStart_x+letterHeight*2 );
798 if( withActualDrawed )
800 //show the actual value of actual
801 wxString text_actual;
802 // text_actual <<"Actual: " <<GetActual();
803 text_actual.Printf(_T("%s %d"),_T("Actual: "), (int)GetActual() );
804 temp_dc.DrawText( text_actual ,deviceStart_y,_w+deviceStart_x+letterHeight*3);
806 //the min value, always at the same place
808 // text_min<<"Min: " << GetMin();
809 text_min.Printf(_T("%s %d"),_T("Min: "), (int)GetMin() );
810 temp_dc.DrawText( text_min ,deviceStart_y,_w+deviceStart_x+3);
811 //the max value always at the samen place
813 // text_max <<"Max: "<< GetMax();
814 text_max.Printf(_T("%s %d"),_T("Max: "), (int)GetMax() );
815 //toca calcular cuantol lo corremos
816 temp_dc.DrawText(text_max,deviceStart_y,_w+deviceStart_x+43);
821 //----------------------------------------------------------------------------
822 void mBarRange::RefreshForce()
827 //----------------------------------------------------------------------------
828 void mBarRange::OnMouseMove(wxMouseEvent& event )
832 wxPoint point = event.GetPosition();
836 setClickedX(point.x);
841 setClickedX(point.y);
844 int logicClick = getLogicValueofPixel(clickedX);
846 if( _selectionMoveId==-1 )
850 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
851 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
852 bool in_actualT= withActualDrawed && (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
853 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
856 _selectionMoveId = 3;
858 _selectionMoveId = 1;
860 _selectionMoveId = 2;
861 else if( in_movingBar )
862 _selectionMoveId = 4;
869 //is in start triagle
870 if( _selectionMoveId ==1 && event.LeftIsDown())
872 bool validPos_StartTri = (logicClick<GetEnd() && logicClick >=_min);
873 if( validPos_StartTri && !_in_rangeProperty)
875 SetPixelStart(clickedX);
877 RefreshHorizontalView();
878 //-------------------------------------------
879 // Sending the event of start triangle moved
880 //-------------------------------------------
881 createAndSendEvent( wxEVT_TSBAR_START );
883 //start has to be less than actual
884 else if (validPos_StartTri && _in_rangeProperty)
886 if(logicClick<=GetActual())
888 SetPixelStart(clickedX);
890 // RefreshHorizontalView();
891 //-------------------------------------------
892 // Sending the event of start triangle moved
893 //-------------------------------------------
894 createAndSendEvent( wxEVT_TSBAR_START );
897 } // _selectionMoveId == 1
899 else if( _selectionMoveId == 2 && event.LeftIsDown() )
901 bool validPos_EndTri = logicClick>GetStart()&& logicClick<=_max;
902 if( validPos_EndTri && !_in_rangeProperty )
904 SetPixelEnd(clickedX);
906 // RefreshHorizontalView();
907 //-------------------------------------------
908 //Sending the event of end triangle moved
909 //-------------------------------------------
910 createAndSendEvent( wxEVT_TSBAR_END );
912 //the end triangle cant be less than actual
913 else if( validPos_EndTri && _in_rangeProperty )
915 if(logicClick>=GetActual())
917 SetPixelEnd(clickedX);
919 // RefreshHorizontalView();
920 //-------------------------------------------
921 //Sending the event of end triangle moved
922 //-------------------------------------------
923 createAndSendEvent( wxEVT_TSBAR_END );
927 //is the actual triangle
928 else if( _selectionMoveId == 3 && event.LeftIsDown())
930 bool validPos_ActualTri=(logicClick<=_max) && (logicClick>=_min);
931 //is in actual triangle but it could be anywhere
932 if( validPos_ActualTri && !_in_rangeProperty )
934 SetPixelActual(clickedX);
936 RefreshHorizontalView();
937 //-------------------------------------------
938 //Sending the event of actual triangle moved
939 //-------------------------------------------
940 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
941 // createAndSendEvent( 98765 );
943 else if( validPos_ActualTri && _in_rangeProperty )
944 // the tringle in between start and end
946 if( logicClick>=GetStart() && logicClick<=GetEnd())
948 SetPixelActual(clickedX);
950 RefreshHorizontalView();
951 //-------------------------------------------
952 //Sending the event of actual triangle moved
953 //-------------------------------------------
954 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
959 else if ( _selectionMoveId == 4 && event.LeftIsDown() )
961 //FILE * f=fopen("E:/borrar/file.txt","a+");
962 if(_initialPoint == 0)
964 _initialPoint = logicClick;
965 logicInitial_start = GetStart();
966 logicInitial_end = GetEnd();
967 logicInitial_actual = GetActual();
968 //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);
970 int difference = logicClick -_initialPoint;
971 int next_end = difference + logicInitial_end;
972 int next_start = difference + logicInitial_start;
973 int next_actual = difference + logicInitial_actual;
975 /*SIL//fprintf(f,"diff:%d, next_end%d, next_start%d, next_actual%d \n", difference,next_end,next_start,next_actual);
978 //if actual is not fixed to be in the middle
979 if( ((logicClick>next_start) && (logicClick<next_end)&& (next_end<=_max)&& (next_start>=_min)) && !_in_rangeProperty)
981 SetStart(next_start);
983 if( _moveActualWithBar )
985 SetActual (next_actual);
986 //-------------------------------------------
987 //Sending the event of actual triangle moved
988 //-------------------------------------------
989 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
992 RefreshHorizontalView();
994 //-------------------------------------------
995 // Sending the event that the bar ahs being moved
996 //-------------------------------------------
997 createAndSendEvent( wxEVT_TSBAR_MOVED );
999 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1000 createAndSendEvent( wxEVT_TSBAR_END );
1001 createAndSendEvent( wxEVT_TSBAR_START );
1003 //if actual has to be between start and end
1004 else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
1006 SetStart(next_start);
1008 if( _moveActualWithBar )
1010 SetActual (next_actual);
1011 //-------------------------------------------
1012 //Sending the event of actual triangle moved
1013 //-------------------------------------------
1014 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1017 RefreshHorizontalView();
1019 //-------------------------------------------
1020 // Sending the event that the bar ahs being moved
1021 //-------------------------------------------
1022 createAndSendEvent( wxEVT_TSBAR_MOVED );
1024 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1025 createAndSendEvent( wxEVT_TSBAR_END );
1026 createAndSendEvent( wxEVT_TSBAR_START );
1030 if( !event.LeftIsDown())
1033 _selectionMoveId = -1;
1035 //-------------------------------------------
1036 //Sending a general event just because
1037 //-------------------------------------------
1038 //SIL//createAndSendEvent( wxEVT_TSBAR );
1039 createAndSendEvent(wxEVT_SELECTION_END);
1047 * Sets the represented minimum and maximunm values
1048 * param minRealValue The minimum represented value (real value)
1049 * param maxRealValue The maximum represented value (real value)
1051 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
1053 _min = minRealValue;
1054 _max = maxRealValue;
1060 * Sets the property for viewing or not the bar labels information
1062 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
1064 _visibleLables = setVisibleLB;
1068 * Sets the property for viewing or not the bar labels information
1069 * return _visibleLables The state of visible labels or not
1071 bool mBarRange ::getIfVisibleLabels ()
1073 return _visibleLables;
1077 * Sets the device start drawing left-superior (pixel) start point
1078 * param deviceStart_x Pixel start for x-coord
1079 * param deviceStart_y Pixel start for y-coord
1081 void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1083 deviceStart_x = devStart_x;
1084 deviceStart_y = devStart_y;
1085 // For the initialization case
1086 if (GetPixelEnd()<0)
1090 SetPixelStart(deviceStart_x);
1091 SetPixelEnd(_w+deviceStart_x);
1092 SetPixelActual(deviceStart_x);
1096 SetPixelStart(deviceStart_x);
1097 SetPixelEnd(_h+deviceStart_x);
1098 SetPixelActual(deviceStart_x);
1105 * Shows the popup menu
1107 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1111 bool validClic = false;
1114 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1118 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1123 setClickedX(event.GetX());
1125 setClickedX(event.GetY());
1127 if (getClickedX()<=_h)
1129 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1130 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1131 bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1132 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1135 _selectionMoveId = 1;
1136 else if( in_EndTri )
1137 _selectionMoveId = 2;
1138 else if( in_actualT )
1139 _selectionMoveId = 3;
1140 else if( in_movingBar )
1141 _selectionMoveId = 4;
1143 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1149 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1150 * param & anEvent The wxCommandEvent actioned event
1152 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1154 bool okSelectedColor = false;
1155 wxColour selectedColour;
1157 wxColourDialog dialog( GetParent(), &data);
1159 if ( dialog.ShowModal() == wxID_OK )
1161 selectedColour = dialog.GetColourData().GetColour();
1162 okSelectedColor = true;
1164 if( okSelectedColor )
1166 if (_selectionMoveId==1 )
1167 start_Colour = selectedColour;
1168 else if (_selectionMoveId==2 )
1169 end_Colour = selectedColour;
1170 else if( _selectionMoveId==3 )
1171 actual_Colour = selectedColour;
1172 else if( _selectionMoveId==4 )
1173 bar_Colour = selectedColour;
1175 _selectionMoveId = -1;
1181 * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1182 * param & anEvent The wxCommandEvent actioned event
1184 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1186 if (!_in_rangeProperty)
1188 if(IsActualInRange())
1190 SetInRangeProperty (true);
1191 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1196 SetInRangeProperty (false);
1197 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
1202 * 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.
1203 * param & anEvent The wxCommandEvent actioned event
1205 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1207 if (_moveActualWithBar )
1209 _moveActualWithBar = false;
1210 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1214 if(IsActualInRange())
1216 _moveActualWithBar = true;
1217 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1224 * param activeNow The new state
1226 void mBarRange :: setActiveStateTo (bool activeNow)
1228 activeState = activeNow;
1232 * Gets the active state of the bar
1233 * return activeState The actual state
1235 bool mBarRange :: isActive()
1241 * Gets the real-x value to draw a vertical line
1242 * return realX_vertical_line The real x value for the vertical line
1244 int mBarRange :: getRealX_vertical_line()
1246 return realX_vertical_line;
1250 * Sets the real-x value to draw a vertical line
1251 * param newReal_x The new real x value for the vertical line
1253 void mBarRange :: setRealX_vertical_line(int newReal_x)
1255 realX_vertical_line = newReal_x;
1259 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1260 * return deviceEndMargin The value asigned to the right margin
1262 int mBarRange :: getDeviceEndX()
1264 return deviceEndMargin;
1268 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1269 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1271 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1273 deviceEndMargin = newDeviceEnd_pixels;
1277 * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1278 * return clickedX The x-coord pixel value
1280 int mBarRange :: getClickedX()
1286 * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1287 * param nwClickX The x-coord pixel value
1289 void mBarRange :: setClickedX(int nwClickX)
1291 clickedX = nwClickX;
1296 * Gets the start porcentage with respect to the represented values of the bar
1297 * return The porcentage represented by the start showing point
1299 float mBarRange :: getStartShowPorcentage()
1301 return (float)( 1+(_start - _max)/(_max-_min));
1305 * Gets the end porcentage with respect to the represented values of the bar
1306 * return The porcentage represented by the end showing point
1308 float mBarRange :: getEndShowPorcentage()
1310 return (float) (1+(_end - _max)/(_max-_min));
1314 * Gets the actual porcentage with respect to the represented values of the bar
1315 * return The porcentage represented by the actual showing point
1317 float mBarRange :: getActualShowPorcentage()
1319 return (float) (1+(_actual - _max)/(_max-_min));
1322 int mBarRange :: getLogicValueofPixel(int thePixel)
1324 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1328 * Sets the condition for knowing if the actual triangle is being drawed or not
1329 * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1331 void mBarRange :: setIfWithActualDrawed(bool drawActual)
1333 if(!withActualDrawed && drawActual)
1335 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1336 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
1338 else if (withActualDrawed && !drawActual)
1340 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1341 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1343 withActualDrawed = drawActual;
1348 * Gets the condition for knowing if the actual triangle is being drawed or not
1349 * return withActualDrawed The condition for drawing or not the actual control
1351 bool mBarRange :: getIfWithActualDrawed()
1353 return withActualDrawed;
1356 void mBarRange::createAndSendEvent(WXTYPE theEventType)
1358 wxCommandEvent cevent( theEventType, GetId() );
1359 cevent.SetEventObject( this );
1360 GetEventHandler()->ProcessEvent( cevent );
1364 * Sets the background color od the bar
1365 * theColor The color to set to the backgroundColor
1367 void mBarRange :: setBackgroundColor(wxColour theColor)
1369 backgroundColor = theColor;
1373 * Sets the guide line color
1374 * param theNwGuideLineColor The color to set to the guideLineColor
1376 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1378 guideLineColor = theNwGuideLineColor;
1382 * Gets the guide line color
1383 * return guideLineColor The color of the guideLine
1385 wxColour mBarRange :: getGuideLineColour()
1387 return guideLineColor;
1390 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
1392 acceptedClick = true;
1396 void mBarRange::onLeftClickUp(wxMouseEvent& event )
1398 acceptedClick = false;
1401 //EED 20 Juillet 2011
1402 void mBarRange::onKey(wxKeyEvent& event)
1405 if ((event.GetKeyCode()==314) || (event.GetKeyCode()==317))
1410 if ((event.GetKeyCode()==315) || (event.GetKeyCode()==316))
1417 if (_selectionMoveId == 1) // start
1419 SetStart(GetStart()+step);
1420 createAndSendEvent( wxEVT_TSBAR_START );
1423 if (_selectionMoveId == 2) // end
1425 SetEnd(GetEnd()+step);
1426 createAndSendEvent( wxEVT_TSBAR_END );
1429 if (_selectionMoveId == 3) // actual
1431 SetActual(GetActual()+step);
1432 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1435 if (_selectionMoveId == 4) // bar
1437 if (( GetStart()+step>=_min ) && ( GetEnd()+step<=_max ))
1439 SetStart(GetStart()+step);
1440 SetEnd(GetEnd()+step);
1441 if (_moveActualWithBar)
1443 SetActual(GetActual()+step);
1445 createAndSendEvent( wxEVT_TSBAR_START );
1446 createAndSendEvent( wxEVT_TSBAR_END );
1447 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1448 createAndSendEvent( wxEVT_TSBAR_MOVED );
1449 } // Start>_min && End<_max
1450 }// _selectionMoveId == 4