KiCad PCB EDA Suite
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 <stambaughw@gmail.com>
6  * Copyright (C) 1992-2021 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>
30 #include <gerber_file_image_list.h>
31 #include <string_utils.h>
32 #include <tool/actions.h>
33 #include <tool/action_toolbar.h>
34 #include <tools/gerbview_actions.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
65 
68 
75 
76 
78 
79  if( !m_SelLayerBox )
82  wxDefaultPosition, wxDefaultSize, 0, nullptr );
83 
85  m_mainToolBar->AddControl( m_SelLayerBox );
86 
87  if( !m_TextInfo )
88  m_TextInfo = new wxTextCtrl( m_mainToolBar, ID_TOOLBARH_GERBER_DATA_TEXT_BOX, wxEmptyString, wxDefaultPosition,
89  wxDefaultSize, wxTE_READONLY );
90 
91  m_mainToolBar->AddControl( m_TextInfo );
92 
95 
96  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
98 }
99 
100 
102 {
103  wxWindowUpdateLocker dummy( this );
104 
105  if( m_auxiliaryToolBar )
106  {
108  }
109  else
110  {
112  wxDefaultPosition, wxDefaultSize,
113  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
115  }
116 
117  // Creates box to display and choose components:
118  // (note, when the m_auxiliaryToolBar is recreated, tools are deleted, but controls
119  // are not deleted: they are just no longer managed by the toolbar
120  if( !m_SelComponentBox )
121  m_SelComponentBox = new wxChoice( m_auxiliaryToolBar,
123 
124  if( !m_cmpText )
125  m_cmpText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Cmp:" ) + wxS( " " ) );
126 
127  m_SelComponentBox->SetToolTip( _("Highlight items belonging to this component") );
128  m_cmpText->SetLabel( _( "Cmp:" ) + wxS( " " ) ); // can change when changing the language
129  m_auxiliaryToolBar->AddControl( m_cmpText );
130  m_auxiliaryToolBar->AddControl( m_SelComponentBox );
131  m_auxiliaryToolBar->AddSpacer( 5 );
132 
133  // Creates choice box to display net names and highlight selected:
134  if( !m_SelNetnameBox )
135  m_SelNetnameBox = new wxChoice( m_auxiliaryToolBar,
137 
138  if( !m_netText )
139  m_netText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Net:" ) );
140 
141  m_SelNetnameBox->SetToolTip( _("Highlight items belonging to this net") );
142  m_netText->SetLabel( _( "Net:" ) ); // can change when changing the language
143  m_auxiliaryToolBar->AddControl( m_netText );
144  m_auxiliaryToolBar->AddControl( m_SelNetnameBox );
145  m_auxiliaryToolBar->AddSpacer( 5 );
146 
147  // Creates choice box to display aperture attributes and highlight selected:
151 
152  if( !m_apertText )
153  m_apertText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Attr:" ) );
154 
155  m_SelAperAttributesBox->SetToolTip( _( "Highlight items with this aperture attribute" ) );
156  m_apertText->SetLabel( _( "Attr:" ) ); // can change when changing the language
157  m_auxiliaryToolBar->AddControl( m_apertText );
159  m_auxiliaryToolBar->AddSpacer( 5 );
160 
161  if( !m_DCodeSelector )
164  wxDefaultPosition, wxSize( 150, -1 ) );
165 
166  if( !m_dcodeText )
167  m_dcodeText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "DCode:" ) );
168 
169  m_dcodeText->SetLabel( _( "DCode:" ) );
170  m_auxiliaryToolBar->AddControl( m_dcodeText );
171  m_auxiliaryToolBar->AddControl( m_DCodeSelector );
172 
173  if( !m_gridSelectBox )
174  {
176  wxDefaultPosition, wxDefaultSize, 0, nullptr );
177  }
178 
180  m_auxiliaryToolBar->AddControl( m_gridSelectBox );
181 
182  if( !m_zoomSelectBox )
183  {
185  wxDefaultPosition, wxDefaultSize, 0, nullptr );
186  }
187 
189  m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
190 
197 
198  // Go through and ensure the comboboxes are the correct size, since the strings in the
199  // box could have changed widths.
205 
206  // after adding the buttons to the toolbar, must call Realize()
208 }
209 
210 
212 {
213  // This toolbar isn't used currently
214 }
215 
216 
218 {
219  if( m_optionsToolBar )
220  {
222  }
223  else
224  {
225  m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition,
226  wxDefaultSize,
227  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
229  }
230 
231  // TODO: these can be moved to the 'proper' vertical toolbar if and when there are
232  // actual tools to put there. That, or I'll get around to implementing configurable
233  // toolbars.
236 
244 
254 
257 
259 }
260 
261 
263 {
264  if( m_mainToolBar )
265  {
266  // Update the item widths
269  }
270 
271  if( m_auxiliaryToolBar )
272  {
273  // Update the item widths
279  }
280 }
281 
282 
283 #define NO_SELECTION_STRING _("<No selection>")
284 
285 
287 {
288  m_DCodeSelector->Clear();
289 
290  // Add an empty string to deselect net highlight
292 
293  int layer = GetActiveLayer();
294  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
295 
296  if( !gerber || gerber->GetDcodesCount() == 0 )
297  {
298  if( m_DCodeSelector->GetSelection() != 0 )
299  m_DCodeSelector->SetSelection( 0 );
300 
301  return;
302  }
303 
304  // Build the aperture list of the current layer, and add it to the combo box:
305  wxArrayString dcode_list;
306  wxString msg;
307 
308  double scale = 1.0;
309  wxString units;
310 
311  switch( GetUserUnits() )
312  {
314  scale = IU_PER_MM;
315  units = "mm";
316  break;
317 
318  case EDA_UNITS::INCHES:
319  scale = IU_PER_MILS * 1000;
320  units = "in";
321  break;
322 
323  case EDA_UNITS::MILS:
324  scale = IU_PER_MILS;
325  units = "mil";
326  break;
327 
328  default:
329  wxASSERT_MSG( false, "Invalid units" );
330  }
331 
332  for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
333  {
334  D_CODE* dcode = gerber->GetDCODE( ii + FIRST_DCODE );
335 
336  if( dcode == nullptr )
337  continue;
338 
339  if( !dcode->m_InUse && !dcode->m_Defined )
340  continue;
341 
342  msg.Printf( "tool %d [%.3fx%.3f %s] %s",
343  dcode->m_Num_Dcode,
344  dcode->m_Size.x / scale, dcode->m_Size.y / scale,
345  units,
347  );
348  if( !dcode->m_AperFunction.IsEmpty() )
349  msg << ", " << dcode->m_AperFunction;
350 
351  dcode_list.Add( msg );
352  }
353 
354  m_DCodeSelector->AppendDCodeList( dcode_list );
355 
356  if( dcode_list.size() > 1 )
357  {
358  wxSize size = m_DCodeSelector->GetBestSize();
359  size.x = std::max( size.x, 100 );
360  m_DCodeSelector->SetMinSize( size );
361  m_auimgr.Update();
362  }
363 }
364 
365 
367 {
368  m_SelComponentBox->Clear();
369 
370  // Build the full list of component names from the partial lists stored in each file image
371  std::map<wxString, int> full_list;
372 
373  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
374  {
375  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
376 
377  if( gerber == nullptr ) // Graphic layer not yet used
378  continue;
379 
380  full_list.insert( gerber->m_ComponentsList.begin(), gerber->m_ComponentsList.end() );
381  }
382 
383  // Add an empty string to deselect net highlight
385 
386  // Now copy the list to the choice box
387  for( auto& ii : full_list )
388  m_SelComponentBox->Append( ii.first );
389 
390  m_SelComponentBox->SetSelection( 0 );
391 }
392 
393 
395 {
396  m_SelNetnameBox->Clear();
397 
398  // Build the full list of netnames from the partial lists stored in each file image
399  std::map<wxString, int> full_list;
400 
401  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
402  {
403  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
404 
405  if( gerber == nullptr ) // Graphic layer not yet used
406  continue;
407 
408  full_list.insert( gerber->m_NetnamesList.begin(), gerber->m_NetnamesList.end() );
409  }
410 
411  // Add an empty string to deselect net highlight
413 
414  // Now copy the list to the choice box
415  for( auto& ii : full_list )
416  m_SelNetnameBox->Append( UnescapeString( ii.first ) );
417 
418  m_SelNetnameBox->SetSelection( 0 );
419 }
420 
421 
423 {
424  m_SelAperAttributesBox->Clear();
425 
426  // Build the full list of netnames from the partial lists stored in each file image
427  std::map<wxString, int> full_list;
428 
429  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
430  {
431  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
432 
433  if( gerber == nullptr ) // Graphic layer not yet used
434  continue;
435 
436  if( gerber->GetDcodesCount() == 0 )
437  continue;
438 
439  for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
440  {
441  D_CODE* aperture = gerber->GetDCODE( ii + FIRST_DCODE );
442 
443  if( aperture == nullptr )
444  continue;
445 
446  if( !aperture->m_InUse && !aperture->m_Defined )
447  continue;
448 
449  if( !aperture->m_AperFunction.IsEmpty() )
450  full_list.insert( std::make_pair( aperture->m_AperFunction, 0 ) );
451  }
452  }
453 
454  // Add an empty string to deselect net highlight
456 
457  // Now copy the list to the choice box
458  for( auto ii = full_list.begin(); ii != full_list.end(); ++ii )
459  {
460  m_SelAperAttributesBox->Append( ii->first );
461  }
462 
463  m_SelAperAttributesBox->SetSelection( 0 );
464 }
465 
466 
467 void GERBVIEW_FRAME::OnUpdateDrawMode( wxUpdateUIEvent& aEvent )
468 {
469  switch( aEvent.GetId() )
470  {
472  aEvent.Check( GetDisplayMode() == 0 );
473  break;
474 
476  aEvent.Check( GetDisplayMode() == 1 );
477  break;
478 
480  aEvent.Check( GetDisplayMode() == 2 );
481  break;
482 
483  default:
484  break;
485  }
486 }
487 
488 
489 void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
490 {
491  if( !m_DCodeSelector )
492  return;
493 
494  int layer = GetActiveLayer();
495  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
496  int selected = ( gerber ) ? gerber->m_Selected_Tool : 0;
497 
498  aEvent.Enable( gerber != nullptr );
499 
500  if( m_DCodeSelector->GetSelectedDCodeId() != selected )
501  {
502  m_DCodeSelector->SetDCodeSelection( selected );
503  // Be sure the selection can be made. If no, set to
504  // a correct value
505  if( gerber )
507  }
508 }
509 
510 
511 void GERBVIEW_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
512 {
513  if( m_SelLayerBox->GetSelection() != GetActiveLayer() )
514  m_SelLayerBox->SetSelection( GetActiveLayer() );
515 }
516 
Define the structure of a toolbar with buttons that invoke ACTIONs.
static TOOL_ACTION openDrillFile
static TOOL_ACTION zoomInCenter
Definition: actions.h:93
void OnUpdateSelectDCode(wxUpdateUIEvent &aEvent)
static TOOL_ACTION openGerber
ACTION_TOOLBAR * m_auxiliaryToolBar
wxSize m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:188
ACTION_TOOLBAR * m_optionsToolBar
static constexpr bool TOGGLE
static constexpr double IU_PER_MM
Mock up a conversion function.
bool m_InUse
false if the aperture (previously defined) is not used to draw something
Definition: dcode.h:197
static TOOL_ACTION zoomTool
Definition: actions.h:99
APERTURE_T m_Shape
shape ( Line, rectangle, circle , oval .. )
Definition: dcode.h:189
void AddScaledSeparator(wxWindow *aWindow)
Add a separator that introduces space on either side to not squash the tools when scaled.
void Add(const TOOL_ACTION &aAction, bool aIsToggleEntry=false, bool aIsCancellable=false)
Add a TOOL_ACTION-based button to the toolbar.
static TOOL_ACTION clearAllLayers
D_CODE * GetDCODE(int aDCODE) const
Return a pointer to the D_CODE within this GERBER for the given aDCODE.
Hold the image data and parameters for one gerber file and layer parameters.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:96
static TOOL_ACTION millimetersUnits
Definition: actions.h:146
GERBVIEW_FRAME::OnZipFileHistory ID_TB_OPTIONS_SHOW_GBR_MODE_2
GBR_LAYER_BOX_SELECTOR * m_SelLayerBox
void SetDCodeSelection(int aDCodeId)
void SetAuiManager(wxAuiManager *aManager)
Set the AUI manager that this toolbar belongs to.
void UpdateZoomSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
void OnUpdateLayerSelectBox(wxUpdateUIEvent &aEvent)
static TOOL_ACTION toggleLayerManager
void updateNetnameListSelectBox()
wxAuiManager m_auimgr
ACTION_TOOLBAR * m_mainToolBar
static TOOL_ACTION print
Definition: actions.h:57
wxChoice * m_gridSelectBox
bool KiRealize()
Use this over Realize() to avoid a rendering glitch with fixed orientation toolbars.
static TOOL_ACTION dcodeDisplay
static TOOL_ACTION negativeObjectDisplay
static TOOL_ACTION zoomOutCenter
Definition: actions.h:94
wxChoice * m_SelNetnameBox
void UpdateToolbarControlSizes() override
Update the sizes of any controls in the toolbars of the frame.
static TOOL_ACTION toggleDiffMode
void ReCreateHToolbar() override
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
void updateComponentListSelectBox()
void UpdateGridSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
static TOOL_ACTION measureTool
Definition: actions.h:154
bool m_Defined
false if the aperture is not defined in the header
Definition: dcode.h:199
static TOOL_ACTION flipGerberView
static constexpr bool CANCEL
void ReCreateAuxiliaryToolbar() override
void ReCreateVToolbar() override
Create or update the right vertical toolbar.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
#define FIRST_DCODE
Definition: dcode.h:70
static TOOL_ACTION toggleGrid
Definition: actions.h:140
static TOOL_ACTION inchesUnits
Definition: actions.h:144
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
wxChoice * m_zoomSelectBox
static TOOL_ACTION linesDisplayOutlines
int m_Num_Dcode
D code value ( >= 10 )
Definition: dcode.h:190
void UpdateControlWidth(int aID)
Update the toolbar item width of a control using its best size.
static TOOL_ACTION togglePolarCoords
Definition: actions.h:149
static const wxChar * ShowApertureType(APERTURE_T aType)
Return a character string telling what type of aperture type aType is.
Definition: dcode.cpp:87
#define _(s)
Helper to display a DCode list and select a DCode id.
void AppendDCodeList(const wxArrayString &aChoices)
static TOOL_ACTION milsUnits
Definition: actions.h:145
wxString UnescapeString(const wxString &aSource)
std::map< wxString, int > m_NetnamesList
wxString m_AperFunction
the aperture attribute (created by a TA.AperFunction command).
Definition: dcode.h:200
static TOOL_ACTION flashedDisplayOutlines
wxTextCtrl * m_TextInfo
DCODE_SELECTION_BOX * m_DCodeSelector
wxStaticText * m_cmpText
int GetActiveLayer() const
Return the active layer.
void updateAperAttributesSelectBox()
wxChoice * m_SelAperAttributesBox
const int scale
A gerber DCODE (also called Aperture) definition.
Definition: dcode.h:80
void OnUpdateDrawMode(wxUpdateUIEvent &aEvent)
static TOOL_ACTION zoomRedraw
Definition: actions.h:90
static TOOL_ACTION polygonsDisplayOutlines
#define TOOLS_MAX_COUNT
Definition: dcode.h:72
#define IU_PER_MILS
Definition: plotter.cpp:136
wxStaticText * m_dcodeText
static constexpr int KICAD_AUI_TB_STYLE
< Default style flags used for wxAUI toolbars.
#define NO_SELECTION_STRING
wxChoice * m_SelComponentBox
wxStaticText * m_netText
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:102
wxStaticText * m_apertText
static TOOL_ACTION highContrastMode
Definition: actions.h:103
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
std::map< wxString, int > m_ComponentsList
static TOOL_ACTION reloadAllLayers
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION selectionTool
Definition: actions.h:153
void ClearToolbar()
Clear the toolbar and remove all associated menus.
void ReCreateOptToolbar() override
Create or update the left vertical toolbar (option toolbar)