diff --git a/pcbnew/connectivity/connectivity_data.cpp b/pcbnew/connectivity/connectivity_data.cpp index c7d79104cd..1c64c39fba 100644 --- a/pcbnew/connectivity/connectivity_data.cpp +++ b/pcbnew/connectivity/connectivity_data.cpp @@ -788,7 +788,7 @@ const std::vector CONNECTIVITY_DATA::GetRatsnestForItems( std::vector edges; std::set item_set; - for( auto item : aItems ) + for( BOARD_ITEM* item : aItems ) { if( item->Type() == PCB_FOOTPRINT_T ) { @@ -809,18 +809,18 @@ const std::vector CONNECTIVITY_DATA::GetRatsnestForItems( std::vectorGetEdges() ) + for( const CN_EDGE& edge : net->GetEdges() ) { - auto srcNode = edge.GetSourceNode(); - auto dstNode = edge.GetTargetNode(); + std::shared_ptr srcNode = edge.GetSourceNode(); + std::shared_ptr dstNode = edge.GetTargetNode(); - auto srcParent = srcNode->Parent(); - auto dstParent = dstNode->Parent(); + BOARD_CONNECTED_ITEM* srcParent = srcNode->Parent(); + BOARD_CONNECTED_ITEM* dstParent = dstNode->Parent(); - bool srcFound = ( item_set.find(srcParent) != item_set.end() ); - bool dstFound = ( item_set.find(dstParent) != item_set.end() ); + bool srcFound = ( item_set.find( srcParent ) != item_set.end() ); + bool dstFound = ( item_set.find( dstParent ) != item_set.end() ); if ( srcFound && dstFound ) edges.push_back( edge ); @@ -831,6 +831,21 @@ const std::vector CONNECTIVITY_DATA::GetRatsnestForItems( std::vector CONNECTIVITY_DATA::GetRatsnestForPad( const PAD* aPad ) +{ + std::vector edges; + RN_NET* net = GetRatsnestForNet( aPad->GetNetCode() ); + + for( const CN_EDGE& edge : net->GetEdges() ) + { + if( edge.GetSourceNode()->Parent() == aPad || edge.GetTargetNode()->Parent() == aPad ) + edges.push_back( edge ); + } + + return edges; +} + + const std::vector CONNECTIVITY_DATA::GetRatsnestForComponent( FOOTPRINT* aComponent, bool aSkipInternalConnections ) { std::set nets; diff --git a/pcbnew/connectivity/connectivity_data.h b/pcbnew/connectivity/connectivity_data.h index c7bf7ec8b5..004cbae206 100644 --- a/pcbnew/connectivity/connectivity_data.h +++ b/pcbnew/connectivity/connectivity_data.h @@ -294,6 +294,8 @@ public: #ifndef SWIG const std::vector GetRatsnestForItems( const std::vector aItems ); + const std::vector GetRatsnestForPad( const PAD* aPad ); + const std::vector GetRatsnestForComponent( FOOTPRINT* aComponent, bool aSkipInternalConnections = false ); #endif diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 975476ed89..42f6c734ae 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -39,6 +39,8 @@ using namespace std::placeholders; #include #include #include +#include +#include #include #include #include @@ -1603,17 +1605,31 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) PNS::ITEM_SET itemsToDrag; const FOOTPRINT* footprint = nullptr; + std::shared_ptr connectivityData = board()->GetConnectivity(); + std::vector dynamicItems; + std::unique_ptr dynamicData = nullptr; + VECTOR2I lastOffset; + if( item->Type() == PCB_FOOTPRINT_T ) { footprint = static_cast(item); - for( const PAD* pad : footprint->Pads() ) + for( PAD* pad : footprint->Pads() ) { PNS::ITEM* solid = m_router->GetWorld()->FindItemByParent( pad ); if( solid ) itemsToDrag.Add( solid ); + + if( pad->GetLocalRatsnestVisible() || displayOptions().m_ShowModuleRatsnest ) + { + if( connectivityData->GetRatsnestForPad( pad ).size() > 0 ) + dynamicItems.push_back( pad ); + } } + + dynamicData = std::make_unique( dynamicItems, true ); + connectivityData->BlockRatsnestItems( dynamicItems ); } else { @@ -1717,6 +1733,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) { VECTOR2I offset = m_endSnapPoint - p; BOARD_ITEM* previewItem; + wxPoint fp_offset = wxPoint( offset.Rotate( footprint->GetOrientationRadians() ) ); view()->ClearPreview(); @@ -1727,7 +1744,6 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) if( drawing->Type() == PCB_FP_SHAPE_T ) { FP_SHAPE* shape = static_cast( previewItem ); - wxPoint fp_offset = wxPoint( offset.Rotate( footprint->GetOrientationRadians() ) ); shape->FP_SHAPE::Move( fp_offset ); } else @@ -1756,6 +1772,11 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) view()->AddToPreview( previewItem ); view()->Hide( zone, true ); } + + // Update ratsnest + dynamicData->Move( offset - lastOffset ); + lastOffset = offset; + connectivityData->ComputeDynamicRatsnest( dynamicItems, dynamicData.get() ); } } else if( hasMouseMoved && ( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) ) @@ -1800,6 +1821,8 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) view()->ClearPreview(); view()->ShowPreview( false ); + + connectivityData->ClearDynamicRatsnest(); } if( m_router->RoutingInProgress() )