kicad/pcbnew/netlist.cpp

246 lines
8.1 KiB
C++
Raw Normal View History

/**
* @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>
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
#include <pgm_base.h>
#include <class_draw_panel_gal.h>
#include <confirm.h>
#include <dialog_helpers.h>
2018-01-29 20:58:58 +00:00
#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>
2014-06-03 14:08:23 +00:00
#include <ratsnest_data.h>
#include <pcbnew.h>
#include <io_mgr.h>
#include <board_netlist_updater.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <tools/selection_tool.h>
#include <view/view.h>
bool PCB_EDIT_FRAME::ReadNetlistFromFile( const wxString &aFilename,
NETLIST& aNetlist,
REPORTER& aReporter )
{
wxString msg;
try
{
std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
&aNetlist, aFilename, wxEmptyString ) );
if( !netlistReader.get() )
{
msg.Printf( _( "Cannot open netlist file \"%s\"." ), GetChars( aFilename ) );
wxMessageBox( msg, _( "Netlist Load Error." ), wxOK | wxICON_ERROR, this );
return false;
}
SetLastNetListRead( aFilename );
netlistReader->LoadNetlist();
LoadFootprints( aNetlist, 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 false;
}
SetLastNetListRead( aFilename );
return true;
}
void PCB_EDIT_FRAME::OnNetlistChanged( BOARD_NETLIST_UPDATER& aUpdater,
bool* aRunDragCommand )
{
BOARD* board = GetBoard();
SetMsgPanel( board );
// Update rendered tracks and vias net labels
auto view = GetGalCanvas()->GetView();
// TODO is there a way to extract information about which nets were modified?
for( auto track : board->Tracks() )
view->Update( track );
std::vector<MODULE*> newFootprints = aUpdater.GetAddedComponents();
// Spread new footprints.
wxPoint areaPosition = GetCrossHairPosition();
EDA_RECT bbox = board->GetBoundingBox();
GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
SpreadFootprints( &newFootprints, false, false, areaPosition, false );
2019-05-27 16:16:54 +00:00
// Start drag command for new modules
if( !newFootprints.empty() )
{
2019-05-27 16:16:54 +00:00
for( MODULE* footprint : newFootprints )
GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, footprint );
2019-05-27 16:16:54 +00:00
*aRunDragCommand = true;
2019-05-27 16:16:54 +00:00
// Now fix a reference point to move the footprints.
// We use the first footprint in list as reference point
// The graphic cursor will be on this fp when moving the footprints.
2019-06-09 21:57:23 +00:00
SELECTION_TOOL* selTool = GetToolManager()->GetTool<SELECTION_TOOL>();
PCBNEW_SELECTION& selection = selTool->GetSelection();
2019-05-27 16:16:54 +00:00
selection.SetReferencePoint( newFootprints[0]->GetPosition() );
}
GetGalCanvas()->Refresh();
}
#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
{
msg.Printf( _( "No footprint defined for symbol \"%s\".\n" ),
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() )
{
msg.Printf( _( "Footprint of %s changed: board footprint \"%s\", netlist footprint \"%s\"." ),
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
{
msg.Printf( _( "%s footprint ID \"%s\" is not valid." ),
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
{
msg.Printf( _( "%s footprint \"%s\" not found in any libraries in the footprint library table.\n" ),
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 );
}
}