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 (C) 2021 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 "pns_item.h"
29#include "pns_linked_item.h"
30
31namespace PNS
32{
33class LINK_HOLDER : public ITEM
34{
35public:
36 LINK_HOLDER( PnsKind aKind ) : ITEM( aKind )
37 {}
38
40 void Link( LINKED_ITEM* aLink )
41 {
42 wxCHECK_MSG( !alg::contains( m_links, aLink ), /* void */,
43 "Trying to link an item that is already linked" );
44 m_links.push_back( aLink );
45 }
46
47 void Unlink( const LINKED_ITEM* aLink )
48 {
49 wxCHECK_MSG( alg::contains( m_links, aLink ), /* void */,
50 "Trying to unlink an item that is not linked" );
52 }
53
56 std::vector<LINKED_ITEM*>& Links() { return m_links; }
57 const std::vector<LINKED_ITEM*>& Links() const { return m_links; }
58
59 bool IsLinked() const
60 {
61 return m_links.size() != 0;
62 }
63
65 bool ContainsLink( const LINKED_ITEM* aItem ) const
66 {
67 return alg::contains( m_links, aItem );
68 }
69
70 LINKED_ITEM* GetLink( int aIndex ) const
71 {
72 if( aIndex < 0 )
73 aIndex += m_links.size();
74 return m_links[aIndex];
75 }
76
78 virtual void ClearLinks()
79 {
80 m_links.clear();
81 }
82
84 int LinkCount() const
85 {
86 return m_links.size();
87 }
88
89 void ShowLinks() const
90 {
91#if 0
92 if( !IsLinked() )
93 {
94 wxLogTrace( wxT( "PNS" ), wxT( "item %p: no links" ), this );
95 return;
96 }
97
98 wxLogTrace( wxT( "PNS" ), wxT( "item %p: %d links" ), this, (int) m_links.size() );
99
100 for( int i = 0; i < (int) m_links.size(); i++ )
101 wxLogTrace( wxT( "PNS" ), wxT( "item %d: %p\n" ), i, m_links[i] );
102#endif
103 }
104
105protected:
107 void copyLinks( const LINK_HOLDER* aParent )
108 {
109 m_links = aParent->m_links;
110 }
111
114 std::vector<LINKED_ITEM*> m_links;
115};
116
117} // namespace PNS
118#endif /* PCBNEW_ROUTER_PNS_LINK_HOLDER_H_ */
Base class for PNS router board items.
Definition: pns_item.h:97
PnsKind
< Supported item types
Definition: pns_item.h:101
Push and Shove diff pair dimensions (gap) settings dialog.
void delete_matching(_Container &__c, _Value __value)
Covers for the horrifically named std::remove and std::remove_if (neither of which remove anything).
Definition: kicad_algo.h:165
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:100