37#include <wx/filename.h>
90 auto libSelectedCondition =
100 auto libInferredCondition =
107 auto fpSelectedCondition =
114 auto fpExportCondition =
118 return fp !=
nullptr;
121 auto canOpenExternally =
126 bool ret = !
m_frame->IsContentModified();
134 ctxMenu.AddSeparator( 10 );
136 ctxMenu.AddItem(
ACTIONS::saveAs, libSelectedCondition || fpSelectedCondition, 10 );
137 ctxMenu.AddItem(
ACTIONS::revert, libSelectedCondition || libInferredCondition, 10 );
139 ctxMenu.AddSeparator( 10 );
148 ctxMenu.AddSeparator( 100 );
154 ctxMenu.AddSeparator( 200 );
160 ctxMenu.AddSeparator( 200 );
161 ctxMenu.AddItem(
ACTIONS::openDirectory, canOpenExternally && ( libSelectedCondition || fpSelectedCondition ), 200 );
176 const LIB_ID& aTargetLib )
194 _(
"The footprint could not be added to the selected library ('%s'). "
195 "This library is read-only." ),
209 if(
m_frame->SaveFootprint( &aFootprint ) )
221 if( !
m_frame->BeginNewFootprint( libraryName ) )
224 FOOTPRINT* newFootprint =
m_frame->CreateNewFootprint( wxEmptyString, libraryName );
231 if(
m_frame->GetTabsPanel() && !libraryName.IsEmpty() )
235 m_frame->AddFootprintToBoard( newFootprint );
243 m_frame->Zoom_Automatique(
false );
244 m_frame->GetScreen()->SetContentModified();
249 m_frame->GetCanvas()->ForceRefresh();
250 m_frame->Update3DView(
true,
true );
252 m_frame->SyncLibraryTree(
false );
261 if(
m_frame->IsContentModified() )
289 m_frame->AddFootprintToBoard( newFootprint );
297 m_frame->Zoom_Automatique(
false );
298 m_frame->GetScreen()->SetContentModified();
305 m_frame->Update3DView(
true,
true );
307 m_frame->SyncLibraryTree(
false );
342 if(
m_frame->GetTargetFPID().GetLibItemName().empty() )
347 const wxString& src_libNickname =
m_frame->GetTargetFPID().GetLibNickname();
349 wxCHECK( optUri, 0 );
351 if(
m_frame->SaveLibraryAs( *optUri ) )
352 m_frame->SyncLibraryTree(
true );
369 m_frame->SyncLibraryTree(
true );
379 m_frame->SyncLibraryTree(
true );
400 if( fpID ==
m_frame->GetLoadedFPID() )
421 wxString newLib =
m_frame->GetLibTree()->GetSelectedLibId().GetLibNickname();
425 newName +=
_(
"_copy" );
430 m_frame->SyncLibraryTree(
true );
445 if( fpID ==
m_frame->GetLoadedFPID() )
452 m_frame->SyncLibraryTree(
true );
473 if( !libTool->
RenameLibrary(
_(
"Change Footprint Name" ), oldName,
474 [&](
const wxString& aNewName )
478 if( newName.IsEmpty() )
480 wxMessageBox(
_(
"Footprint must have a name." ) );
485 if( oldName != newName && adapter->FootprintExists( libraryName, newName ) )
487 msg = wxString::Format(
_(
"Footprint '%s' already exists in library '%s'." ),
488 newName, libraryName );
491 wxOK | wxCANCEL | wxICON_WARNING );
492 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
503 if( newName == oldName )
508 if( fpID ==
m_frame->GetLoadedFPID() )
538 adapter->DeleteFootprint( libraryName, oldName );
552 m_frame->RenameFootprintTab( fpID,
LIB_ID( libraryName, newName ) );
554 wxDataViewItem treeItem =
m_frame->GetLibTreeAdapter()->FindItem( fpID );
571 if(
frame->DeleteFootprintFromLibrary( fpID,
true ) )
575 if(
frame->GetTabsPanel() )
576 frame->CloseFootprintTab( fpID );
577 else if( fpID ==
frame->GetLoadedFPID() )
578 frame->Clear_Pcb(
false );
580 frame->SyncLibraryTree(
true );
589 bool is_last_fp_from_brd =
m_frame->IsCurrentFPFromBoard();
591 if( !
m_frame->Clear_Pcb(
true ) )
597 if(
m_frame->GetBoard()->GetFirstFootprint() )
598 m_frame->GetBoard()->GetFirstFootprint()->ClearFlags();
600 frame()->ClearUndoRedoList();
603 if( is_last_fp_from_brd )
618 m_frame->ExportFootprint( fp );
628 const wxString libNickname =
m_frame->GetTargetFPID().GetUniStringLibNickname();
630 if( libNickname.IsEmpty() )
632 m_frame->ShowInfoBarError(
_(
"Select a library to compare against another." ) );
638 wxCHECK( adapter, 0 );
640 std::optional<LIBRARY_TABLE_ROW*> row = adapter->
GetRow( libNickname );
644 m_frame->ShowInfoBarError( wxString::Format(
_(
"Library '%s' is not in the footprint "
652 wxFileName currentFn = wxFileName::DirName(
654 currentFn.MakeAbsolute();
655 const wxString currentPath = currentFn.GetPath();
657 wxDirDialog dlg(
m_frame,
_(
"Choose .pretty Folder to Compare With" ), wxEmptyString,
658 wxDD_DIR_MUST_EXIST );
660 if( dlg.ShowModal() != wxID_OK )
663 wxFileName otherFn = wxFileName::DirName( dlg.GetPath() );
664 otherFn.MakeAbsolute();
666 if( otherFn.GetDirs().IsEmpty()
667 || !otherFn.GetDirs().Last().EndsWith( wxS(
".pretty" ) ) )
670 _(
"Select a KiCad footprint library folder (ends with .pretty)." ) );
674 if( otherFn.SameAs( currentFn ) )
677 _(
"Select a different .pretty folder than the active library." ) );
681 const wxString otherPath = otherFn.GetPath();
683 std::vector<std::unique_ptr<FOOTPRINT>> beforeStorage;
684 std::vector<std::unique_ptr<FOOTPRINT>> afterStorage;
689 [&](
const wxString& aPath,
690 std::vector<std::unique_ptr<FOOTPRINT>>& aOwners,
696 aOwners = std::move( loaded.first );
697 aMap = std::move( loaded.second );
703 wxString::Format(
_(
"Failed to load %s: %s" ), aPath, ioe.
What() ) );
705 catch(
const std::exception& e )
708 wxString::Format(
_(
"Failed to load %s: %s" ), aPath,
709 wxString::FromUTF8( e.what() ) ) );
715 if( !load( currentPath, beforeStorage, beforeMap ) )
718 if( !load( otherPath, afterStorage, afterMap ) )
738 wxString
path = wxEmptyString;
748 wxString fileExt = wxEmptyString;
751 if( !libItemName.IsEmpty() )
754 wxFileName fileName(
path, libItemName, fileExt );
755 wxString explorerCommand;
758 explorerCommand = cfg->m_System.file_explorer;
760 if( explorerCommand.IsEmpty() )
762 path = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
764 if( !
path.IsEmpty() && wxDirExists(
path ) )
770 if( !explorerCommand.EndsWith(
"%F" ) )
772 wxMessageBox(
_(
"Missing/malformed file explorer argument '%F' in common settings." ) );
776 wxString escapedFilePath = fileName.GetFullPath();
777 escapedFilePath.Replace( wxS(
"\"" ), wxS(
"_" ) );
779 wxString fileArg = wxEmptyString;
780 fileArg <<
'"' << escapedFilePath <<
'"';
782 explorerCommand.Replace( wxT(
"%F" ), fileArg );
784 if( !explorerCommand.IsEmpty() )
785 wxExecute( explorerCommand );
795 if( fullEditorName.IsEmpty() )
797 wxMessageBox(
_(
"No text editor selected in KiCad. Please choose one." ) );
807 wxString libItemName = wxEmptyString;
814 libItemName = *optUri;
815 libItemName << wxFileName::GetPathSeparator();
819 if( !wxFileName::FileExists( libItemName ) )
822 ExecuteFile( fullEditorName, libItemName.wc_str(),
nullptr,
false );
834 if( !url.has_value() )
836 frame()->ShowInfoBarMsg(
_(
"No datasheet found in the footprint." ) );
843 { m_frame->GetBoard(), footprint } );
852 m_frame->LoadFootprintFromLibrary(
m_frame->GetLibTree()->GetSelectedLibId() );
869 if( !
m_frame->IsLibraryTreeShown() )
878 m_frame->ToggleLayersManager();
895 LIB_ID treeLibId =
m_frame->GetLibTree()->GetSelectedLibId();
899 && ( !
m_frame->GetBoard()->GetFirstFootprint()
900 ||
m_frame->GetBoard()->GetFirstFootprint()->GetFPID() != treeLibId ) )
911 m_frame->GetCanvas()->Refresh();
923 if( !libraryFootprint )
927 std::unique_ptr<BOARD> tempBoard(
new BOARD() );
931 tempBoard->SetDesignSettings(
m_frame->GetBoard()->GetDesignSettings() );
932 tempBoard->SetProject( &
m_frame->Prj(),
true );
934 tempBoard->SynchronizeProperties();
938 delete libraryFootprint;
940 tempBoard->Add( tempFootprint );
941 tempFootprint->
SetParent( tempBoard.get() );
952 tempBoard->Remove( tempFootprint );
963 wxDataViewItem treeItem =
m_frame->GetLibTreeAdapter()->FindItem( oldFPID );
964 m_frame->UpdateLibraryTree( treeItem, tempFootprint );
965 m_frame->SyncLibraryTree(
true );
968 delete tempFootprint;
972 delete tempFootprint;
1046 if( ids.count( aItem->m_Uuid ) )
1050 boardItem->ResetUuid();
1053 ids.insert( aItem->m_Uuid );
1072 processItem( item );
1075 processItem( zone );
1078 processItem(
group );
1082 errors += duplicates;
1083 details += wxString::Format(
_(
"%d duplicate IDs replaced.\n" ), duplicates );
1090 wxString msg = wxString::Format(
_(
"%d potential problems repaired." ), errors );
1110 for( wxWindow* focus = wxWindow::FindFocus(); focus; focus = focus->GetParent() )
1112 if( focus == appearance )
1125 m_frame->AdvanceFootprintTab(
true );
1135 m_frame->AdvanceFootprintTab(
false );
1142 m_frame->CloseActiveFootprintTab();
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 TOOL_ACTION refreshPreview
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
File-compare dialog (Phase 7).
void SelectToolbarAction(const TOOL_ACTION &aAction)
Select the given action in the toolbar group which contains it, if any.
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)
virtual void SetParent(EDA_ITEM *aParent)
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()
Diff two .pretty footprint library directories.
static std::pair< std::vector< std::unique_ptr< FOOTPRINT > >, FOOTPRINT_MAP > LoadLibrary(const wxString &aPrettyPath)
Load a .pretty directory into a FOOTPRINT_MAP.
DOCUMENT_DIFF Diff() override
Produce a DOCUMENT_DIFF of the inputs the concrete differ was constructed with.
std::map< wxString, const FOOTPRINT * > FOOTPRINT_MAP
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)
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
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.
static TOOL_ACTION lineModeFree
Unconstrained angle mode (icon lines_any)
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 lineMode45
45-degree-or-orthogonal mode (icon hv45mode)
static TOOL_ACTION angleSnapModeChanged
Notification event when angle mode changes.
static TOOL_ACTION newFootprint
static TOOL_ACTION defaultPadProperties
static TOOL_ACTION prevFootprintTab
static TOOL_ACTION importFootprint
static TOOL_ACTION pasteFootprint
static TOOL_ACTION footprintProperties
static TOOL_ACTION lineMode90
90-degree-only mode (icon lines90)
static TOOL_ACTION closeFootprintTab
static TOOL_ACTION nextFootprintTab
static TOOL_ACTION checkFootprint
static TOOL_ACTION editLibFpInFpEditor
static TOOL_ACTION duplicateFootprint
static TOOL_ACTION cutFootprint
static TOOL_ACTION repairFootprint
static TOOL_ACTION compareFpLibraryWithFile
static TOOL_ACTION copyFootprint
static TOOL_ACTION cleanupGraphics
APPEARANCE_CONTROLS * GetAppearancePanel()
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.
virtual LIBRARY_MANAGER & GetLibraryManager() const
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
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.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
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.
LEADER_MODE
The kind of the leader line.
@ DIRECT
Unconstrained point-to-point.
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.
T * GetAppSettings(const char *aFilename)
The full set of changes between two parsed documents of one type.
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
Definition of file extensions used in Kicad.