KiCad PCB EDA Suite
pcbnew/dialogs/dialog_netlist.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) 1992-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
24#include <project.h>
25#include <kiface_base.h>
26#include <confirm.h>
27#include <pcb_edit_frame.h>
28#include <pcbnew_settings.h>
29#include <reporter.h>
30#include <bitmaps.h>
31#include <tool/tool_manager.h>
32#include <tools/pcb_actions.h>
37#include <project/project_file.h> // LAST_PATH_TYPE
38#include <dialog_netlist.h>
40#include <wx/filedlg.h>
41
42
44{
45 wxString netlistName = GetLastPath( LAST_PATH_NETLIST );
46
47 DIALOG_NETLIST_IMPORT dlg( this, netlistName );
48
49 dlg.ShowModal();
50
51 SetLastPath( LAST_PATH_NETLIST, netlistName );
52}
53
55
56
57DIALOG_NETLIST_IMPORT::DIALOG_NETLIST_IMPORT( PCB_EDIT_FRAME* aParent, wxString& aNetlistFullFilename )
58 : DIALOG_NETLIST_IMPORT_BASE( aParent ),
59 m_parent( aParent ),
60 m_netlistPath( aNetlistFullFilename ),
61 m_initialized( false ),
62 m_runDragCommand( false )
63{
66
67 auto cfg = m_parent->GetPcbNewSettings();
68
69 m_cbUpdateFootprints->SetValue( cfg->m_NetlistDialog.update_footprints );
70 m_cbDeleteShortingTracks->SetValue( cfg->m_NetlistDialog.delete_shorting_tracks );
71 m_cbDeleteExtraFootprints->SetValue( cfg->m_NetlistDialog.delete_extra_footprints );
72
73 m_matchByTimestamp->SetSelection( m_matchByUUID ? 0 : 1 );
74
75 m_MessageWindow->SetLabel( _("Changes To Be Applied") );
76 m_MessageWindow->SetVisibleSeverities( cfg->m_NetlistDialog.report_filter );
77 m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
78
79 SetupStandardButtons( { { wxID_OK, _( "Load and Test Netlist" ) },
80 { wxID_CANCEL, _( "Close" ) },
81 { wxID_APPLY, _( "Update PCB" ) } } );
82
84
85 m_initialized = true;
86}
87
89{
90 m_matchByUUID = m_matchByTimestamp->GetSelection() == 0;
91
93
98
100 {
102 controls->SetCursorPosition( controls->GetMousePosition() );
104 }
105}
106
107
109{
110 wxString dirPath = wxFileName( Prj().GetProjectFullName() ).GetPath();
111
112 wxString filename = m_parent->GetLastPath( LAST_PATH_NETLIST );
113
114 if( !filename.IsEmpty() )
115 {
116 wxFileName fn = filename;
117 dirPath = fn.GetPath();
118 filename = fn.GetFullName();
119 }
120
121 wxFileDialog FilesDialog( this, _( "Select Netlist" ), dirPath, filename,
122 NetlistFileWildcard(), wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
123
124 if( FilesDialog.ShowModal() != wxID_OK )
125 return;
126
127 m_NetlistFilenameCtrl->SetValue( FilesDialog.GetPath() );
128 onFilenameChanged( false );
129}
130
131
132void DIALOG_NETLIST_IMPORT::onImportNetlist( wxCommandEvent& event )
133{
134 onFilenameChanged( true );
135}
136
137
138void DIALOG_NETLIST_IMPORT::onUpdatePCB( wxCommandEvent& event )
139{
140 wxFileName fn = m_NetlistFilenameCtrl->GetValue();
141
142 if( !fn.IsOk() )
143 {
144 wxMessageBox( _( "Please choose a valid netlist file." ) );
145 return;
146 }
147
148 if( !fn.FileExists() )
149 {
150 wxMessageBox( _( "The netlist file does not exist." ) );
151 return;
152 }
153
154 m_MessageWindow->SetLabel( _( "Changes Applied to PCB" ) );
155 loadNetlist( false );
156
157 m_sdbSizerCancel->SetDefault();
158 m_sdbSizerCancel->SetFocus();
159}
160
161
163{
164 event.Skip();
165}
166
167
169{
170 if( m_initialized )
171 {
172 wxFileName fn = m_NetlistFilenameCtrl->GetValue();
173
174 if( fn.IsOk() )
175 {
176 if( fn.FileExists() )
177 {
179
180 if( aLoadNetlist )
181 loadNetlist( true );
182 }
183 else
184 {
186 REPORTER& reporter = m_MessageWindow->Reporter();
187 reporter.Report( _( "The netlist file does not exist." ), RPT_SEVERITY_ERROR );
188 }
189 }
190 }
191}
192
193
194void DIALOG_NETLIST_IMPORT::OnMatchChanged( wxCommandEvent& event )
195{
196 if( m_initialized )
197 loadNetlist( true );
198}
199
200
201void DIALOG_NETLIST_IMPORT::OnOptionChanged( wxCommandEvent& event )
202{
203 if( m_initialized )
204 loadNetlist( true );
205}
206
207
209{
210 wxString netlistFileName = m_NetlistFilenameCtrl->GetValue();
211 wxFileName fn = netlistFileName;
212
213 if( !fn.IsOk() || !fn.FileExists() )
214 return;
215
217 REPORTER& reporter = m_MessageWindow->Reporter();
218
219 wxBusyCursor busy;
220
221 wxString msg;
222 msg.Printf( _( "Reading netlist file '%s'.\n" ), netlistFileName );
223 reporter.ReportHead( msg, RPT_SEVERITY_INFO );
224
225 if( m_matchByTimestamp->GetSelection() == 1 )
226 msg = _( "Using reference designators to match symbols and footprints.\n" );
227 else
228 msg = _( "Using tstamps (unique IDs) to match symbols and footprints.\n" );
229
230 reporter.ReportHead( msg, RPT_SEVERITY_INFO );
231 m_MessageWindow->SetLazyUpdate( true ); // Use lazy update to speed the creation of the report
232 // (the window is not updated for each message)
233 m_matchByUUID = m_matchByTimestamp->GetSelection() == 0;
234
236
237 netlist.SetFindByTimeStamp( m_matchByUUID );
238 netlist.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
239
240 if( !m_parent->ReadNetlistFromFile( netlistFileName, netlist, reporter ) )
241 return;
242
244 updater.SetReporter ( &reporter );
245 updater.SetIsDryRun( aDryRun );
248 updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
249 updater.UpdateNetlist( netlist );
250
251 // The creation of the report was made without window update: the full page must be displayed
252 m_MessageWindow->Flush( true );
253
254 if( aDryRun )
255 return;
256
258}
259
260
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
@ small_folder
Update the BOARD with a new netlist.
void SetReporter(REPORTER *aReporter)
Enable dry run mode (just report, no changes to PCB).
bool UpdateNetlist(NETLIST &aNetlist)
Update the board's components according to the new netlist.
void SetIsDryRun(bool aEnabled)
void SetDeleteUnusedFootprints(bool aEnabled)
void SetReplaceFootprints(bool aEnabled)
void SetLookupByTimestamp(bool aEnabled)
Class DIALOG_NETLIST_IMPORT_BASE.
void onUpdatePCB(wxCommandEvent &event) override
void onFilenameChanged(bool aLoadNetlist)
static bool m_matchByUUID
void onImportNetlist(wxCommandEvent &event) override
void OnFilenameKillFocus(wxFocusEvent &event) override
PCB_EDIT_FRAME * m_parent
void onBrowseNetlistFiles(wxCommandEvent &event) override
DIALOG_NETLIST_IMPORT(PCB_EDIT_FRAME *aParent, wxString &aNetlistFullFilename)
void OnOptionChanged(wxCommandEvent &event) override
void OnMatchChanged(wxCommandEvent &event) override
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...
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Move cursor to the requested position expressed in world coordinates.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition: pcb_netlist.h:213
DIALOG_NETLIST m_NetlistDialog
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:110
PCBNEW_SETTINGS * GetPcbNewSettings() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
The main frame for Pcbnew.
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.
bool ReadNetlistFromFile(const wxString &aFilename, NETLIST &aNetlist, REPORTER &aReporter)
Read a netlist from a file into a NETLIST object.
Definition: netlist.cpp:50
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
void OnNetlistChanged(BOARD_NETLIST_UPDATER &aUpdater, bool *aRunDragCommand)
Called after netlist is updated.
Definition: netlist.cpp:84
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
virtual REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the beginning of the list for objects that support ordering.
Definition: reporter.h:108
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
void Clear()
return the number of messages matching the given severity mask.
void SetLazyUpdate(bool aLazyUpdate)
Forces updating the HTML page, after the report is built in lazy mode If aSort = true,...
void SetLabel(const wxString &aLabel) override
Sets the lazy update.
void SetFileName(const wxString &aReportFileName)
void SetVisibleSeverities(int aSeverities)
void Flush(bool aSort=false)
Set the visible severity filter.
This file is part of the common library.
#define _(s)
wxString NetlistFileWildcard()
@ LAST_PATH_NETLIST
Definition: project_file.h:48
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
Definition of file extensions used in Kicad.