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 The 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 <pcb_edit_frame.h>
27#include <pcbnew_settings.h>
28#include <reporter.h>
29#include <bitmaps.h>
30#include <tool/tool_manager.h>
31#include <tools/pcb_actions.h>
37#include <project/project_file.h> // LAST_PATH_TYPE
40#include <view/view_controls.h>
41#include <wx/filedlg.h>
42#include <wx/msgdlg.h>
43
44
46{
47 wxString netlistName = GetLastPath( LAST_PATH_NETLIST );
48
49 DIALOG_IMPORT_NETLIST dlg( this, netlistName );
50
51 dlg.ShowModal();
52
53 SetLastPath( LAST_PATH_NETLIST, netlistName );
54}
55
56
57DIALOG_IMPORT_NETLIST::DIALOG_IMPORT_NETLIST( PCB_EDIT_FRAME* aParent, wxString& aNetlistFullFilename ) :
59 m_parent( aParent ),
60 m_netlistPath( aNetlistFullFilename ),
61 m_initialized( false ),
62 m_runDragCommand( false )
63{
66
67 m_MessageWindow->SetLabel( _("Changes to Be Applied") );
68 m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
69
70 SetupStandardButtons( { { wxID_OK, _( "Load and Test Netlist" ) },
71 { wxID_CANCEL, _( "Close" ) },
72 { wxID_APPLY, _( "Update PCB" ) } } );
73
75
76 m_initialized = true;
77}
78
80{
82 {
83 KIGFX::VIEW_CONTROLS* controls = m_parent->GetCanvas()->GetViewControls();
84 controls->SetCursorPosition( controls->GetMousePosition() );
85 m_parent->GetToolManager()->RunAction( PCB_ACTIONS::move );
86 }
87}
88
89
91{
92 wxString dirPath = wxFileName( Prj().GetProjectFullName() ).GetPath();
93 wxString filename = m_parent->GetLastPath( LAST_PATH_NETLIST );
94
95 if( !filename.IsEmpty() )
96 {
97 wxFileName fn = filename;
98 dirPath = fn.GetPath();
99 filename = fn.GetFullName();
100 }
101
102 wxFileDialog FilesDialog( this, _( "Import Netlist" ), dirPath, filename, FILEEXT::NetlistFileWildcard(),
103 wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
104
105 if( FilesDialog.ShowModal() != wxID_OK )
106 return;
107
108 m_NetlistFilenameCtrl->SetValue( FilesDialog.GetPath() );
109 onFilenameChanged( false );
110}
111
112
113
114void DIALOG_IMPORT_NETLIST::onImportNetlist( wxCommandEvent& event )
115{
116 onFilenameChanged( true );
117}
118
119
120void DIALOG_IMPORT_NETLIST::onUpdatePCB( wxCommandEvent& event )
121{
122 wxFileName fn = m_NetlistFilenameCtrl->GetValue();
123
124 if( !fn.IsOk() )
125 {
126 wxMessageBox( _( "Please choose a valid netlist file." ) );
127 return;
128 }
129
130 if( !fn.FileExists() )
131 {
132 wxMessageBox( _( "The netlist file does not exist." ) );
133 return;
134 }
135
136 m_MessageWindow->SetLabel( _( "Changes Applied to PCB" ) );
137 loadNetlist( false );
138
139 m_sdbSizerCancel->SetDefault();
140 m_sdbSizerCancel->SetFocus();
141}
142
143
145{
146 event.Skip();
147}
148
149
151{
152 if( m_initialized )
153 {
154 wxFileName fn = m_NetlistFilenameCtrl->GetValue();
155
156 if( fn.IsOk() )
157 {
158 if( fn.FileExists() )
159 {
161
162 if( aLoadNetlist )
163 loadNetlist( true );
164 }
165 else
166 {
167 m_MessageWindow->Clear();
168 REPORTER& reporter = m_MessageWindow->Reporter();
169 reporter.Report( _( "The netlist file does not exist." ), RPT_SEVERITY_ERROR );
170 }
171 }
172 }
173}
174
175
176void DIALOG_IMPORT_NETLIST::OnMatchChanged( wxCommandEvent& event )
177{
178 if( m_initialized )
179 loadNetlist( true );
180}
181
182
183void DIALOG_IMPORT_NETLIST::OnOptionChanged( wxCommandEvent& event )
184{
185 if( m_initialized )
186 loadNetlist( true );
187}
188
189
191{
192 wxString netlistFileName = m_NetlistFilenameCtrl->GetValue();
193 wxFileName fn = netlistFileName;
194
195 if( !fn.IsOk() || !fn.FileExists() )
196 return;
197
198 m_MessageWindow->Clear();
199 REPORTER& reporter = m_MessageWindow->Reporter();
200
201 wxBusyCursor busy;
202
203 wxString msg;
204 msg.Printf( _( "Reading netlist file '%s'.\n" ), netlistFileName );
205 reporter.ReportHead( msg, RPT_SEVERITY_INFO );
206
207 if( m_matchByTimestamp->GetSelection() == 1 )
208 msg = _( "Using reference designators to match symbols and footprints.\n" );
209 else
210 msg = _( "Using tstamps (unique IDs) to match symbols and footprints.\n" );
211
212 reporter.ReportHead( msg, RPT_SEVERITY_INFO );
213 m_MessageWindow->SetLazyUpdate( true ); // Use lazy update to speed the creation of the report
214 // (the window is not updated for each message)
215
217
218 netlist.SetFindByTimeStamp( m_matchByTimestamp->GetSelection() == 0 );
219 netlist.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
220
221 if( !m_parent->ReadNetlistFromFile( netlistFileName, netlist, reporter ) )
222 return;
223
224 BOARD_NETLIST_UPDATER updater( m_parent, m_parent->GetBoard() );
225 updater.SetReporter ( &reporter );
226 updater.SetIsDryRun( aDryRun );
227 updater.SetLookupByTimestamp( m_matchByTimestamp->GetSelection() == 0 );
229 updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
230 updater.SetTransferGroups( m_cbTransferGroups->GetValue() );
231 updater.SetOverrideLocks( m_cbOverrideLocks->GetValue() );
232 updater.UpdateNetlist( netlist );
233
234 // The creation of the report was made without window update: the full page must be displayed
235 m_MessageWindow->Flush( true );
236
237 if( aDryRun )
238 return;
239
240 m_parent->OnNetlistChanged( updater, &m_runDragCommand );
241}
242
243
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
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)
void SetTransferGroups(bool aEnabled)
DIALOG_IMPORT_NETLIST_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Import Netlist"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void onFilenameChanged(bool aLoadNetlist)
void onUpdatePCB(wxCommandEvent &event) override
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...
int ShowModal() override
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.
static TOOL_ACTION move
move or drag an item
The main frame for Pcbnew.
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
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:121
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
#define _(s)
static wxString NetlistFileWildcard()
@ LAST_PATH_NETLIST
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
Definition of file extensions used in Kicad.