KiCad PCB EDA Suite
toolbars_libedit.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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
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
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 
26 #include <fctsys.h>
27 #include <eeschema_id.h>
28 #include <general.h>
29 #include <lib_edit_frame.h>
30 #include <dialog_helpers.h>
31 #include <bitmaps.h>
32 #include <lib_manager.h>
33 #include <class_library.h>
34 #include <tool/action_toolbar.h>
35 #include <tools/ee_actions.h>
36 
37 #ifdef __UNIX__
38 #define LISTBOX_WIDTH 140
39 #else
40 #define LISTBOX_WIDTH 120
41 #endif
42 
43 
45 {
46  if( m_drawToolBar )
47  m_drawToolBar->Clear();
48  else
49  m_drawToolBar = new ACTION_TOOLBAR( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
50  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
51 
52  // Set up toolbar
54 
63 
64  m_drawToolBar->AddTool( ID_LIBEDIT_IMPORT_BODY_BUTT, wxEmptyString,
65  KiScaledBitmap( import_xpm, this ),
66  _( "Import existing drawings" ), wxITEM_CHECK );
67 
68  m_drawToolBar->AddTool( ID_LIBEDIT_EXPORT_BODY_BUTT, wxEmptyString,
69  KiScaledBitmap( export_xpm, this ),
70  _( "Export current drawing" ), wxITEM_CHECK );
71 
73 
74  m_drawToolBar->Realize();
75 }
76 
77 
79 {
80  if( m_mainToolBar )
81  m_mainToolBar->Clear();
82  else
83  m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
84  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
85 
86  // Set up toolbar
89 
90  m_mainToolBar->AddSeparator();
93 
94  m_mainToolBar->AddSeparator();
100 
101  m_mainToolBar->AddSeparator();
104 
108 
112 
114  m_unitSelectBox = new wxComboBox( m_mainToolBar, ID_LIBEDIT_SELECT_PART_NUMBER, wxEmptyString,
115  wxDefaultPosition, wxSize( LISTBOX_WIDTH, -1 ), 0, nullptr,
116  wxCB_READONLY );
117  m_mainToolBar->AddControl( m_unitSelectBox );
118 
121 
124 
125  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
126  m_mainToolBar->Realize();
127 }
128 
129 
131 {
132  if( m_optionsToolBar )
133  m_optionsToolBar->Clear();
134  else
136  wxDefaultPosition, wxDefaultSize,
137  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
138 
139  ACTION_TOOLBAR* optToolbar = static_cast<ACTION_TOOLBAR*>( m_optionsToolBar );
140 
147 
148  m_optionsToolBar->Realize();
149 }
150 
151 
153 {
155 
156  LIB_ID libId = getTargetLibId();
157  const wxString& libName = libId.GetLibNickname();
158  const wxString& partName = libId.GetLibItemName();
159  bool modified = m_libMgr->IsLibraryModified( libName );
160 
161  if( !partName.IsEmpty() && m_libMgr->IsPartModified( partName, libName ) )
162  modified = true;
163 
164  m_mainToolBar->Toggle( ACTIONS::saveAll, modified );
165  m_mainToolBar->Toggle( ACTIONS::undo, GetScreen() && GetScreen()->GetUndoCommandCount() > 0 );
166  m_mainToolBar->Toggle( ACTIONS::redo, GetScreen() && GetScreen()->GetRedoCommandCount() > 0 );
170  GetShowDeMorgan(),
171  m_convert == LIB_ITEM::LIB_CONVERT::BASE );
173  GetShowDeMorgan(),
174  m_convert == LIB_ITEM::LIB_CONVERT::DEMORGAN );
176  GetCurPart() && GetCurPart()->IsMulti() && !GetCurPart()->UnitsLocked(),
177  m_SyncPinEdit );
178  m_mainToolBar->Refresh();
179 
186  m_optionsToolBar->Refresh();
187 
188 #define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) )
189 
198  m_drawToolBar->Refresh();
199 }
static TOOL_ACTION pinTable
Definition: ee_actions.h:150
LIB_PART * GetCurPart() const
Return the current part being edited or NULL if none selected.
static TOOL_ACTION showDatasheet
Inspection and Editing.
Definition: ee_actions.h:143
static TOOL_ACTION placeSymbolText
Definition: ee_actions.h:105
Class ACTION_TOOLBAR.
static TOOL_ACTION drawSymbolLines
Definition: ee_actions.h:109
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
static TOOL_ACTION zoomInCenter
Definition: actions.h:89
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
static TOOL_ACTION runERC
Definition: ee_actions.h:144
ACTION_TOOLBAR * m_optionsToolBar
static TOOL_ACTION zoomTool
Definition: actions.h:94
static const bool TOGGLE
virtual bool IsGridVisible() const
LIB_MANAGER * m_libMgr
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
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:92
#define TOGGLE_TOOL(toolbar, tool)
static TOOL_ACTION showComponentTree
Definition: ee_actions.h:191
ACTION_TOOLBAR * m_mainToolBar
#define LISTBOX_WIDTH
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)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
static TOOL_ACTION showDeMorganAlternate
Definition: ee_actions.h:129
static TOOL_ACTION imperialUnits
Definition: actions.h:135
static TOOL_ACTION zoomOutCenter
Definition: actions.h:90
static TOOL_ACTION drawSymbolRectangle
Definition: ee_actions.h:106
static TOOL_ACTION placeSymbolPin
Definition: ee_actions.h:104
void SyncToolbars() override
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
bool GetShowDeMorgan() const
static TOOL_ACTION toggleGrid
Definition: actions.h:131
bool IsPartModified(const wxString &aAlias, const wxString &aLibrary) const
Returns true if part has unsaved modifications.
Definition: common.h:155
static TOOL_ACTION symbolProperties
Definition: ee_actions.h:149
static TOOL_ACTION drawSymbolCircle
Definition: ee_actions.h:107
Helper dialog and control classes.
void ReCreateOptToolbar() override
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
static TOOL_ACTION addSymbolToSchematic
Definition: ee_actions.h:162
#define _(s)
static TOOL_ACTION showDeMorganStandard
Definition: ee_actions.h:128
static TOOL_ACTION showElectricalTypes
Definition: ee_actions.h:190
static TOOL_ACTION newSymbol
Definition: ee_actions.h:165
static TOOL_ACTION metricUnits
Definition: actions.h:136
static TOOL_ACTION redo
Definition: actions.h:68
void ReCreateHToolbar() override
bool m_SyncPinEdit
Set to true to synchronize pins at the same position when editing symbols with multiple units or mult...
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION zoomRedraw
Definition: actions.h:86
LIB_ID getTargetLibId() const
Returns either the part selected in the component tree, if context menu is active or the currently mo...
void Toggle(const TOOL_ACTION &aAction, bool aState)
Applies the default toggle action.
static TOOL_ACTION drawSymbolArc
Definition: ee_actions.h:108
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
bool IsLibraryModified(const wxString &aLibrary) const
Returns true if library has unsaved modifications.
static TOOL_ACTION deleteTool
Definition: actions.h:74
static TOOL_ACTION toggleSyncedPinsMode
Definition: ee_actions.h:184
static TOOL_ACTION undo
Definition: actions.h:67
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:97
static TOOL_ACTION saveAll
Definition: actions.h:57
Definition for part library class.
wxComboBox * m_unitSelectBox
bool IsCurrentTool(const TOOL_ACTION &aAction) const
bool m_fullscreenCursor
Fullscreen crosshair or small cross
static TOOL_ACTION placeSymbolAnchor
Definition: ee_actions.h:110
static TOOL_ACTION selectionTool
Definition: actions.h:142
bool GetShowElectricalType()
Allow some frames to show/hide pin electrical type names.
ACTION_TOOLBAR * m_drawToolBar
void ReCreateVToolbar() override