Clean up pointer casting

* Make note of when dynamic cast is actually needed
* Convert some to static cast when we know the type for sure
This commit is contained in:
Ian McInerney 2020-01-12 19:45:37 +00:00
parent 4ffbefb9dc
commit b445ce6632
3 changed files with 15 additions and 12 deletions

View File

@ -70,7 +70,8 @@ void GRID_CELL_TEXT_BUTTON::StartingKey( wxKeyEvent& event )
// Do it ourselves instead. We know that if we get this far that we have
// a valid character, so not a whole lot of testing needs to be done.
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( Combo() );
// wxComboCtrl inherits from wxTextEntry, so can staticly cast
wxTextEntry* textEntry = static_cast<wxTextEntry*>( Combo() );
int ch;
bool isPrintable;

View File

@ -46,6 +46,8 @@ DIALOG_EDIT_ONE_FIELD::DIALOG_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent, const wxS
m_posY( aParent, m_yPosLabel, m_yPosCtrl, m_yPosUnits, true ),
m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true )
{
wxASSERT( aTextItem );
SetTitle( aTitle );
// The field ID and power status are Initialized in the derived object's ctor.
@ -201,10 +203,9 @@ void DIALOG_EDIT_ONE_FIELD::updateText( EDA_TEXT* aText )
}
DIALOG_LIB_EDIT_ONE_FIELD::DIALOG_LIB_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent,
const wxString& aTitle,
const LIB_FIELD* aField ) :
DIALOG_EDIT_ONE_FIELD( aParent, aTitle, dynamic_cast< const EDA_TEXT* >( aField ) )
DIALOG_LIB_EDIT_ONE_FIELD::DIALOG_LIB_EDIT_ONE_FIELD(
SCH_BASE_FRAME* aParent, const wxString& aTitle, const LIB_FIELD* aField )
: DIALOG_EDIT_ONE_FIELD( aParent, aTitle, static_cast<const EDA_TEXT*>( aField ) )
{
m_fieldId = aField->GetId();
@ -214,10 +215,9 @@ DIALOG_LIB_EDIT_ONE_FIELD::DIALOG_LIB_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent,
}
DIALOG_SCH_EDIT_ONE_FIELD::DIALOG_SCH_EDIT_ONE_FIELD( SCH_BASE_FRAME* aParent,
const wxString& aTitle,
const SCH_FIELD* aField ) :
DIALOG_EDIT_ONE_FIELD( aParent, aTitle, dynamic_cast< const EDA_TEXT* >( aField ) )
DIALOG_SCH_EDIT_ONE_FIELD::DIALOG_SCH_EDIT_ONE_FIELD(
SCH_BASE_FRAME* aParent, const wxString& aTitle, const SCH_FIELD* aField )
: DIALOG_EDIT_ONE_FIELD( aParent, aTitle, static_cast<const EDA_TEXT*>( aField ) )
{
m_fieldId = aField->GetId();
@ -242,11 +242,11 @@ void DIALOG_SCH_EDIT_ONE_FIELD::UpdateField( SCH_FIELD* aField, SCH_SHEET_PATH*
{
if( aField->GetId() == REFERENCE )
{
wxASSERT( aSheetPath );
wxASSERT( aSheetPath );
SCH_COMPONENT* component = dynamic_cast< SCH_COMPONENT* >( aField->GetParent() );
wxASSERT( component );
wxASSERT( component );
if( component )
component->SetRef( aSheetPath, m_text );

View File

@ -369,6 +369,8 @@ bool DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataFromWindow()
{
if( boardItem->Type() == PCB_MODULE_TEXT_T )
{
// We are guaranteed to always get an EDA_TEXT in this statement, but we must
// use the dynamic_cast to move through the type tree anyway.
const wxString text = dynamic_cast<EDA_TEXT*>( boardItem )->GetText();
if( m_references->GetValue() && text == wxT( "%R" ) )
@ -412,7 +414,7 @@ int GLOBAL_EDIT_TOOL::EditTextAndGraphics( const TOOL_EVENT& aEvent )
{
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS dlg( editFrame );
dlg.ShowModal();
return 0;
}