REMOVED new footprint dialog.

We now just create an "Untitled" footprint.

Also fixes a bug where the preview of new footprints
would zoom in too far.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17573
This commit is contained in:
Jeff Young 2024-05-31 10:17:17 +01:00
parent 015b93b474
commit 1eb26b439a
9 changed files with 53 additions and 92 deletions

View File

@ -267,10 +267,8 @@ public:
*
* @param aFootprintName is the name of the new footprint in library.
* @param aLibName optional, if specified is the library for the new footprint
* @param aQuiet prevents user dialogs from being shown
*/
FOOTPRINT* CreateNewFootprint( const wxString& aFootprintName, const wxString& aLibName,
bool aQuiet );
FOOTPRINT* CreateNewFootprint( wxString aFootprintName, const wxString& aLibName );
/**
* Places \a aFootprint at the current cursor position and updates footprint coordinates

View File

@ -1220,6 +1220,21 @@ BOX2I FOOTPRINT::GetFpPadsLocalBbox() const
}
bool FOOTPRINT::TextOnly() const
{
for( BOARD_ITEM* item : m_drawings )
{
if( m_privateLayers.test( item->GetLayer() ) )
continue;
if( item->Type() != PCB_FIELD_T && item->Type() != PCB_TEXT_T )
return false;
}
return true;
}
const BOX2I FOOTPRINT::GetBoundingBox() const
{
return GetBoundingBox( true, true );

View File

@ -171,6 +171,8 @@ public:
*/
SHAPE_POLY_SET GetBoundingHull() const;
bool TextOnly() const;
// Virtual function
const BOX2I GetBoundingBox() const override;
const BOX2I GetBoundingBox( bool aIncludeText, bool aIncludeInvisibleText ) const;

View File

@ -26,7 +26,6 @@
#include <kiface_base.h>
#include <confirm.h>
#include <kidialog.h>
#include <string_utils.h>
#include <macros.h>
#include <pcb_edit_frame.h>
#include <eda_list_dialog.h>
@ -41,10 +40,8 @@
#include <footprint.h>
#include <zone.h>
#include <pcb_group.h>
#include <board_commit.h>
#include <footprint_edit_frame.h>
#include <wildcards_and_files_ext.h>
#include <pcb_io/kicad_legacy/pcb_io_kicad_legacy.h>
#include <pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h>
#include <env_paths.h>
#include <paths.h>
@ -1229,97 +1226,45 @@ bool FOOTPRINT_EDIT_FRAME::RevertFootprint()
}
class NEW_FP_DIALOG : public WX_TEXT_ENTRY_DIALOG
FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( wxString aFootprintName, const wxString& aLibName )
{
public:
NEW_FP_DIALOG( PCB_BASE_FRAME* aParent, const wxString& aName, int aFootprintType,
std::function<bool( wxString newName )> aValidator ) :
WX_TEXT_ENTRY_DIALOG( aParent, _( "Enter footprint name:" ), _( "New Footprint" ),
aName, _( "Footprint type:" ),
{ _( "Through hole" ), _( "SMD" ), _( "Other" ) },
aFootprintType ),
m_validator( std::move( aValidator ) )
{ }
if( aFootprintName.IsEmpty() )
aFootprintName = _( "Untitled" );
wxString GetFPName()
int footprintAttrs = FP_SMD;
if( !aLibName.IsEmpty() )
{
wxString name = m_textCtrl->GetValue();
name.Trim( true ).Trim( false );
return name;
}
FP_LIB_TABLE* tbl = PROJECT_PCB::PcbFootprintLibs( &Prj() );
wxArrayString fpnames;
wxString baseName = aFootprintName;
int idx = 1;
protected:
bool TransferDataFromWindow() override
{
return m_validator( GetFPName() );
}
// Make sure the name is unique
while( tbl->FootprintExists( aLibName, aFootprintName ) )
aFootprintName = baseName + wxString::Format( wxS( "_%d" ), idx++ );
private:
std::function<bool( wxString newName )> m_validator;
};
FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( const wxString& aFootprintName,
const wxString& aLibName, bool aQuiet )
{
FP_LIB_TABLE* tbl = PROJECT_PCB::PcbFootprintLibs( &Prj() );
wxString footprintName = aFootprintName;
wxString msg;
// Static to store user preference for a session
static int footprintType = 1;
int footprintTranslated = FP_SMD;
// Ask for the new footprint name
if( footprintName.IsEmpty() && !aQuiet )
{
NEW_FP_DIALOG dlg( this, footprintName, footprintType,
[&]( wxString newName )
{
if( newName.IsEmpty() )
{
wxMessageBox( _( "Footprint must have a name." ) );
return false;
}
if( !aLibName.IsEmpty() && tbl->FootprintExists( aLibName, newName ) )
{
msg = wxString::Format( _( "Footprint '%s' already exists in library '%s'." ),
newName, aLibName );
KIDIALOG errorDlg( this, msg, _( "Confirmation" ),
wxOK | wxCANCEL | wxICON_WARNING );
errorDlg.SetOKLabel( _( "Overwrite" ) );
return errorDlg.ShowModal() == wxID_OK;
}
return true;
} );
dlg.SetTextValidator( FOOTPRINT_NAME_VALIDATOR( &footprintName ) );
if( dlg.ShowModal() != wxID_OK )
return nullptr; //Aborted by user
footprintName = dlg.GetFPName();
footprintType = dlg.GetChoice();
switch( footprintType )
// Try to infer the footprint attributes from an existing footprint in the library
try
{
case 0: footprintTranslated = FP_THROUGH_HOLE; break;
case 1: footprintTranslated = FP_SMD; break;
default: footprintTranslated = 0; break;
tbl->FootprintEnumerate( fpnames, aLibName, true );
if( !fpnames.empty() )
footprintAttrs = tbl->FootprintLoad( aLibName, fpnames.Last() )->GetAttributes();
}
catch( ... )
{
// best efforts
}
}
// Creates the new footprint and add it to the head of the linked list of footprints
// Create the new footprint and add it to the head of the linked list of footprints
FOOTPRINT* footprint = new FOOTPRINT( GetBoard() );
// Update its name in lib
footprint->SetFPID( LIB_ID( wxEmptyString, footprintName ) );
footprint->SetFPID( LIB_ID( wxEmptyString, aFootprintName ) );
footprint->SetAttributes( footprintTranslated );
footprint->SetAttributes( footprintAttrs );
PCB_LAYER_ID txt_layer;
VECTOR2I default_pos;
@ -1355,10 +1300,10 @@ FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( const wxString& aFootprintName,
}
if( footprint->GetReference().IsEmpty() )
footprint->SetReference( footprintName );
footprint->SetReference( aFootprintName );
if( footprint->GetValue().IsEmpty() )
footprint->SetValue( footprintName );
footprint->SetValue( aFootprintName );
footprint->RunOnDescendants(
[&]( BOARD_ITEM* aChild )

View File

@ -143,7 +143,8 @@ void FOOTPRINT_PREVIEW_PANEL::renderFootprint( std::shared_ptr<FOOTPRINT> aFootp
void FOOTPRINT_PREVIEW_PANEL::fitToCurrentFootprint()
{
BOX2I bbox = m_currentFootprint->GetBoundingBox( false, false );
bool includeText = m_currentFootprint->TextOnly();
BOX2I bbox = m_currentFootprint->GetBoundingBox( includeText, false );
if( bbox.GetSize().x > 0 && bbox.GetSize().y > 0 )
{

View File

@ -194,7 +194,7 @@ FOOTPRINT* MICROWAVE_TOOL::createBaseFootprint( const wxString& aValue,
{
PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
FOOTPRINT* footprint = editFrame.CreateNewFootprint( aValue, wxEmptyString, true );
FOOTPRINT* footprint = editFrame.CreateNewFootprint( aValue, wxEmptyString );
footprint->SetAttributes( FP_EXCLUDE_FROM_POS_FILES | FP_EXCLUDE_FROM_BOM );

View File

@ -409,7 +409,7 @@ FOOTPRINT* MICROWAVE_TOOL::createMicrowaveInductor( MICROWAVE_INDUCTOR_PATTERN&
if( ( cmpdlg.ShowQuasiModal() != wxID_OK ) || msg.IsEmpty() )
return nullptr; // Aborted by user
FOOTPRINT* footprint = editFrame->CreateNewFootprint( msg, wxEmptyString, true );
FOOTPRINT* footprint = editFrame->CreateNewFootprint( msg, wxEmptyString );
footprint->SetFPID( LIB_ID( wxEmptyString, wxT( "mw_inductor" ) ) );
footprint->SetAttributes( FP_EXCLUDE_FROM_POS_FILES | FP_EXCLUDE_FROM_BOM );

View File

@ -171,9 +171,9 @@ bool FOOTPRINT_EDITOR_CONTROL::Init()
int FOOTPRINT_EDITOR_CONTROL::NewFootprint( const TOOL_EVENT& aEvent )
{
LIB_ID selected = m_frame->GetTreeFPID();
LIB_ID selected = m_frame->GetTargetFPID();
wxString libraryName = selected.GetUniStringLibNickname();
FOOTPRINT* newFootprint = m_frame->CreateNewFootprint( wxEmptyString, libraryName, false );
FOOTPRINT* newFootprint = m_frame->CreateNewFootprint( wxEmptyString, libraryName );
if( !newFootprint )
return 0;

View File

@ -708,7 +708,7 @@ TOOL_ACTION PCB_ACTIONS::newFootprint( TOOL_ACTION_ARGS()
.Scope( AS_GLOBAL )
.DefaultHotkey( MD_CTRL + 'N' )
.LegacyHotkeyName( "New" )
.FriendlyName( _( "New Footprint..." ) )
.FriendlyName( _( "New Footprint" ) )
.Tooltip( _( "Create a new, empty footprint" ) )
.Icon( BITMAPS::new_footprint ) );