36#include <wx/choicdlg.h>
38#include <wx/textdlg.h>
55 wxString msg = wxString::Format(
_(
"Design block '%s' already exists in library '%s'." ), newName.GetData(),
58 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing design block?" ),
_(
"Overwrite" ) )
72 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing layout?" ),
_(
"Overwrite" ) )
88 wxFileName pcbFileName( aFileName );
94 DisplayError(
this, wxString::Format(
_(
"Insufficient permissions to write file '%s'." ),
95 pcbFileName.GetFullPath() ) );
104 wxASSERT( pcbFileName.IsAbsolute() );
106 pi->SaveBoard( pcbFileName.GetFullPath(), aBoard,
nullptr );
112 DisplayError(
this, wxString::Format(
_(
"Error saving board file '%s'.\n%s" ), pcbFileName.GetFullPath(),
133 wxFileName fn = wxFileNameFromPath(
GetBoard()->GetFileName() );
145 if(
Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !
checkOverwriteDb(
this, libName, newName ) )
151 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
156 wxRemoveFile( tempFile );
162 bool success =
false;
175 wxRemoveFile( tempFile );
193 std::unique_ptr<DESIGN_BLOCK> blk;
209 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
214 wxRemoveFile( tempFile );
218 blk->SetBoardFile( tempFile );
220 bool success =
false;
233 wxRemoveFile( tempFile );
252 auto addNetIfNeeded =
267 cItem->
SetNet( existingInfo );
271 tempBoard->
Add( newNet );
281 if( !aItem->IsBOARD_ITEM() )
297 copy->SetParentGroup(
nullptr );
312 addNetIfNeeded(
copy );
315 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
320 wxRemoveFile( tempFile );
326 bool success =
false;
339 wxRemoveFile( tempFile );
360 if( selection.
Empty() )
378 wxFileName fn = wxFileNameFromPath(
GetBoard()->GetFileName() );
390 if(
Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !
checkOverwriteDb(
this, libName, newName ) )
401 group->RunOnChildren(
404 selection.
Add( aItem );
411 if( success && !
group )
421 for(
EDA_ITEM* edaItem : selection )
423 if( !edaItem->IsBOARD_ITEM() )
444 commit.
Add( newGroup );
445 commit.
Push(
_(
"Group Items" ) );
456 if( success &&
group && !
group->HasDesignBlockLink() )
463 commit.
Push(
_(
"Set Group Design Block Link" ) );
482 if( selection.
Empty() )
491 if( selection.
Size() == 1 )
506 std::unique_ptr<DESIGN_BLOCK> blk;
531 if( !
group->HasDesignBlockLink() )
536 group->SetDesignBlockLibId( aLibId );
538 commit.
Push(
_(
"Set Group Design Block Link" ) );
551 for(
EDA_ITEM* edaItem : selection )
553 if( !edaItem->IsBOARD_ITEM() )
574 commit.
Add( newGroup );
575 commit.
Push(
_(
"Group Items" ) );
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
static TOOL_ACTION selectionClear
Clear the current selection.
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.
void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
bool IsGroupableType() const
FOOTPRINT * GetParentFootprint() const
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)
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.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
SAVE_T SaveDesignBlock(const wxString &aNickname, const DESIGN_BLOCK *aDesignBlock, bool aOverwrite=true)
Write aDesignBlock to an existing library given by aNickname.
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 set of EDA_ITEMs (i.e., without duplicates).
void SetDesignBlockLibId(const LIB_ID &aLibId)
void AddItem(EDA_ITEM *aItem)
Add item to group.
void SetName(const wxString &aName)
A base class for most all the KiCad significant classes used in schematics and boards.
virtual EDA_GROUP * GetParentGroup() const
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 saveSelectionToDesignBlock(const wxString &aNickname, PCB_SELECTION &aSelection, DESIGN_BLOCK &aBlock)
bool UpdateDesignBlockFromBoard(const LIB_ID &aLibId)
bool UpdateDesignBlockFromSelection(const LIB_ID &aLibId)
bool SavePcbCopy(const wxString &aFileName, bool aCreateProject=false, bool aHeadless=false)
Write the board data structures to aFileName.
bool SaveSelectionAsDesignBlock(const wxString &aLibraryName)
bool SaveBoardAsDesignBlock(const wxString &aLibraryName)
PCB_DESIGN_BLOCK_PANE * m_designBlocksPane
A set of BOARD_ITEMs (i.e., without duplicates).
EDA_ITEM * AsEdaItem() override
@ KICAD_SEXP
S-expression Pcbnew file format.
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
virtual DESIGN_BLOCK_LIBRARY_ADAPTER * 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.
bool HasType(KICAD_T aType) const
Checks if there is at least one item of requested kind.
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.
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.