33#include <wx/choicdlg.h>
35#include <wx/textdlg.h>
52 wxString msg = wxString::Format(
_(
"Design block '%s' already exists in library '%s'." ), newName.GetData(),
55 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing design block?" ),
_(
"Overwrite" ) )
69 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing layout?" ),
_(
"Overwrite" ) )
85 wxFileName pcbFileName( aFileName );
91 DisplayError(
this, wxString::Format(
_(
"Insufficient permissions to write file '%s'." ),
92 pcbFileName.GetFullPath() ) );
101 wxASSERT( pcbFileName.IsAbsolute() );
103 pi->SaveBoard( pcbFileName.GetFullPath(), aBoard,
nullptr );
109 DisplayError(
this, wxString::Format(
_(
"Error saving board file '%s'.\n%s" ), pcbFileName.GetFullPath(),
130 wxFileName fn = wxFileNameFromPath(
GetBoard()->GetFileName() );
142 if(
Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !
checkOverwriteDb(
this, libName, newName ) )
148 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
153 wxRemoveFile( tempFile );
159 bool success =
false;
172 wxRemoveFile( tempFile );
191 std::unique_ptr<DESIGN_BLOCK> blk;
206 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
211 wxRemoveFile( tempFile );
215 blk->SetBoardFile( tempFile );
217 bool success =
false;
230 wxRemoveFile( tempFile );
253 auto addNetIfNeeded =
268 cItem->
SetNet( existingInfo );
272 tempBoard->
Add( newNet );
282 if( !aItem->IsBOARD_ITEM() )
298 copy->SetParentGroup(
nullptr );
316 deepCopy =
static_cast<PCB_GROUP*
>( item )->DeepClone();
325 addNetIfNeeded( child );
332 addNetIfNeeded(
copy );
335 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
340 wxRemoveFile( tempFile );
346 bool success =
false;
359 wxRemoveFile( tempFile );
380 if( selection.
Empty() )
398 wxFileName fn = wxFileNameFromPath(
GetBoard()->GetFileName() );
410 if(
Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !
checkOverwriteDb(
this, libName, newName ) )
421 group->RunOnChildren(
424 selection.
Add( aItem );
431 if( success && !
group )
441 for(
EDA_ITEM* edaItem : selection )
443 if( !edaItem->IsBOARD_ITEM() )
464 commit.
Add( newGroup );
465 commit.
Push(
_(
"Group Items" ) );
477 if( success &&
group && !
group->HasDesignBlockLink() )
484 commit.
Push(
_(
"Set Group Design Block Link" ) );
503 if( selection.
Empty() )
512 std::vector<BOARD_ITEM*> extraItems;
514 if( selection.
Size() == 1 )
523 std::vector<PCB_GROUP*> linkedGroups;
528 linkedGroups.push_back(
static_cast<PCB_GROUP*
>( item ) );
531 if( linkedGroups.size() > 1 )
534 "this design block." ) );
538 if( !linkedGroups.empty() )
539 group = linkedGroups.front();
546 if( item !=
group && item->IsBOARD_ITEM() )
547 extraItems.push_back(
static_cast<BOARD_ITEM*
>( item ) );
550 selection.Remove(
group );
553 group->RunOnChildren(
556 selection.Add( aItem );
562 std::unique_ptr<DESIGN_BLOCK> blk;
586 bool changed =
false;
590 if( item->GetParentFootprint() || !item->IsGroupableType() )
593 if( item->GetParentGroup() ==
group )
596 if(
EDA_GROUP* existingGroup = item->GetParentGroup() )
603 group->AddItem( item );
608 if( !
group->HasDesignBlockLink() )
611 group->SetDesignBlockLibId( aLibId );
616 commit.
Push(
_(
"Update Design Block Group" ) );
628 for(
EDA_ITEM* edaItem : selection )
630 if( !edaItem->IsBOARD_ITEM() )
651 commit.
Add( newGroup );
652 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,...
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
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...
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)
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
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.
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
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).
const LIB_ID & GetDesignBlockLibId() const
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.
virtual void SetParentGroup(EDA_GROUP *aGroup)
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).
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
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)
A null aItem is ignored; the selection never holds null members.
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.
PCB_LAYER_ID
A quick note on layer IDs:
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.