kicad-source/pagelayout_editor/toolbars_pl_editor.cpp

186 lines
6.0 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
2019-08-14 09:28:07 +01:00
* Copyright (C) 2013-2019 CERN
* @author Jean-Pierre Charras, jp.charras at wanadoo.fr
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <bitmaps.h>
2019-06-09 22:57:23 +01:00
#include <tool/action_toolbar.h>
#include <tool/tool_manager.h>
#include <tools/pl_actions.h>
#include <tools/pl_selection_tool.h>
2021-06-03 07:49:49 -04:00
#include <wx/choice.h>
2020-10-13 01:04:31 -04:00
#include "pl_editor_id.h"
#include "pl_editor_frame.h"
std::optional<TOOLBAR_CONFIGURATION> PL_EDITOR_FRAME::DefaultLeftToolbarConfig()
{
TOOLBAR_CONFIGURATION config;
// clang-format off
config.AppendAction( ACTIONS::toggleGrid )
.AppendAction( ACTIONS::inchesUnits )
.AppendAction( ACTIONS::milsUnits )
.AppendAction( ACTIONS::millimetersUnits );
/* TODO: Implement context menus
PL_SELECTION_TOOL* selTool = m_toolManager->GetTool<PL_SELECTION_TOOL>();
std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( false, selTool );
gridMenu->Add( ACTIONS::gridProperties );
m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) );
*/
// clang-format on
return config;
}
std::optional<TOOLBAR_CONFIGURATION> PL_EDITOR_FRAME::DefaultRightToolbarConfig()
{
TOOLBAR_CONFIGURATION config;
// clang-format off
config.AppendAction( ACTIONS::selectionTool );
config.AppendSeparator()
.AppendAction( PL_ACTIONS::drawLine )
.AppendAction( PL_ACTIONS::drawRectangle )
.AppendAction( PL_ACTIONS::placeText )
.AppendAction( PL_ACTIONS::placeImage )
.AppendAction( PL_ACTIONS::appendImportedDrawingSheet );
config.AppendSeparator()
.AppendAction( ACTIONS::deleteTool );
// clang-format on
return config;
}
std::optional<TOOLBAR_CONFIGURATION> PL_EDITOR_FRAME::DefaultTopMainToolbarConfig()
{
TOOLBAR_CONFIGURATION config;
// clang-format off
config.AppendAction( ACTIONS::doNew )
.AppendAction( ACTIONS::open )
.AppendAction( ACTIONS::save );
config.AppendSeparator()
.AppendAction( ACTIONS::print );
config.AppendSeparator()
.AppendAction( ACTIONS::undo )
.AppendAction( ACTIONS::redo );
config.AppendSeparator()
.AppendAction( ACTIONS::zoomRedraw )
.AppendAction( ACTIONS::zoomInCenter )
.AppendAction( ACTIONS::zoomOutCenter )
.AppendAction( ACTIONS::zoomFitScreen )
.AppendAction( ACTIONS::zoomTool );
config.AppendSeparator()
.AppendAction( PL_ACTIONS::showInspector )
.AppendAction( PL_ACTIONS::previewSettings );
// Display mode switch
config.AppendSeparator()
.AppendAction( PL_ACTIONS::layoutNormalMode )
.AppendAction( PL_ACTIONS::layoutEditMode );
config.AppendSeparator()
.AppendControl( "control.PLEditorOrigin" )
.AppendControl( "control.PLEditorPageSelect" );
// clang-format on
return config;
}
void PL_EDITOR_FRAME::configureToolbars()
{
EDA_DRAW_FRAME::configureToolbars();
2025-02-20 12:42:39 +00:00
auto originSelectorFactory =
[this]( ACTION_TOOLBAR* aToolbar )
{
if( !m_originSelectBox )
{
m_originSelectBox = new wxChoice( aToolbar, ID_SELECT_COORDINATE_ORIGIN,
wxDefaultPosition, wxDefaultSize, 5, m_originChoiceList );
}
m_originSelectBox->SetToolTip( _("Origin of coordinates displayed to the status bar") );
m_originSelectBox->SetSelection( m_originSelectChoice );
aToolbar->Add( m_originSelectBox );
};
RegisterCustomToolbarControlFactory( "control.PLEditorOrigin", _( "Origin Selector" ),
_( "Select the origin of the status bar coordinates" ),
originSelectorFactory );
2025-02-20 12:42:39 +00:00
auto pageSelectorFactory =
[this]( ACTION_TOOLBAR* aToolbar )
{
wxString pageList[5] =
{
_("Page 1"),
_("Other pages")
};
if( !m_pageSelectBox )
{
m_pageSelectBox = new wxChoice( aToolbar, ID_SELECT_PAGE_NUMBER,
wxDefaultPosition, wxDefaultSize, 2, pageList );
}
m_pageSelectBox->SetToolTip( _("Simulate page 1 or other pages to show how items\n"\
"which are not on all page are displayed") );
m_pageSelectBox->SetSelection( 0 );
aToolbar->Add( m_pageSelectBox );
};
RegisterCustomToolbarControlFactory( "control.PLEditorPageSelect", _( "Page Selector" ),
_( "Select the page to simulate item displays" ),
pageSelectorFactory );
}
void PL_EDITOR_FRAME::UpdateToolbarControlSizes()
{
// Ensure the origin selector is a minimum size
int minwidth = 0;
for( int ii = 0; ii < 5; ii++ )
{
int width = KIUI::GetTextSize( m_originChoiceList[ii], m_originSelectBox ).x;
minwidth = std::max( minwidth, width );
}
m_originSelectBox->SetMinSize( wxSize( minwidth, -1 ) );
// Base class actually will go through and update the sizes of the controls
EDA_DRAW_FRAME::UpdateToolbarControlSizes();
}