KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_assign_netclass.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) 2022-2023 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
26#include <project.h>
29#include <eda_base_frame.h>
30
31
33 const std::set<wxString> aCandidateNetNames,
34 const std::function<void( const std::vector<wxString>& )>& aPreviewer ) :
36 m_frame( aParent ),
37 m_netCandidates( aCandidateNetNames ),
38 m_previewer( aPreviewer )
39{
40 std::shared_ptr<NET_SETTINGS>& netSettings = m_frame->Prj().GetProjectFile().m_NetSettings;
41
43
44 for( const auto& [ name, netclass ] : netSettings->m_NetClasses )
45 m_netclassCtrl->Append( name );
46
47 if( m_netclassCtrl->GetCount() > 1 )
48 m_netclassCtrl->SetSelection( 1 ); // First non-Default netclass
49 else
50 m_netclassCtrl->SetSelection( 0 ); // Default netclass
51
52 m_patternCtrl->SetValue( aNetName );
53 m_matchingNets->SetFont( KIUI::GetInfoFont( this ) );
54 m_info->SetFont( KIUI::GetInfoFont( this ).Italic() );
55
56 if( aParent->GetFrameType() == FRAME_PCB_EDITOR )
57 m_info->SetLabel( wxT( "Note: complete netclass assignments can be edited in Board Setup > Project." ) );
58
60
62}
63
64
66{
67 std::shared_ptr<NET_SETTINGS>& netSettings = m_frame->Prj().GetProjectFile().m_NetSettings;
68
69 if( m_patternCtrl->GetValue().IsEmpty() )
70 return true;
71
72 // TODO: Rework when we support multiple netclass assignments
73 // Replace existing assignment if we have one
74 for( auto& assignment : netSettings->m_NetClassPatternAssignments )
75 {
76 if( assignment.first->GetPattern() == m_patternCtrl->GetValue() )
77 {
78 assignment.second = m_netclassCtrl->GetStringSelection();
79 return true;
80 }
81 }
82
83 // No assignment, add a new one
84 netSettings->m_NetClassPatternAssignments.push_back(
85 {
86 std::make_unique<EDA_COMBINED_MATCHER>( m_patternCtrl->GetValue(), CTX_NETCLASS ),
87 m_netclassCtrl->GetStringSelection()
88 } );
89
90 netSettings->m_NetClassPatternAssignmentCache.clear();
91
92 return true;
93}
94
95
96void DIALOG_ASSIGN_NETCLASS::onPatternText( wxCommandEvent& aEvent )
97{
98 wxString pattern = m_patternCtrl->GetValue();
99
100 if( pattern != m_lastPattern )
101 {
103
104 std::vector<wxString> matchingNetNames;
105
106 if( !pattern.IsEmpty() )
107 {
108 EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
109
110 m_matchingNets->Report( _( "<b>Currently matching nets:</b>" ) );
111
112 for( const wxString& net : m_netCandidates )
113 {
114 if( matcher.StartsWith( net ) )
115 {
116 m_matchingNets->Report( net );
117 matchingNetNames.push_back( net );
118 }
119 }
120 }
121
123
124 m_previewer( matchingNetNames );
125 m_lastPattern = pattern;
126 }
127}
128
129
const char * name
Definition: DXF_plotter.cpp:57
Class DIALOG_ASSIGN_NETCLASS_BASE.
void onPatternText(wxCommandEvent &aEvent) override
std::function< void(const std::vector< wxString > &)> m_previewer
DIALOG_ASSIGN_NETCLASS(EDA_BASE_FRAME *aParent, const wxString aNetName, const std::set< wxString > aCandidateNetNames, const std::function< void(const std::vector< wxString > &)> &aPreviewer)
bool TransferDataFromWindow() override
std::set< wxString > m_netCandidates
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
The base frame for deriving all KiCad main window classes.
FRAME_T GetFrameType() const
bool StartsWith(const wxString &aTerm)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:46
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
Definition: project_file.h:173
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:166
void Clear()
Delete the stored messages.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
void Flush()
Build the HTML messages page.
#define _(s)
Base window classes and related definitions.
@ CTX_NETCLASS
@ FRAME_PCB_EDITOR
Definition: frame_type.h:42
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:154