KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
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
19 * along with this program. If not, see <https://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
49 return std::nullopt;
50
52 config.AppendAction( ACTIONS::selectionTool )
53 .AppendAction( ACTIONS::measureTool );
54
55 config.AppendSeparator()
56 .AppendAction( ACTIONS::toggleGrid )
57 .AppendAction( ACTIONS::togglePolarCoords )
58 .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Units" ) )
59 .AddAction( ACTIONS::millimetersUnits )
60 .AddAction( ACTIONS::inchesUnits )
61 .AddAction( ACTIONS::milsUnits ) )
62 .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Crosshair modes" ) )
65 .AddAction( ACTIONS::cursor45Crosshairs ) );
66
67 config.AppendSeparator()
72 .AppendAction( GERBVIEW_ACTIONS::dcodeDisplay );
73
74 config.AppendSeparator()
76 .AppendAction( GERBVIEW_ACTIONS::toggleXORMode )
78 .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Inactive Layer View Mode" ) )
82
83 config.AppendSeparator()
85 break;
86
91 .AppendAction( GERBVIEW_ACTIONS::openGerber )
92 .AppendAction( GERBVIEW_ACTIONS::openDrillFile );
93
94 config.AppendSeparator()
95 .AppendAction( ACTIONS::print );
96
97 config.AppendSeparator()
98 .AppendAction( ACTIONS::zoomRedraw )
99 .AppendAction( ACTIONS::zoomInCenter )
100 .AppendAction( ACTIONS::zoomOutCenter )
101 .AppendAction( ACTIONS::zoomFitScreen )
102 .AppendAction( ACTIONS::zoomTool );
103
104 config.AppendSeparator()
107 break;
108
111 .AppendSpacer( 5 )
113 .AppendSpacer( 5 )
115 .AppendSpacer( 5 )
117 .AppendSeparator()
119 .AppendSeparator()
120 .AppendControl( ACTION_TOOLBAR_CONTROLS::zoomSelect );
121 break;
122 }
123
124 // clang-format on
125 return config;
126}
127
128
130{
131 // Base class loads the default settings
133
134 // Register factories for the various toolbar controls
135 auto layerBoxFactory =
136 [this]( ACTION_TOOLBAR* aToolbar )
137 {
138 if( !m_SelLayerBox )
139 {
141 wxDefaultPosition, wxDefaultSize, 0, nullptr );
142 }
143
144 m_SelLayerBox->Resync();
145 aToolbar->Add( m_SelLayerBox );
146
147 // UI update handler for the control
148 aToolbar->Bind( wxEVT_UPDATE_UI,
149 [this]( wxUpdateUIEvent& aEvent )
150 {
151 if( m_SelLayerBox->GetCount() )
152 {
153 if( m_SelLayerBox->GetSelection() != GetActiveLayer() )
154 m_SelLayerBox->SetSelection( GetActiveLayer() );
155 }
156 },
157 m_SelLayerBox->GetId() );
158 };
159
161
162
163 auto textInfoFactory =
164 [this]( ACTION_TOOLBAR* aToolbar )
165 {
166 if( !m_TextInfo )
167 {
168 m_TextInfo = new wxTextCtrl( aToolbar, ID_TOOLBARH_GERBER_DATA_TEXT_BOX, wxEmptyString,
169 wxDefaultPosition, wxDefaultSize, wxTE_READONLY );
170 }
171
172 aToolbar->Add( m_TextInfo );
173 };
174
176
177
178 // Creates box to display and choose components:
179 // (note, when the m_tbTopAux is recreated, tools are deleted, but controls
180 // are not deleted: they are just no longer managed by the toolbar
181 auto componentBoxFactory =
182 [this]( ACTION_TOOLBAR* aToolbar )
183 {
184 if( !m_SelComponentBox )
185 m_SelComponentBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
186
187 if( !m_cmpText )
188 m_cmpText = new wxStaticText( aToolbar, wxID_ANY, _( "Cmp:" ) + wxS( " " ) );
189
190 m_SelComponentBox->SetToolTip( _("Highlight items belonging to this component") );
191 m_cmpText->SetLabel( _( "Cmp:" ) + wxS( " " ) ); // can change when changing the language
192
194
195 aToolbar->Add( m_cmpText );
196 aToolbar->Add( m_SelComponentBox );
197 };
198
200
201
202 // Creates choice box to display net names and highlight selected:
203 auto netBoxFactory =
204 [this]( ACTION_TOOLBAR* aToolbar )
205 {
206 if( !m_SelNetnameBox )
207 m_SelNetnameBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE );
208
209 if( !m_netText )
210 m_netText = new wxStaticText( aToolbar, wxID_ANY, _( "Net:" ) );
211
212 m_SelNetnameBox->SetToolTip( _("Highlight items belonging to this net") );
213 m_netText->SetLabel( _( "Net:" ) ); // can change when changing the language
214
216
217 aToolbar->Add( m_netText );
218 aToolbar->Add( m_SelNetnameBox );
219 };
220
222
223
224 // Creates choice box to display aperture attributes and highlight selected:
225 auto appertureBoxFactory =
226 [this]( ACTION_TOOLBAR* aToolbar )
227 {
230
231 if( !m_apertText )
232 m_apertText = new wxStaticText( aToolbar, wxID_ANY, _( "Attr:" ) );
233
234 m_SelAperAttributesBox->SetToolTip( _( "Highlight items with this aperture attribute" ) );
235 m_apertText->SetLabel( _( "Attr:" ) ); // can change when changing the language
236
238
239 aToolbar->Add( m_apertText );
240 aToolbar->Add( m_SelAperAttributesBox );
241 };
242
244
245
246 // D-code selection
247 auto dcodeSelectorFactory =
248 [this]( ACTION_TOOLBAR* aToolbar )
249 {
250 if( !m_DCodeSelector )
251 {
253 wxDefaultPosition, wxSize( 150, -1 ) );
254 }
255
256 if( !m_dcodeText )
257 m_dcodeText = new wxStaticText( aToolbar, wxID_ANY, _( "DCode:" ) );
258
259 m_dcodeText->SetLabel( _( "DCode:" ) );
260
262
263 aToolbar->Add( m_dcodeText );
264 aToolbar->Add( m_DCodeSelector );
265 };
266
268}
269
270
272{
274
275 switch( aId )
276 {
278 m_SelLayerBox = nullptr;
279 break;
281 m_TextInfo = nullptr;
282 break;
284 m_SelComponentBox = nullptr;
285 m_cmpText = nullptr;
286 break;
288 m_SelNetnameBox = nullptr;
289 m_netText = nullptr;
290 break;
292 m_SelAperAttributesBox = nullptr;
293 m_apertText = nullptr;
294 break;
296 m_DCodeSelector = nullptr;
297 m_dcodeText = nullptr;
298 break;
299 }
300}
301
302
304 _( "Text info entry" ),
305 _( "Text info entry" ),
306 { FRAME_GERBER } );
308 _( "Component highlight" ),
309 _( "Highlight items belonging to this component" ),
310 { FRAME_GERBER } );
312 _( "Net highlight" ),
313 _( "Highlight items belonging to this net" ),
314 { FRAME_GERBER } );
316 _( "Aperture highlight" ),
317 _( "Highlight items with this aperture attribute" ),
318 { FRAME_GERBER } );
320 _( "DCode selector" ),
321 _( "Select all items with the selected DCode" ),
322 { FRAME_GERBER } );
323
324
325#define NO_SELECTION_STRING _( "<No selection>" )
326
327
329{
330 if( !m_DCodeSelector )
331 return;
332
333 m_DCodeSelector->Clear();
334
335 // Add an empty string to deselect net highlight
337
338 int layer = GetActiveLayer();
339 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
340
341 if( !gerber || gerber->GetDcodesCount() == 0 )
342 {
343 if( m_DCodeSelector->GetSelection() != 0 )
344 m_DCodeSelector->SetSelection( 0 );
345
346 return;
347 }
348
349 // Build the aperture list of the current layer, and add it to the combo box:
350 wxArrayString dcode_list;
351 wxString msg;
352
353 double scale = 1.0;
354 wxString units;
355
356 switch( GetUserUnits() )
357 {
358 case EDA_UNITS::MM:
359 scale = gerbIUScale.IU_PER_MM;
360 units = wxT( "mm" );
361 break;
362
363 case EDA_UNITS::INCH:
364 scale = gerbIUScale.IU_PER_MILS * 1000;
365 units = wxT( "in" );
366 break;
367
368 case EDA_UNITS::MILS:
369 scale = gerbIUScale.IU_PER_MILS;
370 units = wxT( "mil" );
371 break;
372
373 default:
374 wxASSERT_MSG( false, wxT( "Invalid units" ) );
375 }
376
377 for( const auto& [_, dcode] : gerber->m_ApertureList )
378 {
379 wxCHECK2( dcode,continue );
380
381 if( !dcode->m_InUse && !dcode->m_Defined )
382 continue;
383
384 msg.Printf( wxT( "tool %d [%.3fx%.3f %s] %s" ),
385 dcode->m_Num_Dcode,
386 dcode->m_Size.x / scale, dcode->m_Size.y / scale,
387 units,
388 D_CODE::ShowApertureType( dcode->m_ApertType ) );
389
390 if( !dcode->m_AperFunction.IsEmpty() )
391 msg << wxT( ", " ) << dcode->m_AperFunction;
392
393 dcode_list.Add( msg );
394 }
395
396 m_DCodeSelector->AppendDCodeList( dcode_list );
397
398 if( dcode_list.size() > 1 )
399 {
400 wxSize size = m_DCodeSelector->GetBestSize();
401 size.x = std::max( size.x, 100 );
402 m_DCodeSelector->SetMinSize( size );
403 m_auimgr.Update();
404 }
405}
406
407
409{
410 m_SelComponentBox->Clear();
411
412 // Build the full list of component names from the partial lists stored in each file image
413 std::map<wxString, int> full_list;
414
415 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
416 {
417 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
418
419 if( gerber == nullptr ) // Graphic layer not yet used
420 continue;
421
422 full_list.insert( gerber->m_ComponentsList.begin(), gerber->m_ComponentsList.end() );
423 }
424
425 // Add an empty string to deselect net highlight
427
428 // Now copy the list to the choice box
429 for( const std::pair<const wxString, int>& entry : full_list )
430 m_SelComponentBox->Append( entry.first );
431
432 m_SelComponentBox->SetSelection( 0 );
433}
434
435
437{
438 m_SelNetnameBox->Clear();
439
440 // Build the full list of netnames from the partial lists stored in each file image
441 std::map<wxString, int> full_list;
442
443 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
444 {
445 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
446
447 if( gerber == nullptr ) // Graphic layer not yet used
448 continue;
449
450 full_list.insert( gerber->m_NetnamesList.begin(), gerber->m_NetnamesList.end() );
451 }
452
453 // Add an empty string to deselect net highlight
455
456 // Now copy the list to the choice box
457 for( const std::pair<const wxString, int>& entry : full_list )
458 m_SelNetnameBox->Append( UnescapeString( entry.first ) );
459
460 m_SelNetnameBox->SetSelection( 0 );
461}
462
463
465{
466 m_SelAperAttributesBox->Clear();
467
468 // Build the full list of netnames from the partial lists stored in each file image
469 std::map<wxString, int> full_list;
470
471 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
472 {
473 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
474
475 if( gerber == nullptr ) // Graphic layer not yet used
476 continue;
477
478 if( gerber->GetDcodesCount() == 0 )
479 continue;
480
481 for( const auto &[_, aperture] : gerber->m_ApertureList )
482 {
483 if( aperture == nullptr )
484 continue;
485
486 if( !aperture->m_InUse && !aperture->m_Defined )
487 continue;
488
489 if( !aperture->m_AperFunction.IsEmpty() )
490 full_list.insert( std::make_pair( aperture->m_AperFunction, 0 ) );
491 }
492 }
493
494 // Add an empty string to deselect net highlight
496
497 // Now copy the list to the choice box
498 for( const std::pair<const wxString, int>& entry : full_list )
499 m_SelAperAttributesBox->Append( entry.first );
500
501 m_SelAperAttributesBox->SetSelection( 0 );
502}
503
504
505void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
506{
507 if( !m_DCodeSelector )
508 return;
509
510 int layer = GetActiveLayer();
511 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
512 int selected = gerber ? gerber->m_Selected_Tool : 0;
513
514 aEvent.Enable( gerber != nullptr );
515
516 if( m_DCodeSelector->GetSelectedDCodeId() != selected )
517 {
518 m_DCodeSelector->SetDCodeSelection( selected );
519 // Be sure the selection can be made. If no, set to
520 // a correct value
521 if( gerber )
522 gerber->m_Selected_Tool = m_DCodeSelector->GetSelectedDCodeId();
523 }
524}
constexpr EDA_IU_SCALE gerbIUScale
Definition base_units.h:127
static TOOL_ACTION toggleGrid
Definition actions.h:194
static TOOL_ACTION zoomRedraw
Definition actions.h:128
static TOOL_ACTION millimetersUnits
Definition actions.h:202
static TOOL_ACTION cursorSmallCrosshairs
Definition actions.h:148
static TOOL_ACTION zoomOutCenter
Definition actions.h:132
static TOOL_ACTION togglePolarCoords
Definition actions.h:205
static TOOL_ACTION milsUnits
Definition actions.h:201
static TOOL_ACTION inchesUnits
Definition actions.h:200
static TOOL_ACTION measureTool
Definition actions.h:248
static TOOL_ACTION selectionTool
Definition actions.h:247
static TOOL_ACTION zoomFitScreen
Definition actions.h:138
static TOOL_ACTION zoomTool
Definition actions.h:142
static TOOL_ACTION cursor45Crosshairs
Definition actions.h:150
static TOOL_ACTION print
Definition actions.h:60
static TOOL_ACTION zoomInCenter
Definition actions.h:131
static TOOL_ACTION cursorFullCrosshairs
Definition actions.h:149
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.
static const wxChar * ShowApertureType(APERTURE_T aType)
Return a character string telling what type of aperture type aType is.
Definition dcode.cpp:82
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
void ClearToolbarControl(int aId) 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 showInactiveLayers
static TOOL_ACTION flipGerberView
static TOOL_ACTION openAutodetected
static TOOL_ACTION reloadAllLayers
static TOOL_ACTION toggleForceOpacityMode
static TOOL_ACTION dimInactiveLayers
static TOOL_ACTION linesDisplayOutlines
static TOOL_ACTION openDrillFile
static TOOL_ACTION polygonsDisplayOutlines
static TOOL_ACTION hideInactiveLayers
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()
void ClearToolbarControl(int aId) override
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)
@ FRAME_GERBER
Definition frame_type.h:53
@ ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE
Definition gerbview_id.h:38
@ ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER
Definition gerbview_id.h:41
@ ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE
Definition gerbview_id.h:37
@ ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE
Definition gerbview_id.h:34
@ ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE
Definition gerbview_id.h:39
@ ID_TOOLBARH_GERBER_DATA_TEXT_BOX
Definition gerbview_id.h:35
const int scale
wxString UnescapeString(const wxString &aSource)
@ RIGHT
Toolbar on the right side of the canvas.
@ LEFT
Toolbar on the left side of the canvas.
@ TOP_AUX
Toolbar on the top of the canvas.
@ TOP_MAIN
Toolbar on the top of the canvas.
#define NO_SELECTION_STRING