kicad/pcbnew/class_track.h

333 lines
9.7 KiB
C
Raw Normal View History

/*******************************************************************/
2007-10-19 06:31:17 +00:00
/* class_track.h: definitions relatives to tracks, vias and zones */
/*******************************************************************/
#ifndef CLASS_TRACK_H
#define CLASS_TRACK_H
#include "base_struct.h"
// Via attributes (m_Shape parmeter)
#define VIA_THROUGH 3 /* Always a through hole via */
#define VIA_BLIND_BURIED 2 /* this via can be on internal layers */
#define VIA_MICROVIA 1 /* this via which connect from an external layer to the near neightbour internal layer */
#define VIA_NOT_DEFINED 0 /* not yet used */
/***/
class TRACK : public BOARD_CONNECTED_ITEM
{
public:
int m_Width; // 0 = line, > 0 = tracks, bus ...
wxPoint m_Start; // Line start point
wxPoint m_End; // Line end point
int m_Shape; // vias: shape and type, Track = shape..
protected:
2008-02-09 08:34:45 +00:00
int m_Drill; // for vias: via drill (- 1 for default value)
public:
BOARD_ITEM* start; // pointers to a connected item (pad or track)
BOARD_ITEM* end;
2007-08-08 20:51:08 +00:00
// chain = 0 indique une connexion non encore traitee
int m_Param; // Auxiliary variable ( used in some computations )
protected:
2007-09-15 04:25:54 +00:00
TRACK( const TRACK& track ); // protected so Copy() is used instead.
2007-08-08 20:51:08 +00:00
public:
TRACK( BOARD_ITEM* StructFather, KICAD_T idtype = TYPETRACK );
2007-09-01 12:00:30 +00:00
/**
* Function Copy
* will copy this object whether it is a TRACK or a SEGVIA returning
* the corresponding type.
* @return - TRACK*, SEGVIA*, or SEGZONE*, declared as the least common
2007-09-15 04:25:54 +00:00
* demoninator: TRACK
2007-09-01 12:00:30 +00:00
*/
TRACK* Copy() const;
2007-08-08 20:51:08 +00:00
TRACK* Next() const { return (TRACK*) Pnext; }
2007-08-08 20:51:08 +00:00
TRACK* Back() const { return (TRACK*) Pback; }
2007-08-08 20:51:08 +00:00
2007-12-01 03:42:52 +00:00
/**
* Function GetPosition
* returns the position of this object.
* @return const wxPoint& - The position of this object.
*/
wxPoint& GetPosition()
{
return m_Start; // it had to be start or end.
}
2008-03-15 04:18:32 +00:00
EDA_Rect GetBoundingBox();
2008-03-05 22:39:33 +00:00
/* Remove "this" from the linked list */
2007-08-30 22:20:52 +00:00
void UnLink();
2007-08-08 20:51:08 +00:00
2007-10-30 21:30:58 +00:00
/**
* Function Save
2007-10-31 14:14:21 +00:00
* writes the data structures for this object out to a FILE in "*.brd" format.
2007-10-30 21:30:58 +00:00
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
2007-09-01 12:00:30 +00:00
/**
* Function Insert
2007-11-02 18:21:43 +00:00
* inserts a single TRACK, SEGVIA or SEGZONE, or a list of such,
* into the proper list within a BOARD, either at the
2007-09-01 12:00:30 +00:00
* list's front or immediately after the InsertPoint.
* If Insertpoint == NULL, then insert at the beginning of the proper list.
* If InsertPoint != NULL, then insert immediately after InsertPoint.
* TRACKs and SEGVIAs are put on the m_Track list, SEGZONE on the m_Zone list.
2007-11-02 18:21:43 +00:00
* @param aPcb The BOARD to insert into.
2007-09-01 12:00:30 +00:00
* @param InsertPoint See above
*/
2007-11-02 18:21:43 +00:00
void Insert( BOARD* aPcb, BOARD_ITEM* InsertPoint );
2007-10-31 06:40:15 +00:00
/**
* Function GetBestInsertPoint
* searches the "best" insertion point within the track linked list.
2007-11-02 18:21:43 +00:00
* The best point is the begging of the corresponding net code section.
* (The BOARD::m_Track and BOARD::m_Zone lists are sorted by netcode.)
* @param aPcb The BOARD to search for the insertion point.
2007-10-31 06:40:15 +00:00
* @return TRACK* - the item found in the linked list (or NULL if no track)
*/
2007-11-02 18:21:43 +00:00
TRACK* GetBestInsertPoint( BOARD* aPcb );
2007-08-08 20:51:08 +00:00
2007-10-19 06:31:17 +00:00
/* Search (within the track linked list) the first segment matching the netcode
* ( the linked list is always sorted by net codes )
*/
2007-08-08 20:51:08 +00:00
TRACK* GetStartNetCode( int NetCode );
2007-10-19 06:31:17 +00:00
/* Search (within the track linked list) the last segment matching the netcode
* ( the linked list is always sorted by net codes )
*/
2007-08-08 20:51:08 +00:00
TRACK* GetEndNetCode( int NetCode );
2007-10-13 06:18:44 +00:00
/**
* Function GetLength
* returns the length of the track using the hypotenuse calculation.
* @return double - the length of the track
*/
2007-12-01 03:42:52 +00:00
double GetLength() const
{
int dx = m_Start.x - m_End.x;
int dy = m_Start.y - m_End.y;
2007-12-01 03:42:52 +00:00
return hypot( dx, dy );
}
2007-08-08 20:51:08 +00:00
/* Display on screen: */
2008-04-01 05:21:50 +00:00
void Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const wxPoint& offset = ZeroOffset );
2007-08-08 20:51:08 +00:00
/* divers */
2007-08-30 22:20:52 +00:00
int Shape() const { return m_Shape & 0xFF; }
2008-02-09 08:34:45 +00:00
/**
* Function SetDrillValue
2008-02-09 08:34:45 +00:00
* Set the drill value for vias
* @param drill_value = new drill value
*/
void SetDrillValue(int drill_value) { m_Drill = drill_value; }
2008-02-09 08:34:45 +00:00
/**
* Function SetDrillDefault
2008-02-09 08:34:45 +00:00
* Set the drill value for vias at default value (-1)
*/
void SetDrillDefault(void) { m_Drill = -1; }
/**
* Function IsDrillDefault
2008-02-09 08:34:45 +00:00
* @return true if the drill value is default value (-1)
*/
bool IsDrillDefault(void) { return m_Drill < 0; }
2008-02-09 08:34:45 +00:00
/**
* Function GetDrillValue
2008-02-09 08:34:45 +00:00
* calculate the drill value for vias (m-Drill if > 0, or default drill value for the board
* @return real drill_value
*/
int GetDrillValue() const;
2007-08-08 20:51:08 +00:00
2007-10-01 13:51:07 +00:00
/**
* Function ReturnMaskLayer
* returns a "layer mask", which is a bitmap of all layers on which the
2007-10-01 13:51:07 +00:00
* TRACK segment or SEGVIA physically resides.
* @return int - a layer mask, see pcbstruct.h's CUIVRE_LAYER, etc.
*/
int ReturnMaskLayer();
int IsPointOnEnds( const wxPoint& point, int min_dist = 0 );
bool IsNull(); // return TRUE if segment lenght = 0
2007-08-08 20:51:08 +00:00
/**
* Function Display_Infos
* has knowledge about the frame and how and where to put status information
* about this object into the frame's message panel.
* Is virtual from EDA_BaseStruct.
2007-08-30 22:20:52 +00:00
* @param frame A WinEDA_DrawFrame in which to print status information.
*/
void Display_Infos( WinEDA_DrawFrame* frame );
2007-10-11 00:11:59 +00:00
/**
* Function ShowWidth
* returns the width of the track in displayable user units.
*/
wxString ShowWidth();
2007-08-30 22:20:52 +00:00
/**
* Function Visit
* is re-implemented here because TRACKs and SEGVIAs are in the same list
* within BOARD. If that were not true, then we could inherit the
* version from EDA_BaseStruct. This one does not iterate through scanTypes
* but only looks at the first item in the list.
2007-08-30 22:20:52 +00:00
* @param inspector An INSPECTOR instance to use in the inspection.
* @param testData Arbitrary data used by the inspector.
* @param scanTypes Which KICAD_T types are of interest and the order
2007-08-30 22:20:52 +00:00
* is significant too, terminated by EOT.
* @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan,
* else SCAN_CONTINUE, and determined by the inspector.
*/
SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData,
const KICAD_T scanTypes[] );
2007-08-08 20:51:08 +00:00
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param refPos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool HitTest( const wxPoint& refPos );
2007-08-08 20:51:08 +00:00
/**
2008-01-06 12:43:57 +00:00
* Function HitTest (overlayed)
* tests if the given wxRect intersect this object.
* For now, an ending point must be inside this rect.
2008-01-06 12:43:57 +00:00
* @param refPos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool HitTest( EDA_Rect& refArea );
2008-01-06 12:43:57 +00:00
/**
2007-08-08 20:51:08 +00:00
* Function GetClass
* returns the class name.
* @return wxString
*/
wxString GetClass() const
{
return wxT( "TRACK" );
2007-08-08 20:51:08 +00:00
}
#if defined (DEBUG)
2007-08-09 01:41:30 +00:00
/**
* Function Show
* is used to output the object tree, currently for debugging only.
* @param nestLevel An aid to prettier tree indenting, and is the level
2007-08-09 01:41:30 +00:00
* of nesting of this object within the overall tree.
* @param os The ostream& to output to.
*/
void Show( int nestLevel, std::ostream& os );
#endif
};
2007-09-01 12:00:30 +00:00
2007-08-08 20:51:08 +00:00
class SEGZONE : public TRACK
{
public:
2007-08-23 04:28:46 +00:00
SEGZONE( BOARD_ITEM* StructFather );
2007-08-08 20:51:08 +00:00
/**
* Function GetClass
* returns the class name.
* @return wxString
*/
wxString GetClass() const
{
return wxT( "ZONE" );
2007-08-08 20:51:08 +00:00
}
SEGZONE* Next() const { return (SEGZONE*) Pnext; }
};
2007-09-01 12:00:30 +00:00
2007-08-08 20:51:08 +00:00
class SEGVIA : public TRACK
{
public:
2007-08-23 04:28:46 +00:00
SEGVIA( BOARD_ITEM* StructFather );
2007-09-01 12:00:30 +00:00
SEGVIA( const SEGVIA& source ) :
TRACK( source )
{
}
2007-08-30 22:20:52 +00:00
/**
* Function IsOnLayer
* tests to see if this object is on the given layer. Is virtual
2007-08-30 22:20:52 +00:00
* from BOARD_ITEM. Tests the starting and ending range of layers for the
* via.
* @param aLayer The layer to test for.
* @return bool - true if on given layer, else false.
*/
bool IsOnLayer( int aLayer ) const;
2007-08-08 20:51:08 +00:00
void SetLayerPair( int top_layer, int bottom_layer );
2007-08-30 22:20:52 +00:00
void ReturnLayerPair( int* top_layer, int* bottom_layer ) const;
2007-12-01 03:42:52 +00:00
/**
* Function GetPosition
* returns the position of this object.
* @return const wxPoint& - The position of this object.
*/
wxPoint& GetPosition()
{
return m_Start;
2007-12-01 03:42:52 +00:00
}
void SetPosition( const wxPoint& aPoint ) { m_Start = aPoint; m_End = aPoint; }
2007-08-08 20:51:08 +00:00
/**
* Function GetClass
* returns the class name.
* @return wxString
*/
wxString GetClass() const
{
return wxT( "VIA" );
2007-08-08 20:51:08 +00:00
}
#if defined (DEBUG)
/**
* Function Show
* is used to output the object tree, currently for debugging only.
* @param nestLevel An aid to prettier tree indenting, and is the level
* of nesting of this object within the overall tree.
* @param os The ostream& to output to.
*/
void Show( int nestLevel, std::ostream& os );
#endif
};
#endif /* CLASS_TRACK_H */