more cleanup and enhancements about rats nest (work in progress)

This commit is contained in:
charras 2009-05-25 11:53:55 +00:00
parent e073bdc042
commit 3f970c85ce
10 changed files with 349 additions and 408 deletions

View File

@ -56,7 +56,7 @@ set(PCB_COMMON_SRCS
../pcbnew/class_drawsegment.cpp
../pcbnew/class_drc_item.cpp
../pcbnew/class_edge_mod.cpp
../pcbnew/class_equipot.cpp
../pcbnew/class_netinfo_item.cpp
../pcbnew/class_netinfolist.cpp
../pcbnew/class_marker.cpp
../pcbnew/class_mire.cpp

View File

@ -250,7 +250,7 @@ public:
#include "class_edge_mod.h" // Class for footprint graphic elements
#include "class_text_mod.h" // Class for footprint fields
#include "class_module.h" // Class for the footprint
#include "class_equipot.h"
#include "class_netinfo.h" // Class for nets
/***********************************/

View File

@ -286,7 +286,7 @@ public:
void Build_Board_Ratsnest( wxDC* DC );
void DrawGeneralRatsnest( wxDC* DC, int net_code = 0 );
void trace_ratsnest_pad( wxDC* DC );
int* build_ratsnest_pad( EDA_BaseStruct* ref,
void build_ratsnest_pad( BOARD_ITEM* ref,
const wxPoint& refpos,
bool init );

View File

@ -7,7 +7,7 @@
#include "dlist.h"
#include "class_equipot.h"
#include "class_netinfo.h"
class ZONE_CONTAINER;

View File

@ -3,14 +3,14 @@
/*************************************************************************/
#include "fctsys.h"
#include "wxstruct.h"
#include "class_drawpanel.h"
#include "common.h"
#include "kicad_string.h"
#include "pcbnew.h"
/*********************************************************/
/* class NETINFO_ITEM: hand data relative to a given net */
/* class NETINFO_ITEM: handle data relative to a given net */
/*********************************************************/
/* Constructor */
@ -24,7 +24,7 @@ NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent )
}
/* destructot */
/* destructor */
NETINFO_ITEM::~NETINFO_ITEM()
{
@ -107,9 +107,8 @@ void NETINFO_ITEM::SetNetname( const wxString & aNetname )
/** function Draw (TODO)
* we actually could show a NET, simply show all the tracks and pads or net name on pad and vias
*/
void NETINFO_ITEM::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const wxPoint& offset )
void NETINFO_ITEM::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const wxPoint& aOffset )
{
}
@ -169,3 +168,24 @@ void NETINFO_ITEM::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const
valeur_param( (int) lengthnet, txt );
Affiche_1_Parametre( frame, 60, _( "Net Length" ), txt, RED );
}
/***********************/
/* class RATSNEST_ITEM */
/***********************/
/** function Draw
* Draws a line from the starting pad to the ending pad
*/
void RATSNEST_ITEM::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const wxPoint& aOffset )
{
EDA_Colors color = (EDA_Colors) g_DesignSettings.m_RatsnestColor;
if ( (m_Status & LOCAL_RATSNEST_ITEM) )
color = YELLOW;
GRLine( &panel->m_ClipBox, DC, m_PadStart->m_Pos.x + aOffset.x,
m_PadStart->m_Pos.y + aOffset.y,
m_PadEnd->m_Pos.x + aOffset.x,
m_PadEnd->m_Pos.y + aOffset.y,
0, color );
}

View File

