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 <locale_io.h>
36 #include <bitmaps.h>
37 #include <board.h>
38 #include <dialog_plot.h>
39 #include <dialog_gendrill.h>
40 #include <wx_html_report_panel.h>
41 #include <tool/tool_manager.h>
42 #include <tools/zone_filler_tool.h>
43 #include <tools/drc_tool.h>
44 #include <math/util.h> // for KiROUND
45 #include <macros.h>
46 
47 
49  DIALOG_PLOT_BASE( aParent ), m_parent( aParent ),
50  m_defaultPenSize( aParent, m_hpglPenLabel, m_hpglPenCtrl, m_hpglPenUnits, true ),
51  m_trackWidthCorrection( aParent, m_widthAdjustLabel, m_widthAdjustCtrl, m_widthAdjustUnits, true )
52 {
53  SetName( DLG_WINDOW_NAME );
54  m_plotOpts = aParent->GetPlotSettings();
56 
57  init_Dialog();
58 
59  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
60  // that requires us to correct the button labels here.
61  m_sdbSizer1OK->SetLabel( _( "Plot" ) );
62  m_sdbSizer1Apply->SetLabel( _( "Generate Drill Files..." ) );
63  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
64  m_sizerButtons->Layout();
65 
66  m_sdbSizer1OK->SetDefault();
67 
68  GetSizer()->Fit( this );
69  GetSizer()->SetSizeHints( this );
70 }
71 
72 
74 {
75  BOARD* board = m_parent->GetBoard();
76  wxFileName fileName;
77 
78  auto cfg = m_parent->GetPcbNewSettings();
79 
80  m_XScaleAdjust = cfg->m_Plot.fine_scale_x;
81  m_YScaleAdjust = cfg->m_Plot.fine_scale_y;
82 
83  m_zoneFillCheck->SetValue( cfg->m_Plot.check_zones_before_plotting );
84 
85  m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
86 
87  // m_PSWidthAdjust is stored in mm in user config
88  m_PSWidthAdjust = KiROUND( cfg->m_Plot.ps_fine_width_adjust * IU_PER_MM );
89 
90  // The reasonable width correction value must be in a range of
91  // [-(MinTrackWidth-1), +(MinClearanceValue-1)] decimils.
94 
95  switch( m_plotOpts.GetFormat() )
96  {
97  default:
98  case PLOT_FORMAT::GERBER: m_plotFormatOpt->SetSelection( 0 ); break;
99  case PLOT_FORMAT::POST: m_plotFormatOpt->SetSelection( 1 ); break;
100  case PLOT_FORMAT::SVG: m_plotFormatOpt->SetSelection( 2 ); break;
101  case PLOT_FORMAT::DXF: m_plotFormatOpt->SetSelection( 3 ); break;
102  case PLOT_FORMAT::HPGL: m_plotFormatOpt->SetSelection( 4 ); break;
103  case PLOT_FORMAT::PDF: m_plotFormatOpt->SetSelection( 5 ); break;
104  }
105 
106  // Set units and value for HPGL pen size (this param is in mils).
108 
109  // Test for a reasonable scale value. Set to 1 if problem
113 
116 
117  // Test for a reasonable PS width correction value. Set to 0 if problem.
118  if( m_PSWidthAdjust < m_widthAdjustMinValue || m_PSWidthAdjust > m_widthAdjustMaxValue )
119  m_PSWidthAdjust = 0.;
120 
122 
125 
126  // Could devote a PlotOrder() function in place of UIOrder().
127  m_layerList = board->GetEnabledLayers().UIOrder();
128 
129  // Populate the check list box by all enabled layers names
130  for( LSEQ seq = m_layerList; seq; ++seq )
131  {
132  PCB_LAYER_ID layer = *seq;
133 
134  int checkIndex = m_layerCheckListBox->Append( board->GetLayerName( layer ) );
135 
136  if( m_plotOpts.GetLayerSelection()[layer] )
137  m_layerCheckListBox->Check( checkIndex );
138  }
139 
140  // Option for disabling Gerber Aperture Macro (for broken Gerber readers)
142 
143  // Option for using proper Gerber extensions. Note also Protel extensions are
144  // a broken feature. However, for now, we need to handle it.
146 
147  // Option for including Gerber attributes, from Gerber X2 format, in the output
148  // In X1 format, they will be added as comments
150 
151  // Option for including Gerber netlist info (from Gerber X2 format) in the output
153 
154  // Option to generate a Gerber job file
156 
157  // Gerber precision for coordinates
158  m_coordFormatCtrl->SetSelection( m_plotOpts.GetGerberPrecision() == 5 ? 0 : 1 );
159 
160  // SVG precision and units for coordinates
162  m_svgUnits->SetSelection( m_plotOpts.GetSvgUseInch() );
163 
164  // Option for excluding contents of "Edges Pcb" layer
166 
167  // Option to exclude pads from silkscreen layers
169 
170  // Option to tent vias
172 
173  // Option to use aux origin
175 
176  // Option to plot page references:
178 
179  // Options to plot texts on footprints
183 
184  // Options to plot pads and vias holes
185  m_drillShapeOpt->SetSelection( m_plotOpts.GetDrillMarksType() );
186 
187  // Scale option
188  m_scaleOpt->SetSelection( m_plotOpts.GetScaleSelection() );
189 
190  // Plot mode
192 
193  // DXF outline mode
195 
196  // DXF text mode
198 
199  // DXF units selection
200  m_DXF_plotUnits->SetSelection( m_plotOpts.GetDXFPlotUnits() == DXF_UNITS::INCHES ? 0 : 1);
201 
202  // Plot mirror option
203  m_plotMirrorOpt->SetValue( m_plotOpts.GetMirror() );
204 
205  // Put vias on mask layer
207 
208  // Initialize a few other parameters, which can also be modified
209  // from the drill dialog
210  reInitDialog();
211 
212  // Update options values:
213  wxCommandEvent cmd_event;
214  SetPlotFormat( cmd_event );
215  OnSetScaleOpt( cmd_event );
216 }
217 
218 
220 {
221  // after calling the Drill or DRC dialogs some parameters can be modified....
222 
223  // Output directory
225 
226  // Origin of coordinates:
228 
229  int knownViolations = 0;
230  int exclusions = 0;
231 
232  for( PCB_MARKER* marker : m_parent->GetBoard()->Markers() )
233  {
234  if( marker->IsExcluded() )
235  exclusions++;
236  else
237  knownViolations++;
238  }
239 
240  if( knownViolations || exclusions )
241  {
243  knownViolations,
244  exclusions ) );
245  m_DRCExclusionsWarning->Show();
246  }
247  else
248  {
249  m_DRCExclusionsWarning->Hide();
250  }
251 
252  BOARD* board = m_parent->GetBoard();
253  const BOARD_DESIGN_SETTINGS& brd_settings = board->GetDesignSettings();
254 
256  ( brd_settings.m_SolderMaskMargin || brd_settings.m_SolderMaskMinWidth ) )
257  {
259  }
260  else
261  {
263  }
264 }
265 
266 
267 // A helper function to show a popup menu, when the dialog is right clicked.
268 void DIALOG_PLOT::OnRightClick( wxMouseEvent& event )
269 {
270  PopupMenu( m_popMenu );
271 }
272 
273 
274 // Select or deselect groups of layers in the layers list:
275 void DIALOG_PLOT::OnPopUpLayers( wxCommandEvent& event )
276 {
277  // Build a list of layers for usual fabrication:
278  // copper layers + tech layers without courtyard
279  LSET fab_layer_set = ( LSET::AllCuMask() | LSET::AllTechMask() )
280  & ~LSET( 2, B_CrtYd, F_CrtYd );
281 
282  switch( event.GetId() )
283  {
284  case ID_LAYER_FAB: // Select layers usually needed to build a board
285  for( unsigned i = 0; i < m_layerList.size(); i++ )
286  {
287  LSET layermask( m_layerList[ i ] );
288 
289  if( ( layermask & fab_layer_set ).any() )
290  m_layerCheckListBox->Check( i, true );
291  else
292  m_layerCheckListBox->Check( i, false );
293  }
294  break;
295 
297  for( unsigned i = 0; i < m_layerList.size(); i++ )
298  {
299  if( IsCopperLayer( m_layerList[i] ) )
300  m_layerCheckListBox->Check( i, true );
301  }
302  break;
303 
305  for( unsigned i = 0; i < m_layerList.size(); i++ )
306  {
307  if( IsCopperLayer( m_layerList[i] ) )
308  m_layerCheckListBox->Check( i, false );
309  }
310  break;
311 
313  for( unsigned i = 0; i < m_layerList.size(); i++ )
314  m_layerCheckListBox->Check( i, true );
315  break;
316 
318  for( unsigned i = 0; i < m_layerList.size(); i++ )
319  m_layerCheckListBox->Check( i, false );
320  break;
321 
322  default:
323  break;
324  }
325 }
326 
327 
328 void DIALOG_PLOT::CreateDrillFile( wxCommandEvent& event )
329 {
330  // Be sure drill file use the same settings (axis option, plot directory)
331  // as plot files:
333 
334  DIALOG_GENDRILL dlg( m_parent, this );
335  dlg.ShowModal();
336 
337  // a few plot settings can be modified: take them in account
339  reInitDialog();
340 }
341 
342 
343 void DIALOG_PLOT::OnChangeDXFPlotMode( wxCommandEvent& event )
344 {
345  // m_DXF_plotTextStrokeFontOpt is disabled if m_DXF_plotModeOpt
346  // is checked (plot in DXF polygon mode)
347  m_DXF_plotTextStrokeFontOpt->Enable( !m_DXF_plotModeOpt->GetValue() );
348 
349  // if m_DXF_plotTextStrokeFontOpt option is disabled (plot DXF in polygon mode),
350  // force m_DXF_plotTextStrokeFontOpt to true to use Pcbnew stroke font
351  if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() )
352  m_DXF_plotTextStrokeFontOpt->SetValue( true );
353 }
354 
355 
356 void DIALOG_PLOT::OnSetScaleOpt( wxCommandEvent& event )
357 {
358  /* Disable sheet reference for scale != 1:1 */
359  bool scale1 = ( m_scaleOpt->GetSelection() == 1 );
360 
361  m_plotSheetRef->Enable( scale1 );
362 
363  if( !scale1 )
364  m_plotSheetRef->SetValue( false );
365 }
366 
367 
368 void DIALOG_PLOT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
369 {
370  // Build the absolute path of current output directory to preselect it in the file browser.
371  wxString path = ExpandEnvVarSubstitutions( m_outputDirectoryName->GetValue(), &Prj() );
372  path = Prj().AbsolutePath( path );
373 
374  wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
375 
376  if( dirDialog.ShowModal() == wxID_CANCEL )
377  return;
378 
379  wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
380 
381  wxFileName fn( Prj().AbsolutePath( m_parent->GetBoard()->GetFileName() ) );
382  wxString defaultPath = fn.GetPathWithSep();
383  wxString msg;
384  wxFileName relPathTest; // Used to test if we can make the path relative
385 
386  relPathTest.Assign( dirDialog.GetPath() );
387 
388  // Test if making the path relative is possible before asking the user if they want to do it
389  if( relPathTest.MakeRelativeTo( defaultPath ) )
390  {
391  msg.Printf( _( "Do you want to use a path relative to\n\"%s\"" ), defaultPath );
392 
393  wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
394  wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
395 
396  if( dialog.ShowModal() == wxID_YES )
397  dirName.MakeRelativeTo( defaultPath );
398  }
399 
400  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
401 }
402 
403 
405 {
406  // plot format id's are ordered like displayed in m_plotFormatOpt
409 
410  return plotFmt[m_plotFormatOpt->GetSelection()];
411 }
412 
413 
414 // Enable or disable widgets according to the plot format selected
415 // and clear also some optional values
416 void DIALOG_PLOT::SetPlotFormat( wxCommandEvent& event )
417 {
418  // this option exist only in DXF format:
420 
421  // The alert message about non 0 solder mask min width and margin is shown
422  // only in gerber format and if min mask width or mask margin is not 0
423  BOARD* board = m_parent->GetBoard();
424  const BOARD_DESIGN_SETTINGS& brd_settings = board->GetDesignSettings();
425 
427  ( brd_settings.m_SolderMaskMargin || brd_settings.m_SolderMaskMinWidth ) )
428  {
430  }
431  else
432  {
434  }
435 
436 
437  switch( getPlotFormat() )
438  {
439  case PLOT_FORMAT::SVG:
440  case PLOT_FORMAT::PDF:
441  m_drillShapeOpt->Enable( true );
442  m_plotModeOpt->Enable( false );
444  m_plotMirrorOpt->Enable( true );
445  m_useAuxOriginCheckBox->Enable( false );
446  m_useAuxOriginCheckBox->SetValue( false );
447  m_defaultPenSize.Enable( false );
448  m_excludeEdgeLayerOpt->Enable( true );
449  m_scaleOpt->Enable( false );
450  m_scaleOpt->SetSelection( 1 );
451  m_fineAdjustXCtrl->Enable( false );
452  m_fineAdjustYCtrl->Enable( false );
454  m_plotPSNegativeOpt->Enable( true );
455  m_forcePSA4OutputOpt->Enable( false );
456  m_forcePSA4OutputOpt->SetValue( false );
457 
460  else
462 
467  break;
468 
469  case PLOT_FORMAT::POST:
470  m_drillShapeOpt->Enable( true );
471  m_plotModeOpt->Enable( true );
472  m_plotMirrorOpt->Enable( true );
473  m_useAuxOriginCheckBox->Enable( false );
474  m_useAuxOriginCheckBox->SetValue( false );
475  m_defaultPenSize.Enable( false );
476  m_excludeEdgeLayerOpt->Enable( true );
477  m_scaleOpt->Enable( true );
478  m_fineAdjustXCtrl->Enable( true );
479  m_fineAdjustYCtrl->Enable( true );
481  m_plotPSNegativeOpt->Enable( true );
482  m_forcePSA4OutputOpt->Enable( true );
483 
489  break;
490 
491  case PLOT_FORMAT::GERBER:
492  m_drillShapeOpt->Enable( false );
493  m_drillShapeOpt->SetSelection( 0 );
494  m_plotModeOpt->Enable( false );
496  m_plotMirrorOpt->Enable( false );
497  m_plotMirrorOpt->SetValue( false );
498  m_useAuxOriginCheckBox->Enable( true );
499  m_defaultPenSize.Enable( false );
500  m_excludeEdgeLayerOpt->Enable( true );
501  m_scaleOpt->Enable( false );
502  m_scaleOpt->SetSelection( 1 );
503  m_fineAdjustXCtrl->Enable( false );
504  m_fineAdjustYCtrl->Enable( false );
506  m_plotPSNegativeOpt->Enable( false );
507  m_plotPSNegativeOpt->SetValue( false );
508  m_forcePSA4OutputOpt->Enable( false );
509  m_forcePSA4OutputOpt->SetValue( false );
510 
516  break;
517 
518  case PLOT_FORMAT::HPGL:
519  m_drillShapeOpt->Enable( true );
520  m_plotModeOpt->Enable( true );
521  m_plotMirrorOpt->Enable( true );
522  m_useAuxOriginCheckBox->Enable( false );
523  m_useAuxOriginCheckBox->SetValue( false );
524  m_defaultPenSize.Enable( true );
525  m_excludeEdgeLayerOpt->Enable( true );
526  m_scaleOpt->Enable( true );
527  m_fineAdjustXCtrl->Enable( false );
528  m_fineAdjustYCtrl->Enable( false );
530  m_plotPSNegativeOpt->SetValue( false );
531  m_plotPSNegativeOpt->Enable( false );
532  m_forcePSA4OutputOpt->Enable( true );
533 
539  break;
540 
541  case PLOT_FORMAT::DXF:
542  m_drillShapeOpt->Enable( true );
543  m_plotModeOpt->Enable( false );
545  m_plotMirrorOpt->Enable( false );
546  m_plotMirrorOpt->SetValue( false );
547  m_useAuxOriginCheckBox->Enable( true );
548  m_defaultPenSize.Enable( false );
549  m_excludeEdgeLayerOpt->Enable( true );
550  m_scaleOpt->Enable( false );
551  m_scaleOpt->SetSelection( 1 );
552  m_fineAdjustXCtrl->Enable( false );
553  m_fineAdjustYCtrl->Enable( false );
555  m_plotPSNegativeOpt->Enable( false );
556  m_plotPSNegativeOpt->SetValue( false );
557  m_forcePSA4OutputOpt->Enable( false );
558  m_forcePSA4OutputOpt->SetValue( false );
559 
565 
566  OnChangeDXFPlotMode( event );
567  break;
568 
570  break;
571  }
572 
573  /* Update the interlock between scale and frame reference
574  * (scaling would mess up the frame border...) */
575  OnSetScaleOpt( event );
576 
577  Layout();
578  m_MainSizer->SetSizeHints( this );
579 }
580 
581 
582 // A helper function to "clip" aValue between aMin and aMax
583 // and write result in * aResult
584 // return false if clipped, true if aValue is just copied into * aResult
585 static bool setDouble( double* aResult, double aValue, double aMin, double aMax )
586 {
587  if( aValue < aMin )
588  {
589  *aResult = aMin;
590  return false;
591  }
592  else if( aValue > aMax )
593  {
594  *aResult = aMax;
595  return false;
596  }
597 
598  *aResult = aValue;
599  return true;
600 }
601 
602 
603 static bool setInt( int* aResult, int aValue, int aMin, int aMax )
604 {
605  if( aValue < aMin )
606  {
607  *aResult = aMin;
608  return false;
609  }
610  else if( aValue > aMax )
611  {
612  *aResult = aMax;
613  return false;
614  }
615 
616  *aResult = aValue;
617  return true;
618 }
619 
620 
622 {
623  REPORTER& reporter = m_messagesPanel->Reporter();
624  int sel;
625  PCB_PLOT_PARAMS tempOptions;
626 
627  tempOptions.SetExcludeEdgeLayer( m_excludeEdgeLayerOpt->GetValue() );
628  tempOptions.SetSubtractMaskFromSilk( m_subtractMaskFromSilk->GetValue() );
629  tempOptions.SetPlotFrameRef( m_plotSheetRef->GetValue() );
630  tempOptions.SetSketchPadsOnFabLayers( m_sketchPadsOnFabLayers->GetValue() );
631  tempOptions.SetUseAuxOrigin( m_useAuxOriginCheckBox->GetValue() );
632  tempOptions.SetPlotValue( m_plotModuleValueOpt->GetValue() );
633  tempOptions.SetPlotReference( m_plotModuleRefOpt->GetValue() );
634  tempOptions.SetPlotInvisibleText( m_plotInvisibleText->GetValue() );
635  tempOptions.SetScaleSelection( m_scaleOpt->GetSelection() );
636 
637  sel = m_drillShapeOpt->GetSelection();
638  tempOptions.SetDrillMarksType( static_cast<PCB_PLOT_PARAMS::DrillMarksType>( sel ) );
639 
640  tempOptions.SetMirror( m_plotMirrorOpt->GetValue() );
641  tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED );
642  tempOptions.SetDXFPlotPolygonMode( m_DXF_plotModeOpt->GetValue() );
643 
644  sel = m_DXF_plotUnits->GetSelection();
645  tempOptions.SetDXFPlotUnits( sel == 0 ? DXF_UNITS::INCHES : DXF_UNITS::MILLIMETERS );
646 
647  tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() );
648 
649  if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() ) // Currently, only DXF supports this option
650  tempOptions.SetTextMode( PLOT_TEXT_MODE::DEFAULT );
651  else
654 
655  // Update settings from text fields. Rewrite values back to the fields,
656  // since the values may have been constrained by the setters.
657  wxString msg;
658 
659  // read HPLG pen size (this param is stored in mils)
660  // However, due to issues when converting this value from or to mm
661  // that can slightly change the value, update this param only if it
662  // is in use
664  {
665  if( !tempOptions.SetHPGLPenDiameter( m_defaultPenSize.GetValue() / IU_PER_MILS ) )
666  {
668  msg.Printf( _( "HPGL pen size constrained." ) );
669  reporter.Report( msg, RPT_SEVERITY_INFO );
670  }
671  }
672  else // keep the last value (initial value if no HPGL plot made)
674 
675  // X scale
676  double tmpDouble;
677  msg = m_fineAdjustXCtrl->GetValue();
678  msg.ToDouble( &tmpDouble );
679 
680  if( !setDouble( &m_XScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
681  {
682  msg.Printf( wxT( "%f" ), m_XScaleAdjust );
683  m_fineAdjustXCtrl->SetValue( msg );
684  msg.Printf( _( "X scale constrained." ) );
685  reporter.Report( msg, RPT_SEVERITY_INFO );
686  }
687 
688  // Y scale
689  msg = m_fineAdjustYCtrl->GetValue();
690  msg.ToDouble( &tmpDouble );
691 
692  if( !setDouble( &m_YScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
693  {
694  msg.Printf( wxT( "%f" ), m_YScaleAdjust );
695  m_fineAdjustYCtrl->SetValue( msg );
696  msg.Printf( _( "Y scale constrained." ) );
697  reporter.Report( msg, RPT_SEVERITY_INFO );
698  }
699 
700  auto cfg = m_parent->GetPcbNewSettings();
701 
703  cfg->m_Plot.fine_scale_y = m_YScaleAdjust;
704 
705  cfg->m_Plot.check_zones_before_plotting = m_zoneFillCheck->GetValue();
706 
707  // PS Width correction
710  {
712  msg.Printf( _( "Width correction constrained. "
713  "The reasonable width correction value must be in a range of "
714  " [%s; %s] (%s) for current design rules." ),
718  reporter.Report( msg, RPT_SEVERITY_WARNING );
719  }
720 
721  // Store m_PSWidthAdjust in mm in user config
722  cfg->m_Plot.ps_fine_width_adjust = Iu2Millimeter( m_PSWidthAdjust );
723 
724  tempOptions.SetFormat( getPlotFormat() );
725 
726  tempOptions.SetDisableGerberMacros( m_disableApertMacros->GetValue() );
727  tempOptions.SetUseGerberProtelExtensions( m_useGerberExtensions->GetValue() );
728  tempOptions.SetUseGerberX2format( m_useGerberX2Format->GetValue() );
729  tempOptions.SetIncludeGerberNetlistInfo( m_useGerberNetAttributes->GetValue() );
730  tempOptions.SetCreateGerberJobFile( m_generateGerberJobFile->GetValue() );
731 
732  tempOptions.SetGerberPrecision( m_coordFormatCtrl->GetSelection() == 0 ? 5 : 6 );
733  tempOptions.SetSvgPrecision( m_svgPrecsision->GetValue(), m_svgUnits->GetSelection() );
734 
735  LSET selectedLayers;
736  for( unsigned i = 0; i < m_layerList.size(); i++ )
737  {
738  if( m_layerCheckListBox->IsChecked( i ) )
739  selectedLayers.set( m_layerList[i] );
740  }
741  // Get a list of copper layers that aren't being used by inverting enabled layers.
742  LSET disabledCopperLayers = LSET::AllCuMask() & ~m_parent->GetBoard()->GetEnabledLayers();
743  // Enable all of the disabled copper layers.
744  // If someone enables more copper layers they will be selected by default.
745  selectedLayers = selectedLayers | disabledCopperLayers;
746  tempOptions.SetLayerSelection( selectedLayers );
747 
748  tempOptions.SetNegative( m_plotPSNegativeOpt->GetValue() );
749  tempOptions.SetA4Output( m_forcePSA4OutputOpt->GetValue() );
750 
751  // Set output directory and replace backslashes with forward ones
752  wxString dirStr;
753  dirStr = m_outputDirectoryName->GetValue();
754  dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
755  tempOptions.SetOutputDirectory( dirStr );
756 
757  if( !m_plotOpts.IsSameAs( tempOptions, false ) )
758  {
759  // First, mark board as modified only for parameters saved in file
760  if( !m_plotOpts.IsSameAs( tempOptions, true ) )
761  m_parent->OnModify();
762 
763  // Now, save any change, for the session
764  m_parent->SetPlotSettings( tempOptions );
765  m_plotOpts = tempOptions;
766  }
767 }
768 
769 
770 void DIALOG_PLOT::OnGerberX2Checked( wxCommandEvent& event )
771 {
772  // Currently: do nothing
773 }
774 
775 
776 void DIALOG_PLOT::Plot( wxCommandEvent& event )
777 {
778  BOARD* board = m_parent->GetBoard();
779 
781 
782  SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
784 
786 
788 
789  // If no layer selected, we have nothing plotted.
790  // Prompt user if it happens because he could think there is a bug in Pcbnew.
791  if( !m_plotOpts.GetLayerSelection().any() )
792  {
793  DisplayError( this, _( "No layer selected, Nothing to plot" ) );
794  return;
795  }
796 
797  // Create output directory if it does not exist (also transform it in
798  // absolute form). Bail if it fails
800  wxFileName outputDir = wxFileName::DirName( path );
801  wxString boardFilename = m_parent->GetBoard()->GetFileName();
802  REPORTER& reporter = m_messagesPanel->Reporter();
803 
804  if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
805  {
806  wxString msg;
807  msg.Printf( _( "Could not write plot files to folder \"%s\"." ), outputDir.GetPath() );
808  DisplayError( this, msg );
809  return;
810  }
811 
812  if( m_zoneFillCheck->GetValue() )
813  m_parent->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
814 
815  m_plotOpts.SetAutoScale( false );
816 
817  switch( m_plotOpts.GetScaleSelection() )
818  {
819  default: m_plotOpts.SetScale( 1 ); break;
820  case 0: m_plotOpts.SetAutoScale( true ); break;
821  case 2: m_plotOpts.SetScale( 1.5 ); break;
822  case 3: m_plotOpts.SetScale( 2 ); break;
823  case 4: m_plotOpts.SetScale( 3 ); break;
824  }
825 
826  /* If the scale factor edit controls are disabled or the scale value
827  * is 0, don't adjust the base scale factor. This fixes a bug when
828  * the default scale adjust is initialized to 0 and saved in program
829  * settings resulting in a divide by zero fault.
830  */
832  {
833  if( m_XScaleAdjust != 0.0 )
835 
836  if( m_YScaleAdjust != 0.0 )
838 
840  }
841 
842  wxString file_ext( GetDefaultPlotExtension( m_plotOpts.GetFormat() ) );
843 
844  // Test for a reasonable scale value
845  // XXX could this actually happen? isn't it constrained in the apply
846  // function?
848  DisplayInfoMessage( this, _( "Warning: Scale option set to a very small value" ) );
849 
851  DisplayInfoMessage( this, _( "Warning: Scale option set to a very large value" ) );
852 
853  GERBER_JOBFILE_WRITER jobfile_writer( board, &reporter );
854 
855  // Save the current plot options in the board
857 
858  wxBusyCursor dummy;
859 
860  for( LSEQ seq = m_plotOpts.GetLayerSelection().UIOrder(); seq; ++seq )
861  {
862  PCB_LAYER_ID layer = *seq;
863 
864  // All copper layers that are disabled are actually selected
865  // This is due to wonkyness in automatically selecting copper layers
866  // for plotting when adding more than two layers to a board.
867  // If plot options become accessible to the layers setup dialog
868  // please move this functionality there!
869  // This skips a copper layer if it is actually disabled on the board.
870  if( ( LSET::AllCuMask() & ~board->GetEnabledLayers() )[layer] )
871  continue;
872 
873  // Pick the basename from the board file
874  wxFileName fn( boardFilename );
875 
876  // Use Gerber Extensions based on layer number
877  // (See http://en.wikipedia.org/wiki/Gerber_File)
879  file_ext = GetGerberProtelExtension( layer );
880 
881  BuildPlotFileName( &fn, outputDir.GetPath(), board->GetLayerName( layer ), file_ext );
882  wxString fullname = fn.GetFullName();
883  jobfile_writer.AddGbrFile( layer, fullname );
884 
885  LOCALE_IO toggle;
886 
887  PLOTTER* plotter = StartPlotBoard( board, &m_plotOpts, layer, fn.GetFullPath(), wxEmptyString );
888 
889  // Print diags in messages box:
890  wxString msg;
891 
892  if( plotter )
893  {
894  PlotOneBoardLayer( board, plotter, layer, m_plotOpts );
895  plotter->EndPlot();
896  delete plotter->RenderSettings();
897  delete plotter;
898 
899  msg.Printf( _( "Plot file \"%s\" created." ), fn.GetFullPath() );
900  reporter.Report( msg, RPT_SEVERITY_ACTION );
901  }
902  else
903  {
904  msg.Printf( _( "Unable to create file \"%s\"." ), fn.GetFullPath() );
905  reporter.Report( msg, RPT_SEVERITY_ERROR );
906  }
907 
908  wxSafeYield(); // displays report message.
909  }
910 
912  {
913  // Pick the basename from the board file
914  wxFileName fn( boardFilename );
915  // Build gerber job file from basename
916  BuildPlotFileName( &fn, outputDir.GetPath(), "job", GerberJobFileExtension );
917  jobfile_writer.CreateJobFile( fn.GetFullPath() );
918  }
919 }
920 
921 
922 void DIALOG_PLOT::onRunDRC( wxCommandEvent& event )
923 {
924  PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
925 
926  if( parent )
927  {
928  DRC_TOOL* drcTool = parent->GetToolManager()->GetTool<DRC_TOOL>();
929 
930  // First close an existing dialog if open
931  // (low probability, but can happen)
932  drcTool->DestroyDRCDialog();
933 
934  // Open a new drc dialod, with the right parent frame, and in Modal Mode
935  drcTool->ShowDRCDialog( this );
936 
937  // Update DRC warnings on return to this dialog
938  reInitDialog();
939  }
940 }
941 
942 
943 void DIALOG_PLOT::onBoardSetup( wxHyperlinkEvent& aEvent )
944 {
945  PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
946 
947  if( parent )
948  {
949  parent->ShowBoardSetupDialog( _( "Solder Mask/Paste" ) );
950 
951  // Update warnings on return to this dialog
952  reInitDialog();
953  }
954 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
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:240
WX_HTML_REPORT_PANEL * m_messagesPanel
OUTLINE_MODE GetPlotMode() const
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
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
void SetGerberPrecision(int aPrecision)
void OnOutputDirectoryBrowseClicked(wxCommandEvent &event) override
wxButton * m_sdbSizer1Cancel
void SetPlotViaOnMaskLayer(bool aFlag)
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:332
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: locale_io.h:40
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
bool GetDisableGerberMacros() const
MARKERS & Markers()
Definition: board.h:292
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:45
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:559
wxCheckBox * m_plotMirrorOpt
void SetTextMode(PLOT_TEXT_MODE aVal)
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings Returns a bit-mask of all t...
Definition: board.cpp:437
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:467
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:81
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:255
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
wxChoice * m_plotFormatOpt
static LSET AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:820
virtual const PCB_PLOT_PARAMS & GetPlotSettings() const
Function GetPlotSettings returns the PCB_PLOT_PARAMS for the BOARD owned by this frame.
wxChoice * m_coordFormatCtrl
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
void SetDXFPlotUnits(DXF_UNITS aUnit)
void CreateDrillFile(wxCommandEvent &event) override
const wxString & GetFileName() const
Definition: board.h:278
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:270
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:82
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:
void SetDisableGerberMacros(bool aDisable)
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.
void ShowBoardSetupDialog(const wxString &aInitialPage=wxEmptyString)
Function ShowBoardSetupDialog.
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 SetColorSettings(COLOR_SETTINGS *aSettings)
PLOT_FORMAT getPlotFormat()
unsigned GetSvgPrecision() const
PLOT_FORMAT
The set of supported output plot formats.
Definition: plotter.h:67
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void onBoardSetup(wxHyperlinkEvent &aEvent) override
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:283
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(OUTLINE_MODE aPlotMode)
Definition: dialog_plot.h:85
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)
wxCheckBox * m_disableApertMacros
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
void SetPlotMode(OUTLINE_MODE aPlotMode)
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 Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
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:370
void reInitDialog()
wxCheckBox * m_plotModuleRefOpt
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
bool SetHPGLPenDiameter(double aValue)
wxString m_DRCWarningTemplate
Definition: dialog_plot.h:62
Base plotter engine class.
Definition: plotter.h:131
wxBoxSizer * m_sizerButtons
wxCheckBox * m_subtractMaskFromSilk
bool GetSketchPadsOnFabLayers() const
void init_Dialog()
Definition: dialog_plot.cpp:73
wxCheckBox * m_plotNoViaOnMaskOpt
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:165
wxCheckBox * m_plotModuleValueOpt
bool GetPlotViaOnMaskLayer() const
wxChoice * m_drillShapeOpt
Board layer functions and definitions.
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.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:186
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:137
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)
Tests whether a layer is a copper layer.
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:220
int GetScaleSelection() const
DXF_UNITS GetDXFPlotUnits() 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:76
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:132
wxStaticBoxSizer * m_PSOptionsSizer
LSET GetLayerSelection() const
LSEQ UIOrder() const
Definition: lset.cpp:888
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:268
DrillMarksType GetDrillMarksType() const
wxBoxSizer * m_PlotOptionsSizer
bool GetPlotReference() const
DIALOG_PLOT(PCB_EDIT_FRAME *parent)
Definition: dialog_plot.cpp:48
#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.
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:176