27#include <wx/choicdlg.h>
29#include <wx/textdlg.h>
44 wxString msg = wxString::Format(
_(
"Design block '%s' already exists in library '%s'." ),
48 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing design block?" ),
_(
"Overwrite" ) )
60 wxString msg = wxString::Format(
_(
"Design block '%s' already has a schematic." ),
63 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing schematic?" ),
_(
"Overwrite" ) )
83 std::vector<SCH_ITEM*> sheets;
93 wxFileName fn = wxFileNameFromPath( aSheetPath.
Last()->
GetName() );
103 blk.
GetFields()[field.GetUntranslatedName()] = field.GetText();
114 if(
Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !
checkOverwriteDb(
this, libName, newName ) )
118 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
122 DisplayErrorMessage(
this,
_(
"Error saving temporary schematic file to create design block." ) );
123 wxRemoveFile( tempFile );
129 bool success =
false;
142 wxRemoveFile( tempFile );
161 std::vector<SCH_ITEM*> sheets;
164 if( !sheets.empty() )
171 std::unique_ptr<DESIGN_BLOCK> blk;
193 blk->GetFields()[field.GetUntranslatedName()] = field.GetText();
202 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
206 DisplayErrorMessage(
this,
_(
"Error saving temporary schematic file to create design block." ) );
207 wxRemoveFile( tempFile );
211 blk->SetSchematicFile( tempFile );
213 bool success =
false;
226 wxRemoveFile( tempFile );
240 if( selection.
Empty() )
256 if( selection.
Size() == 1 )
283 wxFileName fn = wxFileNameFromPath(
GetScreen()->GetFileName() );
295 if(
Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !
checkOverwriteDb(
this, libName, newName ) )
307 group->RunOnChildren(
310 selection.
Add( aItem );
323 tempScreen->
Append( clonedGroup );
335 tempScreen->
Append( clonedSymbol );
350 std::unique_ptr<SCH_SHEET> tempSheet = std::make_unique<SCH_SHEET>(
m_schematic );
351 tempSheet->SetScreen( tempScreen );
354 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
358 DisplayErrorMessage(
this,
_(
"Error saving temporary schematic file to create design block." ) );
359 wxRemoveFile( tempFile );
365 bool success =
false;
377 if( success && !
group )
389 for(
EDA_ITEM* edaItem : selection )
391 if( !edaItem->IsSCH_ITEM() )
412 commit.
Add( newGroup, screen );
413 commit.
Push(
_(
"Group Items" ) );
424 else if( success &&
group && !
group->HasDesignBlockLink() )
431 commit.
Push(
_(
"Set Group Design Block Link" ) );
435 wxRemoveFile( tempFile );
449 if( selection.
Empty() )
465 if( selection.
Size() == 1 )
483 std::vector<SCH_ITEM*> extraItems;
485 if( selection.
Size() == 1 )
499 if(
static_cast<SCH_GROUP*
>( item )->GetDesignBlockLibId() != aLibId )
505 "this design block." ) );
517 if( item !=
group && item->IsSCH_ITEM() )
518 extraItems.push_back(
static_cast<SCH_ITEM*
>( item ) );
521 selection.Remove(
group );
524 group->RunOnChildren(
527 selection.Add( aItem );
533 std::unique_ptr<DESIGN_BLOCK> blk;
553 if( !aItem->IsSCH_ITEM() )
566 copy->SetParentGroup(
nullptr );
578 std::unique_ptr<SCH_SHEET> tempSheet = std::make_unique<SCH_SHEET>(
m_schematic );
579 tempSheet->SetScreen( tempScreen );
582 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
586 DisplayErrorMessage(
this,
_(
"Error saving temporary schematic file to create design block." ) );
587 wxRemoveFile( tempFile );
591 blk->SetSchematicFile( tempFile );
593 bool success =
false;
608 bool changed =
false;
612 if( item->GetParentSymbol() || !item->IsGroupableType() )
615 if( item->GetParentGroup() ==
group )
618 if(
EDA_GROUP* existingGroup = item->GetParentGroup() )
625 group->AddItem( item );
630 if( !
group->HasDesignBlockLink() )
633 group->SetDesignBlockLibId( aLibId );
638 commit.
Push(
_(
"Update Design Block Group" ) );
646 if( success && !
group )
658 for(
EDA_ITEM* edaItem : selection )
660 if( !edaItem->IsSCH_ITEM() )
681 commit.
Add( newGroup, screen );
682 commit.
Push(
_(
"Group Items" ) );
695 wxRemoveFile( tempFile );
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
static TOOL_ACTION selectionClear
Clear the current selection.
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 SetSchematicFile(const wxString &aFile)
void SetLibId(const LIB_ID &aName)
const LIB_ID & GetLibId() const
const nlohmann::ordered_map< wxString, wxString > & GetFields() const
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.
virtual void SetParent(EDA_ITEM *aParent)
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.
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.
virtual DESIGN_BLOCK_LIBRARY_ADAPTER * DesignBlockLibs()
Return the table of design block libraries.
Commit for the schematic and symbol editors.
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
bool UpdateDesignBlockFromSelection(const LIB_ID &aLibId)
bool saveSchematicFile(SCH_SHEET *aSheet, const wxString &aSavePath, bool isSaveAs)
Save aSheet to a schematic file.
SCHEMATIC * m_schematic
The currently loaded schematic.
SCH_SHEET_PATH & GetCurrentSheet() const
SCH_DESIGN_BLOCK_PANE * m_designBlocksPane
bool SaveSheetAsDesignBlock(const wxString &aLibraryName, SCH_SHEET_PATH &aSheetPath)
bool UpdateDesignBlockFromSheet(const LIB_ID &aLibId, SCH_SHEET_PATH &aSheetPath)
bool SaveSelectionAsDesignBlock(const wxString &aLibraryName)
A set of SCH_ITEMs (i.e., without duplicates).
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode) override
EDA_ITEM * AsEdaItem() override
Base class for any item which can be embedded within the SCHEMATIC container class,...
const SYMBOL * GetParentSymbol() const
bool IsGroupableType() const
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void GetSheets(std::vector< SCH_ITEM * > *aItems) const
Similar to Items().OfType( SCH_SHEET_T ), but return the sheets in a deterministic order (L-R,...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the sheet's fields.
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.
bool checkOverwriteDb(wxWindow *aFrame, wxString &libname, wxString &newName)
bool checkOverwriteDbSchematic(wxWindow *aFrame, const LIB_ID &aLibId)
Class to handle a set of SCH_ITEMs.
Definition of file extensions used in Kicad.