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

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
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -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 )
{
+0 −1
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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
+109 −43
Original line number Diff line number Diff line
@@ -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

eeschema/dangling_ends.cpp

deleted100644 → 0
+0 −32
Original line number Diff line number Diff line
/**
 * @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;
}
Loading