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-2017 KiCad Developers, see change_log.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
32 #include <dialog_helpers.h>
33 #include <macros.h>
34 #include <menus_helpers.h>
35 
36 #include "class_library.h"
37 #include "eeschema_id.h"
38 #include "general.h"
39 #include "help_common_strings.h"
40 #include "hotkeys.h"
41 #include "viewlib_frame.h"
42 #include <symbol_lib_table.h>
43 
44 
46 {
47  wxString msg;
48  LIB_PART* part = NULL;
49 
50  if( m_mainToolBar == NULL )
51  {
52  m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
53  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
54 
55  m_mainToolBar->AddTool( ID_LIBVIEW_SELECT_PART, wxEmptyString,
56  KiBitmap( add_component_xpm ),
57  _( "Select component to browse" ) );
58 
59  m_mainToolBar->AddSeparator();
60  m_mainToolBar->AddTool( ID_LIBVIEW_PREVIOUS, wxEmptyString,
61  KiBitmap( lib_previous_xpm ),
62  _( "Display previous component" ) );
63 
64  m_mainToolBar->AddTool( ID_LIBVIEW_NEXT, wxEmptyString,
65  KiBitmap( lib_next_xpm ),
66  _( "Display next component" ) );
67 
68  m_mainToolBar->AddSeparator();
69  msg = AddHotkeyName( _( "Zoom in" ), g_Viewlib_Hokeys_Descr,
71  m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString,
72  KiBitmap( zoom_in_xpm ), msg );
73 
74  msg = AddHotkeyName( _( "Zoom out" ), g_Viewlib_Hokeys_Descr,
76  m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString,
77  KiBitmap( zoom_out_xpm ), msg );
78 
79  msg = AddHotkeyName( _( "Redraw view" ), g_Viewlib_Hokeys_Descr,
81  m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString,
82  KiBitmap( zoom_redraw_xpm ), msg );
83 
84  msg = AddHotkeyName( _( "Zoom auto" ), g_Viewlib_Hokeys_Descr,
86  m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
87  KiBitmap( zoom_fit_in_page_xpm ), msg );
88 
89  m_mainToolBar->AddSeparator();
90  m_mainToolBar->AddTool( ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT, wxEmptyString,
91  KiBitmap( morgan1_xpm ),
92  _( "Show as \"De Morgan\" normal part" ),
93  wxITEM_CHECK );
94 
95  m_mainToolBar->AddTool( ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, wxEmptyString,
96  KiBitmap( morgan2_xpm ),
97  _( "Show as \"De Morgan\" convert part" ),
98  wxITEM_CHECK );
99 
100  m_mainToolBar->AddSeparator();
101 
103  wxEmptyString, wxDefaultPosition,
104  wxSize( 150, -1 ), 0, NULL, wxCB_READONLY );
105  m_mainToolBar->AddControl( m_selpartBox );
106 
107  m_mainToolBar->AddSeparator();
108  m_mainToolBar->AddTool( ID_LIBVIEW_VIEWDOC, wxEmptyString,
109  KiBitmap( datasheet_xpm ),
110  _( "View component documents" ) );
111  m_mainToolBar->EnableTool( ID_LIBVIEW_VIEWDOC, false );
112 
113  if( IsModal() )
114  {
115  m_mainToolBar->AddSeparator();
117  wxEmptyString, KiBitmap( export_xpm ),
118  _( "Insert component in schematic" ) );
119  }
120 
121  // after adding the buttons to the toolbar, must call Realize() to
122  // reflect the changes
123  m_mainToolBar->Realize();
124  }
125 
126  if( m_libraryName.size() && m_entryName.size() )
127  {
128  if( Prj().SchSymbolLibTable()->HasLibrary( m_libraryName ) )
129  {
131  }
132  }
133 
137  int parts_count = 1;
138 
139  if( part )
140  parts_count = std::max( part->GetUnitCount(), 1 );
141 
142  m_selpartBox->Clear();
143 
144  for( int ii = 0; ii < parts_count; ii++ )
145  {
146  msg.Printf( _( "Unit %c" ), 'A' + ii );
147  m_selpartBox->Append( msg );
148  }
149 
150  m_selpartBox->SetSelection( m_unit > 0 ? m_unit - 1 : 0 );
151  m_selpartBox->Enable( parts_count > 1 );
152 
153  m_mainToolBar->Refresh();
154 }
155 
156 
158 {
159 }
160 
161 
162 // Virtual function
164 {
165  // Create and try to get the current menubar
166  wxMenuBar* menuBar = GetMenuBar();
167 
168  if( !menuBar )
169  menuBar = new wxMenuBar();
170 
171  // Delete all existing menus so they can be rebuilt.
172  // This allows language changes of the menu text on the fly.
173  menuBar->Freeze();
174 
175  while( menuBar->GetMenuCount() )
176  delete menuBar->Remove( 0 );
177 
178  // Recreate all menus:
179  wxString text;
180 
181  // Menu File:
182  wxMenu* fileMenu = new wxMenu;
183 
184  AddMenuItem( fileMenu, wxID_EXIT,
185  _( "Cl&ose" ),
186  _( "Close schematic component viewer" ),
187  KiBitmap( exit_xpm ) );
188 
189  // View menu
190  wxMenu* viewMenu = new wxMenu;
191 
192  text = AddHotkeyName( _( "Zoom &In" ), g_Viewlib_Hokeys_Descr,
194  AddMenuItem( viewMenu, ID_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
195 
196  text = AddHotkeyName( _( "Zoom &Out" ), g_Viewlib_Hokeys_Descr,
198  AddMenuItem( viewMenu, ID_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
199 
200  text = AddHotkeyName( _( "&Fit on Screen" ), g_Viewlib_Hokeys_Descr,
201  HK_ZOOM_AUTO );
202  AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, HELP_ZOOM_FIT,
203  KiBitmap( zoom_fit_in_page_xpm ) );
204 
205  text = AddHotkeyName( _( "&Redraw" ), g_Viewlib_Hokeys_Descr, HK_ZOOM_REDRAW );
206  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text,
207  HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
208 
209  viewMenu->AppendSeparator();
210  AddMenuItem( viewMenu, ID_LIBVIEW_SHOW_ELECTRICAL_TYPE, _( "&Show Pin Electrical Type" ),
211  wxEmptyString, KiBitmap( pin_show_etype_xpm ), wxITEM_CHECK );
212 
213  // Menu Help:
214  wxMenu* helpMenu = new wxMenu;
215 
216  // Contents
217  AddMenuItem( helpMenu, wxID_HELP,
218  _( "Eeschema &Manual" ),
219  _( "Open Eeschema manual" ),
220  KiBitmap( online_help_xpm ) );
221 
222  AddMenuItem( helpMenu, wxID_INDEX,
223  _( "&Getting Started in KiCad" ),
224  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
225  KiBitmap( help_xpm ) );
226 
227  helpMenu->AppendSeparator();
229  _( "Get &Involved" ),
230  _( "Contribute to KiCad (opens a web browser)" ),
231  KiBitmap( info_xpm ) );
232 
233  helpMenu->AppendSeparator();
234  AddMenuItem( helpMenu, wxID_ABOUT,
235  _( "&About Eeschema" ),
236  _( "About Eeschema schematic designer" ),
237  KiBitmap( info_xpm ) );
238 
239  // Append menus to the menubar
240  menuBar->Append( fileMenu, _( "&File" ) );
241 
242  menuBar->Append( viewMenu, _( "&View" ) );
243  menuBar->Append( helpMenu, _( "&Help" ) );
244 
245  menuBar->Thaw();
246 
247  // Associate the menu bar with the frame, if no previous menubar
248  if( GetMenuBar() == NULL )
249  SetMenuBar( menuBar );
250  else
251  menuBar->Refresh();
252 }
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:55
#define HELP_ZOOM_FIT
Definition: id.h:232
LIB_PART * GetLibPart(const LIB_ID &aLibId, bool aUseCacheLib=false, bool aShowErrorMsg=false)
static wxString m_libraryName
Class LIB_ID.
Definition: lib_id.h:56
#define HELP_ZOOM_OUT
This file contains miscellaneous commonly used macros and functions.
#define HELP_ZOOM_REDRAW
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.
strings common to toolbars and menubar
Class LIB_PART defines a library part object.
Helper dialog and control classes.
void ReCreateHToolbar() override
bool IsModal()
Definition: kiway_player.h:259
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:145
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
Definition: wxstruct.h:168
void ReCreateVToolbar() override
Definition for part library class.
wxComboBox * m_selpartBox