41#include <wx/filename.h>
88 auto libSelectedCondition =
98 auto libInferredCondition =
105 auto fpSelectedCondition =
112 auto fpExportCondition =
116 return fp !=
nullptr;
119 auto canOpenExternally =
124 bool ret = !
m_frame->IsContentModified();
132 ctxMenu.AddSeparator( 10 );
134 ctxMenu.AddItem(
ACTIONS::saveAs, libSelectedCondition || fpSelectedCondition, 10 );
135 ctxMenu.AddItem(
ACTIONS::revert, libSelectedCondition || libInferredCondition, 10 );
137 ctxMenu.AddSeparator( 10 );
145 ctxMenu.AddSeparator( 100 );
151 ctxMenu.AddSeparator( 200 );
157 ctxMenu.AddSeparator( 200 );
158 ctxMenu.AddItem(
ACTIONS::openDirectory, canOpenExternally && ( libSelectedCondition || fpSelectedCondition ), 200 );
173 const LIB_ID& aTargetLib )
191 _(
"The footprint could not be added to the selected library ('%s'). "
192 "This library is read-only." ),
203 m_frame->SaveFootprint( &aFootprint );
214 FOOTPRINT* newFootprint =
m_frame->CreateNewFootprint( wxEmptyString, libraryName );
219 if( !
m_frame->Clear_Pcb(
true ) )
223 m_frame->AddFootprintToBoard( newFootprint );
231 m_frame->Zoom_Automatique(
false );
232 m_frame->GetScreen()->SetContentModified();
237 m_frame->GetCanvas()->ForceRefresh();
238 m_frame->Update3DView(
true,
true );
240 m_frame->SyncLibraryTree(
false );
250 if(
m_frame->IsContentModified() )
278 m_frame->AddFootprintToBoard( newFootprint );
286 m_frame->Zoom_Automatique(
false );
287 m_frame->GetScreen()->SetContentModified();
294 m_frame->Update3DView(
true,
true );
296 m_frame->SyncLibraryTree(
false );
331 if(
m_frame->GetTargetFPID().GetLibItemName().empty() )
336 const wxString& src_libNickname =
m_frame->GetTargetFPID().GetLibNickname();
338 wxCHECK( optUri, 0 );
340 if(
m_frame->SaveLibraryAs( *optUri ) )
341 m_frame->SyncLibraryTree(
true );
358 m_frame->SyncLibraryTree(
true );
368 m_frame->SyncLibraryTree(
true );
389 if( fpID ==
m_frame->GetLoadedFPID() )
410 wxString newLib =
m_frame->GetLibTree()->GetSelectedLibId().GetLibNickname();
414 newName +=
_(
"_copy" );
419 m_frame->SyncLibraryTree(
true );
434 if( fpID ==
m_frame->GetLoadedFPID() )
441 m_frame->SyncLibraryTree(
true );
462 if( !libTool->
RenameLibrary(
_(
"Change Footprint Name" ), oldName,
463 [&](
const wxString& aNewName )
467 if( newName.IsEmpty() )
469 wxMessageBox(
_(
"Footprint must have a name." ) );
474 if( oldName != newName && adapter->FootprintExists( libraryName, newName ) )
476 msg = wxString::Format(
_(
"Footprint '%s' already exists in library '%s'." ),
477 newName, libraryName );
480 wxOK | wxCANCEL | wxICON_WARNING );
481 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
492 if( newName == oldName )
497 if( fpID ==
m_frame->GetLoadedFPID() )
527 adapter->DeleteFootprint( libraryName, oldName );
540 wxDataViewItem treeItem =
m_frame->GetLibTreeAdapter()->FindItem( fpID );
556 if(
frame->DeleteFootprintFromLibrary(
frame->GetTargetFPID(),
true ) )
558 if(
frame->GetTargetFPID() ==
frame->GetLoadedFPID() )
559 frame->Clear_Pcb(
false );
561 frame->SyncLibraryTree(
true );
570 bool is_last_fp_from_brd =
m_frame->IsCurrentFPFromBoard();
572 if( !
m_frame->Clear_Pcb(
true ) )
578 if(
m_frame->GetBoard()->GetFirstFootprint() )
579 m_frame->GetBoard()->GetFirstFootprint()->ClearFlags();
581 frame()->ClearUndoRedoList();
584 if( is_last_fp_from_brd )
599 m_frame->ExportFootprint( fp );
612 wxString
path = wxEmptyString;
622 wxString fileExt = wxEmptyString;
625 if( !libItemName.IsEmpty() )
628 wxFileName fileName(
path, libItemName, fileExt );
629 wxString explorerCommand;
632 explorerCommand = cfg->m_System.file_explorer;
634 if( explorerCommand.IsEmpty() )
636 path = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
638 if( !
path.IsEmpty() && wxDirExists(
path ) )
644 if( !explorerCommand.EndsWith(
"%F" ) )
646 wxMessageBox(
_(
"Missing/malformed file explorer argument '%F' in common settings." ) );
650 wxString escapedFilePath = fileName.GetFullPath();
651 escapedFilePath.Replace( wxS(
"\"" ), wxS(
"_" ) );
653 wxString fileArg = wxEmptyString;
654 fileArg <<
'"' << escapedFilePath <<
'"';
656 explorerCommand.Replace( wxT(
"%F" ), fileArg );
658 if( !explorerCommand.IsEmpty() )
659 wxExecute( explorerCommand );
669 if( fullEditorName.IsEmpty() )
671 wxMessageBox(
_(
"No text editor selected in KiCad. Please choose one." ) );
681 wxString libItemName = wxEmptyString;
688 libItemName = *optUri;
689 libItemName << wxFileName::GetPathSeparator();
693 if( !wxFileName::FileExists( libItemName ) )
696 ExecuteFile( fullEditorName, libItemName.wc_str(),
nullptr,
false );
708 if( !url.has_value() )
710 frame()->ShowInfoBarMsg(
_(
"No datasheet found in the footprint." ) );
717 { m_frame->GetBoard(), footprint } );
726 m_frame->LoadFootprintFromLibrary(
m_frame->GetLibTree()->GetSelectedLibId() );
743 if( !
m_frame->IsLibraryTreeShown() )
752 m_frame->ToggleLayersManager();
769 m_frame->GetCanvas()->Refresh();
844 if( ids.count( aItem->m_Uuid ) )
847 const_cast<KIID&
>( aItem->m_Uuid ) =
KIID();
850 ids.insert( aItem->m_Uuid );
875 processItem(
group );
879 errors += duplicates;
880 details += wxString::Format(
_(
"%d duplicate IDs replaced.\n" ), duplicates );
887 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 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
void SelectLeftToolbarAction(const TOOL_ACTION &aAction)
Select the given action in the left 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)
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)
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false) const
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.
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 importFootprint
static TOOL_ACTION pasteFootprint
static TOOL_ACTION footprintProperties
static TOOL_ACTION lineMode90
90-degree-only mode (icon lines90)
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.
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.
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)
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
Definition of file extensions used in Kicad.