@ -86,7 +86,7 @@ TRACK* WinEDA_PcbFrame::Begin_Route( TRACK* aTrack, wxDC* DC )
D_PAD* pt_pad = NULL;
TRACK* TrackOnStartPoint = NULL;
int masquelayer = g_TabOneLayerMask[((PCB_SCREEN*)GetScreen())->m_Active_Layer];
EDA_BaseStruct* LockPoint;
BOARD_ITEM* LockPoint;
wxPoint pos = GetScreen()->m_Curseur;
static int InitialTrackWidthValue; /* first track segment width.
@ -457,7 +457,7 @@ void WinEDA_PcbFrame::End_Route( TRACK* aTrack, wxDC* DC )
* ceci contribue a la reduction du temps de calcul */
/* Accrochage de la fin de la piste */
EDA_BaseStruct* LockPoint = LocateLockPoint( GetBoard(), pos, masquelayer );
BOARD_ITEM* LockPoint = LocateLockPoint( GetBoard(), pos, masquelayer );
if( LockPoint ) /* La fin de la piste est sur un PAD */
{

View File

@ -924,7 +924,7 @@ bool WinEDA_PcbFrame::PlaceDraggedTrackSegment( TRACK* Track, wxDC* DC )
Track->SetState( EDIT, OFF );
Track->Draw( DrawPanel, DC, draw_mode );
/* Tracage des segments dragges */
/* Draw ddragged tracks */
pt_drag = g_DragSegmentList;
for( ; pt_drag; pt_drag = pt_drag->Pnext )
{
@ -954,10 +954,10 @@ bool WinEDA_PcbFrame::PlaceDraggedTrackSegment( TRACK* Track, wxDC* DC )
/************************************************************************/
EDA_BaseStruct* LocateLockPoint( BOARD* Pcb, wxPoint pos, int LayerMask )
BOARD_ITEM* LocateLockPoint( BOARD* Pcb, wxPoint pos, int LayerMask )
/************************************************************************/
/* Routine trouvant le point " d'accrochage " d'une extremite de piste.
/* Routine trouvant le point "d'accrochage" d'une extremite de piste.
* Ce point peut etre un PAD ou un autre segment de piste
* Retourne:
* - pointeur sur ce PAD ou:

View File

@ -353,7 +353,7 @@ void MasqueAttributs( int* masque_set, int* masque_clr );
/* DUPLTRAC.CPP */
/***************/
EDA_BaseStruct* LocateLockPoint( BOARD* Pcb, wxPoint pos, int LayerMask );
BOARD_ITEM* LocateLockPoint( BOARD* Pcb, wxPoint pos, int LayerMask );
/* Routine trouvant le point " d'accrochage " d'une extremite de piste.
* Ce point peut etre un PAD ou un autre segment de piste

View File

@ -291,11 +291,7 @@ static int gen_rats_block_to_block( WinEDA_DrawPanel* DrawPanel, wxDC* DC,
g_pt_chevelu->m_PadEnd = *pt_liste_pad_tmp;
if( DisplayRastnestInProgress && DC )
GRLine( &DrawPanel->m_ClipBox, DC, g_pt_chevelu->m_PadStart->m_Pos.x,
g_pt_chevelu->m_PadStart->m_Pos.y,
g_pt_chevelu->m_PadEnd->m_Pos.x,
g_pt_chevelu->m_PadEnd->m_Pos.y,
0, g_DesignSettings.m_RatsnestColor );
g_pt_chevelu->Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) );
g_pt_chevelu++;
}
@ -339,9 +335,6 @@ static int gen_rats_pad_to_pad( WinEDA_DrawPanel* DrawPanel, wxDC* DC,
pt_start_liste = pt_liste_pad;
if( DC )
GRSetDrawMode( DC, GR_XOR );
for( ; pt_liste_pad < pt_limite; pt_liste_pad++ )
{
ref_pad = *pt_liste_pad;
@ -400,13 +393,8 @@ static int gen_rats_pad_to_pad( WinEDA_DrawPanel* DrawPanel, wxDC* DC,
g_pt_chevelu->m_PadEnd = pad;
if( DisplayRastnestInProgress && DC )
{
GRLine( &DrawPanel->m_ClipBox, DC, g_pt_chevelu->m_PadStart->m_Pos.x,
g_pt_chevelu->m_PadStart->m_Pos.y,
g_pt_chevelu->m_PadEnd->m_Pos.x,
g_pt_chevelu->m_PadEnd->m_Pos.y,
0, g_DesignSettings.m_RatsnestColor );
}
g_pt_chevelu->Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) );
g_pt_chevelu++;
}
}
@ -477,7 +465,8 @@ void WinEDA_BasePcbFrame::Build_Board_Ratsnest( wxDC* DC )
if( m_Pcb->m_NbNodes == 0 )
return; /* pas de connexions utiles */
m_Pcb->m_Ratsnest = (RATSNEST_ITEM*) MyZMalloc( (m_Pcb->m_NbNodes + 10 ) * sizeof(RATSNEST_ITEM) );
m_Pcb->m_Ratsnest =
(RATSNEST_ITEM*) MyZMalloc( (m_Pcb->m_NbNodes + 10 ) * sizeof(RATSNEST_ITEM) );
if( m_Pcb->m_Ratsnest == NULL )
return;
@ -505,8 +494,8 @@ void WinEDA_BasePcbFrame::Build_Board_Ratsnest( wxDC* DC )
/* Compute the ratsnest relative to the current net */
/* a - first pass : create the blocks from not already in block pads */
D_PAD ** pstart = &net->m_ListPad[0];
D_PAD ** pend = pstart + net->m_ListPad.size();
D_PAD** pstart = &net->m_ListPad[0];
D_PAD** pend = pstart + net->m_ListPad.size();
int icnt = gen_rats_pad_to_pad( DrawPanel, DC, pstart, pend,
num_block, &noconn );
@ -530,19 +519,13 @@ void WinEDA_BasePcbFrame::Build_Board_Ratsnest( wxDC* DC )
// erase the ratsnest displayed on screen if needed
RATSNEST_ITEM* Chevelu = m_Pcb->m_Ratsnest;
if( DC )
GRSetDrawMode( DC, GR_XOR );
for( int ii = m_Pcb->GetNumRatsnests(); ii > 0 && Chevelu; ii--, Chevelu++ )
{
if( !g_Show_Ratsnest )
Chevelu->m_Status &= ~CH_VISIBLE;
if( DC )
GRLine( &DrawPanel->m_ClipBox, DC,
Chevelu->m_PadStart->m_Pos.x, Chevelu->m_PadStart->m_Pos.y,
Chevelu->m_PadEnd->m_Pos.x, Chevelu->m_PadEnd->m_Pos.y,
0, g_DesignSettings.m_RatsnestColor );
Chevelu->Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) );
}
}
@ -583,19 +566,13 @@ void WinEDA_BasePcbFrame::DrawGeneralRatsnest( wxDC* DC, int net_code )
if( Chevelu == NULL )
return;
GRSetDrawMode( DC, GR_XOR );
for( ii = m_Pcb->GetNumRatsnests(); ii > 0; Chevelu++, ii-- )
{
if( ( Chevelu->m_Status & (CH_VISIBLE | CH_ACTIF) ) != (CH_VISIBLE | CH_ACTIF) )
continue;
if( (net_code <= 0) || ( net_code == Chevelu->GetNet() ) )
{
GRLine( &DrawPanel->m_ClipBox, DC,
Chevelu->m_PadStart->m_Pos.x, Chevelu->m_PadStart->m_Pos.y,
Chevelu->m_PadEnd->m_Pos.x, Chevelu->m_PadEnd->m_Pos.y,
0, g_DesignSettings.m_RatsnestColor );
}
Chevelu->Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) );
}
}
@ -739,7 +716,7 @@ void WinEDA_BasePcbFrame::Tst_Ratsnest( wxDC* DC, int ref_netcode )
if( m_Pcb->m_Pads.size() == 0 )
return;
if ( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
if( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
Build_Board_Ratsnest( DC );
for( net_code = 1; ; net_code++ )
@ -1039,7 +1016,7 @@ calcul_chevelu_ext:
local_chevelu++;
}
return (char*)(local_chevelu + 1); /* the struct pointed by local_chevelu is used
return (char*) (local_chevelu + 1); /* the struct pointed by local_chevelu is used
* in temporary computations, so we skip it
*/
}
@ -1064,34 +1041,15 @@ void WinEDA_BasePcbFrame::trace_ratsnest_module( wxDC* DC )
local_chevelu = local_liste_chevelu;
ii = nb_local_chevelu;
GRSetDrawMode( DC, GR_XOR );
while( ii-- > 0 )
{
if( local_chevelu->m_Status & LOCAL_RATSNEST_ITEM )
{
GRLine( &DrawPanel->m_ClipBox, DC,
local_chevelu->m_PadStart->m_Pos.x - g_Offset_Module.x,
local_chevelu->m_PadStart->m_Pos.y - g_Offset_Module.y,
local_chevelu->m_PadEnd->m_Pos.x - g_Offset_Module.x,
local_chevelu->m_PadEnd->m_Pos.y - g_Offset_Module.y,
0, YELLOW );
}
else
{
GRLine( &DrawPanel->m_ClipBox, DC,
local_chevelu->m_PadStart->m_Pos.x - g_Offset_Module.x,
local_chevelu->m_PadStart->m_Pos.y - g_Offset_Module.y,
local_chevelu->m_PadEnd->m_Pos.x,
local_chevelu->m_PadEnd->m_Pos.y,
0, g_DesignSettings.m_RatsnestColor );
}
local_chevelu->Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) );
local_chevelu++;
}
}
/**
/*
* construction de la liste en mode de calcul rapide pour affichage
* en temps reel du chevelu d'un pad lors des tracés d'une piste démarrant
* sur ce pad.
@ -1102,61 +1060,53 @@ void WinEDA_BasePcbFrame::trace_ratsnest_module( wxDC* DC )
* init (flag)
* = 0 : mise a jour des chevelu
* <> 0: creation de la liste
* retourne: adresse memoire disponible
*/
/* Used by build_ratsnest_pad(): sort function by link lenght (manathan distance)*/
static int sort_by_localnetlength( const void* o1, const void* o2 )
/* Buffer to store pads coordinates when creating a track.
* these pads are members of the net
* and when the mouse is moved, the g_MaxLinksShowed links to neightbors are drawn
*/
static std::vector <wxPoint> s_RatsnestMouseToPads;
static wxPoint s_CursorPos; // Coordinate of the moving point (mouse cursor and end of current track segment)
/* Used by build_ratsnest_pad(): sort function by link lenght (manhattan distance)*/
static bool sort_by_localnetlength( const wxPoint& ref, const wxPoint& compare )
{
int* ref = (int*) o1;
int* compare = (int*) o2;
wxPoint deltaref = ref - s_CursorPos;
wxPoint deltacmp = compare - s_CursorPos;
int* org = (int*) adr_lowmem; // ref coordinate (todo : change for a betted code: used an external wxPoint variable)
int ox = *org++;
int oy = *org++;
int lengthref, lengthcmp;
// = distance between ref coordinate and pad ref
int lengthref = abs( deltaref.x ) + abs( deltaref.y );
lengthref = abs( *ref - ox );
ref++;
// distance between ref coordinate and the other pad
int lengthcmp = abs( deltacmp.x ) + abs( deltacmp.y );
lengthref += abs( *ref - oy ); // = distance between ref coordinate and pad ref
lengthcmp = abs( *compare - ox );
compare++;
lengthcmp += abs( *compare - oy ); // = distance between ref coordinate and the other pad
return lengthref - lengthcmp;
return lengthref < lengthcmp;
}
/****************************************************************************************/
int* WinEDA_BasePcbFrame::build_ratsnest_pad( EDA_BaseStruct* ref,
void WinEDA_BasePcbFrame::build_ratsnest_pad( BOARD_ITEM* ref,
const wxPoint& refpos, bool init )
/****************************************************************************************/
{
int ii;
int* pt_coord, * base_data;
int current_net_code = 0, conn_number = 0;
D_PAD** padlist;
D_PAD* pad_ref = NULL;
if( ( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
|| ( (m_Pcb->m_Status_Pcb & LISTE_PAD_OK) == 0 ) )
|| ( (m_Pcb->m_Status_Pcb & LISTE_PAD_OK) == 0 ) || ( (m_Pcb->m_Status_Pcb & NET_CODES_OK) == 0 ) )
{
nb_local_chevelu = 0;
return NULL;
s_RatsnestMouseToPads.clear();
return;
}
base_data = pt_coord = (int*) adr_lowmem;
local_liste_chevelu = (RATSNEST_ITEM*) pt_coord;
s_CursorPos = refpos;
if( init )
{
nb_local_chevelu = 0;
s_RatsnestMouseToPads.clear();
if( ref == NULL )
return NULL;
return;
switch( ref->Type() )
{
@ -1180,41 +1130,26 @@ int* WinEDA_BasePcbFrame::build_ratsnest_pad( EDA_BaseStruct* ref,
}
if( current_net_code <= 0 )
return NULL;
return;
*pt_coord++ = refpos.x;
*pt_coord++ = refpos.y;
NETINFO_ITEM * net = m_Pcb->FindNet(current_net_code);
if ( net == NULL )
return;
if( m_Pcb->m_Ratsnest == NULL )
return NULL;
padlist = &m_Pcb->m_Pads[0];
for( ii = 0; ii < (int) m_Pcb->m_Pads.size(); padlist++, ii++ )
// Create a list of pads candidates ( pads not already connected to the current track:
for( unsigned ii = 0; ii < net->m_ListPad.size(); ii++ )
{
D_PAD* pad = *padlist;
if( pad->GetNet() != current_net_code )
continue;
D_PAD* pad = net->m_ListPad[ii];
if( pad == pad_ref )
continue;
if( !pad->GetSubNet() || (pad->GetSubNet() != conn_number) )
{
*pt_coord = pad->m_Pos.x; pt_coord++;
*pt_coord = pad->m_Pos.y; pt_coord++;
nb_local_chevelu++;
}
s_RatsnestMouseToPads.push_back( pad->m_Pos );
}
} /* end if Init */
else if( nb_local_chevelu )
{
*pt_coord = refpos.x;
*(pt_coord + 1) = refpos.y;
}
qsort( base_data + 2, nb_local_chevelu, 2 * sizeof(int),
sort_by_localnetlength );
return pt_coord;
if( s_RatsnestMouseToPads.size() > 1)
sort( s_RatsnestMouseToPads.begin(), s_RatsnestMouseToPads.end(), sort_by_localnetlength );
}
@ -1226,35 +1161,21 @@ void WinEDA_BasePcbFrame::trace_ratsnest_pad( wxDC* DC )
* Displays a "ratsnest" during track creation
*/
{
int* pt_coord;
int ii;
int refX, refY;
if( DC == NULL )
return;
if( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
if( s_RatsnestMouseToPads.size() == 0)
return;
if( nb_local_chevelu == 0 )
return;
if( local_liste_chevelu == NULL )
return;
pt_coord = (int*) local_liste_chevelu;
refX = *pt_coord++;
refY = *pt_coord++;
GRSetDrawMode( DC, GR_XOR );
for( ii = 0; ii < nb_local_chevelu; ii++ )
for( int ii = 0; ii < (int)s_RatsnestMouseToPads.size(); ii++ )
{
if( ii >= g_MaxLinksShowed )
break;
GRLine( &DrawPanel->m_ClipBox, DC, refX, refY, *pt_coord, *(pt_coord + 1),
GRLine( &DrawPanel->m_ClipBox, DC, s_CursorPos.x, s_CursorPos.y,
s_RatsnestMouseToPads[ii].x, s_RatsnestMouseToPads[ii].y,
0, YELLOW );
pt_coord += 2;
}
}