Commit f2e5da63 authored by jean-pierre charras's avatar jean-pierre charras

Eeschema: netlist generation: fix bad choice for the "best net name" when...

Eeschema: netlist generation: fix bad choice for the "best net name" when selecting a net name between labels connected to the same net.
Code cleanup and remove unused file.
parent 5927f026
......@@ -9,7 +9,27 @@
#include <common.h>
#include <math_for_graphics.h>
// Returns true if the point P is on the segment S.
// faster than TestSegmentHit() because P should be exactly on S
// therefore works fine only for H, V and 45 deg segm (suitable for wires in eeschema)
bool IsPointOnSegment( const wxPoint& aSegStart, const wxPoint& aSegEnd,
const wxPoint& aTestPoint )
{
wxPoint vectSeg = aSegEnd - aSegStart; // Vector from S1 to S2
wxPoint vectPoint = aTestPoint - aSegStart; // Vector from S1 to P
// Use long long here to avoid overflow in calculations
if( (long long) vectSeg.x * vectPoint.y - (long long) vectSeg.y * vectPoint.x )
return false; /* Cross product non-zero, vectors not parallel */
if( ( (long long) vectSeg.x * vectPoint.x + (long long) vectSeg.y * vectPoint.y ) <
( (long long) vectPoint.x * vectPoint.x + (long long) vectPoint.y * vectPoint.y ) )
return false; /* Point not on segment */
return true;
}
// Returns true if the segment 1 intersectd the segment 2.
bool SegmentIntersectsSegment( const wxPoint &a_p1_l1, const wxPoint &a_p2_l1,
const wxPoint &a_p1_l2, const wxPoint &a_p2_l2 )
{
......
......@@ -71,7 +71,6 @@ set(EESCHEMA_SRCS
component_references_lister.cpp
controle.cpp
cross-probing.cpp
dangling_ends.cpp
database.cpp
${EESCHEMA_DLGS}
edit_component_in_schematic.cpp
......
......@@ -182,7 +182,7 @@ NETLIST_OBJECT::NETLIST_OBJECT()
m_Member = 0; /* for labels type NET_BUSLABELMEMBER ( bus member created
* from the BUS label ) member number
*/
m_FlagOfConnection = UNCONNECTED;
m_ConnectionType = UNCONNECTED;
m_PinNum = 0; /* pin number ( 1 long = 4 bytes -> 4 ascii codes) */
m_netNameCandidate = NULL; /* a pointer to a NETLIST_OBJECT type label connected to this
* object used to give a name to the net
......
......@@ -104,7 +104,7 @@ public:
int m_Member; /* for labels type NET_BUSLABELMEMBER ( bus member
* created from the BUS label ) member number.
*/
NET_CONNECTION_T m_FlagOfConnection;
NET_CONNECTION_T m_ConnectionType; // Used to store the connection type
SCH_SHEET_PATH m_SheetListInclude; // sheet path which contains the hierarchical label
long m_PinNum; // pin number ( 1 long = 4 bytes -> 4 ascii codes)
wxString m_Label; // Label text (for labels) or Pin name (for pins)
......@@ -137,6 +137,23 @@ public:
void SetNet( int aNetCode ) { m_netCode = aNetCode; }
int GetNet() const { return m_netCode; }
/**
* Set the item connection type:
* UNCONNECTED Pin or Label not connected (error)
* NOCONNECT_SYMBOL_PRESENT Pin not connected but have a NoConnect
* symbol on it (no error)
* PAD_CONNECT Normal connection (no error)
*/
void SetConnectionType( NET_CONNECTION_T aFlg = UNCONNECTED )
{
m_ConnectionType = aFlg;
}
NET_CONNECTION_T GetConnectionType()
{
return m_ConnectionType;
}
/**
* Set m_netNameCandidate to a connected item which will
* be used to calcule the net name of the item
......@@ -223,6 +240,10 @@ class NETLIST_OBJECT_LIST: public std::vector <NETLIST_OBJECT*>
{
bool m_isOwner; // = true if the objects in list are owned my me, and therefore
// the memory should be freed by the destructor and the list cleared
int m_lastNetCode; // Used in intermediate calculation: last net code created
int m_lastBusNetCode; // Used in intermediate calculation:
// last net code created for bus members
public:
/**
* Constructor.
......@@ -250,69 +271,77 @@ public:
/*
* Acces to an item in list
*/
NETLIST_OBJECT* GetItem( unsigned aIdx )
NETLIST_OBJECT* GetItem( unsigned aIdx ) const
{
return *( this->begin() + aIdx );
}
/*
* Delete all objects in list and clear list
* (free memory used to store info about NETLIST_OBJECT items)
* Acces to an item type
*/
void ClearList();
NETLIST_ITEM_T GetItemType( unsigned aIdx ) const
{
return GetItem( aIdx )->m_Type;
}
/*
* Sorts the list of connected items by net code
* Acces to an item net code
*/
void SortListbyNetcode();
int GetItemNet( unsigned aIdx ) const
{
return GetItem( aIdx )->GetNet();
}
/*
* Sorts the list of connected items by sheet.
* This sorting is used when searching "physical" connection between items
* because obviously only items inside the same sheet can be connected
NET_CONNECTION_T GetConnectionType( unsigned aIdx )
{
return GetItem( aIdx )->GetConnectionType();
}
/**
* Set the item connection type:
* UNCONNECTED Pin or Label not connected (error)
* NOCONNECT_SYMBOL_PRESENT Pin not connected but have a NoConnect
* symbol on it (no error)
* PAD_CONNECT Normal connection (no error)
*/
void SortListbySheet();
void SetConnectionType( unsigned aIdx, NET_CONNECTION_T aFlg = UNCONNECTED )
{
GetItem( aIdx )->SetConnectionType( aFlg );
}
/*
* Propagate net codes from a parent sheet to an include sheet,
* from a pin sheet connection
* Delete all objects in list and clear list
* (delete NETLIST_OBJECT items)
*/
void SheetLabelConnect( NETLIST_OBJECT* aSheetLabel );
void PointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus, int start );
void FreeList();
/*
* Search connections betweena junction and segments
* Propagate the junction net code to objects connected by this junction.
* The junction must have a valid net code
* The list of objects is expected sorted by sheets.
* Search is done from index aIdxStart to the last element of list
* Clear list but do not delete NETLIST_OBJECT items
* (they can be deleted only if the instance is owner of the items
*/
void SegmentToPointConnect( NETLIST_OBJECT* aJonction, bool aIsBus, int aIdxStart );
void Clear() { this->clear(); }
void ConnectBusLabels();
/**
* Reset the connection type of all items to UNCONNECTED type
*/
void ResetConnectionsType( )
{
for( unsigned ii = 0; ii < size(); ii++ )
GetItem( ii )->SetConnectionType( UNCONNECTED );
}
/*
* Set the m_FlagOfConnection member of items in list
* depending on the connection type:
* UNCONNECTED, PAD_CONNECT or NOCONNECT_SYMBOL_PRESENT
* The list is expected sorted by order of net code,
* i.e. items having the same net code are grouped
* Sorts the list of connected items by net code
*/
void SetUnconnectedFlag();
void SortListbyNetcode();
/**
* Function FindBestNetNameForEachNet
* fill the .m_NetNameCandidate member of each item of aNetItemBuffer
* with a reference to the "best" NETLIST_OBJECT usable to give a name to the net
* If no suitable object found, .m_NetNameCandidate is filled with 0.
* The "best" NETLIST_OBJECT is a NETLIST_OBJECT that have the type label
* and by priority order:
* the label is global or local
* the label is in the first sheet in a hierarchy (the root sheet has the most priority)
* alphabetic order.
/*
* Sorts the list of connected items by sheet.
* This sorting is used when searching "physical" connection between items
* because obviously only items inside the same sheet can be connected
*/
void FindBestNetNameForEachNet();
void SortListbySheet();
#if defined(DEBUG)
void DumpNetTable()
......@@ -352,10 +381,47 @@ private:
{
return Objet1->m_SheetList.Cmp( Objet2->m_SheetList ) < 0;
}
};
/*
* Propagate net codes from a parent sheet to an include sheet,
* from a pin sheet connection
*/
void sheetLabelConnect( NETLIST_OBJECT* aSheetLabel );
void pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus, int start );
extern NETLIST_OBJECT_LIST g_NetObjectslist;
/*
* Search connections betweena junction and segments
* Propagate the junction net code to objects connected by this junction.
* The junction must have a valid net code
* The list of objects is expected sorted by sheets.
* Search is done from index aIdxStart to the last element of list
*/
void segmentToPointConnect( NETLIST_OBJECT* aJonction, bool aIsBus, int aIdxStart );
void connectBusLabels();
/*
* Set the m_FlagOfConnection member of items in list
* depending on the connection type:
* UNCONNECTED, PAD_CONNECT or NOCONNECT_SYMBOL_PRESENT
* The list is expected sorted by order of net code,
* i.e. items having the same net code are grouped
*/
void setUnconnectedFlag();
/**
* Function findBestNetNameForEachNet
* fill the .m_NetNameCandidate member of each item of aNetItemBuffer
* with a reference to the "best" NETLIST_OBJECT usable to give a name to the net
* If no suitable object found, .m_NetNameCandidate is filled with 0.
* The "best" NETLIST_OBJECT is a NETLIST_OBJECT that have the type label
* and by priority order:
* the label is global or local
* the label is in the first sheet in a hierarchy (the root sheet has the most priority)
* alphabetic order.
*/
void findBestNetNameForEachNet();
};
/**
* Function IsBusLabel
......
/**
* @file dangling_ends.cpp
*/
#include <fctsys.h>
#include <gr_basic.h>
#include <sch_item_struct.h>
#include <wxEeschemaStruct.h>
#include <general.h>
#include <protos.h>
#include <class_libentry.h>
#include <lib_pin.h>
#include <sch_component.h>
/* Returns true if the point P is on the segment S. */
bool SegmentIntersect( wxPoint aSegStart, wxPoint aSegEnd, wxPoint aTestPoint )
{
wxPoint vectSeg = aSegEnd - aSegStart; // Vector from S1 to S2
wxPoint vectPoint = aTestPoint - aSegStart; // Vector from S1 to P
// Use long long here to avoid overflow in calculations
if( (long long) vectSeg.x * vectPoint.y - (long long) vectSeg.y * vectPoint.x )
return false; /* Cross product non-zero, vectors not parallel */
if( ( (long long) vectSeg.x * vectPoint.x + (long long) vectSeg.y * vectPoint.y ) <
( (long long) vectPoint.x * vectPoint.x + (long long) vectPoint.y * vectPoint.y ) )
return false; /* Point not on segment */
return true;
}
......@@ -464,20 +464,20 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
*/
TestDuplicateSheetNames( true );
m_parent->BuildNetListBase();
NETLIST_OBJECT_LIST* objectsConnectedList = m_parent->BuildNetListBase();
/* Reset the flag m_FlagOfConnection, that will be used next, in calculations */
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
g_NetObjectslist[ii]->m_FlagOfConnection = UNCONNECTED;
// Reset the connection type indicator
objectsConnectedList->ResetConnectionsType();
unsigned lastNet;
unsigned nextNet = lastNet = 0;
int NetNbItems = 0;
int MinConn = NOC;
for( unsigned net = 0; net < g_NetObjectslist.size(); net++ )
for( unsigned net = 0; net < objectsConnectedList->size(); net++ )
{
if( g_NetObjectslist[lastNet]->GetNet() != g_NetObjectslist[net]->GetNet() )
if( objectsConnectedList->GetItemNet( lastNet ) !=
objectsConnectedList->GetItemNet( net ) )
{
// New net found:
MinConn = NOC;
......@@ -485,7 +485,7 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
nextNet = net;
}
switch( g_NetObjectslist[net]->m_Type )
switch( objectsConnectedList->GetItemType( net ) )
{
// These items do not create erc problems
case NET_ITEM_UNSPECIFIED:
......@@ -507,7 +507,7 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
// ERC problems when pin sheets do not match hierarchical labels.
// Each pin sheet must match a hierarchical label
// Each hierarchical label must match a pin sheet
TestLabel( net, nextNet );
TestLabel( objectsConnectedList, net, nextNet );
break;
case NET_NOCONNECT:
......@@ -516,14 +516,14 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
MinConn = NET_NC;
if( NetNbItems != 0 )
Diagnose( g_NetObjectslist[net], NULL, MinConn, UNC );
Diagnose( objectsConnectedList->GetItem( net ), NULL, MinConn, UNC );
break;
case NET_PIN:
// Look for ERC problems between pins:
TestOthersItems( net, nextNet, &NetNbItems, &MinConn );
TestOthersItems( objectsConnectedList, net, nextNet, &NetNbItems, &MinConn );
break;
}
......
......@@ -727,8 +727,9 @@ Do you want to annotate schematic?" ) ) )
SCH_SCREENS screens;
screens.SchematicCleanUp();
BuildNetListBase();
bool success = WriteNetListFile( aFormat, aFullFileName, aNetlistOptions );
NETLIST_OBJECT_LIST * connectedItemsList = BuildNetListBase();
bool success = WriteNetListFile( connectedItemsList, aFormat,
aFullFileName, aNetlistOptions );
return success;
}
......
......@@ -349,40 +349,40 @@ void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst,
}
void TestOthersItems( unsigned NetItemRef, unsigned netstart,
int* NetNbItems, int* MinConnexion )
void TestOthersItems( NETLIST_OBJECT_LIST* aList,
unsigned aNetItemRef, unsigned aNetStart,
int* aNetNbItems, int* aMinConnexion )
{
unsigned NetItemTst;
int ref_elect_type, jj, erc = OK, local_minconn;
unsigned netItemTst = aNetStart;
int jj;
int erc = OK;
/* Analysis of the table of connections. */
ref_elect_type = g_NetObjectslist[NetItemRef]->m_ElectricalType;
NetItemTst = netstart;
local_minconn = NOC;
int ref_elect_type = aList->GetItem( aNetItemRef )->m_ElectricalType;
int local_minconn = NOC;
if( ref_elect_type == PIN_NC )
local_minconn = NPI;
/* Test pins connected to NetItemRef */
for( ; ; NetItemTst++ )
for( ; ; netItemTst++ )
{
if( NetItemRef == NetItemTst )
if( aNetItemRef == netItemTst )
continue;
// We examine only a given net. We stop the search if the net changes
if( ( NetItemTst >= g_NetObjectslist.size() ) // End of list
|| ( g_NetObjectslist[NetItemRef]->GetNet() !=
g_NetObjectslist[NetItemTst]->GetNet() ) ) // End of net
if( ( netItemTst >= aList->size() ) // End of list
|| ( aList->GetItemNet( aNetItemRef ) !=
aList->GetItemNet( netItemTst ) ) ) // End of net
{
/* End net code found: minimum connection test. */
if( (*MinConnexion < NET_NC ) && (local_minconn < NET_NC ) )
if( ( *aMinConnexion < NET_NC ) && ( local_minconn < NET_NC ) )
{
/* Not connected or not driven pin. */
bool seterr = true;
if( local_minconn == NOC && g_NetObjectslist[NetItemRef]->m_Type == NET_PIN )
if( local_minconn == NOC &&
aList->GetItemType( aNetItemRef ) == NET_PIN )
{
/* This pin is not connected: for multiple part per
* package, and duplicated pin,
......@@ -392,49 +392,49 @@ void TestOthersItems( unsigned NetItemRef, unsigned netstart,
* TODO test also if instances connected are connected to
* the same net
*/
for( unsigned duplicate = 0; duplicate < g_NetObjectslist.size(); duplicate++ )
for( unsigned duplicate = 0; duplicate < aList->size(); duplicate++ )
{
if( g_NetObjectslist[duplicate]->m_Type != NET_PIN )
if( aList->GetItemType( duplicate ) != NET_PIN )
continue;
if( duplicate == NetItemRef )
if( duplicate == aNetItemRef )
continue;
if( g_NetObjectslist[NetItemRef]->m_PinNum !=
g_NetObjectslist[duplicate]->m_PinNum )
if( aList->GetItem( aNetItemRef )->m_PinNum !=
aList->GetItem( duplicate )->m_PinNum )
continue;
if( ( (SCH_COMPONENT*) g_NetObjectslist[NetItemRef]->
m_Link )->GetRef( &g_NetObjectslist[NetItemRef]-> m_SheetList ) !=
( (SCH_COMPONENT*) g_NetObjectslist[duplicate]->m_Link )
->GetRef( &g_NetObjectslist[duplicate]->m_SheetList ) )
if( ( (SCH_COMPONENT*) aList->GetItem( aNetItemRef )->
m_Link )->GetRef( &aList->GetItem( aNetItemRef )-> m_SheetList ) !=
( (SCH_COMPONENT*) aList->GetItem( duplicate )->m_Link )
->GetRef( &aList->GetItem( duplicate )->m_SheetList ) )
continue;
// Same component and same pin. Do dot create error for this pin
// if the other pin is connected (i.e. if duplicate net has an other
// item)
if( (duplicate > 0)
&& ( g_NetObjectslist[duplicate]->GetNet() ==
g_NetObjectslist[duplicate - 1]->GetNet() ) )
&& ( aList->GetItemNet( duplicate ) ==
aList->GetItemNet( duplicate - 1 ) ) )
seterr = false;
if( (duplicate < g_NetObjectslist.size() - 1)
&& ( g_NetObjectslist[duplicate]->GetNet() ==
g_NetObjectslist[duplicate + 1]->GetNet() ) )
if( (duplicate < aList->size() - 1)
&& ( aList->GetItemNet( duplicate ) ==
aList->GetItemNet( duplicate + 1 ) ) )
seterr = false;
}
}
if( seterr )
Diagnose( g_NetObjectslist[NetItemRef], NULL, local_minconn, WAR );
Diagnose( aList->GetItem( aNetItemRef ), NULL, local_minconn, WAR );
*MinConnexion = DRV; // inhibiting other messages of this
*aMinConnexion = DRV; // inhibiting other messages of this
// type for the net.
}
return;
}
switch( g_NetObjectslist[NetItemTst]->m_Type )
switch( aList->GetItemType( netItemTst ) )
{
case NET_ITEM_UNSPECIFIED:
case NET_SEGMENT:
......@@ -456,13 +456,13 @@ void TestOthersItems( unsigned NetItemRef, unsigned netstart,
break;
case NET_PIN:
jj = g_NetObjectslist[NetItemTst]->m_ElectricalType;
jj = aList->GetItem( netItemTst )->m_ElectricalType;
local_minconn = std::max( MinimalReq[ref_elect_type][jj], local_minconn );
if( NetItemTst <= NetItemRef )
if( netItemTst <= aNetItemRef )
break;
*NetNbItems += 1;
*aNetNbItems += 1;
if( erc == OK )
{
......@@ -470,14 +470,12 @@ void TestOthersItems( unsigned NetItemRef, unsigned netstart,
if( erc != OK )
{
if( g_NetObjectslist[NetItemTst]->m_FlagOfConnection == 0 )
if( aList->GetConnectionType( netItemTst ) == UNCONNECTED )
{
Diagnose( g_NetObjectslist[NetItemRef],
g_NetObjectslist[NetItemTst],
0,
erc );
g_NetObjectslist[NetItemTst]->m_FlagOfConnection =
NOCONNECT_SYMBOL_PRESENT;
Diagnose( aList->GetItem( aNetItemRef ),
aList->GetItem( netItemTst ),
0, erc );
aList->SetConnectionType( netItemTst, NOCONNECT_SYMBOL_PRESENT );
}
}
}
......@@ -538,38 +536,36 @@ bool WriteDiagnosticERC( const wxString& aFullFileName )
}
void TestLabel( unsigned NetItemRef, unsigned StartNet )
void TestLabel( NETLIST_OBJECT_LIST* aList, unsigned aNetItemRef, unsigned aStartNet )
{
unsigned NetItemTst;
unsigned netItemTst = aStartNet;
int erc = 1;
NetItemTst = StartNet;
/* Review the list of labels connected to NetItemRef. */
for( ; ; NetItemTst++ )
for( ; ; netItemTst++ )
{
if( NetItemTst == NetItemRef )
if( netItemTst == aNetItemRef )
continue;
/* Is always in the same net? */
if( ( NetItemTst == g_NetObjectslist.size() )
|| ( g_NetObjectslist[NetItemRef]->GetNet() != g_NetObjectslist[NetItemTst]->GetNet() ) )
if( ( netItemTst == aList->size() )
|| ( aList->GetItemNet( aNetItemRef ) != aList->GetItemNet( netItemTst ) ) )
{
/* End Netcode found. */
if( erc )
{
/* Glabel or SheetLabel orphaned. */
Diagnose( g_NetObjectslist[NetItemRef], NULL, -1, WAR );
Diagnose( aList->GetItem( aNetItemRef ), NULL, -1, WAR );
}
return;
}
if( g_NetObjectslist[NetItemRef]->IsLabelConnected( g_NetObjectslist[NetItemTst] ) )
if( aList->GetItem( aNetItemRef )->IsLabelConnected( aList->GetItem( netItemTst ) ) )
erc = 0;
//same thing, different order.
if( g_NetObjectslist[NetItemTst]->IsLabelConnected( g_NetObjectslist[NetItemRef] ) )
if( aList->GetItem( netItemTst )->IsLabelConnected( aList->GetItem( aNetItemRef ) ) )
erc = 0;
}
}
......@@ -33,6 +33,7 @@
class EDA_DRAW_PANEL;
class NETLIST_OBJECT;
class NETLIST_OBJECT_LIST;
/* For ERC markers: error types (used in diags, and to set the color):
*/
......@@ -83,15 +84,16 @@ extern void Diagnose( NETLIST_OBJECT* NetItemRef, NETLIST_OBJECT* NetItemTst,
* Perform ERC testing for electrical conflicts between \a NetItemRef and other items
* on the same net.
*/
extern void TestOthersItems( unsigned NetItemRef, unsigned NetStart,
int* NetNbItems, int* MinConnexion );
extern void TestOthersItems( NETLIST_OBJECT_LIST* aList,
unsigned aNetItemRef, unsigned aNetStart,
int* aNetNbItems, int* aMinConnexion );
/**
* Function TestLabel
* performs an ERC on a sheet labels to verify that it is connected to a corresponding
* sub sheet global label.
*/
extern void TestLabel( unsigned NetItemRef, unsigned StartNet );
extern void TestLabel( NETLIST_OBJECT_LIST* aList, unsigned aNetItemRef, unsigned aStartNet );
/**
* Function TestDuplicateSheetNames( )
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* 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.
* Copyright (C) 1992-2013 jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2013 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -44,15 +44,12 @@
#include <sch_sheet.h>
#include <wx/tokenzr.h>
#include <xnode.h> // also nests: <wx/xml/xml.h>
#include <build_version.h>
#include <set>
#define INTERMEDIATE_NETLIST_EXT wxT("xml")
#include <set>
/**
* Class UNIQUE_STRINGS
* tracks unique wxStrings and is useful in telling if a string
......@@ -95,6 +92,8 @@ bool UNIQUE_STRINGS::Lookup( const wxString& aString )
*/
class NETLIST_EXPORT_TOOL
{
NETLIST_OBJECT_LIST * m_masterList; /// The main connected items flat list
/// Used to temporary store and filter the list of pins of a schematic component
/// when generating schematic component data in netlist (comp section)
NETLIST_OBJECT_LIST m_SortedComponentPinList;
......@@ -187,7 +186,7 @@ class NETLIST_EXPORT_TOOL
* - 6 CA
* </p>
*/
bool writeListOfNetsCADSTAR( FILE* f, NETLIST_OBJECT_LIST& aObjectsList );
bool writeListOfNetsCADSTAR( FILE* f );
/**
* Function makeGenericRoot
......@@ -230,6 +229,10 @@ class NETLIST_EXPORT_TOOL
XNODE* makeGenericLibraries();
public:
NETLIST_EXPORT_TOOL( NETLIST_OBJECT_LIST * aMasterList )
{
m_masterList = aMasterList;
}
/**
* Function WriteKiCadNetList
......@@ -354,6 +357,8 @@ wxString NETLIST_EXPORT_TOOL::MakeCommandLine( const wxString& aFormatString,
/* Function WriteNetListFile
* creates the netlist file. Netlist info must be existing
* (call BuildNetListBase() to create this info )
* param aConnectedItemsList = the initialized list of connected items
* param aFormat = netlist format (NET_TYPE_PCBNEW ...)
* param aFullFileName = full netlist file name
* param aNetlistOptions = netlist options using OR'ed bits.
......@@ -361,12 +366,13 @@ wxString NETLIST_EXPORT_TOOL::MakeCommandLine( const wxString& aFormatString,
* if NET_USE_X_PREFIX is set : change "U" and "IC" refernce prefix to "X"
* return true if success.
*/
bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileName,
bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList,
int aFormat, const wxString& aFullFileName,
unsigned aNetlistOptions )
{
bool ret = true;
FILE* f = NULL;
NETLIST_EXPORT_TOOL helper;
NETLIST_EXPORT_TOOL helper( aConnectedItemsList );
bool open_file = aFormat < NET_TYPE_CUSTOM1;
if( (aFormat == NET_TYPE_PCBNEW) && (aNetlistOptions & NET_PCBNEW_USE_NEW_FORMAT ) )
......@@ -439,8 +445,6 @@ bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileNam
D(printf("commandLine:'%s'\n", TO_UTF8( commandLine ) );)
ProcessExecute( commandLine, wxEXEC_SYNC );
// ::wxRemoveFile( tmpFile.GetFullPath() );
}
break;
}
......@@ -473,7 +477,7 @@ void NETLIST_EXPORT_TOOL::sprintPinNetName( wxString& aResult,
// caller's loop.
aResult.Empty();
if( netcode != 0 && aPin->m_FlagOfConnection == PAD_CONNECT )
if( netcode != 0 && aPin->GetConnectionType() == PAD_CONNECT )
{
aResult = aPin->GetNetName();
......@@ -852,9 +856,9 @@ XNODE* NETLIST_EXPORT_TOOL::makeGenericListOfNets()
m_LibParts.clear(); // must call this function before using m_LibParts.
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
{
NETLIST_OBJECT* nitem = g_NetObjectslist[ii];
NETLIST_OBJECT* nitem = m_masterList->GetItem( ii );
SCH_COMPONENT* comp;
// New net found, write net id;
......@@ -1035,8 +1039,8 @@ XNODE* NETLIST_EXPORT_TOOL::makeGenericComponents()
bool NETLIST_EXPORT_TOOL::WriteKiCadNetList( const wxString& aOutFileName )
{
// Prepare list of nets generation
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
g_NetObjectslist[ii]->m_Flag = 0;
for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
m_masterList->GetItem( ii )->m_Flag = 0;
std::auto_ptr<XNODE> xroot( makeGenericRoot() );
......@@ -1058,8 +1062,8 @@ bool NETLIST_EXPORT_TOOL::WriteKiCadNetList( const wxString& aOutFileName )
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;
for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
m_masterList->GetItem( ii )->m_Flag = 0;
// output the XML format netlist.
wxXmlDocument xdoc;
......@@ -1091,8 +1095,8 @@ bool NETLIST_EXPORT_TOOL::WriteNetListPspice( FILE* f, bool aUsePrefix )
NETLIST_HEAD_STRING, TO_UTF8( DateAndTime() ) );
// Prepare list of nets generation (not used here, but...
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
g_NetObjectslist[ii]->m_Flag = 0;
for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
m_masterList->GetItem( ii )->m_Flag = 0;
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" );
......@@ -1370,8 +1374,8 @@ bool NETLIST_EXPORT_TOOL::WriteNetListPCBNEW( FILE* f, bool with_pcbnew )
NETLIST_HEAD_STRING, TO_UTF8( DateAndTime() ) );
// Prepare list of nets generation
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
g_NetObjectslist[ii]->m_Flag = 0;
for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
m_masterList->GetItem( ii )->m_Flag = 0;
// Create netlist module section
m_ReferencesAlreadyFound.Clear();
......@@ -1487,7 +1491,7 @@ bool NETLIST_EXPORT_TOOL::WriteNetListPCBNEW( FILE* f, bool with_pcbnew )
{
ret |= fprintf( f, "{ Pin List by Nets\n" );
if( !writeGENERICListOfNets( f, g_NetObjectslist ) )
if( !writeGENERICListOfNets( f, *m_masterList ) )
ret = -1;
ret |= fprintf( f, "}\n" );
......@@ -1502,9 +1506,9 @@ bool NETLIST_EXPORT_TOOL::addPinToComponentPinList( SCH_COMPONENT* aComponent,
SCH_SHEET_PATH* aSheetPath, LIB_PIN* aPin )
{
// Search the PIN description for Pin in g_NetObjectslist
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
{
NETLIST_OBJECT* pin = g_NetObjectslist[ii];
NETLIST_OBJECT* pin = m_masterList->GetItem( ii );
if( pin->m_Type != NET_PIN )
continue;
......@@ -1567,7 +1571,7 @@ void NETLIST_EXPORT_TOOL::eraseDuplicatePins( )
if( m_SortedComponentPinList[idxref]->m_PinNum != m_SortedComponentPinList[jj]->m_PinNum )
break;
if( m_SortedComponentPinList[idxref]->m_FlagOfConnection == PAD_CONNECT )
if( m_SortedComponentPinList[idxref]->GetConnectionType() == PAD_CONNECT )
{
m_SortedComponentPinList[jj]->m_Flag = 1;
m_SortedComponentPinList[jj] = NULL;
......@@ -1575,7 +1579,7 @@ void NETLIST_EXPORT_TOOL::eraseDuplicatePins( )
else /* the reference pin is not connected: remove this pin if the
* other pin is connected */
{
if( m_SortedComponentPinList[jj]->m_FlagOfConnection == PAD_CONNECT )
if( m_SortedComponentPinList[jj]->GetConnectionType() == PAD_CONNECT )
{
m_SortedComponentPinList[idxref]->m_Flag = 1;
m_SortedComponentPinList[idxref] = NULL;
......@@ -1729,8 +1733,8 @@ bool NETLIST_EXPORT_TOOL::WriteNetListCADSTAR( FILE* f )
ret |= fprintf( f, "\n" );
// Prepare list of nets generation
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
g_NetObjectslist[ii]->m_Flag = 0;
for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
m_masterList->GetItem( ii )->m_Flag = 0;
// Create netlist module section
m_ReferencesAlreadyFound.Clear();
......@@ -1772,7 +1776,7 @@ bool NETLIST_EXPORT_TOOL::WriteNetListCADSTAR( FILE* f )
m_SortedComponentPinList.clear();
if( ! writeListOfNetsCADSTAR( f, g_NetObjectslist ) )
if( ! writeListOfNetsCADSTAR( f ) )
ret = -1; // set error
ret |= fprintf( f, "\n%sEND\n", TO_UTF8( StartLine ) );
......@@ -1781,7 +1785,7 @@ bool NETLIST_EXPORT_TOOL::WriteNetListCADSTAR( FILE* f )
}
bool NETLIST_EXPORT_TOOL::writeListOfNetsCADSTAR( FILE* f, NETLIST_OBJECT_LIST& aObjectsList )
bool NETLIST_EXPORT_TOOL::writeListOfNetsCADSTAR( FILE* f )
{
int ret = 0;
wxString InitNetDesc = StartLine + wxT( "ADD_TER" );
......@@ -1793,9 +1797,9 @@ bool NETLIST_EXPORT_TOOL::writeListOfNetsCADSTAR( FILE* f, NETLIST_OBJECT_LIST&
SCH_COMPONENT* Cmp;
wxString netName;
for( ii = 0; ii < g_NetObjectslist.size(); ii++ )
for( ii = 0; ii < m_masterList->size(); ii++ )
{
NETLIST_OBJECT* nitem = aObjectsList[ii];
NETLIST_OBJECT* nitem = m_masterList->GetItem( ii );
// Get the NetName of the current net :
if( ( NetCode = nitem->GetNet() ) != lastNetCode )
......
This diff is collapsed.
......@@ -21,12 +21,6 @@ class SCH_ITEM;
//void DisplayCmpDoc( wxString& Name );
wxString DataBaseGetName( EDA_DRAW_FRAME* frame, wxString& Keys, wxString& BufName );
/*********************/
/* DANGLING_ENDS.CPP */
/*********************/
bool SegmentIntersect( wxPoint aSegStart, wxPoint aSegEnd, wxPoint aTestPoint );
// operations_on_item_lists.cpp
void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList );
......
......@@ -535,7 +535,7 @@ bool SCH_TEXT::IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemLi
wxT( "Dangling end type list overflow. Bad programmer!" ) );
DANGLING_END_ITEM & nextItem = aItemList[ii];
m_isDangling = !SegmentIntersect( item.GetPosition(), nextItem.GetPosition(), m_Pos );
m_isDangling = !IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), m_Pos );
}
break;
......
......@@ -31,6 +31,19 @@
#include <math.h>
#include <wx/gdicmn.h> // For wxPoint
/**
* Function IsPointOnSegment
* @param aSegStart The first point of the segment S.
* @param aSegEnd The second point of the segment S.
* @param aTestPoint The point P to test.
* @return true if the point P is on the segment S.
* faster than TestSegmentHit() because P should be exactly on S
* therefore works fine only for H, V and 45 deg segm.
* suitable for busses and wires in eeschema, otherwise use TestSegmentHit()
*/
bool IsPointOnSegment( const wxPoint& aSegStart, const wxPoint& aSegEnd,
const wxPoint& aTestPoint );
/**
* Function SegmentIntersectsSegment
*
......
......@@ -446,8 +446,14 @@ public:
*/
void SendMessageToPCBNEW( EDA_ITEM* objectToSync, SCH_COMPONENT* LibItem );
/* netlist generation */
void BuildNetListBase();
/**
* BuildNetListBase
* netlist generation:
* Creates a flat list which stores all connected objects, and mainly
* pins and labels.
* @return a pointer to the list
*/
NETLIST_OBJECT_LIST * BuildNetListBase();
/**
* Function CreateNetlist
......@@ -474,6 +480,8 @@ public:
/**
* Function WriteNetListFile
* Create the netlist file. Netlist info must be existing
* (BuildNetListBase() creates this info)
* @param aConnectedItemsList = the initialized list of connected items
* @param aFormat = netlist format (NET_TYPE_PCBNEW ...)
* @param aFullFileName = full netlist file name
* @param aNetlistOptions = netlist options using OR'ed bits.
......@@ -485,7 +493,8 @@ public:
* </p>
* @return true if success.
*/
bool WriteNetListFile( int aFormat,
bool WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList,
int aFormat,
const wxString& aFullFileName,
unsigned aNetlistOptions );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment