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 
29 
31 class TREE_NODE;
32 class LIB_ALIAS;
33 
34 
77 public:
78  enum TYPE {
80  };
81 
83  std::vector<std::unique_ptr<CMP_TREE_NODE>> Children;
84  enum TYPE Type;
85 
92 
94  int Score;
95 
96  wxString Name;
97  wxString Desc;
98  wxString MatchName;
99  wxString SearchText;
100 
102  int Unit;
103 
104 
112  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) = 0;
113 
117  void ResetScore();
118 
123  void AssignIntrinsicRanks();
124 
128  void SortNodes();
129 
134  static int Compare( CMP_TREE_NODE const& aNode1, CMP_TREE_NODE const& aNode2 );
135 
136  CMP_TREE_NODE();
137  virtual ~CMP_TREE_NODE() {}
138 };
139 
140 
145 {
146 
147 public:
152  CMP_TREE_NODE_UNIT( CMP_TREE_NODE_UNIT const& _ ) = delete;
153  void operator=( CMP_TREE_NODE_UNIT const& _ ) = delete;
154 
155 
165  CMP_TREE_NODE_UNIT( CMP_TREE_NODE* aParent, int aUnit );
166 
167 
171  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override {}
172 };
173 
174 
179 {
180 public:
185  CMP_TREE_NODE_ALIAS( CMP_TREE_NODE_ALIAS const& _ ) = delete;
186  void operator=( CMP_TREE_NODE_ALIAS const& _ ) = delete;
187 
188 
198  CMP_TREE_NODE_ALIAS( CMP_TREE_NODE* aParent, LIB_ALIAS* aAlias );
199 
200 
204  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
205 
206 protected:
212  CMP_TREE_NODE_UNIT& AddUnit( int aUnit );
213 };
214 
215 
220 {
221 public:
226  CMP_TREE_NODE_LIB( CMP_TREE_NODE_LIB const& _ ) = delete;
227  void operator=( CMP_TREE_NODE_LIB const& _ ) = delete;
228 
229 
236  CMP_TREE_NODE_LIB( CMP_TREE_NODE* aParent, wxString const& aName );
237 
244 
245  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
246 };
247 
248 
253 {
254 public:
259  CMP_TREE_NODE_ROOT( CMP_TREE_NODE_ROOT const& _ ) = delete;
260  void operator=( CMP_TREE_NODE_ROOT const& _ ) = delete;
261 
266 
270  CMP_TREE_NODE_LIB& AddLib( wxString const& aName );
271 
272  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
273 };
274 
275 
276 #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_UNIT & AddUnit(int aUnit)
Add a new unit to the component and return it.
Part library alias object definition.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Do nothing, units just take the parent's score.
Node type: alias.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Perform the actual search.
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.
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
void operator=(CMP_TREE_NODE_UNIT const &_)=delete
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.
void AssignIntrinsicRanks()
Store intrinsic ranks on all children of this node.
void operator=(CMP_TREE_NODE_ALIAS const &_)=delete
wxString MatchName
Normalized name for matching.
void operator=(CMP_TREE_NODE_ROOT const &_)=delete
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.
CMP_TREE_NODE_ALIAS & AddAlias(LIB_ALIAS *aAlias)
Construct a new alias node, add it to this library, and return it.
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 ...
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.
LIB_ALIAS * Alias
Actual LIB_ALIAS*, or null.
std::vector< std::unique_ptr< CMP_TREE_NODE > > Children
List of child nodes.
Node type: unit of component.
CMP_TREE_NODE_ALIAS(CMP_TREE_NODE_ALIAS const &_)=delete
The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be ...
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.
virtual ~CMP_TREE_NODE()
Node type: root.