KiCad PCB EDA Suite
Loading...
Searching...
No Matches
headless_footprint_context.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21#include <board.h>
22#include <footprint.h>
24#include <project.h>
25#include <project_pcb.h>
26#include <tool/tool_manager.h>
27#include <wx/debug.h>
28
29
30HEADLESS_FOOTPRINT_CONTEXT::HEADLESS_FOOTPRINT_CONTEXT( std::unique_ptr<FOOTPRINT> aFootprint,
31 const LIB_ID& aFPID,
32 PROJECT* aProject,
33 APP_SETTINGS_BASE* aSettings,
34 KIWAY* aKiway ) :
35 m_board( std::make_unique<BOARD>() ),
36 m_fpid( aFPID ),
37 m_project( aProject ),
38 m_kiway( aKiway ),
39 m_toolManager( std::make_unique<TOOL_MANAGER>() )
40{
41 wxCHECK( aFootprint, /* void */ );
42 wxCHECK( m_project, /* void */ );
43
44 m_board->SetBoardUse( BOARD_USE::FPHOLDER );
45 m_board->SetProject( m_project );
46 aFootprint->SetParent( m_board.get() );
47 m_board->Add( aFootprint.release() );
48 m_toolManager->SetEnvironment( m_board.get(), nullptr, nullptr, aSettings, nullptr );
49}
50
51
53
54
56{
57 return m_board.get();
58}
59
60
62{
63 wxASSERT( m_project );
64 return *m_project;
65}
66
67
72
73
78
79
81{
82 if( !aFootprint )
83 return false;
84
85 wxString libraryName = m_fpid.GetLibNickname();
86
87 if( libraryName.IsEmpty() )
88 return false;
89
90 return SaveFootprintInLibrary( aFootprint, libraryName );
91}
92
93
95 const wxString& aLibraryName )
96{
97 if( !aFootprint )
98 return false;
99
100 try
101 {
102 aFootprint->SetFPID( LIB_ID( wxEmptyString, aFootprint->GetFPID().GetLibItemName() ) );
103
104 aFootprint->RunOnChildren(
105 []( BOARD_ITEM* child )
106 {
107 child->ClearFlags();
108 },
110
112 adapter->SaveFootprint( aLibraryName, aFootprint );
113
114 aFootprint->SetFPID( LIB_ID( aLibraryName, aFootprint->GetFPID().GetLibItemName() ) );
115 m_fpid = aFootprint->GetFPID();
116
117 return true;
118 }
119 catch( const IO_ERROR& )
120 {
121 aFootprint->SetFPID( LIB_ID( aLibraryName, aFootprint->GetFPID().GetLibItemName() ) );
122 return false;
123 }
124}
@ FPHOLDER
Definition board.h:315
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:158
An interface to the global shared library manager that is schematic-specific and linked to one projec...
SAVE_T SaveFootprint(const wxString &aNickname, const FOOTPRINT *aFootprint, bool aOverwrite=true)
Write aFootprint to an existing library given by aNickname.
void SetFPID(const LIB_ID &aFPID)
Definition footprint.h:430
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
const LIB_ID & GetFPID() const
Definition footprint.h:429
TOOL_MANAGER * GetToolManager() const override
bool SaveFootprintInLibrary(FOOTPRINT *aFootprint, const wxString &aLibraryName) override
~HEADLESS_FOOTPRINT_CONTEXT() override
bool SaveFootprint(FOOTPRINT *aFootprint) override
std::unique_ptr< TOOL_MANAGER > m_toolManager
HEADLESS_FOOTPRINT_CONTEXT(std::unique_ptr< FOOTPRINT > aFootprint, const LIB_ID &aFPID, PROJECT *aProject, APP_SETTINGS_BASE *aSettings, KIWAY *aKiway=nullptr)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:315
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
const UTF8 & GetLibItemName() const
Definition lib_id.h:102
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
Container for project specific data.
Definition project.h:66
Master controller class:
@ RECURSE
Definition eda_item.h:53
STL namespace.