KiCad PCB EDA Suite
connect.h
Go to the documentation of this file.
1 
5 #ifndef CONNECT_H
6 #define CONNECT_H
7 
8 /*
9  * This program source code file is part of KiCad, a free EDA CAD application.
10  *
11  * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
12  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
13  * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, you may find one here:
27  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
28  * or you may search the http://www.gnu.org website for the version 2 license,
29  * or you may write to the Free Software Foundation, Inc.,
30  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
31  */
32 
33 #include <class_track.h>
34 #include <class_board.h>
35 
36 
37 // Helper classes to handle connection points (i.e. candidates) for tracks
38 
39 /* class CONNECTED_POINT describes a coordinate having a track or pad parent.
40  * when a pad is the parent, the coordinate is (obviously) the connection point
41  * when a track is the parent, the coordinate is the staring point
42  * or the ending point.
43  * therefore when building a list of CONNECTED_POINT, a pad or via generates one item,
44  * and a track generates 2 items.
45  */
47 {
48 private:
49  BOARD_CONNECTED_ITEM * m_item; // a link to the parent item (track, via or pad)
50  wxPoint m_point; // coordinates of this connected point
51 
52 public:
53  // ctor to build a CONNECTED_POINT instance, when the parent is a track or via
54  CONNECTED_POINT( TRACK * aTrack, const wxPoint & aPoint)
55  {
56  m_item = aTrack;
57  m_point = aPoint;
58  }
59 
60  // ctor to build a CONNECTED_POINT instance, when the parent is a pad
61  CONNECTED_POINT( D_PAD * aPad, const wxPoint & aPoint)
62  {
63  m_item = aPad;
64  m_point = aPoint;
65  }
66 
72  TRACK* GetTrack() const
73  {
74  return m_item->Type() != PCB_PAD_T ? (TRACK*) m_item : NULL ;
75  }
76 
82  D_PAD * GetPad() const
83  {
84  return m_item->Type() == PCB_PAD_T ? (D_PAD*) m_item : NULL;
85  }
86 
87  const wxPoint & GetPoint() const { return m_point; }
88 };
89 
90 // A helper class to handle connections calculations:
92 {
93 private:
94  std::vector <TRACK*> m_connected; // List of connected tracks/vias
95  // to a given track or via
96  std::vector <CONNECTED_POINT> m_candidates; // List of points to test
97  // (end points of tracks or vias location )
98  BOARD * m_brd; // the master board.
99  const TRACK * m_firstTrack; // The first track used to build m_Candidates
100  const TRACK * m_lastTrack; // The last track used to build m_Candidates
101  std::vector<D_PAD*> m_sortedPads; // list of sorted pads by X (then Y) coordinate
102 
103 public:
104  CONNECTIONS( BOARD * aBrd );
106 
114  void BuildPadsList( int aNetcode = -1 );
115 
120  std::vector<D_PAD*>& GetPadsList() { return m_sortedPads; }
121 
136  void Build_CurrNet_SubNets_Connections( TRACK* aFirstTrack, TRACK* aLastTrack, int aNetcode );
137 
146  void BuildTracksCandidatesList( TRACK * aBegin, TRACK * aEnd = NULL);
147 
154 
161  int SearchConnectedTracks( const TRACK * aTrack );
162 
170  void GetConnectedTracks(TRACK * aTrack)
171  {
172  aTrack->m_TracksConnected = m_connected;
173  }
174 
183 
196  void SearchTracksConnectedToPads( bool add_to_padlist = true, bool add_to_tracklist = true);
197 
207  void CollectItemsNearTo( std::vector<CONNECTED_POINT*>& aList,
208  const wxPoint& aPosition, int aDistMax );
209 
224  void Propagate_SubNets();
225 
226 private:
236  int searchEntryPointInCandidatesList( const wxPoint & aPoint);
237 
249  int Merge_SubNets( int aOldSubNet, int aNewSubNet );
250 
260  int Merge_PadsSubNets( int aOldSubNet, int aNewSubNet );
261 };
262 
263 #endif // ifndef CONNECT_H
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
wxPoint m_point
Definition: connect.h:50
void GetConnectedTracks(TRACK *aTrack)
Function GetConnectedTracks Copy m_Connected that contains the list of tracks connected calculated by...
Definition: connect.h:170
Class BOARD to handle a board.
void BuildPadsCandidatesList()
Function BuildPadsCandidatesList Populates m_candidates with all pads connecting points (pads positio...
Definition: connect.cpp:227
CONNECTED_POINT(D_PAD *aPad, const wxPoint &aPoint)
Definition: connect.h:61
void Build_CurrNet_SubNets_Connections(TRACK *aFirstTrack, TRACK *aLastTrack, int aNetcode)
Function Build_CurrNet_SubNets_Connections should be called after a track change (delete or add a tra...
Definition: connect.cpp:459
int Merge_PadsSubNets(int aOldSubNet, int aNewSubNet)
Function Merge_PadsSubNets Change a subnet value to a new value, in m_sortedPads pad list After that...
Definition: connect.cpp:500
CONNECTIONS(BOARD *aBrd)
Definition: connect.cpp:49
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
BOARD * m_brd
Definition: connect.h:98
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
const TRACK * m_lastTrack
Definition: connect.h:100
void Propagate_SubNets()
Function Propagate_SubNets Test a list of tracks, to create or propagate a sub netcode to pads and se...
Definition: connect.cpp:584
Functions relatives to tracks, vias and segments used to fill zones.
void BuildPadsList(int aNetcode=-1)
Function BuildPadsList Fills m_sortedPads with all pads that be connected to tracks pads are sorted b...
Definition: connect.cpp:61
std::vector< D_PAD * > m_sortedPads
Definition: connect.h:101
const wxPoint & GetPoint() const
Definition: connect.h:87
void BuildTracksCandidatesList(TRACK *aBegin, TRACK *aEnd=NULL)
Function BuildTracksCandidatesList Fills m_Candidates with all connecting points (track ends or via l...
Definition: connect.cpp:252
std::vector< D_PAD * > & GetPadsList()
Function GetPadsList.
Definition: connect.h:120
TRACK * GetTrack() const
Function GetTrack.
Definition: connect.h:72
int SearchConnectedTracks(const TRACK *aTrack)
function SearchConnectedTracks Populates .m_connected with tracks/vias connected to aTrack m_candidat...
Definition: connect.cpp:306
void SearchConnectionsPadsToIntersectingPads()
function SearchConnectionsPadsToIntersectingPads Explores the list of pads and adds to m_PadsConnecte...
Definition: connect.cpp:72
void SearchTracksConnectedToPads(bool add_to_padlist=true, bool add_to_tracklist=true)
function SearchTracksConnectedToPads Explores the list of pads.
Definition: connect.cpp:114
int Merge_SubNets(int aOldSubNet, int aNewSubNet)
Function Merge_SubNets Change a subnet old value to a new value, for tracks and pads which are connec...
Definition: connect.cpp:529
std::vector< CONNECTED_POINT > m_candidates
Definition: connect.h:96
~CONNECTIONS()
Definition: connect.h:105
CONNECTED_POINT(TRACK *aTrack, const wxPoint &aPoint)
Definition: connect.h:54
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
void CollectItemsNearTo(std::vector< CONNECTED_POINT * > &aList, const wxPoint &aPosition, int aDistMax)
function CollectItemsNearTo Used by SearchTracksConnectedToPads Fills aList with pads near to aPositi...
Definition: connect.cpp:146
const TRACK * m_firstTrack
Definition: connect.h:99
std::vector< TRACK * > m_TracksConnected
BOARD_CONNECTED_ITEM * m_item
Definition: connect.h:49
int searchEntryPointInCandidatesList(const wxPoint &aPoint)
function searchEntryPointInCandidatesList Search an item in m_Connected connected to aPoint note m_Co...
Definition: connect.cpp:396
D_PAD * GetPad() const
Function GetPad.
Definition: connect.h:82
std::vector< TRACK * > m_connected
Definition: connect.h:94