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 );
35 wxStaticText *tittleText = new wxStaticText( this, -1,
36 _T(" Manual Paint") );
38 sizer->Add( tittleText );
39 //giving some blank spaces
40 sizer->Add( new wxStaticText( this, -1, _T(" key A : Enable/Disable ") ) );
42 this->ConfigureActiveCBButton( );
43 this->ConfigureBrushToolRadioButton( );
44 this->Configure2D3DRadioButton( );
45 this->ConfigureBrushFormRadioButton( );
46 this->ConfigureRangeBar( );
47 this->ConfigureGrayLevelSld( );
48 this->ConfigureBrushSizeSld( );
49 this->ConfigureDistanceFillSld( );
50 this->ConfigureTolFillSld( );
51 this->ConfigureEditButtons( );
54 wxStaticText *editButtonsText = new wxStaticText( this, -1,
56 this->_buttonsSizer = new wxFlexGridSizer( 4 );
57 this->_buttonsSizer->Add( _btnUndo, 1, wxGROW );
58 this->_buttonsSizer->Add( _btnRedo, 1, wxGROW );
59 this->_buttonsSizer->Add( _btnCopy, 1, wxGROW );
61 this->_gConfigSizer = new wxFlexGridSizer( 1 );
62 //BrushTool Radio Button
64 this->_gConfigSizer->Add( new wxStaticText( this, -1, _T(" ") ) );
66 this->_gConfigSizer->Add( _rbBrushTool, 1, wxGROW );
68 this->_gConfigSizer->Add( _rb2D3D, 1, wxGROW );
70 this->_gConfigSizer->Add(
71 new wxStaticText( this, -1, _T( "Select Range" ) ), 1, wxGROW );
72 this->_gConfigSizer->Add( _mBarSlices, 1, wxGROW );
74 this->_gConfigSizer->Add( _txtGrayLevel );
76 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
77 #if wxMAJOR_VERSION <= 2
78 wxFlexGridSizer *sizerGrayLevel = new wxFlexGridSizer( 2, wxHORIZONTAL );
80 wxFlexGridSizer *sizerGrayLevel = new wxFlexGridSizer( 2 );
83 sizerGrayLevel->Add( _sldGrayLevel, 1, wxGROW );
84 sizerGrayLevel->Add( _graylevelCtrl, 1,
85 wxALIGN_BOTTOM | wxALIGN_LEFT | wxALL, 5 );
86 this->_gConfigSizer->Add( sizerGrayLevel, 1, wxGROW );
89 this->_brushSizer = new wxFlexGridSizer( 1 );
91 this->_brushSizer->Add( new wxStaticText( this, -1, _T(" ") ) );
93 this->_brushSizer->Add(
94 new wxStaticText( this, -1, _T("Brush Settings") ) );
96 this->_brushSizer->Add( _txtBrushSize );
98 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
99 #if wxMAJOR_VERSION <= 2
100 wxFlexGridSizer *sizersdlBrushSize = new wxFlexGridSizer( 2, wxHORIZONTAL );
102 wxFlexGridSizer *sizersdlBrushSize = new wxFlexGridSizer( 2 );
105 sizersdlBrushSize->Add( _sldBrushSize, 1, wxGROW );
106 sizersdlBrushSize->Add( _BrushSizeCtrl, 1,
107 wxALIGN_BOTTOM | wxALIGN_LEFT | wxALL, 5 );
108 this->_brushSizer->Add( sizersdlBrushSize );
109 //BrushForm RadioButton
110 this->_brushSizer->Add( _rbBrushForm, 1, wxGROW );
112 this->_FillSizer = new wxFlexGridSizer( 1 );
114 this->_FillSizer->Add( new wxStaticText( this, -1, _T(" ") ) );
116 this->_FillSizer->Add( new wxStaticText( this, -1, _T("Fill Settings") ) );
118 this->_FillSizer->Add( _txtToleranceFill );
119 wxFlexGridSizer *sizerTolerance = new wxFlexGridSizer( 2 );
120 sizerTolerance->Add( _sldToleranceFill, 1, wxGROW );
121 sizerTolerance->Add( _tolerancefillCtrl, 1,
122 wxALIGN_BOTTOM | wxALIGN_LEFT | wxALL, 5 );
123 this->_FillSizer->Add( sizerTolerance, 1, wxGROW );
125 this->_FillSizer->Add( _txtDistanceFill );
126 wxFlexGridSizer *sizerDistance = new wxFlexGridSizer( 2 );
127 sizerDistance->Add( _sldDistanceFill, 1, wxGROW );
128 sizerDistance->Add( _distancefillCtrl, 1,
129 wxALIGN_BOTTOM | wxALIGN_LEFT | wxALL, 5 );
130 this->_FillSizer->Add( sizerDistance );
132 sizer->Add( _activeCB );
133 sizer->Add( editButtonsText );
134 sizer->Add( _buttonsSizer );
135 sizer->Add( _gConfigSizer );
136 sizer->Add( _brushSizer );
137 sizer->Add( _FillSizer );
139 this->ConnectComponents( ); //DFCH
140 this->_FillSizer->Show( false );
142 this->SetSizer( sizer );
143 this->SetAutoLayout( true );
148 //---------------------------------------------------------------------------
149 wxManualPaintPanel::~wxManualPaintPanel( )
153 //--------------------------------------------------------------------------
154 void wxManualPaintPanel::ConfigureActiveCBButton( )
156 _activeCB = new wxCheckBox (this, -1, _T("Active") );
157 _activeCB->SetValue(true);
158 SetActive( _activeCB->GetValue() );
163 //--------------------------------------------------------------------------
164 void wxManualPaintPanel::ConfigureBrushToolRadioButton( )
166 wxString lstBrushForm[ 2 ];
167 lstBrushForm[ 0 ] = _T("rectangle/cube");
168 lstBrushForm[ 1 ] = _T("circle/sphere");
169 _rbBrushForm = new wxRadioBox( this, -1, _T("Brush form"),
170 wxDefaultPosition, wxSize( 270, 45 ), 2, lstBrushForm, 2,
174 //--------------------------------------------------------------------------
175 void wxManualPaintPanel::Configure2D3DRadioButton( )
177 wxString lst2D3D[ 2 ];
178 lst2D3D[ 0 ] = _T("2D");
179 lst2D3D[ 1 ] = _T("3D");
180 _rb2D3D = new wxRadioBox( this, -1, _T("2D / 3D"), wxDefaultPosition,
181 wxSize( 270, 45 ), 2, lst2D3D, 2, wxRA_SPECIFY_COLS );
182 _rb2D3D->SetSelection( 1 );
186 //--------------------------------------------------------------------------
187 void wxManualPaintPanel::ConfigureBrushFormRadioButton( )
189 wxString lstBrushTool[ 2 ];
190 lstBrushTool[ 0 ] = _T("Brush");
191 lstBrushTool[ 1 ] = _T("Fill");
192 _rbBrushTool = new wxRadioBox( this, -1, _T("Brush tool"),
193 wxDefaultPosition, wxSize( 270, 45 ), 2, lstBrushTool, 2,
197 //--------------------------------------------------------------------------
198 void wxManualPaintPanel::ConfigureRangeBar( )
202 GetScalarRange( range );
203 int min = 0; //range[0];
204 int max = 6000; //range[1];
205 _mBarSlices = new mBarRange( this, 70, 65 );
206 _mBarSlices->SetMin( 0 );
207 _mBarSlices->SetStart( 0 );
208 _mBarSlices->SetOrientation( true );
209 _mBarSlices->setActiveStateTo( true );
210 _mBarSlices->setVisibleLabels( true );
211 _mBarSlices->setDeviceEndMargin( 10 );
212 _mBarSlices->setDeviceBlitStart( 10, 10 );
213 _mBarSlices->setIfWithActualDrawed( false );
214 _mBarSlices->setRepresentedValues( min, max );
215 _mBarSlices->SetStart( min );
216 _mBarSlices->SetEnd( max );
217 _mBarSlices->Update( );
222 //DFCH -- End BarSlices
224 //--------------------------------------------------------------------------
225 void wxManualPaintPanel::ConfigureGrayLevelSld( )
227 _txtGrayLevel = new wxStaticText( this, -1,
228 wxString( _T(" Gray Level ") ) );
229 _sldGrayLevel = new wxSlider( this, -1, 0, 0, 255, wxDefaultPosition,
230 wxDefaultSize, wxSL_LABELS );
231 _sldGrayLevel->SetMinSize( wxSize( 200, -1 ) );
232 _sldGrayLevel->SetMaxSize( wxSize( 200, -1 ) );
233 _graylevelCtrl = new wxSpinCtrl( this, wxID_ANY, wxEmptyString,
234 wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 65535, 0 );
236 //--------------------------------------------------------------------------
237 void wxManualPaintPanel::ConfigureBrushSizeSld( )
239 _txtBrushSize = new wxStaticText( this, -1,
240 wxString( _T(" Brush size ") ) );
241 _sldBrushSize = new wxSlider( this, -1, 1, 1, 50, wxDefaultPosition,
242 wxDefaultSize, wxSL_LABELS );
243 _BrushSizeCtrl = new wxSpinCtrl( this, wxID_ANY, wxEmptyString,
244 wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 65535, 0 );
245 _sldBrushSize->SetMinSize( wxSize( 200, -1 ) );
246 _sldBrushSize->SetMaxSize( wxSize( 200, -1 ) );
248 //--------------------------------------------------------------------------
249 void wxManualPaintPanel::ConfigureDistanceFillSld( )
251 _txtDistanceFill = new wxStaticText( this, -1,
252 wxString( _T(" Distance fill ") ) );
253 _sldDistanceFill = new wxSlider( this, -1, 50, 1, 500, wxDefaultPosition,
254 wxDefaultSize, wxSL_LABELS );
255 _sldDistanceFill->SetMinSize( wxSize( 200, -1 ) );
256 _sldDistanceFill->SetMaxSize( wxSize( 200, -1 ) );
257 _distancefillCtrl = new wxSpinCtrl( this, wxID_ANY, wxEmptyString,
258 wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 500, 50 );
259 _txtDistanceFill->Disable( );
260 _sldDistanceFill->Disable( );
261 _distancefillCtrl->Disable( );
263 //--------------------------------------------------------------------------
264 void wxManualPaintPanel::ConfigureTolFillSld( )
266 _txtToleranceFill = new wxStaticText( this, -1,
267 wxString( _T(" Tolerance fill ") ) );
268 _sldToleranceFill = new wxSlider( this, -1, 125, 0, 255, wxDefaultPosition,
269 wxDefaultSize, wxSL_LABELS );
270 _sldToleranceFill->SetMinSize( wxSize( 200, -1 ) );
271 _sldToleranceFill->SetMaxSize( wxSize( 200, -1 ) );
272 _tolerancefillCtrl = new wxSpinCtrl( this, wxID_ANY, wxEmptyString,
273 wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 65535, 50 );
274 _txtToleranceFill->Disable( );
275 _sldToleranceFill->Disable( );
276 _tolerancefillCtrl->Disable( );
279 //--------------------------------------------------------------------------
280 void wxManualPaintPanel::ConfigureEditButtons( )
282 _btnCopy = new wxButton( this, -1, _T("Copy") );
283 _btnCopy->Disable( );
284 _btnUndo = new wxButton( this, -1, _T("Undo") );
285 _btnRedo = new wxButton( this, -1, _T("Redo") );
286 //btnUndo->Disable();
288 //--------------------------------------------------------------------------
291 * The following function allows the management of the events
293 void wxManualPaintPanel::ConnectComponents( ) //DFCH
295 this->Connect(_sldBrushSize->GetId( ),
296 wxEVT_SCROLL_THUMBRELEASE,
297 (wxObjectEventFunction) (void(wxPanel::*)(
298 wxScrollEvent& )) (&wxManualPaintPanel::OnBrushSize) );this ->Connect (_sldGrayLevel->GetId(),
299 wxEVT_SCROLL_THUMBRELEASE,
300 (wxObjectEventFunction) (void(wxPanel::*)( wxScrollEvent&)) &wxManualPaintPanel::OnSldGrayLevel);
302 this->Connect( _graylevelCtrl->GetId(),
303 wxEVT_COMMAND_TEXT_UPDATED,
304 (wxObjectEventFunction) (void(wxPanel::*)(
305 wxCommandEvent&)) &wxManualPaintPanel::OnCtrTxtGrayLevel);
308 _sldToleranceFill->GetId(),
309 wxEVT_SCROLL_THUMBRELEASE,
310 (wxObjectEventFunction) (void(wxPanel::*)(
311 wxScrollEvent&)) &wxManualPaintPanel::OnSldToleranceFill);this->Connect
313 _tolerancefillCtrl->GetId(),
314 wxEVT_COMMAND_TEXT_UPDATED,
315 (wxObjectEventFunction) (void(wxPanel::*)(
316 wxCommandEvent&)) &wxManualPaintPanel::OnCtrTxtToleranceFill);
319 _sldDistanceFill->GetId(),
320 wxEVT_SCROLL_THUMBRELEASE,
321 (wxObjectEventFunction) (void(wxPanel::*)(
322 wxScrollEvent&)) &wxManualPaintPanel::OnSldDistanceFill);this->Connect
324 _distancefillCtrl->GetId(),
325 wxEVT_COMMAND_TEXT_UPDATED,
326 (wxObjectEventFunction) (void(wxPanel::*)(
327 wxCommandEvent&)) &wxManualPaintPanel::OnCtrTxtDistanceFill);
331 wxEVT_COMMAND_RADIOBOX_SELECTED,
332 (wxObjectEventFunction) (void(wxPanel::*)(
333 wxCommandEvent&)) &wxManualPaintPanel::On2D3D);this->Connect
335 _rbBrushForm->GetId(),
336 wxEVT_COMMAND_RADIOBOX_SELECTED,
337 (wxObjectEventFunction) (void(wxPanel::*)(
338 wxCommandEvent&)) &wxManualPaintPanel::OnBrushForm);this->Connect
340 _rbBrushTool->GetId(),
341 wxEVT_COMMAND_RADIOBOX_SELECTED,
342 (wxObjectEventFunction) (void(wxPanel::*)(
343 wxCommandEvent&)) &wxManualPaintPanel::OnBrushTool);this->Connect
346 wxEVT_COMMAND_BUTTON_CLICKED,
347 (wxObjectEventFunction) (void(wxPanel::*)(
348 wxCommandEvent&)) &wxManualPaintPanel::OnCopy);
352 wxEVT_COMMAND_BUTTON_CLICKED,
353 (wxObjectEventFunction) (void(wxPanel::*)(
354 wxCommandEvent&)) &wxManualPaintPanel::OnUndo);
355 this->Connect(_btnRedo->GetId(),
356 wxEVT_COMMAND_BUTTON_CLICKED,
357 (wxObjectEventFunction) (void(wxPanel::*)(
358 wxCommandEvent&)) &wxManualPaintPanel::OnRedo); //DFCH
361 _mBarSlices->GetId(),
363 (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onBarrange);
364 // Connect(modBarRange->GetId(),98765,(wxObjectEventFunction) (wxCommandEventFunction) &wxWidgetSliderMinMax::onActualChange_Bar );
366 _mBarSlices->GetId(),
368 (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onActualChange_Bar);
370 _mBarSlices->GetId(),
372 (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onStartChange_Bar);
374 _mBarSlices->GetId(),
376 (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onEndChange_Bar);
378 _mBarSlices->GetId(),
380 (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onSelectionEnd);
382 _mBarSlices->GetId(),
384 (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onMovedBar);
387 _BrushSizeCtrl->GetId(),
388 wxEVT_COMMAND_TEXT_UPDATED,
389 (wxObjectEventFunction) (void(wxPanel::*)(
390 wxCommandEvent&)) &wxManualPaintPanel::OnCtrBrushSize);
394 wxEVT_COMMAND_CHECKBOX_CLICKED,
395 (wxObjectEventFunction) (void (wxPanel::*)(wxCommandEvent&))&wxManualPaintPanel::OnActive);
400 //-------------------------------------------------------------------------
401 void wxManualPaintPanel::OnActive(wxCommandEvent& event)
403 printf("EED wxManualPaintPanel::OnActive \n");
404 SetActive( _activeCB->GetValue() );
408 //---------------------------------------------------------------------------
409 void wxManualPaintPanel::OnBrushSize( wxScrollEvent& event )
411 SetBrushSize( this->_sldBrushSize->GetValue( ) );
413 text.Printf( wxT("%d"), this->_sldBrushSize->GetValue( ) );
414 _BrushSizeCtrl->SetValue( text );
417 //---------------------------------------------------------------------------
418 void wxManualPaintPanel::OnSldGrayLevel( wxScrollEvent& event )
420 SetGrayLevel( (double) ( _sldGrayLevel->GetValue( )) );
423 text.Printf( wxT("%d"), _sldGrayLevel->GetValue( ) );
424 _graylevelCtrl->SetValue( text );
427 //---------------------------------------------------------------------------
428 void wxManualPaintPanel::OnCtrTxtGrayLevel( wxCommandEvent &event )
430 int graylevel = this->_graylevelCtrl->GetValue( );
431 this->_sldGrayLevel->SetValue( graylevel );
432 SetGrayLevel( graylevel );
435 //---------------------------------------------------------------------------
436 void wxManualPaintPanel::OnSldDistanceFill( wxScrollEvent& event )
438 SetDistanceFill( (double) ( _sldDistanceFill->GetValue( )) );
441 text.Printf( wxT("%d"), _sldDistanceFill->GetValue( ) );
442 _distancefillCtrl->SetValue( text );
445 //---------------------------------------------------------------------------
446 void wxManualPaintPanel::OnCtrTxtDistanceFill( wxCommandEvent &event )
448 int distancefill = this->_distancefillCtrl->GetValue( );
449 this->_sldDistanceFill->SetValue( distancefill );
450 SetDistanceFill( distancefill );
452 //---------------------------------------------------------------------------
453 void wxManualPaintPanel::OnCtrBrushSize( wxCommandEvent &event )
455 int brushSize = _BrushSizeCtrl->GetValue( );
456 this->_sldBrushSize->SetValue( brushSize );
457 SetBrushSize( brushSize );
460 //---------------------------------------------------------------------------
461 void wxManualPaintPanel::OnSldToleranceFill( wxScrollEvent& event )
463 SetToleranceFill( (double) ( _sldToleranceFill->GetValue( )) );
466 text.Printf( wxT("%d"), _sldToleranceFill->GetValue( ) );
467 _tolerancefillCtrl->SetValue( text );
470 //---------------------------------------------------------------------------
471 void wxManualPaintPanel::OnCtrTxtToleranceFill( wxCommandEvent &event )
473 int tolerance = _tolerancefillCtrl->GetValue( );
474 this->_sldToleranceFill->SetValue( tolerance );
475 SetToleranceFill( tolerance );
478 //---------------------------------------------------------------------------
479 void wxManualPaintPanel::DisableControls( )
481 _txtBrushSize->Disable( );
482 _sldBrushSize->Disable( );
483 _rbBrushForm->Disable( );
485 _txtToleranceFill->Disable( );
486 _sldToleranceFill->Disable( );
487 _tolerancefillCtrl->Disable( );
489 _txtDistanceFill->Disable( );
490 _sldDistanceFill->Disable( );
491 _distancefillCtrl->Disable( );
494 //---------------------------------------------------------------------------
495 void wxManualPaintPanel::On2D3D( wxCommandEvent &event )
497 Set2D3D( _rb2D3D->GetSelection( ) );
500 //---------------------------------------------------------------------------
501 void wxManualPaintPanel::OnBrushForm( wxCommandEvent &event )
503 SetBrushForm( _rbBrushForm->GetSelection( ) );
506 //---------------------------------------------------------------------------
507 void wxManualPaintPanel::OnBrushTool( wxCommandEvent &event )
510 SetTool( _rbBrushTool->GetSelection( ) );
512 if( _rbBrushTool->GetSelection( ) == 0 ) //Brush tool
514 _txtBrushSize->Enable( );
515 _sldBrushSize->Enable( );
516 _rbBrushForm->Enable( );
517 _brushSizer->Show( true );
518 _FillSizer->Show( false );
522 if( _rbBrushTool->GetSelection( ) == 1 ) //Fill tool
524 _txtToleranceFill->Enable( );
525 _sldToleranceFill->Enable( );
526 _tolerancefillCtrl->Enable( );
528 _txtDistanceFill->Enable( );
529 _sldDistanceFill->Enable( );
530 _distancefillCtrl->Enable( );
531 _FillSizer->Show( true );
532 _brushSizer->Show( false );
537 //---------------------------------------------------------------------------
538 void wxManualPaintPanel::OnCopy( wxCommandEvent &event )
542 //---------------------------------------------------------------------------
543 void wxManualPaintPanel::OnUndo( wxCommandEvent &event )
545 this->_manualPaintModel->Undo( );
548 //---------------------------------------------------------------------------
549 void wxManualPaintPanel::OnRedo( wxCommandEvent &event )
551 this->_manualPaintModel->Redo( );
554 //--------------------------------------------------------------------------------------------------------------------------------
555 // Min-Max Barrange received events
556 //--------------------------------------------------------------------------------------------------------------------------------
557 void wxManualPaintPanel::onBarrange( wxCommandEvent& event )
560 void wxManualPaintPanel::onActualChange_Bar( wxCommandEvent& event )
562 /*mbbtkSliderMinMax->bbSetOutputOutActual(modBarRange->GetActual());
563 mbbtkSliderMinMax->bbSignalOutputModification(std::string("OutActual"));*/
565 void wxManualPaintPanel::onStartChange_Bar( wxCommandEvent& event )
567 SetRangeMin( _mBarSlices->GetStart( ) );
570 void wxManualPaintPanel::onEndChange_Bar( wxCommandEvent& event )
572 SetRangeMax( _mBarSlices->GetEnd( ) );
575 void wxManualPaintPanel::onSelectionEnd( wxCommandEvent& event )
579 void wxManualPaintPanel::onMovedBar( wxCommandEvent& event )
582 //-------------------------------------------------------------------------
583 //--------------------------------------------------------------------------
584 //--------------------------------------------------------------------------