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 //----------------------------------------------------------------------------
72 mBarRange::mBarRange(wxWindow *parent, int w, int h)
73 :wxScrolledWindow(parent,-1,wxDefaultPosition, wxSize(60,60) ,wxTAB_TRAVERSAL)
80 trianglesHalfWidth = 5;
81 // Setting the default parts colors
82 start_Colour = wxColour(1,0,255,254);
83 actual_Colour = wxColour(255,255,202);
84 end_Colour = wxColour(0,0,255);
85 bar_Colour = wxColour(255,0,255);
86 backgroundColor = parent ->GetBackgroundColour();
87 guideLineColor = wxColour(255,0,0);
88 //actual is in _start and end
89 //false means that it could be anywhere
90 _moveActualWithBar = false;
91 _in_rangeProperty = false;
92 _selectionMoveId = -1;
93 realX_vertical_line = -1;
98 setIfWithActualDrawed(true);
99 b_popmenu.Append (cntID_CHANGE_COLOR, _("Change Color"), _("Changes the color of the selected part"));
100 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
101 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
105 //----------------------------------------------------------------------------
107 //----------------------------------------------------------------------------
109 mBarRange::~mBarRange()
113 //---------------------------------------------------------------------------
114 //Draw bar: vertical or Horizontal
115 //---------------------------------------------------------------------------
116 void mBarRange::DrawBar()
121 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
122 _bitmap_bar = new wxBitmap(_w+1280,_h+100);
123 //SIL//_bitmap_info = new wxBitmap(_w+100+1280, _h+100);
128 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
129 _bitmap_bar = new wxBitmap(_h+deviceStart_y+100,_w+1280);
130 _bitmap_info = new wxBitmap(_h+deviceStart_y+100, _w+1280);
133 //----------------------------------------------------------------------------
135 //----------------------------------------------------------------------------
136 //----------------------------------------------------------------------------
137 //the property condition on actual triangle
138 //----------------------------------------------------------------------------
139 bool mBarRange::GetInRangeProperty()
141 return _in_rangeProperty;
143 //----------------------------------------------------------------------------
144 void mBarRange::SetInRangeProperty(bool in)
146 _in_rangeProperty=in;
148 //----------------------------------------------------------------------------
149 //the information about the actual triangle in range or not, true if is between start and end
150 //----------------------------------------------------------------------------
151 bool mBarRange::IsActualInRange()
153 return ( _actual <= _end && _actual >= _start );
156 //----------------------------------------------------------------------------
157 // the position of the rectangle, vertical or horizontal
158 //----------------------------------------------------------------------------
159 bool mBarRange::GetOrientation()
163 //-----------------------------------------------------------------------------
164 void mBarRange::SetOrientation(bool orientation)
170 _orientation=orientation;
173 //----------------------------------------------------------------------------
174 // _start of the pixel rectangle
175 //----------------------------------------------------------------------------
177 int mBarRange::GetPixelStart()
179 return ((_start - _min)*(_w-deviceEndMargin))/(_max - _min);
182 //----------------------------------------------------------------------------
183 // param i: value in pixels
184 //----------------------------------------------------------------------------
185 void mBarRange::SetPixelStart(int i)
187 _start = _min+((i - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
191 //----------------------------------------------------------------------------
192 // _actual of the pixel rectangle
193 //----------------------------------------------------------------------------
194 int mBarRange::GetPixelActual()
196 return ((_actual - _min)*(_w-deviceEndMargin))/(_max - _min);
199 //----------------------------------------------------------------------------
200 // param i: value in pixels
201 //----------------------------------------------------------------------------
202 void mBarRange::SetPixelActual(int i)
204 _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);
215 //----------------------------------------------------------------------------
216 // param i: value in pixels to be converted to real logical value
217 //----------------------------------------------------------------------------
218 void mBarRange::SetPixelEnd(int i)
220 _end = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
223 //----------------------------------------------------------------------------
224 // Logical max of the triangle
225 //----------------------------------------------------------------------------
226 double mBarRange::GetMax()
231 //----------------------------------------------------------------------------
232 void mBarRange::SetMax(double i)
236 //----------------------------------------------------------------------------
237 // Logical min of the triangle
238 //----------------------------------------------------------------------------
240 double mBarRange::GetMin()
245 //----------------------------------------------------------------------------
246 void mBarRange::SetMin(double i)
251 //----------------------------------------------------------------------------
252 // pixel dimensions of the rectangle
253 //----------------------------------------------------------------------------
255 int mBarRange::GetWidth()
259 //----------------------------------------------------------------------------
260 void mBarRange::SetWidth(int w)
264 //----------------------------------------------------------------------------
265 int mBarRange::GetHeight()
270 //----------------------------------------------------------------------------
271 void mBarRange::SetHeight(int h)
276 //----------------------------------------------------------------------------
277 // Logical Start of the rectangle
278 //----------------------------------------------------------------------------
280 int mBarRange::filtreValue(int value)
285 } else if (value>_max) {
291 //----------------------------------------------------------------------------
292 int mBarRange::GetStart()
296 //----------------------------------------------------------------------------
297 // param start: value real units
298 //----------------------------------------------------------------------------
299 void mBarRange::SetStart(int newstart)
301 _start = filtreValue(newstart);
308 if (_in_rangeProperty==true)
310 if (_start>_actual) { _start=_actual; }
315 //----------------------------------------------------------------------------
316 // Logical End of the rectangle
317 //----------------------------------------------------------------------------
319 int mBarRange::GetEnd()
323 //----------------------------------------------------------------------------
324 // param end: value pixel units
325 //----------------------------------------------------------------------------
326 void mBarRange::SetEnd(int newend)
328 _end = filtreValue(newend);
329 if (_end<_start) { _end=_start; }
330 if (_in_rangeProperty==true)
339 //----------------------------------------------------------------------------
340 // logical Actual of the rectangle
341 //----------------------------------------------------------------------------
342 int mBarRange::GetActual()
346 //----------------------------------------------------------------------------
347 void mBarRange::SetActual(int newactual)
349 _actual = filtreValue(newactual);
350 if (_in_rangeProperty==true)
352 if (_actual<_start) { _actual=_start; }
353 if (_actual>_end) { _actual=_end; }
358 //----------------------------------------------------------------------------
360 //----------------------------------------------------------------------------
361 int mBarRange::GetTrianglesHalfWidth()
363 return trianglesHalfWidth;
366 //----------------------------------------------------------------------------
367 void mBarRange::SetTrianglesHalfWidth(int nwTriHalfWidth)
369 trianglesHalfWidth = nwTriHalfWidth;
372 void mBarRange::OnSize( wxSizeEvent &WXUNUSED(event) )
374 wxRect rectTotal = GetClientRect();
377 SetWidth( rectTotal.GetWidth() - deviceEndMargin );
379 SetWidth( rectTotal.GetHeight() - deviceEndMargin);
381 _selectionMoveId = -1;
385 //----------------------------------------------------------------------------
387 void mBarRange::Refresh(bool eraseBackground, const wxRect* rect)
389 wxScrolledWindow::Refresh(false);
393 //----------------------------------------------------------------------------
395 //----------------------------------------------------------------------------
396 void mBarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
398 if (_bitmap_bar!=NULL)
403 RefreshHorizontalView();
405 temp_dc.SelectObject( *_bitmap_bar );
406 wxPaintDC dc( this );
407 dc.Blit(deviceStart_x-(trianglesHalfWidth+2), deviceStart_y, _w-deviceEndMargin+2*(trianglesHalfWidth+2), _h, &temp_dc, 0, 0);
409 // if (_visibleLables)
411 // temp_dc.SelectObject( *_bitmap_info );
412 // dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+200, &temp_dc, deviceStart_x, deviceStart_y);
413 // //dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+60, &temp_dc, 0, 0);
417 RefreshVerticalView();
419 temp_dc.SelectObject( *_bitmap_bar );
420 wxPaintDC dc( this );
421 // dc.Blit(deviceStart_y,deviceStart_x, _h+deviceStart_y-deviceEndMargin,_w+deviceStart_x-deviceEndMargin, &temp_dc, 0, 0);
422 dc.Blit(deviceStart_y,deviceStart_x-(trianglesHalfWidth+2), _h,_w-deviceEndMargin+2*(trianglesHalfWidth+2), &temp_dc, 0, 0);
425 // if (_visibleLables)
427 // temp_dc.SelectObject( *_bitmap_info );
428 // dc.Blit(0,_w, _h+deviceStart_y+200, _w+deviceStart_x+200-deviceEndMargin, &temp_dc, deviceStart_y,_w+deviceStart_x);
436 //----------------------------------------------------------------------------
437 //Repaint the bar if it is horizontal
438 //----------------------------------------------------------------------------
439 void mBarRange::RefreshHorizontalView()
443 //int largestNumberWidthInPixels = 15; // JPRx
444 int pxStart = GetPixelStart();
445 int pxEnd = GetPixelEnd();
446 int pxActual = GetPixelActual();
449 int barHeight = 2*letterHeight;
450 int tempHeight = _h-(6*letterHeight);
454 barHeight = (tempHeight>0) ? tempHeight : (int) _h/2;
460 temp_dc.SelectObject( *_bitmap_bar );
462 // Background of this widget
463 temp_dc.SetPen(wxPen( backgroundColor ));
464 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
465 temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
466 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
467 temp_dc.DrawLine(trianglesHalfWidth+2, 0, _w-deviceEndMargin, 0);
468 temp_dc.DrawLine(trianglesHalfWidth+2, barHeight, (_w-deviceEndMargin-trianglesHalfWidth-2), barHeight);
469 temp_dc.SetDeviceOrigin(trianglesHalfWidth+2,0);
472 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
473 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
474 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 ));
482 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
483 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
485 temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
487 // 2 Shadow Triangles: Start and End
488 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
489 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
491 points[0].y= barHeight;
492 points[1].x= -trianglesHalfWidth-1;
494 points[2].x= trianglesHalfWidth+2;
496 temp_dc.DrawPolygon(3,points,pxStart,0);
497 temp_dc.DrawPolygon(3,points,pxEnd,0);
499 // 2 Triangles: Start and End
500 points[1].x = -trianglesHalfWidth;
501 points[2].x = trianglesHalfWidth;
503 //first triangle (start)
504 if( _selectionMoveId == 1 )
506 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
507 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
509 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
510 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
512 temp_dc.DrawPolygon(3,points,pxStart,0);
513 //second triangle (end)
514 if( _selectionMoveId == 2 )
516 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
517 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
519 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
520 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
522 temp_dc.DrawPolygon(3,points,pxEnd,0);
524 if( withActualDrawed )
526 // 1 Shadow Triangle: Actual
527 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
528 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
529 points[1].x = -trianglesHalfWidth-1;
530 points[2].x = trianglesHalfWidth+2;
532 temp_dc.DrawPolygon(3,points,pxActual,0);
534 // 1 Triangle: Actual (red)
535 if( _selectionMoveId==3 )
537 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
538 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
540 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
541 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
543 points[1].x = -trianglesHalfWidth;
544 points[2].x = trianglesHalfWidth;
545 temp_dc.DrawPolygon(3,points,pxActual,0);
548 if (realX_vertical_line!=-1)
550 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
551 int pixelX_guide = ((realX_vertical_line - _min)*(_w-deviceEndMargin))/(_max - _min) ;
552 temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, barHeight);
555 //Information Device drawing
559 //temp_dc.SelectObject( *_bitmap_info );
560 /*temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID ));
561 temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID ));*/
562 //temp_dc.DrawRectangle(deviceStart_x,_h+deviceStart_y,_w+deviceStart_x+40,_h+deviceStart_y+40);
563 //temp_dc.DrawRectangle(0,_h,_w+40-deviceEndMargin,_h+40);
565 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
566 temp_dc.SetFont(font);
567 temp_dc.SetTextForeground(*wxBLACK);
569 //the **MIN** value, always at the same y level that corresponds to barHeight+1
571 // text_min<< GetMin();
572 text_min.Printf(_T("%d"), (int)GetMin() );
574 temp_dc.DrawText(text_min,0,barHeight+1);
576 //the **MAX** value always at the same place
578 // text_max << GetMax();
579 text_max.Printf(_T("%d"), (int)GetMax() );
581 //As there is a margin of 40 extra most numbers (max) should be visibles
582 // stringSize = temp_dc.GetTextExtent(text_max);
584 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
585 wxSize stringSize(tmpX,tmpY);
587 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth())/*2*trianglesHalfWidth*/,barHeight+1);
589 //show logical values
590 //show the **START TRIANGLE** value
592 // text_start << GetStart();
593 text_start.Printf(_T("%d"), (int)GetStart() );
595 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
596 //show the **END TRIANGLE** value
598 // text_end << GetEnd();
599 text_end.Printf(_T("%d"), (int)GetEnd() );
601 // stringSize = temp_dc.GetTextExtent(text_end);
602 temp_dc.GetTextExtent(text_end,&tmpX,&tmpY);
603 stringSize.SetHeight(tmpY);
604 stringSize.SetWidth(tmpX);
605 temp_dc.DrawText(text_end, pxEnd-stringSize.GetWidth(),barHeight+3*letterHeight);
606 if( withActualDrawed )
608 //show the actual value of actual
609 wxString text_actual;
610 // text_actual << GetActual();
611 text_actual.Printf(_T("%d"), (int)GetActual() );
612 // stringSize = temp_dc.GetTextExtent(text_actual);
613 temp_dc.GetTextExtent(text_actual,&tmpX,&tmpY);
614 stringSize.SetHeight(tmpY);
615 stringSize.SetWidth(tmpX);
616 temp_dc.DrawText(text_actual, pxActual-(stringSize.GetWidth()/2),barHeight+letterHeight);
621 //----------------------------------------------------------------------------
622 //Repaint the bar if it is vertical
623 //----------------------------------------------------------------------------
625 void mBarRange::RefreshVerticalView()
629 int px1=GetPixelStart();
630 int px2=GetPixelEnd();
631 int px3=GetPixelActual();
632 int letterHeight = 9;
633 int panelHeight = 9*3+_w;
638 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
644 temp_dc.SelectObject( *_bitmap_bar );
647 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
648 temp_dc.SetPen(wxPen( backgroundColor ));
650 temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
653 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
654 temp_dc.DrawLine(0,trianglesHalfWidth+2, 0, _w-deviceEndMargin);
655 temp_dc.DrawLine(barWidth, trianglesHalfWidth+2, barWidth, (_w-deviceEndMargin-trianglesHalfWidth-2));
656 temp_dc.SetDeviceOrigin(0,trianglesHalfWidth+2);
659 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
660 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
661 temp_dc.DrawRectangle( 0,px1 ,_h, px2-px1 );
665 if( _selectionMoveId==4 )
667 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
668 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
672 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
673 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
675 temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
678 // 2 Shadow Triangles: Start and End
682 points[1].y = -trianglesHalfWidth-1;
684 points[2].y = trianglesHalfWidth+2;
685 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
686 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
687 temp_dc.DrawPolygon(3,points,0,px1);
688 temp_dc.DrawPolygon(3,points,0,px2);
690 // 2 Triangles: Start and End
694 points[1].y = -trianglesHalfWidth;
696 points[2].y = trianglesHalfWidth;
697 //first triangle (start)
698 if( _selectionMoveId==1 )
700 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
701 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
705 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
706 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
708 temp_dc.DrawPolygon(3,points,0,px1);
709 //second triangle (end)
710 if( _selectionMoveId==2 )
712 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
713 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
717 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
718 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
720 temp_dc.DrawPolygon(3,points,0,px2);
722 if( withActualDrawed )
724 // 1 Shadow Triangle: Actual
725 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
726 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
730 points[1].y=-trianglesHalfWidth-1;
732 points[2].y=trianglesHalfWidth+2;
733 temp_dc.DrawPolygon(3,points,0,px3);
735 // 1 Triangle: Actual (red)
739 points[1].y = -trianglesHalfWidth;
741 points[2].y = trianglesHalfWidth;
742 if( _selectionMoveId==3 )
744 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
745 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
749 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
750 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
752 temp_dc.DrawPolygon(3,points,0,px3);
755 if (realX_vertical_line!=-1)
757 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
758 int pixelX_guide = realX_vertical_line*_w/(_max-_min)+deviceStart_x;
759 temp_dc.DrawLine(0,pixelX_guide, _h, pixelX_guide);
762 //Information Device drawing
765 /*temp_dc.SelectObject( *_bitmap_info );
767 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
768 temp_dc.SetPen(wxPen( backgroundColor ,1,wxSOLID ));
769 temp_dc.DrawRectangle(deviceStart_y,_w+deviceStart_x,_h+deviceStart_y+200,_w+deviceStart_x+200);
772 temp_dc.SetBackgroundMode(wxTRANSPARENT);
773 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
774 temp_dc.SetFont(font);
775 temp_dc.SetTextForeground(*wxBLACK);
777 //show logical values
778 //show the actual value of start
780 // text_start<<"Start:"<< GetStart();
781 text_start.Printf(_T("%s %d"),_T("Start: "), (int)GetStart() );
782 temp_dc.DrawText( text_start ,deviceStart_y, _w+deviceStart_x+letterHeight+1);
783 //show the actual value of end
785 // text_end <<"End: "<<GetEnd();
786 text_end.Printf(_T("%s %d"),_T("End: "), (int)GetEnd() );
787 temp_dc.DrawText( text_end ,deviceStart_y,_w+deviceStart_x+letterHeight*2 );
788 if( withActualDrawed )
790 //show the actual value of actual
791 wxString text_actual;
792 // text_actual <<"Actual: " <<GetActual();
793 text_actual.Printf(_T("%s %d"),_T("Actual: "), (int)GetActual() );
794 temp_dc.DrawText( text_actual ,deviceStart_y,_w+deviceStart_x+letterHeight*3);
796 //the min value, always at the same place
798 // text_min<<"Min: " << GetMin();
799 text_min.Printf(_T("%s %d"),_T("Min: "), (int)GetMin() );
800 temp_dc.DrawText( text_min ,deviceStart_y,_w+deviceStart_x+3);
801 //the max value always at the samen place
803 // text_max <<"Max: "<< GetMax();
804 text_max.Printf(_T("%s %d"),_T("Max: "), (int)GetMax() );
805 //toca calcular cuantol lo corremos
806 temp_dc.DrawText(text_max,deviceStart_y,_w+deviceStart_x+43);
811 //----------------------------------------------------------------------------
812 void mBarRange::RefreshForce()
817 //----------------------------------------------------------------------------
818 void mBarRange::OnMouseMove(wxMouseEvent& event )
822 wxPoint point = event.GetPosition();
826 setClickedX(point.x);
831 setClickedX(point.y);
834 int logicClick = getLogicValueofPixel(clickedX);
836 if( _selectionMoveId==-1 )
840 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
841 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
842 bool in_actualT= withActualDrawed && (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
843 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
846 _selectionMoveId = 3;
848 _selectionMoveId = 1;
850 _selectionMoveId = 2;
851 else if( in_movingBar )
852 _selectionMoveId = 4;
859 //is in start triagle
860 if( _selectionMoveId ==1 && event.LeftIsDown())
862 bool validPos_StartTri = (logicClick<GetEnd() && logicClick >=_min);
863 if( validPos_StartTri && !_in_rangeProperty)
865 SetPixelStart(clickedX);
867 RefreshHorizontalView();
868 //-------------------------------------------
869 // Sending the event of start triangle moved
870 //-------------------------------------------
871 createAndSendEvent( wxEVT_TSBAR_START );
873 //start has to be less than actual
874 else if (validPos_StartTri && _in_rangeProperty)
876 if(logicClick<=GetActual())
878 SetPixelStart(clickedX);
880 // RefreshHorizontalView();
881 //-------------------------------------------
882 // Sending the event of start triangle moved
883 //-------------------------------------------
884 createAndSendEvent( wxEVT_TSBAR_START );
887 } // _selectionMoveId == 1
889 else if( _selectionMoveId == 2 && event.LeftIsDown() )
891 bool validPos_EndTri = logicClick>GetStart()&& logicClick<=_max;
892 if( validPos_EndTri && !_in_rangeProperty )
894 SetPixelEnd(clickedX);
896 // RefreshHorizontalView();
897 //-------------------------------------------
898 //Sending the event of end triangle moved
899 //-------------------------------------------
900 createAndSendEvent( wxEVT_TSBAR_END );
902 //the end triangle cant be less than actual
903 else if( validPos_EndTri && _in_rangeProperty )
905 if(logicClick>=GetActual())
907 SetPixelEnd(clickedX);
909 // RefreshHorizontalView();
910 //-------------------------------------------
911 //Sending the event of end triangle moved
912 //-------------------------------------------
913 createAndSendEvent( wxEVT_TSBAR_END );
917 //is the actual triangle
918 else if( _selectionMoveId == 3 && event.LeftIsDown())
920 bool validPos_ActualTri=(logicClick<=_max) && (logicClick>=_min);
921 //is in actual triangle but it could be anywhere
922 if( validPos_ActualTri && !_in_rangeProperty )
924 SetPixelActual(clickedX);
926 RefreshHorizontalView();
927 //-------------------------------------------
928 //Sending the event of actual triangle moved
929 //-------------------------------------------
930 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
931 // createAndSendEvent( 98765 );
933 else if( validPos_ActualTri && _in_rangeProperty )
934 // the tringle in between start and end
936 if( logicClick>=GetStart() && logicClick<=GetEnd())
938 SetPixelActual(clickedX);
940 RefreshHorizontalView();
941 //-------------------------------------------
942 //Sending the event of actual triangle moved
943 //-------------------------------------------
944 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
949 else if ( _selectionMoveId == 4 && event.LeftIsDown() )
951 //FILE * f=fopen("E:/borrar/file.txt","a+");
952 if(_initialPoint == 0)
954 _initialPoint = logicClick;
955 logicInitial_start = GetStart();
956 logicInitial_end = GetEnd();
957 logicInitial_actual = GetActual();
958 //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);
960 int difference = logicClick -_initialPoint;
961 int next_end = difference + logicInitial_end;
962 int next_start = difference + logicInitial_start;
963 int next_actual = difference + logicInitial_actual;
965 /*SIL//fprintf(f,"diff:%d, next_end%d, next_start%d, next_actual%d \n", difference,next_end,next_start,next_actual);
968 //if actual is not fixed to be in the middle
969 if( ((logicClick>next_start) && (logicClick<next_end)&& (next_end<=_max)&& (next_start>=_min)) && !_in_rangeProperty)
971 SetStart(next_start);
973 if( _moveActualWithBar )
975 SetActual (next_actual);
976 //-------------------------------------------
977 //Sending the event of actual triangle moved
978 //-------------------------------------------
979 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
982 RefreshHorizontalView();
984 //-------------------------------------------
985 // Sending the event that the bar ahs being moved
986 //-------------------------------------------
987 createAndSendEvent( wxEVT_TSBAR_MOVED );
989 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
990 createAndSendEvent( wxEVT_TSBAR_END );
991 createAndSendEvent( wxEVT_TSBAR_START );
993 //if actual has to be between start and end
994 else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
996 SetStart(next_start);
998 if( _moveActualWithBar )
1000 SetActual (next_actual);
1001 //-------------------------------------------
1002 //Sending the event of actual triangle moved
1003 //-------------------------------------------
1004 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1007 RefreshHorizontalView();
1009 //-------------------------------------------
1010 // Sending the event that the bar ahs being moved
1011 //-------------------------------------------
1012 createAndSendEvent( wxEVT_TSBAR_MOVED );
1014 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1015 createAndSendEvent( wxEVT_TSBAR_END );
1016 createAndSendEvent( wxEVT_TSBAR_START );
1020 if( !event.LeftIsDown())
1023 _selectionMoveId = -1;
1025 //-------------------------------------------
1026 //Sending a general event just because
1027 //-------------------------------------------
1028 //SIL//createAndSendEvent( wxEVT_TSBAR );
1029 createAndSendEvent(wxEVT_SELECTION_END);
1037 * Sets the represented minimum and maximunm values
1038 * param minRealValue The minimum represented value (real value)
1039 * param maxRealValue The maximum represented value (real value)
1041 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
1043 _min = minRealValue;
1044 _max = maxRealValue;
1050 * Sets the property for viewing or not the bar labels information
1052 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
1054 _visibleLables = setVisibleLB;
1058 * Sets the property for viewing or not the bar labels information
1059 * return _visibleLables The state of visible labels or not
1061 bool mBarRange ::getIfVisibleLabels ()
1063 return _visibleLables;
1067 * Sets the device start drawing left-superior (pixel) start point
1068 * param deviceStart_x Pixel start for x-coord
1069 * param deviceStart_y Pixel start for y-coord
1071 void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1073 deviceStart_x = devStart_x;
1074 deviceStart_y = devStart_y;
1075 // For the initialization case
1076 if (GetPixelEnd()<0)
1080 SetPixelStart(deviceStart_x);
1081 SetPixelEnd(_w+deviceStart_x);
1082 SetPixelActual(deviceStart_x);
1086 SetPixelStart(deviceStart_x);
1087 SetPixelEnd(_h+deviceStart_x);
1088 SetPixelActual(deviceStart_x);
1095 * Shows the popup menu
1097 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1101 bool validClic = false;
1104 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1108 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1113 setClickedX(event.GetX());
1115 setClickedX(event.GetY());
1117 if (getClickedX()<=_h)
1119 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1120 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1121 bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1122 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1125 _selectionMoveId = 1;
1126 else if( in_EndTri )
1127 _selectionMoveId = 2;
1128 else if( in_actualT )
1129 _selectionMoveId = 3;
1130 else if( in_movingBar )
1131 _selectionMoveId = 4;
1133 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1139 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1140 * param & anEvent The wxCommandEvent actioned event
1142 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1144 bool okSelectedColor = false;
1145 wxColour selectedColour;
1147 wxColourDialog dialog( GetParent(), &data);
1149 if ( dialog.ShowModal() == wxID_OK )
1151 selectedColour = dialog.GetColourData().GetColour();
1152 okSelectedColor = true;
1154 if( okSelectedColor )
1156 if (_selectionMoveId==1 )
1157 start_Colour = selectedColour;
1158 else if (_selectionMoveId==2 )
1159 end_Colour = selectedColour;
1160 else if( _selectionMoveId==3 )
1161 actual_Colour = selectedColour;
1162 else if( _selectionMoveId==4 )
1163 bar_Colour = selectedColour;
1165 _selectionMoveId = -1;
1171 * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1172 * param & anEvent The wxCommandEvent actioned event
1174 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1176 if (!_in_rangeProperty)
1178 if(IsActualInRange())
1180 SetInRangeProperty (true);
1181 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1186 SetInRangeProperty (false);
1187 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
1192 * 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.
1193 * param & anEvent The wxCommandEvent actioned event
1195 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1197 if (_moveActualWithBar )
1199 _moveActualWithBar = false;
1200 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1204 if(IsActualInRange())
1206 _moveActualWithBar = true;
1207 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1214 * param activeNow The new state
1216 void mBarRange :: setActiveStateTo (bool activeNow)
1218 activeState = activeNow;
1222 * Gets the active state of the bar
1223 * return activeState The actual state
1225 bool mBarRange :: isActive()
1231 * Gets the real-x value to draw a vertical line
1232 * return realX_vertical_line The real x value for the vertical line
1234 int mBarRange :: getRealX_vertical_line()
1236 return realX_vertical_line;
1240 * Sets the real-x value to draw a vertical line
1241 * param newReal_x The new real x value for the vertical line
1243 void mBarRange :: setRealX_vertical_line(int newReal_x)
1245 realX_vertical_line = newReal_x;
1249 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1250 * return deviceEndMargin The value asigned to the right margin
1252 int mBarRange :: getDeviceEndX()
1254 return deviceEndMargin;
1258 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1259 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1261 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1263 deviceEndMargin = newDeviceEnd_pixels;
1267 * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1268 * return clickedX The x-coord pixel value
1270 int mBarRange :: getClickedX()
1276 * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1277 * param nwClickX The x-coord pixel value
1279 void mBarRange :: setClickedX(int nwClickX)
1281 clickedX = nwClickX;
1286 * Gets the start porcentage with respect to the represented values of the bar
1287 * return The porcentage represented by the start showing point
1289 float mBarRange :: getStartShowPorcentage()
1291 return (float)( 1+(_start - _max)/(_max-_min));
1295 * Gets the end porcentage with respect to the represented values of the bar
1296 * return The porcentage represented by the end showing point
1298 float mBarRange :: getEndShowPorcentage()
1300 return (float) (1+(_end - _max)/(_max-_min));
1304 * Gets the actual porcentage with respect to the represented values of the bar
1305 * return The porcentage represented by the actual showing point
1307 float mBarRange :: getActualShowPorcentage()
1309 return (float) (1+(_actual - _max)/(_max-_min));
1312 int mBarRange :: getLogicValueofPixel(int thePixel)
1314 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1318 * Sets the condition for knowing if the actual triangle is being drawed or not
1319 * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1321 void mBarRange :: setIfWithActualDrawed(bool drawActual)
1323 if(!withActualDrawed && drawActual)
1325 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1326 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
1328 else if (withActualDrawed && !drawActual)
1330 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1331 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1333 withActualDrawed = drawActual;
1338 * Gets the condition for knowing if the actual triangle is being drawed or not
1339 * return withActualDrawed The condition for drawing or not the actual control
1341 bool mBarRange :: getIfWithActualDrawed()
1343 return withActualDrawed;
1346 void mBarRange::createAndSendEvent(WXTYPE theEventType)
1348 wxCommandEvent cevent( theEventType, GetId() );
1349 cevent.SetEventObject( this );
1350 GetEventHandler()->ProcessEvent( cevent );
1354 * Sets the background color od the bar
1355 * theColor The color to set to the backgroundColor
1357 void mBarRange :: setBackgroundColor(wxColour theColor)
1359 backgroundColor = theColor;
1363 * Sets the guide line color
1364 * param theNwGuideLineColor The color to set to the guideLineColor
1366 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1368 guideLineColor = theNwGuideLineColor;
1372 * Gets the guide line color
1373 * return guideLineColor The color of the guideLine
1375 wxColour mBarRange :: getGuideLineColour()
1377 return guideLineColor;
1380 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
1382 acceptedClick = true;
1386 void mBarRange::onLeftClickUp(wxMouseEvent& event )
1388 acceptedClick = false;
1391 //EED 20 Juillet 2011
1392 void mBarRange::onKey(wxKeyEvent& event)
1395 if ((event.GetKeyCode()==314) || (event.GetKeyCode()==317))
1400 if ((event.GetKeyCode()==315) || (event.GetKeyCode()==316))
1407 if (_selectionMoveId == 1) // start
1409 SetStart(GetStart()+step);
1410 createAndSendEvent( wxEVT_TSBAR_START );
1413 if (_selectionMoveId == 2) // end
1415 SetEnd(GetEnd()+step);
1416 createAndSendEvent( wxEVT_TSBAR_END );
1419 if (_selectionMoveId == 3) // actual
1421 SetActual(GetActual()+step);
1422 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1425 if (_selectionMoveId == 4) // bar
1427 if (( GetStart()+step>=_min ) && ( GetEnd()+step<=_max ))
1429 SetStart(GetStart()+step);
1430 SetEnd(GetEnd()+step);
1431 if (_moveActualWithBar)
1433 SetActual(GetActual()+step);
1435 createAndSendEvent( wxEVT_TSBAR_START );
1436 createAndSendEvent( wxEVT_TSBAR_END );
1437 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1438 createAndSendEvent( wxEVT_TSBAR_MOVED );
1439 } // Start>_min && End<_max
1440 }// _selectionMoveId == 4