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-2016 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 2004-2016 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 
43 
45 {
46  wxString msg;
47  LIB_PART* part = NULL;
48 
49  if( m_mainToolBar == NULL )
50  {
51  m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
52  wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_HORZ_LAYOUT );
53 
54  m_mainToolBar->AddTool( ID_LIBVIEW_SELECT_PART, wxEmptyString,
55  KiBitmap( add_component_xpm ),
56  _( "Select component to browse" ) );
57 
58  m_mainToolBar->AddSeparator();
59  m_mainToolBar->AddTool( ID_LIBVIEW_PREVIOUS, wxEmptyString,
60  KiBitmap( lib_previous_xpm ),
61  _( "Display previous component" ) );
62 
63  m_mainToolBar->AddTool( ID_LIBVIEW_NEXT, wxEmptyString,
64  KiBitmap( lib_next_xpm ),
65  _( "Display next component" ) );
66 
67  m_mainToolBar->AddSeparator();
68  msg = AddHotkeyName( _( "Zoom in" ), g_Viewlib_Hokeys_Descr,
70  m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString,
71  KiBitmap( zoom_in_xpm ), msg );
72 
73  msg = AddHotkeyName( _( "Zoom out" ), g_Viewlib_Hokeys_Descr,
75  m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString,
76  KiBitmap( zoom_out_xpm ), msg );
77 
78  msg = AddHotkeyName( _( "Redraw view" ), g_Viewlib_Hokeys_Descr,
80  m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString,
81  KiBitmap( zoom_redraw_xpm ), msg );
82 
83  msg = AddHotkeyName( _( "Zoom auto" ), g_Viewlib_Hokeys_Descr,
85  m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
86  KiBitmap( zoom_fit_in_page_xpm ), msg );
87 
88  m_mainToolBar->AddSeparator();
89  m_mainToolBar->AddTool( ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT, wxEmptyString,
90  KiBitmap( morgan1_xpm ),
91  _( "Show as \"De Morgan\" normal part" ),
92  wxITEM_CHECK );
93 
94  m_mainToolBar->AddTool( ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, wxEmptyString,
95  KiBitmap( morgan2_xpm ),
96  _( "Show as \"De Morgan\" convert part" ),
97  wxITEM_CHECK );
98 
99  m_mainToolBar->AddSeparator();
100 
102  wxEmptyString, wxDefaultPosition,
103  wxSize( 150, -1 ), 0, NULL, wxCB_READONLY );
104  m_mainToolBar->AddControl( m_selpartBox );
105 
106  m_mainToolBar->AddSeparator();
107  m_mainToolBar->AddTool( ID_LIBVIEW_VIEWDOC, wxEmptyString,
108  KiBitmap( datasheet_xpm ),
109  _( "View component documents" ) );
110  m_mainToolBar->EnableTool( ID_LIBVIEW_VIEWDOC, false );
111 
112  if( IsModal() )
113  {
114  m_mainToolBar->AddSeparator();
116  wxEmptyString, KiBitmap( export_xpm ),
117  _( "Insert component in schematic" ) );
118  }
119 
120  // after adding the buttons to the toolbar, must call Realize() to
121  // reflect the changes
122  m_mainToolBar->Realize();
123  }
124 
125  if( m_libraryName.size() && m_entryName.size() )
126  {
127  if( PART_LIB* lib = Prj().SchLibs()->FindLibrary( m_libraryName ) )
128  {
129  part = lib->FindPart( m_entryName );
130  }
131  }
132 
136  int parts_count = 1;
137 
138  if( part )
139  parts_count = std::max( part->GetUnitCount(), 1 );
140 
141  m_selpartBox->Clear();
142 
143  for( int ii = 0; ii < parts_count; ii++ )
144  {
145  msg.Printf( _( "Unit %c" ), 'A' + ii );
146  m_selpartBox->Append( msg );
147  }
148 
149  m_selpartBox->SetSelection( m_unit > 0 ? m_unit - 1 : 0 );
150  m_selpartBox->Enable( parts_count > 1 );
151 
152  m_mainToolBar->Refresh();
153 }
154 
155 
157 {
158 }
159 
160 
161 // Virtual function
163 {
164  // Create and try to get the current menubar
165  wxMenuBar* menuBar = GetMenuBar();
166 
167  if( !menuBar )
168  menuBar = new wxMenuBar();
169 
170  // Delete all existing menus so they can be rebuilt.
171  // This allows language changes of the menu text on the fly.
172  menuBar->Freeze();
173 
174  while( menuBar->GetMenuCount() )
175  delete menuBar->Remove( 0 );
176 
177  // Recreate all menus:
178  wxString text;
179 
180  // Menu File:
181  wxMenu* fileMenu = new wxMenu;
182 
183  AddMenuItem( fileMenu, wxID_EXIT,
184  _( "Cl&ose" ),
185  _( "Close schematic component viewer" ),
186  KiBitmap( exit_xpm ) );
187 
188  // View menu
189  wxMenu* viewMenu = new wxMenu;
190 
191  text = AddHotkeyName( _( "Zoom &In" ), g_Viewlib_Hokeys_Descr,
193  AddMenuItem( viewMenu, ID_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) );
194 
195  text = AddHotkeyName( _( "Zoom &Out" ), g_Viewlib_Hokeys_Descr,
197  AddMenuItem( viewMenu, ID_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) );
198 
199  text = AddHotkeyName( _( "&Fit on Screen" ), g_Viewlib_Hokeys_Descr,
200  HK_ZOOM_AUTO );
201  AddMenuItem( viewMenu, ID_ZOOM_PAGE, text, HELP_ZOOM_FIT,
202  KiBitmap( zoom_fit_in_page_xpm ) );
203 
204  text = AddHotkeyName( _( "&Redraw" ), g_Viewlib_Hokeys_Descr, HK_ZOOM_REDRAW );
205  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, text,
206  HELP_ZOOM_REDRAW, KiBitmap( zoom_redraw_xpm ) );
207 
208  viewMenu->AppendSeparator();
209  AddMenuItem( viewMenu, ID_LIBVIEW_SHOW_ELECTRICAL_TYPE, _( "&Show Pin Electrical Type" ),
210  wxEmptyString, KiBitmap( pin_show_etype_xpm ), wxITEM_CHECK );
211 
212  // Menu Help:
213  wxMenu* helpMenu = new wxMenu;
214 
215  // Contents
216  AddMenuItem( helpMenu, wxID_HELP,
217  _( "Eeschema &Manual" ),
218  _( "Open Eeschema manual" ),
219  KiBitmap( online_help_xpm ) );
220 
221  AddMenuItem( helpMenu, wxID_INDEX,
222  _( "&Getting Started in KiCad" ),
223  _( "Open the \"Getting Started in KiCad\" guide for beginners" ),
224  KiBitmap( help_xpm ) );
225 
226  helpMenu->AppendSeparator();
228  _( "Get &Involved" ),
229  _( "Contribute to KiCad (opens a web browser)" ),
230  KiBitmap( info_xpm ) );
231 
232  helpMenu->AppendSeparator();
233  AddMenuItem( helpMenu, wxID_ABOUT,
234  _( "&About Eeschema" ),
235  _( "About Eeschema schematic designer" ),
236  KiBitmap( info_xpm ) );
237 
238  // Append menus to the menubar
239  menuBar->Append( fileMenu, _( "&File" ) );
240 
241  menuBar->Append( viewMenu, _( "&View" ) );
242  menuBar->Append( helpMenu, _( "&Help" ) );
243 
244  menuBar->Thaw();
245 
246  // Associate the menu bar with the frame, if no previous menubar
247  if( GetMenuBar() == NULL )
248  SetMenuBar( menuBar );
249  else
250  menuBar->Refresh();
251 }
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
static wxString m_libraryName
#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:216
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:136
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[]
void ReCreateVToolbar() override
Definition for part library class.
Class PART_LIB is used to load, save, search, and otherwise manipulate part library files...
wxComboBox * m_selpartBox