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.

182 lines
6.3 KiB

10 months ago
10 months ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. * Copyright (C) 2013-2019 CERN
  6. * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
  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. #include <bitmaps.h>
  22. #include <tool/action_toolbar.h>
  23. #include <tool/tool_manager.h>
  24. #include <tools/pl_actions.h>
  25. #include <tools/pl_selection_tool.h>
  26. #include <wx/choice.h>
  27. #include "pl_editor_id.h"
  28. #include "pl_editor_frame.h"
  29. #include <toolbars_pl_editor.h>
  30. std::optional<TOOLBAR_CONFIGURATION> PL_EDITOR_TOOLBAR_SETTINGS::DefaultToolbarConfig( TOOLBAR_LOC aToolbar )
  31. {
  32. TOOLBAR_CONFIGURATION config;
  33. // clang-format off
  34. switch( aToolbar )
  35. {
  36. // No aux toolbar
  37. case TOOLBAR_LOC::TOP_AUX:
  38. return std::nullopt;
  39. case TOOLBAR_LOC::LEFT:
  40. config.AppendAction( ACTIONS::toggleGrid )
  41. .AppendAction( ACTIONS::inchesUnits )
  42. .AppendAction( ACTIONS::milsUnits )
  43. .AppendAction( ACTIONS::millimetersUnits );
  44. /* TODO: Implement context menus
  45. PL_SELECTION_TOOL* selTool = m_toolManager->GetTool<PL_SELECTION_TOOL>();
  46. std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( false, selTool );
  47. gridMenu->Add( ACTIONS::gridProperties );
  48. m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) );
  49. */
  50. break;
  51. case TOOLBAR_LOC::RIGHT:
  52. config.AppendAction( ACTIONS::selectionTool );
  53. config.AppendSeparator()
  54. .AppendAction( PL_ACTIONS::drawLine )
  55. .AppendAction( PL_ACTIONS::drawRectangle )
  56. .AppendAction( PL_ACTIONS::placeText )
  57. .AppendAction( PL_ACTIONS::placeImage )
  58. .AppendAction( PL_ACTIONS::appendImportedDrawingSheet );
  59. config.AppendSeparator()
  60. .AppendAction( ACTIONS::deleteTool );
  61. break;
  62. case TOOLBAR_LOC::TOP_MAIN:
  63. config.AppendAction( ACTIONS::doNew )
  64. .AppendAction( ACTIONS::open )
  65. .AppendAction( ACTIONS::save );
  66. config.AppendSeparator()
  67. .AppendAction( ACTIONS::print );
  68. config.AppendSeparator()
  69. .AppendAction( ACTIONS::undo )
  70. .AppendAction( ACTIONS::redo );
  71. config.AppendSeparator()
  72. .AppendAction( ACTIONS::zoomRedraw )
  73. .AppendAction( ACTIONS::zoomInCenter )
  74. .AppendAction( ACTIONS::zoomOutCenter )
  75. .AppendAction( ACTIONS::zoomFitScreen )
  76. .AppendAction( ACTIONS::zoomTool );
  77. config.AppendSeparator()
  78. .AppendAction( PL_ACTIONS::showInspector )
  79. .AppendAction( PL_ACTIONS::previewSettings );
  80. // Display mode switch
  81. config.AppendSeparator()
  82. .AppendAction( PL_ACTIONS::layoutNormalMode )
  83. .AppendAction( PL_ACTIONS::layoutEditMode );
  84. config.AppendSeparator()
  85. .AppendControl( PL_EDITOR_ACTION_TOOLBAR_CONTROLS::originSelector )
  86. .AppendControl( PL_EDITOR_ACTION_TOOLBAR_CONTROLS::pageSelect );
  87. break;
  88. }
  89. // clang-format on
  90. return config;
  91. }
  92. void PL_EDITOR_FRAME::configureToolbars()
  93. {
  94. EDA_DRAW_FRAME::configureToolbars();
  95. auto originSelectorFactory =
  96. [this]( ACTION_TOOLBAR* aToolbar )
  97. {
  98. if( !m_originSelectBox )
  99. {
  100. m_originSelectBox = new wxChoice( aToolbar, ID_SELECT_COORDINATE_ORIGIN,
  101. wxDefaultPosition, wxDefaultSize, 5, m_originChoiceList );
  102. }
  103. m_originSelectBox->SetToolTip( _("Origin of coordinates displayed to the status bar") );
  104. m_originSelectBox->SetSelection( m_originSelectChoice );
  105. aToolbar->Add( m_originSelectBox );
  106. };
  107. RegisterCustomToolbarControlFactory( PL_EDITOR_ACTION_TOOLBAR_CONTROLS::originSelector, originSelectorFactory );
  108. auto pageSelectorFactory =
  109. [this]( ACTION_TOOLBAR* aToolbar )
  110. {
  111. wxString pageList[5] =
  112. {
  113. _("Page 1"),
  114. _("Other pages")
  115. };
  116. if( !m_pageSelectBox )
  117. {
  118. m_pageSelectBox = new wxChoice( aToolbar, ID_SELECT_PAGE_NUMBER,
  119. wxDefaultPosition, wxDefaultSize, 2, pageList );
  120. }
  121. m_pageSelectBox->SetToolTip( _("Simulate page 1 or other pages to show how items\n"\
  122. "which are not on all page are displayed") );
  123. m_pageSelectBox->SetSelection( 0 );
  124. aToolbar->Add( m_pageSelectBox );
  125. };
  126. RegisterCustomToolbarControlFactory( PL_EDITOR_ACTION_TOOLBAR_CONTROLS::pageSelect, pageSelectorFactory );
  127. }
  128. ACTION_TOOLBAR_CONTROL PL_EDITOR_ACTION_TOOLBAR_CONTROLS::originSelector( "control.OriginSelector", _( "Origin Selector" ),
  129. _( "Select the origin of the status bar coordinates" ) );
  130. ACTION_TOOLBAR_CONTROL PL_EDITOR_ACTION_TOOLBAR_CONTROLS::pageSelect( "control.PageSelect", _( "Page Selector" ),
  131. _( "Select the page to simulate item displays" ));
  132. void PL_EDITOR_FRAME::UpdateToolbarControlSizes()
  133. {
  134. // Ensure the origin selector is a minimum size
  135. int minwidth = 0;
  136. for( int ii = 0; ii < 5; ii++ )
  137. {
  138. int width = KIUI::GetTextSize( m_originChoiceList[ii], m_originSelectBox ).x;
  139. minwidth = std::max( minwidth, width );
  140. }
  141. m_originSelectBox->SetMinSize( wxSize( minwidth, -1 ) );
  142. // Base class actually will go through and update the sizes of the controls
  143. EDA_DRAW_FRAME::UpdateToolbarControlSizes();
  144. }