KiCad PCB EDA Suite
ratsnest_data.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KICAD, a free EDA CAD application.
3  *
4  * Copyright (C) 2013-2015 CERN
5  * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
32 #ifndef RATSNEST_DATA_H
33 #define RATSNEST_DATA_H
34 
35 #include <core/typeinfo.h>
36 #include <math/box2.h>
37 
38 #include <set>
39 #include <vector>
40 
42 
43 class BOARD_ITEM;
45 class CN_CLUSTER;
46 
47 struct CN_PTR_CMP
48 {
49  bool operator()( const CN_ANCHOR_PTR& aItem, const CN_ANCHOR_PTR& bItem ) const
50  {
51  if( aItem->Pos().x == bItem->Pos().x )
52  return aItem->Pos().y < bItem->Pos().y;
53  else
54  return aItem->Pos().x < bItem->Pos().x;
55  }
56 };
57 
61 class RN_NET
62 {
63 public:
64  RN_NET();
65 
72  void SetVisible( bool aEnabled );
73 
77  void MarkDirty()
78  {
79  m_dirty = true;
80  }
81 
88  bool IsDirty() const
89  {
90  return m_dirty;
91  }
92 
98  const std::vector<CN_EDGE> GetUnconnected() const
99  {
100  return m_rnEdges;
101  }
102 
106  void Update();
107  void Clear();
108 
109  void AddCluster( std::shared_ptr<CN_CLUSTER> aCluster );
110 
111  unsigned int GetNodeCount() const
112  {
113  return m_nodes.size();
114  }
115 
122  std::list<CN_ANCHOR_PTR> GetNodes( const BOARD_CONNECTED_ITEM* aItem ) const;
123 
124  const std::vector<CN_EDGE>& GetEdges() const
125  {
126  return m_rnEdges;
127  }
128 
135  void GetAllItems( std::list<BOARD_CONNECTED_ITEM*>& aOutput, const KICAD_T aTypes[] ) const;
136 
142  const CN_ANCHOR_PTR GetClosestNode( const CN_ANCHOR_PTR& aNode ) const;
143 
144  bool NearestBicoloredPair( const RN_NET& aOtherNet, CN_ANCHOR_PTR& aNode1,
145  CN_ANCHOR_PTR& aNode2 ) const;
146 
147 protected:
149  void compute();
150 
152  void kruskalMST( const std::vector<CN_EDGE> &aEdges );
153 
155  std::multiset<CN_ANCHOR_PTR, CN_PTR_CMP> m_nodes;
156 
158  std::vector<CN_EDGE> m_boardEdges;
159 
161  std::vector<CN_EDGE> m_rnEdges;
162 
164  bool m_dirty;
165 
167 
168  std::shared_ptr<TRIANGULATOR_STATE> m_triangulator;
169 };
170 
171 #endif /* RATSNEST_DATA_H */
void Update()
Recompute ratsnest for a net.
const std::vector< CN_EDGE > GetUnconnected() const
Return pointer to a vector of edges that makes ratsnest for a given net.
Definition: ratsnest_data.h:98
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
const CN_ANCHOR_PTR GetClosestNode(const CN_ANCHOR_PTR &aNode) const
Return a single node that lies in the shortest distance from a specific node.
bool m_dirty
bool operator()(const CN_ANCHOR_PTR &aItem, const CN_ANCHOR_PTR &bItem) const
Definition: ratsnest_data.h:49
std::vector< CN_EDGE > m_rnEdges
Flag indicating necessity of recalculation of ratsnest for a net.
void compute()
< Recompute ratsnest from scratch.
void MarkDirty()
Mark ratsnest for given net as 'dirty', i.e.
Definition: ratsnest_data.h:77
void GetAllItems(std::list< BOARD_CONNECTED_ITEM * > &aOutput, const KICAD_T aTypes[]) const
Add all stored items to a list.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
void Clear()
void kruskalMST(const std::vector< CN_EDGE > &aEdges)
Vector of nodes.
void SetVisible(bool aEnabled)
Set state of the visibility flag.
unsigned int GetNodeCount() const
const std::vector< CN_EDGE > & GetEdges() const
bool NearestBicoloredPair(const RN_NET &aOtherNet, CN_ANCHOR_PTR &aNode1, CN_ANCHOR_PTR &aNode2) const
void AddCluster(std::shared_ptr< CN_CLUSTER > aCluster)
std::shared_ptr< TRIANGULATOR_STATE > m_triangulator
std::vector< CN_EDGE > m_boardEdges
Vector of edges that makes ratsnest for a given net.
std::shared_ptr< CN_ANCHOR > CN_ANCHOR_PTR
Describe ratsnest for a single net.
Definition: ratsnest_data.h:61
std::list< CN_ANCHOR_PTR > GetNodes(const BOARD_CONNECTED_ITEM *aItem) const
Return list of nodes that are associated with a given item.
std::multiset< CN_ANCHOR_PTR, CN_PTR_CMP > m_nodes
Vector of edges that make pre-defined connections.
bool IsDirty() const
Return state of the 'dirty' flag, indicating that ratsnest for a given net is invalid and requires an...
Definition: ratsnest_data.h:88