Pin Table Dialog: Set the pin parent when creating pins

Removes the possibility of a pin getting created without a parent.
This fixes a bug where the first pin is created without a parent and then trying to reference the parent later causes a segfault.
This commit is contained in:
Kevin Lannen 2022-11-18 12:03:32 -07:00 committed by Jeff Young
parent 83ecd466ae
commit 9e5d96b9d3
1 changed files with 9 additions and 9 deletions

View File

@ -80,11 +80,13 @@ void getSelectedArea( WX_GRID* aGrid, int* aRowStart, int* aRowCount )
class PIN_TABLE_DATA_MODEL : public wxGridTableBase class PIN_TABLE_DATA_MODEL : public wxGridTableBase
{ {
public: public:
PIN_TABLE_DATA_MODEL( SYMBOL_EDIT_FRAME* aFrame, DIALOG_LIB_EDIT_PIN_TABLE* aPinTable ) : PIN_TABLE_DATA_MODEL( SYMBOL_EDIT_FRAME* aFrame, DIALOG_LIB_EDIT_PIN_TABLE* aPinTable,
LIB_SYMBOL* aSymbol ) :
m_frame( aFrame ), m_frame( aFrame ),
m_unitFilter( -1 ), m_unitFilter( -1 ),
m_edited( false ), m_edited( false ),
m_pinTable( aPinTable ) m_pinTable( aPinTable ),
m_symbol( aSymbol )
{ {
m_eval = std::make_unique<NUMERIC_EVALUATOR>( m_frame->GetUserUnits() ); m_eval = std::make_unique<NUMERIC_EVALUATOR>( m_frame->GetUserUnits() );
@ -312,7 +314,7 @@ public:
else else
{ {
// Create new pins // Create new pins
LIB_PIN* newPin = new LIB_PIN( nullptr ); LIB_PIN* newPin = new LIB_PIN( this->m_symbol );
LIB_PIN* last = pins.back(); LIB_PIN* last = pins.back();
newPin->SetNumber( pinName ); newPin->SetNumber( pinName );
@ -321,7 +323,6 @@ public:
newPin->SetType( last->GetType() ); newPin->SetType( last->GetType() );
newPin->SetShape( last->GetShape() ); newPin->SetShape( last->GetShape() );
newPin->SetUnit( last->GetUnit() ); newPin->SetUnit( last->GetUnit() );
newPin->SetParent( last->GetParent() );
VECTOR2I pos = last->GetPosition(); VECTOR2I pos = last->GetPosition();
@ -417,7 +418,7 @@ public:
} }
else else
{ {
for( int i = 1; i <= pin->GetParent()->GetUnitCount(); i++ ) for( int i = 1; i <= m_symbol->GetUnitCount(); i++ )
{ {
if( value == LIB_SYMBOL::SubReference( i, false ) ) if( value == LIB_SYMBOL::SubReference( i, false ) )
{ {
@ -692,6 +693,7 @@ private:
bool m_edited; bool m_edited;
DIALOG_LIB_EDIT_PIN_TABLE* m_pinTable; DIALOG_LIB_EDIT_PIN_TABLE* m_pinTable;
LIB_SYMBOL* m_symbol; // Parent symbol that the pins belong to.
std::unique_ptr<NUMERIC_EVALUATOR> m_eval; std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
std::map< std::pair<LIB_PINS, int>, wxString > m_evalOriginal; std::map< std::pair<LIB_PINS, int>, wxString > m_evalOriginal;
@ -704,7 +706,7 @@ DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( SYMBOL_EDIT_FRAME* parent,
m_editFrame( parent ), m_editFrame( parent ),
m_symbol( aSymbol ) m_symbol( aSymbol )
{ {
m_dataModel = new PIN_TABLE_DATA_MODEL( m_editFrame, this ); m_dataModel = new PIN_TABLE_DATA_MODEL( m_editFrame, this, this->m_symbol );
// Save original columns widths so we can do proportional sizing. // Save original columns widths so we can do proportional sizing.
for( int i = 0; i < COL_COUNT; ++i ) for( int i = 0; i < COL_COUNT; ++i )
@ -891,7 +893,6 @@ bool DIALOG_LIB_EDIT_PIN_TABLE::TransferDataFromWindow()
// Transfer our pins to the part // Transfer our pins to the part
for( LIB_PIN* pin : m_pins ) for( LIB_PIN* pin : m_pins )
{ {
pin->SetParent( m_symbol );
m_symbol->AddDrawItem( pin ); m_symbol->AddDrawItem( pin );
} }
@ -924,7 +925,7 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnAddRow( wxCommandEvent& event )
if( !m_grid->CommitPendingChanges() ) if( !m_grid->CommitPendingChanges() )
return; return;
LIB_PIN* newPin = new LIB_PIN( nullptr ); LIB_PIN* newPin = new LIB_PIN( this->m_symbol );
// Copy the settings of the last pin onto the new pin. // Copy the settings of the last pin onto the new pin.
if( m_pins.size() > 0 ) if( m_pins.size() > 0 )
@ -935,7 +936,6 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnAddRow( wxCommandEvent& event )
newPin->SetType( last->GetType() ); newPin->SetType( last->GetType() );
newPin->SetShape( last->GetShape() ); newPin->SetShape( last->GetShape() );
newPin->SetUnit( last->GetUnit() ); newPin->SetUnit( last->GetUnit() );
newPin->SetParent( last->GetParent() );
VECTOR2I pos = last->GetPosition(); VECTOR2I pos = last->GetPosition();