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 
45 
47 {
48  wxString netlistName = GetLastPath( LAST_PATH_NETLIST );
49 
50  DIALOG_NETLIST dlg( this, netlistName );
51 
52  dlg.ShowModal();
53 
54  SetLastPath( LAST_PATH_NETLIST, netlistName );
55 }
56 
59 
60 
61 DIALOG_NETLIST::DIALOG_NETLIST( PCB_EDIT_FRAME* aParent, wxString& aNetlistFullFilename )
62  : DIALOG_NETLIST_BASE( aParent ),
63  m_parent( aParent ),
64  m_netlistPath( aNetlistFullFilename ),
65  m_initialized( false ),
66  m_runDragCommand( false )
67 {
69  m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
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  m_cbDeleteSinglePadNets->SetValue( cfg->m_NetlistDialog.delete_single_pad_nets );
77 
79  m_matchByTimestamp->SetSelection( m_matchByUUID ? 0 : 1 );
80 
81  m_MessageWindow->SetLabel( _("Changes To Be Applied") );
82  m_MessageWindow->SetVisibleSeverities( cfg->m_NetlistDialog.report_filter );
83 
84  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
85  // that requires us to correct the button labels here.
86  m_sdbSizer1OK->SetLabel( _( "Update PCB" ) );
87  m_sdbSizer1Apply->SetLabel( _( "Rebuild Ratsnest" ) );
88  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
89  m_buttonsSizer->Layout();
90 
91  m_sdbSizer1OK->SetDefault();
93 
94  m_initialized = true;
95  loadNetlist( true );
96 }
97 
99 {
100  m_warnForNoNetPads = m_cbWarnNoNetPad->GetValue();
101  m_matchByUUID = m_matchByTimestamp->GetSelection() == 0;
102 
103  auto cfg = m_parent->GetPcbNewSettings();
104 
106  cfg->m_NetlistDialog.update_footprints = m_cbUpdateFootprints->GetValue();
107  cfg->m_NetlistDialog.delete_shorting_tracks = m_cbDeleteShortingTracks->GetValue();
108  cfg->m_NetlistDialog.delete_extra_footprints = m_cbDeleteExtraFootprints->GetValue();
109  cfg->m_NetlistDialog.delete_single_pad_nets = m_cbDeleteSinglePadNets->GetValue();
110 
111  if( m_runDragCommand )
112  {
114  controls->SetCursorPosition( controls->GetMousePosition() );
116  }
117 }
118 
119 
120 void DIALOG_NETLIST::OnOpenNetlistClick( wxCommandEvent& event )
121 {
122  wxString dirPath = wxFileName( Prj().GetProjectFullName() ).GetPath();
123 
124  wxString filename = m_parent->GetLastPath( LAST_PATH_NETLIST );
125 
126  if( !filename.IsEmpty() )
127  {
128  wxFileName fn = filename;
129  dirPath = fn.GetPath();
130  filename = fn.GetFullName();
131  }
132 
133  wxFileDialog FilesDialog( this, _( "Select Netlist" ), dirPath, filename,
134  NetlistFileWildcard(), wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
135 
136  if( FilesDialog.ShowModal() != wxID_OK )
137  return;
138 
139  m_NetlistFilenameCtrl->SetValue( FilesDialog.GetPath() );
141 }
142 
143 void DIALOG_NETLIST::OnUpdatePCB( wxCommandEvent& event )
144 {
145  wxFileName fn = m_NetlistFilenameCtrl->GetValue();
146 
147  if( !fn.IsOk() )
148  {
149  wxMessageBox( _( "Please, choose a valid netlist file." ) );
150  return;
151  }
152 
153  if( !fn.FileExists() )
154  {
155  wxMessageBox( _( "The netlist file does not exist." ) );
156  return;
157  }
158 
159  m_MessageWindow->SetLabel( _( "Changes Applied to PCB" ) );
160  loadNetlist( false );
161 
162  m_sdbSizer1Cancel->SetDefault();
163 }
164 
165 
166 void DIALOG_NETLIST::OnFilenameKillFocus( wxFocusEvent& event )
167 {
169  event.Skip();
170 }
171 
172 
174 {
175  if( m_initialized )
176  {
177  wxFileName fn = m_NetlistFilenameCtrl->GetValue();
178 
179  if( fn.IsOk() )
180  {
181  if( fn.FileExists() )
182  {
183  m_netlistPath = m_NetlistFilenameCtrl->GetValue();
184  loadNetlist( true );
185  }
186  else
187  {
189  REPORTER& reporter = m_MessageWindow->Reporter();
190  reporter.Report( _( "The netlist file does not exist." ), RPT_SEVERITY_ERROR );
191  }
192  }
193  }
194 }
195 
196 
197 void DIALOG_NETLIST::OnMatchChanged( wxCommandEvent& event )
198 {
199  if( m_initialized )
200  loadNetlist( true );
201 }
202 
203 
204 void DIALOG_NETLIST::OnOptionChanged( wxCommandEvent& event )
205 {
206  if( m_initialized )
207  loadNetlist( true );
208 }
209 
210 
211 void DIALOG_NETLIST::OnCompileRatsnestClick( wxCommandEvent& event )
212 {
213  // Rebuild the board connectivity:
214  auto board = m_parent->GetBoard();
215  board->GetConnectivity()->RecalculateRatsnest();
216 }
217 
218 
219 void DIALOG_NETLIST::loadNetlist( bool aDryRun )
220 {
221  wxString netlistFileName = m_NetlistFilenameCtrl->GetValue();
222  wxFileName fn = netlistFileName;
223 
224  if( !fn.IsOk() || !fn.FileExists() )
225  return;
226 
228  REPORTER& reporter = m_MessageWindow->Reporter();
229 
230  wxBusyCursor busy;
231 
232  wxString msg;
233  msg.Printf( _( "Reading netlist file \"%s\".\n" ), netlistFileName );
234  reporter.ReportHead( msg, RPT_SEVERITY_INFO );
235 
236  if( m_matchByTimestamp->GetSelection() == 1 )
237  msg = _( "Using reference designators to match components and footprints.\n" );
238  else
239  msg = _( "Using tstamps (unique IDs) to match components and footprints.\n" );
240 
241  reporter.ReportHead( msg, RPT_SEVERITY_INFO );
242  m_MessageWindow->SetLazyUpdate( true ); // Use lazy update to speed the creation of the report
243  // (the window is not updated for each message)
244  m_matchByUUID = m_matchByTimestamp->GetSelection() == 0;
245 
246  NETLIST netlist;
247 
249  netlist.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
250 
251  if( !m_parent->ReadNetlistFromFile( netlistFileName, netlist, reporter ) )
252  return;
253 
255  updater.SetReporter ( &reporter );
256  updater.SetIsDryRun( aDryRun );
257  updater.SetLookupByTimestamp( m_matchByUUID );
258  updater.SetDeleteUnusedComponents ( m_cbDeleteExtraFootprints->GetValue() );
259  updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
260  updater.SetDeleteSinglePadNets( m_cbDeleteSinglePadNets->GetValue() );
261  m_warnForNoNetPads = m_cbWarnNoNetPad->GetValue();
262  updater.SetWarnPadNoNetInNetlist( m_warnForNoNetPads );
263  updater.UpdateNetlist( netlist );
264 
265  // The creation of the report was made without window update: the full page must be displayed
266  m_MessageWindow->Flush( true );
267 
268  if( aDryRun )
269  return;
270 
272 }
273 
274 
void SetVisibleSeverities(int aSeverities)
Set the visible severity filter.
const BITMAP_OPAQUE folder_xpm[1]
Definition: folder.cpp:20
void SetLazyUpdate(bool aLazyUpdate)
Sets the lasy update.
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:95
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel.
void OnMatchChanged(wxCommandEvent &event) override
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Function GetMousePosition() Returns the current mouse pointer position.
PCB_EDIT_FRAME * m_parent
This file is part of the common library.
BOARD_NETLIST_UPDATER updates 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)
Reads a netlist from a file into a NETLIST object.
void Flush(bool aSort=false)
Forces updating the HTML page, after the report is built in lazy mode If aSort = true,...
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
BOARD_NETLIST_UPDATER class definition.
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Moves cursor to the requested position expressed in world coordinates.
void SetFindByTimeStamp(bool aFindByTimeStamp)
Definition: pcb_netlist.h:267
void SetReporter(REPORTER *aReporter)
Sets the reporter object
PCBNEW_SETTINGS * GetPcbNewSettings()
REPORTER is 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.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
void OnFilenameKillFocus(wxFocusEvent &event) override
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
void SetReplaceFootprints(bool aReplace)
Definition: pcb_netlist.h:270
NETLIST stores all of information read from a netlist along with the flags used to update the NETLIST...
Definition: pcb_netlist.h:194
DIALOG_NETLIST m_NetlistDialog
void OnOpenNetlistClick(wxCommandEvent &event) override
wxString NetlistFileWildcard()
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
REPORTER & Reporter()
returns the reporter object that reports to this panel
void OnOptionChanged(wxCommandEvent &event) override
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:382
Definition of file extensions used in Kicad.
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
static bool m_warnForNoNetPads
WX_HTML_REPORT_PANEL * m_MessageWindow
virtual REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Function ReportHead Places the report at the beginning of the list for objects that support ordering.
Definition: reporter.h:103
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()
clears the report panel
#define _(s)
Definition: 3d_actions.cpp:33
wxString & m_netlistPath
PCB_EDIT_FRAME is the main frame for Pcbnew.
void OnCompileRatsnestClick(wxCommandEvent &event) override
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
BOARD * GetBoard() const
static bool m_matchByUUID
void SetLabel(const wxString &aLabel) override
sets the frame label
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.