KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_import_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-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
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>
38#include <project/project_file.h> // LAST_PATH_TYPE
41#include <view/view_controls.h>
42#include <wx/filedlg.h>
43#include <wx/msgdlg.h>
44
45
47{
48 wxString netlistName = GetLastPath( LAST_PATH_NETLIST );
49
50 DIALOG_IMPORT_NETLIST dlg( this, netlistName );
51
52 dlg.ShowModal();
53
54 SetLastPath( LAST_PATH_NETLIST, netlistName );
55}
56
58
59
61 wxString& aNetlistFullFilename )
62 : DIALOG_IMPORT_NETLIST_BASE( aParent ),
63 m_parent( aParent ),
64 m_netlistPath( aNetlistFullFilename ),
65 m_initialized( false ),
66 m_runDragCommand( false )
67{
69 m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
70
71 auto cfg = m_parent->GetPcbNewSettings();
72
73 m_cbUpdateFootprints->SetValue( cfg->m_NetlistDialog.update_footprints );
74 m_cbDeleteShortingTracks->SetValue( cfg->m_NetlistDialog.delete_shorting_tracks );
75 m_cbDeleteExtraFootprints->SetValue( cfg->m_NetlistDialog.delete_extra_footprints );
76
77 m_matchByTimestamp->SetSelection( m_matchByUUID ? 0 : 1 );
78
79 m_MessageWindow->SetLabel( _("Changes To Be Applied") );
80 m_MessageWindow->SetVisibleSeverities( cfg->m_NetlistDialog.report_filter );
81 m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
82
83 SetupStandardButtons( { { wxID_OK, _( "Load and Test Netlist" ) },
84 { wxID_CANCEL, _( "Close" ) },
85 { wxID_APPLY, _( "Update PCB" ) } } );
86
88
89 m_initialized = true;
90}
91
93{
94 m_matchByUUID = m_matchByTimestamp->GetSelection() == 0;
95
96 PCBNEW_SETTINGS* cfg = nullptr;
97
98 try
99 {
101 }
102 catch( const std::runtime_error& e )
103 {
104 wxFAIL_MSG( e.what() );
105 }
106
107 if( cfg )
108 {
113 }
114
115 if( m_runDragCommand )
116 {
118 controls->SetCursorPosition( controls->GetMousePosition() );
120 }
121}
122
123
125{
126 wxString dirPath = wxFileName( Prj().GetProjectFullName() ).GetPath();
127
128 wxString filename = m_parent->GetLastPath( LAST_PATH_NETLIST );
129
130 if( !filename.IsEmpty() )
131 {
132 wxFileName fn = filename;
133 dirPath = fn.GetPath();
134 filename = fn.GetFullName();
135 }
136
137 wxFileDialog FilesDialog( this, _( "Import Netlist" ), dirPath, filename,
139 wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
140
141 if( FilesDialog.ShowModal() != wxID_OK )
142 return;
143
144 m_NetlistFilenameCtrl->SetValue( FilesDialog.GetPath() );
145 onFilenameChanged( false );
146}
147
148
149
150void DIALOG_IMPORT_NETLIST::onImportNetlist( wxCommandEvent& event )
151{
152 onFilenameChanged( true );
153}
154
155
156void DIALOG_IMPORT_NETLIST::onUpdatePCB( wxCommandEvent& event )
157{
158 wxFileName fn = m_NetlistFilenameCtrl->GetValue();
159
160 if( !fn.IsOk() )
161 {
162 wxMessageBox( _( "Please choose a valid netlist file." ) );
163 return;
164 }
165
166 if( !fn.FileExists() )
167 {
168 wxMessageBox( _( "The netlist file does not exist." ) );
169 return;
170 }
171
172 m_MessageWindow->SetLabel( _( "Changes Applied to PCB" ) );
173 loadNetlist( false );
174
175 m_sdbSizerCancel->SetDefault();
176 m_sdbSizerCancel->SetFocus();
177}
178
179
181{
182 event.Skip();
183}
184
185
187{
188 if( m_initialized )
189 {
190 wxFileName fn = m_NetlistFilenameCtrl->GetValue();
191
192 if( fn.IsOk() )
193 {
194 if( fn.FileExists() )
195 {
197
198 if( aLoadNetlist )
199 loadNetlist( true );
200 }
201 else
202 {
204 REPORTER& reporter = m_MessageWindow->Reporter();
205 reporter.Report( _( "The netlist file does not exist." ), RPT_SEVERITY_ERROR );
206 }
207 }
208 }
209}
210
211
212void DIALOG_IMPORT_NETLIST::OnMatchChanged( wxCommandEvent& event )
213{
214 if( m_initialized )
215 loadNetlist( true );
216}
217
218
219void DIALOG_IMPORT_NETLIST::OnOptionChanged( wxCommandEvent& event )
220{
221 if( m_initialized )
222 loadNetlist( true );
223}
224
225
227{
228 wxString netlistFileName = m_NetlistFilenameCtrl->GetValue();
229 wxFileName fn = netlistFileName;
230
231 if( !fn.IsOk() || !fn.FileExists() )
232 return;
233
235 REPORTER& reporter = m_MessageWindow->Reporter();
236
237 wxBusyCursor busy;
238
239 wxString msg;
240 msg.Printf( _( "Reading netlist file '%s'.\n" ), netlistFileName );
241 reporter.ReportHead( msg, RPT_SEVERITY_INFO );
242
243 if( m_matchByTimestamp->GetSelection() == 1 )
244 msg = _( "Using reference designators to match symbols and footprints.\n" );
245 else
246 msg = _( "Using tstamps (unique IDs) to match symbols and footprints.\n" );
247
248 reporter.ReportHead( msg, RPT_SEVERITY_INFO );
249 m_MessageWindow->SetLazyUpdate( true ); // Use lazy update to speed the creation of the report
250 // (the window is not updated for each message)
251 m_matchByUUID = m_matchByTimestamp->GetSelection() == 0;
252
254
255 netlist.SetFindByTimeStamp( m_matchByUUID );
256 netlist.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
257
258 if( !m_parent->ReadNetlistFromFile( netlistFileName, netlist, reporter ) )
259 return;
260
262 updater.SetReporter ( &reporter );
263 updater.SetIsDryRun( aDryRun );
266 updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
267 updater.SetOverrideLocks( m_cbOverrideLocks->GetValue() );
268 updater.UpdateNetlist( netlist );
269
270 // The creation of the report was made without window update: the full page must be displayed
271 m_MessageWindow->Flush( true );
272
273 if( aDryRun )
274 return;
275
277}
278
279
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
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 SetOverrideLocks(bool aOverride)
void SetReplaceFootprints(bool aEnabled)
void SetLookupByTimestamp(bool aEnabled)
Class DIALOG_IMPORT_NETLIST_BASE.
WX_HTML_REPORT_PANEL * m_MessageWindow
void onFilenameChanged(bool aLoadNetlist)
void onUpdatePCB(wxCommandEvent &event) override
void loadNetlist(bool aDryRun)
void onImportNetlist(wxCommandEvent &event) override
void OnFilenameKillFocus(wxFocusEvent &event) override
void OnOptionChanged(wxCommandEvent &event) override
void OnMatchChanged(wxCommandEvent &event) override
void onBrowseNetlistFiles(wxCommandEvent &event) override
DIALOG_IMPORT_NETLIST(PCB_EDIT_FRAME *aParent, wxString &aNetlistFullFilename)
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:223
DIALOG_NETLIST m_NetlistDialog
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:120
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:51
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:85
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.
void SetBitmap(const wxBitmapBundle &aBmp)
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
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)
static wxString NetlistFileWildcard()
@ LAST_PATH_NETLIST
Definition: project_file.h:49
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
Definition of file extensions used in Kicad.