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
30
32 const std::set<wxString> aCandidateNetNames,
33 const std::function<void( const std::vector<wxString>& )>& aPreviewer ) :
35 m_frame( aParent ),
36 m_netCandidates( aCandidateNetNames ),
37 m_previewer( aPreviewer )
38{
39 std::shared_ptr<NET_SETTINGS>& netSettings = m_frame->Prj().GetProjectFile().m_NetSettings;
40
42
43 for( const auto& [ name, netclass ] : netSettings->m_NetClasses )
44 m_netclassCtrl->Append( name );
45
46 if( m_netclassCtrl->GetCount() > 1 )
47 m_netclassCtrl->SetSelection( 1 ); // First non-Default netclass
48 else
49 m_netclassCtrl->SetSelection( 0 ); // Default netclass
50
51 m_patternCtrl->SetValue( aNetName );
52 m_matchingNets->SetFont( KIUI::GetInfoFont( this ) );
53 m_info->SetFont( KIUI::GetInfoFont( this ).Italic() );
54
55 if( aParent->GetFrameType() == FRAME_PCB_EDITOR )
56 m_info->SetLabel( wxT( "Note: complete netclass assignments can be edited in Board Setup > Project." ) );
57
59
61}
62
63
65{
66 std::shared_ptr<NET_SETTINGS>& netSettings = m_frame->Prj().GetProjectFile().m_NetSettings;
67
68 if( m_patternCtrl->GetValue().IsEmpty() )
69 return true;
70
71 // TODO: Rework when we support multiple netclass assignments
72 // Replace existing assignment if we have one
73 for( auto& assignment : netSettings->m_NetClassPatternAssignments )
74 {
75 if( assignment.first->GetPattern() == m_patternCtrl->GetValue() )
76 {
77 assignment.second = m_netclassCtrl->GetStringSelection();
78 return true;
79 }
80 }
81
82 // No assignment, add a new one
83 netSettings->m_NetClassPatternAssignments.push_back(
84 {
85 std::make_unique<EDA_COMBINED_MATCHER>( m_patternCtrl->GetValue(), CTX_NETCLASS ),
86 m_netclassCtrl->GetStringSelection()
87 } );
88
89 netSettings->m_NetClassPatternAssignmentCache.clear();
90
91 return true;
92}
93
94
95void DIALOG_ASSIGN_NETCLASS::onPatternText( wxCommandEvent& aEvent )
96{
97 wxString pattern = m_patternCtrl->GetValue();
98
99 if( pattern != m_lastPattern )
100 {
102
103 std::vector<wxString> matchingNetNames;
104
105 if( !pattern.IsEmpty() )
106 {
107 EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
108
109 m_matchingNets->Report( _( "<b>Currently matching nets:</b>" ) );
110
111 for( const wxString& net : m_netCandidates )
112 {
113 if( matcher.StartsWith( net ) )
114 {
115 m_matchingNets->Report( net );
116 matchingNetNames.push_back( net );
117 }
118 }
119 }
120
122
123 m_previewer( matchingNetNames );
124 m_lastPattern = pattern;
125 }
126}
127
128
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)
@ CTX_NETCLASS
@ FRAME_PCB_EDITOR
Definition: frame_type.h:42
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:151