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 (C) 1992-2023, 2024 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 <confirm.h>
27#include <refdes_utils.h>
28
29#include <sch_edit_frame.h>
30#include <sch_reference_list.h>
31#include <string_utils.h>
32#include <symbol_library.h>
33#include <symbol_lib_table.h>
34
35#include <netlist.h>
37
38
39bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName,
40 unsigned /* aNetlistOptions */,
41 REPORTER& aReporter )
42{
43 FILE* f = nullptr;
44 wxString field;
45 wxString footprint;
46 int ret = 0; // zero now, OR in the sign bit on error
47 wxString netName;
48
49
50 if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == nullptr )
51 {
52 wxString msg = wxString::Format( _( "Failed to create file '%s'." ), aOutFileName );
53 aReporter.Report( msg, RPT_SEVERITY_ERROR );
54 return false;
55 }
56
57 std::vector< SCH_REFERENCE > cmpList;
58
59 ret |= fprintf( f, "( { %s created %s }\n",
61
62 // Create netlist footprints section
64
65 for( const SCH_SHEET_PATH& sheet : m_schematic->Hierarchy() )
66 {
67 // Process symbol attributes
68 for( EDA_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
69 {
70 SCH_SYMBOL* symbol = findNextSymbol( item, sheet );
71
72 if( !symbol )
73 continue;
74
75 if( symbol->GetExcludedFromBoard() )
76 continue;
77
78 std::vector<PIN_INFO> pins = CreatePinList( symbol, sheet, true );
79
80 if( symbol->GetLibSymbolRef()
81 && symbol->GetLibSymbolRef()->GetFPFilters().GetCount() != 0 )
82 {
83 cmpList.push_back( SCH_REFERENCE( symbol, sheet ) );
84 }
85
86 footprint = symbol->GetFootprintFieldText( true, &sheet, false );
87 footprint.Replace( wxT( " " ), wxT( "_" ) );
88
89 if( footprint.IsEmpty() )
90 footprint = wxT( "$noname" );
91
92 ret |= fprintf( f, " ( %s %s",
93 TO_UTF8( sheet.PathAsString() + symbol->m_Uuid.AsString() ),
94 TO_UTF8( footprint ) );
95
96 field = symbol->GetRef( &sheet );
97
98 ret |= fprintf( f, " %s", TO_UTF8( field ) );
99
100 field = symbol->GetValue( true, &sheet, false );
101 field.Replace( wxT( " " ), wxT( "_" ) );
102
103 ret |= fprintf( f, " %s", TO_UTF8( field ) );
104
105 ret |= fprintf( f, "\n" );
106
107 // Write pin list:
108 for( const PIN_INFO& pin : pins )
109 {
110 if( pin.num.IsEmpty() ) // Erased pin in list
111 continue;
112
113 netName = pin.netName;
114 netName.Replace( wxT( " " ), wxT( "_" ) );
115
116 ret |= fprintf( f, " ( %4.4s %s )\n", TO_UTF8( pin.num ), TO_UTF8( netName ) );
117 }
118
119 ret |= fprintf( f, " )\n" );
120 }
121 }
122
123 ret |= fprintf( f, ")\n*\n" );
124
125 fclose( f );
126
127 return ret >= 0;
128}
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
const KIID m_Uuid
Definition: eda_item.h:489
wxString AsString() const
Definition: kiid.cpp:238
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.
SCHEMATIC_IFACE * m_schematic
The schematic we're generating a netlist for.
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:72
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
virtual SCH_SHEET_LIST Hierarchy() const =0
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:104
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const override
Definition: sch_symbol.cpp:907
const wxString GetFootprintFieldText(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const
Definition: sch_symbol.cpp:923
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:212
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:737
bool GetExcludedFromBoard() const
Definition: symbol.h:148
void Clear()
Erase the record.
This file is part of the common library.
#define _(s)
#define NETLIST_HEAD_STRING
Definition: netlist.h:54
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.
Definition: string_utils.h:398
Definition for symbol library class.
@ SCH_SYMBOL_T
Definition: typeinfo.h:172