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-2019 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 <fctsys.h>
23 
24 #include <common.h>
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 <gbr_layer_box_selector.h>
32 #include <DCodeSelectionbox.h>
33 #include <dialog_helpers.h>
34 #include <kicad_string.h>
35 #include <wx/wupdlock.h>
36 #include <tool/actions.h>
37 #include <tool/action_toolbar.h>
38 #include <tools/gerbview_actions.h>
39 
41 {
42  // Note:
43  // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
44  // all wxAuiToolBarItems.
45  // However the wxAuiToolBarItems are not the owners of controls managed by
46  // them ( m_TextInfo and m_SelLayerBox ), and therefore do not delete them
47  // So we do not recreate them after clearing the tools.
48 
49  if( m_mainToolBar )
51  else
52  m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
53  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
54 
55  // Set up toolbar
56  m_mainToolBar->AddTool( ID_GERBVIEW_ERASE_ALL, wxEmptyString,
58  _( "Clear all layers" ) );
59 
60  m_mainToolBar->AddTool( ID_GERBVIEW_RELOAD_ALL, wxEmptyString,
61  KiScaledBitmap( reload2_xpm, this ),
62  _( "Reload all layers" ) );
63 
66 
69 
76 
77 
79 
80  if( !m_SelLayerBox )
83  wxDefaultPosition, wxDefaultSize, 0, NULL );
84 
86  m_mainToolBar->AddControl( m_SelLayerBox );
87 
88  if( !m_TextInfo )
89  m_TextInfo = new wxTextCtrl( m_mainToolBar, wxID_ANY, wxEmptyString, wxDefaultPosition,
90  wxDefaultSize, wxTE_READONLY );
91 
92  m_mainToolBar->AddControl( m_TextInfo );
93 
94  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
95  m_mainToolBar->Realize();
96 }
97 
98 
100 {
101  wxWindowUpdateLocker dummy( this );
102 
103  if( m_auxiliaryToolBar )
105  else
107  wxDefaultPosition, wxDefaultSize,
108  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
109 
110  // Creates box to display and choose components:
111  // (note, when the m_auxiliaryToolBar is recreated, tools are deleted, but controls
112  // are not deleted: they are just no longer managed by the toolbar
113  if( !m_SelComponentBox )
114  m_SelComponentBox = new wxChoice( m_auxiliaryToolBar,
116 
117  if( !m_cmpText )
118  m_cmpText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Cmp: ") );
119 
120  m_SelComponentBox->SetToolTip( _("Highlight items belonging to this component") );
121  m_cmpText->SetLabel( _( "Cmp: ") ); // can change when changing the language
122  m_auxiliaryToolBar->AddControl( m_cmpText );
123  m_auxiliaryToolBar->AddControl( m_SelComponentBox );
124  m_auxiliaryToolBar->AddSpacer( 5 );
125 
126  // Creates choice box to display net names and highlight selected:
127  if( !m_SelNetnameBox )
128  m_SelNetnameBox = new wxChoice( m_auxiliaryToolBar,
130 
131  if( !m_netText )
132  m_netText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Net:" ) );
133 
134  m_SelNetnameBox->SetToolTip( _("Highlight items belonging to this net") );
135  m_netText->SetLabel( _( "Net:" ) ); // can change when changing the language
136  m_auxiliaryToolBar->AddControl( m_netText );
137  m_auxiliaryToolBar->AddControl( m_SelNetnameBox );
138  m_auxiliaryToolBar->AddSpacer( 5 );
139 
140  // Creates choice box to display aperture attributes and highlight selected:
144 
145  if( !m_apertText )
146  m_apertText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Attr:" ) );
147 
148  m_SelAperAttributesBox->SetToolTip( _("Highlight items with this aperture attribute") );
149  m_apertText->SetLabel( _( "Attr:" ) ); // can change when changing the language
150  m_auxiliaryToolBar->AddControl( m_apertText );
152  m_auxiliaryToolBar->AddSpacer( 5 );
153 
154  if( !m_DCodeSelector )
157  wxDefaultPosition, wxSize( 150, -1 ) );
158 
159  if( !m_dcodeText )
160  m_dcodeText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "DCode:" ) );
161 
162  m_dcodeText->SetLabel( _( "DCode:" ) );
163  m_auxiliaryToolBar->AddControl( m_dcodeText );
164  m_auxiliaryToolBar->AddControl( m_DCodeSelector );
165 
166  if( !m_gridSelectBox )
167  {
169  wxDefaultPosition, wxDefaultSize, 0, nullptr );
170  }
171 
173  m_auxiliaryToolBar->AddControl( m_gridSelectBox );
174 
175  if( !m_zoomSelectBox )
176  {
178  wxDefaultPosition, wxDefaultSize, 0, nullptr );
179  }
180 
182  m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
183 
190 
191  // combobox sizes can have changed: apply new best sizes
192  auto item = m_auxiliaryToolBar->FindTool( ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
193  wxASSERT( item );
194  item->SetMinSize( m_SelComponentBox->GetBestSize() );
195 
197  wxASSERT( item );
198  item->SetMinSize( m_SelNetnameBox->GetBestSize() );
199 
201  wxASSERT( item );
202  item->SetMinSize( m_SelAperAttributesBox->GetBestSize() );
203 
204  item = m_auxiliaryToolBar->FindTool( ID_ON_GRID_SELECT );
205  wxASSERT( item );
206  item->SetMinSize( m_gridSelectBox->GetBestSize() );
207 
208  item = m_auxiliaryToolBar->FindTool( ID_ON_ZOOM_SELECT );
209  wxASSERT( item );
210  item->SetMinSize( m_zoomSelectBox->GetBestSize() );
211 
212  // after adding the buttons to the toolbar, must call Realize()
213  m_auxiliaryToolBar->Realize();
214 }
215 
216 
218 {
219  // This toolbar isn't used currently
220 }
221 
222 
224 {
225  if( m_optionsToolBar )
227  else
228  m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
229  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
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 
243 
253 
254  // Tools to show/hide toolbars:
257  wxEmptyString,
259  _( "Show/hide the layers manager toolbar" ),
260  wxITEM_CHECK );
261 
262  m_optionsToolBar->Realize();
263 }
264 
265 
266 #define NO_SELECTION_STRING _("<No selection>")
267 
269 {
270  m_DCodeSelector->Clear();
271 
272  // Add an empty string to deselect net highlight
274 
275  int layer = GetActiveLayer();
276  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
277 
278  if( !gerber || gerber->GetDcodesCount() == 0 )
279  {
280  if( m_DCodeSelector->GetSelection() != 0 )
281  m_DCodeSelector->SetSelection( 0 );
282 
283  return;
284  }
285 
286  // Build the aperture list of the current layer, and add it to the combo box:
287  wxArrayString dcode_list;
288  wxString msg;
289  const char* units = GetUserUnits() == EDA_UNITS::INCHES ? "mils" : "mm";
291 
292  for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
293  {
294  D_CODE* dcode = gerber->GetDCODE( ii + FIRST_DCODE );
295 
296  if( dcode == NULL )
297  continue;
298 
299  if( !dcode->m_InUse && !dcode->m_Defined )
300  continue;
301 
302  msg.Printf( "tool %d [%.3fx%.3f %s] %s",
303  dcode->m_Num_Dcode,
304  dcode->m_Size.x / scale, dcode->m_Size.y / scale,
305  units,
307  );
308  if( !dcode->m_AperFunction.IsEmpty() )
309  msg << ", " << dcode->m_AperFunction;
310 
311  dcode_list.Add( msg );
312  }
313 
314  m_DCodeSelector->AppendDCodeList( dcode_list );
315 
316  if( dcode_list.size() > 1 )
317  {
318  wxSize size = m_DCodeSelector->GetBestSize();
319  size.x = std::max( size.x, 100 );
320  m_DCodeSelector->SetMinSize( size );
321  m_auimgr.Update();
322  }
323 }
324 
325 
327 {
328  m_SelComponentBox->Clear();
329 
330  // Build the full list of component names from the partial lists stored in each file image
331  std::map<wxString, int> full_list;
332 
333  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
334  {
335  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
336 
337  if( gerber == NULL ) // Graphic layer not yet used
338  continue;
339 
340  full_list.insert( gerber->m_ComponentsList.begin(), gerber->m_ComponentsList.end() );
341  }
342 
343  // Add an empty string to deselect net highlight
345 
346  // Now copy the list to the choice box
347  for( auto& ii : full_list )
348  m_SelComponentBox->Append( ii.first );
349 
350  m_SelComponentBox->SetSelection( 0 );
351 }
352 
353 
355 {
356  m_SelNetnameBox->Clear();
357 
358  // Build the full list of netnames from the partial lists stored in each file image
359  std::map<wxString, int> full_list;
360 
361  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
362  {
363  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
364 
365  if( gerber == NULL ) // Graphic layer not yet used
366  continue;
367 
368  full_list.insert( gerber->m_NetnamesList.begin(), gerber->m_NetnamesList.end() );
369  }
370 
371  // Add an empty string to deselect net highlight
373 
374  // Now copy the list to the choice box
375  for( auto& ii : full_list )
376  m_SelNetnameBox->Append( UnescapeString( ii.first ) );
377 
378  m_SelNetnameBox->SetSelection( 0 );
379 }
380 
381 
383 {
384  m_SelAperAttributesBox->Clear();
385 
386  // Build the full list of netnames from the partial lists stored in each file image
387  std::map<wxString, int> full_list;
388 
389  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
390  {
391  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
392 
393  if( gerber == NULL ) // Graphic layer not yet used
394  continue;
395 
396  if( gerber->GetDcodesCount() == 0 )
397  continue;
398 
399  for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
400  {
401  D_CODE* aperture = gerber->GetDCODE( ii + FIRST_DCODE );
402 
403  if( aperture == NULL )
404  continue;
405 
406  if( !aperture->m_InUse && !aperture->m_Defined )
407  continue;
408 
409  if( !aperture->m_AperFunction.IsEmpty() )
410  full_list.insert( std::make_pair( aperture->m_AperFunction, 0 ) );
411  }
412  }
413 
414  // Add an empty string to deselect net highlight
416 
417  // Now copy the list to the choice box
418  for( auto ii = full_list.begin(); ii != full_list.end(); ++ii )
419  {
420  m_SelAperAttributesBox->Append( ii->first );
421  }
422 
423  m_SelAperAttributesBox->SetSelection( 0 );
424 }
425 
426 
427 void GERBVIEW_FRAME::OnUpdateDrawMode( wxUpdateUIEvent& aEvent )
428 {
429  switch( aEvent.GetId() )
430  {
432  aEvent.Check( GetDisplayMode() == 0 );
433  break;
434 
436  aEvent.Check( GetDisplayMode() == 1 );
437  break;
438 
440  aEvent.Check( GetDisplayMode() == 2 );
441  break;
442 
443  default:
444  break;
445  }
446 }
447 
448 
449 void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
450 {
451  if( !m_DCodeSelector )
452  return;
453 
454  int layer = GetActiveLayer();
455  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
456  int selected = ( gerber ) ? gerber->m_Selected_Tool : 0;
457 
458  aEvent.Enable( gerber != NULL );
459 
460  if( m_DCodeSelector->GetSelectedDCodeId() != selected )
461  {
462  m_DCodeSelector->SetDCodeSelection( selected );
463  // Be sure the selection can be made. If no, set to
464  // a correct value
465  if( gerber )
467  }
468 }
469 
470 
471 void GERBVIEW_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
472 {
473  if( m_SelLayerBox->GetSelection() != GetActiveLayer() )
474  m_SelLayerBox->SetSelection( GetActiveLayer() );
475 }
476 
477 
479 {
481 
482 #define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) )
483 
485  m_mainToolBar->Refresh();
486 
505  m_optionsToolBar->Refresh();
506 }
bool m_DisplayPolygonsFill
Option to draw polygons (filled/sketch)
ACTION_TOOLBAR.
static TOOL_ACTION openDrillFile
static TOOL_ACTION zoomInCenter
Definition: actions.h:90
void OnUpdateSelectDCode(wxUpdateUIEvent &aEvent)
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
static TOOL_ACTION openGerber
ACTION_TOOLBAR * m_auxiliaryToolBar
wxSize m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:94
ACTION_TOOLBAR * m_optionsToolBar
int GetDisplayMode()
Function GetDisplayMode.
static constexpr double IU_PER_MM
Mock up a conversion function.
#define TOGGLE_TOOL(toolbar, tool)
bool m_InUse
false if the aperure (previously defined) is not used to draw something
Definition: dcode.h:102
static const bool TOGGLE
static TOOL_ACTION zoomTool
Definition: actions.h:95
APERTURE_T m_Shape
shape ( Line, rectangle, circle , oval .. )
Definition: dcode.h:95
void AddScaledSeparator(wxWindow *aWindow)
Add a separator that introduces space on either side to not squash the tools when scaled.
D_CODE * GetDCODE(int aDCODE) const
Function GetDCODE returns a pointer to the D_CODE within this GERBER for the given aDCODE.
GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters (TODO:...
void Add(const TOOL_ACTION &aAction, bool aIsToggleEntry=false)
Function Add() Adds a TOOL_ACTION-based button to the toolbar.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
GBR_LAYER_BOX_SELECTOR * m_SelLayerBox
void SetDCodeSelection(int aDCodeId)
Function SetDCodeSelection.
void UpdateZoomSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
void OnUpdateLayerSelectBox(wxUpdateUIEvent &aEvent)
bool m_HighContrastMode
High contrast mode (dim un-highlighted objects)
void updateNetnameListSelectBox()
wxAuiManager m_auimgr
ACTION_TOOLBAR * m_mainToolBar
static TOOL_ACTION print
Definition: actions.h:60
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, wxWindow *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
static TOOL_ACTION imperialUnits
Definition: actions.h:140
wxChoice * m_gridSelectBox
static TOOL_ACTION dcodeDisplay
static TOOL_ACTION negativeObjectDisplay
static TOOL_ACTION zoomOutCenter
Definition: actions.h:91
wxChoice * m_SelNetnameBox
bool m_DisplayLinesFill
Option to draw line items (filled/sketch)
static TOOL_ACTION toggleDiffMode
void ReCreateHToolbar() override
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:148
bool m_Defined
false if the aperture is not defined in the header
Definition: dcode.h:104
static TOOL_ACTION flipGerberView
bool m_DiffMode
Display layers in diff mode.
void ReCreateAuxiliaryToolbar() override
void ReCreateVToolbar() override
Function ReCreateVToolbar creates or updates the right vertical toolbar.
#define NULL
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
bool IsGridVisible() const
#define FIRST_DCODE
Definition: dcode.h:71
static TOOL_ACTION toggleGrid
Definition: actions.h:136
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:96
GBR_DISPLAY_OPTIONS m_DisplayOptions
bool m_DisplayFlashedItemsFill
Option to draw flashed items (filled/sketch)
int GetSelectedDCodeId()
Function GetSelectedDCodeId.
static TOOL_ACTION togglePolarCoords
Definition: actions.h:143
static const wxChar * ShowApertureType(APERTURE_T aType)
Function ShowApertureType returns a character string telling what type of aperture type aType is.
Definition: dcode.cpp:93
Helper dialog and control classes.
bool IsElementVisible(int aLayerID) const
Function IsElementVisible tests whether a given element category is visible.
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnToggleShowLayerManager GERBVIEW_FRAME::OnSelectHighlightChoice ID_TB_OPTIONS_SHOW_GBR_MODE_2
void AppendDCodeList(const wxArrayString &aChoices)
Function AppendDCodeList.
std::map< wxString, int > m_NetnamesList
wxString m_AperFunction
the aperture attribute (created by a TA.AperFunction command) attached to the D_CODE
Definition: dcode.h:105
static TOOL_ACTION flashedDisplayOutlines
wxTextCtrl * m_TextInfo
DCODE_SELECTION_BOX * m_DCodeSelector
static TOOL_ACTION metricUnits
Definition: actions.h:141
wxStaticText * m_cmpText
int GetActiveLayer() const
Function SetActiveLayer returns the active layer.
void updateAperAttributesSelectBox()
const BITMAP_OPAQUE layers_manager_xpm[1]
wxChoice * m_SelAperAttributesBox
const int scale
void SyncToolbars() override
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
void OnUpdateDrawMode(wxUpdateUIEvent &aEvent)
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:125
static TOOL_ACTION polygonsDisplayOutlines
const BITMAP_OPAQUE delete_gerber_xpm[1]
#define TOOLS_MAX_COUNT
Definition: dcode.h:73
void Toggle(const TOOL_ACTION &aAction, bool aState)
Applies the default toggle action.
#define IU_PER_MILS
Definition: plotter.cpp:138
const BITMAP_OPAQUE reload2_xpm[1]
Definition: reload2.cpp:68
wxStaticText * m_dcodeText
The common library.
bool m_FlipGerberView
Display as a mirror image.
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:98
wxStaticText * m_apertText
static TOOL_ACTION highContrastMode
Definition: actions.h:99
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
std::map< wxString, int > m_ComponentsList
bool m_fullscreenCursor
Fullscreen crosshair or small cross
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION selectionTool
Definition: actions.h:147
void ClearToolbar()
Clear the toolbar and remove all associated menus.
void ReCreateOptToolbar() override
Create or update the left vertical toolbar (option toolbar)