35#include <wx/choicdlg.h>
37#include <wx/textdlg.h>
49#include <nlohmann/json.hpp>
53 wxString msg = wxString::Format(
_(
"Design block '%s' already exists in library '%s'." ), newName.GetData(),
56 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing design block?" ),
_(
"Overwrite" ) )
70 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing layout?" ),
_(
"Overwrite" ) )
86 wxFileName pcbFileName( aFileName );
92 DisplayError(
this, wxString::Format(
_(
"Insufficient permissions to write file '%s'." ),
93 pcbFileName.GetFullPath() ) );
102 wxASSERT( pcbFileName.IsAbsolute() );
104 pi->SaveBoard( pcbFileName.GetFullPath(), aBoard,
nullptr );
110 DisplayError(
this, wxString::Format(
_(
"Error saving board file '%s'.\n%s" ), pcbFileName.GetFullPath(),
131 wxFileName fn = wxFileNameFromPath(
GetBoard()->GetFileName() );
143 if(
Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !
checkOverwriteDb(
this, libName, newName ) )
149 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
154 wxRemoveFile( tempFile );
160 bool success =
false;
172 wxRemoveFile( tempFile );
208 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
213 wxRemoveFile( tempFile );
219 bool success =
false;
232 wxRemoveFile( tempFile );
251 auto addNetIfNeeded =
261 tempBoard->
Add( netinfo );
272 fp->RunOnChildren( addNetIfNeeded, RECURSE_MODE::NO_RECURSE );
274 addNetIfNeeded(
copy );
281 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
286 wxRemoveFile( tempFile );
292 bool success =
false;
304 wxRemoveFile( tempFile );
325 if( selection.
Empty() )
332 wxFileName fn = wxFileNameFromPath(
GetBoard()->GetFileName() );
344 if(
Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !
checkOverwriteDb(
this, libName, newName ) )
365 if( selection.
Empty() )
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aSettings)
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
void SynchronizeProperties()
Copy the current project's text variables into the boards property cache.
DESIGN_BLOCK * DesignBlockLoad(const wxString &aNickname, const wxString &aDesignBlockName, bool aKeepUUID=false)
Load a design block having aDesignBlockName from the library given by aNickname.
SAVE_T DesignBlockSave(const wxString &aNickname, const DESIGN_BLOCK *aDesignBlock, bool aOverwrite=true)
Write aDesignBlock to an existing library given by aNickname.
void SelectLibId(const LIB_ID &aLibId)
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
void SetBoardFile(const wxString &aFile)
void SetLibId(const LIB_ID &aName)
const wxString & GetBoardFile() const
const LIB_ID & GetLibId() const
bool IsWritable(const wxFileName &aFileName, bool aVerbose=true)
Check if aFileName can be written.
A base class for most all the KiCad significant classes used in schematics and boards.
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()
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Handle the data for a net.
const wxString & GetNetname() const
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Return the BOARD_DESIGN_SETTINGS for the open project.
bool saveBoardAsFile(BOARD *aBoard, const wxString &aFileName, bool aHeadless=false)
Save a board object to a file.
bool SaveBoardToDesignBlock(const LIB_ID &aLibId)
bool saveSelectionToDesignBlock(const wxString &aNickname, PCB_SELECTION &aSelection, DESIGN_BLOCK &aBlock)
bool SavePcbCopy(const wxString &aFileName, bool aCreateProject=false, bool aHeadless=false)
Write the board data structures to aFileName.
bool SaveSelectionAsDesignBlock(const wxString &aLibraryName)
bool SaveSelectionToDesignBlock(const LIB_ID &aLibId)
bool SaveBoardAsDesignBlock(const wxString &aLibraryName)
PCB_DESIGN_BLOCK_PANE * m_designBlocksPane
static PCB_IO * PluginFind(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
@ KICAD_SEXP
S-expression Pcbnew file format.
virtual DESIGN_BLOCK_LIB_TABLE * DesignBlockLibs()
Return the table of design block libraries.
bool Empty() const
Checks if there is anything selected.
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aDetailedMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Display a warning dialog with aMessage and returns the user response.
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.
Helper functions to substitute paths with environmental variables.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
This file is part of the common library.
bool checkOverwriteDb(wxWindow *aFrame, wxString &libname, wxString &newName)
bool checkOverwriteDbLayout(wxWindow *aFrame, const LIB_ID &aLibId)
bool checkOverwriteDb(wxWindow *aFrame, wxString &libname, wxString &newName)
std::vector< FAB_LAYER_COLOR > dummy
Definition of file extensions used in Kicad.