KiCad PCB EDA Suite
Loading...
Searching...
No Matches
netlist_exporter_orcadpcb2.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-2018 jp.charras at wanadoo.fr
5 * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <algorithm>
27#include <vector>
28
29#include <confirm.h>
30#include <refdes_utils.h>
31
32#include <sch_edit_frame.h>
33#include <sch_reference_list.h>
34#include <string_utils.h>
35
36#include <netlist.h>
38
39
40bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName,
41 unsigned /* aNetlistOptions */,
42 REPORTER& aReporter )
43{
44 FILE* f = nullptr;
45 wxString field;
46 wxString footprint;
47 int ret = 0; // zero now, OR in the sign bit on error
48 wxString netName;
49
50
51 if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == nullptr )
52 {
53 wxString msg = wxString::Format( _( "Failed to create file '%s'." ), aOutFileName );
54 aReporter.Report( msg, RPT_SEVERITY_ERROR );
55 return false;
56 }
57
58 std::vector< SCH_REFERENCE > cmpList;
59
60 ret |= fprintf( f, "( { %s created %s }\n",
62
63 // Create netlist footprints section
65
66 for( const SCH_SHEET_PATH& sheet : m_schematic->Hierarchy() )
67 {
68 // The rtree returns items in a non-deterministic order (platform-dependent)
69 // Therefore we need to sort them before outputting to ensure file stability for version
70 // control and QA comparisons
71 std::vector<EDA_ITEM*> sheetItems;
72
73 for( EDA_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
74 sheetItems.push_back( item );
75
76 auto pred = []( const EDA_ITEM* item1, const EDA_ITEM* item2 )
77 {
78 return item1->m_Uuid < item2->m_Uuid;
79 };
80
81 std::sort( sheetItems.begin(), sheetItems.end(), pred );
82
83 // Process symbol attributes
84 for( EDA_ITEM* item : sheetItems )
85 {
86 SCH_SYMBOL* symbol = findNextSymbol( item, sheet );
87
88 if( !symbol )
89 continue;
90
91 if( symbol->GetExcludedFromBoard() )
92 continue;
93
94 std::vector<PIN_INFO> pins = CreatePinList( symbol, sheet, true );
95
96 if( symbol->GetLibSymbolRef()
97 && symbol->GetLibSymbolRef()->GetFPFilters().GetCount() != 0 )
98 {
99 cmpList.push_back( SCH_REFERENCE( symbol, sheet ) );
100 }
101
102 footprint = symbol->GetFootprintFieldText( true, &sheet, false );
103 footprint.Replace( wxT( " " ), wxT( "_" ) );
104
105 if( footprint.IsEmpty() )
106 footprint = wxT( "$noname" );
107
108 ret |= fprintf( f, " ( %s %s",
109 TO_UTF8( sheet.PathAsString() + symbol->m_Uuid.AsString() ),
110 TO_UTF8( footprint ) );
111
112 field = symbol->GetRef( &sheet );
113
114 ret |= fprintf( f, " %s", TO_UTF8( field ) );
115
116 field = symbol->GetValue( true, &sheet, false );
117 field.Replace( wxT( " " ), wxT( "_" ) );
118
119 ret |= fprintf( f, " %s", TO_UTF8( field ) );
120
121 ret |= fprintf( f, "\n" );
122
123 // Write pin list:
124 for( const PIN_INFO& pin : pins )
125 {
126 if( pin.num.IsEmpty() ) // Erased pin in list
127 continue;
128
129 netName = pin.netName;
130 netName.Replace( wxT( " " ), wxT( "_" ) );
131
132 ret |= fprintf( f, " ( %4.4s %s )\n", TO_UTF8( pin.num ), TO_UTF8( netName ) );
133 }
134
135 ret |= fprintf( f, " )\n" );
136 }
137 }
138
139 ret |= fprintf( f, ")\n*\n" );
140
141 fclose( f );
142
143 return ret >= 0;
144}
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
const KIID m_Uuid
Definition eda_item.h:516
wxString AsString() const
Definition kiid.cpp:246
wxArrayString GetFPFilters() const
Definition lib_symbol.h:217
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
std::vector< PIN_INFO > CreatePinList(SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aSheetPath, bool aKeepUnconnectedPins)
Find a symbol from the DrawList and builds its pin list.
SCH_SYMBOL * findNextSymbol(EDA_ITEM *aItem, const SCH_SHEET_PATH &aSheetPath)
Check if the given symbol should be processed for netlisting.
UNIQUE_STRINGS m_referencesAlreadyFound
Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once.
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter) override
Write to specified output file.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
A helper to define a symbol's reference designator in a schematic.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:76
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const override
const wxString GetFootprintFieldText(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:184
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
bool GetExcludedFromBoard() const override
Definition symbol.h:208
This file is part of the common library.
#define _(s)
Collection of utility functions for component reference designators (refdes)
@ RPT_SEVERITY_ERROR
wxString GetISO8601CurrentDateTime()
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
@ SCH_SYMBOL_T
Definition typeinfo.h:176