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 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
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 )
77 .AppendAction( ACTIONS::highContrastMode )
78 .AppendAction( GERBVIEW_ACTIONS::flipGerberView );
79
80 config.AppendSeparator()
82 break;
83
88 .AppendAction( GERBVIEW_ACTIONS::openGerber )
89 .AppendAction( GERBVIEW_ACTIONS::openDrillFile );
90
91 config.AppendSeparator()
92 .AppendAction( ACTIONS::print );
93
94 config.AppendSeparator()
95 .AppendAction( ACTIONS::zoomRedraw )
96 .AppendAction( ACTIONS::zoomInCenter )
97 .AppendAction( ACTIONS::zoomOutCenter )
98 .AppendAction( ACTIONS::zoomFitScreen )
99 .AppendAction( ACTIONS::zoomTool );
100
101 config.AppendSeparator()
104 break;
105
108 .AppendSpacer( 5 )
110 .AppendSpacer( 5 )
112 .AppendSpacer( 5 )
114 .AppendSeparator()
116 .AppendSeparator()
117 .AppendControl( ACTION_TOOLBAR_CONTROLS::zoomSelect );
118 break;
119 }
120
121 // clang-format on
122 return config;
123}
124
125
127{
128 // Base class loads the default settings
130
131 // Register factories for the various toolbar controls
132 auto layerBoxFactory =
133 [this]( ACTION_TOOLBAR* aToolbar )
134 {
135 if( !m_SelLayerBox )
136 {
138 wxDefaultPosition, wxDefaultSize, 0, nullptr );
139 }
140
141 m_SelLayerBox->Resync();
142 aToolbar->Add( m_SelLayerBox );
143
144 // UI update handler for the control
145 aToolbar->Bind( wxEVT_UPDATE_UI,
146 [this]( wxUpdateUIEvent& aEvent )
147 {
148 if( m_SelLayerBox->GetCount() )
149 {
150 if( m_SelLayerBox->GetSelection() != GetActiveLayer() )
151 m_SelLayerBox->SetSelection( GetActiveLayer() );
152 }
153 },
154 m_SelLayerBox->GetId() );
155 };
156
158
159
160 auto textInfoFactory =
161 [this]( ACTION_TOOLBAR* aToolbar )
162 {
163 if( !m_TextInfo )
164 {
165 m_TextInfo = new wxTextCtrl( aToolbar, ID_TOOLBARH_GERBER_DATA_TEXT_BOX, wxEmptyString,
166 wxDefaultPosition, wxDefaultSize, wxTE_READONLY );
167 }
168
169 aToolbar->Add( m_TextInfo );
170 };
171
173
174
175 // Creates box to display and choose components:
176 // (note, when the m_tbTopAux is recreated, tools are deleted, but controls
177 // are not deleted: they are just no longer managed by the toolbar
178 auto componentBoxFactory =
179 [this]( ACTION_TOOLBAR* aToolbar )
180 {
181 if( !m_SelComponentBox )
182 m_SelComponentBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
183
184 if( !m_cmpText )
185 m_cmpText = new wxStaticText( aToolbar, wxID_ANY, _( "Cmp:" ) + wxS( " " ) );
186
187 m_SelComponentBox->SetToolTip( _("Highlight items belonging to this component") );
188 m_cmpText->SetLabel( _( "Cmp:" ) + wxS( " " ) ); // can change when changing the language
189
191
192 aToolbar->Add( m_cmpText );
193 aToolbar->Add( m_SelComponentBox );
194 };
195
197
198
199 // Creates choice box to display net names and highlight selected:
200 auto netBoxFactory =
201 [this]( ACTION_TOOLBAR* aToolbar )
202 {
203 if( !m_SelNetnameBox )
204 m_SelNetnameBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE );
205
206 if( !m_netText )
207 m_netText = new wxStaticText( aToolbar, wxID_ANY, _( "Net:" ) );
208
209 m_SelNetnameBox->SetToolTip( _("Highlight items belonging to this net") );
210 m_netText->SetLabel( _( "Net:" ) ); // can change when changing the language
211
213
214 aToolbar->Add( m_netText );
215 aToolbar->Add( m_SelNetnameBox );
216 };
217
219
220
221 // Creates choice box to display aperture attributes and highlight selected:
222 auto appertureBoxFactory =
223 [this]( ACTION_TOOLBAR* aToolbar )
224 {
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 {
250 wxDefaultPosition, wxSize( 150, -1 ) );
251 }
252
253 if( !m_dcodeText )
254 m_dcodeText = new wxStaticText( aToolbar, wxID_ANY, _( "DCode:" ) );
255
256 m_dcodeText->SetLabel( _( "DCode:" ) );
257
259
260 aToolbar->Add( m_dcodeText );
261 aToolbar->Add( m_DCodeSelector );
262 };
263
265}
266
267
269{
271
272 switch( aId )
273 {
275 m_SelLayerBox = nullptr;
276 break;
278 m_TextInfo = nullptr;
279 break;
281 m_SelComponentBox = nullptr;
282 m_cmpText = nullptr;
283 break;
285 m_SelNetnameBox = nullptr;
286 m_netText = nullptr;
287 break;
289 m_SelAperAttributesBox = nullptr;
290 m_apertText = nullptr;
291 break;
293 m_DCodeSelector = nullptr;
294 m_dcodeText = nullptr;
295 break;
296 }
297}
298
299
301 _( "Text info entry" ),
302 _( "Text info entry" ),
303 { FRAME_GERBER } );
305 _( "Component highlight" ),
306 _( "Highlight items belonging to this component" ),
307 { FRAME_GERBER } );
309 _( "Net highlight" ),
310 _( "Highlight items belonging to this net" ),
311 { FRAME_GERBER } );
313 _( "Aperture highlight" ),
314 _( "Highlight items with this aperture attribute" ),
315 { FRAME_GERBER } );
317 _( "DCode selector" ),
318 _( "Select all items with the selected DCode" ),
319 { FRAME_GERBER } );
320
321
322#define NO_SELECTION_STRING _( "<No selection>" )
323
324
326{
327 m_DCodeSelector->Clear();
328
329 // Add an empty string to deselect net highlight
331
332 int layer = GetActiveLayer();
333 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
334
335 if( !gerber || gerber->GetDcodesCount() == 0 )
336 {
337 if( m_DCodeSelector->GetSelection() != 0 )
338 m_DCodeSelector->SetSelection( 0 );
339
340 return;
341 }
342
343 // Build the aperture list of the current layer, and add it to the combo box:
344 wxArrayString dcode_list;
345 wxString msg;
346
347 double scale = 1.0;
348 wxString units;
349
350 switch( GetUserUnits() )
351 {
352 case EDA_UNITS::MM:
353 scale = gerbIUScale.IU_PER_MM;
354 units = wxT( "mm" );
355 break;
356
357 case EDA_UNITS::INCH:
358 scale = gerbIUScale.IU_PER_MILS * 1000;
359 units = wxT( "in" );
360 break;
361
362 case EDA_UNITS::MILS:
363 scale = gerbIUScale.IU_PER_MILS;
364 units = wxT( "mil" );
365 break;
366
367 default:
368 wxASSERT_MSG( false, wxT( "Invalid units" ) );
369 }
370
371 for( const auto& [_, dcode] : gerber->m_ApertureList )
372 {
373 wxCHECK2( dcode,continue );
374
375 if( !dcode->m_InUse && !dcode->m_Defined )
376 continue;
377
378 msg.Printf( wxT( "tool %d [%.3fx%.3f %s] %s" ),
379 dcode->m_Num_Dcode,
380 dcode->m_Size.x / scale, dcode->m_Size.y / scale,
381 units,
382 D_CODE::ShowApertureType( dcode->m_ApertType ) );
383
384 if( !dcode->m_AperFunction.IsEmpty() )
385 msg << wxT( ", " ) << dcode->m_AperFunction;
386
387 dcode_list.Add( msg );
388 }
389
390 m_DCodeSelector->AppendDCodeList( dcode_list );
391
392 if( dcode_list.size() > 1 )
393 {
394 wxSize size = m_DCodeSelector->GetBestSize();
395 size.x = std::max( size.x, 100 );
396 m_DCodeSelector->SetMinSize( size );
397 m_auimgr.Update();
398 }
399}
400
401
403{
404 m_SelComponentBox->Clear();
405
406 // Build the full list of component names from the partial lists stored in each file image
407 std::map<wxString, int> full_list;
408
409 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
410 {
411 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
412
413 if( gerber == nullptr ) // Graphic layer not yet used
414 continue;
415
416 full_list.insert( gerber->m_ComponentsList.begin(), gerber->m_ComponentsList.end() );
417 }
418
419 // Add an empty string to deselect net highlight
421
422 // Now copy the list to the choice box
423 for( const std::pair<const wxString, int>& entry : full_list )
424 m_SelComponentBox->Append( entry.first );
425
426 m_SelComponentBox->SetSelection( 0 );
427}
428
429
431{
432 m_SelNetnameBox->Clear();
433
434 // Build the full list of netnames from the partial lists stored in each file image
435 std::map<wxString, int> full_list;
436
437 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
438 {
439 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
440
441 if( gerber == nullptr ) // Graphic layer not yet used
442 continue;
443
444 full_list.insert( gerber->m_NetnamesList.begin(), gerber->m_NetnamesList.end() );
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_SelNetnameBox->Append( UnescapeString( entry.first ) );
453
454 m_SelNetnameBox->SetSelection( 0 );
455}
456
457
459{
460 m_SelAperAttributesBox->Clear();
461
462 // Build the full list of netnames from the partial lists stored in each file image
463 std::map<wxString, int> full_list;
464
465 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
466 {
467 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
468
469 if( gerber == nullptr ) // Graphic layer not yet used
470 continue;
471
472 if( gerber->GetDcodesCount() == 0 )
473 continue;
474
475 for( const auto &[_, aperture] : gerber->m_ApertureList )
476 {
477 if( aperture == nullptr )
478 continue;
479
480 if( !aperture->m_InUse && !aperture->m_Defined )
481 continue;
482
483 if( !aperture->m_AperFunction.IsEmpty() )
484 full_list.insert( std::make_pair( aperture->m_AperFunction, 0 ) );
485 }
486 }
487
488 // Add an empty string to deselect net highlight
490
491 // Now copy the list to the choice box
492 for( const std::pair<const wxString, int>& entry : full_list )
493 m_SelAperAttributesBox->Append( entry.first );
494
495 m_SelAperAttributesBox->SetSelection( 0 );
496}
497
498
499void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
500{
501 if( !m_DCodeSelector )
502 return;
503
504 int layer = GetActiveLayer();
505 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
506 int selected = gerber ? gerber->m_Selected_Tool : 0;
507
508 aEvent.Enable( gerber != nullptr );
509
510 if( m_DCodeSelector->GetSelectedDCodeId() != selected )
511 {
512 m_DCodeSelector->SetDCodeSelection( selected );
513 // Be sure the selection can be made. If no, set to
514 // a correct value
515 if( gerber )
516 gerber->m_Selected_Tool = m_DCodeSelector->GetSelectedDCodeId();
517 }
518}
constexpr EDA_IU_SCALE gerbIUScale
Definition base_units.h:111
static TOOL_ACTION toggleGrid
Definition actions.h:198
static TOOL_ACTION zoomRedraw
Definition actions.h:132
static TOOL_ACTION millimetersUnits
Definition actions.h:206
static TOOL_ACTION cursorSmallCrosshairs
Definition actions.h:152
static TOOL_ACTION zoomOutCenter
Definition actions.h:136
static TOOL_ACTION togglePolarCoords
Definition actions.h:209
static TOOL_ACTION milsUnits
Definition actions.h:205
static TOOL_ACTION inchesUnits
Definition actions.h:204
static TOOL_ACTION highContrastMode
Definition actions.h:155
static TOOL_ACTION measureTool
Definition actions.h:252
static TOOL_ACTION selectionTool
Definition actions.h:251
static TOOL_ACTION zoomFitScreen
Definition actions.h:142
static TOOL_ACTION zoomTool
Definition actions.h:146
static TOOL_ACTION cursor45Crosshairs
Definition actions.h:154
static TOOL_ACTION print
Definition actions.h:64
static TOOL_ACTION zoomInCenter
Definition actions.h:135
static TOOL_ACTION cursorFullCrosshairs
Definition actions.h:153
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: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
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 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()
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:57
@ ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE
Definition gerbview_id.h:42
@ ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER
Definition gerbview_id.h:45
@ ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE
Definition gerbview_id.h:41
@ ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE
Definition gerbview_id.h:38
@ ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE
Definition gerbview_id.h:43
@ ID_TOOLBARH_GERBER_DATA_TEXT_BOX
Definition gerbview_id.h:39
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