diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 8611ec6f38..c65f5f6b1b 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -163,6 +163,13 @@ PGM_BASE& Pgm() return *process; } +// Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face is run from +// a python script or something else. +PGM_BASE* PgmOrNull() +{ + return process; +} + bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) { diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index 099de9c491..38b5e1bbd2 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -153,10 +153,23 @@ LIB_PIN::LIB_PIN( LIB_PART* aParent ) m_attributes = 0; // bit 0 != 0: pin invisible m_width = 0; - LIBEDIT_SETTINGS* settings = Pgm().GetSettingsManager().GetAppSettings(); - m_length = Mils2iu( settings->m_Defaults.pin_length ); - m_numTextSize = Mils2iu( settings->m_Defaults.pin_num_size ); - m_nameTextSize = Mils2iu( settings->m_Defaults.pin_name_size ); + // Use the application settings for pin sizes if exists. + // pgm can be nullptr when running a shared lib from a script, not from a kicad appl + PGM_BASE* pgm = PgmOrNull(); + + if( pgm ) + { + LIBEDIT_SETTINGS* settings = pgm->GetSettingsManager().GetAppSettings(); + m_length = Mils2iu( settings->m_Defaults.pin_length ); + m_numTextSize = Mils2iu( settings->m_Defaults.pin_num_size ); + m_nameTextSize = Mils2iu( settings->m_Defaults.pin_name_size ); + } + else // Use hardcoded eeschema defaults: libedit settings are not existing. + { + m_length = Mils2iu( 100 ); + m_numTextSize = Mils2iu( 50 ); + m_nameTextSize = Mils2iu( 50 ); + } } diff --git a/qa/eeschema/mocks_eeschema.cpp b/qa/eeschema/mocks_eeschema.cpp index cd50c44b50..5aa9bf1b5c 100644 --- a/qa/eeschema/mocks_eeschema.cpp +++ b/qa/eeschema/mocks_eeschema.cpp @@ -113,6 +113,14 @@ PGM_BASE& Pgm() return program; } +// Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face is run from +// a python script or something else. +// Therefore here return always nullptr +PGM_BASE* PgmOrNull() +{ + return nullptr; +} + KIFACE_I& Kiface() {