KiCad PCB EDA Suite
toolbars_lib_view.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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
7  * Copyright (C) 2019 CERN
8  *
9  * This program is free software: you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation, either version 3 of the License, or (at your
12  * option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 
24 #include <macros.h>
25 #include "class_library.h"
26 #include "eeschema_id.h"
27 #include "lib_view_frame.h"
28 #include "sch_painter.h"
29 #include <symbol_lib_table.h>
30 #include <tool/action_toolbar.h>
31 #include <tool/conditional_menu.h>
32 #include <tool/tool_manager.h>
33 #include <tools/ee_actions.h>
34 #include <tools/lib_control.h>
35 #include <widgets/wx_menubar.h>
36 
38 {
39  if( m_mainToolBar )
41  else
43  wxDefaultPosition, wxDefaultSize,
44  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
45 
46  m_mainToolBar->AddTool( ID_LIBVIEW_SELECT_PART, wxEmptyString,
48  _( "Select symbol to browse" ) );
49 
51  m_mainToolBar->AddTool( ID_LIBVIEW_PREVIOUS, wxEmptyString,
53  _( "Display previous symbol" ) );
54 
55  m_mainToolBar->AddTool( ID_LIBVIEW_NEXT, wxEmptyString,
57  _( "Display next symbol" ) );
58 
64 
68 
70 
71  if( m_unitChoice == nullptr )
73  wxDefaultPosition, wxSize( 150, -1 ) );
74  m_mainToolBar->AddControl( m_unitChoice );
75 
78 
81 
82  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
83  m_mainToolBar->Realize();
84 
85  m_mainToolBar->Refresh();
86 }
87 
88 
90 {
91 }
92 
93 
95 {
96  LIB_CONTROL* libControl = m_toolManager->GetTool<LIB_CONTROL>();
97  // wxWidgets handles the OSX Application menu behind the scenes, but that means
98  // we always have to start from scratch with a new wxMenuBar.
99  wxMenuBar* oldMenuBar = GetMenuBar();
100  WX_MENUBAR* menuBar = new WX_MENUBAR();
101 
102  //-- File menu -----------------------------------------------------------
103  //
104  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, libControl );
105 
106  fileMenu->AddClose( _( "Footprint Viewer" ) );
107 
108  fileMenu->Resolve();
109 
110 
111  //-- View menu -----------------------------------------------------------
112  //
113  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, libControl );
114 
115  auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
116  return IsGridVisible();
117  };
118  auto electricalTypesShownCondition = [ this ] ( const SELECTION& aSel ) {
120  };
121 
126 
127  viewMenu->AddSeparator();
128  viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
130 
131  viewMenu->AddSeparator();
132  viewMenu->AddCheckItem( EE_ACTIONS::showElectricalTypes, electricalTypesShownCondition );
133 
134  viewMenu->Resolve();
135 
136  //-- Menubar -------------------------------------------------------------
137  //
138  menuBar->Append( fileMenu, _( "&File" ) );
139  menuBar->Append( viewMenu, _( "&View" ) );
140  AddStandardHelpMenu( menuBar );
141  menuBar->SetDoubleBuffered( true );
142 
143  SetMenuBar( menuBar );
144  delete oldMenuBar;
145 }
146 
147 
149 {
150  LIB_PART* symbol = GetSelectedSymbol();
151 
153  symbol && !symbol->GetDatasheetField().GetText().IsEmpty() );
155  m_convert == LIB_FIELD::LIB_CONVERT::BASE );
157  m_convert == LIB_FIELD::LIB_CONVERT::DEMORGAN );
158  m_mainToolBar->Refresh();
159 }
static int m_convert
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
static TOOL_ACTION showDatasheet
Inspection and Editing.
Definition: ee_actions.h:139
LIB_PART * GetSelectedSymbol() const
ACTION_TOOLBAR.
LIB_FIELD & GetDatasheetField()
Return reference to the datasheet field.
static TOOL_ACTION zoomInCenter
Definition: actions.h:90
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
static const bool TOGGLE
void AddScaledSeparator(wxWindow *aWindow)
Add a separator that introduces space on either side to not squash the tools when scaled.
void Add(const TOOL_ACTION &aAction, bool aIsToggleEntry=false)
Function Add() Adds a TOOL_ACTION-based button to the toolbar.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
const BITMAP_OPAQUE add_component_xpm[1]
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
ACTION_TOOLBAR * m_mainToolBar
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:45
static TOOL_ACTION showDeMorganAlternate
Definition: ee_actions.h:127
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, wxWindow *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
static TOOL_ACTION zoomOutCenter
Definition: actions.h:91
This file contains miscellaneous commonly used macros and functions.
LIB_CONTROL.
Definition: lib_control.h:39
void ReCreateMenuBar() override
Recreates the menu bar.
bool IsGridVisible() const
static TOOL_ACTION toggleGrid
Definition: actions.h:136
const BITMAP_OPAQUE lib_previous_xpm[1]
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
Define a library symbol object.
void ReCreateHToolbar() override
const BITMAP_OPAQUE lib_next_xpm[1]
Definition: lib_next.cpp:82
static TOOL_ACTION addSymbolToSchematic
Definition: ee_actions.h:162
void Resolve()
Function Resolve()
static TOOL_ACTION showDeMorganStandard
Definition: ee_actions.h:126
static TOOL_ACTION showElectricalTypes
Definition: ee_actions.h:193
void SyncToolbars() override
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
void AddClose(wxString aAppname="")
Function AddClose()
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
void Toggle(const TOOL_ACTION &aAction, bool aState)
Applies the default toggle action.
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
static TOOL_ACTION gridProperties
Definition: actions.h:137
wxChoice * m_unitChoice
void ReCreateVToolbar() override
Definition for part library class.
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
void ClearToolbar()
Clear the toolbar and remove all associated menus.