Commit 2ba19844 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Eeschema net list object generation improvements.

* Define function to allow schematic objects to create their own net list
  objects.
* Add net list object creation functions to schematic line, junction, and
  no connect objects.
* Add license statements to all modified files that required one.
parent d4fb921b
Loading
Loading
Loading
Loading
+51 −106
Original line number Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 Kicad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file eeschema/netlist.cpp
 */
@@ -94,13 +119,10 @@ void SCH_EDIT_FRAME::BuildNetListBase()
    FreeNetObjectsList( g_NetObjectslist );

    /* Build the sheet (not screen) list (flattened)*/
    SCH_SHEET_LIST SheetListList;
    SCH_SHEET_LIST sheets;

    /* Fill g_NetObjectslist with items used in connectivity calculation */

    sheet = SheetListList.GetFirst();

    for( ; sheet != NULL; sheet = SheetListList.GetNext() )
    for( sheet = sheets.GetFirst(); sheet != NULL; sheet = sheets.GetNext() )
        AddConnectedObjects( sheet, g_NetObjectslist );

    if( g_NetObjectslist.size() == 0 )
@@ -409,6 +431,7 @@ static NETLIST_OBJECT* FindBestNetName( NETLIST_OBJECT_LIST& aLabelItemBuffer )

    // Calculate item priority (initial priority)
    int item_priority = 0;

    for( unsigned ii = 0; ii <= NET_PRIO_MAX; ii++ )
    {
        if ( item->m_Type == priority_order[ii]  )
@@ -433,6 +456,7 @@ static NETLIST_OBJECT* FindBestNetName( NETLIST_OBJECT_LIST& aLabelItemBuffer )
                break;
            }
        }

        if( candidate_priority > item_priority )
        {
            item = candidate;
@@ -474,6 +498,7 @@ static NETLIST_OBJECT* FindBestNetName( NETLIST_OBJECT_LIST& aLabelItemBuffer )
    return item;
}


/*
 * Connect sheets by sheetLabels
 */
