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.

147 lines
5.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 3
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * https://www.gnu.org/licenses/gpl-3.0.html
  19. * or you may search the http://www.gnu.org website for the version 3 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include "footprint_tree_pane.h"
  24. #include "fp_tree_synchronizing_adapter.h"
  25. #include <widgets/lib_tree.h>
  26. #include <pcbnew_id.h>
  27. #include <footprint_edit_frame.h>
  28. #include <fp_lib_table.h>
  29. #include <menus_helpers.h>
  30. FOOTPRINT_TREE_PANE::FOOTPRINT_TREE_PANE( FOOTPRINT_EDIT_FRAME* aParent )
  31. : wxPanel( aParent ),
  32. m_frame( aParent ),
  33. m_tree( nullptr )
  34. {
  35. // Create widgets
  36. wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
  37. m_tree = new LIB_TREE( this, &GFootprintTable, m_frame->GetLibTreeAdapter(), LIB_TREE::SEARCH );
  38. boxSizer->Add( m_tree, 1, wxEXPAND, 5 );
  39. SetSizer( boxSizer ); // should remove the previous sizer according to wxWidgets docs
  40. Layout();
  41. boxSizer->Fit( this );
  42. // Setup right click-context menus
  43. std::unique_ptr<wxMenu> menuLibrary = std::make_unique<wxMenu>();
  44. AddMenuItem( menuLibrary.get(), ID_MODEDIT_CREATE_NEW_LIB, _( "&New Library..." ),
  45. KiBitmap( new_library_xpm ) );
  46. AddMenuItem( menuLibrary.get(), ID_MODEDIT_ADD_LIBRARY, _( "&Add Library..." ),
  47. KiBitmap( add_library_xpm ) );
  48. AddMenuItem( menuLibrary.get(), ID_MODEDIT_SAVE, _( "&Save" ),
  49. KiBitmap( save_xpm ) );
  50. AddMenuItem( menuLibrary.get(), ID_MODEDIT_SAVE_AS, _( "Save a Copy &As..." ),
  51. KiBitmap( save_as_xpm ) );
  52. menuLibrary->AppendSeparator();
  53. AddMenuItem( menuLibrary.get(), ID_MODEDIT_NEW_MODULE, _( "&New Footprint..." ),
  54. KiBitmap( new_component_xpm ) );
  55. #ifdef KICAD_SCRIPTING
  56. AddMenuItem( menuLibrary.get(), ID_MODEDIT_NEW_MODULE_FROM_WIZARD, _( "&Create Footprint from Wizard..." ),
  57. KiBitmap( new_component_xpm ) );
  58. #endif
  59. AddMenuItem( menuLibrary.get(), ID_MODEDIT_IMPORT_PART, _( "&Import Footprint..." ),
  60. KiBitmap( import_part_xpm ) );
  61. AddMenuItem( menuLibrary.get(), ID_MODEDIT_PASTE_PART, _( "Paste Footprint" ),
  62. KiBitmap( paste_xpm ) );
  63. std::unique_ptr<wxMenu> menuPart = std::make_unique<wxMenu>();
  64. AddMenuItem( menuPart.get(), ID_MODEDIT_EDIT_MODULE, _( "&Edit Footprint" ),
  65. KiBitmap( edit_xpm ) );
  66. menuPart->AppendSeparator();
  67. AddMenuItem( menuPart.get(), ID_MODEDIT_SAVE, _( "&Save" ),
  68. KiBitmap( save_xpm ) );
  69. AddMenuItem( menuPart.get(), ID_MODEDIT_SAVE_AS, _( "Save &As..." ),
  70. KiBitmap( save_xpm ) );
  71. AddMenuItem( menuPart.get(), ID_MODEDIT_DELETE_PART, _( "&Delete" ),
  72. KiBitmap( delete_xpm ) );
  73. AddMenuItem( menuPart.get(), ID_MODEDIT_REVERT_PART, _( "Revert" ),
  74. KiBitmap( undo_xpm ) );
  75. menuPart->AppendSeparator();
  76. AddMenuItem( menuPart.get(), ID_MODEDIT_CUT_PART, _( "Cut" ),
  77. KiBitmap( cut_xpm ) );
  78. AddMenuItem( menuPart.get(), ID_MODEDIT_COPY_PART, _( "Copy" ),
  79. KiBitmap( copy_xpm ) );
  80. menuPart->AppendSeparator();
  81. AddMenuItem( menuPart.get(), ID_MODEDIT_EXPORT_PART, _( "E&xport Footprint..." ),
  82. KiBitmap( export_part_xpm ) );
  83. // Menu displayed when nothing is selected
  84. std::unique_ptr<wxMenu> menuNoSelection = std::make_unique<wxMenu>();
  85. AddMenuItem( menuNoSelection.get(), ID_MODEDIT_CREATE_NEW_LIB, _( "&New Library..." ),
  86. KiBitmap( new_library_xpm ) );
  87. AddMenuItem( menuNoSelection.get(), ID_MODEDIT_ADD_LIBRARY, _( "&Add Library..." ),
  88. KiBitmap( add_library_xpm ) );
  89. m_tree->SetMenu( LIB_TREE_NODE::LIBID, std::move( menuPart ) );
  90. m_tree->SetMenu( LIB_TREE_NODE::LIB, std::move( menuLibrary ) );
  91. m_tree->SetMenu( LIB_TREE_NODE::INVALID, std::move( menuNoSelection ) );
  92. // Event handlers
  93. Bind( COMPONENT_SELECTED, &FOOTPRINT_TREE_PANE::onComponentSelected, this );
  94. m_tree->Bind( wxEVT_UPDATE_UI, &FOOTPRINT_TREE_PANE::onUpdateUI, this );
  95. }
  96. FOOTPRINT_TREE_PANE::~FOOTPRINT_TREE_PANE()
  97. {
  98. m_tree->Destroy();
  99. }
  100. void FOOTPRINT_TREE_PANE::Regenerate()
  101. {
  102. if( m_tree )
  103. m_tree->Regenerate( true );
  104. }
  105. void FOOTPRINT_TREE_PANE::onComponentSelected( wxCommandEvent& aEvent )
  106. {
  107. wxCommandEvent evt( wxEVT_COMMAND_TOOL_CLICKED, ID_MODEDIT_EDIT_MODULE );
  108. m_frame->Process_Special_Functions( evt );
  109. // Make sure current-part highlighting doesn't get lost in seleciton highlighting
  110. m_tree->Unselect();
  111. }
  112. void FOOTPRINT_TREE_PANE::onUpdateUI( wxUpdateUIEvent& aEvent )
  113. {
  114. if( m_frame->GetGalCanvas()->HasFocus() )
  115. {
  116. // Don't allow a selected item in the tree when the canvas has focus: it's too easy
  117. // to confuse the selected-highlighting with the being-edited-on-canvas-highlighting.
  118. m_tree->Unselect();
  119. }
  120. }