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 <gerbview.h>
23 #include <gerbview_frame.h>
24 #include <bitmaps.h>
25 #include <gerbview_id.h>
26 #include <gerber_file_image.h>
27 #include <gerber_file_image_list.h>
28 #include <dialog_helpers.h>
29 #include <kicad_string.h>
30 #include <wx/wupdlock.h>
31 #include <tool/actions.h>
32 #include <tool/action_toolbar.h>
33 #include <tools/gerbview_actions.h>
36 
38 {
39  // Note:
40  // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
41  // all wxAuiToolBarItems.
42  // However the wxAuiToolBarItems are not the owners of controls managed by
43  // them ( m_TextInfo and m_SelLayerBox ), and therefore do not delete them
44  // So we do not recreate them after clearing the tools.
45 
46  if( m_mainToolBar )
47  {
49  }
50  else
51  {
52  m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
53  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT | wxAUI_TB_HORIZONTAL );
55  }
56 
57  // Set up toolbar
62 
65 
72 
73 
75 
76  if( !m_SelLayerBox )
79  wxDefaultPosition, wxDefaultSize, 0, NULL );
80 
82  m_mainToolBar->AddControl( m_SelLayerBox );
83 
84  if( !m_TextInfo )
85  m_TextInfo = new wxTextCtrl( m_mainToolBar, ID_TOOLBARH_GERBER_DATA_TEXT_BOX, wxEmptyString, wxDefaultPosition,
86  wxDefaultSize, wxTE_READONLY );
87 
88  m_mainToolBar->AddControl( m_TextInfo );
89 
92 
93  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
95 }
96 
97 
99 {
100  wxWindowUpdateLocker dummy( this );
101 
102  if( m_auxiliaryToolBar )
103  {
105  }
106  else
107  {
109  wxDefaultPosition, wxDefaultSize,
110  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
112  }
113 
114  // Creates box to display and choose components:
115  // (note, when the m_auxiliaryToolBar is recreated, tools are deleted, but controls
116  // are not deleted: they are just no longer managed by the toolbar
117  if( !m_SelComponentBox )
118  m_SelComponentBox = new wxChoice( m_auxiliaryToolBar,
120 
121  if( !m_cmpText )
122  m_cmpText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Cmp:" ) + wxS( " " ) );
123 
124  m_SelComponentBox->SetToolTip( _("Highlight items belonging to this component") );
125  m_cmpText->SetLabel( _( "Cmp:" ) + wxS( " " ) ); // can change when changing the language
126  m_auxiliaryToolBar->AddControl( m_cmpText );
127  m_auxiliaryToolBar->AddControl( m_SelComponentBox );
128  m_auxiliaryToolBar->AddSpacer( 5 );
129 
130  // Creates choice box to display net names and highlight selected:
131  if( !m_SelNetnameBox )
132  m_SelNetnameBox = new wxChoice( m_auxiliaryToolBar,
134 
135  if( !m_netText )
136  m_netText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Net:" ) );
137 
138  m_SelNetnameBox->SetToolTip( _("Highlight items belonging to this net") );
139  m_netText->SetLabel( _( "Net:" ) ); // can change when changing the language
140  m_auxiliaryToolBar->AddControl( m_netText );
141  m_auxiliaryToolBar->AddControl( m_SelNetnameBox );
142  m_auxiliaryToolBar->AddSpacer( 5 );
143 
144  // Creates choice box to display aperture attributes and highlight selected:
148 
149  if( !m_apertText )
150  m_apertText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Attr:" ) );
151 
152  m_SelAperAttributesBox->SetToolTip( _("Highlight items with this aperture attribute") );
153  m_apertText->SetLabel( _( "Attr:" ) ); // can change when changing the language
154  m_auxiliaryToolBar->AddControl( m_apertText );
156  m_auxiliaryToolBar->AddSpacer( 5 );
157 
158  if( !m_DCodeSelector )
161  wxDefaultPosition, wxSize( 150, -1 ) );
162 
163  if( !m_dcodeText )
164  m_dcodeText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "DCode:" ) );
165 
166  m_dcodeText->SetLabel( _( "DCode:" ) );
167  m_auxiliaryToolBar->AddControl( m_dcodeText );
168  m_auxiliaryToolBar->AddControl( m_DCodeSelector );
169 
170  if( !m_gridSelectBox )
171  {
173  wxDefaultPosition, wxDefaultSize, 0, nullptr );
174  }
175 
177  m_auxiliaryToolBar->AddControl( m_gridSelectBox );
178 
179  if( !m_zoomSelectBox )
180  {
182  wxDefaultPosition, wxDefaultSize, 0, nullptr );
183  }
184 
186  m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
187 
194 
195  // Go through and ensure the comboboxes are the correct size, since the strings in the
196  // box could have changed widths.
202 
203  // after adding the buttons to the toolbar, must call Realize()
205 }
206 
207 
209 {
210  // This toolbar isn't used currently
211 }
212 
213 
215 {
216  if( m_optionsToolBar )
217  {
219  }
220  else
221  {
222  m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
223  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
225  }
226 
227  // TODO: these can be moved to the 'proper' vertical toolbar if and when there are
228  // actual tools to put there. That, or I'll get around to implementing configurable
229  // toolbars.
232 
240 
250 
253 
255 }
256 
257 
259 {
260  if( m_mainToolBar )
261  {
262  // Update the item widths
265  }
266 
267  if( m_auxiliaryToolBar )
268  {
269  // Update the item widths
275  }
276 }
277 
278 
279 #define NO_SELECTION_STRING _("<No selection>")
280 
282 {
283  m_DCodeSelector->Clear();
284 
285  // Add an empty string to deselect net highlight
287 
288  int layer = GetActiveLayer();
289  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
290 
291  if( !gerber || gerber->GetDcodesCount() == 0 )
292  {
293  if( m_DCodeSelector->GetSelection() != 0 )
294  m_DCodeSelector->SetSelection( 0 );
295 
296  return;
297  }
298 
299  // Build the aperture list of the current layer, and add it to the combo box:
300  wxArrayString dcode_list;
301  wxString msg;
302 
303  double scale = 1.0;
304  wxString units;
305 
306  switch( GetUserUnits() )
307  {
309  scale = IU_PER_MM;
310  units = "mm";
311  break;
312 
313  case EDA_UNITS::INCHES:
314  scale = IU_PER_MILS * 1000;
315  units = "in";
316  break;
317 
318  case EDA_UNITS::MILS:
319  scale = IU_PER_MILS;
320  units = "mil";
321  break;
322 
323  default:
324  wxASSERT_MSG( false, "Invalid units" );
325  }
326 
327  for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
328  {
329  D_CODE* dcode = gerber->GetDCODE( ii + FIRST_DCODE );
330 
331  if( dcode == NULL )
332  continue;
333 
334  if( !dcode->m_InUse && !dcode->m_Defined )
335  continue;
336 
337  msg.Printf( "tool %d [%.3fx%.3f %s] %s",
338  dcode->m_Num_Dcode,
339  dcode->m_Size.x / scale, dcode->m_Size.y / scale,
340  units,
342  );
343  if( !dcode->m_AperFunction.IsEmpty() )
344  msg << ", " << dcode->m_AperFunction;
345 
346  dcode_list.Add( msg );
347  }
348 
349  m_DCodeSelector->AppendDCodeList( dcode_list );
350 
351  if( dcode_list.size() > 1 )
352  {
353  wxSize size = m_DCodeSelector->GetBestSize();
354  size.x = std::max( size.x, 100 );
355  m_DCodeSelector->SetMinSize( size );
356  m_auimgr.Update();
357  }
358 }
359 
360 
362 {
363  m_SelComponentBox->Clear();
364 
365  // Build the full list of component names from the partial lists stored in each file image
366  std::map<wxString, int> full_list;
367 
368  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
369  {
370  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
371 
372  if( gerber == NULL ) // Graphic layer not yet used
373  continue;
374 
375  full_list.insert( gerber->m_ComponentsList.begin(), gerber->m_ComponentsList.end() );
376  }
377 
378  // Add an empty string to deselect net highlight
380 
381  // Now copy the list to the choice box
382  for( auto& ii : full_list )
383  m_SelComponentBox->Append( ii.first );
384 
385  m_SelComponentBox->SetSelection( 0 );
386 }
387 
388 
390 {
391  m_SelNetnameBox->Clear();
392 
393  // Build the full list of netnames from the partial lists stored in each file image
394  std::map<wxString, int> full_list;
395 
396  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
397  {
398  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
399 
400  if( gerber == NULL ) // Graphic layer not yet used
401  continue;
402 
403  full_list.insert( gerber->m_NetnamesList.begin(), gerber->m_NetnamesList.end() );
404  }
405 
406  // Add an empty string to deselect net highlight
408 
409  // Now copy the list to the choice box
410  for( auto& ii : full_list )
411  m_SelNetnameBox->Append( UnescapeString( ii.first ) );
412 
413  m_SelNetnameBox->SetSelection( 0 );
414 }
415 
416 
418 {
419  m_SelAperAttributesBox->Clear();
420 
421  // Build the full list of netnames from the partial lists stored in each file image
422  std::map<wxString, int> full_list;
423 
424  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
425  {
426  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
427 
428  if( gerber == NULL ) // Graphic layer not yet used
429  continue;
430 
431  if( gerber->GetDcodesCount() == 0 )
432  continue;
433 
434  for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
435  {
436  D_CODE* aperture = gerber->GetDCODE( ii + FIRST_DCODE );
437 
438  if( aperture == NULL )
439  continue;
440 
441  if( !aperture->m_InUse && !aperture->m_Defined )
442  continue;
443 
444  if( !aperture->m_AperFunction.IsEmpty() )
445  full_list.insert( std::make_pair( aperture->m_AperFunction, 0 ) );
446  }
447  }
448 
449  // Add an empty string to deselect net highlight
451 
452  // Now copy the list to the choice box
453  for( auto ii = full_list.begin(); ii != full_list.end(); ++ii )
454  {
455  m_SelAperAttributesBox->Append( ii->first );
456  }
457 
458  m_SelAperAttributesBox->SetSelection( 0 );
459 }
460 
461 
462 void GERBVIEW_FRAME::OnUpdateDrawMode( wxUpdateUIEvent& aEvent )
463 {
464  switch( aEvent.GetId() )
465  {
467  aEvent.Check( GetDisplayMode() == 0 );
468  break;
469 
471  aEvent.Check( GetDisplayMode() == 1 );
472  break;
473 
475  aEvent.Check( GetDisplayMode() == 2 );
476  break;
477 
478  default:
479  break;
480  }
481 }
482 
483 
484 void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
485 {
486  if( !m_DCodeSelector )
487  return;
488 
489  int layer = GetActiveLayer();
490  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
491  int selected = ( gerber ) ? gerber->m_Selected_Tool : 0;
492 
493  aEvent.Enable( gerber != NULL );
494 
495  if( m_DCodeSelector->GetSelectedDCodeId() != selected )
496  {
497  m_DCodeSelector->SetDCodeSelection( selected );
498  // Be sure the selection can be made. If no, set to
499  // a correct value
500  if( gerber )
502  }
503 }
504 
505 
506 void GERBVIEW_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
507 {
508  if( m_SelLayerBox->GetSelection() != GetActiveLayer() )
509  m_SelLayerBox->SetSelection( GetActiveLayer() );
510 }
511 
Define the structure of a toolbar with buttons that invoke ACTIONs.
static TOOL_ACTION openDrillFile
static TOOL_ACTION zoomInCenter
Definition: actions.h:96
void OnUpdateSelectDCode(wxUpdateUIEvent &aEvent)
static TOOL_ACTION openGerber
ACTION_TOOLBAR * m_auxiliaryToolBar
wxSize m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:94
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 aperure (previously defined) is not used to draw something
Definition: dcode.h:102
static TOOL_ACTION zoomTool
Definition: actions.h:102
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.
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:99
static TOOL_ACTION millimetersUnits
Definition: actions.h:149
GERBVIEW_FRAME::OnZipFileHistory ID_TB_OPTIONS_SHOW_GBR_MODE_2
GBR_LAYER_BOX_SELECTOR * m_SelLayerBox
void SetDCodeSelection(int aDCodeId)
Function SetDCodeSelection.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Definition: sch_symbol.cpp:69
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:60
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:97
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
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:157
bool m_Defined
false if the aperture is not defined in the header
Definition: dcode.h:104
static TOOL_ACTION flipGerberView
static constexpr bool CANCEL
void ReCreateAuxiliaryToolbar() override
void ReCreateVToolbar() override
Create or update the right vertical toolbar.
#define NULL
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
#define FIRST_DCODE
Definition: dcode.h:71
static TOOL_ACTION toggleGrid
Definition: actions.h:143
static TOOL_ACTION inchesUnits
Definition: actions.h:147
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
void UpdateControlWidth(int aID)
Update the toolbar item width of a control using its best size.
int GetSelectedDCodeId()
Function GetSelectedDCodeId.
static TOOL_ACTION togglePolarCoords
Definition: actions.h:152
static const wxChar * ShowApertureType(APERTURE_T aType)
Function ShowApertureType returns a character string telling what type of aperture type aType is.
Definition: dcode.cpp:92
Helper dialog and control classes.
void AppendDCodeList(const wxArrayString &aChoices)
Function AppendDCodeList.
static TOOL_ACTION milsUnits
Definition: actions.h:148
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
wxStaticText * m_cmpText
int GetActiveLayer() const
Return the active layer.
void updateAperAttributesSelectBox()
wxChoice * m_SelAperAttributesBox
const int scale
D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
void OnUpdateDrawMode(wxUpdateUIEvent &aEvent)
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:93
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:151
static TOOL_ACTION polygonsDisplayOutlines
#define TOOLS_MAX_COUNT
Definition: dcode.h:73
#define IU_PER_MILS
Definition: plotter.cpp:137
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:105
wxStaticText * m_apertText
static TOOL_ACTION highContrastMode
Definition: actions.h:106
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:156
void ClearToolbar()
Clear the toolbar and remove all associated menus.
void ReCreateOptToolbar() override
Create or update the left vertical toolbar (option toolbar)