Commit 4e55b6be authored by Wayne Stambaugh's avatar Wayne Stambaugh

More Eeschema net list object generation improvements.

* Add net list object creation functions to schematic sheet and label
  objects.
* Remove function to add schematic object net list items as it is no
  longer needed.
* Add license statements to all modified files that required one.
parent 31a4334a
......@@ -3,7 +3,7 @@
*
* 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.
* 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
......@@ -53,9 +53,6 @@ NETLIST_OBJECT_LIST g_NetObjectslist;
static void PropageNetCode( int OldNetCode, int NewNetCode, int IsBus );
static void SheetLabelConnect( NETLIST_OBJECT* SheetLabel );
static void AddConnectedObjects( SCH_SHEET_PATH* sheetlist,
NETLIST_OBJECT_LIST& aNetItemBuffer );
static void ConvertBusToMembers( NETLIST_OBJECT_LIST& aNetItemBuffer, NETLIST_OBJECT& ObjNet );
static void PointToPointConnect( NETLIST_OBJECT* Ref, int IsBus, int start );
static void SegmentToPointConnect( NETLIST_OBJECT* Jonction, int IsBus, int start );
static void LabelConnect( NETLIST_OBJECT* Label );
......@@ -122,7 +119,12 @@ void SCH_EDIT_FRAME::BuildNetListBase()
/* Fill g_NetObjectslist with items used in connectivity calculation */
for( sheet = sheets.GetFirst(); sheet != NULL; sheet = sheets.GetNext() )
AddConnectedObjects( sheet, g_NetObjectslist );
{
for( SCH_ITEM* item = sheet->LastScreen()->GetDrawItems(); item; item = item->Next() )
{
item->GetNetListItem( g_NetObjectslist, sheet );
}
}
if( g_NetObjectslist.size() == 0 )
return; // no objects
......@@ -396,6 +398,7 @@ void FindBestNetNameForEachNet( NETLIST_OBJECT_LIST& aNetItemBuffer )
}
}
/**
* Function FindBestNetName
* @return a reference to the "best" label that can be used to give a name
......@@ -537,105 +540,87 @@ static void SheetLabelConnect( NETLIST_OBJECT* SheetLabel )
/**
* Function AddConnectedObjects
* Creates the list of objects related to connections (pins of components,
* wires, labels, junctions ...)
* Function ConvertBusToMembers
* breaks the text of a bus label type in as many members as it contains and
* creates a #NETLIST_OBJECT for each label.
*
* @param sheetlist: pointer to a sheetlist.
* @param aNetItemBuffer: a std::vector to store pointer on NETLIST_OBJECT
* created
* @param aNetListItems A reference to vector of #NETLIST_OBJECT pointers to add
* the bus label NETLIST_OBJECTs.
* @param aBusLabel A reference to the base bus label #NETLIST_OBJECT.
*/
static void AddConnectedObjects( SCH_SHEET_PATH* sheetlist,
std::vector<NETLIST_OBJECT*>& aNetItemBuffer )
void ConvertBusToMembers( NETLIST_OBJECT_LIST& aNetListItems, NETLIST_OBJECT& aBusLabel )
{
SCH_ITEM* item;
NETLIST_OBJECT* new_item;
SCH_SHEET_PATH list;
wxCHECK_RET( IsBusLabel( aBusLabel.m_Label ),
wxT( "<" ) + aBusLabel.m_Label + wxT( "> is not a valid bus label." ) );
item = sheetlist->LastScreen()->GetDrawItems();
if( aBusLabel.m_Type == NET_HIERLABEL )
aBusLabel.m_Type = NET_HIERBUSLABELMEMBER;
else if( aBusLabel.m_Type == NET_GLOBLABEL )
aBusLabel.m_Type = NET_GLOBBUSLABELMEMBER;
else if( aBusLabel.m_Type == NET_SHEETLABEL )
aBusLabel.m_Type = NET_SHEETBUSLABELMEMBER;
else if( aBusLabel.m_Type == NET_LABEL )
aBusLabel.m_Type = NET_BUSLABELMEMBER;
else
wxCHECK_RET( false, wxT( "Net object type is not valid." ) );
unsigned i;
wxString tmp, busName;
long begin, end, member;
for( ; item; item = item->Next() )
/* Search for '[' because a bus label is like "busname[nn..mm]" */
i = aBusLabel.m_Label.Find( '[' );
busName = aBusLabel.m_Label.Left( i );
i++;
while( aBusLabel.m_Label[i] != '.' && i < aBusLabel.m_Label.Len() )
{
switch( item->Type() )
{
case SCH_POLYLINE_T:
case SCH_BUS_ENTRY_T:
case SCH_MARKER_T:
case SCH_TEXT_T:
case SCH_LINE_T:
case SCH_JUNCTION_T:
case SCH_NO_CONNECT_T:
case SCH_COMPONENT_T:
item->GetNetListItem( aNetItemBuffer, sheetlist );
break;
tmp.Append( aBusLabel.m_Label[i] );
i++;
}
case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T:
case SCH_HIERARCHICAL_LABEL_T:
#undef STRUCT
#define STRUCT ( (SCH_LABEL*) item )
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;
tmp.ToLong( &begin );
// this is not the simplest way of doing it
// (look at the case statement above).
if( STRUCT->GetLayer() == LAYER_GLOBLABEL )
new_item->m_Type = NET_GLOBLABEL;
while( aBusLabel.m_Label[i] == '.' && i < aBusLabel.m_Label.Len() )
i++;
tmp.Empty();
if( STRUCT->GetLayer() == LAYER_HIERLABEL )
new_item->m_Type = NET_HIERLABEL;
while( aBusLabel.m_Label[i] != ']' && i < aBusLabel.m_Label.Len() )
{
tmp.Append( aBusLabel.m_Label[i] );
i++;
}
new_item->m_Label = STRUCT->m_Text;
new_item->m_Start = new_item->m_End = STRUCT->m_Pos;
aNetItemBuffer.push_back( new_item );
tmp.ToLong( &end );
/* If a bus connects to label */
if( IsBusLabel( STRUCT->m_Text ) )
ConvertBusToMembers( aNetItemBuffer, *new_item );
if( begin < 0 )
begin = 0;
if( end < 0 )
end = 0;
break;
if( begin > end )
EXCHG( begin, end );
case SCH_SHEET_T:
{
#undef STRUCT
#define STRUCT ( (SCH_SHEET*) item )
list = *sheetlist;
list.Push( STRUCT );
SCH_SHEET* sheet = (SCH_SHEET*) item;
member = begin;
tmp = busName;
tmp << member;
aBusLabel.m_Label = tmp;
aBusLabel.m_Member = member;
BOOST_FOREACH( SCH_SHEET_PIN pin, sheet->GetPins() )
{
new_item = new NETLIST_OBJECT();
new_item->m_SheetList = *sheetlist;
new_item->m_SheetListInclude = list;
new_item->m_Comp = &pin;
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_Start = new_item->m_End = pin.m_Pos;
aNetItemBuffer.push_back( new_item );
if( IsBusLabel( pin.m_Text ) )
ConvertBusToMembers( aNetItemBuffer, *new_item );
}
for( member++; member <= end; member++ )
{
NETLIST_OBJECT* item = new NETLIST_OBJECT( aBusLabel );
break;
}
/* Conversion of BusLabel to the root name + the current member id.*/
tmp = busName;
tmp << member;
item->m_Label = tmp;
item->m_Member = member;
case SCH_SHEET_PIN_T:
default:
{
wxString msg;
msg.Printf( wxT( "Netlist: unexpected struct type %d" ), item->Type() );
wxMessageBox( msg );
break;
}
}
aNetListItems.push_back( item );
}
}
......@@ -694,94 +679,6 @@ bool IsBusLabel( const wxString& aLabel )
}
/*
* Routine which breaks a seal Bus type Label in as many members it contains,
* And creates structures with type NET_GLOBBUSLABELMEMBER, NET_BUSLABELMEMBER
* Or NET_SHEETBUSLABELMEMBER
* Entry = pointer to NETLIST_OBJECT initializes the corresp buslabel
* Assumes that FirstNumWireBus, LastNumWireBus and RootBusNameLength are up
* to date
* Amends NETLIST_OBJECT base and meets the following
* M_Label is a pointer to a new wxString
* M_Label must be deallocated by the user (only for a NET_GLOBBUSLABELMEMBER,
* NET_BUSLABELMEMBER gold NET_SHEETBUSLABELMEMBER object type)
*/
static void ConvertBusToMembers( NETLIST_OBJECT_LIST& aNetItemBuffer,
NETLIST_OBJECT& aBusLabel )
{
wxCHECK_RET( IsBusLabel( aBusLabel.m_Label ),
wxT( "<" ) + aBusLabel.m_Label + wxT( "> is not a valid bus label." ) );
if( aBusLabel.m_Type == NET_HIERLABEL )
aBusLabel.m_Type = NET_HIERBUSLABELMEMBER;
else if( aBusLabel.m_Type == NET_GLOBLABEL )
aBusLabel.m_Type = NET_GLOBBUSLABELMEMBER;
else if( aBusLabel.m_Type == NET_SHEETLABEL )
aBusLabel.m_Type = NET_SHEETBUSLABELMEMBER;
else
aBusLabel.m_Type = NET_BUSLABELMEMBER;
unsigned i;
wxString tmp, busName;
long begin, end, member;
/* Search for '[' because a bus label is like "busname[nn..mm]" */
i = aBusLabel.m_Label.Find( '[' );
busName = aBusLabel.m_Label.Left( i );
i++;
while( aBusLabel.m_Label[i] != '.' && i < aBusLabel.m_Label.Len() )
{
tmp.Append( aBusLabel.m_Label[i] );
i++;
}
tmp.ToLong( &begin );
while( aBusLabel.m_Label[i] == '.' && i < aBusLabel.m_Label.Len() )
i++;
tmp.Empty();
while( aBusLabel.m_Label[i] != ']' && i < aBusLabel.m_Label.Len() )
{
tmp.Append( aBusLabel.m_Label[i] );
i++;
}
tmp.ToLong( &end );
if( begin < 0 )
begin = 0;
if( end < 0 )
end = 0;
if( begin > end )
EXCHG( begin, end );
member = begin;
tmp = busName;
tmp << member;
aBusLabel.m_Label = tmp;
aBusLabel.m_Member = member;
for( member++; member <= end; member++ )
{
NETLIST_OBJECT* item = new NETLIST_OBJECT( aBusLabel );
/* Conversion of BusLabel to the root name + the current member id.*/
tmp = busName;
tmp << member;
item->m_Label = tmp;
item->m_Member = member;
aNetItemBuffer.push_back( item );
}
}
/*
* PropageNetCode propagates Netcode NewNetCode on all elements
* belonging to the former Netcode OldNetCode
......
......@@ -61,6 +61,13 @@ EDA_Colors ReturnLayerColor( int Layer );
/***************/
/* NETLIST.CPP */
/***************/
/**
* Function IsBusLabel
* test if the \a aLabel has a bus notation.
*
* @param aLabel A wxString object containing the label to test.
* @return false if text is not a bus notattion otherwise true is returned.
*/
bool IsBusLabel( const wxString& aLabel );
......
......@@ -37,13 +37,17 @@
#include "richio.h"
#include "wxEeschemaStruct.h"
#include "plot_common.h"
#include "kicad_string.h"
#include "general.h"
#include "protos.h"
#include "sch_sheet.h"
#include "sch_sheet_path.h"
#include "sch_component.h"
#include "kicad_string.h"
#include "class_netlist_object.h"
extern void ConvertBusToMembers( NETLIST_OBJECT_LIST& aNetItemBuffer, NETLIST_OBJECT& aBusLabel );
SCH_SHEET::SCH_SHEET( const wxPoint& pos ) :
......@@ -1094,6 +1098,31 @@ wxPoint SCH_SHEET::GetResizePosition() const
}
void SCH_SHEET::GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
SCH_SHEET_PATH* aSheetPath )
{
SCH_SHEET_PATH sheetPath = *aSheetPath;
sheetPath.Push( this );
for( size_t i = 0; i < m_pins.size(); i++ )
{
NETLIST_OBJECT* item = new NETLIST_OBJECT();
item->m_SheetListInclude = sheetPath;
item->m_SheetList = *aSheetPath;
item->m_Comp = &m_pins[i];
item->m_Link = this;
item->m_Type = NET_SHEETLABEL;
item->m_ElectricalType = m_pins[i].m_Shape;
item->m_Label = m_pins[i].m_Text;
item->m_Start = item->m_End = m_pins[i].m_Pos;
aNetListItems.push_back( item );
if( IsBusLabel( m_pins[i].m_Text ) )
ConvertBusToMembers( aNetListItems, *item );
}
}
void SCH_SHEET::doPlot( PLOTTER* aPlotter )
{
EDA_Colors txtcolor = UNSPECIFIED_COLOR;
......
/*
* 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_sheet.h
* @brief Definition of the SCH_SHEET class for Eeschema.
......@@ -565,6 +590,9 @@ public:
virtual BITMAP_DEF GetMenuImage() const { return add_hierarchical_subsheet_xpm; }
virtual void GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
SCH_SHEET_PATH* aSheetPath );
#if defined(DEBUG)
// comment inherited by Doxygen from Base_Struct
......
/*
* 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_text.cpp
* @brief Code for handling schematic sheet labels.
......@@ -16,16 +41,12 @@
#include "general.h"
#include "protos.h"
#include "sch_text.h"
#include "class_netlist_object.h"
extern void IncrementLabelMember( wxString& name );
extern void IncrementLabelMember( wxString& name );
extern void ConvertBusToMembers( NETLIST_OBJECT_LIST& aNetItemBuffer, NETLIST_OBJECT& aBusLabel );
/************************/
/* class SCH_TEXT */
/* class SCH_LABEL */
/* class SCH_GLOBALLABEL */
/* class SCH_HIERLABEL */
/************************/
/* Names of sheet label types. */
const char* SheetLabelType[] =
......@@ -150,8 +171,10 @@ bool SCH_TEXT::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint
if( SCH_ITEM::Matches( m_Text, aSearchData ) )
{
EDA_RECT BoundaryBox = GetBoundingBox();
if( aFindLocation )
*aFindLocation = BoundaryBox.Centre();
return true;
}
......@@ -337,7 +360,7 @@ void SCH_TEXT::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
SCH_ITEM* undoItem = frame->GetUndoItem();
wxCHECK_RET( undoItem != NULL && undoItem->Type() == Type(),
wxT( "Invalid text undo item." ) );
wxT( "Invalid text undo item." ) );
undoItem->ClearFlags();
picker.SetLink( undoItem );
......@@ -345,7 +368,7 @@ void SCH_TEXT::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
frame->SetUndoItem( NULL );
pickList.PushItem( picker );
frame->SaveCopyInUndoList( pickList, UR_CHANGED); //UR_EXCHANGE_T );
frame->SaveCopyInUndoList( pickList, UR_CHANGED ); //UR_EXCHANGE_T );
}
SCH_ITEM::Place( frame, DC );
......@@ -389,6 +412,7 @@ void SCH_TEXT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& aOffset,
EXCHG( linewidth, m_Thickness ); // Set the minimum width
EDA_TEXT::Draw( panel, DC, text_offset, color, DrawMode, FILLED, UNSPECIFIED_COLOR );
EXCHG( linewidth, m_Thickness ); // set initial value
if( m_IsDangling )
DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color );
......@@ -648,6 +672,34 @@ wxString SCH_TEXT::GetSelectMenuText() const
}
void SCH_TEXT::GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
SCH_SHEET_PATH* aSheetPath )
{
if( GetLayer() == LAYER_NOTES || GetLayer() == LAYER_SHEETLABEL )
return;
NETLIST_OBJECT* item = new NETLIST_OBJECT();
item->m_SheetList = *aSheetPath;
item->m_SheetListInclude = *aSheetPath;
item->m_Comp = (SCH_ITEM*) this;
item->m_Type = NET_LABEL;
if( GetLayer() == LAYER_GLOBLABEL )
item->m_Type = NET_GLOBLABEL;
else if( GetLayer() == LAYER_HIERLABEL )
item->m_Type = NET_HIERLABEL;
item->m_Label = m_Text;
item->m_Start = item->m_End = m_Pos;
aNetListItems.push_back( item );
/* If a bus connects to label */
if( IsBusLabel( m_Text ) )
ConvertBusToMembers( aNetListItems, *item );
}
bool SCH_TEXT::doHitTest( const wxPoint& aPoint, int aAccuracy ) const
{
return TextHitTest( aPoint, aAccuracy );
......@@ -1416,6 +1468,7 @@ bool SCH_HIERLABEL::Load( LINE_READER& aLine, wxString& aErrorMsg )
Name1[0] = 0; Name2[0] = 0; Name3[0] = 0;
char* sline = (char*) aLine;
while( (*sline != ' ' ) && *sline )
sline++;
......
/*
* 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_text.h
* @brief Definitions of the SCH_TEXT class and derivatives for Eeschema.
......@@ -205,6 +230,9 @@ public:
virtual BITMAP_DEF GetMenuImage() const { return add_text_xpm; }
virtual void GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
SCH_SHEET_PATH* aSheetPath );
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os );
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment