KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_link_holder.h
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2019 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * Author: Seth Hillbrand <[email protected]>
8 * Author: Tomasz Wlostowski <[email protected]>
9 *
10 * This program is free software: you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation, either version 3 of the License, or (at your
13 * option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#ifndef PCBNEW_ROUTER_PNS_LINK_HOLDER_H_
25#define PCBNEW_ROUTER_PNS_LINK_HOLDER_H_
26
27#include <core/kicad_algo.h>
28#include <algorithm>
29
30#include <wx/log.h>
31
32#include "pns_item.h"
33#include "pns_linked_item.h"
34
35
36namespace PNS
37{
38class LINK_HOLDER : public ITEM
39{
40public:
42 ITEM( aKind )
43 {}
44
46 void Link( LINKED_ITEM* aLink )
47 {
48 if( alg::contains( m_links, aLink ) )
49 {
50 wxLogDebug( wxT( "PNS LINK_HOLDER::Link: item %p already linked to %p" ), aLink, this );
51 return;
52 }
53
54 m_links.push_back( aLink );
55 }
56
57 void Unlink( const LINKED_ITEM* aLink )
58 {
59 wxCHECK_MSG( alg::contains( m_links, aLink ), /* void */,
60 "Trying to unlink an item that is not linked" );
61 std::erase( m_links, aLink );
62 }
63
66 std::vector<LINKED_ITEM*>& Links() { return m_links; }
67 const std::vector<LINKED_ITEM*>& Links() const { return m_links; }
68
69 bool IsLinked() const
70 {
71 return m_links.size() != 0;
72 }
73
75 bool ContainsLink( const LINKED_ITEM* aItem ) const
76 {
77 return alg::contains( m_links, aItem );
78 }
79
80 LINKED_ITEM* GetLink( int aIndex ) const
81 {
82 if( aIndex < 0 )
83 aIndex += m_links.size();
84
85 return m_links[aIndex];
86 }
87
89 virtual void ClearLinks()
90 {
91 m_links.clear();
92 }
93
95 int LinkCount() const
96 {
97 return m_links.size();
98 }
99
100 void ShowLinks() const
101 {
102#if 0
103 if( !IsLinked() )
104 {
105 wxLogTrace( wxT( "PNS" ), wxT( "item %p: no links" ), this );
106 return;
107 }
108
109 wxLogTrace( wxT( "PNS" ), wxT( "item %p: %d links" ), this, (int) m_links.size() );
110
111 for( int i = 0; i < (int) m_links.size(); i++ )
112 wxLogTrace( wxT( "PNS" ), wxT( "item %d: %p\n" ), i, m_links[i] );
113#endif
114 }
115
116protected:
118 void copyLinks( const LINK_HOLDER* aParent )
119 {
120 m_links = aParent->m_links;
121 }
122
125 std::vector<LINKED_ITEM*> m_links;
126};
127
128} // namespace PNS
129#endif /* PCBNEW_ROUTER_PNS_LINK_HOLDER_H_ */
ITEM(PnsKind aKind)
Definition pns_item.h:116
PnsKind
< Supported item types
Definition pns_item.h:102
Push and Shove diff pair dimensions (gap) settings dialog.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:100