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 auto" ), 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  // Create and try to get the current menubar
162  wxMenuBar* menuBar = GetMenuBar();
163 
164  if( !menuBar )
165  menuBar = new wxMenuBar();
166 
167  // Delete all existing menus so they can be rebuilt.
168  // This allows language changes of the menu text on the fly.
169  menuBar->Freeze();
170 
171  while( menuBar->GetMenuCount() )
172  delete menuBar->Remove( 0 );
173 
174  // Recreate all menus:
175  wxString text;
176 
177  // Menu File:
178  wxMenu* fileMenu = new wxMenu;
179 
180  AddMenuItem( fileMenu, wxID_EXIT,
181  _( "Cl&ose" ),
182  _( "Close schematic symbol viewer" ),
183  KiBitmap( exit_xpm ) );
184 
185  // View menu
186  wxMenu* viewMenu = new wxMenu;
187 
188  text = AddHotkeyName( _( "Zoom &In" ), g_Viewlib_Hokeys_Descr,
190  AddMenuItem( viewMenu, ID_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
191 
192  text = AddHotkeyName( _( "Zoom &Out" ), g_Viewlib_Hokeys_Descr,
194  AddMenuItem( viewMenu, ID_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
195 
196  text = AddHotkeyName( _( "&Fit on Screen" ), g_Viewlib_Hokeys_Descr,
197  HK_ZOOM_AUTO );
198  AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, HELP_ZOOM_FIT,
199  KiBitmap( zoom_fit_in_page_xpm ) );
200 
201  text = AddHotkeyName( _( "&Redraw" ), g_Viewlib_Hokeys_Descr, HK_ZOOM_REDRAW );
202  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text,
203  HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
204 
205  viewMenu->AppendSeparator();
206  AddMenuItem( viewMenu, ID_LIBVIEW_SHOW_ELECTRICAL_TYPE, _( "&Show Pin Electrical Type" ),
207  wxEmptyString, KiBitmap( pin_show_etype_xpm ), wxITEM_CHECK );
208 
209  // Menu Help:
210  wxMenu* helpMenu = new wxMenu;
211 
212  // Contents
213  AddMenuItem( helpMenu, wxID_HELP,
214  _( "Eeschema &Manual" ),
215  _( "Open Eeschema manual" ),
216  KiBitmap( online_help_xpm ) );
217 
218  AddMenuItem( helpMenu, wxID_INDEX,
219  _( "&Getting Started in KiCad" ),
220  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
221  KiBitmap( help_xpm ) );
222 
223  helpMenu->AppendSeparator();
225  _( "Get &Involved" ),
226  _( "Contribute to KiCad (opens a web browser)" ),
227  KiBitmap( info_xpm ) );
228 
229  helpMenu->AppendSeparator();
230  AddMenuItem( helpMenu, wxID_ABOUT,
231  _( "&About Eeschema" ),
232  _( "About Eeschema schematic designer" ),
233  KiBitmap( info_xpm ) );
234 
235  // Append menus to the menubar
236  menuBar->Append( fileMenu, _( "&File" ) );
237 
238  menuBar->Append( viewMenu, _( "&View" ) );
239  menuBar->Append( helpMenu, _( "&Help" ) );
240 
241  menuBar->Thaw();
242 
243  // Associate the menu bar with the frame, if no previous menubar
244  if( GetMenuBar() == NULL )
245  SetMenuBar( menuBar );
246  else
247  menuBar->Refresh();
248 }
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
#define HELP_ZOOM_FIT
Definition: id.h:241
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:229
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