36#include <wx/choicdlg.h>
38#include <wx/textdlg.h>
54 wxString msg = wxString::Format(
_(
"Design block '%s' already exists in library '%s'." ), newName.GetData(),
57 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing design block?" ),
_(
"Overwrite" ) )
71 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing layout?" ),
_(
"Overwrite" ) )
87 wxFileName pcbFileName( aFileName );
93 DisplayError(
this, wxString::Format(
_(
"Insufficient permissions to write file '%s'." ),
94 pcbFileName.GetFullPath() ) );
103 wxASSERT( pcbFileName.IsAbsolute() );
105 pi->SaveBoard( pcbFileName.GetFullPath(), aBoard,
nullptr );
111 DisplayError(
this, wxString::Format(
_(
"Error saving board file '%s'.\n%s" ), pcbFileName.GetFullPath(),
132 wxFileName fn = wxFileNameFromPath(
GetBoard()->GetFileName() );
144 if(
Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !
checkOverwriteDb(
this, libName, newName ) )
150 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
155 wxRemoveFile( tempFile );
161 bool success =
false;
173 wxRemoveFile( tempFile );
191 std::unique_ptr<DESIGN_BLOCK> blk;
207 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
212 wxRemoveFile( tempFile );
216 blk->SetBoardFile( tempFile );
218 bool success =
false;
231 wxRemoveFile( tempFile );
250 auto addNetIfNeeded =
260 tempBoard->
Add( netinfo );
267 if( !aItem->IsBOARD_ITEM() )
271 tempBoard->
Add(
copy, ADD_MODE::APPEND,
false );
279 copy->SetParentGroup(
nullptr );
283 static_cast<FOOTPRINT*
>( item )->RunOnChildren( addNetIfNeeded, RECURSE_MODE::NO_RECURSE );
290 group->RunOnChildren( cloneAndAdd, RECURSE_MODE::RECURSE );
291 group->RunOnChildren( addNetIfNeeded, RECURSE_MODE::RECURSE );
294 addNetIfNeeded( item );
301 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
306 wxRemoveFile( tempFile );
312 bool success =
false;
324 wxRemoveFile( tempFile );
345 if( selection.
Empty() )
352 wxFileName fn = wxFileNameFromPath(
GetBoard()->GetFileName() );
364 if(
Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !
checkOverwriteDb(
this, libName, newName ) )
385 if( selection.
Empty() )
394 if( selection.
Size() == 1 )
405 group->RunOnChildren( [&](
EDA_ITEM* aItem ) { selection.
Add( aItem ); }, RECURSE_MODE::NO_RECURSE );
409 std::unique_ptr<DESIGN_BLOCK> blk;
434 if( !
group->HasDesignBlockLink() )
438 commit.
Modify(
group,
nullptr, RECURSE_MODE::NO_RECURSE );
439 group->SetDesignBlockLibId( aLibId );
441 commit.
Push(
"Set Group Design Block Link" );
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
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.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
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 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.
KICAD_T Type() const
Returns the type of object.
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
A set of BOARD_ITEMs (i.e., without duplicates).
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.
virtual void Add(EDA_ITEM *aItem)
virtual void Remove(EDA_ITEM *aItem)
virtual void Clear() override
Remove all the stored items from the group.
int Size() const
Returns the number of selected parts.
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)
Class to handle a set of BOARD_ITEMs.
bool checkOverwriteDb(wxWindow *aFrame, wxString &libname, wxString &newName)
std::vector< FAB_LAYER_COLOR > dummy
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition of file extensions used in Kicad.