KiCad PCB EDA Suite
test_sch_sheet_list.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 (C) 2020 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 "eeschema_test_utils.h"
22 
23 #include <sch_io_mgr.h>
24 #include <sch_screen.h>
25 #include <sch_sheet_path.h>
26 #include <schematic.h>
29 
30 
32 {
33 public:
35  m_schematic( nullptr ),
36  m_manager( true )
37  {
38  m_pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD );
39  }
40 
42  {
44  delete m_pi;
45  }
46 
47  void loadSchematic( const wxString& aBaseName );
48 
51 
53 
55 };
56 
57 
58 void TEST_SCH_SHEET_LIST_FIXTURE::loadSchematic( const wxString& aBaseName )
59 {
60  wxFileName fn = KI_TEST::GetEeschemaTestDataDir();
61 
62  fn.AppendDir( "netlists" );
63  fn.AppendDir( aBaseName );
64  fn.SetName( aBaseName );
65  fn.SetExt( KiCadSchematicFileExtension );
66 
67  BOOST_TEST_MESSAGE( fn.GetFullPath() );
68 
69  wxFileName pro( fn );
70  pro.SetExt( ProjectFileExtension );
71 
72  m_manager.LoadProject( pro.GetFullPath() );
73 
75 
78  m_schematic.SetRoot( m_pi->Load( fn.GetFullPath(), &m_schematic ) );
79 
80  BOOST_REQUIRE_EQUAL( m_pi->GetError().IsEmpty(), true );
81 
83 
84  SCH_SCREENS screens( m_schematic.Root() );
85 
86  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
87  screen->UpdateLocalLibSymbolLinks();
88 
90 
91  // Restore all of the loaded symbol instances from the root sheet screen.
93 
94  sheets.AnnotatePowerSymbols();
95 
96  // NOTE: This is required for multi-unit symbols to be correct
97  // Normally called from SCH_EDIT_FRAME::FixupJunctions() but could be refactored
98  for( SCH_SHEET_PATH& sheet : sheets )
99  sheet.UpdateAllScreenReferences();
100 }
101 
102 
103 BOOST_FIXTURE_TEST_SUITE( SchSheetList, TEST_SCH_SHEET_LIST_FIXTURE )
104 
105 
106 BOOST_AUTO_TEST_CASE( TestSheetListPageProperties )
107 {
108  loadSchematic( "complex_hierarchy" );
109 
110  SCH_SHEET_LIST sheets = m_schematic.GetSheets();
111 
113 
114  sheets.SetInitialPageNumbers();
115 
116  // The root sheet should now be page 1.
117  BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "1" );
118  BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "2" );
119  BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "3" );
120 }
121 
122 
123 BOOST_AUTO_TEST_SUITE_END()
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:58
const std::string ProjectFileExtension
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
const std::vector< SYMBOL_INSTANCE_REFERENCE > & GetSymbolInstances() const
Definition: sch_screen.h:505
virtual SCH_SHEET * Load(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL)
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:51
BOOST_CHECK(v2.Cross(v1)==1)
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
void SetRoot(SCH_SHEET *aRootSheet)
Initializes the schematic with a new root sheet.
Definition: schematic.cpp:100
void loadSchematic(const wxString &aBaseName)
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:153
SCHEMATIC m_schematic
Schematic to load
Definition of file extensions used in Kicad.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:73
void UpdateSymbolInstances(const std::vector< SYMBOL_INSTANCE_REFERENCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
wxFileName GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
void Reset()
Initializes this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:50
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:111
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
SCH_SHEET & Root() const
Definition: schematic.h:116
virtual const wxString & GetError() const
Return an error string to the caller.
Definition: sch_plugin.cpp:177
const std::string KiCadSchematicFileExtension
BOOST_AUTO_TEST_CASE(TestSheetListPageProperties)
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
SCH_SCREEN * RootScreen() const
Helper to retreive the screen of the root sheet.
Definition: schematic.cpp:113
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:141
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
void SetInitialPageNumbers()
Set initial sheet page numbers.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:536