38#include <wx/filename.h>
85 auto libSelectedCondition =
95 auto libInferredCondition =
102 auto fpSelectedCondition =
109 auto fpExportCondition =
113 return fp !=
nullptr;
116 auto canOpenExternally =
121 bool ret = !
m_frame->IsContentModified();
129 ctxMenu.AddSeparator( 10 );
131 ctxMenu.AddItem(
ACTIONS::saveAs, libSelectedCondition || fpSelectedCondition, 10 );
132 ctxMenu.AddItem(
ACTIONS::revert, libSelectedCondition || libInferredCondition, 10 );
134 ctxMenu.AddSeparator( 10 );
142 ctxMenu.AddSeparator( 100 );
148 ctxMenu.AddSeparator( 200 );
154 ctxMenu.AddSeparator( 200 );
155 ctxMenu.AddItem(
ACTIONS::openDirectory, canOpenExternally && ( libSelectedCondition || fpSelectedCondition ), 200 );
166 const LIB_ID& aTargetLib )
186 _(
"The footprint could not be added to the selected library ('%s'). "
187 "This library is read-only." ),
198 m_frame->SaveFootprint( &aFootprint );
209 FOOTPRINT* newFootprint =
m_frame->CreateNewFootprint( wxEmptyString, libraryName );
214 if( !
m_frame->Clear_Pcb(
true ) )
218 m_frame->AddFootprintToBoard( newFootprint );
226 m_frame->Zoom_Automatique(
false );
227 m_frame->GetScreen()->SetContentModified();
232 m_frame->GetCanvas()->ForceRefresh();
233 m_frame->Update3DView(
true,
true );
235 m_frame->SyncLibraryTree(
false );
245 if(
m_frame->IsContentModified() )
273 m_frame->AddFootprintToBoard( newFootprint );
281 m_frame->Zoom_Automatique(
false );
282 m_frame->GetScreen()->SetContentModified();
289 m_frame->Update3DView(
true,
true );
291 m_frame->SyncLibraryTree(
false );
326 if(
m_frame->GetTargetFPID().GetLibItemName().empty() )
329 const wxString& src_libNickname =
m_frame->GetTargetFPID().GetLibNickname();
332 if(
m_frame->SaveLibraryAs( src_libFullName ) )
333 m_frame->SyncLibraryTree(
true );
350 m_frame->SyncLibraryTree(
true );
360 m_frame->SyncLibraryTree(
true );
381 if( fpID ==
m_frame->GetLoadedFPID() )
402 wxString newLib =
m_frame->GetLibTree()->GetSelectedLibId().GetLibNickname();
406 newName +=
_(
"_copy" );
411 m_frame->SyncLibraryTree(
true );
426 if( fpID ==
m_frame->GetLoadedFPID() )
433 m_frame->SyncLibraryTree(
true );
454 if( !libTool->
RenameLibrary(
_(
"Change Footprint Name" ), oldName,
455 [&](
const wxString& aNewName )
459 if( newName.IsEmpty() )
461 wxMessageBox(
_(
"Footprint must have a name." ) );
466 if( oldName != newName && tbl->FootprintExists( libraryName, newName ) )
468 msg = wxString::Format(
_(
"Footprint '%s' already exists in library '%s'." ),
469 newName, libraryName );
472 wxOK | wxCANCEL | wxICON_WARNING );
473 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
484 if( newName == oldName )
489 if( fpID ==
m_frame->GetLoadedFPID() )
532 wxDataViewItem treeItem =
m_frame->GetLibTreeAdapter()->FindItem( fpID );
548 if(
frame->DeleteFootprintFromLibrary(
frame->GetTargetFPID(),
true ) )
550 if(
frame->GetTargetFPID() ==
frame->GetLoadedFPID() )
551 frame->Clear_Pcb(
false );
553 frame->SyncLibraryTree(
true );
562 bool is_last_fp_from_brd =
m_frame->IsCurrentFPFromBoard();
564 if( !
m_frame->Clear_Pcb(
true ) )
570 if(
m_frame->GetBoard()->GetFirstFootprint() )
571 m_frame->GetBoard()->GetFirstFootprint()->ClearFlags();
573 frame()->ClearUndoRedoList();
576 if( is_last_fp_from_brd )
591 m_frame->ExportFootprint( fp );
606 wxString
path = wxEmptyString;
615 path =
table->FindRow( libName,
true )->GetFullURI(
true );
622 if( !
path.IsEmpty() )
626 wxString fileExt = wxEmptyString;
629 if( !libItemName.IsEmpty() )
632 wxFileName fileName(
path, libItemName, fileExt );
633 wxString explorerCommand;
636 explorerCommand = cfg->m_System.file_explorer;
638 if( explorerCommand.IsEmpty() )
640 path = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
642 if( !
path.IsEmpty() && wxDirExists(
path ) )
648 if( !explorerCommand.EndsWith(
"%F" ) )
650 wxMessageBox(
_(
"Missing/malformed file explorer argument '%F' in common settings." ) );
654 wxString escapedFilePath = fileName.GetFullPath();
655 escapedFilePath.Replace( wxS(
"\"" ), wxS(
"_" ) );
657 wxString fileArg = wxEmptyString;
658 fileArg <<
'"' << escapedFilePath <<
'"';
660 explorerCommand.Replace( wxT(
"%F" ), fileArg );
662 if( !explorerCommand.IsEmpty() )
663 wxExecute( explorerCommand );
673 if( fullEditorName.IsEmpty() )
675 wxMessageBox(
_(
"No text editor selected in KiCad. Please choose one." ) );
685 wxString libItemName = wxEmptyString;
694 libItemName =
table->FindRow( libName,
true )->GetFullURI(
true );
701 if( !libItemName.IsEmpty() )
705 libItemName << wxFileName::GetPathSeparator();
709 if( !wxFileName::FileExists( libItemName ) )
712 ExecuteFile( fullEditorName, libItemName.wc_str(),
nullptr,
false );
724 if( !url.has_value() )
726 frame()->ShowInfoBarMsg(
_(
"No datasheet found in the footprint." ) );
733 { m_frame->GetBoard(), footprint } );
742 m_frame->LoadFootprintFromLibrary(
m_frame->GetLibTree()->GetSelectedLibId() );
759 if( !
m_frame->IsLibraryTreeShown() )
768 m_frame->ToggleLayersManager();
785 m_frame->GetCanvas()->Refresh();
860 if( ids.count( aItem->m_Uuid ) )
863 const_cast<KIID&
>( aItem->m_Uuid ) =
KIID();
866 ids.insert( aItem->m_Uuid );
891 processItem(
group );
895 errors += duplicates;
896 details += wxString::Format(
_(
"%d duplicate IDs replaced.\n" ), duplicates );
903 wxString msg = wxString::Format(
_(
"%d potential problems repaired." ), errors );
static TOOL_ACTION openWithTextEditor
static TOOL_ACTION revert
static TOOL_ACTION saveAs
static TOOL_ACTION openDirectory
static TOOL_ACTION showDatasheet
static TOOL_ACTION zoomFitScreen
static TOOL_ACTION showProperties
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
const FOOTPRINTS & Footprints() const
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
void ForceRefresh()
Force a redraw.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A base class for most all the KiCad significant classes used in schematics and boards.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
void FootprintDelete(const wxString &aNickname, const wxString &aFootprintName)
Delete the aFootprintName from the library given by aNickname.
bool IsFootprintLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
virtual bool ShowModal(wxString *aResult=nullptr, wxWindow *aResultantFocusWindow=nullptr)
Show this wxFrame as if it were a modal dialog, with all other instantiated wxFrames disabled until t...
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
Module editor specific tools.
bool RenameLibrary(const wxString &aTitle, const wxString &aName, std::function< bool(const wxString &aNewName)> aValidator)
void AddContextMenuItems(CONDITIONAL_MENU *aMenu)
A logical library item identifier and consists of various portions much like a URI.
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
const wxString GetUniStringLibNickname() const
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
wxString GetFullURI(const wxString &aLibNickname, bool aExpandEnvVars=true) const
Return the full URI of the library mapped to aLibNickname.
static TOOL_ACTION deleteFootprint
static TOOL_ACTION renameFootprint
static TOOL_ACTION showLayersManager
static TOOL_ACTION createFootprint
static TOOL_ACTION editFootprint
static TOOL_ACTION exportFootprint
static TOOL_ACTION editTextAndGraphics
static TOOL_ACTION newFootprint
static TOOL_ACTION defaultPadProperties
static TOOL_ACTION importFootprint
static TOOL_ACTION pasteFootprint
static TOOL_ACTION footprintProperties
static TOOL_ACTION checkFootprint
static TOOL_ACTION editLibFpInFpEditor
static TOOL_ACTION duplicateFootprint
static TOOL_ACTION cutFootprint
static TOOL_ACTION repairFootprint
static TOOL_ACTION copyFootprint
static TOOL_ACTION cleanupGraphics
A set of BOARD_ITEMs (i.e., without duplicates).
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
static FP_LIB_TABLE * PcbFootprintLibs(PROJECT *aProject)
Return the table of footprint libraries without Kiway.
Look for files in a number of paths.
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
A modified version of the wxInfoBar class that allows us to:
bool HasCloseButton() const
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Handle a list of polygons defining a copper zone.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
FP_LIB_TABLE GFootprintTable
The global footprint library table.
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths, std::vector< EMBEDDED_FILES * > aFilesStack)
Open a document (file) with the suitable browser.
This file is part of the common library.
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback, bool aFileForKicad)
Call the executable file aEditorName with the parameter aFileName.
static const std::string KiCadFootprintFileExtension
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
Class to handle a set of BOARD_ITEMs.
PGM_BASE & Pgm()
The global program "get" accessor.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
Definition of file extensions used in Kicad.