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_library.h>
36 #include <dialog_helpers.h>
39 #include <symbol_lib_table.h>
40 
41 void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
42 {
43  std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_COMPONENT::g_Mutex, std::defer_lock );
44 
45  // One CHOOSE_COMPONENT dialog at a time. User probaby can't handle more anyway.
46  if( !dialogLock.try_lock() )
47  return;
48 
49  // Container doing search-as-you-type.
50  SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
51  auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( libs ) );
52  auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
53 
54  const auto libNicknames = libs->GetLogicalLibs();
55  adapter->AddLibraries( libNicknames, this );
56 
57  LIB_ALIAS *current = getSelectedAlias();
58  LIB_ID id;
59  int unit = 0;
60 
61  if( current )
62  {
63  id = current->GetLibId();
64  adapter->SetPreselectNode( id, unit );
65  }
66 
67  wxString dialogTitle;
68  dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
69 
70  DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, m_convert, false, false, false );
71 
72  if( dlg.ShowQuasiModal() == wxID_CANCEL )
73  return;
74 
75  id = dlg.GetSelectedLibId( &unit );
76 
77  if( !id.IsValid() )
78  return;
79 
80  SetSelectedLibrary( id.GetLibNickname() );
81  SetSelectedComponent( id.GetLibItemName() );
82  SetUnitAndConvert( unit, 1 );
83 }
84 
85 
86 void LIB_VIEW_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
87 {
88  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
89  int ii = m_cmpList->GetSelection();
90 
91  // Select the next symbol or stop at the end of the list.
92  if( ii != wxNOT_FOUND || ii != (int)m_cmpList->GetCount() - 1 )
93  ii += 1;
94 
95  m_cmpList->SetSelection( ii );
96  ProcessEvent( evt );
97 }
98 
99 
100 void LIB_VIEW_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
101 {
102  wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
103  int ii = m_cmpList->GetSelection();
104 
105  // Select the previous symbol or stop at the beginning of list.
106  if( ii != wxNOT_FOUND && ii != 0 )
107  ii -= 1;
108 
109  m_cmpList->SetSelection( ii );
110  ProcessEvent( evt );
111 }
112 
113 
114 void LIB_VIEW_FRAME::onUpdateDocButton( wxUpdateUIEvent& aEvent )
115 {
116  LIB_ALIAS* entry = getSelectedAlias();
117 
118  aEvent.Enable( entry && !entry->GetDocFileName().IsEmpty() );
119 }
120 
121 
122 void LIB_VIEW_FRAME::onViewSymbolDocument( wxCommandEvent& aEvent )
123 {
124  LIB_ALIAS* entry = getSelectedAlias();
125 
126  if( entry && !entry->GetDocFileName().IsEmpty() )
127  {
128  SEARCH_STACK* lib_search = Prj().SchSearchS();
129 
130  GetAssociatedDocument( this, entry->GetDocFileName(), lib_search );
131  }
132 }
133 
134 
135 void LIB_VIEW_FRAME::onSelectSymbolBodyStyle( wxCommandEvent& aEvent )
136 {
137  if( aEvent.GetId() == ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT )
138  m_convert = LIB_ITEM::LIB_CONVERT::DEMORGAN;
139  else
140  m_convert = LIB_ITEM::LIB_CONVERT::BASE;
141 
143 }
144 
145 
146 void LIB_VIEW_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
147 {
148  int ii = m_unitChoice->GetSelection();
149 
150  if( ii < 0 )
151  return;
152 
153  m_unit = ii + 1;
154 
156 }
157 
158 
159 void LIB_VIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
160 {
161 }
162 
163 
164 bool LIB_VIEW_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
165 {
166  return true;
167 }
168 
169 
171 {
172  if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
173  {
174  const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName );
175 
176  wxString title = wxString::Format( _( "Symbol Library Browser -- %s" ),
177  row ? row->GetFullURI() : _( "no library selected" ) );
178  SetTitle( title );
179  }
180 }
181 
182 
183 void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
184 {
185  DisplayLibInfos();
186  UpdateStatusBar();
187 }
static int m_unit
static int m_convert
Part library alias object definition.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
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.
LIB_ID GetLibId() const override
This file is part of the common library.
bool OnRightClick(const wxPoint &MousePos, wxMenu *PopMenu) override
Definition: viewlibs.cpp:164
void onSelectPreviousSymbol(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:100
void OnLeftClick(wxDC *DC, const wxPoint &MousePos) override
Definition: viewlibs.cpp:159
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, const wxPathList *aPaths)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:87
wxListBox * m_cmpList
Class SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
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 & GetDocFileName() const
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:41
void onViewSymbolDocument(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:122
int ShowQuasiModal()
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void RedrawActiveWindow(wxDC *DC, bool EraseBg) override
Definition: viewlibs.cpp:183
void onSelectSymbolBodyStyle(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:135
Helper dialog and control classes.
void DisplayLibInfos()
Definition: viewlibs.cpp:170
void UpdateStatusBar() override
Update the status bar information.
void onSelectNextSymbol(wxCommandEvent &aEvent)
Definition: viewlibs.cpp:86
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:146
Definition for part library class.
void onUpdateDocButton(wxUpdateUIEvent &aEvent)
Definition: viewlibs.cpp:114
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().
LIB_ALIAS * getSelectedAlias() const
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.