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-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #ifndef RATSNEST_DATA_H
32 #define RATSNEST_DATA_H
33 
34 #include <core/typeinfo.h>
35 #include <math/box2.h>
36 
37 #include <set>
38 #include <vector>
39 
41 
42 class BOARD_ITEM;
44 class CN_CLUSTER;
45 
46 struct CN_PTR_CMP
47 {
48  bool operator()( const CN_ANCHOR_PTR& aItem, const CN_ANCHOR_PTR& bItem ) const
49  {
50  if( aItem->Pos().x == bItem->Pos().x )
51  return aItem->Pos().y < bItem->Pos().y;
52  else
53  return aItem->Pos().x < bItem->Pos().x;
54  }
55 };
56 
61 class RN_NET
62 {
63 public:
65  RN_NET();
66 
73  void SetVisible( bool aEnabled );
74 
79  void MarkDirty()
80  {
81  m_dirty = true;
82  }
83 
90  bool IsDirty() const
91  {
92  return m_dirty;
93  }
94 
100  const std::vector<CN_EDGE> GetUnconnected() const
101  {
102  return m_rnEdges;
103  }
104 
109  void Update();
110  void Clear();
111 
112  void AddCluster( std::shared_ptr<CN_CLUSTER> aCluster );
113 
114  unsigned int GetNodeCount() const
115  {
116  return m_nodes.size();
117  }
118 
125  std::list<CN_ANCHOR_PTR> GetNodes( const BOARD_CONNECTED_ITEM* aItem ) const;
126 
127  const std::vector<CN_EDGE>& GetEdges() const
128  {
129  return m_rnEdges;
130  }
131 
138  void GetAllItems( std::list<BOARD_CONNECTED_ITEM*>& aOutput, const KICAD_T aTypes[] ) const;
139 
145  const CN_ANCHOR_PTR GetClosestNode( const CN_ANCHOR_PTR& aNode ) const;
146 
147  bool NearestBicoloredPair( const RN_NET& aOtherNet, CN_ANCHOR_PTR& aNode1, CN_ANCHOR_PTR& aNode2 ) const;
148 
149 protected:
151  void compute();
152 
154  void kruskalMST( const std::vector<CN_EDGE> &aEdges );
155 
157  std::multiset<CN_ANCHOR_PTR, CN_PTR_CMP> m_nodes;
158 
160  std::vector<CN_EDGE> m_boardEdges;
161 
163  std::vector<CN_EDGE> m_rnEdges;
164 
166  bool m_dirty;
167 
169 
170  std::shared_ptr<TRIANGULATOR_STATE> m_triangulator;
171 };
172 
173 #endif /* RATSNEST_DATA_H */
void Update()
Function Update() Recomputes ratsnest for a net.
const std::vector< CN_EDGE > GetUnconnected() const
Function GetUnconnected() Returns pointer to a vector of edges that makes ratsnest for a given net.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
const CN_ANCHOR_PTR GetClosestNode(const CN_ANCHOR_PTR &aNode) const
Function GetClosestNode() Returns a single node that lies in the shortest distance from a specific no...
bool m_dirty
Flag indicating necessity of recalculation of ratsnest for a net.
bool operator()(const CN_ANCHOR_PTR &aItem, const CN_ANCHOR_PTR &bItem) const
Definition: ratsnest_data.h:48
std::vector< CN_EDGE > m_rnEdges
Vector of edges that makes ratsnest for a given net.
void compute()
Recomputes ratsnest from scratch.
void MarkDirty()
Function MarkDirty() Marks ratsnest for given net as 'dirty', i.e.
Definition: ratsnest_data.h:79
void GetAllItems(std::list< BOARD_CONNECTED_ITEM * > &aOutput, const KICAD_T aTypes[]) const
Function GetAllItems() Adds all stored items to a list.
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
RN_NET()
Default constructor.
void Clear()
void kruskalMST(const std::vector< CN_EDGE > &aEdges)
Compute the minimum spanning tree using Kruskal's algorithm
void SetVisible(bool aEnabled)
Function SetVisible() Sets 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 make pre-defined connections
std::shared_ptr< CN_ANCHOR > CN_ANCHOR_PTR
RN_NET Describes ratsnest for a single net.
Definition: ratsnest_data.h:61
std::list< CN_ANCHOR_PTR > GetNodes(const BOARD_CONNECTED_ITEM *aItem) const
Function GetNodes() Returns list of nodes that are associated with a given item.
std::multiset< CN_ANCHOR_PTR, CN_PTR_CMP > m_nodes
Vector of nodes
bool IsDirty() const
Function IsDirty() Returns state of the 'dirty' flag, indicating that ratsnest for a given net is inv...
Definition: ratsnest_data.h:90