KiCad PCB EDA Suite
tool_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-2018 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 
28 #include <dialog_helpers.h>
29 #include <macros.h>
30 #include <menus_helpers.h>
31 
32 #include "class_library.h"
33 #include "eeschema_id.h"
34 #include "general.h"
35 #include "help_common_strings.h"
36 #include "hotkeys.h"
37 #include "viewlib_frame.h"
38 #include <symbol_lib_table.h>
39 
40 
42 {
43  wxString msg;
44  LIB_PART* part = NULL;
45 
46  if( m_mainToolBar )
47  m_mainToolBar->Clear();
48  else
49  m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
50  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
51 
52  m_mainToolBar->AddTool( ID_LIBVIEW_SELECT_PART, wxEmptyString,
53  KiScaledBitmap( add_component_xpm, this ),
54  _( "Select symbol to browse" ) );
55 
56  m_mainToolBar->AddSeparator();
57  m_mainToolBar->AddTool( ID_LIBVIEW_PREVIOUS, wxEmptyString,
58  KiScaledBitmap( lib_previous_xpm, this ),
59  _( "Display previous symbol" ) );
60 
61  m_mainToolBar->AddTool( ID_LIBVIEW_NEXT, wxEmptyString,
62  KiScaledBitmap( lib_next_xpm, this ),
63  _( "Display next symbol" ) );
64 
65  m_mainToolBar->AddSeparator();
66  msg = AddHotkeyName( _( "Zoom in" ), g_Viewlib_Hokeys_Descr,
68  m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString,
69  KiScaledBitmap( zoom_in_xpm, this ), msg );
70 
71  msg = AddHotkeyName( _( "Zoom out" ), g_Viewlib_Hokeys_Descr,
73  m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString,
74  KiScaledBitmap( zoom_out_xpm, this ), msg );
75 
76  msg = AddHotkeyName( _( "Redraw view" ), g_Viewlib_Hokeys_Descr,
78  m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString,
79  KiScaledBitmap( zoom_redraw_xpm, this ), msg );
80 
81  msg = AddHotkeyName( _( "Zoom to fit symbol" ), g_Viewlib_Hokeys_Descr,
83  m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
84  KiScaledBitmap( zoom_fit_in_page_xpm, this ), msg );
85 
86  m_mainToolBar->AddSeparator();
87  m_mainToolBar->AddTool( ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT, wxEmptyString,
88  KiScaledBitmap( morgan1_xpm, this ),
89  _( "Show as \"De Morgan\" normal symbol" ),
90  wxITEM_CHECK );
91 
92  m_mainToolBar->AddTool( ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, wxEmptyString,
93  KiScaledBitmap( morgan2_xpm, this ),
94  _( "Show as \"De Morgan\" convert symbol" ),
95  wxITEM_CHECK );
96 
97  m_mainToolBar->AddSeparator();
98 
100  wxEmptyString, wxDefaultPosition,
101  wxSize( 150, -1 ), 0, NULL, wxCB_READONLY );
102  m_mainToolBar->AddControl( m_selpartBox );
103 
104  m_mainToolBar->AddSeparator();
105  m_mainToolBar->AddTool( ID_LIBVIEW_VIEWDOC, wxEmptyString,
106  KiScaledBitmap( datasheet_xpm, this ),
107  _( "View symbol documents" ) );
108  m_mainToolBar->EnableTool( ID_LIBVIEW_VIEWDOC, false );
109 
110  if( IsModal() )
111  {
112  m_mainToolBar->AddSeparator();
114  wxEmptyString, KiScaledBitmap( export_xpm, this ),
115  _( "Insert symbol in schematic" ) );
116  }
117 
118  // after adding the buttons to the toolbar, must call Realize() to
119  // reflect the changes
120  m_mainToolBar->Realize();
121 
122  if( m_libraryName.size() && m_entryName.size() )
123  {
124  if( Prj().SchSymbolLibTable()->HasLibrary( m_libraryName ) )
125  {
127  }
128  }
129 
133  int parts_count = 1;
134 
135  if( part )
136  parts_count = std::max( part->GetUnitCount(), 1 );
137 
138  m_selpartBox->Clear();
139 
140  for( int ii = 0; ii < parts_count; ii++ )
141  {
142  msg.Printf( _( "Unit %c" ), 'A' + ii );
143  m_selpartBox->Append( msg );
144  }
145 
146  m_selpartBox->SetSelection( m_unit > 0 ? m_unit - 1 : 0 );
147  m_selpartBox->Enable( parts_count > 1 );
148 
149  m_mainToolBar->Refresh();
150 }
151 
152 
154 {
155 }
156 
157 
158 // Virtual function
160 {
161  // wxWidgets handles the Mac Application menu behind the scenes, but that means
162  // we always have to start from scratch with a new wxMenuBar.
163  wxMenuBar* oldMenuBar = GetMenuBar();
164  wxMenuBar* menuBar = new wxMenuBar();
165  wxString text;
166 
167  // Recreate all menus:
168 
169  // Menu File:
170  wxMenu* fileMenu = new wxMenu;
171 
172  AddMenuItem( fileMenu, wxID_EXIT,
173  _( "Cl&ose" ),
174  _( "Close schematic symbol viewer" ),
175  KiBitmap( exit_xpm ) );
176 
177  // View menu
178  wxMenu* viewMenu = new wxMenu;
179 
180  text = AddHotkeyName( _( "Zoom &In" ), g_Viewlib_Hokeys_Descr,
182  AddMenuItem( viewMenu, ID_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
183 
184  text = AddHotkeyName( _( "Zoom &Out" ), g_Viewlib_Hokeys_Descr,
186  AddMenuItem( viewMenu, ID_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
187 
188  text = AddHotkeyName( _( "&Zoom to Fit" ), g_Viewlib_Hokeys_Descr, HK_ZOOM_AUTO );
189  AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, _( "Zoom to fit symbol" ),
190  KiBitmap( zoom_fit_in_page_xpm ) );
191 
192  text = AddHotkeyName( _( "&Redraw" ), g_Viewlib_Hokeys_Descr, HK_ZOOM_REDRAW );
193  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text,
194  HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
195 
196  viewMenu->AppendSeparator();
197  AddMenuItem( viewMenu, ID_LIBVIEW_SHOW_ELECTRICAL_TYPE, _( "&Show Pin Electrical Type" ),
198  wxEmptyString, KiBitmap( pin_show_etype_xpm ), wxITEM_CHECK );
199 
200  // Menu Help:
201  wxMenu* helpMenu = new wxMenu;
202 
203  // Contents
204  AddMenuItem( helpMenu, wxID_HELP,
205  _( "Eeschema &Manual" ),
206  _( "Open Eeschema manual" ),
207  KiBitmap( online_help_xpm ) );
208 
209  AddMenuItem( helpMenu, wxID_INDEX,
210  _( "&Getting Started in KiCad" ),
211  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
212  KiBitmap( help_xpm ) );
213 
214  helpMenu->AppendSeparator();
216  _( "Get &Involved" ),
217  _( "Contribute to KiCad (opens a web browser)" ),
218  KiBitmap( info_xpm ) );
219 
220  helpMenu->AppendSeparator();
221  AddMenuItem( helpMenu, wxID_ABOUT,
222  _( "&About Eeschema" ),
223  _( "About Eeschema schematic designer" ),
224  KiBitmap( info_xpm ) );
225 
226  // Append menus to the menubar
227  menuBar->Append( fileMenu, _( "&File" ) );
228 
229  menuBar->Append( viewMenu, _( "&View" ) );
230  menuBar->Append( helpMenu, _( "&Help" ) );
231 
232  SetMenuBar( menuBar );
233  delete oldMenuBar;
234 }
static int m_unit
static wxString m_entryName
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:174
Definition: id.h:242
LIB_PART * GetLibPart(const LIB_ID &aLibId, bool aUseCacheLib=false, bool aShowErrorMsg=false)
static wxString m_libraryName
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, EDA_BASE_FRAME *aWindow)
Function KiScaledBitmap Constructs a wxBitmap from a memory record, scaling it if device DPI demands ...
Definition: bitmap.cpp:114
#define HELP_ZOOM_OUT
This file contains miscellaneous commonly used macros and functions.
#define HELP_ZOOM_REDRAW
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.
strings common to toolbars and menubar
Define a library symbol object.
Helper dialog and control classes.
void ReCreateHToolbar() override
bool IsModal()
Definition: kiway_player.h:217
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
int GetUnitCount() const
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
#define max(a, b)
Definition: auxiliary.h:86
#define HELP_ZOOM_IN
struct EDA_HOTKEY_CONFIG g_Viewlib_Hokeys_Descr[]
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
void ReCreateVToolbar() override
Definition for part library class.
wxComboBox * m_selpartBox