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
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( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
331 {
332 D_CODE* dcode = gerber->GetDCODE( ii + FIRST_DCODE );
333
334 if( dcode == nullptr )
335 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,
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( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
438 {
439 D_CODE* aperture = gerber->GetDCODE( ii + FIRST_DCODE );
440
441 if( aperture == nullptr )
442 continue;
443
444 if( !aperture->m_InUse && !aperture->m_Defined )
445 continue;
446
447 if( !aperture->m_AperFunction.IsEmpty() )
448 full_list.insert( std::make_pair( aperture->m_AperFunction, 0 ) );
449 }
450 }
451
452 // Add an empty string to deselect net highlight
454
455 // Now copy the list to the choice box
456 for( const std::pair<const wxString, int>& entry : full_list )
457 m_SelAperAttributesBox->Append( entry.first );
458
459 m_SelAperAttributesBox->SetSelection( 0 );
460}
461
462
463void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
464{
465 if( !m_DCodeSelector )
466 return;
467
468 int layer = GetActiveLayer();
469 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
470 int selected = gerber ? gerber->m_Selected_Tool : 0;
471
472 aEvent.Enable( gerber != nullptr );
473
474 if( m_DCodeSelector->GetSelectedDCodeId() != selected )
475 {
477 // Be sure the selection can be made. If no, set to
478 // a correct value
479 if( gerber )
481 }
482}
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)
A gerber DCODE (also called Aperture) definition.
Definition: dcode.h:80
wxString m_AperFunction
the aperture attribute (created by a TA.AperFunction command).
Definition: dcode.h:203
int m_Num_Dcode
D code value ( >= 10 )
Definition: dcode.h:193
static const wxChar * ShowApertureType(APERTURE_T aType)
Return a character string telling what type of aperture type aType is.
Definition: dcode.cpp:86
VECTOR2I m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:190
APERTURE_T m_ApertType
Aperture type ( Line, rectangle, circle, oval poly, macro )
Definition: dcode.h:191
bool m_Defined
false if the aperture is not defined in the header
Definition: dcode.h:202
bool m_InUse
false if the aperture (previously defined) is not used to draw something
Definition: dcode.h:200
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
D_CODE * GetDCODE(int aDCODE) const
Return a pointer to the D_CODE within this GERBER for the given aDCODE.
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 FIRST_DCODE
Definition: dcode.h:69
#define TOOLS_MAX_COUNT
Definition: dcode.h:71
#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