KiCad PCB EDA Suite
dialog_plot.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 
25 #include <kiface_i.h>
26 #include <plotter.h>
27 #include <confirm.h>
28 #include <pcb_edit_frame.h>
29 #include <pcbplot.h>
30 #include <gerber_jobfile_writer.h>
31 #include <reporter.h>
33 #include <bitmaps.h>
34 #include <class_board.h>
35 #include <dialog_plot.h>
36 #include <wx_html_report_panel.h>
37 #include <drc.h>
38 
39 
41  DIALOG_PLOT_BASE( aParent ), m_parent( aParent ),
42  m_defaultLineWidth( aParent, m_lineWidthLabel, m_lineWidthCtrl, m_lineWidthUnits, true, 0 ),
43  m_defaultPenSize( aParent, m_hpglPenLabel, m_hpglPenCtrl, m_hpglPenUnits, true, 0 ),
44  m_trackWidthCorrection( aParent, m_widthAdjustLabel, m_widthAdjustCtrl, m_widthAdjustUnits, true )
45 {
46  SetName( DLG_WINDOW_NAME );
48  m_plotOpts = aParent->GetPlotSettings();
49  init_Dialog();
50 
51  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
52  // that requires us to correct the button labels here.
53  m_sdbSizer1OK->SetLabel( _( "Plot" ) );
54  m_sdbSizer1Apply->SetLabel( _( "Generate Drill Files..." ) );
55  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
56  m_sizerButtons->Layout();
57 
58  m_sdbSizer1OK->SetDefault();
59 
60  GetSizer()->Fit( this );
61  GetSizer()->SetSizeHints( this );
62 }
63 
64 
66 {
67  BOARD* board = m_parent->GetBoard();
68  wxFileName fileName;
69 
72 
73  bool checkZones;
74  m_config->Read( OPTKEY_PLOT_CHECK_ZONES, &checkZones, true );
75  m_zoneFillCheck->SetValue( checkZones );
76 
77  m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
78 
79  // m_PSWidthAdjust is stored in mm in user config
80  double dtmp;
81  m_config->Read( CONFIG_PS_FINEWIDTH_ADJ, &dtmp, 0 );
82  m_PSWidthAdjust = KiROUND( dtmp * IU_PER_MM );
83 
84  // The reasonable width correction value must be in a range of
85  // [-(MinTrackWidth-1), +(MinClearanceValue-1)] decimils.
88 
89  switch( m_plotOpts.GetFormat() )
90  {
91  default:
92  case PLOT_FORMAT_GERBER: m_plotFormatOpt->SetSelection( 0 ); break;
93  case PLOT_FORMAT_POST: m_plotFormatOpt->SetSelection( 1 ); break;
94  case PLOT_FORMAT_SVG: m_plotFormatOpt->SetSelection( 2 ); break;
95  case PLOT_FORMAT_DXF: m_plotFormatOpt->SetSelection( 3 ); break;
96  case PLOT_FORMAT_HPGL: m_plotFormatOpt->SetSelection( 4 ); break;
97  case PLOT_FORMAT_PDF: m_plotFormatOpt->SetSelection( 5 ); break;
98  }
99 
100  // Set units and value for HPGL pen size (this param is in mils).
102 
104 
105  // Test for a reasonable scale value. Set to 1 if problem
109 
112 
113  // Test for a reasonable PS width correction value. Set to 0 if problem.
114  if( m_PSWidthAdjust < m_widthAdjustMinValue || m_PSWidthAdjust > m_widthAdjustMaxValue )
115  m_PSWidthAdjust = 0.;
116 
118 
121 
122  // Could devote a PlotOrder() function in place of UIOrder().
123  m_layerList = board->GetEnabledLayers().UIOrder();
124 
125  // Populate the check list box by all enabled layers names
126  for( LSEQ seq = m_layerList; seq; ++seq )
127  {
128  PCB_LAYER_ID layer = *seq;
129 
130  int checkIndex = m_layerCheckListBox->Append( board->GetLayerName( layer ) );
131 
132  if( m_plotOpts.GetLayerSelection()[layer] )
133  m_layerCheckListBox->Check( checkIndex );
134  }
135 
136  // Option for using proper Gerber extensions
138 
139  // Option for including Gerber attributes (from Gerber X2 format) in the output
141 
142  // Option for including Gerber netlist info (from Gerber X2 format) in the output
144 
145  // Grey out if m_useGerberX2Attributes is not checked
146  m_useGerberNetAttributes->Enable( m_useGerberX2Attributes->GetValue() );
147 
148  // Option to generate a Gerber job file
150 
151  // Gerber precision for coordinates
152  m_coordFormatCtrl->SetSelection( m_plotOpts.GetGerberPrecision() == 5 ? 0 : 1 );
153 
154  // Option for excluding contents of "Edges Pcb" layer
156 
157  // Option to exclude pads from silkscreen layers
159 
161 
162  // Option to plot page references:
164 
165  // Options to plot texts on footprints
169 
170  // Options to plot pads and vias holes
171  m_drillShapeOpt->SetSelection( m_plotOpts.GetDrillMarksType() );
172 
173  // Scale option
174  m_scaleOpt->SetSelection( m_plotOpts.GetScaleSelection() );
175 
176  // Plot mode
178 
179  // Plot outline mode
181 
182  // Plot text mode
184 
185  // Plot mirror option
186  m_plotMirrorOpt->SetValue( m_plotOpts.GetMirror() );
187 
188  // Put vias on mask layer
190 
191  // Initialize a few other parameters, which can also be modified
192  // from the drill dialog
193  reInitDialog();
194 
195  // Update options values:
196  wxCommandEvent cmd_event;
197  SetPlotFormat( cmd_event );
198  OnSetScaleOpt( cmd_event );
199 }
200 
201 
203 {
204  // after calling drill dialog, some parameters can be modified.
205  // update them
206 
207  // Output directory
209 
210  // Origin of coordinates:
212 }
213 
214 
215 // A helper function to show a popup menu, when the dialog is right clicked.
216 void DIALOG_PLOT::OnRightClick( wxMouseEvent& event )
217 {
218  PopupMenu( m_popMenu );
219 }
220 
221 
222 // Select or deselect groups of layers in the layers list:
224 void DIALOG_PLOT::OnPopUpLayers( wxCommandEvent& event )
225 {
226  unsigned int i;
227 
228  switch( event.GetId() )
229  {
230  case ID_LAYER_FAB: // Select layers usually needed to build a board
231  for( i = 0; i < m_layerList.size(); i++ )
232  {
233  LSET layermask( m_layerList[ i ] );
234 
235  if( ( layermask & ( LSET::AllCuMask() | LSET::AllTechMask() ) ).any() )
236  m_layerCheckListBox->Check( i, true );
237  else
238  m_layerCheckListBox->Check( i, false );
239  }
240  break;
241 
243  for( i = 0; i < m_layerList.size(); i++ )
244  {
245  if( IsCopperLayer( m_layerList[i] ) )
246  m_layerCheckListBox->Check( i, true );
247  }
248  break;
249 
251  for( i = 0; i < m_layerList.size(); i++ )
252  {
253  if( IsCopperLayer( m_layerList[i] ) )
254  m_layerCheckListBox->Check( i, false );
255  }
256  break;
257 
259  for( i = 0; i < m_layerList.size(); i++ )
260  m_layerCheckListBox->Check( i, true );
261  break;
262 
264  for( i = 0; i < m_layerList.size(); i++ )
265  m_layerCheckListBox->Check( i, false );
266  break;
267 
268  default:
269  break;
270  }
271 }
272 
273 
274 void DIALOG_PLOT::CreateDrillFile( wxCommandEvent& event )
275 {
276  // Be sure drill file use the same settings (axis option, plot directory)
277  // than plot files:
279  m_parent->InstallDrillFrame( event );
280 
281  // a few plot settings can be modified: take them in account
283  reInitDialog();
284 }
285 
286 
287 void DIALOG_PLOT::OnChangeDXFPlotMode( wxCommandEvent& event )
288 {
289  // m_DXF_plotTextStrokeFontOpt is disabled if m_DXF_plotModeOpt
290  // is checked (plot in DXF polygon mode)
291  m_DXF_plotTextStrokeFontOpt->Enable( !m_DXF_plotModeOpt->GetValue() );
292 
293  // if m_DXF_plotTextStrokeFontOpt option is disabled (plot DXF in polygon mode),
294  // force m_DXF_plotTextStrokeFontOpt to true to use Pcbnew stroke font
295  if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() )
296  m_DXF_plotTextStrokeFontOpt->SetValue( true );
297 }
298 
299 
300 void DIALOG_PLOT::OnSetScaleOpt( wxCommandEvent& event )
301 {
302  /* Disable sheet reference for scale != 1:1 */
303  bool scale1 = ( m_scaleOpt->GetSelection() == 1 );
304 
305  m_plotSheetRef->Enable( scale1 );
306 
307  if( !scale1 )
308  m_plotSheetRef->SetValue( false );
309 }
310 
311 
312 void DIALOG_PLOT::OnOutputDirectoryBrowseClicked( wxCommandEvent& event )
313 {
314  // Build the absolute path of current output plot directory
315  // to preselect it when opening the dialog.
316  wxFileName fn( m_outputDirectoryName->GetValue() );
317  wxString path = Prj().AbsolutePath( m_outputDirectoryName->GetValue() );
318 
319  wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
320 
321  if( dirDialog.ShowModal() == wxID_CANCEL )
322  return;
323 
324  wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
325 
326  fn = Prj().AbsolutePath( m_parent->GetBoard()->GetFileName() );
327  wxString defaultPath = fn.GetPathWithSep();
328  wxString msg;
329  msg.Printf( _( "Do you want to use a path relative to\n\"%s\"" ),
330  GetChars( defaultPath ) );
331 
332  wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
333  wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
334 
335  if( dialog.ShowModal() == wxID_YES )
336  {
337  if( !dirName.MakeRelativeTo( defaultPath ) )
338  wxMessageBox( _( "Cannot make path relative (target volume different from file volume)!" ),
339  _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
340  }
341 
342  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
343 }
344 
345 
347 {
348  // plot format id's are ordered like displayed in m_plotFormatOpt
349  static const PlotFormat plotFmt[] =
350  {
357  };
358 
359  return plotFmt[ m_plotFormatOpt->GetSelection() ];
360 }
361 
362 
363 // Enable or disable widgets according to the plot format selected
364 // and clear also some optional values
365 void DIALOG_PLOT::SetPlotFormat( wxCommandEvent& event )
366 {
367  // this option exist only in DXF format:
369 
370  switch( getPlotFormat() )
371  {
372  case PLOT_FORMAT_PDF:
373  case PLOT_FORMAT_SVG:
374  m_drillShapeOpt->Enable( true );
375  m_plotModeOpt->Enable( false );
377  m_plotMirrorOpt->Enable( true );
378  m_useAuxOriginCheckBox->Enable( false );
379  m_useAuxOriginCheckBox->SetValue( false );
380  m_defaultLineWidth.Enable( true );
381  m_defaultPenSize.Enable( false );
382  m_excludeEdgeLayerOpt->Enable( true );
383  m_scaleOpt->Enable( false );
384  m_scaleOpt->SetSelection( 1 );
385  m_fineAdjustXCtrl->Enable( false );
386  m_fineAdjustYCtrl->Enable( false );
388  m_plotPSNegativeOpt->Enable( true );
389  m_forcePSA4OutputOpt->Enable( false );
390  m_forcePSA4OutputOpt->SetValue( false );
391 
396  break;
397 
398  case PLOT_FORMAT_POST:
399  m_drillShapeOpt->Enable( true );
400  m_plotModeOpt->Enable( true );
401  m_plotMirrorOpt->Enable( true );
402  m_useAuxOriginCheckBox->Enable( false );
403  m_useAuxOriginCheckBox->SetValue( false );
404  m_defaultLineWidth.Enable( true );
405  m_defaultPenSize.Enable( false );
406  m_excludeEdgeLayerOpt->Enable( true );
407  m_scaleOpt->Enable( true );
408  m_fineAdjustXCtrl->Enable( true );
409  m_fineAdjustYCtrl->Enable( true );
411  m_plotPSNegativeOpt->Enable( true );
412  m_forcePSA4OutputOpt->Enable( true );
413 
418  break;
419 
420  case PLOT_FORMAT_GERBER:
421  m_drillShapeOpt->Enable( false );
422  m_drillShapeOpt->SetSelection( 0 );
423  m_plotModeOpt->Enable( false );
425  m_plotMirrorOpt->Enable( false );
426  m_plotMirrorOpt->SetValue( false );
427  m_useAuxOriginCheckBox->Enable( true );
428  m_defaultLineWidth.Enable( true );
429  m_defaultPenSize.Enable( false );
430  m_excludeEdgeLayerOpt->Enable( true );
431  m_scaleOpt->Enable( false );
432  m_scaleOpt->SetSelection( 1 );
433  m_fineAdjustXCtrl->Enable( false );
434  m_fineAdjustYCtrl->Enable( false );
436  m_plotPSNegativeOpt->Enable( false );
437  m_plotPSNegativeOpt->SetValue( false );
438  m_forcePSA4OutputOpt->Enable( false );
439  m_forcePSA4OutputOpt->SetValue( false );
440 
445  break;
446 
447  case PLOT_FORMAT_HPGL:
448  m_drillShapeOpt->Enable( true );
449  m_plotModeOpt->Enable( true );
450  m_plotMirrorOpt->Enable( true );
451  m_useAuxOriginCheckBox->Enable( false );
452  m_useAuxOriginCheckBox->SetValue( false );
453  m_defaultLineWidth.Enable( false );
454  m_defaultPenSize.Enable( true );
455  m_excludeEdgeLayerOpt->Enable( true );
456  m_scaleOpt->Enable( true );
457  m_fineAdjustXCtrl->Enable( false );
458  m_fineAdjustYCtrl->Enable( false );
460  m_plotPSNegativeOpt->SetValue( false );
461  m_plotPSNegativeOpt->Enable( false );
462  m_forcePSA4OutputOpt->Enable( true );
463 
468  break;
469 
470  case PLOT_FORMAT_DXF:
471  m_drillShapeOpt->Enable( true );
472  m_plotModeOpt->Enable( false );
474  m_plotMirrorOpt->Enable( false );
475  m_plotMirrorOpt->SetValue( false );
476  m_useAuxOriginCheckBox->Enable( true );
477  m_defaultLineWidth.Enable( false );
478  m_defaultPenSize.Enable( false );
479  m_excludeEdgeLayerOpt->Enable( true );
480  m_scaleOpt->Enable( false );
481  m_scaleOpt->SetSelection( 1 );
482  m_fineAdjustXCtrl->Enable( false );
483  m_fineAdjustYCtrl->Enable( false );
485  m_plotPSNegativeOpt->Enable( false );
486  m_plotPSNegativeOpt->SetValue( false );
487  m_forcePSA4OutputOpt->Enable( false );
488  m_forcePSA4OutputOpt->SetValue( false );
489 
494 
495  OnChangeDXFPlotMode( event );
496  break;
497 
499  break;
500  }
501 
502  /* Update the interlock between scale and frame reference
503  * (scaling would mess up the frame border...) */
504  OnSetScaleOpt( event );
505 
506  Layout();
507  m_MainSizer->SetSizeHints( this );
508 }
509 
510 
511 // A helper function to "clip" aValue between aMin and aMax
512 // and write result in * aResult
513 // return false if clipped, true if aValue is just copied into * aResult
514 static bool setDouble( double* aResult, double aValue, double aMin, double aMax )
515 {
516  if( aValue < aMin )
517  {
518  *aResult = aMin;
519  return false;
520  }
521  else if( aValue > aMax )
522  {
523  *aResult = aMax;
524  return false;
525  }
526 
527  *aResult = aValue;
528  return true;
529 }
530 
531 
532 static bool setInt( int* aResult, int aValue, int aMin, int aMax )
533 {
534  if( aValue < aMin )
535  {
536  *aResult = aMin;
537  return false;
538  }
539  else if( aValue > aMax )
540  {
541  *aResult = aMax;
542  return false;
543  }
544 
545  *aResult = aValue;
546  return true;
547 }
548 
549 
551 {
552  REPORTER& reporter = m_messagesPanel->Reporter();
553 
554  PCB_PLOT_PARAMS tempOptions;
555 
556  tempOptions.SetExcludeEdgeLayer( m_excludeEdgeLayerOpt->GetValue() );
557  tempOptions.SetSubtractMaskFromSilk( m_subtractMaskFromSilk->GetValue() );
558  tempOptions.SetPlotFrameRef( m_plotSheetRef->GetValue() );
559  tempOptions.SetPlotPadsOnSilkLayer( !m_excludePadsFromSilkscreen->GetValue() );
560  tempOptions.SetUseAuxOrigin( m_useAuxOriginCheckBox->GetValue() );
561  tempOptions.SetPlotValue( m_plotModuleValueOpt->GetValue() );
562  tempOptions.SetPlotReference( m_plotModuleRefOpt->GetValue() );
563  tempOptions.SetPlotInvisibleText( m_plotInvisibleText->GetValue() );
564  tempOptions.SetScaleSelection( m_scaleOpt->GetSelection() );
565  tempOptions.SetDrillMarksType( static_cast<PCB_PLOT_PARAMS::DrillMarksType>
566  ( m_drillShapeOpt->GetSelection() ) );
567  tempOptions.SetMirror( m_plotMirrorOpt->GetValue() );
568  tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED );
569  tempOptions.SetDXFPlotPolygonMode( m_DXF_plotModeOpt->GetValue() );
570  tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() );
571 
572  if( !m_DXF_plotTextStrokeFontOpt->IsEnabled() ) // Currently, only DXF supports this option
573  tempOptions.SetTextMode( PLOTTEXTMODE_DEFAULT );
574  else
575  tempOptions.SetTextMode( m_DXF_plotTextStrokeFontOpt->GetValue() ?
577 
578  // Update settings from text fields. Rewrite values back to the fields,
579  // since the values may have been constrained by the setters.
580  wxString msg;
581 
582  // read HPLG pen size (this param is stored in mils)
583  // However, due to issues when converting this value from or to mm
584  // that can slightly change the value, update this param only if it
585  // is in use
587  {
588  if( !tempOptions.SetHPGLPenDiameter( m_defaultPenSize.GetValue() / IU_PER_MILS ) )
589  {
591  msg.Printf( _( "HPGL pen size constrained." ) );
592  reporter.Report( msg, REPORTER::RPT_INFO );
593  }
594  }
595  else // keep the last value (initial value if no HPGL plot made)
597 
598  // Default linewidth
599  if( !tempOptions.SetLineWidth( m_defaultLineWidth.GetValue() ) )
600  {
601  m_defaultLineWidth.SetValue( tempOptions.GetLineWidth() );
602  msg.Printf( _( "Default line width constrained." ) );
603  reporter.Report( msg, REPORTER::RPT_INFO );
604  }
605 
606  // X scale
607  double tmpDouble;
608  msg = m_fineAdjustXCtrl->GetValue();
609  msg.ToDouble( &tmpDouble );
610 
611  if( !setDouble( &m_XScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
612  {
613  msg.Printf( wxT( "%f" ), m_XScaleAdjust );
614  m_fineAdjustXCtrl->SetValue( msg );
615  msg.Printf( _( "X scale constrained." ) );
616  reporter.Report( msg, REPORTER::RPT_INFO );
617  }
618 
620 
621  // Y scale
622  msg = m_fineAdjustYCtrl->GetValue();
623  msg.ToDouble( &tmpDouble );
624 
625  if( !setDouble( &m_YScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) )
626  {
627  msg.Printf( wxT( "%f" ), m_YScaleAdjust );
628  m_fineAdjustYCtrl->SetValue( msg );
629  msg.Printf( _( "Y scale constrained." ) );
630  reporter.Report( msg, REPORTER::RPT_INFO );
631  }
632 
634 
635  m_config->Write( OPTKEY_PLOT_CHECK_ZONES, m_zoneFillCheck->GetValue() );
636 
637  // PS Width correction
640  {
642  msg.Printf( _( "Width correction constrained. "
643  "The reasonable width correction value must be in a range of "
644  " [%s; %s] (%s) for current design rules." ),
648  reporter.Report( msg, REPORTER::RPT_WARNING );
649  }
650 
651  // Store m_PSWidthAdjust in mm in user config
653  (double)m_PSWidthAdjust / IU_PER_MM );
654 
655  tempOptions.SetFormat( getPlotFormat() );
656 
657  tempOptions.SetUseGerberProtelExtensions( m_useGerberExtensions->GetValue() );
658  tempOptions.SetUseGerberAttributes( m_useGerberX2Attributes->GetValue() );
659  tempOptions.SetIncludeGerberNetlistInfo( m_useGerberNetAttributes->GetValue() );
660  tempOptions.SetCreateGerberJobFile( m_generateGerberJobFile->GetValue() );
661 
662  tempOptions.SetGerberPrecision( m_coordFormatCtrl->GetSelection() == 0 ? 5 : 6 );
663 
664  LSET selectedLayers;
665  for( unsigned i = 0; i < m_layerList.size(); i++ )
666  {
667  if( m_layerCheckListBox->IsChecked( i ) )
668  selectedLayers.set( m_layerList[i] );
669  }
670  // Get a list of copper layers that aren't being used by inverting enabled layers.
671  LSET disabledCopperLayers = LSET::AllCuMask() & ~m_parent->GetBoard()->GetEnabledLayers();
672  // Enable all of the disabled copper layers.
673  // If someone enables more copper layers they will be selected by default.
674  selectedLayers = selectedLayers | disabledCopperLayers;
675  tempOptions.SetLayerSelection( selectedLayers );
676 
677  tempOptions.SetNegative( m_plotPSNegativeOpt->GetValue() );
678  tempOptions.SetA4Output( m_forcePSA4OutputOpt->GetValue() );
679 
680  // Set output directory and replace backslashes with forward ones
681  wxString dirStr;
682  dirStr = m_outputDirectoryName->GetValue();
683  dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
684  tempOptions.SetOutputDirectory( dirStr );
685 
686  if( !m_plotOpts.IsSameAs( tempOptions, false ) )
687  {
688  // First, mark board as modified only for parameters saved in file
689  if( !m_plotOpts.IsSameAs( tempOptions, true ) )
690  m_parent->OnModify();
691 
692  // Now, save any change, for the session
693  m_parent->SetPlotSettings( tempOptions );
694  m_plotOpts = tempOptions;
695  }
696 }
697 
698 
699 void DIALOG_PLOT::OnGerberX2Checked( wxCommandEvent& event )
700 {
701  // m_useGerberNetAttributes is useless if m_useGerberX2Attributes
702  // is not checked. So disabled (greyed out) when Gerber X2 gets unchecked
703  // to make it clear to the user.
704  if( m_useGerberX2Attributes->GetValue() )
705  {
706  m_useGerberNetAttributes->Enable( true );
707  }
708  else
709  {
710  m_useGerberNetAttributes->Enable( false );
711  m_useGerberNetAttributes->SetValue( false );
712  }
713 }
714 
715 
716 void DIALOG_PLOT::Plot( wxCommandEvent& event )
717 {
718  BOARD* board = m_parent->GetBoard();
719 
721 
722  // If no layer selected, we have nothing plotted.
723  // Prompt user if it happens because he could think there is a bug in Pcbnew.
724  if( !m_plotOpts.GetLayerSelection().any() )
725  {
726  DisplayError( this, _( "No layer selected, Nothing to plot" ) );
727  return;
728  }
729 
730  // Create output directory if it does not exist (also transform it in
731  // absolute form). Bail if it fails
732  wxFileName outputDir = wxFileName::DirName( m_plotOpts.GetOutputDirectory() );
733  wxString boardFilename = m_parent->GetBoard()->GetFileName();
734  REPORTER& reporter = m_messagesPanel->Reporter();
735 
736  if( !EnsureFileDirectoryExists( &outputDir, boardFilename, &reporter ) )
737  {
738  wxString msg;
739  msg.Printf( _( "Could not write plot files to folder \"%s\"." ),
740  GetChars( outputDir.GetPath() ) );
741  DisplayError( this, msg );
742  return;
743  }
744 
745  if( m_zoneFillCheck->GetValue() )
746  m_parent->Check_All_Zones( this );
747 
748  m_plotOpts.SetAutoScale( false );
749  m_plotOpts.SetScale( 1 );
750 
751  switch( m_plotOpts.GetScaleSelection() )
752  {
753  default:
754  break;
755 
756  case 0: // Autoscale option
757  m_plotOpts.SetAutoScale( true );
758  break;
759 
760  case 2: // 3:2 option
761  m_plotOpts.SetScale( 1.5 );
762  break;
763 
764  case 3: // 2:1 option
765  m_plotOpts.SetScale( 2 );
766  break;
767 
768  case 4: // 3:1 option
769  m_plotOpts.SetScale( 3 );
770  break;
771  }
772 
773  /* If the scale factor edit controls are disabled or the scale value
774  * is 0, don't adjust the base scale factor. This fixes a bug when
775  * the default scale adjust is initialized to 0 and saved in program
776  * settings resulting in a divide by zero fault.
777  */
779  {
780  if( m_XScaleAdjust != 0.0 )
782 
783  if( m_YScaleAdjust != 0.0 )
785 
787  }
788 
789  wxString file_ext( GetDefaultPlotExtension( m_plotOpts.GetFormat() ) );
790 
791  // Test for a reasonable scale value
792  // XXX could this actually happen? isn't it constrained in the apply
793  // function?
795  DisplayInfoMessage( this, _( "Warning: Scale option set to a very small value" ) );
796 
798  DisplayInfoMessage( this, _( "Warning: Scale option set to a very large value" ) );
799 
800  GERBER_JOBFILE_WRITER jobfile_writer( board, &reporter );
801 
802  // Save the current plot options in the board
804 
805  wxBusyCursor dummy;
806 
807  for( LSEQ seq = m_plotOpts.GetLayerSelection().UIOrder(); seq; ++seq )
808  {
809  PCB_LAYER_ID layer = *seq;
810 
811  // All copper layers that are disabled are actually selected
812  // This is due to wonkyness in automatically selecting copper layers
813  // for plotting when adding more than two layers to a board.
814  // If plot options become accessible to the layers setup dialog
815  // please move this functionality there!
816  // This skips a copper layer if it is actually disabled on the board.
817  if( ( LSET::AllCuMask() & ~board->GetEnabledLayers() )[layer] )
818  continue;
819 
820  // Pick the basename from the board file
821  wxFileName fn( boardFilename );
822 
823  // Use Gerber Extensions based on layer number
824  // (See http://en.wikipedia.org/wiki/Gerber_File)
826  file_ext = GetGerberProtelExtension( layer );
827 
828  BuildPlotFileName( &fn, outputDir.GetPath(), board->GetLayerName( layer ), file_ext );
829  wxString fullname = fn.GetFullName();
830  jobfile_writer.AddGbrFile( layer, fullname );
831 
832  LOCALE_IO toggle;
833 
834  PLOTTER* plotter = StartPlotBoard( board, &m_plotOpts, layer, fn.GetFullPath(), wxEmptyString );
835 
836  // Print diags in messages box:
837  wxString msg;
838 
839  if( plotter )
840  {
841  PlotOneBoardLayer( board, plotter, layer, m_plotOpts );
842  plotter->EndPlot();
843  delete plotter;
844 
845  msg.Printf( _( "Plot file \"%s\" created." ), GetChars( fn.GetFullPath() ) );
846  reporter.Report( msg, REPORTER::RPT_ACTION );
847  }
848  else
849  {
850  msg.Printf( _( "Unable to create file \"%s\"." ), GetChars( fn.GetFullPath() ) );
851  reporter.Report( msg, REPORTER::RPT_ERROR );
852  }
853  }
854 
856  {
857  // Pick the basename from the board file
858  wxFileName fn( boardFilename );
859  // Build gerber job file from basename
860  BuildPlotFileName( &fn, outputDir.GetPath(), "job", GerberJobFileExtension );
861  jobfile_writer.CreateJobFile( fn.GetFullPath() );
862  }
863 }
864 
865 
866 void DIALOG_PLOT::onRunDRC( wxCommandEvent& event )
867 {
868  PCB_EDIT_FRAME* parent = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
869 
870  if( parent )
871  {
872  // First close an existing dialog if open
873  // (low probability, but can happen)
874  parent->GetDrcController()->DestroyDRCDialog( wxID_OK );
875 
876  // Open a new drc dialod, with the right parent frame, and in Modal Mode
877  parent->GetDrcController()->ShowDRCDialog( this );
878  }
879 }
880 
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)
LSEQ m_layerList
Definition: dialog_plot.h:48
void SetIncludeGerberNetlistInfo(bool aUse)
double GetHPGLPenDiameter() const
void SetDXFPlotPolygonMode(bool aFlag)
bool GetMirror() const
double m_YScaleAdjust
Definition: dialog_plot.h:51
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
bool GetSubtractMaskFromSilk() 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:119
double GetScale() const
void SetGerberPrecision(int aPrecision)
void OnOutputDirectoryBrowseClicked(wxCommandEvent &event) override
wxButton * m_sdbSizer1Cancel
void SetPlotViaOnMaskLayer(bool aFlag)
bool CreateJobFile(const wxString &aFullFilename)
Creates a Gerber job file.
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:179
#define OPTKEY_PLOT_Y_FINESCALE_ADJ
Definition: pcbplot.h:61
void SetLayerSelection(LSET aSelection)
void OnGerberX2Checked(wxCommandEvent &event) override
void SetUseAuxOrigin(bool aAux)
This file is part of the common library.
int GetSmallestClearanceValue()
Function GetSmallestClearanceValue.
bool GetUseGerberAttributes() const
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.
void SetFormat(PlotFormat aFormat)
PlotFormat getPlotFormat()
wxString GetDefaultPlotExtension(PlotFormat aFormat)
Returns the default plot extension for a format.
void Check_All_Zones(wxWindow *aActiveWindow)
Function Check_All_Zones Checks for out-of-date fills and fills them if requested by the user...
wxCheckBox * m_excludeEdgeLayerOpt
void SetCreateGerberJobFile(bool aCreate)
void onRunDRC(wxCommandEvent &event) override
void SetMirror(bool aFlag)
wxButton * m_sdbSizer1OK
const wxString GetGerberProtelExtension(LAYER_NUM aLayer)
Function GetGerberProtelExtension.
Definition: pcbplot.cpp:48
PlotFormat
Enum PlotFormat is the set of supported output plot formats.
Definition: plotter.h:50
BOARD * GetBoard() const
wxCheckBox * m_plotMirrorOpt
wxCheckBox * m_zoneFillCheck
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
wxChoice * m_coordFormatCtrl
void CreateDrillFile(wxCommandEvent &event) override
Classes used to generate a Gerber job file in JSON.
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
wxStaticBoxSizer * m_SizerDXF_options
bool GetPlotValue() const
UNIT_BINDER m_trackWidthCorrection
Definition: dialog_plot.h:62
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:49
wxButton * m_sdbSizer1Apply
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
wxTextCtrl * m_fineAdjustYCtrl
wxCheckBox * m_DXF_plotModeOpt
bool SetLineWidth(int aValue)
void SetPlotValue(bool aFlag)
bool GetA4Output() const
bool GetExcludeEdgeLayer() const
Board plot function definition file.
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
wxCheckBox * m_plotSheetRef
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
virtual bool EndPlot()=0
void SetPlotFrameRef(bool aFlag)
wxString GetOutputDirectory() const
void SetPlotFormat(wxCommandEvent &event) override
void Plot(wxCommandEvent &event) override
wxTextCtrl * m_fineAdjustXCtrl
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:60
PCB_EDIT_FRAME * m_parent
Definition: dialog_plot.h:46
int GetLineWidth() const
int m_widthAdjustMaxValue
Definition: dialog_plot.h:58
const wxString & GetFileName() const
Definition: class_board.h:237
PlotTextMode GetTextMode() const
int m_TrackMinWidth
track min value for width ((min copper size value
static bool setDouble(double *aResult, double aValue, double aMin, double aMax)
bool EnsureFileDirectoryExists(wxFileName *aTargetFullFileName, const wxString &aBaseFilename, REPORTER *aReporter)
Make aTargetFullFileName absolute and create the path of this file if it doesn&#39;t yet exist...
Definition: common.cpp:469
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:53
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
const std::string GerberJobFileExtension
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:538
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:62
void setPlotModeChoiceSelection(EDA_DRAW_MODE_T aPlotMode)
Definition: dialog_plot.h:84
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:57
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:64
void SetNegative(bool aFlag)
bool GetDXFPlotPolygonMode() const
void SetFineScaleAdjustX(double aVal)
wxChoice * m_scaleOpt
void BuildPlotFileName(wxFileName *aFilename, const wxString &aOutputDir, const wxString &aSuffix, const wxString &aExtension)
Function BuildPlotFileName (helper function) Complete a plot filename: forces the output directory...
Definition: pcbplot.cpp:380
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)
UNIT_BINDER m_defaultLineWidth
Definition: dialog_plot.h:60
bool SetHPGLPenDiameter(double aValue)
Base plotter engine class.
Definition: plotter.h:97
wxBoxSizer * m_sizerButtons
wxCheckBox * m_subtractMaskFromSilk
void init_Dialog()
Definition: dialog_plot.cpp:65
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:61
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
Board layer functions and definitions.
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:170
bool GetNegative() const
static bool setInt(int *aResult, int aValue, int aMin, int aMax)
bool GetPlotFrameRef() const
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
size_t i
Definition: json11.cpp:597
wxCheckBox * m_plotInvisibleText
EDA_DRAW_MODE_T GetPlotMode() const
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
bool GetPlotPadsOnSilkLayer() const
#define IU_PER_MILS
Definition: plotter.cpp:134
wxCheckBox * m_useAuxOriginCheckBox
void SetAutoScale(bool aFlag)
void SetFineScaleAdjustY(double aVal)
wxChoice * m_plotModeOpt
wxConfigBase * m_config
Definition: dialog_plot.h:47
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.
wxString StringFromValue(EDA_UNITS_T aUnits, int aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:210
wxCheckBox * m_excludePadsFromSilkscreen
#define OPTKEY_PLOT_CHECK_ZONES
Definition: pcbplot.h:63
UNIT_BINDER m_defaultPenSize
Definition: dialog_plot.h:61
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...
#define DLG_WINDOW_NAME
Definition: dialog_plot.h:34
wxCheckListBox * m_layerCheckListBox
DRC * GetDrcController()
Function 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:277
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
wxBoxSizer * m_PlotOptionsSizer
void InstallDrillFrame(wxCommandEvent &event)
DIALOG_PLOT(PCB_EDIT_FRAME *parent)
Definition: dialog_plot.cpp:40
void Enable(bool aEnable)
Function Enable Enables/diasables the label, widget and units label.
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit, bool aUseMils)
Get the units string for a given units type.
Definition: base_units.cpp:432
LSEQ UIOrder() const
Definition: lset.cpp:800
EDA_UNITS_T GetUserUnits() const override
Definition: dialog_shim.h:103
int GetGerberPrecision() const