Commit 190af5d9 authored by Maciej Suminski's avatar Maciej Suminski

Added functions to resolve connectivity queries in ratsnest (GAL).

parent e6a10faa
......@@ -100,6 +100,9 @@ protected:
/// Node coordinates
int m_x, m_y;
/// Tag for quick connection resolution
int m_tag;
/// Reference count
unsigned int m_refCount;
......@@ -112,7 +115,7 @@ public:
#ifdef TTL_USE_NODE_ID
m_id( id_count++ ),
#endif
m_x( aX ), m_y( aY ), m_refCount( 0 )
m_x( aX ), m_y( aY ), m_tag( -1 ), m_refCount( 0 )
{
}
......@@ -120,20 +123,32 @@ public:
~NODE() {}
/// Returns the x-coordinate
int GetX() const
inline int GetX() const
{
return m_x;
}
/// Returns the y-coordinate
int GetY() const
inline int GetY() const
{
return m_y;
}
/// Returns tag, common identifier for connected nodes
inline int GetTag() const
{
return m_tag;
}
/// Sets tag, common identifier for connected nodes
inline void SetTag( int aTag )
{
m_tag = aTag;
}
#ifdef TTL_USE_NODE_ID
/// Returns the id (TTL_USE_NODE_ID must be defined)
int Id() const
inline int Id() const
{
return m_id;
}
......@@ -141,29 +156,29 @@ public:
#ifdef TTL_USE_NODE_FLAG
/// Sets the flag (TTL_USE_NODE_FLAG must be defined)
void SetFlag( bool aFlag )
inline void SetFlag( bool aFlag )
{
m_flag = aFlag;
}
/// Returns the flag (TTL_USE_NODE_FLAG must be defined)
const bool& GetFlag() const
inline const bool& GetFlag() const
{
return m_flag;
}
#endif
void IncRefCount()
inline void IncRefCount()
{
m_refCount++;
}
void DecRefCount()
inline void DecRefCount()
{
m_refCount--;
}
unsigned int GetRefCount() const
inline unsigned int GetRefCount() const
{
return m_refCount;
}
......@@ -187,55 +202,65 @@ public:
{
}
/// Returns tag, common identifier for connected nodes
inline int GetTag() const
{
int tag = GetSourceNode()->GetTag();
if( tag >= 0 )
return tag;
return GetTargetNode()->GetTag();
}
/// Sets the source node
void SetSourceNode( const NODE_PTR& aNode )
inline void SetSourceNode( const NODE_PTR& aNode )
{
m_sourceNode = aNode;
}
/// Sets the next edge in face
void SetNextEdgeInFace( const EDGE_PTR& aEdge )
inline void SetNextEdgeInFace( const EDGE_PTR& aEdge )
{
m_nextEdgeInFace = aEdge;
}
/// Sets the twin edge
void SetTwinEdge( const EDGE_PTR& aEdge )
inline void SetTwinEdge( const EDGE_PTR& aEdge )
{
m_twinEdge = aEdge;
}
/// Sets the edge as a leading edge
void SetAsLeadingEdge( bool aLeading = true )
inline void SetAsLeadingEdge( bool aLeading = true )
{
m_isLeadingEdge = aLeading;
}
/// Checks if an edge is a leading edge
bool IsLeadingEdge() const
inline bool IsLeadingEdge() const
{
return m_isLeadingEdge;
}
/// Returns the twin edge
EDGE_PTR GetTwinEdge() const
inline EDGE_PTR GetTwinEdge() const
{
return m_twinEdge.lock();
}
void ClearTwinEdge()
inline void ClearTwinEdge()
{
m_twinEdge.reset();
}
/// Returns the next edge in face
const EDGE_PTR& GetNextEdgeInFace() const
inline const EDGE_PTR& GetNextEdgeInFace() const
{
return m_nextEdgeInFace;
}
/// Retuns the source node
const NODE_PTR& GetSourceNode() const
inline const NODE_PTR& GetSourceNode() const
{
return m_sourceNode;
}
......@@ -246,12 +271,12 @@ public:
return m_nextEdgeInFace->GetSourceNode();
}
void SetWeight( unsigned int weight )
inline void SetWeight( unsigned int weight )
{
m_weight = weight;
}
unsigned int GetWeight() const
inline unsigned int GetWeight() const
{
return m_weight;
}
......@@ -294,22 +319,17 @@ public:
m_weight = aWeight;
}
EDGE_MST( const EDGE& edge )
{
m_sourceNode = edge.GetSourceNode();
m_target = edge.GetTargetNode();
m_weight = edge.GetWeight();
}
~EDGE_MST()
{
}
/// @copydoc Edge::setSourceNode()
virtual const NODE_PTR& GetTargetNode() const
{
return m_target;
}
private:
EDGE_MST( const EDGE& aEdge )
{
assert( false );
}
};
class DART; // Forward declaration (class in this namespace)
......
This diff is collapsed.
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* Copyright (C) 2013-2015 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
......@@ -49,6 +49,16 @@ class TRACK;
class ZONE_CONTAINER;
class CPolyPt;
///> Types of items that are handled by the class
enum RN_ITEM_TYPES
{
RN_PADS = 0x01,
RN_VIAS = 0x02,
RN_TRACKS = 0x04,
RN_ZONES = 0x08,
RN_ALL = 0xFF
};
// Preserve KiCad coding style policy
typedef hed::NODE RN_NODE;
typedef hed::NODE_PTR RN_NODE_PTR;
......@@ -157,7 +167,7 @@ public:
* @param aDistance is the distance of the connection (0 means that nodes are actually
* connected, >0 means a missing connection).
*/
const RN_EDGE_PTR& AddConnection( const RN_NODE_PTR& aNode1, const RN_NODE_PTR& aNode2,
RN_EDGE_MST_PTR AddConnection( const RN_NODE_PTR& aNode1, const RN_NODE_PTR& aNode2,
unsigned int aDistance = 0 );
/**
......@@ -181,7 +191,7 @@ public:
}
protected:
///> Set of nodes that are used are expected to be connected together.
///> Set of nodes that are expected to be connected together (vias, tracks, pads).
RN_NODE_SET m_nodes;
///> List of edges that currently connect nodes.
......@@ -210,7 +220,6 @@ public:
return m_node;
}
/**
* Function GetParent()
* Returns pointer to zone that is the owner of subpolygon.
......@@ -307,7 +316,7 @@ public:
* Returns pointer to a vector of edges that makes ratsnest for a given net.
* @return Pointer to a vector of edges that makes ratsnest for a given net.
*/
const std::vector<RN_EDGE_PTR>* GetUnconnected() const
const std::vector<RN_EDGE_MST_PTR>* GetUnconnected() const
{
return m_rnEdges.get();
}
......@@ -429,22 +438,12 @@ public:
std::list<RN_NODE_PTR> GetClosestNodes( const RN_NODE_PTR& aNode,
const RN_NODE_FILTER& aFilter, int aNumber = -1 ) const;
/**
* Function GetEdges()
* Returns pointer to the vector of edges that makes ratsnest for a given net.
* @return Pointer to the vector of edges that makes ratsnest for a given net.
*/
const std::vector<RN_EDGE_PTR>* GetEdges() const
{
return m_rnEdges.get();
}
/**
* Function AddSimpleNode()
* Changes drawing mode for a node to simple (i.e. one ratsnest line per node).
* @param aNode is a node that changes its drawing mode.
*/
void AddSimpleNode( RN_NODE_PTR& aNode )
inline void AddSimpleNode( RN_NODE_PTR& aNode )
{
m_simpleNodes.push_back( aNode );
aNode->SetFlag( true );
......@@ -456,7 +455,7 @@ public:
* target the node). The status is cleared after calling ClearSimple().
* @param aNode is the node that is not going to be used as a ratsnest line target.
*/
void AddBlockedNode( RN_NODE_PTR& aNode )
inline void AddBlockedNode( RN_NODE_PTR& aNode )
{
m_blockedNodes.push_back( aNode );
aNode->SetFlag( true );
......@@ -468,7 +467,7 @@ public:
* ratsnest line per node).
* @return list of nodes for which ratsnest is drawn in simple mode.
*/
const std::deque<RN_NODE_PTR>& GetSimpleNodes() const
inline const std::deque<RN_NODE_PTR>& GetSimpleNodes() const
{
return m_simpleNodes;
}
......@@ -477,22 +476,23 @@ public:
* Function ClearSimple()
* Removes all nodes and edges that are used for displaying ratsnest in simple mode.
*/
void ClearSimple()
{
BOOST_FOREACH( const RN_NODE_PTR& node, m_simpleNodes )
node->SetFlag( false );
BOOST_FOREACH( const RN_NODE_PTR& node, m_blockedNodes )
node->SetFlag( false );
void ClearSimple();
m_simpleNodes.clear();
m_blockedNodes.clear();
}
/**
* Function GetConnectedItems()
* Adds items that are connected together to a list.
* @param aItem is the reference item to find other connected items.
* @param aOutput is the list that will contain found items.
* @param aTypes allows to filter by item types.
*/
void GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
std::list<BOARD_CONNECTED_ITEM*>& aOutput,
RN_ITEM_TYPES aTypes = RN_ALL) const;
protected:
///> Validates edge, i.e. modifies source and target nodes for an edge
///> to make sure that they are not ones with the flag set.
void validateEdge( RN_EDGE_PTR& aEdge );
void validateEdge( RN_EDGE_MST_PTR& aEdge );
///> Removes all ratsnest edges for a given node.
void clearNode( const RN_NODE_PTR& aNode );
......@@ -507,31 +507,37 @@ protected:
RN_LINKS m_links;
///> Vector of edges that makes ratsnest for a given net.
boost::shared_ptr< std::vector<RN_EDGE_PTR> > m_rnEdges;
boost::shared_ptr< std::vector<RN_EDGE_MST_PTR> > m_rnEdges;
///> List of nodes for which ratsnest is drawn in simple mode.
std::deque<RN_NODE_PTR> m_simpleNodes;
///> List of nodes which should 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;
///> Flag indicating necessity of recalculation of ratsnest for a net.
bool m_dirty;
///> Helper typedefs
typedef boost::unordered_map<const D_PAD*, RN_NODE_PTR> PAD_NODE_MAP;
typedef boost::unordered_map<const VIA*, RN_NODE_PTR> VIA_NODE_MAP;
typedef boost::unordered_map<const TRACK*, RN_EDGE_MST_PTR> TRACK_EDGE_MAP;
typedef boost::unordered_map<const ZONE_CONTAINER*, std::deque<RN_POLY> > ZONE_POLY_MAP;
typedef boost::unordered_map<const ZONE_CONTAINER*, std::deque<RN_EDGE_MST_PTR> > ZONE_EDGE_MAP;
///> Map that associates nodes in the ratsnest model to respective nodes.
boost::unordered_map<const D_PAD*, RN_NODE_PTR> m_pads;
PAD_NODE_MAP m_pads;
///> Map that associates nodes in the ratsnest model to respective vias.
boost::unordered_map<const VIA*, RN_NODE_PTR> m_vias;
VIA_NODE_MAP m_vias;
///> Map that associates edges in the ratsnest model to respective tracks.
boost::unordered_map<const TRACK*, RN_EDGE_PTR> m_tracks;
TRACK_EDGE_MAP m_tracks;
///> Map that associates groups of subpolygons in the ratsnest model to their respective zones.
boost::unordered_map<const ZONE_CONTAINER*, std::deque<RN_POLY> > m_zonePolygons;
///> Map that associates groups of subpolygons in the ratsnest model to respective zones.
ZONE_POLY_MAP m_zonePolygons;
///> Map that associates groups of edges in the ratsnest model to their respective zones.
boost::unordered_map<const ZONE_CONTAINER*, std::deque<RN_EDGE_PTR> > m_zoneConnections;
///> Map that associates groups of edges in the ratsnest model to respective zones.
ZONE_EDGE_MAP m_zoneConnections;
///> Visibility flag.
bool m_visible;
......@@ -646,6 +652,26 @@ public:
return m_nets[aNetCode];
}
/**
* Function GetConnectedItems()
* Adds items that are connected together to a list.
* @param aItem is the reference item to find other connected items.
* @param aOutput is the list that will contain found items.
* @param aTypes allows to filter by item types.
*/
void GetConnectedItems( const BOARD_CONNECTED_ITEM* aItem,
std::list<BOARD_CONNECTED_ITEM*>& aOutput,
RN_ITEM_TYPES aTypes = RN_ALL ) const;
/**
* Function AreConnected()
* Checks if two items are connected with copper.
* @param aThis is the first item.
* @param aOther is the second item.
* @return True if they are connected, false otherwise.
*/
bool AreConnected( const BOARD_CONNECTED_ITEM* aItem, const BOARD_CONNECTED_ITEM* aOther );
protected:
/**
* Function updateNet()
......
......@@ -72,7 +72,7 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, GAL* aGal ) const
// Set brighter color for the temporary ratsnest
aGal->SetStrokeColor( color.Brightened( 0.8 ) );
// Draw the "dynamic" ratsnest (ie. 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() )
{
RN_NODE_PTR dest = net.GetClosestNode( node, WITHOUT_FLAG() );
......@@ -93,11 +93,12 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, GAL* aGal ) const
if( i != highlightedNet )
aGal->SetStrokeColor( color ); // using the default ratsnest color for not highlighted
const std::vector<RN_EDGE_PTR>* edges = net.GetUnconnected();
const std::vector<RN_EDGE_MST_PTR>* edges = net.GetUnconnected();
if( edges == NULL )
continue;
BOOST_FOREACH( const RN_EDGE_PTR& edge, *edges )
BOOST_FOREACH( const RN_EDGE_MST_PTR& edge, *edges )
{
const RN_NODE_PTR& sourceNode = edge->GetSourceNode();
const RN_NODE_PTR& targetNode = edge->GetTargetNode();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment