From 3ac5fc41cc4c8d6a9f846a859b106da790919ad7 Mon Sep 17 00:00:00 2001 From: Chris Pavlina Date: Sat, 9 Apr 2016 16:17:19 -0400 Subject: [PATCH] Refactor dialog_edit_module_text and nuke the 0.1 degrees --- pcbnew/dialogs/dialog_edit_module_text.cpp | 173 +++++++++--------- pcbnew/dialogs/dialog_edit_module_text.h | 13 +- .../dialogs/dialog_edit_module_text_base.cpp | 6 +- .../dialogs/dialog_edit_module_text_base.fbp | 6 +- pcbnew/dialogs/dialog_edit_module_text_base.h | 4 +- 5 files changed, 102 insertions(+), 100 deletions(-) diff --git a/pcbnew/dialogs/dialog_edit_module_text.cpp b/pcbnew/dialogs/dialog_edit_module_text.cpp index fcc5be912a..63fc539983 100644 --- a/pcbnew/dialogs/dialog_edit_module_text.cpp +++ b/pcbnew/dialogs/dialog_edit_module_text.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -63,7 +64,8 @@ void PCB_BASE_FRAME::InstallTextModOptionsFrame( TEXTE_MODULE* TextMod, wxDC* DC DialogEditModuleText::DialogEditModuleText( PCB_BASE_FRAME* aParent, TEXTE_MODULE* aTextMod, wxDC* aDC ) : - DialogEditModuleText_base( aParent ) + DialogEditModuleText_base( aParent ), + m_OrientValidator( 1, &m_OrientValue, wxNUM_VAL_ZERO_AS_BLANK ) { m_parent = aParent; @@ -71,29 +73,26 @@ DialogEditModuleText::DialogEditModuleText( PCB_BASE_FRAME* aParent, m_module = NULL; m_currentText = aTextMod; + m_OrientValidator.SetRange(-90.0, 90.0); + m_OrientValueCtrl->SetValidator( m_OrientValidator ); + if( m_currentText ) m_module = (MODULE*) m_currentText->GetParent(); - initDlg(); - m_sdbSizer1OK->SetDefault(); GetSizer()->Fit( this ); GetSizer()->SetSizeHints( this ); Centre(); -} - - -void DialogEditModuleText::OnCancelClick( wxCommandEvent& event ) -{ - EndModal( 0 ); -} - - -void DialogEditModuleText::initDlg( ) -{ SetFocus(); +} + + +bool DialogEditModuleText::TransferDataToWindow() +{ + if( !wxDialog::TransferDataToWindow() ) + return false; wxString msg; @@ -136,18 +135,23 @@ void DialogEditModuleText::initDlg( ) m_Style->SetSelection( m_currentText->IsItalic() ? 1 : 0 ); + m_SizeXTitle->SetLabelText( wxEmptyString ); AddUnitSymbol( *m_SizeXTitle ); PutValueInLocalUnits( *m_TxtSizeCtrlX, m_currentText->GetSize().x ); + m_SizeYTitle->SetLabelText( wxEmptyString ); AddUnitSymbol( *m_SizeYTitle ); PutValueInLocalUnits( *m_TxtSizeCtrlY, m_currentText->GetSize().y ); + m_PosXTitle->SetLabelText( wxEmptyString ); AddUnitSymbol( *m_PosXTitle ); PutValueInLocalUnits( *m_TxtPosCtrlX, m_currentText->GetPos0().x ); + m_PosYTitle->SetLabelText( wxEmptyString ); AddUnitSymbol( *m_PosYTitle ); PutValueInLocalUnits( *m_TxtPosCtrlY, m_currentText->GetPos0().y ); + m_WidthTitle->SetLabelText( wxEmptyString ); AddUnitSymbol( *m_WidthTitle ); PutValueInLocalUnits( *m_TxtWidthCtlr, m_currentText->GetThickness() ); @@ -160,7 +164,7 @@ void DialogEditModuleText::initDlg( ) if( !m_currentText->IsVisible() ) m_Show->SetSelection( 1 ); - bool select = false; + bool custom_orientation = false; switch( int( m_currentText->GetOrientation() ) ) { case 0: @@ -179,14 +183,14 @@ void DialogEditModuleText::initDlg( ) default: m_Orient->SetSelection( 3 ); - select = true; + custom_orientation = true; break; } - wxString msg2; - msg2 << m_currentText->GetOrientation(); - m_OrientValue->SetValue( msg2 ); - m_OrientValue->Enable( select ); + wxString orientation_fmt; + orientation_fmt.Printf( _( "%0.1f" ), (double)( m_currentText->GetOrientation() ) / 10.0 ); + m_OrientValueCtrl->SetValue( orientation_fmt ); + m_OrientValueCtrl->Enable( custom_orientation ); // Configure the layers list selector if( !m_parent->GetBoard()->IsLayerEnabled( m_currentText->GetLayer() ) ) @@ -205,36 +209,15 @@ void DialogEditModuleText::initDlg( ) "Now, forced on the front silk screen layer. Please, fix it" ) ); m_LayerSelectionCtrl->SetLayerSelection( F_SilkS ); } + + return true; } -void DialogEditModuleText::ModuleOrientEvent( wxCommandEvent& event ) + +bool DialogEditModuleText::TransferDataFromWindow() { - switch( m_Orient->GetSelection() ) - { - case 0: - m_OrientValue->Enable( false ); - m_OrientValue->SetValue( wxT( "0" ) ); - break; - - case 1: - m_OrientValue->Enable( false ); - m_OrientValue->SetValue( wxT( "900" ) ); - break; - - case 2: - m_OrientValue->Enable( false ); - m_OrientValue->SetValue( wxT( "-900" ) ); - break; - - default: - m_OrientValue->Enable( true ); - break; - } -} - -void DialogEditModuleText::OnOkClick( wxCommandEvent& event ) -{ - wxString msg; + if( !wxDialog::TransferDataFromWindow() ) + return false; if( m_module ) m_parent->SaveCopyInUndoList( m_module, UR_CHANGED ); @@ -252,11 +235,8 @@ void DialogEditModuleText::OnOkClick( wxCommandEvent& event ) wxPoint tmp; - msg = m_TxtPosCtrlX->GetValue(); - tmp.x = ValueFromString( g_UserUnit, msg ); - - msg = m_TxtPosCtrlY->GetValue(); - tmp.y = ValueFromString( g_UserUnit, msg ); + tmp.x = ValueFromString( g_UserUnit, m_TxtPosCtrlX->GetValue() ); + tmp.y = ValueFromString( g_UserUnit, m_TxtPosCtrlY->GetValue() ); m_currentText->SetPos0( tmp ); @@ -270,10 +250,9 @@ void DialogEditModuleText::OnOkClick( wxCommandEvent& event ) if( textSize.y < TEXTS_MIN_SIZE ) textSize.y = TEXTS_MIN_SIZE; - m_currentText->SetSize( textSize ), + m_currentText->SetSize( textSize ); - msg = m_TxtWidthCtlr->GetValue(); - int width = ValueFromString( g_UserUnit, msg ); + int width = ValueFromString( g_UserUnit, m_TxtWidthCtlr->GetValue() ); // Test for a reasonable width: if( width <= 1 ) @@ -292,27 +271,24 @@ void DialogEditModuleText::OnOkClick( wxCommandEvent& event ) m_currentText->SetVisible( m_Show->GetSelection() == 0 ); - bool select = false; + bool custom_orientation = false; switch( m_Orient->GetSelection() ) { - case 0: - m_currentText->SetOrientation( 0 ); - break; + case 0: + m_currentText->SetOrientation( 0 ); + break; - case 1: - m_currentText->SetOrientation( 900 ); - break; + case 1: + m_currentText->SetOrientation( 900 ); + break; - case 2: - m_currentText->SetOrientation( -900 ); - break; + case 2: + m_currentText->SetOrientation( -900 ); + break; - default: - select = true; - long orient = 0; - msg = m_OrientValue->GetValue(); - msg.ToLong( &orient ); - m_currentText->SetOrientation( orient ); + default: + custom_orientation = true; + m_currentText->SetOrientation( KiROUND( m_OrientValue * 10.0 ) ); break; }; @@ -334,23 +310,14 @@ void DialogEditModuleText::OnOkClick( wxCommandEvent& event ) default: m_Orient->SetSelection( 3 ); - long orient = 0; - msg = m_OrientValue->GetValue(); - msg.ToLong( &orient ); - - while( orient < -900 ) - orient += 1800; - - while( orient > 900 ) - orient -= 1800; - - m_currentText->SetOrientation( orient ); - select = true; + m_currentText->SetOrientation( KiROUND( m_OrientValue * 10.0 ) ); + custom_orientation = true; break; } - msg << m_currentText->GetOrientation(); - m_OrientValue->SetValue( msg ); - m_OrientValue->Enable( select ); + m_OrientValue = 10.0 * m_currentText->GetOrientation(); + m_OrientValueCtrl->Enable( custom_orientation ); + m_OrientValidator.SetWindow( m_OrientValueCtrl ); + m_OrientValidator.TransferToWindow(); m_currentText->SetDrawCoord(); @@ -362,7 +329,7 @@ void DialogEditModuleText::OnOkClick( wxCommandEvent& event ) if( m_dc ) // Display new text { m_currentText->Draw( m_parent->GetCanvas(), m_dc, GR_XOR, - (m_currentText->IsMoving()) ? MoveVector : wxPoint( 0, 0 ) ); + (m_currentText->IsMoving()) ? MoveVector : wxPoint( 0, 0 ) ); } #else m_parent->Refresh(); @@ -373,5 +340,35 @@ void DialogEditModuleText::OnOkClick( wxCommandEvent& event ) if( m_module ) m_module->SetLastEditTime(); - EndModal( 1 ); + return true; } + + +void DialogEditModuleText::ModuleOrientEvent( wxCommandEvent& event ) +{ + bool custom_orientation = false; + + switch( m_Orient->GetSelection() ) + { + case 0: + m_OrientValue = 0.0; + break; + + case 1: + m_OrientValue = 90.0; + break; + + case 2: + m_OrientValue = -90.0; + break; + + default: + custom_orientation = true; + break; + } + + m_OrientValidator.SetWindow( m_OrientValueCtrl ); + m_OrientValidator.TransferToWindow(); + m_OrientValueCtrl->Enable( custom_orientation ); +} + diff --git a/pcbnew/dialogs/dialog_edit_module_text.h b/pcbnew/dialogs/dialog_edit_module_text.h index d5a868e287..a9f1e79292 100644 --- a/pcbnew/dialogs/dialog_edit_module_text.h +++ b/pcbnew/dialogs/dialog_edit_module_text.h @@ -4,7 +4,7 @@ * Copyright (C) 2013 Jean-Pierre Charras * Copyright (C) 2013 Dick Hollenbeck, dick@softplc.com * Copyright (C) 2008-2013 Wayne Stambaugh - * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -28,6 +28,7 @@ #define DIALOG_EDIT_MODULE_TEXT_H #include +#include /*************** **************/ /* class DialogEditModuleText */ @@ -40,14 +41,18 @@ private: MODULE* m_module; TEXTE_MODULE* m_currentText; + wxFloatingPointValidator m_OrientValidator; + double m_OrientValue; + public: DialogEditModuleText( PCB_BASE_FRAME* aParent, TEXTE_MODULE* aTextMod, wxDC* aDC ); ~DialogEditModuleText() {}; +protected: + bool TransferDataToWindow(); + bool TransferDataFromWindow(); + private: - void initDlg( ); - void OnOkClick( wxCommandEvent& event ); - void OnCancelClick( wxCommandEvent& event ); void ModuleOrientEvent( wxCommandEvent& event ); }; diff --git a/pcbnew/dialogs/dialog_edit_module_text_base.cpp b/pcbnew/dialogs/dialog_edit_module_text_base.cpp index fbf5c26af5..0efaf0d9ee 100644 --- a/pcbnew/dialogs/dialog_edit_module_text_base.cpp +++ b/pcbnew/dialogs/dialog_edit_module_text_base.cpp @@ -121,12 +121,12 @@ DialogEditModuleText_base::DialogEditModuleText_base( wxWindow* parent, wxWindow m_Orient->SetSelection( 2 ); bSizer4->Add( m_Orient, 1, wxALL|wxEXPAND, 5 ); - m_staticTextRotation = new wxStaticText( this, wxID_ANY, _("Rotation (in 0.1 degrees):"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextRotation = new wxStaticText( this, wxID_ANY, _("Rotation (-90.0 to 90.0)"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextRotation->Wrap( -1 ); bSizer4->Add( m_staticTextRotation, 0, wxEXPAND|wxLEFT|wxTOP, 5 ); - m_OrientValue = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - bSizer4->Add( m_OrientValue, 0, wxALL|wxEXPAND, 5 ); + m_OrientValueCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + bSizer4->Add( m_OrientValueCtrl, 0, wxALL|wxEXPAND, 5 ); bSizer10->Add( bSizer4, 2, wxBOTTOM|wxEXPAND|wxRIGHT, 5 ); diff --git a/pcbnew/dialogs/dialog_edit_module_text_base.fbp b/pcbnew/dialogs/dialog_edit_module_text_base.fbp index 8d31e45782..a729136b69 100644 --- a/pcbnew/dialogs/dialog_edit_module_text_base.fbp +++ b/pcbnew/dialogs/dialog_edit_module_text_base.fbp @@ -44,7 +44,7 @@ DialogEditModuleText_base - 479,413 + 500,401 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER DIALOG_SHIM; dialog_shim.h Footprint Text Properties @@ -1843,7 +1843,7 @@ 0 0 wxID_ANY - Rotation (in 0.1 degrees): + Rotation (-90.0 to 90.0) 0 @@ -1934,7 +1934,7 @@ 0 1 - m_OrientValue + m_OrientValueCtrl 1 diff --git a/pcbnew/dialogs/dialog_edit_module_text_base.h b/pcbnew/dialogs/dialog_edit_module_text_base.h index 2cd6b7dd17..1231f5f6a7 100644 --- a/pcbnew/dialogs/dialog_edit_module_text_base.h +++ b/pcbnew/dialogs/dialog_edit_module_text_base.h @@ -59,7 +59,7 @@ class DialogEditModuleText_base : public DIALOG_SHIM wxRadioBox* m_Style; wxRadioBox* m_Orient; wxStaticText* m_staticTextRotation; - wxTextCtrl* m_OrientValue; + wxTextCtrl* m_OrientValueCtrl; wxStaticLine* m_staticline2; wxStdDialogButtonSizer* m_sdbSizer1; wxButton* m_sdbSizer1OK; @@ -72,7 +72,7 @@ class DialogEditModuleText_base : public DIALOG_SHIM public: - DialogEditModuleText_base( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Footprint Text Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 479,413 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + DialogEditModuleText_base( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Footprint Text Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,401 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DialogEditModuleText_base(); };