KiCad PCB EDA Suite
lib_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-2018 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 LIB_TREE_MODEL_H
23 #define LIB_TREE_MODEL_H
24 
25 #include <vector>
26 #include <memory>
27 #include <wx/string.h>
28 #include <lib_tree_item.h>
29 
30 
32 
33 
76 public:
77  enum TYPE {
79  };
80 
81  typedef std::vector<std::unique_ptr<LIB_TREE_NODE>> PTR_VECTOR;
82 
85  enum TYPE Type;
86 
93 
95  int Score;
96 
97  wxString Name;
98  wxString Desc;
99  wxString MatchName;
100  wxString SearchText;
101  bool Normalized;
102 
103 
105  int Unit;
106  bool IsRoot;
107  int VisLen;
108 
115  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) = 0;
116 
120  void ResetScore();
121 
126  void AssignIntrinsicRanks( bool presorted = false );
127 
131  void SortNodes();
132 
137  static int Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2 );
138 
139  LIB_TREE_NODE();
140  virtual ~LIB_TREE_NODE() {}
141 };
142 
143 
148 {
149 
150 public:
155  LIB_TREE_NODE_UNIT( LIB_TREE_NODE_UNIT const& _ ) = delete;
156  void operator=( LIB_TREE_NODE_UNIT const& _ ) = delete;
157 
158 
169  LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem, int aUnit );
170 
171 
175  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override {}
176 };
177 
178 
183 {
184 public:
189  LIB_TREE_NODE_LIB_ID( LIB_TREE_NODE_LIB_ID const& _ ) = delete;
190  void operator=( LIB_TREE_NODE_LIB_ID const& _ ) = delete;
191 
192 
206 
210  void Update( LIB_TREE_ITEM* aItem );
211 
215  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
216 
217 protected:
223  LIB_TREE_NODE_UNIT& AddUnit( LIB_TREE_ITEM* aItem, int aUnit );
224 };
225 
226 
231 {
232 public:
237  LIB_TREE_NODE_LIB( LIB_TREE_NODE_LIB const& _ ) = delete;
238  void operator=( LIB_TREE_NODE_LIB const& _ ) = delete;
239 
240 
248  LIB_TREE_NODE_LIB( LIB_TREE_NODE* aParent, wxString const& aName, wxString const& aDesc );
249 
256 
257  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
258 };
259 
260 
265 {
266 public:
271  LIB_TREE_NODE_ROOT( LIB_TREE_NODE_ROOT const& _ ) = delete;
272  void operator=( LIB_TREE_NODE_ROOT const& _ ) = delete;
273 
278 
282  LIB_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 // LIB_TREE_MODEL_H
void operator=(LIB_TREE_NODE_LIB_ID const &_)=delete
int VisLen
Length of the string as shown on screen.
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
PTR_VECTOR Children
List of child nodes.
enum TYPE Type
Node type.
static int Compare(LIB_TREE_NODE const &aNode1, LIB_TREE_NODE const &aNode2)
Compare two nodes.
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
Definition: lib_tree_item.h:39
bool Normalized
Support for lazy normalization.
Node type: LIB_ID.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Perform the actual search.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
LIB_TREE_NODE * Parent
Parent node or null.
int Score
The score of an item resulting from the search algorithm.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher)=0
Update the score for this part.
void operator=(LIB_TREE_NODE_ROOT const &_)=delete
LIB_TREE_NODE_LIB_ID & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
void operator=(LIB_TREE_NODE_UNIT const &_)=delete
Node type: root.
wxString MatchName
Normalized name for matching.
Node type: library.
LIB_ID LibId
LIB_ID determined by the parent library nickname and alias name.
LIB_TREE_NODE_UNIT & AddUnit(LIB_TREE_ITEM *aItem, int aUnit)
Add a new unit to the component and return it.
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
void operator=(LIB_TREE_NODE_LIB const &_)=delete
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
Node type: unit of component.
wxString Desc
Description to be displayed.
LIB_TREE_NODE_LIB & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.
wxString SearchText
Descriptive text to search.
wxString Name
Actual name of the part.
bool IsRoot
Indicates if the symbol is a root symbol instead of an alias.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
LIB_TREE_NODE_LIB_ID(LIB_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 ...
std::vector< std::unique_ptr< LIB_TREE_NODE > > PTR_VECTOR
int Unit
Actual unit, or zero.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Do nothing, units just take the parent's score.
LIB_TREE_NODE_ROOT()
Construct the root node.
int IntrinsicRank
The rank of the item before any search terms are applied.
void Update(LIB_TREE_ITEM *aItem)
Update the node using data from a LIB_ALIAS object.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Update the score for this part.
LIB_TREE_NODE_LIB(LIB_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 ...
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Update the score for this part.
virtual ~LIB_TREE_NODE()
LIB_TREE_NODE_UNIT(LIB_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 ...