KiCad PCB EDA Suite
Loading...
Searching...
No Matches
headless_board_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 * @author Jon Evans <[email protected]>
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <board.h>
23#include <board_loader.h>
24#include <project.h>
26#include <tool/tool_manager.h>
27#include <wx/debug.h>
28
29
30HEADLESS_BOARD_CONTEXT::HEADLESS_BOARD_CONTEXT( std::unique_ptr<BOARD> aBoard, PROJECT* aProject,
31 APP_SETTINGS_BASE* aSettings,
32 KIWAY* aKiway ) :
33 m_board( std::move( aBoard ) ),
34 m_project( aProject ),
35 m_kiway( aKiway ),
36 m_toolManager( std::make_unique<TOOL_MANAGER>() )
37{
38 wxCHECK( m_board, /* void */ );
39 wxCHECK( m_project, /* void */ );
40
41 m_board->SetProject( m_project );
42 m_toolManager->SetEnvironment( m_board.get(), nullptr, nullptr, aSettings, nullptr );
43}
44
45
47
48
50{
51 return m_board.get();
52}
53
54
56{
57 // Shouldn't be able to construct this without a project
58 wxASSERT( m_project );
59 return *m_project;
60}
61
62
67
68
70{
71 if( !m_board )
72 return wxEmptyString;
73
74 return m_board->GetFileName();
75}
76
77
79{
80 if( !m_board )
81 return false;
82
83 wxString fileName = m_board->GetFileName();
84
85 if( fileName.IsEmpty() )
86 return false;
87
88 bool success = BOARD_LOADER::SaveBoard( fileName, m_board.get() );
89
90 if( success )
91 {
92 wxFileName pro = fileName;
94 pro.MakeAbsolute();
95
96 Pgm().GetSettingsManager().SaveProjectAs( pro.GetFullPath(), m_board->GetProject() );
97 }
98
99 return success;
100}
101
102
103bool HEADLESS_BOARD_CONTEXT::SavePcbCopy( const wxString& aFileName, bool aCreateProject, bool aHeadless )
104{
105 if( !m_board || aFileName.IsEmpty() )
106 return false;
107
108 wxString outPath = aFileName;
109
110 bool success = BOARD_LOADER::SaveBoard( outPath, m_board.get() );
111
112 if( success && aCreateProject )
113 {
114 wxFileName pro = aFileName;
115 pro.SetExt( FILEEXT::ProjectFileExtension );
116 pro.MakeAbsolute();
117
118 Pgm().GetSettingsManager().SaveProjectAs( pro.GetFullPath(), m_board->GetProject() );
119 }
120
121 return success;
122}
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
static bool SaveBoard(wxString &aFileName, BOARD *aBoard, PCB_IO_MGR::PCB_FILE_T aFormat)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
PROJECT & Prj() const override
TOOL_MANAGER * GetToolManager() const override
BOARD * GetBoard() const override
std::unique_ptr< TOOL_MANAGER > m_toolManager
HEADLESS_BOARD_CONTEXT(std::unique_ptr< BOARD > aBoard, PROJECT *aProject, APP_SETTINGS_BASE *aSettings, KIWAY *aKiway=nullptr)
std::unique_ptr< BOARD > m_board
wxString GetCurrentFileName() const override
bool SavePcbCopy(const wxString &aFileName, bool aCreateProject, bool aHeadless) override
~HEADLESS_BOARD_CONTEXT() override
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:315
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:130
Container for project specific data.
Definition project.h:66
void SaveProjectAs(const wxString &aFullPath, PROJECT *aProject=nullptr)
Set the currently loaded project path and saves it (pointers remain valid).
Master controller class:
static const std::string ProjectFileExtension
STL namespace.
PGM_BASE & Pgm()
The global program "get" accessor.