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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <project.h>
21#include <kiface_base.h>
22#include <pcb_edit_frame.h>
23#include <pcbnew_settings.h>
24#include <reporter.h>
25#include <bitmaps.h>
26#include <tool/tool_manager.h>
27#include <tools/pcb_actions.h>
34#include <project/project_file.h> // LAST_PATH_TYPE
37#include <kiplatform/ui.h>
38#include <view/view_controls.h>
39#include <wx/filedlg.h>
40#include <wx/msgdlg.h>
41
42
44{
45 wxString netlistName = GetLastPath( LAST_PATH_NETLIST );
46
47 DIALOG_IMPORT_NETLIST dlg( this, netlistName );
48
49 dlg.ShowModal();
50
51 SetLastPath( LAST_PATH_NETLIST, netlistName );
52}
53
54
55DIALOG_IMPORT_NETLIST::DIALOG_IMPORT_NETLIST( PCB_EDIT_FRAME* aParent, wxString& aNetlistFullFilename ) :
57 m_parent( aParent ),
58 m_netlistPath( aNetlistFullFilename ),
59 m_initialized( false ),
60 m_runDragCommand( false )
61{
64
65 m_MessageWindow->SetLabel( _("Changes to Be Applied") );
66 m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
67
68 SetupStandardButtons( { { wxID_OK, _( "Load and Test Netlist" ) },
69 { wxID_CANCEL, _( "Close" ) },
70 { wxID_APPLY, _( "Update PCB" ) } } );
71
73
74 m_initialized = true;
75}
76
78{
80 {
81 PCB_SELECTION_TOOL* selTool = m_parent->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
82 PCB_SELECTION& selection = selTool->GetSelection();
83
84 // Set the reference point to (0,0) where the new footprints were spread. This ensures
85 // the move tool knows where the items are located, preventing an offset when the "warp
86 // cursor to origin of moved object" preference is disabled.
87 if( selection.Size() > 0 )
88 selection.SetReferencePoint( VECTOR2I( 0, 0 ) );
89
90 KIGFX::VIEW_CONTROLS* controls = m_parent->GetCanvas()->GetViewControls();
91 controls->SetCursorPosition( controls->GetMousePosition() );
92 m_parent->GetToolManager()->RunAction( PCB_ACTIONS::move );
93 }
94}
95
96
98{
99 wxString dirPath = wxFileName( Prj().GetProjectFullName() ).GetPath();
100 wxString filename = m_parent->GetLastPath( LAST_PATH_NETLIST );
101
102 if( !filename.IsEmpty() )
103 {
104 wxFileName fn = filename;
105 dirPath = fn.GetPath();
106 filename = fn.GetFullName();
107 }
108
109 wxFileDialog FilesDialog( this, _( "Import Netlist" ), dirPath, filename, FILEEXT::NetlistFileWildcard(),
110 wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
111
113
114 if( FilesDialog.ShowModal() != wxID_OK )
115 return;
116
117 m_NetlistFilenameCtrl->SetValue( FilesDialog.GetPath() );
118 onFilenameChanged( false );
119}
120
121
122
123void DIALOG_IMPORT_NETLIST::onImportNetlist( wxCommandEvent& event )
124{
125 onFilenameChanged( true );
126}
127
128
129void DIALOG_IMPORT_NETLIST::onUpdatePCB( wxCommandEvent& event )
130{
131 wxFileName fn = m_NetlistFilenameCtrl->GetValue();
132
133 if( !fn.IsOk() )
134 {
135 wxMessageBox( _( "Please choose a valid netlist file." ) );
136 return;
137 }
138
139 if( !fn.FileExists() )
140 {
141 wxMessageBox( _( "The netlist file does not exist." ) );
142 return;
143 }
144
145 m_MessageWindow->SetLabel( _( "Changes Applied to PCB" ) );
146 loadNetlist( false );
147
148 m_sdbSizerCancel->SetDefault();
149 m_sdbSizerCancel->SetFocus();
150}
151
152
154{
155 event.Skip();
156}
157
158
160{
161 if( m_initialized )
162 {
163 wxFileName fn = m_NetlistFilenameCtrl->GetValue();
164
165 if( fn.IsOk() )
166 {
167 if( fn.FileExists() )
168 {
170
171 if( aLoadNetlist )
172 loadNetlist( true );
173 }
174 else
175 {
176 m_MessageWindow->Clear();
177 REPORTER& reporter = m_MessageWindow->Reporter();
178 reporter.Report( _( "The netlist file does not exist." ), RPT_SEVERITY_ERROR );
179 }
180 }
181 }
182}
183
184
185void DIALOG_IMPORT_NETLIST::OnMatchChanged( wxCommandEvent& event )
186{
187 if( m_initialized )
188 loadNetlist( true );
189}
190
191
192void DIALOG_IMPORT_NETLIST::OnOptionChanged( wxCommandEvent& event )
193{
194 if( m_initialized )
195 loadNetlist( true );
196}
197
198
200{
201 wxString netlistFileName = m_NetlistFilenameCtrl->GetValue();
202 wxFileName fn = netlistFileName;
203
204 if( !fn.IsOk() || !fn.FileExists() )
205 return;
206
207 m_MessageWindow->Clear();
208 REPORTER& reporter = m_MessageWindow->Reporter();
209
210 wxBusyCursor busy;
211
212 wxString msg;
213 msg.Printf( _( "Reading netlist file '%s'.\n" ), netlistFileName );
214 reporter.ReportHead( msg, RPT_SEVERITY_INFO );
215
216 if( m_matchByTimestamp->GetSelection() == 1 )
217 msg = _( "Using reference designators to match symbols and footprints.\n" );
218 else
219 msg = _( "Using tstamps (unique IDs) to match symbols and footprints.\n" );
220
221 reporter.ReportHead( msg, RPT_SEVERITY_INFO );
222 m_MessageWindow->SetLazyUpdate( true ); // Use lazy update to speed the creation of the report
223 // (the window is not updated for each message)
224
226
227 netlist.SetFindByTimeStamp( m_matchByTimestamp->GetSelection() == 0 );
228 netlist.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
229
230 if( !m_parent->ReadNetlistFromFile( netlistFileName, netlist, reporter ) )
231 return;
232
233 BOARD_NETLIST_UPDATER updater( m_parent, m_parent->GetBoard() );
234 updater.SetReporter ( &reporter );
235 updater.SetIsDryRun( aDryRun );
236 updater.SetLookupByTimestamp( m_matchByTimestamp->GetSelection() == 0 );
238 updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
239 updater.SetTransferGroups( m_cbTransferGroups->GetValue() );
240 updater.SetOverrideLocks( m_cbOverrideLocks->GetValue() );
241 updater.SetUpdateFields( true );
242 updater.UpdateNetlist( netlist );
243
244 // The creation of the report was made without window update: the full page must be displayed
245 m_MessageWindow->Flush( true );
246
247 if( aDryRun )
248 return;
249
250 m_parent->OnNetlistChanged( updater, &m_runDragCommand );
251}
252
253
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
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 SetUpdateFields(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.
The selection tool: currently supports:
PCB_SELECTION & GetSelection()
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:71
void SetReferencePoint(const VECTOR2I &aP)
#define _(s)
static wxString NetlistFileWildcard()
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:448
@ LAST_PATH_NETLIST
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
std::string netlist
IbisParser parser & reporter
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
Definition of file extensions used in Kicad.