KiCad PCB EDA Suite
cmp_tree_model_adapter.cpp
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 #include <cmp_tree_model_adapter.h>
23 
24 #include <eda_pattern_match.h>
25 #include <wx/tokenzr.h>
26 #include <symbol_lib_table.h>
27 #include <wx/progdlg.h>
28 
30 {
31  auto adapter = new CMP_TREE_MODEL_ADAPTER( aLibs );
32  auto container = CMP_TREE_MODEL_ADAPTER::PTR( adapter );
33  return container;
34 }
35 
36 
38  : m_libs( aLibs )
39 {}
40 
41 
43 {}
44 
45 
46 void CMP_TREE_MODEL_ADAPTER::AddLibrary( wxString const& aLibNickname )
47 {
48  bool onlyPowerSymbols = ( GetFilter() == CMP_FILTER_POWER );
49 
50  wxArrayString aliases;
51 
52  try
53  {
54  m_libs->EnumerateSymbolLib( aLibNickname, aliases, onlyPowerSymbols );
55  }
56  catch( const IO_ERROR& ioe )
57  {
58  wxLogError( wxString::Format( _( "Error occurred loading symbol library %s."
59  "\n\n%s" ), aLibNickname, ioe.What() ) );
60  return;
61  }
62 
63  if( aliases.size() > 0 )
64  {
65  AddAliasList( aLibNickname, aliases );
67  }
68 }
69 
70 
72  wxString const& aNodeName,
73  wxArrayString const& aAliasNameList )
74 {
75  std::vector<LIB_ALIAS*> alias_list;
76 
77  for( const wxString& name: aAliasNameList )
78  {
79  LIB_ALIAS* a = nullptr;
80 
81  try
82  {
83  a = m_libs->LoadSymbol( aNodeName, name );
84  }
85  catch( const IO_ERROR& ioe )
86  {
87  wxLogError( wxString::Format( _( "Error occurred loading symbol %s from library %s."
88  "\n\n%s" ), name, aNodeName, ioe.What() ) );
89  continue;
90  }
91 
92  if( a )
93  alias_list.push_back( a );
94  }
95 
96  if( alias_list.size() > 0 )
97  AddAliasList( aNodeName, alias_list );
98 }
LIB_ALIAS * LoadSymbol(const wxString &aNickname, const wxString &aAliasName)
Load a LIB_ALIAS having aAliasName from the library given by aNickname.
void EnumerateSymbolLib(const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
Return a list of symbol alias names contained within the library given by aNickname.
Part library alias object definition.
void AddLibrary(wxString const &aLibNickname) override
Add all the components and their aliases in this library.
~CMP_TREE_MODEL_ADAPTER()
Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER.
static PTR Create(SYMBOL_LIB_TABLE *aLibs)
Factory function: create a model adapter in a reference-counting container.
Abstract pattern-matching tool and implementations.
void AssignIntrinsicRanks()
Store intrinsic ranks on all children of this node.
wxObjectDataPtr< CMP_TREE_MODEL_ADAPTER_BASE > PTR
Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.
void AddAliasList(wxString const &aNodeName, wxArrayString const &aAliasNameList) override
Add the given list of components, by name.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
CMP_TREE_MODEL_ADAPTER(SYMBOL_LIB_TABLE *aLibs)
Constructor; takes a set of libraries to be included in the search.
const char * name
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
CMP_FILTER_TYPE GetFilter() const
Return the active filter.