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