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-2016 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 <plot_common.h>
31 #include <confirm.h>
32 #include <wxPcbStruct.h>
33 #include <pcbplot.h>
34 #include <base_units.h>
35 #include <macros.h>
36 #include <reporter.h>
37 
38 #include <class_board.h>
39 #include <wx/ffile.h>
40 #include <dialog_plot.h>
41 #include <wx_html_report_panel.h>
42 
43 // Uncomment this line to allow experimetal net attributes in Gerber files:
44 #define KICAD_USE_GBR_NETATTRIBUTES
45 
47  DIALOG_PLOT_BASE( aParent ), m_parent( aParent ),
48  m_board( aParent->GetBoard() ),
49  m_plotOpts( aParent->GetPlotSettings() )
50 {
52  Init_Dialog();
53 
54  GetSizer()->Fit( this );
55  GetSizer()->SetSizeHints( this );
56 }
57 
58 
60 {
61  wxString msg;
62  wxFileName fileName;
63 
66 
67  // m_PSWidthAdjust is stored in mm in user config
68  double dtmp;
69  m_config->Read( CONFIG_PS_FINEWIDTH_ADJ, &dtmp, 0 );
70  m_PSWidthAdjust = KiROUND( dtmp * IU_PER_MM );
71 
72  // The reasonable width correction value must be in a range of
73  // [-(MinTrackWidth-1), +(MinClearanceValue-1)] decimils.
76 
77  switch( m_plotOpts.GetFormat() )
78  {
79  default:
80  case PLOT_FORMAT_GERBER:
81  m_plotFormatOpt->SetSelection( 0 );
82  break;
83 
84  case PLOT_FORMAT_POST:
85  m_plotFormatOpt->SetSelection( 1 );
86  break;
87 
88  case PLOT_FORMAT_SVG:
89  m_plotFormatOpt->SetSelection( 2 );
90  break;
91 
92  case PLOT_FORMAT_DXF:
93  m_plotFormatOpt->SetSelection( 3 );
94  break;
95 
96  case PLOT_FORMAT_HPGL:
97  m_plotFormatOpt->SetSelection( 4 );
98  break;
99 
100  case PLOT_FORMAT_PDF:
101  m_plotFormatOpt->SetSelection( 5 );
102  break;
103  }
104 
106  m_SolderMaskMarginCurrValue->SetLabel( msg );
108  m_SolderMaskMinWidthCurrValue->SetLabel( msg );
109 
110  // Set units and value for HPGL pen size (this param in in mils).
113  m_plotOpts.GetHPGLPenDiameter() * IU_PER_MILS );
114  m_HPGLPenSizeOpt->AppendText( msg );
115 
118  m_linesWidth->AppendText( msg );
119 
120  // Set units for PS global width correction.
122 
124 
125  // Test for a reasonable scale value. Set to 1 if problem
129 
130  msg.Printf( wxT( "%f" ), m_XScaleAdjust );
131  m_fineAdjustXscaleOpt->AppendText( msg );
132 
133  msg.Printf( wxT( "%f" ), m_YScaleAdjust );
134  m_fineAdjustYscaleOpt->AppendText( msg );
135 
136  // Test for a reasonable PS width correction value. Set to 0 if problem.
137  if( m_PSWidthAdjust < m_widthAdjustMinValue || m_PSWidthAdjust > m_widthAdjustMaxValue )
138  m_PSWidthAdjust = 0.;
139 
140  msg.Printf( wxT( "%f" ), To_User_Unit( g_UserUnit, m_PSWidthAdjust ) );
141  m_PSFineAdjustWidthOpt->AppendText( msg );
142 
145 
146  // Could devote a PlotOrder() function in place of UIOrder().
148 
149  // Populate the check list box by all enabled layers names
150  for( LSEQ seq = m_layerList; seq; ++seq )
151  {
152  LAYER_ID layer = *seq;
153 
154  int checkIndex = m_layerCheckListBox->Append( m_board->GetLayerName( layer ) );
155 
156  if( m_plotOpts.GetLayerSelection()[layer] )
157  m_layerCheckListBox->Check( checkIndex );
158  }
159 
160  // Option for using proper Gerber extensions
162 
163  // Option for including Gerber attributes (from Gerber X2 format) in the output
165 
166  // Option for including Gerber netlist info (from Gerber X2 format) in the output
167 #ifdef KICAD_USE_GBR_NETATTRIBUTES
169 
170  // Grey out if m_useGerberX2Attributes is not checked
171  m_useGerberNetAttributes->Enable( m_useGerberX2Attributes->GetValue() );
172 #else
174  m_useGerberNetAttributes->SetValue( false );
175 #endif
176  // Gerber precision for coordinates
177  m_rbGerberFormat->SetSelection( m_plotOpts.GetGerberPrecision() == 5 ? 0 : 1 );
178 
179  // Option for excluding contents of "Edges Pcb" layer
181 
183 
184  // Option to plot page references:
186 
187  // Option to allow pads on silkscreen layers
189 
190  // Options to plot texts on footprints
194 
195  // Options to plot pads and vias holes
196  m_drillShapeOpt->SetSelection( m_plotOpts.GetDrillMarksType() );
197 
198  // Scale option
199  m_scaleOpt->SetSelection( m_plotOpts.GetScaleSelection() );
200 
201  // Plot mode
203 
204  // Plot mirror option
205  m_plotMirrorOpt->SetValue( m_plotOpts.GetMirror() );
206 
207  // Put vias on mask layer
209 
210  // Output directory
212 
213  // Update options values:
214  wxCommandEvent cmd_event;
215  SetPlotFormat( cmd_event );
216  OnSetScaleOpt( cmd_event );
217 }
218 
219 
220 void DIALOG_PLOT::OnQuit( wxCommandEvent& event )
221 {
222  Close( true ); // true is to force the frame to close
223 }
224 
225 
226 void DIALOG_PLOT::OnClose( wxCloseEvent& event )
227 {
229  EndModal( 0 );
230 }
231 
232 
233 // A helper function to show a popup menu, when the dialog is right clicked.
234 void DIALOG_PLOT::OnRightClick( wxMouseEvent& event )
235 {
236  PopupMenu( m_popMenu );
237 }
238 
239 
240 // Select or deselect groups of layers in the layers list:
242 void DIALOG_PLOT::OnPopUpLayers( wxCommandEvent& event )
243 {
244  unsigned int i;
245 
246  switch( event.GetId() )
247  {
248  case ID_LAYER_FAB: // Select layers usually needed to build a board
249  for( i = 0; i < m_layerList.size(); i++ )
250  {
251  LSET layermask( m_layerList[ i ] );
252 
253  if( ( layermask & ( LSET::AllCuMask() | LSET::AllTechMask() ) ).any() )
254  m_layerCheckListBox->Check( i, true );
255  else
256  m_layerCheckListBox->Check( i, false );
257  }
258  break;
259 
261  for( i = 0; i < m_layerList.size(); i++ )
262  {
263  if( IsCopperLayer( m_layerList[i] ) )
264  m_layerCheckListBox->Check( i, true );
265  }
266  break;
267 
269  for( i = 0; i < m_layerList.size(); i++ )
270  {
271  if( IsCopperLayer( m_layerList[i] ) )
272  m_layerCheckListBox->Check( i, false );
273  }
274  break;
275 
277  for( i = 0; i < m_layerList.size(); i++ )
278  m_layerCheckListBox->Check( i, true );
279  break;
280 
282  for( i = 0; i < m_layerList.size(); i++ )
283  m_layerCheckListBox->Check( i, false );
284  break;
285 
286  default:
287  break;
288  }
289 }
290 
291 
292 void DIALOG_PLOT::CreateDrillFile( wxCommandEvent& event )
293 {
294  m_parent->InstallDrillFrame( event );
295 }
296 
297 
298 void DIALOG_PLOT::OnSetScaleOpt( wxCommandEvent& event )
299 {
300  /* Disable sheet reference for scale != 1:1 */
301  bool scale1 = ( m_scaleOpt->GetSelection() == 1 );
302 
303  m_plotSheetRef->Enable( scale1 );
304 
305  if( !scale1 )
306  m_plotSheetRef->SetValue( false );
307 }
308 
309 
310 void DIALOG_PLOT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
311 {
312  // Build the absolute path of current output plot directory
313  // to preselect it when opening the dialog.
314  wxFileName fn( m_outputDirectoryName->GetValue() );
315  wxString path = Prj().AbsolutePath( m_outputDirectoryName->GetValue() );
316 
317  wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
318 
319  if( dirDialog.ShowModal() == wxID_CANCEL )
320  return;
321 
322  wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
323 
324  fn = Prj().AbsolutePath( m_parent->GetBoard()->GetFileName() );
325  wxString defaultPath = fn.GetPathWithSep();
326  wxString msg;
327  msg.Printf( _( "Do you want to use a path relative to\n'%s'" ),
328  GetChars( defaultPath ) );
329 
330  wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
331  wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
332 
333  if( dialog.ShowModal() == wxID_YES )
334  {
335  if( !dirName.MakeRelativeTo( defaultPath ) )
336  wxMessageBox( _( "Cannot make path relative (target volume different from file volume)!" ),
337  _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
338  }
339 
340  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
341 }
342 
343 
345 {
346  // plot format id's are ordered like displayed in m_plotFormatOpt
347  static const PlotFormat plotFmt[] =
348  {
355  };
356 
357  return plotFmt[ m_plotFormatOpt->GetSelection() ];
358 }
359 
360 
361 // Enable or disable widgets according to the plot format selected
362 // and clear also some optional values
363 void DIALOG_PLOT::SetPlotFormat( wxCommandEvent& event )
364 {
365  switch( getPlotFormat() )
366  {
367  case PLOT_FORMAT_PDF:
368  case PLOT_FORMAT_SVG:
369  m_drillShapeOpt->Enable( true );
370  m_plotModeOpt->Enable( false );
372  m_plotMirrorOpt->Enable( true );
373  m_useAuxOriginCheckBox->Enable( false );
374  m_useAuxOriginCheckBox->SetValue( false );
375  m_linesWidth->Enable( true );
376  m_HPGLPenSizeOpt->Enable( false );
377  m_excludeEdgeLayerOpt->Enable( true );
378  m_scaleOpt->Enable( false );
379  m_scaleOpt->SetSelection( 1 );
380  m_fineAdjustXscaleOpt->Enable( false );
381  m_fineAdjustYscaleOpt->Enable( false );
382  m_PSFineAdjustWidthOpt->Enable( false );
383  m_plotPSNegativeOpt->Enable( true );
384  m_forcePSA4OutputOpt->Enable( false );
385  m_forcePSA4OutputOpt->SetValue( false );
386 
390  break;
391 
392  case PLOT_FORMAT_POST:
393  m_drillShapeOpt->Enable( true );
394  m_plotModeOpt->Enable( true );
395  m_plotMirrorOpt->Enable( true );
396  m_useAuxOriginCheckBox->Enable( false );
397  m_useAuxOriginCheckBox->SetValue( false );
398  m_linesWidth->Enable( true );
399  m_HPGLPenSizeOpt->Enable( false );
400  m_excludeEdgeLayerOpt->Enable( true );
401  m_scaleOpt->Enable( true );
402  m_fineAdjustXscaleOpt->Enable( true );
403  m_fineAdjustYscaleOpt->Enable( true );
404  m_PSFineAdjustWidthOpt->Enable( true );
405  m_plotPSNegativeOpt->Enable( true );
406  m_forcePSA4OutputOpt->Enable( true );
407 
411  break;
412 
413  case PLOT_FORMAT_GERBER:
414  m_drillShapeOpt->Enable( false );
415  m_drillShapeOpt->SetSelection( 0 );
416  m_plotModeOpt->Enable( false );
418  m_plotMirrorOpt->Enable( false );
419  m_plotMirrorOpt->SetValue( false );
420  m_useAuxOriginCheckBox->Enable( true );
421  m_linesWidth->Enable( true );
422  m_HPGLPenSizeOpt->Enable( false );
423  m_excludeEdgeLayerOpt->Enable( true );
424  m_scaleOpt->Enable( false );
425  m_scaleOpt->SetSelection( 1 );
426  m_fineAdjustXscaleOpt->Enable( false );
427  m_fineAdjustYscaleOpt->Enable( false );
428  m_PSFineAdjustWidthOpt->Enable( false );
429  m_plotPSNegativeOpt->Enable( false );
430  m_plotPSNegativeOpt->SetValue( false );
431  m_forcePSA4OutputOpt->Enable( false );
432  m_forcePSA4OutputOpt->SetValue( false );
433 
437 #ifndef KICAD_USE_GBR_NETATTRIBUTES
438  m_useGerberNetAttributes->Show( false );
439 #endif
440  break;
441 
442  case PLOT_FORMAT_HPGL:
443  m_drillShapeOpt->Enable( true );
444  m_plotModeOpt->Enable( true );
445  m_plotMirrorOpt->Enable( true );
446  m_useAuxOriginCheckBox->Enable( false );
447  m_useAuxOriginCheckBox->SetValue( false );
448  m_linesWidth->Enable( false );
449  m_HPGLPenSizeOpt->Enable( true );
450  m_excludeEdgeLayerOpt->Enable( true );
451  m_scaleOpt->Enable( true );
452  m_fineAdjustXscaleOpt->Enable( false );
453  m_fineAdjustYscaleOpt->Enable( false );
454  m_PSFineAdjustWidthOpt->Enable( false );
455  m_plotPSNegativeOpt->SetValue( false );
456  m_plotPSNegativeOpt->Enable( false );
457  m_forcePSA4OutputOpt->Enable( true );
458 
462  break;
463 
464  case PLOT_FORMAT_DXF:
465  m_drillShapeOpt->Enable( true );
466  m_plotModeOpt->Enable( false );
467  m_plotMirrorOpt->Enable( false );
468  m_plotMirrorOpt->SetValue( false );
469  m_useAuxOriginCheckBox->Enable( true );
470  m_linesWidth->Enable( false );
471  m_HPGLPenSizeOpt->Enable( false );
472  m_excludeEdgeLayerOpt->Enable( true );
473  m_scaleOpt->Enable( false );
474  m_scaleOpt->SetSelection( 1 );
475  m_fineAdjustXscaleOpt->Enable( false );
476  m_fineAdjustYscaleOpt->Enable( false );
477  m_PSFineAdjustWidthOpt->Enable( false );
478  m_plotPSNegativeOpt->Enable( false );
479  m_plotPSNegativeOpt->SetValue( false );
480  m_forcePSA4OutputOpt->Enable( false );
481  m_forcePSA4OutputOpt->SetValue( false );
482 
486  break;
487 
488  default:
489  wxASSERT( false );
490  }
491 
492  /* Update the interlock between scale and frame reference
493  * (scaling would mess up the frame border...) */
494  OnSetScaleOpt( event );
495 
496  Layout();
497  m_MainSizer->SetSizeHints( this );
498 }
499 
500 
501 // A helper function to "clip" aValue between aMin and aMax
502 // and write result in * aResult
503 // return false if clipped, true if aValue is just copied into * aResult
504 static bool setDouble( double* aResult, double aValue, double aMin, double aMax )
505 {
506  if( aValue < aMin )
507  {
508  *aResult = aMin;
509  return false;
510  }
511  else if( aValue > aMax )
512  {
513  *aResult = aMax;
514  return false;
515  }
516 
517  *aResult = aValue;
518  return true;
519 }
520 
521 
522 static bool setInt( int* aResult, int aValue, int aMin, int aMax )
523 {
524  if( aValue < aMin )
525  {
526  *aResult = aMin;
527  return false;
528  }
529  else if( aValue > aMax )
530  {
531  *aResult = aMax;
532  return false;
533  }
534 
535  *aResult = aValue;
536  return true;
537 }
538 
539 
541 {
542  REPORTER& reporter = m_messagesPanel->Reporter();
543 
544  PCB_PLOT_PARAMS tempOptions;
545 
546  tempOptions.SetExcludeEdgeLayer( m_excludeEdgeLayerOpt->GetValue() );
547  tempOptions.SetSubtractMaskFromSilk( m_subtractMaskFromSilk->GetValue() );
548  tempOptions.SetPlotFrameRef( m_plotSheetRef->GetValue() );
549  tempOptions.SetPlotPadsOnSilkLayer( m_plotPads_on_Silkscreen->GetValue() );
550  tempOptions.SetUseAuxOrigin( m_useAuxOriginCheckBox->GetValue() );
551  tempOptions.SetPlotValue( m_plotModuleValueOpt->GetValue() );
552  tempOptions.SetPlotReference( m_plotModuleRefOpt->GetValue() );
553  tempOptions.SetPlotInvisibleText( m_plotInvisibleText->GetValue() );
554  tempOptions.SetScaleSelection( m_scaleOpt->GetSelection() );
555  tempOptions.SetDrillMarksType( static_cast<PCB_PLOT_PARAMS::DrillMarksType>
556  ( m_drillShapeOpt->GetSelection() ) );
557  tempOptions.SetMirror( m_plotMirrorOpt->GetValue() );
558  tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED );
559  tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() );
560 
561  // Update settings from text fields. Rewrite values back to the fields,
562  // since the values may have been constrained by the setters.
563 
564  // read HPLG pen size (this param is stored in mils)
565  wxString msg = m_HPGLPenSizeOpt->GetValue();
566  int tmp = ValueFromString( g_UserUnit, msg ) / IU_PER_MILS;
567 
568  if( !tempOptions.SetHPGLPenDiameter( tmp ) )
569  {
570  msg = StringFromValue( g_UserUnit, tempOptions.GetHPGLPenDiameter() * IU_PER_MILS );
571  m_HPGLPenSizeOpt->SetValue( msg );
572  msg.Printf( _( "HPGL pen size constrained." ) );
573  reporter.Report( msg, REPORTER::RPT_INFO );
574  }
575 
576  // Default linewidth
577  msg = m_linesWidth->GetValue();
578  tmp = ValueFromString( g_UserUnit, msg );
579 
580  if( !tempOptions.SetLineWidth( tmp ) )
581  {
582  msg = StringFromValue( g_UserUnit, tempOptions.GetLineWidth() );
583  m_linesWidth->SetValue( msg );
584  msg.Printf( _( "Default line width constrained." ) );
585  reporter.Report( msg, REPORTER::RPT_INFO );
586  }
587 
588  // X scale
589  double tmpDouble;
590  msg = m_fineAdjustXscaleOpt->GetValue();
591  msg.ToDouble( &tmpDouble );
592 
593  if( !setDouble( &m_XScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
594  {
595  msg.Printf( wxT( "%f" ), m_XScaleAdjust );
596  m_fineAdjustXscaleOpt->SetValue( msg );
597  msg.Printf( _( "X scale constrained." ) );
598  reporter.Report( msg, REPORTER::RPT_INFO );
599  }
600 
602 
603  // Y scale
604  msg = m_fineAdjustYscaleOpt->GetValue();
605  msg.ToDouble( &tmpDouble );
606 
607  if( !setDouble( &m_YScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
608  {
609  msg.Printf( wxT( "%f" ), m_YScaleAdjust );
610  m_fineAdjustYscaleOpt->SetValue( msg );
611  msg.Printf( _( "Y scale constrained." ) );
612  reporter.Report( msg, REPORTER::RPT_INFO );
613  }
614 
616 
617  // PS Width correction
618  msg = m_PSFineAdjustWidthOpt->GetValue();
619  int itmp = ValueFromString( g_UserUnit, msg );
620 
622  {
624  m_PSFineAdjustWidthOpt->SetValue( msg );
625  msg.Printf( _( "Width correction constrained. "
626  "The reasonable width correction value must be in a range of "
627  " [%+f; %+f] (%s) for current design rules. " ),
630  ( g_UserUnit == INCHES ) ? wxT( "\"" ) : wxT( "mm" ) );
631  reporter.Report( msg, REPORTER::RPT_WARNING );
632  }
633 
634  // Store m_PSWidthAdjust in mm in user config
636  (double)m_PSWidthAdjust / IU_PER_MM );
637 
638  tempOptions.SetFormat( getPlotFormat() );
639 
640  tempOptions.SetUseGerberProtelExtensions( m_useGerberExtensions->GetValue() );
641  tempOptions.SetUseGerberAttributes( m_useGerberX2Attributes->GetValue() );
642  tempOptions.SetIncludeGerberNetlistInfo( m_useGerberNetAttributes->GetValue() );
643  tempOptions.SetGerberPrecision( m_rbGerberFormat->GetSelection() == 0 ? 5 : 6 );
644 
645  LSET selectedLayers;
646  for( unsigned i = 0; i < m_layerList.size(); i++ )
647  {
648  if( m_layerCheckListBox->IsChecked( i ) )
649  selectedLayers.set( m_layerList[i] );
650  }
651  // Get a list of copper layers that aren't being used by inverting enabled layers.
652  LSET disabledCopperLayers = LSET::AllCuMask() & ~m_board->GetEnabledLayers();
653  // Enable all of the disabled copper layers.
654  // If someone enables more copper layers they will be selected by default.
655  selectedLayers = selectedLayers | disabledCopperLayers;
656  tempOptions.SetLayerSelection( selectedLayers );
657 
658  tempOptions.SetNegative( m_plotPSNegativeOpt->GetValue() );
659  tempOptions.SetA4Output( m_forcePSA4OutputOpt->GetValue() );
660 
661  // Set output directory and replace backslashes with forward ones
662  wxString dirStr;
663  dirStr = m_outputDirectoryName->GetValue();
664  dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
665  tempOptions.SetOutputDirectory( dirStr );
666 
667  if( m_plotOpts != tempOptions )
668  {
669  m_parent->SetPlotSettings( tempOptions );
670  m_plotOpts = tempOptions;
671  m_parent->OnModify();
672  }
673 }
674 
675 
676 void DIALOG_PLOT::OnGerberX2Checked( wxCommandEvent& event )
677 {
678  // m_useGerberNetAttributes is useless if m_useGerberX2Attributes
679  // is not checked. So disabled (greyed out) when Gerber X2 gets unchecked
680  // to make it clear to the user.
681  if( m_useGerberX2Attributes->GetValue() )
682  {
683  m_useGerberNetAttributes->Enable( true );
684  }
685  else
686  {
687  m_useGerberNetAttributes->Enable( false );
688  m_useGerberNetAttributes->SetValue( false );
689  }
690 }
691 
692 
693 void DIALOG_PLOT::Plot( wxCommandEvent& event )
694 {
696 
697  // Create output directory if it does not exist (also transform it in
698  // absolute form). Bail if it fails
699  wxFileName outputDir = wxFileName::DirName( m_plotOpts.GetOutputDirectory() );
700  wxString boardFilename = m_parent->GetBoard()->GetFileName();
701  REPORTER& reporter = m_messagesPanel->Reporter();
702 
703  if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
704  {
705  wxString msg;
706  msg.Printf( _( "Could not write plot files to folder \"%s\"." ),
707  GetChars( outputDir.GetPath() ) );
708  DisplayError( this, msg );
709  return;
710  }
711 
712  m_plotOpts.SetAutoScale( false );
713  m_plotOpts.SetScale( 1 );
714 
715  switch( m_plotOpts.GetScaleSelection() )
716  {
717  default:
718  break;
719 
720  case 0: // Autoscale option
721  m_plotOpts.SetAutoScale( true );
722  break;
723 
724  case 2: // 3:2 option
725  m_plotOpts.SetScale( 1.5 );
726  break;
727 
728  case 3: // 2:1 option
729  m_plotOpts.SetScale( 2 );
730  break;
731 
732  case 4: // 3:1 option
733  m_plotOpts.SetScale( 3 );
734  break;
735  }
736 
737  /* If the scale factor edit controls are disabled or the scale value
738  * is 0, don't adjust the base scale factor. This fixes a bug when
739  * the default scale adjust is initialized to 0 and saved in program
740  * settings resulting in a divide by zero fault.
741  */
742  if( m_fineAdjustXscaleOpt->IsEnabled() && m_XScaleAdjust != 0.0 )
744 
745  if( m_fineAdjustYscaleOpt->IsEnabled() && m_YScaleAdjust != 0.0 )
747 
748  if( m_PSFineAdjustWidthOpt->IsEnabled() )
750 
751  wxString file_ext( GetDefaultPlotExtension( m_plotOpts.GetFormat() ) );
752 
753  // Test for a reasonable scale value
754  // XXX could this actually happen? isn't it constrained in the apply
755  // function?
757  DisplayInfoMessage( this,
758  _( "Warning: Scale option set to a very small value" ) );
759 
761  DisplayInfoMessage( this,
762  _( "Warning: Scale option set to a very large value" ) );
763 
764  // Save the current plot options in the board
766 
767  wxBusyCursor dummy;
768 
769  for( LSEQ seq = m_plotOpts.GetLayerSelection().UIOrder(); seq; ++seq )
770  {
771  LAYER_ID layer = *seq;
772 
773  // All copper layers that are disabled are actually selected
774  // This is due to wonkyness in automatically selecting copper layers
775  // for plotting when adding more than two layers to a board.
776  // If plot options become accessible to the layers setup dialog
777  // please move this functionality there!
778  // This skips a copper layer if it is actually disabled on the board.
779  if( ( LSET::AllCuMask() & ~m_board->GetEnabledLayers() )[layer] )
780  continue;
781 
782  // Pick the basename from the board file
783  wxFileName fn( boardFilename );
784 
785  // Use Gerber Extensions based on layer number
786  // (See http://en.wikipedia.org/wiki/Gerber_File)
788  file_ext = GetGerberProtelExtension( layer );
789 
790  BuildPlotFileName( &fn, outputDir.GetPath(),
791  m_board->GetLayerName( layer ),
792  file_ext );
793 
794  LOCALE_IO toggle;
795 
796  BOARD* board = m_parent->GetBoard();
797  PLOTTER* plotter = StartPlotBoard( board, &m_plotOpts, layer, fn.GetFullPath(), wxEmptyString );
798 
799  // Print diags in messages box:
800  wxString msg;
801 
802  if( plotter )
803  {
804  PlotOneBoardLayer( board, plotter, layer, m_plotOpts );
805  plotter->EndPlot();
806  delete plotter;
807 
808  msg.Printf( _( "Plot file '%s' created." ), GetChars( fn.GetFullPath() ) );
809  reporter.Report( msg, REPORTER::RPT_ACTION );
810  }
811  else
812  {
813  msg.Printf( _( "Unable to create file '%s'." ), GetChars( fn.GetFullPath() ) );
814  reporter.Report( msg, REPORTER::RPT_ERROR );
815  }
816  }
817 
818  // If no layer selected, we have nothing plotted.
819  // Prompt user if it happens because he could think there is a bug in Pcbnew.
820  if( !m_plotOpts.GetLayerSelection().any() )
821  DisplayError( this, _( "No layer selected" ) );
822 }
823 
824 #include <drc_stuff.h>
825 void DIALOG_PLOT::onRunDRC( wxCommandEvent& event )
826 {
827  PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
828 
829  if( parent )
830  {
831  // First close an existing dialog if open
832  // (low probability, but can happen)
833  parent->GetDrcController()->DestroyDRCDialog( wxID_OK );
834 
835  // Open a new drc dialod, with the right parent frame, and in Modal Mode
836  parent->GetDrcController()->ShowDRCDialog( this );
837  }
838 }
839 
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu LAYER_IDs.
Definition: lset.cpp:638
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.
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.
Definition: pcbframe.cpp:1004
bool GetSubtractMaskFromSilk() const
wxTextCtrl * m_fineAdjustYscaleOpt
int GetHPGLPenDiameter() const
wxCheckBox * m_useGerberExtensions
void DestroyDRCDialog(int aReason)
Function DestroyDRCDialog deletes this ui dialog box and zeros out its pointer to remember the state ...
Definition: drc.cpp:97
double GetScale() const
void SetGerberPrecision(int aPrecision)
void OnOutputDirectoryBrowseClicked(wxCommandEvent &event) override
void SetPlotViaOnMaskLayer(bool aFlag)
wxCheckBox * m_plotPads_on_Silkscreen
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.
PlotFormat
Enum PlotFormat is the set of supported output plot formats.
Definition: plot_common.h:49
int GetSmallestClearanceValue()
Function GetSmallestClearanceValue.
bool GetUseGerberAttributes() const
wxStaticText * m_textPenSize
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:203
void SetFormat(PlotFormat aFormat)
PlotFormat getPlotFormat()
wxString GetDefaultPlotExtension(PlotFormat aFormat)
Returns the default plot extension for a format.
wxCheckBox * m_excludeEdgeLayerOpt
virtual void onRunDRC(wxCommandEvent &event) override
void SetMirror(bool aFlag)
const wxString GetGerberProtelExtension(LAYER_NUM aLayer)
Function GetGerberProtelExtension.
Definition: pcbplot.cpp:48
BOARD * m_board
Definition: dialog_plot.h:43
BOARD * GetBoard() const
wxCheckBox * m_plotMirrorOpt
void PlotOneBoardLayer(BOARD *aBoard, PLOTTER *aPlotter, LAYER_ID aLayer, const PCB_PLOT_PARAMS &aPlotOpt)
Function PlotOneBoardLayer main function to plot one copper or technical layer.
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:708
const wxString GetLayerName(LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
void CreateDrillFile(wxCommandEvent &event) override
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
bool GetPlotValue() const
wxCheckBox * m_useGerberX2Attributes
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)
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.
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.
bool GetIncludeGerberNetlistInfo() const
Class LSET is a set of 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:237
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
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's directory to be an absolu...
Definition: project.cpp:371
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:368
wxCheckBox * m_forcePSA4OutputOpt
void OnPopUpLayers(wxCommandEvent &event) override
void SetSubtractMaskFromSilk(bool aSubtract)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
#define CONFIG_PS_FINEWIDTH_ADJ
Definition: pcbplot.h:63
void setPlotModeChoiceSelection(EDA_DRAW_MODE_T aPlotMode)
Definition: dialog_plot.h:78
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:101
bool GetPlotViaOnMaskLayer() const
int GetScaleSelection() const
virtual void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings)
void OnSetScaleOpt(wxCommandEvent &event) override
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
wxStaticBoxSizer * m_GerberOptionsSizer
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)
Class PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board...
wxTextCtrl * m_outputDirectoryName
void SetPlotInvisibleText(bool aFlag)
void SetScale(double aVal)
Class LSEQ is a sequence (and therefore also a set) of LAYER_IDs.
PCB_PLOT_PARAMS m_plotOpts
Definition: dialog_plot.h:58
void SetNegative(bool aFlag)
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:355
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: plot_common.h:86
wxCheckBox * m_subtractMaskFromSilk
void DisplayInfoMessage(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:89
wxCheckBox * m_plotNoViaOnMaskOpt
wxCheckBox * m_plotModuleValueOpt
void ShowDRCDialog(wxWindow *aParent=NULL)
Function ShowDRCDialog opens a dialog and prompts the user, then if a test run button is clicked...
Definition: drc.cpp:56
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:509
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:166
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
bool GetNegative() const
static bool setInt(int *aResult, int aValue, int aMin, int aMax)
bool GetPlotFrameRef() const
void Init_Dialog()
Definition: dialog_plot.cpp:59
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:90
void OnRightClick(wxMouseEvent &event) override
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()
Definition: wxPcbStruct.h:910
wxStaticBoxSizer * m_PSOptionsSizer
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:69
wxBoxSizer * m_PlotOptionsSizer
void InstallDrillFrame(wxCommandEvent &event)
DIALOG_PLOT(PCB_EDIT_FRAME *parent)
Definition: dialog_plot.cpp:46
int m_SolderMaskMinWidth
Solder mask min width.
LSEQ UIOrder() const
Definition: lset.cpp:751
int GetGerberPrecision() const