KiCad PCB EDA Suite
cmp_tree_model.h
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) 2017 Chris Pavlina <pavlina.chris@gmail.com>
5  * Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
6  * Copyright (C) 2014-2017 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation, either version 3 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef _CMP_TREE_MODEL_H
23 #define _CMP_TREE_MODEL_H
24 
25 #include <vector>
26 #include <memory>
27 #include <wx/string.h>
28 #include <lib_id.h>
29 
30 
32 class TREE_NODE;
33 class LIB_ALIAS;
34 
35 
78 public:
79  enum TYPE {
81  };
82 
83  typedef std::vector<std::unique_ptr<CMP_TREE_NODE>> PTR_VECTOR;
84 
86  PTR_VECTOR Children;
87  enum TYPE Type;
88 
95 
97  int Score;
98 
99  wxString Name;
100  wxString Desc;
101  wxString MatchName;
102  wxString SearchText;
104 
105 
107  int Unit;
108  bool IsRoot;
109 
116  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) = 0;
117 
121  void ResetScore();
122 
127  void AssignIntrinsicRanks();
128 
132  void SortNodes();
133 
138  static int Compare( CMP_TREE_NODE const& aNode1, CMP_TREE_NODE const& aNode2 );
139 
140  CMP_TREE_NODE();
141  virtual ~CMP_TREE_NODE() {}
142 };
143 
144 
149 {
150 
151 public:
156  CMP_TREE_NODE_UNIT( CMP_TREE_NODE_UNIT const& _ ) = delete;
157  void operator=( CMP_TREE_NODE_UNIT const& _ ) = delete;
158 
159 
169  CMP_TREE_NODE_UNIT( CMP_TREE_NODE* aParent, int aUnit );
170 
171 
175  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override {}
176 };
177 
178 
183 {
184 public:
189  CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE_LIB_ID const& _ ) = delete;
190  void operator=( CMP_TREE_NODE_LIB_ID const& _ ) = delete;
191 
192 
205  CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* aAlias );
206 
210  void Update( LIB_ALIAS* aAlias );
211 
215  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
216 
217 protected:
223  CMP_TREE_NODE_UNIT& AddUnit( int aUnit );
224 };
225 
226 
231 {
232 public:
237  CMP_TREE_NODE_LIB( CMP_TREE_NODE_LIB const& _ ) = delete;
238  void operator=( CMP_TREE_NODE_LIB const& _ ) = delete;
239 
240 
248  CMP_TREE_NODE_LIB( CMP_TREE_NODE* aParent, wxString const& aName, wxString const& aDesc );
249 
255  CMP_TREE_NODE_LIB_ID& AddAlias( LIB_ALIAS* aAlias );
256 
257  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
258 };
259 
260 
265 {
266 public:
271  CMP_TREE_NODE_ROOT( CMP_TREE_NODE_ROOT const& _ ) = delete;
272  void operator=( CMP_TREE_NODE_ROOT const& _ ) = delete;
273 
278 
282  CMP_TREE_NODE_LIB& AddLib( wxString const& aName, wxString const& aDesc );
283 
284  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
285 };
286 
287 
288 #endif // _CMP_TREE_MODEL_H
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher)=0
Update the score for this part.
wxString Name
Actual name of the part.
wxString Desc
Description to be displayed.
Part library alias object definition.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Do nothing, units just take the parent&#39;s score.
bool SearchTextNormalized
Support for lazy normalization.
enum TYPE Type
Node type.
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
bool IsRoot
Indicates if the symbol is a root symbol instead of an alias.
LIB_ID LibId
LIB_ID determined by the parent library nickname and alias name.
std::vector< std::unique_ptr< CMP_TREE_NODE > > PTR_VECTOR
void AssignIntrinsicRanks()
Store intrinsic ranks on all children of this node.
wxString MatchName
Normalized name for matching.
Node type: library.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
CMP_TREE_NODE * Parent
Parent node or null.
wxString SearchText
Descriptive text to search.
PTR_VECTOR Children
List of child nodes.
int IntrinsicRank
The rank of the item before any search terms are applied.
static int Compare(CMP_TREE_NODE const &aNode1, CMP_TREE_NODE const &aNode2)
Compare two nodes.
int Unit
Actual unit, or zero.
Node type: unit of component.
int Score
The score of an item resulting from the search algorithm.
Node type: LIB_ID.
virtual ~CMP_TREE_NODE()
Node type: root.