KiCad PCB EDA Suite
gen_footprints_placefile.cpp
Go to the documentation of this file.
1 
4 /*
5  * This program source code file is part of KiCad, a free EDA CAD application.
6  *
7  * Copyright (C) 2015-2018 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 /*
28  * 1 - create ascii files for automatic placement of smd components
29  * 2 - create a module report (pos and module descr) (ascii file)
30  */
31 
32 #include <fctsys.h>
33 #include <confirm.h>
34 #include <kicad_string.h>
35 #include <gestfich.h>
36 #include <pcb_edit_frame.h>
37 #include <pgm_base.h>
38 #include <bitmaps.h>
39 #include <build_version.h>
40 #include <macros.h>
41 #include <reporter.h>
42 
43 #include <class_board.h>
44 #include <class_module.h>
45 
46 #include <pcbnew.h>
48 #include <kiface_i.h>
49 #include <wx_html_report_panel.h>
50 
51 
53 /*
54  * The ASCII format of the kicad place file is:
55  * ### Module positions - created on 04/12/2012 15:24:24 ###
56  * ### Printed by Pcbnew version pcbnew (2012-11-30 BZR 3828)-testing
57  * ## Unit = inches, Angle = deg.
58  * or
59  * ## Unit = mm, Angle = deg.
60  * ## Side : top
61  * or
62  * ## Side : bottom
63  * or
64  * ## Side : all
65  * # Ref Val Package PosX PosY Rot Side
66  * C123 0,1uF/50V SM0603 1.6024 -2.6280 180.0 Front
67  * C124 0,1uF/50V SM0603 1.6063 -2.7579 180.0 Front
68  * C125 0,1uF/50V SM0603 1.6010 -2.8310 180.0 Front
69  * ## End
70  */
71 
72 #define PLACEFILE_UNITS_KEY wxT( "PlaceFileUnits" )
73 #define PLACEFILE_OPT_KEY wxT( "PlaceFileOpts" )
74 #define PLACEFILE_FORMAT_KEY wxT( "PlaceFileFormat" )
75 
76 
77 #define PCB_BACK_SIDE 0
78 #define PCB_FRONT_SIDE 1
79 #define PCB_BOTH_SIDES 2
80 
81 class LIST_MOD // An helper class used to build a list of useful footprints.
82 {
83 public:
84  MODULE* m_Module; // Link to the actual footprint
85  wxString m_Reference; // Its schematic reference
86  wxString m_Value; // Its schematic value
87  LAYER_NUM m_Layer; // its side (B_Cu, or F_Cu)
88 };
89 
90 
96 {
97 public:
100  m_parent( aParent ),
101  m_plotOpts( aParent->GetPlotSettings() )
102  {
103  m_reporter = &m_messagesPanel->Reporter();
104  initDialog();
105 
106  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
107  // that requires us to correct the button labels here.
108  m_sdbSizer1OK->SetLabel( _( "Generate Position File" ) );
109  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
110  m_sdbSizer1->Layout();
111 
112  m_sdbSizer1OK->SetDefault();
113 
114  GetSizer()->SetSizeHints(this);
115  Centre();
116  }
117 
118 private:
121  wxConfigBase* m_config;
123 
124  static int m_unitsOpt;
125  static int m_fileOpt;
126  static int m_fileFormat;
127 
128  void initDialog();
129  void OnOutputDirectoryBrowseClicked( wxCommandEvent& event ) override;
130  void OnGenerate( wxCommandEvent& event ) override;
131 
132  bool CreateFiles();
133 
134  // accessors to options:
136  {
137  return m_outputDirectoryName->GetValue();
138  }
139 
140  bool UnitsMM()
141  {
142  return m_radioBoxUnits->GetSelection() == 1;
143  }
144 
145  bool OneFileOnly()
146  {
147  return m_radioBoxFilesCount->GetSelection() == 1;
148  }
149 
150  bool ForceAllSmd()
151  {
152  return m_forceSMDOpt->GetValue();
153  }
154 };
155 
156 
157 // Static members to remember choices
161 
162 // Use standard board side name. do not translate them,
163 // they are keywords in place file
164 const wxString frontSideName = wxT( "top" );
165 const wxString backSideName = wxT( "bottom" );
166 
168 {
169  m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
170 
171  m_config = Kiface().KifaceSettings();
172  m_config->Read( PLACEFILE_UNITS_KEY, &m_unitsOpt, 1 );
173  m_config->Read( PLACEFILE_OPT_KEY, &m_fileOpt, 0 );
174  m_config->Read( PLACEFILE_FORMAT_KEY, &m_fileFormat, 0 );
175 
176  // Output directory
177  m_outputDirectoryName->SetValue( m_plotOpts.GetOutputDirectory() );
178  m_radioBoxUnits->SetSelection( m_unitsOpt );
179  m_radioBoxFilesCount->SetSelection( m_fileOpt );
180  m_rbFormat->SetSelection( m_fileFormat );
181 
182  // Update sizes and sizers:
183  m_messagesPanel->MsgPanelSetMinSize( wxSize( -1, 160 ) );
184  GetSizer()->SetSizeHints( this );
185 }
186 
188 {
189  // Build the absolute path of current output plot directory
190  // to preselect it when opening the dialog.
191  wxString path = Prj().AbsolutePath( m_outputDirectoryName->GetValue() );
192 
193  wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
194 
195  if( dirDialog.ShowModal() == wxID_CANCEL )
196  return;
197 
198  wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
199 
200  wxMessageDialog dialog( this, _( "Use a relative path?"),
201  _( "Plot Output Directory" ),
202  wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
203 
204  if( dialog.ShowModal() == wxID_YES )
205  {
206  wxString boardFilePath = ( (wxFileName) m_parent->GetBoard()->GetFileName()).GetPath();
207 
208  if( !dirName.MakeRelativeTo( boardFilePath ) )
209  wxMessageBox( _( "Cannot make path relative (target volume different from board file volume)!" ),
210  _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
211  }
212 
213  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
214 }
215 
216 void DIALOG_GEN_FOOTPRINT_POSITION::OnGenerate( wxCommandEvent& event )
217 {
218  m_unitsOpt = m_radioBoxUnits->GetSelection();
219  m_fileOpt = m_radioBoxFilesCount->GetSelection();
220  m_fileFormat = m_rbFormat->GetSelection();
221 
222 
223  m_config->Write( PLACEFILE_UNITS_KEY, m_unitsOpt );
224  m_config->Write( PLACEFILE_OPT_KEY, m_fileOpt );
225  m_config->Write( PLACEFILE_FORMAT_KEY, m_fileFormat );
226 
227  // Set output directory and replace backslashes with forward ones
228  // (Keep unix convention in cfg files)
229  wxString dirStr;
230  dirStr = m_outputDirectoryName->GetValue();
231  dirStr.Replace( wxT( "\\" ), wxT( "/" ) );
232 
233  m_plotOpts.SetOutputDirectory( dirStr );
234  m_parent->SetPlotSettings( m_plotOpts );
235 
236  CreateFiles();
237 
238  // the dialog is not closed here.
239 }
240 
241 
243 {
244  BOARD * brd = m_parent->GetBoard();
245  wxFileName fn;
246  wxString msg;
247  bool singleFile = OneFileOnly();
248  bool useCSVfmt = m_fileFormat == 1;
249  int fullcount = 0;
250 
251  // Count the footprints to place, do not yet create a file
252  int fpcount = m_parent->DoGenFootprintsPositionFile( wxEmptyString, UnitsMM(),
253  ForceAllSmd(), PCB_BOTH_SIDES,
254  useCSVfmt );
255  if( fpcount == 0)
256  {
257  wxMessageBox( _( "No footprint for automated placement." ) );
258  return false;
259  }
260 
261  // Create output directory if it does not exist (also transform it in
262  // absolute path). Bail if it fails
263  wxFileName outputDir = wxFileName::DirName( m_plotOpts.GetOutputDirectory() );
264  wxString boardFilename = m_parent->GetBoard()->GetFileName();
265 
266  m_reporter = &m_messagesPanel->Reporter();
267 
268  if( !EnsureFileDirectoryExists( &outputDir, boardFilename, m_reporter ) )
269  {
270  msg.Printf( _( "Could not write plot files to folder \"%s\"." ),
271  GetChars( outputDir.GetPath() ) );
272  DisplayError( this, msg );
273  return false;
274  }
275 
276  fn = m_parent->GetBoard()->GetFileName();
277  fn.SetPath( outputDir.GetPath() );
278 
279  // Create the the Front or Top side placement file,
280  // or the single file
281  int side = PCB_FRONT_SIDE;
282 
283  if( singleFile )
284  {
285  side = PCB_BOTH_SIDES;
286  fn.SetName( fn.GetName() + wxT( "-" ) + wxT("all") );
287  }
288  else
289  fn.SetName( fn.GetName() + wxT( "-" ) + frontSideName );
290 
291 
292  if( useCSVfmt )
293  {
294  fn.SetName( fn.GetName() + wxT( "-" ) + FootprintPlaceFileExtension );
295  fn.SetExt( wxT( "csv" ) );
296  }
297  else
298  fn.SetExt( FootprintPlaceFileExtension );
299 
300  fpcount = m_parent->DoGenFootprintsPositionFile( fn.GetFullPath(), UnitsMM(),
301  ForceAllSmd(), side, useCSVfmt );
302  if( fpcount < 0 )
303  {
304  msg.Printf( _( "Unable to create \"%s\"." ), GetChars( fn.GetFullPath() ) );
305  wxMessageBox( msg );
306  m_reporter->Report( msg, REPORTER::RPT_ERROR );
307  return false;
308  }
309 
310  if( singleFile )
311  msg.Printf( _( "Place file: \"%s\"." ), GetChars( fn.GetFullPath() ) );
312  else
313  msg.Printf( _( "Front side (top side) place file: \"%s\"." ),
314  GetChars( fn.GetFullPath() ) );
315  m_reporter->Report( msg, REPORTER::RPT_INFO );
316 
317  msg.Printf( _( "Component count: %d." ), fpcount );
318  m_reporter->Report( msg, REPORTER::RPT_INFO );
319 
320  if( singleFile )
321  {
322  m_reporter->Report( _( "Component Placement File generation OK." ), REPORTER::RPT_ACTION );
323  return true;
324  }
325 
326  // Create the Back or Bottom side placement file
327  fullcount = fpcount;
328  side = PCB_BACK_SIDE;
329  fn = brd->GetFileName();
330  fn.SetPath( outputDir.GetPath() );
331  fn.SetName( fn.GetName() + wxT( "-" ) + backSideName );
332 
333  if( useCSVfmt )
334  {
335  fn.SetName( fn.GetName() + wxT( "-" ) + FootprintPlaceFileExtension );
336  fn.SetExt( wxT( "csv" ) );
337  }
338  else
339  fn.SetExt( FootprintPlaceFileExtension );
340 
341  fpcount = m_parent->DoGenFootprintsPositionFile( fn.GetFullPath(), UnitsMM(),
342  ForceAllSmd(), side, useCSVfmt );
343 
344  if( fpcount < 0 )
345  {
346  msg.Printf( _( "Unable to create file \"%s\"." ), GetChars( fn.GetFullPath() ) );
347  m_reporter->Report( msg, REPORTER::RPT_ERROR );
348  wxMessageBox( msg );
349  return false;
350  }
351 
352  // Display results
353  if( !singleFile )
354  {
355  msg.Printf( _( "Back side (bottom side) place file: \"%s\"." ), GetChars( fn.GetFullPath() ) );
356  m_reporter->Report( msg, REPORTER::RPT_INFO );
357 
358  msg.Printf( _( "Component count: %d." ), fpcount );
359 
360  m_reporter->Report( msg, REPORTER::RPT_INFO );
361  }
362 
363  if( !singleFile )
364  {
365  fullcount += fpcount;
366  msg.Printf( _( "Full component count: %d\n" ), fullcount );
367  m_reporter->Report( msg, REPORTER::RPT_INFO );
368  }
369 
370  m_reporter->Report( _( "Component Placement File generation OK." ), REPORTER::RPT_ACTION );
371 
372  return true;
373 }
374 
375 // Defined values to write coordinates using inches or mm:
376 static const double conv_unit_inch = 0.001 / IU_PER_MILS ; // units = INCHES
377 static const char unit_text_inch[] = "## Unit = inches, Angle = deg.\n";
378 
379 static const double conv_unit_mm = 1.0 / IU_PER_MM; // units = mm
380 static const char unit_text_mm[] = "## Unit = mm, Angle = deg.\n";
381 
382 static wxPoint File_Place_Offset; // Offset coordinates for generated file.
383 
384 
385 // Sort function use by GenereModulesPosition()
386 // sort is made by side (layer) top layer first
387 // then by reference increasing order
388 static bool sortFPlist( const LIST_MOD& ref, const LIST_MOD& tst )
389 {
390  if( ref.m_Layer == tst.m_Layer )
391  return StrNumCmp( ref.m_Reference, tst.m_Reference, 16 ) < 0;
392 
393  return ref.m_Layer > tst.m_Layer;
394 }
395 
396 
402 static bool HasNonSMDPins( MODULE* aModule )
403 {
404  D_PAD* pad;
405 
406  for( pad = aModule->PadsList(); pad; pad = pad->Next() )
407  {
408  if( pad->GetAttribute() != PAD_ATTRIB_SMD )
409  return true;
410  }
411 
412  return false;
413 }
414 
415 void PCB_EDIT_FRAME::GenFootprintsPositionFile( wxCommandEvent& event )
416 {
417  DIALOG_GEN_FOOTPRINT_POSITION dlg( this );
418  dlg.ShowModal();
419 }
420 
421 /*
422  * Creates a footprint position file
423  * aSide = 0 -> Back (bottom) side)
424  * aSide = 1 -> Front (top) side)
425  * aSide = 2 -> both sides
426  * if aFullFileName is empty, the file is not created, only the
427  * count of footprints to place is returned
428  */
429 int PCB_EDIT_FRAME::DoGenFootprintsPositionFile( const wxString& aFullFileName,
430  bool aUnitsMM,
431  bool aForceSmdItems, int aSide,
432  bool aFormatCSV )
433 {
434  MODULE* footprint;
435 
436  // Minimal text lengths:
437  int lenRefText = 8;
438  int lenValText = 8;
439  int lenPkgText = 16;
440 
441  File_Place_Offset = GetAuxOrigin();
442 
443  // Calculating the number of useful footprints (CMS attribute, not VIRTUAL)
444  int footprintCount = 0;
445 
446  // Select units:
447  double conv_unit = aUnitsMM ? conv_unit_mm : conv_unit_inch;
448  const char *unit_text = aUnitsMM ? unit_text_mm : unit_text_inch;
449 
450  // Build and sort the list of footprints alphabetically
451  std::vector<LIST_MOD> list;
452  list.reserve( footprintCount );
453 
454  for( footprint = GetBoard()->m_Modules; footprint; footprint = footprint->Next() )
455  {
456  if( aSide != PCB_BOTH_SIDES )
457  {
458  if( footprint->GetLayer() == B_Cu && aSide == PCB_FRONT_SIDE)
459  continue;
460  if( footprint->GetLayer() == F_Cu && aSide == PCB_BACK_SIDE)
461  continue;
462  }
463 
464  if( footprint->GetAttributes() & MOD_VIRTUAL )
465  {
466  DBG( printf( "skipping footprint %s because it's virtual\n",
467  TO_UTF8( footprint->GetReference() ) );)
468  continue;
469  }
470 
471  if( ( footprint->GetAttributes() & MOD_CMS ) == 0 )
472  {
473  if( aForceSmdItems ) // true to fix a bunch of mis-labeled footprints:
474  {
475  if( !HasNonSMDPins( footprint ) )
476  {
477  // all footprint's pins are SMD, mark the part for pick and place
478  footprint->SetAttributes( footprint->GetAttributes() | MOD_CMS );
479  OnModify();
480  }
481  else
482  {
483  DBG(printf( "skipping %s because its attribute is not CMS and it has non SMD pins\n",
484  TO_UTF8(footprint->GetReference()) ) );
485  continue;
486  }
487  }
488  else
489  continue;
490  }
491 
492  footprintCount++;
493 
494  LIST_MOD item;
495  item.m_Module = footprint;
496  item.m_Reference = footprint->GetReference();
497  item.m_Value = footprint->GetValue();
498  item.m_Layer = footprint->GetLayer();
499  list.push_back( item );
500 
501  lenRefText = std::max( lenRefText, int(item.m_Reference.length()) );
502  lenValText = std::max( lenValText, int(item.m_Value.length()) );
503  lenPkgText = std::max( lenPkgText, int(item.m_Module->GetFPID().GetLibItemName().length()) );
504  }
505 
506  if( aFullFileName.IsEmpty() )
507  return footprintCount;
508 
509  FILE * file = wxFopen( aFullFileName, wxT( "wt" ) );
510  if( file == NULL )
511  return -1;
512 
513  if( list.size() > 1 )
514  sort( list.begin(), list.end(), sortFPlist );
515 
516  // Switch the locale to standard C (needed to print floating point numbers)
517  LOCALE_IO toggle;
518 
519  if( aFormatCSV )
520  {
521  wxChar csv_sep = ',';
522 
523  // Set first line:;
524  fprintf( file, "Ref%cVal%cPackage%cPosX%cPosY%cRot%cSide\n",
525  csv_sep, csv_sep, csv_sep, csv_sep, csv_sep, csv_sep );
526 
527  for( int ii = 0; ii < footprintCount; ii++ )
528  {
529  wxPoint footprint_pos;
530  footprint_pos = list[ii].m_Module->GetPosition();
531  footprint_pos -= File_Place_Offset;
532 
533  LAYER_NUM layer = list[ii].m_Module->GetLayer();
534  wxASSERT( layer == F_Cu || layer == B_Cu );
535 
536  wxString line = "\"" + list[ii].m_Reference;
537  line << "\"" << csv_sep;
538  line << "\"" << list[ii].m_Value;
539  line << "\"" << csv_sep;
540  line << "\"" << list[ii].m_Module->GetFPID().GetLibItemName().wx_str();
541  line << "\"" << csv_sep;
542 
543  line << wxString::Format( "%f%c%f%c%f",
544  footprint_pos.x * conv_unit, csv_sep,
545  // Keep the Y axis oriented from bottom to top,
546  // ( change y coordinate sign )
547  -footprint_pos.y * conv_unit, csv_sep,
548  list[ii].m_Module->GetOrientation() / 10.0 );
549  line << csv_sep;
550 
551  line << ( (layer == F_Cu ) ? frontSideName : backSideName );
552  line << '\n';
553 
554  fputs( TO_UTF8( line ), file );
555  }
556  }
557  else
558  {
559  // Write file header
560  fprintf( file, "### Module positions - created on %s ###\n", TO_UTF8( DateAndTime() ) );
561 
562  wxString Title = Pgm().App().GetAppName() + wxT( " " ) + GetBuildVersion();
563  fprintf( file, "### Printed by Pcbnew version %s\n", TO_UTF8( Title ) );
564 
565  fputs( unit_text, file );
566 
567  fputs( "## Side : ", file );
568 
569  if( aSide == PCB_BACK_SIDE )
570  fputs( TO_UTF8( backSideName ), file );
571  else if( aSide == PCB_FRONT_SIDE )
572  fputs( TO_UTF8( frontSideName ), file );
573  else
574  fputs( "All", file );
575 
576  fputs( "\n", file );
577 
578  fprintf(file, "%-*s %-*s %-*s %9.9s %9.9s %8.8s %s\n",
579  int(lenRefText), "# Ref",
580  int(lenValText), "Val",
581  int(lenPkgText), "Package",
582  "PosX", "PosY", "Rot", "Side" );
583 
584  for( int ii = 0; ii < footprintCount; ii++ )
585  {
586  wxPoint footprint_pos;
587  footprint_pos = list[ii].m_Module->GetPosition();
588  footprint_pos -= File_Place_Offset;
589 
590  LAYER_NUM layer = list[ii].m_Module->GetLayer();
591  wxASSERT( layer == F_Cu || layer == B_Cu );
592 
593  if( layer == B_Cu )
594  footprint_pos.x = - footprint_pos.x;
595 
596  wxString ref = list[ii].m_Reference;
597  wxString val = list[ii].m_Value;
598  wxString pkg = list[ii].m_Module->GetFPID().GetLibItemName();
599  ref.Replace( wxT( " " ), wxT( "_" ) );
600  val.Replace( wxT( " " ), wxT( "_" ) );
601  pkg.Replace( wxT( " " ), wxT( "_" ) );
602  fprintf(file, "%-*s %-*s %-*s %9.4f %9.4f %8.4f %s\n",
603  lenRefText, TO_UTF8( ref ),
604  lenValText, TO_UTF8( val ),
605  lenPkgText, TO_UTF8( pkg ),
606  footprint_pos.x * conv_unit,
607  // Keep the coordinates in the first quadrant,
608  // (i.e. change y sign
609  -footprint_pos.y * conv_unit,
610  list[ii].m_Module->GetOrientation() / 10.0,
611  (layer == F_Cu ) ? TO_UTF8( frontSideName ) : TO_UTF8( backSideName ));
612  }
613 
614  // Write EOF
615  fputs( "## End\n", file );
616  }
617 
618  fclose( file );
619  return footprintCount;
620 }
621 
622 
623 void PCB_EDIT_FRAME::GenFootprintsReport( wxCommandEvent& event )
624 {
625  wxFileName fn;
626 
627  wxString boardFilePath = ( (wxFileName) GetBoard()->GetFileName()).GetPath();
628  wxDirDialog dirDialog( this, _( "Select Output Directory" ), boardFilePath );
629 
630  if( dirDialog.ShowModal() == wxID_CANCEL )
631  return;
632 
633  fn = GetBoard()->GetFileName();
634  fn.SetPath( dirDialog.GetPath() );
635  fn.SetExt( wxT( "rpt" ) );
636 
637  bool unitMM = GetUserUnits() != INCHES;
638  bool success = DoGenFootprintsReport( fn.GetFullPath(), unitMM );
639 
640  wxString msg;
641  if( success )
642  {
643  msg.Printf( _( "Footprint report file created:\n\"%s\"" ),
644  GetChars( fn.GetFullPath() ) );
645  wxMessageBox( msg, _( "Footprint Report" ), wxICON_INFORMATION );
646  }
647 
648  else
649  {
650  msg.Printf( _( "Unable to create \"%s\"" ), GetChars( fn.GetFullPath() ) );
651  DisplayError( this, msg );
652  }
653 }
654 
655 /* Print a module report.
656  */
657 bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool aUnitsMM )
658 {
659  wxString msg;
660  FILE* rptfile;
661  wxPoint module_pos;
662 
663  File_Place_Offset = wxPoint( 0, 0 );
664 
665  rptfile = wxFopen( aFullFilename, wxT( "wt" ) );
666 
667  if( rptfile == NULL )
668  return false;
669 
670  // Select units:
671  double conv_unit = aUnitsMM ? conv_unit_mm : conv_unit_inch;
672  const char *unit_text = aUnitsMM ? unit_text_mm : unit_text_inch;
673 
674  LOCALE_IO toggle;
675 
676  // Generate header file comments.)
677  fprintf( rptfile, "## Footprint report - date %s\n", TO_UTF8( DateAndTime() ) );
678 
679  wxString Title = Pgm().App().GetAppName() + wxT( " " ) + GetBuildVersion();
680  fprintf( rptfile, "## Created by Pcbnew version %s\n", TO_UTF8( Title ) );
681  fputs( unit_text, rptfile );
682 
683  fputs( "\n$BeginDESCRIPTION\n", rptfile );
684 
685  EDA_RECT bbbox = GetBoard()->ComputeBoundingBox();
686 
687  fputs( "\n$BOARD\n", rptfile );
688 
689  fprintf( rptfile, "upper_left_corner %9.6f %9.6f\n",
690  bbbox.GetX() * conv_unit,
691  bbbox.GetY() * conv_unit );
692 
693  fprintf( rptfile, "lower_right_corner %9.6f %9.6f\n",
694  bbbox.GetRight() * conv_unit,
695  bbbox.GetBottom() * conv_unit );
696 
697  fputs( "$EndBOARD\n\n", rptfile );
698 
699  for( MODULE* Module = GetBoard()->m_Modules; Module; Module = Module->Next() )
700  {
701  fprintf( rptfile, "$MODULE %s\n", EscapedUTF8( Module->GetReference() ).c_str() );
702 
703  fprintf( rptfile, "reference %s\n", EscapedUTF8( Module->GetReference() ).c_str() );
704  fprintf( rptfile, "value %s\n", EscapedUTF8( Module->GetValue() ).c_str() );
705  fprintf( rptfile, "footprint %s\n",
706  EscapedUTF8( FROM_UTF8( Module->GetFPID().Format().c_str() ) ).c_str() );
707 
708  msg = wxT( "attribut" );
709 
710  if( Module->GetAttributes() & MOD_VIRTUAL )
711  msg += wxT( " virtual" );
712 
713  if( Module->GetAttributes() & MOD_CMS )
714  msg += wxT( " smd" );
715 
716  if( ( Module->GetAttributes() & (MOD_VIRTUAL | MOD_CMS) ) == 0 )
717  msg += wxT( " none" );
718 
719  msg += wxT( "\n" );
720  fputs( TO_UTF8( msg ), rptfile );
721 
722  module_pos = Module->GetPosition();
723  module_pos.x -= File_Place_Offset.x;
724  module_pos.y -= File_Place_Offset.y;
725 
726  fprintf( rptfile, "position %9.6f %9.6f orientation %.2f\n",
727  module_pos.x * conv_unit,
728  module_pos.y * conv_unit,
729  Module->GetOrientation() / 10.0 );
730 
731  if( Module->GetLayer() == F_Cu )
732  fputs( "layer front\n", rptfile );
733  else if( Module->GetLayer() == B_Cu )
734  fputs( "layer back\n", rptfile );
735  else
736  fputs( "layer other\n", rptfile );
737 
738  for( D_PAD* pad = Module->PadsList(); pad != NULL; pad = pad->Next() )
739  {
740  fprintf( rptfile, "$PAD \"%s\"\n", TO_UTF8( pad->GetName() ) );
741  int layer = 0;
742 
743  if( pad->GetLayerSet()[B_Cu] )
744  layer = 1;
745 
746  if( pad->GetLayerSet()[F_Cu] )
747  layer |= 2;
748 
749  static const char* layer_name[4] = { "nocopper", "back", "front", "both" };
750  fprintf( rptfile, "Shape %s Layer %s\n", TO_UTF8( pad->ShowPadShape() ), layer_name[layer] );
751 
752  fprintf( rptfile, "position %9.6f %9.6f size %9.6f %9.6f orientation %.2f\n",
753  pad->GetPos0().x * conv_unit, pad->GetPos0().y * conv_unit,
754  pad->GetSize().x * conv_unit, pad->GetSize().y * conv_unit,
755  (pad->GetOrientation() - Module->GetOrientation()) / 10.0 );
756 
757  fprintf( rptfile, "drill %9.6f\n", pad->GetDrillSize().x * conv_unit );
758 
759  fprintf( rptfile, "shape_offset %9.6f %9.6f\n",
760  pad->GetOffset().x * conv_unit,
761  pad->GetOffset().y * conv_unit );
762 
763  fprintf( rptfile, "$EndPAD\n" );
764  }
765 
766  fprintf( rptfile, "$EndMODULE %s\n\n", TO_UTF8 (Module->GetReference() ) );
767  }
768 
769  // Generate EOF.
770  fputs( "$EndDESCRIPTION\n", rptfile );
771  fclose( rptfile );
772 
773  return true;
774 }
static const double conv_unit_inch
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:405
This file is part of the common library TODO brief description.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:179
This file is part of the common library.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
static bool HasNonSMDPins(MODULE *aModule)
Helper function HasNonSMDPins returns true if the given module has any non smd pins, such as through hole and therefore cannot be placed automatically.
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Function ComputeBoundingBox calculates the bounding box containing all board items (or board edge seg...
void OnOutputDirectoryBrowseClicked(wxCommandEvent &event) override
PROJECT & Prj()
Definition: kicad.cpp:292
Class BOARD to handle a board.
MODULE * Next() const
Definition: class_module.h:123
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:61
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:188
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:77
static const char unit_text_mm[]
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:497
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
Class DIALOG_GEN_FOOTPRINT_POSITION_BASE.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
This file contains miscellaneous commonly used macros and functions.
BOARD_ITEM * Next() const
const LIB_ID & GetFPID() const
Definition: class_module.h:193
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
int DoGenFootprintsPositionFile(const wxString &aFullFileName, bool aUnitsMM, bool aForceSmdItems, int aSide, bool aFormatCSV=false)
Function DoGenFootprintsPositionFile Creates an ascii footprint position file.
static bool sortFPlist(const LIST_MOD &ref, const LIST_MOD &tst)
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:214
#define PLACEFILE_FORMAT_KEY
bool DoGenFootprintsReport(const wxString &aFullFilename, bool aUnitsMM)
Function DoGenFootprintsReport Creates an ascii footprint report file giving some infos on footprints...
void GenFootprintsReport(wxCommandEvent &event)
Function GenFootprintsReport Calls DoGenFootprintsReport to create a footprint reprot file See DoGenF...
DIALOG_GEN_FOOTPRINT_POSITION(PCB_EDIT_FRAME *aParent)
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
const wxString & GetFileName() const
Definition: class_board.h:237
const wxString backSideName
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
const wxString frontSideName
Definition: common.h:160
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
static const double conv_unit_mm
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
D_PAD * Next() const
Definition: class_pad.h:160
The common library.
int GetAttributes() const
Definition: class_module.h:226
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
std::string::size_type length() const
Definition: utf8.h:114
int GetBottom() const
Definition: eda_rect.h:122
int GetRight() const
Definition: eda_rect.h:119
Class PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board...
#define PLACEFILE_OPT_KEY
#define PCB_BOTH_SIDES
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
BOARD * GetBoard()
#define PLACEFILE_UNITS_KEY
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
see class PGM_BASE
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:463
Virtual component: when created by copper shapes on board (Like edge card connectors, mounting hole...)
Definition: class_module.h:79
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
int GetX() const
Definition: eda_rect.h:109
#define IU_PER_MILS
Definition: plotter.cpp:134
static wxPoint File_Place_Offset
#define PCB_FRONT_SIDE
int GetY() const
Definition: eda_rect.h:110
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
#define DBG(x)
Definition: fctsys.h:33
const std::string FootprintPlaceFileExtension
DLIST< D_PAD > & PadsList()
Definition: class_module.h:163
Module description (excepted pads)
int StrNumCmp(const wxString &aString1, const wxString &aString2, int aLength, bool aIgnoreCase)
Function StrNumCmp is a routine compatible with qsort() to sort by alphabetical order.
Definition: string.cpp:315
static const char unit_text_inch[]
#define PCB_BACK_SIDE
The dialog to create footprint position files and choose options (one or 2 files, units and force all...
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
wxString DateAndTime()
Function DateAndTime.
Definition: string.cpp:306
void SetAttributes(int aAttributes)
Definition: class_module.h:227
void OnGenerate(wxCommandEvent &event) override
void GenFootprintsPositionFile(wxCommandEvent &event)
Function GenFootprintsPositionFile Calls DoGenFootprintsPositionFile to create a footprint position f...