Fix for disappearing ratsnest lines (GAL).

This commit is contained in:
Maciej Suminski 2015-06-24 00:28:21 +02:00
parent 5dd0099119
commit a8bffb862c
3 changed files with 25 additions and 50 deletions

View File

@ -680,6 +680,7 @@ std::list<RN_NODE_PTR> RN_NET::GetClosestNodes( const RN_NODE_PTR& aNode, int aN
closest.sort( boost::bind( sortDistance, boost::cref( aNode ), _1, _2 ) ); closest.sort( boost::bind( sortDistance, boost::cref( aNode ), _1, _2 ) );
// Remove the first node (==aNode), as it is surely located within the smallest distance // Remove the first node (==aNode), as it is surely located within the smallest distance
assert( closest.front() == aNode );
closest.pop_front(); closest.pop_front();
// Trim the result to the asked size // Trim the result to the asked size
@ -704,6 +705,7 @@ std::list<RN_NODE_PTR> RN_NET::GetClosestNodes( const RN_NODE_PTR& aNode,
closest.sort( boost::bind( sortDistance, boost::cref( aNode ), _1, _2 ) ); closest.sort( boost::bind( sortDistance, boost::cref( aNode ), _1, _2 ) );
// Remove the first node (==aNode), as it is surely located within the smallest distance // Remove the first node (==aNode), as it is surely located within the smallest distance
assert( closest.front() == aNode );
closest.pop_front(); closest.pop_front();
// Filter out by condition // Filter out by condition
@ -719,17 +721,15 @@ std::list<RN_NODE_PTR> RN_NET::GetClosestNodes( const RN_NODE_PTR& aNode,
void RN_NET::AddSimple( const BOARD_CONNECTED_ITEM* aItem ) void RN_NET::AddSimple( const BOARD_CONNECTED_ITEM* aItem )
{ {
std::list<RN_NODE_PTR> nodes = GetNodes( aItem ); BOOST_FOREACH( RN_NODE_PTR node, GetNodes( aItem ) )
{
// Block all nodes, so they do not become targets for dynamic ratsnest lines
AddBlockedNode( node );
if( nodes.empty() ) // Filter out junctions
return; if( node->GetRefCount() == 1 )
m_simpleNodes.insert( node );
int tag = nodes.front()->GetTag(); }
if( m_simpleItems.count( tag ) )
return; // we already have a simple item for this tag
m_simpleItems[tag] = aItem;
} }
@ -816,42 +816,13 @@ void RN_NET::GetAllItems( std::list<BOARD_CONNECTED_ITEM*>& aOutput, RN_ITEM_TYP
} }
boost::unordered_set<RN_NODE_PTR> RN_NET::GetSimpleNodes() const
{
boost::unordered_set<RN_NODE_PTR> nodes;
BOOST_FOREACH( const BOARD_CONNECTED_ITEM* item, m_simpleItems | boost::adaptors::map_values )
{
std::list<RN_NODE_PTR> n = GetNodes( item );
if( n.empty() )
return nodes;
nodes.insert( n.front() ); // one node is enough, the rest belong to the same item
n.front()->SetFlag( true );
}
return nodes;
}
void RN_NET::ClearSimple() void RN_NET::ClearSimple()
{ {
BOOST_FOREACH( const BOARD_CONNECTED_ITEM* item, m_simpleItems | boost::adaptors::map_values )
{
std::list<RN_NODE_PTR> n = GetNodes( item );
if( n.empty() )
return;
n.front()->SetFlag( false );
}
BOOST_FOREACH( const RN_NODE_PTR& node, m_blockedNodes ) BOOST_FOREACH( const RN_NODE_PTR& node, m_blockedNodes )
node->SetFlag( false ); node->SetFlag( false );
m_blockedNodes.clear(); m_blockedNodes.clear();
m_simpleItems.clear(); m_simpleNodes.clear();
} }

View File

@ -506,7 +506,7 @@ public:
*/ */
inline void AddBlockedNode( RN_NODE_PTR& aNode ) inline void AddBlockedNode( RN_NODE_PTR& aNode )
{ {
m_blockedNodes.push_back( aNode ); m_blockedNodes.insert( aNode );
aNode->SetFlag( true ); aNode->SetFlag( true );
} }
@ -516,7 +516,10 @@ public:
* ratsnest line per node). * ratsnest line per node).
* @return list of nodes for which ratsnest is drawn in simple mode. * @return list of nodes for which ratsnest is drawn in simple mode.
*/ */
boost::unordered_set<RN_NODE_PTR> GetSimpleNodes() const; inline const boost::unordered_set<RN_NODE_PTR>& GetSimpleNodes() const
{
return m_simpleNodes;
}
/** /**
* Function ClearSimple() * Function ClearSimple()
@ -556,10 +559,10 @@ protected:
boost::shared_ptr< std::vector<RN_EDGE_MST_PTR> > m_rnEdges; boost::shared_ptr< std::vector<RN_EDGE_MST_PTR> > m_rnEdges;
///> List of nodes which will not be used as ratsnest target nodes. ///> List of nodes which will not be used as ratsnest target nodes.
std::deque<RN_NODE_PTR> m_blockedNodes; boost::unordered_set<RN_NODE_PTR> m_blockedNodes;
///> Map that stores items to be computed in simple mode, keyed by their tags. ///> Nodes to be displayed using the simplified ratsnest algorithm.
boost::unordered_map<int, const BOARD_CONNECTED_ITEM*> m_simpleItems; boost::unordered_set<RN_NODE_PTR> m_simpleNodes;
///> Flag indicating necessity of recalculation of ratsnest for a net. ///> Flag indicating necessity of recalculation of ratsnest for a net.
bool m_dirty; bool m_dirty;

View File

@ -62,6 +62,7 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, GAL* aGal ) const
COLOR4D color = rs->GetColor( NULL, ITEM_GAL_LAYER( RATSNEST_VISIBLE ) ); COLOR4D color = rs->GetColor( NULL, ITEM_GAL_LAYER( RATSNEST_VISIBLE ) );
int highlightedNet = rs->GetHighlightNetCode(); int highlightedNet = rs->GetHighlightNetCode();
// Dynamic ratsnest (for e.g. dragged items)
for( int i = 1; i < m_data->GetNetCount(); ++i ) for( int i = 1; i < m_data->GetNetCount(); ++i )
{ {
RN_NET& net = m_data->GetNet( i ); RN_NET& net = m_data->GetNet( i );
@ -75,8 +76,11 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, GAL* aGal ) const
// Draw the "dynamic" ratsnest (i.e. for objects that may be currently being moved) // Draw the "dynamic" ratsnest (i.e. for objects that may be currently being moved)
BOOST_FOREACH( const RN_NODE_PTR& node, net.GetSimpleNodes() ) BOOST_FOREACH( const RN_NODE_PTR& node, net.GetSimpleNodes() )
{ {
RN_NODE_PTR dest = net.GetClosestNode( node, WITHOUT_FLAG() && // Skipping nodes with higher reference count avoids displaying redundant lines
DIFFERENT_TAG( RN_NODE::TAG_UNCONNECTED ) ); if( node->GetRefCount() > 1 )
continue;
RN_NODE_PTR dest = net.GetClosestNode( node, WITHOUT_FLAG() );
if( dest ) if( dest )
{ {
@ -84,9 +88,6 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, GAL* aGal ) const
VECTOR2D end( dest->GetX(), dest->GetY() ); VECTOR2D end( dest->GetX(), dest->GetY() );
aGal->DrawLine( origin, end ); aGal->DrawLine( origin, end );
// Avoid duplicate destinations for ratsnest lines by storing already used nodes
net.AddBlockedNode( dest );
} }
} }