KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[email protected]>
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, see <https://www.gnu.org/licenses/>.
21 */
22
27
28#ifndef RATSNEST_DATA_H
29#define RATSNEST_DATA_H
30
31#include <algorithm>
32#include <core/typeinfo.h>
33#include <math/box2.h>
34
35#include <set>
36#include <vector>
37
39
40class BOARD_ITEM;
42class CN_CLUSTER;
43
45{
46 bool operator()( const std::shared_ptr<CN_ANCHOR>& aItem,
47 const std::shared_ptr<CN_ANCHOR>& bItem ) const
48 {
49 if( aItem->Pos().x == bItem->Pos().x )
50 return aItem->Pos().y < bItem->Pos().y;
51 else
52 return aItem->Pos().x < bItem->Pos().x;
53 }
54};
55
59class RN_NET
60{
61public:
62 RN_NET();
63
70 bool IsDirty() const { return m_dirty; }
71
75 void UpdateNet();
76
77 void RemoveInvalidRefs();
78
85 void OptimizeRNEdges();
86
87 void Clear();
88
89 void AddCluster( std::shared_ptr<CN_CLUSTER> aCluster );
90
91 unsigned int GetNodeCount() const { return m_nodes.size(); }
92
93 const std::vector<CN_EDGE>& GetEdges() const
94 {
95 // Use a const_cast to allow sorting in the const method
96 // This is safe because we're not changing the logical content of the vector,
97 // just the ordering of elements
98 std::stable_sort( const_cast<std::vector<CN_EDGE>&>( m_rnEdges ).begin(),
99 const_cast<std::vector<CN_EDGE>&>( m_rnEdges ).end(),
100 []( const CN_EDGE& a, const CN_EDGE& b )
101 {
102 return a.StableSortCompare( b );
103 } );
104 return m_rnEdges;
105 }
106 std::vector<CN_EDGE>& GetEdges()
107 {
108 std::stable_sort( m_rnEdges.begin(), m_rnEdges.end(),
109 []( const CN_EDGE& a, const CN_EDGE& b )
110 {
111 return a.StableSortCompare( b );
112 } );
113 return m_rnEdges;
114 }
115
116 bool NearestBicoloredPair( RN_NET* aOtherNet, VECTOR2I& aPos1, VECTOR2I& aPos2 ) const;
117
118protected:
120 void compute();
121
123 void kruskalMST( const std::vector<CN_EDGE> &aEdges );
124
125protected:
127 std::multiset<std::shared_ptr<CN_ANCHOR>, CN_PTR_CMP> m_nodes;
128
130 std::vector<CN_EDGE> m_boardEdges;
131
133 std::vector<CN_EDGE> m_rnEdges;
134
137
138 class TRIANGULATOR_STATE;
139
140 std::shared_ptr<TRIANGULATOR_STATE> m_triangulator;
141};
142
143#endif /* RATSNEST_DATA_H */
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:80
CN_EDGE represents a point-to-point connection, whether realized or unrealized (ie: tracks etc.
bool StableSortCompare(const CN_EDGE &aOther) const
Comparison operator for std::stable_sort.
Describe ratsnest for a single net.
unsigned int GetNodeCount() const
std::shared_ptr< TRIANGULATOR_STATE > m_triangulator
std::multiset< std::shared_ptr< CN_ANCHOR >, CN_PTR_CMP > m_nodes
< Vector of nodes
void RemoveInvalidRefs()
void kruskalMST(const std::vector< CN_EDGE > &aEdges)
void UpdateNet()
Recompute ratsnest for a net.
std::vector< CN_EDGE > & GetEdges()
const std::vector< CN_EDGE > & GetEdges() const
std::vector< CN_EDGE > m_rnEdges
Flag indicating necessity of recalculation of ratsnest for a net.
void OptimizeRNEdges()
Find optimal ends of RNEdges.
bool NearestBicoloredPair(RN_NET *aOtherNet, VECTOR2I &aPos1, VECTOR2I &aPos2) const
bool m_dirty
std::vector< CN_EDGE > m_boardEdges
Vector of edges that makes ratsnest for a given net.
void compute()
< Recompute ratsnest from scratch.
bool IsDirty() const
Return state of the 'dirty' flag, indicating that ratsnest for a given net is invalid and requires an...
void Clear()
void AddCluster(std::shared_ptr< CN_CLUSTER > aCluster)
bool operator()(const std::shared_ptr< CN_ANCHOR > &aItem, const std::shared_ptr< CN_ANCHOR > &bItem) const
VECTOR2I end
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683