PNS: Check for nearest segment anchor for initial track constraints
(Based on cherry-pick from commit c39551b032)
This commit is contained in:
@@ -646,7 +646,7 @@ bool PNS_KICAD_IFACE_BASE::inheritTrackWidth( PNS::ITEM* aItem, int* aInheritedW
|
||||
|
||||
|
||||
bool PNS_KICAD_IFACE_BASE::ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM* aStartItem,
|
||||
PNS::NET_HANDLE aNet )
|
||||
PNS::NET_HANDLE aNet, VECTOR2D aStartPosition )
|
||||
{
|
||||
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
||||
PNS::CONSTRAINT constraint;
|
||||
@@ -658,10 +658,29 @@ bool PNS_KICAD_IFACE_BASE::ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM*
|
||||
aSizes.SetMinClearance( bds.m_MinClearance );
|
||||
aSizes.SetClearanceSource( _( "board minimum clearance" ) );
|
||||
|
||||
int startAnchor = 0;
|
||||
VECTOR2I startPosInt( aStartPosition.x, aStartPosition.y );
|
||||
|
||||
if( aStartItem && aStartItem->Kind() == PNS::ITEM::SEGMENT_T )
|
||||
{
|
||||
// Find the start anchor which is closest to the start mouse location
|
||||
VECTOR2I anchor0 = aStartItem->Anchor( 0 );
|
||||
VECTOR2I anchor1 = aStartItem->Anchor( 1 );
|
||||
|
||||
VECTOR2<double> diff0( anchor0.x - startPosInt.x, anchor0.y - startPosInt.y );
|
||||
VECTOR2<double> diff1( anchor1.x - startPosInt.x, anchor1.y - startPosInt.y );
|
||||
|
||||
double anchor0Distance = diff0.EuclideanNorm();
|
||||
double anchor1Distance = diff1.EuclideanNorm();
|
||||
|
||||
if( anchor1Distance < anchor0Distance )
|
||||
startAnchor = 1;
|
||||
}
|
||||
|
||||
if( aStartItem )
|
||||
{
|
||||
PNS::SEGMENT dummyTrack;
|
||||
dummyTrack.SetEnds( aStartItem->Anchor( 0 ), aStartItem->Anchor( 0 ) );
|
||||
dummyTrack.SetEnds( aStartItem->Anchor( startAnchor ), aStartItem->Anchor( startAnchor ) );
|
||||
dummyTrack.SetLayer( ToLAYER_ID( m_startLayer ) );
|
||||
dummyTrack.SetNet( static_cast<NETINFO_ITEM*>( aStartItem->Net() ) );
|
||||
|
||||
@@ -691,7 +710,7 @@ bool PNS_KICAD_IFACE_BASE::ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM*
|
||||
if( !found && bds.UseNetClassTrack() && aStartItem )
|
||||
{
|
||||
PNS::SEGMENT dummyTrack;
|
||||
dummyTrack.SetEnds( aStartItem->Anchor( 0 ), aStartItem->Anchor( 0 ) );
|
||||
dummyTrack.SetEnds( aStartItem->Anchor( startAnchor ), aStartItem->Anchor( startAnchor ) );
|
||||
dummyTrack.SetLayer( ToLAYER_ID( m_startLayer ) );
|
||||
dummyTrack.SetNet( static_cast<NETINFO_ITEM*>( aStartItem->Net() ) );
|
||||
|
||||
|
||||
@@ -70,8 +70,8 @@ public:
|
||||
void UpdateItem( PNS::ITEM* aItem ) override;
|
||||
void RemoveItem( PNS::ITEM* aItem ) override;
|
||||
void Commit() override {}
|
||||
bool ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM* aStartItem,
|
||||
PNS::NET_HANDLE aNet ) override;
|
||||
bool ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM* aStartItem, PNS::NET_HANDLE aNet,
|
||||
VECTOR2D aStartPosition ) override;
|
||||
int StackupHeight( int aFirstLayer, int aSecondLayer ) const override;
|
||||
|
||||
int GetNetCode( PNS::NET_HANDLE aNet ) const override { return -1; }
|
||||
|
||||
@@ -103,7 +103,8 @@ enum DRAG_MODE
|
||||
virtual void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, NET_HANDLE aNetCode ) = 0;
|
||||
virtual void HideItem( ITEM* aItem ) = 0;
|
||||
virtual void Commit() = 0;
|
||||
virtual bool ImportSizes( SIZES_SETTINGS& aSizes, ITEM* aStartItem, NET_HANDLE aNet ) = 0;
|
||||
virtual bool ImportSizes( SIZES_SETTINGS& aSizes, ITEM* aStartItem, NET_HANDLE aNet,
|
||||
VECTOR2D aStartPosition ) = 0;
|
||||
virtual int StackupHeight( int aFirstLayer, int aSecondLayer ) const = 0;
|
||||
virtual void EraseView() = 0;
|
||||
virtual int GetNetCode( NET_HANDLE aNet ) const = 0;
|
||||
|
||||
@@ -1208,7 +1208,7 @@ int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia )
|
||||
}
|
||||
|
||||
|
||||
bool ROUTER_TOOL::prepareInteractive()
|
||||
bool ROUTER_TOOL::prepareInteractive( VECTOR2D aStartPosition )
|
||||
{
|
||||
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
||||
int routingLayer = getStartLayer( m_startItem );
|
||||
@@ -1233,7 +1233,7 @@ bool ROUTER_TOOL::prepareInteractive()
|
||||
m_iface->SetStartLayer( routingLayer );
|
||||
|
||||
frame()->GetBoard()->GetDesignSettings().m_TempOverrideTrackWidth = false;
|
||||
m_iface->ImportSizes( sizes, m_startItem, nullptr );
|
||||
m_iface->ImportSizes( sizes, m_startItem, nullptr, aStartPosition );
|
||||
sizes.AddLayerPair( frame()->GetScreen()->m_Route_Layer_TOP,
|
||||
frame()->GetScreen()->m_Route_Layer_BOTTOM );
|
||||
|
||||
@@ -1301,11 +1301,11 @@ bool ROUTER_TOOL::finishInteractive()
|
||||
}
|
||||
|
||||
|
||||
void ROUTER_TOOL::performRouting()
|
||||
void ROUTER_TOOL::performRouting( VECTOR2D aStartPosition )
|
||||
{
|
||||
m_router->ClearViewDecorations();
|
||||
|
||||
if( !prepareInteractive() )
|
||||
if( !prepareInteractive( aStartPosition ) )
|
||||
return;
|
||||
|
||||
auto setCursor =
|
||||
@@ -1711,7 +1711,7 @@ int ROUTER_TOOL::RouteSelected( const TOOL_EVENT& aEvent )
|
||||
m_iface->SetCommitFlags( APPEND_UNDO );
|
||||
|
||||
// Start interactive routing. Will automatically finish if possible.
|
||||
performRouting();
|
||||
performRouting( VECTOR2D() );
|
||||
|
||||
// Route didn't complete automatically, need to a new undo commit
|
||||
// for the next line so those can group as far as they autoroute
|
||||
@@ -1828,7 +1828,7 @@ int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent )
|
||||
updateStartItem( *evt );
|
||||
|
||||
if( evt->HasPosition() )
|
||||
performRouting();
|
||||
performRouting( evt->Position() );
|
||||
}
|
||||
else if( evt->IsAction( &ACT_PlaceThroughVia ) )
|
||||
{
|
||||
@@ -2609,7 +2609,7 @@ int ROUTER_TOOL::onTrackViaSizeChanged( const TOOL_EVENT& aEvent )
|
||||
PNS::SIZES_SETTINGS sizes( m_router->Sizes() );
|
||||
|
||||
if( !m_router->GetCurrentNets().empty() )
|
||||
m_iface->ImportSizes( sizes, m_startItem, m_router->GetCurrentNets()[0] );
|
||||
m_iface->ImportSizes( sizes, m_startItem, m_router->GetCurrentNets()[0], VECTOR2D() );
|
||||
|
||||
m_router->UpdateSizes( sizes );
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
void UpdateMessagePanel();
|
||||
|
||||
private:
|
||||
void performRouting();
|
||||
void performRouting( VECTOR2D aStartPosition );
|
||||
void performDragging( int aMode = PNS::DM_ANY );
|
||||
void breakTrack();
|
||||
|
||||
@@ -85,7 +85,7 @@ private:
|
||||
int onViaCommand( const TOOL_EVENT& aEvent );
|
||||
int onTrackViaSizeChanged( const TOOL_EVENT& aEvent );
|
||||
|
||||
bool prepareInteractive();
|
||||
bool prepareInteractive( VECTOR2D aStartPosition );
|
||||
bool finishInteractive();
|
||||
void saveRouterDebugLog();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user