KiCad PCB EDA Suite
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 <dick@softplc.com>
6  * Copyright (C) 1992-2019 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 <kicad_string.h>
32 #include <class_library.h>
33 #include <symbol_lib_table.h>
34 
35 #include <netlist.h>
37 
38 
39 bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName,
40  unsigned aNetlistOptions )
41 {
42  (void)aNetlistOptions; //unused
43  FILE* f = NULL;
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" ) ) ) == NULL )
51  {
52  wxString msg;
53  msg.Printf( _( "Failed to create file \"%s\"" ), aOutFileName );
54  DisplayError( NULL, msg );
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  SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
67 
68  for( unsigned i = 0; i < sheetList.size(); i++ )
69  {
70  SCH_SHEET_PATH sheet = sheetList[i];
71 
72  // Process component attributes
73  for( auto item : sheet.LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
74  {
75  SCH_COMPONENT* symbol = findNextSymbol( item, &sheet );
76 
77  if( !symbol )
78  continue;
79 
80  CreatePinList( symbol, &sheet );
81 
82  if( symbol->GetPartRef() && symbol->GetPartRef()->GetFPFilters().GetCount() != 0 )
83  cmpList.push_back( SCH_REFERENCE( symbol, symbol->GetPartRef().get(), sheet ) );
84 
85  footprint = symbol->GetFootprint( &sheet, true );
86  footprint.Replace( wxT( " " ), wxT( "_" ) );
87 
88  if( footprint.IsEmpty() )
89  footprint = wxT( "$noname" );
90 
91  ret |= fprintf( f, " ( %s %s",
92  TO_UTF8( sheet.PathAsString() + symbol->m_Uuid.AsString() ),
93  TO_UTF8( footprint ) );
94 
95  field = symbol->GetRef( &sheet );
96 
97  ret |= fprintf( f, " %s", TO_UTF8( field ) );
98 
99  field = symbol->GetValue( &sheet, true );
100  field.Replace( wxT( " " ), wxT( "_" ) );
101 
102  ret |= fprintf( f, " %s", TO_UTF8( field ) );
103 
104  ret |= fprintf( f, "\n" );
105 
106  // Write pin list:
107  for( const PIN_INFO& pin : m_sortedSymbolPinList )
108  {
109  netName = pin.netName;
110  netName.Replace( wxT( " " ), wxT( "_" ) );
111 
112  ret |= fprintf( f, " ( %4.4s %s )\n", TO_UTF8( pin.num ), TO_UTF8( netName ) );
113  }
114 
115  ret |= fprintf( f, " )\n" );
116  }
117  }
118 
119  ret |= fprintf( f, ")\n*\n" );
120 
121  fclose( f );
122 
123  return ret >= 0;
124 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:253
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:219
#define NETLIST_HEAD_STRING
Definition: netlist.h:50
void CreatePinList(SCH_COMPONENT *aSymbol, SCH_SHEET_PATH *aSheetPath)
Function findNextSymbolAndCreatePinList finds a symbol from the DrawList and builds its pin list in m...
std::vector< PIN_INFO > m_sortedSymbolPinList
Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic...
This file is part of the common library.
Collection of utility functions for component reference designators (refdes)
wxString AsString() const
Definition: kiid.cpp:213
wxString PathAsString() const
Return the path of time stamps which do not changes even when editing sheet parameters.
void Clear()
Function Clear erases the record.
SCHEMATIC_IFACE * m_schematic
The schematic we're generating a netlist for.
UNIQUE_STRINGS m_referencesAlreadyFound
Used for "multiple parts per package" symbols to avoid processing a lib part more than once.
const wxString GetFootprint(const SCH_SHEET_PATH *sheet, bool aResolve) const
Definition: sch_symbol.cpp:637
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
const wxString GetValue(const SCH_SHEET_PATH *sheet, bool aResolve) const
Definition: sch_symbol.cpp:587
#define NULL
SCH_COMPONENT * findNextSymbol(EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
Checks if the given symbol should be processed for netlisting.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
std::unique_ptr< LIB_PART > & GetPartRef()
Definition: sch_symbol.h:206
const KIID m_Uuid
Definition: eda_item.h:524
SCH_SCREEN * LastScreen()
#define _(s)
Definition: 3d_actions.cpp:33
EE_RTREE & Items()
Definition: sch_screen.h:162
Schematic symbol object.
Definition: sch_symbol.h:79
Definition for part library class.
virtual SCH_SHEET_LIST GetSheets() const =0
A helper to define a symbol's reference designator in a schematic.
wxString DateAndTime()
Definition: string.cpp:411
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:426
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions) override
Function WriteNetlist writes to specified output file.