KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_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/sch_context.h>
22#include <api/sch_api_save.h>
23
24#include <kiway_player.h>
25#include <sch_edit_frame.h>
26#include <tool/tool_manager.h>
27#include <tools/sch_actions.h>
28
29
31{
32public:
34 m_frame( aFrame )
35 {
36 }
37
38 SCHEMATIC* GetSchematic() const override
39 {
40 return &m_frame->Schematic();
41 }
42
43 PROJECT& Prj() const override
44 {
45 return m_frame->Prj();
46 }
47
48 TOOL_MANAGER* GetToolManager() const override
49 {
50 return m_frame->GetToolManager();
51 }
52
53 KIWAY* GetKiway() const override
54 {
55 return &m_frame->Kiway();
56 }
57
58 wxString GetCurrentFileName() const override
59 {
60 return m_frame->GetCurrentFileName();
61 }
62
63 bool CanAcceptApiCommands() const override
64 {
65 return m_frame->CanAcceptApiCommands();
66 }
67
68 std::optional<SCH_SHEET_PATH> GetCurrentSheet() const override
69 {
70 return m_frame->GetCurrentSheet();
71 }
72
73 bool SaveSchematic() override
74 {
75 return SCH_API_SAVE::SaveSchematic( m_frame->Schematic(), m_frame->Prj() );
76 }
77
78 bool SaveSchematicCopy( const wxString& aFileName, bool aCreateProject ) override
79 {
80 return SCH_API_SAVE::SaveSchematicCopy( m_frame->Schematic(), m_frame->Prj(), aFileName, aCreateProject );
81 }
82
83 bool RevertToSaved() override
84 {
85 wxFileName fn = m_frame->Prj().AbsolutePath( m_frame->Schematic().GetFileName() );
86
87 if( m_frame->GetCurrentSheet().Last() != &m_frame->Schematic().Root() )
88 {
89 SCH_SHEET_PATH rootSheetPath = m_frame->Schematic().Hierarchy().at( 0 );
90 m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, &rootSheetPath );
91 }
92
93 SCH_SCREENS screenList( m_frame->Schematic().Root() );
94
95 for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
96 screen->SetContentModified( false );
97
98 m_frame->ReleaseFile();
99 m_frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ), KICTL_REVERT );
100
101 return true;
102 }
103
104private:
106};
107
108
109std::shared_ptr<SCH_CONTEXT> CreateSchFrameContext( SCH_EDIT_FRAME* aFrame )
110{
111 return std::make_shared<SCH_EDIT_FRAME_CONTEXT>( aFrame );
112}
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:340
Container for project specific data.
Definition project.h:63
Holds all the data relating to one schematic.
Definition schematic.h:148
static TOOL_ACTION changeSheet
An interface for the frame surface that the SCH API handlers need; to enable headless mode.
Definition sch_context.h:39
std::optional< SCH_SHEET_PATH > GetCurrentSheet() const override
SCH_EDIT_FRAME * m_frame
SCHEMATIC * GetSchematic() const override
bool CanAcceptApiCommands() const override
PROJECT & Prj() const override
bool SaveSchematicCopy(const wxString &aFileName, bool aCreateProject) override
bool RevertToSaved() override
KIWAY * GetKiway() const override
bool SaveSchematic() override
wxString GetCurrentFileName() const override
SCH_EDIT_FRAME_CONTEXT(SCH_EDIT_FRAME *aFrame)
TOOL_MANAGER * GetToolManager() const override
Schematic editor (Eeschema) main window.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition sch_screen.h:758
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Master controller class:
#define KICTL_REVERT
reverting to a previously-saved (KiCad) file.
bool SaveSchematic(SCHEMATIC &aSchematic, PROJECT &aProject)
Save every screen in the hierarchy to its current path, then update the project file.
bool SaveSchematicCopy(SCHEMATIC &aSchematic, PROJECT &aProject, const wxString &aFileName, bool aCreateProject)
Save the root schematic to aFileName without changing the open document.
std::shared_ptr< SCH_CONTEXT > CreateSchFrameContext(SCH_EDIT_FRAME *aFrame)