KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcbnew/netlist_reader/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 (C) 1992-2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2013-2016 Wayne Stambaugh <[email protected]>
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23#include <functional>
24using namespace std::placeholders;
25
26#include <confirm.h>
27#include <drc/drc_engine.h>
28#include <kiway.h>
29#include <pcb_edit_frame.h>
31#include <netlist_reader/netlist_reader.h>
33#include <reporter.h>
34#include <board.h>
36#include <footprint.h>
37#include <pad.h>
38#include <pcb_track.h>
39#include <spread_footprints.h>
41#include <tool/tool_manager.h>
42#include <tools/drc_tool.h>
43#include <tools/pcb_actions.h>
45#include <project/project_file.h> // LAST_PATH_TYPE
46
47
48bool PCB_EDIT_FRAME::ReadNetlistFromFile( const wxString &aFilename, NETLIST& aNetlist,
49 REPORTER& aReporter )
50{
51 wxString msg;
52
53 try
54 {
55 std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
56 &aNetlist, aFilename, wxEmptyString ) );
57
58 if( !netlistReader.get() )
59 {
60 msg.Printf( _( "Cannot open netlist file '%s'." ), aFilename );
61 DisplayErrorMessage( this, msg );
62 return false;
63 }
64
65 SetLastPath( LAST_PATH_NETLIST, aFilename );
66 netlistReader->LoadNetlist();
67 LoadNetlistFootprints( GetBoard(), aNetlist, aReporter );
68 }
69 catch( const IO_ERROR& ioe )
70 {
71 msg.Printf( _( "Error loading netlist.\n%s" ), ioe.What().GetData() );
72 DisplayErrorMessage( this, msg );
73 return false;
74 }
75
76 SetLastPath( LAST_PATH_NETLIST, aFilename );
77
78 return true;
79}
80
81
82void PCB_EDIT_FRAME::OnNetlistChanged( BOARD_NETLIST_UPDATER& aUpdater, bool* aRunDragCommand )
83{
84 BOARD* board = GetBoard();
85
86 SetMsgPanel( board );
87
88 // Re-sync nets and netclasses
89 board->SynchronizeNetsAndNetClasses( false );
90
91 // Recompute component classes
94
95 // Resync DRC rules to account for new aggregate netclass / component class rules
96 DRC_TOOL* drcTool = m_toolManager->GetTool<DRC_TOOL>();
97
98 try
99 {
100 drcTool->GetDRCEngine()->InitEngine( board->GetDesignRulesPath() );
101 }
102 catch( PARSE_ERROR& )
103 {
104 }
105
106 // Update rendered track/via/pad net labels, and any text items that might reference a
107 // netName or netClass
108 int netNamesCfg = GetPcbNewSettings()->m_Display.m_NetNames;
109
111 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
112 {
113 if( dynamic_cast<PCB_TRACK*>( aItem ) )
114 {
115 if( netNamesCfg == 2 || netNamesCfg == 3 )
116 return KIGFX::REPAINT;
117 }
118 else if( dynamic_cast<PAD*>( aItem ) )
119 {
120 if( netNamesCfg == 1 || netNamesCfg == 3 )
121 return KIGFX::REPAINT;
122 }
123
124 EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
125
126 if( text && text->HasTextVars() )
127 {
128 text->ClearRenderCache();
129 text->ClearBoundingBoxCache();
131 }
132
133 return 0;
134 } );
135
136 // Spread new footprints.
137 std::vector<FOOTPRINT*> newFootprints = aUpdater.GetAddedFootprints();
138
140
141 SpreadFootprints( &newFootprints, { 0, 0 }, true );
142
143 // Start drag command for new footprints
144 if( !newFootprints.empty() )
145 {
146 EDA_ITEMS items;
147 std::copy( newFootprints.begin(), newFootprints.end(), std::back_inserter( items ) );
149
150 *aRunDragCommand = true;
151 }
152
153 board->CompileRatsnest();
154 SetMsgPanel( board );
155
157
158 GetCanvas()->Refresh();
159}
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition actions.h:228
Update the BOARD with a new netlist.
std::vector< FOOTPRINT * > GetAddedFootprints() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
void CompileRatsnest()
Rebuild the entire board ratsnest.
Definition board.cpp:3595
void SynchronizeNetsAndNetClasses(bool aResetTrackAndViaSizes)
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition board.cpp:3004
wxString GetDesignRulesPath() const
Return the absolute path to the design rules file for this board.
Definition board.cpp:272
COMPONENT_CLASS_MANAGER & GetComponentClassManager()
Gets the component class manager.
Definition board.h:1521
void InvalidateComponentClasses()
Invalidates any caches component classes and recomputes caches if required.
void RebuildRequiredCaches(FOOTPRINT *aFootprint=nullptr) const
Rebuilds any caches that may be required by custom assignment rules.
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
std::shared_ptr< DRC_ENGINE > GetDRCEngine()
Definition drc_tool.h:83
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:89
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
void UpdateAllItemsConditionally(int aUpdateFlags, std::function< bool(VIEW_ITEM *)> aCondition)
Update items in the view according to the given flags and condition.
Definition view.cpp:1702
static NETLIST_READER * GetNetlistReader(NETLIST *aNetlist, const wxString &aNetlistFileName, const wxString &aCompFootprintFileName=wxEmptyString)
Attempt to determine the net list file type of aNetlistFileName and return the appropriate NETLIST_RE...
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition pad.h:61
DISPLAY_OPTIONS m_Display
PCBNEW_SETTINGS * GetPcbNewSettings() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.
bool ReadNetlistFromFile(const wxString &aFilename, NETLIST &aNetlist, REPORTER &aReporter)
Read a netlist from a file into a NETLIST object.
void UpdateVariantSelectionCtrl()
Update the variant selection dropdown with the current board's variant names.
void OnNetlistChanged(BOARD_NETLIST_UPDATER &aUpdater, bool *aRunDragCommand)
Called after netlist is updated.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:71
TOOL_MANAGER * m_toolManager
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
This file is part of the common library.
#define _(s)
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ GEOMETRY
Position or shape has changed.
Definition view_item.h:51
void LoadNetlistFootprints(BOARD *aBoard, NETLIST &aNetlist, REPORTER &aReporter)
Load the footprints for each #SCH_COMPONENT in aNetlist from the list of libraries.
@ LAST_PATH_NETLIST
std::vector< EDA_ITEM * > EDA_ITEMS
void SpreadFootprints(std::vector< FOOTPRINT * > *aFootprints, VECTOR2I aTargetBoxPosition, bool aGroupBySheet, int aComponentGap, int aGroupGap)
Footprints (after loaded by reading a netlist for instance) are moved to be in a small free area (out...
A filename or source description, a problem input line, a line number, a byte offset,...