KiCad PCB EDA Suite
viewlibs.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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2015-2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <fctsys.h>
26 #include <kiway.h>
27 #include <pgm_base.h>
28 #include <sch_draw_panel.h>
29 #include <sch_view.h>
30 #include <confirm.h>
31 #include <eda_doc.h>
32 
33 #include <viewlib_frame.h>
34 #include <eeschema_id.h>
35 #include <class_libentry.h>
36 #include <class_library.h>
37 #include <dialog_helpers.h>
40 #include <symbol_lib_table.h>
41 
42 void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
43 {
44  std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_COMPONENT::g_Mutex, std::defer_lock );
45 
46  // One CHOOSE_COMPONENT dialog at a time. User probaby can't handle more anyway.
47  if( !dialogLock.try_lock() )
48  return;
49 
50  // Container doing search-as-you-type.
51  SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
52  auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( libs ) );
53  auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
54 
55  const auto libNicknames = libs->GetLogicalLibs();
56  adapter->AddLibraries( libNicknames, this );
57 
58  LIB_PART* current = GetSelectedSymbol();
59  LIB_ID id;
60  int unit = 0;
61 
62  if( current )
63  {
64  id = current->GetLibId();
65  adapter->SetPreselectNode( id, unit );
66  }
67 
68  wxString dialogTitle;
69  dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
70 
71  DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, m_convert, false, false, false );
72 
73  if( dlg.ShowQuasiModal() == wxID_CANCEL )
74  return;
75 
76  id = dlg.GetSelectedLibId( &unit );
77 
78  if( !id.IsValid() )
79  return;
80 
81  SetSelectedLibrary( id.GetLibNickname() );
82  SetSelectedComponent( id.GetLibItemName() );
83  SetUnitAndConvert( unit, 1 );
84 }
85 
86 
87 void LIB_VIEW_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
88 {
89  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
90  int ii = m_cmpList->GetSelection();
91 
92  // Select the next symbol or stop at the end of the list.
93  if( ii != wxNOT_FOUND || ii != (int)m_cmpList->GetCount() - 1 )
94  ii += 1;
95 
96  m_cmpList->SetSelection( ii );
97  ProcessEvent( evt );
98 }
99 
100 
101 void LIB_VIEW_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
102 {
103  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
104  int ii = m_cmpList->GetSelection();
105 
106  // Select the previous symbol or stop at the beginning of list.
107  if( ii != wxNOT_FOUND && ii != 0 )
108  ii -= 1;
109 
110  m_cmpList->SetSelection( ii );
111  ProcessEvent( evt );
112 }
113 
114 
115 void LIB_VIEW_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
116 {
117  int ii = m_unitChoice->GetSelection();
118 
119  if( ii < 0 )
120  return;
121 
122  m_unit = ii + 1;
123 
125 }
126 
127 
129 {
130  if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
131  {
132  const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName );
133 
134  wxString title = wxString::Format( _( "Symbol Library Browser -- %s" ),
135  row ? row->GetFullURI() : _( "no library selected" ) );
136  SetTitle( title );
137  }
138 }
139 
static int m_unit
static int m_convert
LIB_PART * GetSelectedSymbol() const
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
LIB_ID GetLibId() const override
void SetUnitAndConvert(int aUnit, int aConvert)
Set unit and convert, and set flag preventing them from automatically resetting to 1.
This file is part of the common library.
This file is part of the common library.
void onSelectPreviousSymbol(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:101
wxListBox * m_cmpList
static wxString m_libraryName
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void SetSelectedComponent(const wxString &aComponentName)
Set the selected component.
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
Dialog class to select a component from the libraries.
void OnSelectSymbol(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:42
int ShowQuasiModal()
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
Class LIB_PIN definition.
Define a library symbol object.
Helper dialog and control classes.
#define _(s)
void DisplayLibInfos()
Definition: viewlibs.cpp:128
void onSelectNextSymbol(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:87
void updatePreviewSymbol()
static PTR Create(LIB_TABLE *aLibs)
Factory function: create a model adapter in a reference-counting container.
see class PGM_BASE
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
wxListBox * m_libList
wxChoice * m_unitChoice
void onSelectSymbolUnit(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:115
Definition for part library class.
bool ProcessEvent(wxEvent &aEvent) override
Override the default process event handler to implement the auto save feature.
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
To be called after this dialog returns from ShowModal().
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
void SetSelectedLibrary(const wxString &aLibName)
Set the selected library in the library window.