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->GetNetclasses() )
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 netSettings->SetNetclassPatternAssignment( m_patternCtrl->GetValue(),
73 m_netclassCtrl->GetStringSelection() );
74
75 return true;
76}
77
78
79void DIALOG_ASSIGN_NETCLASS::onPatternText( wxCommandEvent& aEvent )
80{
81 wxString pattern = m_patternCtrl->GetValue();
82
83 if( pattern != m_lastPattern )
84 {
86
87 std::vector<wxString> matchingNetNames;
88
89 if( !pattern.IsEmpty() )
90 {
91 EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
92
93 m_matchingNets->Report( _( "<b>Currently matching nets:</b>" ) );
94
95 for( const wxString& net : m_netCandidates )
96 {
97 if( matcher.StartsWith( net ) )
98 {
99 m_matchingNets->Report( net );
100 matchingNetNames.push_back( net );
101 }
102 }
103 }
104
106
107 m_previewer( matchingNetNames );
108 m_lastPattern = pattern;
109 }
110}
111
112
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:178
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:200
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