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