Commit 654e7e55 authored by Maciej Suminski's avatar Maciej Suminski

Removed D_PAD::SetNetname() function and D_PAD::m_Netname, D_PAD::m_ShortNetname fields.

D_PAD::GetNetname() and D_PAD::GetShortNetname() were moved to BOARD_CONNECTED_ITEM. Now they use the net name stored in NETINFO_ITEM.
Moved some one-line functions from class_board_connected_item.cpp to class_board_connected_item.h.
Added a copyright notice, moved Doxygen comments from class_board_connected_item.cpp to class_board_connected_item.h.

I have some doubts if changes introduced pcbnew/dialogs/dialog_pad_properties.cpp do not break anything, but I could not find a test case that breaks the pcbnew.

Performed tests:
- changed pad's net name from empty to existent - ok, name was changed
- changed pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty
- changed pad's net name from existent to empty - ok, net name became empty
- changed pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed
- (re)reading netlists, including net changes - fine, changes are applied, but empty nets are still kept
- loaded pcbnew/pcad2kicadpcb_plugin/examples/CK1202_V1.pcb to test P-CAD import plugin - ok, net names are correct
- imported an Eagle 6.0 board (Arduino Uno; http://arduino.cc/en/uploads/Main/arduino_Uno_Rev3-02-TH.zip) then saved in .kicad_pcb format and reloaded - ok, net names are correct
- saved demos/video/video.kicad_pcb in legacy format and then loaded it again - ok, net names are correct
parent bf80cc77
......@@ -2546,10 +2546,7 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
}
if( !aNetlist.IsDryRun() )
{
pad->SetNetname( wxEmptyString );
pad->SetNet( 0 );
}
}
}
else // Footprint pad has a net.
......@@ -2570,8 +2567,6 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
if( !aNetlist.IsDryRun() )
{
pad->SetNetname( net.GetNetName() );
NETINFO_ITEM* netinfo = FindNet( net.GetNetName() );
if( netinfo == NULL )
{
......@@ -2653,7 +2648,7 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
GetChars( previouspad->GetPadName() ) );
aReporter->Report( msg );
}
previouspad->SetNetname( wxEmptyString );
previouspad->SetNet( 0 );
}
netname = pad->GetNetname();
......@@ -2667,10 +2662,7 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
// Examine last pad
if( pad && count == 1 )
{
pad->SetNetname( wxEmptyString );
pad->SetNet( 0 );
}
}
// Last step: Some tests:
......
/**
* @file class_board_connected_item.cpp
* @brief BOARD_CONNECTED_ITEM class functions.
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
......@@ -28,6 +23,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file class_board_connected_item.cpp
* @brief BOARD_CONNECTED_ITEM class functions.
*/
#include <fctsys.h>
#include <pcbnew.h>
......@@ -36,68 +36,32 @@
BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
BOARD_ITEM( aParent, idtype )
BOARD_ITEM( aParent, idtype ), m_NetCode( 0 ), m_Subnet( 0 ), m_ZoneSubnet( 0 )
{
m_NetCode = 0;
m_Subnet = 0;
m_ZoneSubnet = 0;
}
BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( const BOARD_CONNECTED_ITEM& aItem ) :
BOARD_ITEM( aItem )
{
m_NetCode = aItem.m_NetCode;
m_Subnet = aItem.m_Subnet;
m_ZoneSubnet = aItem.m_ZoneSubnet;
}
/**
* Function GetNet
* @return int - the net code.
*/
int BOARD_CONNECTED_ITEM::GetNet() const
{
return m_NetCode;
}
void BOARD_CONNECTED_ITEM::SetNet( int aNetCode )
BOARD_ITEM( aItem ), m_NetCode( aItem.m_NetCode ), m_Subnet( aItem.m_Subnet ),
m_ZoneSubnet( aItem.m_ZoneSubnet )
{
m_NetCode = aNetCode;
}
/**
* Function GetSubNet
* @return int - the sub net code.
*/
int BOARD_CONNECTED_ITEM::GetSubNet() const
const wxString& BOARD_CONNECTED_ITEM::GetNetname() const
{
return m_Subnet;
}
BOARD* board = GetBoard();
NETINFO_ITEM* netinfo = board->FindNet( m_NetCode );
void BOARD_CONNECTED_ITEM::SetSubNet( int aSubNetCode )
{
m_Subnet = aSubNetCode;
return netinfo->GetNetname();
}
/**
* Function GetZoneSubNet
* @return int - the sub net code in zone connections.
*/
int BOARD_CONNECTED_ITEM::GetZoneSubNet() const
const wxString& BOARD_CONNECTED_ITEM::GetShortNetname() const
{
return m_ZoneSubnet;
}
NETINFO_ITEM* netinfo = GetBoard()->FindNet( m_NetCode );
void BOARD_CONNECTED_ITEM::SetZoneSubNet( int aSubNetCode )
{
m_ZoneSubnet = aSubNetCode;
return netinfo->GetShortNetname();
}
......@@ -132,11 +96,6 @@ int BOARD_CONNECTED_ITEM::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const
}
/** return a pointer to the netclass of the zone
* if the net is not found (can happen when a netlist is reread,
* and the net name is not existant, return the default net class
* So should not return a null pointer
*/
NETCLASS* BOARD_CONNECTED_ITEM::GetNetClass() const
{
// It is important that this be implemented without any sequential searching.
......@@ -176,10 +135,7 @@ NETCLASS* BOARD_CONNECTED_ITEM::GetNetClass() const
return board->m_NetClasses.GetDefault();
}
/**
* Function GetNetClassName
* @return the Net Class name of this item
*/
wxString BOARD_CONNECTED_ITEM::GetNetClassName() const
{
wxString name;
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2012 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 class_board_connected_item.h
* @brief Class BOARD_CONNECTED_ITEM.
......@@ -6,7 +31,6 @@
#ifndef BOARD_CONNECTED_ITEM_H
#define BOARD_CONNECTED_ITEM_H
#include <class_board_item.h>
class NETCLASS;
......@@ -48,22 +72,55 @@ public:
* Function GetNet
* @return int - the net code.
*/
int GetNet() const;
virtual void SetNet( int aNetCode );
int GetNet() const
{
return m_NetCode;
}
virtual void SetNet( int aNetCode )
{
m_NetCode = aNetCode;
}
/**
* Function GetSubNet
* @return int - the sub net code.
*/
int GetSubNet() const;
void SetSubNet( int aSubNetCode );
int GetSubNet() const
{
return m_Subnet;
}
void SetSubNet( int aSubNetCode )
{
m_Subnet = aSubNetCode;
}
/**
* Function GetZoneSubNet
* @return int - the sub net code in zone connections.
*/
int GetZoneSubNet() const;
void SetZoneSubNet( int aSubNetCode );
int GetZoneSubNet() const
{
return m_ZoneSubnet;
}
void SetZoneSubNet( int aSubNetCode )
{
m_ZoneSubnet = aSubNetCode;
}
/**
* Function GetNetname
* @return const wxString& - the full netname
*/
const wxString& GetNetname() const;
/**
* Function GetShortNetname
* @return const wxString& - the short netname
*/
const wxString& GetShortNetname() const;
/**
* Function GetClearance
......@@ -84,6 +141,10 @@ public:
/**
* Function GetNetClassName
* returns a pointer to the netclass of the zone.
* If the net is not found (can happen when a netlist is reread,
* and the net name does not exist, return the default net class
* (should not return a null pointer).
* @return the Net Class name of this item
*/
wxString GetNetClassName() const;
......
......@@ -364,13 +364,6 @@ void D_PAD::SetPadName( const wxString& name )
}
void D_PAD::SetNetname( const wxString& aNetname )
{
m_Netname = aNetname;
m_ShortNetname = m_Netname.AfterLast( '/' );
}
void D_PAD::Copy( D_PAD* source )
{
if( source == NULL )
......@@ -402,8 +395,6 @@ void D_PAD::Copy( D_PAD* source )
SetSubRatsnest( 0 );
SetSubNet( 0 );
m_Netname = source->m_Netname;
m_ShortNetname = source->m_ShortNetname;
}
......@@ -412,7 +403,6 @@ void D_PAD::CopyNetlistSettings( D_PAD* aPad )
// Don't do anything foolish like trying to copy to yourself.
wxCHECK_RET( aPad != NULL && aPad != this, wxT( "Cannot copy to NULL or yourself." ) );
aPad->SetNetname( GetNetname() );
aPad->SetNet( GetNet() );
aPad->SetLocalClearance( m_LocalClearance );
......@@ -578,7 +568,7 @@ void D_PAD::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM>& aList )
aList.push_back( MSG_PANEL_ITEM( _( "Pad" ), Line, BROWN ) );
}
aList.push_back( MSG_PANEL_ITEM( _( "Net" ), m_Netname, DARKCYAN ) );
aList.push_back( MSG_PANEL_ITEM( _( "Net" ), GetNetname(), DARKCYAN ) );
/* For test and debug only: display m_physical_connexion and
* m_logical_connexion */
......
......@@ -118,30 +118,6 @@ public:
return m_NumPadName == other->m_NumPadName; // hide tricks behind sensible API
}
/**
* Function SetNetname
* @param aNetname: the new netname
*/
void SetNetname( const wxString& aNetname );
/**
* Function GetNetname
* @return const wxString& - the full netname
*/
const wxString& GetNetname() const
{
assert( ( GetNet() == 0 ) == m_Netname.IsEmpty() );
// assert( GetBoard()->FindNet( GetNet() ) == GetBoard()->FindNet( m_Netname ) );
return m_Netname;
}
/**
* Function GetShortNetname
* @return const wxString& - the short netname
*/
const wxString& GetShortNetname() const { return m_ShortNetname; }
/**
* Function GetShape
* @return the shape of this pad.
......@@ -475,10 +451,6 @@ private:
int m_boundingRadius; ///< radius of the circle containing the pad shape
wxString m_Netname; ///< Full net name like /mysheet/mysubsheet/vout used by Eeschema
wxString m_ShortNetname; ///< short net name, like vout from /mysheet/mysubsheet/vout
/// Pad name (4 char) or a long identifier (used in pad name
/// comparisons because this is faster than string comparison)
union
......
......@@ -473,7 +473,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
GRSetDrawMode( aDC, aDrawInfo.m_DrawMode );
// Draw "No connect" ( / or \ or cross X ) if necessary
if( m_Netname.IsEmpty() && aDrawInfo.m_ShowNCMark )
if( GetNet() == 0 && aDrawInfo.m_ShowNCMark )
{
int dx0 = std::min( halfsize.x, halfsize.y );
EDA_COLOR_T nc_color = BLUE;
......@@ -499,7 +499,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
wxPoint tpos0 = shape_pos; // Position of the centre of text
wxPoint tpos = tpos0;
wxSize AreaSize; // size of text area, normalized to AreaSize.y < AreaSize.x
int shortname_len = m_ShortNetname.Len();
int shortname_len = GetShortNetname().Len();
if( !aDrawInfo.m_Display_netname )
shortname_len = 0;
......@@ -583,7 +583,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
tsize = ( tsize * 7 ) / 10;
DrawGraphicHaloText( clipBox, aDC, tpos,
aDrawInfo.m_Color, BLACK, WHITE,
m_ShortNetname, t_angle,
GetShortNetname(), t_angle,
wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false );
}
......
......@@ -151,7 +151,8 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, D_PAD* aP
m_parent = aParent;
m_currentPad = aPad;
m_board = m_parent->GetBoard();
m_dummyPad = new D_PAD( (MODULE*) NULL );
m_dummyPad = new D_PAD( aPad->GetParent() );
m_padMaster.SetParent( aPad->GetParent() );
if( aPad )
m_dummyPad->Copy( aPad );
......@@ -809,25 +810,16 @@ void DIALOG_PAD_PROPERTIES::PadPropertiesAccept( wxCommandEvent& event )
m_currentPad->SetPadName( m_padMaster.GetPadName() );
if( m_currentPad->GetNetname() != m_padMaster.GetNetname() )
if( m_currentPad->GetNetname() != m_PadNetNameCtrl->GetValue() )
{
if( m_padMaster.GetNetname().IsEmpty() )
if( !m_PadNetNameCtrl->GetValue().IsEmpty() && m_padMaster.GetNet() == 0 )
{
rastnestIsChanged = true;
m_currentPad->SetNet( 0 );
m_currentPad->SetNetname( wxEmptyString );
DisplayError( NULL, _( "Unknown netname, netname not changed" ) );
}
else
{
const NETINFO_ITEM* net = m_board->FindNet( m_padMaster.GetNetname() );
if( net )
{
rastnestIsChanged = true;
m_currentPad->SetNetname( m_padMaster.GetNetname() );
m_currentPad->SetNet( net->GetNet() );
}
else
DisplayError( NULL, _( "Unknown netname, netname not changed" ) );
rastnestIsChanged = true;
m_currentPad->SetNet( m_padMaster.GetNet() );
}
}
......@@ -986,7 +978,13 @@ bool DIALOG_PAD_PROPERTIES::transferDataToPad( D_PAD* aPad )
msg = m_PadNumCtrl->GetValue().Left( 4 );
aPad->SetPadName( msg );
aPad->SetNetname( m_PadNetNameCtrl->GetValue() );
// Check if user has set an existing net name
const NETINFO_ITEM* netinfo = m_board->FindNet( m_PadNetNameCtrl->GetValue() );
if( netinfo != NULL )
aPad->SetNet( netinfo->GetNet() );
else
aPad->SetNet( 0 );
// Clear some values, according to the pad type and shape
switch( aPad->GetShape() )
......@@ -1034,7 +1032,7 @@ bool DIALOG_PAD_PROPERTIES::transferDataToPad( D_PAD* aPad )
// no offset, no net name, no pad name allowed
aPad->SetOffset( wxPoint( 0, 0 ) );
aPad->SetPadName( wxEmptyString );
aPad->SetNetname( wxEmptyString );
aPad->SetNet( 0 );
break;
default:
......
......@@ -1696,7 +1696,6 @@ void EAGLE_PLUGIN::loadElements( CPTREE& aElements )
if( ni != m_pads_to_nets.end() )
{
const ENET* enet = &ni->second;
pad->SetNetname( FROM_UTF8( enet->netname.c_str() ) );
pad->SetNet( enet->netcode );
}
}
......
......@@ -1303,7 +1303,7 @@ void LEGACY_PLUGIN::loadPAD( MODULE* aModule )
// read Netname
ReadDelimitedText( buf, data, sizeof(buf) );
pad->SetNetname( FROM_UTF8( StrPurge( buf ) ) );
assert( m_board->FindNet( netcode )->GetNetname() == FROM_UTF8( StrPurge( buf ) ) );
}
else if( TESTLINE( "Po" ) ) // (Po)sition
......
......@@ -141,7 +141,6 @@ void PCB_BASE_FRAME::AddPad( MODULE* aModule, bool draw )
// Update the pad properties.
Import_Pad_Settings( pad, false );
pad->SetNetname( wxEmptyString );
pad->SetNet( 0 );
pad->SetPosition( GetCrossHairPosition() );
......
......@@ -914,17 +914,17 @@ void PCB::AddToBoard()
m_board->SetCopperLayerCount( m_layersStackup.GetCount() );
for( i = 0; i < (int) m_pcbComponents.GetCount(); i++ )
{
m_pcbComponents[i]->AddToBoard();
}
for( i = 0; i < (int) m_pcbNetlist.GetCount(); i++ )
{
net = m_pcbNetlist[i];
m_board->AppendNet( new NETINFO_ITEM( m_board, net->m_name, net->m_netCode ) );
}
for( i = 0; i < (int) m_pcbComponents.GetCount(); i++ )
{
m_pcbComponents[i]->AddToBoard();
}
}
} // namespace PCAD2KICAD
......@@ -273,8 +273,16 @@ void PCB_PAD::AddToModule( MODULE* aModule, int aRotation, bool aEncapsulatedPad
pad->SetAttribute( padType );
pad->SetNet( 0 );
pad->SetNetname( m_net );
// Set the proper net code
NETINFO_ITEM* netinfo = m_board->FindNet( m_net );
if( netinfo == NULL ) // I believe this should not happen, but just in case
{
// It is a new net
netinfo = new NETINFO_ITEM( m_board, m_net, m_board->GetNetCount() );
m_board->AppendNet( netinfo );
}
pad->SetNet( netinfo->GetNet() );
}
if( !aEncapsulatedPad )
......
......@@ -2191,7 +2191,7 @@ D_PAD* PCB_PARSER::parseD_PAD() throw( IO_ERROR, PARSE_ERROR )
case T_net:
pad->SetNet( parseInt( "net number" ) );
NeedSYMBOLorNUMBER();
pad->SetNetname( FromUTF8() );
assert( FromUTF8() == m_board->FindNet( pad->GetNet() )->GetNetname() );
NeedRIGHT();
break;
......
......@@ -455,17 +455,13 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
// Update pad netnames ( when possible)
for( D_PAD* pad = aNewModule->Pads(); pad != NULL; pad = pad->Next() )
{
pad->SetNetname( wxEmptyString );
pad->SetNet( 0 );
D_PAD* old_pad = aOldModule->Pads();
for( ; old_pad != NULL; old_pad = old_pad->Next() )
{
if( pad->PadNameEqual( old_pad ) )
{
pad->SetNetname( old_pad->GetNetname() );
pad->SetNet( old_pad->GetNet() );
}
}
}
......
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