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  bool InTree;
89 
96 
98  int Score;
99 
100  wxString Name;
101  wxString Desc;
102  wxString MatchName;
103  wxString SearchText;
104 
106  int Unit;
107  bool IsRoot;
108 
115  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) = 0;
116 
120  void ResetScore();
121 
126  void AssignIntrinsicRanks();
127 
131  void SortNodes();
132 
137  static int Compare( CMP_TREE_NODE const& aNode1, CMP_TREE_NODE const& aNode2 );
138 
139  CMP_TREE_NODE();
140  virtual ~CMP_TREE_NODE() {}
141 };
142 
143 
148 {
149 
150 public:
155  CMP_TREE_NODE_UNIT( CMP_TREE_NODE_UNIT const& _ ) = delete;
156  void operator=( CMP_TREE_NODE_UNIT const& _ ) = delete;
157 
158 
168  CMP_TREE_NODE_UNIT( CMP_TREE_NODE* aParent, int aUnit );
169 
170 
174  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override {}
175 };
176 
177 
182 {
183 public:
188  CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE_LIB_ID const& _ ) = delete;
189  void operator=( CMP_TREE_NODE_LIB_ID const& _ ) = delete;
190 
191 
204  CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* aAlias );
205 
206 
210  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
211 
212 protected:
218  CMP_TREE_NODE_UNIT& AddUnit( int aUnit );
219 };
220 
221 
226 {
227 public:
232  CMP_TREE_NODE_LIB( CMP_TREE_NODE_LIB const& _ ) = delete;
233  void operator=( CMP_TREE_NODE_LIB const& _ ) = delete;
234 
235 
242  CMP_TREE_NODE_LIB( CMP_TREE_NODE* aParent, wxString const& aName );
243 
250 
251  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
252 };
253 
254 
259 {
260 public:
265  CMP_TREE_NODE_ROOT( CMP_TREE_NODE_ROOT const& _ ) = delete;
266  void operator=( CMP_TREE_NODE_ROOT const& _ ) = delete;
267 
272 
276  CMP_TREE_NODE_LIB& AddLib( wxString const& aName );
277 
278  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
279 };
280 
281 
282 #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.
CMP_TREE_NODE_LIB_ID(CMP_TREE_NODE_LIB_ID const &_)=delete
The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be ...
Part library alias object definition.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Do nothing, units just take the parent's score.
void operator=(CMP_TREE_NODE_LIB const &_)=delete
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Update the score for this part.
enum TYPE Type
Node type.
CMP_TREE_NODE_LIB_ID & AddAlias(LIB_ALIAS *aAlias)
Construct a new alias node, add it to this library, and return it.
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
Class LIB_ID.
Definition: lib_id.h:56
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
void operator=(CMP_TREE_NODE_UNIT const &_)=delete
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.
CMP_TREE_NODE_UNIT(CMP_TREE_NODE_UNIT const &_)=delete
The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be ...
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Update the score for this part.
std::vector< std::unique_ptr< CMP_TREE_NODE > > PTR_VECTOR
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Perform the actual search.
void AssignIntrinsicRanks()
Store intrinsic ranks on all children of this node.
wxString MatchName
Normalized name for matching.
void operator=(CMP_TREE_NODE_ROOT const &_)=delete
CMP_TREE_NODE_UNIT & AddUnit(int aUnit)
Add a new unit to the component and return it.
Node type: library.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
CMP_TREE_NODE_ROOT()
Construct the root node.
CMP_TREE_NODE * Parent
Parent node or null.
wxString SearchText
Descriptive text to search.
PTR_VECTOR Children
List of child nodes.
CMP_TREE_NODE_LIB(CMP_TREE_NODE_LIB const &_)=delete
The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be ...
void operator=(CMP_TREE_NODE_LIB_ID const &_)=delete
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.
bool InTree
Flag indicating whether the node is added to the tree.
int Unit
Actual unit, or zero.
Node type: unit of component.
CMP_TREE_NODE_LIB & AddLib(wxString const &aName)
Construct an empty library node, add it to the root, and return it.
int Score
The score of an item resulting from the search algorithm.
Node type: LIB_ID.
virtual ~CMP_TREE_NODE()
Node type: root.