2014-10-23 17:53:38 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file ratsnest.cpp
|
|
|
|
* @brief Ratsnets functions.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <wxBasePcbFrame.h>
|
2013-05-02 18:06:58 +00:00
|
|
|
#include <macros.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_track.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
#include <connectivity.h>
|
|
|
|
#include <ratsnest_data.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-03-22 15:47:15 +00:00
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Compile_Ratsnest
|
2009-11-20 14:55:20 +00:00
|
|
|
* Create the entire board ratsnest.
|
2007-10-13 12:17:17 +00:00
|
|
|
* Must be called after a board change (changes for
|
|
|
|
* pads, footprints or a read netlist ).
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aDC = the current device context (can be NULL)
|
|
|
|
* @param aDisplayStatus : if true, display the computation results
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_BASE_FRAME::Compile_Ratsnest( wxDC* aDC, bool aDisplayStatus )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
GetBoard()->GetConnectivity()->RecalculateRatsnest();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0; // we want a full ratsnest computation, from the scratch
|
2009-06-05 15:57:41 +00:00
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
if( GetBoard()->IsElementVisible( LAYER_RATSNEST ) && aDC )
|
2017-03-22 13:51:07 +00:00
|
|
|
DrawGeneralRatsnest( aDC, 0 );
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
ClearMsgPanel();
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aDisplayStatus )
|
2009-05-24 18:28:36 +00:00
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
msg.Printf( wxT( " %d" ), m_Pcb->GetConnectivity()->GetPadCount() );
|
2011-04-12 14:19:59 +00:00
|
|
|
AppendMsgPanel( wxT( "Pads" ), msg, RED );
|
2017-03-22 13:51:07 +00:00
|
|
|
msg.Printf( wxT( " %d" ), m_Pcb->GetConnectivity()->GetNetCount() );
|
2011-04-12 14:19:59 +00:00
|
|
|
AppendMsgPanel( wxT( "Nets" ), msg, CYAN );
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( m_Pcb );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
/**
|
2011-11-07 18:04:19 +00:00
|
|
|
* function DrawGeneralRatsnest
|
|
|
|
* Only ratsnest items with the status bit CH_VISIBLE set are displayed
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aDC = the current device context (can be NULL)
|
2011-11-07 18:04:19 +00:00
|
|
|
* @param aNetcode: if > 0, Display only the ratsnest relative to the
|
2009-11-20 14:55:20 +00:00
|
|
|
* corresponding net_code
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_BASE_FRAME::DrawGeneralRatsnest( wxDC* aDC, int aNetcode )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
if( ( m_Pcb->m_Status_Pcb & DO_NOT_SHOW_GENERAL_RASTNEST ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
return;
|
2009-05-24 18:28:36 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
if( aDC == NULL )
|
|
|
|
return;
|
2011-09-15 17:58:35 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
auto connectivity = m_Pcb->GetConnectivity();
|
2009-05-28 08:42:24 +00:00
|
|
|
|
2017-08-04 12:43:02 +00:00
|
|
|
COLOR4D color = Settings().Colors().GetItemColor( LAYER_RATSNEST );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
for( int i = 1; i < connectivity->GetNetCount(); ++i )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2017-03-28 16:30:49 +00:00
|
|
|
RN_NET* net = connectivity->GetRatsnestForNet( i );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-06-29 22:45:50 +00:00
|
|
|
if( !net )
|
|
|
|
continue;
|
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
if( ( aNetcode <= 0 ) || ( aNetcode == i ) )
|
|
|
|
{
|
|
|
|
for( const auto& edge : net->GetEdges() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2017-03-28 16:30:49 +00:00
|
|
|
auto s = edge.GetSourcePos();
|
|
|
|
auto d = edge.GetTargetPos();
|
|
|
|
auto sn = edge.GetSourceNode();
|
|
|
|
auto dn = edge.GetTargetNode();
|
|
|
|
|
|
|
|
bool enable = !sn->GetNoLine() && !dn->GetNoLine();
|
|
|
|
bool show = sn->Parent()->GetLocalRatsnestVisible()
|
|
|
|
|| dn->Parent()->GetLocalRatsnestVisible();
|
|
|
|
|
|
|
|
if( enable && show )
|
|
|
|
GRLine( m_canvas->GetClipBox(), aDC, wxPoint( s.x, s.y ), wxPoint( d.x,
|
|
|
|
d.y ), 0, color );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2017-03-28 16:30:49 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
void PCB_BASE_FRAME::TraceModuleRatsNest( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
if( DC == NULL )
|
2008-03-22 18:08:44 +00:00
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-08-04 12:43:02 +00:00
|
|
|
COLOR4D tmpcolor = Settings().Colors().GetItemColor( LAYER_RATSNEST );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
for( const auto& l : GetBoard()->GetConnectivity()->GetDynamicRatsnest() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2017-03-28 16:30:49 +00:00
|
|
|
GRLine( m_canvas->GetClipBox(), DC, wxPoint( l.a.x, l.a.y ), wxPoint( l.b.x,
|
|
|
|
l.b.y ), 0, tmpcolor );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 11:53:55 +00:00
|
|
|
/*
|
2011-11-10 08:21:11 +00:00
|
|
|
* PCB_BASE_FRAME::BuildAirWiresTargetsList and
|
|
|
|
* PCB_BASE_FRAME::TraceAirWiresToTargets
|
|
|
|
* are 2 function to show the near connecting points when
|
|
|
|
* a new track is created, by displaying g_MaxLinksShowed airwires
|
|
|
|
* between the on grid mouse cursor and these connecting points
|
|
|
|
* during the creation of a track
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-05-25 11:53:55 +00:00
|
|
|
/* Buffer to store pads coordinates when creating a track.
|
|
|
|
* these pads are members of the net
|
2009-11-20 14:55:20 +00:00
|
|
|
* and when the mouse is moved, the g_MaxLinksShowed links to neighbors are
|
|
|
|
* drawn
|
2009-05-25 11:53:55 +00:00
|
|
|
*/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
static wxPoint s_CursorPos; // Coordinate of the moving point (mouse cursor and
|
|
|
|
// end of current track segment)
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
/* Function BuildAirWiresTargetsList
|
|
|
|
* Build a list of candidates that can be a coonection point
|
|
|
|
* when a track is started.
|
|
|
|
* This functions prepares data to show airwires to nearest connecting points (pads)
|
|
|
|
* from the current new track to candidates during track creation
|
|
|
|
*/
|
2017-03-22 13:51:07 +00:00
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
static BOARD_CONNECTED_ITEM* s_ref = nullptr;
|
2017-03-22 13:51:07 +00:00
|
|
|
static int s_refNet = -1;
|
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
void PCB_BASE_FRAME::BuildAirWiresTargetsList( BOARD_CONNECTED_ITEM* aItemRef,
|
2017-03-28 16:30:49 +00:00
|
|
|
const wxPoint& aPosition, int aNet )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-08 16:18:46 +00:00
|
|
|
s_CursorPos = aPosition; // needed for sort_by_distance
|
2017-03-22 13:51:07 +00:00
|
|
|
s_ref = aItemRef;
|
|
|
|
s_refNet = aNet;
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
static MODULE movedModule( nullptr );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2017-06-25 09:26:04 +00:00
|
|
|
void PCB_BASE_FRAME::build_ratsnest_module( MODULE* aModule, wxPoint aMoveVector )
|
2017-03-22 13:51:07 +00:00
|
|
|
{
|
|
|
|
auto connectivity = GetBoard()->GetConnectivity();
|
2017-03-28 16:30:49 +00:00
|
|
|
|
2017-06-25 09:26:04 +00:00
|
|
|
movedModule = *aModule;
|
2017-03-22 13:51:07 +00:00
|
|
|
movedModule.Move( -aMoveVector );
|
|
|
|
connectivity->ClearDynamicRatsnest();
|
2017-06-25 09:26:04 +00:00
|
|
|
connectivity->BlockRatsnestItems( { aModule } );
|
2017-03-28 16:30:49 +00:00
|
|
|
connectivity->ComputeDynamicRatsnest( { &movedModule } );
|
2017-03-22 13:51:07 +00:00
|
|
|
}
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2009-05-25 16:07:33 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
void PCB_BASE_FRAME::TraceAirWiresToTargets( wxDC* aDC )
|
|
|
|
{
|
|
|
|
auto connectivity = GetBoard()->GetConnectivity();
|
2017-10-30 17:21:07 +00:00
|
|
|
auto displ_opts = (PCB_DISPLAY_OPTIONS*) GetDisplayOptions();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
auto targets = connectivity->NearestUnconnectedTargets( s_ref, s_CursorPos, s_refNet );
|
2011-11-08 16:18:46 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
if( aDC == NULL )
|
|
|
|
return;
|
2011-11-08 16:18:46 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
GRSetDrawMode( aDC, GR_XOR );
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
for( int i = 0; i < std::min( (int) displ_opts->m_MaxLinksShowed, (int) targets.size() ); i++ )
|
2017-03-22 13:51:07 +00:00
|
|
|
{
|
|
|
|
auto p = targets[i];
|
2017-03-28 16:30:49 +00:00
|
|
|
GRLine( m_canvas->GetClipBox(), aDC, s_CursorPos, wxPoint( p.x, p.y ), 0, YELLOW );
|
2017-03-22 13:51:07 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-19 04:02:19 +00:00
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
// Redraw in XOR mode the outlines of the module.
|
|
|
|
void MODULE::DrawOutlinesWhenMoving( EDA_DRAW_PANEL* panel, wxDC* DC,
|
2017-03-28 16:30:49 +00:00
|
|
|
const wxPoint& aMoveVector )
|
2017-03-22 13:51:07 +00:00
|
|
|
{
|
2017-03-28 16:30:49 +00:00
|
|
|
int pad_fill_tmp;
|
2017-03-22 13:51:07 +00:00
|
|
|
D_PAD* pt_pad;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
DrawEdgesOnly( panel, DC, aMoveVector, GR_XOR );
|
2017-10-30 17:21:07 +00:00
|
|
|
auto displ_opts = (PCB_DISPLAY_OPTIONS*) ( panel->GetDisplayOptions() );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
// Show pads in sketch mode to speedu up drawings
|
|
|
|
pad_fill_tmp = displ_opts->m_DisplayPadFill;
|
|
|
|
displ_opts->m_DisplayPadFill = true;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2017-04-25 09:06:24 +00:00
|
|
|
pt_pad = PadsList();
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
for( ; pt_pad != NULL; pt_pad = pt_pad->Next() )
|
|
|
|
pt_pad->Draw( panel, DC, GR_XOR, aMoveVector );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
displ_opts->m_DisplayPadFill = pad_fill_tmp;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
if( displ_opts->m_Show_Module_Ratsnest )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) panel->GetParent();
|
|
|
|
frame->build_ratsnest_module( this, aMoveVector );
|
|
|
|
frame->TraceModuleRatsNest( DC );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2017-03-22 15:47:15 +00:00
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
|
2017-03-22 15:47:15 +00:00
|
|
|
void PCB_EDIT_FRAME::Show_1_Ratsnest( EDA_ITEM* item, wxDC* DC )
|
|
|
|
{
|
2017-07-03 09:06:44 +00:00
|
|
|
if( item && item->Type() == PCB_MODULE_T )
|
2017-03-22 15:47:15 +00:00
|
|
|
{
|
2017-03-28 16:30:49 +00:00
|
|
|
auto mod = static_cast<MODULE*> (item);
|
2017-03-22 15:47:15 +00:00
|
|
|
|
2017-04-25 09:06:24 +00:00
|
|
|
for( auto pad : mod->Pads() )
|
2017-03-22 15:47:15 +00:00
|
|
|
{
|
2017-03-28 16:30:49 +00:00
|
|
|
pad->SetLocalRatsnestVisible( true );
|
2017-03-22 15:47:15 +00:00
|
|
|
}
|
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
m_canvas->Refresh();
|
2017-03-22 15:47:15 +00:00
|
|
|
}
|
|
|
|
}
|