55 _(
"Writing/modifying legacy libraries (.mod files) is not allowed\n"\
56 "Please save the current library to the new .pretty format\n"\
57 "and update your footprint lib table\n"\
58 "to save your footprint (a .kicad_mod file) in the .pretty library folder" ) );
61 _(
"Modifying legacy libraries (.mod files) is not allowed\n"\
62 "Please save the current library under the new .pretty format\n"\
63 "and update your footprint lib table\n"\
64 "before deleting a footprint" ) );
74 static int lastFilterIndex = 0;
82 wxFileDialog dlg( aParent,
_(
"Import Footprint" ), aLastPath, wxEmptyString, wildCard,
83 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
85 dlg.SetFilterIndex( lastFilterIndex );
87 if( dlg.ShowModal() == wxID_CANCEL )
90 lastFilterIndex = dlg.GetFilterIndex();
92 return wxFileName( dlg.GetPath() );
112 char* line = reader.Line();
116 if( strncasecmp( line,
"(module", strlen(
"(module" ) ) == 0
117 || strncasecmp( line,
"(footprint", strlen(
"(footprint" ) ) == 0 )
120 *aName = aFileName.GetName();
126 while( reader.ReadLine() )
128 if( !strncasecmp( line,
"$MODULE", strlen(
"$MODULE" ) ) )
135 else if( !strncasecmp( line,
"Element", strlen(
"Element" ) ) )
138 *aName = aFileName.GetName();
157 const wxString& aName )
165 default: wxFAIL_MSG( wxT(
"unexpected IO_MGR::PCB_FILE_T" ) );
break;
170 return pi->FootprintLoad( path, aName );
182 wxFFile f( aFileName.GetFullPath() );
187 f.ReadAll( &fcontents );
189 return dynamic_cast<FOOTPRINT*>( pcb_io.
Parse( fcontents ) );
200 const wxString& aName )
216 wxFAIL_MSG( wxT(
"unexpected IO_MGR::PCB_FILE_T" ) );
226 wxString lastOpenedPathForLoading =
m_mruPath;
234 if( aName != wxT(
"") )
242 FILE* fp = wxFopen( fn.GetFullPath(), wxT(
"rt" ) );
246 wxString msg =
wxString::Format(
_(
"File \"%s\" not found" ), fn.GetFullPath() );
253 wxString footprintName;
290 footprint->
SetFPID(
LIB_ID( wxEmptyString, footprintName ) );
327 wxFileDialog dlg(
this,
_(
"Export Footprint" ), fn.GetPath(), fn.GetFullName(),
328 wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
330 if( dlg.ShowModal() == wxID_CANCEL )
350 pcb_io.
Format( aFootprint );
352 FILE* fp = wxFopen( dlg.GetPath(), wxT(
"wt" ) );
370 wxString msg =
wxString::Format(
_(
"Footprint exported to file \"%s\"" ), dlg.GetPath() );
376 const wxString& aProposedName )
384 if( table ==
nullptr )
386 return wxEmptyString;
389 wxString initialPath = aProposedName.IsEmpty() ?
Prj().
GetProjectPath() : aProposedName;
394 if( aLibName.IsEmpty() )
402 return wxEmptyString;
411 if( !fn.IsAbsolute() )
413 fn.SetName( aLibName );
414 fn.MakeAbsolute( initialPath );
423 wxString libPath = fn.GetFullPath();
429 bool writable =
false;
434 writable = pi->IsFootprintLibWritable( libPath );
446 return wxEmptyString;
451 KIDIALOG dlg(
this, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
452 dlg.SetOKLabel(
_(
"Overwrite" ) );
456 return wxEmptyString;
458 pi->FootprintLibDelete( libPath );
462 pi->FootprintLibCreate( libPath );
467 return wxEmptyString;
480 if(
Prj().IsNullProject() )
486 wxMessageDialog dlg(
this,
_(
"Add the library to the global library table?" ),
487 _(
"Add To Global Library Table" ), wxYES_NO );
489 if( dlg.ShowModal() != wxID_OK )
496 wxArrayString libTableNames;
497 libTableNames.Add(
_(
"Global" ) );
498 libTableNames.Add(
_(
"Project" ) );
500 wxSingleChoiceDialog dlg(
this,
_(
"Choose the Library Table to add the library to:" ),
501 _(
"Add To Library Table" ), libTableNames );
505 dlg.FindWindow( wxID_CANCEL )->SetLabel(
_(
"Skip" ) );
506 dlg.FindWindow( wxID_OK )->SetLabel(
_(
"Add" ) );
509 if( dlg.ShowModal() != wxID_OK )
512 switch( dlg.GetSelection() )
516 default:
return nullptr;
523 if( aTable ==
nullptr )
527 if( aTable ==
nullptr )
529 return wxEmptyString;
535 wxFileName fn( aFilename );
537 if( aFilename.IsEmpty() )
547 wxString libPath = fn.GetFullPath();
548 wxString libName = fn.GetName();
550 if( libName.IsEmpty() )
559 if( normalizedPath.IsEmpty() )
560 normalizedPath = libPath;
564 auto row =
new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString );
586 LIB_ID libID( libName, wxEmptyString );
587 editor->SyncLibraryTree(
true );
588 editor->FocusOnLibID( libID );
594 viewer->ReCreateLibraryList();
618 if( !
Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname ) )
626 wxString msg =
wxString::Format(
_(
"Delete footprint '%s' from library '%s'?" ),
628 nickname.GetData() );
630 if( aConfirm && !
IsOK(
this, msg ) )
643 msg.Printf(
_(
"Footprint '%s' deleted from library '%s'" ),
645 nickname.GetData() );
647 SetStatusText( msg );
656 if(
GetBoard()->GetFirstFootprint() ==
nullptr )
662 wxString footprintName;
664 auto resetReference =
667 aFootprint->SetReference(
"REF**" );
670 if( !aStoreInNewLib )
688 if( !footprint->GetFPID().GetLibItemName().empty() )
690 FOOTPRINT* fpCopy = static_cast<FOOTPRINT*>( footprint->Duplicate() );
692 resetReference( fpCopy );
710 if( libPath.IsEmpty() )
723 if( !footprint->GetFPID().GetLibItemName().empty() )
725 FOOTPRINT* fpCopy = static_cast<FOOTPRINT*>( footprint->Duplicate() );
727 resetReference( fpCopy );
728 pi->FootprintSave( libPath, fpCopy );
763 else if( libraryName.IsEmpty() || footprintName.IsEmpty() )
809 const wxString& aLibraryName )
836 if( pcbframe ==
nullptr )
850 sourceFootprint =
nullptr;
854 if( editorFootprint->
GetLink() == candidate->m_Uuid )
856 sourceFootprint = candidate;
862 if( !aAddNew && sourceFootprint ==
nullptr )
864 DisplayError(
this,
_(
"Unable to find the footprint on the main board.\nCannot save." ) );
874 FOOTPRINT* newFootprint = static_cast<FOOTPRINT*>( editorFootprint->
Clone() );
887 fixUuid( const_cast<KIID&>( newFootprint->
m_Uuid ) );
891 fixUuid( const_cast<KIID&>( aChild->
m_Uuid ) );
894 if( sourceFootprint )
900 commit.
Push( wxT(
"Update footprint" ) );
907 commit.
Add( newFootprint );
912 const_cast<KIID&>( newFootprint->
m_Uuid ) =
KIID();
913 commit.
Push( wxT(
"Insert footprint" ) );
927 if( aFootprint ==
nullptr )
936 bool updateValue = aFootprint->
GetValue() == footprintName;
938 wxArrayString headers;
939 std::vector<wxArrayString> itemsToDisplay;
942 headers.Add(
_(
"Nickname" ) );
943 headers.Add(
_(
"Description" ) );
945 for(
const wxString& nickname : nicknames )
948 item.Add( nickname );
950 itemsToDisplay.push_back( item );
953 EDA_LIST_DIALOG dlg(
this,
_(
"Save Footprint As" ), headers, itemsToDisplay, libraryName );
957 wxBoxSizer* bNameSizer =
new wxBoxSizer( wxHORIZONTAL );
959 wxStaticText* label =
new wxStaticText( &dlg, wxID_ANY,
_(
"Name:" ),
960 wxDefaultPosition, wxDefaultSize, 0 );
961 bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
963 wxTextCtrl* nameTextCtrl =
new wxTextCtrl( &dlg, wxID_ANY, footprintName,
964 wxDefaultPosition, wxDefaultSize, 0 );
965 bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
967 wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
969 nameTextCtrl->SetValidator( nameValidator );
971 wxSizer* mainSizer = dlg.GetSizer();
972 mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
975 if( dlg.GetChildren().DeleteObject( nameTextCtrl ) )
976 dlg.GetChildren().Insert( nameTextCtrl );
981 mainSizer->Fit( &dlg );
983 if( dlg.ShowModal() != wxID_OK )
988 if( libraryName.IsEmpty() )
990 DisplayError(
this,
_(
"No library specified. Footprint could not be saved." ) );
994 footprintName = nameTextCtrl->GetValue();
995 footprintName.Trim(
true );
996 footprintName.Trim(
false );
998 if( footprintName.IsEmpty() )
1000 DisplayError(
this,
_(
"No footprint name specified. Footprint could not be saved." ) );
1004 aFootprint->
SetFPID(
LIB_ID( libraryName, footprintName ) );
1007 aFootprint->
SetValue( footprintName );
1020 bool footprintExists = tbl->
FootprintExists( libraryName, footprintName );
1022 if( footprintExists )
1027 KIDIALOG chkdlg(
this, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
1028 chkdlg.SetOKLabel(
_(
"Overwrite" ) );
1040 wxString fmt = footprintExists ?
_(
"Footprint '%s' replaced in '%s'" )
1041 :
_(
"Footprint '%s' added to '%s'" );
1043 wxString msg =
wxString::Format( fmt, footprintName.GetData(), libraryName.GetData() );
1044 SetStatusText( msg );
1084 wxString footprintName = aFootprintName;
1087 if( footprintName.IsEmpty() )
1093 if( dlg.ShowModal() != wxID_OK )
1097 footprintName.Trim(
true );
1098 footprintName.Trim(
false );
1100 if( footprintName.IsEmpty() )
1113 footprint->
SetFPID(
LIB_ID( wxEmptyString, footprintName ) );
1116 wxPoint default_pos;
1123 default_pos.y -= settings.
GetTextSize( txt_layer ).y / 2;
1125 default_pos.y += settings.
GetTextSize( txt_layer ).y;
1131 default_pos.y += settings.
GetTextSize( txt_layer ).y / 2;
1133 default_pos.y += settings.
GetTextSize( txt_layer ).y;
1142 default_pos.y += settings.
GetTextSize( txt_layer ).y / 2;
1144 default_pos.y += settings.
GetTextSize( txt_layer ).y;
1151 if( footprint->
GetValue().IsEmpty() )
1152 footprint->
SetValue( footprintName );
1159 FP_TEXT* textItem = static_cast<FP_TEXT*>( aChild );
1176 wxArrayString headers;
1178 headers.Add(
_(
"Nickname" ) );
1179 headers.Add(
_(
"Description" ) );
1183 std::vector< wxArrayString > itemsToDisplay;
1186 for(
const wxString& nickname : nicknames )
1190 item.Add( nickname );
1193 itemsToDisplay.push_back( item );
1196 EDA_LIST_DIALOG dlg(
this,
_(
"Select Library" ), headers, itemsToDisplay, aNicknameExisting );
1198 if( dlg.ShowModal() != wxID_OK )
1199 return wxEmptyString;
static TOOL_ACTION selectionClear
Clear the current selection.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
const UTF8 & GetLibItemName() const
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
bool ConfirmRevertDialog(wxWindow *parent, const wxString &aMessage)
Display a confirmation dialog for a revert action.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
BOARD_ITEM * Parse(const wxString &aClipboardSourceInput)
std::vector< TEXT_ITEM_INFO > m_DefaultFPTextItems
wxString GetTextSelection(int aColumn=0)
Return the selected text from aColumn in the wxListCtrl in the dialog.
A PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
class FP_TEXT, text in a footprint
virtual void SetPosition(const wxPoint &aPos) override
FP_LIB_TABLE GFootprintTable
!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it.
Container for project specific data.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
char * StrPurge(char *text)
Remove leading and training spaces, tabs and end of line chars in text.
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
This file is part of the common library.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
const std::string KiCadFootprintFileExtension
void SetOKLabel(const wxString &aLabel)
COMMIT & Add(EDA_ITEM *aItem)
Notify observers that aItem has been added.
virtual void Update3DView(bool aReloadRequest, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SetItalic(bool isItalic)
A KICAD version of wxTextEntryDialog which supports the various improvments/work-arounds from DIALOG_...
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false, bool aIsGlobal=false, const wxString &aGlobalPath=wxEmptyString)
void SetTextValidator(wxTextValidatorStyle style)
void SetVisible(bool aVisible)
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
void SetTextSize(const wxSize &aNewSize)
static const wxString ShowType(PCB_FILE_T aFileType)
Return a brief name for a plugin given aFileType enum.
A logical library item identifier and consists of various portions much like a URI.
int GetTextThickness(PCB_LAYER_ID aLayer) const
Return the default text thickness from the layer class for the given layer.
bool IsValid() const
Check if this LID_ID is valid.
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
virtual const wxString GetProjectPath() const
Return the full path of the project.
wxString AllFilesWildcard()
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Read lines of text from another LINE_READER but only returns non-comment lines and non-blank lines wi...
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Return a plugin type given a footprint library's libPath.
virtual void SetParent(EDA_ITEM *aParent)
void PlaceFootprint(FOOTPRINT *aFootprint, bool aRecreateRatsnest=true)
Places aFootprint at the current cursor position and updates footprint coordinates with the new posit...
void ExportFootprintsToLibrary(bool aStoreInNewLib, const wxString &aLibName=wxEmptyString, wxString *aLibPath=NULL)
Save footprints in a library:
bool GetTextUpright(PCB_LAYER_ID aLayer) const
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
bool GetTextItalic(PCB_LAYER_ID aLayer) const
Releases a PLUGIN in the context of a potential thrown exception through its destructor.
virtual void Zoom_Automatique(bool aWarpPointer)
Redraw the screen with best zoom level and the best centering that shows all the page or the board.
void ExchangeFootprint(FOOTPRINT *aExisting, FOOTPRINT *aNew, BOARD_COMMIT &aCommit, bool deleteExtraTexts=true, bool resetTextLayers=true, bool resetTextEffects=true, bool resetFabricationAttrs=true, bool reset3DModels=true)
Replace aExisting footprint by aNew footprint using the Existing footprint settings (position,...
PCB_LAYER_ID
A quick note on layer IDs:
#define FOOTPRINT_LIBRARY_HEADER
A LINE_READER that reads from an open file.
FOOTPRINT * GetFirstFootprint() const
Gets the first footprint on the board or nullptr.
virtual void SetText(const wxString &aText)
VECTOR2< double > VECTOR2D
virtual const wxString What() const
A composite of Problem() and Where()
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
std::string GetStringOutput(bool doClear)
const wxString GetDescription(const wxString &aNickname)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
wxString CreateNewLibrary(const wxString &aLibName=wxEmptyString, const wxString &aProposedName=wxEmptyString)
If a library name is given, creates a new footprint library in the project folder with the given name...
FOOTPRINTS & Footprints()
wxString ModLegacyExportFileWildcard()
Definition of file extensions used in Kicad.
Helper dialog and control classes.
An interface for classes handling user events controlling the view behavior such as zooming,...
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
bool AddLibrary(const wxString &aLibName=wxEmptyString, FP_LIB_TABLE *aTable=nullptr)
Add an existing library to either the global or project library table.
FormatType fileType(const char *aFileName)
#define FOOTPRINT_LIBRARY_HEADER_CNT
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
virtual void SetRString(RSTRING_T aStringId, const wxString &aString)
Store a "retained string", which is any session and project specific string identified in enum RSTRIN...
virtual FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
FOOTPRINT * CreateNewFootprint(const wxString &aFootprintName)
Creates a new footprint, at position 0,0.
void SetKeepUpright(bool aKeepUpright)
void Format(const BOARD_ITEM *aItem, int aNestLevel=0) const
Output aItem to aFormatter in s-expression format.
virtual const wxString & GetRString(RSTRING_T aStringId)
Return a "retained string", which is any session and project specific string identified in enum RSTRI...
wxString KiCadFootprintLibPathWildcard()
static TOOL_ACTION placeFootprint
static wxString GetDefaultUserFootprintsPath()
Gets the default path we point users to create projects.
Legacy Pcbnew file formats prior to s-expression.
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an FP_LIB_TABLE_ROW if aNickName is found in this table or in any chained fall back table frag...
FP_LIB_TABLE * selectLibTable(bool aOptional=false)
Prompts a user to select global or project library tables.
Information pertinent to a Pcbnew printed circuit board.
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Return a PLUGIN which the caller can use to import, export, save, or load design documents.
SAVE_T FootprintSave(const wxString &aNickname, const FOOTPRINT *aFootprint, bool aOverwrite=true)
Write aFootprint to an existing library given by aNickname.
The main frame for Pcbnew.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
wxString SelectLibrary(const wxString &aNicknameExisting)
Put up a dialog and allows the user to pick a library, for unspecified use.
void FootprintDelete(const wxString &aNickname, const wxString &aFootprintName)
Delete the aFootprintName from the library given by aNickname.
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
const std::string KiCadFootprintLibPathExtension
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
wxString KiCadFootprintLibFileWildcard()
Custom text control validator definitions.
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Return the default text size from the layer class for the given layer.
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
bool FootprintExists(const wxString &aNickname, const wxString &aFootprintName)
Indicates whether or not the given footprint already exists in the given library.
static wxString GetGlobalTableFileName()
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
wxString GedaPcbFootprintLibFileWildcard()
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
KICAD_T Type() const
Returns the type of object.
S-expression Pcbnew file format.
Container for design settings for a BOARD object.
void SetListLabel(const wxString &aLabel)