kicad/pcbnew/class_track.cpp

1068 lines
27 KiB
C++
Raw Normal View History

2007-10-19 06:31:17 +00:00
/*******************************************************************/
/* Functions relatives to tracks, vias and zones(see class_track.h */
/*******************************************************************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "pcbnew.h"
#ifdef CVPCB
#include "cvpcb.h"
#endif
2007-08-08 20:51:08 +00:00
#include "trigo.h"
#include "protos.h"
// #define RATSNET_DEBUG
#ifdef RATSNET_DEBUG
/**************************************/
2007-10-19 06:31:17 +00:00
void DbgDisplayTrackInfos( TRACK* track )
/**************************************/
2007-10-19 06:31:17 +00:00
/* Only for ratsnest debug
2007-10-19 06:31:17 +00:00
*/
{
2007-10-19 06:31:17 +00:00
wxString msg;
2007-10-19 06:31:17 +00:00
msg << wxT( "Netcode " ) << track->GetNet();
msg << wxT( " - " ) << track->GetSubNet();
msg << wxT( "\nptrS " ) << (unsigned) track->start;
msg << wxT( " ptrE " ) << (unsigned) track->end;
msg << wxT( " this " ) << (unsigned) track;
2007-10-19 06:31:17 +00:00
wxMessageBox( msg );
}
2007-10-19 06:31:17 +00:00
#endif
/**
* Function ShowClearance
* tests to see if the clearance border is drawn on the given track.
* @return bool - true if should draw clearance, else false.
*/
static bool ShowClearance( const TRACK* aTrack )
{
// maybe return true for tracks and vias, not for zone segments
return !(aTrack->m_Flags & DRAW_ERASED)
&& DisplayOpt.DisplayTrackIsol
&& aTrack->GetLayer() <= LAST_COPPER_LAYER
&& ( aTrack->Type() == TYPE_TRACK || aTrack->Type() == TYPE_VIA );
}
2007-10-19 06:31:17 +00:00
/**********************************************************/
TRACK::TRACK( BOARD_ITEM* aParent, KICAD_T idtype ) :
BOARD_CONNECTED_ITEM( aParent, idtype )
2007-10-19 06:31:17 +00:00
/**********************************************************/
{
2007-10-19 06:31:17 +00:00
m_Width = 0;
m_Shape = S_SEGMENT;
start = end = NULL;
SetDrillDefault();
2007-10-19 06:31:17 +00:00
m_Param = 0;
}
2007-08-08 20:51:08 +00:00
2007-10-19 06:31:17 +00:00
/***************************/
2007-10-11 00:11:59 +00:00
wxString TRACK::ShowWidth()
2007-10-19 06:31:17 +00:00
/***************************/
2007-10-11 00:11:59 +00:00
{
wxString msg;
2008-02-09 08:34:45 +00:00
2007-10-11 00:11:59 +00:00
valeur_param( m_Width, msg );
return msg;
}
2007-08-09 01:41:30 +00:00
SEGZONE::SEGZONE( BOARD_ITEM* aParent ) :
TRACK( aParent, TYPE_ZONE )
{
}
2007-08-08 20:51:08 +00:00
SEGVIA::SEGVIA( BOARD_ITEM* aParent ) :
TRACK( aParent, TYPE_VIA )
{
}
2007-08-08 20:51:08 +00:00
2007-09-01 12:00:30 +00:00
// Copy constructor
2007-08-08 20:51:08 +00:00
TRACK::TRACK( const TRACK& Source ) :
BOARD_CONNECTED_ITEM( Source )
{
2007-10-19 06:31:17 +00:00
m_Shape = Source.m_Shape;
2007-10-13 06:18:44 +00:00
SetNet( Source.GetNet() );
2007-08-08 20:51:08 +00:00
m_Flags = Source.m_Flags;
m_TimeStamp = Source.m_TimeStamp;
SetStatus( Source.ReturnStatus() );
m_Start = Source.m_Start;
m_End = Source.m_End;
m_Width = Source.m_Width;
m_Drill = Source.m_Drill;
2007-10-13 06:18:44 +00:00
SetSubNet( Source.GetSubNet() );
2007-08-08 20:51:08 +00:00
m_Param = Source.m_Param;
}
2007-10-19 06:31:17 +00:00
/* Because of the way SEGVIA and SEGZONE are derived from TRACK and because there are
* virtual functions being used, we can no longer simply copy a TRACK and
* expect it to be a via or zone. We must construct a true SEGVIA or SEGZONE so its constructor
* can initialize the virtual function table properly. This factory type of
* function called Copy() can duplicate either a TRACK, SEGVIA, or SEGZONE.
*/
2007-09-01 12:00:30 +00:00
TRACK* TRACK::Copy() const
{
if( Type() == TYPE_TRACK )
2007-10-19 06:31:17 +00:00
return new TRACK( *this );
if( Type() == TYPE_VIA )
2007-10-19 06:31:17 +00:00
return new SEGVIA( (const SEGVIA &) * this );
2007-09-11 04:14:15 +00:00
if( Type() == TYPE_ZONE )
2007-10-19 06:31:17 +00:00
return new SEGZONE( (const SEGZONE &) * this );
2007-09-01 12:00:30 +00:00
return NULL; // should never happen
}
/**
* Function GetDrillValue
* calculate the drill value for vias (m-Drill if > 0, or default drill value for the board
* @return real drill_value
*/
2008-02-09 08:34:45 +00:00
int TRACK::GetDrillValue() const
{
if ( Type() != TYPE_VIA )
2008-02-09 08:34:45 +00:00
return 0;
if ( m_Drill >= 0 )
return m_Drill;
2008-02-09 08:34:45 +00:00
if ( m_Shape == VIA_MICROVIA )
return g_DesignSettings.m_MicroViaDrill;
2008-02-09 08:34:45 +00:00
return g_DesignSettings.m_ViaDrill;
}
/***********************/
2007-08-30 22:20:52 +00:00
bool TRACK::IsNull()
/***********************/
2007-08-08 20:51:08 +00:00
// return TRUE if segment length = 0
{
if( ( Type() != TYPE_VIA ) && ( m_Start == m_End ) )
2007-08-08 20:51:08 +00:00
return TRUE;
else
return FALSE;
}
2007-08-08 20:51:08 +00:00
/*************************************************************/
2007-08-08 20:51:08 +00:00
int TRACK::IsPointOnEnds( const wxPoint& point, int min_dist )
/*************************************************************/
2007-08-08 20:51:08 +00:00
/* Return:
2007-08-08 20:51:08 +00:00
* STARTPOINT if point if near (dist = min_dist) star point
* ENDPOINT if point if near (dist = min_dist) end point
* STARTPOINT|ENDPOINT if point if near (dist = min_dist) both ends
* 0 if no
* if min_dist < 0: min_dist = track_width/2
*/
{
2007-08-08 20:51:08 +00:00
int result = 0;
if( min_dist < 0 )
min_dist = m_Width / 2;
2007-10-13 06:18:44 +00:00
int dx = m_Start.x - point.x;
int dy = m_Start.y - point.y;
2007-10-19 06:31:17 +00:00
2007-08-08 20:51:08 +00:00
if( min_dist == 0 )
{
if( (dx == 0) && (dy == 0 ) )
result |= STARTPOINT;
}
else
{
double dist = ( (double) dx * dx ) + ( (double) dy * dy );
dist = sqrt( dist );
if( min_dist >= (int) dist )
result |= STARTPOINT;
}
dx = m_End.x - point.x;
dy = m_End.y - point.y;
if( min_dist == 0 )
{
if( (dx == 0) && (dy == 0 ) )
result |= ENDPOINT;
}
else
{
double dist = ( (double) dx * dx ) + ( (double) dy * dy );
dist = sqrt( dist );
if( min_dist >= (int) dist )
result |= ENDPOINT;
}
return result;
}
2007-08-08 20:51:08 +00:00
2008-03-15 04:18:32 +00:00
EDA_Rect TRACK::GetBoundingBox()
2008-03-05 22:39:33 +00:00
{
2008-03-10 13:33:12 +00:00
// end of track is round, this is its radius, rounded up
int radius = ( m_Width+1 )/2;
2008-03-05 22:39:33 +00:00
2008-03-10 15:00:22 +00:00
int ymax;
int xmax;
2008-03-05 22:39:33 +00:00
2008-03-10 15:00:22 +00:00
int ymin;
int xmin;
if( Type() == TYPE_VIA )
2008-03-10 15:00:22 +00:00
{
2008-03-10 15:02:27 +00:00
// Because vias are sometimes drawn larger than their m_Width would
// provide, erasing them using a dirty rect must also compensate for this
// possibility (that the via is larger on screen than its m_Width would provide).
// Because it is cheap to return a larger BoundingBox, do it so that
2008-03-10 15:00:22 +00:00
// the via gets erased properly. Do not divide width by 2 for this reason.
radius = m_Width;
ymax = m_Start.y;
xmax = m_Start.x;
ymin = m_Start.y;
xmin = m_Start.x;
}
else
{
radius = ( m_Width+1 )/2;
ymax = MAX( m_Start.y, m_End.y );
xmax = MAX( m_Start.x, m_End.x );
ymin = MIN( m_Start.y, m_End.y );
xmin = MIN( m_Start.x, m_End.x );
}
2008-03-05 22:39:33 +00:00
if( ShowClearance( this ) )
{
// + 1 is for the clearance line itself.
radius += g_DesignSettings.m_TrackClearence + 1;
}
2008-03-05 22:39:33 +00:00
ymax += radius;
xmax += radius;
ymin -= radius;
xmin -= radius;
2008-03-10 13:33:12 +00:00
// return a rectangle which is [pos,dim) in nature. therefore the +1
EDA_Rect ret( wxPoint( xmin, ymin ), wxSize( xmax-xmin+1, ymax-ymin+1 ) );
return ret;
2008-03-05 22:39:33 +00:00
}
2007-08-30 22:20:52 +00:00
// see class_track.h
// SEGVIA and SEGZONE inherit this version
2007-10-19 06:31:17 +00:00
SEARCH_RESULT TRACK::Visit( INSPECTOR* inspector, const void* testData,
const KICAD_T scanTypes[] )
2007-08-30 22:20:52 +00:00
{
2007-10-19 06:31:17 +00:00
KICAD_T stype = *scanTypes;
2007-08-08 20:51:08 +00:00
2007-10-19 06:31:17 +00:00
#if 0 && defined (DEBUG)
std::cout << GetClass().mb_str() << ' ';
2007-08-30 22:20:52 +00:00
#endif
2007-08-30 22:20:52 +00:00
// If caller wants to inspect my type
2007-09-01 12:00:30 +00:00
if( stype == Type() )
2007-08-30 22:20:52 +00:00
{
if( SEARCH_QUIT == inspector->Inspect( this, testData ) )
return SEARCH_QUIT;
}
2007-10-15 07:50:59 +00:00
return SEARCH_CONTINUE;
2007-08-30 22:20:52 +00:00
}
2007-10-19 06:31:17 +00:00
/***********************************************/
2007-08-30 22:20:52 +00:00
bool SEGVIA::IsOnLayer( int layer_number ) const
2007-10-19 06:31:17 +00:00
/***********************************************/
{
2007-10-19 06:31:17 +00:00
/**
* @param layer_number = layer number to test
* @return true if the via is on the layer layer_number
*/
2007-08-08 20:51:08 +00:00
int bottom_layer, top_layer;
2007-10-15 07:50:59 +00:00
2007-08-08 20:51:08 +00:00
ReturnLayerPair( &top_layer, &bottom_layer );
2007-10-15 07:50:59 +00:00
if( bottom_layer <= layer_number && layer_number <= top_layer )
2007-08-30 22:20:52 +00:00
return true;
2007-08-08 20:51:08 +00:00
else
2007-08-30 22:20:52 +00:00
return false;
}
/***********************************/
2007-08-30 22:20:52 +00:00
int TRACK::ReturnMaskLayer()
/***********************************/
2007-08-08 20:51:08 +00:00
2007-10-19 06:31:17 +00:00
/* Return the mask layer for this.
* for a via, there is more than one layer used
2007-08-08 20:51:08 +00:00
*/
{
if( Type() == TYPE_VIA )
2007-08-08 20:51:08 +00:00
{
2007-10-01 13:51:07 +00:00
int via_type = Shape();
2007-10-15 07:50:59 +00:00
if( via_type == VIA_THROUGH )
2007-08-08 20:51:08 +00:00
return ALL_CU_LAYERS;
// VIA_BLIND_BURIED or VIA_MICRVIA:
2007-10-15 07:50:59 +00:00
int bottom_layer, top_layer;
2007-10-01 13:51:07 +00:00
// ReturnLayerPair() knows how layers are stored
2007-10-19 06:31:17 +00:00
( (SEGVIA*) this )->ReturnLayerPair( &top_layer, &bottom_layer );
2007-10-15 07:50:59 +00:00
2007-08-08 20:51:08 +00:00
int layermask = 0;
while( bottom_layer <= top_layer )
{
layermask |= g_TabOneLayerMask[bottom_layer++];
}
return layermask;
}
else
return g_TabOneLayerMask[m_Layer];
}
/*********************************************************/
2007-08-08 20:51:08 +00:00
void SEGVIA::SetLayerPair( int top_layer, int bottom_layer )
/*********************************************************/
2007-08-08 20:51:08 +00:00
2007-10-19 06:31:17 +00:00
/** Set the .m_Layer member param:
* For a via m_Layer contains the 2 layers :
* top layer and bottom layer used by the via.
* The via connect all layers from top layer to bottom layer
* 4 bits for the first layer and 4 next bits for the secaon layer
* @param top_layer = first layer connected by the via
* @param bottom_layer = last layer connected by the via
2007-08-08 20:51:08 +00:00
*/
{
int via_type = Shape();
if( via_type == VIA_THROUGH )
2007-08-08 20:51:08 +00:00
{
2007-10-15 07:50:59 +00:00
top_layer = LAYER_CMP_N;
bottom_layer = COPPER_LAYER_N;
2007-08-08 20:51:08 +00:00
}
2007-08-08 20:51:08 +00:00
if( bottom_layer > top_layer )
EXCHG( bottom_layer, top_layer );
2007-08-08 20:51:08 +00:00
m_Layer = (top_layer & 15) + ( (bottom_layer & 15) << 4 );
}
2007-08-08 20:51:08 +00:00
/*********************************************************************/
2007-08-30 22:20:52 +00:00
void SEGVIA::ReturnLayerPair( int* top_layer, int* bottom_layer ) const
/*********************************************************************/
2007-08-08 20:51:08 +00:00
/**
* Function ReturnLayerPair
* Return the 2 layers used by the via (the via actually uses
2007-10-19 06:31:17 +00:00
* all layers between these 2 layers)
* @param top_layer = pointer to the first layer (can be null)
* @param bottom_layer = pointer to the last layer (can be null)
2007-08-08 20:51:08 +00:00
*/
{
2007-08-08 20:51:08 +00:00
int b_layer = (m_Layer >> 4) & 15;
int t_layer = m_Layer & 15;
if( b_layer > t_layer )
EXCHG( b_layer, t_layer );
2007-10-19 06:31:17 +00:00
2007-08-08 20:51:08 +00:00
if( top_layer )
*top_layer = t_layer;
2007-10-19 06:31:17 +00:00
2007-08-08 20:51:08 +00:00
if( bottom_layer )
*bottom_layer = b_layer;
}
/***********************************************/
2007-08-08 20:51:08 +00:00
TRACK* TRACK::GetBestInsertPoint( BOARD* Pcb )
/***********************************************/
2007-08-08 20:51:08 +00:00
2007-10-19 06:31:17 +00:00
/**
* Search the "best" insertion point within the track linked list
* the best point is the of the corresponding net code section
* @return the item found in the linked list (or NULL if no track)
2007-08-08 20:51:08 +00:00
*/
{
TRACK* track;
2007-08-08 20:51:08 +00:00
if( Type() == TYPE_ZONE )
2007-08-08 20:51:08 +00:00
track = Pcb->m_Zone;
else
track = Pcb->m_Track;
for( ; track; track = track->Next() )
2007-08-08 20:51:08 +00:00
{
if( GetNet() <= track->GetNet() )
return track;
2007-08-08 20:51:08 +00:00
}
return NULL;
}
2007-08-08 20:51:08 +00:00
2007-10-19 06:31:17 +00:00
/*******************************************/
2007-08-08 20:51:08 +00:00
TRACK* TRACK::GetStartNetCode( int NetCode )
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* Track = this;
int ii = 0;
if( NetCode == -1 )
2007-10-13 06:18:44 +00:00
NetCode = GetNet();
2007-08-08 20:51:08 +00:00
while( Track != NULL )
{
2007-10-13 06:18:44 +00:00
if( Track->GetNet() > NetCode )
2007-08-08 20:51:08 +00:00
break;
2007-10-19 06:31:17 +00:00
2007-10-13 06:18:44 +00:00
if( Track->GetNet() == NetCode )
2007-08-08 20:51:08 +00:00
{
2007-10-19 06:31:17 +00:00
ii++;
2007-10-13 06:18:44 +00:00
break;
2007-08-08 20:51:08 +00:00
}
2007-10-19 06:31:17 +00:00
2007-08-08 20:51:08 +00:00
Track = (TRACK*) Track->Pnext;
}
if( ii )
return Track;
else
return NULL;
}
2007-08-08 20:51:08 +00:00
2007-10-19 06:31:17 +00:00
/*****************************************/
2007-08-08 20:51:08 +00:00
TRACK* TRACK::GetEndNetCode( 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* NextS, * Track = this;
int ii = 0;
if( Track == NULL )
return NULL;
if( NetCode == -1 )
2007-10-13 06:18:44 +00:00
NetCode = GetNet();
2007-08-08 20:51:08 +00:00
while( Track != NULL )
{
NextS = (TRACK*) Track->Pnext;
2007-10-13 06:18:44 +00:00
if( Track->GetNet() == NetCode )
2007-08-08 20:51:08 +00:00
ii++;
2007-10-19 06:31:17 +00:00
2007-08-08 20:51:08 +00:00
if( NextS == NULL )
break;
2007-10-19 06:31:17 +00:00
2007-10-13 06:18:44 +00:00
if( NextS->GetNet() > NetCode )
2007-08-08 20:51:08 +00:00
break;
2007-10-19 06:31:17 +00:00
2007-08-08 20:51:08 +00:00
Track = NextS;
}
if( ii )
return Track;
else
return NULL;
}
2007-10-30 21:30:58 +00:00
bool TRACK::Save( FILE* aFile ) const
{
int type = 0;
if( Type() == TYPE_VIA )
2007-10-30 21:30:58 +00:00
type = 1;
if( GetState( DELETED ) )
return true;
fprintf( aFile, "Po %d %d %d %d %d %d %d\n", m_Shape,
m_Start.x, m_Start.y, m_End.x, m_End.y, m_Width, m_Drill );
fprintf( aFile, "De %d %d %d %lX %X\n",
m_Layer, type, GetNet(),
m_TimeStamp, ReturnStatus() );
return true;
}
2007-08-08 20:51:08 +00:00
/*********************************************************************/
2008-04-01 05:21:50 +00:00
void TRACK::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, const wxPoint& notUsed )
/*********************************************************************/
{
2007-08-08 20:51:08 +00:00
int l_piste;
int color;
int zoom;
int rayon;
int curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
if( Type() == TYPE_ZONE && !DisplayOpt.DisplayZones )
2007-08-08 20:51:08 +00:00
return;
if( m_Flags & DRAW_ERASED ) // draw in background color, used by classs TRACK in gerbview
{
color = g_DrawBgColor;
D(printf("DRAW_ERASED in Track::Draw, g_DrawBgColor=%04X\n", g_DrawBgColor );)
}
2007-08-08 20:51:08 +00:00
else
{
color = g_DesignSettings.m_LayerColor[m_Layer];
2007-08-08 20:51:08 +00:00
if( ( color & (ITEM_NOT_SHOW | HIGHT_LIGHT_FLAG) ) == ITEM_NOT_SHOW )
return;
2007-08-08 20:51:08 +00:00
if( DisplayOpt.ContrastModeDisplay )
2007-08-08 20:51:08 +00:00
{
if( !IsOnLayer( curr_layer ) )
{
color &= ~MASKCOLOR;
color |= DARKDARKGRAY;
}
2007-08-08 20:51:08 +00:00
}
if( draw_mode & GR_SURBRILL )
{
if( draw_mode & GR_AND )
color &= ~HIGHT_LIGHT_FLAG;
else
color |= HIGHT_LIGHT_FLAG;
}
2008-04-02 14:16:14 +00:00
if( color & HIGHT_LIGHT_FLAG )
color = ColorRefs[color & MASKCOLOR].m_LightColor;
2007-08-08 20:51:08 +00:00
SetAlpha( &color, 150 );
}
GRSetDrawMode( DC, draw_mode );
2008-04-02 14:16:14 +00:00
2007-08-08 20:51:08 +00:00
zoom = panel->GetZoom();
l_piste = m_Width >> 1;
if( m_Shape == S_CIRCLE )
{
rayon = (int) hypot( (double) (m_End.x - m_Start.x),
(double) (m_End.y - m_Start.y) );
if( (l_piste / zoom) < L_MIN_DESSIN )
{
GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y, rayon, color );
}
else
{
2007-10-19 06:31:17 +00:00
if( l_piste <= zoom ) /* Sketch mode if l_piste/zoom <= 1 */
2007-08-08 20:51:08 +00:00
{
GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y, rayon, color );
}
else if( ( !DisplayOpt.DisplayPcbTrackFill) || GetState( FORCE_SKETCH ) )
{
GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y, rayon - l_piste, color );
GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y, rayon + l_piste, color );
}
else
{
GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y, rayon,
m_Width, color );
}
}
return;
}
if( (l_piste / zoom) < L_MIN_DESSIN )
{
GRLine( &panel->m_ClipBox, DC, m_Start.x, m_Start.y,
m_End.x, m_End.y, 0, color );
return;
}
if( !DisplayOpt.DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
2007-08-08 20:51:08 +00:00
{
GRCSegm( &panel->m_ClipBox, DC, m_Start.x, m_Start.y,
m_End.x, m_End.y, m_Width, color );
}
else
{
GRFillCSegm( &panel->m_ClipBox, DC, m_Start.x, m_Start.y,
m_End.x, m_End.y, m_Width, color );
}
// Show clearance for tracks, not for zone segments
if( ShowClearance( this ) )
2007-08-08 20:51:08 +00:00
{
GRCSegm( &panel->m_ClipBox, DC, m_Start.x, m_Start.y,
m_End.x, m_End.y,
m_Width + (g_DesignSettings.m_TrackClearence * 2), color );
}
}
/*******************************************************************************************/
void SEGVIA::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, const wxPoint& notUsed )
/*******************************************************************************************/
{
int color;
int zoom;
int rayon;
int curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
GRSetDrawMode( DC, draw_mode );
color = g_DesignSettings.m_ViaColor[m_Shape];
if( ( color & (ITEM_NOT_SHOW | HIGHT_LIGHT_FLAG) ) == ITEM_NOT_SHOW )
return;
if( DisplayOpt.ContrastModeDisplay )
{
if( !IsOnLayer( curr_layer ) )
{
color &= ~MASKCOLOR;
color |= DARKDARKGRAY;
}
}
if( draw_mode & GR_SURBRILL )
{
if( draw_mode & GR_AND )
color &= ~HIGHT_LIGHT_FLAG;
else
color |= HIGHT_LIGHT_FLAG;
}
if( color & HIGHT_LIGHT_FLAG )
color = ColorRefs[color & MASKCOLOR].m_LightColor;
SetAlpha( &color, 150 );
zoom = panel->GetZoom();
rayon = m_Width >> 1;
if( rayon < zoom )
rayon = zoom;
GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y, rayon, color );
if( rayon > (4 * zoom) )
{
int drill_rayon = GetDrillValue() / 2;
int inner_rayon = rayon - (2 * zoom);
GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y,
inner_rayon, color );
// Draw the via hole if the display option allows it
if( DisplayOpt.m_DisplayViaMode != VIA_HOLE_NOT_SHOW )
{
if( (DisplayOpt.m_DisplayViaMode == ALL_VIA_HOLE_SHOW) || // Display all drill holes requested
( (drill_rayon > 0 ) && ! IsDrillDefault() ) ) // Or Display non default holes requested
{
if( drill_rayon < inner_rayon ) // We can show the via hole
{
GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y,
drill_rayon, color );
}
}
}
if( DisplayOpt.DisplayTrackIsol )
GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y,
rayon + g_DesignSettings.m_TrackClearence, color );
// for Micro Vias, draw a partial cross :
// X on component layer, or + on copper layer
// (so we can see 2 superimposed microvias ):
if( Shape() == VIA_MICROVIA )
{
int ax, ay, bx, by;
if( IsOnLayer(COPPER_LAYER_N) )
{
ax = rayon; ay = 0;
bx = drill_rayon; by = 0;
}
else
{
ax = ay = (rayon * 707) / 1000;
bx = by = (drill_rayon * 707) / 1000;
}
/* lines | or \ */
GRLine( &panel->m_ClipBox, DC, m_Start.x - ax , m_Start.y - ay,
m_Start.x - bx , m_Start.y - by, 0, color );
GRLine( &panel->m_ClipBox, DC, m_Start.x + bx , m_Start.y + by,
m_Start.x + ax , m_Start.y + ay, 0, color );
/* lines - or / */
GRLine( &panel->m_ClipBox, DC, m_Start.x + ay, m_Start.y - ax ,
m_Start.x + by, m_Start.y - bx, 0, color );
GRLine( &panel->m_ClipBox, DC, m_Start.x - by, m_Start.y + bx ,
m_Start.x - ay, m_Start.y + ax, 0, color );
}
// for Buried Vias, draw a partial line :
// orient depending on layer pair
// (so we can see superimposed buried vias ):
if( Shape() == VIA_BLIND_BURIED )
{
int ax = 0, ay = rayon, bx = 0, by = drill_rayon;
int layer_top, layer_bottom;
((SEGVIA*)this)->ReturnLayerPair(&layer_top, &layer_bottom);
/* lines for the top layer */
RotatePoint( &ax, &ay, layer_top * 3600 / g_DesignSettings.m_CopperLayerCount);
RotatePoint( &bx, &by, layer_top * 3600 / g_DesignSettings.m_CopperLayerCount);
GRLine( &panel->m_ClipBox, DC, m_Start.x - ax , m_Start.y - ay,
m_Start.x - bx , m_Start.y - by, 0, color );
/* lines for the bottom layer */
ax = 0; ay = rayon; bx = 0; by = drill_rayon;
RotatePoint( &ax, &ay, layer_bottom * 3600 / g_DesignSettings.m_CopperLayerCount);
RotatePoint( &bx, &by, layer_bottom * 3600 / g_DesignSettings.m_CopperLayerCount);
GRLine( &panel->m_ClipBox, DC, m_Start.x - ax , m_Start.y - ay,
m_Start.x - bx , m_Start.y - by, 0, color );
}
}
}
// see class_track.h
void TRACK::Display_Infos( WinEDA_DrawFrame* frame )
{
2008-02-19 00:30:10 +00:00
wxString msg;
int text_pos;
BOARD* board = ((WinEDA_PcbFrame*)frame)->m_Pcb;
2007-10-19 06:31:17 +00:00
#ifdef RATSNET_DEBUG
2007-10-19 06:31:17 +00:00
DbgDisplayTrackInfos( this );
#endif
frame->MsgPanel->EraseMsgBox();
2007-09-01 12:00:30 +00:00
switch( Type() )
{
case TYPE_VIA:
2007-10-03 19:45:32 +00:00
msg = g_ViaType_Name[Shape()];
break;
case TYPE_TRACK:
msg = _( "Track" );
break;
case TYPE_ZONE:
msg = _( "Zone" ); break;
default:
msg = wxT( "????" ); break;
}
text_pos = 1;
Affiche_1_Parametre( frame, text_pos, _( "Type" ), msg, DARKCYAN );
text_pos += 10;
2008-02-19 00:30:10 +00:00
if( Type() == TYPE_TRACK
|| Type() == TYPE_ZONE
|| Type() == TYPE_VIA )
{
/* Display NetName pour les segments de piste type cuivre */
2008-02-19 00:30:10 +00:00
EQUIPOT* equipot = board->FindNet( GetNet() );
2007-10-19 06:31:17 +00:00
if( equipot )
msg = equipot->m_Netname;
else
msg = wxT( "<noname>" );
2007-10-19 06:31:17 +00:00
Affiche_1_Parametre( frame, text_pos, _( "NetName" ), msg, RED );
text_pos += 20;
2007-10-19 06:31:17 +00:00
/* Display net code : (usefull in test or debug) */
2007-10-13 06:18:44 +00:00
msg.Printf( wxT( "%d .%d" ), GetNet(), GetSubNet() );
Affiche_1_Parametre( frame, text_pos, _( "NetCode" ), msg, RED );
text_pos += 8;
}
else
{
Affiche_1_Parametre( frame, text_pos, _( "Segment" ), wxEmptyString, RED );
if( m_Shape == S_CIRCLE )
Affiche_1_Parametre( frame, -1, wxEmptyString, _( "Circle" ), RED );
else
Affiche_1_Parametre( frame, -1, wxEmptyString, _( "Standard" ), RED );
text_pos += 8;
}
#if defined(DEBUG)
/* Display the flags */
msg.Printf( wxT("0x%08X"), m_Flags );
Affiche_1_Parametre( frame, text_pos, _( "Flags" ), msg, BLUE );
text_pos += 8;
#endif
/* Display the State member */
msg = wxT( ". . " );
if( GetState( SEGM_FIXE ) )
msg[0] = 'F';
2007-10-19 06:31:17 +00:00
if( GetState( SEGM_AR ) )
msg[2] = 'A';
2007-10-19 06:31:17 +00:00
Affiche_1_Parametre( frame, text_pos, _( "Stat" ), msg, MAGENTA );
text_pos += 6;
2007-10-19 06:31:17 +00:00
/* Display layer or layer pair) */
if( Type() == TYPE_VIA )
{
SEGVIA* Via = (SEGVIA*) this;
int top_layer, bottom_layer;
2007-10-19 06:31:17 +00:00
Via->ReturnLayerPair( &top_layer, &bottom_layer );
2008-02-19 00:30:10 +00:00
msg = board->GetLayerName( top_layer ) + wxT( "/" )
+ board->GetLayerName( bottom_layer );
}
else
2008-02-19 00:30:10 +00:00
msg = board->GetLayerName( m_Layer );
Affiche_1_Parametre( frame, text_pos, _( "Layer" ), msg, BROWN );
text_pos += 15;
2007-10-19 06:31:17 +00:00
/* Display width */
valeur_param( (unsigned) m_Width, msg );
2007-10-19 06:31:17 +00:00
if( Type() == TYPE_VIA ) // Display Diam and Drill values
{
Affiche_1_Parametre( frame, text_pos, _( "Diam" ), msg, DARKCYAN );
text_pos += 8;
int drill_value = GetDrillValue();
2007-10-19 06:31:17 +00:00
valeur_param( (unsigned) drill_value, msg );
2007-10-19 06:31:17 +00:00
wxString title = _( "Drill" );
2007-10-19 06:31:17 +00:00
if( g_DesignSettings.m_ViaDrill >= 0 )
title += wxT( "*" );
2007-10-19 06:31:17 +00:00
Affiche_1_Parametre( frame, text_pos, _( "Drill" ), msg, RED );
}
else
Affiche_1_Parametre( frame, text_pos, _( "Width" ), msg, DARKCYAN );
}
2007-08-08 20:51:08 +00:00
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param ref_pos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool TRACK::HitTest( const wxPoint& ref_pos )
{
2008-03-05 22:39:33 +00:00
int radius = m_Width >> 1;
// (dx, dy) is a vector from m_Start to m_End (an origin of m_Start)
int dx = m_End.x - m_Start.x;
int dy = m_End.y - m_Start.y;
// (spot_cX, spot_cY) is a vector from m_Start to ref_pos (an origin of m_Start)
int spot_cX = ref_pos.x - m_Start.x;
int spot_cY = ref_pos.y - m_Start.y;
if( Type() == TYPE_VIA ) /* VIA rencontree */
2008-03-05 22:39:33 +00:00
{
return (double) spot_cX * spot_cX + (double) spot_cY * spot_cY <=
(double) radius * radius;
}
else
{
if( DistanceTest( radius, dx, dy, spot_cX, spot_cY ) )
return true;
}
2007-10-19 06:31:17 +00:00
return false;
}
2007-08-09 01:41:30 +00:00
2008-01-06 12:43:57 +00:00
/**
* Function HitTest (overlayed)
* tests if the given EDA_Rect intersect this object.
* For now, an ending point must be inside this rect.
* @param refArea : the given EDA_Rect
* @return bool - true if a hit, else false
*/
bool TRACK::HitTest( EDA_Rect& refArea )
{
2008-02-09 08:34:45 +00:00
if( refArea.Inside( m_Start ) )
return true;
if( refArea.Inside( m_End ) )
return true;
return false;
2008-01-06 12:43:57 +00:00
}
2007-10-19 06:31:17 +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.
2007-10-19 06:31:17 +00:00
* @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 TRACK::Show( int nestLevel, std::ostream& os )
{
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() <<
2007-10-19 06:31:17 +00:00
// " shape=\"" << m_Shape << '"' <<
" addr=\"" << std::hex << this << std::dec << '"' <<
2007-10-19 06:31:17 +00:00
" layer=\"" << m_Layer << '"' <<
" width=\"" << m_Width << '"' <<
" flags=\"" << m_Flags << '"' <<
" status=\"" << GetState(-1) << '"' <<
2007-10-19 06:31:17 +00:00
// " drill=\"" << GetDrillValue() << '"' <<
2007-10-19 06:31:17 +00:00
" netcode=\"" << GetNet() << "\">" <<
"<start" << m_Start << "/>" <<
"<end" << m_End << "/>";
os << "</" << GetClass().Lower().mb_str() << ">\n";
2007-08-09 01:41:30 +00:00
}
/**
* Function Show
* is used to output the object tree, currently for debugging only.
2007-10-19 06:31:17 +00:00
* @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 SEGVIA::Show( int nestLevel, std::ostream& os )
{
const char* cp;
2007-10-19 06:31:17 +00:00
switch( Shape() )
{
case VIA_THROUGH:
2007-10-15 07:50:59 +00:00
cp = "through";
break;
case VIA_BLIND_BURIED:
cp = "blind/buried";
2007-10-15 07:50:59 +00:00
break;
case VIA_MICROVIA:
cp = "micro via";
2007-10-15 07:50:59 +00:00
break;
default:
2007-10-15 07:50:59 +00:00
case VIA_NOT_DEFINED:
cp = "undefined";
break;
}
2007-10-19 06:31:17 +00:00
int topLayer;
int botLayer;
2008-02-19 00:30:10 +00:00
BOARD* board = (BOARD*) m_Parent;
2007-10-19 06:31:17 +00:00
ReturnLayerPair( &topLayer, &botLayer );
2007-10-19 06:31:17 +00:00
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() <<
2008-02-19 00:30:10 +00:00
" type=\"" << cp << '"';
if( board )
os << " layers=\"" << board->GetLayerName( topLayer ).Trim().mb_str() << ","
<< board->GetLayerName( botLayer ).Trim().mb_str() << '"';
os <<
2007-10-19 06:31:17 +00:00
" width=\"" << m_Width << '"' <<
" drill=\"" << GetDrillValue() << '"' <<
2007-10-19 06:31:17 +00:00
" netcode=\"" << GetNet() << "\">" <<
"<pos" << m_Start << "/>";
os << "</" << GetClass().Lower().mb_str() << ">\n";
}
wxString TRACK::ShowState( int stateBits )
{
wxString ret;
if( stateBits & CHAIN )
ret << wxT(" | CHAIN");
if( stateBits & SEGM_AR )
ret << wxT(" | SEGM_AR");
if( stateBits & SEGM_FIXE )
ret << wxT(" | SEGM_FIXE");
if( stateBits & EDIT )
ret << wxT(" | EDIT");
if( stateBits & DRAG )
ret << wxT(" | DRAG");
if( stateBits & SURBRILL )
ret << wxT(" | SURBRILL");
if( stateBits & NO_TRACE )
ret << wxT(" | NO_TRACE");
if( stateBits & DELETED )
ret << wxT(" | DELETED");
if( stateBits & BUSY )
ret << wxT(" | BUSY");
if( stateBits & END_ONPAD)
ret << wxT(" | END_ONPAD");
if( stateBits & BEGIN_ONPAD)
ret << wxT(" | BEGIN_ONPAD");
if( stateBits & FLAG0)
ret << wxT(" | FLAG0");
if( stateBits & FLAG1 )
ret << wxT(" | FLAG1");
return ret;
}
2007-08-09 01:41:30 +00:00
#endif