KiCad PCB EDA Suite
Loading...
Searching...
No Matches
conn_preview.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 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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "conn_preview.h"
21#include "conn_facade.h"
22#include <sch_item.h>
23#include <sch_screen.h>
24#include <sch_sheet_path.h>
25
26namespace SCH_CONNECTIVITY
27{
29{
31 SCH_SCREEN* screen = aPath.LastScreen();
32
33 if( !screen )
34 return result;
35
36 result.reserve( screen->Items().size() );
37 const KIID_PATH& path = aPath.PathRef();
38 const auto capture = [&]( SCH_ITEM* item )
39 {
40 if( !item->IsConnectable() )
41 return;
42
43 const auto connection = aFacade.Connection( item->m_Uuid, path );
44 const int code = connection && connection->IsNet() && !connection->IsUnconnected() ? connection->NetCode() : 0;
45 result.emplace( item, code > 0 ? std::optional<int>( code ) : std::nullopt );
46 };
47
48 for( SCH_ITEM* item : screen->Items() )
49 {
50 capture( item );
51 item->RunOnChildren( capture, RECURSE_MODE::NO_RECURSE );
52 }
53
54 return result;
55}
56} // namespace SCH_CONNECTIVITY
size_t size() const
Return the number of items in the tree.
Definition sch_rtree.h:177
Model-owned source resolver.
std::optional< ITEM_VIEW > Connection(const KIID &aItem, const KIID_PATH &aPath) const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
const KIID_PATH & PathRef() const
Borrow the cached path until this sheet path is modified or destroyed.
@ NO_RECURSE
Definition eda_item.h:52
Value keys and the key session of the schematic connectivity engine.
std::unordered_map< const SCH_ITEM *, std::optional< int > > PREVIEW_NET_CODES
PREVIEW_NET_CODES CapturePreviewNetCodes(const FACADE &aFacade, const SCH_SHEET_PATH &aPath)
Owned local net assignments for advisory drag feedback; unavailable rows remain unknown.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::string path
wxString result
Test unit parsing edge cases and error handling.