KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_diff_utils.h
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 3
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, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 */
20
21#ifndef SCH_DIFF_UTILS_H
22#define SCH_DIFF_UTILS_H
23
24#include <schematic.h>
25#include <sch_item.h>
26#include <sch_screen.h>
27#include <sch_sheet_path.h>
28
29
30namespace KICAD_DIFF
31{
32
47{
48public:
49 SHEET_SCOPE( const SCHEMATIC* aSch, const SCH_SHEET_PATH* aPath ) :
50 m_sch( aSch ),
51 m_saved( aSch ? aSch->CurrentSheet() : SCH_SHEET_PATH{} )
52 {
53 if( m_sch && aPath )
54 m_sch->CurrentSheet() = *aPath;
55 }
56
58 {
59 if( m_sch )
60 m_sch->CurrentSheet() = m_saved;
61 }
62
63 SHEET_SCOPE( const SHEET_SCOPE& ) = delete;
64 SHEET_SCOPE& operator=( const SHEET_SCOPE& ) = delete;
65
66private:
69};
70
71
97template <typename SHEET_VISITOR, typename ITEM_VISITOR>
98void WalkSchematic( const SCHEMATIC* aSchematic, SHEET_VISITOR&& aSheetVisitor, ITEM_VISITOR&& aItemVisitor,
99 const KIID_PATH& aScope = {} )
100{
101 if( !aSchematic )
102 return;
103
105
106 for( const SCH_SHEET_PATH& path : sheets )
107 {
108 const KIID_PATH sheetPath = path.Path();
109
110 if( !aScope.empty() && sheetPath != aScope )
111 continue;
112
113 aSheetVisitor( path );
114
115 SCH_SCREEN* screen = path.LastScreen();
116
117 if( !screen )
118 continue;
119
120 for( SCH_ITEM* item : screen->Items() )
121 {
122 if( !item )
123 continue;
124
125 // Scoped mode emits just the item KIID so items align across
126 // schematics with different hierarchies.
127 KIID_PATH kiidPath;
128
129 if( aScope.empty() )
130 kiidPath = sheetPath;
131
132 kiidPath.push_back( item->m_Uuid );
133
134 aItemVisitor( item, path, kiidPath );
135 }
136 }
137}
138
139} // namespace KICAD_DIFF
140
141#endif // SCH_DIFF_UTILS_H
SHEET_SCOPE(const SHEET_SCOPE &)=delete
SHEET_SCOPE(const SCHEMATIC *aSch, const SCH_SHEET_PATH *aPath)
const SCHEMATIC * m_sch
SHEET_SCOPE & operator=(const SHEET_SCOPE &)=delete
Holds all the data relating to one schematic.
Definition schematic.h:90
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:115
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void WalkSchematic(const SCHEMATIC *aSchematic, SHEET_VISITOR &&aSheetVisitor, ITEM_VISITOR &&aItemVisitor, const KIID_PATH &aScope={})
Visit every SCH_ITEM in every sheet of aSchematic in page-number order.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::string path