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 .AppendAction( ACTIONS::inchesUnits )
59 .AppendAction( ACTIONS::milsUnits )
60 .AppendAction( ACTIONS::millimetersUnits )
61 .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Crosshair modes" ) )
64 .AddAction( ACTIONS::cursor45Crosshairs ) );
65
66 config.AppendSeparator()
71 .AppendAction( GERBVIEW_ACTIONS::dcodeDisplay );
72
73 config.AppendSeparator()
75 .AppendAction( GERBVIEW_ACTIONS::toggleXORMode )
76 .AppendAction( ACTIONS::highContrastMode )
77 .AppendAction( GERBVIEW_ACTIONS::flipGerberView );
78
79 config.AppendSeparator()
81 break;
82
87 .AppendAction( GERBVIEW_ACTIONS::openGerber )
88 .AppendAction( GERBVIEW_ACTIONS::openDrillFile );
89
90 config.AppendSeparator()
91 .AppendAction( ACTIONS::print );
92
93 config.AppendSeparator()
94 .AppendAction( ACTIONS::zoomRedraw )
95 .AppendAction( ACTIONS::zoomInCenter )
96 .AppendAction( ACTIONS::zoomOutCenter )
97 .AppendAction( ACTIONS::zoomFitScreen )
98 .AppendAction( ACTIONS::zoomTool );
99
100 config.AppendSeparator()
103 break;
104
107 .AppendSpacer( 5 )
109 .AppendSpacer( 5 )
111 .AppendSpacer( 5 )
113 .AppendSeparator()
115 .AppendSeparator()
116 .AppendControl( ACTION_TOOLBAR_CONTROLS::zoomSelect );
117 break;
118 }
119
120 // clang-format on
121 return config;
122}
123
124
126{
127 // Base class loads the default settings
129
130 // Register factories for the various toolbar controls
131 auto layerBoxFactory =
132 [this]( ACTION_TOOLBAR* aToolbar )
133 {
134 if( !m_SelLayerBox )
135 {
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 {
226 {
227 m_SelAperAttributesBox = new wxChoice( aToolbar,
229 }
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 {
252 m_DCodeSelector = new DCODE_SELECTION_BOX( aToolbar,
254 wxDefaultPosition, wxSize( 150, -1 ) );
255 }
256
257 if( !m_dcodeText )
258 m_dcodeText = new wxStaticText( aToolbar, wxID_ANY, _( "DCode:" ) );
259
260 m_dcodeText->SetLabel( _( "DCode:" ) );
261
263
264 aToolbar->Add( m_dcodeText );
265 aToolbar->Add( m_DCodeSelector );
266 };
267
269}
270
271ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::textInfo( "control.TextInfo", _( "Text info entry" ),
272 _( "Text info entry" ) );
274 _( "Component highlight" ),
275 _( "Highlight items belonging to this component" ) );
276ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::netHighlight( "control.NetHighlight", _( "Net highlight" ),
277 _( "Highlight items belonging to this net" ) );
278ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::appertureHighlight( "control.AppertureHighlight", _( "Aperture highlight" ),
279 _( "Highlight items with this aperture attribute" ));
280ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::dcodeSelector( "control.GerberDcodeSelector", _( "DCode Selector" ),
281 _( "Select all items with the selected DCode" ) );
282
283
284#define NO_SELECTION_STRING _("<No selection>")
285
286
288{
289 m_DCodeSelector->Clear();
290
291 // Add an empty string to deselect net highlight
293
294 int layer = GetActiveLayer();
295 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
296
297 if( !gerber || gerber->GetDcodesCount() == 0 )
298 {
299 if( m_DCodeSelector->GetSelection() != 0 )
300 m_DCodeSelector->SetSelection( 0 );
301
302 return;
303 }
304
305 // Build the aperture list of the current layer, and add it to the combo box:
306 wxArrayString dcode_list;
307 wxString msg;
308
309 double scale = 1.0;
310 wxString units;
311
312 switch( GetUserUnits() )
313 {
314 case EDA_UNITS::MM:
315 scale = gerbIUScale.IU_PER_MM;
316 units = wxT( "mm" );
317 break;
318
319 case EDA_UNITS::INCH:
320 scale = gerbIUScale.IU_PER_MILS * 1000;
321 units = wxT( "in" );
322 break;
323
324 case EDA_UNITS::MILS:
325 scale = gerbIUScale.IU_PER_MILS;
326 units = wxT( "mil" );
327 break;
328
329 default:
330 wxASSERT_MSG( false, wxT( "Invalid units" ) );
331 }
332
333 for( const auto& [_, dcode] : gerber->m_ApertureList )
334 {
335 wxCHECK2( dcode,continue );
336
337 if( !dcode->m_InUse && !dcode->m_Defined )
338 continue;
339
340 msg.Printf( wxT( "tool %d [%.3fx%.3f %s] %s" ),
341 dcode->m_Num_Dcode,
342 dcode->m_Size.x / scale, dcode->m_Size.y / scale,
343 units,
344 D_CODE::ShowApertureType( dcode->m_ApertType ) );
345
346 if( !dcode->m_AperFunction.IsEmpty() )
347 msg << wxT( ", " ) << dcode->m_AperFunction;
348
349 dcode_list.Add( msg );
350 }
351
352 m_DCodeSelector->AppendDCodeList( dcode_list );
353
354 if( dcode_list.size() > 1 )
355 {
356 wxSize size = m_DCodeSelector->GetBestSize();
357 size.x = std::max( size.x, 100 );
358 m_DCodeSelector->SetMinSize( size );
359 m_auimgr.Update();
360 }
361}
362
363
365{
366 m_SelComponentBox->Clear();
367
368 // Build the full list of component names from the partial lists stored in each file image
369 std::map<wxString, int> full_list;
370
371 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
372 {
373 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
374
375 if( gerber == nullptr ) // Graphic layer not yet used
376 continue;
377
378 full_list.insert( gerber->m_ComponentsList.begin(), gerber->m_ComponentsList.end() );
379 }
380
381 // Add an empty string to deselect net highlight
383
384 // Now copy the list to the choice box
385 for( const std::pair<const wxString, int>& entry : full_list )
386 m_SelComponentBox->Append( entry.first );
387
388 m_SelComponentBox->SetSelection( 0 );
389}
390
391
393{
394 m_SelNetnameBox->Clear();
395
396 // Build the full list of netnames from the partial lists stored in each file image
397 std::map<wxString, int> full_list;
398
399 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
400 {
401 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
402
403 if( gerber == nullptr ) // Graphic layer not yet used
404 continue;
405
406 full_list.insert( gerber->m_NetnamesList.begin(), gerber->m_NetnamesList.end() );
407 }
408
409 // Add an empty string to deselect net highlight
411
412 // Now copy the list to the choice box
413 for( const std::pair<const wxString, int>& entry : full_list )
414 m_SelNetnameBox->Append( UnescapeString( entry.first ) );
415
416 m_SelNetnameBox->SetSelection( 0 );
417}
418
419
421{
422 m_SelAperAttributesBox->Clear();
423
424 // Build the full list of netnames from the partial lists stored in each file image
425 std::map<wxString, int> full_list;
426
427 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
428 {
429 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
430
431 if( gerber == nullptr ) // Graphic layer not yet used
432 continue;
433
434 if( gerber->GetDcodesCount() == 0 )
435 continue;
436
437 for( const auto &[_, aperture] : gerber->m_ApertureList )
438 {
439 if( aperture == nullptr )
440 continue;
441
442 if( !aperture->m_InUse && !aperture->m_Defined )
443 continue;
444
445 if( !aperture->m_AperFunction.IsEmpty() )
446 full_list.insert( std::make_pair( aperture->m_AperFunction, 0 ) );
447 }
448 }
449
450 // Add an empty string to deselect net highlight
452
453 // Now copy the list to the choice box
454 for( const std::pair<const wxString, int>& entry : full_list )
455 m_SelAperAttributesBox->Append( entry.first );
456
457 m_SelAperAttributesBox->SetSelection( 0 );
458}
459
460
461void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
462{
463 if( !m_DCodeSelector )
464 return;
465
466 int layer = GetActiveLayer();
467 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
468 int selected = gerber ? gerber->m_Selected_Tool : 0;
469
470 aEvent.Enable( gerber != nullptr );
471
472 if( m_DCodeSelector->GetSelectedDCodeId() != selected )
473 {
474 m_DCodeSelector->SetDCodeSelection( selected );
475 // Be sure the selection can be made. If no, set to
476 // a correct value
477 if( gerber )
478 gerber->m_Selected_Tool = m_DCodeSelector->GetSelectedDCodeId();
479 }
480}
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