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 <drc/drc.h>
41 #include <tool/tool_manager.h>
42 #include <tools/zone_filler_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  msg.Printf( _( "Do you want to use a path relative to\n\"%s\"" ),
366  GetChars( defaultPath ) );
367 
368  wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
369  wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
370 
371  if( dialog.ShowModal() == wxID_YES )
372  {
373  if( !dirName.MakeRelativeTo( defaultPath ) )
374  wxMessageBox( _( "Cannot make path relative (target volume different from file volume)!" ),
375  _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
376  }
377 
378  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
379 }
380 
381 
383 {
384  // plot format id's are ordered like displayed in m_plotFormatOpt
387 
388  return plotFmt[m_plotFormatOpt->GetSelection()];
389 }
390 
391 
392 // Enable or disable widgets according to the plot format selected
393 // and clear also some optional values
394 void DIALOG_PLOT::SetPlotFormat( wxCommandEvent& event )
395 {
396  // this option exist only in DXF format:
398 
399  // The alert message about non 0 solder mask min width and margin is shown
400  // only in gerber format and if min mask width or mask margin is not 0
401  BOARD* board = m_parent->GetBoard();
402  const BOARD_DESIGN_SETTINGS& brd_settings = board->GetDesignSettings();
403 
405  ( brd_settings.m_SolderMaskMargin || brd_settings.m_SolderMaskMinWidth ) )
407  else
409 
410 
411  switch( getPlotFormat() )
412  {
413  case PLOT_FORMAT::SVG:
414  case PLOT_FORMAT::PDF:
415  m_drillShapeOpt->Enable( true );
416  m_plotModeOpt->Enable( false );
418  m_plotMirrorOpt->Enable( true );
419  m_useAuxOriginCheckBox->Enable( false );
420  m_useAuxOriginCheckBox->SetValue( false );
421  m_defaultPenSize.Enable( false );
422  m_excludeEdgeLayerOpt->Enable( true );
423  m_scaleOpt->Enable( false );
424  m_scaleOpt->SetSelection( 1 );
425  m_fineAdjustXCtrl->Enable( false );
426  m_fineAdjustYCtrl->Enable( false );
428  m_plotPSNegativeOpt->Enable( true );
429  m_forcePSA4OutputOpt->Enable( false );
430  m_forcePSA4OutputOpt->SetValue( false );
431 
434  else
436 
441  break;
442 
443  case PLOT_FORMAT::POST:
444  m_drillShapeOpt->Enable( true );
445  m_plotModeOpt->Enable( true );
446  m_plotMirrorOpt->Enable( true );
447  m_useAuxOriginCheckBox->Enable( false );
448  m_useAuxOriginCheckBox->SetValue( false );
449  m_defaultPenSize.Enable( false );
450  m_excludeEdgeLayerOpt->Enable( true );
451  m_scaleOpt->Enable( true );
452  m_fineAdjustXCtrl->Enable( true );
453  m_fineAdjustYCtrl->Enable( true );
455  m_plotPSNegativeOpt->Enable( true );
456  m_forcePSA4OutputOpt->Enable( true );
457 
463  break;
464 
465  case PLOT_FORMAT::GERBER:
466  m_drillShapeOpt->Enable( false );
467  m_drillShapeOpt->SetSelection( 0 );
468  m_plotModeOpt->Enable( false );
470  m_plotMirrorOpt->Enable( false );
471  m_plotMirrorOpt->SetValue( false );
472  m_useAuxOriginCheckBox->Enable( true );
473  m_defaultPenSize.Enable( false );
474  m_excludeEdgeLayerOpt->Enable( true );
475  m_scaleOpt->Enable( false );
476  m_scaleOpt->SetSelection( 1 );
477  m_fineAdjustXCtrl->Enable( false );
478  m_fineAdjustYCtrl->Enable( false );
480  m_plotPSNegativeOpt->Enable( false );
481  m_plotPSNegativeOpt->SetValue( false );
482  m_forcePSA4OutputOpt->Enable( false );
483  m_forcePSA4OutputOpt->SetValue( false );
484 
490  break;
491 
492  case PLOT_FORMAT::HPGL:
493  m_drillShapeOpt->Enable( true );
494  m_plotModeOpt->Enable( true );
495  m_plotMirrorOpt->Enable( true );
496  m_useAuxOriginCheckBox->Enable( false );
497  m_useAuxOriginCheckBox->SetValue( false );
498  m_defaultPenSize.Enable( true );
499  m_excludeEdgeLayerOpt->Enable( true );
500  m_scaleOpt->Enable( true );
501  m_fineAdjustXCtrl->Enable( false );
502  m_fineAdjustYCtrl->Enable( false );
504  m_plotPSNegativeOpt->SetValue( false );
505  m_plotPSNegativeOpt->Enable( false );
506  m_forcePSA4OutputOpt->Enable( true );
507 
513  break;
514 
515  case PLOT_FORMAT::DXF:
516  m_drillShapeOpt->Enable( true );
517  m_plotModeOpt->Enable( false );
519  m_plotMirrorOpt->Enable( false );
520  m_plotMirrorOpt->SetValue( false );
521  m_useAuxOriginCheckBox->Enable( true );
522  m_defaultPenSize.Enable( false );
523  m_excludeEdgeLayerOpt->Enable( true );
524  m_scaleOpt->Enable( false );
525  m_scaleOpt->SetSelection( 1 );
526  m_fineAdjustXCtrl->Enable( false );
527  m_fineAdjustYCtrl->Enable( false );
529  m_plotPSNegativeOpt->Enable( false );
530  m_plotPSNegativeOpt->SetValue( false );
531  m_forcePSA4OutputOpt->Enable( false );
532  m_forcePSA4OutputOpt->SetValue( false );
533 
539 
540  OnChangeDXFPlotMode( event );
541  break;
542 
544  break;
545  }
546 
547  /* Update the interlock between scale and frame reference
548  * (scaling would mess up the frame border...) */
549  OnSetScaleOpt( event );
550 
551  Layout();
552  m_MainSizer->SetSizeHints( this );
553 }
554 
555 
556 // A helper function to "clip" aValue between aMin and aMax
557 // and write result in * aResult
558 // return false if clipped, true if aValue is just copied into * aResult
559 static bool setDouble( double* aResult, double aValue, double aMin, double aMax )
560 {
561  if( aValue < aMin )
562  {
563  *aResult = aMin;
564  return false;
565  }
566  else if( aValue > aMax )
567  {
568  *aResult = aMax;
569  return false;
570  }
571 
572  *aResult = aValue;
573  return true;
574 }
575 
576 
577 static bool setInt( int* aResult, int aValue, int aMin, int aMax )
578 {
579  if( aValue < aMin )
580  {
581  *aResult = aMin;
582  return false;
583  }
584  else if( aValue > aMax )
585  {
586  *aResult = aMax;
587  return false;
588  }
589 
590  *aResult = aValue;
591  return true;
592 }
593 
594 
596 {
597  REPORTER& reporter = m_messagesPanel->Reporter();
598  int sel;
599  PCB_PLOT_PARAMS tempOptions;
600 
601  tempOptions.SetExcludeEdgeLayer( m_excludeEdgeLayerOpt->GetValue() );
602  tempOptions.SetSubtractMaskFromSilk( m_subtractMaskFromSilk->GetValue() );
603  tempOptions.SetPlotFrameRef( m_plotSheetRef->GetValue() );
604  tempOptions.SetSketchPadsOnFabLayers( m_sketchPadsOnFabLayers->GetValue());
605  tempOptions.SetUseAuxOrigin( m_useAuxOriginCheckBox->GetValue() );
606  tempOptions.SetPlotValue( m_plotModuleValueOpt->GetValue() );
607  tempOptions.SetPlotReference( m_plotModuleRefOpt->GetValue() );
608  tempOptions.SetPlotInvisibleText( m_plotInvisibleText->GetValue() );
609  tempOptions.SetScaleSelection( m_scaleOpt->GetSelection() );
610 
611  sel = m_drillShapeOpt->GetSelection();
612  tempOptions.SetDrillMarksType( static_cast<PCB_PLOT_PARAMS::DrillMarksType>( sel ) );
613 
614  tempOptions.SetMirror( m_plotMirrorOpt->GetValue() );
615  tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED );
616  tempOptions.SetDXFPlotPolygonMode( m_DXF_plotModeOpt->GetValue() );
617 
618  sel = m_DXF_plotUnits->GetSelection();
619  tempOptions.SetDXFPlotUnits( static_cast<DXF_PLOTTER::DXF_UNITS>( sel ) );
620 
621  tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() );
622 
623  if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() ) // Currently, only DXF supports this option
624  tempOptions.SetTextMode( PLOT_TEXT_MODE::DEFAULT );
625  else
628 
629  // Update settings from text fields. Rewrite values back to the fields,
630  // since the values may have been constrained by the setters.
631  wxString msg;
632 
633  // read HPLG pen size (this param is stored in mils)
634  // However, due to issues when converting this value from or to mm
635  // that can slightly change the value, update this param only if it
636  // is in use
638  {
639  if( !tempOptions.SetHPGLPenDiameter( m_defaultPenSize.GetValue() / IU_PER_MILS ) )
640  {
642  msg.Printf( _( "HPGL pen size constrained." ) );
643  reporter.Report( msg, RPT_SEVERITY_INFO );
644  }
645  }
646  else // keep the last value (initial value if no HPGL plot made)
648 
649  // X scale
650  double tmpDouble;
651  msg = m_fineAdjustXCtrl->GetValue();
652  msg.ToDouble( &tmpDouble );
653 
654  if( !setDouble( &m_XScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
655  {
656  msg.Printf( wxT( "%f" ), m_XScaleAdjust );
657  m_fineAdjustXCtrl->SetValue( msg );
658  msg.Printf( _( "X scale constrained." ) );
659  reporter.Report( msg, RPT_SEVERITY_INFO );
660  }
661 
662  // Y scale
663  msg = m_fineAdjustYCtrl->GetValue();
664  msg.ToDouble( &tmpDouble );
665 
666  if( !setDouble( &m_YScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
667  {
668  msg.Printf( wxT( "%f" ), m_YScaleAdjust );
669  m_fineAdjustYCtrl->SetValue( msg );
670  msg.Printf( _( "Y scale constrained." ) );
671  reporter.Report( msg, RPT_SEVERITY_INFO );
672  }
673 
674  auto cfg = m_parent->GetPcbNewSettings();
675 
677  cfg->m_Plot.fine_scale_y = m_YScaleAdjust;
678 
679  cfg->m_Plot.check_zones_before_plotting = m_zoneFillCheck->GetValue();
680 
681  // PS Width correction
684  {
686  msg.Printf( _( "Width correction constrained. "
687  "The reasonable width correction value must be in a range of "
688  " [%s; %s] (%s) for current design rules." ),
692  reporter.Report( msg, RPT_SEVERITY_WARNING );
693  }
694 
695  // Store m_PSWidthAdjust in mm in user config
696  cfg->m_Plot.ps_fine_width_adjust = Iu2Millimeter( m_PSWidthAdjust );
697 
698  tempOptions.SetFormat( getPlotFormat() );
699 
700  tempOptions.SetUseGerberProtelExtensions( m_useGerberExtensions->GetValue() );
701  tempOptions.SetUseGerberX2format( m_useGerberX2Format->GetValue() );
702  tempOptions.SetIncludeGerberNetlistInfo( m_useGerberNetAttributes->GetValue() );
703  tempOptions.SetCreateGerberJobFile( m_generateGerberJobFile->GetValue() );
704 
705  tempOptions.SetGerberPrecision( m_coordFormatCtrl->GetSelection() == 0 ? 5 : 6 );
706  tempOptions.SetSvgPrecision( m_svgPrecsision->GetValue(), m_svgUnits->GetSelection() );
707 
708  LSET selectedLayers;
709  for( unsigned i = 0; i < m_layerList.size(); i++ )
710  {
711  if( m_layerCheckListBox->IsChecked( i ) )
712  selectedLayers.set( m_layerList[i] );
713  }
714  // Get a list of copper layers that aren't being used by inverting enabled layers.
715  LSET disabledCopperLayers = LSET::AllCuMask() & ~m_parent->GetBoard()->GetEnabledLayers();
716  // Enable all of the disabled copper layers.
717  // If someone enables more copper layers they will be selected by default.
718  selectedLayers = selectedLayers | disabledCopperLayers;
719  tempOptions.SetLayerSelection( selectedLayers );
720 
721  tempOptions.SetNegative( m_plotPSNegativeOpt->GetValue() );
722  tempOptions.SetA4Output( m_forcePSA4OutputOpt->GetValue() );
723 
724  // Set output directory and replace backslashes with forward ones
725  wxString dirStr;
726  dirStr = m_outputDirectoryName->GetValue();
727  dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
728  tempOptions.SetOutputDirectory( dirStr );
729 
730  if( !m_plotOpts.IsSameAs( tempOptions, false ) )
731  {
732  // First, mark board as modified only for parameters saved in file
733  if( !m_plotOpts.IsSameAs( tempOptions, true ) )
734  m_parent->OnModify();
735 
736  // Now, save any change, for the session
737  m_parent->SetPlotSettings( tempOptions );
738  m_plotOpts = tempOptions;
739  }
740 }
741 
742 
743 void DIALOG_PLOT::OnGerberX2Checked( wxCommandEvent& event )
744 {
745  // Currently: do nothing
746 }
747 
748 
749 void DIALOG_PLOT::Plot( wxCommandEvent& event )
750 {
751  BOARD* board = m_parent->GetBoard();
752 
754 
755  SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
757 
759 
761 
762  // If no layer selected, we have nothing plotted.
763  // Prompt user if it happens because he could think there is a bug in Pcbnew.
764  if( !m_plotOpts.GetLayerSelection().any() )
765  {
766  DisplayError( this, _( "No layer selected, Nothing to plot" ) );
767  return;
768  }
769 
770  // Create output directory if it does not exist (also transform it in
771  // absolute form). Bail if it fails
773  wxFileName outputDir = wxFileName::DirName( path );
774  wxString boardFilename = m_parent->GetBoard()->GetFileName();
775  REPORTER& reporter = m_messagesPanel->Reporter();
776 
777  if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
778  {
779  wxString msg;
780  msg.Printf( _( "Could not write plot files to folder \"%s\"." ),
781  GetChars( outputDir.GetPath() ) );
782  DisplayError( this, msg );
783  return;
784  }
785 
786  if( m_zoneFillCheck->GetValue() )
787  m_parent->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
788 
789  m_plotOpts.SetAutoScale( false );
790 
791  switch( m_plotOpts.GetScaleSelection() )
792  {
793  default: m_plotOpts.SetScale( 1 ); break;
794  case 0: m_plotOpts.SetAutoScale( true ); break;
795  case 2: m_plotOpts.SetScale( 1.5 ); break;
796  case 3: m_plotOpts.SetScale( 2 ); break;
797  case 4: m_plotOpts.SetScale( 3 ); break;
798  }
799 
800  /* If the scale factor edit controls are disabled or the scale value
801  * is 0, don't adjust the base scale factor. This fixes a bug when
802  * the default scale adjust is initialized to 0 and saved in program
803  * settings resulting in a divide by zero fault.
804  */
806  {
807  if( m_XScaleAdjust != 0.0 )
809 
810  if( m_YScaleAdjust != 0.0 )
812 
814  }
815 
816  wxString file_ext( GetDefaultPlotExtension( m_plotOpts.GetFormat() ) );
817 
818  // Test for a reasonable scale value
819  // XXX could this actually happen? isn't it constrained in the apply
820  // function?
822  DisplayInfoMessage( this, _( "Warning: Scale option set to a very small value" ) );
823 
825  DisplayInfoMessage( this, _( "Warning: Scale option set to a very large value" ) );
826 
827  GERBER_JOBFILE_WRITER jobfile_writer( board, &reporter );
828 
829  // Save the current plot options in the board
831 
832  wxBusyCursor dummy;
833 
834  for( LSEQ seq = m_plotOpts.GetLayerSelection().UIOrder(); seq; ++seq )
835  {
836  PCB_LAYER_ID layer = *seq;
837 
838  // All copper layers that are disabled are actually selected
839  // This is due to wonkyness in automatically selecting copper layers
840  // for plotting when adding more than two layers to a board.
841  // If plot options become accessible to the layers setup dialog
842  // please move this functionality there!
843  // This skips a copper layer if it is actually disabled on the board.
844  if( ( LSET::AllCuMask() & ~board->GetEnabledLayers() )[layer] )
845  continue;
846 
847  // Pick the basename from the board file
848  wxFileName fn( boardFilename );
849 
850  // Use Gerber Extensions based on layer number
851  // (See http://en.wikipedia.org/wiki/Gerber_File)
853  file_ext = GetGerberProtelExtension( layer );
854 
855  BuildPlotFileName( &fn, outputDir.GetPath(), board->GetLayerName( layer ), file_ext );
856  wxString fullname = fn.GetFullName();
857  jobfile_writer.AddGbrFile( layer, fullname );
858 
859  LOCALE_IO toggle;
860 
861  PLOTTER* plotter = StartPlotBoard( board, &m_plotOpts, layer, fn.GetFullPath(), wxEmptyString );
862 
863  // Print diags in messages box:
864  wxString msg;
865 
866  if( plotter )
867  {
868  PlotOneBoardLayer( board, plotter, layer, m_plotOpts );
869  plotter->EndPlot();
870  delete plotter;
871 
872  msg.Printf( _( "Plot file \"%s\" created." ), fn.GetFullPath() );
873  reporter.Report( msg, RPT_SEVERITY_ACTION );
874  }
875  else
876  {
877  msg.Printf( _( "Unable to create file \"%s\"." ), fn.GetFullPath() );
878  reporter.Report( msg, RPT_SEVERITY_ERROR );
879  }
880 
881  wxSafeYield(); // displays report message.
882  }
883 
885  {
886  // Pick the basename from the board file
887  wxFileName fn( boardFilename );
888  // Build gerber job file from basename
889  BuildPlotFileName( &fn, outputDir.GetPath(), "job", GerberJobFileExtension );
890  jobfile_writer.CreateJobFile( fn.GetFullPath() );
891  }
892 }
893 
894 
895 void DIALOG_PLOT::onRunDRC( wxCommandEvent& event )
896 {
897  PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
898 
899  if( parent )
900  {
901  DRC* drcTool = parent->GetToolManager()->GetTool<DRC>();
902 
903  // First close an existing dialog if open
904  // (low probability, but can happen)
905  drcTool->DestroyDRCDialog( wxID_OK );
906 
907  // Open a new drc dialod, with the right parent frame, and in Modal Mode
908  drcTool->ShowDRCDialog( this );
909 
910  // Update DRC warnings on return to this dialog
911  reInitDialog();
912  }
913 }
914 
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:712
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)
int m_SolderMaskMargin
Solder mask margin.
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
void DestroyDRCDialog(int aReason)
Deletes this ui dialog box and zeros out its pointer to remember the state of the dialog's existence.
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.
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:285
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:551
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...
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...
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:574
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:782
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:255
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: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:602
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
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:205
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:180
bool GetSubtractMaskFromSilk() const
#define _(s)
Definition: 3d_actions.cpp:33
Design Rule Checker object that performs all the DRC tests.
Definition: drc.h:105
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:74
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
wxStaticBoxSizer * m_PSOptionsSizer
LSET GetLayerSelection() const
DXF_PLOTTER::DXF_UNITS GetDXFPlotUnits() const
LSEQ UIOrder() const
Definition: lset.cpp:839
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)
int m_SolderMaskMinWidth
Solder mask min width.
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:156