KiCad PCB EDA Suite
dialog_plot.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 
29 #include <kiface_i.h>
30 #include <plotter.h>
31 #include <confirm.h>
32 #include <pcb_edit_frame.h>
33 #include <pcbplot.h>
34 #include <gerber_jobfile_writer.h>
35 #include <base_units.h>
36 #include <macros.h>
37 #include <reporter.h>
39 #include <bitmaps.h>
40 
41 #include <class_board.h>
42 #include <wx/ffile.h>
43 #include <dialog_plot.h>
44 #include <wx_html_report_panel.h>
45 #include <drc.h>
46 
47 
49  DIALOG_PLOT_BASE( aParent ), m_parent( aParent ),
50  m_board( aParent->GetBoard() )
51 {
53  m_plotOpts = aParent->GetPlotSettings();
54  init_Dialog();
55 
56  GetSizer()->Fit( this );
57  GetSizer()->SetSizeHints( this );
58 }
59 
60 
62 {
63  wxString msg;
64  wxFileName fileName;
65 
68 
69  m_browseButton->SetBitmap( KiBitmap( browse_files_xpm ) );
70 
71  // m_PSWidthAdjust is stored in mm in user config
72  double dtmp;
73  m_config->Read( CONFIG_PS_FINEWIDTH_ADJ, &dtmp, 0 );
74  m_PSWidthAdjust = KiROUND( dtmp * IU_PER_MM );
75 
76  // The reasonable width correction value must be in a range of
77  // [-(MinTrackWidth-1), +(MinClearanceValue-1)] decimils.
80 
81  switch( m_plotOpts.GetFormat() )
82  {
83  default:
84  case PLOT_FORMAT_GERBER:
85  m_plotFormatOpt->SetSelection( 0 );
86  break;
87 
88  case PLOT_FORMAT_POST:
89  m_plotFormatOpt->SetSelection( 1 );
90  break;
91 
92  case PLOT_FORMAT_SVG:
93  m_plotFormatOpt->SetSelection( 2 );
94  break;
95 
96  case PLOT_FORMAT_DXF:
97  m_plotFormatOpt->SetSelection( 3 );
98  break;
99 
100  case PLOT_FORMAT_HPGL:
101  m_plotFormatOpt->SetSelection( 4 );
102  break;
103 
104  case PLOT_FORMAT_PDF:
105  m_plotFormatOpt->SetSelection( 5 );
106  break;
107  }
108 
110  m_SolderMaskMarginCurrValue->SetLabel( msg );
112  m_SolderMaskMinWidthCurrValue->SetLabel( msg );
113 
114  // Set units and value for HPGL pen size (this param in in mils).
117  m_plotOpts.GetHPGLPenDiameter() * IU_PER_MILS );
118  m_HPGLPenSizeOpt->AppendText( msg );
119 
122  m_linesWidth->AppendText( msg );
123 
124  // Set units for PS global width correction.
126 
127  // Test for a reasonable scale value. Set to 1 if problem
131 
132  msg.Printf( wxT( "%f" ), m_XScaleAdjust );
133  m_fineAdjustXscaleOpt->AppendText( msg );
134 
135  msg.Printf( wxT( "%f" ), m_YScaleAdjust );
136  m_fineAdjustYscaleOpt->AppendText( msg );
137 
138  // Test for a reasonable PS width correction value. Set to 0 if problem.
139  if( m_PSWidthAdjust < m_widthAdjustMinValue || m_PSWidthAdjust > m_widthAdjustMaxValue )
140  m_PSWidthAdjust = 0.;
141 
142  msg.Printf( wxT( "%f" ), To_User_Unit( g_UserUnit, m_PSWidthAdjust ) );
143  m_PSFineAdjustWidthOpt->AppendText( msg );
144 
147 
148  // Could devote a PlotOrder() function in place of UIOrder().
150 
151  // Populate the check list box by all enabled layers names
152  for( LSEQ seq = m_layerList; seq; ++seq )
153  {
154  PCB_LAYER_ID layer = *seq;
155 
156  int checkIndex = m_layerCheckListBox->Append( m_board->GetLayerName( layer ) );
157 
158  if( m_plotOpts.GetLayerSelection()[layer] )
159  m_layerCheckListBox->Check( checkIndex );
160  }
161 
162  // Option for using proper Gerber extensions
164 
165  // Option for including Gerber attributes (from Gerber X2 format) in the output
167 
168  // Option for including Gerber netlist info (from Gerber X2 format) in the output
170 
171  // Grey out if m_useGerberX2Attributes is not checked
172  m_useGerberNetAttributes->Enable( m_useGerberX2Attributes->GetValue() );
173 
174  // Option to generate a Gerber job file
176 
177  // Gerber precision for coordinates
178  m_rbGerberFormat->SetSelection( m_plotOpts.GetGerberPrecision() == 5 ? 0 : 1 );
179 
180  // Option for excluding contents of "Edges Pcb" layer
182 
183  // Option to exclude pads from silkscreen layers
185 
187 
188  // Option to plot page references:
190 
191  // Options to plot texts on footprints
195 
196  // Options to plot pads and vias holes
197  m_drillShapeOpt->SetSelection( m_plotOpts.GetDrillMarksType() );
198 
199  // Scale option
200  m_scaleOpt->SetSelection( m_plotOpts.GetScaleSelection() );
201 
202  // Plot mode
204 
205  // Plot outline mode
207 
208  // Plot text mode
210 
211  // Plot mirror option
212  m_plotMirrorOpt->SetValue( m_plotOpts.GetMirror() );
213 
214  // Put vias on mask layer
216 
217  // Initialize a few other parameters, which can also be modified
218  // from the drill dialog
219  reInitDialog();
220 
221  // Update options values:
222  wxCommandEvent cmd_event;
223  SetPlotFormat( cmd_event );
224  OnSetScaleOpt( cmd_event );
225 }
226 
227 
229 {
230  // after calling drill dialog, some parameters can be modified.
231  // update them
232 
233  // Output directory
235 
236  // Origin of coordinates:
238 }
239 
240 void DIALOG_PLOT::OnQuit( wxCommandEvent& event )
241 {
242  Close( true ); // true is to force the frame to close
243 }
244 
245 
246 void DIALOG_PLOT::OnClose( wxCloseEvent& event )
247 {
249  EndModal( 0 );
250 }
251 
252 
253 // A helper function to show a popup menu, when the dialog is right clicked.
254 void DIALOG_PLOT::OnRightClick( wxMouseEvent& event )
255 {
256  PopupMenu( m_popMenu );
257 }
258 
259 
260 // Select or deselect groups of layers in the layers list:
262 void DIALOG_PLOT::OnPopUpLayers( wxCommandEvent& event )
263 {
264  unsigned int i;
265 
266  switch( event.GetId() )
267  {
268  case ID_LAYER_FAB: // Select layers usually needed to build a board
269  for( i = 0; i < m_layerList.size(); i++ )
270  {
271  LSET layermask( m_layerList[ i ] );
272 
273  if( ( layermask & ( LSET::AllCuMask() | LSET::AllTechMask() ) ).any() )
274  m_layerCheckListBox->Check( i, true );
275  else
276  m_layerCheckListBox->Check( i, false );
277  }
278  break;
279 
281  for( i = 0; i < m_layerList.size(); i++ )
282  {
283  if( IsCopperLayer( m_layerList[i] ) )
284  m_layerCheckListBox->Check( i, true );
285  }
286  break;
287 
289  for( i = 0; i < m_layerList.size(); i++ )
290  {
291  if( IsCopperLayer( m_layerList[i] ) )
292  m_layerCheckListBox->Check( i, false );
293  }
294  break;
295 
297  for( i = 0; i < m_layerList.size(); i++ )
298  m_layerCheckListBox->Check( i, true );
299  break;
300 
302  for( i = 0; i < m_layerList.size(); i++ )
303  m_layerCheckListBox->Check( i, false );
304  break;
305 
306  default:
307  break;
308  }
309 }
310 
311 
312 void DIALOG_PLOT::CreateDrillFile( wxCommandEvent& event )
313 {
314  // Be sure drill file use the same settings (axis option, plot directory)
315  // than plot files:
317  m_parent->InstallDrillFrame( event );
318 
319  // a few plot settings can be modified: take them in account
321  reInitDialog();
322 }
323 
324 
325 void DIALOG_PLOT::OnChangeDXFPlotMode( wxCommandEvent& event )
326 {
327  // m_DXF_plotTextStrokeFontOpt is disabled if m_DXF_plotModeOpt
328  // is checked (plot in DXF polygon mode)
329  m_DXF_plotTextStrokeFontOpt->Enable( !m_DXF_plotModeOpt->GetValue() );
330 
331  // if m_DXF_plotTextStrokeFontOpt option is disabled (plot DXF in polygon mode),
332  // force m_DXF_plotTextStrokeFontOpt to true to use Pcbnew stroke font
333  if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() )
334  m_DXF_plotTextStrokeFontOpt->SetValue( true );
335 }
336 
337 
338 void DIALOG_PLOT::OnSetScaleOpt( wxCommandEvent& event )
339 {
340  /* Disable sheet reference for scale != 1:1 */
341  bool scale1 = ( m_scaleOpt->GetSelection() == 1 );
342 
343  m_plotSheetRef->Enable( scale1 );
344 
345  if( !scale1 )
346  m_plotSheetRef->SetValue( false );
347 }
348 
349 
350 void DIALOG_PLOT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
351 {
352  // Build the absolute path of current output plot directory
353  // to preselect it when opening the dialog.
354  wxFileName fn( m_outputDirectoryName->GetValue() );
355  wxString path = Prj().AbsolutePath( m_outputDirectoryName->GetValue() );
356 
357  wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
358 
359  if( dirDialog.ShowModal() == wxID_CANCEL )
360  return;
361 
362  wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
363 
364  fn = Prj().AbsolutePath( m_parent->GetBoard()->GetFileName() );
365  wxString defaultPath = fn.GetPathWithSep();
366  wxString msg;
367  msg.Printf( _( "Do you want to use a path relative to\n\"%s\"" ),
368  GetChars( defaultPath ) );
369 
370  wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
371  wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
372 
373  if( dialog.ShowModal() == wxID_YES )
374  {
375  if( !dirName.MakeRelativeTo( defaultPath ) )
376  wxMessageBox( _( "Cannot make path relative (target volume different from file volume)!" ),
377  _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
378  }
379 
380  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
381 }
382 
383 
385 {
386  // plot format id's are ordered like displayed in m_plotFormatOpt
387  static const PlotFormat plotFmt[] =
388  {
395  };
396 
397  return plotFmt[ m_plotFormatOpt->GetSelection() ];
398 }
399 
400 
401 // Enable or disable widgets according to the plot format selected
402 // and clear also some optional values
403 void DIALOG_PLOT::SetPlotFormat( wxCommandEvent& event )
404 {
405  // this option exist only in DXF format:
407 
408  switch( getPlotFormat() )
409  {
410  case PLOT_FORMAT_PDF:
411  case PLOT_FORMAT_SVG:
412  m_drillShapeOpt->Enable( true );
413  m_plotModeOpt->Enable( false );
415  m_plotMirrorOpt->Enable( true );
416  m_useAuxOriginCheckBox->Enable( false );
417  m_useAuxOriginCheckBox->SetValue( false );
418  m_linesWidth->Enable( true );
419  m_HPGLPenSizeOpt->Enable( false );
420  m_excludeEdgeLayerOpt->Enable( true );
421  m_scaleOpt->Enable( false );
422  m_scaleOpt->SetSelection( 1 );
423  m_fineAdjustXscaleOpt->Enable( false );
424  m_fineAdjustYscaleOpt->Enable( false );
425  m_PSFineAdjustWidthOpt->Enable( false );
426  m_plotPSNegativeOpt->Enable( true );
427  m_forcePSA4OutputOpt->Enable( false );
428  m_forcePSA4OutputOpt->SetValue( false );
429 
434  break;
435 
436  case PLOT_FORMAT_POST:
437  m_drillShapeOpt->Enable( true );
438  m_plotModeOpt->Enable( true );
439  m_plotMirrorOpt->Enable( true );
440  m_useAuxOriginCheckBox->Enable( false );
441  m_useAuxOriginCheckBox->SetValue( false );
442  m_linesWidth->Enable( true );
443  m_HPGLPenSizeOpt->Enable( false );
444  m_excludeEdgeLayerOpt->Enable( true );
445  m_scaleOpt->Enable( true );
446  m_fineAdjustXscaleOpt->Enable( true );
447  m_fineAdjustYscaleOpt->Enable( true );
448  m_PSFineAdjustWidthOpt->Enable( true );
449  m_plotPSNegativeOpt->Enable( true );
450  m_forcePSA4OutputOpt->Enable( true );
451 
456  break;
457 
458  case PLOT_FORMAT_GERBER:
459  m_drillShapeOpt->Enable( false );
460  m_drillShapeOpt->SetSelection( 0 );
461  m_plotModeOpt->Enable( false );
463  m_plotMirrorOpt->Enable( false );
464  m_plotMirrorOpt->SetValue( false );
465  m_useAuxOriginCheckBox->Enable( true );
466  m_linesWidth->Enable( true );
467  m_HPGLPenSizeOpt->Enable( false );
468  m_excludeEdgeLayerOpt->Enable( true );
469  m_scaleOpt->Enable( false );
470  m_scaleOpt->SetSelection( 1 );
471  m_fineAdjustXscaleOpt->Enable( false );
472  m_fineAdjustYscaleOpt->Enable( false );
473  m_PSFineAdjustWidthOpt->Enable( false );
474  m_plotPSNegativeOpt->Enable( false );
475  m_plotPSNegativeOpt->SetValue( false );
476  m_forcePSA4OutputOpt->Enable( false );
477  m_forcePSA4OutputOpt->SetValue( false );
478 
483  break;
484 
485  case PLOT_FORMAT_HPGL:
486  m_drillShapeOpt->Enable( true );
487  m_plotModeOpt->Enable( true );
488  m_plotMirrorOpt->Enable( true );
489  m_useAuxOriginCheckBox->Enable( false );
490  m_useAuxOriginCheckBox->SetValue( false );
491  m_linesWidth->Enable( false );
492  m_HPGLPenSizeOpt->Enable( true );
493  m_excludeEdgeLayerOpt->Enable( true );
494  m_scaleOpt->Enable( true );
495  m_fineAdjustXscaleOpt->Enable( false );
496  m_fineAdjustYscaleOpt->Enable( false );
497  m_PSFineAdjustWidthOpt->Enable( false );
498  m_plotPSNegativeOpt->SetValue( false );
499  m_plotPSNegativeOpt->Enable( false );
500  m_forcePSA4OutputOpt->Enable( true );
501 
506  break;
507 
508  case PLOT_FORMAT_DXF:
509  m_drillShapeOpt->Enable( true );
510  m_plotModeOpt->Enable( false );
512  m_plotMirrorOpt->Enable( false );
513  m_plotMirrorOpt->SetValue( false );
514  m_useAuxOriginCheckBox->Enable( true );
515  m_linesWidth->Enable( false );
516  m_HPGLPenSizeOpt->Enable( false );
517  m_excludeEdgeLayerOpt->Enable( true );
518  m_scaleOpt->Enable( false );
519  m_scaleOpt->SetSelection( 1 );
520  m_fineAdjustXscaleOpt->Enable( false );
521  m_fineAdjustYscaleOpt->Enable( false );
522  m_PSFineAdjustWidthOpt->Enable( false );
523  m_plotPSNegativeOpt->Enable( false );
524  m_plotPSNegativeOpt->SetValue( false );
525  m_forcePSA4OutputOpt->Enable( false );
526  m_forcePSA4OutputOpt->SetValue( false );
527 
532 
533  OnChangeDXFPlotMode( event );
534  break;
535  }
536 
537  /* Update the interlock between scale and frame reference
538  * (scaling would mess up the frame border...) */
539  OnSetScaleOpt( event );
540 
541  Layout();
542  m_MainSizer->SetSizeHints( this );
543 }
544 
545 
546 // A helper function to "clip" aValue between aMin and aMax
547 // and write result in * aResult
548 // return false if clipped, true if aValue is just copied into * aResult
549 static bool setDouble( double* aResult, double aValue, double aMin, double aMax )
550 {
551  if( aValue < aMin )
552  {
553  *aResult = aMin;
554  return false;
555  }
556  else if( aValue > aMax )
557  {
558  *aResult = aMax;
559  return false;
560  }
561 
562  *aResult = aValue;
563  return true;
564 }
565 
566 
567 static bool setInt( int* aResult, int aValue, int aMin, int aMax )
568 {
569  if( aValue < aMin )
570  {
571  *aResult = aMin;
572  return false;
573  }
574  else if( aValue > aMax )
575  {
576  *aResult = aMax;
577  return false;
578  }
579 
580  *aResult = aValue;
581  return true;
582 }
583 
584 
586 {
587  REPORTER& reporter = m_messagesPanel->Reporter();
588 
589  PCB_PLOT_PARAMS tempOptions;
590 
591  tempOptions.SetExcludeEdgeLayer( m_excludeEdgeLayerOpt->GetValue() );
592  tempOptions.SetSubtractMaskFromSilk( m_subtractMaskFromSilk->GetValue() );
593  tempOptions.SetPlotFrameRef( m_plotSheetRef->GetValue() );
594  tempOptions.SetPlotPadsOnSilkLayer( !m_excludePadsFromSilkscreen->GetValue() );
595  tempOptions.SetUseAuxOrigin( m_useAuxOriginCheckBox->GetValue() );
596  tempOptions.SetPlotValue( m_plotModuleValueOpt->GetValue() );
597  tempOptions.SetPlotReference( m_plotModuleRefOpt->GetValue() );
598  tempOptions.SetPlotInvisibleText( m_plotInvisibleText->GetValue() );
599  tempOptions.SetScaleSelection( m_scaleOpt->GetSelection() );
600  tempOptions.SetDrillMarksType( static_cast<PCB_PLOT_PARAMS::DrillMarksType>
601  ( m_drillShapeOpt->GetSelection() ) );
602  tempOptions.SetMirror( m_plotMirrorOpt->GetValue() );
603  tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED );
604  tempOptions.SetDXFPlotPolygonMode( m_DXF_plotModeOpt->GetValue() );
605  tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() );
606 
607  if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() ) // Currently, only DXF supports this option
608  tempOptions.SetTextMode( PLOTTEXTMODE_DEFAULT );
609  else
610  tempOptions.SetTextMode( m_DXF_plotTextStrokeFontOpt->GetValue() ?
612 
613  // Update settings from text fields. Rewrite values back to the fields,
614  // since the values may have been constrained by the setters.
615 
616  // read HPLG pen size (this param is stored in mils)
617  wxString msg = m_HPGLPenSizeOpt->GetValue();
618  int tmp = ValueFromString( g_UserUnit, msg ) / IU_PER_MILS;
619 
620  if( !tempOptions.SetHPGLPenDiameter( tmp ) )
621  {
622  msg = StringFromValue( g_UserUnit, tempOptions.GetHPGLPenDiameter() * IU_PER_MILS );
623  m_HPGLPenSizeOpt->SetValue( msg );
624  msg.Printf( _( "HPGL pen size constrained." ) );
625  reporter.Report( msg, REPORTER::RPT_INFO );
626  }
627 
628  // Default linewidth
629  msg = m_linesWidth->GetValue();
630  tmp = ValueFromString( g_UserUnit, msg );
631 
632  if( !tempOptions.SetLineWidth( tmp ) )
633  {
634  msg = StringFromValue( g_UserUnit, tempOptions.GetLineWidth() );
635  m_linesWidth->SetValue( msg );
636  msg.Printf( _( "Default line width constrained." ) );
637  reporter.Report( msg, REPORTER::RPT_INFO );
638  }
639 
640  // X scale
641  double tmpDouble;
642  msg = m_fineAdjustXscaleOpt->GetValue();
643  msg.ToDouble( &tmpDouble );
644 
645  if( !setDouble( &m_XScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
646  {
647  msg.Printf( wxT( "%f" ), m_XScaleAdjust );
648  m_fineAdjustXscaleOpt->SetValue( msg );
649  msg.Printf( _( "X scale constrained." ) );
650  reporter.Report( msg, REPORTER::RPT_INFO );
651  }
652 
654 
655  // Y scale
656  msg = m_fineAdjustYscaleOpt->GetValue();
657  msg.ToDouble( &tmpDouble );
658 
659  if( !setDouble( &m_YScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
660  {
661  msg.Printf( wxT( "%f" ), m_YScaleAdjust );
662  m_fineAdjustYscaleOpt->SetValue( msg );
663  msg.Printf( _( "Y scale constrained." ) );
664  reporter.Report( msg, REPORTER::RPT_INFO );
665  }
666 
668 
669  // PS Width correction
670  msg = m_PSFineAdjustWidthOpt->GetValue();
671  int itmp = ValueFromString( g_UserUnit, msg );
672 
674  {
676  m_PSFineAdjustWidthOpt->SetValue( msg );
677  msg.Printf( _( "Width correction constrained. "
678  "The reasonable width correction value must be in a range of "
679  " [%+f; %+f] (%s) for current design rules. " ),
682  ( g_UserUnit == INCHES ) ? wxT( "\"" ) : wxT( "mm" ) );
683  reporter.Report( msg, REPORTER::RPT_WARNING );
684  }
685 
686  // Store m_PSWidthAdjust in mm in user config
688  (double)m_PSWidthAdjust / IU_PER_MM );
689 
690  tempOptions.SetFormat( getPlotFormat() );
691 
692  tempOptions.SetUseGerberProtelExtensions( m_useGerberExtensions->GetValue() );
693  tempOptions.SetUseGerberAttributes( m_useGerberX2Attributes->GetValue() );
694  tempOptions.SetIncludeGerberNetlistInfo( m_useGerberNetAttributes->GetValue() );
695  tempOptions.SetCreateGerberJobFile( m_generateGerberJobFile->GetValue() );
696 
697  tempOptions.SetGerberPrecision( m_rbGerberFormat->GetSelection() == 0 ? 5 : 6 );
698 
699  LSET selectedLayers;
700  for( unsigned i = 0; i < m_layerList.size(); i++ )
701  {
702  if( m_layerCheckListBox->IsChecked( i ) )
703  selectedLayers.set( m_layerList[i] );
704  }
705  // Get a list of copper layers that aren't being used by inverting enabled layers.
706  LSET disabledCopperLayers = LSET::AllCuMask() & ~m_board->GetEnabledLayers();
707  // Enable all of the disabled copper layers.
708  // If someone enables more copper layers they will be selected by default.
709  selectedLayers = selectedLayers | disabledCopperLayers;
710  tempOptions.SetLayerSelection( selectedLayers );
711 
712  tempOptions.SetNegative( m_plotPSNegativeOpt->GetValue() );
713  tempOptions.SetA4Output( m_forcePSA4OutputOpt->GetValue() );
714 
715  // Set output directory and replace backslashes with forward ones
716  wxString dirStr;
717  dirStr = m_outputDirectoryName->GetValue();
718  dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
719  tempOptions.SetOutputDirectory( dirStr );
720 
721  if( !m_plotOpts.IsSameAs( tempOptions, false ) )
722  {
723  // First, mark board as modified only for parameters saved in file
724  if( !m_plotOpts.IsSameAs( tempOptions, true ) )
725  m_parent->OnModify();
726 
727  // Now, save any change, for the session
728  m_parent->SetPlotSettings( tempOptions );
729  m_plotOpts = tempOptions;
730  }
731 }
732 
733 
734 void DIALOG_PLOT::OnGerberX2Checked( wxCommandEvent& event )
735 {
736  // m_useGerberNetAttributes is useless if m_useGerberX2Attributes
737  // is not checked. So disabled (greyed out) when Gerber X2 gets unchecked
738  // to make it clear to the user.
739  if( m_useGerberX2Attributes->GetValue() )
740  {
741  m_useGerberNetAttributes->Enable( true );
742  }
743  else
744  {
745  m_useGerberNetAttributes->Enable( false );
746  m_useGerberNetAttributes->SetValue( false );
747  }
748 }
749 
750 
751 void DIALOG_PLOT::Plot( wxCommandEvent& event )
752 {
754 
755  // If no layer selected, we have nothing plotted.
756  // Prompt user if it happens because he could think there is a bug in Pcbnew.
757  if( !m_plotOpts.GetLayerSelection().any() )
758  {
759  DisplayError( this, _( "No layer selected, Nothing to plot" ) );
760  return;
761  }
762 
763  // Create output directory if it does not exist (also transform it in
764  // absolute form). Bail if it fails
765  wxFileName outputDir = wxFileName::DirName( m_plotOpts.GetOutputDirectory() );
766  wxString boardFilename = m_parent->GetBoard()->GetFileName();
767  REPORTER& reporter = m_messagesPanel->Reporter();
768 
769  if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
770  {
771  wxString msg;
772  msg.Printf( _( "Could not write plot files to folder \"%s\"." ),
773  GetChars( outputDir.GetPath() ) );
774  DisplayError( this, msg );
775  return;
776  }
777 
778  m_plotOpts.SetAutoScale( false );
779  m_plotOpts.SetScale( 1 );
780 
781  switch( m_plotOpts.GetScaleSelection() )
782  {
783  default:
784  break;
785 
786  case 0: // Autoscale option
787  m_plotOpts.SetAutoScale( true );
788  break;
789 
790  case 2: // 3:2 option
791  m_plotOpts.SetScale( 1.5 );
792  break;
793 
794  case 3: // 2:1 option
795  m_plotOpts.SetScale( 2 );
796  break;
797 
798  case 4: // 3:1 option
799  m_plotOpts.SetScale( 3 );
800  break;
801  }
802 
803  /* If the scale factor edit controls are disabled or the scale value
804  * is 0, don't adjust the base scale factor. This fixes a bug when
805  * the default scale adjust is initialized to 0 and saved in program
806  * settings resulting in a divide by zero fault.
807  */
808  if( m_fineAdjustXscaleOpt->IsEnabled() && m_XScaleAdjust != 0.0 )
810 
811  if( m_fineAdjustYscaleOpt->IsEnabled() && m_YScaleAdjust != 0.0 )
813 
814  if( m_PSFineAdjustWidthOpt->IsEnabled() )
816 
817  wxString file_ext( GetDefaultPlotExtension( m_plotOpts.GetFormat() ) );
818 
819  // Test for a reasonable scale value
820  // XXX could this actually happen? isn't it constrained in the apply
821  // function?
823  DisplayInfoMessage( this,
824  _( "Warning: Scale option set to a very small value" ) );
825 
827  DisplayInfoMessage( this,
828  _( "Warning: Scale option set to a very large value" ) );
829 
830  GERBER_JOBFILE_WRITER jobfile_writer( m_board, &reporter );
831 
832  // Save the current plot options in the board
834 
835  wxBusyCursor dummy;
836 
837  for( LSEQ seq = m_plotOpts.GetLayerSelection().UIOrder(); seq; ++seq )
838  {
839  PCB_LAYER_ID layer = *seq;
840 
841  // All copper layers that are disabled are actually selected
842  // This is due to wonkyness in automatically selecting copper layers
843  // for plotting when adding more than two layers to a board.
844  // If plot options become accessible to the layers setup dialog
845  // please move this functionality there!
846  // This skips a copper layer if it is actually disabled on the board.
847  if( ( LSET::AllCuMask() & ~m_board->GetEnabledLayers() )[layer] )
848  continue;
849 
850  // Pick the basename from the board file
851  wxFileName fn( boardFilename );
852 
853  // Use Gerber Extensions based on layer number
854  // (See http://en.wikipedia.org/wiki/Gerber_File)
856  file_ext = GetGerberProtelExtension( layer );
857 
858  BuildPlotFileName( &fn, outputDir.GetPath(), m_board->GetLayerName( layer ), file_ext );
859  wxString fullname = fn.GetFullName();
860  jobfile_writer.AddGbrFile( layer, fullname );
861 
862  LOCALE_IO toggle;
863 
864  BOARD* board = m_parent->GetBoard();
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;
875 
876  msg.Printf( _( "Plot file \"%s\" created." ), GetChars( fn.GetFullPath() ) );
877  reporter.Report( msg, REPORTER::RPT_ACTION );
878  }
879  else
880  {
881  msg.Printf( _( "Unable to create file \"%s\"." ), GetChars( fn.GetFullPath() ) );
882  reporter.Report( msg, REPORTER::RPT_ERROR );
883  }
884  }
885 
887  {
888  // Pick the basename from the board file
889  wxFileName fn( boardFilename );
890  // Build gerber job file from basename
891  BuildPlotFileName( &fn, outputDir.GetPath(), "job", GerberJobFileExtension );
892  jobfile_writer.CreateJobFile( fn.GetFullPath() );
893  }
894 }
895 
896 
897 void DIALOG_PLOT::onRunDRC( wxCommandEvent& event )
898 {
899  PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
900 
901  if( parent )
902  {
903  // First close an existing dialog if open
904  // (low probability, but can happen)
905  parent->GetDrcController()->DestroyDRCDialog( wxID_OK );
906 
907  // Open a new drc dialod, with the right parent frame, and in Modal Mode
908  parent->GetDrcController()->ShowDRCDialog( this );
909  }
910 }
911 
void SetTextMode(PlotTextMode aVal)
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:673
void SetUseGerberProtelExtensions(bool aUse)
void SetPlotReference(bool aFlag)
void SetExcludeEdgeLayer(bool aFlag)
bool GetUseGerberProtelExtensions() const
WX_HTML_REPORT_PANEL * m_messagesPanel
wxStaticBoxSizer * m_HPGLOptionsSizer
void SetScaleSelection(int aSelection)
wxStaticText * m_textPSFineAdjustWidth
LSEQ m_layerList
Definition: dialog_plot.h:45
void SetIncludeGerberNetlistInfo(bool aUse)
int m_SolderMaskMargin
Solder mask margin.
void SetDXFPlotPolygonMode(bool aFlag)
wxTextCtrl * m_linesWidth
bool GetMirror() const
double m_YScaleAdjust
Definition: dialog_plot.h:48
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
bool GetSubtractMaskFromSilk() const
wxTextCtrl * m_fineAdjustYscaleOpt
int GetHPGLPenDiameter() const
wxCheckBox * m_useGerberExtensions
void DestroyDRCDialog(int aReason)
Deletes this ui dialog box and zeros out its pointer to remember the state of the dialog&#39;s existence...
Definition: drc.cpp:102
double GetScale() const
void SetGerberPrecision(int aPrecision)
void OnOutputDirectoryBrowseClicked(wxCommandEvent &event) override
void SetPlotViaOnMaskLayer(bool aFlag)
bool CreateJobFile(const wxString &aFullFilename)
Creates an Excellon drill file.
wxStaticText * m_SolderMaskMarginCurrValue
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
#define OPTKEY_PLOT_Y_FINESCALE_ADJ
Definition: pcbplot.h:62
void SetLayerSelection(LSET aSelection)
void OnGerberX2Checked(wxCommandEvent &event) override
void SetUseAuxOrigin(bool aAux)
Implementation of conversion functions that require both schematic and board internal units...
This file is part of the common library.
int GetSmallestClearanceValue()
Function GetSmallestClearanceValue.
bool GetUseGerberAttributes() const
wxStaticText * m_textPenSize
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:68
Class BOARD to handle a board.
wxRadioBox * m_rbGerberFormat
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:204
void SetFormat(PlotFormat aFormat)
PlotFormat getPlotFormat()
wxString GetDefaultPlotExtension(PlotFormat aFormat)
Returns the default plot extension for a format.
wxCheckBox * m_excludeEdgeLayerOpt
void SetCreateGerberJobFile(bool aCreate)
void onRunDRC(wxCommandEvent &event) override
void SetMirror(bool aFlag)
const wxString GetGerberProtelExtension(LAYER_NUM aLayer)
Function GetGerberProtelExtension.
Definition: pcbplot.cpp:47
BOARD * m_board
Definition: dialog_plot.h:43
PlotFormat
Enum PlotFormat is the set of supported output plot formats.
Definition: plotter.h:50
BOARD * GetBoard() const
wxCheckBox * m_plotMirrorOpt
bool GetUseAuxOrigin() const
void SetDrillMarksType(DrillMarksType aVal)
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
LSET GetLayerSelection() const
wxChoice * m_plotFormatOpt
static LSET AllTechMask()
Function AllTechMask returns a mask holding all technical layers (no CU layer) on both side...
Definition: lset.cpp:743
void CreateDrillFile(wxCommandEvent &event) override
Classes used in drill files, map files and report files generation.
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
wxStaticBoxSizer * m_SizerDXF_options
bool GetPlotValue() const
wxCheckBox * m_useGerberX2Attributes
virtual const PCB_PLOT_PARAMS & GetPlotSettings() const
Function GetPlotSettings returns the PCB_PLOT_PARAMS for the BOARD owned by this frame.
void SetA4Output(int aForce)
double m_XScaleAdjust
Definition: dialog_plot.h:46
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
bool SetHPGLPenDiameter(int aValue)
wxCheckBox * m_DXF_plotModeOpt
bool SetLineWidth(int aValue)
This file contains miscellaneous commonly used macros and functions.
void SetPlotValue(bool aFlag)
bool GetA4Output() const
bool GetExcludeEdgeLayer() const
Board plot function definition file.
wxCheckBox * m_plotSheetRef
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
virtual bool EndPlot()=0
void SetPlotFrameRef(bool aFlag)
wxString GetOutputDirectory() const
void SetPlotFormat(wxCommandEvent &event) override
void Plot(wxCommandEvent &event) override
wxTextCtrl * m_PSFineAdjustWidthOpt
DrillMarksType GetDrillMarksType() const
Class DIALOG_PLOT_BASE.
PCB_LAYER_ID
A quick note on layer IDs:
GERBER_JOBFILE_WRITER is a class used to create Gerber job file a Gerber job file stores info to make...
bool GetIncludeGerberNetlistInfo() const
Class LSET is a set of PCB_LAYER_IDs.
#define OPTKEY_PLOT_X_FINESCALE_ADJ
Definition: pcbplot.h:61
PCB_EDIT_FRAME * m_parent
Definition: dialog_plot.h:42
int GetLineWidth() const
int m_widthAdjustMaxValue
Definition: dialog_plot.h:55
wxStaticText * m_SolderMaskMinWidthCurrValue
const wxString & GetFileName() const
Definition: class_board.h:234
PlotTextMode GetTextMode() const
int m_TrackMinWidth
track min value for width ((min copper size value
Definition: common.h:145
static bool setDouble(double *aResult, double aValue, double aMin, double aMax)
bool EnsureFileDirectoryExists(wxFileName *aTargetFullFileName, const wxString &aBaseFilename, REPORTER *aReporter)
Helper function EnsureFileDirectoryExists make aTargetFullFileName absolute and creates the path of t...
Definition: common.cpp:267
REPORTER & Reporter()
returns the reporter object that reports to this panel
#define PLOT_MAX_SCALE
Definition: pcbplot.h:69
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
int m_PSWidthAdjust
Definition: dialog_plot.h:50
VTBL_ENTRY const wxString AbsolutePath(const wxString &aFileName) const
Function AbsolutePath fixes up aFileName if it is relative to the project&#39;s directory to be an absolu...
Definition: project.cpp:380
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:369
The common library.
wxCheckBox * m_forcePSA4OutputOpt
void OnPopUpLayers(wxCommandEvent &event) override
void SetSubtractMaskFromSilk(bool aSubtract)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
void AddGbrFile(PCB_LAYER_ID aLayer, wxString &aFilename)
add a gerber file name and type in job file list
#define CONFIG_PS_FINEWIDTH_ADJ
Definition: pcbplot.h:63
void setPlotModeChoiceSelection(EDA_DRAW_MODE_T aPlotMode)
Definition: dialog_plot.h:80
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
bool GetPlotViaOnMaskLayer() const
int GetScaleSelection() const
virtual void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings)
void OnSetScaleOpt(wxCommandEvent &event) override
wxStaticBoxSizer * m_GerberOptionsSizer
bool GetCreateGerberJobFile() const
wxCheckBox * m_useGerberNetAttributes
void SetOutputDirectory(wxString aDir)
bool GetPlotReference() const
int m_widthAdjustMinValue
Definition: dialog_plot.h:54
PlotFormat GetFormat() const
void SetUseGerberAttributes(bool aUse)
wxCheckBox * m_generateGerberJobFile
Class PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board...
wxTextCtrl * m_outputDirectoryName
void SetPlotInvisibleText(bool aFlag)
bool IsSameAs(const PCB_PLOT_PARAMS &aPcbPlotParams, bool aCompareOnlySavedPrms) const
Compare current settings to aPcbPlotParams, including not saved parameters in brd file...
void SetScale(double aVal)
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
wxCheckBox * m_DXF_plotTextStrokeFontOpt
const wxString GerberJobFileExtension
PCB_PLOT_PARAMS m_plotOpts
Definition: dialog_plot.h:58
void SetNegative(bool aFlag)
bool GetDXFPlotPolygonMode() const
BOARD * GetBoard()
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
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:484
void reInitDialog()
wxCheckBox * m_plotModuleRefOpt
void ConfigBaseWriteDouble(wxConfigBase *aConfig, const wxString &aKey, double aValue)
Function ConfigBaseWriteDouble This is a helper function to write doubles in config We cannot use wxC...
void SetPlotPadsOnSilkLayer(bool aFlag)
void SetPlotMode(EDA_DRAW_MODE_T aPlotMode)
Base plotter engine class.
Definition: plotter.h:96
wxCheckBox * m_subtractMaskFromSilk
void init_Dialog()
Definition: dialog_plot.cpp:61
wxCheckBox * m_plotNoViaOnMaskOpt
wxCheckBox * m_plotModuleValueOpt
void ShowDRCDialog(wxWindow *aParent=NULL)
Open a dialog and prompts the user, then if a test run button is clicked, runs the test(s) and create...
Definition: drc.cpp:59
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:92
bool GetPlotInvisibleText() const
wxChoice * m_drillShapeOpt
void AddUnitSymbol(wxStaticText &Stext, EDA_UNITS_T aUnit)
Definition: base_units.cpp:514
Board layer functions and definitions.
wxTextCtrl * m_fineAdjustXscaleOpt
void applyPlotSettings()
void SetWidthAdjust(int aVal)
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
bool GetNegative() const
static bool setInt(int *aResult, int aValue, int aMin, int aMax)
bool GetPlotFrameRef() const
wxTextCtrl * m_HPGLPenSizeOpt
wxCheckBox * m_plotInvisibleText
EDA_DRAW_MODE_T GetPlotMode() const
bool GetPlotPadsOnSilkLayer() const
wxCheckBox * m_useAuxOriginCheckBox
void SetAutoScale(bool aFlag)
void SetFineScaleAdjustY(double aVal)
wxChoice * m_plotModeOpt
wxConfigBase * m_config
Definition: dialog_plot.h:44
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
double To_User_Unit(EDA_UNITS_T aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:91
wxCheckBox * m_excludePadsFromSilkscreen
void OnRightClick(wxMouseEvent &event) override
wxBitmapButton * m_browseButton
wxBoxSizer * m_MainSizer
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...
wxStaticText * m_textDefaultPenSize
void OnQuit(wxCommandEvent &event) override
wxCheckListBox * m_layerCheckListBox
DRC * GetDrcController()
wxStaticBoxSizer * m_PSOptionsSizer
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:105
void OnClose(wxCloseEvent &event) override
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:74
wxBoxSizer * m_PlotOptionsSizer
void InstallDrillFrame(wxCommandEvent &event)
DIALOG_PLOT(PCB_EDIT_FRAME *parent)
Definition: dialog_plot.cpp:48
int m_SolderMaskMinWidth
Solder mask min width.
LSEQ UIOrder() const
Definition: lset.cpp:786
int GetGerberPrecision() const