KiCad PCB EDA Suite
Loading...
Searching...
No Matches
conn_presentation.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
21#include <netclass.h>
22#include <sch_item.h>
24#include <advanced_config.h>
25#include <bus_alias.h>
26#include <schematic.h>
28#include <units_provider.h>
29#include <boost/algorithm/string/join.hpp>
30#include <wx/thread.h>
31#include <sch_connection.h>
32#include <string_utils.h>
33#include <widgets/msgpanel.h>
34
36 const SCH_ITEM& aItem, std::vector<MSG_PANEL_ITEM>& aList, const SCH_SHEET_PATH* aPath )
37{
38 wxASSERT( wxThread::IsMain() );
39 wxString name;
40 bool isBus;
41
42 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
43 {
44 SCHEMATIC* schematic = aItem.Schematic();
45
46 if( !schematic || !schematic->IsValid() )
47 return std::nullopt;
48
49 const SCH_SHEET_PATH& path = aPath ? *aPath : schematic->CurrentSheet();
50 const auto connection = schematic->Connectivity().Connection( aItem.m_Uuid, path.PathRef() );
51
52 if( !connection )
53 return std::nullopt;
54
55 name = connection->Name();
56 isBus = connection->IsBus();
57 aList.emplace_back( _( "Connection Name" ), UnescapeString( name ) );
58
59 if( isBus )
60 {
61 auto appendAlias = [&]( const std::shared_ptr<BUS_ALIAS>& alias )
62 {
63 aList.emplace_back( wxString::Format( _( "Bus Alias %s Members" ), alias->GetName() ),
64 boost::algorithm::join( alias->Members(), " " ) );
65 };
66 const wxString localName = connection->Name( true );
67
68 if( const auto alias = schematic->GetBusAlias( localName ) )
69 {
70 appendAlias( alias );
71 }
72 else
73 {
74 wxString group;
75 std::vector<wxString> members;
76
77 if( NET_SETTINGS::ParseBusGroup( localName, &group, &members ) )
78 {
79 for( const wxString& member : members )
80 {
81 if( const auto memberAlias = schematic->GetBusAlias( member ) )
82 appendAlias( memberAlias );
83 }
84 }
85 }
86 }
87
88#if defined(DEBUG)
89 aList.emplace_back( "Subgraph Code", wxString::Format( "%u", connection->SubgraphCode() ) );
90
91 if( SCH_ITEM* driver = connection->Driver() )
92 {
94 aList.emplace_back( "Connection Source", wxString::Format( "%s at %p",
95 driver->GetItemDescription( &units, false ), driver ) );
96 }
97#endif
98 }
99 else
100 {
101 const SCH_CONNECTION* connection = aItem.Connection( aPath );
102
103 if( !connection )
104 return std::nullopt;
105
106 connection->AppendInfoToMsgPanel( aList );
107 name = connection->Name();
108 isBus = connection->IsBus();
109 }
110
111 if( isBus )
112 return std::nullopt;
113
114 aList.emplace_back( _( "Resolved Netclass" ),
116 return name;
117}
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
const KIID m_Uuid
Definition eda_item.h:599
const wxString GetHumanReadableName() const
Gets the consolidated name of this netclass (which may be an aggregate).
Definition netclass.cpp:334
static bool ParseBusGroup(const wxString &aGroup, wxString *name, std::vector< wxString > *aMemberList, size_t *aPrefixEnd=nullptr)
Parse a bus group label into the name and a list of components.
Holds all the data relating to one schematic.
Definition schematic.h:149
std::shared_ptr< BUS_ALIAS > GetBusAlias(const wxString &aLabel) const
Return a pointer to a bus alias object for the given label, or null if one doesn't exist.
SCH_CONNECTIVITY::FACADE & Connectivity() const
Definition schematic.h:316
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition schematic.h:289
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:304
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString Name(bool aIgnoreSheet=false) const
bool IsBus() const
void AppendInfoToMsgPanel(std::vector< MSG_PANEL_ITEM > &aList) const
Adds information about the connection object to aList.
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
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:302
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition sch_item.cpp:733
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition sch_item.cpp:580
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
#define _(s)
Message panel definition file.
std::optional< wxString > AppendConnectionInfo(const SCH_ITEM &aItem, std::vector< MSG_PANEL_ITEM > &aList, const SCH_SHEET_PATH *aPath=nullptr)
Append connection details; return its name for a signal, or no value for a bus/missing row.
wxString UnescapeString(const wxString &aSource)
std::string path