KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <api/pcb_context.h>
22
25#include <pcb_edit_frame.h>
26#include <reporter.h>
27#include <board.h>
28#include <project.h>
29
30
32{
33public:
35 m_frame( aFrame )
36 {
37 }
38
39 BOARD* GetBoard() const override
40 {
41 return m_frame->GetBoard();
42 }
43
44 PROJECT& Prj() const override
45 {
46 return m_frame->Prj();
47 }
48
49 TOOL_MANAGER* GetToolManager() const override
50 {
51 return m_frame->GetToolManager();
52 }
53
54 KIWAY* GetKiway() const override
55 {
56 return &m_frame->Kiway();
57 }
58
59 bool IsContentModified() const override
60 {
61 return m_frame->GetScreen()->IsContentModified();
62 }
63
64 void SetContentModified( bool aModified = true ) override
65 {
66 m_frame->GetScreen()->SetContentModified( aModified );
67 }
68
69 wxString GetCurrentFileName() const override
70 {
71 return m_frame->GetCurrentFileName();
72 }
73
74 bool CanAcceptApiCommands() const override
75 {
76 return m_frame->CanAcceptApiCommands();
77 }
78
79 bool SaveBoard() override
80 {
81 return m_frame->SaveBoard();
82 }
83
84 bool SavePcbCopy( const wxString& aFileName, bool aCreateProject, bool aHeadless ) override
85 {
86 return m_frame->SavePcbCopy( aFileName, aCreateProject, aHeadless );
87 }
88
89 bool ReadNetlistFromFile( const wxString& aFilename, NETLIST& aNetlist, REPORTER& aReporter ) override
90 {
91 return m_frame->ReadNetlistFromFile( aFilename, aNetlist, aReporter );
92 }
93
94 std::unique_ptr<BOARD_NETLIST_UPDATER> MakeNetlistUpdater() override
95 {
96 return std::make_unique<BOARD_NETLIST_UPDATER>( m_frame, GetBoard() );
97 }
98
99 void OnNetlistChanged( BOARD_NETLIST_UPDATER& aUpdater ) override
100 {
101 bool runDragCommand = false;
102 m_frame->OnNetlistChanged( aUpdater, &runDragCommand );
103 }
104
105 bool RevertToSaved() override
106 {
107 wxFileName fn = m_frame->Prj().AbsolutePath( m_frame->GetBoard()->GetFileName() );
108
109 m_frame->GetScreen()->SetContentModified( false );
110 m_frame->ReleaseFile();
111 m_frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ), KICTL_REVERT );
112
113 return true;
114 }
115
116private:
118};
119
120
121std::shared_ptr<PCB_CONTEXT> CreatePcbFrameContext( PCB_EDIT_FRAME* aFrame )
122{
123 return std::make_shared<PCB_EDIT_FRAME_CONTEXT>( aFrame );
124}
Update the BOARD with a new netlist.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:340
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
PCB-editor-specific context; extends BOARD_CONTEXT with save/filename operations.
Definition pcb_context.h:38
TOOL_MANAGER * GetToolManager() const override
bool SavePcbCopy(const wxString &aFileName, bool aCreateProject, bool aHeadless) override
bool IsContentModified() const override
std::unique_ptr< BOARD_NETLIST_UPDATER > MakeNetlistUpdater() override
Create a netlist updater bound to this context's board.
wxString GetCurrentFileName() const override
bool SaveBoard() override
PROJECT & Prj() const override
bool CanAcceptApiCommands() const override
bool ReadNetlistFromFile(const wxString &aFilename, NETLIST &aNetlist, REPORTER &aReporter) override
Read a netlist file and preload component footprints.
PCB_EDIT_FRAME_CONTEXT(PCB_EDIT_FRAME *aFrame)
void OnNetlistChanged(BOARD_NETLIST_UPDATER &aUpdater) override
Post-import board sync (nets, classes, DRC, ratsnest, new footprint placement).
bool RevertToSaved() override
KIWAY * GetKiway() const override
void SetContentModified(bool aModified=true) override
BOARD * GetBoard() const override
PCB_EDIT_FRAME * m_frame
The main frame for Pcbnew.
Container for project specific data.
Definition project.h:63
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
Master controller class:
#define KICTL_REVERT
reverting to a previously-saved (KiCad) file.
std::shared_ptr< PCB_CONTEXT > CreatePcbFrameContext(PCB_EDIT_FRAME *aFrame)