KiCad PCB EDA Suite
Loading...
Searching...
No Matches
design_block_info.cpp
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) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24/*
25 * Functions to read design block libraries and fill m_design_blocks by available design blocks names
26 * and their documentation (comments and keywords)
27 */
28
29#include <design_block_info.h>
30#include <fp_lib_table.h>
32#include <string_utils.h>
33#include <kiface_ids.h>
34#include <kiway.h>
35#include <lib_id.h>
36#include <thread>
37#include <utility>
38#include <wx/tokenzr.h>
39#include <kiface_base.h>
40
42 const wxString& aDesignBlockName )
43{
44 if( aDesignBlockName.IsEmpty() )
45 return nullptr;
46
47 for( std::unique_ptr<DESIGN_BLOCK_INFO>& db : m_list )
48 {
49 if( aLibNickname == db->GetLibNickname() && aDesignBlockName == db->GetDesignBlockName() )
50 return db.get();
51 }
52
53 return nullptr;
54}
55
56
57DESIGN_BLOCK_INFO* DESIGN_BLOCK_LIST::GetDesignBlockInfo( const wxString& aDesignBlockName )
58{
59 if( aDesignBlockName.IsEmpty() )
60 return nullptr;
61
62 LIB_ID dbid;
63
64 wxCHECK_MSG( dbid.Parse( aDesignBlockName ) < 0, nullptr,
65 wxString::Format( wxT( "'%s' is not a valid LIB_ID." ), aDesignBlockName ) );
66
67 return GetDesignBlockInfo( dbid.GetLibNickname(), dbid.GetLibItemName() );
68}
69
70
71std::vector<SEARCH_TERM> DESIGN_BLOCK_INFO::GetSearchTerms()
72{
73 std::vector<SEARCH_TERM> terms;
74
75 terms.emplace_back( SEARCH_TERM( GetName(), 8 ) );
76
77 wxStringTokenizer keywordTokenizer( GetKeywords(), wxS( " " ), wxTOKEN_STRTOK );
78
79 while( keywordTokenizer.HasMoreTokens() )
80 terms.emplace_back( SEARCH_TERM( keywordTokenizer.GetNextToken(), 4 ) );
81
82 // Also include keywords as one long string, just in case
83 terms.emplace_back( SEARCH_TERM( GetKeywords(), 1 ) );
84 terms.emplace_back( SEARCH_TERM( GetDesc(), 1 ) );
85
86 return terms;
87}
88
89
90bool DESIGN_BLOCK_INFO::InLibrary( const wxString& aLibrary ) const
91{
92 return aLibrary == m_nickname;
93}
94
95
96bool operator<( const DESIGN_BLOCK_INFO& lhs, const DESIGN_BLOCK_INFO& rhs )
97{
98 int retv = StrNumCmp( lhs.m_nickname, rhs.m_nickname, false );
99
100 if( retv != 0 )
101 return retv < 0;
102
103 // Technically design block names are not case sensitive because the file name is used
104 // as the design block name. On windows this would be problematic because windows does
105 // not support case sensitive file names by default. This should not cause any issues
106 // and allow for a future change to use the name defined in the design block file.
107 return StrNumCmp( lhs.m_dbname, rhs.m_dbname, false ) < 0;
108}
wxString m_nickname
library as known in DESIGN_BLOCK_LIB_TABLE
bool InLibrary(const wxString &aLibrary) const
Test if the DESIGN_BLOCK_INFO object was loaded from aLibrary.
wxString m_dbname
Module name.
wxString GetDesc() override
std::vector< SEARCH_TERM > GetSearchTerms() override
wxString GetName() const override
DESIGN_BLOCK_INFO * GetDesignBlockInfo(const wxString &aDesignBlockName)
Get info for a design block by id.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:51
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
bool operator<(const DESIGN_BLOCK_INFO &lhs, const DESIGN_BLOCK_INFO &rhs)
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.