1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
|
/**
* @file pcbnew/netlist.cpp
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2013-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <functional>
using namespace std::placeholders;
#include <fctsys.h>
#include <pgm_base.h>
#include <class_drawpanel.h>
#include <class_draw_panel_gal.h>
#include <confirm.h>
#include <dialog_helpers.h>
#include <pcb_edit_frame.h>
#include <pcb_netlist.h>
#include <netlist_reader.h>
#include <reporter.h>
#include <wildcards_and_files_ext.h>
#include <lib_id.h>
#include <fp_lib_table.h>
#include <class_board.h>
#include <class_module.h>
#include <ratsnest_data.h>
#include <pcbnew.h>
#include <io_mgr.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <view/view.h>
void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName,
const wxString& aCmpFileName,
REPORTER* aReporter,
bool aChangeFootprints,
bool aDeleteUnconnectedTracks,
bool aDeleteExtraFootprints,
bool aSelectByTimeStamp,
bool aDeleteSinglePadNets,
bool aIsDryRun )
{
wxString msg;
NETLIST netlist;
KIGFX::VIEW* view = GetGalCanvas()->GetView();
BOARD* board = GetBoard();
std::vector<MODULE*> newFootprints;
// keep trace of the initial baord area, if we want to place new footprints
// outside the existinag board
EDA_RECT bbox = board->GetBoundingBox();
netlist.SetIsDryRun( aIsDryRun );
netlist.SetFindByTimeStamp( aSelectByTimeStamp );
netlist.SetDeleteExtraFootprints( aDeleteExtraFootprints );
netlist.SetReplaceFootprints( aChangeFootprints );
try
{
std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
&netlist, aNetlistFileName, aCmpFileName ) );
if( !netlistReader.get() )
{
msg.Printf( _( "Cannot open netlist file \"%s\"." ), GetChars( aNetlistFileName ) );
wxMessageBox( msg, _( "Netlist Load Error." ), wxOK | wxICON_ERROR, this );
return;
}
SetLastNetListRead( aNetlistFileName );
netlistReader->LoadNetlist();
LoadFootprints( netlist, aReporter );
}
catch( const IO_ERROR& ioe )
{
msg.Printf( _( "Error loading netlist.\n%s" ), ioe.What().GetData() );
wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR );
return;
}
// Clear undo and redo lists to avoid inconsistencies between lists
if( !netlist.IsDryRun() )
GetScreen()->ClearUndoRedoList();
if( !netlist.IsDryRun() )
{
// Remove old modules
for( MODULE* module = board->m_Modules; module; module = module->Next() )
{
view->Remove( module );
}
}
// Clear selection, just in case a selected item has to be removed
m_toolManager->RunAction( PCB_ACTIONS::selectionClear, true );
netlist.SortByReference();
board->ReplaceNetlist( netlist, aDeleteSinglePadNets, &newFootprints, aReporter );
// If it was a dry run, nothing has changed so we're done.
if( netlist.IsDryRun() )
return;
if( IsGalCanvasActive() )
{
SpreadFootprints( &newFootprints, false, false, GetCrossHairPosition() );
if( !newFootprints.empty() )
{
for( MODULE* footprint : newFootprints )
{
m_toolManager->RunAction( PCB_ACTIONS::selectItem, true, footprint );
}
m_toolManager->InvokeTool( "pcbnew.InteractiveEdit" );
}
}
else
{
wxPoint placementAreaPosition;
// Place area to the left side of the board.
// if the board is empty, the bbox position is (0,0)
placementAreaPosition.x = bbox.GetEnd().x + Millimeter2iu( 10 );
placementAreaPosition.y = bbox.GetOrigin().y;
SpreadFootprints( &newFootprints, false, false, placementAreaPosition );
}
OnModify();
SetCurItem( NULL );
// Reload modules
for( MODULE* module = board->m_Modules; module; module = module->Next() )
{
view->Add( module );
}
if( aDeleteUnconnectedTracks && board->m_Track )
{
// Remove erroneous tracks. This should probably pushed down to the #BOARD object.
RemoveMisConnectedTracks();
}
// Rebuild the board connectivity:
board->GetConnectivity()->Build( board );
// TODO is there a way to extract information about which nets were modified?
for( auto track : board->Tracks() )
view->Update( track );
SetMsgPanel( board );
m_canvas->Refresh();
}
MODULE* PCB_EDIT_FRAME::ListAndSelectModuleName()
{
if( GetBoard()->m_Modules == NULL )
{
DisplayError( this, _( "No footprints" ) );
return 0;
}
wxArrayString listnames;
MODULE* module;
for( module = GetBoard()->m_Modules; module; module = module->Next() )
listnames.Add( module->GetReference() );
wxArrayString headers;
headers.Add( wxT( "Module" ) );
std::vector<wxArrayString> itemsToDisplay;
// Conversion from wxArrayString to vector of ArrayString
for( unsigned i = 0; i < listnames.GetCount(); i++ )
{
wxArrayString item;
item.Add( listnames[i] );
itemsToDisplay.push_back( item );
}
EDA_LIST_DIALOG dlg( this, _( "Components" ), headers, itemsToDisplay, wxEmptyString );
if( dlg.ShowModal() != wxID_OK )
return NULL;
wxString ref = dlg.GetTextSelection();
for( module = GetBoard()->m_Modules; module; module = module->Next() )
{
if( module->GetReference() == ref )
break;
}
return module;
}
#define ALLOW_PARTIAL_FPID 1
void PCB_EDIT_FRAME::LoadFootprints( NETLIST& aNetlist, REPORTER* aReporter )
{
wxString msg;
LIB_ID lastFPID;
COMPONENT* component;
MODULE* module = 0;
MODULE* fpOnBoard;
if( aNetlist.IsEmpty() || Prj().PcbFootprintLibs()->IsEmpty() )
return;
aNetlist.SortByFPID();
for( unsigned ii = 0; ii < aNetlist.GetCount(); ii++ )
{
component = aNetlist.GetComponent( ii );
#if ALLOW_PARTIAL_FPID
// The FPID is ok as long as there is a footprint portion coming
// from eeschema.
if( !component->GetFPID().GetLibItemName().size() )
#else
if( component->GetFPID().empty() )
#endif
{
if( aReporter )
{
msg.Printf( _( "No footprint defined for symbol \"%s\".\n" ),
GetChars( component->GetReference() ) );
aReporter->Report( msg, REPORTER::RPT_ERROR );
}
continue;
}
// Check if component footprint is already on BOARD and only load the footprint from
// the library if it's needed. Nickname can be blank.
if( aNetlist.IsFindByTimeStamp() )
fpOnBoard = m_Pcb->FindModule( aNetlist.GetComponent( ii )->GetTimeStamp(), true );
else
fpOnBoard = m_Pcb->FindModule( aNetlist.GetComponent( ii )->GetReference() );
bool footprintMisMatch = fpOnBoard &&
fpOnBoard->GetFPID() != component->GetFPID();
if( footprintMisMatch && !aNetlist.GetReplaceFootprints() )
{
if( aReporter )
{
msg.Printf( _( "Footprint of symbol \"%s\" changed: board footprint \"%s\", netlist footprint \"%s\"\n" ),
GetChars( component->GetReference() ),
GetChars( fpOnBoard->GetFPID().Format() ),
GetChars( component->GetFPID().Format() ) );
aReporter->Report( msg, REPORTER::RPT_WARNING );
}
continue;
}
if( !aNetlist.GetReplaceFootprints() )
footprintMisMatch = false;
if( fpOnBoard && !footprintMisMatch ) // nothing else to do here
continue;
if( component->GetFPID() != lastFPID )
{
module = NULL;
#if ALLOW_PARTIAL_FPID
// The LIB_ID is ok as long as there is a footprint portion coming
// the library if it's needed. Nickname can be blank.
if( !component->GetFPID().GetLibItemName().size() )
#else
if( !component->GetFPID().IsValid() )
#endif
{
if( aReporter )
{
msg.Printf( _( "Component \"%s\" footprint ID \"%s\" is not "
"valid.\n" ),
GetChars( component->GetReference() ),
GetChars( component->GetFPID().Format() ) );
aReporter->Report( msg, REPORTER::RPT_ERROR );
}
continue;
}
// loadFootprint() can find a footprint with an empty nickname in fpid.
module = PCB_BASE_FRAME::loadFootprint( component->GetFPID() );
if( module )
{
lastFPID = component->GetFPID();
}
else
{
if( aReporter )
{
msg.Printf( _( "Component \"%s\" footprint \"%s\" was not found in "
"any libraries in the footprint library table.\n" ),
GetChars( component->GetReference() ),
GetChars( component->GetFPID().GetLibItemName() ) );
aReporter->Report( msg, REPORTER::RPT_ERROR );
}
continue;
}
}
else
{
// Footprint already loaded from a library, duplicate it (faster)
if( module == NULL )
continue; // Module does not exist in any library.
module = new MODULE( *module );
}
if( module )
component->SetModule( module );
}
}
|