Mostly const safety, but also performance opt. by avoiding shared_ptr overhead.
This commit is contained in:
parent
1a9bc415c1
commit
226529235c
|
@ -87,11 +87,11 @@ public:
|
|||
return m_weight < aOther.m_weight;
|
||||
}
|
||||
|
||||
std::shared_ptr<CN_ANCHOR> GetSourceNode() const { return m_source; }
|
||||
std::shared_ptr<CN_ANCHOR> GetTargetNode() const { return m_target; }
|
||||
std::shared_ptr<const CN_ANCHOR> GetSourceNode() const { return m_source; }
|
||||
std::shared_ptr<const CN_ANCHOR> GetTargetNode() const { return m_target; }
|
||||
|
||||
void SetSourceNode( const std::shared_ptr<CN_ANCHOR>& aNode ) { m_source = aNode; }
|
||||
void SetTargetNode( const std::shared_ptr<CN_ANCHOR>& aNode ) { m_target = aNode; }
|
||||
void ResetSourceNode( const CN_ANCHOR* aNode ) { m_source.reset( aNode ); }
|
||||
void ResetTargetNode( const CN_ANCHOR* aNode ) { m_target.reset( aNode ); }
|
||||
|
||||
void SetWeight( unsigned weight ) { m_weight = weight; }
|
||||
unsigned GetWeight() const { return m_weight; }
|
||||
|
@ -107,10 +107,10 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<CN_ANCHOR> m_source;
|
||||
std::shared_ptr<CN_ANCHOR> m_target;
|
||||
unsigned m_weight;
|
||||
bool m_visible;
|
||||
std::shared_ptr<const CN_ANCHOR> m_source;
|
||||
std::shared_ptr<const CN_ANCHOR> m_target;
|
||||
unsigned m_weight;
|
||||
bool m_visible;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -356,9 +356,9 @@ void CONNECTIVITY_DATA::ComputeLocalRatsnest( const std::vector<BOARD_ITEM*>& aI
|
|||
|
||||
for( const CN_EDGE& edge : edges )
|
||||
{
|
||||
const std::shared_ptr<CN_ANCHOR>& nodeA = edge.GetSourceNode();
|
||||
const std::shared_ptr<CN_ANCHOR>& nodeB = edge.GetTargetNode();
|
||||
RN_DYNAMIC_LINE l;
|
||||
const std::shared_ptr<const CN_ANCHOR>& nodeA = edge.GetSourceNode();
|
||||
const std::shared_ptr<const CN_ANCHOR>& nodeB = edge.GetTargetNode();
|
||||
RN_DYNAMIC_LINE l;
|
||||
|
||||
// Use the parents' positions
|
||||
l.a = nodeA->Parent()->GetPosition() + aInternalOffset;
|
||||
|
@ -913,8 +913,8 @@ const std::vector<CN_EDGE> CONNECTIVITY_DATA::GetRatsnestForItems( std::vector<B
|
|||
|
||||
for( const CN_EDGE& edge : net->GetEdges() )
|
||||
{
|
||||
std::shared_ptr<CN_ANCHOR> srcNode = edge.GetSourceNode();
|
||||
std::shared_ptr<CN_ANCHOR> dstNode = edge.GetTargetNode();
|
||||
std::shared_ptr<const CN_ANCHOR> srcNode = edge.GetSourceNode();
|
||||
std::shared_ptr<const CN_ANCHOR> dstNode = edge.GetTargetNode();
|
||||
|
||||
BOARD_CONNECTED_ITEM* srcParent = srcNode->Parent();
|
||||
BOARD_CONNECTED_ITEM* dstParent = dstNode->Parent();
|
||||
|
|
|
@ -120,8 +120,8 @@ void RN_NET::kruskalMST( const std::vector<CN_EDGE> &aEdges )
|
|||
|
||||
for( const CN_EDGE& tmp : aEdges )
|
||||
{
|
||||
const std::shared_ptr<CN_ANCHOR>& source = tmp.GetSourceNode();
|
||||
const std::shared_ptr<CN_ANCHOR>& target = tmp.GetTargetNode();
|
||||
const std::shared_ptr<const CN_ANCHOR>& source = tmp.GetSourceNode();
|
||||
const std::shared_ptr<const CN_ANCHOR>& target = tmp.GetTargetNode();
|
||||
|
||||
if( dset.unite( source->GetTag(), target->GetTag() ) )
|
||||
{
|
||||
|
@ -276,14 +276,14 @@ void RN_NET::compute()
|
|||
// Check if the only possible connection exists
|
||||
if( m_boardEdges.size() == 0 && m_nodes.size() == 2 )
|
||||
{
|
||||
auto last = ++m_nodes.begin();
|
||||
|
||||
// There can be only one possible connection, but it is missing
|
||||
CN_EDGE edge ( *m_nodes.begin(), *last );
|
||||
edge.GetSourceNode()->SetTag( 0 );
|
||||
edge.GetTargetNode()->SetTag( 1 );
|
||||
auto it = m_nodes.begin();
|
||||
const std::shared_ptr<CN_ANCHOR>& source = *it++;
|
||||
const std::shared_ptr<CN_ANCHOR>& target = *it;
|
||||
|
||||
m_rnEdges.push_back( edge );
|
||||
source->SetTag( 0 );
|
||||
target->SetTag( 1 );
|
||||
m_rnEdges.emplace_back( source, target );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -330,9 +330,8 @@ void RN_NET::compute()
|
|||
|
||||
void RN_NET::optimizeRNEdges()
|
||||
{
|
||||
auto findZoneAnchor =
|
||||
[&]( const VECTOR2I& aPos, const LSET& aLayerSet,
|
||||
const std::shared_ptr<CN_ANCHOR> aAnchor )
|
||||
auto optimizeZoneAnchor =
|
||||
[&]( const VECTOR2I& aPos, const LSET& aLayerSet, const CN_ANCHOR*& aAnchor )
|
||||
{
|
||||
SEG::ecoord closest_dist_sq = ( aAnchor->Pos() - aPos ).SquaredEuclideanNorm();
|
||||
VECTOR2I closest_pt;
|
||||
|
@ -361,17 +360,17 @@ void RN_NET::optimizeRNEdges()
|
|||
}
|
||||
|
||||
if( closest_item )
|
||||
return closest_item->AddAnchor( closest_pt );
|
||||
else
|
||||
return aAnchor;
|
||||
{
|
||||
aAnchor = closest_item->AddAnchor( closest_pt ).get();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
auto optimizeZoneToZoneAnchors =
|
||||
[&]( CN_EDGE& edge )
|
||||
[&]( const CN_ANCHOR*& a, const CN_ANCHOR*& b )
|
||||
{
|
||||
const std::shared_ptr<CN_ANCHOR> a = edge.GetSourceNode();
|
||||
const std::shared_ptr<CN_ANCHOR> b = edge.GetTargetNode();
|
||||
|
||||
for( CN_ITEM* itemA : a->Item()->ConnectedItems() )
|
||||
{
|
||||
CN_ZONE_LAYER* zoneLayerA = dynamic_cast<CN_ZONE_LAYER*>( itemA );
|
||||
|
@ -398,36 +397,42 @@ void RN_NET::optimizeRNEdges()
|
|||
|
||||
VECTOR2I ptA;
|
||||
shapeA->Collide( shapeB, startDist + 10, nullptr, &ptA );
|
||||
edge.SetSourceNode( zoneLayerA->AddAnchor( ptA ) );
|
||||
a = zoneLayerA->AddAnchor( ptA ).get();
|
||||
|
||||
VECTOR2I ptB;
|
||||
shapeB->Collide( shapeA, startDist + 10, nullptr, &ptB );
|
||||
edge.SetTargetNode( zoneLayerB->AddAnchor( ptB ) );
|
||||
b = zoneLayerB->AddAnchor( ptB ).get();
|
||||
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
for( CN_EDGE& edge : m_rnEdges )
|
||||
{
|
||||
const std::shared_ptr<CN_ANCHOR> source = edge.GetSourceNode();
|
||||
const std::shared_ptr<CN_ANCHOR> target = edge.GetTargetNode();
|
||||
const CN_ANCHOR* source = edge.GetSourceNode().get();
|
||||
const CN_ANCHOR* target = edge.GetTargetNode().get();
|
||||
|
||||
if( source->ConnectedItemsCount() == 0 )
|
||||
{
|
||||
edge.SetTargetNode( findZoneAnchor( source->Pos(), source->Parent()->GetLayerSet(),
|
||||
target ) );
|
||||
if( optimizeZoneAnchor( source->Pos(), source->Parent()->GetLayerSet(), target ) )
|
||||
edge.ResetTargetNode( target );
|
||||
}
|
||||
else if( target->ConnectedItemsCount() == 0 )
|
||||
{
|
||||
edge.SetSourceNode( findZoneAnchor( target->Pos(), target->Parent()->GetLayerSet(),
|
||||
source ) );
|
||||
if( optimizeZoneAnchor( target->Pos(), target->Parent()->GetLayerSet(), source ) )
|
||||
edge.ResetSourceNode( source );
|
||||
}
|
||||
else
|
||||
{
|
||||
optimizeZoneToZoneAnchors( edge );
|
||||
if( optimizeZoneToZoneAnchors( source, target ) )
|
||||
{
|
||||
edge.ResetSourceNode( source );
|
||||
edge.ResetTargetNode( target );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,10 +181,10 @@ void RATSNEST_VIEW_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
|
|||
if( !edge.IsVisible() )
|
||||
continue;
|
||||
|
||||
const std::shared_ptr<CN_ANCHOR>& sourceNode = edge.GetSourceNode();
|
||||
const std::shared_ptr<CN_ANCHOR>& targetNode = edge.GetTargetNode();
|
||||
const VECTOR2I source( sourceNode->Pos() );
|
||||
const VECTOR2I target( targetNode->Pos() );
|
||||
const std::shared_ptr<const CN_ANCHOR>& sourceNode = edge.GetSourceNode();
|
||||
const std::shared_ptr<const CN_ANCHOR>& targetNode = edge.GetTargetNode();
|
||||
const VECTOR2I source( sourceNode->Pos() );
|
||||
const VECTOR2I target( targetNode->Pos() );
|
||||
|
||||
if( !sourceNode->Valid() || !targetNode->Valid() )
|
||||
continue;
|
||||
|
|
|
@ -1582,12 +1582,12 @@ int ROUTER_TOOL::RouteSelected( const TOOL_EVENT& aEvent )
|
|||
// the side of the connectivity on this pad. It also checks for ratsnest points
|
||||
// inside the pad (like a trace end) and counts them.
|
||||
RN_NET* net = connectivity->GetRatsnestForNet( item->GetNetCode() );
|
||||
std::vector<std::shared_ptr<CN_ANCHOR>> anchors;
|
||||
std::vector<std::shared_ptr<const CN_ANCHOR>> anchors;
|
||||
|
||||
for( const CN_EDGE& edge : net->GetEdges() )
|
||||
{
|
||||
std::shared_ptr<CN_ANCHOR> target = edge.GetTargetNode();
|
||||
std::shared_ptr<CN_ANCHOR> source = edge.GetSourceNode();
|
||||
std::shared_ptr<const CN_ANCHOR> target = edge.GetTargetNode();
|
||||
std::shared_ptr<const CN_ANCHOR> source = edge.GetSourceNode();
|
||||
|
||||
if( source->Parent() == item )
|
||||
anchors.push_back( edge.GetSourceNode() );
|
||||
|
@ -1596,7 +1596,7 @@ int ROUTER_TOOL::RouteSelected( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
|
||||
// Route them
|
||||
for( std::shared_ptr<CN_ANCHOR> anchor : anchors )
|
||||
for( std::shared_ptr<const CN_ANCHOR> anchor : anchors )
|
||||
{
|
||||
// Try to return to the original layer as indicating the user's preferred
|
||||
// layer for autorouting tracks. The layer can be changed by the user to
|
||||
|
|
|
@ -1501,21 +1501,17 @@ int PCB_SELECTION_TOOL::grabUnconnected( const TOOL_EVENT& aEvent )
|
|||
for( const CN_EDGE& edge : edges )
|
||||
{
|
||||
// Figure out if we are the source or the target node on the ratnest
|
||||
std::shared_ptr<CN_ANCHOR> ourNode = edge.GetSourceNode()->Parent() == pad
|
||||
? edge.GetSourceNode()
|
||||
: edge.GetTargetNode();
|
||||
std::shared_ptr<CN_ANCHOR> otherNode = edge.GetSourceNode()->Parent() != pad
|
||||
? edge.GetSourceNode()
|
||||
: edge.GetTargetNode();
|
||||
const CN_ANCHOR* other = edge.GetSourceNode()->Parent() == pad ? edge.GetTargetNode().get()
|
||||
: edge.GetSourceNode().get();
|
||||
|
||||
// We only want to grab footprints, so the ratnest has to point to a pad
|
||||
if( otherNode->Parent()->Type() != PCB_PAD_T )
|
||||
if( other->Parent()->Type() != PCB_PAD_T )
|
||||
continue;
|
||||
|
||||
if( edge.GetLength() < currentDistance )
|
||||
{
|
||||
currentDistance = edge.GetLength();
|
||||
nearest = static_cast<PAD*>( otherNode->Parent() )->GetParent();
|
||||
nearest = static_cast<PAD*>( other->Parent() )->GetParent();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue