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 <gbr_layer_box_selector.h>
29 #include <DCodeSelectionbox.h>
30 #include <dialog_helpers.h>
31 #include <kicad_string.h>
32 #include <wx/wupdlock.h>
33 #include <tool/actions.h>
34 #include <tool/action_toolbar.h>
35 #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 );
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, wxID_ANY, wxEmptyString, wxDefaultPosition,
86  wxDefaultSize, wxTE_READONLY );
87 
88  m_mainToolBar->AddControl( m_TextInfo );
89 
90  // after adding the buttons to the toolbar, must call Realize() to reflect the changes
91  m_mainToolBar->Realize();
92 }
93 
94 
96 {
97  wxWindowUpdateLocker dummy( this );
98 
99  if( m_auxiliaryToolBar )
100  {
102  }
103  else
104  {
106  wxDefaultPosition, wxDefaultSize,
107  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
109  }
110 
111  // Creates box to display and choose components:
112  // (note, when the m_auxiliaryToolBar is recreated, tools are deleted, but controls
113  // are not deleted: they are just no longer managed by the toolbar
114  if( !m_SelComponentBox )
115  m_SelComponentBox = new wxChoice( m_auxiliaryToolBar,
117 
118  if( !m_cmpText )
119  m_cmpText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Cmp: ") );
120 
121  m_SelComponentBox->SetToolTip( _("Highlight items belonging to this component") );
122  m_cmpText->SetLabel( _( "Cmp: ") ); // can change when changing the language
123  m_auxiliaryToolBar->AddControl( m_cmpText );
124  m_auxiliaryToolBar->AddControl( m_SelComponentBox );
125  m_auxiliaryToolBar->AddSpacer( 5 );
126 
127  // Creates choice box to display net names and highlight selected:
128  if( !m_SelNetnameBox )
129  m_SelNetnameBox = new wxChoice( m_auxiliaryToolBar,
131 
132  if( !m_netText )
133  m_netText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Net:" ) );
134 
135  m_SelNetnameBox->SetToolTip( _("Highlight items belonging to this net") );
136  m_netText->SetLabel( _( "Net:" ) ); // can change when changing the language
137  m_auxiliaryToolBar->AddControl( m_netText );
138  m_auxiliaryToolBar->AddControl( m_SelNetnameBox );
139  m_auxiliaryToolBar->AddSpacer( 5 );
140 
141  // Creates choice box to display aperture attributes and highlight selected:
145 
146  if( !m_apertText )
147  m_apertText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Attr:" ) );
148 
149  m_SelAperAttributesBox->SetToolTip( _("Highlight items with this aperture attribute") );
150  m_apertText->SetLabel( _( "Attr:" ) ); // can change when changing the language
151  m_auxiliaryToolBar->AddControl( m_apertText );
153  m_auxiliaryToolBar->AddSpacer( 5 );
154 
155  if( !m_DCodeSelector )
158  wxDefaultPosition, wxSize( 150, -1 ) );
159 
160  if( !m_dcodeText )
161  m_dcodeText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "DCode:" ) );
162 
163  m_dcodeText->SetLabel( _( "DCode:" ) );
164  m_auxiliaryToolBar->AddControl( m_dcodeText );
165  m_auxiliaryToolBar->AddControl( m_DCodeSelector );
166 
167  if( !m_gridSelectBox )
168  {
170  wxDefaultPosition, wxDefaultSize, 0, nullptr );
171  }
172 
174  m_auxiliaryToolBar->AddControl( m_gridSelectBox );
175 
176  if( !m_zoomSelectBox )
177  {
179  wxDefaultPosition, wxDefaultSize, 0, nullptr );
180  }
181 
183  m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
184 
191 
192  // combobox sizes can have changed: apply new best sizes
193  auto item = m_auxiliaryToolBar->FindTool( ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE );
194  wxASSERT( item );
195  item->SetMinSize( m_SelComponentBox->GetBestSize() );
196 
198  wxASSERT( item );
199  item->SetMinSize( m_SelNetnameBox->GetBestSize() );
200 
202  wxASSERT( item );
203  item->SetMinSize( m_SelAperAttributesBox->GetBestSize() );
204 
205  item = m_auxiliaryToolBar->FindTool( ID_ON_GRID_SELECT );
206  wxASSERT( item );
207  item->SetMinSize( m_gridSelectBox->GetBestSize() );
208 
209  item = m_auxiliaryToolBar->FindTool( ID_ON_ZOOM_SELECT );
210  wxASSERT( item );
211  item->SetMinSize( m_zoomSelectBox->GetBestSize() );
212 
213  // after adding the buttons to the toolbar, must call Realize()
214  m_auxiliaryToolBar->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, wxDefaultSize,
233  KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
235  }
236 
237  // TODO: these can be moved to the 'proper' vertical toolbar if and when there are
238  // actual tools to put there. That, or I'll get around to implementing configurable
239  // toolbars.
242 
250 
260 
263 
264  m_optionsToolBar->Realize();
265 }
266 
267 
268 #define NO_SELECTION_STRING _("<No selection>")
269 
271 {
272  m_DCodeSelector->Clear();
273 
274  // Add an empty string to deselect net highlight
276 
277  int layer = GetActiveLayer();
278  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
279 
280  if( !gerber || gerber->GetDcodesCount() == 0 )
281  {
282  if( m_DCodeSelector->GetSelection() != 0 )
283  m_DCodeSelector->SetSelection( 0 );
284 
285  return;
286  }
287 
288  // Build the aperture list of the current layer, and add it to the combo box:
289  wxArrayString dcode_list;
290  wxString msg;
291 
292  double scale = 1.0;
293  wxString units;
294 
295  switch( GetUserUnits() )
296  {
298  scale = IU_PER_MM;
299  units = "mm";
300  break;
301 
302  case EDA_UNITS::INCHES:
303  scale = IU_PER_MILS * 1000;
304  units = "in";
305  break;
306 
307  case EDA_UNITS::MILS:
308  scale = IU_PER_MILS;
309  units = "mil";
310  break;
311 
312  default:
313  wxASSERT_MSG( false, "Invalid units" );
314  }
315 
316  for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
317  {
318  D_CODE* dcode = gerber->GetDCODE( ii + FIRST_DCODE );
319 
320  if( dcode == NULL )
321  continue;
322 
323  if( !dcode->m_InUse && !dcode->m_Defined )
324  continue;
325 
326  msg.Printf( "tool %d [%.3fx%.3f %s] %s",
327  dcode->m_Num_Dcode,
328  dcode->m_Size.x / scale, dcode->m_Size.y / scale,
329  units,
331  );
332  if( !dcode->m_AperFunction.IsEmpty() )
333  msg << ", " << dcode->m_AperFunction;
334 
335  dcode_list.Add( msg );
336  }
337 
338  m_DCodeSelector->AppendDCodeList( dcode_list );
339 
340  if( dcode_list.size() > 1 )
341  {
342  wxSize size = m_DCodeSelector->GetBestSize();
343  size.x = std::max( size.x, 100 );
344  m_DCodeSelector->SetMinSize( size );
345  m_auimgr.Update();
346  }
347 }
348 
349 
351 {
352  m_SelComponentBox->Clear();
353 
354  // Build the full list of component names from the partial lists stored in each file image
355  std::map<wxString, int> full_list;
356 
357  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
358  {
359  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
360 
361  if( gerber == NULL ) // Graphic layer not yet used
362  continue;
363 
364  full_list.insert( gerber->m_ComponentsList.begin(), gerber->m_ComponentsList.end() );
365  }
366 
367  // Add an empty string to deselect net highlight
369 
370  // Now copy the list to the choice box
371  for( auto& ii : full_list )
372  m_SelComponentBox->Append( ii.first );
373 
374  m_SelComponentBox->SetSelection( 0 );
375 }
376 
377 
379 {
380  m_SelNetnameBox->Clear();
381 
382  // Build the full list of netnames from the partial lists stored in each file image
383  std::map<wxString, int> full_list;
384 
385  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
386  {
387  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
388 
389  if( gerber == NULL ) // Graphic layer not yet used
390  continue;
391 
392  full_list.insert( gerber->m_NetnamesList.begin(), gerber->m_NetnamesList.end() );
393  }
394 
395  // Add an empty string to deselect net highlight
397 
398  // Now copy the list to the choice box
399  for( auto& ii : full_list )
400  m_SelNetnameBox->Append( UnescapeString( ii.first ) );
401 
402  m_SelNetnameBox->SetSelection( 0 );
403 }
404 
405 
407 {
408  m_SelAperAttributesBox->Clear();
409 
410  // Build the full list of netnames from the partial lists stored in each file image
411  std::map<wxString, int> full_list;
412 
413  for( unsigned layer = 0; layer < GetImagesList()->ImagesMaxCount(); ++layer )
414  {
415  GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer );
416 
417  if( gerber == NULL ) // Graphic layer not yet used
418  continue;
419 
420  if( gerber->GetDcodesCount() == 0 )
421  continue;
422 
423  for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ )
424  {
425  D_CODE* aperture = gerber->GetDCODE( ii + FIRST_DCODE );
426 
427  if( aperture == NULL )
428  continue;
429 
430  if( !aperture->m_InUse && !aperture->m_Defined )
431  continue;
432 
433  if( !aperture->m_AperFunction.IsEmpty() )
434  full_list.insert( std::make_pair( aperture->m_AperFunction, 0 ) );
435  }
436  }
437 
438  // Add an empty string to deselect net highlight
440 
441  // Now copy the list to the choice box
442  for( auto ii = full_list.begin(); ii != full_list.end(); ++ii )
443  {
444  m_SelAperAttributesBox->Append( ii->first );
445  }
446 
447  m_SelAperAttributesBox->SetSelection( 0 );
448 }
449 
450 
451 void GERBVIEW_FRAME::OnUpdateDrawMode( wxUpdateUIEvent& aEvent )
452 {
453  switch( aEvent.GetId() )
454  {
456  aEvent.Check( GetDisplayMode() == 0 );
457  break;
458 
460  aEvent.Check( GetDisplayMode() == 1 );
461  break;
462 
464  aEvent.Check( GetDisplayMode() == 2 );
465  break;
466 
467  default:
468  break;
469  }
470 }
471 
472 
473 void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent )
474 {
475  if( !m_DCodeSelector )
476  return;
477 
478  int layer = GetActiveLayer();
479  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
480  int selected = ( gerber ) ? gerber->m_Selected_Tool : 0;
481 
482  aEvent.Enable( gerber != NULL );
483 
484  if( m_DCodeSelector->GetSelectedDCodeId() != selected )
485  {
486  m_DCodeSelector->SetDCodeSelection( selected );
487  // Be sure the selection can be made. If no, set to
488  // a correct value
489  if( gerber )
491  }
492 }
493 
494 
495 void GERBVIEW_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
496 {
497  if( m_SelLayerBox->GetSelection() != GetActiveLayer() )
498  m_SelLayerBox->SetSelection( GetActiveLayer() );
499 }
500 
ACTION_TOOLBAR.
static TOOL_ACTION openDrillFile
static TOOL_ACTION zoomInCenter
Definition: actions.h:91
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
int GetDisplayMode()
Function GetDisplayMode.
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:97
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)
Adds a TOOL_ACTION-based button to the toolbar.
static TOOL_ACTION clearAllLayers
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:...
static TOOL_ACTION zoomFitScreen
Definition: actions.h:94
static TOOL_ACTION millimetersUnits
Definition: actions.h:144
GERBVIEW_FRAME::OnZipFileHistory ID_TB_OPTIONS_SHOW_GBR_MODE_2
GBR_LAYER_BOX_SELECTOR * m_SelLayerBox
void SetDCodeSelection(int aDCodeId)
Function SetDCodeSelection.
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
static TOOL_ACTION dcodeDisplay
static TOOL_ACTION negativeObjectDisplay
static TOOL_ACTION zoomOutCenter
Definition: actions.h:92
wxChoice * m_SelNetnameBox
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:152
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
Function ReCreateVToolbar creates or updates 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:138
static TOOL_ACTION inchesUnits
Definition: actions.h:142
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
int GetSelectedDCodeId()
Function GetSelectedDCodeId.
static TOOL_ACTION togglePolarCoords
Definition: actions.h:147
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:143
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
Function SetActiveLayer returns 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
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:88
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:100
wxStaticText * m_apertText
static TOOL_ACTION highContrastMode
Definition: actions.h:101
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:151
void ClearToolbar()
Clear the toolbar and remove all associated menus.
void ReCreateOptToolbar() override
Create or update the left vertical toolbar (option toolbar)