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