KiCad PCB EDA Suite
FROM_TO_CACHE Class Reference

#include <from_to_cache.h>

Classes

struct  FT_ENDPOINT
 
struct  FT_PATH
 

Public Member Functions

 FROM_TO_CACHE (BOARD *aBoard=nullptr)
 
 ~FROM_TO_CACHE ()
 
void Rebuild (BOARD *aBoard)
 
bool IsOnFromToPath (BOARD_CONNECTED_ITEM *aItem, const wxString &aFrom, const wxString &aTo)
 
FT_PATHQueryFromToPath (const std::set< BOARD_CONNECTED_ITEM * > &aItems)
 

Private Member Functions

int cacheFromToPaths (const wxString &aFrom, const wxString &aTo)
 
void buildEndpointList ()
 

Private Attributes

std::vector< FT_ENDPOINTm_ftEndpoints
 
std::vector< FT_PATHm_ftPaths
 
BOARDm_board
 

Detailed Description

Definition at line 28 of file from_to_cache.h.

Constructor & Destructor Documentation

◆ FROM_TO_CACHE()

FROM_TO_CACHE::FROM_TO_CACHE ( BOARD aBoard = nullptr)
inline

Definition at line 49 of file from_to_cache.h.

49 :
50 m_board( aBoard )
51 {
52 }
BOARD * m_board
Definition: from_to_cache.h:71

◆ ~FROM_TO_CACHE()

FROM_TO_CACHE::~FROM_TO_CACHE ( )
inline

Definition at line 54 of file from_to_cache.h.

55 {
56 }

Member Function Documentation

◆ buildEndpointList()

void FROM_TO_CACHE::buildEndpointList ( )
private

Definition at line 33 of file from_to_cache.cpp.

34{
35 m_ftEndpoints.clear();
36
37 for( FOOTPRINT* footprint : m_board->Footprints() )
38 {
39 for( PAD* pad : footprint->Pads() )
40 {
41 FT_ENDPOINT ent;
42 ent.name = footprint->GetReference() + wxT( "-" ) + pad->GetNumber();
43 ent.parent = pad;
44 m_ftEndpoints.push_back( ent );
45 ent.name = footprint->GetReference();
46 ent.parent = pad;
47 m_ftEndpoints.push_back( ent );
48 }
49 }
50}
FOOTPRINTS & Footprints()
Definition: board.h:282
std::vector< FT_ENDPOINT > m_ftEndpoints
Definition: from_to_cache.h:68
Definition: pad.h:59

References BOARD::Footprints(), m_board, m_ftEndpoints, FROM_TO_CACHE::FT_ENDPOINT::name, pad, and FROM_TO_CACHE::FT_ENDPOINT::parent.

Referenced by Rebuild().

◆ cacheFromToPaths()

int FROM_TO_CACHE::cacheFromToPaths ( const wxString &  aFrom,
const wxString &  aTo 
)
private

Definition at line 122 of file from_to_cache.cpp.

123{
124 std::vector<FT_PATH> paths;
125 std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_board->GetConnectivity();
126 std::shared_ptr<CN_CONNECTIVITY_ALGO> cnAlgo = connectivity->GetConnectivityAlgo();
127
128 for( FT_ENDPOINT& endpoint : m_ftEndpoints )
129 {
130 if( WildCompareString( aFrom, endpoint.name, false ) )
131 {
132 FT_PATH p;
133 p.net = endpoint.parent->GetNetCode();
134 p.from = endpoint.parent;
135 p.to = nullptr;
136 paths.push_back(p);
137 }
138 }
139
140 for( FT_PATH& path : paths )
141 {
142 int count = 0;
143
144 wxString fromName = path.from->GetParent()->GetReference() + wxT( "-" )
145 + path.from->GetNumber();
146
147 auto padCandidates = connectivity->GetConnectedItems( path.from,
148 { PCB_PAD_T, PCB_ARC_T, PCB_VIA_T, PCB_TRACE_T } );
149 PAD* toPad = nullptr;
150
151 for( BOARD_CONNECTED_ITEM* pitem : padCandidates )
152 {
153 if( pitem == path.from )
154 continue;
155
156 if( pitem->Type() != PCB_PAD_T )
157 continue;
158
159 const PAD *pad = static_cast<const PAD*>( pitem );
160
161 wxString toName = pad->GetParent()->GetReference() + wxT( "-" ) + pad->GetNumber();
162
163
164 for( const FT_ENDPOINT& endpoint : m_ftEndpoints )
165 {
166 if( pad == endpoint.parent )
167 {
168 if( WildCompareString( aTo, endpoint.name, false ) )
169 {
170 count++;
171 toPad = endpoint.parent;
172
173 path.to = toPad;
174 path.fromName = fromName;
175 path.toName = toName;
176 path.fromWildcard = aFrom;
177 path.toWildcard = aTo;
178
179 if( count >= 2 )
180 {
181 // fixme: report this somewhere?
182 //printf("Multiple targets found, aborting...\n");
183 path.to = nullptr;
184 }
185 }
186 }
187 }
188 }
189 }
190
191 int newPaths = 0;
192
193 for( FT_PATH& path : paths )
194 {
195 if( !path.from || !path.to )
196 continue;
197
198 CN_ITEM* cnFrom = cnAlgo->ItemEntry( path.from ).GetItems().front();
199 CN_ITEM* cnTo = cnAlgo->ItemEntry( path.to ).GetItems().front();
200 std::vector<CN_ITEM*> upath;
201
202 auto result = uniquePathBetweenNodes( cnFrom, cnTo, upath );
203
204 if( result == PS_OK )
205 path.isUnique = true;
206 else
207 path.isUnique = false;
208
209
210 //printf( "%s\n", (const char *) wxString::Format( _("Check path: %s -> %s (net %s)"), path.fromName, path.toName, cnFrom->Parent()->GetNetname() ) );
211
212 if( result == PS_NO_PATH )
213 continue;
214
215 for( const auto item : upath )
216 {
217 path.pathItems.insert( item->Parent() );
218 }
219
220 m_ftPaths.push_back(path);
221 newPaths++;
222 }
223
224 // reportAux( _("Cached %d paths\n"), newPaths );
225
226 return newPaths;
227}
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:399
CN_ITEM represents a BOARD_CONNETED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
std::vector< FT_PATH > m_ftPaths
Definition: from_to_cache.h:69
@ PS_OK
@ PS_NO_PATH
static PATH_STATUS uniquePathBetweenNodes(CN_ITEM *u, CN_ITEM *v, std::vector< CN_ITEM * > &outPath)
bool WildCompareString(const wxString &pattern, const wxString &string_to_tst, bool case_sensitive)
Compare a string against wild card (* and ?) pattern using the usual rules.
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:89

