2010-07-31 23:57:36 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2010-07-31 23:57:36 +00:00
|
|
|
*
|
2012-12-16 11:36:18 +00:00
|
|
|
* Copyright (C) 1992-2012 jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors.
|
2010-07-31 23:57:36 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
2012-01-26 09:37:36 +00:00
|
|
|
* @file eeschema/netform.cpp
|
2011-10-07 14:41:30 +00:00
|
|
|
* @brief Net list generation code.
|
|
|
|
*/
|
2010-07-31 23:57:36 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
|
|
|
|
|
|
|
#include <general.h>
|
|
|
|
#include <netlist.h>
|
2012-12-16 11:36:18 +00:00
|
|
|
#include <dialog_netlist.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_library.h>
|
|
|
|
#include <lib_pin.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_text.h>
|
|
|
|
#include <sch_sheet.h>
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2011-03-18 14:38:25 +00:00
|
|
|
#include <wx/tokenzr.h>
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <xnode.h> // also nests: <wx/xml/xml.h>
|
2010-08-07 15:25:18 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <build_version.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-08 12:01:14 +00:00
|
|
|
#define INTERMEDIATE_NETLIST_EXT wxT("xml")
|
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
#include <set>
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
/**
|
|
|
|
* Class UNIQUE_STRINGS
|
2010-08-03 02:13:33 +00:00
|
|
|
* tracks unique wxStrings and is useful in telling if a string
|
2010-07-30 21:41:55 +00:00
|
|
|
* has been seen before.
|
|
|
|
*/
|
|
|
|
class UNIQUE_STRINGS
|
|
|
|
{
|
|
|
|
std::set<wxString> m_set; ///< set of wxStrings already found
|
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
typedef std::set<wxString>::iterator us_iterator;
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
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 );
|
|
|
|
};
|
|
|
|
|
|
|
|
bool UNIQUE_STRINGS::Lookup( const wxString& aString )
|
|
|
|
{
|
2010-08-04 19:14:51 +00:00
|
|
|
std::pair<us_iterator, bool> pair = m_set.insert( aString );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
return !pair.second;
|
2010-07-30 21:41:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
|
|
|
|
/**
|
2012-01-26 09:37:36 +00:00
|
|
|
* Class NETLIST_EXPORT_TOOL
|
2010-08-03 02:13:33 +00:00
|
|
|
* is a private implementation class used in this source file to keep track
|
|
|
|
* of and recycle datastructures used in the generation of various exported netlist
|
|
|
|
* files. Since it is private it is not in a header file.
|
|
|
|
*/
|
2012-01-26 09:37:36 +00:00
|
|
|
class NETLIST_EXPORT_TOOL
|
2010-08-03 02:13:33 +00:00
|
|
|
{
|
2011-02-11 10:52:48 +00:00
|
|
|
/// Used to temporary store and filter the list of pins of a schematic component
|
|
|
|
/// when generating schematic component data in netlist (comp section)
|
2010-08-03 02:13:33 +00:00
|
|
|
NETLIST_OBJECT_LIST m_SortedComponentPinList;
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
/// Used for "multi parts per package" components,
|
|
|
|
/// avoids processing a lib component more than once.
|
2010-08-03 02:13:33 +00:00
|
|
|
UNIQUE_STRINGS m_ReferencesAlreadyFound;
|
|
|
|
|
2010-08-05 14:20:12 +00:00
|
|
|
// share a code generated std::set<void*> to reduce code volume
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-05 14:20:12 +00:00
|
|
|
std::set<void*> m_LibParts; ///< unique library parts used
|
|
|
|
|
|
|
|
std::set<void*> m_Libraries; ///< unique libraries used
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 ..
|
2011-02-10 17:49:04 +00:00
|
|
|
* <li> "/path/netname" for the usual nets
|
2010-08-03 02:13:33 +00:00
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
static void sprintPinNetName( wxString* aResult, const wxString& aNetNameFormat, NETLIST_OBJECT* aPin );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function findNextComponentAndCreatePinList
|
2011-02-10 19:39:18 +00:00
|
|
|
* 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
|
2011-02-10 17:49:04 +00:00
|
|
|
* (power symbols and virtual components that have their reference starting by '#'are skipped).
|
2010-08-03 02:13:33 +00:00
|
|
|
*/
|
2011-02-10 17:49:04 +00:00
|
|
|
SCH_COMPONENT* findNextComponentAndCreatePinList( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_COMPONENT* findNextComponent( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function eraseDuplicatePins
|
2011-02-10 19:39:18 +00:00
|
|
|
* erase duplicate Pins from m_SortedComponentPinList (i.e. set pointer in this list to NULL).
|
2010-08-04 19:14:51 +00:00
|
|
|
* (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)
|
2011-02-10 19:39:18 +00:00
|
|
|
* Also set the m_Flag member of "removed" NETLIST_OBJECT pin item to 1
|
2010-08-04 19:14:51 +00:00
|
|
|
*/
|
2011-02-10 19:39:18 +00:00
|
|
|
void eraseDuplicatePins( );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
/**
|
2011-02-10 17:49:04 +00:00
|
|
|
* Function addPinToComponentPinList
|
2010-08-04 19:14:51 +00:00
|
|
|
* adds a new pin description to the pin list m_SortedComponentPinList.
|
2011-02-10 17:49:04 +00:00
|
|
|
* A pin description is a pointer to the corresponding structure
|
2010-08-04 19:14:51 +00:00
|
|
|
* created by BuildNetList() in the table g_NetObjectslist.
|
|
|
|
*/
|
|
|
|
bool addPinToComponentPinList( SCH_COMPONENT* Component,
|
2011-06-07 15:29:01 +00:00
|
|
|
SCH_SHEET_PATH* sheet,
|
|
|
|
LIB_PIN* PinEntry );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-06-07 15:29:01 +00:00
|
|
|
void findAllInstancesOfComponent( SCH_COMPONENT* aComponent,
|
|
|
|
LIB_COMPONENT* aEntry,
|
|
|
|
SCH_SHEET_PATH* aSheetPath );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function writeGENERICListOfNets
|
|
|
|
* writes out nets (ranked by Netcode), and elements that are
|
|
|
|
* connected as part of that net.
|
|
|
|
*/
|
|
|
|
bool writeGENERICListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function writeListOfNetsCADSTAR
|
2011-06-07 15:29:01 +00:00
|
|
|
* writes a net list (ranked by Netcode), and pins connected to it.
|
|
|
|
* <p>
|
2010-08-04 19:14:51 +00:00
|
|
|
* Format:
|
2011-06-07 15:29:01 +00:00
|
|
|
* - ADD_TER RR2 6 \"$42\"
|
|
|
|
* - B U1 100
|
|
|
|
* - 6 CA
|
|
|
|
* </p>
|
2010-08-04 19:14:51 +00:00
|
|
|
*/
|
2012-01-26 09:37:36 +00:00
|
|
|
bool writeListOfNetsCADSTAR( FILE* f, NETLIST_OBJECT_LIST& aObjectsList );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-07 15:25:18 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* makeGenericRoot();
|
2010-08-07 15:25:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function makeGenericComponents
|
|
|
|
* returns a sub-tree holding all the schematic components.
|
|
|
|
*/
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* makeGenericComponents();
|
2010-08-07 15:25:18 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
/**
|
|
|
|
* Function makeGenericDesignHeader
|
|
|
|
* fills out a project "design" header into an XML node.
|
2010-08-08 00:31:07 +00:00
|
|
|
* @return XNODE* - the design header
|
2010-08-04 19:14:51 +00:00
|
|
|
*/
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* makeGenericDesignHeader();
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function makeGenericLibParts
|
|
|
|
* fills out an XML node with the unique library parts and returns it.
|
|
|
|
*/
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* makeGenericLibParts();
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function makeGenericListOfNets
|
|
|
|
* fills out an XML node with a list of nets and returns it.
|
|
|
|
*/
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* makeGenericListOfNets();
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function makeGenericLibraries
|
|
|
|
* fills out an XML node with a list of used libraries and returns it.
|
|
|
|
* Must have called makeGenericLibParts() before this function.
|
|
|
|
*/
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* makeGenericLibraries();
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
public:
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
/**
|
|
|
|
* Function WriteKiCadNetList
|
|
|
|
* creates a netlist, using the S expressions.
|
|
|
|
* the netlist creates the same data as the generic XML netlist,
|
|
|
|
* but using SWEET (or S expression), more easy to read and faster to parse
|
|
|
|
* @param aOutFileName = the full filename of the file to create
|
|
|
|
* @return bool - true if there were no errors, else false.
|
|
|
|
*/
|
|
|
|
bool WriteKiCadNetList( const wxString& aOutFileName );
|
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
/**
|
2010-08-07 15:25:18 +00:00
|
|
|
* Function WriteGENERICNetList
|
2010-08-04 19:14:51 +00:00
|
|
|
* creates a generic netlist, now in XML.
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aOutFileName = the full filename of the file to create
|
2010-08-04 19:14:51 +00:00
|
|
|
* @return bool - true if there were no errors, else false.
|
|
|
|
*/
|
2011-02-10 17:49:04 +00:00
|
|
|
bool WriteGENERICNetList( const wxString& aOutFileName );
|
2010-08-03 02:13:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function WriteNetListPCBNEW
|
|
|
|
* generates a net list file (Format 2 improves ORCAD PCB)
|
2010-08-04 19:14:51 +00:00
|
|
|
*
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param f = the file to write to
|
2011-02-10 17:49:04 +00:00
|
|
|
* @param with_pcbnew if true, then use Pcbnew format (OrcadPcb2 + a list of net),<p>
|
|
|
|
* else use ORCADPCB2 basic format.
|
2010-08-03 02:13:33 +00:00
|
|
|
*/
|
2011-02-10 17:49:04 +00:00
|
|
|
bool WriteNetListPCBNEW( FILE* f, bool with_pcbnew );
|
2010-08-03 02:13:33 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
/**
|
|
|
|
* Function WriteNetListCADSTAR
|
|
|
|
* generates a netlist file in CADSTAR Format.
|
|
|
|
* Header:
|
|
|
|
* HEA ..
|
|
|
|
* TIM .. 2004 07 29 16 22 17
|
|
|
|
* APA .. "Cadstar RINF Output - Version 6.0.2.3"
|
|
|
|
* INCH UNI .. 1000.0 in
|
|
|
|
* FULL TYP ..
|
|
|
|
*
|
|
|
|
* List of components:
|
|
|
|
* .. ADD_COM X1 "CNT D41612 (48pts CONTOUR TM)"
|
|
|
|
* .. ADD_COM U2 "74HCT245D" "74HCT245D"
|
|
|
|
*
|
|
|
|
* Connections:
|
|
|
|
* .. ADD_TER RR2 * 6 "$ 42"
|
|
|
|
* .. B U1 100
|
|
|
|
* 6 CA
|
|
|
|
*
|
|
|
|
* ADD_TER .. U2 * 6 "$ 59"
|
|
|
|
* .. B * U7 39
|
|
|
|
* U6 17
|
|
|
|
* U1 * 122
|
|
|
|
*
|
|
|
|
* .. ADD_TER P2 * 1 "$ 9"
|
|
|
|
* .. B * T3 1
|
|
|
|
*U1 * 14
|
|
|
|
*/
|
2012-01-26 09:37:36 +00:00
|
|
|
bool WriteNetListCADSTAR( FILE* f );
|
2010-08-03 02:13:33 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
/**
|
|
|
|
* Function WriteNetListPspice
|
|
|
|
* generates a netlist file in PSPICE format.
|
|
|
|
* <p>
|
2011-02-10 17:49:04 +00:00
|
|
|
* All graphics text starting by [.-+] PSpice or [.-+] gnucap
|
|
|
|
* are seen as spice directives and put in netlist
|
|
|
|
* .-PSpice or .-gnucap put at beginning of the netlist
|
|
|
|
* .+PSpice or .-genucap are put at end of the netList
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param f = the file to write to
|
2011-02-10 17:49:04 +00:00
|
|
|
* @param use_netnames = true, to use netnames in netlist,
|
|
|
|
* false to use net number.
|
2011-03-31 15:22:34 +00:00
|
|
|
* @param aUsePrefix = true, adds an 'X' prefix to any reference designator starting with "U" or "IC",
|
|
|
|
* false to leave reference designator unchanged.
|
2010-08-04 19:14:51 +00:00
|
|
|
*/
|
2011-03-31 15:22:34 +00:00
|
|
|
bool WriteNetListPspice( FILE* f, bool use_netnames, bool aUsePrefix );
|
2010-08-11 05:58:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 );
|
2010-08-03 02:13:33 +00:00
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
wxString NETLIST_EXPORT_TOOL::MakeCommandLine( const wxString& aFormatString,
|
2010-08-11 05:58:34 +00:00
|
|
|
const wxString& aTempfile, const wxString& aFinalFile )
|
|
|
|
{
|
|
|
|
wxString ret = aFormatString;
|
|
|
|
wxFileName in = aTempfile;
|
|
|
|
wxFileName out = aFinalFile;
|
|
|
|
|
|
|
|
ret.Replace( wxT("%B"), out.GetName().GetData(), true );
|
2010-08-11 14:47:16 +00:00
|
|
|
ret.Replace( wxT("%I"), in.GetFullPath().GetData(), true );
|
|
|
|
ret.Replace( wxT("%O"), out.GetFullPath().GetData(), true );
|
2010-08-11 05:58:34 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
/* Function WriteNetListFile
|
2010-07-30 21:41:55 +00:00
|
|
|
* creates the netlist file. Netlist info must be existing
|
2012-01-26 09:37:36 +00:00
|
|
|
* param aFormat = netlist format (NET_TYPE_PCBNEW ...)
|
|
|
|
* param aFullFileName = full netlist file name
|
|
|
|
* param aNetlistOptions = netlist options using OR'ed bits.
|
|
|
|
* For SPICE netlist only:
|
|
|
|
* if NET_USE_NETNAMES is set, use net names from labels in schematic
|
|
|
|
* else use net numbers (net codes)
|
|
|
|
* if NET_USE_X_PREFIX is set : change "U" and "IC" refernce prefix to "X"
|
|
|
|
* return true if success.
|
2007-09-21 13:23:51 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileName,
|
2012-01-26 09:37:36 +00:00
|
|
|
unsigned aNetlistOptions )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2010-08-04 19:14:51 +00:00
|
|
|
bool ret = true;
|
|
|
|
FILE* f = NULL;
|
2012-01-26 09:37:36 +00:00
|
|
|
NETLIST_EXPORT_TOOL helper;
|
|
|
|
|
|
|
|
bool open_file = aFormat < NET_TYPE_CUSTOM1;
|
|
|
|
if( (aFormat == NET_TYPE_PCBNEW) && (aNetlistOptions & NET_PCBNEW_USE_NEW_FORMAT ) )
|
|
|
|
open_file = false;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
if( open_file )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-14 13:24:36 +00:00
|
|
|
if( ( f = wxFopen( aFullFileName, wxT( "wt" ) ) ) == NULL )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-14 13:24:36 +00:00
|
|
|
wxString msg = _( "Failed to create file " ) + aFullFileName;
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxBusyCursor Busy;
|
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
switch( aFormat )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
case NET_TYPE_PCBNEW:
|
2012-01-26 09:37:36 +00:00
|
|
|
if( (aNetlistOptions & NET_PCBNEW_USE_NEW_FORMAT ) )
|
|
|
|
ret = helper.WriteKiCadNetList( aFullFileName );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = helper.WriteNetListPCBNEW( f, true );
|
|
|
|
fclose( f );
|
|
|
|
}
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_ORCADPCB2:
|
2011-02-10 17:49:04 +00:00
|
|
|
ret = helper.WriteNetListPCBNEW( f, false );
|
2007-09-21 13:23:51 +00:00
|
|
|
fclose( f );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_CADSTAR:
|
2012-01-26 09:37:36 +00:00
|
|
|
ret = helper.WriteNetListCADSTAR( f );
|
2007-09-21 13:23:51 +00:00
|
|
|
fclose( f );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_SPICE:
|
2012-01-26 09:37:36 +00:00
|
|
|
ret = helper.WriteNetListPspice( f,
|
|
|
|
aNetlistOptions & NET_USE_NETNAMES,
|
|
|
|
aNetlistOptions & NET_USE_X_PREFIX );
|
2007-09-21 13:23:51 +00:00
|
|
|
fclose( f );
|
|
|
|
break;
|
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
default:
|
2010-07-30 21:41:55 +00:00
|
|
|
{
|
|
|
|
wxFileName tmpFile = aFullFileName;
|
2011-02-08 12:01:14 +00:00
|
|
|
tmpFile.SetExt( INTERMEDIATE_NETLIST_EXT );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
D(printf("tmpFile:'%s'\n", TO_UTF8( tmpFile.GetFullPath() ) );)
|
2010-08-11 14:47:16 +00:00
|
|
|
|
2011-02-10 17:49:04 +00:00
|
|
|
ret = helper.WriteGENERICNetList( tmpFile.GetFullPath() );
|
2010-07-30 21:41:55 +00:00
|
|
|
if( !ret )
|
|
|
|
break;
|
|
|
|
|
2010-08-11 05:58:34 +00:00
|
|
|
// If user provided no plugin command line, return now.
|
2011-06-15 18:44:24 +00:00
|
|
|
if( m_netListerCommand.IsEmpty() )
|
2010-07-30 21:41:55 +00:00
|
|
|
break;
|
|
|
|
|
2010-08-11 05:58:34 +00:00
|
|
|
// build full command line from user's format string, e.g.:
|
|
|
|
// "xsltproc -o %O /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl %I"
|
|
|
|
// becomes, after the user selects /tmp/s1.net as the output file from the file dialog:
|
2011-10-29 12:01:59 +00:00
|
|
|
// "xsltproc -o /tmp/s1.net /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl /tmp/s1.xml"
|
2012-01-26 09:37:36 +00:00
|
|
|
wxString commandLine = NETLIST_EXPORT_TOOL::MakeCommandLine( m_netListerCommand,
|
2011-06-15 18:44:24 +00:00
|
|
|
tmpFile.GetFullPath(),
|
|
|
|
aFullFileName );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
D(printf("commandLine:'%s'\n", TO_UTF8( commandLine ) );)
|
2010-08-11 14:47:16 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ProcessExecute( commandLine, wxEXEC_SYNC );
|
|
|
|
|
|
|
|
// ::wxRemoveFile( tmpFile.GetFullPath() );
|
|
|
|
}
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
2008-05-15 11:20:19 +00:00
|
|
|
}
|
2010-07-14 13:24:36 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
return ret;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
/// Comparison routine for sorting by pin numbers.
|
|
|
|
static bool sortPinsByNum( NETLIST_OBJECT* aPin1, NETLIST_OBJECT* aPin2 )
|
2010-08-03 02:13:33 +00:00
|
|
|
{
|
|
|
|
// return "lhs < rhs"
|
2010-08-04 19:14:51 +00:00
|
|
|
return RefDesStringCompare( aPin1->GetPinNumText(), aPin2->GetPinNumText() ) < 0;
|
2010-08-03 02:13:33 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:31:07 +00:00
|
|
|
static bool sortPinsByNumber( LIB_PIN* aPin1, LIB_PIN* aPin2 )
|
|
|
|
{
|
|
|
|
// return "lhs < rhs"
|
2010-12-07 16:10:42 +00:00
|
|
|
return RefDesStringCompare( aPin1->GetNumberString(), aPin2->GetNumberString() ) < 0;
|
2010-08-08 00:31:07 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
void NETLIST_EXPORT_TOOL::sprintPinNetName( wxString* aResult,
|
2010-12-07 16:10:42 +00:00
|
|
|
const wxString& aNetNameFormat, NETLIST_OBJECT* aPin )
|
2010-08-03 02:13:33 +00:00
|
|
|
{
|
|
|
|
int netcode = aPin->GetNet();
|
|
|
|
|
|
|
|
// Not wxString::Clear(), which would free memory. We want the worst
|
|
|
|
// case wxString memory to grow to avoid reallocation from within the
|
|
|
|
// caller's loop.
|
|
|
|
aResult->Empty();
|
|
|
|
|
|
|
|
if( netcode != 0 && aPin->m_FlagOfConnection == PAD_CONNECT )
|
|
|
|
{
|
|
|
|
NETLIST_OBJECT* netref = aPin->m_NetNameCandidate;
|
|
|
|
if( netref )
|
|
|
|
*aResult = netref->m_Label;
|
|
|
|
|
|
|
|
if( !aResult->IsEmpty() )
|
|
|
|
{
|
|
|
|
// prefix non global label names with the sheet path, to avoid name collisions
|
|
|
|
if( netref->m_Type != NET_PINLABEL && netref->m_Type != NET_GLOBLABEL )
|
|
|
|
{
|
|
|
|
wxString lnet = *aResult;
|
|
|
|
|
|
|
|
*aResult = netref->m_SheetList.PathHumanReadable();
|
|
|
|
|
|
|
|
// If sheet path is too long, use the time stamp name instead
|
|
|
|
if( aResult->Length() > 32 )
|
|
|
|
*aResult = netref->m_SheetList.Path();
|
|
|
|
|
|
|
|
*aResult += lnet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aResult->Printf( aNetNameFormat.GetData(), netcode );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
SCH_COMPONENT* NETLIST_EXPORT_TOOL::findNextComponent( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath )
|
2010-08-04 19:14:51 +00:00
|
|
|
{
|
|
|
|
wxString ref;
|
|
|
|
|
|
|
|
// continue searching from the middle of a linked list (the draw list)
|
|
|
|
for( ; aItem; aItem = aItem->Next() )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( aItem->Type() != SCH_COMPONENT_T )
|
2010-08-04 19:14:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// found next component
|
|
|
|
SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
|
|
|
|
|
|
|
|
// Power symbols and other components which have the reference starting
|
|
|
|
// with "#" are not included in netlist (pseudo or virtual components)
|
|
|
|
ref = comp->GetRef( aSheetPath );
|
|
|
|
if( ref[0] == wxChar( '#' ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// if( Component->m_FlagControlMulti == 1 )
|
|
|
|
// continue; /* yes */
|
|
|
|
// removed because with multiple instances of one schematic
|
|
|
|
// (several sheets pointing to 1 screen), this will be erroneously be
|
|
|
|
// toggled.
|
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() );
|
2010-08-04 19:14:51 +00:00
|
|
|
if( !entry )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If component is a "multi parts per package" type
|
|
|
|
if( entry->GetPartCount() > 1 )
|
|
|
|
{
|
|
|
|
// test if this reference has already been processed, and if so skip
|
|
|
|
if( m_ReferencesAlreadyFound.Lookup( ref ) )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// record the usage of this library component entry.
|
|
|
|
m_LibParts.insert( entry ); // rejects non-unique pointers
|
|
|
|
|
|
|
|
return comp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
SCH_COMPONENT* NETLIST_EXPORT_TOOL::findNextComponentAndCreatePinList( EDA_ITEM* aItem,
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_SHEET_PATH* aSheetPath )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-08-03 02:13:33 +00:00
|
|
|
wxString ref;
|
|
|
|
|
|
|
|
m_SortedComponentPinList.clear();
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
// continue searching from the middle of a linked list (the draw list)
|
|
|
|
for( ; aItem; aItem = aItem->Next() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( aItem->Type() != SCH_COMPONENT_T )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
// found next component
|
2010-08-03 02:13:33 +00:00
|
|
|
SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
|
2010-07-30 21:41:55 +00:00
|
|
|
|
|
|
|
// Power symbols and other components which have the reference starting
|
|
|
|
// with "#" are not included in netlist (pseudo or virtual components)
|
2010-08-03 02:13:33 +00:00
|
|
|
ref = comp->GetRef( aSheetPath );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
if( ref[0] == wxChar( '#' ) )
|
2008-05-15 11:20:19 +00:00
|
|
|
continue;
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
// if( Component->m_FlagControlMulti == 1 )
|
2008-02-12 21:12:46 +00:00
|
|
|
// continue; /* yes */
|
2008-03-20 01:50:21 +00:00
|
|
|
// removed because with multiple instances of one schematic
|
2009-09-29 18:38:21 +00:00
|
|
|
// (several sheets pointing to 1 screen), this will be erroneously be
|
|
|
|
// toggled.
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
if( !entry )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
// If component is a "multi parts per package" type
|
2010-07-30 21:41:55 +00:00
|
|
|
if( entry->GetPartCount() > 1 )
|
2008-05-15 11:20:19 +00:00
|
|
|
{
|
2010-08-04 19:14:51 +00:00
|
|
|
// test if this reference has already been processed, and if so skip
|
2010-08-03 02:13:33 +00:00
|
|
|
if( m_ReferencesAlreadyFound.Lookup( ref ) )
|
2008-05-15 11:20:19 +00:00
|
|
|
continue;
|
2010-07-31 23:57:36 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
// Collect all pins for this reference designator by searching
|
|
|
|
// the entire design for other parts with the same reference designator.
|
2010-08-03 02:13:33 +00:00
|
|
|
// This is only done once, it would be too expensive otherwise.
|
2010-08-04 19:14:51 +00:00
|
|
|
findAllInstancesOfComponent( comp, entry, aSheetPath );
|
2008-05-15 11:20:19 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 23:57:36 +00:00
|
|
|
else // entry->GetPartCount() <= 1 means one part per package
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_PINS pins; // constructed once here
|
2009-10-14 19:43:31 +00:00
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
entry->GetPins( pins, comp->GetUnitSelection( aSheetPath ), comp->GetConvert() );
|
2009-10-14 19:43:31 +00:00
|
|
|
|
|
|
|
for( size_t i = 0; i < pins.size(); i++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
LIB_PIN* pin = pins[i];
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
wxASSERT( pin->Type() == LIB_PIN_T );
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
addPinToComponentPinList( comp, aSheetPath, pin );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
// Sort pins in m_SortedComponentPinList by pin number
|
|
|
|
sort( m_SortedComponentPinList.begin(),
|
|
|
|
m_SortedComponentPinList.end(), sortPinsByNum );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
// Remove duplicate Pins in m_SortedComponentPinList
|
2011-02-10 19:39:18 +00:00
|
|
|
eraseDuplicatePins( );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2011-02-08 12:01:14 +00:00
|
|
|
// record the usage of this library component entry.
|
|
|
|
m_LibParts.insert( entry ); // rejects non-unique pointers
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
return comp;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-31 23:57:36 +00:00
|
|
|
/**
|
2010-08-05 14:20:12 +00:00
|
|
|
* Function node
|
2010-08-07 15:31:32 +00:00
|
|
|
* 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.
|
2010-08-05 14:20:12 +00:00
|
|
|
*
|
2010-07-31 23:57:36 +00:00
|
|
|
* @param aName is the name to associate with a new node of type wxXML_ELEMENT_NODE.
|
2010-12-14 15:56:30 +00:00
|
|
|
* @param aTextualContent is optional, and if given is the text to include in a child
|
2010-07-31 23:57:36 +00:00
|
|
|
* of the returned node, and has type wxXML_TEXT_NODE.
|
|
|
|
*/
|
2010-08-07 15:31:32 +00:00
|
|
|
static XNODE* node( const wxString& aName, const wxString& aTextualContent = wxEmptyString )
|
2010-07-30 21:41:55 +00:00
|
|
|
{
|
2010-08-07 15:31:32 +00:00
|
|
|
XNODE* n = new XNODE( wxXML_ELEMENT_NODE, aName );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
if( aTextualContent.Len() > 0 ) // excludes wxEmptyString, the parameter's default value
|
2010-08-07 15:31:32 +00:00
|
|
|
n->AddChild( new XNODE( wxXML_TEXT_NODE, wxEmptyString, aTextualContent ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
XNODE* NETLIST_EXPORT_TOOL::makeGenericDesignHeader()
|
2010-08-04 19:14:51 +00:00
|
|
|
{
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* xdesign = node( wxT("design") );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
// the root sheet is a special sheet, call it source
|
2011-01-20 16:34:57 +00:00
|
|
|
xdesign->AddChild( node( wxT( "source" ), g_RootSheet->GetScreen()->GetFileName() ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
xdesign->AddChild( node( wxT( "date" ), DateAndTime() ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// which Eeschema tool
|
|
|
|
xdesign->AddChild( node( wxT( "tool" ), wxGetApp().GetAppName() + wxChar(' ') +
|
|
|
|
GetBuildVersion() ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
/* @todo might do a list of schematic pages
|
|
|
|
|
|
|
|
<page name="">
|
|
|
|
<title/>
|
|
|
|
<revision/>
|
|
|
|
<company/>
|
|
|
|
<comments>
|
|
|
|
<comment>blah</comment> <!-- comment1 -->
|
|
|
|
<comment>blah</comment> <!-- comment2 -->
|
|
|
|
</comments>
|
|
|
|
<pagesize/>
|
|
|
|
</page>
|
2010-08-05 14:20:12 +00:00
|
|
|
:
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
and a sheet hierarchy report here
|
|
|
|
<sheets>
|
|
|
|
<sheet name="sheetname1" page="pagenameA">
|
2010-08-05 14:20:12 +00:00
|
|
|
<sheet name="sheetname2" page="pagenameB"/> use recursion to output?
|
2010-08-04 19:14:51 +00:00
|
|
|
</sheet>
|
|
|
|
</sheets>
|
|
|
|
*/
|
|
|
|
|
|
|
|
return xdesign;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
XNODE* NETLIST_EXPORT_TOOL::makeGenericLibraries()
|
2010-08-04 19:14:51 +00:00
|
|
|
{
|
2012-11-15 16:04:10 +00:00
|
|
|
XNODE* xlibs = node( wxT( "libraries" ) ); // auto_ptr
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-05 14:20:12 +00:00
|
|
|
for( std::set<void*>::iterator it = m_Libraries.begin(); it!=m_Libraries.end(); ++it )
|
2010-08-04 19:14:51 +00:00
|
|
|
{
|
2010-08-05 14:20:12 +00:00
|
|
|
CMP_LIBRARY* lib = (CMP_LIBRARY*) *it;
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* xlibrary;
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-05 14:20:12 +00:00
|
|
|
xlibs->AddChild( xlibrary = node( wxT( "library" ) ) );
|
2010-08-08 00:31:07 +00:00
|
|
|
xlibrary->AddAttribute( wxT( "logical" ), lib->GetLogicalName() );
|
2010-08-05 14:20:12 +00:00
|
|
|
xlibrary->AddChild( node( wxT( "uri" ), lib->GetFullFileName() ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
// @todo: add more fun stuff here
|
|
|
|
}
|
|
|
|
|
|
|
|
return xlibs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
XNODE* NETLIST_EXPORT_TOOL::makeGenericLibParts()
|
2010-08-04 19:14:51 +00:00
|
|
|
{
|
2012-11-15 16:04:10 +00:00
|
|
|
XNODE* xlibparts = node( wxT( "libparts" ) ); // auto_ptr
|
2010-08-04 19:14:51 +00:00
|
|
|
wxString sLibpart = wxT( "libpart" );
|
|
|
|
wxString sLib = wxT( "lib" );
|
|
|
|
wxString sPart = wxT( "part" );
|
2011-02-08 12:01:14 +00:00
|
|
|
wxString sPins = wxT( "pins" ); // key for library component pins list
|
|
|
|
wxString sPin = wxT( "pin" ); // key for one library component pin descr
|
2011-02-11 10:52:48 +00:00
|
|
|
wxString sPinNum = wxT( "num" ); // key for one library component pin num
|
|
|
|
wxString sPinName = wxT( "name" ); // key for one library component pin name
|
2011-02-08 12:01:14 +00:00
|
|
|
wxString sPinType = wxT( "type" ); // key for one library component pin electrical type
|
2010-08-04 19:14:51 +00:00
|
|
|
wxString sName = wxT( "name" );
|
|
|
|
wxString sField = wxT( "field" );
|
|
|
|
wxString sFields = wxT( "fields" );
|
|
|
|
wxString sDescr = wxT( "description" );
|
|
|
|
wxString sDocs = wxT( "docs" );
|
2010-08-09 02:03:16 +00:00
|
|
|
wxString sFprints = wxT( "footprints" );
|
|
|
|
wxString sFp = wxT( "fp" );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_PINS pinList;
|
|
|
|
LIB_FIELDS fieldList;
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
m_Libraries.clear();
|
|
|
|
|
2010-08-05 14:20:12 +00:00
|
|
|
for( std::set<void*>::iterator it = m_LibParts.begin(); it!=m_LibParts.end(); ++it )
|
2010-08-04 19:14:51 +00:00
|
|
|
{
|
2010-08-05 14:20:12 +00:00
|
|
|
LIB_COMPONENT* lcomp = (LIB_COMPONENT*) *it;
|
|
|
|
CMP_LIBRARY* library = lcomp->GetLibrary();
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
m_Libraries.insert( library ); // inserts component's library if unique
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-07 15:31:32 +00:00
|
|
|
XNODE* xlibpart;
|
2010-08-05 14:20:12 +00:00
|
|
|
xlibparts->AddChild( xlibpart = node( sLibpart ) );
|
2010-08-08 00:31:07 +00:00
|
|
|
xlibpart->AddAttribute( sLib, library->GetLogicalName() );
|
|
|
|
xlibpart->AddAttribute( sPart, lcomp->GetName() );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
//----- show the important properties -------------------------
|
2010-10-25 15:43:42 +00:00
|
|
|
if( !lcomp->GetAlias( 0 )->GetDescription().IsEmpty() )
|
|
|
|
xlibpart->AddChild( node( sDescr, lcomp->GetAlias( 0 )->GetDescription() ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
if( !lcomp->GetAlias( 0 )->GetDocFileName().IsEmpty() )
|
|
|
|
xlibpart->AddChild( node( sDocs, lcomp->GetAlias( 0 )->GetDocFileName() ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-09 02:03:16 +00:00
|
|
|
// Write the footprint list
|
2010-09-09 17:37:25 +00:00
|
|
|
if( lcomp->GetFootPrints().GetCount() )
|
2010-08-09 02:03:16 +00:00
|
|
|
{
|
|
|
|
XNODE* xfootprints;
|
|
|
|
xlibpart->AddChild( xfootprints = node( sFprints ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-09-09 17:37:25 +00:00
|
|
|
for( unsigned i=0; i<lcomp->GetFootPrints().GetCount(); ++i )
|
2010-08-09 02:03:16 +00:00
|
|
|
{
|
2010-09-09 17:37:25 +00:00
|
|
|
xfootprints->AddChild( node( sFp, lcomp->GetFootPrints()[i] ) );
|
2010-08-09 02:03:16 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
//----- show the fields here ----------------------------------
|
|
|
|
fieldList.clear();
|
2010-08-05 14:20:12 +00:00
|
|
|
lcomp->GetFields( fieldList );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-07 15:31:32 +00:00
|
|
|
XNODE* xfields;
|
2010-08-05 14:20:12 +00:00
|
|
|
xlibpart->AddChild( xfields = node( sFields ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
for( unsigned i=0; i<fieldList.size(); ++i )
|
|
|
|
{
|
|
|
|
if( !fieldList[i].m_Text.IsEmpty() )
|
|
|
|
{
|
2010-08-07 15:31:32 +00:00
|
|
|
XNODE* xfield;
|
2010-08-05 14:20:12 +00:00
|
|
|
xfields->AddChild( xfield = node( sField, fieldList[i].m_Text ) );
|
2011-02-08 12:01:14 +00:00
|
|
|
xfield->AddAttribute( sName, fieldList[i].GetName(false) );
|
2010-08-04 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----- show the pins here ------------------------------------
|
|
|
|
pinList.clear();
|
2010-08-05 14:20:12 +00:00
|
|
|
lcomp->GetPins( pinList, 0, 0 );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2011-02-11 10:52:48 +00:00
|
|
|
/* we must erase redundant Pins references in pinList
|
|
|
|
* These redundant pins exist because some pins
|
2012-01-26 09:37:36 +00:00
|
|
|
* are found more than one time when a component has
|
|
|
|
* multiple parts per package or has 2 representations (DeMorgan conversion)
|
2011-02-11 10:52:48 +00:00
|
|
|
* For instance, a 74ls00 has DeMorgan conversion, with different pin shapes,
|
|
|
|
* and therefore each pin appears 2 times in the list.
|
|
|
|
* Common pins (VCC, GND) can also be found more than once.
|
|
|
|
*/
|
2010-08-08 00:31:07 +00:00
|
|
|
sort( pinList.begin(), pinList.end(), sortPinsByNumber );
|
2011-11-24 19:57:41 +00:00
|
|
|
for( int ii = 0; ii < (int)pinList.size()-1; ii++ )
|
2011-02-11 10:52:48 +00:00
|
|
|
{
|
|
|
|
if( pinList[ii]->GetNumber() == pinList[ii+1]->GetNumber() )
|
|
|
|
{ // 2 pins have the same number, remove the redundant pin at index i+1
|
|
|
|
pinList.erase(pinList.begin() + ii + 1);
|
|
|
|
ii--;
|
|
|
|
}
|
|
|
|
}
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
if( pinList.size() )
|
|
|
|
{
|
2010-08-07 15:31:32 +00:00
|
|
|
XNODE* pins;
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-05 14:20:12 +00:00
|
|
|
xlibpart->AddChild( pins = node( sPins ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
for( unsigned i=0; i<pinList.size(); ++i )
|
|
|
|
{
|
2010-08-07 15:31:32 +00:00
|
|
|
XNODE* pin;
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-05 14:20:12 +00:00
|
|
|
pins->AddChild( pin = node( sPin ) );
|
2011-02-11 10:52:48 +00:00
|
|
|
pin->AddAttribute( sPinNum, pinList[i]->GetNumberString() );
|
|
|
|
pin->AddAttribute( sPinName, pinList[i]->GetName() );
|
2011-02-08 12:01:14 +00:00
|
|
|
pin->AddAttribute( sPinType, pinList[i]->GetTypeString() );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
// caution: construction work site here, drive slowly
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return xlibparts;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
XNODE* NETLIST_EXPORT_TOOL::makeGenericListOfNets()
|
2010-08-04 19:14:51 +00:00
|
|
|
{
|
2012-11-15 16:04:10 +00:00
|
|
|
XNODE* xnets = node( wxT( "nets" ) ); // auto_ptr if exceptions ever get used.
|
2010-08-04 19:14:51 +00:00
|
|
|
wxString netCodeTxt;
|
|
|
|
wxString netName;
|
|
|
|
wxString ref;
|
|
|
|
|
|
|
|
wxString sNet = wxT( "net" );
|
|
|
|
wxString sName = wxT( "name" );
|
|
|
|
wxString sCode = wxT( "code" );
|
|
|
|
wxString sRef = wxT( "ref" );
|
|
|
|
wxString sPin = wxT( "pin" );
|
|
|
|
wxString sNode = wxT( "node" );
|
|
|
|
wxString sFmtd = wxT( "%d" );
|
|
|
|
|
2010-08-07 15:31:32 +00:00
|
|
|
XNODE* xnet = 0;
|
2010-08-04 19:14:51 +00:00
|
|
|
int netCode;
|
|
|
|
int lastNetCode = -1;
|
|
|
|
int sameNetcodeCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* output:
|
|
|
|
<net code="123" name="/cfcard.sch/WAIT#">
|
|
|
|
<node ref="R23" pin="1"/>
|
|
|
|
<node ref="U18" pin="12"/>
|
|
|
|
</net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
m_LibParts.clear(); // must call this function before using m_LibParts.
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
|
|
|
{
|
|
|
|
NETLIST_OBJECT* nitem = g_NetObjectslist[ii];
|
|
|
|
SCH_COMPONENT* comp;
|
|
|
|
|
|
|
|
// New net found, write net id;
|
|
|
|
if( ( netCode = nitem->GetNet() ) != lastNetCode )
|
|
|
|
{
|
|
|
|
sameNetcodeCount = 0; // item count for this net
|
|
|
|
|
|
|
|
netName.Empty();
|
|
|
|
|
|
|
|
// Find a label for this net, if it exists.
|
|
|
|
NETLIST_OBJECT* netref = nitem->m_NetNameCandidate;
|
|
|
|
if( netref )
|
|
|
|
{
|
|
|
|
if( netref->m_Type != NET_PINLABEL && netref->m_Type != NET_GLOBLABEL )
|
|
|
|
{
|
|
|
|
// usual net name, prefix it by the sheet path
|
|
|
|
netName = netref->m_SheetList.PathHumanReadable();
|
|
|
|
}
|
|
|
|
|
|
|
|
netName += netref->m_Label;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastNetCode = netCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nitem->m_Type != NET_PIN )
|
|
|
|
continue;
|
|
|
|
|
2011-02-10 17:49:04 +00:00
|
|
|
if( nitem->m_Flag != 0 ) // Redundant pin, skip it
|
|
|
|
continue;
|
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
comp = (SCH_COMPONENT*) nitem->m_Link;
|
|
|
|
|
|
|
|
// Get the reference for the net name and the main parent component
|
|
|
|
ref = comp->GetRef( &nitem->m_SheetList );
|
|
|
|
if( ref[0] == wxChar( '#' ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( ++sameNetcodeCount == 1 )
|
|
|
|
{
|
2010-08-05 14:20:12 +00:00
|
|
|
xnets->AddChild( xnet = node( sNet ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
netCodeTxt.Printf( sFmtd, netCode );
|
2010-08-08 00:31:07 +00:00
|
|
|
xnet->AddAttribute( sCode, netCodeTxt );
|
|
|
|
xnet->AddAttribute( sName, netName );
|
2010-08-04 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2010-08-07 15:31:32 +00:00
|
|
|
XNODE* xnode;
|
2010-08-05 14:20:12 +00:00
|
|
|
xnet->AddChild( xnode = node( sNode ) );
|
2010-08-08 00:31:07 +00:00
|
|
|
xnode->AddAttribute( sRef, ref );
|
|
|
|
xnode->AddAttribute( sPin, nitem->GetPinNumText() );
|
2010-08-04 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return xnets;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
XNODE* NETLIST_EXPORT_TOOL::makeGenericRoot()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-08-07 15:31:32 +00:00
|
|
|
XNODE* xroot = node( wxT( "export" ) );
|
2010-08-07 15:25:18 +00:00
|
|
|
|
2010-08-08 00:31:07 +00:00
|
|
|
xroot->AddAttribute( wxT( "version" ), wxT( "D" ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-07 15:25:18 +00:00
|
|
|
// add the "design" header
|
|
|
|
xroot->AddChild( makeGenericDesignHeader() );
|
|
|
|
|
|
|
|
xroot->AddChild( makeGenericComponents() );
|
|
|
|
|
|
|
|
xroot->AddChild( makeGenericLibParts() );
|
|
|
|
|
|
|
|
// must follow makeGenericLibParts()
|
|
|
|
xroot->AddChild( makeGenericLibraries() );
|
|
|
|
|
|
|
|
xroot->AddChild( makeGenericListOfNets() );
|
|
|
|
|
|
|
|
return xroot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
XNODE* NETLIST_EXPORT_TOOL::makeGenericComponents()
|
2010-08-07 15:25:18 +00:00
|
|
|
{
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* xcomps = node( wxT( "components" ) );
|
2010-08-07 15:25:18 +00:00
|
|
|
|
2010-08-08 00:31:07 +00:00
|
|
|
wxString timeStamp;
|
2010-07-30 21:41:55 +00:00
|
|
|
|
|
|
|
// some strings we need many times, but don't want to construct more
|
|
|
|
// than once for performance. These are used within loops so the
|
2010-07-31 23:57:36 +00:00
|
|
|
// enclosing wxString constructor would fire on each loop iteration if
|
|
|
|
// they were in a nested scope.
|
|
|
|
|
|
|
|
// these are actually constructor invocations, not assignments as it appears:
|
2010-08-08 00:31:07 +00:00
|
|
|
wxString sFields = wxT( "fields" );
|
|
|
|
wxString sField = wxT( "field" );
|
|
|
|
wxString sComponent = wxT( "comp" ); // use "part" ?
|
|
|
|
wxString sName = wxT( "name" );
|
|
|
|
wxString sRef = wxT( "ref" );
|
|
|
|
wxString sPins = wxT( "pins" );
|
|
|
|
wxString sPin = wxT( "pin" );
|
|
|
|
wxString sValue = wxT( "value" );
|
|
|
|
wxString sSheetPath = wxT( "sheetpath" );
|
|
|
|
wxString sFootprint = wxT( "footprint" );
|
|
|
|
wxString sDatasheet = wxT( "datasheet" );
|
|
|
|
wxString sTStamp = wxT( "tstamp" );
|
|
|
|
wxString sTStamps = wxT( "tstamps" );
|
|
|
|
wxString sTSFmt = wxT( "%8.8lX" ); // comp->m_TimeStamp
|
|
|
|
wxString sLibSource = wxT( "libsource" );
|
|
|
|
wxString sLibPart = wxT( "libpart" );
|
|
|
|
wxString sLib = wxT( "lib" );
|
|
|
|
wxString sPart = wxT( "part" );
|
|
|
|
wxString sNames = wxT( "names" );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
m_ReferencesAlreadyFound.Clear();
|
2010-07-30 21:41:55 +00:00
|
|
|
|
|
|
|
SCH_SHEET_LIST sheetList;
|
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
// Output is xml, so there is no reason to remove spaces from the field values.
|
|
|
|
// And XML element names need not be translated to various languages.
|
2010-07-30 21:41:55 +00:00
|
|
|
|
|
|
|
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() )
|
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
for( EDA_ITEM* schItem = path->LastDrawList(); schItem; schItem = schItem->Next() )
|
2010-07-30 21:41:55 +00:00
|
|
|
{
|
2011-02-10 17:49:04 +00:00
|
|
|
SCH_COMPONENT* comp = findNextComponentAndCreatePinList( schItem, path );
|
2010-07-30 21:41:55 +00:00
|
|
|
if( !comp )
|
|
|
|
break; // No component left
|
|
|
|
|
|
|
|
schItem = comp;
|
|
|
|
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* xcomp; // current component being constructed
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
// Output the component's elements in order of expected access frequency.
|
2010-07-31 23:57:36 +00:00
|
|
|
// This may not always look best, but it will allow faster execution
|
|
|
|
// under XSL processing systems which do sequential searching within
|
|
|
|
// an element.
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-08-05 14:20:12 +00:00
|
|
|
xcomps->AddChild( xcomp = node( sComponent ) );
|
2010-08-08 00:31:07 +00:00
|
|
|
xcomp->AddAttribute( sRef, comp->GetRef( path ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-08-05 14:20:12 +00:00
|
|
|
xcomp->AddChild( node( sValue, comp->GetField( VALUE )->m_Text ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
|
|
|
if( !comp->GetField( FOOTPRINT )->m_Text.IsEmpty() )
|
2010-08-05 14:20:12 +00:00
|
|
|
xcomp->AddChild( node( sFootprint, comp->GetField( FOOTPRINT )->m_Text ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
|
|
|
if( !comp->GetField( DATASHEET )->m_Text.IsEmpty() )
|
2010-08-05 14:20:12 +00:00
|
|
|
xcomp->AddChild( node( sDatasheet, comp->GetField( DATASHEET )->m_Text ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-07-31 23:57:36 +00:00
|
|
|
// Export all user defined fields within the component,
|
|
|
|
// which start at field index MANDATORY_FIELDS. Only output the <fields>
|
|
|
|
// container element if there are any <field>s.
|
2010-07-30 21:41:55 +00:00
|
|
|
if( comp->GetFieldCount() > MANDATORY_FIELDS )
|
|
|
|
{
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* xfields;
|
2010-08-05 14:20:12 +00:00
|
|
|
xcomp->AddChild( xfields = node( sFields ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-07-31 23:57:36 +00:00
|
|
|
for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx )
|
2010-07-30 21:41:55 +00:00
|
|
|
{
|
|
|
|
SCH_FIELD* f = comp->GetField( fldNdx );
|
|
|
|
|
2010-07-31 23:57:36 +00:00
|
|
|
// only output a field if non empty
|
2011-12-07 18:47:59 +00:00
|
|
|
if( !f->GetText().IsEmpty() )
|
2010-07-31 23:57:36 +00:00
|
|
|
{
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* xfield;
|
2010-08-05 14:20:12 +00:00
|
|
|
xfields->AddChild( xfield = node( sField, f->m_Text ) );
|
2011-12-07 18:47:59 +00:00
|
|
|
xfield->AddAttribute( sName, f->GetName() );
|
2010-07-31 23:57:36 +00:00
|
|
|
}
|
2010-07-30 21:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* xlibsource;
|
2010-08-05 14:20:12 +00:00
|
|
|
xcomp->AddChild( xlibsource = node( sLibSource ) );
|
2010-07-31 23:57:36 +00:00
|
|
|
|
|
|
|
// "logical" library name, which is in anticipation of a better search
|
|
|
|
// algorithm for parts based on "logical_lib.part" and where logical_lib
|
|
|
|
// is merely the library name minus path and extension.
|
2010-12-14 15:56:30 +00:00
|
|
|
LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() );
|
2010-07-31 23:57:36 +00:00
|
|
|
if( entry )
|
2010-08-08 00:31:07 +00:00
|
|
|
xlibsource->AddAttribute( sLib, entry->GetLibrary()->GetLogicalName() );
|
2010-12-14 15:56:30 +00:00
|
|
|
xlibsource->AddAttribute( sPart, comp->GetLibName() );
|
2010-07-31 23:57:36 +00:00
|
|
|
|
2010-08-08 00:31:07 +00:00
|
|
|
XNODE* xsheetpath;
|
2010-08-05 14:20:12 +00:00
|
|
|
xcomp->AddChild( xsheetpath = node( sSheetPath ) );
|
2010-08-08 00:31:07 +00:00
|
|
|
xsheetpath->AddAttribute( sNames, path->PathHumanReadable() );
|
|
|
|
xsheetpath->AddAttribute( sTStamps, path->Path() );
|
2010-07-31 23:57:36 +00:00
|
|
|
|
2011-12-12 08:37:05 +00:00
|
|
|
timeStamp.Printf( sTSFmt, comp->GetTimeStamp() );
|
2010-08-05 14:20:12 +00:00
|
|
|
xcomp->AddChild( node( sTStamp, timeStamp ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-07 15:25:18 +00:00
|
|
|
return xcomps;
|
|
|
|
}
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
bool NETLIST_EXPORT_TOOL::WriteKiCadNetList( const wxString& aOutFileName )
|
2010-08-07 15:25:18 +00:00
|
|
|
{
|
2011-02-10 17:49:04 +00:00
|
|
|
// Prepare list of nets generation
|
|
|
|
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
|
|
|
g_NetObjectslist[ii]->m_Flag = 0;
|
|
|
|
|
2012-11-15 16:04:10 +00:00
|
|
|
std::auto_ptr<XNODE> xroot( makeGenericRoot() );
|
2010-08-08 00:31:07 +00:00
|
|
|
|
2012-10-25 15:41:20 +00:00
|
|
|
try
|
2010-08-08 00:31:07 +00:00
|
|
|
{
|
2012-10-25 15:41:20 +00:00
|
|
|
FILE_OUTPUTFORMATTER formatter( aOutFileName );
|
|
|
|
|
|
|
|
xroot->Format( &formatter, 0 );
|
2010-08-08 00:31:07 +00:00
|
|
|
}
|
2012-10-25 15:41:20 +00:00
|
|
|
catch( IO_ERROR ioe )
|
2010-08-08 00:31:07 +00:00
|
|
|
{
|
2012-10-25 15:41:20 +00:00
|
|
|
DisplayError( NULL, ioe.errorText );
|
|
|
|
return false;
|
2010-08-08 00:31:07 +00:00
|
|
|
}
|
|
|
|
|
2012-10-25 15:41:20 +00:00
|
|
|
return true;
|
2012-01-26 09:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NETLIST_EXPORT_TOOL::WriteGENERICNetList( const wxString& aOutFileName )
|
|
|
|
{
|
|
|
|
// Prepare list of nets generation
|
|
|
|
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
|
|
|
g_NetObjectslist[ii]->m_Flag = 0;
|
2010-08-08 00:31:07 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
#if 1
|
2010-08-07 15:25:18 +00:00
|
|
|
// output the XML format netlist.
|
|
|
|
wxXmlDocument xdoc;
|
|
|
|
|
|
|
|
xdoc.SetRoot( makeGenericRoot() );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
return xdoc.Save( aOutFileName, 2 /* indent bug, today was ignored by wxXml lib */ );
|
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
#else // output the well established/old generic net list format which was not XML.
|
2010-07-30 21:41:55 +00:00
|
|
|
|
|
|
|
wxString field;
|
|
|
|
wxString footprint;
|
|
|
|
wxString netname;
|
|
|
|
FILE* out;
|
|
|
|
int ret = 0; // OR on each call, test sign bit at very end.
|
|
|
|
|
|
|
|
if( ( out = wxFopen( aOutFileName, wxT( "wt" ) ) ) == NULL )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
wxString msg = _( "Failed to create file " ) + aOutFileName;
|
2011-02-10 17:49:04 +00:00
|
|
|
DisplayError( NULL, msg );
|
2010-07-30 21:41:55 +00:00
|
|
|
return false;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
m_ReferencesAlreadyFound.Clear();
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( out, "$BeginNetlist\n" );
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
// Create netlist module section
|
|
|
|
ret |= fprintf( out, "$BeginComponentList\n" );
|
|
|
|
|
|
|
|
SCH_SHEET_LIST sheetList;
|
|
|
|
|
|
|
|
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
for( EDA_ITEM* schItem = path->LastDrawList(); schItem; schItem = schItem->Next() )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
2011-02-10 17:49:04 +00:00
|
|
|
SCH_COMPONENT* comp = findNextComponentAndCreatePinList( schItem, path );
|
2010-07-30 21:41:55 +00:00
|
|
|
if( !comp )
|
2009-11-04 20:46:53 +00:00
|
|
|
break; // No component left
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
schItem = comp;
|
|
|
|
|
|
|
|
footprint.Empty();
|
|
|
|
if( !comp->GetField( FOOTPRINT )->IsVoid() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
footprint = comp->GetField( FOOTPRINT )->m_Text;
|
|
|
|
footprint.Replace( wxT( " " ), wxT( "_" ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( out, "\n$BeginComponent\n" );
|
|
|
|
ret |= fprintf( out, "TimeStamp=%8.8lX\n", comp->m_TimeStamp );
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( out, "Footprint=%s\n", TO_UTF8( footprint ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
field = wxT( "Reference=" ) + comp->GetRef( path ) + wxT( "\n" );
|
|
|
|
field.Replace( wxT( " " ), wxT( "_" ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fputs( TO_UTF8( field ), out );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
field = comp->GetField( VALUE )->m_Text;
|
|
|
|
field.Replace( wxT( " " ), wxT( "_" ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( out, "Value=%s\n", TO_UTF8( field ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
field = comp->GetLibName();
|
2010-07-30 21:41:55 +00:00
|
|
|
field.Replace( wxT( " " ), wxT( "_" ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( out, "Libref=%s\n", TO_UTF8( field ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
// Write pin list:
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( out, "$BeginPinList\n" );
|
2010-08-03 02:13:33 +00:00
|
|
|
for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-08-03 02:13:33 +00:00
|
|
|
NETLIST_OBJECT* Pin = m_SortedComponentPinList[ii];
|
2007-09-21 13:23:51 +00:00
|
|
|
if( !Pin )
|
|
|
|
continue;
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
sprintPinNetName( &netname, wxT( "$-%.6d" ), Pin );
|
2007-09-21 13:23:51 +00:00
|
|
|
if( netname.IsEmpty() )
|
|
|
|
netname = wxT( "?" );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( out, "%.4s=%s\n", (char*) &Pin->m_PinNum, TO_UTF8( netname ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( out, "$EndPinList\n" );
|
|
|
|
ret |= fprintf( out, "$EndComponent\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( out, "$EndComponentList\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( out, "\n$BeginNets\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
if( !writeGENERICListOfNets( out, g_NetObjectslist ) )
|
2010-07-30 21:41:55 +00:00
|
|
|
ret = -1;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( out, "$EndNets\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( out, "\n$EndNetlist\n" );
|
|
|
|
ret |= fclose( out );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
return ret >= 0;
|
|
|
|
#endif
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
bool NETLIST_EXPORT_TOOL::WriteNetListPspice( FILE* f, bool use_netnames, bool aUsePrefix )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-18 14:38:25 +00:00
|
|
|
int ret = 0;
|
|
|
|
int nbitems;
|
|
|
|
wxString text;
|
|
|
|
wxArrayString spiceCommandAtBeginFile;
|
|
|
|
wxArrayString spiceCommandAtEndFile;
|
|
|
|
wxString msg;
|
|
|
|
wxString netName;
|
|
|
|
|
|
|
|
#define BUFYPOS_LEN 4
|
|
|
|
wxChar bufnum[BUFYPOS_LEN + 1];
|
|
|
|
std::vector<int> pinSequence; // numeric indices into m_SortedComponentPinList
|
|
|
|
wxArrayString stdPinNameArray; // Array containing Standard Pin Names
|
|
|
|
wxString delimeters = wxT( "{:,; }" );
|
|
|
|
wxString disableStr = wxT( "N" );
|
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
ret |= fprintf( f, "* %s (Spice format) creation date: %s\n\n",
|
|
|
|
NETLIST_HEAD_STRING, TO_UTF8( DateAndTime() ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
2011-02-10 17:49:04 +00:00
|
|
|
// Prepare list of nets generation (not used here, but...
|
|
|
|
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
|
|
|
g_NetObjectslist[ii]->m_Flag = 0;
|
|
|
|
|
2011-03-18 14:38:25 +00:00
|
|
|
ret |= fprintf( f, "* To exclude a component from the Spice Netlist add [Spice_Netlist_Enabled] user FIELD set to: N\n" );
|
|
|
|
ret |= fprintf( f, "* To reorder the component spice node sequence add [Spice_Node_Sequence] user FIELD and define sequence: 2,1,0\n" );
|
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
// Create text list starting by [.-]pspice , or [.-]gnucap (simulator
|
|
|
|
// commands) and create text list starting by [+]pspice , or [+]gnucap
|
|
|
|
// (simulator commands)
|
2007-09-21 13:23:51 +00:00
|
|
|
bufnum[BUFYPOS_LEN] = 0;
|
2010-08-04 19:14:51 +00:00
|
|
|
SCH_SHEET_LIST sheetList;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
wxChar ident;
|
2010-12-10 19:47:44 +00:00
|
|
|
if( item->Type() != SCH_TEXT_T )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2010-08-03 02:13:33 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
SCH_TEXT* drawText = (SCH_TEXT*) item;
|
|
|
|
|
|
|
|
text = drawText->m_Text;
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
if( text.IsEmpty() )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2010-08-03 02:13:33 +00:00
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
ident = text.GetChar( 0 );
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
if( ident != '.' && ident != '-' && ident != '+' )
|
|
|
|
continue;
|
2010-08-03 02:13:33 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
text.Remove( 0, 1 ); // Remove the first char.
|
|
|
|
text.Remove( 6 ); // text contains 6 char.
|
2008-06-18 09:18:51 +00:00
|
|
|
text.MakeLower();
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
if( ( text == wxT( "pspice" ) ) || ( text == wxT( "gnucap" ) ) )
|
|
|
|
{
|
2010-08-04 19:14:51 +00:00
|
|
|
// Put the Y position as an ascii string, for sort by vertical
|
|
|
|
// position, using usual sort string by alphabetic value
|
|
|
|
int ypos = drawText->m_Pos.y;
|
2009-07-12 15:29:42 +00:00
|
|
|
for( int ii = 0; ii < BUFYPOS_LEN; ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-09-09 17:37:25 +00:00
|
|
|
bufnum[BUFYPOS_LEN - 1 - ii] = (ypos & 63) + ' ';
|
|
|
|
ypos >>= 6;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
text = drawText->m_Text.AfterFirst( ' ' );
|
2010-07-14 13:24:36 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
// First BUFYPOS_LEN char are the Y position.
|
|
|
|
msg.Printf( wxT( "%s %s" ), bufnum, text.GetData() );
|
2007-09-21 13:23:51 +00:00
|
|
|
if( ident == '+' )
|
2010-08-04 19:14:51 +00:00
|
|
|
spiceCommandAtEndFile.Add( msg );
|
2007-09-21 13:23:51 +00:00
|
|
|
else
|
2010-08-04 19:14:51 +00:00
|
|
|
spiceCommandAtBeginFile.Add( msg );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
// Print texts starting by [.-]pspice , ou [.-]gnucap (of course, without
|
|
|
|
// the Y position string)
|
|
|
|
nbitems = spiceCommandAtBeginFile.GetCount();
|
2007-09-21 13:23:51 +00:00
|
|
|
if( nbitems )
|
|
|
|
{
|
2010-08-04 19:14:51 +00:00
|
|
|
spiceCommandAtBeginFile.Sort();
|
2009-07-12 15:29:42 +00:00
|
|
|
for( int ii = 0; ii < nbitems; ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-08-04 19:14:51 +00:00
|
|
|
spiceCommandAtBeginFile[ii].Remove( 0, BUFYPOS_LEN );
|
|
|
|
spiceCommandAtBeginFile[ii].Trim( true );
|
|
|
|
spiceCommandAtBeginFile[ii].Trim( false );
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( f, "%s\n", TO_UTF8( spiceCommandAtBeginFile[ii] ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-04 19:14:51 +00:00
|
|
|
ret |= fprintf( f, "\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
// Create component list
|
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
m_ReferencesAlreadyFound.Clear();
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2012-01-26 09:37:36 +00:00
|
|
|
ret |= fprintf( f, "*Sheet Name:%s\n", TO_UTF8( sheet->PathHumanReadable() ) );
|
2011-03-18 14:38:25 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2011-02-10 17:49:04 +00:00
|
|
|
SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, sheet );
|
2010-08-04 19:14:51 +00:00
|
|
|
if( !comp )
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
item = comp;
|
|
|
|
|
2011-03-18 14:38:25 +00:00
|
|
|
// Reset NodeSeqIndex Count:
|
|
|
|
pinSequence.clear();
|
|
|
|
|
|
|
|
// Check to see if component should be removed from Spice Netlist:
|
|
|
|
SCH_FIELD* netlistEnabledField = comp->FindField( wxT( "Spice_Netlist_Enabled" ) );
|
|
|
|
if( netlistEnabledField )
|
|
|
|
{
|
|
|
|
wxString netlistEnabled = netlistEnabledField->m_Text;
|
|
|
|
|
|
|
|
if( netlistEnabled.IsEmpty() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( netlistEnabled.CmpNoCase( disableStr ) == 0 )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if Alternative Pin Sequence is Available:
|
|
|
|
SCH_FIELD* spiceSeqField = comp->FindField( wxT( "Spice_Node_Sequence" ) );
|
|
|
|
if( spiceSeqField )
|
|
|
|
{
|
|
|
|
// Get String containing the Sequence of Nodes:
|
|
|
|
wxString nodeSeqIndexLineStr = spiceSeqField->m_Text;
|
|
|
|
|
|
|
|
// Verify Field Exists and is not empty:
|
|
|
|
if( nodeSeqIndexLineStr.IsEmpty() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Create an Array of Standard Pin Names from part definition:
|
|
|
|
stdPinNameArray.Clear();
|
|
|
|
for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
|
|
|
|
{
|
|
|
|
NETLIST_OBJECT* pin = m_SortedComponentPinList[ii];
|
|
|
|
if( !pin )
|
|
|
|
continue;
|
|
|
|
stdPinNameArray.Add( pin->GetPinNumText() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get Alt Pin Name Array From User:
|
|
|
|
wxStringTokenizer tkz( nodeSeqIndexLineStr, delimeters );
|
|
|
|
while( tkz.HasMoreTokens() )
|
|
|
|
{
|
|
|
|
wxString pinIndex = tkz.GetNextToken();
|
|
|
|
int seq;
|
|
|
|
|
|
|
|
// Find PinName In Standard List assign Standard List Index to Name:
|
|
|
|
seq = stdPinNameArray.Index(pinIndex);
|
|
|
|
|
|
|
|
if( seq != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
pinSequence.push_back( seq );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 15:22:34 +00:00
|
|
|
//Get Standard Reference Designator:
|
|
|
|
wxString RefName = comp->GetRef( sheet );
|
|
|
|
|
|
|
|
//Conditionally add Prefix only for devices that begin with U or IC:
|
|
|
|
if( aUsePrefix )
|
|
|
|
{
|
|
|
|
if( RefName.StartsWith( wxT( "U" ) ) || RefName.StartsWith( wxT( "IC" ) ) )
|
|
|
|
RefName = wxT( "X" ) + RefName;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret |= fprintf( f, "%s ", TO_UTF8( RefName) );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
// Write pin list:
|
2011-03-18 14:38:25 +00:00
|
|
|
int activePinIndex = 0;
|
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2011-03-18 14:38:25 +00:00
|
|
|
// Case of Alt Sequence definition with Unused/Invalid Node index:
|
|
|
|
// Valid used Node Indexes are in the set {0,1,2,...m_SortedComponentPinList.size()-1}
|
|
|
|
if( pinSequence.size() )
|
|
|
|
{
|
|
|
|
// All Vector values must be less <= max package size
|
|
|
|
// And Total Vector size should be <= package size
|
|
|
|
if( ( (unsigned) pinSequence[ii] < m_SortedComponentPinList.size() ) && ( ii < pinSequence.size() ) )
|
|
|
|
{
|
|
|
|
// Case of Alt Pin Sequence in control good Index:
|
|
|
|
activePinIndex = pinSequence[ii];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Case of Alt Pin Sequence in control Bad Index or not using all pins for simulation:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Case of Standard Pin Sequence in control:
|
|
|
|
else
|
|
|
|
{
|
|
|
|
activePinIndex = ii;
|
|
|
|
}
|
|
|
|
|
|
|
|
NETLIST_OBJECT* pin = m_SortedComponentPinList[activePinIndex];
|
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
if( !pin )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2010-08-03 02:13:33 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
sprintPinNetName( &netName , wxT( "N-%.6d" ), pin );
|
2010-08-03 02:13:33 +00:00
|
|
|
|
|
|
|
if( netName.IsEmpty() )
|
|
|
|
netName = wxT( "?" );
|
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
if( use_netnames )
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( f, " %s", TO_UTF8( netName ) );
|
2010-08-04 19:14:51 +00:00
|
|
|
|
|
|
|
else // Use number for net names (net number = 0 for "GND")
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
// NetName = "0" is "GND" net for Spice
|
2010-08-03 02:13:33 +00:00
|
|
|
if( netName == wxT( "0" ) || netName == wxT( "GND" ) )
|
2010-08-04 19:14:51 +00:00
|
|
|
ret |= fprintf( f, " 0" );
|
2007-09-21 13:23:51 +00:00
|
|
|
else
|
2010-08-04 19:14:51 +00:00
|
|
|
ret |= fprintf( f, " %d", pin->GetNet() );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 15:22:34 +00:00
|
|
|
// Get Component Value Name:
|
|
|
|
wxString CompValue = comp->GetField( VALUE )->m_Text;
|
|
|
|
|
|
|
|
// Check if Override Model Name is Provided:
|
|
|
|
SCH_FIELD* spiceModelField = comp->FindField( wxT( "spice_model" ) );
|
|
|
|
|
|
|
|
if( spiceModelField )
|
|
|
|
{
|
|
|
|
// Get Model Name String:
|
|
|
|
wxString ModelNameStr = spiceModelField->m_Text;
|
|
|
|
|
|
|
|
// Verify Field Exists and is not empty:
|
|
|
|
if( !ModelNameStr.IsEmpty() )
|
|
|
|
CompValue = ModelNameStr;
|
|
|
|
}
|
|
|
|
|
2011-03-18 14:38:25 +00:00
|
|
|
// Print Component Value:
|
2011-03-31 15:22:34 +00:00
|
|
|
ret |= fprintf( f, " %s\t\t",TO_UTF8( CompValue ) );
|
2011-03-18 14:38:25 +00:00
|
|
|
|
|
|
|
// Show Seq Spec on same line as component using line-comment ";":
|
|
|
|
for( unsigned i = 0; i < pinSequence.size(); ++i )
|
|
|
|
{
|
|
|
|
if( i==0 )
|
2012-01-26 09:37:36 +00:00
|
|
|
ret |= fprintf( f, ";Node Sequence Spec.<" );
|
2011-03-18 14:38:25 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
ret |= fprintf( f, "%s", TO_UTF8( stdPinNameArray.Item( pinSequence[i] ) ) );
|
2011-03-18 14:38:25 +00:00
|
|
|
|
|
|
|
if( i < pinSequence.size()-1 )
|
2012-01-26 09:37:36 +00:00
|
|
|
ret |= fprintf( f, "," );
|
2011-03-18 14:38:25 +00:00
|
|
|
else
|
2012-01-26 09:37:36 +00:00
|
|
|
ret |= fprintf( f, ">" );
|
2011-03-18 14:38:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Next Netlist line record:
|
|
|
|
ret |= fprintf( f, "\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
m_SortedComponentPinList.clear();
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
// Print texts starting with [+]pspice or [+]gnucap
|
|
|
|
nbitems = spiceCommandAtEndFile.GetCount();
|
2007-09-21 13:23:51 +00:00
|
|
|
if( nbitems )
|
|
|
|
{
|
2010-08-04 19:14:51 +00:00
|
|
|
ret |= fprintf( f, "\n" );
|
|
|
|
spiceCommandAtEndFile.Sort();
|
2011-03-18 14:38:25 +00:00
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
for( int ii = 0; ii < nbitems; ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-08-04 19:14:51 +00:00
|
|
|
spiceCommandAtEndFile[ii].Remove( 0, +BUFYPOS_LEN );
|
|
|
|
spiceCommandAtEndFile[ii].Trim( true );
|
|
|
|
spiceCommandAtEndFile[ii].Trim( false );
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( f, "%s\n", TO_UTF8( spiceCommandAtEndFile[ii] ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
ret |= fprintf( f, "\n.end\n" );
|
|
|
|
|
|
|
|
return ret >= 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
bool NETLIST_EXPORT_TOOL::WriteNetListPCBNEW( FILE* f, bool with_pcbnew )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-07-31 23:57:36 +00:00
|
|
|
wxString field;
|
2010-07-30 21:41:55 +00:00
|
|
|
wxString footprint;
|
|
|
|
int ret = 0; // zero now, OR in the sign bit on error
|
2010-08-03 02:13:33 +00:00
|
|
|
wxString netName;
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
std::vector< SCH_REFERENCE > cmpList;
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
if( with_pcbnew )
|
2011-11-08 16:37:25 +00:00
|
|
|
ret |= fprintf( f, "# %s created %s\n(\n",
|
|
|
|
NETLIST_HEAD_STRING, TO_UTF8( DateAndTime() ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
else
|
2011-11-08 16:37:25 +00:00
|
|
|
ret |= fprintf( f, "( { %s created %s }\n",
|
|
|
|
NETLIST_HEAD_STRING, TO_UTF8( DateAndTime() ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2011-02-10 17:49:04 +00:00
|
|
|
// Prepare list of nets generation
|
|
|
|
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
|
|
|
g_NetObjectslist[ii]->m_Flag = 0;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2011-02-10 17:49:04 +00:00
|
|
|
// Create netlist module section
|
2010-08-03 02:13:33 +00:00
|
|
|
m_ReferencesAlreadyFound.Clear();
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
SCH_SHEET_LIST sheetList;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
for( EDA_ITEM* item = path->LastDrawList(); item; item = item->Next() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2011-02-10 17:49:04 +00:00
|
|
|
SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, path );
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
if( !comp )
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
item = comp;
|
|
|
|
|
|
|
|
// Get the Component FootprintFilter and put the component in
|
|
|
|
// cmpList if filter is present
|
2011-01-05 19:16:55 +00:00
|
|
|
LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
if( entry )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-09-09 17:37:25 +00:00
|
|
|
if( entry->GetFootPrints().GetCount() != 0 ) // Put in list
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2011-01-05 19:16:55 +00:00
|
|
|
cmpList.push_back( SCH_REFERENCE( comp, entry, *path ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
if( !comp->GetField( FOOTPRINT )->IsVoid() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
footprint = comp->GetField( FOOTPRINT )->m_Text;
|
|
|
|
footprint.Replace( wxT( " " ), wxT( "_" ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
else
|
2010-07-30 21:41:55 +00:00
|
|
|
footprint = wxT( "$noname" );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-31 23:57:36 +00:00
|
|
|
field = comp->GetRef( path );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( f, " ( %s %s",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( comp->GetPath( path ) ),
|
|
|
|
TO_UTF8( footprint ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( f, " %s", TO_UTF8( field ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-07-31 23:57:36 +00:00
|
|
|
field = comp->GetField( VALUE )->m_Text;
|
|
|
|
field.Replace( wxT( " " ), wxT( "_" ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( f, " %s", TO_UTF8( field ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
if( with_pcbnew ) // Add the lib name for this component
|
|
|
|
{
|
2010-12-14 15:56:30 +00:00
|
|
|
field = comp->GetLibName();
|
2010-07-31 23:57:36 +00:00
|
|
|
field.Replace( wxT( " " ), wxT( "_" ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( f, " {Lib=%s}", TO_UTF8( field ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( f, "\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
// Write pin list:
|
2010-08-03 02:13:33 +00:00
|
|
|
for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-08-03 02:13:33 +00:00
|
|
|
NETLIST_OBJECT* pin = m_SortedComponentPinList[ii];
|
2010-07-30 21:41:55 +00:00
|
|
|
if( !pin )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
sprintPinNetName( &netName, wxT( "N-%.6d" ), pin );
|
|
|
|
if( netName.IsEmpty() )
|
|
|
|
netName = wxT( "?" );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
netName.Replace( wxT( " " ), wxT( "_" ) );
|
2009-07-12 15:29:42 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( f, " ( %4.4s %s )\n", (char*) &pin->m_PinNum,
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( netName ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( f, " )\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( f, ")\n*\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
m_SortedComponentPinList.clear();
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
// Write the allowed footprint list for each component
|
|
|
|
if( with_pcbnew && cmpList.size() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
wxString ref;
|
|
|
|
|
|
|
|
ret |= fprintf( f, "{ Allowed footprints by component:\n" );
|
2011-01-05 19:16:55 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
for( unsigned ii = 0; ii < cmpList.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2011-01-05 19:16:55 +00:00
|
|
|
LIB_COMPONENT* entry = cmpList[ii].GetLibComponent();
|
2010-07-30 21:41:55 +00:00
|
|
|
|
|
|
|
ref = cmpList[ii].GetRef();
|
|
|
|
|
|
|
|
ref.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( f, "$component %s\n", TO_UTF8( ref ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
|
|
|
// Write the footprint list
|
2010-09-09 17:37:25 +00:00
|
|
|
for( unsigned jj = 0; jj < entry->GetFootPrints().GetCount(); jj++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( f, " %s\n", TO_UTF8( entry->GetFootPrints()[jj] ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( f, "$endlist\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( f, "$endfootprintlist\n}\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( with_pcbnew )
|
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fprintf( f, "{ Pin List by Nets\n" );
|
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
if( !writeGENERICListOfNets( f, g_NetObjectslist ) )
|
2010-07-30 21:41:55 +00:00
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
ret |= fprintf( f, "}\n" );
|
|
|
|
ret |= fprintf( f, "#End\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
2010-07-30 21:41:55 +00:00
|
|
|
|
|
|
|
return ret >= 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
bool NETLIST_EXPORT_TOOL::addPinToComponentPinList( SCH_COMPONENT* aComponent,
|
2010-08-03 02:13:33 +00:00
|
|
|
SCH_SHEET_PATH* aSheetPath, LIB_PIN* aPin )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
// Search the PIN description for Pin in g_NetObjectslist
|
2009-07-12 15:29:42 +00:00
|
|
|
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-08-03 02:13:33 +00:00
|
|
|
NETLIST_OBJECT* pin = g_NetObjectslist[ii];
|
|
|
|
|
|
|
|
if( pin->m_Type != NET_PIN )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2010-08-03 02:13:33 +00:00
|
|
|
|
|
|
|
if( pin->m_Link != aComponent )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2010-08-03 02:13:33 +00:00
|
|
|
|
2010-12-07 16:10:42 +00:00
|
|
|
if( pin->m_PinNum != aPin->GetNumber() )
|
2008-03-20 01:50:21 +00:00
|
|
|
continue;
|
2010-08-03 02:13:33 +00:00
|
|
|
|
|
|
|
// most expensive test at the end.
|
|
|
|
if( pin->m_SheetList != *aSheetPath )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2009-07-12 15:29:42 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
m_SortedComponentPinList.push_back( pin );
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
if( m_SortedComponentPinList.size() >= MAXPIN )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
// Log message for Internal error
|
2010-08-04 19:14:51 +00:00
|
|
|
DisplayError( NULL, wxT( "addPinToComponentPinList err: MAXPIN reached" ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
2010-08-03 02:13:33 +00:00
|
|
|
|
|
|
|
return true; // we're done, we appended.
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
2010-08-03 02:13:33 +00:00
|
|
|
|
|
|
|
return false;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2011-02-10 17:49:04 +00:00
|
|
|
/*
|
|
|
|
* remove duplicate pins from aPinList (list of pins relative to a given component)
|
|
|
|
* (i.e. set pointer to duplicate pins to NULL in this list).
|
|
|
|
* also set .m_Flag member of "removed" NETLIST_OBJECT pins to 1
|
2012-01-26 09:37:36 +00:00
|
|
|
* When pins are duplicated, not connected duplicate is removed
|
|
|
|
* (for instance when a multiple part per package component has its power pins connected
|
|
|
|
* only on a part).
|
2011-02-10 17:49:04 +00:00
|
|
|
*/
|
2012-01-26 09:37:36 +00:00
|
|
|
void NETLIST_EXPORT_TOOL::eraseDuplicatePins( )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-02-10 19:39:18 +00:00
|
|
|
for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2011-02-10 19:39:18 +00:00
|
|
|
if( m_SortedComponentPinList[ii] == NULL ) /* already deleted */
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2009-07-21 07:25:31 +00:00
|
|
|
/* Search for duplicated pins
|
2009-11-04 20:46:53 +00:00
|
|
|
* If found, remove duplicates. The priority is to keep connected pins
|
|
|
|
* and remove unconnected
|
2009-07-21 07:25:31 +00:00
|
|
|
* - So this allows (for instance when using multi op amps per package
|
|
|
|
* - to connect only one op amp to power
|
2009-11-04 20:46:53 +00:00
|
|
|
* Because the pin list is sorted by m_PinNum value, duplicated pins
|
|
|
|
* are necessary successive in list
|
|
|
|
*/
|
2009-07-05 12:09:41 +00:00
|
|
|
int idxref = ii;
|
2011-02-10 19:39:18 +00:00
|
|
|
for( unsigned jj = ii + 1; jj < m_SortedComponentPinList.size(); jj++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2011-02-10 19:39:18 +00:00
|
|
|
if( m_SortedComponentPinList[jj] == NULL ) // Already removed
|
2009-07-20 17:00:55 +00:00
|
|
|
continue;
|
2010-07-14 13:24:36 +00:00
|
|
|
|
2011-02-10 17:49:04 +00:00
|
|
|
// if other pin num, stop search,
|
|
|
|
// because all pins having the same number are consecutive in list.
|
2011-02-10 19:39:18 +00:00
|
|
|
if( m_SortedComponentPinList[idxref]->m_PinNum != m_SortedComponentPinList[jj]->m_PinNum )
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
2010-08-03 02:13:33 +00:00
|
|
|
|
2011-02-10 19:39:18 +00:00
|
|
|
if( m_SortedComponentPinList[idxref]->m_FlagOfConnection == PAD_CONNECT )
|
2011-02-10 17:49:04 +00:00
|
|
|
{
|
2011-02-10 19:39:18 +00:00
|
|
|
m_SortedComponentPinList[jj]->m_Flag = 1;
|
|
|
|
m_SortedComponentPinList[jj] = NULL;
|
2011-02-10 17:49:04 +00:00
|
|
|
}
|
2009-11-04 20:46:53 +00:00
|
|
|
else /* the reference pin is not connected: remove this pin if the
|
|
|
|
* other pin is connected */
|
|
|
|
{
|
2011-02-10 19:39:18 +00:00
|
|
|
if( m_SortedComponentPinList[jj]->m_FlagOfConnection == PAD_CONNECT )
|
2009-07-05 12:09:41 +00:00
|
|
|
{
|
2011-02-10 19:39:18 +00:00
|
|
|
m_SortedComponentPinList[idxref]->m_Flag = 1;
|
|
|
|
m_SortedComponentPinList[idxref] = NULL;
|
2009-07-05 12:09:41 +00:00
|
|
|
idxref = jj;
|
|
|
|
}
|
2009-11-04 20:46:53 +00:00
|
|
|
else // the 2 pins are not connected: remove the tested pin,
|
2011-02-10 17:49:04 +00:00
|
|
|
{ // and continue ...
|
2011-02-10 19:39:18 +00:00
|
|
|
m_SortedComponentPinList[jj]->m_Flag = 1;
|
|
|
|
m_SortedComponentPinList[jj] = NULL;
|
2011-02-10 17:49:04 +00:00
|
|
|
}
|
2009-07-05 12:09:41 +00:00
|
|
|
}
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
void NETLIST_EXPORT_TOOL::findAllInstancesOfComponent( SCH_COMPONENT* aComponent,
|
2010-08-03 02:13:33 +00:00
|
|
|
LIB_COMPONENT* aEntry,
|
|
|
|
SCH_SHEET_PATH* aSheetPath )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-08-03 02:13:33 +00:00
|
|
|
wxString ref = aComponent->GetRef( aSheetPath );
|
|
|
|
wxString ref2;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
SCH_SHEET_LIST sheetList;
|
2008-05-15 11:20:19 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
2008-05-15 11:20:19 +00:00
|
|
|
continue;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-08-04 19:14:51 +00:00
|
|
|
SCH_COMPONENT* comp2 = (SCH_COMPONENT*) item;
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
ref2 = comp2->GetRef( sheet );
|
|
|
|
if( ref2.CmpNoCase( ref ) != 0 )
|
2008-05-15 11:20:19 +00:00
|
|
|
continue;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2011-03-17 10:52:01 +00:00
|
|
|
int unit2 = comp2->GetUnitSelection( sheet ); // slow
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
for( LIB_PIN* pin = aEntry->GetNextPin(); pin; pin = aEntry->GetNextPin( pin ) )
|
2008-05-15 11:20:19 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
wxASSERT( pin->Type() == LIB_PIN_T );
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
if( pin->GetUnit() && pin->GetUnit() != unit2 )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
if( pin->GetConvert() && pin->GetConvert() != comp2->GetConvert() )
|
2009-11-04 20:46:53 +00:00
|
|
|
continue;
|
2009-07-05 12:09:41 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
// A suitable pin is found: add it to the current list
|
2010-08-04 19:14:51 +00:00
|
|
|
addPinToComponentPinList( comp2, sheet, pin );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
bool NETLIST_EXPORT_TOOL::writeGENERICListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
int ret = 0;
|
|
|
|
int netCode;
|
|
|
|
int lastNetCode = -1;
|
|
|
|
int sameNetcodeCount = 0;
|
|
|
|
wxString netName;
|
|
|
|
wxString ref;
|
|
|
|
wxString netcodeName;
|
|
|
|
char firstItemInNet[256];
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
for( unsigned ii = 0; ii < aObjectsList.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
SCH_COMPONENT* comp;
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
// New net found, write net id;
|
2010-07-30 21:41:55 +00:00
|
|
|
if( ( netCode = aObjectsList[ii]->GetNet() ) != lastNetCode )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
sameNetcodeCount = 0; // Items count for this net
|
|
|
|
netName.Empty();
|
2009-11-04 20:46:53 +00:00
|
|
|
|
|
|
|
// Find a label (if exists) for this net.
|
2010-06-23 17:00:12 +00:00
|
|
|
NETLIST_OBJECT* netref;
|
|
|
|
netref = aObjectsList[ii]->m_NetNameCandidate;
|
|
|
|
if( netref )
|
2010-07-30 21:41:55 +00:00
|
|
|
netName = netref->m_Label;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
netcodeName.Printf( wxT( "Net %d " ), netCode );
|
|
|
|
netcodeName += wxT( "\"" );
|
|
|
|
if( !netName.IsEmpty() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-14 13:24:36 +00:00
|
|
|
if( ( netref->m_Type != NET_PINLABEL )
|
|
|
|
&& ( netref->m_Type != NET_GLOBLABEL ) )
|
2008-05-15 11:20:19 +00:00
|
|
|
{
|
2008-10-25 10:21:46 +00:00
|
|
|
// usual net name, prefix it by the sheet path
|
2010-07-30 21:41:55 +00:00
|
|
|
netcodeName += netref->m_SheetList.PathHumanReadable();
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2010-07-30 21:41:55 +00:00
|
|
|
netcodeName += netName;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
2010-07-30 21:41:55 +00:00
|
|
|
netcodeName += wxT( "\"" );
|
2009-07-05 12:09:41 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
// Add the netname without prefix, in cases we need only the
|
|
|
|
// "short" netname
|
2010-07-30 21:41:55 +00:00
|
|
|
netcodeName += wxT( " \"" ) + netName + wxT( "\"" );
|
|
|
|
lastNetCode = netCode;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[ii]->m_Type != NET_PIN )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
|
2011-02-10 17:49:04 +00:00
|
|
|
if( aObjectsList[ii]->m_Flag != 0 ) // Redundant pin, skip it
|
|
|
|
continue;
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
comp = (SCH_COMPONENT*) aObjectsList[ii]->m_Link;
|
2009-11-04 20:46:53 +00:00
|
|
|
|
|
|
|
// Get the reference for the net name and the main parent component
|
2010-07-30 21:41:55 +00:00
|
|
|
ref = comp->GetRef( &aObjectsList[ii]->m_SheetList );
|
|
|
|
if( ref[0] == wxChar( '#' ) )
|
2009-11-04 20:46:53 +00:00
|
|
|
continue; // Pseudo component (Like Power symbol)
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
// Print the pin list for this net, use special handling if
|
|
|
|
// 2 or more items are connected:
|
|
|
|
|
|
|
|
// if first item for this net found, defer printing this connection
|
|
|
|
// until a second item will is found
|
|
|
|
if( ++sameNetcodeCount == 1 )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
snprintf( firstItemInNet, sizeof(firstItemInNet), " %s %.4s\n",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( ref ),
|
2010-07-30 21:41:55 +00:00
|
|
|
(const char*) &aObjectsList[ii]->m_PinNum );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
// Second item for this net found, print the Net name, and the
|
2009-11-04 20:46:53 +00:00
|
|
|
// first item
|
2010-07-30 21:41:55 +00:00
|
|
|
if( sameNetcodeCount == 2 )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( f, "%s\n", TO_UTF8( netcodeName ) );
|
2010-07-30 21:41:55 +00:00
|
|
|
ret |= fputs( firstItemInNet, f );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
if( sameNetcodeCount >= 2 )
|
2011-02-28 18:36:19 +00:00
|
|
|
ret |= fprintf( f, " %s %.4s\n", TO_UTF8( ref ),
|
2009-07-12 15:29:42 +00:00
|
|
|
(const char*) &aObjectsList[ii]->m_PinNum );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
2010-07-30 21:41:55 +00:00
|
|
|
|
|
|
|
return ret >= 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Generate CADSTAR net list. */
|
2010-08-11 05:58:34 +00:00
|
|
|
static wxString StartLine( wxT( "." ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
bool NETLIST_EXPORT_TOOL::WriteNetListCADSTAR( FILE* f )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-01-26 09:37:36 +00:00
|
|
|
int ret = 0;
|
2007-09-21 13:23:51 +00:00
|
|
|
wxString StartCmpDesc = StartLine + wxT( "ADD_COM" );
|
|
|
|
wxString msg;
|
2010-07-30 21:41:55 +00:00
|
|
|
wxString footprint;
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* sheet;
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* DrawList;
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* Component;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString Title = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
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" );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2011-02-10 17:49:04 +00:00
|
|
|
// Prepare list of nets generation
|
|
|
|
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
|
|
|
g_NetObjectslist[ii]->m_Flag = 0;
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
// Create netlist module section
|
2010-08-03 02:13:33 +00:00
|
|
|
m_ReferencesAlreadyFound.Clear();
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_LIST SheetList;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-06-24 18:31:43 +00:00
|
|
|
for( DrawList = sheet->LastDrawList(); DrawList != NULL; DrawList = DrawList->Next() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2011-02-10 17:49:04 +00:00
|
|
|
DrawList = Component = findNextComponentAndCreatePinList( DrawList, sheet );
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
if( Component == NULL )
|
|
|
|
break;
|
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
/*
|
|
|
|
doing nothing with footprint
|
2008-10-06 05:44:29 +00:00
|
|
|
if( !Component->GetField( FOOTPRINT )->IsVoid() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2010-07-30 21:41:55 +00:00
|
|
|
footprint = Component->GetField( FOOTPRINT )->m_Text;
|
|
|
|
footprint.Replace( wxT( " " ), wxT( "_" ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
else
|
2010-07-30 21:41:55 +00:00
|
|
|
footprint = wxT( "$noname" );
|
|
|
|
*/
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
msg = Component->GetRef( sheet );
|
2012-01-26 09:37:36 +00:00
|
|
|
ret |= fprintf( f, "%s ", TO_UTF8( StartCmpDesc ) );
|
|
|
|
ret |= fprintf( f, "%s", TO_UTF8( msg ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
msg = Component->GetField( VALUE )->m_Text;
|
2007-09-21 13:23:51 +00:00
|
|
|
msg.Replace( wxT( " " ), wxT( "_" ) );
|
2012-01-26 09:37:36 +00:00
|
|
|
ret |= fprintf( f, " \"%s\"", TO_UTF8( msg ) );
|
|
|
|
ret |= fprintf( f, "\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
ret |= fprintf( f, "\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-08-03 02:13:33 +00:00
|
|
|
m_SortedComponentPinList.clear();
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
if( ! writeListOfNetsCADSTAR( f, g_NetObjectslist ) )
|
|
|
|
ret = -1; // set error
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
ret |= fprintf( f, "\n%sEND\n", TO_UTF8( StartLine ) );
|
|
|
|
|
|
|
|
return ret >= 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
bool NETLIST_EXPORT_TOOL::writeListOfNetsCADSTAR( FILE* f, NETLIST_OBJECT_LIST& aObjectsList )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-01-26 09:37:36 +00:00
|
|
|
int ret = 0;
|
2007-09-21 13:23:51 +00:00
|
|
|
wxString InitNetDesc = StartLine + wxT( "ADD_TER" );
|
|
|
|
wxString StartNetDesc = StartLine + wxT( "TER" );
|
2010-07-30 21:41:55 +00:00
|
|
|
wxString netcodeName, InitNetDescLine;
|
2010-06-23 17:00:12 +00:00
|
|
|
unsigned ii;
|
2009-07-12 15:29:42 +00:00
|
|
|
int print_ter = 0;
|
2010-07-30 21:41:55 +00:00
|
|
|
int NetCode, lastNetCode = -1;
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* Cmp;
|
2007-09-21 13:23:51 +00:00
|
|
|
wxString NetName;
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
for( ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
// Get the NetName of the current net :
|
2010-07-30 21:41:55 +00:00
|
|
|
if( ( NetCode = aObjectsList[ii]->GetNet() ) != lastNetCode )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
NetName.Empty();
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2010-06-23 17:00:12 +00:00
|
|
|
NETLIST_OBJECT* netref;
|
|
|
|
netref = aObjectsList[ii]->m_NetNameCandidate;
|
|
|
|
if( netref )
|
2010-06-24 18:31:43 +00:00
|
|
|
NetName = netref->m_Label;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-30 21:41:55 +00:00
|
|
|
netcodeName = wxT( "\"" );
|
2007-09-21 13:23:51 +00:00
|
|
|
if( !NetName.IsEmpty() )
|
|
|
|
{
|
2010-07-14 13:24:36 +00:00
|
|
|
if( ( netref->m_Type != NET_PINLABEL )
|
|
|
|
&& ( netref->m_Type != NET_GLOBLABEL ) )
|
2008-05-15 11:20:19 +00:00
|
|
|
{
|
2010-06-23 17:00:12 +00:00
|
|
|
// usual net name, prefix it by the sheet path
|
2010-07-30 21:41:55 +00:00
|
|
|
netcodeName +=
|
2010-06-23 17:00:12 +00:00
|
|
|
netref->m_SheetList.PathHumanReadable();
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2010-07-30 21:41:55 +00:00
|
|
|
netcodeName += NetName;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
else // this net has no name: create a default name $<net number>
|
2010-07-30 21:41:55 +00:00
|
|
|
netcodeName << wxT( "$" ) << NetCode;
|
|
|
|
netcodeName += wxT( "\"" );
|
|
|
|
lastNetCode = NetCode;
|
2007-09-21 13:23:51 +00:00
|
|
|
print_ter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[ii]->m_Type != NET_PIN )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[ii]->m_Flag != 0 )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
Cmp = (SCH_COMPONENT*) aObjectsList[ii]->m_Link;
|
|
|
|
wxString refstr = Cmp->GetRef( &(aObjectsList[ii]->m_SheetList) );
|
2008-02-12 21:12:46 +00:00
|
|
|
if( refstr[0] == '#' )
|
2009-11-04 20:46:53 +00:00
|
|
|
continue; // Power supply symbols.
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
switch( print_ter )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
char buf[5];
|
|
|
|
wxString str_pinnum;
|
2009-07-12 15:29:42 +00:00
|
|
|
strncpy( buf, (char*) &aObjectsList[ii]->m_PinNum, 4 );
|
2009-11-04 20:46:53 +00:00
|
|
|
buf[4] = 0;
|
2011-02-28 18:36:19 +00:00
|
|
|
str_pinnum = FROM_UTF8( buf );
|
2007-09-21 13:23:51 +00:00
|
|
|
InitNetDescLine.Printf( wxT( "\n%s %s %.4s %s" ),
|
2010-07-14 13:24:36 +00:00
|
|
|
GetChars( InitNetDesc ),
|
|
|
|
GetChars( refstr ),
|
|
|
|
GetChars( str_pinnum ),
|
2010-07-30 21:41:55 +00:00
|
|
|
GetChars( netcodeName ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
print_ter++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2012-01-26 09:37:36 +00:00
|
|
|
ret |= fprintf( f, "%s\n", TO_UTF8( InitNetDescLine ) );
|
|
|
|
ret |= fprintf( f, "%s %s %.4s\n",
|
|
|
|
TO_UTF8( StartNetDesc ),
|
|
|
|
TO_UTF8( refstr ),
|
|
|
|
(char*) &aObjectsList[ii]->m_PinNum );
|
2007-09-21 13:23:51 +00:00
|
|
|
print_ter++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-01-26 09:37:36 +00:00
|
|
|
ret |= fprintf( f, " %s %.4s\n",
|
|
|
|
TO_UTF8( refstr ),
|
|
|
|
(char*) &aObjectsList[ii]->m_PinNum );
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
aObjectsList[ii]->m_Flag = 1;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
2012-01-26 09:37:36 +00:00
|
|
|
|
|
|
|
return ret >= 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|