2011-09-20 13:57:40 +00:00
|
|
|
/**
|
|
|
|
* @file class_board_item.h
|
|
|
|
* @brief Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
|
|
|
|
*/
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
#ifndef BOARD_ITEM_STRUCT_H
|
|
|
|
#define BOARD_ITEM_STRUCT_H
|
|
|
|
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
#include "base_struct.h"
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
#include <boost/ptr_container/ptr_vector.hpp>
|
2008-11-18 18:13:55 +00:00
|
|
|
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
class BOARD;
|
|
|
|
class EDA_DRAW_PANEL;
|
|
|
|
|
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
/* Shapes for segments (graphic segments and tracks) ( .m_Shape member ) */
|
2008-05-05 19:56:06 +00:00
|
|
|
enum Track_Shapes {
|
2011-08-01 15:29:27 +00:00
|
|
|
S_SEGMENT = 0, /* usual segment : line with rounded ends */
|
|
|
|
S_RECT, /* segment with non rounded ends */
|
|
|
|
S_ARC, /* Arcs (with rounded ends) */
|
|
|
|
S_CIRCLE, /* ring */
|
|
|
|
S_POLYGON, /* polygon (not yet used for tracks, but could be in microwave apps) */
|
|
|
|
S_CURVE, /* Bezier Curve */
|
|
|
|
S_LAST /* last value for this list */
|
2008-05-05 19:56:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
/**
|
|
|
|
* Class BOARD_ITEM
|
|
|
|
* is a base class for any item which can be embedded within the BOARD
|
|
|
|
* container class, and therefore instances of derived classes should only be
|
2011-09-30 18:15:37 +00:00
|
|
|
* found in Pcbnew or other programs that use class BOARD and its contents.
|
|
|
|
* The corresponding class in Eeschema is SCH_ITEM.
|
2008-04-14 19:22:48 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
class BOARD_ITEM : public EDA_ITEM
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2008-12-06 21:20:50 +00:00
|
|
|
// These are made private here so they may not be used.
|
|
|
|
// Instead everything derived from BOARD_ITEM is handled via DLIST<>'s
|
|
|
|
// use of DHEAD's member functions.
|
2010-12-08 20:12:46 +00:00
|
|
|
void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
|
|
|
|
void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
|
2008-12-06 21:20:50 +00:00
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
protected:
|
|
|
|
int m_Layer;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM( aParent, idtype )
|
2008-04-14 19:22:48 +00:00
|
|
|
, m_Layer( 0 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOARD_ITEM( const BOARD_ITEM& src ) :
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM( src.m_Parent, src.Type() )
|
2008-04-14 19:22:48 +00:00
|
|
|
, m_Layer( src.m_Layer )
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
m_Flags = src.m_Flags;
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A value of wxPoint(0,0) which can be passed to the Draw() functions.
|
|
|
|
*/
|
2011-08-01 15:29:27 +00:00
|
|
|
static wxPoint ZeroOffset;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
BOARD_ITEM* Next() const { return (BOARD_ITEM*) Pnext; }
|
|
|
|
BOARD_ITEM* Back() const { return (BOARD_ITEM*) Pback; }
|
|
|
|
BOARD_ITEM* GetParent() const { return (BOARD_ITEM*) m_Parent; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetPosition
|
|
|
|
* returns the position of this object.
|
2011-11-16 17:04:12 +00:00
|
|
|
* @return wxPoint - The position of this object
|
|
|
|
* It seems this function could not return modifiable reference as this
|
|
|
|
* contradict good design practice: as the class could be able
|
|
|
|
* doing internal recalculations on reposition.
|
|
|
|
* @TODO: Check all the GetPosition calls for position assignments.
|
2008-04-14 19:22:48 +00:00
|
|
|
*/
|
2011-11-17 17:47:27 +00:00
|
|
|
virtual const wxPoint GetPosition() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the position of this object.
|
|
|
|
* @param pos The position of this object
|
|
|
|
*/
|
|
|
|
virtual void SetPosition( const wxPoint& pos ) = 0;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetLayer
|
|
|
|
* returns the layer this item is on.
|
|
|
|
*/
|
|
|
|
int GetLayer() const { return m_Layer; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetLayer
|
|
|
|
* sets the layer this item is on.
|
|
|
|
* @param aLayer The layer number.
|
2010-04-23 09:54:40 +00:00
|
|
|
* is virtual because some items (in fact: class DIMENSION)
|
2011-08-01 15:29:27 +00:00
|
|
|
* have a slightly different initialization
|
2008-04-14 19:22:48 +00:00
|
|
|
*/
|
2011-08-01 15:29:27 +00:00
|
|
|
virtual void SetLayer( int aLayer ) { m_Layer = aLayer; }
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Draw
|
|
|
|
* BOARD_ITEMs have their own color information.
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
virtual void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
|
|
|
|
int aDrawMode, const wxPoint& offset = ZeroOffset ) = 0;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function IsOnLayer
|
|
|
|
* tests to see if this object is on the given layer. Is virtual so
|
|
|
|
* objects like D_PAD, which reside on multiple layers can do their own
|
|
|
|
* form of testing.
|
|
|
|
* @param aLayer The layer to test for.
|
|
|
|
* @return bool - true if on given layer, else false.
|
|
|
|
*/
|
|
|
|
virtual bool IsOnLayer( int aLayer ) const
|
|
|
|
{
|
|
|
|
return m_Layer == aLayer;
|
|
|
|
}
|
|
|
|
|
2010-11-24 15:10:33 +00:00
|
|
|
/**
|
|
|
|
* Function IsTrack
|
|
|
|
* tests to see if this object is a track or via (or microvia).
|
|
|
|
* form of testing.
|
|
|
|
* @return bool - true if a track or via, else false.
|
|
|
|
*/
|
2011-08-01 15:29:27 +00:00
|
|
|
bool IsTrack() const
|
2010-11-24 15:10:33 +00:00
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
|
2010-11-24 15:10:33 +00:00
|
|
|
}
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function IsLocked
|
|
|
|
* @return bool - true if the object is locked, else false
|
|
|
|
*/
|
|
|
|
virtual bool IsLocked() const
|
|
|
|
{
|
|
|
|
return false; // only MODULEs can be locked at this time.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function UnLink
|
2008-12-04 04:28:11 +00:00
|
|
|
* detaches this object from its owner. This base class implementation
|
|
|
|
* should work for all derived classes which are held in a DLIST<>.
|
2008-04-14 19:22:48 +00:00
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
virtual void UnLink();
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function DeleteStructure
|
|
|
|
* deletes this object after UnLink()ing it from its owner.
|
|
|
|
*/
|
|
|
|
void DeleteStructure()
|
|
|
|
{
|
|
|
|
UnLink();
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-05 19:56:06 +00:00
|
|
|
/**
|
|
|
|
* Function ShowShape
|
|
|
|
* converts the enum Track_Shapes integer value to a wxString.
|
|
|
|
*/
|
|
|
|
static wxString ShowShape( Track_Shapes aShape );
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
/**
|
|
|
|
* Function Save
|
|
|
|
* writes the data structures for this object out to a FILE in "*.brd" format.
|
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
* @return bool - true if success writing else false.
|
|
|
|
*/
|
2011-08-01 15:29:27 +00:00
|
|
|
virtual bool Save( FILE* aFile ) const = 0;
|
2009-08-01 19:26:05 +00:00
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
// Some geometric transforms, that must be rewritten for derived classes
|
2009-08-01 19:26:05 +00:00
|
|
|
/**
|
|
|
|
* Function Move
|
|
|
|
* move this object.
|
2010-12-14 15:56:30 +00:00
|
|
|
* @param aMoveVector - the move vector for this object.
|
2009-08-01 19:26:05 +00:00
|
|
|
*/
|
2011-08-01 15:29:27 +00:00
|
|
|
virtual void Move( const wxPoint& aMoveVector )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2011-08-01 15:29:27 +00:00
|
|
|
wxMessageBox( wxT( "virtual BOARD_ITEM::Move used, should not occur" ), GetClass() );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2009-08-17 02:59:38 +00:00
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/**
|
|
|
|
* Function Rotate
|
|
|
|
* Rotate this object.
|
2010-12-28 11:24:42 +00:00
|
|
|
* @param aRotCentre - the rotation point.
|
2009-08-01 19:26:05 +00:00
|
|
|
* @param aAngle - the rotation angle in 0.1 degree.
|
|
|
|
*/
|
2011-08-01 15:29:27 +00:00
|
|
|
virtual void Rotate( const wxPoint& aRotCentre, int aAngle )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2011-08-01 15:29:27 +00:00
|
|
|
wxMessageBox( wxT( "virtual BOARD_ITEM::Rotate used, should not occur" ), GetClass() );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2009-08-17 02:59:38 +00:00
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/**
|
|
|
|
* Function Flip
|
|
|
|
* Flip this object, i.e. change the board side for this object
|
2010-12-28 11:24:42 +00:00
|
|
|
* @param aCentre - the rotation point.
|
2009-08-01 19:26:05 +00:00
|
|
|
*/
|
2011-08-01 15:29:27 +00:00
|
|
|
virtual void Flip( const wxPoint& aCentre )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2011-08-01 15:29:27 +00:00
|
|
|
wxMessageBox( wxT( "virtual BOARD_ITEM::Flip used, should not occur" ), GetClass() );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2009-08-17 02:59:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetBoard
|
|
|
|
* returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
|
|
|
|
*/
|
|
|
|
virtual BOARD* GetBoard() const;
|
2011-07-14 15:42:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetLayerName
|
|
|
|
* returns the name of the PCB layer on which the item resides.
|
|
|
|
*
|
|
|
|
* @return wxString containing the layer name associated with this item.
|
|
|
|
*/
|
|
|
|
wxString GetLayerName() const;
|
2008-04-14 19:22:48 +00:00
|
|
|
};
|
|
|
|
|
2011-07-14 15:42:44 +00:00
|
|
|
|
2009-08-17 02:59:38 +00:00
|
|
|
class NETCLASS;
|
2008-11-18 18:13:55 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
/**
|
|
|
|
* Class BOARD_CONNECTED_ITEM
|
|
|
|
* This is a base class derived from BOARD_ITEM for items that can be connected
|
2009-10-21 19:16:25 +00:00
|
|
|
* and have a net, a netname, a clearance ...
|
|
|
|
* mainly: tracks, pads and zones
|
2008-12-04 04:28:11 +00:00
|
|
|
* Handle connection info
|
|
|
|
*/
|
2008-11-24 06:53:43 +00:00
|
|
|
class BOARD_CONNECTED_ITEM : public BOARD_ITEM
|
2008-11-18 18:13:55 +00:00
|
|
|
{
|
|
|
|
protected:
|
2011-08-01 15:29:27 +00:00
|
|
|
int m_NetCode; // Net number
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
int m_Subnet; /* In rastnest routines : for the current net, block number
|
|
|
|
* (number common to the current connected items found)
|
|
|
|
*/
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
int m_ZoneSubnet; // variable used in rastnest computations : for the current net,
|
|
|
|
// handle block number in zone connection
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
public:
|
2008-12-04 04:28:11 +00:00
|
|
|
BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype );
|
2008-11-18 18:13:55 +00:00
|
|
|
BOARD_CONNECTED_ITEM( const BOARD_CONNECTED_ITEM& src );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetNet
|
|
|
|
* @return int - the net code.
|
|
|
|
*/
|
|
|
|
int GetNet() const;
|
2009-10-21 19:16:25 +00:00
|
|
|
virtual void SetNet( int aNetCode );
|
2008-11-18 18:13:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetSubNet
|
|
|
|
* @return int - the sub net code.
|
|
|
|
*/
|
|
|
|
int GetSubNet() const;
|
|
|
|
void SetSubNet( int aSubNetCode );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetZoneSubNet
|
|
|
|
* @return int - the sub net code in zone connections.
|
|
|
|
*/
|
|
|
|
int GetZoneSubNet() const;
|
|
|
|
void SetZoneSubNet( int aSubNetCode );
|
2009-08-17 02:59:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetClearance
|
2009-09-10 15:22:26 +00:00
|
|
|
* returns the clearance in 1/10000 inches. If \a aItem is not NULL then the
|
|
|
|
* returned clearance is the greater of this object's NETCLASS clearance and
|
|
|
|
* aItem's NETCLASS clearance. If \a aItem is NULL, then this objects clearance
|
|
|
|
* is returned.
|
|
|
|
* @param aItem is another BOARD_CONNECTED_ITEM or NULL
|
|
|
|
* @return int - the clearance in 1/10000 inches.
|
2009-08-17 02:59:38 +00:00
|
|
|
*/
|
2009-09-10 15:22:26 +00:00
|
|
|
virtual int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const;
|
2009-08-17 02:59:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetNetClass
|
|
|
|
* returns the NETCLASS for this item.
|
|
|
|
*/
|
2009-09-10 15:22:26 +00:00
|
|
|
NETCLASS* GetNetClass() const;
|
2009-09-27 11:00:21 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function GetNetClassName
|
2009-09-27 11:00:21 +00:00
|
|
|
* @return the Net Class name of this item
|
|
|
|
*/
|
2011-08-01 15:29:27 +00:00
|
|
|
wxString GetNetClassName() const;
|
2008-11-18 18:13:55 +00:00
|
|
|
};
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-10-21 19:16:25 +00:00
|
|
|
/*
|
|
|
|
* class BOARD_ITEM_LIST
|
|
|
|
* Handles a collection of BOARD_ITEM elements
|
2011-08-01 15:29:27 +00:00
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
class BOARD_ITEM_LIST : public BOARD_ITEM
|
|
|
|
{
|
|
|
|
typedef boost::ptr_vector<BOARD_ITEM> ITEM_ARRAY;
|
|
|
|
|
|
|
|
ITEM_ARRAY myItems;
|
|
|
|
|
|
|
|
BOARD_ITEM_LIST( const BOARD_ITEM_LIST& other ) :
|
2011-10-01 19:24:27 +00:00
|
|
|
BOARD_ITEM( NULL, PCB_ITEM_LIST_T )
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
|
|
|
// copy constructor is not supported, is private to cause compiler error
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
BOARD_ITEM_LIST( BOARD_ITEM* aParent = NULL ) :
|
2011-10-01 19:24:27 +00:00
|
|
|
BOARD_ITEM( aParent, PCB_ITEM_LIST_T )
|
2008-12-04 04:28:11 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
//-----< satisfy some virtual functions >------------------------------
|
2011-11-17 17:47:27 +00:00
|
|
|
const wxPoint GetPosition() const
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
2011-11-16 17:04:12 +00:00
|
|
|
return wxPoint(0, 0);
|
2008-12-04 04:28:11 +00:00
|
|
|
}
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void Draw( EDA_DRAW_PANEL* DrawPanel, wxDC* DC,
|
2008-12-04 04:28:11 +00:00
|
|
|
int aDrawMode, const wxPoint& offset = ZeroOffset )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnLink()
|
|
|
|
{
|
|
|
|
/* if it were needed:
|
|
|
|
DHEAD* list = GetList();
|
|
|
|
|
|
|
|
wxASSERT( list );
|
|
|
|
|
|
|
|
list->remove( this );
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Save( FILE* aFile ) const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----</ satisfy some virtual functions >-----------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetCount
|
|
|
|
* returns the number of BOARD_ITEMs.
|
|
|
|
*/
|
|
|
|
int GetCount() const
|
|
|
|
{
|
|
|
|
return myItems.size();
|
|
|
|
}
|
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
void Append( BOARD_ITEM* aItem )
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
|
|
|
myItems.push_back( aItem );
|
|
|
|
}
|
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
BOARD_ITEM* Replace( int aIndex, BOARD_ITEM* aItem )
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
|
|
|
ITEM_ARRAY::auto_type ret = myItems.replace( aIndex, aItem );
|
|
|
|
return ret.release();
|
|
|
|
}
|
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
BOARD_ITEM* Remove( int aIndex )
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
|
|
|
ITEM_ARRAY::auto_type ret = myItems.release( myItems.begin()+aIndex );
|
|
|
|
return ret.release();
|
|
|
|
}
|
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
void Insert( int aIndex, BOARD_ITEM* aItem )
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
|
|
|
myItems.insert( myItems.begin()+aIndex, aItem );
|
|
|
|
}
|
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
BOARD_ITEM* At( int aIndex ) const
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
|
|
|
// we have varying sized objects and are using polymorphism, so we
|
|
|
|
// must return a pointer not a reference.
|
|
|
|
return (BOARD_ITEM*) &myItems[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
BOARD_ITEM* operator[]( int aIndex ) const
|
|
|
|
{
|
|
|
|
return At( aIndex );
|
|
|
|
}
|
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
void Delete( int aIndex )
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
|
|
|
myItems.erase( myItems.begin()+aIndex );
|
|
|
|
}
|
|
|
|
|
|
|
|
void PushBack( BOARD_ITEM* aItem )
|
|
|
|
{
|
|
|
|
Append( aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
BOARD_ITEM* PopBack()
|
|
|
|
{
|
|
|
|
if( GetCount() )
|
|
|
|
return Remove( GetCount()-1 );
|
2011-08-01 15:29:27 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
#endif /* BOARD_ITEM_STRUCT_H */
|