References FROM_TO_CACHE::FT_PATH::from, BOARD::GetConnectivity(), m_board, m_ftEndpoints, m_ftPaths, FROM_TO_CACHE::FT_PATH::net, pad, path, PCB_PAD_T, PS_NO_PATH, PS_OK, FROM_TO_CACHE::FT_PATH::to, uniquePathBetweenNodes(), and WildCompareString().

Referenced by IsOnFromToPath().

◆ IsOnFromToPath()

bool FROM_TO_CACHE::IsOnFromToPath ( BOARD_CONNECTED_ITEM aItem,
const wxString &  aFrom,
const wxString &  aTo 
)

Definition at line 229 of file from_to_cache.cpp.

230{
231 int nFromTosFound = 0;
232
233 if( !m_board )
234 return false;
235
236 //printf("Check %d cached paths [%p]\n", m_ftPaths.size(), aItem );
237 for( int attempt = 0; attempt < 2; attempt++ )
238 {
239 // item already belongs to path
240 for( FT_PATH& ftPath : m_ftPaths )
241 {
242 if( aFrom == ftPath.fromWildcard && aTo == ftPath.toWildcard )
243 {
244 nFromTosFound++;
245
246 if( ftPath.pathItems.count( aItem ) )
247 {
248 // printf("Found cached path for %p [%s->%s]\n", aItem, (const char *)ftPath.fromName, (const char *) ftPath.toName );
249 return true;
250 }
251 }
252 }
253
254 if( !nFromTosFound )
255 cacheFromToPaths( aFrom, aTo );
256 else
257 return false;
258 }
259
260 return false;
261}
int cacheFromToPaths(const wxString &aFrom, const wxString &aTo)

References cacheFromToPaths(), m_board, and m_ftPaths.

◆ QueryFromToPath()

FROM_TO_CACHE::FT_PATH * FROM_TO_CACHE::QueryFromToPath ( const std::set< BOARD_CONNECTED_ITEM * > &  aItems)

Definition at line 272 of file from_to_cache.cpp.

273{
274 for( FT_PATH& ftPath : m_ftPaths )
275 {
276 if ( ftPath.pathItems == aItems )
277 return &ftPath;
278 }
279
280 return nullptr;
281}

References m_ftPaths.

◆ Rebuild()

void FROM_TO_CACHE::Rebuild ( BOARD aBoard)

Definition at line 264 of file from_to_cache.cpp.

265{
266 m_board = aBoard;
268 m_ftPaths.clear();
269}
void buildEndpointList()

References buildEndpointList(), m_board, and m_ftPaths.

Member Data Documentation

◆ m_board

BOARD* FROM_TO_CACHE::m_board
private

Definition at line 71 of file from_to_cache.h.

Referenced by buildEndpointList(), cacheFromToPaths(), IsOnFromToPath(), and Rebuild().

◆ m_ftEndpoints

std::vector<FT_ENDPOINT> FROM_TO_CACHE::m_ftEndpoints
private

Definition at line 68 of file from_to_cache.h.

Referenced by buildEndpointList(), and cacheFromToPaths().

◆ m_ftPaths

std::vector<FT_PATH> FROM_TO_CACHE::m_ftPaths
private

Definition at line 69 of file from_to_cache.h.

Referenced by cacheFromToPaths(), IsOnFromToPath(), QueryFromToPath(), and Rebuild().


The documentation for this class was generated from the following files: