kicad/include/netclass.h

305 lines
8.7 KiB
C
Raw Normal View History

/**
* @file class_netclass.h
*/
2009-08-17 02:59:38 +00:00
/*
* This program source code file is part of KiCad, a free EDA CAD application.
2009-08-17 02:59:38 +00:00
*
* Copyright (C) 2009 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@inpg.fr
* Copyright (C) 2009 KiCad Developers, see change_log.txt for contributors.
2009-08-17 02:59:38 +00:00
*
* 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
*/
#ifndef CLASS_NETCLASS_H
#define CLASS_NETCLASS_H
#include <macros.h>
#include <set>
#include <memory>
#include <richio.h>
class LINE_READER;
class BOARD;
class BOARD_DESIGN_SETTINGS;
DECL_SET_FOR_SWIG( STRINGSET, wxString )
/**
* NETCLASS
2009-08-17 02:59:38 +00:00
* handles a collection of nets and the parameters used to route or
* test these nets.
*/
2009-08-17 02:59:38 +00:00
class NETCLASS
{
2009-08-17 02:59:38 +00:00
protected:
wxString m_Name; ///< Name of the net class
wxString m_Description; ///< what this NETCLASS is for.
2009-08-17 02:59:38 +00:00
STRINGSET m_Members; ///< names of NET members of this class
/// The units on these parameters is Internal Units (1 nm)
int m_Clearance; ///< clearance when routing
int m_TrackWidth; ///< track width used to route NETs in this NETCLASS
int m_ViaDia; ///< via diameter
int m_ViaDrill; ///< via drill hole diameter
2009-09-10 15:22:26 +00:00
int m_uViaDia; ///< microvia diameter
int m_uViaDrill; ///< microvia drill hole diameter
2009-09-10 15:22:26 +00:00
int m_diffPairWidth;
int m_diffPairGap;
int m_diffPairViaGap;
public:
static const char Default[]; ///< the name of the default NETCLASS
2009-09-10 15:22:26 +00:00
/**
* Constructor
* stuffs a NETCLASS instance with aParent, aName, and optionally the initialParameters
2010-12-29 17:47:32 +00:00
* @param aName = the name of this new netclass
2009-09-10 15:22:26 +00:00
*/
NETCLASS( const wxString& aName );
2009-09-10 15:22:26 +00:00
~NETCLASS();
2009-08-17 02:59:38 +00:00
wxString GetClass() const
{
return wxT( "NETCLASS" );
}
const wxString& GetName() const
{
return m_Name;
}
2011-11-30 07:43:46 +00:00
void SetName( const wxString& aName ) { m_Name = aName; }
/**
2009-08-17 02:59:38 +00:00
* Function GetCount
* returns the number of nets in this NETCLASS, i.e. using these rules.
*/
2009-08-17 02:59:38 +00:00
unsigned GetCount() const
{
2009-08-17 02:59:38 +00:00
return m_Members.size();
}
2009-08-17 02:59:38 +00:00
/**
* Function Clear
* empties the collection of members.
*/
void Clear()
{
2009-08-17 02:59:38 +00:00
m_Members.clear();
}
2009-08-17 02:59:38 +00:00
/**
* Function Add
2009-08-17 02:59:38 +00:00
* adds \a aNetname to this NETCLASS if it is not already in this NETCLASS.
* It is harmless to try and add a second identical name.
*/
void Add( const wxString& aNetname )
{
2009-08-17 02:59:38 +00:00
m_Members.insert( aNetname );
}
2009-08-17 02:59:38 +00:00
typedef STRINGSET::iterator iterator;
iterator begin() { return m_Members.begin(); }
iterator end() { return m_Members.end(); }
2009-08-17 02:59:38 +00:00
typedef STRINGSET::const_iterator const_iterator;
const_iterator begin() const { return m_Members.begin(); }
const_iterator end() const { return m_Members.end(); }
/**
* Function Remove
* will remove NET name \a aName from the collection of members.
*/
void Remove( iterator aName )
{
m_Members.erase( aName );
}
/**
* Function Remove
* will remove NET name \a aName from the collection of members.
*/
void Remove( const wxString& aName )
{
2009-08-17 02:59:38 +00:00
m_Members.erase( aName );
}
STRINGSET& NetNames() { return m_Members; } ///< for SWIG
2009-08-17 02:59:38 +00:00
const wxString& GetDescription() const { return m_Description; }
void SetDescription( const wxString& aDesc ) { m_Description = aDesc; }
int GetClearance( wxString* aSource = nullptr ) const
{
if( aSource )
*aSource = wxString::Format( _( "'%s' netclass" ), m_Name );
return m_Clearance;
}
2009-08-17 02:59:38 +00:00
void SetClearance( int aClearance ) { m_Clearance = aClearance; }
2009-09-10 15:22:26 +00:00
int GetTrackWidth() const { return m_TrackWidth; }
void SetTrackWidth( int aWidth ) { m_TrackWidth = aWidth; }
int GetViaDiameter() const { return m_ViaDia; }
void SetViaDiameter( int aDia ) { m_ViaDia = aDia; }
2009-08-17 02:59:38 +00:00
int GetViaDrill() const { return m_ViaDrill; }
void SetViaDrill( int aSize ) { m_ViaDrill = aSize; }
2009-08-17 02:59:38 +00:00
int GetuViaDiameter() const { return m_uViaDia; }
void SetuViaDiameter( int aSize ) { m_uViaDia = aSize; }
2009-08-17 02:59:38 +00:00
int GetuViaDrill() const { return m_uViaDrill; }
void SetuViaDrill( int aSize ) { m_uViaDrill = aSize; }
int GetDiffPairWidth() const { return m_diffPairWidth; }
void SetDiffPairWidth( int aSize ) { m_diffPairWidth = aSize; }
int GetDiffPairGap() const { return m_diffPairGap; }
void SetDiffPairGap( int aSize ) { m_diffPairGap = aSize; }
int GetDiffPairViaGap() const { return m_diffPairViaGap; }
void SetDiffPairViaGap( int aSize ) { m_diffPairViaGap = aSize; }
2009-09-10 15:22:26 +00:00
/**
* Function SetParams
* will set all the parameters by copying them from \a defaults.
* Parameters are the values like m_ViaSize, etc, but do not include m_Description.
* @param aDefaults is another NETCLASS object to copy from.
*/
void SetParams( const NETCLASS& aDefaults );
2009-08-17 02:59:38 +00:00
#if defined(DEBUG)
2017-02-23 19:57:20 +00:00
void Show( int nestLevel, std::ostream& os ) const;
2009-08-17 02:59:38 +00:00
#endif
};
DECL_SPTR_FOR_SWIG( NETCLASSPTR, NETCLASS )
2017-11-02 20:41:29 +00:00
DECL_MAP_FOR_SWIG( NETCLASS_MAP, wxString, NETCLASSPTR )
/**
* NETCLASSES
* is a container for NETCLASS instances. It owns all its NETCLASSes
2009-08-17 02:59:38 +00:00
* (=> it will delete them at time of destruction). This container will always have
* a default NETCLASS with the name given by const NETCLASS::Default.
*/
2009-08-17 02:59:38 +00:00
class NETCLASSES
{
2009-08-17 02:59:38 +00:00
private:
/// all the NETCLASSes except the default one.
NETCLASS_MAP m_NetClasses;
/// the default NETCLASS
NETCLASSPTR m_default;
public:
NETCLASSES();
2009-08-17 02:59:38 +00:00
~NETCLASSES();
2009-08-17 02:59:38 +00:00
/**
* Function Clear
* destroys any contained NETCLASS instances except the Default one.
2009-08-17 02:59:38 +00:00
*/
void Clear()
{
m_NetClasses.clear();
}
2009-08-17 02:59:38 +00:00
typedef NETCLASS_MAP::iterator iterator;
2009-08-17 02:59:38 +00:00
iterator begin() { return m_NetClasses.begin(); }
iterator end() { return m_NetClasses.end(); }
typedef NETCLASS_MAP::const_iterator const_iterator;
2009-08-17 02:59:38 +00:00
const_iterator begin() const { return m_NetClasses.begin(); }
const_iterator end() const { return m_NetClasses.end(); }
/**
2009-08-17 02:59:38 +00:00
* Function GetCount
* @return the number of netclasses, excluding the default one.
*/
2009-08-17 02:59:38 +00:00
unsigned GetCount() const
{
2009-08-17 02:59:38 +00:00
return m_NetClasses.size();
}
/**
* Function GetDefault
* @return the default net class.
*/
NETCLASSPTR GetDefault() const
{
return m_default;
}
2020-05-18 00:20:16 +00:00
NETCLASS* GetDefaultPtr() const
{
return m_default.get();
}
2009-08-17 02:59:38 +00:00
/**
* Function Add
* takes \a aNetclass and puts it into this NETCLASSES container.
2009-08-17 02:59:38 +00:00
* @param aNetclass is netclass to add
2009-09-10 15:22:26 +00:00
* @return true if the name within aNetclass is unique and it could be inserted OK,
* else false because the name was not unique.
2009-08-17 02:59:38 +00:00
*/
bool Add( const NETCLASSPTR& aNetclass );
2009-08-17 02:59:38 +00:00
/**
* Function Remove
* removes a NETCLASS from this container but does not destroy/delete it.
* @param aNetName is the name of the net to delete, and it may not be NETCLASS::Default.
* @return NETCLASSPTR - the NETCLASS associated with aNetName if found and removed, else NULL.
2009-08-17 02:59:38 +00:00
*/
NETCLASSPTR Remove( const wxString& aNetName );
2009-08-17 02:59:38 +00:00
/**
* Function Find
* searches this container for a NETCLASS given by \a aName.
* @param aName is the name of the NETCLASS to search for.
* @return NETCLASSPTR - if found, else NULL.
*/
NETCLASSPTR Find( const wxString& aName ) const;
/// Provide public access to m_NetClasses so it gets swigged.
NETCLASS_MAP& NetClasses() { return m_NetClasses; }
};
#endif // CLASS_NETCLASS_H