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 {
77 public:
78  enum TYPE {
80  };
81 
82  typedef std::vector<std::unique_ptr<LIB_TREE_NODE>> PTR_VECTOR;
83 
84  LIB_TREE_NODE* m_Parent; // Parent node or null
85  PTR_VECTOR m_Children; // List of child nodes
86  enum TYPE m_Type; // Node type
87 
94 
95  int m_Score; // The score of an item resulting from the search algorithm.
96  bool m_Pinned; // Item should appear at top when there is no search string
97 
98  wxString m_Name; // Actual name of the part
99  wxString m_Desc; // Description to be displayed
100  wxString m_MatchName; // Normalized name for matching
101  wxString m_SearchText; // Descriptive text to search
102  bool m_Normalized; // Support for lazy normalization.
103 
104 
105  LIB_ID m_LibId; // LIB_ID determined by the parent library nickname and alias name.
106  int m_Unit; // Actual unit, or zero
107  bool m_IsRoot; // Indicates if the symbol is a root symbol instead of an alias.
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
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
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
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
int m_IntrinsicRank
The rank of the item before any search terms are applied.
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.
LIB_TREE_NODE * m_Parent
Node type: library.
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.
LIB_TREE_NODE_LIB & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.
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
#define _(s)
Definition: 3d_actions.cpp:33
enum TYPE m_Type
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.
wxString m_Name
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()
PTR_VECTOR m_Children
wxString m_Desc
wxString m_SearchText
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 ...
wxString m_MatchName