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 //EED-2019-10-25 :wxScrolledWindow(parent,-1,wxDefaultPosition, wxSize(60,60) ,wxTAB_TRAVERSAL)
74 :wxPanel(parent,-1,wxDefaultPosition, wxSize(60,60) ,wxTAB_TRAVERSAL)
81 trianglesHalfWidth = 5;
82 // Setting the default parts colors
83 start_Colour = wxColour(1,0,255,254);
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);
89 //actual is in _start and end
90 //false means that it could be anywhere
91 _moveActualWithBar = false;
92 _in_rangeProperty = false;
93 _selectionMoveId = -1;
94 realX_vertical_line = -1;
99 setIfWithActualDrawed(true);
100 b_popmenu.Append (cntID_CHANGE_COLOR, _("Change Color"), _("Changes the color of the selected part"));
101 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
102 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
106 //----------------------------------------------------------------------------
108 //----------------------------------------------------------------------------
110 mBarRange::~mBarRange()
112 DeletePendingEvents ();
113 RemoveEventHandler ( GetEventHandler() );
116 //---------------------------------------------------------------------------
117 //Draw bar: vertical or Horizontal
118 //---------------------------------------------------------------------------
119 void mBarRange::DrawBar()
124 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
125 _bitmap_bar = new wxBitmap(_w+1280,_h+100);
126 //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 //EED2019-10-25 wxScrolledWindow::Refresh(false);
390 wxPanel::Refresh(false);
394 //----------------------------------------------------------------------------
396 //----------------------------------------------------------------------------
397 void mBarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
399 if (_bitmap_bar!=NULL)
404 RefreshHorizontalView();
406 temp_dc.SelectObject( *_bitmap_bar );
407 wxPaintDC dc( this );
408 dc.Blit(deviceStart_x-(trianglesHalfWidth+2), deviceStart_y, _w-deviceEndMargin+2*(trianglesHalfWidth+2), _h, &temp_dc, 0, 0);
410 // if (_visibleLables)
412 // temp_dc.SelectObject( *_bitmap_info );
413 // dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+200, &temp_dc, deviceStart_x, deviceStart_y);
414 // //dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+60, &temp_dc, 0, 0);
418 RefreshVerticalView();
420 temp_dc.SelectObject( *_bitmap_bar );
421 wxPaintDC dc( this );
422 // dc.Blit(deviceStart_y,deviceStart_x, _h+deviceStart_y-deviceEndMargin,_w+deviceStart_x-deviceEndMargin, &temp_dc, 0, 0);
423 dc.Blit(deviceStart_y,deviceStart_x-(trianglesHalfWidth+2), _h,_w-deviceEndMargin+2*(trianglesHalfWidth+2), &temp_dc, 0, 0);
426 // if (_visibleLables)
428 // temp_dc.SelectObject( *_bitmap_info );
429 // dc.Blit(0,_w, _h+deviceStart_y+200, _w+deviceStart_x+200-deviceEndMargin, &temp_dc, deviceStart_y,_w+deviceStart_x);
437 //----------------------------------------------------------------------------
438 //Repaint the bar if it is horizontal
439 //----------------------------------------------------------------------------
440 void mBarRange::RefreshHorizontalView()
444 //int largestNumberWidthInPixels = 15; // JPRx
445 int pxStart = GetPixelStart();
446 int pxEnd = GetPixelEnd();
447 int pxActual = GetPixelActual();
450 int barHeight = 2*letterHeight;
451 int tempHeight = _h-(6*letterHeight);
455 barHeight = (tempHeight>0) ? tempHeight : (int) _h/2;
461 temp_dc.SelectObject( *_bitmap_bar );
463 // Background of this widget
464 temp_dc.SetPen(wxPen( backgroundColor ));
465 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
466 temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
467 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
468 temp_dc.DrawLine(trianglesHalfWidth+2, 0, _w-deviceEndMargin, 0);
469 temp_dc.DrawLine(trianglesHalfWidth+2, barHeight, (_w-deviceEndMargin-trianglesHalfWidth-2), barHeight);
470 temp_dc.SetDeviceOrigin(trianglesHalfWidth+2,0);
473 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
474 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
475 temp_dc.DrawRectangle( pxStart , 0, pxEnd-pxStart, barHeight);
478 if( _selectionMoveId==4 )
480 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
481 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
483 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
484 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
486 temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
488 // 2 Shadow Triangles: Start and End
489 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
490 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
492 points[0].y= barHeight;
493 points[1].x= -trianglesHalfWidth-1;
495 points[2].x= trianglesHalfWidth+2;
497 temp_dc.DrawPolygon(3,points,pxStart,0);
498 temp_dc.DrawPolygon(3,points,pxEnd,0);
500 // 2 Triangles: Start and End
501 points[1].x = -trianglesHalfWidth;
502 points[2].x = trianglesHalfWidth;
504 //first triangle (start)
505 if( _selectionMoveId == 1 )
507 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
508 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
510 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
511 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
513 temp_dc.DrawPolygon(3,points,pxStart,0);
514 //second triangle (end)
515 if( _selectionMoveId == 2 )
517 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
518 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
520 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
521 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
523 temp_dc.DrawPolygon(3,points,pxEnd,0);
525 if( withActualDrawed )
527 // 1 Shadow Triangle: Actual
528 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
529 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
530 points[1].x = -trianglesHalfWidth-1;
531 points[2].x = trianglesHalfWidth+2;
533 temp_dc.DrawPolygon(3,points,pxActual,0);
535 // 1 Triangle: Actual (red)
536 if( _selectionMoveId==3 )
538 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
539 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
541 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
542 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
544 points[1].x = -trianglesHalfWidth;
545 points[2].x = trianglesHalfWidth;
546 temp_dc.DrawPolygon(3,points,pxActual,0);
549 if (realX_vertical_line!=-1)
551 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
552 int pixelX_guide = ((realX_vertical_line - _min)*(_w-deviceEndMargin))/(_max - _min) ;
553 temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, barHeight);
556 //Information Device drawing
560 //temp_dc.SelectObject( *_bitmap_info );
561 /*temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID ));
562 temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID ));*/
563 //temp_dc.DrawRectangle(deviceStart_x,_h+deviceStart_y,_w+deviceStart_x+40,_h+deviceStart_y+40);
564 //temp_dc.DrawRectangle(0,_h,_w+40-deviceEndMargin,_h+40);
566 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
567 temp_dc.SetFont(font);
568 temp_dc.SetTextForeground(*wxBLACK);
570 //the **MIN** value, always at the same y level that corresponds to barHeight+1
572 // text_min<< GetMin();
573 text_min.Printf(_T("%d"), (int)GetMin() );
575 temp_dc.DrawText(text_min,0,barHeight+1);
577 //the **MAX** value always at the same place
579 // text_max << GetMax();
580 text_max.Printf(_T("%d"), (int)GetMax() );
582 //As there is a margin of 40 extra most numbers (max) should be visibles
583 // stringSize = temp_dc.GetTextExtent(text_max);
585 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
586 wxSize stringSize(tmpX,tmpY);
588 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth())/*2*trianglesHalfWidth*/,barHeight+1);
590 //show logical values
591 //show the **START TRIANGLE** value
593 // text_start << GetStart();
594 text_start.Printf(_T("%d"), (int)GetStart() );
596 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
597 //show the **END TRIANGLE** value
599 // text_end << GetEnd();
600 text_end.Printf(_T("%d"), (int)GetEnd() );
602 // stringSize = temp_dc.GetTextExtent(text_end);
603 temp_dc.GetTextExtent(text_end,&tmpX,&tmpY);
604 stringSize.SetHeight(tmpY);
605 stringSize.SetWidth(tmpX);
606 temp_dc.DrawText(text_end, pxEnd-stringSize.GetWidth(),barHeight+3*letterHeight);
607 if( withActualDrawed )
609 //show the actual value of actual
610 wxString text_actual;
611 // text_actual << GetActual();
612 text_actual.Printf(_T("%d"), (int)GetActual() );
613 // stringSize = temp_dc.GetTextExtent(text_actual);
614 temp_dc.GetTextExtent(text_actual,&tmpX,&tmpY);
615 stringSize.SetHeight(tmpY);
616 stringSize.SetWidth(tmpX);
617 temp_dc.DrawText(text_actual, pxActual-(stringSize.GetWidth()/2),barHeight+letterHeight);
622 //----------------------------------------------------------------------------
623 //Repaint the bar if it is vertical
624 //----------------------------------------------------------------------------
626 void mBarRange::RefreshVerticalView()
630 int px1=GetPixelStart();
631 int px2=GetPixelEnd();
632 int px3=GetPixelActual();
633 int letterHeight = 9;
634 int panelHeight = 9*3+_w;
639 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
645 temp_dc.SelectObject( *_bitmap_bar );
648 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
649 temp_dc.SetPen(wxPen( backgroundColor ));
651 temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
654 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
655 temp_dc.DrawLine(0,trianglesHalfWidth+2, 0, _w-deviceEndMargin);
656 temp_dc.DrawLine(barWidth, trianglesHalfWidth+2, barWidth, (_w-deviceEndMargin-trianglesHalfWidth-2));
657 temp_dc.SetDeviceOrigin(0,trianglesHalfWidth+2);
660 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
661 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
662 temp_dc.DrawRectangle( 0,px1 ,_h, px2-px1 );
666 if( _selectionMoveId==4 )
668 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
669 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
673 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
674 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
676 temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
679 // 2 Shadow Triangles: Start and End
683 points[1].y = -trianglesHalfWidth-1;
685 points[2].y = trianglesHalfWidth+2;
686 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
687 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
688 temp_dc.DrawPolygon(3,points,0,px1);
689 temp_dc.DrawPolygon(3,points,0,px2);
691 // 2 Triangles: Start and End
695 points[1].y = -trianglesHalfWidth;
697 points[2].y = trianglesHalfWidth;
698 //first triangle (start)
699 if( _selectionMoveId==1 )
701 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
702 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
706 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
707 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
709 temp_dc.DrawPolygon(3,points,0,px1);
710 //second triangle (end)
711 if( _selectionMoveId==2 )
713 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
714 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
718 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
719 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
721 temp_dc.DrawPolygon(3,points,0,px2);
723 if( withActualDrawed )
725 // 1 Shadow Triangle: Actual
726 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
727 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
731 points[1].y=-trianglesHalfWidth-1;
733 points[2].y=trianglesHalfWidth+2;
734 temp_dc.DrawPolygon(3,points,0,px3);
736 // 1 Triangle: Actual (red)
740 points[1].y = -trianglesHalfWidth;
742 points[2].y = trianglesHalfWidth;
743 if( _selectionMoveId==3 )
745 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
746 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
750 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
751 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
753 temp_dc.DrawPolygon(3,points,0,px3);
756 if (realX_vertical_line!=-1)
758 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
759 int pixelX_guide = realX_vertical_line*_w/(_max-_min)+deviceStart_x;
760 temp_dc.DrawLine(0,pixelX_guide, _h, pixelX_guide);
763 //Information Device drawing
766 /*temp_dc.SelectObject( *_bitmap_info );
768 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
769 temp_dc.SetPen(wxPen( backgroundColor ,1,wxSOLID ));
770 temp_dc.DrawRectangle(deviceStart_y,_w+deviceStart_x,_h+deviceStart_y+200,_w+deviceStart_x+200);
773 temp_dc.SetBackgroundMode(wxTRANSPARENT);
774 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
775 temp_dc.SetFont(font);
776 temp_dc.SetTextForeground(*wxBLACK);
778 //show logical values
779 //show the actual value of start
781 // text_start<<"Start:"<< GetStart();
782 text_start.Printf(_T("%s %d"),_T("Start: "), (int)GetStart() );
783 temp_dc.DrawText( text_start ,deviceStart_y, _w+deviceStart_x+letterHeight+1);
784 //show the actual value of end
786 // text_end <<"End: "<<GetEnd();
787 text_end.Printf(_T("%s %d"),_T("End: "), (int)GetEnd() );
788 temp_dc.DrawText( text_end ,deviceStart_y,_w+deviceStart_x+letterHeight*2 );
789 if( withActualDrawed )
791 //show the actual value of actual
792 wxString text_actual;
793 // text_actual <<"Actual: " <<GetActual();
794 text_actual.Printf(_T("%s %d"),_T("Actual: "), (int)GetActual() );
795 temp_dc.DrawText( text_actual ,deviceStart_y,_w+deviceStart_x+letterHeight*3);
797 //the min value, always at the same place
799 // text_min<<"Min: " << GetMin();
800 text_min.Printf(_T("%s %d"),_T("Min: "), (int)GetMin() );
801 temp_dc.DrawText( text_min ,deviceStart_y,_w+deviceStart_x+3);
802 //the max value always at the samen place
804 // text_max <<"Max: "<< GetMax();
805 text_max.Printf(_T("%s %d"),_T("Max: "), (int)GetMax() );
806 //toca calcular cuantol lo corremos
807 temp_dc.DrawText(text_max,deviceStart_y,_w+deviceStart_x+43);
812 //----------------------------------------------------------------------------
813 void mBarRange::RefreshForce()
818 //----------------------------------------------------------------------------
819 void mBarRange::OnMouseMove(wxMouseEvent& event )
823 wxPoint point = event.GetPosition();
827 setClickedX(point.x);
832 setClickedX(point.y);
835 int logicClick = getLogicValueofPixel(clickedX);
837 if( _selectionMoveId==-1 )
841 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
842 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
843 bool in_actualT = withActualDrawed && (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
844 bool in_movingBar= (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
847 _selectionMoveId = 3;
849 _selectionMoveId = 1;
851 _selectionMoveId = 2;
852 else if( in_movingBar )
853 _selectionMoveId = 4;
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);
1083 SetPixelStart(deviceStart_x);
1084 SetPixelEnd(_h+deviceStart_x);
1085 SetPixelActual(deviceStart_x);
1092 * Shows the popup menu
1094 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1098 bool validClic = false;
1101 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1105 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1110 setClickedX(event.GetX());
1112 setClickedX(event.GetY());
1114 if (getClickedX()<=_h)
1116 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1117 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1118 bool in_actualT = (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1119 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1122 _selectionMoveId = 1;
1123 else if( in_EndTri )
1124 _selectionMoveId = 2;
1125 else if( in_actualT )
1126 _selectionMoveId = 3;
1127 else if( in_movingBar )
1128 _selectionMoveId = 4;
1130 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1136 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1137 * param & anEvent The wxCommandEvent actioned event
1139 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1141 bool okSelectedColor = false;
1142 wxColour selectedColour;
1144 wxColourDialog dialog( GetParent(), &data);
1146 if ( dialog.ShowModal() == wxID_OK )
1148 selectedColour = dialog.GetColourData().GetColour();
1149 okSelectedColor = true;
1151 if( okSelectedColor )
1153 if (_selectionMoveId==1 )
1154 start_Colour = selectedColour;
1155 else if (_selectionMoveId==2 )
1156 end_Colour = selectedColour;
1157 else if( _selectionMoveId==3 )
1158 actual_Colour = selectedColour;
1159 else if( _selectionMoveId==4 )
1160 bar_Colour = selectedColour;
1162 _selectionMoveId = -1;
1168 * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1169 * param & anEvent The wxCommandEvent actioned event
1171 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1173 if (!_in_rangeProperty)
1175 if(IsActualInRange())
1177 SetInRangeProperty (true);
1178 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1183 SetInRangeProperty (false);
1184 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
1189 * 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.
1190 * param & anEvent The wxCommandEvent actioned event
1192 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1194 if (_moveActualWithBar )
1196 _moveActualWithBar = false;
1197 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1201 if(IsActualInRange())
1203 _moveActualWithBar = true;
1204 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1211 * param activeNow The new state
1213 void mBarRange :: setActiveStateTo (bool activeNow)
1215 activeState = activeNow;
1219 * Gets the active state of the bar
1220 * return activeState The actual state
1222 bool mBarRange :: isActive()
1228 * Gets the real-x value to draw a vertical line
1229 * return realX_vertical_line The real x value for the vertical line
1231 int mBarRange :: getRealX_vertical_line()
1233 return realX_vertical_line;
1237 * Sets the real-x value to draw a vertical line
1238 * param newReal_x The new real x value for the vertical line
1240 void mBarRange :: setRealX_vertical_line(int newReal_x)
1242 realX_vertical_line = newReal_x;
1246 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1247 * return deviceEndMargin The value asigned to the right margin
1249 int mBarRange :: getDeviceEndX()
1251 return deviceEndMargin;
1255 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1256 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1258 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1260 deviceEndMargin = newDeviceEnd_pixels;
1264 * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1265 * return clickedX The x-coord pixel value
1267 int mBarRange :: getClickedX()
1273 * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1274 * param nwClickX The x-coord pixel value
1276 void mBarRange :: setClickedX(int nwClickX)
1278 clickedX = nwClickX;
1283 * Gets the start porcentage with respect to the represented values of the bar
1284 * return The porcentage represented by the start showing point
1286 float mBarRange :: getStartShowPorcentage()
1288 return (float)( 1+(_start - _max)/(_max-_min));
1292 * Gets the end porcentage with respect to the represented values of the bar
1293 * return The porcentage represented by the end showing point
1295 float mBarRange :: getEndShowPorcentage()
1297 return (float) (1+(_end - _max)/(_max-_min));
1301 * Gets the actual porcentage with respect to the represented values of the bar
1302 * return The porcentage represented by the actual showing point
1304 float mBarRange :: getActualShowPorcentage()
1306 return (float) (1+(_actual - _max)/(_max-_min));
1309 int mBarRange :: getLogicValueofPixel(int thePixel)
1311 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1315 * Sets the condition for knowing if the actual triangle is being drawed or not
1316 * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1318 void mBarRange :: setIfWithActualDrawed(bool drawActual)
1320 if(!withActualDrawed && drawActual)
1322 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1323 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
1325 else if (withActualDrawed && !drawActual)
1327 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1328 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1330 withActualDrawed = drawActual;
1335 * Gets the condition for knowing if the actual triangle is being drawed or not
1336 * return withActualDrawed The condition for drawing or not the actual control
1338 bool mBarRange :: getIfWithActualDrawed()
1340 return withActualDrawed;
1343 void mBarRange::createAndSendEvent(WXTYPE theEventType)
1345 wxCommandEvent cevent( theEventType, GetId() );
1346 cevent.SetEventObject( this );
1347 GetEventHandler()->ProcessEvent( cevent );
1351 * Sets the background color od the bar
1352 * theColor The color to set to the backgroundColor
1354 void mBarRange :: setBackgroundColor(wxColour theColor)
1356 backgroundColor = theColor;
1360 * Sets the guide line color
1361 * param theNwGuideLineColor The color to set to the guideLineColor
1363 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1365 guideLineColor = theNwGuideLineColor;
1369 * Gets the guide line color
1370 * return guideLineColor The color of the guideLine
1372 wxColour mBarRange :: getGuideLineColour()
1374 return guideLineColor;
1377 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
1379 acceptedClick = true;
1383 void mBarRange::onLeftClickUp(wxMouseEvent& event )
1385 acceptedClick = false;
1388 //EED 20 Juillet 2011
1389 void mBarRange::onKey(wxKeyEvent& event)
1392 if ((event.GetKeyCode()==314) || (event.GetKeyCode()==317))
1397 if ((event.GetKeyCode()==315) || (event.GetKeyCode()==316))
1404 if (_selectionMoveId == 1) // start
1406 SetStart(GetStart()+step);
1407 createAndSendEvent( wxEVT_TSBAR_START );
1410 if (_selectionMoveId == 2) // end
1412 SetEnd(GetEnd()+step);
1413 createAndSendEvent( wxEVT_TSBAR_END );
1416 if (_selectionMoveId == 3) // actual
1418 SetActual(GetActual()+step);
1419 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1422 if (_selectionMoveId == 4) // bar
1424 if (( GetStart()+step>=_min ) && ( GetEnd()+step<=_max ))
1426 SetStart(GetStart()+step);
1427 SetEnd(GetEnd()+step);
1428 if (_moveActualWithBar)
1430 SetActual(GetActual()+step);
1432 createAndSendEvent( wxEVT_TSBAR_START );
1433 createAndSendEvent( wxEVT_TSBAR_END );
1434 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1435 createAndSendEvent( wxEVT_TSBAR_MOVED );
1436 } // Start>_min && End<_max
1437 }// _selectionMoveId == 4