2013-11-25 15:50:03 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
2015-03-09 12:41:34 +00:00
|
|
|
* Copyright (C) 2013-2015 CERN
|
2013-11-25 15:50:03 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file ratsnest_data.cpp
|
|
|
|
* @brief Class that computes missing connections on a PCB.
|
|
|
|
*/
|
|
|
|
|
2014-01-31 17:27:06 +00:00
|
|
|
#ifdef USE_OPENMP
|
|
|
|
#include <omp.h>
|
|
|
|
#endif /* USE_OPENMP */
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
#include <ratsnest_data.h>
|
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_pad.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_zone.h>
|
|
|
|
|
|
|
|
#include <boost/range/adaptor/map.hpp>
|
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <limits>
|
|
|
|
|
2015-06-04 12:54:06 +00:00
|
|
|
#ifdef PROFILE
|
|
|
|
#include <profile.h>
|
|
|
|
#endif
|
|
|
|
|
2015-06-05 15:49:00 +00:00
|
|
|
static uint64_t getDistance( const RN_NODE_PTR& aNode1, const RN_NODE_PTR& aNode2 )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
|
|
|
// Drop the least significant bits to avoid overflow
|
|
|
|
int64_t x = ( aNode1->GetX() - aNode2->GetX() ) >> 16;
|
|
|
|
int64_t y = ( aNode1->GetY() - aNode2->GetY() ) >> 16;
|
|
|
|
|
|
|
|
// We do not need sqrt() here, as the distance is computed only for comparison
|
|
|
|
return ( x * x + y * y );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-05 15:49:00 +00:00
|
|
|
static bool sortDistance( const RN_NODE_PTR& aOrigin, const RN_NODE_PTR& aNode1,
|
2013-11-25 15:50:03 +00:00
|
|
|
const RN_NODE_PTR& aNode2 )
|
|
|
|
{
|
|
|
|
return getDistance( aOrigin, aNode1 ) < getDistance( aOrigin, aNode2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-05 15:49:00 +00:00
|
|
|
static bool sortWeight( const RN_EDGE_PTR& aEdge1, const RN_EDGE_PTR& aEdge2 )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-04-07 11:32:09 +00:00
|
|
|
return aEdge1->GetWeight() < aEdge2->GetWeight();
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool sortArea( const RN_POLY& aP1, const RN_POLY& aP2 )
|
|
|
|
{
|
|
|
|
return aP1.m_bbox.GetArea() < aP2.m_bbox.GetArea();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-31 12:19:59 +00:00
|
|
|
bool operator==( const RN_NODE_PTR& aFirst, const RN_NODE_PTR& aSecond )
|
|
|
|
{
|
|
|
|
return aFirst->GetX() == aSecond->GetX() && aFirst->GetY() == aSecond->GetY();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=( const RN_NODE_PTR& aFirst, const RN_NODE_PTR& aSecond )
|
|
|
|
{
|
|
|
|
return aFirst->GetX() != aSecond->GetX() || aFirst->GetY() != aSecond->GetY();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-05 15:49:00 +00:00
|
|
|
RN_NODE_AND_FILTER operator&&( const RN_NODE_FILTER& aFilter1, const RN_NODE_FILTER& aFilter2 )
|
|
|
|
{
|
|
|
|
return RN_NODE_AND_FILTER( aFilter1, aFilter2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RN_NODE_OR_FILTER operator||( const RN_NODE_FILTER& aFilter1, const RN_NODE_FILTER& aFilter2 )
|
|
|
|
{
|
|
|
|
return RN_NODE_OR_FILTER( aFilter1, aFilter2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-05 15:49:00 +00:00
|
|
|
static bool isEdgeConnectingNode( const RN_EDGE_PTR& aEdge, const RN_NODE_PTR& aNode )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-04-07 11:32:09 +00:00
|
|
|
return aEdge->GetSourceNode() == aNode || aEdge->GetTargetNode() == aNode;
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
static std::vector<RN_EDGE_MST_PTR>* kruskalMST( RN_LINKS::RN_EDGE_LIST& aEdges,
|
|
|
|
std::vector<RN_NODE_PTR>& aNodes )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
|
|
|
unsigned int nodeNumber = aNodes.size();
|
|
|
|
unsigned int mstExpectedSize = nodeNumber - 1;
|
|
|
|
unsigned int mstSize = 0;
|
2015-03-09 12:41:34 +00:00
|
|
|
bool ratsnestLines = false;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// The output
|
2015-03-09 12:41:34 +00:00
|
|
|
std::vector<RN_EDGE_MST_PTR>* mst = new std::vector<RN_EDGE_MST_PTR>;
|
2013-11-25 15:50:03 +00:00
|
|
|
mst->reserve( mstExpectedSize );
|
|
|
|
|
|
|
|
// Set tags for marking cycles
|
|
|
|
boost::unordered_map<RN_NODE_PTR, int> tags;
|
|
|
|
unsigned int tag = 0;
|
2015-03-09 12:41:34 +00:00
|
|
|
BOOST_FOREACH( RN_NODE_PTR& node, aNodes )
|
|
|
|
{
|
|
|
|
node->SetTag( tag );
|
2013-11-25 15:50:03 +00:00
|
|
|
tags[node] = tag++;
|
2015-03-09 12:41:34 +00:00
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// Lists of nodes connected together (subtrees) to detect cycles in the graph
|
|
|
|
std::vector<std::list<int> > cycles( nodeNumber );
|
|
|
|
for( unsigned int i = 0; i < nodeNumber; ++i )
|
|
|
|
cycles[i].push_back( i );
|
|
|
|
|
|
|
|
// Kruskal algorithm requires edges to be sorted by their weight
|
|
|
|
aEdges.sort( sortWeight );
|
|
|
|
|
|
|
|
while( mstSize < mstExpectedSize && !aEdges.empty() )
|
|
|
|
{
|
2015-03-09 12:41:34 +00:00
|
|
|
RN_EDGE_PTR& dt = aEdges.front();
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
int srcTag = tags[dt->GetSourceNode()];
|
|
|
|
int trgTag = tags[dt->GetTargetNode()];
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// Check if by adding this edge we are going to join two different forests
|
|
|
|
if( srcTag != trgTag )
|
|
|
|
{
|
2015-06-04 12:54:07 +00:00
|
|
|
// Because edges are sorted by their weight, first we always process connected
|
|
|
|
// items (weight == 0). Once we stumble upon an edge with non-zero weight,
|
|
|
|
// it means that the rest of the lines are ratsnest.
|
|
|
|
if( !ratsnestLines && dt->GetWeight() != 0 )
|
|
|
|
ratsnestLines = true;
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
// Update tags
|
|
|
|
std::list<int>::iterator it, itEnd;
|
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
if( ratsnestLines )
|
2014-03-05 13:57:14 +00:00
|
|
|
{
|
2015-03-09 12:41:34 +00:00
|
|
|
for( it = cycles[trgTag].begin(), itEnd = cycles[trgTag].end(); it != itEnd; ++it )
|
|
|
|
tags[aNodes[*it]] = srcTag;
|
2014-03-05 13:57:14 +00:00
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
else
|
2015-03-09 12:41:34 +00:00
|
|
|
{
|
|
|
|
for( it = cycles[trgTag].begin(), itEnd = cycles[trgTag].end(); it != itEnd; ++it ) {
|
|
|
|
tags[aNodes[*it]] = srcTag;
|
|
|
|
aNodes[*it]->SetTag( srcTag );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move nodes that were marked with old tag to the list marked with the new tag
|
|
|
|
cycles[srcTag].splice( cycles[srcTag].end(), cycles[trgTag] );
|
|
|
|
|
|
|
|
if( ratsnestLines )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-03-05 13:57:14 +00:00
|
|
|
// Do a copy of edge, but make it RN_EDGE_MST. In contrary to RN_EDGE,
|
|
|
|
// RN_EDGE_MST saves both source and target node and does not require any other
|
|
|
|
// edges to exist for getting source/target nodes
|
2014-04-07 11:32:09 +00:00
|
|
|
RN_EDGE_MST_PTR newEdge = boost::make_shared<RN_EDGE_MST>( dt->GetSourceNode(),
|
|
|
|
dt->GetTargetNode(),
|
|
|
|
dt->GetWeight() );
|
2014-03-05 13:57:14 +00:00
|
|
|
mst->push_back( newEdge );
|
2013-11-25 15:50:03 +00:00
|
|
|
++mstSize;
|
|
|
|
}
|
2015-03-09 12:41:34 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Processing a connection, decrease the expected size of the ratsnest MST
|
|
|
|
--mstExpectedSize;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the edge that was just processed
|
|
|
|
aEdges.erase( aEdges.begin() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Probably we have discarded some of edges, so reduce the size
|
|
|
|
mst->resize( mstSize );
|
|
|
|
|
|
|
|
return mst;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
void RN_NET::validateEdge( RN_EDGE_MST_PTR& aEdge )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-04-07 11:32:09 +00:00
|
|
|
RN_NODE_PTR source = aEdge->GetSourceNode();
|
|
|
|
RN_NODE_PTR target = aEdge->GetTargetNode();
|
2013-11-25 15:50:03 +00:00
|
|
|
bool valid = true;
|
|
|
|
|
|
|
|
// If any of nodes belonging to the edge has the flag set,
|
|
|
|
// change it to the closest node that has flag cleared
|
|
|
|
if( source->GetFlag() )
|
|
|
|
{
|
|
|
|
valid = false;
|
|
|
|
|
|
|
|
std::list<RN_NODE_PTR> closest = GetClosestNodes( source, WITHOUT_FLAG() );
|
|
|
|
BOOST_FOREACH( RN_NODE_PTR& node, closest )
|
|
|
|
{
|
|
|
|
if( node && node != target )
|
|
|
|
{
|
|
|
|
source = node;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( target->GetFlag() )
|
|
|
|
{
|
|
|
|
valid = false;
|
|
|
|
|
|
|
|
std::list<RN_NODE_PTR> closest = GetClosestNodes( target, WITHOUT_FLAG() );
|
|
|
|
BOOST_FOREACH( RN_NODE_PTR& node, closest )
|
|
|
|
{
|
|
|
|
if( node && node != source )
|
|
|
|
{
|
|
|
|
target = node;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace an invalid edge with new, valid one
|
|
|
|
if( !valid )
|
|
|
|
aEdge.reset( new RN_EDGE_MST( source, target ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const RN_NODE_PTR& RN_LINKS::AddNode( int aX, int aY )
|
|
|
|
{
|
|
|
|
RN_NODE_SET::iterator node;
|
|
|
|
bool wasNewElement;
|
|
|
|
|
|
|
|
boost::tie( node, wasNewElement ) = m_nodes.emplace( boost::make_shared<RN_NODE>( aX, aY ) );
|
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-07 13:15:40 +00:00
|
|
|
bool RN_LINKS::RemoveNode( const RN_NODE_PTR& aNode )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
|
|
|
if( aNode->GetRefCount() == 0 )
|
2014-01-07 13:15:40 +00:00
|
|
|
{
|
2013-11-25 15:50:03 +00:00
|
|
|
m_nodes.erase( aNode );
|
2014-01-07 13:15:40 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
RN_EDGE_MST_PTR RN_LINKS::AddConnection( const RN_NODE_PTR& aNode1, const RN_NODE_PTR& aNode2,
|
|
|
|
unsigned int aDistance )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2015-06-04 12:54:07 +00:00
|
|
|
assert( aNode1 != aNode2 );
|
2015-03-09 12:41:34 +00:00
|
|
|
RN_EDGE_MST_PTR edge = boost::make_shared<RN_EDGE_MST>( aNode1, aNode2, aDistance );
|
|
|
|
m_edges.push_back( edge );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
return edge;
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_NET::compute()
|
|
|
|
{
|
|
|
|
const RN_LINKS::RN_NODE_SET& boardNodes = m_links.GetNodes();
|
|
|
|
const RN_LINKS::RN_EDGE_LIST& boardEdges = m_links.GetConnections();
|
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
// Special cases do not need complicated algorithms
|
2015-03-09 12:41:34 +00:00
|
|
|
if( boardNodes.size() <= 2 )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2015-03-09 12:41:34 +00:00
|
|
|
m_rnEdges.reset( new std::vector<RN_EDGE_MST_PTR>( 0 ) );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// Check if the only possible connection exists
|
2015-03-10 14:02:27 +00:00
|
|
|
if( boardEdges.size() == 0 && boardNodes.size() == 2 )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
|
|
|
RN_LINKS::RN_NODE_SET::iterator last = ++boardNodes.begin();
|
|
|
|
|
|
|
|
// There can be only one possible connection, but it is missing
|
|
|
|
m_rnEdges->push_back( boost::make_shared<RN_EDGE_MST>( *boardNodes.begin(), *last ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move and sort (sorting speeds up) all nodes to a vector for the Delaunay triangulation
|
|
|
|
std::vector<RN_NODE_PTR> nodes( boardNodes.size() );
|
|
|
|
std::partial_sort_copy( boardNodes.begin(), boardNodes.end(), nodes.begin(), nodes.end() );
|
|
|
|
|
|
|
|
TRIANGULATOR triangulator;
|
2014-04-07 11:32:09 +00:00
|
|
|
triangulator.CreateDelaunay( nodes.begin(), nodes.end() );
|
|
|
|
boost::scoped_ptr<RN_LINKS::RN_EDGE_LIST> triangEdges( triangulator.GetEdges() );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// Compute weight/distance for edges resulting from triangulation
|
|
|
|
RN_LINKS::RN_EDGE_LIST::iterator eit, eitEnd;
|
|
|
|
for( eit = (*triangEdges).begin(), eitEnd = (*triangEdges).end(); eit != eitEnd; ++eit )
|
2014-04-07 11:32:09 +00:00
|
|
|
(*eit)->SetWeight( getDistance( (*eit)->GetSourceNode(), (*eit)->GetTargetNode() ) );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// Add the currently existing connections list to the results of triangulation
|
|
|
|
std::copy( boardEdges.begin(), boardEdges.end(), std::front_inserter( *triangEdges ) );
|
|
|
|
|
|
|
|
// Get the minimal spanning tree
|
|
|
|
m_rnEdges.reset( kruskalMST( *triangEdges, nodes ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_NET::clearNode( const RN_NODE_PTR& aNode )
|
|
|
|
{
|
2014-01-07 13:15:40 +00:00
|
|
|
if( !m_rnEdges )
|
|
|
|
return;
|
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
std::vector<RN_EDGE_MST_PTR>::iterator newEnd;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// Remove all ratsnest edges for associated with the node
|
|
|
|
newEnd = std::remove_if( m_rnEdges->begin(), m_rnEdges->end(),
|
2015-06-04 12:54:07 +00:00
|
|
|
boost::bind( isEdgeConnectingNode, _1, boost::cref( aNode ) ) );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
m_rnEdges->resize( std::distance( m_rnEdges->begin(), newEnd ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
RN_POLY::RN_POLY( const CPolyPt* aBegin, const CPolyPt* aEnd,
|
|
|
|
RN_LINKS& aConnections, const BOX2I& aBBox ) :
|
|
|
|
m_begin( aBegin ), m_end( aEnd ), m_bbox( aBBox )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
|
|
|
m_node = aConnections.AddNode( m_begin->x, m_begin->y );
|
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
// Mark it as not appropriate as a destination of ratsnest edges
|
2013-11-25 15:50:03 +00:00
|
|
|
// (edges coming out from a polygon vertex look weird)
|
|
|
|
m_node->SetFlag( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RN_POLY::HitTest( const RN_NODE_PTR& aNode ) const
|
|
|
|
{
|
|
|
|
long xt = aNode->GetX();
|
|
|
|
long yt = aNode->GetY();
|
|
|
|
|
|
|
|
// If the point lies outside the bounding box, there is no point to check it further
|
|
|
|
if( !m_bbox.Contains( xt, yt ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
long xNew, yNew, xOld, yOld, x1, y1, x2, y2;
|
|
|
|
bool inside = false;
|
|
|
|
|
|
|
|
// For the first loop we have to use the last point as the previous point
|
|
|
|
xOld = m_end->x;
|
|
|
|
yOld = m_end->y;
|
|
|
|
|
|
|
|
for( const CPolyPt* point = m_begin; point <= m_end; ++point )
|
|
|
|
{
|
|
|
|
xNew = point->x;
|
|
|
|
yNew = point->y;
|
|
|
|
|
|
|
|
// Swap points if needed, so always x2 >= x1
|
|
|
|
if( xNew > xOld )
|
|
|
|
{
|
|
|
|
x1 = xOld; y1 = yOld;
|
|
|
|
x2 = xNew; y2 = yNew;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x1 = xNew; y1 = yNew;
|
|
|
|
x2 = xOld; y2 = yOld;
|
|
|
|
}
|
|
|
|
|
2014-03-12 16:11:52 +00:00
|
|
|
if( ( xNew < xt ) == ( xt <= xOld ) && /* edge "open" at left end */
|
2014-03-19 10:16:01 +00:00
|
|
|
(double)( yt - y1 ) * (double)( x2 - x1 ) < (double)( y2 - y1 ) * (double)( xt - x1 ) )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
|
|
|
inside = !inside;
|
|
|
|
}
|
|
|
|
|
|
|
|
xOld = xNew;
|
|
|
|
yOld = yNew;
|
|
|
|
}
|
|
|
|
|
|
|
|
return inside;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_NET::Update()
|
|
|
|
{
|
|
|
|
// Add edges resulting from nodes being connected by zones
|
|
|
|
processZones();
|
|
|
|
|
|
|
|
compute();
|
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
BOOST_FOREACH( RN_EDGE_MST_PTR& edge, *m_rnEdges )
|
2013-11-25 15:50:03 +00:00
|
|
|
validateEdge( edge );
|
|
|
|
|
|
|
|
m_dirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_NET::AddItem( const D_PAD* aPad )
|
|
|
|
{
|
2015-06-04 12:54:08 +00:00
|
|
|
RN_NODE_PTR node = m_links.AddNode( aPad->GetPosition().x, aPad->GetPosition().y );
|
|
|
|
node->AddParent( aPad );
|
|
|
|
m_pads[aPad] = node;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
void RN_NET::AddItem( const VIA* aVia )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2015-06-04 12:54:08 +00:00
|
|
|
RN_NODE_PTR node = m_links.AddNode( aVia->GetPosition().x, aVia->GetPosition().y );
|
|
|
|
node->AddParent( aVia );
|
|
|
|
m_vias[aVia] = node;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_NET::AddItem( const TRACK* aTrack )
|
|
|
|
{
|
2015-06-05 15:49:01 +00:00
|
|
|
if( aTrack->GetStart() == aTrack->GetEnd() )
|
|
|
|
return;
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
RN_NODE_PTR start = m_links.AddNode( aTrack->GetStart().x, aTrack->GetStart().y );
|
|
|
|
RN_NODE_PTR end = m_links.AddNode( aTrack->GetEnd().x, aTrack->GetEnd().y );
|
|
|
|
|
2015-06-05 15:49:01 +00:00
|
|
|
start->AddParent( aTrack );
|
|
|
|
end->AddParent( aTrack );
|
|
|
|
m_tracks[aTrack] = m_links.AddConnection( start, end );
|
|
|
|
|
|
|
|
m_dirty = true;
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_NET::AddItem( const ZONE_CONTAINER* aZone )
|
|
|
|
{
|
|
|
|
// Prepare a list of polygons (every zone can contain one or more polygons)
|
|
|
|
const std::vector<CPolyPt>& polyPoints = aZone->GetFilledPolysList().GetList();
|
2015-06-04 12:54:07 +00:00
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
if( polyPoints.size() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Origin and end of bounding box for a polygon
|
|
|
|
VECTOR2I origin( polyPoints[0].x, polyPoints[0].y );
|
|
|
|
VECTOR2I end( polyPoints[0].x, polyPoints[0].y );
|
2014-03-05 13:57:14 +00:00
|
|
|
unsigned int idxStart = 0;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// Extract polygons from zones
|
|
|
|
for( unsigned int i = 0; i < polyPoints.size(); ++i )
|
|
|
|
{
|
|
|
|
const CPolyPt& point = polyPoints[i];
|
|
|
|
|
|
|
|
if( point.end_contour )
|
|
|
|
{
|
2015-06-04 12:54:08 +00:00
|
|
|
RN_POLY poly = RN_POLY( &polyPoints[idxStart], &point,
|
|
|
|
m_links, BOX2I( origin, end - origin ) );
|
|
|
|
poly.GetNode()->AddParent( aZone );
|
|
|
|
m_zones[aZone].m_Polygons.push_back( poly );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
idxStart = i + 1;
|
2014-03-05 13:57:14 +00:00
|
|
|
|
|
|
|
if( idxStart < polyPoints.size() )
|
|
|
|
{
|
|
|
|
origin.x = polyPoints[idxStart].x;
|
|
|
|
origin.y = polyPoints[idxStart].y;
|
|
|
|
end.x = polyPoints[idxStart].x;
|
|
|
|
end.y = polyPoints[idxStart].y;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
2015-06-04 12:54:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Determine bounding box
|
|
|
|
if( point.x < origin.x )
|
|
|
|
origin.x = point.x;
|
|
|
|
else if( point.x > end.x )
|
|
|
|
end.x = point.x;
|
|
|
|
|
|
|
|
if( point.y < origin.y )
|
|
|
|
origin.y = point.y;
|
|
|
|
else if( point.y > end.y )
|
|
|
|
end.y = point.y;
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_NET::RemoveItem( const D_PAD* aPad )
|
|
|
|
{
|
2014-01-07 13:15:40 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
RN_NODE_PTR node = m_pads.at( aPad );
|
2015-06-04 12:54:08 +00:00
|
|
|
node->RemoveParent( aPad );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-07 13:15:40 +00:00
|
|
|
if( m_links.RemoveNode( node ) )
|
|
|
|
clearNode( node );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-07 13:15:40 +00:00
|
|
|
m_pads.erase( aPad );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-07 13:15:40 +00:00
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
void RN_NET::RemoveItem( const VIA* aVia )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-01-07 13:15:40 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
RN_NODE_PTR node = m_vias.at( aVia );
|
2015-06-04 12:54:08 +00:00
|
|
|
node->RemoveParent( aVia );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-07 13:15:40 +00:00
|
|
|
if( m_links.RemoveNode( node ) )
|
|
|
|
clearNode( node );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-07 13:15:40 +00:00
|
|
|
m_vias.erase( aVia );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-07 13:15:40 +00:00
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_NET::RemoveItem( const TRACK* aTrack )
|
|
|
|
{
|
2014-01-07 13:15:40 +00:00
|
|
|
try
|
|
|
|
{
|
2015-03-09 12:41:34 +00:00
|
|
|
RN_EDGE_MST_PTR& edge = m_tracks.at( aTrack );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-07 13:15:40 +00:00
|
|
|
// Save nodes, so they can be cleared later
|
2015-06-04 12:54:08 +00:00
|
|
|
RN_NODE_PTR start = edge->GetSourceNode();
|
|
|
|
start->RemoveParent( aTrack );
|
|
|
|
RN_NODE_PTR end = edge->GetTargetNode();
|
|
|
|
end->RemoveParent( aTrack );
|
|
|
|
|
2014-01-07 13:15:40 +00:00
|
|
|
m_links.RemoveConnection( edge );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-07 13:15:40 +00:00
|
|
|
// Remove nodes associated with the edge. It is done in a safe way, there is a check
|
|
|
|
// if nodes are not used by other edges.
|
2015-06-04 12:54:08 +00:00
|
|
|
if( m_links.RemoveNode( start ) )
|
|
|
|
clearNode( start );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2015-06-04 12:54:08 +00:00
|
|
|
if( m_links.RemoveNode( end ) )
|
|
|
|
clearNode( end );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-07 13:15:40 +00:00
|
|
|
m_tracks.erase( aTrack );
|
|
|
|
|
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_NET::RemoveItem( const ZONE_CONTAINER* aZone )
|
|
|
|
{
|
2014-01-07 13:15:40 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// Remove all subpolygons that make the zone
|
2015-06-04 12:54:07 +00:00
|
|
|
std::deque<RN_POLY>& polygons = m_zones.at( aZone ).m_Polygons;
|
2014-01-07 13:15:40 +00:00
|
|
|
BOOST_FOREACH( RN_POLY& polygon, polygons )
|
2014-02-03 16:40:39 +00:00
|
|
|
{
|
2015-06-04 12:54:08 +00:00
|
|
|
RN_NODE_PTR node = polygon.GetNode();
|
|
|
|
node->RemoveParent( aZone );
|
2014-02-03 16:40:39 +00:00
|
|
|
|
|
|
|
if( m_links.RemoveNode( node ) )
|
|
|
|
clearNode( node );
|
|
|
|
}
|
2014-01-07 13:15:40 +00:00
|
|
|
polygons.clear();
|
|
|
|
|
|
|
|
// Remove all connections added by the zone
|
2015-06-04 12:54:07 +00:00
|
|
|
std::deque<RN_EDGE_MST_PTR>& edges = m_zones.at( aZone ).m_Edges;
|
2015-03-09 12:41:34 +00:00
|
|
|
BOOST_FOREACH( RN_EDGE_PTR edge, edges )
|
2014-01-07 13:15:40 +00:00
|
|
|
m_links.RemoveConnection( edge );
|
|
|
|
edges.clear();
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-07 13:15:40 +00:00
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const RN_NODE_PTR RN_NET::GetClosestNode( const RN_NODE_PTR& aNode ) const
|
|
|
|
{
|
|
|
|
const RN_LINKS::RN_NODE_SET& nodes = m_links.GetNodes();
|
|
|
|
RN_LINKS::RN_NODE_SET::const_iterator it, itEnd;
|
|
|
|
|
|
|
|
unsigned int minDistance = std::numeric_limits<unsigned int>::max();
|
|
|
|
RN_NODE_PTR closest;
|
|
|
|
|
|
|
|
for( it = nodes.begin(), itEnd = nodes.end(); it != itEnd; ++it )
|
|
|
|
{
|
2014-01-31 13:41:15 +00:00
|
|
|
RN_NODE_PTR node = *it;
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
// Obviously the distance between node and itself is the shortest,
|
|
|
|
// that's why we have to skip it
|
2014-01-31 13:41:15 +00:00
|
|
|
if( node != aNode )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-01-31 13:41:15 +00:00
|
|
|
unsigned int distance = getDistance( node, aNode );
|
2013-11-25 15:50:03 +00:00
|
|
|
if( distance < minDistance )
|
|
|
|
{
|
|
|
|
minDistance = distance;
|
2014-01-31 13:41:15 +00:00
|
|
|
closest = node;
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-20 10:54:48 +00:00
|
|
|
const RN_NODE_PTR RN_NET::GetClosestNode( const RN_NODE_PTR& aNode,
|
|
|
|
const RN_NODE_FILTER& aFilter ) const
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
|
|
|
const RN_LINKS::RN_NODE_SET& nodes = m_links.GetNodes();
|
|
|
|
RN_LINKS::RN_NODE_SET::const_iterator it, itEnd;
|
|
|
|
|
|
|
|
unsigned int minDistance = std::numeric_limits<unsigned int>::max();
|
|
|
|
RN_NODE_PTR closest;
|
|
|
|
|
|
|
|
for( it = nodes.begin(), itEnd = nodes.end(); it != itEnd; ++it )
|
|
|
|
{
|
2014-01-31 12:19:59 +00:00
|
|
|
RN_NODE_PTR node = *it;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// Obviously the distance between node and itself is the shortest,
|
|
|
|
// that's why we have to skip it
|
2014-01-31 12:19:59 +00:00
|
|
|
if( node != aNode && aFilter( node ) )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-01-31 12:19:59 +00:00
|
|
|
unsigned int distance = getDistance( node, aNode );
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
if( distance < minDistance )
|
|
|
|
{
|
|
|
|
minDistance = distance;
|
2014-01-31 12:19:59 +00:00
|
|
|
closest = node;
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::list<RN_NODE_PTR> RN_NET::GetClosestNodes( const RN_NODE_PTR& aNode, int aNumber ) const
|
|
|
|
{
|
|
|
|
std::list<RN_NODE_PTR> closest;
|
|
|
|
const RN_LINKS::RN_NODE_SET& nodes = m_links.GetNodes();
|
|
|
|
|
|
|
|
// Copy nodes
|
|
|
|
BOOST_FOREACH( const RN_NODE_PTR& node, nodes )
|
|
|
|
closest.push_back( node );
|
|
|
|
|
|
|
|
// Sort by the distance from aNode
|
2015-06-05 15:49:00 +00:00
|
|
|
closest.sort( boost::bind( sortDistance, boost::cref( aNode ), _1, _2 ) );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// Remove the first node (==aNode), as it is surely located within the smallest distance
|
2015-06-23 22:28:21 +00:00
|
|
|
assert( closest.front() == aNode );
|
2013-11-25 15:50:03 +00:00
|
|
|
closest.pop_front();
|
|
|
|
|
|
|
|
// Trim the result to the asked size
|
|
|
|
if( aNumber > 0 )
|
|
|
|
closest.resize( std::min( (size_t)aNumber, nodes.size() ) );
|
|
|
|
|
|
|
|
return closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::list<RN_NODE_PTR> RN_NET::GetClosestNodes( const RN_NODE_PTR& aNode,
|
2013-12-20 10:54:48 +00:00
|
|
|
const RN_NODE_FILTER& aFilter, int aNumber ) const
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
|
|
|
std::list<RN_NODE_PTR> closest;
|
|
|
|
const RN_LINKS::RN_NODE_SET& nodes = m_links.GetNodes();
|
|
|
|
|
|
|
|
// Copy nodes
|
|
|
|
BOOST_FOREACH( const RN_NODE_PTR& node, nodes )
|
|
|
|
closest.push_back( node );
|
|
|
|
|
|
|
|
// Sort by the distance from aNode
|
2015-06-05 15:49:00 +00:00
|
|
|
closest.sort( boost::bind( sortDistance, boost::cref( aNode ), _1, _2 ) );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// Remove the first node (==aNode), as it is surely located within the smallest distance
|
2015-06-23 22:28:21 +00:00
|
|
|
assert( closest.front() == aNode );
|
2013-11-25 15:50:03 +00:00
|
|
|
closest.pop_front();
|
|
|
|
|
|
|
|
// Filter out by condition
|
|
|
|
std::remove_if( closest.begin(), closest.end(), aFilter );
|
|
|
|
|
|
|
|
// Trim the result to the asked size
|
|
|
|
if( aNumber > 0 )
|
|
|
|
closest.resize( std::min( static_cast<size_t>( aNumber ), nodes.size() ) );
|
|
|
|
|
|
|
|
return closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-05 15:49:00 +00:00
|
|
|
void RN_NET::AddSimple( const BOARD_CONNECTED_ITEM* aItem )
|
|
|
|
{
|
2015-06-23 22:28:21 +00:00
|
|
|
BOOST_FOREACH( RN_NODE_PTR node, GetNodes( aItem ) )
|
|
|
|
{
|
|
|
|
// Block all nodes, so they do not become targets for dynamic ratsnest lines
|
|
|
|
AddBlockedNode( node );
|
2015-06-05 15:49:00 +00:00
|
|
|
|
2015-06-23 22:28:21 +00:00
|
|
|
// Filter out junctions
|
|
|
|
if( node->GetRefCount() == 1 )
|
|
|
|
m_simpleNodes.insert( node );
|
|
|
|
}
|
2015-06-05 15:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
std::list<RN_NODE_PTR> RN_NET::GetNodes( const BOARD_CONNECTED_ITEM* aItem ) const
|
|
|
|
{
|
|
|
|
std::list<RN_NODE_PTR> nodes;
|
|
|
|
|
2014-01-31 13:41:15 +00:00
|
|
|
try
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-01-31 13:41:15 +00:00
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
|
|
|
const D_PAD* pad = static_cast<const D_PAD*>( aItem );
|
|
|
|
nodes.push_back( m_pads.at( pad ) );
|
|
|
|
}
|
|
|
|
break;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-31 13:41:15 +00:00
|
|
|
case PCB_VIA_T:
|
|
|
|
{
|
2014-04-25 06:00:04 +00:00
|
|
|
const VIA* via = static_cast<const VIA*>( aItem );
|
2014-01-31 13:41:15 +00:00
|
|
|
nodes.push_back( m_vias.at( via ) );
|
|
|
|
}
|
|
|
|
break;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-31 13:41:15 +00:00
|
|
|
case PCB_TRACE_T:
|
|
|
|
{
|
|
|
|
const TRACK* track = static_cast<const TRACK*>( aItem );
|
2015-03-09 12:41:34 +00:00
|
|
|
const RN_EDGE_MST_PTR& edge = m_tracks.at( track );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-04-07 11:32:09 +00:00
|
|
|
nodes.push_back( edge->GetSourceNode() );
|
|
|
|
nodes.push_back( edge->GetTargetNode() );
|
2014-01-31 13:41:15 +00:00
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
break;
|
2014-01-31 13:41:15 +00:00
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
case PCB_ZONE_AREA_T:
|
|
|
|
{
|
|
|
|
const ZONE_CONTAINER* zone = static_cast<const ZONE_CONTAINER*>( aItem );
|
2015-06-04 12:54:07 +00:00
|
|
|
const std::deque<RN_POLY>& polys = m_zones.at( zone ).m_Polygons;
|
2015-06-04 12:54:07 +00:00
|
|
|
|
|
|
|
for( std::deque<RN_POLY>::const_iterator it = polys.begin(); it != polys.end(); ++it )
|
|
|
|
nodes.push_back( it->GetNode() );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-01-31 13:41:15 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-06-04 12:54:07 +00:00
|
|
|
catch( ... )
|
2014-01-31 13:41:15 +00:00
|
|
|
{
|
2015-06-05 15:49:00 +00:00
|
|
|
// It is fine, just return empty list of nodes
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-10 08:36:04 +00:00
|
|
|
void RN_NET::GetAllItems( std::list<BOARD_CONNECTED_ITEM*>& aOutput, RN_ITEM_TYPE aType ) const
|
|
|
|
{
|
|
|
|
if( aType & RN_PADS )
|
|
|
|
{
|
2015-06-05 15:49:00 +00:00
|
|
|
BOOST_FOREACH( const BOARD_CONNECTED_ITEM* item, m_pads | boost::adaptors::map_keys )
|
|
|
|
aOutput.push_back( const_cast<BOARD_CONNECTED_ITEM*>( item ) );
|
2015-03-10 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aType & RN_VIAS )
|
|
|
|
{
|
2015-06-05 15:49:00 +00:00
|
|
|
BOOST_FOREACH( const BOARD_CONNECTED_ITEM* item, m_vias | boost::adaptors::map_keys )
|
|
|
|
aOutput.push_back( const_cast<BOARD_CONNECTED_ITEM*>( item ) );
|
2015-03-10 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aType & RN_TRACKS )
|
|
|
|
{
|
2015-06-05 15:49:00 +00:00
|
|
|
BOOST_FOREACH( const BOARD_CONNECTED_ITEM* item, m_tracks | boost::adaptors::map_keys )
|
|
|
|
aOutput.push_back( const_cast<BOARD_CONNECTED_ITEM*>( item ) );
|
2015-03-10 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aType & RN_ZONES )
|
|
|
|
{
|
2015-06-05 15:49:00 +00:00
|
|
|
BOOST_FOREACH( const BOARD_CONNECTED_ITEM* item, m_zones | boost::adaptors::map_keys )
|
|
|
|
aOutput.push_back( const_cast<BOARD_CONNECTED_ITEM*>( item ) );
|
2015-03-10 08:36:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
void RN_NET::ClearSimple()
|
|
|
|
{
|
|
|
|
BOOST_FOREACH( const RN_NODE_PTR& node, m_blockedNodes )
|
|
|
|
node->SetFlag( false );
|
|
|
|
|
|
|
|
m_blockedNodes.clear();
|
2015-06-23 22:28:21 +00:00
|
|
|
m_simpleNodes.clear();
|
2015-03-09 12:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_NET::GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
|
|
|
|
std::list<BOARD_CONNECTED_ITEM*>& aOutput,
|
2015-03-10 08:36:04 +00:00
|
|
|
RN_ITEM_TYPE aTypes ) const
|
2015-03-09 12:41:34 +00:00
|
|
|
{
|
|
|
|
std::list<RN_NODE_PTR> nodes = GetNodes( aItem );
|
|
|
|
assert( !nodes.empty() );
|
|
|
|
|
|
|
|
int tag = nodes.front()->GetTag();
|
|
|
|
assert( tag >= 0 );
|
|
|
|
|
|
|
|
if( aTypes & RN_PADS )
|
|
|
|
{
|
|
|
|
for( PAD_NODE_MAP::const_iterator it = m_pads.begin(); it != m_pads.end(); ++it )
|
|
|
|
{
|
|
|
|
if( it->second->GetTag() == tag )
|
|
|
|
aOutput.push_back( const_cast<D_PAD*>( it->first ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aTypes & RN_VIAS )
|
|
|
|
{
|
|
|
|
for( VIA_NODE_MAP::const_iterator it = m_vias.begin(); it != m_vias.end(); ++it )
|
|
|
|
{
|
|
|
|
if( it->second->GetTag() == tag )
|
|
|
|
aOutput.push_back( const_cast<VIA*>( it->first ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aTypes & RN_TRACKS )
|
|
|
|
{
|
|
|
|
for( TRACK_EDGE_MAP::const_iterator it = m_tracks.begin(); it != m_tracks.end(); ++it )
|
|
|
|
{
|
|
|
|
if( it->second->GetTag() == tag )
|
|
|
|
aOutput.push_back( const_cast<TRACK*>( it->first ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aTypes & RN_ZONES )
|
|
|
|
{
|
2015-06-04 12:54:07 +00:00
|
|
|
for( ZONE_DATA_MAP::const_iterator it = m_zones.begin(); it != m_zones.end(); ++it )
|
2015-03-09 12:41:34 +00:00
|
|
|
{
|
2015-06-04 12:54:07 +00:00
|
|
|
BOOST_FOREACH( const RN_EDGE_MST_PTR& edge, it->second.m_Edges )
|
2015-03-09 12:41:34 +00:00
|
|
|
{
|
|
|
|
if( edge->GetTag() == tag )
|
|
|
|
{
|
|
|
|
aOutput.push_back( const_cast<ZONE_CONTAINER*>( it->first ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
void RN_DATA::AddSimple( const BOARD_ITEM* aItem )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-01-28 15:30:58 +00:00
|
|
|
int net;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
if( aItem->IsConnected() )
|
|
|
|
{
|
|
|
|
const BOARD_CONNECTED_ITEM* item = static_cast<const BOARD_CONNECTED_ITEM*>( aItem );
|
2014-02-25 10:47:27 +00:00
|
|
|
net = item->GetNetCode();
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
if( net < 1 ) // do not process unconnected items
|
|
|
|
return;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2015-06-05 15:49:00 +00:00
|
|
|
m_nets[net].AddSimple( item );
|
2014-01-28 15:30:58 +00:00
|
|
|
}
|
|
|
|
else if( aItem->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
const MODULE* module = static_cast<const MODULE*>( aItem );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
|
|
|
|
AddSimple( pad );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-31 17:05:11 +00:00
|
|
|
void RN_DATA::AddBlocked( const BOARD_ITEM* aItem )
|
|
|
|
{
|
|
|
|
int net;
|
|
|
|
|
|
|
|
if( aItem->IsConnected() )
|
|
|
|
{
|
|
|
|
const BOARD_CONNECTED_ITEM* item = static_cast<const BOARD_CONNECTED_ITEM*>( aItem );
|
2014-02-25 10:47:27 +00:00
|
|
|
net = item->GetNetCode();
|
2014-01-31 17:05:11 +00:00
|
|
|
|
|
|
|
if( net < 1 ) // do not process unconnected items
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Block all nodes belonging to the item
|
|
|
|
BOOST_FOREACH( RN_NODE_PTR node, m_nets[net].GetNodes( item ) )
|
|
|
|
m_nets[net].AddBlockedNode( node );
|
|
|
|
}
|
|
|
|
else if( aItem->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
const MODULE* module = static_cast<const MODULE*>( aItem );
|
|
|
|
|
|
|
|
for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
|
|
|
|
AddBlocked( pad );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
void RN_DATA::GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
|
|
|
|
std::list<BOARD_CONNECTED_ITEM*>& aOutput,
|
2015-03-10 08:36:04 +00:00
|
|
|
RN_ITEM_TYPE aTypes ) const
|
2015-03-09 12:41:34 +00:00
|
|
|
{
|
|
|
|
int net = aItem->GetNetCode();
|
|
|
|
|
|
|
|
if( net < 1 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert( net < (int) m_nets.size() );
|
|
|
|
|
|
|
|
m_nets[net].GetConnectedItems( aItem, aOutput, aTypes );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-10 08:36:04 +00:00
|
|
|
void RN_DATA::GetNetItems( int aNetCode, std::list<BOARD_CONNECTED_ITEM*>& aOutput,
|
|
|
|
RN_ITEM_TYPE aTypes ) const
|
|
|
|
{
|
|
|
|
if( aNetCode < 1 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert( aNetCode < (int) m_nets.size() );
|
|
|
|
|
|
|
|
m_nets[aNetCode].GetAllItems( aOutput, aTypes );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-09 12:41:34 +00:00
|
|
|
bool RN_DATA::AreConnected( const BOARD_CONNECTED_ITEM* aItem, const BOARD_CONNECTED_ITEM* aOther )
|
|
|
|
{
|
|
|
|
int net1 = aItem->GetNetCode();
|
|
|
|
int net2 = aOther->GetNetCode();
|
|
|
|
|
|
|
|
if( net1 < 1 || net2 < 1 || net1 != net2 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
assert( net1 < (int) m_nets.size() && net2 < (int) m_nets.size() );
|
|
|
|
|
|
|
|
// net1 == net2
|
|
|
|
std::list<RN_NODE_PTR> items1 = m_nets[net1].GetNodes( aItem );
|
|
|
|
std::list<RN_NODE_PTR> items2 = m_nets[net1].GetNodes( aOther );
|
|
|
|
|
|
|
|
assert( !items1.empty() && !items2.empty() );
|
|
|
|
|
|
|
|
return ( items1.front()->GetTag() == items2.front()->GetTag() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-03 18:58:12 +00:00
|
|
|
int RN_DATA::GetUnconnectedCount() const
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_nets.size(); ++i )
|
|
|
|
{
|
|
|
|
const std::vector<RN_EDGE_MST_PTR>* unconnected = m_nets[i].GetUnconnected();
|
|
|
|
|
|
|
|
if( unconnected )
|
|
|
|
count += unconnected->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
void RN_NET::processZones()
|
|
|
|
{
|
2015-06-04 12:54:08 +00:00
|
|
|
for( ZONE_DATA_MAP::iterator it = m_zones.begin(); it != m_zones.end(); ++it )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2015-06-04 12:54:08 +00:00
|
|
|
const ZONE_CONTAINER* zone = it->first;
|
|
|
|
RN_ZONE_DATA& zoneData = it->second;
|
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
// Reset existing connections
|
|
|
|
BOOST_FOREACH( RN_EDGE_MST_PTR edge, zoneData.m_Edges )
|
2013-11-25 15:50:03 +00:00
|
|
|
m_links.RemoveConnection( edge );
|
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
zoneData.m_Edges.clear();
|
2015-06-04 12:54:08 +00:00
|
|
|
LSET layers = zone->GetLayerSet();
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
// Compute new connections
|
2015-06-04 12:54:07 +00:00
|
|
|
RN_LINKS::RN_NODE_SET candidates = m_links.GetNodes();
|
2013-11-25 15:50:03 +00:00
|
|
|
RN_LINKS::RN_NODE_SET::iterator point, pointEnd;
|
|
|
|
|
|
|
|
// Sorting by area should speed up the processing, as smaller polygons are computed
|
|
|
|
// faster and may reduce the number of points for further checks
|
2015-06-04 12:54:07 +00:00
|
|
|
std::sort( zoneData.m_Polygons.begin(), zoneData.m_Polygons.end(), sortArea );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
for( std::deque<RN_POLY>::iterator poly = zoneData.m_Polygons.begin(),
|
|
|
|
polyEnd = zoneData.m_Polygons.end(); poly != polyEnd; ++poly )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2015-06-04 12:54:07 +00:00
|
|
|
const RN_NODE_PTR& node = poly->GetNode();
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
point = candidates.begin();
|
|
|
|
pointEnd = candidates.end();
|
|
|
|
|
|
|
|
while( point != pointEnd )
|
|
|
|
{
|
2015-06-04 12:54:08 +00:00
|
|
|
if( *point != node && ( (*point)->GetLayers() & layers ).any()
|
|
|
|
&& poly->HitTest( *point ) )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2015-06-04 12:54:06 +00:00
|
|
|
RN_EDGE_MST_PTR connection = m_links.AddConnection( node, *point );
|
2015-06-04 12:54:07 +00:00
|
|
|
zoneData.m_Edges.push_back( connection );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// This point already belongs to a polygon, we do not need to check it anymore
|
|
|
|
point = candidates.erase( point );
|
|
|
|
pointEnd = candidates.end();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++point;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
void RN_DATA::Add( const BOARD_ITEM* aItem )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-01-28 15:30:58 +00:00
|
|
|
int net;
|
|
|
|
|
|
|
|
if( aItem->IsConnected() )
|
|
|
|
{
|
2014-02-25 10:47:27 +00:00
|
|
|
net = static_cast<const BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode();
|
2014-01-28 15:30:58 +00:00
|
|
|
if( net < 1 ) // do not process unconnected items
|
|
|
|
return;
|
2014-01-30 14:46:39 +00:00
|
|
|
|
2014-06-03 14:08:23 +00:00
|
|
|
if( net >= (int) m_nets.size() ) // Autoresize
|
2014-01-30 14:46:39 +00:00
|
|
|
m_nets.resize( net + 1 );
|
2014-01-28 15:30:58 +00:00
|
|
|
}
|
|
|
|
else if( aItem->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
const MODULE* module = static_cast<const MODULE*>( aItem );
|
|
|
|
for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
|
|
|
|
{
|
2014-02-25 10:47:27 +00:00
|
|
|
net = pad->GetNetCode();
|
2014-06-03 14:08:23 +00:00
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
if( net < 1 ) // do not process unconnected items
|
|
|
|
continue;
|
|
|
|
|
2014-06-03 14:08:23 +00:00
|
|
|
if( net >= (int) m_nets.size() ) // Autoresize
|
2014-01-30 14:46:39 +00:00
|
|
|
m_nets.resize( net + 1 );
|
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
m_nets[net].AddItem( pad );
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2013-11-25 15:50:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case PCB_PAD_T:
|
2014-01-28 15:30:58 +00:00
|
|
|
m_nets[net].AddItem( static_cast<const D_PAD*>( aItem ) );
|
|
|
|
break;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
case PCB_TRACE_T:
|
2014-01-28 15:30:58 +00:00
|
|
|
m_nets[net].AddItem( static_cast<const TRACK*>( aItem ) );
|
|
|
|
break;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
case PCB_VIA_T:
|
2014-04-25 06:00:04 +00:00
|
|
|
m_nets[net].AddItem( static_cast<const VIA*>( aItem ) );
|
2014-01-28 15:30:58 +00:00
|
|
|
break;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
case PCB_ZONE_AREA_T:
|
2014-01-28 15:30:58 +00:00
|
|
|
m_nets[net].AddItem( static_cast<const ZONE_CONTAINER*>( aItem ) );
|
|
|
|
break;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
void RN_DATA::Remove( const BOARD_ITEM* aItem )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-01-28 15:30:58 +00:00
|
|
|
int net;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
if( aItem->IsConnected() )
|
|
|
|
{
|
2014-02-25 10:47:27 +00:00
|
|
|
net = static_cast<const BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode();
|
2014-06-03 14:08:23 +00:00
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
if( net < 1 ) // do not process unconnected items
|
|
|
|
return;
|
2014-06-03 14:08:23 +00:00
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
if( net >= (int) m_nets.size() ) // Autoresize
|
|
|
|
{
|
|
|
|
m_nets.resize( net + 1 );
|
|
|
|
|
|
|
|
return; // if it was resized, then surely the item had not been added before
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
assert( net < (int) m_nets.size() );
|
2014-01-28 15:30:58 +00:00
|
|
|
}
|
|
|
|
else if( aItem->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
const MODULE* module = static_cast<const MODULE*>( aItem );
|
|
|
|
for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-02-25 10:47:27 +00:00
|
|
|
net = pad->GetNetCode();
|
2014-06-03 14:08:23 +00:00
|
|
|
|
2014-01-28 15:30:58 +00:00
|
|
|
if( net < 1 ) // do not process unconnected items
|
|
|
|
continue;
|
|
|
|
|
2014-06-03 14:08:23 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
if( net >= (int) m_nets.size() ) // Autoresize
|
|
|
|
{
|
|
|
|
m_nets.resize( net + 1 );
|
|
|
|
|
|
|
|
return; // if it was resized, then surely the item had not been added before
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
assert( net < (int) m_nets.size() );
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
m_nets[net].RemoveItem( pad );
|
|
|
|
}
|
2014-01-28 15:30:58 +00:00
|
|
|
|
|
|
|
return;
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
2014-01-28 15:30:58 +00:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case PCB_PAD_T:
|
|
|
|
m_nets[net].RemoveItem( static_cast<const D_PAD*>( aItem ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TRACE_T:
|
|
|
|
m_nets[net].RemoveItem( static_cast<const TRACK*>( aItem ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_VIA_T:
|
2014-04-25 06:00:04 +00:00
|
|
|
m_nets[net].RemoveItem( static_cast<const VIA*>( aItem ) );
|
2014-01-28 15:30:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_ZONE_AREA_T:
|
|
|
|
m_nets[net].RemoveItem( static_cast<const ZONE_CONTAINER*>( aItem ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_DATA::Update( const BOARD_ITEM* aItem )
|
|
|
|
{
|
|
|
|
Remove( aItem );
|
|
|
|
Add( aItem );
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_DATA::ProcessBoard()
|
|
|
|
{
|
2015-06-04 12:54:07 +00:00
|
|
|
int netCount = m_board->GetNetCount();
|
2013-11-25 15:50:03 +00:00
|
|
|
m_nets.clear();
|
2015-06-04 12:54:07 +00:00
|
|
|
m_nets.resize( netCount );
|
2014-02-28 10:12:55 +00:00
|
|
|
int netCode;
|
2013-11-25 15:50:03 +00:00
|
|
|
|
|
|
|
// Iterate over all items that may need to be connected
|
|
|
|
for( MODULE* module = m_board->m_Modules; module; module = module->Next() )
|
|
|
|
{
|
|
|
|
for( D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
|
2014-02-28 10:12:55 +00:00
|
|
|
{
|
2014-03-06 08:42:16 +00:00
|
|
|
netCode = pad->GetNetCode();
|
2014-02-28 10:12:55 +00:00
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
assert( netCode >= 0 && netCode < netCount );
|
|
|
|
|
|
|
|
if( netCode > 0 && netCode < netCount )
|
2014-02-28 10:12:55 +00:00
|
|
|
m_nets[netCode].AddItem( pad );
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( TRACK* track = m_board->m_Track; track; track = track->Next() )
|
|
|
|
{
|
2014-03-06 08:42:16 +00:00
|
|
|
netCode = track->GetNetCode();
|
2014-02-28 10:12:55 +00:00
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
assert( netCode >= 0 && netCode < netCount );
|
|
|
|
|
|
|
|
if( netCode > 0 && netCode < netCount )
|
2014-02-28 10:12:55 +00:00
|
|
|
{
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
2014-04-25 06:00:04 +00:00
|
|
|
m_nets[netCode].AddItem( static_cast<VIA*>( track ) );
|
2014-02-28 10:12:55 +00:00
|
|
|
else if( track->Type() == PCB_TRACE_T )
|
|
|
|
m_nets[netCode].AddItem( track );
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( int i = 0; i < m_board->GetAreaCount(); ++i )
|
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zone = m_board->GetArea( i );
|
2014-03-06 09:43:40 +00:00
|
|
|
|
2014-03-06 08:42:16 +00:00
|
|
|
netCode = zone->GetNetCode();
|
2014-02-28 10:12:55 +00:00
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
assert( netCode >= 0 && netCode < netCount );
|
|
|
|
|
|
|
|
if( netCode > 0 && netCode < netCount )
|
2014-02-28 10:12:55 +00:00
|
|
|
m_nets[netCode].AddItem( zone );
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
2014-07-09 13:10:32 +00:00
|
|
|
|
|
|
|
Recalculate();
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RN_DATA::Recalculate( int aNet )
|
|
|
|
{
|
2014-06-03 14:08:23 +00:00
|
|
|
unsigned int netCount = m_board->GetNetCount();
|
|
|
|
|
|
|
|
if( netCount > m_nets.size() )
|
|
|
|
m_nets.resize( netCount );
|
2014-06-02 09:41:54 +00:00
|
|
|
|
2015-04-30 08:46:06 +00:00
|
|
|
if( aNet < 0 && netCount > 1 ) // Recompute everything
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2015-06-04 12:54:06 +00:00
|
|
|
#ifdef PROFILE
|
|
|
|
prof_counter totalRealTime;
|
|
|
|
prof_start( &totalRealTime );
|
|
|
|
#endif
|
|
|
|
|
2014-06-03 14:08:23 +00:00
|
|
|
unsigned int i;
|
2015-04-30 08:46:06 +00:00
|
|
|
|
2014-01-31 17:27:06 +00:00
|
|
|
#ifdef USE_OPENMP
|
2014-03-05 13:57:14 +00:00
|
|
|
#pragma omp parallel shared(netCount) private(i)
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2014-03-05 13:57:14 +00:00
|
|
|
#pragma omp for schedule(guided, 1)
|
2014-01-31 17:27:06 +00:00
|
|
|
#else /* USE_OPENMP */
|
|
|
|
{
|
|
|
|
#endif
|
2014-03-05 13:57:14 +00:00
|
|
|
// Start with net number 1, as 0 stands for not connected
|
2014-01-31 17:27:06 +00:00
|
|
|
for( i = 1; i < netCount; ++i )
|
|
|
|
{
|
|
|
|
if( m_nets[i].IsDirty() )
|
|
|
|
updateNet( i );
|
|
|
|
}
|
2014-03-05 13:57:14 +00:00
|
|
|
} /* end of parallel section */
|
2015-06-04 12:54:06 +00:00
|
|
|
#ifdef PROFILE
|
|
|
|
prof_end( &totalRealTime );
|
|
|
|
|
|
|
|
wxLogDebug( wxT( "Recalculate all nets: %.1f ms" ), totalRealTime.msecs() );
|
|
|
|
#endif /* PROFILE */
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
2013-12-20 14:18:41 +00:00
|
|
|
else if( aNet > 0 ) // Recompute only specific net
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
|
|
|
updateNet( aNet );
|
|
|
|
}
|
|
|
|
}
|
2014-01-31 17:05:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
void RN_DATA::updateNet( int aNetCode )
|
|
|
|
{
|
|
|
|
assert( aNetCode < (int) m_nets.size() );
|
2014-02-05 10:55:04 +00:00
|
|
|
|
2014-03-21 17:00:11 +00:00
|
|
|
if( aNetCode < 1 || aNetCode > (int) m_nets.size() )
|
2014-01-31 17:05:11 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_nets[aNetCode].ClearSimple();
|
|
|
|
m_nets[aNetCode].Update();
|
|
|
|
}
|