Refactor dialog_edit_module_text and nuke the 0.1 degrees

This commit is contained in:
Chris Pavlina 2016-04-09 16:17:19 -04:00
parent f12d87b800
commit 3ac5fc41cc
5 changed files with 102 additions and 100 deletions

View File

@ -40,6 +40,7 @@
#include <confirm.h> #include <confirm.h>
#include <wxBasePcbFrame.h> #include <wxBasePcbFrame.h>
#include <base_units.h> #include <base_units.h>
#include <wx/numformatter.h>
#include <class_module.h> #include <class_module.h>
#include <class_text_mod.h> #include <class_text_mod.h>
@ -63,7 +64,8 @@ void PCB_BASE_FRAME::InstallTextModOptionsFrame( TEXTE_MODULE* TextMod, wxDC* DC
DialogEditModuleText::DialogEditModuleText( PCB_BASE_FRAME* aParent, DialogEditModuleText::DialogEditModuleText( PCB_BASE_FRAME* aParent,
TEXTE_MODULE* aTextMod, wxDC* aDC ) : TEXTE_MODULE* aTextMod, wxDC* aDC ) :
DialogEditModuleText_base( aParent ) DialogEditModuleText_base( aParent ),
m_OrientValidator( 1, &m_OrientValue, wxNUM_VAL_ZERO_AS_BLANK )
{ {
m_parent = aParent; m_parent = aParent;
@ -71,29 +73,26 @@ DialogEditModuleText::DialogEditModuleText( PCB_BASE_FRAME* aParent,
m_module = NULL; m_module = NULL;
m_currentText = aTextMod; m_currentText = aTextMod;
m_OrientValidator.SetRange(-90.0, 90.0);
m_OrientValueCtrl->SetValidator( m_OrientValidator );
if( m_currentText ) if( m_currentText )
m_module = (MODULE*) m_currentText->GetParent(); m_module = (MODULE*) m_currentText->GetParent();
initDlg();
m_sdbSizer1OK->SetDefault(); m_sdbSizer1OK->SetDefault();
GetSizer()->Fit( this ); GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this ); GetSizer()->SetSizeHints( this );
Centre(); Centre();
}
void DialogEditModuleText::OnCancelClick( wxCommandEvent& event )
{
EndModal( 0 );
}
void DialogEditModuleText::initDlg( )
{
SetFocus(); SetFocus();
}
bool DialogEditModuleText::TransferDataToWindow()
{
if( !wxDialog::TransferDataToWindow() )
return false;
wxString msg; wxString msg;
@ -136,18 +135,23 @@ void DialogEditModuleText::initDlg( )
m_Style->SetSelection( m_currentText->IsItalic() ? 1 : 0 ); m_Style->SetSelection( m_currentText->IsItalic() ? 1 : 0 );
m_SizeXTitle->SetLabelText( wxEmptyString );
AddUnitSymbol( *m_SizeXTitle ); AddUnitSymbol( *m_SizeXTitle );
PutValueInLocalUnits( *m_TxtSizeCtrlX, m_currentText->GetSize().x ); PutValueInLocalUnits( *m_TxtSizeCtrlX, m_currentText->GetSize().x );
m_SizeYTitle->SetLabelText( wxEmptyString );
AddUnitSymbol( *m_SizeYTitle ); AddUnitSymbol( *m_SizeYTitle );
PutValueInLocalUnits( *m_TxtSizeCtrlY, m_currentText->GetSize().y ); PutValueInLocalUnits( *m_TxtSizeCtrlY, m_currentText->GetSize().y );
m_PosXTitle->SetLabelText( wxEmptyString );
AddUnitSymbol( *m_PosXTitle ); AddUnitSymbol( *m_PosXTitle );
PutValueInLocalUnits( *m_TxtPosCtrlX, m_currentText->GetPos0().x ); PutValueInLocalUnits( *m_TxtPosCtrlX, m_currentText->GetPos0().x );
m_PosYTitle->SetLabelText( wxEmptyString );
AddUnitSymbol( *m_PosYTitle ); AddUnitSymbol( *m_PosYTitle );
PutValueInLocalUnits( *m_TxtPosCtrlY, m_currentText->GetPos0().y ); PutValueInLocalUnits( *m_TxtPosCtrlY, m_currentText->GetPos0().y );
m_WidthTitle->SetLabelText( wxEmptyString );
AddUnitSymbol( *m_WidthTitle ); AddUnitSymbol( *m_WidthTitle );
PutValueInLocalUnits( *m_TxtWidthCtlr, m_currentText->GetThickness() ); PutValueInLocalUnits( *m_TxtWidthCtlr, m_currentText->GetThickness() );
@ -160,7 +164,7 @@ void DialogEditModuleText::initDlg( )
if( !m_currentText->IsVisible() ) if( !m_currentText->IsVisible() )
m_Show->SetSelection( 1 ); m_Show->SetSelection( 1 );
bool select = false; bool custom_orientation = false;
switch( int( m_currentText->GetOrientation() ) ) switch( int( m_currentText->GetOrientation() ) )
{ {
case 0: case 0:
@ -179,14 +183,14 @@ void DialogEditModuleText::initDlg( )
default: default:
m_Orient->SetSelection( 3 ); m_Orient->SetSelection( 3 );
select = true; custom_orientation = true;
break; break;
} }
wxString msg2; wxString orientation_fmt;
msg2 << m_currentText->GetOrientation(); orientation_fmt.Printf( _( "%0.1f" ), (double)( m_currentText->GetOrientation() ) / 10.0 );
m_OrientValue->SetValue( msg2 ); m_OrientValueCtrl->SetValue( orientation_fmt );
m_OrientValue->Enable( select ); m_OrientValueCtrl->Enable( custom_orientation );
// Configure the layers list selector // Configure the layers list selector
if( !m_parent->GetBoard()->IsLayerEnabled( m_currentText->GetLayer() ) ) 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" ) ); "Now, forced on the front silk screen layer. Please, fix it" ) );
m_LayerSelectionCtrl->SetLayerSelection( F_SilkS ); m_LayerSelectionCtrl->SetLayerSelection( F_SilkS );
} }
return true;
} }
void DialogEditModuleText::ModuleOrientEvent( wxCommandEvent& event )
bool DialogEditModuleText::TransferDataFromWindow()
{ {
switch( m_Orient->GetSelection() ) if( !wxDialog::TransferDataFromWindow() )
{ return false;
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( m_module ) if( m_module )
m_parent->SaveCopyInUndoList( m_module, UR_CHANGED ); m_parent->SaveCopyInUndoList( m_module, UR_CHANGED );
@ -252,11 +235,8 @@ void DialogEditModuleText::OnOkClick( wxCommandEvent& event )
wxPoint tmp; wxPoint tmp;
msg = m_TxtPosCtrlX->GetValue(); tmp.x = ValueFromString( g_UserUnit, m_TxtPosCtrlX->GetValue() );
tmp.x = ValueFromString( g_UserUnit, msg ); tmp.y = ValueFromString( g_UserUnit, m_TxtPosCtrlY->GetValue() );
msg = m_TxtPosCtrlY->GetValue();
tmp.y = ValueFromString( g_UserUnit, msg );
m_currentText->SetPos0( tmp ); m_currentText->SetPos0( tmp );
@ -270,10 +250,9 @@ void DialogEditModuleText::OnOkClick( wxCommandEvent& event )
if( textSize.y < TEXTS_MIN_SIZE ) if( textSize.y < TEXTS_MIN_SIZE )
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, m_TxtWidthCtlr->GetValue() );
int width = ValueFromString( g_UserUnit, msg );
// Test for a reasonable width: // Test for a reasonable width:
if( width <= 1 ) if( width <= 1 )
@ -292,27 +271,24 @@ void DialogEditModuleText::OnOkClick( wxCommandEvent& event )
m_currentText->SetVisible( m_Show->GetSelection() == 0 ); m_currentText->SetVisible( m_Show->GetSelection() == 0 );
bool select = false; bool custom_orientation = false;
switch( m_Orient->GetSelection() ) switch( m_Orient->GetSelection() )
{ {
case 0: case 0:
m_currentText->SetOrientation( 0 ); m_currentText->SetOrientation( 0 );
break; break;
case 1: case 1:
m_currentText->SetOrientation( 900 ); m_currentText->SetOrientation( 900 );
break; break;
case 2: case 2:
m_currentText->SetOrientation( -900 ); m_currentText->SetOrientation( -900 );
break; break;
default: default:
select = true; custom_orientation = true;
long orient = 0; m_currentText->SetOrientation( KiROUND( m_OrientValue * 10.0 ) );
msg = m_OrientValue->GetValue();
msg.ToLong( &orient );
m_currentText->SetOrientation( orient );
break; break;
}; };
@ -334,23 +310,14 @@ void DialogEditModuleText::OnOkClick( wxCommandEvent& event )
default: default:
m_Orient->SetSelection( 3 ); m_Orient->SetSelection( 3 );
long orient = 0; m_currentText->SetOrientation( KiROUND( m_OrientValue * 10.0 ) );
msg = m_OrientValue->GetValue(); custom_orientation = true;
msg.ToLong( &orient );
while( orient < -900 )
orient += 1800;
while( orient > 900 )
orient -= 1800;
m_currentText->SetOrientation( orient );
select = true;
break; break;
} }
msg << m_currentText->GetOrientation(); m_OrientValue = 10.0 * m_currentText->GetOrientation();
m_OrientValue->SetValue( msg ); m_OrientValueCtrl->Enable( custom_orientation );
m_OrientValue->Enable( select ); m_OrientValidator.SetWindow( m_OrientValueCtrl );
m_OrientValidator.TransferToWindow();
m_currentText->SetDrawCoord(); m_currentText->SetDrawCoord();
@ -362,7 +329,7 @@ void DialogEditModuleText::OnOkClick( wxCommandEvent& event )
if( m_dc ) // Display new text if( m_dc ) // Display new text
{ {
m_currentText->Draw( m_parent->GetCanvas(), m_dc, GR_XOR, 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 #else
m_parent->Refresh(); m_parent->Refresh();
@ -373,5 +340,35 @@ void DialogEditModuleText::OnOkClick( wxCommandEvent& event )
if( m_module ) if( m_module )
m_module->SetLastEditTime(); 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 );
}

View File

@ -4,7 +4,7 @@
* Copyright (C) 2013 Jean-Pierre Charras * Copyright (C) 2013 Jean-Pierre Charras
* Copyright (C) 2013 Dick Hollenbeck, dick@softplc.com * Copyright (C) 2013 Dick Hollenbeck, dick@softplc.com
* Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
* 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -28,6 +28,7 @@
#define DIALOG_EDIT_MODULE_TEXT_H #define DIALOG_EDIT_MODULE_TEXT_H
#include <dialog_edit_module_text_base.h> #include <dialog_edit_module_text_base.h>
#include <wx/valnum.h>
/*************** **************/ /*************** **************/
/* class DialogEditModuleText */ /* class DialogEditModuleText */
@ -40,14 +41,18 @@ private:
MODULE* m_module; MODULE* m_module;
TEXTE_MODULE* m_currentText; TEXTE_MODULE* m_currentText;
wxFloatingPointValidator<double> m_OrientValidator;
double m_OrientValue;
public: public:
DialogEditModuleText( PCB_BASE_FRAME* aParent, TEXTE_MODULE* aTextMod, wxDC* aDC ); DialogEditModuleText( PCB_BASE_FRAME* aParent, TEXTE_MODULE* aTextMod, wxDC* aDC );
~DialogEditModuleText() {}; ~DialogEditModuleText() {};
protected:
bool TransferDataToWindow();
bool TransferDataFromWindow();
private: private:
void initDlg( );
void OnOkClick( wxCommandEvent& event );
void OnCancelClick( wxCommandEvent& event );
void ModuleOrientEvent( wxCommandEvent& event ); void ModuleOrientEvent( wxCommandEvent& event );
}; };

View File

@ -121,12 +121,12 @@ DialogEditModuleText_base::DialogEditModuleText_base( wxWindow* parent, wxWindow
m_Orient->SetSelection( 2 ); m_Orient->SetSelection( 2 );
bSizer4->Add( m_Orient, 1, wxALL|wxEXPAND, 5 ); 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 ); m_staticTextRotation->Wrap( -1 );
bSizer4->Add( m_staticTextRotation, 0, wxEXPAND|wxLEFT|wxTOP, 5 ); bSizer4->Add( m_staticTextRotation, 0, wxEXPAND|wxLEFT|wxTOP, 5 );
m_OrientValue = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); m_OrientValueCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
bSizer4->Add( m_OrientValue, 0, wxALL|wxEXPAND, 5 ); bSizer4->Add( m_OrientValueCtrl, 0, wxALL|wxEXPAND, 5 );
bSizer10->Add( bSizer4, 2, wxBOTTOM|wxEXPAND|wxRIGHT, 5 ); bSizer10->Add( bSizer4, 2, wxBOTTOM|wxEXPAND|wxRIGHT, 5 );

View File

@ -44,7 +44,7 @@
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="name">DialogEditModuleText_base</property> <property name="name">DialogEditModuleText_base</property>
<property name="pos"></property> <property name="pos"></property>
<property name="size">479,413</property> <property name="size">500,401</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property> <property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property> <property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">Footprint Text Properties</property> <property name="title">Footprint Text Properties</property>
@ -1843,7 +1843,7 @@
<property name="gripper">0</property> <property name="gripper">0</property>
<property name="hidden">0</property> <property name="hidden">0</property>
<property name="id">wxID_ANY</property> <property name="id">wxID_ANY</property>
<property name="label">Rotation (in 0.1 degrees):</property> <property name="label">Rotation (-90.0 to 90.0)</property>
<property name="max_size"></property> <property name="max_size"></property>
<property name="maximize_button">0</property> <property name="maximize_button">0</property>
<property name="maximum_size"></property> <property name="maximum_size"></property>
@ -1934,7 +1934,7 @@
<property name="minimize_button">0</property> <property name="minimize_button">0</property>
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="moveable">1</property> <property name="moveable">1</property>
<property name="name">m_OrientValue</property> <property name="name">m_OrientValueCtrl</property>
<property name="pane_border">1</property> <property name="pane_border">1</property>
<property name="pane_position"></property> <property name="pane_position"></property>
<property name="pane_size"></property> <property name="pane_size"></property>

View File

@ -59,7 +59,7 @@ class DialogEditModuleText_base : public DIALOG_SHIM
wxRadioBox* m_Style; wxRadioBox* m_Style;
wxRadioBox* m_Orient; wxRadioBox* m_Orient;
wxStaticText* m_staticTextRotation; wxStaticText* m_staticTextRotation;
wxTextCtrl* m_OrientValue; wxTextCtrl* m_OrientValueCtrl;
wxStaticLine* m_staticline2; wxStaticLine* m_staticline2;
wxStdDialogButtonSizer* m_sdbSizer1; wxStdDialogButtonSizer* m_sdbSizer1;
wxButton* m_sdbSizer1OK; wxButton* m_sdbSizer1OK;
@ -72,7 +72,7 @@ class DialogEditModuleText_base : public DIALOG_SHIM
public: 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(); ~DialogEditModuleText_base();
}; };