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 <plot_common.h>
31 #include <confirm.h>
32 #include <wxPcbStruct.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 
40 #include <class_board.h>
41 #include <wx/ffile.h>
42 #include <dialog_plot.h>
43 #include <wx_html_report_panel.h>
44 
46  DIALOG_PLOT_BASE( aParent ), m_parent( aParent ),
47  m_board( aParent->GetBoard() )
48 {
50  m_plotOpts = aParent->GetPlotSettings();
51  init_Dialog();
52 
53  GetSizer()->Fit( this );
54  GetSizer()->SetSizeHints( this );
55 }
56 
57 
59 {
60  wxString msg;
61  wxFileName fileName;
62 
65 
66  // m_PSWidthAdjust is stored in mm in user config
67  double dtmp;
68  m_config->Read( CONFIG_PS_FINEWIDTH_ADJ, &dtmp, 0 );
69  m_PSWidthAdjust = KiROUND( dtmp * IU_PER_MM );
70 
71  // The reasonable width correction value must be in a range of
72  // [-(MinTrackWidth-1), +(MinClearanceValue-1)] decimils.
75 
76  switch( m_plotOpts.GetFormat() )
77  {
78  default:
79  case PLOT_FORMAT_GERBER:
80  m_plotFormatOpt->SetSelection( 0 );
81  break;
82 
83  case PLOT_FORMAT_POST:
84  m_plotFormatOpt->SetSelection( 1 );
85  break;
86 
87  case PLOT_FORMAT_SVG:
88  m_plotFormatOpt->SetSelection( 2 );
89  break;
90 
91  case PLOT_FORMAT_DXF:
92  m_plotFormatOpt->SetSelection( 3 );
93  break;
94 
95  case PLOT_FORMAT_HPGL:
96  m_plotFormatOpt->SetSelection( 4 );
97  break;
98 
99  case PLOT_FORMAT_PDF:
100  m_plotFormatOpt->SetSelection( 5 );
101  break;
102  }
103 
105  m_SolderMaskMarginCurrValue->SetLabel( msg );
107  m_SolderMaskMinWidthCurrValue->SetLabel( msg );
108 
109  // Set units and value for HPGL pen size (this param in in mils).
112  m_plotOpts.GetHPGLPenDiameter() * IU_PER_MILS );
113  m_HPGLPenSizeOpt->AppendText( msg );
114 
117  m_linesWidth->AppendText( msg );
118 
119  // Set units for PS global width correction.
121 
122  // Test for a reasonable scale value. Set to 1 if problem
126 
127  msg.Printf( wxT( "%f" ), m_XScaleAdjust );
128  m_fineAdjustXscaleOpt->AppendText( msg );
129 
130  msg.Printf( wxT( "%f" ), m_YScaleAdjust );
131  m_fineAdjustYscaleOpt->AppendText( msg );
132 
133  // Test for a reasonable PS width correction value. Set to 0 if problem.
134  if( m_PSWidthAdjust < m_widthAdjustMinValue || m_PSWidthAdjust > m_widthAdjustMaxValue )
135  m_PSWidthAdjust = 0.;
136 
137  msg.Printf( wxT( "%f" ), To_User_Unit( g_UserUnit, m_PSWidthAdjust ) );
138  m_PSFineAdjustWidthOpt->AppendText( msg );
139 
142 
143  // Could devote a PlotOrder() function in place of UIOrder().
145 
146  // Populate the check list box by all enabled layers names
147  for( LSEQ seq = m_layerList; seq; ++seq )
148  {
149  PCB_LAYER_ID layer = *seq;
150 
151  int checkIndex = m_layerCheckListBox->Append( m_board->GetLayerName( layer ) );
152 
153  if( m_plotOpts.GetLayerSelection()[layer] )
154  m_layerCheckListBox->Check( checkIndex );
155  }
156 
157  // Option for using proper Gerber extensions
159 
160  // Option for including Gerber attributes (from Gerber X2 format) in the output
162 
163  // Option for including Gerber netlist info (from Gerber X2 format) in the output
165 
166  // Grey out if m_useGerberX2Attributes is not checked
167  m_useGerberNetAttributes->Enable( m_useGerberX2Attributes->GetValue() );
168 
169  // Option to generate a Gerber job file
171 
172  // Gerber precision for coordinates
173  m_rbGerberFormat->SetSelection( m_plotOpts.GetGerberPrecision() == 5 ? 0 : 1 );
174 
175  // Option for excluding contents of "Edges Pcb" layer
177 
179 
180  // Option to plot page references:
182 
183  // Option to allow pads on silkscreen layers
185 
186  // Options to plot texts on footprints
190 
191  // Options to plot pads and vias holes
192  m_drillShapeOpt->SetSelection( m_plotOpts.GetDrillMarksType() );
193 
194  // Scale option
195  m_scaleOpt->SetSelection( m_plotOpts.GetScaleSelection() );
196 
197  // Plot mode
199 
200  // Plot outline mode
202 
203  // Plot text mode
205 
206  // Plot mirror option
207  m_plotMirrorOpt->SetValue( m_plotOpts.GetMirror() );
208 
209  // Put vias on mask layer
211 
212  // Initialize a few other parameters, which can also be modified
213  // from the drill dialog
214  reInitDialog();
215 
216  // Update options values:
217  wxCommandEvent cmd_event;
218  SetPlotFormat( cmd_event );
219  OnSetScaleOpt( cmd_event );
220 }
221 
222 
224 {
225  // after calling drill dialog, some parameters can be modified.
226  // update them
227 
228  // Output directory
230 
231  // Origin of coordinates:
233 }
234 
235 void DIALOG_PLOT::OnQuit( wxCommandEvent& event )
236 {
237  Close( true ); // true is to force the frame to close
238 }
239 
240 
241 void DIALOG_PLOT::OnClose( wxCloseEvent& event )
242 {
244  EndModal( 0 );
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:
257 void DIALOG_PLOT::OnPopUpLayers( wxCommandEvent& event )
258 {
259  unsigned int i;
260 
261  switch( event.GetId() )
262  {
263  case ID_LAYER_FAB: // Select layers usually needed to build a board
264  for( i = 0; i < m_layerList.size(); i++ )
265  {
266  LSET layermask( m_layerList[ i ] );
267 
268  if( ( layermask & ( LSET::AllCuMask() | LSET::AllTechMask() ) ).any() )
269  m_layerCheckListBox->Check( i, true );
270  else
271  m_layerCheckListBox->Check( i, false );
272  }
273  break;
274 
276  for( i = 0; i < m_layerList.size(); i++ )
277  {
278  if( IsCopperLayer( m_layerList[i] ) )
279  m_layerCheckListBox->Check( i, true );
280  }
281  break;
282 
284  for( i = 0; i < m_layerList.size(); i++ )
285  {
286  if( IsCopperLayer( m_layerList[i] ) )
287  m_layerCheckListBox->Check( i, false );
288  }
289  break;
290 
292  for( i = 0; i < m_layerList.size(); i++ )
293  m_layerCheckListBox->Check( i, true );
294  break;
295 
297  for( i = 0; i < m_layerList.size(); i++ )
298  m_layerCheckListBox->Check( i, false );
299  break;
300 
301  default:
302  break;
303  }
304 }
305 
306 
307 void DIALOG_PLOT::CreateDrillFile( wxCommandEvent& event )
308 {
309  // Be sure drill file use the same settings (axis option, plot directory)
310  // than plot files:
312  m_parent->InstallDrillFrame( event );
313 
314  // a few plot settings can be modified: take them in account
316  reInitDialog();
317 }
318 
319 
320 void DIALOG_PLOT::OnChangeDXFPlotMode( wxCommandEvent& event )
321 {
322  // m_DXF_plotTextStrokeFontOpt is disabled if m_DXF_plotModeOpt
323  // is checked (plot in DXF polygon mode)
324  m_DXF_plotTextStrokeFontOpt->Enable( !m_DXF_plotModeOpt->GetValue() );
325 
326  // if m_DXF_plotTextStrokeFontOpt option is disabled (plot DXF in polygon mode),
327  // force m_DXF_plotTextStrokeFontOpt to true to use Pcbnew stroke font
328  if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() )
329  m_DXF_plotTextStrokeFontOpt->SetValue( true );
330 }
331 
332 
333 void DIALOG_PLOT::OnSetScaleOpt( wxCommandEvent& event )
334 {
335  /* Disable sheet reference for scale != 1:1 */
336  bool scale1 = ( m_scaleOpt->GetSelection() == 1 );
337 
338  m_plotSheetRef->Enable( scale1 );
339 
340  if( !scale1 )
341  m_plotSheetRef->SetValue( false );
342 }
343 
344 
345 void DIALOG_PLOT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
346 {
347  // Build the absolute path of current output plot directory
348  // to preselect it when opening the dialog.
349  wxFileName fn( m_outputDirectoryName->GetValue() );
350  wxString path = Prj().AbsolutePath( m_outputDirectoryName->GetValue() );
351 
352  wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
353 
354  if( dirDialog.ShowModal() == wxID_CANCEL )
355  return;
356 
357  wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
358 
359  fn = Prj().AbsolutePath( m_parent->GetBoard()->GetFileName() );
360  wxString defaultPath = fn.GetPathWithSep();
361  wxString msg;
362  msg.Printf( _( "Do you want to use a path relative to\n'%s'" ),
363  GetChars( defaultPath ) );
364 
365  wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
366  wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
367 
368  if( dialog.ShowModal() == wxID_YES )
369  {
370  if( !dirName.MakeRelativeTo( defaultPath ) )
371  wxMessageBox( _( "Cannot make path relative (target volume different from file volume)!" ),
372  _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
373  }
374 
375  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
376 }
377 
378 
380 {
381  // plot format id's are ordered like displayed in m_plotFormatOpt
382  static const PlotFormat plotFmt[] =
383  {
390  };
391 
392  return plotFmt[ m_plotFormatOpt->GetSelection() ];
393 }
394 
395 
396 // Enable or disable widgets according to the plot format selected
397 // and clear also some optional values
398 void DIALOG_PLOT::SetPlotFormat( wxCommandEvent& event )
399 {
400  // this option exist only in DXF format:
402 
403  switch( getPlotFormat() )
404  {
405  case PLOT_FORMAT_PDF:
406  case PLOT_FORMAT_SVG:
407  m_drillShapeOpt->Enable( true );
408  m_plotModeOpt->Enable( false );
410  m_plotMirrorOpt->Enable( true );
411  m_useAuxOriginCheckBox->Enable( false );
412  m_useAuxOriginCheckBox->SetValue( false );
413  m_linesWidth->Enable( true );
414  m_HPGLPenSizeOpt->Enable( false );
415  m_excludeEdgeLayerOpt->Enable( true );
416  m_scaleOpt->Enable( false );
417  m_scaleOpt->SetSelection( 1 );
418  m_fineAdjustXscaleOpt->Enable( false );
419  m_fineAdjustYscaleOpt->Enable( false );
420  m_PSFineAdjustWidthOpt->Enable( false );
421  m_plotPSNegativeOpt->Enable( true );
422  m_forcePSA4OutputOpt->Enable( false );
423  m_forcePSA4OutputOpt->SetValue( false );
424 
429  break;
430 
431  case PLOT_FORMAT_POST:
432  m_drillShapeOpt->Enable( true );
433  m_plotModeOpt->Enable( true );
434  m_plotMirrorOpt->Enable( true );
435  m_useAuxOriginCheckBox->Enable( false );
436  m_useAuxOriginCheckBox->SetValue( false );
437  m_linesWidth->Enable( true );
438  m_HPGLPenSizeOpt->Enable( false );
439  m_excludeEdgeLayerOpt->Enable( true );
440  m_scaleOpt->Enable( true );
441  m_fineAdjustXscaleOpt->Enable( true );
442  m_fineAdjustYscaleOpt->Enable( true );
443  m_PSFineAdjustWidthOpt->Enable( true );
444  m_plotPSNegativeOpt->Enable( true );
445  m_forcePSA4OutputOpt->Enable( true );
446 
451  break;
452 
453  case PLOT_FORMAT_GERBER:
454  m_drillShapeOpt->Enable( false );
455  m_drillShapeOpt->SetSelection( 0 );
456  m_plotModeOpt->Enable( false );
458  m_plotMirrorOpt->Enable( false );
459  m_plotMirrorOpt->SetValue( false );
460  m_useAuxOriginCheckBox->Enable( true );
461  m_linesWidth->Enable( true );
462  m_HPGLPenSizeOpt->Enable( false );
463  m_excludeEdgeLayerOpt->Enable( true );
464  m_scaleOpt->Enable( false );
465  m_scaleOpt->SetSelection( 1 );
466  m_fineAdjustXscaleOpt->Enable( false );
467  m_fineAdjustYscaleOpt->Enable( false );
468  m_PSFineAdjustWidthOpt->Enable( false );
469  m_plotPSNegativeOpt->Enable( false );
470  m_plotPSNegativeOpt->SetValue( false );
471  m_forcePSA4OutputOpt->Enable( false );
472  m_forcePSA4OutputOpt->SetValue( false );
473 
478  break;
479 
480  case PLOT_FORMAT_HPGL:
481  m_drillShapeOpt->Enable( true );
482  m_plotModeOpt->Enable( true );
483  m_plotMirrorOpt->Enable( true );
484  m_useAuxOriginCheckBox->Enable( false );
485  m_useAuxOriginCheckBox->SetValue( false );
486  m_linesWidth->Enable( false );
487  m_HPGLPenSizeOpt->Enable( true );
488  m_excludeEdgeLayerOpt->Enable( true );
489  m_scaleOpt->Enable( true );
490  m_fineAdjustXscaleOpt->Enable( false );
491  m_fineAdjustYscaleOpt->Enable( false );
492  m_PSFineAdjustWidthOpt->Enable( false );
493  m_plotPSNegativeOpt->SetValue( false );
494  m_plotPSNegativeOpt->Enable( false );
495  m_forcePSA4OutputOpt->Enable( true );
496 
501  break;
502 
503  case PLOT_FORMAT_DXF:
504  m_drillShapeOpt->Enable( true );
505  m_plotModeOpt->Enable( false );
507  m_plotMirrorOpt->Enable( false );
508  m_plotMirrorOpt->SetValue( false );
509  m_useAuxOriginCheckBox->Enable( true );
510  m_linesWidth->Enable( false );
511  m_HPGLPenSizeOpt->Enable( false );
512  m_excludeEdgeLayerOpt->Enable( true );
513  m_scaleOpt->Enable( false );
514  m_scaleOpt->SetSelection( 1 );
515  m_fineAdjustXscaleOpt->Enable( false );
516  m_fineAdjustYscaleOpt->Enable( false );
517  m_PSFineAdjustWidthOpt->Enable( false );
518  m_plotPSNegativeOpt->Enable( false );
519  m_plotPSNegativeOpt->SetValue( false );
520  m_forcePSA4OutputOpt->Enable( false );
521  m_forcePSA4OutputOpt->SetValue( false );
522 
527 
528  OnChangeDXFPlotMode( event );
529  break;
530  }
531 
532  /* Update the interlock between scale and frame reference
533  * (scaling would mess up the frame border...) */
534  OnSetScaleOpt( event );
535 
536  Layout();
537  m_MainSizer->SetSizeHints( this );
538 }
539 
540 
541 // A helper function to "clip" aValue between aMin and aMax
542 // and write result in * aResult
543 // return false if clipped, true if aValue is just copied into * aResult
544 static bool setDouble( double* aResult, double aValue, double aMin, double aMax )
545 {
546  if( aValue < aMin )
547  {
548  *aResult = aMin;
549  return false;
550  }
551  else if( aValue > aMax )
552  {
553  *aResult = aMax;
554  return false;
555  }
556 
557  *aResult = aValue;
558  return true;
559 }
560 
561 
562 static bool setInt( int* aResult, int aValue, int aMin, int aMax )
563 {
564  if( aValue < aMin )
565  {
566  *aResult = aMin;
567  return false;
568  }
569  else if( aValue > aMax )
570  {
571  *aResult = aMax;
572  return false;
573  }
574 
575  *aResult = aValue;
576  return true;
577 }
578 
579 
581 {
582  REPORTER& reporter = m_messagesPanel->Reporter();
583 
584  PCB_PLOT_PARAMS tempOptions;
585 
586  tempOptions.SetExcludeEdgeLayer( m_excludeEdgeLayerOpt->GetValue() );
587  tempOptions.SetSubtractMaskFromSilk( m_subtractMaskFromSilk->GetValue() );
588  tempOptions.SetPlotFrameRef( m_plotSheetRef->GetValue() );
589  tempOptions.SetPlotPadsOnSilkLayer( m_plotPads_on_Silkscreen->GetValue() );
590  tempOptions.SetUseAuxOrigin( m_useAuxOriginCheckBox->GetValue() );
591  tempOptions.SetPlotValue( m_plotModuleValueOpt->GetValue() );
592  tempOptions.SetPlotReference( m_plotModuleRefOpt->GetValue() );
593  tempOptions.SetPlotInvisibleText( m_plotInvisibleText->GetValue() );
594  tempOptions.SetScaleSelection( m_scaleOpt->GetSelection() );
595  tempOptions.SetDrillMarksType( static_cast<PCB_PLOT_PARAMS::DrillMarksType>
596  ( m_drillShapeOpt->GetSelection() ) );
597  tempOptions.SetMirror( m_plotMirrorOpt->GetValue() );
598  tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED );
599  tempOptions.SetDXFPlotPolygonMode( m_DXF_plotModeOpt->GetValue() );
600  tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() );
601 
602  if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() ) // Currently, only DXF supports this option
603  tempOptions.SetTextMode( PLOTTEXTMODE_DEFAULT );
604  else
605  tempOptions.SetTextMode( m_DXF_plotTextStrokeFontOpt->GetValue() ?
607 
608  // Update settings from text fields. Rewrite values back to the fields,
609  // since the values may have been constrained by the setters.
610 
611  // read HPLG pen size (this param is stored in mils)
612  wxString msg = m_HPGLPenSizeOpt->GetValue();
613  int tmp = ValueFromString( g_UserUnit, msg ) / IU_PER_MILS;
614 
615  if( !tempOptions.SetHPGLPenDiameter( tmp ) )
616  {
617  msg = StringFromValue( g_UserUnit, tempOptions.GetHPGLPenDiameter() * IU_PER_MILS );
618  m_HPGLPenSizeOpt->SetValue( msg );
619  msg.Printf( _( "HPGL pen size constrained." ) );
620  reporter.Report( msg, REPORTER::RPT_INFO );
621  }
622 
623  // Default linewidth
624  msg = m_linesWidth->GetValue();
625  tmp = ValueFromString( g_UserUnit, msg );
626 
627  if( !tempOptions.SetLineWidth( tmp ) )
628  {
629  msg = StringFromValue( g_UserUnit, tempOptions.GetLineWidth() );
630  m_linesWidth->SetValue( msg );
631  msg.Printf( _( "Default line width constrained." ) );
632  reporter.Report( msg, REPORTER::RPT_INFO );
633  }
634 
635  // X scale
636  double tmpDouble;
637  msg = m_fineAdjustXscaleOpt->GetValue();
638  msg.ToDouble( &tmpDouble );
639 
640  if( !setDouble( &m_XScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
641  {
642  msg.Printf( wxT( "%f" ), m_XScaleAdjust );
643  m_fineAdjustXscaleOpt->SetValue( msg );
644  msg.Printf( _( "X scale constrained." ) );
645  reporter.Report( msg, REPORTER::RPT_INFO );
646  }
647 
649 
650  // Y scale
651  msg = m_fineAdjustYscaleOpt->GetValue();
652  msg.ToDouble( &tmpDouble );
653 
654  if( !setDouble( &m_YScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
655  {
656  msg.Printf( wxT( "%f" ), m_YScaleAdjust );
657  m_fineAdjustYscaleOpt->SetValue( msg );
658  msg.Printf( _( "Y scale constrained." ) );
659  reporter.Report( msg, REPORTER::RPT_INFO );
660  }
661 
663 
664  // PS Width correction
665  msg = m_PSFineAdjustWidthOpt->GetValue();
666  int itmp = ValueFromString( g_UserUnit, msg );
667 
669  {
671  m_PSFineAdjustWidthOpt->SetValue( msg );
672  msg.Printf( _( "Width correction constrained. "
673  "The reasonable width correction value must be in a range of "
674  " [%+f; %+f] (%s) for current design rules. " ),
677  ( g_UserUnit == INCHES ) ? wxT( "\"" ) : wxT( "mm" ) );
678  reporter.Report( msg, REPORTER::RPT_WARNING );
679  }
680 
681  // Store m_PSWidthAdjust in mm in user config
683  (double)m_PSWidthAdjust / IU_PER_MM );
684 
685  tempOptions.SetFormat( getPlotFormat() );
686 
687  tempOptions.SetUseGerberProtelExtensions( m_useGerberExtensions->GetValue() );
688  tempOptions.SetUseGerberAttributes( m_useGerberX2Attributes->GetValue() );
689  tempOptions.SetIncludeGerberNetlistInfo( m_useGerberNetAttributes->GetValue() );
690  tempOptions.SetCreateGerberJobFile( m_generateGerberJobFile->GetValue() );
691 
692  tempOptions.SetGerberPrecision( m_rbGerberFormat->GetSelection() == 0 ? 5 : 6 );
693 
694  LSET selectedLayers;
695  for( unsigned i = 0; i < m_layerList.size(); i++ )
696  {
697  if( m_layerCheckListBox->IsChecked( i ) )
698  selectedLayers.set( m_layerList[i] );
699  }
700  // Get a list of copper layers that aren't being used by inverting enabled layers.
701  LSET disabledCopperLayers = LSET::AllCuMask() & ~m_board->GetEnabledLayers();
702  // Enable all of the disabled copper layers.
703  // If someone enables more copper layers they will be selected by default.
704  selectedLayers = selectedLayers | disabledCopperLayers;
705  tempOptions.SetLayerSelection( selectedLayers );
706 
707  tempOptions.SetNegative( m_plotPSNegativeOpt->GetValue() );
708  tempOptions.SetA4Output( m_forcePSA4OutputOpt->GetValue() );
709 
710  // Set output directory and replace backslashes with forward ones
711  wxString dirStr;
712  dirStr = m_outputDirectoryName->GetValue();
713  dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
714  tempOptions.SetOutputDirectory( dirStr );
715 
716  if( !m_plotOpts.IsSameAs( tempOptions, false ) )
717  {
718  // First, mark board as modified only for parameters saved in file
719  if( !m_plotOpts.IsSameAs( tempOptions, true ) )
720  m_parent->OnModify();
721 
722  // Now, save any change, for the session
723  m_parent->SetPlotSettings( tempOptions );
724  m_plotOpts = tempOptions;
725  }
726 }
727 
728 
729 void DIALOG_PLOT::OnGerberX2Checked( wxCommandEvent& event )
730 {
731  // m_useGerberNetAttributes is useless if m_useGerberX2Attributes
732  // is not checked. So disabled (greyed out) when Gerber X2 gets unchecked
733  // to make it clear to the user.
734  if( m_useGerberX2Attributes->GetValue() )
735  {
736  m_useGerberNetAttributes->Enable( true );
737  }
738  else
739  {
740  m_useGerberNetAttributes->Enable( false );
741  m_useGerberNetAttributes->SetValue( false );
742  }
743 }
744 
745 
746 void DIALOG_PLOT::Plot( wxCommandEvent& event )
747 {
749 
750  // If no layer selected, we have nothing plotted.
751  // Prompt user if it happens because he could think there is a bug in Pcbnew.
752  if( !m_plotOpts.GetLayerSelection().any() )
753  {
754  DisplayError( this, _( "No layer selected, Nothing to plot" ) );
755  return;
756  }
757 
758  // Create output directory if it does not exist (also transform it in
759  // absolute form). Bail if it fails
760  wxFileName outputDir = wxFileName::DirName( m_plotOpts.GetOutputDirectory() );
761  wxString boardFilename = m_parent->GetBoard()->GetFileName();
762  REPORTER& reporter = m_messagesPanel->Reporter();
763 
764  if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
765  {
766  wxString msg;
767  msg.Printf( _( "Could not write plot files to folder \"%s\"." ),
768  GetChars( outputDir.GetPath() ) );
769  DisplayError( this, msg );
770  return;
771  }
772 
773  m_plotOpts.SetAutoScale( false );
774  m_plotOpts.SetScale( 1 );
775 
776  switch( m_plotOpts.GetScaleSelection() )
777  {
778  default:
779  break;
780 
781  case 0: // Autoscale option
782  m_plotOpts.SetAutoScale( true );
783  break;
784 
785  case 2: // 3:2 option
786  m_plotOpts.SetScale( 1.5 );
787  break;
788 
789  case 3: // 2:1 option
790  m_plotOpts.SetScale( 2 );
791  break;
792 
793  case 4: // 3:1 option
794  m_plotOpts.SetScale( 3 );
795  break;
796  }
797 
798  /* If the scale factor edit controls are disabled or the scale value
799  * is 0, don't adjust the base scale factor. This fixes a bug when
800  * the default scale adjust is initialized to 0 and saved in program
801  * settings resulting in a divide by zero fault.
802  */
803  if( m_fineAdjustXscaleOpt->IsEnabled() && m_XScaleAdjust != 0.0 )
805 
806  if( m_fineAdjustYscaleOpt->IsEnabled() && m_YScaleAdjust != 0.0 )
808 
809  if( m_PSFineAdjustWidthOpt->IsEnabled() )
811 
812  wxString file_ext( GetDefaultPlotExtension( m_plotOpts.GetFormat() ) );
813 
814  // Test for a reasonable scale value
815  // XXX could this actually happen? isn't it constrained in the apply
816  // function?
818  DisplayInfoMessage( this,
819  _( "Warning: Scale option set to a very small value" ) );
820 
822  DisplayInfoMessage( this,
823  _( "Warning: Scale option set to a very large value" ) );
824 
825  GERBER_JOBFILE_WRITER jobfile_writer( m_board, &reporter );
826 
827  // Save the current plot options in the board
829 
830  wxBusyCursor dummy;
831 
832  for( LSEQ seq = m_plotOpts.GetLayerSelection().UIOrder(); seq; ++seq )
833  {
834  PCB_LAYER_ID layer = *seq;
835 
836  // All copper layers that are disabled are actually selected
837  // This is due to wonkyness in automatically selecting copper layers
838  // for plotting when adding more than two layers to a board.
839  // If plot options become accessible to the layers setup dialog
840  // please move this functionality there!
841  // This skips a copper layer if it is actually disabled on the board.
842  if( ( LSET::AllCuMask() & ~m_board->GetEnabledLayers() )[layer] )
843  continue;
844 
845  // Pick the basename from the board file
846  wxFileName fn( boardFilename );
847 
848  // Use Gerber Extensions based on layer number
849  // (See http://en.wikipedia.org/wiki/Gerber_File)
851  file_ext = GetGerberProtelExtension( layer );
852 
853  BuildPlotFileName( &fn, outputDir.GetPath(), m_board->GetLayerName( layer ), file_ext );
854  wxString fullname = fn.GetFullName();
855  jobfile_writer.AddGbrFile( layer, fullname );
856 
857  LOCALE_IO toggle;
858 
859  BOARD* board = m_parent->GetBoard();
860  PLOTTER* plotter = StartPlotBoard( board, &m_plotOpts, layer, fn.GetFullPath(), wxEmptyString );
861 
862  // Print diags in messages box:
863  wxString msg;
864 
865  if( plotter )
866  {
867  PlotOneBoardLayer( board, plotter, layer, m_plotOpts );
868  plotter->EndPlot();
869  delete plotter;
870 
871  msg.Printf( _( "Plot file '%s' created." ), GetChars( fn.GetFullPath() ) );
872  reporter.Report( msg, REPORTER::RPT_ACTION );
873  }
874  else
875  {
876  msg.Printf( _( "Unable to create file '%s'." ), GetChars( fn.GetFullPath() ) );
877  reporter.Report( msg, REPORTER::RPT_ERROR );
878  }
879  }
880 
882  {
883  // Pick the basename from the board file
884  wxFileName fn( boardFilename );
885  // Build gerber job file from basename
886  BuildPlotFileName( &fn, outputDir.GetPath(), "job", GerberJobFileExtension );
887  jobfile_writer.CreateJobFile( fn.GetFullPath() );
888  }
889 }
890 
891 #include <drc_stuff.h>
892 void DIALOG_PLOT::onRunDRC( wxCommandEvent& event )
893 {
894  PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
895 
896  if( parent )
897  {
898  // First close an existing dialog if open
899  // (low probability, but can happen)
900  parent->GetDrcController()->DestroyDRCDialog( wxID_OK );
901 
902  // Open a new drc dialod, with the right parent frame, and in Modal Mode
903  parent->GetDrcController()->ShowDRCDialog( this );
904  }
905 }
906 
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:639
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:46
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:49
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
Definition: pcbframe.cpp:999
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:99
double GetScale() const
void SetGerberPrecision(int aPrecision)
void OnOutputDirectoryBrowseClicked(wxCommandEvent &event) override
void SetPlotViaOnMaskLayer(bool aFlag)
wxCheckBox * m_plotPads_on_Silkscreen
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.
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
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:203
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:48
BOARD * m_board
Definition: dialog_plot.h:44
BOARD * GetBoard() const
wxCheckBox * m_plotMirrorOpt
const wxString GerberJobFileExtension
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:709
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:47
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.
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:43
int GetLineWidth() const
int m_widthAdjustMaxValue
Definition: dialog_plot.h:56
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:51
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
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:81
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
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
wxStaticBoxSizer * m_GerberOptionsSizer
bool GetCreateGerberJobFile() const
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString aExtraInfo)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:102
wxCheckBox * m_useGerberNetAttributes
void SetOutputDirectory(wxString aDir)
bool GetPlotReference() const
int m_widthAdjustMinValue
Definition: dialog_plot.h:55
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
PCB_PLOT_PARAMS m_plotOpts
Definition: dialog_plot.h:59
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:485
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: plot_common.h:86
wxCheckBox * m_subtractMaskFromSilk
void init_Dialog()
Definition: dialog_plot.cpp:58
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:58
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: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:45
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:920
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:71
wxBoxSizer * m_PlotOptionsSizer
void InstallDrillFrame(wxCommandEvent &event)
DIALOG_PLOT(PCB_EDIT_FRAME *parent)
Definition: dialog_plot.cpp:45
int m_SolderMaskMinWidth
Solder mask min width.
LSEQ UIOrder() const
Definition: lset.cpp:752
int GetGerberPrecision() const