KiCad PCB EDA Suite
toolbars_viewlib.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-2019 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 "general.h"
28 #include "viewlib_frame.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 
37 {
38  if( m_mainToolBar )
39  m_mainToolBar->Clear();
40  else
42  wxDefaultPosition, wxDefaultSize,
43  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
44 
45  ACTION_TOOLBAR* toolbar = static_cast<ACTION_TOOLBAR*>( m_mainToolBar );
46  wxString msg;
47 
48  m_mainToolBar->AddTool( ID_LIBVIEW_SELECT_PART, wxEmptyString,
49  KiScaledBitmap( add_component_xpm, this ),
50  _( "Select symbol to browse" ) );
51 
53  m_mainToolBar->AddTool( ID_LIBVIEW_PREVIOUS, wxEmptyString,
54  KiScaledBitmap( lib_previous_xpm, this ),
55  _( "Display previous symbol" ) );
56 
57  m_mainToolBar->AddTool( ID_LIBVIEW_NEXT, wxEmptyString,
58  KiScaledBitmap( lib_next_xpm, this ),
59  _( "Display next symbol" ) );
60 
61  toolbar->AddSeparator();
62  toolbar->Add( ACTIONS::zoomRedraw );
63  toolbar->Add( ACTIONS::zoomInCenter );
64  toolbar->Add( ACTIONS::zoomOutCenter );
65  toolbar->Add( ACTIONS::zoomFitScreen );
66 
70 
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  wxMenuBar* menuBar = new wxMenuBar();
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 ) {
119  return GetShowElectricalType();
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 
142  SetMenuBar( menuBar );
143  delete oldMenuBar;
144 }
145 
146 
148 {
149  LIB_PART* symbol = GetSelectedSymbol();
150  LIB_ALIAS* alias = GetSelectedAlias();
151 
152  m_mainToolBar->Toggle( EE_ACTIONS::showDatasheet, alias && !alias->GetDocFileName().IsEmpty() );
154  m_convert == LIB_FIELD::LIB_CONVERT::BASE );
156  m_convert == LIB_FIELD::LIB_CONVERT::DEMORGAN );
157  m_mainToolBar->Refresh();
158 }
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:143
LIB_PART * GetSelectedSymbol() const
Class ACTION_TOOLBAR.
Part library alias object definition.
static TOOL_ACTION zoomInCenter
Definition: actions.h:89
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
static const bool TOGGLE
virtual bool IsGridVisible() const
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:92
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
ACTION_TOOLBAR * m_mainToolBar
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, EDA_BASE_FRAME *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
static TOOL_ACTION showDeMorganAlternate
Definition: ee_actions.h:129
static TOOL_ACTION zoomOutCenter
Definition: actions.h:90
const wxString & GetDocFileName() const
This file contains miscellaneous commonly used macros and functions.
Class LIB_CONTROL.
Definition: lib_control.h:39
void ReCreateMenuBar() override
Recreates the menu bar.
static TOOL_ACTION toggleGrid
Definition: actions.h:131
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
Define a library symbol object.
void ReCreateHToolbar() override
static TOOL_ACTION addSymbolToSchematic
Definition: ee_actions.h:162
#define _(s)
void Resolve()
Function Resolve()
static TOOL_ACTION showDeMorganStandard
Definition: ee_actions.h:128
static TOOL_ACTION showElectricalTypes
Definition: ee_actions.h:190
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()
LIB_ALIAS * GetSelectedAlias() const
static TOOL_ACTION zoomRedraw
Definition: actions.h:86
void Toggle(const TOOL_ACTION &aAction, bool aState)
Applies the default toggle action.
void KiScaledSeparator(wxAuiToolBar *aToolbar, EDA_BASE_FRAME *aWindow)
Add a separator to the given toolbar scaled the same way as KiScaledBitmap.
Definition: bitmap.cpp:167
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
static TOOL_ACTION gridProperties
Definition: actions.h:132
wxChoice * m_unitChoice
void ReCreateVToolbar() override
TOOL_MANAGER * m_toolManager
Definition for part library class.
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
bool GetShowElectricalType()
Allow some frames to show/hide pin electrical type names.