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 #include "wxManualPaintPanel.h"
27 #include <wx/radiobox.h>
29 wxManualPaintPanel::wxManualPaintPanel( wxWindow * parent )
30 : wxPanel( parent, -1 )
32 wxSizer *sizer = new wxFlexGridSizer( 1 );
34 wxStaticText *tittleText = new wxStaticText( this, -1,_T(" Manual Paint") );
36 sizer->Add( tittleText );
37 //giving some blank spaces
38 sizer->Add( new wxStaticText( this, -1, _T(" key A : Enable/Disable ") ) );
39 this->ConfigureActiveCBButton( );
40 this->ConfigureBrushToolRadioButton( );
41 this->Configure2D3DRadioButton( );
42 this->ConfigureBrushFormRadioButton( );
43 this->ConfigureRangeBar( );
44 this->ConfigureGrayLevelSld( );
45 this->ConfigureBrushSizeSld( );
46 this->ConfigureDistanceFillSld( );
47 this->ConfigureTolFillSld( );
48 this->ConfigureEditButtons( );
50 wxStaticText *editButtonsText = new wxStaticText( this, -1,_T("Edit Buttons") );
51 this->_buttonsSizer = new wxFlexGridSizer( 4 );
52 this->_buttonsSizer->Add( _btnUndo, 1, wxGROW );
53 this->_buttonsSizer->Add( _btnRedo, 1, wxGROW );
54 this->_buttonsSizer->Add( _btnCopy, 1, wxGROW );
55 this->_gConfigSizer = new wxFlexGridSizer( 1 );
56 //BrushTool Radio Button
58 this->_gConfigSizer->Add( new wxStaticText( this, -1, _T(" ") ) );
60 this->_gConfigSizer->Add( _rbBrushTool, 1, wxGROW );
62 this->_gConfigSizer->Add( _rb2D3D, 1, wxGROW );
64 this->_gConfigSizer->Add( new wxStaticText( this, -1, _T( "Select Range" ) ), 1, wxGROW );
65 this->_gConfigSizer->Add( _mBarSlices, 1, wxGROW );
67 this->_gConfigSizer->Add( _txtGrayLevel );
69 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
70 #if wxMAJOR_VERSION <= 2
71 wxFlexGridSizer *sizerGrayLevel = new wxFlexGridSizer( 2, wxHORIZONTAL );
73 wxFlexGridSizer *sizerGrayLevel = new wxFlexGridSizer( 2 );
76 sizerGrayLevel->Add( _sldGrayLevel, 1, wxGROW );
77 sizerGrayLevel->Add( _graylevelCtrl, 1,
78 wxALIGN_BOTTOM | wxALIGN_LEFT | wxALL, 5 );
79 this->_gConfigSizer->Add( sizerGrayLevel, 1, wxGROW );
82 this->_brushSizer = new wxFlexGridSizer( 1 );
84 this->_brushSizer->Add( new wxStaticText( this, -1, _T(" ") ) );
86 this->_brushSizer->Add( new wxStaticText( this, -1, _T("Brush Settings") ) );
88 this->_brushSizer->Add( _txtBrushSize );
90 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
91 #if wxMAJOR_VERSION <= 2
92 wxFlexGridSizer *sizersdlBrushSize = new wxFlexGridSizer( 2, wxHORIZONTAL );
94 wxFlexGridSizer *sizersdlBrushSize = new wxFlexGridSizer( 2 );
97 sizersdlBrushSize->Add( _sldBrushSize, 1, wxGROW );
98 sizersdlBrushSize->Add( _BrushSizeCtrl, 1,
99 wxALIGN_BOTTOM | wxALIGN_LEFT | wxALL, 5 );
100 this->_brushSizer->Add( sizersdlBrushSize );
101 //BrushForm RadioButton
102 this->_brushSizer->Add( _rbBrushForm, 1, wxGROW );
104 this->_FillSizer = new wxFlexGridSizer( 1 );
106 this->_FillSizer->Add( new wxStaticText( this, -1, _T(" ") ) );
108 this->_FillSizer->Add( new wxStaticText( this, -1, _T("Fill Settings") ) );
110 this->_FillSizer->Add( _txtToleranceFill );
111 wxFlexGridSizer *sizerTolerance = new wxFlexGridSizer( 2 );
112 sizerTolerance->Add( _sldToleranceFill, 1, wxGROW );
113 sizerTolerance->Add( _tolerancefillCtrl, 1, wxALIGN_BOTTOM | wxALIGN_LEFT | wxALL, 5 );
114 this->_FillSizer->Add( sizerTolerance, 1, wxGROW );
116 this->_FillSizer->Add( _txtDistanceFill );
117 wxFlexGridSizer *sizerDistance = new wxFlexGridSizer( 2 );
118 sizerDistance->Add( _sldDistanceFill, 1, wxGROW );
119 sizerDistance->Add( _distancefillCtrl, 1, wxALIGN_BOTTOM | wxALIGN_LEFT | wxALL, 5 );
120 this->_FillSizer->Add( sizerDistance );
121 sizer->Add( _activeCB );
122 sizer->Add( editButtonsText );
123 sizer->Add( _buttonsSizer );
124 sizer->Add( _gConfigSizer );
125 sizer->Add( _brushSizer );
126 sizer->Add( _FillSizer );
127 this->ConnectComponents( ); //DFCH
128 this->_FillSizer->Show( false );
129 this->SetSizer( sizer );
130 this->SetAutoLayout( true );
134 //---------------------------------------------------------------------------
135 wxManualPaintPanel::~wxManualPaintPanel( )
139 //--------------------------------------------------------------------------
140 void wxManualPaintPanel::ConfigureActiveCBButton( )
142 _activeCB = new wxCheckBox (this, -1, _T("Active") );
143 _activeCB->SetValue(true);
144 SetActive( _activeCB->GetValue() );
149 //--------------------------------------------------------------------------
150 void wxManualPaintPanel::ConfigureBrushToolRadioButton( )
152 wxString lstBrushForm[ 2 ];
153 lstBrushForm[ 0 ] = _T("rectangle/cube");
154 lstBrushForm[ 1 ] = _T("circle/sphere");
155 _rbBrushForm = new wxRadioBox( this, -1, _T("Brush form"),
156 wxDefaultPosition, wxSize( 270, 45 ), 2, lstBrushForm, 2,
160 //--------------------------------------------------------------------------
161 void wxManualPaintPanel::Configure2D3DRadioButton( )
163 wxString lst2D3D[ 2 ];
164 lst2D3D[ 0 ] = _T("2D");
165 lst2D3D[ 1 ] = _T("3D");
166 _rb2D3D = new wxRadioBox( this, -1, _T("2D / 3D"), wxDefaultPosition,
167 wxSize( 270, 45 ), 2, lst2D3D, 2, wxRA_SPECIFY_COLS );
168 _rb2D3D->SetSelection( 1 );
172 //--------------------------------------------------------------------------
173 void wxManualPaintPanel::ConfigureBrushFormRadioButton( )
175 wxString lstBrushTool[ 2 ];
176 lstBrushTool[ 0 ] = _T("Brush");
177 lstBrushTool[ 1 ] = _T("Fill");
178 _rbBrushTool = new wxRadioBox( this, -1, _T("Brush tool"),
179 wxDefaultPosition, wxSize( 270, 45 ), 2, lstBrushTool, 2,
183 //--------------------------------------------------------------------------
184 void wxManualPaintPanel::ConfigureRangeBar( )
188 GetScalarRange( range );
189 int min = 0; //range[0];
190 int max = 6000; //range[1];
191 _mBarSlices = new mBarRange( this, 70, 65 );
192 _mBarSlices->SetMin( 0 );
193 _mBarSlices->SetStart( 0 );
194 _mBarSlices->SetOrientation( true );
195 _mBarSlices->setActiveStateTo( true );
196 _mBarSlices->setVisibleLabels( true );
197 _mBarSlices->setDeviceEndMargin( 10 );
198 _mBarSlices->setDeviceBlitStart( 10, 10 );
199 _mBarSlices->setIfWithActualDrawed( false );
200 _mBarSlices->setRepresentedValues( min, max );
201 _mBarSlices->SetStart( min );
202 _mBarSlices->SetEnd( max );
203 _mBarSlices->Update( );
206 //DFCH -- End BarSlices
209 //--------------------------------------------------------------------------
210 void wxManualPaintPanel::ConfigureGrayLevelSld( )
212 _txtGrayLevel = new wxStaticText( this, -1,
213 wxString( _T(" Gray Level ") ) );
214 _sldGrayLevel = new wxSlider( this, -1, 0, 0, 255, wxDefaultPosition,
215 wxDefaultSize, wxSL_LABELS );
216 _sldGrayLevel->SetMinSize( wxSize( 200, -1 ) );
217 _sldGrayLevel->SetMaxSize( wxSize( 200, -1 ) );
218 _graylevelCtrl = new wxSpinCtrl( this, wxID_ANY, wxEmptyString,
219 wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 65535, 0 );
222 //--------------------------------------------------------------------------
223 void wxManualPaintPanel::ConfigureBrushSizeSld( )
225 _txtBrushSize = new wxStaticText( this, -1,
226 wxString( _T(" Brush size ") ) );
227 _sldBrushSize = new wxSlider( this, -1, 5, 1, 50, wxDefaultPosition,
228 wxDefaultSize, wxSL_LABELS );
229 _BrushSizeCtrl = new wxSpinCtrl( this, wxID_ANY, wxEmptyString,
230 wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 65535, 0 );
231 _sldBrushSize->SetMinSize( wxSize( 200, -1 ) );
232 _sldBrushSize->SetMaxSize( wxSize( 200, -1 ) );
235 //--------------------------------------------------------------------------
236 void wxManualPaintPanel::ConfigureDistanceFillSld( )
238 _txtDistanceFill = new wxStaticText( this, -1,
239 wxString( _T(" Distance fill ") ) );
240 _sldDistanceFill = new wxSlider( this, -1, 5, 1, 500, wxDefaultPosition,
241 wxDefaultSize, wxSL_LABELS );
242 _sldDistanceFill->SetMinSize( wxSize( 200, -1 ) );
243 _sldDistanceFill->SetMaxSize( wxSize( 200, -1 ) );
244 _distancefillCtrl = new wxSpinCtrl( this, wxID_ANY, wxEmptyString,
245 wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 500, 50 );
246 _txtDistanceFill->Disable( );
247 _sldDistanceFill->Disable( );
248 _distancefillCtrl->Disable( );
251 //--------------------------------------------------------------------------
252 void wxManualPaintPanel::ConfigureTolFillSld( )
254 _txtToleranceFill = new wxStaticText( this, -1,wxString( _T(" Tolerance fill ") ) );
255 _sldToleranceFill = new wxSlider( this, -1, 125, 0, 255, wxDefaultPosition,wxDefaultSize, wxSL_LABELS );
256 _sldToleranceFill->SetMinSize( wxSize( 200, -1 ) );
257 _sldToleranceFill->SetMaxSize( wxSize( 200, -1 ) );
258 _tolerancefillCtrl = new wxSpinCtrl( this, wxID_ANY, wxEmptyString,wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 65535, 50 );
259 _txtToleranceFill->Disable( );
260 _sldToleranceFill->Disable( );
261 _tolerancefillCtrl->Disable( );
264 //--------------------------------------------------------------------------
265 void wxManualPaintPanel::ConfigureEditButtons( )
267 _btnCopy = new wxButton( this, -1, _T("Copy") );
268 _btnCopy->Disable( );
269 _btnUndo = new wxButton( this, -1, _T("Undo") );
270 _btnRedo = new wxButton( this, -1, _T("Redo") );
271 //btnUndo->Disable();
273 //--------------------------------------------------------------------------
276 * The following function allows the management of the events
278 void wxManualPaintPanel::ConnectComponents( ) //DFCH
280 this->Connect(_sldBrushSize->GetId( ),
281 wxEVT_SCROLL_THUMBRELEASE,
282 (wxObjectEventFunction) (void(wxPanel::*)(
283 wxScrollEvent& )) (&wxManualPaintPanel::OnBrushSize) );this ->Connect (_sldGrayLevel->GetId(),
284 wxEVT_SCROLL_THUMBRELEASE,
285 (wxObjectEventFunction) (void(wxPanel::*)( wxScrollEvent&)) &wxManualPaintPanel::OnSldGrayLevel);
287 this->Connect( _graylevelCtrl->GetId(),
288 wxEVT_COMMAND_TEXT_UPDATED,
289 (wxObjectEventFunction) (void(wxPanel::*)(
290 wxCommandEvent&)) &wxManualPaintPanel::OnCtrTxtGrayLevel);
293 _sldToleranceFill->GetId(),
294 wxEVT_SCROLL_THUMBRELEASE,
295 (wxObjectEventFunction) (void(wxPanel::*)(
296 wxScrollEvent&)) &wxManualPaintPanel::OnSldToleranceFill);this->Connect
298 _tolerancefillCtrl->GetId(),
299 wxEVT_COMMAND_TEXT_UPDATED,
300 (wxObjectEventFunction) (void(wxPanel::*)(
301 wxCommandEvent&)) &wxManualPaintPanel::OnCtrTxtToleranceFill);
304 _sldDistanceFill->GetId(),
305 wxEVT_SCROLL_THUMBRELEASE,
306 (wxObjectEventFunction) (void(wxPanel::*)(
307 wxScrollEvent&)) &wxManualPaintPanel::OnSldDistanceFill);this->Connect
309 _distancefillCtrl->GetId(),
310 wxEVT_COMMAND_TEXT_UPDATED,
311 (wxObjectEventFunction) (void(wxPanel::*)(
312 wxCommandEvent&)) &wxManualPaintPanel::OnCtrTxtDistanceFill);
316 wxEVT_COMMAND_RADIOBOX_SELECTED,
317 (wxObjectEventFunction) (void(wxPanel::*)(
318 wxCommandEvent&)) &wxManualPaintPanel::On2D3D);this->Connect
320 _rbBrushForm->GetId(),
321 wxEVT_COMMAND_RADIOBOX_SELECTED,
322 (wxObjectEventFunction) (void(wxPanel::*)(
323 wxCommandEvent&)) &wxManualPaintPanel::OnBrushForm);this->Connect
325 _rbBrushTool->GetId(),
326 wxEVT_COMMAND_RADIOBOX_SELECTED,
327 (wxObjectEventFunction) (void(wxPanel::*)(
328 wxCommandEvent&)) &wxManualPaintPanel::OnTool);this->Connect
331 wxEVT_COMMAND_BUTTON_CLICKED,
332 (wxObjectEventFunction) (void(wxPanel::*)(
333 wxCommandEvent&)) &wxManualPaintPanel::OnCopy);
337 wxEVT_COMMAND_BUTTON_CLICKED,
338 (wxObjectEventFunction) (void(wxPanel::*)(
339 wxCommandEvent&)) &wxManualPaintPanel::OnUndo);
340 this->Connect(_btnRedo->GetId(),
341 wxEVT_COMMAND_BUTTON_CLICKED,
342 (wxObjectEventFunction) (void(wxPanel::*)(
343 wxCommandEvent&)) &wxManualPaintPanel::OnRedo); //DFCH
346 _mBarSlices->GetId(),
348 (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onBarrange);
349 // Connect(modBarRange->GetId(),98765,(wxObjectEventFunction) (wxCommandEventFunction) &wxWidgetSliderMinMax::onActualChange_Bar );
351 _mBarSlices->GetId(),
353 (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onActualChange_Bar);
355 _mBarSlices->GetId(),
357 (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onStartChange_Bar);
359 _mBarSlices->GetId(),
361 (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onEndChange_Bar);
363 _mBarSlices->GetId(),
365 (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onSelectionEnd);
367 _mBarSlices->GetId(),
369 (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onMovedBar);
372 _BrushSizeCtrl->GetId(),
373 wxEVT_COMMAND_TEXT_UPDATED,
374 (wxObjectEventFunction) (void(wxPanel::*)(
375 wxCommandEvent&)) &wxManualPaintPanel::OnCtrBrushSize);
379 wxEVT_COMMAND_CHECKBOX_CLICKED,
380 (wxObjectEventFunction) (void (wxPanel::*)(wxCommandEvent&))&wxManualPaintPanel::OnActive);
384 //-------------------------------------------------------------------------
385 void wxManualPaintPanel::OnActive(wxCommandEvent& event)
387 SetActive( _activeCB->GetValue() );
391 //---------------------------------------------------------------------------
392 void wxManualPaintPanel::OnBrushSize( wxScrollEvent& event )
394 SetBrushSize( this->_sldBrushSize->GetValue( ) );
396 text.Printf( wxT("%d"), this->_sldBrushSize->GetValue( ) );
397 _BrushSizeCtrl->SetValue( text );
400 //---------------------------------------------------------------------------
401 void wxManualPaintPanel::OnSldGrayLevel( wxScrollEvent& event )
403 SetGrayLevel( (double) ( _sldGrayLevel->GetValue( )) );
405 text.Printf( wxT("%d"), _sldGrayLevel->GetValue( ) );
406 _graylevelCtrl->SetValue( text );
409 //---------------------------------------------------------------------------
410 void wxManualPaintPanel::OnCtrTxtGrayLevel( wxCommandEvent &event )
412 int graylevel = this->_graylevelCtrl->GetValue( );
413 this->_sldGrayLevel->SetValue( graylevel );
414 SetGrayLevel( graylevel );
417 //---------------------------------------------------------------------------
418 void wxManualPaintPanel::OnSldDistanceFill( wxScrollEvent& event )
420 SetDistanceFill( (double) ( _sldDistanceFill->GetValue( )) );
422 text.Printf( wxT("%d"), _sldDistanceFill->GetValue( ) );
423 _distancefillCtrl->SetValue( text );
426 //---------------------------------------------------------------------------
427 void wxManualPaintPanel::OnCtrTxtDistanceFill( wxCommandEvent &event )
429 int distancefill = this->_distancefillCtrl->GetValue( );
430 this->_sldDistanceFill->SetValue( distancefill );
431 SetDistanceFill( distancefill );
433 //---------------------------------------------------------------------------
434 void wxManualPaintPanel::OnCtrBrushSize( wxCommandEvent &event )
436 int brushSize = _BrushSizeCtrl->GetValue( );
437 this->_sldBrushSize->SetValue( brushSize );
438 SetBrushSize( brushSize );
441 //---------------------------------------------------------------------------
442 void wxManualPaintPanel::OnSldToleranceFill( wxScrollEvent& event )
444 SetToleranceFill( (double) ( _sldToleranceFill->GetValue( )) );
446 text.Printf( wxT("%d"), _sldToleranceFill->GetValue( ) );
447 _tolerancefillCtrl->SetValue( text );
450 //---------------------------------------------------------------------------
451 void wxManualPaintPanel::OnCtrTxtToleranceFill( wxCommandEvent &event )
453 int tolerance = _tolerancefillCtrl->GetValue( );
454 this->_sldToleranceFill->SetValue( tolerance );
455 SetToleranceFill( tolerance );
458 //---------------------------------------------------------------------------
459 void wxManualPaintPanel::DisableControls( )
461 _txtBrushSize->Disable( );
462 _sldBrushSize->Disable( );
463 _rbBrushForm->Disable( );
465 _txtToleranceFill->Disable( );
466 _sldToleranceFill->Disable( );
467 _tolerancefillCtrl->Disable( );
469 _txtDistanceFill->Disable( );
470 _sldDistanceFill->Disable( );
471 _distancefillCtrl->Disable( );
474 //---------------------------------------------------------------------------
475 void wxManualPaintPanel::On2D3D( wxCommandEvent &event )
477 Set2D3D( _rb2D3D->GetSelection( ) );
480 //---------------------------------------------------------------------------
481 void wxManualPaintPanel::OnBrushForm( wxCommandEvent &event )
483 SetBrushForm( _rbBrushForm->GetSelection( ) );
486 //---------------------------------------------------------------------------
487 void wxManualPaintPanel::OnTool( wxCommandEvent &event )
490 SetTool( _rbBrushTool->GetSelection( ) );
492 if( _rbBrushTool->GetSelection( ) == 0 ) //Brush tool
494 _txtBrushSize->Enable( );
495 _sldBrushSize->Enable( );
496 _rbBrushForm->Enable( );
497 _brushSizer->Show( true );
498 _FillSizer->Show( false );
502 if( _rbBrushTool->GetSelection( ) == 1 ) //Fill tool
504 _txtToleranceFill->Enable( );
505 _sldToleranceFill->Enable( );
506 _tolerancefillCtrl->Enable( );
507 _txtDistanceFill->Enable( );
508 _sldDistanceFill->Enable( );
509 _distancefillCtrl->Enable( );
510 _FillSizer->Show( true );
511 _brushSizer->Show( false );
516 //---------------------------------------------------------------------------
517 void wxManualPaintPanel::OnCopy( wxCommandEvent &event )
521 //---------------------------------------------------------------------------
522 void wxManualPaintPanel::OnUndo( wxCommandEvent &event )
524 this->_manualPaintControler->Undo( );
527 //---------------------------------------------------------------------------
528 void wxManualPaintPanel::OnRedo( wxCommandEvent &event )
530 this->_manualPaintControler->Redo( );
533 //--------------------------------------------------------------------------------------------------------------------------------
534 // Min-Max Barrange received events
535 //--------------------------------------------------------------------------------------------------------------------------------
536 void wxManualPaintPanel::onBarrange( wxCommandEvent& event )
540 void wxManualPaintPanel::onActualChange_Bar( wxCommandEvent& event )
542 /*mbbtkSliderMinMax->bbSetOutputOutActual(modBarRange->GetActual());
543 mbbtkSliderMinMax->bbSignalOutputModification(std::string("OutActual"));*/
546 void wxManualPaintPanel::onStartChange_Bar( wxCommandEvent& event )
548 SetRangeMin( _mBarSlices->GetStart( ) );
551 void wxManualPaintPanel::onEndChange_Bar( wxCommandEvent& event )
553 SetRangeMax( _mBarSlices->GetEnd( ) );
556 void wxManualPaintPanel::onSelectionEnd( wxCommandEvent& event )
560 void wxManualPaintPanel::onMovedBar( wxCommandEvent& event )
563 //-------------------------------------------------------------------------
564 //--------------------------------------------------------------------------
565 //--------------------------------------------------------------------------