KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
toolbars_gerber.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) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
6 * Copyright The 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
22#include <wx/wupdlock.h>
23#include <wx/stattext.h>
24
25#include <gerbview.h>
26#include <gerbview_frame.h>
27#include <bitmaps.h>
28#include <gerbview_id.h>
29#include <gerber_file_image.h>
31#include <string_utils.h>
32#include <tool/actions.h>
33#include <tool/action_toolbar.h>
37#include <toolbars_gerber.h>
38
39
40std::optional<TOOLBAR_CONFIGURATION> GERBVIEW_TOOLBAR_SETTINGS::DefaultToolbarConfig( TOOLBAR_LOC aToolbar )
41{
43
44 // clang-format off
45 switch( aToolbar )
46 {
47 // No right toolbar
48 case TOOLBAR_LOC::RIGHT:
49 return std::nullopt;
50
51 case TOOLBAR_LOC::LEFT:
52 config.AppendAction( ACTIONS::selectionTool )
53 .AppendAction( ACTIONS::measureTool );
54
55 config.AppendSeparator()
56 .AppendAction( ACTIONS::toggleGrid )
57 .AppendAction( ACTIONS::togglePolarCoords )
58 .AppendAction( ACTIONS::inchesUnits )
59 .AppendAction( ACTIONS::milsUnits )
60 .AppendAction( ACTIONS::millimetersUnits )
61 .AppendAction( ACTIONS::toggleCursorStyle );
62
63 config.AppendSeparator()
68 .AppendAction( GERBVIEW_ACTIONS::dcodeDisplay );
69
70 config.AppendSeparator()
72 .AppendAction( GERBVIEW_ACTIONS::toggleXORMode )
73 .AppendAction( ACTIONS::highContrastMode )
74 .AppendAction( GERBVIEW_ACTIONS::flipGerberView );
75
76 config.AppendSeparator()
78 break;
79
80 case TOOLBAR_LOC::TOP_MAIN:
84 .AppendAction( GERBVIEW_ACTIONS::openGerber )
85 .AppendAction( GERBVIEW_ACTIONS::openDrillFile );
86
87 config.AppendSeparator()
88 .AppendAction( ACTIONS::print );
89
90 config.AppendSeparator()
91 .AppendAction( ACTIONS::zoomRedraw )
92 .AppendAction( ACTIONS::zoomInCenter )
93 .AppendAction( ACTIONS::zoomOutCenter )
94 .AppendAction( ACTIONS::zoomFitScreen )
95 .AppendAction( ACTIONS::zoomTool );
96
97 config.AppendSeparator()
100 break;
101
102 case TOOLBAR_LOC::TOP_AUX:
104 .AppendSpacer( 5 )
106 .AppendSpacer( 5 )
108 .AppendSpacer( 5 )
110 .AppendSeparator()
112 .AppendSeparator()
113 .AppendControl( ACTION_TOOLBAR_CONTROLS::zoomSelect );
114 break;
115 }
116
117 // clang-format on
118 return config;
119}
120
121
123{
124 // Base class loads the default settings
126
127 // Register factories for the various toolbar controls
128 auto layerBoxFactory =
129 [this]( ACTION_TOOLBAR* aToolbar )
130 {
131 if( !m_SelLayerBox )
132 {
135 wxDefaultPosition, wxDefaultSize, 0, nullptr );
136 }
137
139 aToolbar->Add( m_SelLayerBox );
140
141 // UI update handler for the control
142 aToolbar->Bind( wxEVT_UPDATE_UI,
143 [this]( wxUpdateUIEvent& aEvent )
144 {
145 if( m_SelLayerBox->GetCount() )
146 {
147 if( m_SelLayerBox->GetSelection() != GetActiveLayer() )
148 m_SelLayerBox->SetSelection( GetActiveLayer() );
149 }
150 },
151 m_SelLayerBox->GetId() );
152 };
153
155
156
157 auto textInfoFactory =
158 [this]( ACTION_TOOLBAR* aToolbar )
159 {
160 if( !m_TextInfo )
161 {
162 m_TextInfo = new wxTextCtrl( aToolbar, ID_TOOLBARH_GERBER_DATA_TEXT_BOX, wxEmptyString,
163 wxDefaultPosition, wxDefaultSize, wxTE_READONLY );
164 }
165
166 aToolbar->Add( m_TextInfo );
167 };
168
170
171
172 // Creates box to display and choose components:
173 // (note, when the m_tbTopAux is recreated, tools are deleted, but controls
174 // are not deleted: they are just no longer managed by the toolbar
175 auto componentBoxFactory =
176 [this]( ACTION_TOOLBAR* aToolbar )
177 {
178 if( !m_SelComponentBox )
179 m_SelComponentBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
180
181 if( !m_cmpText )
182 m_cmpText = new wxStaticText( aToolbar, wxID_ANY, _( "Cmp:" ) + wxS( " " ) );
183
184 m_SelComponentBox->SetToolTip( _("Highlight items belonging to this component") );
185 m_cmpText->SetLabel( _( "Cmp:" ) + wxS( " " ) ); // can change when changing the language
186
188
189 aToolbar->Add( m_cmpText );
190 aToolbar->Add( m_SelComponentBox );
191 };
192
194
195
196 // Creates choice box to display net names and highlight selected:
197 auto netBoxFactory =
198 [this]( ACTION_TOOLBAR* aToolbar )
199 {
200 if( !m_SelNetnameBox )
201 m_SelNetnameBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE );
202
203 if( !m_netText )
204 m_netText = new wxStaticText( aToolbar, wxID_ANY, _( "Net:" ) );
205
206 m_SelNetnameBox->SetToolTip( _("Highlight items belonging to this net") );
207 m_netText->SetLabel( _( "Net:" ) ); // can change when changing the language
208
210
211 aToolbar->Add( m_netText );
212 aToolbar->Add( m_SelNetnameBox );
213 };
214
216
217
218 // Creates choice box to display aperture attributes and highlight selected:
219 auto appertureBoxFactory =
220 [this]( ACTION_TOOLBAR* aToolbar )
221 {
223 {
224 m_SelAperAttributesBox = new wxChoice( aToolbar,
226 }
227
228 if( !m_apertText )
229 m_apertText = new wxStaticText( aToolbar, wxID_ANY, _( "Attr:" ) );
230
231 m_SelAperAttributesBox->SetToolTip( _( "Highlight items with this aperture attribute" ) );
232 m_apertText->SetLabel( _( "Attr:" ) ); // can change when changing the language
233
235
236 aToolbar->Add( m_apertText );
237 aToolbar->Add( m_SelAperAttributesBox );
238 };
239
241
242
243 // D-code selection
244 auto dcodeSelectorFactory =
245 [this]( ACTION_TOOLBAR* aToolbar )
246 {
247 if( !m_DCodeSelector )
248 {
249 m_DCodeSelector = new DCODE_SELECTION_BOX( aToolbar,
251 wxDefaultPosition, wxSize( 150, -1 ) );
252 }
253
254 if( !m_dcodeText )
255 m_dcodeText = new wxStaticText( aToolbar, wxID_ANY, _( "DCode:" ) );
256
257 m_dcodeText->SetLabel( _( "DCode:" ) );
258
260
261 aToolbar->Add( m_dcodeText );
262 aToolbar->Add( m_DCodeSelector );
263 };
264
266}
267
268ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::textInfo( "control.TextInfo", _( "Text info entry" ),
269 _( "Text info entry" ) );
271 _( "Component highlight" ),
272 _( "Highlight items belonging to this component" ) );
273ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::netHighlight( "control.NetHighlight", _( "Net highlight" ),
274 _( "Highlight items belonging to this net" ) );
275ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::appertureHighlight( "control.AppertureHighlight", _( "Aperture highlight" ),
276 _( "Highlight items with this aperture attribute" ));
277ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::dcodeSelector( "control.GerberDcodeSelector", _( "DCode Selector" ),
278 _( "Select all items with the selected DCode" ) );
279
280
281#define NO_SELECTION_STRING _("<No selection>")
282
283
285{
286 m_DCodeSelector->Clear();
287
288 // Add an empty string to deselect net highlight
290
291 int layer = GetActiveLayer();
292 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
293
294 if( !gerber || gerber->GetDcodesCount() == 0 )
295 {
296 if( m_DCodeSelector->GetSelection() != 0 )
297 m_DCodeSelector->SetSelection( 0 );
298
299 return;
300 }
301
302 // Build the aperture list of the current layer, and add it to the combo box:
303 wxArrayString dcode_list;
304 wxString msg;
305
306 double scale = 1.0;
307 wxString units;
308
309 switch( GetUserUnits() )
310 {
311 case EDA_UNITS::MM:
313 units = wxT( "mm" );
314 break;
315
316 case EDA_UNITS::INCH:
318 units = wxT( "in" );
319 break;
320
321 case EDA_UNITS::MILS:
323 units = wxT( "mil" );
324 break;
325
326 default:
327 wxASSERT_MSG( false, wxT( "Invalid units" ) );
328 }
329
330 for( const auto [_, dcode] : gerber->m_ApertureList )
331 {
332 wxCHECK2( dcode,continue );
333
334 if( !dcode->m_InUse && !dcode->m_Defined )
335 continue;
336
337 msg.Printf( wxT( "tool %d [%.3fx%.3f %s] %s" ),
338 dcode->m_Num_Dcode,
339 dcode->m_Size.x / scale, dcode->m_Size.y / scale,
340 units,
341 D_CODE::ShowApertureType( dcode->m_ApertType ) );
342
343 if( !dcode->m_AperFunction.IsEmpty() )
344 msg << wxT( ", " ) << dcode->m_AperFunction;
345
346 dcode_list.Add( msg );
347 }
348
349 m_DCodeSelector->AppendDCodeList( dcode_list );
350
351 if( dcode_list.size() > 1 )
352 {
353 wxSize size = m_DCodeSelector->GetBestSize();
354 size.x = std::max( size.x, 100 );
355 m_DCodeSelector->SetMinSize( size );
356 m_auimgr.Update();
357 }
358}
359
360
362{
363 m_SelComponentBox->Clear();
364
365 // Build the full list of component names from the partial lists stored in each file image
366 std::map<wxString, int> full_list;
367
368 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
369 {
370 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
371
372 if( gerber == nullptr ) // Graphic layer not yet used
373 continue;
374
375 full_list.insert( gerber->m_ComponentsList.begin(), gerber->m_ComponentsList.end() );
376 }
377
378 // Add an empty string to deselect net highlight
380
381 // Now copy the list to the choice box
382 for( const std::pair<const wxString, int>& entry : full_list )
383 m_SelComponentBox->Append( entry.first );
384
385 m_SelComponentBox->SetSelection( 0 );
386}
387
388
390{
391 m_SelNetnameBox->Clear();
392
393 // Build the full list of netnames from the partial lists stored in each file image
394 std::map<wxString, int> full_list;
395
396 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
397 {
398 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
399
400 if( gerber == nullptr ) // Graphic layer not yet used
401 continue;
402
403 full_list.insert( gerber->m_NetnamesList.begin(), gerber->m_NetnamesList.end() );
404 }
405
406 // Add an empty string to deselect net highlight
408
409 // Now copy the list to the choice box
410 for( const std::pair<const wxString, int>& entry : full_list )
411 m_SelNetnameBox->Append( UnescapeString( entry.first ) );
412
413 m_SelNetnameBox->SetSelection( 0 );
414}
415
416
418{
419 m_SelAperAttributesBox->Clear();
420
421 // Build the full list of netnames from the partial lists stored in each file image
422 std::map<wxString, int> full_list;
423
424 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
425 {
426 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
427
428 if( gerber == nullptr ) // Graphic layer not yet used
429 continue;
430
431 if( gerber->GetDcodesCount() == 0 )
432 continue;
433
434 for( const auto &[_, aperture] : gerber->m_ApertureList )
435 {
436 if( aperture == nullptr )
437 continue;
438
439 if( !aperture->m_InUse && !aperture->m_Defined )
440 continue;
441
442 if( !aperture->m_AperFunction.IsEmpty() )
443 full_list.insert( std::make_pair( aperture->m_AperFunction, 0 ) );
444 }
445 }
446
447 // Add an empty string to deselect net highlight
449
450 // Now copy the list to the choice box
451 for( const std::pair<const wxString, int>& entry : full_list )
452 m_SelAperAttributesBox->Append( entry.first );
453
454 m_SelAperAttributesBox->SetSelection( 0 );
455}
456
457
458void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
459{
460 if( !m_DCodeSelector )
461 return;
462
463 int layer = GetActiveLayer();
464 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
465 int selected = gerber ? gerber->m_Selected_Tool : 0;
466
467 aEvent.Enable( gerber != nullptr );
468
469 if( m_DCodeSelector->GetSelectedDCodeId() != selected )
470 {
472 // Be sure the selection can be made. If no, set to
473 // a correct value
474 if( gerber )
476 }
477}
constexpr EDA_IU_SCALE gerbIUScale
Definition: base_units.h:107
static TOOL_ACTION toggleGrid
Definition: actions.h:191
static TOOL_ACTION zoomRedraw
Definition: actions.h:124
static TOOL_ACTION millimetersUnits
Definition: actions.h:199
static TOOL_ACTION zoomOutCenter
Definition: actions.h:128
static TOOL_ACTION togglePolarCoords
Definition: actions.h:202
static TOOL_ACTION milsUnits
Definition: actions.h:198
static TOOL_ACTION inchesUnits
Definition: actions.h:197
static TOOL_ACTION highContrastMode
Definition: actions.h:145
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:144
static TOOL_ACTION measureTool
Definition: actions.h:207
static TOOL_ACTION selectionTool
Definition: actions.h:206
static TOOL_ACTION zoomFitScreen
Definition: actions.h:134
static TOOL_ACTION zoomTool
Definition: actions.h:138
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION zoomInCenter
Definition: actions.h:127
static ACTION_TOOLBAR_CONTROL gridSelect
static ACTION_TOOLBAR_CONTROL layerSelector
static ACTION_TOOLBAR_CONTROL zoomSelect
Class to hold basic information about controls that can be added to the toolbars.
Define the structure of a toolbar with buttons that invoke ACTIONs.
Helper to display a DCode list and select a DCode id.
void SetDCodeSelection(int aDCodeId)
void AppendDCodeList(const wxArrayString &aChoices)
static const wxChar * ShowApertureType(APERTURE_T aType)
Return a character string telling what type of aperture type aType is.
Definition: dcode.cpp:86
void RegisterCustomToolbarControlFactory(const ACTION_TOOLBAR_CONTROL &aControlDesc, const ACTION_TOOLBAR_CONTROL_FACTORY &aControlFactory)
Register a creation factory for toolbar controls that are present in this frame.
wxAuiManager m_auimgr
void configureToolbars() override
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
Hold the image data and parameters for one gerber file and layer parameters.
std::map< wxString, int > m_ComponentsList
std::map< int, D_CODE * > m_ApertureList
Dcode (Aperture) List for this layer (see dcode.h)
std::map< wxString, int > m_NetnamesList
static TOOL_ACTION dcodeDisplay
static TOOL_ACTION negativeObjectDisplay
static TOOL_ACTION flashedDisplayOutlines
static TOOL_ACTION toggleXORMode
static TOOL_ACTION toggleLayerManager
static TOOL_ACTION openGerber
static TOOL_ACTION clearAllLayers
static TOOL_ACTION flipGerberView
static TOOL_ACTION openAutodetected
static TOOL_ACTION reloadAllLayers
static TOOL_ACTION toggleForceOpacityMode
static TOOL_ACTION linesDisplayOutlines
static TOOL_ACTION openDrillFile
static TOOL_ACTION polygonsDisplayOutlines
static ACTION_TOOLBAR_CONTROL componentHighlight
static ACTION_TOOLBAR_CONTROL textInfo
static ACTION_TOOLBAR_CONTROL dcodeSelector
static ACTION_TOOLBAR_CONTROL appertureHighlight
static ACTION_TOOLBAR_CONTROL netHighlight
void OnUpdateSelectDCode(wxUpdateUIEvent &aEvent)
wxStaticText * m_dcodeText
wxChoice * m_SelAperAttributesBox
void configureToolbars() override
GBR_LAYER_BOX_SELECTOR * m_SelLayerBox
wxStaticText * m_cmpText
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
wxChoice * m_SelComponentBox
wxChoice * m_SelNetnameBox
int GetActiveLayer() const
Return the active layer.
wxTextCtrl * m_TextInfo
DCODE_SELECTION_BOX * m_DCodeSelector
wxStaticText * m_netText
void updateAperAttributesSelectBox()
wxStaticText * m_apertText
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
void updateComponentListSelectBox()
void updateNetnameListSelectBox()
std::optional< TOOLBAR_CONFIGURATION > DefaultToolbarConfig(TOOLBAR_LOC aToolbar) override
Get the default tools to show on the specified canvas toolbar.
EDA_UNITS GetUserUnits() const
#define _(s)
@ ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE
Definition: gerbview_id.h:44
@ ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER
Definition: gerbview_id.h:47
@ ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE
Definition: gerbview_id.h:43
@ ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE
Definition: gerbview_id.h:40
@ ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE
Definition: gerbview_id.h:45
@ ID_TOOLBARH_GERBER_DATA_TEXT_BOX
Definition: gerbview_id.h:41
const int scale
wxString UnescapeString(const wxString &aSource)
const double IU_PER_MM
Definition: base_units.h:76
const double IU_PER_MILS
Definition: base_units.h:77
#define NO_SELECTION_STRING