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-2019 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_i.h>
26 #include <confirm.h>
28 #include <pcb_edit_frame.h>
29 #include <pcbnew_settings.h>
30 #include <reporter.h>
31 #include <bitmaps.h>
32 #include <tool/tool_manager.h>
33 #include <tools/pcb_actions.h>
34 #include <board.h>
39 #include <project/project_file.h> // LAST_PATH_TYPE
40 
41 #include <dialog_netlist.h>
42 
43 #include <wx_html_report_panel.h>
44 #include <wx/filedlg.h>
45 
46 
48 {
49  wxString netlistName = GetLastPath( LAST_PATH_NETLIST );
50 
51  DIALOG_NETLIST dlg( this, netlistName );
52 
53  dlg.ShowModal();
54 
55  SetLastPath( LAST_PATH_NETLIST, netlistName );
56 }
57 
60 
61 
62 DIALOG_NETLIST::DIALOG_NETLIST( PCB_EDIT_FRAME* aParent, wxString& aNetlistFullFilename )
63  : DIALOG_NETLIST_BASE( aParent ),
64  m_parent( aParent ),
65  m_netlistPath( aNetlistFullFilename ),
66  m_initialized( false ),
67  m_runDragCommand( false )
68 {
71 
72  auto cfg = m_parent->GetPcbNewSettings();
73 
74  m_cbUpdateFootprints->SetValue( cfg->m_NetlistDialog.update_footprints );
75  m_cbDeleteShortingTracks->SetValue( cfg->m_NetlistDialog.delete_shorting_tracks );
76  m_cbDeleteExtraFootprints->SetValue( cfg->m_NetlistDialog.delete_extra_footprints );
77  m_cbDeleteSinglePadNets->SetValue( cfg->m_NetlistDialog.delete_single_pad_nets );
78 
80  m_matchByTimestamp->SetSelection( m_matchByUUID ? 0 : 1 );
81 
82  m_MessageWindow->SetLabel( _("Changes To Be Applied") );
83  m_MessageWindow->SetVisibleSeverities( cfg->m_NetlistDialog.report_filter );
84  m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
85 
86  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
87  // that requires us to correct the button labels here.
88  m_sdbSizer1OK->SetLabel( _( "Update PCB" ) );
89  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
90  m_buttonsSizer->Layout();
91 
92  m_sdbSizer1OK->SetDefault();
94 
95  m_initialized = true;
96  loadNetlist( true );
97 }
98 
100 {
101  m_warnForNoNetPads = m_cbWarnNoNetPad->GetValue();
102  m_matchByUUID = m_matchByTimestamp->GetSelection() == 0;
103 
104  auto cfg = m_parent->GetPcbNewSettings();
105 
107  cfg->m_NetlistDialog.update_footprints = m_cbUpdateFootprints->GetValue();
108  cfg->m_NetlistDialog.delete_shorting_tracks = m_cbDeleteShortingTracks->GetValue();
109  cfg->m_NetlistDialog.delete_extra_footprints = m_cbDeleteExtraFootprints->GetValue();
110  cfg->m_NetlistDialog.delete_single_pad_nets = m_cbDeleteSinglePadNets->GetValue();
111 
112  if( m_runDragCommand )
113  {
115  controls->SetCursorPosition( controls->GetMousePosition() );
117  }
118 }
119 
120 
121 void DIALOG_NETLIST::OnOpenNetlistClick( wxCommandEvent& event )
122 {
123  wxString dirPath = wxFileName( Prj().GetProjectFullName() ).GetPath();
124 
125  wxString filename = m_parent->GetLastPath( LAST_PATH_NETLIST );
126 
127  if( !filename.IsEmpty() )
128  {
129  wxFileName fn = filename;
130  dirPath = fn.GetPath();
131  filename = fn.GetFullName();
132  }
133 
134  wxFileDialog FilesDialog( this, _( "Select Netlist" ), dirPath, filename,
135  NetlistFileWildcard(), wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
136 
137  if( FilesDialog.ShowModal() != wxID_OK )
138  return;
139 
140  m_NetlistFilenameCtrl->SetValue( FilesDialog.GetPath() );
142 }
143 
144 void DIALOG_NETLIST::OnUpdatePCB( wxCommandEvent& event )
145 {
146  wxFileName fn = m_NetlistFilenameCtrl->GetValue();
147 
148  if( !fn.IsOk() )
149  {
150  wxMessageBox( _( "Please, choose a valid netlist file." ) );
151  return;
152  }
153 
154  if( !fn.FileExists() )
155  {
156  wxMessageBox( _( "The netlist file does not exist." ) );
157  return;
158  }
159 
160  m_MessageWindow->SetLabel( _( "Changes Applied to PCB" ) );
161  loadNetlist( false );
162 
163  m_sdbSizer1Cancel->SetDefault();
164 }
165 
166 
167 void DIALOG_NETLIST::OnFilenameKillFocus( wxFocusEvent& event )
168 {
170  event.Skip();
171 }
172 
173 
175 {
176  if( m_initialized )
177  {
178  wxFileName fn = m_NetlistFilenameCtrl->GetValue();
179 
180  if( fn.IsOk() )
181  {
182  if( fn.FileExists() )
183  {
184  m_netlistPath = m_NetlistFilenameCtrl->GetValue();
185  loadNetlist( true );
186  }
187  else
188  {
190  REPORTER& reporter = m_MessageWindow->Reporter();
191  reporter.Report( _( "The netlist file does not exist." ), RPT_SEVERITY_ERROR );
192  }
193  }
194  }
195 }
196 
197 
198 void DIALOG_NETLIST::OnMatchChanged( wxCommandEvent& event )
199 {
200  if( m_initialized )
201  loadNetlist( true );
202 }
203 
204 
205 void DIALOG_NETLIST::OnOptionChanged( wxCommandEvent& event )
206 {
207  if( m_initialized )
208  loadNetlist( true );
209 }
210 
211 
212 void DIALOG_NETLIST::loadNetlist( bool aDryRun )
213 {
214  wxString netlistFileName = m_NetlistFilenameCtrl->GetValue();
215  wxFileName fn = netlistFileName;
216 
217  if( !fn.IsOk() || !fn.FileExists() )
218  return;
219 
221  REPORTER& reporter = m_MessageWindow->Reporter();
222 
223  wxBusyCursor busy;
224 
225  wxString msg;
226  msg.Printf( _( "Reading netlist file '%s'.\n" ), netlistFileName );
227  reporter.ReportHead( msg, RPT_SEVERITY_INFO );
228 
229  if( m_matchByTimestamp->GetSelection() == 1 )
230  msg = _( "Using reference designators to match symbols and footprints.\n" );
231  else
232  msg = _( "Using tstamps (unique IDs) to match symbols and footprints.\n" );
233 
234  reporter.ReportHead( msg, RPT_SEVERITY_INFO );
235  m_MessageWindow->SetLazyUpdate( true ); // Use lazy update to speed the creation of the report
236  // (the window is not updated for each message)
237  m_matchByUUID = m_matchByTimestamp->GetSelection() == 0;
238 
240 
241  netlist.SetFindByTimeStamp( m_matchByUUID );
242  netlist.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
243 
244  if( !m_parent->ReadNetlistFromFile( netlistFileName, netlist, reporter ) )
245  return;
246 
248  updater.SetReporter ( &reporter );
249  updater.SetIsDryRun( aDryRun );
250  updater.SetLookupByTimestamp( m_matchByUUID );
251  updater.SetDeleteUnusedFootprints( m_cbDeleteExtraFootprints->GetValue());
252  updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
253  updater.SetDeleteSinglePadNets( m_cbDeleteSinglePadNets->GetValue() );
254  m_warnForNoNetPads = m_cbWarnNoNetPad->GetValue();
255  updater.SetWarnPadNoNetInNetlist( m_warnForNoNetPads );
256  updater.UpdateNetlist( netlist );
257 
258  // The creation of the report was made without window update: the full page must be displayed
259  m_MessageWindow->Flush( true );
260 
261  if( aDryRun )
262  return;
263 
265 }
266 
267 
void SetVisibleSeverities(int aSeverities)
void SetLazyUpdate(bool aLazyUpdate)
Forces updating the HTML page, after the report is built in lazy mode If aSort = true,...
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:92
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
void OnMatchChanged(wxCommandEvent &event) override
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
PCB_EDIT_FRAME * m_parent
This file is part of the common library.
Update the BOARD with a new netlist.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
bool ReadNetlistFromFile(const wxString &aFilename, NETLIST &aNetlist, REPORTER &aReporter)
Read a netlist from a file into a NETLIST object.
Definition: netlist.cpp:55
void Flush(bool aSort=false)
Set the visible severity filter.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
BOARD_NETLIST_UPDATER class definition.
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.
void SetReporter(REPORTER *aReporter)
Enable dry run mode (just report, no changes to PCB).
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
void OnNetlistChanged(BOARD_NETLIST_UPDATER &aUpdater, bool *aRunDragCommand)
Called after netlist is updated.
Definition: netlist.cpp:89
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void OnFilenameKillFocus(wxFocusEvent &event) override
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition: pcb_netlist.h:206
DIALOG_NETLIST m_NetlistDialog
void OnOpenNetlistClick(wxCommandEvent &event) override
wxString NetlistFileWildcard()
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
void OnOptionChanged(wxCommandEvent &event) override
Definition of file extensions used in Kicad.
An interface for classes handling user events controlling the view behavior such as zooming,...
#define _(s)
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
static bool m_warnForNoNetPads
WX_HTML_REPORT_PANEL * m_MessageWindow
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:102
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void OnUpdatePCB(wxCommandEvent &event) override
DIALOG_NETLIST(PCB_EDIT_FRAME *aParent, wxString &aNetlistFullFilename)
void Clear()
return the number of messages matching the given severity mask.
wxString & m_netlistPath
The main frame for Pcbnew.
PCBNEW_SETTINGS * GetPcbNewSettings() const
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
BOARD * GetBoard() const
void SetFileName(const wxString &aReportFileName)
static bool m_matchByUUID
void SetLabel(const wxString &aLabel) override
Sets the lazy update.
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.