44#include <wx/filedlg.h>
45#include <wx/filename.h>
99 auto libSelectedCondition =
109 auto libInferredCondition =
116 auto fpSelectedCondition =
123 auto fpExportCondition =
127 return fp !=
nullptr;
130 auto canOpenExternally =
135 bool ret = !
m_frame->IsContentModified();
143 ctxMenu.AddSeparator( 10 );
145 ctxMenu.AddItem(
ACTIONS::saveAs, libSelectedCondition || fpSelectedCondition, 10 );
146 ctxMenu.AddItem(
ACTIONS::revert, libSelectedCondition || libInferredCondition, 10 );
148 ctxMenu.AddSeparator( 10 );
157 ctxMenu.AddSeparator( 100 );
163 ctxMenu.AddSeparator( 200 );
169 ctxMenu.AddSeparator( 200 );
170 ctxMenu.AddItem(
ACTIONS::openDirectory, canOpenExternally && ( libSelectedCondition || fpSelectedCondition ), 200 );
173 ctxMenu.AddSeparator( 300 );
188 const LIB_ID& aTargetLib )
206 _(
"The footprint could not be added to the selected library ('%s'). "
207 "This library is read-only." ),
221 if(
m_frame->SaveFootprint( &aFootprint ) )
233 if( !
m_frame->BeginNewFootprint( libraryName ) )
236 FOOTPRINT* newFootprint =
m_frame->CreateNewFootprint( wxEmptyString, libraryName );
243 if( !libraryName.IsEmpty() )
250 m_frame->CreateUnsavedFootprintTab();
254 m_frame->AddFootprintToBoard( newFootprint );
262 m_frame->Zoom_Automatique(
false );
263 m_frame->GetScreen()->SetContentModified();
269 m_frame->GetCanvas()->ForceRefresh();
270 m_frame->Update3DView(
true,
true );
272 m_frame->SyncLibraryTree(
false );
300 m_frame->CreateUnsavedFootprintTab();
304 m_frame->AddFootprintToBoard( newFootprint );
312 m_frame->Zoom_Automatique(
false );
313 m_frame->GetScreen()->SetContentModified();
320 m_frame->Update3DView(
true,
true );
322 m_frame->SyncLibraryTree(
false );
360 if(
m_frame->GetTargetFPID().GetLibItemName().empty() )
365 const wxString& src_libNickname =
m_frame->GetTargetFPID().GetLibNickname();
367 wxCHECK( optUri, 0 );
369 if(
m_frame->SaveLibraryAs( *optUri ) )
370 m_frame->SyncLibraryTree(
true );
387 m_frame->SyncLibraryTree(
true );
397 m_frame->SyncLibraryTree(
true );
418 if( fpID ==
m_frame->GetLoadedFPID() )
439 wxString newLib =
m_frame->GetLibTree()->GetSelectedLibId().GetLibNickname();
443 newName +=
_(
"_copy" );
448 m_frame->SyncLibraryTree(
true );
463 if( fpID ==
m_frame->GetLoadedFPID() )
470 m_frame->SyncLibraryTree(
true );
491 if( !libTool->
RenameLibrary(
_(
"Change Footprint Name" ), oldName,
492 [&](
const wxString& aNewName )
496 if( newName.IsEmpty() )
498 wxMessageBox(
_(
"Footprint must have a name." ) );
503 if( oldName != newName && adapter->FootprintExists( libraryName, newName ) )
505 msg = wxString::Format(
_(
"Footprint '%s' already exists in library '%s'." ),
506 newName, libraryName );
509 wxOK | wxCANCEL | wxICON_WARNING );
510 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
521 if( newName == oldName )
526 if( fpID ==
m_frame->GetLoadedFPID() )
555 adapter->DeleteFootprint( libraryName, oldName );
571 m_frame->RenameFootprintTab( fpID,
LIB_ID( libraryName, newName ) );
573 wxDataViewItem treeItem =
m_frame->GetLibTreeAdapter()->FindItem( fpID );
590 if(
frame->DeleteFootprintFromLibrary( fpID,
true ) )
593 frame->CloseFootprintTab( fpID );
595 frame->SyncLibraryTree(
true );
604 bool is_last_fp_from_brd =
m_frame->IsCurrentFPFromBoard();
609 if( !
m_frame->ImportFootprint() )
612 if(
m_frame->GetBoard()->GetFirstFootprint() )
613 m_frame->GetBoard()->GetFirstFootprint()->ClearFlags();
615 frame()->ClearUndoRedoList();
618 if( is_last_fp_from_brd )
632 const wxString title =
_(
"Export for Older KiCad Version" );
633 wxString libName =
m_frame->GetTargetFPID().GetLibNickname();
640 wxMessageBox(
_(
"Select a library first." ), title, wxOK | wxICON_ERROR,
m_frame );
644 const wxString
library = *optUri;
647 if(
m_frame->IsContentModified()
648 && wxMessageBox(
_(
"A library editor has unsaved changes. The export uses the last saved "
649 "library files. Continue?" ),
650 title, wxYES_NO | wxICON_WARNING,
m_frame )
664 wxFileName out( aPass.
m_folder, wxEmptyString );
665 out.AppendDir( wxFileName(
library ).GetFullName() );
679 m_frame->ExportFootprint( fp );
691 wxMessageBox(
_(
"No footprint to export" ) );
698 wxString pro_dir = wxPathOnly(
m_frame->Prj().GetProjectFullName() );
703 if( !fullFileName.IsEmpty() )
724 const wxString libNickname =
m_frame->GetTargetFPID().GetUniStringLibNickname();
726 if( libNickname.IsEmpty() )
728 m_frame->ShowInfoBarError(
_(
"Select a library to compare against another." ) );
734 wxCHECK( adapter, 0 );
736 std::optional<LIBRARY_TABLE_ROW*> row = adapter->
GetRow( libNickname );
740 m_frame->ShowInfoBarError( wxString::Format(
_(
"Library '%s' is not in the footprint "
748 wxFileName currentFn = wxFileName::DirName(
750 currentFn.MakeAbsolute();
751 const wxString currentPath = currentFn.GetPath();
753 wxDirDialog dlg(
m_frame,
_(
"Choose .pretty Folder to Compare With" ), wxEmptyString,
754 wxDD_DIR_MUST_EXIST );
756 if( dlg.ShowModal() != wxID_OK )
759 wxFileName otherFn = wxFileName::DirName( dlg.GetPath() );
760 otherFn.MakeAbsolute();
762 if( otherFn.GetDirs().IsEmpty()
763 || !otherFn.GetDirs().Last().EndsWith( wxS(
".pretty" ) ) )
766 _(
"Select a KiCad footprint library folder (ends with .pretty)." ) );
770 if( otherFn.SameAs( currentFn ) )
773 _(
"Select a different .pretty folder than the active library." ) );
777 const wxString otherPath = otherFn.GetPath();
779 std::vector<std::unique_ptr<FOOTPRINT>> beforeStorage;
780 std::vector<std::unique_ptr<FOOTPRINT>> afterStorage;
785 [&](
const wxString& aPath,
786 std::vector<std::unique_ptr<FOOTPRINT>>& aOwners,
792 aOwners = std::move( loaded.first );
793 aMap = std::move( loaded.second );
799 wxString::Format(
_(
"Failed to load %s: %s" ), aPath, ioe.
What() ) );
801 catch(
const std::exception& e )
804 wxString::Format(
_(
"Failed to load %s: %s" ), aPath,
805 wxString::FromUTF8( e.what() ) ) );
811 if( !load( currentPath, beforeStorage, beforeMap ) )
814 if( !load( otherPath, afterStorage, afterMap ) )
845 wxString
path = wxEmptyString;
855 wxString fileExt = wxEmptyString;
858 if( !libItemName.IsEmpty() )
861 wxFileName fileName(
path, libItemName, fileExt );
862 wxString explorerCommand;
865 explorerCommand = cfg->m_System.file_explorer;
867 if( explorerCommand.IsEmpty() )
869 path = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
871 if( !
path.IsEmpty() && wxDirExists(
path ) )
877 if( !explorerCommand.EndsWith(
"%F" ) )
879 wxMessageBox(
_(
"Missing/malformed file explorer argument '%F' in common settings." ) );
883 wxString escapedFilePath = fileName.GetFullPath();
884 escapedFilePath.Replace( wxS(
"\"" ), wxS(
"_" ) );
886 wxString fileArg = wxEmptyString;
887 fileArg <<
'"' << escapedFilePath <<
'"';
889 explorerCommand.Replace( wxT(
"%F" ), fileArg );
891 if( !explorerCommand.IsEmpty() )
892 wxExecute( explorerCommand );
902 if( fullEditorName.IsEmpty() )
904 wxMessageBox(
_(
"No text editor selected in KiCad. Please choose one." ) );
914 wxString libItemName = wxEmptyString;
921 libItemName = *optUri;
922 libItemName << wxFileName::GetPathSeparator();
926 if( !wxFileName::FileExists( libItemName ) )
929 ExecuteFile( fullEditorName, libItemName.wc_str(),
nullptr,
false );
941 if( !url.has_value() )
943 frame()->ShowInfoBarMsg(
_(
"No datasheet found in the footprint." ) );
950 { m_frame->GetBoard(), footprint } );
959 m_frame->LoadFootprintFromLibrary(
m_frame->GetLibTree()->GetSelectedLibId() );
976 if( !
m_frame->IsLibraryTreeShown() )
985 m_frame->ToggleLayersManager();
1002 LIB_ID treeLibId =
m_frame->GetLibTree()->GetSelectedLibId();
1006 && ( !
m_frame->GetBoard()->GetFirstFootprint()
1007 ||
m_frame->GetBoard()->GetFirstFootprint()->GetFPID() != treeLibId ) )
1018 m_frame->GetCanvas()->Refresh();
1030 if( !libraryFootprint )
1034 std::unique_ptr<BOARD> tempBoard(
new BOARD() );
1038 tempBoard->SetDesignSettings(
m_frame->GetBoard()->GetDesignSettings() );
1039 tempBoard->SetProject( &
m_frame->Prj(),
true );
1041 tempBoard->SynchronizeProperties();
1045 delete libraryFootprint;
1047 tempBoard->Add( tempFootprint );
1048 tempFootprint->
SetParent( tempBoard.get() );
1059 tempBoard->Remove( tempFootprint );
1070 wxDataViewItem treeItem =
m_frame->GetLibTreeAdapter()->FindItem( oldFPID );
1071 m_frame->UpdateLibraryTree( treeItem, tempFootprint );
1072 m_frame->SyncLibraryTree(
true );
1075 delete tempFootprint;
1079 delete tempFootprint;
1160 if( ids.count( aItem->m_Uuid ) )
1164 boardItem->ResetUuid();
1167 ids.insert( aItem->m_Uuid );
1186 processItem( item );
1189 processItem( zone );
1192 processItem(
group );
1196 errors += duplicates;
1197 details += wxString::Format(
_(
"%d duplicate IDs replaced.\n" ), duplicates );
1204 wxString msg = wxString::Format(
_(
"%d potential problems repaired." ), errors );
1224 for( wxWindow* focus = wxWindow::FindFocus(); focus; focus = focus->GetParent() )
1226 if( focus == appearance )
1239 m_frame->AdvanceFootprintTab(
true );
1249 m_frame->AdvanceFootprintTab(
false );
1256 m_frame->CloseActiveFootprintTab();
1263 if(
m_frame->GetTargetFPID().GetLibNickname().empty() )
1266 if(
m_frame->HasModifiedFootprintTabs() )
1269 "the Footprint Fields Table." ) );
static TOOL_ACTION openWithTextEditor
static TOOL_ACTION revert
static TOOL_ACTION saveAs
static TOOL_ACTION exportForOlderVersion
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 DrawChosenLibraryItem(LIBRARY_ITEM_DRAWER aDraw)
Draw only the library item named by the chosen change, since the outlines of a whole library pile up ...
void SelectToolbarAction(const TOOL_ACTION &aAction) override
Select the given action in the toolbar group which contains it, if any.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the KIGFX::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()
wxString m_outputLibraryPath
Where to write the converted copy.
wxString m_libraryPath
The .pretty footprint library to convert.
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.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
LSEQ SeqStackupForPlotting() const
Return the sequence that is typical for a bottom-to-top stack-up.
static const LSET & AllLayersMask()
static TOOL_ACTION lineModeFree
Unconstrained angle mode (icon lines_any)
static TOOL_ACTION deleteFootprint
static TOOL_ACTION renameFootprint
static TOOL_ACTION showFootprintUsers
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 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 showLibFootprintFieldsTable
static TOOL_ACTION checkFootprint
static TOOL_ACTION editLibFpInFpEditor
static TOOL_ACTION duplicateFootprint
static TOOL_ACTION cutFootprint
static TOOL_ACTION repairFootprint
static TOOL_ACTION exportFootprintAsSVG
static TOOL_ACTION compareFpLibraryWithFile
static TOOL_ACTION copyFootprint
static TOOL_ACTION cleanupGraphics
APPEARANCE_CONTROLS * GetAppearancePanel()
A set of BOARD_ITEMs (i.e., without duplicates).
Parameters and options when plotting/printing a board.
void SetAutoScale(bool aFlag)
void SetScale(double aVal)
void SetColorSettings(COLOR_SETTINGS *aSettings)
void SetFormat(PLOT_FORMAT aFormat)
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.
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.
void RunExportForOlderVersion(EDA_BASE_FRAME *aFrame, const DOWNGRADE_EXPORT_RUNNER &aRun)
bool RunDowngradeJob(KIWAY &aKiway, KIWAY::FACE_T aFace, JOB_T &aJob, const DOWNGRADE_EXPORT_PASS &aPass, DOWNGRADE_EXPORT_RESULT &aResult)
Fill in the parts of a downgrade job that every editor sets the same way, run it, and hand back its r...
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 SVGFileExtension
static const std::string KiCadFootprintFileExtension
static wxString SVGFileWildcard()
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
DOCUMENT_GEOMETRY ExtractFootprintGeometry(const FOOTPRINT &aFootprint, const KIGFX::COLOR4D &aColor)
Extract drawable context geometry from a single FOOTPRINT.
void ShowFootprintPair(WIDGET_DIFF_CANVAS &aCanvas, const FP_LIB_DIFFER::FOOTPRINT_MAP &aBefore, const FP_LIB_DIFFER::FOOTPRINT_MAP &aAfter, const wxString &aName)
Draw the footprint aName as it is in aBefore and aAfter.
Class to handle a set of BOARD_ITEMs.
bool PlotFootprintToSVG(const FOOTPRINT &aFootprint, PROJECT &aProject, const std::map< wxString, wxString > *aVarOverrides, PCB_PLOT_PARAMS &aPlotOpts, const LSEQ &aLayersToPlot, const LSEQ &aLayersOnAll, const wxString &aFileName, REPORTER *aReporter)
Plot a footprint to an SVG file, with the footprint origin at the SVG origin and the page/viewBox siz...
PGM_BASE & Pgm()
The global program "get" accessor.
T * GetAppSettings(const char *aFilename)
What one pass of an export is asked to do.
bool m_dryRun
Classify only, write nothing.
wxString m_folder
Destination, empty on a dry run.
What the flow needs back from a pass.
Diff colors with defaults for light backgrounds.
KIGFX::COLOR4D reference
Default color for source-document context geometry.
KIGFX::COLOR4D comparison
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.