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 <fctsys.h>
27 #include <confirm.h>
28 #include <refdes_utils.h>
29 
30 #include <sch_edit_frame.h>
31 #include <sch_reference_list.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\"" ),
54  GetChars( aOutFileName ) );
55  DisplayError( NULL, msg );
56  return false;
57  }
58 
59  std::vector< SCH_REFERENCE > cmpList;
60 
61  ret |= fprintf( f, "( { %s created %s }\n",
63 
64  // Create netlist module section
66 
67  SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
68 
69  for( unsigned i = 0; i < sheetList.size(); i++ )
70  {
71  SCH_SHEET_PATH sheet = sheetList[i];
72 
73  // Process component attributes
74  for( auto item : sheet.LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
75  {
76  SCH_COMPONENT* comp = findNextComponent( item, &sheet );
77 
78  if( !comp )
79  continue;
80 
81  CreatePinList( comp, &sheet );
82 
83  if( comp->GetPartRef() && comp->GetPartRef()->GetFootprints().GetCount() != 0 )
84  cmpList.push_back( SCH_REFERENCE( comp, comp->GetPartRef().get(), sheet ) );
85 
86  if( !comp->GetField( FOOTPRINT )->IsVoid() )
87  {
88  footprint = comp->GetField( FOOTPRINT )->GetText();
89  footprint.Replace( wxT( " " ), wxT( "_" ) );
90  }
91  else
92  {
93  footprint = wxT( "$noname" );
94  }
95 
96  field = comp->GetRef( &sheetList[i] );
97 
98  ret |= fprintf( f, " ( %s %s",
99  TO_UTF8( sheetList[i].PathAsString() + comp->m_Uuid.AsString() ),
100  TO_UTF8( footprint ) );
101 
102  ret |= fprintf( f, " %s", TO_UTF8( field ) );
103 
104  field = comp->GetField( VALUE )->GetText();
105  field.Replace( wxT( " " ), wxT( "_" ) );
106  ret |= fprintf( f, " %s", TO_UTF8( field ) );
107 
108  ret |= fprintf( f, "\n" );
109 
110  // Write pin list:
111  for( const PIN_INFO& pin : m_SortedComponentPinList )
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 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
SCH_SHEET_LIST.
#define NETLIST_HEAD_STRING
Definition: netlist.h:50
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:92
UNIQUE_STRINGS m_ReferencesAlreadyFound
Used for "multi parts per package" components, avoids processing a lib component more than once.
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
This file is part of the common library.
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
Collection of utility functions for component reference designators (refdes)
wxString AsString() const
Definition: common.cpp:165
void Clear()
Function Clear erases the record.
SCH_COMPONENT * findNextComponent(EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
Checks if the given component should be processed for netlisting.
Field Name Module PCB, i.e. "16DIP300".
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.cpp:293
#define VALUE
#define NULL
void CreatePinList(SCH_COMPONENT *aItem, SCH_SHEET_PATH *aSheetPath)
Function findNextComponentAndCreatePinList finds a component from the DrawList and builds its pin lis...
std::vector< PIN_INFO > m_SortedComponentPinList
Used to temporarily store and filter the list of pins of a schematic component when generating schema...
SCH_SHEET_PATH.
std::unique_ptr< LIB_PART > & GetPartRef()
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false)
Return the reference for the given sheet path.
const KIID m_Uuid
Definition: base_struct.h:162
SCH_FIELD * GetField(int aFieldNdx)
Returns a field in this symbol.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153
SCH_SCREEN * LastScreen()
Function LastScreen.
#define _(s)
Definition: 3d_actions.cpp:33
EE_RTREE & Items()
Definition: sch_screen.h:162
Schematic symbol object.
Definition: sch_component.h:88
#define TO_UTF8(wxstring)
Definition for part library class.
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic.
wxString DateAndTime()
Definition: string.cpp:379
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions) override
Function WriteNetlist writes to specified output file.