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"
32 //const wxEventType wxEVT_TSBAR = wxNewEventType();
34 DEFINE_EVENT_TYPE(wxEVT_TSBAR)
35 DEFINE_EVENT_TYPE(wxEVT_TSBAR_ACTUAL)
36 DEFINE_EVENT_TYPE(wxEVT_TSBAR_START)
37 DEFINE_EVENT_TYPE(wxEVT_TSBAR_END)
38 DEFINE_EVENT_TYPE(wxEVT_TSBAR_MOVED)
39 DEFINE_EVENT_TYPE(wxEVT_SELECTION_END)
41 //----------------------------------------------------------------------------
43 //----------------------------------------------------------------------------
45 IMPLEMENT_CLASS(mBarRange, wxScrolledWindow)
47 BEGIN_EVENT_TABLE(mBarRange, wxScrolledWindow)
48 EVT_PAINT (mBarRange::OnPaint)
49 EVT_SIZE (mBarRange::OnSize)
50 EVT_MOTION (mBarRange::OnMouseMove)
51 EVT_RIGHT_DOWN (mBarRange :: onShowPopupMenu)
52 EVT_MENU(cntID_CHANGE_COLOR, mBarRange :: onChangePartColor)
53 EVT_MENU(cntID_ENABLE_ACTUAL, mBarRange :: onEnableRange_Actual)
54 EVT_MENU(cntID_MOVABLE_ACTUAL_BAR, mBarRange :: onMovable_ActualWithBar)
57 EVT_LEFT_DOWN( mBarRange :: onLeftClicDown)
58 EVT_LEFT_UP( mBarRange :: onLeftClickUp)
60 EVT_CHAR( mBarRange :: onKey )
62 //how to catch the new event (our event)
63 //EVT_COMMAND (ID_MY_WINDOW, wxEVT_MY_EVENT, MyFrame::OnMyEvent)
67 //----------------------------------------------------------------------------
69 //----------------------------------------------------------------------------
71 mBarRange::mBarRange(wxWindow *parent, int w, int h)
72 :wxScrolledWindow(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
79 trianglesHalfWidth = 5;
80 // Setting the default parts colors
81 start_Colour = wxColour(1,0,255,254);
82 actual_Colour = wxColour(255,255,202);
83 end_Colour = wxColour(0,0,255);
84 bar_Colour = wxColour(255,0,255);
85 backgroundColor = parent ->GetBackgroundColour();
86 guideLineColor = wxColour(255,0,0);
87 //actual is in _start and end
88 //false means that it could be anywhere
89 _moveActualWithBar = false;
90 _in_rangeProperty = false;
91 _selectionMoveId = -1;
92 realX_vertical_line = -1;
97 setIfWithActualDrawed(true);
98 b_popmenu.Append (cntID_CHANGE_COLOR, _("Change Color"), _("Changes the color of the selected part"));
99 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
100 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
104 //----------------------------------------------------------------------------
106 //----------------------------------------------------------------------------
108 mBarRange::~mBarRange()
112 //---------------------------------------------------------------------------
113 //Draw bar: vertical or Horizontal
114 //---------------------------------------------------------------------------
115 void mBarRange::DrawBar()
120 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
121 _bitmap_bar = new wxBitmap(_w+1280,_h+100);
122 //SIL//_bitmap_info = new wxBitmap(_w+100+1280, _h+100);
127 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
128 _bitmap_bar = new wxBitmap(_h+deviceStart_y+100,_w+1280);
129 _bitmap_info = new wxBitmap(_h+deviceStart_y+100, _w+1280);
132 //----------------------------------------------------------------------------
134 //----------------------------------------------------------------------------
135 //----------------------------------------------------------------------------
136 //the property condition on actual triangle
137 //----------------------------------------------------------------------------
138 bool mBarRange::GetInRangeProperty()
140 return _in_rangeProperty;
142 //----------------------------------------------------------------------------
143 void mBarRange::SetInRangeProperty(bool in)
145 _in_rangeProperty=in;
147 //----------------------------------------------------------------------------
148 //the information about the actual triangle in range or not, true if is between start and end
149 //----------------------------------------------------------------------------
150 bool mBarRange::IsActualInRange()
152 return ( _actual <= _end && _actual >= _start );
155 //----------------------------------------------------------------------------
156 // the position of the rectangle, vertical or horizontal
157 //----------------------------------------------------------------------------
158 bool mBarRange::GetOrientation()
162 //-----------------------------------------------------------------------------
163 void mBarRange::SetOrientation(bool orientation)
169 _orientation=orientation;
172 //----------------------------------------------------------------------------
173 // _start of the pixel rectangle
174 //----------------------------------------------------------------------------
176 int mBarRange::GetPixelStart()
178 return ((_start - _min)*(_w-deviceEndMargin))/(_max - _min);
181 //----------------------------------------------------------------------------
182 // param i: value in pixels
183 //----------------------------------------------------------------------------
184 void mBarRange::SetPixelStart(int i)
186 _start = _min+((i - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
190 //----------------------------------------------------------------------------
191 // _actual of the pixel rectangle
192 //----------------------------------------------------------------------------
193 int mBarRange::GetPixelActual()
195 return ((_actual - _min)*(_w-deviceEndMargin))/(_max - _min);
198 //----------------------------------------------------------------------------
199 // param i: value in pixels
200 //----------------------------------------------------------------------------
201 void mBarRange::SetPixelActual(int i)
203 _actual = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
206 //----------------------------------------------------------------------------
207 // _end of the pixel rectangle
208 //----------------------------------------------------------------------------
209 int mBarRange::GetPixelEnd()
211 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);
222 //----------------------------------------------------------------------------
223 // Logical max of the triangle
224 //----------------------------------------------------------------------------
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();
448 int barHeight = 2*letterHeight;
449 int tempHeight = _h-(6*letterHeight);
453 barHeight = (tempHeight>0) ? tempHeight : (int) _h/2;
459 temp_dc.SelectObject( *_bitmap_bar );
461 // Background of this widget
462 temp_dc.SetPen(wxPen( backgroundColor ));
463 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
464 temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
465 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
466 temp_dc.DrawLine(trianglesHalfWidth+2, 0, _w-deviceEndMargin, 0);
467 temp_dc.DrawLine(trianglesHalfWidth+2, barHeight, (_w-deviceEndMargin-trianglesHalfWidth-2), barHeight);
468 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);
476 if( _selectionMoveId==4 )
478 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
479 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
481 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
482 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
484 temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
486 // 2 Shadow Triangles: Start and End
487 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
488 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
490 points[0].y= barHeight;
491 points[1].x= -trianglesHalfWidth-1;
493 points[2].x= trianglesHalfWidth+2;
495 temp_dc.DrawPolygon(3,points,pxStart,0);
496 temp_dc.DrawPolygon(3,points,pxEnd,0);
498 // 2 Triangles: Start and End
499 points[1].x = -trianglesHalfWidth;
500 points[2].x = trianglesHalfWidth;
502 //first triangle (start)
503 if( _selectionMoveId == 1 )
505 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
506 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
508 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
509 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
511 temp_dc.DrawPolygon(3,points,pxStart,0);
512 //second triangle (end)
513 if( _selectionMoveId == 2 )
515 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
516 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
518 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
519 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
521 temp_dc.DrawPolygon(3,points,pxEnd,0);
523 if( withActualDrawed )
525 // 1 Shadow Triangle: Actual
526 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
527 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
528 points[1].x = -trianglesHalfWidth-1;
529 points[2].x = trianglesHalfWidth+2;
531 temp_dc.DrawPolygon(3,points,pxActual,0);
533 // 1 Triangle: Actual (red)
534 if( _selectionMoveId==3 )
536 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
537 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
539 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
540 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
542 points[1].x = -trianglesHalfWidth;
543 points[2].x = trianglesHalfWidth;
544 temp_dc.DrawPolygon(3,points,pxActual,0);
547 if (realX_vertical_line!=-1)
549 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
550 int pixelX_guide = ((realX_vertical_line - _min)*(_w-deviceEndMargin))/(_max - _min) ;
551 temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, barHeight);
554 //Information Device drawing
558 //temp_dc.SelectObject( *_bitmap_info );
559 /*temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID ));
560 temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID ));*/
561 //temp_dc.DrawRectangle(deviceStart_x,_h+deviceStart_y,_w+deviceStart_x+40,_h+deviceStart_y+40);
562 //temp_dc.DrawRectangle(0,_h,_w+40-deviceEndMargin,_h+40);
564 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
565 temp_dc.SetFont(font);
566 temp_dc.SetTextForeground(*wxBLACK);
568 //the **MIN** value, always at the same y level that corresponds to barHeight+1
570 // text_min<< GetMin();
571 text_min.Printf(_T("%d"), (int)GetMin() );
573 temp_dc.DrawText(text_min,0,barHeight+1);
575 //the **MAX** value always at the same place
577 // text_max << GetMax();
578 text_max.Printf(_T("%d"), (int)GetMax() );
580 //As there is a margin of 40 extra most numbers (max) should be visibles
581 // stringSize = temp_dc.GetTextExtent(text_max);
583 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
584 wxSize stringSize(tmpX,tmpY);
586 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth())/*2*trianglesHalfWidth*/,barHeight+1);
588 //show logical values
589 //show the **START TRIANGLE** value
591 // text_start << GetStart();
592 text_start.Printf(_T("%d"), (int)GetStart() );
594 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
595 //show the **END TRIANGLE** value
597 // text_end << GetEnd();
598 text_end.Printf(_T("%d"), (int)GetEnd() );
600 // stringSize = temp_dc.GetTextExtent(text_end);
601 temp_dc.GetTextExtent(text_end,&tmpX,&tmpY);
602 stringSize.SetHeight(tmpY);
603 stringSize.SetWidth(tmpX);
604 temp_dc.DrawText(text_end, pxEnd-stringSize.GetWidth(),barHeight+3*letterHeight);
605 if( withActualDrawed )
607 //show the actual value of actual
608 wxString text_actual;
609 // text_actual << GetActual();
610 text_actual.Printf(_T("%d"), (int)GetActual() );
611 // stringSize = temp_dc.GetTextExtent(text_actual);
612 temp_dc.GetTextExtent(text_actual,&tmpX,&tmpY);
613 stringSize.SetHeight(tmpY);
614 stringSize.SetWidth(tmpX);
615 temp_dc.DrawText(text_actual, pxActual-(stringSize.GetWidth()/2),barHeight+letterHeight);
620 //----------------------------------------------------------------------------
621 //Repaint the bar if it is vertical
622 //----------------------------------------------------------------------------
624 void mBarRange::RefreshVerticalView()
628 int px1=GetPixelStart();
629 int px2=GetPixelEnd();
630 int px3=GetPixelActual();
631 int letterHeight = 9;
632 int panelHeight = 9*3+_w;
637 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
643 temp_dc.SelectObject( *_bitmap_bar );
646 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
647 temp_dc.SetPen(wxPen( backgroundColor ));
649 temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
652 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
653 temp_dc.DrawLine(0,trianglesHalfWidth+2, 0, _w-deviceEndMargin);
654 temp_dc.DrawLine(barWidth, trianglesHalfWidth+2, barWidth, (_w-deviceEndMargin-trianglesHalfWidth-2));
655 temp_dc.SetDeviceOrigin(0,trianglesHalfWidth+2);
658 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
659 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
660 temp_dc.DrawRectangle( 0,px1 ,_h, px2-px1 );
664 if( _selectionMoveId==4 )
666 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
667 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
671 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
672 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
674 temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
677 // 2 Shadow Triangles: Start and End
681 points[1].y = -trianglesHalfWidth-1;
683 points[2].y = trianglesHalfWidth+2;
684 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
685 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
686 temp_dc.DrawPolygon(3,points,0,px1);
687 temp_dc.DrawPolygon(3,points,0,px2);
689 // 2 Triangles: Start and End
693 points[1].y = -trianglesHalfWidth;
695 points[2].y = trianglesHalfWidth;
696 //first triangle (start)
697 if( _selectionMoveId==1 )
699 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
700 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
704 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
705 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
707 temp_dc.DrawPolygon(3,points,0,px1);
708 //second triangle (end)
709 if( _selectionMoveId==2 )
711 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
712 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
716 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
717 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
719 temp_dc.DrawPolygon(3,points,0,px2);
721 if( withActualDrawed )
723 // 1 Shadow Triangle: Actual
724 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
725 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
729 points[1].y=-trianglesHalfWidth-1;
731 points[2].y=trianglesHalfWidth+2;
732 temp_dc.DrawPolygon(3,points,0,px3);
734 // 1 Triangle: Actual (red)
738 points[1].y = -trianglesHalfWidth;
740 points[2].y = trianglesHalfWidth;
741 if( _selectionMoveId==3 )
743 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
744 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
748 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
749 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
751 temp_dc.DrawPolygon(3,points,0,px3);
754 if (realX_vertical_line!=-1)
756 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
757 int pixelX_guide = realX_vertical_line*_w/(_max-_min)+deviceStart_x;
758 temp_dc.DrawLine(0,pixelX_guide, _h, pixelX_guide);
761 //Information Device drawing
764 /*temp_dc.SelectObject( *_bitmap_info );
766 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
767 temp_dc.SetPen(wxPen( backgroundColor ,1,wxSOLID ));
768 temp_dc.DrawRectangle(deviceStart_y,_w+deviceStart_x,_h+deviceStart_y+200,_w+deviceStart_x+200);
771 temp_dc.SetBackgroundMode(wxTRANSPARENT);
772 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
773 temp_dc.SetFont(font);
774 temp_dc.SetTextForeground(*wxBLACK);
776 //show logical values
777 //show the actual value of start
779 // text_start<<"Start:"<< GetStart();
780 text_start.Printf(_T("%s %d"),_T("Start: "), (int)GetStart() );
781 temp_dc.DrawText( text_start ,deviceStart_y, _w+deviceStart_x+letterHeight+1);
782 //show the actual value of end
784 // text_end <<"End: "<<GetEnd();
785 text_end.Printf(_T("%s %d"),_T("End: "), (int)GetEnd() );
786 temp_dc.DrawText( text_end ,deviceStart_y,_w+deviceStart_x+letterHeight*2 );
787 if( withActualDrawed )
789 //show the actual value of actual
790 wxString text_actual;
791 // text_actual <<"Actual: " <<GetActual();
792 text_actual.Printf(_T("%s %d"),_T("Actual: "), (int)GetActual() );
793 temp_dc.DrawText( text_actual ,deviceStart_y,_w+deviceStart_x+letterHeight*3);
795 //the min value, always at the same place
797 // text_min<<"Min: " << GetMin();
798 text_min.Printf(_T("%s %d"),_T("Min: "), (int)GetMin() );
799 temp_dc.DrawText( text_min ,deviceStart_y,_w+deviceStart_x+3);
800 //the max value always at the samen place
802 // text_max <<"Max: "<< GetMax();
803 text_max.Printf(_T("%s %d"),_T("Max: "), (int)GetMax() );
804 //toca calcular cuantol lo corremos
805 temp_dc.DrawText(text_max,deviceStart_y,_w+deviceStart_x+43);
810 //----------------------------------------------------------------------------
811 void mBarRange::RefreshForce()
816 //----------------------------------------------------------------------------
817 void mBarRange::OnMouseMove(wxMouseEvent& event )
821 wxPoint point = event.GetPosition();
825 setClickedX(point.x);
830 setClickedX(point.y);
833 int logicClick = getLogicValueofPixel(clickedX);
835 if( _selectionMoveId==-1 )
839 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
840 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
841 bool in_actualT= withActualDrawed && (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
842 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
845 _selectionMoveId = 3;
847 _selectionMoveId = 1;
849 _selectionMoveId = 2;
850 else if( in_movingBar )
851 _selectionMoveId = 4;
858 //is in start triagle
859 if( _selectionMoveId ==1 && event.LeftIsDown())
861 bool validPos_StartTri = (logicClick<GetEnd() && logicClick >=_min);
862 if( validPos_StartTri && !_in_rangeProperty)
864 SetPixelStart(clickedX);
866 RefreshHorizontalView();
867 //-------------------------------------------
868 // Sending the event of start triangle moved
869 //-------------------------------------------
870 createAndSendEvent( wxEVT_TSBAR_START );
872 //start has to be less than actual
873 else if (validPos_StartTri && _in_rangeProperty)
875 if(logicClick<=GetActual())
877 SetPixelStart(clickedX);
879 // RefreshHorizontalView();
880 //-------------------------------------------
881 // Sending the event of start triangle moved
882 //-------------------------------------------
883 createAndSendEvent( wxEVT_TSBAR_START );
886 } // _selectionMoveId == 1
888 else if( _selectionMoveId == 2 && event.LeftIsDown() )
890 bool validPos_EndTri = logicClick>GetStart()&& logicClick<=_max;
891 if( validPos_EndTri && !_in_rangeProperty )
893 SetPixelEnd(clickedX);
895 // RefreshHorizontalView();
896 //-------------------------------------------
897 //Sending the event of end triangle moved
898 //-------------------------------------------
899 createAndSendEvent( wxEVT_TSBAR_END );
901 //the end triangle cant be less than actual
902 else if( validPos_EndTri && _in_rangeProperty )
904 if(logicClick>=GetActual())
906 SetPixelEnd(clickedX);
908 // RefreshHorizontalView();
909 //-------------------------------------------
910 //Sending the event of end triangle moved
911 //-------------------------------------------
912 createAndSendEvent( wxEVT_TSBAR_END );
916 //is the actual triangle
917 else if( _selectionMoveId == 3 && event.LeftIsDown())
919 bool validPos_ActualTri=(logicClick<=_max) && (logicClick>=_min);
920 //is in actual triangle but it could be anywhere
921 if( validPos_ActualTri && !_in_rangeProperty )
923 SetPixelActual(clickedX);
925 RefreshHorizontalView();
926 //-------------------------------------------
927 //Sending the event of actual triangle moved
928 //-------------------------------------------
929 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
930 // createAndSendEvent( 98765 );
932 else if( validPos_ActualTri && _in_rangeProperty )
933 // the tringle in between start and end
935 if( logicClick>=GetStart() && logicClick<=GetEnd())
937 SetPixelActual(clickedX);
939 RefreshHorizontalView();
940 //-------------------------------------------
941 //Sending the event of actual triangle moved
942 //-------------------------------------------
943 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
948 else if ( _selectionMoveId == 4 && event.LeftIsDown() )
950 //FILE * f=fopen("E:/borrar/file.txt","a+");
951 if(_initialPoint == 0)
953 _initialPoint = logicClick;
954 logicInitial_start = GetStart();
955 logicInitial_end = GetEnd();
956 logicInitial_actual = GetActual();
957 //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);
959 int difference = logicClick -_initialPoint;
960 int next_end = difference + logicInitial_end;
961 int next_start = difference + logicInitial_start;
962 int next_actual = difference + logicInitial_actual;
964 /*SIL//fprintf(f,"diff:%d, next_end%d, next_start%d, next_actual%d \n", difference,next_end,next_start,next_actual);
967 //if actual is not fixed to be in the middle
968 if( ((logicClick>next_start) && (logicClick<next_end)&& (next_end<=_max)&& (next_start>=_min)) && !_in_rangeProperty)
970 SetStart(next_start);
972 if( _moveActualWithBar )
974 SetActual (next_actual);
975 //-------------------------------------------
976 //Sending the event of actual triangle moved
977 //-------------------------------------------
978 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
981 RefreshHorizontalView();
983 //-------------------------------------------
984 // Sending the event that the bar ahs being moved
985 //-------------------------------------------
986 createAndSendEvent( wxEVT_TSBAR_MOVED );
988 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
989 createAndSendEvent( wxEVT_TSBAR_END );
990 createAndSendEvent( wxEVT_TSBAR_START );
992 //if actual has to be between start and end
993 else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
995 SetStart(next_start);
997 if( _moveActualWithBar )
999 SetActual (next_actual);
1000 //-------------------------------------------
1001 //Sending the event of actual triangle moved
1002 //-------------------------------------------
1003 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1006 RefreshHorizontalView();
1008 //-------------------------------------------
1009 // Sending the event that the bar ahs being moved
1010 //-------------------------------------------
1011 createAndSendEvent( wxEVT_TSBAR_MOVED );
1013 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1014 createAndSendEvent( wxEVT_TSBAR_END );
1015 createAndSendEvent( wxEVT_TSBAR_START );
1019 if( !event.LeftIsDown())
1022 _selectionMoveId = -1;
1024 //-------------------------------------------
1025 //Sending a general event just because
1026 //-------------------------------------------
1027 //SIL//createAndSendEvent( wxEVT_TSBAR );
1028 createAndSendEvent(wxEVT_SELECTION_END);
1036 * Sets the represented minimum and maximunm values
1037 * param minRealValue The minimum represented value (real value)
1038 * param maxRealValue The maximum represented value (real value)
1040 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
1042 _min = minRealValue;
1043 _max = maxRealValue;
1049 * Sets the property for viewing or not the bar labels information
1051 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
1053 _visibleLables = setVisibleLB;
1057 * Sets the property for viewing or not the bar labels information
1058 * return _visibleLables The state of visible labels or not
1060 bool mBarRange ::getIfVisibleLabels ()
1062 return _visibleLables;
1066 * Sets the device start drawing left-superior (pixel) start point
1067 * param deviceStart_x Pixel start for x-coord
1068 * param deviceStart_y Pixel start for y-coord
1070 void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1072 deviceStart_x = devStart_x;
1073 deviceStart_y = devStart_y;
1074 // For the initialization case
1075 if (GetPixelEnd()<0)
1079 SetPixelStart(deviceStart_x);
1080 SetPixelEnd(_w+deviceStart_x);
1081 SetPixelActual(deviceStart_x);
1085 SetPixelStart(deviceStart_x);
1086 SetPixelEnd(_h+deviceStart_x);
1087 SetPixelActual(deviceStart_x);
1094 * Shows the popup menu
1096 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1100 bool validClic = false;
1103 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1107 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1112 setClickedX(event.GetX());
1114 setClickedX(event.GetY());
1116 if (getClickedX()<=_h)
1118 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1119 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1120 bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1121 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1124 _selectionMoveId = 1;
1125 else if( in_EndTri )
1126 _selectionMoveId = 2;
1127 else if( in_actualT )
1128 _selectionMoveId = 3;
1129 else if( in_movingBar )
1130 _selectionMoveId = 4;
1132 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1138 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1139 * param & anEvent The wxCommandEvent actioned event
1141 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1143 bool okSelectedColor = false;
1144 wxColour selectedColour;
1146 wxColourDialog dialog( GetParent(), &data);
1148 if ( dialog.ShowModal() == wxID_OK )
1150 selectedColour = dialog.GetColourData().GetColour();
1151 okSelectedColor = true;
1153 if( okSelectedColor )
1155 if (_selectionMoveId==1 )
1156 start_Colour = selectedColour;
1157 else if (_selectionMoveId==2 )
1158 end_Colour = selectedColour;
1159 else if( _selectionMoveId==3 )
1160 actual_Colour = selectedColour;
1161 else if( _selectionMoveId==4 )
1162 bar_Colour = selectedColour;
1164 _selectionMoveId = -1;
1170 * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1171 * param & anEvent The wxCommandEvent actioned event
1173 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1175 if (!_in_rangeProperty)
1177 if(IsActualInRange())
1179 SetInRangeProperty (true);
1180 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1185 SetInRangeProperty (false);
1186 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
1191 * 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.
1192 * param & anEvent The wxCommandEvent actioned event
1194 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1196 if (_moveActualWithBar )
1198 _moveActualWithBar = false;
1199 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1203 if(IsActualInRange())
1205 _moveActualWithBar = true;
1206 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1213 * param activeNow The new state
1215 void mBarRange :: setActiveStateTo (bool activeNow)
1217 activeState = activeNow;
1221 * Gets the active state of the bar
1222 * return activeState The actual state
1224 bool mBarRange :: isActive()
1230 * Gets the real-x value to draw a vertical line
1231 * return realX_vertical_line The real x value for the vertical line
1233 int mBarRange :: getRealX_vertical_line()
1235 return realX_vertical_line;
1239 * Sets the real-x value to draw a vertical line
1240 * param newReal_x The new real x value for the vertical line
1242 void mBarRange :: setRealX_vertical_line(int newReal_x)
1244 realX_vertical_line = newReal_x;
1248 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1249 * return deviceEndMargin The value asigned to the right margin
1251 int mBarRange :: getDeviceEndX()
1253 return deviceEndMargin;
1257 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1258 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1260 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1262 deviceEndMargin = newDeviceEnd_pixels;
1266 * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1267 * return clickedX The x-coord pixel value
1269 int mBarRange :: getClickedX()
1275 * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1276 * param nwClickX The x-coord pixel value
1278 void mBarRange :: setClickedX(int nwClickX)
1280 clickedX = nwClickX;
1285 * Gets the start porcentage with respect to the represented values of the bar
1286 * return The porcentage represented by the start showing point
1288 float mBarRange :: getStartShowPorcentage()
1290 return (float)( 1+(_start - _max)/(_max-_min));
1294 * Gets the end porcentage with respect to the represented values of the bar
1295 * return The porcentage represented by the end showing point
1297 float mBarRange :: getEndShowPorcentage()
1299 return (float) (1+(_end - _max)/(_max-_min));
1303 * Gets the actual porcentage with respect to the represented values of the bar
1304 * return The porcentage represented by the actual showing point
1306 float mBarRange :: getActualShowPorcentage()
1308 return (float) (1+(_actual - _max)/(_max-_min));
1311 int mBarRange :: getLogicValueofPixel(int thePixel)
1313 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1317 * Sets the condition for knowing if the actual triangle is being drawed or not
1318 * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1320 void mBarRange :: setIfWithActualDrawed(bool drawActual)
1322 if(!withActualDrawed && drawActual)
1324 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1325 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
1327 else if (withActualDrawed && !drawActual)
1329 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1330 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1332 withActualDrawed = drawActual;
1337 * Gets the condition for knowing if the actual triangle is being drawed or not
1338 * return withActualDrawed The condition for drawing or not the actual control
1340 bool mBarRange :: getIfWithActualDrawed()
1342 return withActualDrawed;
1345 void mBarRange::createAndSendEvent(WXTYPE theEventType)
1347 wxCommandEvent cevent( theEventType, GetId() );
1348 cevent.SetEventObject( this );
1349 GetEventHandler()->ProcessEvent( cevent );
1353 * Sets the background color od the bar
1354 * theColor The color to set to the backgroundColor
1356 void mBarRange :: setBackgroundColor(wxColour theColor)
1358 backgroundColor = theColor;
1362 * Sets the guide line color
1363 * param theNwGuideLineColor The color to set to the guideLineColor
1365 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1367 guideLineColor = theNwGuideLineColor;
1371 * Gets the guide line color
1372 * return guideLineColor The color of the guideLine
1374 wxColour mBarRange :: getGuideLineColour()
1376 return guideLineColor;
1379 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
1381 acceptedClick = true;
1385 void mBarRange::onLeftClickUp(wxMouseEvent& event )
1387 acceptedClick = false;
1390 //EED 20 Juillet 2011
1391 void mBarRange::onKey(wxKeyEvent& event)
1394 if ((event.GetKeyCode()==314) || (event.GetKeyCode()==317))
1399 if ((event.GetKeyCode()==315) || (event.GetKeyCode()==316))
1406 if (_selectionMoveId == 1) // start
1408 SetStart(GetStart()+step);
1409 createAndSendEvent( wxEVT_TSBAR_START );
1412 if (_selectionMoveId == 2) // end
1414 SetEnd(GetEnd()+step);
1415 createAndSendEvent( wxEVT_TSBAR_END );
1418 if (_selectionMoveId == 3) // actual
1420 SetActual(GetActual()+step);
1421 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1424 if (_selectionMoveId == 4) // bar
1426 if (( GetStart()+step>=_min ) && ( GetEnd()+step<=_max ))
1428 SetStart(GetStart()+step);
1429 SetEnd(GetEnd()+step);
1430 if (_moveActualWithBar)
1432 SetActual(GetActual()+step);
1434 createAndSendEvent( wxEVT_TSBAR_START );
1435 createAndSendEvent( wxEVT_TSBAR_END );
1436 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1437 createAndSendEvent( wxEVT_TSBAR_MOVED );
1438 } // Start>_min && End<_max
1439 }// _selectionMoveId == 4