kicad/pcbnew/ratsnest/ratsnest_data.h

174 lines
4.9 KiB
C
Raw Normal View History

2013-11-25 15:50:03 +00:00
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2013-2015 CERN
* Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
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.h
* @brief Class that computes missing connections on a PCB.
*/
#ifndef RATSNEST_DATA_H
#define RATSNEST_DATA_H
2017-03-22 13:43:10 +00:00
#include <core/typeinfo.h>
2013-11-25 15:50:03 +00:00
#include <math/box2.h>
2020-06-23 02:18:46 +00:00
#include <set>
#include <vector>
2017-03-22 13:43:10 +00:00
#include <connectivity/connectivity_algo.h>
2017-03-22 13:43:10 +00:00
2013-11-25 15:50:03 +00:00
class BOARD_ITEM;
class BOARD_CONNECTED_ITEM;
2017-03-22 13:43:10 +00:00
class CN_CLUSTER;
2020-06-23 02:18:46 +00:00
struct CN_PTR_CMP
{
bool operator()( const CN_ANCHOR_PTR& aItem, const CN_ANCHOR_PTR& bItem ) const
{
if( aItem->Pos().x == bItem->Pos().x )
return aItem->Pos().y < bItem->Pos().y;
else
return aItem->Pos().x < bItem->Pos().x;
}
};
2013-11-25 15:50:03 +00:00
/**
* RN_NET
2013-11-25 15:50:03 +00:00
* Describes ratsnest for a single net.
*/
class RN_NET
{
public:
///> Default constructor.
2017-03-22 13:43:10 +00:00
RN_NET();
2013-11-25 15:50:03 +00:00
/**
* Function SetVisible()
* Sets state of the visibility flag.
* @param aEnabled is new state. True if ratsnest for a given net is meant to be displayed,
* false otherwise.
*/
void SetVisible( bool aEnabled );
2017-06-23 11:56:28 +00:00
2013-11-25 15:50:03 +00:00
/**
* Function MarkDirty()
* Marks ratsnest for given net as 'dirty', i.e. requiring recomputation.
2013-11-25 15:50:03 +00:00
*/
void MarkDirty()
{
m_dirty = true;
}
2013-11-25 15:50:03 +00:00
/**
* Function IsDirty()
* Returns state of the 'dirty' flag, indicating that ratsnest for a given net is invalid
* and requires an update.
* @return True if ratsnest requires recomputation, false otherwise.
*/
bool IsDirty() const
{
return m_dirty;
}
/**
* Function GetUnconnected()
* 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.
*/
2017-03-22 13:43:10 +00:00
const std::vector<CN_EDGE> GetUnconnected() const
2013-11-25 15:50:03 +00:00
{
2017-03-22 13:43:10 +00:00
return m_rnEdges;
2013-11-25 15:50:03 +00:00
}
/**
* Function Update()
* Recomputes ratsnest for a net.
*/
void Update();
2017-03-22 13:43:10 +00:00
void Clear();
2013-11-25 15:50:03 +00:00
2017-03-22 13:43:10 +00:00
void AddCluster( std::shared_ptr<CN_CLUSTER> aCluster );
2013-11-25 15:50:03 +00:00
2017-06-23 12:20:08 +00:00
unsigned int GetNodeCount() const
{
return m_nodes.size();
}
2013-11-25 15:50:03 +00:00
/**
* Function GetNodes()
* Returns list of nodes that are associated with a given item.
* @param aItem is an item for which the list is generated.
* @return List of associated nodes.
*/
2017-03-22 13:43:10 +00:00
std::list<CN_ANCHOR_PTR> GetNodes( const BOARD_CONNECTED_ITEM* aItem ) const;
const std::vector<CN_EDGE>& GetEdges() const
{
return m_rnEdges;
}
2013-11-25 15:50:03 +00:00
2015-03-10 08:36:04 +00:00
/**
* Function GetAllItems()
2015-03-10 08:36:04 +00:00
* Adds all stored items to a list.
* @param aOutput is the list that will have items added.
2017-06-25 09:26:04 +00:00
* @param aTypes determines the type of added items.
2015-03-10 08:36:04 +00:00
*/
2017-03-22 13:43:10 +00:00
void GetAllItems( std::list<BOARD_CONNECTED_ITEM*>& aOutput, const KICAD_T aTypes[] ) const;
2015-03-10 08:36:04 +00:00
2013-11-25 15:50:03 +00:00
/**
* Function GetClosestNode()
* Returns a single node that lies in the shortest distance from a specific node.
* @param aNode is the node for which the closest node is searched.
*/
2017-03-22 13:43:10 +00:00
const CN_ANCHOR_PTR GetClosestNode( const CN_ANCHOR_PTR& aNode ) const;
bool NearestBicoloredPair( const RN_NET& aOtherNet, CN_ANCHOR_PTR& aNode1, CN_ANCHOR_PTR& aNode2 ) const;
2013-11-25 15:50:03 +00:00
protected:
2017-06-23 11:56:28 +00:00
///> Recomputes ratsnest from scratch.
2013-11-25 15:50:03 +00:00
void compute();
///> Compute the minimum spanning tree using Kruskal's algorithm
void kruskalMST( const std::vector<CN_EDGE> &aEdges );
2017-03-22 13:43:10 +00:00
///> Vector of nodes
2020-06-23 02:18:46 +00:00
std::multiset<CN_ANCHOR_PTR, CN_PTR_CMP> m_nodes;
2013-11-25 15:50:03 +00:00
2017-03-22 13:43:10 +00:00
///> Vector of edges that make pre-defined connections
std::vector<CN_EDGE> m_boardEdges;
2017-03-22 13:43:10 +00:00
///> Vector of edges that makes ratsnest for a given net.
std::vector<CN_EDGE> m_rnEdges;
2013-11-25 15:50:03 +00:00
///> Flag indicating necessity of recalculation of ratsnest for a net.
bool m_dirty;
2017-03-22 13:43:10 +00:00
class TRIANGULATOR_STATE;
2017-03-22 13:43:10 +00:00
std::shared_ptr<TRIANGULATOR_STATE> m_triangulator;
2013-11-25 15:50:03 +00:00
};
#endif /* RATSNEST_DATA_H */