31#include <wx/choicdlg.h>
33#include <wx/textdlg.h>
47 wxString msg = wxString::Format(
_(
"Design block '%s' already exists in library '%s'." ),
51 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing design block?" ),
_(
"Overwrite" ) )
63 wxString msg = wxString::Format(
_(
"Design block '%s' already has a schematic." ),
66 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing schematic?" ),
_(
"Overwrite" ) )
86 std::vector<SCH_ITEM*> sheets;
96 wxFileName fn = wxFileNameFromPath( aSheetPath.
Last()->
GetName() );
101 std::vector<SCH_FIELD>& shFields = aSheetPath.
Last()->
GetFields();
102 nlohmann::ordered_map<wxString, wxString> dbFields;
106 if( f.GetId() == FIELD_T::SHEET_NAME || f.GetId() == FIELD_T::SHEET_FILENAME )
109 dbFields[f.GetCanonicalName()] = f.GetText();
122 if(
Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !
checkOverwriteDb(
this, libName, newName ) )
126 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
129 DisplayErrorMessage(
this,
_(
"Error saving temporary schematic file to create design block." ) );
130 wxRemoveFile( tempFile );
136 bool success =
false;
148 wxRemoveFile( tempFile );
167 std::vector<SCH_ITEM*> sheets;
170 if( !sheets.empty() )
176 std::unique_ptr<DESIGN_BLOCK> blk;
194 std::vector<SCH_FIELD>& shFields = aSheetPath.
Last()->
GetFields();
195 nlohmann::ordered_map<wxString, wxString> dbFields = blk->GetFields();
199 if( f.GetId() == FIELD_T::SHEET_NAME || f.GetId() == FIELD_T::SHEET_FILENAME )
202 dbFields[f.GetCanonicalName()] = f.GetText();
205 blk->SetFields( dbFields );
213 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
216 DisplayErrorMessage(
this,
_(
"Error saving temporary schematic file to create design block." ) );
217 wxRemoveFile( tempFile );
221 blk->SetSchematicFile( tempFile );
223 bool success =
false;
236 wxRemoveFile( tempFile );
250 if( selection.
Empty() )
266 if( selection.
Size() == 1 )
283 wxFileName fn = wxFileNameFromPath(
GetScreen()->GetFileName() );
295 if(
Prj().DesignBlockLibs()->DesignBlockExists( libName, newName ) && !
checkOverwriteDb(
this, libName, newName ) )
313 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
316 DisplayErrorMessage(
this,
_(
"Error saving temporary schematic file to create design block." ) );
317 wxRemoveFile( tempFile );
323 bool success =
false;
335 wxRemoveFile( tempFile );
351 if( selection.
Empty() )
367 if( selection.
Size() == 1 )
386 if( selection.
Size() == 1 )
399 selection.
Add( aItem );
401 RECURSE_MODE::NO_RECURSE );
405 std::unique_ptr<DESIGN_BLOCK> blk;
426 if( !aItem->IsSCH_ITEM() )
439 copy->SetParentGroup(
nullptr );
446 innerGroup->
RunOnChildren( cloneAndAdd, RECURSE_MODE::RECURSE );
455 wxString tempFile = wxFileName::CreateTempFileName(
"design_block" );
459 DisplayErrorMessage(
this,
_(
"Error saving temporary schematic file to create design block." ) );
460 wxRemoveFile( tempFile );
464 blk->SetSchematicFile( tempFile );
466 bool success =
false;
480 if( !
group->HasDesignBlockLink() )
485 group->SetDesignBlockLibId( aLibId );
487 commit.
Push(
"Set Group Design Block Link" );
497 wxRemoveFile( tempFile );
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 SetSchematicFile(const wxString &aFile)
void SetLibId(const LIB_ID &aName)
void SetFields(nlohmann::ordered_map< wxString, wxString > &aFields)
const LIB_ID & GetLibId() const
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.
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_LIB_TABLE * DesignBlockLibs()
Return the table of design block libraries.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
bool SaveSheetToDesignBlock(const LIB_ID &aLibId, SCH_SHEET_PATH &aSheetPath)
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
bool SaveSelectionToDesignBlock(const LIB_ID &aLibId)
SCHEMATIC * m_schematic
The currently loaded schematic.
SCH_SHEET_PATH & GetCurrentSheet() const
bool saveSchematicFile(SCH_SHEET *aSheet, const wxString &aSavePath)
Save aSheet to a schematic file.
SCH_DESIGN_BLOCK_PANE * m_designBlocksPane
bool SaveSheetAsDesignBlock(const wxString &aLibraryName, 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
Base class for any item which can be embedded within the SCHEMATIC container class,...
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.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
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.
This file is part of the common library.
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.