2014-02-14 08:05:04 +00:00
|
|
|
/* -*- c++ -*-
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
|
|
|
|
* Copyright (C) 2014 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http: *www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http: *www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2014-02-18 21:41:27 +00:00
|
|
|
#ifndef COMPONENT_TREE_SEARCH_CONTAINER_H
|
|
|
|
#define COMPONENT_TREE_SEARCH_CONTAINER_H
|
2014-02-14 08:05:04 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <wx/string.h>
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
class LIB_ALIAS;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
class PART_LIB;
|
|
|
|
class PART_LIBS;
|
2014-02-14 08:05:04 +00:00
|
|
|
class wxTreeCtrl;
|
|
|
|
class wxArrayString;
|
|
|
|
|
|
|
|
// class COMPONENT_TREE_SEARCH_CONTAINER
|
|
|
|
// A container for components that allows to search them matching their name, keywords
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
// and descriptions, updating a wxTreeCtrl with the results (toplevel nodes:
|
2014-02-14 08:05:04 +00:00
|
|
|
// libraries, leafs: components), scored by relevance.
|
|
|
|
//
|
|
|
|
// The scored result list is adpated on each update on the search-term: this allows
|
|
|
|
// to have a search-as-you-type experience.
|
|
|
|
class COMPONENT_TREE_SEARCH_CONTAINER
|
|
|
|
{
|
|
|
|
public:
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
COMPONENT_TREE_SEARCH_CONTAINER( PART_LIBS* aLibs );
|
2014-02-14 08:05:04 +00:00
|
|
|
~COMPONENT_TREE_SEARCH_CONTAINER();
|
|
|
|
|
|
|
|
/** Function AddLibrary
|
2014-02-18 21:41:27 +00:00
|
|
|
* Add all the components and their aliases of this library to be searched.
|
2014-02-14 08:05:04 +00:00
|
|
|
* To be called in the setup phase to fill this container.
|
|
|
|
*
|
|
|
|
* @param aLib containting all the components to be added.
|
|
|
|
*/
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
void AddLibrary( PART_LIB& aLib );
|
2014-02-14 08:05:04 +00:00
|
|
|
|
|
|
|
/** Function AddComponentList
|
|
|
|
* Add the given list of components, given by name, to be searched.
|
|
|
|
* To be called in the setup phase to fill this container.
|
|
|
|
*
|
|
|
|
* @param aNodeName The parent node name the components will show up as leaf.
|
2014-02-18 21:41:27 +00:00
|
|
|
* @param aAliasNameList List of alias names.
|
2014-02-14 08:05:04 +00:00
|
|
|
* @param aOptionalLib Library to look up the component names (if NULL: global lookup)
|
|
|
|
*/
|
2014-02-18 21:41:27 +00:00
|
|
|
void AddAliasList( const wxString& aNodeName, const wxArrayString& aAliasNameList,
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
PART_LIB* aOptionalLib );
|
2014-02-14 08:05:04 +00:00
|
|
|
|
|
|
|
/** Function SetPreselectNode
|
|
|
|
* Set the component name to be selected in absence of any search-result.
|
|
|
|
*
|
|
|
|
* @param aComponentName the component name to be selected.
|
2014-02-18 21:41:27 +00:00
|
|
|
* @param aUnit the component unit to be selected (if > 0).
|
2014-02-14 08:05:04 +00:00
|
|
|
*/
|
2014-02-18 21:41:27 +00:00
|
|
|
void SetPreselectNode( const wxString& aComponentName, int aUnit );
|
2014-02-14 08:05:04 +00:00
|
|
|
|
|
|
|
/** Function SetTree
|
|
|
|
* Set the tree to be manipulated.
|
|
|
|
* Each update of the search term will update the tree, with the most
|
|
|
|
* scoring component at the top and selected. If a preselect node is set, this
|
|
|
|
* is displayed. Does not take ownership of the tree.
|
|
|
|
*
|
|
|
|
* @param aTree that is to be modified on search updates.
|
|
|
|
*/
|
|
|
|
void SetTree( wxTreeCtrl* aTree );
|
|
|
|
|
|
|
|
/** Function UpdateSearchTerm
|
|
|
|
* Update the search string provided by the user and narrow down the result list.
|
|
|
|
*
|
|
|
|
* This string is a space-separated list of terms, each of which
|
|
|
|
* is applied to the components list to narrow it down. Results are scored by
|
|
|
|
* relevancy (e.g. exact match scores higher than prefix-match which in turn scores
|
|
|
|
* higher than substring match). This updates the search and tree on each call.
|
|
|
|
*
|
|
|
|
* @param aSearch is the user-provided search string.
|
|
|
|
*/
|
|
|
|
void UpdateSearchTerm( const wxString& aSearch );
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
/** Function GetSelectedAlias
|
2014-02-14 08:05:04 +00:00
|
|
|
*
|
2014-11-02 16:25:04 +00:00
|
|
|
* @param aUnit : if not NULL, the selected sub-unit is set here.
|
2014-02-24 10:52:08 +00:00
|
|
|
* @return the selected alias or NULL if there is none, or there is no tree.
|
2014-02-14 08:05:04 +00:00
|
|
|
*/
|
2014-02-18 21:41:27 +00:00
|
|
|
LIB_ALIAS* GetSelectedAlias( int* aUnit );
|
2014-02-14 08:05:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct TREE_NODE;
|
|
|
|
static bool scoreComparator( const TREE_NODE* a1, const TREE_NODE* a2 );
|
|
|
|
|
|
|
|
std::vector<TREE_NODE*> nodes;
|
|
|
|
wxTreeCtrl* tree;
|
2014-02-18 21:41:27 +00:00
|
|
|
int libraries_added;
|
|
|
|
|
|
|
|
wxString preselect_node_name;
|
|
|
|
int preselect_unit_number;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
|
|
|
PART_LIBS* m_libs; // no ownership
|
2014-02-14 08:05:04 +00:00
|
|
|
};
|
2014-02-18 21:41:27 +00:00
|
|
|
|
|
|
|
#endif /* COMPONENT_TREE_SEARCH_CONTAINER_H */
|