@@ -489,11 +514,11 @@ static void SheetLabelConnect( NETLIST_OBJECT* SheetLabel )
    for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
    {
        NETLIST_OBJECT* ObjetNet = g_NetObjectslist[ii];

        if( ObjetNet->m_SheetList != SheetLabel->m_SheetListInclude )
            continue;  //use SheetInclude, not the sheet!!

        if( (ObjetNet->m_Type != NET_HIERLABEL )
           && (ObjetNet->m_Type != NET_HIERBUSLABELMEMBER ) )
        if( (ObjetNet->m_Type != NET_HIERLABEL ) && (ObjetNet->m_Type != NET_HIERBUSLABELMEMBER ) )
            continue;

        if( ObjetNet->GetNet() == SheetLabel->GetNet() )
@@ -524,105 +549,33 @@ static void AddConnectedObjects( SCH_SHEET_PATH* sheetlist,
                                 std::vector<NETLIST_OBJECT*>& aNetItemBuffer )
{
    int             ii;
    SCH_ITEM*       DrawList;
    SCH_ITEM*       item;
    NETLIST_OBJECT* new_item;
    SCH_COMPONENT*  DrawLibItem;
    LIB_COMPONENT*  Entry;
    SCH_SHEET_PATH  list;

    DrawList = sheetlist->LastScreen()->GetDrawItems();
    item = sheetlist->LastScreen()->GetDrawItems();

    for( ; DrawList; DrawList = DrawList->Next() )
    for( ; item; item = item->Next() )
    {
        switch( DrawList->Type() )
        switch( item->Type() )
        {
        case SCH_POLYLINE_T:
        case SCH_BUS_ENTRY_T:
        case SCH_MARKER_T:
        case SCH_TEXT_T:
        case SCH_LINE_T:
            #undef STRUCT
            #define STRUCT ( (SCH_LINE*) DrawList )

            if( (STRUCT->GetLayer() != LAYER_BUS) && (STRUCT->GetLayer() != LAYER_WIRE) )
                break;

            new_item = new NETLIST_OBJECT();
            new_item->m_SheetList = *sheetlist;
            new_item->m_SheetListInclude = *sheetlist;
            new_item->m_Comp  = STRUCT;
            new_item->m_Start = STRUCT->m_Start;
            new_item->m_End   = STRUCT->m_End;

            if( STRUCT->GetLayer() == LAYER_BUS )
            {
                new_item->m_Type = NET_BUS;
            }
            else            /* WIRE */
            {
                new_item->m_Type = NET_SEGMENT;
            }

            aNetItemBuffer.push_back( new_item );
            break;

        case SCH_JUNCTION_T:
            #undef STRUCT
            #define STRUCT ( (SCH_JUNCTION*) DrawList )
            new_item = new NETLIST_OBJECT();

            new_item->m_SheetList = *sheetlist;
            new_item->m_SheetListInclude = *sheetlist;
            new_item->m_Comp  = STRUCT;
            new_item->m_Type  = NET_JUNCTION;
            new_item->m_Start = new_item->m_End = STRUCT->m_Pos;

            aNetItemBuffer.push_back( new_item );
            break;

        case SCH_NO_CONNECT_T:
            #undef STRUCT
            #define STRUCT ( (SCH_NO_CONNECT*) DrawList )
            new_item = new NETLIST_OBJECT();

            new_item->m_SheetList = *sheetlist;
            new_item->m_SheetListInclude = *sheetlist;
            new_item->m_Comp  = STRUCT;
            new_item->m_Type  = NET_NOCONNECT;
            new_item->m_Start = new_item->m_End = STRUCT->m_Pos;

            aNetItemBuffer.push_back( new_item );
            item->GetNetListItem( aNetItemBuffer, sheetlist );
            break;

        case SCH_LABEL_T:
            #undef STRUCT
            #define STRUCT ( (SCH_LABEL*) DrawList )
            ii = IsBusLabel( STRUCT->m_Text );

            new_item = new NETLIST_OBJECT();
            new_item->m_SheetList = *sheetlist;
            new_item->m_SheetListInclude = *sheetlist;
            new_item->m_Comp = STRUCT;
            new_item->m_Type = NET_LABEL;

            if( STRUCT->GetLayer() ==  LAYER_GLOBLABEL )
                new_item->m_Type = NET_GLOBLABEL;

            if( STRUCT->GetLayer() ==  LAYER_HIERLABEL )
                new_item->m_Type = NET_HIERLABEL;

            new_item->m_Label = STRUCT->m_Text;
            new_item->m_Start = new_item->m_End = STRUCT->m_Pos;

            aNetItemBuffer.push_back( new_item );

            /* If a bus connects to label */
            if( ii )
                ConvertBusToMembers( aNetItemBuffer, *new_item );


            break;

        case SCH_GLOBAL_LABEL_T:
        case SCH_HIERARCHICAL_LABEL_T:
            #undef STRUCT
            #define STRUCT ( (SCH_LABEL*) DrawList )
            #define STRUCT ( (SCH_LABEL*) item )
            ii = IsBusLabel( STRUCT->m_Text );
            new_item = new NETLIST_OBJECT();
            new_item->m_SheetList = *sheetlist;
@@ -650,7 +603,7 @@ static void AddConnectedObjects( SCH_SHEET_PATH* sheetlist,
            break;

        case SCH_COMPONENT_T:
            DrawLibItem = (SCH_COMPONENT*) DrawList;
            DrawLibItem = (SCH_COMPONENT*) item;

            Entry = CMP_LIBRARY::FindLibraryComponent( DrawLibItem->GetLibName() );

@@ -703,32 +656,26 @@ static void AddConnectedObjects( SCH_SHEET_PATH* sheetlist,
            }
            break;

        case SCH_POLYLINE_T:
        case SCH_BUS_ENTRY_T:
        case SCH_MARKER_T:
        case SCH_TEXT_T:
            break;

        case SCH_SHEET_T:
        {
            #undef STRUCT
            #define STRUCT ( (SCH_SHEET*) DrawList )
            #define STRUCT ( (SCH_SHEET*) item )
            list = *sheetlist;
            list.Push( STRUCT );
            SCH_SHEET* sheet = (SCH_SHEET*) DrawList;
            SCH_SHEET* sheet = (SCH_SHEET*) item;

            BOOST_FOREACH( SCH_SHEET_PIN pin, sheet->GetPins() )
            {
                ii = IsBusLabel( pin.m_Text );
                new_item = new NETLIST_OBJECT();
                new_item->m_SheetList = *sheetlist;
                new_item->m_SheetListInclude = *sheetlist;
                new_item->m_SheetListInclude = list;
                new_item->m_Comp = &pin;
                new_item->m_SheetList = *sheetlist;
                new_item->m_Link = DrawList;
                new_item->m_Link = item;
                new_item->m_Type = NET_SHEETLABEL;
                new_item->m_ElectricalType = pin.m_Shape;
                new_item->m_Label = pin.m_Text;
                new_item->m_SheetListInclude = list;
                new_item->m_Start = new_item->m_End = pin.m_Pos;
                aNetItemBuffer.push_back( new_item );

@@ -743,7 +690,7 @@ static void AddConnectedObjects( SCH_SHEET_PATH* sheetlist,
        default:
        {
            wxString msg;
            msg.Printf( wxT( "Netlist: unexpected struct type %d" ), DrawList->Type() );
            msg.Printf( wxT( "Netlist: unexpected struct type %d" ), item->Type() );
            wxMessageBox( msg );
            break;
        }
@@ -1172,8 +1119,7 @@ void LabelConnect( NETLIST_OBJECT* LabelRef )
/* Comparison routine for sorting by increasing Netcode
 * table of elements connected (TabPinSort) by qsort ()
 */
bool SortItemsbyNetcode( const NETLIST_OBJECT* Objet1,
                         const NETLIST_OBJECT* Objet2 )
bool SortItemsbyNetcode( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 )
{
    return Objet1->GetNet() < Objet2->GetNet();
}
@@ -1182,8 +1128,7 @@ bool SortItemsbyNetcode( const NETLIST_OBJECT* Objet1,
/* Comparison routine for sorting items by Sheet Number ( used by qsort )
 */

bool SortItemsBySheet( const NETLIST_OBJECT* Objet1,
                       const NETLIST_OBJECT* Objet2 )
bool SortItemsBySheet( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 )
{
    return Objet1->m_SheetList.Cmp( Objet2->m_SheetList ) < 0;
}
+44 −7
Original line number Diff line number Diff line
/********************/
/* sch_junction.cpp */
/********************/
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file sch_junction.cpp
 */

#include "fctsys.h"
#include "gr_basic.h"
@@ -14,12 +39,9 @@
#include "general.h"
#include "protos.h"
#include "sch_junction.h"
#include "class_netlist_object.h"


/**********************/
/* class SCH_JUNCTION */
/**********************/

SCH_JUNCTION::SCH_JUNCTION( const wxPoint& pos ) :
    SCH_ITEM( NULL, SCH_JUNCTION_T )
{
@@ -155,6 +177,21 @@ void SCH_JUNCTION::GetConnectionPoints( vector< wxPoint >& aPoints ) const
}


void SCH_JUNCTION::GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
                                   SCH_SHEET_PATH*          aSheetPath )
{
    NETLIST_OBJECT* item = new NETLIST_OBJECT();

    item->m_SheetList = *aSheetPath;
    item->m_SheetListInclude = *aSheetPath;
    item->m_Comp = (SCH_ITEM*) this;
    item->m_Type = NET_JUNCTION;
    item->m_Start = item->m_End = m_Pos;

    aNetListItems.push_back( item );
}


#if defined(DEBUG)
void SCH_JUNCTION::Show( int nestLevel, std::ostream& os )
{
+28 −1
Original line number Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file sch_junction.h
 *
 */

#ifndef _SCH_JUNCTION_H_
@@ -93,6 +117,9 @@ public:

    virtual BITMAP_DEF GetMenuImage() const { return  add_junction_xpm; }

    virtual void GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
                                 SCH_SHEET_PATH*          aSheetPath );

#if defined(DEBUG)
    void Show( int nestLevel, std::ostream& os );
#endif
+59 −4
Original line number Diff line number Diff line
/******************/
/* Class SCH_LINE */
/******************/
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file sch_line.cpp
 * @brief Class SCH_LINE implementation
 */

#include "fctsys.h"
#include "gr_basic.h"
@@ -13,6 +39,7 @@
#include "general.h"
#include "protos.h"
#include "sch_line.h"
#include "class_netlist_object.h"

#include <boost/foreach.hpp>

@@ -23,7 +50,7 @@ SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) :
    m_Start = pos;
    m_End   = pos;
    m_Width = 0;        // Default thickness used
    m_StartIsDangling = m_EndIsDangling = FALSE;
    m_StartIsDangling = m_EndIsDangling = false;

    switch( layer )
    {
@@ -421,6 +448,7 @@ void SCH_LINE::GetConnectionPoints( vector< wxPoint >& aPoints ) const
wxString SCH_LINE::GetSelectMenuText() const
{
    wxString menuText, txtfmt, orient;

    if( m_Start.x == m_End.x )
        orient = _("Vert.");
    else if( m_Start.y == m_End.y )
@@ -465,6 +493,33 @@ BITMAP_DEF SCH_LINE::GetMenuImage() const
}


void SCH_LINE::GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
                               SCH_SHEET_PATH*          aSheetPath )
{
    // Net list item not required for graphic lines.
    if( (GetLayer() != LAYER_BUS) && (GetLayer() != LAYER_WIRE) )
        return;

    NETLIST_OBJECT* item = new NETLIST_OBJECT();
    item->m_SheetList = *aSheetPath;
    item->m_SheetListInclude = *aSheetPath;
    item->m_Comp = (SCH_ITEM*) this;
    item->m_Start = m_Start;
    item->m_End = m_End;

    if( GetLayer() == LAYER_BUS )
    {
        item->m_Type = NET_BUS;
    }
    else            /* WIRE */
    {
        item->m_Type = NET_SEGMENT;
    }

    aNetListItems.push_back( item );
}


bool SCH_LINE::operator <( const SCH_ITEM& aItem ) const
{
    if( Type() != aItem.Type() )
+30 −3
Original line number Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file sch_line.h
 *
 */

#ifndef _SCH_LINE_H_
@@ -117,9 +141,9 @@ public:
     */
    bool MergeOverlap( SCH_LINE* aLine );

    virtual void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList );
    virtual void GetEndPoints( vector <DANGLING_END_ITEM>& aItemList );

    virtual bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList );
    virtual bool IsDanglingStateChanged( vector< DANGLING_END_ITEM >& aItemList );

    virtual bool IsDangling() const { return m_StartIsDangling || m_EndIsDangling; }

@@ -137,6 +161,9 @@ public:

    virtual BITMAP_DEF GetMenuImage() const;

    virtual void GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
                                 SCH_SHEET_PATH*          aSheetPath );

    virtual bool operator <( const SCH_ITEM& aItem ) const;

#if defined(DEBUG)
Loading