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:
parent
015b93b474
commit
1eb26b439a
|
@ -267,10 +267,8 @@ public:
|
||||||
*
|
*
|
||||||
* @param aFootprintName is the name of the new footprint in library.
|
* @param aFootprintName is the name of the new footprint in library.
|
||||||
* @param aLibName optional, if specified is the library for the new footprint
|
* @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,
|
FOOTPRINT* CreateNewFootprint( wxString aFootprintName, const wxString& aLibName );
|
||||||
bool aQuiet );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places \a aFootprint at the current cursor position and updates footprint coordinates
|
* Places \a aFootprint at the current cursor position and updates footprint coordinates
|
||||||
|
|
|
@ -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
|
const BOX2I FOOTPRINT::GetBoundingBox() const
|
||||||
{
|
{
|
||||||
return GetBoundingBox( true, true );
|
return GetBoundingBox( true, true );
|
||||||
|
|
|
@ -171,6 +171,8 @@ public:
|
||||||
*/
|
*/
|
||||||
SHAPE_POLY_SET GetBoundingHull() const;
|
SHAPE_POLY_SET GetBoundingHull() const;
|
||||||
|
|
||||||
|
bool TextOnly() const;
|
||||||
|
|
||||||
// Virtual function
|
// Virtual function
|
||||||
const BOX2I GetBoundingBox() const override;
|
const BOX2I GetBoundingBox() const override;
|
||||||
const BOX2I GetBoundingBox( bool aIncludeText, bool aIncludeInvisibleText ) const;
|
const BOX2I GetBoundingBox( bool aIncludeText, bool aIncludeInvisibleText ) const;
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include <kiface_base.h>
|
#include <kiface_base.h>
|
||||||
#include <confirm.h>
|
#include <confirm.h>
|
||||||
#include <kidialog.h>
|
#include <kidialog.h>
|
||||||
#include <string_utils.h>
|
|
||||||
#include <macros.h>
|
#include <macros.h>
|
||||||
#include <pcb_edit_frame.h>
|
#include <pcb_edit_frame.h>
|
||||||
#include <eda_list_dialog.h>
|
#include <eda_list_dialog.h>
|
||||||
|
@ -41,10 +40,8 @@
|
||||||
#include <footprint.h>
|
#include <footprint.h>
|
||||||
#include <zone.h>
|
#include <zone.h>
|
||||||
#include <pcb_group.h>
|
#include <pcb_group.h>
|
||||||
#include <board_commit.h>
|
|
||||||
#include <footprint_edit_frame.h>
|
#include <footprint_edit_frame.h>
|
||||||
#include <wildcards_and_files_ext.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 <pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h>
|
||||||
#include <env_paths.h>
|
#include <env_paths.h>
|
||||||
#include <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:
|
if( aFootprintName.IsEmpty() )
|
||||||
NEW_FP_DIALOG( PCB_BASE_FRAME* aParent, const wxString& aName, int aFootprintType,
|
aFootprintName = _( "Untitled" );
|
||||||
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 ) )
|
|
||||||
{ }
|
|
||||||
|
|
||||||
wxString GetFPName()
|
int footprintAttrs = FP_SMD;
|
||||||
|
|
||||||
|
if( !aLibName.IsEmpty() )
|
||||||
{
|
{
|
||||||
wxString name = m_textCtrl->GetValue();
|
|
||||||
name.Trim( true ).Trim( false );
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool TransferDataFromWindow() override
|
|
||||||
{
|
|
||||||
return m_validator( GetFPName() );
|
|
||||||
}
|
|
||||||
|
|
||||||
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() );
|
FP_LIB_TABLE* tbl = PROJECT_PCB::PcbFootprintLibs( &Prj() );
|
||||||
wxString footprintName = aFootprintName;
|
wxArrayString fpnames;
|
||||||
wxString msg;
|
wxString baseName = aFootprintName;
|
||||||
|
int idx = 1;
|
||||||
|
|
||||||
// Static to store user preference for a session
|
// Make sure the name is unique
|
||||||
static int footprintType = 1;
|
while( tbl->FootprintExists( aLibName, aFootprintName ) )
|
||||||
int footprintTranslated = FP_SMD;
|
aFootprintName = baseName + wxString::Format( wxS( "_%d" ), idx++ );
|
||||||
|
|
||||||
// Ask for the new footprint name
|
// Try to infer the footprint attributes from an existing footprint in the library
|
||||||
if( footprintName.IsEmpty() && !aQuiet )
|
try
|
||||||
{
|
{
|
||||||
NEW_FP_DIALOG dlg( this, footprintName, footprintType,
|
tbl->FootprintEnumerate( fpnames, aLibName, true );
|
||||||
[&]( wxString newName )
|
|
||||||
{
|
if( !fpnames.empty() )
|
||||||
if( newName.IsEmpty() )
|
footprintAttrs = tbl->FootprintLoad( aLibName, fpnames.Last() )->GetAttributes();
|
||||||
{
|
|
||||||
wxMessageBox( _( "Footprint must have a name." ) );
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
catch( ... )
|
||||||
if( !aLibName.IsEmpty() && tbl->FootprintExists( aLibName, newName ) )
|
|
||||||
{
|
{
|
||||||
msg = wxString::Format( _( "Footprint '%s' already exists in library '%s'." ),
|
// best efforts
|
||||||
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 )
|
|
||||||
{
|
|
||||||
case 0: footprintTranslated = FP_THROUGH_HOLE; break;
|
|
||||||
case 1: footprintTranslated = FP_SMD; break;
|
|
||||||
default: footprintTranslated = 0; break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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() );
|
FOOTPRINT* footprint = new FOOTPRINT( GetBoard() );
|
||||||
|
|
||||||
// Update its name in lib
|
// 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;
|
PCB_LAYER_ID txt_layer;
|
||||||
VECTOR2I default_pos;
|
VECTOR2I default_pos;
|
||||||
|
@ -1355,10 +1300,10 @@ FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( const wxString& aFootprintName,
|
||||||
}
|
}
|
||||||
|
|
||||||
if( footprint->GetReference().IsEmpty() )
|
if( footprint->GetReference().IsEmpty() )
|
||||||
footprint->SetReference( footprintName );
|
footprint->SetReference( aFootprintName );
|
||||||
|
|
||||||
if( footprint->GetValue().IsEmpty() )
|
if( footprint->GetValue().IsEmpty() )
|
||||||
footprint->SetValue( footprintName );
|
footprint->SetValue( aFootprintName );
|
||||||
|
|
||||||
footprint->RunOnDescendants(
|
footprint->RunOnDescendants(
|
||||||
[&]( BOARD_ITEM* aChild )
|
[&]( BOARD_ITEM* aChild )
|
||||||
|
|
|
@ -143,7 +143,8 @@ void FOOTPRINT_PREVIEW_PANEL::renderFootprint( std::shared_ptr<FOOTPRINT> aFootp
|
||||||
|
|
||||||
void FOOTPRINT_PREVIEW_PANEL::fitToCurrentFootprint()
|
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 )
|
if( bbox.GetSize().x > 0 && bbox.GetSize().y > 0 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -194,7 +194,7 @@ FOOTPRINT* MICROWAVE_TOOL::createBaseFootprint( const wxString& aValue,
|
||||||
{
|
{
|
||||||
PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
|
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 );
|
footprint->SetAttributes( FP_EXCLUDE_FROM_POS_FILES | FP_EXCLUDE_FROM_BOM );
|
||||||
|
|
||||||
|
|
|
@ -409,7 +409,7 @@ FOOTPRINT* MICROWAVE_TOOL::createMicrowaveInductor( MICROWAVE_INDUCTOR_PATTERN&
|
||||||
if( ( cmpdlg.ShowQuasiModal() != wxID_OK ) || msg.IsEmpty() )
|
if( ( cmpdlg.ShowQuasiModal() != wxID_OK ) || msg.IsEmpty() )
|
||||||
return nullptr; // Aborted by user
|
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->SetFPID( LIB_ID( wxEmptyString, wxT( "mw_inductor" ) ) );
|
||||||
footprint->SetAttributes( FP_EXCLUDE_FROM_POS_FILES | FP_EXCLUDE_FROM_BOM );
|
footprint->SetAttributes( FP_EXCLUDE_FROM_POS_FILES | FP_EXCLUDE_FROM_BOM );
|
||||||
|
|
|
@ -171,9 +171,9 @@ bool FOOTPRINT_EDITOR_CONTROL::Init()
|
||||||
|
|
||||||
int FOOTPRINT_EDITOR_CONTROL::NewFootprint( const TOOL_EVENT& aEvent )
|
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();
|
wxString libraryName = selected.GetUniStringLibNickname();
|
||||||
FOOTPRINT* newFootprint = m_frame->CreateNewFootprint( wxEmptyString, libraryName, false );
|
FOOTPRINT* newFootprint = m_frame->CreateNewFootprint( wxEmptyString, libraryName );
|
||||||
|
|
||||||
if( !newFootprint )
|
if( !newFootprint )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -708,7 +708,7 @@ TOOL_ACTION PCB_ACTIONS::newFootprint( TOOL_ACTION_ARGS()
|
||||||
.Scope( AS_GLOBAL )
|
.Scope( AS_GLOBAL )
|
||||||
.DefaultHotkey( MD_CTRL + 'N' )
|
.DefaultHotkey( MD_CTRL + 'N' )
|
||||||
.LegacyHotkeyName( "New" )
|
.LegacyHotkeyName( "New" )
|
||||||
.FriendlyName( _( "New Footprint..." ) )
|
.FriendlyName( _( "New Footprint" ) )
|
||||||
.Tooltip( _( "Create a new, empty footprint" ) )
|
.Tooltip( _( "Create a new, empty footprint" ) )
|
||||||
.Icon( BITMAPS::new_footprint ) );
|
.Icon( BITMAPS::new_footprint ) );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue