KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_target3001.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
22
24
25#include <wx/filename.h>
26
27#include <progress_reporter.h>
28#include <project.h>
29#include <sch_screen.h>
30#include <sch_sheet.h>
31#include <sch_sheet_path.h>
32#include <schematic.h>
34
35
36bool SCH_IO_TARGET3001::CanReadSchematicFile( const wxString& aFileName ) const
37{
38 if( !SCH_IO::CanReadSchematicFile( aFileName ) )
39 return false;
40
41 return TARGET3001::LooksLikeProject( aFileName );
42}
43
44
45SCH_SHEET* SCH_IO_TARGET3001::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
46 SCH_SHEET* aAppendToMe,
47 const std::map<std::string, UTF8>* aProperties )
48{
49 wxASSERT( !aFileName.IsEmpty() && aSchematic != nullptr );
50
52 {
53 m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
54
55 if( !m_progressReporter->KeepRefreshing() )
57 }
58
60
61 wxFileName newFilename( aFileName );
62 newFilename.SetExt( FILEEXT::KiCadSchematicFileExtension );
63
64 SCH_SHEET* rootSheet = nullptr;
65
66 if( aAppendToMe )
67 {
68 wxCHECK_MSG( aSchematic->IsValid(), nullptr, wxT( "Can't append to a schematic with no root!" ) );
69 rootSheet = &aSchematic->Root();
70 }
71 else
72 {
73 // A real UUID lets SetTopLevelSheets() accept the content root as a top-level sheet
74 rootSheet = new SCH_SHEET( aSchematic );
75 rootSheet->SetFileName( newFilename.GetFullPath() );
76
77 SCH_SCREEN* screen = new SCH_SCREEN( aSchematic );
78 screen->SetFileName( newFilename.GetFullPath() );
79 rootSheet->SetScreen( screen );
80
81 aSchematic->SetTopLevelSheets( { rootSheet } );
82 }
83
84 if( !rootSheet->GetScreen() )
85 {
86 SCH_SCREEN* screen = new SCH_SCREEN( aSchematic );
87 screen->SetFileName( newFilename.GetFullPath() );
88 rootSheet->SetScreen( screen );
89 }
90
91 TARGET3001_SCH_BUILDER builder( aSchematic, rootSheet, project, aFileName, m_reporter );
92 builder.Build();
93
94 aSchematic->RefreshHierarchy();
95
96 // Foreign imports do not get per-sheet instance data from the native loader
97 if( !aAppendToMe )
98 {
99 wxString projectName = aSchematic->Project().GetProjectName();
100
101 if( projectName.IsEmpty() )
102 projectName = wxFileName( aFileName ).GetName();
103
104 SCH_SHEET_LIST sheets = aSchematic->BuildUnorderedSheetList();
105 sheets.AddNewSymbolInstances( SCH_SHEET_PATH(), projectName );
107
108 if( sheets.AllSheetPageNumbersEmpty() )
109 sheets.SetInitialPageNumbers();
110 }
111
112 return rootSheet;
113}
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
Definition io_base.h:242
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition io_base.h:245
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition project.cpp:273
Holds all the data relating to one schematic.
Definition schematic.h:149
SCH_SHEET_LIST BuildUnorderedSheetList() const
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:171
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition schematic.h:297
void SetTopLevelSheets(const std::vector< SCH_SHEET * > &aSheets)
Replace the top level sheets, rebuilding the hierarchy and connectivity around them.
SCH_SHEET & Root() const
Definition schematic.h:208
void RefreshHierarchy()
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_IO can read the specified schematic file.
Definition sch_io.cpp:47
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void AddNewSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath, const wxString &aProjectName)
Attempt to add new symbol instances for all symbols in this list of sheet paths prefixed with aPrefix...
void SetInitialPageNumbers()
Set initial sheet page numbers.
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
void AddNewSheetInstances(const SCH_SHEET_PATH &aPrefixSheetPath, int aLastVirtualPageNumber)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
void SetFileName(const wxString &aFilename)
Definition sch_sheet.h:398
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:151
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
#define _(s)
#define THROW_IO_CANCELLED()
static const std::string KiCadSchematicFileExtension
PROJECT ParseFile(const wxString &aFileName)
Parse a complete .T3001 file.
bool LooksLikeProject(const wxString &aFileName)
Cheap check used by the plugin managers: the extension matches and the header is plausible.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Definition of file extensions used in Kicad.