KiCad PCB EDA Suite
dialog_plot.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) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 
25 #include <kiface_i.h>
26 #include <plotter.h>
27 #include <confirm.h>
28 #include <pcb_edit_frame.h>
29 #include <pcbnew_settings.h>
30 #include <pcbplot.h>
31 #include <gerber_jobfile_writer.h>
32 #include <reporter.h>
35 #include <bitmaps.h>
36 #include <class_board.h>
37 #include <dialog_plot.h>
38 #include <dialog_gendrill.h>
39 #include <wx_html_report_panel.h>
40 #include <tool/tool_manager.h>
41 #include <tools/zone_filler_tool.h>
42 #include <tools/drc_tool.h>
43 #include <math/util.h> // for KiROUND
44 #include <macros.h>
45 
46 
48  DIALOG_PLOT_BASE( aParent ), m_parent( aParent ),
49  m_defaultPenSize( aParent, m_hpglPenLabel, m_hpglPenCtrl, m_hpglPenUnits, true ),
50  m_trackWidthCorrection( aParent, m_widthAdjustLabel, m_widthAdjustCtrl, m_widthAdjustUnits, true )
51 {
52  SetName( DLG_WINDOW_NAME );
53  m_plotOpts = aParent->GetPlotSettings();
55 
56  init_Dialog();
57 
58  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
59  // that requires us to correct the button labels here.
60  m_sdbSizer1OK->SetLabel( _( "Plot" ) );
61  m_sdbSizer1Apply->SetLabel( _( "Generate Drill Files..." ) );
62  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
63  m_sizerButtons->Layout();
64 
65  m_sdbSizer1OK->SetDefault();
66 
67  GetSizer()->Fit( this );
68  GetSizer()->SetSizeHints( this );
69 }
70 
71 
73 {
74  BOARD* board = m_parent->GetBoard();
75  wxFileName fileName;
76 
77  auto cfg = m_parent->GetPcbNewSettings();
78 
79  m_XScaleAdjust = cfg->m_Plot.fine_scale_x;
80  m_YScaleAdjust = cfg->m_Plot.fine_scale_y;
81 
82  m_zoneFillCheck->SetValue( cfg->m_Plot.check_zones_before_plotting );
83 
84  m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
85 
86  // m_PSWidthAdjust is stored in mm in user config
87  m_PSWidthAdjust = KiROUND( cfg->m_Plot.ps_fine_width_adjust * IU_PER_MM );
88 
89  // The reasonable width correction value must be in a range of
90  // [-(MinTrackWidth-1), +(MinClearanceValue-1)] decimils.
93 
94  switch( m_plotOpts.GetFormat() )
95  {
96  default:
97  case PLOT_FORMAT::GERBER: m_plotFormatOpt->SetSelection( 0 ); break;
98  case PLOT_FORMAT::POST: m_plotFormatOpt->SetSelection( 1 ); break;
99  case PLOT_FORMAT::SVG: m_plotFormatOpt->SetSelection( 2 ); break;
100  case PLOT_FORMAT::DXF: m_plotFormatOpt->SetSelection( 3 ); break;
101  case PLOT_FORMAT::HPGL: m_plotFormatOpt->SetSelection( 4 ); break;
102  case PLOT_FORMAT::PDF: m_plotFormatOpt->SetSelection( 5 ); break;
103  }
104 
105  // Set units and value for HPGL pen size (this param is in mils).
107 
108  // Test for a reasonable scale value. Set to 1 if problem
112 
115 
116  // Test for a reasonable PS width correction value. Set to 0 if problem.
117  if( m_PSWidthAdjust < m_widthAdjustMinValue || m_PSWidthAdjust > m_widthAdjustMaxValue )
118  m_PSWidthAdjust = 0.;
119 
121 
124 
125  // Could devote a PlotOrder() function in place of UIOrder().
126  m_layerList = board->GetEnabledLayers().UIOrder();
127 
128  // Populate the check list box by all enabled layers names
129  for( LSEQ seq = m_layerList; seq; ++seq )
130  {
131  PCB_LAYER_ID layer = *seq;
132 
133  int checkIndex = m_layerCheckListBox->Append( board->GetLayerName( layer ) );
134 
135  if( m_plotOpts.GetLayerSelection()[layer] )
136  m_layerCheckListBox->Check( checkIndex );
137  }
138 
139  // Option for using proper Gerber extensions. Note also Protel extensions are
140  // a broken feature. However, for now, we need to handle it.
142 
143  // Option for including Gerber attributes, from Gerber X2 format, in the output
144  // In X1 format, they will be added as comments
146 
147  // Option for including Gerber netlist info (from Gerber X2 format) in the output
149 
150  // Option to generate a Gerber job file
152 
153  // Gerber precision for coordinates
154  m_coordFormatCtrl->SetSelection( m_plotOpts.GetGerberPrecision() == 5 ? 0 : 1 );
155 
156  // SVG precision and units for coordinates
158  m_svgUnits->SetSelection( m_plotOpts.GetSvgUseInch() );
159 
160  // Option for excluding contents of "Edges Pcb" layer
162 
163  // Option to exclude pads from silkscreen layers
165 
166  // Option to tent vias
168 
169  // Option to use aux origin
171 
172  // Option to plot page references:
174 
175  // Options to plot texts on footprints
179 
180  // Options to plot pads and vias holes
181  m_drillShapeOpt->SetSelection( m_plotOpts.GetDrillMarksType() );
182 
183  // Scale option
184  m_scaleOpt->SetSelection( m_plotOpts.GetScaleSelection() );
185 
186  // Plot mode
188 
189  // DXF outline mode
191 
192  // DXF text mode
194 
195  // DXF units selection
196  m_DXF_plotUnits->SetSelection( static_cast<int>( m_plotOpts.GetDXFPlotUnits() ) );
197 
198  // Plot mirror option
199  m_plotMirrorOpt->SetValue( m_plotOpts.GetMirror() );
200 
201  // Put vias on mask layer
203 
204  // Initialize a few other parameters, which can also be modified
205  // from the drill dialog
206  reInitDialog();
207 
208  // Update options values:
209  wxCommandEvent cmd_event;
210  SetPlotFormat( cmd_event );
211  OnSetScaleOpt( cmd_event );
212 }
213 
214 
216 {
217  // after calling the Drill or DRC dialogs some parameters can be modified....
218 
219  // Output directory
221 
222  // Origin of coordinates:
224 
225  int knownViolations = 0;
226  int exclusions = 0;
227 
228  for( MARKER_PCB* marker : m_parent->GetBoard()->Markers() )
229  {
230  if( marker->IsExcluded() )
231  exclusions++;
232  else
233  knownViolations++;
234  }
235 
236  if( knownViolations || exclusions )
237  {
239  knownViolations,
240  exclusions ) );
241  m_DRCExclusionsWarning->Show();
242  }
243  else
244  m_DRCExclusionsWarning->Hide();
245 }
246 
247 
248 // A helper function to show a popup menu, when the dialog is right clicked.
249 void DIALOG_PLOT::OnRightClick( wxMouseEvent& event )
250 {
251  PopupMenu( m_popMenu );
252 }
253 
254 
255 // Select or deselect groups of layers in the layers list:
256 void DIALOG_PLOT::OnPopUpLayers( wxCommandEvent& event )
257 {
258  // Build a list of layers for usual fabrication:
259  // copper layers + tech layers without courtyard
260  LSET fab_layer_set = ( LSET::AllCuMask() | LSET::AllTechMask() )
261  & ~LSET( 2, B_CrtYd, F_CrtYd );
262 
263  switch( event.GetId() )
264  {
265  case ID_LAYER_FAB: // Select layers usually needed to build a board
266  for( unsigned i = 0; i < m_layerList.size(); i++ )
267  {
268  LSET layermask( m_layerList[ i ] );
269 
270  if( ( layermask & fab_layer_set ).any() )
271  m_layerCheckListBox->Check( i, true );
272  else
273  m_layerCheckListBox->Check( i, false );
274  }
275  break;
276 
278  for( unsigned i = 0; i < m_layerList.size(); i++ )
279  {
280  if( IsCopperLayer( m_layerList[i] ) )
281  m_layerCheckListBox->Check( i, true );
282  }
283  break;
284 
286  for( unsigned i = 0; i < m_layerList.size(); i++ )
287  {
288  if( IsCopperLayer( m_layerList[i] ) )
289  m_layerCheckListBox->Check( i, false );
290  }
291  break;
292 
294  for( unsigned i = 0; i < m_layerList.size(); i++ )
295  m_layerCheckListBox->Check( i, true );
296  break;
297 
299  for( unsigned i = 0; i < m_layerList.size(); i++ )
300  m_layerCheckListBox->Check( i, false );
301  break;
302 
303  default:
304  break;
305  }
306 }
307 
308 
309 void DIALOG_PLOT::CreateDrillFile( wxCommandEvent& event )
310 {
311  // Be sure drill file use the same settings (axis option, plot directory)
312  // as plot files:
314 
315  DIALOG_GENDRILL dlg( m_parent, this );
316  dlg.ShowModal();
317 
318  // a few plot settings can be modified: take them in account
320  reInitDialog();
321 }
322 
323 
324 void DIALOG_PLOT::OnChangeDXFPlotMode( wxCommandEvent& event )
325 {
326  // m_DXF_plotTextStrokeFontOpt is disabled if m_DXF_plotModeOpt
327  // is checked (plot in DXF polygon mode)
328  m_DXF_plotTextStrokeFontOpt->Enable( !m_DXF_plotModeOpt->GetValue() );
329 
330  // if m_DXF_plotTextStrokeFontOpt option is disabled (plot DXF in polygon mode),
331  // force m_DXF_plotTextStrokeFontOpt to true to use Pcbnew stroke font
332  if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() )
333  m_DXF_plotTextStrokeFontOpt->SetValue( true );
334 }
335 
336 
337 void DIALOG_PLOT::OnSetScaleOpt( wxCommandEvent& event )
338 {
339  /* Disable sheet reference for scale != 1:1 */
340  bool scale1 = ( m_scaleOpt->GetSelection() == 1 );
341 
342  m_plotSheetRef->Enable( scale1 );
343 
344  if( !scale1 )
345  m_plotSheetRef->SetValue( false );
346 }
347 
348 
349 void DIALOG_PLOT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
350 {
351  // Build the absolute path of current output directory to preselect it in the file browser.
352  wxString path = ExpandEnvVarSubstitutions( m_outputDirectoryName->GetValue(), &Prj() );
353  path = Prj().AbsolutePath( path );
354 
355  wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
356 
357  if( dirDialog.ShowModal() == wxID_CANCEL )
358  return;
359 
360  wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
361 
362  wxFileName fn( Prj().AbsolutePath( m_parent->GetBoard()->GetFileName() ) );
363  wxString defaultPath = fn.GetPathWithSep();
364  wxString msg;
365  wxFileName relPathTest; // Used to test if we can make the path relative
366 
367  relPathTest.Assign( dirDialog.GetPath() );
368 
369  // Test if making the path relative is possible before asking the user if they want to do it
370  if( relPathTest.MakeRelativeTo( defaultPath ) )
371  {
372  msg.Printf( _( "Do you want to use a path relative to\n\"%s\"" ),
373  GetChars( defaultPath ) );
374 
375  wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
376  wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
377 
378  if( dialog.ShowModal() == wxID_YES )
379  dirName.MakeRelativeTo( defaultPath );
380  }
381 
382  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
383 }
384 
385 
387 {
388  // plot format id's are ordered like displayed in m_plotFormatOpt
391 
392  return plotFmt[m_plotFormatOpt->GetSelection()];
393 }
394 
395 
396 // Enable or disable widgets according to the plot format selected
397 // and clear also some optional values
398 void DIALOG_PLOT::SetPlotFormat( wxCommandEvent& event )
399 {
400  // this option exist only in DXF format:
402 
403  // The alert message about non 0 solder mask min width and margin is shown
404  // only in gerber format and if min mask width or mask margin is not 0
405  BOARD* board = m_parent->GetBoard();
406  const BOARD_DESIGN_SETTINGS& brd_settings = board->GetDesignSettings();
407 
409  ( brd_settings.m_SolderMaskMargin || brd_settings.m_SolderMaskMinWidth ) )
411  else
413 
414 
415  switch( getPlotFormat() )
416  {
417  case PLOT_FORMAT::SVG:
418  case PLOT_FORMAT::PDF:
419  m_drillShapeOpt->Enable( true );
420  m_plotModeOpt->Enable( false );
422  m_plotMirrorOpt->Enable( true );
423  m_useAuxOriginCheckBox->Enable( false );
424  m_useAuxOriginCheckBox->SetValue( false );
425  m_defaultPenSize.Enable( false );
426  m_excludeEdgeLayerOpt->Enable( true );
427  m_scaleOpt->Enable( false );
428  m_scaleOpt->SetSelection( 1 );
429  m_fineAdjustXCtrl->Enable( false );
430  m_fineAdjustYCtrl->Enable( false );
432  m_plotPSNegativeOpt->Enable( true );
433  m_forcePSA4OutputOpt->Enable( false );
434  m_forcePSA4OutputOpt->SetValue( false );
435 
438  else
440 
445  break;
446 
447  case PLOT_FORMAT::POST:
448  m_drillShapeOpt->Enable( true );
449  m_plotModeOpt->Enable( true );
450  m_plotMirrorOpt->Enable( true );
451  m_useAuxOriginCheckBox->Enable( false );
452  m_useAuxOriginCheckBox->SetValue( false );
453  m_defaultPenSize.Enable( false );
454  m_excludeEdgeLayerOpt->Enable( true );
455  m_scaleOpt->Enable( true );
456  m_fineAdjustXCtrl->Enable( true );
457  m_fineAdjustYCtrl->Enable( true );
459  m_plotPSNegativeOpt->Enable( true );
460  m_forcePSA4OutputOpt->Enable( true );
461 
467  break;
468 
469  case PLOT_FORMAT::GERBER:
470  m_drillShapeOpt->Enable( false );
471  m_drillShapeOpt->SetSelection( 0 );
472  m_plotModeOpt->Enable( false );
474  m_plotMirrorOpt->Enable( false );
475  m_plotMirrorOpt->SetValue( false );
476  m_useAuxOriginCheckBox->Enable( true );
477  m_defaultPenSize.Enable( false );
478  m_excludeEdgeLayerOpt->Enable( true );
479  m_scaleOpt->Enable( false );
480  m_scaleOpt->SetSelection( 1 );
481  m_fineAdjustXCtrl->Enable( false );
482  m_fineAdjustYCtrl->Enable( false );
484  m_plotPSNegativeOpt->Enable( false );
485  m_plotPSNegativeOpt->SetValue( false );
486  m_forcePSA4OutputOpt->Enable( false );
487  m_forcePSA4OutputOpt->SetValue( false );
488 
494  break;
495 
496  case PLOT_FORMAT::HPGL:
497  m_drillShapeOpt->Enable( true );
498  m_plotModeOpt->Enable( true );
499  m_plotMirrorOpt->Enable( true );
500  m_useAuxOriginCheckBox->Enable( false );
501  m_useAuxOriginCheckBox->SetValue( false );
502  m_defaultPenSize.Enable( true );
503  m_excludeEdgeLayerOpt->Enable( true );
504  m_scaleOpt->Enable( true );
505  m_fineAdjustXCtrl->Enable( false );
506  m_fineAdjustYCtrl->Enable( false );
508  m_plotPSNegativeOpt->SetValue( false );
509  m_plotPSNegativeOpt->Enable( false );
510  m_forcePSA4OutputOpt->Enable( true );
511 
517  break;
518 
519  case PLOT_FORMAT::DXF:
520  m_drillShapeOpt->Enable( true );
521  m_plotModeOpt->Enable( false );
523  m_plotMirrorOpt->Enable( false );
524  m_plotMirrorOpt->SetValue( false );
525  m_useAuxOriginCheckBox->Enable( true );
526  m_defaultPenSize.Enable( false );
527  m_excludeEdgeLayerOpt->Enable( true );
528  m_scaleOpt->Enable( false );
529  m_scaleOpt->SetSelection( 1 );
530  m_fineAdjustXCtrl->Enable( false );
531  m_fineAdjustYCtrl->Enable( false );
533  m_plotPSNegativeOpt->Enable( false );
534  m_plotPSNegativeOpt->SetValue( false );
535  m_forcePSA4OutputOpt->Enable( false );
536  m_forcePSA4OutputOpt->SetValue( false );
537 
543 
544  OnChangeDXFPlotMode( event );
545  break;
546 
548  break;
549  }
550 
551  /* Update the interlock between scale and frame reference
552  * (scaling would mess up the frame border...) */
553  OnSetScaleOpt( event );
554 
555  Layout();
556  m_MainSizer->SetSizeHints( this );
557 }
558 
559 
560 // A helper function to "clip" aValue between aMin and aMax
561 // and write result in * aResult
562 // return false if clipped, true if aValue is just copied into * aResult
563 static bool setDouble( double* aResult, double aValue, double aMin, double aMax )
564 {
565  if( aValue < aMin )
566  {
567  *aResult = aMin;
568  return false;
569  }
570  else if( aValue > aMax )
571  {
572  *aResult = aMax;
573  return false;
574  }
575 
576  *aResult = aValue;
577  return true;
578 }
579 
580 
581 static bool setInt( int* aResult, int aValue, int aMin, int aMax )
582 {
583  if( aValue < aMin )
584  {
585  *aResult = aMin;
586  return false;
587  }
588  else if( aValue > aMax )
589  {
590  *aResult = aMax;
591  return false;
592  }
593 
594  *aResult = aValue;
595  return true;
596 }
597 
598 
600 {
601  REPORTER& reporter = m_messagesPanel->Reporter();
602  int sel;
603  PCB_PLOT_PARAMS tempOptions;
604 
605  tempOptions.SetExcludeEdgeLayer( m_excludeEdgeLayerOpt->GetValue() );
606  tempOptions.SetSubtractMaskFromSilk( m_subtractMaskFromSilk->GetValue() );
607  tempOptions.SetPlotFrameRef( m_plotSheetRef->GetValue() );
608  tempOptions.SetSketchPadsOnFabLayers( m_sketchPadsOnFabLayers->GetValue());
609  tempOptions.SetUseAuxOrigin( m_useAuxOriginCheckBox->GetValue() );
610  tempOptions.SetPlotValue( m_plotModuleValueOpt->GetValue() );
611  tempOptions.SetPlotReference( m_plotModuleRefOpt->GetValue() );
612  tempOptions.SetPlotInvisibleText( m_plotInvisibleText->GetValue() );
613  tempOptions.SetScaleSelection( m_scaleOpt->GetSelection() );
614 
615  sel = m_drillShapeOpt->GetSelection();
616  tempOptions.SetDrillMarksType( static_cast<PCB_PLOT_PARAMS::DrillMarksType>( sel ) );
617 
618  tempOptions.SetMirror( m_plotMirrorOpt->GetValue() );
619  tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED );
620  tempOptions.SetDXFPlotPolygonMode( m_DXF_plotModeOpt->GetValue() );
621 
622  sel = m_DXF_plotUnits->GetSelection();
623  tempOptions.SetDXFPlotUnits( static_cast<DXF_PLOTTER::DXF_UNITS>( sel ) );
624 
625  tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() );
626 
627  if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() ) // Currently, only DXF supports this option
628  tempOptions.SetTextMode( PLOT_TEXT_MODE::DEFAULT );
629  else
632 
633  // Update settings from text fields. Rewrite values back to the fields,
634  // since the values may have been constrained by the setters.
635  wxString msg;
636 
637  // read HPLG pen size (this param is stored in mils)
638  // However, due to issues when converting this value from or to mm
639  // that can slightly change the value, update this param only if it
640  // is in use
642  {
643  if( !tempOptions.SetHPGLPenDiameter( m_defaultPenSize.GetValue() / IU_PER_MILS ) )
644  {
646  msg.Printf( _( "HPGL pen size constrained." ) );
647  reporter.Report( msg, RPT_SEVERITY_INFO );
648  }
649  }
650  else // keep the last value (initial value if no HPGL plot made)
652 
653  // X scale
654  double tmpDouble;
655  msg = m_fineAdjustXCtrl->GetValue();
656  msg.ToDouble( &tmpDouble );
657 
658  if( !setDouble( &m_XScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
659  {
660  msg.Printf( wxT( "%f" ), m_XScaleAdjust );
661  m_fineAdjustXCtrl->SetValue( msg );
662  msg.Printf( _( "X scale constrained." ) );
663  reporter.Report( msg, RPT_SEVERITY_INFO );
664  }
665 
666  // Y scale
667  msg = m_fineAdjustYCtrl->GetValue();
668  msg.ToDouble( &tmpDouble );
669 
670  if( !setDouble( &m_YScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
671  {
672  msg.Printf( wxT( "%f" ), m_YScaleAdjust );
673  m_fineAdjustYCtrl->SetValue( msg );
674  msg.Printf( _( "Y scale constrained." ) );
675  reporter.Report( msg, RPT_SEVERITY_INFO );
676  }
677 
678  auto cfg = m_parent->GetPcbNewSettings();
679 
681  cfg->m_Plot.fine_scale_y = m_YScaleAdjust;
682 
683  cfg->m_Plot.check_zones_before_plotting = m_zoneFillCheck->GetValue();
684 
685  // PS Width correction
688  {
690  msg.Printf( _( "Width correction constrained. "
691  "The reasonable width correction value must be in a range of "
692  " [%s; %s] (%s) for current design rules." ),
696  reporter.Report( msg, RPT_SEVERITY_WARNING );
697  }
698 
699  // Store m_PSWidthAdjust in mm in user config
700  cfg->m_Plot.ps_fine_width_adjust = Iu2Millimeter( m_PSWidthAdjust );
701 
702  tempOptions.SetFormat( getPlotFormat() );
703 
704  tempOptions.SetUseGerberProtelExtensions( m_useGerberExtensions->GetValue() );
705  tempOptions.SetUseGerberX2format( m_useGerberX2Format->GetValue() );
706  tempOptions.SetIncludeGerberNetlistInfo( m_useGerberNetAttributes->GetValue() );
707  tempOptions.SetCreateGerberJobFile( m_generateGerberJobFile->GetValue() );
708 
709  tempOptions.SetGerberPrecision( m_coordFormatCtrl->GetSelection() == 0 ? 5 : 6 );
710  tempOptions.SetSvgPrecision( m_svgPrecsision->GetValue(), m_svgUnits->GetSelection() );
711 
712  LSET selectedLayers;
713  for( unsigned i = 0; i < m_layerList.size(); i++ )
714  {
715  if( m_layerCheckListBox->IsChecked( i ) )
716  selectedLayers.set( m_layerList[i] );
717  }
718  // Get a list of copper layers that aren't being used by inverting enabled layers.
719  LSET disabledCopperLayers = LSET::AllCuMask() & ~m_parent->GetBoard()->GetEnabledLayers();
720  // Enable all of the disabled copper layers.
721  // If someone enables more copper layers they will be selected by default.
722  selectedLayers = selectedLayers | disabledCopperLayers;
723  tempOptions.SetLayerSelection( selectedLayers );
724 
725  tempOptions.SetNegative( m_plotPSNegativeOpt->GetValue() );
726  tempOptions.SetA4Output( m_forcePSA4OutputOpt->GetValue() );
727 
728  // Set output directory and replace backslashes with forward ones
729  wxString dirStr;
730  dirStr = m_outputDirectoryName->GetValue();
731  dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
732  tempOptions.SetOutputDirectory( dirStr );
733 
734  if( !m_plotOpts.IsSameAs( tempOptions, false ) )
735  {
736  // First, mark board as modified only for parameters saved in file
737  if( !m_plotOpts.IsSameAs( tempOptions, true ) )
738  m_parent->OnModify();
739 
740  // Now, save any change, for the session
741  m_parent->SetPlotSettings( tempOptions );
742  m_plotOpts = tempOptions;
743  }
744 }
745 
746 
747 void DIALOG_PLOT::OnGerberX2Checked( wxCommandEvent& event )
748 {
749  // Currently: do nothing
750 }
751 
752 
753 void DIALOG_PLOT::Plot( wxCommandEvent& event )
754 {
755  BOARD* board = m_parent->GetBoard();
756 
758 
759  SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
761 
763 
765 
766  // If no layer selected, we have nothing plotted.
767  // Prompt user if it happens because he could think there is a bug in Pcbnew.
768  if( !m_plotOpts.GetLayerSelection().any() )
769  {
770  DisplayError( this, _( "No layer selected, Nothing to plot" ) );
771  return;
772  }
773 
774  // Create output directory if it does not exist (also transform it in
775  // absolute form). Bail if it fails
777  wxFileName outputDir = wxFileName::DirName( path );
778  wxString boardFilename = m_parent->GetBoard()->GetFileName();
779  REPORTER& reporter = m_messagesPanel->Reporter();
780 
781  if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
782  {
783  wxString msg;
784  msg.Printf( _( "Could not write plot files to folder \"%s\"." ),
785  GetChars( outputDir.GetPath() ) );
786  DisplayError( this, msg );
787  return;
788  }
789 
790  if( m_zoneFillCheck->GetValue() )
791  m_parent->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
792 
793  m_plotOpts.SetAutoScale( false );
794 
795  switch( m_plotOpts.GetScaleSelection() )
796  {
797  default: m_plotOpts.SetScale( 1 ); break;
798  case 0: m_plotOpts.SetAutoScale( true ); break;
799  case 2: m_plotOpts.SetScale( 1.5 ); break;
800  case 3: m_plotOpts.SetScale( 2 ); break;
801  case 4: m_plotOpts.SetScale( 3 ); break;
802  }
803 
804  /* If the scale factor edit controls are disabled or the scale value
805  * is 0, don't adjust the base scale factor. This fixes a bug when
806  * the default scale adjust is initialized to 0 and saved in program
807  * settings resulting in a divide by zero fault.
808  */
810  {
811  if( m_XScaleAdjust != 0.0 )
813 
814  if( m_YScaleAdjust != 0.0 )
816 
818  }
819 
820  wxString file_ext( GetDefaultPlotExtension( m_plotOpts.GetFormat() ) );
821 
822  // Test for a reasonable scale value
823  // XXX could this actually happen? isn't it constrained in the apply
824  // function?
826  DisplayInfoMessage( this, _( "Warning: Scale option set to a very small value" ) );
827 
829  DisplayInfoMessage( this, _( "Warning: Scale option set to a very large value" ) );
830 
831  GERBER_JOBFILE_WRITER jobfile_writer( board, &reporter );
832 
833  // Save the current plot options in the board
835 
836  wxBusyCursor dummy;
837 
838  for( LSEQ seq = m_plotOpts.GetLayerSelection().UIOrder(); seq; ++seq )
839  {
840  PCB_LAYER_ID layer = *seq;
841 
842  // All copper layers that are disabled are actually selected
843  // This is due to wonkyness in automatically selecting copper layers
844  // for plotting when adding more than two layers to a board.
845  // If plot options become accessible to the layers setup dialog
846  // please move this functionality there!
847  // This skips a copper layer if it is actually disabled on the board.
848  if( ( LSET::AllCuMask() & ~board->GetEnabledLayers() )[layer] )
849  continue;
850 
851  // Pick the basename from the board file
852  wxFileName fn( boardFilename );
853 
854  // Use Gerber Extensions based on layer number
855  // (See http://en.wikipedia.org/wiki/Gerber_File)
857  file_ext = GetGerberProtelExtension( layer );
858 
859  BuildPlotFileName( &fn, outputDir.GetPath(), board->GetLayerName( layer ), file_ext );
860  wxString fullname = fn.GetFullName();
861  jobfile_writer.AddGbrFile( layer, fullname );
862 
863  LOCALE_IO toggle;
864 
865  PLOTTER* plotter = StartPlotBoard( board, &m_plotOpts, layer, fn.GetFullPath(), wxEmptyString );
866 
867  // Print diags in messages box:
868  wxString msg;
869 
870  if( plotter )
871  {
872  PlotOneBoardLayer( board, plotter, layer, m_plotOpts );
873  plotter->EndPlot();
874  delete plotter->RenderSettings();
875  delete plotter;
876 
877  msg.Printf( _( "Plot file \"%s\" created." ), fn.GetFullPath() );
878  reporter.Report( msg, RPT_SEVERITY_ACTION );
879  }
880  else
881  {
882  msg.Printf( _( "Unable to create file \"%s\"." ), fn.GetFullPath() );
883  reporter.Report( msg, RPT_SEVERITY_ERROR );
884  }
885 
886  wxSafeYield(); // displays report message.
887  }
888 
890  {
891  // Pick the basename from the board file
892  wxFileName fn( boardFilename );
893  // Build gerber job file from basename
894  BuildPlotFileName( &fn, outputDir.GetPath(), "job", GerberJobFileExtension );
895  jobfile_writer.CreateJobFile( fn.GetFullPath() );
896  }
897 }
898 
899 
900 void DIALOG_PLOT::onRunDRC( wxCommandEvent& event )
901 {
902  PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
903 
904  if( parent )
905  {
906  DRC_TOOL* drcTool = parent->GetToolManager()->GetTool<DRC_TOOL>();
907 
908  // First close an existing dialog if open
909  // (low probability, but can happen)
910  drcTool->DestroyDRCDialog();
911 
912  // Open a new drc dialod, with the right parent frame, and in Modal Mode
913  drcTool->ShowDRCDialog( this );
914 
915  // Update DRC warnings on return to this dialog
916  reInitDialog();
917  }
918 }
919 
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:719
void SetUseGerberProtelExtensions(bool aUse)
void SetPlotReference(bool aFlag)
void SetExcludeEdgeLayer(bool aFlag)
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
WX_HTML_REPORT_PANEL * m_messagesPanel
wxStaticBoxSizer * m_HPGLOptionsSizer
void SetScaleSelection(int aSelection)
LSEQ m_layerList
Definition: dialog_plot.h:47
void SetIncludeGerberNetlistInfo(bool aUse)
const BITMAP_OPAQUE folder_xpm[1]
Definition: folder.cpp:20
void SetDXFPlotPolygonMode(bool aFlag)
double m_YScaleAdjust
Definition: dialog_plot.h:50
bool GetCreateGerberJobFile() const
void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
wxCheckBox * m_useGerberExtensions
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
void SetGerberPrecision(int aPrecision)
void OnOutputDirectoryBrowseClicked(wxCommandEvent &event) override
wxButton * m_sdbSizer1Cancel
void SetPlotViaOnMaskLayer(bool aFlag)
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer.
bool GetPlotFrameRef() const
bool CreateJobFile(const wxString &aFullFilename)
Creates a Gerber job file.
bool GetDXFPlotPolygonMode() const
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
wxString GetDefaultPlotExtension(PLOT_FORMAT aFormat)
Returns the default plot extension for a format.
void SetLayerSelection(LSET aSelection)
void OnGerberX2Checked(wxCommandEvent &event) override
void SetUseAuxOrigin(bool aAux)
This file is part of the common library.
void SetSketchPadLineWidth(int aWidth)
int GetSmallestClearanceValue()
Function GetSmallestClearanceValue.
static constexpr double IU_PER_MM
Mock up a conversion function.
void OnChangeDXFPlotMode(wxCommandEvent &event) override
void PlotOneBoardLayer(BOARD *aBoard, PLOTTER *aPlotter, PCB_LAYER_ID aLayer, const PCB_PLOT_PARAMS &aPlotOpt)
Function PlotOneBoardLayer main function to plot one copper or technical layer.
wxCheckBox * m_plotPSNegativeOpt
#define PLOT_MIN_SCALE
Definition: pcbplot.h:56
MARKERS & Markers()
Definition: class_board.h:257
wxCheckBox * m_excludeEdgeLayerOpt
void SetCreateGerberJobFile(bool aCreate)
void onRunDRC(wxCommandEvent &event) override
void SetMirror(bool aFlag)
wxButton * m_sdbSizer1OK
const wxString GetGerberProtelExtension(LAYER_NUM aLayer)
Function GetGerberProtelExtension.
Definition: pcbplot.cpp:48
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:531
wxCheckBox * m_plotMirrorOpt
void SetTextMode(PLOT_TEXT_MODE aVal)
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
void ShowDRCDialog(wxWindow *aParent)
Open a dialog and prompts the user, then if a test run button is clicked, runs the test(s) and create...
Definition: drc_tool.cpp:70
wxCheckBox * m_zoneFillCheck
void SetDrillMarksType(DrillMarksType aVal)
PCBNEW_SETTINGS * GetPcbNewSettings()
const wxString ExpandEnvVarSubstitutions(const wxString &aString, PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:581
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
wxChoice * m_plotFormatOpt
static LSET AllTechMask()
Function AllTechMask returns a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:789
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, bool aUseMils, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:495
virtual const PCB_PLOT_PARAMS & GetPlotSettings() const
Function GetPlotSettings returns the PCB_PLOT_PARAMS for the BOARD owned by this frame.
wxChoice * m_coordFormatCtrl
void CreateDrillFile(wxCommandEvent &event) override
const wxString & GetFileName() const
Definition: class_board.h:244
Classes used to generate a Gerber job file in JSON.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
wxStaticBoxSizer * m_SizerDXF_options
double GetScale() const
UNIT_BINDER m_trackWidthCorrection
Definition: dialog_plot.h:60
void SetA4Output(int aForce)
bool GetUseGerberX2format() const
double m_XScaleAdjust
Definition: dialog_plot.h:48
wxButton * m_sdbSizer1Apply
wxTextCtrl * m_fineAdjustYCtrl
wxCheckBox * m_DXF_plotModeOpt
VTBL_ENTRY const wxString AbsolutePath(const wxString &aFileName) const
Function AbsolutePath fixes up aFileName if it is relative to the project's directory to be an absolu...
Definition: project.cpp:272
This file contains miscellaneous commonly used macros and functions.
bool GetMirror() const
void SetPlotValue(bool aFlag)
EDA_UNITS GetUserUnits() const
Definition: dialog_shim.h:131
wxBoxSizer * m_SizerSolderMaskAlert
Board plot function definition file.
int GetLineThickness(PCB_LAYER_ID aLayer) const
Function GetLineThickness Returns the default graphic segment thickness from the layer class for the ...
wxCheckBox * m_plotSheetRef
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
virtual bool EndPlot()=0
void SetPlotFrameRef(bool aFlag)
void SetPlotFormat(wxCommandEvent &event) override
void Plot(wxCommandEvent &event) override
wxTextCtrl * m_fineAdjustXCtrl
Class DIALOG_PLOT_BASE.
PCB_LAYER_ID
A quick note on layer IDs:
bool GetA4Output() const
ZONE_FILLER_TOOL.
int GetGerberPrecision() const
wxSpinCtrl * m_svgPrecsision
GERBER_JOBFILE_WRITER is a class used to create Gerber job file a Gerber job file stores info to make...
LSET is a set of PCB_LAYER_IDs.
PLOT_FORMAT GetFormat() const
PCB_EDIT_FRAME * m_parent
Definition: dialog_plot.h:46
int m_widthAdjustMaxValue
Definition: dialog_plot.h:57
bool GetUseGerberProtelExtensions() const
void SetDXFPlotUnits(DXF_PLOTTER::DXF_UNITS aUnit)
void SetColorSettings(COLOR_SETTINGS *aSettings)
PLOT_FORMAT getPlotFormat()
unsigned GetSvgPrecision() const
PLOT_FORMAT
Enum PlotFormat is the set of supported output plot formats.
Definition: plotter.h:51
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
static bool setDouble(double *aResult, double aValue, double aMin, double aMax)
bool EnsureFileDirectoryExists(wxFileName *aTargetFullFileName, const wxString &aBaseFilename, REPORTER *aReporter)
Make aTargetFullFileName absolute and create the path of this file if it doesn't yet exist.
Definition: common.cpp:609
REPORTER & Reporter()
returns the reporter object that reports to this panel
#define PLOT_MAX_SCALE
Definition: pcbplot.h:57
bool GetIncludeGerberNetlistInfo() const
int m_PSWidthAdjust
Definition: dialog_plot.h:52
const std::string GerberJobFileExtension
Definition of file extensions used in Kicad.
PLOT_TEXT_MODE GetTextMode() const
wxCheckBox * m_forcePSA4OutputOpt
void OnPopUpLayers(wxCommandEvent &event) override
void SetSubtractMaskFromSilk(bool aSubtract)
void AddGbrFile(PCB_LAYER_ID aLayer, wxString &aFilename)
add a gerber file name and type in job file list
void setPlotModeChoiceSelection(EDA_DRAW_MODE_T aPlotMode)
Definition: dialog_plot.h:84
void SetUseGerberX2format(bool aUse)
virtual void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings)
AppSettings * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
void OnSetScaleOpt(wxCommandEvent &event) override
wxStaticBoxSizer * m_GerberOptionsSizer
wxCheckBox * m_useGerberNetAttributes
void SetOutputDirectory(wxString aDir)
wxChoice * m_DXF_plotUnits
void SetFormat(PLOT_FORMAT aFormat)
int m_widthAdjustMinValue
Definition: dialog_plot.h:56
wxCheckBox * m_generateGerberJobFile
PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board.
wxTextCtrl * m_outputDirectoryName
void SetPlotInvisibleText(bool aFlag)
void SetScale(double aVal)
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
wxCheckBox * m_DXF_plotTextStrokeFontOpt
PCB_PLOT_PARAMS m_plotOpts
Definition: dialog_plot.h:64
void SetNegative(bool aFlag)
bool GetPlotValue() const
void SetSvgPrecision(unsigned aPrecision, bool aUseInch)
wxString GetOutputDirectory() const
void SetFineScaleAdjustX(double aVal)
wxChoice * m_scaleOpt
void BuildPlotFileName(wxFileName *aFilename, const wxString &aOutputDir, const wxString &aSuffix, const wxString &aExtension)
Function BuildPlotFileName (helper function) Complete a plot filename: forces the output directory,...
Definition: pcbplot.cpp:373
void reInitDialog()
wxCheckBox * m_plotModuleRefOpt
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
void SetPlotMode(EDA_DRAW_MODE_T aPlotMode)
bool SetHPGLPenDiameter(double aValue)
wxString m_DRCWarningTemplate
Definition: dialog_plot.h:62
Base plotter engine class.
Definition: plotter.h:114
wxBoxSizer * m_sizerButtons
wxCheckBox * m_subtractMaskFromSilk
bool GetSketchPadsOnFabLayers() const
void init_Dialog()
Definition: dialog_plot.cpp:72
wxCheckBox * m_plotNoViaOnMaskOpt
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:147
wxCheckBox * m_plotModuleValueOpt
bool GetPlotViaOnMaskLayer() const
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153
wxChoice * m_drillShapeOpt
Board layer functions and definitions.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
void applyPlotSettings()
void SetWidthAdjust(int aVal)
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:178
bool GetSubtractMaskFromSilk() const
#define _(s)
Definition: 3d_actions.cpp:33
static bool setInt(int *aResult, int aValue, int aMin, int aMax)
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
wxCheckBox * m_plotInvisibleText
double GetHPGLPenDiameter() const
wxCheckBox * m_sketchPadsOnFabLayers
PCB_EDIT_FRAME is the main frame for Pcbnew.
bool IsSameAs(const PCB_PLOT_PARAMS &aPcbPlotParams, bool aCompareOnlySavedPrms) const
Compare current settings to aPcbPlotParams, including not saved parameters in brd file.
#define IU_PER_MILS
Definition: plotter.cpp:138
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
wxCheckBox * m_useAuxOriginCheckBox
DIALOG_PLOT m_Plot
bool GetPlotInvisibleText() const
void SetAutoScale(bool aFlag)
void SetFineScaleAdjustY(double aVal)
wxChoice * m_plotModeOpt
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
int GetScaleSelection() const
UNIT_BINDER m_defaultPenSize
Definition: dialog_plot.h:59
void OnRightClick(wxMouseEvent &event) override
bool GetSvgUseInch() const
wxBitmapButton * m_browseButton
wxBoxSizer * m_MainSizer
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:78
PLOTTER * StartPlotBoard(BOARD *aBoard, PCB_PLOT_PARAMS *aPlotOpts, int aLayer, const wxString &aFullFileName, const wxString &aSheetDesc)
Open a new plotfile using the options (and especially the format) specified in the options and prepar...
bool GetNegative() const
wxCheckBox * m_useGerberX2Format
wxStaticBoxSizer * m_svgOptionsSizer
BOARD * GetBoard() const
bool GetUseAuxOrigin() const
wxCheckListBox * m_layerCheckListBox
void DestroyDRCDialog()
Closes and frees the DRC dialog.
Definition: drc_tool.cpp:121
wxStaticBoxSizer * m_PSOptionsSizer
LSET GetLayerSelection() const
DXF_PLOTTER::DXF_UNITS GetDXFPlotUnits() const
LSEQ UIOrder() const
Definition: lset.cpp:846
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:267
DrillMarksType GetDrillMarksType() const
wxBoxSizer * m_PlotOptionsSizer
bool GetPlotReference() const
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils, EDA_DATA_TYPE aType)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:233
DIALOG_PLOT(PCB_EDIT_FRAME *parent)
Definition: dialog_plot.cpp:47
#define DLG_WINDOW_NAME
wxStaticText * m_DRCExclusionsWarning
void Enable(bool aEnable)
Function Enable Enables/diasables the label, widget and units label.
bool GetExcludeEdgeLayer() const
void SetSketchPadsOnFabLayers(bool aFlag)
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
EDA_DRAW_MODE_T GetPlotMode() const
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:174