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  *
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 
22 
23 #include <dialog_helpers.h>
24 #include <macros.h>
25 #include <menus_helpers.h>
26 
27 #include "class_library.h"
28 #include "eeschema_id.h"
29 #include "general.h"
30 #include "help_common_strings.h"
31 #include "ee_hotkeys.h"
32 #include "viewlib_frame.h"
33 #include <symbol_lib_table.h>
34 #include <tool/conditional_menu.h>
35 #include <tool/tool_manager.h>
36 #include <tools/ee_actions.h>
37 #include <tools/lib_control.h>
38 
40 {
41  if( m_mainToolBar )
42  m_mainToolBar->Clear();
43  else
45  wxDefaultPosition, wxDefaultSize,
46  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
47 
48  ACTION_TOOLBAR* toolbar = static_cast<ACTION_TOOLBAR*>( m_mainToolBar );
49  wxString msg;
50 
51  m_mainToolBar->AddTool( ID_LIBVIEW_SELECT_PART, wxEmptyString,
52  KiScaledBitmap( add_component_xpm, this ),
53  _( "Select symbol to browse" ) );
54 
56  m_mainToolBar->AddTool( ID_LIBVIEW_PREVIOUS, wxEmptyString,
57  KiScaledBitmap( lib_previous_xpm, this ),
58  _( "Display previous symbol" ) );
59 
60  m_mainToolBar->AddTool( ID_LIBVIEW_NEXT, wxEmptyString,
61  KiScaledBitmap( lib_next_xpm, this ),
62  _( "Display next symbol" ) );
63 
64  toolbar->AddSeparator();
65  toolbar->Add( ACTIONS::zoomRedraw );
66  toolbar->Add( ACTIONS::zoomInCenter );
67  toolbar->Add( ACTIONS::zoomOutCenter );
68  toolbar->Add( ACTIONS::zoomFitScreen );
69 
71  m_mainToolBar->AddTool( ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT, wxEmptyString,
72  KiScaledBitmap( morgan1_xpm, this ),
73  _( "Show as \"De Morgan\" normal symbol" ),
74  wxITEM_CHECK );
75 
76  m_mainToolBar->AddTool( ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, wxEmptyString,
77  KiScaledBitmap( morgan2_xpm, this ),
78  _( "Show as \"De Morgan\" convert symbol" ),
79  wxITEM_CHECK );
80 
82 
84  wxDefaultPosition, wxSize( 150, -1 ) );
85  m_mainToolBar->AddControl( m_unitChoice );
86 
88  m_mainToolBar->AddTool( ID_LIBVIEW_VIEWDOC, wxEmptyString,
89  KiScaledBitmap( datasheet_xpm, this ),
90  _( "View symbol documents" ) );
91 
93  m_mainToolBar->AddTool( ID_ADD_PART_TO_SCHEMATIC, wxEmptyString,
94  KiScaledBitmap( export_xpm, this ),
95  _( "Add symbol to schematic" ) );
96 
97  // after adding the buttons to the toolbar, must call Realize() to
98  // reflect the changes
99  m_mainToolBar->Realize();
100 
101  m_mainToolBar->Refresh();
102 }
103 
104 
106 {
107 }
108 
109 
110 // Virtual function
112 {
113  LIB_CONTROL* libControl = m_toolManager->GetTool<LIB_CONTROL>();
114  // wxWidgets handles the Mac Application menu behind the scenes, but that means
115  // we always have to start from scratch with a new wxMenuBar.
116  wxMenuBar* oldMenuBar = GetMenuBar();
117  wxMenuBar* menuBar = new wxMenuBar();
118  wxString text;
119 
120  // Recreate all menus:
121 
122  // Menu File:
123  wxMenu* fileMenu = new wxMenu;
124 
125  AddMenuItem( fileMenu, wxID_EXIT,
126  _( "Cl&ose" ),
127  _( "Close schematic symbol viewer" ),
128  KiBitmap( exit_xpm ) );
129 
130  // View menu
131  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, libControl );
132 
133  auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
134  return IsGridVisible();
135  };
136 
141 
142  viewMenu->AddSeparator();
143  viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
145 
146  viewMenu->AddSeparator();
148 
149  // Menu Help:
150  wxMenu* helpMenu = new wxMenu;
151 
152  // Contents
153  AddMenuItem( helpMenu, wxID_HELP,
154  _( "Eeschema &Manual" ),
155  _( "Open Eeschema manual" ),
156  KiBitmap( online_help_xpm ) );
157 
158  AddMenuItem( helpMenu, wxID_INDEX,
159  _( "&Getting Started in KiCad" ),
160  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
161  KiBitmap( help_xpm ) );
162 
163  helpMenu->AppendSeparator();
165  _( "Get &Involved" ),
166  _( "Contribute to KiCad (opens a web browser)" ),
167  KiBitmap( info_xpm ) );
168 
169  helpMenu->AppendSeparator();
170  AddMenuItem( helpMenu, wxID_ABOUT,
171  _( "&About Eeschema" ),
172  _( "About Eeschema schematic designer" ),
173  KiBitmap( info_xpm ) );
174  // Append menus to the menubar
175  menuBar->Append( fileMenu, _( "&File" ) );
176 
177  menuBar->Append( viewMenu, _( "&View" ) );
178  menuBar->Append( helpMenu, _( "&Help" ) );
179 
180  SetMenuBar( menuBar );
181  delete oldMenuBar;
182 }
TOOL_MANAGER * m_toolManager
Definition: draw_frame.h:130
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
Class ACTION_TOOLBAR.
static TOOL_ACTION zoomInCenter
Definition: actions.h:60
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:251
void AddSeparator(const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddSeparator()
virtual bool IsGridVisible() const
Definition: draw_frame.h:533
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:63
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
ACTION_TOOLBAR * m_mainToolBar
Definition: draw_frame.h:156
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 zoomOutCenter
Definition: actions.h:61
This file contains miscellaneous commonly used macros and functions.
Class LIB_CONTROL.
Definition: lib_control.h:38
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
void ReCreateMenuBar() override
Recreates the menu bar.
static TOOL_ACTION toggleGrid
Definition: actions.h:98
strings common to toolbars and menubar
Helper dialog and control classes.
void ReCreateHToolbar() override
static TOOL_ACTION showElectricalTypes
Definition: ee_actions.h:173
static TOOL_ACTION zoomRedraw
Definition: actions.h:57
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:99
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()