2015-02-18 00:29:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wx/numdlg.h>
|
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
#include "class_draw_panel_gal.h"
|
|
|
|
#include "class_board.h"
|
|
|
|
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <id.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <pcbnew_id.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <pcbcommon.h>
|
|
|
|
#include <pcb_painter.h>
|
|
|
|
#include <dialogs/dialog_pns_settings.h>
|
|
|
|
#include <dialogs/dialog_pns_diff_pair_dimensions.h>
|
|
|
|
#include <dialogs/dialog_pns_length_tuning_settings.h>
|
|
|
|
#include <dialogs/dialog_track_via_size.h>
|
|
|
|
#include <base_units.h>
|
|
|
|
|
|
|
|
#include <tool/context_menu.h>
|
|
|
|
#include <tools/common_actions.h>
|
2015-11-03 16:19:42 +00:00
|
|
|
#include <tools/grid_helper.h>
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
#include <ratsnest_data.h>
|
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
#include "pns_kicad_iface.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
#include "pns_tool_base.h"
|
|
|
|
#include "pns_segment.h"
|
2016-08-15 15:16:51 +00:00
|
|
|
#include "pns_solid.h"
|
|
|
|
#include "pns_via.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
#include "pns_router.h"
|
|
|
|
#include "pns_meander_placer.h" // fixme: move settings to separate header
|
|
|
|
#include "pns_tune_status_popup.h"
|
2016-08-15 15:16:47 +00:00
|
|
|
#include "pns_topology.h"
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
using namespace KIGFX;
|
|
|
|
|
|
|
|
TOOL_ACTION PNS_TOOL_BASE::ACT_RouterOptions( "pcbnew.InteractiveRouter.RouterOptions",
|
|
|
|
AS_CONTEXT, 'E',
|
2015-04-05 16:01:50 +00:00
|
|
|
_( "Routing Options..." ),
|
2015-05-03 18:43:07 +00:00
|
|
|
_( "Shows a dialog containing router options." ), tools_xpm );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
PNS_TOOL_BASE::PNS_TOOL_BASE( const std::string& aToolName ) :
|
|
|
|
TOOL_INTERACTIVE( aToolName )
|
|
|
|
{
|
2016-08-17 13:09:48 +00:00
|
|
|
m_gridHelper = NULL;
|
|
|
|
m_iface = NULL;
|
2015-02-18 00:29:54 +00:00
|
|
|
m_router = NULL;
|
2016-08-17 13:09:48 +00:00
|
|
|
|
2015-03-10 14:38:27 +00:00
|
|
|
m_startItem = NULL;
|
|
|
|
m_startLayer = 0;
|
|
|
|
|
|
|
|
m_endItem = NULL;
|
|
|
|
|
|
|
|
m_frame = NULL;
|
|
|
|
m_ctls = NULL;
|
|
|
|
m_board = NULL;
|
2015-11-03 16:19:42 +00:00
|
|
|
m_gridHelper = NULL;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PNS_TOOL_BASE::~PNS_TOOL_BASE()
|
|
|
|
{
|
2015-11-03 16:19:42 +00:00
|
|
|
delete m_gridHelper;
|
2016-08-17 13:09:48 +00:00
|
|
|
delete m_iface;
|
|
|
|
delete m_router;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-03 16:19:42 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
void PNS_TOOL_BASE::Reset( RESET_REASON aReason )
|
|
|
|
{
|
2016-08-17 13:09:48 +00:00
|
|
|
delete m_gridHelper;
|
|
|
|
delete m_iface;
|
|
|
|
delete m_router;
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_frame = getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
m_ctls = getViewControls();
|
|
|
|
m_board = getModel<BOARD>();
|
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
m_iface = new PNS_KICAD_IFACE;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
m_iface->SetBoard( m_board );
|
2016-08-15 15:16:47 +00:00
|
|
|
m_iface->SetView( getView() );
|
2016-08-15 15:16:53 +00:00
|
|
|
m_iface->SetHostFrame( m_frame );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
m_router = new PNS_ROUTER;
|
|
|
|
m_router->SetInterface(m_iface);
|
2015-02-18 00:29:54 +00:00
|
|
|
m_router->ClearWorld();
|
|
|
|
m_router->SyncWorld();
|
|
|
|
m_router->LoadSettings( m_savedSettings );
|
|
|
|
m_router->UpdateSizes( m_savedSizes );
|
2015-11-03 16:19:42 +00:00
|
|
|
|
|
|
|
m_gridHelper = new GRID_HELPER( m_frame );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_ITEM* PNS_TOOL_BASE::pickSingleItem( const VECTOR2I& aWhere, int aNet, int aLayer )
|
|
|
|
{
|
|
|
|
int tl = getView()->GetTopLayer();
|
|
|
|
|
|
|
|
if( aLayer > 0 )
|
|
|
|
tl = aLayer;
|
|
|
|
|
|
|
|
PNS_ITEM* prioritized[4];
|
|
|
|
|
|
|
|
for( int i = 0; i < 4; i++ )
|
|
|
|
prioritized[i] = 0;
|
|
|
|
|
|
|
|
PNS_ITEMSET candidates = m_router->QueryHoverItems( aWhere );
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_ITEM* item : candidates.Items() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( !IsCopperLayer( item->Layers().Start() ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// fixme: this causes flicker with live loop removal...
|
|
|
|
//if( item->Parent() && !item->Parent()->ViewIsVisible() )
|
|
|
|
// continue;
|
|
|
|
|
|
|
|
if( aNet < 0 || item->Net() == aNet )
|
|
|
|
{
|
|
|
|
if( item->OfKind( PNS_ITEM::VIA | PNS_ITEM::SOLID ) )
|
|
|
|
{
|
|
|
|
if( !prioritized[2] )
|
|
|
|
prioritized[2] = item;
|
|
|
|
if( item->Layers().Overlaps( tl ) )
|
|
|
|
prioritized[0] = item;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !prioritized[3] )
|
|
|
|
prioritized[3] = item;
|
|
|
|
if( item->Layers().Overlaps( tl ) )
|
|
|
|
prioritized[1] = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PNS_ITEM* rv = NULL;
|
2015-02-18 16:53:46 +00:00
|
|
|
PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>();
|
2015-02-18 00:29:54 +00:00
|
|
|
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)frame->GetDisplayOptions();
|
|
|
|
|
|
|
|
for( int i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
PNS_ITEM* item = prioritized[i];
|
|
|
|
|
|
|
|
if( displ_opts->m_ContrastModeDisplay )
|
|
|
|
if( item && !item->Layers().Overlaps( tl ) )
|
|
|
|
item = NULL;
|
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
rv = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( rv && aLayer >= 0 && !rv->Layers().Overlaps( aLayer ) )
|
|
|
|
rv = NULL;
|
|
|
|
|
|
|
|
if( rv )
|
2016-08-17 14:00:21 +00:00
|
|
|
{
|
|
|
|
wxLogTrace( "PNS", "%s, layer : %d, tl: %d", rv->KindStr().c_str(), rv->Layers().Start(), tl );
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PNS_TOOL_BASE::highlightNet( bool aEnabled, int aNetcode )
|
|
|
|
{
|
|
|
|
RENDER_SETTINGS* rs = getView()->GetPainter()->GetSettings();
|
|
|
|
|
|
|
|
if( aNetcode >= 0 && aEnabled )
|
|
|
|
rs->SetHighlight( true, aNetcode );
|
|
|
|
else
|
|
|
|
rs->SetHighlight( false );
|
|
|
|
|
|
|
|
getView()->UpdateAllLayersColor();
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
void PNS_TOOL_BASE::updateStartItem( TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
int tl = getView()->GetTopLayer();
|
|
|
|
VECTOR2I cp = m_ctls->GetCursorPosition();
|
2015-08-04 09:37:16 +00:00
|
|
|
VECTOR2I p;
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_ITEM* startItem = NULL;
|
2015-08-04 09:37:16 +00:00
|
|
|
bool snapEnabled = true;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
if( aEvent.IsMotion() || aEvent.IsClick() )
|
|
|
|
{
|
2015-08-04 09:37:16 +00:00
|
|
|
snapEnabled = !aEvent.Modifier( MD_SHIFT );
|
|
|
|
p = aEvent.Position();
|
2016-08-15 15:16:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-04 09:37:16 +00:00
|
|
|
p = cp;
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-08-04 09:37:16 +00:00
|
|
|
startItem = pickSingleItem( p );
|
2016-08-15 15:16:53 +00:00
|
|
|
m_router->EnableSnapping( snapEnabled );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-08-04 09:37:16 +00:00
|
|
|
if( !snapEnabled && startItem && !startItem->Layers().Overlaps( tl ) )
|
|
|
|
startItem = NULL;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-08-04 09:37:16 +00:00
|
|
|
if( startItem && startItem->Net() >= 0 )
|
|
|
|
{
|
|
|
|
bool dummy;
|
2016-08-15 15:16:51 +00:00
|
|
|
VECTOR2I psnap = snapToItem( startItem, p, dummy );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-08-04 09:37:16 +00:00
|
|
|
if( snapEnabled )
|
|
|
|
{
|
|
|
|
m_startSnapPoint = psnap;
|
|
|
|
m_ctls->ForceCursorPosition( true, psnap );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_startSnapPoint = cp;
|
|
|
|
m_ctls->ForceCursorPosition( false );
|
|
|
|
}
|
2015-08-04 09:37:16 +00:00
|
|
|
|
|
|
|
m_startItem = startItem;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_startItem = NULL;
|
|
|
|
m_startSnapPoint = cp;
|
|
|
|
m_ctls->ForceCursorPosition( false );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
void PNS_TOOL_BASE::updateEndItem( TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
VECTOR2I mp = m_ctls->GetMousePosition();
|
|
|
|
VECTOR2I p = getView()->ToWorld( mp );
|
|
|
|
VECTOR2I cp = m_ctls->GetCursorPosition();
|
|
|
|
int layer;
|
2015-07-02 14:10:07 +00:00
|
|
|
bool snapEnabled = !aEvent.Modifier( MD_SHIFT );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
m_router->EnableSnapping( snapEnabled );
|
|
|
|
|
2015-08-21 14:35:34 +00:00
|
|
|
if( m_router->GetCurrentNets().empty() || m_router->GetCurrentNets().front() < 0 )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_endItem = NULL;
|
|
|
|
m_endSnapPoint = cp;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool dummy;
|
|
|
|
|
|
|
|
if( m_router->IsPlacingVia() )
|
|
|
|
layer = -1;
|
|
|
|
else
|
|
|
|
layer = m_router->GetCurrentLayer();
|
|
|
|
|
2015-08-21 14:35:34 +00:00
|
|
|
PNS_ITEM* endItem = NULL;
|
|
|
|
|
|
|
|
std::vector<int> nets = m_router->GetCurrentNets();
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( int net : nets )
|
2015-08-21 14:35:34 +00:00
|
|
|
{
|
|
|
|
endItem = pickSingleItem( p, net, layer );
|
|
|
|
|
|
|
|
if( endItem )
|
|
|
|
break;
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
if( endItem )
|
|
|
|
{
|
2016-08-15 15:16:51 +00:00
|
|
|
VECTOR2I cursorPos = snapToItem( endItem, p, dummy );
|
2015-02-18 00:29:54 +00:00
|
|
|
m_ctls->ForceCursorPosition( true, cursorPos );
|
|
|
|
m_endItem = endItem;
|
|
|
|
m_endSnapPoint = cursorPos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_endItem = NULL;
|
|
|
|
m_endSnapPoint = cp;
|
|
|
|
m_ctls->ForceCursorPosition( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_endItem )
|
2016-08-17 14:00:21 +00:00
|
|
|
{
|
|
|
|
wxLogTrace( "PNS", "%s, layer : %d", m_endItem->KindStr().c_str(), m_endItem->Layers().Start() );
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
|
|
|
void PNS_TOOL_BASE::deleteTraces( PNS_ITEM* aStartItem, bool aWholeTrack )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
PNS_NODE *node = m_router->GetWorld()->Branch();
|
|
|
|
|
|
|
|
if( !aStartItem )
|
|
|
|
return;
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
if( !aWholeTrack )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
node->Remove( aStartItem );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
PNS_TOPOLOGY topo( node );
|
2016-08-15 15:16:47 +00:00
|
|
|
PNS_ITEMSET path = topo.AssembleTrivialPath( aStartItem );
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
for( auto ent : path.Items() )
|
2016-08-15 15:16:47 +00:00
|
|
|
node->Remove( ent.item );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_router->CommitRouting( node );
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
PNS_ROUTER *PNS_TOOL_BASE::Router() const
|
|
|
|
{
|
|
|
|
return m_router;
|
|
|
|
}
|
2016-08-15 15:16:51 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-15 15:16:51 +00:00
|
|
|
const VECTOR2I PNS_TOOL_BASE::snapToItem( PNS_ITEM* aItem, VECTOR2I aP, bool& aSplitsSegment )
|
|
|
|
{
|
|
|
|
VECTOR2I anchor;
|
|
|
|
|
|
|
|
if( !aItem )
|
|
|
|
{
|
|
|
|
aSplitsSegment = false;
|
|
|
|
return aP;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( aItem->Kind() )
|
|
|
|
{
|
|
|
|
case PNS_ITEM::SOLID:
|
|
|
|
anchor = static_cast<PNS_SOLID*>( aItem )->Pos();
|
|
|
|
aSplitsSegment = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS_ITEM::VIA:
|
|
|
|
anchor = static_cast<PNS_VIA*>( aItem )->Pos();
|
|
|
|
aSplitsSegment = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS_ITEM::SEGMENT:
|
|
|
|
{
|
|
|
|
PNS_SEGMENT* seg = static_cast<PNS_SEGMENT*>( aItem );
|
|
|
|
const SEG& s = seg->Seg();
|
|
|
|
int w = seg->Width();
|
|
|
|
|
|
|
|
aSplitsSegment = false;
|
|
|
|
|
|
|
|
if( ( aP - s.A ).EuclideanNorm() < w / 2 )
|
|
|
|
anchor = s.A;
|
|
|
|
else if( ( aP - s.B ).EuclideanNorm() < w / 2 )
|
|
|
|
anchor = s.B;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
anchor = s.NearestPoint( aP );
|
|
|
|
aSplitsSegment = true;
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
anchor = m_gridHelper->AlignToSegment( aP, s );
|
|
|
|
aSplitsSegment = ( anchor != s.A && anchor != s.B );
|
2016-08-15 15:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return anchor;
|
|
|
|
}
|