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 {
139 wxDefaultPosition, wxDefaultSize, 0, nullptr );
140 }
141
142 m_SelLayerBox->Resync();
143 aToolbar->Add( m_SelLayerBox );
144
145 // UI update handler for the control
146 aToolbar->Bind( wxEVT_UPDATE_UI,
147 [this]( wxUpdateUIEvent& aEvent )
148 {
149 if( m_SelLayerBox->GetCount() )
150 {
151 if( m_SelLayerBox->GetSelection() != GetActiveLayer() )
152 m_SelLayerBox->SetSelection( GetActiveLayer() );
153 }
154 },
155 m_SelLayerBox->GetId() );
156 };
157
159
160
161 auto textInfoFactory =
162 [this]( ACTION_TOOLBAR* aToolbar )
163 {
164 if( !m_TextInfo )
165 {
166 m_TextInfo = new wxTextCtrl( aToolbar, ID_TOOLBARH_GERBER_DATA_TEXT_BOX, wxEmptyString,
167 wxDefaultPosition, wxDefaultSize, wxTE_READONLY );
168 }
169
170 aToolbar->Add( m_TextInfo );
171 };
172
174
175
176 // Creates box to display and choose components:
177 // (note, when the m_tbTopAux is recreated, tools are deleted, but controls
178 // are not deleted: they are just no longer managed by the toolbar
179 auto componentBoxFactory =
180 [this]( ACTION_TOOLBAR* aToolbar )
181 {
182 if( !m_SelComponentBox )
183 m_SelComponentBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
184
185 if( !m_cmpText )
186 m_cmpText = new wxStaticText( aToolbar, wxID_ANY, _( "Cmp:" ) + wxS( " " ) );
187
188 m_SelComponentBox->SetToolTip( _("Highlight items belonging to this component") );
189 m_cmpText->SetLabel( _( "Cmp:" ) + wxS( " " ) ); // can change when changing the language
190
192
193 aToolbar->Add( m_cmpText );
194 aToolbar->Add( m_SelComponentBox );
195 };
196
198
199
200 // Creates choice box to display net names and highlight selected:
201 auto netBoxFactory =
202 [this]( ACTION_TOOLBAR* aToolbar )
203 {
204 if( !m_SelNetnameBox )
205 m_SelNetnameBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE );
206
207 if( !m_netText )
208 m_netText = new wxStaticText( aToolbar, wxID_ANY, _( "Net:" ) );
209
210 m_SelNetnameBox->SetToolTip( _("Highlight items belonging to this net") );
211 m_netText->SetLabel( _( "Net:" ) ); // can change when changing the language
212
214
215 aToolbar->Add( m_netText );
216 aToolbar->Add( m_SelNetnameBox );
217 };
218
220
221
222 // Creates choice box to display aperture attributes and highlight selected:
223 auto appertureBoxFactory =
224 [this]( ACTION_TOOLBAR* aToolbar )
225 {
227 {
228 m_SelAperAttributesBox = new wxChoice( aToolbar,
230 }
231
232 if( !m_apertText )
233 m_apertText = new wxStaticText( aToolbar, wxID_ANY, _( "Attr:" ) );
234
235 m_SelAperAttributesBox->SetToolTip( _( "Highlight items with this aperture attribute" ) );
236 m_apertText->SetLabel( _( "Attr:" ) ); // can change when changing the language
237
239
240 aToolbar->Add( m_apertText );
241 aToolbar->Add( m_SelAperAttributesBox );
242 };
243
245
246
247 // D-code selection
248 auto dcodeSelectorFactory =
249 [this]( ACTION_TOOLBAR* aToolbar )
250 {
251 if( !m_DCodeSelector )
252 {
253 m_DCodeSelector = new DCODE_SELECTION_BOX( aToolbar,
255 wxDefaultPosition, wxSize( 150, -1 ) );
256 }
257
258 if( !m_dcodeText )
259 m_dcodeText = new wxStaticText( aToolbar, wxID_ANY, _( "DCode:" ) );
260
261 m_dcodeText->SetLabel( _( "DCode:" ) );
262
264
265 aToolbar->Add( m_dcodeText );
266 aToolbar->Add( m_DCodeSelector );
267 };
268
270}
271
272ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::textInfo( "control.TextInfo", _( "Text info entry" ),
273 _( "Text info entry" ) );
275 _( "Component highlight" ),
276 _( "Highlight items belonging to this component" ) );
277ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::netHighlight( "control.NetHighlight", _( "Net highlight" ),
278 _( "Highlight items belonging to this net" ) );
279ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::appertureHighlight( "control.AppertureHighlight", _( "Aperture highlight" ),
280 _( "Highlight items with this aperture attribute" ));
281ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::dcodeSelector( "control.GerberDcodeSelector", _( "DCode Selector" ),
282 _( "Select all items with the selected DCode" ) );
283
284
285#define NO_SELECTION_STRING _("<No selection>")
286
287
289{
290 m_DCodeSelector->Clear();
291
292 // Add an empty string to deselect net highlight
294
295 int layer = GetActiveLayer();
296 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
297
298 if( !gerber || gerber->GetDcodesCount() == 0 )
299 {
300 if( m_DCodeSelector->GetSelection() != 0 )
301 m_DCodeSelector->SetSelection( 0 );
302
303 return;
304 }
305
306 // Build the aperture list of the current layer, and add it to the combo box:
307 wxArrayString dcode_list;
308 wxString msg;
309
310 double scale = 1.0;
311 wxString units;
312
313 switch( GetUserUnits() )
314 {
315 case EDA_UNITS::MM:
316 scale = gerbIUScale.IU_PER_MM;
317 units = wxT( "mm" );
318 break;
319
320 case EDA_UNITS::INCH:
321 scale = gerbIUScale.IU_PER_MILS * 1000;
322 units = wxT( "in" );
323 break;
324
325 case EDA_UNITS::MILS:
326 scale = gerbIUScale.IU_PER_MILS;
327 units = wxT( "mil" );
328 break;
329
330 default:
331 wxASSERT_MSG( false, wxT( "Invalid units" ) );
332 }
333
334 for( const auto& [_, dcode] : gerber->m_ApertureList )
335 {
336 wxCHECK2( dcode,continue );
337
338 if( !dcode->m_InUse && !dcode->m_Defined )
339 continue;
340
341 msg.Printf( wxT( "tool %d [%.3fx%.3f %s] %s" ),
342 dcode->m_Num_Dcode,
343 dcode->m_Size.x / scale, dcode->m_Size.y / scale,
344 units,
345 D_CODE::ShowApertureType( dcode->m_ApertType ) );
346
347 if( !dcode->m_AperFunction.IsEmpty() )
348 msg << wxT( ", " ) << dcode->m_AperFunction;
349
350 dcode_list.Add( msg );
351 }
352
353 m_DCodeSelector->AppendDCodeList( dcode_list );
354
355 if( dcode_list.size() > 1 )
356 {
357 wxSize size = m_DCodeSelector->GetBestSize();
358 size.x = std::max( size.x, 100 );
359 m_DCodeSelector->SetMinSize( size );
360 m_auimgr.Update();
361 }
362}
363
364
366{
367 m_SelComponentBox->Clear();
368
369 // Build the full list of component names from the partial lists stored in each file image
370 std::map<wxString, int> full_list;
371
372 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
373 {
374 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
375
376 if( gerber == nullptr ) // Graphic layer not yet used
377 continue;
378
379 full_list.insert( gerber->m_ComponentsList.begin(), gerber->m_ComponentsList.end() );
380 }
381
382 // Add an empty string to deselect net highlight
384
385 // Now copy the list to the choice box
386 for( const std::pair<const wxString, int>& entry : full_list )
387 m_SelComponentBox->Append( entry.first );
388
389 m_SelComponentBox->SetSelection( 0 );
390}
391
392
394{
395 m_SelNetnameBox->Clear();
396
397 // Build the full list of netnames from the partial lists stored in each file image
398 std::map<wxString, int> full_list;
399
400 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
401 {
402 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
403
404 if( gerber == nullptr ) // Graphic layer not yet used
405 continue;
406
407 full_list.insert( gerber->m_NetnamesList.begin(), gerber->m_NetnamesList.end() );
408 }
409
410 // Add an empty string to deselect net highlight
412
413 // Now copy the list to the choice box
414 for( const std::pair<const wxString, int>& entry : full_list )
415 m_SelNetnameBox->Append( UnescapeString( entry.first ) );
416
417 m_SelNetnameBox->SetSelection( 0 );
418}
419
420
422{
423 m_SelAperAttributesBox->Clear();
424
425 // Build the full list of netnames from the partial lists stored in each file image
426 std::map<wxString, int> full_list;
427
428 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
429 {
430 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
431
432 if( gerber == nullptr ) // Graphic layer not yet used
433 continue;
434
435 if( gerber->GetDcodesCount() == 0 )
436 continue;
437
438 for( const auto &[_, aperture] : gerber->m_ApertureList )
439 {
440 if( aperture == nullptr )
441 continue;
442
443 if( !aperture->m_InUse && !aperture->m_Defined )
444 continue;
445
446 if( !aperture->m_AperFunction.IsEmpty() )
447 full_list.insert( std::make_pair( aperture->m_AperFunction, 0 ) );
448 }
449 }
450
451 // Add an empty string to deselect net highlight
453
454 // Now copy the list to the choice box
455 for( const std::pair<const wxString, int>& entry : full_list )
456 m_SelAperAttributesBox->Append( entry.first );
457
458 m_SelAperAttributesBox->SetSelection( 0 );
459}
460
461
462void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
463{
464 if( !m_DCodeSelector )
465 return;
466
467 int layer = GetActiveLayer();
468 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
469 int selected = gerber ? gerber->m_Selected_Tool : 0;
470
471 aEvent.Enable( gerber != nullptr );
472
473 if( m_DCodeSelector->GetSelectedDCodeId() != selected )
474 {
475 m_DCodeSelector->SetDCodeSelection( selected );
476 // Be sure the selection can be made. If no, set to
477 // a correct value
478 if( gerber )
479 gerber->m_Selected_Tool = m_DCodeSelector->GetSelectedDCodeId();
480 }
481}
constexpr EDA_IU_SCALE gerbIUScale
Definition base_units.h:111
static TOOL_ACTION toggleGrid
Definition actions.h:197
static TOOL_ACTION zoomRedraw
Definition actions.h:131
static TOOL_ACTION millimetersUnits
Definition actions.h:205
static TOOL_ACTION cursorSmallCrosshairs
Definition actions.h:151
static TOOL_ACTION zoomOutCenter
Definition actions.h:135
static TOOL_ACTION togglePolarCoords
Definition actions.h:208
static TOOL_ACTION milsUnits
Definition actions.h:204
static TOOL_ACTION inchesUnits
Definition actions.h:203
static TOOL_ACTION highContrastMode
Definition actions.h:154
static TOOL_ACTION measureTool
Definition actions.h:251
static TOOL_ACTION selectionTool
Definition actions.h:250
static TOOL_ACTION zoomFitScreen
Definition actions.h:141
static TOOL_ACTION zoomTool
Definition actions.h:145
static TOOL_ACTION cursor45Crosshairs
Definition actions.h:153
static TOOL_ACTION print
Definition actions.h:64
static TOOL_ACTION zoomInCenter
Definition actions.h:134
static TOOL_ACTION cursorFullCrosshairs
Definition actions.h:152
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
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: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