Commit 036404de authored by unknown's avatar unknown Committed by jean-pierre charras

eeschema restructure of netlist export code.

parent 6e8a8a6b
......@@ -12,6 +12,7 @@ add_definitions( -DEESCHEMA )
include_directories( BEFORE ${INC_BEFORE} )
include_directories(
./dialogs
./netlist_exporters
../common
../common/dialogs
${INC_AFTER}
......@@ -164,6 +165,13 @@ set( EESCHEMA_SRCS
transform.cpp
viewlib_frame.cpp
viewlibs.cpp
netlist_exporters/netlist_exporter.cpp
netlist_exporters/netlist_exporter_cadstar.cpp
netlist_exporters/netlist_exporter_generic.cpp
netlist_exporters/netlist_exporter_kicad.cpp
netlist_exporters/netlist_exporter_orcadpcb2.cpp
netlist_exporters/netlist_exporter_pspice.cpp
)
......
......@@ -562,7 +562,6 @@ void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event )
break;
case NET_TYPE_PCBNEW:
netlist_opt = NET_PCBNEW_USE_NEW_FORMAT;
break;
case NET_TYPE_ORCADPCB2:
......
This diff is collapsed.
......@@ -49,7 +49,6 @@ enum NETLIST_TYPE_ID {
/// Options for Spice netlist generation (OR'ed bits
enum netlistOptions {
NET_PCBNEW_USE_NEW_FORMAT = 1, // For Pcbnew use the new format (S expression and SWEET)
NET_USE_X_PREFIX = 2, // for Spice netlist : change "U" and "IC" reference prefix to "X"
NET_USE_NETCODES_AS_NETNAMES = 4 // for Spice netlist : use netcode numbers as netnames
};
......
This diff is collapsed.
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2015 KiCad Developers
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef NETLIST_EXPORTER_H
#define NETLIST_EXPORTER_H
#include <kicad_string.h>
#include <class_netlist_object.h>
#include <lib_pin.h>
#include <sch_component.h>
#include <sch_text.h>
#include <sch_sheet.h>
/**
* Class UNIQUE_STRINGS
* tracks unique wxStrings and is useful in telling if a string
* has been seen before.
*/
class UNIQUE_STRINGS
{
std::set<wxString> m_set; ///< set of wxStrings already found
typedef std::set<wxString>::iterator us_iterator;
public:
/**
* Function Clear
* erases the record.
*/
void Clear() { m_set.clear(); }
/**
* Function Lookup
* returns true if \a aString already exists in the set, otherwise returns
* false and adds \a aString to the set for next time.
*/
bool Lookup( const wxString& aString )
{
std::pair<us_iterator, bool> pair = m_set.insert( aString );
return !pair.second;
}
};
/**
* Class NETLIST_EXPORTER
* is a abstract class used for the netlist exporters that eeschema supports.
*/
class NETLIST_EXPORTER
{
protected:
NETLIST_OBJECT_LIST* m_masterList; /// The main connected items flat list
PART_LIBS* m_libs; /// no ownership
/// Used to temporary store and filter the list of pins of a schematic component
/// when generating schematic component data in netlist (comp section)
NETLIST_OBJECT_LIST m_SortedComponentPinList;
/// Used for "multi parts per package" components,
/// avoids processing a lib component more than once.
UNIQUE_STRINGS m_ReferencesAlreadyFound;
// share a code generated std::set<void*> to reduce code volume
std::set<void*> m_LibParts; ///< unique library parts used
std::set<void*> m_Libraries; ///< unique libraries used
/**
* Function sprintPinNetName
* formats the net name for \a aPin using \a aNetNameFormat into \a aResult.
* <p>
* Net name is:
* <ul>
* <li> "?" if pin not connected
* <li> "netname" for global net (like gnd, vcc ..
* <li> "/path/netname" for the usual nets
* </ul>
* if aUseNetcodeAsNetName is true, the net name is just the net code (SPICE only)
*/
static void sprintPinNetName( wxString& aResult, const wxString& aNetNameFormat,
NETLIST_OBJECT* aPin, bool aUseNetcodeAsNetName = false );
/**
* Function findNextComponentAndCreatePinList
* finds a component from the DrawList and builds
* its pin list in m_SortedComponentPinList. This list is sorted by pin num.
* the component is the next actual component after aItem
* (power symbols and virtual components that have their reference starting by '#'are skipped).
*/
SCH_COMPONENT* findNextComponentAndCreatePinList( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath );
SCH_COMPONENT* findNextComponent( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath );
/**
* Function eraseDuplicatePins
* erase duplicate Pins from m_SortedComponentPinList (i.e. set pointer in this list to NULL).
* (This is a list of pins found in the whole schematic, for a single
* component.) These duplicate pins were put in list because some pins (powers... )
* are found more than one time when we have a multiple parts per package
* component. For instance, a 74ls00 has 4 parts, and therefore the VCC pin
* and GND pin appears 4 times in the list.
* Note: this list *MUST* be sorted by pin number (.m_PinNum member value)
* Also set the m_Flag member of "removed" NETLIST_OBJECT pin item to 1
*/
void eraseDuplicatePins();
/**
* Function addPinToComponentPinList
* adds a new pin description to the pin list m_SortedComponentPinList.
* A pin description is a pointer to the corresponding structure
* created by BuildNetList() in the table g_NetObjectslist.
*/
bool addPinToComponentPinList( SCH_COMPONENT* Component,
SCH_SHEET_PATH* sheet,
LIB_PIN* PinEntry );
/**
* Function findAllInstancesOfComponent
* is used for "multiple parts per package" components.
* <p>
* Search the entire design for all instances of \a aComponent based on
* matching reference designator, and for each part, add all its pins
* to the temporary sorted pin list.
*/
void findAllInstancesOfComponent( SCH_COMPONENT* aComponent,
LIB_PART* aEntry,
SCH_SHEET_PATH* aSheetPath );
public:
NETLIST_EXPORTER( NETLIST_OBJECT_LIST* aMasterList, PART_LIBS* aLibs )
{
m_masterList = aMasterList;
m_libs = aLibs;
}
virtual ~NETLIST_EXPORTER()
{
}
/**
* Function Write
* writes to specified output file
*/
virtual bool Write( const wxString& aOutFileName, unsigned aNetlistOptions )
{
return false;
}
/**
* Function MakeCommandLine
* builds up a string that describes a command line for
* executing a child process. The input and output file names
* along with any options to the executable are all possibly
* in the returned string.
*
* @param aFormatString holds:
* <ul>
* <li>the name of the external program
* <li>any options needed by that program
* <li>formatting sequences, see below.
* </ul>
*
* @param aTempfile is the name of an input file to the
* external program.
* @param aFinalFile is the name of an output file that
* the user expects.
*
* <p> Supported formatting sequences and their meaning:
* <ul>
* <li> %B => base filename of selected output file, minus
* path and extension.
* <li> %I => complete filename and path of the temporary
* input file.
* <li> %O => complete filename and path of the user chosen
* output file.
* </ul>
*/
static wxString MakeCommandLine( const wxString& aFormatString,
const wxString& aTempfile, const wxString& aFinalFile );
};
#endif
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <fctsys.h>
#include <build_version.h>
#include <confirm.h>
#include <schframe.h>
#include <sch_reference_list.h>
#include <class_netlist_object.h>
#include "netlist_exporter_cadstar.h"
/* Generate CADSTAR net list. */
static wxString StartLine( wxT( "." ) );
bool NETLIST_EXPORTER_CADSTAR::Write( const wxString& aOutFileName, unsigned aNetlistOptions )
{
(void)aNetlistOptions; //unused
int ret = 0;
FILE* f = NULL;
if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == NULL )
{
wxString msg;
msg.Printf( _( "Failed to create file '%s'" ),
GetChars( aOutFileName ) );
DisplayError( NULL, msg );
return false;
}
wxString StartCmpDesc = StartLine + wxT( "ADD_COM" );
wxString msg;
wxString footprint;
SCH_SHEET_PATH* sheet;
EDA_ITEM* DrawList;
SCH_COMPONENT* component;
wxString title = wxT( "Eeschema " ) + GetBuildVersion();
ret |= fprintf( f, "%sHEA\n", TO_UTF8( StartLine ) );
ret |= fprintf( f, "%sTIM %s\n", TO_UTF8( StartLine ), TO_UTF8( DateAndTime() ) );
ret |= fprintf( f, "%sAPP ", TO_UTF8( StartLine ) );
ret |= fprintf( f, "\"%s\"\n", TO_UTF8( title ) );
ret |= fprintf( f, "\n" );
// Prepare list of nets generation
for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
m_masterList->GetItem( ii )->m_Flag = 0;
// Create netlist module section
m_ReferencesAlreadyFound.Clear();
SCH_SHEET_LIST SheetList;
for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() )
{
for( DrawList = sheet->LastDrawList(); DrawList != NULL; DrawList = DrawList->Next() )
{
DrawList = component = findNextComponentAndCreatePinList( DrawList, sheet );
if( component == NULL )
break;
/*
doing nothing with footprint
if( !component->GetField( FOOTPRINT )->IsVoid() )
{
footprint = component->GetField( FOOTPRINT )->m_Text;
footprint.Replace( wxT( " " ), wxT( "_" ) );
}
else
footprint = wxT( "$noname" );
*/
msg = component->GetRef( sheet );
ret |= fprintf( f, "%s ", TO_UTF8( StartCmpDesc ) );
ret |= fprintf( f, "%s", TO_UTF8( msg ) );
msg = component->GetField( VALUE )->GetText();
msg.Replace( wxT( " " ), wxT( "_" ) );
ret |= fprintf( f, " \"%s\"", TO_UTF8( msg ) );
ret |= fprintf( f, "\n" );
}
}
ret |= fprintf( f, "\n" );
m_SortedComponentPinList.clear();
if( ! writeListOfNets( f ) )
ret = -1; // set error
ret |= fprintf( f, "\n%sEND\n", TO_UTF8( StartLine ) );
fclose( f );
return ret >= 0;
}
bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f )
{
int ret = 0;
wxString InitNetDesc = StartLine + wxT( "ADD_TER" );
wxString StartNetDesc = StartLine + wxT( "TER" );
wxString netcodeName, InitNetDescLine;
unsigned ii;
int print_ter = 0;
int NetCode, lastNetCode = -1;
SCH_COMPONENT* Cmp;
wxString netName;
for( ii = 0; ii < m_masterList->size(); ii++ )
{
NETLIST_OBJECT* nitem = m_masterList->GetItem( ii );
// Get the NetName of the current net :
if( ( NetCode = nitem->GetNet() ) != lastNetCode )
{
netName = nitem->GetNetName();
netcodeName = wxT( "\"" );
if( !netName.IsEmpty() )
netcodeName << netName;
else // this net has no name: create a default name $<net number>
netcodeName << wxT( "$" ) << NetCode;
netcodeName += wxT( "\"" );
lastNetCode = NetCode;
print_ter = 0;
}
if( nitem->m_Type != NET_PIN )
continue;
if( nitem->m_Flag != 0 )
continue;
Cmp = nitem->GetComponentParent();
wxString refstr = Cmp->GetRef( &nitem->m_SheetPath );
if( refstr[0] == '#' )
continue; // Power supply symbols.
switch( print_ter )
{
case 0:
{
char buf[5];
wxString str_pinnum;
strncpy( buf, (char*) &nitem->m_PinNum, 4 );
buf[4] = 0;
str_pinnum = FROM_UTF8( buf );
InitNetDescLine.Printf( wxT( "\n%s %s %.4s %s" ),
GetChars( InitNetDesc ),
GetChars( refstr ),
GetChars( str_pinnum ),
GetChars( netcodeName ) );
}
print_ter++;
break;
case 1:
ret |= fprintf( f, "%s\n", TO_UTF8( InitNetDescLine ) );
ret |= fprintf( f, "%s %s %.4s\n",
TO_UTF8( StartNetDesc ),
TO_UTF8( refstr ),
(char*) &nitem->m_PinNum );
print_ter++;
break;
default:
ret |= fprintf( f, " %s %.4s\n",
TO_UTF8( refstr ),
(char*) &nitem->m_PinNum );
break;
}
nitem->m_Flag = 1;
}
return ret >= 0;
}
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2015 KiCad Developers
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef NETLIST_EXPORTER_CADSTAR_H
#define NETLIST_EXPORTER_CADSTAR_H
#include "netlist_exporter.h"
/**
* Class NETLIST_EXPORTER_CADSTAR
* generates a netlist compatible with CADSTAR
*/
class NETLIST_EXPORTER_CADSTAR : public NETLIST_EXPORTER
{
/**
* Function writeListOfNetsCADSTAR
* writes a net list (ranked by Netcode), and pins connected to it.
* <p>
* Format:
* - ADD_TER RR2 6 \"$42\"
* - B U1 100
* - 6 CA
* </p>
*/
bool writeListOfNets( FILE* f );
public:
NETLIST_EXPORTER_CADSTAR( NETLIST_OBJECT_LIST* aMasterList, PART_LIBS* aLibs ) :
NETLIST_EXPORTER( aMasterList, aLibs )
{
}
/**
* Function Write
* writes to specified output file
*/
bool Write( const wxString& aOutFileName, unsigned aNetlistOptions );
};
#endif
This diff is collapsed.
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2015 KiCad Developers
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef NETLIST_EXPORT_GENERIC_H
#define NETLIST_EXPORT_GENERIC_H
#include <netlist_exporter.h>
#include <xnode.h> // also nests: <wx/xml/xml.h>
#define GENERIC_INTERMEDIATE_NETLIST_EXT wxT( "xml" )
/**
* Class NETLIST_EXPORTER_GENERIC
* generates a generic XML based netlist file. This allows using XSLT or other methods to
* transform the XML to other netlist formats outside of the C++ codebase.
*/
class NETLIST_EXPORTER_GENERIC : public NETLIST_EXPORTER
{
protected:
/**
* Function node
* is a convenience function that creates a new XNODE with an optional textual child.
* It also provides some insulation from a possible change in XML library.
*
* @param aName is the name to associate with a new node of type wxXML_ELEMENT_NODE.
* @param aTextualContent is optional, and if given is the text to include in a child
* of the returned node, and has type wxXML_TEXT_NODE.
*/
XNODE* node( const wxString& aName, const wxString& aTextualContent = wxEmptyString );
/**
* Function writeGENERICListOfNets
* writes out nets (ranked by Netcode), and elements that are
* connected as part of that net.
*/
bool writeListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList );
/**
* Function makeGenericRoot
* builds the entire document tree for the generic export. This is factored
* out here so we can write the tree in either S-expression file format
* or in XML if we put the tree built here into a wxXmlDocument.
* @return XNODE* - the root nodes
*/
XNODE* makeRoot();
/**
* Function makeComponents
* @return XNODE* - returns a sub-tree holding all the schematic components.
*/
XNODE* makeComponents();
/**
* Function makeDesignHeader
* fills out a project "design" header into an XML node.
* @return XNODE* - the design header
*/
XNODE* makeDesignHeader();
/**
* Function makeLibParts
* fills out an XML node with the unique library parts and returns it.
* @return XNODE* - the library parts nodes
*/
XNODE* makeLibParts();
/**
* Function makeListOfNets
* fills out an XML node with a list of nets and returns it.
* @return XNODE* - the list of nets nodes
*/
XNODE* makeListOfNets();
/**
* Function makeLibraries
* fills out an XML node with a list of used libraries and returns it.
* Must have called makeGenericLibParts() before this function.
* @return XNODE* - the library nodes
*/
XNODE* makeLibraries();
public:
NETLIST_EXPORTER_GENERIC( NETLIST_OBJECT_LIST* aMasterList, PART_LIBS* aLibs ) :
NETLIST_EXPORTER( aMasterList, aLibs )
{
}
/**
* Function Write
* writes to specified output file
*/
bool Write( const wxString& aOutFileName, unsigned aNetlistOptions );
};
#endif
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <fctsys.h>
#include <build_version.h>
#include <confirm.h>
#include <schframe.h>
#include "netlist_exporter_kicad.h"
bool NETLIST_EXPORTER_KICAD::Write( const wxString& aOutFileName, unsigned aNetlistOptions )
{
// Prepare list of nets generation
for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
m_masterList->GetItem( ii )->m_Flag = 0;
std::auto_ptr<XNODE> xroot( makeRoot() );
try
{
FILE_OUTPUTFORMATTER formatter( aOutFileName );
xroot->Format( &formatter, 0 );
}
catch( const IO_ERROR& ioe )
{
DisplayError( NULL, ioe.errorText );
return false;
}
return true;
}
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2015 KiCad Developers
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef NETLIST_EXPORTER_KICAD_H
#define NETLIST_EXPORTER_KICAD_H
#include <netlist_exporter_generic.h>
/**
* Class NETLIST_EXPORTER_KICAD
* generates the kicad netlist format supported by pcbnew. It is basically
* the generic netlist format just formatted slightly different.
*/
class NETLIST_EXPORTER_KICAD : public NETLIST_EXPORTER_GENERIC
{
public:
NETLIST_EXPORTER_KICAD( NETLIST_OBJECT_LIST* aMasterList, PART_LIBS* aLibs ) :
NETLIST_EXPORTER_GENERIC( aMasterList, aLibs )
{
}
/**
* Function Write
* writes to specified output file
*/
bool Write( const wxString& aOutFileName, unsigned aNetlistOptions );
};
#endif
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <fctsys.h>
#include <build_version.h>
#include <confirm.h>
#include <schframe.h>
#include <sch_reference_list.h>
#include <class_library.h>
#include <class_netlist_object.h>
#include <netlist.h>
#include "netlist_exporter_orcadpcb2.h"
bool NETLIST_EXPORTER_ORCADPCB2::Write( const wxString& aOutFileName, unsigned aNetlistOptions )
{
(void)aNetlistOptions; //unused
FILE* f = NULL;
wxString field;
wxString footprint;
int ret = 0; // zero now, OR in the sign bit on error
wxString netName;
if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == NULL )
{
wxString msg;
msg.Printf( _( "Failed to create file '%s'" ),
GetChars( aOutFileName ) );
DisplayError( NULL, msg );
return false;
}
std::vector< SCH_REFERENCE > cmpList;
ret |= fprintf( f, "( { %s created %s }\n",
NETLIST_HEAD_STRING, TO_UTF8( DateAndTime() ) );
// Prepare list of nets generation
for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
m_masterList->GetItem( ii )->m_Flag = 0;
// Create netlist module section
m_ReferencesAlreadyFound.Clear();
SCH_SHEET_LIST sheetList;
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() )
{
for( EDA_ITEM* item = path->LastDrawList(); item; item = item->Next() )
{
SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, path );
if( !comp )
break;
item = comp;
// Get the Component FootprintFilter and put the component in
// cmpList if filter is present
LIB_PART* part = m_libs->FindLibPart( comp->GetPartName() );
if( part )
{
if( part->GetFootPrints().GetCount() != 0 ) // Put in list
{
cmpList.push_back( SCH_REFERENCE( comp, part, *path ) );
}
}
if( !comp->GetField( FOOTPRINT )->IsVoid() )
{
footprint = comp->GetField( FOOTPRINT )->GetText();
footprint.Replace( wxT( " " ), wxT( "_" ) );
}
else
footprint = wxT( "$noname" );
field = comp->GetRef( path );
ret |= fprintf( f, " ( %s %s",
TO_UTF8( comp->GetPath( path ) ),
TO_UTF8( footprint ) );
ret |= fprintf( f, " %s", TO_UTF8( field ) );
field = comp->GetField( VALUE )->GetText();
field.Replace( wxT( " " ), wxT( "_" ) );
ret |= fprintf( f, " %s", TO_UTF8( field ) );
ret |= fprintf( f, "\n" );
// Write pin list:
for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
{
NETLIST_OBJECT* pin = m_SortedComponentPinList[ii];
if( !pin )
continue;
sprintPinNetName( netName, wxT( "N-%.6d" ), pin );
if( netName.IsEmpty() )
netName = wxT( "?" );
netName.Replace( wxT( " " ), wxT( "_" ) );
ret |= fprintf( f, " ( %4.4s %s )\n", (char*) &pin->m_PinNum,
TO_UTF8( netName ) );
}
ret |= fprintf( f, " )\n" );
}
}
ret |= fprintf( f, ")\n*\n" );
fclose( f );
m_SortedComponentPinList.clear();
return ret >= 0;
}
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2015 KiCad Developers
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef NETLIST_EXPORTER_ORCADPCB2_H
#define NETLIST_EXPORTER_ORCADPCB2_H
#include "netlist_exporter.h"
/**
* Class NETLIST_EXPORTER_ORCADPCB2
* generates a netlist compatible with OrCAD
*/
class NETLIST_EXPORTER_ORCADPCB2 : public NETLIST_EXPORTER
{
public:
NETLIST_EXPORTER_ORCADPCB2( NETLIST_OBJECT_LIST* aMasterList, PART_LIBS* aLibs ) :
NETLIST_EXPORTER( aMasterList, aLibs )
{
}
bool Write( const wxString& aOutFileName, unsigned aNetlistOptions );
};
#endif
This diff is collapsed.
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2015 KiCad Developers
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef NETLIST_EXPORTER_PSPICE_H
#define NETLIST_EXPORTER_PSPICE_H
#include "netlist_exporter.h"
/**
* Class NETLIST_EXPORTER_PSPICE
* generates a PSPICE compatible netlist
*/
class NETLIST_EXPORTER_PSPICE : public NETLIST_EXPORTER
{
public:
NETLIST_EXPORTER_PSPICE( NETLIST_OBJECT_LIST* aMasterList, PART_LIBS* aLibs ) :
NETLIST_EXPORTER( aMasterList, aLibs )
{
}
/**
* Function Write
* writes to specified output file
*/
bool Write( const wxString& aOutFileName, unsigned aNetlistOptions );
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment