Browse Source

Warn user when template field names contain trailing/leading white space.

When loading a schematic that contains fields with trailing/leading white
space, show an infobar message.  When editing the template field names,
prompt the user to keep or remove any trailing or leading white space
characters from field names.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18601

(cherry picked from commit d9d984d2c8)
8.0
Wayne Stambaugh 1 year ago
committed by Seth Hillbrand
parent
commit
710b6adb8c
  1. 35
      eeschema/dialogs/panel_template_fieldnames.cpp
  2. 7
      eeschema/files-io.cpp
  3. 37
      eeschema/sch_screen.cpp
  4. 4
      eeschema/sch_screen.h

35
eeschema/dialogs/panel_template_fieldnames.cpp

@ -22,6 +22,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <wx/msgdlg.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <eeschema_settings.h>
@ -186,10 +188,41 @@ bool PANEL_TEMPLATE_FIELDNAMES::TransferDataFromWindow()
m_templateMgr->DeleteAllFieldNameTemplates( m_global );
for( const TEMPLATE_FIELDNAME& field : m_fields )
for( TEMPLATE_FIELDNAME& field : m_fields )
{
if( !field.m_Name.IsEmpty() )
{
wxString trimmedName = field.m_Name;
trimmedName.Trim();
trimmedName.Trim( false );
// Check if the field name contains leading and/or trailing white space.
if( field.m_Name != trimmedName )
{
wxString msg;
msg.Printf( _( "The field name \"%s\" contains trailing and/or leading white"
"space." ), field.m_Name );
wxMessageDialog dlg( this, msg, _( "Warning" ),
wxOK | wxCANCEL | wxCENTER | wxICON_WARNING );
dlg.SetExtendedMessage( _( "This may result in what appears to be duplicate field "
"names but are actually unique names differing only by "
"white space characters. Removing the white space "
"characters will have no effect on existing symbol "
"field names." ) );
dlg.SetOKCancelLabels( wxMessageDialog::ButtonLabel( _( "Remove White Space" ) ),
wxMessageDialog::ButtonLabel( _( "Keep White Space" ) ) );
if( dlg.ShowModal() == wxID_OK )
field.m_Name = trimmedName;
}
m_templateMgr->AddTemplateFieldName( field, m_global );
}
}
if( m_global )

7
eeschema/files-io.cpp

@ -533,6 +533,13 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
SCH_COMMIT dummy( this );
RecalculateConnections( &dummy, GLOBAL_CLEANUP );
if( schematic.HasSymbolFieldNamesWithWhiteSpace() )
{
m_infoBar->QueueShowMessage( _( "This schematic contains symbols that have leading "
"and/or trailing white space field names." ),
wxICON_WARNING );
}
}
// Load any exclusions from the project file

37
eeschema/sch_screen.cpp

@ -1743,6 +1743,31 @@ void SCH_SCREEN::PruneOrphanedSheetInstances( const wxString& aProjectName,
}
bool SCH_SCREEN::HasSymbolFieldNamesWithWhiteSpace() const
{
wxString trimmedFieldName;
for( const SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
{
const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( item );
wxCHECK2( symbol, continue );
for( const SCH_FIELD& field : symbol->GetFields() )
{
trimmedFieldName = field.GetName();
trimmedFieldName.Trim();
trimmedFieldName.Trim( false );
if( field.GetName() != trimmedFieldName )
return true;
}
}
return false;
}
#if defined(DEBUG)
void SCH_SCREEN::Show( int nestLevel, std::ostream& os ) const
{
@ -2161,3 +2186,15 @@ void SCH_SCREENS::PruneOrphanedSheetInstances( const wxString& aProjectName,
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
screen->PruneOrphanedSheetInstances( aProjectName, aValidSheetPaths );
}
bool SCH_SCREENS::HasSymbolFieldNamesWithWhiteSpace() const
{
for( const SCH_SCREEN* screen : m_screens )
{
if( screen->HasSymbolFieldNamesWithWhiteSpace() )
return true;
}
return false;
}

4
eeschema/sch_screen.h

@ -542,6 +542,8 @@ public:
*/
bool AllSymbolDefaultInstancesNotSet();
bool HasSymbolFieldNamesWithWhiteSpace() const;
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override;
#endif
@ -829,6 +831,8 @@ public:
void PruneOrphanedSheetInstances( const wxString& aProjectName,
const SCH_SHEET_LIST& aValidSheetPaths );
bool HasSymbolFieldNamesWithWhiteSpace() const;
private:
void addScreenToList( SCH_SCREEN* aScreen, SCH_SHEET* aSheet );
void buildScreenList( SCH_SHEET* aSheet);

Loading…
Cancel
Save