KiCad PCB EDA Suite
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 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
56
58}
59
60
62{
63 std::shared_ptr<NET_SETTINGS>& netSettings = m_frame->Prj().GetProjectFile().m_NetSettings;
64
65 if( m_patternCtrl->GetValue().IsEmpty() )
66 return true;
67
68 netSettings->m_NetClassPatternAssignments.push_back(
69 {
70 std::make_unique<EDA_COMBINED_MATCHER>( m_patternCtrl->GetValue(), CTX_NETCLASS ),
71 m_netclassCtrl->GetStringSelection()
72 } );
73
74 return true;
75}
76
77
78void DIALOG_ASSIGN_NETCLASS::onPatternText( wxCommandEvent& aEvent )
79{
80 wxString pattern = m_patternCtrl->GetValue();
81
82 if( pattern != m_lastPattern )
83 {
85
86 std::vector<wxString> matchingNetNames;
87
88 if( !pattern.IsEmpty() )
89 {
90 EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
91
92 m_matchingNets->Report( _( "<b>Currently matching nets:</b>" ) );
93
94 for( const wxString& net : m_netCandidates )
95 {
96 int matches;
97 int offset;
98
99 if( matcher.Find( net, matches, offset ) && offset == 0 )
100 {
101 m_matchingNets->Report( net );
102 matchingNetNames.push_back( net );
103 }
104 }
105 }
106
108
109 m_previewer( matchingNetNames );
110 m_lastPattern = pattern;
111 }
112}
113
114
const char * name
Definition: DXF_plotter.cpp:56
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.
bool Find(const wxString &aTerm, int &aMatchersTriggered, int &aPosition)
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:49
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
Definition: project_file.h:168
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:148
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
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144