You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1163 lines
35 KiB

5 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
5 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
5 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
5 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
5 years ago
5 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
2 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
2 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
5 years ago
5 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
5 years ago
2 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <bitmaps.h>
  26. #include <symbol_library_common.h>
  27. #include <confirm.h>
  28. #include <dialogs/html_message_box.h>
  29. #include <eeschema_id.h>
  30. #include <eeschema_settings.h>
  31. #include <gal/graphics_abstraction_layer.h>
  32. #include <kiface_base.h>
  33. #include <kiway.h>
  34. #include <kiway_express.h>
  35. #include <locale_io.h>
  36. #include <symbol_viewer_frame.h>
  37. #include <widgets/msgpanel.h>
  38. #include <widgets/wx_listbox.h>
  39. #include <widgets/wx_aui_utils.h>
  40. #include <widgets/wx_progress_reporters.h>
  41. #include <sch_view.h>
  42. #include <sch_painter.h>
  43. #include <symbol_lib_table.h>
  44. #include <symbol_tree_model_adapter.h>
  45. #include <pgm_base.h>
  46. #include <project/project_file.h>
  47. #include <project_sch.h>
  48. #include <settings/settings_manager.h>
  49. #include <symbol_async_loader.h>
  50. #include <tool/action_toolbar.h>
  51. #include <tool/common_control.h>
  52. #include <tool/common_tools.h>
  53. #include <tool/editor_conditions.h>
  54. #include <tool/selection.h>
  55. #include <tool/tool_dispatcher.h>
  56. #include <tool/tool_manager.h>
  57. #include <tool/zoom_tool.h>
  58. #include <tools/sch_actions.h>
  59. #include <tools/symbol_editor_control.h>
  60. #include <tools/sch_inspection_tool.h>
  61. #include <view/view_controls.h>
  62. #include <wx/srchctrl.h>
  63. #include <wx/log.h>
  64. #include <default_values.h>
  65. #include <string_utils.h>
  66. #include "eda_pattern_match.h"
  67. // Save previous symbol library viewer state.
  68. LIB_ID SYMBOL_VIEWER_FRAME::m_currentSymbol;
  69. int SYMBOL_VIEWER_FRAME::m_unit = 1;
  70. int SYMBOL_VIEWER_FRAME::m_bodyStyle = 1;
  71. bool SYMBOL_VIEWER_FRAME::m_show_progress = true;
  72. BEGIN_EVENT_TABLE( SYMBOL_VIEWER_FRAME, SCH_BASE_FRAME )
  73. // Window events
  74. EVT_SIZE( SYMBOL_VIEWER_FRAME::OnSize )
  75. EVT_ACTIVATE( SYMBOL_VIEWER_FRAME::OnActivate )
  76. // Toolbar events
  77. EVT_TOOL( ID_LIBVIEW_NEXT, SYMBOL_VIEWER_FRAME::onSelectNextSymbol )
  78. EVT_TOOL( ID_LIBVIEW_PREVIOUS, SYMBOL_VIEWER_FRAME::onSelectPreviousSymbol )
  79. EVT_CHOICE( ID_LIBVIEW_SELECT_UNIT_NUMBER, SYMBOL_VIEWER_FRAME::onSelectSymbolUnit )
  80. // listbox events
  81. EVT_TEXT( ID_LIBVIEW_LIB_FILTER, SYMBOL_VIEWER_FRAME::OnLibFilter )
  82. EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, SYMBOL_VIEWER_FRAME::ClickOnLibList )
  83. EVT_TEXT( ID_LIBVIEW_SYM_FILTER, SYMBOL_VIEWER_FRAME::OnSymFilter )
  84. EVT_LISTBOX( ID_LIBVIEW_SYM_LIST, SYMBOL_VIEWER_FRAME::ClickOnSymbolList )
  85. EVT_LISTBOX_DCLICK( ID_LIBVIEW_SYM_LIST, SYMBOL_VIEWER_FRAME::DClickOnSymbolList )
  86. // Menu (and/or hotkey) events
  87. EVT_MENU( wxID_CLOSE, SYMBOL_VIEWER_FRAME::CloseLibraryViewer )
  88. EVT_UPDATE_UI( ID_LIBVIEW_SELECT_UNIT_NUMBER, SYMBOL_VIEWER_FRAME::onUpdateUnitChoice )
  89. END_EVENT_TABLE()
  90. SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  91. SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_VIEWER, _( "Symbol Library Browser" ),
  92. wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE,
  93. LIB_VIEW_FRAME_NAME ),
  94. m_unitChoice( nullptr ),
  95. m_libList( nullptr ),
  96. m_symbolList( nullptr )
  97. {
  98. m_aboutTitle = _HKI( "KiCad Symbol Library Browser" );
  99. // Force the frame name used in config. the lib viewer frame has a name
  100. // depending on aFrameType (needed to identify the frame by wxWidgets),
  101. // but only one configuration is preferable.
  102. m_configName = LIB_VIEW_FRAME_NAME;
  103. // Give an icon
  104. wxIcon icon;
  105. icon.CopyFromBitmap( KiBitmap( BITMAPS::library_browser ) );
  106. SetIcon( icon );
  107. m_libListWidth = 200;
  108. m_symbolListWidth = 300;
  109. m_listPowerOnly = false;
  110. SetScreen( new SCH_SCREEN );
  111. GetScreen()->m_Center = true; // Axis origin centered on screen.
  112. LoadSettings( config() );
  113. // Ensure axis are always drawn (initial default display was not drawn)
  114. KIGFX::GAL_DISPLAY_OPTIONS& gal_opts = GetGalDisplayOptions();
  115. gal_opts.m_axesEnabled = true;
  116. gal_opts.m_gridMinSpacing = 10.0;
  117. gal_opts.NotifyChanged();
  118. GetRenderSettings()->LoadColors( GetColorSettings() );
  119. GetCanvas()->GetGAL()->SetAxesColor( m_colorSettings->GetColor( LAYER_SCHEMATIC_GRID_AXES ) );
  120. GetRenderSettings()->SetDefaultPenWidth( DEFAULT_LINE_WIDTH_MILS * schIUScale.IU_PER_MILS );
  121. setupTools();
  122. setupUIConditions();
  123. ReCreateHToolbar();
  124. ReCreateVToolbar();
  125. ReCreateMenuBar();
  126. wxPanel* libPanel = new wxPanel( this );
  127. wxSizer* libSizer = new wxBoxSizer( wxVERTICAL );
  128. m_libFilter = new wxSearchCtrl( libPanel, ID_LIBVIEW_LIB_FILTER, wxEmptyString,
  129. wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
  130. m_libFilter->SetDescriptiveText( _( "Filter" ) );
  131. libSizer->Add( m_libFilter, 0, wxEXPAND, 5 );
  132. m_libList = new WX_LISTBOX( libPanel, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
  133. 0, nullptr, wxLB_HSCROLL | wxNO_BORDER );
  134. libSizer->Add( m_libList, 1, wxEXPAND, 5 );
  135. libPanel->SetSizer( libSizer );
  136. libPanel->Fit();
  137. wxPanel* symbolPanel = new wxPanel( this );
  138. wxSizer* symbolSizer = new wxBoxSizer( wxVERTICAL );
  139. m_symbolFilter = new wxSearchCtrl( symbolPanel, ID_LIBVIEW_SYM_FILTER, wxEmptyString,
  140. wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
  141. m_symbolFilter->SetDescriptiveText( _( "Filter" ) );
  142. m_symbolFilter->SetToolTip(
  143. _( "Filter on symbol name, keywords, description and pin count.\n"
  144. "Search terms are separated by spaces. All search terms must match.\n"
  145. "A term which is a number will also match against the pin count." ) );
  146. symbolSizer->Add( m_symbolFilter, 0, wxEXPAND, 5 );
  147. #ifdef __WXGTK__
  148. // wxSearchCtrl vertical height is not calculated correctly on some GTK setups
  149. // See https://gitlab.com/kicad/code/kicad/-/issues/9019
  150. m_libFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT( "qb" ) ).y + 10 ) );
  151. m_symbolFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT( "qb" ) ).y + 10 ) );
  152. #endif
  153. m_symbolList = new WX_LISTBOX( symbolPanel, ID_LIBVIEW_SYM_LIST, wxDefaultPosition,
  154. wxDefaultSize, 0, nullptr, wxLB_HSCROLL | wxNO_BORDER );
  155. symbolSizer->Add( m_symbolList, 1, wxEXPAND, 5 );
  156. symbolPanel->SetSizer( symbolSizer );
  157. symbolPanel->Fit();
  158. // Preload libraries
  159. loadAllLibraries();
  160. ReCreateLibList();
  161. m_selection_changed = false;
  162. DisplayLibInfos();
  163. m_auimgr.SetManagedWindow( this );
  164. CreateInfoBar();
  165. // Manage main toolbar
  166. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
  167. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ) .Bottom().Layer(6) );
  168. m_auimgr.AddPane( libPanel, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(2)
  169. .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 200, -1 ) );
  170. m_auimgr.AddPane( symbolPanel, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1)
  171. .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 300, -1 ) );
  172. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
  173. m_auimgr.Update();
  174. if( m_libListWidth > 0 )
  175. SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "Libraries" ), m_libListWidth, -1 );
  176. if( m_symbolListWidth > 0 )
  177. SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "Symbols" ), m_symbolListWidth, -1 );
  178. FinishAUIInitialization();
  179. Raise();
  180. Show( true );
  181. SyncView();
  182. GetCanvas()->SetCanFocus( false );
  183. setupUnits( config() );
  184. // Set the working/draw area size to display a symbol to a reasonable value:
  185. // A 450mm x 450mm with a origin at the area center looks like a large working area
  186. double max_size_x = schIUScale.mmToIU( 450 );
  187. double max_size_y = schIUScale.mmToIU( 450 );
  188. BOX2D bbox;
  189. bbox.SetOrigin( -max_size_x / 2, -max_size_y / 2 );
  190. bbox.SetSize( max_size_x, max_size_y );
  191. GetCanvas()->GetView()->SetBoundary( bbox );
  192. GetToolManager()->RunAction( ACTIONS::zoomFitScreen );
  193. // If a symbol was previously selected in m_symbolList from a previous run, show it
  194. wxString symbName = m_symbolList->GetStringSelection();
  195. if( !symbName.IsEmpty() )
  196. {
  197. SetSelectedSymbol( symbName );
  198. updatePreviewSymbol();
  199. }
  200. }
  201. SYMBOL_VIEWER_FRAME::~SYMBOL_VIEWER_FRAME()
  202. {
  203. // Shutdown all running tools
  204. if( m_toolManager )
  205. m_toolManager->ShutdownAllTools();
  206. if( m_previewItem )
  207. {
  208. GetCanvas()->GetView()->Remove( m_previewItem.get() );
  209. m_previewItem = nullptr;
  210. }
  211. }
  212. void SYMBOL_VIEWER_FRAME::loadAllLibraries()
  213. {
  214. // TODO: deduplicate with SYMBOL_TREE_MODEL_ADAPTER::AddLibraries
  215. std::vector<wxString> libraryNames = PROJECT_SCH::SchSymbolLibTable( &Prj() )->GetLogicalLibs();
  216. std::unique_ptr<WX_PROGRESS_REPORTER> progressReporter = nullptr;
  217. if( m_show_progress )
  218. {
  219. progressReporter = std::make_unique<WX_PROGRESS_REPORTER>( this,
  220. _( "Loading Symbol Libraries" ),
  221. libraryNames.size(), true );
  222. }
  223. // Disable KIID generation: not needed for library parts; sometimes very slow
  224. KIID::CreateNilUuids( true );
  225. std::unordered_map<wxString, std::vector<LIB_SYMBOL*>> loadedSymbols;
  226. SYMBOL_ASYNC_LOADER loader( libraryNames, PROJECT_SCH::SchSymbolLibTable( &Prj() ), false,
  227. nullptr, progressReporter.get() );
  228. LOCALE_IO toggle;
  229. loader.Start();
  230. while( !loader.Done() )
  231. {
  232. if( progressReporter && !progressReporter->KeepRefreshing() )
  233. break;
  234. wxMilliSleep( 33 );
  235. }
  236. loader.Join();
  237. KIID::CreateNilUuids( false );
  238. if( !loader.GetErrors().IsEmpty() )
  239. {
  240. HTML_MESSAGE_BOX dlg( this, _( "Load Error" ) );
  241. dlg.MessageSet( _( "Errors loading symbols:" ) );
  242. wxString msg = loader.GetErrors();
  243. msg.Replace( "\n", "<BR>" );
  244. dlg.AddHTML_Text( msg );
  245. dlg.ShowModal();
  246. }
  247. }
  248. void SYMBOL_VIEWER_FRAME::setupTools()
  249. {
  250. // Create the manager and dispatcher & route draw panel events to the dispatcher
  251. m_toolManager = new TOOL_MANAGER;
  252. m_toolManager->SetEnvironment( GetScreen(), GetCanvas()->GetView(),
  253. GetCanvas()->GetViewControls(), config(), this );
  254. m_actions = new SCH_ACTIONS();
  255. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  256. // Register tools
  257. m_toolManager->RegisterTool( new COMMON_TOOLS );
  258. m_toolManager->RegisterTool( new COMMON_CONTROL );
  259. m_toolManager->RegisterTool( new ZOOM_TOOL );
  260. m_toolManager->RegisterTool( new SCH_INSPECTION_TOOL ); // manage show datasheet
  261. m_toolManager->RegisterTool( new SCH_SELECTION_TOOL ); // manage context menu
  262. m_toolManager->RegisterTool( new SYMBOL_EDITOR_CONTROL ); // manage render settings
  263. m_toolManager->InitTools();
  264. // Run the selection tool, it is supposed to be always active
  265. // It also manages the mouse right click to show the context menu
  266. m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
  267. GetCanvas()->SetEventDispatcher( m_toolDispatcher );
  268. }
  269. void SYMBOL_VIEWER_FRAME::setupUIConditions()
  270. {
  271. SCH_BASE_FRAME::setupUIConditions();
  272. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  273. EDITOR_CONDITIONS cond( this );
  274. wxASSERT( mgr );
  275. #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
  276. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  277. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  278. auto electricalTypesShownCondition =
  279. [this]( const SELECTION& aSel )
  280. {
  281. return GetRenderSettings() && GetRenderSettings()->m_ShowPinsElectricalType;
  282. };
  283. auto pinNumbersShownCondition =
  284. [this]( const SELECTION& )
  285. {
  286. return GetRenderSettings() && GetRenderSettings()->m_ShowPinNumbers;
  287. };
  288. auto demorganCond =
  289. [this]( const SELECTION& )
  290. {
  291. LIB_SYMBOL* symbol = GetSelectedSymbol();
  292. return symbol && symbol->HasAlternateBodyStyle();
  293. };
  294. auto demorganStandardCond =
  295. []( const SELECTION& )
  296. {
  297. return m_bodyStyle == BODY_STYLE::BASE;
  298. };
  299. auto demorganAlternateCond =
  300. []( const SELECTION& )
  301. {
  302. return m_bodyStyle == BODY_STYLE::DEMORGAN;
  303. };
  304. auto haveDatasheetCond =
  305. [this]( const SELECTION& )
  306. {
  307. LIB_SYMBOL* symbol = GetSelectedSymbol();
  308. return symbol && !symbol->GetDatasheetField().GetText().IsEmpty();
  309. };
  310. mgr->SetConditions( ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
  311. mgr->SetConditions( SCH_ACTIONS::showElectricalTypes, CHECK( electricalTypesShownCondition ) );
  312. mgr->SetConditions( SCH_ACTIONS::showPinNumbers, CHECK( pinNumbersShownCondition ) );
  313. mgr->SetConditions( SCH_ACTIONS::showDeMorganStandard, ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganStandardCond ) );
  314. mgr->SetConditions( SCH_ACTIONS::showDeMorganAlternate, ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganAlternateCond ) );
  315. #undef CHECK
  316. #undef ENABLE
  317. }
  318. void SYMBOL_VIEWER_FRAME::SetUnitAndBodyStyle( int aUnit, int aBodyStyle )
  319. {
  320. m_unit = aUnit > 0 ? aUnit : 1;
  321. m_bodyStyle = aBodyStyle > 0 ? aBodyStyle : BODY_STYLE::BASE;
  322. m_selection_changed = false;
  323. updatePreviewSymbol();
  324. }
  325. LIB_SYMBOL* SYMBOL_VIEWER_FRAME::GetSelectedSymbol() const
  326. {
  327. LIB_SYMBOL* symbol = nullptr;
  328. if( m_currentSymbol.IsValid() )
  329. symbol = PROJECT_SCH::SchSymbolLibTable( &Prj() )->LoadSymbol( m_currentSymbol );
  330. return symbol;
  331. }
  332. void SYMBOL_VIEWER_FRAME::updatePreviewSymbol()
  333. {
  334. LIB_SYMBOL* symbol = GetSelectedSymbol();
  335. KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
  336. if( m_previewItem )
  337. {
  338. view->Remove( m_previewItem.get() );
  339. m_previewItem = nullptr;
  340. }
  341. ClearMsgPanel();
  342. if( symbol )
  343. {
  344. GetRenderSettings()->m_ShowUnit = m_unit;
  345. GetRenderSettings()->m_ShowBodyStyle = m_bodyStyle;
  346. m_previewItem = symbol->Flatten();
  347. view->Add( m_previewItem.get() );
  348. wxString parentName;
  349. std::shared_ptr<LIB_SYMBOL> parent = symbol->GetParent().lock();
  350. if( parent )
  351. parentName = parent->GetName();
  352. AppendMsgPanel( _( "Name" ), UnescapeString( m_previewItem->GetName() ) );
  353. AppendMsgPanel( _( "Parent" ), UnescapeString( parentName ) );
  354. AppendMsgPanel( _( "Description" ), m_previewItem->GetDescription() );
  355. AppendMsgPanel( _( "Keywords" ), m_previewItem->GetKeyWords() );
  356. }
  357. m_toolManager->RunAction( ACTIONS::zoomFitScreen );
  358. GetCanvas()->Refresh();
  359. }
  360. void SYMBOL_VIEWER_FRAME::doCloseWindow()
  361. {
  362. GetCanvas()->SetEvtHandlerEnabled( false );
  363. GetCanvas()->StopDrawing();
  364. Destroy();
  365. }
  366. void SYMBOL_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
  367. {
  368. if( m_auimgr.GetManagedWindow() )
  369. m_auimgr.Update();
  370. SizeEv.Skip();
  371. }
  372. void SYMBOL_VIEWER_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
  373. {
  374. LIB_SYMBOL* symbol = GetSelectedSymbol();
  375. int unit_count = 1;
  376. if( symbol )
  377. unit_count = std::max( symbol->GetUnitCount(), 1 );
  378. m_unitChoice->Enable( unit_count > 1 );
  379. if( unit_count > 1 )
  380. {
  381. // rebuild the unit list if it is not suitable (after a new selection for instance)
  382. if( unit_count != (int)m_unitChoice->GetCount() )
  383. {
  384. m_unitChoice->Clear();
  385. for( int ii = 0; ii < unit_count; ii++ )
  386. {
  387. wxString unit = symbol->GetUnitDisplayName( ii + 1 );
  388. m_unitChoice->Append( unit );
  389. }
  390. }
  391. if( m_unitChoice->GetSelection() != std::max( 0, m_unit - 1 ) )
  392. m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) );
  393. }
  394. else if( m_unitChoice->GetCount() )
  395. {
  396. m_unitChoice->Clear();
  397. }
  398. }
  399. bool SYMBOL_VIEWER_FRAME::ReCreateLibList()
  400. {
  401. if( !m_libList )
  402. return false;
  403. m_libList->Clear();
  404. COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
  405. PROJECT_FILE& project = Kiway().Prj().GetProjectFile();
  406. SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &Prj() );
  407. std::vector<wxString> libs = libTable->GetLogicalLibs();
  408. std::vector<wxString> pinnedMatches;
  409. std::vector<wxString> otherMatches;
  410. auto doAddLib =
  411. [&]( const wxString& aLib )
  412. {
  413. if( alg::contains( project.m_PinnedSymbolLibs, aLib )
  414. || alg::contains( cfg->m_Session.pinned_symbol_libs, aLib ) )
  415. {
  416. pinnedMatches.push_back( aLib );
  417. }
  418. else
  419. {
  420. otherMatches.push_back( aLib );
  421. }
  422. };
  423. auto process =
  424. [&]( const wxString& aLib )
  425. {
  426. // Remove not allowed libs, if the allowed lib list is not empty
  427. if( m_allowedLibs.GetCount() )
  428. {
  429. if( m_allowedLibs.Index( aLib ) == wxNOT_FOUND )
  430. return;
  431. }
  432. // Remove libs which have no power symbols, if this filter is activated
  433. if( m_listPowerOnly )
  434. {
  435. wxArrayString aliasNames;
  436. PROJECT_SCH::SchSymbolLibTable( &Prj() )->EnumerateSymbolLib( aLib,
  437. aliasNames,
  438. true );
  439. if( aliasNames.IsEmpty() )
  440. return;
  441. }
  442. SYMBOL_LIB_TABLE_ROW* row = libTable->FindRow( aLib );
  443. wxCHECK( row, /* void */ );
  444. if( !row->GetIsVisible() )
  445. return;
  446. if( row->SupportsSubLibraries() )
  447. {
  448. std::vector<wxString> subLibraries;
  449. row->GetSubLibraryNames( subLibraries );
  450. for( const wxString& lib : subLibraries )
  451. {
  452. wxString suffix = lib.IsEmpty() ? wxString( wxT( "" ) )
  453. : wxString::Format( wxT( " - %s" ), lib );
  454. wxString name = wxString::Format( wxT( "%s%s" ), aLib, suffix );
  455. doAddLib( name );
  456. }
  457. }
  458. else
  459. {
  460. doAddLib( aLib );
  461. }
  462. };
  463. if( m_libFilter->GetValue().IsEmpty() )
  464. {
  465. for( const wxString& lib : libs )
  466. process( lib );
  467. }
  468. else
  469. {
  470. wxStringTokenizer tokenizer( m_libFilter->GetValue() );
  471. while( tokenizer.HasMoreTokens() )
  472. {
  473. const wxString term = tokenizer.GetNextToken().Lower();
  474. EDA_COMBINED_MATCHER matcher( term, CTX_LIBITEM );
  475. for( const wxString& lib : libs )
  476. {
  477. if( matcher.Find( lib.Lower() ) )
  478. process( lib );
  479. }
  480. }
  481. }
  482. if( libs.empty() )
  483. return true;
  484. for( const wxString& name : pinnedMatches )
  485. m_libList->Append( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + UnescapeString( name ) );
  486. for( const wxString& name : otherMatches )
  487. m_libList->Append( UnescapeString( name ) );
  488. // Search for a previous selection:
  489. int index =
  490. m_libList->FindString( UnescapeString( m_currentSymbol.GetUniStringLibNickname() ) );
  491. if( index != wxNOT_FOUND )
  492. {
  493. m_libList->SetSelection( index, true );
  494. }
  495. else
  496. {
  497. // If not found, clear current library selection because it can be deleted after a
  498. // config change.
  499. m_currentSymbol.SetLibNickname( m_libList->GetCount() > 0
  500. ? m_libList->GetBaseString( 0 ) : wxString( wxT( "" ) ) );
  501. m_currentSymbol.SetLibItemName( wxEmptyString );
  502. m_unit = 1;
  503. m_bodyStyle = BODY_STYLE::BASE;
  504. }
  505. bool cmp_changed = ReCreateSymbolList();
  506. DisplayLibInfos();
  507. GetCanvas()->Refresh();
  508. return cmp_changed;
  509. }
  510. bool SYMBOL_VIEWER_FRAME::ReCreateSymbolList()
  511. {
  512. if( m_symbolList == nullptr )
  513. return false;
  514. m_symbolList->Clear();
  515. wxString libName = m_currentSymbol.GetUniStringLibNickname();
  516. if( libName.IsEmpty() )
  517. return false;
  518. std::vector<LIB_SYMBOL*> symbols;
  519. SYMBOL_LIB_TABLE_ROW* row = PROJECT_SCH::SchSymbolLibTable( &Prj() )->FindRow( libName );
  520. try
  521. {
  522. if( row )
  523. PROJECT_SCH::SchSymbolLibTable( &Prj() )->LoadSymbolLib( symbols, libName,
  524. m_listPowerOnly );
  525. }
  526. catch( const IO_ERROR& ) {} // ignore, it is handled below
  527. std::set<wxString> excludes;
  528. if( !m_symbolFilter->GetValue().IsEmpty() )
  529. {
  530. wxStringTokenizer tokenizer( m_symbolFilter->GetValue() );
  531. while( tokenizer.HasMoreTokens() )
  532. {
  533. const wxString filterTerm = tokenizer.GetNextToken().Lower();
  534. EDA_COMBINED_MATCHER matcher( filterTerm, CTX_LIBITEM );
  535. for( LIB_SYMBOL* symbol : symbols )
  536. {
  537. std::vector<SEARCH_TERM> searchTerms = symbol->GetSearchTerms();
  538. int matched = matcher.ScoreTerms( searchTerms );
  539. if( filterTerm.IsNumber() && wxAtoi( filterTerm ) == (int)symbol->GetPinCount() )
  540. matched++;
  541. if( !matched )
  542. excludes.insert( symbol->GetName() );
  543. }
  544. }
  545. }
  546. wxString subLib = m_currentSymbol.GetSubLibraryName();
  547. for( const LIB_SYMBOL* symbol : symbols )
  548. {
  549. if( row && row->SupportsSubLibraries()
  550. && !subLib.IsSameAs( symbol->GetLibId().GetSubLibraryName() ) )
  551. {
  552. continue;
  553. }
  554. if( !excludes.count( symbol->GetName() ) )
  555. m_symbolList->Append( UnescapeString( symbol->GetName() ) );
  556. }
  557. if( m_symbolList->IsEmpty() )
  558. {
  559. SetSelectedSymbol( wxEmptyString );
  560. m_bodyStyle = BODY_STYLE::BASE;
  561. m_unit = 1;
  562. return true;
  563. }
  564. int index =
  565. m_symbolList->FindString( UnescapeString( m_currentSymbol.GetUniStringLibItemName() ) );
  566. bool changed = false;
  567. if( index == wxNOT_FOUND )
  568. {
  569. // Select the first library entry when the previous entry name does not exist in
  570. // the current library.
  571. m_bodyStyle = BODY_STYLE::BASE;
  572. m_unit = 1;
  573. index = -1;
  574. changed = true;
  575. SetSelectedSymbol( wxEmptyString );
  576. }
  577. m_symbolList->SetSelection( index, true );
  578. return changed;
  579. }
  580. void SYMBOL_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event )
  581. {
  582. int ii = m_libList->GetSelection();
  583. if( ii < 0 )
  584. return;
  585. m_selection_changed = true;
  586. wxString selection = EscapeString( m_libList->GetBaseString( ii ), CTX_LIBID );
  587. if( !PROJECT_SCH::SchSymbolLibTable( &Prj() )->FindRow( selection )
  588. && selection.Find( '-' ) != wxNOT_FOUND )
  589. {
  590. // Probably a sub-library
  591. wxString sublib;
  592. selection = selection.BeforeLast( '-', &sublib ).Trim();
  593. sublib.Trim( false );
  594. SetSelectedLibrary( selection, sublib );
  595. }
  596. else
  597. {
  598. SetSelectedLibrary( selection );
  599. }
  600. }
  601. void SYMBOL_VIEWER_FRAME::SetSelectedLibrary( const wxString& aLibraryName,
  602. const wxString& aSubLibName )
  603. {
  604. if( m_currentSymbol.GetUniStringLibNickname() == aLibraryName
  605. && wxString( m_currentSymbol.GetSubLibraryName().wx_str() ) == aSubLibName )
  606. return;
  607. m_currentSymbol.SetLibNickname( aLibraryName );
  608. m_currentSymbol.SetSubLibraryName( aSubLibName );
  609. ReCreateSymbolList();
  610. GetCanvas()->Refresh();
  611. DisplayLibInfos();
  612. // Ensure the corresponding line in m_libList is selected
  613. // (which is not necessary the case if SetSelectedLibrary is called
  614. // by another caller than ClickOnLibList.
  615. m_libList->SetStringSelection( UnescapeString( m_currentSymbol.GetFullLibraryName() ), true );
  616. // The m_libList has now the focus, in order to be able to use arrow keys
  617. // to navigate inside the list.
  618. // the gal canvas must not steal the focus to allow navigation
  619. GetCanvas()->SetStealsFocus( false );
  620. m_libList->SetFocus();
  621. }
  622. void SYMBOL_VIEWER_FRAME::ClickOnSymbolList( wxCommandEvent& event )
  623. {
  624. int ii = m_symbolList->GetSelection();
  625. if( ii < 0 )
  626. return;
  627. m_selection_changed = true;
  628. SetSelectedSymbol( EscapeString( m_symbolList->GetBaseString( ii ), CTX_LIBID ) );
  629. // The m_symbolList has now the focus, in order to be able to use arrow keys
  630. // to navigate inside the list.
  631. // the gal canvas must not steal the focus to allow navigation
  632. GetCanvas()->SetStealsFocus( false );
  633. m_symbolList->SetFocus();
  634. }
  635. void SYMBOL_VIEWER_FRAME::SetSelectedSymbol( const wxString& aSymbolName )
  636. {
  637. if( m_currentSymbol.GetUniStringLibItemName() != aSymbolName )
  638. {
  639. m_currentSymbol.SetLibItemName( aSymbolName );
  640. // Ensure the corresponding line in m_symbolList is selected
  641. // (which is not necessarily the case if SetSelectedSymbol is called
  642. // by another caller than ClickOnSymbolList.
  643. m_symbolList->SetStringSelection( UnescapeString( aSymbolName ), true );
  644. DisplayLibInfos();
  645. if( m_selection_changed )
  646. {
  647. m_unit = 1;
  648. m_bodyStyle = BODY_STYLE::BASE;
  649. m_selection_changed = false;
  650. }
  651. updatePreviewSymbol();
  652. }
  653. }
  654. void SYMBOL_VIEWER_FRAME::DClickOnSymbolList( wxCommandEvent& event )
  655. {
  656. m_toolManager->RunAction( SCH_ACTIONS::addSymbolToSchematic );
  657. }
  658. void SYMBOL_VIEWER_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  659. {
  660. SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
  661. EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
  662. SCH_BASE_FRAME::LoadSettings( cfg );
  663. // Grid shape, etc.
  664. GetGalDisplayOptions().ReadWindowSettings( cfg->m_LibViewPanel.window );
  665. m_libListWidth = cfg->m_LibViewPanel.lib_list_width;
  666. m_symbolListWidth = cfg->m_LibViewPanel.cmp_list_width;
  667. GetRenderSettings()->m_ShowPinsElectricalType = cfg->m_LibViewPanel.show_pin_electrical_type;
  668. GetRenderSettings()->m_ShowPinNumbers = cfg->m_LibViewPanel.show_pin_numbers;
  669. // Set parameters to a reasonable value.
  670. int maxWidth = cfg->m_LibViewPanel.window.state.size_x - 80;
  671. if( m_libListWidth + m_symbolListWidth > maxWidth )
  672. {
  673. m_libListWidth = maxWidth * ( m_libListWidth / ( m_libListWidth + m_symbolListWidth ) );
  674. m_symbolListWidth = maxWidth - m_libListWidth;
  675. }
  676. }
  677. void SYMBOL_VIEWER_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg)
  678. {
  679. SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
  680. EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
  681. SCH_BASE_FRAME::SaveSettings( cfg );
  682. if( m_libListWidth && m_libList )
  683. m_libListWidth = m_libList->GetSize().x;
  684. m_symbolListWidth = m_symbolList->GetSize().x;
  685. cfg->m_LibViewPanel.lib_list_width = m_libListWidth;
  686. cfg->m_LibViewPanel.cmp_list_width = m_symbolListWidth;
  687. if( SCH_RENDER_SETTINGS* renderSettings = GetRenderSettings() )
  688. {
  689. cfg->m_LibViewPanel.show_pin_electrical_type = renderSettings->m_ShowPinsElectricalType;
  690. cfg->m_LibViewPanel.show_pin_numbers = renderSettings->m_ShowPinNumbers;
  691. }
  692. }
  693. WINDOW_SETTINGS* SYMBOL_VIEWER_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
  694. {
  695. EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
  696. wxASSERT( cfg );
  697. return &cfg->m_LibViewPanel.window;
  698. }
  699. void SYMBOL_VIEWER_FRAME::CommonSettingsChanged( int aFlags )
  700. {
  701. SCH_BASE_FRAME::CommonSettingsChanged( aFlags );
  702. SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
  703. EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
  704. GetGalDisplayOptions().ReadWindowSettings( cfg->m_LibViewPanel.window );
  705. GetCanvas()->GetGAL()->SetAxesColor( m_colorSettings->GetColor( LAYER_SCHEMATIC_GRID_AXES ) );
  706. GetCanvas()->GetGAL()->DrawGrid();
  707. GetCanvas()->ForceRefresh();
  708. if( aFlags && ENVVARS_CHANGED )
  709. ReCreateLibList();
  710. }
  711. void SYMBOL_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
  712. {
  713. if( event.GetActive() )
  714. {
  715. bool changed = m_libList ? ReCreateLibList() : false;
  716. if (changed)
  717. m_selection_changed = true;
  718. updatePreviewSymbol();
  719. DisplayLibInfos();
  720. }
  721. event.Skip(); // required under wxMAC
  722. }
  723. void SYMBOL_VIEWER_FRAME::CloseLibraryViewer( wxCommandEvent& event )
  724. {
  725. Close();
  726. }
  727. const BOX2I SYMBOL_VIEWER_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
  728. {
  729. LIB_SYMBOL* symbol = GetSelectedSymbol();
  730. if( !symbol )
  731. {
  732. return BOX2I( VECTOR2I( -200, -200 ), VECTOR2I( 400, 400 ) );
  733. }
  734. else
  735. {
  736. std::shared_ptr<LIB_SYMBOL> tmp = symbol->IsAlias() ? symbol->GetParent().lock()
  737. : symbol->SharedPtr();
  738. wxCHECK( tmp, BOX2I( VECTOR2I( -200, -200 ), VECTOR2I( 400, 400 ) ) );
  739. return tmp->GetUnitBoundingBox( m_unit, m_bodyStyle );
  740. }
  741. }
  742. void SYMBOL_VIEWER_FRAME::OnLibFilter( wxCommandEvent& aEvent )
  743. {
  744. ReCreateLibList();
  745. // Required to avoid interaction with SetHint()
  746. // See documentation for wxTextEntry::SetHint
  747. aEvent.Skip();
  748. }
  749. void SYMBOL_VIEWER_FRAME::OnSymFilter( wxCommandEvent& aEvent )
  750. {
  751. ReCreateSymbolList();
  752. // Required to avoid interaction with SetHint()
  753. // See documentation for wxTextEntry::SetHint
  754. aEvent.Skip();
  755. }
  756. void SYMBOL_VIEWER_FRAME::OnCharHook( wxKeyEvent& aEvent )
  757. {
  758. if( aEvent.GetKeyCode() == WXK_UP )
  759. {
  760. if( m_libFilter->HasFocus() || m_libList->HasFocus() )
  761. {
  762. int prev = m_libList->GetSelection() - 1;
  763. if( prev >= 0 )
  764. {
  765. m_libList->SetSelection( prev );
  766. m_libList->EnsureVisible( prev );
  767. wxCommandEvent dummy;
  768. ClickOnLibList( dummy );
  769. }
  770. }
  771. else
  772. {
  773. wxCommandEvent dummy;
  774. onSelectPreviousSymbol( dummy );
  775. }
  776. }
  777. else if( aEvent.GetKeyCode() == WXK_DOWN )
  778. {
  779. if( m_libFilter->HasFocus() || m_libList->HasFocus() )
  780. {
  781. int next = m_libList->GetSelection() + 1;
  782. if( next < (int)m_libList->GetCount() )
  783. {
  784. m_libList->SetSelection( next );
  785. m_libList->EnsureVisible( next );
  786. wxCommandEvent dummy;
  787. ClickOnLibList( dummy );
  788. }
  789. }
  790. else
  791. {
  792. wxCommandEvent dummy;
  793. onSelectNextSymbol( dummy );
  794. }
  795. }
  796. else if( aEvent.GetKeyCode() == WXK_TAB && m_libFilter->HasFocus() )
  797. {
  798. if( !aEvent.ShiftDown() )
  799. m_symbolFilter->SetFocus();
  800. else
  801. aEvent.Skip();
  802. }
  803. else if( aEvent.GetKeyCode() == WXK_TAB && m_symbolFilter->HasFocus() )
  804. {
  805. if( aEvent.ShiftDown() )
  806. m_libFilter->SetFocus();
  807. else
  808. aEvent.Skip();
  809. }
  810. else if( ( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
  811. && m_symbolList->GetSelection() >= 0 )
  812. {
  813. wxCommandEvent dummy;
  814. DClickOnSymbolList( dummy );
  815. }
  816. else
  817. {
  818. aEvent.Skip();
  819. }
  820. }
  821. void SYMBOL_VIEWER_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
  822. {
  823. wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_SYM_LIST );
  824. int ii = m_symbolList->GetSelection();
  825. // Select the next symbol or stop at the end of the list.
  826. if( ii != wxNOT_FOUND && ii < (int) ( m_symbolList->GetCount() - 1 ) )
  827. ii += 1;
  828. m_symbolList->SetSelection( ii );
  829. ProcessEvent( evt );
  830. }
  831. void SYMBOL_VIEWER_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
  832. {
  833. wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_SYM_LIST );
  834. int ii = m_symbolList->GetSelection();
  835. // Select the previous symbol or stop at the beginning of list.
  836. if( ii != wxNOT_FOUND && ii != 0 )
  837. ii -= 1;
  838. m_symbolList->SetSelection( ii );
  839. ProcessEvent( evt );
  840. }
  841. void SYMBOL_VIEWER_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
  842. {
  843. int ii = m_unitChoice->GetSelection();
  844. if( ii < 0 )
  845. return;
  846. m_unit = ii + 1;
  847. updatePreviewSymbol();
  848. }
  849. void SYMBOL_VIEWER_FRAME::DisplayLibInfos()
  850. {
  851. wxString libName = m_currentSymbol.GetUniStringLibNickname();
  852. if( m_libList && !m_libList->IsEmpty() && !libName.IsEmpty() )
  853. {
  854. const SYMBOL_LIB_TABLE_ROW* row =
  855. PROJECT_SCH::SchSymbolLibTable( &Prj() )->FindRow( libName, true );
  856. wxString title = row ? row->GetFullURI( true ) : _( "[no library selected]" );
  857. title += wxT( " \u2014 " ) + _( "Symbol Library Browser" );
  858. SetTitle( title );
  859. }
  860. }
  861. SELECTION& SYMBOL_VIEWER_FRAME::GetCurrentSelection()
  862. {
  863. return m_toolManager->GetTool<SCH_SELECTION_TOOL>()->GetSelection();
  864. }
  865. void SYMBOL_VIEWER_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
  866. {
  867. switch( mail.Command() )
  868. {
  869. case MAIL_RELOAD_LIB:
  870. {
  871. ReCreateLibList();
  872. break;
  873. }
  874. case MAIL_REFRESH_SYMBOL:
  875. {
  876. SYMBOL_LIB_TABLE* tbl = PROJECT_SCH::SchSymbolLibTable( &Prj() );
  877. LIB_SYMBOL* symbol = GetSelectedSymbol();
  878. wxCHECK2( tbl && symbol, break );
  879. const SYMBOL_LIB_TABLE_ROW* row = tbl->FindRow( symbol->GetLibId().GetLibNickname() );
  880. if( !row )
  881. return;
  882. wxString libfullname = row->GetFullURI( true );
  883. wxString lib( mail.GetPayload() );
  884. wxLogTrace( "KICAD_LIB_WATCH", "Received refresh symbol request for %s, current symbols "
  885. "is %s", lib, libfullname );
  886. if( lib == libfullname )
  887. {
  888. wxLogTrace( "KICAD_LIB_WATCH", "Refreshing symbol %s", symbol->GetName() );
  889. updatePreviewSymbol();
  890. GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL );
  891. }
  892. break;
  893. }
  894. default:;
  895. }
  896. }