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-2013 jp.charras at wanadoo.fr
5  * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 1992-2017 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 <build_version.h>
28 #include <confirm.h>
29 
30 #include <schframe.h>
31 #include <sch_reference_list.h>
32 #include <class_library.h>
33 #include <class_netlist_object.h>
34 
35 #include <netlist.h>
37 
38 bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions )
39 {
40  (void)aNetlistOptions; //unused
41  FILE* f = NULL;
42  wxString field;
43  wxString footprint;
44  int ret = 0; // zero now, OR in the sign bit on error
45  wxString netName;
46 
47 
48  if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == NULL )
49  {
50  wxString msg;
51  msg.Printf( _( "Failed to create file '%s'" ),
52  GetChars( aOutFileName ) );
53  DisplayError( NULL, msg );
54  return false;
55  }
56 
57  std::vector< SCH_REFERENCE > cmpList;
58 
59  ret |= fprintf( f, "( { %s created %s }\n",
61 
62  // Prepare list of nets generation
63  for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
64  m_masterList->GetItem( ii )->m_Flag = 0;
65 
66  // Create netlist module section
68 
69  SCH_SHEET_LIST sheetList( g_RootSheet );
70 
71  for( unsigned i = 0; i < sheetList.size(); i++ )
72  {
73  for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
74  {
75  SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, &sheetList[i] );
76 
77  if( !comp )
78  break;
79 
80  item = comp;
81 
82  // Get the Component FootprintFilter and put the component in
83  // cmpList if filter is present
84  LIB_PART* part = m_libs->FindLibPart( comp->GetLibId() );
85 
86  if( part )
87  {
88  if( part->GetFootPrints().GetCount() != 0 ) // Put in list
89  {
90  cmpList.push_back( SCH_REFERENCE( comp, part, sheetList[i] ) );
91  }
92  }
93 
94  if( !comp->GetField( FOOTPRINT )->IsVoid() )
95  {
96  footprint = comp->GetField( FOOTPRINT )->GetText();
97  footprint.Replace( wxT( " " ), wxT( "_" ) );
98  }
99  else
100  footprint = wxT( "$noname" );
101 
102  field = comp->GetRef( &sheetList[i] );
103 
104  ret |= fprintf( f, " ( %s %s",
105  TO_UTF8( comp->GetPath( &sheetList[i] ) ),
106  TO_UTF8( footprint ) );
107 
108  ret |= fprintf( f, " %s", TO_UTF8( field ) );
109 
110  field = comp->GetField( VALUE )->GetText();
111  field.Replace( wxT( " " ), wxT( "_" ) );
112  ret |= fprintf( f, " %s", TO_UTF8( field ) );
113 
114  ret |= fprintf( f, "\n" );
115 
116  // Write pin list:
117  for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
118  {
120 
121  if( !pin )
122  continue;
123 
124  sprintPinNetName( netName, wxT( "N-%.6d" ), pin );
125 
126  if( netName.IsEmpty() )
127  netName = wxT( "?" );
128 
129  netName.Replace( wxT( " " ), wxT( "_" ) );
130 
131  ret |= fprintf( f, " ( %4.4s %s )\n", (char*) &pin->m_PinNum,
132  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  m_SortedComponentPinList.clear();
144  return ret >= 0;
145 }
Class SCH_SHEET_LIST.
#define NETLIST_HEAD_STRING
Definition: netlist.h:50
wxString GetPath(const SCH_SHEET_PATH *sheet) const
UNIQUE_STRINGS m_ReferencesAlreadyFound
Used for "multi parts per package" components, avoids processing a lib component more than once...
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
This file is part of the common library.
static void sprintPinNetName(wxString &aResult, const wxString &aNetNameFormat, NETLIST_OBJECT *aPin, bool aUseNetcodeAsNetName=false)
Function sprintPinNetName formats the net name for aPin using aNetNameFormat into aResult...
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.h:116
void Clear()
Function Clear erases the record.
NETLIST_OBJECT_LIST * m_masterList
Field Name Module PCB, i.e. "16DIP300".
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
Class LIB_PART defines a library part object.
SCH_COMPONENT * findNextComponentAndCreatePinList(EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
Function findNextComponentAndCreatePinList finds a component from the DrawList and builds its pin lis...
LIB_PART * FindLibPart(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Function FindLibPart searches all libraries in the list for a part.
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
Definition of the NETLIST_OBJECT class.
Field Value of part, i.e. "3.3K".
NETLIST_OBJECTS m_SortedComponentPinList
no ownership
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:92
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
const LIB_ID & GetLibId() const
wxArrayString & GetFootPrints()
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
PART_LIBS * m_libs
yes ownership, connected items flat list
Definition for part library class.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69
Class SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic...
wxString DateAndTime()
Function DateAndTime.
Definition: string.cpp:229
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions) override
Function WriteNetlist writes to specified output file.