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 (C) 1992-2023 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
38
40{
41 // Note:
42 // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
43 // all wxAuiToolBarItems.
44 // However the wxAuiToolBarItems are not the owners of controls managed by
45 // them ( m_TextInfo and m_SelLayerBox ), and therefore do not delete them
46 // So we do not recreate them after clearing the tools.
47
48 if( m_mainToolBar )
49 {
51 }
52 else
53 {
54 m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
55 KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT |
56 wxAUI_TB_HORIZONTAL );
58 }
59
60 // Set up toolbar
66
69
76
77
79
80 if( !m_SelLayerBox )
81 {
84 wxDefaultPosition, wxDefaultSize, 0, nullptr );
85 }
86
88 m_mainToolBar->AddControl( m_SelLayerBox );
89
90 if( !m_TextInfo )
91 {
92 m_TextInfo = new wxTextCtrl( m_mainToolBar, ID_TOOLBARH_GERBER_DATA_TEXT_BOX, wxEmptyString,
93 wxDefaultPosition, wxDefaultSize, wxTE_READONLY );
94 }
95
96 m_mainToolBar->AddControl( m_TextInfo );
97
100
101 // after adding the buttons to the toolbar, must call Realize() to reflect the changes
103}
104
105
107{
108 wxWindowUpdateLocker dummy( this );
109
111 {
113 }
114 else
115 {
116 m_auxiliaryToolBar = new ACTION_TOOLBAR( this, ID_AUX_TOOLBAR, wxDefaultPosition,
117 wxDefaultSize,
118 KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
120 }
121
122 // Creates box to display and choose components:
123 // (note, when the m_auxiliaryToolBar is recreated, tools are deleted, but controls
124 // are not deleted: they are just no longer managed by the toolbar
125 if( !m_SelComponentBox )
127
128 if( !m_cmpText )
129 m_cmpText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Cmp:" ) + wxS( " " ) );
130
131 m_SelComponentBox->SetToolTip( _("Highlight items belonging to this component") );
132 m_cmpText->SetLabel( _( "Cmp:" ) + wxS( " " ) ); // can change when changing the language
133 m_auxiliaryToolBar->AddControl( m_cmpText );
135 m_auxiliaryToolBar->AddSpacer( 5 );
136
137 // Creates choice box to display net names and highlight selected:
138 if( !m_SelNetnameBox )
140
141 if( !m_netText )
142 m_netText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Net:" ) );
143
144 m_SelNetnameBox->SetToolTip( _("Highlight items belonging to this net") );
145 m_netText->SetLabel( _( "Net:" ) ); // can change when changing the language
146 m_auxiliaryToolBar->AddControl( m_netText );
147 m_auxiliaryToolBar->AddControl( m_SelNetnameBox );
148 m_auxiliaryToolBar->AddSpacer( 5 );
149
150 // Creates choice box to display aperture attributes and highlight selected:
152 {
155 }
156
157 if( !m_apertText )
158 m_apertText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Attr:" ) );
159
160 m_SelAperAttributesBox->SetToolTip( _( "Highlight items with this aperture attribute" ) );
161 m_apertText->SetLabel( _( "Attr:" ) ); // can change when changing the language
162 m_auxiliaryToolBar->AddControl( m_apertText );
164 m_auxiliaryToolBar->AddSpacer( 5 );
165
166 if( !m_DCodeSelector )
167 {
170 wxDefaultPosition, wxSize( 150, -1 ) );
171 }
172
173 if( !m_dcodeText )
174 m_dcodeText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "DCode:" ) );
175
176 m_dcodeText->SetLabel( _( "DCode:" ) );
177 m_auxiliaryToolBar->AddControl( m_dcodeText );
178 m_auxiliaryToolBar->AddControl( m_DCodeSelector );
179
180 if( !m_gridSelectBox )
181 {
182 m_gridSelectBox = new wxChoice( m_auxiliaryToolBar, ID_ON_GRID_SELECT, wxDefaultPosition,
183 wxDefaultSize, 0, nullptr );
184 }
185
187 m_auxiliaryToolBar->AddControl( m_gridSelectBox );
188
189 if( !m_zoomSelectBox )
190 {
191 m_zoomSelectBox = new wxChoice( m_auxiliaryToolBar, ID_ON_ZOOM_SELECT, wxDefaultPosition,
192 wxDefaultSize, 0, nullptr );
193 }
194
196 m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
197
204
205 // Go through and ensure the comboboxes are the correct size, since the strings in the
206 // box could have changed widths.
212
213 // after adding the buttons to the toolbar, must call Realize()
215}
216
217
219{
220 // This toolbar isn't used currently
221}
222
223
225{
226 if( m_optionsToolBar )
227 {
229 }
230 else
231 {
232 m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition,
233 wxDefaultSize,
234 KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
236 }
237
238 // TODO: these can be moved to the 'proper' vertical toolbar if and when there are
239 // actual tools to put there. That, or I'll get around to implementing configurable
240 // toolbars.
243
251
263
266
268}
269
270
272{
273 if( m_mainToolBar )
274 {
275 // Update the item widths
278 }
279
281 {
282 // Update the item widths
288 }
289}
290
291
292#define NO_SELECTION_STRING _("<No selection>")
293
294
296{
297 m_DCodeSelector->Clear();
298
299 // Add an empty string to deselect net highlight
301
302 int layer = GetActiveLayer();
303 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
304
305 if( !gerber || gerber->GetDcodesCount() == 0 )
306 {
307 if( m_DCodeSelector->GetSelection() != 0 )
308 m_DCodeSelector->SetSelection( 0 );
309
310 return;
311 }
312
313 // Build the aperture list of the current layer, and add it to the combo box:
314 wxArrayString dcode_list;
315 wxString msg;
316
317 double scale = 1.0;
318 wxString units;
319
320 switch( GetUserUnits() )
321 {
322 case EDA_UNITS::MILLIMETRES:
324 units = wxT( "mm" );
325 break;
326
327 case EDA_UNITS::INCHES:
329 units = wxT( "in" );
330 break;
331
332 case EDA_UNITS::MILS:
334 units = wxT( "mil" );
335 break;
336
337 default:
338 wxASSERT_MSG( false, wxT( "Invalid units" ) );
339 }
340
341 for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
342 {
343 D_CODE* dcode = gerber->GetDCODE( ii + FIRST_DCODE );
344
345 if( dcode == nullptr )
346 continue;
347
348 if( !dcode->m_InUse && !dcode->m_Defined )
349 continue;
350
351 msg.Printf( wxT( "tool %d [%.3fx%.3f %s] %s" ),
352 dcode->m_Num_Dcode,
353 dcode->m_Size.x / scale, dcode->m_Size.y / scale,
354 units,
356
357 if( !dcode->m_AperFunction.IsEmpty() )
358 msg << wxT( ", " ) << dcode->m_AperFunction;
359
360 dcode_list.Add( msg );
361 }
362
363 m_DCodeSelector->AppendDCodeList( dcode_list );
364
365 if( dcode_list.size() > 1 )
366 {
367 wxSize size = m_DCodeSelector->GetBestSize();
368 size.x = std::max( size.x, 100 );
369 m_DCodeSelector->SetMinSize( size );
370 m_auimgr.Update();
371 }
372}
373
374
376{
377 m_SelComponentBox->Clear();
378
379 // Build the full list of component names from the partial lists stored in each file image
380 std::map<wxString, int> full_list;
381
382 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
383 {
384 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
385
386 if( gerber == nullptr ) // Graphic layer not yet used
387 continue;
388
389 full_list.insert( gerber->m_ComponentsList.begin(), gerber->m_ComponentsList.end() );
390 }
391
392 // Add an empty string to deselect net highlight
394
395 // Now copy the list to the choice box
396 for( const std::pair<const wxString, int>& entry : full_list )
397 m_SelComponentBox->Append( entry.first );
398
399 m_SelComponentBox->SetSelection( 0 );
400}
401
402
404{
405 m_SelNetnameBox->Clear();
406
407 // Build the full list of netnames from the partial lists stored in each file image
408 std::map<wxString, int> full_list;
409
410 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
411 {
412 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
413
414 if( gerber == nullptr ) // Graphic layer not yet used
415 continue;
416
417 full_list.insert( gerber->m_NetnamesList.begin(), gerber->m_NetnamesList.end() );
418 }
419
420 // Add an empty string to deselect net highlight
422
423 // Now copy the list to the choice box
424 for( const std::pair<const wxString, int>& entry : full_list )
425 m_SelNetnameBox->Append( UnescapeString( entry.first ) );
426
427 m_SelNetnameBox->SetSelection( 0 );
428}
429
430
432{
433 m_SelAperAttributesBox->Clear();
434
435 // Build the full list of netnames from the partial lists stored in each file image
436 std::map<wxString, int> full_list;
437
438 for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
439 {
440 GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
441
442 if( gerber == nullptr ) // Graphic layer not yet used
443 continue;
444
445 if( gerber->GetDcodesCount() == 0 )
446 continue;
447
448 for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
449 {
450 D_CODE* aperture = gerber->GetDCODE( ii + FIRST_DCODE );
451
452 if( aperture == nullptr )
453 continue;
454
455 if( !aperture->m_InUse && !aperture->m_Defined )
456 continue;
457
458 if( !aperture->m_AperFunction.IsEmpty() )
459 full_list.insert( std::make_pair( aperture->m_AperFunction, 0 ) );
460 }
461 }
462
463 // Add an empty string to deselect net highlight
465
466 // Now copy the list to the choice box
467 for( const std::pair<const wxString, int>& entry : full_list )
468 m_SelAperAttributesBox->Append( entry.first );
469
470 m_SelAperAttributesBox->SetSelection( 0 );
471}
472
473
474void GERBVIEW_FRAME::OnUpdateDrawMode( wxUpdateUIEvent& aEvent )
475{
476 switch( aEvent.GetId() )
477 {
478 case ID_TB_OPTIONS_SHOW_GBR_MODE_0: aEvent.Check( GetDisplayMode() == 0 ); break;
479 case ID_TB_OPTIONS_SHOW_GBR_MODE_1: aEvent.Check( GetDisplayMode() == 1 ); break;
480 case ID_TB_OPTIONS_SHOW_GBR_MODE_2: aEvent.Check( GetDisplayMode() == 2 ); break;
481 default: break;
482 }
483}
484
485
486void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
487{
488 if( !m_DCodeSelector )
489 return;
490
491 int layer = GetActiveLayer();
492 GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
493 int selected = gerber ? gerber->m_Selected_Tool : 0;
494
495 aEvent.Enable( gerber != nullptr );
496
497 if( m_DCodeSelector->GetSelectedDCodeId() != selected )
498 {
500 // Be sure the selection can be made. If no, set to
501 // a correct value
502 if( gerber )
504 }
505}
506
507
508void GERBVIEW_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
509{
510 if( m_SelLayerBox->GetCount() )
511 {
512 if( m_SelLayerBox->GetSelection() != GetActiveLayer() )
513 m_SelLayerBox->SetSelection( GetActiveLayer() );
514 }
515}
516
constexpr EDA_IU_SCALE gerbIUScale
Definition: base_units.h:108
static TOOL_ACTION toggleGrid
Definition: actions.h:172
static TOOL_ACTION zoomRedraw
Definition: actions.h:114
static TOOL_ACTION millimetersUnits
Definition: actions.h:180
static TOOL_ACTION zoomOutCenter
Definition: actions.h:118
static TOOL_ACTION togglePolarCoords
Definition: actions.h:183
static TOOL_ACTION milsUnits
Definition: actions.h:179
static TOOL_ACTION inchesUnits
Definition: actions.h:178
static TOOL_ACTION highContrastMode
Definition: actions.h:133
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:132
static TOOL_ACTION measureTool
Definition: actions.h:188
static TOOL_ACTION selectionTool
Definition: actions.h:187
static TOOL_ACTION zoomFitScreen
Definition: actions.h:124
static TOOL_ACTION zoomTool
Definition: actions.h:127
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION zoomInCenter
Definition: actions.h:117
Define the structure of a toolbar with buttons that invoke ACTIONs.
static constexpr bool TOGGLE
static constexpr bool CANCEL
void SetAuiManager(wxAuiManager *aManager)
Set the AUI manager that this toolbar belongs to.
void UpdateControlWidth(int aID)
Update the toolbar item width of a control using its best size.
void AddScaledSeparator(wxWindow *aWindow)
Add a separator that introduces space on either side to not squash the tools when scaled.
bool KiRealize()
Use this over Realize() to avoid a rendering glitch with fixed orientation toolbars.
void ClearToolbar()
Clear the toolbar and remove all associated menus.
void Add(const TOOL_ACTION &aAction, bool aIsToggleEntry=false, bool aIsCancellable=false)
Add a TOOL_ACTION-based button to the toolbar.
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
static constexpr int KICAD_AUI_TB_STYLE
< Default style flags used for wxAUI toolbars.
wxAuiManager m_auimgr
wxChoice * m_gridSelectBox
ACTION_TOOLBAR * m_optionsToolBar
void UpdateGridSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
void UpdateZoomSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
ACTION_TOOLBAR * m_mainToolBar
wxChoice * m_zoomSelectBox
ACTION_TOOLBAR * m_auxiliaryToolBar
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 toggleDiffMode
static TOOL_ACTION clearAllLayers
static TOOL_ACTION flipGerberView
static TOOL_ACTION openAutodetected
static TOOL_ACTION reloadAllLayers
static TOOL_ACTION linesDisplayOutlines
static TOOL_ACTION openDrillFile
static TOOL_ACTION polygonsDisplayOutlines
void OnUpdateSelectDCode(wxUpdateUIEvent &aEvent)
void OnUpdateDrawMode(wxUpdateUIEvent &aEvent)
wxStaticText * m_dcodeText
wxChoice * m_SelAperAttributesBox
void OnUpdateLayerSelectBox(wxUpdateUIEvent &aEvent)
void ReCreateHToolbar() override
GBR_LAYER_BOX_SELECTOR * m_SelLayerBox
void UpdateToolbarControlSizes() override
Update the sizes of any controls in the toolbars of the frame.
wxStaticText * m_cmpText
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
void ReCreateAuxiliaryToolbar() override
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()
void ReCreateOptToolbar() override
Create or update the left vertical toolbar (option toolbar)
wxStaticText * m_apertText
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
void updateComponentListSelectBox()
void updateNetnameListSelectBox()
void ReCreateVToolbar() override
Create or update the right vertical toolbar.
EDA_UNITS GetUserUnits() const
#define FIRST_DCODE
Definition: dcode.h:69
#define TOOLS_MAX_COUNT
Definition: dcode.h:71
#define _(s)
GERBVIEW_FRAME::OnZipFileHistory ID_TB_OPTIONS_SHOW_GBR_MODE_2
@ 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
@ ID_TB_OPTIONS_SHOW_GBR_MODE_1
Definition: gerbview_id.h:49
@ ID_TB_OPTIONS_SHOW_GBR_MODE_0
Definition: gerbview_id.h:48
@ ID_ON_GRID_SELECT
Definition: id.h:145
@ ID_OPT_TOOLBAR
Definition: id.h:102
@ ID_ON_ZOOM_SELECT
Definition: id.h:143
@ ID_AUX_TOOLBAR
Definition: id.h:103
@ ID_H_TOOLBAR
Definition: id.h:100
const int scale
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
const double IU_PER_MM
Definition: base_units.h:77
const double IU_PER_MILS
Definition: base_units.h:78
#define NO_SELECTION_STRING