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 <bitmaps.h>
35 #include <kicad_string.h>
36 #include <wx/wupdlock.h>
37 #include <tool/actions.h>
38 #include <tool/action_toolbar.h>
39 #include <tools/gerbview_actions.h>
40 
42 {
43  wxString msg;
44 
45  if( m_mainToolBar )
46  m_mainToolBar->Clear();
47  else
48  m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
49  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
50 
51  // Set up toolbar
52  m_mainToolBar->AddTool( ID_GERBVIEW_ERASE_ALL, wxEmptyString,
53  KiScaledBitmap( delete_gerber_xpm, this ),
54  _( "Clear all layers" ) );
55 
56  m_mainToolBar->AddTool( ID_GERBVIEW_RELOAD_ALL, wxEmptyString,
57  KiScaledBitmap( reload2_xpm, this ),
58  _( "Reload all layers" ) );
59 
60  m_mainToolBar->AddTool( wxID_FILE, wxEmptyString, KiScaledBitmap( load_gerber_xpm, this ),
61  _( "Open Gerber file(s) on the current layer. Previous data will be deleted" ) );
62 
63  m_mainToolBar->AddTool( ID_GERBVIEW_LOAD_DRILL_FILE, wxEmptyString,
64  KiScaledBitmap( gerbview_drill_file_xpm, this ),
65  _( "Open Excellon drill file(s) on the current layer. Previous data will be deleted" ) );
66 
68  m_mainToolBar->AddTool( wxID_PRINT, wxEmptyString, KiScaledBitmap( print_button_xpm, this ),
69  _( "Print layers" ) );
70 
71  m_mainToolBar->AddSeparator();
77 
78 
80 
83  wxDefaultPosition, wxDefaultSize, 0, NULL );
85 
86  m_mainToolBar->AddControl( m_SelLayerBox );
87 
88  m_TextInfo = new wxTextCtrl( m_mainToolBar, wxID_ANY, wxEmptyString, wxDefaultPosition,
89  wxDefaultSize, wxTE_READONLY );
90  m_mainToolBar->AddControl( m_TextInfo );
91 
92  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
93  m_mainToolBar->Realize();
94 }
95 
96 
98 {
99  wxWindowUpdateLocker dummy( this );
100  wxStaticText* text;
101 
102  if( !m_auxiliaryToolBar )
104  wxDefaultPosition, wxDefaultSize,
105  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
106 
107  // Creates box to display and choose components:
108  if( !m_SelComponentBox )
109  {
110  m_SelComponentBox = new wxChoice( m_auxiliaryToolBar,
112  m_SelComponentBox->SetToolTip( _("Highlight items belonging to this component") );
113  text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Cmp: ") );
114  m_auxiliaryToolBar->AddControl( text );
115  m_auxiliaryToolBar->AddControl( m_SelComponentBox );
116  m_auxiliaryToolBar->AddSpacer( 5 );
117  }
118 
119  // Creates choice box to display net names and highlight selected:
120  if( !m_SelNetnameBox )
121  {
122  m_SelNetnameBox = new wxChoice( m_auxiliaryToolBar,
124  m_SelNetnameBox->SetToolTip( _("Highlight items belonging to this net") );
125  text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Net:" ) );
126  m_auxiliaryToolBar->AddControl( text );
127  m_auxiliaryToolBar->AddControl( m_SelNetnameBox );
128  m_auxiliaryToolBar->AddSpacer( 5 );
129  }
130 
131  // Creates choice box to display aperture attributes and highlight selected:
133  {
136  m_SelAperAttributesBox->SetToolTip( _("Highlight items with this aperture attribute") );
137  text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Attr:" ) );
138  m_auxiliaryToolBar->AddControl( text );
140  m_auxiliaryToolBar->AddSpacer( 5 );
141  }
142 
143  if( !m_DCodeSelector )
144  {
147  wxDefaultPosition, wxSize( 150, -1 ) );
148  text = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "DCode:" ) );
149  m_auxiliaryToolBar->AddControl( text );
150  m_auxiliaryToolBar->AddControl( m_DCodeSelector );
151  }
152 
153  if( !m_gridSelectBox )
154  {
157  wxDefaultPosition, wxDefaultSize, 0, nullptr );
158  m_auxiliaryToolBar->AddControl( m_gridSelectBox );
159  }
160 
161  if( !m_zoomSelectBox )
162  {
165  wxDefaultPosition, wxDefaultSize, 0, nullptr );
166  m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
167  }
168 
175 
176  // combobox sizes can have changed: apply new best sizes
177  auto item = m_auxiliaryToolBar->FindTool( ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
178  item->SetMinSize( m_SelComponentBox->GetBestSize() );
179 
181  item->SetMinSize( m_SelNetnameBox->GetBestSize() );
182 
184  item->SetMinSize( m_SelAperAttributesBox->GetBestSize() );
185 
186  item = m_auxiliaryToolBar->FindTool( ID_ON_GRID_SELECT );
187  item->SetMinSize( m_gridSelectBox->GetBestSize() );
188 
189  item = m_auxiliaryToolBar->FindTool( ID_ON_ZOOM_SELECT );
190  item->SetMinSize( m_zoomSelectBox->GetBestSize() );
191 
192  // after adding the buttons to the toolbar, must call Realize()
193  m_auxiliaryToolBar->Realize();
194 }
195 
196 
198 {
199  if( m_drawToolBar )
200  return;
201 
202  m_drawToolBar = new ACTION_TOOLBAR( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
203  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
204 
206  m_drawToolBar->AddSeparator();
207 
208  m_drawToolBar->Realize();
209 }
210 
211 
213 {
214  if( m_optionsToolBar )
215  m_optionsToolBar->Clear();
216  else
217  m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
218  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
219 
220  // TODO: these can be moved to the 'proper' vertical toolbar if and when there are
221  // actual tools to put there. That, or I'll get around to implementing configurable
222  // toolbars.
225 
226  m_optionsToolBar->AddSeparator();
232 
241 
242  // Tools to show/hide toolbars:
245  wxEmptyString,
246  KiScaledBitmap( layers_manager_xpm, this ),
247  _( "Show/hide the layers manager toolbar" ),
248  wxITEM_CHECK );
249 
250  m_optionsToolBar->Realize();
251 }
252 
253 
254 #define NO_SELECTION_STRING _("<No selection>")
255 
257 {
258  m_DCodeSelector->Clear();
259 
260  // Add an empty string to deselect net highlight
262 
263  int layer = GetActiveLayer();
264  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
265 
266  if( !gerber || gerber->GetDcodesCount() == 0 )
267  {
268  if( m_DCodeSelector->GetSelection() != 0 )
269  m_DCodeSelector->SetSelection( 0 );
270 
271  return;
272  }
273 
274  // Build the aperture list of the current layer, and add it to the combo box:
275  wxArrayString dcode_list;
276  wxString msg;
277  const char* units = GetUserUnits() == INCHES ? "mils" : "mm";
278  double scale = GetUserUnits() == INCHES ? IU_PER_MILS : IU_PER_MM;
279 
280  for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
281  {
282  D_CODE* dcode = gerber->GetDCODE( ii + FIRST_DCODE );
283 
284  if( dcode == NULL )
285  continue;
286 
287  if( !dcode->m_InUse && !dcode->m_Defined )
288  continue;
289 
290  msg.Printf( "tool %d [%.3fx%.3f %s] %s",
291  dcode->m_Num_Dcode,
292  dcode->m_Size.y / scale, dcode->m_Size.x / scale,
293  units,
295  );
296  if( !dcode->m_AperFunction.IsEmpty() )
297  msg << ", " << dcode->m_AperFunction;
298 
299  dcode_list.Add( msg );
300  }
301 
302  m_DCodeSelector->AppendDCodeList( dcode_list );
303 
304  if( dcode_list.size() > 1 )
305  {
306  wxSize size = m_DCodeSelector->GetBestSize();
307  size.x = std::max( size.x, 100 );
308  m_DCodeSelector->SetMinSize( size );
309  m_auimgr.Update();
310  }
311 }
312 
313 
315 {
316  m_SelComponentBox->Clear();
317 
318  // Build the full list of component names from the partial lists stored in each file image
319  std::map<wxString, int> full_list;
320 
321  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
322  {
323  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
324 
325  if( gerber == NULL ) // Graphic layer not yet used
326  continue;
327 
328  full_list.insert( gerber->m_ComponentsList.begin(), gerber->m_ComponentsList.end() );
329  }
330 
331  // Add an empty string to deselect net highlight
333 
334  // Now copy the list to the choice box
335  for( auto& ii : full_list )
336  m_SelComponentBox->Append( ii.first );
337 
338  m_SelComponentBox->SetSelection( 0 );
339 }
340 
341 
343 {
344  m_SelNetnameBox->Clear();
345 
346  // Build the full list of netnames from the partial lists stored in each file image
347  std::map<wxString, int> full_list;
348 
349  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
350  {
351  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
352 
353  if( gerber == NULL ) // Graphic layer not yet used
354  continue;
355 
356  full_list.insert( gerber->m_NetnamesList.begin(), gerber->m_NetnamesList.end() );
357  }
358 
359  // Add an empty string to deselect net highlight
361 
362  // Now copy the list to the choice box
363  for( auto& ii : full_list )
364  m_SelNetnameBox->Append( UnescapeString( ii.first ) );
365 
366  m_SelNetnameBox->SetSelection( 0 );
367 }
368 
369 
371 {
372  m_SelAperAttributesBox->Clear();
373 
374  // Build the full list of netnames from the partial lists stored in each file image
375  std::map<wxString, int> full_list;
376 
377  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
378  {
379  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
380 
381  if( gerber == NULL ) // Graphic layer not yet used
382  continue;
383 
384  if( gerber->GetDcodesCount() == 0 )
385  continue;
386 
387  for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
388  {
389  D_CODE* aperture = gerber->GetDCODE( ii + FIRST_DCODE );
390 
391  if( aperture == NULL )
392  continue;
393 
394  if( !aperture->m_InUse && !aperture->m_Defined )
395  continue;
396 
397  if( !aperture->m_AperFunction.IsEmpty() )
398  full_list.insert( std::make_pair( aperture->m_AperFunction, 0 ) );
399  }
400  }
401 
402  // Add an empty string to deselect net highlight
404 
405  // Now copy the list to the choice box
406  for( auto ii = full_list.begin(); ii != full_list.end(); ++ii )
407  {
408  m_SelAperAttributesBox->Append( ii->first );
409  }
410 
411  m_SelAperAttributesBox->SetSelection( 0 );
412 }
413 
414 
415 void GERBVIEW_FRAME::OnUpdateDrawMode( wxUpdateUIEvent& aEvent )
416 {
417  switch( aEvent.GetId() )
418  {
420  aEvent.Check( GetDisplayMode() == 0 );
421  break;
422 
424  aEvent.Check( GetDisplayMode() == 1 );
425  break;
426 
428  aEvent.Check( GetDisplayMode() == 2 );
429  break;
430 
431  default:
432  break;
433  }
434 }
435 
436 
437 void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
438 {
439  if( !m_DCodeSelector )
440  return;
441 
442  int layer = GetActiveLayer();
443  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
444  int selected = ( gerber ) ? gerber->m_Selected_Tool : 0;
445 
446  aEvent.Enable( gerber != NULL );
447 
448  if( m_DCodeSelector->GetSelectedDCodeId() != selected )
449  {
450  m_DCodeSelector->SetDCodeSelection( selected );
451  // Be sure the selection can be made. If no, set to
452  // a correct value
453  if( gerber )
455  }
456 }
457 
458 
459 void GERBVIEW_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
460 {
461  if( m_SelLayerBox->GetSelection() != GetActiveLayer() )
462  m_SelLayerBox->SetSelection( GetActiveLayer() );
463 }
464 
465 
467 {
469 
470 #define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) )
471 
473  m_mainToolBar->Refresh();
474 
492  m_optionsToolBar->Refresh();
493 }
bool m_DisplayPolygonsFill
Option to draw polygons (filled/sketch)
Class ACTION_TOOLBAR.
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.
ACTION_TOOLBAR * m_auxiliaryToolBar
wxSize m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:94
ACTION_TOOLBAR * m_optionsToolBar
int GetDisplayMode()
Function GetDisplayMode.
#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
virtual bool IsGridVisible() const
D_CODE * GetDCODE(int aDCODE) const
Function GetDCODE returns a pointer to the D_CODE within this GERBER for the given aDCODE.
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
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 OnUpdateLayerSelectBox(wxUpdateUIEvent &aEvent)
bool m_HighContrastMode
High contrast mode (dim un-highlighted objects)
void updateNetnameListSelectBox()
wxAuiManager m_auimgr
ACTION_TOOLBAR * m_mainToolBar
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, EDA_BASE_FRAME *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
int GetActiveLayer()
Function SetActiveLayer returns the active layer.
static TOOL_ACTION imperialUnits
Definition: actions.h:136
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()
static TOOL_ACTION measureTool
Definition: actions.h:144
bool m_Defined
false if the aperture is not defined in the header
Definition: dcode.h:104
bool m_DiffMode
Display layers in diff mode.
void ReCreateAuxiliaryToolbar() override
void ReCreateVToolbar() override
Function ReCreateVToolbar creates or updates the right vertical toolbar.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
#define FIRST_DCODE
Definition: dcode.h:71
static TOOL_ACTION toggleGrid
Definition: actions.h:132
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
Definition: common.h:134
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:139
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
#define _(s)
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:137
void updateAperAttributesSelectBox()
wxChoice * m_SelAperAttributesBox
const int scale
void SyncToolbars() override
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
#define max(a, b)
Definition: auxiliary.h:86
void OnUpdateDrawMode(wxUpdateUIEvent &aEvent)
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
static TOOL_ACTION polygonsDisplayOutlines
#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:135
The common library.
void KiScaledSeparator(wxAuiToolBar *aToolbar, EDA_BASE_FRAME *aWindow)
Add a separator to the given toolbar scaled the same way as KiScaledBitmap.
Definition: bitmap.cpp:167
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
#define NO_SELECTION_STRING
wxChoice * m_SelComponentBox
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:98
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
static TOOL_ACTION selectionTool
Definition: actions.h:143
ACTION_TOOLBAR * m_drawToolBar
void ReCreateOptToolbar() override
Create or update the left vertical toolbar (option toolbar.