kicad/pcbnew/class_track.cpp

955 lines
24 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
/**********************************************************/
TRACK::TRACK( BOARD_ITEM* StructFather, KICAD_T idtype ) :
2007-08-23 04:28:46 +00:00
BOARD_ITEM( StructFather, 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;
2007-10-13 06:18:44 +00:00
SetNet( 0 );
SetSubNet( 0 );
2007-10-19 06:31:17 +00:00
m_Drill = -1;
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;
2007-10-19 06:31:17 +00:00
#if 0
2007-10-11 00:11:59 +00:00
double value = To_User_Unit( g_UnitMetric, m_Width, PCB_INTERNAL_UNIT );
2007-10-19 06:31:17 +00:00
2007-10-11 00:11:59 +00:00
if( g_UnitMetric == INCHES ) // Affichage en mils
msg.Printf( wxT( "%.1f" ), value * 1000 );
else
msg.Printf( wxT( "%.3f" ), value );
#else
valeur_param( m_Width, msg );
#endif
2007-10-19 06:31:17 +00:00
2007-10-11 00:11:59 +00:00
return msg;
}
2007-08-09 01:41:30 +00:00
2007-08-23 04:28:46 +00:00
SEGZONE::SEGZONE( BOARD_ITEM* StructFather ) :
2007-08-08 20:51:08 +00:00
TRACK( StructFather, TYPEZONE )
{
}
2007-08-08 20:51:08 +00:00
2007-08-23 04:28:46 +00:00
SEGVIA::SEGVIA( BOARD_ITEM* StructFather ) :
2007-08-08 20:51:08 +00:00
TRACK( StructFather, TYPEVIA )
{
}
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 ) :
2007-09-01 12:00:30 +00:00
BOARD_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() == TYPETRACK )
2007-10-19 06:31:17 +00:00
return new TRACK( *this );
2007-09-01 12:00:30 +00:00
if( Type() == TYPEVIA )
2007-10-19 06:31:17 +00:00
return new SEGVIA( (const SEGVIA &) * this );
2007-09-11 04:14:15 +00:00
if( Type() == TYPEZONE )
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
}
/***********************/
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
{
2007-09-01 12:00:30 +00:00
if( ( Type() != TYPEVIA ) && ( 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
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
*/
{
2007-09-01 12:00:30 +00:00
if( Type() == TYPEVIA )
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 or VIA_BURIED:
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
2007-10-19 06:31:17 +00:00
/* Return the 2 layers used by the via (the via actually uses
* 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;
}
/* Remove this from the track or zone linked list
*/
2007-08-30 22:20:52 +00:00
void TRACK::UnLink()
{
2007-10-19 06:31:17 +00:00
/* Remove the back link */
2007-08-08 20:51:08 +00:00
if( Pback )
{
2007-09-01 12:00:30 +00:00
if( Pback->Type() != TYPEPCB )
2007-08-08 20:51:08 +00:00
{
Pback->Pnext = Pnext;
}
else /* Le chainage arriere pointe sur la structure "Pere" */
{
if( GetState( DELETED ) ) // A REVOIR car Pback = NULL si place en undelete
{
2007-11-05 07:07:00 +00:00
if( g_UnDeleteStackPtr )
2007-10-19 06:31:17 +00:00
g_UnDeleteStack[g_UnDeleteStackPtr - 1] = (BOARD_ITEM*) Pnext;
2007-08-08 20:51:08 +00:00
}
else
{
2007-09-01 12:00:30 +00:00
if( Type() == TYPEZONE )
2007-08-08 20:51:08 +00:00
{
( (BOARD*) Pback )->m_Zone = (SEGZONE*) Pnext;
2007-08-08 20:51:08 +00:00
}
else
{
( (BOARD*) Pback )->m_Track = (TRACK*) Pnext;
}
}
}
}
2007-10-19 06:31:17 +00:00
/* Remove the forward link */
2007-08-08 20:51:08 +00:00
if( Pnext )
Pnext->Pback = Pback;
Pnext = Pback = NULL;
}
2007-08-08 20:51:08 +00:00
/************************************************************/
2007-09-01 12:00:30 +00:00
void TRACK::Insert( BOARD* Pcb, BOARD_ITEM* InsertPoint )
/************************************************************/
2007-10-19 06:31:17 +00:00
/* insert this (and its linked segments is exists)
* in the track linked list
* @param InsertPoint = insert point within the linked list
* if NULL: insert as first element of Pcb->m_Tracks
*/
{
2007-09-01 12:00:30 +00:00
TRACK* track;
TRACK* NextS;
2007-08-08 20:51:08 +00:00
if( InsertPoint == NULL )
{
Pback = Pcb;
2007-10-19 06:31:17 +00:00
2007-09-01 12:00:30 +00:00
if( Type() == TYPEZONE ) // put SEGZONE on front of m_Zone list
2007-08-08 20:51:08 +00:00
{
2007-10-19 06:31:17 +00:00
NextS = Pcb->m_Zone;
Pcb->m_Zone = (SEGZONE*) this;
2007-08-08 20:51:08 +00:00
}
2007-09-01 12:00:30 +00:00
else // put TRACK or SEGVIA on front of m_Track list
2007-08-08 20:51:08 +00:00
{
2007-10-19 06:31:17 +00:00
NextS = Pcb->m_Track;
2007-09-01 12:00:30 +00:00
Pcb->m_Track = this;
2007-08-08 20:51:08 +00:00
}
}
else
{
NextS = (TRACK*) InsertPoint->Pnext;
Pback = InsertPoint;
InsertPoint->Pnext = this;
}
2007-10-19 06:31:17 +00:00
/* Set the forward link */
2007-08-08 20:51:08 +00:00
track = this;
2007-10-19 06:31:17 +00:00
while( track->Pnext ) // Search the end of added chain
2007-08-08 20:51:08 +00:00
track = (TRACK*) track->Pnext;
2007-10-19 06:31:17 +00:00
/* Link the end of chain */
2007-08-08 20:51:08 +00:00
track->Pnext = NextS;
if( NextS )
NextS->Pback = track;
}
/***********************************************/
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
*/
{
2007-08-08 20:51:08 +00:00
TRACK* track, * NextTrack;
2007-09-01 12:00:30 +00:00
if( Type() == TYPEZONE )
2007-08-08 20:51:08 +00:00
track = Pcb->m_Zone;
else
track = Pcb->m_Track;
/* Traitement du debut de liste */
if( track == NULL )
2007-10-19 06:31:17 +00:00
return NULL; /* No tracks ! */
2007-11-02 18:21:43 +00:00
2007-10-19 06:31:17 +00:00
if( GetNet() < track->GetNet() ) /* no net code or net code = 0 (track not connected) */
2007-08-08 20:51:08 +00:00
return NULL;
while( (NextTrack = (TRACK*) track->Pnext) != NULL )
{
2007-10-13 06:18:44 +00:00
if( NextTrack->GetNet() > this->GetNet() )
2007-08-08 20:51:08 +00:00
break;
2007-11-02 18:21:43 +00:00
2007-08-08 20:51:08 +00:00
track = NextTrack;
}
return track;
}
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
#if 0 // replaced by Save()
/********************************************/
2007-08-08 20:51:08 +00:00
bool TRACK::WriteTrackDescr( FILE* File )
/********************************************/
2007-10-19 06:31:17 +00:00
/* write a via description on file
*/
{
2007-08-09 01:41:30 +00:00
int type = 0;
2007-09-01 12:00:30 +00:00
if( Type() == TYPEVIA )
2007-08-08 20:51:08 +00:00
type = 1;
2007-08-08 20:51:08 +00:00
if( GetState( DELETED ) )
return FALSE;
fprintf( File, "Po %d %d %d %d %d %d %d\n", m_Shape,
2007-08-08 20:51:08 +00:00
m_Start.x, m_Start.y, m_End.x, m_End.y, m_Width, m_Drill );
2007-08-08 20:51:08 +00:00
fprintf( File, "De %d %d %d %lX %X\n",
2007-10-13 06:18:44 +00:00
m_Layer, type, GetNet(),
2007-08-08 20:51:08 +00:00
m_TimeStamp, ReturnStatus() );
2007-08-08 20:51:08 +00:00
return TRUE;
}
2007-10-30 21:30:58 +00:00
#endif
bool TRACK::Save( FILE* aFile ) const
{
int type = 0;
if( Type() == TYPEVIA )
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
/*********************************************************************/
2007-08-08 20:51:08 +00:00
void TRACK::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode )
/*********************************************************************/
2007-08-08 20:51:08 +00:00
2007-10-19 06:31:17 +00:00
/** Draws the segment.
* @param panel = current panel
* @param DC = current device context
* @param draw_mode = GR_XOR, GR_OR..
2007-08-08 20:51:08 +00:00
*/
{
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() == TYPEZONE && !DisplayOpt.DisplayZones )
2007-08-08 20:51:08 +00:00
return;
GRSetDrawMode( DC, draw_mode );
2007-10-19 06:31:17 +00:00
if( Type() == TYPEVIA )
2007-08-08 20:51:08 +00:00
color = g_DesignSettings.m_ViaColor[m_Shape];
else
color = g_DesignSettings.m_LayerColor[m_Layer];
if( ( color & (ITEM_NOT_SHOW | HIGHT_LIGHT_FLAG) ) == ITEM_NOT_SHOW )
return;
if( DisplayOpt.ContrastModeDisplay )
{
2007-08-30 22:20:52 +00:00
if( !IsOnLayer( curr_layer ) )
2007-08-08 20:51:08 +00:00
{
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;
zoom = panel->GetZoom();
l_piste = m_Width >> 1;
2007-10-19 06:31:17 +00:00
if( Type() == TYPEVIA ) /* The via is drawn as a circle */
2007-08-08 20:51:08 +00:00
{
2007-10-19 06:31:17 +00:00
rayon = l_piste;
if( rayon < zoom )
2007-08-08 20:51:08 +00:00
rayon = zoom;
GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y, rayon, color );
if( rayon > (4 * zoom) )
{
int drill_rayon, inner_rayon = rayon - (2 * zoom);
GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y,
inner_rayon, color );
2007-10-19 06:31:17 +00:00
// Draw the via hole if the display option allows it
2007-08-08 20:51:08 +00:00
if( DisplayOpt.m_DisplayViaMode != VIA_HOLE_NOT_SHOW )
{
if( (DisplayOpt.m_DisplayViaMode == ALL_VIA_HOLE_SHOW)
|| ( m_Drill > 0 ) )
{
if( m_Drill > 0 )
drill_rayon = m_Drill / 2;
else
drill_rayon = g_DesignSettings.m_ViaDrill / 2;
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 );
}
return;
}
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 ) )
{
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 );
}
2007-10-19 06:31:17 +00:00
/* Shows clearance (for tracks and vias, not for zone segments */
if( DisplayOpt.DisplayTrackIsol && ( m_Layer <= LAST_COPPER_LAYER )
2007-10-19 06:31:17 +00:00
&& ( Type() == TYPETRACK || Type() == TYPEVIA) )
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 );
}
}
// see class_track.h
void TRACK::Display_Infos( WinEDA_DrawFrame* frame )
{
wxString msg;
int text_pos;
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 TYPEVIA:
2007-10-03 19:45:32 +00:00
msg = g_ViaType_Name[Shape()];
break;
case TYPETRACK:
msg = _( "Track" );
break;
case TYPEZONE:
msg = _( "Zone" ); break;
default:
msg = wxT( "????" ); break;
}
text_pos = 1;
Affiche_1_Parametre( frame, text_pos, _( "Type" ), msg, DARKCYAN );
2007-10-19 06:31:17 +00:00
/* Display NetName pour les segments de piste type cuivre */
text_pos += 15;
2007-10-19 06:31:17 +00:00
if( Type() == TYPETRACK
|| Type() == TYPEZONE
|| Type() == TYPEVIA )
{
2007-10-19 06:31:17 +00:00
EQUIPOT* equipot = ( (WinEDA_PcbFrame*) frame )->m_Pcb->FindNet( GetNet() );
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 );
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() );
text_pos += 18;
Affiche_1_Parametre( frame, text_pos, _( "NetCode" ), msg, RED );
}
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 );
}
2007-10-19 06:31:17 +00:00
/* Display the Status flags */
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
text_pos = 42;
Affiche_1_Parametre( frame, text_pos, _( "Stat" ), msg, MAGENTA );
2007-10-19 06:31:17 +00:00
/* Display layer or layer pair) */
2007-09-01 12:00:30 +00:00
if( Type() == TYPEVIA )
{
SEGVIA* Via = (SEGVIA*) this;
int top_layer, bottom_layer;
2007-10-19 06:31:17 +00:00
Via->ReturnLayerPair( &top_layer, &bottom_layer );
2007-10-19 06:31:17 +00:00
msg = ReturnPcbLayerName( top_layer, TRUE ) + wxT( "/" )
+ ReturnPcbLayerName( bottom_layer, TRUE );
}
else
msg = ReturnPcbLayerName( m_Layer );
text_pos += 5;
Affiche_1_Parametre( frame, text_pos, _( "Layer" ), msg, BROWN );
2007-10-19 06:31:17 +00:00
/* Display width */
valeur_param( (unsigned) m_Width, msg );
text_pos += 11;
2007-10-19 06:31:17 +00:00
2007-09-01 12:00:30 +00:00
if( Type() == TYPEVIA ) // Display Diam and Drill values
{
Affiche_1_Parametre( frame, text_pos, _( "Diam" ), msg, DARKCYAN );
int drill_value = m_Drill >= 0 ?
m_Drill : g_DesignSettings.m_ViaDrill;
2007-10-19 06:31:17 +00:00
valeur_param( (unsigned) drill_value, msg );
2007-10-19 06:31:17 +00:00
text_pos += 8;
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 )
{
2007-10-19 06:31:17 +00:00
int l_piste; /* demi-largeur de la piste */
int dx, dy, spot_cX, spot_cY;
int ux0, uy0;
2007-08-08 20:51:08 +00:00
/* calcul des coordonnees du segment teste */
l_piste = m_Width >> 1; /* l_piste = demi largeur piste */
2007-10-19 06:31:17 +00:00
ux0 = m_Start.x;
2007-08-08 20:51:08 +00:00
uy0 = m_Start.y; /* coord de depart */
2007-10-19 06:31:17 +00:00
dx = m_End.x;
2007-08-08 20:51:08 +00:00
dy = m_End.y; /* coord d'arrivee */
/* recalcul des coordonnees avec ux0, uy0 = origine des coordonnees */
2007-10-19 06:31:17 +00:00
dx -= ux0;
2007-08-08 20:51:08 +00:00
dy -= uy0;
2007-10-19 06:31:17 +00:00
spot_cX = ref_pos.x - ux0;
2007-08-08 20:51:08 +00:00
spot_cY = ref_pos.y - uy0;
2007-09-01 12:00:30 +00:00
if( Type() == TYPEVIA ) /* VIA rencontree */
2007-08-08 20:51:08 +00:00
{
if( (abs( spot_cX ) <= l_piste ) && (abs( spot_cY ) <=l_piste) )
return true;
else
return false;
}
else
{
if( DistanceTest( l_piste, 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
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 << '"' <<
2007-10-19 06:31:17 +00:00
" layer=\"" << m_Layer << '"' <<
" width=\"" << m_Width << '"' <<
// " drill=\"" << m_Drill << '"' <<
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_BURIED:
2007-10-15 07:50:59 +00:00
cp = "blind";
break;
case VIA_BLIND:
2007-10-15 07:50:59 +00:00
cp = "buried";
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;
ReturnLayerPair( &topLayer, &botLayer );
2007-10-19 06:31:17 +00:00
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() <<
2007-10-19 06:31:17 +00:00
" type=\"" << cp << '"' <<
" layers=\"" << ReturnPcbLayerName( topLayer ).Trim().mb_str() << ","
<< ReturnPcbLayerName( botLayer ).Trim().mb_str() << '"' <<
" width=\"" << m_Width << '"' <<
" drill=\"" << m_Drill << '"' <<
" netcode=\"" << GetNet() << "\">" <<
"<pos" << m_Start << "/>";
os << "</" << GetClass().Lower().mb_str() << ">\n";
}
2007-08-09 01:41:30 +00:00
#endif