Add NewBoard API to allow standalone BOARD creation

Fixes https://gitlab.com/kicad/code/kicad/-/issues/9687
This commit is contained in:
Jon Evans 2021-11-18 21:43:05 -05:00
parent c5ddb8de26
commit d76c6bc884
2 changed files with 36 additions and 0 deletions

View File

@ -191,6 +191,34 @@ BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat )
}
BOARD* NewBoard( wxString& aFileName )
{
wxFileName boardFn = aFileName;
wxFileName proFn = aFileName;
proFn.SetExt( ProjectFileExtension );
proFn.MakeAbsolute();
wxString projectPath = proFn.GetFullPath();
// Ensure the "C" locale is temporary set, before reading any file
// It also avoids wxWidgets alerts about locale issues, later, when using Python 3
LOCALE_IO dummy;
GetSettingsManager()->LoadProject( projectPath, false );
PROJECT* project = GetSettingsManager()->GetProject( projectPath );
BOARD* brd = new BOARD();
brd->SetProject( project );
BOARD_DESIGN_SETTINGS& bds = brd->GetDesignSettings();
bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( brd, &bds );
SaveBoard( aFileName, brd );
return brd;
}
BOARD* CreateEmptyBoard()
{
// Creating a new board is not possible if running inside KiCad

View File

@ -45,6 +45,14 @@ BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat );
// Default LoadBoard() to load .kicad_pcb files:.
BOARD* LoadBoard( wxString& aFileName );
/**
* Creates a new board and project with the given filename (will overwrite existing files!)
*
* @param aFileName is the filename (including full path if desired) of the kicad_pcb to create
* @return a pointer to the board if it was created, or None if not
*/
BOARD* NewBoard( wxString& aFileName );
SETTINGS_MANAGER* GetSettingsManager();
/**